crypto: dh - Check mpi_rshift errors
authorHerbert Xu <herbert@gondor.apana.org.au>
Sat, 10 Aug 2024 06:20:59 +0000 (14:20 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 17 Aug 2024 05:55:50 +0000 (13:55 +0800)
Now that mpi_rshift can return errors, check them.

Fixes: 35d2bf20683f ("crypto: dh - calculate Q from P for the full public key verification")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/dh.c

index 68d11d6..afc0fd8 100644 (file)
@@ -145,9 +145,9 @@ static int dh_is_pubkey_valid(struct dh_ctx *ctx, MPI y)
         * ->p is odd, so no need to explicitly subtract one
         * from it before shifting to the right.
         */
-       mpi_rshift(q, ctx->p, 1);
+       ret = mpi_rshift(q, ctx->p, 1) ?:
+             mpi_powm(val, y, q, ctx->p);
 
-       ret = mpi_powm(val, y, q, ctx->p);
        mpi_free(q);
        if (ret) {
                mpi_free(val);