From 9088d5f24f467bb8d0c08d78be416cc8226bbcad Mon Sep 17 00:00:00 2001 From: Geoff Thorpe Date: Thu, 17 Jun 2004 20:13:50 +0000 Subject: [PATCH] As Nils put it; Yet another question: some time ago you changed BN_set_word. Why didn't you change BN_get_word as well? Quite. I'm also removing the older commented-out implementations to improve readability. This complex stuff seems to date from a time when the types didn't match up well. Submitted by: Nils Larsch, Geoff Thorpe --- crypto/bn/bn_lib.c | 52 ++++------------------------------------------ 1 file changed, 4 insertions(+), 48 deletions(-) diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c index 0cc20d9239..8aa817dfc6 100644 --- a/crypto/bn/bn_lib.c +++ b/crypto/bn/bn_lib.c @@ -616,55 +616,12 @@ void BN_clear(BIGNUM *a) BN_ULONG BN_get_word(const BIGNUM *a) { - int i,n; - BN_ULONG ret=0; - - n=BN_num_bytes(a); - if (n > (int)sizeof(BN_ULONG)) - return(BN_MASK2); - for (i=a->top-1; i>=0; i--) - { -#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ - ret<<=BN_BITS4; /* stops the compiler complaining */ - ret<<=BN_BITS4; -#else - ret=0; -#endif - ret|=a->d[i]; - } - return(ret); + if (a->top > 1) + return BN_MASK2; + else + return a->d[0]; } -#if 0 /* a->d[0] is a BN_ULONG, w is a BN_ULONG, what's the big deal? */ -int BN_set_word(BIGNUM *a, BN_ULONG w) - { - int i,n; - bn_check_top(a); - if (bn_expand(a,(int)sizeof(BN_ULONG)*8) == NULL) return(0); - - n=sizeof(BN_ULONG)/BN_BYTES; - a->neg=0; - a->top=0; - a->d[0]=(BN_ULONG)w&BN_MASK2; - if (a->d[0] != 0) a->top=1; - for (i=1; i>=BN_BITS2 so compilers don't complain - * on builds where sizeof(long) == BN_TYPES */ -#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ - w>>=BN_BITS4; - w>>=BN_BITS4; -#else - w=0; -#endif - a->d[i]=(BN_ULONG)w&BN_MASK2; - if (a->d[i] != 0) a->top=i+1; - } - bn_check_top(a); - return(1); - } -#else int BN_set_word(BIGNUM *a, BN_ULONG w) { bn_check_top(a); @@ -675,7 +632,6 @@ int BN_set_word(BIGNUM *a, BN_ULONG w) bn_check_top(a); return(1); } -#endif BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret) { -- 2.40.0