Xuyi Wang / wolfcrypt

Dependents:   OS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cmac.h Source File

cmac.h

00001 /* cmac.h
00002  *
00003  * Copyright (C) 2006-2017 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
00020  */
00021 
00022 
00023 #ifndef WOLF_CRYPT_CMAC_H
00024 #define WOLF_CRYPT_CMAC_H
00025 
00026 #include <wolfcrypt/types.h>
00027 #include <wolfcrypt/aes.h>
00028 
00029 #if !defined(NO_AES) && defined(WOLFSSL_CMAC)
00030 
00031 #if defined(HAVE_FIPS) && \
00032     defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
00033     #include <wolfssl/wolfcrypt/fips.h>
00034 #endif /* HAVE_FIPS_VERSION >= 2 */
00035 
00036 #ifdef __cplusplus
00037     extern "C" {
00038 #endif
00039 
00040 /* avoid redefinition of structs */
00041 #if !defined(HAVE_FIPS) || \
00042     (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
00043 
00044 typedef struct Cmac {
00045     Aes aes;
00046     byte buffer[AES_BLOCK_SIZE]; /* partially stored block */
00047     byte digest[AES_BLOCK_SIZE]; /* running digest */
00048     byte k1[AES_BLOCK_SIZE];
00049     byte k2[AES_BLOCK_SIZE];
00050     word32 bufferSz;
00051     word32 totalSz;
00052 } Cmac;
00053 
00054 
00055 typedef enum CmacType {
00056     WC_CMAC_AES = 1
00057 } CmacType;
00058 
00059 #define WC_CMAC_TAG_MAX_SZ AES_BLOCK_SIZE
00060 #define WC_CMAC_TAG_MIN_SZ (AES_BLOCK_SIZE/4)
00061 
00062 #endif /* HAVE_FIPS */
00063 
00064 WOLFSSL_API
00065 int wc_InitCmac(Cmac* cmac,
00066                 const byte* key, word32 keySz,
00067                 int type, void* unused);
00068 WOLFSSL_API
00069 int wc_CmacUpdate(Cmac* cmac,
00070                   const byte* in, word32 inSz);
00071 WOLFSSL_API
00072 int wc_CmacFinal(Cmac* cmac,
00073                  byte* out, word32* outSz);
00074 
00075 WOLFSSL_API
00076 int wc_AesCmacGenerate(byte* out, word32* outSz,
00077                        const byte* in, word32 inSz,
00078                        const byte* key, word32 keySz);
00079 
00080 WOLFSSL_API
00081 int wc_AesCmacVerify(const byte* check, word32 checkSz,
00082                      const byte* in, word32 inSz,
00083                      const byte* key, word32 keySz);
00084 
00085 #ifdef __cplusplus
00086     } /* extern "C" */
00087 #endif
00088 
00089 
00090 #endif /* NO_AES && WOLFSSL_CMAC */
00091 #endif /* WOLF_CRYPT_CMAC_H */
00092 
00093