A library for setting up Secure Socket Layer (SSL) connections and verifying remote hosts using certificates. Contains only the source files for mbed platform implementation of the library.

Dependents:   HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL

Committer:
Mike Fiore
Date:
Mon Mar 23 16:51:07 2015 -0500
Revision:
6:cf58d49e1a86
Parent:
0:b86d15c6ba29
fix whitespace in sha512.c

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vanger 0:b86d15c6ba29 1 /* rabbit.c
Vanger 0:b86d15c6ba29 2 *
Vanger 0:b86d15c6ba29 3 * Copyright (C) 2006-2014 wolfSSL Inc.
Vanger 0:b86d15c6ba29 4 *
Vanger 0:b86d15c6ba29 5 * This file is part of CyaSSL.
Vanger 0:b86d15c6ba29 6 *
Vanger 0:b86d15c6ba29 7 * CyaSSL is free software; you can redistribute it and/or modify
Vanger 0:b86d15c6ba29 8 * it under the terms of the GNU General Public License as published by
Vanger 0:b86d15c6ba29 9 * the Free Software Foundation; either version 2 of the License, or
Vanger 0:b86d15c6ba29 10 * (at your option) any later version.
Vanger 0:b86d15c6ba29 11 *
Vanger 0:b86d15c6ba29 12 * CyaSSL is distributed in the hope that it will be useful,
Vanger 0:b86d15c6ba29 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Vanger 0:b86d15c6ba29 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Vanger 0:b86d15c6ba29 15 * GNU General Public License for more details.
Vanger 0:b86d15c6ba29 16 *
Vanger 0:b86d15c6ba29 17 * You should have received a copy of the GNU General Public License
Vanger 0:b86d15c6ba29 18 * along with this program; if not, write to the Free Software
Vanger 0:b86d15c6ba29 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Vanger 0:b86d15c6ba29 20 */
Vanger 0:b86d15c6ba29 21
Vanger 0:b86d15c6ba29 22 #ifdef HAVE_CONFIG_H
Vanger 0:b86d15c6ba29 23 #include <config.h>
Vanger 0:b86d15c6ba29 24 #endif
Vanger 0:b86d15c6ba29 25
Vanger 0:b86d15c6ba29 26 #include <cyassl/ctaocrypt/settings.h>
Vanger 0:b86d15c6ba29 27
Vanger 0:b86d15c6ba29 28 #ifndef NO_RABBIT
Vanger 0:b86d15c6ba29 29
Vanger 0:b86d15c6ba29 30 #include <cyassl/ctaocrypt/rabbit.h>
Vanger 0:b86d15c6ba29 31 #include <cyassl/ctaocrypt/error-crypt.h>
Vanger 0:b86d15c6ba29 32 #include <cyassl/ctaocrypt/logging.h>
Vanger 0:b86d15c6ba29 33 #ifdef NO_INLINE
Vanger 0:b86d15c6ba29 34 #include <cyassl/ctaocrypt/misc.h>
Vanger 0:b86d15c6ba29 35 #else
Vanger 0:b86d15c6ba29 36 #include <ctaocrypt/src/misc.c>
Vanger 0:b86d15c6ba29 37 #endif
Vanger 0:b86d15c6ba29 38
Vanger 0:b86d15c6ba29 39
Vanger 0:b86d15c6ba29 40 #ifdef BIG_ENDIAN_ORDER
Vanger 0:b86d15c6ba29 41 #define LITTLE32(x) ByteReverseWord32(x)
Vanger 0:b86d15c6ba29 42 #else
Vanger 0:b86d15c6ba29 43 #define LITTLE32(x) (x)
Vanger 0:b86d15c6ba29 44 #endif
Vanger 0:b86d15c6ba29 45
Vanger 0:b86d15c6ba29 46 #define U32V(x) ((word32)(x) & 0xFFFFFFFFU)
Vanger 0:b86d15c6ba29 47
Vanger 0:b86d15c6ba29 48
Vanger 0:b86d15c6ba29 49 /* Square a 32-bit unsigned integer to obtain the 64-bit result and return */
Vanger 0:b86d15c6ba29 50 /* the upper 32 bits XOR the lower 32 bits */
Vanger 0:b86d15c6ba29 51 static word32 RABBIT_g_func(word32 x)
Vanger 0:b86d15c6ba29 52 {
Vanger 0:b86d15c6ba29 53 /* Temporary variables */
Vanger 0:b86d15c6ba29 54 word32 a, b, h, l;
Vanger 0:b86d15c6ba29 55
Vanger 0:b86d15c6ba29 56 /* Construct high and low argument for squaring */
Vanger 0:b86d15c6ba29 57 a = x&0xFFFF;
Vanger 0:b86d15c6ba29 58 b = x>>16;
Vanger 0:b86d15c6ba29 59
Vanger 0:b86d15c6ba29 60 /* Calculate high and low result of squaring */
Vanger 0:b86d15c6ba29 61 h = (((U32V(a*a)>>17) + U32V(a*b))>>15) + b*b;
Vanger 0:b86d15c6ba29 62 l = x*x;
Vanger 0:b86d15c6ba29 63
Vanger 0:b86d15c6ba29 64 /* Return high XOR low */
Vanger 0:b86d15c6ba29 65 return U32V(h^l);
Vanger 0:b86d15c6ba29 66 }
Vanger 0:b86d15c6ba29 67
Vanger 0:b86d15c6ba29 68
Vanger 0:b86d15c6ba29 69 /* Calculate the next internal state */
Vanger 0:b86d15c6ba29 70 static void RABBIT_next_state(RabbitCtx* ctx)
Vanger 0:b86d15c6ba29 71 {
Vanger 0:b86d15c6ba29 72 /* Temporary variables */
Vanger 0:b86d15c6ba29 73 word32 g[8], c_old[8], i;
Vanger 0:b86d15c6ba29 74
Vanger 0:b86d15c6ba29 75 /* Save old counter values */
Vanger 0:b86d15c6ba29 76 for (i=0; i<8; i++)
Vanger 0:b86d15c6ba29 77 c_old[i] = ctx->c[i];
Vanger 0:b86d15c6ba29 78
Vanger 0:b86d15c6ba29 79 /* Calculate new counter values */
Vanger 0:b86d15c6ba29 80 ctx->c[0] = U32V(ctx->c[0] + 0x4D34D34D + ctx->carry);
Vanger 0:b86d15c6ba29 81 ctx->c[1] = U32V(ctx->c[1] + 0xD34D34D3 + (ctx->c[0] < c_old[0]));
Vanger 0:b86d15c6ba29 82 ctx->c[2] = U32V(ctx->c[2] + 0x34D34D34 + (ctx->c[1] < c_old[1]));
Vanger 0:b86d15c6ba29 83 ctx->c[3] = U32V(ctx->c[3] + 0x4D34D34D + (ctx->c[2] < c_old[2]));
Vanger 0:b86d15c6ba29 84 ctx->c[4] = U32V(ctx->c[4] + 0xD34D34D3 + (ctx->c[3] < c_old[3]));
Vanger 0:b86d15c6ba29 85 ctx->c[5] = U32V(ctx->c[5] + 0x34D34D34 + (ctx->c[4] < c_old[4]));
Vanger 0:b86d15c6ba29 86 ctx->c[6] = U32V(ctx->c[6] + 0x4D34D34D + (ctx->c[5] < c_old[5]));
Vanger 0:b86d15c6ba29 87 ctx->c[7] = U32V(ctx->c[7] + 0xD34D34D3 + (ctx->c[6] < c_old[6]));
Vanger 0:b86d15c6ba29 88 ctx->carry = (ctx->c[7] < c_old[7]);
Vanger 0:b86d15c6ba29 89
Vanger 0:b86d15c6ba29 90 /* Calculate the g-values */
Vanger 0:b86d15c6ba29 91 for (i=0;i<8;i++)
Vanger 0:b86d15c6ba29 92 g[i] = RABBIT_g_func(U32V(ctx->x[i] + ctx->c[i]));
Vanger 0:b86d15c6ba29 93
Vanger 0:b86d15c6ba29 94 /* Calculate new state values */
Vanger 0:b86d15c6ba29 95 ctx->x[0] = U32V(g[0] + rotlFixed(g[7],16) + rotlFixed(g[6], 16));
Vanger 0:b86d15c6ba29 96 ctx->x[1] = U32V(g[1] + rotlFixed(g[0], 8) + g[7]);
Vanger 0:b86d15c6ba29 97 ctx->x[2] = U32V(g[2] + rotlFixed(g[1],16) + rotlFixed(g[0], 16));
Vanger 0:b86d15c6ba29 98 ctx->x[3] = U32V(g[3] + rotlFixed(g[2], 8) + g[1]);
Vanger 0:b86d15c6ba29 99 ctx->x[4] = U32V(g[4] + rotlFixed(g[3],16) + rotlFixed(g[2], 16));
Vanger 0:b86d15c6ba29 100 ctx->x[5] = U32V(g[5] + rotlFixed(g[4], 8) + g[3]);
Vanger 0:b86d15c6ba29 101 ctx->x[6] = U32V(g[6] + rotlFixed(g[5],16) + rotlFixed(g[4], 16));
Vanger 0:b86d15c6ba29 102 ctx->x[7] = U32V(g[7] + rotlFixed(g[6], 8) + g[5]);
Vanger 0:b86d15c6ba29 103 }
Vanger 0:b86d15c6ba29 104
Vanger 0:b86d15c6ba29 105
Vanger 0:b86d15c6ba29 106 /* IV setup */
Vanger 0:b86d15c6ba29 107 static void RabbitSetIV(Rabbit* ctx, const byte* inIv)
Vanger 0:b86d15c6ba29 108 {
Vanger 0:b86d15c6ba29 109 /* Temporary variables */
Vanger 0:b86d15c6ba29 110 word32 i0, i1, i2, i3, i;
Vanger 0:b86d15c6ba29 111 word32 iv[2];
Vanger 0:b86d15c6ba29 112
Vanger 0:b86d15c6ba29 113 if (inIv)
Vanger 0:b86d15c6ba29 114 XMEMCPY(iv, inIv, sizeof(iv));
Vanger 0:b86d15c6ba29 115 else
Vanger 0:b86d15c6ba29 116 XMEMSET(iv, 0, sizeof(iv));
Vanger 0:b86d15c6ba29 117
Vanger 0:b86d15c6ba29 118 /* Generate four subvectors */
Vanger 0:b86d15c6ba29 119 i0 = LITTLE32(iv[0]);
Vanger 0:b86d15c6ba29 120 i2 = LITTLE32(iv[1]);
Vanger 0:b86d15c6ba29 121 i1 = (i0>>16) | (i2&0xFFFF0000);
Vanger 0:b86d15c6ba29 122 i3 = (i2<<16) | (i0&0x0000FFFF);
Vanger 0:b86d15c6ba29 123
Vanger 0:b86d15c6ba29 124 /* Modify counter values */
Vanger 0:b86d15c6ba29 125 ctx->workCtx.c[0] = ctx->masterCtx.c[0] ^ i0;
Vanger 0:b86d15c6ba29 126 ctx->workCtx.c[1] = ctx->masterCtx.c[1] ^ i1;
Vanger 0:b86d15c6ba29 127 ctx->workCtx.c[2] = ctx->masterCtx.c[2] ^ i2;
Vanger 0:b86d15c6ba29 128 ctx->workCtx.c[3] = ctx->masterCtx.c[3] ^ i3;
Vanger 0:b86d15c6ba29 129 ctx->workCtx.c[4] = ctx->masterCtx.c[4] ^ i0;
Vanger 0:b86d15c6ba29 130 ctx->workCtx.c[5] = ctx->masterCtx.c[5] ^ i1;
Vanger 0:b86d15c6ba29 131 ctx->workCtx.c[6] = ctx->masterCtx.c[6] ^ i2;
Vanger 0:b86d15c6ba29 132 ctx->workCtx.c[7] = ctx->masterCtx.c[7] ^ i3;
Vanger 0:b86d15c6ba29 133
Vanger 0:b86d15c6ba29 134 /* Copy state variables */
Vanger 0:b86d15c6ba29 135 for (i=0; i<8; i++)
Vanger 0:b86d15c6ba29 136 ctx->workCtx.x[i] = ctx->masterCtx.x[i];
Vanger 0:b86d15c6ba29 137 ctx->workCtx.carry = ctx->masterCtx.carry;
Vanger 0:b86d15c6ba29 138
Vanger 0:b86d15c6ba29 139 /* Iterate the system four times */
Vanger 0:b86d15c6ba29 140 for (i=0; i<4; i++)
Vanger 0:b86d15c6ba29 141 RABBIT_next_state(&(ctx->workCtx));
Vanger 0:b86d15c6ba29 142 }
Vanger 0:b86d15c6ba29 143
Vanger 0:b86d15c6ba29 144
Vanger 0:b86d15c6ba29 145 /* Key setup */
Vanger 0:b86d15c6ba29 146 static INLINE int DoKey(Rabbit* ctx, const byte* key, const byte* iv)
Vanger 0:b86d15c6ba29 147 {
Vanger 0:b86d15c6ba29 148 /* Temporary variables */
Vanger 0:b86d15c6ba29 149 word32 k0, k1, k2, k3, i;
Vanger 0:b86d15c6ba29 150
Vanger 0:b86d15c6ba29 151 /* Generate four subkeys */
Vanger 0:b86d15c6ba29 152 k0 = LITTLE32(*(word32*)(key+ 0));
Vanger 0:b86d15c6ba29 153 k1 = LITTLE32(*(word32*)(key+ 4));
Vanger 0:b86d15c6ba29 154 k2 = LITTLE32(*(word32*)(key+ 8));
Vanger 0:b86d15c6ba29 155 k3 = LITTLE32(*(word32*)(key+12));
Vanger 0:b86d15c6ba29 156
Vanger 0:b86d15c6ba29 157 /* Generate initial state variables */
Vanger 0:b86d15c6ba29 158 ctx->masterCtx.x[0] = k0;
Vanger 0:b86d15c6ba29 159 ctx->masterCtx.x[2] = k1;
Vanger 0:b86d15c6ba29 160 ctx->masterCtx.x[4] = k2;
Vanger 0:b86d15c6ba29 161 ctx->masterCtx.x[6] = k3;
Vanger 0:b86d15c6ba29 162 ctx->masterCtx.x[1] = U32V(k3<<16) | (k2>>16);
Vanger 0:b86d15c6ba29 163 ctx->masterCtx.x[3] = U32V(k0<<16) | (k3>>16);
Vanger 0:b86d15c6ba29 164 ctx->masterCtx.x[5] = U32V(k1<<16) | (k0>>16);
Vanger 0:b86d15c6ba29 165 ctx->masterCtx.x[7] = U32V(k2<<16) | (k1>>16);
Vanger 0:b86d15c6ba29 166
Vanger 0:b86d15c6ba29 167 /* Generate initial counter values */
Vanger 0:b86d15c6ba29 168 ctx->masterCtx.c[0] = rotlFixed(k2, 16);
Vanger 0:b86d15c6ba29 169 ctx->masterCtx.c[2] = rotlFixed(k3, 16);
Vanger 0:b86d15c6ba29 170 ctx->masterCtx.c[4] = rotlFixed(k0, 16);
Vanger 0:b86d15c6ba29 171 ctx->masterCtx.c[6] = rotlFixed(k1, 16);
Vanger 0:b86d15c6ba29 172 ctx->masterCtx.c[1] = (k0&0xFFFF0000) | (k1&0xFFFF);
Vanger 0:b86d15c6ba29 173 ctx->masterCtx.c[3] = (k1&0xFFFF0000) | (k2&0xFFFF);
Vanger 0:b86d15c6ba29 174 ctx->masterCtx.c[5] = (k2&0xFFFF0000) | (k3&0xFFFF);
Vanger 0:b86d15c6ba29 175 ctx->masterCtx.c[7] = (k3&0xFFFF0000) | (k0&0xFFFF);
Vanger 0:b86d15c6ba29 176
Vanger 0:b86d15c6ba29 177 /* Clear carry bit */
Vanger 0:b86d15c6ba29 178 ctx->masterCtx.carry = 0;
Vanger 0:b86d15c6ba29 179
Vanger 0:b86d15c6ba29 180 /* Iterate the system four times */
Vanger 0:b86d15c6ba29 181 for (i=0; i<4; i++)
Vanger 0:b86d15c6ba29 182 RABBIT_next_state(&(ctx->masterCtx));
Vanger 0:b86d15c6ba29 183
Vanger 0:b86d15c6ba29 184 /* Modify the counters */
Vanger 0:b86d15c6ba29 185 for (i=0; i<8; i++)
Vanger 0:b86d15c6ba29 186 ctx->masterCtx.c[i] ^= ctx->masterCtx.x[(i+4)&0x7];
Vanger 0:b86d15c6ba29 187
Vanger 0:b86d15c6ba29 188 /* Copy master instance to work instance */
Vanger 0:b86d15c6ba29 189 for (i=0; i<8; i++) {
Vanger 0:b86d15c6ba29 190 ctx->workCtx.x[i] = ctx->masterCtx.x[i];
Vanger 0:b86d15c6ba29 191 ctx->workCtx.c[i] = ctx->masterCtx.c[i];
Vanger 0:b86d15c6ba29 192 }
Vanger 0:b86d15c6ba29 193 ctx->workCtx.carry = ctx->masterCtx.carry;
Vanger 0:b86d15c6ba29 194
Vanger 0:b86d15c6ba29 195 RabbitSetIV(ctx, iv);
Vanger 0:b86d15c6ba29 196
Vanger 0:b86d15c6ba29 197 return 0;
Vanger 0:b86d15c6ba29 198 }
Vanger 0:b86d15c6ba29 199
Vanger 0:b86d15c6ba29 200
Vanger 0:b86d15c6ba29 201 /* Key setup */
Vanger 0:b86d15c6ba29 202 int RabbitSetKey(Rabbit* ctx, const byte* key, const byte* iv)
Vanger 0:b86d15c6ba29 203 {
Vanger 0:b86d15c6ba29 204 #ifdef XSTREAM_ALIGN
Vanger 0:b86d15c6ba29 205 if ((cyassl_word)key % 4) {
Vanger 0:b86d15c6ba29 206 int alignKey[4];
Vanger 0:b86d15c6ba29 207
Vanger 0:b86d15c6ba29 208 /* iv aligned in SetIV */
Vanger 0:b86d15c6ba29 209 CYASSL_MSG("RabbitSetKey unaligned key");
Vanger 0:b86d15c6ba29 210
Vanger 0:b86d15c6ba29 211 XMEMCPY(alignKey, key, sizeof(alignKey));
Vanger 0:b86d15c6ba29 212
Vanger 0:b86d15c6ba29 213 return DoKey(ctx, (const byte*)alignKey, iv);
Vanger 0:b86d15c6ba29 214 }
Vanger 0:b86d15c6ba29 215 #endif /* XSTREAM_ALIGN */
Vanger 0:b86d15c6ba29 216
Vanger 0:b86d15c6ba29 217 return DoKey(ctx, key, iv);
Vanger 0:b86d15c6ba29 218 }
Vanger 0:b86d15c6ba29 219
Vanger 0:b86d15c6ba29 220
Vanger 0:b86d15c6ba29 221 /* Encrypt/decrypt a message of any size */
Vanger 0:b86d15c6ba29 222 static INLINE int DoProcess(Rabbit* ctx, byte* output, const byte* input,
Vanger 0:b86d15c6ba29 223 word32 msglen)
Vanger 0:b86d15c6ba29 224 {
Vanger 0:b86d15c6ba29 225 /* Encrypt/decrypt all full blocks */
Vanger 0:b86d15c6ba29 226 while (msglen >= 16) {
Vanger 0:b86d15c6ba29 227 /* Iterate the system */
Vanger 0:b86d15c6ba29 228 RABBIT_next_state(&(ctx->workCtx));
Vanger 0:b86d15c6ba29 229
Vanger 0:b86d15c6ba29 230 /* Encrypt/decrypt 16 bytes of data */
Vanger 0:b86d15c6ba29 231 *(word32*)(output+ 0) = *(word32*)(input+ 0) ^
Vanger 0:b86d15c6ba29 232 LITTLE32(ctx->workCtx.x[0] ^ (ctx->workCtx.x[5]>>16) ^
Vanger 0:b86d15c6ba29 233 U32V(ctx->workCtx.x[3]<<16));
Vanger 0:b86d15c6ba29 234 *(word32*)(output+ 4) = *(word32*)(input+ 4) ^
Vanger 0:b86d15c6ba29 235 LITTLE32(ctx->workCtx.x[2] ^ (ctx->workCtx.x[7]>>16) ^
Vanger 0:b86d15c6ba29 236 U32V(ctx->workCtx.x[5]<<16));
Vanger 0:b86d15c6ba29 237 *(word32*)(output+ 8) = *(word32*)(input+ 8) ^
Vanger 0:b86d15c6ba29 238 LITTLE32(ctx->workCtx.x[4] ^ (ctx->workCtx.x[1]>>16) ^
Vanger 0:b86d15c6ba29 239 U32V(ctx->workCtx.x[7]<<16));
Vanger 0:b86d15c6ba29 240 *(word32*)(output+12) = *(word32*)(input+12) ^
Vanger 0:b86d15c6ba29 241 LITTLE32(ctx->workCtx.x[6] ^ (ctx->workCtx.x[3]>>16) ^
Vanger 0:b86d15c6ba29 242 U32V(ctx->workCtx.x[1]<<16));
Vanger 0:b86d15c6ba29 243
Vanger 0:b86d15c6ba29 244 /* Increment pointers and decrement length */
Vanger 0:b86d15c6ba29 245 input += 16;
Vanger 0:b86d15c6ba29 246 output += 16;
Vanger 0:b86d15c6ba29 247 msglen -= 16;
Vanger 0:b86d15c6ba29 248 }
Vanger 0:b86d15c6ba29 249
Vanger 0:b86d15c6ba29 250 /* Encrypt/decrypt remaining data */
Vanger 0:b86d15c6ba29 251 if (msglen) {
Vanger 0:b86d15c6ba29 252
Vanger 0:b86d15c6ba29 253 word32 i;
Vanger 0:b86d15c6ba29 254 word32 tmp[4];
Vanger 0:b86d15c6ba29 255 byte* buffer = (byte*)tmp;
Vanger 0:b86d15c6ba29 256
Vanger 0:b86d15c6ba29 257 XMEMSET(tmp, 0, sizeof(tmp)); /* help static analysis */
Vanger 0:b86d15c6ba29 258
Vanger 0:b86d15c6ba29 259 /* Iterate the system */
Vanger 0:b86d15c6ba29 260 RABBIT_next_state(&(ctx->workCtx));
Vanger 0:b86d15c6ba29 261
Vanger 0:b86d15c6ba29 262 /* Generate 16 bytes of pseudo-random data */
Vanger 0:b86d15c6ba29 263 tmp[0] = LITTLE32(ctx->workCtx.x[0] ^
Vanger 0:b86d15c6ba29 264 (ctx->workCtx.x[5]>>16) ^ U32V(ctx->workCtx.x[3]<<16));
Vanger 0:b86d15c6ba29 265 tmp[1] = LITTLE32(ctx->workCtx.x[2] ^
Vanger 0:b86d15c6ba29 266 (ctx->workCtx.x[7]>>16) ^ U32V(ctx->workCtx.x[5]<<16));
Vanger 0:b86d15c6ba29 267 tmp[2] = LITTLE32(ctx->workCtx.x[4] ^
Vanger 0:b86d15c6ba29 268 (ctx->workCtx.x[1]>>16) ^ U32V(ctx->workCtx.x[7]<<16));
Vanger 0:b86d15c6ba29 269 tmp[3] = LITTLE32(ctx->workCtx.x[6] ^
Vanger 0:b86d15c6ba29 270 (ctx->workCtx.x[3]>>16) ^ U32V(ctx->workCtx.x[1]<<16));
Vanger 0:b86d15c6ba29 271
Vanger 0:b86d15c6ba29 272 /* Encrypt/decrypt the data */
Vanger 0:b86d15c6ba29 273 for (i=0; i<msglen; i++)
Vanger 0:b86d15c6ba29 274 output[i] = input[i] ^ buffer[i];
Vanger 0:b86d15c6ba29 275 }
Vanger 0:b86d15c6ba29 276
Vanger 0:b86d15c6ba29 277 return 0;
Vanger 0:b86d15c6ba29 278 }
Vanger 0:b86d15c6ba29 279
Vanger 0:b86d15c6ba29 280
Vanger 0:b86d15c6ba29 281 /* Encrypt/decrypt a message of any size */
Vanger 0:b86d15c6ba29 282 int RabbitProcess(Rabbit* ctx, byte* output, const byte* input, word32 msglen)
Vanger 0:b86d15c6ba29 283 {
Vanger 0:b86d15c6ba29 284 #ifdef XSTREAM_ALIGN
Vanger 0:b86d15c6ba29 285 if ((cyassl_word)input % 4 || (cyassl_word)output % 4) {
Vanger 0:b86d15c6ba29 286 #ifndef NO_CYASSL_ALLOC_ALIGN
Vanger 0:b86d15c6ba29 287 byte* tmp;
Vanger 0:b86d15c6ba29 288 CYASSL_MSG("RabbitProcess unaligned");
Vanger 0:b86d15c6ba29 289
Vanger 0:b86d15c6ba29 290 tmp = (byte*)XMALLOC(msglen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
Vanger 0:b86d15c6ba29 291 if (tmp == NULL) return MEMORY_E;
Vanger 0:b86d15c6ba29 292
Vanger 0:b86d15c6ba29 293 XMEMCPY(tmp, input, msglen);
Vanger 0:b86d15c6ba29 294 DoProcess(ctx, tmp, tmp, msglen);
Vanger 0:b86d15c6ba29 295 XMEMCPY(output, tmp, msglen);
Vanger 0:b86d15c6ba29 296
Vanger 0:b86d15c6ba29 297 XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
Vanger 0:b86d15c6ba29 298
Vanger 0:b86d15c6ba29 299 return 0;
Vanger 0:b86d15c6ba29 300 #else
Vanger 0:b86d15c6ba29 301 return BAD_ALIGN_E;
Vanger 0:b86d15c6ba29 302 #endif
Vanger 0:b86d15c6ba29 303 }
Vanger 0:b86d15c6ba29 304 #endif /* XSTREAM_ALIGN */
Vanger 0:b86d15c6ba29 305
Vanger 0:b86d15c6ba29 306 return DoProcess(ctx, output, input, msglen);
Vanger 0:b86d15c6ba29 307 }
Vanger 0:b86d15c6ba29 308
Vanger 0:b86d15c6ba29 309
Vanger 0:b86d15c6ba29 310 #endif /* NO_RABBIT */