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

Introduce KeyFragID instead of using a Scalar for this purpose #40

Merged
merged 5 commits into from
Mar 12, 2021

Conversation

fjarri
Copy link
Contributor

@fjarri fjarri commented Mar 6, 2021

A part of #27
Fixes #21

  • now KeyFrag identifier matches the one used in PyUmbral.
  • hash CapsuleFrag metadata in bytes instead of a scalar

@codecov-io
Copy link

Codecov Report

Merging #40 (99cae8c) into master (125a2c6) will decrease coverage by 0.18%.
The diff coverage is 87.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #40      +/-   ##
==========================================
- Coverage   94.83%   94.64%   -0.19%     
==========================================
  Files          10       10              
  Lines         736      766      +30     
==========================================
+ Hits          698      725      +27     
- Misses         38       41       +3     
Impacted Files Coverage Δ
umbral-pre/src/key_frag.rs 86.39% <66.66%> (-0.41%) ⬇️
umbral-pre/src/capsule_frag.rs 92.75% <82.35%> (+1.08%) ⬆️
umbral-pre/src/dem.rs 94.44% <100.00%> (-0.30%) ⬇️
umbral-pre/src/hashing.rs 98.18% <100.00%> (+0.28%) ⬆️
umbral-pre/src/hashing_ds.rs 100.00% <100.00%> (ø)
umbral-pre/src/curve.rs 95.50% <0.00%> (-2.25%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 125a2c6...99cae8c. Read the comment docs.

Copy link

@tuxxy tuxxy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@@ -17,7 +48,7 @@ pub struct CapsuleFragProof {
kfrag_pok: CurvePoint,
signature: CurveScalar,
kfrag_signature: Signature,
metadata: CurveScalar,
metadata: HashedMetadata,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

type HashedMetadataSize = BytesDigestOutputSize;

#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct HashedMetadata(GenericArray<u8, HashedMetadataSize>);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice.

) -> CurveScalar {
ScalarDigest::new_with_dst(b"POLYNOMIAL_ARG")
.chain_point(precursor)
.chain_point(pubkey)
.chain_point(dh_point)
.chain_scalar(id)
.chain_bytes(kfrag_id)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct KeyFragID(GenericArray<u8, KeyFragIDSize>);

impl KeyFragID {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, lots of room for other cool additions here in the future.

@@ -59,7 +91,7 @@ impl KeyFragProof {
#[allow(clippy::too_many_arguments)]
fn new(
params: &Parameters,
kfrag_id: &CurveScalar,
kfrag_id: &KeyFragID,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -151,8 +183,7 @@ impl SerializableToArray for KeyFrag {

impl KeyFrag {
fn new(factory: &KeyFragFactory, sign_delegating_key: bool, sign_receiving_key: bool) -> Self {
// Was: `os.urandom(bn_size)`. But it seems we just want a scalar?
let kfrag_id = CurveScalar::random_nonzero();
let kfrag_id = KeyFragID::random();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -221,7 +252,7 @@ impl KeyFrag {
let correct_commitment = commitment == &u * &key;

let mut digest = SignatureDigest::new()
.chain_scalar(&kfrag_id)
.chain_bytes(&kfrag_id)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -200,7 +231,7 @@ impl CapsuleFrag {

let h = ScalarDigest::new()
.chain_points(&[e, e1, e2, v, v1, v2, u, u1, u2])
.chain_scalar(&self.proof.metadata)
.chain_bytes(&self.proof.metadata)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -209,7 +240,7 @@ impl CapsuleFrag {
let kfrag_id = self.kfrag_id;

let valid_kfrag_signature = SignatureDigest::new()
.chain_scalar(&kfrag_id)
.chain_bytes(&kfrag_id)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -137,7 +168,7 @@ impl SerializableToArray for CapsuleFrag {
fn from_array(arr: &GenericArray<u8, Self::Size>) -> Option<Self> {
let (point_e1, rest) = CurvePoint::take(*arr)?;
let (point_v1, rest) = CurvePoint::take(rest)?;
let (kfrag_id, rest) = CurveScalar::take(rest)?;
let (kfrag_id, rest) = KeyFragID::take(rest)?;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@fjarri fjarri merged commit 128eb0c into nucypher:master Mar 12, 2021
@fjarri fjarri deleted the kfrag_id branch March 12, 2021 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CapsuleFrag metadata as a scalar
3 participants