Print this page
6189743 Need an ARCFOUR implementation optimized for AMD64
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/common/crypto/arcfour/arcfour_crypt.c
+++ new/usr/src/common/crypto/arcfour/arcfour_crypt.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 - * 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.
5 + * Common Development and Distribution License (the "License").
6 + * You may not use this file except in compliance with the License.
8 7 *
9 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 9 * or http://www.opensolaris.org/os/licensing.
11 10 * See the License for the specific language governing permissions
12 11 * and limitations under the License.
13 12 *
14 13 * When distributing Covered Code, include this CDDL HEADER in each
15 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 15 * If applicable, add the following below this CDDL HEADER, with the
17 16 * fields enclosed by brackets "[]" replaced with your own identifying
18 17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 18 *
20 19 * CDDL HEADER END
21 20 */
22 21 /*
23 - * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
22 + * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 23 * Use is subject to license terms.
25 24 */
26 25
27 -#pragma ident "@(#)arcfour_crypt.c 1.5 05/08/23 SMI"
26 +#pragma ident "@(#)arcfour_crypt.c 1.6 08/01/02 SMI"
28 27
29 28 #include "arcfour.h"
30 29
30 +#if defined(__amd64)
31 +/*
32 + * Use hand-tuned, processor-specific assembly version of arcfour_crypt()
33 + * for 64-bit x86:
34 + */
35 +#define USE_PSR_VERSION_OF_ARCFOUR_CRYPT
36 +#endif /* __amd64 */
37 +
31 38 /* Initialize the key stream 'key' using the key value */
32 39 void
33 40 arcfour_key_init(ARCFour_key *key, uchar_t *keyval, int keyvallen)
34 41 {
35 42 /* EXPORT DELETE START */
36 43
37 44 uchar_t ext_keyval[256];
38 45 uchar_t tmp;
39 46 int i, j;
40 47
41 48 for (i = j = 0; i < 256; i++, j++) {
42 49 if (j == keyvallen)
43 50 j = 0;
44 51
45 52 ext_keyval[i] = keyval[j];
46 53 }
47 54 for (i = 0; i < 256; i++)
48 55 key->arr[i] = (uchar_t)i;
49 56
50 57 j = 0;
51 58 for (i = 0; i < 256; i++) {
52 59 j = (j + key->arr[i] + ext_keyval[i]) % 256;
53 60 tmp = key->arr[i];
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
54 61 key->arr[i] = key->arr[j];
55 62 key->arr[j] = tmp;
56 63 }
57 64 key->i = 0;
58 65 key->j = 0;
59 66
60 67 /* EXPORT DELETE END */
61 68 }
62 69
63 70
71 +#if !defined(USE_PSR_VERSION_OF_ARCFOUR_CRYPT)
64 72 /*
65 - * Encipher 'in' using 'key.
73 + * Encipher 'in' using 'key'.
66 74 * in and out can point to the same location
67 75 */
68 76 void
69 77 arcfour_crypt(ARCFour_key *key, uchar_t *in, uchar_t *out, size_t len)
70 78 {
71 79 size_t ii;
72 80 uchar_t tmp, i, j;
73 81
74 82 /* EXPORT DELETE START */
75 83
76 84 /*
77 85 * The sun4u has a version of arcfour_crypt_aligned() hand-tuned for
78 86 * the cases where the input and output buffers are aligned on
79 87 * a multiple of 8-byte boundary.
80 88 */
81 89 #ifdef sun4u
82 90 int index;
83 91
84 92 index = (((uint64_t)(uintptr_t)in) & 0x7);
85 93
86 94 /* Get the 'in' on an 8-byte alignment */
87 95 if (index > 0) {
88 96 i = key->i;
89 97 j = key->j;
90 98 for (index = 8 - (uint64_t)(uintptr_t)in & 0x7;
91 99 (index-- > 0) && len > 0;
92 100 len--, in++, out++) {
93 101 i = i + 1;
94 102 j = j + key->arr[i];
95 103 tmp = key->arr[i];
96 104 key->arr[i] = key->arr[j];
97 105 key->arr[j] = tmp;
98 106 tmp = key->arr[i] + key->arr[j];
99 107 *out = *in ^ key->arr[tmp];
100 108 }
101 109 key->i = i;
102 110 key->j = j;
103 111
104 112 }
105 113 if (len == 0)
106 114 return;
107 115
108 116 /* See if we're fortunate and 'out' got aligned as well */
109 117
110 118 if ((((uint64_t)(uintptr_t)out) & 7) != 0) {
111 119 #endif /* sun4u */
112 120 i = key->i;
113 121 j = key->j;
114 122 for (ii = 0; ii < len; ii++) {
115 123 i = i + 1;
116 124 j = j + key->arr[i];
117 125 tmp = key->arr[i];
118 126 key->arr[i] = key->arr[j];
119 127 key->arr[j] = tmp;
120 128 tmp = key->arr[i] + key->arr[j];
121 129 out[ii] = in[ii] ^ key->arr[tmp];
122 130 }
↓ open down ↓ |
47 lines elided |
↑ open up ↑ |
123 131 key->i = i;
124 132 key->j = j;
125 133 #ifdef sun4u
126 134 } else {
127 135 arcfour_crypt_aligned(key, len, in, out);
128 136 }
129 137 #endif /* sun4u */
130 138
131 139 /* EXPORT DELETE END */
132 140 }
141 +#endif /* !USE_PSR_VERSION_OF_ARCFOUR_CRYPT */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX