summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_shift.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_shift.c')
-rw-r--r--src/lib/libcrypto/bn/bn_shift.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/lib/libcrypto/bn/bn_shift.c b/src/lib/libcrypto/bn/bn_shift.c
index 944bf1794b..70f785ea18 100644
--- a/src/lib/libcrypto/bn/bn_shift.c
+++ b/src/lib/libcrypto/bn/bn_shift.c
@@ -60,9 +60,7 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63int BN_lshift1(r, a) 63int BN_lshift1(BIGNUM *r, const BIGNUM *a)
64BIGNUM *r;
65BIGNUM *a;
66 { 64 {
67 register BN_ULONG *ap,*rp,t,c; 65 register BN_ULONG *ap,*rp,t,c;
68 int i; 66 int i;
@@ -94,9 +92,7 @@ BIGNUM *a;
94 return(1); 92 return(1);
95 } 93 }
96 94
97int BN_rshift1(r, a) 95int BN_rshift1(BIGNUM *r, const BIGNUM *a)
98BIGNUM *r;
99BIGNUM *a;
100 { 96 {
101 BN_ULONG *ap,*rp,t,c; 97 BN_ULONG *ap,*rp,t,c;
102 int i; 98 int i;
@@ -125,18 +121,15 @@ BIGNUM *a;
125 return(1); 121 return(1);
126 } 122 }
127 123
128int BN_lshift(r, a, n) 124int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
129BIGNUM *r;
130BIGNUM *a;
131int n;
132 { 125 {
133 int i,nw,lb,rb; 126 int i,nw,lb,rb;
134 BN_ULONG *t,*f; 127 BN_ULONG *t,*f;
135 BN_ULONG l; 128 BN_ULONG l;
136 129
137 r->neg=a->neg; 130 r->neg=a->neg;
138 if (bn_wexpand(r,a->top+(n/BN_BITS2)+1) == NULL) return(0);
139 nw=n/BN_BITS2; 131 nw=n/BN_BITS2;
132 if (bn_wexpand(r,a->top+nw+1) == NULL) return(0);
140 lb=n%BN_BITS2; 133 lb=n%BN_BITS2;
141 rb=BN_BITS2-lb; 134 rb=BN_BITS2-lb;
142 f=a->d; 135 f=a->d;
@@ -160,10 +153,7 @@ int n;
160 return(1); 153 return(1);
161 } 154 }
162 155
163int BN_rshift(r, a, n) 156int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
164BIGNUM *r;
165BIGNUM *a;
166int n;
167 { 157 {
168 int i,j,nw,lb,rb; 158 int i,j,nw,lb,rb;
169 BN_ULONG *t,*f; 159 BN_ULONG *t,*f;
@@ -172,7 +162,7 @@ int n;
172 nw=n/BN_BITS2; 162 nw=n/BN_BITS2;
173 rb=n%BN_BITS2; 163 rb=n%BN_BITS2;
174 lb=BN_BITS2-rb; 164 lb=BN_BITS2-rb;
175 if (nw > a->top) 165 if (nw > a->top || a->top == 0)
176 { 166 {
177 BN_zero(r); 167 BN_zero(r);
178 return(1); 168 return(1);
@@ -182,6 +172,11 @@ int n;
182 r->neg=a->neg; 172 r->neg=a->neg;
183 if (bn_wexpand(r,a->top-nw+1) == NULL) return(0); 173 if (bn_wexpand(r,a->top-nw+1) == NULL) return(0);
184 } 174 }
175 else
176 {
177 if (n == 0)
178 return 1; /* or the copying loop will go berserk */
179 }
185 180
186 f= &(a->d[nw]); 181 f= &(a->d[nw]);
187 t=r->d; 182 t=r->d;