xref: /onnv-gate/usr/src/common/crypto/aes/aes_impl.h (revision 6125:38a604bf8269)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6125Sbubbva  * Common Development and Distribution License (the "License").
6*6125Sbubbva  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*6125Sbubbva  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_AES_IMPL_H
270Sstevel@tonic-gate #define	_AES_IMPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate /*
320Sstevel@tonic-gate  * Common definitions used by AES.
330Sstevel@tonic-gate  */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #ifdef	__cplusplus
360Sstevel@tonic-gate extern "C" {
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #define	AES_BLOCK_LEN 16
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #define	AES_COPY_BLOCK(src, dst) \
420Sstevel@tonic-gate 	(dst)[0] = (src)[0]; \
430Sstevel@tonic-gate 	(dst)[1] = (src)[1]; \
440Sstevel@tonic-gate 	(dst)[2] = (src)[2]; \
450Sstevel@tonic-gate 	(dst)[3] = (src)[3]; \
460Sstevel@tonic-gate 	(dst)[4] = (src)[4]; \
470Sstevel@tonic-gate 	(dst)[5] = (src)[5]; \
480Sstevel@tonic-gate 	(dst)[6] = (src)[6]; \
490Sstevel@tonic-gate 	(dst)[7] = (src)[7]; \
500Sstevel@tonic-gate 	(dst)[8] = (src)[8]; \
510Sstevel@tonic-gate 	(dst)[9] = (src)[9]; \
520Sstevel@tonic-gate 	(dst)[10] = (src)[10]; \
530Sstevel@tonic-gate 	(dst)[11] = (src)[11]; \
540Sstevel@tonic-gate 	(dst)[12] = (src)[12]; \
550Sstevel@tonic-gate 	(dst)[13] = (src)[13]; \
560Sstevel@tonic-gate 	(dst)[14] = (src)[14]; \
570Sstevel@tonic-gate 	(dst)[15] = (src)[15]
580Sstevel@tonic-gate 
590Sstevel@tonic-gate #define	AES_XOR_BLOCK(src, dst) \
600Sstevel@tonic-gate 	(dst)[0] ^= (src)[0]; \
610Sstevel@tonic-gate 	(dst)[1] ^= (src)[1]; \
620Sstevel@tonic-gate 	(dst)[2] ^= (src)[2]; \
630Sstevel@tonic-gate 	(dst)[3] ^= (src)[3]; \
640Sstevel@tonic-gate 	(dst)[4] ^= (src)[4]; \
650Sstevel@tonic-gate 	(dst)[5] ^= (src)[5]; \
660Sstevel@tonic-gate 	(dst)[6] ^= (src)[6]; \
670Sstevel@tonic-gate 	(dst)[7] ^= (src)[7]; \
680Sstevel@tonic-gate 	(dst)[8] ^= (src)[8]; \
690Sstevel@tonic-gate 	(dst)[9] ^= (src)[9]; \
700Sstevel@tonic-gate 	(dst)[10] ^= (src)[10]; \
710Sstevel@tonic-gate 	(dst)[11] ^= (src)[11]; \
720Sstevel@tonic-gate 	(dst)[12] ^= (src)[12]; \
730Sstevel@tonic-gate 	(dst)[13] ^= (src)[13]; \
740Sstevel@tonic-gate 	(dst)[14] ^= (src)[14]; \
750Sstevel@tonic-gate 	(dst)[15] ^= (src)[15]
760Sstevel@tonic-gate 
770Sstevel@tonic-gate #define	AES_MINBITS		128
780Sstevel@tonic-gate #define	AES_MINBYTES		(AES_MINBITS >> 3)
790Sstevel@tonic-gate #define	AES_MAXBITS		256
800Sstevel@tonic-gate #define	AES_MAXBYTES		(AES_MAXBITS >> 3)
810Sstevel@tonic-gate 
820Sstevel@tonic-gate #define	AES_MIN_KEY_BYTES	(AES_MINBITS >> 3)
830Sstevel@tonic-gate #define	AES_MAX_KEY_BYTES	(AES_MAXBITS >> 3)
840Sstevel@tonic-gate #define	AES_192_KEY_BYTES	24
850Sstevel@tonic-gate #define	AES_IV_LEN		16
860Sstevel@tonic-gate 
870Sstevel@tonic-gate #define	AES_32BIT_KS		32
880Sstevel@tonic-gate #define	AES_64BIT_KS		64
890Sstevel@tonic-gate 
900Sstevel@tonic-gate #define	MAX_AES_NR		14
910Sstevel@tonic-gate 
920Sstevel@tonic-gate typedef union {
930Sstevel@tonic-gate 	uint64_t	ks64[(MAX_AES_NR + 1) * 4];
940Sstevel@tonic-gate 	uint32_t	ks32[(MAX_AES_NR + 1) * 4];
950Sstevel@tonic-gate } aes_ks_t;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate typedef struct aes_key aes_key_t;
980Sstevel@tonic-gate struct aes_key {
990Sstevel@tonic-gate 	int		nr;
1000Sstevel@tonic-gate 	int		type;
1010Sstevel@tonic-gate 	aes_ks_t	encr_ks;
1020Sstevel@tonic-gate 	aes_ks_t	decr_ks;
1030Sstevel@tonic-gate };
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate extern void aes_encrypt_block(void *, uint8_t *, uint8_t *);
1060Sstevel@tonic-gate extern void aes_decrypt_block(void *, uint8_t *, uint8_t *);
1070Sstevel@tonic-gate extern void aes_init_keysched(uint8_t *, uint_t, void *);
1080Sstevel@tonic-gate extern void *aes_alloc_keysched(size_t *, int);
1090Sstevel@tonic-gate extern void aes_encrypt_impl(const aes_ks_t *ks, int Nr, const uint32_t pt[4],
1100Sstevel@tonic-gate     uint32_t ct[4]);
1110Sstevel@tonic-gate extern void aes_decrypt_impl(const aes_ks_t *ks, int Nr, const uint32_t ct[4],
1120Sstevel@tonic-gate     uint32_t pt[4]);
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate #ifdef	__cplusplus
1150Sstevel@tonic-gate }
1160Sstevel@tonic-gate #endif
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate #endif	/* _AES_IMPL_H */
119