Skip to content

Commit

Permalink
Add storage utility methods for presign #429
Browse files Browse the repository at this point in the history
- adds serialization methods and equality checking for presign records
- adds a utility method in the parse-bytes function to read an 8-byte length, since we use that everywhere.
  • Loading branch information
marsella authored Jul 7, 2023
1 parent 56d09f4 commit b454254
Show file tree
Hide file tree
Showing 4 changed files with 422 additions and 27 deletions.
12 changes: 1 addition & 11 deletions src/auxinfo/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ pub struct AuxInfoPrivate {
}

const AUXINFO_TAG: &[u8] = b"AuxInfoPrivate";
// Length of the length field for auxinfo serialization.
const AUXINFO_LEN: usize = 8;

impl AuxInfoPrivate {
pub(crate) fn encryption_key(&self) -> EncryptionKey {
Expand Down Expand Up @@ -93,15 +91,7 @@ impl AuxInfoPrivate {
}

// Extract the length of the key
let key_len_slice = parser.take_bytes(AUXINFO_LEN)?;
let len_bytes: [u8; AUXINFO_LEN] = key_len_slice.try_into().map_err(|_| {
error!(
"Failed to convert byte array (should always work because we
defined it to be exactly 8 bytes)"
);
InternalError::InternalInvariantFailed
})?;
let key_len = usize::from_le_bytes(len_bytes);
let key_len = parser.take_len()?;

let key_bytes = parser.take_rest()?;
if key_bytes.len() != key_len {
Expand Down
14 changes: 2 additions & 12 deletions src/keygen/keyshare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// of this source tree.

use crate::{
errors::{CallerError, InternalError, Result},
errors::{CallerError, Result},
utils::{k256_order, CurvePoint, ParseBytes},
ParticipantIdentifier,
};
Expand All @@ -19,8 +19,6 @@ use tracing::error;
use zeroize::{Zeroize, ZeroizeOnDrop};

const KEYSHARE_TAG: &[u8] = b"KeySharePrivate";
/// Length of the field indicating the length of the key share.
const KEYSHARE_LEN: usize = 8;

/// Private key corresponding to a given [`Participant`](crate::Participant)'s
/// [`KeySharePublic`].
Expand Down Expand Up @@ -92,15 +90,7 @@ impl KeySharePrivate {
}

// Extract the length of the key share
let share_len_slice = parser.take_bytes(KEYSHARE_LEN)?;
let share_len_bytes: [u8; KEYSHARE_LEN] = share_len_slice.try_into().map_err(|_| {
error!(
"Failed to convert byte array (should always work because we
defined it to be exactly 8 bytes"
);
InternalError::InternalInvariantFailed
})?;
let share_len = usize::from_le_bytes(share_len_bytes);
let share_len = parser.take_len()?;

let share_bytes = parser.take_rest()?;
if share_bytes.len() != share_len {
Expand Down
Loading

0 comments on commit b454254

Please sign in to comment.