wolfSSL SSL/TLS library, support up to TLS1.3
Dependents: CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more
wolfssl/wolfcrypt/cmac.h@17:a5f916481144, 2020-06-05 (annotated)
- Committer:
- wolfSSL
- Date:
- Fri Jun 05 00:11:07 2020 +0000
- Revision:
- 17:a5f916481144
- Parent:
- 16:8e0d178b1d1e
wolfSSL 4.4.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 15:117db924cf7c | 1 | /* cmac.h |
wolfSSL | 15:117db924cf7c | 2 | * |
wolfSSL | 16:8e0d178b1d1e | 3 | * Copyright (C) 2006-2020 wolfSSL Inc. |
wolfSSL | 15:117db924cf7c | 4 | * |
wolfSSL | 15:117db924cf7c | 5 | * This file is part of wolfSSL. |
wolfSSL | 15:117db924cf7c | 6 | * |
wolfSSL | 15:117db924cf7c | 7 | * wolfSSL is free software; you can redistribute it and/or modify |
wolfSSL | 15:117db924cf7c | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 15:117db924cf7c | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 15:117db924cf7c | 10 | * (at your option) any later version. |
wolfSSL | 15:117db924cf7c | 11 | * |
wolfSSL | 15:117db924cf7c | 12 | * wolfSSL is distributed in the hope that it will be useful, |
wolfSSL | 15:117db924cf7c | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 15:117db924cf7c | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 15:117db924cf7c | 15 | * GNU General Public License for more details. |
wolfSSL | 15:117db924cf7c | 16 | * |
wolfSSL | 15:117db924cf7c | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 15:117db924cf7c | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 15:117db924cf7c | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
wolfSSL | 15:117db924cf7c | 20 | */ |
wolfSSL | 15:117db924cf7c | 21 | |
wolfSSL | 15:117db924cf7c | 22 | |
wolfSSL | 15:117db924cf7c | 23 | #ifndef WOLF_CRYPT_CMAC_H |
wolfSSL | 15:117db924cf7c | 24 | #define WOLF_CRYPT_CMAC_H |
wolfSSL | 15:117db924cf7c | 25 | |
wolfSSL | 15:117db924cf7c | 26 | #include <wolfssl/wolfcrypt/types.h> |
wolfSSL | 15:117db924cf7c | 27 | #include <wolfssl/wolfcrypt/aes.h> |
wolfSSL | 15:117db924cf7c | 28 | |
wolfSSL | 15:117db924cf7c | 29 | #if !defined(NO_AES) && defined(WOLFSSL_CMAC) |
wolfSSL | 15:117db924cf7c | 30 | |
wolfSSL | 15:117db924cf7c | 31 | #if defined(HAVE_FIPS) && \ |
wolfSSL | 15:117db924cf7c | 32 | defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2) |
wolfSSL | 15:117db924cf7c | 33 | #include <wolfssl/wolfcrypt/fips.h> |
wolfSSL | 15:117db924cf7c | 34 | #endif /* HAVE_FIPS_VERSION >= 2 */ |
wolfSSL | 15:117db924cf7c | 35 | |
wolfSSL | 15:117db924cf7c | 36 | #ifdef __cplusplus |
wolfSSL | 15:117db924cf7c | 37 | extern "C" { |
wolfSSL | 15:117db924cf7c | 38 | #endif |
wolfSSL | 15:117db924cf7c | 39 | |
wolfSSL | 15:117db924cf7c | 40 | /* avoid redefinition of structs */ |
wolfSSL | 15:117db924cf7c | 41 | #if !defined(HAVE_FIPS) || \ |
wolfSSL | 15:117db924cf7c | 42 | (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) |
wolfSSL | 15:117db924cf7c | 43 | |
wolfSSL | 16:8e0d178b1d1e | 44 | #ifndef WC_CMAC_TYPE_DEFINED |
wolfSSL | 16:8e0d178b1d1e | 45 | typedef struct Cmac Cmac; |
wolfSSL | 16:8e0d178b1d1e | 46 | #define WC_CMAC_TYPE_DEFINED |
wolfSSL | 16:8e0d178b1d1e | 47 | #endif |
wolfSSL | 16:8e0d178b1d1e | 48 | struct Cmac { |
wolfSSL | 15:117db924cf7c | 49 | Aes aes; |
wolfSSL | 15:117db924cf7c | 50 | byte buffer[AES_BLOCK_SIZE]; /* partially stored block */ |
wolfSSL | 15:117db924cf7c | 51 | byte digest[AES_BLOCK_SIZE]; /* running digest */ |
wolfSSL | 15:117db924cf7c | 52 | byte k1[AES_BLOCK_SIZE]; |
wolfSSL | 15:117db924cf7c | 53 | byte k2[AES_BLOCK_SIZE]; |
wolfSSL | 15:117db924cf7c | 54 | word32 bufferSz; |
wolfSSL | 15:117db924cf7c | 55 | word32 totalSz; |
wolfSSL | 16:8e0d178b1d1e | 56 | }; |
wolfSSL | 16:8e0d178b1d1e | 57 | |
wolfSSL | 15:117db924cf7c | 58 | |
wolfSSL | 15:117db924cf7c | 59 | |
wolfSSL | 15:117db924cf7c | 60 | typedef enum CmacType { |
wolfSSL | 15:117db924cf7c | 61 | WC_CMAC_AES = 1 |
wolfSSL | 15:117db924cf7c | 62 | } CmacType; |
wolfSSL | 15:117db924cf7c | 63 | |
wolfSSL | 15:117db924cf7c | 64 | #define WC_CMAC_TAG_MAX_SZ AES_BLOCK_SIZE |
wolfSSL | 15:117db924cf7c | 65 | #define WC_CMAC_TAG_MIN_SZ (AES_BLOCK_SIZE/4) |
wolfSSL | 15:117db924cf7c | 66 | |
wolfSSL | 15:117db924cf7c | 67 | #endif /* HAVE_FIPS */ |
wolfSSL | 15:117db924cf7c | 68 | |
wolfSSL | 15:117db924cf7c | 69 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 70 | int wc_InitCmac(Cmac* cmac, |
wolfSSL | 15:117db924cf7c | 71 | const byte* key, word32 keySz, |
wolfSSL | 15:117db924cf7c | 72 | int type, void* unused); |
wolfSSL | 15:117db924cf7c | 73 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 74 | int wc_CmacUpdate(Cmac* cmac, |
wolfSSL | 15:117db924cf7c | 75 | const byte* in, word32 inSz); |
wolfSSL | 15:117db924cf7c | 76 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 77 | int wc_CmacFinal(Cmac* cmac, |
wolfSSL | 15:117db924cf7c | 78 | byte* out, word32* outSz); |
wolfSSL | 15:117db924cf7c | 79 | |
wolfSSL | 15:117db924cf7c | 80 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 81 | int wc_AesCmacGenerate(byte* out, word32* outSz, |
wolfSSL | 15:117db924cf7c | 82 | const byte* in, word32 inSz, |
wolfSSL | 15:117db924cf7c | 83 | const byte* key, word32 keySz); |
wolfSSL | 15:117db924cf7c | 84 | |
wolfSSL | 15:117db924cf7c | 85 | WOLFSSL_API |
wolfSSL | 15:117db924cf7c | 86 | int wc_AesCmacVerify(const byte* check, word32 checkSz, |
wolfSSL | 15:117db924cf7c | 87 | const byte* in, word32 inSz, |
wolfSSL | 15:117db924cf7c | 88 | const byte* key, word32 keySz); |
wolfSSL | 15:117db924cf7c | 89 | |
wolfSSL | 15:117db924cf7c | 90 | #ifdef __cplusplus |
wolfSSL | 15:117db924cf7c | 91 | } /* extern "C" */ |
wolfSSL | 15:117db924cf7c | 92 | #endif |
wolfSSL | 15:117db924cf7c | 93 | |
wolfSSL | 15:117db924cf7c | 94 | |
wolfSSL | 15:117db924cf7c | 95 | #endif /* NO_AES && WOLFSSL_CMAC */ |
wolfSSL | 15:117db924cf7c | 96 | #endif /* WOLF_CRYPT_CMAC_H */ |
wolfSSL | 15:117db924cf7c | 97 | |
wolfSSL | 15:117db924cf7c | 98 |