Skip to content

Commit

Permalink
remove tracer public key from the MSK
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrezot committed Dec 4, 2024
1 parent 382a6bd commit 4e0be2f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
16 changes: 8 additions & 8 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ impl UserId {
#[derive(Debug, PartialEq, Eq)]
struct TracingSecretKey {
s: Scalar,
tracers: LinkedList<(Scalar, EcPoint)>,
tracers: LinkedList<Scalar>,
users: HashSet<UserId>,
}

impl TracingSecretKey {
fn new_with_level(level: usize, rng: &mut impl CryptoRngCore) -> Result<Self, Error> {
let s = nike::Scalar::new(rng);
let tracers = (0..=level)
.map(|_| R25519::keygen(rng))
.map(|_| R25519::keygen(rng).map(|kp| kp.0))
.collect::<Result<_, _>>()?;
let users = HashSet::new();

Expand All @@ -194,12 +194,12 @@ impl TracingSecretKey {

/// Generates a new tracer. Returns the associated trap.
fn _increase_tracing(&mut self, rng: &mut impl CryptoRngCore) -> Result<(), Error> {
self.tracers.push_back(R25519::keygen(rng)?);
self.tracers.push_back(R25519::keygen(rng)?.0);
Ok(())
}

/// Drops the oldest tracer and returns it.
fn _decrease_tracing(&mut self) -> Result<(Scalar, EcPoint), Error> {
fn _decrease_tracing(&mut self) -> Result<Scalar, Error> {
if self.tracing_level() == MIN_TRACING_LEVEL {
Err(Error::OperationNotPermitted(format!(
"tracing level cannot be lower than {MIN_TRACING_LEVEL}"
Expand Down Expand Up @@ -250,7 +250,7 @@ impl TracingSecretKey {
/// Generates the associated tracing public key.
#[must_use]
fn tpk(&self) -> TracingPublicKey {
TracingPublicKey(self.tracers.iter().map(|(_, p)| p).cloned().collect())
TracingPublicKey(self.tracers.iter().map(|s| s.into()).collect())
}

/// Returns the binding points.
Expand All @@ -274,9 +274,9 @@ impl TracingSecretKey {
.tracers
.iter()
.zip(markers.iter())
.map(|((sk_i, _), a_i)| sk_i * a_i)
.map(|(sk_i, a_i)| sk_i * a_i)
.fold(Scalar::zero(), |acc, x_i| &acc + &x_i))
/ &last_tracer.0;
/ last_tracer;

markers.push_back(last_marker);
let id = UserId(markers);
Expand All @@ -293,7 +293,7 @@ impl TracingSecretKey {
== id
.iter()
.zip(self.tracers.iter())
.map(|(identifier, tracer)| identifier * &tracer.0)
.map(|(identifier, tracer)| identifier * tracer)
.sum()
}

Expand Down
22 changes: 14 additions & 8 deletions src/core/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,20 @@ pub fn full_decaps(
msk: &MasterSecretKey,
encapsulation: &XEnc,
) -> Result<(Secret<SHARED_SECRET_LENGTH>, HashSet<Right>), Error> {
let A;
if let Some(c) = encapsulation.c.first() {
A = c * &(&msk.tsk.s / &msk.tsk.tracers.front().unwrap().0);
} else {
return Err(Error::InvalidBooleanExpression(
"empty encapsulation dose not allow to go further".to_string(),
));
}
let A = {
let c_0 = encapsulation
.c
.first()
.ok_or_else(|| Error::Kem("invalid encapsulation: C is empty".to_string()))?;
let t_0 = msk
.tsk
.tracers
.front()
.ok_or_else(|| Error::KeyError("MSK has no tracer".to_string()))?;

c_0 * &(&msk.tsk.s / t_0)
};

let mut rights = HashSet::with_capacity(encapsulation.encapsulations.len());
let ss = Secret::new();
for enc in &encapsulation.encapsulations {
Expand Down
12 changes: 3 additions & 9 deletions src/core/serialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,15 @@ impl Serializable for TracingSecretKey {
+ to_leb128_len(self.users.len())
+ self.users.iter().map(Serializable::length).sum::<usize>()
+ to_leb128_len(self.tracers.len())
+ self
.tracers
.iter()
.map(|(sk, pk)| sk.length() + pk.length())
.sum::<usize>()
+ self.tracers.iter().map(|sk| sk.length()).sum::<usize>()
}

fn write(&self, ser: &mut Serializer) -> Result<usize, Self::Error> {
let mut n = self.s.write(ser)?;

n += ser.write_leb128_u64(self.tracers.len() as u64)?;
for (sk, pk) in &self.tracers {
for sk in &self.tracers {
n += ser.write(sk)?;
n += ser.write(pk)?;
}

n = ser.write_leb128_u64(self.users.len() as u64)?;
Expand All @@ -171,8 +166,7 @@ impl Serializable for TracingSecretKey {
let mut tracers = LinkedList::new();
for _ in 0..n_tracers {
let sk = de.read()?;
let pk = de.read()?;
tracers.push_back((sk, pk));
tracers.push_back(sk);
}

let n_users = <usize>::try_from(de.read_leb128_u64()?)?;
Expand Down

0 comments on commit 4e0be2f

Please sign in to comment.