Skip to content

Commit

Permalink
Ritual id is now a u32 - modify object protocol version for incompati…
Browse files Browse the repository at this point in the history
…ble change.

Improve error name for invalid seed length.
  • Loading branch information
derekpierre committed Jun 6, 2023
1 parent 8b1b90c commit 7735aba
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed `E2EThresholdDecryptionRequest` type and bindings. ([#54])
- Modified `EncryptedThresholdDecryptionRequest`/`EncryptedThresholdDecryptionResponse` to use Curve 25519 keys instead of Umbral keys for encryption/decryption. ([#54])
- Modified `ThresholdDecryptionResponse`/`EncryptedThresholdDecryptionResponse` to include `ritual_id` member in struct. ([#54])
- Ritual ID for `ThresholdDecryption[Request/Response]` / `EncryptedThresholdDecryption[Request/Response]` is now u32 instead of u16. ([#54])


[#53]: https://github.com/nucypher/nucypher-core/pull/53
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions nucypher-core-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ pub struct ThresholdDecryptionRequest {
impl ThresholdDecryptionRequest {
#[new]
pub fn new(
ritual_id: u16,
ritual_id: u32,
variant: u8,
ciphertext: &Ciphertext,
conditions: Option<&Conditions>,
Expand Down Expand Up @@ -792,7 +792,7 @@ impl ThresholdDecryptionRequest {
}

#[getter]
pub fn ritual_id(&self) -> u16 {
pub fn ritual_id(&self) -> u32 {
self.backend.ritual_id
}

Expand Down Expand Up @@ -863,7 +863,7 @@ pub struct EncryptedThresholdDecryptionRequest {
#[pymethods]
impl EncryptedThresholdDecryptionRequest {
#[getter]
pub fn ritual_id(&self) -> u16 {
pub fn ritual_id(&self) -> u32 {
self.backend.ritual_id
}

Expand Down Expand Up @@ -905,14 +905,14 @@ pub struct ThresholdDecryptionResponse {
#[pymethods]
impl ThresholdDecryptionResponse {
#[new]
pub fn new(ritual_id: u16, decryption_share: &[u8]) -> Self {
pub fn new(ritual_id: u32, decryption_share: &[u8]) -> Self {
ThresholdDecryptionResponse {
backend: nucypher_core::ThresholdDecryptionResponse::new(ritual_id, decryption_share),
}
}

#[getter]
pub fn ritual_id(&self) -> u16 {
pub fn ritual_id(&self) -> u32 {
self.backend.ritual_id
}

Expand Down Expand Up @@ -953,7 +953,7 @@ pub struct EncryptedThresholdDecryptionResponse {
#[pymethods]
impl EncryptedThresholdDecryptionResponse {
#[getter]
pub fn ritual_id(&self) -> u16 {
pub fn ritual_id(&self) -> u32 {
self.backend.ritual_id
}

Expand Down
12 changes: 6 additions & 6 deletions nucypher-core-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ pub struct ThresholdDecryptionRequest(nucypher_core::ThresholdDecryptionRequest)
impl ThresholdDecryptionRequest {
#[wasm_bindgen(constructor)]
pub fn new(
ritual_id: u16,
ritual_id: u32,
variant: u8,
ciphertext: &Ciphertext,
conditions: &OptionConditions,
Expand All @@ -682,7 +682,7 @@ impl ThresholdDecryptionRequest {
}

#[wasm_bindgen(getter, js_name = ritualId)]
pub fn ritual_id(&self) -> u16 {
pub fn ritual_id(&self) -> u32 {
self.0.ritual_id
}

Expand Down Expand Up @@ -732,7 +732,7 @@ pub struct EncryptedThresholdDecryptionRequest(nucypher_core::EncryptedThreshold
#[wasm_bindgen]
impl EncryptedThresholdDecryptionRequest {
#[wasm_bindgen(getter, js_name = ritualId)]
pub fn ritual_id(&self) -> u16 {
pub fn ritual_id(&self) -> u32 {
self.0.ritual_id
}

Expand Down Expand Up @@ -774,7 +774,7 @@ pub struct ThresholdDecryptionResponse(nucypher_core::ThresholdDecryptionRespons
impl ThresholdDecryptionResponse {
#[wasm_bindgen(constructor)]
pub fn new(
ritual_id: u16,
ritual_id: u32,
decryption_share: &[u8],
) -> Result<ThresholdDecryptionResponse, Error> {
Ok(Self(nucypher_core::ThresholdDecryptionResponse::new(
Expand All @@ -784,7 +784,7 @@ impl ThresholdDecryptionResponse {
}

#[wasm_bindgen(getter, js_name = ritualId)]
pub fn ritual_id(&self) -> u16 {
pub fn ritual_id(&self) -> u32 {
self.0.ritual_id
}

Expand Down Expand Up @@ -824,7 +824,7 @@ pub struct EncryptedThresholdDecryptionResponse(
#[wasm_bindgen]
impl EncryptedThresholdDecryptionResponse {
#[wasm_bindgen(getter, js_name = ritualId)]
pub fn ritual_id(&self) -> u16 {
pub fn ritual_id(&self) -> u32 {
self.0.ritual_id
}

Expand Down
2 changes: 1 addition & 1 deletion nucypher-core-wasm/tests/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ fn request_public_key() {

#[wasm_bindgen_test]
fn threshold_decryption_request() {
let ritual_id: u16 = 5;
let ritual_id: u32 = 5;
let service_secret = RequestSecretKey::random();
let service_public_key = service_secret.public_key();

Expand Down
36 changes: 22 additions & 14 deletions nucypher-core/src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ pub mod request_keys {
type RequestKeyFactorySeed = GenericArray<u8, SecretKeyFactorySeedSize>;

/// Error thrown when invalid random seed provided for creating key factory.
pub struct InvalidRequestFactorySeedLengthError;
pub struct InvalidRequestFactorySeedLength;

impl fmt::Display for InvalidRequestFactorySeedLengthError {
impl fmt::Display for InvalidRequestFactorySeedLength {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Invalid seed length")
}
Expand Down Expand Up @@ -304,9 +304,9 @@ pub mod request_keys {
/// from a cryptographically secure source of randomness!
pub fn from_secure_randomness(
seed: &[u8],
) -> Result<Self, InvalidRequestFactorySeedLengthError> {
) -> Result<Self, InvalidRequestFactorySeedLength> {
if seed.len() != Self::seed_size() {
return Err(InvalidRequestFactorySeedLengthError);
return Err(InvalidRequestFactorySeedLength);
}
Ok(Self(SecretBox::new(*RequestKeyFactorySeed::from_slice(
seed,
Expand Down Expand Up @@ -343,7 +343,7 @@ pub mod request_keys {
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
pub struct ThresholdDecryptionRequest {
/// The ID of the ritual.
pub ritual_id: u16,
pub ritual_id: u32,
/// The ciphertext to generate a decryption share for.
pub ciphertext: Ciphertext,
/// A blob of bytes containing decryption conditions for this message.
Expand All @@ -357,7 +357,7 @@ pub struct ThresholdDecryptionRequest {
impl ThresholdDecryptionRequest {
/// Creates a new decryption request.
pub fn new(
ritual_id: u16,
ritual_id: u32,
ciphertext: &Ciphertext,
conditions: Option<&Conditions>,
context: Option<&Context>,
Expand All @@ -384,7 +384,7 @@ impl ThresholdDecryptionRequest {

impl<'a> ProtocolObjectInner<'a> for ThresholdDecryptionRequest {
fn version() -> (u16, u16) {
(1, 0)
(2, 0)
}

fn brand() -> [u8; 4] {
Expand All @@ -410,7 +410,7 @@ impl<'a> ProtocolObject<'a> for ThresholdDecryptionRequest {}
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
pub struct EncryptedThresholdDecryptionRequest {
/// ID of the ritual
pub ritual_id: u16,
pub ritual_id: u32,

/// Public key of requester
pub requester_public_key: RequestPublicKey,
Expand Down Expand Up @@ -449,7 +449,7 @@ impl EncryptedThresholdDecryptionRequest {

impl<'a> ProtocolObjectInner<'a> for EncryptedThresholdDecryptionRequest {
fn version() -> (u16, u16) {
(1, 0)
(2, 0)
}

fn brand() -> [u8; 4] {
Expand All @@ -475,7 +475,7 @@ impl<'a> ProtocolObject<'a> for EncryptedThresholdDecryptionRequest {}
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
pub struct ThresholdDecryptionResponse {
/// The ID of the ritual.
pub ritual_id: u16,
pub ritual_id: u32,

/// The decryption share to include in the response.
#[serde(with = "serde_bytes::as_base64")]
Expand All @@ -484,7 +484,7 @@ pub struct ThresholdDecryptionResponse {

impl ThresholdDecryptionResponse {
/// Creates and a new decryption response.
pub fn new(ritual_id: u16, decryption_share: &[u8]) -> Self {
pub fn new(ritual_id: u32, decryption_share: &[u8]) -> Self {
ThresholdDecryptionResponse {
ritual_id,
decryption_share: decryption_share.to_vec().into(),
Expand All @@ -502,7 +502,7 @@ impl ThresholdDecryptionResponse {

impl<'a> ProtocolObjectInner<'a> for ThresholdDecryptionResponse {
fn version() -> (u16, u16) {
(1, 0)
(2, 0)
}

fn brand() -> [u8; 4] {
Expand All @@ -528,7 +528,7 @@ impl<'a> ProtocolObject<'a> for ThresholdDecryptionResponse {}
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
pub struct EncryptedThresholdDecryptionResponse {
/// The ID of the ritual.
pub ritual_id: u16,
pub ritual_id: u32,

#[serde(with = "serde_bytes::as_base64")]
ciphertext: Box<[u8]>,
Expand Down Expand Up @@ -560,7 +560,7 @@ impl EncryptedThresholdDecryptionResponse {

impl<'a> ProtocolObjectInner<'a> for EncryptedThresholdDecryptionResponse {
fn version() -> (u16, u16) {
(1, 0)
(2, 0)
}

fn brand() -> [u8; 4] {
Expand Down Expand Up @@ -719,6 +719,10 @@ mod tests {
// service decrypts request
let service_shared_secret =
service_secret.derive_shared_secret(&encrypted_request_from_bytes.requester_public_key);
assert_eq!(
service_shared_secret.as_bytes(),
requester_shared_secret.as_bytes()
);
let decrypted_request = encrypted_request_from_bytes
.decrypt(&service_shared_secret)
.unwrap();
Expand Down Expand Up @@ -758,6 +762,10 @@ mod tests {
// requester decrypts response
let service_public_key = service_secret.public_key();
let requester_shared_secret = requester_secret.derive_shared_secret(&service_public_key);
assert_eq!(
requester_shared_secret.as_bytes(),
service_shared_secret.as_bytes()
);
let decrypted_response = encrypted_response_from_bytes
.decrypt(&requester_shared_secret)
.unwrap();
Expand Down

0 comments on commit 7735aba

Please sign in to comment.