diff options
Diffstat (limited to 'src/lib/libcrypto/bn')
36 files changed, 0 insertions, 12434 deletions
diff --git a/src/lib/libcrypto/bn/asm/bn-586.pl b/src/lib/libcrypto/bn/asm/bn-586.pl deleted file mode 100644 index 5191bed273..0000000000 --- a/src/lib/libcrypto/bn/asm/bn-586.pl +++ /dev/null | |||
| @@ -1,384 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | push(@INC,"perlasm","../../perlasm"); | ||
| 4 | require "x86asm.pl"; | ||
| 5 | |||
| 6 | &asm_init($ARGV[0],$0); | ||
| 7 | |||
| 8 | &bn_mul_add_words("bn_mul_add_words"); | ||
| 9 | &bn_mul_words("bn_mul_words"); | ||
| 10 | &bn_sqr_words("bn_sqr_words"); | ||
| 11 | &bn_div_words("bn_div_words"); | ||
| 12 | &bn_add_words("bn_add_words"); | ||
| 13 | &bn_sub_words("bn_sub_words"); | ||
| 14 | |||
| 15 | &asm_finish(); | ||
| 16 | |||
| 17 | sub bn_mul_add_words | ||
| 18 | { | ||
| 19 | local($name)=@_; | ||
| 20 | |||
| 21 | &function_begin($name,""); | ||
| 22 | |||
| 23 | &comment(""); | ||
| 24 | $Low="eax"; | ||
| 25 | $High="edx"; | ||
| 26 | $a="ebx"; | ||
| 27 | $w="ebp"; | ||
| 28 | $r="edi"; | ||
| 29 | $c="esi"; | ||
| 30 | |||
| 31 | &xor($c,$c); # clear carry | ||
| 32 | &mov($r,&wparam(0)); # | ||
| 33 | |||
| 34 | &mov("ecx",&wparam(2)); # | ||
| 35 | &mov($a,&wparam(1)); # | ||
| 36 | |||
| 37 | &and("ecx",0xfffffff8); # num / 8 | ||
| 38 | &mov($w,&wparam(3)); # | ||
| 39 | |||
| 40 | &push("ecx"); # Up the stack for a tmp variable | ||
| 41 | |||
| 42 | &jz(&label("maw_finish")); | ||
| 43 | |||
| 44 | &set_label("maw_loop",0); | ||
| 45 | |||
| 46 | &mov(&swtmp(0),"ecx"); # | ||
| 47 | |||
| 48 | for ($i=0; $i<32; $i+=4) | ||
| 49 | { | ||
| 50 | &comment("Round $i"); | ||
| 51 | |||
| 52 | &mov("eax",&DWP($i,$a,"",0)); # *a | ||
| 53 | &mul($w); # *a * w | ||
| 54 | &add("eax",$c); # L(t)+= *r | ||
| 55 | &mov($c,&DWP($i,$r,"",0)); # L(t)+= *r | ||
| 56 | &adc("edx",0); # H(t)+=carry | ||
| 57 | &add("eax",$c); # L(t)+=c | ||
| 58 | &adc("edx",0); # H(t)+=carry | ||
| 59 | &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t); | ||
| 60 | &mov($c,"edx"); # c= H(t); | ||
| 61 | } | ||
| 62 | |||
| 63 | &comment(""); | ||
| 64 | &mov("ecx",&swtmp(0)); # | ||
| 65 | &add($a,32); | ||
| 66 | &add($r,32); | ||
| 67 | &sub("ecx",8); | ||
| 68 | &jnz(&label("maw_loop")); | ||
| 69 | |||
| 70 | &set_label("maw_finish",0); | ||
| 71 | &mov("ecx",&wparam(2)); # get num | ||
| 72 | &and("ecx",7); | ||
| 73 | &jnz(&label("maw_finish2")); # helps branch prediction | ||
| 74 | &jmp(&label("maw_end")); | ||
| 75 | |||
| 76 | &set_label("maw_finish2",1); | ||
| 77 | for ($i=0; $i<7; $i++) | ||
| 78 | { | ||
| 79 | &comment("Tail Round $i"); | ||
| 80 | &mov("eax",&DWP($i*4,$a,"",0));# *a | ||
| 81 | &mul($w); # *a * w | ||
| 82 | &add("eax",$c); # L(t)+=c | ||
| 83 | &mov($c,&DWP($i*4,$r,"",0)); # L(t)+= *r | ||
| 84 | &adc("edx",0); # H(t)+=carry | ||
| 85 | &add("eax",$c); | ||
| 86 | &adc("edx",0); # H(t)+=carry | ||
| 87 | &dec("ecx") if ($i != 7-1); | ||
| 88 | &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t); | ||
| 89 | &mov($c,"edx"); # c= H(t); | ||
| 90 | &jz(&label("maw_end")) if ($i != 7-1); | ||
| 91 | } | ||
| 92 | &set_label("maw_end",0); | ||
| 93 | &mov("eax",$c); | ||
| 94 | |||
| 95 | &pop("ecx"); # clear variable from | ||
| 96 | |||
| 97 | &function_end($name); | ||
| 98 | } | ||
| 99 | |||
| 100 | sub bn_mul_words | ||
| 101 | { | ||
| 102 | local($name)=@_; | ||
| 103 | |||
| 104 | &function_begin($name,""); | ||
| 105 | |||
| 106 | &comment(""); | ||
| 107 | $Low="eax"; | ||
| 108 | $High="edx"; | ||
| 109 | $a="ebx"; | ||
| 110 | $w="ecx"; | ||
| 111 | $r="edi"; | ||
| 112 | $c="esi"; | ||
| 113 | $num="ebp"; | ||
| 114 | |||
| 115 | &xor($c,$c); # clear carry | ||
| 116 | &mov($r,&wparam(0)); # | ||
| 117 | &mov($a,&wparam(1)); # | ||
| 118 | &mov($num,&wparam(2)); # | ||
| 119 | &mov($w,&wparam(3)); # | ||
| 120 | |||
| 121 | &and($num,0xfffffff8); # num / 8 | ||
| 122 | &jz(&label("mw_finish")); | ||
| 123 | |||
| 124 | &set_label("mw_loop",0); | ||
| 125 | for ($i=0; $i<32; $i+=4) | ||
| 126 | { | ||
| 127 | &comment("Round $i"); | ||
| 128 | |||
| 129 | &mov("eax",&DWP($i,$a,"",0)); # *a | ||
| 130 | &mul($w); # *a * w | ||
| 131 | &add("eax",$c); # L(t)+=c | ||
| 132 | # XXX | ||
| 133 | |||
| 134 | &adc("edx",0); # H(t)+=carry | ||
| 135 | &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t); | ||
| 136 | |||
| 137 | &mov($c,"edx"); # c= H(t); | ||
| 138 | } | ||
| 139 | |||
| 140 | &comment(""); | ||
| 141 | &add($a,32); | ||
| 142 | &add($r,32); | ||
| 143 | &sub($num,8); | ||
| 144 | &jz(&label("mw_finish")); | ||
| 145 | &jmp(&label("mw_loop")); | ||
| 146 | |||
| 147 | &set_label("mw_finish",0); | ||
| 148 | &mov($num,&wparam(2)); # get num | ||
| 149 | &and($num,7); | ||
| 150 | &jnz(&label("mw_finish2")); | ||
| 151 | &jmp(&label("mw_end")); | ||
| 152 | |||
| 153 | &set_label("mw_finish2",1); | ||
| 154 | for ($i=0; $i<7; $i++) | ||
| 155 | { | ||
| 156 | &comment("Tail Round $i"); | ||
| 157 | &mov("eax",&DWP($i*4,$a,"",0));# *a | ||
| 158 | &mul($w); # *a * w | ||
| 159 | &add("eax",$c); # L(t)+=c | ||
| 160 | # XXX | ||
| 161 | &adc("edx",0); # H(t)+=carry | ||
| 162 | &mov(&DWP($i*4,$r,"",0),"eax");# *r= L(t); | ||
| 163 | &mov($c,"edx"); # c= H(t); | ||
| 164 | &dec($num) if ($i != 7-1); | ||
| 165 | &jz(&label("mw_end")) if ($i != 7-1); | ||
| 166 | } | ||
| 167 | &set_label("mw_end",0); | ||
| 168 | &mov("eax",$c); | ||
| 169 | |||
| 170 | &function_end($name); | ||
| 171 | } | ||
| 172 | |||
| 173 | sub bn_sqr_words | ||
| 174 | { | ||
| 175 | local($name)=@_; | ||
| 176 | |||
| 177 | &function_begin($name,""); | ||
| 178 | |||
| 179 | &comment(""); | ||
| 180 | $r="esi"; | ||
| 181 | $a="edi"; | ||
| 182 | $num="ebx"; | ||
| 183 | |||
| 184 | &mov($r,&wparam(0)); # | ||
| 185 | &mov($a,&wparam(1)); # | ||
| 186 | &mov($num,&wparam(2)); # | ||
| 187 | |||
| 188 | &and($num,0xfffffff8); # num / 8 | ||
| 189 | &jz(&label("sw_finish")); | ||
| 190 | |||
| 191 | &set_label("sw_loop",0); | ||
| 192 | for ($i=0; $i<32; $i+=4) | ||
| 193 | { | ||
| 194 | &comment("Round $i"); | ||
| 195 | &mov("eax",&DWP($i,$a,"",0)); # *a | ||
| 196 | # XXX | ||
| 197 | &mul("eax"); # *a * *a | ||
| 198 | &mov(&DWP($i*2,$r,"",0),"eax"); # | ||
| 199 | &mov(&DWP($i*2+4,$r,"",0),"edx");# | ||
| 200 | } | ||
| 201 | |||
| 202 | &comment(""); | ||
| 203 | &add($a,32); | ||
| 204 | &add($r,64); | ||
| 205 | &sub($num,8); | ||
| 206 | &jnz(&label("sw_loop")); | ||
| 207 | |||
| 208 | &set_label("sw_finish",0); | ||
| 209 | &mov($num,&wparam(2)); # get num | ||
| 210 | &and($num,7); | ||
| 211 | &jz(&label("sw_end")); | ||
| 212 | |||
| 213 | for ($i=0; $i<7; $i++) | ||
| 214 | { | ||
| 215 | &comment("Tail Round $i"); | ||
| 216 | &mov("eax",&DWP($i*4,$a,"",0)); # *a | ||
| 217 | # XXX | ||
| 218 | &mul("eax"); # *a * *a | ||
| 219 | &mov(&DWP($i*8,$r,"",0),"eax"); # | ||
| 220 | &dec($num) if ($i != 7-1); | ||
| 221 | &mov(&DWP($i*8+4,$r,"",0),"edx"); | ||
| 222 | &jz(&label("sw_end")) if ($i != 7-1); | ||
| 223 | } | ||
| 224 | &set_label("sw_end",0); | ||
| 225 | |||
| 226 | &function_end($name); | ||
| 227 | } | ||
| 228 | |||
| 229 | sub bn_div_words | ||
| 230 | { | ||
| 231 | local($name)=@_; | ||
| 232 | |||
| 233 | &function_begin($name,""); | ||
| 234 | &mov("edx",&wparam(0)); # | ||
| 235 | &mov("eax",&wparam(1)); # | ||
| 236 | &mov("ebx",&wparam(2)); # | ||
| 237 | &div("ebx"); | ||
| 238 | &function_end($name); | ||
| 239 | } | ||
| 240 | |||
| 241 | sub bn_add_words | ||
| 242 | { | ||
| 243 | local($name)=@_; | ||
| 244 | |||
| 245 | &function_begin($name,""); | ||
| 246 | |||
| 247 | &comment(""); | ||
| 248 | $a="esi"; | ||
| 249 | $b="edi"; | ||
| 250 | $c="eax"; | ||
| 251 | $r="ebx"; | ||
| 252 | $tmp1="ecx"; | ||
| 253 | $tmp2="edx"; | ||
| 254 | $num="ebp"; | ||
| 255 | |||
| 256 | &mov($r,&wparam(0)); # get r | ||
| 257 | &mov($a,&wparam(1)); # get a | ||
| 258 | &mov($b,&wparam(2)); # get b | ||
| 259 | &mov($num,&wparam(3)); # get num | ||
| 260 | &xor($c,$c); # clear carry | ||
| 261 | &and($num,0xfffffff8); # num / 8 | ||
| 262 | |||
| 263 | &jz(&label("aw_finish")); | ||
| 264 | |||
| 265 | &set_label("aw_loop",0); | ||
| 266 | for ($i=0; $i<8; $i++) | ||
| 267 | { | ||
| 268 | &comment("Round $i"); | ||
| 269 | |||
| 270 | &mov($tmp1,&DWP($i*4,$a,"",0)); # *a | ||
| 271 | &mov($tmp2,&DWP($i*4,$b,"",0)); # *b | ||
| 272 | &add($tmp1,$c); | ||
| 273 | &mov($c,0); | ||
| 274 | &adc($c,$c); | ||
| 275 | &add($tmp1,$tmp2); | ||
| 276 | &adc($c,0); | ||
| 277 | &mov(&DWP($i*4,$r,"",0),$tmp1); # *r | ||
| 278 | } | ||
| 279 | |||
| 280 | &comment(""); | ||
| 281 | &add($a,32); | ||
| 282 | &add($b,32); | ||
| 283 | &add($r,32); | ||
| 284 | &sub($num,8); | ||
| 285 | &jnz(&label("aw_loop")); | ||
| 286 | |||
| 287 | &set_label("aw_finish",0); | ||
| 288 | &mov($num,&wparam(3)); # get num | ||
| 289 | &and($num,7); | ||
| 290 | &jz(&label("aw_end")); | ||
| 291 | |||
| 292 | for ($i=0; $i<7; $i++) | ||
| 293 | { | ||
| 294 | &comment("Tail Round $i"); | ||
| 295 | &mov($tmp1,&DWP($i*4,$a,"",0)); # *a | ||
| 296 | &mov($tmp2,&DWP($i*4,$b,"",0));# *b | ||
| 297 | &add($tmp1,$c); | ||
| 298 | &mov($c,0); | ||
| 299 | &adc($c,$c); | ||
| 300 | &add($tmp1,$tmp2); | ||
| 301 | &adc($c,0); | ||
| 302 | &dec($num) if ($i != 6); | ||
| 303 | &mov(&DWP($i*4,$r,"",0),$tmp1); # *a | ||
| 304 | &jz(&label("aw_end")) if ($i != 6); | ||
| 305 | } | ||
| 306 | &set_label("aw_end",0); | ||
| 307 | |||
| 308 | # &mov("eax",$c); # $c is "eax" | ||
| 309 | |||
| 310 | &function_end($name); | ||
| 311 | } | ||
| 312 | |||
| 313 | sub bn_sub_words | ||
| 314 | { | ||
| 315 | local($name)=@_; | ||
| 316 | |||
| 317 | &function_begin($name,""); | ||
| 318 | |||
| 319 | &comment(""); | ||
| 320 | $a="esi"; | ||
| 321 | $b="edi"; | ||
| 322 | $c="eax"; | ||
| 323 | $r="ebx"; | ||
| 324 | $tmp1="ecx"; | ||
| 325 | $tmp2="edx"; | ||
| 326 | $num="ebp"; | ||
| 327 | |||
| 328 | &mov($r,&wparam(0)); # get r | ||
| 329 | &mov($a,&wparam(1)); # get a | ||
| 330 | &mov($b,&wparam(2)); # get b | ||
| 331 | &mov($num,&wparam(3)); # get num | ||
| 332 | &xor($c,$c); # clear carry | ||
| 333 | &and($num,0xfffffff8); # num / 8 | ||
| 334 | |||
| 335 | &jz(&label("aw_finish")); | ||
| 336 | |||
| 337 | &set_label("aw_loop",0); | ||
| 338 | for ($i=0; $i<8; $i++) | ||
| 339 | { | ||
| 340 | &comment("Round $i"); | ||
| 341 | |||
| 342 | &mov($tmp1,&DWP($i*4,$a,"",0)); # *a | ||
| 343 | &mov($tmp2,&DWP($i*4,$b,"",0)); # *b | ||
| 344 | &sub($tmp1,$c); | ||
| 345 | &mov($c,0); | ||
| 346 | &adc($c,$c); | ||
| 347 | &sub($tmp1,$tmp2); | ||
| 348 | &adc($c,0); | ||
| 349 | &mov(&DWP($i*4,$r,"",0),$tmp1); # *r | ||
| 350 | } | ||
| 351 | |||
| 352 | &comment(""); | ||
| 353 | &add($a,32); | ||
| 354 | &add($b,32); | ||
| 355 | &add($r,32); | ||
| 356 | &sub($num,8); | ||
| 357 | &jnz(&label("aw_loop")); | ||
| 358 | |||
| 359 | &set_label("aw_finish",0); | ||
| 360 | &mov($num,&wparam(3)); # get num | ||
| 361 | &and($num,7); | ||
| 362 | &jz(&label("aw_end")); | ||
| 363 | |||
| 364 | for ($i=0; $i<7; $i++) | ||
| 365 | { | ||
| 366 | &comment("Tail Round $i"); | ||
| 367 | &mov($tmp1,&DWP($i*4,$a,"",0)); # *a | ||
| 368 | &mov($tmp2,&DWP($i*4,$b,"",0));# *b | ||
| 369 | &sub($tmp1,$c); | ||
| 370 | &mov($c,0); | ||
| 371 | &adc($c,$c); | ||
| 372 | &sub($tmp1,$tmp2); | ||
| 373 | &adc($c,0); | ||
| 374 | &dec($num) if ($i != 6); | ||
| 375 | &mov(&DWP($i*4,$r,"",0),$tmp1); # *a | ||
| 376 | &jz(&label("aw_end")) if ($i != 6); | ||
| 377 | } | ||
| 378 | &set_label("aw_end",0); | ||
| 379 | |||
| 380 | # &mov("eax",$c); # $c is "eax" | ||
| 381 | |||
| 382 | &function_end($name); | ||
| 383 | } | ||
| 384 | |||
diff --git a/src/lib/libcrypto/bn/asm/co-586.pl b/src/lib/libcrypto/bn/asm/co-586.pl deleted file mode 100644 index 5d962cb957..0000000000 --- a/src/lib/libcrypto/bn/asm/co-586.pl +++ /dev/null | |||
| @@ -1,286 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | push(@INC,"perlasm","../../perlasm"); | ||
| 4 | require "x86asm.pl"; | ||
| 5 | |||
| 6 | &asm_init($ARGV[0],$0); | ||
| 7 | |||
| 8 | &bn_mul_comba("bn_mul_comba8",8); | ||
| 9 | &bn_mul_comba("bn_mul_comba4",4); | ||
| 10 | &bn_sqr_comba("bn_sqr_comba8",8); | ||
| 11 | &bn_sqr_comba("bn_sqr_comba4",4); | ||
| 12 | |||
| 13 | &asm_finish(); | ||
| 14 | |||
| 15 | sub mul_add_c | ||
| 16 | { | ||
| 17 | local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_; | ||
| 18 | |||
| 19 | # pos == -1 if eax and edx are pre-loaded, 0 to load from next | ||
| 20 | # words, and 1 if load return value | ||
| 21 | |||
| 22 | &comment("mul a[$ai]*b[$bi]"); | ||
| 23 | |||
| 24 | # "eax" and "edx" will always be pre-loaded. | ||
| 25 | # &mov("eax",&DWP($ai*4,$a,"",0)) ; | ||
| 26 | # &mov("edx",&DWP($bi*4,$b,"",0)); | ||
| 27 | |||
| 28 | &mul("edx"); | ||
| 29 | &add($c0,"eax"); | ||
| 30 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a | ||
| 31 | &mov("eax",&wparam(0)) if $pos > 0; # load r[] | ||
| 32 | ### | ||
| 33 | &adc($c1,"edx"); | ||
| 34 | &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b | ||
| 35 | &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b | ||
| 36 | ### | ||
| 37 | &adc($c2,0); | ||
| 38 | # is pos > 1, it means it is the last loop | ||
| 39 | &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[]; | ||
| 40 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a | ||
| 41 | } | ||
| 42 | |||
| 43 | sub sqr_add_c | ||
| 44 | { | ||
| 45 | local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_; | ||
| 46 | |||
| 47 | # pos == -1 if eax and edx are pre-loaded, 0 to load from next | ||
| 48 | # words, and 1 if load return value | ||
| 49 | |||
| 50 | &comment("sqr a[$ai]*a[$bi]"); | ||
| 51 | |||
| 52 | # "eax" and "edx" will always be pre-loaded. | ||
| 53 | # &mov("eax",&DWP($ai*4,$a,"",0)) ; | ||
| 54 | # &mov("edx",&DWP($bi*4,$b,"",0)); | ||
| 55 | |||
| 56 | if ($ai == $bi) | ||
| 57 | { &mul("eax");} | ||
| 58 | else | ||
| 59 | { &mul("edx");} | ||
| 60 | &add($c0,"eax"); | ||
| 61 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a | ||
| 62 | ### | ||
| 63 | &adc($c1,"edx"); | ||
| 64 | &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb); | ||
| 65 | ### | ||
| 66 | &adc($c2,0); | ||
| 67 | # is pos > 1, it means it is the last loop | ||
| 68 | &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[]; | ||
| 69 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b | ||
| 70 | } | ||
| 71 | |||
| 72 | sub sqr_add_c2 | ||
| 73 | { | ||
| 74 | local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_; | ||
| 75 | |||
| 76 | # pos == -1 if eax and edx are pre-loaded, 0 to load from next | ||
| 77 | # words, and 1 if load return value | ||
| 78 | |||
| 79 | &comment("sqr a[$ai]*a[$bi]"); | ||
| 80 | |||
| 81 | # "eax" and "edx" will always be pre-loaded. | ||
| 82 | # &mov("eax",&DWP($ai*4,$a,"",0)) ; | ||
| 83 | # &mov("edx",&DWP($bi*4,$a,"",0)); | ||
| 84 | |||
| 85 | if ($ai == $bi) | ||
| 86 | { &mul("eax");} | ||
| 87 | else | ||
| 88 | { &mul("edx");} | ||
| 89 | &add("eax","eax"); | ||
| 90 | ### | ||
| 91 | &adc("edx","edx"); | ||
| 92 | ### | ||
| 93 | &adc($c2,0); | ||
| 94 | &add($c0,"eax"); | ||
| 95 | &adc($c1,"edx"); | ||
| 96 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a | ||
| 97 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b | ||
| 98 | &adc($c2,0); | ||
| 99 | &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[]; | ||
| 100 | &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb); | ||
| 101 | ### | ||
| 102 | } | ||
| 103 | |||
| 104 | sub bn_mul_comba | ||
| 105 | { | ||
| 106 | local($name,$num)=@_; | ||
| 107 | local($a,$b,$c0,$c1,$c2); | ||
| 108 | local($i,$as,$ae,$bs,$be,$ai,$bi); | ||
| 109 | local($tot,$end); | ||
| 110 | |||
| 111 | &function_begin_B($name,""); | ||
| 112 | |||
| 113 | $c0="ebx"; | ||
| 114 | $c1="ecx"; | ||
| 115 | $c2="ebp"; | ||
| 116 | $a="esi"; | ||
| 117 | $b="edi"; | ||
| 118 | |||
| 119 | $as=0; | ||
| 120 | $ae=0; | ||
| 121 | $bs=0; | ||
| 122 | $be=0; | ||
| 123 | $tot=$num+$num-1; | ||
| 124 | |||
| 125 | &push("esi"); | ||
| 126 | &mov($a,&wparam(1)); | ||
| 127 | &push("edi"); | ||
| 128 | &mov($b,&wparam(2)); | ||
| 129 | &push("ebp"); | ||
| 130 | &push("ebx"); | ||
| 131 | |||
| 132 | &xor($c0,$c0); | ||
| 133 | &mov("eax",&DWP(0,$a,"",0)); # load the first word | ||
| 134 | &xor($c1,$c1); | ||
| 135 | &mov("edx",&DWP(0,$b,"",0)); # load the first second | ||
| 136 | |||
| 137 | for ($i=0; $i<$tot; $i++) | ||
| 138 | { | ||
| 139 | $ai=$as; | ||
| 140 | $bi=$bs; | ||
| 141 | $end=$be+1; | ||
| 142 | |||
| 143 | &comment("################## Calculate word $i"); | ||
| 144 | |||
| 145 | for ($j=$bs; $j<$end; $j++) | ||
| 146 | { | ||
| 147 | &xor($c2,$c2) if ($j == $bs); | ||
| 148 | if (($j+1) == $end) | ||
| 149 | { | ||
| 150 | $v=1; | ||
| 151 | $v=2 if (($i+1) == $tot); | ||
| 152 | } | ||
| 153 | else | ||
| 154 | { $v=0; } | ||
| 155 | if (($j+1) != $end) | ||
| 156 | { | ||
| 157 | $na=($ai-1); | ||
| 158 | $nb=($bi+1); | ||
| 159 | } | ||
| 160 | else | ||
| 161 | { | ||
| 162 | $na=$as+($i < ($num-1)); | ||
| 163 | $nb=$bs+($i >= ($num-1)); | ||
| 164 | } | ||
| 165 | #printf STDERR "[$ai,$bi] -> [$na,$nb]\n"; | ||
| 166 | &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb); | ||
| 167 | if ($v) | ||
| 168 | { | ||
| 169 | &comment("saved r[$i]"); | ||
| 170 | # &mov("eax",&wparam(0)); | ||
| 171 | # &mov(&DWP($i*4,"eax","",0),$c0); | ||
| 172 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 173 | } | ||
| 174 | $ai--; | ||
| 175 | $bi++; | ||
| 176 | } | ||
| 177 | $as++ if ($i < ($num-1)); | ||
| 178 | $ae++ if ($i >= ($num-1)); | ||
| 179 | |||
| 180 | $bs++ if ($i >= ($num-1)); | ||
| 181 | $be++ if ($i < ($num-1)); | ||
| 182 | } | ||
| 183 | &comment("save r[$i]"); | ||
| 184 | # &mov("eax",&wparam(0)); | ||
| 185 | &mov(&DWP($i*4,"eax","",0),$c0); | ||
| 186 | |||
| 187 | &pop("ebx"); | ||
| 188 | &pop("ebp"); | ||
| 189 | &pop("edi"); | ||
| 190 | &pop("esi"); | ||
| 191 | &ret(); | ||
| 192 | &function_end_B($name); | ||
| 193 | } | ||
| 194 | |||
| 195 | sub bn_sqr_comba | ||
| 196 | { | ||
| 197 | local($name,$num)=@_; | ||
| 198 | local($r,$a,$c0,$c1,$c2)=@_; | ||
| 199 | local($i,$as,$ae,$bs,$be,$ai,$bi); | ||
| 200 | local($b,$tot,$end,$half); | ||
| 201 | |||
| 202 | &function_begin_B($name,""); | ||
| 203 | |||
| 204 | $c0="ebx"; | ||
| 205 | $c1="ecx"; | ||
| 206 | $c2="ebp"; | ||
| 207 | $a="esi"; | ||
| 208 | $r="edi"; | ||
| 209 | |||
| 210 | &push("esi"); | ||
| 211 | &push("edi"); | ||
| 212 | &push("ebp"); | ||
| 213 | &push("ebx"); | ||
| 214 | &mov($r,&wparam(0)); | ||
| 215 | &mov($a,&wparam(1)); | ||
| 216 | &xor($c0,$c0); | ||
| 217 | &xor($c1,$c1); | ||
| 218 | &mov("eax",&DWP(0,$a,"",0)); # load the first word | ||
| 219 | |||
| 220 | $as=0; | ||
| 221 | $ae=0; | ||
| 222 | $bs=0; | ||
| 223 | $be=0; | ||
| 224 | $tot=$num+$num-1; | ||
| 225 | |||
| 226 | for ($i=0; $i<$tot; $i++) | ||
| 227 | { | ||
| 228 | $ai=$as; | ||
| 229 | $bi=$bs; | ||
| 230 | $end=$be+1; | ||
| 231 | |||
| 232 | &comment("############### Calculate word $i"); | ||
| 233 | for ($j=$bs; $j<$end; $j++) | ||
| 234 | { | ||
| 235 | &xor($c2,$c2) if ($j == $bs); | ||
| 236 | if (($ai-1) < ($bi+1)) | ||
| 237 | { | ||
| 238 | $v=1; | ||
| 239 | $v=2 if ($i+1) == $tot; | ||
| 240 | } | ||
| 241 | else | ||
| 242 | { $v=0; } | ||
| 243 | if (!$v) | ||
| 244 | { | ||
| 245 | $na=$ai-1; | ||
| 246 | $nb=$bi+1; | ||
| 247 | } | ||
| 248 | else | ||
| 249 | { | ||
| 250 | $na=$as+($i < ($num-1)); | ||
| 251 | $nb=$bs+($i >= ($num-1)); | ||
| 252 | } | ||
| 253 | if ($ai == $bi) | ||
| 254 | { | ||
| 255 | &sqr_add_c($r,$a,$ai,$bi, | ||
| 256 | $c0,$c1,$c2,$v,$i,$na,$nb); | ||
| 257 | } | ||
| 258 | else | ||
| 259 | { | ||
| 260 | &sqr_add_c2($r,$a,$ai,$bi, | ||
| 261 | $c0,$c1,$c2,$v,$i,$na,$nb); | ||
| 262 | } | ||
| 263 | if ($v) | ||
| 264 | { | ||
| 265 | &comment("saved r[$i]"); | ||
| 266 | #&mov(&DWP($i*4,$r,"",0),$c0); | ||
| 267 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 268 | last; | ||
| 269 | } | ||
| 270 | $ai--; | ||
| 271 | $bi++; | ||
| 272 | } | ||
| 273 | $as++ if ($i < ($num-1)); | ||
| 274 | $ae++ if ($i >= ($num-1)); | ||
| 275 | |||
| 276 | $bs++ if ($i >= ($num-1)); | ||
| 277 | $be++ if ($i < ($num-1)); | ||
| 278 | } | ||
| 279 | &mov(&DWP($i*4,$r,"",0),$c0); | ||
| 280 | &pop("ebx"); | ||
| 281 | &pop("ebp"); | ||
| 282 | &pop("edi"); | ||
| 283 | &pop("esi"); | ||
| 284 | &ret(); | ||
| 285 | &function_end_B($name); | ||
| 286 | } | ||
diff --git a/src/lib/libcrypto/bn/asm/pa-risc2.s b/src/lib/libcrypto/bn/asm/pa-risc2.s deleted file mode 100644 index c2725996a4..0000000000 --- a/src/lib/libcrypto/bn/asm/pa-risc2.s +++ /dev/null | |||
| @@ -1,416 +0,0 @@ | |||
| 1 | .SPACE $PRIVATE$ | ||
| 2 | .SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31 | ||
| 3 | .SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82 | ||
| 4 | .SPACE $TEXT$ | ||
| 5 | .SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44 | ||
| 6 | .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY | ||
| 7 | .IMPORT $global$,DATA | ||
| 8 | .IMPORT $$dyncall,MILLICODE | ||
| 9 | ; gcc_compiled.: | ||
| 10 | .SPACE $TEXT$ | ||
| 11 | .SUBSPA $CODE$ | ||
| 12 | |||
| 13 | .align 4 | ||
| 14 | .EXPORT bn_mul_add_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR | ||
| 15 | bn_mul_add_words | ||
| 16 | .PROC | ||
| 17 | .CALLINFO FRAME=64,CALLS,SAVE_RP,ENTRY_GR=4 | ||
| 18 | .ENTRY | ||
| 19 | stw %r2,-20(0,%r30) | ||
| 20 | stwm %r4,64(0,%r30) | ||
| 21 | copy %r24,%r31 | ||
| 22 | stw %r3,-60(0,%r30) | ||
| 23 | ldi 0,%r20 | ||
| 24 | ldo 12(%r26),%r2 | ||
| 25 | stw %r23,-16(0,%r30) | ||
| 26 | copy %r25,%r3 | ||
| 27 | ldo 12(%r3),%r1 | ||
| 28 | fldws -16(0,%r30),%fr8L | ||
| 29 | L$0010 | ||
| 30 | copy %r20,%r25 | ||
| 31 | ldi 0,%r24 | ||
| 32 | fldws 0(0,%r3),%fr9L | ||
| 33 | ldw 0(0,%r26),%r19 | ||
| 34 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 35 | fstds %fr9,-16(0,%r30) | ||
| 36 | copy %r19,%r23 | ||
| 37 | ldw -16(0,%r30),%r28 | ||
| 38 | ldw -12(0,%r30),%r29 | ||
| 39 | ldi 0,%r22 | ||
| 40 | add %r23,%r29,%r29 | ||
| 41 | addc %r22,%r28,%r28 | ||
| 42 | add %r25,%r29,%r29 | ||
| 43 | addc %r24,%r28,%r28 | ||
| 44 | copy %r28,%r21 | ||
| 45 | ldi 0,%r20 | ||
| 46 | copy %r21,%r20 | ||
| 47 | addib,= -1,%r31,L$0011 | ||
| 48 | stw %r29,0(0,%r26) | ||
| 49 | copy %r20,%r25 | ||
| 50 | ldi 0,%r24 | ||
| 51 | fldws -8(0,%r1),%fr9L | ||
| 52 | ldw -8(0,%r2),%r19 | ||
| 53 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 54 | fstds %fr9,-16(0,%r30) | ||
| 55 | copy %r19,%r23 | ||
| 56 | ldw -16(0,%r30),%r28 | ||
| 57 | ldw -12(0,%r30),%r29 | ||
| 58 | ldi 0,%r22 | ||
| 59 | add %r23,%r29,%r29 | ||
| 60 | addc %r22,%r28,%r28 | ||
| 61 | add %r25,%r29,%r29 | ||
| 62 | addc %r24,%r28,%r28 | ||
| 63 | copy %r28,%r21 | ||
| 64 | ldi 0,%r20 | ||
| 65 | copy %r21,%r20 | ||
| 66 | addib,= -1,%r31,L$0011 | ||
| 67 | stw %r29,-8(0,%r2) | ||
| 68 | copy %r20,%r25 | ||
| 69 | ldi 0,%r24 | ||
| 70 | fldws -4(0,%r1),%fr9L | ||
| 71 | ldw -4(0,%r2),%r19 | ||
| 72 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 73 | fstds %fr9,-16(0,%r30) | ||
| 74 | copy %r19,%r23 | ||
| 75 | ldw -16(0,%r30),%r28 | ||
| 76 | ldw -12(0,%r30),%r29 | ||
| 77 | ldi 0,%r22 | ||
| 78 | add %r23,%r29,%r29 | ||
| 79 | addc %r22,%r28,%r28 | ||
| 80 | add %r25,%r29,%r29 | ||
| 81 | addc %r24,%r28,%r28 | ||
| 82 | copy %r28,%r21 | ||
| 83 | ldi 0,%r20 | ||
| 84 | copy %r21,%r20 | ||
| 85 | addib,= -1,%r31,L$0011 | ||
| 86 | stw %r29,-4(0,%r2) | ||
| 87 | copy %r20,%r25 | ||
| 88 | ldi 0,%r24 | ||
| 89 | fldws 0(0,%r1),%fr9L | ||
| 90 | ldw 0(0,%r2),%r19 | ||
| 91 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 92 | fstds %fr9,-16(0,%r30) | ||
| 93 | copy %r19,%r23 | ||
| 94 | ldw -16(0,%r30),%r28 | ||
| 95 | ldw -12(0,%r30),%r29 | ||
| 96 | ldi 0,%r22 | ||
| 97 | add %r23,%r29,%r29 | ||
| 98 | addc %r22,%r28,%r28 | ||
| 99 | add %r25,%r29,%r29 | ||
| 100 | addc %r24,%r28,%r28 | ||
| 101 | copy %r28,%r21 | ||
| 102 | ldi 0,%r20 | ||
| 103 | copy %r21,%r20 | ||
| 104 | addib,= -1,%r31,L$0011 | ||
| 105 | stw %r29,0(0,%r2) | ||
| 106 | ldo 16(%r1),%r1 | ||
| 107 | ldo 16(%r3),%r3 | ||
| 108 | ldo 16(%r2),%r2 | ||
| 109 | bl L$0010,0 | ||
| 110 | ldo 16(%r26),%r26 | ||
| 111 | L$0011 | ||
| 112 | copy %r20,%r28 | ||
| 113 | ldw -84(0,%r30),%r2 | ||
| 114 | ldw -60(0,%r30),%r3 | ||
| 115 | bv 0(%r2) | ||
| 116 | ldwm -64(0,%r30),%r4 | ||
| 117 | .EXIT | ||
| 118 | .PROCEND | ||
| 119 | .align 4 | ||
| 120 | .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR | ||
| 121 | bn_mul_words | ||
| 122 | .PROC | ||
| 123 | .CALLINFO FRAME=64,CALLS,SAVE_RP,ENTRY_GR=3 | ||
| 124 | .ENTRY | ||
| 125 | stw %r2,-20(0,%r30) | ||
| 126 | copy %r25,%r2 | ||
| 127 | stwm %r4,64(0,%r30) | ||
| 128 | copy %r24,%r19 | ||
| 129 | ldi 0,%r28 | ||
| 130 | stw %r23,-16(0,%r30) | ||
| 131 | ldo 12(%r26),%r31 | ||
| 132 | ldo 12(%r2),%r29 | ||
| 133 | fldws -16(0,%r30),%fr8L | ||
| 134 | L$0026 | ||
| 135 | fldws 0(0,%r2),%fr9L | ||
| 136 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 137 | fstds %fr9,-16(0,%r30) | ||
| 138 | copy %r28,%r21 | ||
| 139 | ldi 0,%r20 | ||
| 140 | ldw -16(0,%r30),%r24 | ||
| 141 | ldw -12(0,%r30),%r25 | ||
| 142 | add %r21,%r25,%r25 | ||
| 143 | addc %r20,%r24,%r24 | ||
| 144 | copy %r24,%r23 | ||
| 145 | ldi 0,%r22 | ||
| 146 | copy %r23,%r28 | ||
| 147 | addib,= -1,%r19,L$0027 | ||
| 148 | stw %r25,0(0,%r26) | ||
| 149 | fldws -8(0,%r29),%fr9L | ||
| 150 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 151 | fstds %fr9,-16(0,%r30) | ||
| 152 | copy %r28,%r21 | ||
| 153 | ldi 0,%r20 | ||
| 154 | ldw -16(0,%r30),%r24 | ||
| 155 | ldw -12(0,%r30),%r25 | ||
| 156 | add %r21,%r25,%r25 | ||
| 157 | addc %r20,%r24,%r24 | ||
| 158 | copy %r24,%r23 | ||
| 159 | ldi 0,%r22 | ||
| 160 | copy %r23,%r28 | ||
| 161 | addib,= -1,%r19,L$0027 | ||
| 162 | stw %r25,-8(0,%r31) | ||
| 163 | fldws -4(0,%r29),%fr9L | ||
| 164 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 165 | fstds %fr9,-16(0,%r30) | ||
| 166 | copy %r28,%r21 | ||
| 167 | ldi 0,%r20 | ||
| 168 | ldw -16(0,%r30),%r24 | ||
| 169 | ldw -12(0,%r30),%r25 | ||
| 170 | add %r21,%r25,%r25 | ||
| 171 | addc %r20,%r24,%r24 | ||
| 172 | copy %r24,%r23 | ||
| 173 | ldi 0,%r22 | ||
| 174 | copy %r23,%r28 | ||
| 175 | addib,= -1,%r19,L$0027 | ||
| 176 | stw %r25,-4(0,%r31) | ||
| 177 | fldws 0(0,%r29),%fr9L | ||
| 178 | xmpyu %fr8L,%fr9L,%fr9 | ||
| 179 | fstds %fr9,-16(0,%r30) | ||
| 180 | copy %r28,%r21 | ||
| 181 | ldi 0,%r20 | ||
| 182 | ldw -16(0,%r30),%r24 | ||
| 183 | ldw -12(0,%r30),%r25 | ||
| 184 | add %r21,%r25,%r25 | ||
| 185 | addc %r20,%r24,%r24 | ||
| 186 | copy %r24,%r23 | ||
| 187 | ldi 0,%r22 | ||
| 188 | copy %r23,%r28 | ||
| 189 | addib,= -1,%r19,L$0027 | ||
| 190 | stw %r25,0(0,%r31) | ||
| 191 | ldo 16(%r29),%r29 | ||
| 192 | ldo 16(%r2),%r2 | ||
| 193 | ldo 16(%r31),%r31 | ||
| 194 | bl L$0026,0 | ||
| 195 | ldo 16(%r26),%r26 | ||
| 196 | L$0027 | ||
| 197 | ldw -84(0,%r30),%r2 | ||
| 198 | bv 0(%r2) | ||
| 199 | ldwm -64(0,%r30),%r4 | ||
| 200 | .EXIT | ||
| 201 | .PROCEND | ||
| 202 | .align 4 | ||
| 203 | .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR | ||
| 204 | bn_sqr_words | ||
| 205 | .PROC | ||
| 206 | .CALLINFO FRAME=0,NO_CALLS | ||
| 207 | .ENTRY | ||
| 208 | ldo 28(%r26),%r19 | ||
| 209 | ldo 12(%r25),%r28 | ||
| 210 | L$0042 | ||
| 211 | fldws 0(0,%r25),%fr8L | ||
| 212 | fldws 0(0,%r25),%fr8R | ||
| 213 | xmpyu %fr8L,%fr8R,%fr8 | ||
| 214 | fstds %fr8,-16(0,%r30) | ||
| 215 | ldw -16(0,%r30),%r22 | ||
| 216 | ldw -12(0,%r30),%r23 | ||
| 217 | stw %r23,0(0,%r26) | ||
| 218 | copy %r22,%r21 | ||
| 219 | ldi 0,%r20 | ||
| 220 | addib,= -1,%r24,L$0049 | ||
| 221 | stw %r21,-24(0,%r19) | ||
| 222 | fldws -8(0,%r28),%fr8L | ||
| 223 | fldws -8(0,%r28),%fr8R | ||
| 224 | xmpyu %fr8L,%fr8R,%fr8 | ||
| 225 | fstds %fr8,-16(0,%r30) | ||
| 226 | ldw -16(0,%r30),%r22 | ||
| 227 | ldw -12(0,%r30),%r23 | ||
| 228 | stw %r23,-20(0,%r19) | ||
| 229 | copy %r22,%r21 | ||
| 230 | ldi 0,%r20 | ||
| 231 | addib,= -1,%r24,L$0049 | ||
| 232 | stw %r21,-16(0,%r19) | ||
| 233 | fldws -4(0,%r28),%fr8L | ||
| 234 | fldws -4(0,%r28),%fr8R | ||
| 235 | xmpyu %fr8L,%fr8R,%fr8 | ||
| 236 | fstds %fr8,-16(0,%r30) | ||
| 237 | ldw -16(0,%r30),%r22 | ||
| 238 | ldw -12(0,%r30),%r23 | ||
| 239 | stw %r23,-12(0,%r19) | ||
| 240 | copy %r22,%r21 | ||
| 241 | ldi 0,%r20 | ||
| 242 | addib,= -1,%r24,L$0049 | ||
| 243 | stw %r21,-8(0,%r19) | ||
| 244 | fldws 0(0,%r28),%fr8L | ||
| 245 | fldws 0(0,%r28),%fr8R | ||
| 246 | xmpyu %fr8L,%fr8R,%fr8 | ||
| 247 | fstds %fr8,-16(0,%r30) | ||
| 248 | ldw -16(0,%r30),%r22 | ||
| 249 | ldw -12(0,%r30),%r23 | ||
| 250 | stw %r23,-4(0,%r19) | ||
| 251 | copy %r22,%r21 | ||
| 252 | ldi 0,%r20 | ||
| 253 | addib,= -1,%r24,L$0049 | ||
| 254 | stw %r21,0(0,%r19) | ||
| 255 | ldo 16(%r28),%r28 | ||
| 256 | ldo 16(%r25),%r25 | ||
| 257 | ldo 32(%r19),%r19 | ||
| 258 | bl L$0042,0 | ||
| 259 | ldo 32(%r26),%r26 | ||
| 260 | L$0049 | ||
| 261 | bv,n 0(%r2) | ||
| 262 | .EXIT | ||
| 263 | .PROCEND | ||
| 264 | .IMPORT BN_num_bits_word,CODE | ||
| 265 | .IMPORT fprintf,CODE | ||
| 266 | .IMPORT __iob,DATA | ||
| 267 | .SPACE $TEXT$ | ||
| 268 | .SUBSPA $LIT$ | ||
| 269 | |||
| 270 | .align 4 | ||
| 271 | L$C0000 | ||
| 272 | .STRING "Division would overflow (%d)\x0a\x00" | ||
| 273 | .IMPORT abort,CODE | ||
| 274 | .SPACE $TEXT$ | ||
| 275 | .SUBSPA $CODE$ | ||
| 276 | |||
| 277 | .align 4 | ||
| 278 | .EXPORT bn_div64,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR | ||
| 279 | bn_div64 | ||
| 280 | .PROC | ||
| 281 | .CALLINFO FRAME=128,CALLS,SAVE_RP,ENTRY_GR=8 | ||
| 282 | .ENTRY | ||
| 283 | stw %r2,-20(0,%r30) | ||
| 284 | stwm %r8,128(0,%r30) | ||
| 285 | stw %r7,-124(0,%r30) | ||
| 286 | stw %r4,-112(0,%r30) | ||
| 287 | stw %r3,-108(0,%r30) | ||
| 288 | copy %r26,%r3 | ||
| 289 | copy %r25,%r4 | ||
| 290 | stw %r6,-120(0,%r30) | ||
| 291 | ldi 0,%r7 | ||
| 292 | stw %r5,-116(0,%r30) | ||
| 293 | movb,<> %r24,%r5,L$0051 | ||
| 294 | ldi 2,%r6 | ||
| 295 | bl L$0068,0 | ||
| 296 | ldi -1,%r28 | ||
| 297 | L$0051 | ||
| 298 | .CALL ARGW0=GR | ||
| 299 | bl BN_num_bits_word,%r2 | ||
| 300 | copy %r5,%r26 | ||
| 301 | copy %r28,%r24 | ||
| 302 | ldi 32,%r19 | ||
| 303 | comb,= %r19,%r24,L$0052 | ||
| 304 | subi 31,%r24,%r19 | ||
| 305 | mtsar %r19 | ||
| 306 | zvdepi 1,32,%r19 | ||
| 307 | comb,>>= %r19,%r3,L$0052 | ||
| 308 | addil LR'__iob-$global$+32,%r27 | ||
| 309 | ldo RR'__iob-$global$+32(%r1),%r26 | ||
| 310 | ldil LR'L$C0000,%r25 | ||
| 311 | .CALL ARGW0=GR,ARGW1=GR,ARGW2=GR | ||
| 312 | bl fprintf,%r2 | ||
| 313 | ldo RR'L$C0000(%r25),%r25 | ||
| 314 | .CALL | ||
| 315 | bl abort,%r2 | ||
| 316 | nop | ||
| 317 | L$0052 | ||
| 318 | comb,>> %r5,%r3,L$0053 | ||
| 319 | subi 32,%r24,%r24 | ||
| 320 | sub %r3,%r5,%r3 | ||
| 321 | L$0053 | ||
| 322 | comib,= 0,%r24,L$0054 | ||
| 323 | subi 31,%r24,%r19 | ||
| 324 | mtsar %r19 | ||
| 325 | zvdep %r5,32,%r5 | ||
| 326 | zvdep %r3,32,%r21 | ||
| 327 | subi 32,%r24,%r20 | ||
| 328 | mtsar %r20 | ||
| 329 | vshd 0,%r4,%r20 | ||
| 330 | or %r21,%r20,%r3 | ||
| 331 | mtsar %r19 | ||
| 332 | zvdep %r4,32,%r4 | ||
| 333 | L$0054 | ||
| 334 | extru %r5,15,16,%r23 | ||
| 335 | extru %r5,31,16,%r28 | ||
| 336 | L$0055 | ||
| 337 | extru %r3,15,16,%r19 | ||
| 338 | comb,<> %r23,%r19,L$0058 | ||
| 339 | copy %r3,%r26 | ||
| 340 | bl L$0059,0 | ||
| 341 | zdepi -1,31,16,%r29 | ||
| 342 | L$0058 | ||
| 343 | .IMPORT $$divU,MILLICODE | ||
| 344 | bl $$divU,%r31 | ||
| 345 | copy %r23,%r25 | ||
| 346 | L$0059 | ||
| 347 | stw %r29,-16(0,%r30) | ||
| 348 | fldws -16(0,%r30),%fr10L | ||
| 349 | stw %r28,-16(0,%r30) | ||
| 350 | fldws -16(0,%r30),%fr10R | ||
| 351 | stw %r23,-16(0,%r30) | ||
| 352 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 353 | fldws -16(0,%r30),%fr10R | ||
| 354 | fstws %fr8R,-16(0,%r30) | ||
| 355 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 356 | ldw -16(0,%r30),%r8 | ||
| 357 | fstws %fr9R,-16(0,%r30) | ||
| 358 | copy %r8,%r22 | ||
| 359 | ldw -16(0,%r30),%r8 | ||
| 360 | extru %r4,15,16,%r24 | ||
| 361 | copy %r8,%r21 | ||
| 362 | L$0060 | ||
| 363 | sub %r3,%r21,%r20 | ||
| 364 | copy %r20,%r19 | ||
| 365 | depi 0,31,16,%r19 | ||
| 366 | comib,<> 0,%r19,L$0061 | ||
| 367 | zdep %r20,15,16,%r19 | ||
| 368 | addl %r19,%r24,%r19 | ||
| 369 | comb,>>= %r19,%r22,L$0061 | ||
| 370 | sub %r22,%r28,%r22 | ||
| 371 | sub %r21,%r23,%r21 | ||
| 372 | bl L$0060,0 | ||
| 373 | ldo -1(%r29),%r29 | ||
| 374 | L$0061 | ||
| 375 | stw %r29,-16(0,%r30) | ||
| 376 | fldws -16(0,%r30),%fr10L | ||
| 377 | stw %r28,-16(0,%r30) | ||
| 378 | fldws -16(0,%r30),%fr10R | ||
| 379 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 380 | fstws %fr8R,-16(0,%r30) | ||
| 381 | ldw -16(0,%r30),%r8 | ||
| 382 | stw %r23,-16(0,%r30) | ||
| 383 | fldws -16(0,%r30),%fr10R | ||
| 384 | copy %r8,%r19 | ||
| 385 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 386 | fstws %fr8R,-16(0,%r30) | ||
| 387 | extru %r19,15,16,%r20 | ||
| 388 | ldw -16(0,%r30),%r8 | ||
| 389 | zdep %r19,15,16,%r19 | ||
| 390 | addl %r8,%r20,%r20 | ||
| 391 | comclr,<<= %r19,%r4,0 | ||
| 392 | addi 1,%r20,%r20 | ||
| 393 | comb,<<= %r20,%r3,L$0066 | ||
| 394 | sub %r4,%r19,%r4 | ||
| 395 | addl %r3,%r5,%r3 | ||
| 396 | ldo -1(%r29),%r29 | ||
| 397 | L$0066 | ||
| 398 | addib,= -1,%r6,L$0056 | ||
| 399 | sub %r3,%r20,%r3 | ||
| 400 | zdep %r29,15,16,%r7 | ||
| 401 | shd %r3,%r4,16,%r3 | ||
| 402 | bl L$0055,0 | ||
| 403 | zdep %r4,15,16,%r4 | ||
| 404 | L$0056 | ||
| 405 | or %r7,%r29,%r28 | ||
| 406 | L$0068 | ||
| 407 | ldw -148(0,%r30),%r2 | ||
| 408 | ldw -124(0,%r30),%r7 | ||
| 409 | ldw -120(0,%r30),%r6 | ||
| 410 | ldw -116(0,%r30),%r5 | ||
| 411 | ldw -112(0,%r30),%r4 | ||
| 412 | ldw -108(0,%r30),%r3 | ||
| 413 | bv 0(%r2) | ||
| 414 | ldwm -128(0,%r30),%r8 | ||
| 415 | .EXIT | ||
| 416 | .PROCEND | ||
diff --git a/src/lib/libcrypto/bn/asm/sparcv8.S b/src/lib/libcrypto/bn/asm/sparcv8.S deleted file mode 100644 index 88c5dc480a..0000000000 --- a/src/lib/libcrypto/bn/asm/sparcv8.S +++ /dev/null | |||
| @@ -1,1458 +0,0 @@ | |||
| 1 | .ident "sparcv8.s, Version 1.4" | ||
| 2 | .ident "SPARC v8 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>" | ||
| 3 | |||
| 4 | /* | ||
| 5 | * ==================================================================== | ||
| 6 | * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL | ||
| 7 | * project. | ||
| 8 | * | ||
| 9 | * Rights for redistribution and usage in source and binary forms are | ||
| 10 | * granted according to the OpenSSL license. Warranty of any kind is | ||
| 11 | * disclaimed. | ||
| 12 | * ==================================================================== | ||
| 13 | */ | ||
| 14 | |||
| 15 | /* | ||
| 16 | * This is my modest contributon to OpenSSL project (see | ||
| 17 | * http://www.openssl.org/ for more information about it) and is | ||
| 18 | * a drop-in SuperSPARC ISA replacement for crypto/bn/bn_asm.c | ||
| 19 | * module. For updates see http://fy.chalmers.se/~appro/hpe/. | ||
| 20 | * | ||
| 21 | * See bn_asm.sparc.v8plus.S for more details. | ||
| 22 | */ | ||
| 23 | |||
| 24 | /* | ||
| 25 | * Revision history. | ||
| 26 | * | ||
| 27 | * 1.1 - new loop unrolling model(*); | ||
| 28 | * 1.2 - made gas friendly; | ||
| 29 | * 1.3 - fixed problem with /usr/ccs/lib/cpp; | ||
| 30 | * 1.4 - some retunes; | ||
| 31 | * | ||
| 32 | * (*) see bn_asm.sparc.v8plus.S for details | ||
| 33 | */ | ||
| 34 | |||
| 35 | .section ".text",#alloc,#execinstr | ||
| 36 | .file "bn_asm.sparc.v8.S" | ||
| 37 | |||
| 38 | .align 32 | ||
| 39 | |||
| 40 | .global bn_mul_add_words | ||
| 41 | /* | ||
| 42 | * BN_ULONG bn_mul_add_words(rp,ap,num,w) | ||
| 43 | * BN_ULONG *rp,*ap; | ||
| 44 | * int num; | ||
| 45 | * BN_ULONG w; | ||
| 46 | */ | ||
| 47 | bn_mul_add_words: | ||
| 48 | cmp %o2,0 | ||
| 49 | bg,a .L_bn_mul_add_words_proceed | ||
| 50 | ld [%o1],%g2 | ||
| 51 | retl | ||
| 52 | clr %o0 | ||
| 53 | |||
| 54 | .L_bn_mul_add_words_proceed: | ||
| 55 | andcc %o2,-4,%g0 | ||
| 56 | bz .L_bn_mul_add_words_tail | ||
| 57 | clr %o5 | ||
| 58 | |||
| 59 | .L_bn_mul_add_words_loop: | ||
| 60 | ld [%o0],%o4 | ||
| 61 | ld [%o1+4],%g3 | ||
| 62 | umul %o3,%g2,%g2 | ||
| 63 | rd %y,%g1 | ||
| 64 | addcc %o4,%o5,%o4 | ||
| 65 | addx %g1,0,%g1 | ||
| 66 | addcc %o4,%g2,%o4 | ||
| 67 | st %o4,[%o0] | ||
| 68 | addx %g1,0,%o5 | ||
| 69 | |||
| 70 | ld [%o0+4],%o4 | ||
| 71 | ld [%o1+8],%g2 | ||
| 72 | umul %o3,%g3,%g3 | ||
| 73 | dec 4,%o2 | ||
| 74 | rd %y,%g1 | ||
| 75 | addcc %o4,%o5,%o4 | ||
| 76 | addx %g1,0,%g1 | ||
| 77 | addcc %o4,%g3,%o4 | ||
| 78 | st %o4,[%o0+4] | ||
| 79 | addx %g1,0,%o5 | ||
| 80 | |||
| 81 | ld [%o0+8],%o4 | ||
| 82 | ld [%o1+12],%g3 | ||
| 83 | umul %o3,%g2,%g2 | ||
| 84 | inc 16,%o1 | ||
| 85 | rd %y,%g1 | ||
| 86 | addcc %o4,%o5,%o4 | ||
| 87 | addx %g1,0,%g1 | ||
| 88 | addcc %o4,%g2,%o4 | ||
| 89 | st %o4,[%o0+8] | ||
| 90 | addx %g1,0,%o5 | ||
| 91 | |||
| 92 | ld [%o0+12],%o4 | ||
| 93 | umul %o3,%g3,%g3 | ||
| 94 | inc 16,%o0 | ||
| 95 | rd %y,%g1 | ||
| 96 | addcc %o4,%o5,%o4 | ||
| 97 | addx %g1,0,%g1 | ||
| 98 | addcc %o4,%g3,%o4 | ||
| 99 | st %o4,[%o0-4] | ||
| 100 | addx %g1,0,%o5 | ||
| 101 | andcc %o2,-4,%g0 | ||
| 102 | bnz,a .L_bn_mul_add_words_loop | ||
| 103 | ld [%o1],%g2 | ||
| 104 | |||
| 105 | tst %o2 | ||
| 106 | bnz,a .L_bn_mul_add_words_tail | ||
| 107 | ld [%o1],%g2 | ||
| 108 | .L_bn_mul_add_words_return: | ||
| 109 | retl | ||
| 110 | mov %o5,%o0 | ||
| 111 | nop | ||
| 112 | |||
| 113 | .L_bn_mul_add_words_tail: | ||
| 114 | ld [%o0],%o4 | ||
| 115 | umul %o3,%g2,%g2 | ||
| 116 | addcc %o4,%o5,%o4 | ||
| 117 | rd %y,%g1 | ||
| 118 | addx %g1,0,%g1 | ||
| 119 | addcc %o4,%g2,%o4 | ||
| 120 | addx %g1,0,%o5 | ||
| 121 | deccc %o2 | ||
| 122 | bz .L_bn_mul_add_words_return | ||
| 123 | st %o4,[%o0] | ||
| 124 | |||
| 125 | ld [%o1+4],%g2 | ||
| 126 | ld [%o0+4],%o4 | ||
| 127 | umul %o3,%g2,%g2 | ||
| 128 | rd %y,%g1 | ||
| 129 | addcc %o4,%o5,%o4 | ||
| 130 | addx %g1,0,%g1 | ||
| 131 | addcc %o4,%g2,%o4 | ||
| 132 | addx %g1,0,%o5 | ||
| 133 | deccc %o2 | ||
| 134 | bz .L_bn_mul_add_words_return | ||
| 135 | st %o4,[%o0+4] | ||
| 136 | |||
| 137 | ld [%o1+8],%g2 | ||
| 138 | ld [%o0+8],%o4 | ||
| 139 | umul %o3,%g2,%g2 | ||
| 140 | rd %y,%g1 | ||
| 141 | addcc %o4,%o5,%o4 | ||
| 142 | addx %g1,0,%g1 | ||
| 143 | addcc %o4,%g2,%o4 | ||
| 144 | st %o4,[%o0+8] | ||
| 145 | retl | ||
| 146 | addx %g1,0,%o0 | ||
| 147 | |||
| 148 | .type bn_mul_add_words,#function | ||
| 149 | .size bn_mul_add_words,(.-bn_mul_add_words) | ||
| 150 | |||
| 151 | .align 32 | ||
| 152 | |||
| 153 | .global bn_mul_words | ||
| 154 | /* | ||
| 155 | * BN_ULONG bn_mul_words(rp,ap,num,w) | ||
| 156 | * BN_ULONG *rp,*ap; | ||
| 157 | * int num; | ||
| 158 | * BN_ULONG w; | ||
| 159 | */ | ||
| 160 | bn_mul_words: | ||
| 161 | cmp %o2,0 | ||
| 162 | bg,a .L_bn_mul_words_proceeed | ||
| 163 | ld [%o1],%g2 | ||
| 164 | retl | ||
| 165 | clr %o0 | ||
| 166 | |||
| 167 | .L_bn_mul_words_proceeed: | ||
| 168 | andcc %o2,-4,%g0 | ||
| 169 | bz .L_bn_mul_words_tail | ||
| 170 | clr %o5 | ||
| 171 | |||
| 172 | .L_bn_mul_words_loop: | ||
| 173 | ld [%o1+4],%g3 | ||
| 174 | umul %o3,%g2,%g2 | ||
| 175 | addcc %g2,%o5,%g2 | ||
| 176 | rd %y,%g1 | ||
| 177 | addx %g1,0,%o5 | ||
| 178 | st %g2,[%o0] | ||
| 179 | |||
| 180 | ld [%o1+8],%g2 | ||
| 181 | umul %o3,%g3,%g3 | ||
| 182 | addcc %g3,%o5,%g3 | ||
| 183 | rd %y,%g1 | ||
| 184 | dec 4,%o2 | ||
| 185 | addx %g1,0,%o5 | ||
| 186 | st %g3,[%o0+4] | ||
| 187 | |||
| 188 | ld [%o1+12],%g3 | ||
| 189 | umul %o3,%g2,%g2 | ||
| 190 | addcc %g2,%o5,%g2 | ||
| 191 | rd %y,%g1 | ||
| 192 | inc 16,%o1 | ||
| 193 | st %g2,[%o0+8] | ||
| 194 | addx %g1,0,%o5 | ||
| 195 | |||
| 196 | umul %o3,%g3,%g3 | ||
| 197 | addcc %g3,%o5,%g3 | ||
| 198 | rd %y,%g1 | ||
| 199 | inc 16,%o0 | ||
| 200 | addx %g1,0,%o5 | ||
| 201 | st %g3,[%o0-4] | ||
| 202 | andcc %o2,-4,%g0 | ||
| 203 | nop | ||
| 204 | bnz,a .L_bn_mul_words_loop | ||
| 205 | ld [%o1],%g2 | ||
| 206 | |||
| 207 | tst %o2 | ||
| 208 | bnz,a .L_bn_mul_words_tail | ||
| 209 | ld [%o1],%g2 | ||
| 210 | .L_bn_mul_words_return: | ||
| 211 | retl | ||
| 212 | mov %o5,%o0 | ||
| 213 | nop | ||
| 214 | |||
| 215 | .L_bn_mul_words_tail: | ||
| 216 | umul %o3,%g2,%g2 | ||
| 217 | addcc %g2,%o5,%g2 | ||
| 218 | rd %y,%g1 | ||
| 219 | addx %g1,0,%o5 | ||
| 220 | deccc %o2 | ||
| 221 | bz .L_bn_mul_words_return | ||
| 222 | st %g2,[%o0] | ||
| 223 | nop | ||
| 224 | |||
| 225 | ld [%o1+4],%g2 | ||
| 226 | umul %o3,%g2,%g2 | ||
| 227 | addcc %g2,%o5,%g2 | ||
| 228 | rd %y,%g1 | ||
| 229 | addx %g1,0,%o5 | ||
| 230 | deccc %o2 | ||
| 231 | bz .L_bn_mul_words_return | ||
| 232 | st %g2,[%o0+4] | ||
| 233 | |||
| 234 | ld [%o1+8],%g2 | ||
| 235 | umul %o3,%g2,%g2 | ||
| 236 | addcc %g2,%o5,%g2 | ||
| 237 | rd %y,%g1 | ||
| 238 | st %g2,[%o0+8] | ||
| 239 | retl | ||
| 240 | addx %g1,0,%o0 | ||
| 241 | |||
| 242 | .type bn_mul_words,#function | ||
| 243 | .size bn_mul_words,(.-bn_mul_words) | ||
| 244 | |||
| 245 | .align 32 | ||
| 246 | .global bn_sqr_words | ||
| 247 | /* | ||
| 248 | * void bn_sqr_words(r,a,n) | ||
| 249 | * BN_ULONG *r,*a; | ||
| 250 | * int n; | ||
| 251 | */ | ||
| 252 | bn_sqr_words: | ||
| 253 | cmp %o2,0 | ||
| 254 | bg,a .L_bn_sqr_words_proceeed | ||
| 255 | ld [%o1],%g2 | ||
| 256 | retl | ||
| 257 | clr %o0 | ||
| 258 | |||
| 259 | .L_bn_sqr_words_proceeed: | ||
| 260 | andcc %o2,-4,%g0 | ||
| 261 | bz .L_bn_sqr_words_tail | ||
| 262 | clr %o5 | ||
| 263 | |||
| 264 | .L_bn_sqr_words_loop: | ||
| 265 | ld [%o1+4],%g3 | ||
| 266 | umul %g2,%g2,%o4 | ||
| 267 | st %o4,[%o0] | ||
| 268 | rd %y,%o5 | ||
| 269 | st %o5,[%o0+4] | ||
| 270 | |||
| 271 | ld [%o1+8],%g2 | ||
| 272 | umul %g3,%g3,%o4 | ||
| 273 | dec 4,%o2 | ||
| 274 | st %o4,[%o0+8] | ||
| 275 | rd %y,%o5 | ||
| 276 | st %o5,[%o0+12] | ||
| 277 | nop | ||
| 278 | |||
| 279 | ld [%o1+12],%g3 | ||
| 280 | umul %g2,%g2,%o4 | ||
| 281 | st %o4,[%o0+16] | ||
| 282 | rd %y,%o5 | ||
| 283 | inc 16,%o1 | ||
| 284 | st %o5,[%o0+20] | ||
| 285 | |||
| 286 | umul %g3,%g3,%o4 | ||
| 287 | inc 32,%o0 | ||
| 288 | st %o4,[%o0-8] | ||
| 289 | rd %y,%o5 | ||
| 290 | st %o5,[%o0-4] | ||
| 291 | andcc %o2,-4,%g2 | ||
| 292 | bnz,a .L_bn_sqr_words_loop | ||
| 293 | ld [%o1],%g2 | ||
| 294 | |||
| 295 | tst %o2 | ||
| 296 | nop | ||
| 297 | bnz,a .L_bn_sqr_words_tail | ||
| 298 | ld [%o1],%g2 | ||
| 299 | .L_bn_sqr_words_return: | ||
| 300 | retl | ||
| 301 | clr %o0 | ||
| 302 | |||
| 303 | .L_bn_sqr_words_tail: | ||
| 304 | umul %g2,%g2,%o4 | ||
| 305 | st %o4,[%o0] | ||
| 306 | deccc %o2 | ||
| 307 | rd %y,%o5 | ||
| 308 | bz .L_bn_sqr_words_return | ||
| 309 | st %o5,[%o0+4] | ||
| 310 | |||
| 311 | ld [%o1+4],%g2 | ||
| 312 | umul %g2,%g2,%o4 | ||
| 313 | st %o4,[%o0+8] | ||
| 314 | deccc %o2 | ||
| 315 | rd %y,%o5 | ||
| 316 | nop | ||
| 317 | bz .L_bn_sqr_words_return | ||
| 318 | st %o5,[%o0+12] | ||
| 319 | |||
| 320 | ld [%o1+8],%g2 | ||
| 321 | umul %g2,%g2,%o4 | ||
| 322 | st %o4,[%o0+16] | ||
| 323 | rd %y,%o5 | ||
| 324 | st %o5,[%o0+20] | ||
| 325 | retl | ||
| 326 | clr %o0 | ||
| 327 | |||
| 328 | .type bn_sqr_words,#function | ||
| 329 | .size bn_sqr_words,(.-bn_sqr_words) | ||
| 330 | |||
| 331 | .align 32 | ||
| 332 | |||
| 333 | .global bn_div_words | ||
| 334 | /* | ||
| 335 | * BN_ULONG bn_div_words(h,l,d) | ||
| 336 | * BN_ULONG h,l,d; | ||
| 337 | */ | ||
| 338 | bn_div_words: | ||
| 339 | wr %o0,%y | ||
| 340 | udiv %o1,%o2,%o0 | ||
| 341 | retl | ||
| 342 | nop | ||
| 343 | |||
| 344 | .type bn_div_words,#function | ||
| 345 | .size bn_div_words,(.-bn_div_words) | ||
| 346 | |||
| 347 | .align 32 | ||
| 348 | |||
| 349 | .global bn_add_words | ||
| 350 | /* | ||
| 351 | * BN_ULONG bn_add_words(rp,ap,bp,n) | ||
| 352 | * BN_ULONG *rp,*ap,*bp; | ||
| 353 | * int n; | ||
| 354 | */ | ||
| 355 | bn_add_words: | ||
| 356 | cmp %o3,0 | ||
| 357 | bg,a .L_bn_add_words_proceed | ||
| 358 | ld [%o1],%o4 | ||
| 359 | retl | ||
| 360 | clr %o0 | ||
| 361 | |||
| 362 | .L_bn_add_words_proceed: | ||
| 363 | andcc %o3,-4,%g0 | ||
| 364 | bz .L_bn_add_words_tail | ||
| 365 | clr %g1 | ||
| 366 | ba .L_bn_add_words_warn_loop | ||
| 367 | addcc %g0,0,%g0 ! clear carry flag | ||
| 368 | |||
| 369 | .L_bn_add_words_loop: | ||
| 370 | ld [%o1],%o4 | ||
| 371 | .L_bn_add_words_warn_loop: | ||
| 372 | ld [%o2],%o5 | ||
| 373 | ld [%o1+4],%g3 | ||
| 374 | ld [%o2+4],%g4 | ||
| 375 | dec 4,%o3 | ||
| 376 | addxcc %o5,%o4,%o5 | ||
| 377 | st %o5,[%o0] | ||
| 378 | |||
| 379 | ld [%o1+8],%o4 | ||
| 380 | ld [%o2+8],%o5 | ||
| 381 | inc 16,%o1 | ||
| 382 | addxcc %g3,%g4,%g3 | ||
| 383 | st %g3,[%o0+4] | ||
| 384 | |||
| 385 | ld [%o1-4],%g3 | ||
| 386 | ld [%o2+12],%g4 | ||
| 387 | inc 16,%o2 | ||
| 388 | addxcc %o5,%o4,%o5 | ||
| 389 | st %o5,[%o0+8] | ||
| 390 | |||
| 391 | inc 16,%o0 | ||
| 392 | addxcc %g3,%g4,%g3 | ||
| 393 | st %g3,[%o0-4] | ||
| 394 | addx %g0,0,%g1 | ||
| 395 | andcc %o3,-4,%g0 | ||
| 396 | bnz,a .L_bn_add_words_loop | ||
| 397 | addcc %g1,-1,%g0 | ||
| 398 | |||
| 399 | tst %o3 | ||
| 400 | bnz,a .L_bn_add_words_tail | ||
| 401 | ld [%o1],%o4 | ||
| 402 | .L_bn_add_words_return: | ||
| 403 | retl | ||
| 404 | mov %g1,%o0 | ||
| 405 | |||
| 406 | .L_bn_add_words_tail: | ||
| 407 | addcc %g1,-1,%g0 | ||
| 408 | ld [%o2],%o5 | ||
| 409 | addxcc %o5,%o4,%o5 | ||
| 410 | addx %g0,0,%g1 | ||
| 411 | deccc %o3 | ||
| 412 | bz .L_bn_add_words_return | ||
| 413 | st %o5,[%o0] | ||
| 414 | |||
| 415 | ld [%o1+4],%o4 | ||
| 416 | addcc %g1,-1,%g0 | ||
| 417 | ld [%o2+4],%o5 | ||
| 418 | addxcc %o5,%o4,%o5 | ||
| 419 | addx %g0,0,%g1 | ||
| 420 | deccc %o3 | ||
| 421 | bz .L_bn_add_words_return | ||
| 422 | st %o5,[%o0+4] | ||
| 423 | |||
| 424 | ld [%o1+8],%o4 | ||
| 425 | addcc %g1,-1,%g0 | ||
| 426 | ld [%o2+8],%o5 | ||
| 427 | addxcc %o5,%o4,%o5 | ||
| 428 | st %o5,[%o0+8] | ||
| 429 | retl | ||
| 430 | addx %g0,0,%o0 | ||
| 431 | |||
| 432 | .type bn_add_words,#function | ||
| 433 | .size bn_add_words,(.-bn_add_words) | ||
| 434 | |||
| 435 | .align 32 | ||
| 436 | |||
| 437 | .global bn_sub_words | ||
| 438 | /* | ||
| 439 | * BN_ULONG bn_sub_words(rp,ap,bp,n) | ||
| 440 | * BN_ULONG *rp,*ap,*bp; | ||
| 441 | * int n; | ||
| 442 | */ | ||
| 443 | bn_sub_words: | ||
| 444 | cmp %o3,0 | ||
| 445 | bg,a .L_bn_sub_words_proceed | ||
| 446 | ld [%o1],%o4 | ||
| 447 | retl | ||
| 448 | clr %o0 | ||
| 449 | |||
| 450 | .L_bn_sub_words_proceed: | ||
| 451 | andcc %o3,-4,%g0 | ||
| 452 | bz .L_bn_sub_words_tail | ||
| 453 | clr %g1 | ||
| 454 | ba .L_bn_sub_words_warm_loop | ||
| 455 | addcc %g0,0,%g0 ! clear carry flag | ||
| 456 | |||
| 457 | .L_bn_sub_words_loop: | ||
| 458 | ld [%o1],%o4 | ||
| 459 | .L_bn_sub_words_warm_loop: | ||
| 460 | ld [%o2],%o5 | ||
| 461 | ld [%o1+4],%g3 | ||
| 462 | ld [%o2+4],%g4 | ||
| 463 | dec 4,%o3 | ||
| 464 | subxcc %o4,%o5,%o5 | ||
| 465 | st %o5,[%o0] | ||
| 466 | |||
| 467 | ld [%o1+8],%o4 | ||
| 468 | ld [%o2+8],%o5 | ||
| 469 | inc 16,%o1 | ||
| 470 | subxcc %g3,%g4,%g4 | ||
| 471 | st %g4,[%o0+4] | ||
| 472 | |||
| 473 | ld [%o1-4],%g3 | ||
| 474 | ld [%o2+12],%g4 | ||
| 475 | inc 16,%o2 | ||
| 476 | subxcc %o4,%o5,%o5 | ||
| 477 | st %o5,[%o0+8] | ||
| 478 | |||
| 479 | inc 16,%o0 | ||
| 480 | subxcc %g3,%g4,%g4 | ||
| 481 | st %g4,[%o0-4] | ||
| 482 | addx %g0,0,%g1 | ||
| 483 | andcc %o3,-4,%g0 | ||
| 484 | bnz,a .L_bn_sub_words_loop | ||
| 485 | addcc %g1,-1,%g0 | ||
| 486 | |||
| 487 | tst %o3 | ||
| 488 | nop | ||
| 489 | bnz,a .L_bn_sub_words_tail | ||
| 490 | ld [%o1],%o4 | ||
| 491 | .L_bn_sub_words_return: | ||
| 492 | retl | ||
| 493 | mov %g1,%o0 | ||
| 494 | |||
| 495 | .L_bn_sub_words_tail: | ||
| 496 | addcc %g1,-1,%g0 | ||
| 497 | ld [%o2],%o5 | ||
| 498 | subxcc %o4,%o5,%o5 | ||
| 499 | addx %g0,0,%g1 | ||
| 500 | deccc %o3 | ||
| 501 | bz .L_bn_sub_words_return | ||
| 502 | st %o5,[%o0] | ||
| 503 | nop | ||
| 504 | |||
| 505 | ld [%o1+4],%o4 | ||
| 506 | addcc %g1,-1,%g0 | ||
| 507 | ld [%o2+4],%o5 | ||
| 508 | subxcc %o4,%o5,%o5 | ||
| 509 | addx %g0,0,%g1 | ||
| 510 | deccc %o3 | ||
| 511 | bz .L_bn_sub_words_return | ||
| 512 | st %o5,[%o0+4] | ||
| 513 | |||
| 514 | ld [%o1+8],%o4 | ||
| 515 | addcc %g1,-1,%g0 | ||
| 516 | ld [%o2+8],%o5 | ||
| 517 | subxcc %o4,%o5,%o5 | ||
| 518 | st %o5,[%o0+8] | ||
| 519 | retl | ||
| 520 | addx %g0,0,%o0 | ||
| 521 | |||
| 522 | .type bn_sub_words,#function | ||
| 523 | .size bn_sub_words,(.-bn_sub_words) | ||
| 524 | |||
| 525 | #define FRAME_SIZE -96 | ||
| 526 | |||
| 527 | /* | ||
| 528 | * Here is register usage map for *all* routines below. | ||
| 529 | */ | ||
| 530 | #define t_1 %o0 | ||
| 531 | #define t_2 %o1 | ||
| 532 | #define c_1 %o2 | ||
| 533 | #define c_2 %o3 | ||
| 534 | #define c_3 %o4 | ||
| 535 | |||
| 536 | #define ap(I) [%i1+4*I] | ||
| 537 | #define bp(I) [%i2+4*I] | ||
| 538 | #define rp(I) [%i0+4*I] | ||
| 539 | |||
| 540 | #define a_0 %l0 | ||
| 541 | #define a_1 %l1 | ||
| 542 | #define a_2 %l2 | ||
| 543 | #define a_3 %l3 | ||
| 544 | #define a_4 %l4 | ||
| 545 | #define a_5 %l5 | ||
| 546 | #define a_6 %l6 | ||
| 547 | #define a_7 %l7 | ||
| 548 | |||
| 549 | #define b_0 %i3 | ||
| 550 | #define b_1 %i4 | ||
| 551 | #define b_2 %i5 | ||
| 552 | #define b_3 %o5 | ||
| 553 | #define b_4 %g1 | ||
| 554 | #define b_5 %g2 | ||
| 555 | #define b_6 %g3 | ||
| 556 | #define b_7 %g4 | ||
| 557 | |||
| 558 | .align 32 | ||
| 559 | .global bn_mul_comba8 | ||
| 560 | /* | ||
| 561 | * void bn_mul_comba8(r,a,b) | ||
| 562 | * BN_ULONG *r,*a,*b; | ||
| 563 | */ | ||
| 564 | bn_mul_comba8: | ||
| 565 | save %sp,FRAME_SIZE,%sp | ||
| 566 | ld ap(0),a_0 | ||
| 567 | ld bp(0),b_0 | ||
| 568 | umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3); | ||
| 569 | ld bp(1),b_1 | ||
| 570 | rd %y,c_2 | ||
| 571 | st c_1,rp(0) !r[0]=c1; | ||
| 572 | |||
| 573 | umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1); | ||
| 574 | ld ap(1),a_1 | ||
| 575 | addcc c_2,t_1,c_2 | ||
| 576 | rd %y,t_2 | ||
| 577 | addxcc %g0,t_2,c_3 != | ||
| 578 | addx %g0,%g0,c_1 | ||
| 579 | ld ap(2),a_2 | ||
| 580 | umul a_1,b_0,t_1 !mul_add_c(a[1],b[0],c2,c3,c1); | ||
| 581 | addcc c_2,t_1,c_2 != | ||
| 582 | rd %y,t_2 | ||
| 583 | addxcc c_3,t_2,c_3 | ||
| 584 | st c_2,rp(1) !r[1]=c2; | ||
| 585 | addx c_1,%g0,c_1 != | ||
| 586 | |||
| 587 | umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2); | ||
| 588 | addcc c_3,t_1,c_3 | ||
| 589 | rd %y,t_2 | ||
| 590 | addxcc c_1,t_2,c_1 != | ||
| 591 | addx %g0,%g0,c_2 | ||
| 592 | ld bp(2),b_2 | ||
| 593 | umul a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2); | ||
| 594 | addcc c_3,t_1,c_3 != | ||
| 595 | rd %y,t_2 | ||
| 596 | addxcc c_1,t_2,c_1 | ||
| 597 | ld bp(3),b_3 | ||
| 598 | addx c_2,%g0,c_2 != | ||
| 599 | umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2); | ||
| 600 | addcc c_3,t_1,c_3 | ||
| 601 | rd %y,t_2 | ||
| 602 | addxcc c_1,t_2,c_1 != | ||
| 603 | addx c_2,%g0,c_2 | ||
| 604 | st c_3,rp(2) !r[2]=c3; | ||
| 605 | |||
| 606 | umul a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3); | ||
| 607 | addcc c_1,t_1,c_1 != | ||
| 608 | rd %y,t_2 | ||
| 609 | addxcc c_2,t_2,c_2 | ||
| 610 | addx %g0,%g0,c_3 | ||
| 611 | umul a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3); | ||
| 612 | addcc c_1,t_1,c_1 | ||
| 613 | rd %y,t_2 | ||
| 614 | addxcc c_2,t_2,c_2 | ||
| 615 | addx c_3,%g0,c_3 != | ||
| 616 | ld ap(3),a_3 | ||
| 617 | umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3); | ||
| 618 | addcc c_1,t_1,c_1 | ||
| 619 | rd %y,t_2 != | ||
| 620 | addxcc c_2,t_2,c_2 | ||
| 621 | addx c_3,%g0,c_3 | ||
| 622 | ld ap(4),a_4 | ||
| 623 | umul a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!= | ||
| 624 | addcc c_1,t_1,c_1 | ||
| 625 | rd %y,t_2 | ||
| 626 | addxcc c_2,t_2,c_2 | ||
| 627 | addx c_3,%g0,c_3 != | ||
| 628 | st c_1,rp(3) !r[3]=c1; | ||
| 629 | |||
| 630 | umul a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1); | ||
| 631 | addcc c_2,t_1,c_2 | ||
| 632 | rd %y,t_2 != | ||
| 633 | addxcc c_3,t_2,c_3 | ||
| 634 | addx %g0,%g0,c_1 | ||
| 635 | umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1); | ||
| 636 | addcc c_2,t_1,c_2 != | ||
| 637 | rd %y,t_2 | ||
| 638 | addxcc c_3,t_2,c_3 | ||
| 639 | addx c_1,%g0,c_1 | ||
| 640 | umul a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1); | ||
| 641 | addcc c_2,t_1,c_2 | ||
| 642 | rd %y,t_2 | ||
| 643 | addxcc c_3,t_2,c_3 | ||
| 644 | addx c_1,%g0,c_1 != | ||
| 645 | ld bp(4),b_4 | ||
| 646 | umul a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1); | ||
| 647 | addcc c_2,t_1,c_2 | ||
| 648 | rd %y,t_2 != | ||
| 649 | addxcc c_3,t_2,c_3 | ||
| 650 | addx c_1,%g0,c_1 | ||
| 651 | ld bp(5),b_5 | ||
| 652 | umul a_0,b_4,t_1 !=!mul_add_c(a[0],b[4],c2,c3,c1); | ||
| 653 | addcc c_2,t_1,c_2 | ||
| 654 | rd %y,t_2 | ||
| 655 | addxcc c_3,t_2,c_3 | ||
| 656 | addx c_1,%g0,c_1 != | ||
| 657 | st c_2,rp(4) !r[4]=c2; | ||
| 658 | |||
| 659 | umul a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2); | ||
| 660 | addcc c_3,t_1,c_3 | ||
| 661 | rd %y,t_2 != | ||
| 662 | addxcc c_1,t_2,c_1 | ||
| 663 | addx %g0,%g0,c_2 | ||
| 664 | umul a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2); | ||
| 665 | addcc c_3,t_1,c_3 != | ||
| 666 | rd %y,t_2 | ||
| 667 | addxcc c_1,t_2,c_1 | ||
| 668 | addx c_2,%g0,c_2 | ||
| 669 | umul a_2,b_3,t_1 !=!mul_add_c(a[2],b[3],c3,c1,c2); | ||
| 670 | addcc c_3,t_1,c_3 | ||
| 671 | rd %y,t_2 | ||
| 672 | addxcc c_1,t_2,c_1 | ||
| 673 | addx c_2,%g0,c_2 != | ||
| 674 | umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2); | ||
| 675 | addcc c_3,t_1,c_3 | ||
| 676 | rd %y,t_2 | ||
| 677 | addxcc c_1,t_2,c_1 != | ||
| 678 | addx c_2,%g0,c_2 | ||
| 679 | ld ap(5),a_5 | ||
| 680 | umul a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2); | ||
| 681 | addcc c_3,t_1,c_3 != | ||
| 682 | rd %y,t_2 | ||
| 683 | addxcc c_1,t_2,c_1 | ||
| 684 | ld ap(6),a_6 | ||
| 685 | addx c_2,%g0,c_2 != | ||
| 686 | umul a_5,b_0,t_1 !mul_add_c(a[5],b[0],c3,c1,c2); | ||
| 687 | addcc c_3,t_1,c_3 | ||
| 688 | rd %y,t_2 | ||
| 689 | addxcc c_1,t_2,c_1 != | ||
| 690 | addx c_2,%g0,c_2 | ||
| 691 | st c_3,rp(5) !r[5]=c3; | ||
| 692 | |||
| 693 | umul a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3); | ||
| 694 | addcc c_1,t_1,c_1 != | ||
| 695 | rd %y,t_2 | ||
| 696 | addxcc c_2,t_2,c_2 | ||
| 697 | addx %g0,%g0,c_3 | ||
| 698 | umul a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3); | ||
| 699 | addcc c_1,t_1,c_1 | ||
| 700 | rd %y,t_2 | ||
| 701 | addxcc c_2,t_2,c_2 | ||
| 702 | addx c_3,%g0,c_3 != | ||
| 703 | umul a_4,b_2,t_1 !mul_add_c(a[4],b[2],c1,c2,c3); | ||
| 704 | addcc c_1,t_1,c_1 | ||
| 705 | rd %y,t_2 | ||
| 706 | addxcc c_2,t_2,c_2 != | ||
| 707 | addx c_3,%g0,c_3 | ||
| 708 | umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3); | ||
| 709 | addcc c_1,t_1,c_1 | ||
| 710 | rd %y,t_2 != | ||
| 711 | addxcc c_2,t_2,c_2 | ||
| 712 | addx c_3,%g0,c_3 | ||
| 713 | umul a_2,b_4,t_1 !mul_add_c(a[2],b[4],c1,c2,c3); | ||
| 714 | addcc c_1,t_1,c_1 != | ||
| 715 | rd %y,t_2 | ||
| 716 | addxcc c_2,t_2,c_2 | ||
| 717 | ld bp(6),b_6 | ||
| 718 | addx c_3,%g0,c_3 != | ||
| 719 | umul a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3); | ||
| 720 | addcc c_1,t_1,c_1 | ||
| 721 | rd %y,t_2 | ||
| 722 | addxcc c_2,t_2,c_2 != | ||
| 723 | addx c_3,%g0,c_3 | ||
| 724 | ld bp(7),b_7 | ||
| 725 | umul a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3); | ||
| 726 | addcc c_1,t_1,c_1 != | ||
| 727 | rd %y,t_2 | ||
| 728 | addxcc c_2,t_2,c_2 | ||
| 729 | st c_1,rp(6) !r[6]=c1; | ||
| 730 | addx c_3,%g0,c_3 != | ||
| 731 | |||
| 732 | umul a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1); | ||
| 733 | addcc c_2,t_1,c_2 | ||
| 734 | rd %y,t_2 | ||
| 735 | addxcc c_3,t_2,c_3 != | ||
| 736 | addx %g0,%g0,c_1 | ||
| 737 | umul a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1); | ||
| 738 | addcc c_2,t_1,c_2 | ||
| 739 | rd %y,t_2 != | ||
| 740 | addxcc c_3,t_2,c_3 | ||
| 741 | addx c_1,%g0,c_1 | ||
| 742 | umul a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1); | ||
| 743 | addcc c_2,t_1,c_2 != | ||
| 744 | rd %y,t_2 | ||
| 745 | addxcc c_3,t_2,c_3 | ||
| 746 | addx c_1,%g0,c_1 | ||
| 747 | umul a_3,b_4,t_1 !=!mul_add_c(a[3],b[4],c2,c3,c1); | ||
| 748 | addcc c_2,t_1,c_2 | ||
| 749 | rd %y,t_2 | ||
| 750 | addxcc c_3,t_2,c_3 | ||
| 751 | addx c_1,%g0,c_1 != | ||
| 752 | umul a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1); | ||
| 753 | addcc c_2,t_1,c_2 | ||
| 754 | rd %y,t_2 | ||
| 755 | addxcc c_3,t_2,c_3 != | ||
| 756 | addx c_1,%g0,c_1 | ||
| 757 | umul a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1); | ||
| 758 | addcc c_2,t_1,c_2 | ||
| 759 | rd %y,t_2 != | ||
| 760 | addxcc c_3,t_2,c_3 | ||
| 761 | addx c_1,%g0,c_1 | ||
| 762 | ld ap(7),a_7 | ||
| 763 | umul a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1); | ||
| 764 | addcc c_2,t_1,c_2 | ||
| 765 | rd %y,t_2 | ||
| 766 | addxcc c_3,t_2,c_3 | ||
| 767 | addx c_1,%g0,c_1 != | ||
| 768 | umul a_7,b_0,t_1 !mul_add_c(a[7],b[0],c2,c3,c1); | ||
| 769 | addcc c_2,t_1,c_2 | ||
| 770 | rd %y,t_2 | ||
| 771 | addxcc c_3,t_2,c_3 != | ||
| 772 | addx c_1,%g0,c_1 | ||
| 773 | st c_2,rp(7) !r[7]=c2; | ||
| 774 | |||
| 775 | umul a_7,b_1,t_1 !mul_add_c(a[7],b[1],c3,c1,c2); | ||
| 776 | addcc c_3,t_1,c_3 != | ||
| 777 | rd %y,t_2 | ||
| 778 | addxcc c_1,t_2,c_1 | ||
| 779 | addx %g0,%g0,c_2 | ||
| 780 | umul a_6,b_2,t_1 !=!mul_add_c(a[6],b[2],c3,c1,c2); | ||
| 781 | addcc c_3,t_1,c_3 | ||
| 782 | rd %y,t_2 | ||
| 783 | addxcc c_1,t_2,c_1 | ||
| 784 | addx c_2,%g0,c_2 != | ||
| 785 | umul a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2); | ||
| 786 | addcc c_3,t_1,c_3 | ||
| 787 | rd %y,t_2 | ||
| 788 | addxcc c_1,t_2,c_1 != | ||
| 789 | addx c_2,%g0,c_2 | ||
| 790 | umul a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2); | ||
| 791 | addcc c_3,t_1,c_3 | ||
| 792 | rd %y,t_2 != | ||
| 793 | addxcc c_1,t_2,c_1 | ||
| 794 | addx c_2,%g0,c_2 | ||
| 795 | umul a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2); | ||
| 796 | addcc c_3,t_1,c_3 != | ||
| 797 | rd %y,t_2 | ||
| 798 | addxcc c_1,t_2,c_1 | ||
| 799 | addx c_2,%g0,c_2 | ||
| 800 | umul a_2,b_6,t_1 !=!mul_add_c(a[2],b[6],c3,c1,c2); | ||
| 801 | addcc c_3,t_1,c_3 | ||
| 802 | rd %y,t_2 | ||
| 803 | addxcc c_1,t_2,c_1 | ||
| 804 | addx c_2,%g0,c_2 != | ||
| 805 | umul a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2); | ||
| 806 | addcc c_3,t_1,c_3 | ||
| 807 | rd %y,t_2 | ||
| 808 | addxcc c_1,t_2,c_1 ! | ||
| 809 | addx c_2,%g0,c_2 | ||
| 810 | st c_3,rp(8) !r[8]=c3; | ||
| 811 | |||
| 812 | umul a_2,b_7,t_1 !mul_add_c(a[2],b[7],c1,c2,c3); | ||
| 813 | addcc c_1,t_1,c_1 != | ||
| 814 | rd %y,t_2 | ||
| 815 | addxcc c_2,t_2,c_2 | ||
| 816 | addx %g0,%g0,c_3 | ||
| 817 | umul a_3,b_6,t_1 !=!mul_add_c(a[3],b[6],c1,c2,c3); | ||
| 818 | addcc c_1,t_1,c_1 | ||
| 819 | rd %y,t_2 | ||
| 820 | addxcc c_2,t_2,c_2 | ||
| 821 | addx c_3,%g0,c_3 != | ||
| 822 | umul a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3); | ||
| 823 | addcc c_1,t_1,c_1 | ||
| 824 | rd %y,t_2 | ||
| 825 | addxcc c_2,t_2,c_2 != | ||
| 826 | addx c_3,%g0,c_3 | ||
| 827 | umul a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3); | ||
| 828 | addcc c_1,t_1,c_1 | ||
| 829 | rd %y,t_2 != | ||
| 830 | addxcc c_2,t_2,c_2 | ||
| 831 | addx c_3,%g0,c_3 | ||
| 832 | umul a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3); | ||
| 833 | addcc c_1,t_1,c_1 != | ||
| 834 | rd %y,t_2 | ||
| 835 | addxcc c_2,t_2,c_2 | ||
| 836 | addx c_3,%g0,c_3 | ||
| 837 | umul a_7,b_2,t_1 !=!mul_add_c(a[7],b[2],c1,c2,c3); | ||
| 838 | addcc c_1,t_1,c_1 | ||
| 839 | rd %y,t_2 | ||
| 840 | addxcc c_2,t_2,c_2 | ||
| 841 | addx c_3,%g0,c_3 != | ||
| 842 | st c_1,rp(9) !r[9]=c1; | ||
| 843 | |||
| 844 | umul a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1); | ||
| 845 | addcc c_2,t_1,c_2 | ||
| 846 | rd %y,t_2 != | ||
| 847 | addxcc c_3,t_2,c_3 | ||
| 848 | addx %g0,%g0,c_1 | ||
| 849 | umul a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1); | ||
| 850 | addcc c_2,t_1,c_2 != | ||
| 851 | rd %y,t_2 | ||
| 852 | addxcc c_3,t_2,c_3 | ||
| 853 | addx c_1,%g0,c_1 | ||
| 854 | umul a_5,b_5,t_1 !=!mul_add_c(a[5],b[5],c2,c3,c1); | ||
| 855 | addcc c_2,t_1,c_2 | ||
| 856 | rd %y,t_2 | ||
| 857 | addxcc c_3,t_2,c_3 | ||
| 858 | addx c_1,%g0,c_1 != | ||
| 859 | umul a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1); | ||
| 860 | addcc c_2,t_1,c_2 | ||
| 861 | rd %y,t_2 | ||
| 862 | addxcc c_3,t_2,c_3 != | ||
| 863 | addx c_1,%g0,c_1 | ||
| 864 | umul a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1); | ||
| 865 | addcc c_2,t_1,c_2 | ||
| 866 | rd %y,t_2 != | ||
| 867 | addxcc c_3,t_2,c_3 | ||
| 868 | addx c_1,%g0,c_1 | ||
| 869 | st c_2,rp(10) !r[10]=c2; | ||
| 870 | |||
| 871 | umul a_4,b_7,t_1 !=!mul_add_c(a[4],b[7],c3,c1,c2); | ||
| 872 | addcc c_3,t_1,c_3 | ||
| 873 | rd %y,t_2 | ||
| 874 | addxcc c_1,t_2,c_1 | ||
| 875 | addx %g0,%g0,c_2 != | ||
| 876 | umul a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2); | ||
| 877 | addcc c_3,t_1,c_3 | ||
| 878 | rd %y,t_2 | ||
| 879 | addxcc c_1,t_2,c_1 != | ||
| 880 | addx c_2,%g0,c_2 | ||
| 881 | umul a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2); | ||
| 882 | addcc c_3,t_1,c_3 | ||
| 883 | rd %y,t_2 != | ||
| 884 | addxcc c_1,t_2,c_1 | ||
| 885 | addx c_2,%g0,c_2 | ||
| 886 | umul a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2); | ||
| 887 | addcc c_3,t_1,c_3 != | ||
| 888 | rd %y,t_2 | ||
| 889 | addxcc c_1,t_2,c_1 | ||
| 890 | st c_3,rp(11) !r[11]=c3; | ||
| 891 | addx c_2,%g0,c_2 != | ||
| 892 | |||
| 893 | umul a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3); | ||
| 894 | addcc c_1,t_1,c_1 | ||
| 895 | rd %y,t_2 | ||
| 896 | addxcc c_2,t_2,c_2 != | ||
| 897 | addx %g0,%g0,c_3 | ||
| 898 | umul a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3); | ||
| 899 | addcc c_1,t_1,c_1 | ||
| 900 | rd %y,t_2 != | ||
| 901 | addxcc c_2,t_2,c_2 | ||
| 902 | addx c_3,%g0,c_3 | ||
| 903 | umul a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3); | ||
| 904 | addcc c_1,t_1,c_1 != | ||
| 905 | rd %y,t_2 | ||
| 906 | addxcc c_2,t_2,c_2 | ||
| 907 | st c_1,rp(12) !r[12]=c1; | ||
| 908 | addx c_3,%g0,c_3 != | ||
| 909 | |||
| 910 | umul a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1); | ||
| 911 | addcc c_2,t_1,c_2 | ||
| 912 | rd %y,t_2 | ||
| 913 | addxcc c_3,t_2,c_3 != | ||
| 914 | addx %g0,%g0,c_1 | ||
| 915 | umul a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1); | ||
| 916 | addcc c_2,t_1,c_2 | ||
| 917 | rd %y,t_2 != | ||
| 918 | addxcc c_3,t_2,c_3 | ||
| 919 | addx c_1,%g0,c_1 | ||
| 920 | st c_2,rp(13) !r[13]=c2; | ||
| 921 | |||
| 922 | umul a_7,b_7,t_1 !=!mul_add_c(a[7],b[7],c3,c1,c2); | ||
| 923 | addcc c_3,t_1,c_3 | ||
| 924 | rd %y,t_2 | ||
| 925 | addxcc c_1,t_2,c_1 | ||
| 926 | nop != | ||
| 927 | st c_3,rp(14) !r[14]=c3; | ||
| 928 | st c_1,rp(15) !r[15]=c1; | ||
| 929 | |||
| 930 | ret | ||
| 931 | restore %g0,%g0,%o0 | ||
| 932 | |||
| 933 | .type bn_mul_comba8,#function | ||
| 934 | .size bn_mul_comba8,(.-bn_mul_comba8) | ||
| 935 | |||
| 936 | .align 32 | ||
| 937 | |||
| 938 | .global bn_mul_comba4 | ||
| 939 | /* | ||
| 940 | * void bn_mul_comba4(r,a,b) | ||
| 941 | * BN_ULONG *r,*a,*b; | ||
| 942 | */ | ||
| 943 | bn_mul_comba4: | ||
| 944 | save %sp,FRAME_SIZE,%sp | ||
| 945 | ld ap(0),a_0 | ||
| 946 | ld bp(0),b_0 | ||
| 947 | umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3); | ||
| 948 | ld bp(1),b_1 | ||
| 949 | rd %y,c_2 | ||
| 950 | st c_1,rp(0) !r[0]=c1; | ||
| 951 | |||
| 952 | umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1); | ||
| 953 | ld ap(1),a_1 | ||
| 954 | addcc c_2,t_1,c_2 | ||
| 955 | rd %y,t_2 != | ||
| 956 | addxcc %g0,t_2,c_3 | ||
| 957 | addx %g0,%g0,c_1 | ||
| 958 | ld ap(2),a_2 | ||
| 959 | umul a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1); | ||
| 960 | addcc c_2,t_1,c_2 | ||
| 961 | rd %y,t_2 | ||
| 962 | addxcc c_3,t_2,c_3 | ||
| 963 | addx c_1,%g0,c_1 != | ||
| 964 | st c_2,rp(1) !r[1]=c2; | ||
| 965 | |||
| 966 | umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2); | ||
| 967 | addcc c_3,t_1,c_3 | ||
| 968 | rd %y,t_2 != | ||
| 969 | addxcc c_1,t_2,c_1 | ||
| 970 | addx %g0,%g0,c_2 | ||
| 971 | ld bp(2),b_2 | ||
| 972 | umul a_1,b_1,t_1 !=!mul_add_c(a[1],b[1],c3,c1,c2); | ||
| 973 | addcc c_3,t_1,c_3 | ||
| 974 | rd %y,t_2 | ||
| 975 | addxcc c_1,t_2,c_1 | ||
| 976 | addx c_2,%g0,c_2 != | ||
| 977 | ld bp(3),b_3 | ||
| 978 | umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2); | ||
| 979 | addcc c_3,t_1,c_3 | ||
| 980 | rd %y,t_2 != | ||
| 981 | addxcc c_1,t_2,c_1 | ||
| 982 | addx c_2,%g0,c_2 | ||
| 983 | st c_3,rp(2) !r[2]=c3; | ||
| 984 | |||
| 985 | umul a_0,b_3,t_1 !=!mul_add_c(a[0],b[3],c1,c2,c3); | ||
| 986 | addcc c_1,t_1,c_1 | ||
| 987 | rd %y,t_2 | ||
| 988 | addxcc c_2,t_2,c_2 | ||
| 989 | addx %g0,%g0,c_3 != | ||
| 990 | umul a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3); | ||
| 991 | addcc c_1,t_1,c_1 | ||
| 992 | rd %y,t_2 | ||
| 993 | addxcc c_2,t_2,c_2 != | ||
| 994 | addx c_3,%g0,c_3 | ||
| 995 | ld ap(3),a_3 | ||
| 996 | umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3); | ||
| 997 | addcc c_1,t_1,c_1 != | ||
| 998 | rd %y,t_2 | ||
| 999 | addxcc c_2,t_2,c_2 | ||
| 1000 | addx c_3,%g0,c_3 | ||
| 1001 | umul a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3); | ||
| 1002 | addcc c_1,t_1,c_1 | ||
| 1003 | rd %y,t_2 | ||
| 1004 | addxcc c_2,t_2,c_2 | ||
| 1005 | addx c_3,%g0,c_3 != | ||
| 1006 | st c_1,rp(3) !r[3]=c1; | ||
| 1007 | |||
| 1008 | umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1); | ||
| 1009 | addcc c_2,t_1,c_2 | ||
| 1010 | rd %y,t_2 != | ||
| 1011 | addxcc c_3,t_2,c_3 | ||
| 1012 | addx %g0,%g0,c_1 | ||
| 1013 | umul a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1); | ||
| 1014 | addcc c_2,t_1,c_2 != | ||
| 1015 | rd %y,t_2 | ||
| 1016 | addxcc c_3,t_2,c_3 | ||
| 1017 | addx c_1,%g0,c_1 | ||
| 1018 | umul a_1,b_3,t_1 !=!mul_add_c(a[1],b[3],c2,c3,c1); | ||
| 1019 | addcc c_2,t_1,c_2 | ||
| 1020 | rd %y,t_2 | ||
| 1021 | addxcc c_3,t_2,c_3 | ||
| 1022 | addx c_1,%g0,c_1 != | ||
| 1023 | st c_2,rp(4) !r[4]=c2; | ||
| 1024 | |||
| 1025 | umul a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2); | ||
| 1026 | addcc c_3,t_1,c_3 | ||
| 1027 | rd %y,t_2 != | ||
| 1028 | addxcc c_1,t_2,c_1 | ||
| 1029 | addx %g0,%g0,c_2 | ||
| 1030 | umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2); | ||
| 1031 | addcc c_3,t_1,c_3 != | ||
| 1032 | rd %y,t_2 | ||
| 1033 | addxcc c_1,t_2,c_1 | ||
| 1034 | st c_3,rp(5) !r[5]=c3; | ||
| 1035 | addx c_2,%g0,c_2 != | ||
| 1036 | |||
| 1037 | umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3); | ||
| 1038 | addcc c_1,t_1,c_1 | ||
| 1039 | rd %y,t_2 | ||
| 1040 | addxcc c_2,t_2,c_2 != | ||
| 1041 | st c_1,rp(6) !r[6]=c1; | ||
| 1042 | st c_2,rp(7) !r[7]=c2; | ||
| 1043 | |||
| 1044 | ret | ||
| 1045 | restore %g0,%g0,%o0 | ||
| 1046 | |||
| 1047 | .type bn_mul_comba4,#function | ||
| 1048 | .size bn_mul_comba4,(.-bn_mul_comba4) | ||
| 1049 | |||
| 1050 | .align 32 | ||
| 1051 | |||
| 1052 | .global bn_sqr_comba8 | ||
| 1053 | bn_sqr_comba8: | ||
| 1054 | save %sp,FRAME_SIZE,%sp | ||
| 1055 | ld ap(0),a_0 | ||
| 1056 | ld ap(1),a_1 | ||
| 1057 | umul a_0,a_0,c_1 !=!sqr_add_c(a,0,c1,c2,c3); | ||
| 1058 | rd %y,c_2 | ||
| 1059 | st c_1,rp(0) !r[0]=c1; | ||
| 1060 | |||
| 1061 | ld ap(2),a_2 | ||
| 1062 | umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1); | ||
| 1063 | addcc c_2,t_1,c_2 | ||
| 1064 | rd %y,t_2 | ||
| 1065 | addxcc %g0,t_2,c_3 | ||
| 1066 | addx %g0,%g0,c_1 != | ||
| 1067 | addcc c_2,t_1,c_2 | ||
| 1068 | addxcc c_3,t_2,c_3 | ||
| 1069 | st c_2,rp(1) !r[1]=c2; | ||
| 1070 | addx c_1,%g0,c_1 != | ||
| 1071 | |||
| 1072 | umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2); | ||
| 1073 | addcc c_3,t_1,c_3 | ||
| 1074 | rd %y,t_2 | ||
| 1075 | addxcc c_1,t_2,c_1 != | ||
| 1076 | addx %g0,%g0,c_2 | ||
| 1077 | addcc c_3,t_1,c_3 | ||
| 1078 | addxcc c_1,t_2,c_1 | ||
| 1079 | addx c_2,%g0,c_2 != | ||
| 1080 | ld ap(3),a_3 | ||
| 1081 | umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2); | ||
| 1082 | addcc c_3,t_1,c_3 | ||
| 1083 | rd %y,t_2 != | ||
| 1084 | addxcc c_1,t_2,c_1 | ||
| 1085 | addx c_2,%g0,c_2 | ||
| 1086 | st c_3,rp(2) !r[2]=c3; | ||
| 1087 | |||
| 1088 | umul a_0,a_3,t_1 !=!sqr_add_c2(a,3,0,c1,c2,c3); | ||
| 1089 | addcc c_1,t_1,c_1 | ||
| 1090 | rd %y,t_2 | ||
| 1091 | addxcc c_2,t_2,c_2 | ||
| 1092 | addx %g0,%g0,c_3 != | ||
| 1093 | addcc c_1,t_1,c_1 | ||
| 1094 | addxcc c_2,t_2,c_2 | ||
| 1095 | ld ap(4),a_4 | ||
| 1096 | addx c_3,%g0,c_3 != | ||
| 1097 | umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3); | ||
| 1098 | addcc c_1,t_1,c_1 | ||
| 1099 | rd %y,t_2 | ||
| 1100 | addxcc c_2,t_2,c_2 != | ||
| 1101 | addx c_3,%g0,c_3 | ||
| 1102 | addcc c_1,t_1,c_1 | ||
| 1103 | addxcc c_2,t_2,c_2 | ||
| 1104 | addx c_3,%g0,c_3 != | ||
| 1105 | st c_1,rp(3) !r[3]=c1; | ||
| 1106 | |||
| 1107 | umul a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1); | ||
| 1108 | addcc c_2,t_1,c_2 | ||
| 1109 | rd %y,t_2 != | ||
| 1110 | addxcc c_3,t_2,c_3 | ||
| 1111 | addx %g0,%g0,c_1 | ||
| 1112 | addcc c_2,t_1,c_2 | ||
| 1113 | addxcc c_3,t_2,c_3 != | ||
| 1114 | addx c_1,%g0,c_1 | ||
| 1115 | umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1); | ||
| 1116 | addcc c_2,t_1,c_2 | ||
| 1117 | rd %y,t_2 != | ||
| 1118 | addxcc c_3,t_2,c_3 | ||
| 1119 | addx c_1,%g0,c_1 | ||
| 1120 | addcc c_2,t_1,c_2 | ||
| 1121 | addxcc c_3,t_2,c_3 != | ||
| 1122 | addx c_1,%g0,c_1 | ||
| 1123 | ld ap(5),a_5 | ||
| 1124 | umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1); | ||
| 1125 | addcc c_2,t_1,c_2 != | ||
| 1126 | rd %y,t_2 | ||
| 1127 | addxcc c_3,t_2,c_3 | ||
| 1128 | st c_2,rp(4) !r[4]=c2; | ||
| 1129 | addx c_1,%g0,c_1 != | ||
| 1130 | |||
| 1131 | umul a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2); | ||
| 1132 | addcc c_3,t_1,c_3 | ||
| 1133 | rd %y,t_2 | ||
| 1134 | addxcc c_1,t_2,c_1 != | ||
| 1135 | addx %g0,%g0,c_2 | ||
| 1136 | addcc c_3,t_1,c_3 | ||
| 1137 | addxcc c_1,t_2,c_1 | ||
| 1138 | addx c_2,%g0,c_2 != | ||
| 1139 | umul a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2); | ||
| 1140 | addcc c_3,t_1,c_3 | ||
| 1141 | rd %y,t_2 | ||
| 1142 | addxcc c_1,t_2,c_1 != | ||
| 1143 | addx c_2,%g0,c_2 | ||
| 1144 | addcc c_3,t_1,c_3 | ||
| 1145 | addxcc c_1,t_2,c_1 | ||
| 1146 | addx c_2,%g0,c_2 != | ||
| 1147 | ld ap(6),a_6 | ||
| 1148 | umul a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2); | ||
| 1149 | addcc c_3,t_1,c_3 | ||
| 1150 | rd %y,t_2 != | ||
| 1151 | addxcc c_1,t_2,c_1 | ||
| 1152 | addx c_2,%g0,c_2 | ||
| 1153 | addcc c_3,t_1,c_3 | ||
| 1154 | addxcc c_1,t_2,c_1 != | ||
| 1155 | addx c_2,%g0,c_2 | ||
| 1156 | st c_3,rp(5) !r[5]=c3; | ||
| 1157 | |||
| 1158 | umul a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3); | ||
| 1159 | addcc c_1,t_1,c_1 != | ||
| 1160 | rd %y,t_2 | ||
| 1161 | addxcc c_2,t_2,c_2 | ||
| 1162 | addx %g0,%g0,c_3 | ||
| 1163 | addcc c_1,t_1,c_1 != | ||
| 1164 | addxcc c_2,t_2,c_2 | ||
| 1165 | addx c_3,%g0,c_3 | ||
| 1166 | umul a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3); | ||
| 1167 | addcc c_1,t_1,c_1 != | ||
| 1168 | rd %y,t_2 | ||
| 1169 | addxcc c_2,t_2,c_2 | ||
| 1170 | addx c_3,%g0,c_3 | ||
| 1171 | addcc c_1,t_1,c_1 != | ||
| 1172 | addxcc c_2,t_2,c_2 | ||
| 1173 | addx c_3,%g0,c_3 | ||
| 1174 | umul a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3); | ||
| 1175 | addcc c_1,t_1,c_1 != | ||
| 1176 | rd %y,t_2 | ||
| 1177 | addxcc c_2,t_2,c_2 | ||
| 1178 | addx c_3,%g0,c_3 | ||
| 1179 | addcc c_1,t_1,c_1 != | ||
| 1180 | addxcc c_2,t_2,c_2 | ||
| 1181 | addx c_3,%g0,c_3 | ||
| 1182 | ld ap(7),a_7 | ||
| 1183 | umul a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3); | ||
| 1184 | addcc c_1,t_1,c_1 | ||
| 1185 | rd %y,t_2 | ||
| 1186 | addxcc c_2,t_2,c_2 | ||
| 1187 | addx c_3,%g0,c_3 != | ||
| 1188 | st c_1,rp(6) !r[6]=c1; | ||
| 1189 | |||
| 1190 | umul a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1); | ||
| 1191 | addcc c_2,t_1,c_2 | ||
| 1192 | rd %y,t_2 != | ||
| 1193 | addxcc c_3,t_2,c_3 | ||
| 1194 | addx %g0,%g0,c_1 | ||
| 1195 | addcc c_2,t_1,c_2 | ||
| 1196 | addxcc c_3,t_2,c_3 != | ||
| 1197 | addx c_1,%g0,c_1 | ||
| 1198 | umul a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1); | ||
| 1199 | addcc c_2,t_1,c_2 | ||
| 1200 | rd %y,t_2 != | ||
| 1201 | addxcc c_3,t_2,c_3 | ||
| 1202 | addx c_1,%g0,c_1 | ||
| 1203 | addcc c_2,t_1,c_2 | ||
| 1204 | addxcc c_3,t_2,c_3 != | ||
| 1205 | addx c_1,%g0,c_1 | ||
| 1206 | umul a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1); | ||
| 1207 | addcc c_2,t_1,c_2 | ||
| 1208 | rd %y,t_2 != | ||
| 1209 | addxcc c_3,t_2,c_3 | ||
| 1210 | addx c_1,%g0,c_1 | ||
| 1211 | addcc c_2,t_1,c_2 | ||
| 1212 | addxcc c_3,t_2,c_3 != | ||
| 1213 | addx c_1,%g0,c_1 | ||
| 1214 | umul a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1); | ||
| 1215 | addcc c_2,t_1,c_2 | ||
| 1216 | rd %y,t_2 != | ||
| 1217 | addxcc c_3,t_2,c_3 | ||
| 1218 | addx c_1,%g0,c_1 | ||
| 1219 | addcc c_2,t_1,c_2 | ||
| 1220 | addxcc c_3,t_2,c_3 != | ||
| 1221 | addx c_1,%g0,c_1 | ||
| 1222 | st c_2,rp(7) !r[7]=c2; | ||
| 1223 | |||
| 1224 | umul a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2); | ||
| 1225 | addcc c_3,t_1,c_3 != | ||
| 1226 | rd %y,t_2 | ||
| 1227 | addxcc c_1,t_2,c_1 | ||
| 1228 | addx %g0,%g0,c_2 | ||
| 1229 | addcc c_3,t_1,c_3 != | ||
| 1230 | addxcc c_1,t_2,c_1 | ||
| 1231 | addx c_2,%g0,c_2 | ||
| 1232 | umul a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2); | ||
| 1233 | addcc c_3,t_1,c_3 != | ||
| 1234 | rd %y,t_2 | ||
| 1235 | addxcc c_1,t_2,c_1 | ||
| 1236 | addx c_2,%g0,c_2 | ||
| 1237 | addcc c_3,t_1,c_3 != | ||
| 1238 | addxcc c_1,t_2,c_1 | ||
| 1239 | addx c_2,%g0,c_2 | ||
| 1240 | umul a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2); | ||
| 1241 | addcc c_3,t_1,c_3 != | ||
| 1242 | rd %y,t_2 | ||
| 1243 | addxcc c_1,t_2,c_1 | ||
| 1244 | addx c_2,%g0,c_2 | ||
| 1245 | addcc c_3,t_1,c_3 != | ||
| 1246 | addxcc c_1,t_2,c_1 | ||
| 1247 | addx c_2,%g0,c_2 | ||
| 1248 | umul a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2); | ||
| 1249 | addcc c_3,t_1,c_3 != | ||
| 1250 | rd %y,t_2 | ||
| 1251 | addxcc c_1,t_2,c_1 | ||
| 1252 | st c_3,rp(8) !r[8]=c3; | ||
| 1253 | addx c_2,%g0,c_2 != | ||
| 1254 | |||
| 1255 | umul a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3); | ||
| 1256 | addcc c_1,t_1,c_1 | ||
| 1257 | rd %y,t_2 | ||
| 1258 | addxcc c_2,t_2,c_2 != | ||
| 1259 | addx %g0,%g0,c_3 | ||
| 1260 | addcc c_1,t_1,c_1 | ||
| 1261 | addxcc c_2,t_2,c_2 | ||
| 1262 | addx c_3,%g0,c_3 != | ||
| 1263 | umul a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3); | ||
| 1264 | addcc c_1,t_1,c_1 | ||
| 1265 | rd %y,t_2 | ||
| 1266 | addxcc c_2,t_2,c_2 != | ||
| 1267 | addx c_3,%g0,c_3 | ||
| 1268 | addcc c_1,t_1,c_1 | ||
| 1269 | addxcc c_2,t_2,c_2 | ||
| 1270 | addx c_3,%g0,c_3 != | ||
| 1271 | umul a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3); | ||
| 1272 | addcc c_1,t_1,c_1 | ||
| 1273 | rd %y,t_2 | ||
| 1274 | addxcc c_2,t_2,c_2 != | ||
| 1275 | addx c_3,%g0,c_3 | ||
| 1276 | addcc c_1,t_1,c_1 | ||
| 1277 | addxcc c_2,t_2,c_2 | ||
| 1278 | addx c_3,%g0,c_3 != | ||
| 1279 | st c_1,rp(9) !r[9]=c1; | ||
| 1280 | |||
| 1281 | umul a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1); | ||
| 1282 | addcc c_2,t_1,c_2 | ||
| 1283 | rd %y,t_2 != | ||
| 1284 | addxcc c_3,t_2,c_3 | ||
| 1285 | addx %g0,%g0,c_1 | ||
| 1286 | addcc c_2,t_1,c_2 | ||
| 1287 | addxcc c_3,t_2,c_3 != | ||
| 1288 | addx c_1,%g0,c_1 | ||
| 1289 | umul a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1); | ||
| 1290 | addcc c_2,t_1,c_2 | ||
| 1291 | rd %y,t_2 != | ||
| 1292 | addxcc c_3,t_2,c_3 | ||
| 1293 | addx c_1,%g0,c_1 | ||
| 1294 | addcc c_2,t_1,c_2 | ||
| 1295 | addxcc c_3,t_2,c_3 != | ||
| 1296 | addx c_1,%g0,c_1 | ||
| 1297 | umul a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1); | ||
| 1298 | addcc c_2,t_1,c_2 | ||
| 1299 | rd %y,t_2 != | ||
| 1300 | addxcc c_3,t_2,c_3 | ||
| 1301 | addx c_1,%g0,c_1 | ||
| 1302 | st c_2,rp(10) !r[10]=c2; | ||
| 1303 | |||
| 1304 | umul a_4,a_7,t_1 !=!sqr_add_c2(a,7,4,c3,c1,c2); | ||
| 1305 | addcc c_3,t_1,c_3 | ||
| 1306 | rd %y,t_2 | ||
| 1307 | addxcc c_1,t_2,c_1 | ||
| 1308 | addx %g0,%g0,c_2 != | ||
| 1309 | addcc c_3,t_1,c_3 | ||
| 1310 | addxcc c_1,t_2,c_1 | ||
| 1311 | addx c_2,%g0,c_2 | ||
| 1312 | umul a_5,a_6,t_1 !=!sqr_add_c2(a,6,5,c3,c1,c2); | ||
| 1313 | addcc c_3,t_1,c_3 | ||
| 1314 | rd %y,t_2 | ||
| 1315 | addxcc c_1,t_2,c_1 | ||
| 1316 | addx c_2,%g0,c_2 != | ||
| 1317 | addcc c_3,t_1,c_3 | ||
| 1318 | addxcc c_1,t_2,c_1 | ||
| 1319 | st c_3,rp(11) !r[11]=c3; | ||
| 1320 | addx c_2,%g0,c_2 != | ||
| 1321 | |||
| 1322 | umul a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3); | ||
| 1323 | addcc c_1,t_1,c_1 | ||
| 1324 | rd %y,t_2 | ||
| 1325 | addxcc c_2,t_2,c_2 != | ||
| 1326 | addx %g0,%g0,c_3 | ||
| 1327 | addcc c_1,t_1,c_1 | ||
| 1328 | addxcc c_2,t_2,c_2 | ||
| 1329 | addx c_3,%g0,c_3 != | ||
| 1330 | umul a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3); | ||
| 1331 | addcc c_1,t_1,c_1 | ||
| 1332 | rd %y,t_2 | ||
| 1333 | addxcc c_2,t_2,c_2 != | ||
| 1334 | addx c_3,%g0,c_3 | ||
| 1335 | st c_1,rp(12) !r[12]=c1; | ||
| 1336 | |||
| 1337 | umul a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1); | ||
| 1338 | addcc c_2,t_1,c_2 != | ||
| 1339 | rd %y,t_2 | ||
| 1340 | addxcc c_3,t_2,c_3 | ||
| 1341 | addx %g0,%g0,c_1 | ||
| 1342 | addcc c_2,t_1,c_2 != | ||
| 1343 | addxcc c_3,t_2,c_3 | ||
| 1344 | st c_2,rp(13) !r[13]=c2; | ||
| 1345 | addx c_1,%g0,c_1 != | ||
| 1346 | |||
| 1347 | umul a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2); | ||
| 1348 | addcc c_3,t_1,c_3 | ||
| 1349 | rd %y,t_2 | ||
| 1350 | addxcc c_1,t_2,c_1 != | ||
| 1351 | st c_3,rp(14) !r[14]=c3; | ||
| 1352 | st c_1,rp(15) !r[15]=c1; | ||
| 1353 | |||
| 1354 | ret | ||
| 1355 | restore %g0,%g0,%o0 | ||
| 1356 | |||
| 1357 | .type bn_sqr_comba8,#function | ||
| 1358 | .size bn_sqr_comba8,(.-bn_sqr_comba8) | ||
| 1359 | |||
| 1360 | .align 32 | ||
| 1361 | |||
| 1362 | .global bn_sqr_comba4 | ||
| 1363 | /* | ||
| 1364 | * void bn_sqr_comba4(r,a) | ||
| 1365 | * BN_ULONG *r,*a; | ||
| 1366 | */ | ||
| 1367 | bn_sqr_comba4: | ||
| 1368 | save %sp,FRAME_SIZE,%sp | ||
| 1369 | ld ap(0),a_0 | ||
| 1370 | umul a_0,a_0,c_1 !sqr_add_c(a,0,c1,c2,c3); | ||
| 1371 | ld ap(1),a_1 != | ||
| 1372 | rd %y,c_2 | ||
| 1373 | st c_1,rp(0) !r[0]=c1; | ||
| 1374 | |||
| 1375 | ld ap(2),a_2 | ||
| 1376 | umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1); | ||
| 1377 | addcc c_2,t_1,c_2 | ||
| 1378 | rd %y,t_2 | ||
| 1379 | addxcc %g0,t_2,c_3 | ||
| 1380 | addx %g0,%g0,c_1 != | ||
| 1381 | addcc c_2,t_1,c_2 | ||
| 1382 | addxcc c_3,t_2,c_3 | ||
| 1383 | addx c_1,%g0,c_1 != | ||
| 1384 | st c_2,rp(1) !r[1]=c2; | ||
| 1385 | |||
| 1386 | umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2); | ||
| 1387 | addcc c_3,t_1,c_3 | ||
| 1388 | rd %y,t_2 != | ||
| 1389 | addxcc c_1,t_2,c_1 | ||
| 1390 | addx %g0,%g0,c_2 | ||
| 1391 | addcc c_3,t_1,c_3 | ||
| 1392 | addxcc c_1,t_2,c_1 != | ||
| 1393 | addx c_2,%g0,c_2 | ||
| 1394 | ld ap(3),a_3 | ||
| 1395 | umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2); | ||
| 1396 | addcc c_3,t_1,c_3 != | ||
| 1397 | rd %y,t_2 | ||
| 1398 | addxcc c_1,t_2,c_1 | ||
| 1399 | st c_3,rp(2) !r[2]=c3; | ||
| 1400 | addx c_2,%g0,c_2 != | ||
| 1401 | |||
| 1402 | umul a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3); | ||
| 1403 | addcc c_1,t_1,c_1 | ||
| 1404 | rd %y,t_2 | ||
| 1405 | addxcc c_2,t_2,c_2 != | ||
| 1406 | addx %g0,%g0,c_3 | ||
| 1407 | addcc c_1,t_1,c_1 | ||
| 1408 | addxcc c_2,t_2,c_2 | ||
| 1409 | addx c_3,%g0,c_3 != | ||
| 1410 | umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3); | ||
| 1411 | addcc c_1,t_1,c_1 | ||
| 1412 | rd %y,t_2 | ||
| 1413 | addxcc c_2,t_2,c_2 != | ||
| 1414 | addx c_3,%g0,c_3 | ||
| 1415 | addcc c_1,t_1,c_1 | ||
| 1416 | addxcc c_2,t_2,c_2 | ||
| 1417 | addx c_3,%g0,c_3 != | ||
| 1418 | st c_1,rp(3) !r[3]=c1; | ||
| 1419 | |||
| 1420 | umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1); | ||
| 1421 | addcc c_2,t_1,c_2 | ||
| 1422 | rd %y,t_2 != | ||
| 1423 | addxcc c_3,t_2,c_3 | ||
| 1424 | addx %g0,%g0,c_1 | ||
| 1425 | addcc c_2,t_1,c_2 | ||
| 1426 | addxcc c_3,t_2,c_3 != | ||
| 1427 | addx c_1,%g0,c_1 | ||
| 1428 | umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1); | ||
| 1429 | addcc c_2,t_1,c_2 | ||
| 1430 | rd %y,t_2 != | ||
| 1431 | addxcc c_3,t_2,c_3 | ||
| 1432 | addx c_1,%g0,c_1 | ||
| 1433 | st c_2,rp(4) !r[4]=c2; | ||
| 1434 | |||
| 1435 | umul a_2,a_3,t_1 !=!sqr_add_c2(a,3,2,c3,c1,c2); | ||
| 1436 | addcc c_3,t_1,c_3 | ||
| 1437 | rd %y,t_2 | ||
| 1438 | addxcc c_1,t_2,c_1 | ||
| 1439 | addx %g0,%g0,c_2 != | ||
| 1440 | addcc c_3,t_1,c_3 | ||
| 1441 | addxcc c_1,t_2,c_1 | ||
| 1442 | st c_3,rp(5) !r[5]=c3; | ||
| 1443 | addx c_2,%g0,c_2 != | ||
| 1444 | |||
| 1445 | umul a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3); | ||
| 1446 | addcc c_1,t_1,c_1 | ||
| 1447 | rd %y,t_2 | ||
| 1448 | addxcc c_2,t_2,c_2 != | ||
| 1449 | st c_1,rp(6) !r[6]=c1; | ||
| 1450 | st c_2,rp(7) !r[7]=c2; | ||
| 1451 | |||
| 1452 | ret | ||
| 1453 | restore %g0,%g0,%o0 | ||
| 1454 | |||
| 1455 | .type bn_sqr_comba4,#function | ||
| 1456 | .size bn_sqr_comba4,(.-bn_sqr_comba4) | ||
| 1457 | |||
| 1458 | .align 32 | ||
diff --git a/src/lib/libcrypto/bn/asm/sparcv8plus.S b/src/lib/libcrypto/bn/asm/sparcv8plus.S deleted file mode 100644 index 0074dfdb75..0000000000 --- a/src/lib/libcrypto/bn/asm/sparcv8plus.S +++ /dev/null | |||
| @@ -1,1535 +0,0 @@ | |||
| 1 | .ident "sparcv8plus.s, Version 1.4" | ||
| 2 | .ident "SPARC v9 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>" | ||
| 3 | |||
| 4 | /* | ||
| 5 | * ==================================================================== | ||
| 6 | * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL | ||
| 7 | * project. | ||
| 8 | * | ||
| 9 | * Rights for redistribution and usage in source and binary forms are | ||
| 10 | * granted according to the OpenSSL license. Warranty of any kind is | ||
| 11 | * disclaimed. | ||
| 12 | * ==================================================================== | ||
| 13 | */ | ||
| 14 | |||
| 15 | /* | ||
| 16 | * This is my modest contributon to OpenSSL project (see | ||
| 17 | * http://www.openssl.org/ for more information about it) and is | ||
| 18 | * a drop-in UltraSPARC ISA replacement for crypto/bn/bn_asm.c | ||
| 19 | * module. For updates see http://fy.chalmers.se/~appro/hpe/. | ||
| 20 | * | ||
| 21 | * Questions-n-answers. | ||
| 22 | * | ||
| 23 | * Q. How to compile? | ||
| 24 | * A. With SC4.x/SC5.x: | ||
| 25 | * | ||
| 26 | * cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o | ||
| 27 | * | ||
| 28 | * and with gcc: | ||
| 29 | * | ||
| 30 | * gcc -mcpu=ultrasparc -c bn_asm.sparc.v8plus.S -o bn_asm.o | ||
| 31 | * | ||
| 32 | * or if above fails (it does if you have gas installed): | ||
| 33 | * | ||
| 34 | * gcc -E bn_asm.sparc.v8plus.S | as -xarch=v8plus /dev/fd/0 -o bn_asm.o | ||
| 35 | * | ||
| 36 | * Quick-n-dirty way to fuse the module into the library. | ||
| 37 | * Provided that the library is already configured and built | ||
| 38 | * (in 0.9.2 case with no-asm option): | ||
| 39 | * | ||
| 40 | * # cd crypto/bn | ||
| 41 | * # cp /some/place/bn_asm.sparc.v8plus.S . | ||
| 42 | * # cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o | ||
| 43 | * # make | ||
| 44 | * # cd ../.. | ||
| 45 | * # make; make test | ||
| 46 | * | ||
| 47 | * Quick-n-dirty way to get rid of it: | ||
| 48 | * | ||
| 49 | * # cd crypto/bn | ||
| 50 | * # touch bn_asm.c | ||
| 51 | * # make | ||
| 52 | * # cd ../.. | ||
| 53 | * # make; make test | ||
| 54 | * | ||
| 55 | * Q. V8plus achitecture? What kind of beast is that? | ||
| 56 | * A. Well, it's rather a programming model than an architecture... | ||
| 57 | * It's actually v9-compliant, i.e. *any* UltraSPARC, CPU under | ||
| 58 | * special conditions, namely when kernel doesn't preserve upper | ||
| 59 | * 32 bits of otherwise 64-bit registers during a context switch. | ||
| 60 | * | ||
| 61 | * Q. Why just UltraSPARC? What about SuperSPARC? | ||
| 62 | * A. Original release did target UltraSPARC only. Now SuperSPARC | ||
| 63 | * version is provided along. Both version share bn_*comba[48] | ||
| 64 | * implementations (see comment later in code for explanation). | ||
| 65 | * But what's so special about this UltraSPARC implementation? | ||
| 66 | * Why didn't I let compiler do the job? Trouble is that most of | ||
| 67 | * available compilers (well, SC5.0 is the only exception) don't | ||
| 68 | * attempt to take advantage of UltraSPARC's 64-bitness under | ||
| 69 | * 32-bit kernels even though it's perfectly possible (see next | ||
| 70 | * question). | ||
| 71 | * | ||
| 72 | * Q. 64-bit registers under 32-bit kernels? Didn't you just say it | ||
| 73 | * doesn't work? | ||
| 74 | * A. You can't adress *all* registers as 64-bit wide:-( The catch is | ||
| 75 | * that you actually may rely upon %o0-%o5 and %g1-%g4 being fully | ||
| 76 | * preserved if you're in a leaf function, i.e. such never calling | ||
| 77 | * any other functions. All functions in this module are leaf and | ||
| 78 | * 10 registers is a handful. And as a matter of fact none-"comba" | ||
| 79 | * routines don't require even that much and I could even afford to | ||
| 80 | * not allocate own stack frame for 'em:-) | ||
| 81 | * | ||
| 82 | * Q. What about 64-bit kernels? | ||
| 83 | * A. What about 'em? Just kidding:-) Pure 64-bit version is currently | ||
| 84 | * under evaluation and development... | ||
| 85 | * | ||
| 86 | * Q. What about shared libraries? | ||
| 87 | * A. What about 'em? Kidding again:-) Code does *not* contain any | ||
| 88 | * code position dependencies and it's safe to include it into | ||
| 89 | * shared library as is. | ||
| 90 | * | ||
| 91 | * Q. How much faster does it go? | ||
| 92 | * A. Do you have a good benchmark? In either case below is what I | ||
| 93 | * experience with crypto/bn/expspeed.c test program: | ||
| 94 | * | ||
| 95 | * v8plus module on U10/300MHz against bn_asm.c compiled with: | ||
| 96 | * | ||
| 97 | * cc-5.0 -xarch=v8plus -xO5 -xdepend +7-12% | ||
| 98 | * cc-4.2 -xarch=v8plus -xO5 -xdepend +25-35% | ||
| 99 | * egcs-1.1.2 -mcpu=ultrasparc -O3 +35-45% | ||
| 100 | * | ||
| 101 | * v8 module on SS10/60MHz against bn_asm.c compiled with: | ||
| 102 | * | ||
| 103 | * cc-5.0 -xarch=v8 -xO5 -xdepend +7-10% | ||
| 104 | * cc-4.2 -xarch=v8 -xO5 -xdepend +10% | ||
| 105 | * egcs-1.1.2 -mv8 -O3 +35-45% | ||
| 106 | * | ||
| 107 | * As you can see it's damn hard to beat the new Sun C compiler | ||
| 108 | * and it's in first place GNU C users who will appreciate this | ||
| 109 | * assembler implementation:-) | ||
| 110 | */ | ||
| 111 | |||
| 112 | /* | ||
| 113 | * Revision history. | ||
| 114 | * | ||
| 115 | * 1.0 - initial release; | ||
| 116 | * 1.1 - new loop unrolling model(*); | ||
| 117 | * - some more fine tuning; | ||
| 118 | * 1.2 - made gas friendly; | ||
| 119 | * - updates to documentation concerning v9; | ||
| 120 | * - new performance comparison matrix; | ||
| 121 | * 1.3 - fixed problem with /usr/ccs/lib/cpp; | ||
| 122 | * 1.4 - native V9 bn_*_comba[48] implementation (15% more efficient) | ||
| 123 | * resulting in slight overall performance kick; | ||
| 124 | * - some retunes; | ||
| 125 | * - support for GNU as added; | ||
| 126 | * | ||
| 127 | * (*) Originally unrolled loop looked like this: | ||
| 128 | * for (;;) { | ||
| 129 | * op(p+0); if (--n==0) break; | ||
| 130 | * op(p+1); if (--n==0) break; | ||
| 131 | * op(p+2); if (--n==0) break; | ||
| 132 | * op(p+3); if (--n==0) break; | ||
| 133 | * p+=4; | ||
| 134 | * } | ||
| 135 | * I unroll according to following: | ||
| 136 | * while (n&~3) { | ||
| 137 | * op(p+0); op(p+1); op(p+2); op(p+3); | ||
| 138 | * p+=4; n=-4; | ||
| 139 | * } | ||
| 140 | * if (n) { | ||
| 141 | * op(p+0); if (--n==0) return; | ||
| 142 | * op(p+2); if (--n==0) return; | ||
| 143 | * op(p+3); return; | ||
| 144 | * } | ||
| 145 | */ | ||
| 146 | |||
| 147 | /* | ||
| 148 | * GNU assembler can't stand stuw:-( | ||
| 149 | */ | ||
| 150 | #define stuw st | ||
| 151 | |||
| 152 | .section ".text",#alloc,#execinstr | ||
| 153 | .file "bn_asm.sparc.v8plus.S" | ||
| 154 | |||
| 155 | .align 32 | ||
| 156 | |||
| 157 | .global bn_mul_add_words | ||
| 158 | /* | ||
| 159 | * BN_ULONG bn_mul_add_words(rp,ap,num,w) | ||
| 160 | * BN_ULONG *rp,*ap; | ||
| 161 | * int num; | ||
| 162 | * BN_ULONG w; | ||
| 163 | */ | ||
| 164 | bn_mul_add_words: | ||
| 165 | brgz,a %o2,.L_bn_mul_add_words_proceed | ||
| 166 | lduw [%o1],%g2 | ||
| 167 | retl | ||
| 168 | clr %o0 | ||
| 169 | |||
| 170 | .L_bn_mul_add_words_proceed: | ||
| 171 | srl %o3,%g0,%o3 ! clruw %o3 | ||
| 172 | andcc %o2,-4,%g0 | ||
| 173 | bz,pn %icc,.L_bn_mul_add_words_tail | ||
| 174 | clr %o5 | ||
| 175 | |||
| 176 | .L_bn_mul_add_words_loop: ! wow! 32 aligned! | ||
| 177 | lduw [%o0],%g1 | ||
| 178 | lduw [%o1+4],%g3 | ||
| 179 | mulx %o3,%g2,%g2 | ||
| 180 | add %g1,%o5,%o4 | ||
| 181 | nop | ||
| 182 | add %o4,%g2,%o4 | ||
| 183 | stuw %o4,[%o0] | ||
| 184 | srlx %o4,32,%o5 | ||
| 185 | |||
| 186 | lduw [%o0+4],%g1 | ||
| 187 | lduw [%o1+8],%g2 | ||
| 188 | mulx %o3,%g3,%g3 | ||
| 189 | add %g1,%o5,%o4 | ||
| 190 | dec 4,%o2 | ||
| 191 | add %o4,%g3,%o4 | ||
| 192 | stuw %o4,[%o0+4] | ||
| 193 | srlx %o4,32,%o5 | ||
| 194 | |||
| 195 | lduw [%o0+8],%g1 | ||
| 196 | lduw [%o1+12],%g3 | ||
| 197 | mulx %o3,%g2,%g2 | ||
| 198 | add %g1,%o5,%o4 | ||
| 199 | inc 16,%o1 | ||
| 200 | add %o4,%g2,%o4 | ||
| 201 | stuw %o4,[%o0+8] | ||
| 202 | srlx %o4,32,%o5 | ||
| 203 | |||
| 204 | lduw [%o0+12],%g1 | ||
| 205 | mulx %o3,%g3,%g3 | ||
| 206 | add %g1,%o5,%o4 | ||
| 207 | inc 16,%o0 | ||
| 208 | add %o4,%g3,%o4 | ||
| 209 | andcc %o2,-4,%g0 | ||
| 210 | stuw %o4,[%o0-4] | ||
| 211 | srlx %o4,32,%o5 | ||
| 212 | bnz,a,pt %icc,.L_bn_mul_add_words_loop | ||
| 213 | lduw [%o1],%g2 | ||
| 214 | |||
| 215 | brnz,a,pn %o2,.L_bn_mul_add_words_tail | ||
| 216 | lduw [%o1],%g2 | ||
| 217 | .L_bn_mul_add_words_return: | ||
| 218 | retl | ||
| 219 | mov %o5,%o0 | ||
| 220 | |||
| 221 | .L_bn_mul_add_words_tail: | ||
| 222 | lduw [%o0],%g1 | ||
| 223 | mulx %o3,%g2,%g2 | ||
| 224 | add %g1,%o5,%o4 | ||
| 225 | dec %o2 | ||
| 226 | add %o4,%g2,%o4 | ||
| 227 | srlx %o4,32,%o5 | ||
| 228 | brz,pt %o2,.L_bn_mul_add_words_return | ||
| 229 | stuw %o4,[%o0] | ||
| 230 | |||
| 231 | lduw [%o1+4],%g2 | ||
| 232 | lduw [%o0+4],%g1 | ||
| 233 | mulx %o3,%g2,%g2 | ||
| 234 | add %g1,%o5,%o4 | ||
| 235 | dec %o2 | ||
| 236 | add %o4,%g2,%o4 | ||
| 237 | srlx %o4,32,%o5 | ||
| 238 | brz,pt %o2,.L_bn_mul_add_words_return | ||
| 239 | stuw %o4,[%o0+4] | ||
| 240 | |||
| 241 | lduw [%o1+8],%g2 | ||
| 242 | lduw [%o0+8],%g1 | ||
| 243 | mulx %o3,%g2,%g2 | ||
| 244 | add %g1,%o5,%o4 | ||
| 245 | add %o4,%g2,%o4 | ||
| 246 | stuw %o4,[%o0+8] | ||
| 247 | retl | ||
| 248 | srlx %o4,32,%o0 | ||
| 249 | |||
| 250 | .type bn_mul_add_words,#function | ||
| 251 | .size bn_mul_add_words,(.-bn_mul_add_words) | ||
| 252 | |||
| 253 | .align 32 | ||
| 254 | |||
| 255 | .global bn_mul_words | ||
| 256 | /* | ||
| 257 | * BN_ULONG bn_mul_words(rp,ap,num,w) | ||
| 258 | * BN_ULONG *rp,*ap; | ||
| 259 | * int num; | ||
| 260 | * BN_ULONG w; | ||
| 261 | */ | ||
| 262 | bn_mul_words: | ||
| 263 | brgz,a %o2,.L_bn_mul_words_proceeed | ||
| 264 | lduw [%o1],%g2 | ||
| 265 | retl | ||
| 266 | clr %o0 | ||
| 267 | |||
| 268 | .L_bn_mul_words_proceeed: | ||
| 269 | srl %o3,%g0,%o3 ! clruw %o3 | ||
| 270 | andcc %o2,-4,%g0 | ||
| 271 | bz,pn %icc,.L_bn_mul_words_tail | ||
| 272 | clr %o5 | ||
| 273 | |||
| 274 | .L_bn_mul_words_loop: ! wow! 32 aligned! | ||
| 275 | lduw [%o1+4],%g3 | ||
| 276 | mulx %o3,%g2,%g2 | ||
| 277 | add %g2,%o5,%o4 | ||
| 278 | nop | ||
| 279 | stuw %o4,[%o0] | ||
| 280 | srlx %o4,32,%o5 | ||
| 281 | |||
| 282 | lduw [%o1+8],%g2 | ||
| 283 | mulx %o3,%g3,%g3 | ||
| 284 | add %g3,%o5,%o4 | ||
| 285 | dec 4,%o2 | ||
| 286 | stuw %o4,[%o0+4] | ||
| 287 | srlx %o4,32,%o5 | ||
| 288 | |||
| 289 | lduw [%o1+12],%g3 | ||
| 290 | mulx %o3,%g2,%g2 | ||
| 291 | add %g2,%o5,%o4 | ||
| 292 | inc 16,%o1 | ||
| 293 | stuw %o4,[%o0+8] | ||
| 294 | srlx %o4,32,%o5 | ||
| 295 | |||
| 296 | mulx %o3,%g3,%g3 | ||
| 297 | add %g3,%o5,%o4 | ||
| 298 | inc 16,%o0 | ||
| 299 | stuw %o4,[%o0-4] | ||
| 300 | srlx %o4,32,%o5 | ||
| 301 | andcc %o2,-4,%g0 | ||
| 302 | bnz,a,pt %icc,.L_bn_mul_words_loop | ||
| 303 | lduw [%o1],%g2 | ||
| 304 | nop | ||
| 305 | nop | ||
| 306 | |||
| 307 | brnz,a,pn %o2,.L_bn_mul_words_tail | ||
| 308 | lduw [%o1],%g2 | ||
| 309 | .L_bn_mul_words_return: | ||
| 310 | retl | ||
| 311 | mov %o5,%o0 | ||
| 312 | |||
| 313 | .L_bn_mul_words_tail: | ||
| 314 | mulx %o3,%g2,%g2 | ||
| 315 | add %g2,%o5,%o4 | ||
| 316 | dec %o2 | ||
| 317 | srlx %o4,32,%o5 | ||
| 318 | brz,pt %o2,.L_bn_mul_words_return | ||
| 319 | stuw %o4,[%o0] | ||
| 320 | |||
| 321 | lduw [%o1+4],%g2 | ||
| 322 | mulx %o3,%g2,%g2 | ||
| 323 | add %g2,%o5,%o4 | ||
| 324 | dec %o2 | ||
| 325 | srlx %o4,32,%o5 | ||
| 326 | brz,pt %o2,.L_bn_mul_words_return | ||
| 327 | stuw %o4,[%o0+4] | ||
| 328 | |||
| 329 | lduw [%o1+8],%g2 | ||
| 330 | mulx %o3,%g2,%g2 | ||
| 331 | add %g2,%o5,%o4 | ||
| 332 | stuw %o4,[%o0+8] | ||
| 333 | retl | ||
| 334 | srlx %o4,32,%o0 | ||
| 335 | |||
| 336 | .type bn_mul_words,#function | ||
| 337 | .size bn_mul_words,(.-bn_mul_words) | ||
| 338 | |||
| 339 | .align 32 | ||
| 340 | .global bn_sqr_words | ||
| 341 | /* | ||
| 342 | * void bn_sqr_words(r,a,n) | ||
| 343 | * BN_ULONG *r,*a; | ||
| 344 | * int n; | ||
| 345 | */ | ||
| 346 | bn_sqr_words: | ||
| 347 | brgz,a %o2,.L_bn_sqr_words_proceeed | ||
| 348 | lduw [%o1],%g2 | ||
| 349 | retl | ||
| 350 | clr %o0 | ||
| 351 | |||
| 352 | .L_bn_sqr_words_proceeed: | ||
| 353 | andcc %o2,-4,%g0 | ||
| 354 | nop | ||
| 355 | bz,pn %icc,.L_bn_sqr_words_tail | ||
| 356 | nop | ||
| 357 | |||
| 358 | .L_bn_sqr_words_loop: ! wow! 32 aligned! | ||
| 359 | lduw [%o1+4],%g3 | ||
| 360 | mulx %g2,%g2,%o4 | ||
| 361 | stuw %o4,[%o0] | ||
| 362 | srlx %o4,32,%o5 | ||
| 363 | stuw %o5,[%o0+4] | ||
| 364 | nop | ||
| 365 | |||
| 366 | lduw [%o1+8],%g2 | ||
| 367 | mulx %g3,%g3,%o4 | ||
| 368 | dec 4,%o2 | ||
| 369 | stuw %o4,[%o0+8] | ||
| 370 | srlx %o4,32,%o5 | ||
| 371 | stuw %o5,[%o0+12] | ||
| 372 | |||
| 373 | lduw [%o1+12],%g3 | ||
| 374 | mulx %g2,%g2,%o4 | ||
| 375 | srlx %o4,32,%o5 | ||
| 376 | stuw %o4,[%o0+16] | ||
| 377 | inc 16,%o1 | ||
| 378 | stuw %o5,[%o0+20] | ||
| 379 | |||
| 380 | mulx %g3,%g3,%o4 | ||
| 381 | inc 32,%o0 | ||
| 382 | stuw %o4,[%o0-8] | ||
| 383 | srlx %o4,32,%o5 | ||
| 384 | andcc %o2,-4,%g2 | ||
| 385 | stuw %o5,[%o0-4] | ||
| 386 | bnz,a,pt %icc,.L_bn_sqr_words_loop | ||
| 387 | lduw [%o1],%g2 | ||
| 388 | nop | ||
| 389 | |||
| 390 | brnz,a,pn %o2,.L_bn_sqr_words_tail | ||
| 391 | lduw [%o1],%g2 | ||
| 392 | .L_bn_sqr_words_return: | ||
| 393 | retl | ||
| 394 | clr %o0 | ||
| 395 | |||
| 396 | .L_bn_sqr_words_tail: | ||
| 397 | mulx %g2,%g2,%o4 | ||
| 398 | dec %o2 | ||
| 399 | stuw %o4,[%o0] | ||
| 400 | srlx %o4,32,%o5 | ||
| 401 | brz,pt %o2,.L_bn_sqr_words_return | ||
| 402 | stuw %o5,[%o0+4] | ||
| 403 | |||
| 404 | lduw [%o1+4],%g2 | ||
| 405 | mulx %g2,%g2,%o4 | ||
| 406 | dec %o2 | ||
| 407 | stuw %o4,[%o0+8] | ||
| 408 | srlx %o4,32,%o5 | ||
| 409 | brz,pt %o2,.L_bn_sqr_words_return | ||
| 410 | stuw %o5,[%o0+12] | ||
| 411 | |||
| 412 | lduw [%o1+8],%g2 | ||
| 413 | mulx %g2,%g2,%o4 | ||
| 414 | srlx %o4,32,%o5 | ||
| 415 | stuw %o4,[%o0+16] | ||
| 416 | stuw %o5,[%o0+20] | ||
| 417 | retl | ||
| 418 | clr %o0 | ||
| 419 | |||
| 420 | .type bn_sqr_words,#function | ||
| 421 | .size bn_sqr_words,(.-bn_sqr_words) | ||
| 422 | |||
| 423 | .align 32 | ||
| 424 | .global bn_div_words | ||
| 425 | /* | ||
| 426 | * BN_ULONG bn_div_words(h,l,d) | ||
| 427 | * BN_ULONG h,l,d; | ||
| 428 | */ | ||
| 429 | bn_div_words: | ||
| 430 | sllx %o0,32,%o0 | ||
| 431 | or %o0,%o1,%o0 | ||
| 432 | udivx %o0,%o2,%o0 | ||
| 433 | retl | ||
| 434 | srl %o0,%g0,%o0 ! clruw %o0 | ||
| 435 | |||
| 436 | .type bn_div_words,#function | ||
| 437 | .size bn_div_words,(.-bn_div_words) | ||
| 438 | |||
| 439 | .align 32 | ||
| 440 | |||
| 441 | .global bn_add_words | ||
| 442 | /* | ||
| 443 | * BN_ULONG bn_add_words(rp,ap,bp,n) | ||
| 444 | * BN_ULONG *rp,*ap,*bp; | ||
| 445 | * int n; | ||
| 446 | */ | ||
| 447 | bn_add_words: | ||
| 448 | brgz,a %o3,.L_bn_add_words_proceed | ||
| 449 | lduw [%o1],%o4 | ||
| 450 | retl | ||
| 451 | clr %o0 | ||
| 452 | |||
| 453 | .L_bn_add_words_proceed: | ||
| 454 | andcc %o3,-4,%g0 | ||
| 455 | bz,pn %icc,.L_bn_add_words_tail | ||
| 456 | addcc %g0,0,%g0 ! clear carry flag | ||
| 457 | nop | ||
| 458 | |||
| 459 | .L_bn_add_words_loop: ! wow! 32 aligned! | ||
| 460 | dec 4,%o3 | ||
| 461 | lduw [%o2],%o5 | ||
| 462 | lduw [%o1+4],%g1 | ||
| 463 | lduw [%o2+4],%g2 | ||
| 464 | lduw [%o1+8],%g3 | ||
| 465 | lduw [%o2+8],%g4 | ||
| 466 | addccc %o5,%o4,%o5 | ||
| 467 | stuw %o5,[%o0] | ||
| 468 | |||
| 469 | lduw [%o1+12],%o4 | ||
| 470 | lduw [%o2+12],%o5 | ||
| 471 | inc 16,%o1 | ||
| 472 | addccc %g1,%g2,%g1 | ||
| 473 | stuw %g1,[%o0+4] | ||
| 474 | |||
| 475 | inc 16,%o2 | ||
| 476 | addccc %g3,%g4,%g3 | ||
| 477 | stuw %g3,[%o0+8] | ||
| 478 | |||
| 479 | inc 16,%o0 | ||
| 480 | addccc %o5,%o4,%o5 | ||
| 481 | stuw %o5,[%o0-4] | ||
| 482 | and %o3,-4,%g1 | ||
| 483 | brnz,a,pt %g1,.L_bn_add_words_loop | ||
| 484 | lduw [%o1],%o4 | ||
| 485 | |||
| 486 | brnz,a,pn %o3,.L_bn_add_words_tail | ||
| 487 | lduw [%o1],%o4 | ||
| 488 | .L_bn_add_words_return: | ||
| 489 | clr %o0 | ||
| 490 | retl | ||
| 491 | movcs %icc,1,%o0 | ||
| 492 | nop | ||
| 493 | |||
| 494 | .L_bn_add_words_tail: | ||
| 495 | lduw [%o2],%o5 | ||
| 496 | dec %o3 | ||
| 497 | addccc %o5,%o4,%o5 | ||
| 498 | brz,pt %o3,.L_bn_add_words_return | ||
| 499 | stuw %o5,[%o0] | ||
| 500 | |||
| 501 | lduw [%o1+4],%o4 | ||
| 502 | lduw [%o2+4],%o5 | ||
| 503 | dec %o3 | ||
| 504 | addccc %o5,%o4,%o5 | ||
| 505 | brz,pt %o3,.L_bn_add_words_return | ||
| 506 | stuw %o5,[%o0+4] | ||
| 507 | |||
| 508 | lduw [%o1+8],%o4 | ||
| 509 | lduw [%o2+8],%o5 | ||
| 510 | addccc %o5,%o4,%o5 | ||
| 511 | stuw %o5,[%o0+8] | ||
| 512 | clr %o0 | ||
| 513 | retl | ||
| 514 | movcs %icc,1,%o0 | ||
| 515 | |||
| 516 | .type bn_add_words,#function | ||
| 517 | .size bn_add_words,(.-bn_add_words) | ||
| 518 | |||
| 519 | .global bn_sub_words | ||
| 520 | /* | ||
| 521 | * BN_ULONG bn_sub_words(rp,ap,bp,n) | ||
| 522 | * BN_ULONG *rp,*ap,*bp; | ||
| 523 | * int n; | ||
| 524 | */ | ||
| 525 | bn_sub_words: | ||
| 526 | brgz,a %o3,.L_bn_sub_words_proceed | ||
| 527 | lduw [%o1],%o4 | ||
| 528 | retl | ||
| 529 | clr %o0 | ||
| 530 | |||
| 531 | .L_bn_sub_words_proceed: | ||
| 532 | andcc %o3,-4,%g0 | ||
| 533 | bz,pn %icc,.L_bn_sub_words_tail | ||
| 534 | addcc %g0,0,%g0 ! clear carry flag | ||
| 535 | nop | ||
| 536 | |||
| 537 | .L_bn_sub_words_loop: ! wow! 32 aligned! | ||
| 538 | dec 4,%o3 | ||
| 539 | lduw [%o2],%o5 | ||
| 540 | lduw [%o1+4],%g1 | ||
| 541 | lduw [%o2+4],%g2 | ||
| 542 | lduw [%o1+8],%g3 | ||
| 543 | lduw [%o2+8],%g4 | ||
| 544 | subccc %o4,%o5,%o5 | ||
| 545 | stuw %o5,[%o0] | ||
| 546 | |||
| 547 | lduw [%o1+12],%o4 | ||
| 548 | lduw [%o2+12],%o5 | ||
| 549 | inc 16,%o1 | ||
| 550 | subccc %g1,%g2,%g2 | ||
| 551 | stuw %g2,[%o0+4] | ||
| 552 | |||
| 553 | inc 16,%o2 | ||
| 554 | subccc %g3,%g4,%g4 | ||
| 555 | stuw %g4,[%o0+8] | ||
| 556 | |||
| 557 | inc 16,%o0 | ||
| 558 | subccc %o4,%o5,%o5 | ||
| 559 | stuw %o5,[%o0-4] | ||
| 560 | and %o3,-4,%g1 | ||
| 561 | brnz,a,pt %g1,.L_bn_sub_words_loop | ||
| 562 | lduw [%o1],%o4 | ||
| 563 | |||
| 564 | brnz,a,pn %o3,.L_bn_sub_words_tail | ||
| 565 | lduw [%o1],%o4 | ||
| 566 | .L_bn_sub_words_return: | ||
| 567 | clr %o0 | ||
| 568 | retl | ||
| 569 | movcs %icc,1,%o0 | ||
| 570 | nop | ||
| 571 | |||
| 572 | .L_bn_sub_words_tail: ! wow! 32 aligned! | ||
| 573 | lduw [%o2],%o5 | ||
| 574 | dec %o3 | ||
| 575 | subccc %o4,%o5,%o5 | ||
| 576 | brz,pt %o3,.L_bn_sub_words_return | ||
| 577 | stuw %o5,[%o0] | ||
| 578 | |||
| 579 | lduw [%o1+4],%o4 | ||
| 580 | lduw [%o2+4],%o5 | ||
| 581 | dec %o3 | ||
| 582 | subccc %o4,%o5,%o5 | ||
| 583 | brz,pt %o3,.L_bn_sub_words_return | ||
| 584 | stuw %o5,[%o0+4] | ||
| 585 | |||
| 586 | lduw [%o1+8],%o4 | ||
| 587 | lduw [%o2+8],%o5 | ||
| 588 | subccc %o4,%o5,%o5 | ||
| 589 | stuw %o5,[%o0+8] | ||
| 590 | clr %o0 | ||
| 591 | retl | ||
| 592 | movcs %icc,1,%o0 | ||
| 593 | |||
| 594 | .type bn_sub_words,#function | ||
| 595 | .size bn_sub_words,(.-bn_sub_words) | ||
| 596 | |||
| 597 | /* | ||
| 598 | * Code below depends on the fact that upper parts of the %l0-%l7 | ||
| 599 | * and %i0-%i7 are zeroed by kernel after context switch. In | ||
| 600 | * previous versions this comment stated that "the trouble is that | ||
| 601 | * it's not feasible to implement the mumbo-jumbo in less V9 | ||
| 602 | * instructions:-(" which apparently isn't true thanks to | ||
| 603 | * 'bcs,a %xcc,.+8; inc %rd' pair. But the performance improvement | ||
| 604 | * results not from the shorter code, but from elimination of | ||
| 605 | * multicycle none-pairable 'rd %y,%rd' instructions. | ||
| 606 | * | ||
| 607 | * Andy. | ||
| 608 | */ | ||
| 609 | |||
| 610 | #define FRAME_SIZE -96 | ||
| 611 | |||
| 612 | /* | ||
| 613 | * Here is register usage map for *all* routines below. | ||
| 614 | */ | ||
| 615 | #define t_1 %o0 | ||
| 616 | #define t_2 %o1 | ||
| 617 | #define c_12 %o2 | ||
| 618 | #define c_3 %o3 | ||
| 619 | |||
| 620 | #define ap(I) [%i1+4*I] | ||
| 621 | #define bp(I) [%i2+4*I] | ||
| 622 | #define rp(I) [%i0+4*I] | ||
| 623 | |||
| 624 | #define a_0 %l0 | ||
| 625 | #define a_1 %l1 | ||
| 626 | #define a_2 %l2 | ||
| 627 | #define a_3 %l3 | ||
| 628 | #define a_4 %l4 | ||
| 629 | #define a_5 %l5 | ||
| 630 | #define a_6 %l6 | ||
| 631 | #define a_7 %l7 | ||
| 632 | |||
| 633 | #define b_0 %i3 | ||
| 634 | #define b_1 %i4 | ||
| 635 | #define b_2 %i5 | ||
| 636 | #define b_3 %o4 | ||
| 637 | #define b_4 %o5 | ||
| 638 | #define b_5 %o7 | ||
| 639 | #define b_6 %g1 | ||
| 640 | #define b_7 %g4 | ||
| 641 | |||
| 642 | .align 32 | ||
| 643 | .global bn_mul_comba8 | ||
| 644 | /* | ||
| 645 | * void bn_mul_comba8(r,a,b) | ||
| 646 | * BN_ULONG *r,*a,*b; | ||
| 647 | */ | ||
| 648 | bn_mul_comba8: | ||
| 649 | save %sp,FRAME_SIZE,%sp | ||
| 650 | mov 1,t_2 | ||
| 651 | lduw ap(0),a_0 | ||
| 652 | sllx t_2,32,t_2 | ||
| 653 | lduw bp(0),b_0 != | ||
| 654 | lduw bp(1),b_1 | ||
| 655 | mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3); | ||
| 656 | srlx t_1,32,c_12 | ||
| 657 | stuw t_1,rp(0) !=!r[0]=c1; | ||
| 658 | |||
| 659 | lduw ap(1),a_1 | ||
| 660 | mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1); | ||
| 661 | addcc c_12,t_1,c_12 | ||
| 662 | clr c_3 != | ||
| 663 | bcs,a %xcc,.+8 | ||
| 664 | add c_3,t_2,c_3 | ||
| 665 | lduw ap(2),a_2 | ||
| 666 | mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1); | ||
| 667 | addcc c_12,t_1,t_1 | ||
| 668 | bcs,a %xcc,.+8 | ||
| 669 | add c_3,t_2,c_3 | ||
| 670 | srlx t_1,32,c_12 != | ||
| 671 | stuw t_1,rp(1) !r[1]=c2; | ||
| 672 | or c_12,c_3,c_12 | ||
| 673 | |||
| 674 | mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2); | ||
| 675 | addcc c_12,t_1,c_12 != | ||
| 676 | clr c_3 | ||
| 677 | bcs,a %xcc,.+8 | ||
| 678 | add c_3,t_2,c_3 | ||
| 679 | lduw bp(2),b_2 != | ||
| 680 | mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2); | ||
| 681 | addcc c_12,t_1,c_12 | ||
| 682 | bcs,a %xcc,.+8 | ||
| 683 | add c_3,t_2,c_3 != | ||
| 684 | lduw bp(3),b_3 | ||
| 685 | mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2); | ||
| 686 | addcc c_12,t_1,t_1 | ||
| 687 | bcs,a %xcc,.+8 != | ||
| 688 | add c_3,t_2,c_3 | ||
| 689 | srlx t_1,32,c_12 | ||
| 690 | stuw t_1,rp(2) !r[2]=c3; | ||
| 691 | or c_12,c_3,c_12 != | ||
| 692 | |||
| 693 | mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3); | ||
| 694 | addcc c_12,t_1,c_12 | ||
| 695 | clr c_3 | ||
| 696 | bcs,a %xcc,.+8 != | ||
| 697 | add c_3,t_2,c_3 | ||
| 698 | mulx a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3); | ||
| 699 | addcc c_12,t_1,c_12 | ||
| 700 | bcs,a %xcc,.+8 != | ||
| 701 | add c_3,t_2,c_3 | ||
| 702 | lduw ap(3),a_3 | ||
| 703 | mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3); | ||
| 704 | addcc c_12,t_1,c_12 != | ||
| 705 | bcs,a %xcc,.+8 | ||
| 706 | add c_3,t_2,c_3 | ||
| 707 | lduw ap(4),a_4 | ||
| 708 | mulx a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3);!= | ||
| 709 | addcc c_12,t_1,t_1 | ||
| 710 | bcs,a %xcc,.+8 | ||
| 711 | add c_3,t_2,c_3 | ||
| 712 | srlx t_1,32,c_12 != | ||
| 713 | stuw t_1,rp(3) !r[3]=c1; | ||
| 714 | or c_12,c_3,c_12 | ||
| 715 | |||
| 716 | mulx a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1); | ||
| 717 | addcc c_12,t_1,c_12 != | ||
| 718 | clr c_3 | ||
| 719 | bcs,a %xcc,.+8 | ||
| 720 | add c_3,t_2,c_3 | ||
| 721 | mulx a_3,b_1,t_1 !=!mul_add_c(a[3],b[1],c2,c3,c1); | ||
| 722 | addcc c_12,t_1,c_12 | ||
| 723 | bcs,a %xcc,.+8 | ||
| 724 | add c_3,t_2,c_3 | ||
| 725 | mulx a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1); | ||
| 726 | addcc c_12,t_1,c_12 | ||
| 727 | bcs,a %xcc,.+8 | ||
| 728 | add c_3,t_2,c_3 | ||
| 729 | lduw bp(4),b_4 != | ||
| 730 | mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1); | ||
| 731 | addcc c_12,t_1,c_12 | ||
| 732 | bcs,a %xcc,.+8 | ||
| 733 | add c_3,t_2,c_3 != | ||
| 734 | lduw bp(5),b_5 | ||
| 735 | mulx a_0,b_4,t_1 !mul_add_c(a[0],b[4],c2,c3,c1); | ||
| 736 | addcc c_12,t_1,t_1 | ||
| 737 | bcs,a %xcc,.+8 != | ||
| 738 | add c_3,t_2,c_3 | ||
| 739 | srlx t_1,32,c_12 | ||
| 740 | stuw t_1,rp(4) !r[4]=c2; | ||
| 741 | or c_12,c_3,c_12 != | ||
| 742 | |||
| 743 | mulx a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2); | ||
| 744 | addcc c_12,t_1,c_12 | ||
| 745 | clr c_3 | ||
| 746 | bcs,a %xcc,.+8 != | ||
| 747 | add c_3,t_2,c_3 | ||
| 748 | mulx a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2); | ||
| 749 | addcc c_12,t_1,c_12 | ||
| 750 | bcs,a %xcc,.+8 != | ||
| 751 | add c_3,t_2,c_3 | ||
| 752 | mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2); | ||
| 753 | addcc c_12,t_1,c_12 | ||
| 754 | bcs,a %xcc,.+8 != | ||
| 755 | add c_3,t_2,c_3 | ||
| 756 | mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2); | ||
| 757 | addcc c_12,t_1,c_12 | ||
| 758 | bcs,a %xcc,.+8 != | ||
| 759 | add c_3,t_2,c_3 | ||
| 760 | lduw ap(5),a_5 | ||
| 761 | mulx a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2); | ||
| 762 | addcc c_12,t_1,c_12 != | ||
| 763 | bcs,a %xcc,.+8 | ||
| 764 | add c_3,t_2,c_3 | ||
| 765 | lduw ap(6),a_6 | ||
| 766 | mulx a_5,b_0,t_1 !=!mul_add_c(a[5],b[0],c3,c1,c2); | ||
| 767 | addcc c_12,t_1,t_1 | ||
| 768 | bcs,a %xcc,.+8 | ||
| 769 | add c_3,t_2,c_3 | ||
| 770 | srlx t_1,32,c_12 != | ||
| 771 | stuw t_1,rp(5) !r[5]=c3; | ||
| 772 | or c_12,c_3,c_12 | ||
| 773 | |||
| 774 | mulx a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3); | ||
| 775 | addcc c_12,t_1,c_12 != | ||
| 776 | clr c_3 | ||
| 777 | bcs,a %xcc,.+8 | ||
| 778 | add c_3,t_2,c_3 | ||
| 779 | mulx a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3); | ||
| 780 | addcc c_12,t_1,c_12 | ||
| 781 | bcs,a %xcc,.+8 | ||
| 782 | add c_3,t_2,c_3 | ||
| 783 | mulx a_4,b_2,t_1 !=!mul_add_c(a[4],b[2],c1,c2,c3); | ||
| 784 | addcc c_12,t_1,c_12 | ||
| 785 | bcs,a %xcc,.+8 | ||
| 786 | add c_3,t_2,c_3 | ||
| 787 | mulx a_3,b_3,t_1 !=!mul_add_c(a[3],b[3],c1,c2,c3); | ||
| 788 | addcc c_12,t_1,c_12 | ||
| 789 | bcs,a %xcc,.+8 | ||
| 790 | add c_3,t_2,c_3 | ||
| 791 | mulx a_2,b_4,t_1 !=!mul_add_c(a[2],b[4],c1,c2,c3); | ||
| 792 | addcc c_12,t_1,c_12 | ||
| 793 | bcs,a %xcc,.+8 | ||
| 794 | add c_3,t_2,c_3 | ||
| 795 | lduw bp(6),b_6 != | ||
| 796 | mulx a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3); | ||
| 797 | addcc c_12,t_1,c_12 | ||
| 798 | bcs,a %xcc,.+8 | ||
| 799 | add c_3,t_2,c_3 != | ||
| 800 | lduw bp(7),b_7 | ||
| 801 | mulx a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3); | ||
| 802 | addcc c_12,t_1,t_1 | ||
| 803 | bcs,a %xcc,.+8 != | ||
| 804 | add c_3,t_2,c_3 | ||
| 805 | srlx t_1,32,c_12 | ||
| 806 | stuw t_1,rp(6) !r[6]=c1; | ||
| 807 | or c_12,c_3,c_12 != | ||
| 808 | |||
| 809 | mulx a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1); | ||
| 810 | addcc c_12,t_1,c_12 | ||
| 811 | clr c_3 | ||
| 812 | bcs,a %xcc,.+8 != | ||
| 813 | add c_3,t_2,c_3 | ||
| 814 | mulx a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1); | ||
| 815 | addcc c_12,t_1,c_12 | ||
| 816 | bcs,a %xcc,.+8 != | ||
| 817 | add c_3,t_2,c_3 | ||
| 818 | mulx a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1); | ||
| 819 | addcc c_12,t_1,c_12 | ||
| 820 | bcs,a %xcc,.+8 != | ||
| 821 | add c_3,t_2,c_3 | ||
| 822 | mulx a_3,b_4,t_1 !mul_add_c(a[3],b[4],c2,c3,c1); | ||
| 823 | addcc c_12,t_1,c_12 | ||
| 824 | bcs,a %xcc,.+8 != | ||
| 825 | add c_3,t_2,c_3 | ||
| 826 | mulx a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1); | ||
| 827 | addcc c_12,t_1,c_12 | ||
| 828 | bcs,a %xcc,.+8 != | ||
| 829 | add c_3,t_2,c_3 | ||
| 830 | mulx a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1); | ||
| 831 | addcc c_12,t_1,c_12 | ||
| 832 | bcs,a %xcc,.+8 != | ||
| 833 | add c_3,t_2,c_3 | ||
| 834 | lduw ap(7),a_7 | ||
| 835 | mulx a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1); | ||
| 836 | addcc c_12,t_1,c_12 | ||
| 837 | bcs,a %xcc,.+8 | ||
| 838 | add c_3,t_2,c_3 | ||
| 839 | mulx a_7,b_0,t_1 !=!mul_add_c(a[7],b[0],c2,c3,c1); | ||
| 840 | addcc c_12,t_1,t_1 | ||
| 841 | bcs,a %xcc,.+8 | ||
| 842 | add c_3,t_2,c_3 | ||
| 843 | srlx t_1,32,c_12 != | ||
| 844 | stuw t_1,rp(7) !r[7]=c2; | ||
| 845 | or c_12,c_3,c_12 | ||
| 846 | |||
| 847 | mulx a_7,b_1,t_1 !=!mul_add_c(a[7],b[1],c3,c1,c2); | ||
| 848 | addcc c_12,t_1,c_12 | ||
| 849 | clr c_3 | ||
| 850 | bcs,a %xcc,.+8 | ||
| 851 | add c_3,t_2,c_3 != | ||
| 852 | mulx a_6,b_2,t_1 !mul_add_c(a[6],b[2],c3,c1,c2); | ||
| 853 | addcc c_12,t_1,c_12 | ||
| 854 | bcs,a %xcc,.+8 | ||
| 855 | add c_3,t_2,c_3 != | ||
| 856 | mulx a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2); | ||
| 857 | addcc c_12,t_1,c_12 | ||
| 858 | bcs,a %xcc,.+8 | ||
| 859 | add c_3,t_2,c_3 != | ||
| 860 | mulx a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2); | ||
| 861 | addcc c_12,t_1,c_12 | ||
| 862 | bcs,a %xcc,.+8 | ||
| 863 | add c_3,t_2,c_3 != | ||
| 864 | mulx a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2); | ||
| 865 | addcc c_12,t_1,c_12 | ||
| 866 | bcs,a %xcc,.+8 | ||
| 867 | add c_3,t_2,c_3 != | ||
| 868 | mulx a_2,b_6,t_1 !mul_add_c(a[2],b[6],c3,c1,c2); | ||
| 869 | addcc c_12,t_1,c_12 | ||
| 870 | bcs,a %xcc,.+8 | ||
| 871 | add c_3,t_2,c_3 != | ||
| 872 | mulx a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2); | ||
| 873 | addcc c_12,t_1,t_1 | ||
| 874 | bcs,a %xcc,.+8 | ||
| 875 | add c_3,t_2,c_3 != | ||
| 876 | srlx t_1,32,c_12 | ||
| 877 | stuw t_1,rp(8) !r[8]=c3; | ||
| 878 | or c_12,c_3,c_12 | ||
| 879 | |||
| 880 | mulx a_2,b_7,t_1 !=!mul_add_c(a[2],b[7],c1,c2,c3); | ||
| 881 | addcc c_12,t_1,c_12 | ||
| 882 | clr c_3 | ||
| 883 | bcs,a %xcc,.+8 | ||
| 884 | add c_3,t_2,c_3 != | ||
| 885 | mulx a_3,b_6,t_1 !mul_add_c(a[3],b[6],c1,c2,c3); | ||
| 886 | addcc c_12,t_1,c_12 | ||
| 887 | bcs,a %xcc,.+8 != | ||
| 888 | add c_3,t_2,c_3 | ||
| 889 | mulx a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3); | ||
| 890 | addcc c_12,t_1,c_12 | ||
| 891 | bcs,a %xcc,.+8 != | ||
| 892 | add c_3,t_2,c_3 | ||
| 893 | mulx a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3); | ||
| 894 | addcc c_12,t_1,c_12 | ||
| 895 | bcs,a %xcc,.+8 != | ||
| 896 | add c_3,t_2,c_3 | ||
| 897 | mulx a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3); | ||
| 898 | addcc c_12,t_1,c_12 | ||
| 899 | bcs,a %xcc,.+8 != | ||
| 900 | add c_3,t_2,c_3 | ||
| 901 | mulx a_7,b_2,t_1 !mul_add_c(a[7],b[2],c1,c2,c3); | ||
| 902 | addcc c_12,t_1,t_1 | ||
| 903 | bcs,a %xcc,.+8 != | ||
| 904 | add c_3,t_2,c_3 | ||
| 905 | srlx t_1,32,c_12 | ||
| 906 | stuw t_1,rp(9) !r[9]=c1; | ||
| 907 | or c_12,c_3,c_12 != | ||
| 908 | |||
| 909 | mulx a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1); | ||
| 910 | addcc c_12,t_1,c_12 | ||
| 911 | clr c_3 | ||
| 912 | bcs,a %xcc,.+8 != | ||
| 913 | add c_3,t_2,c_3 | ||
| 914 | mulx a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1); | ||
| 915 | addcc c_12,t_1,c_12 | ||
| 916 | bcs,a %xcc,.+8 != | ||
| 917 | add c_3,t_2,c_3 | ||
| 918 | mulx a_5,b_5,t_1 !mul_add_c(a[5],b[5],c2,c3,c1); | ||
| 919 | addcc c_12,t_1,c_12 | ||
| 920 | bcs,a %xcc,.+8 != | ||
| 921 | add c_3,t_2,c_3 | ||
| 922 | mulx a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1); | ||
| 923 | addcc c_12,t_1,c_12 | ||
| 924 | bcs,a %xcc,.+8 != | ||
| 925 | add c_3,t_2,c_3 | ||
| 926 | mulx a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1); | ||
| 927 | addcc c_12,t_1,t_1 | ||
| 928 | bcs,a %xcc,.+8 != | ||
| 929 | add c_3,t_2,c_3 | ||
| 930 | srlx t_1,32,c_12 | ||
| 931 | stuw t_1,rp(10) !r[10]=c2; | ||
| 932 | or c_12,c_3,c_12 != | ||
| 933 | |||
| 934 | mulx a_4,b_7,t_1 !mul_add_c(a[4],b[7],c3,c1,c2); | ||
| 935 | addcc c_12,t_1,c_12 | ||
| 936 | clr c_3 | ||
| 937 | bcs,a %xcc,.+8 != | ||
| 938 | add c_3,t_2,c_3 | ||
| 939 | mulx a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2); | ||
| 940 | addcc c_12,t_1,c_12 | ||
| 941 | bcs,a %xcc,.+8 != | ||
| 942 | add c_3,t_2,c_3 | ||
| 943 | mulx a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2); | ||
| 944 | addcc c_12,t_1,c_12 | ||
| 945 | bcs,a %xcc,.+8 != | ||
| 946 | add c_3,t_2,c_3 | ||
| 947 | mulx a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2); | ||
| 948 | addcc c_12,t_1,t_1 | ||
| 949 | bcs,a %xcc,.+8 != | ||
| 950 | add c_3,t_2,c_3 | ||
| 951 | srlx t_1,32,c_12 | ||
| 952 | stuw t_1,rp(11) !r[11]=c3; | ||
| 953 | or c_12,c_3,c_12 != | ||
| 954 | |||
| 955 | mulx a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3); | ||
| 956 | addcc c_12,t_1,c_12 | ||
| 957 | clr c_3 | ||
| 958 | bcs,a %xcc,.+8 != | ||
| 959 | add c_3,t_2,c_3 | ||
| 960 | mulx a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3); | ||
| 961 | addcc c_12,t_1,c_12 | ||
| 962 | bcs,a %xcc,.+8 != | ||
| 963 | add c_3,t_2,c_3 | ||
| 964 | mulx a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3); | ||
| 965 | addcc c_12,t_1,t_1 | ||
| 966 | bcs,a %xcc,.+8 != | ||
| 967 | add c_3,t_2,c_3 | ||
| 968 | srlx t_1,32,c_12 | ||
| 969 | stuw t_1,rp(12) !r[12]=c1; | ||
| 970 | or c_12,c_3,c_12 != | ||
| 971 | |||
| 972 | mulx a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1); | ||
| 973 | addcc c_12,t_1,c_12 | ||
| 974 | clr c_3 | ||
| 975 | bcs,a %xcc,.+8 != | ||
| 976 | add c_3,t_2,c_3 | ||
| 977 | mulx a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1); | ||
| 978 | addcc c_12,t_1,t_1 | ||
| 979 | bcs,a %xcc,.+8 != | ||
| 980 | add c_3,t_2,c_3 | ||
| 981 | srlx t_1,32,c_12 | ||
| 982 | st t_1,rp(13) !r[13]=c2; | ||
| 983 | or c_12,c_3,c_12 != | ||
| 984 | |||
| 985 | mulx a_7,b_7,t_1 !mul_add_c(a[7],b[7],c3,c1,c2); | ||
| 986 | addcc c_12,t_1,t_1 | ||
| 987 | srlx t_1,32,c_12 != | ||
| 988 | stuw t_1,rp(14) !r[14]=c3; | ||
| 989 | stuw c_12,rp(15) !r[15]=c1; | ||
| 990 | |||
| 991 | ret | ||
| 992 | restore %g0,%g0,%o0 != | ||
| 993 | |||
| 994 | .type bn_mul_comba8,#function | ||
| 995 | .size bn_mul_comba8,(.-bn_mul_comba8) | ||
| 996 | |||
| 997 | .align 32 | ||
| 998 | |||
| 999 | .global bn_mul_comba4 | ||
| 1000 | /* | ||
| 1001 | * void bn_mul_comba4(r,a,b) | ||
| 1002 | * BN_ULONG *r,*a,*b; | ||
| 1003 | */ | ||
| 1004 | bn_mul_comba4: | ||
| 1005 | save %sp,FRAME_SIZE,%sp | ||
| 1006 | lduw ap(0),a_0 | ||
| 1007 | mov 1,t_2 | ||
| 1008 | lduw bp(0),b_0 | ||
| 1009 | sllx t_2,32,t_2 != | ||
| 1010 | lduw bp(1),b_1 | ||
| 1011 | mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3); | ||
| 1012 | srlx t_1,32,c_12 | ||
| 1013 | stuw t_1,rp(0) !=!r[0]=c1; | ||
| 1014 | |||
| 1015 | lduw ap(1),a_1 | ||
| 1016 | mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1); | ||
| 1017 | addcc c_12,t_1,c_12 | ||
| 1018 | clr c_3 != | ||
| 1019 | bcs,a %xcc,.+8 | ||
| 1020 | add c_3,t_2,c_3 | ||
| 1021 | lduw ap(2),a_2 | ||
| 1022 | mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1); | ||
| 1023 | addcc c_12,t_1,t_1 | ||
| 1024 | bcs,a %xcc,.+8 | ||
| 1025 | add c_3,t_2,c_3 | ||
| 1026 | srlx t_1,32,c_12 != | ||
| 1027 | stuw t_1,rp(1) !r[1]=c2; | ||
| 1028 | or c_12,c_3,c_12 | ||
| 1029 | |||
| 1030 | mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2); | ||
| 1031 | addcc c_12,t_1,c_12 != | ||
| 1032 | clr c_3 | ||
| 1033 | bcs,a %xcc,.+8 | ||
| 1034 | add c_3,t_2,c_3 | ||
| 1035 | lduw bp(2),b_2 != | ||
| 1036 | mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2); | ||
| 1037 | addcc c_12,t_1,c_12 | ||
| 1038 | bcs,a %xcc,.+8 | ||
| 1039 | add c_3,t_2,c_3 != | ||
| 1040 | lduw bp(3),b_3 | ||
| 1041 | mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2); | ||
| 1042 | addcc c_12,t_1,t_1 | ||
| 1043 | bcs,a %xcc,.+8 != | ||
| 1044 | add c_3,t_2,c_3 | ||
| 1045 | srlx t_1,32,c_12 | ||
| 1046 | stuw t_1,rp(2) !r[2]=c3; | ||
| 1047 | or c_12,c_3,c_12 != | ||
| 1048 | |||
| 1049 | mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3); | ||
| 1050 | addcc c_12,t_1,c_12 | ||
| 1051 | clr c_3 | ||
| 1052 | bcs,a %xcc,.+8 != | ||
| 1053 | add c_3,t_2,c_3 | ||
| 1054 | mulx a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3); | ||
| 1055 | addcc c_12,t_1,c_12 | ||
| 1056 | bcs,a %xcc,.+8 != | ||
| 1057 | add c_3,t_2,c_3 | ||
| 1058 | lduw ap(3),a_3 | ||
| 1059 | mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3); | ||
| 1060 | addcc c_12,t_1,c_12 != | ||
| 1061 | bcs,a %xcc,.+8 | ||
| 1062 | add c_3,t_2,c_3 | ||
| 1063 | mulx a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!= | ||
| 1064 | addcc c_12,t_1,t_1 != | ||
| 1065 | bcs,a %xcc,.+8 | ||
| 1066 | add c_3,t_2,c_3 | ||
| 1067 | srlx t_1,32,c_12 | ||
| 1068 | stuw t_1,rp(3) !=!r[3]=c1; | ||
| 1069 | or c_12,c_3,c_12 | ||
| 1070 | |||
| 1071 | mulx a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1); | ||
| 1072 | addcc c_12,t_1,c_12 | ||
| 1073 | clr c_3 != | ||
| 1074 | bcs,a %xcc,.+8 | ||
| 1075 | add c_3,t_2,c_3 | ||
| 1076 | mulx a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1); | ||
| 1077 | addcc c_12,t_1,c_12 != | ||
| 1078 | bcs,a %xcc,.+8 | ||
| 1079 | add c_3,t_2,c_3 | ||
| 1080 | mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1); | ||
| 1081 | addcc c_12,t_1,t_1 != | ||
| 1082 | bcs,a %xcc,.+8 | ||
| 1083 | add c_3,t_2,c_3 | ||
| 1084 | srlx t_1,32,c_12 | ||
| 1085 | stuw t_1,rp(4) !=!r[4]=c2; | ||
| 1086 | or c_12,c_3,c_12 | ||
| 1087 | |||
| 1088 | mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2); | ||
| 1089 | addcc c_12,t_1,c_12 | ||
| 1090 | clr c_3 != | ||
| 1091 | bcs,a %xcc,.+8 | ||
| 1092 | add c_3,t_2,c_3 | ||
| 1093 | mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2); | ||
| 1094 | addcc c_12,t_1,t_1 != | ||
| 1095 | bcs,a %xcc,.+8 | ||
| 1096 | add c_3,t_2,c_3 | ||
| 1097 | srlx t_1,32,c_12 | ||
| 1098 | stuw t_1,rp(5) !=!r[5]=c3; | ||
| 1099 | or c_12,c_3,c_12 | ||
| 1100 | |||
| 1101 | mulx a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3); | ||
| 1102 | addcc c_12,t_1,t_1 | ||
| 1103 | srlx t_1,32,c_12 != | ||
| 1104 | stuw t_1,rp(6) !r[6]=c1; | ||
| 1105 | stuw c_12,rp(7) !r[7]=c2; | ||
| 1106 | |||
| 1107 | ret | ||
| 1108 | restore %g0,%g0,%o0 | ||
| 1109 | |||
| 1110 | .type bn_mul_comba4,#function | ||
| 1111 | .size bn_mul_comba4,(.-bn_mul_comba4) | ||
| 1112 | |||
| 1113 | .align 32 | ||
| 1114 | |||
| 1115 | .global bn_sqr_comba8 | ||
| 1116 | bn_sqr_comba8: | ||
| 1117 | save %sp,FRAME_SIZE,%sp | ||
| 1118 | mov 1,t_2 | ||
| 1119 | lduw ap(0),a_0 | ||
| 1120 | sllx t_2,32,t_2 | ||
| 1121 | lduw ap(1),a_1 | ||
| 1122 | mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3); | ||
| 1123 | srlx t_1,32,c_12 | ||
| 1124 | stuw t_1,rp(0) !r[0]=c1; | ||
| 1125 | |||
| 1126 | lduw ap(2),a_2 | ||
| 1127 | mulx a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1); | ||
| 1128 | addcc c_12,t_1,c_12 | ||
| 1129 | clr c_3 | ||
| 1130 | bcs,a %xcc,.+8 | ||
| 1131 | add c_3,t_2,c_3 | ||
| 1132 | addcc c_12,t_1,t_1 | ||
| 1133 | bcs,a %xcc,.+8 | ||
| 1134 | add c_3,t_2,c_3 | ||
| 1135 | srlx t_1,32,c_12 | ||
| 1136 | stuw t_1,rp(1) !r[1]=c2; | ||
| 1137 | or c_12,c_3,c_12 | ||
| 1138 | |||
| 1139 | mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2); | ||
| 1140 | addcc c_12,t_1,c_12 | ||
| 1141 | clr c_3 | ||
| 1142 | bcs,a %xcc,.+8 | ||
| 1143 | add c_3,t_2,c_3 | ||
| 1144 | addcc c_12,t_1,c_12 | ||
| 1145 | bcs,a %xcc,.+8 | ||
| 1146 | add c_3,t_2,c_3 | ||
| 1147 | lduw ap(3),a_3 | ||
| 1148 | mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2); | ||
| 1149 | addcc c_12,t_1,t_1 | ||
| 1150 | bcs,a %xcc,.+8 | ||
| 1151 | add c_3,t_2,c_3 | ||
| 1152 | srlx t_1,32,c_12 | ||
| 1153 | stuw t_1,rp(2) !r[2]=c3; | ||
| 1154 | or c_12,c_3,c_12 | ||
| 1155 | |||
| 1156 | mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3); | ||
| 1157 | addcc c_12,t_1,c_12 | ||
| 1158 | clr c_3 | ||
| 1159 | bcs,a %xcc,.+8 | ||
| 1160 | add c_3,t_2,c_3 | ||
| 1161 | addcc c_12,t_1,c_12 | ||
| 1162 | bcs,a %xcc,.+8 | ||
| 1163 | add c_3,t_2,c_3 | ||
| 1164 | lduw ap(4),a_4 | ||
| 1165 | mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3); | ||
| 1166 | addcc c_12,t_1,c_12 | ||
| 1167 | bcs,a %xcc,.+8 | ||
| 1168 | add c_3,t_2,c_3 | ||
| 1169 | addcc c_12,t_1,t_1 | ||
| 1170 | bcs,a %xcc,.+8 | ||
| 1171 | add c_3,t_2,c_3 | ||
| 1172 | srlx t_1,32,c_12 | ||
| 1173 | st t_1,rp(3) !r[3]=c1; | ||
| 1174 | or c_12,c_3,c_12 | ||
| 1175 | |||
| 1176 | mulx a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1); | ||
| 1177 | addcc c_12,t_1,c_12 | ||
| 1178 | clr c_3 | ||
| 1179 | bcs,a %xcc,.+8 | ||
| 1180 | add c_3,t_2,c_3 | ||
| 1181 | addcc c_12,t_1,c_12 | ||
| 1182 | bcs,a %xcc,.+8 | ||
| 1183 | add c_3,t_2,c_3 | ||
| 1184 | mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1); | ||
| 1185 | addcc c_12,t_1,c_12 | ||
| 1186 | bcs,a %xcc,.+8 | ||
| 1187 | add c_3,t_2,c_3 | ||
| 1188 | addcc c_12,t_1,c_12 | ||
| 1189 | bcs,a %xcc,.+8 | ||
| 1190 | add c_3,t_2,c_3 | ||
| 1191 | lduw ap(5),a_5 | ||
| 1192 | mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1); | ||
| 1193 | addcc c_12,t_1,t_1 | ||
| 1194 | bcs,a %xcc,.+8 | ||
| 1195 | add c_3,t_2,c_3 | ||
| 1196 | srlx t_1,32,c_12 | ||
| 1197 | stuw t_1,rp(4) !r[4]=c2; | ||
| 1198 | or c_12,c_3,c_12 | ||
| 1199 | |||
| 1200 | mulx a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2); | ||
| 1201 | addcc c_12,t_1,c_12 | ||
| 1202 | clr c_3 | ||
| 1203 | bcs,a %xcc,.+8 | ||
| 1204 | add c_3,t_2,c_3 | ||
| 1205 | addcc c_12,t_1,c_12 | ||
| 1206 | bcs,a %xcc,.+8 | ||
| 1207 | add c_3,t_2,c_3 | ||
| 1208 | mulx a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2); | ||
| 1209 | addcc c_12,t_1,c_12 | ||
| 1210 | bcs,a %xcc,.+8 | ||
| 1211 | add c_3,t_2,c_3 | ||
| 1212 | addcc c_12,t_1,c_12 | ||
| 1213 | bcs,a %xcc,.+8 | ||
| 1214 | add c_3,t_2,c_3 | ||
| 1215 | lduw ap(6),a_6 | ||
| 1216 | mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2); | ||
| 1217 | addcc c_12,t_1,c_12 | ||
| 1218 | bcs,a %xcc,.+8 | ||
| 1219 | add c_3,t_2,c_3 | ||
| 1220 | addcc c_12,t_1,t_1 | ||
| 1221 | bcs,a %xcc,.+8 | ||
| 1222 | add c_3,t_2,c_3 | ||
| 1223 | srlx t_1,32,c_12 | ||
| 1224 | stuw t_1,rp(5) !r[5]=c3; | ||
| 1225 | or c_12,c_3,c_12 | ||
| 1226 | |||
| 1227 | mulx a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3); | ||
| 1228 | addcc c_12,t_1,c_12 | ||
| 1229 | clr c_3 | ||
| 1230 | bcs,a %xcc,.+8 | ||
| 1231 | add c_3,t_2,c_3 | ||
| 1232 | addcc c_12,t_1,c_12 | ||
| 1233 | bcs,a %xcc,.+8 | ||
| 1234 | add c_3,t_2,c_3 | ||
| 1235 | mulx a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3); | ||
| 1236 | addcc c_12,t_1,c_12 | ||
| 1237 | bcs,a %xcc,.+8 | ||
| 1238 | add c_3,t_2,c_3 | ||
| 1239 | addcc c_12,t_1,c_12 | ||
| 1240 | bcs,a %xcc,.+8 | ||
| 1241 | add c_3,t_2,c_3 | ||
| 1242 | mulx a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3); | ||
| 1243 | addcc c_12,t_1,c_12 | ||
| 1244 | bcs,a %xcc,.+8 | ||
| 1245 | add c_3,t_2,c_3 | ||
| 1246 | addcc c_12,t_1,c_12 | ||
| 1247 | bcs,a %xcc,.+8 | ||
| 1248 | add c_3,t_2,c_3 | ||
| 1249 | lduw ap(7),a_7 | ||
| 1250 | mulx a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3); | ||
| 1251 | addcc c_12,t_1,t_1 | ||
| 1252 | bcs,a %xcc,.+8 | ||
| 1253 | add c_3,t_2,c_3 | ||
| 1254 | srlx t_1,32,c_12 | ||
| 1255 | stuw t_1,rp(6) !r[6]=c1; | ||
| 1256 | or c_12,c_3,c_12 | ||
| 1257 | |||
| 1258 | mulx a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1); | ||
| 1259 | addcc c_12,t_1,c_12 | ||
| 1260 | clr c_3 | ||
| 1261 | bcs,a %xcc,.+8 | ||
| 1262 | add c_3,t_2,c_3 | ||
| 1263 | addcc c_12,t_1,c_12 | ||
| 1264 | bcs,a %xcc,.+8 | ||
| 1265 | add c_3,t_2,c_3 | ||
| 1266 | mulx a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1); | ||
| 1267 | addcc c_12,t_1,c_12 | ||
| 1268 | bcs,a %xcc,.+8 | ||
| 1269 | add c_3,t_2,c_3 | ||
| 1270 | addcc c_12,t_1,c_12 | ||
| 1271 | bcs,a %xcc,.+8 | ||
| 1272 | add c_3,t_2,c_3 | ||
| 1273 | mulx a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1); | ||
| 1274 | addcc c_12,t_1,c_12 | ||
| 1275 | bcs,a %xcc,.+8 | ||
| 1276 | add c_3,t_2,c_3 | ||
| 1277 | addcc c_12,t_1,c_12 | ||
| 1278 | bcs,a %xcc,.+8 | ||
| 1279 | add c_3,t_2,c_3 | ||
| 1280 | mulx a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1); | ||
| 1281 | addcc c_12,t_1,c_12 | ||
| 1282 | bcs,a %xcc,.+8 | ||
| 1283 | add c_3,t_2,c_3 | ||
| 1284 | addcc c_12,t_1,t_1 | ||
| 1285 | bcs,a %xcc,.+8 | ||
| 1286 | add c_3,t_2,c_3 | ||
| 1287 | srlx t_1,32,c_12 | ||
| 1288 | stuw t_1,rp(7) !r[7]=c2; | ||
| 1289 | or c_12,c_3,c_12 | ||
| 1290 | |||
| 1291 | mulx a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2); | ||
| 1292 | addcc c_12,t_1,c_12 | ||
| 1293 | clr c_3 | ||
| 1294 | bcs,a %xcc,.+8 | ||
| 1295 | add c_3,t_2,c_3 | ||
| 1296 | addcc c_12,t_1,c_12 | ||
| 1297 | bcs,a %xcc,.+8 | ||
| 1298 | add c_3,t_2,c_3 | ||
| 1299 | mulx a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2); | ||
| 1300 | addcc c_12,t_1,c_12 | ||
| 1301 | bcs,a %xcc,.+8 | ||
| 1302 | add c_3,t_2,c_3 | ||
| 1303 | addcc c_12,t_1,c_12 | ||
| 1304 | bcs,a %xcc,.+8 | ||
| 1305 | add c_3,t_2,c_3 | ||
| 1306 | mulx a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2); | ||
| 1307 | addcc c_12,t_1,c_12 | ||
| 1308 | bcs,a %xcc,.+8 | ||
| 1309 | add c_3,t_2,c_3 | ||
| 1310 | addcc c_12,t_1,c_12 | ||
| 1311 | bcs,a %xcc,.+8 | ||
| 1312 | add c_3,t_2,c_3 | ||
| 1313 | mulx a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2); | ||
| 1314 | addcc c_12,t_1,t_1 | ||
| 1315 | bcs,a %xcc,.+8 | ||
| 1316 | add c_3,t_2,c_3 | ||
| 1317 | srlx t_1,32,c_12 | ||
| 1318 | stuw t_1,rp(8) !r[8]=c3; | ||
| 1319 | or c_12,c_3,c_12 | ||
| 1320 | |||
| 1321 | mulx a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3); | ||
| 1322 | addcc c_12,t_1,c_12 | ||
| 1323 | clr c_3 | ||
| 1324 | bcs,a %xcc,.+8 | ||
| 1325 | add c_3,t_2,c_3 | ||
| 1326 | addcc c_12,t_1,c_12 | ||
| 1327 | bcs,a %xcc,.+8 | ||
| 1328 | add c_3,t_2,c_3 | ||
| 1329 | mulx a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3); | ||
| 1330 | addcc c_12,t_1,c_12 | ||
| 1331 | bcs,a %xcc,.+8 | ||
| 1332 | add c_3,t_2,c_3 | ||
| 1333 | addcc c_12,t_1,c_12 | ||
| 1334 | bcs,a %xcc,.+8 | ||
| 1335 | add c_3,t_2,c_3 | ||
| 1336 | mulx a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3); | ||
| 1337 | addcc c_12,t_1,c_12 | ||
| 1338 | bcs,a %xcc,.+8 | ||
| 1339 | add c_3,t_2,c_3 | ||
| 1340 | addcc c_12,t_1,t_1 | ||
| 1341 | bcs,a %xcc,.+8 | ||
| 1342 | add c_3,t_2,c_3 | ||
| 1343 | srlx t_1,32,c_12 | ||
| 1344 | stuw t_1,rp(9) !r[9]=c1; | ||
| 1345 | or c_12,c_3,c_12 | ||
| 1346 | |||
| 1347 | mulx a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1); | ||
| 1348 | addcc c_12,t_1,c_12 | ||
| 1349 | clr c_3 | ||
| 1350 | bcs,a %xcc,.+8 | ||
| 1351 | add c_3,t_2,c_3 | ||
| 1352 | addcc c_12,t_1,c_12 | ||
| 1353 | bcs,a %xcc,.+8 | ||
| 1354 | add c_3,t_2,c_3 | ||
| 1355 | mulx a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1); | ||
| 1356 | addcc c_12,t_1,c_12 | ||
| 1357 | bcs,a %xcc,.+8 | ||
| 1358 | add c_3,t_2,c_3 | ||
| 1359 | addcc c_12,t_1,c_12 | ||
| 1360 | bcs,a %xcc,.+8 | ||
| 1361 | add c_3,t_2,c_3 | ||
| 1362 | mulx a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1); | ||
| 1363 | addcc c_12,t_1,t_1 | ||
| 1364 | bcs,a %xcc,.+8 | ||
| 1365 | add c_3,t_2,c_3 | ||
| 1366 | srlx t_1,32,c_12 | ||
| 1367 | stuw t_1,rp(10) !r[10]=c2; | ||
| 1368 | or c_12,c_3,c_12 | ||
| 1369 | |||
| 1370 | mulx a_4,a_7,t_1 !sqr_add_c2(a,7,4,c3,c1,c2); | ||
| 1371 | addcc c_12,t_1,c_12 | ||
| 1372 | clr c_3 | ||
| 1373 | bcs,a %xcc,.+8 | ||
| 1374 | add c_3,t_2,c_3 | ||
| 1375 | addcc c_12,t_1,c_12 | ||
| 1376 | bcs,a %xcc,.+8 | ||
| 1377 | add c_3,t_2,c_3 | ||
| 1378 | mulx a_5,a_6,t_1 !sqr_add_c2(a,6,5,c3,c1,c2); | ||
| 1379 | addcc c_12,t_1,c_12 | ||
| 1380 | bcs,a %xcc,.+8 | ||
| 1381 | add c_3,t_2,c_3 | ||
| 1382 | addcc c_12,t_1,t_1 | ||
| 1383 | bcs,a %xcc,.+8 | ||
| 1384 | add c_3,t_2,c_3 | ||
| 1385 | srlx t_1,32,c_12 | ||
| 1386 | stuw t_1,rp(11) !r[11]=c3; | ||
| 1387 | or c_12,c_3,c_12 | ||
| 1388 | |||
| 1389 | mulx a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3); | ||
| 1390 | addcc c_12,t_1,c_12 | ||
| 1391 | clr c_3 | ||
| 1392 | bcs,a %xcc,.+8 | ||
| 1393 | add c_3,t_2,c_3 | ||
| 1394 | addcc c_12,t_1,c_12 | ||
| 1395 | bcs,a %xcc,.+8 | ||
| 1396 | add c_3,t_2,c_3 | ||
| 1397 | mulx a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3); | ||
| 1398 | addcc c_12,t_1,t_1 | ||
| 1399 | bcs,a %xcc,.+8 | ||
| 1400 | add c_3,t_2,c_3 | ||
| 1401 | srlx t_1,32,c_12 | ||
| 1402 | stuw t_1,rp(12) !r[12]=c1; | ||
| 1403 | or c_12,c_3,c_12 | ||
| 1404 | |||
| 1405 | mulx a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1); | ||
| 1406 | addcc c_12,t_1,c_12 | ||
| 1407 | clr c_3 | ||
| 1408 | bcs,a %xcc,.+8 | ||
| 1409 | add c_3,t_2,c_3 | ||
| 1410 | addcc c_12,t_1,t_1 | ||
| 1411 | bcs,a %xcc,.+8 | ||
| 1412 | add c_3,t_2,c_3 | ||
| 1413 | srlx t_1,32,c_12 | ||
| 1414 | stuw t_1,rp(13) !r[13]=c2; | ||
| 1415 | or c_12,c_3,c_12 | ||
| 1416 | |||
| 1417 | mulx a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2); | ||
| 1418 | addcc c_12,t_1,t_1 | ||
| 1419 | srlx t_1,32,c_12 | ||
| 1420 | stuw t_1,rp(14) !r[14]=c3; | ||
| 1421 | stuw c_12,rp(15) !r[15]=c1; | ||
| 1422 | |||
| 1423 | ret | ||
| 1424 | restore %g0,%g0,%o0 | ||
| 1425 | |||
| 1426 | .type bn_sqr_comba8,#function | ||
| 1427 | .size bn_sqr_comba8,(.-bn_sqr_comba8) | ||
| 1428 | |||
| 1429 | .align 32 | ||
| 1430 | |||
| 1431 | .global bn_sqr_comba4 | ||
| 1432 | /* | ||
| 1433 | * void bn_sqr_comba4(r,a) | ||
| 1434 | * BN_ULONG *r,*a; | ||
| 1435 | */ | ||
| 1436 | bn_sqr_comba4: | ||
| 1437 | save %sp,FRAME_SIZE,%sp | ||
| 1438 | mov 1,t_2 | ||
| 1439 | lduw ap(0),a_0 | ||
| 1440 | sllx t_2,32,t_2 | ||
| 1441 | lduw ap(1),a_1 | ||
| 1442 | mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3); | ||
| 1443 | srlx t_1,32,c_12 | ||
| 1444 | stuw t_1,rp(0) !r[0]=c1; | ||
| 1445 | |||
| 1446 | lduw ap(2),a_2 | ||
| 1447 | mulx a_0,a_1,t_1 !sqr_add_c2(a,1,0,c2,c3,c1); | ||
| 1448 | addcc c_12,t_1,c_12 | ||
| 1449 | clr c_3 | ||
| 1450 | bcs,a %xcc,.+8 | ||
| 1451 | add c_3,t_2,c_3 | ||
| 1452 | addcc c_12,t_1,t_1 | ||
| 1453 | bcs,a %xcc,.+8 | ||
| 1454 | add c_3,t_2,c_3 | ||
| 1455 | srlx t_1,32,c_12 | ||
| 1456 | stuw t_1,rp(1) !r[1]=c2; | ||
| 1457 | or c_12,c_3,c_12 | ||
| 1458 | |||
| 1459 | mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2); | ||
| 1460 | addcc c_12,t_1,c_12 | ||
| 1461 | clr c_3 | ||
| 1462 | bcs,a %xcc,.+8 | ||
| 1463 | add c_3,t_2,c_3 | ||
| 1464 | addcc c_12,t_1,c_12 | ||
| 1465 | bcs,a %xcc,.+8 | ||
| 1466 | add c_3,t_2,c_3 | ||
| 1467 | lduw ap(3),a_3 | ||
| 1468 | mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2); | ||
| 1469 | addcc c_12,t_1,t_1 | ||
| 1470 | bcs,a %xcc,.+8 | ||
| 1471 | add c_3,t_2,c_3 | ||
| 1472 | srlx t_1,32,c_12 | ||
| 1473 | stuw t_1,rp(2) !r[2]=c3; | ||
| 1474 | or c_12,c_3,c_12 | ||
| 1475 | |||
| 1476 | mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3); | ||
| 1477 | addcc c_12,t_1,c_12 | ||
| 1478 | clr c_3 | ||
| 1479 | bcs,a %xcc,.+8 | ||
| 1480 | add c_3,t_2,c_3 | ||
| 1481 | addcc c_12,t_1,c_12 | ||
| 1482 | bcs,a %xcc,.+8 | ||
| 1483 | add c_3,t_2,c_3 | ||
| 1484 | mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3); | ||
| 1485 | addcc c_12,t_1,c_12 | ||
| 1486 | bcs,a %xcc,.+8 | ||
| 1487 | add c_3,t_2,c_3 | ||
| 1488 | addcc c_12,t_1,t_1 | ||
| 1489 | bcs,a %xcc,.+8 | ||
| 1490 | add c_3,t_2,c_3 | ||
| 1491 | srlx t_1,32,c_12 | ||
| 1492 | stuw t_1,rp(3) !r[3]=c1; | ||
| 1493 | or c_12,c_3,c_12 | ||
| 1494 | |||
| 1495 | mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1); | ||
| 1496 | addcc c_12,t_1,c_12 | ||
| 1497 | clr c_3 | ||
| 1498 | bcs,a %xcc,.+8 | ||
| 1499 | add c_3,t_2,c_3 | ||
| 1500 | addcc c_12,t_1,c_12 | ||
| 1501 | bcs,a %xcc,.+8 | ||
| 1502 | add c_3,t_2,c_3 | ||
| 1503 | mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1); | ||
| 1504 | addcc c_12,t_1,t_1 | ||
| 1505 | bcs,a %xcc,.+8 | ||
| 1506 | add c_3,t_2,c_3 | ||
| 1507 | srlx t_1,32,c_12 | ||
| 1508 | stuw t_1,rp(4) !r[4]=c2; | ||
| 1509 | or c_12,c_3,c_12 | ||
| 1510 | |||
| 1511 | mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2); | ||
| 1512 | addcc c_12,t_1,c_12 | ||
| 1513 | clr c_3 | ||
| 1514 | bcs,a %xcc,.+8 | ||
| 1515 | add c_3,t_2,c_3 | ||
| 1516 | addcc c_12,t_1,t_1 | ||
| 1517 | bcs,a %xcc,.+8 | ||
| 1518 | add c_3,t_2,c_3 | ||
| 1519 | srlx t_1,32,c_12 | ||
| 1520 | stuw t_1,rp(5) !r[5]=c3; | ||
| 1521 | or c_12,c_3,c_12 | ||
| 1522 | |||
| 1523 | mulx a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3); | ||
| 1524 | addcc c_12,t_1,t_1 | ||
| 1525 | srlx t_1,32,c_12 | ||
| 1526 | stuw t_1,rp(6) !r[6]=c1; | ||
| 1527 | stuw c_12,rp(7) !r[7]=c2; | ||
| 1528 | |||
| 1529 | ret | ||
| 1530 | restore %g0,%g0,%o0 | ||
| 1531 | |||
| 1532 | .type bn_sqr_comba4,#function | ||
| 1533 | .size bn_sqr_comba4,(.-bn_sqr_comba4) | ||
| 1534 | |||
| 1535 | .align 32 | ||
diff --git a/src/lib/libcrypto/bn/asm/x86.pl b/src/lib/libcrypto/bn/asm/x86.pl deleted file mode 100644 index 1bc4f1bb27..0000000000 --- a/src/lib/libcrypto/bn/asm/x86.pl +++ /dev/null | |||
| @@ -1,28 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | push(@INC,"perlasm","../../perlasm"); | ||
| 4 | require "x86asm.pl"; | ||
| 5 | |||
| 6 | require("x86/mul_add.pl"); | ||
| 7 | require("x86/mul.pl"); | ||
| 8 | require("x86/sqr.pl"); | ||
| 9 | require("x86/div.pl"); | ||
| 10 | require("x86/add.pl"); | ||
| 11 | require("x86/sub.pl"); | ||
| 12 | require("x86/comba.pl"); | ||
| 13 | |||
| 14 | &asm_init($ARGV[0],$0); | ||
| 15 | |||
| 16 | &bn_mul_add_words("bn_mul_add_words"); | ||
| 17 | &bn_mul_words("bn_mul_words"); | ||
| 18 | &bn_sqr_words("bn_sqr_words"); | ||
| 19 | &bn_div_words("bn_div_words"); | ||
| 20 | &bn_add_words("bn_add_words"); | ||
| 21 | &bn_sub_words("bn_sub_words"); | ||
| 22 | &bn_mul_comba("bn_mul_comba8",8); | ||
| 23 | &bn_mul_comba("bn_mul_comba4",4); | ||
| 24 | &bn_sqr_comba("bn_sqr_comba8",8); | ||
| 25 | &bn_sqr_comba("bn_sqr_comba4",4); | ||
| 26 | |||
| 27 | &asm_finish(); | ||
| 28 | |||
diff --git a/src/lib/libcrypto/bn/asm/x86/add.pl b/src/lib/libcrypto/bn/asm/x86/add.pl deleted file mode 100644 index 0b5cf583e3..0000000000 --- a/src/lib/libcrypto/bn/asm/x86/add.pl +++ /dev/null | |||
| @@ -1,76 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # x86 assember | ||
| 3 | |||
| 4 | sub bn_add_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | |||
| 8 | &function_begin($name,""); | ||
| 9 | |||
| 10 | &comment(""); | ||
| 11 | $a="esi"; | ||
| 12 | $b="edi"; | ||
| 13 | $c="eax"; | ||
| 14 | $r="ebx"; | ||
| 15 | $tmp1="ecx"; | ||
| 16 | $tmp2="edx"; | ||
| 17 | $num="ebp"; | ||
| 18 | |||
| 19 | &mov($r,&wparam(0)); # get r | ||
| 20 | &mov($a,&wparam(1)); # get a | ||
| 21 | &mov($b,&wparam(2)); # get b | ||
| 22 | &mov($num,&wparam(3)); # get num | ||
| 23 | &xor($c,$c); # clear carry | ||
| 24 | &and($num,0xfffffff8); # num / 8 | ||
| 25 | |||
| 26 | &jz(&label("aw_finish")); | ||
| 27 | |||
| 28 | &set_label("aw_loop",0); | ||
| 29 | for ($i=0; $i<8; $i++) | ||
| 30 | { | ||
| 31 | &comment("Round $i"); | ||
| 32 | |||
| 33 | &mov($tmp1,&DWP($i*4,$a,"",0)); # *a | ||
| 34 | &mov($tmp2,&DWP($i*4,$b,"",0)); # *b | ||
| 35 | &add($tmp1,$c); | ||
| 36 | &mov($c,0); | ||
| 37 | &adc($c,$c); | ||
| 38 | &add($tmp1,$tmp2); | ||
| 39 | &adc($c,0); | ||
| 40 | &mov(&DWP($i*4,$r,"",0),$tmp1); # *r | ||
| 41 | } | ||
| 42 | |||
| 43 | &comment(""); | ||
| 44 | &add($a,32); | ||
| 45 | &add($b,32); | ||
| 46 | &add($r,32); | ||
| 47 | &sub($num,8); | ||
| 48 | &jnz(&label("aw_loop")); | ||
| 49 | |||
| 50 | &set_label("aw_finish",0); | ||
| 51 | &mov($num,&wparam(3)); # get num | ||
| 52 | &and($num,7); | ||
| 53 | &jz(&label("aw_end")); | ||
| 54 | |||
| 55 | for ($i=0; $i<7; $i++) | ||
| 56 | { | ||
| 57 | &comment("Tail Round $i"); | ||
| 58 | &mov($tmp1,&DWP($i*4,$a,"",0)); # *a | ||
| 59 | &mov($tmp2,&DWP($i*4,$b,"",0));# *b | ||
| 60 | &add($tmp1,$c); | ||
| 61 | &mov($c,0); | ||
| 62 | &adc($c,$c); | ||
| 63 | &add($tmp1,$tmp2); | ||
| 64 | &adc($c,0); | ||
| 65 | &dec($num) if ($i != 6); | ||
| 66 | &mov(&DWP($i*4,$r,"",0),$tmp1); # *a | ||
| 67 | &jz(&label("aw_end")) if ($i != 6); | ||
| 68 | } | ||
| 69 | &set_label("aw_end",0); | ||
| 70 | |||
| 71 | # &mov("eax",$c); # $c is "eax" | ||
| 72 | |||
| 73 | &function_end($name); | ||
| 74 | } | ||
| 75 | |||
| 76 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/x86/comba.pl b/src/lib/libcrypto/bn/asm/x86/comba.pl deleted file mode 100644 index 2291253629..0000000000 --- a/src/lib/libcrypto/bn/asm/x86/comba.pl +++ /dev/null | |||
| @@ -1,277 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # x86 assember | ||
| 3 | |||
| 4 | sub mul_add_c | ||
| 5 | { | ||
| 6 | local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_; | ||
| 7 | |||
| 8 | # pos == -1 if eax and edx are pre-loaded, 0 to load from next | ||
| 9 | # words, and 1 if load return value | ||
| 10 | |||
| 11 | &comment("mul a[$ai]*b[$bi]"); | ||
| 12 | |||
| 13 | # "eax" and "edx" will always be pre-loaded. | ||
| 14 | # &mov("eax",&DWP($ai*4,$a,"",0)) ; | ||
| 15 | # &mov("edx",&DWP($bi*4,$b,"",0)); | ||
| 16 | |||
| 17 | &mul("edx"); | ||
| 18 | &add($c0,"eax"); | ||
| 19 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a | ||
| 20 | &mov("eax",&wparam(0)) if $pos > 0; # load r[] | ||
| 21 | ### | ||
| 22 | &adc($c1,"edx"); | ||
| 23 | &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b | ||
| 24 | &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b | ||
| 25 | ### | ||
| 26 | &adc($c2,0); | ||
| 27 | # is pos > 1, it means it is the last loop | ||
| 28 | &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[]; | ||
| 29 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a | ||
| 30 | } | ||
| 31 | |||
| 32 | sub sqr_add_c | ||
| 33 | { | ||
| 34 | local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_; | ||
| 35 | |||
| 36 | # pos == -1 if eax and edx are pre-loaded, 0 to load from next | ||
| 37 | # words, and 1 if load return value | ||
| 38 | |||
| 39 | &comment("sqr a[$ai]*a[$bi]"); | ||
| 40 | |||
| 41 | # "eax" and "edx" will always be pre-loaded. | ||
| 42 | # &mov("eax",&DWP($ai*4,$a,"",0)) ; | ||
| 43 | # &mov("edx",&DWP($bi*4,$b,"",0)); | ||
| 44 | |||
| 45 | if ($ai == $bi) | ||
| 46 | { &mul("eax");} | ||
| 47 | else | ||
| 48 | { &mul("edx");} | ||
| 49 | &add($c0,"eax"); | ||
| 50 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a | ||
| 51 | ### | ||
| 52 | &adc($c1,"edx"); | ||
| 53 | &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb); | ||
| 54 | ### | ||
| 55 | &adc($c2,0); | ||
| 56 | # is pos > 1, it means it is the last loop | ||
| 57 | &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[]; | ||
| 58 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b | ||
| 59 | } | ||
| 60 | |||
| 61 | sub sqr_add_c2 | ||
| 62 | { | ||
| 63 | local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_; | ||
| 64 | |||
| 65 | # pos == -1 if eax and edx are pre-loaded, 0 to load from next | ||
| 66 | # words, and 1 if load return value | ||
| 67 | |||
| 68 | &comment("sqr a[$ai]*a[$bi]"); | ||
| 69 | |||
| 70 | # "eax" and "edx" will always be pre-loaded. | ||
| 71 | # &mov("eax",&DWP($ai*4,$a,"",0)) ; | ||
| 72 | # &mov("edx",&DWP($bi*4,$a,"",0)); | ||
| 73 | |||
| 74 | if ($ai == $bi) | ||
| 75 | { &mul("eax");} | ||
| 76 | else | ||
| 77 | { &mul("edx");} | ||
| 78 | &add("eax","eax"); | ||
| 79 | ### | ||
| 80 | &adc("edx","edx"); | ||
| 81 | ### | ||
| 82 | &adc($c2,0); | ||
| 83 | &add($c0,"eax"); | ||
| 84 | &adc($c1,"edx"); | ||
| 85 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a | ||
| 86 | &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b | ||
| 87 | &adc($c2,0); | ||
| 88 | &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[]; | ||
| 89 | &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb); | ||
| 90 | ### | ||
| 91 | } | ||
| 92 | |||
| 93 | sub bn_mul_comba | ||
| 94 | { | ||
| 95 | local($name,$num)=@_; | ||
| 96 | local($a,$b,$c0,$c1,$c2); | ||
| 97 | local($i,$as,$ae,$bs,$be,$ai,$bi); | ||
| 98 | local($tot,$end); | ||
| 99 | |||
| 100 | &function_begin_B($name,""); | ||
| 101 | |||
| 102 | $c0="ebx"; | ||
| 103 | $c1="ecx"; | ||
| 104 | $c2="ebp"; | ||
| 105 | $a="esi"; | ||
| 106 | $b="edi"; | ||
| 107 | |||
| 108 | $as=0; | ||
| 109 | $ae=0; | ||
| 110 | $bs=0; | ||
| 111 | $be=0; | ||
| 112 | $tot=$num+$num-1; | ||
| 113 | |||
| 114 | &push("esi"); | ||
| 115 | &mov($a,&wparam(1)); | ||
| 116 | &push("edi"); | ||
| 117 | &mov($b,&wparam(2)); | ||
| 118 | &push("ebp"); | ||
| 119 | &push("ebx"); | ||
| 120 | |||
| 121 | &xor($c0,$c0); | ||
| 122 | &mov("eax",&DWP(0,$a,"",0)); # load the first word | ||
| 123 | &xor($c1,$c1); | ||
| 124 | &mov("edx",&DWP(0,$b,"",0)); # load the first second | ||
| 125 | |||
| 126 | for ($i=0; $i<$tot; $i++) | ||
| 127 | { | ||
| 128 | $ai=$as; | ||
| 129 | $bi=$bs; | ||
| 130 | $end=$be+1; | ||
| 131 | |||
| 132 | &comment("################## Calculate word $i"); | ||
| 133 | |||
| 134 | for ($j=$bs; $j<$end; $j++) | ||
| 135 | { | ||
| 136 | &xor($c2,$c2) if ($j == $bs); | ||
| 137 | if (($j+1) == $end) | ||
| 138 | { | ||
| 139 | $v=1; | ||
| 140 | $v=2 if (($i+1) == $tot); | ||
| 141 | } | ||
| 142 | else | ||
| 143 | { $v=0; } | ||
| 144 | if (($j+1) != $end) | ||
| 145 | { | ||
| 146 | $na=($ai-1); | ||
| 147 | $nb=($bi+1); | ||
| 148 | } | ||
| 149 | else | ||
| 150 | { | ||
| 151 | $na=$as+($i < ($num-1)); | ||
| 152 | $nb=$bs+($i >= ($num-1)); | ||
| 153 | } | ||
| 154 | #printf STDERR "[$ai,$bi] -> [$na,$nb]\n"; | ||
| 155 | &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb); | ||
| 156 | if ($v) | ||
| 157 | { | ||
| 158 | &comment("saved r[$i]"); | ||
| 159 | # &mov("eax",&wparam(0)); | ||
| 160 | # &mov(&DWP($i*4,"eax","",0),$c0); | ||
| 161 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 162 | } | ||
| 163 | $ai--; | ||
| 164 | $bi++; | ||
| 165 | } | ||
| 166 | $as++ if ($i < ($num-1)); | ||
| 167 | $ae++ if ($i >= ($num-1)); | ||
| 168 | |||
| 169 | $bs++ if ($i >= ($num-1)); | ||
| 170 | $be++ if ($i < ($num-1)); | ||
| 171 | } | ||
| 172 | &comment("save r[$i]"); | ||
| 173 | # &mov("eax",&wparam(0)); | ||
| 174 | &mov(&DWP($i*4,"eax","",0),$c0); | ||
| 175 | |||
| 176 | &pop("ebx"); | ||
| 177 | &pop("ebp"); | ||
| 178 | &pop("edi"); | ||
| 179 | &pop("esi"); | ||
| 180 | &ret(); | ||
| 181 | &function_end_B($name); | ||
| 182 | } | ||
| 183 | |||
| 184 | sub bn_sqr_comba | ||
| 185 | { | ||
| 186 | local($name,$num)=@_; | ||
| 187 | local($r,$a,$c0,$c1,$c2)=@_; | ||
| 188 | local($i,$as,$ae,$bs,$be,$ai,$bi); | ||
| 189 | local($b,$tot,$end,$half); | ||
| 190 | |||
| 191 | &function_begin_B($name,""); | ||
| 192 | |||
| 193 | $c0="ebx"; | ||
| 194 | $c1="ecx"; | ||
| 195 | $c2="ebp"; | ||
| 196 | $a="esi"; | ||
| 197 | $r="edi"; | ||
| 198 | |||
| 199 | &push("esi"); | ||
| 200 | &push("edi"); | ||
| 201 | &push("ebp"); | ||
| 202 | &push("ebx"); | ||
| 203 | &mov($r,&wparam(0)); | ||
| 204 | &mov($a,&wparam(1)); | ||
| 205 | &xor($c0,$c0); | ||
| 206 | &xor($c1,$c1); | ||
| 207 | &mov("eax",&DWP(0,$a,"",0)); # load the first word | ||
| 208 | |||
| 209 | $as=0; | ||
| 210 | $ae=0; | ||
| 211 | $bs=0; | ||
| 212 | $be=0; | ||
| 213 | $tot=$num+$num-1; | ||
| 214 | |||
| 215 | for ($i=0; $i<$tot; $i++) | ||
| 216 | { | ||
| 217 | $ai=$as; | ||
| 218 | $bi=$bs; | ||
| 219 | $end=$be+1; | ||
| 220 | |||
| 221 | &comment("############### Calculate word $i"); | ||
| 222 | for ($j=$bs; $j<$end; $j++) | ||
| 223 | { | ||
| 224 | &xor($c2,$c2) if ($j == $bs); | ||
| 225 | if (($ai-1) < ($bi+1)) | ||
| 226 | { | ||
| 227 | $v=1; | ||
| 228 | $v=2 if ($i+1) == $tot; | ||
| 229 | } | ||
| 230 | else | ||
| 231 | { $v=0; } | ||
| 232 | if (!$v) | ||
| 233 | { | ||
| 234 | $na=$ai-1; | ||
| 235 | $nb=$bi+1; | ||
| 236 | } | ||
| 237 | else | ||
| 238 | { | ||
| 239 | $na=$as+($i < ($num-1)); | ||
| 240 | $nb=$bs+($i >= ($num-1)); | ||
| 241 | } | ||
| 242 | if ($ai == $bi) | ||
| 243 | { | ||
| 244 | &sqr_add_c($r,$a,$ai,$bi, | ||
| 245 | $c0,$c1,$c2,$v,$i,$na,$nb); | ||
| 246 | } | ||
| 247 | else | ||
| 248 | { | ||
| 249 | &sqr_add_c2($r,$a,$ai,$bi, | ||
| 250 | $c0,$c1,$c2,$v,$i,$na,$nb); | ||
| 251 | } | ||
| 252 | if ($v) | ||
| 253 | { | ||
| 254 | &comment("saved r[$i]"); | ||
| 255 | #&mov(&DWP($i*4,$r,"",0),$c0); | ||
| 256 | ($c0,$c1,$c2)=($c1,$c2,$c0); | ||
| 257 | last; | ||
| 258 | } | ||
| 259 | $ai--; | ||
| 260 | $bi++; | ||
| 261 | } | ||
| 262 | $as++ if ($i < ($num-1)); | ||
| 263 | $ae++ if ($i >= ($num-1)); | ||
| 264 | |||
| 265 | $bs++ if ($i >= ($num-1)); | ||
| 266 | $be++ if ($i < ($num-1)); | ||
| 267 | } | ||
| 268 | &mov(&DWP($i*4,$r,"",0),$c0); | ||
| 269 | &pop("ebx"); | ||
| 270 | &pop("ebp"); | ||
| 271 | &pop("edi"); | ||
| 272 | &pop("esi"); | ||
| 273 | &ret(); | ||
| 274 | &function_end_B($name); | ||
| 275 | } | ||
| 276 | |||
| 277 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/x86/div.pl b/src/lib/libcrypto/bn/asm/x86/div.pl deleted file mode 100644 index 0e90152caa..0000000000 --- a/src/lib/libcrypto/bn/asm/x86/div.pl +++ /dev/null | |||
| @@ -1,15 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # x86 assember | ||
| 3 | |||
| 4 | sub bn_div_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | |||
| 8 | &function_begin($name,""); | ||
| 9 | &mov("edx",&wparam(0)); # | ||
| 10 | &mov("eax",&wparam(1)); # | ||
| 11 | &mov("ebx",&wparam(2)); # | ||
| 12 | &div("ebx"); | ||
| 13 | &function_end($name); | ||
| 14 | } | ||
| 15 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/x86/mul.pl b/src/lib/libcrypto/bn/asm/x86/mul.pl deleted file mode 100644 index 674cb9b055..0000000000 --- a/src/lib/libcrypto/bn/asm/x86/mul.pl +++ /dev/null | |||
| @@ -1,77 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # x86 assember | ||
| 3 | |||
| 4 | sub bn_mul_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | |||
| 8 | &function_begin($name,""); | ||
| 9 | |||
| 10 | &comment(""); | ||
| 11 | $Low="eax"; | ||
| 12 | $High="edx"; | ||
| 13 | $a="ebx"; | ||
| 14 | $w="ecx"; | ||
| 15 | $r="edi"; | ||
| 16 | $c="esi"; | ||
| 17 | $num="ebp"; | ||
| 18 | |||
| 19 | &xor($c,$c); # clear carry | ||
| 20 | &mov($r,&wparam(0)); # | ||
| 21 | &mov($a,&wparam(1)); # | ||
| 22 | &mov($num,&wparam(2)); # | ||
| 23 | &mov($w,&wparam(3)); # | ||
| 24 | |||
| 25 | &and($num,0xfffffff8); # num / 8 | ||
| 26 | &jz(&label("mw_finish")); | ||
| 27 | |||
| 28 | &set_label("mw_loop",0); | ||
| 29 | for ($i=0; $i<32; $i+=4) | ||
| 30 | { | ||
| 31 | &comment("Round $i"); | ||
| 32 | |||
| 33 | &mov("eax",&DWP($i,$a,"",0)); # *a | ||
| 34 | &mul($w); # *a * w | ||
| 35 | &add("eax",$c); # L(t)+=c | ||
| 36 | # XXX | ||
| 37 | |||
| 38 | &adc("edx",0); # H(t)+=carry | ||
| 39 | &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t); | ||
| 40 | |||
| 41 | &mov($c,"edx"); # c= H(t); | ||
| 42 | } | ||
| 43 | |||
| 44 | &comment(""); | ||
| 45 | &add($a,32); | ||
| 46 | &add($r,32); | ||
| 47 | &sub($num,8); | ||
| 48 | &jz(&label("mw_finish")); | ||
| 49 | &jmp(&label("mw_loop")); | ||
| 50 | |||
| 51 | &set_label("mw_finish",0); | ||
| 52 | &mov($num,&wparam(2)); # get num | ||
| 53 | &and($num,7); | ||
| 54 | &jnz(&label("mw_finish2")); | ||
| 55 | &jmp(&label("mw_end")); | ||
| 56 | |||
| 57 | &set_label("mw_finish2",1); | ||
| 58 | for ($i=0; $i<7; $i++) | ||
| 59 | { | ||
| 60 | &comment("Tail Round $i"); | ||
| 61 | &mov("eax",&DWP($i*4,$a,"",0));# *a | ||
| 62 | &mul($w); # *a * w | ||
| 63 | &add("eax",$c); # L(t)+=c | ||
| 64 | # XXX | ||
| 65 | &adc("edx",0); # H(t)+=carry | ||
| 66 | &mov(&DWP($i*4,$r,"",0),"eax");# *r= L(t); | ||
| 67 | &mov($c,"edx"); # c= H(t); | ||
| 68 | &dec($num) if ($i != 7-1); | ||
| 69 | &jz(&label("mw_end")) if ($i != 7-1); | ||
| 70 | } | ||
| 71 | &set_label("mw_end",0); | ||
| 72 | &mov("eax",$c); | ||
| 73 | |||
| 74 | &function_end($name); | ||
| 75 | } | ||
| 76 | |||
| 77 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/x86/mul_add.pl b/src/lib/libcrypto/bn/asm/x86/mul_add.pl deleted file mode 100644 index 61830d3a90..0000000000 --- a/src/lib/libcrypto/bn/asm/x86/mul_add.pl +++ /dev/null | |||
| @@ -1,87 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # x86 assember | ||
| 3 | |||
| 4 | sub bn_mul_add_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | |||
| 8 | &function_begin($name,""); | ||
| 9 | |||
| 10 | &comment(""); | ||
| 11 | $Low="eax"; | ||
| 12 | $High="edx"; | ||
| 13 | $a="ebx"; | ||
| 14 | $w="ebp"; | ||
| 15 | $r="edi"; | ||
| 16 | $c="esi"; | ||
| 17 | |||
| 18 | &xor($c,$c); # clear carry | ||
| 19 | &mov($r,&wparam(0)); # | ||
| 20 | |||
| 21 | &mov("ecx",&wparam(2)); # | ||
| 22 | &mov($a,&wparam(1)); # | ||
| 23 | |||
| 24 | &and("ecx",0xfffffff8); # num / 8 | ||
| 25 | &mov($w,&wparam(3)); # | ||
| 26 | |||
| 27 | &push("ecx"); # Up the stack for a tmp variable | ||
| 28 | |||
| 29 | &jz(&label("maw_finish")); | ||
| 30 | |||
| 31 | &set_label("maw_loop",0); | ||
| 32 | |||
| 33 | &mov(&swtmp(0),"ecx"); # | ||
| 34 | |||
| 35 | for ($i=0; $i<32; $i+=4) | ||
| 36 | { | ||
| 37 | &comment("Round $i"); | ||
| 38 | |||
| 39 | &mov("eax",&DWP($i,$a,"",0)); # *a | ||
| 40 | &mul($w); # *a * w | ||
| 41 | &add("eax",$c); # L(t)+= *r | ||
| 42 | &mov($c,&DWP($i,$r,"",0)); # L(t)+= *r | ||
| 43 | &adc("edx",0); # H(t)+=carry | ||
| 44 | &add("eax",$c); # L(t)+=c | ||
| 45 | &adc("edx",0); # H(t)+=carry | ||
| 46 | &mov(&DWP($i,$r,"",0),"eax"); # *r= L(t); | ||
| 47 | &mov($c,"edx"); # c= H(t); | ||
| 48 | } | ||
| 49 | |||
| 50 | &comment(""); | ||
| 51 | &mov("ecx",&swtmp(0)); # | ||
| 52 | &add($a,32); | ||
| 53 | &add($r,32); | ||
| 54 | &sub("ecx",8); | ||
| 55 | &jnz(&label("maw_loop")); | ||
| 56 | |||
| 57 | &set_label("maw_finish",0); | ||
| 58 | &mov("ecx",&wparam(2)); # get num | ||
| 59 | &and("ecx",7); | ||
| 60 | &jnz(&label("maw_finish2")); # helps branch prediction | ||
| 61 | &jmp(&label("maw_end")); | ||
| 62 | |||
| 63 | &set_label("maw_finish2",1); | ||
| 64 | for ($i=0; $i<7; $i++) | ||
| 65 | { | ||
| 66 | &comment("Tail Round $i"); | ||
| 67 | &mov("eax",&DWP($i*4,$a,"",0));# *a | ||
| 68 | &mul($w); # *a * w | ||
| 69 | &add("eax",$c); # L(t)+=c | ||
| 70 | &mov($c,&DWP($i*4,$r,"",0)); # L(t)+= *r | ||
| 71 | &adc("edx",0); # H(t)+=carry | ||
| 72 | &add("eax",$c); | ||
| 73 | &adc("edx",0); # H(t)+=carry | ||
| 74 | &dec("ecx") if ($i != 7-1); | ||
| 75 | &mov(&DWP($i*4,$r,"",0),"eax"); # *r= L(t); | ||
| 76 | &mov($c,"edx"); # c= H(t); | ||
| 77 | &jz(&label("maw_end")) if ($i != 7-1); | ||
| 78 | } | ||
| 79 | &set_label("maw_end",0); | ||
| 80 | &mov("eax",$c); | ||
| 81 | |||
| 82 | &pop("ecx"); # clear variable from | ||
| 83 | |||
| 84 | &function_end($name); | ||
| 85 | } | ||
| 86 | |||
| 87 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/x86/sqr.pl b/src/lib/libcrypto/bn/asm/x86/sqr.pl deleted file mode 100644 index 1f90993cf6..0000000000 --- a/src/lib/libcrypto/bn/asm/x86/sqr.pl +++ /dev/null | |||
| @@ -1,60 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # x86 assember | ||
| 3 | |||
| 4 | sub bn_sqr_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | |||
| 8 | &function_begin($name,""); | ||
| 9 | |||
| 10 | &comment(""); | ||
| 11 | $r="esi"; | ||
| 12 | $a="edi"; | ||
| 13 | $num="ebx"; | ||
| 14 | |||
| 15 | &mov($r,&wparam(0)); # | ||
| 16 | &mov($a,&wparam(1)); # | ||
| 17 | &mov($num,&wparam(2)); # | ||
| 18 | |||
| 19 | &and($num,0xfffffff8); # num / 8 | ||
| 20 | &jz(&label("sw_finish")); | ||
| 21 | |||
| 22 | &set_label("sw_loop",0); | ||
| 23 | for ($i=0; $i<32; $i+=4) | ||
| 24 | { | ||
| 25 | &comment("Round $i"); | ||
| 26 | &mov("eax",&DWP($i,$a,"",0)); # *a | ||
| 27 | # XXX | ||
| 28 | &mul("eax"); # *a * *a | ||
| 29 | &mov(&DWP($i*2,$r,"",0),"eax"); # | ||
| 30 | &mov(&DWP($i*2+4,$r,"",0),"edx");# | ||
| 31 | } | ||
| 32 | |||
| 33 | &comment(""); | ||
| 34 | &add($a,32); | ||
| 35 | &add($r,64); | ||
| 36 | &sub($num,8); | ||
| 37 | &jnz(&label("sw_loop")); | ||
| 38 | |||
| 39 | &set_label("sw_finish",0); | ||
| 40 | &mov($num,&wparam(2)); # get num | ||
| 41 | &and($num,7); | ||
| 42 | &jz(&label("sw_end")); | ||
| 43 | |||
| 44 | for ($i=0; $i<7; $i++) | ||
| 45 | { | ||
| 46 | &comment("Tail Round $i"); | ||
| 47 | &mov("eax",&DWP($i*4,$a,"",0)); # *a | ||
| 48 | # XXX | ||
| 49 | &mul("eax"); # *a * *a | ||
| 50 | &mov(&DWP($i*8,$r,"",0),"eax"); # | ||
| 51 | &dec($num) if ($i != 7-1); | ||
| 52 | &mov(&DWP($i*8+4,$r,"",0),"edx"); | ||
| 53 | &jz(&label("sw_end")) if ($i != 7-1); | ||
| 54 | } | ||
| 55 | &set_label("sw_end",0); | ||
| 56 | |||
| 57 | &function_end($name); | ||
| 58 | } | ||
| 59 | |||
| 60 | 1; | ||
diff --git a/src/lib/libcrypto/bn/asm/x86/sub.pl b/src/lib/libcrypto/bn/asm/x86/sub.pl deleted file mode 100644 index 837b0e1b07..0000000000 --- a/src/lib/libcrypto/bn/asm/x86/sub.pl +++ /dev/null | |||
| @@ -1,76 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # x86 assember | ||
| 3 | |||
| 4 | sub bn_sub_words | ||
| 5 | { | ||
| 6 | local($name)=@_; | ||
| 7 | |||
| 8 | &function_begin($name,""); | ||
| 9 | |||
| 10 | &comment(""); | ||
| 11 | $a="esi"; | ||
| 12 | $b="edi"; | ||
| 13 | $c="eax"; | ||
| 14 | $r="ebx"; | ||
| 15 | $tmp1="ecx"; | ||
| 16 | $tmp2="edx"; | ||
| 17 | $num="ebp"; | ||
| 18 | |||
| 19 | &mov($r,&wparam(0)); # get r | ||
| 20 | &mov($a,&wparam(1)); # get a | ||
| 21 | &mov($b,&wparam(2)); # get b | ||
| 22 | &mov($num,&wparam(3)); # get num | ||
| 23 | &xor($c,$c); # clear carry | ||
| 24 | &and($num,0xfffffff8); # num / 8 | ||
| 25 | |||
| 26 | &jz(&label("aw_finish")); | ||
| 27 | |||
| 28 | &set_label("aw_loop",0); | ||
| 29 | for ($i=0; $i<8; $i++) | ||
| 30 | { | ||
| 31 | &comment("Round $i"); | ||
| 32 | |||
| 33 | &mov($tmp1,&DWP($i*4,$a,"",0)); # *a | ||
| 34 | &mov($tmp2,&DWP($i*4,$b,"",0)); # *b | ||
| 35 | &sub($tmp1,$c); | ||
| 36 | &mov($c,0); | ||
| 37 | &adc($c,$c); | ||
| 38 | &sub($tmp1,$tmp2); | ||
| 39 | &adc($c,0); | ||
| 40 | &mov(&DWP($i*4,$r,"",0),$tmp1); # *r | ||
| 41 | } | ||
| 42 | |||
| 43 | &comment(""); | ||
| 44 | &add($a,32); | ||
| 45 | &add($b,32); | ||
| 46 | &add($r,32); | ||
| 47 | &sub($num,8); | ||
| 48 | &jnz(&label("aw_loop")); | ||
| 49 | |||
| 50 | &set_label("aw_finish",0); | ||
| 51 | &mov($num,&wparam(3)); # get num | ||
| 52 | &and($num,7); | ||
| 53 | &jz(&label("aw_end")); | ||
| 54 | |||
| 55 | for ($i=0; $i<7; $i++) | ||
| 56 | { | ||
| 57 | &comment("Tail Round $i"); | ||
| 58 | &mov($tmp1,&DWP($i*4,$a,"",0)); # *a | ||
| 59 | &mov($tmp2,&DWP($i*4,$b,"",0));# *b | ||
| 60 | &sub($tmp1,$c); | ||
| 61 | &mov($c,0); | ||
| 62 | &adc($c,$c); | ||
| 63 | &sub($tmp1,$tmp2); | ||
| 64 | &adc($c,0); | ||
| 65 | &dec($num) if ($i != 6); | ||
| 66 | &mov(&DWP($i*4,$r,"",0),$tmp1); # *a | ||
| 67 | &jz(&label("aw_end")) if ($i != 6); | ||
| 68 | } | ||
| 69 | &set_label("aw_end",0); | ||
| 70 | |||
| 71 | # &mov("eax",$c); # $c is "eax" | ||
| 72 | |||
| 73 | &function_end($name); | ||
| 74 | } | ||
| 75 | |||
| 76 | 1; | ||
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h deleted file mode 100644 index f935e1ca79..0000000000 --- a/src/lib/libcrypto/bn/bn.h +++ /dev/null | |||
| @@ -1,467 +0,0 @@ | |||
| 1 | /* crypto/bn/bn.h */ | ||
| 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_BN_H | ||
| 60 | #define HEADER_BN_H | ||
| 61 | |||
| 62 | #ifndef WIN16 | ||
| 63 | #include <stdio.h> /* FILE */ | ||
| 64 | #endif | ||
| 65 | #include <openssl/opensslconf.h> | ||
| 66 | |||
| 67 | #ifdef __cplusplus | ||
| 68 | extern "C" { | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #ifdef VMS | ||
| 72 | #undef BN_LLONG /* experimental, so far... */ | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #define BN_MUL_COMBA | ||
| 76 | #define BN_SQR_COMBA | ||
| 77 | #define BN_RECURSION | ||
| 78 | #define RECP_MUL_MOD | ||
| 79 | #define MONT_MUL_MOD | ||
| 80 | |||
| 81 | /* This next option uses the C libraries (2 word)/(1 word) function. | ||
| 82 | * If it is not defined, I use my C version (which is slower). | ||
| 83 | * The reason for this flag is that when the particular C compiler | ||
| 84 | * library routine is used, and the library is linked with a different | ||
| 85 | * compiler, the library is missing. This mostly happens when the | ||
| 86 | * library is built with gcc and then linked using nornal cc. This would | ||
| 87 | * be a common occurance because gcc normally produces code that is | ||
| 88 | * 2 times faster than system compilers for the big number stuff. | ||
| 89 | * For machines with only one compiler (or shared libraries), this should | ||
| 90 | * be on. Again this in only really a problem on machines | ||
| 91 | * using "long long's", are 32bit, and are not using my assember code. */ | ||
| 92 | #if defined(MSDOS) || defined(WINDOWS) || defined(linux) | ||
| 93 | #define BN_DIV2W | ||
| 94 | #endif | ||
| 95 | |||
| 96 | /* assuming long is 64bit - this is the DEC Alpha | ||
| 97 | * unsigned long long is only 64 bits :-(, don't define | ||
| 98 | * BN_LLONG for the DEC Alpha */ | ||
| 99 | #ifdef SIXTY_FOUR_BIT_LONG | ||
| 100 | #define BN_ULLONG unsigned long long | ||
| 101 | #define BN_ULONG unsigned long | ||
| 102 | #define BN_LONG long | ||
| 103 | #define BN_BITS 128 | ||
| 104 | #define BN_BYTES 8 | ||
| 105 | #define BN_BITS2 64 | ||
| 106 | #define BN_BITS4 32 | ||
| 107 | #define BN_MASK (0xffffffffffffffffffffffffffffffffLL) | ||
| 108 | #define BN_MASK2 (0xffffffffffffffffL) | ||
| 109 | #define BN_MASK2l (0xffffffffL) | ||
| 110 | #define BN_MASK2h (0xffffffff00000000L) | ||
| 111 | #define BN_MASK2h1 (0xffffffff80000000L) | ||
| 112 | #define BN_TBIT (0x8000000000000000L) | ||
| 113 | #define BN_DEC_CONV (10000000000000000000UL) | ||
| 114 | #define BN_DEC_FMT1 "%lu" | ||
| 115 | #define BN_DEC_FMT2 "%019lu" | ||
| 116 | #define BN_DEC_NUM 19 | ||
| 117 | #endif | ||
| 118 | |||
| 119 | /* This is where the long long data type is 64 bits, but long is 32. | ||
| 120 | * For machines where there are 64bit registers, this is the mode to use. | ||
| 121 | * IRIX, on R4000 and above should use this mode, along with the relevent | ||
| 122 | * assember code :-). Do NOT define BN_LLONG. | ||
| 123 | */ | ||
| 124 | #ifdef SIXTY_FOUR_BIT | ||
| 125 | #undef BN_LLONG | ||
| 126 | #undef BN_ULLONG | ||
| 127 | #define BN_ULONG unsigned long long | ||
| 128 | #define BN_LONG long long | ||
| 129 | #define BN_BITS 128 | ||
| 130 | #define BN_BYTES 8 | ||
| 131 | #define BN_BITS2 64 | ||
| 132 | #define BN_BITS4 32 | ||
| 133 | #define BN_MASK2 (0xffffffffffffffffLL) | ||
| 134 | #define BN_MASK2l (0xffffffffL) | ||
| 135 | #define BN_MASK2h (0xffffffff00000000LL) | ||
| 136 | #define BN_MASK2h1 (0xffffffff80000000LL) | ||
| 137 | #define BN_TBIT (0x8000000000000000LL) | ||
| 138 | #define BN_DEC_CONV (10000000000000000000LL) | ||
| 139 | #define BN_DEC_FMT1 "%llu" | ||
| 140 | #define BN_DEC_FMT2 "%019llu" | ||
| 141 | #define BN_DEC_NUM 19 | ||
| 142 | #endif | ||
| 143 | |||
| 144 | #ifdef THIRTY_TWO_BIT | ||
| 145 | #if defined(WIN32) && !defined(__GNUC__) | ||
| 146 | #define BN_ULLONG unsigned _int64 | ||
| 147 | #else | ||
| 148 | #define BN_ULLONG unsigned long long | ||
| 149 | #endif | ||
| 150 | #define BN_ULONG unsigned long | ||
| 151 | #define BN_LONG long | ||
| 152 | #define BN_BITS 64 | ||
| 153 | #define BN_BYTES 4 | ||
| 154 | #define BN_BITS2 32 | ||
| 155 | #define BN_BITS4 16 | ||
| 156 | #ifdef WIN32 | ||
| 157 | /* VC++ doesn't like the LL suffix */ | ||
| 158 | #define BN_MASK (0xffffffffffffffffL) | ||
| 159 | #else | ||
| 160 | #define BN_MASK (0xffffffffffffffffLL) | ||
| 161 | #endif | ||
| 162 | #define BN_MASK2 (0xffffffffL) | ||
| 163 | #define BN_MASK2l (0xffff) | ||
| 164 | #define BN_MASK2h1 (0xffff8000L) | ||
| 165 | #define BN_MASK2h (0xffff0000L) | ||
| 166 | #define BN_TBIT (0x80000000L) | ||
| 167 | #define BN_DEC_CONV (1000000000L) | ||
| 168 | #define BN_DEC_FMT1 "%lu" | ||
| 169 | #define BN_DEC_FMT2 "%09lu" | ||
| 170 | #define BN_DEC_NUM 9 | ||
| 171 | #endif | ||
| 172 | |||
| 173 | #ifdef SIXTEEN_BIT | ||
| 174 | #ifndef BN_DIV2W | ||
| 175 | #define BN_DIV2W | ||
| 176 | #endif | ||
| 177 | #define BN_ULLONG unsigned long | ||
| 178 | #define BN_ULONG unsigned short | ||
| 179 | #define BN_LONG short | ||
| 180 | #define BN_BITS 32 | ||
| 181 | #define BN_BYTES 2 | ||
| 182 | #define BN_BITS2 16 | ||
| 183 | #define BN_BITS4 8 | ||
| 184 | #define BN_MASK (0xffffffff) | ||
| 185 | #define BN_MASK2 (0xffff) | ||
| 186 | #define BN_MASK2l (0xff) | ||
| 187 | #define BN_MASK2h1 (0xff80) | ||
| 188 | #define BN_MASK2h (0xff00) | ||
| 189 | #define BN_TBIT (0x8000) | ||
| 190 | #define BN_DEC_CONV (100000) | ||
| 191 | #define BN_DEC_FMT1 "%u" | ||
| 192 | #define BN_DEC_FMT2 "%05u" | ||
| 193 | #define BN_DEC_NUM 5 | ||
| 194 | #endif | ||
| 195 | |||
| 196 | #ifdef EIGHT_BIT | ||
| 197 | #ifndef BN_DIV2W | ||
| 198 | #define BN_DIV2W | ||
| 199 | #endif | ||
| 200 | #define BN_ULLONG unsigned short | ||
| 201 | #define BN_ULONG unsigned char | ||
| 202 | #define BN_LONG char | ||
| 203 | #define BN_BITS 16 | ||
| 204 | #define BN_BYTES 1 | ||
| 205 | #define BN_BITS2 8 | ||
| 206 | #define BN_BITS4 4 | ||
| 207 | #define BN_MASK (0xffff) | ||
| 208 | #define BN_MASK2 (0xff) | ||
| 209 | #define BN_MASK2l (0xf) | ||
| 210 | #define BN_MASK2h1 (0xf8) | ||
| 211 | #define BN_MASK2h (0xf0) | ||
| 212 | #define BN_TBIT (0x80) | ||
| 213 | #define BN_DEC_CONV (100) | ||
| 214 | #define BN_DEC_FMT1 "%u" | ||
| 215 | #define BN_DEC_FMT2 "%02u" | ||
| 216 | #define BN_DEC_NUM 2 | ||
| 217 | #endif | ||
| 218 | |||
| 219 | #define BN_DEFAULT_BITS 1280 | ||
| 220 | |||
| 221 | #ifdef BIGNUM | ||
| 222 | #undef BIGNUM | ||
| 223 | #endif | ||
| 224 | |||
| 225 | #define BN_FLG_MALLOCED 0x01 | ||
| 226 | #define BN_FLG_STATIC_DATA 0x02 | ||
| 227 | #define BN_FLG_FREE 0x8000 /* used for debuging */ | ||
| 228 | #define BN_set_flags(b,n) ((b)->flags|=(n)) | ||
| 229 | #define BN_get_flags(b,n) ((b)->flags&(n)) | ||
| 230 | |||
| 231 | typedef struct bignum_st | ||
| 232 | { | ||
| 233 | BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ | ||
| 234 | int top; /* Index of last used d +1. */ | ||
| 235 | /* The next are internal book keeping for bn_expand. */ | ||
| 236 | int max; /* Size of the d array. */ | ||
| 237 | int neg; /* one if the number is negative */ | ||
| 238 | int flags; | ||
| 239 | } BIGNUM; | ||
| 240 | |||
| 241 | /* Used for temp variables */ | ||
| 242 | #define BN_CTX_NUM 12 | ||
| 243 | typedef struct bignum_ctx | ||
| 244 | { | ||
| 245 | int tos; | ||
| 246 | BIGNUM bn[BN_CTX_NUM+1]; | ||
| 247 | int flags; | ||
| 248 | } BN_CTX; | ||
| 249 | |||
| 250 | typedef struct bn_blinding_st | ||
| 251 | { | ||
| 252 | int init; | ||
| 253 | BIGNUM *A; | ||
| 254 | BIGNUM *Ai; | ||
| 255 | BIGNUM *mod; /* just a reference */ | ||
| 256 | } BN_BLINDING; | ||
| 257 | |||
| 258 | /* Used for montgomery multiplication */ | ||
| 259 | typedef struct bn_mont_ctx_st | ||
| 260 | { | ||
| 261 | int use_word; /* 0 for word form, 1 for long form */ | ||
| 262 | int ri; /* number of bits in R */ | ||
| 263 | BIGNUM RR; /* used to convert to montgomery form */ | ||
| 264 | BIGNUM N; /* The modulus */ | ||
| 265 | BIGNUM Ni; /* The inverse of N */ | ||
| 266 | BN_ULONG n0; /* word form of inverse, normally only one of | ||
| 267 | * Ni or n0 is defined */ | ||
| 268 | int flags; | ||
| 269 | } BN_MONT_CTX; | ||
| 270 | |||
| 271 | /* Used for reciprocal division/mod functions | ||
| 272 | * It cannot be shared between threads | ||
| 273 | */ | ||
| 274 | typedef struct bn_recp_ctx_st | ||
| 275 | { | ||
| 276 | BIGNUM N; /* the divisor */ | ||
| 277 | BIGNUM Nr; /* the reciprocal */ | ||
| 278 | int num_bits; | ||
| 279 | int shift; | ||
| 280 | int flags; | ||
| 281 | } BN_RECP_CTX; | ||
| 282 | |||
| 283 | #define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ | ||
| 284 | r,a,&((mont)->RR),(mont),ctx) | ||
| 285 | |||
| 286 | #define BN_prime_checks (5) | ||
| 287 | |||
| 288 | #define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) | ||
| 289 | #define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) | ||
| 290 | #define BN_is_zero(a) (((a)->top == 0) || BN_is_word(a,0)) | ||
| 291 | #define BN_is_one(a) (BN_is_word((a),1)) | ||
| 292 | #define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1)) | ||
| 293 | #define BN_one(a) (BN_set_word((a),1)) | ||
| 294 | #define BN_zero(a) (BN_set_word((a),0)) | ||
| 295 | |||
| 296 | /*#define BN_ascii2bn(a) BN_hex2bn(a) */ | ||
| 297 | /*#define BN_bn2ascii(a) BN_bn2hex(a) */ | ||
| 298 | |||
| 299 | #define bn_expand(n,b) ((((((b+BN_BITS2-1))/BN_BITS2)) <= (n)->max)?\ | ||
| 300 | (n):bn_expand2((n),(b)/BN_BITS2+1)) | ||
| 301 | #define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b))) | ||
| 302 | |||
| 303 | #define bn_fix_top(a) \ | ||
| 304 | { \ | ||
| 305 | BN_ULONG *ftl; \ | ||
| 306 | if ((a)->top > 0) \ | ||
| 307 | { \ | ||
| 308 | for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ | ||
| 309 | if (*(ftl--)) break; \ | ||
| 310 | } \ | ||
| 311 | } | ||
| 312 | |||
| 313 | BIGNUM *BN_value_one(void); | ||
| 314 | char * BN_options(void); | ||
| 315 | BN_CTX *BN_CTX_new(void); | ||
| 316 | void BN_CTX_init(BN_CTX *c); | ||
| 317 | void BN_CTX_free(BN_CTX *c); | ||
| 318 | int BN_rand(BIGNUM *rnd, int bits, int top,int bottom); | ||
| 319 | int BN_num_bits(const BIGNUM *a); | ||
| 320 | int BN_num_bits_word(BN_ULONG); | ||
| 321 | BIGNUM *BN_new(void); | ||
| 322 | void BN_init(BIGNUM *); | ||
| 323 | void BN_clear_free(BIGNUM *a); | ||
| 324 | BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b); | ||
| 325 | BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret); | ||
| 326 | int BN_bn2bin(const BIGNUM *a, unsigned char *to); | ||
| 327 | BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret); | ||
| 328 | int BN_bn2mpi(const BIGNUM *a, unsigned char *to); | ||
| 329 | int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); | ||
| 330 | int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); | ||
| 331 | int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); | ||
| 332 | int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b); | ||
| 333 | int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); | ||
| 334 | int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, | ||
| 335 | BN_CTX *ctx); | ||
| 336 | int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b,BN_CTX *ctx); | ||
| 337 | int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx); | ||
| 338 | BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w); | ||
| 339 | BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); | ||
| 340 | int BN_mul_word(BIGNUM *a, BN_ULONG w); | ||
| 341 | int BN_add_word(BIGNUM *a, BN_ULONG w); | ||
| 342 | int BN_sub_word(BIGNUM *a, BN_ULONG w); | ||
| 343 | int BN_set_word(BIGNUM *a, BN_ULONG w); | ||
| 344 | BN_ULONG BN_get_word(BIGNUM *a); | ||
| 345 | int BN_cmp(const BIGNUM *a, const BIGNUM *b); | ||
| 346 | void BN_free(BIGNUM *a); | ||
| 347 | int BN_is_bit_set(const BIGNUM *a, int n); | ||
| 348 | int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); | ||
| 349 | int BN_lshift1(BIGNUM *r, BIGNUM *a); | ||
| 350 | int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p,BN_CTX *ctx); | ||
| 351 | int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 352 | const BIGNUM *m,BN_CTX *ctx); | ||
| 353 | int BN_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 354 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); | ||
| 355 | int BN_mod_exp2_mont(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2, | ||
| 356 | BIGNUM *p2,BIGNUM *m,BN_CTX *ctx,BN_MONT_CTX *m_ctx); | ||
| 357 | int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, | ||
| 358 | BIGNUM *m,BN_CTX *ctx); | ||
| 359 | int BN_mask_bits(BIGNUM *a,int n); | ||
| 360 | int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); | ||
| 361 | #ifndef WIN16 | ||
| 362 | int BN_print_fp(FILE *fp, BIGNUM *a); | ||
| 363 | #endif | ||
| 364 | #ifdef HEADER_BIO_H | ||
| 365 | int BN_print(BIO *fp, const BIGNUM *a); | ||
| 366 | #else | ||
| 367 | int BN_print(char *fp, const BIGNUM *a); | ||
| 368 | #endif | ||
| 369 | int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx); | ||
| 370 | int BN_rshift(BIGNUM *r, BIGNUM *a, int n); | ||
| 371 | int BN_rshift1(BIGNUM *r, BIGNUM *a); | ||
| 372 | void BN_clear(BIGNUM *a); | ||
| 373 | BIGNUM *bn_expand2(BIGNUM *b, int bits); | ||
| 374 | BIGNUM *BN_dup(const BIGNUM *a); | ||
| 375 | int BN_ucmp(const BIGNUM *a, const BIGNUM *b); | ||
| 376 | int BN_set_bit(BIGNUM *a, int n); | ||
| 377 | int BN_clear_bit(BIGNUM *a, int n); | ||
| 378 | char * BN_bn2hex(const BIGNUM *a); | ||
| 379 | char * BN_bn2dec(const BIGNUM *a); | ||
| 380 | int BN_hex2bn(BIGNUM **a, const char *str); | ||
| 381 | int BN_dec2bn(BIGNUM **a, const char *str); | ||
| 382 | int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx); | ||
| 383 | BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); | ||
| 384 | BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int strong,BIGNUM *add, | ||
| 385 | BIGNUM *rem,void (*callback)(int,int,void *),void *cb_arg); | ||
| 386 | int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(int,int,void *), | ||
| 387 | BN_CTX *ctx,void *cb_arg); | ||
| 388 | void ERR_load_BN_strings(void ); | ||
| 389 | |||
| 390 | BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); | ||
| 391 | BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); | ||
| 392 | void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num); | ||
| 393 | BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d); | ||
| 394 | BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num); | ||
| 395 | BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num); | ||
| 396 | |||
| 397 | BN_MONT_CTX *BN_MONT_CTX_new(void ); | ||
| 398 | void BN_MONT_CTX_init(BN_MONT_CTX *ctx); | ||
| 399 | int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont, | ||
| 400 | BN_CTX *ctx); | ||
| 401 | int BN_from_montgomery(BIGNUM *r,BIGNUM *a,BN_MONT_CTX *mont,BN_CTX *ctx); | ||
| 402 | void BN_MONT_CTX_free(BN_MONT_CTX *mont); | ||
| 403 | int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *modulus,BN_CTX *ctx); | ||
| 404 | BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from); | ||
| 405 | |||
| 406 | BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod); | ||
| 407 | void BN_BLINDING_free(BN_BLINDING *b); | ||
| 408 | int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx); | ||
| 409 | int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *r, BN_CTX *ctx); | ||
| 410 | int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); | ||
| 411 | |||
| 412 | void BN_set_params(int mul,int high,int low,int mont); | ||
| 413 | int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */ | ||
| 414 | |||
| 415 | void BN_RECP_CTX_init(BN_RECP_CTX *recp); | ||
| 416 | BN_RECP_CTX *BN_RECP_CTX_new(void); | ||
| 417 | void BN_RECP_CTX_free(BN_RECP_CTX *recp); | ||
| 418 | int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx); | ||
| 419 | int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, | ||
| 420 | BN_RECP_CTX *recp,BN_CTX *ctx); | ||
| 421 | int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 422 | const BIGNUM *m, BN_CTX *ctx); | ||
| 423 | int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, | ||
| 424 | BN_RECP_CTX *recp, BN_CTX *ctx); | ||
| 425 | |||
| 426 | |||
| 427 | /* BEGIN ERROR CODES */ | ||
| 428 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 429 | * made after this point may be overwritten when the script is next run. | ||
| 430 | */ | ||
| 431 | |||
| 432 | /* Error codes for the BN functions. */ | ||
| 433 | |||
| 434 | /* Function codes. */ | ||
| 435 | #define BN_F_BN_BLINDING_CONVERT 100 | ||
| 436 | #define BN_F_BN_BLINDING_INVERT 101 | ||
| 437 | #define BN_F_BN_BLINDING_NEW 102 | ||
| 438 | #define BN_F_BN_BLINDING_UPDATE 103 | ||
| 439 | #define BN_F_BN_BN2DEC 104 | ||
| 440 | #define BN_F_BN_BN2HEX 105 | ||
| 441 | #define BN_F_BN_CTX_NEW 106 | ||
| 442 | #define BN_F_BN_DIV 107 | ||
| 443 | #define BN_F_BN_EXPAND2 108 | ||
| 444 | #define BN_F_BN_MOD_EXP_MONT 109 | ||
| 445 | #define BN_F_BN_MOD_INVERSE 110 | ||
| 446 | #define BN_F_BN_MOD_MUL_RECIPROCAL 111 | ||
| 447 | #define BN_F_BN_MPI2BN 112 | ||
| 448 | #define BN_F_BN_NEW 113 | ||
| 449 | #define BN_F_BN_RAND 114 | ||
| 450 | #define BN_F_BN_USUB 115 | ||
| 451 | |||
| 452 | /* Reason codes. */ | ||
| 453 | #define BN_R_ARG2_LT_ARG3 100 | ||
| 454 | #define BN_R_BAD_RECIPROCAL 101 | ||
| 455 | #define BN_R_CALLED_WITH_EVEN_MODULUS 102 | ||
| 456 | #define BN_R_DIV_BY_ZERO 103 | ||
| 457 | #define BN_R_ENCODING_ERROR 104 | ||
| 458 | #define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105 | ||
| 459 | #define BN_R_INVALID_LENGTH 106 | ||
| 460 | #define BN_R_NOT_INITIALIZED 107 | ||
| 461 | #define BN_R_NO_INVERSE 108 | ||
| 462 | |||
| 463 | #ifdef __cplusplus | ||
| 464 | } | ||
| 465 | #endif | ||
| 466 | #endif | ||
| 467 | |||
diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c deleted file mode 100644 index c5ab066c9e..0000000000 --- a/src/lib/libcrypto/bn/bn_add.c +++ /dev/null | |||
| @@ -1,307 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_add.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | /* r can == a or b */ | ||
| 64 | int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b) | ||
| 65 | { | ||
| 66 | BIGNUM *tmp; | ||
| 67 | |||
| 68 | bn_check_top(a); | ||
| 69 | bn_check_top(b); | ||
| 70 | |||
| 71 | /* a + b a+b | ||
| 72 | * a + -b a-b | ||
| 73 | * -a + b b-a | ||
| 74 | * -a + -b -(a+b) | ||
| 75 | */ | ||
| 76 | if (a->neg ^ b->neg) | ||
| 77 | { | ||
| 78 | /* only one is negative */ | ||
| 79 | if (a->neg) | ||
| 80 | { tmp=a; a=b; b=tmp; } | ||
| 81 | |||
| 82 | /* we are now a - b */ | ||
| 83 | |||
| 84 | if (BN_ucmp(a,b) < 0) | ||
| 85 | { | ||
| 86 | if (!BN_usub(r,b,a)) return(0); | ||
| 87 | r->neg=1; | ||
| 88 | } | ||
| 89 | else | ||
| 90 | { | ||
| 91 | if (!BN_usub(r,a,b)) return(0); | ||
| 92 | r->neg=0; | ||
| 93 | } | ||
| 94 | return(1); | ||
| 95 | } | ||
| 96 | |||
| 97 | if (a->neg) /* both are neg */ | ||
| 98 | r->neg=1; | ||
| 99 | else | ||
| 100 | r->neg=0; | ||
| 101 | |||
| 102 | if (!BN_uadd(r,a,b)) return(0); | ||
| 103 | return(1); | ||
| 104 | } | ||
| 105 | |||
| 106 | /* unsigned add of b to a, r must be large enough */ | ||
| 107 | int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) | ||
| 108 | { | ||
| 109 | register int i; | ||
| 110 | int max,min; | ||
| 111 | BN_ULONG *ap,*bp,*rp,carry,t1; | ||
| 112 | const BIGNUM *tmp; | ||
| 113 | |||
| 114 | bn_check_top(a); | ||
| 115 | bn_check_top(b); | ||
| 116 | |||
| 117 | if (a->top < b->top) | ||
| 118 | { tmp=a; a=b; b=tmp; } | ||
| 119 | max=a->top; | ||
| 120 | min=b->top; | ||
| 121 | |||
| 122 | if (bn_wexpand(r,max+1) == NULL) | ||
| 123 | return(0); | ||
| 124 | |||
| 125 | r->top=max; | ||
| 126 | |||
| 127 | |||
| 128 | ap=a->d; | ||
| 129 | bp=b->d; | ||
| 130 | rp=r->d; | ||
| 131 | carry=0; | ||
| 132 | |||
| 133 | carry=bn_add_words(rp,ap,bp,min); | ||
| 134 | rp+=min; | ||
| 135 | ap+=min; | ||
| 136 | bp+=min; | ||
| 137 | i=min; | ||
| 138 | |||
| 139 | if (carry) | ||
| 140 | { | ||
| 141 | while (i < max) | ||
| 142 | { | ||
| 143 | i++; | ||
| 144 | t1= *(ap++); | ||
| 145 | if ((*(rp++)=(t1+1)&BN_MASK2) >= t1) | ||
| 146 | { | ||
| 147 | carry=0; | ||
| 148 | break; | ||
| 149 | } | ||
| 150 | } | ||
| 151 | if ((i >= max) && carry) | ||
| 152 | { | ||
| 153 | *(rp++)=1; | ||
| 154 | r->top++; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | if (rp != ap) | ||
| 158 | { | ||
| 159 | for (; i<max; i++) | ||
| 160 | *(rp++)= *(ap++); | ||
| 161 | } | ||
| 162 | /* memcpy(rp,ap,sizeof(*ap)*(max-i));*/ | ||
| 163 | return(1); | ||
| 164 | } | ||
| 165 | |||
| 166 | /* unsigned subtraction of b from a, a must be larger than b. */ | ||
| 167 | int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) | ||
| 168 | { | ||
| 169 | int max,min; | ||
| 170 | register BN_ULONG t1,t2,*ap,*bp,*rp; | ||
| 171 | int i,carry; | ||
| 172 | #if defined(IRIX_CC_BUG) && !defined(LINT) | ||
| 173 | int dummy; | ||
| 174 | #endif | ||
| 175 | |||
| 176 | bn_check_top(a); | ||
| 177 | bn_check_top(b); | ||
| 178 | |||
| 179 | if (a->top < b->top) /* hmm... should not be happening */ | ||
| 180 | { | ||
| 181 | BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3); | ||
| 182 | return(0); | ||
| 183 | } | ||
| 184 | |||
| 185 | max=a->top; | ||
| 186 | min=b->top; | ||
| 187 | if (bn_wexpand(r,max) == NULL) return(0); | ||
| 188 | |||
| 189 | ap=a->d; | ||
| 190 | bp=b->d; | ||
| 191 | rp=r->d; | ||
| 192 | |||
| 193 | #if 1 | ||
| 194 | carry=0; | ||
| 195 | for (i=0; i<min; i++) | ||
| 196 | { | ||
| 197 | t1= *(ap++); | ||
| 198 | t2= *(bp++); | ||
| 199 | if (carry) | ||
| 200 | { | ||
| 201 | carry=(t1 <= t2); | ||
| 202 | t1=(t1-t2-1)&BN_MASK2; | ||
| 203 | } | ||
| 204 | else | ||
| 205 | { | ||
| 206 | carry=(t1 < t2); | ||
| 207 | t1=(t1-t2)&BN_MASK2; | ||
| 208 | } | ||
| 209 | #if defined(IRIX_CC_BUG) && !defined(LINT) | ||
| 210 | dummy=t1; | ||
| 211 | #endif | ||
| 212 | *(rp++)=t1&BN_MASK2; | ||
| 213 | } | ||
| 214 | #else | ||
| 215 | carry=bn_sub_words(rp,ap,bp,min); | ||
| 216 | ap+=min; | ||
| 217 | bp+=min; | ||
| 218 | rp+=min; | ||
| 219 | i=min; | ||
| 220 | #endif | ||
| 221 | if (carry) /* subtracted */ | ||
| 222 | { | ||
| 223 | while (i < max) | ||
| 224 | { | ||
| 225 | i++; | ||
| 226 | t1= *(ap++); | ||
| 227 | t2=(t1-1)&BN_MASK2; | ||
| 228 | *(rp++)=t2; | ||
| 229 | if (t1 > t2) break; | ||
| 230 | } | ||
| 231 | } | ||
| 232 | #if 0 | ||
| 233 | memcpy(rp,ap,sizeof(*rp)*(max-i)); | ||
| 234 | #else | ||
| 235 | if (rp != ap) | ||
| 236 | { | ||
| 237 | for (;;) | ||
| 238 | { | ||
| 239 | if (i++ >= max) break; | ||
| 240 | rp[0]=ap[0]; | ||
| 241 | if (i++ >= max) break; | ||
| 242 | rp[1]=ap[1]; | ||
| 243 | if (i++ >= max) break; | ||
| 244 | rp[2]=ap[2]; | ||
| 245 | if (i++ >= max) break; | ||
| 246 | rp[3]=ap[3]; | ||
| 247 | rp+=4; | ||
| 248 | ap+=4; | ||
| 249 | } | ||
| 250 | } | ||
| 251 | #endif | ||
| 252 | |||
| 253 | r->top=max; | ||
| 254 | bn_fix_top(r); | ||
| 255 | return(1); | ||
| 256 | } | ||
| 257 | |||
| 258 | int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) | ||
| 259 | { | ||
| 260 | int max; | ||
| 261 | int add=0,neg=0; | ||
| 262 | const BIGNUM *tmp; | ||
| 263 | |||
| 264 | bn_check_top(a); | ||
| 265 | bn_check_top(b); | ||
| 266 | |||
| 267 | /* a - b a-b | ||
| 268 | * a - -b a+b | ||
| 269 | * -a - b -(a+b) | ||
| 270 | * -a - -b b-a | ||
| 271 | */ | ||
| 272 | if (a->neg) | ||
| 273 | { | ||
| 274 | if (b->neg) | ||
| 275 | { tmp=a; a=b; b=tmp; } | ||
| 276 | else | ||
| 277 | { add=1; neg=1; } | ||
| 278 | } | ||
| 279 | else | ||
| 280 | { | ||
| 281 | if (b->neg) { add=1; neg=0; } | ||
| 282 | } | ||
| 283 | |||
| 284 | if (add) | ||
| 285 | { | ||
| 286 | if (!BN_uadd(r,a,b)) return(0); | ||
| 287 | r->neg=neg; | ||
| 288 | return(1); | ||
| 289 | } | ||
| 290 | |||
| 291 | /* We are actually doing a - b :-) */ | ||
| 292 | |||
| 293 | max=(a->top > b->top)?a->top:b->top; | ||
| 294 | if (bn_wexpand(r,max) == NULL) return(0); | ||
| 295 | if (BN_ucmp(a,b) < 0) | ||
| 296 | { | ||
| 297 | if (!BN_usub(r,b,a)) return(0); | ||
| 298 | r->neg=1; | ||
| 299 | } | ||
| 300 | else | ||
| 301 | { | ||
| 302 | if (!BN_usub(r,a,b)) return(0); | ||
| 303 | r->neg=0; | ||
| 304 | } | ||
| 305 | return(1); | ||
| 306 | } | ||
| 307 | |||
diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c deleted file mode 100644 index 4d3da16a0c..0000000000 --- a/src/lib/libcrypto/bn/bn_asm.c +++ /dev/null | |||
| @@ -1,802 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_asm.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | #ifdef BN_LLONG | ||
| 64 | |||
| 65 | BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) | ||
| 66 | { | ||
| 67 | BN_ULONG c1=0; | ||
| 68 | |||
| 69 | bn_check_num(num); | ||
| 70 | if (num <= 0) return(c1); | ||
| 71 | |||
| 72 | for (;;) | ||
| 73 | { | ||
| 74 | mul_add(rp[0],ap[0],w,c1); | ||
| 75 | if (--num == 0) break; | ||
| 76 | mul_add(rp[1],ap[1],w,c1); | ||
| 77 | if (--num == 0) break; | ||
| 78 | mul_add(rp[2],ap[2],w,c1); | ||
| 79 | if (--num == 0) break; | ||
| 80 | mul_add(rp[3],ap[3],w,c1); | ||
| 81 | if (--num == 0) break; | ||
| 82 | ap+=4; | ||
| 83 | rp+=4; | ||
| 84 | } | ||
| 85 | |||
| 86 | return(c1); | ||
| 87 | } | ||
| 88 | |||
| 89 | BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) | ||
| 90 | { | ||
| 91 | BN_ULONG c1=0; | ||
| 92 | |||
| 93 | bn_check_num(num); | ||
| 94 | if (num <= 0) return(c1); | ||
| 95 | |||
| 96 | /* for (;;) */ | ||
| 97 | while (1) /* circumvent egcs-1.1.2 bug */ | ||
| 98 | { | ||
| 99 | mul(rp[0],ap[0],w,c1); | ||
| 100 | if (--num == 0) break; | ||
| 101 | mul(rp[1],ap[1],w,c1); | ||
| 102 | if (--num == 0) break; | ||
| 103 | mul(rp[2],ap[2],w,c1); | ||
| 104 | if (--num == 0) break; | ||
| 105 | mul(rp[3],ap[3],w,c1); | ||
| 106 | if (--num == 0) break; | ||
| 107 | ap+=4; | ||
| 108 | rp+=4; | ||
| 109 | } | ||
| 110 | return(c1); | ||
| 111 | } | ||
| 112 | |||
| 113 | void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n) | ||
| 114 | { | ||
| 115 | bn_check_num(n); | ||
| 116 | if (n <= 0) return; | ||
| 117 | for (;;) | ||
| 118 | { | ||
| 119 | BN_ULLONG t; | ||
| 120 | |||
| 121 | t=(BN_ULLONG)(a[0])*(a[0]); | ||
| 122 | r[0]=Lw(t); r[1]=Hw(t); | ||
| 123 | if (--n == 0) break; | ||
| 124 | |||
| 125 | t=(BN_ULLONG)(a[1])*(a[1]); | ||
| 126 | r[2]=Lw(t); r[3]=Hw(t); | ||
| 127 | if (--n == 0) break; | ||
| 128 | |||
| 129 | t=(BN_ULLONG)(a[2])*(a[2]); | ||
| 130 | r[4]=Lw(t); r[5]=Hw(t); | ||
| 131 | if (--n == 0) break; | ||
| 132 | |||
| 133 | t=(BN_ULLONG)(a[3])*(a[3]); | ||
| 134 | r[6]=Lw(t); r[7]=Hw(t); | ||
| 135 | if (--n == 0) break; | ||
| 136 | |||
| 137 | a+=4; | ||
| 138 | r+=8; | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | #else | ||
| 143 | |||
| 144 | BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) | ||
| 145 | { | ||
| 146 | BN_ULONG c=0; | ||
| 147 | BN_ULONG bl,bh; | ||
| 148 | |||
| 149 | bn_check_num(num); | ||
| 150 | if (num <= 0) return((BN_ULONG)0); | ||
| 151 | |||
| 152 | bl=LBITS(w); | ||
| 153 | bh=HBITS(w); | ||
| 154 | |||
| 155 | for (;;) | ||
| 156 | { | ||
| 157 | mul_add(rp[0],ap[0],bl,bh,c); | ||
| 158 | if (--num == 0) break; | ||
| 159 | mul_add(rp[1],ap[1],bl,bh,c); | ||
| 160 | if (--num == 0) break; | ||
| 161 | mul_add(rp[2],ap[2],bl,bh,c); | ||
| 162 | if (--num == 0) break; | ||
| 163 | mul_add(rp[3],ap[3],bl,bh,c); | ||
| 164 | if (--num == 0) break; | ||
| 165 | ap+=4; | ||
| 166 | rp+=4; | ||
| 167 | } | ||
| 168 | return(c); | ||
| 169 | } | ||
| 170 | |||
| 171 | BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) | ||
| 172 | { | ||
| 173 | BN_ULONG carry=0; | ||
| 174 | BN_ULONG bl,bh; | ||
| 175 | |||
| 176 | bn_check_num(num); | ||
| 177 | if (num <= 0) return((BN_ULONG)0); | ||
| 178 | |||
| 179 | bl=LBITS(w); | ||
| 180 | bh=HBITS(w); | ||
| 181 | |||
| 182 | for (;;) | ||
| 183 | { | ||
| 184 | mul(rp[0],ap[0],bl,bh,carry); | ||
| 185 | if (--num == 0) break; | ||
| 186 | mul(rp[1],ap[1],bl,bh,carry); | ||
| 187 | if (--num == 0) break; | ||
| 188 | mul(rp[2],ap[2],bl,bh,carry); | ||
| 189 | if (--num == 0) break; | ||
| 190 | mul(rp[3],ap[3],bl,bh,carry); | ||
| 191 | if (--num == 0) break; | ||
| 192 | ap+=4; | ||
| 193 | rp+=4; | ||
| 194 | } | ||
| 195 | return(carry); | ||
| 196 | } | ||
| 197 | |||
| 198 | void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n) | ||
| 199 | { | ||
| 200 | bn_check_num(n); | ||
| 201 | if (n <= 0) return; | ||
| 202 | for (;;) | ||
| 203 | { | ||
| 204 | sqr64(r[0],r[1],a[0]); | ||
| 205 | if (--n == 0) break; | ||
| 206 | |||
| 207 | sqr64(r[2],r[3],a[1]); | ||
| 208 | if (--n == 0) break; | ||
| 209 | |||
| 210 | sqr64(r[4],r[5],a[2]); | ||
| 211 | if (--n == 0) break; | ||
| 212 | |||
| 213 | sqr64(r[6],r[7],a[3]); | ||
| 214 | if (--n == 0) break; | ||
| 215 | |||
| 216 | a+=4; | ||
| 217 | r+=8; | ||
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | #endif | ||
| 222 | |||
| 223 | #if defined(BN_LLONG) && defined(BN_DIV2W) | ||
| 224 | |||
| 225 | BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d) | ||
| 226 | { | ||
| 227 | return((BN_ULONG)(((((BN_ULLONG)h)<<BN_BITS2)|l)/(BN_ULLONG)d)); | ||
| 228 | } | ||
| 229 | |||
| 230 | #else | ||
| 231 | |||
| 232 | /* Divide h-l by d and return the result. */ | ||
| 233 | /* I need to test this some more :-( */ | ||
| 234 | BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d) | ||
| 235 | { | ||
| 236 | BN_ULONG dh,dl,q,ret=0,th,tl,t; | ||
| 237 | int i,count=2; | ||
| 238 | |||
| 239 | if (d == 0) return(BN_MASK2); | ||
| 240 | |||
| 241 | i=BN_num_bits_word(d); | ||
| 242 | if ((i != BN_BITS2) && (h > (BN_ULONG)1<<i)) | ||
| 243 | { | ||
| 244 | #if !defined(NO_STDIO) && !defined(WIN16) | ||
| 245 | fprintf(stderr,"Division would overflow (%d)\n",i); | ||
| 246 | #endif | ||
| 247 | abort(); | ||
| 248 | } | ||
| 249 | i=BN_BITS2-i; | ||
| 250 | if (h >= d) h-=d; | ||
| 251 | |||
| 252 | if (i) | ||
| 253 | { | ||
| 254 | d<<=i; | ||
| 255 | h=(h<<i)|(l>>(BN_BITS2-i)); | ||
| 256 | l<<=i; | ||
| 257 | } | ||
| 258 | dh=(d&BN_MASK2h)>>BN_BITS4; | ||
| 259 | dl=(d&BN_MASK2l); | ||
| 260 | for (;;) | ||
| 261 | { | ||
| 262 | if ((h>>BN_BITS4) == dh) | ||
| 263 | q=BN_MASK2l; | ||
| 264 | else | ||
| 265 | q=h/dh; | ||
| 266 | |||
| 267 | th=q*dh; | ||
| 268 | tl=dl*q; | ||
| 269 | for (;;) | ||
| 270 | { | ||
| 271 | t=h-th; | ||
| 272 | if ((t&BN_MASK2h) || | ||
| 273 | ((tl) <= ( | ||
| 274 | (t<<BN_BITS4)| | ||
| 275 | ((l&BN_MASK2h)>>BN_BITS4)))) | ||
| 276 | break; | ||
| 277 | q--; | ||
| 278 | th-=dh; | ||
| 279 | tl-=dl; | ||
| 280 | } | ||
| 281 | t=(tl>>BN_BITS4); | ||
| 282 | tl=(tl<<BN_BITS4)&BN_MASK2h; | ||
| 283 | th+=t; | ||
| 284 | |||
| 285 | if (l < tl) th++; | ||
| 286 | l-=tl; | ||
| 287 | if (h < th) | ||
| 288 | { | ||
| 289 | h+=d; | ||
| 290 | q--; | ||
| 291 | } | ||
| 292 | h-=th; | ||
| 293 | |||
| 294 | if (--count == 0) break; | ||
| 295 | |||
| 296 | ret=q<<BN_BITS4; | ||
| 297 | h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2; | ||
| 298 | l=(l&BN_MASK2l)<<BN_BITS4; | ||
| 299 | } | ||
| 300 | ret|=q; | ||
| 301 | return(ret); | ||
| 302 | } | ||
| 303 | #endif | ||
| 304 | |||
| 305 | #ifdef BN_LLONG | ||
| 306 | BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) | ||
| 307 | { | ||
| 308 | BN_ULLONG ll=0; | ||
| 309 | |||
| 310 | bn_check_num(n); | ||
| 311 | if (n <= 0) return((BN_ULONG)0); | ||
| 312 | |||
| 313 | for (;;) | ||
| 314 | { | ||
| 315 | ll+=(BN_ULLONG)a[0]+b[0]; | ||
| 316 | r[0]=(BN_ULONG)ll&BN_MASK2; | ||
| 317 | ll>>=BN_BITS2; | ||
| 318 | if (--n <= 0) break; | ||
| 319 | |||
| 320 | ll+=(BN_ULLONG)a[1]+b[1]; | ||
| 321 | r[1]=(BN_ULONG)ll&BN_MASK2; | ||
| 322 | ll>>=BN_BITS2; | ||
| 323 | if (--n <= 0) break; | ||
| 324 | |||
| 325 | ll+=(BN_ULLONG)a[2]+b[2]; | ||
| 326 | r[2]=(BN_ULONG)ll&BN_MASK2; | ||
| 327 | ll>>=BN_BITS2; | ||
| 328 | if (--n <= 0) break; | ||
| 329 | |||
| 330 | ll+=(BN_ULLONG)a[3]+b[3]; | ||
| 331 | r[3]=(BN_ULONG)ll&BN_MASK2; | ||
| 332 | ll>>=BN_BITS2; | ||
| 333 | if (--n <= 0) break; | ||
| 334 | |||
| 335 | a+=4; | ||
| 336 | b+=4; | ||
| 337 | r+=4; | ||
| 338 | } | ||
| 339 | return((BN_ULONG)ll); | ||
| 340 | } | ||
| 341 | #else | ||
| 342 | BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) | ||
| 343 | { | ||
| 344 | BN_ULONG c,l,t; | ||
| 345 | |||
| 346 | bn_check_num(n); | ||
| 347 | if (n <= 0) return((BN_ULONG)0); | ||
| 348 | |||
| 349 | c=0; | ||
| 350 | for (;;) | ||
| 351 | { | ||
| 352 | t=a[0]; | ||
| 353 | t=(t+c)&BN_MASK2; | ||
| 354 | c=(t < c); | ||
| 355 | l=(t+b[0])&BN_MASK2; | ||
| 356 | c+=(l < t); | ||
| 357 | r[0]=l; | ||
| 358 | if (--n <= 0) break; | ||
| 359 | |||
| 360 | t=a[1]; | ||
| 361 | t=(t+c)&BN_MASK2; | ||
| 362 | c=(t < c); | ||
| 363 | l=(t+b[1])&BN_MASK2; | ||
| 364 | c+=(l < t); | ||
| 365 | r[1]=l; | ||
| 366 | if (--n <= 0) break; | ||
| 367 | |||
| 368 | t=a[2]; | ||
| 369 | t=(t+c)&BN_MASK2; | ||
| 370 | c=(t < c); | ||
| 371 | l=(t+b[2])&BN_MASK2; | ||
| 372 | c+=(l < t); | ||
| 373 | r[2]=l; | ||
| 374 | if (--n <= 0) break; | ||
| 375 | |||
| 376 | t=a[3]; | ||
| 377 | t=(t+c)&BN_MASK2; | ||
| 378 | c=(t < c); | ||
| 379 | l=(t+b[3])&BN_MASK2; | ||
| 380 | c+=(l < t); | ||
| 381 | r[3]=l; | ||
| 382 | if (--n <= 0) break; | ||
| 383 | |||
| 384 | a+=4; | ||
| 385 | b+=4; | ||
| 386 | r+=4; | ||
| 387 | } | ||
| 388 | return((BN_ULONG)c); | ||
| 389 | } | ||
| 390 | #endif | ||
| 391 | |||
| 392 | BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) | ||
| 393 | { | ||
| 394 | BN_ULONG t1,t2; | ||
| 395 | int c=0; | ||
| 396 | |||
| 397 | bn_check_num(n); | ||
| 398 | if (n <= 0) return((BN_ULONG)0); | ||
| 399 | |||
| 400 | for (;;) | ||
| 401 | { | ||
| 402 | t1=a[0]; t2=b[0]; | ||
| 403 | r[0]=(t1-t2-c)&BN_MASK2; | ||
| 404 | if (t1 != t2) c=(t1 < t2); | ||
| 405 | if (--n <= 0) break; | ||
| 406 | |||
| 407 | t1=a[1]; t2=b[1]; | ||
| 408 | r[1]=(t1-t2-c)&BN_MASK2; | ||
| 409 | if (t1 != t2) c=(t1 < t2); | ||
| 410 | if (--n <= 0) break; | ||
| 411 | |||
| 412 | t1=a[2]; t2=b[2]; | ||
| 413 | r[2]=(t1-t2-c)&BN_MASK2; | ||
| 414 | if (t1 != t2) c=(t1 < t2); | ||
| 415 | if (--n <= 0) break; | ||
| 416 | |||
| 417 | t1=a[3]; t2=b[3]; | ||
| 418 | r[3]=(t1-t2-c)&BN_MASK2; | ||
| 419 | if (t1 != t2) c=(t1 < t2); | ||
| 420 | if (--n <= 0) break; | ||
| 421 | |||
| 422 | a+=4; | ||
| 423 | b+=4; | ||
| 424 | r+=4; | ||
| 425 | } | ||
| 426 | return(c); | ||
| 427 | } | ||
| 428 | |||
| 429 | #ifdef BN_MUL_COMBA | ||
| 430 | |||
| 431 | #undef bn_mul_comba8 | ||
| 432 | #undef bn_mul_comba4 | ||
| 433 | #undef bn_sqr_comba8 | ||
| 434 | #undef bn_sqr_comba4 | ||
| 435 | |||
| 436 | #ifdef BN_LLONG | ||
| 437 | #define mul_add_c(a,b,c0,c1,c2) \ | ||
| 438 | t=(BN_ULLONG)a*b; \ | ||
| 439 | t1=(BN_ULONG)Lw(t); \ | ||
| 440 | t2=(BN_ULONG)Hw(t); \ | ||
| 441 | c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ | ||
| 442 | c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; | ||
| 443 | |||
| 444 | #define mul_add_c2(a,b,c0,c1,c2) \ | ||
| 445 | t=(BN_ULLONG)a*b; \ | ||
| 446 | tt=(t+t)&BN_MASK; \ | ||
| 447 | if (tt < t) c2++; \ | ||
| 448 | t1=(BN_ULONG)Lw(tt); \ | ||
| 449 | t2=(BN_ULONG)Hw(tt); \ | ||
| 450 | c0=(c0+t1)&BN_MASK2; \ | ||
| 451 | if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \ | ||
| 452 | c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; | ||
| 453 | |||
| 454 | #define sqr_add_c(a,i,c0,c1,c2) \ | ||
| 455 | t=(BN_ULLONG)a[i]*a[i]; \ | ||
| 456 | t1=(BN_ULONG)Lw(t); \ | ||
| 457 | t2=(BN_ULONG)Hw(t); \ | ||
| 458 | c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ | ||
| 459 | c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; | ||
| 460 | |||
| 461 | #define sqr_add_c2(a,i,j,c0,c1,c2) \ | ||
| 462 | mul_add_c2((a)[i],(a)[j],c0,c1,c2) | ||
| 463 | #else | ||
| 464 | #define mul_add_c(a,b,c0,c1,c2) \ | ||
| 465 | t1=LBITS(a); t2=HBITS(a); \ | ||
| 466 | bl=LBITS(b); bh=HBITS(b); \ | ||
| 467 | mul64(t1,t2,bl,bh); \ | ||
| 468 | c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ | ||
| 469 | c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; | ||
| 470 | |||
| 471 | #define mul_add_c2(a,b,c0,c1,c2) \ | ||
| 472 | t1=LBITS(a); t2=HBITS(a); \ | ||
| 473 | bl=LBITS(b); bh=HBITS(b); \ | ||
| 474 | mul64(t1,t2,bl,bh); \ | ||
| 475 | if (t2 & BN_TBIT) c2++; \ | ||
| 476 | t2=(t2+t2)&BN_MASK2; \ | ||
| 477 | if (t1 & BN_TBIT) t2++; \ | ||
| 478 | t1=(t1+t1)&BN_MASK2; \ | ||
| 479 | c0=(c0+t1)&BN_MASK2; \ | ||
| 480 | if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \ | ||
| 481 | c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; | ||
| 482 | |||
| 483 | #define sqr_add_c(a,i,c0,c1,c2) \ | ||
| 484 | sqr64(t1,t2,(a)[i]); \ | ||
| 485 | c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ | ||
| 486 | c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; | ||
| 487 | |||
| 488 | #define sqr_add_c2(a,i,j,c0,c1,c2) \ | ||
| 489 | mul_add_c2((a)[i],(a)[j],c0,c1,c2) | ||
| 490 | #endif | ||
| 491 | |||
| 492 | void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) | ||
| 493 | { | ||
| 494 | #ifdef BN_LLONG | ||
| 495 | BN_ULLONG t; | ||
| 496 | #else | ||
| 497 | BN_ULONG bl,bh; | ||
| 498 | #endif | ||
| 499 | BN_ULONG t1,t2; | ||
| 500 | BN_ULONG c1,c2,c3; | ||
| 501 | |||
| 502 | c1=0; | ||
| 503 | c2=0; | ||
| 504 | c3=0; | ||
| 505 | mul_add_c(a[0],b[0],c1,c2,c3); | ||
| 506 | r[0]=c1; | ||
| 507 | c1=0; | ||
| 508 | mul_add_c(a[0],b[1],c2,c3,c1); | ||
| 509 | mul_add_c(a[1],b[0],c2,c3,c1); | ||
| 510 | r[1]=c2; | ||
| 511 | c2=0; | ||
| 512 | mul_add_c(a[2],b[0],c3,c1,c2); | ||
| 513 | mul_add_c(a[1],b[1],c3,c1,c2); | ||
| 514 | mul_add_c(a[0],b[2],c3,c1,c2); | ||
| 515 | r[2]=c3; | ||
| 516 | c3=0; | ||
| 517 | mul_add_c(a[0],b[3],c1,c2,c3); | ||
| 518 | mul_add_c(a[1],b[2],c1,c2,c3); | ||
| 519 | mul_add_c(a[2],b[1],c1,c2,c3); | ||
| 520 | mul_add_c(a[3],b[0],c1,c2,c3); | ||
| 521 | r[3]=c1; | ||
| 522 | c1=0; | ||
| 523 | mul_add_c(a[4],b[0],c2,c3,c1); | ||
| 524 | mul_add_c(a[3],b[1],c2,c3,c1); | ||
| 525 | mul_add_c(a[2],b[2],c2,c3,c1); | ||
| 526 | mul_add_c(a[1],b[3],c2,c3,c1); | ||
| 527 | mul_add_c(a[0],b[4],c2,c3,c1); | ||
| 528 | r[4]=c2; | ||
| 529 | c2=0; | ||
| 530 | mul_add_c(a[0],b[5],c3,c1,c2); | ||
| 531 | mul_add_c(a[1],b[4],c3,c1,c2); | ||
| 532 | mul_add_c(a[2],b[3],c3,c1,c2); | ||
| 533 | mul_add_c(a[3],b[2],c3,c1,c2); | ||
| 534 | mul_add_c(a[4],b[1],c3,c1,c2); | ||
| 535 | mul_add_c(a[5],b[0],c3,c1,c2); | ||
| 536 | r[5]=c3; | ||
| 537 | c3=0; | ||
| 538 | mul_add_c(a[6],b[0],c1,c2,c3); | ||
| 539 | mul_add_c(a[5],b[1],c1,c2,c3); | ||
| 540 | mul_add_c(a[4],b[2],c1,c2,c3); | ||
| 541 | mul_add_c(a[3],b[3],c1,c2,c3); | ||
| 542 | mul_add_c(a[2],b[4],c1,c2,c3); | ||
| 543 | mul_add_c(a[1],b[5],c1,c2,c3); | ||
| 544 | mul_add_c(a[0],b[6],c1,c2,c3); | ||
| 545 | r[6]=c1; | ||
| 546 | c1=0; | ||
| 547 | mul_add_c(a[0],b[7],c2,c3,c1); | ||
| 548 | mul_add_c(a[1],b[6],c2,c3,c1); | ||
| 549 | mul_add_c(a[2],b[5],c2,c3,c1); | ||
| 550 | mul_add_c(a[3],b[4],c2,c3,c1); | ||
| 551 | mul_add_c(a[4],b[3],c2,c3,c1); | ||
| 552 | mul_add_c(a[5],b[2],c2,c3,c1); | ||
| 553 | mul_add_c(a[6],b[1],c2,c3,c1); | ||
| 554 | mul_add_c(a[7],b[0],c2,c3,c1); | ||
| 555 | r[7]=c2; | ||
| 556 | c2=0; | ||
| 557 | mul_add_c(a[7],b[1],c3,c1,c2); | ||
| 558 | mul_add_c(a[6],b[2],c3,c1,c2); | ||
| 559 | mul_add_c(a[5],b[3],c3,c1,c2); | ||
| 560 | mul_add_c(a[4],b[4],c3,c1,c2); | ||
| 561 | mul_add_c(a[3],b[5],c3,c1,c2); | ||
| 562 | mul_add_c(a[2],b[6],c3,c1,c2); | ||
| 563 | mul_add_c(a[1],b[7],c3,c1,c2); | ||
| 564 | r[8]=c3; | ||
| 565 | c3=0; | ||
| 566 | mul_add_c(a[2],b[7],c1,c2,c3); | ||
| 567 | mul_add_c(a[3],b[6],c1,c2,c3); | ||
| 568 | mul_add_c(a[4],b[5],c1,c2,c3); | ||
| 569 | mul_add_c(a[5],b[4],c1,c2,c3); | ||
| 570 | mul_add_c(a[6],b[3],c1,c2,c3); | ||
| 571 | mul_add_c(a[7],b[2],c1,c2,c3); | ||
| 572 | r[9]=c1; | ||
| 573 | c1=0; | ||
| 574 | mul_add_c(a[7],b[3],c2,c3,c1); | ||
| 575 | mul_add_c(a[6],b[4],c2,c3,c1); | ||
| 576 | mul_add_c(a[5],b[5],c2,c3,c1); | ||
| 577 | mul_add_c(a[4],b[6],c2,c3,c1); | ||
| 578 | mul_add_c(a[3],b[7],c2,c3,c1); | ||
| 579 | r[10]=c2; | ||
| 580 | c2=0; | ||
| 581 | mul_add_c(a[4],b[7],c3,c1,c2); | ||
| 582 | mul_add_c(a[5],b[6],c3,c1,c2); | ||
| 583 | mul_add_c(a[6],b[5],c3,c1,c2); | ||
| 584 | mul_add_c(a[7],b[4],c3,c1,c2); | ||
| 585 | r[11]=c3; | ||
| 586 | c3=0; | ||
| 587 | mul_add_c(a[7],b[5],c1,c2,c3); | ||
| 588 | mul_add_c(a[6],b[6],c1,c2,c3); | ||
| 589 | mul_add_c(a[5],b[7],c1,c2,c3); | ||
| 590 | r[12]=c1; | ||
| 591 | c1=0; | ||
| 592 | mul_add_c(a[6],b[7],c2,c3,c1); | ||
| 593 | mul_add_c(a[7],b[6],c2,c3,c1); | ||
| 594 | r[13]=c2; | ||
| 595 | c2=0; | ||
| 596 | mul_add_c(a[7],b[7],c3,c1,c2); | ||
| 597 | r[14]=c3; | ||
| 598 | r[15]=c1; | ||
| 599 | } | ||
| 600 | |||
| 601 | void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) | ||
| 602 | { | ||
| 603 | #ifdef BN_LLONG | ||
| 604 | BN_ULLONG t; | ||
| 605 | #else | ||
| 606 | BN_ULONG bl,bh; | ||
| 607 | #endif | ||
| 608 | BN_ULONG t1,t2; | ||
| 609 | BN_ULONG c1,c2,c3; | ||
| 610 | |||
| 611 | c1=0; | ||
| 612 | c2=0; | ||
| 613 | c3=0; | ||
| 614 | mul_add_c(a[0],b[0],c1,c2,c3); | ||
| 615 | r[0]=c1; | ||
| 616 | c1=0; | ||
| 617 | mul_add_c(a[0],b[1],c2,c3,c1); | ||
| 618 | mul_add_c(a[1],b[0],c2,c3,c1); | ||
| 619 | r[1]=c2; | ||
| 620 | c2=0; | ||
| 621 | mul_add_c(a[2],b[0],c3,c1,c2); | ||
| 622 | mul_add_c(a[1],b[1],c3,c1,c2); | ||
| 623 | mul_add_c(a[0],b[2],c3,c1,c2); | ||
| 624 | r[2]=c3; | ||
| 625 | c3=0; | ||
| 626 | mul_add_c(a[0],b[3],c1,c2,c3); | ||
| 627 | mul_add_c(a[1],b[2],c1,c2,c3); | ||
| 628 | mul_add_c(a[2],b[1],c1,c2,c3); | ||
| 629 | mul_add_c(a[3],b[0],c1,c2,c3); | ||
| 630 | r[3]=c1; | ||
| 631 | c1=0; | ||
| 632 | mul_add_c(a[3],b[1],c2,c3,c1); | ||
| 633 | mul_add_c(a[2],b[2],c2,c3,c1); | ||
| 634 | mul_add_c(a[1],b[3],c2,c3,c1); | ||
| 635 | r[4]=c2; | ||
| 636 | c2=0; | ||
| 637 | mul_add_c(a[2],b[3],c3,c1,c2); | ||
| 638 | mul_add_c(a[3],b[2],c3,c1,c2); | ||
| 639 | r[5]=c3; | ||
| 640 | c3=0; | ||
| 641 | mul_add_c(a[3],b[3],c1,c2,c3); | ||
| 642 | r[6]=c1; | ||
| 643 | r[7]=c2; | ||
| 644 | } | ||
| 645 | |||
| 646 | void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a) | ||
| 647 | { | ||
| 648 | #ifdef BN_LLONG | ||
| 649 | BN_ULLONG t,tt; | ||
| 650 | #else | ||
| 651 | BN_ULONG bl,bh; | ||
| 652 | #endif | ||
| 653 | BN_ULONG t1,t2; | ||
| 654 | BN_ULONG c1,c2,c3; | ||
| 655 | |||
| 656 | c1=0; | ||
| 657 | c2=0; | ||
| 658 | c3=0; | ||
| 659 | sqr_add_c(a,0,c1,c2,c3); | ||
| 660 | r[0]=c1; | ||
| 661 | c1=0; | ||
| 662 | sqr_add_c2(a,1,0,c2,c3,c1); | ||
| 663 | r[1]=c2; | ||
| 664 | c2=0; | ||
| 665 | sqr_add_c(a,1,c3,c1,c2); | ||
| 666 | sqr_add_c2(a,2,0,c3,c1,c2); | ||
| 667 | r[2]=c3; | ||
| 668 | c3=0; | ||
| 669 | sqr_add_c2(a,3,0,c1,c2,c3); | ||
| 670 | sqr_add_c2(a,2,1,c1,c2,c3); | ||
| 671 | r[3]=c1; | ||
| 672 | c1=0; | ||
| 673 | sqr_add_c(a,2,c2,c3,c1); | ||
| 674 | sqr_add_c2(a,3,1,c2,c3,c1); | ||
| 675 | sqr_add_c2(a,4,0,c2,c3,c1); | ||
| 676 | r[4]=c2; | ||
| 677 | c2=0; | ||
| 678 | sqr_add_c2(a,5,0,c3,c1,c2); | ||
| 679 | sqr_add_c2(a,4,1,c3,c1,c2); | ||
| 680 | sqr_add_c2(a,3,2,c3,c1,c2); | ||
| 681 | r[5]=c3; | ||
| 682 | c3=0; | ||
| 683 | sqr_add_c(a,3,c1,c2,c3); | ||
| 684 | sqr_add_c2(a,4,2,c1,c2,c3); | ||
| 685 | sqr_add_c2(a,5,1,c1,c2,c3); | ||
| 686 | sqr_add_c2(a,6,0,c1,c2,c3); | ||
| 687 | r[6]=c1; | ||
| 688 | c1=0; | ||
| 689 | sqr_add_c2(a,7,0,c2,c3,c1); | ||
| 690 | sqr_add_c2(a,6,1,c2,c3,c1); | ||
| 691 | sqr_add_c2(a,5,2,c2,c3,c1); | ||
| 692 | sqr_add_c2(a,4,3,c2,c3,c1); | ||
| 693 | r[7]=c2; | ||
| 694 | c2=0; | ||
| 695 | sqr_add_c(a,4,c3,c1,c2); | ||
| 696 | sqr_add_c2(a,5,3,c3,c1,c2); | ||
| 697 | sqr_add_c2(a,6,2,c3,c1,c2); | ||
| 698 | sqr_add_c2(a,7,1,c3,c1,c2); | ||
| 699 | r[8]=c3; | ||
| 700 | c3=0; | ||
| 701 | sqr_add_c2(a,7,2,c1,c2,c3); | ||
| 702 | sqr_add_c2(a,6,3,c1,c2,c3); | ||
| 703 | sqr_add_c2(a,5,4,c1,c2,c3); | ||
| 704 | r[9]=c1; | ||
| 705 | c1=0; | ||
| 706 | sqr_add_c(a,5,c2,c3,c1); | ||
| 707 | sqr_add_c2(a,6,4,c2,c3,c1); | ||
| 708 | sqr_add_c2(a,7,3,c2,c3,c1); | ||
| 709 | r[10]=c2; | ||
| 710 | c2=0; | ||
| 711 | sqr_add_c2(a,7,4,c3,c1,c2); | ||
| 712 | sqr_add_c2(a,6,5,c3,c1,c2); | ||
| 713 | r[11]=c3; | ||
| 714 | c3=0; | ||
| 715 | sqr_add_c(a,6,c1,c2,c3); | ||
| 716 | sqr_add_c2(a,7,5,c1,c2,c3); | ||
| 717 | r[12]=c1; | ||
| 718 | c1=0; | ||
| 719 | sqr_add_c2(a,7,6,c2,c3,c1); | ||
| 720 | r[13]=c2; | ||
| 721 | c2=0; | ||
| 722 | sqr_add_c(a,7,c3,c1,c2); | ||
| 723 | r[14]=c3; | ||
| 724 | r[15]=c1; | ||
| 725 | } | ||
| 726 | |||
| 727 | void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a) | ||
| 728 | { | ||
| 729 | #ifdef BN_LLONG | ||
| 730 | BN_ULLONG t,tt; | ||
| 731 | #else | ||
| 732 | BN_ULONG bl,bh; | ||
| 733 | #endif | ||
| 734 | BN_ULONG t1,t2; | ||
| 735 | BN_ULONG c1,c2,c3; | ||
| 736 | |||
| 737 | c1=0; | ||
| 738 | c2=0; | ||
| 739 | c3=0; | ||
| 740 | sqr_add_c(a,0,c1,c2,c3); | ||
| 741 | r[0]=c1; | ||
| 742 | c1=0; | ||
| 743 | sqr_add_c2(a,1,0,c2,c3,c1); | ||
| 744 | r[1]=c2; | ||
| 745 | c2=0; | ||
| 746 | sqr_add_c(a,1,c3,c1,c2); | ||
| 747 | sqr_add_c2(a,2,0,c3,c1,c2); | ||
| 748 | r[2]=c3; | ||
| 749 | c3=0; | ||
| 750 | sqr_add_c2(a,3,0,c1,c2,c3); | ||
| 751 | sqr_add_c2(a,2,1,c1,c2,c3); | ||
| 752 | r[3]=c1; | ||
| 753 | c1=0; | ||
| 754 | sqr_add_c(a,2,c2,c3,c1); | ||
| 755 | sqr_add_c2(a,3,1,c2,c3,c1); | ||
| 756 | r[4]=c2; | ||
| 757 | c2=0; | ||
| 758 | sqr_add_c2(a,3,2,c3,c1,c2); | ||
| 759 | r[5]=c3; | ||
| 760 | c3=0; | ||
| 761 | sqr_add_c(a,3,c1,c2,c3); | ||
| 762 | r[6]=c1; | ||
| 763 | r[7]=c2; | ||
| 764 | } | ||
| 765 | #else | ||
| 766 | |||
| 767 | /* hmm... is it faster just to do a multiply? */ | ||
| 768 | #undef bn_sqr_comba4 | ||
| 769 | void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a) | ||
| 770 | { | ||
| 771 | BN_ULONG t[8]; | ||
| 772 | bn_sqr_normal(r,a,4,t); | ||
| 773 | } | ||
| 774 | |||
| 775 | #undef bn_sqr_comba8 | ||
| 776 | void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a) | ||
| 777 | { | ||
| 778 | BN_ULONG t[16]; | ||
| 779 | bn_sqr_normal(r,a,8,t); | ||
| 780 | } | ||
| 781 | |||
| 782 | void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) | ||
| 783 | { | ||
| 784 | r[4]=bn_mul_words( &(r[0]),a,4,b[0]); | ||
| 785 | r[5]=bn_mul_add_words(&(r[1]),a,4,b[1]); | ||
| 786 | r[6]=bn_mul_add_words(&(r[2]),a,4,b[2]); | ||
| 787 | r[7]=bn_mul_add_words(&(r[3]),a,4,b[3]); | ||
| 788 | } | ||
| 789 | |||
| 790 | void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) | ||
| 791 | { | ||
| 792 | r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]); | ||
| 793 | r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]); | ||
| 794 | r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]); | ||
| 795 | r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]); | ||
| 796 | r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]); | ||
| 797 | r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]); | ||
| 798 | r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]); | ||
| 799 | r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]); | ||
| 800 | } | ||
| 801 | |||
| 802 | #endif /* BN_COMBA */ | ||
diff --git a/src/lib/libcrypto/bn/bn_blind.c b/src/lib/libcrypto/bn/bn_blind.c deleted file mode 100644 index 1b1bb06046..0000000000 --- a/src/lib/libcrypto/bn/bn_blind.c +++ /dev/null | |||
| @@ -1,144 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_blind.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | BN_BLINDING *BN_BLINDING_new(BIGNUM *A, BIGNUM *Ai, BIGNUM *mod) | ||
| 64 | { | ||
| 65 | BN_BLINDING *ret=NULL; | ||
| 66 | |||
| 67 | bn_check_top(Ai); | ||
| 68 | bn_check_top(mod); | ||
| 69 | |||
| 70 | if ((ret=(BN_BLINDING *)Malloc(sizeof(BN_BLINDING))) == NULL) | ||
| 71 | { | ||
| 72 | BNerr(BN_F_BN_BLINDING_NEW,ERR_R_MALLOC_FAILURE); | ||
| 73 | return(NULL); | ||
| 74 | } | ||
| 75 | memset(ret,0,sizeof(BN_BLINDING)); | ||
| 76 | if ((ret->A=BN_new()) == NULL) goto err; | ||
| 77 | if ((ret->Ai=BN_new()) == NULL) goto err; | ||
| 78 | if (!BN_copy(ret->A,A)) goto err; | ||
| 79 | if (!BN_copy(ret->Ai,Ai)) goto err; | ||
| 80 | ret->mod=mod; | ||
| 81 | return(ret); | ||
| 82 | err: | ||
| 83 | if (ret != NULL) BN_BLINDING_free(ret); | ||
| 84 | return(NULL); | ||
| 85 | } | ||
| 86 | |||
| 87 | void BN_BLINDING_free(BN_BLINDING *r) | ||
| 88 | { | ||
| 89 | if(r == NULL) | ||
| 90 | return; | ||
| 91 | |||
| 92 | if (r->A != NULL) BN_free(r->A ); | ||
| 93 | if (r->Ai != NULL) BN_free(r->Ai); | ||
| 94 | Free(r); | ||
| 95 | } | ||
| 96 | |||
| 97 | int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx) | ||
| 98 | { | ||
| 99 | int ret=0; | ||
| 100 | |||
| 101 | if ((b->A == NULL) || (b->Ai == NULL)) | ||
| 102 | { | ||
| 103 | BNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITIALIZED); | ||
| 104 | goto err; | ||
| 105 | } | ||
| 106 | |||
| 107 | if (!BN_mod_mul(b->A,b->A,b->A,b->mod,ctx)) goto err; | ||
| 108 | if (!BN_mod_mul(b->Ai,b->Ai,b->Ai,b->mod,ctx)) goto err; | ||
| 109 | |||
| 110 | ret=1; | ||
| 111 | err: | ||
| 112 | return(ret); | ||
| 113 | } | ||
| 114 | |||
| 115 | int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx) | ||
| 116 | { | ||
| 117 | bn_check_top(n); | ||
| 118 | |||
| 119 | if ((b->A == NULL) || (b->Ai == NULL)) | ||
| 120 | { | ||
| 121 | BNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITIALIZED); | ||
| 122 | return(0); | ||
| 123 | } | ||
| 124 | return(BN_mod_mul(n,n,b->A,b->mod,ctx)); | ||
| 125 | } | ||
| 126 | |||
| 127 | int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx) | ||
| 128 | { | ||
| 129 | int ret; | ||
| 130 | |||
| 131 | bn_check_top(n); | ||
| 132 | if ((b->A == NULL) || (b->Ai == NULL)) | ||
| 133 | { | ||
| 134 | BNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITIALIZED); | ||
| 135 | return(0); | ||
| 136 | } | ||
| 137 | if ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0) | ||
| 138 | { | ||
| 139 | if (!BN_BLINDING_update(b,ctx)) | ||
| 140 | return(0); | ||
| 141 | } | ||
| 142 | return(ret); | ||
| 143 | } | ||
| 144 | |||
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c deleted file mode 100644 index 150dd289a5..0000000000 --- a/src/lib/libcrypto/bn/bn_div.c +++ /dev/null | |||
| @@ -1,358 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_div.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <openssl/bn.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "bn_lcl.h" | ||
| 63 | |||
| 64 | /* The old slow way */ | ||
| 65 | #if 0 | ||
| 66 | int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx) | ||
| 67 | { | ||
| 68 | int i,nm,nd; | ||
| 69 | BIGNUM *D; | ||
| 70 | |||
| 71 | bn_check_top(m); | ||
| 72 | bn_check_top(d); | ||
| 73 | if (BN_is_zero(d)) | ||
| 74 | { | ||
| 75 | BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); | ||
| 76 | return(0); | ||
| 77 | } | ||
| 78 | |||
| 79 | if (BN_ucmp(m,d) < 0) | ||
| 80 | { | ||
| 81 | if (rem != NULL) | ||
| 82 | { if (BN_copy(rem,m) == NULL) return(0); } | ||
| 83 | if (dv != NULL) BN_zero(dv); | ||
| 84 | return(1); | ||
| 85 | } | ||
| 86 | |||
| 87 | D= &(ctx->bn[ctx->tos]); | ||
| 88 | if (dv == NULL) dv= &(ctx->bn[ctx->tos+1]); | ||
| 89 | if (rem == NULL) rem= &(ctx->bn[ctx->tos+2]); | ||
| 90 | |||
| 91 | nd=BN_num_bits(d); | ||
| 92 | nm=BN_num_bits(m); | ||
| 93 | if (BN_copy(D,d) == NULL) return(0); | ||
| 94 | if (BN_copy(rem,m) == NULL) return(0); | ||
| 95 | |||
| 96 | /* The next 2 are needed so we can do a dv->d[0]|=1 later | ||
| 97 | * since BN_lshift1 will only work once there is a value :-) */ | ||
| 98 | BN_zero(dv); | ||
| 99 | bn_wexpand(dv,1); | ||
| 100 | dv->top=1; | ||
| 101 | |||
| 102 | if (!BN_lshift(D,D,nm-nd)) return(0); | ||
| 103 | for (i=nm-nd; i>=0; i--) | ||
| 104 | { | ||
| 105 | if (!BN_lshift1(dv,dv)) return(0); | ||
| 106 | if (BN_ucmp(rem,D) >= 0) | ||
| 107 | { | ||
| 108 | dv->d[0]|=1; | ||
| 109 | if (!BN_usub(rem,rem,D)) return(0); | ||
| 110 | } | ||
| 111 | /* CAN IMPROVE (and have now :=) */ | ||
| 112 | if (!BN_rshift1(D,D)) return(0); | ||
| 113 | } | ||
| 114 | rem->neg=BN_is_zero(rem)?0:m->neg; | ||
| 115 | dv->neg=m->neg^d->neg; | ||
| 116 | return(1); | ||
| 117 | } | ||
| 118 | |||
| 119 | #else | ||
| 120 | |||
| 121 | int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, | ||
| 122 | BN_CTX *ctx) | ||
| 123 | { | ||
| 124 | int norm_shift,i,j,loop; | ||
| 125 | BIGNUM *tmp,wnum,*snum,*sdiv,*res; | ||
| 126 | BN_ULONG *resp,*wnump; | ||
| 127 | BN_ULONG d0,d1; | ||
| 128 | int num_n,div_n; | ||
| 129 | |||
| 130 | bn_check_top(num); | ||
| 131 | bn_check_top(divisor); | ||
| 132 | |||
| 133 | if (BN_is_zero(divisor)) | ||
| 134 | { | ||
| 135 | BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); | ||
| 136 | return(0); | ||
| 137 | } | ||
| 138 | |||
| 139 | if (BN_ucmp(num,divisor) < 0) | ||
| 140 | { | ||
| 141 | if (rm != NULL) | ||
| 142 | { if (BN_copy(rm,num) == NULL) return(0); } | ||
| 143 | if (dv != NULL) BN_zero(dv); | ||
| 144 | return(1); | ||
| 145 | } | ||
| 146 | |||
| 147 | tmp= &(ctx->bn[ctx->tos]); | ||
| 148 | tmp->neg=0; | ||
| 149 | snum= &(ctx->bn[ctx->tos+1]); | ||
| 150 | sdiv= &(ctx->bn[ctx->tos+2]); | ||
| 151 | if (dv == NULL) | ||
| 152 | res= &(ctx->bn[ctx->tos+3]); | ||
| 153 | else res=dv; | ||
| 154 | |||
| 155 | /* First we normalise the numbers */ | ||
| 156 | norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2); | ||
| 157 | BN_lshift(sdiv,divisor,norm_shift); | ||
| 158 | sdiv->neg=0; | ||
| 159 | norm_shift+=BN_BITS2; | ||
| 160 | BN_lshift(snum,num,norm_shift); | ||
| 161 | snum->neg=0; | ||
| 162 | div_n=sdiv->top; | ||
| 163 | num_n=snum->top; | ||
| 164 | loop=num_n-div_n; | ||
| 165 | |||
| 166 | /* Lets setup a 'window' into snum | ||
| 167 | * This is the part that corresponds to the current | ||
| 168 | * 'area' being divided */ | ||
| 169 | BN_init(&wnum); | ||
| 170 | wnum.d= &(snum->d[loop]); | ||
| 171 | wnum.top= div_n; | ||
| 172 | wnum.max= snum->max+1; /* a bit of a lie */ | ||
| 173 | |||
| 174 | /* Get the top 2 words of sdiv */ | ||
| 175 | /* i=sdiv->top; */ | ||
| 176 | d0=sdiv->d[div_n-1]; | ||
| 177 | d1=(div_n == 1)?0:sdiv->d[div_n-2]; | ||
| 178 | |||
| 179 | /* pointer to the 'top' of snum */ | ||
| 180 | wnump= &(snum->d[num_n-1]); | ||
| 181 | |||
| 182 | /* Setup to 'res' */ | ||
| 183 | res->neg= (num->neg^divisor->neg); | ||
| 184 | if (!bn_wexpand(res,(loop+1))) goto err; | ||
| 185 | res->top=loop; | ||
| 186 | resp= &(res->d[loop-1]); | ||
| 187 | |||
| 188 | /* space for temp */ | ||
| 189 | if (!bn_wexpand(tmp,(div_n+1))) goto err; | ||
| 190 | |||
| 191 | if (BN_ucmp(&wnum,sdiv) >= 0) | ||
| 192 | { | ||
| 193 | if (!BN_usub(&wnum,&wnum,sdiv)) goto err; | ||
| 194 | *resp=1; | ||
| 195 | res->d[res->top-1]=1; | ||
| 196 | } | ||
| 197 | else | ||
| 198 | res->top--; | ||
| 199 | resp--; | ||
| 200 | |||
| 201 | for (i=0; i<loop-1; i++) | ||
| 202 | { | ||
| 203 | BN_ULONG q,l0; | ||
| 204 | #ifdef BN_DIV3W | ||
| 205 | q=bn_div_3_words(wnump,d0,d1); | ||
| 206 | #else | ||
| 207 | |||
| 208 | #if !defined(NO_ASM) && !defined(PEDANTIC) | ||
| 209 | # if defined(__GNUC__) && __GNUC__>=2 | ||
| 210 | # if defined(__i386) | ||
| 211 | /* | ||
| 212 | * There were two reasons for implementing this template: | ||
| 213 | * - GNU C generates a call to a function (__udivdi3 to be exact) | ||
| 214 | * in reply to ((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0 (I fail to | ||
| 215 | * understand why...); | ||
| 216 | * - divl doesn't only calculate quotient, but also leaves | ||
| 217 | * remainder in %edx which we can definitely use here:-) | ||
| 218 | * | ||
| 219 | * <appro@fy.chalmers.se> | ||
| 220 | */ | ||
| 221 | # define bn_div_words(n0,n1,d0) \ | ||
| 222 | ({ asm volatile ( \ | ||
| 223 | "divl %4" \ | ||
| 224 | : "=a"(q), "=d"(rem) \ | ||
| 225 | : "a"(n1), "d"(n0), "g"(d0) \ | ||
| 226 | : "cc"); \ | ||
| 227 | q; \ | ||
| 228 | }) | ||
| 229 | # define REMINDER_IS_ALREADY_CALCULATED | ||
| 230 | # endif /* __<cpu> */ | ||
| 231 | # endif /* __GNUC__ */ | ||
| 232 | #endif /* NO_ASM */ | ||
| 233 | BN_ULONG n0,n1,rem=0; | ||
| 234 | |||
| 235 | n0=wnump[0]; | ||
| 236 | n1=wnump[-1]; | ||
| 237 | if (n0 == d0) | ||
| 238 | q=BN_MASK2; | ||
| 239 | else | ||
| 240 | #if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words) | ||
| 241 | q=((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0; | ||
| 242 | #else | ||
| 243 | q=bn_div_words(n0,n1,d0); | ||
| 244 | #endif | ||
| 245 | { | ||
| 246 | #ifdef BN_LLONG | ||
| 247 | BN_ULLONG t2; | ||
| 248 | |||
| 249 | #ifndef REMINDER_IS_ALREADY_CALCULATED | ||
| 250 | /* | ||
| 251 | * rem doesn't have to be BN_ULLONG. The least we | ||
| 252 | * know it's less that d0, isn't it? | ||
| 253 | */ | ||
| 254 | rem=(n1-q*d0)&BN_MASK2; | ||
| 255 | #endif | ||
| 256 | t2=(BN_ULLONG)d1*q; | ||
| 257 | |||
| 258 | for (;;) | ||
| 259 | { | ||
| 260 | if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2])) | ||
| 261 | break; | ||
| 262 | q--; | ||
| 263 | rem += d0; | ||
| 264 | if (rem < d0) break; /* don't let rem overflow */ | ||
| 265 | t2 -= d1; | ||
| 266 | } | ||
| 267 | #else | ||
| 268 | BN_ULONG t2l,t2h,ql,qh; | ||
| 269 | |||
| 270 | #ifndef REMINDER_IS_ALREADY_CALCULATED | ||
| 271 | /* | ||
| 272 | * It's more than enough with the only multiplication. | ||
| 273 | * See the comment above in BN_LLONG section... | ||
| 274 | */ | ||
| 275 | rem=(n1-q*d0)&BN_MASK2; | ||
| 276 | #endif | ||
| 277 | t2l=LBITS(d1); t2h=HBITS(d1); | ||
| 278 | ql =LBITS(q); qh =HBITS(q); | ||
| 279 | mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */ | ||
| 280 | |||
| 281 | for (;;) | ||
| 282 | { | ||
| 283 | if ((t2h < rem) || | ||
| 284 | ((t2h == rem) && (t2l <= wnump[-2]))) | ||
| 285 | break; | ||
| 286 | q--; | ||
| 287 | rem += d0; | ||
| 288 | if (rem < d0) break; /* don't let rem overflow */ | ||
| 289 | if (t2l < d1) t2h--; t2l -= d1; | ||
| 290 | } | ||
| 291 | #endif | ||
| 292 | } | ||
| 293 | #endif /* !BN_DIV3W */ | ||
| 294 | wnum.d--; wnum.top++; | ||
| 295 | l0=bn_mul_words(tmp->d,sdiv->d,div_n,q); | ||
| 296 | tmp->d[div_n]=l0; | ||
| 297 | for (j=div_n+1; j>0; j--) | ||
| 298 | if (tmp->d[j-1]) break; | ||
| 299 | tmp->top=j; | ||
| 300 | |||
| 301 | j=wnum.top; | ||
| 302 | BN_sub(&wnum,&wnum,tmp); | ||
| 303 | |||
| 304 | snum->top=snum->top+wnum.top-j; | ||
| 305 | |||
| 306 | if (wnum.neg) | ||
| 307 | { | ||
| 308 | q--; | ||
| 309 | j=wnum.top; | ||
| 310 | BN_add(&wnum,&wnum,sdiv); | ||
| 311 | snum->top+=wnum.top-j; | ||
| 312 | } | ||
| 313 | *(resp--)=q; | ||
| 314 | wnump--; | ||
| 315 | } | ||
| 316 | if (rm != NULL) | ||
| 317 | { | ||
| 318 | BN_rshift(rm,snum,norm_shift); | ||
| 319 | rm->neg=num->neg; | ||
| 320 | } | ||
| 321 | return(1); | ||
| 322 | err: | ||
| 323 | return(0); | ||
| 324 | } | ||
| 325 | |||
| 326 | #endif | ||
| 327 | |||
| 328 | /* rem != m */ | ||
| 329 | int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) | ||
| 330 | { | ||
| 331 | #if 0 /* The old slow way */ | ||
| 332 | int i,nm,nd; | ||
| 333 | BIGNUM *dv; | ||
| 334 | |||
| 335 | if (BN_ucmp(m,d) < 0) | ||
| 336 | return((BN_copy(rem,m) == NULL)?0:1); | ||
| 337 | |||
| 338 | dv= &(ctx->bn[ctx->tos]); | ||
| 339 | |||
| 340 | if (!BN_copy(rem,m)) return(0); | ||
| 341 | |||
| 342 | nm=BN_num_bits(rem); | ||
| 343 | nd=BN_num_bits(d); | ||
| 344 | if (!BN_lshift(dv,d,nm-nd)) return(0); | ||
| 345 | for (i=nm-nd; i>=0; i--) | ||
| 346 | { | ||
| 347 | if (BN_cmp(rem,dv) >= 0) | ||
| 348 | { | ||
| 349 | if (!BN_sub(rem,rem,dv)) return(0); | ||
| 350 | } | ||
| 351 | if (!BN_rshift1(dv,dv)) return(0); | ||
| 352 | } | ||
| 353 | return(1); | ||
| 354 | #else | ||
| 355 | return(BN_div(NULL,rem,m,d,ctx)); | ||
| 356 | #endif | ||
| 357 | } | ||
| 358 | |||
diff --git a/src/lib/libcrypto/bn/bn_err.c b/src/lib/libcrypto/bn/bn_err.c deleted file mode 100644 index 73e80774e5..0000000000 --- a/src/lib/libcrypto/bn/bn_err.c +++ /dev/null | |||
| @@ -1,116 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_err.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file. | ||
| 58 | */ | ||
| 59 | |||
| 60 | #include <stdio.h> | ||
| 61 | #include <openssl/err.h> | ||
| 62 | #include <openssl/bn.h> | ||
| 63 | |||
| 64 | /* BEGIN ERROR CODES */ | ||
| 65 | #ifndef NO_ERR | ||
| 66 | static ERR_STRING_DATA BN_str_functs[]= | ||
| 67 | { | ||
| 68 | {ERR_PACK(0,BN_F_BN_BLINDING_CONVERT,0), "BN_BLINDING_convert"}, | ||
| 69 | {ERR_PACK(0,BN_F_BN_BLINDING_INVERT,0), "BN_BLINDING_invert"}, | ||
| 70 | {ERR_PACK(0,BN_F_BN_BLINDING_NEW,0), "BN_BLINDING_new"}, | ||
| 71 | {ERR_PACK(0,BN_F_BN_BLINDING_UPDATE,0), "BN_BLINDING_update"}, | ||
| 72 | {ERR_PACK(0,BN_F_BN_BN2DEC,0), "BN_bn2dec"}, | ||
| 73 | {ERR_PACK(0,BN_F_BN_BN2HEX,0), "BN_bn2hex"}, | ||
| 74 | {ERR_PACK(0,BN_F_BN_CTX_NEW,0), "BN_CTX_new"}, | ||
| 75 | {ERR_PACK(0,BN_F_BN_DIV,0), "BN_div"}, | ||
| 76 | {ERR_PACK(0,BN_F_BN_EXPAND2,0), "bn_expand2"}, | ||
| 77 | {ERR_PACK(0,BN_F_BN_MOD_EXP_MONT,0), "BN_mod_exp_mont"}, | ||
| 78 | {ERR_PACK(0,BN_F_BN_MOD_INVERSE,0), "BN_mod_inverse"}, | ||
| 79 | {ERR_PACK(0,BN_F_BN_MOD_MUL_RECIPROCAL,0), "BN_mod_mul_reciprocal"}, | ||
| 80 | {ERR_PACK(0,BN_F_BN_MPI2BN,0), "BN_mpi2bn"}, | ||
| 81 | {ERR_PACK(0,BN_F_BN_NEW,0), "BN_new"}, | ||
| 82 | {ERR_PACK(0,BN_F_BN_RAND,0), "BN_rand"}, | ||
| 83 | {ERR_PACK(0,BN_F_BN_USUB,0), "BN_usub"}, | ||
| 84 | {0,NULL} | ||
| 85 | }; | ||
| 86 | |||
| 87 | static ERR_STRING_DATA BN_str_reasons[]= | ||
| 88 | { | ||
| 89 | {BN_R_ARG2_LT_ARG3 ,"arg2 lt arg3"}, | ||
| 90 | {BN_R_BAD_RECIPROCAL ,"bad reciprocal"}, | ||
| 91 | {BN_R_CALLED_WITH_EVEN_MODULUS ,"called with even modulus"}, | ||
| 92 | {BN_R_DIV_BY_ZERO ,"div by zero"}, | ||
| 93 | {BN_R_ENCODING_ERROR ,"encoding error"}, | ||
| 94 | {BN_R_EXPAND_ON_STATIC_BIGNUM_DATA ,"expand on static bignum data"}, | ||
| 95 | {BN_R_INVALID_LENGTH ,"invalid length"}, | ||
| 96 | {BN_R_NOT_INITIALIZED ,"not initialized"}, | ||
| 97 | {BN_R_NO_INVERSE ,"no inverse"}, | ||
| 98 | {0,NULL} | ||
| 99 | }; | ||
| 100 | |||
| 101 | #endif | ||
| 102 | |||
| 103 | void ERR_load_BN_strings(void) | ||
| 104 | { | ||
| 105 | static int init=1; | ||
| 106 | |||
| 107 | if (init) | ||
| 108 | { | ||
| 109 | init=0; | ||
| 110 | #ifndef NO_ERR | ||
| 111 | ERR_load_strings(ERR_LIB_BN,BN_str_functs); | ||
| 112 | ERR_load_strings(ERR_LIB_BN,BN_str_reasons); | ||
| 113 | #endif | ||
| 114 | |||
| 115 | } | ||
| 116 | } | ||
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c deleted file mode 100644 index 2df1614ada..0000000000 --- a/src/lib/libcrypto/bn/bn_exp.c +++ /dev/null | |||
| @@ -1,549 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_exp.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | #define TABLE_SIZE 16 | ||
| 64 | |||
| 65 | /* slow but works */ | ||
| 66 | int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx) | ||
| 67 | { | ||
| 68 | BIGNUM *t; | ||
| 69 | int r=0; | ||
| 70 | |||
| 71 | bn_check_top(a); | ||
| 72 | bn_check_top(b); | ||
| 73 | bn_check_top(m); | ||
| 74 | |||
| 75 | t= &(ctx->bn[ctx->tos++]); | ||
| 76 | if (a == b) | ||
| 77 | { if (!BN_sqr(t,a,ctx)) goto err; } | ||
| 78 | else | ||
| 79 | { if (!BN_mul(t,a,b,ctx)) goto err; } | ||
| 80 | if (!BN_mod(ret,t,m,ctx)) goto err; | ||
| 81 | r=1; | ||
| 82 | err: | ||
| 83 | ctx->tos--; | ||
| 84 | return(r); | ||
| 85 | } | ||
| 86 | |||
| 87 | #if 0 | ||
| 88 | /* this one works - simple but works */ | ||
| 89 | int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx) | ||
| 90 | { | ||
| 91 | int i,bits,ret=0; | ||
| 92 | BIGNUM *v,*tmp; | ||
| 93 | |||
| 94 | v= &(ctx->bn[ctx->tos++]); | ||
| 95 | tmp= &(ctx->bn[ctx->tos++]); | ||
| 96 | |||
| 97 | if (BN_copy(v,a) == NULL) goto err; | ||
| 98 | bits=BN_num_bits(p); | ||
| 99 | |||
| 100 | if (BN_is_odd(p)) | ||
| 101 | { if (BN_copy(r,a) == NULL) goto err; } | ||
| 102 | else { if (!BN_one(r)) goto err; } | ||
| 103 | |||
| 104 | for (i=1; i<bits; i++) | ||
| 105 | { | ||
| 106 | if (!BN_sqr(tmp,v,ctx)) goto err; | ||
| 107 | if (!BN_mod(v,tmp,m,ctx)) goto err; | ||
| 108 | if (BN_is_bit_set(p,i)) | ||
| 109 | { | ||
| 110 | if (!BN_mul(tmp,r,v,ctx)) goto err; | ||
| 111 | if (!BN_mod(r,tmp,m,ctx)) goto err; | ||
| 112 | } | ||
| 113 | } | ||
| 114 | ret=1; | ||
| 115 | err: | ||
| 116 | ctx->tos-=2; | ||
| 117 | return(ret); | ||
| 118 | } | ||
| 119 | |||
| 120 | #endif | ||
| 121 | |||
| 122 | /* this one works - simple but works */ | ||
| 123 | int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx) | ||
| 124 | { | ||
| 125 | int i,bits,ret=0,tos; | ||
| 126 | BIGNUM *v,*rr; | ||
| 127 | |||
| 128 | tos=ctx->tos; | ||
| 129 | v= &(ctx->bn[ctx->tos++]); | ||
| 130 | if ((r == a) || (r == p)) | ||
| 131 | rr= &(ctx->bn[ctx->tos++]); | ||
| 132 | else | ||
| 133 | rr=r; | ||
| 134 | |||
| 135 | if (BN_copy(v,a) == NULL) goto err; | ||
| 136 | bits=BN_num_bits(p); | ||
| 137 | |||
| 138 | if (BN_is_odd(p)) | ||
| 139 | { if (BN_copy(rr,a) == NULL) goto err; } | ||
| 140 | else { if (!BN_one(rr)) goto err; } | ||
| 141 | |||
| 142 | for (i=1; i<bits; i++) | ||
| 143 | { | ||
| 144 | if (!BN_sqr(v,v,ctx)) goto err; | ||
| 145 | if (BN_is_bit_set(p,i)) | ||
| 146 | { | ||
| 147 | if (!BN_mul(rr,rr,v,ctx)) goto err; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | ret=1; | ||
| 151 | err: | ||
| 152 | ctx->tos=tos; | ||
| 153 | if (r != rr) BN_copy(r,rr); | ||
| 154 | return(ret); | ||
| 155 | } | ||
| 156 | |||
| 157 | int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m, | ||
| 158 | BN_CTX *ctx) | ||
| 159 | { | ||
| 160 | int ret; | ||
| 161 | |||
| 162 | bn_check_top(a); | ||
| 163 | bn_check_top(p); | ||
| 164 | bn_check_top(m); | ||
| 165 | |||
| 166 | #ifdef MONT_MUL_MOD | ||
| 167 | /* I have finally been able to take out this pre-condition of | ||
| 168 | * the top bit being set. It was caused by an error in BN_div | ||
| 169 | * with negatives. There was also another problem when for a^b%m | ||
| 170 | * a >= m. eay 07-May-97 */ | ||
| 171 | /* if ((m->d[m->top-1]&BN_TBIT) && BN_is_odd(m)) */ | ||
| 172 | |||
| 173 | if (BN_is_odd(m)) | ||
| 174 | { ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL); } | ||
| 175 | else | ||
| 176 | #endif | ||
| 177 | #ifdef RECP_MUL_MOD | ||
| 178 | { ret=BN_mod_exp_recp(r,a,p,m,ctx); } | ||
| 179 | #else | ||
| 180 | { ret=BN_mod_exp_simple(r,a,p,m,ctx); } | ||
| 181 | #endif | ||
| 182 | |||
| 183 | return(ret); | ||
| 184 | } | ||
| 185 | |||
| 186 | /* #ifdef RECP_MUL_MOD */ | ||
| 187 | int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, | ||
| 188 | const BIGNUM *m, BN_CTX *ctx) | ||
| 189 | { | ||
| 190 | int i,j,bits,ret=0,wstart,wend,window,wvalue; | ||
| 191 | int start=1,ts=0; | ||
| 192 | BIGNUM *aa; | ||
| 193 | BIGNUM val[TABLE_SIZE]; | ||
| 194 | BN_RECP_CTX recp; | ||
| 195 | |||
| 196 | aa= &(ctx->bn[ctx->tos++]); | ||
| 197 | bits=BN_num_bits(p); | ||
| 198 | |||
| 199 | if (bits == 0) | ||
| 200 | { | ||
| 201 | BN_one(r); | ||
| 202 | return(1); | ||
| 203 | } | ||
| 204 | BN_RECP_CTX_init(&recp); | ||
| 205 | if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err; | ||
| 206 | |||
| 207 | BN_init(&(val[0])); | ||
| 208 | ts=1; | ||
| 209 | |||
| 210 | if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */ | ||
| 211 | if (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx)) | ||
| 212 | goto err; /* 2 */ | ||
| 213 | |||
| 214 | if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */ | ||
| 215 | window=1; | ||
| 216 | else if (bits >= 256) | ||
| 217 | window=5; /* max size of window */ | ||
| 218 | else if (bits >= 128) | ||
| 219 | window=4; | ||
| 220 | else | ||
| 221 | window=3; | ||
| 222 | |||
| 223 | j=1<<(window-1); | ||
| 224 | for (i=1; i<j; i++) | ||
| 225 | { | ||
| 226 | BN_init(&val[i]); | ||
| 227 | if (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx)) | ||
| 228 | goto err; | ||
| 229 | } | ||
| 230 | ts=i; | ||
| 231 | |||
| 232 | start=1; /* This is used to avoid multiplication etc | ||
| 233 | * when there is only the value '1' in the | ||
| 234 | * buffer. */ | ||
| 235 | wvalue=0; /* The 'value' of the window */ | ||
| 236 | wstart=bits-1; /* The top bit of the window */ | ||
| 237 | wend=0; /* The bottom bit of the window */ | ||
| 238 | |||
| 239 | if (!BN_one(r)) goto err; | ||
| 240 | |||
| 241 | for (;;) | ||
| 242 | { | ||
| 243 | if (BN_is_bit_set(p,wstart) == 0) | ||
| 244 | { | ||
| 245 | if (!start) | ||
| 246 | if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx)) | ||
| 247 | goto err; | ||
| 248 | if (wstart == 0) break; | ||
| 249 | wstart--; | ||
| 250 | continue; | ||
| 251 | } | ||
| 252 | /* We now have wstart on a 'set' bit, we now need to work out | ||
| 253 | * how bit a window to do. To do this we need to scan | ||
| 254 | * forward until the last set bit before the end of the | ||
| 255 | * window */ | ||
| 256 | j=wstart; | ||
| 257 | wvalue=1; | ||
| 258 | wend=0; | ||
| 259 | for (i=1; i<window; i++) | ||
| 260 | { | ||
| 261 | if (wstart-i < 0) break; | ||
| 262 | if (BN_is_bit_set(p,wstart-i)) | ||
| 263 | { | ||
| 264 | wvalue<<=(i-wend); | ||
| 265 | wvalue|=1; | ||
| 266 | wend=i; | ||
| 267 | } | ||
| 268 | } | ||
| 269 | |||
| 270 | /* wend is the size of the current window */ | ||
| 271 | j=wend+1; | ||
| 272 | /* add the 'bytes above' */ | ||
| 273 | if (!start) | ||
| 274 | for (i=0; i<j; i++) | ||
| 275 | { | ||
| 276 | if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx)) | ||
| 277 | goto err; | ||
| 278 | } | ||
| 279 | |||
| 280 | /* wvalue will be an odd number < 2^window */ | ||
| 281 | if (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx)) | ||
| 282 | goto err; | ||
| 283 | |||
| 284 | /* move the 'window' down further */ | ||
| 285 | wstart-=wend+1; | ||
| 286 | wvalue=0; | ||
| 287 | start=0; | ||
| 288 | if (wstart < 0) break; | ||
| 289 | } | ||
| 290 | ret=1; | ||
| 291 | err: | ||
| 292 | ctx->tos--; | ||
| 293 | for (i=0; i<ts; i++) | ||
| 294 | BN_clear_free(&(val[i])); | ||
| 295 | BN_RECP_CTX_free(&recp); | ||
| 296 | return(ret); | ||
| 297 | } | ||
| 298 | /* #endif */ | ||
| 299 | |||
| 300 | /* #ifdef MONT_MUL_MOD */ | ||
| 301 | int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, const BIGNUM *p, | ||
| 302 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
| 303 | { | ||
| 304 | int i,j,bits,ret=0,wstart,wend,window,wvalue; | ||
| 305 | int start=1,ts=0; | ||
| 306 | BIGNUM *d,*r; | ||
| 307 | BIGNUM *aa; | ||
| 308 | BIGNUM val[TABLE_SIZE]; | ||
| 309 | BN_MONT_CTX *mont=NULL; | ||
| 310 | |||
| 311 | bn_check_top(a); | ||
| 312 | bn_check_top(p); | ||
| 313 | bn_check_top(m); | ||
| 314 | |||
| 315 | if (!(m->d[0] & 1)) | ||
| 316 | { | ||
| 317 | BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); | ||
| 318 | return(0); | ||
| 319 | } | ||
| 320 | d= &(ctx->bn[ctx->tos++]); | ||
| 321 | r= &(ctx->bn[ctx->tos++]); | ||
| 322 | bits=BN_num_bits(p); | ||
| 323 | if (bits == 0) | ||
| 324 | { | ||
| 325 | BN_one(r); | ||
| 326 | return(1); | ||
| 327 | } | ||
| 328 | |||
| 329 | /* If this is not done, things will break in the montgomery | ||
| 330 | * part */ | ||
| 331 | |||
| 332 | #if 1 | ||
| 333 | if (in_mont != NULL) | ||
| 334 | mont=in_mont; | ||
| 335 | else | ||
| 336 | #endif | ||
| 337 | { | ||
| 338 | if ((mont=BN_MONT_CTX_new()) == NULL) goto err; | ||
| 339 | if (!BN_MONT_CTX_set(mont,m,ctx)) goto err; | ||
| 340 | } | ||
| 341 | |||
| 342 | BN_init(&val[0]); | ||
| 343 | ts=1; | ||
| 344 | if (BN_ucmp(a,m) >= 0) | ||
| 345 | { | ||
| 346 | BN_mod(&(val[0]),a,m,ctx); | ||
| 347 | aa= &(val[0]); | ||
| 348 | } | ||
| 349 | else | ||
| 350 | aa=a; | ||
| 351 | if (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err; /* 1 */ | ||
| 352 | if (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err; /* 2 */ | ||
| 353 | |||
| 354 | if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */ | ||
| 355 | window=1; | ||
| 356 | else if (bits >= 256) | ||
| 357 | window=5; /* max size of window */ | ||
| 358 | else if (bits >= 128) | ||
| 359 | window=4; | ||
| 360 | else | ||
| 361 | window=3; | ||
| 362 | |||
| 363 | j=1<<(window-1); | ||
| 364 | for (i=1; i<j; i++) | ||
| 365 | { | ||
| 366 | BN_init(&(val[i])); | ||
| 367 | if (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx)) | ||
| 368 | goto err; | ||
| 369 | } | ||
| 370 | ts=i; | ||
| 371 | |||
| 372 | start=1; /* This is used to avoid multiplication etc | ||
| 373 | * when there is only the value '1' in the | ||
| 374 | * buffer. */ | ||
| 375 | wvalue=0; /* The 'value' of the window */ | ||
| 376 | wstart=bits-1; /* The top bit of the window */ | ||
| 377 | wend=0; /* The bottom bit of the window */ | ||
| 378 | |||
| 379 | if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err; | ||
| 380 | for (;;) | ||
| 381 | { | ||
| 382 | if (BN_is_bit_set(p,wstart) == 0) | ||
| 383 | { | ||
| 384 | if (!start) | ||
| 385 | { | ||
| 386 | if (!BN_mod_mul_montgomery(r,r,r,mont,ctx)) | ||
| 387 | goto err; | ||
| 388 | } | ||
| 389 | if (wstart == 0) break; | ||
| 390 | wstart--; | ||
| 391 | continue; | ||
| 392 | } | ||
| 393 | /* We now have wstart on a 'set' bit, we now need to work out | ||
| 394 | * how bit a window to do. To do this we need to scan | ||
| 395 | * forward until the last set bit before the end of the | ||
| 396 | * window */ | ||
| 397 | j=wstart; | ||
| 398 | wvalue=1; | ||
| 399 | wend=0; | ||
| 400 | for (i=1; i<window; i++) | ||
| 401 | { | ||
| 402 | if (wstart-i < 0) break; | ||
| 403 | if (BN_is_bit_set(p,wstart-i)) | ||
| 404 | { | ||
| 405 | wvalue<<=(i-wend); | ||
| 406 | wvalue|=1; | ||
| 407 | wend=i; | ||
| 408 | } | ||
| 409 | } | ||
| 410 | |||
| 411 | /* wend is the size of the current window */ | ||
| 412 | j=wend+1; | ||
| 413 | /* add the 'bytes above' */ | ||
| 414 | if (!start) | ||
| 415 | for (i=0; i<j; i++) | ||
| 416 | { | ||
| 417 | if (!BN_mod_mul_montgomery(r,r,r,mont,ctx)) | ||
| 418 | goto err; | ||
| 419 | } | ||
| 420 | |||
| 421 | /* wvalue will be an odd number < 2^window */ | ||
| 422 | if (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx)) | ||
| 423 | goto err; | ||
| 424 | |||
| 425 | /* move the 'window' down further */ | ||
| 426 | wstart-=wend+1; | ||
| 427 | wvalue=0; | ||
| 428 | start=0; | ||
| 429 | if (wstart < 0) break; | ||
| 430 | } | ||
| 431 | BN_from_montgomery(rr,r,mont,ctx); | ||
| 432 | ret=1; | ||
| 433 | err: | ||
| 434 | if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); | ||
| 435 | ctx->tos-=2; | ||
| 436 | for (i=0; i<ts; i++) | ||
| 437 | BN_clear_free(&(val[i])); | ||
| 438 | return(ret); | ||
| 439 | } | ||
| 440 | /* #endif */ | ||
| 441 | |||
| 442 | /* The old fallback, simple version :-) */ | ||
| 443 | int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, | ||
| 444 | BN_CTX *ctx) | ||
| 445 | { | ||
| 446 | int i,j,bits,ret=0,wstart,wend,window,wvalue,ts=0; | ||
| 447 | int start=1; | ||
| 448 | BIGNUM *d; | ||
| 449 | BIGNUM val[TABLE_SIZE]; | ||
| 450 | |||
| 451 | d= &(ctx->bn[ctx->tos++]); | ||
| 452 | bits=BN_num_bits(p); | ||
| 453 | |||
| 454 | if (bits == 0) | ||
| 455 | { | ||
| 456 | BN_one(r); | ||
| 457 | return(1); | ||
| 458 | } | ||
| 459 | |||
| 460 | BN_init(&(val[0])); | ||
| 461 | ts=1; | ||
| 462 | if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */ | ||
| 463 | if (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx)) | ||
| 464 | goto err; /* 2 */ | ||
| 465 | |||
| 466 | if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */ | ||
| 467 | window=1; | ||
| 468 | else if (bits >= 256) | ||
| 469 | window=5; /* max size of window */ | ||
| 470 | else if (bits >= 128) | ||
| 471 | window=4; | ||
| 472 | else | ||
| 473 | window=3; | ||
| 474 | |||
| 475 | j=1<<(window-1); | ||
| 476 | for (i=1; i<j; i++) | ||
| 477 | { | ||
| 478 | BN_init(&(val[i])); | ||
| 479 | if (!BN_mod_mul(&(val[i]),&(val[i-1]),d,m,ctx)) | ||
| 480 | goto err; | ||
| 481 | } | ||
| 482 | ts=i; | ||
| 483 | |||
| 484 | start=1; /* This is used to avoid multiplication etc | ||
| 485 | * when there is only the value '1' in the | ||
| 486 | * buffer. */ | ||
| 487 | wvalue=0; /* The 'value' of the window */ | ||
| 488 | wstart=bits-1; /* The top bit of the window */ | ||
| 489 | wend=0; /* The bottom bit of the window */ | ||
| 490 | |||
| 491 | if (!BN_one(r)) goto err; | ||
| 492 | |||
| 493 | for (;;) | ||
| 494 | { | ||
| 495 | if (BN_is_bit_set(p,wstart) == 0) | ||
| 496 | { | ||
| 497 | if (!start) | ||
| 498 | if (!BN_mod_mul(r,r,r,m,ctx)) | ||
| 499 | goto err; | ||
| 500 | if (wstart == 0) break; | ||
| 501 | wstart--; | ||
| 502 | continue; | ||
| 503 | } | ||
| 504 | /* We now have wstart on a 'set' bit, we now need to work out | ||
| 505 | * how bit a window to do. To do this we need to scan | ||
| 506 | * forward until the last set bit before the end of the | ||
| 507 | * window */ | ||
| 508 | j=wstart; | ||
| 509 | wvalue=1; | ||
| 510 | wend=0; | ||
| 511 | for (i=1; i<window; i++) | ||
| 512 | { | ||
| 513 | if (wstart-i < 0) break; | ||
| 514 | if (BN_is_bit_set(p,wstart-i)) | ||
| 515 | { | ||
| 516 | wvalue<<=(i-wend); | ||
| 517 | wvalue|=1; | ||
| 518 | wend=i; | ||
| 519 | } | ||
| 520 | } | ||
| 521 | |||
| 522 | /* wend is the size of the current window */ | ||
| 523 | j=wend+1; | ||
| 524 | /* add the 'bytes above' */ | ||
| 525 | if (!start) | ||
| 526 | for (i=0; i<j; i++) | ||
| 527 | { | ||
| 528 | if (!BN_mod_mul(r,r,r,m,ctx)) | ||
| 529 | goto err; | ||
| 530 | } | ||
| 531 | |||
| 532 | /* wvalue will be an odd number < 2^window */ | ||
| 533 | if (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,ctx)) | ||
| 534 | goto err; | ||
| 535 | |||
| 536 | /* move the 'window' down further */ | ||
| 537 | wstart-=wend+1; | ||
| 538 | wvalue=0; | ||
| 539 | start=0; | ||
| 540 | if (wstart < 0) break; | ||
| 541 | } | ||
| 542 | ret=1; | ||
| 543 | err: | ||
| 544 | ctx->tos--; | ||
| 545 | for (i=0; i<ts; i++) | ||
| 546 | BN_clear_free(&(val[i])); | ||
| 547 | return(ret); | ||
| 548 | } | ||
| 549 | |||
diff --git a/src/lib/libcrypto/bn/bn_exp2.c b/src/lib/libcrypto/bn/bn_exp2.c deleted file mode 100644 index 1132d53365..0000000000 --- a/src/lib/libcrypto/bn/bn_exp2.c +++ /dev/null | |||
| @@ -1,195 +0,0 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include "cryptlib.h" | ||
| 3 | #include "bn_lcl.h" | ||
| 4 | |||
| 5 | /* I've done some timing with different table sizes. | ||
| 6 | * The main hassle is that even with bits set at 3, this requires | ||
| 7 | * 63 BIGNUMs to store the pre-calculated values. | ||
| 8 | * 512 1024 | ||
| 9 | * bits=1 75.4% 79.4% | ||
| 10 | * bits=2 61.2% 62.4% | ||
| 11 | * bits=3 61.3% 59.3% | ||
| 12 | * The lack of speed improvment is also a function of the pre-calculation | ||
| 13 | * which could be removed. | ||
| 14 | */ | ||
| 15 | #define EXP2_TABLE_BITS 2 /* 1 2 3 4 5 */ | ||
| 16 | #define EXP2_TABLE_SIZE 4 /* 2 4 8 16 32 */ | ||
| 17 | |||
| 18 | int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2, | ||
| 19 | BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont) | ||
| 20 | { | ||
| 21 | int i,j,k,bits,bits1,bits2,ret=0,wstart,wend,window,xvalue,yvalue; | ||
| 22 | int start=1,ts=0,x,y; | ||
| 23 | BIGNUM *d,*aa1,*aa2,*r; | ||
| 24 | BIGNUM val[EXP2_TABLE_SIZE][EXP2_TABLE_SIZE]; | ||
| 25 | BN_MONT_CTX *mont=NULL; | ||
| 26 | |||
| 27 | bn_check_top(a1); | ||
| 28 | bn_check_top(p1); | ||
| 29 | bn_check_top(a2); | ||
| 30 | bn_check_top(p2); | ||
| 31 | bn_check_top(m); | ||
| 32 | |||
| 33 | if (!(m->d[0] & 1)) | ||
| 34 | { | ||
| 35 | BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); | ||
| 36 | return(0); | ||
| 37 | } | ||
| 38 | d= &(ctx->bn[ctx->tos++]); | ||
| 39 | r= &(ctx->bn[ctx->tos++]); | ||
| 40 | bits1=BN_num_bits(p1); | ||
| 41 | bits2=BN_num_bits(p2); | ||
| 42 | if ((bits1 == 0) && (bits2 == 0)) | ||
| 43 | { | ||
| 44 | BN_one(r); | ||
| 45 | return(1); | ||
| 46 | } | ||
| 47 | bits=(bits1 > bits2)?bits1:bits2; | ||
| 48 | |||
| 49 | /* If this is not done, things will break in the montgomery | ||
| 50 | * part */ | ||
| 51 | |||
| 52 | if (in_mont != NULL) | ||
| 53 | mont=in_mont; | ||
| 54 | else | ||
| 55 | { | ||
| 56 | if ((mont=BN_MONT_CTX_new()) == NULL) goto err; | ||
| 57 | if (!BN_MONT_CTX_set(mont,m,ctx)) goto err; | ||
| 58 | } | ||
| 59 | |||
| 60 | BN_init(&(val[0][0])); | ||
| 61 | BN_init(&(val[1][1])); | ||
| 62 | BN_init(&(val[0][1])); | ||
| 63 | BN_init(&(val[1][0])); | ||
| 64 | ts=1; | ||
| 65 | if (BN_ucmp(a1,m) >= 0) | ||
| 66 | { | ||
| 67 | BN_mod(&(val[1][0]),a1,m,ctx); | ||
| 68 | aa1= &(val[1][0]); | ||
| 69 | } | ||
| 70 | else | ||
| 71 | aa1=a1; | ||
| 72 | if (BN_ucmp(a2,m) >= 0) | ||
| 73 | { | ||
| 74 | BN_mod(&(val[0][1]),a2,m,ctx); | ||
| 75 | aa2= &(val[0][1]); | ||
| 76 | } | ||
| 77 | else | ||
| 78 | aa2=a2; | ||
| 79 | if (!BN_to_montgomery(&(val[1][0]),aa1,mont,ctx)) goto err; | ||
| 80 | if (!BN_to_montgomery(&(val[0][1]),aa2,mont,ctx)) goto err; | ||
| 81 | if (!BN_mod_mul_montgomery(&(val[1][1]), | ||
| 82 | &(val[1][0]),&(val[0][1]),mont,ctx)) | ||
| 83 | goto err; | ||
| 84 | |||
| 85 | #if 0 | ||
| 86 | if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */ | ||
| 87 | window=1; | ||
| 88 | else if (bits > 250) | ||
| 89 | window=5; /* max size of window */ | ||
| 90 | else if (bits >= 120) | ||
| 91 | window=4; | ||
| 92 | else | ||
| 93 | window=3; | ||
| 94 | #else | ||
| 95 | window=EXP2_TABLE_BITS; | ||
| 96 | #endif | ||
| 97 | |||
| 98 | k=1<<window; | ||
| 99 | for (x=0; x<k; x++) | ||
| 100 | { | ||
| 101 | if (x >= 2) | ||
| 102 | { | ||
| 103 | BN_init(&(val[x][0])); | ||
| 104 | BN_init(&(val[x][1])); | ||
| 105 | if (!BN_mod_mul_montgomery(&(val[x][0]), | ||
| 106 | &(val[1][0]),&(val[x-1][0]),mont,ctx)) goto err; | ||
| 107 | if (!BN_mod_mul_montgomery(&(val[x][1]), | ||
| 108 | &(val[1][0]),&(val[x-1][1]),mont,ctx)) goto err; | ||
| 109 | } | ||
| 110 | for (y=2; y<k; y++) | ||
| 111 | { | ||
| 112 | BN_init(&(val[x][y])); | ||
| 113 | if (!BN_mod_mul_montgomery(&(val[x][y]), | ||
| 114 | &(val[x][y-1]),&(val[0][1]),mont,ctx)) | ||
| 115 | goto err; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | ts=k; | ||
| 119 | |||
| 120 | start=1; /* This is used to avoid multiplication etc | ||
| 121 | * when there is only the value '1' in the | ||
| 122 | * buffer. */ | ||
| 123 | xvalue=0; /* The 'x value' of the window */ | ||
| 124 | yvalue=0; /* The 'y value' of the window */ | ||
| 125 | wstart=bits-1; /* The top bit of the window */ | ||
| 126 | wend=0; /* The bottom bit of the window */ | ||
| 127 | |||
| 128 | if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err; | ||
| 129 | for (;;) | ||
| 130 | { | ||
| 131 | xvalue=BN_is_bit_set(p1,wstart); | ||
| 132 | yvalue=BN_is_bit_set(p2,wstart); | ||
| 133 | if (!(xvalue || yvalue)) | ||
| 134 | { | ||
| 135 | if (!start) | ||
| 136 | { | ||
| 137 | if (!BN_mod_mul_montgomery(r,r,r,mont,ctx)) | ||
| 138 | goto err; | ||
| 139 | } | ||
| 140 | wstart--; | ||
| 141 | if (wstart < 0) break; | ||
| 142 | continue; | ||
| 143 | } | ||
| 144 | /* We now have wstart on a 'set' bit, we now need to work out | ||
| 145 | * how bit a window to do. To do this we need to scan | ||
| 146 | * forward until the last set bit before the end of the | ||
| 147 | * window */ | ||
| 148 | j=wstart; | ||
| 149 | /* xvalue=BN_is_bit_set(p1,wstart); already set */ | ||
| 150 | /* yvalue=BN_is_bit_set(p1,wstart); already set */ | ||
| 151 | wend=0; | ||
| 152 | for (i=1; i<window; i++) | ||
| 153 | { | ||
| 154 | if (wstart-i < 0) break; | ||
| 155 | xvalue+=xvalue; | ||
| 156 | xvalue|=BN_is_bit_set(p1,wstart-i); | ||
| 157 | yvalue+=yvalue; | ||
| 158 | yvalue|=BN_is_bit_set(p2,wstart-i); | ||
| 159 | } | ||
| 160 | |||
| 161 | /* i is the size of the current window */ | ||
| 162 | /* add the 'bytes above' */ | ||
| 163 | if (!start) | ||
| 164 | for (j=0; j<i; j++) | ||
| 165 | { | ||
| 166 | if (!BN_mod_mul_montgomery(r,r,r,mont,ctx)) | ||
| 167 | goto err; | ||
| 168 | } | ||
| 169 | |||
| 170 | /* wvalue will be an odd number < 2^window */ | ||
| 171 | if (xvalue || yvalue) | ||
| 172 | { | ||
| 173 | if (!BN_mod_mul_montgomery(r,r,&(val[xvalue][yvalue]), | ||
| 174 | mont,ctx)) goto err; | ||
| 175 | } | ||
| 176 | |||
| 177 | /* move the 'window' down further */ | ||
| 178 | wstart-=i; | ||
| 179 | start=0; | ||
| 180 | if (wstart < 0) break; | ||
| 181 | } | ||
| 182 | BN_from_montgomery(rr,r,mont,ctx); | ||
| 183 | ret=1; | ||
| 184 | err: | ||
| 185 | if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); | ||
| 186 | ctx->tos-=2; | ||
| 187 | for (i=0; i<ts; i++) | ||
| 188 | { | ||
| 189 | for (j=0; j<ts; j++) | ||
| 190 | { | ||
| 191 | BN_clear_free(&(val[i][j])); | ||
| 192 | } | ||
| 193 | } | ||
| 194 | return(ret); | ||
| 195 | } | ||
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c deleted file mode 100644 index 64a76f4498..0000000000 --- a/src/lib/libcrypto/bn/bn_gcd.c +++ /dev/null | |||
| @@ -1,204 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_gcd.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | static BIGNUM *euclid(BIGNUM *a, BIGNUM *b); | ||
| 64 | int BN_gcd(BIGNUM *r, BIGNUM *in_a, BIGNUM *in_b, BN_CTX *ctx) | ||
| 65 | { | ||
| 66 | BIGNUM *a,*b,*t; | ||
| 67 | int ret=0; | ||
| 68 | |||
| 69 | bn_check_top(in_a); | ||
| 70 | bn_check_top(in_b); | ||
| 71 | |||
| 72 | a= &(ctx->bn[ctx->tos]); | ||
| 73 | b= &(ctx->bn[ctx->tos+1]); | ||
| 74 | |||
| 75 | if (BN_copy(a,in_a) == NULL) goto err; | ||
| 76 | if (BN_copy(b,in_b) == NULL) goto err; | ||
| 77 | |||
| 78 | if (BN_cmp(a,b) < 0) { t=a; a=b; b=t; } | ||
| 79 | t=euclid(a,b); | ||
| 80 | if (t == NULL) goto err; | ||
| 81 | |||
| 82 | if (BN_copy(r,t) == NULL) goto err; | ||
| 83 | ret=1; | ||
| 84 | err: | ||
| 85 | return(ret); | ||
| 86 | } | ||
| 87 | |||
| 88 | static BIGNUM *euclid(BIGNUM *a, BIGNUM *b) | ||
| 89 | { | ||
| 90 | BIGNUM *t; | ||
| 91 | int shifts=0; | ||
| 92 | |||
| 93 | bn_check_top(a); | ||
| 94 | bn_check_top(b); | ||
| 95 | |||
| 96 | for (;;) | ||
| 97 | { | ||
| 98 | if (BN_is_zero(b)) | ||
| 99 | break; | ||
| 100 | |||
| 101 | if (BN_is_odd(a)) | ||
| 102 | { | ||
| 103 | if (BN_is_odd(b)) | ||
| 104 | { | ||
| 105 | if (!BN_sub(a,a,b)) goto err; | ||
| 106 | if (!BN_rshift1(a,a)) goto err; | ||
| 107 | if (BN_cmp(a,b) < 0) | ||
| 108 | { t=a; a=b; b=t; } | ||
| 109 | } | ||
| 110 | else /* a odd - b even */ | ||
| 111 | { | ||
| 112 | if (!BN_rshift1(b,b)) goto err; | ||
| 113 | if (BN_cmp(a,b) < 0) | ||
| 114 | { t=a; a=b; b=t; } | ||
| 115 | } | ||
| 116 | } | ||
| 117 | else /* a is even */ | ||
| 118 | { | ||
| 119 | if (BN_is_odd(b)) | ||
| 120 | { | ||
| 121 | if (!BN_rshift1(a,a)) goto err; | ||
| 122 | if (BN_cmp(a,b) < 0) | ||
| 123 | { t=a; a=b; b=t; } | ||
| 124 | } | ||
| 125 | else /* a even - b even */ | ||
| 126 | { | ||
| 127 | if (!BN_rshift1(a,a)) goto err; | ||
| 128 | if (!BN_rshift1(b,b)) goto err; | ||
| 129 | shifts++; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | } | ||
| 133 | if (shifts) | ||
| 134 | { | ||
| 135 | if (!BN_lshift(a,a,shifts)) goto err; | ||
| 136 | } | ||
| 137 | return(a); | ||
| 138 | err: | ||
| 139 | return(NULL); | ||
| 140 | } | ||
| 141 | |||
| 142 | /* solves ax == 1 (mod n) */ | ||
| 143 | BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) | ||
| 144 | { | ||
| 145 | BIGNUM *A,*B,*X,*Y,*M,*D,*R; | ||
| 146 | BIGNUM *T,*ret=NULL; | ||
| 147 | int sign; | ||
| 148 | |||
| 149 | bn_check_top(a); | ||
| 150 | bn_check_top(n); | ||
| 151 | |||
| 152 | A= &(ctx->bn[ctx->tos]); | ||
| 153 | B= &(ctx->bn[ctx->tos+1]); | ||
| 154 | X= &(ctx->bn[ctx->tos+2]); | ||
| 155 | D= &(ctx->bn[ctx->tos+3]); | ||
| 156 | M= &(ctx->bn[ctx->tos+4]); | ||
| 157 | Y= &(ctx->bn[ctx->tos+5]); | ||
| 158 | ctx->tos+=6; | ||
| 159 | if (in == NULL) | ||
| 160 | R=BN_new(); | ||
| 161 | else | ||
| 162 | R=in; | ||
| 163 | if (R == NULL) goto err; | ||
| 164 | |||
| 165 | BN_zero(X); | ||
| 166 | BN_one(Y); | ||
| 167 | if (BN_copy(A,a) == NULL) goto err; | ||
| 168 | if (BN_copy(B,n) == NULL) goto err; | ||
| 169 | sign=1; | ||
| 170 | |||
| 171 | while (!BN_is_zero(B)) | ||
| 172 | { | ||
| 173 | if (!BN_div(D,M,A,B,ctx)) goto err; | ||
| 174 | T=A; | ||
| 175 | A=B; | ||
| 176 | B=M; | ||
| 177 | /* T has a struct, M does not */ | ||
| 178 | |||
| 179 | if (!BN_mul(T,D,X,ctx)) goto err; | ||
| 180 | if (!BN_add(T,T,Y)) goto err; | ||
| 181 | M=Y; | ||
| 182 | Y=X; | ||
| 183 | X=T; | ||
| 184 | sign= -sign; | ||
| 185 | } | ||
| 186 | if (sign < 0) | ||
| 187 | { | ||
| 188 | if (!BN_sub(Y,n,Y)) goto err; | ||
| 189 | } | ||
| 190 | |||
| 191 | if (BN_is_one(A)) | ||
| 192 | { if (!BN_mod(R,Y,n,ctx)) goto err; } | ||
| 193 | else | ||
| 194 | { | ||
| 195 | BNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE); | ||
| 196 | goto err; | ||
| 197 | } | ||
| 198 | ret=R; | ||
| 199 | err: | ||
| 200 | if ((ret == NULL) && (in == NULL)) BN_free(R); | ||
| 201 | ctx->tos-=6; | ||
| 202 | return(ret); | ||
| 203 | } | ||
| 204 | |||
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h deleted file mode 100644 index 85a372695b..0000000000 --- a/src/lib/libcrypto/bn/bn_lcl.h +++ /dev/null | |||
| @@ -1,268 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_lcl.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_BN_LCL_H | ||
| 60 | #define HEADER_BN_LCL_H | ||
| 61 | |||
| 62 | #include <openssl/bn.h> | ||
| 63 | |||
| 64 | #ifdef __cplusplus | ||
| 65 | extern "C" { | ||
| 66 | #endif | ||
| 67 | |||
| 68 | /* Pentium pro 16,16,16,32,64 */ | ||
| 69 | /* Alpha 16,16,16,16.64 */ | ||
| 70 | #define BN_MULL_SIZE_NORMAL (16) /* 32 */ | ||
| 71 | #define BN_MUL_RECURSIVE_SIZE_NORMAL (16) /* 32 less than */ | ||
| 72 | #define BN_SQR_RECURSIVE_SIZE_NORMAL (16) /* 32 */ | ||
| 73 | #define BN_MUL_LOW_RECURSIVE_SIZE_NORMAL (32) /* 32 */ | ||
| 74 | #define BN_MONT_CTX_SET_SIZE_WORD (64) /* 32 */ | ||
| 75 | |||
| 76 | #if 0 | ||
| 77 | #ifndef BN_MUL_COMBA | ||
| 78 | /* #define bn_mul_comba8(r,a,b) bn_mul_normal(r,a,8,b,8) */ | ||
| 79 | /* #define bn_mul_comba4(r,a,b) bn_mul_normal(r,a,4,b,4) */ | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #ifndef BN_SQR_COMBA | ||
| 83 | /* This is probably faster than using the C code - I need to check */ | ||
| 84 | #define bn_sqr_comba8(r,a) bn_mul_normal(r,a,8,a,8) | ||
| 85 | #define bn_sqr_comba4(r,a) bn_mul_normal(r,a,4,a,4) | ||
| 86 | #endif | ||
| 87 | #endif | ||
| 88 | |||
| 89 | /************************************************************* | ||
| 90 | * Using the long long type | ||
| 91 | */ | ||
| 92 | #define Lw(t) (((BN_ULONG)(t))&BN_MASK2) | ||
| 93 | #define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) | ||
| 94 | |||
| 95 | /* These are used for internal error checking and are not normally used */ | ||
| 96 | #ifdef BN_DEBUG | ||
| 97 | #define bn_check_top(a) \ | ||
| 98 | { if (((a)->top < 0) || ((a)->top > (a)->max)) \ | ||
| 99 | { char *nullp=NULL; *nullp='z'; } } | ||
| 100 | #define bn_check_num(a) if ((a) < 0) { char *nullp=NULL; *nullp='z'; } | ||
| 101 | #else | ||
| 102 | #define bn_check_top(a) | ||
| 103 | #define bn_check_num(a) | ||
| 104 | #endif | ||
| 105 | |||
| 106 | /* This macro is to add extra stuff for development checking */ | ||
| 107 | #ifdef BN_DEBUG | ||
| 108 | #define bn_set_max(r) ((r)->max=(r)->top,BN_set_flags((r),BN_FLG_STATIC_DATA)) | ||
| 109 | #else | ||
| 110 | #define bn_set_max(r) | ||
| 111 | #endif | ||
| 112 | |||
| 113 | /* These macros are used to 'take' a section of a bignum for read only use */ | ||
| 114 | #define bn_set_low(r,a,n) \ | ||
| 115 | { \ | ||
| 116 | (r)->top=((a)->top > (n))?(n):(a)->top; \ | ||
| 117 | (r)->d=(a)->d; \ | ||
| 118 | (r)->neg=(a)->neg; \ | ||
| 119 | (r)->flags|=BN_FLG_STATIC_DATA; \ | ||
| 120 | bn_set_max(r); \ | ||
| 121 | } | ||
| 122 | |||
| 123 | #define bn_set_high(r,a,n) \ | ||
| 124 | { \ | ||
| 125 | if ((a)->top > (n)) \ | ||
| 126 | { \ | ||
| 127 | (r)->top=(a)->top-n; \ | ||
| 128 | (r)->d= &((a)->d[n]); \ | ||
| 129 | } \ | ||
| 130 | else \ | ||
| 131 | (r)->top=0; \ | ||
| 132 | (r)->neg=(a)->neg; \ | ||
| 133 | (r)->flags|=BN_FLG_STATIC_DATA; \ | ||
| 134 | bn_set_max(r); \ | ||
| 135 | } | ||
| 136 | |||
| 137 | /* #define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?(n):bn_expand2((n),(b))) */ | ||
| 138 | |||
| 139 | #ifdef BN_LLONG | ||
| 140 | #define mul_add(r,a,w,c) { \ | ||
| 141 | BN_ULLONG t; \ | ||
| 142 | t=(BN_ULLONG)w * (a) + (r) + (c); \ | ||
| 143 | (r)= Lw(t); \ | ||
| 144 | (c)= Hw(t); \ | ||
| 145 | } | ||
| 146 | |||
| 147 | #define mul(r,a,w,c) { \ | ||
| 148 | BN_ULLONG t; \ | ||
| 149 | t=(BN_ULLONG)w * (a) + (c); \ | ||
| 150 | (r)= Lw(t); \ | ||
| 151 | (c)= Hw(t); \ | ||
| 152 | } | ||
| 153 | |||
| 154 | #else | ||
| 155 | /************************************************************* | ||
| 156 | * No long long type | ||
| 157 | */ | ||
| 158 | |||
| 159 | #define LBITS(a) ((a)&BN_MASK2l) | ||
| 160 | #define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l) | ||
| 161 | #define L2HBITS(a) ((BN_ULONG)((a)&BN_MASK2l)<<BN_BITS4) | ||
| 162 | |||
| 163 | #define LLBITS(a) ((a)&BN_MASKl) | ||
| 164 | #define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl) | ||
| 165 | #define LL2HBITS(a) ((BN_ULLONG)((a)&BN_MASKl)<<BN_BITS2) | ||
| 166 | |||
| 167 | #define mul64(l,h,bl,bh) \ | ||
| 168 | { \ | ||
| 169 | BN_ULONG m,m1,lt,ht; \ | ||
| 170 | \ | ||
| 171 | lt=l; \ | ||
| 172 | ht=h; \ | ||
| 173 | m =(bh)*(lt); \ | ||
| 174 | lt=(bl)*(lt); \ | ||
| 175 | m1=(bl)*(ht); \ | ||
| 176 | ht =(bh)*(ht); \ | ||
| 177 | m=(m+m1)&BN_MASK2; if (m < m1) ht+=L2HBITS(1L); \ | ||
| 178 | ht+=HBITS(m); \ | ||
| 179 | m1=L2HBITS(m); \ | ||
| 180 | lt=(lt+m1)&BN_MASK2; if (lt < m1) ht++; \ | ||
| 181 | (l)=lt; \ | ||
| 182 | (h)=ht; \ | ||
| 183 | } | ||
| 184 | |||
| 185 | #define sqr64(lo,ho,in) \ | ||
| 186 | { \ | ||
| 187 | BN_ULONG l,h,m; \ | ||
| 188 | \ | ||
| 189 | h=(in); \ | ||
| 190 | l=LBITS(h); \ | ||
| 191 | h=HBITS(h); \ | ||
| 192 | m =(l)*(h); \ | ||
| 193 | l*=l; \ | ||
| 194 | h*=h; \ | ||
| 195 | h+=(m&BN_MASK2h1)>>(BN_BITS4-1); \ | ||
| 196 | m =(m&BN_MASK2l)<<(BN_BITS4+1); \ | ||
| 197 | l=(l+m)&BN_MASK2; if (l < m) h++; \ | ||
| 198 | (lo)=l; \ | ||
| 199 | (ho)=h; \ | ||
| 200 | } | ||
| 201 | |||
| 202 | #define mul_add(r,a,bl,bh,c) { \ | ||
| 203 | BN_ULONG l,h; \ | ||
| 204 | \ | ||
| 205 | h= (a); \ | ||
| 206 | l=LBITS(h); \ | ||
| 207 | h=HBITS(h); \ | ||
| 208 | mul64(l,h,(bl),(bh)); \ | ||
| 209 | \ | ||
| 210 | /* non-multiply part */ \ | ||
| 211 | l=(l+(c))&BN_MASK2; if (l < (c)) h++; \ | ||
| 212 | (c)=(r); \ | ||
| 213 | l=(l+(c))&BN_MASK2; if (l < (c)) h++; \ | ||
| 214 | (c)=h&BN_MASK2; \ | ||
| 215 | (r)=l; \ | ||
| 216 | } | ||
| 217 | |||
| 218 | #define mul(r,a,bl,bh,c) { \ | ||
| 219 | BN_ULONG l,h; \ | ||
| 220 | \ | ||
| 221 | h= (a); \ | ||
| 222 | l=LBITS(h); \ | ||
| 223 | h=HBITS(h); \ | ||
| 224 | mul64(l,h,(bl),(bh)); \ | ||
| 225 | \ | ||
| 226 | /* non-multiply part */ \ | ||
| 227 | l+=(c); if ((l&BN_MASK2) < (c)) h++; \ | ||
| 228 | (c)=h&BN_MASK2; \ | ||
| 229 | (r)=l&BN_MASK2; \ | ||
| 230 | } | ||
| 231 | |||
| 232 | #endif | ||
| 233 | |||
| 234 | OPENSSL_EXTERN int bn_limit_bits; | ||
| 235 | OPENSSL_EXTERN int bn_limit_num; /* (1<<bn_limit_bits) */ | ||
| 236 | /* Recursive 'low' limit */ | ||
| 237 | OPENSSL_EXTERN int bn_limit_bits_low; | ||
| 238 | OPENSSL_EXTERN int bn_limit_num_low; /* (1<<bn_limit_bits_low) */ | ||
| 239 | /* Do modified 'high' part calculation' */ | ||
| 240 | OPENSSL_EXTERN int bn_limit_bits_high; | ||
| 241 | OPENSSL_EXTERN int bn_limit_num_high; /* (1<<bn_limit_bits_high) */ | ||
| 242 | OPENSSL_EXTERN int bn_limit_bits_mont; | ||
| 243 | OPENSSL_EXTERN int bn_limit_num_mont; /* (1<<bn_limit_bits_mont) */ | ||
| 244 | |||
| 245 | BIGNUM *bn_expand2(BIGNUM *b, int bits); | ||
| 246 | |||
| 247 | void bn_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb); | ||
| 248 | void bn_mul_comba8(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b); | ||
| 249 | void bn_mul_comba4(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b); | ||
| 250 | void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp); | ||
| 251 | void bn_sqr_comba8(BN_ULONG *r,BN_ULONG *a); | ||
| 252 | void bn_sqr_comba4(BN_ULONG *r,BN_ULONG *a); | ||
| 253 | int bn_cmp_words(BN_ULONG *a,BN_ULONG *b,int n); | ||
| 254 | void bn_mul_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,BN_ULONG *t); | ||
| 255 | void bn_mul_part_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, | ||
| 256 | int tn, int n,BN_ULONG *t); | ||
| 257 | void bn_sqr_recursive(BN_ULONG *r,BN_ULONG *a, int n2, BN_ULONG *t); | ||
| 258 | void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n); | ||
| 259 | void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, | ||
| 260 | BN_ULONG *t); | ||
| 261 | void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2, | ||
| 262 | BN_ULONG *t); | ||
| 263 | |||
| 264 | #ifdef __cplusplus | ||
| 265 | } | ||
| 266 | #endif | ||
| 267 | |||
| 268 | #endif | ||
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c deleted file mode 100644 index 5d62d88e8b..0000000000 --- a/src/lib/libcrypto/bn/bn_lib.c +++ /dev/null | |||
| @@ -1,787 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_lib.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | const char *BN_version="Big Number" OPENSSL_VERSION_PTEXT; | ||
| 64 | |||
| 65 | /* For a 32 bit machine | ||
| 66 | * 2 - 4 == 128 | ||
| 67 | * 3 - 8 == 256 | ||
| 68 | * 4 - 16 == 512 | ||
| 69 | * 5 - 32 == 1024 | ||
| 70 | * 6 - 64 == 2048 | ||
| 71 | * 7 - 128 == 4096 | ||
| 72 | * 8 - 256 == 8192 | ||
| 73 | */ | ||
| 74 | OPENSSL_GLOBAL int bn_limit_bits=0; | ||
| 75 | OPENSSL_GLOBAL int bn_limit_num=8; /* (1<<bn_limit_bits) */ | ||
| 76 | OPENSSL_GLOBAL int bn_limit_bits_low=0; | ||
| 77 | OPENSSL_GLOBAL int bn_limit_num_low=8; /* (1<<bn_limit_bits_low) */ | ||
| 78 | OPENSSL_GLOBAL int bn_limit_bits_high=0; | ||
| 79 | OPENSSL_GLOBAL int bn_limit_num_high=8; /* (1<<bn_limit_bits_high) */ | ||
| 80 | OPENSSL_GLOBAL int bn_limit_bits_mont=0; | ||
| 81 | OPENSSL_GLOBAL int bn_limit_num_mont=8; /* (1<<bn_limit_bits_mont) */ | ||
| 82 | |||
| 83 | void BN_set_params(int mult, int high, int low, int mont) | ||
| 84 | { | ||
| 85 | if (mult >= 0) | ||
| 86 | { | ||
| 87 | if (mult > (sizeof(int)*8)-1) | ||
| 88 | mult=sizeof(int)*8-1; | ||
| 89 | bn_limit_bits=mult; | ||
| 90 | bn_limit_num=1<<mult; | ||
| 91 | } | ||
| 92 | if (high >= 0) | ||
| 93 | { | ||
| 94 | if (high > (sizeof(int)*8)-1) | ||
| 95 | high=sizeof(int)*8-1; | ||
| 96 | bn_limit_bits_high=high; | ||
| 97 | bn_limit_num_high=1<<high; | ||
| 98 | } | ||
| 99 | if (low >= 0) | ||
| 100 | { | ||
| 101 | if (low > (sizeof(int)*8)-1) | ||
| 102 | low=sizeof(int)*8-1; | ||
| 103 | bn_limit_bits_low=low; | ||
| 104 | bn_limit_num_low=1<<low; | ||
| 105 | } | ||
| 106 | if (mont >= 0) | ||
| 107 | { | ||
| 108 | if (mont > (sizeof(int)*8)-1) | ||
| 109 | mont=sizeof(int)*8-1; | ||
| 110 | bn_limit_bits_mont=mont; | ||
| 111 | bn_limit_num_mont=1<<mont; | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | int BN_get_params(int which) | ||
| 116 | { | ||
| 117 | if (which == 0) return(bn_limit_bits); | ||
| 118 | else if (which == 1) return(bn_limit_bits_high); | ||
| 119 | else if (which == 2) return(bn_limit_bits_low); | ||
| 120 | else if (which == 3) return(bn_limit_bits_mont); | ||
| 121 | else return(0); | ||
| 122 | } | ||
| 123 | |||
| 124 | BIGNUM *BN_value_one(void) | ||
| 125 | { | ||
| 126 | static BN_ULONG data_one=1L; | ||
| 127 | static BIGNUM const_one={&data_one,1,1,0}; | ||
| 128 | |||
| 129 | return(&const_one); | ||
| 130 | } | ||
| 131 | |||
| 132 | char *BN_options(void) | ||
| 133 | { | ||
| 134 | static int init=0; | ||
| 135 | static char data[16]; | ||
| 136 | |||
| 137 | if (!init) | ||
| 138 | { | ||
| 139 | init++; | ||
| 140 | #ifdef BN_LLONG | ||
| 141 | sprintf(data,"bn(%d,%d)",(int)sizeof(BN_ULLONG)*8, | ||
| 142 | (int)sizeof(BN_ULONG)*8); | ||
| 143 | #else | ||
| 144 | sprintf(data,"bn(%d,%d)",(int)sizeof(BN_ULONG)*8, | ||
| 145 | (int)sizeof(BN_ULONG)*8); | ||
| 146 | #endif | ||
| 147 | } | ||
| 148 | return(data); | ||
| 149 | } | ||
| 150 | |||
| 151 | int BN_num_bits_word(BN_ULONG l) | ||
| 152 | { | ||
| 153 | static const char bits[256]={ | ||
| 154 | 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4, | ||
| 155 | 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | ||
| 156 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
| 157 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | ||
| 158 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 159 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 160 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 161 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | ||
| 162 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 163 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 164 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 165 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 166 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 167 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 168 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 169 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | ||
| 170 | }; | ||
| 171 | |||
| 172 | #if defined(SIXTY_FOUR_BIT_LONG) | ||
| 173 | if (l & 0xffffffff00000000L) | ||
| 174 | { | ||
| 175 | if (l & 0xffff000000000000L) | ||
| 176 | { | ||
| 177 | if (l & 0xff00000000000000L) | ||
| 178 | { | ||
| 179 | return(bits[(int)(l>>56)]+56); | ||
| 180 | } | ||
| 181 | else return(bits[(int)(l>>48)]+48); | ||
| 182 | } | ||
| 183 | else | ||
| 184 | { | ||
| 185 | if (l & 0x0000ff0000000000L) | ||
| 186 | { | ||
| 187 | return(bits[(int)(l>>40)]+40); | ||
| 188 | } | ||
| 189 | else return(bits[(int)(l>>32)]+32); | ||
| 190 | } | ||
| 191 | } | ||
| 192 | else | ||
| 193 | #else | ||
| 194 | #ifdef SIXTY_FOUR_BIT | ||
| 195 | if (l & 0xffffffff00000000LL) | ||
| 196 | { | ||
| 197 | if (l & 0xffff000000000000LL) | ||
| 198 | { | ||
| 199 | if (l & 0xff00000000000000LL) | ||
| 200 | { | ||
| 201 | return(bits[(int)(l>>56)]+56); | ||
| 202 | } | ||
| 203 | else return(bits[(int)(l>>48)]+48); | ||
| 204 | } | ||
| 205 | else | ||
| 206 | { | ||
| 207 | if (l & 0x0000ff0000000000LL) | ||
| 208 | { | ||
| 209 | return(bits[(int)(l>>40)]+40); | ||
| 210 | } | ||
| 211 | else return(bits[(int)(l>>32)]+32); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | else | ||
| 215 | #endif | ||
| 216 | #endif | ||
| 217 | { | ||
| 218 | #if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | ||
| 219 | if (l & 0xffff0000L) | ||
| 220 | { | ||
| 221 | if (l & 0xff000000L) | ||
| 222 | return(bits[(int)(l>>24L)]+24); | ||
| 223 | else return(bits[(int)(l>>16L)]+16); | ||
| 224 | } | ||
| 225 | else | ||
| 226 | #endif | ||
| 227 | { | ||
| 228 | #if defined(SIXTEEN_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | ||
| 229 | if (l & 0xff00L) | ||
| 230 | return(bits[(int)(l>>8)]+8); | ||
| 231 | else | ||
| 232 | #endif | ||
| 233 | return(bits[(int)(l )] ); | ||
| 234 | } | ||
| 235 | } | ||
| 236 | } | ||
| 237 | |||
| 238 | int BN_num_bits(const BIGNUM *a) | ||
| 239 | { | ||
| 240 | BN_ULONG l; | ||
| 241 | int i; | ||
| 242 | |||
| 243 | bn_check_top(a); | ||
| 244 | |||
| 245 | if (a->top == 0) return(0); | ||
| 246 | l=a->d[a->top-1]; | ||
| 247 | i=(a->top-1)*BN_BITS2; | ||
| 248 | if (l == 0) | ||
| 249 | { | ||
| 250 | #if !defined(NO_STDIO) && !defined(WIN16) | ||
| 251 | fprintf(stderr,"BAD TOP VALUE\n"); | ||
| 252 | #endif | ||
| 253 | abort(); | ||
| 254 | } | ||
| 255 | return(i+BN_num_bits_word(l)); | ||
| 256 | } | ||
| 257 | |||
| 258 | void BN_clear_free(BIGNUM *a) | ||
| 259 | { | ||
| 260 | int i; | ||
| 261 | |||
| 262 | if (a == NULL) return; | ||
| 263 | if (a->d != NULL) | ||
| 264 | { | ||
| 265 | memset(a->d,0,a->max*sizeof(a->d[0])); | ||
| 266 | if (!(BN_get_flags(a,BN_FLG_STATIC_DATA))) | ||
| 267 | Free(a->d); | ||
| 268 | } | ||
| 269 | i=BN_get_flags(a,BN_FLG_MALLOCED); | ||
| 270 | memset(a,0,sizeof(BIGNUM)); | ||
| 271 | if (i) | ||
| 272 | Free(a); | ||
| 273 | } | ||
| 274 | |||
| 275 | void BN_free(BIGNUM *a) | ||
| 276 | { | ||
| 277 | if (a == NULL) return; | ||
| 278 | if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA))) | ||
| 279 | Free(a->d); | ||
| 280 | a->flags|=BN_FLG_FREE; /* REMOVE? */ | ||
| 281 | if (a->flags & BN_FLG_MALLOCED) | ||
| 282 | Free(a); | ||
| 283 | } | ||
| 284 | |||
| 285 | void BN_init(BIGNUM *a) | ||
| 286 | { | ||
| 287 | memset(a,0,sizeof(BIGNUM)); | ||
| 288 | } | ||
| 289 | |||
| 290 | BIGNUM *BN_new(void) | ||
| 291 | { | ||
| 292 | BIGNUM *ret; | ||
| 293 | |||
| 294 | if ((ret=(BIGNUM *)Malloc(sizeof(BIGNUM))) == NULL) | ||
| 295 | { | ||
| 296 | BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE); | ||
| 297 | return(NULL); | ||
| 298 | } | ||
| 299 | ret->flags=BN_FLG_MALLOCED; | ||
| 300 | ret->top=0; | ||
| 301 | ret->neg=0; | ||
| 302 | ret->max=0; | ||
| 303 | ret->d=NULL; | ||
| 304 | return(ret); | ||
| 305 | } | ||
| 306 | |||
| 307 | |||
| 308 | BN_CTX *BN_CTX_new(void) | ||
| 309 | { | ||
| 310 | BN_CTX *ret; | ||
| 311 | |||
| 312 | ret=(BN_CTX *)Malloc(sizeof(BN_CTX)); | ||
| 313 | if (ret == NULL) | ||
| 314 | { | ||
| 315 | BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE); | ||
| 316 | return(NULL); | ||
| 317 | } | ||
| 318 | |||
| 319 | BN_CTX_init(ret); | ||
| 320 | ret->flags=BN_FLG_MALLOCED; | ||
| 321 | return(ret); | ||
| 322 | } | ||
| 323 | |||
| 324 | void BN_CTX_init(BN_CTX *ctx) | ||
| 325 | { | ||
| 326 | memset(ctx,0,sizeof(BN_CTX)); | ||
| 327 | ctx->tos=0; | ||
| 328 | ctx->flags=0; | ||
| 329 | } | ||
| 330 | |||
| 331 | void BN_CTX_free(BN_CTX *c) | ||
| 332 | { | ||
| 333 | int i; | ||
| 334 | |||
| 335 | if(c == NULL) | ||
| 336 | return; | ||
| 337 | |||
| 338 | for (i=0; i<BN_CTX_NUM; i++) | ||
| 339 | BN_clear_free(&(c->bn[i])); | ||
| 340 | if (c->flags & BN_FLG_MALLOCED) | ||
| 341 | Free(c); | ||
| 342 | } | ||
| 343 | |||
| 344 | BIGNUM *bn_expand2(BIGNUM *b, int words) | ||
| 345 | { | ||
| 346 | BN_ULONG *A,*a; | ||
| 347 | const BN_ULONG *B; | ||
| 348 | int i; | ||
| 349 | |||
| 350 | bn_check_top(b); | ||
| 351 | |||
| 352 | if (words > b->max) | ||
| 353 | { | ||
| 354 | bn_check_top(b); | ||
| 355 | if (BN_get_flags(b,BN_FLG_STATIC_DATA)) | ||
| 356 | { | ||
| 357 | BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); | ||
| 358 | return(NULL); | ||
| 359 | } | ||
| 360 | a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1)); | ||
| 361 | if (A == NULL) | ||
| 362 | { | ||
| 363 | BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); | ||
| 364 | return(NULL); | ||
| 365 | } | ||
| 366 | #if 1 | ||
| 367 | B=b->d; | ||
| 368 | /* Check if the previous number needs to be copied */ | ||
| 369 | if (B != NULL) | ||
| 370 | { | ||
| 371 | #if 0 | ||
| 372 | /* This lot is an unrolled loop to copy b->top | ||
| 373 | * BN_ULONGs from B to A | ||
| 374 | */ | ||
| 375 | /* | ||
| 376 | * I have nothing against unrolling but it's usually done for | ||
| 377 | * several reasons, namely: | ||
| 378 | * - minimize percentage of decision making code, i.e. branches; | ||
| 379 | * - avoid cache trashing; | ||
| 380 | * - make it possible to schedule loads earlier; | ||
| 381 | * Now let's examine the code below. The cornerstone of C is | ||
| 382 | * "programmer is always right" and that's what we love it for:-) | ||
| 383 | * For this very reason C compilers have to be paranoid when it | ||
| 384 | * comes to data aliasing and assume the worst. Yeah, but what | ||
| 385 | * does it mean in real life? This means that loop body below will | ||
| 386 | * be compiled to sequence of loads immediately followed by stores | ||
| 387 | * as compiler assumes the worst, something in A==B+1 style. As a | ||
| 388 | * result CPU pipeline is going to starve for incoming data. Secondly | ||
| 389 | * if A and B happen to share same cache line such code is going to | ||
| 390 | * cause severe cache trashing. Both factors have severe impact on | ||
| 391 | * performance of modern CPUs and this is the reason why this | ||
| 392 | * particulare piece of code is #ifdefed away and replaced by more | ||
| 393 | * "friendly" version found in #else section below. This comment | ||
| 394 | * also applies to BN_copy function. | ||
| 395 | * | ||
| 396 | * <appro@fy.chalmers.se> | ||
| 397 | */ | ||
| 398 | for (i=b->top&(~7); i>0; i-=8) | ||
| 399 | { | ||
| 400 | A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3]; | ||
| 401 | A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7]; | ||
| 402 | A+=8; | ||
| 403 | B+=8; | ||
| 404 | } | ||
| 405 | switch (b->top&7) | ||
| 406 | { | ||
| 407 | case 7: | ||
| 408 | A[6]=B[6]; | ||
| 409 | case 6: | ||
| 410 | A[5]=B[5]; | ||
| 411 | case 5: | ||
| 412 | A[4]=B[4]; | ||
| 413 | case 4: | ||
| 414 | A[3]=B[3]; | ||
| 415 | case 3: | ||
| 416 | A[2]=B[2]; | ||
| 417 | case 2: | ||
| 418 | A[1]=B[1]; | ||
| 419 | case 1: | ||
| 420 | A[0]=B[0]; | ||
| 421 | case 0: | ||
| 422 | /* I need the 'case 0' entry for utrix cc. | ||
| 423 | * If the optimiser is turned on, it does the | ||
| 424 | * switch table by doing | ||
| 425 | * a=top&7 | ||
| 426 | * a--; | ||
| 427 | * goto jump_table[a]; | ||
| 428 | * If top is 0, this makes us jump to 0xffffffc | ||
| 429 | * which is rather bad :-(. | ||
| 430 | * eric 23-Apr-1998 | ||
| 431 | */ | ||
| 432 | ; | ||
| 433 | } | ||
| 434 | #else | ||
| 435 | for (i=b->top>>2; i>0; i--,A+=4,B+=4) | ||
| 436 | { | ||
| 437 | /* | ||
| 438 | * The fact that the loop is unrolled | ||
| 439 | * 4-wise is a tribute to Intel. It's | ||
| 440 | * the one that doesn't have enough | ||
| 441 | * registers to accomodate more data. | ||
| 442 | * I'd unroll it 8-wise otherwise:-) | ||
| 443 | * | ||
| 444 | * <appro@fy.chalmers.se> | ||
| 445 | */ | ||
| 446 | BN_ULONG a0,a1,a2,a3; | ||
| 447 | a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3]; | ||
| 448 | A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3; | ||
| 449 | } | ||
| 450 | switch (b->top&3) | ||
| 451 | { | ||
| 452 | case 3: A[2]=B[2]; | ||
| 453 | case 2: A[1]=B[1]; | ||
| 454 | case 1: A[0]=B[0]; | ||
| 455 | case 0: ; /* ultrix cc workaround, see above */ | ||
| 456 | } | ||
| 457 | #endif | ||
| 458 | Free(b->d); | ||
| 459 | } | ||
| 460 | |||
| 461 | b->d=a; | ||
| 462 | b->max=words; | ||
| 463 | |||
| 464 | /* Now need to zero any data between b->top and b->max */ | ||
| 465 | |||
| 466 | A= &(b->d[b->top]); | ||
| 467 | for (i=(b->max - b->top)>>3; i>0; i--,A+=8) | ||
| 468 | { | ||
| 469 | A[0]=0; A[1]=0; A[2]=0; A[3]=0; | ||
| 470 | A[4]=0; A[5]=0; A[6]=0; A[7]=0; | ||
| 471 | } | ||
| 472 | for (i=(b->max - b->top)&7; i>0; i--,A++) | ||
| 473 | A[0]=0; | ||
| 474 | #else | ||
| 475 | memset(A,0,sizeof(BN_ULONG)*(words+1)); | ||
| 476 | memcpy(A,b->d,sizeof(b->d[0])*b->top); | ||
| 477 | b->d=a; | ||
| 478 | b->max=words; | ||
| 479 | #endif | ||
| 480 | |||
| 481 | /* memset(&(p[b->max]),0,((words+1)-b->max)*sizeof(BN_ULONG)); */ | ||
| 482 | /* { int i; for (i=b->max; i<words+1; i++) p[i]=i;} */ | ||
| 483 | |||
| 484 | } | ||
| 485 | return(b); | ||
| 486 | } | ||
| 487 | |||
| 488 | BIGNUM *BN_dup(const BIGNUM *a) | ||
| 489 | { | ||
| 490 | BIGNUM *r; | ||
| 491 | |||
| 492 | if (a == NULL) return NULL; | ||
| 493 | |||
| 494 | bn_check_top(a); | ||
| 495 | |||
| 496 | r=BN_new(); | ||
| 497 | if (r == NULL) return(NULL); | ||
| 498 | return((BIGNUM *)BN_copy(r,a)); | ||
| 499 | } | ||
| 500 | |||
| 501 | BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) | ||
| 502 | { | ||
| 503 | int i; | ||
| 504 | BN_ULONG *A; | ||
| 505 | const BN_ULONG *B; | ||
| 506 | |||
| 507 | bn_check_top(b); | ||
| 508 | |||
| 509 | if (a == b) return(a); | ||
| 510 | if (bn_wexpand(a,b->top) == NULL) return(NULL); | ||
| 511 | |||
| 512 | #if 1 | ||
| 513 | A=a->d; | ||
| 514 | B=b->d; | ||
| 515 | for (i=b->top>>2; i>0; i--,A+=4,B+=4) | ||
| 516 | { | ||
| 517 | BN_ULONG a0,a1,a2,a3; | ||
| 518 | a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3]; | ||
| 519 | A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3; | ||
| 520 | } | ||
| 521 | switch (b->top&3) | ||
| 522 | { | ||
| 523 | case 3: A[2]=B[2]; | ||
| 524 | case 2: A[1]=B[1]; | ||
| 525 | case 1: A[0]=B[0]; | ||
| 526 | case 0: ; /* ultrix cc workaround, see comments in bn_expand2 */ | ||
| 527 | } | ||
| 528 | #else | ||
| 529 | memcpy(a->d,b->d,sizeof(b->d[0])*b->top); | ||
| 530 | #endif | ||
| 531 | |||
| 532 | /* memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/ | ||
| 533 | a->top=b->top; | ||
| 534 | if ((a->top == 0) && (a->d != NULL)) | ||
| 535 | a->d[0]=0; | ||
| 536 | a->neg=b->neg; | ||
| 537 | return(a); | ||
| 538 | } | ||
| 539 | |||
| 540 | void BN_clear(BIGNUM *a) | ||
| 541 | { | ||
| 542 | if (a->d != NULL) | ||
| 543 | memset(a->d,0,a->max*sizeof(a->d[0])); | ||
| 544 | a->top=0; | ||
| 545 | a->neg=0; | ||
| 546 | } | ||
| 547 | |||
| 548 | BN_ULONG BN_get_word(BIGNUM *a) | ||
| 549 | { | ||
| 550 | int i,n; | ||
| 551 | BN_ULONG ret=0; | ||
| 552 | |||
| 553 | n=BN_num_bytes(a); | ||
| 554 | if (n > sizeof(BN_ULONG)) | ||
| 555 | return(BN_MASK2); | ||
| 556 | for (i=a->top-1; i>=0; i--) | ||
| 557 | { | ||
| 558 | #ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ | ||
| 559 | ret<<=BN_BITS4; /* stops the compiler complaining */ | ||
| 560 | ret<<=BN_BITS4; | ||
| 561 | #else | ||
| 562 | ret=0; | ||
| 563 | #endif | ||
| 564 | ret|=a->d[i]; | ||
| 565 | } | ||
| 566 | return(ret); | ||
| 567 | } | ||
| 568 | |||
| 569 | int BN_set_word(BIGNUM *a, BN_ULONG w) | ||
| 570 | { | ||
| 571 | int i,n; | ||
| 572 | if (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0); | ||
| 573 | |||
| 574 | n=sizeof(BN_ULONG)/BN_BYTES; | ||
| 575 | a->neg=0; | ||
| 576 | a->top=0; | ||
| 577 | a->d[0]=(BN_ULONG)w&BN_MASK2; | ||
| 578 | if (a->d[0] != 0) a->top=1; | ||
| 579 | for (i=1; i<n; i++) | ||
| 580 | { | ||
| 581 | /* the following is done instead of | ||
| 582 | * w>>=BN_BITS2 so compilers don't complain | ||
| 583 | * on builds where sizeof(long) == BN_TYPES */ | ||
| 584 | #ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ | ||
| 585 | w>>=BN_BITS4; | ||
| 586 | w>>=BN_BITS4; | ||
| 587 | #else | ||
| 588 | w=0; | ||
| 589 | #endif | ||
| 590 | a->d[i]=(BN_ULONG)w&BN_MASK2; | ||
| 591 | if (a->d[i] != 0) a->top=i+1; | ||
| 592 | } | ||
| 593 | return(1); | ||
| 594 | } | ||
| 595 | |||
| 596 | /* ignore negative */ | ||
| 597 | BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret) | ||
| 598 | { | ||
| 599 | unsigned int i,m; | ||
| 600 | unsigned int n; | ||
| 601 | BN_ULONG l; | ||
| 602 | |||
| 603 | if (ret == NULL) ret=BN_new(); | ||
| 604 | if (ret == NULL) return(NULL); | ||
| 605 | l=0; | ||
| 606 | n=len; | ||
| 607 | if (n == 0) | ||
| 608 | { | ||
| 609 | ret->top=0; | ||
| 610 | return(ret); | ||
| 611 | } | ||
| 612 | if (bn_expand(ret,(int)(n+2)*8) == NULL) | ||
| 613 | return(NULL); | ||
| 614 | i=((n-1)/BN_BYTES)+1; | ||
| 615 | m=((n-1)%(BN_BYTES)); | ||
| 616 | ret->top=i; | ||
| 617 | while (n-- > 0) | ||
| 618 | { | ||
| 619 | l=(l<<8L)| *(s++); | ||
| 620 | if (m-- == 0) | ||
| 621 | { | ||
| 622 | ret->d[--i]=l; | ||
| 623 | l=0; | ||
| 624 | m=BN_BYTES-1; | ||
| 625 | } | ||
| 626 | } | ||
| 627 | /* need to call this due to clear byte at top if avoiding | ||
| 628 | * having the top bit set (-ve number) */ | ||
| 629 | bn_fix_top(ret); | ||
| 630 | return(ret); | ||
| 631 | } | ||
| 632 | |||
| 633 | /* ignore negative */ | ||
| 634 | int BN_bn2bin(const BIGNUM *a, unsigned char *to) | ||
| 635 | { | ||
| 636 | int n,i; | ||
| 637 | BN_ULONG l; | ||
| 638 | |||
| 639 | n=i=BN_num_bytes(a); | ||
| 640 | while (i-- > 0) | ||
| 641 | { | ||
| 642 | l=a->d[i/BN_BYTES]; | ||
| 643 | *(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff; | ||
| 644 | } | ||
| 645 | return(n); | ||
| 646 | } | ||
| 647 | |||
| 648 | int BN_ucmp(const BIGNUM *a, const BIGNUM *b) | ||
| 649 | { | ||
| 650 | int i; | ||
| 651 | BN_ULONG t1,t2,*ap,*bp; | ||
| 652 | |||
| 653 | bn_check_top(a); | ||
| 654 | bn_check_top(b); | ||
| 655 | |||
| 656 | i=a->top-b->top; | ||
| 657 | if (i != 0) return(i); | ||
| 658 | ap=a->d; | ||
| 659 | bp=b->d; | ||
| 660 | for (i=a->top-1; i>=0; i--) | ||
| 661 | { | ||
| 662 | t1= ap[i]; | ||
| 663 | t2= bp[i]; | ||
| 664 | if (t1 != t2) | ||
| 665 | return(t1 > t2?1:-1); | ||
| 666 | } | ||
| 667 | return(0); | ||
| 668 | } | ||
| 669 | |||
| 670 | int BN_cmp(const BIGNUM *a, const BIGNUM *b) | ||
| 671 | { | ||
| 672 | int i; | ||
| 673 | int gt,lt; | ||
| 674 | BN_ULONG t1,t2; | ||
| 675 | |||
| 676 | if ((a == NULL) || (b == NULL)) | ||
| 677 | { | ||
| 678 | if (a != NULL) | ||
| 679 | return(-1); | ||
| 680 | else if (b != NULL) | ||
| 681 | return(1); | ||
| 682 | else | ||
| 683 | return(0); | ||
| 684 | } | ||
| 685 | |||
| 686 | bn_check_top(a); | ||
| 687 | bn_check_top(b); | ||
| 688 | |||
| 689 | if (a->neg != b->neg) | ||
| 690 | { | ||
| 691 | if (a->neg) | ||
| 692 | return(-1); | ||
| 693 | else return(1); | ||
| 694 | } | ||
| 695 | if (a->neg == 0) | ||
| 696 | { gt=1; lt= -1; } | ||
| 697 | else { gt= -1; lt=1; } | ||
| 698 | |||
| 699 | if (a->top > b->top) return(gt); | ||
| 700 | if (a->top < b->top) return(lt); | ||
| 701 | for (i=a->top-1; i>=0; i--) | ||
| 702 | { | ||
| 703 | t1=a->d[i]; | ||
| 704 | t2=b->d[i]; | ||
| 705 | if (t1 > t2) return(gt); | ||
| 706 | if (t1 < t2) return(lt); | ||
| 707 | } | ||
| 708 | return(0); | ||
| 709 | } | ||
| 710 | |||
| 711 | int BN_set_bit(BIGNUM *a, int n) | ||
| 712 | { | ||
| 713 | int i,j,k; | ||
| 714 | |||
| 715 | i=n/BN_BITS2; | ||
| 716 | j=n%BN_BITS2; | ||
| 717 | if (a->top <= i) | ||
| 718 | { | ||
| 719 | if (bn_wexpand(a,i+1) == NULL) return(0); | ||
| 720 | for(k=a->top; k<i+1; k++) | ||
| 721 | a->d[k]=0; | ||
| 722 | a->top=i+1; | ||
| 723 | } | ||
| 724 | |||
| 725 | a->d[i]|=(((BN_ULONG)1)<<j); | ||
| 726 | return(1); | ||
| 727 | } | ||
| 728 | |||
| 729 | int BN_clear_bit(BIGNUM *a, int n) | ||
| 730 | { | ||
| 731 | int i,j; | ||
| 732 | |||
| 733 | i=n/BN_BITS2; | ||
| 734 | j=n%BN_BITS2; | ||
| 735 | if (a->top <= i) return(0); | ||
| 736 | |||
| 737 | a->d[i]&=(~(((BN_ULONG)1)<<j)); | ||
| 738 | bn_fix_top(a); | ||
| 739 | return(1); | ||
| 740 | } | ||
| 741 | |||
| 742 | int BN_is_bit_set(const BIGNUM *a, int n) | ||
| 743 | { | ||
| 744 | int i,j; | ||
| 745 | |||
| 746 | if (n < 0) return(0); | ||
| 747 | i=n/BN_BITS2; | ||
| 748 | j=n%BN_BITS2; | ||
| 749 | if (a->top <= i) return(0); | ||
| 750 | return((a->d[i]&(((BN_ULONG)1)<<j))?1:0); | ||
| 751 | } | ||
| 752 | |||
| 753 | int BN_mask_bits(BIGNUM *a, int n) | ||
| 754 | { | ||
| 755 | int b,w; | ||
| 756 | |||
| 757 | w=n/BN_BITS2; | ||
| 758 | b=n%BN_BITS2; | ||
| 759 | if (w >= a->top) return(0); | ||
| 760 | if (b == 0) | ||
| 761 | a->top=w; | ||
| 762 | else | ||
| 763 | { | ||
| 764 | a->top=w+1; | ||
| 765 | a->d[w]&= ~(BN_MASK2<<b); | ||
| 766 | } | ||
| 767 | bn_fix_top(a); | ||
| 768 | return(1); | ||
| 769 | } | ||
| 770 | |||
| 771 | int bn_cmp_words(BN_ULONG *a, BN_ULONG *b, int n) | ||
| 772 | { | ||
| 773 | int i; | ||
| 774 | BN_ULONG aa,bb; | ||
| 775 | |||
| 776 | aa=a[n-1]; | ||
| 777 | bb=b[n-1]; | ||
| 778 | if (aa != bb) return((aa > bb)?1:-1); | ||
| 779 | for (i=n-2; i>=0; i--) | ||
| 780 | { | ||
| 781 | aa=a[i]; | ||
| 782 | bb=b[i]; | ||
| 783 | if (aa != bb) return((aa > bb)?1:-1); | ||
| 784 | } | ||
| 785 | return(0); | ||
| 786 | } | ||
| 787 | |||
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c deleted file mode 100644 index ee0f410c22..0000000000 --- a/src/lib/libcrypto/bn/bn_mont.c +++ /dev/null | |||
| @@ -1,407 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_mont.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* | ||
| 60 | * Details about Montgomery multiplication algorithms can be found at: | ||
| 61 | * http://www.ece.orst.edu/ISL/Publications.html | ||
| 62 | * http://www.ece.orst.edu/ISL/Koc/papers/j37acmon.pdf | ||
| 63 | */ | ||
| 64 | |||
| 65 | #include <stdio.h> | ||
| 66 | #include "cryptlib.h" | ||
| 67 | #include "bn_lcl.h" | ||
| 68 | |||
| 69 | #define MONT_WORD | ||
| 70 | |||
| 71 | int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, | ||
| 72 | BN_MONT_CTX *mont, BN_CTX *ctx) | ||
| 73 | { | ||
| 74 | BIGNUM *tmp,*tmp2; | ||
| 75 | |||
| 76 | tmp= &(ctx->bn[ctx->tos]); | ||
| 77 | tmp2= &(ctx->bn[ctx->tos]); | ||
| 78 | ctx->tos+=2; | ||
| 79 | |||
| 80 | bn_check_top(tmp); | ||
| 81 | bn_check_top(tmp2); | ||
| 82 | |||
| 83 | if (a == b) | ||
| 84 | { | ||
| 85 | #if 0 | ||
| 86 | bn_wexpand(tmp,a->top*2); | ||
| 87 | bn_wexpand(tmp2,a->top*4); | ||
| 88 | bn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d); | ||
| 89 | tmp->top=a->top*2; | ||
| 90 | if (tmp->d[tmp->top-1] == 0) | ||
| 91 | tmp->top--; | ||
| 92 | #else | ||
| 93 | if (!BN_sqr(tmp,a,ctx)) goto err; | ||
| 94 | #endif | ||
| 95 | } | ||
| 96 | else | ||
| 97 | { | ||
| 98 | if (!BN_mul(tmp,a,b,ctx)) goto err; | ||
| 99 | } | ||
| 100 | /* reduce from aRR to aR */ | ||
| 101 | if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err; | ||
| 102 | ctx->tos-=2; | ||
| 103 | return(1); | ||
| 104 | err: | ||
| 105 | return(0); | ||
| 106 | } | ||
| 107 | |||
| 108 | int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont, | ||
| 109 | BN_CTX *ctx) | ||
| 110 | { | ||
| 111 | #ifdef BN_RECURSION_MONT | ||
| 112 | if (mont->use_word) | ||
| 113 | #endif | ||
| 114 | { | ||
| 115 | BIGNUM *n,*r; | ||
| 116 | BN_ULONG *ap,*np,*rp,n0,v,*nrp; | ||
| 117 | int al,nl,max,i,x,ri; | ||
| 118 | int retn=0; | ||
| 119 | |||
| 120 | r= &(ctx->bn[ctx->tos]); | ||
| 121 | |||
| 122 | if (!BN_copy(r,a)) goto err1; | ||
| 123 | n= &(mont->N); | ||
| 124 | |||
| 125 | ap=a->d; | ||
| 126 | /* mont->ri is the size of mont->N in bits/words */ | ||
| 127 | al=ri=mont->ri/BN_BITS2; | ||
| 128 | |||
| 129 | nl=n->top; | ||
| 130 | if ((al == 0) || (nl == 0)) { r->top=0; return(1); } | ||
| 131 | |||
| 132 | max=(nl+al+1); /* allow for overflow (no?) XXX */ | ||
| 133 | if (bn_wexpand(r,max) == NULL) goto err1; | ||
| 134 | if (bn_wexpand(ret,max) == NULL) goto err1; | ||
| 135 | |||
| 136 | r->neg=a->neg^n->neg; | ||
| 137 | np=n->d; | ||
| 138 | rp=r->d; | ||
| 139 | nrp= &(r->d[nl]); | ||
| 140 | |||
| 141 | /* clear the top words of T */ | ||
| 142 | #if 1 | ||
| 143 | for (i=r->top; i<max; i++) /* memset? XXX */ | ||
| 144 | r->d[i]=0; | ||
| 145 | #else | ||
| 146 | memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG)); | ||
| 147 | #endif | ||
| 148 | |||
| 149 | r->top=max; | ||
| 150 | n0=mont->n0; | ||
| 151 | |||
| 152 | #ifdef BN_COUNT | ||
| 153 | printf("word BN_from_montgomery %d * %d\n",nl,nl); | ||
| 154 | #endif | ||
| 155 | for (i=0; i<nl; i++) | ||
| 156 | { | ||
| 157 | v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2); | ||
| 158 | nrp++; | ||
| 159 | rp++; | ||
| 160 | if (((nrp[-1]+=v)&BN_MASK2) >= v) | ||
| 161 | continue; | ||
| 162 | else | ||
| 163 | { | ||
| 164 | if (((++nrp[0])&BN_MASK2) != 0) continue; | ||
| 165 | if (((++nrp[1])&BN_MASK2) != 0) continue; | ||
| 166 | for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ; | ||
| 167 | } | ||
| 168 | } | ||
| 169 | bn_fix_top(r); | ||
| 170 | |||
| 171 | /* mont->ri will be a multiple of the word size */ | ||
| 172 | #if 0 | ||
| 173 | BN_rshift(ret,r,mont->ri); | ||
| 174 | #else | ||
| 175 | x=ri; | ||
| 176 | rp=ret->d; | ||
| 177 | ap= &(r->d[x]); | ||
| 178 | if (r->top < x) | ||
| 179 | al=0; | ||
| 180 | else | ||
| 181 | al=r->top-x; | ||
| 182 | ret->top=al; | ||
| 183 | al-=4; | ||
| 184 | for (i=0; i<al; i+=4) | ||
| 185 | { | ||
| 186 | BN_ULONG t1,t2,t3,t4; | ||
| 187 | |||
| 188 | t1=ap[i+0]; | ||
| 189 | t2=ap[i+1]; | ||
| 190 | t3=ap[i+2]; | ||
| 191 | t4=ap[i+3]; | ||
| 192 | rp[i+0]=t1; | ||
| 193 | rp[i+1]=t2; | ||
| 194 | rp[i+2]=t3; | ||
| 195 | rp[i+3]=t4; | ||
| 196 | } | ||
| 197 | al+=4; | ||
| 198 | for (; i<al; i++) | ||
| 199 | rp[i]=ap[i]; | ||
| 200 | #endif | ||
| 201 | |||
| 202 | if (BN_ucmp(ret, &(mont->N)) >= 0) | ||
| 203 | { | ||
| 204 | BN_usub(ret,ret,&(mont->N)); /* XXX */ | ||
| 205 | } | ||
| 206 | retn=1; | ||
| 207 | err1: | ||
| 208 | return(retn); | ||
| 209 | } | ||
| 210 | #ifdef BN_RECURSION_MONT | ||
| 211 | else /* bignum version */ | ||
| 212 | { | ||
| 213 | BIGNUM *t1,*t2,*t3; | ||
| 214 | int j,i; | ||
| 215 | |||
| 216 | #ifdef BN_COUNT | ||
| 217 | printf("number BN_from_montgomery\n"); | ||
| 218 | #endif | ||
| 219 | |||
| 220 | t1= &(ctx->bn[ctx->tos]); | ||
| 221 | t2= &(ctx->bn[ctx->tos+1]); | ||
| 222 | t3= &(ctx->bn[ctx->tos+2]); | ||
| 223 | |||
| 224 | i=mont->Ni.top; | ||
| 225 | bn_wexpand(ret,i); /* perhaps only i*2 */ | ||
| 226 | bn_wexpand(t1,i*4); /* perhaps only i*2 */ | ||
| 227 | bn_wexpand(t2,i*2); /* perhaps only i */ | ||
| 228 | |||
| 229 | bn_mul_low_recursive(t2->d,a->d,mont->Ni.d,i,t1->d); | ||
| 230 | |||
| 231 | BN_zero(t3); | ||
| 232 | BN_set_bit(t3,mont->N.top*BN_BITS2); | ||
| 233 | bn_sub_words(t3->d,t3->d,a->d,i); | ||
| 234 | bn_mul_high(ret->d,t2->d,mont->N.d,t3->d,i,t1->d); | ||
| 235 | |||
| 236 | /* hmm... if a is between i and 2*i, things are bad */ | ||
| 237 | if (a->top > i) | ||
| 238 | { | ||
| 239 | j=(int)(bn_add_words(ret->d,ret->d,&(a->d[i]),i)); | ||
| 240 | if (j) /* overflow */ | ||
| 241 | bn_sub_words(ret->d,ret->d,mont->N.d,i); | ||
| 242 | } | ||
| 243 | ret->top=i; | ||
| 244 | bn_fix_top(ret); | ||
| 245 | if (a->d[0]) | ||
| 246 | BN_add_word(ret,1); /* Always? */ | ||
| 247 | else /* Very very rare */ | ||
| 248 | { | ||
| 249 | for (i=1; i<mont->N.top-1; i++) | ||
| 250 | { | ||
| 251 | if (a->d[i]) | ||
| 252 | { | ||
| 253 | BN_add_word(ret,1); /* Always? */ | ||
| 254 | break; | ||
| 255 | } | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 259 | if (BN_ucmp(ret,&(mont->N)) >= 0) | ||
| 260 | BN_usub(ret,ret,&(mont->N)); | ||
| 261 | |||
| 262 | return(1); | ||
| 263 | } | ||
| 264 | #endif | ||
| 265 | } | ||
| 266 | |||
| 267 | BN_MONT_CTX *BN_MONT_CTX_new(void) | ||
| 268 | { | ||
| 269 | BN_MONT_CTX *ret; | ||
| 270 | |||
| 271 | if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL) | ||
| 272 | return(NULL); | ||
| 273 | |||
| 274 | BN_MONT_CTX_init(ret); | ||
| 275 | ret->flags=BN_FLG_MALLOCED; | ||
| 276 | return(ret); | ||
| 277 | } | ||
| 278 | |||
| 279 | void BN_MONT_CTX_init(BN_MONT_CTX *ctx) | ||
| 280 | { | ||
| 281 | ctx->use_word=0; | ||
| 282 | ctx->ri=0; | ||
| 283 | BN_init(&(ctx->RR)); | ||
| 284 | BN_init(&(ctx->N)); | ||
| 285 | BN_init(&(ctx->Ni)); | ||
| 286 | ctx->flags=0; | ||
| 287 | } | ||
| 288 | |||
| 289 | void BN_MONT_CTX_free(BN_MONT_CTX *mont) | ||
| 290 | { | ||
| 291 | if(mont == NULL) | ||
| 292 | return; | ||
| 293 | |||
| 294 | BN_free(&(mont->RR)); | ||
| 295 | BN_free(&(mont->N)); | ||
| 296 | BN_free(&(mont->Ni)); | ||
| 297 | if (mont->flags & BN_FLG_MALLOCED) | ||
| 298 | Free(mont); | ||
| 299 | } | ||
| 300 | |||
| 301 | int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx) | ||
| 302 | { | ||
| 303 | BIGNUM Ri,*R; | ||
| 304 | |||
| 305 | BN_init(&Ri); | ||
| 306 | R= &(mont->RR); /* grab RR as a temp */ | ||
| 307 | BN_copy(&(mont->N),mod); /* Set N */ | ||
| 308 | |||
| 309 | #ifdef BN_RECURSION_MONT | ||
| 310 | if (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD) | ||
| 311 | #endif | ||
| 312 | { | ||
| 313 | BIGNUM tmod; | ||
| 314 | BN_ULONG buf[2]; | ||
| 315 | |||
| 316 | mont->use_word=1; | ||
| 317 | |||
| 318 | mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2; | ||
| 319 | BN_zero(R); | ||
| 320 | BN_set_bit(R,BN_BITS2); | ||
| 321 | /* I was bad, this modification of a passed variable was | ||
| 322 | * breaking the multithreaded stuff :-( | ||
| 323 | * z=mod->top; | ||
| 324 | * mod->top=1; */ | ||
| 325 | |||
| 326 | buf[0]=mod->d[0]; | ||
| 327 | buf[1]=0; | ||
| 328 | tmod.d=buf; | ||
| 329 | tmod.top=1; | ||
| 330 | tmod.max=mod->max; | ||
| 331 | tmod.neg=mod->neg; | ||
| 332 | |||
| 333 | if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL) | ||
| 334 | goto err; | ||
| 335 | BN_lshift(&Ri,&Ri,BN_BITS2); /* R*Ri */ | ||
| 336 | if (!BN_is_zero(&Ri)) | ||
| 337 | { | ||
| 338 | #if 1 | ||
| 339 | BN_sub_word(&Ri,1); | ||
| 340 | #else | ||
| 341 | BN_usub(&Ri,&Ri,BN_value_one()); /* R*Ri - 1 */ | ||
| 342 | #endif | ||
| 343 | } | ||
| 344 | else | ||
| 345 | { | ||
| 346 | /* This is not common..., 1 in BN_MASK2, | ||
| 347 | * It happens when buf[0] was == 1. So for 8 bit, | ||
| 348 | * this is 1/256, 16bit, 1 in 2^16 etc. | ||
| 349 | */ | ||
| 350 | BN_set_word(&Ri,BN_MASK2); | ||
| 351 | } | ||
| 352 | BN_div(&Ri,NULL,&Ri,&tmod,ctx); | ||
| 353 | mont->n0=Ri.d[0]; | ||
| 354 | BN_free(&Ri); | ||
| 355 | /* mod->top=z; */ | ||
| 356 | } | ||
| 357 | #ifdef BN_RECURSION_MONT | ||
| 358 | else | ||
| 359 | { | ||
| 360 | mont->use_word=0; | ||
| 361 | mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2; | ||
| 362 | #if 1 | ||
| 363 | BN_zero(R); | ||
| 364 | BN_set_bit(R,mont->ri); | ||
| 365 | #else | ||
| 366 | BN_lshift(R,BN_value_one(),mont->ri); /* R */ | ||
| 367 | #endif | ||
| 368 | if ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL) | ||
| 369 | goto err; | ||
| 370 | BN_lshift(&Ri,&Ri,mont->ri); /* R*Ri */ | ||
| 371 | #if 1 | ||
| 372 | BN_sub_word(&Ri,1); | ||
| 373 | #else | ||
| 374 | BN_usub(&Ri,&Ri,BN_value_one()); /* R*Ri - 1 */ | ||
| 375 | #endif | ||
| 376 | BN_div(&(mont->Ni),NULL,&Ri,mod,ctx); | ||
| 377 | BN_free(&Ri); | ||
| 378 | } | ||
| 379 | #endif | ||
| 380 | |||
| 381 | /* setup RR for conversions */ | ||
| 382 | #if 1 | ||
| 383 | BN_zero(&(mont->RR)); | ||
| 384 | BN_set_bit(&(mont->RR),mont->ri*2); | ||
| 385 | #else | ||
| 386 | BN_lshift(mont->RR,BN_value_one(),mont->ri*2); | ||
| 387 | #endif | ||
| 388 | BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx); | ||
| 389 | |||
| 390 | return(1); | ||
| 391 | err: | ||
| 392 | return(0); | ||
| 393 | } | ||
| 394 | |||
| 395 | BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from) | ||
| 396 | { | ||
| 397 | if (to == from) return(to); | ||
| 398 | |||
| 399 | BN_copy(&(to->RR),&(from->RR)); | ||
| 400 | BN_copy(&(to->N),&(from->N)); | ||
| 401 | BN_copy(&(to->Ni),&(from->Ni)); | ||
| 402 | to->use_word=from->use_word; | ||
| 403 | to->ri=from->ri; | ||
| 404 | to->n0=from->n0; | ||
| 405 | return(to); | ||
| 406 | } | ||
| 407 | |||
diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c deleted file mode 100644 index 80e1dca6b7..0000000000 --- a/src/lib/libcrypto/bn/bn_mpi.c +++ /dev/null | |||
| @@ -1,129 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_mpi.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | int BN_bn2mpi(const BIGNUM *a, unsigned char *d) | ||
| 64 | { | ||
| 65 | int bits; | ||
| 66 | int num=0; | ||
| 67 | int ext=0; | ||
| 68 | long l; | ||
| 69 | |||
| 70 | bits=BN_num_bits(a); | ||
| 71 | num=(bits+7)/8; | ||
| 72 | if (bits > 0) | ||
| 73 | { | ||
| 74 | ext=((bits & 0x07) == 0); | ||
| 75 | } | ||
| 76 | if (d == NULL) | ||
| 77 | return(num+4+ext); | ||
| 78 | |||
| 79 | l=num+ext; | ||
| 80 | d[0]=(unsigned char)(l>>24)&0xff; | ||
| 81 | d[1]=(unsigned char)(l>>16)&0xff; | ||
| 82 | d[2]=(unsigned char)(l>> 8)&0xff; | ||
| 83 | d[3]=(unsigned char)(l )&0xff; | ||
| 84 | if (ext) d[4]=0; | ||
| 85 | num=BN_bn2bin(a,&(d[4+ext])); | ||
| 86 | if (a->neg) | ||
| 87 | d[4]|=0x80; | ||
| 88 | return(num+4+ext); | ||
| 89 | } | ||
| 90 | |||
| 91 | BIGNUM *BN_mpi2bn(unsigned char *d, int n, BIGNUM *a) | ||
| 92 | { | ||
| 93 | long len; | ||
| 94 | int neg=0; | ||
| 95 | |||
| 96 | if (n < 4) | ||
| 97 | { | ||
| 98 | BNerr(BN_F_BN_MPI2BN,BN_R_INVALID_LENGTH); | ||
| 99 | return(NULL); | ||
| 100 | } | ||
| 101 | len=((long)d[0]<<24)|((long)d[1]<<16)|((int)d[2]<<8)|(int)d[3]; | ||
| 102 | if ((len+4) != n) | ||
| 103 | { | ||
| 104 | BNerr(BN_F_BN_MPI2BN,BN_R_ENCODING_ERROR); | ||
| 105 | return(NULL); | ||
| 106 | } | ||
| 107 | |||
| 108 | if (a == NULL) a=BN_new(); | ||
| 109 | if (a == NULL) return(NULL); | ||
| 110 | |||
| 111 | if (len == 0) | ||
| 112 | { | ||
| 113 | a->neg=0; | ||
| 114 | a->top=0; | ||
| 115 | return(a); | ||
| 116 | } | ||
| 117 | d+=4; | ||
| 118 | if ((*d) & 0x80) | ||
| 119 | neg=1; | ||
| 120 | if (BN_bin2bn(d,(int)len,a) == NULL) | ||
| 121 | return(NULL); | ||
| 122 | a->neg=neg; | ||
| 123 | if (neg) | ||
| 124 | { | ||
| 125 | BN_clear_bit(a,BN_num_bits(a)-1); | ||
| 126 | } | ||
| 127 | return(a); | ||
| 128 | } | ||
| 129 | |||
diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c deleted file mode 100644 index 38c47f3d1f..0000000000 --- a/src/lib/libcrypto/bn/bn_mul.c +++ /dev/null | |||
| @@ -1,756 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_mul.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | #ifdef BN_RECURSION | ||
| 64 | /* r is 2*n2 words in size, | ||
| 65 | * a and b are both n2 words in size. | ||
| 66 | * n2 must be a power of 2. | ||
| 67 | * We multiply and return the result. | ||
| 68 | * t must be 2*n2 words in size | ||
| 69 | * We calulate | ||
| 70 | * a[0]*b[0] | ||
| 71 | * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) | ||
| 72 | * a[1]*b[1] | ||
| 73 | */ | ||
| 74 | void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, | ||
| 75 | BN_ULONG *t) | ||
| 76 | { | ||
| 77 | int n=n2/2,c1,c2; | ||
| 78 | unsigned int neg,zero; | ||
| 79 | BN_ULONG ln,lo,*p; | ||
| 80 | |||
| 81 | #ifdef BN_COUNT | ||
| 82 | printf(" bn_mul_recursive %d * %d\n",n2,n2); | ||
| 83 | #endif | ||
| 84 | #ifdef BN_MUL_COMBA | ||
| 85 | /* if (n2 == 4) | ||
| 86 | { | ||
| 87 | bn_mul_comba4(r,a,b); | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | else */ if (n2 == 8) | ||
| 91 | { | ||
| 92 | bn_mul_comba8(r,a,b); | ||
| 93 | return; | ||
| 94 | } | ||
| 95 | #endif | ||
| 96 | if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) | ||
| 97 | { | ||
| 98 | /* This should not happen */ | ||
| 99 | bn_mul_normal(r,a,n2,b,n2); | ||
| 100 | return; | ||
| 101 | } | ||
| 102 | /* r=(a[0]-a[1])*(b[1]-b[0]) */ | ||
| 103 | c1=bn_cmp_words(a,&(a[n]),n); | ||
| 104 | c2=bn_cmp_words(&(b[n]),b,n); | ||
| 105 | zero=neg=0; | ||
| 106 | switch (c1*3+c2) | ||
| 107 | { | ||
| 108 | case -4: | ||
| 109 | bn_sub_words(t, &(a[n]),a, n); /* - */ | ||
| 110 | bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ | ||
| 111 | break; | ||
| 112 | case -3: | ||
| 113 | zero=1; | ||
| 114 | break; | ||
| 115 | case -2: | ||
| 116 | bn_sub_words(t, &(a[n]),a, n); /* - */ | ||
| 117 | bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */ | ||
| 118 | neg=1; | ||
| 119 | break; | ||
| 120 | case -1: | ||
| 121 | case 0: | ||
| 122 | case 1: | ||
| 123 | zero=1; | ||
| 124 | break; | ||
| 125 | case 2: | ||
| 126 | bn_sub_words(t, a, &(a[n]),n); /* + */ | ||
| 127 | bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ | ||
| 128 | neg=1; | ||
| 129 | break; | ||
| 130 | case 3: | ||
| 131 | zero=1; | ||
| 132 | break; | ||
| 133 | case 4: | ||
| 134 | bn_sub_words(t, a, &(a[n]),n); | ||
| 135 | bn_sub_words(&(t[n]),&(b[n]),b, n); | ||
| 136 | break; | ||
| 137 | } | ||
| 138 | |||
| 139 | #ifdef BN_MUL_COMBA | ||
| 140 | if (n == 4) | ||
| 141 | { | ||
| 142 | if (!zero) | ||
| 143 | bn_mul_comba4(&(t[n2]),t,&(t[n])); | ||
| 144 | else | ||
| 145 | memset(&(t[n2]),0,8*sizeof(BN_ULONG)); | ||
| 146 | |||
| 147 | bn_mul_comba4(r,a,b); | ||
| 148 | bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n])); | ||
| 149 | } | ||
| 150 | else if (n == 8) | ||
| 151 | { | ||
| 152 | if (!zero) | ||
| 153 | bn_mul_comba8(&(t[n2]),t,&(t[n])); | ||
| 154 | else | ||
| 155 | memset(&(t[n2]),0,16*sizeof(BN_ULONG)); | ||
| 156 | |||
| 157 | bn_mul_comba8(r,a,b); | ||
| 158 | bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n])); | ||
| 159 | } | ||
| 160 | else | ||
| 161 | #endif | ||
| 162 | { | ||
| 163 | p= &(t[n2*2]); | ||
| 164 | if (!zero) | ||
| 165 | bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); | ||
| 166 | else | ||
| 167 | memset(&(t[n2]),0,n2*sizeof(BN_ULONG)); | ||
| 168 | bn_mul_recursive(r,a,b,n,p); | ||
| 169 | bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p); | ||
| 170 | } | ||
| 171 | |||
| 172 | /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign | ||
| 173 | * r[10] holds (a[0]*b[0]) | ||
| 174 | * r[32] holds (b[1]*b[1]) | ||
| 175 | */ | ||
| 176 | |||
| 177 | c1=(int)(bn_add_words(t,r,&(r[n2]),n2)); | ||
| 178 | |||
| 179 | if (neg) /* if t[32] is negative */ | ||
| 180 | { | ||
| 181 | c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2)); | ||
| 182 | } | ||
| 183 | else | ||
| 184 | { | ||
| 185 | /* Might have a carry */ | ||
| 186 | c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2)); | ||
| 187 | } | ||
| 188 | |||
| 189 | /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1]) | ||
| 190 | * r[10] holds (a[0]*b[0]) | ||
| 191 | * r[32] holds (b[1]*b[1]) | ||
| 192 | * c1 holds the carry bits | ||
| 193 | */ | ||
| 194 | c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2)); | ||
| 195 | if (c1) | ||
| 196 | { | ||
| 197 | p= &(r[n+n2]); | ||
| 198 | lo= *p; | ||
| 199 | ln=(lo+c1)&BN_MASK2; | ||
| 200 | *p=ln; | ||
| 201 | |||
| 202 | /* The overflow will stop before we over write | ||
| 203 | * words we should not overwrite */ | ||
| 204 | if (ln < (BN_ULONG)c1) | ||
| 205 | { | ||
| 206 | do { | ||
| 207 | p++; | ||
| 208 | lo= *p; | ||
| 209 | ln=(lo+1)&BN_MASK2; | ||
| 210 | *p=ln; | ||
| 211 | } while (ln == 0); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | } | ||
| 215 | |||
| 216 | /* n+tn is the word length | ||
| 217 | * t needs to be n*4 is size, as does r */ | ||
| 218 | void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn, | ||
| 219 | int n, BN_ULONG *t) | ||
| 220 | { | ||
| 221 | int i,j,n2=n*2; | ||
| 222 | unsigned int c1; | ||
| 223 | BN_ULONG ln,lo,*p; | ||
| 224 | |||
| 225 | #ifdef BN_COUNT | ||
| 226 | printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n); | ||
| 227 | #endif | ||
| 228 | if (n < 8) | ||
| 229 | { | ||
| 230 | i=tn+n; | ||
| 231 | bn_mul_normal(r,a,i,b,i); | ||
| 232 | return; | ||
| 233 | } | ||
| 234 | |||
| 235 | /* r=(a[0]-a[1])*(b[1]-b[0]) */ | ||
| 236 | bn_sub_words(t, a, &(a[n]),n); /* + */ | ||
| 237 | bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ | ||
| 238 | |||
| 239 | /* if (n == 4) | ||
| 240 | { | ||
| 241 | bn_mul_comba4(&(t[n2]),t,&(t[n])); | ||
| 242 | bn_mul_comba4(r,a,b); | ||
| 243 | bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); | ||
| 244 | memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2)); | ||
| 245 | } | ||
| 246 | else */ if (n == 8) | ||
| 247 | { | ||
| 248 | bn_mul_comba8(&(t[n2]),t,&(t[n])); | ||
| 249 | bn_mul_comba8(r,a,b); | ||
| 250 | bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); | ||
| 251 | memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2)); | ||
| 252 | } | ||
| 253 | else | ||
| 254 | { | ||
| 255 | p= &(t[n2*2]); | ||
| 256 | bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); | ||
| 257 | bn_mul_recursive(r,a,b,n,p); | ||
| 258 | i=n/2; | ||
| 259 | /* If there is only a bottom half to the number, | ||
| 260 | * just do it */ | ||
| 261 | j=tn-i; | ||
| 262 | if (j == 0) | ||
| 263 | { | ||
| 264 | bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p); | ||
| 265 | memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2)); | ||
| 266 | } | ||
| 267 | else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */ | ||
| 268 | { | ||
| 269 | bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]), | ||
| 270 | j,i,p); | ||
| 271 | memset(&(r[n2+tn*2]),0, | ||
| 272 | sizeof(BN_ULONG)*(n2-tn*2)); | ||
| 273 | } | ||
| 274 | else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */ | ||
| 275 | { | ||
| 276 | memset(&(r[n2]),0,sizeof(BN_ULONG)*n2); | ||
| 277 | if (tn < BN_MUL_RECURSIVE_SIZE_NORMAL) | ||
| 278 | { | ||
| 279 | bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); | ||
| 280 | } | ||
| 281 | else | ||
| 282 | { | ||
| 283 | for (;;) | ||
| 284 | { | ||
| 285 | i/=2; | ||
| 286 | if (i < tn) | ||
| 287 | { | ||
| 288 | bn_mul_part_recursive(&(r[n2]), | ||
| 289 | &(a[n]),&(b[n]), | ||
| 290 | tn-i,i,p); | ||
| 291 | break; | ||
| 292 | } | ||
| 293 | else if (i == tn) | ||
| 294 | { | ||
| 295 | bn_mul_recursive(&(r[n2]), | ||
| 296 | &(a[n]),&(b[n]), | ||
| 297 | i,p); | ||
| 298 | break; | ||
| 299 | } | ||
| 300 | } | ||
| 301 | } | ||
| 302 | } | ||
| 303 | } | ||
| 304 | |||
| 305 | /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign | ||
| 306 | * r[10] holds (a[0]*b[0]) | ||
| 307 | * r[32] holds (b[1]*b[1]) | ||
| 308 | */ | ||
| 309 | |||
| 310 | c1=(int)(bn_add_words(t,r,&(r[n2]),n2)); | ||
| 311 | c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2)); | ||
| 312 | |||
| 313 | /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1]) | ||
| 314 | * r[10] holds (a[0]*b[0]) | ||
| 315 | * r[32] holds (b[1]*b[1]) | ||
| 316 | * c1 holds the carry bits | ||
| 317 | */ | ||
| 318 | c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2)); | ||
| 319 | if (c1) | ||
| 320 | { | ||
| 321 | p= &(r[n+n2]); | ||
| 322 | lo= *p; | ||
| 323 | ln=(lo+c1)&BN_MASK2; | ||
| 324 | *p=ln; | ||
| 325 | |||
| 326 | /* The overflow will stop before we over write | ||
| 327 | * words we should not overwrite */ | ||
| 328 | if (ln < c1) | ||
| 329 | { | ||
| 330 | do { | ||
| 331 | p++; | ||
| 332 | lo= *p; | ||
| 333 | ln=(lo+1)&BN_MASK2; | ||
| 334 | *p=ln; | ||
| 335 | } while (ln == 0); | ||
| 336 | } | ||
| 337 | } | ||
| 338 | } | ||
| 339 | |||
| 340 | /* a and b must be the same size, which is n2. | ||
| 341 | * r needs to be n2 words and t needs to be n2*2 | ||
| 342 | */ | ||
| 343 | void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, | ||
| 344 | BN_ULONG *t) | ||
| 345 | { | ||
| 346 | int n=n2/2; | ||
| 347 | |||
| 348 | #ifdef BN_COUNT | ||
| 349 | printf(" bn_mul_low_recursive %d * %d\n",n2,n2); | ||
| 350 | #endif | ||
| 351 | |||
| 352 | bn_mul_recursive(r,a,b,n,&(t[0])); | ||
| 353 | if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL) | ||
| 354 | { | ||
| 355 | bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2])); | ||
| 356 | bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); | ||
| 357 | bn_mul_low_recursive(&(t[0]),&(a[n]),&(b[0]),n,&(t[n2])); | ||
| 358 | bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); | ||
| 359 | } | ||
| 360 | else | ||
| 361 | { | ||
| 362 | bn_mul_low_normal(&(t[0]),&(a[0]),&(b[n]),n); | ||
| 363 | bn_mul_low_normal(&(t[n]),&(a[n]),&(b[0]),n); | ||
| 364 | bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); | ||
| 365 | bn_add_words(&(r[n]),&(r[n]),&(t[n]),n); | ||
| 366 | } | ||
| 367 | } | ||
| 368 | |||
| 369 | /* a and b must be the same size, which is n2. | ||
| 370 | * r needs to be n2 words and t needs to be n2*2 | ||
| 371 | * l is the low words of the output. | ||
| 372 | * t needs to be n2*3 | ||
| 373 | */ | ||
| 374 | void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2, | ||
| 375 | BN_ULONG *t) | ||
| 376 | { | ||
| 377 | int i,n; | ||
| 378 | int c1,c2; | ||
| 379 | int neg,oneg,zero; | ||
| 380 | BN_ULONG ll,lc,*lp,*mp; | ||
| 381 | |||
| 382 | #ifdef BN_COUNT | ||
| 383 | printf(" bn_mul_high %d * %d\n",n2,n2); | ||
| 384 | #endif | ||
| 385 | n=n2/2; | ||
| 386 | |||
| 387 | /* Calculate (al-ah)*(bh-bl) */ | ||
| 388 | neg=zero=0; | ||
| 389 | c1=bn_cmp_words(&(a[0]),&(a[n]),n); | ||
| 390 | c2=bn_cmp_words(&(b[n]),&(b[0]),n); | ||
| 391 | switch (c1*3+c2) | ||
| 392 | { | ||
| 393 | case -4: | ||
| 394 | bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n); | ||
| 395 | bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n); | ||
| 396 | break; | ||
| 397 | case -3: | ||
| 398 | zero=1; | ||
| 399 | break; | ||
| 400 | case -2: | ||
| 401 | bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n); | ||
| 402 | bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n); | ||
| 403 | neg=1; | ||
| 404 | break; | ||
| 405 | case -1: | ||
| 406 | case 0: | ||
| 407 | case 1: | ||
| 408 | zero=1; | ||
| 409 | break; | ||
| 410 | case 2: | ||
| 411 | bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n); | ||
| 412 | bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n); | ||
| 413 | neg=1; | ||
| 414 | break; | ||
| 415 | case 3: | ||
| 416 | zero=1; | ||
| 417 | break; | ||
| 418 | case 4: | ||
| 419 | bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n); | ||
| 420 | bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n); | ||
| 421 | break; | ||
| 422 | } | ||
| 423 | |||
| 424 | oneg=neg; | ||
| 425 | /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */ | ||
| 426 | /* r[10] = (a[1]*b[1]) */ | ||
| 427 | #ifdef BN_MUL_COMBA | ||
| 428 | if (n == 8) | ||
| 429 | { | ||
| 430 | bn_mul_comba8(&(t[0]),&(r[0]),&(r[n])); | ||
| 431 | bn_mul_comba8(r,&(a[n]),&(b[n])); | ||
| 432 | } | ||
| 433 | else | ||
| 434 | #endif | ||
| 435 | { | ||
| 436 | bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2])); | ||
| 437 | bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2])); | ||
| 438 | } | ||
| 439 | |||
| 440 | /* s0 == low(al*bl) | ||
| 441 | * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl) | ||
| 442 | * We know s0 and s1 so the only unknown is high(al*bl) | ||
| 443 | * high(al*bl) == s1 - low(ah*bh+s0+(al-ah)*(bh-bl)) | ||
| 444 | * high(al*bl) == s1 - (r[0]+l[0]+t[0]) | ||
| 445 | */ | ||
| 446 | if (l != NULL) | ||
| 447 | { | ||
| 448 | lp= &(t[n2+n]); | ||
| 449 | c1=(int)(bn_add_words(lp,&(r[0]),&(l[0]),n)); | ||
| 450 | } | ||
| 451 | else | ||
| 452 | { | ||
| 453 | c1=0; | ||
| 454 | lp= &(r[0]); | ||
| 455 | } | ||
| 456 | |||
| 457 | if (neg) | ||
| 458 | neg=(int)(bn_sub_words(&(t[n2]),lp,&(t[0]),n)); | ||
| 459 | else | ||
| 460 | { | ||
| 461 | bn_add_words(&(t[n2]),lp,&(t[0]),n); | ||
| 462 | neg=0; | ||
| 463 | } | ||
| 464 | |||
| 465 | if (l != NULL) | ||
| 466 | { | ||
| 467 | bn_sub_words(&(t[n2+n]),&(l[n]),&(t[n2]),n); | ||
| 468 | } | ||
| 469 | else | ||
| 470 | { | ||
| 471 | lp= &(t[n2+n]); | ||
| 472 | mp= &(t[n2]); | ||
| 473 | for (i=0; i<n; i++) | ||
| 474 | lp[i]=((~mp[i])+1)&BN_MASK2; | ||
| 475 | } | ||
| 476 | |||
| 477 | /* s[0] = low(al*bl) | ||
| 478 | * t[3] = high(al*bl) | ||
| 479 | * t[10] = (a[0]-a[1])*(b[1]-b[0]) neg is the sign | ||
| 480 | * r[10] = (a[1]*b[1]) | ||
| 481 | */ | ||
| 482 | /* R[10] = al*bl | ||
| 483 | * R[21] = al*bl + ah*bh + (a[0]-a[1])*(b[1]-b[0]) | ||
| 484 | * R[32] = ah*bh | ||
| 485 | */ | ||
| 486 | /* R[1]=t[3]+l[0]+r[0](+-)t[0] (have carry/borrow) | ||
| 487 | * R[2]=r[0]+t[3]+r[1](+-)t[1] (have carry/borrow) | ||
| 488 | * R[3]=r[1]+(carry/borrow) | ||
| 489 | */ | ||
| 490 | if (l != NULL) | ||
| 491 | { | ||
| 492 | lp= &(t[n2]); | ||
| 493 | c1= (int)(bn_add_words(lp,&(t[n2+n]),&(l[0]),n)); | ||
| 494 | } | ||
| 495 | else | ||
| 496 | { | ||
| 497 | lp= &(t[n2+n]); | ||
| 498 | c1=0; | ||
| 499 | } | ||
| 500 | c1+=(int)(bn_add_words(&(t[n2]),lp, &(r[0]),n)); | ||
| 501 | if (oneg) | ||
| 502 | c1-=(int)(bn_sub_words(&(t[n2]),&(t[n2]),&(t[0]),n)); | ||
| 503 | else | ||
| 504 | c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),&(t[0]),n)); | ||
| 505 | |||
| 506 | c2 =(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n2+n]),n)); | ||
| 507 | c2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(r[n]),n)); | ||
| 508 | if (oneg) | ||
| 509 | c2-=(int)(bn_sub_words(&(r[0]),&(r[0]),&(t[n]),n)); | ||
| 510 | else | ||
| 511 | c2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n]),n)); | ||
| 512 | |||
| 513 | if (c1 != 0) /* Add starting at r[0], could be +ve or -ve */ | ||
| 514 | { | ||
| 515 | i=0; | ||
| 516 | if (c1 > 0) | ||
| 517 | { | ||
| 518 | lc=c1; | ||
| 519 | do { | ||
| 520 | ll=(r[i]+lc)&BN_MASK2; | ||
| 521 | r[i++]=ll; | ||
| 522 | lc=(lc > ll); | ||
| 523 | } while (lc); | ||
| 524 | } | ||
| 525 | else | ||
| 526 | { | ||
| 527 | lc= -c1; | ||
| 528 | do { | ||
| 529 | ll=r[i]; | ||
| 530 | r[i++]=(ll-lc)&BN_MASK2; | ||
| 531 | lc=(lc > ll); | ||
| 532 | } while (lc); | ||
| 533 | } | ||
| 534 | } | ||
| 535 | if (c2 != 0) /* Add starting at r[1] */ | ||
| 536 | { | ||
| 537 | i=n; | ||
| 538 | if (c2 > 0) | ||
| 539 | { | ||
| 540 | lc=c2; | ||
| 541 | do { | ||
| 542 | ll=(r[i]+lc)&BN_MASK2; | ||
| 543 | r[i++]=ll; | ||
| 544 | lc=(lc > ll); | ||
| 545 | } while (lc); | ||
| 546 | } | ||
| 547 | else | ||
| 548 | { | ||
| 549 | lc= -c2; | ||
| 550 | do { | ||
| 551 | ll=r[i]; | ||
| 552 | r[i++]=(ll-lc)&BN_MASK2; | ||
| 553 | lc=(lc > ll); | ||
| 554 | } while (lc); | ||
| 555 | } | ||
| 556 | } | ||
| 557 | } | ||
| 558 | #endif | ||
| 559 | |||
| 560 | int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) | ||
| 561 | { | ||
| 562 | int top,al,bl; | ||
| 563 | BIGNUM *rr; | ||
| 564 | #ifdef BN_RECURSION | ||
| 565 | BIGNUM *t; | ||
| 566 | int i,j,k; | ||
| 567 | #endif | ||
| 568 | |||
| 569 | #ifdef BN_COUNT | ||
| 570 | printf("BN_mul %d * %d\n",a->top,b->top); | ||
| 571 | #endif | ||
| 572 | |||
| 573 | bn_check_top(a); | ||
| 574 | bn_check_top(b); | ||
| 575 | bn_check_top(r); | ||
| 576 | |||
| 577 | al=a->top; | ||
| 578 | bl=b->top; | ||
| 579 | r->neg=a->neg^b->neg; | ||
| 580 | |||
| 581 | if ((al == 0) || (bl == 0)) | ||
| 582 | { | ||
| 583 | BN_zero(r); | ||
| 584 | return(1); | ||
| 585 | } | ||
| 586 | top=al+bl; | ||
| 587 | |||
| 588 | if ((r == a) || (r == b)) | ||
| 589 | rr= &(ctx->bn[ctx->tos+1]); | ||
| 590 | else | ||
| 591 | rr=r; | ||
| 592 | |||
| 593 | #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) | ||
| 594 | if (al == bl) | ||
| 595 | { | ||
| 596 | # ifdef BN_MUL_COMBA | ||
| 597 | /* if (al == 4) | ||
| 598 | { | ||
| 599 | if (bn_wexpand(rr,8) == NULL) return(0); | ||
| 600 | rr->top=8; | ||
| 601 | bn_mul_comba4(rr->d,a->d,b->d); | ||
| 602 | goto end; | ||
| 603 | } | ||
| 604 | else */ if (al == 8) | ||
| 605 | { | ||
| 606 | if (bn_wexpand(rr,16) == NULL) return(0); | ||
| 607 | rr->top=16; | ||
| 608 | bn_mul_comba8(rr->d,a->d,b->d); | ||
| 609 | goto end; | ||
| 610 | } | ||
| 611 | else | ||
| 612 | # endif | ||
| 613 | #ifdef BN_RECURSION | ||
| 614 | if (al < BN_MULL_SIZE_NORMAL) | ||
| 615 | #endif | ||
| 616 | { | ||
| 617 | if (bn_wexpand(rr,top) == NULL) return(0); | ||
| 618 | rr->top=top; | ||
| 619 | bn_mul_normal(rr->d,a->d,al,b->d,bl); | ||
| 620 | goto end; | ||
| 621 | } | ||
| 622 | # ifdef BN_RECURSION | ||
| 623 | goto symetric; | ||
| 624 | # endif | ||
| 625 | } | ||
| 626 | #endif | ||
| 627 | #ifdef BN_RECURSION | ||
| 628 | else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL)) | ||
| 629 | { | ||
| 630 | if (bn_wexpand(rr,top) == NULL) return(0); | ||
| 631 | rr->top=top; | ||
| 632 | bn_mul_normal(rr->d,a->d,al,b->d,bl); | ||
| 633 | goto end; | ||
| 634 | } | ||
| 635 | else | ||
| 636 | { | ||
| 637 | i=(al-bl); | ||
| 638 | if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA)) | ||
| 639 | { | ||
| 640 | bn_wexpand(b,al); | ||
| 641 | b->d[bl]=0; | ||
| 642 | bl++; | ||
| 643 | goto symetric; | ||
| 644 | } | ||
| 645 | else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA)) | ||
| 646 | { | ||
| 647 | bn_wexpand(a,bl); | ||
| 648 | a->d[al]=0; | ||
| 649 | al++; | ||
| 650 | goto symetric; | ||
| 651 | } | ||
| 652 | } | ||
| 653 | #endif | ||
| 654 | |||
| 655 | /* asymetric and >= 4 */ | ||
| 656 | if (bn_wexpand(rr,top) == NULL) return(0); | ||
| 657 | rr->top=top; | ||
| 658 | bn_mul_normal(rr->d,a->d,al,b->d,bl); | ||
| 659 | |||
| 660 | #ifdef BN_RECURSION | ||
| 661 | if (0) | ||
| 662 | { | ||
| 663 | symetric: | ||
| 664 | /* symetric and > 4 */ | ||
| 665 | /* 16 or larger */ | ||
| 666 | j=BN_num_bits_word((BN_ULONG)al); | ||
| 667 | j=1<<(j-1); | ||
| 668 | k=j+j; | ||
| 669 | t= &(ctx->bn[ctx->tos]); | ||
| 670 | if (al == j) /* exact multiple */ | ||
| 671 | { | ||
| 672 | bn_wexpand(t,k*2); | ||
| 673 | bn_wexpand(rr,k*2); | ||
| 674 | bn_mul_recursive(rr->d,a->d,b->d,al,t->d); | ||
| 675 | } | ||
| 676 | else | ||
| 677 | { | ||
| 678 | bn_wexpand(a,k); | ||
| 679 | bn_wexpand(b,k); | ||
| 680 | bn_wexpand(t,k*4); | ||
| 681 | bn_wexpand(rr,k*4); | ||
| 682 | for (i=a->top; i<k; i++) | ||
| 683 | a->d[i]=0; | ||
| 684 | for (i=b->top; i<k; i++) | ||
| 685 | b->d[i]=0; | ||
| 686 | bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d); | ||
| 687 | } | ||
| 688 | rr->top=top; | ||
| 689 | } | ||
| 690 | #endif | ||
| 691 | #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) | ||
| 692 | end: | ||
| 693 | #endif | ||
| 694 | bn_fix_top(rr); | ||
| 695 | if (r != rr) BN_copy(r,rr); | ||
| 696 | return(1); | ||
| 697 | } | ||
| 698 | |||
| 699 | void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb) | ||
| 700 | { | ||
| 701 | BN_ULONG *rr; | ||
| 702 | |||
| 703 | #ifdef BN_COUNT | ||
| 704 | printf(" bn_mul_normal %d * %d\n",na,nb); | ||
| 705 | #endif | ||
| 706 | |||
| 707 | if (na < nb) | ||
| 708 | { | ||
| 709 | int itmp; | ||
| 710 | BN_ULONG *ltmp; | ||
| 711 | |||
| 712 | itmp=na; na=nb; nb=itmp; | ||
| 713 | ltmp=a; a=b; b=ltmp; | ||
| 714 | |||
| 715 | } | ||
| 716 | rr= &(r[na]); | ||
| 717 | rr[0]=bn_mul_words(r,a,na,b[0]); | ||
| 718 | |||
| 719 | for (;;) | ||
| 720 | { | ||
| 721 | if (--nb <= 0) return; | ||
| 722 | rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]); | ||
| 723 | if (--nb <= 0) return; | ||
| 724 | rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]); | ||
| 725 | if (--nb <= 0) return; | ||
| 726 | rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]); | ||
| 727 | if (--nb <= 0) return; | ||
| 728 | rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]); | ||
| 729 | rr+=4; | ||
| 730 | r+=4; | ||
| 731 | b+=4; | ||
| 732 | } | ||
| 733 | } | ||
| 734 | |||
| 735 | void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) | ||
| 736 | { | ||
| 737 | #ifdef BN_COUNT | ||
| 738 | printf(" bn_mul_low_normal %d * %d\n",n,n); | ||
| 739 | #endif | ||
| 740 | bn_mul_words(r,a,n,b[0]); | ||
| 741 | |||
| 742 | for (;;) | ||
| 743 | { | ||
| 744 | if (--n <= 0) return; | ||
| 745 | bn_mul_add_words(&(r[1]),a,n,b[1]); | ||
| 746 | if (--n <= 0) return; | ||
| 747 | bn_mul_add_words(&(r[2]),a,n,b[2]); | ||
| 748 | if (--n <= 0) return; | ||
| 749 | bn_mul_add_words(&(r[3]),a,n,b[3]); | ||
| 750 | if (--n <= 0) return; | ||
| 751 | bn_mul_add_words(&(r[4]),a,n,b[4]); | ||
| 752 | r+=4; | ||
| 753 | b+=4; | ||
| 754 | } | ||
| 755 | } | ||
| 756 | |||
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c deleted file mode 100644 index 6fa0f9be1e..0000000000 --- a/src/lib/libcrypto/bn/bn_prime.c +++ /dev/null | |||
| @@ -1,447 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_prime.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <time.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "bn_lcl.h" | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | |||
| 65 | /* The quick seive algorithm approach to weeding out primes is | ||
| 66 | * Philip Zimmermann's, as implemented in PGP. I have had a read of | ||
| 67 | * his comments and implemented my own version. | ||
| 68 | */ | ||
| 69 | #include "bn_prime.h" | ||
| 70 | |||
| 71 | static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx,BN_CTX *ctx2, | ||
| 72 | BN_MONT_CTX *mont); | ||
| 73 | static int probable_prime(BIGNUM *rnd, int bits); | ||
| 74 | static int probable_prime_dh(BIGNUM *rnd, int bits, | ||
| 75 | BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); | ||
| 76 | static int probable_prime_dh_strong(BIGNUM *rnd, int bits, | ||
| 77 | BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); | ||
| 78 | BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int strong, BIGNUM *add, | ||
| 79 | BIGNUM *rem, void (*callback)(int,int,void *), void *cb_arg) | ||
| 80 | { | ||
| 81 | BIGNUM *rnd=NULL; | ||
| 82 | BIGNUM t; | ||
| 83 | int i,j,c1=0; | ||
| 84 | BN_CTX *ctx; | ||
| 85 | |||
| 86 | ctx=BN_CTX_new(); | ||
| 87 | if (ctx == NULL) goto err; | ||
| 88 | if (ret == NULL) | ||
| 89 | { | ||
| 90 | if ((rnd=BN_new()) == NULL) goto err; | ||
| 91 | } | ||
| 92 | else | ||
| 93 | rnd=ret; | ||
| 94 | BN_init(&t); | ||
| 95 | loop: | ||
| 96 | /* make a random number and set the top and bottom bits */ | ||
| 97 | if (add == NULL) | ||
| 98 | { | ||
| 99 | if (!probable_prime(rnd,bits)) goto err; | ||
| 100 | } | ||
| 101 | else | ||
| 102 | { | ||
| 103 | if (strong) | ||
| 104 | { | ||
| 105 | if (!probable_prime_dh_strong(rnd,bits,add,rem,ctx)) | ||
| 106 | goto err; | ||
| 107 | } | ||
| 108 | else | ||
| 109 | { | ||
| 110 | if (!probable_prime_dh(rnd,bits,add,rem,ctx)) | ||
| 111 | goto err; | ||
| 112 | } | ||
| 113 | } | ||
| 114 | /* if (BN_mod_word(rnd,(BN_ULONG)3) == 1) goto loop; */ | ||
| 115 | if (callback != NULL) callback(0,c1++,cb_arg); | ||
| 116 | |||
| 117 | if (!strong) | ||
| 118 | { | ||
| 119 | i=BN_is_prime(rnd,BN_prime_checks,callback,ctx,cb_arg); | ||
| 120 | if (i == -1) goto err; | ||
| 121 | if (i == 0) goto loop; | ||
| 122 | } | ||
| 123 | else | ||
| 124 | { | ||
| 125 | /* for a strong prime generation, | ||
| 126 | * check that (p-1)/2 is prime. | ||
| 127 | * Since a prime is odd, We just | ||
| 128 | * need to divide by 2 */ | ||
| 129 | if (!BN_rshift1(&t,rnd)) goto err; | ||
| 130 | |||
| 131 | for (i=0; i<BN_prime_checks; i++) | ||
| 132 | { | ||
| 133 | j=BN_is_prime(rnd,1,callback,ctx,cb_arg); | ||
| 134 | if (j == -1) goto err; | ||
| 135 | if (j == 0) goto loop; | ||
| 136 | |||
| 137 | j=BN_is_prime(&t,1,callback,ctx,cb_arg); | ||
| 138 | if (j == -1) goto err; | ||
| 139 | if (j == 0) goto loop; | ||
| 140 | |||
| 141 | if (callback != NULL) callback(2,c1-1,cb_arg); | ||
| 142 | /* We have a strong prime test pass */ | ||
| 143 | } | ||
| 144 | } | ||
| 145 | /* we have a prime :-) */ | ||
| 146 | ret=rnd; | ||
| 147 | err: | ||
| 148 | if ((ret == NULL) && (rnd != NULL)) BN_free(rnd); | ||
| 149 | BN_free(&t); | ||
| 150 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 151 | return(ret); | ||
| 152 | } | ||
| 153 | |||
| 154 | int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,void *), | ||
| 155 | BN_CTX *ctx_passed, void *cb_arg) | ||
| 156 | { | ||
| 157 | int i,j,c2=0,ret= -1; | ||
| 158 | BIGNUM *check; | ||
| 159 | BN_CTX *ctx=NULL,*ctx2=NULL; | ||
| 160 | BN_MONT_CTX *mont=NULL; | ||
| 161 | |||
| 162 | if (!BN_is_odd(a)) | ||
| 163 | return(0); | ||
| 164 | if (ctx_passed != NULL) | ||
| 165 | ctx=ctx_passed; | ||
| 166 | else | ||
| 167 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 168 | |||
| 169 | if ((ctx2=BN_CTX_new()) == NULL) goto err; | ||
| 170 | if ((mont=BN_MONT_CTX_new()) == NULL) goto err; | ||
| 171 | |||
| 172 | check= &(ctx->bn[ctx->tos++]); | ||
| 173 | |||
| 174 | /* Setup the montgomery structure */ | ||
| 175 | if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err; | ||
| 176 | |||
| 177 | for (i=0; i<checks; i++) | ||
| 178 | { | ||
| 179 | if (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err; | ||
| 180 | j=witness(check,a,ctx,ctx2,mont); | ||
| 181 | if (j == -1) goto err; | ||
| 182 | if (j) | ||
| 183 | { | ||
| 184 | ret=0; | ||
| 185 | goto err; | ||
| 186 | } | ||
| 187 | if (callback != NULL) callback(1,c2++,cb_arg); | ||
| 188 | } | ||
| 189 | ret=1; | ||
| 190 | err: | ||
| 191 | ctx->tos--; | ||
| 192 | if ((ctx_passed == NULL) && (ctx != NULL)) | ||
| 193 | BN_CTX_free(ctx); | ||
| 194 | if (ctx2 != NULL) | ||
| 195 | BN_CTX_free(ctx2); | ||
| 196 | if (mont != NULL) BN_MONT_CTX_free(mont); | ||
| 197 | |||
| 198 | return(ret); | ||
| 199 | } | ||
| 200 | |||
| 201 | #define RECP_MUL_MOD | ||
| 202 | |||
| 203 | static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx, BN_CTX *ctx2, | ||
| 204 | BN_MONT_CTX *mont) | ||
| 205 | { | ||
| 206 | int k,i,ret= -1,good; | ||
| 207 | BIGNUM *d,*dd,*tmp,*d1,*d2,*n1; | ||
| 208 | BIGNUM *mont_one,*mont_n1,*mont_a; | ||
| 209 | |||
| 210 | d1= &(ctx->bn[ctx->tos]); | ||
| 211 | d2= &(ctx->bn[ctx->tos+1]); | ||
| 212 | n1= &(ctx->bn[ctx->tos+2]); | ||
| 213 | ctx->tos+=3; | ||
| 214 | |||
| 215 | mont_one= &(ctx2->bn[ctx2->tos]); | ||
| 216 | mont_n1= &(ctx2->bn[ctx2->tos+1]); | ||
| 217 | mont_a= &(ctx2->bn[ctx2->tos+2]); | ||
| 218 | ctx2->tos+=3; | ||
| 219 | |||
| 220 | d=d1; | ||
| 221 | dd=d2; | ||
| 222 | if (!BN_one(d)) goto err; | ||
| 223 | if (!BN_sub(n1,n,d)) goto err; /* n1=n-1; */ | ||
| 224 | k=BN_num_bits(n1); | ||
| 225 | |||
| 226 | if (!BN_to_montgomery(mont_one,BN_value_one(),mont,ctx2)) goto err; | ||
| 227 | if (!BN_to_montgomery(mont_n1,n1,mont,ctx2)) goto err; | ||
| 228 | if (!BN_to_montgomery(mont_a,a,mont,ctx2)) goto err; | ||
| 229 | |||
| 230 | BN_copy(d,mont_one); | ||
| 231 | for (i=k-1; i>=0; i--) | ||
| 232 | { | ||
| 233 | if ( (BN_cmp(d,mont_one) != 0) && | ||
| 234 | (BN_cmp(d,mont_n1) != 0)) | ||
| 235 | good=1; | ||
| 236 | else | ||
| 237 | good=0; | ||
| 238 | |||
| 239 | BN_mod_mul_montgomery(dd,d,d,mont,ctx2); | ||
| 240 | |||
| 241 | if (good && (BN_cmp(dd,mont_one) == 0)) | ||
| 242 | { | ||
| 243 | ret=1; | ||
| 244 | goto err; | ||
| 245 | } | ||
| 246 | if (BN_is_bit_set(n1,i)) | ||
| 247 | { | ||
| 248 | BN_mod_mul_montgomery(d,dd,mont_a,mont,ctx2); | ||
| 249 | } | ||
| 250 | else | ||
| 251 | { | ||
| 252 | tmp=d; | ||
| 253 | d=dd; | ||
| 254 | dd=tmp; | ||
| 255 | } | ||
| 256 | } | ||
| 257 | if (BN_cmp(d,mont_one) == 0) | ||
| 258 | i=0; | ||
| 259 | else i=1; | ||
| 260 | ret=i; | ||
| 261 | err: | ||
| 262 | ctx->tos-=3; | ||
| 263 | ctx2->tos-=3; | ||
| 264 | return(ret); | ||
| 265 | } | ||
| 266 | |||
| 267 | static int probable_prime(BIGNUM *rnd, int bits) | ||
| 268 | { | ||
| 269 | int i; | ||
| 270 | MS_STATIC BN_ULONG mods[NUMPRIMES]; | ||
| 271 | BN_ULONG delta,d; | ||
| 272 | |||
| 273 | again: | ||
| 274 | if (!BN_rand(rnd,bits,1,1)) return(0); | ||
| 275 | /* we now have a random number 'rand' to test. */ | ||
| 276 | for (i=1; i<NUMPRIMES; i++) | ||
| 277 | mods[i]=BN_mod_word(rnd,(BN_ULONG)primes[i]); | ||
| 278 | delta=0; | ||
| 279 | loop: for (i=1; i<NUMPRIMES; i++) | ||
| 280 | { | ||
| 281 | /* check that rnd is not a prime and also | ||
| 282 | * that gcd(rnd-1,primes) == 1 (except for 2) */ | ||
| 283 | if (((mods[i]+delta)%primes[i]) <= 1) | ||
| 284 | { | ||
| 285 | d=delta; | ||
| 286 | delta+=2; | ||
| 287 | /* perhaps need to check for overflow of | ||
| 288 | * delta (but delta can be upto 2^32) | ||
| 289 | * 21-May-98 eay - added overflow check */ | ||
| 290 | if (delta < d) goto again; | ||
| 291 | goto loop; | ||
| 292 | } | ||
| 293 | } | ||
| 294 | if (!BN_add_word(rnd,delta)) return(0); | ||
| 295 | return(1); | ||
| 296 | } | ||
| 297 | |||
| 298 | static int probable_prime_dh(BIGNUM *rnd, int bits, BIGNUM *add, BIGNUM *rem, | ||
| 299 | BN_CTX *ctx) | ||
| 300 | { | ||
| 301 | int i,ret=0; | ||
| 302 | BIGNUM *t1; | ||
| 303 | |||
| 304 | t1= &(ctx->bn[ctx->tos++]); | ||
| 305 | |||
| 306 | if (!BN_rand(rnd,bits,0,1)) goto err; | ||
| 307 | |||
| 308 | /* we need ((rnd-rem) % add) == 0 */ | ||
| 309 | |||
| 310 | if (!BN_mod(t1,rnd,add,ctx)) goto err; | ||
| 311 | if (!BN_sub(rnd,rnd,t1)) goto err; | ||
| 312 | if (rem == NULL) | ||
| 313 | { if (!BN_add_word(rnd,1)) goto err; } | ||
| 314 | else | ||
| 315 | { if (!BN_add(rnd,rnd,rem)) goto err; } | ||
| 316 | |||
| 317 | /* we now have a random number 'rand' to test. */ | ||
| 318 | |||
| 319 | loop: for (i=1; i<NUMPRIMES; i++) | ||
| 320 | { | ||
| 321 | /* check that rnd is a prime */ | ||
| 322 | if (BN_mod_word(rnd,(BN_ULONG)primes[i]) <= 1) | ||
| 323 | { | ||
| 324 | if (!BN_add(rnd,rnd,add)) goto err; | ||
| 325 | goto loop; | ||
| 326 | } | ||
| 327 | } | ||
| 328 | ret=1; | ||
| 329 | err: | ||
| 330 | ctx->tos--; | ||
| 331 | return(ret); | ||
| 332 | } | ||
| 333 | |||
| 334 | static int probable_prime_dh_strong(BIGNUM *p, int bits, BIGNUM *padd, | ||
| 335 | BIGNUM *rem, BN_CTX *ctx) | ||
| 336 | { | ||
| 337 | int i,ret=0; | ||
| 338 | BIGNUM *t1,*qadd=NULL,*q=NULL; | ||
| 339 | |||
| 340 | bits--; | ||
| 341 | t1= &(ctx->bn[ctx->tos++]); | ||
| 342 | q= &(ctx->bn[ctx->tos++]); | ||
| 343 | qadd= &(ctx->bn[ctx->tos++]); | ||
| 344 | |||
| 345 | if (!BN_rshift1(qadd,padd)) goto err; | ||
| 346 | |||
| 347 | if (!BN_rand(q,bits,0,1)) goto err; | ||
| 348 | |||
| 349 | /* we need ((rnd-rem) % add) == 0 */ | ||
| 350 | if (!BN_mod(t1,q,qadd,ctx)) goto err; | ||
| 351 | if (!BN_sub(q,q,t1)) goto err; | ||
| 352 | if (rem == NULL) | ||
| 353 | { if (!BN_add_word(q,1)) goto err; } | ||
| 354 | else | ||
| 355 | { | ||
| 356 | if (!BN_rshift1(t1,rem)) goto err; | ||
| 357 | if (!BN_add(q,q,t1)) goto err; | ||
| 358 | } | ||
| 359 | |||
| 360 | /* we now have a random number 'rand' to test. */ | ||
| 361 | if (!BN_lshift1(p,q)) goto err; | ||
| 362 | if (!BN_add_word(p,1)) goto err; | ||
| 363 | |||
| 364 | loop: for (i=1; i<NUMPRIMES; i++) | ||
| 365 | { | ||
| 366 | /* check that p and q are prime */ | ||
| 367 | /* check that for p and q | ||
| 368 | * gcd(p-1,primes) == 1 (except for 2) */ | ||
| 369 | if ( (BN_mod_word(p,(BN_ULONG)primes[i]) == 0) || | ||
| 370 | (BN_mod_word(q,(BN_ULONG)primes[i]) == 0)) | ||
| 371 | { | ||
| 372 | if (!BN_add(p,p,padd)) goto err; | ||
| 373 | if (!BN_add(q,q,qadd)) goto err; | ||
| 374 | goto loop; | ||
| 375 | } | ||
| 376 | } | ||
| 377 | ret=1; | ||
| 378 | err: | ||
| 379 | ctx->tos-=3; | ||
| 380 | return(ret); | ||
| 381 | } | ||
| 382 | |||
| 383 | #if 0 | ||
| 384 | static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx) | ||
| 385 | { | ||
| 386 | int k,i,nb,ret= -1; | ||
| 387 | BIGNUM *d,*dd,*tmp; | ||
| 388 | BIGNUM *d1,*d2,*x,*n1,*inv; | ||
| 389 | |||
| 390 | d1= &(ctx->bn[ctx->tos]); | ||
| 391 | d2= &(ctx->bn[ctx->tos+1]); | ||
| 392 | x= &(ctx->bn[ctx->tos+2]); | ||
| 393 | n1= &(ctx->bn[ctx->tos+3]); | ||
| 394 | inv=&(ctx->bn[ctx->tos+4]); | ||
| 395 | ctx->tos+=5; | ||
| 396 | |||
| 397 | d=d1; | ||
| 398 | dd=d2; | ||
| 399 | if (!BN_one(d)) goto err; | ||
| 400 | if (!BN_sub(n1,n,d)) goto err; /* n1=n-1; */ | ||
| 401 | k=BN_num_bits(n1); | ||
| 402 | |||
| 403 | /* i=BN_num_bits(n); */ | ||
| 404 | #ifdef RECP_MUL_MOD | ||
| 405 | nb=BN_reciprocal(inv,n,ctx); /**/ | ||
| 406 | if (nb == -1) goto err; | ||
| 407 | #endif | ||
| 408 | |||
| 409 | for (i=k-1; i>=0; i--) | ||
| 410 | { | ||
| 411 | if (BN_copy(x,d) == NULL) goto err; | ||
| 412 | #ifndef RECP_MUL_MOD | ||
| 413 | if (!BN_mod_mul(dd,d,d,n,ctx)) goto err; | ||
| 414 | #else | ||
| 415 | if (!BN_mod_mul_reciprocal(dd,d,d,n,inv,nb,ctx)) goto err; | ||
| 416 | #endif | ||
| 417 | if ( BN_is_one(dd) && | ||
| 418 | !BN_is_one(x) && | ||
| 419 | (BN_cmp(x,n1) != 0)) | ||
| 420 | { | ||
| 421 | ret=1; | ||
| 422 | goto err; | ||
| 423 | } | ||
| 424 | if (BN_is_bit_set(n1,i)) | ||
| 425 | { | ||
| 426 | #ifndef RECP_MUL_MOD | ||
| 427 | if (!BN_mod_mul(d,dd,a,n,ctx)) goto err; | ||
| 428 | #else | ||
| 429 | if (!BN_mod_mul_reciprocal(d,dd,a,n,inv,nb,ctx)) goto err; | ||
| 430 | #endif | ||
| 431 | } | ||
| 432 | else | ||
| 433 | { | ||
| 434 | tmp=d; | ||
| 435 | d=dd; | ||
| 436 | dd=tmp; | ||
| 437 | } | ||
| 438 | } | ||
| 439 | if (BN_is_one(d)) | ||
| 440 | i=0; | ||
| 441 | else i=1; | ||
| 442 | ret=i; | ||
| 443 | err: | ||
| 444 | ctx->tos-=5; | ||
| 445 | return(ret); | ||
| 446 | } | ||
| 447 | #endif | ||
diff --git a/src/lib/libcrypto/bn/bn_prime.h b/src/lib/libcrypto/bn/bn_prime.h deleted file mode 100644 index 6fce0210cd..0000000000 --- a/src/lib/libcrypto/bn/bn_prime.h +++ /dev/null | |||
| @@ -1,325 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_prime.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef EIGHT_BIT | ||
| 60 | #define NUMPRIMES 2048 | ||
| 61 | #else | ||
| 62 | #define NUMPRIMES 54 | ||
| 63 | #endif | ||
| 64 | static unsigned int primes[NUMPRIMES]= | ||
| 65 | { | ||
| 66 | 2, 3, 5, 7, 11, 13, 17, 19, | ||
| 67 | 23, 29, 31, 37, 41, 43, 47, 53, | ||
| 68 | 59, 61, 67, 71, 73, 79, 83, 89, | ||
| 69 | 97, 101, 103, 107, 109, 113, 127, 131, | ||
| 70 | 137, 139, 149, 151, 157, 163, 167, 173, | ||
| 71 | 179, 181, 191, 193, 197, 199, 211, 223, | ||
| 72 | 227, 229, 233, 239, 241, 251, | ||
| 73 | #ifndef EIGHT_BIT | ||
| 74 | 257, 263, | ||
| 75 | 269, 271, 277, 281, 283, 293, 307, 311, | ||
| 76 | 313, 317, 331, 337, 347, 349, 353, 359, | ||
| 77 | 367, 373, 379, 383, 389, 397, 401, 409, | ||
| 78 | 419, 421, 431, 433, 439, 443, 449, 457, | ||
| 79 | 461, 463, 467, 479, 487, 491, 499, 503, | ||
| 80 | 509, 521, 523, 541, 547, 557, 563, 569, | ||
| 81 | 571, 577, 587, 593, 599, 601, 607, 613, | ||
| 82 | 617, 619, 631, 641, 643, 647, 653, 659, | ||
| 83 | 661, 673, 677, 683, 691, 701, 709, 719, | ||
| 84 | 727, 733, 739, 743, 751, 757, 761, 769, | ||
| 85 | 773, 787, 797, 809, 811, 821, 823, 827, | ||
| 86 | 829, 839, 853, 857, 859, 863, 877, 881, | ||
| 87 | 883, 887, 907, 911, 919, 929, 937, 941, | ||
| 88 | 947, 953, 967, 971, 977, 983, 991, 997, | ||
| 89 | 1009,1013,1019,1021,1031,1033,1039,1049, | ||
| 90 | 1051,1061,1063,1069,1087,1091,1093,1097, | ||
| 91 | 1103,1109,1117,1123,1129,1151,1153,1163, | ||
| 92 | 1171,1181,1187,1193,1201,1213,1217,1223, | ||
| 93 | 1229,1231,1237,1249,1259,1277,1279,1283, | ||
| 94 | 1289,1291,1297,1301,1303,1307,1319,1321, | ||
| 95 | 1327,1361,1367,1373,1381,1399,1409,1423, | ||
| 96 | 1427,1429,1433,1439,1447,1451,1453,1459, | ||
| 97 | 1471,1481,1483,1487,1489,1493,1499,1511, | ||
| 98 | 1523,1531,1543,1549,1553,1559,1567,1571, | ||
| 99 | 1579,1583,1597,1601,1607,1609,1613,1619, | ||
| 100 | 1621,1627,1637,1657,1663,1667,1669,1693, | ||
| 101 | 1697,1699,1709,1721,1723,1733,1741,1747, | ||
| 102 | 1753,1759,1777,1783,1787,1789,1801,1811, | ||
| 103 | 1823,1831,1847,1861,1867,1871,1873,1877, | ||
| 104 | 1879,1889,1901,1907,1913,1931,1933,1949, | ||
| 105 | 1951,1973,1979,1987,1993,1997,1999,2003, | ||
| 106 | 2011,2017,2027,2029,2039,2053,2063,2069, | ||
| 107 | 2081,2083,2087,2089,2099,2111,2113,2129, | ||
| 108 | 2131,2137,2141,2143,2153,2161,2179,2203, | ||
| 109 | 2207,2213,2221,2237,2239,2243,2251,2267, | ||
| 110 | 2269,2273,2281,2287,2293,2297,2309,2311, | ||
| 111 | 2333,2339,2341,2347,2351,2357,2371,2377, | ||
| 112 | 2381,2383,2389,2393,2399,2411,2417,2423, | ||
| 113 | 2437,2441,2447,2459,2467,2473,2477,2503, | ||
| 114 | 2521,2531,2539,2543,2549,2551,2557,2579, | ||
| 115 | 2591,2593,2609,2617,2621,2633,2647,2657, | ||
| 116 | 2659,2663,2671,2677,2683,2687,2689,2693, | ||
| 117 | 2699,2707,2711,2713,2719,2729,2731,2741, | ||
| 118 | 2749,2753,2767,2777,2789,2791,2797,2801, | ||
| 119 | 2803,2819,2833,2837,2843,2851,2857,2861, | ||
| 120 | 2879,2887,2897,2903,2909,2917,2927,2939, | ||
| 121 | 2953,2957,2963,2969,2971,2999,3001,3011, | ||
| 122 | 3019,3023,3037,3041,3049,3061,3067,3079, | ||
| 123 | 3083,3089,3109,3119,3121,3137,3163,3167, | ||
| 124 | 3169,3181,3187,3191,3203,3209,3217,3221, | ||
| 125 | 3229,3251,3253,3257,3259,3271,3299,3301, | ||
| 126 | 3307,3313,3319,3323,3329,3331,3343,3347, | ||
| 127 | 3359,3361,3371,3373,3389,3391,3407,3413, | ||
| 128 | 3433,3449,3457,3461,3463,3467,3469,3491, | ||
| 129 | 3499,3511,3517,3527,3529,3533,3539,3541, | ||
| 130 | 3547,3557,3559,3571,3581,3583,3593,3607, | ||
| 131 | 3613,3617,3623,3631,3637,3643,3659,3671, | ||
| 132 | 3673,3677,3691,3697,3701,3709,3719,3727, | ||
| 133 | 3733,3739,3761,3767,3769,3779,3793,3797, | ||
| 134 | 3803,3821,3823,3833,3847,3851,3853,3863, | ||
| 135 | 3877,3881,3889,3907,3911,3917,3919,3923, | ||
| 136 | 3929,3931,3943,3947,3967,3989,4001,4003, | ||
| 137 | 4007,4013,4019,4021,4027,4049,4051,4057, | ||
| 138 | 4073,4079,4091,4093,4099,4111,4127,4129, | ||
| 139 | 4133,4139,4153,4157,4159,4177,4201,4211, | ||
| 140 | 4217,4219,4229,4231,4241,4243,4253,4259, | ||
| 141 | 4261,4271,4273,4283,4289,4297,4327,4337, | ||
| 142 | 4339,4349,4357,4363,4373,4391,4397,4409, | ||
| 143 | 4421,4423,4441,4447,4451,4457,4463,4481, | ||
| 144 | 4483,4493,4507,4513,4517,4519,4523,4547, | ||
| 145 | 4549,4561,4567,4583,4591,4597,4603,4621, | ||
| 146 | 4637,4639,4643,4649,4651,4657,4663,4673, | ||
| 147 | 4679,4691,4703,4721,4723,4729,4733,4751, | ||
| 148 | 4759,4783,4787,4789,4793,4799,4801,4813, | ||
| 149 | 4817,4831,4861,4871,4877,4889,4903,4909, | ||
| 150 | 4919,4931,4933,4937,4943,4951,4957,4967, | ||
| 151 | 4969,4973,4987,4993,4999,5003,5009,5011, | ||
| 152 | 5021,5023,5039,5051,5059,5077,5081,5087, | ||
| 153 | 5099,5101,5107,5113,5119,5147,5153,5167, | ||
| 154 | 5171,5179,5189,5197,5209,5227,5231,5233, | ||
| 155 | 5237,5261,5273,5279,5281,5297,5303,5309, | ||
| 156 | 5323,5333,5347,5351,5381,5387,5393,5399, | ||
| 157 | 5407,5413,5417,5419,5431,5437,5441,5443, | ||
| 158 | 5449,5471,5477,5479,5483,5501,5503,5507, | ||
| 159 | 5519,5521,5527,5531,5557,5563,5569,5573, | ||
| 160 | 5581,5591,5623,5639,5641,5647,5651,5653, | ||
| 161 | 5657,5659,5669,5683,5689,5693,5701,5711, | ||
| 162 | 5717,5737,5741,5743,5749,5779,5783,5791, | ||
| 163 | 5801,5807,5813,5821,5827,5839,5843,5849, | ||
| 164 | 5851,5857,5861,5867,5869,5879,5881,5897, | ||
| 165 | 5903,5923,5927,5939,5953,5981,5987,6007, | ||
| 166 | 6011,6029,6037,6043,6047,6053,6067,6073, | ||
| 167 | 6079,6089,6091,6101,6113,6121,6131,6133, | ||
| 168 | 6143,6151,6163,6173,6197,6199,6203,6211, | ||
| 169 | 6217,6221,6229,6247,6257,6263,6269,6271, | ||
| 170 | 6277,6287,6299,6301,6311,6317,6323,6329, | ||
| 171 | 6337,6343,6353,6359,6361,6367,6373,6379, | ||
| 172 | 6389,6397,6421,6427,6449,6451,6469,6473, | ||
| 173 | 6481,6491,6521,6529,6547,6551,6553,6563, | ||
| 174 | 6569,6571,6577,6581,6599,6607,6619,6637, | ||
| 175 | 6653,6659,6661,6673,6679,6689,6691,6701, | ||
| 176 | 6703,6709,6719,6733,6737,6761,6763,6779, | ||
| 177 | 6781,6791,6793,6803,6823,6827,6829,6833, | ||
| 178 | 6841,6857,6863,6869,6871,6883,6899,6907, | ||
| 179 | 6911,6917,6947,6949,6959,6961,6967,6971, | ||
| 180 | 6977,6983,6991,6997,7001,7013,7019,7027, | ||
| 181 | 7039,7043,7057,7069,7079,7103,7109,7121, | ||
| 182 | 7127,7129,7151,7159,7177,7187,7193,7207, | ||
| 183 | 7211,7213,7219,7229,7237,7243,7247,7253, | ||
| 184 | 7283,7297,7307,7309,7321,7331,7333,7349, | ||
| 185 | 7351,7369,7393,7411,7417,7433,7451,7457, | ||
| 186 | 7459,7477,7481,7487,7489,7499,7507,7517, | ||
| 187 | 7523,7529,7537,7541,7547,7549,7559,7561, | ||
| 188 | 7573,7577,7583,7589,7591,7603,7607,7621, | ||
| 189 | 7639,7643,7649,7669,7673,7681,7687,7691, | ||
| 190 | 7699,7703,7717,7723,7727,7741,7753,7757, | ||
| 191 | 7759,7789,7793,7817,7823,7829,7841,7853, | ||
| 192 | 7867,7873,7877,7879,7883,7901,7907,7919, | ||
| 193 | 7927,7933,7937,7949,7951,7963,7993,8009, | ||
| 194 | 8011,8017,8039,8053,8059,8069,8081,8087, | ||
| 195 | 8089,8093,8101,8111,8117,8123,8147,8161, | ||
| 196 | 8167,8171,8179,8191,8209,8219,8221,8231, | ||
| 197 | 8233,8237,8243,8263,8269,8273,8287,8291, | ||
| 198 | 8293,8297,8311,8317,8329,8353,8363,8369, | ||
| 199 | 8377,8387,8389,8419,8423,8429,8431,8443, | ||
| 200 | 8447,8461,8467,8501,8513,8521,8527,8537, | ||
| 201 | 8539,8543,8563,8573,8581,8597,8599,8609, | ||
| 202 | 8623,8627,8629,8641,8647,8663,8669,8677, | ||
| 203 | 8681,8689,8693,8699,8707,8713,8719,8731, | ||
| 204 | 8737,8741,8747,8753,8761,8779,8783,8803, | ||
| 205 | 8807,8819,8821,8831,8837,8839,8849,8861, | ||
| 206 | 8863,8867,8887,8893,8923,8929,8933,8941, | ||
| 207 | 8951,8963,8969,8971,8999,9001,9007,9011, | ||
| 208 | 9013,9029,9041,9043,9049,9059,9067,9091, | ||
| 209 | 9103,9109,9127,9133,9137,9151,9157,9161, | ||
| 210 | 9173,9181,9187,9199,9203,9209,9221,9227, | ||
| 211 | 9239,9241,9257,9277,9281,9283,9293,9311, | ||
| 212 | 9319,9323,9337,9341,9343,9349,9371,9377, | ||
| 213 | 9391,9397,9403,9413,9419,9421,9431,9433, | ||
| 214 | 9437,9439,9461,9463,9467,9473,9479,9491, | ||
| 215 | 9497,9511,9521,9533,9539,9547,9551,9587, | ||
| 216 | 9601,9613,9619,9623,9629,9631,9643,9649, | ||
| 217 | 9661,9677,9679,9689,9697,9719,9721,9733, | ||
| 218 | 9739,9743,9749,9767,9769,9781,9787,9791, | ||
| 219 | 9803,9811,9817,9829,9833,9839,9851,9857, | ||
| 220 | 9859,9871,9883,9887,9901,9907,9923,9929, | ||
| 221 | 9931,9941,9949,9967,9973,10007,10009,10037, | ||
| 222 | 10039,10061,10067,10069,10079,10091,10093,10099, | ||
| 223 | 10103,10111,10133,10139,10141,10151,10159,10163, | ||
| 224 | 10169,10177,10181,10193,10211,10223,10243,10247, | ||
| 225 | 10253,10259,10267,10271,10273,10289,10301,10303, | ||
| 226 | 10313,10321,10331,10333,10337,10343,10357,10369, | ||
| 227 | 10391,10399,10427,10429,10433,10453,10457,10459, | ||
| 228 | 10463,10477,10487,10499,10501,10513,10529,10531, | ||
| 229 | 10559,10567,10589,10597,10601,10607,10613,10627, | ||
| 230 | 10631,10639,10651,10657,10663,10667,10687,10691, | ||
| 231 | 10709,10711,10723,10729,10733,10739,10753,10771, | ||
| 232 | 10781,10789,10799,10831,10837,10847,10853,10859, | ||
| 233 | 10861,10867,10883,10889,10891,10903,10909,10937, | ||
| 234 | 10939,10949,10957,10973,10979,10987,10993,11003, | ||
| 235 | 11027,11047,11057,11059,11069,11071,11083,11087, | ||
| 236 | 11093,11113,11117,11119,11131,11149,11159,11161, | ||
| 237 | 11171,11173,11177,11197,11213,11239,11243,11251, | ||
| 238 | 11257,11261,11273,11279,11287,11299,11311,11317, | ||
| 239 | 11321,11329,11351,11353,11369,11383,11393,11399, | ||
| 240 | 11411,11423,11437,11443,11447,11467,11471,11483, | ||
| 241 | 11489,11491,11497,11503,11519,11527,11549,11551, | ||
| 242 | 11579,11587,11593,11597,11617,11621,11633,11657, | ||
| 243 | 11677,11681,11689,11699,11701,11717,11719,11731, | ||
| 244 | 11743,11777,11779,11783,11789,11801,11807,11813, | ||
| 245 | 11821,11827,11831,11833,11839,11863,11867,11887, | ||
| 246 | 11897,11903,11909,11923,11927,11933,11939,11941, | ||
| 247 | 11953,11959,11969,11971,11981,11987,12007,12011, | ||
| 248 | 12037,12041,12043,12049,12071,12073,12097,12101, | ||
| 249 | 12107,12109,12113,12119,12143,12149,12157,12161, | ||
| 250 | 12163,12197,12203,12211,12227,12239,12241,12251, | ||
| 251 | 12253,12263,12269,12277,12281,12289,12301,12323, | ||
| 252 | 12329,12343,12347,12373,12377,12379,12391,12401, | ||
| 253 | 12409,12413,12421,12433,12437,12451,12457,12473, | ||
| 254 | 12479,12487,12491,12497,12503,12511,12517,12527, | ||
| 255 | 12539,12541,12547,12553,12569,12577,12583,12589, | ||
| 256 | 12601,12611,12613,12619,12637,12641,12647,12653, | ||
| 257 | 12659,12671,12689,12697,12703,12713,12721,12739, | ||
| 258 | 12743,12757,12763,12781,12791,12799,12809,12821, | ||
| 259 | 12823,12829,12841,12853,12889,12893,12899,12907, | ||
| 260 | 12911,12917,12919,12923,12941,12953,12959,12967, | ||
| 261 | 12973,12979,12983,13001,13003,13007,13009,13033, | ||
| 262 | 13037,13043,13049,13063,13093,13099,13103,13109, | ||
| 263 | 13121,13127,13147,13151,13159,13163,13171,13177, | ||
| 264 | 13183,13187,13217,13219,13229,13241,13249,13259, | ||
| 265 | 13267,13291,13297,13309,13313,13327,13331,13337, | ||
| 266 | 13339,13367,13381,13397,13399,13411,13417,13421, | ||
| 267 | 13441,13451,13457,13463,13469,13477,13487,13499, | ||
| 268 | 13513,13523,13537,13553,13567,13577,13591,13597, | ||
| 269 | 13613,13619,13627,13633,13649,13669,13679,13681, | ||
| 270 | 13687,13691,13693,13697,13709,13711,13721,13723, | ||
| 271 | 13729,13751,13757,13759,13763,13781,13789,13799, | ||
| 272 | 13807,13829,13831,13841,13859,13873,13877,13879, | ||
| 273 | 13883,13901,13903,13907,13913,13921,13931,13933, | ||
| 274 | 13963,13967,13997,13999,14009,14011,14029,14033, | ||
| 275 | 14051,14057,14071,14081,14083,14087,14107,14143, | ||
| 276 | 14149,14153,14159,14173,14177,14197,14207,14221, | ||
| 277 | 14243,14249,14251,14281,14293,14303,14321,14323, | ||
| 278 | 14327,14341,14347,14369,14387,14389,14401,14407, | ||
| 279 | 14411,14419,14423,14431,14437,14447,14449,14461, | ||
| 280 | 14479,14489,14503,14519,14533,14537,14543,14549, | ||
| 281 | 14551,14557,14561,14563,14591,14593,14621,14627, | ||
| 282 | 14629,14633,14639,14653,14657,14669,14683,14699, | ||
| 283 | 14713,14717,14723,14731,14737,14741,14747,14753, | ||
| 284 | 14759,14767,14771,14779,14783,14797,14813,14821, | ||
| 285 | 14827,14831,14843,14851,14867,14869,14879,14887, | ||
| 286 | 14891,14897,14923,14929,14939,14947,14951,14957, | ||
| 287 | 14969,14983,15013,15017,15031,15053,15061,15073, | ||
| 288 | 15077,15083,15091,15101,15107,15121,15131,15137, | ||
| 289 | 15139,15149,15161,15173,15187,15193,15199,15217, | ||
| 290 | 15227,15233,15241,15259,15263,15269,15271,15277, | ||
| 291 | 15287,15289,15299,15307,15313,15319,15329,15331, | ||
| 292 | 15349,15359,15361,15373,15377,15383,15391,15401, | ||
| 293 | 15413,15427,15439,15443,15451,15461,15467,15473, | ||
| 294 | 15493,15497,15511,15527,15541,15551,15559,15569, | ||
| 295 | 15581,15583,15601,15607,15619,15629,15641,15643, | ||
| 296 | 15647,15649,15661,15667,15671,15679,15683,15727, | ||
| 297 | 15731,15733,15737,15739,15749,15761,15767,15773, | ||
| 298 | 15787,15791,15797,15803,15809,15817,15823,15859, | ||
| 299 | 15877,15881,15887,15889,15901,15907,15913,15919, | ||
| 300 | 15923,15937,15959,15971,15973,15991,16001,16007, | ||
| 301 | 16033,16057,16061,16063,16067,16069,16073,16087, | ||
| 302 | 16091,16097,16103,16111,16127,16139,16141,16183, | ||
| 303 | 16187,16189,16193,16217,16223,16229,16231,16249, | ||
| 304 | 16253,16267,16273,16301,16319,16333,16339,16349, | ||
| 305 | 16361,16363,16369,16381,16411,16417,16421,16427, | ||
| 306 | 16433,16447,16451,16453,16477,16481,16487,16493, | ||
| 307 | 16519,16529,16547,16553,16561,16567,16573,16603, | ||
| 308 | 16607,16619,16631,16633,16649,16651,16657,16661, | ||
| 309 | 16673,16691,16693,16699,16703,16729,16741,16747, | ||
| 310 | 16759,16763,16787,16811,16823,16829,16831,16843, | ||
| 311 | 16871,16879,16883,16889,16901,16903,16921,16927, | ||
| 312 | 16931,16937,16943,16963,16979,16981,16987,16993, | ||
| 313 | 17011,17021,17027,17029,17033,17041,17047,17053, | ||
| 314 | 17077,17093,17099,17107,17117,17123,17137,17159, | ||
| 315 | 17167,17183,17189,17191,17203,17207,17209,17231, | ||
| 316 | 17239,17257,17291,17293,17299,17317,17321,17327, | ||
| 317 | 17333,17341,17351,17359,17377,17383,17387,17389, | ||
| 318 | 17393,17401,17417,17419,17431,17443,17449,17467, | ||
| 319 | 17471,17477,17483,17489,17491,17497,17509,17519, | ||
| 320 | 17539,17551,17569,17573,17579,17581,17597,17599, | ||
| 321 | 17609,17623,17627,17657,17659,17669,17681,17683, | ||
| 322 | 17707,17713,17729,17737,17747,17749,17761,17783, | ||
| 323 | 17789,17791,17807,17827,17837,17839,17851,17863, | ||
| 324 | #endif | ||
| 325 | }; | ||
diff --git a/src/lib/libcrypto/bn/bn_prime.pl b/src/lib/libcrypto/bn/bn_prime.pl deleted file mode 100644 index 979385a334..0000000000 --- a/src/lib/libcrypto/bn/bn_prime.pl +++ /dev/null | |||
| @@ -1,56 +0,0 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # bn_prime.pl | ||
| 3 | |||
| 4 | $num=2048; | ||
| 5 | $num=$ARGV[0] if ($#ARGV >= 0); | ||
| 6 | |||
| 7 | push(@primes,2); | ||
| 8 | $p=1; | ||
| 9 | loop: while ($#primes < $num-1) | ||
| 10 | { | ||
| 11 | $p+=2; | ||
| 12 | $s=int(sqrt($p)); | ||
| 13 | |||
| 14 | for ($i=0; $primes[$i]<=$s; $i++) | ||
| 15 | { | ||
| 16 | next loop if (($p%$primes[$i]) == 0); | ||
| 17 | } | ||
| 18 | push(@primes,$p); | ||
| 19 | } | ||
| 20 | |||
| 21 | print <<"EOF"; | ||
| 22 | /* Auto generated by bn_prime.pl */ | ||
| 23 | /* Copyright (C) 1995-1997 Eric Young (eay\@mincom.oz.au). | ||
| 24 | * All rights reserved. | ||
| 25 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 26 | * the code are not to be removed. | ||
| 27 | * See the COPYRIGHT file in the SSLeay distribution for more details. | ||
| 28 | */ | ||
| 29 | |||
| 30 | EOF | ||
| 31 | |||
| 32 | for ($i=0; $i <= $#primes; $i++) | ||
| 33 | { | ||
| 34 | if ($primes[$i] > 256) | ||
| 35 | { | ||
| 36 | $eight=$i; | ||
| 37 | last; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | printf "#ifndef EIGHT_BIT\n"; | ||
| 42 | printf "#define NUMPRIMES %d\n",$num; | ||
| 43 | printf "#else\n"; | ||
| 44 | printf "#define NUMPRIMES %d\n",$eight; | ||
| 45 | printf "#endif\n"; | ||
| 46 | print "static unsigned int primes[NUMPRIMES]=\n\t{\n\t"; | ||
| 47 | $init=0; | ||
| 48 | for ($i=0; $i <= $#primes; $i++) | ||
| 49 | { | ||
| 50 | printf "\n#ifndef EIGHT_BIT\n\t" if ($primes[$i] > 256) && !($init++); | ||
| 51 | printf("\n\t") if (($i%8) == 0) && ($i != 0); | ||
| 52 | printf("%4d,",$primes[$i]); | ||
| 53 | } | ||
| 54 | print "\n#endif\n\t};\n"; | ||
| 55 | |||
| 56 | |||
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c deleted file mode 100644 index 2f5ab2617b..0000000000 --- a/src/lib/libcrypto/bn/bn_print.c +++ /dev/null | |||
| @@ -1,323 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_print.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <ctype.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/buffer.h> | ||
| 63 | #include "bn_lcl.h" | ||
| 64 | |||
| 65 | static const char *Hex="0123456789ABCDEF"; | ||
| 66 | |||
| 67 | /* Must 'Free' the returned data */ | ||
| 68 | char *BN_bn2hex(const BIGNUM *a) | ||
| 69 | { | ||
| 70 | int i,j,v,z=0; | ||
| 71 | char *buf; | ||
| 72 | char *p; | ||
| 73 | |||
| 74 | buf=(char *)Malloc(a->top*BN_BYTES*2+2); | ||
| 75 | if (buf == NULL) | ||
| 76 | { | ||
| 77 | BNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE); | ||
| 78 | goto err; | ||
| 79 | } | ||
| 80 | p=buf; | ||
| 81 | if (a->neg) *(p++)='-'; | ||
| 82 | if (a->top == 0) *(p++)='0'; | ||
| 83 | for (i=a->top-1; i >=0; i--) | ||
| 84 | { | ||
| 85 | for (j=BN_BITS2-8; j >= 0; j-=8) | ||
| 86 | { | ||
| 87 | /* strip leading zeros */ | ||
| 88 | v=((int)(a->d[i]>>(long)j))&0xff; | ||
| 89 | if (z || (v != 0)) | ||
| 90 | { | ||
| 91 | *(p++)=Hex[v>>4]; | ||
| 92 | *(p++)=Hex[v&0x0f]; | ||
| 93 | z=1; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
| 97 | *p='\0'; | ||
| 98 | err: | ||
| 99 | return(buf); | ||
| 100 | } | ||
| 101 | |||
| 102 | /* Must 'Free' the returned data */ | ||
| 103 | char *BN_bn2dec(const BIGNUM *a) | ||
| 104 | { | ||
| 105 | int i=0,num; | ||
| 106 | char *buf=NULL; | ||
| 107 | char *p; | ||
| 108 | BIGNUM *t=NULL; | ||
| 109 | BN_ULONG *bn_data=NULL,*lp; | ||
| 110 | |||
| 111 | i=BN_num_bits(a)*3; | ||
| 112 | num=(i/10+i/1000+3)+1; | ||
| 113 | bn_data=(BN_ULONG *)Malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG)); | ||
| 114 | buf=(char *)Malloc(num+3); | ||
| 115 | if ((buf == NULL) || (bn_data == NULL)) | ||
| 116 | { | ||
| 117 | BNerr(BN_F_BN_BN2DEC,ERR_R_MALLOC_FAILURE); | ||
| 118 | goto err; | ||
| 119 | } | ||
| 120 | if ((t=BN_dup(a)) == NULL) goto err; | ||
| 121 | |||
| 122 | p=buf; | ||
| 123 | lp=bn_data; | ||
| 124 | if (t->neg) *(p++)='-'; | ||
| 125 | if (t->top == 0) | ||
| 126 | { | ||
| 127 | *(p++)='0'; | ||
| 128 | *(p++)='\0'; | ||
| 129 | } | ||
| 130 | else | ||
| 131 | { | ||
| 132 | i=0; | ||
| 133 | while (!BN_is_zero(t)) | ||
| 134 | { | ||
| 135 | *lp=BN_div_word(t,BN_DEC_CONV); | ||
| 136 | lp++; | ||
| 137 | } | ||
| 138 | lp--; | ||
| 139 | /* We now have a series of blocks, BN_DEC_NUM chars | ||
| 140 | * in length, where the last one needs trucation. | ||
| 141 | * The blocks need to be reversed in order. */ | ||
| 142 | sprintf(p,BN_DEC_FMT1,*lp); | ||
| 143 | while (*p) p++; | ||
| 144 | while (lp != bn_data) | ||
| 145 | { | ||
| 146 | lp--; | ||
| 147 | sprintf(p,BN_DEC_FMT2,*lp); | ||
| 148 | while (*p) p++; | ||
| 149 | } | ||
| 150 | } | ||
| 151 | err: | ||
| 152 | if (bn_data != NULL) Free(bn_data); | ||
| 153 | if (t != NULL) BN_free(t); | ||
| 154 | return(buf); | ||
| 155 | } | ||
| 156 | |||
| 157 | int BN_hex2bn(BIGNUM **bn, const char *a) | ||
| 158 | { | ||
| 159 | BIGNUM *ret=NULL; | ||
| 160 | BN_ULONG l=0; | ||
| 161 | int neg=0,h,m,i,j,k,c; | ||
| 162 | int num; | ||
| 163 | |||
| 164 | if ((a == NULL) || (*a == '\0')) return(0); | ||
| 165 | |||
| 166 | if (*a == '-') { neg=1; a++; } | ||
| 167 | |||
| 168 | for (i=0; isxdigit((unsigned char) a[i]); i++) | ||
| 169 | ; | ||
| 170 | |||
| 171 | num=i+neg; | ||
| 172 | if (bn == NULL) return(num); | ||
| 173 | |||
| 174 | /* a is the start of the hex digets, and it is 'i' long */ | ||
| 175 | if (*bn == NULL) | ||
| 176 | { | ||
| 177 | if ((ret=BN_new()) == NULL) return(0); | ||
| 178 | } | ||
| 179 | else | ||
| 180 | { | ||
| 181 | ret= *bn; | ||
| 182 | BN_zero(ret); | ||
| 183 | } | ||
| 184 | |||
| 185 | /* i is the number of hex digests; */ | ||
| 186 | if (bn_expand(ret,i*4) == NULL) goto err; | ||
| 187 | |||
| 188 | j=i; /* least significate 'hex' */ | ||
| 189 | m=0; | ||
| 190 | h=0; | ||
| 191 | while (j > 0) | ||
| 192 | { | ||
| 193 | m=((BN_BYTES*2) <= j)?(BN_BYTES*2):j; | ||
| 194 | l=0; | ||
| 195 | for (;;) | ||
| 196 | { | ||
| 197 | c=a[j-m]; | ||
| 198 | if ((c >= '0') && (c <= '9')) k=c-'0'; | ||
| 199 | else if ((c >= 'a') && (c <= 'f')) k=c-'a'+10; | ||
| 200 | else if ((c >= 'A') && (c <= 'F')) k=c-'A'+10; | ||
| 201 | else k=0; /* paranoia */ | ||
| 202 | l=(l<<4)|k; | ||
| 203 | |||
| 204 | if (--m <= 0) | ||
| 205 | { | ||
| 206 | ret->d[h++]=l; | ||
| 207 | break; | ||
| 208 | } | ||
| 209 | } | ||
| 210 | j-=(BN_BYTES*2); | ||
| 211 | } | ||
| 212 | ret->top=h; | ||
| 213 | bn_fix_top(ret); | ||
| 214 | ret->neg=neg; | ||
| 215 | |||
| 216 | *bn=ret; | ||
| 217 | return(num); | ||
| 218 | err: | ||
| 219 | if (*bn == NULL) BN_free(ret); | ||
| 220 | return(0); | ||
| 221 | } | ||
| 222 | |||
| 223 | int BN_dec2bn(BIGNUM **bn, const char *a) | ||
| 224 | { | ||
| 225 | BIGNUM *ret=NULL; | ||
| 226 | BN_ULONG l=0; | ||
| 227 | int neg=0,i,j; | ||
| 228 | int num; | ||
| 229 | |||
| 230 | if ((a == NULL) || (*a == '\0')) return(0); | ||
| 231 | if (*a == '-') { neg=1; a++; } | ||
| 232 | |||
| 233 | for (i=0; isdigit((unsigned char) a[i]); i++) | ||
| 234 | ; | ||
| 235 | |||
| 236 | num=i+neg; | ||
| 237 | if (bn == NULL) return(num); | ||
| 238 | |||
| 239 | /* a is the start of the digets, and it is 'i' long. | ||
| 240 | * We chop it into BN_DEC_NUM digets at a time */ | ||
| 241 | if (*bn == NULL) | ||
| 242 | { | ||
| 243 | if ((ret=BN_new()) == NULL) return(0); | ||
| 244 | } | ||
| 245 | else | ||
| 246 | { | ||
| 247 | ret= *bn; | ||
| 248 | BN_zero(ret); | ||
| 249 | } | ||
| 250 | |||
| 251 | /* i is the number of digests, a bit of an over expand; */ | ||
| 252 | if (bn_expand(ret,i*4) == NULL) goto err; | ||
| 253 | |||
| 254 | j=BN_DEC_NUM-(i%BN_DEC_NUM); | ||
| 255 | if (j == BN_DEC_NUM) j=0; | ||
| 256 | l=0; | ||
| 257 | while (*a) | ||
| 258 | { | ||
| 259 | l*=10; | ||
| 260 | l+= *a-'0'; | ||
| 261 | a++; | ||
| 262 | if (++j == BN_DEC_NUM) | ||
| 263 | { | ||
| 264 | BN_mul_word(ret,BN_DEC_CONV); | ||
| 265 | BN_add_word(ret,l); | ||
| 266 | l=0; | ||
| 267 | j=0; | ||
| 268 | } | ||
| 269 | } | ||
| 270 | ret->neg=neg; | ||
| 271 | |||
| 272 | bn_fix_top(ret); | ||
| 273 | *bn=ret; | ||
| 274 | return(num); | ||
| 275 | err: | ||
| 276 | if (*bn == NULL) BN_free(ret); | ||
| 277 | return(0); | ||
| 278 | } | ||
| 279 | |||
| 280 | #ifndef NO_BIO | ||
| 281 | |||
| 282 | #ifndef NO_FP_API | ||
| 283 | int BN_print_fp(FILE *fp, BIGNUM *a) | ||
| 284 | { | ||
| 285 | BIO *b; | ||
| 286 | int ret; | ||
| 287 | |||
| 288 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
| 289 | return(0); | ||
| 290 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
| 291 | ret=BN_print(b,a); | ||
| 292 | BIO_free(b); | ||
| 293 | return(ret); | ||
| 294 | } | ||
| 295 | #endif | ||
| 296 | |||
| 297 | int BN_print(BIO *bp, const BIGNUM *a) | ||
| 298 | { | ||
| 299 | int i,j,v,z=0; | ||
| 300 | int ret=0; | ||
| 301 | |||
| 302 | if ((a->neg) && (BIO_write(bp,"-",1) != 1)) goto end; | ||
| 303 | if ((a->top == 0) && (BIO_write(bp,"0",1) != 1)) goto end; | ||
| 304 | for (i=a->top-1; i >=0; i--) | ||
| 305 | { | ||
| 306 | for (j=BN_BITS2-4; j >= 0; j-=4) | ||
| 307 | { | ||
| 308 | /* strip leading zeros */ | ||
| 309 | v=((int)(a->d[i]>>(long)j))&0x0f; | ||
| 310 | if (z || (v != 0)) | ||
| 311 | { | ||
| 312 | if (BIO_write(bp,&(Hex[v]),1) != 1) | ||
| 313 | goto end; | ||
| 314 | z=1; | ||
| 315 | } | ||
| 316 | } | ||
| 317 | } | ||
| 318 | ret=1; | ||
| 319 | end: | ||
| 320 | return(ret); | ||
| 321 | } | ||
| 322 | |||
| 323 | #endif | ||
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c deleted file mode 100644 index 91b8e34ae6..0000000000 --- a/src/lib/libcrypto/bn/bn_rand.c +++ /dev/null | |||
| @@ -1,117 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_rand.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <time.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "bn_lcl.h" | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | |||
| 65 | int BN_rand(BIGNUM *rnd, int bits, int top, int bottom) | ||
| 66 | { | ||
| 67 | unsigned char *buf=NULL; | ||
| 68 | int ret=0,bit,bytes,mask; | ||
| 69 | time_t tim; | ||
| 70 | |||
| 71 | bytes=(bits+7)/8; | ||
| 72 | bit=(bits-1)%8; | ||
| 73 | mask=0xff<<bit; | ||
| 74 | |||
| 75 | buf=(unsigned char *)Malloc(bytes); | ||
| 76 | if (buf == NULL) | ||
| 77 | { | ||
| 78 | BNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE); | ||
| 79 | goto err; | ||
| 80 | } | ||
| 81 | |||
| 82 | /* make a random number and set the top and bottom bits */ | ||
| 83 | time(&tim); | ||
| 84 | RAND_seed(&tim,sizeof(tim)); | ||
| 85 | |||
| 86 | RAND_bytes(buf,(int)bytes); | ||
| 87 | if (top) | ||
| 88 | { | ||
| 89 | if (bit == 0) | ||
| 90 | { | ||
| 91 | buf[0]=1; | ||
| 92 | buf[1]|=0x80; | ||
| 93 | } | ||
| 94 | else | ||
| 95 | { | ||
| 96 | buf[0]|=(3<<(bit-1)); | ||
| 97 | buf[0]&= ~(mask<<1); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | else | ||
| 101 | { | ||
| 102 | buf[0]|=(1<<bit); | ||
| 103 | buf[0]&= ~(mask<<1); | ||
| 104 | } | ||
| 105 | if (bottom) /* set bottom bits to whatever odd is */ | ||
| 106 | buf[bytes-1]|=1; | ||
| 107 | if (!BN_bin2bn(buf,bytes,rnd)) goto err; | ||
| 108 | ret=1; | ||
| 109 | err: | ||
| 110 | if (buf != NULL) | ||
| 111 | { | ||
| 112 | memset(buf,0,bytes); | ||
| 113 | Free(buf); | ||
| 114 | } | ||
| 115 | return(ret); | ||
| 116 | } | ||
| 117 | |||
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c deleted file mode 100644 index c1b0e230ea..0000000000 --- a/src/lib/libcrypto/bn/bn_recp.c +++ /dev/null | |||
| @@ -1,227 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_recp.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | void BN_RECP_CTX_init(BN_RECP_CTX *recp) | ||
| 64 | { | ||
| 65 | BN_init(&(recp->N)); | ||
| 66 | BN_init(&(recp->Nr)); | ||
| 67 | recp->num_bits=0; | ||
| 68 | recp->flags=0; | ||
| 69 | } | ||
| 70 | |||
| 71 | BN_RECP_CTX *BN_RECP_CTX_new(void) | ||
| 72 | { | ||
| 73 | BN_RECP_CTX *ret; | ||
| 74 | |||
| 75 | if ((ret=(BN_RECP_CTX *)Malloc(sizeof(BN_RECP_CTX))) == NULL) | ||
| 76 | return(NULL); | ||
| 77 | |||
| 78 | BN_RECP_CTX_init(ret); | ||
| 79 | ret->flags=BN_FLG_MALLOCED; | ||
| 80 | return(ret); | ||
| 81 | } | ||
| 82 | |||
| 83 | void BN_RECP_CTX_free(BN_RECP_CTX *recp) | ||
| 84 | { | ||
| 85 | if(recp == NULL) | ||
| 86 | return; | ||
| 87 | |||
| 88 | BN_free(&(recp->N)); | ||
| 89 | BN_free(&(recp->Nr)); | ||
| 90 | if (recp->flags & BN_FLG_MALLOCED) | ||
| 91 | Free(recp); | ||
| 92 | } | ||
| 93 | |||
| 94 | int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx) | ||
| 95 | { | ||
| 96 | BN_copy(&(recp->N),d); | ||
| 97 | BN_zero(&(recp->Nr)); | ||
| 98 | recp->num_bits=BN_num_bits(d); | ||
| 99 | recp->shift=0; | ||
| 100 | return(1); | ||
| 101 | } | ||
| 102 | |||
| 103 | int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_RECP_CTX *recp, | ||
| 104 | BN_CTX *ctx) | ||
| 105 | { | ||
| 106 | int ret=0; | ||
| 107 | BIGNUM *a; | ||
| 108 | |||
| 109 | a= &(ctx->bn[ctx->tos++]); | ||
| 110 | if (y != NULL) | ||
| 111 | { | ||
| 112 | if (x == y) | ||
| 113 | { if (!BN_sqr(a,x,ctx)) goto err; } | ||
| 114 | else | ||
| 115 | { if (!BN_mul(a,x,y,ctx)) goto err; } | ||
| 116 | } | ||
| 117 | else | ||
| 118 | a=x; /* Just do the mod */ | ||
| 119 | |||
| 120 | BN_div_recp(NULL,r,a,recp,ctx); | ||
| 121 | ret=1; | ||
| 122 | err: | ||
| 123 | ctx->tos--; | ||
| 124 | return(ret); | ||
| 125 | } | ||
| 126 | |||
| 127 | int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp, | ||
| 128 | BN_CTX *ctx) | ||
| 129 | { | ||
| 130 | int i,j,tos,ret=0,ex; | ||
| 131 | BIGNUM *a,*b,*d,*r; | ||
| 132 | |||
| 133 | tos=ctx->tos; | ||
| 134 | a= &(ctx->bn[ctx->tos++]); | ||
| 135 | b= &(ctx->bn[ctx->tos++]); | ||
| 136 | if (dv != NULL) | ||
| 137 | d=dv; | ||
| 138 | else | ||
| 139 | d= &(ctx->bn[ctx->tos++]); | ||
| 140 | if (rem != NULL) | ||
| 141 | r=rem; | ||
| 142 | else | ||
| 143 | r= &(ctx->bn[ctx->tos++]); | ||
| 144 | |||
| 145 | if (BN_ucmp(m,&(recp->N)) < 0) | ||
| 146 | { | ||
| 147 | BN_zero(d); | ||
| 148 | BN_copy(r,m); | ||
| 149 | ctx->tos=tos; | ||
| 150 | return(1); | ||
| 151 | } | ||
| 152 | |||
| 153 | /* We want the remainder | ||
| 154 | * Given input of ABCDEF / ab | ||
| 155 | * we need multiply ABCDEF by 3 digests of the reciprocal of ab | ||
| 156 | * | ||
| 157 | */ | ||
| 158 | i=BN_num_bits(m); | ||
| 159 | |||
| 160 | j=recp->num_bits*2; | ||
| 161 | if (j > i) | ||
| 162 | { | ||
| 163 | i=j; | ||
| 164 | ex=0; | ||
| 165 | } | ||
| 166 | else | ||
| 167 | { | ||
| 168 | ex=(i-j)/2; | ||
| 169 | } | ||
| 170 | |||
| 171 | j=i/2; | ||
| 172 | |||
| 173 | if (i != recp->shift) | ||
| 174 | recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N), | ||
| 175 | i,ctx); | ||
| 176 | |||
| 177 | if (!BN_rshift(a,m,j-ex)) goto err; | ||
| 178 | if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err; | ||
| 179 | if (!BN_rshift(d,b,j+ex)) goto err; | ||
| 180 | d->neg=0; | ||
| 181 | if (!BN_mul(b,&(recp->N),d,ctx)) goto err; | ||
| 182 | if (!BN_usub(r,m,b)) goto err; | ||
| 183 | r->neg=0; | ||
| 184 | |||
| 185 | j=0; | ||
| 186 | #if 1 | ||
| 187 | while (BN_ucmp(r,&(recp->N)) >= 0) | ||
| 188 | { | ||
| 189 | if (j++ > 2) | ||
| 190 | { | ||
| 191 | BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL); | ||
| 192 | goto err; | ||
| 193 | } | ||
| 194 | if (!BN_usub(r,r,&(recp->N))) goto err; | ||
| 195 | if (!BN_add_word(d,1)) goto err; | ||
| 196 | } | ||
| 197 | #endif | ||
| 198 | |||
| 199 | r->neg=BN_is_zero(r)?0:m->neg; | ||
| 200 | d->neg=m->neg^recp->N.neg; | ||
| 201 | ret=1; | ||
| 202 | err: | ||
| 203 | ctx->tos=tos; | ||
| 204 | return(ret); | ||
| 205 | } | ||
| 206 | |||
| 207 | /* len is the expected size of the result | ||
| 208 | * We actually calculate with an extra word of precision, so | ||
| 209 | * we can do faster division if the remainder is not required. | ||
| 210 | */ | ||
| 211 | int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx) | ||
| 212 | { | ||
| 213 | int ret= -1; | ||
| 214 | BIGNUM t; | ||
| 215 | |||
| 216 | BN_init(&t); | ||
| 217 | |||
| 218 | BN_zero(&t); | ||
| 219 | if (!BN_set_bit(&t,len)) goto err; | ||
| 220 | |||
| 221 | if (!BN_div(r,NULL,&t,m,ctx)) goto err; | ||
| 222 | ret=len; | ||
| 223 | err: | ||
| 224 | BN_free(&t); | ||
| 225 | return(ret); | ||
| 226 | } | ||
| 227 | |||
diff --git a/src/lib/libcrypto/bn/bn_shift.c b/src/lib/libcrypto/bn/bn_shift.c deleted file mode 100644 index 61aae65a6b..0000000000 --- a/src/lib/libcrypto/bn/bn_shift.c +++ /dev/null | |||
| @@ -1,200 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_shift.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | int BN_lshift1(BIGNUM *r, BIGNUM *a) | ||
| 64 | { | ||
| 65 | register BN_ULONG *ap,*rp,t,c; | ||
| 66 | int i; | ||
| 67 | |||
| 68 | if (r != a) | ||
| 69 | { | ||
| 70 | r->neg=a->neg; | ||
| 71 | if (bn_wexpand(r,a->top+1) == NULL) return(0); | ||
| 72 | r->top=a->top; | ||
| 73 | } | ||
| 74 | else | ||
| 75 | { | ||
| 76 | if (bn_wexpand(r,a->top+1) == NULL) return(0); | ||
| 77 | } | ||
| 78 | ap=a->d; | ||
| 79 | rp=r->d; | ||
| 80 | c=0; | ||
| 81 | for (i=0; i<a->top; i++) | ||
| 82 | { | ||
| 83 | t= *(ap++); | ||
| 84 | *(rp++)=((t<<1)|c)&BN_MASK2; | ||
| 85 | c=(t & BN_TBIT)?1:0; | ||
| 86 | } | ||
| 87 | if (c) | ||
| 88 | { | ||
| 89 | *rp=1; | ||
| 90 | r->top++; | ||
| 91 | } | ||
| 92 | return(1); | ||
| 93 | } | ||
| 94 | |||
| 95 | int BN_rshift1(BIGNUM *r, BIGNUM *a) | ||
| 96 | { | ||
| 97 | BN_ULONG *ap,*rp,t,c; | ||
| 98 | int i; | ||
| 99 | |||
| 100 | if (BN_is_zero(a)) | ||
| 101 | { | ||
| 102 | BN_zero(r); | ||
| 103 | return(1); | ||
| 104 | } | ||
| 105 | if (a != r) | ||
| 106 | { | ||
| 107 | if (bn_wexpand(r,a->top) == NULL) return(0); | ||
| 108 | r->top=a->top; | ||
| 109 | r->neg=a->neg; | ||
| 110 | } | ||
| 111 | ap=a->d; | ||
| 112 | rp=r->d; | ||
| 113 | c=0; | ||
| 114 | for (i=a->top-1; i>=0; i--) | ||
| 115 | { | ||
| 116 | t=ap[i]; | ||
| 117 | rp[i]=((t>>1)&BN_MASK2)|c; | ||
| 118 | c=(t&1)?BN_TBIT:0; | ||
| 119 | } | ||
| 120 | bn_fix_top(r); | ||
| 121 | return(1); | ||
| 122 | } | ||
| 123 | |||
| 124 | int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) | ||
| 125 | { | ||
| 126 | int i,nw,lb,rb; | ||
| 127 | BN_ULONG *t,*f; | ||
| 128 | BN_ULONG l; | ||
| 129 | |||
| 130 | r->neg=a->neg; | ||
| 131 | if (bn_wexpand(r,a->top+(n/BN_BITS2)+1) == NULL) return(0); | ||
| 132 | nw=n/BN_BITS2; | ||
| 133 | lb=n%BN_BITS2; | ||
| 134 | rb=BN_BITS2-lb; | ||
| 135 | f=a->d; | ||
| 136 | t=r->d; | ||
| 137 | t[a->top+nw]=0; | ||
| 138 | if (lb == 0) | ||
| 139 | for (i=a->top-1; i>=0; i--) | ||
| 140 | t[nw+i]=f[i]; | ||
| 141 | else | ||
| 142 | for (i=a->top-1; i>=0; i--) | ||
| 143 | { | ||
| 144 | l=f[i]; | ||
| 145 | t[nw+i+1]|=(l>>rb)&BN_MASK2; | ||
| 146 | t[nw+i]=(l<<lb)&BN_MASK2; | ||
| 147 | } | ||
| 148 | memset(t,0,nw*sizeof(t[0])); | ||
| 149 | /* for (i=0; i<nw; i++) | ||
| 150 | t[i]=0;*/ | ||
| 151 | r->top=a->top+nw+1; | ||
| 152 | bn_fix_top(r); | ||
| 153 | return(1); | ||
| 154 | } | ||
| 155 | |||
| 156 | int BN_rshift(BIGNUM *r, BIGNUM *a, int n) | ||
| 157 | { | ||
| 158 | int i,j,nw,lb,rb; | ||
| 159 | BN_ULONG *t,*f; | ||
| 160 | BN_ULONG l,tmp; | ||
| 161 | |||
| 162 | nw=n/BN_BITS2; | ||
| 163 | rb=n%BN_BITS2; | ||
| 164 | lb=BN_BITS2-rb; | ||
| 165 | if (nw > a->top) | ||
| 166 | { | ||
| 167 | BN_zero(r); | ||
| 168 | return(1); | ||
| 169 | } | ||
| 170 | if (r != a) | ||
| 171 | { | ||
| 172 | r->neg=a->neg; | ||
| 173 | if (bn_wexpand(r,a->top-nw+1) == NULL) return(0); | ||
| 174 | } | ||
| 175 | |||
| 176 | f= &(a->d[nw]); | ||
| 177 | t=r->d; | ||
| 178 | j=a->top-nw; | ||
| 179 | r->top=j; | ||
| 180 | |||
| 181 | if (rb == 0) | ||
| 182 | { | ||
| 183 | for (i=j+1; i > 0; i--) | ||
| 184 | *(t++)= *(f++); | ||
| 185 | } | ||
| 186 | else | ||
| 187 | { | ||
| 188 | l= *(f++); | ||
| 189 | for (i=1; i<j; i++) | ||
| 190 | { | ||
| 191 | tmp =(l>>rb)&BN_MASK2; | ||
| 192 | l= *(f++); | ||
| 193 | *(t++) =(tmp|(l<<lb))&BN_MASK2; | ||
| 194 | } | ||
| 195 | *(t++) =(l>>rb)&BN_MASK2; | ||
| 196 | } | ||
| 197 | *t=0; | ||
| 198 | bn_fix_top(r); | ||
| 199 | return(1); | ||
| 200 | } | ||
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c deleted file mode 100644 index 12cce4d7ce..0000000000 --- a/src/lib/libcrypto/bn/bn_sqr.c +++ /dev/null | |||
| @@ -1,281 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_sqr.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | /* r must not be a */ | ||
| 64 | /* I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96 */ | ||
| 65 | int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx) | ||
| 66 | { | ||
| 67 | int max,al; | ||
| 68 | BIGNUM *tmp,*rr; | ||
| 69 | |||
| 70 | #ifdef BN_COUNT | ||
| 71 | printf("BN_sqr %d * %d\n",a->top,a->top); | ||
| 72 | #endif | ||
| 73 | bn_check_top(a); | ||
| 74 | tmp= &(ctx->bn[ctx->tos]); | ||
| 75 | rr=(a != r)?r: (&ctx->bn[ctx->tos+1]); | ||
| 76 | |||
| 77 | al=a->top; | ||
| 78 | if (al <= 0) | ||
| 79 | { | ||
| 80 | r->top=0; | ||
| 81 | return(1); | ||
| 82 | } | ||
| 83 | |||
| 84 | max=(al+al); | ||
| 85 | if (bn_wexpand(rr,max+1) == NULL) return(0); | ||
| 86 | |||
| 87 | r->neg=0; | ||
| 88 | if (al == 4) | ||
| 89 | { | ||
| 90 | #ifndef BN_SQR_COMBA | ||
| 91 | BN_ULONG t[8]; | ||
| 92 | bn_sqr_normal(rr->d,a->d,4,t); | ||
| 93 | #else | ||
| 94 | bn_sqr_comba4(rr->d,a->d); | ||
| 95 | #endif | ||
| 96 | } | ||
| 97 | else if (al == 8) | ||
| 98 | { | ||
| 99 | #ifndef BN_SQR_COMBA | ||
| 100 | BN_ULONG t[16]; | ||
| 101 | bn_sqr_normal(rr->d,a->d,8,t); | ||
| 102 | #else | ||
| 103 | bn_sqr_comba8(rr->d,a->d); | ||
| 104 | #endif | ||
| 105 | } | ||
| 106 | else | ||
| 107 | { | ||
| 108 | #if defined(BN_RECURSION) | ||
| 109 | if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) | ||
| 110 | { | ||
| 111 | BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2]; | ||
| 112 | bn_sqr_normal(rr->d,a->d,al,t); | ||
| 113 | } | ||
| 114 | else | ||
| 115 | { | ||
| 116 | int j,k; | ||
| 117 | |||
| 118 | j=BN_num_bits_word((BN_ULONG)al); | ||
| 119 | j=1<<(j-1); | ||
| 120 | k=j+j; | ||
| 121 | if (al == j) | ||
| 122 | { | ||
| 123 | if (bn_wexpand(a,k*2) == NULL) return(0); | ||
| 124 | if (bn_wexpand(tmp,k*2) == NULL) return(0); | ||
| 125 | bn_sqr_recursive(rr->d,a->d,al,tmp->d); | ||
| 126 | } | ||
| 127 | else | ||
| 128 | { | ||
| 129 | if (bn_wexpand(tmp,max) == NULL) return(0); | ||
| 130 | bn_sqr_normal(rr->d,a->d,al,tmp->d); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | #else | ||
| 134 | if (bn_wexpand(tmp,max) == NULL) return(0); | ||
| 135 | bn_sqr_normal(rr->d,a->d,al,tmp->d); | ||
| 136 | #endif | ||
| 137 | } | ||
| 138 | |||
| 139 | rr->top=max; | ||
| 140 | if ((max > 0) && (rr->d[max-1] == 0)) rr->top--; | ||
| 141 | if (rr != r) BN_copy(r,rr); | ||
| 142 | return(1); | ||
| 143 | } | ||
| 144 | |||
| 145 | /* tmp must have 2*n words */ | ||
| 146 | void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp) | ||
| 147 | { | ||
| 148 | int i,j,max; | ||
| 149 | BN_ULONG *ap,*rp; | ||
| 150 | |||
| 151 | max=n*2; | ||
| 152 | ap=a; | ||
| 153 | rp=r; | ||
| 154 | rp[0]=rp[max-1]=0; | ||
| 155 | rp++; | ||
| 156 | j=n; | ||
| 157 | |||
| 158 | if (--j > 0) | ||
| 159 | { | ||
| 160 | ap++; | ||
| 161 | rp[j]=bn_mul_words(rp,ap,j,ap[-1]); | ||
| 162 | rp+=2; | ||
| 163 | } | ||
| 164 | |||
| 165 | for (i=n-2; i>0; i--) | ||
| 166 | { | ||
| 167 | j--; | ||
| 168 | ap++; | ||
| 169 | rp[j]=bn_mul_add_words(rp,ap,j,ap[-1]); | ||
| 170 | rp+=2; | ||
| 171 | } | ||
| 172 | |||
| 173 | bn_add_words(r,r,r,max); | ||
| 174 | |||
| 175 | /* There will not be a carry */ | ||
| 176 | |||
| 177 | bn_sqr_words(tmp,a,n); | ||
| 178 | |||
| 179 | bn_add_words(r,r,tmp,max); | ||
| 180 | } | ||
| 181 | |||
| 182 | #ifdef BN_RECURSION | ||
| 183 | /* r is 2*n words in size, | ||
| 184 | * a and b are both n words in size. | ||
| 185 | * n must be a power of 2. | ||
| 186 | * We multiply and return the result. | ||
| 187 | * t must be 2*n words in size | ||
| 188 | * We calulate | ||
| 189 | * a[0]*b[0] | ||
| 190 | * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) | ||
| 191 | * a[1]*b[1] | ||
| 192 | */ | ||
| 193 | void bn_sqr_recursive(BN_ULONG *r, BN_ULONG *a, int n2, BN_ULONG *t) | ||
| 194 | { | ||
| 195 | int n=n2/2; | ||
| 196 | int zero,c1; | ||
| 197 | BN_ULONG ln,lo,*p; | ||
| 198 | |||
| 199 | #ifdef BN_COUNT | ||
| 200 | printf(" bn_sqr_recursive %d * %d\n",n2,n2); | ||
| 201 | #endif | ||
| 202 | if (n2 == 4) | ||
| 203 | { | ||
| 204 | #ifndef BN_SQR_COMBA | ||
| 205 | bn_sqr_normal(r,a,4,t); | ||
| 206 | #else | ||
| 207 | bn_sqr_comba4(r,a); | ||
| 208 | #endif | ||
| 209 | return; | ||
| 210 | } | ||
| 211 | else if (n2 == 8) | ||
| 212 | { | ||
| 213 | #ifndef BN_SQR_COMBA | ||
| 214 | bn_sqr_normal(r,a,8,t); | ||
| 215 | #else | ||
| 216 | bn_sqr_comba8(r,a); | ||
| 217 | #endif | ||
| 218 | return; | ||
| 219 | } | ||
| 220 | if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL) | ||
| 221 | { | ||
| 222 | bn_sqr_normal(r,a,n2,t); | ||
| 223 | return; | ||
| 224 | } | ||
| 225 | /* r=(a[0]-a[1])*(a[1]-a[0]) */ | ||
| 226 | c1=bn_cmp_words(a,&(a[n]),n); | ||
| 227 | zero=0; | ||
| 228 | if (c1 > 0) | ||
| 229 | bn_sub_words(t,a,&(a[n]),n); | ||
| 230 | else if (c1 < 0) | ||
| 231 | bn_sub_words(t,&(a[n]),a,n); | ||
| 232 | else | ||
| 233 | zero=1; | ||
| 234 | |||
| 235 | /* The result will always be negative unless it is zero */ | ||
| 236 | p= &(t[n2*2]); | ||
| 237 | |||
| 238 | if (!zero) | ||
| 239 | bn_sqr_recursive(&(t[n2]),t,n,p); | ||
| 240 | else | ||
| 241 | memset(&(t[n2]),0,n*sizeof(BN_ULONG)); | ||
| 242 | bn_sqr_recursive(r,a,n,p); | ||
| 243 | bn_sqr_recursive(&(r[n2]),&(a[n]),n,p); | ||
| 244 | |||
| 245 | /* t[32] holds (a[0]-a[1])*(a[1]-a[0]), it is negative or zero | ||
| 246 | * r[10] holds (a[0]*b[0]) | ||
| 247 | * r[32] holds (b[1]*b[1]) | ||
| 248 | */ | ||
| 249 | |||
| 250 | c1=(int)(bn_add_words(t,r,&(r[n2]),n2)); | ||
| 251 | |||
| 252 | /* t[32] is negative */ | ||
| 253 | c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2)); | ||
| 254 | |||
| 255 | /* t[32] holds (a[0]-a[1])*(a[1]-a[0])+(a[0]*a[0])+(a[1]*a[1]) | ||
| 256 | * r[10] holds (a[0]*a[0]) | ||
| 257 | * r[32] holds (a[1]*a[1]) | ||
| 258 | * c1 holds the carry bits | ||
| 259 | */ | ||
| 260 | c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2)); | ||
| 261 | if (c1) | ||
| 262 | { | ||
| 263 | p= &(r[n+n2]); | ||
| 264 | lo= *p; | ||
| 265 | ln=(lo+c1)&BN_MASK2; | ||
| 266 | *p=ln; | ||
| 267 | |||
| 268 | /* The overflow will stop before we over write | ||
| 269 | * words we should not overwrite */ | ||
| 270 | if (ln < (BN_ULONG)c1) | ||
| 271 | { | ||
| 272 | do { | ||
| 273 | p++; | ||
| 274 | lo= *p; | ||
| 275 | ln=(lo+1)&BN_MASK2; | ||
| 276 | *p=ln; | ||
| 277 | } while (ln == 0); | ||
| 278 | } | ||
| 279 | } | ||
| 280 | } | ||
| 281 | #endif | ||
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c deleted file mode 100644 index c0cfbc6797..0000000000 --- a/src/lib/libcrypto/bn/bn_word.c +++ /dev/null | |||
| @@ -1,194 +0,0 @@ | |||
| 1 | /* crypto/bn/bn_word.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include "bn_lcl.h" | ||
| 62 | |||
| 63 | BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w) | ||
| 64 | { | ||
| 65 | #ifndef BN_LLONG | ||
| 66 | BN_ULONG ret=0; | ||
| 67 | #else | ||
| 68 | BN_ULLONG ret=0; | ||
| 69 | #endif | ||
| 70 | int i; | ||
| 71 | |||
| 72 | w&=BN_MASK2; | ||
| 73 | for (i=a->top-1; i>=0; i--) | ||
| 74 | { | ||
| 75 | #ifndef BN_LLONG | ||
| 76 | ret=((ret<<BN_BITS4)|((a->d[i]>>BN_BITS4)&BN_MASK2l))%w; | ||
| 77 | ret=((ret<<BN_BITS4)|(a->d[i]&BN_MASK2l))%w; | ||
| 78 | #else | ||
| 79 | ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])% | ||
| 80 | (BN_ULLONG)w); | ||
| 81 | #endif | ||
| 82 | } | ||
| 83 | return((BN_ULONG)ret); | ||
| 84 | } | ||
| 85 | |||
| 86 | BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w) | ||
| 87 | { | ||
| 88 | BN_ULONG ret; | ||
| 89 | int i; | ||
| 90 | |||
| 91 | if (a->top == 0) return(0); | ||
| 92 | ret=0; | ||
| 93 | w&=BN_MASK2; | ||
| 94 | for (i=a->top-1; i>=0; i--) | ||
| 95 | { | ||
| 96 | BN_ULONG l,d; | ||
| 97 | |||
| 98 | l=a->d[i]; | ||
| 99 | d=bn_div_words(ret,l,w); | ||
| 100 | ret=(l-((d*w)&BN_MASK2))&BN_MASK2; | ||
| 101 | a->d[i]=d; | ||
| 102 | } | ||
| 103 | if ((a->top > 0) && (a->d[a->top-1] == 0)) | ||
| 104 | a->top--; | ||
| 105 | return(ret); | ||
| 106 | } | ||
| 107 | |||
| 108 | int BN_add_word(BIGNUM *a, BN_ULONG w) | ||
| 109 | { | ||
| 110 | BN_ULONG l; | ||
| 111 | int i; | ||
| 112 | |||
| 113 | if (a->neg) | ||
| 114 | { | ||
| 115 | a->neg=0; | ||
| 116 | i=BN_sub_word(a,w); | ||
| 117 | if (!BN_is_zero(a)) | ||
| 118 | a->neg=1; | ||
| 119 | return(i); | ||
| 120 | } | ||
| 121 | w&=BN_MASK2; | ||
| 122 | if (bn_wexpand(a,a->top+1) == NULL) return(0); | ||
| 123 | i=0; | ||
| 124 | for (;;) | ||
| 125 | { | ||
| 126 | l=(a->d[i]+(BN_ULONG)w)&BN_MASK2; | ||
| 127 | a->d[i]=l; | ||
| 128 | if (w > l) | ||
| 129 | w=1; | ||
| 130 | else | ||
| 131 | break; | ||
| 132 | i++; | ||
| 133 | } | ||
| 134 | if (i >= a->top) | ||
| 135 | a->top++; | ||
| 136 | return(1); | ||
| 137 | } | ||
| 138 | |||
| 139 | int BN_sub_word(BIGNUM *a, BN_ULONG w) | ||
| 140 | { | ||
| 141 | int i; | ||
| 142 | |||
| 143 | if (a->neg) | ||
| 144 | { | ||
| 145 | a->neg=0; | ||
| 146 | i=BN_add_word(a,w); | ||
| 147 | a->neg=1; | ||
| 148 | return(i); | ||
| 149 | } | ||
| 150 | |||
| 151 | w&=BN_MASK2; | ||
| 152 | if ((a->top == 1) && (a->d[0] < w)) | ||
| 153 | { | ||
| 154 | a->d[0]=w-a->d[0]; | ||
| 155 | a->neg=1; | ||
| 156 | return(1); | ||
| 157 | } | ||
| 158 | i=0; | ||
| 159 | for (;;) | ||
| 160 | { | ||
| 161 | if (a->d[i] >= w) | ||
| 162 | { | ||
| 163 | a->d[i]-=w; | ||
| 164 | break; | ||
| 165 | } | ||
| 166 | else | ||
| 167 | { | ||
| 168 | a->d[i]=(a->d[i]-w)&BN_MASK2; | ||
| 169 | i++; | ||
| 170 | w=1; | ||
| 171 | } | ||
| 172 | } | ||
| 173 | if ((a->d[i] == 0) && (i == (a->top-1))) | ||
| 174 | a->top--; | ||
| 175 | return(1); | ||
| 176 | } | ||
| 177 | |||
| 178 | int BN_mul_word(BIGNUM *a, BN_ULONG w) | ||
| 179 | { | ||
| 180 | BN_ULONG ll; | ||
| 181 | |||
| 182 | w&=BN_MASK2; | ||
| 183 | if (a->top) | ||
| 184 | { | ||
| 185 | ll=bn_mul_words(a->d,a->d,a->top,w); | ||
| 186 | if (ll) | ||
| 187 | { | ||
| 188 | if (bn_wexpand(a,a->top+1) == NULL) return(0); | ||
| 189 | a->d[a->top++]=ll; | ||
| 190 | } | ||
| 191 | } | ||
| 192 | return(1); | ||
| 193 | } | ||
| 194 | |||
