Skip to content

Commit

Permalink
Merge pull request #134 from Cosmian/refresh_encaps
Browse files Browse the repository at this point in the history
Refactoring of CoverCrypt API
  • Loading branch information
Adamk93 authored May 6, 2024
2 parents 692de32 + 62f11dd commit 0f00011
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 173 deletions.
11 changes: 7 additions & 4 deletions examples/decrypt.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
const USK: &str = "sUBriVEsM8HowAKOsIs9Y5p+Xa8JwJf84rlBHXzfkg+BJ6PzK79cT37Wsku5pMVKrfi/eIWhufC2pjYNMBOUAgMAH+waKc6AuwtAaYXXUAJA0K/uc5A22nXEShVXykjZ8QIBuNMsBrpSQaW0hAZ0AFvJTlwSM2BgI8m5k4wj3kQQ9NaP4cK6VvwyFlx7ZwwMZkJoCSgfiPvN4XqeWmiw/hehgjU2HkgYDQJf9QABaUoa74qM42SBnNubVVVnPvO5zrZ++NgoIHt4VPJfsMu157i6bakhOEWJy/CduXYGqedOGsNpj+gq0VsanjqeJ9gZ6sKjCknGoTxbEipIrPUO5jqJLzmJilS0ycAhR1mYlGU9yApPithxeIMaQFAAegOUTVFDFausKPbDZ1IYEWyftONyaaelMyJF4eCQIWILEihLuoscwGkVlYmRttcNVrLDW3yHN/cFQgiBSNVOi/RTLSpdsaMtattwDcaEiRUvCxe2gfaCYQV9zPIsdfAG2TIf2MPLcqUu0EBnIohX/TKyOTavt7HB76d/pCWT7sceu/YldifCYUoWABA8GbnF6DurlVwhfYUKhThnchbP3mgsEUsy+vQlWIwvrwxgpgqaabNSwJIUCXttY6kYNjJbL5pkahaAnxYLRMcvvKfGtzwlX7ewINAFrMSUBua8abWzgIa2NWlt2/ON7tKrVIaqRMYs8KFJSSsQ4bGEhZfBjWEYacAho8bFMuqamQgxaJhyj/J+tZrA24A5ckmPSPeGOIKealWkQmy8f0oAPVsOGaQFcBwLMPe4qRl49tpM6kRgpsyOkeQYOdpQ7Rue0xMKR+UhdPJkzYcGoVlAIGRmv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1+O43hcoW7PgxGk7Pt1CUAJ+gI15rAmRo/s7dFdI+TLGGHhnQFXiQO+1fsWydjjR/AV1grEj56NZNKwkH6FbThRI95D2y1V33+Tdg3nu6jbZB6MN1SMnBCURJoPRN5YB5Ed263j7v+XcsLKoXf14QNYuTCPqyigEoWEsd+yyjt2yWTjZtyte+FRdgauG+12GBrXzR6UnuaXWtl7Dl0GPmtFUALnIbUnLwQx5fBwpKluOMTpcrDHUJGupnZCdXuKJD8aF0fqzZjKkkpGMRm7yG32PeqFOzx9gKPnHUT7EOEKXMPK/NIFSXpez9GbDRkzeCXrweMiShzFBb2kGC/CIbFRJJ5wA=";

fn main() {
use base64::{
alphabet::STANDARD,
engine::{GeneralPurpose, GeneralPurposeConfig},
Engine,
};
use cosmian_cover_crypt::{Covercrypt, EncryptedHeader, UserSecretKey};
use cosmian_cover_crypt::api::Covercrypt;
use cosmian_cover_crypt::core::UserSecretKey;
use cosmian_crypto_core::bytes_ser_de::Serializable;

let config: GeneralPurposeConfig = GeneralPurposeConfig::default();
Expand All @@ -18,7 +21,7 @@ fn main() {
let usk = UserSecretKey::deserialize(&transcoder.decode(USK.as_bytes()).unwrap()).unwrap();
let encrypted_header =
EncryptedHeader::deserialize(&transcoder.decode(HEADER.as_bytes()).unwrap()).unwrap();
for _ in 0..1000 {
for _ in 0..100 {
encrypted_header
.decrypt(&cc, &usk, None)
.expect("cannot decrypt hybrid header");
Expand Down
8 changes: 4 additions & 4 deletions examples/encrypt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use cosmian_cover_crypt::{
abe_policy::{AccessPolicy, Policy},
api::{Covercrypt, EncryptedHeader},
test_utils::policy,
Covercrypt, EncryptedHeader, MasterPublicKey, MasterSecretKey,
MasterPublicKey, MasterSecretKey,
};

/// Generates a new USK and encrypted header and prints them.
Expand Down Expand Up @@ -46,8 +47,7 @@ fn generate_new(

fn main() {
let policy = policy().expect("cannot generate policy");
let ap = AccessPolicy::parse("Department::FIN && Security Level::Top Secret")
.expect("cannot parse given access policy");
let ap = AccessPolicy::parse("Department::FIN && Security Level::Top Secret").unwrap();

let cc = Covercrypt::default();
let (mut msk, _) = cc.setup().expect("cannot generate master keys");
Expand All @@ -58,7 +58,7 @@ fn main() {
generate_new(&cc, &policy, &mut msk, &mpk);

// Encrypt header, use loop to increase its wight in the flame graph.
for _ in 0..1000 {
for _ in 0..100 {
EncryptedHeader::generate(&cc, &policy, &mpk, &ap, None, None)
.expect("cannot encrypt header");
}
Expand Down
39 changes: 27 additions & 12 deletions examples/runme.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This is the demo given in `README.md` and `lib.rs`

use cosmian_cover_crypt::{
abe_policy::{AccessPolicy, Attribute, DimensionBuilder, EncryptionHint, Policy},
Covercrypt, EncryptedHeader,
abe_policy::{AccessPolicy, DimensionBuilder, EncryptionHint, Policy},
api::{Covercrypt, EncryptedHeader},
};

fn main() {
Expand Down Expand Up @@ -54,36 +54,51 @@ fn main() {
.unwrap();

// Encrypt
let (_, encrypted_header) =
EncryptedHeader::generate(&cover_crypt, &policy, &mpk, &access_policy, None, None).unwrap();
let (_, encrypted_header) = EncryptedHeader::generate(
&cover_crypt,
&policy,
&mpk,
&access_policy.clone(),
None,
None,
)
.unwrap();

// The user is able to decrypt the encrypted header.
assert!(encrypted_header.decrypt(&cover_crypt, &usk, None).is_ok());
assert!(encrypted_header
.decrypt(&cover_crypt, &usk, None)
.unwrap()
.is_some());

//
// Rekey all keys using the `Security Level::Top Secret` attribute
let rekey_access_policy = AccessPolicy::Attr(Attribute::from(("Security Level", "Top Secret")));
// Rekey the user access policy.
let mpk = cover_crypt
.rekey(&rekey_access_policy, &policy, &mut msk)
.rekey(&access_policy, &policy, &mut msk)
.unwrap();

let enc_policy = AccessPolicy::parse("Security Level::Top Secret").unwrap();
// Encrypt with rotated attribute
let (_, new_encrypted_header) =
EncryptedHeader::generate(&cover_crypt, &policy, &mpk, &access_policy, None, None).unwrap();
EncryptedHeader::generate(&cover_crypt, &policy, &mpk, &enc_policy, None, None).unwrap();

// user cannot decrypt the newly encrypted header
assert!(new_encrypted_header
.decrypt(&cover_crypt, &usk, None)
.is_err());
.unwrap()
.is_none());

// refresh user secret key, do not grant old encryption access
cover_crypt.refresh_usk(&mut usk, &mut msk, false).unwrap();

// The user with refreshed key is able to decrypt the newly encrypted header.
assert!(new_encrypted_header
.decrypt(&cover_crypt, &usk, None)
.is_ok());
.unwrap()
.is_some());

// But it cannot decrypt old ciphertexts
assert!(encrypted_header.decrypt(&cover_crypt, &usk, None).is_err());
assert!(encrypted_header
.decrypt(&cover_crypt, &usk, None)
.unwrap()
.is_none());
}
12 changes: 6 additions & 6 deletions src/abe_policy/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Policy {
/// Adds the given dimension to the policy.
/// /!\ Invalidates all previous keys and ciphers.
pub fn add_dimension(&mut self, dim: DimensionBuilder) -> Result<(), Error> {
if self.dimensions.get(&dim.name).is_some() {
if self.dimensions.contains_key(&dim.name) {
return Err(Error::ExistingPolicy(dim.name));
}

Expand Down Expand Up @@ -184,7 +184,7 @@ impl Policy {
/// Returns an error if the access policy is invalid.
pub fn generate_semantic_space_coordinates(
&self,
ap: AccessPolicy,
ap: &AccessPolicy,
) -> Result<HashSet<Coordinate>, Error> {
let dnf = ap.to_dnf();
let mut coordinates = HashSet::new();
Expand Down Expand Up @@ -216,7 +216,7 @@ impl Policy {
/// Returns an error if the access policy is invalid.
pub fn generate_point_coordinates(
&self,
ap: AccessPolicy,
ap: &AccessPolicy,
) -> Result<HashSet<Coordinate>, Error> {
let dnf = ap.to_dnf();
let mut coordinates = HashSet::with_capacity(dnf.len());
Expand Down Expand Up @@ -318,7 +318,7 @@ mod tests {
let ap = "(Department::HR || Department::FIN) && Security Level::Low Secret";

let semantic_space_coordinates =
policy.generate_semantic_space_coordinates(AccessPolicy::parse(ap)?)?;
policy.generate_semantic_space_coordinates(&AccessPolicy::parse(ap)?)?;

// Check the number of coordinates is correct.
assert_eq!(semantic_space_coordinates.len(), (2 + 1) * (2 + 1));
Expand Down Expand Up @@ -415,7 +415,7 @@ mod tests {

assert_eq!(
policy
.generate_semantic_space_coordinates(AccessPolicy::parse(ap)?)?
.generate_semantic_space_coordinates(&AccessPolicy::parse(ap)?)?
.len(),
// remove (2 + 1) not to count "Security Level::Protected" -> "Security Level::Low Secret" twice
2 * (1 + 1) * (2 + 1) - (2 + 1)
Expand All @@ -425,7 +425,7 @@ mod tests {
|| (Department::MKG && Security Level::Medium Secret)";
assert_eq!(
policy
.generate_semantic_space_coordinates(AccessPolicy::parse(ap)?)?
.generate_semantic_space_coordinates(&AccessPolicy::parse(ap)?)?
.len(),
// remove (2 + 1) not to count "Security Level::Protected" -> "Security Level::Low Secret" twice
(1 + 1) * (2 + 1) + (1 + 1) * (3 + 1) - (2 + 1)
Expand Down
Loading

0 comments on commit 0f00011

Please sign in to comment.