cyassl re-port with cellular comms, PSK test

Dependencies:   VodafoneUSBModem_bleedingedge2 mbed-rtos mbed-src

Committer:
ashleymills
Date:
Fri Apr 26 16:59:36 2013 +0000
Revision:
1:b211d97b0068
Parent:
0:e979170e02e7
nothing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:e979170e02e7 1 /* aes.c
ashleymills 0:e979170e02e7 2 *
ashleymills 0:e979170e02e7 3 * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
ashleymills 0:e979170e02e7 4 *
ashleymills 0:e979170e02e7 5 * This file is part of CyaSSL.
ashleymills 0:e979170e02e7 6 *
ashleymills 0:e979170e02e7 7 * CyaSSL is free software; you can redistribute it and/or modify
ashleymills 0:e979170e02e7 8 * it under the terms of the GNU General Public License as published by
ashleymills 0:e979170e02e7 9 * the Free Software Foundation; either version 2 of the License, or
ashleymills 0:e979170e02e7 10 * (at your option) any later version.
ashleymills 0:e979170e02e7 11 *
ashleymills 0:e979170e02e7 12 * CyaSSL is distributed in the hope that it will be useful,
ashleymills 0:e979170e02e7 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ashleymills 0:e979170e02e7 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ashleymills 0:e979170e02e7 15 * GNU General Public License for more details.
ashleymills 0:e979170e02e7 16 *
ashleymills 0:e979170e02e7 17 * You should have received a copy of the GNU General Public License
ashleymills 0:e979170e02e7 18 * along with this program; if not, write to the Free Software
ashleymills 0:e979170e02e7 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
ashleymills 0:e979170e02e7 20 */
ashleymills 0:e979170e02e7 21
ashleymills 0:e979170e02e7 22 #ifdef HAVE_CONFIG_H
ashleymills 0:e979170e02e7 23 #include <config.h>
ashleymills 0:e979170e02e7 24 #endif
ashleymills 0:e979170e02e7 25
ashleymills 0:e979170e02e7 26 #ifndef NO_AES
ashleymills 0:e979170e02e7 27
ashleymills 0:e979170e02e7 28 #include <cyassl/ctaocrypt/aes.h>
ashleymills 0:e979170e02e7 29 #include <cyassl/ctaocrypt/error.h>
ashleymills 0:e979170e02e7 30 #include <cyassl/ctaocrypt/logging.h>
ashleymills 0:e979170e02e7 31 #ifdef NO_INLINE
ashleymills 0:e979170e02e7 32 #include <cyassl/ctaocrypt/misc.h>
ashleymills 0:e979170e02e7 33 #else
ashleymills 0:e979170e02e7 34 #include <ctaocrypt/src/misc.c>
ashleymills 0:e979170e02e7 35 #endif
ashleymills 0:e979170e02e7 36
ashleymills 0:e979170e02e7 37
ashleymills 0:e979170e02e7 38 #ifdef _MSC_VER
ashleymills 0:e979170e02e7 39 /* 4127 warning constant while(1) */
ashleymills 0:e979170e02e7 40 #pragma warning(disable: 4127)
ashleymills 0:e979170e02e7 41 #endif
ashleymills 0:e979170e02e7 42
ashleymills 0:e979170e02e7 43
ashleymills 0:e979170e02e7 44 #ifdef HAVE_CAVIUM
ashleymills 0:e979170e02e7 45 static int AesCaviumSetKey(Aes* aes, const byte* key, word32 length,
ashleymills 0:e979170e02e7 46 const byte* iv);
ashleymills 0:e979170e02e7 47 static void AesCaviumCbcEncrypt(Aes* aes, byte* out, const byte* in,
ashleymills 0:e979170e02e7 48 word32 length);
ashleymills 0:e979170e02e7 49 static void AesCaviumCbcDecrypt(Aes* aes, byte* out, const byte* in,
ashleymills 0:e979170e02e7 50 word32 length);
ashleymills 0:e979170e02e7 51 #endif
ashleymills 0:e979170e02e7 52
ashleymills 0:e979170e02e7 53 #ifdef STM32F2_CRYPTO
ashleymills 0:e979170e02e7 54 /*
ashleymills 0:e979170e02e7 55 * STM32F2 hardware AES support through the STM32F2 standard peripheral
ashleymills 0:e979170e02e7 56 * library. Documentation located in STM32F2xx Standard Peripheral Library
ashleymills 0:e979170e02e7 57 * document (See note in README).
ashleymills 0:e979170e02e7 58 */
ashleymills 0:e979170e02e7 59 #include "stm32f2xx.h"
ashleymills 0:e979170e02e7 60
ashleymills 0:e979170e02e7 61 int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
ashleymills 0:e979170e02e7 62 int dir)
ashleymills 0:e979170e02e7 63 {
ashleymills 0:e979170e02e7 64 word32 *rk = aes->key;
ashleymills 0:e979170e02e7 65
ashleymills 0:e979170e02e7 66 if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
ashleymills 0:e979170e02e7 67 return BAD_FUNC_ARG;
ashleymills 0:e979170e02e7 68
ashleymills 0:e979170e02e7 69 aes->rounds = keylen/4 + 6;
ashleymills 0:e979170e02e7 70 XMEMCPY(rk, userKey, keylen);
ashleymills 0:e979170e02e7 71 ByteReverseWords(rk, rk, keylen);
ashleymills 0:e979170e02e7 72
ashleymills 0:e979170e02e7 73 return AesSetIV(aes, iv);
ashleymills 0:e979170e02e7 74 }
ashleymills 0:e979170e02e7 75
ashleymills 0:e979170e02e7 76 void AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
ashleymills 0:e979170e02e7 77 {
ashleymills 0:e979170e02e7 78 word32 *enc_key, *iv;
ashleymills 0:e979170e02e7 79 CRYP_InitTypeDef AES_CRYP_InitStructure;
ashleymills 0:e979170e02e7 80 CRYP_KeyInitTypeDef AES_CRYP_KeyInitStructure;
ashleymills 0:e979170e02e7 81 CRYP_IVInitTypeDef AES_CRYP_IVInitStructure;
ashleymills 0:e979170e02e7 82
ashleymills 0:e979170e02e7 83 enc_key = aes->key;
ashleymills 0:e979170e02e7 84 iv = aes->reg;
ashleymills 0:e979170e02e7 85
ashleymills 0:e979170e02e7 86 /* crypto structure initialization */
ashleymills 0:e979170e02e7 87 CRYP_KeyStructInit(&AES_CRYP_KeyInitStructure);
ashleymills 0:e979170e02e7 88 CRYP_StructInit(&AES_CRYP_InitStructure);
ashleymills 0:e979170e02e7 89 CRYP_IVStructInit(&AES_CRYP_IVInitStructure);
ashleymills 0:e979170e02e7 90
ashleymills 0:e979170e02e7 91 /* reset registers to their default values */
ashleymills 0:e979170e02e7 92 CRYP_DeInit();
ashleymills 0:e979170e02e7 93
ashleymills 0:e979170e02e7 94 /* load key into correct registers */
ashleymills 0:e979170e02e7 95 switch(aes->rounds)
ashleymills 0:e979170e02e7 96 {
ashleymills 0:e979170e02e7 97 case 10: /* 128-bit key */
ashleymills 0:e979170e02e7 98 AES_CRYP_InitStructure.CRYP_KeySize = CRYP_KeySize_128b;
ashleymills 0:e979170e02e7 99 AES_CRYP_KeyInitStructure.CRYP_Key2Left = enc_key[0];
ashleymills 0:e979170e02e7 100 AES_CRYP_KeyInitStructure.CRYP_Key2Right = enc_key[1];
ashleymills 0:e979170e02e7 101 AES_CRYP_KeyInitStructure.CRYP_Key3Left = enc_key[2];
ashleymills 0:e979170e02e7 102 AES_CRYP_KeyInitStructure.CRYP_Key3Right = enc_key[3];
ashleymills 0:e979170e02e7 103 break;
ashleymills 0:e979170e02e7 104
ashleymills 0:e979170e02e7 105 case 12: /* 192-bit key */
ashleymills 0:e979170e02e7 106 AES_CRYP_InitStructure.CRYP_KeySize = CRYP_KeySize_192b;
ashleymills 0:e979170e02e7 107 AES_CRYP_KeyInitStructure.CRYP_Key1Left = enc_key[0];
ashleymills 0:e979170e02e7 108 AES_CRYP_KeyInitStructure.CRYP_Key1Right = enc_key[1];
ashleymills 0:e979170e02e7 109 AES_CRYP_KeyInitStructure.CRYP_Key2Left = enc_key[2];
ashleymills 0:e979170e02e7 110 AES_CRYP_KeyInitStructure.CRYP_Key2Right = enc_key[3];
ashleymills 0:e979170e02e7 111 AES_CRYP_KeyInitStructure.CRYP_Key3Left = enc_key[4];
ashleymills 0:e979170e02e7 112 AES_CRYP_KeyInitStructure.CRYP_Key3Right = enc_key[5];
ashleymills 0:e979170e02e7 113 break;
ashleymills 0:e979170e02e7 114
ashleymills 0:e979170e02e7 115 case 14: /* 256-bit key */
ashleymills 0:e979170e02e7 116 AES_CRYP_InitStructure.CRYP_KeySize = CRYP_KeySize_256b;
ashleymills 0:e979170e02e7 117 AES_CRYP_KeyInitStructure.CRYP_Key0Left = enc_key[0];
ashleymills 0:e979170e02e7 118 AES_CRYP_KeyInitStructure.CRYP_Key0Right = enc_key[1];
ashleymills 0:e979170e02e7 119 AES_CRYP_KeyInitStructure.CRYP_Key1Left = enc_key[2];
ashleymills 0:e979170e02e7 120 AES_CRYP_KeyInitStructure.CRYP_Key1Right = enc_key[3];
ashleymills 0:e979170e02e7 121 AES_CRYP_KeyInitStructure.CRYP_Key2Left = enc_key[4];
ashleymills 0:e979170e02e7 122 AES_CRYP_KeyInitStructure.CRYP_Key2Right = enc_key[5];
ashleymills 0:e979170e02e7 123 AES_CRYP_KeyInitStructure.CRYP_Key3Left = enc_key[6];
ashleymills 0:e979170e02e7 124 AES_CRYP_KeyInitStructure.CRYP_Key3Right = enc_key[7];
ashleymills 0:e979170e02e7 125 break;
ashleymills 0:e979170e02e7 126
ashleymills 0:e979170e02e7 127 default:
ashleymills 0:e979170e02e7 128 break;
ashleymills 0:e979170e02e7 129 }
ashleymills 0:e979170e02e7 130 CRYP_KeyInit(&AES_CRYP_KeyInitStructure);
ashleymills 0:e979170e02e7 131
ashleymills 0:e979170e02e7 132 /* set iv */
ashleymills 0:e979170e02e7 133 ByteReverseWords(iv, iv, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 134 AES_CRYP_IVInitStructure.CRYP_IV0Left = iv[0];
ashleymills 0:e979170e02e7 135 AES_CRYP_IVInitStructure.CRYP_IV0Right = iv[1];
ashleymills 0:e979170e02e7 136 AES_CRYP_IVInitStructure.CRYP_IV1Left = iv[2];
ashleymills 0:e979170e02e7 137 AES_CRYP_IVInitStructure.CRYP_IV1Right = iv[3];
ashleymills 0:e979170e02e7 138 CRYP_IVInit(&AES_CRYP_IVInitStructure);
ashleymills 0:e979170e02e7 139
ashleymills 0:e979170e02e7 140 /* set direction, mode, and datatype */
ashleymills 0:e979170e02e7 141 AES_CRYP_InitStructure.CRYP_AlgoDir = CRYP_AlgoDir_Encrypt;
ashleymills 0:e979170e02e7 142 AES_CRYP_InitStructure.CRYP_AlgoMode = CRYP_AlgoMode_AES_CBC;
ashleymills 0:e979170e02e7 143 AES_CRYP_InitStructure.CRYP_DataType = CRYP_DataType_8b;
ashleymills 0:e979170e02e7 144 CRYP_Init(&AES_CRYP_InitStructure);
ashleymills 0:e979170e02e7 145
ashleymills 0:e979170e02e7 146 /* enable crypto processor */
ashleymills 0:e979170e02e7 147 CRYP_Cmd(ENABLE);
ashleymills 0:e979170e02e7 148
ashleymills 0:e979170e02e7 149 while (sz > 0)
ashleymills 0:e979170e02e7 150 {
ashleymills 0:e979170e02e7 151 /* flush IN/OUT FIFOs */
ashleymills 0:e979170e02e7 152 CRYP_FIFOFlush();
ashleymills 0:e979170e02e7 153
ashleymills 0:e979170e02e7 154 CRYP_DataIn(*(uint32_t*)&in[0]);
ashleymills 0:e979170e02e7 155 CRYP_DataIn(*(uint32_t*)&in[4]);
ashleymills 0:e979170e02e7 156 CRYP_DataIn(*(uint32_t*)&in[8]);
ashleymills 0:e979170e02e7 157 CRYP_DataIn(*(uint32_t*)&in[12]);
ashleymills 0:e979170e02e7 158
ashleymills 0:e979170e02e7 159 /* wait until the complete message has been processed */
ashleymills 0:e979170e02e7 160 while(CRYP_GetFlagStatus(CRYP_FLAG_BUSY) != RESET) {}
ashleymills 0:e979170e02e7 161
ashleymills 0:e979170e02e7 162 *(uint32_t*)&out[0] = CRYP_DataOut();
ashleymills 0:e979170e02e7 163 *(uint32_t*)&out[4] = CRYP_DataOut();
ashleymills 0:e979170e02e7 164 *(uint32_t*)&out[8] = CRYP_DataOut();
ashleymills 0:e979170e02e7 165 *(uint32_t*)&out[12] = CRYP_DataOut();
ashleymills 0:e979170e02e7 166
ashleymills 0:e979170e02e7 167 /* store iv for next call */
ashleymills 0:e979170e02e7 168 XMEMCPY(aes->reg, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 169
ashleymills 0:e979170e02e7 170 sz -= 16;
ashleymills 0:e979170e02e7 171 in += 16;
ashleymills 0:e979170e02e7 172 out += 16;
ashleymills 0:e979170e02e7 173 }
ashleymills 0:e979170e02e7 174
ashleymills 0:e979170e02e7 175 /* disable crypto processor */
ashleymills 0:e979170e02e7 176 CRYP_Cmd(DISABLE);
ashleymills 0:e979170e02e7 177 }
ashleymills 0:e979170e02e7 178
ashleymills 0:e979170e02e7 179 void AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
ashleymills 0:e979170e02e7 180 {
ashleymills 0:e979170e02e7 181 word32 *dec_key, *iv;
ashleymills 0:e979170e02e7 182 CRYP_InitTypeDef AES_CRYP_InitStructure;
ashleymills 0:e979170e02e7 183 CRYP_KeyInitTypeDef AES_CRYP_KeyInitStructure;
ashleymills 0:e979170e02e7 184 CRYP_IVInitTypeDef AES_CRYP_IVInitStructure;
ashleymills 0:e979170e02e7 185
ashleymills 0:e979170e02e7 186 dec_key = aes->key;
ashleymills 0:e979170e02e7 187 iv = aes->reg;
ashleymills 0:e979170e02e7 188
ashleymills 0:e979170e02e7 189 /* crypto structure initialization */
ashleymills 0:e979170e02e7 190 CRYP_KeyStructInit(&AES_CRYP_KeyInitStructure);
ashleymills 0:e979170e02e7 191 CRYP_StructInit(&AES_CRYP_InitStructure);
ashleymills 0:e979170e02e7 192 CRYP_IVStructInit(&AES_CRYP_IVInitStructure);
ashleymills 0:e979170e02e7 193
ashleymills 0:e979170e02e7 194 /* if input and output same will overwrite input iv */
ashleymills 0:e979170e02e7 195 XMEMCPY(aes->tmp, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 196
ashleymills 0:e979170e02e7 197 /* reset registers to their default values */
ashleymills 0:e979170e02e7 198 CRYP_DeInit();
ashleymills 0:e979170e02e7 199
ashleymills 0:e979170e02e7 200 /* load key into correct registers */
ashleymills 0:e979170e02e7 201 switch(aes->rounds)
ashleymills 0:e979170e02e7 202 {
ashleymills 0:e979170e02e7 203 case 10: /* 128-bit key */
ashleymills 0:e979170e02e7 204 AES_CRYP_InitStructure.CRYP_KeySize = CRYP_KeySize_128b;
ashleymills 0:e979170e02e7 205 AES_CRYP_KeyInitStructure.CRYP_Key2Left = dec_key[0];
ashleymills 0:e979170e02e7 206 AES_CRYP_KeyInitStructure.CRYP_Key2Right = dec_key[1];
ashleymills 0:e979170e02e7 207 AES_CRYP_KeyInitStructure.CRYP_Key3Left = dec_key[2];
ashleymills 0:e979170e02e7 208 AES_CRYP_KeyInitStructure.CRYP_Key3Right = dec_key[3];
ashleymills 0:e979170e02e7 209 break;
ashleymills 0:e979170e02e7 210
ashleymills 0:e979170e02e7 211 case 12: /* 192-bit key */
ashleymills 0:e979170e02e7 212 AES_CRYP_InitStructure.CRYP_KeySize = CRYP_KeySize_192b;
ashleymills 0:e979170e02e7 213 AES_CRYP_KeyInitStructure.CRYP_Key1Left = dec_key[0];
ashleymills 0:e979170e02e7 214 AES_CRYP_KeyInitStructure.CRYP_Key1Right = dec_key[1];
ashleymills 0:e979170e02e7 215 AES_CRYP_KeyInitStructure.CRYP_Key2Left = dec_key[2];
ashleymills 0:e979170e02e7 216 AES_CRYP_KeyInitStructure.CRYP_Key2Right = dec_key[3];
ashleymills 0:e979170e02e7 217 AES_CRYP_KeyInitStructure.CRYP_Key3Left = dec_key[4];
ashleymills 0:e979170e02e7 218 AES_CRYP_KeyInitStructure.CRYP_Key3Right = dec_key[5];
ashleymills 0:e979170e02e7 219 break;
ashleymills 0:e979170e02e7 220
ashleymills 0:e979170e02e7 221 case 14: /* 256-bit key */
ashleymills 0:e979170e02e7 222 AES_CRYP_InitStructure.CRYP_KeySize = CRYP_KeySize_256b;
ashleymills 0:e979170e02e7 223 AES_CRYP_KeyInitStructure.CRYP_Key0Left = dec_key[0];
ashleymills 0:e979170e02e7 224 AES_CRYP_KeyInitStructure.CRYP_Key0Right = dec_key[1];
ashleymills 0:e979170e02e7 225 AES_CRYP_KeyInitStructure.CRYP_Key1Left = dec_key[2];
ashleymills 0:e979170e02e7 226 AES_CRYP_KeyInitStructure.CRYP_Key1Right = dec_key[3];
ashleymills 0:e979170e02e7 227 AES_CRYP_KeyInitStructure.CRYP_Key2Left = dec_key[4];
ashleymills 0:e979170e02e7 228 AES_CRYP_KeyInitStructure.CRYP_Key2Right = dec_key[5];
ashleymills 0:e979170e02e7 229 AES_CRYP_KeyInitStructure.CRYP_Key3Left = dec_key[6];
ashleymills 0:e979170e02e7 230 AES_CRYP_KeyInitStructure.CRYP_Key3Right = dec_key[7];
ashleymills 0:e979170e02e7 231 break;
ashleymills 0:e979170e02e7 232
ashleymills 0:e979170e02e7 233 default:
ashleymills 0:e979170e02e7 234 break;
ashleymills 0:e979170e02e7 235 }
ashleymills 0:e979170e02e7 236
ashleymills 0:e979170e02e7 237 /* set direction, mode, and datatype for key preparation */
ashleymills 0:e979170e02e7 238 AES_CRYP_InitStructure.CRYP_AlgoDir = CRYP_AlgoDir_Decrypt;
ashleymills 0:e979170e02e7 239 AES_CRYP_InitStructure.CRYP_AlgoMode = CRYP_AlgoMode_AES_Key;
ashleymills 0:e979170e02e7 240 AES_CRYP_InitStructure.CRYP_DataType = CRYP_DataType_32b;
ashleymills 0:e979170e02e7 241 CRYP_Init(&AES_CRYP_InitStructure);
ashleymills 0:e979170e02e7 242 CRYP_KeyInit(&AES_CRYP_KeyInitStructure);
ashleymills 0:e979170e02e7 243
ashleymills 0:e979170e02e7 244 /* enable crypto processor */
ashleymills 0:e979170e02e7 245 CRYP_Cmd(ENABLE);
ashleymills 0:e979170e02e7 246
ashleymills 0:e979170e02e7 247 /* wait until key has been prepared */
ashleymills 0:e979170e02e7 248 while(CRYP_GetFlagStatus(CRYP_FLAG_BUSY) != RESET) {}
ashleymills 0:e979170e02e7 249
ashleymills 0:e979170e02e7 250 /* set direction, mode, and datatype for decryption */
ashleymills 0:e979170e02e7 251 AES_CRYP_InitStructure.CRYP_AlgoDir = CRYP_AlgoDir_Decrypt;
ashleymills 0:e979170e02e7 252 AES_CRYP_InitStructure.CRYP_AlgoMode = CRYP_AlgoMode_AES_CBC;
ashleymills 0:e979170e02e7 253 AES_CRYP_InitStructure.CRYP_DataType = CRYP_DataType_8b;
ashleymills 0:e979170e02e7 254 CRYP_Init(&AES_CRYP_InitStructure);
ashleymills 0:e979170e02e7 255
ashleymills 0:e979170e02e7 256 /* set iv */
ashleymills 0:e979170e02e7 257 ByteReverseWords(iv, iv, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 258
ashleymills 0:e979170e02e7 259 AES_CRYP_IVInitStructure.CRYP_IV0Left = iv[0];
ashleymills 0:e979170e02e7 260 AES_CRYP_IVInitStructure.CRYP_IV0Right = iv[1];
ashleymills 0:e979170e02e7 261 AES_CRYP_IVInitStructure.CRYP_IV1Left = iv[2];
ashleymills 0:e979170e02e7 262 AES_CRYP_IVInitStructure.CRYP_IV1Right = iv[3];
ashleymills 0:e979170e02e7 263 CRYP_IVInit(&AES_CRYP_IVInitStructure);
ashleymills 0:e979170e02e7 264
ashleymills 0:e979170e02e7 265 /* enable crypto processor */
ashleymills 0:e979170e02e7 266 CRYP_Cmd(ENABLE);
ashleymills 0:e979170e02e7 267
ashleymills 0:e979170e02e7 268 while (sz > 0)
ashleymills 0:e979170e02e7 269 {
ashleymills 0:e979170e02e7 270 /* flush IN/OUT FIFOs */
ashleymills 0:e979170e02e7 271 CRYP_FIFOFlush();
ashleymills 0:e979170e02e7 272
ashleymills 0:e979170e02e7 273 CRYP_DataIn(*(uint32_t*)&in[0]);
ashleymills 0:e979170e02e7 274 CRYP_DataIn(*(uint32_t*)&in[4]);
ashleymills 0:e979170e02e7 275 CRYP_DataIn(*(uint32_t*)&in[8]);
ashleymills 0:e979170e02e7 276 CRYP_DataIn(*(uint32_t*)&in[12]);
ashleymills 0:e979170e02e7 277
ashleymills 0:e979170e02e7 278 /* wait until the complete message has been processed */
ashleymills 0:e979170e02e7 279 while(CRYP_GetFlagStatus(CRYP_FLAG_BUSY) != RESET) {}
ashleymills 0:e979170e02e7 280
ashleymills 0:e979170e02e7 281 *(uint32_t*)&out[0] = CRYP_DataOut();
ashleymills 0:e979170e02e7 282 *(uint32_t*)&out[4] = CRYP_DataOut();
ashleymills 0:e979170e02e7 283 *(uint32_t*)&out[8] = CRYP_DataOut();
ashleymills 0:e979170e02e7 284 *(uint32_t*)&out[12] = CRYP_DataOut();
ashleymills 0:e979170e02e7 285
ashleymills 0:e979170e02e7 286 /* store iv for next call */
ashleymills 0:e979170e02e7 287 XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 288
ashleymills 0:e979170e02e7 289 sz -= 16;
ashleymills 0:e979170e02e7 290 in += 16;
ashleymills 0:e979170e02e7 291 out += 16;
ashleymills 0:e979170e02e7 292 }
ashleymills 0:e979170e02e7 293
ashleymills 0:e979170e02e7 294 /* disable crypto processor */
ashleymills 0:e979170e02e7 295 CRYP_Cmd(DISABLE);
ashleymills 0:e979170e02e7 296 }
ashleymills 0:e979170e02e7 297
ashleymills 0:e979170e02e7 298 #ifdef CYASSL_AES_COUNTER
ashleymills 0:e979170e02e7 299
ashleymills 0:e979170e02e7 300 /* AES-CTR calls this for key setup */
ashleymills 0:e979170e02e7 301 int AesSetKeyDirect(Aes* aes, const byte* userKey, word32 keylen,
ashleymills 0:e979170e02e7 302 const byte* iv, int dir)
ashleymills 0:e979170e02e7 303 {
ashleymills 0:e979170e02e7 304 return AesSetKey(aes, userKey, keylen, iv, dir);
ashleymills 0:e979170e02e7 305 }
ashleymills 0:e979170e02e7 306
ashleymills 0:e979170e02e7 307 void AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
ashleymills 0:e979170e02e7 308 {
ashleymills 0:e979170e02e7 309 word32 *enc_key, *iv;
ashleymills 0:e979170e02e7 310 CRYP_InitTypeDef AES_CRYP_InitStructure;
ashleymills 0:e979170e02e7 311 CRYP_KeyInitTypeDef AES_CRYP_KeyInitStructure;
ashleymills 0:e979170e02e7 312 CRYP_IVInitTypeDef AES_CRYP_IVInitStructure;
ashleymills 0:e979170e02e7 313
ashleymills 0:e979170e02e7 314 enc_key = aes->key;
ashleymills 0:e979170e02e7 315 iv = aes->reg;
ashleymills 0:e979170e02e7 316
ashleymills 0:e979170e02e7 317 /* crypto structure initialization */
ashleymills 0:e979170e02e7 318 CRYP_KeyStructInit(&AES_CRYP_KeyInitStructure);
ashleymills 0:e979170e02e7 319 CRYP_StructInit(&AES_CRYP_InitStructure);
ashleymills 0:e979170e02e7 320 CRYP_IVStructInit(&AES_CRYP_IVInitStructure);
ashleymills 0:e979170e02e7 321
ashleymills 0:e979170e02e7 322 /* reset registers to their default values */
ashleymills 0:e979170e02e7 323 CRYP_DeInit();
ashleymills 0:e979170e02e7 324
ashleymills 0:e979170e02e7 325 /* load key into correct registers */
ashleymills 0:e979170e02e7 326 switch(aes->rounds)
ashleymills 0:e979170e02e7 327 {
ashleymills 0:e979170e02e7 328 case 10: /* 128-bit key */
ashleymills 0:e979170e02e7 329 AES_CRYP_InitStructure.CRYP_KeySize = CRYP_KeySize_128b;
ashleymills 0:e979170e02e7 330 AES_CRYP_KeyInitStructure.CRYP_Key2Left = enc_key[0];
ashleymills 0:e979170e02e7 331 AES_CRYP_KeyInitStructure.CRYP_Key2Right = enc_key[1];
ashleymills 0:e979170e02e7 332 AES_CRYP_KeyInitStructure.CRYP_Key3Left = enc_key[2];
ashleymills 0:e979170e02e7 333 AES_CRYP_KeyInitStructure.CRYP_Key3Right = enc_key[3];
ashleymills 0:e979170e02e7 334 break;
ashleymills 0:e979170e02e7 335
ashleymills 0:e979170e02e7 336 case 12: /* 192-bit key */
ashleymills 0:e979170e02e7 337 AES_CRYP_InitStructure.CRYP_KeySize = CRYP_KeySize_192b;
ashleymills 0:e979170e02e7 338 AES_CRYP_KeyInitStructure.CRYP_Key1Left = enc_key[0];
ashleymills 0:e979170e02e7 339 AES_CRYP_KeyInitStructure.CRYP_Key1Right = enc_key[1];
ashleymills 0:e979170e02e7 340 AES_CRYP_KeyInitStructure.CRYP_Key2Left = enc_key[2];
ashleymills 0:e979170e02e7 341 AES_CRYP_KeyInitStructure.CRYP_Key2Right = enc_key[3];
ashleymills 0:e979170e02e7 342 AES_CRYP_KeyInitStructure.CRYP_Key3Left = enc_key[4];
ashleymills 0:e979170e02e7 343 AES_CRYP_KeyInitStructure.CRYP_Key3Right = enc_key[5];
ashleymills 0:e979170e02e7 344 break;
ashleymills 0:e979170e02e7 345
ashleymills 0:e979170e02e7 346 case 14: /* 256-bit key */
ashleymills 0:e979170e02e7 347 AES_CRYP_InitStructure.CRYP_KeySize = CRYP_KeySize_256b;
ashleymills 0:e979170e02e7 348 AES_CRYP_KeyInitStructure.CRYP_Key0Left = enc_key[0];
ashleymills 0:e979170e02e7 349 AES_CRYP_KeyInitStructure.CRYP_Key0Right = enc_key[1];
ashleymills 0:e979170e02e7 350 AES_CRYP_KeyInitStructure.CRYP_Key1Left = enc_key[2];
ashleymills 0:e979170e02e7 351 AES_CRYP_KeyInitStructure.CRYP_Key1Right = enc_key[3];
ashleymills 0:e979170e02e7 352 AES_CRYP_KeyInitStructure.CRYP_Key2Left = enc_key[4];
ashleymills 0:e979170e02e7 353 AES_CRYP_KeyInitStructure.CRYP_Key2Right = enc_key[5];
ashleymills 0:e979170e02e7 354 AES_CRYP_KeyInitStructure.CRYP_Key3Left = enc_key[6];
ashleymills 0:e979170e02e7 355 AES_CRYP_KeyInitStructure.CRYP_Key3Right = enc_key[7];
ashleymills 0:e979170e02e7 356 break;
ashleymills 0:e979170e02e7 357
ashleymills 0:e979170e02e7 358 default:
ashleymills 0:e979170e02e7 359 break;
ashleymills 0:e979170e02e7 360 }
ashleymills 0:e979170e02e7 361 CRYP_KeyInit(&AES_CRYP_KeyInitStructure);
ashleymills 0:e979170e02e7 362
ashleymills 0:e979170e02e7 363 /* set iv */
ashleymills 0:e979170e02e7 364 ByteReverseWords(iv, iv, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 365 AES_CRYP_IVInitStructure.CRYP_IV0Left = iv[0];
ashleymills 0:e979170e02e7 366 AES_CRYP_IVInitStructure.CRYP_IV0Right = iv[1];
ashleymills 0:e979170e02e7 367 AES_CRYP_IVInitStructure.CRYP_IV1Left = iv[2];
ashleymills 0:e979170e02e7 368 AES_CRYP_IVInitStructure.CRYP_IV1Right = iv[3];
ashleymills 0:e979170e02e7 369 CRYP_IVInit(&AES_CRYP_IVInitStructure);
ashleymills 0:e979170e02e7 370
ashleymills 0:e979170e02e7 371 /* set direction, mode, and datatype */
ashleymills 0:e979170e02e7 372 AES_CRYP_InitStructure.CRYP_AlgoDir = CRYP_AlgoDir_Encrypt;
ashleymills 0:e979170e02e7 373 AES_CRYP_InitStructure.CRYP_AlgoMode = CRYP_AlgoMode_AES_CTR;
ashleymills 0:e979170e02e7 374 AES_CRYP_InitStructure.CRYP_DataType = CRYP_DataType_8b;
ashleymills 0:e979170e02e7 375 CRYP_Init(&AES_CRYP_InitStructure);
ashleymills 0:e979170e02e7 376
ashleymills 0:e979170e02e7 377 /* enable crypto processor */
ashleymills 0:e979170e02e7 378 CRYP_Cmd(ENABLE);
ashleymills 0:e979170e02e7 379
ashleymills 0:e979170e02e7 380 while (sz > 0)
ashleymills 0:e979170e02e7 381 {
ashleymills 0:e979170e02e7 382 /* flush IN/OUT FIFOs */
ashleymills 0:e979170e02e7 383 CRYP_FIFOFlush();
ashleymills 0:e979170e02e7 384
ashleymills 0:e979170e02e7 385 CRYP_DataIn(*(uint32_t*)&in[0]);
ashleymills 0:e979170e02e7 386 CRYP_DataIn(*(uint32_t*)&in[4]);
ashleymills 0:e979170e02e7 387 CRYP_DataIn(*(uint32_t*)&in[8]);
ashleymills 0:e979170e02e7 388 CRYP_DataIn(*(uint32_t*)&in[12]);
ashleymills 0:e979170e02e7 389
ashleymills 0:e979170e02e7 390 /* wait until the complete message has been processed */
ashleymills 0:e979170e02e7 391 while(CRYP_GetFlagStatus(CRYP_FLAG_BUSY) != RESET) {}
ashleymills 0:e979170e02e7 392
ashleymills 0:e979170e02e7 393 *(uint32_t*)&out[0] = CRYP_DataOut();
ashleymills 0:e979170e02e7 394 *(uint32_t*)&out[4] = CRYP_DataOut();
ashleymills 0:e979170e02e7 395 *(uint32_t*)&out[8] = CRYP_DataOut();
ashleymills 0:e979170e02e7 396 *(uint32_t*)&out[12] = CRYP_DataOut();
ashleymills 0:e979170e02e7 397
ashleymills 0:e979170e02e7 398 /* store iv for next call */
ashleymills 0:e979170e02e7 399 XMEMCPY(aes->reg, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 400
ashleymills 0:e979170e02e7 401 sz -= 16;
ashleymills 0:e979170e02e7 402 in += 16;
ashleymills 0:e979170e02e7 403 out += 16;
ashleymills 0:e979170e02e7 404 }
ashleymills 0:e979170e02e7 405
ashleymills 0:e979170e02e7 406 /* disable crypto processor */
ashleymills 0:e979170e02e7 407 CRYP_Cmd(DISABLE);
ashleymills 0:e979170e02e7 408 }
ashleymills 0:e979170e02e7 409
ashleymills 0:e979170e02e7 410 #endif /* CYASSL_AES_COUNTER */
ashleymills 0:e979170e02e7 411
ashleymills 0:e979170e02e7 412 #else /* CTaoCrypt software implementation */
ashleymills 0:e979170e02e7 413
ashleymills 0:e979170e02e7 414 static const word32 rcon[] = {
ashleymills 0:e979170e02e7 415 0x01000000, 0x02000000, 0x04000000, 0x08000000,
ashleymills 0:e979170e02e7 416 0x10000000, 0x20000000, 0x40000000, 0x80000000,
ashleymills 0:e979170e02e7 417 0x1B000000, 0x36000000,
ashleymills 0:e979170e02e7 418 /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
ashleymills 0:e979170e02e7 419 };
ashleymills 0:e979170e02e7 420
ashleymills 0:e979170e02e7 421
ashleymills 0:e979170e02e7 422 static const word32 Te[5][256] = {
ashleymills 0:e979170e02e7 423 {
ashleymills 0:e979170e02e7 424 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
ashleymills 0:e979170e02e7 425 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
ashleymills 0:e979170e02e7 426 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
ashleymills 0:e979170e02e7 427 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
ashleymills 0:e979170e02e7 428 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
ashleymills 0:e979170e02e7 429 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
ashleymills 0:e979170e02e7 430 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
ashleymills 0:e979170e02e7 431 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
ashleymills 0:e979170e02e7 432 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
ashleymills 0:e979170e02e7 433 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
ashleymills 0:e979170e02e7 434 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
ashleymills 0:e979170e02e7 435 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
ashleymills 0:e979170e02e7 436 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
ashleymills 0:e979170e02e7 437 0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
ashleymills 0:e979170e02e7 438 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
ashleymills 0:e979170e02e7 439 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
ashleymills 0:e979170e02e7 440 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
ashleymills 0:e979170e02e7 441 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
ashleymills 0:e979170e02e7 442 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
ashleymills 0:e979170e02e7 443 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
ashleymills 0:e979170e02e7 444 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
ashleymills 0:e979170e02e7 445 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
ashleymills 0:e979170e02e7 446 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
ashleymills 0:e979170e02e7 447 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
ashleymills 0:e979170e02e7 448 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
ashleymills 0:e979170e02e7 449 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
ashleymills 0:e979170e02e7 450 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
ashleymills 0:e979170e02e7 451 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
ashleymills 0:e979170e02e7 452 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
ashleymills 0:e979170e02e7 453 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
ashleymills 0:e979170e02e7 454 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
ashleymills 0:e979170e02e7 455 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
ashleymills 0:e979170e02e7 456 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
ashleymills 0:e979170e02e7 457 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
ashleymills 0:e979170e02e7 458 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
ashleymills 0:e979170e02e7 459 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
ashleymills 0:e979170e02e7 460 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
ashleymills 0:e979170e02e7 461 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
ashleymills 0:e979170e02e7 462 0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
ashleymills 0:e979170e02e7 463 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
ashleymills 0:e979170e02e7 464 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
ashleymills 0:e979170e02e7 465 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
ashleymills 0:e979170e02e7 466 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
ashleymills 0:e979170e02e7 467 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
ashleymills 0:e979170e02e7 468 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
ashleymills 0:e979170e02e7 469 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
ashleymills 0:e979170e02e7 470 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
ashleymills 0:e979170e02e7 471 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
ashleymills 0:e979170e02e7 472 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
ashleymills 0:e979170e02e7 473 0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
ashleymills 0:e979170e02e7 474 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
ashleymills 0:e979170e02e7 475 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
ashleymills 0:e979170e02e7 476 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
ashleymills 0:e979170e02e7 477 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
ashleymills 0:e979170e02e7 478 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
ashleymills 0:e979170e02e7 479 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
ashleymills 0:e979170e02e7 480 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
ashleymills 0:e979170e02e7 481 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
ashleymills 0:e979170e02e7 482 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
ashleymills 0:e979170e02e7 483 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
ashleymills 0:e979170e02e7 484 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
ashleymills 0:e979170e02e7 485 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
ashleymills 0:e979170e02e7 486 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
ashleymills 0:e979170e02e7 487 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
ashleymills 0:e979170e02e7 488 },
ashleymills 0:e979170e02e7 489 {
ashleymills 0:e979170e02e7 490 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
ashleymills 0:e979170e02e7 491 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
ashleymills 0:e979170e02e7 492 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
ashleymills 0:e979170e02e7 493 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
ashleymills 0:e979170e02e7 494 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
ashleymills 0:e979170e02e7 495 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
ashleymills 0:e979170e02e7 496 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
ashleymills 0:e979170e02e7 497 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
ashleymills 0:e979170e02e7 498 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
ashleymills 0:e979170e02e7 499 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
ashleymills 0:e979170e02e7 500 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
ashleymills 0:e979170e02e7 501 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
ashleymills 0:e979170e02e7 502 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
ashleymills 0:e979170e02e7 503 0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
ashleymills 0:e979170e02e7 504 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
ashleymills 0:e979170e02e7 505 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
ashleymills 0:e979170e02e7 506 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
ashleymills 0:e979170e02e7 507 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
ashleymills 0:e979170e02e7 508 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
ashleymills 0:e979170e02e7 509 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
ashleymills 0:e979170e02e7 510 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
ashleymills 0:e979170e02e7 511 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
ashleymills 0:e979170e02e7 512 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
ashleymills 0:e979170e02e7 513 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
ashleymills 0:e979170e02e7 514 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
ashleymills 0:e979170e02e7 515 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
ashleymills 0:e979170e02e7 516 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
ashleymills 0:e979170e02e7 517 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
ashleymills 0:e979170e02e7 518 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
ashleymills 0:e979170e02e7 519 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
ashleymills 0:e979170e02e7 520 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
ashleymills 0:e979170e02e7 521 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
ashleymills 0:e979170e02e7 522 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
ashleymills 0:e979170e02e7 523 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
ashleymills 0:e979170e02e7 524 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
ashleymills 0:e979170e02e7 525 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
ashleymills 0:e979170e02e7 526 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
ashleymills 0:e979170e02e7 527 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
ashleymills 0:e979170e02e7 528 0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
ashleymills 0:e979170e02e7 529 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
ashleymills 0:e979170e02e7 530 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
ashleymills 0:e979170e02e7 531 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
ashleymills 0:e979170e02e7 532 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
ashleymills 0:e979170e02e7 533 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
ashleymills 0:e979170e02e7 534 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
ashleymills 0:e979170e02e7 535 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
ashleymills 0:e979170e02e7 536 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
ashleymills 0:e979170e02e7 537 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
ashleymills 0:e979170e02e7 538 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
ashleymills 0:e979170e02e7 539 0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
ashleymills 0:e979170e02e7 540 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
ashleymills 0:e979170e02e7 541 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
ashleymills 0:e979170e02e7 542 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
ashleymills 0:e979170e02e7 543 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
ashleymills 0:e979170e02e7 544 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
ashleymills 0:e979170e02e7 545 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
ashleymills 0:e979170e02e7 546 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
ashleymills 0:e979170e02e7 547 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
ashleymills 0:e979170e02e7 548 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
ashleymills 0:e979170e02e7 549 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
ashleymills 0:e979170e02e7 550 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
ashleymills 0:e979170e02e7 551 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
ashleymills 0:e979170e02e7 552 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
ashleymills 0:e979170e02e7 553 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
ashleymills 0:e979170e02e7 554 },
ashleymills 0:e979170e02e7 555 {
ashleymills 0:e979170e02e7 556 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
ashleymills 0:e979170e02e7 557 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
ashleymills 0:e979170e02e7 558 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
ashleymills 0:e979170e02e7 559 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
ashleymills 0:e979170e02e7 560 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
ashleymills 0:e979170e02e7 561 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
ashleymills 0:e979170e02e7 562 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
ashleymills 0:e979170e02e7 563 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
ashleymills 0:e979170e02e7 564 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
ashleymills 0:e979170e02e7 565 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
ashleymills 0:e979170e02e7 566 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
ashleymills 0:e979170e02e7 567 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
ashleymills 0:e979170e02e7 568 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
ashleymills 0:e979170e02e7 569 0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
ashleymills 0:e979170e02e7 570 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
ashleymills 0:e979170e02e7 571 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
ashleymills 0:e979170e02e7 572 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
ashleymills 0:e979170e02e7 573 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
ashleymills 0:e979170e02e7 574 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
ashleymills 0:e979170e02e7 575 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
ashleymills 0:e979170e02e7 576 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
ashleymills 0:e979170e02e7 577 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
ashleymills 0:e979170e02e7 578 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
ashleymills 0:e979170e02e7 579 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
ashleymills 0:e979170e02e7 580 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
ashleymills 0:e979170e02e7 581 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
ashleymills 0:e979170e02e7 582 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
ashleymills 0:e979170e02e7 583 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
ashleymills 0:e979170e02e7 584 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
ashleymills 0:e979170e02e7 585 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
ashleymills 0:e979170e02e7 586 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
ashleymills 0:e979170e02e7 587 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
ashleymills 0:e979170e02e7 588 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
ashleymills 0:e979170e02e7 589 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
ashleymills 0:e979170e02e7 590 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
ashleymills 0:e979170e02e7 591 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
ashleymills 0:e979170e02e7 592 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
ashleymills 0:e979170e02e7 593 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
ashleymills 0:e979170e02e7 594 0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
ashleymills 0:e979170e02e7 595 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
ashleymills 0:e979170e02e7 596 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
ashleymills 0:e979170e02e7 597 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
ashleymills 0:e979170e02e7 598 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
ashleymills 0:e979170e02e7 599 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
ashleymills 0:e979170e02e7 600 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
ashleymills 0:e979170e02e7 601 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
ashleymills 0:e979170e02e7 602 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
ashleymills 0:e979170e02e7 603 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
ashleymills 0:e979170e02e7 604 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
ashleymills 0:e979170e02e7 605 0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
ashleymills 0:e979170e02e7 606 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
ashleymills 0:e979170e02e7 607 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
ashleymills 0:e979170e02e7 608 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
ashleymills 0:e979170e02e7 609 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
ashleymills 0:e979170e02e7 610 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
ashleymills 0:e979170e02e7 611 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
ashleymills 0:e979170e02e7 612 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
ashleymills 0:e979170e02e7 613 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
ashleymills 0:e979170e02e7 614 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
ashleymills 0:e979170e02e7 615 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
ashleymills 0:e979170e02e7 616 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
ashleymills 0:e979170e02e7 617 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
ashleymills 0:e979170e02e7 618 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
ashleymills 0:e979170e02e7 619 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
ashleymills 0:e979170e02e7 620 },
ashleymills 0:e979170e02e7 621 {
ashleymills 0:e979170e02e7 622 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
ashleymills 0:e979170e02e7 623 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
ashleymills 0:e979170e02e7 624 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
ashleymills 0:e979170e02e7 625 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
ashleymills 0:e979170e02e7 626 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
ashleymills 0:e979170e02e7 627 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
ashleymills 0:e979170e02e7 628 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
ashleymills 0:e979170e02e7 629 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
ashleymills 0:e979170e02e7 630 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
ashleymills 0:e979170e02e7 631 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
ashleymills 0:e979170e02e7 632 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
ashleymills 0:e979170e02e7 633 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
ashleymills 0:e979170e02e7 634 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
ashleymills 0:e979170e02e7 635 0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
ashleymills 0:e979170e02e7 636 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
ashleymills 0:e979170e02e7 637 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
ashleymills 0:e979170e02e7 638 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
ashleymills 0:e979170e02e7 639 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
ashleymills 0:e979170e02e7 640 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
ashleymills 0:e979170e02e7 641 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
ashleymills 0:e979170e02e7 642 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
ashleymills 0:e979170e02e7 643 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
ashleymills 0:e979170e02e7 644 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
ashleymills 0:e979170e02e7 645 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
ashleymills 0:e979170e02e7 646 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
ashleymills 0:e979170e02e7 647 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
ashleymills 0:e979170e02e7 648 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
ashleymills 0:e979170e02e7 649 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
ashleymills 0:e979170e02e7 650 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
ashleymills 0:e979170e02e7 651 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
ashleymills 0:e979170e02e7 652 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
ashleymills 0:e979170e02e7 653 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
ashleymills 0:e979170e02e7 654 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
ashleymills 0:e979170e02e7 655 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
ashleymills 0:e979170e02e7 656 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
ashleymills 0:e979170e02e7 657 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
ashleymills 0:e979170e02e7 658 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
ashleymills 0:e979170e02e7 659 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
ashleymills 0:e979170e02e7 660 0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
ashleymills 0:e979170e02e7 661 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
ashleymills 0:e979170e02e7 662 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
ashleymills 0:e979170e02e7 663 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
ashleymills 0:e979170e02e7 664 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
ashleymills 0:e979170e02e7 665 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
ashleymills 0:e979170e02e7 666 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
ashleymills 0:e979170e02e7 667 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
ashleymills 0:e979170e02e7 668 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
ashleymills 0:e979170e02e7 669 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
ashleymills 0:e979170e02e7 670 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
ashleymills 0:e979170e02e7 671 0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
ashleymills 0:e979170e02e7 672 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
ashleymills 0:e979170e02e7 673 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
ashleymills 0:e979170e02e7 674 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
ashleymills 0:e979170e02e7 675 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
ashleymills 0:e979170e02e7 676 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
ashleymills 0:e979170e02e7 677 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
ashleymills 0:e979170e02e7 678 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
ashleymills 0:e979170e02e7 679 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
ashleymills 0:e979170e02e7 680 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
ashleymills 0:e979170e02e7 681 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
ashleymills 0:e979170e02e7 682 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
ashleymills 0:e979170e02e7 683 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
ashleymills 0:e979170e02e7 684 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
ashleymills 0:e979170e02e7 685 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
ashleymills 0:e979170e02e7 686 },
ashleymills 0:e979170e02e7 687 {
ashleymills 0:e979170e02e7 688 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
ashleymills 0:e979170e02e7 689 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
ashleymills 0:e979170e02e7 690 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
ashleymills 0:e979170e02e7 691 0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
ashleymills 0:e979170e02e7 692 0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
ashleymills 0:e979170e02e7 693 0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
ashleymills 0:e979170e02e7 694 0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
ashleymills 0:e979170e02e7 695 0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
ashleymills 0:e979170e02e7 696 0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
ashleymills 0:e979170e02e7 697 0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
ashleymills 0:e979170e02e7 698 0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
ashleymills 0:e979170e02e7 699 0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
ashleymills 0:e979170e02e7 700 0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
ashleymills 0:e979170e02e7 701 0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
ashleymills 0:e979170e02e7 702 0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
ashleymills 0:e979170e02e7 703 0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
ashleymills 0:e979170e02e7 704 0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
ashleymills 0:e979170e02e7 705 0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
ashleymills 0:e979170e02e7 706 0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
ashleymills 0:e979170e02e7 707 0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
ashleymills 0:e979170e02e7 708 0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
ashleymills 0:e979170e02e7 709 0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
ashleymills 0:e979170e02e7 710 0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
ashleymills 0:e979170e02e7 711 0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
ashleymills 0:e979170e02e7 712 0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
ashleymills 0:e979170e02e7 713 0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
ashleymills 0:e979170e02e7 714 0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
ashleymills 0:e979170e02e7 715 0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
ashleymills 0:e979170e02e7 716 0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
ashleymills 0:e979170e02e7 717 0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
ashleymills 0:e979170e02e7 718 0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
ashleymills 0:e979170e02e7 719 0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
ashleymills 0:e979170e02e7 720 0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
ashleymills 0:e979170e02e7 721 0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
ashleymills 0:e979170e02e7 722 0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
ashleymills 0:e979170e02e7 723 0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
ashleymills 0:e979170e02e7 724 0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
ashleymills 0:e979170e02e7 725 0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
ashleymills 0:e979170e02e7 726 0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
ashleymills 0:e979170e02e7 727 0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
ashleymills 0:e979170e02e7 728 0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
ashleymills 0:e979170e02e7 729 0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
ashleymills 0:e979170e02e7 730 0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
ashleymills 0:e979170e02e7 731 0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
ashleymills 0:e979170e02e7 732 0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
ashleymills 0:e979170e02e7 733 0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
ashleymills 0:e979170e02e7 734 0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
ashleymills 0:e979170e02e7 735 0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
ashleymills 0:e979170e02e7 736 0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
ashleymills 0:e979170e02e7 737 0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
ashleymills 0:e979170e02e7 738 0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
ashleymills 0:e979170e02e7 739 0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
ashleymills 0:e979170e02e7 740 0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
ashleymills 0:e979170e02e7 741 0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
ashleymills 0:e979170e02e7 742 0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
ashleymills 0:e979170e02e7 743 0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
ashleymills 0:e979170e02e7 744 0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
ashleymills 0:e979170e02e7 745 0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
ashleymills 0:e979170e02e7 746 0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
ashleymills 0:e979170e02e7 747 0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
ashleymills 0:e979170e02e7 748 0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
ashleymills 0:e979170e02e7 749 0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
ashleymills 0:e979170e02e7 750 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
ashleymills 0:e979170e02e7 751 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
ashleymills 0:e979170e02e7 752 }
ashleymills 0:e979170e02e7 753 };
ashleymills 0:e979170e02e7 754
ashleymills 0:e979170e02e7 755
ashleymills 0:e979170e02e7 756 static const word32 Td[5][256] = {
ashleymills 0:e979170e02e7 757 {
ashleymills 0:e979170e02e7 758 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
ashleymills 0:e979170e02e7 759 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
ashleymills 0:e979170e02e7 760 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
ashleymills 0:e979170e02e7 761 0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU,
ashleymills 0:e979170e02e7 762 0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U,
ashleymills 0:e979170e02e7 763 0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U,
ashleymills 0:e979170e02e7 764 0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU,
ashleymills 0:e979170e02e7 765 0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U,
ashleymills 0:e979170e02e7 766 0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU,
ashleymills 0:e979170e02e7 767 0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U,
ashleymills 0:e979170e02e7 768 0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U,
ashleymills 0:e979170e02e7 769 0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U,
ashleymills 0:e979170e02e7 770 0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U,
ashleymills 0:e979170e02e7 771 0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU,
ashleymills 0:e979170e02e7 772 0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U,
ashleymills 0:e979170e02e7 773 0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU,
ashleymills 0:e979170e02e7 774 0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U,
ashleymills 0:e979170e02e7 775 0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU,
ashleymills 0:e979170e02e7 776 0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U,
ashleymills 0:e979170e02e7 777 0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U,
ashleymills 0:e979170e02e7 778 0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U,
ashleymills 0:e979170e02e7 779 0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU,
ashleymills 0:e979170e02e7 780 0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U,
ashleymills 0:e979170e02e7 781 0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU,
ashleymills 0:e979170e02e7 782 0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U,
ashleymills 0:e979170e02e7 783 0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU,
ashleymills 0:e979170e02e7 784 0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U,
ashleymills 0:e979170e02e7 785 0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU,
ashleymills 0:e979170e02e7 786 0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU,
ashleymills 0:e979170e02e7 787 0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U,
ashleymills 0:e979170e02e7 788 0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU,
ashleymills 0:e979170e02e7 789 0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U,
ashleymills 0:e979170e02e7 790 0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU,
ashleymills 0:e979170e02e7 791 0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U,
ashleymills 0:e979170e02e7 792 0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U,
ashleymills 0:e979170e02e7 793 0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U,
ashleymills 0:e979170e02e7 794 0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU,
ashleymills 0:e979170e02e7 795 0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U,
ashleymills 0:e979170e02e7 796 0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U,
ashleymills 0:e979170e02e7 797 0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU,
ashleymills 0:e979170e02e7 798 0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U,
ashleymills 0:e979170e02e7 799 0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U,
ashleymills 0:e979170e02e7 800 0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U,
ashleymills 0:e979170e02e7 801 0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U,
ashleymills 0:e979170e02e7 802 0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U,
ashleymills 0:e979170e02e7 803 0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU,
ashleymills 0:e979170e02e7 804 0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U,
ashleymills 0:e979170e02e7 805 0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U,
ashleymills 0:e979170e02e7 806 0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U,
ashleymills 0:e979170e02e7 807 0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U,
ashleymills 0:e979170e02e7 808 0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U,
ashleymills 0:e979170e02e7 809 0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU,
ashleymills 0:e979170e02e7 810 0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU,
ashleymills 0:e979170e02e7 811 0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU,
ashleymills 0:e979170e02e7 812 0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU,
ashleymills 0:e979170e02e7 813 0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U,
ashleymills 0:e979170e02e7 814 0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U,
ashleymills 0:e979170e02e7 815 0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU,
ashleymills 0:e979170e02e7 816 0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU,
ashleymills 0:e979170e02e7 817 0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U,
ashleymills 0:e979170e02e7 818 0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU,
ashleymills 0:e979170e02e7 819 0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U,
ashleymills 0:e979170e02e7 820 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
ashleymills 0:e979170e02e7 821 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
ashleymills 0:e979170e02e7 822 },
ashleymills 0:e979170e02e7 823 {
ashleymills 0:e979170e02e7 824 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
ashleymills 0:e979170e02e7 825 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
ashleymills 0:e979170e02e7 826 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
ashleymills 0:e979170e02e7 827 0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U,
ashleymills 0:e979170e02e7 828 0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U,
ashleymills 0:e979170e02e7 829 0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U,
ashleymills 0:e979170e02e7 830 0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U,
ashleymills 0:e979170e02e7 831 0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U,
ashleymills 0:e979170e02e7 832 0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U,
ashleymills 0:e979170e02e7 833 0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU,
ashleymills 0:e979170e02e7 834 0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU,
ashleymills 0:e979170e02e7 835 0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU,
ashleymills 0:e979170e02e7 836 0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U,
ashleymills 0:e979170e02e7 837 0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU,
ashleymills 0:e979170e02e7 838 0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U,
ashleymills 0:e979170e02e7 839 0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U,
ashleymills 0:e979170e02e7 840 0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U,
ashleymills 0:e979170e02e7 841 0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU,
ashleymills 0:e979170e02e7 842 0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU,
ashleymills 0:e979170e02e7 843 0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U,
ashleymills 0:e979170e02e7 844 0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU,
ashleymills 0:e979170e02e7 845 0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U,
ashleymills 0:e979170e02e7 846 0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU,
ashleymills 0:e979170e02e7 847 0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU,
ashleymills 0:e979170e02e7 848 0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U,
ashleymills 0:e979170e02e7 849 0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U,
ashleymills 0:e979170e02e7 850 0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U,
ashleymills 0:e979170e02e7 851 0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU,
ashleymills 0:e979170e02e7 852 0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U,
ashleymills 0:e979170e02e7 853 0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU,
ashleymills 0:e979170e02e7 854 0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U,
ashleymills 0:e979170e02e7 855 0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U,
ashleymills 0:e979170e02e7 856 0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U,
ashleymills 0:e979170e02e7 857 0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU,
ashleymills 0:e979170e02e7 858 0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U,
ashleymills 0:e979170e02e7 859 0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U,
ashleymills 0:e979170e02e7 860 0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U,
ashleymills 0:e979170e02e7 861 0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U,
ashleymills 0:e979170e02e7 862 0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U,
ashleymills 0:e979170e02e7 863 0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U,
ashleymills 0:e979170e02e7 864 0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU,
ashleymills 0:e979170e02e7 865 0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU,
ashleymills 0:e979170e02e7 866 0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U,
ashleymills 0:e979170e02e7 867 0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU,
ashleymills 0:e979170e02e7 868 0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U,
ashleymills 0:e979170e02e7 869 0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU,
ashleymills 0:e979170e02e7 870 0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU,
ashleymills 0:e979170e02e7 871 0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U,
ashleymills 0:e979170e02e7 872 0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU,
ashleymills 0:e979170e02e7 873 0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U,
ashleymills 0:e979170e02e7 874 0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U,
ashleymills 0:e979170e02e7 875 0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U,
ashleymills 0:e979170e02e7 876 0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U,
ashleymills 0:e979170e02e7 877 0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U,
ashleymills 0:e979170e02e7 878 0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U,
ashleymills 0:e979170e02e7 879 0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U,
ashleymills 0:e979170e02e7 880 0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU,
ashleymills 0:e979170e02e7 881 0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U,
ashleymills 0:e979170e02e7 882 0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U,
ashleymills 0:e979170e02e7 883 0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU,
ashleymills 0:e979170e02e7 884 0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U,
ashleymills 0:e979170e02e7 885 0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U,
ashleymills 0:e979170e02e7 886 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
ashleymills 0:e979170e02e7 887 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
ashleymills 0:e979170e02e7 888 },
ashleymills 0:e979170e02e7 889 {
ashleymills 0:e979170e02e7 890 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
ashleymills 0:e979170e02e7 891 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
ashleymills 0:e979170e02e7 892 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
ashleymills 0:e979170e02e7 893 0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U,
ashleymills 0:e979170e02e7 894 0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU,
ashleymills 0:e979170e02e7 895 0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U,
ashleymills 0:e979170e02e7 896 0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U,
ashleymills 0:e979170e02e7 897 0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U,
ashleymills 0:e979170e02e7 898 0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U,
ashleymills 0:e979170e02e7 899 0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU,
ashleymills 0:e979170e02e7 900 0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U,
ashleymills 0:e979170e02e7 901 0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U,
ashleymills 0:e979170e02e7 902 0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU,
ashleymills 0:e979170e02e7 903 0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U,
ashleymills 0:e979170e02e7 904 0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U,
ashleymills 0:e979170e02e7 905 0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U,
ashleymills 0:e979170e02e7 906 0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U,
ashleymills 0:e979170e02e7 907 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U,
ashleymills 0:e979170e02e7 908 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U,
ashleymills 0:e979170e02e7 909 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU,
ashleymills 0:e979170e02e7 910
ashleymills 0:e979170e02e7 911 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U,
ashleymills 0:e979170e02e7 912 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U,
ashleymills 0:e979170e02e7 913 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U,
ashleymills 0:e979170e02e7 914 0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U,
ashleymills 0:e979170e02e7 915 0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U,
ashleymills 0:e979170e02e7 916 0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU,
ashleymills 0:e979170e02e7 917 0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU,
ashleymills 0:e979170e02e7 918 0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U,
ashleymills 0:e979170e02e7 919 0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU,
ashleymills 0:e979170e02e7 920 0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U,
ashleymills 0:e979170e02e7 921 0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU,
ashleymills 0:e979170e02e7 922 0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU,
ashleymills 0:e979170e02e7 923 0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU,
ashleymills 0:e979170e02e7 924 0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU,
ashleymills 0:e979170e02e7 925 0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U,
ashleymills 0:e979170e02e7 926 0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U,
ashleymills 0:e979170e02e7 927 0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U,
ashleymills 0:e979170e02e7 928 0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U,
ashleymills 0:e979170e02e7 929 0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U,
ashleymills 0:e979170e02e7 930 0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U,
ashleymills 0:e979170e02e7 931 0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U,
ashleymills 0:e979170e02e7 932 0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU,
ashleymills 0:e979170e02e7 933 0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU,
ashleymills 0:e979170e02e7 934 0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U,
ashleymills 0:e979170e02e7 935 0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U,
ashleymills 0:e979170e02e7 936 0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU,
ashleymills 0:e979170e02e7 937 0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU,
ashleymills 0:e979170e02e7 938 0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U,
ashleymills 0:e979170e02e7 939 0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U,
ashleymills 0:e979170e02e7 940 0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U,
ashleymills 0:e979170e02e7 941 0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U,
ashleymills 0:e979170e02e7 942 0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U,
ashleymills 0:e979170e02e7 943 0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U,
ashleymills 0:e979170e02e7 944 0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U,
ashleymills 0:e979170e02e7 945 0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU,
ashleymills 0:e979170e02e7 946 0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U,
ashleymills 0:e979170e02e7 947 0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U,
ashleymills 0:e979170e02e7 948 0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U,
ashleymills 0:e979170e02e7 949 0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U,
ashleymills 0:e979170e02e7 950 0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U,
ashleymills 0:e979170e02e7 951 0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U,
ashleymills 0:e979170e02e7 952 0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU,
ashleymills 0:e979170e02e7 953 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
ashleymills 0:e979170e02e7 954 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
ashleymills 0:e979170e02e7 955 },
ashleymills 0:e979170e02e7 956 {
ashleymills 0:e979170e02e7 957 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
ashleymills 0:e979170e02e7 958 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
ashleymills 0:e979170e02e7 959 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
ashleymills 0:e979170e02e7 960 0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U,
ashleymills 0:e979170e02e7 961 0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU,
ashleymills 0:e979170e02e7 962 0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU,
ashleymills 0:e979170e02e7 963 0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U,
ashleymills 0:e979170e02e7 964 0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU,
ashleymills 0:e979170e02e7 965 0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U,
ashleymills 0:e979170e02e7 966 0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU,
ashleymills 0:e979170e02e7 967 0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U,
ashleymills 0:e979170e02e7 968 0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U,
ashleymills 0:e979170e02e7 969 0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U,
ashleymills 0:e979170e02e7 970 0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U,
ashleymills 0:e979170e02e7 971 0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U,
ashleymills 0:e979170e02e7 972 0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU,
ashleymills 0:e979170e02e7 973 0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU,
ashleymills 0:e979170e02e7 974 0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U,
ashleymills 0:e979170e02e7 975 0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U,
ashleymills 0:e979170e02e7 976 0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU,
ashleymills 0:e979170e02e7 977 0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU,
ashleymills 0:e979170e02e7 978 0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U,
ashleymills 0:e979170e02e7 979 0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U,
ashleymills 0:e979170e02e7 980 0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U,
ashleymills 0:e979170e02e7 981 0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U,
ashleymills 0:e979170e02e7 982 0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU,
ashleymills 0:e979170e02e7 983 0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U,
ashleymills 0:e979170e02e7 984 0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U,
ashleymills 0:e979170e02e7 985 0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU,
ashleymills 0:e979170e02e7 986 0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU,
ashleymills 0:e979170e02e7 987 0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U,
ashleymills 0:e979170e02e7 988 0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U,
ashleymills 0:e979170e02e7 989 0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U,
ashleymills 0:e979170e02e7 990 0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU,
ashleymills 0:e979170e02e7 991 0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U,
ashleymills 0:e979170e02e7 992 0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U,
ashleymills 0:e979170e02e7 993 0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U,
ashleymills 0:e979170e02e7 994 0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U,
ashleymills 0:e979170e02e7 995 0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U,
ashleymills 0:e979170e02e7 996 0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U,
ashleymills 0:e979170e02e7 997 0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U,
ashleymills 0:e979170e02e7 998 0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU,
ashleymills 0:e979170e02e7 999 0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U,
ashleymills 0:e979170e02e7 1000 0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U,
ashleymills 0:e979170e02e7 1001 0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU,
ashleymills 0:e979170e02e7 1002 0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU,
ashleymills 0:e979170e02e7 1003 0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U,
ashleymills 0:e979170e02e7 1004 0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU,
ashleymills 0:e979170e02e7 1005 0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U,
ashleymills 0:e979170e02e7 1006 0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U,
ashleymills 0:e979170e02e7 1007 0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U,
ashleymills 0:e979170e02e7 1008 0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U,
ashleymills 0:e979170e02e7 1009 0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U,
ashleymills 0:e979170e02e7 1010 0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U,
ashleymills 0:e979170e02e7 1011 0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU,
ashleymills 0:e979170e02e7 1012 0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU,
ashleymills 0:e979170e02e7 1013 0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU,
ashleymills 0:e979170e02e7 1014 0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU,
ashleymills 0:e979170e02e7 1015 0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U,
ashleymills 0:e979170e02e7 1016 0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U,
ashleymills 0:e979170e02e7 1017 0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U,
ashleymills 0:e979170e02e7 1018 0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU,
ashleymills 0:e979170e02e7 1019 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
ashleymills 0:e979170e02e7 1020 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
ashleymills 0:e979170e02e7 1021 },
ashleymills 0:e979170e02e7 1022 {
ashleymills 0:e979170e02e7 1023 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
ashleymills 0:e979170e02e7 1024 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
ashleymills 0:e979170e02e7 1025 0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
ashleymills 0:e979170e02e7 1026 0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU,
ashleymills 0:e979170e02e7 1027 0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U,
ashleymills 0:e979170e02e7 1028 0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U,
ashleymills 0:e979170e02e7 1029 0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U,
ashleymills 0:e979170e02e7 1030 0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU,
ashleymills 0:e979170e02e7 1031 0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U,
ashleymills 0:e979170e02e7 1032 0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU,
ashleymills 0:e979170e02e7 1033 0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU,
ashleymills 0:e979170e02e7 1034 0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU,
ashleymills 0:e979170e02e7 1035 0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U,
ashleymills 0:e979170e02e7 1036 0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U,
ashleymills 0:e979170e02e7 1037 0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U,
ashleymills 0:e979170e02e7 1038 0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U,
ashleymills 0:e979170e02e7 1039 0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U,
ashleymills 0:e979170e02e7 1040 0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U,
ashleymills 0:e979170e02e7 1041 0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU,
ashleymills 0:e979170e02e7 1042 0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U,
ashleymills 0:e979170e02e7 1043 0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U,
ashleymills 0:e979170e02e7 1044 0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU,
ashleymills 0:e979170e02e7 1045 0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U,
ashleymills 0:e979170e02e7 1046 0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U,
ashleymills 0:e979170e02e7 1047 0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U,
ashleymills 0:e979170e02e7 1048 0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU,
ashleymills 0:e979170e02e7 1049 0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U,
ashleymills 0:e979170e02e7 1050 0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U,
ashleymills 0:e979170e02e7 1051 0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU,
ashleymills 0:e979170e02e7 1052 0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U,
ashleymills 0:e979170e02e7 1053 0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U,
ashleymills 0:e979170e02e7 1054 0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU,
ashleymills 0:e979170e02e7 1055 0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U,
ashleymills 0:e979170e02e7 1056 0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU,
ashleymills 0:e979170e02e7 1057 0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU,
ashleymills 0:e979170e02e7 1058 0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U,
ashleymills 0:e979170e02e7 1059 0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U,
ashleymills 0:e979170e02e7 1060 0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U,
ashleymills 0:e979170e02e7 1061 0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U,
ashleymills 0:e979170e02e7 1062 0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU,
ashleymills 0:e979170e02e7 1063 0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U,
ashleymills 0:e979170e02e7 1064 0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U,
ashleymills 0:e979170e02e7 1065 0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU,
ashleymills 0:e979170e02e7 1066 0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU,
ashleymills 0:e979170e02e7 1067 0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU,
ashleymills 0:e979170e02e7 1068 0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U,
ashleymills 0:e979170e02e7 1069 0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU,
ashleymills 0:e979170e02e7 1070 0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U,
ashleymills 0:e979170e02e7 1071 0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U,
ashleymills 0:e979170e02e7 1072 0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U,
ashleymills 0:e979170e02e7 1073 0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U,
ashleymills 0:e979170e02e7 1074 0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU,
ashleymills 0:e979170e02e7 1075 0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U,
ashleymills 0:e979170e02e7 1076 0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU,
ashleymills 0:e979170e02e7 1077 0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU,
ashleymills 0:e979170e02e7 1078 0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU,
ashleymills 0:e979170e02e7 1079 0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU,
ashleymills 0:e979170e02e7 1080 0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U,
ashleymills 0:e979170e02e7 1081 0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU,
ashleymills 0:e979170e02e7 1082 0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U,
ashleymills 0:e979170e02e7 1083 0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU,
ashleymills 0:e979170e02e7 1084 0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U,
ashleymills 0:e979170e02e7 1085 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
ashleymills 0:e979170e02e7 1086 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
ashleymills 0:e979170e02e7 1087 }
ashleymills 0:e979170e02e7 1088 };
ashleymills 0:e979170e02e7 1089
ashleymills 0:e979170e02e7 1090
ashleymills 0:e979170e02e7 1091
ashleymills 0:e979170e02e7 1092 #define GETBYTE(x, y) (word32)((byte)((x) >> (8 * (y))))
ashleymills 0:e979170e02e7 1093
ashleymills 0:e979170e02e7 1094
ashleymills 0:e979170e02e7 1095 #ifdef CYASSL_AESNI
ashleymills 0:e979170e02e7 1096
ashleymills 0:e979170e02e7 1097 #ifndef _MSC_VER
ashleymills 0:e979170e02e7 1098
ashleymills 0:e979170e02e7 1099 #define cpuid(func,ax,bx,cx,dx)\
ashleymills 0:e979170e02e7 1100 __asm__ __volatile__ ("cpuid":\
ashleymills 0:e979170e02e7 1101 "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
ashleymills 0:e979170e02e7 1102
ashleymills 0:e979170e02e7 1103 #else
ashleymills 0:e979170e02e7 1104
ashleymills 0:e979170e02e7 1105 #define cpuid(func,ax,bx,cx,dx)\
ashleymills 0:e979170e02e7 1106 __asm mov eax, func \
ashleymills 0:e979170e02e7 1107 __asm cpuid \
ashleymills 0:e979170e02e7 1108 __asm mov ax, eax \
ashleymills 0:e979170e02e7 1109 __asm mov bx, ebx \
ashleymills 0:e979170e02e7 1110 __asm mov cx, ecx \
ashleymills 0:e979170e02e7 1111 __asm mov dx, edx
ashleymills 0:e979170e02e7 1112
ashleymills 0:e979170e02e7 1113 #endif /* _MSC_VER */
ashleymills 0:e979170e02e7 1114
ashleymills 0:e979170e02e7 1115
ashleymills 0:e979170e02e7 1116 static int Check_CPU_support_AES(void)
ashleymills 0:e979170e02e7 1117 {
ashleymills 0:e979170e02e7 1118 unsigned int a,b,c,d;
ashleymills 0:e979170e02e7 1119 cpuid(1,a,b,c,d);
ashleymills 0:e979170e02e7 1120
ashleymills 0:e979170e02e7 1121 if (c & 0x2000000)
ashleymills 0:e979170e02e7 1122 return 1;
ashleymills 0:e979170e02e7 1123
ashleymills 0:e979170e02e7 1124 return 0;
ashleymills 0:e979170e02e7 1125 }
ashleymills 0:e979170e02e7 1126
ashleymills 0:e979170e02e7 1127 static int checkAESNI = 0;
ashleymills 0:e979170e02e7 1128 static int haveAESNI = 0;
ashleymills 0:e979170e02e7 1129
ashleymills 0:e979170e02e7 1130
ashleymills 0:e979170e02e7 1131 void AES_CBC_encrypt(const unsigned char* in, unsigned char* out,
ashleymills 0:e979170e02e7 1132 unsigned char* ivec, unsigned long length,
ashleymills 0:e979170e02e7 1133 const unsigned char* KS, int nr);
ashleymills 0:e979170e02e7 1134
ashleymills 0:e979170e02e7 1135
ashleymills 0:e979170e02e7 1136 void AES_CBC_decrypt(const unsigned char* in, unsigned char* out,
ashleymills 0:e979170e02e7 1137 unsigned char* ivec, unsigned long length,
ashleymills 0:e979170e02e7 1138 const unsigned char* KS, int nr);
ashleymills 0:e979170e02e7 1139
ashleymills 0:e979170e02e7 1140 void AES_128_Key_Expansion(const unsigned char* userkey,
ashleymills 0:e979170e02e7 1141 unsigned char* key_schedule);
ashleymills 0:e979170e02e7 1142
ashleymills 0:e979170e02e7 1143 void AES_192_Key_Expansion(const unsigned char* userkey,
ashleymills 0:e979170e02e7 1144 unsigned char* key_schedule);
ashleymills 0:e979170e02e7 1145
ashleymills 0:e979170e02e7 1146 void AES_256_Key_Expansion(const unsigned char* userkey,
ashleymills 0:e979170e02e7 1147 unsigned char* key_schedule);
ashleymills 0:e979170e02e7 1148
ashleymills 0:e979170e02e7 1149
ashleymills 0:e979170e02e7 1150 static int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
ashleymills 0:e979170e02e7 1151 Aes* aes)
ashleymills 0:e979170e02e7 1152 {
ashleymills 0:e979170e02e7 1153 if (!userKey || !aes)
ashleymills 0:e979170e02e7 1154 return BAD_FUNC_ARG;
ashleymills 0:e979170e02e7 1155
ashleymills 0:e979170e02e7 1156 if (bits == 128) {
ashleymills 0:e979170e02e7 1157 AES_128_Key_Expansion (userKey,(byte*)aes->key); aes->rounds = 10;
ashleymills 0:e979170e02e7 1158 return 0;
ashleymills 0:e979170e02e7 1159 }
ashleymills 0:e979170e02e7 1160 else if (bits == 192) {
ashleymills 0:e979170e02e7 1161 AES_192_Key_Expansion (userKey,(byte*)aes->key); aes->rounds = 12;
ashleymills 0:e979170e02e7 1162 return 0;
ashleymills 0:e979170e02e7 1163 }
ashleymills 0:e979170e02e7 1164 else if (bits == 256) {
ashleymills 0:e979170e02e7 1165 AES_256_Key_Expansion (userKey,(byte*)aes->key); aes->rounds = 14;
ashleymills 0:e979170e02e7 1166 return 0;
ashleymills 0:e979170e02e7 1167 }
ashleymills 0:e979170e02e7 1168 return BAD_FUNC_ARG;
ashleymills 0:e979170e02e7 1169 }
ashleymills 0:e979170e02e7 1170
ashleymills 0:e979170e02e7 1171
ashleymills 0:e979170e02e7 1172 static int AES_set_decrypt_key(const unsigned char* userKey, const int bits,
ashleymills 0:e979170e02e7 1173 Aes* aes)
ashleymills 0:e979170e02e7 1174 {
ashleymills 0:e979170e02e7 1175 int nr;
ashleymills 0:e979170e02e7 1176 Aes temp_key;
ashleymills 0:e979170e02e7 1177 __m128i *Key_Schedule = (__m128i*)aes->key;
ashleymills 0:e979170e02e7 1178 __m128i *Temp_Key_Schedule = (__m128i*)temp_key.key;
ashleymills 0:e979170e02e7 1179
ashleymills 0:e979170e02e7 1180 if (!userKey || !aes)
ashleymills 0:e979170e02e7 1181 return BAD_FUNC_ARG;
ashleymills 0:e979170e02e7 1182
ashleymills 0:e979170e02e7 1183 if (AES_set_encrypt_key(userKey,bits,&temp_key) == BAD_FUNC_ARG)
ashleymills 0:e979170e02e7 1184 return BAD_FUNC_ARG;
ashleymills 0:e979170e02e7 1185
ashleymills 0:e979170e02e7 1186 nr = temp_key.rounds;
ashleymills 0:e979170e02e7 1187 aes->rounds = nr;
ashleymills 0:e979170e02e7 1188
ashleymills 0:e979170e02e7 1189 Key_Schedule[nr] = Temp_Key_Schedule[0];
ashleymills 0:e979170e02e7 1190 Key_Schedule[nr-1] = _mm_aesimc_si128(Temp_Key_Schedule[1]);
ashleymills 0:e979170e02e7 1191 Key_Schedule[nr-2] = _mm_aesimc_si128(Temp_Key_Schedule[2]);
ashleymills 0:e979170e02e7 1192 Key_Schedule[nr-3] = _mm_aesimc_si128(Temp_Key_Schedule[3]);
ashleymills 0:e979170e02e7 1193 Key_Schedule[nr-4] = _mm_aesimc_si128(Temp_Key_Schedule[4]);
ashleymills 0:e979170e02e7 1194 Key_Schedule[nr-5] = _mm_aesimc_si128(Temp_Key_Schedule[5]);
ashleymills 0:e979170e02e7 1195 Key_Schedule[nr-6] = _mm_aesimc_si128(Temp_Key_Schedule[6]);
ashleymills 0:e979170e02e7 1196 Key_Schedule[nr-7] = _mm_aesimc_si128(Temp_Key_Schedule[7]);
ashleymills 0:e979170e02e7 1197 Key_Schedule[nr-8] = _mm_aesimc_si128(Temp_Key_Schedule[8]);
ashleymills 0:e979170e02e7 1198 Key_Schedule[nr-9] = _mm_aesimc_si128(Temp_Key_Schedule[9]);
ashleymills 0:e979170e02e7 1199
ashleymills 0:e979170e02e7 1200 if(nr>10) {
ashleymills 0:e979170e02e7 1201 Key_Schedule[nr-10] = _mm_aesimc_si128(Temp_Key_Schedule[10]);
ashleymills 0:e979170e02e7 1202 Key_Schedule[nr-11] = _mm_aesimc_si128(Temp_Key_Schedule[11]);
ashleymills 0:e979170e02e7 1203 }
ashleymills 0:e979170e02e7 1204
ashleymills 0:e979170e02e7 1205 if(nr>12) {
ashleymills 0:e979170e02e7 1206 Key_Schedule[nr-12] = _mm_aesimc_si128(Temp_Key_Schedule[12]);
ashleymills 0:e979170e02e7 1207 Key_Schedule[nr-13] = _mm_aesimc_si128(Temp_Key_Schedule[13]);
ashleymills 0:e979170e02e7 1208 }
ashleymills 0:e979170e02e7 1209
ashleymills 0:e979170e02e7 1210 Key_Schedule[0] = Temp_Key_Schedule[nr];
ashleymills 0:e979170e02e7 1211
ashleymills 0:e979170e02e7 1212 return 0;
ashleymills 0:e979170e02e7 1213 }
ashleymills 0:e979170e02e7 1214
ashleymills 0:e979170e02e7 1215
ashleymills 0:e979170e02e7 1216
ashleymills 0:e979170e02e7 1217 #endif /* CYASSL_AESNI */
ashleymills 0:e979170e02e7 1218
ashleymills 0:e979170e02e7 1219
ashleymills 0:e979170e02e7 1220 static int AesSetKeyLocal(Aes* aes, const byte* userKey, word32 keylen,
ashleymills 0:e979170e02e7 1221 const byte* iv, int dir)
ashleymills 0:e979170e02e7 1222 {
ashleymills 0:e979170e02e7 1223 word32 temp, *rk = aes->key;
ashleymills 0:e979170e02e7 1224 unsigned int i = 0;
ashleymills 0:e979170e02e7 1225
ashleymills 0:e979170e02e7 1226 #ifdef CYASSL_AESNI
ashleymills 0:e979170e02e7 1227 aes->use_aesni = 0;
ashleymills 0:e979170e02e7 1228 #endif /* CYASSL_AESNI */
ashleymills 0:e979170e02e7 1229 aes->rounds = keylen/4 + 6;
ashleymills 0:e979170e02e7 1230
ashleymills 0:e979170e02e7 1231 XMEMCPY(rk, userKey, keylen);
ashleymills 0:e979170e02e7 1232 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 1233 ByteReverseWords(rk, rk, keylen);
ashleymills 0:e979170e02e7 1234 #endif
ashleymills 0:e979170e02e7 1235
ashleymills 0:e979170e02e7 1236 switch(keylen)
ashleymills 0:e979170e02e7 1237 {
ashleymills 0:e979170e02e7 1238 case 16:
ashleymills 0:e979170e02e7 1239 while (1)
ashleymills 0:e979170e02e7 1240 {
ashleymills 0:e979170e02e7 1241 temp = rk[3];
ashleymills 0:e979170e02e7 1242 rk[4] = rk[0] ^
ashleymills 0:e979170e02e7 1243 (Te[4][GETBYTE(temp, 2)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1244 (Te[4][GETBYTE(temp, 1)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1245 (Te[4][GETBYTE(temp, 0)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1246 (Te[4][GETBYTE(temp, 3)] & 0x000000ff) ^
ashleymills 0:e979170e02e7 1247 rcon[i];
ashleymills 0:e979170e02e7 1248 rk[5] = rk[1] ^ rk[4];
ashleymills 0:e979170e02e7 1249 rk[6] = rk[2] ^ rk[5];
ashleymills 0:e979170e02e7 1250 rk[7] = rk[3] ^ rk[6];
ashleymills 0:e979170e02e7 1251 if (++i == 10)
ashleymills 0:e979170e02e7 1252 break;
ashleymills 0:e979170e02e7 1253 rk += 4;
ashleymills 0:e979170e02e7 1254 }
ashleymills 0:e979170e02e7 1255 break;
ashleymills 0:e979170e02e7 1256
ashleymills 0:e979170e02e7 1257 case 24:
ashleymills 0:e979170e02e7 1258 while (1) /* for (;;) here triggers a bug in VC60 SP4 w/ Pro Pack */
ashleymills 0:e979170e02e7 1259 {
ashleymills 0:e979170e02e7 1260 temp = rk[ 5];
ashleymills 0:e979170e02e7 1261 rk[ 6] = rk[ 0] ^
ashleymills 0:e979170e02e7 1262 (Te[4][GETBYTE(temp, 2)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1263 (Te[4][GETBYTE(temp, 1)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1264 (Te[4][GETBYTE(temp, 0)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1265 (Te[4][GETBYTE(temp, 3)] & 0x000000ff) ^
ashleymills 0:e979170e02e7 1266 rcon[i];
ashleymills 0:e979170e02e7 1267 rk[ 7] = rk[ 1] ^ rk[ 6];
ashleymills 0:e979170e02e7 1268 rk[ 8] = rk[ 2] ^ rk[ 7];
ashleymills 0:e979170e02e7 1269 rk[ 9] = rk[ 3] ^ rk[ 8];
ashleymills 0:e979170e02e7 1270 if (++i == 8)
ashleymills 0:e979170e02e7 1271 break;
ashleymills 0:e979170e02e7 1272 rk[10] = rk[ 4] ^ rk[ 9];
ashleymills 0:e979170e02e7 1273 rk[11] = rk[ 5] ^ rk[10];
ashleymills 0:e979170e02e7 1274 rk += 6;
ashleymills 0:e979170e02e7 1275 }
ashleymills 0:e979170e02e7 1276 break;
ashleymills 0:e979170e02e7 1277
ashleymills 0:e979170e02e7 1278 case 32:
ashleymills 0:e979170e02e7 1279 while (1)
ashleymills 0:e979170e02e7 1280 {
ashleymills 0:e979170e02e7 1281 temp = rk[ 7];
ashleymills 0:e979170e02e7 1282 rk[ 8] = rk[ 0] ^
ashleymills 0:e979170e02e7 1283 (Te[4][GETBYTE(temp, 2)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1284 (Te[4][GETBYTE(temp, 1)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1285 (Te[4][GETBYTE(temp, 0)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1286 (Te[4][GETBYTE(temp, 3)] & 0x000000ff) ^
ashleymills 0:e979170e02e7 1287 rcon[i];
ashleymills 0:e979170e02e7 1288 rk[ 9] = rk[ 1] ^ rk[ 8];
ashleymills 0:e979170e02e7 1289 rk[10] = rk[ 2] ^ rk[ 9];
ashleymills 0:e979170e02e7 1290 rk[11] = rk[ 3] ^ rk[10];
ashleymills 0:e979170e02e7 1291 if (++i == 7)
ashleymills 0:e979170e02e7 1292 break;
ashleymills 0:e979170e02e7 1293 temp = rk[11];
ashleymills 0:e979170e02e7 1294 rk[12] = rk[ 4] ^
ashleymills 0:e979170e02e7 1295 (Te[4][GETBYTE(temp, 3)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1296 (Te[4][GETBYTE(temp, 2)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1297 (Te[4][GETBYTE(temp, 1)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1298 (Te[4][GETBYTE(temp, 0)] & 0x000000ff);
ashleymills 0:e979170e02e7 1299 rk[13] = rk[ 5] ^ rk[12];
ashleymills 0:e979170e02e7 1300 rk[14] = rk[ 6] ^ rk[13];
ashleymills 0:e979170e02e7 1301 rk[15] = rk[ 7] ^ rk[14];
ashleymills 0:e979170e02e7 1302
ashleymills 0:e979170e02e7 1303 rk += 8;
ashleymills 0:e979170e02e7 1304 }
ashleymills 0:e979170e02e7 1305 break;
ashleymills 0:e979170e02e7 1306
ashleymills 0:e979170e02e7 1307 default:
ashleymills 0:e979170e02e7 1308 return BAD_FUNC_ARG;
ashleymills 0:e979170e02e7 1309 }
ashleymills 0:e979170e02e7 1310
ashleymills 0:e979170e02e7 1311 if (dir == AES_DECRYPTION)
ashleymills 0:e979170e02e7 1312 {
ashleymills 0:e979170e02e7 1313 unsigned int j;
ashleymills 0:e979170e02e7 1314 rk = aes->key;
ashleymills 0:e979170e02e7 1315
ashleymills 0:e979170e02e7 1316 /* invert the order of the round keys: */
ashleymills 0:e979170e02e7 1317 for (i = 0, j = 4* aes->rounds; i < j; i += 4, j -= 4) {
ashleymills 0:e979170e02e7 1318 temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp;
ashleymills 0:e979170e02e7 1319 temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
ashleymills 0:e979170e02e7 1320 temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
ashleymills 0:e979170e02e7 1321 temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
ashleymills 0:e979170e02e7 1322 }
ashleymills 0:e979170e02e7 1323 /* apply the inverse MixColumn transform to all round keys but the
ashleymills 0:e979170e02e7 1324 first and the last: */
ashleymills 0:e979170e02e7 1325 for (i = 1; i < aes->rounds; i++) {
ashleymills 0:e979170e02e7 1326 rk += 4;
ashleymills 0:e979170e02e7 1327 rk[0] =
ashleymills 0:e979170e02e7 1328 Td[0][Te[4][GETBYTE(rk[0], 3)] & 0xff] ^
ashleymills 0:e979170e02e7 1329 Td[1][Te[4][GETBYTE(rk[0], 2)] & 0xff] ^
ashleymills 0:e979170e02e7 1330 Td[2][Te[4][GETBYTE(rk[0], 1)] & 0xff] ^
ashleymills 0:e979170e02e7 1331 Td[3][Te[4][GETBYTE(rk[0], 0)] & 0xff];
ashleymills 0:e979170e02e7 1332 rk[1] =
ashleymills 0:e979170e02e7 1333 Td[0][Te[4][GETBYTE(rk[1], 3)] & 0xff] ^
ashleymills 0:e979170e02e7 1334 Td[1][Te[4][GETBYTE(rk[1], 2)] & 0xff] ^
ashleymills 0:e979170e02e7 1335 Td[2][Te[4][GETBYTE(rk[1], 1)] & 0xff] ^
ashleymills 0:e979170e02e7 1336 Td[3][Te[4][GETBYTE(rk[1], 0)] & 0xff];
ashleymills 0:e979170e02e7 1337 rk[2] =
ashleymills 0:e979170e02e7 1338 Td[0][Te[4][GETBYTE(rk[2], 3)] & 0xff] ^
ashleymills 0:e979170e02e7 1339 Td[1][Te[4][GETBYTE(rk[2], 2)] & 0xff] ^
ashleymills 0:e979170e02e7 1340 Td[2][Te[4][GETBYTE(rk[2], 1)] & 0xff] ^
ashleymills 0:e979170e02e7 1341 Td[3][Te[4][GETBYTE(rk[2], 0)] & 0xff];
ashleymills 0:e979170e02e7 1342 rk[3] =
ashleymills 0:e979170e02e7 1343 Td[0][Te[4][GETBYTE(rk[3], 3)] & 0xff] ^
ashleymills 0:e979170e02e7 1344 Td[1][Te[4][GETBYTE(rk[3], 2)] & 0xff] ^
ashleymills 0:e979170e02e7 1345 Td[2][Te[4][GETBYTE(rk[3], 1)] & 0xff] ^
ashleymills 0:e979170e02e7 1346 Td[3][Te[4][GETBYTE(rk[3], 0)] & 0xff];
ashleymills 0:e979170e02e7 1347 }
ashleymills 0:e979170e02e7 1348 }
ashleymills 0:e979170e02e7 1349
ashleymills 0:e979170e02e7 1350 return AesSetIV(aes, iv);
ashleymills 0:e979170e02e7 1351 }
ashleymills 0:e979170e02e7 1352
ashleymills 0:e979170e02e7 1353
ashleymills 0:e979170e02e7 1354 int AesSetKey(Aes* aes, const byte* userKey, word32 keylen, const byte* iv,
ashleymills 0:e979170e02e7 1355 int dir)
ashleymills 0:e979170e02e7 1356 {
ashleymills 0:e979170e02e7 1357
ashleymills 0:e979170e02e7 1358 if (!((keylen == 16) || (keylen == 24) || (keylen == 32)))
ashleymills 0:e979170e02e7 1359 return BAD_FUNC_ARG;
ashleymills 0:e979170e02e7 1360
ashleymills 0:e979170e02e7 1361 #ifdef HAVE_CAVIUM
ashleymills 0:e979170e02e7 1362 if (aes->magic == CYASSL_AES_CAVIUM_MAGIC)
ashleymills 0:e979170e02e7 1363 return AesCaviumSetKey(aes, userKey, keylen, iv);
ashleymills 0:e979170e02e7 1364 #endif
ashleymills 0:e979170e02e7 1365
ashleymills 0:e979170e02e7 1366 #ifdef CYASSL_AESNI
ashleymills 0:e979170e02e7 1367 if (checkAESNI == 0) {
ashleymills 0:e979170e02e7 1368 haveAESNI = Check_CPU_support_AES();
ashleymills 0:e979170e02e7 1369 checkAESNI = 1;
ashleymills 0:e979170e02e7 1370 }
ashleymills 0:e979170e02e7 1371 if (haveAESNI) {
ashleymills 0:e979170e02e7 1372 aes->use_aesni = 1;
ashleymills 0:e979170e02e7 1373 if (iv)
ashleymills 0:e979170e02e7 1374 XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1375 if (dir == AES_ENCRYPTION)
ashleymills 0:e979170e02e7 1376 return AES_set_encrypt_key(userKey, keylen * 8, aes);
ashleymills 0:e979170e02e7 1377 else
ashleymills 0:e979170e02e7 1378 return AES_set_decrypt_key(userKey, keylen * 8, aes);
ashleymills 0:e979170e02e7 1379 }
ashleymills 0:e979170e02e7 1380 #endif /* CYASSL_AESNI */
ashleymills 0:e979170e02e7 1381
ashleymills 0:e979170e02e7 1382 return AesSetKeyLocal(aes, userKey, keylen, iv, dir);
ashleymills 0:e979170e02e7 1383 }
ashleymills 0:e979170e02e7 1384
ashleymills 0:e979170e02e7 1385
ashleymills 0:e979170e02e7 1386 static void AesEncrypt(Aes* aes, const byte* inBlock, byte* outBlock)
ashleymills 0:e979170e02e7 1387 {
ashleymills 0:e979170e02e7 1388 word32 s0, s1, s2, s3;
ashleymills 0:e979170e02e7 1389 word32 t0, t1, t2, t3;
ashleymills 0:e979170e02e7 1390 word32 r = aes->rounds >> 1;
ashleymills 0:e979170e02e7 1391
ashleymills 0:e979170e02e7 1392 const word32* rk = aes->key;
ashleymills 0:e979170e02e7 1393 if (r > 7 || r == 0) {
ashleymills 0:e979170e02e7 1394 CYASSL_MSG("AesEncrypt encountered improper key, set it up");
ashleymills 0:e979170e02e7 1395 return; /* stop instead of segfaulting, set up your keys! */
ashleymills 0:e979170e02e7 1396 }
ashleymills 0:e979170e02e7 1397 #ifdef CYASSL_AESNI
ashleymills 0:e979170e02e7 1398 if (aes->use_aesni) {
ashleymills 0:e979170e02e7 1399 CYASSL_MSG("AesEncrypt encountered aesni keysetup, don't use direct");
ashleymills 0:e979170e02e7 1400 return; /* just stop now */
ashleymills 0:e979170e02e7 1401 }
ashleymills 0:e979170e02e7 1402 #endif
ashleymills 0:e979170e02e7 1403
ashleymills 0:e979170e02e7 1404 /*
ashleymills 0:e979170e02e7 1405 * map byte array block to cipher state
ashleymills 0:e979170e02e7 1406 * and add initial round key:
ashleymills 0:e979170e02e7 1407 */
ashleymills 0:e979170e02e7 1408 XMEMCPY(&s0, inBlock, sizeof(s0));
ashleymills 0:e979170e02e7 1409 XMEMCPY(&s1, inBlock + sizeof(s0), sizeof(s1));
ashleymills 0:e979170e02e7 1410 XMEMCPY(&s2, inBlock + 2 * sizeof(s0), sizeof(s2));
ashleymills 0:e979170e02e7 1411 XMEMCPY(&s3, inBlock + 3 * sizeof(s0), sizeof(s3));
ashleymills 0:e979170e02e7 1412
ashleymills 0:e979170e02e7 1413 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 1414 s0 = ByteReverseWord32(s0);
ashleymills 0:e979170e02e7 1415 s1 = ByteReverseWord32(s1);
ashleymills 0:e979170e02e7 1416 s2 = ByteReverseWord32(s2);
ashleymills 0:e979170e02e7 1417 s3 = ByteReverseWord32(s3);
ashleymills 0:e979170e02e7 1418 #endif
ashleymills 0:e979170e02e7 1419
ashleymills 0:e979170e02e7 1420 s0 ^= rk[0];
ashleymills 0:e979170e02e7 1421 s1 ^= rk[1];
ashleymills 0:e979170e02e7 1422 s2 ^= rk[2];
ashleymills 0:e979170e02e7 1423 s3 ^= rk[3];
ashleymills 0:e979170e02e7 1424
ashleymills 0:e979170e02e7 1425 /*
ashleymills 0:e979170e02e7 1426 * Nr - 1 full rounds:
ashleymills 0:e979170e02e7 1427 */
ashleymills 0:e979170e02e7 1428
ashleymills 0:e979170e02e7 1429 for (;;) {
ashleymills 0:e979170e02e7 1430 t0 =
ashleymills 0:e979170e02e7 1431 Te[0][GETBYTE(s0, 3)] ^
ashleymills 0:e979170e02e7 1432 Te[1][GETBYTE(s1, 2)] ^
ashleymills 0:e979170e02e7 1433 Te[2][GETBYTE(s2, 1)] ^
ashleymills 0:e979170e02e7 1434 Te[3][GETBYTE(s3, 0)] ^
ashleymills 0:e979170e02e7 1435 rk[4];
ashleymills 0:e979170e02e7 1436 t1 =
ashleymills 0:e979170e02e7 1437 Te[0][GETBYTE(s1, 3)] ^
ashleymills 0:e979170e02e7 1438 Te[1][GETBYTE(s2, 2)] ^
ashleymills 0:e979170e02e7 1439 Te[2][GETBYTE(s3, 1)] ^
ashleymills 0:e979170e02e7 1440 Te[3][GETBYTE(s0, 0)] ^
ashleymills 0:e979170e02e7 1441 rk[5];
ashleymills 0:e979170e02e7 1442 t2 =
ashleymills 0:e979170e02e7 1443 Te[0][GETBYTE(s2, 3)] ^
ashleymills 0:e979170e02e7 1444 Te[1][GETBYTE(s3, 2)] ^
ashleymills 0:e979170e02e7 1445 Te[2][GETBYTE(s0, 1)] ^
ashleymills 0:e979170e02e7 1446 Te[3][GETBYTE(s1, 0)] ^
ashleymills 0:e979170e02e7 1447 rk[6];
ashleymills 0:e979170e02e7 1448 t3 =
ashleymills 0:e979170e02e7 1449 Te[0][GETBYTE(s3, 3)] ^
ashleymills 0:e979170e02e7 1450 Te[1][GETBYTE(s0, 2)] ^
ashleymills 0:e979170e02e7 1451 Te[2][GETBYTE(s1, 1)] ^
ashleymills 0:e979170e02e7 1452 Te[3][GETBYTE(s2, 0)] ^
ashleymills 0:e979170e02e7 1453 rk[7];
ashleymills 0:e979170e02e7 1454
ashleymills 0:e979170e02e7 1455 rk += 8;
ashleymills 0:e979170e02e7 1456 if (--r == 0) {
ashleymills 0:e979170e02e7 1457 break;
ashleymills 0:e979170e02e7 1458 }
ashleymills 0:e979170e02e7 1459
ashleymills 0:e979170e02e7 1460 s0 =
ashleymills 0:e979170e02e7 1461 Te[0][GETBYTE(t0, 3)] ^
ashleymills 0:e979170e02e7 1462 Te[1][GETBYTE(t1, 2)] ^
ashleymills 0:e979170e02e7 1463 Te[2][GETBYTE(t2, 1)] ^
ashleymills 0:e979170e02e7 1464 Te[3][GETBYTE(t3, 0)] ^
ashleymills 0:e979170e02e7 1465 rk[0];
ashleymills 0:e979170e02e7 1466 s1 =
ashleymills 0:e979170e02e7 1467 Te[0][GETBYTE(t1, 3)] ^
ashleymills 0:e979170e02e7 1468 Te[1][GETBYTE(t2, 2)] ^
ashleymills 0:e979170e02e7 1469 Te[2][GETBYTE(t3, 1)] ^
ashleymills 0:e979170e02e7 1470 Te[3][GETBYTE(t0, 0)] ^
ashleymills 0:e979170e02e7 1471 rk[1];
ashleymills 0:e979170e02e7 1472 s2 =
ashleymills 0:e979170e02e7 1473 Te[0][GETBYTE(t2, 3)] ^
ashleymills 0:e979170e02e7 1474 Te[1][GETBYTE(t3, 2)] ^
ashleymills 0:e979170e02e7 1475 Te[2][GETBYTE(t0, 1)] ^
ashleymills 0:e979170e02e7 1476 Te[3][GETBYTE(t1, 0)] ^
ashleymills 0:e979170e02e7 1477 rk[2];
ashleymills 0:e979170e02e7 1478 s3 =
ashleymills 0:e979170e02e7 1479 Te[0][GETBYTE(t3, 3)] ^
ashleymills 0:e979170e02e7 1480 Te[1][GETBYTE(t0, 2)] ^
ashleymills 0:e979170e02e7 1481 Te[2][GETBYTE(t1, 1)] ^
ashleymills 0:e979170e02e7 1482 Te[3][GETBYTE(t2, 0)] ^
ashleymills 0:e979170e02e7 1483 rk[3];
ashleymills 0:e979170e02e7 1484 }
ashleymills 0:e979170e02e7 1485
ashleymills 0:e979170e02e7 1486 /*
ashleymills 0:e979170e02e7 1487 * apply last round and
ashleymills 0:e979170e02e7 1488 * map cipher state to byte array block:
ashleymills 0:e979170e02e7 1489 */
ashleymills 0:e979170e02e7 1490
ashleymills 0:e979170e02e7 1491 s0 =
ashleymills 0:e979170e02e7 1492 (Te[4][GETBYTE(t0, 3)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1493 (Te[4][GETBYTE(t1, 2)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1494 (Te[4][GETBYTE(t2, 1)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1495 (Te[4][GETBYTE(t3, 0)] & 0x000000ff) ^
ashleymills 0:e979170e02e7 1496 rk[0];
ashleymills 0:e979170e02e7 1497 s1 =
ashleymills 0:e979170e02e7 1498 (Te[4][GETBYTE(t1, 3)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1499 (Te[4][GETBYTE(t2, 2)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1500 (Te[4][GETBYTE(t3, 1)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1501 (Te[4][GETBYTE(t0, 0)] & 0x000000ff) ^
ashleymills 0:e979170e02e7 1502 rk[1];
ashleymills 0:e979170e02e7 1503 s2 =
ashleymills 0:e979170e02e7 1504 (Te[4][GETBYTE(t2, 3)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1505 (Te[4][GETBYTE(t3, 2)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1506 (Te[4][GETBYTE(t0, 1)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1507 (Te[4][GETBYTE(t1, 0)] & 0x000000ff) ^
ashleymills 0:e979170e02e7 1508 rk[2];
ashleymills 0:e979170e02e7 1509 s3 =
ashleymills 0:e979170e02e7 1510 (Te[4][GETBYTE(t3, 3)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1511 (Te[4][GETBYTE(t0, 2)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1512 (Te[4][GETBYTE(t1, 1)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1513 (Te[4][GETBYTE(t2, 0)] & 0x000000ff) ^
ashleymills 0:e979170e02e7 1514 rk[3];
ashleymills 0:e979170e02e7 1515
ashleymills 0:e979170e02e7 1516 /* write out */
ashleymills 0:e979170e02e7 1517 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 1518 s0 = ByteReverseWord32(s0);
ashleymills 0:e979170e02e7 1519 s1 = ByteReverseWord32(s1);
ashleymills 0:e979170e02e7 1520 s2 = ByteReverseWord32(s2);
ashleymills 0:e979170e02e7 1521 s3 = ByteReverseWord32(s3);
ashleymills 0:e979170e02e7 1522 #endif
ashleymills 0:e979170e02e7 1523
ashleymills 0:e979170e02e7 1524 XMEMCPY(outBlock, &s0, sizeof(s0));
ashleymills 0:e979170e02e7 1525 XMEMCPY(outBlock + sizeof(s0), &s1, sizeof(s1));
ashleymills 0:e979170e02e7 1526 XMEMCPY(outBlock + 2 * sizeof(s0), &s2, sizeof(s2));
ashleymills 0:e979170e02e7 1527 XMEMCPY(outBlock + 3 * sizeof(s0), &s3, sizeof(s3));
ashleymills 0:e979170e02e7 1528 }
ashleymills 0:e979170e02e7 1529
ashleymills 0:e979170e02e7 1530
ashleymills 0:e979170e02e7 1531 static void AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock)
ashleymills 0:e979170e02e7 1532 {
ashleymills 0:e979170e02e7 1533 word32 s0, s1, s2, s3;
ashleymills 0:e979170e02e7 1534 word32 t0, t1, t2, t3;
ashleymills 0:e979170e02e7 1535 word32 r = aes->rounds >> 1;
ashleymills 0:e979170e02e7 1536
ashleymills 0:e979170e02e7 1537 const word32* rk = aes->key;
ashleymills 0:e979170e02e7 1538 if (r > 7 || r == 0) {
ashleymills 0:e979170e02e7 1539 CYASSL_MSG("AesDecrypt encountered improper key, set it up");
ashleymills 0:e979170e02e7 1540 return; /* stop instead of segfaulting, set up your keys! */
ashleymills 0:e979170e02e7 1541 }
ashleymills 0:e979170e02e7 1542 #ifdef CYASSL_AESNI
ashleymills 0:e979170e02e7 1543 if (aes->use_aesni) {
ashleymills 0:e979170e02e7 1544 CYASSL_MSG("AesEncrypt encountered aesni keysetup, don't use direct");
ashleymills 0:e979170e02e7 1545 return; /* just stop now */
ashleymills 0:e979170e02e7 1546 }
ashleymills 0:e979170e02e7 1547 #endif
ashleymills 0:e979170e02e7 1548
ashleymills 0:e979170e02e7 1549 /*
ashleymills 0:e979170e02e7 1550 * map byte array block to cipher state
ashleymills 0:e979170e02e7 1551 * and add initial round key:
ashleymills 0:e979170e02e7 1552 */
ashleymills 0:e979170e02e7 1553 XMEMCPY(&s0, inBlock, sizeof(s0));
ashleymills 0:e979170e02e7 1554 XMEMCPY(&s1, inBlock + sizeof(s0), sizeof(s1));
ashleymills 0:e979170e02e7 1555 XMEMCPY(&s2, inBlock + 2 * sizeof(s0), sizeof(s2));
ashleymills 0:e979170e02e7 1556 XMEMCPY(&s3, inBlock + 3 * sizeof(s0), sizeof(s3));
ashleymills 0:e979170e02e7 1557
ashleymills 0:e979170e02e7 1558 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 1559 s0 = ByteReverseWord32(s0);
ashleymills 0:e979170e02e7 1560 s1 = ByteReverseWord32(s1);
ashleymills 0:e979170e02e7 1561 s2 = ByteReverseWord32(s2);
ashleymills 0:e979170e02e7 1562 s3 = ByteReverseWord32(s3);
ashleymills 0:e979170e02e7 1563 #endif
ashleymills 0:e979170e02e7 1564
ashleymills 0:e979170e02e7 1565 s0 ^= rk[0];
ashleymills 0:e979170e02e7 1566 s1 ^= rk[1];
ashleymills 0:e979170e02e7 1567 s2 ^= rk[2];
ashleymills 0:e979170e02e7 1568 s3 ^= rk[3];
ashleymills 0:e979170e02e7 1569
ashleymills 0:e979170e02e7 1570 /*
ashleymills 0:e979170e02e7 1571 * Nr - 1 full rounds:
ashleymills 0:e979170e02e7 1572 */
ashleymills 0:e979170e02e7 1573
ashleymills 0:e979170e02e7 1574 for (;;) {
ashleymills 0:e979170e02e7 1575 t0 =
ashleymills 0:e979170e02e7 1576 Td[0][GETBYTE(s0, 3)] ^
ashleymills 0:e979170e02e7 1577 Td[1][GETBYTE(s3, 2)] ^
ashleymills 0:e979170e02e7 1578 Td[2][GETBYTE(s2, 1)] ^
ashleymills 0:e979170e02e7 1579 Td[3][GETBYTE(s1, 0)] ^
ashleymills 0:e979170e02e7 1580 rk[4];
ashleymills 0:e979170e02e7 1581 t1 =
ashleymills 0:e979170e02e7 1582 Td[0][GETBYTE(s1, 3)] ^
ashleymills 0:e979170e02e7 1583 Td[1][GETBYTE(s0, 2)] ^
ashleymills 0:e979170e02e7 1584 Td[2][GETBYTE(s3, 1)] ^
ashleymills 0:e979170e02e7 1585 Td[3][GETBYTE(s2, 0)] ^
ashleymills 0:e979170e02e7 1586 rk[5];
ashleymills 0:e979170e02e7 1587 t2 =
ashleymills 0:e979170e02e7 1588 Td[0][GETBYTE(s2, 3)] ^
ashleymills 0:e979170e02e7 1589 Td[1][GETBYTE(s1, 2)] ^
ashleymills 0:e979170e02e7 1590 Td[2][GETBYTE(s0, 1)] ^
ashleymills 0:e979170e02e7 1591 Td[3][GETBYTE(s3, 0)] ^
ashleymills 0:e979170e02e7 1592 rk[6];
ashleymills 0:e979170e02e7 1593 t3 =
ashleymills 0:e979170e02e7 1594 Td[0][GETBYTE(s3, 3)] ^
ashleymills 0:e979170e02e7 1595 Td[1][GETBYTE(s2, 2)] ^
ashleymills 0:e979170e02e7 1596 Td[2][GETBYTE(s1, 1)] ^
ashleymills 0:e979170e02e7 1597 Td[3][GETBYTE(s0, 0)] ^
ashleymills 0:e979170e02e7 1598 rk[7];
ashleymills 0:e979170e02e7 1599
ashleymills 0:e979170e02e7 1600 rk += 8;
ashleymills 0:e979170e02e7 1601 if (--r == 0) {
ashleymills 0:e979170e02e7 1602 break;
ashleymills 0:e979170e02e7 1603 }
ashleymills 0:e979170e02e7 1604
ashleymills 0:e979170e02e7 1605 s0 =
ashleymills 0:e979170e02e7 1606 Td[0][GETBYTE(t0, 3)] ^
ashleymills 0:e979170e02e7 1607 Td[1][GETBYTE(t3, 2)] ^
ashleymills 0:e979170e02e7 1608 Td[2][GETBYTE(t2, 1)] ^
ashleymills 0:e979170e02e7 1609 Td[3][GETBYTE(t1, 0)] ^
ashleymills 0:e979170e02e7 1610 rk[0];
ashleymills 0:e979170e02e7 1611 s1 =
ashleymills 0:e979170e02e7 1612 Td[0][GETBYTE(t1, 3)] ^
ashleymills 0:e979170e02e7 1613 Td[1][GETBYTE(t0, 2)] ^
ashleymills 0:e979170e02e7 1614 Td[2][GETBYTE(t3, 1)] ^
ashleymills 0:e979170e02e7 1615 Td[3][GETBYTE(t2, 0)] ^
ashleymills 0:e979170e02e7 1616 rk[1];
ashleymills 0:e979170e02e7 1617 s2 =
ashleymills 0:e979170e02e7 1618 Td[0][GETBYTE(t2, 3)] ^
ashleymills 0:e979170e02e7 1619 Td[1][GETBYTE(t1, 2)] ^
ashleymills 0:e979170e02e7 1620 Td[2][GETBYTE(t0, 1)] ^
ashleymills 0:e979170e02e7 1621 Td[3][GETBYTE(t3, 0)] ^
ashleymills 0:e979170e02e7 1622 rk[2];
ashleymills 0:e979170e02e7 1623 s3 =
ashleymills 0:e979170e02e7 1624 Td[0][GETBYTE(t3, 3)] ^
ashleymills 0:e979170e02e7 1625 Td[1][GETBYTE(t2, 2)] ^
ashleymills 0:e979170e02e7 1626 Td[2][GETBYTE(t1, 1)] ^
ashleymills 0:e979170e02e7 1627 Td[3][GETBYTE(t0, 0)] ^
ashleymills 0:e979170e02e7 1628 rk[3];
ashleymills 0:e979170e02e7 1629 }
ashleymills 0:e979170e02e7 1630 /*
ashleymills 0:e979170e02e7 1631 * apply last round and
ashleymills 0:e979170e02e7 1632 * map cipher state to byte array block:
ashleymills 0:e979170e02e7 1633 */
ashleymills 0:e979170e02e7 1634 s0 =
ashleymills 0:e979170e02e7 1635 (Td[4][GETBYTE(t0, 3)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1636 (Td[4][GETBYTE(t3, 2)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1637 (Td[4][GETBYTE(t2, 1)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1638 (Td[4][GETBYTE(t1, 0)] & 0x000000ff) ^
ashleymills 0:e979170e02e7 1639 rk[0];
ashleymills 0:e979170e02e7 1640 s1 =
ashleymills 0:e979170e02e7 1641 (Td[4][GETBYTE(t1, 3)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1642 (Td[4][GETBYTE(t0, 2)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1643 (Td[4][GETBYTE(t3, 1)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1644 (Td[4][GETBYTE(t2, 0)] & 0x000000ff) ^
ashleymills 0:e979170e02e7 1645 rk[1];
ashleymills 0:e979170e02e7 1646 s2 =
ashleymills 0:e979170e02e7 1647 (Td[4][GETBYTE(t2, 3)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1648 (Td[4][GETBYTE(t1, 2)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1649 (Td[4][GETBYTE(t0, 1)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1650 (Td[4][GETBYTE(t3, 0)] & 0x000000ff) ^
ashleymills 0:e979170e02e7 1651 rk[2];
ashleymills 0:e979170e02e7 1652 s3 =
ashleymills 0:e979170e02e7 1653 (Td[4][GETBYTE(t3, 3)] & 0xff000000) ^
ashleymills 0:e979170e02e7 1654 (Td[4][GETBYTE(t2, 2)] & 0x00ff0000) ^
ashleymills 0:e979170e02e7 1655 (Td[4][GETBYTE(t1, 1)] & 0x0000ff00) ^
ashleymills 0:e979170e02e7 1656 (Td[4][GETBYTE(t0, 0)] & 0x000000ff) ^
ashleymills 0:e979170e02e7 1657 rk[3];
ashleymills 0:e979170e02e7 1658
ashleymills 0:e979170e02e7 1659 /* write out */
ashleymills 0:e979170e02e7 1660 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 1661 s0 = ByteReverseWord32(s0);
ashleymills 0:e979170e02e7 1662 s1 = ByteReverseWord32(s1);
ashleymills 0:e979170e02e7 1663 s2 = ByteReverseWord32(s2);
ashleymills 0:e979170e02e7 1664 s3 = ByteReverseWord32(s3);
ashleymills 0:e979170e02e7 1665 #endif
ashleymills 0:e979170e02e7 1666
ashleymills 0:e979170e02e7 1667 XMEMCPY(outBlock, &s0, sizeof(s0));
ashleymills 0:e979170e02e7 1668 XMEMCPY(outBlock + sizeof(s0), &s1, sizeof(s1));
ashleymills 0:e979170e02e7 1669 XMEMCPY(outBlock + 2 * sizeof(s0), &s2, sizeof(s2));
ashleymills 0:e979170e02e7 1670 XMEMCPY(outBlock + 3 * sizeof(s0), &s3, sizeof(s3));
ashleymills 0:e979170e02e7 1671 }
ashleymills 0:e979170e02e7 1672
ashleymills 0:e979170e02e7 1673
ashleymills 0:e979170e02e7 1674 void AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
ashleymills 0:e979170e02e7 1675 {
ashleymills 0:e979170e02e7 1676 word32 blocks = sz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1677
ashleymills 0:e979170e02e7 1678 #ifdef HAVE_CAVIUM
ashleymills 0:e979170e02e7 1679 if (aes->magic == CYASSL_AES_CAVIUM_MAGIC)
ashleymills 0:e979170e02e7 1680 return AesCaviumCbcEncrypt(aes, out, in, sz);
ashleymills 0:e979170e02e7 1681 #endif
ashleymills 0:e979170e02e7 1682
ashleymills 0:e979170e02e7 1683 #ifdef CYASSL_AESNI
ashleymills 0:e979170e02e7 1684 if (haveAESNI) {
ashleymills 0:e979170e02e7 1685 #ifdef DEBUG_AESNI
ashleymills 0:e979170e02e7 1686 printf("about to aes cbc encrypt\n");
ashleymills 0:e979170e02e7 1687 printf("in = %p\n", in);
ashleymills 0:e979170e02e7 1688 printf("out = %p\n", out);
ashleymills 0:e979170e02e7 1689 printf("aes->key = %p\n", aes->key);
ashleymills 0:e979170e02e7 1690 printf("aes->reg = %p\n", aes->reg);
ashleymills 0:e979170e02e7 1691 printf("aes->rounds = %d\n", aes->rounds);
ashleymills 0:e979170e02e7 1692 printf("sz = %d\n", sz);
ashleymills 0:e979170e02e7 1693 #endif
ashleymills 0:e979170e02e7 1694 AES_CBC_encrypt(in, out, (byte*)aes->reg, sz, (byte*)aes->key,
ashleymills 0:e979170e02e7 1695 aes->rounds);
ashleymills 0:e979170e02e7 1696 /* store iv for next call */
ashleymills 0:e979170e02e7 1697 XMEMCPY(aes->reg, out + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1698 return;
ashleymills 0:e979170e02e7 1699 }
ashleymills 0:e979170e02e7 1700 #endif
ashleymills 0:e979170e02e7 1701
ashleymills 0:e979170e02e7 1702 while (blocks--) {
ashleymills 0:e979170e02e7 1703 xorbuf((byte*)aes->reg, in, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1704 AesEncrypt(aes, (byte*)aes->reg, (byte*)aes->reg);
ashleymills 0:e979170e02e7 1705 XMEMCPY(out, aes->reg, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1706
ashleymills 0:e979170e02e7 1707 out += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1708 in += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1709 }
ashleymills 0:e979170e02e7 1710 }
ashleymills 0:e979170e02e7 1711
ashleymills 0:e979170e02e7 1712
ashleymills 0:e979170e02e7 1713 void AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz)
ashleymills 0:e979170e02e7 1714 {
ashleymills 0:e979170e02e7 1715 word32 blocks = sz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1716
ashleymills 0:e979170e02e7 1717 #ifdef HAVE_CAVIUM
ashleymills 0:e979170e02e7 1718 if (aes->magic == CYASSL_AES_CAVIUM_MAGIC)
ashleymills 0:e979170e02e7 1719 return AesCaviumCbcDecrypt(aes, out, in, sz);
ashleymills 0:e979170e02e7 1720 #endif
ashleymills 0:e979170e02e7 1721
ashleymills 0:e979170e02e7 1722 #ifdef CYASSL_AESNI
ashleymills 0:e979170e02e7 1723 if (haveAESNI) {
ashleymills 0:e979170e02e7 1724 #ifdef DEBUG_AESNI
ashleymills 0:e979170e02e7 1725 printf("about to aes cbc decrypt\n");
ashleymills 0:e979170e02e7 1726 printf("in = %p\n", in);
ashleymills 0:e979170e02e7 1727 printf("out = %p\n", out);
ashleymills 0:e979170e02e7 1728 printf("aes->key = %p\n", aes->key);
ashleymills 0:e979170e02e7 1729 printf("aes->reg = %p\n", aes->reg);
ashleymills 0:e979170e02e7 1730 printf("aes->rounds = %d\n", aes->rounds);
ashleymills 0:e979170e02e7 1731 printf("sz = %d\n", sz);
ashleymills 0:e979170e02e7 1732 #endif
ashleymills 0:e979170e02e7 1733
ashleymills 0:e979170e02e7 1734 /* if input and output same will overwrite input iv */
ashleymills 0:e979170e02e7 1735 XMEMCPY(aes->tmp, in + sz - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1736 AES_CBC_decrypt(in, out, (byte*)aes->reg, sz, (byte*)aes->key,
ashleymills 0:e979170e02e7 1737 aes->rounds);
ashleymills 0:e979170e02e7 1738 /* store iv for next call */
ashleymills 0:e979170e02e7 1739 XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1740 return;
ashleymills 0:e979170e02e7 1741 }
ashleymills 0:e979170e02e7 1742 #endif
ashleymills 0:e979170e02e7 1743
ashleymills 0:e979170e02e7 1744 while (blocks--) {
ashleymills 0:e979170e02e7 1745 XMEMCPY(aes->tmp, in, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1746 AesDecrypt(aes, (byte*)aes->tmp, out);
ashleymills 0:e979170e02e7 1747 xorbuf(out, (byte*)aes->reg, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1748 XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1749
ashleymills 0:e979170e02e7 1750 out += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1751 in += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1752 }
ashleymills 0:e979170e02e7 1753 }
ashleymills 0:e979170e02e7 1754
ashleymills 0:e979170e02e7 1755
ashleymills 0:e979170e02e7 1756 #ifdef CYASSL_AES_DIRECT
ashleymills 0:e979170e02e7 1757
ashleymills 0:e979170e02e7 1758 /* Allow direct access to one block encrypt */
ashleymills 0:e979170e02e7 1759 void AesEncryptDirect(Aes* aes, byte* out, const byte* in)
ashleymills 0:e979170e02e7 1760 {
ashleymills 0:e979170e02e7 1761 return AesEncrypt(aes, in, out);
ashleymills 0:e979170e02e7 1762 }
ashleymills 0:e979170e02e7 1763
ashleymills 0:e979170e02e7 1764
ashleymills 0:e979170e02e7 1765 /* Allow direct access to one block decrypt */
ashleymills 0:e979170e02e7 1766 void AesDecryptDirect(Aes* aes, byte* out, const byte* in)
ashleymills 0:e979170e02e7 1767 {
ashleymills 0:e979170e02e7 1768 return AesDecrypt(aes, in, out);
ashleymills 0:e979170e02e7 1769 }
ashleymills 0:e979170e02e7 1770
ashleymills 0:e979170e02e7 1771
ashleymills 0:e979170e02e7 1772 #endif /* CYASSL_AES_DIRECT */
ashleymills 0:e979170e02e7 1773
ashleymills 0:e979170e02e7 1774
ashleymills 0:e979170e02e7 1775 #if defined(CYASSL_AES_DIRECT) || defined(CYASSL_AES_COUNTER)
ashleymills 0:e979170e02e7 1776
ashleymills 0:e979170e02e7 1777 /* AES-CTR and AES-DIRECT need to use this for key setup, no aesni yet */
ashleymills 0:e979170e02e7 1778 int AesSetKeyDirect(Aes* aes, const byte* userKey, word32 keylen,
ashleymills 0:e979170e02e7 1779 const byte* iv, int dir)
ashleymills 0:e979170e02e7 1780 {
ashleymills 0:e979170e02e7 1781 return AesSetKeyLocal(aes, userKey, keylen, iv, dir);
ashleymills 0:e979170e02e7 1782 }
ashleymills 0:e979170e02e7 1783
ashleymills 0:e979170e02e7 1784 #endif /* CYASSL_AES_DIRECT || CYASSL_AES_COUNTER */
ashleymills 0:e979170e02e7 1785
ashleymills 0:e979170e02e7 1786
ashleymills 0:e979170e02e7 1787 #ifdef CYASSL_AES_COUNTER
ashleymills 0:e979170e02e7 1788
ashleymills 0:e979170e02e7 1789 /* Increment AES counter */
ashleymills 0:e979170e02e7 1790 static INLINE void IncrementAesCounter(byte* inOutCtr)
ashleymills 0:e979170e02e7 1791 {
ashleymills 0:e979170e02e7 1792 int i;
ashleymills 0:e979170e02e7 1793
ashleymills 0:e979170e02e7 1794 /* in network byte order so start at end and work back */
ashleymills 0:e979170e02e7 1795 for (i = AES_BLOCK_SIZE - 1; i >= 0; i--) {
ashleymills 0:e979170e02e7 1796 if (++inOutCtr[i]) /* we're done unless we overflow */
ashleymills 0:e979170e02e7 1797 return;
ashleymills 0:e979170e02e7 1798 }
ashleymills 0:e979170e02e7 1799 }
ashleymills 0:e979170e02e7 1800
ashleymills 0:e979170e02e7 1801
ashleymills 0:e979170e02e7 1802 void AesCtrEncrypt(Aes* aes, byte* out, const byte* in, word32 sz)
ashleymills 0:e979170e02e7 1803 {
ashleymills 0:e979170e02e7 1804 word32 blocks = sz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1805
ashleymills 0:e979170e02e7 1806 while (blocks--) {
ashleymills 0:e979170e02e7 1807 AesEncrypt(aes, (byte*)aes->reg, out);
ashleymills 0:e979170e02e7 1808 IncrementAesCounter((byte*)aes->reg);
ashleymills 0:e979170e02e7 1809 xorbuf(out, in, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1810
ashleymills 0:e979170e02e7 1811 out += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1812 in += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1813 }
ashleymills 0:e979170e02e7 1814 }
ashleymills 0:e979170e02e7 1815
ashleymills 0:e979170e02e7 1816 #endif /* CYASSL_AES_COUNTER */
ashleymills 0:e979170e02e7 1817
ashleymills 0:e979170e02e7 1818
ashleymills 0:e979170e02e7 1819 #ifdef HAVE_AESGCM
ashleymills 0:e979170e02e7 1820
ashleymills 0:e979170e02e7 1821 /*
ashleymills 0:e979170e02e7 1822 * The IV for AES GCM, stored in struct Aes's member reg, is comprised of
ashleymills 0:e979170e02e7 1823 * three parts in order:
ashleymills 0:e979170e02e7 1824 * 1. The implicit IV. This is generated from the PRF using the shared
ashleymills 0:e979170e02e7 1825 * secrets between endpoints. It is 4 bytes long.
ashleymills 0:e979170e02e7 1826 * 2. The explicit IV. This is set by the user of the AES. It needs to be
ashleymills 0:e979170e02e7 1827 * unique for each call to encrypt. The explicit IV is shared with the
ashleymills 0:e979170e02e7 1828 * other end of the transaction in the clear.
ashleymills 0:e979170e02e7 1829 * 3. The counter. Each block of data is encrypted with its own sequence
ashleymills 0:e979170e02e7 1830 * number counter.
ashleymills 0:e979170e02e7 1831 */
ashleymills 0:e979170e02e7 1832
ashleymills 0:e979170e02e7 1833 enum {
ashleymills 0:e979170e02e7 1834 CTR_SZ = 4
ashleymills 0:e979170e02e7 1835 };
ashleymills 0:e979170e02e7 1836
ashleymills 0:e979170e02e7 1837
ashleymills 0:e979170e02e7 1838 static INLINE void InitGcmCounter(byte* inOutCtr)
ashleymills 0:e979170e02e7 1839 {
ashleymills 0:e979170e02e7 1840 inOutCtr[AES_BLOCK_SIZE - 4] = 0;
ashleymills 0:e979170e02e7 1841 inOutCtr[AES_BLOCK_SIZE - 3] = 0;
ashleymills 0:e979170e02e7 1842 inOutCtr[AES_BLOCK_SIZE - 2] = 0;
ashleymills 0:e979170e02e7 1843 inOutCtr[AES_BLOCK_SIZE - 1] = 1;
ashleymills 0:e979170e02e7 1844 }
ashleymills 0:e979170e02e7 1845
ashleymills 0:e979170e02e7 1846
ashleymills 0:e979170e02e7 1847 static INLINE void IncrementGcmCounter(byte* inOutCtr)
ashleymills 0:e979170e02e7 1848 {
ashleymills 0:e979170e02e7 1849 int i;
ashleymills 0:e979170e02e7 1850
ashleymills 0:e979170e02e7 1851 /* in network byte order so start at end and work back */
ashleymills 0:e979170e02e7 1852 for (i = AES_BLOCK_SIZE - 1; i >= AES_BLOCK_SIZE - CTR_SZ; i--) {
ashleymills 0:e979170e02e7 1853 if (++inOutCtr[i]) /* we're done unless we overflow */
ashleymills 0:e979170e02e7 1854 return;
ashleymills 0:e979170e02e7 1855 }
ashleymills 0:e979170e02e7 1856 }
ashleymills 0:e979170e02e7 1857
ashleymills 0:e979170e02e7 1858
ashleymills 0:e979170e02e7 1859 #if defined(GCM_SMALL) || defined(GCM_TABLE)
ashleymills 0:e979170e02e7 1860
ashleymills 0:e979170e02e7 1861 static INLINE void FlattenSzInBits(byte* buf, word32 sz)
ashleymills 0:e979170e02e7 1862 {
ashleymills 0:e979170e02e7 1863 /* Multiply the sz by 8 */
ashleymills 0:e979170e02e7 1864 word32 szHi = (sz >> (8*sizeof(sz) - 3));
ashleymills 0:e979170e02e7 1865 sz <<= 3;
ashleymills 0:e979170e02e7 1866
ashleymills 0:e979170e02e7 1867 /* copy over the words of the sz into the destination buffer */
ashleymills 0:e979170e02e7 1868 buf[0] = (szHi >> 24) & 0xff;
ashleymills 0:e979170e02e7 1869 buf[1] = (szHi >> 16) & 0xff;
ashleymills 0:e979170e02e7 1870 buf[2] = (szHi >> 8) & 0xff;
ashleymills 0:e979170e02e7 1871 buf[3] = szHi & 0xff;
ashleymills 0:e979170e02e7 1872 buf[4] = (sz >> 24) & 0xff;
ashleymills 0:e979170e02e7 1873 buf[5] = (sz >> 16) & 0xff;
ashleymills 0:e979170e02e7 1874 buf[6] = (sz >> 8) & 0xff;
ashleymills 0:e979170e02e7 1875 buf[7] = sz & 0xff;
ashleymills 0:e979170e02e7 1876 }
ashleymills 0:e979170e02e7 1877
ashleymills 0:e979170e02e7 1878
ashleymills 0:e979170e02e7 1879 static INLINE void RIGHTSHIFTX(byte* x)
ashleymills 0:e979170e02e7 1880 {
ashleymills 0:e979170e02e7 1881 int i;
ashleymills 0:e979170e02e7 1882 int carryOut = 0;
ashleymills 0:e979170e02e7 1883 int carryIn = 0;
ashleymills 0:e979170e02e7 1884 int borrow = x[15] & 0x01;
ashleymills 0:e979170e02e7 1885
ashleymills 0:e979170e02e7 1886 for (i = 0; i < AES_BLOCK_SIZE; i++) {
ashleymills 0:e979170e02e7 1887 carryOut = x[i] & 0x01;
ashleymills 0:e979170e02e7 1888 x[i] = (x[i] >> 1) | (carryIn ? 0x80 : 0);
ashleymills 0:e979170e02e7 1889 carryIn = carryOut;
ashleymills 0:e979170e02e7 1890 }
ashleymills 0:e979170e02e7 1891 if (borrow) x[0] ^= 0xE1;
ashleymills 0:e979170e02e7 1892 }
ashleymills 0:e979170e02e7 1893
ashleymills 0:e979170e02e7 1894 #endif /* defined(GCM_SMALL) || defined(GCM_TABLE) */
ashleymills 0:e979170e02e7 1895
ashleymills 0:e979170e02e7 1896
ashleymills 0:e979170e02e7 1897 #ifdef GCM_TABLE
ashleymills 0:e979170e02e7 1898
ashleymills 0:e979170e02e7 1899 static void GenerateM0(Aes* aes)
ashleymills 0:e979170e02e7 1900 {
ashleymills 0:e979170e02e7 1901 int i, j;
ashleymills 0:e979170e02e7 1902 byte (*m)[AES_BLOCK_SIZE] = aes->M0;
ashleymills 0:e979170e02e7 1903
ashleymills 0:e979170e02e7 1904 XMEMCPY(m[128], aes->H, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1905
ashleymills 0:e979170e02e7 1906 for (i = 64; i > 0; i /= 2) {
ashleymills 0:e979170e02e7 1907 XMEMCPY(m[i], m[i*2], AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1908 RIGHTSHIFTX(m[i]);
ashleymills 0:e979170e02e7 1909 }
ashleymills 0:e979170e02e7 1910
ashleymills 0:e979170e02e7 1911 for (i = 2; i < 256; i *= 2) {
ashleymills 0:e979170e02e7 1912 for (j = 1; j < i; j++) {
ashleymills 0:e979170e02e7 1913 XMEMCPY(m[i+j], m[i], AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1914 xorbuf(m[i+j], m[j], AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1915 }
ashleymills 0:e979170e02e7 1916 }
ashleymills 0:e979170e02e7 1917
ashleymills 0:e979170e02e7 1918 XMEMSET(m[0], 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1919 }
ashleymills 0:e979170e02e7 1920
ashleymills 0:e979170e02e7 1921 #endif /* GCM_TABLE */
ashleymills 0:e979170e02e7 1922
ashleymills 0:e979170e02e7 1923
ashleymills 0:e979170e02e7 1924 void AesGcmSetKey(Aes* aes, const byte* key, word32 len)
ashleymills 0:e979170e02e7 1925 {
ashleymills 0:e979170e02e7 1926 byte iv[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 1927
ashleymills 0:e979170e02e7 1928 if (!((len == 16) || (len == 24) || (len == 32)))
ashleymills 0:e979170e02e7 1929 return;
ashleymills 0:e979170e02e7 1930
ashleymills 0:e979170e02e7 1931 XMEMSET(iv, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1932 AesSetKeyLocal(aes, key, len, iv, AES_ENCRYPTION);
ashleymills 0:e979170e02e7 1933
ashleymills 0:e979170e02e7 1934 AesEncrypt(aes, iv, aes->H);
ashleymills 0:e979170e02e7 1935 #ifdef GCM_TABLE
ashleymills 0:e979170e02e7 1936 GenerateM0(aes);
ashleymills 0:e979170e02e7 1937 #endif /* GCM_TABLE */
ashleymills 0:e979170e02e7 1938 }
ashleymills 0:e979170e02e7 1939
ashleymills 0:e979170e02e7 1940
ashleymills 0:e979170e02e7 1941 #if defined(GCM_SMALL)
ashleymills 0:e979170e02e7 1942
ashleymills 0:e979170e02e7 1943 static void GMULT(byte* X, byte* Y)
ashleymills 0:e979170e02e7 1944 {
ashleymills 0:e979170e02e7 1945 byte Z[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 1946 byte V[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 1947 int i, j;
ashleymills 0:e979170e02e7 1948
ashleymills 0:e979170e02e7 1949 XMEMSET(Z, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1950 XMEMCPY(V, X, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1951 for (i = 0; i < AES_BLOCK_SIZE; i++)
ashleymills 0:e979170e02e7 1952 {
ashleymills 0:e979170e02e7 1953 byte y = Y[i];
ashleymills 0:e979170e02e7 1954 for (j = 0; j < 8; j++)
ashleymills 0:e979170e02e7 1955 {
ashleymills 0:e979170e02e7 1956 if (y & 0x80) {
ashleymills 0:e979170e02e7 1957 xorbuf(Z, V, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1958 }
ashleymills 0:e979170e02e7 1959
ashleymills 0:e979170e02e7 1960 RIGHTSHIFTX(V);
ashleymills 0:e979170e02e7 1961 y = y << 1;
ashleymills 0:e979170e02e7 1962 }
ashleymills 0:e979170e02e7 1963 }
ashleymills 0:e979170e02e7 1964 XMEMCPY(X, Z, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1965 }
ashleymills 0:e979170e02e7 1966
ashleymills 0:e979170e02e7 1967
ashleymills 0:e979170e02e7 1968 static void GHASH(Aes* aes, const byte* a, word32 aSz,
ashleymills 0:e979170e02e7 1969 const byte* c, word32 cSz, byte* s, word32 sSz)
ashleymills 0:e979170e02e7 1970 {
ashleymills 0:e979170e02e7 1971 byte x[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 1972 byte scratch[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 1973 word32 blocks, partial;
ashleymills 0:e979170e02e7 1974 byte* h = aes->H;
ashleymills 0:e979170e02e7 1975
ashleymills 0:e979170e02e7 1976 XMEMSET(x, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1977
ashleymills 0:e979170e02e7 1978 /* Hash in A, the Additional Authentication Data */
ashleymills 0:e979170e02e7 1979 if (aSz != 0 && a != NULL) {
ashleymills 0:e979170e02e7 1980 blocks = aSz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1981 partial = aSz % AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1982 while (blocks--) {
ashleymills 0:e979170e02e7 1983 xorbuf(x, a, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1984 GMULT(x, h);
ashleymills 0:e979170e02e7 1985 a += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1986 }
ashleymills 0:e979170e02e7 1987 if (partial != 0) {
ashleymills 0:e979170e02e7 1988 XMEMSET(scratch, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1989 XMEMCPY(scratch, a, partial);
ashleymills 0:e979170e02e7 1990 xorbuf(x, scratch, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 1991 GMULT(x, h);
ashleymills 0:e979170e02e7 1992 }
ashleymills 0:e979170e02e7 1993 }
ashleymills 0:e979170e02e7 1994
ashleymills 0:e979170e02e7 1995 /* Hash in C, the Ciphertext */
ashleymills 0:e979170e02e7 1996 if (cSz != 0 && c != NULL) {
ashleymills 0:e979170e02e7 1997 blocks = cSz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1998 partial = cSz % AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 1999 while (blocks--) {
ashleymills 0:e979170e02e7 2000 xorbuf(x, c, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2001 GMULT(x, h);
ashleymills 0:e979170e02e7 2002 c += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2003 }
ashleymills 0:e979170e02e7 2004 if (partial != 0) {
ashleymills 0:e979170e02e7 2005 XMEMSET(scratch, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2006 XMEMCPY(scratch, c, partial);
ashleymills 0:e979170e02e7 2007 xorbuf(x, scratch, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2008 GMULT(x, h);
ashleymills 0:e979170e02e7 2009 }
ashleymills 0:e979170e02e7 2010 }
ashleymills 0:e979170e02e7 2011
ashleymills 0:e979170e02e7 2012 /* Hash in the lengths of A and C in bits */
ashleymills 0:e979170e02e7 2013 FlattenSzInBits(&scratch[0], aSz);
ashleymills 0:e979170e02e7 2014 FlattenSzInBits(&scratch[8], cSz);
ashleymills 0:e979170e02e7 2015 xorbuf(x, scratch, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2016 GMULT(x, h);
ashleymills 0:e979170e02e7 2017
ashleymills 0:e979170e02e7 2018 /* Copy the result into s. */
ashleymills 0:e979170e02e7 2019 XMEMCPY(s, x, sSz);
ashleymills 0:e979170e02e7 2020 }
ashleymills 0:e979170e02e7 2021
ashleymills 0:e979170e02e7 2022 /* end GCM_SMALL */
ashleymills 0:e979170e02e7 2023 #elif defined(GCM_TABLE)
ashleymills 0:e979170e02e7 2024
ashleymills 0:e979170e02e7 2025 static const byte R[256][2] = {
ashleymills 0:e979170e02e7 2026 {0x00, 0x00}, {0x01, 0xc2}, {0x03, 0x84}, {0x02, 0x46},
ashleymills 0:e979170e02e7 2027 {0x07, 0x08}, {0x06, 0xca}, {0x04, 0x8c}, {0x05, 0x4e},
ashleymills 0:e979170e02e7 2028 {0x0e, 0x10}, {0x0f, 0xd2}, {0x0d, 0x94}, {0x0c, 0x56},
ashleymills 0:e979170e02e7 2029 {0x09, 0x18}, {0x08, 0xda}, {0x0a, 0x9c}, {0x0b, 0x5e},
ashleymills 0:e979170e02e7 2030 {0x1c, 0x20}, {0x1d, 0xe2}, {0x1f, 0xa4}, {0x1e, 0x66},
ashleymills 0:e979170e02e7 2031 {0x1b, 0x28}, {0x1a, 0xea}, {0x18, 0xac}, {0x19, 0x6e},
ashleymills 0:e979170e02e7 2032 {0x12, 0x30}, {0x13, 0xf2}, {0x11, 0xb4}, {0x10, 0x76},
ashleymills 0:e979170e02e7 2033 {0x15, 0x38}, {0x14, 0xfa}, {0x16, 0xbc}, {0x17, 0x7e},
ashleymills 0:e979170e02e7 2034 {0x38, 0x40}, {0x39, 0x82}, {0x3b, 0xc4}, {0x3a, 0x06},
ashleymills 0:e979170e02e7 2035 {0x3f, 0x48}, {0x3e, 0x8a}, {0x3c, 0xcc}, {0x3d, 0x0e},
ashleymills 0:e979170e02e7 2036 {0x36, 0x50}, {0x37, 0x92}, {0x35, 0xd4}, {0x34, 0x16},
ashleymills 0:e979170e02e7 2037 {0x31, 0x58}, {0x30, 0x9a}, {0x32, 0xdc}, {0x33, 0x1e},
ashleymills 0:e979170e02e7 2038 {0x24, 0x60}, {0x25, 0xa2}, {0x27, 0xe4}, {0x26, 0x26},
ashleymills 0:e979170e02e7 2039 {0x23, 0x68}, {0x22, 0xaa}, {0x20, 0xec}, {0x21, 0x2e},
ashleymills 0:e979170e02e7 2040 {0x2a, 0x70}, {0x2b, 0xb2}, {0x29, 0xf4}, {0x28, 0x36},
ashleymills 0:e979170e02e7 2041 {0x2d, 0x78}, {0x2c, 0xba}, {0x2e, 0xfc}, {0x2f, 0x3e},
ashleymills 0:e979170e02e7 2042 {0x70, 0x80}, {0x71, 0x42}, {0x73, 0x04}, {0x72, 0xc6},
ashleymills 0:e979170e02e7 2043 {0x77, 0x88}, {0x76, 0x4a}, {0x74, 0x0c}, {0x75, 0xce},
ashleymills 0:e979170e02e7 2044 {0x7e, 0x90}, {0x7f, 0x52}, {0x7d, 0x14}, {0x7c, 0xd6},
ashleymills 0:e979170e02e7 2045 {0x79, 0x98}, {0x78, 0x5a}, {0x7a, 0x1c}, {0x7b, 0xde},
ashleymills 0:e979170e02e7 2046 {0x6c, 0xa0}, {0x6d, 0x62}, {0x6f, 0x24}, {0x6e, 0xe6},
ashleymills 0:e979170e02e7 2047 {0x6b, 0xa8}, {0x6a, 0x6a}, {0x68, 0x2c}, {0x69, 0xee},
ashleymills 0:e979170e02e7 2048 {0x62, 0xb0}, {0x63, 0x72}, {0x61, 0x34}, {0x60, 0xf6},
ashleymills 0:e979170e02e7 2049 {0x65, 0xb8}, {0x64, 0x7a}, {0x66, 0x3c}, {0x67, 0xfe},
ashleymills 0:e979170e02e7 2050 {0x48, 0xc0}, {0x49, 0x02}, {0x4b, 0x44}, {0x4a, 0x86},
ashleymills 0:e979170e02e7 2051 {0x4f, 0xc8}, {0x4e, 0x0a}, {0x4c, 0x4c}, {0x4d, 0x8e},
ashleymills 0:e979170e02e7 2052 {0x46, 0xd0}, {0x47, 0x12}, {0x45, 0x54}, {0x44, 0x96},
ashleymills 0:e979170e02e7 2053 {0x41, 0xd8}, {0x40, 0x1a}, {0x42, 0x5c}, {0x43, 0x9e},
ashleymills 0:e979170e02e7 2054 {0x54, 0xe0}, {0x55, 0x22}, {0x57, 0x64}, {0x56, 0xa6},
ashleymills 0:e979170e02e7 2055 {0x53, 0xe8}, {0x52, 0x2a}, {0x50, 0x6c}, {0x51, 0xae},
ashleymills 0:e979170e02e7 2056 {0x5a, 0xf0}, {0x5b, 0x32}, {0x59, 0x74}, {0x58, 0xb6},
ashleymills 0:e979170e02e7 2057 {0x5d, 0xf8}, {0x5c, 0x3a}, {0x5e, 0x7c}, {0x5f, 0xbe},
ashleymills 0:e979170e02e7 2058 {0xe1, 0x00}, {0xe0, 0xc2}, {0xe2, 0x84}, {0xe3, 0x46},
ashleymills 0:e979170e02e7 2059 {0xe6, 0x08}, {0xe7, 0xca}, {0xe5, 0x8c}, {0xe4, 0x4e},
ashleymills 0:e979170e02e7 2060 {0xef, 0x10}, {0xee, 0xd2}, {0xec, 0x94}, {0xed, 0x56},
ashleymills 0:e979170e02e7 2061 {0xe8, 0x18}, {0xe9, 0xda}, {0xeb, 0x9c}, {0xea, 0x5e},
ashleymills 0:e979170e02e7 2062 {0xfd, 0x20}, {0xfc, 0xe2}, {0xfe, 0xa4}, {0xff, 0x66},
ashleymills 0:e979170e02e7 2063 {0xfa, 0x28}, {0xfb, 0xea}, {0xf9, 0xac}, {0xf8, 0x6e},
ashleymills 0:e979170e02e7 2064 {0xf3, 0x30}, {0xf2, 0xf2}, {0xf0, 0xb4}, {0xf1, 0x76},
ashleymills 0:e979170e02e7 2065 {0xf4, 0x38}, {0xf5, 0xfa}, {0xf7, 0xbc}, {0xf6, 0x7e},
ashleymills 0:e979170e02e7 2066 {0xd9, 0x40}, {0xd8, 0x82}, {0xda, 0xc4}, {0xdb, 0x06},
ashleymills 0:e979170e02e7 2067 {0xde, 0x48}, {0xdf, 0x8a}, {0xdd, 0xcc}, {0xdc, 0x0e},
ashleymills 0:e979170e02e7 2068 {0xd7, 0x50}, {0xd6, 0x92}, {0xd4, 0xd4}, {0xd5, 0x16},
ashleymills 0:e979170e02e7 2069 {0xd0, 0x58}, {0xd1, 0x9a}, {0xd3, 0xdc}, {0xd2, 0x1e},
ashleymills 0:e979170e02e7 2070 {0xc5, 0x60}, {0xc4, 0xa2}, {0xc6, 0xe4}, {0xc7, 0x26},
ashleymills 0:e979170e02e7 2071 {0xc2, 0x68}, {0xc3, 0xaa}, {0xc1, 0xec}, {0xc0, 0x2e},
ashleymills 0:e979170e02e7 2072 {0xcb, 0x70}, {0xca, 0xb2}, {0xc8, 0xf4}, {0xc9, 0x36},
ashleymills 0:e979170e02e7 2073 {0xcc, 0x78}, {0xcd, 0xba}, {0xcf, 0xfc}, {0xce, 0x3e},
ashleymills 0:e979170e02e7 2074 {0x91, 0x80}, {0x90, 0x42}, {0x92, 0x04}, {0x93, 0xc6},
ashleymills 0:e979170e02e7 2075 {0x96, 0x88}, {0x97, 0x4a}, {0x95, 0x0c}, {0x94, 0xce},
ashleymills 0:e979170e02e7 2076 {0x9f, 0x90}, {0x9e, 0x52}, {0x9c, 0x14}, {0x9d, 0xd6},
ashleymills 0:e979170e02e7 2077 {0x98, 0x98}, {0x99, 0x5a}, {0x9b, 0x1c}, {0x9a, 0xde},
ashleymills 0:e979170e02e7 2078 {0x8d, 0xa0}, {0x8c, 0x62}, {0x8e, 0x24}, {0x8f, 0xe6},
ashleymills 0:e979170e02e7 2079 {0x8a, 0xa8}, {0x8b, 0x6a}, {0x89, 0x2c}, {0x88, 0xee},
ashleymills 0:e979170e02e7 2080 {0x83, 0xb0}, {0x82, 0x72}, {0x80, 0x34}, {0x81, 0xf6},
ashleymills 0:e979170e02e7 2081 {0x84, 0xb8}, {0x85, 0x7a}, {0x87, 0x3c}, {0x86, 0xfe},
ashleymills 0:e979170e02e7 2082 {0xa9, 0xc0}, {0xa8, 0x02}, {0xaa, 0x44}, {0xab, 0x86},
ashleymills 0:e979170e02e7 2083 {0xae, 0xc8}, {0xaf, 0x0a}, {0xad, 0x4c}, {0xac, 0x8e},
ashleymills 0:e979170e02e7 2084 {0xa7, 0xd0}, {0xa6, 0x12}, {0xa4, 0x54}, {0xa5, 0x96},
ashleymills 0:e979170e02e7 2085 {0xa0, 0xd8}, {0xa1, 0x1a}, {0xa3, 0x5c}, {0xa2, 0x9e},
ashleymills 0:e979170e02e7 2086 {0xb5, 0xe0}, {0xb4, 0x22}, {0xb6, 0x64}, {0xb7, 0xa6},
ashleymills 0:e979170e02e7 2087 {0xb2, 0xe8}, {0xb3, 0x2a}, {0xb1, 0x6c}, {0xb0, 0xae},
ashleymills 0:e979170e02e7 2088 {0xbb, 0xf0}, {0xba, 0x32}, {0xb8, 0x74}, {0xb9, 0xb6},
ashleymills 0:e979170e02e7 2089 {0xbc, 0xf8}, {0xbd, 0x3a}, {0xbf, 0x7c}, {0xbe, 0xbe} };
ashleymills 0:e979170e02e7 2090
ashleymills 0:e979170e02e7 2091
ashleymills 0:e979170e02e7 2092 static void GMULT(byte *x, byte m[256][AES_BLOCK_SIZE])
ashleymills 0:e979170e02e7 2093 {
ashleymills 0:e979170e02e7 2094 int i, j;
ashleymills 0:e979170e02e7 2095 byte Z[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2096 byte a;
ashleymills 0:e979170e02e7 2097
ashleymills 0:e979170e02e7 2098 XMEMSET(Z, 0, sizeof(Z));
ashleymills 0:e979170e02e7 2099
ashleymills 0:e979170e02e7 2100 for (i = 15; i > 0; i--) {
ashleymills 0:e979170e02e7 2101 xorbuf(Z, m[x[i]], AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2102 a = Z[15];
ashleymills 0:e979170e02e7 2103
ashleymills 0:e979170e02e7 2104 for (j = 15; j > 0; j--) {
ashleymills 0:e979170e02e7 2105 Z[j] = Z[j-1];
ashleymills 0:e979170e02e7 2106 }
ashleymills 0:e979170e02e7 2107
ashleymills 0:e979170e02e7 2108 Z[0] = R[a][0];
ashleymills 0:e979170e02e7 2109 Z[1] ^= R[a][1];
ashleymills 0:e979170e02e7 2110 }
ashleymills 0:e979170e02e7 2111 xorbuf(Z, m[x[0]], AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2112
ashleymills 0:e979170e02e7 2113 XMEMCPY(x, Z, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2114 }
ashleymills 0:e979170e02e7 2115
ashleymills 0:e979170e02e7 2116
ashleymills 0:e979170e02e7 2117 static void GHASH(Aes* aes, const byte* a, word32 aSz,
ashleymills 0:e979170e02e7 2118 const byte* c, word32 cSz, byte* s, word32 sSz)
ashleymills 0:e979170e02e7 2119 {
ashleymills 0:e979170e02e7 2120 byte x[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2121 byte scratch[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2122 word32 blocks, partial;
ashleymills 0:e979170e02e7 2123
ashleymills 0:e979170e02e7 2124 XMEMSET(x, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2125
ashleymills 0:e979170e02e7 2126 /* Hash in A, the Additional Authentication Data */
ashleymills 0:e979170e02e7 2127 if (aSz != 0 && a != NULL) {
ashleymills 0:e979170e02e7 2128 blocks = aSz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2129 partial = aSz % AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2130 while (blocks--) {
ashleymills 0:e979170e02e7 2131 xorbuf(x, a, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2132 GMULT(x, aes->M0);
ashleymills 0:e979170e02e7 2133 a += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2134 }
ashleymills 0:e979170e02e7 2135 if (partial != 0) {
ashleymills 0:e979170e02e7 2136 XMEMSET(scratch, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2137 XMEMCPY(scratch, a, partial);
ashleymills 0:e979170e02e7 2138 xorbuf(x, scratch, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2139 GMULT(x, aes->M0);
ashleymills 0:e979170e02e7 2140 }
ashleymills 0:e979170e02e7 2141 }
ashleymills 0:e979170e02e7 2142
ashleymills 0:e979170e02e7 2143 /* Hash in C, the Ciphertext */
ashleymills 0:e979170e02e7 2144 if (cSz != 0 && c != NULL) {
ashleymills 0:e979170e02e7 2145 blocks = cSz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2146 partial = cSz % AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2147 while (blocks--) {
ashleymills 0:e979170e02e7 2148 xorbuf(x, c, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2149 GMULT(x, aes->M0);
ashleymills 0:e979170e02e7 2150 c += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2151 }
ashleymills 0:e979170e02e7 2152 if (partial != 0) {
ashleymills 0:e979170e02e7 2153 XMEMSET(scratch, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2154 XMEMCPY(scratch, c, partial);
ashleymills 0:e979170e02e7 2155 xorbuf(x, scratch, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2156 GMULT(x, aes->M0);
ashleymills 0:e979170e02e7 2157 }
ashleymills 0:e979170e02e7 2158 }
ashleymills 0:e979170e02e7 2159
ashleymills 0:e979170e02e7 2160 /* Hash in the lengths of A and C in bits */
ashleymills 0:e979170e02e7 2161 FlattenSzInBits(&scratch[0], aSz);
ashleymills 0:e979170e02e7 2162 FlattenSzInBits(&scratch[8], cSz);
ashleymills 0:e979170e02e7 2163 xorbuf(x, scratch, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2164 GMULT(x, aes->M0);
ashleymills 0:e979170e02e7 2165
ashleymills 0:e979170e02e7 2166 /* Copy the result into s. */
ashleymills 0:e979170e02e7 2167 XMEMCPY(s, x, sSz);
ashleymills 0:e979170e02e7 2168 }
ashleymills 0:e979170e02e7 2169
ashleymills 0:e979170e02e7 2170 /* end GCM_TABLE */
ashleymills 0:e979170e02e7 2171 #elif defined(WORD64_AVAILABLE) && !defined(GCM_WORD32)
ashleymills 0:e979170e02e7 2172
ashleymills 0:e979170e02e7 2173 static void GMULT(word64* X, word64* Y)
ashleymills 0:e979170e02e7 2174 {
ashleymills 0:e979170e02e7 2175 word64 Z[2] = {0,0};
ashleymills 0:e979170e02e7 2176 word64 V[2] = {X[0], X[1]};
ashleymills 0:e979170e02e7 2177 int i, j;
ashleymills 0:e979170e02e7 2178
ashleymills 0:e979170e02e7 2179 for (i = 0; i < 2; i++)
ashleymills 0:e979170e02e7 2180 {
ashleymills 0:e979170e02e7 2181 word64 y = Y[i];
ashleymills 0:e979170e02e7 2182 for (j = 0; j < 64; j++)
ashleymills 0:e979170e02e7 2183 {
ashleymills 0:e979170e02e7 2184 if (y & 0x8000000000000000) {
ashleymills 0:e979170e02e7 2185 Z[0] ^= V[0];
ashleymills 0:e979170e02e7 2186 Z[1] ^= V[1];
ashleymills 0:e979170e02e7 2187 }
ashleymills 0:e979170e02e7 2188
ashleymills 0:e979170e02e7 2189 if (V[1] & 0x0000000000000001) {
ashleymills 0:e979170e02e7 2190 V[1] >>= 1;
ashleymills 0:e979170e02e7 2191 V[1] |= ((V[0] & 0x0000000000000001) ? 0x8000000000000000 : 0);
ashleymills 0:e979170e02e7 2192 V[0] >>= 1;
ashleymills 0:e979170e02e7 2193 V[0] ^= 0xE100000000000000;
ashleymills 0:e979170e02e7 2194 }
ashleymills 0:e979170e02e7 2195 else {
ashleymills 0:e979170e02e7 2196 V[1] >>= 1;
ashleymills 0:e979170e02e7 2197 V[1] |= ((V[0] & 0x0000000000000001) ? 0x8000000000000000 : 0);
ashleymills 0:e979170e02e7 2198 V[0] >>= 1;
ashleymills 0:e979170e02e7 2199 }
ashleymills 0:e979170e02e7 2200 y <<= 1;
ashleymills 0:e979170e02e7 2201 }
ashleymills 0:e979170e02e7 2202 }
ashleymills 0:e979170e02e7 2203 X[0] = Z[0];
ashleymills 0:e979170e02e7 2204 X[1] = Z[1];
ashleymills 0:e979170e02e7 2205 }
ashleymills 0:e979170e02e7 2206
ashleymills 0:e979170e02e7 2207
ashleymills 0:e979170e02e7 2208 static void GHASH(Aes* aes, const byte* a, word32 aSz,
ashleymills 0:e979170e02e7 2209 const byte* c, word32 cSz, byte* s, word32 sSz)
ashleymills 0:e979170e02e7 2210 {
ashleymills 0:e979170e02e7 2211 word64 x[2] = {0,0};
ashleymills 0:e979170e02e7 2212 word32 blocks, partial;
ashleymills 0:e979170e02e7 2213 word64 bigH[2];
ashleymills 0:e979170e02e7 2214
ashleymills 0:e979170e02e7 2215 XMEMCPY(bigH, aes->H, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2216 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2217 ByteReverseWords64(bigH, bigH, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2218 #endif
ashleymills 0:e979170e02e7 2219
ashleymills 0:e979170e02e7 2220 /* Hash in A, the Additional Authentication Data */
ashleymills 0:e979170e02e7 2221 if (aSz != 0 && a != NULL) {
ashleymills 0:e979170e02e7 2222 word64 bigA[2];
ashleymills 0:e979170e02e7 2223 blocks = aSz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2224 partial = aSz % AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2225 while (blocks--) {
ashleymills 0:e979170e02e7 2226 XMEMCPY(bigA, a, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2227 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2228 ByteReverseWords64(bigA, bigA, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2229 #endif
ashleymills 0:e979170e02e7 2230 x[0] ^= bigA[0];
ashleymills 0:e979170e02e7 2231 x[1] ^= bigA[1];
ashleymills 0:e979170e02e7 2232 GMULT(x, bigH);
ashleymills 0:e979170e02e7 2233 a += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2234 }
ashleymills 0:e979170e02e7 2235 if (partial != 0) {
ashleymills 0:e979170e02e7 2236 XMEMSET(bigA, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2237 XMEMCPY(bigA, a, partial);
ashleymills 0:e979170e02e7 2238 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2239 ByteReverseWords64(bigA, bigA, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2240 #endif
ashleymills 0:e979170e02e7 2241 x[0] ^= bigA[0];
ashleymills 0:e979170e02e7 2242 x[1] ^= bigA[1];
ashleymills 0:e979170e02e7 2243 GMULT(x, bigH);
ashleymills 0:e979170e02e7 2244 }
ashleymills 0:e979170e02e7 2245 }
ashleymills 0:e979170e02e7 2246
ashleymills 0:e979170e02e7 2247 /* Hash in C, the Ciphertext */
ashleymills 0:e979170e02e7 2248 if (cSz != 0 && c != NULL) {
ashleymills 0:e979170e02e7 2249 word64 bigC[2];
ashleymills 0:e979170e02e7 2250 blocks = cSz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2251 partial = cSz % AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2252 while (blocks--) {
ashleymills 0:e979170e02e7 2253 XMEMCPY(bigC, c, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2254 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2255 ByteReverseWords64(bigC, bigC, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2256 #endif
ashleymills 0:e979170e02e7 2257 x[0] ^= bigC[0];
ashleymills 0:e979170e02e7 2258 x[1] ^= bigC[1];
ashleymills 0:e979170e02e7 2259 GMULT(x, bigH);
ashleymills 0:e979170e02e7 2260 c += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2261 }
ashleymills 0:e979170e02e7 2262 if (partial != 0) {
ashleymills 0:e979170e02e7 2263 XMEMSET(bigC, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2264 XMEMCPY(bigC, c, partial);
ashleymills 0:e979170e02e7 2265 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2266 ByteReverseWords64(bigC, bigC, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2267 #endif
ashleymills 0:e979170e02e7 2268 x[0] ^= bigC[0];
ashleymills 0:e979170e02e7 2269 x[1] ^= bigC[1];
ashleymills 0:e979170e02e7 2270 GMULT(x, bigH);
ashleymills 0:e979170e02e7 2271 }
ashleymills 0:e979170e02e7 2272 }
ashleymills 0:e979170e02e7 2273
ashleymills 0:e979170e02e7 2274 /* Hash in the lengths in bits of A and C */
ashleymills 0:e979170e02e7 2275 {
ashleymills 0:e979170e02e7 2276 word64 len[2] = {aSz, cSz};
ashleymills 0:e979170e02e7 2277
ashleymills 0:e979170e02e7 2278 /* Lengths are in bytes. Convert to bits. */
ashleymills 0:e979170e02e7 2279 len[0] *= 8;
ashleymills 0:e979170e02e7 2280 len[1] *= 8;
ashleymills 0:e979170e02e7 2281
ashleymills 0:e979170e02e7 2282 x[0] ^= len[0];
ashleymills 0:e979170e02e7 2283 x[1] ^= len[1];
ashleymills 0:e979170e02e7 2284 GMULT(x, bigH);
ashleymills 0:e979170e02e7 2285 }
ashleymills 0:e979170e02e7 2286 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2287 ByteReverseWords64(x, x, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2288 #endif
ashleymills 0:e979170e02e7 2289 XMEMCPY(s, x, sSz);
ashleymills 0:e979170e02e7 2290 }
ashleymills 0:e979170e02e7 2291
ashleymills 0:e979170e02e7 2292 /* end defined(WORD64_AVAILABLE) && !defined(GCM_WORD32) */
ashleymills 0:e979170e02e7 2293 #else /* GCM_WORD32 */
ashleymills 0:e979170e02e7 2294
ashleymills 0:e979170e02e7 2295 static void GMULT(word32* X, word32* Y)
ashleymills 0:e979170e02e7 2296 {
ashleymills 0:e979170e02e7 2297 word32 Z[4] = {0,0,0,0};
ashleymills 0:e979170e02e7 2298 word32 V[4] = {X[0], X[1], X[2], X[3]};
ashleymills 0:e979170e02e7 2299 int i, j;
ashleymills 0:e979170e02e7 2300
ashleymills 0:e979170e02e7 2301 for (i = 0; i < 4; i++)
ashleymills 0:e979170e02e7 2302 {
ashleymills 0:e979170e02e7 2303 word32 y = Y[i];
ashleymills 0:e979170e02e7 2304 for (j = 0; j < 32; j++)
ashleymills 0:e979170e02e7 2305 {
ashleymills 0:e979170e02e7 2306 if (y & 0x80000000) {
ashleymills 0:e979170e02e7 2307 Z[0] ^= V[0];
ashleymills 0:e979170e02e7 2308 Z[1] ^= V[1];
ashleymills 0:e979170e02e7 2309 Z[2] ^= V[2];
ashleymills 0:e979170e02e7 2310 Z[3] ^= V[3];
ashleymills 0:e979170e02e7 2311 }
ashleymills 0:e979170e02e7 2312
ashleymills 0:e979170e02e7 2313 if (V[3] & 0x00000001) {
ashleymills 0:e979170e02e7 2314 V[3] >>= 1;
ashleymills 0:e979170e02e7 2315 V[3] |= ((V[2] & 0x00000001) ? 0x80000000 : 0);
ashleymills 0:e979170e02e7 2316 V[2] >>= 1;
ashleymills 0:e979170e02e7 2317 V[2] |= ((V[1] & 0x00000001) ? 0x80000000 : 0);
ashleymills 0:e979170e02e7 2318 V[1] >>= 1;
ashleymills 0:e979170e02e7 2319 V[1] |= ((V[0] & 0x00000001) ? 0x80000000 : 0);
ashleymills 0:e979170e02e7 2320 V[0] >>= 1;
ashleymills 0:e979170e02e7 2321 V[0] ^= 0xE1000000;
ashleymills 0:e979170e02e7 2322 } else {
ashleymills 0:e979170e02e7 2323 V[3] >>= 1;
ashleymills 0:e979170e02e7 2324 V[3] |= ((V[2] & 0x00000001) ? 0x80000000 : 0);
ashleymills 0:e979170e02e7 2325 V[2] >>= 1;
ashleymills 0:e979170e02e7 2326 V[2] |= ((V[1] & 0x00000001) ? 0x80000000 : 0);
ashleymills 0:e979170e02e7 2327 V[1] >>= 1;
ashleymills 0:e979170e02e7 2328 V[1] |= ((V[0] & 0x00000001) ? 0x80000000 : 0);
ashleymills 0:e979170e02e7 2329 V[0] >>= 1;
ashleymills 0:e979170e02e7 2330 }
ashleymills 0:e979170e02e7 2331 y <<= 1;
ashleymills 0:e979170e02e7 2332 }
ashleymills 0:e979170e02e7 2333 }
ashleymills 0:e979170e02e7 2334 X[0] = Z[0];
ashleymills 0:e979170e02e7 2335 X[1] = Z[1];
ashleymills 0:e979170e02e7 2336 X[2] = Z[2];
ashleymills 0:e979170e02e7 2337 X[3] = Z[3];
ashleymills 0:e979170e02e7 2338 }
ashleymills 0:e979170e02e7 2339
ashleymills 0:e979170e02e7 2340
ashleymills 0:e979170e02e7 2341 static void GHASH(Aes* aes, const byte* a, word32 aSz,
ashleymills 0:e979170e02e7 2342 const byte* c, word32 cSz, byte* s, word32 sSz)
ashleymills 0:e979170e02e7 2343 {
ashleymills 0:e979170e02e7 2344 word32 x[4] = {0,0,0,0};
ashleymills 0:e979170e02e7 2345 word32 blocks, partial;
ashleymills 0:e979170e02e7 2346 word32 bigH[4];
ashleymills 0:e979170e02e7 2347
ashleymills 0:e979170e02e7 2348 XMEMCPY(bigH, aes->H, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2349 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2350 ByteReverseWords(bigH, bigH, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2351 #endif
ashleymills 0:e979170e02e7 2352
ashleymills 0:e979170e02e7 2353 /* Hash in A, the Additional Authentication Data */
ashleymills 0:e979170e02e7 2354 if (aSz != 0 && a != NULL) {
ashleymills 0:e979170e02e7 2355 word32 bigA[4];
ashleymills 0:e979170e02e7 2356 blocks = aSz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2357 partial = aSz % AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2358 while (blocks--) {
ashleymills 0:e979170e02e7 2359 XMEMCPY(bigA, a, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2360 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2361 ByteReverseWords(bigA, bigA, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2362 #endif
ashleymills 0:e979170e02e7 2363 x[0] ^= bigA[0];
ashleymills 0:e979170e02e7 2364 x[1] ^= bigA[1];
ashleymills 0:e979170e02e7 2365 x[2] ^= bigA[2];
ashleymills 0:e979170e02e7 2366 x[3] ^= bigA[3];
ashleymills 0:e979170e02e7 2367 GMULT(x, bigH);
ashleymills 0:e979170e02e7 2368 a += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2369 }
ashleymills 0:e979170e02e7 2370 if (partial != 0) {
ashleymills 0:e979170e02e7 2371 XMEMSET(bigA, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2372 XMEMCPY(bigA, a, partial);
ashleymills 0:e979170e02e7 2373 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2374 ByteReverseWords(bigA, bigA, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2375 #endif
ashleymills 0:e979170e02e7 2376 x[0] ^= bigA[0];
ashleymills 0:e979170e02e7 2377 x[1] ^= bigA[1];
ashleymills 0:e979170e02e7 2378 x[2] ^= bigA[2];
ashleymills 0:e979170e02e7 2379 x[3] ^= bigA[3];
ashleymills 0:e979170e02e7 2380 GMULT(x, bigH);
ashleymills 0:e979170e02e7 2381 }
ashleymills 0:e979170e02e7 2382 }
ashleymills 0:e979170e02e7 2383
ashleymills 0:e979170e02e7 2384 /* Hash in C, the Ciphertext */
ashleymills 0:e979170e02e7 2385 if (cSz != 0 && c != NULL) {
ashleymills 0:e979170e02e7 2386 word32 bigC[4];
ashleymills 0:e979170e02e7 2387 blocks = cSz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2388 partial = cSz % AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2389 while (blocks--) {
ashleymills 0:e979170e02e7 2390 XMEMCPY(bigC, c, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2391 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2392 ByteReverseWords(bigC, bigC, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2393 #endif
ashleymills 0:e979170e02e7 2394 x[0] ^= bigC[0];
ashleymills 0:e979170e02e7 2395 x[1] ^= bigC[1];
ashleymills 0:e979170e02e7 2396 x[2] ^= bigC[2];
ashleymills 0:e979170e02e7 2397 x[3] ^= bigC[3];
ashleymills 0:e979170e02e7 2398 GMULT(x, bigH);
ashleymills 0:e979170e02e7 2399 c += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2400 }
ashleymills 0:e979170e02e7 2401 if (partial != 0) {
ashleymills 0:e979170e02e7 2402 XMEMSET(bigC, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2403 XMEMCPY(bigC, c, partial);
ashleymills 0:e979170e02e7 2404 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2405 ByteReverseWords(bigC, bigC, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2406 #endif
ashleymills 0:e979170e02e7 2407 x[0] ^= bigC[0];
ashleymills 0:e979170e02e7 2408 x[1] ^= bigC[1];
ashleymills 0:e979170e02e7 2409 x[2] ^= bigC[2];
ashleymills 0:e979170e02e7 2410 x[3] ^= bigC[3];
ashleymills 0:e979170e02e7 2411 GMULT(x, bigH);
ashleymills 0:e979170e02e7 2412 }
ashleymills 0:e979170e02e7 2413 }
ashleymills 0:e979170e02e7 2414
ashleymills 0:e979170e02e7 2415 /* Hash in the lengths in bits of A and C */
ashleymills 0:e979170e02e7 2416 {
ashleymills 0:e979170e02e7 2417 word32 len[4];
ashleymills 0:e979170e02e7 2418
ashleymills 0:e979170e02e7 2419 /* Lengths are in bytes. Convert to bits. */
ashleymills 0:e979170e02e7 2420 len[0] = (aSz >> (8*sizeof(aSz) - 3));
ashleymills 0:e979170e02e7 2421 len[1] = aSz << 3;
ashleymills 0:e979170e02e7 2422 len[2] = (cSz >> (8*sizeof(cSz) - 3));
ashleymills 0:e979170e02e7 2423 len[3] = cSz << 3;
ashleymills 0:e979170e02e7 2424
ashleymills 0:e979170e02e7 2425 x[0] ^= len[0];
ashleymills 0:e979170e02e7 2426 x[1] ^= len[1];
ashleymills 0:e979170e02e7 2427 x[2] ^= len[2];
ashleymills 0:e979170e02e7 2428 x[3] ^= len[3];
ashleymills 0:e979170e02e7 2429 GMULT(x, bigH);
ashleymills 0:e979170e02e7 2430 }
ashleymills 0:e979170e02e7 2431 #ifdef LITTLE_ENDIAN_ORDER
ashleymills 0:e979170e02e7 2432 ByteReverseWords(x, x, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2433 #endif
ashleymills 0:e979170e02e7 2434 XMEMCPY(s, x, sSz);
ashleymills 0:e979170e02e7 2435 }
ashleymills 0:e979170e02e7 2436
ashleymills 0:e979170e02e7 2437 #endif /* end GCM_WORD32 */
ashleymills 0:e979170e02e7 2438
ashleymills 0:e979170e02e7 2439
ashleymills 0:e979170e02e7 2440 void AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
ashleymills 0:e979170e02e7 2441 const byte* iv, word32 ivSz,
ashleymills 0:e979170e02e7 2442 byte* authTag, word32 authTagSz,
ashleymills 0:e979170e02e7 2443 const byte* authIn, word32 authInSz)
ashleymills 0:e979170e02e7 2444 {
ashleymills 0:e979170e02e7 2445 word32 blocks = sz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2446 word32 partial = sz % AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2447 const byte* p = in;
ashleymills 0:e979170e02e7 2448 byte* c = out;
ashleymills 0:e979170e02e7 2449 byte ctr[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2450 byte scratch[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2451
ashleymills 0:e979170e02e7 2452 CYASSL_ENTER("AesGcmEncrypt");
ashleymills 0:e979170e02e7 2453
ashleymills 0:e979170e02e7 2454 XMEMSET(ctr, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2455 XMEMCPY(ctr, iv, ivSz);
ashleymills 0:e979170e02e7 2456 InitGcmCounter(ctr);
ashleymills 0:e979170e02e7 2457
ashleymills 0:e979170e02e7 2458 while (blocks--) {
ashleymills 0:e979170e02e7 2459 IncrementGcmCounter(ctr);
ashleymills 0:e979170e02e7 2460 AesEncrypt(aes, ctr, scratch);
ashleymills 0:e979170e02e7 2461 xorbuf(scratch, p, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2462 XMEMCPY(c, scratch, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2463
ashleymills 0:e979170e02e7 2464 p += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2465 c += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2466 }
ashleymills 0:e979170e02e7 2467 if (partial != 0) {
ashleymills 0:e979170e02e7 2468 IncrementGcmCounter(ctr);
ashleymills 0:e979170e02e7 2469 AesEncrypt(aes, ctr, scratch);
ashleymills 0:e979170e02e7 2470 xorbuf(scratch, p, partial);
ashleymills 0:e979170e02e7 2471 XMEMCPY(c, scratch, partial);
ashleymills 0:e979170e02e7 2472 }
ashleymills 0:e979170e02e7 2473 GHASH(aes, authIn, authInSz, out, sz, authTag, authTagSz);
ashleymills 0:e979170e02e7 2474 InitGcmCounter(ctr);
ashleymills 0:e979170e02e7 2475 AesEncrypt(aes, ctr, scratch);
ashleymills 0:e979170e02e7 2476 xorbuf(authTag, scratch, authTagSz);
ashleymills 0:e979170e02e7 2477 }
ashleymills 0:e979170e02e7 2478
ashleymills 0:e979170e02e7 2479
ashleymills 0:e979170e02e7 2480 int AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
ashleymills 0:e979170e02e7 2481 const byte* iv, word32 ivSz,
ashleymills 0:e979170e02e7 2482 const byte* authTag, word32 authTagSz,
ashleymills 0:e979170e02e7 2483 const byte* authIn, word32 authInSz)
ashleymills 0:e979170e02e7 2484 {
ashleymills 0:e979170e02e7 2485 word32 blocks = sz / AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2486 word32 partial = sz % AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2487 const byte* c = in;
ashleymills 0:e979170e02e7 2488 byte* p = out;
ashleymills 0:e979170e02e7 2489 byte ctr[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2490 byte scratch[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2491
ashleymills 0:e979170e02e7 2492 CYASSL_ENTER("AesGcmDecrypt");
ashleymills 0:e979170e02e7 2493
ashleymills 0:e979170e02e7 2494 XMEMSET(ctr, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2495 XMEMCPY(ctr, iv, ivSz);
ashleymills 0:e979170e02e7 2496 InitGcmCounter(ctr);
ashleymills 0:e979170e02e7 2497
ashleymills 0:e979170e02e7 2498 /* Calculate the authTag again using the received auth data and the
ashleymills 0:e979170e02e7 2499 * cipher text. */
ashleymills 0:e979170e02e7 2500 {
ashleymills 0:e979170e02e7 2501 byte Tprime[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2502 byte EKY0[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2503
ashleymills 0:e979170e02e7 2504 GHASH(aes, authIn, authInSz, in, sz, Tprime, sizeof(Tprime));
ashleymills 0:e979170e02e7 2505 AesEncrypt(aes, ctr, EKY0);
ashleymills 0:e979170e02e7 2506 xorbuf(Tprime, EKY0, sizeof(Tprime));
ashleymills 0:e979170e02e7 2507 if (XMEMCMP(authTag, Tprime, authTagSz) != 0) {
ashleymills 0:e979170e02e7 2508 return AES_GCM_AUTH_E;
ashleymills 0:e979170e02e7 2509 }
ashleymills 0:e979170e02e7 2510 }
ashleymills 0:e979170e02e7 2511
ashleymills 0:e979170e02e7 2512 while (blocks--) {
ashleymills 0:e979170e02e7 2513 IncrementGcmCounter(ctr);
ashleymills 0:e979170e02e7 2514 AesEncrypt(aes, ctr, scratch);
ashleymills 0:e979170e02e7 2515 xorbuf(scratch, c, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2516 XMEMCPY(p, scratch, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2517
ashleymills 0:e979170e02e7 2518 p += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2519 c += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2520 }
ashleymills 0:e979170e02e7 2521 if (partial != 0) {
ashleymills 0:e979170e02e7 2522 IncrementGcmCounter(ctr);
ashleymills 0:e979170e02e7 2523 AesEncrypt(aes, ctr, scratch);
ashleymills 0:e979170e02e7 2524 xorbuf(scratch, c, partial);
ashleymills 0:e979170e02e7 2525 XMEMCPY(p, scratch, partial);
ashleymills 0:e979170e02e7 2526 }
ashleymills 0:e979170e02e7 2527
ashleymills 0:e979170e02e7 2528 return 0;
ashleymills 0:e979170e02e7 2529 }
ashleymills 0:e979170e02e7 2530
ashleymills 0:e979170e02e7 2531 #endif /* HAVE_AESGCM */
ashleymills 0:e979170e02e7 2532
ashleymills 0:e979170e02e7 2533 #ifdef HAVE_AESCCM
ashleymills 0:e979170e02e7 2534
ashleymills 0:e979170e02e7 2535 void AesCcmSetKey(Aes* aes, const byte* key, word32 keySz)
ashleymills 0:e979170e02e7 2536 {
ashleymills 0:e979170e02e7 2537 byte nonce[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2538
ashleymills 0:e979170e02e7 2539 if (!((keySz == 16) || (keySz == 24) || (keySz == 32)))
ashleymills 0:e979170e02e7 2540 return;
ashleymills 0:e979170e02e7 2541
ashleymills 0:e979170e02e7 2542 XMEMSET(nonce, 0, sizeof(nonce));
ashleymills 0:e979170e02e7 2543 AesSetKeyLocal(aes, key, keySz, nonce, AES_ENCRYPTION);
ashleymills 0:e979170e02e7 2544 }
ashleymills 0:e979170e02e7 2545
ashleymills 0:e979170e02e7 2546
ashleymills 0:e979170e02e7 2547 static void roll_x(Aes* aes, const byte* in, word32 inSz, byte* out)
ashleymills 0:e979170e02e7 2548 {
ashleymills 0:e979170e02e7 2549 /* process the bulk of the data */
ashleymills 0:e979170e02e7 2550 while (inSz >= AES_BLOCK_SIZE) {
ashleymills 0:e979170e02e7 2551 xorbuf(out, in, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2552 in += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2553 inSz -= AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2554
ashleymills 0:e979170e02e7 2555 AesEncrypt(aes, out, out);
ashleymills 0:e979170e02e7 2556 }
ashleymills 0:e979170e02e7 2557
ashleymills 0:e979170e02e7 2558 /* process remainder of the data */
ashleymills 0:e979170e02e7 2559 if (inSz > 0) {
ashleymills 0:e979170e02e7 2560 xorbuf(out, in, inSz);
ashleymills 0:e979170e02e7 2561 AesEncrypt(aes, out, out);
ashleymills 0:e979170e02e7 2562 }
ashleymills 0:e979170e02e7 2563 }
ashleymills 0:e979170e02e7 2564
ashleymills 0:e979170e02e7 2565
ashleymills 0:e979170e02e7 2566 static void roll_auth(Aes* aes, const byte* in, word32 inSz, byte* out)
ashleymills 0:e979170e02e7 2567 {
ashleymills 0:e979170e02e7 2568 word32 authLenSz;
ashleymills 0:e979170e02e7 2569 word32 remainder;
ashleymills 0:e979170e02e7 2570
ashleymills 0:e979170e02e7 2571 /* encode the length in */
ashleymills 0:e979170e02e7 2572 if (inSz <= 0xFEFF) {
ashleymills 0:e979170e02e7 2573 authLenSz = 2;
ashleymills 0:e979170e02e7 2574 out[0] ^= ((inSz & 0xFF00) >> 8);
ashleymills 0:e979170e02e7 2575 out[1] ^= (inSz & 0x00FF);
ashleymills 0:e979170e02e7 2576 }
ashleymills 0:e979170e02e7 2577 else if (inSz <= 0xFFFFFFFF) {
ashleymills 0:e979170e02e7 2578 authLenSz = 6;
ashleymills 0:e979170e02e7 2579 out[0] ^= 0xFF; out[1] ^= 0xFE;
ashleymills 0:e979170e02e7 2580 out[2] ^= ((inSz & 0xFF000000) >> 24);
ashleymills 0:e979170e02e7 2581 out[3] ^= ((inSz & 0x00FF0000) >> 16);
ashleymills 0:e979170e02e7 2582 out[4] ^= ((inSz & 0x0000FF00) >> 8);
ashleymills 0:e979170e02e7 2583 out[5] ^= (inSz & 0x000000FF);
ashleymills 0:e979170e02e7 2584 }
ashleymills 0:e979170e02e7 2585 /* Note, the protocol handles auth data up to 2^64, but we are
ashleymills 0:e979170e02e7 2586 * using 32-bit sizes right now, so the bigger data isn't handled
ashleymills 0:e979170e02e7 2587 * else if (inSz <= 0xFFFFFFFFFFFFFFFF) {} */
ashleymills 0:e979170e02e7 2588 else
ashleymills 0:e979170e02e7 2589 return;
ashleymills 0:e979170e02e7 2590
ashleymills 0:e979170e02e7 2591 /* start fill out the rest of the first block */
ashleymills 0:e979170e02e7 2592 remainder = AES_BLOCK_SIZE - authLenSz;
ashleymills 0:e979170e02e7 2593 if (inSz >= remainder) {
ashleymills 0:e979170e02e7 2594 /* plenty of bulk data to fill the remainder of this block */
ashleymills 0:e979170e02e7 2595 xorbuf(out + authLenSz, in, remainder);
ashleymills 0:e979170e02e7 2596 inSz -= remainder;
ashleymills 0:e979170e02e7 2597 in += remainder;
ashleymills 0:e979170e02e7 2598 }
ashleymills 0:e979170e02e7 2599 else {
ashleymills 0:e979170e02e7 2600 /* not enough bulk data, copy what is available, and pad zero */
ashleymills 0:e979170e02e7 2601 xorbuf(out + authLenSz, in, inSz);
ashleymills 0:e979170e02e7 2602 inSz = 0;
ashleymills 0:e979170e02e7 2603 }
ashleymills 0:e979170e02e7 2604 AesEncrypt(aes, out, out);
ashleymills 0:e979170e02e7 2605
ashleymills 0:e979170e02e7 2606 if (inSz > 0)
ashleymills 0:e979170e02e7 2607 roll_x(aes, in, inSz, out);
ashleymills 0:e979170e02e7 2608 }
ashleymills 0:e979170e02e7 2609
ashleymills 0:e979170e02e7 2610
ashleymills 0:e979170e02e7 2611 static INLINE void AesCcmCtrInc(byte* B, word32 lenSz)
ashleymills 0:e979170e02e7 2612 {
ashleymills 0:e979170e02e7 2613 word32 i;
ashleymills 0:e979170e02e7 2614
ashleymills 0:e979170e02e7 2615 for (i = 0; i < lenSz; i++) {
ashleymills 0:e979170e02e7 2616 if (++B[AES_BLOCK_SIZE - 1 - i] != 0) return;
ashleymills 0:e979170e02e7 2617 }
ashleymills 0:e979170e02e7 2618 }
ashleymills 0:e979170e02e7 2619
ashleymills 0:e979170e02e7 2620
ashleymills 0:e979170e02e7 2621 void AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
ashleymills 0:e979170e02e7 2622 const byte* nonce, word32 nonceSz,
ashleymills 0:e979170e02e7 2623 byte* authTag, word32 authTagSz,
ashleymills 0:e979170e02e7 2624 const byte* authIn, word32 authInSz)
ashleymills 0:e979170e02e7 2625 {
ashleymills 0:e979170e02e7 2626 byte A[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2627 byte B[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2628 word32 i, lenSz;
ashleymills 0:e979170e02e7 2629
ashleymills 0:e979170e02e7 2630 XMEMCPY(B+1, nonce, nonceSz);
ashleymills 0:e979170e02e7 2631 lenSz = AES_BLOCK_SIZE - 1 - nonceSz;
ashleymills 0:e979170e02e7 2632 B[0] = (authInSz > 0 ? 64 : 0)
ashleymills 0:e979170e02e7 2633 + (8 * ((authTagSz - 2) / 2))
ashleymills 0:e979170e02e7 2634 + (lenSz - 1);
ashleymills 0:e979170e02e7 2635 for (i = 0; i < lenSz; i++)
ashleymills 0:e979170e02e7 2636 B[AES_BLOCK_SIZE - 1 - i] = (inSz >> (8 * i)) & 0xFF;
ashleymills 0:e979170e02e7 2637
ashleymills 0:e979170e02e7 2638 AesEncrypt(aes, B, A);
ashleymills 0:e979170e02e7 2639 if (authInSz > 0)
ashleymills 0:e979170e02e7 2640 roll_auth(aes, authIn, authInSz, A);
ashleymills 0:e979170e02e7 2641 if (inSz > 0)
ashleymills 0:e979170e02e7 2642 roll_x(aes, in, inSz, A);
ashleymills 0:e979170e02e7 2643 XMEMCPY(authTag, A, authTagSz);
ashleymills 0:e979170e02e7 2644
ashleymills 0:e979170e02e7 2645 B[0] = (lenSz - 1);
ashleymills 0:e979170e02e7 2646 for (i = 0; i < lenSz; i++)
ashleymills 0:e979170e02e7 2647 B[AES_BLOCK_SIZE - 1 - i] = 0;
ashleymills 0:e979170e02e7 2648 AesEncrypt(aes, B, A);
ashleymills 0:e979170e02e7 2649 xorbuf(authTag, A, authTagSz);
ashleymills 0:e979170e02e7 2650
ashleymills 0:e979170e02e7 2651 B[15] = 1;
ashleymills 0:e979170e02e7 2652 while (inSz >= AES_BLOCK_SIZE) {
ashleymills 0:e979170e02e7 2653 AesEncrypt(aes, B, A);
ashleymills 0:e979170e02e7 2654 xorbuf(A, in, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2655 XMEMCPY(out, A, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2656
ashleymills 0:e979170e02e7 2657 AesCcmCtrInc(B, lenSz);
ashleymills 0:e979170e02e7 2658 inSz -= AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2659 in += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2660 out += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2661 }
ashleymills 0:e979170e02e7 2662 if (inSz > 0) {
ashleymills 0:e979170e02e7 2663 AesEncrypt(aes, B, A);
ashleymills 0:e979170e02e7 2664 xorbuf(A, in, inSz);
ashleymills 0:e979170e02e7 2665 XMEMCPY(out, A, inSz);
ashleymills 0:e979170e02e7 2666 }
ashleymills 0:e979170e02e7 2667
ashleymills 0:e979170e02e7 2668 XMEMSET(A, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2669 XMEMSET(B, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2670 }
ashleymills 0:e979170e02e7 2671
ashleymills 0:e979170e02e7 2672
ashleymills 0:e979170e02e7 2673 int AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
ashleymills 0:e979170e02e7 2674 const byte* nonce, word32 nonceSz,
ashleymills 0:e979170e02e7 2675 const byte* authTag, word32 authTagSz,
ashleymills 0:e979170e02e7 2676 const byte* authIn, word32 authInSz)
ashleymills 0:e979170e02e7 2677 {
ashleymills 0:e979170e02e7 2678 byte A[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2679 byte B[AES_BLOCK_SIZE];
ashleymills 0:e979170e02e7 2680 byte* o;
ashleymills 0:e979170e02e7 2681 word32 i, lenSz, oSz, result = 0;
ashleymills 0:e979170e02e7 2682
ashleymills 0:e979170e02e7 2683 o = out;
ashleymills 0:e979170e02e7 2684 oSz = inSz;
ashleymills 0:e979170e02e7 2685 XMEMCPY(B+1, nonce, nonceSz);
ashleymills 0:e979170e02e7 2686 lenSz = AES_BLOCK_SIZE - 1 - nonceSz;
ashleymills 0:e979170e02e7 2687
ashleymills 0:e979170e02e7 2688 B[0] = (lenSz - 1);
ashleymills 0:e979170e02e7 2689 for (i = 0; i < lenSz; i++)
ashleymills 0:e979170e02e7 2690 B[AES_BLOCK_SIZE - 1 - i] = 0;
ashleymills 0:e979170e02e7 2691 B[15] = 1;
ashleymills 0:e979170e02e7 2692
ashleymills 0:e979170e02e7 2693 while (oSz >= AES_BLOCK_SIZE) {
ashleymills 0:e979170e02e7 2694 AesEncrypt(aes, B, A);
ashleymills 0:e979170e02e7 2695 xorbuf(A, in, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2696 XMEMCPY(o, A, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2697
ashleymills 0:e979170e02e7 2698 AesCcmCtrInc(B, lenSz);
ashleymills 0:e979170e02e7 2699 oSz -= AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2700 in += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2701 o += AES_BLOCK_SIZE;
ashleymills 0:e979170e02e7 2702 }
ashleymills 0:e979170e02e7 2703 if (inSz > 0) {
ashleymills 0:e979170e02e7 2704 AesEncrypt(aes, B, A);
ashleymills 0:e979170e02e7 2705 xorbuf(A, in, oSz);
ashleymills 0:e979170e02e7 2706 XMEMCPY(o, A, oSz);
ashleymills 0:e979170e02e7 2707 }
ashleymills 0:e979170e02e7 2708
ashleymills 0:e979170e02e7 2709 for (i = 0; i < lenSz; i++)
ashleymills 0:e979170e02e7 2710 B[AES_BLOCK_SIZE - 1 - i] = 0;
ashleymills 0:e979170e02e7 2711 AesEncrypt(aes, B, A);
ashleymills 0:e979170e02e7 2712
ashleymills 0:e979170e02e7 2713 o = out;
ashleymills 0:e979170e02e7 2714 oSz = inSz;
ashleymills 0:e979170e02e7 2715
ashleymills 0:e979170e02e7 2716 B[0] = (authInSz > 0 ? 64 : 0)
ashleymills 0:e979170e02e7 2717 + (8 * ((authTagSz - 2) / 2))
ashleymills 0:e979170e02e7 2718 + (lenSz - 1);
ashleymills 0:e979170e02e7 2719 for (i = 0; i < lenSz; i++)
ashleymills 0:e979170e02e7 2720 B[AES_BLOCK_SIZE - 1 - i] = (inSz >> (8 * i)) & 0xFF;
ashleymills 0:e979170e02e7 2721
ashleymills 0:e979170e02e7 2722 AesEncrypt(aes, B, A);
ashleymills 0:e979170e02e7 2723 if (authInSz > 0)
ashleymills 0:e979170e02e7 2724 roll_auth(aes, authIn, authInSz, A);
ashleymills 0:e979170e02e7 2725 if (inSz > 0)
ashleymills 0:e979170e02e7 2726 roll_x(aes, o, oSz, A);
ashleymills 0:e979170e02e7 2727
ashleymills 0:e979170e02e7 2728 B[0] = (lenSz - 1);
ashleymills 0:e979170e02e7 2729 for (i = 0; i < lenSz; i++)
ashleymills 0:e979170e02e7 2730 B[AES_BLOCK_SIZE - 1 - i] = 0;
ashleymills 0:e979170e02e7 2731 AesEncrypt(aes, B, B);
ashleymills 0:e979170e02e7 2732 xorbuf(A, B, authTagSz);
ashleymills 0:e979170e02e7 2733
ashleymills 0:e979170e02e7 2734 if (XMEMCMP(A, authTag, authTagSz) != 0) {
ashleymills 0:e979170e02e7 2735 /* If the authTag check fails, don't keep the decrypted data.
ashleymills 0:e979170e02e7 2736 * Unfortunately, you need the decrypted data to calculate the
ashleymills 0:e979170e02e7 2737 * check value. */
ashleymills 0:e979170e02e7 2738 XMEMSET(out, 0, inSz);
ashleymills 0:e979170e02e7 2739 result = AES_CCM_AUTH_E;
ashleymills 0:e979170e02e7 2740 }
ashleymills 0:e979170e02e7 2741
ashleymills 0:e979170e02e7 2742 XMEMSET(A, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2743 XMEMSET(B, 0, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2744 o = NULL;
ashleymills 0:e979170e02e7 2745
ashleymills 0:e979170e02e7 2746 return result;
ashleymills 0:e979170e02e7 2747 }
ashleymills 0:e979170e02e7 2748
ashleymills 0:e979170e02e7 2749 #endif
ashleymills 0:e979170e02e7 2750
ashleymills 0:e979170e02e7 2751 #endif /* STM32F2_CRYPTO */
ashleymills 0:e979170e02e7 2752
ashleymills 0:e979170e02e7 2753 int AesSetIV(Aes* aes, const byte* iv)
ashleymills 0:e979170e02e7 2754 {
ashleymills 0:e979170e02e7 2755 if (aes == NULL)
ashleymills 0:e979170e02e7 2756 return BAD_FUNC_ARG;
ashleymills 0:e979170e02e7 2757
ashleymills 0:e979170e02e7 2758 if (iv)
ashleymills 0:e979170e02e7 2759 XMEMCPY(aes->reg, iv, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2760
ashleymills 0:e979170e02e7 2761 return 0;
ashleymills 0:e979170e02e7 2762 }
ashleymills 0:e979170e02e7 2763
ashleymills 0:e979170e02e7 2764
ashleymills 0:e979170e02e7 2765 #ifdef HAVE_CAVIUM
ashleymills 0:e979170e02e7 2766
ashleymills 0:e979170e02e7 2767 #include <cyassl/ctaocrypt/logging.h>
ashleymills 0:e979170e02e7 2768 #include "cavium_common.h"
ashleymills 0:e979170e02e7 2769
ashleymills 0:e979170e02e7 2770 /* Initiliaze Aes for use with Nitrox device */
ashleymills 0:e979170e02e7 2771 int AesInitCavium(Aes* aes, int devId)
ashleymills 0:e979170e02e7 2772 {
ashleymills 0:e979170e02e7 2773 if (aes == NULL)
ashleymills 0:e979170e02e7 2774 return -1;
ashleymills 0:e979170e02e7 2775
ashleymills 0:e979170e02e7 2776 if (CspAllocContext(CONTEXT_SSL, &aes->contextHandle, devId) != 0)
ashleymills 0:e979170e02e7 2777 return -1;
ashleymills 0:e979170e02e7 2778
ashleymills 0:e979170e02e7 2779 aes->devId = devId;
ashleymills 0:e979170e02e7 2780 aes->magic = CYASSL_AES_CAVIUM_MAGIC;
ashleymills 0:e979170e02e7 2781
ashleymills 0:e979170e02e7 2782 return 0;
ashleymills 0:e979170e02e7 2783 }
ashleymills 0:e979170e02e7 2784
ashleymills 0:e979170e02e7 2785
ashleymills 0:e979170e02e7 2786 /* Free Aes from use with Nitrox device */
ashleymills 0:e979170e02e7 2787 void AesFreeCavium(Aes* aes)
ashleymills 0:e979170e02e7 2788 {
ashleymills 0:e979170e02e7 2789 if (aes == NULL)
ashleymills 0:e979170e02e7 2790 return;
ashleymills 0:e979170e02e7 2791
ashleymills 0:e979170e02e7 2792 if (aes->magic != CYASSL_AES_CAVIUM_MAGIC)
ashleymills 0:e979170e02e7 2793 return;
ashleymills 0:e979170e02e7 2794
ashleymills 0:e979170e02e7 2795 CspFreeContext(CONTEXT_SSL, aes->contextHandle, aes->devId);
ashleymills 0:e979170e02e7 2796 aes->magic = 0;
ashleymills 0:e979170e02e7 2797 }
ashleymills 0:e979170e02e7 2798
ashleymills 0:e979170e02e7 2799
ashleymills 0:e979170e02e7 2800 static int AesCaviumSetKey(Aes* aes, const byte* key, word32 length,
ashleymills 0:e979170e02e7 2801 const byte* iv)
ashleymills 0:e979170e02e7 2802 {
ashleymills 0:e979170e02e7 2803 if (aes == NULL)
ashleymills 0:e979170e02e7 2804 return -1;
ashleymills 0:e979170e02e7 2805
ashleymills 0:e979170e02e7 2806 XMEMCPY(aes->key, key, length); /* key still holds key, iv still in reg */
ashleymills 0:e979170e02e7 2807 if (length == 16)
ashleymills 0:e979170e02e7 2808 aes->type = AES_128;
ashleymills 0:e979170e02e7 2809 else if (length == 24)
ashleymills 0:e979170e02e7 2810 aes->type = AES_192;
ashleymills 0:e979170e02e7 2811 else if (length == 32)
ashleymills 0:e979170e02e7 2812 aes->type = AES_256;
ashleymills 0:e979170e02e7 2813
ashleymills 0:e979170e02e7 2814 return AesSetIV(aes, iv);
ashleymills 0:e979170e02e7 2815 }
ashleymills 0:e979170e02e7 2816
ashleymills 0:e979170e02e7 2817
ashleymills 0:e979170e02e7 2818 static void AesCaviumCbcEncrypt(Aes* aes, byte* out, const byte* in,
ashleymills 0:e979170e02e7 2819 word32 length)
ashleymills 0:e979170e02e7 2820 {
ashleymills 0:e979170e02e7 2821 word offset = 0;
ashleymills 0:e979170e02e7 2822 word32 requestId;
ashleymills 0:e979170e02e7 2823
ashleymills 0:e979170e02e7 2824 while (length > CYASSL_MAX_16BIT) {
ashleymills 0:e979170e02e7 2825 word16 slen = (word16)CYASSL_MAX_16BIT;
ashleymills 0:e979170e02e7 2826 if (CspEncryptAes(CAVIUM_BLOCKING, aes->contextHandle, CAVIUM_NO_UPDATE,
ashleymills 0:e979170e02e7 2827 aes->type, slen, (byte*)in + offset, out + offset,
ashleymills 0:e979170e02e7 2828 (byte*)aes->reg, (byte*)aes->key, &requestId,
ashleymills 0:e979170e02e7 2829 aes->devId) != 0) {
ashleymills 0:e979170e02e7 2830 CYASSL_MSG("Bad Cavium Aes Encrypt");
ashleymills 0:e979170e02e7 2831 }
ashleymills 0:e979170e02e7 2832 length -= CYASSL_MAX_16BIT;
ashleymills 0:e979170e02e7 2833 offset += CYASSL_MAX_16BIT;
ashleymills 0:e979170e02e7 2834 XMEMCPY(aes->reg, out + offset - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2835 }
ashleymills 0:e979170e02e7 2836 if (length) {
ashleymills 0:e979170e02e7 2837 word16 slen = (word16)length;
ashleymills 0:e979170e02e7 2838 if (CspEncryptAes(CAVIUM_BLOCKING, aes->contextHandle, CAVIUM_NO_UPDATE,
ashleymills 0:e979170e02e7 2839 aes->type, slen, (byte*)in + offset, out + offset,
ashleymills 0:e979170e02e7 2840 (byte*)aes->reg, (byte*)aes->key, &requestId,
ashleymills 0:e979170e02e7 2841 aes->devId) != 0) {
ashleymills 0:e979170e02e7 2842 CYASSL_MSG("Bad Cavium Aes Encrypt");
ashleymills 0:e979170e02e7 2843 }
ashleymills 0:e979170e02e7 2844 XMEMCPY(aes->reg, out + offset+length - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2845 }
ashleymills 0:e979170e02e7 2846 }
ashleymills 0:e979170e02e7 2847
ashleymills 0:e979170e02e7 2848 static void AesCaviumCbcDecrypt(Aes* aes, byte* out, const byte* in,
ashleymills 0:e979170e02e7 2849 word32 length)
ashleymills 0:e979170e02e7 2850 {
ashleymills 0:e979170e02e7 2851 word32 requestId;
ashleymills 0:e979170e02e7 2852 word offset = 0;
ashleymills 0:e979170e02e7 2853
ashleymills 0:e979170e02e7 2854 while (length > CYASSL_MAX_16BIT) {
ashleymills 0:e979170e02e7 2855 word16 slen = (word16)CYASSL_MAX_16BIT;
ashleymills 0:e979170e02e7 2856 XMEMCPY(aes->tmp, in + offset + slen - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2857 if (CspDecryptAes(CAVIUM_BLOCKING, aes->contextHandle, CAVIUM_NO_UPDATE,
ashleymills 0:e979170e02e7 2858 aes->type, slen, (byte*)in + offset, out + offset,
ashleymills 0:e979170e02e7 2859 (byte*)aes->reg, (byte*)aes->key, &requestId,
ashleymills 0:e979170e02e7 2860 aes->devId) != 0) {
ashleymills 0:e979170e02e7 2861 CYASSL_MSG("Bad Cavium Aes Decrypt");
ashleymills 0:e979170e02e7 2862 }
ashleymills 0:e979170e02e7 2863 length -= CYASSL_MAX_16BIT;
ashleymills 0:e979170e02e7 2864 offset += CYASSL_MAX_16BIT;
ashleymills 0:e979170e02e7 2865 XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2866 }
ashleymills 0:e979170e02e7 2867 if (length) {
ashleymills 0:e979170e02e7 2868 word16 slen = (word16)length;
ashleymills 0:e979170e02e7 2869 XMEMCPY(aes->tmp, in + offset + slen - AES_BLOCK_SIZE, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2870 if (CspDecryptAes(CAVIUM_BLOCKING, aes->contextHandle, CAVIUM_NO_UPDATE,
ashleymills 0:e979170e02e7 2871 aes->type, slen, (byte*)in + offset, out + offset,
ashleymills 0:e979170e02e7 2872 (byte*)aes->reg, (byte*)aes->key, &requestId,
ashleymills 0:e979170e02e7 2873 aes->devId) != 0) {
ashleymills 0:e979170e02e7 2874 CYASSL_MSG("Bad Cavium Aes Decrypt");
ashleymills 0:e979170e02e7 2875 }
ashleymills 0:e979170e02e7 2876 XMEMCPY(aes->reg, aes->tmp, AES_BLOCK_SIZE);
ashleymills 0:e979170e02e7 2877 }
ashleymills 0:e979170e02e7 2878 }
ashleymills 0:e979170e02e7 2879
ashleymills 0:e979170e02e7 2880 #endif /* HAVE_CAVIUM */
ashleymills 0:e979170e02e7 2881
ashleymills 0:e979170e02e7 2882 #endif /* NO_AES */
ashleymills 0:e979170e02e7 2883