diff options
| author | ryker <> | 1998-10-05 20:13:15 +0000 |
|---|---|---|
| committer | ryker <> | 1998-10-05 20:13:15 +0000 |
| commit | 9e77c62555877f9a64805c49d0dcd7dbfbb40f4e (patch) | |
| tree | 2a6396b738ecede1e1dd3ad84c90e47e21d0bcbd /src/lib/libcrypto/bn | |
| parent | fe5d0717e2760d02faf23bf5a714f17b33ae4abb (diff) | |
| parent | 536c76cbb863bab152f19842ab88772c01e922c7 (diff) | |
| download | openbsd-9e77c62555877f9a64805c49d0dcd7dbfbb40f4e.tar.gz openbsd-9e77c62555877f9a64805c49d0dcd7dbfbb40f4e.tar.bz2 openbsd-9e77c62555877f9a64805c49d0dcd7dbfbb40f4e.zip | |
This commit was generated by cvs2git to track changes on a CVS vendor
branch.
Diffstat (limited to 'src/lib/libcrypto/bn')
| -rw-r--r-- | src/lib/libcrypto/bn/asm/README | 30 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/asm/alpha.s | 344 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/asm/pa-risc.s | 710 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/asm/r3000.s | 646 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/bnspeed.c | 248 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/bntest.c | 777 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/expspeed.c | 230 | ||||
| -rw-r--r-- | src/lib/libcrypto/bn/exptest.c | 148 |
8 files changed, 3133 insertions, 0 deletions
diff --git a/src/lib/libcrypto/bn/asm/README b/src/lib/libcrypto/bn/asm/README new file mode 100644 index 0000000000..d93fbff77f --- /dev/null +++ b/src/lib/libcrypto/bn/asm/README | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | All assember in this directory are just version of the file | ||
| 2 | crypto/bn/bn_mulw.c. | ||
| 3 | |||
| 4 | Quite a few of these files are just the assember output from gcc since on | ||
| 5 | quite a few machines they are 2 times faster than the system compiler. | ||
| 6 | |||
| 7 | For the x86, I have hand written assember because of the bad job all | ||
| 8 | compilers seem to do on it. This normally gives a 2 time speed up in the RSA | ||
| 9 | routines. | ||
| 10 | |||
| 11 | For the DEC alpha, I also hand wrote the assember (except the division which | ||
| 12 | is just the output from the C compiler pasted on the end of the file). | ||
| 13 | On the 2 alpha C compilers I had access to, it was not possible to do | ||
| 14 | 64b x 64b -> 128b calculations (both long and the long long data types | ||
| 15 | were 64 bits). So the hand assember gives access to the 128 bit result and | ||
| 16 | a 2 times speedup :-). | ||
| 17 | |||
| 18 | The x86xxxx.obj files are the assembled version of x86xxxx.asm files. | ||
| 19 | I had such a hard time finding a macro assember for Microsoft, I decided to | ||
| 20 | include the object file to save others the hassle :-). | ||
| 21 | |||
| 22 | I have also included uu encoded versions of the .obj incase they get | ||
| 23 | trashed. | ||
| 24 | |||
| 25 | There are 2 versions of assember for the HP PA-RISC. | ||
| 26 | pa-risc.s is the origional one which works fine. | ||
| 27 | pa-risc2.s is a new version that often generates warnings but if the | ||
| 28 | tests pass, it gives performance that is over 2 times faster than | ||
| 29 | pa-risc.s. | ||
| 30 | Both were generated using gcc :-) | ||
diff --git a/src/lib/libcrypto/bn/asm/alpha.s b/src/lib/libcrypto/bn/asm/alpha.s new file mode 100644 index 0000000000..1d17b1d619 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/alpha.s | |||
| @@ -0,0 +1,344 @@ | |||
| 1 | # DEC Alpha assember | ||
| 2 | # The bn_div64 is actually gcc output but the other parts are hand done. | ||
| 3 | # Thanks to tzeruch@ceddec.com for sending me the gcc output for | ||
| 4 | # bn_div64. | ||
| 5 | .file 1 "bn_mulw.c" | ||
| 6 | .set noat | ||
| 7 | gcc2_compiled.: | ||
| 8 | __gnu_compiled_c: | ||
| 9 | .text | ||
| 10 | .align 3 | ||
| 11 | .globl bn_mul_add_words | ||
| 12 | .ent bn_mul_add_words | ||
| 13 | bn_mul_add_words: | ||
| 14 | bn_mul_add_words..ng: | ||
| 15 | .frame $30,0,$26,0 | ||
| 16 | .prologue 0 | ||
| 17 | subq $18,2,$25 # num=-2 | ||
| 18 | bis $31,$31,$0 | ||
| 19 | blt $25,$42 | ||
| 20 | .align 5 | ||
| 21 | $142: | ||
| 22 | subq $18,2,$18 # num-=2 | ||
| 23 | subq $25,2,$25 # num-=2 | ||
| 24 | |||
| 25 | ldq $1,0($17) # a[0] | ||
| 26 | ldq $2,8($17) # a[1] | ||
| 27 | |||
| 28 | mulq $19,$1,$3 # a[0]*w low part r3 | ||
| 29 | umulh $19,$1,$1 # a[0]*w high part r1 | ||
| 30 | mulq $19,$2,$4 # a[1]*w low part r4 | ||
| 31 | umulh $19,$2,$2 # a[1]*w high part r2 | ||
| 32 | |||
| 33 | ldq $22,0($16) # r[0] r22 | ||
| 34 | ldq $23,8($16) # r[1] r23 | ||
| 35 | |||
| 36 | addq $3,$22,$3 # a0 low part + r[0] | ||
| 37 | addq $4,$23,$4 # a1 low part + r[1] | ||
| 38 | cmpult $3,$22,$5 # overflow? | ||
| 39 | cmpult $4,$23,$6 # overflow? | ||
| 40 | addq $5,$1,$1 # high part + overflow | ||
| 41 | addq $6,$2,$2 # high part + overflow | ||
| 42 | |||
| 43 | addq $3,$0,$3 # add c | ||
| 44 | cmpult $3,$0,$5 # overflow? | ||
| 45 | stq $3,0($16) | ||
| 46 | addq $5,$1,$0 # c=high part + overflow | ||
| 47 | |||
| 48 | addq $4,$0,$4 # add c | ||
| 49 | cmpult $4,$0,$5 # overflow? | ||
| 50 | stq $4,8($16) | ||
| 51 | addq $5,$2,$0 # c=high part + overflow | ||
| 52 | |||
| 53 | ble $18,$43 | ||
| 54 | |||
| 55 | addq $16,16,$16 | ||
| 56 | addq $17,16,$17 | ||
| 57 | blt $25,$42 | ||
| 58 | |||
| 59 | br $31,$142 | ||
| 60 | $42: | ||
| 61 | ldq $1,0($17) # a[0] | ||
| 62 | umulh $19,$1,$3 # a[0]*w high part | ||
| 63 | mulq $19,$1,$1 # a[0]*w low part | ||
| 64 | ldq $2,0($16) # r[0] | ||
| 65 | addq $1,$2,$1 # low part + r[0] | ||
| 66 | cmpult $1,$2,$4 # overflow? | ||
| 67 | addq $4,$3,$3 # high part + overflow | ||
| 68 | addq $1,$0,$1 # add c | ||
| 69 | cmpult $1,$0,$4 # overflow? | ||
| 70 | addq $4,$3,$0 # c=high part + overflow | ||
| 71 | stq $1,0($16) | ||
| 72 | |||
| 73 | .align 4 | ||
| 74 | $43: | ||
| 75 | ret $31,($26),1 | ||
| 76 | .end bn_mul_add_words | ||
| 77 | .align 3 | ||
| 78 | .globl bn_mul_words | ||
| 79 | .ent bn_mul_words | ||
| 80 | bn_mul_words: | ||
| 81 | bn_mul_words..ng: | ||
| 82 | .frame $30,0,$26,0 | ||
| 83 | .prologue 0 | ||
| 84 | subq $18,2,$25 # num=-2 | ||
| 85 | bis $31,$31,$0 | ||
| 86 | blt $25,$242 | ||
| 87 | .align 5 | ||
| 88 | $342: | ||
| 89 | subq $18,2,$18 # num-=2 | ||
| 90 | subq $25,2,$25 # num-=2 | ||
| 91 | |||
| 92 | ldq $1,0($17) # a[0] | ||
| 93 | ldq $2,8($17) # a[1] | ||
| 94 | |||
| 95 | mulq $19,$1,$3 # a[0]*w low part r3 | ||
| 96 | umulh $19,$1,$1 # a[0]*w high part r1 | ||
| 97 | mulq $19,$2,$4 # a[1]*w low part r4 | ||
| 98 | umulh $19,$2,$2 # a[1]*w high part r2 | ||
| 99 | |||
| 100 | addq $3,$0,$3 # add c | ||
| 101 | cmpult $3,$0,$5 # overflow? | ||
| 102 | stq $3,0($16) | ||
| 103 | addq $5,$1,$0 # c=high part + overflow | ||
| 104 | |||
| 105 | addq $4,$0,$4 # add c | ||
| 106 | cmpult $4,$0,$5 # overflow? | ||
| 107 | stq $4,8($16) | ||
| 108 | addq $5,$2,$0 # c=high part + overflow | ||
| 109 | |||
| 110 | ble $18,$243 | ||
| 111 | |||
| 112 | addq $16,16,$16 | ||
| 113 | addq $17,16,$17 | ||
| 114 | blt $25,$242 | ||
| 115 | |||
| 116 | br $31,$342 | ||
| 117 | $242: | ||
| 118 | ldq $1,0($17) # a[0] | ||
| 119 | umulh $19,$1,$3 # a[0]*w high part | ||
| 120 | mulq $19,$1,$1 # a[0]*w low part | ||
| 121 | addq $1,$0,$1 # add c | ||
| 122 | cmpult $1,$0,$4 # overflow? | ||
| 123 | addq $4,$3,$0 # c=high part + overflow | ||
| 124 | stq $1,0($16) | ||
| 125 | $243: | ||
| 126 | ret $31,($26),1 | ||
| 127 | .end bn_mul_words | ||
| 128 | .align 3 | ||
| 129 | .globl bn_sqr_words | ||
| 130 | .ent bn_sqr_words | ||
| 131 | bn_sqr_words: | ||
| 132 | bn_sqr_words..ng: | ||
| 133 | .frame $30,0,$26,0 | ||
| 134 | .prologue 0 | ||
| 135 | |||
| 136 | subq $18,2,$25 # num=-2 | ||
| 137 | blt $25,$442 | ||
| 138 | .align 5 | ||
| 139 | $542: | ||
| 140 | subq $18,2,$18 # num-=2 | ||
| 141 | subq $25,2,$25 # num-=2 | ||
| 142 | |||
| 143 | ldq $1,0($17) # a[0] | ||
| 144 | ldq $4,8($17) # a[1] | ||
| 145 | |||
| 146 | mulq $1,$1,$2 # a[0]*w low part r2 | ||
| 147 | umulh $1,$1,$3 # a[0]*w high part r3 | ||
| 148 | mulq $4,$4,$5 # a[1]*w low part r5 | ||
| 149 | umulh $4,$4,$6 # a[1]*w high part r6 | ||
| 150 | |||
| 151 | stq $2,0($16) # r[0] | ||
| 152 | stq $3,8($16) # r[1] | ||
| 153 | stq $5,16($16) # r[3] | ||
| 154 | stq $6,24($16) # r[4] | ||
| 155 | |||
| 156 | ble $18,$443 | ||
| 157 | |||
| 158 | addq $16,32,$16 | ||
| 159 | addq $17,16,$17 | ||
| 160 | blt $25,$442 | ||
| 161 | br $31,$542 | ||
| 162 | |||
| 163 | $442: | ||
| 164 | ldq $1,0($17) # a[0] | ||
| 165 | mulq $1,$1,$2 # a[0]*w low part r2 | ||
| 166 | umulh $1,$1,$3 # a[0]*w high part r3 | ||
| 167 | stq $2,0($16) # r[0] | ||
| 168 | stq $3,8($16) # r[1] | ||
| 169 | |||
| 170 | .align 4 | ||
| 171 | $443: | ||
| 172 | ret $31,($26),1 | ||
| 173 | .end bn_sqr_words | ||
| 174 | |||
| 175 | .align 3 | ||
| 176 | .globl bn_add_words | ||
| 177 | .ent bn_add_words | ||
| 178 | bn_add_words: | ||
| 179 | bn_add_words..ng: | ||
| 180 | .frame $30,0,$26,0 | ||
| 181 | .prologue 0 | ||
| 182 | |||
| 183 | bis $31,$31,$8 # carry = 0 | ||
| 184 | ble $19,$900 | ||
| 185 | $901: | ||
| 186 | ldq $0,0($17) # a[0] | ||
| 187 | ldq $1,0($18) # a[1] | ||
| 188 | |||
| 189 | addq $0,$1,$3 # c=a+b; | ||
| 190 | addq $17,8,$17 # a++ | ||
| 191 | |||
| 192 | cmpult $3,$1,$7 # did we overflow? | ||
| 193 | addq $18,8,$18 # b++ | ||
| 194 | |||
| 195 | addq $8,$3,$3 # c+=carry | ||
| 196 | |||
| 197 | cmpult $3,$8,$8 # did we overflow? | ||
| 198 | stq $3,($16) # r[0]=c | ||
| 199 | |||
| 200 | addq $7,$8,$8 # add into overflow | ||
| 201 | subq $19,1,$19 # loop-- | ||
| 202 | |||
| 203 | addq $16,8,$16 # r++ | ||
| 204 | bgt $19,$901 | ||
| 205 | $900: | ||
| 206 | bis $8,$8,$0 # return carry | ||
| 207 | ret $31,($26),1 | ||
| 208 | .end bn_add_words | ||
| 209 | |||
| 210 | # | ||
| 211 | # What follows was taken directly from the C compiler with a few | ||
| 212 | # hacks to redo the lables. | ||
| 213 | # | ||
| 214 | .text | ||
| 215 | .align 3 | ||
| 216 | .globl bn_div64 | ||
| 217 | .ent bn_div64 | ||
| 218 | bn_div64: | ||
| 219 | ldgp $29,0($27) | ||
| 220 | bn_div64..ng: | ||
| 221 | lda $30,-48($30) | ||
| 222 | .frame $30,48,$26,0 | ||
| 223 | stq $26,0($30) | ||
| 224 | stq $9,8($30) | ||
| 225 | stq $10,16($30) | ||
| 226 | stq $11,24($30) | ||
| 227 | stq $12,32($30) | ||
| 228 | stq $13,40($30) | ||
| 229 | .mask 0x4003e00,-48 | ||
| 230 | .prologue 1 | ||
| 231 | bis $16,$16,$9 | ||
| 232 | bis $17,$17,$10 | ||
| 233 | bis $18,$18,$11 | ||
| 234 | bis $31,$31,$13 | ||
| 235 | bis $31,2,$12 | ||
| 236 | bne $11,$119 | ||
| 237 | lda $0,-1 | ||
| 238 | br $31,$136 | ||
| 239 | .align 4 | ||
| 240 | $119: | ||
| 241 | bis $11,$11,$16 | ||
| 242 | jsr $26,BN_num_bits_word | ||
| 243 | ldgp $29,0($26) | ||
| 244 | subq $0,64,$1 | ||
| 245 | beq $1,$120 | ||
| 246 | bis $31,1,$1 | ||
| 247 | sll $1,$0,$1 | ||
| 248 | cmpule $9,$1,$1 | ||
| 249 | bne $1,$120 | ||
| 250 | # lda $16,_IO_stderr_ | ||
| 251 | # lda $17,$C32 | ||
| 252 | # bis $0,$0,$18 | ||
| 253 | # jsr $26,fprintf | ||
| 254 | # ldgp $29,0($26) | ||
| 255 | jsr $26,abort | ||
| 256 | ldgp $29,0($26) | ||
| 257 | .align 4 | ||
| 258 | $120: | ||
| 259 | bis $31,64,$3 | ||
| 260 | cmpult $9,$11,$2 | ||
| 261 | subq $3,$0,$1 | ||
| 262 | addl $1,$31,$0 | ||
| 263 | subq $9,$11,$1 | ||
| 264 | cmoveq $2,$1,$9 | ||
| 265 | beq $0,$122 | ||
| 266 | zapnot $0,15,$2 | ||
| 267 | subq $3,$0,$1 | ||
| 268 | sll $11,$2,$11 | ||
| 269 | sll $9,$2,$3 | ||
| 270 | srl $10,$1,$1 | ||
| 271 | sll $10,$2,$10 | ||
| 272 | bis $3,$1,$9 | ||
| 273 | $122: | ||
| 274 | srl $11,32,$5 | ||
| 275 | zapnot $11,15,$6 | ||
| 276 | lda $7,-1 | ||
| 277 | .align 5 | ||
| 278 | $123: | ||
| 279 | srl $9,32,$1 | ||
| 280 | subq $1,$5,$1 | ||
| 281 | bne $1,$126 | ||
| 282 | zapnot $7,15,$27 | ||
| 283 | br $31,$127 | ||
| 284 | .align 4 | ||
| 285 | $126: | ||
| 286 | bis $9,$9,$24 | ||
| 287 | bis $5,$5,$25 | ||
| 288 | divqu $24,$25,$27 | ||
| 289 | $127: | ||
| 290 | srl $10,32,$4 | ||
| 291 | .align 5 | ||
| 292 | $128: | ||
| 293 | mulq $27,$5,$1 | ||
| 294 | subq $9,$1,$3 | ||
| 295 | zapnot $3,240,$1 | ||
| 296 | bne $1,$129 | ||
| 297 | mulq $6,$27,$2 | ||
| 298 | sll $3,32,$1 | ||
| 299 | addq $1,$4,$1 | ||
| 300 | cmpule $2,$1,$2 | ||
| 301 | bne $2,$129 | ||
| 302 | subq $27,1,$27 | ||
| 303 | br $31,$128 | ||
| 304 | .align 4 | ||
| 305 | $129: | ||
| 306 | mulq $27,$6,$1 | ||
| 307 | mulq $27,$5,$4 | ||
| 308 | srl $1,32,$3 | ||
| 309 | sll $1,32,$1 | ||
| 310 | addq $4,$3,$4 | ||
| 311 | cmpult $10,$1,$2 | ||
| 312 | subq $10,$1,$10 | ||
| 313 | addq $2,$4,$2 | ||
| 314 | cmpult $9,$2,$1 | ||
| 315 | bis $2,$2,$4 | ||
| 316 | beq $1,$134 | ||
| 317 | addq $9,$11,$9 | ||
| 318 | subq $27,1,$27 | ||
| 319 | $134: | ||
| 320 | subl $12,1,$12 | ||
| 321 | subq $9,$4,$9 | ||
| 322 | beq $12,$124 | ||
| 323 | sll $27,32,$13 | ||
| 324 | sll $9,32,$2 | ||
| 325 | srl $10,32,$1 | ||
| 326 | sll $10,32,$10 | ||
| 327 | bis $2,$1,$9 | ||
| 328 | br $31,$123 | ||
| 329 | .align 4 | ||
| 330 | $124: | ||
| 331 | bis $13,$27,$0 | ||
| 332 | $136: | ||
| 333 | ldq $26,0($30) | ||
| 334 | ldq $9,8($30) | ||
| 335 | ldq $10,16($30) | ||
| 336 | ldq $11,24($30) | ||
| 337 | ldq $12,32($30) | ||
| 338 | ldq $13,40($30) | ||
| 339 | addq $30,48,$30 | ||
| 340 | ret $31,($26),1 | ||
| 341 | .end bn_div64 | ||
| 342 | .ident "GCC: (GNU) 2.7.2.1" | ||
| 343 | |||
| 344 | |||
diff --git a/src/lib/libcrypto/bn/asm/pa-risc.s b/src/lib/libcrypto/bn/asm/pa-risc.s new file mode 100644 index 0000000000..775130a191 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/pa-risc.s | |||
| @@ -0,0 +1,710 @@ | |||
| 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=0,CALLS,SAVE_RP | ||
| 18 | .ENTRY | ||
| 19 | stw %r2,-20(0,%r30) | ||
| 20 | ldi 0,%r28 | ||
| 21 | extru %r23,31,16,%r2 | ||
| 22 | stw %r2,-16(0,%r30) | ||
| 23 | extru %r23,15,16,%r23 | ||
| 24 | ldil L'65536,%r31 | ||
| 25 | fldws -16(0,%r30),%fr11R | ||
| 26 | stw %r23,-16(0,%r30) | ||
| 27 | ldo 12(%r25),%r29 | ||
| 28 | ldo 12(%r26),%r23 | ||
| 29 | fldws -16(0,%r30),%fr11L | ||
| 30 | L$0002 | ||
| 31 | ldw 0(0,%r25),%r19 | ||
| 32 | extru %r19,31,16,%r20 | ||
| 33 | stw %r20,-16(0,%r30) | ||
| 34 | extru %r19,15,16,%r19 | ||
| 35 | fldws -16(0,%r30),%fr22L | ||
| 36 | stw %r19,-16(0,%r30) | ||
| 37 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 38 | fldws -16(0,%r30),%fr22L | ||
| 39 | fstws %fr8R,-16(0,%r30) | ||
| 40 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 41 | ldw -16(0,%r30),%r2 | ||
| 42 | stw %r20,-16(0,%r30) | ||
| 43 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 44 | fldws -16(0,%r30),%fr22L | ||
| 45 | fstws %fr10R,-16(0,%r30) | ||
| 46 | copy %r2,%r22 | ||
| 47 | ldw -16(0,%r30),%r2 | ||
| 48 | fstws %fr9R,-16(0,%r30) | ||
| 49 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 50 | copy %r2,%r19 | ||
| 51 | ldw -16(0,%r30),%r2 | ||
| 52 | fstws %fr8R,-16(0,%r30) | ||
| 53 | copy %r2,%r20 | ||
| 54 | ldw -16(0,%r30),%r2 | ||
| 55 | addl %r2,%r19,%r21 | ||
| 56 | comclr,<<= %r19,%r21,0 | ||
| 57 | addl %r20,%r31,%r20 | ||
| 58 | L$0005 | ||
| 59 | extru %r21,15,16,%r19 | ||
| 60 | addl %r20,%r19,%r20 | ||
| 61 | zdep %r21,15,16,%r19 | ||
| 62 | addl %r22,%r19,%r22 | ||
| 63 | comclr,<<= %r19,%r22,0 | ||
| 64 | addi,tr 1,%r20,%r19 | ||
| 65 | copy %r20,%r19 | ||
| 66 | addl %r22,%r28,%r20 | ||
| 67 | comclr,<<= %r28,%r20,0 | ||
| 68 | addi 1,%r19,%r19 | ||
| 69 | ldw 0(0,%r26),%r28 | ||
| 70 | addl %r20,%r28,%r20 | ||
| 71 | comclr,<<= %r28,%r20,0 | ||
| 72 | addi,tr 1,%r19,%r28 | ||
| 73 | copy %r19,%r28 | ||
| 74 | addib,= -1,%r24,L$0003 | ||
| 75 | stw %r20,0(0,%r26) | ||
| 76 | ldw -8(0,%r29),%r19 | ||
| 77 | extru %r19,31,16,%r20 | ||
| 78 | stw %r20,-16(0,%r30) | ||
| 79 | extru %r19,15,16,%r19 | ||
| 80 | fldws -16(0,%r30),%fr22L | ||
| 81 | stw %r19,-16(0,%r30) | ||
| 82 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 83 | fldws -16(0,%r30),%fr22L | ||
| 84 | fstws %fr8R,-16(0,%r30) | ||
| 85 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 86 | ldw -16(0,%r30),%r2 | ||
| 87 | stw %r20,-16(0,%r30) | ||
| 88 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 89 | fldws -16(0,%r30),%fr22L | ||
| 90 | fstws %fr10R,-16(0,%r30) | ||
| 91 | copy %r2,%r22 | ||
| 92 | ldw -16(0,%r30),%r2 | ||
| 93 | fstws %fr9R,-16(0,%r30) | ||
| 94 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 95 | copy %r2,%r19 | ||
| 96 | ldw -16(0,%r30),%r2 | ||
| 97 | fstws %fr8R,-16(0,%r30) | ||
| 98 | copy %r2,%r20 | ||
| 99 | ldw -16(0,%r30),%r2 | ||
| 100 | addl %r2,%r19,%r21 | ||
| 101 | comclr,<<= %r19,%r21,0 | ||
| 102 | addl %r20,%r31,%r20 | ||
| 103 | L$0010 | ||
| 104 | extru %r21,15,16,%r19 | ||
| 105 | addl %r20,%r19,%r20 | ||
| 106 | zdep %r21,15,16,%r19 | ||
| 107 | addl %r22,%r19,%r22 | ||
| 108 | comclr,<<= %r19,%r22,0 | ||
| 109 | addi,tr 1,%r20,%r19 | ||
| 110 | copy %r20,%r19 | ||
| 111 | addl %r22,%r28,%r20 | ||
| 112 | comclr,<<= %r28,%r20,0 | ||
| 113 | addi 1,%r19,%r19 | ||
| 114 | ldw -8(0,%r23),%r28 | ||
| 115 | addl %r20,%r28,%r20 | ||
| 116 | comclr,<<= %r28,%r20,0 | ||
| 117 | addi,tr 1,%r19,%r28 | ||
| 118 | copy %r19,%r28 | ||
| 119 | addib,= -1,%r24,L$0003 | ||
| 120 | stw %r20,-8(0,%r23) | ||
| 121 | ldw -4(0,%r29),%r19 | ||
| 122 | extru %r19,31,16,%r20 | ||
| 123 | stw %r20,-16(0,%r30) | ||
| 124 | extru %r19,15,16,%r19 | ||
| 125 | fldws -16(0,%r30),%fr22L | ||
| 126 | stw %r19,-16(0,%r30) | ||
| 127 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 128 | fldws -16(0,%r30),%fr22L | ||
| 129 | fstws %fr8R,-16(0,%r30) | ||
| 130 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 131 | ldw -16(0,%r30),%r2 | ||
| 132 | stw %r20,-16(0,%r30) | ||
| 133 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 134 | fldws -16(0,%r30),%fr22L | ||
| 135 | fstws %fr10R,-16(0,%r30) | ||
| 136 | copy %r2,%r22 | ||
| 137 | ldw -16(0,%r30),%r2 | ||
| 138 | fstws %fr9R,-16(0,%r30) | ||
| 139 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 140 | copy %r2,%r19 | ||
| 141 | ldw -16(0,%r30),%r2 | ||
| 142 | fstws %fr8R,-16(0,%r30) | ||
| 143 | copy %r2,%r20 | ||
| 144 | ldw -16(0,%r30),%r2 | ||
| 145 | addl %r2,%r19,%r21 | ||
| 146 | comclr,<<= %r19,%r21,0 | ||
| 147 | addl %r20,%r31,%r20 | ||
| 148 | L$0015 | ||
| 149 | extru %r21,15,16,%r19 | ||
| 150 | addl %r20,%r19,%r20 | ||
| 151 | zdep %r21,15,16,%r19 | ||
| 152 | addl %r22,%r19,%r22 | ||
| 153 | comclr,<<= %r19,%r22,0 | ||
| 154 | addi,tr 1,%r20,%r19 | ||
| 155 | copy %r20,%r19 | ||
| 156 | addl %r22,%r28,%r20 | ||
| 157 | comclr,<<= %r28,%r20,0 | ||
| 158 | addi 1,%r19,%r19 | ||
| 159 | ldw -4(0,%r23),%r28 | ||
| 160 | addl %r20,%r28,%r20 | ||
| 161 | comclr,<<= %r28,%r20,0 | ||
| 162 | addi,tr 1,%r19,%r28 | ||
| 163 | copy %r19,%r28 | ||
| 164 | addib,= -1,%r24,L$0003 | ||
| 165 | stw %r20,-4(0,%r23) | ||
| 166 | ldw 0(0,%r29),%r19 | ||
| 167 | extru %r19,31,16,%r20 | ||
| 168 | stw %r20,-16(0,%r30) | ||
| 169 | extru %r19,15,16,%r19 | ||
| 170 | fldws -16(0,%r30),%fr22L | ||
| 171 | stw %r19,-16(0,%r30) | ||
| 172 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 173 | fldws -16(0,%r30),%fr22L | ||
| 174 | fstws %fr8R,-16(0,%r30) | ||
| 175 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 176 | ldw -16(0,%r30),%r2 | ||
| 177 | stw %r20,-16(0,%r30) | ||
| 178 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 179 | fldws -16(0,%r30),%fr22L | ||
| 180 | fstws %fr10R,-16(0,%r30) | ||
| 181 | copy %r2,%r22 | ||
| 182 | ldw -16(0,%r30),%r2 | ||
| 183 | fstws %fr9R,-16(0,%r30) | ||
| 184 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 185 | copy %r2,%r19 | ||
| 186 | ldw -16(0,%r30),%r2 | ||
| 187 | fstws %fr8R,-16(0,%r30) | ||
| 188 | copy %r2,%r20 | ||
| 189 | ldw -16(0,%r30),%r2 | ||
| 190 | addl %r2,%r19,%r21 | ||
| 191 | comclr,<<= %r19,%r21,0 | ||
| 192 | addl %r20,%r31,%r20 | ||
| 193 | L$0020 | ||
| 194 | extru %r21,15,16,%r19 | ||
| 195 | addl %r20,%r19,%r20 | ||
| 196 | zdep %r21,15,16,%r19 | ||
| 197 | addl %r22,%r19,%r22 | ||
| 198 | comclr,<<= %r19,%r22,0 | ||
| 199 | addi,tr 1,%r20,%r19 | ||
| 200 | copy %r20,%r19 | ||
| 201 | addl %r22,%r28,%r20 | ||
| 202 | comclr,<<= %r28,%r20,0 | ||
| 203 | addi 1,%r19,%r19 | ||
| 204 | ldw 0(0,%r23),%r28 | ||
| 205 | addl %r20,%r28,%r20 | ||
| 206 | comclr,<<= %r28,%r20,0 | ||
| 207 | addi,tr 1,%r19,%r28 | ||
| 208 | copy %r19,%r28 | ||
| 209 | addib,= -1,%r24,L$0003 | ||
| 210 | stw %r20,0(0,%r23) | ||
| 211 | ldo 16(%r29),%r29 | ||
| 212 | ldo 16(%r25),%r25 | ||
| 213 | ldo 16(%r23),%r23 | ||
| 214 | bl L$0002,0 | ||
| 215 | ldo 16(%r26),%r26 | ||
| 216 | L$0003 | ||
| 217 | ldw -20(0,%r30),%r2 | ||
| 218 | bv,n 0(%r2) | ||
| 219 | .EXIT | ||
| 220 | .PROCEND | ||
| 221 | .align 4 | ||
| 222 | .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR | ||
| 223 | bn_mul_words | ||
| 224 | .PROC | ||
| 225 | .CALLINFO FRAME=0,CALLS,SAVE_RP | ||
| 226 | .ENTRY | ||
| 227 | stw %r2,-20(0,%r30) | ||
| 228 | ldi 0,%r28 | ||
| 229 | extru %r23,31,16,%r2 | ||
| 230 | stw %r2,-16(0,%r30) | ||
| 231 | extru %r23,15,16,%r23 | ||
| 232 | ldil L'65536,%r31 | ||
| 233 | fldws -16(0,%r30),%fr11R | ||
| 234 | stw %r23,-16(0,%r30) | ||
| 235 | ldo 12(%r26),%r29 | ||
| 236 | ldo 12(%r25),%r23 | ||
| 237 | fldws -16(0,%r30),%fr11L | ||
| 238 | L$0026 | ||
| 239 | ldw 0(0,%r25),%r19 | ||
| 240 | extru %r19,31,16,%r20 | ||
| 241 | stw %r20,-16(0,%r30) | ||
| 242 | extru %r19,15,16,%r19 | ||
| 243 | fldws -16(0,%r30),%fr22L | ||
| 244 | stw %r19,-16(0,%r30) | ||
| 245 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 246 | fldws -16(0,%r30),%fr22L | ||
| 247 | fstws %fr8R,-16(0,%r30) | ||
| 248 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 249 | ldw -16(0,%r30),%r2 | ||
| 250 | stw %r20,-16(0,%r30) | ||
| 251 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 252 | fldws -16(0,%r30),%fr22L | ||
| 253 | fstws %fr10R,-16(0,%r30) | ||
| 254 | copy %r2,%r22 | ||
| 255 | ldw -16(0,%r30),%r2 | ||
| 256 | fstws %fr9R,-16(0,%r30) | ||
| 257 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 258 | copy %r2,%r19 | ||
| 259 | ldw -16(0,%r30),%r2 | ||
| 260 | fstws %fr8R,-16(0,%r30) | ||
| 261 | copy %r2,%r20 | ||
| 262 | ldw -16(0,%r30),%r2 | ||
| 263 | addl %r2,%r19,%r21 | ||
| 264 | comclr,<<= %r19,%r21,0 | ||
| 265 | addl %r20,%r31,%r20 | ||
| 266 | L$0029 | ||
| 267 | extru %r21,15,16,%r19 | ||
| 268 | addl %r20,%r19,%r20 | ||
| 269 | zdep %r21,15,16,%r19 | ||
| 270 | addl %r22,%r19,%r22 | ||
| 271 | comclr,<<= %r19,%r22,0 | ||
| 272 | addi,tr 1,%r20,%r19 | ||
| 273 | copy %r20,%r19 | ||
| 274 | addl %r22,%r28,%r20 | ||
| 275 | comclr,<<= %r28,%r20,0 | ||
| 276 | addi,tr 1,%r19,%r28 | ||
| 277 | copy %r19,%r28 | ||
| 278 | addib,= -1,%r24,L$0027 | ||
| 279 | stw %r20,0(0,%r26) | ||
| 280 | ldw -8(0,%r23),%r19 | ||
| 281 | extru %r19,31,16,%r20 | ||
| 282 | stw %r20,-16(0,%r30) | ||
| 283 | extru %r19,15,16,%r19 | ||
| 284 | fldws -16(0,%r30),%fr22L | ||
| 285 | stw %r19,-16(0,%r30) | ||
| 286 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 287 | fldws -16(0,%r30),%fr22L | ||
| 288 | fstws %fr8R,-16(0,%r30) | ||
| 289 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 290 | ldw -16(0,%r30),%r2 | ||
| 291 | stw %r20,-16(0,%r30) | ||
| 292 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 293 | fldws -16(0,%r30),%fr22L | ||
| 294 | fstws %fr10R,-16(0,%r30) | ||
| 295 | copy %r2,%r22 | ||
| 296 | ldw -16(0,%r30),%r2 | ||
| 297 | fstws %fr9R,-16(0,%r30) | ||
| 298 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 299 | copy %r2,%r19 | ||
| 300 | ldw -16(0,%r30),%r2 | ||
| 301 | fstws %fr8R,-16(0,%r30) | ||
| 302 | copy %r2,%r20 | ||
| 303 | ldw -16(0,%r30),%r2 | ||
| 304 | addl %r2,%r19,%r21 | ||
| 305 | comclr,<<= %r19,%r21,0 | ||
| 306 | addl %r20,%r31,%r20 | ||
| 307 | L$0033 | ||
| 308 | extru %r21,15,16,%r19 | ||
| 309 | addl %r20,%r19,%r20 | ||
| 310 | zdep %r21,15,16,%r19 | ||
| 311 | addl %r22,%r19,%r22 | ||
| 312 | comclr,<<= %r19,%r22,0 | ||
| 313 | addi,tr 1,%r20,%r19 | ||
| 314 | copy %r20,%r19 | ||
| 315 | addl %r22,%r28,%r20 | ||
| 316 | comclr,<<= %r28,%r20,0 | ||
| 317 | addi,tr 1,%r19,%r28 | ||
| 318 | copy %r19,%r28 | ||
| 319 | addib,= -1,%r24,L$0027 | ||
| 320 | stw %r20,-8(0,%r29) | ||
| 321 | ldw -4(0,%r23),%r19 | ||
| 322 | extru %r19,31,16,%r20 | ||
| 323 | stw %r20,-16(0,%r30) | ||
| 324 | extru %r19,15,16,%r19 | ||
| 325 | fldws -16(0,%r30),%fr22L | ||
| 326 | stw %r19,-16(0,%r30) | ||
| 327 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 328 | fldws -16(0,%r30),%fr22L | ||
| 329 | fstws %fr8R,-16(0,%r30) | ||
| 330 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 331 | ldw -16(0,%r30),%r2 | ||
| 332 | stw %r20,-16(0,%r30) | ||
| 333 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 334 | fldws -16(0,%r30),%fr22L | ||
| 335 | fstws %fr10R,-16(0,%r30) | ||
| 336 | copy %r2,%r22 | ||
| 337 | ldw -16(0,%r30),%r2 | ||
| 338 | fstws %fr9R,-16(0,%r30) | ||
| 339 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 340 | copy %r2,%r19 | ||
| 341 | ldw -16(0,%r30),%r2 | ||
| 342 | fstws %fr8R,-16(0,%r30) | ||
| 343 | copy %r2,%r20 | ||
| 344 | ldw -16(0,%r30),%r2 | ||
| 345 | addl %r2,%r19,%r21 | ||
| 346 | comclr,<<= %r19,%r21,0 | ||
| 347 | addl %r20,%r31,%r20 | ||
| 348 | L$0037 | ||
| 349 | extru %r21,15,16,%r19 | ||
| 350 | addl %r20,%r19,%r20 | ||
| 351 | zdep %r21,15,16,%r19 | ||
| 352 | addl %r22,%r19,%r22 | ||
| 353 | comclr,<<= %r19,%r22,0 | ||
| 354 | addi,tr 1,%r20,%r19 | ||
| 355 | copy %r20,%r19 | ||
| 356 | addl %r22,%r28,%r20 | ||
| 357 | comclr,<<= %r28,%r20,0 | ||
| 358 | addi,tr 1,%r19,%r28 | ||
| 359 | copy %r19,%r28 | ||
| 360 | addib,= -1,%r24,L$0027 | ||
| 361 | stw %r20,-4(0,%r29) | ||
| 362 | ldw 0(0,%r23),%r19 | ||
| 363 | extru %r19,31,16,%r20 | ||
| 364 | stw %r20,-16(0,%r30) | ||
| 365 | extru %r19,15,16,%r19 | ||
| 366 | fldws -16(0,%r30),%fr22L | ||
| 367 | stw %r19,-16(0,%r30) | ||
| 368 | xmpyu %fr22L,%fr11R,%fr8 | ||
| 369 | fldws -16(0,%r30),%fr22L | ||
| 370 | fstws %fr8R,-16(0,%r30) | ||
| 371 | xmpyu %fr11R,%fr22L,%fr10 | ||
| 372 | ldw -16(0,%r30),%r2 | ||
| 373 | stw %r20,-16(0,%r30) | ||
| 374 | xmpyu %fr22L,%fr11L,%fr9 | ||
| 375 | fldws -16(0,%r30),%fr22L | ||
| 376 | fstws %fr10R,-16(0,%r30) | ||
| 377 | copy %r2,%r22 | ||
| 378 | ldw -16(0,%r30),%r2 | ||
| 379 | fstws %fr9R,-16(0,%r30) | ||
| 380 | xmpyu %fr11L,%fr22L,%fr8 | ||
| 381 | copy %r2,%r19 | ||
| 382 | ldw -16(0,%r30),%r2 | ||
| 383 | fstws %fr8R,-16(0,%r30) | ||
| 384 | copy %r2,%r20 | ||
| 385 | ldw -16(0,%r30),%r2 | ||
| 386 | addl %r2,%r19,%r21 | ||
| 387 | comclr,<<= %r19,%r21,0 | ||
| 388 | addl %r20,%r31,%r20 | ||
| 389 | L$0041 | ||
| 390 | extru %r21,15,16,%r19 | ||
| 391 | addl %r20,%r19,%r20 | ||
| 392 | zdep %r21,15,16,%r19 | ||
| 393 | addl %r22,%r19,%r22 | ||
| 394 | comclr,<<= %r19,%r22,0 | ||
| 395 | addi,tr 1,%r20,%r19 | ||
| 396 | copy %r20,%r19 | ||
| 397 | addl %r22,%r28,%r20 | ||
| 398 | comclr,<<= %r28,%r20,0 | ||
| 399 | addi,tr 1,%r19,%r28 | ||
| 400 | copy %r19,%r28 | ||
| 401 | addib,= -1,%r24,L$0027 | ||
| 402 | stw %r20,0(0,%r29) | ||
| 403 | ldo 16(%r23),%r23 | ||
| 404 | ldo 16(%r25),%r25 | ||
| 405 | ldo 16(%r29),%r29 | ||
| 406 | bl L$0026,0 | ||
| 407 | ldo 16(%r26),%r26 | ||
| 408 | L$0027 | ||
| 409 | ldw -20(0,%r30),%r2 | ||
| 410 | bv,n 0(%r2) | ||
| 411 | .EXIT | ||
| 412 | .PROCEND | ||
| 413 | .align 4 | ||
| 414 | .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR | ||
| 415 | bn_sqr_words | ||
| 416 | .PROC | ||
| 417 | .CALLINFO FRAME=0,NO_CALLS | ||
| 418 | .ENTRY | ||
| 419 | ldo 28(%r26),%r23 | ||
| 420 | ldo 12(%r25),%r28 | ||
| 421 | L$0046 | ||
| 422 | ldw 0(0,%r25),%r21 | ||
| 423 | extru %r21,31,16,%r22 | ||
| 424 | stw %r22,-16(0,%r30) | ||
| 425 | extru %r21,15,16,%r21 | ||
| 426 | fldws -16(0,%r30),%fr10L | ||
| 427 | stw %r21,-16(0,%r30) | ||
| 428 | fldws -16(0,%r30),%fr10R | ||
| 429 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 430 | fstws %fr8R,-16(0,%r30) | ||
| 431 | ldw -16(0,%r30),%r29 | ||
| 432 | stw %r22,-16(0,%r30) | ||
| 433 | fldws -16(0,%r30),%fr10R | ||
| 434 | stw %r21,-16(0,%r30) | ||
| 435 | copy %r29,%r19 | ||
| 436 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 437 | fldws -16(0,%r30),%fr10L | ||
| 438 | stw %r21,-16(0,%r30) | ||
| 439 | fldws -16(0,%r30),%fr10R | ||
| 440 | fstws %fr8R,-16(0,%r30) | ||
| 441 | extru %r19,16,17,%r20 | ||
| 442 | zdep %r19,14,15,%r19 | ||
| 443 | ldw -16(0,%r30),%r29 | ||
| 444 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 445 | addl %r29,%r19,%r22 | ||
| 446 | stw %r22,0(0,%r26) | ||
| 447 | fstws %fr9R,-16(0,%r30) | ||
| 448 | ldw -16(0,%r30),%r29 | ||
| 449 | addl %r29,%r20,%r21 | ||
| 450 | comclr,<<= %r19,%r22,0 | ||
| 451 | addi 1,%r21,%r21 | ||
| 452 | addib,= -1,%r24,L$0057 | ||
| 453 | stw %r21,-24(0,%r23) | ||
| 454 | ldw -8(0,%r28),%r21 | ||
| 455 | extru %r21,31,16,%r22 | ||
| 456 | stw %r22,-16(0,%r30) | ||
| 457 | extru %r21,15,16,%r21 | ||
| 458 | fldws -16(0,%r30),%fr10L | ||
| 459 | stw %r21,-16(0,%r30) | ||
| 460 | fldws -16(0,%r30),%fr10R | ||
| 461 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 462 | fstws %fr8R,-16(0,%r30) | ||
| 463 | ldw -16(0,%r30),%r29 | ||
| 464 | stw %r22,-16(0,%r30) | ||
| 465 | fldws -16(0,%r30),%fr10R | ||
| 466 | stw %r21,-16(0,%r30) | ||
| 467 | copy %r29,%r19 | ||
| 468 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 469 | fldws -16(0,%r30),%fr10L | ||
| 470 | stw %r21,-16(0,%r30) | ||
| 471 | fldws -16(0,%r30),%fr10R | ||
| 472 | fstws %fr8R,-16(0,%r30) | ||
| 473 | extru %r19,16,17,%r20 | ||
| 474 | zdep %r19,14,15,%r19 | ||
| 475 | ldw -16(0,%r30),%r29 | ||
| 476 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 477 | addl %r29,%r19,%r22 | ||
| 478 | stw %r22,-20(0,%r23) | ||
| 479 | fstws %fr9R,-16(0,%r30) | ||
| 480 | ldw -16(0,%r30),%r29 | ||
| 481 | addl %r29,%r20,%r21 | ||
| 482 | comclr,<<= %r19,%r22,0 | ||
| 483 | addi 1,%r21,%r21 | ||
| 484 | addib,= -1,%r24,L$0057 | ||
| 485 | stw %r21,-16(0,%r23) | ||
| 486 | ldw -4(0,%r28),%r21 | ||
| 487 | extru %r21,31,16,%r22 | ||
| 488 | stw %r22,-16(0,%r30) | ||
| 489 | extru %r21,15,16,%r21 | ||
| 490 | fldws -16(0,%r30),%fr10L | ||
| 491 | stw %r21,-16(0,%r30) | ||
| 492 | fldws -16(0,%r30),%fr10R | ||
| 493 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 494 | fstws %fr8R,-16(0,%r30) | ||
| 495 | ldw -16(0,%r30),%r29 | ||
| 496 | stw %r22,-16(0,%r30) | ||
| 497 | fldws -16(0,%r30),%fr10R | ||
| 498 | stw %r21,-16(0,%r30) | ||
| 499 | copy %r29,%r19 | ||
| 500 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 501 | fldws -16(0,%r30),%fr10L | ||
| 502 | stw %r21,-16(0,%r30) | ||
| 503 | fldws -16(0,%r30),%fr10R | ||
| 504 | fstws %fr8R,-16(0,%r30) | ||
| 505 | extru %r19,16,17,%r20 | ||
| 506 | zdep %r19,14,15,%r19 | ||
| 507 | ldw -16(0,%r30),%r29 | ||
| 508 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 509 | addl %r29,%r19,%r22 | ||
| 510 | stw %r22,-12(0,%r23) | ||
| 511 | fstws %fr9R,-16(0,%r30) | ||
| 512 | ldw -16(0,%r30),%r29 | ||
| 513 | addl %r29,%r20,%r21 | ||
| 514 | comclr,<<= %r19,%r22,0 | ||
| 515 | addi 1,%r21,%r21 | ||
| 516 | addib,= -1,%r24,L$0057 | ||
| 517 | stw %r21,-8(0,%r23) | ||
| 518 | ldw 0(0,%r28),%r21 | ||
| 519 | extru %r21,31,16,%r22 | ||
| 520 | stw %r22,-16(0,%r30) | ||
| 521 | extru %r21,15,16,%r21 | ||
| 522 | fldws -16(0,%r30),%fr10L | ||
| 523 | stw %r21,-16(0,%r30) | ||
| 524 | fldws -16(0,%r30),%fr10R | ||
| 525 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 526 | fstws %fr8R,-16(0,%r30) | ||
| 527 | ldw -16(0,%r30),%r29 | ||
| 528 | stw %r22,-16(0,%r30) | ||
| 529 | fldws -16(0,%r30),%fr10R | ||
| 530 | stw %r21,-16(0,%r30) | ||
| 531 | copy %r29,%r19 | ||
| 532 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 533 | fldws -16(0,%r30),%fr10L | ||
| 534 | stw %r21,-16(0,%r30) | ||
| 535 | fldws -16(0,%r30),%fr10R | ||
| 536 | fstws %fr8R,-16(0,%r30) | ||
| 537 | extru %r19,16,17,%r20 | ||
| 538 | zdep %r19,14,15,%r19 | ||
| 539 | ldw -16(0,%r30),%r29 | ||
| 540 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 541 | addl %r29,%r19,%r22 | ||
| 542 | stw %r22,-4(0,%r23) | ||
| 543 | fstws %fr9R,-16(0,%r30) | ||
| 544 | ldw -16(0,%r30),%r29 | ||
| 545 | addl %r29,%r20,%r21 | ||
| 546 | comclr,<<= %r19,%r22,0 | ||
| 547 | addi 1,%r21,%r21 | ||
| 548 | addib,= -1,%r24,L$0057 | ||
| 549 | stw %r21,0(0,%r23) | ||
| 550 | ldo 16(%r28),%r28 | ||
| 551 | ldo 16(%r25),%r25 | ||
| 552 | ldo 32(%r23),%r23 | ||
| 553 | bl L$0046,0 | ||
| 554 | ldo 32(%r26),%r26 | ||
| 555 | L$0057 | ||
| 556 | bv,n 0(%r2) | ||
| 557 | .EXIT | ||
| 558 | .PROCEND | ||
| 559 | .IMPORT BN_num_bits_word,CODE | ||
| 560 | .IMPORT fprintf,CODE | ||
| 561 | .IMPORT __iob,DATA | ||
| 562 | .SPACE $TEXT$ | ||
| 563 | .SUBSPA $LIT$ | ||
| 564 | |||
| 565 | .align 4 | ||
| 566 | L$C0000 | ||
| 567 | .STRING "Division would overflow\x0a\x00" | ||
| 568 | .IMPORT abort,CODE | ||
| 569 | .SPACE $TEXT$ | ||
| 570 | .SUBSPA $CODE$ | ||
| 571 | |||
| 572 | .align 4 | ||
| 573 | .EXPORT bn_div64,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR | ||
| 574 | bn_div64 | ||
| 575 | .PROC | ||
| 576 | .CALLINFO FRAME=128,CALLS,SAVE_RP,ENTRY_GR=8 | ||
| 577 | .ENTRY | ||
| 578 | stw %r2,-20(0,%r30) | ||
| 579 | stwm %r8,128(0,%r30) | ||
| 580 | stw %r7,-124(0,%r30) | ||
| 581 | stw %r4,-112(0,%r30) | ||
| 582 | stw %r3,-108(0,%r30) | ||
| 583 | copy %r26,%r3 | ||
| 584 | copy %r25,%r4 | ||
| 585 | stw %r6,-120(0,%r30) | ||
| 586 | ldi 0,%r7 | ||
| 587 | stw %r5,-116(0,%r30) | ||
| 588 | movb,<> %r24,%r5,L$0059 | ||
| 589 | ldi 2,%r6 | ||
| 590 | bl L$0076,0 | ||
| 591 | ldi -1,%r28 | ||
| 592 | L$0059 | ||
| 593 | .CALL ARGW0=GR | ||
| 594 | bl BN_num_bits_word,%r2 | ||
| 595 | copy %r5,%r26 | ||
| 596 | ldi 32,%r19 | ||
| 597 | comb,= %r19,%r28,L$0060 | ||
| 598 | subi 31,%r28,%r19 | ||
| 599 | mtsar %r19 | ||
| 600 | zvdepi 1,32,%r19 | ||
| 601 | comb,>>= %r19,%r3,L$0060 | ||
| 602 | addil LR'__iob-$global$+32,%r27 | ||
| 603 | ldo RR'__iob-$global$+32(%r1),%r26 | ||
| 604 | ldil LR'L$C0000,%r25 | ||
| 605 | .CALL ARGW0=GR,ARGW1=GR | ||
| 606 | bl fprintf,%r2 | ||
| 607 | ldo RR'L$C0000(%r25),%r25 | ||
| 608 | .CALL | ||
| 609 | bl abort,%r2 | ||
| 610 | nop | ||
| 611 | L$0060 | ||
| 612 | comb,>> %r5,%r3,L$0061 | ||
| 613 | subi 32,%r28,%r28 | ||
| 614 | sub %r3,%r5,%r3 | ||
| 615 | L$0061 | ||
| 616 | comib,= 0,%r28,L$0062 | ||
| 617 | subi 31,%r28,%r19 | ||
| 618 | mtsar %r19 | ||
| 619 | zvdep %r5,32,%r5 | ||
| 620 | zvdep %r3,32,%r21 | ||
| 621 | subi 32,%r28,%r20 | ||
| 622 | mtsar %r20 | ||
| 623 | vshd 0,%r4,%r20 | ||
| 624 | or %r21,%r20,%r3 | ||
| 625 | mtsar %r19 | ||
| 626 | zvdep %r4,32,%r4 | ||
| 627 | L$0062 | ||
| 628 | extru %r5,15,16,%r23 | ||
| 629 | extru %r5,31,16,%r28 | ||
| 630 | L$0063 | ||
| 631 | extru %r3,15,16,%r19 | ||
| 632 | comb,<> %r23,%r19,L$0066 | ||
| 633 | copy %r3,%r26 | ||
| 634 | bl L$0067,0 | ||
| 635 | zdepi -1,31,16,%r29 | ||
| 636 | L$0066 | ||
| 637 | .IMPORT $$divU,MILLICODE | ||
| 638 | bl $$divU,%r31 | ||
| 639 | copy %r23,%r25 | ||
| 640 | L$0067 | ||
| 641 | stw %r29,-16(0,%r30) | ||
| 642 | fldws -16(0,%r30),%fr10L | ||
| 643 | stw %r28,-16(0,%r30) | ||
| 644 | fldws -16(0,%r30),%fr10R | ||
| 645 | stw %r23,-16(0,%r30) | ||
| 646 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 647 | fldws -16(0,%r30),%fr10R | ||
| 648 | fstws %fr8R,-16(0,%r30) | ||
| 649 | xmpyu %fr10L,%fr10R,%fr9 | ||
| 650 | ldw -16(0,%r30),%r8 | ||
| 651 | fstws %fr9R,-16(0,%r30) | ||
| 652 | copy %r8,%r22 | ||
| 653 | ldw -16(0,%r30),%r8 | ||
| 654 | extru %r4,15,16,%r24 | ||
| 655 | copy %r8,%r21 | ||
| 656 | L$0068 | ||
| 657 | sub %r3,%r21,%r20 | ||
| 658 | copy %r20,%r19 | ||
| 659 | depi 0,31,16,%r19 | ||
| 660 | comib,<> 0,%r19,L$0069 | ||
| 661 | zdep %r20,15,16,%r19 | ||
| 662 | addl %r19,%r24,%r19 | ||
| 663 | comb,>>= %r19,%r22,L$0069 | ||
| 664 | sub %r22,%r28,%r22 | ||
| 665 | sub %r21,%r23,%r21 | ||
| 666 | bl L$0068,0 | ||
| 667 | ldo -1(%r29),%r29 | ||
| 668 | L$0069 | ||
| 669 | stw %r29,-16(0,%r30) | ||
| 670 | fldws -16(0,%r30),%fr10L | ||
| 671 | stw %r28,-16(0,%r30) | ||
| 672 | fldws -16(0,%r30),%fr10R | ||
| 673 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 674 | fstws %fr8R,-16(0,%r30) | ||
| 675 | ldw -16(0,%r30),%r8 | ||
| 676 | stw %r23,-16(0,%r30) | ||
| 677 | fldws -16(0,%r30),%fr10R | ||
| 678 | copy %r8,%r19 | ||
| 679 | xmpyu %fr10L,%fr10R,%fr8 | ||
| 680 | fstws %fr8R,-16(0,%r30) | ||
| 681 | extru %r19,15,16,%r20 | ||
| 682 | ldw -16(0,%r30),%r8 | ||
| 683 | zdep %r19,15,16,%r19 | ||
| 684 | addl %r8,%r20,%r20 | ||
| 685 | comclr,<<= %r19,%r4,0 | ||
| 686 | addi 1,%r20,%r20 | ||
| 687 | comb,<<= %r20,%r3,L$0074 | ||
| 688 | sub %r4,%r19,%r4 | ||
| 689 | addl %r3,%r5,%r3 | ||
| 690 | ldo -1(%r29),%r29 | ||
| 691 | L$0074 | ||
| 692 | addib,= -1,%r6,L$0064 | ||
| 693 | sub %r3,%r20,%r3 | ||
| 694 | zdep %r29,15,16,%r7 | ||
| 695 | shd %r3,%r4,16,%r3 | ||
| 696 | bl L$0063,0 | ||
| 697 | zdep %r4,15,16,%r4 | ||
| 698 | L$0064 | ||
| 699 | or %r7,%r29,%r28 | ||
| 700 | L$0076 | ||
| 701 | ldw -148(0,%r30),%r2 | ||
| 702 | ldw -124(0,%r30),%r7 | ||
| 703 | ldw -120(0,%r30),%r6 | ||
| 704 | ldw -116(0,%r30),%r5 | ||
| 705 | ldw -112(0,%r30),%r4 | ||
| 706 | ldw -108(0,%r30),%r3 | ||
| 707 | bv 0(%r2) | ||
| 708 | ldwm -128(0,%r30),%r8 | ||
| 709 | .EXIT | ||
| 710 | .PROCEND | ||
diff --git a/src/lib/libcrypto/bn/asm/r3000.s b/src/lib/libcrypto/bn/asm/r3000.s new file mode 100644 index 0000000000..e95269afa3 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/r3000.s | |||
| @@ -0,0 +1,646 @@ | |||
| 1 | .file 1 "../bn_mulw.c" | ||
| 2 | .set nobopt | ||
| 3 | .option pic2 | ||
| 4 | |||
| 5 | # GNU C 2.6.3 [AL 1.1, MM 40] SGI running IRIX 5.0 compiled by GNU C | ||
| 6 | |||
| 7 | # Cc1 defaults: | ||
| 8 | # -mabicalls | ||
| 9 | |||
| 10 | # Cc1 arguments (-G value = 0, Cpu = 3000, ISA = 1): | ||
| 11 | # -quiet -dumpbase -O2 -o | ||
| 12 | |||
| 13 | gcc2_compiled.: | ||
| 14 | __gnu_compiled_c: | ||
| 15 | .rdata | ||
| 16 | |||
| 17 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 18 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x39,0x20 | ||
| 19 | .byte 0x24,0x0 | ||
| 20 | |||
| 21 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 22 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x33,0x34,0x20 | ||
| 23 | .byte 0x24,0x0 | ||
| 24 | |||
| 25 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 26 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x35,0x20,0x24 | ||
| 27 | .byte 0x0 | ||
| 28 | |||
| 29 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 30 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24 | ||
| 31 | .byte 0x0 | ||
| 32 | |||
| 33 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 34 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x33,0x20 | ||
| 35 | .byte 0x24,0x0 | ||
| 36 | |||
| 37 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 38 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x37,0x38,0x20 | ||
| 39 | .byte 0x24,0x0 | ||
| 40 | |||
| 41 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 42 | .byte 0x6e,0x3a,0x20,0x33,0x2e,0x37,0x30,0x20 | ||
| 43 | .byte 0x24,0x0 | ||
| 44 | |||
| 45 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 46 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x20,0x24 | ||
| 47 | .byte 0x0 | ||
| 48 | |||
| 49 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 50 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x20,0x24 | ||
| 51 | .byte 0x0 | ||
| 52 | |||
| 53 | .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f | ||
| 54 | .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24 | ||
| 55 | .byte 0x0 | ||
| 56 | .text | ||
| 57 | .align 2 | ||
| 58 | .globl bn_mul_add_words | ||
| 59 | .ent bn_mul_add_words | ||
| 60 | bn_mul_add_words: | ||
| 61 | .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0 | ||
| 62 | .mask 0x00000000,0 | ||
| 63 | .fmask 0x00000000,0 | ||
| 64 | .set noreorder | ||
| 65 | .cpload $25 | ||
| 66 | .set reorder | ||
| 67 | move $12,$4 | ||
| 68 | move $14,$5 | ||
| 69 | move $9,$6 | ||
| 70 | move $13,$7 | ||
| 71 | move $8,$0 | ||
| 72 | addu $10,$12,12 | ||
| 73 | addu $11,$14,12 | ||
| 74 | $L2: | ||
| 75 | lw $6,0($14) | ||
| 76 | #nop | ||
| 77 | multu $13,$6 | ||
| 78 | mfhi $6 | ||
| 79 | mflo $7 | ||
| 80 | #nop | ||
| 81 | move $5,$8 | ||
| 82 | move $4,$0 | ||
| 83 | lw $3,0($12) | ||
| 84 | addu $9,$9,-1 | ||
| 85 | move $2,$0 | ||
| 86 | addu $7,$7,$3 | ||
| 87 | sltu $8,$7,$3 | ||
| 88 | addu $6,$6,$2 | ||
| 89 | addu $6,$6,$8 | ||
| 90 | addu $7,$7,$5 | ||
| 91 | sltu $2,$7,$5 | ||
| 92 | addu $6,$6,$4 | ||
| 93 | addu $6,$6,$2 | ||
| 94 | srl $3,$6,0 | ||
| 95 | move $2,$0 | ||
| 96 | move $8,$3 | ||
| 97 | .set noreorder | ||
| 98 | .set nomacro | ||
| 99 | beq $9,$0,$L3 | ||
| 100 | sw $7,0($12) | ||
| 101 | .set macro | ||
| 102 | .set reorder | ||
| 103 | |||
| 104 | lw $6,-8($11) | ||
| 105 | #nop | ||
| 106 | multu $13,$6 | ||
| 107 | mfhi $6 | ||
| 108 | mflo $7 | ||
| 109 | #nop | ||
| 110 | move $5,$8 | ||
| 111 | move $4,$0 | ||
| 112 | lw $3,-8($10) | ||
| 113 | addu $9,$9,-1 | ||
| 114 | move $2,$0 | ||
| 115 | addu $7,$7,$3 | ||
| 116 | sltu $8,$7,$3 | ||
| 117 | addu $6,$6,$2 | ||
| 118 | addu $6,$6,$8 | ||
| 119 | addu $7,$7,$5 | ||
| 120 | sltu $2,$7,$5 | ||
| 121 | addu $6,$6,$4 | ||
| 122 | addu $6,$6,$2 | ||
| 123 | srl $3,$6,0 | ||
| 124 | move $2,$0 | ||
| 125 | move $8,$3 | ||
| 126 | .set noreorder | ||
| 127 | .set nomacro | ||
| 128 | beq $9,$0,$L3 | ||
| 129 | sw $7,-8($10) | ||
| 130 | .set macro | ||
| 131 | .set reorder | ||
| 132 | |||
| 133 | lw $6,-4($11) | ||
| 134 | #nop | ||
| 135 | multu $13,$6 | ||
| 136 | mfhi $6 | ||
| 137 | mflo $7 | ||
| 138 | #nop | ||
| 139 | move $5,$8 | ||
| 140 | move $4,$0 | ||
| 141 | lw $3,-4($10) | ||
| 142 | addu $9,$9,-1 | ||
| 143 | move $2,$0 | ||
| 144 | addu $7,$7,$3 | ||
| 145 | sltu $8,$7,$3 | ||
| 146 | addu $6,$6,$2 | ||
| 147 | addu $6,$6,$8 | ||
| 148 | addu $7,$7,$5 | ||
| 149 | sltu $2,$7,$5 | ||
| 150 | addu $6,$6,$4 | ||
| 151 | addu $6,$6,$2 | ||
| 152 | srl $3,$6,0 | ||
| 153 | move $2,$0 | ||
| 154 | move $8,$3 | ||
| 155 | .set noreorder | ||
| 156 | .set nomacro | ||
| 157 | beq $9,$0,$L3 | ||
| 158 | sw $7,-4($10) | ||
| 159 | .set macro | ||
| 160 | .set reorder | ||
| 161 | |||
| 162 | lw $6,0($11) | ||
| 163 | #nop | ||
| 164 | multu $13,$6 | ||
| 165 | mfhi $6 | ||
| 166 | mflo $7 | ||
| 167 | #nop | ||
| 168 | move $5,$8 | ||
| 169 | move $4,$0 | ||
| 170 | lw $3,0($10) | ||
| 171 | addu $9,$9,-1 | ||
| 172 | move $2,$0 | ||
| 173 | addu $7,$7,$3 | ||
| 174 | sltu $8,$7,$3 | ||
| 175 | addu $6,$6,$2 | ||
| 176 | addu $6,$6,$8 | ||
| 177 | addu $7,$7,$5 | ||
| 178 | sltu $2,$7,$5 | ||
| 179 | addu $6,$6,$4 | ||
| 180 | addu $6,$6,$2 | ||
| 181 | srl $3,$6,0 | ||
| 182 | move $2,$0 | ||
| 183 | move $8,$3 | ||
| 184 | .set noreorder | ||
| 185 | .set nomacro | ||
| 186 | beq $9,$0,$L3 | ||
| 187 | sw $7,0($10) | ||
| 188 | .set macro | ||
| 189 | .set reorder | ||
| 190 | |||
| 191 | addu $11,$11,16 | ||
| 192 | addu $14,$14,16 | ||
| 193 | addu $10,$10,16 | ||
| 194 | .set noreorder | ||
| 195 | .set nomacro | ||
| 196 | j $L2 | ||
| 197 | addu $12,$12,16 | ||
| 198 | .set macro | ||
| 199 | .set reorder | ||
| 200 | |||
| 201 | $L3: | ||
| 202 | .set noreorder | ||
| 203 | .set nomacro | ||
| 204 | j $31 | ||
| 205 | move $2,$8 | ||
| 206 | .set macro | ||
| 207 | .set reorder | ||
| 208 | |||
| 209 | .end bn_mul_add_words | ||
| 210 | .align 2 | ||
| 211 | .globl bn_mul_words | ||
| 212 | .ent bn_mul_words | ||
| 213 | bn_mul_words: | ||
| 214 | .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0 | ||
| 215 | .mask 0x00000000,0 | ||
| 216 | .fmask 0x00000000,0 | ||
| 217 | .set noreorder | ||
| 218 | .cpload $25 | ||
| 219 | .set reorder | ||
| 220 | move $11,$4 | ||
| 221 | move $12,$5 | ||
| 222 | move $8,$6 | ||
| 223 | move $6,$0 | ||
| 224 | addu $10,$11,12 | ||
| 225 | addu $9,$12,12 | ||
| 226 | $L10: | ||
| 227 | lw $4,0($12) | ||
| 228 | #nop | ||
| 229 | multu $7,$4 | ||
| 230 | mfhi $4 | ||
| 231 | mflo $5 | ||
| 232 | #nop | ||
| 233 | move $3,$6 | ||
| 234 | move $2,$0 | ||
| 235 | addu $8,$8,-1 | ||
| 236 | addu $5,$5,$3 | ||
| 237 | sltu $6,$5,$3 | ||
| 238 | addu $4,$4,$2 | ||
| 239 | addu $4,$4,$6 | ||
| 240 | srl $3,$4,0 | ||
| 241 | move $2,$0 | ||
| 242 | move $6,$3 | ||
| 243 | .set noreorder | ||
| 244 | .set nomacro | ||
| 245 | beq $8,$0,$L11 | ||
| 246 | sw $5,0($11) | ||
| 247 | .set macro | ||
| 248 | .set reorder | ||
| 249 | |||
| 250 | lw $4,-8($9) | ||
| 251 | #nop | ||
| 252 | multu $7,$4 | ||
| 253 | mfhi $4 | ||
| 254 | mflo $5 | ||
| 255 | #nop | ||
| 256 | move $3,$6 | ||
| 257 | move $2,$0 | ||
| 258 | addu $8,$8,-1 | ||
| 259 | addu $5,$5,$3 | ||
| 260 | sltu $6,$5,$3 | ||
| 261 | addu $4,$4,$2 | ||
| 262 | addu $4,$4,$6 | ||
| 263 | srl $3,$4,0 | ||
| 264 | move $2,$0 | ||
| 265 | move $6,$3 | ||
| 266 | .set noreorder | ||
| 267 | .set nomacro | ||
| 268 | beq $8,$0,$L11 | ||
| 269 | sw $5,-8($10) | ||
| 270 | .set macro | ||
| 271 | .set reorder | ||
| 272 | |||
| 273 | lw $4,-4($9) | ||
| 274 | #nop | ||
| 275 | multu $7,$4 | ||
| 276 | mfhi $4 | ||
| 277 | mflo $5 | ||
| 278 | #nop | ||
| 279 | move $3,$6 | ||
| 280 | move $2,$0 | ||
| 281 | addu $8,$8,-1 | ||
| 282 | addu $5,$5,$3 | ||
| 283 | sltu $6,$5,$3 | ||
| 284 | addu $4,$4,$2 | ||
| 285 | addu $4,$4,$6 | ||
| 286 | srl $3,$4,0 | ||
| 287 | move $2,$0 | ||
| 288 | move $6,$3 | ||
| 289 | .set noreorder | ||
| 290 | .set nomacro | ||
| 291 | beq $8,$0,$L11 | ||
| 292 | sw $5,-4($10) | ||
| 293 | .set macro | ||
| 294 | .set reorder | ||
| 295 | |||
| 296 | lw $4,0($9) | ||
| 297 | #nop | ||
| 298 | multu $7,$4 | ||
| 299 | mfhi $4 | ||
| 300 | mflo $5 | ||
| 301 | #nop | ||
| 302 | move $3,$6 | ||
| 303 | move $2,$0 | ||
| 304 | addu $8,$8,-1 | ||
| 305 | addu $5,$5,$3 | ||
| 306 | sltu $6,$5,$3 | ||
| 307 | addu $4,$4,$2 | ||
| 308 | addu $4,$4,$6 | ||
| 309 | srl $3,$4,0 | ||
| 310 | move $2,$0 | ||
| 311 | move $6,$3 | ||
| 312 | .set noreorder | ||
| 313 | .set nomacro | ||
| 314 | beq $8,$0,$L11 | ||
| 315 | sw $5,0($10) | ||
| 316 | .set macro | ||
| 317 | .set reorder | ||
| 318 | |||
| 319 | addu $9,$9,16 | ||
| 320 | addu $12,$12,16 | ||
| 321 | addu $10,$10,16 | ||
| 322 | .set noreorder | ||
| 323 | .set nomacro | ||
| 324 | j $L10 | ||
| 325 | addu $11,$11,16 | ||
| 326 | .set macro | ||
| 327 | .set reorder | ||
| 328 | |||
| 329 | $L11: | ||
| 330 | .set noreorder | ||
| 331 | .set nomacro | ||
| 332 | j $31 | ||
| 333 | move $2,$6 | ||
| 334 | .set macro | ||
| 335 | .set reorder | ||
| 336 | |||
| 337 | .end bn_mul_words | ||
| 338 | .align 2 | ||
| 339 | .globl bn_sqr_words | ||
| 340 | .ent bn_sqr_words | ||
| 341 | bn_sqr_words: | ||
| 342 | .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0 | ||
| 343 | .mask 0x00000000,0 | ||
| 344 | .fmask 0x00000000,0 | ||
| 345 | .set noreorder | ||
| 346 | .cpload $25 | ||
| 347 | .set reorder | ||
| 348 | move $9,$4 | ||
| 349 | addu $7,$9,28 | ||
| 350 | addu $8,$5,12 | ||
| 351 | $L18: | ||
| 352 | lw $2,0($5) | ||
| 353 | #nop | ||
| 354 | multu $2,$2 | ||
| 355 | mfhi $2 | ||
| 356 | mflo $3 | ||
| 357 | #nop | ||
| 358 | addu $6,$6,-1 | ||
| 359 | sw $3,0($9) | ||
| 360 | srl $3,$2,0 | ||
| 361 | move $2,$0 | ||
| 362 | .set noreorder | ||
| 363 | .set nomacro | ||
| 364 | beq $6,$0,$L19 | ||
| 365 | sw $3,-24($7) | ||
| 366 | .set macro | ||
| 367 | .set reorder | ||
| 368 | |||
| 369 | lw $2,-8($8) | ||
| 370 | #nop | ||
| 371 | multu $2,$2 | ||
| 372 | mfhi $2 | ||
| 373 | mflo $3 | ||
| 374 | #nop | ||
| 375 | addu $6,$6,-1 | ||
| 376 | sw $3,-20($7) | ||
| 377 | srl $3,$2,0 | ||
| 378 | move $2,$0 | ||
| 379 | .set noreorder | ||
| 380 | .set nomacro | ||
| 381 | beq $6,$0,$L19 | ||
| 382 | sw $3,-16($7) | ||
| 383 | .set macro | ||
| 384 | .set reorder | ||
| 385 | |||
| 386 | lw $2,-4($8) | ||
| 387 | #nop | ||
| 388 | multu $2,$2 | ||
| 389 | mfhi $2 | ||
| 390 | mflo $3 | ||
| 391 | #nop | ||
| 392 | addu $6,$6,-1 | ||
| 393 | sw $3,-12($7) | ||
| 394 | srl $3,$2,0 | ||
| 395 | move $2,$0 | ||
| 396 | .set noreorder | ||
| 397 | .set nomacro | ||
| 398 | beq $6,$0,$L19 | ||
| 399 | sw $3,-8($7) | ||
| 400 | .set macro | ||
| 401 | .set reorder | ||
| 402 | |||
| 403 | lw $2,0($8) | ||
| 404 | #nop | ||
| 405 | multu $2,$2 | ||
| 406 | mfhi $2 | ||
| 407 | mflo $3 | ||
| 408 | #nop | ||
| 409 | addu $6,$6,-1 | ||
| 410 | sw $3,-4($7) | ||
| 411 | srl $3,$2,0 | ||
| 412 | move $2,$0 | ||
| 413 | .set noreorder | ||
| 414 | .set nomacro | ||
| 415 | beq $6,$0,$L19 | ||
| 416 | sw $3,0($7) | ||
| 417 | .set macro | ||
| 418 | .set reorder | ||
| 419 | |||
| 420 | addu $8,$8,16 | ||
| 421 | addu $5,$5,16 | ||
| 422 | addu $7,$7,32 | ||
| 423 | .set noreorder | ||
| 424 | .set nomacro | ||
| 425 | j $L18 | ||
| 426 | addu $9,$9,32 | ||
| 427 | .set macro | ||
| 428 | .set reorder | ||
| 429 | |||
| 430 | $L19: | ||
| 431 | j $31 | ||
| 432 | .end bn_sqr_words | ||
| 433 | .rdata | ||
| 434 | .align 2 | ||
| 435 | $LC0: | ||
| 436 | |||
| 437 | .byte 0x44,0x69,0x76,0x69,0x73,0x69,0x6f,0x6e | ||
| 438 | .byte 0x20,0x77,0x6f,0x75,0x6c,0x64,0x20,0x6f | ||
| 439 | .byte 0x76,0x65,0x72,0x66,0x6c,0x6f,0x77,0xa | ||
| 440 | .byte 0x0 | ||
| 441 | .text | ||
| 442 | .align 2 | ||
| 443 | .globl bn_div64 | ||
| 444 | .ent bn_div64 | ||
| 445 | bn_div64: | ||
| 446 | .frame $sp,56,$31 # vars= 0, regs= 7/0, args= 16, extra= 8 | ||
| 447 | .mask 0x901f0000,-8 | ||
| 448 | .fmask 0x00000000,0 | ||
| 449 | .set noreorder | ||
| 450 | .cpload $25 | ||
| 451 | .set reorder | ||
| 452 | subu $sp,$sp,56 | ||
| 453 | .cprestore 16 | ||
| 454 | sw $16,24($sp) | ||
| 455 | move $16,$4 | ||
| 456 | sw $17,28($sp) | ||
| 457 | move $17,$5 | ||
| 458 | sw $18,32($sp) | ||
| 459 | move $18,$6 | ||
| 460 | sw $20,40($sp) | ||
| 461 | move $20,$0 | ||
| 462 | sw $19,36($sp) | ||
| 463 | li $19,0x00000002 # 2 | ||
| 464 | sw $31,48($sp) | ||
| 465 | .set noreorder | ||
| 466 | .set nomacro | ||
| 467 | bne $18,$0,$L26 | ||
| 468 | sw $28,44($sp) | ||
| 469 | .set macro | ||
| 470 | .set reorder | ||
| 471 | |||
| 472 | .set noreorder | ||
| 473 | .set nomacro | ||
| 474 | j $L43 | ||
| 475 | li $2,-1 # 0xffffffff | ||
| 476 | .set macro | ||
| 477 | .set reorder | ||
| 478 | |||
| 479 | $L26: | ||
| 480 | move $4,$18 | ||
| 481 | jal BN_num_bits_word | ||
| 482 | move $4,$2 | ||
| 483 | li $2,0x00000020 # 32 | ||
| 484 | .set noreorder | ||
| 485 | .set nomacro | ||
| 486 | beq $4,$2,$L27 | ||
| 487 | li $2,0x00000001 # 1 | ||
| 488 | .set macro | ||
| 489 | .set reorder | ||
| 490 | |||
| 491 | sll $2,$2,$4 | ||
| 492 | sltu $2,$2,$16 | ||
| 493 | .set noreorder | ||
| 494 | .set nomacro | ||
| 495 | beq $2,$0,$L44 | ||
| 496 | li $5,0x00000020 # 32 | ||
| 497 | .set macro | ||
| 498 | .set reorder | ||
| 499 | |||
| 500 | la $4,__iob+32 | ||
| 501 | la $5,$LC0 | ||
| 502 | jal fprintf | ||
| 503 | jal abort | ||
| 504 | $L27: | ||
| 505 | li $5,0x00000020 # 32 | ||
| 506 | $L44: | ||
| 507 | sltu $2,$16,$18 | ||
| 508 | .set noreorder | ||
| 509 | .set nomacro | ||
| 510 | bne $2,$0,$L28 | ||
| 511 | subu $4,$5,$4 | ||
| 512 | .set macro | ||
| 513 | .set reorder | ||
| 514 | |||
| 515 | subu $16,$16,$18 | ||
| 516 | $L28: | ||
| 517 | .set noreorder | ||
| 518 | .set nomacro | ||
| 519 | beq $4,$0,$L29 | ||
| 520 | li $10,-65536 # 0xffff0000 | ||
| 521 | .set macro | ||
| 522 | .set reorder | ||
| 523 | |||
| 524 | sll $18,$18,$4 | ||
| 525 | sll $3,$16,$4 | ||
| 526 | subu $2,$5,$4 | ||
| 527 | srl $2,$17,$2 | ||
| 528 | or $16,$3,$2 | ||
| 529 | sll $17,$17,$4 | ||
| 530 | $L29: | ||
| 531 | srl $7,$18,16 | ||
| 532 | andi $9,$18,0xffff | ||
| 533 | $L30: | ||
| 534 | srl $2,$16,16 | ||
| 535 | .set noreorder | ||
| 536 | .set nomacro | ||
| 537 | beq $2,$7,$L34 | ||
| 538 | li $6,0x0000ffff # 65535 | ||
| 539 | .set macro | ||
| 540 | .set reorder | ||
| 541 | |||
| 542 | divu $6,$16,$7 | ||
| 543 | $L34: | ||
| 544 | mult $6,$9 | ||
| 545 | mflo $5 | ||
| 546 | #nop | ||
| 547 | #nop | ||
| 548 | mult $6,$7 | ||
| 549 | and $2,$17,$10 | ||
| 550 | srl $8,$2,16 | ||
| 551 | mflo $4 | ||
| 552 | $L35: | ||
| 553 | subu $3,$16,$4 | ||
| 554 | and $2,$3,$10 | ||
| 555 | .set noreorder | ||
| 556 | .set nomacro | ||
| 557 | bne $2,$0,$L36 | ||
| 558 | sll $2,$3,16 | ||
| 559 | .set macro | ||
| 560 | .set reorder | ||
| 561 | |||
| 562 | addu $2,$2,$8 | ||
| 563 | sltu $2,$2,$5 | ||
| 564 | .set noreorder | ||
| 565 | .set nomacro | ||
| 566 | beq $2,$0,$L36 | ||
| 567 | subu $5,$5,$9 | ||
| 568 | .set macro | ||
| 569 | .set reorder | ||
| 570 | |||
| 571 | subu $4,$4,$7 | ||
| 572 | .set noreorder | ||
| 573 | .set nomacro | ||
| 574 | j $L35 | ||
| 575 | addu $6,$6,-1 | ||
| 576 | .set macro | ||
| 577 | .set reorder | ||
| 578 | |||
| 579 | $L36: | ||
| 580 | mult $6,$7 | ||
| 581 | mflo $5 | ||
| 582 | #nop | ||
| 583 | #nop | ||
| 584 | mult $6,$9 | ||
| 585 | mflo $4 | ||
| 586 | #nop | ||
| 587 | #nop | ||
| 588 | srl $3,$4,16 | ||
| 589 | sll $2,$4,16 | ||
| 590 | and $4,$2,$10 | ||
| 591 | sltu $2,$17,$4 | ||
| 592 | .set noreorder | ||
| 593 | .set nomacro | ||
| 594 | beq $2,$0,$L40 | ||
| 595 | addu $5,$5,$3 | ||
| 596 | .set macro | ||
| 597 | .set reorder | ||
| 598 | |||
| 599 | addu $5,$5,1 | ||
| 600 | $L40: | ||
| 601 | sltu $2,$16,$5 | ||
| 602 | .set noreorder | ||
| 603 | .set nomacro | ||
| 604 | beq $2,$0,$L41 | ||
| 605 | subu $17,$17,$4 | ||
| 606 | .set macro | ||
| 607 | .set reorder | ||
| 608 | |||
| 609 | addu $16,$16,$18 | ||
| 610 | addu $6,$6,-1 | ||
| 611 | $L41: | ||
| 612 | addu $19,$19,-1 | ||
| 613 | .set noreorder | ||
| 614 | .set nomacro | ||
| 615 | beq $19,$0,$L31 | ||
| 616 | subu $16,$16,$5 | ||
| 617 | .set macro | ||
| 618 | .set reorder | ||
| 619 | |||
| 620 | sll $20,$6,16 | ||
| 621 | sll $3,$16,16 | ||
| 622 | srl $2,$17,16 | ||
| 623 | or $16,$3,$2 | ||
| 624 | .set noreorder | ||
| 625 | .set nomacro | ||
| 626 | j $L30 | ||
| 627 | sll $17,$17,16 | ||
| 628 | .set macro | ||
| 629 | .set reorder | ||
| 630 | |||
| 631 | $L31: | ||
| 632 | or $2,$20,$6 | ||
| 633 | $L43: | ||
| 634 | lw $31,48($sp) | ||
| 635 | lw $20,40($sp) | ||
| 636 | lw $19,36($sp) | ||
| 637 | lw $18,32($sp) | ||
| 638 | lw $17,28($sp) | ||
| 639 | lw $16,24($sp) | ||
| 640 | addu $sp,$sp,56 | ||
| 641 | j $31 | ||
| 642 | .end bn_div64 | ||
| 643 | |||
| 644 | .globl abort .text | ||
| 645 | .globl fprintf .text | ||
| 646 | .globl BN_num_bits_word .text | ||
diff --git a/src/lib/libcrypto/bn/bnspeed.c b/src/lib/libcrypto/bn/bnspeed.c new file mode 100644 index 0000000000..f7c2790fff --- /dev/null +++ b/src/lib/libcrypto/bn/bnspeed.c | |||
| @@ -0,0 +1,248 @@ | |||
| 1 | /* crypto/bn/bnspeed.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 | /* most of this code has been pilfered from my libdes speed.c program */ | ||
| 60 | |||
| 61 | #define BASENUM 1000000 | ||
| 62 | #undef PROG | ||
| 63 | #define PROG bnspeed_main | ||
| 64 | |||
| 65 | #include <stdio.h> | ||
| 66 | #include <stdlib.h> | ||
| 67 | #include <signal.h> | ||
| 68 | #include <string.h> | ||
| 69 | #include "crypto.h" | ||
| 70 | #include "err.h" | ||
| 71 | |||
| 72 | #ifndef MSDOS | ||
| 73 | #define TIMES | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #ifndef VMS | ||
| 77 | #ifndef _IRIX | ||
| 78 | #include <time.h> | ||
| 79 | #endif | ||
| 80 | #ifdef TIMES | ||
| 81 | #include <sys/types.h> | ||
| 82 | #include <sys/times.h> | ||
| 83 | #endif | ||
| 84 | #else /* VMS */ | ||
| 85 | #include <types.h> | ||
| 86 | struct tms { | ||
| 87 | time_t tms_utime; | ||
| 88 | time_t tms_stime; | ||
| 89 | time_t tms_uchild; /* I dunno... */ | ||
| 90 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
| 91 | } | ||
| 92 | #endif | ||
| 93 | #ifndef TIMES | ||
| 94 | #include <sys/timeb.h> | ||
| 95 | #endif | ||
| 96 | |||
| 97 | #ifdef sun | ||
| 98 | #include <limits.h> | ||
| 99 | #include <sys/param.h> | ||
| 100 | #endif | ||
| 101 | |||
| 102 | #include "bn.h" | ||
| 103 | #include "x509.h" | ||
| 104 | |||
| 105 | /* The following if from times(3) man page. It may need to be changed */ | ||
| 106 | #ifndef HZ | ||
| 107 | # ifndef CLK_TCK | ||
| 108 | # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ | ||
| 109 | # ifndef VMS | ||
| 110 | # define HZ 100.0 | ||
| 111 | # else /* VMS */ | ||
| 112 | # define HZ 100.0 | ||
| 113 | # endif | ||
| 114 | # else /* _BSD_CLK_TCK_ */ | ||
| 115 | # define HZ ((double)_BSD_CLK_TCK_) | ||
| 116 | # endif | ||
| 117 | # else /* CLK_TCK */ | ||
| 118 | # define HZ ((double)CLK_TCK) | ||
| 119 | # endif | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #undef BUFSIZE | ||
| 123 | #define BUFSIZE ((long)1024*8) | ||
| 124 | int run=0; | ||
| 125 | |||
| 126 | #ifndef NOPROTO | ||
| 127 | static double Time_F(int s); | ||
| 128 | #else | ||
| 129 | static double Time_F(); | ||
| 130 | #endif | ||
| 131 | |||
| 132 | #define START 0 | ||
| 133 | #define STOP 1 | ||
| 134 | |||
| 135 | static double Time_F(s) | ||
| 136 | int s; | ||
| 137 | { | ||
| 138 | double ret; | ||
| 139 | #ifdef TIMES | ||
| 140 | static struct tms tstart,tend; | ||
| 141 | |||
| 142 | if (s == START) | ||
| 143 | { | ||
| 144 | times(&tstart); | ||
| 145 | return(0); | ||
| 146 | } | ||
| 147 | else | ||
| 148 | { | ||
| 149 | times(&tend); | ||
| 150 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
| 151 | return((ret < 1e-3)?1e-3:ret); | ||
| 152 | } | ||
| 153 | #else /* !times() */ | ||
| 154 | static struct timeb tstart,tend; | ||
| 155 | long i; | ||
| 156 | |||
| 157 | if (s == START) | ||
| 158 | { | ||
| 159 | ftime(&tstart); | ||
| 160 | return(0); | ||
| 161 | } | ||
| 162 | else | ||
| 163 | { | ||
| 164 | ftime(&tend); | ||
| 165 | i=(long)tend.millitm-(long)tstart.millitm; | ||
| 166 | ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; | ||
| 167 | return((ret < 0.001)?0.001:ret); | ||
| 168 | } | ||
| 169 | #endif | ||
| 170 | } | ||
| 171 | |||
| 172 | #define NUM_SIZES 5 | ||
| 173 | static int sizes[NUM_SIZES]={128,256,512,1024,2048}; | ||
| 174 | /*static int sizes[NUM_SIZES]={59,179,299,419,539}; */ | ||
| 175 | |||
| 176 | void do_mul(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx); | ||
| 177 | |||
| 178 | int main(argc,argv) | ||
| 179 | int argc; | ||
| 180 | char **argv; | ||
| 181 | { | ||
| 182 | BN_CTX *ctx; | ||
| 183 | BIGNUM *a,*b,*c,*r; | ||
| 184 | |||
| 185 | ctx=BN_CTX_new(); | ||
| 186 | a=BN_new(); | ||
| 187 | b=BN_new(); | ||
| 188 | c=BN_new(); | ||
| 189 | r=BN_new(); | ||
| 190 | |||
| 191 | do_mul(a,b,c,ctx); | ||
| 192 | } | ||
| 193 | |||
| 194 | void do_mul(r,a,b,ctx) | ||
| 195 | BIGNUM *r; | ||
| 196 | BIGNUM *a; | ||
| 197 | BIGNUM *b; | ||
| 198 | BN_CTX *ctx; | ||
| 199 | { | ||
| 200 | int i,j,k; | ||
| 201 | double tm; | ||
| 202 | long num; | ||
| 203 | |||
| 204 | for (i=0; i<NUM_SIZES; i++) | ||
| 205 | { | ||
| 206 | num=BASENUM; | ||
| 207 | if (i) num/=(i*3); | ||
| 208 | BN_rand(a,sizes[i],1,0); | ||
| 209 | for (j=i; j<NUM_SIZES; j++) | ||
| 210 | { | ||
| 211 | BN_rand(b,sizes[j],1,0); | ||
| 212 | Time_F(START); | ||
| 213 | for (k=0; k<num; k++) | ||
| 214 | BN_mul(r,b,a); | ||
| 215 | tm=Time_F(STOP); | ||
| 216 | printf("mul %4d x %4d -> %8.3fms\n",sizes[i],sizes[j],tm*1000.0/num); | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | for (i=0; i<NUM_SIZES; i++) | ||
| 221 | { | ||
| 222 | num=BASENUM; | ||
| 223 | if (i) num/=(i*3); | ||
| 224 | BN_rand(a,sizes[i],1,0); | ||
| 225 | Time_F(START); | ||
| 226 | for (k=0; k<num; k++) | ||
| 227 | BN_sqr(r,a,ctx); | ||
| 228 | tm=Time_F(STOP); | ||
| 229 | printf("sqr %4d x %4d -> %8.3fms\n",sizes[i],sizes[i],tm*1000.0/num); | ||
| 230 | } | ||
| 231 | |||
| 232 | for (i=0; i<NUM_SIZES; i++) | ||
| 233 | { | ||
| 234 | num=BASENUM/10; | ||
| 235 | if (i) num/=(i*3); | ||
| 236 | BN_rand(a,sizes[i]-1,1,0); | ||
| 237 | for (j=i; j<NUM_SIZES; j++) | ||
| 238 | { | ||
| 239 | BN_rand(b,sizes[j],1,0); | ||
| 240 | Time_F(START); | ||
| 241 | for (k=0; k<100000; k++) | ||
| 242 | BN_div(r, NULL, b, a,ctx); | ||
| 243 | tm=Time_F(STOP); | ||
| 244 | printf("div %4d / %4d -> %8.3fms\n",sizes[j],sizes[i]-1,tm*1000.0/num); | ||
| 245 | } | ||
| 246 | } | ||
| 247 | } | ||
| 248 | |||
diff --git a/src/lib/libcrypto/bn/bntest.c b/src/lib/libcrypto/bn/bntest.c new file mode 100644 index 0000000000..9ebd68b429 --- /dev/null +++ b/src/lib/libcrypto/bn/bntest.c | |||
| @@ -0,0 +1,777 @@ | |||
| 1 | /* crypto/bn/bntest.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 <stdlib.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include "e_os.h" | ||
| 63 | #include "bio.h" | ||
| 64 | #include "bn.h" | ||
| 65 | #include "rand.h" | ||
| 66 | #include "x509.h" | ||
| 67 | #include "err.h" | ||
| 68 | |||
| 69 | #ifdef WINDOWS | ||
| 70 | #include "../bio/bss_file.c" | ||
| 71 | #endif | ||
| 72 | |||
| 73 | #ifndef NOPROTO | ||
| 74 | int test_add (BIO *bp); | ||
| 75 | int test_sub (BIO *bp); | ||
| 76 | int test_lshift1 (BIO *bp); | ||
| 77 | int test_lshift (BIO *bp); | ||
| 78 | int test_rshift1 (BIO *bp); | ||
| 79 | int test_rshift (BIO *bp); | ||
| 80 | int test_div (BIO *bp,BN_CTX *ctx); | ||
| 81 | int test_mul (BIO *bp); | ||
| 82 | int test_sqr (BIO *bp,BN_CTX *ctx); | ||
| 83 | int test_mont (BIO *bp,BN_CTX *ctx); | ||
| 84 | int test_mod (BIO *bp,BN_CTX *ctx); | ||
| 85 | int test_mod_mul (BIO *bp,BN_CTX *ctx); | ||
| 86 | int test_mod_exp (BIO *bp,BN_CTX *ctx); | ||
| 87 | int rand_neg(void); | ||
| 88 | #else | ||
| 89 | int test_add (); | ||
| 90 | int test_sub (); | ||
| 91 | int test_lshift1 (); | ||
| 92 | int test_lshift (); | ||
| 93 | int test_rshift1 (); | ||
| 94 | int test_rshift (); | ||
| 95 | int test_div (); | ||
| 96 | int test_mul (); | ||
| 97 | int test_sqr (); | ||
| 98 | int test_mont (); | ||
| 99 | int test_mod (); | ||
| 100 | int test_mod_mul (); | ||
| 101 | int test_mod_exp (); | ||
| 102 | int rand_neg(); | ||
| 103 | #endif | ||
| 104 | |||
| 105 | static int results=0; | ||
| 106 | |||
| 107 | #ifdef NO_STDIO | ||
| 108 | #define APPS_WIN16 | ||
| 109 | #include "bss_file.c" | ||
| 110 | #endif | ||
| 111 | |||
| 112 | int main(argc,argv) | ||
| 113 | int argc; | ||
| 114 | char *argv[]; | ||
| 115 | { | ||
| 116 | BN_CTX *ctx; | ||
| 117 | BIO *out; | ||
| 118 | char *outfile=NULL; | ||
| 119 | |||
| 120 | srand((unsigned int)time(NULL)); | ||
| 121 | |||
| 122 | argc--; | ||
| 123 | argv++; | ||
| 124 | while (argc >= 1) | ||
| 125 | { | ||
| 126 | if (strcmp(*argv,"-results") == 0) | ||
| 127 | results=1; | ||
| 128 | else if (strcmp(*argv,"-out") == 0) | ||
| 129 | { | ||
| 130 | if (--argc < 1) break; | ||
| 131 | outfile= *(++argv); | ||
| 132 | } | ||
| 133 | argc--; | ||
| 134 | argv++; | ||
| 135 | } | ||
| 136 | |||
| 137 | |||
| 138 | ctx=BN_CTX_new(); | ||
| 139 | if (ctx == NULL) exit(1); | ||
| 140 | |||
| 141 | out=BIO_new(BIO_s_file()); | ||
| 142 | if (out == NULL) exit(1); | ||
| 143 | if (outfile == NULL) | ||
| 144 | { | ||
| 145 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | ||
| 146 | } | ||
| 147 | else | ||
| 148 | { | ||
| 149 | if (!BIO_write_filename(out,outfile)) | ||
| 150 | { | ||
| 151 | perror(outfile); | ||
| 152 | exit(1); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 | if (!results) | ||
| 157 | BIO_puts(out,"obase=16\nibase=16\n"); | ||
| 158 | |||
| 159 | fprintf(stderr,"test BN_add\n"); | ||
| 160 | if (!test_add(out)) goto err; | ||
| 161 | fflush(stdout); | ||
| 162 | |||
| 163 | fprintf(stderr,"test BN_sub\n"); | ||
| 164 | if (!test_sub(out)) goto err; | ||
| 165 | fflush(stdout); | ||
| 166 | |||
| 167 | fprintf(stderr,"test BN_lshift1\n"); | ||
| 168 | if (!test_lshift1(out)) goto err; | ||
| 169 | fflush(stdout); | ||
| 170 | |||
| 171 | fprintf(stderr,"test BN_lshift\n"); | ||
| 172 | if (!test_lshift(out)) goto err; | ||
| 173 | fflush(stdout); | ||
| 174 | |||
| 175 | fprintf(stderr,"test BN_rshift1\n"); | ||
| 176 | if (!test_rshift1(out)) goto err; | ||
| 177 | fflush(stdout); | ||
| 178 | |||
| 179 | fprintf(stderr,"test BN_rshift\n"); | ||
| 180 | if (!test_rshift(out)) goto err; | ||
| 181 | fflush(stdout); | ||
| 182 | |||
| 183 | fprintf(stderr,"test BN_sqr\n"); | ||
| 184 | if (!test_sqr(out,ctx)) goto err; | ||
| 185 | fflush(stdout); | ||
| 186 | |||
| 187 | fprintf(stderr,"test BN_mul\n"); | ||
| 188 | if (!test_mul(out)) goto err; | ||
| 189 | fflush(stdout); | ||
| 190 | |||
| 191 | fprintf(stderr,"test BN_div\n"); | ||
| 192 | if (!test_div(out,ctx)) goto err; | ||
| 193 | fflush(stdout); | ||
| 194 | |||
| 195 | fprintf(stderr,"test BN_mod\n"); | ||
| 196 | if (!test_mod(out,ctx)) goto err; | ||
| 197 | fflush(stdout); | ||
| 198 | |||
| 199 | fprintf(stderr,"test BN_mod_mul\n"); | ||
| 200 | if (!test_mod_mul(out,ctx)) goto err; | ||
| 201 | fflush(stdout); | ||
| 202 | |||
| 203 | /* | ||
| 204 | fprintf(stderr,"test BN_mont\n"); | ||
| 205 | if (!test_mont(out,ctx)) goto err; | ||
| 206 | fflush(stdout); | ||
| 207 | */ | ||
| 208 | fprintf(stderr,"test BN_mod_exp\n"); | ||
| 209 | if (!test_mod_exp(out,ctx)) goto err; | ||
| 210 | fflush(stdout); | ||
| 211 | |||
| 212 | /**/ | ||
| 213 | exit(0); | ||
| 214 | err: | ||
| 215 | ERR_load_crypto_strings(); | ||
| 216 | ERR_print_errors(out); | ||
| 217 | exit(1); | ||
| 218 | return(1); | ||
| 219 | } | ||
| 220 | |||
| 221 | int test_add(bp) | ||
| 222 | BIO *bp; | ||
| 223 | { | ||
| 224 | BIGNUM *a,*b,*c; | ||
| 225 | int i; | ||
| 226 | int j; | ||
| 227 | |||
| 228 | a=BN_new(); | ||
| 229 | b=BN_new(); | ||
| 230 | c=BN_new(); | ||
| 231 | |||
| 232 | BN_rand(a,512,0,0); | ||
| 233 | for (i=0; i<100; i++) | ||
| 234 | { | ||
| 235 | BN_rand(b,450+i,0,0); | ||
| 236 | a->neg=rand_neg(); | ||
| 237 | b->neg=rand_neg(); | ||
| 238 | if (bp == NULL) | ||
| 239 | for (j=0; j<10000; j++) | ||
| 240 | BN_add(c,a,b); | ||
| 241 | BN_add(c,a,b); | ||
| 242 | if (bp != NULL) | ||
| 243 | { | ||
| 244 | if (!results) | ||
| 245 | { | ||
| 246 | BN_print(bp,a); | ||
| 247 | BIO_puts(bp," + "); | ||
| 248 | BN_print(bp,b); | ||
| 249 | BIO_puts(bp," - "); | ||
| 250 | } | ||
| 251 | BN_print(bp,c); | ||
| 252 | BIO_puts(bp,"\n"); | ||
| 253 | } | ||
| 254 | } | ||
| 255 | BN_free(a); | ||
| 256 | BN_free(b); | ||
| 257 | BN_free(c); | ||
| 258 | return(1); | ||
| 259 | } | ||
| 260 | |||
| 261 | int test_sub(bp) | ||
| 262 | BIO *bp; | ||
| 263 | { | ||
| 264 | BIGNUM *a,*b,*c; | ||
| 265 | int i; | ||
| 266 | int j; | ||
| 267 | |||
| 268 | a=BN_new(); | ||
| 269 | b=BN_new(); | ||
| 270 | c=BN_new(); | ||
| 271 | |||
| 272 | BN_rand(a,512,0,0); | ||
| 273 | for (i=0; i<100; i++) | ||
| 274 | { | ||
| 275 | BN_rand(b,400+i,0,0); | ||
| 276 | a->neg=rand_neg(); | ||
| 277 | b->neg=rand_neg(); | ||
| 278 | if (bp == NULL) | ||
| 279 | for (j=0; j<10000; j++) | ||
| 280 | BN_sub(c,a,b); | ||
| 281 | BN_sub(c,a,b); | ||
| 282 | if (bp != NULL) | ||
| 283 | { | ||
| 284 | if (!results) | ||
| 285 | { | ||
| 286 | BN_print(bp,a); | ||
| 287 | BIO_puts(bp," - "); | ||
| 288 | BN_print(bp,b); | ||
| 289 | BIO_puts(bp," - "); | ||
| 290 | } | ||
| 291 | BN_print(bp,c); | ||
| 292 | BIO_puts(bp,"\n"); | ||
| 293 | } | ||
| 294 | } | ||
| 295 | BN_free(a); | ||
| 296 | BN_free(b); | ||
| 297 | BN_free(c); | ||
| 298 | return(1); | ||
| 299 | } | ||
| 300 | |||
| 301 | int test_div(bp,ctx) | ||
| 302 | BIO *bp; | ||
| 303 | BN_CTX *ctx; | ||
| 304 | { | ||
| 305 | BIGNUM *a,*b,*c,*d; | ||
| 306 | int i; | ||
| 307 | int j; | ||
| 308 | |||
| 309 | a=BN_new(); | ||
| 310 | b=BN_new(); | ||
| 311 | c=BN_new(); | ||
| 312 | d=BN_new(); | ||
| 313 | |||
| 314 | BN_rand(a,400,0,0); | ||
| 315 | for (i=0; i<100; i++) | ||
| 316 | { | ||
| 317 | BN_rand(b,50+i,0,0); | ||
| 318 | a->neg=rand_neg(); | ||
| 319 | b->neg=rand_neg(); | ||
| 320 | if (bp == NULL) | ||
| 321 | for (j=0; j<100; j++) | ||
| 322 | BN_div(d,c,a,b,ctx); | ||
| 323 | BN_div(d,c,a,b,ctx); | ||
| 324 | if (bp != NULL) | ||
| 325 | { | ||
| 326 | if (!results) | ||
| 327 | { | ||
| 328 | BN_print(bp,a); | ||
| 329 | BIO_puts(bp," / "); | ||
| 330 | BN_print(bp,b); | ||
| 331 | BIO_puts(bp," - "); | ||
| 332 | } | ||
| 333 | BN_print(bp,d); | ||
| 334 | BIO_puts(bp,"\n"); | ||
| 335 | |||
| 336 | if (!results) | ||
| 337 | { | ||
| 338 | BN_print(bp,a); | ||
| 339 | BIO_puts(bp," % "); | ||
| 340 | BN_print(bp,b); | ||
| 341 | BIO_puts(bp," - "); | ||
| 342 | } | ||
| 343 | BN_print(bp,c); | ||
| 344 | BIO_puts(bp,"\n"); | ||
| 345 | } | ||
| 346 | } | ||
| 347 | BN_free(a); | ||
| 348 | BN_free(b); | ||
| 349 | BN_free(c); | ||
| 350 | BN_free(d); | ||
| 351 | return(1); | ||
| 352 | } | ||
| 353 | |||
| 354 | int test_mul(bp) | ||
| 355 | BIO *bp; | ||
| 356 | { | ||
| 357 | BIGNUM *a,*b,*c; | ||
| 358 | int i; | ||
| 359 | int j; | ||
| 360 | |||
| 361 | a=BN_new(); | ||
| 362 | b=BN_new(); | ||
| 363 | c=BN_new(); | ||
| 364 | |||
| 365 | BN_rand(a,200,0,0); | ||
| 366 | for (i=0; i<100; i++) | ||
| 367 | { | ||
| 368 | BN_rand(b,250+i,0,0); | ||
| 369 | a->neg=rand_neg(); | ||
| 370 | b->neg=rand_neg(); | ||
| 371 | if (bp == NULL) | ||
| 372 | for (j=0; j<100; j++) | ||
| 373 | BN_mul(c,a,b); | ||
| 374 | BN_mul(c,a,b); | ||
| 375 | if (bp != NULL) | ||
| 376 | { | ||
| 377 | if (!results) | ||
| 378 | { | ||
| 379 | BN_print(bp,a); | ||
| 380 | BIO_puts(bp," * "); | ||
| 381 | BN_print(bp,b); | ||
| 382 | BIO_puts(bp," - "); | ||
| 383 | } | ||
| 384 | BN_print(bp,c); | ||
| 385 | BIO_puts(bp,"\n"); | ||
| 386 | } | ||
| 387 | } | ||
| 388 | BN_free(a); | ||
| 389 | BN_free(b); | ||
| 390 | BN_free(c); | ||
| 391 | return(1); | ||
| 392 | } | ||
| 393 | |||
| 394 | int test_sqr(bp,ctx) | ||
| 395 | BIO *bp; | ||
| 396 | BN_CTX *ctx; | ||
| 397 | { | ||
| 398 | BIGNUM *a,*c; | ||
| 399 | int i; | ||
| 400 | int j; | ||
| 401 | |||
| 402 | a=BN_new(); | ||
| 403 | c=BN_new(); | ||
| 404 | |||
| 405 | for (i=0; i<40; i++) | ||
| 406 | { | ||
| 407 | BN_rand(a,40+i*10,0,0); | ||
| 408 | a->neg=rand_neg(); | ||
| 409 | if (bp == NULL) | ||
| 410 | for (j=0; j<100; j++) | ||
| 411 | BN_sqr(c,a,ctx); | ||
| 412 | BN_sqr(c,a,ctx); | ||
| 413 | if (bp != NULL) | ||
| 414 | { | ||
| 415 | if (!results) | ||
| 416 | { | ||
| 417 | BN_print(bp,a); | ||
| 418 | BIO_puts(bp," * "); | ||
| 419 | BN_print(bp,a); | ||
| 420 | BIO_puts(bp," - "); | ||
| 421 | } | ||
| 422 | BN_print(bp,c); | ||
| 423 | BIO_puts(bp,"\n"); | ||
| 424 | } | ||
| 425 | } | ||
| 426 | BN_free(a); | ||
| 427 | BN_free(c); | ||
| 428 | return(1); | ||
| 429 | } | ||
| 430 | |||
| 431 | int test_mont(bp,ctx) | ||
| 432 | BIO *bp; | ||
| 433 | BN_CTX *ctx; | ||
| 434 | { | ||
| 435 | BIGNUM *a,*b,*c,*A,*B; | ||
| 436 | BIGNUM *n; | ||
| 437 | int i; | ||
| 438 | int j; | ||
| 439 | BN_MONT_CTX *mont; | ||
| 440 | |||
| 441 | a=BN_new(); | ||
| 442 | b=BN_new(); | ||
| 443 | c=BN_new(); | ||
| 444 | A=BN_new(); | ||
| 445 | B=BN_new(); | ||
| 446 | n=BN_new(); | ||
| 447 | |||
| 448 | mont=BN_MONT_CTX_new(); | ||
| 449 | |||
| 450 | BN_rand(a,100,0,0); /**/ | ||
| 451 | BN_rand(b,100,0,0); /**/ | ||
| 452 | for (i=0; i<10; i++) | ||
| 453 | { | ||
| 454 | BN_rand(n,(100%BN_BITS2+1)*BN_BITS2*i*BN_BITS2,0,1); /**/ | ||
| 455 | BN_MONT_CTX_set(mont,n,ctx); | ||
| 456 | |||
| 457 | BN_to_montgomery(A,a,mont,ctx); | ||
| 458 | BN_to_montgomery(B,b,mont,ctx); | ||
| 459 | |||
| 460 | if (bp == NULL) | ||
| 461 | for (j=0; j<100; j++) | ||
| 462 | BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/ | ||
| 463 | BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/ | ||
| 464 | BN_from_montgomery(A,c,mont,ctx);/**/ | ||
| 465 | if (bp != NULL) | ||
| 466 | { | ||
| 467 | if (!results) | ||
| 468 | { | ||
| 469 | #ifdef undef | ||
| 470 | fprintf(stderr,"%d * %d %% %d\n", | ||
| 471 | BN_num_bits(a), | ||
| 472 | BN_num_bits(b), | ||
| 473 | BN_num_bits(mont->N)); | ||
| 474 | #endif | ||
| 475 | BN_print(bp,a); | ||
| 476 | BIO_puts(bp," * "); | ||
| 477 | BN_print(bp,b); | ||
| 478 | BIO_puts(bp," % "); | ||
| 479 | BN_print(bp,mont->N); | ||
| 480 | BIO_puts(bp," - "); | ||
| 481 | } | ||
| 482 | BN_print(bp,A); | ||
| 483 | BIO_puts(bp,"\n"); | ||
| 484 | } | ||
| 485 | } | ||
| 486 | BN_MONT_CTX_free(mont); | ||
| 487 | BN_free(a); | ||
| 488 | BN_free(b); | ||
| 489 | BN_free(c); | ||
| 490 | return(1); | ||
| 491 | } | ||
| 492 | |||
| 493 | int test_mod(bp,ctx) | ||
| 494 | BIO *bp; | ||
| 495 | BN_CTX *ctx; | ||
| 496 | { | ||
| 497 | BIGNUM *a,*b,*c; | ||
| 498 | int i; | ||
| 499 | int j; | ||
| 500 | |||
| 501 | a=BN_new(); | ||
| 502 | b=BN_new(); | ||
| 503 | c=BN_new(); | ||
| 504 | |||
| 505 | BN_rand(a,1024,0,0); /**/ | ||
| 506 | for (i=0; i<20; i++) | ||
| 507 | { | ||
| 508 | BN_rand(b,450+i*10,0,0); /**/ | ||
| 509 | a->neg=rand_neg(); | ||
| 510 | b->neg=rand_neg(); | ||
| 511 | if (bp == NULL) | ||
| 512 | for (j=0; j<100; j++) | ||
| 513 | BN_mod(c,a,b,ctx);/**/ | ||
| 514 | BN_mod(c,a,b,ctx);/**/ | ||
| 515 | if (bp != NULL) | ||
| 516 | { | ||
| 517 | if (!results) | ||
| 518 | { | ||
| 519 | BN_print(bp,a); | ||
| 520 | BIO_puts(bp," % "); | ||
| 521 | BN_print(bp,b); | ||
| 522 | BIO_puts(bp," - "); | ||
| 523 | } | ||
| 524 | BN_print(bp,c); | ||
| 525 | BIO_puts(bp,"\n"); | ||
| 526 | } | ||
| 527 | } | ||
| 528 | BN_free(a); | ||
| 529 | BN_free(b); | ||
| 530 | BN_free(c); | ||
| 531 | return(1); | ||
| 532 | } | ||
| 533 | |||
| 534 | int test_mod_mul(bp,ctx) | ||
| 535 | BIO *bp; | ||
| 536 | BN_CTX *ctx; | ||
| 537 | { | ||
| 538 | BIGNUM *a,*b,*c,*d,*e; | ||
| 539 | int i; | ||
| 540 | |||
| 541 | a=BN_new(); | ||
| 542 | b=BN_new(); | ||
| 543 | c=BN_new(); | ||
| 544 | d=BN_new(); | ||
| 545 | e=BN_new(); | ||
| 546 | |||
| 547 | BN_rand(c,1024,0,0); /**/ | ||
| 548 | for (i=0; i<10; i++) | ||
| 549 | { | ||
| 550 | BN_rand(a,475+i*10,0,0); /**/ | ||
| 551 | BN_rand(b,425+i*10,0,0); /**/ | ||
| 552 | a->neg=rand_neg(); | ||
| 553 | b->neg=rand_neg(); | ||
| 554 | /* if (bp == NULL) | ||
| 555 | for (j=0; j<100; j++) | ||
| 556 | BN_mod_mul(d,a,b,c,ctx);*/ /**/ | ||
| 557 | |||
| 558 | if (!BN_mod_mul(e,a,b,c,ctx)) | ||
| 559 | { | ||
| 560 | unsigned long l; | ||
| 561 | |||
| 562 | while ((l=ERR_get_error())) | ||
| 563 | fprintf(stderr,"ERROR:%s\n", | ||
| 564 | ERR_error_string(l,NULL)); | ||
| 565 | exit(1); | ||
| 566 | } | ||
| 567 | if (bp != NULL) | ||
| 568 | { | ||
| 569 | if (!results) | ||
| 570 | { | ||
| 571 | BN_print(bp,a); | ||
| 572 | BIO_puts(bp," * "); | ||
| 573 | BN_print(bp,b); | ||
| 574 | BIO_puts(bp," % "); | ||
| 575 | BN_print(bp,c); | ||
| 576 | BIO_puts(bp," - "); | ||
| 577 | } | ||
| 578 | BN_print(bp,e); | ||
| 579 | BIO_puts(bp,"\n"); | ||
| 580 | } | ||
| 581 | } | ||
| 582 | BN_free(a); | ||
| 583 | BN_free(b); | ||
| 584 | BN_free(c); | ||
| 585 | BN_free(d); | ||
| 586 | BN_free(e); | ||
| 587 | return(1); | ||
| 588 | } | ||
| 589 | |||
| 590 | int test_mod_exp(bp,ctx) | ||
| 591 | BIO *bp; | ||
| 592 | BN_CTX *ctx; | ||
| 593 | { | ||
| 594 | BIGNUM *a,*b,*c,*d,*e; | ||
| 595 | int i; | ||
| 596 | |||
| 597 | a=BN_new(); | ||
| 598 | b=BN_new(); | ||
| 599 | c=BN_new(); | ||
| 600 | d=BN_new(); | ||
| 601 | e=BN_new(); | ||
| 602 | |||
| 603 | BN_rand(c,30,0,1); /* must be odd for montgomery */ | ||
| 604 | for (i=0; i<6; i++) | ||
| 605 | { | ||
| 606 | BN_rand(a,20+i*5,0,0); /**/ | ||
| 607 | BN_rand(b,2+i,0,0); /**/ | ||
| 608 | |||
| 609 | if (!BN_mod_exp(d,a,b,c,ctx)) | ||
| 610 | return(00); | ||
| 611 | |||
| 612 | if (bp != NULL) | ||
| 613 | { | ||
| 614 | if (!results) | ||
| 615 | { | ||
| 616 | BN_print(bp,a); | ||
| 617 | BIO_puts(bp," ^ "); | ||
| 618 | BN_print(bp,b); | ||
| 619 | BIO_puts(bp," % "); | ||
| 620 | BN_print(bp,c); | ||
| 621 | BIO_puts(bp," - "); | ||
| 622 | } | ||
| 623 | BN_print(bp,d); | ||
| 624 | BIO_puts(bp,"\n"); | ||
| 625 | } | ||
| 626 | } | ||
| 627 | BN_free(a); | ||
| 628 | BN_free(b); | ||
| 629 | BN_free(c); | ||
| 630 | BN_free(d); | ||
| 631 | BN_free(e); | ||
| 632 | return(1); | ||
| 633 | } | ||
| 634 | |||
| 635 | int test_lshift(bp) | ||
| 636 | BIO *bp; | ||
| 637 | { | ||
| 638 | BIGNUM *a,*b,*c; | ||
| 639 | int i; | ||
| 640 | |||
| 641 | a=BN_new(); | ||
| 642 | b=BN_new(); | ||
| 643 | c=BN_new(); | ||
| 644 | BN_one(c); | ||
| 645 | |||
| 646 | BN_rand(a,200,0,0); /**/ | ||
| 647 | a->neg=rand_neg(); | ||
| 648 | for (i=0; i<70; i++) | ||
| 649 | { | ||
| 650 | BN_lshift(b,a,i+1); | ||
| 651 | BN_add(c,c,c); | ||
| 652 | if (bp != NULL) | ||
| 653 | { | ||
| 654 | if (!results) | ||
| 655 | { | ||
| 656 | BN_print(bp,a); | ||
| 657 | BIO_puts(bp," * "); | ||
| 658 | BN_print(bp,c); | ||
| 659 | BIO_puts(bp," - "); | ||
| 660 | } | ||
| 661 | BN_print(bp,b); | ||
| 662 | BIO_puts(bp,"\n"); | ||
| 663 | } | ||
| 664 | } | ||
| 665 | BN_free(a); | ||
| 666 | BN_free(b); | ||
| 667 | BN_free(c); | ||
| 668 | return(1); | ||
| 669 | } | ||
| 670 | |||
| 671 | int test_lshift1(bp) | ||
| 672 | BIO *bp; | ||
| 673 | { | ||
| 674 | BIGNUM *a,*b; | ||
| 675 | int i; | ||
| 676 | |||
| 677 | a=BN_new(); | ||
| 678 | b=BN_new(); | ||
| 679 | |||
| 680 | BN_rand(a,200,0,0); /**/ | ||
| 681 | a->neg=rand_neg(); | ||
| 682 | for (i=0; i<70; i++) | ||
| 683 | { | ||
| 684 | BN_lshift1(b,a); | ||
| 685 | if (bp != NULL) | ||
| 686 | { | ||
| 687 | if (!results) | ||
| 688 | { | ||
| 689 | BN_print(bp,a); | ||
| 690 | BIO_puts(bp," * 2"); | ||
| 691 | BIO_puts(bp," - "); | ||
| 692 | } | ||
| 693 | BN_print(bp,b); | ||
| 694 | BIO_puts(bp,"\n"); | ||
| 695 | } | ||
| 696 | BN_copy(a,b); | ||
| 697 | } | ||
| 698 | BN_free(a); | ||
| 699 | BN_free(b); | ||
| 700 | return(1); | ||
| 701 | } | ||
| 702 | |||
| 703 | int test_rshift(bp) | ||
| 704 | BIO *bp; | ||
| 705 | { | ||
| 706 | BIGNUM *a,*b,*c; | ||
| 707 | int i; | ||
| 708 | |||
| 709 | a=BN_new(); | ||
| 710 | b=BN_new(); | ||
| 711 | c=BN_new(); | ||
| 712 | BN_one(c); | ||
| 713 | |||
| 714 | BN_rand(a,200,0,0); /**/ | ||
| 715 | a->neg=rand_neg(); | ||
| 716 | for (i=0; i<70; i++) | ||
| 717 | { | ||
| 718 | BN_rshift(b,a,i+1); | ||
| 719 | BN_add(c,c,c); | ||
| 720 | if (bp != NULL) | ||
| 721 | { | ||
| 722 | if (!results) | ||
| 723 | { | ||
| 724 | BN_print(bp,a); | ||
| 725 | BIO_puts(bp," / "); | ||
| 726 | BN_print(bp,c); | ||
| 727 | BIO_puts(bp," - "); | ||
| 728 | } | ||
| 729 | BN_print(bp,b); | ||
| 730 | BIO_puts(bp,"\n"); | ||
| 731 | } | ||
| 732 | } | ||
| 733 | BN_free(a); | ||
| 734 | BN_free(b); | ||
| 735 | BN_free(c); | ||
| 736 | return(1); | ||
| 737 | } | ||
| 738 | |||
| 739 | int test_rshift1(bp) | ||
| 740 | BIO *bp; | ||
| 741 | { | ||
| 742 | BIGNUM *a,*b; | ||
| 743 | int i; | ||
| 744 | |||
| 745 | a=BN_new(); | ||
| 746 | b=BN_new(); | ||
| 747 | |||
| 748 | BN_rand(a,200,0,0); /**/ | ||
| 749 | a->neg=rand_neg(); | ||
| 750 | for (i=0; i<70; i++) | ||
| 751 | { | ||
| 752 | BN_rshift1(b,a); | ||
| 753 | if (bp != NULL) | ||
| 754 | { | ||
| 755 | if (!results) | ||
| 756 | { | ||
| 757 | BN_print(bp,a); | ||
| 758 | BIO_puts(bp," / 2"); | ||
| 759 | BIO_puts(bp," - "); | ||
| 760 | } | ||
| 761 | BN_print(bp,b); | ||
| 762 | BIO_puts(bp,"\n"); | ||
| 763 | } | ||
| 764 | BN_copy(a,b); | ||
| 765 | } | ||
| 766 | BN_free(a); | ||
| 767 | BN_free(b); | ||
| 768 | return(1); | ||
| 769 | } | ||
| 770 | |||
| 771 | int rand_neg() | ||
| 772 | { | ||
| 773 | static unsigned int neg=0; | ||
| 774 | static int sign[8]={0,0,0,1,1,0,1,1}; | ||
| 775 | |||
| 776 | return(sign[(neg++)%8]); | ||
| 777 | } | ||
diff --git a/src/lib/libcrypto/bn/expspeed.c b/src/lib/libcrypto/bn/expspeed.c new file mode 100644 index 0000000000..344f883d35 --- /dev/null +++ b/src/lib/libcrypto/bn/expspeed.c | |||
| @@ -0,0 +1,230 @@ | |||
| 1 | /* crypto/bn/expspeed.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 | /* most of this code has been pilfered from my libdes speed.c program */ | ||
| 60 | |||
| 61 | #define BASENUM 5000 | ||
| 62 | #undef PROG | ||
| 63 | #define PROG bnspeed_main | ||
| 64 | |||
| 65 | #include <stdio.h> | ||
| 66 | #include <stdlib.h> | ||
| 67 | #include <signal.h> | ||
| 68 | #include <string.h> | ||
| 69 | #include "crypto.h" | ||
| 70 | #include "err.h" | ||
| 71 | |||
| 72 | #ifndef MSDOS | ||
| 73 | #define TIMES | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #ifndef VMS | ||
| 77 | #ifndef _IRIX | ||
| 78 | #include <time.h> | ||
| 79 | #endif | ||
| 80 | #ifdef TIMES | ||
| 81 | #include <sys/types.h> | ||
| 82 | #include <sys/times.h> | ||
| 83 | #endif | ||
| 84 | #else /* VMS */ | ||
| 85 | #include <types.h> | ||
| 86 | struct tms { | ||
| 87 | time_t tms_utime; | ||
| 88 | time_t tms_stime; | ||
| 89 | time_t tms_uchild; /* I dunno... */ | ||
| 90 | time_t tms_uchildsys; /* so these names are a guess :-) */ | ||
| 91 | } | ||
| 92 | #endif | ||
| 93 | #ifndef TIMES | ||
| 94 | #include <sys/timeb.h> | ||
| 95 | #endif | ||
| 96 | |||
| 97 | #ifdef sun | ||
| 98 | #include <limits.h> | ||
| 99 | #include <sys/param.h> | ||
| 100 | #endif | ||
| 101 | |||
| 102 | #include "bn.h" | ||
| 103 | #include "x509.h" | ||
| 104 | |||
| 105 | /* The following if from times(3) man page. It may need to be changed */ | ||
| 106 | #ifndef HZ | ||
| 107 | # ifndef CLK_TCK | ||
| 108 | # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ | ||
| 109 | # ifndef VMS | ||
| 110 | # define HZ 100.0 | ||
| 111 | # else /* VMS */ | ||
| 112 | # define HZ 100.0 | ||
| 113 | # endif | ||
| 114 | # else /* _BSD_CLK_TCK_ */ | ||
| 115 | # define HZ ((double)_BSD_CLK_TCK_) | ||
| 116 | # endif | ||
| 117 | # else /* CLK_TCK */ | ||
| 118 | # define HZ ((double)CLK_TCK) | ||
| 119 | # endif | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #undef BUFSIZE | ||
| 123 | #define BUFSIZE ((long)1024*8) | ||
| 124 | int run=0; | ||
| 125 | |||
| 126 | #ifndef NOPROTO | ||
| 127 | static double Time_F(int s); | ||
| 128 | #else | ||
| 129 | static double Time_F(); | ||
| 130 | #endif | ||
| 131 | |||
| 132 | #define START 0 | ||
| 133 | #define STOP 1 | ||
| 134 | |||
| 135 | static double Time_F(s) | ||
| 136 | int s; | ||
| 137 | { | ||
| 138 | double ret; | ||
| 139 | #ifdef TIMES | ||
| 140 | static struct tms tstart,tend; | ||
| 141 | |||
| 142 | if (s == START) | ||
| 143 | { | ||
| 144 | times(&tstart); | ||
| 145 | return(0); | ||
| 146 | } | ||
| 147 | else | ||
| 148 | { | ||
| 149 | times(&tend); | ||
| 150 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
| 151 | return((ret < 1e-3)?1e-3:ret); | ||
| 152 | } | ||
| 153 | #else /* !times() */ | ||
| 154 | static struct timeb tstart,tend; | ||
| 155 | long i; | ||
| 156 | |||
| 157 | if (s == START) | ||
| 158 | { | ||
| 159 | ftime(&tstart); | ||
| 160 | return(0); | ||
| 161 | } | ||
| 162 | else | ||
| 163 | { | ||
| 164 | ftime(&tend); | ||
| 165 | i=(long)tend.millitm-(long)tstart.millitm; | ||
| 166 | ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; | ||
| 167 | return((ret < 0.001)?0.001:ret); | ||
| 168 | } | ||
| 169 | #endif | ||
| 170 | } | ||
| 171 | |||
| 172 | #define NUM_SIZES 6 | ||
| 173 | static int sizes[NUM_SIZES]={256,512,1024,2048,4096,8192}; | ||
| 174 | static int mul_c[NUM_SIZES]={8*8*8*8*8,8*8*8*8,8*8*8,8*8,8,1}; | ||
| 175 | /*static int sizes[NUM_SIZES]={59,179,299,419,539}; */ | ||
| 176 | |||
| 177 | void do_mul_exp(BIGNUM *r,BIGNUM *a,BIGNUM *b,BIGNUM *c,BN_CTX *ctx); | ||
| 178 | |||
| 179 | int main(argc,argv) | ||
| 180 | int argc; | ||
| 181 | char **argv; | ||
| 182 | { | ||
| 183 | BN_CTX *ctx; | ||
| 184 | BIGNUM *a,*b,*c,*r; | ||
| 185 | |||
| 186 | ctx=BN_CTX_new(); | ||
| 187 | a=BN_new(); | ||
| 188 | b=BN_new(); | ||
| 189 | c=BN_new(); | ||
| 190 | r=BN_new(); | ||
| 191 | |||
| 192 | do_mul_exp(r,a,b,c,ctx); | ||
| 193 | } | ||
| 194 | |||
| 195 | void do_mul_exp(r,a,b,c,ctx) | ||
| 196 | BIGNUM *r; | ||
| 197 | BIGNUM *a; | ||
| 198 | BIGNUM *b; | ||
| 199 | BIGNUM *c; | ||
| 200 | BN_CTX *ctx; | ||
| 201 | { | ||
| 202 | int i,k; | ||
| 203 | double tm; | ||
| 204 | long num; | ||
| 205 | BN_MONT_CTX m; | ||
| 206 | |||
| 207 | memset(&m,0,sizeof(m)); | ||
| 208 | |||
| 209 | num=BASENUM; | ||
| 210 | for (i=0; i<NUM_SIZES; i++) | ||
| 211 | { | ||
| 212 | BN_rand(a,sizes[i],1,0); | ||
| 213 | BN_rand(b,sizes[i],1,0); | ||
| 214 | BN_rand(c,sizes[i],1,1); | ||
| 215 | BN_mod(a,a,c,ctx); | ||
| 216 | BN_mod(b,b,c,ctx); | ||
| 217 | |||
| 218 | BN_MONT_CTX_set(&m,c,ctx); | ||
| 219 | |||
| 220 | Time_F(START); | ||
| 221 | for (k=0; k<num; k++) | ||
| 222 | BN_mod_exp_mont(r,a,b,c,ctx,&m); | ||
| 223 | tm=Time_F(STOP); | ||
| 224 | printf("mul %4d ^ %4d %% %d -> %8.3fms %5.1f\n",sizes[i],sizes[i],sizes[i],tm*1000.0/num,tm*mul_c[i]/num); | ||
| 225 | num/=7; | ||
| 226 | if (num <= 0) num=1; | ||
| 227 | } | ||
| 228 | |||
| 229 | } | ||
| 230 | |||
diff --git a/src/lib/libcrypto/bn/exptest.c b/src/lib/libcrypto/bn/exptest.c new file mode 100644 index 0000000000..67dc95d726 --- /dev/null +++ b/src/lib/libcrypto/bn/exptest.c | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | /* crypto/bn/exptest.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 <stdlib.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include "bio.h" | ||
| 63 | #include "bn.h" | ||
| 64 | #include "rand.h" | ||
| 65 | #include "err.h" | ||
| 66 | #ifdef WINDOWS | ||
| 67 | #include "../bio/bss_file.c" | ||
| 68 | #endif | ||
| 69 | |||
| 70 | #define NUM_BITS (BN_BITS*2) | ||
| 71 | |||
| 72 | int main(argc,argv) | ||
| 73 | int argc; | ||
| 74 | char *argv[]; | ||
| 75 | { | ||
| 76 | BN_CTX *ctx; | ||
| 77 | BIO *out=NULL; | ||
| 78 | int i,ret; | ||
| 79 | unsigned char c; | ||
| 80 | BIGNUM *r_mont,*r_recp,*a,*b,*m; | ||
| 81 | |||
| 82 | ctx=BN_CTX_new(); | ||
| 83 | if (ctx == NULL) exit(1); | ||
| 84 | r_mont=BN_new(); | ||
| 85 | r_recp=BN_new(); | ||
| 86 | a=BN_new(); | ||
| 87 | b=BN_new(); | ||
| 88 | m=BN_new(); | ||
| 89 | if ( (r_mont == NULL) || (r_recp == NULL) || | ||
| 90 | (a == NULL) || (b == NULL)) | ||
| 91 | goto err; | ||
| 92 | |||
| 93 | out=BIO_new(BIO_s_file()); | ||
| 94 | |||
| 95 | if (out == NULL) exit(1); | ||
| 96 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | ||
| 97 | |||
| 98 | for (i=0; i<200; i++) | ||
| 99 | { | ||
| 100 | RAND_bytes(&c,1); | ||
| 101 | c=(c%BN_BITS)-BN_BITS2; | ||
| 102 | BN_rand(a,NUM_BITS+c,0,0); | ||
| 103 | |||
| 104 | RAND_bytes(&c,1); | ||
| 105 | c=(c%BN_BITS)-BN_BITS2; | ||
| 106 | BN_rand(b,NUM_BITS+c,0,0); | ||
| 107 | |||
| 108 | RAND_bytes(&c,1); | ||
| 109 | c=(c%BN_BITS)-BN_BITS2; | ||
| 110 | BN_rand(m,NUM_BITS+c,0,1); | ||
| 111 | |||
| 112 | BN_mod(a,a,m,ctx); | ||
| 113 | BN_mod(b,b,m,ctx); | ||
| 114 | |||
| 115 | ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL); | ||
| 116 | if (ret <= 0) | ||
| 117 | { printf("BN_mod_exp_mont() problems\n"); exit(1); } | ||
| 118 | |||
| 119 | ret=BN_mod_exp_recp(r_recp,a,b,m,ctx); | ||
| 120 | if (ret <= 0) | ||
| 121 | { printf("BN_mod_exp_recp() problems\n"); exit(1); } | ||
| 122 | |||
| 123 | if (BN_cmp(r_mont,r_recp) != 0) | ||
| 124 | { | ||
| 125 | printf("\nmont and recp results differ\n"); | ||
| 126 | printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a); | ||
| 127 | printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b); | ||
| 128 | printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m); | ||
| 129 | printf("\nrecp ="); BN_print(out,r_recp); | ||
| 130 | printf("\nmont ="); BN_print(out,r_mont); | ||
| 131 | printf("\n"); | ||
| 132 | exit(1); | ||
| 133 | } | ||
| 134 | else | ||
| 135 | { | ||
| 136 | printf("."); | ||
| 137 | fflush(stdout); | ||
| 138 | } | ||
| 139 | } | ||
| 140 | printf(" done\n"); | ||
| 141 | exit(0); | ||
| 142 | err: | ||
| 143 | ERR_load_crypto_strings(); | ||
| 144 | ERR_print_errors(out); | ||
| 145 | exit(1); | ||
| 146 | return(1); | ||
| 147 | } | ||
| 148 | |||
