diff options
Diffstat (limited to 'src/lib/libcrypto/bn/bn_shift.c')
| -rw-r--r-- | src/lib/libcrypto/bn/bn_shift.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/lib/libcrypto/bn/bn_shift.c b/src/lib/libcrypto/bn/bn_shift.c index a6fca2c424..c4d301afc4 100644 --- a/src/lib/libcrypto/bn/bn_shift.c +++ b/src/lib/libcrypto/bn/bn_shift.c | |||
| @@ -99,7 +99,7 @@ int BN_lshift1(BIGNUM *r, const BIGNUM *a) | |||
| 99 | int BN_rshift1(BIGNUM *r, const BIGNUM *a) | 99 | int BN_rshift1(BIGNUM *r, const BIGNUM *a) |
| 100 | { | 100 | { |
| 101 | BN_ULONG *ap,*rp,t,c; | 101 | BN_ULONG *ap,*rp,t,c; |
| 102 | int i,j; | 102 | int i; |
| 103 | 103 | ||
| 104 | bn_check_top(r); | 104 | bn_check_top(r); |
| 105 | bn_check_top(a); | 105 | bn_check_top(a); |
| @@ -109,25 +109,22 @@ int BN_rshift1(BIGNUM *r, const BIGNUM *a) | |||
| 109 | BN_zero(r); | 109 | BN_zero(r); |
| 110 | return(1); | 110 | return(1); |
| 111 | } | 111 | } |
| 112 | i = a->top; | ||
| 113 | ap= a->d; | ||
| 114 | j = i-(ap[i-1]==1); | ||
| 115 | if (a != r) | 112 | if (a != r) |
| 116 | { | 113 | { |
| 117 | if (bn_wexpand(r,j) == NULL) return(0); | 114 | if (bn_wexpand(r,a->top) == NULL) return(0); |
| 115 | r->top=a->top; | ||
| 118 | r->neg=a->neg; | 116 | r->neg=a->neg; |
| 119 | } | 117 | } |
| 118 | ap=a->d; | ||
| 120 | rp=r->d; | 119 | rp=r->d; |
| 121 | t=ap[--i]; | 120 | c=0; |
| 122 | c=(t&1)?BN_TBIT:0; | 121 | for (i=a->top-1; i>=0; i--) |
| 123 | if (t>>=1) rp[i]=t; | ||
| 124 | while (i>0) | ||
| 125 | { | 122 | { |
| 126 | t=ap[--i]; | 123 | t=ap[i]; |
| 127 | rp[i]=((t>>1)&BN_MASK2)|c; | 124 | rp[i]=((t>>1)&BN_MASK2)|c; |
| 128 | c=(t&1)?BN_TBIT:0; | 125 | c=(t&1)?BN_TBIT:0; |
| 129 | } | 126 | } |
| 130 | r->top=j; | 127 | bn_correct_top(r); |
| 131 | bn_check_top(r); | 128 | bn_check_top(r); |
| 132 | return(1); | 129 | return(1); |
| 133 | } | 130 | } |
| @@ -185,11 +182,10 @@ int BN_rshift(BIGNUM *r, const BIGNUM *a, int n) | |||
| 185 | BN_zero(r); | 182 | BN_zero(r); |
| 186 | return(1); | 183 | return(1); |
| 187 | } | 184 | } |
| 188 | i = (BN_num_bits(a)-n+(BN_BITS2-1))/BN_BITS2; | ||
| 189 | if (r != a) | 185 | if (r != a) |
| 190 | { | 186 | { |
| 191 | r->neg=a->neg; | 187 | r->neg=a->neg; |
| 192 | if (bn_wexpand(r,i) == NULL) return(0); | 188 | if (bn_wexpand(r,a->top-nw+1) == NULL) return(0); |
| 193 | } | 189 | } |
| 194 | else | 190 | else |
| 195 | { | 191 | { |
| @@ -200,7 +196,7 @@ int BN_rshift(BIGNUM *r, const BIGNUM *a, int n) | |||
| 200 | f= &(a->d[nw]); | 196 | f= &(a->d[nw]); |
| 201 | t=r->d; | 197 | t=r->d; |
| 202 | j=a->top-nw; | 198 | j=a->top-nw; |
| 203 | r->top=i; | 199 | r->top=j; |
| 204 | 200 | ||
| 205 | if (rb == 0) | 201 | if (rb == 0) |
| 206 | { | 202 | { |
| @@ -216,8 +212,9 @@ int BN_rshift(BIGNUM *r, const BIGNUM *a, int n) | |||
| 216 | l= *(f++); | 212 | l= *(f++); |
| 217 | *(t++) =(tmp|(l<<lb))&BN_MASK2; | 213 | *(t++) =(tmp|(l<<lb))&BN_MASK2; |
| 218 | } | 214 | } |
| 219 | if ((l = (l>>rb)&BN_MASK2)) *(t) = l; | 215 | *(t++) =(l>>rb)&BN_MASK2; |
| 220 | } | 216 | } |
| 217 | bn_correct_top(r); | ||
| 221 | bn_check_top(r); | 218 | bn_check_top(r); |
| 222 | return(1); | 219 | return(1); |
| 223 | } | 220 | } |
