summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bn/bn_word.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bn/bn_word.c')
-rw-r--r--src/lib/libcrypto/bn/bn_word.c30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
index 4b3d0f011d..c0cfbc6797 100644
--- a/src/lib/libcrypto/bn/bn_word.c
+++ b/src/lib/libcrypto/bn/bn_word.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
63BN_ULONG BN_mod_word(a, w) 63BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w)
64BIGNUM *a;
65unsigned long w;
66 { 64 {
67#ifndef BN_LLONG 65#ifndef BN_LLONG
68 BN_ULONG ret=0; 66 BN_ULONG ret=0;
@@ -75,8 +73,8 @@ unsigned long w;
75 for (i=a->top-1; i>=0; i--) 73 for (i=a->top-1; i>=0; i--)
76 { 74 {
77#ifndef BN_LLONG 75#ifndef BN_LLONG
78 ret=((ret<<BN_BITS4)|((a->d[i]>>BN_BITS4)&BN_MASK2l))%(unsigned long)w; 76 ret=((ret<<BN_BITS4)|((a->d[i]>>BN_BITS4)&BN_MASK2l))%w;
79 ret=((ret<<BN_BITS4)|(a->d[i]&BN_MASK2l))%(unsigned long)w; 77 ret=((ret<<BN_BITS4)|(a->d[i]&BN_MASK2l))%w;
80#else 78#else
81 ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])% 79 ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])%
82 (BN_ULLONG)w); 80 (BN_ULLONG)w);
@@ -85,9 +83,7 @@ unsigned long w;
85 return((BN_ULONG)ret); 83 return((BN_ULONG)ret);
86 } 84 }
87 85
88BN_ULONG BN_div_word(a, w) 86BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
89BIGNUM *a;
90unsigned long w;
91 { 87 {
92 BN_ULONG ret; 88 BN_ULONG ret;
93 int i; 89 int i;
@@ -100,18 +96,16 @@ unsigned long w;
100 BN_ULONG l,d; 96 BN_ULONG l,d;
101 97
102 l=a->d[i]; 98 l=a->d[i];
103 d=bn_div64(ret,l,w); 99 d=bn_div_words(ret,l,w);
104 ret=(l-((d*w)&BN_MASK2))&BN_MASK2; 100 ret=(l-((d*w)&BN_MASK2))&BN_MASK2;
105 a->d[i]=d; 101 a->d[i]=d;
106 } 102 }
107 if (a->d[a->top-1] == 0) 103 if ((a->top > 0) && (a->d[a->top-1] == 0))
108 a->top--; 104 a->top--;
109 return(ret); 105 return(ret);
110 } 106 }
111 107
112int BN_add_word(a, w) 108int BN_add_word(BIGNUM *a, BN_ULONG w)
113BIGNUM *a;
114unsigned long w;
115 { 109 {
116 BN_ULONG l; 110 BN_ULONG l;
117 int i; 111 int i;
@@ -142,9 +136,7 @@ unsigned long w;
142 return(1); 136 return(1);
143 } 137 }
144 138
145int BN_sub_word(a, w) 139int BN_sub_word(BIGNUM *a, BN_ULONG w)
146BIGNUM *a;
147unsigned long w;
148 { 140 {
149 int i; 141 int i;
150 142
@@ -183,9 +175,7 @@ unsigned long w;
183 return(1); 175 return(1);
184 } 176 }
185 177
186int BN_mul_word(a,w) 178int BN_mul_word(BIGNUM *a, BN_ULONG w)
187BIGNUM *a;
188unsigned long w;
189 { 179 {
190 BN_ULONG ll; 180 BN_ULONG ll;
191 181
@@ -199,6 +189,6 @@ unsigned long w;
199 a->d[a->top++]=ll; 189 a->d[a->top++]=ll;
200 } 190 }
201 } 191 }
202 return(0); 192 return(1);
203 } 193 }
204 194