wolfSSL SSL/TLS library, support up to TLS1.3
Dependents: CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more
wolfcrypt/src/idea.c@11:cee25a834751, 2017-05-30 (annotated)
- Committer:
- wolfSSL
- Date:
- Tue May 30 01:44:10 2017 +0000
- Revision:
- 11:cee25a834751
wolfSSL 3.11.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 11:cee25a834751 | 1 | /* idea.c |
wolfSSL | 11:cee25a834751 | 2 | * |
wolfSSL | 11:cee25a834751 | 3 | * Copyright (C) 2006-2016 wolfSSL Inc. |
wolfSSL | 11:cee25a834751 | 4 | * |
wolfSSL | 11:cee25a834751 | 5 | * This file is part of wolfSSL. |
wolfSSL | 11:cee25a834751 | 6 | * |
wolfSSL | 11:cee25a834751 | 7 | * wolfSSL is free software; you can redistribute it and/or modify |
wolfSSL | 11:cee25a834751 | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 11:cee25a834751 | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 11:cee25a834751 | 10 | * (at your option) any later version. |
wolfSSL | 11:cee25a834751 | 11 | * |
wolfSSL | 11:cee25a834751 | 12 | * wolfSSL is distributed in the hope that it will be useful, |
wolfSSL | 11:cee25a834751 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 11:cee25a834751 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 11:cee25a834751 | 15 | * GNU General Public License for more details. |
wolfSSL | 11:cee25a834751 | 16 | * |
wolfSSL | 11:cee25a834751 | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 11:cee25a834751 | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 11:cee25a834751 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
wolfSSL | 11:cee25a834751 | 20 | */ |
wolfSSL | 11:cee25a834751 | 21 | |
wolfSSL | 11:cee25a834751 | 22 | |
wolfSSL | 11:cee25a834751 | 23 | #ifdef HAVE_CONFIG_H |
wolfSSL | 11:cee25a834751 | 24 | #include <config.h> |
wolfSSL | 11:cee25a834751 | 25 | #endif |
wolfSSL | 11:cee25a834751 | 26 | |
wolfSSL | 11:cee25a834751 | 27 | #include <wolfssl/wolfcrypt/settings.h> |
wolfSSL | 11:cee25a834751 | 28 | |
wolfSSL | 11:cee25a834751 | 29 | #ifdef HAVE_IDEA |
wolfSSL | 11:cee25a834751 | 30 | |
wolfSSL | 11:cee25a834751 | 31 | #include <wolfssl/wolfcrypt/idea.h> |
wolfSSL | 11:cee25a834751 | 32 | |
wolfSSL | 11:cee25a834751 | 33 | #include <wolfssl/wolfcrypt/error-crypt.h> |
wolfSSL | 11:cee25a834751 | 34 | #include <wolfssl/wolfcrypt/logging.h> |
wolfSSL | 11:cee25a834751 | 35 | |
wolfSSL | 11:cee25a834751 | 36 | #ifdef NO_INLINE |
wolfSSL | 11:cee25a834751 | 37 | #include <wolfssl/wolfcrypt/misc.h> |
wolfSSL | 11:cee25a834751 | 38 | #else |
wolfSSL | 11:cee25a834751 | 39 | #define WOLFSSL_MISC_INCLUDED |
wolfSSL | 11:cee25a834751 | 40 | #include <wolfcrypt/src/misc.c> |
wolfSSL | 11:cee25a834751 | 41 | #endif |
wolfSSL | 11:cee25a834751 | 42 | |
wolfSSL | 11:cee25a834751 | 43 | /* multiplication of x and y modulo 2^16+1 |
wolfSSL | 11:cee25a834751 | 44 | * IDEA specify a special case when an entry value is 0 ( x or y) |
wolfSSL | 11:cee25a834751 | 45 | * then it must be replaced by 2^16 |
wolfSSL | 11:cee25a834751 | 46 | */ |
wolfSSL | 11:cee25a834751 | 47 | static INLINE word16 idea_mult(word16 x, word16 y) |
wolfSSL | 11:cee25a834751 | 48 | { |
wolfSSL | 11:cee25a834751 | 49 | long mul, res; |
wolfSSL | 11:cee25a834751 | 50 | |
wolfSSL | 11:cee25a834751 | 51 | mul = (long)x * (long)y; |
wolfSSL | 11:cee25a834751 | 52 | if (mul) { |
wolfSSL | 11:cee25a834751 | 53 | res = (mul & IDEA_MASK) - ((word32)mul >> 16); |
wolfSSL | 11:cee25a834751 | 54 | if (res <= 0) |
wolfSSL | 11:cee25a834751 | 55 | res += IDEA_MODULO; |
wolfSSL | 11:cee25a834751 | 56 | |
wolfSSL | 11:cee25a834751 | 57 | return (word16) (res & IDEA_MASK); |
wolfSSL | 11:cee25a834751 | 58 | } |
wolfSSL | 11:cee25a834751 | 59 | |
wolfSSL | 11:cee25a834751 | 60 | if (!x) |
wolfSSL | 11:cee25a834751 | 61 | return ((IDEA_MODULO - y) & IDEA_MASK); |
wolfSSL | 11:cee25a834751 | 62 | |
wolfSSL | 11:cee25a834751 | 63 | /* !y */ |
wolfSSL | 11:cee25a834751 | 64 | return ((IDEA_MODULO - x) & IDEA_MASK); |
wolfSSL | 11:cee25a834751 | 65 | } |
wolfSSL | 11:cee25a834751 | 66 | |
wolfSSL | 11:cee25a834751 | 67 | /* compute 1/a modulo 2^16+1 using Extended euclidean algorithm |
wolfSSL | 11:cee25a834751 | 68 | * adapted from fp_invmod */ |
wolfSSL | 11:cee25a834751 | 69 | static INLINE word16 idea_invmod(word16 x) |
wolfSSL | 11:cee25a834751 | 70 | { |
wolfSSL | 11:cee25a834751 | 71 | int u, v, b, d; |
wolfSSL | 11:cee25a834751 | 72 | |
wolfSSL | 11:cee25a834751 | 73 | if (x <= 1) |
wolfSSL | 11:cee25a834751 | 74 | return x; |
wolfSSL | 11:cee25a834751 | 75 | |
wolfSSL | 11:cee25a834751 | 76 | u = IDEA_MODULO; |
wolfSSL | 11:cee25a834751 | 77 | v = x; |
wolfSSL | 11:cee25a834751 | 78 | d = 1; |
wolfSSL | 11:cee25a834751 | 79 | b = 0; |
wolfSSL | 11:cee25a834751 | 80 | |
wolfSSL | 11:cee25a834751 | 81 | do { |
wolfSSL | 11:cee25a834751 | 82 | while (!(u & 1)) { |
wolfSSL | 11:cee25a834751 | 83 | u >>= 1; |
wolfSSL | 11:cee25a834751 | 84 | if (b & 1) |
wolfSSL | 11:cee25a834751 | 85 | b -= IDEA_MODULO; |
wolfSSL | 11:cee25a834751 | 86 | b >>= 1; |
wolfSSL | 11:cee25a834751 | 87 | } |
wolfSSL | 11:cee25a834751 | 88 | |
wolfSSL | 11:cee25a834751 | 89 | while (!(v & 1)) { |
wolfSSL | 11:cee25a834751 | 90 | v >>= 1; |
wolfSSL | 11:cee25a834751 | 91 | if (d & 1) { |
wolfSSL | 11:cee25a834751 | 92 | d -= IDEA_MODULO; |
wolfSSL | 11:cee25a834751 | 93 | } |
wolfSSL | 11:cee25a834751 | 94 | d >>= 1; |
wolfSSL | 11:cee25a834751 | 95 | } |
wolfSSL | 11:cee25a834751 | 96 | |
wolfSSL | 11:cee25a834751 | 97 | if (u >= v) { |
wolfSSL | 11:cee25a834751 | 98 | u -= v; |
wolfSSL | 11:cee25a834751 | 99 | b -= d; |
wolfSSL | 11:cee25a834751 | 100 | } else { |
wolfSSL | 11:cee25a834751 | 101 | v -= u; |
wolfSSL | 11:cee25a834751 | 102 | d -= b; |
wolfSSL | 11:cee25a834751 | 103 | } |
wolfSSL | 11:cee25a834751 | 104 | } while (u != 0); |
wolfSSL | 11:cee25a834751 | 105 | |
wolfSSL | 11:cee25a834751 | 106 | /* d is now the inverse, put positive value if required */ |
wolfSSL | 11:cee25a834751 | 107 | while (d < 0) |
wolfSSL | 11:cee25a834751 | 108 | d += IDEA_MODULO; |
wolfSSL | 11:cee25a834751 | 109 | |
wolfSSL | 11:cee25a834751 | 110 | /* d must be < IDEA_MODULO */ |
wolfSSL | 11:cee25a834751 | 111 | while (d >= (int)IDEA_MODULO) |
wolfSSL | 11:cee25a834751 | 112 | d -= IDEA_MODULO; |
wolfSSL | 11:cee25a834751 | 113 | |
wolfSSL | 11:cee25a834751 | 114 | return (word16)(d & IDEA_MASK); |
wolfSSL | 11:cee25a834751 | 115 | } |
wolfSSL | 11:cee25a834751 | 116 | |
wolfSSL | 11:cee25a834751 | 117 | /* generate the 52 16-bits key sub-blocks from the 128 key */ |
wolfSSL | 11:cee25a834751 | 118 | int wc_IdeaSetKey(Idea *idea, const byte* key, word16 keySz, |
wolfSSL | 11:cee25a834751 | 119 | const byte *iv, int dir) |
wolfSSL | 11:cee25a834751 | 120 | { |
wolfSSL | 11:cee25a834751 | 121 | word16 idx = 0; |
wolfSSL | 11:cee25a834751 | 122 | word32 t; |
wolfSSL | 11:cee25a834751 | 123 | short i; |
wolfSSL | 11:cee25a834751 | 124 | |
wolfSSL | 11:cee25a834751 | 125 | if (idea == NULL || key == NULL || keySz != IDEA_KEY_SIZE || |
wolfSSL | 11:cee25a834751 | 126 | (dir != IDEA_ENCRYPTION && dir != IDEA_DECRYPTION)) |
wolfSSL | 11:cee25a834751 | 127 | return BAD_FUNC_ARG; |
wolfSSL | 11:cee25a834751 | 128 | |
wolfSSL | 11:cee25a834751 | 129 | /* initial key schedule for 0 -> 7 */ |
wolfSSL | 11:cee25a834751 | 130 | for (i = 0; i < IDEA_ROUNDS; i++) { |
wolfSSL | 11:cee25a834751 | 131 | idea->skey[i] = (word16)key[idx++] << 8; |
wolfSSL | 11:cee25a834751 | 132 | idea->skey[i] |= (word16)key[idx++]; |
wolfSSL | 11:cee25a834751 | 133 | } |
wolfSSL | 11:cee25a834751 | 134 | |
wolfSSL | 11:cee25a834751 | 135 | /* shift phase key schedule for 8 -> 51 */ |
wolfSSL | 11:cee25a834751 | 136 | for (i = IDEA_ROUNDS; i < IDEA_SK_NUM; i++) { |
wolfSSL | 11:cee25a834751 | 137 | t = (word32)idea->skey[((i+1) & 7) ? i-7 : i-15] << 9; |
wolfSSL | 11:cee25a834751 | 138 | t |= (word32)idea->skey[((i+2) & 7) < 2 ? i-14 : i-6] >> 7; |
wolfSSL | 11:cee25a834751 | 139 | idea->skey[i] = (word16)(t & IDEA_MASK); |
wolfSSL | 11:cee25a834751 | 140 | } |
wolfSSL | 11:cee25a834751 | 141 | |
wolfSSL | 11:cee25a834751 | 142 | /* compute decryption key from encryption key */ |
wolfSSL | 11:cee25a834751 | 143 | if (dir == IDEA_DECRYPTION) { |
wolfSSL | 11:cee25a834751 | 144 | word16 enckey[IDEA_SK_NUM]; |
wolfSSL | 11:cee25a834751 | 145 | |
wolfSSL | 11:cee25a834751 | 146 | /* put encryption key in tmp buffer */ |
wolfSSL | 11:cee25a834751 | 147 | XMEMCPY(enckey, idea->skey, sizeof(idea->skey)); |
wolfSSL | 11:cee25a834751 | 148 | |
wolfSSL | 11:cee25a834751 | 149 | idx = 0; |
wolfSSL | 11:cee25a834751 | 150 | |
wolfSSL | 11:cee25a834751 | 151 | idea->skey[6*IDEA_ROUNDS] = idea_invmod(enckey[idx++]); |
wolfSSL | 11:cee25a834751 | 152 | idea->skey[6*IDEA_ROUNDS+1] = (IDEA_2EXP16 - enckey[idx++]) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 153 | idea->skey[6*IDEA_ROUNDS+2] = (IDEA_2EXP16 - enckey[idx++]) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 154 | idea->skey[6*IDEA_ROUNDS+3] = idea_invmod(enckey[idx++]); |
wolfSSL | 11:cee25a834751 | 155 | |
wolfSSL | 11:cee25a834751 | 156 | for (i = 6*(IDEA_ROUNDS-1); i >= 0; i -= 6) { |
wolfSSL | 11:cee25a834751 | 157 | idea->skey[i+4] = enckey[idx++]; |
wolfSSL | 11:cee25a834751 | 158 | idea->skey[i+5] = enckey[idx++]; |
wolfSSL | 11:cee25a834751 | 159 | |
wolfSSL | 11:cee25a834751 | 160 | idea->skey[i] = idea_invmod(enckey[idx++]); |
wolfSSL | 11:cee25a834751 | 161 | if (i) { |
wolfSSL | 11:cee25a834751 | 162 | idea->skey[i+2] = (IDEA_2EXP16 - enckey[idx++]) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 163 | idea->skey[i+1] = (IDEA_2EXP16 - enckey[idx++]) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 164 | } |
wolfSSL | 11:cee25a834751 | 165 | else { |
wolfSSL | 11:cee25a834751 | 166 | idea->skey[1] = (IDEA_2EXP16 - enckey[idx++]) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 167 | idea->skey[2] = (IDEA_2EXP16 - enckey[idx++]) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 168 | } |
wolfSSL | 11:cee25a834751 | 169 | |
wolfSSL | 11:cee25a834751 | 170 | idea->skey[i+3] = idea_invmod(enckey[idx++]); |
wolfSSL | 11:cee25a834751 | 171 | } |
wolfSSL | 11:cee25a834751 | 172 | |
wolfSSL | 11:cee25a834751 | 173 | /* erase temporary buffer */ |
wolfSSL | 11:cee25a834751 | 174 | ForceZero(enckey, sizeof(enckey)); |
wolfSSL | 11:cee25a834751 | 175 | } |
wolfSSL | 11:cee25a834751 | 176 | |
wolfSSL | 11:cee25a834751 | 177 | /* set the iv */ |
wolfSSL | 11:cee25a834751 | 178 | return wc_IdeaSetIV(idea, iv); |
wolfSSL | 11:cee25a834751 | 179 | } |
wolfSSL | 11:cee25a834751 | 180 | |
wolfSSL | 11:cee25a834751 | 181 | /* set the IV in the Idea key structure */ |
wolfSSL | 11:cee25a834751 | 182 | int wc_IdeaSetIV(Idea *idea, const byte* iv) |
wolfSSL | 11:cee25a834751 | 183 | { |
wolfSSL | 11:cee25a834751 | 184 | if (idea == NULL) |
wolfSSL | 11:cee25a834751 | 185 | return BAD_FUNC_ARG; |
wolfSSL | 11:cee25a834751 | 186 | |
wolfSSL | 11:cee25a834751 | 187 | if (iv != NULL) |
wolfSSL | 11:cee25a834751 | 188 | XMEMCPY(idea->reg, iv, IDEA_BLOCK_SIZE); |
wolfSSL | 11:cee25a834751 | 189 | else |
wolfSSL | 11:cee25a834751 | 190 | XMEMSET(idea->reg, 0, IDEA_BLOCK_SIZE); |
wolfSSL | 11:cee25a834751 | 191 | |
wolfSSL | 11:cee25a834751 | 192 | return 0; |
wolfSSL | 11:cee25a834751 | 193 | } |
wolfSSL | 11:cee25a834751 | 194 | |
wolfSSL | 11:cee25a834751 | 195 | /* encryption/decryption for a block (64 bits) |
wolfSSL | 11:cee25a834751 | 196 | */ |
wolfSSL | 11:cee25a834751 | 197 | void wc_IdeaCipher(Idea *idea, byte* out, const byte* in) |
wolfSSL | 11:cee25a834751 | 198 | { |
wolfSSL | 11:cee25a834751 | 199 | word32 t1, t2; |
wolfSSL | 11:cee25a834751 | 200 | word16 i, skey_idx = 0, idx = 0; |
wolfSSL | 11:cee25a834751 | 201 | word16 x[4]; |
wolfSSL | 11:cee25a834751 | 202 | |
wolfSSL | 11:cee25a834751 | 203 | /* put input byte block in word16 */ |
wolfSSL | 11:cee25a834751 | 204 | for (i = 0; i < IDEA_BLOCK_SIZE/2; i++) { |
wolfSSL | 11:cee25a834751 | 205 | x[i] = (word16)in[idx++] << 8; |
wolfSSL | 11:cee25a834751 | 206 | x[i] |= (word16)in[idx++]; |
wolfSSL | 11:cee25a834751 | 207 | } |
wolfSSL | 11:cee25a834751 | 208 | |
wolfSSL | 11:cee25a834751 | 209 | for (i = 0; i < IDEA_ROUNDS; i++) { |
wolfSSL | 11:cee25a834751 | 210 | x[0] = idea_mult(x[0], idea->skey[skey_idx++]); |
wolfSSL | 11:cee25a834751 | 211 | x[1] = ((word32)x[1] + (word32)idea->skey[skey_idx++]) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 212 | x[2] = ((word32)x[2] + (word32)idea->skey[skey_idx++]) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 213 | x[3] = idea_mult(x[3], idea->skey[skey_idx++]); |
wolfSSL | 11:cee25a834751 | 214 | |
wolfSSL | 11:cee25a834751 | 215 | t2 = x[0] ^ x[2]; |
wolfSSL | 11:cee25a834751 | 216 | t2 = idea_mult((word16)t2, idea->skey[skey_idx++]); |
wolfSSL | 11:cee25a834751 | 217 | t1 = (t2 + (x[1] ^ x[3])) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 218 | t1 = idea_mult((word16)t1, idea->skey[skey_idx++]); |
wolfSSL | 11:cee25a834751 | 219 | t2 = (t1 + t2) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 220 | |
wolfSSL | 11:cee25a834751 | 221 | x[0] ^= t1; |
wolfSSL | 11:cee25a834751 | 222 | x[3] ^= t2; |
wolfSSL | 11:cee25a834751 | 223 | |
wolfSSL | 11:cee25a834751 | 224 | t2 ^= x[1]; |
wolfSSL | 11:cee25a834751 | 225 | x[1] = x[2] ^ (word16)t1; |
wolfSSL | 11:cee25a834751 | 226 | x[2] = (word16)t2; |
wolfSSL | 11:cee25a834751 | 227 | } |
wolfSSL | 11:cee25a834751 | 228 | |
wolfSSL | 11:cee25a834751 | 229 | x[0] = idea_mult(x[0], idea->skey[skey_idx++]); |
wolfSSL | 11:cee25a834751 | 230 | out[0] = (x[0] >> 8) & 0xFF; |
wolfSSL | 11:cee25a834751 | 231 | out[1] = x[0] & 0xFF; |
wolfSSL | 11:cee25a834751 | 232 | |
wolfSSL | 11:cee25a834751 | 233 | x[2] = ((word32)x[2] + (word32)idea->skey[skey_idx++]) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 234 | out[2] = (x[2] >> 8) & 0xFF; |
wolfSSL | 11:cee25a834751 | 235 | out[3] = x[2] & 0xFF; |
wolfSSL | 11:cee25a834751 | 236 | |
wolfSSL | 11:cee25a834751 | 237 | x[1] = ((word32)x[1] + (word32)idea->skey[skey_idx++]) & IDEA_MASK; |
wolfSSL | 11:cee25a834751 | 238 | out[4] = (x[1] >> 8) & 0xFF; |
wolfSSL | 11:cee25a834751 | 239 | out[5] = x[1] & 0xFF; |
wolfSSL | 11:cee25a834751 | 240 | |
wolfSSL | 11:cee25a834751 | 241 | x[3] = idea_mult(x[3], idea->skey[skey_idx++]); |
wolfSSL | 11:cee25a834751 | 242 | out[6] = (x[3] >> 8) & 0xFF; |
wolfSSL | 11:cee25a834751 | 243 | out[7] = x[3] & 0xFF; |
wolfSSL | 11:cee25a834751 | 244 | } |
wolfSSL | 11:cee25a834751 | 245 | |
wolfSSL | 11:cee25a834751 | 246 | int wc_IdeaCbcEncrypt(Idea *idea, byte* out, const byte* in, word32 len) |
wolfSSL | 11:cee25a834751 | 247 | { |
wolfSSL | 11:cee25a834751 | 248 | int blocks; |
wolfSSL | 11:cee25a834751 | 249 | |
wolfSSL | 11:cee25a834751 | 250 | if (idea == NULL || out == NULL || in == NULL) |
wolfSSL | 11:cee25a834751 | 251 | return BAD_FUNC_ARG; |
wolfSSL | 11:cee25a834751 | 252 | |
wolfSSL | 11:cee25a834751 | 253 | blocks = len / IDEA_BLOCK_SIZE; |
wolfSSL | 11:cee25a834751 | 254 | while (blocks--) { |
wolfSSL | 11:cee25a834751 | 255 | xorbuf((byte*)idea->reg, in, IDEA_BLOCK_SIZE); |
wolfSSL | 11:cee25a834751 | 256 | wc_IdeaCipher(idea, (byte*)idea->reg, (byte*)idea->reg); |
wolfSSL | 11:cee25a834751 | 257 | XMEMCPY(out, idea->reg, IDEA_BLOCK_SIZE); |
wolfSSL | 11:cee25a834751 | 258 | |
wolfSSL | 11:cee25a834751 | 259 | out += IDEA_BLOCK_SIZE; |
wolfSSL | 11:cee25a834751 | 260 | in += IDEA_BLOCK_SIZE; |
wolfSSL | 11:cee25a834751 | 261 | } |
wolfSSL | 11:cee25a834751 | 262 | |
wolfSSL | 11:cee25a834751 | 263 | return 0; |
wolfSSL | 11:cee25a834751 | 264 | } |
wolfSSL | 11:cee25a834751 | 265 | |
wolfSSL | 11:cee25a834751 | 266 | int wc_IdeaCbcDecrypt(Idea *idea, byte* out, const byte* in, word32 len) |
wolfSSL | 11:cee25a834751 | 267 | { |
wolfSSL | 11:cee25a834751 | 268 | int blocks; |
wolfSSL | 11:cee25a834751 | 269 | |
wolfSSL | 11:cee25a834751 | 270 | if (idea == NULL || out == NULL || in == NULL) |
wolfSSL | 11:cee25a834751 | 271 | return BAD_FUNC_ARG; |
wolfSSL | 11:cee25a834751 | 272 | |
wolfSSL | 11:cee25a834751 | 273 | blocks = len / IDEA_BLOCK_SIZE; |
wolfSSL | 11:cee25a834751 | 274 | while (blocks--) { |
wolfSSL | 11:cee25a834751 | 275 | XMEMCPY((byte*)idea->tmp, in, IDEA_BLOCK_SIZE); |
wolfSSL | 11:cee25a834751 | 276 | wc_IdeaCipher(idea, out, (byte*)idea->tmp); |
wolfSSL | 11:cee25a834751 | 277 | xorbuf(out, (byte*)idea->reg, IDEA_BLOCK_SIZE); |
wolfSSL | 11:cee25a834751 | 278 | XMEMCPY(idea->reg, idea->tmp, IDEA_BLOCK_SIZE); |
wolfSSL | 11:cee25a834751 | 279 | |
wolfSSL | 11:cee25a834751 | 280 | out += IDEA_BLOCK_SIZE; |
wolfSSL | 11:cee25a834751 | 281 | in += IDEA_BLOCK_SIZE; |
wolfSSL | 11:cee25a834751 | 282 | } |
wolfSSL | 11:cee25a834751 | 283 | |
wolfSSL | 11:cee25a834751 | 284 | return 0; |
wolfSSL | 11:cee25a834751 | 285 | } |
wolfSSL | 11:cee25a834751 | 286 | |
wolfSSL | 11:cee25a834751 | 287 | #endif /* HAVE_IDEA */ |
wolfSSL | 11:cee25a834751 | 288 |