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