Print this page
5072963 Need an optimized AES implementation for amd64
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/common/crypto/aes/aes_impl.h
+++ new/usr/src/common/crypto/aes/aes_impl.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #ifndef _AES_IMPL_H
27 27 #define _AES_IMPL_H
28 28
29 -#pragma ident "@(#)aes_impl.h 1.3 08/02/26 SMI"
29 +#pragma ident "@(#)aes_impl.h 1.4 08/05/19 SMI"
30 30
31 31 /*
32 32 * Common definitions used by AES.
33 33 */
34 34
35 35 #ifdef __cplusplus
36 36 extern "C" {
37 37 #endif
38 38
39 -#define AES_BLOCK_LEN 16
39 +#include <sys/types.h>
40 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 +
41 49 #define AES_COPY_BLOCK(src, dst) \
42 50 (dst)[0] = (src)[0]; \
43 51 (dst)[1] = (src)[1]; \
44 52 (dst)[2] = (src)[2]; \
45 53 (dst)[3] = (src)[3]; \
46 54 (dst)[4] = (src)[4]; \
47 55 (dst)[5] = (src)[5]; \
48 56 (dst)[6] = (src)[6]; \
49 57 (dst)[7] = (src)[7]; \
50 58 (dst)[8] = (src)[8]; \
51 59 (dst)[9] = (src)[9]; \
52 60 (dst)[10] = (src)[10]; \
53 61 (dst)[11] = (src)[11]; \
54 62 (dst)[12] = (src)[12]; \
55 63 (dst)[13] = (src)[13]; \
56 64 (dst)[14] = (src)[14]; \
57 65 (dst)[15] = (src)[15]
58 66
59 67 #define AES_XOR_BLOCK(src, dst) \
60 68 (dst)[0] ^= (src)[0]; \
61 69 (dst)[1] ^= (src)[1]; \
62 70 (dst)[2] ^= (src)[2]; \
63 71 (dst)[3] ^= (src)[3]; \
64 72 (dst)[4] ^= (src)[4]; \
65 73 (dst)[5] ^= (src)[5]; \
66 74 (dst)[6] ^= (src)[6]; \
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
67 75 (dst)[7] ^= (src)[7]; \
68 76 (dst)[8] ^= (src)[8]; \
69 77 (dst)[9] ^= (src)[9]; \
70 78 (dst)[10] ^= (src)[10]; \
71 79 (dst)[11] ^= (src)[11]; \
72 80 (dst)[12] ^= (src)[12]; \
73 81 (dst)[13] ^= (src)[13]; \
74 82 (dst)[14] ^= (src)[14]; \
75 83 (dst)[15] ^= (src)[15]
76 84
85 +/* AES key size definitions */
77 86 #define AES_MINBITS 128
78 -#define AES_MINBYTES (AES_MINBITS >> 3)
87 +#define AES_MINBYTES ((AES_MINBITS) >> 3)
79 88 #define AES_MAXBITS 256
80 -#define AES_MAXBYTES (AES_MAXBITS >> 3)
89 +#define AES_MAXBYTES ((AES_MAXBITS) >> 3)
81 90
82 -#define AES_MIN_KEY_BYTES (AES_MINBITS >> 3)
83 -#define AES_MAX_KEY_BYTES (AES_MAXBITS >> 3)
91 +#define AES_MIN_KEY_BYTES ((AES_MINBITS) >> 3)
92 +#define AES_MAX_KEY_BYTES ((AES_MAXBITS) >> 3)
84 93 #define AES_192_KEY_BYTES 24
85 94 #define AES_IV_LEN 16
86 95
96 +/* AES key schedule may be implemented with 32- or 64-bit elements: */
87 97 #define AES_32BIT_KS 32
88 98 #define AES_64BIT_KS 64
89 99
90 -#define MAX_AES_NR 14
100 +#define MAX_AES_NR 14 /* Maximum number of rounds */
101 +#define MAX_AES_NB 4 /* Number of columns comprising a state */
91 102
92 103 typedef union {
93 - uint64_t ks64[(MAX_AES_NR + 1) * 4];
94 - uint32_t ks32[(MAX_AES_NR + 1) * 4];
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)];
95 108 } aes_ks_t;
96 109
97 110 typedef struct aes_key aes_key_t;
98 111 struct aes_key {
99 112 int nr;
100 113 int type;
101 114 aes_ks_t encr_ks;
102 115 aes_ks_t decr_ks;
103 116 };
104 117
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]);
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);
113 123
114 124 #ifdef __cplusplus
115 125 }
116 126 #endif
117 127
118 128 #endif /* _AES_IMPL_H */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX