CyaSSL changed for NucleoF401RE board: implemented random and time functions for build. (Has trouble with wildcard domains like *.google.com, *.yahoo.com)

Fork of CyaSSL by wolf SSL

Committer:
Vanger
Date:
Wed Jan 14 22:07:14 2015 +0000
Revision:
4:e505054279ed
Parent:
0:1239e9b70ca2
Implemented some platform specific functions in the Cyassl library code: time functions, seed random functions, and also changed the settings.h file to define settings specific to the platform being used

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:1239e9b70ca2 1 /* aes.h
wolfSSL 0:1239e9b70ca2 2 *
wolfSSL 0:1239e9b70ca2 3 * Copyright (C) 2006-2014 wolfSSL Inc.
wolfSSL 0:1239e9b70ca2 4 *
wolfSSL 0:1239e9b70ca2 5 * This file is part of CyaSSL.
wolfSSL 0:1239e9b70ca2 6 *
wolfSSL 0:1239e9b70ca2 7 * CyaSSL is free software; you can redistribute it and/or modify
wolfSSL 0:1239e9b70ca2 8 * it under the terms of the GNU General Public License as published by
wolfSSL 0:1239e9b70ca2 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 0:1239e9b70ca2 10 * (at your option) any later version.
wolfSSL 0:1239e9b70ca2 11 *
wolfSSL 0:1239e9b70ca2 12 * CyaSSL is distributed in the hope that it will be useful,
wolfSSL 0:1239e9b70ca2 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 0:1239e9b70ca2 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 0:1239e9b70ca2 15 * GNU General Public License for more details.
wolfSSL 0:1239e9b70ca2 16 *
wolfSSL 0:1239e9b70ca2 17 * You should have received a copy of the GNU General Public License
wolfSSL 0:1239e9b70ca2 18 * along with this program; if not, write to the Free Software
wolfSSL 0:1239e9b70ca2 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
wolfSSL 0:1239e9b70ca2 20 */
wolfSSL 0:1239e9b70ca2 21
wolfSSL 0:1239e9b70ca2 22
wolfSSL 0:1239e9b70ca2 23 #ifndef NO_AES
wolfSSL 0:1239e9b70ca2 24
wolfSSL 0:1239e9b70ca2 25 #ifndef CTAO_CRYPT_AES_H
wolfSSL 0:1239e9b70ca2 26 #define CTAO_CRYPT_AES_H
wolfSSL 0:1239e9b70ca2 27
wolfSSL 0:1239e9b70ca2 28
wolfSSL 0:1239e9b70ca2 29 #include <cyassl/ctaocrypt/types.h>
wolfSSL 0:1239e9b70ca2 30
wolfSSL 0:1239e9b70ca2 31 #ifdef HAVE_CAVIUM
wolfSSL 0:1239e9b70ca2 32 #include <cyassl/ctaocrypt/logging.h>
wolfSSL 0:1239e9b70ca2 33 #include "cavium_common.h"
wolfSSL 0:1239e9b70ca2 34 #endif
wolfSSL 0:1239e9b70ca2 35
wolfSSL 0:1239e9b70ca2 36 #ifdef CYASSL_AESNI
wolfSSL 0:1239e9b70ca2 37
wolfSSL 0:1239e9b70ca2 38 #include <wmmintrin.h>
wolfSSL 0:1239e9b70ca2 39
wolfSSL 0:1239e9b70ca2 40 #if !defined (ALIGN16)
wolfSSL 0:1239e9b70ca2 41 #if defined (__GNUC__)
wolfSSL 0:1239e9b70ca2 42 #define ALIGN16 __attribute__ ( (aligned (16)))
wolfSSL 0:1239e9b70ca2 43 #elif defined(_MSC_VER)
wolfSSL 0:1239e9b70ca2 44 #define ALIGN16 __declspec (align (16))
wolfSSL 0:1239e9b70ca2 45 #else
wolfSSL 0:1239e9b70ca2 46 #define ALIGN16
wolfSSL 0:1239e9b70ca2 47 #endif
wolfSSL 0:1239e9b70ca2 48 #endif
wolfSSL 0:1239e9b70ca2 49
wolfSSL 0:1239e9b70ca2 50 #endif /* CYASSL_AESNI */
wolfSSL 0:1239e9b70ca2 51
wolfSSL 0:1239e9b70ca2 52 #if !defined (ALIGN16)
wolfSSL 0:1239e9b70ca2 53 #define ALIGN16
wolfSSL 0:1239e9b70ca2 54 #endif
wolfSSL 0:1239e9b70ca2 55
wolfSSL 0:1239e9b70ca2 56 #ifdef __cplusplus
wolfSSL 0:1239e9b70ca2 57 extern "C" {
wolfSSL 0:1239e9b70ca2 58 #endif
wolfSSL 0:1239e9b70ca2 59
wolfSSL 0:1239e9b70ca2 60
wolfSSL 0:1239e9b70ca2 61 #define CYASSL_AES_CAVIUM_MAGIC 0xBEEF0002
wolfSSL 0:1239e9b70ca2 62
wolfSSL 0:1239e9b70ca2 63 enum {
wolfSSL 0:1239e9b70ca2 64 AES_ENC_TYPE = 1, /* cipher unique type */
wolfSSL 0:1239e9b70ca2 65 AES_ENCRYPTION = 0,
wolfSSL 0:1239e9b70ca2 66 AES_DECRYPTION = 1,
wolfSSL 0:1239e9b70ca2 67 AES_BLOCK_SIZE = 16
wolfSSL 0:1239e9b70ca2 68 };
wolfSSL 0:1239e9b70ca2 69
wolfSSL 0:1239e9b70ca2 70
wolfSSL 0:1239e9b70ca2 71 typedef struct Aes {
wolfSSL 0:1239e9b70ca2 72 /* AESNI needs key first, rounds 2nd, not sure why yet */
wolfSSL 0:1239e9b70ca2 73 ALIGN16 word32 key[60];
wolfSSL 0:1239e9b70ca2 74 word32 rounds;
wolfSSL 0:1239e9b70ca2 75
wolfSSL 0:1239e9b70ca2 76 ALIGN16 word32 reg[AES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
wolfSSL 0:1239e9b70ca2 77 ALIGN16 word32 tmp[AES_BLOCK_SIZE / sizeof(word32)]; /* same */
wolfSSL 0:1239e9b70ca2 78
wolfSSL 0:1239e9b70ca2 79 #ifdef HAVE_AESGCM
wolfSSL 0:1239e9b70ca2 80 ALIGN16 byte H[AES_BLOCK_SIZE];
wolfSSL 0:1239e9b70ca2 81 #ifdef GCM_TABLE
wolfSSL 0:1239e9b70ca2 82 /* key-based fast multiplication table. */
wolfSSL 0:1239e9b70ca2 83 ALIGN16 byte M0[256][AES_BLOCK_SIZE];
wolfSSL 0:1239e9b70ca2 84 #endif /* GCM_TABLE */
wolfSSL 0:1239e9b70ca2 85 #endif /* HAVE_AESGCM */
wolfSSL 0:1239e9b70ca2 86 #ifdef CYASSL_AESNI
wolfSSL 0:1239e9b70ca2 87 byte use_aesni;
wolfSSL 0:1239e9b70ca2 88 #endif /* CYASSL_AESNI */
wolfSSL 0:1239e9b70ca2 89 #ifdef HAVE_CAVIUM
wolfSSL 0:1239e9b70ca2 90 AesType type; /* aes key type */
wolfSSL 0:1239e9b70ca2 91 int devId; /* nitrox device id */
wolfSSL 0:1239e9b70ca2 92 word32 magic; /* using cavium magic */
wolfSSL 0:1239e9b70ca2 93 word64 contextHandle; /* nitrox context memory handle */
wolfSSL 0:1239e9b70ca2 94 #endif
wolfSSL 0:1239e9b70ca2 95 #ifdef CYASSL_AES_COUNTER
wolfSSL 0:1239e9b70ca2 96 word32 left; /* unsued bytes left from last call */
wolfSSL 0:1239e9b70ca2 97 #endif
wolfSSL 0:1239e9b70ca2 98 #ifdef CYASSL_PIC32MZ_CRYPT
wolfSSL 0:1239e9b70ca2 99 word32 key_ce[AES_BLOCK_SIZE*2/sizeof(word32)] ;
wolfSSL 0:1239e9b70ca2 100 word32 iv_ce [AES_BLOCK_SIZE /sizeof(word32)] ;
wolfSSL 0:1239e9b70ca2 101 int keylen ;
wolfSSL 0:1239e9b70ca2 102 #endif
wolfSSL 0:1239e9b70ca2 103 } Aes;
wolfSSL 0:1239e9b70ca2 104
wolfSSL 0:1239e9b70ca2 105
wolfSSL 0:1239e9b70ca2 106 CYASSL_API int AesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv,
wolfSSL 0:1239e9b70ca2 107 int dir);
wolfSSL 0:1239e9b70ca2 108 CYASSL_API int AesSetIV(Aes* aes, const byte* iv);
wolfSSL 0:1239e9b70ca2 109 CYASSL_API int AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz);
wolfSSL 0:1239e9b70ca2 110 CYASSL_API int AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz);
wolfSSL 0:1239e9b70ca2 111 CYASSL_API void AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz);
wolfSSL 0:1239e9b70ca2 112 CYASSL_API void AesEncryptDirect(Aes* aes, byte* out, const byte* in);
wolfSSL 0:1239e9b70ca2 113 CYASSL_API void AesDecryptDirect(Aes* aes, byte* out, const byte* in);
wolfSSL 0:1239e9b70ca2 114 CYASSL_API int AesSetKeyDirect(Aes* aes, const byte* key, word32 len,
wolfSSL 0:1239e9b70ca2 115 const byte* iv, int dir);
wolfSSL 0:1239e9b70ca2 116 #ifdef HAVE_AESGCM
wolfSSL 0:1239e9b70ca2 117 CYASSL_API void AesGcmSetKey(Aes* aes, const byte* key, word32 len);
wolfSSL 0:1239e9b70ca2 118 CYASSL_API void AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
wolfSSL 0:1239e9b70ca2 119 const byte* iv, word32 ivSz,
wolfSSL 0:1239e9b70ca2 120 byte* authTag, word32 authTagSz,
wolfSSL 0:1239e9b70ca2 121 const byte* authIn, word32 authInSz);
wolfSSL 0:1239e9b70ca2 122 CYASSL_API int AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
wolfSSL 0:1239e9b70ca2 123 const byte* iv, word32 ivSz,
wolfSSL 0:1239e9b70ca2 124 const byte* authTag, word32 authTagSz,
wolfSSL 0:1239e9b70ca2 125 const byte* authIn, word32 authInSz);
wolfSSL 0:1239e9b70ca2 126
wolfSSL 0:1239e9b70ca2 127 typedef struct Gmac {
wolfSSL 0:1239e9b70ca2 128 Aes aes;
wolfSSL 0:1239e9b70ca2 129 } Gmac;
wolfSSL 0:1239e9b70ca2 130 CYASSL_API void GmacSetKey(Gmac* gmac, const byte* key, word32 len);
wolfSSL 0:1239e9b70ca2 131 CYASSL_API void GmacUpdate(Gmac* gmac, const byte* iv, word32 ivSz,
wolfSSL 0:1239e9b70ca2 132 const byte* authIn, word32 authInSz,
wolfSSL 0:1239e9b70ca2 133 byte* authTag, word32 authTagSz);
wolfSSL 0:1239e9b70ca2 134 #endif /* HAVE_AESGCM */
wolfSSL 0:1239e9b70ca2 135 #ifdef HAVE_AESCCM
wolfSSL 0:1239e9b70ca2 136 CYASSL_API void AesCcmSetKey(Aes* aes, const byte* key, word32 keySz);
wolfSSL 0:1239e9b70ca2 137 CYASSL_API void AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
wolfSSL 0:1239e9b70ca2 138 const byte* nonce, word32 nonceSz,
wolfSSL 0:1239e9b70ca2 139 byte* authTag, word32 authTagSz,
wolfSSL 0:1239e9b70ca2 140 const byte* authIn, word32 authInSz);
wolfSSL 0:1239e9b70ca2 141 CYASSL_API int AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
wolfSSL 0:1239e9b70ca2 142 const byte* nonce, word32 nonceSz,
wolfSSL 0:1239e9b70ca2 143 const byte* authTag, word32 authTagSz,
wolfSSL 0:1239e9b70ca2 144 const byte* authIn, word32 authInSz);
wolfSSL 0:1239e9b70ca2 145 #endif /* HAVE_AESCCM */
wolfSSL 0:1239e9b70ca2 146
wolfSSL 0:1239e9b70ca2 147 #ifdef HAVE_CAVIUM
wolfSSL 0:1239e9b70ca2 148 CYASSL_API int AesInitCavium(Aes*, int);
wolfSSL 0:1239e9b70ca2 149 CYASSL_API void AesFreeCavium(Aes*);
wolfSSL 0:1239e9b70ca2 150 #endif
wolfSSL 0:1239e9b70ca2 151
wolfSSL 0:1239e9b70ca2 152
wolfSSL 0:1239e9b70ca2 153 #ifdef HAVE_FIPS
wolfSSL 0:1239e9b70ca2 154 /* fips wrapper calls, user can call direct */
wolfSSL 0:1239e9b70ca2 155 CYASSL_API int AesSetKey_fips(Aes* aes, const byte* key, word32 len,
wolfSSL 0:1239e9b70ca2 156 const byte* iv, int dir);
wolfSSL 0:1239e9b70ca2 157 CYASSL_API int AesSetIV_fips(Aes* aes, const byte* iv);
wolfSSL 0:1239e9b70ca2 158 CYASSL_API int AesCbcEncrypt_fips(Aes* aes, byte* out, const byte* in,
wolfSSL 0:1239e9b70ca2 159 word32 sz);
wolfSSL 0:1239e9b70ca2 160 CYASSL_API int AesCbcDecrypt_fips(Aes* aes, byte* out, const byte* in,
wolfSSL 0:1239e9b70ca2 161 word32 sz);
wolfSSL 0:1239e9b70ca2 162 #ifndef FIPS_NO_WRAPPERS
wolfSSL 0:1239e9b70ca2 163 /* if not impl or fips.c impl wrapper force fips calls if fips build */
wolfSSL 0:1239e9b70ca2 164 #define AesSetKey AesSetKey_fips
wolfSSL 0:1239e9b70ca2 165 #define AesSetIV AesSetIV_fips
wolfSSL 0:1239e9b70ca2 166 #define AesCbcEncrypt AesCbcEncrypt_fips
wolfSSL 0:1239e9b70ca2 167 #define AesCbcDecrypt AesCbcDecrypt_fips
wolfSSL 0:1239e9b70ca2 168 #endif /* FIPS_NO_WRAPPERS */
wolfSSL 0:1239e9b70ca2 169
wolfSSL 0:1239e9b70ca2 170 #endif /* HAVE_FIPS */
wolfSSL 0:1239e9b70ca2 171
wolfSSL 0:1239e9b70ca2 172
wolfSSL 0:1239e9b70ca2 173 #ifdef __cplusplus
wolfSSL 0:1239e9b70ca2 174 } /* extern "C" */
wolfSSL 0:1239e9b70ca2 175 #endif
wolfSSL 0:1239e9b70ca2 176
wolfSSL 0:1239e9b70ca2 177
wolfSSL 0:1239e9b70ca2 178 #endif /* CTAO_CRYPT_AES_H */
wolfSSL 0:1239e9b70ca2 179 #endif /* NO_AES */
wolfSSL 0:1239e9b70ca2 180
wolfSSL 0:1239e9b70ca2 181