diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2011-02-14 16:44:29 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2011-02-14 16:44:29 +0000 |
commit | 133291f8e73892dfd00923d278be74229ac07401 (patch) | |
tree | aa72a8232c79ef701c4cc93894a489f1abb7b509 /crypto | |
parent | e990b4f838eaa649a1849d25db5be2236632fe34 (diff) |
New function BN_nist_mod_func which returns an appropriate function
if the passed prime is a NIST prime.
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/bn/bn.h | 2 | ||||
-rw-r--r-- | crypto/bn/bn_nist.c | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/crypto/bn/bn.h b/crypto/bn/bn.h index 5897d2b314..0a66a2ea0c 100644 --- a/crypto/bn/bn.h +++ b/crypto/bn/bn.h @@ -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)?\ diff --git a/crypto/bn/bn_nist.c b/crypto/bn/bn_nist.c index 2ca5b01391..97f980a131 100644 --- a/crypto/bn/bn_nist.c +++ b/crypto/bn/bn_nist.c @@ -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; + } |