Game Develop C++ Platform: AES.h Source File

| Game Develop C++ Platform Platform for developing native games based on OpenGL and SFML with Game Develop

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
AES.h
1 /* The MIT License
2
3 Copyright (C) 2011, 2012 Zilong Tan (eric.zltan@gmail.com)
4
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
12
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 */
25
26 /*
27 * aes.h
28 *
29 * @version 3.0 (December 2000)
30 *
31 * Optimised ANSI C code for the Rijndael cipher (now AES)
32 *
33 * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
34 * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
35 * @author Paulo Barreto <paulo.barreto@terra.com.br>
36 *
37 * This code is hereby placed in the public domain.
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
40 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
41 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
43 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
46 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
47 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
48 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
49 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 */
51
52 #ifndef _ULIB_CRYPT_AES_H
53 #define _ULIB_CRYPT_AES_H
54
55 #include <stddef.h>
56 #include <stdint.h>
57
58 #define AES_MAXNR 14
59 #define AES_BLOCK_SIZE 16
60
61 typedef struct {
62 uint32_t rd_key[4 * (AES_MAXNR + 1)];
63 int rounds;
64 } aes_ks_t;
65
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69
70 /* AES key schedule functions. Inputs user key buffer and generates
71 * key schedule for encryption/decryption. Valid kbits are 128, 192,
72 * and 256. */
73 int GD_API aes_setks_encrypt(const uint8_t *keybuf, int kbits, aes_ks_t *ks);
74 int GD_API aes_setks_decrypt(const uint8_t *keybuf, int kbits, aes_ks_t *ks);
75
76 /* Core AES functions.
77 * in and out are input and output buffers, which can be the same
78 * (except for the aes_cbc_decrypt).
79 * Use aes_setks_* to generate ks.
80 */
81 void GD_API aes_ecb_encrypt(const uint8_t *in, uint8_t *out, const aes_ks_t *ks);
82 void GD_API aes_ecb_decrypt(const uint8_t *in, uint8_t *out, const aes_ks_t *ks);
83 void GD_API aes_cbc_encrypt(const uint8_t *in, uint8_t *out, uint8_t *iv,
84 size_t blks, const aes_ks_t *ks);
85 /* in and out can NOT be the same */
86 void GD_API aes_cbc_decrypt(const uint8_t *in, uint8_t *out, uint8_t *iv,
87 size_t blks, const aes_ks_t *ks);
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif /* _ULIB_CRYPT_AES_H */