Skip to content

Commit

Permalink
Merge pull request #384 from DJAndries/key-sync
Browse files Browse the repository at this point in the history
Add `ServerKeyState` for key synchronization
  • Loading branch information
claucece authored Aug 27, 2024
2 parents acec88f + d142249 commit bbaf428
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 11 deletions.
9 changes: 6 additions & 3 deletions ppoprf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ppoprf"
version = "0.3.1"
version = "0.4.0"
authors = ["Alex Davidson <[email protected]>", "Ralph Ankele <[email protected]>"]
description = "Puncturable Partially-Oblivious Pseudo-Random Function"
documentation = "https://docs.rs/ppoprf"
Expand All @@ -12,9 +12,9 @@ edition = "2021"

[dependencies]
rand = { version = "0.8.5", features = [ "getrandom" ] }
bitvec = "1.0.1"
bitvec = { version = "1.0.1", features = ["serde"] }
curve25519-dalek = { version = "4.0.0", features = [ "rand_core", "serde" ] }
serde = "1.0.147"
serde = { version = "1.0.147", features = ["derive"] }
strobe-rs = "0.8.1"
base64 = "0.13.0"
bincode = "1.3.3"
Expand All @@ -34,3 +34,6 @@ warp = "0.3.7"
[[bench]]
name = "bench"
harness = false

[features]
key-sync = []
19 changes: 13 additions & 6 deletions ppoprf/src/ggm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ use crate::strobe_rng::StrobeRng;
use bitvec::prelude::*;
use rand::rngs::OsRng;
use rand::Rng;
use serde::{Deserialize, Serialize};
use strobe_rs::{SecParam, Strobe};

use zeroize::{Zeroize, ZeroizeOnDrop};

#[derive(Clone, Eq, PartialEq)]
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
struct Prefix {
bits: BitVec<usize, bitvec::order::Lsb0>,
}
Expand All @@ -31,11 +32,15 @@ impl Prefix {

impl fmt::Debug for Prefix {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Prefix").field("bits", &self.bits).finish()
f.debug_struct("Prefix")
.field("bits", &self.bits.as_raw_slice().to_vec())
.finish()
}
}

#[derive(Clone, Zeroize, ZeroizeOnDrop)]
#[derive(
Debug, Clone, Zeroize, ZeroizeOnDrop, Serialize, Deserialize, PartialEq, Eq,
)]
struct GGMPseudorandomGenerator {
key: [u8; 32],
}
Expand All @@ -59,8 +64,10 @@ impl GGMPseudorandomGenerator {
}
}

#[derive(Clone, Zeroize, ZeroizeOnDrop)]
struct GGMPuncturableKey {
#[derive(
Debug, Clone, Zeroize, ZeroizeOnDrop, Serialize, Deserialize, Eq, PartialEq,
)]
pub(crate) struct GGMPuncturableKey {
prgs: Vec<GGMPseudorandomGenerator>,
#[zeroize(skip)]
prefixes: Vec<(Prefix, Vec<u8>)>,
Expand Down Expand Up @@ -125,7 +132,7 @@ impl GGMPuncturableKey {
#[derive(Clone, Zeroize, ZeroizeOnDrop)]
pub struct GGM {
inp_len: usize,
key: GGMPuncturableKey,
pub(crate) key: GGMPuncturableKey,
}

impl GGM {
Expand Down
53 changes: 52 additions & 1 deletion ppoprf/src/ppoprf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use serde::{de, ser, Deserialize, Serialize};
use std::collections::BTreeMap;
use std::convert::TryInto;

#[cfg(feature = "key-sync")]
use crate::ggm::GGMPuncturableKey;
use crate::strobe_rng::StrobeRng;
use strobe_rs::{SecParam, Strobe};

Expand Down Expand Up @@ -192,7 +194,7 @@ impl ProofDLEQ {

// Server public key structure for PPOPRF, contains all elements of the
// form g^{sk_0},g^{t_i} for metadata tags t_i.
#[derive(Deserialize, Serialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
pub struct ServerPublicKey {
base_pk: Point,
md_pks: BTreeMap<u8, Point>,
Expand Down Expand Up @@ -301,6 +303,39 @@ where
Ok(Point(CompressedRistretto(fixed_data)))
}

/// Structure containing all relevant key information
/// for syncing between Server instances.
/// To be used for deserialization.
#[cfg(feature = "key-sync")]
#[derive(Deserialize)]
pub struct ServerKeyState {
oprf_key: RistrettoScalar,
public_key: ServerPublicKey,
ggm_key: GGMPuncturableKey,
}

/// Structure containing all relevant key information
/// for syncing between Server instances.
/// To be used for serialization.
#[cfg(feature = "key-sync")]
#[derive(Serialize, Eq, PartialEq, Debug)]
pub struct ServerKeyStateRef<'a> {
oprf_key: &'a RistrettoScalar,
public_key: &'a ServerPublicKey,
ggm_key: &'a GGMPuncturableKey,
}

#[cfg(feature = "key-sync")]
impl ServerKeyState {
pub fn as_ref(&self) -> ServerKeyStateRef<'_> {
ServerKeyStateRef {
oprf_key: &self.oprf_key,
public_key: &self.public_key,
ggm_key: &self.ggm_key,
}
}
}

// The `Server` runs the server-side component of the PPOPRF protocol.
#[derive(Clone, Zeroize, ZeroizeOnDrop)]
pub struct Server {
Expand Down Expand Up @@ -370,6 +405,22 @@ impl Server {
pub fn get_public_key(&self) -> ServerPublicKey {
self.public_key.clone()
}

#[cfg(feature = "key-sync")]
pub fn get_private_key(&self) -> ServerKeyStateRef<'_> {
ServerKeyStateRef {
oprf_key: &self.oprf_key,
public_key: &self.public_key,
ggm_key: &self.pprf.key,
}
}

#[cfg(feature = "key-sync")]
pub fn set_private_key(&mut self, private_key: ServerKeyState) {
self.oprf_key = private_key.oprf_key;
self.public_key = private_key.public_key;
self.pprf.key = private_key.ggm_key;
}
}

// The `Client` struct is essentially a collection of static functions
Expand Down
2 changes: 1 addition & 1 deletion star/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2018"
[dependencies]
strobe-rs = "0.8.1"
adss = { path = "../adss", version = "0.2.2" }
ppoprf = { path = "../ppoprf", version = "0.3.0" }
ppoprf = { path = "../ppoprf", version = "0.4.0" }
rand = "0.8.5"
rand_core = "0.6.4"
zeroize = "1.5.5"
Expand Down

0 comments on commit bbaf428

Please sign in to comment.