Print this page
4896 Performance improvements for KCF AES modes
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/common/crypto/modes/modes.c
+++ new/usr/src/common/crypto/modes/modes.c
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.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
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 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 +/*
26 + * Copyright 2015 by Saso Kiselkov. All rights reserved.
27 + */
25 28
26 29 #ifndef _KERNEL
27 30 #include <stdlib.h>
28 31 #endif
29 32
30 33 #include <sys/strsun.h>
31 34 #include <sys/types.h>
32 35 #include <modes/modes.h>
33 36 #include <sys/crypto/common.h>
34 37 #include <sys/crypto/impl.h>
35 38
36 39 /*
37 40 * Initialize by setting iov_or_mp to point to the current iovec or mp,
38 41 * and by setting current_offset to an offset within the current iovec or mp.
39 42 */
40 43 void
41 44 crypto_init_ptrs(crypto_data_t *out, void **iov_or_mp, offset_t *current_offset)
42 45 {
43 46 offset_t offset;
44 47
45 48 switch (out->cd_format) {
46 49 case CRYPTO_DATA_RAW:
47 50 *current_offset = out->cd_offset;
48 51 break;
49 52
50 53 case CRYPTO_DATA_UIO: {
51 54 uio_t *uiop = out->cd_uio;
52 55 uintptr_t vec_idx;
53 56
54 57 offset = out->cd_offset;
55 58 for (vec_idx = 0; vec_idx < uiop->uio_iovcnt &&
56 59 offset >= uiop->uio_iov[vec_idx].iov_len;
57 60 offset -= uiop->uio_iov[vec_idx++].iov_len)
58 61 ;
59 62
60 63 *current_offset = offset;
61 64 *iov_or_mp = (void *)vec_idx;
62 65 break;
63 66 }
64 67
65 68 case CRYPTO_DATA_MBLK: {
66 69 mblk_t *mp;
67 70
68 71 offset = out->cd_offset;
69 72 for (mp = out->cd_mp; mp != NULL && offset >= MBLKL(mp);
70 73 offset -= MBLKL(mp), mp = mp->b_cont)
↓ open down ↓ |
36 lines elided |
↑ open up ↑ |
71 74 ;
72 75
73 76 *current_offset = offset;
74 77 *iov_or_mp = mp;
75 78 break;
76 79
77 80 }
78 81 } /* end switch */
79 82 }
80 83
81 -/*
82 - * Get pointers for where in the output to copy a block of encrypted or
83 - * decrypted data. The iov_or_mp argument stores a pointer to the current
84 - * iovec or mp, and offset stores an offset into the current iovec or mp.
85 - */
86 84 void
87 -crypto_get_ptrs(crypto_data_t *out, void **iov_or_mp, offset_t *current_offset,
88 - uint8_t **out_data_1, size_t *out_data_1_len, uint8_t **out_data_2,
89 - size_t amt)
90 -{
91 - offset_t offset;
92 -
93 - switch (out->cd_format) {
94 - case CRYPTO_DATA_RAW: {
95 - iovec_t *iov;
96 -
97 - offset = *current_offset;
98 - iov = &out->cd_raw;
99 - if ((offset + amt) <= iov->iov_len) {
100 - /* one block fits */
101 - *out_data_1 = (uint8_t *)iov->iov_base + offset;
102 - *out_data_1_len = amt;
103 - *out_data_2 = NULL;
104 - *current_offset = offset + amt;
105 - }
106 - break;
107 - }
108 -
109 - case CRYPTO_DATA_UIO: {
110 - uio_t *uio = out->cd_uio;
111 - iovec_t *iov;
112 - offset_t offset;
113 - uintptr_t vec_idx;
114 - uint8_t *p;
115 -
116 - offset = *current_offset;
117 - vec_idx = (uintptr_t)(*iov_or_mp);
118 - iov = &uio->uio_iov[vec_idx];
119 - p = (uint8_t *)iov->iov_base + offset;
120 - *out_data_1 = p;
121 -
122 - if (offset + amt <= iov->iov_len) {
123 - /* can fit one block into this iov */
124 - *out_data_1_len = amt;
125 - *out_data_2 = NULL;
126 - *current_offset = offset + amt;
127 - } else {
128 - /* one block spans two iovecs */
129 - *out_data_1_len = iov->iov_len - offset;
130 - if (vec_idx == uio->uio_iovcnt)
131 - return;
132 - vec_idx++;
133 - iov = &uio->uio_iov[vec_idx];
134 - *out_data_2 = (uint8_t *)iov->iov_base;
135 - *current_offset = amt - *out_data_1_len;
136 - }
137 - *iov_or_mp = (void *)vec_idx;
138 - break;
139 - }
140 -
141 - case CRYPTO_DATA_MBLK: {
142 - mblk_t *mp;
143 - uint8_t *p;
144 -
145 - offset = *current_offset;
146 - mp = (mblk_t *)*iov_or_mp;
147 - p = mp->b_rptr + offset;
148 - *out_data_1 = p;
149 - if ((p + amt) <= mp->b_wptr) {
150 - /* can fit one block into this mblk */
151 - *out_data_1_len = amt;
152 - *out_data_2 = NULL;
153 - *current_offset = offset + amt;
154 - } else {
155 - /* one block spans two mblks */
156 - *out_data_1_len = _PTRDIFF(mp->b_wptr, p);
157 - if ((mp = mp->b_cont) == NULL)
158 - return;
159 - *out_data_2 = mp->b_rptr;
160 - *current_offset = (amt - *out_data_1_len);
161 - }
162 - *iov_or_mp = mp;
163 - break;
164 - }
165 - } /* end switch */
166 -}
167 -
168 -void
169 85 crypto_free_mode_ctx(void *ctx)
170 86 {
171 87 common_ctx_t *common_ctx = (common_ctx_t *)ctx;
172 88
173 89 switch (common_ctx->cc_flags &
174 90 (ECB_MODE|CBC_MODE|CTR_MODE|CCM_MODE|GCM_MODE|GMAC_MODE)) {
175 91 case ECB_MODE:
176 92 #ifdef _KERNEL
177 93 kmem_free(common_ctx, sizeof (ecb_ctx_t));
178 94 #else
179 95 free(common_ctx);
180 96 #endif
181 97 break;
182 98
183 99 case CBC_MODE:
184 100 #ifdef _KERNEL
185 101 kmem_free(common_ctx, sizeof (cbc_ctx_t));
186 102 #else
187 103 free(common_ctx);
188 104 #endif
189 105 break;
190 106
191 107 case CTR_MODE:
192 108 #ifdef _KERNEL
193 109 kmem_free(common_ctx, sizeof (ctr_ctx_t));
194 110 #else
195 111 free(common_ctx);
196 112 #endif
197 113 break;
198 114
199 115 case CCM_MODE:
200 116 #ifdef _KERNEL
201 117 if (((ccm_ctx_t *)ctx)->ccm_pt_buf != NULL)
202 118 kmem_free(((ccm_ctx_t *)ctx)->ccm_pt_buf,
203 119 ((ccm_ctx_t *)ctx)->ccm_data_len);
204 120
205 121 kmem_free(ctx, sizeof (ccm_ctx_t));
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
206 122 #else
207 123 if (((ccm_ctx_t *)ctx)->ccm_pt_buf != NULL)
208 124 free(((ccm_ctx_t *)ctx)->ccm_pt_buf);
209 125 free(ctx);
210 126 #endif
211 127 break;
212 128
213 129 case GCM_MODE:
214 130 case GMAC_MODE:
215 131 #ifdef _KERNEL
216 - if (((gcm_ctx_t *)ctx)->gcm_pt_buf != NULL)
217 - kmem_free(((gcm_ctx_t *)ctx)->gcm_pt_buf,
218 - ((gcm_ctx_t *)ctx)->gcm_pt_buf_len);
219 -
220 132 kmem_free(ctx, sizeof (gcm_ctx_t));
221 133 #else
222 - if (((gcm_ctx_t *)ctx)->gcm_pt_buf != NULL)
223 - free(((gcm_ctx_t *)ctx)->gcm_pt_buf);
224 134 free(ctx);
225 135 #endif
226 136 }
227 137 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX