cya_u
Fork of CyaSSL-forEncrypt by
ctc_aes.h@2:d0516dc143b1, 2017-05-10 (annotated)
- Committer:
- vbahl2
- Date:
- Wed May 10 18:20:47 2017 +0000
- Revision:
- 2:d0516dc143b1
- Parent:
- 1:2cec76fea11b
updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
toddouska | 0:5045d2638c29 | 1 | /* ctc_aes.h |
toddouska | 0:5045d2638c29 | 2 | * |
toddouska | 0:5045d2638c29 | 3 | * Copyright (C) 2006-2009 Sawtooth Consulting Ltd. |
toddouska | 0:5045d2638c29 | 4 | * |
toddouska | 0:5045d2638c29 | 5 | * This file is part of CyaSSL. |
toddouska | 0:5045d2638c29 | 6 | * |
toddouska | 0:5045d2638c29 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
toddouska | 0:5045d2638c29 | 8 | * it under the terms of the GNU General Public License as published by |
toddouska | 0:5045d2638c29 | 9 | * the Free Software Foundation; either version 2 of the License, or |
toddouska | 0:5045d2638c29 | 10 | * (at your option) any later version. |
toddouska | 0:5045d2638c29 | 11 | * |
toddouska | 0:5045d2638c29 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
toddouska | 0:5045d2638c29 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
toddouska | 0:5045d2638c29 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
toddouska | 0:5045d2638c29 | 15 | * GNU General Public License for more details. |
toddouska | 0:5045d2638c29 | 16 | * |
toddouska | 0:5045d2638c29 | 17 | * You should have received a copy of the GNU General Public License |
toddouska | 0:5045d2638c29 | 18 | * along with this program; if not, write to the Free Software |
toddouska | 0:5045d2638c29 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
toddouska | 0:5045d2638c29 | 20 | */ |
toddouska | 0:5045d2638c29 | 21 | |
toddouska | 0:5045d2638c29 | 22 | #ifndef NO_AES |
toddouska | 0:5045d2638c29 | 23 | |
toddouska | 0:5045d2638c29 | 24 | #ifndef CTAO_CRYPT_AES_H |
toddouska | 0:5045d2638c29 | 25 | #define CTAO_CRYPT_AES_H |
toddouska | 0:5045d2638c29 | 26 | |
toddouska | 0:5045d2638c29 | 27 | |
toddouska | 0:5045d2638c29 | 28 | #include "types.h" |
toddouska | 0:5045d2638c29 | 29 | |
toddouska | 0:5045d2638c29 | 30 | #ifdef CYASSL_AESNI |
toddouska | 0:5045d2638c29 | 31 | |
toddouska | 0:5045d2638c29 | 32 | #include <wmmintrin.h> |
toddouska | 0:5045d2638c29 | 33 | |
toddouska | 0:5045d2638c29 | 34 | #if !defined (ALIGN16) |
toddouska | 0:5045d2638c29 | 35 | #if defined (__GNUC__) |
toddouska | 0:5045d2638c29 | 36 | #define ALIGN16 __attribute__ ( (aligned (16))) |
toddouska | 0:5045d2638c29 | 37 | #elif defined(_MSC_VER) |
toddouska | 0:5045d2638c29 | 38 | #define ALIGN16 __declspec (align (16)) |
toddouska | 0:5045d2638c29 | 39 | #else |
toddouska | 0:5045d2638c29 | 40 | #define ALIGN16 |
toddouska | 0:5045d2638c29 | 41 | #endif |
toddouska | 0:5045d2638c29 | 42 | #endif |
toddouska | 0:5045d2638c29 | 43 | |
toddouska | 0:5045d2638c29 | 44 | #endif /* CYASSL_AESNI */ |
toddouska | 0:5045d2638c29 | 45 | |
toddouska | 0:5045d2638c29 | 46 | #if !defined (ALIGN16) |
toddouska | 0:5045d2638c29 | 47 | #define ALIGN16 |
toddouska | 0:5045d2638c29 | 48 | #endif |
toddouska | 0:5045d2638c29 | 49 | |
toddouska | 0:5045d2638c29 | 50 | #ifdef __cplusplus |
toddouska | 0:5045d2638c29 | 51 | extern "C" { |
toddouska | 0:5045d2638c29 | 52 | #endif |
toddouska | 0:5045d2638c29 | 53 | |
toddouska | 0:5045d2638c29 | 54 | |
toddouska | 0:5045d2638c29 | 55 | enum { |
toddouska | 0:5045d2638c29 | 56 | AES_ENCRYPTION = 0, |
toddouska | 0:5045d2638c29 | 57 | AES_DECRYPTION = 1, |
toddouska | 0:5045d2638c29 | 58 | AES_BLOCK_SIZE = 16 |
toddouska | 0:5045d2638c29 | 59 | }; |
toddouska | 0:5045d2638c29 | 60 | |
toddouska | 0:5045d2638c29 | 61 | |
toddouska | 0:5045d2638c29 | 62 | typedef struct Aes { |
toddouska | 0:5045d2638c29 | 63 | /* AESNI needs key first, rounds 2nd, not sure why yet */ |
toddouska | 0:5045d2638c29 | 64 | ALIGN16 word32 key[60]; |
toddouska | 0:5045d2638c29 | 65 | word32 rounds; |
toddouska | 0:5045d2638c29 | 66 | |
toddouska | 0:5045d2638c29 | 67 | ALIGN16 word32 reg[AES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ |
toddouska | 0:5045d2638c29 | 68 | ALIGN16 word32 tmp[AES_BLOCK_SIZE / sizeof(word32)]; /* same */ |
toddouska | 0:5045d2638c29 | 69 | } Aes; |
toddouska | 0:5045d2638c29 | 70 | |
toddouska | 0:5045d2638c29 | 71 | |
toddouska | 0:5045d2638c29 | 72 | int AesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv, int dir); |
toddouska | 0:5045d2638c29 | 73 | void AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz); |
toddouska | 0:5045d2638c29 | 74 | void AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz); |
budoguyiii | 1:2cec76fea11b | 75 | void AesEncrypt(Aes* aes, const byte* inBlock, byte* outBlock); |
toddouska | 0:5045d2638c29 | 76 | |
toddouska | 0:5045d2638c29 | 77 | #ifdef __cplusplus |
toddouska | 0:5045d2638c29 | 78 | } /* extern "C" */ |
toddouska | 0:5045d2638c29 | 79 | #endif |
toddouska | 0:5045d2638c29 | 80 | |
toddouska | 0:5045d2638c29 | 81 | |
toddouska | 0:5045d2638c29 | 82 | #endif /* CTAO_CRYPT_AES_H */ |
toddouska | 0:5045d2638c29 | 83 | #endif /* NO_AES */ |
toddouska | 0:5045d2638c29 | 84 |