Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Lints #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/kem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
hash_h(&mut sk[PK_START..], pk, KYBER_PUBLICKEYBYTES);

if let Some(s) = _seed {
sk[SK_START..].copy_from_slice(&s.1)
sk[SK_START..].copy_from_slice(s.1)
} else {
randombytes(&mut sk[SK_START..], KYBER_SYMBYTES, _rng)?;
}
Expand Down Expand Up @@ -59,7 +59,7 @@ where

// Deterministic randbuf for KAT's
if let Some(s) = _seed {
randbuf[..KYBER_SYMBYTES].copy_from_slice(&s);
randbuf[..KYBER_SYMBYTES].copy_from_slice(s);
} else {
randombytes(&mut randbuf, KYBER_SYMBYTES, _rng)?;
}
Expand Down Expand Up @@ -92,7 +92,7 @@ where
/// - const [u8] sk: input private key (an already allocated array of CRYPTO_SECRETKEYBYTES bytes)
///
/// On failure, ss will contain a pseudo-random value.
pub fn crypto_kem_dec(ss: &mut [u8], ct: &[u8], sk: &[u8]) -> () {
pub fn crypto_kem_dec(ss: &mut [u8], ct: &[u8], sk: &[u8]) {
let mut buf = [0u8; 2 * KYBER_SYMBYTES];
let mut kr = [0u8; 2 * KYBER_SYMBYTES];
let mut cmp = [0u8; KYBER_CIPHERTEXTBYTES];
Expand Down
4 changes: 2 additions & 2 deletions src/kex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ where
fn uake_shared_a(k: &mut [u8], recv: &[u8], tk: &[u8], sk: &[u8]) -> Result<(), KyberError> {
let mut buf = [0u8; 2 * KYBER_SYMBYTES];
crypto_kem_dec(&mut buf, recv, sk);
buf[KYBER_SYMBYTES..].copy_from_slice(&tk[..]);
buf[KYBER_SYMBYTES..].copy_from_slice(tk);
kdf(k, &buf, 2 * KYBER_SYMBYTES);
Ok(())
}
Expand Down Expand Up @@ -424,7 +424,7 @@ fn ake_shared_a(
&recv[KYBER_CIPHERTEXTBYTES..],
ska,
);
buf[2 * KYBER_SYMBYTES..].copy_from_slice(&tk[..]);
buf[2 * KYBER_SYMBYTES..].copy_from_slice(tk);
kdf(k, &buf, 3 * KYBER_SYMBYTES);
Ok(())
}
6 changes: 3 additions & 3 deletions src/reference/fips202.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ pub fn sha3_512(h: &mut [u8], input: &[u8], inlen: usize) {
/// - usize r: rate in bytes (e.g., 168 for SHAKE128)
/// - u8 p: domain separation byte
fn keccak_finalize(s: &mut [u64], pos: usize, r: usize, p: u8) {
s[pos / 8] ^= (p as u64) << 8 * (pos % 8);
s[pos / 8] ^= (p as u64) << (8 * (pos % 8));
s[r / 8 - 1] ^= 1u64 << 63;
}

Expand Down Expand Up @@ -445,9 +445,9 @@ pub fn keccak_absorb_once(s: &mut [u64], r: usize, input: &[u8], mut inlen: usiz
}

for i in 0..inlen {
s[i / 8] ^= (input[idx + i] as u64) << 8 * (i % 8);
s[i / 8] ^= (input[idx + i] as u64) << (8 * (i % 8));
}
s[inlen / 8] ^= (p as u64) << 8 * (inlen % 8);
s[inlen / 8] ^= (p as u64) << (8 * (inlen % 8));
s[(r - 1) / 8] ^= 1u64 << 63;
}

Expand Down
14 changes: 7 additions & 7 deletions src/reference/indcpa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{params::*, poly::*, polyvec::*, symmetric::*, CryptoRng, KyberError,
/// Arguments: [u8] r: the output serialized public key
/// const poly *pk: the input public-key polynomial
/// const [u8] seed: the input public seed
fn pack_pk(r: &mut [u8], pk: &mut Polyvec, seed: &[u8]) {
fn pack_pk(r: &mut [u8], pk: &Polyvec, seed: &[u8]) {
const END: usize = KYBER_SYMBYTES + KYBER_POLYVECBYTES;
polyvec_tobytes(r, pk);
r[KYBER_POLYVECBYTES..END].copy_from_slice(&seed[..KYBER_SYMBYTES]);
Expand All @@ -36,7 +36,7 @@ fn unpack_pk(pk: &mut Polyvec, seed: &mut [u8], packedpk: &[u8]) {
///
/// Arguments: - [u8] r: output serialized secret key
/// - const Polyvec sk: input vector of polynomials (secret key)
fn pack_sk(r: &mut [u8], sk: &mut Polyvec) {
fn pack_sk(r: &mut [u8], sk: &Polyvec) {
polyvec_tobytes(r, sk);
}

Expand All @@ -59,7 +59,7 @@ fn unpack_sk(sk: &mut Polyvec, packedsk: &[u8]) {
/// Arguments: [u8] r: the output serialized ciphertext
/// const poly *pk: the input vector of polynomials b
/// const [u8] seed: the input polynomial v
fn pack_ciphertext(r: &mut [u8], b: &mut Polyvec, v: Poly) {
fn pack_ciphertext(r: &mut [u8], b: &Polyvec, v: Poly) {
polyvec_compress(r, *b);
poly_compress(&mut r[KYBER_POLYVECCOMPRESSEDBYTES..], v);
}
Expand Down Expand Up @@ -184,7 +184,7 @@ where
let mut randbuf = [0u8; 2 * KYBER_SYMBYTES];

if let Some(s) = _seed {
randbuf[..KYBER_SYMBYTES].copy_from_slice(&s.0);
randbuf[..KYBER_SYMBYTES].copy_from_slice(s.0);
} else {
randombytes(&mut randbuf, KYBER_SYMBYTES, _rng)?;
}
Expand Down Expand Up @@ -214,8 +214,8 @@ where
polyvec_add(&mut pkpv, &e);
polyvec_reduce(&mut pkpv);

pack_sk(sk, &mut skpv);
pack_pk(pk, &mut pkpv, publicseed);
pack_sk(sk, &skpv);
pack_pk(pk, &pkpv, publicseed);
Ok(())
}

Expand Down Expand Up @@ -272,7 +272,7 @@ pub fn indcpa_enc(c: &mut [u8], m: &[u8], pk: &[u8], coins: &[u8]) {
polyvec_reduce(&mut b);
poly_reduce(&mut v);

pack_ciphertext(c, &mut b, v);
pack_ciphertext(c, &b, v);
}

/// Name: indcpa_dec
Expand Down
2 changes: 1 addition & 1 deletion src/reference/ntt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn invntt(r: &mut [i16]) {
while j < (start + len) {
t = r[j];
r[j] = barrett_reduce(t + r[j + len]);
r[j + len] = r[j + len] - t;
r[j + len] -= t;
r[j + len] = fqmul(zeta, r[j + len]);
j += 1
}
Expand Down
6 changes: 2 additions & 4 deletions src/reference/poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ pub fn poly_compress(r: &mut [u8], a: Poly) {
pub fn poly_decompress(r: &mut Poly, a: &[u8]) {
match KYBER_POLYCOMPRESSEDBYTES {
128 => {
let mut idx = 0usize;
for i in 0..KYBER_N / 2 {
r.coeffs[2 * i + 0] = ((((a[idx] & 15) as usize * KYBER_Q) + 8) >> 4) as i16;
r.coeffs[2 * i + 1] = ((((a[idx] >> 4) as usize * KYBER_Q) + 8) >> 4) as i16;
idx += 1;
r.coeffs[2 * i + 0] = ((((a[i] & 15) as usize * KYBER_Q) + 8) >> 4) as i16;
r.coeffs[2 * i + 1] = ((((a[i] >> 4) as usize * KYBER_Q) + 8) >> 4) as i16;
}
}
160 => {
Expand Down
4 changes: 2 additions & 2 deletions src/symmetric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn hash_g(out: &mut [u8], input: &[u8], inlen: usize) {

#[cfg(not(feature = "90s"))]
pub fn xof_absorb(state: &mut XofState, input: &[u8], x: u8, y: u8) {
kyber_shake128_absorb(state, &input, x, y);
kyber_shake128_absorb(state, input, x, y);
}

#[cfg(feature = "90s")]
Expand All @@ -99,7 +99,7 @@ pub fn xof_squeezeblocks(out: &mut [u8], outblocks: usize, state: &mut XofState)

#[cfg(not(feature = "90s"))]
pub fn prf(out: &mut [u8], outbytes: usize, key: &[u8], nonce: u8) {
shake256_prf(out, outbytes, &key, nonce);
shake256_prf(out, outbytes, key, nonce);
}

#[cfg(feature = "90s")]
Expand Down
Loading