@@ -5,34 +5,74 @@ import (
55 "testing"
66)
77
8- func TestGOST256VerificationMatchesRFC7091 ( t * testing. T ) {
9- testCurve := newCurve ([6 ]string {
8+ func rfc7091TestCurve () curve {
9+ return newCurve ([6 ]string {
1010 "7" ,
1111 "5FBFF498AA938CE739B8E022FBAFEF40563F6E6A3472FC2A514C0CE9DAE23B7E" ,
1212 "8000000000000000000000000000000000000000000000000000000000000431" ,
1313 "8000000000000000000000000000000150FE8A1892976154C59CFC193ACCF5B3" ,
1414 "2" ,
1515 "8E2A8A0E65147D4BD6316030E16D19C85C97F0A9CA267122B96ABBCEA7E8FC8" ,
1616 })
17- decode := func ( name , value string ) [] byte {
18- t . Helper ()
19- decoded , err := hex . DecodeString ( value )
20- if err != nil {
21- t . Fatalf ( "decode %s: %v" , name , err )
22- }
23- return decoded
17+ }
18+
19+ func decodeGOSTVector ( t * testing. T , name , value string ) [] byte {
20+ t . Helper ()
21+ decoded , err := hex . DecodeString ( value )
22+ if err != nil {
23+ t . Fatalf ( "decode %s: %v" , name , err )
2424 }
25+ return decoded
26+ }
2527
28+ func TestGOST256VerificationMatchesRFC7091 (t * testing.T ) {
2629 // RFC 7091, Section 7, publishes the curve, digest scalar, public key,
2730 // and signature independently of this implementation.
28- public := decode ( "public key" ,
31+ public := decodeGOSTVector ( t , "public key" ,
2932 "7F2B49E270DB6D90D8595BEC458B50C58585BA1D4E9B788F6689DBD8E56FD80B" +
3033 "26F1B489D6701DD185C8413A977B3CBBAF64D1C593D26627DFFB101A87FF77DA" )
31- digest := decode ( "digest" , "2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5" )
32- r := decode ( "r" , "41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493" )
33- s := decode ( "s" , "01456C64BA4642A1653C235A98A60249BCD6D3F746B631DF928014F6C5BF9C40" )
34+ digest := decodeGOSTVector ( t , "digest" , "2DFBC1B372D89A1188C09C52E0EEC61FCE52032AB1022E8E67ECE6672B043EE5" )
35+ r := decodeGOSTVector ( t , "r" , "41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493" )
36+ s := decodeGOSTVector ( t , "s" , "01456C64BA4642A1653C235A98A60249BCD6D3F746B631DF928014F6C5BF9C40" )
3437
35- if ! testCurve .verify (public , digest , r , s ) {
38+ if ! rfc7091TestCurve () .verify (public , digest , r , s ) {
3639 t .Fatal ("GOST R 34.10-2012 RFC 7091 vector verification failed" )
3740 }
3841}
42+
43+ func TestGOSTZeroDigestScalarBecomesOne (t * testing.T ) {
44+ public := decodeGOSTVector (t , "public key" ,
45+ "7F2B49E270DB6D90D8595BEC458B50C58585BA1D4E9B788F6689DBD8E56FD80B" +
46+ "26F1B489D6701DD185C8413A977B3CBBAF64D1C593D26627DFFB101A87FF77DA" )
47+ digest := make ([]byte , 32 )
48+ r := decodeGOSTVector (t , "r" , "41AA28D2F1AB148280CD9ED56FEDA41974053554A42767B83AD043FD39DC0493" )
49+ // RFC 7091's published d, k, and r with the Section 6.1 e = 1 rule.
50+ s := decodeGOSTVector (t , "s" , "2101DCCCABE45DF9FEB8BAE91FB31A8872687A181C23587C3274CB3F88B4650C" )
51+
52+ if ! rfc7091TestCurve ().verify (public , digest , r , s ) {
53+ t .Fatal ("GOST R 34.10-2012 zero digest scalar verification failed" )
54+ }
55+ }
56+
57+ func TestGOSTRejectsOffCurvePublicKey (t * testing.T ) {
58+ public := make ([]byte , 64 )
59+ digest := make ([]byte , 32 )
60+ r := make ([]byte , 32 )
61+ s := make ([]byte , 32 )
62+ digest [31 ], r [31 ], s [31 ] = 1 , 1 , 1
63+
64+ if curve256 .verify (public , digest , r , s ) {
65+ t .Fatal ("GOST verification accepted the off-curve public point (0, 0)" )
66+ }
67+ }
68+
69+ func TestGOSTConfiguredBasePointsAreValid (t * testing.T ) {
70+ for name , configured := range map [string ]curve {"256" : curve256 , "512" : curve512 } {
71+ t .Run (name , func (t * testing.T ) {
72+ base := point {x : configured .gx , y : configured .gy }
73+ if ! configured .validPoint (base ) {
74+ t .Fatal ("configured base point is not in the declared subgroup" )
75+ }
76+ })
77+ }
78+ }
0 commit comments