@@ -49,6 +49,10 @@ typedef struct {
4949 word32 bufSz ;
5050} hash_ctx_t ;
5151
52+ #ifdef USE_OPENSSL
53+ #include <openssl/sha.h>
54+ #endif
55+
5256/* type: WC_HASH_TYPE_SHA, WC_HASH_TYPE_SHA256, WC_HASH_TYPE_SHA384, etc */
5357/* in: Update (when not NULL) / Final (when NULL) */
5458static int cb_hash (int type , const byte * in , word32 inSz , byte * digest ,
@@ -86,11 +90,34 @@ static int cb_hash(int type, const byte* in, word32 inSz, byte* digest,
8690 hashBuf = (byte * )ctx + sizeof (hash_ctx_t );
8791 hashBufSz = ctx -> bufSz ;
8892 }
93+
94+ #ifdef USE_OPENSSL
95+ switch (hash_type ) {
96+ case WC_HASH_TYPE_SHA :
97+ SHA1 (hashBuf , hashBufSz , digest );
98+ break ;
99+ case WC_HASH_TYPE_SHA224 :
100+ SHA224 (hashBuf , hashBufSz , digest );
101+ break ;
102+ case WC_HASH_TYPE_SHA256 :
103+ SHA256 (hashBuf , hashBufSz , digest );
104+ break ;
105+ case WC_HASH_TYPE_SHA384 :
106+ SHA384 (hashBuf , hashBufSz , digest );
107+ break ;
108+ case WC_HASH_TYPE_SHA512 :
109+ SHA512 (hashBuf , hashBufSz , digest );
110+ break ;
111+ default :
112+ ret = NOT_COMPILED_IN ;
113+ break ;
114+ }
115+ #else
89116 ret = wc_Hash_ex (hash_type ,
90117 hashBuf , hashBufSz ,
91118 digest , wc_HashGetDigestSize (hash_type ),
92119 NULL , INVALID_DEVID );
93-
120+ #endif
94121 if (!(flags & WC_HASH_FLAG_ISCOPY )) {
95122 free (ctx );
96123 * devCtx = NULL ;
@@ -481,6 +508,14 @@ int main(int argc, char** argv)
481508 memset (& myCtx , 0 , sizeof (myCtx ));
482509 myCtx .exampleVar = 1 ;
483510
511+ #if 1
512+ /* register a devID for crypto callbacks */
513+ ret = wc_CryptoCb_RegisterDevice (devId , myCryptoCb , & myCtx );
514+ if (ret != 0 ) {
515+ fprintf (stderr , "ERROR: wc_CryptoCb_RegisterDevice failed %d\n" , ret );
516+ goto exit ;
517+ }
518+ #endif
484519
485520 /* Create and initialize WOLFSSL_CTX */
486521 if ((ctx = wolfSSL_CTX_new (wolfTLSv1_3_server_method ())) == NULL ) {
@@ -489,6 +524,9 @@ int main(int argc, char** argv)
489524 goto exit ;
490525 }
491526
527+ /* register a devID for crypto callbacks */
528+ wolfSSL_CTX_SetDevId (ctx , devId );
529+
492530 /* Load server certificates into WOLFSSL_CTX */
493531 if ((ret = wolfSSL_CTX_use_certificate_file (ctx , CERT_FILE , WOLFSSL_FILETYPE_PEM ))
494532 != WOLFSSL_SUCCESS ) {
@@ -506,20 +544,10 @@ int main(int argc, char** argv)
506544 }
507545
508546#if 0
547+ /* Example: "TLS13-AES256-GCM-SHA384", "TLS13-AES128-GCM-SHA256" or "TLS13-CHACHA20-POLY1305-SHA256" */
509548 wolfSSL_CTX_set_cipher_list (ctx , "TLS13-AES256-GCM-SHA384" );
510549#endif
511550
512- /* register a devID for crypto callbacks */
513- ret = wc_CryptoCb_RegisterDevice (devId , myCryptoCb , & myCtx );
514- if (ret != 0 ) {
515- fprintf (stderr , "ERROR: wc_CryptoCb_RegisterDevice failed %d\n" , ret );
516- goto exit ;
517- }
518-
519- /* register a devID for crypto callbacks */
520- wolfSSL_CTX_SetDevId (ctx , devId );
521-
522-
523551 /* Create a socket that uses an internet IPv4 address,
524552 * Sets the socket to be stream based (TCP),
525553 * 0 means choose the default protocol. */
0 commit comments