@@ -147,85 +147,84 @@ int wc_HmacSizeByType(int type)
147147
148148 return ret ;
149149}
150+
150151static int HmacKeyInitHash (wc_HmacHash * hash , int type , void * heap , int devId )
151152{
152153 int ret = 0 ;
153154
154- switch ((enum wc_HashType )type ) {
155- #ifndef WOLFSSL_NO_SHA224
156- case WC_HASH_TYPE_SHA224 :
155+ switch (type ) {
156+ #ifndef NO_MD5
157+ case WC_MD5 :
158+ ret = wc_InitMd5_ex (& hash -> md5 , heap , devId );
159+ break ;
160+ #endif /* !NO_MD5 */
161+
162+ #ifndef NO_SHA
163+ case WC_SHA :
164+ ret = wc_InitSha_ex (& hash -> sha , heap , devId );
165+ break ;
166+ #endif /* !NO_SHA */
167+
168+ #ifdef WOLFSSL_SHA224
169+ case WC_SHA224 :
157170 ret = wc_InitSha224_ex (& hash -> sha224 , heap , devId );
158171 break ;
159- #endif
160- #ifdef WOLFSSL_SHA3
161- case WC_HASH_TYPE_SHA3_224 :
162- ret = wc_InitSha3_224 (& hash -> sha3 , heap , devId );
172+ #endif /* WOLFSSL_SHA224 */
173+
174+ #ifndef NO_SHA256
175+ case WC_SHA256 :
176+ ret = wc_InitSha256_ex (& hash -> sha256 , heap , devId );
163177 break ;
164- case WC_HASH_TYPE_SHA3_256 :
165- ret = wc_InitSha3_256 (& hash -> sha3 , heap , devId );
178+ #endif /* !NO_SHA256 */
179+
180+ #ifdef WOLFSSL_SHA384
181+ case WC_SHA384 :
182+ ret = wc_InitSha384_ex (& hash -> sha384 , heap , devId );
166183 break ;
167- case WC_HASH_TYPE_SHA3_384 :
168- ret = wc_InitSha3_384 (& hash -> sha3 , heap , devId );
184+ #endif /* WOLFSSL_SHA384 */
185+ #ifdef WOLFSSL_SHA512
186+ case WC_SHA512 :
187+ ret = wc_InitSha512_ex (& hash -> sha512 , heap , devId );
169188 break ;
170- case WC_HASH_TYPE_SHA3_512 :
171- ret = wc_InitSha3_512 (& hash -> sha3 , heap , devId );
189+ #endif /* WOLFSSL_SHA512 */
190+
191+ #ifdef WOLFSSL_SHA3
192+ #ifndef WOLFSSL_NOSHA3_224
193+ case WC_SHA3_224 :
194+ ret = wc_InitSha3_224 (& hash -> sha3 , heap , devId );
172195 break ;
173196 #endif
174- #ifndef WOLFSSL_NOSHA512_224
175- case WC_HASH_TYPE_SHA512_224 :
176- ret = BAD_FUNC_ARG ;
197+ #ifndef WOLFSSL_NOSHA3_256
198+ case WC_SHA3_256 :
199+ ret = wc_InitSha3_256 ( & hash -> sha3 , heap , devId ) ;
177200 break ;
178201 #endif
179- #ifndef WOLFSSL_NOSHA512_256
180- case WC_HASH_TYPE_SHA512_256 :
181- ret = BAD_FUNC_ARG ;
202+ #ifndef WOLFSSL_NOSHA3_384
203+ case WC_SHA3_384 :
204+ ret = wc_InitSha3_384 ( & hash -> sha3 , heap , devId ) ;
182205 break ;
183206 #endif
184- #ifdef WOLFSSL_SHAKE128
185- case WC_HASH_TYPE_SHAKE128 :
186- ret = BAD_FUNC_ARG ;
207+ #ifndef WOLFSSL_NOSHA3_512
208+ case WC_SHA3_512 :
209+ ret = wc_InitSha3_512 ( & hash -> sha3 , heap , devId ) ;
187210 break ;
188211 #endif
189- #ifdef WOLFSSL_SHAKE256
190- case WC_HASH_TYPE_SHAKE256 :
191- ret = BAD_FUNC_ARG ;
192- break ;
193212 #endif
213+
194214 #ifdef WOLFSSL_SM3
195- case WC_HASH_TYPE_SM3 :
215+ case WC_SM3 :
196216 ret = wc_InitSm3 (& hash -> sm3 , heap , devId );
197217 break ;
198218 #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 ;
219+
222220 default :
223221 ret = BAD_FUNC_ARG ;
224222 break ;
225223 }
226224
227225 return ret ;
228226}
227+
229228int _InitHmac (Hmac * hmac , int type , void * heap )
230229{
231230 int ret ;
@@ -310,7 +309,7 @@ static int HmacKeyCopyHash(byte macType, wc_HmacHash* src, wc_HmacHash* dst)
310309 ret = wc_Sha3_512_Copy (& src -> sha3 , & dst -> sha3 );
311310 break ;
312311 #endif
313- #endif /* WOLFSSL_SHA3 */ /
312+ #endif /* WOLFSSL_SHA3 */
314313
315314 #ifdef WOLFSSL_SM3
316315 case WC_SM3 :
@@ -325,83 +324,83 @@ static int HmacKeyCopyHash(byte macType, wc_HmacHash* src, wc_HmacHash* dst)
325324 return ret ;
326325}
327326#endif
327+
328328static int HmacKeyHashUpdate (byte macType , wc_HmacHash * hash , byte * pad )
329329{
330330 int ret = 0 ;
331- switch ((enum wc_HashType )macType ) {
332- #ifndef WOLFSSL_NO_SHA224
333- case WC_HASH_TYPE_SHA224 :
334- ret = wc_Sha224Update (& hash -> sha224 , pad , WC_SHA224_BLOCK_SIZE );
331+
332+ switch (macType ) {
333+ #ifndef NO_MD5
334+ case WC_MD5 :
335+ ret = wc_Md5Update (& hash -> md5 , pad , WC_MD5_BLOCK_SIZE );
335336 break ;
336- #endif
337- #ifdef WOLFSSL_SHA3
338- case WC_HASH_TYPE_SHA3_224 :
339- ret = wc_Sha3_224_Update (& hash -> sha3 , pad , WC_SHA3_224_BLOCK_SIZE );
337+ #endif /* !NO_MD5 */
338+
339+ #ifndef NO_SHA
340+ case WC_SHA :
341+ ret = wc_ShaUpdate (& hash -> sha , pad , WC_SHA_BLOCK_SIZE );
340342 break ;
341- case WC_HASH_TYPE_SHA3_256 :
342- ret = wc_Sha3_256_Update (& hash -> sha3 , pad , WC_SHA3_256_BLOCK_SIZE );
343+ #endif /* !NO_SHA */
344+
345+ #ifdef WOLFSSL_SHA224
346+ case WC_SHA224 :
347+ ret = wc_Sha224Update (& hash -> sha224 , pad , WC_SHA224_BLOCK_SIZE );
343348 break ;
344- case WC_HASH_TYPE_SHA3_384 :
345- ret = wc_Sha3_384_Update (& hash -> sha3 , pad , WC_SHA3_384_BLOCK_SIZE );
349+ #endif /* WOLFSSL_SHA224 */
350+ #ifndef NO_SHA256
351+ case WC_SHA256 :
352+ ret = wc_Sha256Update (& hash -> sha256 , pad , WC_SHA256_BLOCK_SIZE );
346353 break ;
347- case WC_HASH_TYPE_SHA3_512 :
348- ret = wc_Sha3_512_Update (& hash -> sha3 , pad , WC_SHA3_512_BLOCK_SIZE );
354+ #endif /* !NO_SHA256 */
355+
356+ #ifdef WOLFSSL_SHA384
357+ case WC_SHA384 :
358+ ret = wc_Sha384Update (& hash -> sha384 , pad , WC_SHA384_BLOCK_SIZE );
349359 break ;
350- #endif
351- #ifndef WOLFSSL_NOSHA512_224
352- case WC_HASH_TYPE_SHA512_224 :
353- ret = BAD_FUNC_ARG ;
360+ #endif /* WOLFSSL_SHA384 */
361+ #ifdef WOLFSSL_SHA512
362+ case WC_SHA512 :
363+ ret = wc_Sha512Update (& hash -> sha512 , pad , WC_SHA512_BLOCK_SIZE );
364+ break ;
365+ #endif /* WOLFSSL_SHA512 */
366+
367+ #ifdef WOLFSSL_SHA3
368+ #ifndef WOLFSSL_NOSHA3_224
369+ case WC_SHA3_224 :
370+ ret = wc_Sha3_224_Update (& hash -> sha3 , pad , WC_SHA3_224_BLOCK_SIZE );
354371 break ;
355372 #endif
356- #ifndef WOLFSSL_NOSHA512_256
357- case WC_HASH_TYPE_SHA512_256 :
358- ret = BAD_FUNC_ARG ;
373+ #ifndef WOLFSSL_NOSHA3_256
374+ case WC_SHA3_256 :
375+ ret = wc_Sha3_256_Update ( & hash -> sha3 , pad , WC_SHA3_256_BLOCK_SIZE ) ;
359376 break ;
360377 #endif
361- #ifdef WOLFSSL_SHAKE128
362- case WC_HASH_TYPE_SHAKE128 :
363- ret = BAD_FUNC_ARG ;
378+ #ifndef WOLFSSL_NOSHA3_384
379+ case WC_SHA3_384 :
380+ ret = wc_Sha3_384_Update ( & hash -> sha3 , pad , WC_SHA3_384_BLOCK_SIZE ) ;
364381 break ;
365382 #endif
366- #ifdef WOLFSSL_SHAKE256
367- case WC_HASH_TYPE_SHAKE256 :
368- ret = BAD_FUNC_ARG ;
383+ #ifndef WOLFSSL_NOSHA3_512
384+ case WC_SHA3_512 :
385+ ret = wc_Sha3_512_Update ( & hash -> sha3 , pad , WC_SHA3_512_BLOCK_SIZE ) ;
369386 break ;
370387 #endif
388+ #endif /* WOLFSSL_SHA3 */
389+
371390 #ifdef WOLFSSL_SM3
372- case WC_HASH_TYPE_SM3 :
391+ case WC_SM3 :
373392 ret = wc_Sm3Update (& hash -> sm3 , pad , WC_SM3_BLOCK_SIZE );
374393 break ;
375394 #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 ;
395+
399396 default :
400- ret = BAD_FUNC_ARG ;
401397 break ;
402398 }
399+
403400 return ret ;
404401}
402+
403+
405404int wc_HmacSetKey_ex (Hmac * hmac , int type , const byte * key , word32 length ,
406405 int allowFlag )
407406{
0 commit comments