/* wolfcaam_hmac.c * * Copyright (C) 2006-2026 wolfSSL Inc. * * This file is part of wolfSSL. * * wolfSSL is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * wolfSSL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ #ifdef HAVE_CONFIG_H #include #endif #include #if defined(WOLFSSL_CAAM) && !defined(NO_HMAC) && defined(WOLFSSL_CAAM_HMAC) #include #include #ifdef NO_INLINE #include #else #define WOLFSSL_MISC_INCLUDED #include #endif #include #include #include #if defined(WOLFSSL_CAAM_DEBUG) || defined(WOLFSSL_CAAM_PRINT) #include #endif #if defined(WOLFSSL_DEVCRYPTO_HMAC) #include /* HSM lib does not support HMAC with QXP board, use devcrypto instead */ int wc_CAAM_Hmac(Hmac* hmac, int macType, const byte* msg, int msgSz, byte* digest) { int ret = 0; if (hmac->ctx.cfd == -1 && hmac->keyLen > 0) { ret = wc_DevCrypto_HmacSetKey(hmac, macType, hmac->keyRaw, hmac->keyLen); if (ret != 0) { WOLFSSL_MSG("Error with set key"); if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E)) { ret = CRYPTOCB_UNAVAILABLE; /* that hash type is not supported*/ } } } if (ret == 0 && msgSz > 0) { ret = wc_DevCrypto_HmacUpdate(hmac, msg, msgSz); if (ret != 0) { WOLFSSL_MSG("Issue with hmac update"); } } if (ret == 0 && digest != NULL) { ret = wc_DevCrypto_HmacFinal(hmac, digest); if (ret != 0) { WOLFSSL_MSG("Issue with hmac final"); } else { wc_DevCrypto_HmacFree(hmac); } } return ret; } #else int wc_CAAM_Hmac(Hmac* hmac, int macType, const byte* msg, int msgSz, byte* digest) { (void)hmac; (void)macType; (void)msg; (void)msgSz; (void)digest; return CRYPTOCB_UNAVAILABLE; } #endif /* WOLFSSL_DEVCRYPTO_HMAC */ #endif