]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
OSSL_FN: Wrap BIGNUM the 'mul' function around the OSSL_FN 'mul' function 29368/head
authorRichard Levitte <levitte@openssl.org>
Mon, 24 Nov 2025 13:39:44 +0000 (14:39 +0100)
committerRichard Levitte <levitte@openssl.org>
Thu, 11 Dec 2025 09:35:46 +0000 (10:35 +0100)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/29203)

crypto/bn/bn_mul.c

index 265f1106ebb7585a234ec81cceb44a7a9eff50bd..5447b8c70db04bca83f06a90d37ccf89d8cdd1f2 100644 (file)
 
 int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
 {
-    int ret = bn_mul_fixed_top(r, a, b, ctx);
+    /* TODO(FIXNUM): TO BE REMOVED */
+    if (r->data == NULL || a->data == NULL || b->data == NULL) {
+        int ret = bn_mul_fixed_top(r, a, b, ctx);
 
-    bn_correct_top(r);
+        bn_correct_top(r);
+        bn_check_top(r);
+
+        return ret;
+    }
+
+    bn_check_top(a);
+    bn_check_top(b);
     bn_check_top(r);
 
+    size_t top = a->top + b->top;
+    size_t max = a->dmax + b->dmax;
+
+    /*
+     * Unfortunately, OSSL_FN_CTX and BN_CTX are too wildly different to
+     * be interchangeable.  We must therefore create an OSSL_FN_CTX here.
+     * (OSSL_FN_CTX is only really useful within OSSL_FN functionality)
+     */
+    OSSL_FN_CTX *fnctx = OSSL_FN_CTX_new(NULL, 1, 1, max);
+    OSSL_FN *rf = bn_acquire_ossl_fn(r, (int)top);
+    int ret = OSSL_FN_mul(rf, a->data, b->data, fnctx);
+    bn_release(r, (int)top);
+
+    if (ret && !BN_is_zero(r))
+        r->neg = a->neg ^ b->neg;
+
+    OSSL_FN_CTX_free(fnctx);
     return ret;
 }