Skip to content

Commit 1eacfda

Browse files
authored
Merge pull request #578 from PQClean/sw-hqc-patch
2 parents c3e6861 + a021b0e commit 1eacfda

84 files changed

Lines changed: 408 additions & 12 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SECURITY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Reported vulnerabilities in the **Historic Issues** section have become irreleva
2929

3030
## Resolved Issues
3131

32+
### 2024-12-11
33+
* HQC decapsulation mishandled the secret key and, when given a malformed ciphertext, returned an incorrect shared secret.
34+
[PR #578](https://github.com/PQClean/PQClean/pull/578) addressed this.
35+
3236
### 2024-06-11
3337
* Kyber used a conditional move that resulted in branch instructions leaking side-channel information for certain compilers.
3438
[PR #558](https://github.com/PQClean/PQClean/pull/558) addressed this for the `clean` and `avx2` implementations.

crypto_kem/hqc-128/META.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ principal-submitters:
2525
- Gilles Zémor
2626
implementations:
2727
- name: clean
28-
version: hqc-submission_2023-04-30 via https://github.com/SWilson4/package-pqclean/tree/8db1b24b/hqc
28+
version: hqc-submission_2023-04-30 via https://github.com/SWilson4/package-pqclean/tree/9b509aa7/hqc

crypto_kem/hqc-128/clean/api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ int PQCLEAN_HQC128_CLEAN_crypto_kem_enc(uint8_t *ct, uint8_t *ss, const uint8_t
2323

2424
int PQCLEAN_HQC128_CLEAN_crypto_kem_dec(uint8_t *ss, const uint8_t *ct, const uint8_t *sk);
2525

26+
2627
#endif

crypto_kem/hqc-128/clean/code.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @brief Implementation of concatenated code
99
*/
1010

11+
12+
1113
/**
1214
*
1315
* @brief Encoding the message m to a code word em using the concatenated code
@@ -26,6 +28,8 @@ void PQCLEAN_HQC128_CLEAN_code_encode(uint64_t *em, const uint8_t *m) {
2628

2729
}
2830

31+
32+
2933
/**
3034
* @brief Decoding the code word em to a message m using the concatenated code
3135
*
@@ -38,4 +42,5 @@ void PQCLEAN_HQC128_CLEAN_code_decode(uint8_t *m, const uint64_t *em) {
3842
PQCLEAN_HQC128_CLEAN_reed_muller_decode(tmp, em);
3943
PQCLEAN_HQC128_CLEAN_reed_solomon_decode(m, tmp);
4044

45+
4146
}

crypto_kem/hqc-128/clean/code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CODE_H
22
#define CODE_H
33

4+
45
/**
56
* @file code.h
67
* @brief Header file of code.c
@@ -12,4 +13,5 @@ void PQCLEAN_HQC128_CLEAN_code_encode(uint64_t *em, const uint8_t *message);
1213

1314
void PQCLEAN_HQC128_CLEAN_code_decode(uint8_t *m, const uint64_t *em);
1415

16+
1517
#endif

crypto_kem/hqc-128/clean/domains.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#ifndef DOMAINS_H
22
#define DOMAINS_H
33

4+
45
/**
56
* @file domains.h
67
* @brief SHAKE-256 domains separation header grouping all domains to avoid collisions
78
*/
89

10+
911
#define PRNG_DOMAIN 1
1012
#define SEEDEXPANDER_DOMAIN 2
1113
#define G_FCT_DOMAIN 3

crypto_kem/hqc-128/clean/fft.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* https://binary.cr.yp.to/mcbits-20130616.pdf
1515
*/
1616

17+
1718
static void radix_big(uint16_t *f0, uint16_t *f1, const uint16_t *f, uint32_t m_f);
1819

1920
/**
@@ -28,6 +29,8 @@ static void compute_fft_betas(uint16_t *betas) {
2829
}
2930
}
3031

32+
33+
3134
/**
3235
* @brief Computes the subset sums of the given set
3336
*
@@ -49,6 +52,8 @@ static void compute_subset_sums(uint16_t *subset_sums, const uint16_t *set, uint
4952
}
5053
}
5154

55+
56+
5257
/**
5358
* @brief Computes the radix conversion of a polynomial f in GF(2^m)[x]
5459
*
@@ -143,6 +148,8 @@ static void radix_big(uint16_t *f0, uint16_t *f1, const uint16_t *f, uint32_t m_
143148
memcpy(f1 + n, Q1, 2 * n);
144149
}
145150

151+
152+
146153
/**
147154
* @brief Evaluates f at all subset sums of a given set
148155
*
@@ -236,6 +243,8 @@ static void fft_rec(uint16_t *w, uint16_t *f, size_t f_coeffs, uint8_t m, uint32
236243
}
237244
}
238245

246+
247+
239248
/**
240249
* @brief Evaluates f on all fields elements using an additive FFT algorithm
241250
*
@@ -305,6 +314,8 @@ void PQCLEAN_HQC128_CLEAN_fft(uint16_t *w, const uint16_t *f, size_t f_coeffs) {
305314
}
306315
}
307316

317+
318+
308319
/**
309320
* @brief Retrieves the error polynomial error from the evaluations w of the ELP (Error Locator Polynomial) on all field elements.
310321
*

crypto_kem/hqc-128/clean/fft.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef FFT_H
22
#define FFT_H
33

4+
45
/**
56
* @file fft.h
67
* @brief Header file of fft.c
@@ -13,4 +14,5 @@ void PQCLEAN_HQC128_CLEAN_fft(uint16_t *w, const uint16_t *f, size_t f_coeffs);
1314

1415
void PQCLEAN_HQC128_CLEAN_fft_retrieve_error_poly(uint8_t *error, const uint16_t *w);
1516

17+
1618
#endif

crypto_kem/hqc-128/clean/gf.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @brief Galois field implementation
88
*/
99

10+
1011
/**
1112
* @brief Computes the number of trailing zero bits.
1213
*
@@ -23,6 +24,8 @@ static uint16_t trailing_zero_bits_count(uint16_t a) {
2324
return tmp;
2425
}
2526

27+
28+
2629
/**
2730
* Reduces polynomial x modulo primitive polynomial GF_POLY.
2831
* @returns x mod GF_POLY
@@ -57,6 +60,8 @@ static uint16_t gf_reduce(uint64_t x, size_t deg_x) {
5760
return (uint16_t)x;
5861
}
5962

63+
64+
6065
/**
6166
* Carryless multiplication of two polynomials a and b.
6267
*
@@ -105,6 +110,8 @@ static void gf_carryless_mul(uint8_t c[2], uint8_t a, uint8_t b) {
105110
c[1] = (uint8_t)h;
106111
}
107112

113+
114+
108115
/**
109116
* Multiplies two elements of GF(2^GF_M).
110117
* @returns the product a*b
@@ -118,6 +125,8 @@ uint16_t PQCLEAN_HQC128_CLEAN_gf_mul(uint16_t a, uint16_t b) {
118125
return gf_reduce(tmp, 2 * (PARAM_M - 1));
119126
}
120127

128+
129+
121130
/**
122131
* @brief Squares an element of GF(2^PARAM_M).
123132
* @returns a^2
@@ -134,6 +143,8 @@ uint16_t PQCLEAN_HQC128_CLEAN_gf_square(uint16_t a) {
134143
return gf_reduce(s, 2 * (PARAM_M - 1));
135144
}
136145

146+
147+
137148
/**
138149
* @brief Computes the inverse of an element of GF(2^PARAM_M),
139150
* using the addition chain 1 2 3 4 7 11 15 30 60 120 127 254

crypto_kem/hqc-128/clean/gf.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
#ifndef GF_H
22
#define GF_H
33

4+
45
/**
56
* @file gf.h
67
* @brief Header file of gf.c
78
*/
89

910
#include <stdint.h>
1011

12+
1113
/**
1214
* Powers of the root alpha of 1 + x^2 + x^3 + x^4 + x^8.
1315
* The last two elements are needed by the PQCLEAN_HQC128_CLEAN_gf_mul function
1416
* (for example if both elements to multiply are zero).
1517
*/
1618
static const uint16_t gf_exp [258] = { 1, 2, 4, 8, 16, 32, 64, 128, 29, 58, 116, 232, 205, 135, 19, 38, 76, 152, 45, 90, 180, 117, 234, 201, 143, 3, 6, 12, 24, 48, 96, 192, 157, 39, 78, 156, 37, 74, 148, 53, 106, 212, 181, 119, 238, 193, 159, 35, 70, 140, 5, 10, 20, 40, 80, 160, 93, 186, 105, 210, 185, 111, 222, 161, 95, 190, 97, 194, 153, 47, 94, 188, 101, 202, 137, 15, 30, 60, 120, 240, 253, 231, 211, 187, 107, 214, 177, 127, 254, 225, 223, 163, 91, 182, 113, 226, 217, 175, 67, 134, 17, 34, 68, 136, 13, 26, 52, 104, 208, 189, 103, 206, 129, 31, 62, 124, 248, 237, 199, 147, 59, 118, 236, 197, 151, 51, 102, 204, 133, 23, 46, 92, 184, 109, 218, 169, 79, 158, 33, 66, 132, 21, 42, 84, 168, 77, 154, 41, 82, 164, 85, 170, 73, 146, 57, 114, 228, 213, 183, 115, 230, 209, 191, 99, 198, 145, 63, 126, 252, 229, 215, 179, 123, 246, 241, 255, 227, 219, 171, 75, 150, 49, 98, 196, 149, 55, 110, 220, 165, 87, 174, 65, 130, 25, 50, 100, 200, 141, 7, 14, 28, 56, 112, 224, 221, 167, 83, 166, 81, 162, 89, 178, 121, 242, 249, 239, 195, 155, 43, 86, 172, 69, 138, 9, 18, 36, 72, 144, 61, 122, 244, 245, 247, 243, 251, 235, 203, 139, 11, 22, 44, 88, 176, 125, 250, 233, 207, 131, 27, 54, 108, 216, 173, 71, 142, 1, 2, 4 };
1719

20+
21+
1822
/**
1923
* Logarithm of elements of GF(2^8) to the base alpha (root of 1 + x^2 + x^3 + x^4 + x^8).
2024
* The logarithm of 0 is set to 0 by convention.
2125
*/
2226
static const uint16_t gf_log [256] = { 0, 0, 1, 25, 2, 50, 26, 198, 3, 223, 51, 238, 27, 104, 199, 75, 4, 100, 224, 14, 52, 141, 239, 129, 28, 193, 105, 248, 200, 8, 76, 113, 5, 138, 101, 47, 225, 36, 15, 33, 53, 147, 142, 218, 240, 18, 130, 69, 29, 181, 194, 125, 106, 39, 249, 185, 201, 154, 9, 120, 77, 228, 114, 166, 6, 191, 139, 98, 102, 221, 48, 253, 226, 152, 37, 179, 16, 145, 34, 136, 54, 208, 148, 206, 143, 150, 219, 189, 241, 210, 19, 92, 131, 56, 70, 64, 30, 66, 182, 163, 195, 72, 126, 110, 107, 58, 40, 84, 250, 133, 186, 61, 202, 94, 155, 159, 10, 21, 121, 43, 78, 212, 229, 172, 115, 243, 167, 87, 7, 112, 192, 247, 140, 128, 99, 13, 103, 74, 222, 237, 49, 197, 254, 24, 227, 165, 153, 119, 38, 184, 180, 124, 17, 68, 146, 217, 35, 32, 137, 46, 55, 63, 209, 91, 149, 188, 207, 205, 144, 135, 151, 178, 220, 252, 190, 97, 242, 86, 211, 171, 20, 42, 93, 158, 132, 60, 57, 83, 71, 109, 65, 162, 31, 45, 67, 216, 183, 123, 164, 118, 196, 23, 73, 236, 127, 12, 111, 246, 108, 161, 59, 82, 41, 157, 85, 170, 251, 96, 134, 177, 187, 204, 62, 90, 203, 89, 95, 176, 156, 169, 160, 81, 11, 245, 22, 235, 122, 117, 44, 215, 79, 174, 213, 233, 230, 231, 173, 232, 116, 214, 244, 234, 168, 80, 88, 175 };
2327

28+
29+
2430
uint16_t PQCLEAN_HQC128_CLEAN_gf_mul(uint16_t a, uint16_t b);
2531

2632
uint16_t PQCLEAN_HQC128_CLEAN_gf_square(uint16_t a);
2733

2834
uint16_t PQCLEAN_HQC128_CLEAN_gf_inverse(uint16_t a);
2935

36+
3037
#endif

0 commit comments

Comments
 (0)