@@ -11,6 +11,7 @@ use crate::{
11
11
PARSEC_PROVIDER_DFLT_PROPERTIES , PARSEC_PROVIDER_ECDSA_NAME , PARSEC_PROVIDER_RSA_NAME ,
12
12
} ;
13
13
use parsec_client:: core:: interface:: operations:: psa_algorithm:: Algorithm ;
14
+ use parsec_client:: core:: interface:: operations:: psa_algorithm:: Hash ;
14
15
use parsec_client:: core:: interface:: operations:: psa_key_attributes:: { Attributes , EccFamily , Type } ;
15
16
use parsec_openssl2:: types:: VOID_PTR ;
16
17
use parsec_openssl2:: * ;
@@ -77,13 +78,12 @@ fn get_signature_len(key_attrs: Attributes) -> Result<usize, String> {
77
78
}
78
79
79
80
/*
80
- performs the actual signing itself. A previously initialised signature context is passed in the ctx parameter. The data
81
- to be signed is pointed to be the tbs parameter which is tbslen bytes long. Unless sig is NULL, the signature should be
82
- written to the location pointed to by the sig parameter and it should not exceed sigsize bytes in length. The length of
83
- the signature should be written to *siglen. If sig is NULL then the maximum length of the signature should be written
84
- to *siglen.
81
+ implements a "one shot" digest sign operation previously started through
82
+ OSSL_FUNC_signature_digeset_sign_init(). A previously initialised signature
83
+ context is passed in the ctx parameter. The data to be signed is in tbs which
84
+ should be tbslen bytes long.
85
85
*/
86
- unsafe extern "C" fn parsec_provider_signature_sign (
86
+ unsafe extern "C" fn parsec_provider_signature_digest_sign (
87
87
ctx : VOID_PTR ,
88
88
sig : * mut std:: os:: raw:: c_uchar ,
89
89
siglen : * mut std:: os:: raw:: c_uint ,
@@ -100,19 +100,19 @@ unsafe extern "C" fn parsec_provider_signature_sign(
100
100
let sig_ctx = Arc :: from_raw ( ctx as * const RwLock < ParsecProviderSignatureContext > ) ;
101
101
102
102
let reader_sig_ctx = sig_ctx. read ( ) . unwrap ( ) ;
103
- let keyobj = match reader_sig_ctx. keyobj {
103
+ let key_data = match reader_sig_ctx. keyobj {
104
104
None => {
105
105
return Err ( "Key Object not set. This should be done through sign_init()" . into ( ) )
106
106
}
107
107
Some ( ref keyobj) => keyobj. read ( ) . unwrap ( ) ,
108
108
} ;
109
109
110
- let key_name = match keyobj . get_key_name ( ) {
110
+ let key_name = match key_data . get_key_name ( ) {
111
111
None => return Err ( "Key name not set in the Key Object" . into ( ) ) ,
112
112
Some ( ref name) => name,
113
113
} ;
114
114
115
- let key_attributes = keyobj
115
+ let key_attributes = key_data
116
116
. get_provctx ( )
117
117
. get_client ( )
118
118
. key_attributes ( key_name)
@@ -152,10 +152,16 @@ unsafe extern "C" fn parsec_provider_signature_sign(
152
152
}
153
153
} ;
154
154
155
- let sign_res : Vec < u8 > = keyobj
155
+ let hash_res : Vec < u8 > = key_data
156
156
. get_provctx ( )
157
157
. get_client ( )
158
- . psa_sign_hash ( key_name, tbs_slice, sign_algorithm)
158
+ . psa_hash_compute ( Hash :: Sha256 , tbs_slice)
159
+ . map_err ( |e| format ! ( "Parsec Client failed to hash: {:?}" , e) ) ?;
160
+
161
+ let sign_res: Vec < u8 > = key_data
162
+ . get_provctx ( )
163
+ . get_client ( )
164
+ . psa_sign_hash ( key_name, & hash_res, sign_algorithm)
159
165
. map_err ( |e| format ! ( "Parsec Client failed to sign: {:?}" , e) ) ?;
160
166
161
167
if siglength != sign_res. len ( ) {
@@ -176,7 +182,7 @@ unsafe extern "C" fn parsec_provider_signature_sign(
176
182
pub type SignatureNewCtxPtr =
177
183
unsafe extern "C" fn ( VOID_PTR , * const std:: os:: raw:: c_char ) -> VOID_PTR ;
178
184
pub type SignatureFreeCtxPtr = unsafe extern "C" fn ( VOID_PTR ) ;
179
- pub type SignatureSignPtr = unsafe extern "C" fn (
185
+ pub type SignatureDigestSignPtr = unsafe extern "C" fn (
180
186
VOID_PTR ,
181
187
* mut std:: os:: raw:: c_uchar ,
182
188
* mut std:: os:: raw:: c_uint ,
@@ -187,12 +193,18 @@ pub type SignatureSignPtr = unsafe extern "C" fn(
187
193
188
194
const OSSL_FUNC_SIGNATURE_NEWCTX_PTR : SignatureNewCtxPtr = parsec_provider_signature_newctx;
189
195
const OSSL_FUNC_SIGNATURE_FREECTX_PTR : SignatureFreeCtxPtr = parsec_provider_signature_freectx;
190
- const OSSL_FUNC_SIGNATURE_SIGN_PTR : SignatureSignPtr = parsec_provider_signature_sign;
196
+ const OSSL_FUNC_SIGNATURE_DIGEST_SIGN_PTR : SignatureDigestSignPtr =
197
+ parsec_provider_signature_digest_sign;
191
198
192
199
const PARSEC_PROVIDER_SIGN_IMPL : [ OSSL_DISPATCH ; 5 ] = [
193
200
unsafe { ossl_dispatch ! ( OSSL_FUNC_SIGNATURE_NEWCTX , OSSL_FUNC_SIGNATURE_NEWCTX_PTR ) } ,
194
201
unsafe { ossl_dispatch ! ( OSSL_FUNC_SIGNATURE_FREECTX , OSSL_FUNC_SIGNATURE_FREECTX_PTR ) } ,
195
- unsafe { ossl_dispatch ! ( OSSL_FUNC_SIGNATURE_SIGN , OSSL_FUNC_SIGNATURE_SIGN_PTR ) } ,
202
+ unsafe {
203
+ ossl_dispatch ! (
204
+ OSSL_FUNC_SIGNATURE_DIGEST_SIGN ,
205
+ OSSL_FUNC_SIGNATURE_DIGEST_SIGN_PTR
206
+ )
207
+ } ,
196
208
ossl_dispatch ! ( ) ,
197
209
] ;
198
210
0 commit comments