Skip to content

Commit

Permalink
fix: cleanup remaining mention of Curve25519 in primitives.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrezot committed Jan 26, 2024
1 parent 84b1eed commit 70f8a14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "13.1.0"
authors = [
"Théophile Brezot <[email protected]>",
"Bruno Grieder <[email protected]>",
"Hugo Rosenkranz-Costa <[email protected]>",
]
documentation = "https://docs.rs/cosmian_cover_crypt/"
edition = "2021"
Expand All @@ -14,6 +15,7 @@ description = "Key Policy attribute encryption based on subset cover"
[lib]
crate-type = ["lib", "cdylib", "staticlib"]
name = "cosmian_cover_crypt"

# The cdylib is only interesting if the `--features ffi` flag is set on build
# This does not seem to be actionable conditionally https://github.com/rust-lang/cargo/issues/4881

Expand Down
27 changes: 18 additions & 9 deletions src/core/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ use std::{
};

use cosmian_crypto_core::{
reexport::rand_core::CryptoRngCore, FixedSizeCBytes, R25519PrivateKey, R25519PublicKey,
RandomFixedSizeCBytes, Secret, SymmetricKey,
reexport::rand_core::CryptoRngCore, FixedSizeCBytes, RandomFixedSizeCBytes, Secret,
SymmetricKey,
};
use tiny_keccak::{Hasher, IntoXof, Kmac, Xof};
use zeroize::Zeroize;

use super::{
pke, CoordinateKeypair, CoordinatePublicKey, CoordinateSecretKey, KmacSignature,
TracingSecretKey, KMAC_KEY_LENGTH, KMAC_SIG_LENGTH, MIN_TRACING_LEVEL, SEED_LENGTH, TAG_LENGTH,
pke::{self, elgamal},
CoordinateKeypair, CoordinatePublicKey, CoordinateSecretKey, KmacSignature, TracingSecretKey,
KMAC_KEY_LENGTH, KMAC_SIG_LENGTH, MIN_TRACING_LEVEL, SEED_LENGTH, TAG_LENGTH,
};
use crate::{
abe_policy::{AttributeStatus, Coordinate, EncryptionHint},
Expand Down Expand Up @@ -78,20 +79,28 @@ pub fn setup(rng: &mut impl CryptoRngCore, tracing_level: usize) -> Result<Maste
"tracing level cannot be lower than {MIN_TRACING_LEVEL}"
)));
}
let s = R25519PrivateKey::new(rng);
let s = elgamal::Scalar::new(rng);

let mut tsk = TracingSecretKey::default();
(0..tracing_level).for_each(|_| tsk.increase_tracing(rng));

let mut coordinate_keypairs = RevisionMap::new();
coordinate_keypairs.insert(
Coordinate::from_attribute_ids(vec![])?,
CoordinateKeypair::random(rng, &elgamal::EcPoint::from(&s), false),
);

Ok(MasterSecretKey {
s,
tsk,
coordinate_keypairs: RevisionMap::new(),
coordinate_keypairs,
signing_key: Some(SymmetricKey::<KMAC_KEY_LENGTH>::new(rng)),
})
}

/// Generates a new MPK holding the latest public information of each universal coordinate.
pub fn mpk_keygen(msk: &MasterSecretKey) -> Result<MasterPublicKey, Error> {
let h = R25519PublicKey::from(&msk.s);
let h = elgamal::EcPoint::from(&msk.s);
let tpk = msk.tsk.tpk();
let coordinate_keys = msk.get_latest_coordinate_pk().collect();
Ok(MasterPublicKey {
Expand Down Expand Up @@ -141,7 +150,7 @@ pub fn encaps(
mpk: &MasterPublicKey,
encryption_set: &HashSet<Coordinate>,
) -> Result<(SymmetricKey<SEED_LENGTH>, Encapsulation), Error> {
let ephemeral_sk = R25519PrivateKey::new(rng);
let ephemeral_sk = elgamal::Scalar::new(rng);
let seed = Secret::<SEED_LENGTH>::random(rng);
let mut coordinate_encapsulations = HashSet::with_capacity(encryption_set.len());
for coordinate in encryption_set {
Expand Down Expand Up @@ -198,7 +207,7 @@ pub fn decaps(
.iter()
.zip(encapsulation.traps.iter())
.map(|(marker, trap)| trap * marker)
.fold(R25519PublicKey::identity(), |mut acc, elt| {
.fold(elgamal::EcPoint::identity(), |mut acc, elt| {
acc = &acc + &elt;
acc
});
Expand Down

0 comments on commit 70f8a14

Please sign in to comment.