]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/CyaSSL/cyassl/ctaocrypt/aes.h
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS-Plus / CyaSSL / cyassl / ctaocrypt / aes.h
1 /* aes.h
2  *
3  * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
4  *
5  * This file is part of CyaSSL.
6  *
7  * CyaSSL is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * CyaSSL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20  */
21
22
23 #ifndef NO_AES
24
25 #ifndef CTAO_CRYPT_AES_H
26 #define CTAO_CRYPT_AES_H
27
28
29 #include <cyassl/ctaocrypt/types.h>
30
31 #ifdef CYASSL_AESNI
32
33 #include <wmmintrin.h>
34
35 #if !defined (ALIGN16)
36     #if defined (__GNUC__)
37         #define ALIGN16 __attribute__ ( (aligned (16)))
38     #elif defined(_MSC_VER)
39         #define ALIGN16 __declspec (align (16))
40     #else
41         #define ALIGN16
42     #endif
43 #endif
44
45 #endif /* CYASSL_AESNI */
46
47 #if !defined (ALIGN16)
48     #define ALIGN16
49 #endif
50
51 #ifdef __cplusplus
52     extern "C" {
53 #endif
54
55
56 enum {
57     AES_ENC_TYPE   = 1,   /* cipher unique type */
58     AES_ENCRYPTION = 0,
59     AES_DECRYPTION = 1,
60     AES_BLOCK_SIZE = 16
61 };
62
63
64 typedef struct Aes {
65     /* AESNI needs key first, rounds 2nd, not sure why yet */
66     ALIGN16 word32 key[60];
67     word32  rounds;
68
69     ALIGN16 word32 reg[AES_BLOCK_SIZE / sizeof(word32)];      /* for CBC mode */
70     ALIGN16 word32 tmp[AES_BLOCK_SIZE / sizeof(word32)];      /* same         */
71 } Aes;
72
73
74 CYASSL_API int  AesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv,
75                           int dir);
76 CYASSL_API int  AesSetIV(Aes* aes, const byte* iv);
77 CYASSL_API void AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz);
78 CYASSL_API void AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz);
79 CYASSL_API void AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz);
80 CYASSL_API void AesEncryptDirect(Aes* aes, byte* out, const byte* in);
81 CYASSL_API void AesDecryptDirect(Aes* aes, byte* out, const byte* in);
82
83
84 #ifdef __cplusplus
85     } /* extern "C" */
86 #endif
87
88
89 #endif /* CTAO_CRYPT_AES_H */
90 #endif /* NO_AES */
91