Skip to content

Commit

Permalink
Merge pull request #5593 from oasisprotocol/peternose/trivial/fix-ove…
Browse files Browse the repository at this point in the history
…rflow

keymanager/src/churp: Fix overflow in test
  • Loading branch information
peternose authored Mar 11, 2024
2 parents 955969d + cf1d337 commit 4f7767c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Empty file added .changelog/5593.trivial.md
Empty file.
12 changes: 7 additions & 5 deletions keymanager/src/churp/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl Storage {
mod tests {
use std::sync::Arc;

use rand::rngs::OsRng;
use rand::{rngs::StdRng, SeedableRng};

use oasis_core_runtime::storage::{KeyValue, UntrustedInMemoryStorage};

Expand All @@ -152,9 +152,10 @@ mod tests {

#[test]
fn test_store_load_polynomial() {
let mut rng: StdRng = SeedableRng::from_seed([1u8; 32]);
let untrusted = Arc::new(UntrustedInMemoryStorage::new());
let storage = Storage::new(untrusted.clone());
let polynomial = BivariatePolynomial::<p384::Scalar>::random(2, 4, &mut OsRng);
let polynomial = BivariatePolynomial::<p384::Scalar>::random(2, 4, &mut rng);
let churp_id = 1;
let round = 10;

Expand Down Expand Up @@ -190,7 +191,7 @@ mod tests {
.insert(wrong_key, encrypted_polynomial.clone())
.expect("bivariate polynomial should be stored");

encrypted_polynomial[0] += 1;
encrypted_polynomial[0] = encrypted_polynomial[0].saturating_add(1);
untrusted
.insert(right_key, encrypted_polynomial.clone())
.expect("bivariate polynomial should be stored");
Expand All @@ -208,7 +209,8 @@ mod tests {

#[test]
fn test_encrypt_decrypt_polynomial() {
let polynomial = BivariatePolynomial::<p384::Scalar>::random(2, 4, &mut OsRng);
let mut rng: StdRng = SeedableRng::from_seed([1u8; 32]);
let polynomial = BivariatePolynomial::<p384::Scalar>::random(2, 4, &mut rng);
let churp_id = 1;
let round = 10;

Expand All @@ -229,7 +231,7 @@ mod tests {

// Corrupted ciphertext, decryption should fail.
let mut ciphertext = Storage::encrypt_bivariate_polynomial(&polynomial, churp_id, round);
ciphertext[0] += 1;
ciphertext[0] = ciphertext[0].saturating_add(1);
Storage::decrypt_bivariate_polynomial::<p384::Scalar>(&mut ciphertext, churp_id, round)
.expect_err("decryption of bivariate polynomial should fail");
}
Expand Down

0 comments on commit 4f7767c

Please sign in to comment.