Skip to content

Commit

Permalink
Use as instead of unwrap().
Browse files Browse the repository at this point in the history
  • Loading branch information
xvzcf committed Aug 10, 2023
1 parent a74bc9d commit 2abc0fd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/kem/kyber768/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn compress_q(fe: KyberFieldElement, to_bit_size: usize) -> KyberFieldElement {
compressed /= u32::from(KyberFieldElement::MODULUS << 1);

KyberFieldElement {
value: (compressed & (two_pow_bit_size - 1)).try_into().unwrap()
value: (compressed & (two_pow_bit_size - 1)) as u16
}
}

Expand All @@ -42,6 +42,6 @@ fn decompress_q(fe: KyberFieldElement, to_bit_size: usize) -> KyberFieldElement
decompressed >>= to_bit_size + 1;

KyberFieldElement {
value: decompressed.try_into().unwrap()
value: decompressed as u16
}
}
4 changes: 2 additions & 2 deletions src/kem/kyber768/field_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ impl KyberFieldElement {

pub fn barrett_reduce(value : u32) -> Self {
let product : u64 = u64::from(value) * u64::from(Self::BARRETT_MULTIPLIER);
let quotient : u32 = (product >> Self::BARRETT_SHIFT).try_into().unwrap();
let quotient : u32 = (product >> Self::BARRETT_SHIFT) as u32;

let remainder = value - (quotient * u32::from(Self::MODULUS));
let remainder : u16 = remainder.try_into().unwrap();
let remainder : u16 = remainder as u16;

let remainder_minus_modulus = remainder.wrapping_sub(Self::MODULUS);

Expand Down
2 changes: 1 addition & 1 deletion src/kem/kyber768/sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn sample_from_binomial_distribution_with_2_coins(
let outcome_2: u8 = ((coin_toss_outcomes >> (outcome_set + 2)) & 0x3) as u8;
let outcome_2: KyberFieldElement = outcome_2.into();

let offset = usize::try_from(outcome_set >> 2).unwrap();
let offset = (outcome_set >> 2) as usize;
sampled[8 * chunk_number + offset] = outcome_1 - outcome_2;
}
}
Expand Down

0 comments on commit 2abc0fd

Please sign in to comment.