@@ -10,13 +10,12 @@ use std::collections::BTreeMap;
10
10
use frost_rerandomized:: RandomizedCiphersuite ;
11
11
use k256:: {
12
12
elliptic_curve:: {
13
- bigint:: { U256 } ,
13
+ bigint:: U256 ,
14
14
group:: prime:: PrimeCurveAffine ,
15
15
hash2curve:: { hash_to_field, ExpandMsgXmd } ,
16
- sec1:: { FromEncodedPoint , ToEncodedPoint } ,
17
- Field as FFField , PrimeField ,
18
- ScalarPrimitive ,
19
16
point:: { AffineCoordinates , DecompactPoint } ,
17
+ sec1:: { FromEncodedPoint , ToEncodedPoint } ,
18
+ Field as FFField , PrimeField , ScalarPrimitive ,
20
19
} ,
21
20
AffinePoint , ProjectivePoint , Scalar ,
22
21
} ;
@@ -29,8 +28,9 @@ use frost_core as frost;
29
28
mod tests;
30
29
31
30
// Re-exports in our public API
32
- pub use frost_core:: { serde, Ciphersuite , Field , FieldError , Group , GroupError ,
33
- Element , Challenge } ;
31
+ pub use frost_core:: {
32
+ serde, Challenge , Ciphersuite , Element , Field , FieldError , Group , GroupError ,
33
+ } ;
34
34
35
35
pub use rand_core;
36
36
@@ -190,8 +190,7 @@ pub struct Secp256K1Sha256;
190
190
191
191
/// Digest the hasher to a Scalar
192
192
pub fn hasher_to_scalar ( hasher : Sha256 ) -> Scalar {
193
- let sp = ScalarPrimitive :: new ( U256 :: from_be_slice ( & hasher. finalize ( ) ) )
194
- . unwrap ( ) ;
193
+ let sp = ScalarPrimitive :: new ( U256 :: from_be_slice ( & hasher. finalize ( ) ) ) . unwrap ( ) ;
195
194
Scalar :: from ( & sp)
196
195
}
197
196
@@ -209,7 +208,7 @@ pub fn tagged_hash(tag: &str) -> Sha256 {
209
208
/// Create a BIP341 compliant taproot tweak
210
209
pub fn tweak (
211
210
public_key : & <<Secp256K1Sha256 as Ciphersuite >:: Group as Group >:: Element ,
212
- merkle_root : & [ u8 ]
211
+ merkle_root : & [ u8 ] ,
213
212
) -> Scalar {
214
213
let mut hasher = tagged_hash ( "TapTweak" ) ;
215
214
hasher. update ( public_key. to_affine ( ) . x ( ) ) ;
@@ -305,8 +304,7 @@ impl Ciphersuite for Secp256K1Sha256 {
305
304
}
306
305
307
306
/// Generates the challenge as is required for Schnorr signatures.
308
- fn challenge ( R : & Element < S > , verifying_key : & VerifyingKey , msg : & [ u8 ] ) -> Challenge < S >
309
- {
307
+ fn challenge ( R : & Element < S > , verifying_key : & VerifyingKey , msg : & [ u8 ] ) -> Challenge < S > {
310
308
let mut preimage = vec ! [ ] ;
311
309
let tweaked_public_key = tweaked_public_key ( & verifying_key. to_element ( ) , & [ ] ) ;
312
310
preimage. extend_from_slice ( & R . to_affine ( ) . x ( ) ) ;
@@ -325,8 +323,7 @@ impl Ciphersuite for Secp256K1Sha256 {
325
323
z : <<Self :: Group as Group >:: Field as Field >:: Scalar ,
326
324
challenge : & Challenge < S > ,
327
325
verifying_key : & Element < S > ,
328
- ) -> <<Self :: Group as Group >:: Field as Field >:: Scalar
329
- {
326
+ ) -> <<Self :: Group as Group >:: Field as Field >:: Scalar {
330
327
let t = tweak ( & verifying_key, & [ ] ) ;
331
328
z + t * challenge. clone ( ) . to_scalar ( )
332
329
}
@@ -339,8 +336,7 @@ impl Ciphersuite for Secp256K1Sha256 {
339
336
lambda_i : <<Self :: Group as Group >:: Field as Field >:: Scalar ,
340
337
key_package : & frost:: keys:: KeyPackage < S > ,
341
338
challenge : Challenge < S > ,
342
- ) -> round2:: SignatureShare
343
- {
339
+ ) -> round2:: SignatureShare {
344
340
let mut sn = signer_nonces. clone ( ) ;
345
341
if group_commitment. y_is_odd ( ) {
346
342
sn. negate_nonces ( ) ;
@@ -351,13 +347,7 @@ impl Ciphersuite for Secp256K1Sha256 {
351
347
kp. negate_signing_share ( ) ;
352
348
}
353
349
354
- frost:: round2:: compute_signature_share (
355
- & sn,
356
- binding_factor,
357
- lambda_i,
358
- & kp,
359
- challenge,
360
- )
350
+ frost:: round2:: compute_signature_share ( & sn, binding_factor, lambda_i, & kp, challenge)
361
351
}
362
352
363
353
/// calculate tweaked public key
@@ -368,27 +358,23 @@ impl Ciphersuite for Secp256K1Sha256 {
368
358
}
369
359
370
360
/// calculate tweaked R
371
- fn tweaked_R (
372
- R : & <Self :: Group as Group >:: Element ,
373
- ) -> <Self :: Group as Group >:: Element {
361
+ fn tweaked_R ( R : & <Self :: Group as Group >:: Element ) -> <Self :: Group as Group >:: Element {
374
362
AffinePoint :: decompact ( & R . to_affine ( ) . x ( ) ) . unwrap ( ) . into ( )
375
363
}
376
364
377
365
/// tweaked secret
378
366
fn tweaked_secret_key (
379
367
secret : <<Self :: Group as Group >:: Field as Field >:: Scalar ,
380
368
public : & Element < Self > ,
381
- ) -> <<Self :: Group as Group >:: Field as Field >:: Scalar
382
- {
369
+ ) -> <<Self :: Group as Group >:: Field as Field >:: Scalar {
383
370
tweaked_secret_key ( secret, & public, & [ ] )
384
371
}
385
372
386
373
/// tweaked nonce
387
374
fn tweaked_nonce (
388
375
nonce : <<Self :: Group as Group >:: Field as Field >:: Scalar ,
389
376
R : & Element < Self > ,
390
- ) -> <<Self :: Group as Group >:: Field as Field >:: Scalar
391
- {
377
+ ) -> <<Self :: Group as Group >:: Field as Field >:: Scalar {
392
378
if R . to_affine ( ) . y_is_odd ( ) . into ( ) {
393
379
-nonce
394
380
} else {
@@ -399,8 +385,7 @@ impl Ciphersuite for Secp256K1Sha256 {
399
385
fn tweaked_group_commitment_share (
400
386
group_commitment_share : & Element < Self > ,
401
387
group_commitment : & Element < Self > ,
402
- ) -> Element < Self >
403
- {
388
+ ) -> Element < Self > {
404
389
if group_commitment. to_affine ( ) . y_is_odd ( ) . into ( ) {
405
390
-group_commitment_share
406
391
} else {
@@ -411,8 +396,7 @@ impl Ciphersuite for Secp256K1Sha256 {
411
396
fn tweaked_verifying_share (
412
397
verifying_share : & <Self :: Group as Group >:: Element ,
413
398
verifying_key : & <Self :: Group as Group >:: Element ,
414
- ) -> <Self :: Group as Group >:: Element
415
- {
399
+ ) -> <Self :: Group as Group >:: Element {
416
400
let mut vs = verifying_share. clone ( ) ;
417
401
if verifying_key. to_affine ( ) . y_is_odd ( ) . into ( ) {
418
402
vs = -vs;
0 commit comments