@@ -167,7 +167,7 @@ impl TryFrom<&DecafPointBytes> for DecafPoint {
167167}
168168
169169impl Group for DecafPoint {
170- type Scalar = DecafScalar ;
170+ type Scalar = Scalar ;
171171
172172 fn try_from_rng < R > ( rng : & mut R ) -> Result < Self , R :: Error >
173173 where
@@ -239,9 +239,9 @@ impl CofactorGroup for DecafPoint {
239239
240240impl PrimeGroup for DecafPoint { }
241241
242- impl < const N : usize > LinearCombination < [ ( DecafPoint , DecafScalar ) ; N ] > for DecafPoint { }
242+ impl < const N : usize > LinearCombination < [ ( DecafPoint , Scalar ) ; N ] > for DecafPoint { }
243243
244- impl LinearCombination < [ ( DecafPoint , DecafScalar ) ] > for DecafPoint { }
244+ impl LinearCombination < [ ( DecafPoint , Scalar ) ] > for DecafPoint { }
245245
246246impl CurveGroup for DecafPoint {
247247 type AffineRepr = DecafAffinePoint ;
@@ -599,7 +599,10 @@ impl From<NonIdentity<DecafPoint>> for DecafPoint {
599599mod test {
600600 use super :: * ;
601601 use crate :: TWISTED_EDWARDS_BASE_POINT ;
602+ use elliptic_curve:: PrimeField ;
603+ use elliptic_curve:: consts:: U64 ;
602604 use hash2curve:: ExpandMsgXof ;
605+ use hex_literal:: hex;
603606 use sha3:: Shake256 ;
604607
605608 #[ test]
@@ -761,6 +764,72 @@ mod test {
761764 assert_ne ! ( point, DecafPoint :: GENERATOR ) ;
762765 }
763766
767+ #[ test]
768+ fn scalar_hash ( ) {
769+ let msg = b"hello world" ;
770+ let dst = b"decaf448_XOF:SHAKE256_D448MAP_RO_" ;
771+ let res =
772+ hash2curve:: hash_to_scalar :: < Decaf448 , ExpandMsgXof < Shake256 > , U64 > ( & [ msg] , & [ dst] )
773+ . unwrap ( ) ;
774+ let expected: [ u8 ; 56 ] = hex_literal:: hex!(
775+ "55e7b59aa035db959409c6b69b817a18c8133d9ad06687665f5720672924da0a84eab7fee415ef13e7aaebdd227291ee8e156f32c507ad2e"
776+ ) ;
777+ assert_eq ! ( res. to_repr( ) , Array :: from( expected) ) ;
778+ }
779+
780+ /// Taken from <https://www.rfc-editor.org/rfc/rfc9497.html#name-decaf448-shake256>.
781+ #[ test]
782+ fn hash_to_scalar_voprf ( ) {
783+ struct TestVector {
784+ dst : & ' static [ u8 ] ,
785+ sk_sm : & ' static [ u8 ] ,
786+ }
787+
788+ const KEY_INFO : & [ u8 ] = b"test key" ;
789+ const SEED : & [ u8 ] =
790+ & hex ! ( "a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3a3" ) ;
791+
792+ const TEST_VECTORS : & [ TestVector ] = & [
793+ TestVector {
794+ dst : b"DeriveKeyPairOPRFV1-\x00 -decaf448-SHAKE256" ,
795+ sk_sm : & hex ! (
796+ "e8b1375371fd11ebeb224f832dcc16d371b4188951c438f751425699ed29ecc80c6c13e558ccd67634fd82eac94aa8d1f0d7fee990695d1e"
797+ ) ,
798+ } ,
799+ TestVector {
800+ dst : b"DeriveKeyPairOPRFV1-\x01 -decaf448-SHAKE256" ,
801+ sk_sm : & hex ! (
802+ "e3c01519a076a326a0eb566343e9b21c115fa18e6e85577ddbe890b33104fcc2835ddfb14a928dc3f5d79b936e17c76b99e0bf6a1680930e"
803+ ) ,
804+ } ,
805+ TestVector {
806+ dst : b"DeriveKeyPairOPRFV1-\x02 -decaf448-SHAKE256" ,
807+ sk_sm : & hex ! (
808+ "792a10dcbd3ba4a52a054f6f39186623208695301e7adb9634b74709ab22de402990eb143fd7c67ac66be75e0609705ecea800992aac8e19"
809+ ) ,
810+ } ,
811+ ] ;
812+
813+ let key_info_len = u16:: try_from ( KEY_INFO . len ( ) ) . unwrap ( ) . to_be_bytes ( ) ;
814+
815+ ' outer: for test_vector in TEST_VECTORS {
816+ for counter in 0_u8 ..=u8:: MAX {
817+ let scalar = hash2curve:: hash_to_scalar :: < Decaf448 , ExpandMsgXof < Shake256 > , U64 > (
818+ & [ SEED , & key_info_len, KEY_INFO , & counter. to_be_bytes ( ) ] ,
819+ & [ test_vector. dst ] ,
820+ )
821+ . unwrap ( ) ;
822+
823+ if !bool:: from ( scalar. is_zero ( ) ) {
824+ assert_eq ! ( scalar. to_bytes( ) . as_slice( ) , test_vector. sk_sm) ;
825+ continue ' outer;
826+ }
827+ }
828+
829+ panic ! ( "deriving key failed" ) ;
830+ }
831+ }
832+
764833 // TODO: uncomment once elliptic-curve-tools is updated to match elliptic-curve 0.14
765834 // #[test]
766835 // fn test_sum_of_products() { use elliptic_curve_tools::SumOfProducts; let values = [ (Scalar::from(8u8), DecafPoint::GENERATOR), (Scalar::from(9u8), DecafPoint::GENERATOR), (Scalar::from(10u8), DecafPoint::GENERATOR), (Scalar::from(11u8), DecafPoint::GENERATOR), (Scalar::from(12u8), DecafPoint::GENERATOR), ]; let expected = DecafPoint::GENERATOR * Scalar::from(50u8); let result = DecafPoint::sum_of_products(&values); assert_eq!(result, expected); }
0 commit comments