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