@@ -147,39 +147,17 @@ int wc_HmacSizeByType(int type)
147147
148148 return ret ;
149149}
150-
151150static int HmacKeyInitHash (wc_HmacHash * hash , int type , void * heap , int devId )
152151{
153152 int ret = 0 ;
154153
155154 switch ((enum wc_HashType )type ) {
156- case WC_HASH_TYPE_NONE :
157- case WC_HASH_TYPE_MD2 :
158- case WC_HASH_TYPE_MD4 :
159- case WC_HASH_TYPE_MD5_SHA :
160- case WC_HASH_TYPE_BLAKE2B :
161- case WC_HASH_TYPE_BLAKE2S :
162- ret = BAD_FUNC_ARG ;
163- break ;
164-
165- case WC_HASH_TYPE_MD5 :
166- ret = wc_InitMd5_ex (& hash -> md5 , heap , devId );
167- break ;
168- case WC_HASH_TYPE_SHA :
169- ret = wc_InitSha_ex (& hash -> sha , heap , devId );
170- break ;
155+ #ifndef WOLFSSL_NO_SHA224
171156 case WC_HASH_TYPE_SHA224 :
172157 ret = wc_InitSha224_ex (& hash -> sha224 , heap , devId );
173158 break ;
174- case WC_HASH_TYPE_SHA256 :
175- ret = wc_InitSha256_ex (& hash -> sha256 , heap , devId );
176- break ;
177- case WC_HASH_TYPE_SHA384 :
178- ret = wc_InitSha384_ex (& hash -> sha384 , heap , devId );
179- break ;
180- case WC_HASH_TYPE_SHA512 :
181- ret = wc_InitSha512_ex (& hash -> sha512 , heap , devId );
182- break ;
159+ #endif
160+ #ifdef WOLFSSL_SHA3
183161 case WC_HASH_TYPE_SHA3_224 :
184162 ret = wc_InitSha3_224 (& hash -> sha3 , heap , devId );
185163 break ;
@@ -192,6 +170,7 @@ static int HmacKeyInitHash(wc_HmacHash* hash, int type, void* heap, int devId)
192170 case WC_HASH_TYPE_SHA3_512 :
193171 ret = wc_InitSha3_512 (& hash -> sha3 , heap , devId );
194172 break ;
173+ #endif
195174 #ifndef WOLFSSL_NOSHA512_224
196175 case WC_HASH_TYPE_SHA512_224 :
197176 ret = BAD_FUNC_ARG ;
@@ -217,6 +196,29 @@ static int HmacKeyInitHash(wc_HmacHash* hash, int type, void* heap, int devId)
217196 ret = wc_InitSm3 (& hash -> sm3 , heap , devId );
218197 break ;
219198 #endif
199+ case WC_HASH_TYPE_NONE :
200+ case WC_HASH_TYPE_MD2 :
201+ case WC_HASH_TYPE_MD4 :
202+ case WC_HASH_TYPE_MD5_SHA :
203+ case WC_HASH_TYPE_BLAKE2B :
204+ case WC_HASH_TYPE_BLAKE2S :
205+ ret = BAD_FUNC_ARG ;
206+ break ;
207+ case WC_HASH_TYPE_MD5 :
208+ ret = wc_InitMd5_ex (& hash -> md5 , heap , devId );
209+ break ;
210+ case WC_HASH_TYPE_SHA :
211+ ret = wc_InitSha_ex (& hash -> sha , heap , devId );
212+ break ;
213+ case WC_HASH_TYPE_SHA256 :
214+ ret = wc_InitSha256_ex (& hash -> sha256 , heap , devId );
215+ break ;
216+ case WC_HASH_TYPE_SHA384 :
217+ ret = wc_InitSha384_ex (& hash -> sha384 , heap , devId );
218+ break ;
219+ case WC_HASH_TYPE_SHA512 :
220+ ret = wc_InitSha512_ex (& hash -> sha512 , heap , devId );
221+ break ;
220222 default :
221223 ret = BAD_FUNC_ARG ;
222224 break ;
@@ -327,33 +329,12 @@ static int HmacKeyHashUpdate(byte macType, wc_HmacHash* hash, byte* pad)
327329{
328330 int ret = 0 ;
329331 switch ((enum wc_HashType )macType ) {
330- case WC_HASH_TYPE_NONE :
331- case WC_HASH_TYPE_MD2 :
332- case WC_HASH_TYPE_MD4 :
333- case WC_HASH_TYPE_MD5_SHA :
334- case WC_HASH_TYPE_BLAKE2B :
335- case WC_HASH_TYPE_BLAKE2S :
336- ret = BAD_FUNC_ARG ;
337- break ;
338-
339- case WC_HASH_TYPE_MD5 :
340- ret = wc_Md5Update (& hash -> md5 , pad , WC_MD5_BLOCK_SIZE );
341- break ;
342- case WC_HASH_TYPE_SHA :
343- ret = wc_ShaUpdate (& hash -> sha , pad , WC_SHA_BLOCK_SIZE );
344- break ;
332+ #ifndef WOLFSSL_NO_SHA224
345333 case WC_HASH_TYPE_SHA224 :
346334 ret = wc_Sha224Update (& hash -> sha224 , pad , WC_SHA224_BLOCK_SIZE );
347335 break ;
348- case WC_HASH_TYPE_SHA256 :
349- ret = wc_Sha256Update (& hash -> sha256 , pad , WC_SHA256_BLOCK_SIZE );
350- break ;
351- case WC_HASH_TYPE_SHA384 :
352- ret = wc_Sha384Update (& hash -> sha384 , pad , WC_SHA384_BLOCK_SIZE );
353- break ;
354- case WC_HASH_TYPE_SHA512 :
355- ret = wc_Sha512Update (& hash -> sha512 , pad , WC_SHA512_BLOCK_SIZE );
356- break ;
336+ #endif
337+ #ifdef WOLFSSL_SHA3
357338 case WC_HASH_TYPE_SHA3_224 :
358339 ret = wc_Sha3_224_Update (& hash -> sha3 , pad , WC_SHA3_224_BLOCK_SIZE );
359340 break ;
@@ -366,6 +347,7 @@ static int HmacKeyHashUpdate(byte macType, wc_HmacHash* hash, byte* pad)
366347 case WC_HASH_TYPE_SHA3_512 :
367348 ret = wc_Sha3_512_Update (& hash -> sha3 , pad , WC_SHA3_512_BLOCK_SIZE );
368349 break ;
350+ #endif
369351 #ifndef WOLFSSL_NOSHA512_224
370352 case WC_HASH_TYPE_SHA512_224 :
371353 ret = BAD_FUNC_ARG ;
@@ -391,6 +373,29 @@ static int HmacKeyHashUpdate(byte macType, wc_HmacHash* hash, byte* pad)
391373 ret = wc_Sm3Update (& hash -> sm3 , pad , WC_SM3_BLOCK_SIZE );
392374 break ;
393375 #endif
376+ case WC_HASH_TYPE_NONE :
377+ case WC_HASH_TYPE_MD2 :
378+ case WC_HASH_TYPE_MD4 :
379+ case WC_HASH_TYPE_MD5_SHA :
380+ case WC_HASH_TYPE_BLAKE2B :
381+ case WC_HASH_TYPE_BLAKE2S :
382+ ret = BAD_FUNC_ARG ;
383+ break ;
384+ case WC_HASH_TYPE_MD5 :
385+ ret = wc_Md5Update (& hash -> md5 , pad , WC_MD5_BLOCK_SIZE );
386+ break ;
387+ case WC_HASH_TYPE_SHA :
388+ ret = wc_ShaUpdate (& hash -> sha , pad , WC_SHA_BLOCK_SIZE );
389+ break ;
390+ case WC_HASH_TYPE_SHA256 :
391+ ret = wc_Sha256Update (& hash -> sha256 , pad , WC_SHA256_BLOCK_SIZE );
392+ break ;
393+ case WC_HASH_TYPE_SHA384 :
394+ ret = wc_Sha384Update (& hash -> sha384 , pad , WC_SHA384_BLOCK_SIZE );
395+ break ;
396+ case WC_HASH_TYPE_SHA512 :
397+ ret = wc_Sha512Update (& hash -> sha512 , pad , WC_SHA512_BLOCK_SIZE );
398+ break ;
394399 default :
395400 ret = BAD_FUNC_ARG ;
396401 break ;
0 commit comments