@@ -68,6 +68,8 @@ use crate::bn::BigNumRef;
68
68
#[ cfg( not( any( boringssl, awslc) ) ) ]
69
69
use crate :: cipher:: CipherRef ;
70
70
use crate :: error:: ErrorStack ;
71
+ #[ cfg( ossl300) ]
72
+ use crate :: lib_ctx:: LibCtxRef ;
71
73
use crate :: md:: MdRef ;
72
74
use crate :: nid:: Nid ;
73
75
use crate :: pkey:: { HasPrivate , HasPublic , Id , PKey , PKeyRef , Params , Private } ;
@@ -84,6 +86,8 @@ use openssl_macros::corresponds;
84
86
use std:: convert:: TryFrom ;
85
87
#[ cfg( ossl320) ]
86
88
use std:: ffi:: CStr ;
89
+ #[ cfg( ossl300) ]
90
+ use std:: ffi:: CString ;
87
91
use std:: ptr;
88
92
89
93
/// HKDF modes of operation.
@@ -159,6 +163,26 @@ impl PkeyCtx<()> {
159
163
Ok ( PkeyCtx :: from_ptr ( ptr) )
160
164
}
161
165
}
166
+
167
+ /// Creates a new pkey context from the algorithm name.
168
+ #[ corresponds( EVP_PKEY_CTX_new_from_name ) ]
169
+ #[ cfg( ossl300) ]
170
+ pub fn new_from_name (
171
+ libctx : Option < & LibCtxRef > ,
172
+ name : & str ,
173
+ propquery : Option < & str > ,
174
+ ) -> Result < Self , ErrorStack > {
175
+ unsafe {
176
+ let propquery = propquery. map ( |s| CString :: new ( s) . unwrap ( ) ) ;
177
+ let name = CString :: new ( name) . unwrap ( ) ;
178
+ let ptr = cvt_p ( ffi:: EVP_PKEY_CTX_new_from_name (
179
+ libctx. map_or ( ptr:: null_mut ( ) , ForeignTypeRef :: as_ptr) ,
180
+ name. as_ptr ( ) ,
181
+ propquery. map_or ( ptr:: null_mut ( ) , |s| s. as_ptr ( ) ) ,
182
+ ) ) ?;
183
+ Ok ( PkeyCtx :: from_ptr ( ptr) )
184
+ }
185
+ }
162
186
}
163
187
164
188
impl < T > PkeyCtxRef < T >
@@ -187,6 +211,26 @@ where
187
211
Ok ( ( ) )
188
212
}
189
213
214
+ /// Prepares the context for signature verification over a message
215
+ /// using the public key.
216
+ #[ cfg( ossl340) ]
217
+ #[ corresponds( EVP_PKEY_verify_message_init ) ]
218
+ #[ inline]
219
+ pub fn verify_message_init (
220
+ & mut self ,
221
+ algo : & mut crate :: signature:: Signature ,
222
+ ) -> Result < ( ) , ErrorStack > {
223
+ unsafe {
224
+ cvt ( ffi:: EVP_PKEY_verify_message_init (
225
+ self . as_ptr ( ) ,
226
+ algo. as_ptr ( ) ,
227
+ ptr:: null ( ) ,
228
+ ) ) ?;
229
+ }
230
+
231
+ Ok ( ( ) )
232
+ }
233
+
190
234
/// Prepares the context for signature recovery using the public key.
191
235
#[ corresponds( EVP_PKEY_verify_recover_init ) ]
192
236
#[ inline]
@@ -319,6 +363,25 @@ where
319
363
Ok ( ( ) )
320
364
}
321
365
366
+ /// Prepares the context for signing a message using the private key.
367
+ #[ cfg( ossl340) ]
368
+ #[ corresponds( EVP_PKEY_sign_message_init ) ]
369
+ #[ inline]
370
+ pub fn sign_message_init (
371
+ & mut self ,
372
+ algo : & mut crate :: signature:: Signature ,
373
+ ) -> Result < ( ) , ErrorStack > {
374
+ unsafe {
375
+ cvt ( ffi:: EVP_PKEY_sign_message_init (
376
+ self . as_ptr ( ) ,
377
+ algo. as_ptr ( ) ,
378
+ ptr:: null ( ) ,
379
+ ) ) ?;
380
+ }
381
+
382
+ Ok ( ( ) )
383
+ }
384
+
322
385
/// Sets the peer key used for secret derivation.
323
386
#[ corresponds( EVP_PKEY_derive_set_peer ) ]
324
387
pub fn derive_set_peer < U > ( & mut self , key : & PKeyRef < U > ) -> Result < ( ) , ErrorStack >
@@ -889,6 +952,20 @@ impl<T> PkeyCtxRef<T> {
889
952
Ok ( ( ) )
890
953
}
891
954
955
+ /// Generates a new public/private keypair.
956
+ ///
957
+ /// New OpenSSL 3.0 function that should do the same thing as keygen()
958
+ #[ corresponds( EVP_PKEY_generate ) ]
959
+ #[ cfg( ossl300) ]
960
+ #[ inline]
961
+ pub fn generate ( & mut self ) -> Result < PKey < Private > , ErrorStack > {
962
+ unsafe {
963
+ let mut key = ptr:: null_mut ( ) ;
964
+ cvt ( ffi:: EVP_PKEY_generate ( self . as_ptr ( ) , & mut key) ) ?;
965
+ Ok ( PKey :: from_ptr ( key) )
966
+ }
967
+ }
968
+
892
969
/// Gets the nonce type for a private key context.
893
970
///
894
971
/// The nonce for DSA and ECDSA can be either random (the default) or deterministic (as defined by RFC 6979).
@@ -913,6 +990,14 @@ impl<T> PkeyCtxRef<T> {
913
990
}
914
991
Ok ( NonceType ( nonce_type) )
915
992
}
993
+
994
+ /// Initializes a conversion from `OsslParam` to `PKey` on given `PkeyCtx`.
995
+ #[ corresponds( EVP_PKEY_fromdata_init ) ]
996
+ #[ cfg( ossl300) ]
997
+ pub fn fromdata_init ( & mut self ) -> Result < ( ) , ErrorStack > {
998
+ unsafe { cvt ( ffi:: EVP_PKEY_fromdata_init ( self . as_ptr ( ) ) ) ? } ;
999
+ Ok ( ( ) )
1000
+ }
916
1001
}
917
1002
918
1003
#[ cfg( test) ]
0 commit comments