diff options
author | Geoff Thorpe <geoff@openssl.org> | 2004-06-17 20:03:56 +0000 |
---|---|---|
committer | Geoff Thorpe <geoff@openssl.org> | 2004-06-17 20:03:56 +0000 |
commit | cf9056cfda3976fc53a630f9965b68569d656e27 (patch) | |
tree | 72bc98c2976677caf6bd1b886b00dce23591c7dc /crypto/bn/bntest.c | |
parent | f7fc4ca1dd98153e8e21ecbd1fb4fd45c8a14011 (diff) |
BN_div_word() was breaking when called from BN_bn2dec() (actually, this is
the only function that uses it) because it would trip up an assertion in
bn_div_words() when first invoked. This also adds BN_div_word() testing to
bntest.
Submitted by: Nils Larsch
Reviewed by: Geoff Thorpe
Diffstat (limited to 'crypto/bn/bntest.c')
-rw-r--r-- | crypto/bn/bntest.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/crypto/bn/bntest.c b/crypto/bn/bntest.c index 0d37dcff4d..d4cb92f847 100644 --- a/crypto/bn/bntest.c +++ b/crypto/bn/bntest.c @@ -98,6 +98,7 @@ int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_); int test_rshift1(BIO *bp); int test_rshift(BIO *bp,BN_CTX *ctx); int test_div(BIO *bp,BN_CTX *ctx); +int test_div_word(BIO *bp); int test_div_recp(BIO *bp,BN_CTX *ctx); int test_mul(BIO *bp); int test_sqr(BIO *bp,BN_CTX *ctx); @@ -221,6 +222,10 @@ int main(int argc, char *argv[]) if (!test_div(out,ctx)) goto err; BIO_flush(out); + message(out,"BN_div_word"); + if (!test_div_word(out)) goto err; + BIO_flush(out); + message(out,"BN_div_recp"); if (!test_div_recp(out,ctx)) goto err; BIO_flush(out); @@ -463,6 +468,62 @@ int test_div(BIO *bp, BN_CTX *ctx) return(1); } +int test_div_word(BIO *bp) + { + BIGNUM a,b; + BN_ULONG r,s; + int i; + + BN_init(&a); + BN_init(&b); + + for (i=0; i<num0; i++) + { + do { + BN_bntest_rand(&a,512,-1,0); + BN_bntest_rand(&b,BN_BITS2,-1,0); + s = b.d[0]; + } while (!s); + + BN_copy(&b, &a); + r = BN_div_word(&b, s); + + if (bp != NULL) + { + if (!results) + { + BN_print(bp,&a); + BIO_puts(bp," / "); + BIO_printf(bp,"%lX",s); + BIO_puts(bp," - "); + } + BN_print(bp,&b); + BIO_puts(bp,"\n"); + + if (!results) + { + BN_print(bp,&a); + BIO_puts(bp," % "); + BIO_printf(bp,"%lX",s); + BIO_puts(bp," - "); + } + BIO_printf(bp,"%lX",r); + BIO_puts(bp,"\n"); + } + BN_mul_word(&b,s); + BN_add_word(&b,r); + BN_sub(&b,&a,&b); + if(!BN_is_zero(&b)) + { + fprintf(stderr,"Division (word) test failed!\n"); + return 0; + } + } + BN_free(&a); + BN_free(&b); + return(1); + } + int test_div_recp(BIO *bp, BN_CTX *ctx) { BIGNUM a,b,c,d,e; |