Skip to content

Commit 6a25cde

Browse files
committed
SP: WOLFSSL_SP_ARM_ARCH to WOLFSSL_ARM_ARCH and fix SAKKE on Thumb2/ARM32
WOLFSSL_SP_ARM_ARCH no longer used. Using WOLFSSL_ARM_ARCH instead. Change umaal check to only available with WOLFSSL_ARM_ARCH > 6. SAKKE mont_reduce with umaal not using correct registers at end.
1 parent 3ae23ec commit 6a25cde

4 files changed

Lines changed: 27 additions & 22 deletions

File tree

wolfcrypt/src/sp_arm32.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@ static void sp_2048_mul_8(sp_digit* r_p, const sp_digit* a_p, const sp_digit* b_
22342234
);
22352235
}
22362236

2237-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
2237+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
22382238
/* Multiply a and b into r. (r = a * b)
22392239
*
22402240
* r A single precision integer.
@@ -4683,7 +4683,7 @@ static void sp_2048_sqr_8(sp_digit* r_p, const sp_digit* a_p)
46834683
);
46844684
}
46854685

4686-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
4686+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
46874687
/* Square a and put result in r. (r = a * a)
46884688
*
46894689
* r A single precision integer.
@@ -9305,7 +9305,7 @@ static SP_NOINLINE void sp_2048_mont_reduce_32(sp_digit* a_p, const sp_digit* m_
93059305
sp_2048_cond_sub_32(a - 32, a, m, (sp_digit)0 - mp);
93069306
}
93079307

9308-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
9308+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
93099309
/* Reduce the number back to 2048 bits using Montgomery reduction.
93109310
*
93119311
* a A single precision number to reduce in place.
@@ -14167,7 +14167,7 @@ static SP_NOINLINE void sp_2048_mont_reduce_64(sp_digit* a_p, const sp_digit* m_
1416714167
sp_2048_cond_sub_64(a - 64, a, m, (sp_digit)0 - mp);
1416814168
}
1416914169

14170-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
14170+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
1417114171
/* Reduce the number back to 2048 bits using Montgomery reduction.
1417214172
*
1417314173
* a A single precision number to reduce in place.
@@ -33531,7 +33531,7 @@ static SP_NOINLINE void sp_3072_mont_reduce_48(sp_digit* a_p, const sp_digit* m_
3353133531
sp_3072_cond_sub_48(a - 48, a, m, (sp_digit)0 - mp);
3353233532
}
3353333533

33534-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
33534+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
3353533535
/* Reduce the number back to 3072 bits using Montgomery reduction.
3353633536
*
3353733537
* a A single precision number to reduce in place.
@@ -40329,7 +40329,7 @@ static SP_NOINLINE void sp_3072_mont_reduce_96(sp_digit* a_p, const sp_digit* m_
4032940329
sp_3072_cond_sub_96(a - 96, a, m, (sp_digit)0 - mp);
4033040330
}
4033140331

40332-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
40332+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
4033340333
/* Reduce the number back to 3072 bits using Montgomery reduction.
4033440334
*
4033540335
* a A single precision number to reduce in place.
@@ -54796,7 +54796,7 @@ static SP_NOINLINE void sp_4096_mont_reduce_128(sp_digit* a_p, const sp_digit* m
5479654796
sp_4096_cond_sub_128(a - 128, a, m, (sp_digit)0 - mp);
5479754797
}
5479854798

54799-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
54799+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
5480054800
/* Reduce the number back to 4096 bits using Montgomery reduction.
5480154801
*
5480254802
* a A single precision number to reduce in place.
@@ -62896,7 +62896,7 @@ static void sp_256_mul_8(sp_digit* r_p, const sp_digit* a_p, const sp_digit* b_p
6289662896
);
6289762897
}
6289862898

62899-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
62899+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
6290062900
/* Multiply a and b into r. (r = a * b)
6290162901
*
6290262902
* r A single precision integer.
@@ -64733,7 +64733,7 @@ static void sp_256_sqr_8(sp_digit* r_p, const sp_digit* a_p)
6473364733
);
6473464734
}
6473564735

64736-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
64736+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
6473764737
/* Square a and put result in r. (r = a * a)
6473864738
*
6473964739
* r A single precision integer.
@@ -67796,7 +67796,7 @@ static SP_NOINLINE void sp_256_mont_mul_8(sp_digit* r_p, const sp_digit* a_p, co
6779667796
(void)mp_p;
6779767797
}
6779867798

67799-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
67799+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
6780067800
/* Multiply two Montgomery form numbers mod the modulus (prime).
6780167801
* (r = a * b mod m)
6780267802
*
@@ -69729,7 +69729,7 @@ static SP_NOINLINE void sp_256_mont_sqr_8(sp_digit* r_p, const sp_digit* a_p, co
6972969729
(void)mp_p;
6973069730
}
6973169731

69732-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
69732+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
6973369733
/* Square the Montgomery form number mod the modulus (prime). (r = a * a mod m)
6973469734
*
6973569735
* r Result of squaring.
@@ -70956,7 +70956,7 @@ static SP_NOINLINE void sp_256_mont_reduce_8(sp_digit* a_p, const sp_digit* m_p,
7095670956
sp_256_cond_sub_8(a - 8, a, m, (sp_digit)0 - mp);
7095770957
}
7095870958

70959-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
70959+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
7096070960
/* Reduce the number back to 256 bits using Montgomery reduction.
7096170961
*
7096270962
* a A single precision number to reduce in place.
@@ -71535,7 +71535,7 @@ static SP_NOINLINE void sp_256_mont_reduce_order_8(sp_digit* a_p, const sp_digit
7153571535
sp_256_cond_sub_8(a - 8, a, m, (sp_digit)0 - mp);
7153671536
}
7153771537

71538-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
71538+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
7153971539
/* Reduce the number back to 256 bits using Montgomery reduction.
7154071540
*
7154171541
* a A single precision number to reduce in place.
@@ -88721,7 +88721,7 @@ static SP_NOINLINE void sp_384_mont_reduce_12(sp_digit* a_p, const sp_digit* m_p
8872188721
sp_384_cond_sub_12(a - 12, a, m, (sp_digit)0 - mp);
8872288722
}
8872388723

88724-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
88724+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
8872588725
/* Reduce the number back to 384 bits using Montgomery reduction.
8872688726
*
8872788727
* a A single precision number to reduce in place.
@@ -115365,7 +115365,7 @@ static SP_NOINLINE void sp_521_mont_reduce_order_17(sp_digit* a_p, const sp_digi
115365115365
sp_521_cond_sub_17(a - 17, a, m, (sp_digit)0 - mp);
115366115366
}
115367115367

115368-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
115368+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
115369115369
/* Reduce the number back to 521 bits using Montgomery reduction.
115370115370
*
115371115371
* a A single precision number to reduce in place.
@@ -144632,7 +144632,7 @@ static SP_NOINLINE void sp_1024_mont_reduce_32(sp_digit* a_p, const sp_digit* m_
144632144632
sp_1024_cond_sub_32(a - 32, a, m, mp);
144633144633
}
144634144634

144635-
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 6)
144635+
#elif defined(WOLFSSL_ARM_ARCH) && (WOLFSSL_ARM_ARCH < 7)
144636144636
/* Reduce the number back to 1024 bits using Montgomery reduction.
144637144637
*
144638144638
* a A single precision number to reduce in place.
@@ -145130,10 +145130,10 @@ static SP_NOINLINE void sp_1024_mont_reduce_32(sp_digit* a_p, const sp_digit* m_
145130145130
"str r7, [%[a], #12]\n\t"
145131145131
"str r8, [%[a], #16]\n\t"
145132145132
"ldr r10, [%[m], #124]\n\t"
145133-
"subs r9, r10, r9\n\t"
145133+
"subs r3, r10, r3\n\t"
145134145134
"neg lr, lr\n\t"
145135-
"sbc r9, r9, r9\n\t"
145136-
"orr lr, lr, r9\n\t"
145135+
"sbc r3, r3, r3\n\t"
145136+
"orr lr, lr, r3\n\t"
145137145137
"mov %[mp], lr\n\t"
145138145138
: [a] "+r" (a), [m] "+r" (m), [mp] "+r" (mp)
145139145139
:

wolfcrypt/src/sp_cortexm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67460,10 +67460,10 @@ static void sp_1024_mont_reduce_32(sp_digit* a_p, const sp_digit* m_p, sp_digit
6746067460
"STR r9, [%[a], #12]\n\t"
6746167461
"STR r10, [%[a], #16]\n\t"
6746267462
"LDR r12, [%[m], #124]\n\t"
67463-
"SUBS r11, r12, r11\n\t"
67463+
"SUBS r3, r12, r3\n\t"
6746467464
"neg r5, r5\n\t"
67465-
"SBC r11, r11, r11\n\t"
67466-
"ORR r5, r5, r11\n\t"
67465+
"SBC r3, r3, r3\n\t"
67466+
"ORR r5, r5, r3\n\t"
6746767467
"MOV %[mp], r5\n\t"
6746867468
: [a] "+r" (a), [m] "+r" (m), [mp] "+r" (mp)
6746967469
:

wolfssl/wolfcrypt/sp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define WOLF_CRYPT_SP_H
2525

2626
#include <wolfssl/wolfcrypt/types.h>
27+
#include <wolfssl/wolfcrypt/settings.h>
2728

2829
#if defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH) || \
2930
defined(WOLFSSL_HAVE_SP_ECC)

wolfssl/wolfcrypt/sp_int.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ This library provides single precision (SP) integer math functions.
3737
extern "C" {
3838
#endif
3939

40+
#if defined(WOLFSSL_SP_ARM_ARCH) && !defined(WOLFSSL_ARM_ARCH)
41+
#define WOLFSSL_ARM_ARCH WOLFSSL_SP_ARM_ARCH
42+
#endif
43+
4044
#if defined(OPENSSL_EXTRA) && !defined(NO_ASN) && \
4145
!defined(WOLFSSL_SP_INT_NEGATIVE)
4246
#define WOLFSSL_SP_INT_NEGATIVE

0 commit comments

Comments
 (0)