cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers aes.h Source File

aes.h

00001 /* aes.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_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 } Aes;
00096 
00097 
00098 CYASSL_API int  AesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv,
00099                           int dir);
00100 CYASSL_API int  AesSetIV(Aes* aes, const byte* iv);
00101 CYASSL_API void AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz);
00102 CYASSL_API void AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz);
00103 CYASSL_API void AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz);
00104 CYASSL_API void AesEncryptDirect(Aes* aes, byte* out, const byte* in);
00105 CYASSL_API void AesDecryptDirect(Aes* aes, byte* out, const byte* in);
00106 CYASSL_API int  AesSetKeyDirect(Aes* aes, const byte* key, word32 len,
00107                                 const byte* iv, int dir);
00108 #ifdef HAVE_AESGCM
00109 CYASSL_API void AesGcmSetKey(Aes* aes, const byte* key, word32 len);
00110 CYASSL_API void AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
00111                               const byte* iv, word32 ivSz,
00112                               byte* authTag, word32 authTagSz,
00113                               const byte* authIn, word32 authInSz);
00114 CYASSL_API int  AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
00115                               const byte* iv, word32 ivSz,
00116                               const byte* authTag, word32 authTagSz,
00117                               const byte* authIn, word32 authInSz);
00118 #endif /* HAVE_AESGCM */
00119 #ifdef HAVE_AESCCM
00120 CYASSL_API void AesCcmSetKey(Aes* aes, const byte* key, word32 keySz);
00121 CYASSL_API void AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
00122                               const byte* nonce, word32 nonceSz,
00123                               byte* authTag, word32 authTagSz,
00124                               const byte* authIn, word32 authInSz);
00125 CYASSL_API int  AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
00126                               const byte* nonce, word32 nonceSz,
00127                               const byte* authTag, word32 authTagSz,
00128                               const byte* authIn, word32 authInSz);
00129 #endif /* HAVE_AESCCM */
00130 
00131 #ifdef HAVE_CAVIUM
00132     CYASSL_API int  AesInitCavium(Aes*, int);
00133     CYASSL_API void AesFreeCavium(Aes*);
00134 #endif
00135 
00136 #ifdef __cplusplus
00137     } /* extern "C" */
00138 #endif
00139 
00140 
00141 #endif /* CTAO_CRYPT_AES_H */
00142 #endif /* NO_AES */
00143