| 7 | .section .rodata |
| 8 | .align 5 |
| 9 | .Lpoly: |
| 10 | .quad 0xffffffffffffffff,0x00000000ffffffff,0x0000000000000000,0xffffffff00000001 |
| 11 | .LRR: // 2^512 mod P precomputed for NIST P256 polynomial |
| 12 | .quad 0x0000000000000003,0xfffffffbffffffff,0xfffffffffffffffe,0x00000004fffffffd |
| 13 | .Lone_mont: |
| 14 | .quad 0x0000000000000001,0xffffffff00000000,0xffffffffffffffff,0x00000000fffffffe |
| 15 | .Lone: |
| 16 | .quad 1,0,0,0 |
| 17 | .Lord: |
| 18 | .quad 0xf3b9cac2fc632551,0xbce6faada7179e84,0xffffffffffffffff,0xffffffff00000000 |
| 19 | .LordK: |
| 20 | .quad 0xccd1c8aaee00bc4f |
| 21 | .byte 69,67,80,95,78,73,83,84,90,50,53,54,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 |
| 22 | .align 2 |
| 23 | .text |
| 24 |
| 25 | // void ecp_nistz256_mul_mont(BN_ULONG x0[4],const BN_ULONG x1[4], |
| 26 | // const BN_ULONG x2[4]); |
| 27 | .globl ecp_nistz256_mul_mont |
| 28 | .hidden ecp_nistz256_mul_mont |
| 29 | .type ecp_nistz256_mul_mont,%function |
| 30 | .align 4 |
| 31 | ecp_nistz256_mul_mont: |
| 32 | AARCH64_SIGN_LINK_REGISTER |
| 33 | stp x29,x30,[sp,#-32]! |
| 34 | add x29,sp,#0 |
| 35 | stp x19,x20,[sp,#16] |
| 36 |
| 37 | ldr x3,[x2] // bp[0] |
| 38 | ldp x4,x5,[x1] |
| 39 | ldp x6,x7,[x1,#16] |
| 40 | adrp x13,.Lpoly |
| 41 | add x13,x13,:lo12:.Lpoly |
| 42 | ldr x12,[x13,#8] |
| 43 | ldr x13,[x13,#24] |
| 44 |
| 45 | bl __ecp_nistz256_mul_mont |
| 46 |
| 47 | ldp x19,x20,[sp,#16] |
| 48 | ldp x29,x30,[sp],#32 |
| 49 | AARCH64_VALIDATE_LINK_REGISTER |
| 50 | ret |
| 51 | .size ecp_nistz256_mul_mont,.-ecp_nistz256_mul_mont |
| 52 |
| 53 | // void ecp_nistz256_sqr_mont(BN_ULONG x0[4],const BN_ULONG x1[4]); |
| 54 | .globl ecp_nistz256_sqr_mont |
| 55 | .hidden ecp_nistz256_sqr_mont |
| 56 | .type ecp_nistz256_sqr_mont,%function |
| 57 | .align 4 |
| 58 | ecp_nistz256_sqr_mont: |
| 59 | AARCH64_SIGN_LINK_REGISTER |
| 60 | stp x29,x30,[sp,#-32]! |
| 61 | add x29,sp,#0 |
| 62 | stp x19,x20,[sp,#16] |
| 63 |
| 64 | ldp x4,x5,[x1] |
| 65 | ldp x6,x7,[x1,#16] |
| 66 | adrp x13,.Lpoly |
| 67 | add x13,x13,:lo12:.Lpoly |
| 68 | ldr x12,[x13,#8] |
| 69 | ldr x13,[x13,#24] |
| 70 |
| 71 | bl __ecp_nistz256_sqr_mont |
| 72 |
| 73 | ldp x19,x20,[sp,#16] |
| 74 | ldp x29,x30,[sp],#32 |
| 75 | AARCH64_VALIDATE_LINK_REGISTER |
| 76 | ret |
| 77 | .size ecp_nistz256_sqr_mont,.-ecp_nistz256_sqr_mont |
| 78 |
| 79 | // void ecp_nistz256_div_by_2(BN_ULONG x0[4],const BN_ULONG x1[4]); |
| 80 | .globl ecp_nistz256_div_by_2 |
| 81 | .hidden ecp_nistz256_div_by_2 |
| 82 | .type ecp_nistz256_div_by_2,%function |
| 83 | .align 4 |
| 84 | ecp_nistz256_div_by_2: |
| 85 | AARCH64_SIGN_LINK_REGISTER |
| 86 | stp x29,x30,[sp,#-16]! |
| 87 | add x29,sp,#0 |
| 88 |
| 89 | ldp x14,x15,[x1] |
| 90 | ldp x16,x17,[x1,#16] |
| 91 | adrp x13,.Lpoly |
| 92 | add x13,x13,:lo12:.Lpoly |
| 93 | ldr x12,[x13,#8] |
| 94 | ldr x13,[x13,#24] |
| 95 |
| 96 | bl __ecp_nistz256_div_by_2 |
| 97 |
| 98 | ldp x29,x30,[sp],#16 |
| 99 | AARCH64_VALIDATE_LINK_REGISTER |
| 100 | ret |
| 101 | .size ecp_nistz256_div_by_2,.-ecp_nistz256_div_by_2 |
| 102 |
| 103 | // void ecp_nistz256_mul_by_2(BN_ULONG x0[4],const BN_ULONG x1[4]); |
| 104 | .globl ecp_nistz256_mul_by_2 |
| 105 | .hidden ecp_nistz256_mul_by_2 |
| 106 | .type ecp_nistz256_mul_by_2,%function |
| 107 | .align 4 |
| 108 | ecp_nistz256_mul_by_2: |
| 109 | AARCH64_SIGN_LINK_REGISTER |
| 110 | stp x29,x30,[sp,#-16]! |
| 111 | add x29,sp,#0 |
| 112 |
| 113 | ldp x14,x15,[x1] |
| 114 | ldp x16,x17,[x1,#16] |
| 115 | adrp x13,.Lpoly |
| 116 | add x13,x13,:lo12:.Lpoly |
| 117 | ldr x12,[x13,#8] |
| 118 | ldr x13,[x13,#24] |
| 119 | mov x8,x14 |
| 120 | mov x9,x15 |
| 121 | mov x10,x16 |
| 122 | mov x11,x17 |
| 123 |
| 124 | bl __ecp_nistz256_add_to // ret = a+a // 2*a |
| 125 |
| 126 | ldp x29,x30,[sp],#16 |
| 127 | AARCH64_VALIDATE_LINK_REGISTER |
| 128 | ret |
| 129 | .size ecp_nistz256_mul_by_2,.-ecp_nistz256_mul_by_2 |
| 130 |
| 131 | // void ecp_nistz256_mul_by_3(BN_ULONG x0[4],const BN_ULONG x1[4]); |
| 132 | .globl ecp_nistz256_mul_by_3 |
| 133 | .hidden ecp_nistz256_mul_by_3 |
| 134 | .type ecp_nistz256_mul_by_3,%function |
| 135 | .align 4 |
| 136 | ecp_nistz256_mul_by_3: |
| 137 | AARCH64_SIGN_LINK_REGISTER |
| 138 | stp x29,x30,[sp,#-16]! |
| 139 | add x29,sp,#0 |
| 140 |
| 141 | ldp x14,x15,[x1] |
| 142 | ldp x16,x17,[x1,#16] |
| 143 | adrp x13,.Lpoly |
| 144 | add x13,x13,:lo12:.Lpoly |
| 145 | ldr x12,[x13,#8] |
| 146 | ldr x13,[x13,#24] |
| 147 | mov x8,x14 |
| 148 | mov x9,x15 |
| 149 | mov x10,x16 |
| 150 | mov x11,x17 |
| 151 | mov x4,x14 |
| 152 | mov x5,x15 |
| 153 | mov x6,x16 |
| 154 | mov x7,x17 |
| 155 |
| 156 | bl __ecp_nistz256_add_to // ret = a+a // 2*a |
| 157 |
| 158 | mov x8,x4 |
| 159 | mov x9,x5 |
| 160 | mov x10,x6 |
| 161 | mov x11,x7 |
| 162 |
| 163 | bl __ecp_nistz256_add_to // ret += a // 2*a+a=3*a |
| 164 |
| 165 | ldp x29,x30,[sp],#16 |
| 166 | AARCH64_VALIDATE_LINK_REGISTER |
| 167 | ret |
| 168 | .size ecp_nistz256_mul_by_3,.-ecp_nistz256_mul_by_3 |
| 169 |
| 170 | // void ecp_nistz256_sub(BN_ULONG x0[4],const BN_ULONG x1[4], |
| 171 | // const BN_ULONG x2[4]); |
| 172 | .globl ecp_nistz256_sub |
| 173 | .hidden ecp_nistz256_sub |
| 174 | .type ecp_nistz256_sub,%function |
| 175 | .align 4 |
| 176 | ecp_nistz256_sub: |
| 177 | AARCH64_SIGN_LINK_REGISTER |
| 178 | stp x29,x30,[sp,#-16]! |
| 179 | add x29,sp,#0 |
| 180 |
| 181 | ldp x14,x15,[x1] |
| 182 | ldp x16,x17,[x1,#16] |
| 183 | adrp x13,.Lpoly |
| 184 | add x13,x13,:lo12:.Lpoly |
| 185 | ldr x12,[x13,#8] |
| 186 | ldr x13,[x13,#24] |
| 187 |
| 188 | bl __ecp_nistz256_sub_from |
| 189 |
| 190 | ldp x29,x30,[sp],#16 |
| 191 | AARCH64_VALIDATE_LINK_REGISTER |
| 192 | ret |
| 193 | .size ecp_nistz256_sub,.-ecp_nistz256_sub |
| 194 |
| 195 | // void ecp_nistz256_neg(BN_ULONG x0[4],const BN_ULONG x1[4]); |
| 196 | .globl ecp_nistz256_neg |
| 197 | .hidden ecp_nistz256_neg |
| 198 | .type ecp_nistz256_neg,%function |
| 199 | .align 4 |
| 200 | ecp_nistz256_neg: |
| 201 | AARCH64_SIGN_LINK_REGISTER |
| 202 | stp x29,x30,[sp,#-16]! |
| 203 | add x29,sp,#0 |
| 204 |
| 205 | mov x2,x1 |
| 206 | mov x14,xzr // a = 0 |
| 207 | mov x15,xzr |
| 208 | mov x16,xzr |
| 209 | mov x17,xzr |
| 210 | adrp x13,.Lpoly |
| 211 | add x13,x13,:lo12:.Lpoly |
| 212 | ldr x12,[x13,#8] |
| 213 | ldr x13,[x13,#24] |
| 214 |
| 215 | bl __ecp_nistz256_sub_from |
| 216 |
| 217 | ldp x29,x30,[sp],#16 |
| 218 | AARCH64_VALIDATE_LINK_REGISTER |
| 219 | ret |
| 220 | .size ecp_nistz256_neg,.-ecp_nistz256_neg |
| 221 |
| 222 | // note that __ecp_nistz256_mul_mont expects a[0-3] input pre-loaded |
| 223 | // to x4-x7 and b[0] - to x3 |
| 224 | .type __ecp_nistz256_mul_mont,%function |
| 225 | .align 4 |
| 226 | __ecp_nistz256_mul_mont: |
| 227 | mul x14,x4,x3 // a[0]*b[0] |
| 228 | umulh x8,x4,x3 |
| 229 |
| 230 | mul x15,x5,x3 // a[1]*b[0] |
| 231 | umulh x9,x5,x3 |
| 232 |
| 233 | mul x16,x6,x3 // a[2]*b[0] |
| 234 | umulh x10,x6,x3 |
| 235 |
| 236 | mul x17,x7,x3 // a[3]*b[0] |
| 237 | umulh x11,x7,x3 |
| 238 | ldr x3,[x2,#8] // b[1] |
| 239 |
| 240 | adds x15,x15,x8 // accumulate high parts of multiplication |
| 241 | lsl x8,x14,#32 |
| 242 | adcs x16,x16,x9 |
| 243 | lsr x9,x14,#32 |
| 244 | adcs x17,x17,x10 |
| 245 | adc x19,xzr,x11 |
| 246 | mov x20,xzr |
| 247 | subs x10,x14,x8 // "*0xffff0001" |
| 248 | sbc x11,x14,x9 |
| 249 | adds x14,x15,x8 // +=acc[0]<<96 and omit acc[0] |
| 250 | mul x8,x4,x3 // lo(a[0]*b[i]) |
| 251 | adcs x15,x16,x9 |
| 252 | mul x9,x5,x3 // lo(a[1]*b[i]) |
| 253 | adcs x16,x17,x10 // +=acc[0]*0xffff0001 |
| 254 | mul x10,x6,x3 // lo(a[2]*b[i]) |
| 255 | adcs x17,x19,x11 |
| 256 | mul x11,x7,x3 // lo(a[3]*b[i]) |
| 257 | adc x19,x20,xzr |
| 258 |
| 259 | adds x14,x14,x8 // accumulate low parts of multiplication |
| 260 | umulh x8,x4,x3 // hi(a[0]*b[i]) |
| 261 | adcs x15,x15,x9 |
| 262 | umulh x9,x5,x3 // hi(a[1]*b[i]) |
| 263 | adcs x16,x16,x10 |
| 264 | umulh x10,x6,x3 // hi(a[2]*b[i]) |
| 265 | adcs x17,x17,x11 |
| 266 | umulh x11,x7,x3 // hi(a[3]*b[i]) |
| 267 | adc x19,x19,xzr |
| 268 | ldr x3,[x2,#8*(1+1)] // b[1+1] |
| 269 | adds x15,x15,x8 // accumulate high parts of multiplication |
| 270 | lsl x8,x14,#32 |
| 271 | adcs x16,x16,x9 |
| 272 | lsr x9,x14,#32 |
| 273 | adcs x17,x17,x10 |
| 274 | adcs x19,x19,x11 |
| 275 | adc x20,xzr,xzr |
| 276 | subs x10,x14,x8 // "*0xffff0001" |
| 277 | sbc x11,x14,x9 |
| 278 | adds x14,x15,x8 // +=acc[0]<<96 and omit acc[0] |
| 279 | mul x8,x4,x3 // lo(a[0]*b[i]) |
| 280 | adcs x15,x16,x9 |
| 281 | mul x9,x5,x3 // lo(a[1]*b[i]) |
| 282 | adcs x16,x17,x10 // +=acc[0]*0xffff0001 |
| 283 | mul x10,x6,x3 // lo(a[2]*b[i]) |
| 284 | adcs x17,x19,x11 |
| 285 | mul x11,x7,x3 // lo(a[3]*b[i]) |
| 286 | adc x19,x20,xzr |
| 287 |
| 288 | adds x14,x14,x8 // accumulate low parts of multiplication |
| 289 | umulh x8,x4,x3 // hi(a[0]*b[i]) |
| 290 | adcs x15,x15,x9 |
| 291 | umulh x9,x5,x3 // hi(a[1]*b[i]) |
| 292 | adcs x16,x16,x10 |
| 293 | umulh x10,x6,x3 // hi(a[2]*b[i]) |
| 294 | adcs x17,x17,x11 |
| 295 | umulh x11,x7,x3 // hi(a[3]*b[i]) |
| 296 | adc x19,x19,xzr |
| 297 | ldr x3,[x2,#8*(2+1)] // b[2+1] |
| 298 | adds x15,x15,x8 // accumulate high parts of multiplication |
| 299 | lsl x8,x14,#32 |
| 300 | adcs x16,x16,x9 |
| 301 | lsr x9,x14,#32 |
| 302 | adcs x17,x17,x10 |
| 303 | adcs x19,x19,x11 |
| 304 | adc x20,xzr,xzr |
| 305 | subs x10,x14,x8 // "*0xffff0001" |
| 306 | sbc x11,x14,x9 |
| 307 | adds x14,x15,x8 // +=acc[0]<<96 and omit acc[0] |
| 308 | mul x8,x4,x3 // lo(a[0]*b[i]) |
| 309 | adcs x15,x16,x9 |
| 310 | mul x9,x5,x3 // lo(a[1]*b[i]) |
| 311 | adcs x16,x17,x10 // +=acc[0]*0xffff0001 |
| 312 | mul x10,x6,x3 // lo(a[2]*b[i]) |
| 313 | adcs x17,x19,x11 |
| 314 | mul x11,x7,x3 // lo(a[3]*b[i]) |
| 315 | adc x19,x20,xzr |
| 316 |
| 317 | adds x14,x14,x8 // accumulate low parts of multiplication |
| 318 | umulh x8,x4,x3 // hi(a[0]*b[i]) |
| 319 | adcs x15,x15,x9 |
| 320 | umulh x9,x5,x3 // hi(a[1]*b[i]) |
| 321 | adcs x16,x16,x10 |
| 322 | umulh x10,x6,x3 // hi(a[2]*b[i]) |
| 323 | adcs x17,x17,x11 |
| 324 | umulh x11,x7,x3 // hi(a[3]*b[i]) |
| 325 | adc x19,x19,xzr |
| 326 | adds x15,x15,x8 // accumulate high parts of multiplication |
| 327 | lsl x8,x14,#32 |
| 328 | adcs x16,x16,x9 |
| 329 | lsr x9,x14,#32 |
| 330 | adcs x17,x17,x10 |
| 331 | adcs x19,x19,x11 |
| 332 | adc x20,xzr,xzr |
| 333 | // last reduction |
| 334 | subs x10,x14,x8 // "*0xffff0001" |
| 335 | sbc x11,x14,x9 |
| 336 | adds x14,x15,x8 // +=acc[0]<<96 and omit acc[0] |
| 337 | adcs x15,x16,x9 |
| 338 | adcs x16,x17,x10 // +=acc[0]*0xffff0001 |
| 339 | adcs x17,x19,x11 |
| 340 | adc x19,x20,xzr |
| 341 |
| 342 | adds x8,x14,#1 // subs x8,x14,#-1 // tmp = ret-modulus |
| 343 | sbcs x9,x15,x12 |
| 344 | sbcs x10,x16,xzr |
| 345 | sbcs x11,x17,x13 |
| 346 | sbcs xzr,x19,xzr // did it borrow? |
| 347 |
| 348 | csel x14,x14,x8,lo // ret = borrow ? ret : ret-modulus |
| 349 | csel x15,x15,x9,lo |
| 350 | csel x16,x16,x10,lo |
| 351 | stp x14,x15,[x0] |
| 352 | csel x17,x17,x11,lo |
| 353 | stp x16,x17,[x0,#16] |
| 354 |
| 355 | ret |
| 356 | .size __ecp_nistz256_mul_mont,.-__ecp_nistz256_mul_mont |
| 357 |
| 358 | // note that __ecp_nistz256_sqr_mont expects a[0-3] input pre-loaded |
| 359 | // to x4-x7 |
| 360 | .type __ecp_nistz256_sqr_mont,%function |
| 361 | .align 4 |
| 362 | __ecp_nistz256_sqr_mont: |
| 363 | // | | | | | |a1*a0| | |
| 364 | // | | | | |a2*a0| | | |
| 365 | // | |a3*a2|a3*a0| | | | |
| 366 | // | | | |a2*a1| | | | |
| 367 | // | | |a3*a1| | | | | |
| 368 | // *| | | | | | | | 2| |
| 369 | // +|a3*a3|a2*a2|a1*a1|a0*a0| |
| 370 | // |--+--+--+--+--+--+--+--| |
| 371 | // |A7|A6|A5|A4|A3|A2|A1|A0|, where Ax is , i.e. follow |
| 372 | // |
| 373 | // "can't overflow" below mark carrying into high part of |
| 374 | // multiplication result, which can't overflow, because it |
| 375 | // can never be all ones. |
| 376 |
| 377 | mul x15,x5,x4 // a[1]*a[0] |
| 378 | umulh x9,x5,x4 |
| 379 | mul x16,x6,x4 // a[2]*a[0] |
| 380 | umulh x10,x6,x4 |
| 381 | mul x17,x7,x4 // a[3]*a[0] |
| 382 | umulh x19,x7,x4 |
| 383 |
| 384 | adds x16,x16,x9 // accumulate high parts of multiplication |
| 385 | mul x8,x6,x5 // a[2]*a[1] |
| 386 | umulh x9,x6,x5 |
| 387 | adcs x17,x17,x10 |
| 388 | mul x10,x7,x5 // a[3]*a[1] |
| 389 | umulh x11,x7,x5 |
| 390 | adc x19,x19,xzr // can't overflow |
| 391 |
| 392 | mul x20,x7,x6 // a[3]*a[2] |
| 393 | umulh x1,x7,x6 |
| 394 |
| 395 | adds x9,x9,x10 // accumulate high parts of multiplication |
| 396 | mul x14,x4,x4 // a[0]*a[0] |
| 397 | adc x10,x11,xzr // can't overflow |
| 398 |
| 399 | adds x17,x17,x8 // accumulate low parts of multiplication |
| 400 | umulh x4,x4,x4 |
| 401 | adcs x19,x19,x9 |
| 402 | mul x9,x5,x5 // a[1]*a[1] |
| 403 | adcs x20,x20,x10 |
| 404 | umulh x5,x5,x5 |
| 405 | adc x1,x1,xzr // can't overflow |
| 406 |
| 407 | adds x15,x15,x15 // acc[1-6]*=2 |
| 408 | mul x10,x6,x6 // a[2]*a[2] |
| 409 | adcs x16,x16,x16 |
| 410 | umulh x6,x6,x6 |
| 411 | adcs x17,x17,x17 |
| 412 | mul x11,x7,x7 // a[3]*a[3] |
| 413 | adcs x19,x19,x19 |
| 414 | umulh x7,x7,x7 |
| 415 | adcs x20,x20,x20 |
| 416 | adcs x1,x1,x1 |
| 417 | adc x2,xzr,xzr |
| 418 |
| 419 | adds x15,x15,x4 // +a[i]*a[i] |
| 420 | adcs x16,x16,x9 |
| 421 | adcs x17,x17,x5 |
| 422 | adcs x19,x19,x10 |
| 423 | adcs x20,x20,x6 |
| 424 | lsl x8,x14,#32 |
| 425 | adcs x1,x1,x11 |
| 426 | lsr x9,x14,#32 |
| 427 | adc x2,x2,x7 |
| 428 | subs x10,x14,x8 // "*0xffff0001" |
| 429 | sbc x11,x14,x9 |
| 430 | adds x14,x15,x8 // +=acc[0]<<96 and omit acc[0] |
| 431 | adcs x15,x16,x9 |
| 432 | lsl x8,x14,#32 |
| 433 | adcs x16,x17,x10 // +=acc[0]*0xffff0001 |
| 434 | lsr x9,x14,#32 |
| 435 | adc x17,x11,xzr // can't overflow |
| 436 | subs x10,x14,x8 // "*0xffff0001" |
| 437 | sbc x11,x14,x9 |
| 438 | adds x14,x15,x8 // +=acc[0]<<96 and omit acc[0] |
| 439 | adcs x15,x16,x9 |
| 440 | lsl x8,x14,#32 |
| 441 | adcs x16,x17,x10 // +=acc[0]*0xffff0001 |
| 442 | lsr x9,x14,#32 |
| 443 | adc x17,x11,xzr // can't overflow |
| 444 | subs x10,x14,x8 // "*0xffff0001" |
| 445 | sbc x11,x14,x9 |
| 446 | adds x14,x15,x8 // +=acc[0]<<96 and omit acc[0] |
| 447 | adcs x15,x16,x9 |
| 448 | lsl x8,x14,#32 |
| 449 | adcs x16,x17,x10 // +=acc[0]*0xffff0001 |
| 450 | lsr x9,x14,#32 |
| 451 | adc x17,x11,xzr // can't overflow |
| 452 | subs x10,x14,x8 // "*0xffff0001" |
| 453 | sbc x11,x14,x9 |
| 454 | adds x14,x15,x8 // +=acc[0]<<96 and omit acc[0] |
| 455 | adcs x15,x16,x9 |
| 456 | adcs x16,x17,x10 // +=acc[0]*0xffff0001 |
| 457 | adc x17,x11,xzr // can't overflow |
| 458 |
| 459 | adds x14,x14,x19 // accumulate upper half |
| 460 | adcs x15,x15,x20 |
| 461 | adcs x16,x16,x1 |
| 462 | adcs x17,x17,x2 |
| 463 | adc x19,xzr,xzr |
| 464 |
| 465 | adds x8,x14,#1 // subs x8,x14,#-1 // tmp = ret-modulus |
| 466 | sbcs x9,x15,x12 |
| 467 | sbcs x10,x16,xzr |
| 468 | sbcs x11,x17,x13 |
| 469 | sbcs xzr,x19,xzr // did it borrow? |
| 470 |
| 471 | csel x14,x14,x8,lo // ret = borrow ? ret : ret-modulus |
| 472 | csel x15,x15,x9,lo |
| 473 | csel x16,x16,x10,lo |
| 474 | stp x14,x15,[x0] |
| 475 | csel x17,x17,x11,lo |
| 476 | stp x16,x17,[x0,#16] |
| 477 |
| 478 | ret |
| 479 | .size __ecp_nistz256_sqr_mont,.-__ecp_nistz256_sqr_mont |
| 480 |
| 481 | // Note that __ecp_nistz256_add_to expects both input vectors pre-loaded to |
| 482 | // x4-x7 and x8-x11. This is done because it's used in multiple |
| 483 | // contexts, e.g. in multiplication by 2 and 3... |
| 484 | .type __ecp_nistz256_add_to,%function |
| 485 | .align 4 |
| 486 | __ecp_nistz256_add_to: |
| 487 | adds x14,x14,x8 // ret = a+b |
| 488 | adcs x15,x15,x9 |
| 489 | adcs x16,x16,x10 |
| 490 | adcs x17,x17,x11 |
| 491 | adc x1,xzr,xzr // zap x1 |
| 492 |
| 493 | adds x8,x14,#1 // subs x8,x4,#-1 // tmp = ret-modulus |
| 494 | sbcs x9,x15,x12 |
| 495 | sbcs x10,x16,xzr |
| 496 | sbcs x11,x17,x13 |
| 497 | sbcs xzr,x1,xzr // did subtraction borrow? |
| 498 |
| 499 | csel x14,x14,x8,lo // ret = borrow ? ret : ret-modulus |
| 500 | csel x15,x15,x9,lo |
| 501 | csel x16,x16,x10,lo |
| 502 | stp x14,x15,[x0] |
| 503 | csel x17,x17,x11,lo |
| 504 | stp x16,x17,[x0,#16] |
| 505 |
| 506 | ret |
| 507 | .size __ecp_nistz256_add_to,.-__ecp_nistz256_add_to |
| 508 |
| 509 | .type __ecp_nistz256_sub_from,%function |
| 510 | .align 4 |
| 511 | __ecp_nistz256_sub_from: |
| 512 | ldp x8,x9,[x2] |
| 513 | ldp x10,x11,[x2,#16] |
| 514 | subs x14,x14,x8 // ret = a-b |
| 515 | sbcs x15,x15,x9 |
| 516 | sbcs x16,x16,x10 |
| 517 | sbcs x17,x17,x11 |
| 518 | sbc x1,xzr,xzr // zap x1 |
| 519 |
| 520 | subs x8,x14,#1 // adds x8,x4,#-1 // tmp = ret+modulus |
| 521 | adcs x9,x15,x12 |
| 522 | adcs x10,x16,xzr |
| 523 | adc x11,x17,x13 |
| 524 | cmp x1,xzr // did subtraction borrow? |
| 525 |
| 526 | csel x14,x14,x8,eq // ret = borrow ? ret+modulus : ret |
| 527 | csel x15,x15,x9,eq |
| 528 | csel x16,x16,x10,eq |
| 529 | stp x14,x15,[x0] |
| 530 | csel x17,x17,x11,eq |
| 531 | stp x16,x17,[x0,#16] |
| 532 |
| 533 | ret |
| 534 | .size __ecp_nistz256_sub_from,.-__ecp_nistz256_sub_from |
| 535 |
| 536 | .type __ecp_nistz256_sub_morf,%function |
| 537 | .align 4 |
| 538 | __ecp_nistz256_sub_morf: |
| 539 | ldp x8,x9,[x2] |
| 540 | ldp x10,x11,[x2,#16] |
| 541 | subs x14,x8,x14 // ret = b-a |
| 542 | sbcs x15,x9,x15 |
| 543 | sbcs x16,x10,x16 |
| 544 | sbcs x17,x11,x17 |
| 545 | sbc x1,xzr,xzr // zap x1 |
| 546 |
| 547 | subs x8,x14,#1 // adds x8,x4,#-1 // tmp = ret+modulus |
| 548 | adcs x9,x15,x12 |
| 549 | adcs x10,x16,xzr |
| 550 | adc x11,x17,x13 |
| 551 | cmp x1,xzr // did subtraction borrow? |
| 552 |
| 553 | csel x14,x14,x8,eq // ret = borrow ? ret+modulus : ret |
| 554 | csel x15,x15,x9,eq |
| 555 | csel x16,x16,x10,eq |
| 556 | stp x14,x15,[x0] |
| 557 | csel x17,x17,x11,eq |
| 558 | stp x16,x17,[x0,#16] |
| 559 |
| 560 | ret |
| 561 | .size __ecp_nistz256_sub_morf,.-__ecp_nistz256_sub_morf |
| 562 |
| 563 | .type __ecp_nistz256_div_by_2,%function |
| 564 | .align 4 |
| 565 | __ecp_nistz256_div_by_2: |
| 566 | subs x8,x14,#1 // adds x8,x4,#-1 // tmp = a+modulus |
| 567 | adcs x9,x15,x12 |
| 568 | adcs x10,x16,xzr |
| 569 | adcs x11,x17,x13 |
| 570 | adc x1,xzr,xzr // zap x1 |
| 571 | tst x14,#1 // is a even? |
| 572 |
| 573 | csel x14,x14,x8,eq // ret = even ? a : a+modulus |
| 574 | csel x15,x15,x9,eq |
| 575 | csel x16,x16,x10,eq |
| 576 | csel x17,x17,x11,eq |
| 577 | csel x1,xzr,x1,eq |
| 578 |
| 579 | lsr x14,x14,#1 // ret >>= 1 |
| 580 | orr x14,x14,x15,lsl#63 |
| 581 | lsr x15,x15,#1 |
| 582 | orr x15,x15,x16,lsl#63 |
| 583 | lsr x16,x16,#1 |
| 584 | orr x16,x16,x17,lsl#63 |
| 585 | lsr x17,x17,#1 |
| 586 | stp x14,x15,[x0] |
| 587 | orr x17,x17,x1,lsl#63 |
| 588 | stp x16,x17,[x0,#16] |
| 589 |
| 590 | ret |
| 591 | .size __ecp_nistz256_div_by_2,.-__ecp_nistz256_div_by_2 |
| 592 | .globl ecp_nistz256_point_double |
| 593 | .hidden ecp_nistz256_point_double |
| 594 | .type ecp_nistz256_point_double,%function |
| 595 | .align 5 |
| 596 | ecp_nistz256_point_double: |
| 597 | AARCH64_SIGN_LINK_REGISTER |
| 598 | stp x29,x30,[sp,#-96]! |
| 599 | add x29,sp,#0 |
| 600 | stp x19,x20,[sp,#16] |
| 601 | stp x21,x22,[sp,#32] |
| 602 | sub sp,sp,#32*4 |
| 603 |
| 604 | .Ldouble_shortcut: |
| 605 | ldp x14,x15,[x1,#32] |
| 606 | mov x21,x0 |
| 607 | ldp x16,x17,[x1,#48] |
| 608 | mov x22,x1 |
| 609 | adrp x13,.Lpoly |
| 610 | add x13,x13,:lo12:.Lpoly |
| 611 | ldr x12,[x13,#8] |
| 612 | mov x8,x14 |
| 613 | ldr x13,[x13,#24] |
| 614 | mov x9,x15 |
| 615 | ldp x4,x5,[x22,#64] // forward load for p256_sqr_mont |
| 616 | mov x10,x16 |
| 617 | mov x11,x17 |
| 618 | ldp x6,x7,[x22,#64+16] |
| 619 | add x0,sp,#0 |
| 620 | bl __ecp_nistz256_add_to // p256_mul_by_2(S, in_y); |
| 621 |
| 622 | add x0,sp,#64 |
| 623 | bl __ecp_nistz256_sqr_mont // p256_sqr_mont(Zsqr, in_z); |
| 624 |
| 625 | ldp x8,x9,[x22] |
| 626 | ldp x10,x11,[x22,#16] |
| 627 | mov x4,x14 // put Zsqr aside for p256_sub |
| 628 | mov x5,x15 |
| 629 | mov x6,x16 |
| 630 | mov x7,x17 |
| 631 | add x0,sp,#32 |
| 632 | bl __ecp_nistz256_add_to // p256_add(M, Zsqr, in_x); |
| 633 |
| 634 | add x2,x22,#0 |
| 635 | mov x14,x4 // restore Zsqr |
| 636 | mov x15,x5 |
| 637 | ldp x4,x5,[sp,#0] // forward load for p256_sqr_mont |
| 638 | mov x16,x6 |
| 639 | mov x17,x7 |
| 640 | ldp x6,x7,[sp,#0+16] |
| 641 | add x0,sp,#64 |
| 642 | bl __ecp_nistz256_sub_morf // p256_sub(Zsqr, in_x, Zsqr); |
| 643 |
| 644 | add x0,sp,#0 |
| 645 | bl __ecp_nistz256_sqr_mont // p256_sqr_mont(S, S); |
| 646 |
| 647 | ldr x3,[x22,#32] |
| 648 | ldp x4,x5,[x22,#64] |
| 649 | ldp x6,x7,[x22,#64+16] |
| 650 | add x2,x22,#32 |
| 651 | add x0,sp,#96 |
| 652 | bl __ecp_nistz256_mul_mont // p256_mul_mont(tmp0, in_z, in_y); |
| 653 |
| 654 | mov x8,x14 |
| 655 | mov x9,x15 |
| 656 | ldp x4,x5,[sp,#0] // forward load for p256_sqr_mont |
| 657 | mov x10,x16 |
| 658 | mov x11,x17 |
| 659 | ldp x6,x7,[sp,#0+16] |
| 660 | add x0,x21,#64 |
| 661 | bl __ecp_nistz256_add_to // p256_mul_by_2(res_z, tmp0); |
| 662 |
| 663 | add x0,sp,#96 |
| 664 | bl __ecp_nistz256_sqr_mont // p256_sqr_mont(tmp0, S); |
| 665 |
| 666 | ldr x3,[sp,#64] // forward load for p256_mul_mont |
| 667 | ldp x4,x5,[sp,#32] |
| 668 | ldp x6,x7,[sp,#32+16] |
| 669 | add x0,x21,#32 |
| 670 | bl __ecp_nistz256_div_by_2 // p256_div_by_2(res_y, tmp0); |
| 671 |
| 672 | add x2,sp,#64 |
| 673 | add x0,sp,#32 |
| 674 | bl __ecp_nistz256_mul_mont // p256_mul_mont(M, M, Zsqr); |
| 675 |
| 676 | mov x8,x14 // duplicate M |
| 677 | mov x9,x15 |
| 678 | mov x10,x16 |
| 679 | mov x11,x17 |
| 680 | mov x4,x14 // put M aside |
| 681 | mov x5,x15 |
| 682 | mov x6,x16 |
| 683 | mov x7,x17 |
| 684 | add x0,sp,#32 |
| 685 | bl __ecp_nistz256_add_to |
| 686 | mov x8,x4 // restore M |
| 687 | mov x9,x5 |
| 688 | ldr x3,[x22] // forward load for p256_mul_mont |
| 689 | mov x10,x6 |
| 690 | ldp x4,x5,[sp,#0] |
| 691 | mov x11,x7 |
| 692 | ldp x6,x7,[sp,#0+16] |
| 693 | bl __ecp_nistz256_add_to // p256_mul_by_3(M, M); |
| 694 |
| 695 | add x2,x22,#0 |
| 696 | add x0,sp,#0 |
| 697 | bl __ecp_nistz256_mul_mont // p256_mul_mont(S, S, in_x); |
| 698 |
| 699 | mov x8,x14 |
| 700 | mov x9,x15 |
| 701 | ldp x4,x5,[sp,#32] // forward load for p256_sqr_mont |
| 702 | mov x10,x16 |
| 703 | mov x11,x17 |
| 704 | ldp x6,x7,[sp,#32+16] |
| 705 | add x0,sp,#96 |
| 706 | bl __ecp_nistz256_add_to // p256_mul_by_2(tmp0, S); |
| 707 |
| 708 | add x0,x21,#0 |
| 709 | bl __ecp_nistz256_sqr_mont // p256_sqr_mont(res_x, M); |
| 710 |
| 711 | add x2,sp,#96 |
| 712 | bl __ecp_nistz256_sub_from // p256_sub(res_x, res_x, tmp0); |
| 713 |
| 714 | add x2,sp,#0 |
| 715 | add x0,sp,#0 |
| 716 | bl __ecp_nistz256_sub_morf // p256_sub(S, S, res_x); |
| 717 |
| 718 | ldr x3,[sp,#32] |
| 719 | mov x4,x14 // copy S |
| 720 | mov x5,x15 |
| 721 | mov x6,x16 |
| 722 | mov x7,x17 |
| 723 | add x2,sp,#32 |
| 724 | bl __ecp_nistz256_mul_mont // p256_mul_mont(S, S, M); |
| 725 |
| 726 | add x2,x21,#32 |
| 727 | add x0,x21,#32 |
| 728 | bl __ecp_nistz256_sub_from // p256_sub(res_y, S, res_y); |
| 729 |
| 730 | add sp,x29,#0 // destroy frame |
| 731 | ldp x19,x20,[x29,#16] |
| 732 | ldp x21,x22,[x29,#32] |
| 733 | ldp x29,x30,[sp],#96 |
| 734 | AARCH64_VALIDATE_LINK_REGISTER |
| 735 | ret |
| 736 | .size ecp_nistz256_point_double,.-ecp_nistz256_point_double |
| 737 | .globl ecp_nistz256_point_add |
| 738 | .hidden ecp_nistz256_point_add |
| 739 | .type ecp_nistz256_point_add,%function |
| 740 | .align 5 |
| 741 | ecp_nistz256_point_add: |
| 742 | AARCH64_SIGN_LINK_REGISTER |
| 743 | stp x29,x30,[sp,#-96]! |
| 744 | add x29,sp,#0 |
| 745 | stp x19,x20,[sp,#16] |
| 746 | stp x21,x22,[sp,#32] |
| 747 | stp x23,x24,[sp,#48] |
| 748 | stp x25,x26,[sp,#64] |
| 749 | stp x27,x28,[sp,#80] |
| 750 | sub sp,sp,#32*12 |
| 751 |
| 752 | ldp x4,x5,[x2,#64] // in2_z |
| 753 | ldp x6,x7,[x2,#64+16] |
| 754 | mov x21,x0 |
| 755 | mov x22,x1 |
| 756 | mov x23,x2 |
| 757 | adrp x13,.Lpoly |
| 758 | add x13,x13,:lo12:.Lpoly |
| 759 | ldr x12,[x13,#8] |
| 760 | ldr x13,[x13,#24] |
| 761 | orr x8,x4,x5 |
| 762 | orr x10,x6,x7 |
| 763 | orr x25,x8,x10 |
| 764 | cmp x25,#0 |
| 765 | csetm x25,ne // ~in2infty |
| 766 | add x0,sp,#192 |
| 767 | bl __ecp_nistz256_sqr_mont // p256_sqr_mont(Z2sqr, in2_z); |
| 768 |
| 769 | ldp x4,x5,[x22,#64] // in1_z |
| 770 | ldp x6,x7,[x22,#64+16] |
| 771 | orr x8,x4,x5 |
| 772 | orr x10,x6,x7 |
| 773 | orr x24,x8,x10 |
| 774 | cmp x24,#0 |
| 775 | csetm x24,ne // ~in1infty |
| 776 | add x0,sp,#128 |
| 777 | bl __ecp_nistz256_sqr_mont // p256_sqr_mont(Z1sqr, in1_z); |
| 778 |
| 779 | ldr x3,[x23,#64] |
| 780 | ldp x4,x5,[sp,#192] |
| 781 | ldp x6,x7,[sp,#192+16] |
| 782 | add x2,x23,#64 |
| 783 | add x0,sp,#320 |
| 784 | bl __ecp_nistz256_mul_mont // p256_mul_mont(S1, Z2sqr, in2_z); |
| 785 |
| 786 | ldr x3,[x22,#64] |
| 787 | ldp x4,x5,[sp,#128] |
| 788 | ldp x6,x7,[sp,#128+16] |
| 789 | add x2,x22,#64 |
| 790 | add x0,sp,#352 |
| 791 | bl __ecp_nistz256_mul_mont // p256_mul_mont(S2, Z1sqr, in1_z); |
| 792 |
| 793 | ldr x3,[x22,#32] |
| 794 | ldp x4,x5,[sp,#320] |
| 795 | ldp x6,x7,[sp,#320+16] |
| 796 | add x2,x22,#32 |
| 797 | add x0,sp,#320 |
| 798 | bl __ecp_nistz256_mul_mont // p256_mul_mont(S1, S1, in1_y); |
| 799 |
| 800 | ldr x3,[x23,#32] |
| 801 | ldp x4,x5,[sp,#352] |
| 802 | ldp x6,x7,[sp,#352+16] |
| 803 | add x2,x23,#32 |
| 804 | add x0,sp,#352 |
| 805 | bl __ecp_nistz256_mul_mont // p256_mul_mont(S2, S2, in2_y); |
| 806 |
| 807 | add x2,sp,#320 |
| 808 | ldr x3,[sp,#192] // forward load for p256_mul_mont |
| 809 | ldp x4,x5,[x22] |
| 810 | ldp x6,x7,[x22,#16] |
| 811 | add x0,sp,#160 |
| 812 | bl __ecp_nistz256_sub_from // p256_sub(R, S2, S1); |
| 813 |
| 814 | orr x14,x14,x15 // see if result is zero |
| 815 | orr x16,x16,x17 |
| 816 | orr x26,x14,x16 // ~is_equal(S1,S2) |
| 817 |
| 818 | add x2,sp,#192 |
| 819 | add x0,sp,#256 |
| 820 | bl __ecp_nistz256_mul_mont // p256_mul_mont(U1, in1_x, Z2sqr); |
| 821 |
| 822 | ldr x3,[sp,#128] |
| 823 | ldp x4,x5,[x23] |
| 824 | ldp x6,x7,[x23,#16] |
| 825 | add x2,sp,#128 |
| 826 | add x0,sp,#288 |
| 827 | bl __ecp_nistz256_mul_mont // p256_mul_mont(U2, in2_x, Z1sqr); |
| 828 |
| 829 | add x2,sp,#256 |
| 830 | ldp x4,x5,[sp,#160] // forward load for p256_sqr_mont |
| 831 | ldp x6,x7,[sp,#160+16] |
| 832 | add x0,sp,#96 |
| 833 | bl __ecp_nistz256_sub_from // p256_sub(H, U2, U1); |
| 834 |
| 835 | orr x14,x14,x15 // see if result is zero |
| 836 | orr x16,x16,x17 |
| 837 | orr x14,x14,x16 // ~is_equal(U1,U2) |
| 838 |
| 839 | mvn x27,x24 // -1/0 -> 0/-1 |
| 840 | mvn x28,x25 // -1/0 -> 0/-1 |
| 841 | orr x14,x14,x27 |
| 842 | orr x14,x14,x28 |
| 843 | orr x14,x14,x26 |
| 844 | cbnz x14,.Ladd_proceed // if(~is_equal(U1,U2) | in1infty | in2infty | ~is_equal(S1,S2)) |
| 845 |
| 846 | .Ladd_double: |
| 847 | mov x1,x22 |
| 848 | mov x0,x21 |
| 849 | ldp x23,x24,[x29,#48] |
| 850 | ldp x25,x26,[x29,#64] |
| 851 | ldp x27,x28,[x29,#80] |
| 852 | add sp,sp,#256 // #256 is from #32*(12-4). difference in stack frames |
| 853 | b .Ldouble_shortcut |
| 854 |
| 855 | .align 4 |
| 856 | .Ladd_proceed: |
| 857 | add x0,sp,#192 |
| 858 | bl __ecp_nistz256_sqr_mont // p256_sqr_mont(Rsqr, R); |
| 859 |
| 860 | ldr x3,[x22,#64] |
| 861 | ldp x4,x5,[sp,#96] |
| 862 | ldp x6,x7,[sp,#96+16] |
| 863 | add x2,x22,#64 |
| 864 | add x0,sp,#64 |
| 865 | bl __ecp_nistz256_mul_mont // p256_mul_mont(res_z, H, in1_z); |
| 866 |
| 867 | ldp x4,x5,[sp,#96] |
| 868 | ldp x6,x7,[sp,#96+16] |
| 869 | add x0,sp,#128 |
| 870 | bl __ecp_nistz256_sqr_mont // p256_sqr_mont(Hsqr, H); |
| 871 |
| 872 | ldr x3,[x23,#64] |
| 873 | ldp x4,x5,[sp,#64] |
| 874 | ldp x6,x7,[sp,#64+16] |
| 875 | add x2,x23,#64 |
| 876 | add x0,sp,#64 |
| 877 | bl __ecp_nistz256_mul_mont // p256_mul_mont(res_z, res_z, in2_z); |
| 878 |
| 879 | ldr x3,[sp,#96] |
| 880 | ldp x4,x5,[sp,#128] |
| 881 | ldp x6,x7,[sp,#128+16] |
| 882 | add x2,sp,#96 |
| 883 | add x0,sp,#224 |
| 884 | bl __ecp_nistz256_mul_mont // p256_mul_mont(Hcub, Hsqr, H); |
| 885 |
| 886 | ldr x3,[sp,#128] |
| 887 | ldp x4,x5,[sp,#256] |
| 888 | ldp x6,x7,[sp,#256+16] |
| 889 | add x2,sp,#128 |
| 890 | add x0,sp,#288 |
| 891 | bl __ecp_nistz256_mul_mont // p256_mul_mont(U2, U1, Hsqr); |
| 892 |
| 893 | mov x8,x14 |
| 894 | mov x9,x15 |
| 895 | mov x10,x16 |
| 896 | mov x11,x17 |
| 897 | add x0,sp,#128 |
| 898 | bl __ecp_nistz256_add_to // p256_mul_by_2(Hsqr, U2); |
| 899 |
| 900 | add x2,sp,#192 |
| 901 | add x0,sp,#0 |
| 902 | bl __ecp_nistz256_sub_morf // p256_sub(res_x, Rsqr, Hsqr); |
| 903 |
| 904 | add x2,sp,#224 |
| 905 | bl __ecp_nistz256_sub_from // p256_sub(res_x, res_x, Hcub); |
| 906 |
| 907 | add x2,sp,#288 |
| 908 | ldr x3,[sp,#224] // forward load for p256_mul_mont |
| 909 | ldp x4,x5,[sp,#320] |
| 910 | ldp x6,x7,[sp,#320+16] |
| 911 | add x0,sp,#32 |
| 912 | bl __ecp_nistz256_sub_morf // p256_sub(res_y, U2, res_x); |
| 913 |
| 914 | add x2,sp,#224 |
| 915 | add x0,sp,#352 |
| 916 | bl __ecp_nistz256_mul_mont // p256_mul_mont(S2, S1, Hcub); |
| 917 |
| 918 | ldr x3,[sp,#160] |
| 919 | ldp x4,x5,[sp,#32] |
| 920 | ldp x6,x7,[sp,#32+16] |
| 921 | add x2,sp,#160 |
| 922 | add x0,sp,#32 |
| 923 | bl __ecp_nistz256_mul_mont // p256_mul_mont(res_y, res_y, R); |
| 924 |
| 925 | add x2,sp,#352 |
| 926 | bl __ecp_nistz256_sub_from // p256_sub(res_y, res_y, S2); |
| 927 |
| 928 | ldp x4,x5,[sp,#0] // res |
| 929 | ldp x6,x7,[sp,#0+16] |
| 930 | ldp x8,x9,[x23] // in2 |
| 931 | ldp x10,x11,[x23,#16] |
| 932 | ldp x14,x15,[x22,#0] // in1 |
| 933 | cmp x24,#0 // ~, remember? |
| 934 | ldp x16,x17,[x22,#0+16] |
| 935 | csel x8,x4,x8,ne |
| 936 | csel x9,x5,x9,ne |
| 937 | ldp x4,x5,[sp,#0+0+32] // res |
| 938 | csel x10,x6,x10,ne |
| 939 | csel x11,x7,x11,ne |
| 940 | cmp x25,#0 // ~, remember? |
| 941 | ldp x6,x7,[sp,#0+0+48] |
| 942 | csel x14,x8,x14,ne |
| 943 | csel x15,x9,x15,ne |
| 944 | ldp x8,x9,[x23,#0+32] // in2 |
| 945 | csel x16,x10,x16,ne |
| 946 | csel x17,x11,x17,ne |
| 947 | ldp x10,x11,[x23,#0+48] |
| 948 | stp x14,x15,[x21,#0] |
| 949 | stp x16,x17,[x21,#0+16] |
| 950 | ldp x14,x15,[x22,#32] // in1 |
| 951 | cmp x24,#0 // ~, remember? |
| 952 | ldp x16,x17,[x22,#32+16] |
| 953 | csel x8,x4,x8,ne |
| 954 | csel x9,x5,x9,ne |
| 955 | ldp x4,x5,[sp,#0+32+32] // res |
| 956 | csel x10,x6,x10,ne |
| 957 | csel x11,x7,x11,ne |
| 958 | cmp x25,#0 // ~, remember? |
| 959 | ldp x6,x7,[sp,#0+32+48] |
| 960 | csel x14,x8,x14,ne |
| 961 | csel x15,x9,x15,ne |
| 962 | ldp x8,x9,[x23,#32+32] // in2 |
| 963 | csel x16,x10,x16,ne |
| 964 | csel x17,x11,x17,ne |
| 965 | ldp x10,x11,[x23,#32+48] |
| 966 | stp x14,x15,[x21,#32] |
| 967 | stp x16,x17,[x21,#32+16] |
| 968 | ldp x14,x15,[x22,#64] // in1 |
| 969 | cmp x24,#0 // ~, remember? |
| 970 | ldp x16,x17,[x22,#64+16] |
| 971 | csel x8,x4,x8,ne |
| 972 | csel x9,x5,x9,ne |
| 973 | csel x10,x6,x10,ne |
| 974 | csel x11,x7,x11,ne |
| 975 | cmp x25,#0 // ~, remember? |
| 976 | csel x14,x8,x14,ne |
| 977 | csel x15,x9,x15,ne |
| 978 | csel x16,x10,x16,ne |
| 979 | csel x17,x11,x17,ne |
| 980 | stp x14,x15,[x21,#64] |
| 981 | stp x16,x17,[x21,#64+16] |
| 982 |
| 983 | .Ladd_done: |
| 984 | add sp,x29,#0 // destroy frame |
| 985 | ldp x19,x20,[x29,#16] |
| 986 | ldp x21,x22,[x29,#32] |
| 987 | ldp x23,x24,[x29,#48] |
| 988 | ldp x25,x26,[x29,#64] |
| 989 | ldp x27,x28,[x29,#80] |
| 990 | ldp x29,x30,[sp],#96 |
| 991 | AARCH64_VALIDATE_LINK_REGISTER |
| 992 | ret |
| 993 | .size ecp_nistz256_point_add,.-ecp_nistz256_point_add |
| 994 | .globl ecp_nistz256_point_add_affine |
| 995 | .hidden ecp_nistz256_point_add_affine |
| 996 | .type ecp_nistz256_point_add_affine,%function |
| 997 | .align 5 |
| 998 | ecp_nistz256_point_add_affine: |
| 999 | AARCH64_SIGN_LINK_REGISTER |
| 1000 | stp x29,x30,[sp,#-80]! |
| 1001 | add x29,sp,#0 |
| 1002 | stp x19,x20,[sp,#16] |
| 1003 | stp x21,x22,[sp,#32] |
| 1004 | stp x23,x24,[sp,#48] |
| 1005 | stp x25,x26,[sp,#64] |
| 1006 | sub sp,sp,#32*10 |
| 1007 |
| 1008 | mov x21,x0 |
| 1009 | mov x22,x1 |
| 1010 | mov x23,x2 |
| 1011 | adrp x13,.Lpoly |
| 1012 | add x13,x13,:lo12:.Lpoly |
| 1013 | ldr x12,[x13,#8] |
| 1014 | ldr x13,[x13,#24] |
| 1015 |
| 1016 | ldp x4,x5,[x1,#64] // in1_z |
| 1017 | ldp x6,x7,[x1,#64+16] |
| 1018 | orr x8,x4,x5 |
| 1019 | orr x10,x6,x7 |
| 1020 | orr x24,x8,x10 |
| 1021 | cmp x24,#0 |
| 1022 | csetm x24,ne // ~in1infty |
| 1023 |
| 1024 | ldp x14,x15,[x2] // in2_x |
| 1025 | ldp x16,x17,[x2,#16] |
| 1026 | ldp x8,x9,[x2,#32] // in2_y |
| 1027 | ldp x10,x11,[x2,#48] |
| 1028 | orr x14,x14,x15 |
| 1029 | orr x16,x16,x17 |
| 1030 | orr x8,x8,x9 |
| 1031 | orr x10,x10,x11 |
| 1032 | orr x14,x14,x16 |
| 1033 | orr x8,x8,x10 |
| 1034 | orr x25,x14,x8 |
| 1035 | cmp x25,#0 |
| 1036 | csetm x25,ne // ~in2infty |
| 1037 |
| 1038 | add x0,sp,#128 |
| 1039 | bl __ecp_nistz256_sqr_mont // p256_sqr_mont(Z1sqr, in1_z); |
| 1040 |
| 1041 | mov x4,x14 |
| 1042 | mov x5,x15 |
| 1043 | mov x6,x16 |
| 1044 | mov x7,x17 |
| 1045 | ldr x3,[x23] |
| 1046 | add x2,x23,#0 |
| 1047 | add x0,sp,#96 |
| 1048 | bl __ecp_nistz256_mul_mont // p256_mul_mont(U2, Z1sqr, in2_x); |
| 1049 |
| 1050 | add x2,x22,#0 |
| 1051 | ldr x3,[x22,#64] // forward load for p256_mul_mont |
| 1052 | ldp x4,x5,[sp,#128] |
| 1053 | ldp x6,x7,[sp,#128+16] |
| 1054 | add x0,sp,#160 |
| 1055 | bl __ecp_nistz256_sub_from // p256_sub(H, U2, in1_x); |
| 1056 |
| 1057 | add x2,x22,#64 |
| 1058 | add x0,sp,#128 |
| 1059 | bl __ecp_nistz256_mul_mont // p256_mul_mont(S2, Z1sqr, in1_z); |
| 1060 |
| 1061 | ldr x3,[x22,#64] |
| 1062 | ldp x4,x5,[sp,#160] |
| 1063 | ldp x6,x7,[sp,#160+16] |
| 1064 | add x2,x22,#64 |
| 1065 | add x0,sp,#64 |
| 1066 | bl __ecp_nistz256_mul_mont // p256_mul_mont(res_z, H, in1_z); |
| 1067 |
| 1068 | ldr x3,[x23,#32] |
| 1069 | ldp x4,x5,[sp,#128] |
| 1070 | ldp x6,x7,[sp,#128+16] |
| 1071 | add x2,x23,#32 |
| 1072 | add x0,sp,#128 |
| 1073 | bl __ecp_nistz256_mul_mont // p256_mul_mont(S2, S2, in2_y); |
| 1074 |
| 1075 | add x2,x22,#32 |
| 1076 | ldp x4,x5,[sp,#160] // forward load for p256_sqr_mont |
| 1077 | ldp x6,x7,[sp,#160+16] |
| 1078 | add x0,sp,#192 |
| 1079 | bl __ecp_nistz256_sub_from // p256_sub(R, S2, in1_y); |
| 1080 |
| 1081 | add x0,sp,#224 |
| 1082 | bl __ecp_nistz256_sqr_mont // p256_sqr_mont(Hsqr, H); |
| 1083 |
| 1084 | ldp x4,x5,[sp,#192] |
| 1085 | ldp x6,x7,[sp,#192+16] |
| 1086 | add x0,sp,#288 |
| 1087 | bl __ecp_nistz256_sqr_mont // p256_sqr_mont(Rsqr, R); |
| 1088 |
| 1089 | ldr x3,[sp,#160] |
| 1090 | ldp x4,x5,[sp,#224] |
| 1091 | ldp x6,x7,[sp,#224+16] |
| 1092 | add x2,sp,#160 |
| 1093 | add x0,sp,#256 |
| 1094 | bl __ecp_nistz256_mul_mont // p256_mul_mont(Hcub, Hsqr, H); |
| 1095 |
| 1096 | ldr x3,[x22] |
| 1097 | ldp x4,x5,[sp,#224] |
| 1098 | ldp x6,x7,[sp,#224+16] |
| 1099 | add x2,x22,#0 |
| 1100 | add x0,sp,#96 |
| 1101 | bl __ecp_nistz256_mul_mont // p256_mul_mont(U2, in1_x, Hsqr); |
| 1102 |
| 1103 | mov x8,x14 |
| 1104 | mov x9,x15 |
| 1105 | mov x10,x16 |
| 1106 | mov x11,x17 |
| 1107 | add x0,sp,#224 |
| 1108 | bl __ecp_nistz256_add_to // p256_mul_by_2(Hsqr, U2); |
| 1109 |
| 1110 | add x2,sp,#288 |
| 1111 | add x0,sp,#0 |
| 1112 | bl __ecp_nistz256_sub_morf // p256_sub(res_x, Rsqr, Hsqr); |
| 1113 |
| 1114 | add x2,sp,#256 |
| 1115 | bl __ecp_nistz256_sub_from // p256_sub(res_x, res_x, Hcub); |
| 1116 |
| 1117 | add x2,sp,#96 |
| 1118 | ldr x3,[x22,#32] // forward load for p256_mul_mont |
| 1119 | ldp x4,x5,[sp,#256] |
| 1120 | ldp x6,x7,[sp,#256+16] |
| 1121 | add x0,sp,#32 |
| 1122 | bl __ecp_nistz256_sub_morf // p256_sub(res_y, U2, res_x); |
| 1123 |
| 1124 | add x2,x22,#32 |
| 1125 | add x0,sp,#128 |
| 1126 | bl __ecp_nistz256_mul_mont // p256_mul_mont(S2, in1_y, Hcub); |
| 1127 |
| 1128 | ldr x3,[sp,#192] |
| 1129 | ldp x4,x5,[sp,#32] |
| 1130 | ldp x6,x7,[sp,#32+16] |
| 1131 | add x2,sp,#192 |
| 1132 | add x0,sp,#32 |
| 1133 | bl __ecp_nistz256_mul_mont // p256_mul_mont(res_y, res_y, R); |
| 1134 |
| 1135 | add x2,sp,#128 |
| 1136 | bl __ecp_nistz256_sub_from // p256_sub(res_y, res_y, S2); |
| 1137 |
| 1138 | ldp x4,x5,[sp,#0] // res |
| 1139 | ldp x6,x7,[sp,#0+16] |
| 1140 | ldp x8,x9,[x23] // in2 |
| 1141 | ldp x10,x11,[x23,#16] |
| 1142 | ldp x14,x15,[x22,#0] // in1 |
| 1143 | cmp x24,#0 // ~, remember? |
| 1144 | ldp x16,x17,[x22,#0+16] |
| 1145 | csel x8,x4,x8,ne |
| 1146 | csel x9,x5,x9,ne |
| 1147 | ldp x4,x5,[sp,#0+0+32] // res |
| 1148 | csel x10,x6,x10,ne |
| 1149 | csel x11,x7,x11,ne |
| 1150 | cmp x25,#0 // ~, remember? |
| 1151 | ldp x6,x7,[sp,#0+0+48] |
| 1152 | csel x14,x8,x14,ne |
| 1153 | csel x15,x9,x15,ne |
| 1154 | ldp x8,x9,[x23,#0+32] // in2 |
| 1155 | csel x16,x10,x16,ne |
| 1156 | csel x17,x11,x17,ne |
| 1157 | ldp x10,x11,[x23,#0+48] |
| 1158 | stp x14,x15,[x21,#0] |
| 1159 | stp x16,x17,[x21,#0+16] |
| 1160 | adrp x23,.Lone_mont-64 |
| 1161 | add x23,x23,:lo12:.Lone_mont-64 |
| 1162 | ldp x14,x15,[x22,#32] // in1 |
| 1163 | cmp x24,#0 // ~, remember? |
| 1164 | ldp x16,x17,[x22,#32+16] |
| 1165 | csel x8,x4,x8,ne |
| 1166 | csel x9,x5,x9,ne |
| 1167 | ldp x4,x5,[sp,#0+32+32] // res |
| 1168 | csel x10,x6,x10,ne |
| 1169 | csel x11,x7,x11,ne |
| 1170 | cmp x25,#0 // ~, remember? |
| 1171 | ldp x6,x7,[sp,#0+32+48] |
| 1172 | csel x14,x8,x14,ne |
| 1173 | csel x15,x9,x15,ne |
| 1174 | ldp x8,x9,[x23,#32+32] // in2 |
| 1175 | csel x16,x10,x16,ne |
| 1176 | csel x17,x11,x17,ne |
| 1177 | ldp x10,x11,[x23,#32+48] |
| 1178 | stp x14,x15,[x21,#32] |
| 1179 | stp x16,x17,[x21,#32+16] |
| 1180 | ldp x14,x15,[x22,#64] // in1 |
| 1181 | cmp x24,#0 // ~, remember? |
| 1182 | ldp x16,x17,[x22,#64+16] |
| 1183 | csel x8,x4,x8,ne |
| 1184 | csel x9,x5,x9,ne |
| 1185 | csel x10,x6,x10,ne |
| 1186 | csel x11,x7,x11,ne |
| 1187 | cmp x25,#0 // ~, remember? |
| 1188 | csel x14,x8,x14,ne |
| 1189 | csel x15,x9,x15,ne |
| 1190 | csel x16,x10,x16,ne |
| 1191 | csel x17,x11,x17,ne |
| 1192 | stp x14,x15,[x21,#64] |
| 1193 | stp x16,x17,[x21,#64+16] |
| 1194 |
| 1195 | add sp,x29,#0 // destroy frame |
| 1196 | ldp x19,x20,[x29,#16] |
| 1197 | ldp x21,x22,[x29,#32] |
| 1198 | ldp x23,x24,[x29,#48] |
| 1199 | ldp x25,x26,[x29,#64] |
| 1200 | ldp x29,x30,[sp],#80 |
| 1201 | AARCH64_VALIDATE_LINK_REGISTER |
| 1202 | ret |
| 1203 | .size ecp_nistz256_point_add_affine,.-ecp_nistz256_point_add_affine |
| 1204 | //////////////////////////////////////////////////////////////////////// |
| 1205 | // void ecp_nistz256_ord_mul_mont(uint64_t res[4], uint64_t a[4], |
| 1206 | // uint64_t b[4]); |
| 1207 | .globl ecp_nistz256_ord_mul_mont |
| 1208 | .hidden ecp_nistz256_ord_mul_mont |
| 1209 | .type ecp_nistz256_ord_mul_mont,%function |
| 1210 | .align 4 |
| 1211 | ecp_nistz256_ord_mul_mont: |
| 1212 | AARCH64_VALID_CALL_TARGET |
| 1213 | // Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later. |
| 1214 | stp x29,x30,[sp,#-64]! |
| 1215 | add x29,sp,#0 |
| 1216 | stp x19,x20,[sp,#16] |
| 1217 | stp x21,x22,[sp,#32] |
| 1218 | stp x23,x24,[sp,#48] |
| 1219 |
| 1220 | adrp x23,.Lord |
| 1221 | add x23,x23,:lo12:.Lord |
| 1222 | ldr x3,[x2] // bp[0] |
| 1223 | ldp x4,x5,[x1] |
| 1224 | ldp x6,x7,[x1,#16] |
| 1225 |
| 1226 | ldp x12,x13,[x23,#0] |
| 1227 | ldp x21,x22,[x23,#16] |
| 1228 | ldr x23,[x23,#32] |
| 1229 |
| 1230 | mul x14,x4,x3 // a[0]*b[0] |
| 1231 | umulh x8,x4,x3 |
| 1232 |
| 1233 | mul x15,x5,x3 // a[1]*b[0] |
| 1234 | umulh x9,x5,x3 |
| 1235 |
| 1236 | mul x16,x6,x3 // a[2]*b[0] |
| 1237 | umulh x10,x6,x3 |
| 1238 |
| 1239 | mul x17,x7,x3 // a[3]*b[0] |
| 1240 | umulh x19,x7,x3 |
| 1241 |
| 1242 | mul x24,x14,x23 |
| 1243 |
| 1244 | adds x15,x15,x8 // accumulate high parts of multiplication |
| 1245 | adcs x16,x16,x9 |
| 1246 | adcs x17,x17,x10 |
| 1247 | adc x19,x19,xzr |
| 1248 | mov x20,xzr |
| 1249 | ldr x3,[x2,#8*1] // b[i] |
| 1250 |
| 1251 | lsl x8,x24,#32 |
| 1252 | subs x16,x16,x24 |
| 1253 | lsr x9,x24,#32 |
| 1254 | sbcs x17,x17,x8 |
| 1255 | sbcs x19,x19,x9 |
| 1256 | sbc x20,x20,xzr |
| 1257 |
| 1258 | subs xzr,x14,#1 |
| 1259 | umulh x9,x12,x24 |
| 1260 | mul x10,x13,x24 |
| 1261 | umulh x11,x13,x24 |
| 1262 |
| 1263 | adcs x10,x10,x9 |
| 1264 | mul x8,x4,x3 |
| 1265 | adc x11,x11,xzr |
| 1266 | mul x9,x5,x3 |
| 1267 |
| 1268 | adds x14,x15,x10 |
| 1269 | mul x10,x6,x3 |
| 1270 | adcs x15,x16,x11 |
| 1271 | mul x11,x7,x3 |
| 1272 | adcs x16,x17,x24 |
| 1273 | adcs x17,x19,x24 |
| 1274 | adc x19,x20,xzr |
| 1275 |
| 1276 | adds x14,x14,x8 // accumulate low parts |
| 1277 | umulh x8,x4,x3 |
| 1278 | adcs x15,x15,x9 |
| 1279 | umulh x9,x5,x3 |
| 1280 | adcs x16,x16,x10 |
| 1281 | umulh x10,x6,x3 |
| 1282 | adcs x17,x17,x11 |
| 1283 | umulh x11,x7,x3 |
| 1284 | adc x19,x19,xzr |
| 1285 | mul x24,x14,x23 |
| 1286 | adds x15,x15,x8 // accumulate high parts |
| 1287 | adcs x16,x16,x9 |
| 1288 | adcs x17,x17,x10 |
| 1289 | adcs x19,x19,x11 |
| 1290 | adc x20,xzr,xzr |
| 1291 | ldr x3,[x2,#8*2] // b[i] |
| 1292 |
| 1293 | lsl x8,x24,#32 |
| 1294 | subs x16,x16,x24 |
| 1295 | lsr x9,x24,#32 |
| 1296 | sbcs x17,x17,x8 |
| 1297 | sbcs x19,x19,x9 |
| 1298 | sbc x20,x20,xzr |
| 1299 |
| 1300 | subs xzr,x14,#1 |
| 1301 | umulh x9,x12,x24 |
| 1302 | mul x10,x13,x24 |
| 1303 | umulh x11,x13,x24 |
| 1304 |
| 1305 | adcs x10,x10,x9 |
| 1306 | mul x8,x4,x3 |
| 1307 | adc x11,x11,xzr |
| 1308 | mul x9,x5,x3 |
| 1309 |
| 1310 | adds x14,x15,x10 |
| 1311 | mul x10,x6,x3 |
| 1312 | adcs x15,x16,x11 |
| 1313 | mul x11,x7,x3 |
| 1314 | adcs x16,x17,x24 |
| 1315 | adcs x17,x19,x24 |
| 1316 | adc x19,x20,xzr |
| 1317 |
| 1318 | adds x14,x14,x8 // accumulate low parts |
| 1319 | umulh x8,x4,x3 |
| 1320 | adcs x15,x15,x9 |
| 1321 | umulh x9,x5,x3 |
| 1322 | adcs x16,x16,x10 |
| 1323 | umulh x10,x6,x3 |
| 1324 | adcs x17,x17,x11 |
| 1325 | umulh x11,x7,x3 |
| 1326 | adc x19,x19,xzr |
| 1327 | mul x24,x14,x23 |
| 1328 | adds x15,x15,x8 // accumulate high parts |
| 1329 | adcs x16,x16,x9 |
| 1330 | adcs x17,x17,x10 |
| 1331 | adcs x19,x19,x11 |
| 1332 | adc x20,xzr,xzr |
| 1333 | ldr x3,[x2,#8*3] // b[i] |
| 1334 |
| 1335 | lsl x8,x24,#32 |
| 1336 | subs x16,x16,x24 |
| 1337 | lsr x9,x24,#32 |
| 1338 | sbcs x17,x17,x8 |
| 1339 | sbcs x19,x19,x9 |
| 1340 | sbc x20,x20,xzr |
| 1341 |
| 1342 | subs xzr,x14,#1 |
| 1343 | umulh x9,x12,x24 |
| 1344 | mul x10,x13,x24 |
| 1345 | umulh x11,x13,x24 |
| 1346 |
| 1347 | adcs x10,x10,x9 |
| 1348 | mul x8,x4,x3 |
| 1349 | adc x11,x11,xzr |
| 1350 | mul x9,x5,x3 |
| 1351 |
| 1352 | adds x14,x15,x10 |
| 1353 | mul x10,x6,x3 |
| 1354 | adcs x15,x16,x11 |
| 1355 | mul x11,x7,x3 |
| 1356 | adcs x16,x17,x24 |
| 1357 | adcs x17,x19,x24 |
| 1358 | adc x19,x20,xzr |
| 1359 |
| 1360 | adds x14,x14,x8 // accumulate low parts |
| 1361 | umulh x8,x4,x3 |
| 1362 | adcs x15,x15,x9 |
| 1363 | umulh x9,x5,x3 |
| 1364 | adcs x16,x16,x10 |
| 1365 | umulh x10,x6,x3 |
| 1366 | adcs x17,x17,x11 |
| 1367 | umulh x11,x7,x3 |
| 1368 | adc x19,x19,xzr |
| 1369 | mul x24,x14,x23 |
| 1370 | adds x15,x15,x8 // accumulate high parts |
| 1371 | adcs x16,x16,x9 |
| 1372 | adcs x17,x17,x10 |
| 1373 | adcs x19,x19,x11 |
| 1374 | adc x20,xzr,xzr |
| 1375 | lsl x8,x24,#32 // last reduction |
| 1376 | subs x16,x16,x24 |
| 1377 | lsr x9,x24,#32 |
| 1378 | sbcs x17,x17,x8 |
| 1379 | sbcs x19,x19,x9 |
| 1380 | sbc x20,x20,xzr |
| 1381 |
| 1382 | subs xzr,x14,#1 |
| 1383 | umulh x9,x12,x24 |
| 1384 | mul x10,x13,x24 |
| 1385 | umulh x11,x13,x24 |
| 1386 |
| 1387 | adcs x10,x10,x9 |
| 1388 | adc x11,x11,xzr |
| 1389 |
| 1390 | adds x14,x15,x10 |
| 1391 | adcs x15,x16,x11 |
| 1392 | adcs x16,x17,x24 |
| 1393 | adcs x17,x19,x24 |
| 1394 | adc x19,x20,xzr |
| 1395 |
| 1396 | subs x8,x14,x12 // ret -= modulus |
| 1397 | sbcs x9,x15,x13 |
| 1398 | sbcs x10,x16,x21 |
| 1399 | sbcs x11,x17,x22 |
| 1400 | sbcs xzr,x19,xzr |
| 1401 |
| 1402 | csel x14,x14,x8,lo // ret = borrow ? ret : ret-modulus |
| 1403 | csel x15,x15,x9,lo |
| 1404 | csel x16,x16,x10,lo |
| 1405 | stp x14,x15,[x0] |
| 1406 | csel x17,x17,x11,lo |
| 1407 | stp x16,x17,[x0,#16] |
| 1408 |
| 1409 | ldp x19,x20,[sp,#16] |
| 1410 | ldp x21,x22,[sp,#32] |
| 1411 | ldp x23,x24,[sp,#48] |
| 1412 | ldr x29,[sp],#64 |
| 1413 | ret |
| 1414 | .size ecp_nistz256_ord_mul_mont,.-ecp_nistz256_ord_mul_mont |
| 1415 |
| 1416 | //////////////////////////////////////////////////////////////////////// |
| 1417 | // void ecp_nistz256_ord_sqr_mont(uint64_t res[4], uint64_t a[4], |
| 1418 | // uint64_t rep); |
| 1419 | .globl ecp_nistz256_ord_sqr_mont |
| 1420 | .hidden ecp_nistz256_ord_sqr_mont |
| 1421 | .type ecp_nistz256_ord_sqr_mont,%function |
| 1422 | .align 4 |
| 1423 | ecp_nistz256_ord_sqr_mont: |
| 1424 | AARCH64_VALID_CALL_TARGET |
| 1425 | // Armv8.3-A PAuth: even though x30 is pushed to stack it is not popped later. |
| 1426 | stp x29,x30,[sp,#-64]! |
| 1427 | add x29,sp,#0 |
| 1428 | stp x19,x20,[sp,#16] |
| 1429 | stp x21,x22,[sp,#32] |
| 1430 | stp x23,x24,[sp,#48] |
| 1431 |
| 1432 | adrp x23,.Lord |
| 1433 | add x23,x23,:lo12:.Lord |
| 1434 | ldp x4,x5,[x1] |
| 1435 | ldp x6,x7,[x1,#16] |
| 1436 |
| 1437 | ldp x12,x13,[x23,#0] |
| 1438 | ldp x21,x22,[x23,#16] |
| 1439 | ldr x23,[x23,#32] |
| 1440 | b .Loop_ord_sqr |
| 1441 |
| 1442 | .align 4 |
| 1443 | .Loop_ord_sqr: |
| 1444 | sub x2,x2,#1 |
| 1445 | //////////////////////////////////////////////////////////////// |
| 1446 | // | | | | | |a1*a0| | |
| 1447 | // | | | | |a2*a0| | | |
| 1448 | // | |a3*a2|a3*a0| | | | |
| 1449 | // | | | |a2*a1| | | | |
| 1450 | // | | |a3*a1| | | | | |
| 1451 | // *| | | | | | | | 2| |
| 1452 | // +|a3*a3|a2*a2|a1*a1|a0*a0| |
| 1453 | // |--+--+--+--+--+--+--+--| |
| 1454 | // |A7|A6|A5|A4|A3|A2|A1|A0|, where Ax is , i.e. follow |
| 1455 | // |
| 1456 | // "can't overflow" below mark carrying into high part of |
| 1457 | // multiplication result, which can't overflow, because it |
| 1458 | // can never be all ones. |
| 1459 |
| 1460 | mul x15,x5,x4 // a[1]*a[0] |
| 1461 | umulh x9,x5,x4 |
| 1462 | mul x16,x6,x4 // a[2]*a[0] |
| 1463 | umulh x10,x6,x4 |
| 1464 | mul x17,x7,x4 // a[3]*a[0] |
| 1465 | umulh x19,x7,x4 |
| 1466 |
| 1467 | adds x16,x16,x9 // accumulate high parts of multiplication |
| 1468 | mul x8,x6,x5 // a[2]*a[1] |
| 1469 | umulh x9,x6,x5 |
| 1470 | adcs x17,x17,x10 |
| 1471 | mul x10,x7,x5 // a[3]*a[1] |
| 1472 | umulh x11,x7,x5 |
| 1473 | adc x19,x19,xzr // can't overflow |
| 1474 |
| 1475 | mul x20,x7,x6 // a[3]*a[2] |
| 1476 | umulh x1,x7,x6 |
| 1477 |
| 1478 | adds x9,x9,x10 // accumulate high parts of multiplication |
| 1479 | mul x14,x4,x4 // a[0]*a[0] |
| 1480 | adc x10,x11,xzr // can't overflow |
| 1481 |
| 1482 | adds x17,x17,x8 // accumulate low parts of multiplication |
| 1483 | umulh x4,x4,x4 |
| 1484 | adcs x19,x19,x9 |
| 1485 | mul x9,x5,x5 // a[1]*a[1] |
| 1486 | adcs x20,x20,x10 |
| 1487 | umulh x5,x5,x5 |
| 1488 | adc x1,x1,xzr // can't overflow |
| 1489 |
| 1490 | adds x15,x15,x15 // acc[1-6]*=2 |
| 1491 | mul x10,x6,x6 // a[2]*a[2] |
| 1492 | adcs x16,x16,x16 |
| 1493 | umulh x6,x6,x6 |
| 1494 | adcs x17,x17,x17 |
| 1495 | mul x11,x7,x7 // a[3]*a[3] |
| 1496 | adcs x19,x19,x19 |
| 1497 | umulh x7,x7,x7 |
| 1498 | adcs x20,x20,x20 |
| 1499 | adcs x1,x1,x1 |
| 1500 | adc x3,xzr,xzr |
| 1501 |
| 1502 | adds x15,x15,x4 // +a[i]*a[i] |
| 1503 | mul x24,x14,x23 |
| 1504 | adcs x16,x16,x9 |
| 1505 | adcs x17,x17,x5 |
| 1506 | adcs x19,x19,x10 |
| 1507 | adcs x20,x20,x6 |
| 1508 | adcs x1,x1,x11 |
| 1509 | adc x3,x3,x7 |
| 1510 | subs xzr,x14,#1 |
| 1511 | umulh x9,x12,x24 |
| 1512 | mul x10,x13,x24 |
| 1513 | umulh x11,x13,x24 |
| 1514 |
| 1515 | adcs x10,x10,x9 |
| 1516 | adc x11,x11,xzr |
| 1517 |
| 1518 | adds x14,x15,x10 |
| 1519 | adcs x15,x16,x11 |
| 1520 | adcs x16,x17,x24 |
| 1521 | adc x17,xzr,x24 // can't overflow |
| 1522 | mul x11,x14,x23 |
| 1523 | lsl x8,x24,#32 |
| 1524 | subs x15,x15,x24 |
| 1525 | lsr x9,x24,#32 |
| 1526 | sbcs x16,x16,x8 |
| 1527 | sbc x17,x17,x9 // can't borrow |
| 1528 | subs xzr,x14,#1 |
| 1529 | umulh x9,x12,x11 |
| 1530 | mul x10,x13,x11 |
| 1531 | umulh x24,x13,x11 |
| 1532 |
| 1533 | adcs x10,x10,x9 |
| 1534 | adc x24,x24,xzr |
| 1535 |
| 1536 | adds x14,x15,x10 |
| 1537 | adcs x15,x16,x24 |
| 1538 | adcs x16,x17,x11 |
| 1539 | adc x17,xzr,x11 // can't overflow |
| 1540 | mul x24,x14,x23 |
| 1541 | lsl x8,x11,#32 |
| 1542 | subs x15,x15,x11 |
| 1543 | lsr x9,x11,#32 |
| 1544 | sbcs x16,x16,x8 |
| 1545 | sbc x17,x17,x9 // can't borrow |
| 1546 | subs xzr,x14,#1 |
| 1547 | umulh x9,x12,x24 |
| 1548 | mul x10,x13,x24 |
| 1549 | umulh x11,x13,x24 |
| 1550 |
| 1551 | adcs x10,x10,x9 |
| 1552 | adc x11,x11,xzr |
| 1553 |
| 1554 | adds x14,x15,x10 |
| 1555 | adcs x15,x16,x11 |
| 1556 | adcs x16,x17,x24 |
| 1557 | adc x17,xzr,x24 // can't overflow |
| 1558 | mul x11,x14,x23 |
| 1559 | lsl x8,x24,#32 |
| 1560 | subs x15,x15,x24 |
| 1561 | lsr x9,x24,#32 |
| 1562 | sbcs x16,x16,x8 |
| 1563 | sbc x17,x17,x9 // can't borrow |
| 1564 | subs xzr,x14,#1 |
| 1565 | umulh x9,x12,x11 |
| 1566 | mul x10,x13,x11 |
| 1567 | umulh x24,x13,x11 |
| 1568 |
| 1569 | adcs x10,x10,x9 |
| 1570 | adc x24,x24,xzr |
| 1571 |
| 1572 | adds x14,x15,x10 |
| 1573 | adcs x15,x16,x24 |
| 1574 | adcs x16,x17,x11 |
| 1575 | adc x17,xzr,x11 // can't overflow |
| 1576 | lsl x8,x11,#32 |
| 1577 | subs x15,x15,x11 |
| 1578 | lsr x9,x11,#32 |
| 1579 | sbcs x16,x16,x8 |
| 1580 | sbc x17,x17,x9 // can't borrow |
| 1581 | adds x14,x14,x19 // accumulate upper half |
| 1582 | adcs x15,x15,x20 |
| 1583 | adcs x16,x16,x1 |
| 1584 | adcs x17,x17,x3 |
| 1585 | adc x19,xzr,xzr |
| 1586 |
| 1587 | subs x8,x14,x12 // ret -= modulus |
| 1588 | sbcs x9,x15,x13 |
| 1589 | sbcs x10,x16,x21 |
| 1590 | sbcs x11,x17,x22 |
| 1591 | sbcs xzr,x19,xzr |
| 1592 |
| 1593 | csel x4,x14,x8,lo // ret = borrow ? ret : ret-modulus |
| 1594 | csel x5,x15,x9,lo |
| 1595 | csel x6,x16,x10,lo |
| 1596 | csel x7,x17,x11,lo |
| 1597 |
| 1598 | cbnz x2,.Loop_ord_sqr |
| 1599 |
| 1600 | stp x4,x5,[x0] |
| 1601 | stp x6,x7,[x0,#16] |
| 1602 |
| 1603 | ldp x19,x20,[sp,#16] |
| 1604 | ldp x21,x22,[sp,#32] |
| 1605 | ldp x23,x24,[sp,#48] |
| 1606 | ldr x29,[sp],#64 |
| 1607 | ret |
| 1608 | .size ecp_nistz256_ord_sqr_mont,.-ecp_nistz256_ord_sqr_mont |
| 1609 | //////////////////////////////////////////////////////////////////////// |
| 1610 | // void ecp_nistz256_select_w5(uint64_t *val, uint64_t *in_t, int index); |
| 1611 | .globl ecp_nistz256_select_w5 |
| 1612 | .hidden ecp_nistz256_select_w5 |
| 1613 | .type ecp_nistz256_select_w5,%function |
| 1614 | .align 4 |
| 1615 | ecp_nistz256_select_w5: |
| 1616 | AARCH64_VALID_CALL_TARGET |
| 1617 |
| 1618 | // x10 := x0 |
| 1619 | // w9 := 0; loop counter and incremented internal index |
| 1620 | mov x10, x0 |
| 1621 | mov w9, #0 |
| 1622 |
| 1623 | // [v16-v21] := 0 |
| 1624 | movi v16.16b, #0 |
| 1625 | movi v17.16b, #0 |
| 1626 | movi v18.16b, #0 |
| 1627 | movi v19.16b, #0 |
| 1628 | movi v20.16b, #0 |
| 1629 | movi v21.16b, #0 |
| 1630 |
| 1631 | .Lselect_w5_loop: |
| 1632 | // Loop 16 times. |
| 1633 |
| 1634 | // Increment index (loop counter); tested at the end of the loop |
| 1635 | add w9, w9, #1 |
| 1636 |
| 1637 | // [v22-v27] := Load a (3*256-bit = 6*128-bit) table entry starting at x1 |
| 1638 | // and advance x1 to point to the next entry |
| 1639 | ld1 {v22.2d, v23.2d, v24.2d, v25.2d}, [x1],#64 |
| 1640 |
| 1641 | // x11 := (w9 == w2)? All 1s : All 0s |
| 1642 | cmp w9, w2 |
| 1643 | csetm x11, eq |
| 1644 |
| 1645 | // continue loading ... |
| 1646 | ld1 {v26.2d, v27.2d}, [x1],#32 |
| 1647 |
| 1648 | // duplicate mask_64 into Mask (all 0s or all 1s) |
| 1649 | dup v3.2d, x11 |
| 1650 |
| 1651 | // [v16-v19] := (Mask == all 1s)? [v22-v25] : [v16-v19] |
| 1652 | // i.e., values in output registers will remain the same if w9 != w2 |
| 1653 | bit v16.16b, v22.16b, v3.16b |
| 1654 | bit v17.16b, v23.16b, v3.16b |
| 1655 |
| 1656 | bit v18.16b, v24.16b, v3.16b |
| 1657 | bit v19.16b, v25.16b, v3.16b |
| 1658 |
| 1659 | bit v20.16b, v26.16b, v3.16b |
| 1660 | bit v21.16b, v27.16b, v3.16b |
| 1661 |
| 1662 | // If bit #4 is not 0 (i.e. idx_ctr < 16) loop back |
| 1663 | tbz w9, #4, .Lselect_w5_loop |
| 1664 |
| 1665 | // Write [v16-v21] to memory at the output pointer |
| 1666 | st1 {v16.2d, v17.2d, v18.2d, v19.2d}, [x10],#64 |
| 1667 | st1 {v20.2d, v21.2d}, [x10] |
| 1668 |
| 1669 | ret |
| 1670 | .size ecp_nistz256_select_w5,.-ecp_nistz256_select_w5 |
| 1671 |
| 1672 |
| 1673 | //////////////////////////////////////////////////////////////////////// |
| 1674 | // void ecp_nistz256_select_w7(uint64_t *val, uint64_t *in_t, int index); |
| 1675 | .globl ecp_nistz256_select_w7 |
| 1676 | .hidden ecp_nistz256_select_w7 |
| 1677 | .type ecp_nistz256_select_w7,%function |
| 1678 | .align 4 |
| 1679 | ecp_nistz256_select_w7: |
| 1680 | AARCH64_VALID_CALL_TARGET |
| 1681 |
| 1682 | // w9 := 0; loop counter and incremented internal index |
| 1683 | mov w9, #0 |
| 1684 |
| 1685 | // [v16-v21] := 0 |
| 1686 | movi v16.16b, #0 |
| 1687 | movi v17.16b, #0 |
| 1688 | movi v18.16b, #0 |
| 1689 | movi v19.16b, #0 |
| 1690 |
| 1691 | .Lselect_w7_loop: |
| 1692 | // Loop 64 times. |
| 1693 |
| 1694 | // Increment index (loop counter); tested at the end of the loop |
| 1695 | add w9, w9, #1 |
| 1696 |
| 1697 | // [v22-v25] := Load a (2*256-bit = 4*128-bit) table entry starting at x1 |
| 1698 | // and advance x1 to point to the next entry |
| 1699 | ld1 {v22.2d, v23.2d, v24.2d, v25.2d}, [x1],#64 |
| 1700 |
| 1701 | // x11 := (w9 == w2)? All 1s : All 0s |
| 1702 | cmp w9, w2 |
| 1703 | csetm x11, eq |
| 1704 |
| 1705 | // duplicate mask_64 into Mask (all 0s or all 1s) |
| 1706 | dup v3.2d, x11 |
| 1707 |
| 1708 | // [v16-v19] := (Mask == all 1s)? [v22-v25] : [v16-v19] |
| 1709 | // i.e., values in output registers will remain the same if w9 != w2 |
| 1710 | bit v16.16b, v22.16b, v3.16b |
| 1711 | bit v17.16b, v23.16b, v3.16b |
| 1712 |
| 1713 | bit v18.16b, v24.16b, v3.16b |
| 1714 | bit v19.16b, v25.16b, v3.16b |
| 1715 |
| 1716 | // If bit #6 is not 0 (i.e. idx_ctr < 64) loop back |
| 1717 | tbz w9, #6, .Lselect_w7_loop |
| 1718 |
| 1719 | // Write [v16-v19] to memory at the output pointer |
| 1720 | st1 {v16.2d, v17.2d, v18.2d, v19.2d}, [x0] |
| 1721 |
| 1722 | ret |
| 1723 | .size ecp_nistz256_select_w7,.-ecp_nistz256_select_w7 |
| 1724 | #endif // !OPENSSL_NO_ASM && defined(OPENSSL_AARCH64) && defined(__ELF__) |
| 1725 |