arcfour_crypt.c revision 92a8e44d7a50507b89a65e1e3226edb5b90fd363
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#define ARCFOUR_LOOP_OPTIMIZED
#include "arcfour.h"
#if defined(__amd64)
/* ARCFour_key.flag values */
#define ARCFOUR_ON_INTEL 1
#define ARCFOUR_ON_AMD64 0
#ifdef _KERNEL
#include <sys/x86_archext.h>
#else
#endif /* _KERNEL */
#endif /* __amd64 */
#ifndef __amd64
/*
* Initialize the key stream 'key' using the key value.
*
* Input:
* keyval User-provided key
* keyvallen Length, in bytes, of keyval
* Output:
* key Initialized ARCFOUR key schedule, based on keyval
*/
void
{
/* EXPORT DELETE START */
int i, j;
/* Normalize key length to 256 */
for (i = j = 0; i < 256; i++, j++) {
if (j == keyvallen)
j = 0;
ext_keyval[i] = keyval[j];
}
for (i = 0; i < 256; i++)
j = 0;
for (i = 0; i < 256; i++) {
}
key->i = 0;
key->j = 0;
/* EXPORT DELETE END */
}
#endif /* !__amd64 */
/*
* Encipher 'in' using 'key'.
*
* Input:
* key ARCFOUR key, initialized by arcfour_key_init()
* in Input text
* out Buffer to contain output text
* len Length, in bytes, of the in and out buffers
*
* Output:
* out Buffer containing output text
*
* Note: in and out can point to the same location
*/
void
{
/* EXPORT DELETE START */
#ifdef __amd64
} else { /* Intel EM64T */
#endif /* amd64 */
#ifdef ARCFOUR_LOOP_OPTIMIZED
#endif
#ifdef __amd64
#else
#endif
#ifdef sun4u
/*
* The sun4u has a version of arcfour_crypt_aligned() hand-tuned for
* the cases where the input and output buffers are aligned on
* a multiple of 8-byte boundary.
*/
int index;
/* Get the 'in' on an 8-byte alignment */
if (index > 0) {
i = key->i;
j = key->j;
++i;
}
key->i = i;
key->j = j;
}
if (len == 0)
return;
/* See if we're fortunate and 'out' got aligned as well */
#endif /* sun4u */
i = key->i;
j = key->j;
#ifndef ARCFOUR_LOOP_OPTIMIZED
/*
* This loop is hasn't been reordered, but is kept for reference
* purposes as it's more readable
*/
++i;
j = j + ti;
}
#else
/*
* This for loop is optimized by carefully spreading out
* memory access and storage to avoid conflicts,
* allowing the processor to process operations in parallel
*/
/* for loop setup */
++i;
j = j + ti;
--len;
++i;
j = j + ti;
/* save result from previous loop: */
++ii;
}
/* save result from last loop: */
#endif
key->i = i;
key->j = j;
#ifdef sun4u
} else {
}
#endif /* sun4u */
#ifdef __amd64
}
#endif /* amd64 */
/* EXPORT DELETE END */
}
#ifdef __amd64
/*
* Return 1 if executing on Intel, otherwise 0 (e.g., AMD64).
*/
int
arcfour_crypt_on_intel(void)
{
#ifdef _KERNEL
#else
return ((ui & AV_386_AMD_MMX) == 0);
#endif /* _KERNEL */
}
#endif /* __amd64 */