Skip to content

Commit

Permalink
pull kyber from upstream: dda29cc63af721981ee2c831cf00822e69be3220
Browse files Browse the repository at this point in the history
  • Loading branch information
bhess committed Dec 15, 2023
1 parent cd67eed commit cba3e40
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 13 deletions.
4 changes: 2 additions & 2 deletions docs/algorithms/kem/kyber.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
- **Authors' website**: https://pq-crystals.org/
- **Specification version**: NIST Round 3 submission.
- **Primary Source**<a name="primary-source"></a>:
- **Source**: https://github.com/pq-crystals/kyber/commit/518de2414a85052bb91349bcbcc347f391292d5b with copy_from_upstream patches
- **Source**: https://github.com/pq-crystals/kyber/commit/dda29cc63af721981ee2c831cf00822e69be3220 with copy_from_upstream patches
- **Implementation license (SPDX-Identifier)**: CC0-1.0 or Apache-2.0
- **Optimized Implementation sources**: https://github.com/pq-crystals/kyber/commit/518de2414a85052bb91349bcbcc347f391292d5b with copy_from_upstream patches
- **Optimized Implementation sources**: https://github.com/pq-crystals/kyber/commit/dda29cc63af721981ee2c831cf00822e69be3220 with copy_from_upstream patches
- **oldpqclean-aarch64**:<a name="oldpqclean-aarch64"></a>
- **Source**: https://github.com/PQClean/PQClean/commit/8e220a87308154d48fdfac40abbb191ac7fce06a with copy_from_upstream patches
- **Implementation license (SPDX-Identifier)**: CC0-1.0 and (CC0-1.0 or Apache-2.0) and (CC0-1.0 or MIT) and MIT
Expand Down
2 changes: 1 addition & 1 deletion docs/algorithms/kem/kyber.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ website: https://pq-crystals.org/
nist-round: 3
spec-version: NIST Round 3 submission
primary-upstream:
source: https://github.com/pq-crystals/kyber/commit/518de2414a85052bb91349bcbcc347f391292d5b
source: https://github.com/pq-crystals/kyber/commit/dda29cc63af721981ee2c831cf00822e69be3220
with copy_from_upstream patches
spdx-license-identifier: CC0-1.0 or Apache-2.0
optimized-upstreams:
Expand Down
2 changes: 1 addition & 1 deletion scripts/copy_from_upstream/copy_from_upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ upstreams:
name: pqcrystals-kyber
git_url: https://github.com/pq-crystals/kyber.git
git_branch: master
git_commit: 518de2414a85052bb91349bcbcc347f391292d5b
git_commit: dda29cc63af721981ee2c831cf00822e69be3220
kem_meta_path: '{pretty_name_full}_META.yml'
kem_scheme_path: '.'
patches: [pqcrystals-kyber-yml.patch, pqcrystals-kyber-ref-shake-aes.patch, pqcrystals-kyber-avx2-shake-aes.patch]
Expand Down
10 changes: 10 additions & 0 deletions src/kem/kyber/pqcrystals-kyber_kyber1024_avx2/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ void cmov(uint8_t * restrict r, const uint8_t *x, size_t len, uint8_t b)
size_t i;
__m256i xvec, rvec, bvec;

#if defined(__GNUC__) || defined(__clang__)
// Prevent the compiler from
// 1) inferring that b is 0/1-valued, and
// 2) handling the two cases with a branch.
// This is not necessary when verify.c and kem.c are separate translation
// units, but we expect that downstream consumers will copy this code and/or
// change how it is built.
__asm__("" : "+r"(b) : /* no inputs */);
#endif

bvec = _mm256_set1_epi64x(-(uint64_t)b);
for(i=0;i<len/32;i++) {
rvec = _mm256_loadu_si256((__m256i *)&r[32*i]);
Expand Down
11 changes: 8 additions & 3 deletions src/kem/kyber/pqcrystals-kyber_kyber1024_ref/poly.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,19 @@ void poly_frommsg(poly *r, const uint8_t msg[KYBER_INDCPA_MSGBYTES])
void poly_tomsg(uint8_t msg[KYBER_INDCPA_MSGBYTES], const poly *a)
{
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->coeffs[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;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/kem/kyber/pqcrystals-kyber_kyber1024_ref/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ void cmov(uint8_t *r, const uint8_t *x, size_t len, uint8_t b)
{
size_t i;

#if defined(__GNUC__) || defined(__clang__)
// Prevent the compiler from
// 1) inferring that b is 0/1-valued, and
// 2) handling the two cases with a branch.
// This is not necessary when verify.c and kem.c are separate translation
// units, but we expect that downstream consumers will copy this code and/or
// change how it is built.
__asm__("" : "+r"(b) : /* no inputs */);
#endif

b = -b;
for(i=0;i<len;i++)
r[i] ^= b & (r[i] ^ x[i]);
Expand Down
10 changes: 10 additions & 0 deletions src/kem/kyber/pqcrystals-kyber_kyber512_avx2/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ void cmov(uint8_t * restrict r, const uint8_t *x, size_t len, uint8_t b)
size_t i;
__m256i xvec, rvec, bvec;

#if defined(__GNUC__) || defined(__clang__)
// Prevent the compiler from
// 1) inferring that b is 0/1-valued, and
// 2) handling the two cases with a branch.
// This is not necessary when verify.c and kem.c are separate translation
// units, but we expect that downstream consumers will copy this code and/or
// change how it is built.
__asm__("" : "+r"(b) : /* no inputs */);
#endif

bvec = _mm256_set1_epi64x(-(uint64_t)b);
for(i=0;i<len/32;i++) {
rvec = _mm256_loadu_si256((__m256i *)&r[32*i]);
Expand Down
11 changes: 8 additions & 3 deletions src/kem/kyber/pqcrystals-kyber_kyber512_ref/poly.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,19 @@ void poly_frommsg(poly *r, const uint8_t msg[KYBER_INDCPA_MSGBYTES])
void poly_tomsg(uint8_t msg[KYBER_INDCPA_MSGBYTES], const poly *a)
{
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->coeffs[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;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/kem/kyber/pqcrystals-kyber_kyber512_ref/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ void cmov(uint8_t *r, const uint8_t *x, size_t len, uint8_t b)
{
size_t i;

#if defined(__GNUC__) || defined(__clang__)
// Prevent the compiler from
// 1) inferring that b is 0/1-valued, and
// 2) handling the two cases with a branch.
// This is not necessary when verify.c and kem.c are separate translation
// units, but we expect that downstream consumers will copy this code and/or
// change how it is built.
__asm__("" : "+r"(b) : /* no inputs */);
#endif

b = -b;
for(i=0;i<len;i++)
r[i] ^= b & (r[i] ^ x[i]);
Expand Down
10 changes: 10 additions & 0 deletions src/kem/kyber/pqcrystals-kyber_kyber768_avx2/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ void cmov(uint8_t * restrict r, const uint8_t *x, size_t len, uint8_t b)
size_t i;
__m256i xvec, rvec, bvec;

#if defined(__GNUC__) || defined(__clang__)
// Prevent the compiler from
// 1) inferring that b is 0/1-valued, and
// 2) handling the two cases with a branch.
// This is not necessary when verify.c and kem.c are separate translation
// units, but we expect that downstream consumers will copy this code and/or
// change how it is built.
__asm__("" : "+r"(b) : /* no inputs */);
#endif

bvec = _mm256_set1_epi64x(-(uint64_t)b);
for(i=0;i<len/32;i++) {
rvec = _mm256_loadu_si256((__m256i *)&r[32*i]);
Expand Down
11 changes: 8 additions & 3 deletions src/kem/kyber/pqcrystals-kyber_kyber768_ref/poly.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,19 @@ void poly_frommsg(poly *r, const uint8_t msg[KYBER_INDCPA_MSGBYTES])
void poly_tomsg(uint8_t msg[KYBER_INDCPA_MSGBYTES], const poly *a)
{
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->coeffs[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;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/kem/kyber/pqcrystals-kyber_kyber768_ref/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ void cmov(uint8_t *r, const uint8_t *x, size_t len, uint8_t b)
{
size_t i;

#if defined(__GNUC__) || defined(__clang__)
// Prevent the compiler from
// 1) inferring that b is 0/1-valued, and
// 2) handling the two cases with a branch.
// This is not necessary when verify.c and kem.c are separate translation
// units, but we expect that downstream consumers will copy this code and/or
// change how it is built.
__asm__("" : "+r"(b) : /* no inputs */);
#endif

b = -b;
for(i=0;i<len;i++)
r[i] ^= b & (r[i] ^ x[i]);
Expand Down

0 comments on commit cba3e40

Please sign in to comment.