Skip to content

Commit

Permalink
use Kyber CCA
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrezot committed May 23, 2024
1 parent 3d292c6 commit 166aa7e
Show file tree
Hide file tree
Showing 15 changed files with 535 additions and 619 deletions.
4 changes: 2 additions & 2 deletions examples/decrypt.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cosmian_cover_crypt::core::EncryptedHeader;

const USK: &str = "AubJg6rkTo7EjT2A7jswv5tq2uR5kZflMxbqogOl+WYNWUDwr8yvmgGSe7D6kHLYHHjW78VWtfV3kjRUrT3gRAsMAAEAnzQygadC4nJKHl4nP9VkHqU/62dVM4NVCkNlmFSBMgMCAQkBAPRl3kM+kOijMKDR0OjOWq2h0N+MhQzdi/uRUwKTi08HAgMJAQCbcxAJ960xi+CDtCeg/l7uux1a/DFzPUOFk94Apdt4CwIECQEAdt+vYI9Hga7eEgBhLTi97eDgp7NGCZV0JTrvKdxJlAMCBQkBAU2GnUJtqBUZ6rRtbdP6gvC5KmOjgMKk1V8p14iiL18E8lwJjdmrcweORogGSlVUZ4OW9IM+IzRJaLqfz0VMGsItYRpkLHQVmslsJxrMs0mzFWt0nsfD6bRzhlFSyWdByEOr1nCJnhClpJWAhAZSUxJe4vOlWlNJOKQDAWKA/4K6vsxRfBachXQ/9GeXbxAValix03xgLdwpszZPM/SshSKgxVIGvojFmNEU5KERtXEw9RVxXWImMVRCuMoMy4MIaRw9tSkczirJSOl9F9WT8jK8OfGSiDdbY9UFmrRijMUIw2QLeWquYtUHyCo3qwd+aTy/yFhgbhEd4vqKttk8XUIAjSuyNSGiJ7tDsNBwJjopdeOdWslOk5pccaYWSfuGo4UHomg1MvA+G5Oc0kqOzegtIAk1DdRGv1tEG1RW8YSGD7WdIyDBo0IAlhBAdRwEjwMmvrg7S5FwFlyVtoKTd9F8AFK3TKep0iO8RwJ9tXci5isYdGlCd6wasDAdEPS87PZYXWxXuLSGuMyZanE6dCJsDkRhBYh/BgWwSbOkFRQlLzyW4YRml/k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ay3705nTjnqbwhxsnYczWpSWtey/1VmPmUxWFxUXfya73Rc242ZbSZzmD2GLAeAHY7QYhQJZzbV6/iC+f+c8hqbE0F1K1xG8UMoA/sXPnfHHZfEMSEcTpR5x6tX4UdB3kfGDM9L0cVkX6b2uvt20C3LHCvVQYn/Fi7iSzRS64tRIqHnk88Sj+9b0/uFigpTh6fjcgRfLr1Ys58qhl/BoBx4JyvGpDKcjGHVBnHcXAY+RguQHUTabqdOBXSKK49ZzSRlTSPdKjYOSqTAY5kfjwYzwMh9HiFdnyV3mXYYukDUjB/3XQO6JPgYsF8oVsnEuzKX6kGw/FN0apflTfQcVOx9wgxge3A10fAA==";

fn main() {
use base64::{
Expand Down
1 change: 0 additions & 1 deletion src/abe_policy/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ impl Policy {
/// - D1::A1 && D2::B2
/// - D2::A2
/// - D2::B2
#[allow(dead_code)]
pub fn combine(
dimensions: &[(&String, &Dimension)], // TODO: signature depends on the HashMap iterator type
) -> Vec<(Vec<u32>, EncryptionHint, AttributeStatus)> {
Expand Down
13 changes: 9 additions & 4 deletions src/core/ae.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,42 @@ use cosmian_crypto_core::{
reexport::rand_core::CryptoRngCore, Aes256Gcm, Dem, FixedSizeCBytes, Instantiable, Nonce,
RandomFixedSizeCBytes, SymmetricKey,
};
use zeroize::Zeroizing;

use crate::Error;

/// Authenticated Encryption trait
pub trait AE<const KEY_LENGTH: usize> {
/// Encrypts the given plaintext `ptx` using the given `key`.
fn encrypt(
rng: &mut impl CryptoRngCore,
key: &SymmetricKey<KEY_LENGTH>,
ptx: &[u8],
rng: &mut impl CryptoRngCore,
) -> Result<Vec<u8>, Error>;

/// Decrypts the given ciphertext `ctx` using the given `key`.
///
/// # Error
///
/// Returns an error if the integrity of the ciphertext could not be verified.
fn decrypt(key: &SymmetricKey<KEY_LENGTH>, ctx: &[u8]) -> Result<Vec<u8>, Error>;
fn decrypt(key: &SymmetricKey<KEY_LENGTH>, ctx: &[u8]) -> Result<Zeroizing<Vec<u8>>, Error>;
}

impl AE<{ Self::KEY_LENGTH }> for Aes256Gcm {
fn encrypt(
rng: &mut impl CryptoRngCore,
key: &SymmetricKey<{ Self::KEY_LENGTH }>,
ptx: &[u8],
rng: &mut impl CryptoRngCore,
) -> Result<Vec<u8>, Error> {
let nonce = Nonce::<{ Self::NONCE_LENGTH }>::new(&mut *rng);
let ciphertext = Self::new(key).encrypt(&nonce, ptx, None)?;
Ok([nonce.as_bytes(), &ciphertext].concat())
}

fn decrypt(key: &SymmetricKey<{ Self::KEY_LENGTH }>, ctx: &[u8]) -> Result<Vec<u8>, Error> {
fn decrypt(
key: &SymmetricKey<{ Self::KEY_LENGTH }>,
ctx: &[u8],
) -> Result<Zeroizing<Vec<u8>>, Error> {
if ctx.len() < Self::NONCE_LENGTH {
return Err(Error::CryptoCoreError(
cosmian_crypto_core::CryptoCoreError::DecryptionError,
Expand All @@ -43,5 +47,6 @@ impl AE<{ Self::KEY_LENGTH }> for Aes256Gcm {
Self::new(key)
.decrypt(&nonce, &ctx[Self::NONCE_LENGTH..], None)
.map_err(Error::CryptoCoreError)
.map(Zeroizing::new)
}
}
18 changes: 9 additions & 9 deletions src/core/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use std::{
};

use cosmian_crypto_core::{kdf256, reexport::rand_core::SeedableRng, CsRng, Secret, SymmetricKey};
use zeroize::Zeroizing;

use super::{
ae::AE,
primitives::{mpk_keygen, prune, update_coordinate_keys, usk_keygen},
primitives::{prune, update_coordinate_keys, usk_keygen},
MIN_TRACING_LEVEL,
};
use crate::{
Expand Down Expand Up @@ -67,7 +68,7 @@ impl Covercrypt {
(EncryptionHint::Classic, AttributeStatus::EncryptDecrypt),
)]),
)?;
let mpk = mpk_keygen(&msk)?;
let mpk = msk.mpk()?;

Ok((msk, mpk))
}
Expand All @@ -92,8 +93,7 @@ impl Covercrypt {
msk,
policy.generate_universal_coordinates()?,
)?;
let mpk = mpk_keygen(msk)?;
Ok(mpk)
msk.mpk()
}

/// Generates new keys for each coordinate in the semantic space of the
Expand All @@ -112,7 +112,7 @@ impl Covercrypt {
msk,
policy.generate_semantic_space_coordinates(ap)?,
)?;
mpk_keygen(msk)
msk.mpk()
}

/// Removes all but the latest secret of each coordinate in the semantic
Expand All @@ -130,7 +130,7 @@ impl Covercrypt {
msk,
&policy.generate_semantic_space_coordinates(access_policy)?,
);
mpk_keygen(msk)
msk.mpk()
}

/// Generates a USK associated to the given access policy.
Expand Down Expand Up @@ -255,7 +255,7 @@ pub trait CovercryptPKE<Aead, const KEY_LENGTH: usize> {
usk: &UserSecretKey,
ciphertext: &[u8],
enc: &Encapsulation,
) -> Result<Option<Vec<u8>>, Error>;
) -> Result<Option<Zeroizing<Vec<u8>>>, Error>;
}

impl<const KEY_LENGTH: usize, E: AE<KEY_LENGTH>> CovercryptPKE<E, KEY_LENGTH> for Covercrypt {
Expand All @@ -276,7 +276,7 @@ impl<const KEY_LENGTH: usize, E: AE<KEY_LENGTH>> CovercryptPKE<E, KEY_LENGTH> fo
let mut sym_key = SymmetricKey::default();
kdf256!(&mut sym_key, &seed);
let mut rng = self.rng.lock().expect("poisoned lock");
let res = E::encrypt(&sym_key, plaintext, &mut *rng)?;
let res = E::encrypt(&mut *rng, &sym_key, plaintext)?;
Ok((enc, res))
}

Expand All @@ -285,7 +285,7 @@ impl<const KEY_LENGTH: usize, E: AE<KEY_LENGTH>> CovercryptPKE<E, KEY_LENGTH> fo
usk: &UserSecretKey,
ciphertext: &[u8],
enc: &Encapsulation,
) -> Result<Option<Vec<u8>>, Error> {
) -> Result<Option<Zeroizing<Vec<u8>>>, Error> {
if SEED_LENGTH < KEY_LENGTH {
return Err(Error::ConversionFailed(format!(
"insufficient entropy to generate a {}-byte key from a {}-byte seed",
Expand Down
Loading

0 comments on commit 166aa7e

Please sign in to comment.