]> granicus.if.org Git - openssl/commitdiff
New function BN_nist_mod_func which returns an appropriate function
authorDr. Stephen Henson <steve@openssl.org>
Mon, 14 Feb 2011 16:44:29 +0000 (16:44 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 14 Feb 2011 16:44:29 +0000 (16:44 +0000)
if the passed prime is a NIST prime.

crypto/bn/bn.h
crypto/bn/bn_nist.c

index 5897d2b314d08a0fe76bbe320e91536d46c6bc02..0a66a2ea0c691949bd9f3c6ba6c81e72cd57cee9 100644 (file)
@@ -674,6 +674,8 @@ const BIGNUM *BN_get0_nist_prime_256(void);
 const BIGNUM *BN_get0_nist_prime_384(void);
 const BIGNUM *BN_get0_nist_prime_521(void);
 
+int (*BN_nist_mod_func(const BIGNUM *p))(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, BN_CTX *ctx);
+
 /* library internal functions */
 
 #define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\
index 2ca5b0139111f76352b3d2c08ba6232056efb942..97f980a1314341ef609bbaf2e0066e560067e21b 100644 (file)
@@ -834,3 +834,18 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,
 
        return 1;
        }
+
+int (*BN_nist_mod_func(const BIGNUM *p))(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, BN_CTX *ctx)
+       {
+       if (BN_ucmp(&_bignum_nist_p_192, p) == 0)
+               return BN_nist_mod_192;
+       if (BN_ucmp(&_bignum_nist_p_224, p) == 0)
+               return BN_nist_mod_224;
+       if (BN_ucmp(&_bignum_nist_p_256, p) == 0)
+               return BN_nist_mod_256;
+       if (BN_ucmp(&_bignum_nist_p_384, p) == 0)
+               return BN_nist_mod_384;
+       if (BN_ucmp(&_bignum_nist_p_521, p) == 0)
+               return BN_nist_mod_521;
+       return 0;
+       }