9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #ifndef _AES_IMPL_H
27 #define _AES_IMPL_H
28
29 #pragma ident "@(#)aes_impl.h 1.3 08/02/26 SMI"
30
31 /*
32 * Common definitions used by AES.
33 */
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 #define AES_BLOCK_LEN 16
40
41 #define AES_COPY_BLOCK(src, dst) \
42 (dst)[0] = (src)[0]; \
43 (dst)[1] = (src)[1]; \
44 (dst)[2] = (src)[2]; \
45 (dst)[3] = (src)[3]; \
46 (dst)[4] = (src)[4]; \
47 (dst)[5] = (src)[5]; \
48 (dst)[6] = (src)[6]; \
49 (dst)[7] = (src)[7]; \
50 (dst)[8] = (src)[8]; \
51 (dst)[9] = (src)[9]; \
52 (dst)[10] = (src)[10]; \
53 (dst)[11] = (src)[11]; \
54 (dst)[12] = (src)[12]; \
55 (dst)[13] = (src)[13]; \
56 (dst)[14] = (src)[14]; \
57 (dst)[15] = (src)[15]
58
59 #define AES_XOR_BLOCK(src, dst) \
60 (dst)[0] ^= (src)[0]; \
61 (dst)[1] ^= (src)[1]; \
62 (dst)[2] ^= (src)[2]; \
63 (dst)[3] ^= (src)[3]; \
64 (dst)[4] ^= (src)[4]; \
65 (dst)[5] ^= (src)[5]; \
66 (dst)[6] ^= (src)[6]; \
67 (dst)[7] ^= (src)[7]; \
68 (dst)[8] ^= (src)[8]; \
69 (dst)[9] ^= (src)[9]; \
70 (dst)[10] ^= (src)[10]; \
71 (dst)[11] ^= (src)[11]; \
72 (dst)[12] ^= (src)[12]; \
73 (dst)[13] ^= (src)[13]; \
74 (dst)[14] ^= (src)[14]; \
75 (dst)[15] ^= (src)[15]
76
77 #define AES_MINBITS 128
78 #define AES_MINBYTES (AES_MINBITS >> 3)
79 #define AES_MAXBITS 256
80 #define AES_MAXBYTES (AES_MAXBITS >> 3)
81
82 #define AES_MIN_KEY_BYTES (AES_MINBITS >> 3)
83 #define AES_MAX_KEY_BYTES (AES_MAXBITS >> 3)
84 #define AES_192_KEY_BYTES 24
85 #define AES_IV_LEN 16
86
87 #define AES_32BIT_KS 32
88 #define AES_64BIT_KS 64
89
90 #define MAX_AES_NR 14
91
92 typedef union {
93 uint64_t ks64[(MAX_AES_NR + 1) * 4];
94 uint32_t ks32[(MAX_AES_NR + 1) * 4];
95 } aes_ks_t;
96
97 typedef struct aes_key aes_key_t;
98 struct aes_key {
99 int nr;
100 int type;
101 aes_ks_t encr_ks;
102 aes_ks_t decr_ks;
103 };
104
105 extern void aes_encrypt_block(void *, uint8_t *, uint8_t *);
106 extern void aes_decrypt_block(void *, uint8_t *, uint8_t *);
107 extern void aes_init_keysched(uint8_t *, uint_t, void *);
108 extern void *aes_alloc_keysched(size_t *, int);
109 extern void aes_encrypt_impl(const aes_ks_t *ks, int Nr, const uint32_t pt[4],
110 uint32_t ct[4]);
111 extern void aes_decrypt_impl(const aes_ks_t *ks, int Nr, const uint32_t ct[4],
112 uint32_t pt[4]);
113
114 #ifdef __cplusplus
115 }
116 #endif
117
118 #endif /* _AES_IMPL_H */
|
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #ifndef _AES_IMPL_H
27 #define _AES_IMPL_H
28
29 #pragma ident "@(#)aes_impl.h 1.4 08/05/19 SMI"
30
31 /*
32 * Common definitions used by AES.
33 */
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 #include <sys/types.h>
40
41 /* Similar to sysmacros.h IS_P2ALIGNED, but checks two pointers: */
42 #define IS_P2ALIGNED2(v, w, a) \
43 ((((uintptr_t)(v) | (uintptr_t)(w)) & ((uintptr_t)(a) - 1)) == 0)
44
45 #define AES_BLOCK_LEN 16 /* bytes */
46 /* Round constant length, in number of 32-bit elements: */
47 #define RC_LENGTH (5 * ((AES_BLOCK_LEN) / 4 - 2))
48
49 #define AES_COPY_BLOCK(src, dst) \
50 (dst)[0] = (src)[0]; \
51 (dst)[1] = (src)[1]; \
52 (dst)[2] = (src)[2]; \
53 (dst)[3] = (src)[3]; \
54 (dst)[4] = (src)[4]; \
55 (dst)[5] = (src)[5]; \
56 (dst)[6] = (src)[6]; \
57 (dst)[7] = (src)[7]; \
58 (dst)[8] = (src)[8]; \
59 (dst)[9] = (src)[9]; \
60 (dst)[10] = (src)[10]; \
61 (dst)[11] = (src)[11]; \
62 (dst)[12] = (src)[12]; \
63 (dst)[13] = (src)[13]; \
64 (dst)[14] = (src)[14]; \
65 (dst)[15] = (src)[15]
66
67 #define AES_XOR_BLOCK(src, dst) \
68 (dst)[0] ^= (src)[0]; \
69 (dst)[1] ^= (src)[1]; \
70 (dst)[2] ^= (src)[2]; \
71 (dst)[3] ^= (src)[3]; \
72 (dst)[4] ^= (src)[4]; \
73 (dst)[5] ^= (src)[5]; \
74 (dst)[6] ^= (src)[6]; \
75 (dst)[7] ^= (src)[7]; \
76 (dst)[8] ^= (src)[8]; \
77 (dst)[9] ^= (src)[9]; \
78 (dst)[10] ^= (src)[10]; \
79 (dst)[11] ^= (src)[11]; \
80 (dst)[12] ^= (src)[12]; \
81 (dst)[13] ^= (src)[13]; \
82 (dst)[14] ^= (src)[14]; \
83 (dst)[15] ^= (src)[15]
84
85 /* AES key size definitions */
86 #define AES_MINBITS 128
87 #define AES_MINBYTES ((AES_MINBITS) >> 3)
88 #define AES_MAXBITS 256
89 #define AES_MAXBYTES ((AES_MAXBITS) >> 3)
90
91 #define AES_MIN_KEY_BYTES ((AES_MINBITS) >> 3)
92 #define AES_MAX_KEY_BYTES ((AES_MAXBITS) >> 3)
93 #define AES_192_KEY_BYTES 24
94 #define AES_IV_LEN 16
95
96 /* AES key schedule may be implemented with 32- or 64-bit elements: */
97 #define AES_32BIT_KS 32
98 #define AES_64BIT_KS 64
99
100 #define MAX_AES_NR 14 /* Maximum number of rounds */
101 #define MAX_AES_NB 4 /* Number of columns comprising a state */
102
103 typedef union {
104 #ifdef sun4u
105 uint64_t ks64[((MAX_AES_NR) + 1) * (MAX_AES_NB)];
106 #endif
107 uint32_t ks32[((MAX_AES_NR) + 1) * (MAX_AES_NB)];
108 } aes_ks_t;
109
110 typedef struct aes_key aes_key_t;
111 struct aes_key {
112 int nr;
113 int type;
114 aes_ks_t encr_ks;
115 aes_ks_t decr_ks;
116 };
117
118 extern void aes_encrypt_block(const void *ks, const uint8_t *pt, uint8_t *ct);
119 extern void aes_decrypt_block(const void *ks, const uint8_t *ct, uint8_t *pt);
120 extern void aes_init_keysched(const uint8_t *cipherKey, uint_t keyBits,
121 void *keysched);
122 extern void *aes_alloc_keysched(size_t *size, int kmflag);
123
124 #ifdef __cplusplus
125 }
126 #endif
127
128 #endif /* _AES_IMPL_H */
|