@@ -7,6 +7,7 @@ use common::init_pins;
77use cryptoki:: context:: Function ;
88use cryptoki:: error:: { Error , RvError } ;
99use cryptoki:: mechanism:: aead:: GcmParams ;
10+ use cryptoki:: mechanism:: eddsa:: { EddsaParams , EddsaSignatureScheme } ;
1011use cryptoki:: mechanism:: rsa:: { PkcsMgfType , PkcsOaepParams , PkcsOaepSource } ;
1112use cryptoki:: mechanism:: { Mechanism , MechanismType } ;
1213use cryptoki:: object:: {
@@ -72,7 +73,7 @@ fn sign_verify() -> TestResult {
7273
7374#[ test]
7475#[ serial]
75- fn sign_verify_ed25519 ( ) -> TestResult {
76+ fn sign_verify_eddsa ( ) -> TestResult {
7677 let ( pkcs11, slot) = init_pins ( ) ;
7778
7879 let session = pkcs11. open_rw_session ( slot) ?;
@@ -99,9 +100,111 @@ fn sign_verify_ed25519() -> TestResult {
99100
100101 let data = [ 0xFF , 0x55 , 0xDD ] ;
101102
102- let signature = session . sign ( & Mechanism :: Eddsa , private , & data ) ? ;
103+ let scheme = EddsaSignatureScheme :: Pure ;
103104
104- session. verify ( & Mechanism :: Eddsa , public, & data, & signature) ?;
105+ let params = EddsaParams :: new ( scheme) ;
106+
107+ let signature = session. sign ( & Mechanism :: Eddsa ( params) , private, & data) ?;
108+
109+ session. verify ( & Mechanism :: Eddsa ( params) , public, & data, & signature) ?;
110+
111+ session. destroy_object ( public) ?;
112+ session. destroy_object ( private) ?;
113+
114+ Ok ( ( ) )
115+ }
116+
117+ #[ test]
118+ #[ serial]
119+ fn sign_verify_eddsa_with_ed25519_schemes ( ) -> TestResult {
120+ let ( pkcs11, slot) = init_pins ( ) ;
121+
122+ let session = pkcs11. open_rw_session ( slot) ?;
123+
124+ session. login ( UserType :: User , Some ( & AuthPin :: new ( USER_PIN . into ( ) ) ) ) ?;
125+
126+ let mechanism = Mechanism :: EccEdwardsKeyPairGen ;
127+
128+ let pub_key_template = vec ! [
129+ Attribute :: Token ( true ) ,
130+ Attribute :: Private ( false ) ,
131+ Attribute :: Verify ( true ) ,
132+ // Ed25519 OID
133+ // See: https://github.com/opendnssec/SoftHSMv2/blob/ac70dc398b236e4522101930e790008936489e2d/src/lib/test/SignVerifyTests.cpp#L173
134+ Attribute :: EcParams ( vec![
135+ 0x13 , 0x0c , 0x65 , 0x64 , 0x77 , 0x61 , 0x72 , 0x64 , 0x73 , 0x32 , 0x35 , 0x35 , 0x31 , 0x39 ,
136+ ] ) ,
137+ ] ;
138+
139+ let priv_key_template = vec ! [ Attribute :: Token ( true ) ] ;
140+
141+ let ( public, private) =
142+ session. generate_key_pair ( & mechanism, & pub_key_template, & priv_key_template) ?;
143+
144+ let data = [ 0xFF , 0x55 , 0xDD ] ;
145+
146+ let schemes = [
147+ EddsaSignatureScheme :: Ed25519 ,
148+ EddsaSignatureScheme :: Ed25519ctx ( b"context" ) ,
149+ EddsaSignatureScheme :: Ed25519ph ( & [ ] ) ,
150+ EddsaSignatureScheme :: Ed25519ph ( b"context" ) ,
151+ ] ;
152+
153+ for scheme in schemes {
154+ let params = EddsaParams :: new ( scheme) ;
155+
156+ let signature = session. sign ( & Mechanism :: Eddsa ( params) , private, & data) ?;
157+
158+ session. verify ( & Mechanism :: Eddsa ( params) , public, & data, & signature) ?;
159+ }
160+
161+ session. destroy_object ( public) ?;
162+ session. destroy_object ( private) ?;
163+
164+ Ok ( ( ) )
165+ }
166+
167+ #[ test]
168+ #[ serial]
169+ fn sign_verify_eddsa_with_ed448_schemes ( ) -> TestResult {
170+ let ( pkcs11, slot) = init_pins ( ) ;
171+
172+ let session = pkcs11. open_rw_session ( slot) ?;
173+
174+ session. login ( UserType :: User , Some ( & AuthPin :: new ( USER_PIN . into ( ) ) ) ) ?;
175+
176+ let mechanism = Mechanism :: EccEdwardsKeyPairGen ;
177+
178+ let pub_key_template = vec ! [
179+ Attribute :: Token ( true ) ,
180+ Attribute :: Private ( false ) ,
181+ Attribute :: Verify ( true ) ,
182+ // Ed448 OID
183+ // See: https://github.com/opendnssec/SoftHSMv2/blob/ac70dc398b236e4522101930e790008936489e2d/src/lib/test/SignVerifyTests.cpp#L173
184+ Attribute :: EcParams ( vec![
185+ 0x13 , 0x0a , 0x65 , 0x64 , 0x77 , 0x61 , 0x72 , 0x64 , 0x73 , 0x34 , 0x34 , 0x38 ,
186+ ] ) ,
187+ ] ;
188+
189+ let priv_key_template = vec ! [ Attribute :: Token ( true ) ] ;
190+
191+ let ( public, private) =
192+ session. generate_key_pair ( & mechanism, & pub_key_template, & priv_key_template) ?;
193+
194+ let data = [ 0xFF , 0x55 , 0xDD ] ;
195+
196+ let schemes = [
197+ EddsaSignatureScheme :: Ed448 ( b"context" ) ,
198+ EddsaSignatureScheme :: Ed448ph ( b"context" ) ,
199+ ] ;
200+
201+ for scheme in schemes {
202+ let params = EddsaParams :: new ( scheme) ;
203+
204+ let signature = session. sign ( & Mechanism :: Eddsa ( params) , private, & data) ?;
205+
206+ session. verify ( & Mechanism :: Eddsa ( params) , public, & data, & signature) ?;
207+ }
105208
106209 session. destroy_object ( public) ?;
107210 session. destroy_object ( private) ?;
0 commit comments