Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ServerKeyState for key synchronization #384

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 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 <coela@alxdavids.xyz>", "Ralph Ankele <rankele@brave.com>"]
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 Down
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
47 changes: 46 additions & 1 deletion ppoprf/src/ppoprf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use serde::{de, ser, Deserialize, Serialize};
use std::collections::BTreeMap;
use std::convert::TryInto;

use crate::ggm::GGMPuncturableKey;
use crate::strobe_rng::StrobeRng;
use strobe_rs::{SecParam, Strobe};

Expand Down Expand Up @@ -192,7 +193,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 +302,36 @@ where
Ok(Point(CompressedRistretto(fixed_data)))
}

/// Structure containing all relevant key information
/// for syncing between Server instances.
/// To be used for deserialization.
#[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.
#[derive(Serialize, Eq, PartialEq, Debug)]
pub struct ServerKeyStateRef<'a> {
oprf_key: &'a RistrettoScalar,
public_key: &'a ServerPublicKey,
ggm_key: &'a GGMPuncturableKey,
}

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 +401,20 @@ impl Server {
pub fn get_public_key(&self) -> ServerPublicKey {
self.public_key.clone()
}

pub fn get_private_key(&self) -> ServerKeyStateRef<'_> {
ServerKeyStateRef {
oprf_key: &self.oprf_key,
public_key: &self.public_key,
ggm_key: &self.pprf.key,
}
}

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
Loading