@@ -109,6 +109,8 @@ static void ibmca_signature_ec_free_cb(struct ibmca_op_ctx *ctx)
109
109
if (ctx -> ec .signature .md_ctx != NULL )
110
110
EVP_MD_CTX_free (ctx -> ec .signature .md_ctx );
111
111
ctx -> ec .signature .md_ctx = NULL ;
112
+
113
+ ctx -> ec .signature .nonce_type = 0 ;
112
114
}
113
115
114
116
static int ibmca_signature_ec_dup_cb (const struct ibmca_op_ctx * ctx ,
@@ -142,6 +144,8 @@ static int ibmca_signature_ec_dup_cb(const struct ibmca_op_ctx *ctx,
142
144
}
143
145
}
144
146
147
+ new_ctx -> ec .signature .nonce_type = ctx -> ec .signature .nonce_type ;
148
+
145
149
return 1 ;
146
150
}
147
151
@@ -268,6 +272,10 @@ static int ibmca_signature_ec_sign_fallback(struct ibmca_op_ctx *ctx,
268
272
{
269
273
EVP_PKEY * pkey = NULL ;
270
274
EVP_PKEY_CTX * pctx = NULL ;
275
+ #ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
276
+ OSSL_PARAM params [3 ];
277
+ const char * md_name ;
278
+ #endif
271
279
int rc = 0 ;
272
280
273
281
ibmca_debug_op_ctx (ctx , "ctx: %p key: %p tbslen: %lu sig: %p siglen: %lu" ,
@@ -296,6 +304,35 @@ static int ibmca_signature_ec_sign_fallback(struct ibmca_op_ctx *ctx,
296
304
goto out ;
297
305
}
298
306
307
+ #ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
308
+ ibmca_debug_op_ctx (ctx , "nonce_type: %u" , ctx -> ec .signature .nonce_type );
309
+
310
+ if (ctx -> ec .signature .nonce_type != 0 ) {
311
+ md_name = EVP_MD_get0_name (ctx -> ec .signature .md );
312
+ if (md_name == NULL ) {
313
+ put_error_op_ctx (ctx , IBMCA_ERR_INVALID_PARAM ,
314
+ "Digest must be set when using deterministic "
315
+ "signatures" );
316
+ goto out ;
317
+ }
318
+
319
+ ibmca_debug_op_ctx (ctx , "md_name: %s" , md_name );
320
+
321
+ params [0 ] = OSSL_PARAM_construct_utf8_string (
322
+ OSSL_SIGNATURE_PARAM_DIGEST ,
323
+ (char * )md_name , strlen (md_name ));
324
+ params [1 ] = OSSL_PARAM_construct_uint (OSSL_SIGNATURE_PARAM_NONCE_TYPE ,
325
+ & ctx -> ec .signature .nonce_type );
326
+ params [2 ] = OSSL_PARAM_construct_end ();
327
+
328
+ if (EVP_PKEY_CTX_set_params (pctx , params ) != 1 ) {
329
+ put_error_op_ctx (ctx , IBMCA_ERR_INTERNAL_ERROR ,
330
+ "EVP_PKEY_CTX_set_params failed" );
331
+ goto out ;
332
+ }
333
+ }
334
+ #endif
335
+
299
336
if (EVP_PKEY_sign (pctx , sig , siglen , tbs , tbslen ) != 1 ) {
300
337
put_error_op_ctx (ctx , IBMCA_ERR_INTERNAL_ERROR ,
301
338
"EVP_PKEY_sign failed" );
@@ -365,7 +402,7 @@ static int ibmca_signature_ec_sign(void *vctx,
365
402
goto out ;
366
403
}
367
404
368
- if (ctx -> key -> ec .fallback .d != NULL ) {
405
+ if (ctx -> key -> ec .fallback .d != NULL || ctx -> ec . signature . nonce_type != 0 ) {
369
406
rc = ibmca_signature_ec_sign_fallback (ctx , sig , siglen , tbs , tbslen );
370
407
if (rc != 1 ) {
371
408
ibmca_debug_op_ctx (ctx ,
@@ -701,7 +738,8 @@ static int ibmca_signature_ec_get_ctx_params(void *vctx,
701
738
#ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
702
739
/* OSSL_SIGNATURE_PARAM_NONCE_TYPE */
703
740
rc = ibmca_param_build_set_uint (ctx -> provctx , NULL , params ,
704
- OSSL_SIGNATURE_PARAM_NONCE_TYPE , 0 );
741
+ OSSL_SIGNATURE_PARAM_NONCE_TYPE ,
742
+ ctx -> ec .signature .nonce_type );
705
743
if (rc == 0 )
706
744
return 0 ;
707
745
#endif
@@ -716,9 +754,6 @@ static int ibmca_signature_ec_set_ctx_params(void *vctx,
716
754
const OSSL_PARAM * p ;
717
755
const char * name , * props = NULL ;
718
756
size_t md_size ;
719
- #ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
720
- unsigned int nonce_type ;
721
- #endif
722
757
int rc ;
723
758
724
759
if (ctx == NULL )
@@ -760,15 +795,10 @@ static int ibmca_signature_ec_set_ctx_params(void *vctx,
760
795
#ifdef OSSL_SIGNATURE_PARAM_NONCE_TYPE
761
796
/* OSSL_SIGNATURE_PARAM_NONCE_TYPE */
762
797
rc = ibmca_param_get_uint (ctx -> provctx , params ,
763
- OSSL_SIGNATURE_PARAM_NONCE_TYPE , & nonce_type );
798
+ OSSL_SIGNATURE_PARAM_NONCE_TYPE ,
799
+ & ctx -> ec .signature .nonce_type );
764
800
if (rc == 0 )
765
801
return 0 ;
766
- /* Only allow nonce_type = 0 = random K */
767
- if (nonce_type != 0 ) {
768
- put_error_op_ctx (ctx , IBMCA_ERR_INVALID_PARAM ,
769
- "Deterministic signature is not supported" );
770
- return 0 ;
771
- }
772
802
#endif
773
803
774
804
return 1 ;
0 commit comments