mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-07-07 22:10:48 +02:00
Merge pull request #3510 from SparkiDev/sp_modinv_nct
SP modinv: add non-constant time modinv
This commit is contained in:
+12
-12
@@ -162,12 +162,12 @@ L_aes_gcm_mod2_128:
|
||||
.text
|
||||
.globl AES_GCM_encrypt
|
||||
.type AES_GCM_encrypt,@function
|
||||
.align 4
|
||||
.align 16
|
||||
AES_GCM_encrypt:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _AES_GCM_encrypt
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_AES_GCM_encrypt:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r13
|
||||
@@ -2016,12 +2016,12 @@ L_AES_GCM_encrypt_store_tag_done:
|
||||
.text
|
||||
.globl AES_GCM_decrypt
|
||||
.type AES_GCM_decrypt,@function
|
||||
.align 4
|
||||
.align 16
|
||||
AES_GCM_decrypt:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _AES_GCM_decrypt
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_AES_GCM_decrypt:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r13
|
||||
@@ -3555,12 +3555,12 @@ L_avx1_aes_gcm_mod2_128:
|
||||
.text
|
||||
.globl AES_GCM_encrypt_avx1
|
||||
.type AES_GCM_encrypt_avx1,@function
|
||||
.align 4
|
||||
.align 16
|
||||
AES_GCM_encrypt_avx1:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _AES_GCM_encrypt_avx1
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_AES_GCM_encrypt_avx1:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r13
|
||||
@@ -5135,12 +5135,12 @@ L_AES_GCM_encrypt_avx1_store_tag_done:
|
||||
.text
|
||||
.globl AES_GCM_decrypt_avx1
|
||||
.type AES_GCM_decrypt_avx1,@function
|
||||
.align 4
|
||||
.align 16
|
||||
AES_GCM_decrypt_avx1:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _AES_GCM_decrypt_avx1
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_AES_GCM_decrypt_avx1:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r13
|
||||
@@ -6455,12 +6455,12 @@ L_avx2_aes_gcm_mod2_128:
|
||||
.text
|
||||
.globl AES_GCM_encrypt_avx2
|
||||
.type AES_GCM_encrypt_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
AES_GCM_encrypt_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _AES_GCM_encrypt_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_AES_GCM_encrypt_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r13
|
||||
@@ -7763,12 +7763,12 @@ L_AES_GCM_encrypt_avx2_store_tag_done:
|
||||
.text
|
||||
.globl AES_GCM_decrypt_avx2
|
||||
.type AES_GCM_decrypt_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
AES_GCM_decrypt_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _AES_GCM_decrypt_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_AES_GCM_decrypt_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r13
|
||||
|
||||
@@ -30,12 +30,12 @@
|
||||
.text
|
||||
.globl chacha_encrypt_x64
|
||||
.type chacha_encrypt_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
chacha_encrypt_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _chacha_encrypt_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_chacha_encrypt_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -508,12 +508,12 @@ L_chacha20_avx1_four:
|
||||
.text
|
||||
.globl chacha_encrypt_avx1
|
||||
.type chacha_encrypt_avx1,@function
|
||||
.align 4
|
||||
.align 16
|
||||
chacha_encrypt_avx1:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _chacha_encrypt_avx1
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_chacha_encrypt_avx1:
|
||||
#endif /* __APPLE__ */
|
||||
subq $0x190, %rsp
|
||||
@@ -1066,12 +1066,12 @@ L_chacha20_avx2_eight:
|
||||
.text
|
||||
.globl chacha_encrypt_avx2
|
||||
.type chacha_encrypt_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
chacha_encrypt_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _chacha_encrypt_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_chacha_encrypt_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
subq $0x310, %rsp
|
||||
|
||||
+114
-114
@@ -30,12 +30,12 @@
|
||||
.text
|
||||
.globl fe_init
|
||||
.type fe_init,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_init:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_init
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_init:
|
||||
#endif /* __APPLE__ */
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
@@ -233,12 +233,12 @@ L_fe_init_flags_done:
|
||||
.text
|
||||
.globl fe_frombytes
|
||||
.type fe_frombytes,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_frombytes:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_frombytes
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_frombytes:
|
||||
#endif /* __APPLE__ */
|
||||
movq $0x7fffffffffffffff, %r9
|
||||
@@ -259,12 +259,12 @@ _fe_frombytes:
|
||||
.text
|
||||
.globl fe_tobytes
|
||||
.type fe_tobytes,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_tobytes:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_tobytes
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_tobytes:
|
||||
#endif /* __APPLE__ */
|
||||
movq $0x7fffffffffffffff, %r10
|
||||
@@ -299,12 +299,12 @@ _fe_tobytes:
|
||||
.text
|
||||
.globl fe_1
|
||||
.type fe_1,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_1:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_1
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_1:
|
||||
#endif /* __APPLE__ */
|
||||
# Set one
|
||||
@@ -320,12 +320,12 @@ _fe_1:
|
||||
.text
|
||||
.globl fe_0
|
||||
.type fe_0,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_0:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_0
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_0:
|
||||
#endif /* __APPLE__ */
|
||||
# Set zero
|
||||
@@ -341,12 +341,12 @@ _fe_0:
|
||||
.text
|
||||
.globl fe_copy
|
||||
.type fe_copy,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_copy:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_copy
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_copy:
|
||||
#endif /* __APPLE__ */
|
||||
# Copy
|
||||
@@ -366,12 +366,12 @@ _fe_copy:
|
||||
.text
|
||||
.globl fe_sub
|
||||
.type fe_sub,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_sub:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_sub
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_sub:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -409,12 +409,12 @@ _fe_sub:
|
||||
.text
|
||||
.globl fe_add
|
||||
.type fe_add,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_add:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_add
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_add:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -452,12 +452,12 @@ _fe_add:
|
||||
.text
|
||||
.globl fe_neg
|
||||
.type fe_neg,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_neg:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_neg
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_neg:
|
||||
#endif /* __APPLE__ */
|
||||
movq $-19, %rdx
|
||||
@@ -480,12 +480,12 @@ _fe_neg:
|
||||
.text
|
||||
.globl fe_cmov
|
||||
.type fe_cmov,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_cmov:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_cmov
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_cmov:
|
||||
#endif /* __APPLE__ */
|
||||
cmpl $0x01, %edx
|
||||
@@ -509,12 +509,12 @@ _fe_cmov:
|
||||
.text
|
||||
.globl fe_isnonzero
|
||||
.type fe_isnonzero,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_isnonzero:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_isnonzero
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_isnonzero:
|
||||
#endif /* __APPLE__ */
|
||||
movq $0x7fffffffffffffff, %r10
|
||||
@@ -548,12 +548,12 @@ _fe_isnonzero:
|
||||
.text
|
||||
.globl fe_isnegative
|
||||
.type fe_isnegative,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_isnegative:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_isnegative
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_isnegative:
|
||||
#endif /* __APPLE__ */
|
||||
movq $0x7fffffffffffffff, %r11
|
||||
@@ -578,12 +578,12 @@ _fe_isnegative:
|
||||
.text
|
||||
.globl fe_cmov_table
|
||||
.type fe_cmov_table,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_cmov_table:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_cmov_table
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_cmov_table:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -866,12 +866,12 @@ _fe_cmov_table:
|
||||
.text
|
||||
.globl fe_mul
|
||||
.type fe_mul,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_mul:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_mul
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_mul:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -886,12 +886,12 @@ _fe_mul:
|
||||
.text
|
||||
.globl fe_sq
|
||||
.type fe_sq,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_sq:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_sq
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_sq:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -906,12 +906,12 @@ _fe_sq:
|
||||
.text
|
||||
.globl fe_mul121666
|
||||
.type fe_mul121666,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_mul121666:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_mul121666
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_mul121666:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -926,12 +926,12 @@ _fe_mul121666:
|
||||
.text
|
||||
.globl fe_sq2
|
||||
.type fe_sq2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_sq2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_sq2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_sq2:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -946,12 +946,12 @@ _fe_sq2:
|
||||
.text
|
||||
.globl fe_invert
|
||||
.type fe_invert,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_invert:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_invert
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_invert:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -966,12 +966,12 @@ _fe_invert:
|
||||
.text
|
||||
.globl curve25519
|
||||
.type curve25519,@function
|
||||
.align 4
|
||||
.align 16
|
||||
curve25519:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _curve25519
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_curve25519:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -986,12 +986,12 @@ _curve25519:
|
||||
.text
|
||||
.globl fe_pow22523
|
||||
.type fe_pow22523,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_pow22523:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_pow22523
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_pow22523:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -1006,12 +1006,12 @@ _fe_pow22523:
|
||||
.text
|
||||
.globl fe_ge_to_p2
|
||||
.type fe_ge_to_p2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_to_p2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_to_p2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_to_p2:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -1026,12 +1026,12 @@ _fe_ge_to_p2:
|
||||
.text
|
||||
.globl fe_ge_to_p3
|
||||
.type fe_ge_to_p3,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_to_p3:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_to_p3
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_to_p3:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -1046,12 +1046,12 @@ _fe_ge_to_p3:
|
||||
.text
|
||||
.globl fe_ge_dbl
|
||||
.type fe_ge_dbl,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_dbl:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_dbl
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_dbl:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -1066,12 +1066,12 @@ _fe_ge_dbl:
|
||||
.text
|
||||
.globl fe_ge_madd
|
||||
.type fe_ge_madd,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_madd:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_madd
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_madd:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -1086,12 +1086,12 @@ _fe_ge_madd:
|
||||
.text
|
||||
.globl fe_ge_msub
|
||||
.type fe_ge_msub,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_msub:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_msub
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_msub:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -1106,12 +1106,12 @@ _fe_ge_msub:
|
||||
.text
|
||||
.globl fe_ge_add
|
||||
.type fe_ge_add,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_add:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_add
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_add:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -1126,12 +1126,12 @@ _fe_ge_add:
|
||||
.text
|
||||
.globl fe_ge_sub
|
||||
.type fe_ge_sub,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_sub:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_sub
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_sub:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -1338,12 +1338,12 @@ _fe_ge_sub_p:
|
||||
.text
|
||||
.globl fe_mul_x64
|
||||
.type fe_mul_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_mul_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_mul_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_mul_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -1518,12 +1518,12 @@ _fe_mul_x64:
|
||||
.text
|
||||
.globl fe_sq_x64
|
||||
.type fe_sq_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_sq_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_sq_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_sq_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -1668,12 +1668,12 @@ _fe_sq_x64:
|
||||
.text
|
||||
.globl fe_sq_n_x64
|
||||
.type fe_sq_n_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_sq_n_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_sq_n_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_sq_n_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -1824,12 +1824,12 @@ L_fe_sq_n_x64:
|
||||
.text
|
||||
.globl fe_mul121666_x64
|
||||
.type fe_mul121666_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_mul121666_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_mul121666_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_mul121666_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -1875,12 +1875,12 @@ _fe_mul121666_x64:
|
||||
.text
|
||||
.globl fe_sq2_x64
|
||||
.type fe_sq2_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_sq2_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_sq2_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_sq2_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -2038,12 +2038,12 @@ _fe_sq2_x64:
|
||||
.text
|
||||
.globl fe_invert_x64
|
||||
.type fe_invert_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_invert_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_invert_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_invert_x64:
|
||||
#endif /* __APPLE__ */
|
||||
subq $0x90, %rsp
|
||||
@@ -2294,12 +2294,12 @@ _fe_invert_x64:
|
||||
.text
|
||||
.globl curve25519_x64
|
||||
.type curve25519_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
curve25519_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _curve25519_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_curve25519_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -4304,12 +4304,12 @@ L_curve25519_x64_bits:
|
||||
.text
|
||||
.globl fe_pow22523_x64
|
||||
.type fe_pow22523_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_pow22523_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_pow22523_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_pow22523_x64:
|
||||
#endif /* __APPLE__ */
|
||||
subq $0x70, %rsp
|
||||
@@ -4559,12 +4559,12 @@ _fe_pow22523_x64:
|
||||
.text
|
||||
.globl fe_ge_to_p2_x64
|
||||
.type fe_ge_to_p2_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_to_p2_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_to_p2_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_to_p2_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -5059,12 +5059,12 @@ _fe_ge_to_p2_x64:
|
||||
.text
|
||||
.globl fe_ge_to_p3_x64
|
||||
.type fe_ge_to_p3_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_to_p3_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_to_p3_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_to_p3_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -5715,12 +5715,12 @@ _fe_ge_to_p3_x64:
|
||||
.text
|
||||
.globl fe_ge_dbl_x64
|
||||
.type fe_ge_dbl_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_dbl_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_dbl_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_dbl_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -6412,12 +6412,12 @@ _fe_ge_dbl_x64:
|
||||
.text
|
||||
.globl fe_ge_madd_x64
|
||||
.type fe_ge_madd_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_madd_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_madd_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_madd_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -7110,12 +7110,12 @@ _fe_ge_madd_x64:
|
||||
.text
|
||||
.globl fe_ge_msub_x64
|
||||
.type fe_ge_msub_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_msub_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_msub_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_msub_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -7808,12 +7808,12 @@ _fe_ge_msub_x64:
|
||||
.text
|
||||
.globl fe_ge_add_x64
|
||||
.type fe_ge_add_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_add_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_add_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_add_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -8662,12 +8662,12 @@ _fe_ge_add_x64:
|
||||
.text
|
||||
.globl fe_ge_sub_x64
|
||||
.type fe_ge_sub_x64,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_sub_x64:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_sub_x64
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_sub_x64:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -9517,12 +9517,12 @@ _fe_ge_sub_x64:
|
||||
.text
|
||||
.globl fe_mul_avx2
|
||||
.type fe_mul_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_mul_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_mul_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_mul_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -9669,12 +9669,12 @@ _fe_mul_avx2:
|
||||
.text
|
||||
.globl fe_sq_avx2
|
||||
.type fe_sq_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_sq_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_sq_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_sq_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -9796,12 +9796,12 @@ _fe_sq_avx2:
|
||||
.text
|
||||
.globl fe_sq_n_avx2
|
||||
.type fe_sq_n_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_sq_n_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_sq_n_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_sq_n_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -9929,12 +9929,12 @@ L_fe_sq_n_avx2:
|
||||
.text
|
||||
.globl fe_mul121666_avx2
|
||||
.type fe_mul121666_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_mul121666_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_mul121666_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_mul121666_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -9970,12 +9970,12 @@ _fe_mul121666_avx2:
|
||||
.text
|
||||
.globl fe_sq2_avx2
|
||||
.type fe_sq2_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_sq2_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_sq2_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_sq2_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -10108,12 +10108,12 @@ _fe_sq2_avx2:
|
||||
.text
|
||||
.globl fe_invert_avx2
|
||||
.type fe_invert_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_invert_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_invert_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_invert_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
subq $0x90, %rsp
|
||||
@@ -10364,12 +10364,12 @@ _fe_invert_avx2:
|
||||
.text
|
||||
.globl curve25519_avx2
|
||||
.type curve25519_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
curve25519_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _curve25519_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_curve25519_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -12095,12 +12095,12 @@ L_curve25519_avx2_bits:
|
||||
.text
|
||||
.globl fe_pow22523_avx2
|
||||
.type fe_pow22523_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_pow22523_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_pow22523_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_pow22523_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
subq $0x70, %rsp
|
||||
@@ -12350,12 +12350,12 @@ _fe_pow22523_avx2:
|
||||
.text
|
||||
.globl fe_ge_to_p2_avx2
|
||||
.type fe_ge_to_p2_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_to_p2_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_to_p2_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_to_p2_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -12765,12 +12765,12 @@ _fe_ge_to_p2_avx2:
|
||||
.text
|
||||
.globl fe_ge_to_p3_avx2
|
||||
.type fe_ge_to_p3_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_to_p3_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_to_p3_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_to_p3_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -13308,12 +13308,12 @@ _fe_ge_to_p3_avx2:
|
||||
.text
|
||||
.globl fe_ge_dbl_avx2
|
||||
.type fe_ge_dbl_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_dbl_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_dbl_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_dbl_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbp
|
||||
@@ -13894,12 +13894,12 @@ _fe_ge_dbl_avx2:
|
||||
.text
|
||||
.globl fe_ge_madd_avx2
|
||||
.type fe_ge_madd_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_madd_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_madd_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_madd_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbp
|
||||
@@ -14493,12 +14493,12 @@ _fe_ge_madd_avx2:
|
||||
.text
|
||||
.globl fe_ge_msub_avx2
|
||||
.type fe_ge_msub_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_msub_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_msub_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_msub_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbp
|
||||
@@ -15091,12 +15091,12 @@ _fe_ge_msub_avx2:
|
||||
.text
|
||||
.globl fe_ge_add_avx2
|
||||
.type fe_ge_add_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_add_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_add_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_add_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -15817,12 +15817,12 @@ _fe_ge_add_avx2:
|
||||
.text
|
||||
.globl fe_ge_sub_avx2
|
||||
.type fe_ge_sub_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
fe_ge_sub_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _fe_ge_sub_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_fe_ge_sub_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
|
||||
@@ -31,12 +31,12 @@
|
||||
.text
|
||||
.globl poly1305_setkey_avx
|
||||
.type poly1305_setkey_avx,@function
|
||||
.align 4
|
||||
.align 16
|
||||
poly1305_setkey_avx:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _poly1305_setkey_avx
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_poly1305_setkey_avx:
|
||||
#endif /* __APPLE__ */
|
||||
movabsq $0xffffffc0fffffff, %r10
|
||||
@@ -91,12 +91,12 @@ _poly1305_setkey_avx:
|
||||
.text
|
||||
.globl poly1305_block_avx
|
||||
.type poly1305_block_avx,@function
|
||||
.align 4
|
||||
.align 16
|
||||
poly1305_block_avx:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _poly1305_block_avx
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_poly1305_block_avx:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r15
|
||||
@@ -175,12 +175,12 @@ _poly1305_block_avx:
|
||||
.text
|
||||
.globl poly1305_blocks_avx
|
||||
.type poly1305_blocks_avx,@function
|
||||
.align 4
|
||||
.align 16
|
||||
poly1305_blocks_avx:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _poly1305_blocks_avx
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_poly1305_blocks_avx:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r15
|
||||
@@ -263,12 +263,12 @@ L_poly1305_avx_blocks_start:
|
||||
.text
|
||||
.globl poly1305_final_avx
|
||||
.type poly1305_final_avx,@function
|
||||
.align 4
|
||||
.align 16
|
||||
poly1305_final_avx:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _poly1305_final_avx
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_poly1305_final_avx:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -346,12 +346,12 @@ L_poly1305_avx_final_no_more:
|
||||
.text
|
||||
.globl poly1305_calc_powers_avx2
|
||||
.type poly1305_calc_powers_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
poly1305_calc_powers_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _poly1305_calc_powers_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_poly1305_calc_powers_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -614,12 +614,12 @@ _poly1305_calc_powers_avx2:
|
||||
.text
|
||||
.globl poly1305_setkey_avx2
|
||||
.type poly1305_setkey_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
poly1305_setkey_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _poly1305_setkey_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_poly1305_setkey_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
#ifndef __APPLE__
|
||||
@@ -669,12 +669,12 @@ L_poly1305_avx2_blocks_hibit:
|
||||
.text
|
||||
.globl poly1305_blocks_avx2
|
||||
.type poly1305_blocks_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
poly1305_blocks_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _poly1305_blocks_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_poly1305_blocks_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %r12
|
||||
@@ -1029,12 +1029,12 @@ L_poly1305_avx2_blocks_complete:
|
||||
.text
|
||||
.globl poly1305_final_avx2
|
||||
.type poly1305_final_avx2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
poly1305_final_avx2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _poly1305_final_avx2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_poly1305_final_avx2:
|
||||
#endif /* __APPLE__ */
|
||||
movb $0x01, 616(%rdi)
|
||||
|
||||
+16
-16
@@ -89,12 +89,12 @@ L_avx1_sha256_flip_mask:
|
||||
.text
|
||||
.globl Transform_Sha256_AVX1
|
||||
.type Transform_Sha256_AVX1,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha256_AVX1:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha256_AVX1
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha256_AVX1:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -2479,12 +2479,12 @@ _Transform_Sha256_AVX1:
|
||||
.text
|
||||
.globl Transform_Sha256_AVX1_Len
|
||||
.type Transform_Sha256_AVX1_Len,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha256_AVX1_Len:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha256_AVX1_Len
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha256_AVX1_Len:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -4943,12 +4943,12 @@ L_avx1_rorx_sha256_flip_mask:
|
||||
.text
|
||||
.globl Transform_Sha256_AVX1_RORX
|
||||
.type Transform_Sha256_AVX1_RORX,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha256_AVX1_RORX:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha256_AVX1_RORX
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha256_AVX1_RORX:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -7291,12 +7291,12 @@ _Transform_Sha256_AVX1_RORX:
|
||||
.text
|
||||
.globl Transform_Sha256_AVX1_RORX_Len
|
||||
.type Transform_Sha256_AVX1_RORX_Len,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha256_AVX1_RORX_Len:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha256_AVX1_RORX_Len
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha256_AVX1_RORX_Len:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -9735,12 +9735,12 @@ L_avx2_sha256_flip_mask:
|
||||
.text
|
||||
.globl Transform_Sha256_AVX2
|
||||
.type Transform_Sha256_AVX2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha256_AVX2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha256_AVX2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha256_AVX2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -12125,12 +12125,12 @@ _Transform_Sha256_AVX2:
|
||||
.text
|
||||
.globl Transform_Sha256_AVX2_Len
|
||||
.type Transform_Sha256_AVX2_Len,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha256_AVX2_Len:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha256_AVX2_Len
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha256_AVX2_Len:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -16331,12 +16331,12 @@ L_avx2_rorx_sha256_shuf_DC00:
|
||||
.text
|
||||
.globl Transform_Sha256_AVX2_RORX
|
||||
.type Transform_Sha256_AVX2_RORX,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha256_AVX2_RORX:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha256_AVX2_RORX
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha256_AVX2_RORX:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -18696,12 +18696,12 @@ _Transform_Sha256_AVX2_RORX:
|
||||
.text
|
||||
.globl Transform_Sha256_AVX2_RORX_Len
|
||||
.type Transform_Sha256_AVX2_RORX_Len,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha256_AVX2_RORX_Len:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha256_AVX2_RORX_Len
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha256_AVX2_RORX_Len:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
|
||||
+16
-16
@@ -94,12 +94,12 @@ L_avx1_sha512_flip_mask:
|
||||
.text
|
||||
.globl Transform_Sha512_AVX1
|
||||
.type Transform_Sha512_AVX1,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha512_AVX1:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha512_AVX1
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha512_AVX1:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -1368,12 +1368,12 @@ L_sha256_len_avx1_start:
|
||||
.text
|
||||
.globl Transform_Sha512_AVX1_Len
|
||||
.type Transform_Sha512_AVX1_Len,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha512_AVX1_Len:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha512_AVX1_Len
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha512_AVX1_Len:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -2724,12 +2724,12 @@ L_avx1_rorx_sha512_flip_mask:
|
||||
.text
|
||||
.globl Transform_Sha512_AVX1_RORX
|
||||
.type Transform_Sha512_AVX1_RORX,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha512_AVX1_RORX:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha512_AVX1_RORX
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha512_AVX1_RORX:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -3927,12 +3927,12 @@ L_sha256_len_avx1_rorx_start:
|
||||
.text
|
||||
.globl Transform_Sha512_AVX1_RORX_Len
|
||||
.type Transform_Sha512_AVX1_RORX_Len,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha512_AVX1_RORX_Len:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha512_AVX1_RORX_Len
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha512_AVX1_RORX_Len:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -5334,12 +5334,12 @@ L_avx2_sha512_flip_mask:
|
||||
.text
|
||||
.globl Transform_Sha512_AVX2
|
||||
.type Transform_Sha512_AVX2,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha512_AVX2:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha512_AVX2
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha512_AVX2:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -6396,12 +6396,12 @@ L_sha256_avx2_start:
|
||||
.text
|
||||
.globl Transform_Sha512_AVX2_Len
|
||||
.type Transform_Sha512_AVX2_Len,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha512_AVX2_Len:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha512_AVX2_Len
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha512_AVX2_Len:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -8191,12 +8191,12 @@ L_avx2_rorx_sha512_flip_mask:
|
||||
.text
|
||||
.globl Transform_Sha512_AVX2_RORX
|
||||
.type Transform_Sha512_AVX2_RORX,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha512_AVX2_RORX:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha512_AVX2_RORX
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha512_AVX2_RORX:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
@@ -9195,12 +9195,12 @@ L_sha256_len_avx2_rorx_start:
|
||||
.text
|
||||
.globl Transform_Sha512_AVX2_RORX_Len
|
||||
.type Transform_Sha512_AVX2_RORX_Len,@function
|
||||
.align 4
|
||||
.align 16
|
||||
Transform_Sha512_AVX2_RORX_Len:
|
||||
#else
|
||||
.section __TEXT,__text
|
||||
.globl _Transform_Sha512_AVX2_RORX_Len
|
||||
.p2align 2
|
||||
.p2align 4
|
||||
_Transform_Sha512_AVX2_RORX_Len:
|
||||
#endif /* __APPLE__ */
|
||||
pushq %rbx
|
||||
|
||||
+653
-10
@@ -31807,7 +31807,7 @@ typedef struct sp_256_proj_point_add_8_ctx {
|
||||
sp_digit* z;
|
||||
} sp_256_proj_point_add_8_ctx;
|
||||
|
||||
static int sp_256_proj_point_add_8_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
static int sp_256_proj_point_add_8_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
const sp_point_256* p, const sp_point_256* q, sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
@@ -36466,7 +36466,7 @@ static int sp_256_mont_inv_order_8_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_mont_inv_order_8_ctx* ctx = (sp_256_mont_inv_order_8_ctx*)sp_ctx;
|
||||
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_mont_inv_order_8_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
@@ -36665,9 +36665,9 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W
|
||||
}
|
||||
XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
|
||||
ctx->state = 2;
|
||||
break;
|
||||
break;
|
||||
case 2: /* MULMOD */
|
||||
err = sp_256_ecc_mulmod_8_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
err = sp_256_ecc_mulmod_8_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
&ctx->point, &p256_base, ctx->k, 1, 1, heap);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 3;
|
||||
@@ -36920,6 +36920,293 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, mp_int* priv,
|
||||
}
|
||||
#endif /* HAVE_ECC_SIGN */
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
static void sp_256_rshift1_8(sp_digit* r, sp_digit* a)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"mov r10, #0\n\t"
|
||||
"mov r9, #0\n\t"
|
||||
"ldr r3, [%[a], #16]\n\t"
|
||||
"ldr r4, [%[a], #20]\n\t"
|
||||
"ldr r5, [%[a], #24]\n\t"
|
||||
"ldr r6, [%[a], #28]\n\t"
|
||||
"lsr r7, r3, #1\n\t"
|
||||
"and r3, r3, #1\n\t"
|
||||
"lsr r8, r4, #1\n\t"
|
||||
"lsr r10, r5, #1\n\t"
|
||||
"lsr r14, r6, #1\n\t"
|
||||
"orr r7, r7, r4, lsl #31\n\t"
|
||||
"orr r8, r8, r5, lsl #31\n\t"
|
||||
"orr r10, r10, r6, lsl #31\n\t"
|
||||
"orr r14, r14, r9, lsl #31\n\t"
|
||||
"mov r9, r3\n\t"
|
||||
"str r7, [%[r], #16]\n\t"
|
||||
"str r8, [%[r], #20]\n\t"
|
||||
"str r10, [%[r], #24]\n\t"
|
||||
"str r14, [%[r], #28]\n\t"
|
||||
"ldr r3, [%[r], #0]\n\t"
|
||||
"ldr r4, [%[r], #4]\n\t"
|
||||
"ldr r5, [%[r], #8]\n\t"
|
||||
"ldr r6, [%[r], #12]\n\t"
|
||||
"lsr r7, r3, #1\n\t"
|
||||
"lsr r8, r4, #1\n\t"
|
||||
"lsr r10, r5, #1\n\t"
|
||||
"lsr r14, r6, #1\n\t"
|
||||
"orr r7, r7, r4, lsl #31\n\t"
|
||||
"orr r8, r8, r5, lsl #31\n\t"
|
||||
"orr r10, r10, r6, lsl #31\n\t"
|
||||
"orr r14, r14, r9, lsl #31\n\t"
|
||||
"str r7, [%[r], #0]\n\t"
|
||||
"str r8, [%[r], #4]\n\t"
|
||||
"str r10, [%[r], #8]\n\t"
|
||||
"str r14, [%[r], #12]\n\t"
|
||||
:
|
||||
: [r] "r" (r), [a] "r" (a)
|
||||
: "memory", "r3", "r4", "r5", "r6", "r7", "r8", "r10", "r14", "r9"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/* Divide the number by 2 mod the modulus. (r = a / 2 % m)
|
||||
*
|
||||
* r Result of division by 2.
|
||||
* a Number to divide.
|
||||
* m Modulus.
|
||||
*/
|
||||
static void sp_256_div2_mod_8(sp_digit* r, const sp_digit* a,
|
||||
const sp_digit* m)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"mov r10, #0\n\t"
|
||||
"ldr r3, [%[a], #0]\n\t"
|
||||
"ands r9, r3, #1\n\t"
|
||||
"beq 1f\n\t"
|
||||
"ldr r4, [%[a], #4]\n\t"
|
||||
"ldr r5, [%[a], #8]\n\t"
|
||||
"ldr r6, [%[a], #12]\n\t"
|
||||
"ldr r7, [%[m], #0]\n\t"
|
||||
"ldr r8, [%[m], #4]\n\t"
|
||||
"ldr r10, [%[m], #8]\n\t"
|
||||
"ldr r14, [%[m], #12]\n\t"
|
||||
"adds r3, r3, r7\n\t"
|
||||
"adcs r4, r4, r8\n\t"
|
||||
"adcs r5, r5, r10\n\t"
|
||||
"adcs r6, r6, r14\n\t"
|
||||
"str r3, [%[r], #0]\n\t"
|
||||
"str r4, [%[r], #4]\n\t"
|
||||
"str r5, [%[r], #8]\n\t"
|
||||
"str r6, [%[r], #12]\n\t"
|
||||
"ldr r3, [%[a], #16]\n\t"
|
||||
"ldr r4, [%[a], #20]\n\t"
|
||||
"ldr r5, [%[a], #24]\n\t"
|
||||
"ldr r6, [%[a], #28]\n\t"
|
||||
"ldr r7, [%[m], #16]\n\t"
|
||||
"ldr r8, [%[m], #20]\n\t"
|
||||
"ldr r10, [%[m], #24]\n\t"
|
||||
"ldr r14, [%[m], #28]\n\t"
|
||||
"adcs r3, r3, r7\n\t"
|
||||
"adcs r4, r4, r8\n\t"
|
||||
"adcs r5, r5, r10\n\t"
|
||||
"adcs r6, r6, r14\n\t"
|
||||
"adc r9, r10, r10\n\t"
|
||||
"b 2f\n\t"
|
||||
"\n1:\n\t"
|
||||
"ldr r3, [%[a], #16]\n\t"
|
||||
"ldr r4, [%[a], #20]\n\t"
|
||||
"ldr r5, [%[a], #24]\n\t"
|
||||
"ldr r6, [%[a], #28]\n\t"
|
||||
"\n2:\n\t"
|
||||
"lsr r7, r3, #1\n\t"
|
||||
"and r3, r3, #1\n\t"
|
||||
"lsr r8, r4, #1\n\t"
|
||||
"lsr r10, r5, #1\n\t"
|
||||
"lsr r14, r6, #1\n\t"
|
||||
"orr r7, r7, r4, lsl #31\n\t"
|
||||
"orr r8, r8, r5, lsl #31\n\t"
|
||||
"orr r10, r10, r6, lsl #31\n\t"
|
||||
"orr r14, r14, r9, lsl #31\n\t"
|
||||
"mov r9, r3\n\t"
|
||||
"str r7, [%[r], #16]\n\t"
|
||||
"str r8, [%[r], #20]\n\t"
|
||||
"str r10, [%[r], #24]\n\t"
|
||||
"str r14, [%[r], #28]\n\t"
|
||||
"ldr r3, [%[r], #0]\n\t"
|
||||
"ldr r4, [%[r], #4]\n\t"
|
||||
"ldr r5, [%[r], #8]\n\t"
|
||||
"ldr r6, [%[r], #12]\n\t"
|
||||
"lsr r7, r3, #1\n\t"
|
||||
"lsr r8, r4, #1\n\t"
|
||||
"lsr r10, r5, #1\n\t"
|
||||
"lsr r14, r6, #1\n\t"
|
||||
"orr r7, r7, r4, lsl #31\n\t"
|
||||
"orr r8, r8, r5, lsl #31\n\t"
|
||||
"orr r10, r10, r6, lsl #31\n\t"
|
||||
"orr r14, r14, r9, lsl #31\n\t"
|
||||
"str r7, [%[r], #0]\n\t"
|
||||
"str r8, [%[r], #4]\n\t"
|
||||
"str r10, [%[r], #8]\n\t"
|
||||
"str r14, [%[r], #12]\n\t"
|
||||
:
|
||||
: [r] "r" (r), [a] "r" (a), [m] "r" (m)
|
||||
: "memory", "r3", "r4", "r5", "r6", "r7", "r8", "r10", "r14", "r9"
|
||||
);
|
||||
}
|
||||
|
||||
static int sp_256_num_bits_8(sp_digit* a)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"ldr r2, [%[a], #28]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 7f\n\t"
|
||||
"mov r3, #256\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n7:\n\t"
|
||||
"ldr r2, [%[a], #24]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 6f\n\t"
|
||||
"mov r3, #224\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n6:\n\t"
|
||||
"ldr r2, [%[a], #20]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 5f\n\t"
|
||||
"mov r3, #192\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n5:\n\t"
|
||||
"ldr r2, [%[a], #16]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 4f\n\t"
|
||||
"mov r3, #160\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n4:\n\t"
|
||||
"ldr r2, [%[a], #12]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 3f\n\t"
|
||||
"mov r3, #128\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n3:\n\t"
|
||||
"ldr r2, [%[a], #8]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 2f\n\t"
|
||||
"mov r3, #96\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n2:\n\t"
|
||||
"ldr r2, [%[a], #4]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 1f\n\t"
|
||||
"mov r3, #64\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n1:\n\t"
|
||||
"ldr r2, [%[a], #0]\n\t"
|
||||
"mov r3, #32\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"\n9:\n\t"
|
||||
: [r] "+r" (r)
|
||||
: [a] "r" (a)
|
||||
: "r2", "r3"
|
||||
);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Non-constant time modular inversion.
|
||||
*
|
||||
* @param [out] r Resulting number.
|
||||
* @param [in] a Number to invert.
|
||||
* @param [in] m Modulus.
|
||||
* @return MP_OKAY on success.
|
||||
*/
|
||||
static int sp_256_mod_inv_8(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
{
|
||||
sp_digit u[8];
|
||||
sp_digit v[8];
|
||||
sp_digit b[8];
|
||||
sp_digit d[8];
|
||||
int ut, vt;
|
||||
sp_digit o;
|
||||
|
||||
XMEMCPY(u, m, sizeof(u));
|
||||
XMEMCPY(v, a, sizeof(v));
|
||||
|
||||
ut = sp_256_num_bits_8(u);
|
||||
vt = sp_256_num_bits_8(v);
|
||||
|
||||
XMEMSET(b, 0, sizeof(b));
|
||||
if ((v[0] & 1) == 0) {
|
||||
sp_256_rshift1_8(v, v);
|
||||
XMEMCPY(d, m, sizeof(u));
|
||||
d[0] += 1;
|
||||
sp_256_rshift1_8(d, d);
|
||||
vt--;
|
||||
|
||||
while ((v[0] & 1) == 0) {
|
||||
sp_256_rshift1_8(v, v);
|
||||
sp_256_div2_mod_8(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
XMEMSET(d+1, 0, sizeof(d)-sizeof(sp_digit));
|
||||
d[0] = 1;
|
||||
}
|
||||
|
||||
while (ut > 1 && vt > 1) {
|
||||
if (ut > vt || (ut == vt && sp_256_cmp_8(u, v) >= 0)) {
|
||||
sp_256_sub_8(u, u, v);
|
||||
o = sp_256_sub_8(b, b, d);
|
||||
if (o != 0)
|
||||
sp_256_add_8(b, b, m);
|
||||
ut = sp_256_num_bits_8(u);
|
||||
|
||||
do {
|
||||
sp_256_rshift1_8(u, u);
|
||||
sp_256_div2_mod_8(b, b, m);
|
||||
ut--;
|
||||
}
|
||||
while (ut > 0 && (u[0] & 1) == 0);
|
||||
}
|
||||
else {
|
||||
sp_256_sub_8(v, v, u);
|
||||
o = sp_256_sub_8(d, d, b);
|
||||
if (o != 0)
|
||||
sp_256_add_8(d, d, m);
|
||||
vt = sp_256_num_bits_8(v);
|
||||
|
||||
do {
|
||||
sp_256_rshift1_8(v, v);
|
||||
sp_256_div2_mod_8(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
while (vt > 0 && (v[0] & 1) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (ut == 1)
|
||||
XMEMCPY(r, b, sizeof(b));
|
||||
else
|
||||
XMEMCPY(r, d, sizeof(d));
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
/* Verify the signature values with the hash and public key.
|
||||
* e = Truncate(hash, 256)
|
||||
@@ -37045,7 +37332,7 @@ int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen,
|
||||
ctx->state = 11;
|
||||
break;
|
||||
case 10: /* DBL */
|
||||
err = sp_256_proj_point_dbl_8_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
err = sp_256_proj_point_dbl_8_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
&ctx->p2, ctx->tmp);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 11;
|
||||
@@ -37168,6 +37455,11 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
sp_256_from_mp(p2->y, 8, pY);
|
||||
sp_256_from_mp(p2->z, 8, pZ);
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_256_mod_inv_8(s, s, p256_order);
|
||||
}
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
{
|
||||
sp_256_mul_8(s, s, p256_norm_order);
|
||||
}
|
||||
@@ -37175,12 +37467,20 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
sp_256_norm_8(s);
|
||||
#ifdef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_256_mont_inv_order_8(s, s, tmp);
|
||||
sp_256_mont_mul_order_8(u1, u1, s);
|
||||
sp_256_mont_mul_order_8(u2, u2, s);
|
||||
}
|
||||
|
||||
#else
|
||||
{
|
||||
sp_256_mont_mul_order_8(u1, u1, s);
|
||||
sp_256_mont_mul_order_8(u2, u2, s);
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
err = sp_256_ecc_mulmod_base_8(p1, u1, 0, 0, heap);
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
@@ -41455,7 +41755,7 @@ typedef struct sp_384_proj_point_add_12_ctx {
|
||||
sp_digit* z;
|
||||
} sp_384_proj_point_add_12_ctx;
|
||||
|
||||
static int sp_384_proj_point_add_12_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
static int sp_384_proj_point_add_12_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
const sp_point_384* p, const sp_point_384* q, sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
@@ -45249,7 +45549,7 @@ static int sp_384_mont_inv_order_12_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_mont_inv_order_12_ctx* ctx = (sp_384_mont_inv_order_12_ctx*)sp_ctx;
|
||||
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_mont_inv_order_12_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
@@ -45419,9 +45719,9 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W
|
||||
}
|
||||
XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
|
||||
ctx->state = 2;
|
||||
break;
|
||||
break;
|
||||
case 2: /* MULMOD */
|
||||
err = sp_384_ecc_mulmod_12_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
err = sp_384_ecc_mulmod_12_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
&ctx->point, &p384_base, ctx->k, 1, 1, heap);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 3;
|
||||
@@ -45674,6 +45974,336 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, mp_int* priv,
|
||||
}
|
||||
#endif /* HAVE_ECC_SIGN */
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
/* Divide the number by 2 mod the modulus. (r = a / 2 % m)
|
||||
*
|
||||
* r Result of division by 2.
|
||||
* a Number to divide.
|
||||
* m Modulus.
|
||||
*/
|
||||
static void sp_384_div2_mod_12(sp_digit* r, const sp_digit* a,
|
||||
const sp_digit* m)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"ldr r4, [%[a]]\n\t"
|
||||
"ands r8, r4, #1\n\t"
|
||||
"beq 1f\n\t"
|
||||
"mov r12, #0\n\t"
|
||||
"ldr r5, [%[a], #4]\n\t"
|
||||
"ldr r6, [%[a], #8]\n\t"
|
||||
"ldr r7, [%[a], #12]\n\t"
|
||||
"ldr r8, [%[m], #0]\n\t"
|
||||
"ldr r9, [%[m], #4]\n\t"
|
||||
"ldr r10, [%[m], #8]\n\t"
|
||||
"ldr r14, [%[m], #12]\n\t"
|
||||
"adds r4, r4, r8\n\t"
|
||||
"adcs r5, r5, r9\n\t"
|
||||
"adcs r6, r6, r10\n\t"
|
||||
"adcs r7, r7, r14\n\t"
|
||||
"str r4, [%[r], #0]\n\t"
|
||||
"str r5, [%[r], #4]\n\t"
|
||||
"str r6, [%[r], #8]\n\t"
|
||||
"str r7, [%[r], #12]\n\t"
|
||||
"ldr r4, [%[a], #16]\n\t"
|
||||
"ldr r5, [%[a], #20]\n\t"
|
||||
"ldr r6, [%[a], #24]\n\t"
|
||||
"ldr r7, [%[a], #28]\n\t"
|
||||
"ldr r8, [%[m], #16]\n\t"
|
||||
"ldr r9, [%[m], #20]\n\t"
|
||||
"ldr r10, [%[m], #24]\n\t"
|
||||
"ldr r14, [%[m], #28]\n\t"
|
||||
"adcs r4, r4, r8\n\t"
|
||||
"adcs r5, r5, r9\n\t"
|
||||
"adcs r6, r6, r10\n\t"
|
||||
"adcs r7, r7, r14\n\t"
|
||||
"str r4, [%[r], #16]\n\t"
|
||||
"str r5, [%[r], #20]\n\t"
|
||||
"str r6, [%[r], #24]\n\t"
|
||||
"str r7, [%[r], #28]\n\t"
|
||||
"ldr r4, [%[a], #32]\n\t"
|
||||
"ldr r5, [%[a], #36]\n\t"
|
||||
"ldr r6, [%[a], #40]\n\t"
|
||||
"ldr r7, [%[a], #44]\n\t"
|
||||
"ldr r8, [%[m], #32]\n\t"
|
||||
"ldr r9, [%[m], #36]\n\t"
|
||||
"ldr r10, [%[m], #40]\n\t"
|
||||
"ldr r14, [%[m], #44]\n\t"
|
||||
"adcs r4, r4, r8\n\t"
|
||||
"adcs r5, r5, r9\n\t"
|
||||
"adcs r6, r6, r10\n\t"
|
||||
"adcs r7, r7, r14\n\t"
|
||||
"str r4, [%[r], #32]\n\t"
|
||||
"str r5, [%[r], #36]\n\t"
|
||||
"str r6, [%[r], #40]\n\t"
|
||||
"str r7, [%[r], #44]\n\t"
|
||||
"adc r8, r12, r12\n\t"
|
||||
"b 2f\n\t"
|
||||
"\n1:\n\t"
|
||||
"ldr r5, [%[a], #2]\n\t"
|
||||
"str r4, [%[r], #0]\n\t"
|
||||
"str r5, [%[r], #2]\n\t"
|
||||
"ldr r4, [%[a], #4]\n\t"
|
||||
"ldr r5, [%[a], #6]\n\t"
|
||||
"str r4, [%[r], #4]\n\t"
|
||||
"str r5, [%[r], #6]\n\t"
|
||||
"ldr r4, [%[a], #8]\n\t"
|
||||
"ldr r5, [%[a], #10]\n\t"
|
||||
"str r4, [%[r], #8]\n\t"
|
||||
"str r5, [%[r], #10]\n\t"
|
||||
"ldr r4, [%[a], #12]\n\t"
|
||||
"ldr r5, [%[a], #14]\n\t"
|
||||
"str r4, [%[r], #12]\n\t"
|
||||
"str r5, [%[r], #14]\n\t"
|
||||
"ldr r4, [%[a], #16]\n\t"
|
||||
"ldr r5, [%[a], #18]\n\t"
|
||||
"str r4, [%[r], #16]\n\t"
|
||||
"str r5, [%[r], #18]\n\t"
|
||||
"ldr r4, [%[a], #20]\n\t"
|
||||
"ldr r5, [%[a], #22]\n\t"
|
||||
"str r4, [%[r], #20]\n\t"
|
||||
"str r5, [%[r], #22]\n\t"
|
||||
"\n2:\n\t"
|
||||
"ldr r3, [%[r]]\n\t"
|
||||
"ldr r4, [%[r], #4]\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"ldr r5, [%[a], #8]\n\t"
|
||||
"str r3, [%[r], #0]\n\t"
|
||||
"orr r4, r4, r5, lsl #31\n\t"
|
||||
"lsr r5, r5, #1\n\t"
|
||||
"ldr r3, [%[a], #12]\n\t"
|
||||
"str r4, [%[r], #4]\n\t"
|
||||
"orr r5, r5, r3, lsl #31\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"ldr r4, [%[a], #16]\n\t"
|
||||
"str r5, [%[r], #8]\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"ldr r5, [%[a], #20]\n\t"
|
||||
"str r3, [%[r], #12]\n\t"
|
||||
"orr r4, r4, r5, lsl #31\n\t"
|
||||
"lsr r5, r5, #1\n\t"
|
||||
"ldr r3, [%[a], #24]\n\t"
|
||||
"str r4, [%[r], #16]\n\t"
|
||||
"orr r5, r5, r3, lsl #31\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"ldr r4, [%[a], #28]\n\t"
|
||||
"str r5, [%[r], #20]\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"ldr r5, [%[a], #32]\n\t"
|
||||
"str r3, [%[r], #24]\n\t"
|
||||
"orr r4, r4, r5, lsl #31\n\t"
|
||||
"lsr r5, r5, #1\n\t"
|
||||
"ldr r3, [%[a], #36]\n\t"
|
||||
"str r4, [%[r], #28]\n\t"
|
||||
"orr r5, r5, r3, lsl #31\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"ldr r4, [%[a], #40]\n\t"
|
||||
"str r5, [%[r], #32]\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"ldr r5, [%[a], #44]\n\t"
|
||||
"str r3, [%[r], #36]\n\t"
|
||||
"orr r4, r4, r5, lsl #31\n\t"
|
||||
"lsr r5, r5, #1\n\t"
|
||||
"orr r5, r5, r8, lsl #31\n\t"
|
||||
"str r4, [%[r], #40]\n\t"
|
||||
"str r5, [%[r], #44]\n\t"
|
||||
:
|
||||
: [r] "r" (r), [a] "r" (a), [m] "r" (m)
|
||||
: "memory", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r14"
|
||||
);
|
||||
}
|
||||
|
||||
static int sp_384_num_bits_12(sp_digit* a)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"ldr r2, [%[a], #44]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 11f\n\t"
|
||||
"mov r3, #384\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n11:\n\t"
|
||||
"ldr r2, [%[a], #40]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 10f\n\t"
|
||||
"mov r3, #352\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n10:\n\t"
|
||||
"ldr r2, [%[a], #36]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 9f\n\t"
|
||||
"mov r3, #320\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n9:\n\t"
|
||||
"ldr r2, [%[a], #32]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 8f\n\t"
|
||||
"mov r3, #288\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n8:\n\t"
|
||||
"ldr r2, [%[a], #28]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 7f\n\t"
|
||||
"mov r3, #256\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n7:\n\t"
|
||||
"ldr r2, [%[a], #24]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 6f\n\t"
|
||||
"mov r3, #224\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n6:\n\t"
|
||||
"ldr r2, [%[a], #20]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 5f\n\t"
|
||||
"mov r3, #192\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n5:\n\t"
|
||||
"ldr r2, [%[a], #16]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 4f\n\t"
|
||||
"mov r3, #160\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n4:\n\t"
|
||||
"ldr r2, [%[a], #12]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 3f\n\t"
|
||||
"mov r3, #128\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n3:\n\t"
|
||||
"ldr r2, [%[a], #8]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 2f\n\t"
|
||||
"mov r3, #96\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n2:\n\t"
|
||||
"ldr r2, [%[a], #4]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 1f\n\t"
|
||||
"mov r3, #64\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n1:\n\t"
|
||||
"ldr r2, [%[a], #0]\n\t"
|
||||
"mov r3, #32\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"\n13:\n\t"
|
||||
: [r] "+r" (r)
|
||||
: [a] "r" (a)
|
||||
: "r2", "r3"
|
||||
);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Non-constant time modular inversion.
|
||||
*
|
||||
* @param [out] r Resulting number.
|
||||
* @param [in] a Number to invert.
|
||||
* @param [in] m Modulus.
|
||||
* @return MP_OKAY on success.
|
||||
*/
|
||||
static int sp_384_mod_inv_12(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
{
|
||||
sp_digit u[12];
|
||||
sp_digit v[12];
|
||||
sp_digit b[12];
|
||||
sp_digit d[12];
|
||||
int ut, vt;
|
||||
sp_digit o;
|
||||
|
||||
XMEMCPY(u, m, sizeof(u));
|
||||
XMEMCPY(v, a, sizeof(v));
|
||||
|
||||
ut = sp_384_num_bits_12(u);
|
||||
vt = sp_384_num_bits_12(v);
|
||||
|
||||
XMEMSET(b, 0, sizeof(b));
|
||||
if ((v[0] & 1) == 0) {
|
||||
sp_384_rshift1_12(v, v);
|
||||
XMEMCPY(d, m, sizeof(u));
|
||||
d[0] += 1;
|
||||
sp_384_rshift1_12(d, d);
|
||||
vt--;
|
||||
|
||||
while ((v[0] & 1) == 0) {
|
||||
sp_384_rshift1_12(v, v);
|
||||
sp_384_div2_mod_12(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
XMEMSET(d+1, 0, sizeof(d)-sizeof(sp_digit));
|
||||
d[0] = 1;
|
||||
}
|
||||
|
||||
while (ut > 1 && vt > 1) {
|
||||
if (ut > vt || (ut == vt && sp_384_cmp_12(u, v) >= 0)) {
|
||||
sp_384_sub_12(u, u, v);
|
||||
o = sp_384_sub_12(b, b, d);
|
||||
if (o != 0)
|
||||
sp_384_add_12(b, b, m);
|
||||
ut = sp_384_num_bits_12(u);
|
||||
|
||||
do {
|
||||
sp_384_rshift1_12(u, u);
|
||||
sp_384_div2_mod_12(b, b, m);
|
||||
ut--;
|
||||
}
|
||||
while (ut > 0 && (u[0] & 1) == 0);
|
||||
}
|
||||
else {
|
||||
sp_384_sub_12(v, v, u);
|
||||
o = sp_384_sub_12(d, d, b);
|
||||
if (o != 0)
|
||||
sp_384_add_12(d, d, m);
|
||||
vt = sp_384_num_bits_12(v);
|
||||
|
||||
do {
|
||||
sp_384_rshift1_12(v, v);
|
||||
sp_384_div2_mod_12(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
while (vt > 0 && (v[0] & 1) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (ut == 1)
|
||||
XMEMCPY(r, b, sizeof(b));
|
||||
else
|
||||
XMEMCPY(r, d, sizeof(d));
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
/* Verify the signature values with the hash and public key.
|
||||
* e = Truncate(hash, 384)
|
||||
@@ -45799,7 +46429,7 @@ int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen,
|
||||
ctx->state = 11;
|
||||
break;
|
||||
case 10: /* DBL */
|
||||
err = sp_384_proj_point_dbl_12_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
err = sp_384_proj_point_dbl_12_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
&ctx->p2, ctx->tmp);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 11;
|
||||
@@ -45922,6 +46552,11 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
sp_384_from_mp(p2->y, 12, pY);
|
||||
sp_384_from_mp(p2->z, 12, pZ);
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_384_mod_inv_12(s, s, p384_order);
|
||||
}
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
{
|
||||
sp_384_mul_12(s, s, p384_norm_order);
|
||||
}
|
||||
@@ -45929,12 +46564,20 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
sp_384_norm_12(s);
|
||||
#ifdef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_384_mont_inv_order_12(s, s, tmp);
|
||||
sp_384_mont_mul_order_12(u1, u1, s);
|
||||
sp_384_mont_mul_order_12(u2, u2, s);
|
||||
}
|
||||
|
||||
#else
|
||||
{
|
||||
sp_384_mont_mul_order_12(u1, u1, s);
|
||||
sp_384_mont_mul_order_12(u2, u2, s);
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
err = sp_384_ecc_mulmod_base_12(p1, u1, 0, 0, heap);
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
|
||||
+498
-15
@@ -1208,7 +1208,7 @@ SP_NOINLINE static void sp_2048_sqr_16(sp_digit* r, const sp_digit* a)
|
||||
u += sp_2048_add_16(r + 8, r + 8, z1);
|
||||
u += sp_2048_add_8(r + 16, r + 16, z2);
|
||||
sp_2048_add_zero_8(r + 24, z2 + 8, u);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Sub b from a into a. (a -= b)
|
||||
@@ -1629,7 +1629,7 @@ SP_NOINLINE static void sp_2048_sqr_32(sp_digit* r, const sp_digit* a)
|
||||
u += sp_2048_add_32(r + 16, r + 16, z1);
|
||||
u += sp_2048_add_16(r + 32, r + 32, z2);
|
||||
sp_2048_add_zero_16(r + 48, z2 + 16, u);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
@@ -8126,7 +8126,7 @@ SP_NOINLINE static void sp_3072_sqr_24(sp_digit* r, const sp_digit* a)
|
||||
u += sp_3072_add_24(r + 12, r + 12, z1);
|
||||
u += sp_3072_add_12(r + 24, r + 24, z2);
|
||||
sp_3072_add_zero_12(r + 36, z2 + 12, u);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Sub b from a into a. (a -= b)
|
||||
@@ -8661,7 +8661,7 @@ SP_NOINLINE static void sp_3072_sqr_48(sp_digit* r, const sp_digit* a)
|
||||
u += sp_3072_add_48(r + 24, r + 24, z1);
|
||||
u += sp_3072_add_24(r + 48, r + 48, z2);
|
||||
sp_3072_add_zero_24(r + 72, z2 + 24, u);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
@@ -14651,7 +14651,7 @@ SP_NOINLINE static void sp_4096_sqr_64(sp_digit* r, const sp_digit* a)
|
||||
u += sp_4096_add_64(r + 32, r + 32, z1);
|
||||
u += sp_4096_add_32(r + 64, r + 64, z2);
|
||||
sp_4096_add_zero_32(r + 96, z2 + 32, u);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
@@ -20611,7 +20611,7 @@ typedef struct sp_256_proj_point_add_4_ctx {
|
||||
sp_digit* z;
|
||||
} sp_256_proj_point_add_4_ctx;
|
||||
|
||||
static int sp_256_proj_point_add_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
static int sp_256_proj_point_add_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
const sp_point_256* p, const sp_point_256* q, sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
@@ -36877,7 +36877,7 @@ static int sp_256_mont_inv_order_4_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_mont_inv_order_4_ctx* ctx = (sp_256_mont_inv_order_4_ctx*)sp_ctx;
|
||||
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_mont_inv_order_4_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
@@ -37076,9 +37076,9 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W
|
||||
}
|
||||
XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
|
||||
ctx->state = 2;
|
||||
break;
|
||||
break;
|
||||
case 2: /* MULMOD */
|
||||
err = sp_256_ecc_mulmod_4_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
err = sp_256_ecc_mulmod_4_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
&ctx->point, &p256_base, ctx->k, 1, 1, heap);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 3;
|
||||
@@ -37331,6 +37331,293 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, mp_int* priv,
|
||||
}
|
||||
#endif /* HAVE_ECC_SIGN */
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
/* Non-constant time modular inversion.
|
||||
*
|
||||
* @param [out] r Resulting number.
|
||||
* @param [in] a Number to invert.
|
||||
* @param [in] m Modulus.
|
||||
* @return MP_OKAY on success.
|
||||
*/
|
||||
static int sp_256_mod_inv_4(sp_digit* r, const sp_digit* a,
|
||||
const sp_digit* m)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"ldr x20, [%[m], 0]\n\t"
|
||||
"ldr x21, [%[m], 8]\n\t"
|
||||
"ldr x22, [%[m], 16]\n\t"
|
||||
"ldr x23, [%[m], 24]\n\t"
|
||||
"ldr x7, [%[a], 0]\n\t"
|
||||
"ldr x8, [%[a], 8]\n\t"
|
||||
"ldr x9, [%[a], 16]\n\t"
|
||||
"ldr x10, [%[a], 24]\n\t"
|
||||
"mov x3, x20\n\t"
|
||||
"mov x4, x21\n\t"
|
||||
"mov x5, x22\n\t"
|
||||
"mov x6, x23\n\t"
|
||||
"mov x11, xzr\n\t"
|
||||
"mov x12, xzr\n\t"
|
||||
"mov x13, xzr\n\t"
|
||||
"mov x14, xzr\n\t"
|
||||
"mov x15, 1\n\t"
|
||||
"mov x16, xzr\n\t"
|
||||
"mov x17, xzr\n\t"
|
||||
"mov x19, xzr\n\t"
|
||||
"cmp x6, 0\n\t"
|
||||
"b.eq 10f\n\t"
|
||||
"mov x26, 256\n\t"
|
||||
"clz x24, x6\n\t"
|
||||
"sub x24, x26, x24\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n10:\n\t"
|
||||
"cmp x5, 0\n\t"
|
||||
"b.eq 11f\n\t"
|
||||
"mov x26, 192\n\t"
|
||||
"clz x24, x5\n\t"
|
||||
"sub x24, x26, x24\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n11:\n\t"
|
||||
"cmp x4, 0\n\t"
|
||||
"b.eq 12f\n\t"
|
||||
"mov x26, 128\n\t"
|
||||
"clz x24, x4\n\t"
|
||||
"sub x24, x26, x24\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n12:\n\t"
|
||||
"mov x26, 64\n\t"
|
||||
"clz x24, x3\n\t"
|
||||
"sub x24, x26, x24\n\t"
|
||||
"\n13:\n\t"
|
||||
"cmp x10, 0\n\t"
|
||||
"b.eq 20f\n\t"
|
||||
"mov x26, 256\n\t"
|
||||
"clz x25, x10\n\t"
|
||||
"sub x25, x26, x25\n\t"
|
||||
"b 23f\n\t"
|
||||
"\n20:\n\t"
|
||||
"cmp x9, 0\n\t"
|
||||
"b.eq 21f\n\t"
|
||||
"mov x26, 192\n\t"
|
||||
"clz x25, x9\n\t"
|
||||
"sub x25, x26, x25\n\t"
|
||||
"b 23f\n\t"
|
||||
"\n21:\n\t"
|
||||
"cmp x8, 0\n\t"
|
||||
"b.eq 22f\n\t"
|
||||
"mov x26, 128\n\t"
|
||||
"clz x25, x8\n\t"
|
||||
"sub x25, x26, x25\n\t"
|
||||
"b 23f\n\t"
|
||||
"\n22:\n\t"
|
||||
"mov x26, 64\n\t"
|
||||
"clz x25, x7\n\t"
|
||||
"sub x25, x26, x25\n\t"
|
||||
"\n23:\n\t"
|
||||
"tst x7, 1\n\t"
|
||||
"b.ne 90f\n\t"
|
||||
"\n1:\n\t"
|
||||
"lsr x7, x7, 1\n\t"
|
||||
"lsr x27, x8, 1\n\t"
|
||||
"lsr x28, x9, 1\n\t"
|
||||
"orr x7, x7, x8, lsl 63\n\t"
|
||||
"orr x8, x27, x9, lsl 63\n\t"
|
||||
"orr x9, x28, x10, lsl 63\n\t"
|
||||
"lsr x10, x10, 1\n\t"
|
||||
"sub x25, x25, 1\n\t"
|
||||
"ands x26, x15, 1\n\t"
|
||||
"b.eq 2f\n\t"
|
||||
"adds x15, x15, x20\n\t"
|
||||
"adcs x16, x16, x21\n\t"
|
||||
"adcs x17, x17, x22\n\t"
|
||||
"adcs x19, x19, x23\n\t"
|
||||
"cset x26, cs\n\t"
|
||||
"\n2:\n\t"
|
||||
"lsr x15, x15, 1\n\t"
|
||||
"lsr x27, x16, 1\n\t"
|
||||
"lsr x28, x17, 1\n\t"
|
||||
"lsr x29, x19, 1\n\t"
|
||||
"orr x15, x15, x16, lsl 63\n\t"
|
||||
"orr x16, x27, x17, lsl 63\n\t"
|
||||
"orr x17, x28, x19, lsl 63\n\t"
|
||||
"orr x19, x29, x26, lsl 63\n\t"
|
||||
"tst x7, 1\n\t"
|
||||
"b.eq 1b\n\t"
|
||||
"\n90:\n\t"
|
||||
"cmp x24, 1\n\t"
|
||||
"b.eq 100f\n\t"
|
||||
"cmp x25, 1\n\t"
|
||||
"b.eq 101f\n\t"
|
||||
"cmp x24, x25\n\t"
|
||||
"b.hi 91f\n\t"
|
||||
"b.cc 92f\n\t"
|
||||
"cmp x6, x10\n\t"
|
||||
"b.hi 91f\n\t"
|
||||
"b.cc 92f\n\t"
|
||||
"cmp x5, x9\n\t"
|
||||
"b.hi 91f\n\t"
|
||||
"b.cc 92f\n\t"
|
||||
"cmp x4, x8\n\t"
|
||||
"b.hi 91f\n\t"
|
||||
"b.cc 92f\n\t"
|
||||
"cmp x3, x7\n\t"
|
||||
"b.cc 92f\n\t"
|
||||
"\n91:\n\t"
|
||||
"subs x3, x3, x7\n\t"
|
||||
"sbcs x4, x4, x8\n\t"
|
||||
"sbcs x5, x5, x9\n\t"
|
||||
"sbc x6, x6, x10\n\t"
|
||||
"subs x11, x11, x15\n\t"
|
||||
"sbcs x12, x12, x16\n\t"
|
||||
"sbcs x13, x13, x17\n\t"
|
||||
"sbcs x14, x14, x19\n\t"
|
||||
"b.cs 30f\n\t"
|
||||
"adds x11, x11, x20\n\t"
|
||||
"adcs x12, x12, x21\n\t"
|
||||
"adcs x13, x13, x22\n\t"
|
||||
"adc x14, x14, x23\n\t"
|
||||
"\n30:\n\t"
|
||||
"cmp x6, 0\n\t"
|
||||
"b.eq 40f\n\t"
|
||||
"mov x26, 256\n\t"
|
||||
"clz x24, x6\n\t"
|
||||
"sub x24, x26, x24\n\t"
|
||||
"b 43f\n\t"
|
||||
"\n40:\n\t"
|
||||
"cmp x5, 0\n\t"
|
||||
"b.eq 41f\n\t"
|
||||
"mov x26, 192\n\t"
|
||||
"clz x24, x5\n\t"
|
||||
"sub x24, x26, x24\n\t"
|
||||
"b 43f\n\t"
|
||||
"\n41:\n\t"
|
||||
"cmp x4, 0\n\t"
|
||||
"b.eq 42f\n\t"
|
||||
"mov x26, 128\n\t"
|
||||
"clz x24, x4\n\t"
|
||||
"sub x24, x26, x24\n\t"
|
||||
"b 43f\n\t"
|
||||
"\n42:\n\t"
|
||||
"mov x26, 64\n\t"
|
||||
"clz x24, x3\n\t"
|
||||
"sub x24, x26, x24\n\t"
|
||||
"\n43:\n\t"
|
||||
"\n50:\n\t"
|
||||
"lsr x3, x3, 1\n\t"
|
||||
"lsr x27, x4, 1\n\t"
|
||||
"lsr x28, x5, 1\n\t"
|
||||
"orr x3, x3, x4, lsl 63\n\t"
|
||||
"orr x4, x27, x5, lsl 63\n\t"
|
||||
"orr x5, x28, x6, lsl 63\n\t"
|
||||
"lsr x6, x6, 1\n\t"
|
||||
"sub x24, x24, 1\n\t"
|
||||
"ands x26, x11, 1\n\t"
|
||||
"b.eq 51f\n\t"
|
||||
"adds x11, x11, x20\n\t"
|
||||
"adcs x12, x12, x21\n\t"
|
||||
"adcs x13, x13, x22\n\t"
|
||||
"adcs x14, x14, x23\n\t"
|
||||
"cset x26, cs\n\t"
|
||||
"\n51:\n\t"
|
||||
"lsr x11, x11, 1\n\t"
|
||||
"lsr x27, x12, 1\n\t"
|
||||
"lsr x28, x13, 1\n\t"
|
||||
"lsr x29, x14, 1\n\t"
|
||||
"orr x11, x11, x12, lsl 63\n\t"
|
||||
"orr x12, x27, x13, lsl 63\n\t"
|
||||
"orr x13, x28, x14, lsl 63\n\t"
|
||||
"orr x14, x29, x26, lsl 63\n\t"
|
||||
"tst x3, 1\n\t"
|
||||
"b.eq 50b\n\t"
|
||||
"b 90b\n\t"
|
||||
"\n92:\n\t"
|
||||
"subs x7, x7, x3\n\t"
|
||||
"sbcs x8, x8, x4\n\t"
|
||||
"sbcs x9, x9, x5\n\t"
|
||||
"sbc x10, x10, x6\n\t"
|
||||
"subs x15, x15, x11\n\t"
|
||||
"sbcs x16, x16, x12\n\t"
|
||||
"sbcs x17, x17, x13\n\t"
|
||||
"sbcs x19, x19, x14\n\t"
|
||||
"b.cs 60f\n\t"
|
||||
"adds x15, x15, x20\n\t"
|
||||
"adcs x16, x16, x21\n\t"
|
||||
"adcs x17, x17, x22\n\t"
|
||||
"adc x19, x19, x23\n\t"
|
||||
"\n60:\n\t"
|
||||
"cmp x10, 0\n\t"
|
||||
"b.eq 70f\n\t"
|
||||
"mov x26, 256\n\t"
|
||||
"clz x25, x10\n\t"
|
||||
"sub x25, x26, x25\n\t"
|
||||
"b 73f\n\t"
|
||||
"\n70:\n\t"
|
||||
"cmp x9, 0\n\t"
|
||||
"b.eq 71f\n\t"
|
||||
"mov x26, 192\n\t"
|
||||
"clz x25, x9\n\t"
|
||||
"sub x25, x26, x25\n\t"
|
||||
"b 73f\n\t"
|
||||
"\n71:\n\t"
|
||||
"cmp x8, 0\n\t"
|
||||
"b.eq 72f\n\t"
|
||||
"mov x26, 128\n\t"
|
||||
"clz x25, x8\n\t"
|
||||
"sub x25, x26, x25\n\t"
|
||||
"b 73f\n\t"
|
||||
"\n72:\n\t"
|
||||
"mov x26, 64\n\t"
|
||||
"clz x25, x7\n\t"
|
||||
"sub x25, x26, x25\n\t"
|
||||
"\n73:\n\t"
|
||||
"\n80:\n\t"
|
||||
"lsr x7, x7, 1\n\t"
|
||||
"lsr x27, x8, 1\n\t"
|
||||
"lsr x28, x9, 1\n\t"
|
||||
"orr x7, x7, x8, lsl 63\n\t"
|
||||
"orr x8, x27, x9, lsl 63\n\t"
|
||||
"orr x9, x28, x10, lsl 63\n\t"
|
||||
"lsr x10, x10, 1\n\t"
|
||||
"sub x25, x25, 1\n\t"
|
||||
"ands x26, x15, 1\n\t"
|
||||
"b.eq 81f\n\t"
|
||||
"adds x15, x15, x20\n\t"
|
||||
"adcs x16, x16, x21\n\t"
|
||||
"adcs x17, x17, x22\n\t"
|
||||
"adcs x19, x19, x23\n\t"
|
||||
"cset x26, cs\n\t"
|
||||
"\n81:\n\t"
|
||||
"lsr x15, x15, 1\n\t"
|
||||
"lsr x27, x16, 1\n\t"
|
||||
"lsr x28, x17, 1\n\t"
|
||||
"lsr x29, x19, 1\n\t"
|
||||
"orr x15, x15, x16, lsl 63\n\t"
|
||||
"orr x16, x27, x17, lsl 63\n\t"
|
||||
"orr x17, x28, x19, lsl 63\n\t"
|
||||
"orr x19, x29, x26, lsl 63\n\t"
|
||||
"tst x7, 1\n\t"
|
||||
"b.eq 80b\n\t"
|
||||
"b 90b\n\t"
|
||||
"\n100:\n\t"
|
||||
"str x11, [%[r], 0]\n\t"
|
||||
"str x12, [%[r], 8]\n\t"
|
||||
"str x13, [%[r], 16]\n\t"
|
||||
"str x14, [%[r], 24]\n\t"
|
||||
"b 102f\n\t"
|
||||
"\n101:\n\t"
|
||||
"str x15, [%[r], 0]\n\t"
|
||||
"str x16, [%[r], 8]\n\t"
|
||||
"str x17, [%[r], 16]\n\t"
|
||||
"str x19, [%[r], 24]\n\t"
|
||||
"\n102:\n\t"
|
||||
:
|
||||
: [r] "r" (r), [a] "r" (a), [m] "r" (m)
|
||||
: "memory", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "x29"
|
||||
);
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
/* Verify the signature values with the hash and public key.
|
||||
* e = Truncate(hash, 256)
|
||||
@@ -37456,7 +37743,7 @@ int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen,
|
||||
ctx->state = 11;
|
||||
break;
|
||||
case 10: /* DBL */
|
||||
err = sp_256_proj_point_dbl_4_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
err = sp_256_proj_point_dbl_4_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
&ctx->p2, ctx->tmp);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 11;
|
||||
@@ -37579,6 +37866,11 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
sp_256_from_mp(p2->y, 4, pY);
|
||||
sp_256_from_mp(p2->z, 4, pZ);
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_256_mod_inv_4(s, s, p256_order);
|
||||
}
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
{
|
||||
sp_256_mul_4(s, s, p256_norm_order);
|
||||
}
|
||||
@@ -37586,12 +37878,20 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
sp_256_norm_4(s);
|
||||
#ifdef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_256_mont_inv_order_4(s, s, tmp);
|
||||
sp_256_mont_mul_order_4(u1, u1, s);
|
||||
sp_256_mont_mul_order_4(u2, u2, s);
|
||||
}
|
||||
|
||||
#else
|
||||
{
|
||||
sp_256_mont_mul_order_4(u1, u1, s);
|
||||
sp_256_mont_mul_order_4(u2, u2, s);
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
err = sp_256_ecc_mulmod_base_4(p1, u1, 0, 0, heap);
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
@@ -40180,7 +40480,7 @@ typedef struct sp_384_proj_point_add_6_ctx {
|
||||
sp_digit* z;
|
||||
} sp_384_proj_point_add_6_ctx;
|
||||
|
||||
static int sp_384_proj_point_add_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
static int sp_384_proj_point_add_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
const sp_point_384* p, const sp_point_384* q, sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
@@ -43366,7 +43666,7 @@ static int sp_384_mont_inv_order_6_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_mont_inv_order_6_ctx* ctx = (sp_384_mont_inv_order_6_ctx*)sp_ctx;
|
||||
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_mont_inv_order_6_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
@@ -43536,9 +43836,9 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W
|
||||
}
|
||||
XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
|
||||
ctx->state = 2;
|
||||
break;
|
||||
break;
|
||||
case 2: /* MULMOD */
|
||||
err = sp_384_ecc_mulmod_6_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
err = sp_384_ecc_mulmod_6_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
&ctx->point, &p384_base, ctx->k, 1, 1, heap);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 3;
|
||||
@@ -43791,6 +44091,176 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, mp_int* priv,
|
||||
}
|
||||
#endif /* HAVE_ECC_SIGN */
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
/* Divide the number by 2 mod the modulus. (r = a / 2 % m)
|
||||
*
|
||||
* r Result of division by 2.
|
||||
* a Number to divide.
|
||||
* m Modulus.
|
||||
*/
|
||||
static void sp_384_div2_mod_6(sp_digit* r, const sp_digit* a,
|
||||
const sp_digit* m)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"ldr x3, [%[a], 0]\n\t"
|
||||
"ldr x4, [%[a], 8]\n\t"
|
||||
"ldr x5, [%[a], 16]\n\t"
|
||||
"ldr x6, [%[a], 24]\n\t"
|
||||
"ldr x7, [%[a], 32]\n\t"
|
||||
"ldr x8, [%[a], 40]\n\t"
|
||||
"ldr x9, [%[m], 0]\n\t"
|
||||
"ldr x10, [%[m], 8]\n\t"
|
||||
"ldr x11, [%[m], 16]\n\t"
|
||||
"ldr x12, [%[m], 24]\n\t"
|
||||
"ldr x13, [%[m], 32]\n\t"
|
||||
"ldr x14, [%[m], 40]\n\t"
|
||||
"ands x15, x3, 1\n\t"
|
||||
"b.eq 1f\n\t"
|
||||
"adds x3, x3, x9\n\t"
|
||||
"adcs x4, x4, x10\n\t"
|
||||
"adcs x5, x5, x11\n\t"
|
||||
"adcs x6, x6, x12\n\t"
|
||||
"adcs x7, x7, x13\n\t"
|
||||
"adcs x8, x8, x14\n\t"
|
||||
"cset x15, cs\n\t"
|
||||
"\n1:\n\t"
|
||||
"lsr x3, x3, 1\n\t"
|
||||
"lsr x10, x4, 1\n\t"
|
||||
"lsr x11, x5, 1\n\t"
|
||||
"lsr x12, x6, 1\n\t"
|
||||
"lsr x13, x7, 1\n\t"
|
||||
"lsr x14, x8, 1\n\t"
|
||||
"orr x3, x3, x4, lsl 63\n\t"
|
||||
"orr x4, x10, x5, lsl 63\n\t"
|
||||
"orr x5, x11, x6, lsl 63\n\t"
|
||||
"orr x6, x12, x7, lsl 63\n\t"
|
||||
"orr x7, x13, x8, lsl 63\n\t"
|
||||
"orr x8, x14, x15, lsl 63\n\t"
|
||||
"str x3, [%[r], 0]\n\t"
|
||||
"str x4, [%[r], 8]\n\t"
|
||||
"str x5, [%[r], 16]\n\t"
|
||||
"str x6, [%[r], 24]\n\t"
|
||||
"str x7, [%[r], 32]\n\t"
|
||||
"str x8, [%[r], 40]\n\t"
|
||||
:
|
||||
: [r] "r" (r), [a] "r" (a), [m] "r" (m)
|
||||
: "memory", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15"
|
||||
);
|
||||
}
|
||||
|
||||
static int sp_384_num_bits_64_6(sp_digit n)
|
||||
{
|
||||
int64_t r = -1;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"mov x1, 64\n\t"
|
||||
"clz %[r], %[n]\n\t"
|
||||
"sub %[r], x1, %[r]"
|
||||
: [r] "+r" (r)
|
||||
: [n] "r" (n)
|
||||
: "x1"
|
||||
);
|
||||
|
||||
return r + 1;
|
||||
}
|
||||
|
||||
static int sp_384_num_bits_6(const sp_digit* a)
|
||||
{
|
||||
int i;
|
||||
int r = 0;
|
||||
|
||||
for (i=5; i>=0; i--) {
|
||||
if (a[i] != 0) {
|
||||
r = sp_384_num_bits_64_6(a[i]);
|
||||
r += i * 64;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Non-constant time modular inversion.
|
||||
*
|
||||
* @param [out] r Resulting number.
|
||||
* @param [in] a Number to invert.
|
||||
* @param [in] m Modulus.
|
||||
* @return MP_OKAY on success.
|
||||
*/
|
||||
static int sp_384_mod_inv_6(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
{
|
||||
sp_digit u[6];
|
||||
sp_digit v[6];
|
||||
sp_digit b[6];
|
||||
sp_digit d[6];
|
||||
int ut, vt;
|
||||
sp_digit o;
|
||||
|
||||
XMEMCPY(u, m, sizeof(u));
|
||||
XMEMCPY(v, a, sizeof(v));
|
||||
|
||||
ut = sp_384_num_bits_6(u);
|
||||
vt = sp_384_num_bits_6(v);
|
||||
|
||||
XMEMSET(b, 0, sizeof(b));
|
||||
if ((v[0] & 1) == 0) {
|
||||
sp_384_rshift1_6(v, v);
|
||||
XMEMCPY(d, m, sizeof(u));
|
||||
d[0] += 1;
|
||||
sp_384_rshift1_6(d, d);
|
||||
vt--;
|
||||
|
||||
while ((v[0] & 1) == 0) {
|
||||
sp_384_rshift1_6(v, v);
|
||||
sp_384_div2_mod_6(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
XMEMSET(d+1, 0, sizeof(d)-sizeof(sp_digit));
|
||||
d[0] = 1;
|
||||
}
|
||||
|
||||
while (ut > 1 && vt > 1) {
|
||||
if (ut > vt || (ut == vt && sp_384_cmp_6(u, v) >= 0)) {
|
||||
sp_384_sub_6(u, u, v);
|
||||
o = sp_384_sub_6(b, b, d);
|
||||
if (o != 0)
|
||||
sp_384_add_6(b, b, m);
|
||||
ut = sp_384_num_bits_6(u);
|
||||
|
||||
do {
|
||||
sp_384_rshift1_6(u, u);
|
||||
sp_384_div2_mod_6(b, b, m);
|
||||
ut--;
|
||||
}
|
||||
while (ut > 0 && (u[0] & 1) == 0);
|
||||
}
|
||||
else {
|
||||
sp_384_sub_6(v, v, u);
|
||||
o = sp_384_sub_6(d, d, b);
|
||||
if (o != 0)
|
||||
sp_384_add_6(d, d, m);
|
||||
vt = sp_384_num_bits_6(v);
|
||||
|
||||
do {
|
||||
sp_384_rshift1_6(v, v);
|
||||
sp_384_div2_mod_6(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
while (vt > 0 && (v[0] & 1) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (ut == 1)
|
||||
XMEMCPY(r, b, sizeof(b));
|
||||
else
|
||||
XMEMCPY(r, d, sizeof(d));
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
/* Verify the signature values with the hash and public key.
|
||||
* e = Truncate(hash, 384)
|
||||
@@ -43916,7 +44386,7 @@ int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen,
|
||||
ctx->state = 11;
|
||||
break;
|
||||
case 10: /* DBL */
|
||||
err = sp_384_proj_point_dbl_6_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
err = sp_384_proj_point_dbl_6_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
&ctx->p2, ctx->tmp);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 11;
|
||||
@@ -44039,6 +44509,11 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
sp_384_from_mp(p2->y, 6, pY);
|
||||
sp_384_from_mp(p2->z, 6, pZ);
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_384_mod_inv_6(s, s, p384_order);
|
||||
}
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
{
|
||||
sp_384_mul_6(s, s, p384_norm_order);
|
||||
}
|
||||
@@ -44046,12 +44521,20 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
sp_384_norm_6(s);
|
||||
#ifdef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_384_mont_inv_order_6(s, s, tmp);
|
||||
sp_384_mont_mul_order_6(u1, u1, s);
|
||||
sp_384_mont_mul_order_6(u2, u2, s);
|
||||
}
|
||||
|
||||
#else
|
||||
{
|
||||
sp_384_mont_mul_order_6(u1, u1, s);
|
||||
sp_384_mont_mul_order_6(u2, u2, s);
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
err = sp_384_ecc_mulmod_base_6(p1, u1, 0, 0, heap);
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
|
||||
+1395
-10
File diff suppressed because it is too large
Load Diff
+457
-141
File diff suppressed because it is too large
Load Diff
+450
-130
File diff suppressed because it is too large
Load Diff
+662
-33
@@ -16798,7 +16798,7 @@ typedef struct sp_256_proj_point_add_8_ctx {
|
||||
sp_digit* z;
|
||||
} sp_256_proj_point_add_8_ctx;
|
||||
|
||||
static int sp_256_proj_point_add_8_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
static int sp_256_proj_point_add_8_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
const sp_point_256* p, const sp_point_256* q, sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
@@ -21245,7 +21245,7 @@ static int sp_256_mont_inv_order_8_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_mont_inv_order_8_ctx* ctx = (sp_256_mont_inv_order_8_ctx*)sp_ctx;
|
||||
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_mont_inv_order_8_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
@@ -21444,9 +21444,9 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W
|
||||
}
|
||||
XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
|
||||
ctx->state = 2;
|
||||
break;
|
||||
break;
|
||||
case 2: /* MULMOD */
|
||||
err = sp_256_ecc_mulmod_8_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
err = sp_256_ecc_mulmod_8_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
&ctx->point, &p256_base, ctx->k, 1, 1, heap);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 3;
|
||||
@@ -21699,6 +21699,291 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, mp_int* priv,
|
||||
}
|
||||
#endif /* HAVE_ECC_SIGN */
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
static void sp_256_rshift1_8(sp_digit* r, sp_digit* a)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"mov r10, #0\n\t"
|
||||
"mov r9, #0\n\t"
|
||||
"ldr r3, [%[a], #16]\n\t"
|
||||
"ldr r4, [%[a], #20]\n\t"
|
||||
"ldr r5, [%[a], #24]\n\t"
|
||||
"ldr r6, [%[a], #28]\n\t"
|
||||
"lsr r7, r3, #1\n\t"
|
||||
"and r3, r3, #1\n\t"
|
||||
"lsr r8, r4, #1\n\t"
|
||||
"lsr r10, r5, #1\n\t"
|
||||
"lsr r14, r6, #1\n\t"
|
||||
"orr r7, r7, r4, lsl #31\n\t"
|
||||
"orr r8, r8, r5, lsl #31\n\t"
|
||||
"orr r10, r10, r6, lsl #31\n\t"
|
||||
"orr r14, r14, r9, lsl #31\n\t"
|
||||
"mov r9, r3\n\t"
|
||||
"str r7, [%[r], #16]\n\t"
|
||||
"str r8, [%[r], #20]\n\t"
|
||||
"str r10, [%[r], #24]\n\t"
|
||||
"str r14, [%[r], #28]\n\t"
|
||||
"ldr r3, [%[r], #0]\n\t"
|
||||
"ldr r4, [%[r], #4]\n\t"
|
||||
"ldr r5, [%[r], #8]\n\t"
|
||||
"ldr r6, [%[r], #12]\n\t"
|
||||
"lsr r7, r3, #1\n\t"
|
||||
"lsr r8, r4, #1\n\t"
|
||||
"lsr r10, r5, #1\n\t"
|
||||
"lsr r14, r6, #1\n\t"
|
||||
"orr r7, r7, r4, lsl #31\n\t"
|
||||
"orr r8, r8, r5, lsl #31\n\t"
|
||||
"orr r10, r10, r6, lsl #31\n\t"
|
||||
"orr r14, r14, r9, lsl #31\n\t"
|
||||
"str r7, [%[r], #0]\n\t"
|
||||
"str r8, [%[r], #4]\n\t"
|
||||
"str r10, [%[r], #8]\n\t"
|
||||
"str r14, [%[r], #12]\n\t"
|
||||
:
|
||||
: [r] "r" (r), [a] "r" (a)
|
||||
: "memory", "r3", "r4", "r5", "r6", "r7", "r8", "r10", "r14", "r9"
|
||||
);
|
||||
}
|
||||
|
||||
/* Divide the number by 2 mod the modulus. (r = a / 2 % m)
|
||||
*
|
||||
* r Result of division by 2.
|
||||
* a Number to divide.
|
||||
* m Modulus.
|
||||
*/
|
||||
static void sp_256_div2_mod_8(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"mov r10, #0\n\t"
|
||||
"ldr r3, [%[a], #0]\n\t"
|
||||
"ands r9, r3, #1\n\t"
|
||||
"beq 1f\n\t"
|
||||
"ldr r4, [%[a], #4]\n\t"
|
||||
"ldr r5, [%[a], #8]\n\t"
|
||||
"ldr r6, [%[a], #12]\n\t"
|
||||
"ldr r7, [%[m], #0]\n\t"
|
||||
"ldr r8, [%[m], #4]\n\t"
|
||||
"ldr r10, [%[m], #8]\n\t"
|
||||
"ldr r14, [%[m], #12]\n\t"
|
||||
"adds r3, r3, r7\n\t"
|
||||
"adcs r4, r4, r8\n\t"
|
||||
"adcs r5, r5, r10\n\t"
|
||||
"adcs r6, r6, r14\n\t"
|
||||
"str r3, [%[r], #0]\n\t"
|
||||
"str r4, [%[r], #4]\n\t"
|
||||
"str r5, [%[r], #8]\n\t"
|
||||
"str r6, [%[r], #12]\n\t"
|
||||
"ldr r3, [%[a], #16]\n\t"
|
||||
"ldr r4, [%[a], #20]\n\t"
|
||||
"ldr r5, [%[a], #24]\n\t"
|
||||
"ldr r6, [%[a], #28]\n\t"
|
||||
"ldr r7, [%[m], #16]\n\t"
|
||||
"ldr r8, [%[m], #20]\n\t"
|
||||
"ldr r10, [%[m], #24]\n\t"
|
||||
"ldr r14, [%[m], #28]\n\t"
|
||||
"adcs r3, r3, r7\n\t"
|
||||
"adcs r4, r4, r8\n\t"
|
||||
"adcs r5, r5, r10\n\t"
|
||||
"adcs r6, r6, r14\n\t"
|
||||
"adc r9, r10, r10\n\t"
|
||||
"b 2f\n\t"
|
||||
"\n1:\n\t"
|
||||
"ldr r3, [%[a], #16]\n\t"
|
||||
"ldr r4, [%[a], #20]\n\t"
|
||||
"ldr r5, [%[a], #24]\n\t"
|
||||
"ldr r6, [%[a], #28]\n\t"
|
||||
"\n2:\n\t"
|
||||
"lsr r7, r3, #1\n\t"
|
||||
"and r3, r3, #1\n\t"
|
||||
"lsr r8, r4, #1\n\t"
|
||||
"lsr r10, r5, #1\n\t"
|
||||
"lsr r14, r6, #1\n\t"
|
||||
"orr r7, r7, r4, lsl #31\n\t"
|
||||
"orr r8, r8, r5, lsl #31\n\t"
|
||||
"orr r10, r10, r6, lsl #31\n\t"
|
||||
"orr r14, r14, r9, lsl #31\n\t"
|
||||
"mov r9, r3\n\t"
|
||||
"str r7, [%[r], #16]\n\t"
|
||||
"str r8, [%[r], #20]\n\t"
|
||||
"str r10, [%[r], #24]\n\t"
|
||||
"str r14, [%[r], #28]\n\t"
|
||||
"ldr r3, [%[r], #0]\n\t"
|
||||
"ldr r4, [%[r], #4]\n\t"
|
||||
"ldr r5, [%[r], #8]\n\t"
|
||||
"ldr r6, [%[r], #12]\n\t"
|
||||
"lsr r7, r3, #1\n\t"
|
||||
"lsr r8, r4, #1\n\t"
|
||||
"lsr r10, r5, #1\n\t"
|
||||
"lsr r14, r6, #1\n\t"
|
||||
"orr r7, r7, r4, lsl #31\n\t"
|
||||
"orr r8, r8, r5, lsl #31\n\t"
|
||||
"orr r10, r10, r6, lsl #31\n\t"
|
||||
"orr r14, r14, r9, lsl #31\n\t"
|
||||
"str r7, [%[r], #0]\n\t"
|
||||
"str r8, [%[r], #4]\n\t"
|
||||
"str r10, [%[r], #8]\n\t"
|
||||
"str r14, [%[r], #12]\n\t"
|
||||
:
|
||||
: [r] "r" (r), [a] "r" (a), [m] "r" (m)
|
||||
: "memory", "r3", "r4", "r5", "r6", "r7", "r8", "r10", "r14", "r9"
|
||||
);
|
||||
}
|
||||
|
||||
static int sp_256_num_bits_8(sp_digit* a)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"ldr r2, [%[a], #28]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 7f\n\t"
|
||||
"mov r3, #256\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n7:\n\t"
|
||||
"ldr r2, [%[a], #24]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 6f\n\t"
|
||||
"mov r3, #224\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n6:\n\t"
|
||||
"ldr r2, [%[a], #20]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 5f\n\t"
|
||||
"mov r3, #192\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n5:\n\t"
|
||||
"ldr r2, [%[a], #16]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 4f\n\t"
|
||||
"mov r3, #160\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n4:\n\t"
|
||||
"ldr r2, [%[a], #12]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 3f\n\t"
|
||||
"mov r3, #128\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n3:\n\t"
|
||||
"ldr r2, [%[a], #8]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 2f\n\t"
|
||||
"mov r3, #96\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n2:\n\t"
|
||||
"ldr r2, [%[a], #4]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 1f\n\t"
|
||||
"mov r3, #64\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 9f\n\t"
|
||||
"\n1:\n\t"
|
||||
"ldr r2, [%[a], #0]\n\t"
|
||||
"mov r3, #32\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"\n9:\n\t"
|
||||
: [r] "+r" (r)
|
||||
: [a] "r" (a)
|
||||
: "r2", "r3"
|
||||
);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Non-constant time modular inversion.
|
||||
*
|
||||
* @param [out] r Resulting number.
|
||||
* @param [in] a Number to invert.
|
||||
* @param [in] m Modulus.
|
||||
* @return MP_OKAY on success.
|
||||
*/
|
||||
static int sp_256_mod_inv_8(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
{
|
||||
sp_digit u[8];
|
||||
sp_digit v[8];
|
||||
sp_digit b[8];
|
||||
sp_digit d[8];
|
||||
int ut, vt;
|
||||
sp_digit o;
|
||||
|
||||
XMEMCPY(u, m, sizeof(u));
|
||||
XMEMCPY(v, a, sizeof(v));
|
||||
|
||||
ut = sp_256_num_bits_8(u);
|
||||
vt = sp_256_num_bits_8(v);
|
||||
|
||||
XMEMSET(b, 0, sizeof(b));
|
||||
if ((v[0] & 1) == 0) {
|
||||
sp_256_rshift1_8(v, v);
|
||||
XMEMCPY(d, m, sizeof(u));
|
||||
d[0] += 1;
|
||||
sp_256_rshift1_8(d, d);
|
||||
vt--;
|
||||
|
||||
while ((v[0] & 1) == 0) {
|
||||
sp_256_rshift1_8(v, v);
|
||||
sp_256_div2_mod_8(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
XMEMSET(d+1, 0, sizeof(d)-sizeof(sp_digit));
|
||||
d[0] = 1;
|
||||
}
|
||||
|
||||
while (ut > 1 && vt > 1) {
|
||||
if (ut > vt || (ut == vt && sp_256_cmp_8(u, v) >= 0)) {
|
||||
sp_256_sub_8(u, u, v);
|
||||
o = sp_256_sub_8(b, b, d);
|
||||
if (o != 0)
|
||||
sp_256_add_8(b, b, m);
|
||||
ut = sp_256_num_bits_8(u);
|
||||
|
||||
do {
|
||||
sp_256_rshift1_8(u, u);
|
||||
sp_256_div2_mod_8(b, b, m);
|
||||
ut--;
|
||||
}
|
||||
while (ut > 0 && (u[0] & 1) == 0);
|
||||
}
|
||||
else {
|
||||
sp_256_sub_8(v, v, u);
|
||||
o = sp_256_sub_8(d, d, b);
|
||||
if (o != 0)
|
||||
sp_256_add_8(d, d, m);
|
||||
vt = sp_256_num_bits_8(v);
|
||||
|
||||
do {
|
||||
sp_256_rshift1_8(v, v);
|
||||
sp_256_div2_mod_8(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
while (vt > 0 && (v[0] & 1) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (ut == 1)
|
||||
XMEMCPY(r, b, sizeof(b));
|
||||
else
|
||||
XMEMCPY(r, d, sizeof(d));
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
/* Verify the signature values with the hash and public key.
|
||||
* e = Truncate(hash, 256)
|
||||
@@ -21824,7 +22109,7 @@ int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen,
|
||||
ctx->state = 11;
|
||||
break;
|
||||
case 10: /* DBL */
|
||||
err = sp_256_proj_point_dbl_8_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
err = sp_256_proj_point_dbl_8_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
&ctx->p2, ctx->tmp);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 11;
|
||||
@@ -21947,6 +22232,11 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
sp_256_from_mp(p2->y, 8, pY);
|
||||
sp_256_from_mp(p2->z, 8, pZ);
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_256_mod_inv_8(s, s, p256_order);
|
||||
}
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
{
|
||||
sp_256_mul_8(s, s, p256_norm_order);
|
||||
}
|
||||
@@ -21954,12 +22244,20 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
sp_256_norm_8(s);
|
||||
#ifdef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_256_mont_inv_order_8(s, s, tmp);
|
||||
sp_256_mont_mul_order_8(u1, u1, s);
|
||||
sp_256_mont_mul_order_8(u2, u2, s);
|
||||
}
|
||||
|
||||
#else
|
||||
{
|
||||
sp_256_mont_mul_order_8(u1, u1, s);
|
||||
sp_256_mont_mul_order_8(u2, u2, s);
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
err = sp_256_ecc_mulmod_base_8(p1, u1, 0, 0, heap);
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
@@ -23907,64 +24205,53 @@ static void sp_384_rshift1_12(sp_digit* r, sp_digit* a)
|
||||
"ldr r2, [%[a]]\n\t"
|
||||
"ldr r3, [%[a], #4]\n\t"
|
||||
"lsr r2, r2, #1\n\t"
|
||||
"lsl r5, r3, #31\n\t"
|
||||
"orr r2, r2, r3, lsl #31\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"orr r2, r2, r5\n\t"
|
||||
"ldr r4, [%[a], #8]\n\t"
|
||||
"str r2, [%[r], #0]\n\t"
|
||||
"lsl r5, r4, #31\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"orr r3, r3, r5\n\t"
|
||||
"ldr r2, [%[a], #12]\n\t"
|
||||
"str r3, [%[r], #4]\n\t"
|
||||
"lsl r5, r2, #31\n\t"
|
||||
"orr r4, r4, r2, lsl #31\n\t"
|
||||
"lsr r2, r2, #1\n\t"
|
||||
"orr r4, r4, r5\n\t"
|
||||
"ldr r3, [%[a], #16]\n\t"
|
||||
"str r4, [%[r], #8]\n\t"
|
||||
"lsl r5, r3, #31\n\t"
|
||||
"orr r2, r2, r3, lsl #31\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"orr r2, r2, r5\n\t"
|
||||
"ldr r4, [%[a], #20]\n\t"
|
||||
"str r2, [%[r], #12]\n\t"
|
||||
"lsl r5, r4, #31\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"orr r3, r3, r5\n\t"
|
||||
"ldr r2, [%[a], #24]\n\t"
|
||||
"str r3, [%[r], #16]\n\t"
|
||||
"lsl r5, r2, #31\n\t"
|
||||
"orr r4, r4, r2, lsl #31\n\t"
|
||||
"lsr r2, r2, #1\n\t"
|
||||
"orr r4, r4, r5\n\t"
|
||||
"ldr r3, [%[a], #28]\n\t"
|
||||
"str r4, [%[r], #20]\n\t"
|
||||
"lsl r5, r3, #31\n\t"
|
||||
"orr r2, r2, r3, lsl #31\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"orr r2, r2, r5\n\t"
|
||||
"ldr r4, [%[a], #32]\n\t"
|
||||
"str r2, [%[r], #24]\n\t"
|
||||
"lsl r5, r4, #31\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"orr r3, r3, r5\n\t"
|
||||
"ldr r2, [%[a], #36]\n\t"
|
||||
"str r3, [%[r], #28]\n\t"
|
||||
"lsl r5, r2, #31\n\t"
|
||||
"orr r4, r4, r2, lsl #31\n\t"
|
||||
"lsr r2, r2, #1\n\t"
|
||||
"orr r4, r4, r5\n\t"
|
||||
"ldr r3, [%[a], #40]\n\t"
|
||||
"str r4, [%[r], #32]\n\t"
|
||||
"lsl r5, r3, #31\n\t"
|
||||
"orr r2, r2, r3, lsl #31\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"orr r2, r2, r5\n\t"
|
||||
"ldr r4, [%[a], #44]\n\t"
|
||||
"str r2, [%[r], #36]\n\t"
|
||||
"lsl r5, r4, #31\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"orr r3, r3, r5\n\t"
|
||||
"str r3, [%[r], #40]\n\t"
|
||||
"str r4, [%[r], #44]\n\t"
|
||||
:
|
||||
: [r] "r" (r), [a] "r" (a)
|
||||
: "memory", "r2", "r3", "r4", "r5"
|
||||
: "memory", "r2", "r3", "r4"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24216,7 +24503,7 @@ typedef struct sp_384_proj_point_add_12_ctx {
|
||||
sp_digit* z;
|
||||
} sp_384_proj_point_add_12_ctx;
|
||||
|
||||
static int sp_384_proj_point_add_12_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
static int sp_384_proj_point_add_12_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
const sp_point_384* p, const sp_point_384* q, sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
@@ -27887,7 +28174,7 @@ static int sp_384_mont_inv_order_12_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_mont_inv_order_12_ctx* ctx = (sp_384_mont_inv_order_12_ctx*)sp_ctx;
|
||||
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_mont_inv_order_12_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
@@ -28057,9 +28344,9 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W
|
||||
}
|
||||
XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
|
||||
ctx->state = 2;
|
||||
break;
|
||||
break;
|
||||
case 2: /* MULMOD */
|
||||
err = sp_384_ecc_mulmod_12_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
err = sp_384_ecc_mulmod_12_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
&ctx->point, &p384_base, ctx->k, 1, 1, heap);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 3;
|
||||
@@ -28312,6 +28599,335 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, mp_int* priv,
|
||||
}
|
||||
#endif /* HAVE_ECC_SIGN */
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
/* Divide the number by 2 mod the modulus. (r = a / 2 % m)
|
||||
*
|
||||
* r Result of division by 2.
|
||||
* a Number to divide.
|
||||
* m Modulus.
|
||||
*/
|
||||
static void sp_384_div2_mod_12(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"ldr r4, [%[a]]\n\t"
|
||||
"ands r8, r4, #1\n\t"
|
||||
"beq 1f\n\t"
|
||||
"mov r12, #0\n\t"
|
||||
"ldr r5, [%[a], #4]\n\t"
|
||||
"ldr r6, [%[a], #8]\n\t"
|
||||
"ldr r7, [%[a], #12]\n\t"
|
||||
"ldr r8, [%[m], #0]\n\t"
|
||||
"ldr r9, [%[m], #4]\n\t"
|
||||
"ldr r10, [%[m], #8]\n\t"
|
||||
"ldr r14, [%[m], #12]\n\t"
|
||||
"adds r4, r4, r8\n\t"
|
||||
"adcs r5, r5, r9\n\t"
|
||||
"adcs r6, r6, r10\n\t"
|
||||
"adcs r7, r7, r14\n\t"
|
||||
"str r4, [%[r], #0]\n\t"
|
||||
"str r5, [%[r], #4]\n\t"
|
||||
"str r6, [%[r], #8]\n\t"
|
||||
"str r7, [%[r], #12]\n\t"
|
||||
"ldr r4, [%[a], #16]\n\t"
|
||||
"ldr r5, [%[a], #20]\n\t"
|
||||
"ldr r6, [%[a], #24]\n\t"
|
||||
"ldr r7, [%[a], #28]\n\t"
|
||||
"ldr r8, [%[m], #16]\n\t"
|
||||
"ldr r9, [%[m], #20]\n\t"
|
||||
"ldr r10, [%[m], #24]\n\t"
|
||||
"ldr r14, [%[m], #28]\n\t"
|
||||
"adcs r4, r4, r8\n\t"
|
||||
"adcs r5, r5, r9\n\t"
|
||||
"adcs r6, r6, r10\n\t"
|
||||
"adcs r7, r7, r14\n\t"
|
||||
"str r4, [%[r], #16]\n\t"
|
||||
"str r5, [%[r], #20]\n\t"
|
||||
"str r6, [%[r], #24]\n\t"
|
||||
"str r7, [%[r], #28]\n\t"
|
||||
"ldr r4, [%[a], #32]\n\t"
|
||||
"ldr r5, [%[a], #36]\n\t"
|
||||
"ldr r6, [%[a], #40]\n\t"
|
||||
"ldr r7, [%[a], #44]\n\t"
|
||||
"ldr r8, [%[m], #32]\n\t"
|
||||
"ldr r9, [%[m], #36]\n\t"
|
||||
"ldr r10, [%[m], #40]\n\t"
|
||||
"ldr r14, [%[m], #44]\n\t"
|
||||
"adcs r4, r4, r8\n\t"
|
||||
"adcs r5, r5, r9\n\t"
|
||||
"adcs r6, r6, r10\n\t"
|
||||
"adcs r7, r7, r14\n\t"
|
||||
"str r4, [%[r], #32]\n\t"
|
||||
"str r5, [%[r], #36]\n\t"
|
||||
"str r6, [%[r], #40]\n\t"
|
||||
"str r7, [%[r], #44]\n\t"
|
||||
"adc r8, r12, r12\n\t"
|
||||
"b 2f\n\t"
|
||||
"\n1:\n\t"
|
||||
"ldr r5, [%[a], #2]\n\t"
|
||||
"str r4, [%[r], #0]\n\t"
|
||||
"str r5, [%[r], #2]\n\t"
|
||||
"ldr r4, [%[a], #4]\n\t"
|
||||
"ldr r5, [%[a], #6]\n\t"
|
||||
"str r4, [%[r], #4]\n\t"
|
||||
"str r5, [%[r], #6]\n\t"
|
||||
"ldr r4, [%[a], #8]\n\t"
|
||||
"ldr r5, [%[a], #10]\n\t"
|
||||
"str r4, [%[r], #8]\n\t"
|
||||
"str r5, [%[r], #10]\n\t"
|
||||
"ldr r4, [%[a], #12]\n\t"
|
||||
"ldr r5, [%[a], #14]\n\t"
|
||||
"str r4, [%[r], #12]\n\t"
|
||||
"str r5, [%[r], #14]\n\t"
|
||||
"ldr r4, [%[a], #16]\n\t"
|
||||
"ldr r5, [%[a], #18]\n\t"
|
||||
"str r4, [%[r], #16]\n\t"
|
||||
"str r5, [%[r], #18]\n\t"
|
||||
"ldr r4, [%[a], #20]\n\t"
|
||||
"ldr r5, [%[a], #22]\n\t"
|
||||
"str r4, [%[r], #20]\n\t"
|
||||
"str r5, [%[r], #22]\n\t"
|
||||
"\n2:\n\t"
|
||||
"ldr r3, [%[r]]\n\t"
|
||||
"ldr r4, [%[r], #4]\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"ldr r5, [%[a], #8]\n\t"
|
||||
"str r3, [%[r], #0]\n\t"
|
||||
"orr r4, r4, r5, lsl #31\n\t"
|
||||
"lsr r5, r5, #1\n\t"
|
||||
"ldr r3, [%[a], #12]\n\t"
|
||||
"str r4, [%[r], #4]\n\t"
|
||||
"orr r5, r5, r3, lsl #31\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"ldr r4, [%[a], #16]\n\t"
|
||||
"str r5, [%[r], #8]\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"ldr r5, [%[a], #20]\n\t"
|
||||
"str r3, [%[r], #12]\n\t"
|
||||
"orr r4, r4, r5, lsl #31\n\t"
|
||||
"lsr r5, r5, #1\n\t"
|
||||
"ldr r3, [%[a], #24]\n\t"
|
||||
"str r4, [%[r], #16]\n\t"
|
||||
"orr r5, r5, r3, lsl #31\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"ldr r4, [%[a], #28]\n\t"
|
||||
"str r5, [%[r], #20]\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"ldr r5, [%[a], #32]\n\t"
|
||||
"str r3, [%[r], #24]\n\t"
|
||||
"orr r4, r4, r5, lsl #31\n\t"
|
||||
"lsr r5, r5, #1\n\t"
|
||||
"ldr r3, [%[a], #36]\n\t"
|
||||
"str r4, [%[r], #28]\n\t"
|
||||
"orr r5, r5, r3, lsl #31\n\t"
|
||||
"lsr r3, r3, #1\n\t"
|
||||
"ldr r4, [%[a], #40]\n\t"
|
||||
"str r5, [%[r], #32]\n\t"
|
||||
"orr r3, r3, r4, lsl #31\n\t"
|
||||
"lsr r4, r4, #1\n\t"
|
||||
"ldr r5, [%[a], #44]\n\t"
|
||||
"str r3, [%[r], #36]\n\t"
|
||||
"orr r4, r4, r5, lsl #31\n\t"
|
||||
"lsr r5, r5, #1\n\t"
|
||||
"orr r5, r5, r8, lsl #31\n\t"
|
||||
"str r4, [%[r], #40]\n\t"
|
||||
"str r5, [%[r], #44]\n\t"
|
||||
:
|
||||
: [r] "r" (r), [a] "r" (a), [m] "r" (m)
|
||||
: "memory", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r14"
|
||||
);
|
||||
}
|
||||
|
||||
static int sp_384_num_bits_12(sp_digit* a)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"ldr r2, [%[a], #44]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 11f\n\t"
|
||||
"mov r3, #384\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n11:\n\t"
|
||||
"ldr r2, [%[a], #40]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 10f\n\t"
|
||||
"mov r3, #352\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n10:\n\t"
|
||||
"ldr r2, [%[a], #36]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 9f\n\t"
|
||||
"mov r3, #320\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n9:\n\t"
|
||||
"ldr r2, [%[a], #32]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 8f\n\t"
|
||||
"mov r3, #288\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n8:\n\t"
|
||||
"ldr r2, [%[a], #28]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 7f\n\t"
|
||||
"mov r3, #256\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n7:\n\t"
|
||||
"ldr r2, [%[a], #24]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 6f\n\t"
|
||||
"mov r3, #224\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n6:\n\t"
|
||||
"ldr r2, [%[a], #20]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 5f\n\t"
|
||||
"mov r3, #192\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n5:\n\t"
|
||||
"ldr r2, [%[a], #16]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 4f\n\t"
|
||||
"mov r3, #160\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n4:\n\t"
|
||||
"ldr r2, [%[a], #12]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 3f\n\t"
|
||||
"mov r3, #128\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n3:\n\t"
|
||||
"ldr r2, [%[a], #8]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 2f\n\t"
|
||||
"mov r3, #96\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n2:\n\t"
|
||||
"ldr r2, [%[a], #4]\n\t"
|
||||
"cmp r2, #0\n\t"
|
||||
"beq 1f\n\t"
|
||||
"mov r3, #64\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"b 13f\n\t"
|
||||
"\n1:\n\t"
|
||||
"ldr r2, [%[a], #0]\n\t"
|
||||
"mov r3, #32\n\t"
|
||||
"clz %[r], r2\n\t"
|
||||
"sub %[r], r3, %[r]\n\t"
|
||||
"\n13:\n\t"
|
||||
: [r] "+r" (r)
|
||||
: [a] "r" (a)
|
||||
: "r2", "r3"
|
||||
);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Non-constant time modular inversion.
|
||||
*
|
||||
* @param [out] r Resulting number.
|
||||
* @param [in] a Number to invert.
|
||||
* @param [in] m Modulus.
|
||||
* @return MP_OKAY on success.
|
||||
*/
|
||||
static int sp_384_mod_inv_12(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
{
|
||||
sp_digit u[12];
|
||||
sp_digit v[12];
|
||||
sp_digit b[12];
|
||||
sp_digit d[12];
|
||||
int ut, vt;
|
||||
sp_digit o;
|
||||
|
||||
XMEMCPY(u, m, sizeof(u));
|
||||
XMEMCPY(v, a, sizeof(v));
|
||||
|
||||
ut = sp_384_num_bits_12(u);
|
||||
vt = sp_384_num_bits_12(v);
|
||||
|
||||
XMEMSET(b, 0, sizeof(b));
|
||||
if ((v[0] & 1) == 0) {
|
||||
sp_384_rshift1_12(v, v);
|
||||
XMEMCPY(d, m, sizeof(u));
|
||||
d[0] += 1;
|
||||
sp_384_rshift1_12(d, d);
|
||||
vt--;
|
||||
|
||||
while ((v[0] & 1) == 0) {
|
||||
sp_384_rshift1_12(v, v);
|
||||
sp_384_div2_mod_12(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
XMEMSET(d+1, 0, sizeof(d)-sizeof(sp_digit));
|
||||
d[0] = 1;
|
||||
}
|
||||
|
||||
while (ut > 1 && vt > 1) {
|
||||
if (ut > vt || (ut == vt && sp_384_cmp_12(u, v) >= 0)) {
|
||||
sp_384_sub_12(u, u, v);
|
||||
o = sp_384_sub_12(b, b, d);
|
||||
if (o != 0)
|
||||
sp_384_add_12(b, b, m);
|
||||
ut = sp_384_num_bits_12(u);
|
||||
|
||||
do {
|
||||
sp_384_rshift1_12(u, u);
|
||||
sp_384_div2_mod_12(b, b, m);
|
||||
ut--;
|
||||
}
|
||||
while (ut > 0 && (u[0] & 1) == 0);
|
||||
}
|
||||
else {
|
||||
sp_384_sub_12(v, v, u);
|
||||
o = sp_384_sub_12(d, d, b);
|
||||
if (o != 0)
|
||||
sp_384_add_12(d, d, m);
|
||||
vt = sp_384_num_bits_12(v);
|
||||
|
||||
do {
|
||||
sp_384_rshift1_12(v, v);
|
||||
sp_384_div2_mod_12(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
while (vt > 0 && (v[0] & 1) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (ut == 1)
|
||||
XMEMCPY(r, b, sizeof(b));
|
||||
else
|
||||
XMEMCPY(r, d, sizeof(d));
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
/* Verify the signature values with the hash and public key.
|
||||
* e = Truncate(hash, 384)
|
||||
@@ -28437,7 +29053,7 @@ int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen,
|
||||
ctx->state = 11;
|
||||
break;
|
||||
case 10: /* DBL */
|
||||
err = sp_384_proj_point_dbl_12_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
err = sp_384_proj_point_dbl_12_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
&ctx->p2, ctx->tmp);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 11;
|
||||
@@ -28560,6 +29176,11 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
sp_384_from_mp(p2->y, 12, pY);
|
||||
sp_384_from_mp(p2->z, 12, pZ);
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_384_mod_inv_12(s, s, p384_order);
|
||||
}
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
{
|
||||
sp_384_mul_12(s, s, p384_norm_order);
|
||||
}
|
||||
@@ -28567,12 +29188,20 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
sp_384_norm_12(s);
|
||||
#ifdef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_384_mont_inv_order_12(s, s, tmp);
|
||||
sp_384_mont_mul_order_12(u1, u1, s);
|
||||
sp_384_mont_mul_order_12(u2, u2, s);
|
||||
}
|
||||
|
||||
#else
|
||||
{
|
||||
sp_384_mont_mul_order_12(u1, u1, s);
|
||||
sp_384_mont_mul_order_12(u2, u2, s);
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
err = sp_384_ecc_mulmod_base_12(p1, u1, 0, 0, heap);
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
|
||||
+179
-52
@@ -7091,7 +7091,7 @@ typedef struct sp_256_proj_point_add_4_ctx {
|
||||
sp_digit* z;
|
||||
} sp_256_proj_point_add_4_ctx;
|
||||
|
||||
static int sp_256_proj_point_add_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
static int sp_256_proj_point_add_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
const sp_point_256* p, const sp_point_256* q, sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
@@ -8171,7 +8171,7 @@ typedef struct sp_256_proj_point_add_avx2_4_ctx {
|
||||
sp_digit* z;
|
||||
} sp_256_proj_point_add_avx2_4_ctx;
|
||||
|
||||
static int sp_256_proj_point_add_avx2_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
static int sp_256_proj_point_add_avx2_4_nb(sp_ecc_ctx_t* sp_ctx, sp_point_256* r,
|
||||
const sp_point_256* p, const sp_point_256* q, sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
@@ -22716,6 +22716,13 @@ static void sp_256_mont_sqr_n_order_4(sp_digit* r, const sp_digit* a, int n)
|
||||
}
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
|
||||
#ifdef WOLFSSL_SP_NONBLOCK
|
||||
/* Context of non-blocking moduluar inversion with Montgomery form number. */
|
||||
typedef struct sp_256_mont_inv_order_4_ctx {
|
||||
int state; /* State of next operation. */
|
||||
int i; /* Index of bit in order. */
|
||||
} sp_256_mont_inv_order_4_ctx;
|
||||
|
||||
/* Invert the number, in Montgomery form, modulo the order of the P256 curve.
|
||||
* (r = 1 / a mod order)
|
||||
*
|
||||
@@ -22723,18 +22730,12 @@ static void sp_256_mont_sqr_n_order_4(sp_digit* r, const sp_digit* a, int n)
|
||||
* a Number to invert.
|
||||
* td Temporary data.
|
||||
*/
|
||||
|
||||
#ifdef WOLFSSL_SP_NONBLOCK
|
||||
typedef struct sp_256_mont_inv_order_4_ctx {
|
||||
int state;
|
||||
int i;
|
||||
} sp_256_mont_inv_order_4_ctx;
|
||||
static int sp_256_mont_inv_order_4_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const sp_digit* a,
|
||||
sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_mont_inv_order_4_ctx* ctx = (sp_256_mont_inv_order_4_ctx*)sp_ctx;
|
||||
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_mont_inv_order_4_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
@@ -22764,6 +22765,13 @@ static int sp_256_mont_inv_order_4_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
|
||||
}
|
||||
#endif /* WOLFSSL_SP_NONBLOCK */
|
||||
|
||||
/* Invert the number, in Montgomery form, modulo the order of the P256 curve.
|
||||
* (r = 1 / a mod order)
|
||||
*
|
||||
* r Inverse result.
|
||||
* a Number to invert.
|
||||
* td Temporary data.
|
||||
*/
|
||||
static void sp_256_mont_inv_order_4(sp_digit* r, const sp_digit* a,
|
||||
sp_digit* td)
|
||||
{
|
||||
@@ -22858,32 +22866,8 @@ static void sp_256_mont_inv_order_4(sp_digit* r, const sp_digit* a,
|
||||
}
|
||||
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
extern void sp_256_sqr_avx2_4(sp_digit* r, const sp_digit* a);
|
||||
#define sp_256_mont_reduce_order_avx2_4 sp_256_mont_reduce_avx2_4
|
||||
|
||||
extern void sp_256_mont_reduce_avx2_4(sp_digit* a, const sp_digit* m, sp_digit mp);
|
||||
/* Multiply two number mod the order of P256 curve. (r = a * b mod order)
|
||||
*
|
||||
* r Result of the multiplication.
|
||||
* a First operand of the multiplication.
|
||||
* b Second operand of the multiplication.
|
||||
*/
|
||||
static void sp_256_mont_mul_order_avx2_4(sp_digit* r, const sp_digit* a, const sp_digit* b)
|
||||
{
|
||||
sp_256_mul_avx2_4(r, a, b);
|
||||
sp_256_mont_reduce_order_avx2_4(r, p256_order, p256_mp_order);
|
||||
}
|
||||
|
||||
/* Square number mod the order of P256 curve. (r = a * a mod order)
|
||||
*
|
||||
* r Result of the squaring.
|
||||
* a Number to square.
|
||||
*/
|
||||
static void sp_256_mont_sqr_order_avx2_4(sp_digit* r, const sp_digit* a)
|
||||
{
|
||||
sp_256_sqr_avx2_4(r, a);
|
||||
sp_256_mont_reduce_order_avx2_4(r, p256_order, p256_mp_order);
|
||||
}
|
||||
extern void sp_256_mont_mul_order_avx2_4(sp_digit* r, const sp_digit* a, const sp_digit* b);
|
||||
extern void sp_256_mont_sqr_order_avx2_4(sp_digit* r, const sp_digit* a);
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
/* Square number mod the order of P256 curve a number of times.
|
||||
@@ -22903,6 +22887,13 @@ static void sp_256_mont_sqr_n_order_avx2_4(sp_digit* r, const sp_digit* a, int n
|
||||
}
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
|
||||
#ifdef WOLFSSL_SP_NONBLOCK
|
||||
/* Context of non-blocking moduluar inversion with Montgomery form number. */
|
||||
typedef struct sp_256_mont_inv_order_avx2_4_ctx {
|
||||
int state; /* State of next operation. */
|
||||
int i; /* Index of bit in order. */
|
||||
} sp_256_mont_inv_order_avx2_4_ctx;
|
||||
|
||||
/* Invert the number, in Montgomery form, modulo the order of the P256 curve.
|
||||
* (r = 1 / a mod order)
|
||||
*
|
||||
@@ -22910,18 +22901,12 @@ static void sp_256_mont_sqr_n_order_avx2_4(sp_digit* r, const sp_digit* a, int n
|
||||
* a Number to invert.
|
||||
* td Temporary data.
|
||||
*/
|
||||
|
||||
#ifdef WOLFSSL_SP_NONBLOCK
|
||||
typedef struct sp_256_mont_inv_order_avx2_4_ctx {
|
||||
int state;
|
||||
int i;
|
||||
} sp_256_mont_inv_order_avx2_4_ctx;
|
||||
static int sp_256_mont_inv_order_avx2_4_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const sp_digit* a,
|
||||
sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_256_mont_inv_order_avx2_4_ctx* ctx = (sp_256_mont_inv_order_avx2_4_ctx*)sp_ctx;
|
||||
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_256_mont_inv_order_avx2_4_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
@@ -22951,6 +22936,13 @@ static int sp_256_mont_inv_order_avx2_4_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, co
|
||||
}
|
||||
#endif /* WOLFSSL_SP_NONBLOCK */
|
||||
|
||||
/* Invert the number, in Montgomery form, modulo the order of the P256 curve.
|
||||
* (r = 1 / a mod order)
|
||||
*
|
||||
* r Inverse result.
|
||||
* a Number to invert.
|
||||
* td Temporary data.
|
||||
*/
|
||||
static void sp_256_mont_inv_order_avx2_4(sp_digit* r, const sp_digit* a,
|
||||
sp_digit* td)
|
||||
{
|
||||
@@ -23121,9 +23113,9 @@ int sp_ecc_sign_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W
|
||||
}
|
||||
XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
|
||||
ctx->state = 2;
|
||||
break;
|
||||
break;
|
||||
case 2: /* MULMOD */
|
||||
err = sp_256_ecc_mulmod_4_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
err = sp_256_ecc_mulmod_4_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
&ctx->point, &p256_base, ctx->k, 1, 1, heap);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 3;
|
||||
@@ -23404,6 +23396,10 @@ int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, mp_int* priv,
|
||||
}
|
||||
#endif /* HAVE_ECC_SIGN */
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
extern void sp_256_mod_inv_4(sp_digit* r, const sp_digit* a, const sp_digit* m);
|
||||
extern void sp_256_mod_inv_avx2_4(sp_digit* r, const sp_digit* a, const sp_digit* m);
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
/* Verify the signature values with the hash and public key.
|
||||
* e = Truncate(hash, 256)
|
||||
@@ -23529,7 +23525,7 @@ int sp_ecc_verify_256_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen,
|
||||
ctx->state = 11;
|
||||
break;
|
||||
case 10: /* DBL */
|
||||
err = sp_256_proj_point_dbl_4_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
err = sp_256_proj_point_dbl_4_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
&ctx->p2, ctx->tmp);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 11;
|
||||
@@ -23655,6 +23651,17 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
sp_256_from_mp(p2->y, 4, pY);
|
||||
sp_256_from_mp(p2->z, 4, pZ);
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags)) {
|
||||
sp_256_mod_inv_avx2_4(s, s, p256_order);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
sp_256_mod_inv_4(s, s, p256_order);
|
||||
}
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags)) {
|
||||
sp_256_mul_avx2_4(s, s, p256_norm_order);
|
||||
@@ -23668,6 +23675,7 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
sp_256_norm_4(s);
|
||||
#ifdef WOLFSSL_SP_SMALL
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags)) {
|
||||
sp_256_mont_inv_order_avx2_4(s, s, tmp);
|
||||
@@ -23682,6 +23690,20 @@ int sp_ecc_verify_256(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
sp_256_mont_mul_order_4(u2, u2, s);
|
||||
}
|
||||
|
||||
#else
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags)) {
|
||||
sp_256_mont_mul_order_avx2_4(u1, u1, s);
|
||||
sp_256_mont_mul_order_avx2_4(u2, u2, s);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
sp_256_mont_mul_order_4(u1, u1, s);
|
||||
sp_256_mont_mul_order_4(u2, u2, s);
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags))
|
||||
err = sp_256_ecc_mulmod_base_avx2_4(p1, u1, 0, 0, heap);
|
||||
@@ -25425,7 +25447,7 @@ typedef struct sp_384_proj_point_add_6_ctx {
|
||||
sp_digit* z;
|
||||
} sp_384_proj_point_add_6_ctx;
|
||||
|
||||
static int sp_384_proj_point_add_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
static int sp_384_proj_point_add_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
const sp_point_384* p, const sp_point_384* q, sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
@@ -26557,7 +26579,7 @@ typedef struct sp_384_proj_point_add_avx2_6_ctx {
|
||||
sp_digit* z;
|
||||
} sp_384_proj_point_add_avx2_6_ctx;
|
||||
|
||||
static int sp_384_proj_point_add_avx2_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
static int sp_384_proj_point_add_avx2_6_nb(sp_ecc_ctx_t* sp_ctx, sp_point_384* r,
|
||||
const sp_point_384* p, const sp_point_384* q, sp_digit* t)
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
@@ -29796,7 +29818,7 @@ static int sp_384_mont_inv_order_6_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, const s
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_mont_inv_order_6_ctx* ctx = (sp_384_mont_inv_order_6_ctx*)sp_ctx;
|
||||
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_mont_inv_order_6_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
@@ -29950,7 +29972,7 @@ static int sp_384_mont_inv_order_avx2_6_nb(sp_ecc_ctx_t* sp_ctx, sp_digit* r, co
|
||||
{
|
||||
int err = FP_WOULDBLOCK;
|
||||
sp_384_mont_inv_order_avx2_6_ctx* ctx = (sp_384_mont_inv_order_avx2_6_ctx*)sp_ctx;
|
||||
|
||||
|
||||
typedef char ctx_size_test[sizeof(sp_384_mont_inv_order_avx2_6_ctx) >= sizeof(*sp_ctx) ? -1 : 1];
|
||||
(void)sizeof(ctx_size_test);
|
||||
|
||||
@@ -30121,9 +30143,9 @@ int sp_ecc_sign_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen, W
|
||||
}
|
||||
XMEMSET(&ctx->mulmod_ctx, 0, sizeof(ctx->mulmod_ctx));
|
||||
ctx->state = 2;
|
||||
break;
|
||||
break;
|
||||
case 2: /* MULMOD */
|
||||
err = sp_384_ecc_mulmod_6_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
err = sp_384_ecc_mulmod_6_nb((sp_ecc_ctx_t*)&ctx->mulmod_ctx,
|
||||
&ctx->point, &p384_base, ctx->k, 1, 1, heap);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 3;
|
||||
@@ -30404,6 +30426,91 @@ int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, mp_int* priv,
|
||||
}
|
||||
#endif /* HAVE_ECC_SIGN */
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
extern void sp_384_rshift1_6(sp_digit* r, const sp_digit* a);
|
||||
extern void sp_384_div2_mod_6(sp_digit* r, const sp_digit* a, const sp_digit* m);
|
||||
extern int sp_384_num_bits_6(const sp_digit * a);
|
||||
/* Non-constant time modular inversion.
|
||||
*
|
||||
* @param [out] r Resulting number.
|
||||
* @param [in] a Number to invert.
|
||||
* @param [in] m Modulus.
|
||||
* @return MP_OKAY on success.
|
||||
*/
|
||||
static int sp_384_mod_inv_6(sp_digit* r, const sp_digit* a, const sp_digit* m)
|
||||
{
|
||||
sp_digit u[6];
|
||||
sp_digit v[6];
|
||||
sp_digit b[6];
|
||||
sp_digit d[6];
|
||||
int ut, vt;
|
||||
sp_digit o;
|
||||
|
||||
XMEMCPY(u, m, sizeof(u));
|
||||
XMEMCPY(v, a, sizeof(v));
|
||||
|
||||
ut = sp_384_num_bits_6(u);
|
||||
vt = sp_384_num_bits_6(v);
|
||||
|
||||
XMEMSET(b, 0, sizeof(b));
|
||||
if ((v[0] & 1) == 0) {
|
||||
sp_384_rshift1_6(v, v);
|
||||
XMEMCPY(d, m, sizeof(u));
|
||||
d[0] += 1;
|
||||
sp_384_rshift1_6(d, d);
|
||||
vt--;
|
||||
|
||||
while ((v[0] & 1) == 0) {
|
||||
sp_384_rshift1_6(v, v);
|
||||
sp_384_div2_mod_6(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
XMEMSET(d+1, 0, sizeof(d)-sizeof(sp_digit));
|
||||
d[0] = 1;
|
||||
}
|
||||
|
||||
while (ut > 1 && vt > 1) {
|
||||
if (ut > vt || (ut == vt && sp_384_cmp_6(u, v) >= 0)) {
|
||||
sp_384_sub_6(u, u, v);
|
||||
o = sp_384_sub_6(b, b, d);
|
||||
if (o != 0)
|
||||
sp_384_add_6(b, b, m);
|
||||
ut = sp_384_num_bits_6(u);
|
||||
|
||||
do {
|
||||
sp_384_rshift1_6(u, u);
|
||||
sp_384_div2_mod_6(b, b, m);
|
||||
ut--;
|
||||
}
|
||||
while (ut > 0 && (u[0] & 1) == 0);
|
||||
}
|
||||
else {
|
||||
sp_384_sub_6(v, v, u);
|
||||
o = sp_384_sub_6(d, d, b);
|
||||
if (o != 0)
|
||||
sp_384_add_6(d, d, m);
|
||||
vt = sp_384_num_bits_6(v);
|
||||
|
||||
do {
|
||||
sp_384_rshift1_6(v, v);
|
||||
sp_384_div2_mod_6(d, d, m);
|
||||
vt--;
|
||||
}
|
||||
while (vt > 0 && (v[0] & 1) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (ut == 1)
|
||||
XMEMCPY(r, b, sizeof(b));
|
||||
else
|
||||
XMEMCPY(r, d, sizeof(d));
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_ECC_VERIFY
|
||||
/* Verify the signature values with the hash and public key.
|
||||
* e = Truncate(hash, 384)
|
||||
@@ -30529,7 +30636,7 @@ int sp_ecc_verify_384_nb(sp_ecc_ctx_t* sp_ctx, const byte* hash, word32 hashLen,
|
||||
ctx->state = 11;
|
||||
break;
|
||||
case 10: /* DBL */
|
||||
err = sp_384_proj_point_dbl_6_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
err = sp_384_proj_point_dbl_6_nb((sp_ecc_ctx_t*)&ctx->dbl_ctx, &ctx->p1,
|
||||
&ctx->p2, ctx->tmp);
|
||||
if (err == MP_OKAY) {
|
||||
ctx->state = 11;
|
||||
@@ -30655,6 +30762,11 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
sp_384_from_mp(p2->y, 6, pY);
|
||||
sp_384_from_mp(p2->z, 6, pZ);
|
||||
|
||||
#ifndef WOLFSSL_SP_SMALL
|
||||
{
|
||||
sp_384_mod_inv_6(s, s, p384_order);
|
||||
}
|
||||
#endif /* !WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags)) {
|
||||
sp_384_mul_avx2_6(s, s, p384_norm_order);
|
||||
@@ -30668,6 +30780,7 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
sp_384_norm_6(s);
|
||||
#ifdef WOLFSSL_SP_SMALL
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags)) {
|
||||
sp_384_mont_inv_order_avx2_6(s, s, tmp);
|
||||
@@ -30682,6 +30795,20 @@ int sp_ecc_verify_384(const byte* hash, word32 hashLen, mp_int* pX,
|
||||
sp_384_mont_mul_order_6(u2, u2, s);
|
||||
}
|
||||
|
||||
#else
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags)) {
|
||||
sp_384_mont_mul_order_avx2_6(u1, u1, s);
|
||||
sp_384_mont_mul_order_avx2_6(u2, u2, s);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
sp_384_mont_mul_order_6(u1, u1, s);
|
||||
sp_384_mont_mul_order_6(u2, u2, s);
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SP_SMALL */
|
||||
#ifdef HAVE_INTEL_AVX2
|
||||
if (IS_INTEL_BMI2(cpuid_flags) && IS_INTEL_ADX(cpuid_flags))
|
||||
err = sp_384_ecc_mulmod_base_avx2_6(p1, u1, 0, 0, heap);
|
||||
|
||||
+3717
-2504
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user