A library for setting up Secure Socket Layer (SSL) connections and verifying remote hosts using certificates. Contains only the source files for mbed platform implementation of the library.

Dependents:   HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL

Committer:
Vanger
Date:
Mon Jan 19 21:45:42 2015 +0000
Revision:
0:b86d15c6ba29
Updated CyaSSL Library to 3.3.0. Changed Settings and functions to be implemented for mbed platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vanger 0:b86d15c6ba29 1 /* hmac.h
Vanger 0:b86d15c6ba29 2 *
Vanger 0:b86d15c6ba29 3 * Copyright (C) 2006-2014 wolfSSL Inc.
Vanger 0:b86d15c6ba29 4 *
Vanger 0:b86d15c6ba29 5 * This file is part of CyaSSL.
Vanger 0:b86d15c6ba29 6 *
Vanger 0:b86d15c6ba29 7 * CyaSSL is free software; you can redistribute it and/or modify
Vanger 0:b86d15c6ba29 8 * it under the terms of the GNU General Public License as published by
Vanger 0:b86d15c6ba29 9 * the Free Software Foundation; either version 2 of the License, or
Vanger 0:b86d15c6ba29 10 * (at your option) any later version.
Vanger 0:b86d15c6ba29 11 *
Vanger 0:b86d15c6ba29 12 * CyaSSL is distributed in the hope that it will be useful,
Vanger 0:b86d15c6ba29 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Vanger 0:b86d15c6ba29 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Vanger 0:b86d15c6ba29 15 * GNU General Public License for more details.
Vanger 0:b86d15c6ba29 16 *
Vanger 0:b86d15c6ba29 17 * You should have received a copy of the GNU General Public License
Vanger 0:b86d15c6ba29 18 * along with this program; if not, write to the Free Software
Vanger 0:b86d15c6ba29 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Vanger 0:b86d15c6ba29 20 */
Vanger 0:b86d15c6ba29 21
Vanger 0:b86d15c6ba29 22
Vanger 0:b86d15c6ba29 23 #ifndef NO_HMAC
Vanger 0:b86d15c6ba29 24
Vanger 0:b86d15c6ba29 25 #ifndef CTAO_CRYPT_HMAC_H
Vanger 0:b86d15c6ba29 26 #define CTAO_CRYPT_HMAC_H
Vanger 0:b86d15c6ba29 27
Vanger 0:b86d15c6ba29 28 #include <cyassl/ctaocrypt/types.h>
Vanger 0:b86d15c6ba29 29
Vanger 0:b86d15c6ba29 30 #ifndef NO_MD5
Vanger 0:b86d15c6ba29 31 #include <cyassl/ctaocrypt/md5.h>
Vanger 0:b86d15c6ba29 32 #endif
Vanger 0:b86d15c6ba29 33
Vanger 0:b86d15c6ba29 34 #ifndef NO_SHA
Vanger 0:b86d15c6ba29 35 #include <cyassl/ctaocrypt/sha.h>
Vanger 0:b86d15c6ba29 36 #endif
Vanger 0:b86d15c6ba29 37
Vanger 0:b86d15c6ba29 38 #ifndef NO_SHA256
Vanger 0:b86d15c6ba29 39 #include <cyassl/ctaocrypt/sha256.h>
Vanger 0:b86d15c6ba29 40 #endif
Vanger 0:b86d15c6ba29 41
Vanger 0:b86d15c6ba29 42 #ifdef CYASSL_SHA512
Vanger 0:b86d15c6ba29 43 #include <cyassl/ctaocrypt/sha512.h>
Vanger 0:b86d15c6ba29 44 #endif
Vanger 0:b86d15c6ba29 45
Vanger 0:b86d15c6ba29 46 #ifdef HAVE_BLAKE2
Vanger 0:b86d15c6ba29 47 #include <cyassl/ctaocrypt/blake2.h>
Vanger 0:b86d15c6ba29 48 #endif
Vanger 0:b86d15c6ba29 49
Vanger 0:b86d15c6ba29 50 #ifdef HAVE_CAVIUM
Vanger 0:b86d15c6ba29 51 #include <cyassl/ctaocrypt/logging.h>
Vanger 0:b86d15c6ba29 52 #include "cavium_common.h"
Vanger 0:b86d15c6ba29 53 #endif
Vanger 0:b86d15c6ba29 54
Vanger 0:b86d15c6ba29 55 #ifdef __cplusplus
Vanger 0:b86d15c6ba29 56 extern "C" {
Vanger 0:b86d15c6ba29 57 #endif
Vanger 0:b86d15c6ba29 58
Vanger 0:b86d15c6ba29 59
Vanger 0:b86d15c6ba29 60 #define CYASSL_HMAC_CAVIUM_MAGIC 0xBEEF0005
Vanger 0:b86d15c6ba29 61
Vanger 0:b86d15c6ba29 62 enum {
Vanger 0:b86d15c6ba29 63 HMAC_FIPS_MIN_KEY = 14, /* 112 bit key length minimum */
Vanger 0:b86d15c6ba29 64
Vanger 0:b86d15c6ba29 65 IPAD = 0x36,
Vanger 0:b86d15c6ba29 66 OPAD = 0x5C,
Vanger 0:b86d15c6ba29 67
Vanger 0:b86d15c6ba29 68 /* If any hash is not enabled, add the ID here. */
Vanger 0:b86d15c6ba29 69 #ifdef NO_MD5
Vanger 0:b86d15c6ba29 70 MD5 = 0,
Vanger 0:b86d15c6ba29 71 #endif
Vanger 0:b86d15c6ba29 72 #ifdef NO_SHA
Vanger 0:b86d15c6ba29 73 SHA = 1,
Vanger 0:b86d15c6ba29 74 #endif
Vanger 0:b86d15c6ba29 75 #ifdef NO_SHA256
Vanger 0:b86d15c6ba29 76 SHA256 = 2,
Vanger 0:b86d15c6ba29 77 #endif
Vanger 0:b86d15c6ba29 78 #ifndef CYASSL_SHA512
Vanger 0:b86d15c6ba29 79 SHA512 = 4,
Vanger 0:b86d15c6ba29 80 #endif
Vanger 0:b86d15c6ba29 81 #ifndef CYASSL_SHA384
Vanger 0:b86d15c6ba29 82 SHA384 = 5,
Vanger 0:b86d15c6ba29 83 #endif
Vanger 0:b86d15c6ba29 84 #ifndef HAVE_BLAKE2
Vanger 0:b86d15c6ba29 85 BLAKE2B_ID = 7,
Vanger 0:b86d15c6ba29 86 #endif
Vanger 0:b86d15c6ba29 87
Vanger 0:b86d15c6ba29 88 /* Select the largest available hash for the buffer size. */
Vanger 0:b86d15c6ba29 89 #if defined(CYASSL_SHA512)
Vanger 0:b86d15c6ba29 90 MAX_DIGEST_SIZE = SHA512_DIGEST_SIZE,
Vanger 0:b86d15c6ba29 91 HMAC_BLOCK_SIZE = SHA512_BLOCK_SIZE
Vanger 0:b86d15c6ba29 92 #elif defined(HAVE_BLAKE2)
Vanger 0:b86d15c6ba29 93 MAX_DIGEST_SIZE = BLAKE2B_OUTBYTES,
Vanger 0:b86d15c6ba29 94 HMAC_BLOCK_SIZE = BLAKE2B_BLOCKBYTES,
Vanger 0:b86d15c6ba29 95 #elif defined(CYASSL_SHA384)
Vanger 0:b86d15c6ba29 96 MAX_DIGEST_SIZE = SHA384_DIGEST_SIZE,
Vanger 0:b86d15c6ba29 97 HMAC_BLOCK_SIZE = SHA384_BLOCK_SIZE
Vanger 0:b86d15c6ba29 98 #elif !defined(NO_SHA256)
Vanger 0:b86d15c6ba29 99 MAX_DIGEST_SIZE = SHA256_DIGEST_SIZE,
Vanger 0:b86d15c6ba29 100 HMAC_BLOCK_SIZE = SHA256_BLOCK_SIZE
Vanger 0:b86d15c6ba29 101 #elif !defined(NO_SHA)
Vanger 0:b86d15c6ba29 102 MAX_DIGEST_SIZE = SHA_DIGEST_SIZE,
Vanger 0:b86d15c6ba29 103 HMAC_BLOCK_SIZE = SHA_BLOCK_SIZE
Vanger 0:b86d15c6ba29 104 #elif !defined(NO_MD5)
Vanger 0:b86d15c6ba29 105 MAX_DIGEST_SIZE = MD5_DIGEST_SIZE,
Vanger 0:b86d15c6ba29 106 HMAC_BLOCK_SIZE = MD5_BLOCK_SIZE
Vanger 0:b86d15c6ba29 107 #else
Vanger 0:b86d15c6ba29 108 #error "You have to have some kind of hash if you want to use HMAC."
Vanger 0:b86d15c6ba29 109 #endif
Vanger 0:b86d15c6ba29 110 };
Vanger 0:b86d15c6ba29 111
Vanger 0:b86d15c6ba29 112
Vanger 0:b86d15c6ba29 113 /* hash union */
Vanger 0:b86d15c6ba29 114 typedef union {
Vanger 0:b86d15c6ba29 115 #ifndef NO_MD5
Vanger 0:b86d15c6ba29 116 Md5 md5;
Vanger 0:b86d15c6ba29 117 #endif
Vanger 0:b86d15c6ba29 118 #ifndef NO_SHA
Vanger 0:b86d15c6ba29 119 Sha sha;
Vanger 0:b86d15c6ba29 120 #endif
Vanger 0:b86d15c6ba29 121 #ifndef NO_SHA256
Vanger 0:b86d15c6ba29 122 Sha256 sha256;
Vanger 0:b86d15c6ba29 123 #endif
Vanger 0:b86d15c6ba29 124 #ifdef CYASSL_SHA384
Vanger 0:b86d15c6ba29 125 Sha384 sha384;
Vanger 0:b86d15c6ba29 126 #endif
Vanger 0:b86d15c6ba29 127 #ifdef CYASSL_SHA512
Vanger 0:b86d15c6ba29 128 Sha512 sha512;
Vanger 0:b86d15c6ba29 129 #endif
Vanger 0:b86d15c6ba29 130 #ifdef HAVE_BLAKE2
Vanger 0:b86d15c6ba29 131 Blake2b blake2b;
Vanger 0:b86d15c6ba29 132 #endif
Vanger 0:b86d15c6ba29 133 } Hash;
Vanger 0:b86d15c6ba29 134
Vanger 0:b86d15c6ba29 135 /* Hmac digest */
Vanger 0:b86d15c6ba29 136 typedef struct Hmac {
Vanger 0:b86d15c6ba29 137 Hash hash;
Vanger 0:b86d15c6ba29 138 word32 ipad[HMAC_BLOCK_SIZE / sizeof(word32)]; /* same block size all*/
Vanger 0:b86d15c6ba29 139 word32 opad[HMAC_BLOCK_SIZE / sizeof(word32)];
Vanger 0:b86d15c6ba29 140 word32 innerHash[MAX_DIGEST_SIZE / sizeof(word32)];
Vanger 0:b86d15c6ba29 141 byte macType; /* md5 sha or sha256 */
Vanger 0:b86d15c6ba29 142 byte innerHashKeyed; /* keyed flag */
Vanger 0:b86d15c6ba29 143 #ifdef HAVE_CAVIUM
Vanger 0:b86d15c6ba29 144 word16 keyLen; /* hmac key length */
Vanger 0:b86d15c6ba29 145 word16 dataLen;
Vanger 0:b86d15c6ba29 146 HashType type; /* hmac key type */
Vanger 0:b86d15c6ba29 147 int devId; /* nitrox device id */
Vanger 0:b86d15c6ba29 148 word32 magic; /* using cavium magic */
Vanger 0:b86d15c6ba29 149 word64 contextHandle; /* nitrox context memory handle */
Vanger 0:b86d15c6ba29 150 byte* data; /* buffered input data for one call */
Vanger 0:b86d15c6ba29 151 #endif
Vanger 0:b86d15c6ba29 152 } Hmac;
Vanger 0:b86d15c6ba29 153
Vanger 0:b86d15c6ba29 154
Vanger 0:b86d15c6ba29 155 /* does init */
Vanger 0:b86d15c6ba29 156 CYASSL_API int HmacSetKey(Hmac*, int type, const byte* key, word32 keySz);
Vanger 0:b86d15c6ba29 157 CYASSL_API int HmacUpdate(Hmac*, const byte*, word32);
Vanger 0:b86d15c6ba29 158 CYASSL_API int HmacFinal(Hmac*, byte*);
Vanger 0:b86d15c6ba29 159
Vanger 0:b86d15c6ba29 160 #ifdef HAVE_CAVIUM
Vanger 0:b86d15c6ba29 161 CYASSL_API int HmacInitCavium(Hmac*, int);
Vanger 0:b86d15c6ba29 162 CYASSL_API void HmacFreeCavium(Hmac*);
Vanger 0:b86d15c6ba29 163 #endif
Vanger 0:b86d15c6ba29 164
Vanger 0:b86d15c6ba29 165 CYASSL_API int CyaSSL_GetHmacMaxSize(void);
Vanger 0:b86d15c6ba29 166
Vanger 0:b86d15c6ba29 167
Vanger 0:b86d15c6ba29 168 #ifdef HAVE_HKDF
Vanger 0:b86d15c6ba29 169
Vanger 0:b86d15c6ba29 170 CYASSL_API int HKDF(int type, const byte* inKey, word32 inKeySz,
Vanger 0:b86d15c6ba29 171 const byte* salt, word32 saltSz,
Vanger 0:b86d15c6ba29 172 const byte* info, word32 infoSz,
Vanger 0:b86d15c6ba29 173 byte* out, word32 outSz);
Vanger 0:b86d15c6ba29 174
Vanger 0:b86d15c6ba29 175 #endif /* HAVE_HKDF */
Vanger 0:b86d15c6ba29 176
Vanger 0:b86d15c6ba29 177
Vanger 0:b86d15c6ba29 178 #ifdef HAVE_FIPS
Vanger 0:b86d15c6ba29 179 /* fips wrapper calls, user can call direct */
Vanger 0:b86d15c6ba29 180 CYASSL_API int HmacSetKey_fips(Hmac*, int type, const byte* key,
Vanger 0:b86d15c6ba29 181 word32 keySz);
Vanger 0:b86d15c6ba29 182 CYASSL_API int HmacUpdate_fips(Hmac*, const byte*, word32);
Vanger 0:b86d15c6ba29 183 CYASSL_API int HmacFinal_fips(Hmac*, byte*);
Vanger 0:b86d15c6ba29 184 #ifndef FIPS_NO_WRAPPERS
Vanger 0:b86d15c6ba29 185 /* if not impl or fips.c impl wrapper force fips calls if fips build */
Vanger 0:b86d15c6ba29 186 #define HmacSetKey HmacSetKey_fips
Vanger 0:b86d15c6ba29 187 #define HmacUpdate HmacUpdate_fips
Vanger 0:b86d15c6ba29 188 #define HmacFinal HmacFinal_fips
Vanger 0:b86d15c6ba29 189 #endif /* FIPS_NO_WRAPPERS */
Vanger 0:b86d15c6ba29 190
Vanger 0:b86d15c6ba29 191 #endif /* HAVE_FIPS */
Vanger 0:b86d15c6ba29 192
Vanger 0:b86d15c6ba29 193
Vanger 0:b86d15c6ba29 194 #ifdef __cplusplus
Vanger 0:b86d15c6ba29 195 } /* extern "C" */
Vanger 0:b86d15c6ba29 196 #endif
Vanger 0:b86d15c6ba29 197
Vanger 0:b86d15c6ba29 198 #endif /* CTAO_CRYPT_HMAC_H */
Vanger 0:b86d15c6ba29 199
Vanger 0:b86d15c6ba29 200 #endif /* NO_HMAC */
Vanger 0:b86d15c6ba29 201