A simple CyaSSL-based HMAC-MD5 implementation. Licensed under GPL v2.
Dependents: RFrec_full RFtrans_full
hmac.h
00001 /* hmac.h 00002 * 00003 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd. 00004 * 00005 * This file is part of CyaSSL. 00006 * 00007 * CyaSSL 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 * CyaSSL 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 00020 */ 00021 00022 00023 #ifndef NO_HMAC 00024 00025 #ifndef CTAO_CRYPT_HMAC_H 00026 #define CTAO_CRYPT_HMAC_H 00027 00028 #define NO_SHA256 00029 #define NO_SHA 00030 00031 #ifndef NO_MD5 00032 #include "md5.h" 00033 #endif 00034 00035 #ifndef NO_SHA 00036 #include <cyassl/ctaocrypt/sha.h> 00037 #endif 00038 00039 00040 #ifndef NO_SHA256 00041 #include <cyassl/ctaocrypt/sha256.h> 00042 #endif 00043 00044 #ifdef CYASSL_SHA384 00045 #include <cyassl/ctaocrypt/sha512.h> 00046 #endif 00047 00048 #ifdef HAVE_CAVIUM 00049 #include <cyassl/ctaocrypt/logging.h> 00050 #include "cavium_common.h" 00051 #endif 00052 00053 #ifdef __cplusplus 00054 extern "C" { 00055 #endif 00056 00057 00058 #define CYASSL_HMAC_CAVIUM_MAGIC 0xBEEF0005 00059 00060 enum { 00061 IPAD = 0x36, 00062 OPAD = 0x5C, 00063 #ifdef NO_MD5 00064 MD5 = 0, 00065 #endif 00066 #if defined(CYASSL_SHA384) 00067 INNER_HASH_SIZE = SHA384_DIGEST_SIZE, 00068 HMAC_BLOCK_SIZE = SHA384_BLOCK_SIZE 00069 #elif !defined(NO_SHA256) 00070 INNER_HASH_SIZE = SHA256_DIGEST_SIZE, 00071 HMAC_BLOCK_SIZE = SHA256_BLOCK_SIZE, 00072 SHA384 = 5 00073 #elif !defined(NO_SHA) 00074 INNER_HASH_SIZE = SHA_DIGEST_SIZE, 00075 HMAC_BLOCK_SIZE = SHA_BLOCK_SIZE, 00076 SHA256 = 2, /* hash type unique */ 00077 SHA384 = 5 00078 #else 00079 INNER_HASH_SIZE = MD5_DIGEST_SIZE, 00080 HMAC_BLOCK_SIZE = MD5_BLOCK_SIZE, 00081 SHA = 1, 00082 SHA256 = 2, /* hash type unique */ 00083 SHA384 = 5 00084 #endif 00085 }; 00086 00087 00088 /* hash union */ 00089 typedef union { 00090 #ifndef NO_MD5 00091 Md5 md5; 00092 #endif 00093 #ifndef NO_SHA 00094 Sha sha; 00095 #endif 00096 #ifndef NO_SHA256 00097 Sha256 sha256; 00098 #endif 00099 #ifdef CYASSL_SHA384 00100 Sha384 sha384; 00101 #endif 00102 } Hash; 00103 00104 /* Hmac digest */ 00105 typedef struct Hmac { 00106 Hash hash; 00107 word32 ipad[HMAC_BLOCK_SIZE / sizeof(word32)]; /* same block size all*/ 00108 word32 opad[HMAC_BLOCK_SIZE / sizeof(word32)]; 00109 word32 innerHash[INNER_HASH_SIZE / sizeof(word32)]; /* max size */ 00110 byte macType; /* md5 sha or sha256 */ 00111 byte innerHashKeyed; /* keyed flag */ 00112 #ifdef HAVE_CAVIUM 00113 word16 keyLen; /* hmac key length */ 00114 word16 dataLen; 00115 HashType type; /* hmac key type */ 00116 int devId; /* nitrox device id */ 00117 word32 magic; /* using cavium magic */ 00118 word64 contextHandle; /* nitrox context memory handle */ 00119 byte* data; /* buffered input data for one call */ 00120 #endif 00121 } Hmac; 00122 00123 00124 /* does init */ 00125 CYASSL_API void HmacSetKey(Hmac*, int type, const byte* key, word32 keySz); 00126 CYASSL_API void HmacUpdate(Hmac*, const byte*, word32); 00127 CYASSL_API void HmacFinal(Hmac*, byte*); 00128 00129 #ifdef HAVE_CAVIUM 00130 CYASSL_API int HmacInitCavium(Hmac*, int); 00131 CYASSL_API void HmacFreeCavium(Hmac*); 00132 #endif 00133 00134 00135 #ifdef __cplusplus 00136 } /* extern "C" */ 00137 #endif 00138 00139 #endif /* CTAO_CRYPT_HMAC_H */ 00140 00141 #endif /* NO_HMAC */
Generated on Wed Jul 13 2022 10:25:18 by 1.7.2