-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
276 additions
and
565 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
/.vscode | ||
Cargo.lock | ||
**/.#* | ||
**/#*# | ||
**/#*# | ||
**/*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,26 @@ | ||
fn main() { | ||
#[cfg(feature = "serialization")] | ||
{ | ||
use base64::{ | ||
alphabet::STANDARD, | ||
engine::{GeneralPurpose, GeneralPurposeConfig}, | ||
Engine, | ||
}; | ||
use cosmian_cover_crypt::{Covercrypt, EncryptedHeader, UserSecretKey}; | ||
use cosmian_crypto_core::bytes_ser_de::Serializable; | ||
const USK: &str = "sUBriVEsM8HowAKOsIs9Y5p+Xa8JwJf84rlBHXzfkg+BJ6PzK79cT37Wsku5pMVKrfi/eIWhufC2pjYNMBOUAgMAH+waKc6AuwtAaYXXUAJA0K/uc5A22nXEShVXykjZ8QIBuNMsBrpSQaW0hAZ0AFvJTlwSM2BgI8m5k4wj3kQQ9NaP4cK6VvwyFlx7ZwwMZkJoCSgfiPvN4XqeWmiw/hehgjU2HkgYDQJf9QABaUoa74qM42SBnNubVVVnPvO5zrZ++NgoIHt4VPJfsMu157i6bakhOEWJy/CduXYGqedOGsNpj+gq0VsanjqeJ9gZ6sKjCknGoTxbEipIrPUO5jqJLzmJilS0ycAhR1mYlGU9yApPithxeIMaQFA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2anWhljNX2f2a/+hOjMbzqG+zaAtgpppylkvG/WlR1xLohGlLKdAWYRETIrI0oKi8RKFNHdnuPCZRDHlHDjhc273rPvsn7FlolSSTxbjvyTacB7jNwKfxW32eEK82p04GQyVN5uEBQBZUG4heNnoba54ybeU66PbOOclgE+LoblnvE0lqv8VxbCvbM3VVxTJ0rMj8ZshcxEWDv1v8E1JkGeq3QcDK/Ww1wBDuwLhxY8xbKmD40bmS8nGkRTLDuyhtg009oboT4+SL83Dz5WXEBcwO2m8Noor0QgtMjuyCAR92gvNSvewk03Q6X80W5Rd+tvw6HMwnoevpKge56akgXnQPnx76h78jIrEZ8FDZ7g6dlqPf7Lr9PnWQKhVHZwh1CBN0Rbb0ylumpvkiSCV7kF1tqPE89LO31jmYdULuQmMclKRst+SdXWSM7t2J/CeFmTgSiJ896P95imsC3XcWvmJqk+qlBNynP/Azmn775H59UHj21t8z2sFYwYkDfDRyBSxVLW/08nz+9vVy05qmrUqej/Iv4sHHjE3cgLCD+rjPOHssoFdr4ubG441N+1HpvoxFbo0Yk/fNH9JzqQj09eA4Wx6t3fjOWYJ8CESyK7lKBANYrQ5IdYuY3tk/Z3uR/uYff2pKu6xuisLF66FVC80WokFlvCEoYLLJs/q2/16mMo7cqkbhI0SLJgaAK8wIvJUS64Xxb3+SVVPYkeVFywrAb89J0kg6txXIuOfHxGcDZu7QaEPQUos7pwnbZBeXb/Q1RHbEE6cXr1pGB6wU+0gABNzLLTRNHuu2qm33myLkNQRilOyR7EqrDmLwY3ysGE5tmxYH5+zEu7nR/rkozqwpueGmrDMibRRw14kLRCNh6YkqvKsbSg1Tg0EKZe2eLGG0mmgj5jcYqusRcVtAA=="; | ||
fn main() { | ||
use base64::{ | ||
alphabet::STANDARD, | ||
engine::{GeneralPurpose, GeneralPurposeConfig}, | ||
Engine, | ||
}; | ||
use cosmian_cover_crypt::{Covercrypt, EncryptedHeader, UserSecretKey}; | ||
use cosmian_crypto_core::bytes_ser_de::Serializable; | ||
|
||
let config: GeneralPurposeConfig = GeneralPurposeConfig::default(); | ||
let transcoder: GeneralPurpose = GeneralPurpose::new(&STANDARD, config); | ||
let config: GeneralPurposeConfig = GeneralPurposeConfig::default(); | ||
let transcoder: GeneralPurpose = GeneralPurpose::new(&STANDARD, config); | ||
|
||
let cc = Covercrypt::default(); | ||
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 { | ||
encrypted_header | ||
.decrypt(&cc, &usk, None) | ||
.expect("cannot decrypt hybrid header"); | ||
} | ||
let cc = Covercrypt::default(); | ||
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 { | ||
encrypted_header | ||
.decrypt(&cc, &usk, None) | ||
.expect("cannot decrypt hybrid header"); | ||
} | ||
#[cfg(not(feature = "serialization"))] | ||
println!("Use the `serialization` feature to run this example") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,64 @@ | ||
fn main() { | ||
// create policy | ||
#[cfg(all(feature = "serialization", feature = "test_utils"))] | ||
use cosmian_cover_crypt::{ | ||
abe_policy::{AccessPolicy, Policy}, | ||
test_utils::policy, | ||
Covercrypt, EncryptedHeader, MasterPublicKey, MasterSecretKey, | ||
}; | ||
|
||
/// Generates a new USK and encrypted header and prints them. | ||
fn generate_new( | ||
cc: &Covercrypt, | ||
policy: &Policy, | ||
_msk: &mut MasterSecretKey, | ||
mpk: &MasterPublicKey, | ||
) { | ||
let access_policy = | ||
AccessPolicy::parse("Department::FIN && Security Level::Top Secret").unwrap(); | ||
|
||
let (_, _header) = EncryptedHeader::generate(cc, policy, mpk, &access_policy, None, None) | ||
.expect("cannot encrypt header"); | ||
|
||
#[cfg(feature = "serialization")] | ||
{ | ||
use base64::{ | ||
alphabet::STANDARD, | ||
engine::{GeneralPurpose, GeneralPurposeConfig}, | ||
Engine, | ||
}; | ||
use cosmian_cover_crypt::{ | ||
abe_policy::{AccessPolicy, Policy}, | ||
test_utils::policy, | ||
Covercrypt, EncryptedHeader, MasterPublicKey, MasterSecretKey, | ||
}; | ||
use cosmian_crypto_core::bytes_ser_de::Serializable; | ||
|
||
fn generate_new( | ||
cc: &Covercrypt, | ||
policy: &Policy, | ||
_msk: &MasterSecretKey, | ||
mpk: &MasterPublicKey, | ||
) { | ||
let access_policy = AccessPolicy::from_boolean_expression( | ||
"Department::FIN && Security Level::Top Secret", | ||
let config: GeneralPurposeConfig = GeneralPurposeConfig::default(); | ||
let transcoder: GeneralPurpose = GeneralPurpose::new(&STANDARD, config); | ||
println!( | ||
"USK = {}", | ||
transcoder.encode( | ||
cc.generate_user_secret_key(&mut _msk, &access_policy, policy) | ||
.unwrap() | ||
.serialize() | ||
.unwrap() | ||
) | ||
.unwrap(); | ||
|
||
let (_, _header) = | ||
EncryptedHeader::generate(cc, policy, mpk, &access_policy, None, None) | ||
.expect("cannot encrypt header"); | ||
|
||
#[cfg(feature = "serialization")] | ||
{ | ||
let config: GeneralPurposeConfig = GeneralPurposeConfig::default(); | ||
let transcoder: GeneralPurpose = GeneralPurpose::new(&STANDARD, config); | ||
|
||
println!( | ||
"usk = {}", | ||
transcoder.encode( | ||
cc.generate_user_secret_key(_msk, &access_policy, policy) | ||
.unwrap() | ||
.serialize() | ||
.unwrap() | ||
) | ||
); | ||
println!( | ||
"header = {}", | ||
transcoder.encode(_header.serialize().unwrap()) | ||
); | ||
} | ||
} | ||
|
||
let policy = policy().expect("cannot generate policy"); | ||
); | ||
println!( | ||
"header = {}", | ||
transcoder.encode(_header.serialize().unwrap()) | ||
); | ||
} | ||
} | ||
|
||
let cc = Covercrypt::default(); | ||
let (_msk, mpk) = cc | ||
.generate_master_keys(&policy) | ||
.expect("cannot generate master keys"); | ||
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"); | ||
|
||
// Encryption of a hybridized ciphertext | ||
let access_policy = | ||
AccessPolicy::from_boolean_expression("Department::FIN && Security Level::Top Secret") | ||
.unwrap(); | ||
let cc = Covercrypt::default(); | ||
let (mut msk, _) = cc.setup().expect("cannot generate master keys"); | ||
let mpk = cc | ||
.update_master_keys(&policy, &mut msk) | ||
.expect("cannot update master keys"); | ||
|
||
// | ||
// Use the following to update `examples/decrypt.rs` constants. | ||
// | ||
generate_new(&cc, &policy, &_msk, &mpk); | ||
generate_new(&cc, &policy, &mut msk, &mpk); | ||
|
||
// encrypt header, use loop to add weight in the flamegraph on it | ||
for _ in 0..1000 { | ||
let _encrypted_header = | ||
EncryptedHeader::generate(&cc, &policy, &mpk, &access_policy, None, None) | ||
.expect("cannot encrypt header"); | ||
} | ||
// Encrypt header, use loop to increase its wight in the flame graph. | ||
for _ in 0..1000 { | ||
EncryptedHeader::generate(&cc, &policy, &mpk, &ap, None, None) | ||
.expect("cannot encrypt header"); | ||
} | ||
|
||
#[cfg(not(all(feature = "test_utils", feature = "serialization")))] | ||
println!("Use the `serialization` feature to run this example") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.