Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: HTTPClient-SSL HTTPClient HTTPClient-SSL http_access ... more
aes.h
00001 /* aes.h 00002 * 00003 * Copyright (C) 2006-2014 wolfSSL Inc. 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 00023 #ifndef NO_AES 00024 00025 #ifndef CTAO_CRYPT_AES_H 00026 #define CTAO_CRYPT_AES_H 00027 00028 00029 #include <cyassl/ctaocrypt/types.h> 00030 00031 #ifdef HAVE_CAVIUM 00032 #include <cyassl/ctaocrypt/logging.h> 00033 #include "cavium_common.h" 00034 #endif 00035 00036 #ifdef CYASSL_AESNI 00037 00038 #include <wmmintrin.h> 00039 00040 #if !defined (ALIGN16) 00041 #if defined (__GNUC__) 00042 #define ALIGN16 __attribute__ ( (aligned (16))) 00043 #elif defined(_MSC_VER) 00044 #define ALIGN16 __declspec (align (16)) 00045 #else 00046 #define ALIGN16 00047 #endif 00048 #endif 00049 00050 #endif /* CYASSL_AESNI */ 00051 00052 #if !defined (ALIGN16) 00053 #define ALIGN16 00054 #endif 00055 00056 #ifdef __cplusplus 00057 extern "C" { 00058 #endif 00059 00060 00061 #define CYASSL_AES_CAVIUM_MAGIC 0xBEEF0002 00062 00063 enum { 00064 AES_ENC_TYPE = 1, /* cipher unique type */ 00065 AES_ENCRYPTION = 0, 00066 AES_DECRYPTION = 1, 00067 AES_BLOCK_SIZE = 16 00068 }; 00069 00070 00071 typedef struct Aes { 00072 /* AESNI needs key first, rounds 2nd, not sure why yet */ 00073 ALIGN16 word32 key[60]; 00074 word32 rounds; 00075 00076 ALIGN16 word32 reg[AES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ 00077 ALIGN16 word32 tmp[AES_BLOCK_SIZE / sizeof(word32)]; /* same */ 00078 00079 #ifdef HAVE_AESGCM 00080 ALIGN16 byte H[AES_BLOCK_SIZE]; 00081 #ifdef GCM_TABLE 00082 /* key-based fast multiplication table. */ 00083 ALIGN16 byte M0[256][AES_BLOCK_SIZE]; 00084 #endif /* GCM_TABLE */ 00085 #endif /* HAVE_AESGCM */ 00086 #ifdef CYASSL_AESNI 00087 byte use_aesni; 00088 #endif /* CYASSL_AESNI */ 00089 #ifdef HAVE_CAVIUM 00090 AesType type; /* aes key type */ 00091 int devId; /* nitrox device id */ 00092 word32 magic; /* using cavium magic */ 00093 word64 contextHandle; /* nitrox context memory handle */ 00094 #endif 00095 #ifdef CYASSL_AES_COUNTER 00096 word32 left; /* unsued bytes left from last call */ 00097 #endif 00098 #ifdef CYASSL_PIC32MZ_CRYPT 00099 word32 key_ce[AES_BLOCK_SIZE*2/sizeof(word32)] ; 00100 word32 iv_ce [AES_BLOCK_SIZE /sizeof(word32)] ; 00101 int keylen ; 00102 #endif 00103 } Aes; 00104 00105 00106 CYASSL_API int AesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv, 00107 int dir); 00108 CYASSL_API int AesSetIV(Aes* aes, const byte* iv); 00109 CYASSL_API int AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz); 00110 CYASSL_API int AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz); 00111 CYASSL_API void AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz); 00112 CYASSL_API void AesEncryptDirect(Aes* aes, byte* out, const byte* in); 00113 CYASSL_API void AesDecryptDirect(Aes* aes, byte* out, const byte* in); 00114 CYASSL_API int AesSetKeyDirect(Aes* aes, const byte* key, word32 len, 00115 const byte* iv, int dir); 00116 #ifdef HAVE_AESGCM 00117 CYASSL_API void AesGcmSetKey(Aes* aes, const byte* key, word32 len); 00118 CYASSL_API void AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz, 00119 const byte* iv, word32 ivSz, 00120 byte* authTag, word32 authTagSz, 00121 const byte* authIn, word32 authInSz); 00122 CYASSL_API int AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz, 00123 const byte* iv, word32 ivSz, 00124 const byte* authTag, word32 authTagSz, 00125 const byte* authIn, word32 authInSz); 00126 00127 typedef struct Gmac { 00128 Aes aes; 00129 } Gmac; 00130 CYASSL_API void GmacSetKey(Gmac* gmac, const byte* key, word32 len); 00131 CYASSL_API void GmacUpdate(Gmac* gmac, const byte* iv, word32 ivSz, 00132 const byte* authIn, word32 authInSz, 00133 byte* authTag, word32 authTagSz); 00134 #endif /* HAVE_AESGCM */ 00135 #ifdef HAVE_AESCCM 00136 CYASSL_API void AesCcmSetKey(Aes* aes, const byte* key, word32 keySz); 00137 CYASSL_API void AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, 00138 const byte* nonce, word32 nonceSz, 00139 byte* authTag, word32 authTagSz, 00140 const byte* authIn, word32 authInSz); 00141 CYASSL_API int AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, 00142 const byte* nonce, word32 nonceSz, 00143 const byte* authTag, word32 authTagSz, 00144 const byte* authIn, word32 authInSz); 00145 #endif /* HAVE_AESCCM */ 00146 00147 #ifdef HAVE_CAVIUM 00148 CYASSL_API int AesInitCavium(Aes*, int); 00149 CYASSL_API void AesFreeCavium(Aes*); 00150 #endif 00151 00152 00153 #ifdef HAVE_FIPS 00154 /* fips wrapper calls, user can call direct */ 00155 CYASSL_API int AesSetKey_fips(Aes* aes, const byte* key, word32 len, 00156 const byte* iv, int dir); 00157 CYASSL_API int AesSetIV_fips(Aes* aes, const byte* iv); 00158 CYASSL_API int AesCbcEncrypt_fips(Aes* aes, byte* out, const byte* in, 00159 word32 sz); 00160 CYASSL_API int AesCbcDecrypt_fips(Aes* aes, byte* out, const byte* in, 00161 word32 sz); 00162 #ifndef FIPS_NO_WRAPPERS 00163 /* if not impl or fips.c impl wrapper force fips calls if fips build */ 00164 #define AesSetKey AesSetKey_fips 00165 #define AesSetIV AesSetIV_fips 00166 #define AesCbcEncrypt AesCbcEncrypt_fips 00167 #define AesCbcDecrypt AesCbcDecrypt_fips 00168 #endif /* FIPS_NO_WRAPPERS */ 00169 00170 #endif /* HAVE_FIPS */ 00171 00172 00173 #ifdef __cplusplus 00174 } /* extern "C" */ 00175 #endif 00176 00177 00178 #endif /* CTAO_CRYPT_AES_H */ 00179 #endif /* NO_AES */ 00180 00181
Generated on Wed Jul 13 2022 02:18:38 by
1.7.2