@@ -51,8 +51,10 @@ typedef struct wp_EcdsaSigCtx {
5151
5252 /** wolfSSL hash object. */
5353 wc_HashAlg hash ;
54+ #if LIBWOLFSSL_VERSION_HEX < 0x05007004
5455 /** Hash algorithm to use on data to be signed. */
5556 enum wc_HashType hashType ;
57+ #endif
5658
5759 /** Property query string. */
5860 char * propQuery ;
@@ -140,16 +142,21 @@ static wp_EcdsaSigCtx* wp_ecdsa_dupctx(wp_EcdsaSigCtx* srcCtx)
140142 ok = 0 ;
141143 }
142144
143- if (ok && (!wp_hash_copy (& srcCtx -> hash , & dstCtx -> hash ,
144- srcCtx -> hashType ))) {
145+ if (ok && (!wp_hash_copy (& srcCtx -> hash , & dstCtx -> hash
146+ #if LIBWOLFSSL_VERSION_HEX < 0x05007004
147+ ,srcCtx -> hashType
148+ #endif
149+ ))) {
145150 ok = 0 ;
146151 }
147152 if (ok && (!wp_ecc_up_ref (srcCtx -> ecc ))) {
148153 ok = 0 ;
149154 }
150155 if (ok ) {
151156 dstCtx -> ecc = srcCtx -> ecc ;
157+ #if LIBWOLFSSL_VERSION_HEX < 0x05007004
152158 dstCtx -> hashType = srcCtx -> hashType ;
159+ #endif
153160 dstCtx -> op = srcCtx -> op ;
154161 XMEMCPY (dstCtx -> mdName , srcCtx -> mdName , sizeof (srcCtx -> mdName ));
155162 }
@@ -249,8 +256,14 @@ static int wp_ecdsa_sign(wp_EcdsaSigCtx *ctx, unsigned char *sig,
249256 * sigLen = wc_ecc_sig_size (wp_ecc_get_key (ctx -> ecc ));
250257 }
251258 else {
259+ #if LIBWOLFSSL_VERSION_HEX >= 0x05007004
260+ if ((ctx -> hash .type != WC_HASH_TYPE_NONE ) &&
261+ (tbsLen != (size_t )wc_HashGetDigestSize (ctx -> hash .type )))
262+ #else
252263 if ((ctx -> hashType != WC_HASH_TYPE_NONE ) &&
253- (tbsLen != (size_t )wc_HashGetDigestSize (ctx -> hashType ))) {
264+ (tbsLen != (size_t )wc_HashGetDigestSize (ctx -> hashType )))
265+ #endif
266+ {
254267 ok = 0 ;
255268 }
256269 else if ((ok = wp_ecc_check_usage (ctx -> ecc ))) {
@@ -410,17 +423,33 @@ static int wp_ecdsa_setup_md(wp_EcdsaSigCtx *ctx, const char *mdName,
410423 if (mdName != NULL ) {
411424 int rc ;
412425
426+ #if LIBWOLFSSL_VERSION_HEX >= 0x05007004
427+ ctx -> hash .type = wp_name_to_wc_hash_type (ctx -> libCtx , mdName , mdProps );
428+ if ((ctx -> hash .type == WC_HASH_TYPE_NONE ) ||
429+ (ctx -> hash .type == WC_HASH_TYPE_MD5 ))
430+ #else
413431 ctx -> hashType = wp_name_to_wc_hash_type (ctx -> libCtx , mdName , mdProps );
414432 if ((ctx -> hashType == WC_HASH_TYPE_NONE ) ||
415- (ctx -> hashType == WC_HASH_TYPE_MD5 )) {
433+ (ctx -> hashType == WC_HASH_TYPE_MD5 ))
434+ #endif
435+ {
416436 ok = 0 ;
417437 }
418- if ((ctx -> hashType == WC_HASH_TYPE_SHA ) && (op == EVP_PKEY_OP_SIGN )) {
438+ #if LIBWOLFSSL_VERSION_HEX >= 0x05007004
439+ if ((ctx -> hash .type == WC_HASH_TYPE_SHA ) && (op == EVP_PKEY_OP_SIGN ))
440+ #else
441+ if ((ctx -> hashType == WC_HASH_TYPE_SHA ) && (op == EVP_PKEY_OP_SIGN ))
442+ #endif
443+ {
419444 ok = 0 ;
420445 }
421446
422447 if (ok ) {
448+ #if LIBWOLFSSL_VERSION_HEX >= 0x05007004
449+ rc = wc_HashInit_ex (& ctx -> hash , ctx -> hash .type , NULL , INVALID_DEVID );
450+ #else
423451 rc = wc_HashInit_ex (& ctx -> hash , ctx -> hashType , NULL , INVALID_DEVID );
452+ #endif
424453 if (rc != 0 ) {
425454 ok = 0 ;
426455 }
@@ -475,7 +504,13 @@ static int wp_ecdsa_digest_signverify_update(wp_EcdsaSigCtx *ctx,
475504 const unsigned char * data , size_t dataLen )
476505{
477506 int ok = 1 ;
478- int rc = wc_HashUpdate (& ctx -> hash , ctx -> hashType , data , (word32 )dataLen );
507+ int rc = wc_HashUpdate (& ctx -> hash ,
508+ #if LIBWOLFSSL_VERSION_HEX >= 0x05007004
509+ ctx -> hash .type ,
510+ #else
511+ ctx -> hashType ,
512+ #endif
513+ data , (word32 )dataLen );
479514 if (rc != 0 ) {
480515 ok = 0 ;
481516 }
@@ -533,15 +568,27 @@ static int wp_ecdsa_digest_sign_final(wp_EcdsaSigCtx *ctx, unsigned char *sig,
533568 ok = 0 ;
534569 }
535570 else if (sig != NULL ) {
536- int rc = wc_HashFinal (& ctx -> hash , ctx -> hashType , digest );
571+ int rc = wc_HashFinal (& ctx -> hash ,
572+ #if LIBWOLFSSL_VERSION_HEX >= 0x05007004
573+ ctx -> hash .type ,
574+ #else
575+ ctx -> hashType ,
576+ #endif
577+ digest );
537578 if (rc != 0 ) {
538579 ok = 0 ;
539580 }
540581 }
541582
542583 if (ok ) {
543584 ok = wp_ecdsa_sign (ctx , sig , sigLen , sigSize , digest ,
544- wc_HashGetDigestSize (ctx -> hashType ));
585+ wc_HashGetDigestSize (
586+ #if LIBWOLFSSL_VERSION_HEX >= 0x05007004
587+ ctx -> hash .type
588+ #else
589+ ctx -> hashType
590+ #endif
591+ ));
545592 }
546593
547594 WOLFPROV_LEAVE (WP_LOG_KE , __FILE__ ":" WOLFPROV_STRINGIZE (__LINE__ ), ok );
@@ -594,15 +641,26 @@ static int wp_ecdsa_digest_verify_final(wp_EcdsaSigCtx *ctx, unsigned char *sig,
594641 ok = 0 ;
595642 }
596643 else {
597- int rc = wc_HashFinal (& ctx -> hash , ctx -> hashType , digest );
644+ int rc = wc_HashFinal (& ctx -> hash ,
645+ #if LIBWOLFSSL_VERSION_HEX >= 0x05007004
646+ ctx -> hash .type ,
647+ #else
648+ ctx -> hashType ,
649+ #endif
650+ digest );
598651 if (rc != 0 ) {
599652 ok = 0 ;
600653 }
601654 }
602655
603656 if (ok ) {
604657 ok = wp_ecdsa_verify (ctx ,sig , sigLen , digest ,
605- wc_HashGetDigestSize (ctx -> hashType ));
658+ #if LIBWOLFSSL_VERSION_HEX >= 0x05007004
659+ wc_HashGetDigestSize (ctx -> hash .type )
660+ #else
661+ wc_HashGetDigestSize (ctx -> hashType )
662+ #endif
663+ );
606664 }
607665
608666 WOLFPROV_LEAVE (WP_LOG_KE , __FILE__ ":" WOLFPROV_STRINGIZE (__LINE__ ), ok );
0 commit comments