This is a port of cyaSSL 2.7.0.

Dependents:   CyaSSL_DTLS_Cellular CyaSSL_DTLS_Ethernet

Committer:
ashleymills
Date:
Thu Sep 05 15:55:50 2013 +0000
Revision:
1:c0ce1562443a
Parent:
0:714293de3836
Nothing;

Who changed what in which revision?

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