From 6e0a376e4c564220da8f111f8af07b7e9177a91a Mon Sep 17 00:00:00 2001 From: Manuthor Date: Mon, 18 Sep 2023 17:59:25 +0200 Subject: [PATCH] feat: support crypto_core 9.2.0 --- CHANGELOG.md | 6 ++++++ Cargo.toml | 4 ++-- benches/benches.rs | 12 ++++++------ src/abe_policy/access_policy.rs | 2 +- src/abe_policy/policy.rs | 2 +- src/abe_policy/tests.rs | 8 ++++---- src/core/api.rs | 4 ++-- src/core/primitives.rs | 4 ++-- src/core/serialization.rs | 8 ++++---- src/lib.rs | 2 +- 10 files changed, 29 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 824eff39..17230e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## [12.0.3] - 2023-09-18 + +### Features + +- Support `crypto_core` v9.2.0 + ## [12.0.2] - 2023-09-01 ### Features diff --git a/Cargo.toml b/Cargo.toml index 5e7ef092..9a3d10a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cosmian_cover_crypt" -version = "12.0.2" +version = "12.0.3" authors = [ "Théophile Brezot ", "Bruno Grieder ", @@ -29,7 +29,7 @@ hybridized_bench = [] [dependencies] base64 = { version = "0.21.0", optional = true } -cosmian_crypto_core = { version = "9.1.0", default-features = false, features = ["ser", "sha3", "aes", "curve25519"] } +cosmian_crypto_core = { version = "9.2.0", default-features = false, features = ["ser", "sha3", "aes", "curve25519"] } pqc_kyber = { version = "0.4", features = ["std", "hazmat"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/benches/benches.rs b/benches/benches.rs index 60e5075b..acf0b5ce 100644 --- a/benches/benches.rs +++ b/benches/benches.rs @@ -199,17 +199,17 @@ fn bench_serialization(c: &mut Criterion) { let mut group = c.benchmark_group("Key serialization"); group.bench_function("MSK", |b| { - b.iter(|| msk.serialize().expect("cannot serialize msk")) + b.iter(|| msk.serialize().expect("cannot serialize msk")); }); group.bench_function("MPK", |b| { - b.iter(|| mpk.serialize().expect("cannot serialize mpk")) + b.iter(|| mpk.serialize().expect("cannot serialize mpk")); }); let usk = cover_crypt .generate_user_secret_key(&msk, &user_access_policies[0], &policy) .unwrap(); group.bench_function("USK 1 partition", |b| { - b.iter(|| usk.serialize().expect("cannot serialize usk")) + b.iter(|| usk.serialize().expect("cannot serialize usk")); }); // removes borrow checker warning about several mutable reference on `c` @@ -228,7 +228,7 @@ fn bench_serialization(c: &mut Criterion) { n_partition + 1 ) }) - }) + }); }); } } @@ -258,7 +258,7 @@ fn bench_header_encryption(c: &mut Criterion) { .unwrap_or_else(|_| { panic!("cannot encrypt header for {} partition(s)", n_partition + 1) }) - }) + }); }, ); } @@ -317,7 +317,7 @@ fn bench_header_decryption(c: &mut Criterion) { n_partitions_usk ) }); - }) + }); }, ); } diff --git a/src/abe_policy/access_policy.rs b/src/abe_policy/access_policy.rs index 5124e27a..30297d35 100644 --- a/src/abe_policy/access_policy.rs +++ b/src/abe_policy/access_policy.rs @@ -383,7 +383,7 @@ impl AccessPolicy { let mut combined = Vec::with_capacity(value_left.len() + value_right.len()); combined.extend_from_slice(&value_left); combined.extend_from_slice(value_right); - res.push(combined) + res.push(combined); } } Ok(res) diff --git a/src/abe_policy/policy.rs b/src/abe_policy/policy.rs index 111ed92f..89140604 100644 --- a/src/abe_policy/policy.rs +++ b/src/abe_policy/policy.rs @@ -424,7 +424,7 @@ fn generate_current_attribute_partitions( policy: &Policy, ) -> Result, Error> { let mut current_attr_value_per_axis = HashMap::>::new(); - for attribute in attributes.iter() { + for attribute in attributes { let entry = current_attr_value_per_axis .entry(attribute.axis.clone()) .or_default(); diff --git a/src/abe_policy/tests.rs b/src/abe_policy/tests.rs index 8b8f6fab..62f19a3e 100644 --- a/src/abe_policy/tests.rs +++ b/src/abe_policy/tests.rs @@ -58,16 +58,16 @@ fn check_policy() { let attributes = policy.attributes(); assert_eq!(security_level.len() + department.len(), attributes.len()); for properties in &security_level.attributes_properties { - assert!(attributes.contains(&Attribute::new("Security Level", &properties.name))) + assert!(attributes.contains(&Attribute::new("Security Level", &properties.name))); } for properties in &department.attributes_properties { - assert!(attributes.contains(&Attribute::new("Department", &properties.name))) + assert!(attributes.contains(&Attribute::new("Department", &properties.name))); } for attribute in &attributes { assert_eq!( policy.attribute_values(attribute).unwrap()[0], policy.attribute_current_value(attribute).unwrap() - ) + ); } } @@ -84,7 +84,7 @@ fn test_rotate_policy_attributes() -> Result<(), Error> { assert_eq!( policy.attribute_values(attribute)?[0], policy.attribute_current_value(attribute)? - ) + ); } Ok(()) } diff --git a/src/core/api.rs b/src/core/api.rs index 1b261d2a..15a87581 100644 --- a/src/core/api.rs +++ b/src/core/api.rs @@ -1,6 +1,6 @@ //! Defines the `Covercrypt` API. -use std::{fmt::Debug, ops::DerefMut, sync::Mutex}; +use std::{fmt::Debug, sync::Mutex}; use cosmian_crypto_core::{ reexport::rand_core::SeedableRng, Aes256Gcm, CsRng, Dem, FixedSizeCBytes, Instantiable, Nonce, @@ -172,7 +172,7 @@ impl Covercrypt { ad: Option<&[u8]>, ) -> Result, Error> { let aes256gcm = Aes256Gcm::new(symmetric_key); - let nonce = Nonce::new(self.rng.lock().expect("could not lock mutex").deref_mut()); + let nonce = Nonce::new(&mut *self.rng.lock().expect("could not lock mutex")); let mut ciphertext = aes256gcm.encrypt(&nonce, plaintext, ad)?; let mut res = Vec::with_capacity(plaintext.len() + Aes256Gcm::MAC_LENGTH + Aes256Gcm::NONCE_LENGTH); diff --git a/src/core/primitives.rs b/src/core/primitives.rs index b12ff3f1..3f5b96b6 100644 --- a/src/core/primitives.rs +++ b/src/core/primitives.rs @@ -5,7 +5,7 @@ use std::collections::{HashMap, HashSet}; use cosmian_crypto_core::{ kdf256, reexport::rand_core::CryptoRngCore, FixedSizeCBytes, R25519PrivateKey, R25519PublicKey, - RandomFixedSizeCBytes, SymmetricKey, + SymmetricKey, }; use pqc_kyber::{ indcpa::{indcpa_dec, indcpa_enc, indcpa_keypair}, @@ -309,7 +309,7 @@ pub fn refresh( keep_old_rights: bool, ) { if !keep_old_rights { - usk.subkeys.drain(); + usk.subkeys.clear(); } for partition in decryption_set { diff --git a/src/core/serialization.rs b/src/core/serialization.rs index bbdfaafc..4d07ce0c 100644 --- a/src/core/serialization.rs +++ b/src/core/serialization.rs @@ -266,13 +266,13 @@ impl Serializable for EncryptedHeader { + to_leb128_len( self.encrypted_metadata .as_ref() - .map(|data| data.len()) + .map(std::vec::Vec::len) .unwrap_or_default(), ) + self .encrypted_metadata .as_ref() - .map(|data| data.len()) + .map(std::vec::Vec::len) .unwrap_or_default() } @@ -310,13 +310,13 @@ impl Serializable for CleartextHeader { + to_leb128_len( self.metadata .as_ref() - .map(|data| data.len()) + .map(std::vec::Vec::len) .unwrap_or_default(), ) + self .metadata .as_ref() - .map(|data| data.len()) + .map(std::vec::Vec::len) .unwrap_or_default() } diff --git a/src/lib.rs b/src/lib.rs index e2b0fc71..3fcc8a72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ //! decryption rights for the post-rotation ciphertexts. A post-rotation key //! cannot be granted decryption rights for the pre-rotation ciphertexts. //! -//! Covercryptencryption offers 128 bits of both pre- and post-quantum +//! Covercrypt encryption offers 128 bits of both pre- and post-quantum //! security. //! //! The `api` module exposes the generic definition of `Covercrypt`.