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

build: bump k256 to 0.13.2 #76

Merged
merged 9 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
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
8 changes: 1 addition & 7 deletions rust-k256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ hex-literal = "0.3.4"
hash2field = "0.4.0"
num-bigint = "0.4.3"
num-integer = "0.1.45"
k256 = { version = "0.11.3", features = [
"arithmetic",
"hash2curve",
"expose-field",
"sha2",
] }
elliptic-curve = { version = "0.12.2", features = ["arithmetic"] }
k256 = {version = "0.13.2", features = ["arithmetic", "hash2curve", "expose-field", "sha2"]}

[dev-dependencies]
hex = "0.4.3"
27 changes: 11 additions & 16 deletions rust-k256/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// #![feature(generic_const_expr)]
// #![allow(incomplete_features)]

use elliptic_curve::bigint::ArrayEncoding;
use elliptic_curve::hash2curve::{ExpandMsgXmd, GroupDigest};
use elliptic_curve::ops::Reduce;
use elliptic_curve::sec1::ToEncodedPoint;
use k256::{
// ecdsa::{signature::Signer, Signature, SigningKey},
elliptic_curve::group::ff::PrimeField,
elliptic_curve::hash2curve::{ExpandMsgXmd, GroupDigest},
elliptic_curve::ops::ReduceNonZero,
elliptic_curve::sec1::ToEncodedPoint,
elliptic_curve::{bigint::ArrayEncoding, group::ff::PrimeField},
sha2::{digest::Output, Digest, Sha256},
FieldBytes,
ProjectivePoint,
Expand Down Expand Up @@ -73,7 +72,7 @@ fn hash_to_curve(m: &[u8], pk: &ProjectivePoint) -> ProjectivePoint {
let pt: ProjectivePoint = Secp256k1::hash_from_bytes::<ExpandMsgXmd<Sha256>>(
&[[m, &encode_pt(pk).unwrap()].concat().as_slice()],
//b"CURVE_XMD:SHA-256_SSWU_RO_",
DST,
&[DST],
)
.unwrap();
pt
Expand Down Expand Up @@ -106,24 +105,20 @@ impl PlumeSignature<'_> {
// don't forget to check `c` is `Output<Sha256>` in the #API
let c = Output::<Sha256>::from_slice(self.c);
// TODO should we allow `c` input greater than BaseField::MODULUS?
let c_scalar = &Scalar::from_uint_reduced(U256::from_be_byte_array(c.to_owned()));
skaunov marked this conversation as resolved.
Show resolved Hide resolved
let c_scalar = &Scalar::reduce_nonzero(U256::from_be_byte_array(c.to_owned()));
Divide-By-0 marked this conversation as resolved.
Show resolved Hide resolved
/* @skaunov would be glad to discuss with @Divide-By-0 excessive of the following check.
Though I should notice that it at least doesn't breaking anything. */
if c_scalar.is_zero().into() {
return false;
}

let r_point = ProjectivePoint::GENERATOR * self.s - self.pk * &c_scalar;
let r_point = ProjectivePoint::GENERATOR * self.s - self.pk * c_scalar;
let hashed_to_curve = hash_to_curve(self.message, self.pk);
let hashed_to_curve_r = &hashed_to_curve * self.s - self.nullifier * &c_scalar;
let hashed_to_curve_r = hashed_to_curve * self.s - self.nullifier * c_scalar;

// Check if the given hash matches
let result = |components: Vec<&ProjectivePoint>| -> bool {
if &c_sha256_vec_signal(components) == c {
true
} else {
false
}
&c_sha256_vec_signal(components) == c
skaunov marked this conversation as resolved.
Show resolved Hide resolved
};

if let Some(PlumeSignatureV1Fields {
Expand Down Expand Up @@ -210,7 +205,7 @@ mod tests {
let pt: ProjectivePoint = Secp256k1::hash_from_bytes::<ExpandMsgXmd<Sha256>>(
&[s],
//b"CURVE_XMD:SHA-256_SSWU_RO_"
DST,
&[DST],
)
.unwrap();
pt
Expand Down Expand Up @@ -302,7 +297,7 @@ mod tests {
};
dbg!(&c, version);

let c_scalar = &Scalar::from_uint_reduced(U256::from_be_byte_array(c.clone()));
let c_scalar = &Scalar::reduce_nonzero(U256::from_be_byte_array(c.to_owned()));
// This value is part of the discrete log equivalence (DLEQ) proof.
let r_sk_c = r + sk * c_scalar;

Expand Down