Add PRIV self test.
[shishi.git] / crypto / aes-internal.h
blob2b7f06f7711e34ee20ea58a03d70d740d974d601
1 /* aes-internal.h
3 * The aes/rijndael block cipher.
4 */
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2001 Niels Möller
9 *
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 * MA 02111-1307, USA.
26 #ifndef NETTLE_AES_INTERNAL_H_INCLUDED
27 #define NETTLE_AES_INTERNAL_H_INCLUDED
29 #include "aes.h"
31 /* Define to use only small tables. */
32 #ifndef AES_SMALL
33 # define AES_SMALL 0
34 #endif
36 #if AES_SMALL
37 # define AES_TABLE_SIZE 1
38 #else
39 # define AES_TABLE_SIZE 4
40 #endif
42 /* Name mangling */
43 #define _aes_crypt _nettle_aes_crypt
45 /* Assembler code using the table should get link errors if linked
46 * against a small table. */
47 #if AES_SMALL
48 # define _aes_encrypt_table _nettle_aes_encrypt_table_small
49 # define _aes_decrypt_table _nettle_aes_decrypt_table_small
50 #else
51 # define _aes_encrypt_table _nettle_aes_encrypt_table
52 # define _aes_decrypt_table _nettle_aes_decrypt_table
53 #endif
55 struct aes_table
57 uint8_t sbox[0x100];
58 unsigned idx[3][4];
60 /* Variant of the idx array suitable for the sparc
61 * assembler code.
63 * sparc_idx[0][i] = idx[0][i] * 4 + 2
64 * sparc_idx[1][i] = idx[2][i] * 4
67 unsigned sparc_idx [2][4];
69 uint32_t table[AES_TABLE_SIZE][0x100];
72 void
73 _aes_crypt(const struct aes_ctx *ctx,
74 const struct aes_table *T,
75 unsigned length, uint8_t *dst,
76 const uint8_t *src);
78 /* Macros */
79 #define ROTBYTE(x) (((x) >> 8) | (((x) & 0xff) << 24))
80 #define ROTRBYTE(x) (((x) << 8) | (((x) >> 24) & 0xff))
81 #define SUBBYTE(x, box) (((box)[((x) & 0xff)]) | \
82 ((box)[(((x) >> 8) & 0xff)] << 8) | \
83 ((box)[(((x) >> 16) & 0xff)] << 16) | \
84 ((box)[(((x) >> 24) & 0xff)] << 24))
86 /* Internal tables */
87 extern const struct aes_table _aes_encrypt_table;
88 extern const struct aes_table _aes_decrypt_table;
90 #define aes_sbox (_aes_encrypt_table.sbox)
92 #endif /* NETTLE_AES_INTERNAL_H_INCLUDED */