-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds patch to aarch64 Kyber pulled from PQClean for variable-time div…
…ision in poly_tomsg. (#1636)
- Loading branch information
Showing
5 changed files
with
106 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
scripts/copy_from_upstream/patches/pqclean-kyber-armneon-variable-timing-fix.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
diff --git a/crypto_kem/kyber1024/aarch64/poly.c b/crypto_kem/kyber1024/aarch64/poly.c | ||
index 1dfa52c..02e010b 100644 | ||
--- a/crypto_kem/kyber1024/aarch64/poly.c | ||
+++ b/crypto_kem/kyber1024/aarch64/poly.c | ||
@@ -207,14 +207,19 @@ void poly_frommsg(int16_t r[KYBER_N], const uint8_t msg[KYBER_INDCPA_MSGBYTES]) | ||
**************************************************/ | ||
void poly_tomsg(uint8_t msg[KYBER_INDCPA_MSGBYTES], const int16_t a[KYBER_N]) { | ||
unsigned int i, j; | ||
- uint16_t t; | ||
+ uint32_t t; | ||
|
||
for (i = 0; i < KYBER_N / 8; i++) { | ||
msg[i] = 0; | ||
for (j = 0; j < 8; j++) { | ||
t = a[8 * i + j]; | ||
- t += ((int16_t)t >> 15) & KYBER_Q; | ||
- t = (((t << 1) + KYBER_Q / 2) / KYBER_Q) & 1; | ||
+ // t += ((int16_t)t >> 15) & KYBER_Q; | ||
+ // t = (((t << 1) + KYBER_Q/2)/KYBER_Q) & 1; | ||
+ t <<= 1; | ||
+ t += 1665; | ||
+ t *= 80635; | ||
+ t >>= 28; | ||
+ t &= 1; | ||
msg[i] |= t << j; | ||
} | ||
} | ||
diff --git a/crypto_kem/kyber512/aarch64/poly.c b/crypto_kem/kyber512/aarch64/poly.c | ||
index dffc655..fcfcedd 100644 | ||
--- a/crypto_kem/kyber512/aarch64/poly.c | ||
+++ b/crypto_kem/kyber512/aarch64/poly.c | ||
@@ -194,14 +194,19 @@ void poly_frommsg(int16_t r[KYBER_N], const uint8_t msg[KYBER_INDCPA_MSGBYTES]) | ||
**************************************************/ | ||
void poly_tomsg(uint8_t msg[KYBER_INDCPA_MSGBYTES], const int16_t a[KYBER_N]) { | ||
unsigned int i, j; | ||
- uint16_t t; | ||
+ uint32_t t; | ||
|
||
for (i = 0; i < KYBER_N / 8; i++) { | ||
msg[i] = 0; | ||
for (j = 0; j < 8; j++) { | ||
t = a[8 * i + j]; | ||
- t += ((int16_t)t >> 15) & KYBER_Q; | ||
- t = (((t << 1) + KYBER_Q / 2) / KYBER_Q) & 1; | ||
+ // t += ((int16_t)t >> 15) & KYBER_Q; | ||
+ // t = (((t << 1) + KYBER_Q/2)/KYBER_Q) & 1; | ||
+ t <<= 1; | ||
+ t += 1665; | ||
+ t *= 80635; | ||
+ t >>= 28; | ||
+ t &= 1; | ||
msg[i] |= t << j; | ||
} | ||
} | ||
diff --git a/crypto_kem/kyber768/aarch64/poly.c b/crypto_kem/kyber768/aarch64/poly.c | ||
index dffc655..fcfcedd 100644 | ||
--- a/crypto_kem/kyber768/aarch64/poly.c | ||
+++ b/crypto_kem/kyber768/aarch64/poly.c | ||
@@ -194,14 +194,19 @@ void poly_frommsg(int16_t r[KYBER_N], const uint8_t msg[KYBER_INDCPA_MSGBYTES]) | ||
**************************************************/ | ||
void poly_tomsg(uint8_t msg[KYBER_INDCPA_MSGBYTES], const int16_t a[KYBER_N]) { | ||
unsigned int i, j; | ||
- uint16_t t; | ||
+ uint32_t t; | ||
|
||
for (i = 0; i < KYBER_N / 8; i++) { | ||
msg[i] = 0; | ||
for (j = 0; j < 8; j++) { | ||
t = a[8 * i + j]; | ||
- t += ((int16_t)t >> 15) & KYBER_Q; | ||
- t = (((t << 1) + KYBER_Q / 2) / KYBER_Q) & 1; | ||
+ // t += ((int16_t)t >> 15) & KYBER_Q; | ||
+ // t = (((t << 1) + KYBER_Q/2)/KYBER_Q) & 1; | ||
+ t <<= 1; | ||
+ t += 1665; | ||
+ t *= 80635; | ||
+ t >>= 28; | ||
+ t &= 1; | ||
msg[i] |= t << j; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters