Skip to content

Commit d64d14a

Browse files
committed
daphne: Remove 16-byte VdafVerifyKey variant
This length was required for Prio3 by VDAF-09. However, we only support variants of Prio3 in VDAF-09 that use the custom XOF, which has a 32-byte key. Also, once Mastic support is fully implemented, it will also use a 32-byte key.
1 parent 03b8b68 commit d64d14a

File tree

6 files changed

+33
-106
lines changed

6 files changed

+33
-106
lines changed

crates/daphne/src/taskprov.rs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,14 @@ pub(crate) fn extract_prk_from_verify_key_init(
6363
Salt::new(HKDF_SHA256, &TASKPROV_SALT).extract(verify_key_init)
6464
}
6565

66-
impl VdafConfig {
67-
fn expand_into_taskprov_verify_key(&self, prk: &Prk, task_id: &TaskId) -> VdafVerifyKey {
68-
let mut verify_key = self.uninitialized_verify_key();
69-
let info = [task_id.as_ref()];
70-
// This expand(), and the associated fill() below can only fail if the length is wrong,
71-
// and it won't be, so we unwrap().
72-
let okm = prk.expand(&info, verify_key.clone()).unwrap();
73-
okm.fill(verify_key.as_mut()).unwrap();
74-
verify_key
75-
}
66+
fn expand_into_taskprov_verify_key(prk: &Prk, task_id: &TaskId) -> VdafVerifyKey {
67+
let mut verify_key = VdafVerifyKey([0; 32]);
68+
let info = [task_id.as_ref()];
69+
// This expand(), and the associated fill() below can only fail if the length is wrong,
70+
// and it won't be, so we unwrap().
71+
let okm = prk.expand(&info, verify_key.clone()).unwrap();
72+
okm.fill(verify_key.as_mut()).unwrap();
73+
verify_key
7674
}
7775

7876
/// Compute the VDAF verify key for `task_id` and the specified VDAF type using the
@@ -86,9 +84,8 @@ fn compute_vdaf_verify_key(
8684
version: DapVersion,
8785
verify_key_init: &[u8; 32],
8886
task_id: &TaskId,
89-
vdaf_config: &VdafConfig,
9087
) -> VdafVerifyKey {
91-
vdaf_config.expand_into_taskprov_verify_key(
88+
expand_into_taskprov_verify_key(
9289
&extract_prk_from_verify_key_init(version, verify_key_init),
9390
task_id,
9491
)
@@ -313,12 +310,8 @@ impl DapTaskConfigNeedsOptIn {
313310
version,
314311
taskprov_advertisement.vdaf_config.var,
315312
)?;
316-
let vdaf_verify_key = compute_vdaf_verify_key(
317-
version,
318-
taskprov_config.vdaf_verify_key_init,
319-
task_id,
320-
&vdaf,
321-
);
313+
let vdaf_verify_key =
314+
compute_vdaf_verify_key(version, taskprov_config.vdaf_verify_key_init, task_id);
322315
Ok(Self {
323316
version,
324317
leader_url: url_from_bytes(task_id, &taskprov_advertisement.leader_url.bytes)?,
@@ -465,7 +458,7 @@ mod test {
465458
messages::{self, TaskId},
466459
taskprov::{DapTaskConfigNeedsOptIn, OptInParam},
467460
test_versions,
468-
vdaf::{VdafConfig, VdafVerifyKey},
461+
vdaf::VdafVerifyKey,
469462
DapRequestMeta, DapVersion,
470463
};
471464

@@ -536,20 +529,13 @@ mod test {
536529
0x0f, 0x32, 0xd7, 0xe1, 0xbc, 0x6c, 0x75, 0x10, 0x05, 0x60, 0x7b, 0x81, 0xda, 0xc3,
537530
0xa7, 0xda, 0x76, 0x1d,
538531
];
539-
let vk = compute_vdaf_verify_key(
540-
version,
541-
&verify_key_init,
542-
&task_id,
543-
&VdafConfig::Prio2 { dimension: 10 },
544-
);
532+
let VdafVerifyKey(verify_key) =
533+
compute_vdaf_verify_key(version, &verify_key_init, &task_id);
545534
let expected: [u8; 32] = [
546535
251, 209, 125, 181, 57, 15, 148, 158, 227, 45, 38, 52, 220, 73, 159, 91, 145, 40, 123,
547536
204, 49, 124, 7, 97, 221, 4, 232, 53, 194, 171, 19, 51,
548537
];
549-
match &vk {
550-
VdafVerifyKey::L32(bytes) => assert_eq!(*bytes, expected),
551-
VdafVerifyKey::L16(..) => unreachable!(),
552-
}
538+
assert_eq!(verify_key, expected);
553539
}
554540

555541
test_versions! { check_vdaf_key_computation }

crates/daphne/src/vdaf/mastic.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,11 @@ pub(crate) fn mastic_shard(
7070
pub(crate) fn mastic_prep_init(
7171
input_size: usize,
7272
weight_config: MasticWeightConfig,
73-
verify_key: &VdafVerifyKey,
73+
_verify_key: &VdafVerifyKey,
7474
agg_param: &DapAggregationParam,
7575
public_share_bytes: &[u8],
7676
input_share_bytes: &[u8],
7777
) -> Result<(VdafPrepState, VdafPrepShare), VdafError> {
78-
let VdafVerifyKey::L16(_verify_key) = verify_key else {
79-
return Err(VdafError::Dap(fatal_error!(
80-
err = "mastic: unexpected verify key type"
81-
)));
82-
};
83-
8478
match (weight_config, agg_param) {
8579
(MasticWeightConfig::Count, DapAggregationParam::Mastic(agg_param)) => {
8680
// Simulate Mastic, insecurely. The public share encodes the plaintext input; the input

crates/daphne/src/vdaf/mod.rs

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -388,38 +388,23 @@ impl std::fmt::Display for Prio3Config {
388388
any(test, feature = "test-utils"),
389389
derive(deepsize::DeepSizeOf, PartialEq, Debug)
390390
)]
391-
pub enum VdafVerifyKey {
392-
/// Prio3 with the standard XOF.
393-
L16(#[serde(with = "hex")] [u8; 16]),
394-
395-
/// Prio2 and Prio3 with `XofHmacSha256Aes128`.
396-
L32(#[serde(with = "hex")] [u8; 32]),
397-
}
391+
pub struct VdafVerifyKey(#[serde(with = "hex")] pub(crate) [u8; 32]);
398392

399393
impl KeyType for VdafVerifyKey {
400394
fn len(&self) -> usize {
401-
match self {
402-
Self::L16(bytes) => bytes.len(),
403-
Self::L32(bytes) => bytes.len(),
404-
}
395+
32
405396
}
406397
}
407398

408399
impl AsRef<[u8]> for VdafVerifyKey {
409400
fn as_ref(&self) -> &[u8] {
410-
match self {
411-
Self::L16(bytes) => &bytes[..],
412-
Self::L32(bytes) => &bytes[..],
413-
}
401+
&self.0
414402
}
415403
}
416404

417405
impl AsMut<[u8]> for VdafVerifyKey {
418406
fn as_mut(&mut self) -> &mut [u8] {
419-
match self {
420-
Self::L16(bytes) => &mut bytes[..],
421-
Self::L32(bytes) => &mut bytes[..],
422-
}
407+
&mut self.0
423408
}
424409
}
425410

@@ -646,39 +631,17 @@ impl Encode for VdafAggregateShare {
646631
}
647632

648633
impl VdafConfig {
649-
pub(crate) fn uninitialized_verify_key(&self) -> VdafVerifyKey {
650-
match self {
651-
Self::Prio2 { .. } | Self::Prio3(..) => VdafVerifyKey::L32([0; 32]),
652-
#[cfg(feature = "experimental")]
653-
Self::Mastic { .. } => VdafVerifyKey::L16([0; 16]),
654-
Self::Pine(..) => VdafVerifyKey::L32([0; 32]),
655-
}
656-
}
657-
658634
/// Parse a verification key from raw bytes.
659635
pub fn get_decoded_verify_key(&self, bytes: &[u8]) -> Result<VdafVerifyKey, CodecError> {
660-
match self {
661-
Self::Prio2 { .. } | Self::Prio3(..) => Ok(VdafVerifyKey::L32(
662-
<[u8; 32]>::try_from(bytes)
663-
.map_err(|e| CodecErrorDraft09::Other(Box::new(e)))
664-
.map_err(upgrade_codec_error)?,
665-
)),
666-
#[cfg(feature = "experimental")]
667-
Self::Mastic { .. } => Ok(VdafVerifyKey::L16(
668-
<[u8; 16]>::try_from(bytes).map_err(|e| CodecError::Other(Box::new(e)))?,
669-
)),
670-
Self::Pine(..) => Ok(VdafVerifyKey::L32(
671-
<[u8; 32]>::try_from(bytes)
672-
.map_err(|e| CodecErrorDraft09::Other(Box::new(e)))
673-
.map_err(upgrade_codec_error)?,
674-
)),
675-
}
636+
Ok(VdafVerifyKey(
637+
<[u8; 32]>::try_from(bytes).map_err(|_| CodecError::UnexpectedValue)?,
638+
))
676639
}
677640

678641
/// Generate the Aggregators' shared verification parameters.
679642
pub fn gen_verify_key(&self) -> VdafVerifyKey {
680643
let mut rng = thread_rng();
681-
let mut verify_key = self.uninitialized_verify_key();
644+
let mut verify_key = VdafVerifyKey([0; 32]);
682645
rng.fill(verify_key.as_mut());
683646
verify_key
684647
}

crates/daphne/src/vdaf/pine.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ impl PineConfig {
8181

8282
pub(crate) fn prep_init(
8383
&self,
84-
verify_key: &VdafVerifyKey,
84+
VdafVerifyKey(verify_key): &VdafVerifyKey,
8585
agg_id: usize,
8686
nonce: &[u8; 16],
8787
public_share_data: &[u8],
8888
input_share_data: &[u8],
8989
) -> Result<(VdafPrepState, VdafPrepShare), VdafError> {
90-
match (self, verify_key) {
91-
(PineConfig::Field32HmacSha256Aes128 { param }, VdafVerifyKey::L32(verify_key)) => {
90+
match self {
91+
PineConfig::Field32HmacSha256Aes128 { param } => {
9292
let vdaf = pine32_hmac_sha256_aes128(param)?;
9393
let (state, share) = prep_init(
9494
vdaf,
@@ -103,7 +103,7 @@ impl PineConfig {
103103
VdafPrepShare::Pine32HmacSha256Aes128(share),
104104
))
105105
}
106-
(PineConfig::Field64HmacSha256Aes128 { param }, VdafVerifyKey::L32(verify_key)) => {
106+
PineConfig::Field64HmacSha256Aes128 { param } => {
107107
let vdaf = pine64_hmac_sha256_aes128(param)?;
108108
let (state, share) = prep_init(
109109
vdaf,
@@ -118,9 +118,6 @@ impl PineConfig {
118118
VdafPrepShare::Pine64HmacSha256Aes128(share),
119119
))
120120
}
121-
_ => Err(VdafError::Dap(fatal_error!(
122-
err = "unhandled config and verify key combination",
123-
))),
124121
}
125122
}
126123

crates/daphne/src/vdaf/prio2.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,12 @@ pub(crate) fn prio2_shard(
5555
/// Consume an input share and return the corresponding prep state and share.
5656
pub(crate) fn prio2_prep_init(
5757
dimension: usize,
58-
verify_key: &VdafVerifyKey,
58+
VdafVerifyKey(verify_key): &VdafVerifyKey,
5959
agg_id: usize,
6060
nonce: &[u8; 16],
6161
public_share_data: &[u8],
6262
input_share_data: &[u8],
6363
) -> Result<(VdafPrepState, VdafPrepShare), VdafError> {
64-
let VdafVerifyKey::L32(verify_key) = verify_key else {
65-
return Err(VdafError::Dap(fatal_error!(
66-
err = "unhandled verify key type"
67-
)));
68-
};
69-
7064
let vdaf = Prio2::new(dimension).map_err(|e| {
7165
VdafError::Dap(fatal_error!(err = ?e, "failed to create prio2 from {dimension}"))
7266
})?;

crates/daphne/src/vdaf/prio3.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ impl Prio3Config {
111111
pub(crate) fn prep_init(
112112
&self,
113113
version: DapVersion,
114-
verify_key: &VdafVerifyKey,
114+
VdafVerifyKey(verify_key): &VdafVerifyKey,
115115
task_id: TaskId,
116116
agg_id: usize,
117117
nonce: &[u8; 16],
118118
public_share_data: &[u8],
119119
input_share_data: &[u8],
120120
) -> Result<(VdafPrepState, VdafPrepShare), VdafError> {
121-
return match (version, self, verify_key) {
122-
(DapVersion::Latest, Prio3Config::Count, VdafVerifyKey::L32(verify_key)) => {
121+
return match (version, self) {
122+
(DapVersion::Latest, Prio3Config::Count) => {
123123
let vdaf = Prio3::new_count(2).map_err(|e| {
124124
VdafError::Dap(fatal_error!(err = ?e, "initializing {self:?} failed"))
125125
})?;
@@ -137,11 +137,7 @@ impl Prio3Config {
137137
VdafPrepShare::Prio3Field64(share),
138138
))
139139
}
140-
(
141-
DapVersion::Latest,
142-
Prio3Config::Sum { max_measurement },
143-
VdafVerifyKey::L32(verify_key),
144-
) => {
140+
(DapVersion::Latest, Prio3Config::Sum { max_measurement }) => {
145141
let vdaf = Prio3::new_sum(2, *max_measurement).map_err(|e| {
146142
VdafError::Dap(fatal_error!(err = ?e, "initializing {self:?} failed"))
147143
})?;
@@ -165,7 +161,6 @@ impl Prio3Config {
165161
length,
166162
chunk_length,
167163
},
168-
VdafVerifyKey::L32(verify_key),
169164
) => {
170165
let vdaf = Prio3::new_histogram(2, *length, *chunk_length).map_err(|e| {
171166
VdafError::Dap(fatal_error!(err = ?e, "initializing {self:?} failed"))
@@ -191,7 +186,6 @@ impl Prio3Config {
191186
length,
192187
chunk_length,
193188
},
194-
VdafVerifyKey::L32(verify_key),
195189
) => {
196190
let vdaf = Prio3::new_sum_vec(2, *bits, *length, *chunk_length).map_err(|e| {
197191
VdafError::Dap(fatal_error!(err = ?e, "initializing {self:?} failed"))
@@ -218,7 +212,6 @@ impl Prio3Config {
218212
chunk_length,
219213
num_proofs,
220214
},
221-
VdafVerifyKey::L32(verify_key),
222215
) => {
223216
let vdaf = draft09::new_prio3_sum_vec_field64_multiproof_hmac_sha256_aes128(
224217
*bits,

0 commit comments

Comments
 (0)