/*
* ---------------------------------------------------------------------------
* Copyright (c) 1998-2007, Brian Gladman, Worcester, UK. All rights reserved.
*
* LICENSE TERMS
*
* The free distribution and use of this software is allowed (with or without
* changes) provided that:
*
* 1. source code distributions include the above copyright notice, this
* list of conditions and the following disclaimer;
*
* 2. binary distributions include the above copyright notice, this list
* of conditions and the following disclaimer in their documentation;
*
* 3. the name of the copyright holder is not used to endorse products
* built using this software without specific written permission.
*
* DISCLAIMER
*
* This software is provided 'as is' with no explicit or implied warranties
* in respect of its properties, including, but not limited to, correctness
* ---------------------------------------------------------------------------
* Issue Date: 20/12/2007
*/
#include "aes_impl.h"
#include "aesopt.h"
#include "aestab.h"
#include "aestab2.h"
/*
* Initialise the key schedule from the user supplied key. The key
* length can be specified in bytes, with legal values of 16, 24
* and 32, or in bits, with legal values of 128, 192 and 256. These
* values correspond with Nk values of 4, 6 and 8 respectively.
*
* The following macros implement a single cycle in the key
* schedule generation process. The number of cycles needed
* for each cx->n_col and nk value is:
*
* nk = 4 5 6 7 8
* ------------------------------
* cx->n_col = 4 10 9 8 7 7
* cx->n_col = 5 14 11 10 9 9
* cx->n_col = 6 19 15 12 11 11
* cx->n_col = 7 21 19 16 13 14
* cx->n_col = 8 29 23 19 17 14
*/
/*
* OpenSolaris changes
* 1. Added header files aes_impl.h and aestab2.h
* 2. Changed uint_8t and uint_32t to uint8_t and uint32_t
* 3. Remove code under ifdef USE_VIA_ACE_IF_PRESENT (always undefined)
* 4. Removed always-defined ifdefs FUNCS_IN_C, ENC_KEYING_IN_C,
* AES_128, AES_192, AES_256, AES_VAR defines
* 5. Changed aes_encrypt_key* aes_decrypt_key* functions to "static void"
* 6. Changed N_COLS to MAX_AES_NB
* 7. Replaced functions aes_encrypt_key and aes_decrypt_key with
* OpenSolaris-compatible functions rijndael_key_setup_enc_amd64 and
* rijndael_key_setup_dec_amd64
* 8. cstyled code and removed lint warnings
*/
#if defined(REDUCE_CODE_SIZE)
#ifdef ENC_KS_UNROLL
#endif
#ifdef DEC_KS_UNROLL
#endif
#endif /* REDUCE_CODE_SIZE */
#define ke4(k, i) \
}
static void
{
#ifdef ENC_KS_UNROLL
#else
{
uint32_t i;
for (i = 0; i < 9; ++i)
}
#endif /* ENC_KS_UNROLL */
}
#define kef6(k, i) \
}
#define ke6(k, i) \
{ kef6(k, i); \
}
static void
{
#ifdef ENC_KS_UNROLL
#else
{
uint32_t i;
for (i = 0; i < 7; ++i)
}
#endif /* ENC_KS_UNROLL */
}
#define kef8(k, i) \
}
#define ke8(k, i) \
{ kef8(k, i); \
}
static void
{
#ifdef ENC_KS_UNROLL
#else
{
uint32_t i;
for (i = 0; i < 6; ++i)
}
#endif /* ENC_KS_UNROLL */
}
/*
* Expand the cipher key into the encryption key schedule.
*
* Return the number of rounds for the given cipher key size.
* The size of the key schedule depends on the number of rounds
* (which can be computed from the size of the key), i.e. 4 * (Nr + 1).
*
* Parameters:
* rk AES key schedule 32-bit array to be initialized
* cipherKey User key
* keyBits AES key size (128, 192, or 256 bits)
*/
int
int keyBits)
{
switch (keyBits) {
case 128:
return (10);
case 192:
return (12);
case 256:
return (14);
default: /* should never get here */
break;
}
return (0);
}
/* this is used to store the decryption round keys */
/* in forward or reverse order */
#ifdef AES_REV_DKS
#define v(n, i) ((n) - (i) + 2 * ((i) & 3))
#else
#define v(n, i) (i)
#endif
#define ff(x) (x)
#else
#if defined(dec_imvars)
#endif
#endif /* FUNCS_IN_C & DEC_KEYING_IN_C */
#define k4e(k, i) \
}
#if 1
#define kdf4(k, i) \
}
#define kd4(k, i) \
}
#define kdl4(k, i) \
}
#else
#define kdf4(k, i) \
}
#define kd4(k, i) \
}
#define kdl4(k, i) \
}
#endif
static void
{
#if defined(d_vars)
#endif
#ifdef DEC_KS_UNROLL
#else
{
uint32_t i;
for (i = 0; i < 10; ++i)
#endif
}
#endif /* DEC_KS_UNROLL */
}
#define k6ef(k, i) \
}
#define k6e(k, i) \
{ k6ef(k, i); \
}
#define kdf6(k, i) \
}
#define kd6(k, i) \
}
#define kdl6(k, i) \
}
static void
{
#if defined(d_vars)
#endif
#ifdef DEC_KS_UNROLL
#else
{
uint32_t i;
for (i = 0; i < 7; ++i)
#endif
}
#endif
}
#define k8ef(k, i) \
}
#define k8e(k, i) \
{ k8ef(k, i); \
}
#define kdf8(k, i) \
}
#define kd8(k, i) \
}
#define kdl8(k, i) \
}
static void
{
#if defined(d_vars)
#endif
#ifdef DEC_KS_UNROLL
#else
{
uint32_t i;
for (i = 0; i < 6; ++i)
#endif
}
#endif /* DEC_KS_UNROLL */
}
/*
* Expand the cipher key into the decryption key schedule.
*
* Return the number of rounds for the given cipher key size.
* The size of the key schedule depends on the number of rounds
* (which can be computed from the size of the key), i.e. 4 * (Nr + 1).
*
* Parameters:
* rk AES key schedule 32-bit array to be initialized
* cipherKey User key
* keyBits AES key size (128, 192, or 256 bits)
*/
int
int keyBits)
{
switch (keyBits) {
case 128:
return (10);
case 192:
return (12);
case 256:
return (14);
default: /* should never get here */
break;
}
return (0);
}