aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/tls_sp_c32.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/networking/tls_sp_c32.c b/networking/tls_sp_c32.c
index 14a7c7066..1391cb405 100644
--- a/networking/tls_sp_c32.c
+++ b/networking/tls_sp_c32.c
@@ -346,8 +346,8 @@ static int sp_256_sub_8(sp_digit* r, const sp_digit* a, const sp_digit* b)
346#endif 346#endif
347} 347}
348 348
349#if ALLOW_ASM && defined(__GNUC__) && defined(__i386__)
350/* Sub p256_mod from a into r. (r = a - p256_mod). */ 349/* Sub p256_mod from a into r. (r = a - p256_mod). */
350#if ALLOW_ASM && defined(__GNUC__) && defined(__i386__)
351static void sp_256_sub_8_p256_mod(sp_digit* r, const sp_digit* a) 351static void sp_256_sub_8_p256_mod(sp_digit* r, const sp_digit* a)
352{ 352{
353 sp_digit reg; 353 sp_digit reg;
@@ -390,6 +390,36 @@ static void sp_256_sub_8_p256_mod(sp_digit* r, const sp_digit* a)
390 : "memory" 390 : "memory"
391 ); 391 );
392} 392}
393#elif ALLOW_ASM && defined(__GNUC__) && defined(__x86_64__)
394static void sp_256_sub_8_p256_mod(sp_digit* r, const sp_digit* a)
395{
396 uint64_t reg;
397 uint64_t ooff;
398//p256_mod[3..0] = ffffffff00000001 0000000000000000 00000000ffffffff ffffffffffffffff
399 asm volatile (
400"\n movq (%0), %3"
401"\n addq $1, %3" // adding 1 is the same as subtracting ffffffffffffffff
402"\n movq %3, (%1)" //
403"\n cmc" // only carry bit needs inverting
404"\n"
405"\n movq 1*8(%0), %3"
406"\n sbbq %2, %3" // %2 holds 00000000ffffffff
407"\n movq %3, 1*8(%1)"
408"\n"
409"\n movq 2*8(%0), %3"
410"\n sbbq $0, %3"
411"\n movq %3, 2*8(%1)"
412"\n"
413"\n movq 3*8(%0), %3"
414"\n sbbq $0, %3" // adding 00000000ffffffff (in %2)
415"\n addq %2, %3" // is the same as subtracting ffffffff00000001
416"\n movq %3, 3*8(%1)"
417"\n"
418 : "=r" (a), "=r" (r), "=r" (ooff), "=r" (reg)
419 : "0" (a), "1" (r), "2" (0x00000000ffffffff)
420 : "memory"
421 );
422}
393#else 423#else
394# define sp_256_sub_8_p256_mod(r, a) sp_256_sub_8((r), (a), p256_mod) 424# define sp_256_sub_8_p256_mod(r, a) sp_256_sub_8((r), (a), p256_mod)
395#endif 425#endif