cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Committer:
ashleymills
Date:
Fri Apr 26 16:59:36 2013 +0000
Revision:
1:b211d97b0068
Parent:
0:e979170e02e7
nothing

Who changed what in which revision?

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