xref: /titanic_51/usr/src/common/crypto/aes/aes_impl.h (revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_AES_IMPL_H
28 #define	_AES_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Common definitions used by AES.
34  */
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #define	AES_BLOCK_LEN 16
41 
42 #define	AES_COPY_BLOCK(src, dst) \
43 	(dst)[0] = (src)[0]; \
44 	(dst)[1] = (src)[1]; \
45 	(dst)[2] = (src)[2]; \
46 	(dst)[3] = (src)[3]; \
47 	(dst)[4] = (src)[4]; \
48 	(dst)[5] = (src)[5]; \
49 	(dst)[6] = (src)[6]; \
50 	(dst)[7] = (src)[7]; \
51 	(dst)[8] = (src)[8]; \
52 	(dst)[9] = (src)[9]; \
53 	(dst)[10] = (src)[10]; \
54 	(dst)[11] = (src)[11]; \
55 	(dst)[12] = (src)[12]; \
56 	(dst)[13] = (src)[13]; \
57 	(dst)[14] = (src)[14]; \
58 	(dst)[15] = (src)[15]
59 
60 #define	AES_XOR_BLOCK(src, dst) \
61 	(dst)[0] ^= (src)[0]; \
62 	(dst)[1] ^= (src)[1]; \
63 	(dst)[2] ^= (src)[2]; \
64 	(dst)[3] ^= (src)[3]; \
65 	(dst)[4] ^= (src)[4]; \
66 	(dst)[5] ^= (src)[5]; \
67 	(dst)[6] ^= (src)[6]; \
68 	(dst)[7] ^= (src)[7]; \
69 	(dst)[8] ^= (src)[8]; \
70 	(dst)[9] ^= (src)[9]; \
71 	(dst)[10] ^= (src)[10]; \
72 	(dst)[11] ^= (src)[11]; \
73 	(dst)[12] ^= (src)[12]; \
74 	(dst)[13] ^= (src)[13]; \
75 	(dst)[14] ^= (src)[14]; \
76 	(dst)[15] ^= (src)[15]
77 
78 #define	AES_MINBITS		128
79 #define	AES_MINBYTES		(AES_MINBITS >> 3)
80 #ifdef	CRYPTO_UNLIMITED
81 #define	AES_MAXBITS		256
82 #else
83 #define	AES_MAXBITS		128
84 #endif /* CRYPTO_UNLIMITED */
85 #define	AES_MAXBYTES		(AES_MAXBITS >> 3)
86 
87 #define	AES_MIN_KEY_BYTES	(AES_MINBITS >> 3)
88 #define	AES_MAX_KEY_BYTES	(AES_MAXBITS >> 3)
89 #define	AES_192_KEY_BYTES	24
90 #define	AES_IV_LEN		16
91 
92 #define	AES_32BIT_KS		32
93 #define	AES_64BIT_KS		64
94 
95 #define	MAX_AES_NR		14
96 
97 typedef union {
98 	uint64_t	ks64[(MAX_AES_NR + 1) * 4];
99 	uint32_t	ks32[(MAX_AES_NR + 1) * 4];
100 } aes_ks_t;
101 
102 typedef struct aes_key aes_key_t;
103 struct aes_key {
104 	int		nr;
105 	int		type;
106 	aes_ks_t	encr_ks;
107 	aes_ks_t	decr_ks;
108 };
109 
110 extern void aes_encrypt_block(void *, uint8_t *, uint8_t *);
111 extern void aes_decrypt_block(void *, uint8_t *, uint8_t *);
112 extern void aes_init_keysched(uint8_t *, uint_t, void *);
113 extern void *aes_alloc_keysched(size_t *, int);
114 extern void aes_encrypt_impl(const aes_ks_t *ks, int Nr, const uint32_t pt[4],
115     uint32_t ct[4]);
116 extern void aes_decrypt_impl(const aes_ks_t *ks, int Nr, const uint32_t ct[4],
117     uint32_t pt[4]);
118 
119 #ifdef	__cplusplus
120 }
121 #endif
122 
123 #endif	/* _AES_IMPL_H */
124