-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Spencer Wilson <spencer.wilson@uwaterloo.ca>
- Loading branch information
Showing
2 changed files
with
90 additions
and
2 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
88 changes: 88 additions & 0 deletions
88
scripts/copy_from_upstream/patches/pqclean-hqc-decaps.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,88 @@ | ||
271d40f339844ece6a2046645da68c08a04b0921 | ||
diff --git a/crypto_kem/hqc-128/clean/kem.c b/crypto_kem/hqc-128/clean/kem.c | ||
index ad09b35..c722a75 100644 | ||
--- a/crypto_kem/hqc-128/clean/kem.c | ||
+++ b/crypto_kem/hqc-128/clean/kem.c | ||
@@ -87,7 +87,7 @@ int PQCLEAN_HQC128_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const ui | ||
uint8_t result; | ||
uint64_t u[VEC_N_SIZE_64] = {0}; | ||
uint64_t v[VEC_N1N2_SIZE_64] = {0}; | ||
- const uint8_t *pk = sk + SEED_BYTES; | ||
+ const uint8_t *pk = sk + SEED_BYTES + VEC_K_SIZE_BYTES; | ||
uint8_t sigma[VEC_K_SIZE_BYTES] = {0}; | ||
uint8_t theta[SHAKE256_512_BYTES] = {0}; | ||
uint64_t u2[VEC_N_SIZE_64] = {0}; | ||
@@ -115,7 +115,7 @@ int PQCLEAN_HQC128_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const ui | ||
result |= PQCLEAN_HQC128_CLEAN_vect_compare((uint8_t *)u, (uint8_t *)u2, VEC_N_SIZE_BYTES); | ||
result |= PQCLEAN_HQC128_CLEAN_vect_compare((uint8_t *)v, (uint8_t *)v2, VEC_N1N2_SIZE_BYTES); | ||
|
||
- result = (uint8_t) (-((int16_t) result) >> 15); | ||
+ result -= 1; | ||
|
||
for (size_t i = 0; i < VEC_K_SIZE_BYTES; ++i) { | ||
mc[i] = (m[i] & result) ^ (sigma[i] & ~result); | ||
@@ -126,5 +126,5 @@ int PQCLEAN_HQC128_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const ui | ||
PQCLEAN_HQC128_CLEAN_store8_arr(mc + VEC_K_SIZE_BYTES + VEC_N_SIZE_BYTES, VEC_N1N2_SIZE_BYTES, v, VEC_N1N2_SIZE_64); | ||
PQCLEAN_HQC128_CLEAN_shake256_512_ds(&shake256state, ss, mc, VEC_K_SIZE_BYTES + VEC_N_SIZE_BYTES + VEC_N1N2_SIZE_BYTES, K_FCT_DOMAIN); | ||
|
||
- return -(~result & 1); | ||
+ return (result & 1) - 1; | ||
} | ||
diff --git a/crypto_kem/hqc-192/clean/kem.c b/crypto_kem/hqc-192/clean/kem.c | ||
index f611ebb..95a0023 100644 | ||
--- a/crypto_kem/hqc-192/clean/kem.c | ||
+++ b/crypto_kem/hqc-192/clean/kem.c | ||
@@ -87,7 +87,7 @@ int PQCLEAN_HQC192_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const ui | ||
uint8_t result; | ||
uint64_t u[VEC_N_SIZE_64] = {0}; | ||
uint64_t v[VEC_N1N2_SIZE_64] = {0}; | ||
- const uint8_t *pk = sk + SEED_BYTES; | ||
+ const uint8_t *pk = sk + SEED_BYTES + VEC_K_SIZE_BYTES; | ||
uint8_t sigma[VEC_K_SIZE_BYTES] = {0}; | ||
uint8_t theta[SHAKE256_512_BYTES] = {0}; | ||
uint64_t u2[VEC_N_SIZE_64] = {0}; | ||
@@ -115,7 +115,7 @@ int PQCLEAN_HQC192_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const ui | ||
result |= PQCLEAN_HQC192_CLEAN_vect_compare((uint8_t *)u, (uint8_t *)u2, VEC_N_SIZE_BYTES); | ||
result |= PQCLEAN_HQC192_CLEAN_vect_compare((uint8_t *)v, (uint8_t *)v2, VEC_N1N2_SIZE_BYTES); | ||
|
||
- result = (uint8_t) (-((int16_t) result) >> 15); | ||
+ result -= 1; | ||
|
||
for (size_t i = 0; i < VEC_K_SIZE_BYTES; ++i) { | ||
mc[i] = (m[i] & result) ^ (sigma[i] & ~result); | ||
@@ -126,5 +126,5 @@ int PQCLEAN_HQC192_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const ui | ||
PQCLEAN_HQC192_CLEAN_store8_arr(mc + VEC_K_SIZE_BYTES + VEC_N_SIZE_BYTES, VEC_N1N2_SIZE_BYTES, v, VEC_N1N2_SIZE_64); | ||
PQCLEAN_HQC192_CLEAN_shake256_512_ds(&shake256state, ss, mc, VEC_K_SIZE_BYTES + VEC_N_SIZE_BYTES + VEC_N1N2_SIZE_BYTES, K_FCT_DOMAIN); | ||
|
||
- return -(~result & 1); | ||
+ return (result & 1) - 1; | ||
} | ||
diff --git a/crypto_kem/hqc-256/clean/kem.c b/crypto_kem/hqc-256/clean/kem.c | ||
index 4e47e87..d4c6a08 100644 | ||
--- a/crypto_kem/hqc-256/clean/kem.c | ||
+++ b/crypto_kem/hqc-256/clean/kem.c | ||
@@ -87,7 +87,7 @@ int PQCLEAN_HQC256_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const ui | ||
uint8_t result; | ||
uint64_t u[VEC_N_SIZE_64] = {0}; | ||
uint64_t v[VEC_N1N2_SIZE_64] = {0}; | ||
- const uint8_t *pk = sk + SEED_BYTES; | ||
+ const uint8_t *pk = sk + SEED_BYTES + VEC_K_SIZE_BYTES; | ||
uint8_t sigma[VEC_K_SIZE_BYTES] = {0}; | ||
uint8_t theta[SHAKE256_512_BYTES] = {0}; | ||
uint64_t u2[VEC_N_SIZE_64] = {0}; | ||
@@ -115,7 +115,7 @@ int PQCLEAN_HQC256_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const ui | ||
result |= PQCLEAN_HQC256_CLEAN_vect_compare((uint8_t *)u, (uint8_t *)u2, VEC_N_SIZE_BYTES); | ||
result |= PQCLEAN_HQC256_CLEAN_vect_compare((uint8_t *)v, (uint8_t *)v2, VEC_N1N2_SIZE_BYTES); | ||
|
||
- result = (uint8_t) (-((int16_t) result) >> 15); | ||
+ result -= 1; | ||
|
||
for (size_t i = 0; i < VEC_K_SIZE_BYTES; ++i) { | ||
mc[i] = (m[i] & result) ^ (sigma[i] & ~result); | ||
@@ -126,5 +126,5 @@ int PQCLEAN_HQC256_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const ui | ||
PQCLEAN_HQC256_CLEAN_store8_arr(mc + VEC_K_SIZE_BYTES + VEC_N_SIZE_BYTES, VEC_N1N2_SIZE_BYTES, v, VEC_N1N2_SIZE_64); | ||
PQCLEAN_HQC256_CLEAN_shake256_512_ds(&shake256state, ss, mc, VEC_K_SIZE_BYTES + VEC_N_SIZE_BYTES + VEC_N1N2_SIZE_BYTES, K_FCT_DOMAIN); | ||
|
||
- return -(~result & 1); | ||
+ return (result & 1) - 1; | ||
} |