12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include "../arcfour.h"
27
28 /* Initialize the key stream 'key' using the key value */
29 void
30 arcfour_key_init(ARCFour_key *key, uchar_t *keyval, int keyvallen)
31 {
32 /* EXPORT DELETE START */
33
34 uchar_t ext_keyval[256];
35 uchar_t tmp;
36 int i, j;
37
38 for (i = j = 0; i < 256; i++, j++) {
39 if (j == keyvallen)
40 j = 0;
41
42 ext_keyval[i] = keyval[j];
43 }
44 for (i = 0; i < 256; i++)
45 key->arr[i] = (uchar_t)i;
46
47 j = 0;
48 for (i = 0; i < 256; i++) {
49 j = (j + key->arr[i] + ext_keyval[i]) % 256;
50 tmp = key->arr[i];
51 key->arr[i] = key->arr[j];
52 key->arr[j] = tmp;
53 }
54 key->i = 0;
55 key->j = 0;
56
57 /* EXPORT DELETE END */
58 }
59
60
61 /*
62 * Encipher 'in' using 'key.
63 * in and out can point to the same location
64 */
65 void
66 arcfour_crypt(ARCFour_key *key, uchar_t *in, uchar_t *out, size_t len)
67 {
68 size_t ii;
69 unsigned long long in0, merge = 0, merge0 = 0, merge1, mask = 0;
70 uchar_t i, j, *base, jj, *base1, tmp;
71 unsigned int tmp0, tmp1, i_accum, shift = 0, i1;
72
73
74 /* EXPORT DELETE START */
75 int index;
76
77 base = key->arr;
78
79 index = (((uintptr_t)in) & 0x7);
80
81 /* Get the 'in' on an 8-byte alignment */
82 if (index > 0) {
83 i = key->i;
84 j = key->j;
85
86 for (index = 8 - index; (index-- > 0) && len > 0;
87 len--, in++, out++) {
88
89 i = i + 1;
90 j = j + key->arr[i];
91 tmp = key->arr[i];
92 key->arr[i] = key->arr[j];
93 key->arr[j] = tmp;
94 tmp = key->arr[i] + key->arr[j];
582 /*
583 * Handle final few bytes
584 */
585 for (; ii < len; ii++) {
586 i = i + 1;
587 tmp0 = base[i];
588 j = j + tmp0;
589 tmp1 = base[j];
590
591 base[i] = (uchar_t)tmp1;
592 base[j] = (uchar_t)tmp0;
593
594 tmp0 += tmp1;
595 tmp0 = tmp0 & 0xff;
596 out[ii] = in[ii] ^ base[tmp0];
597 }
598 key->i = i;
599 key->j = j;
600 }
601 #endif /* sun4v */
602
603 /* EXPORT DELETE END */
604 }
|
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include "../arcfour.h"
27
28 /* Initialize the key stream 'key' using the key value */
29 void
30 arcfour_key_init(ARCFour_key *key, uchar_t *keyval, int keyvallen)
31 {
32 uchar_t ext_keyval[256];
33 uchar_t tmp;
34 int i, j;
35
36 for (i = j = 0; i < 256; i++, j++) {
37 if (j == keyvallen)
38 j = 0;
39
40 ext_keyval[i] = keyval[j];
41 }
42 for (i = 0; i < 256; i++)
43 key->arr[i] = (uchar_t)i;
44
45 j = 0;
46 for (i = 0; i < 256; i++) {
47 j = (j + key->arr[i] + ext_keyval[i]) % 256;
48 tmp = key->arr[i];
49 key->arr[i] = key->arr[j];
50 key->arr[j] = tmp;
51 }
52 key->i = 0;
53 key->j = 0;
54 }
55
56
57 /*
58 * Encipher 'in' using 'key.
59 * in and out can point to the same location
60 */
61 void
62 arcfour_crypt(ARCFour_key *key, uchar_t *in, uchar_t *out, size_t len)
63 {
64 size_t ii;
65 unsigned long long in0, merge = 0, merge0 = 0, merge1, mask = 0;
66 uchar_t i, j, *base, jj, *base1, tmp;
67 unsigned int tmp0, tmp1, i_accum, shift = 0, i1;
68
69 int index;
70
71 base = key->arr;
72
73 index = (((uintptr_t)in) & 0x7);
74
75 /* Get the 'in' on an 8-byte alignment */
76 if (index > 0) {
77 i = key->i;
78 j = key->j;
79
80 for (index = 8 - index; (index-- > 0) && len > 0;
81 len--, in++, out++) {
82
83 i = i + 1;
84 j = j + key->arr[i];
85 tmp = key->arr[i];
86 key->arr[i] = key->arr[j];
87 key->arr[j] = tmp;
88 tmp = key->arr[i] + key->arr[j];
576 /*
577 * Handle final few bytes
578 */
579 for (; ii < len; ii++) {
580 i = i + 1;
581 tmp0 = base[i];
582 j = j + tmp0;
583 tmp1 = base[j];
584
585 base[i] = (uchar_t)tmp1;
586 base[j] = (uchar_t)tmp0;
587
588 tmp0 += tmp1;
589 tmp0 = tmp0 & 0xff;
590 out[ii] = in[ii] ^ base[tmp0];
591 }
592 key->i = i;
593 key->j = j;
594 }
595 #endif /* sun4v */
596 }
|