xref: /titanic_50/usr/src/common/crypto/aes/aes_impl.h (revision 8b2e16e76f55405c78218b9f08c6aefaf13c9e24)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
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	"%Z%%M%	%I%	%E% 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 */
119