forked from wolfSSL/wolfssl
Merge branch 'master' of https://github.com/lfcrypto/wolfssl into idea
This commit is contained in:
@ -5942,8 +5942,8 @@ static INLINE int Encrypt(WOLFSSL* ssl, byte* out, const byte* input, word16 sz)
|
||||
|
||||
#ifdef HAVE_IDEA
|
||||
case wolfssl_idea:
|
||||
wc_IdeaCbcEncrypt(ssl->encrypt.idea, out, input, sz);
|
||||
break;
|
||||
ret = wc_IdeaCbcEncrypt(ssl->encrypt.idea, out, input, sz);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
@ -6103,7 +6103,7 @@ static INLINE int Decrypt(WOLFSSL* ssl, byte* plain, const byte* input,
|
||||
|
||||
#ifdef HAVE_IDEA
|
||||
case wolfssl_idea:
|
||||
wc_IdeaCbcDecrypt(ssl->decrypt.idea, plain, input, sz);
|
||||
ret = wc_IdeaCbcDecrypt(ssl->decrypt.idea, plain, input, sz);
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
@ -44,17 +44,22 @@
|
||||
*/
|
||||
static INLINE word16 idea_mult(word16 x, word16 y)
|
||||
{
|
||||
word32 mul, res;
|
||||
long mul, res;
|
||||
|
||||
mul = (word32)x * (word32)y;
|
||||
mul = (long)x * (long)y;
|
||||
if (mul) {
|
||||
res = (mul & IDEA_MASK) - (mul >> 16);
|
||||
res -= (res >> 16);
|
||||
return (word16) ((res <=0 ? res+IDEA_MODULO : res) & IDEA_MASK);
|
||||
if (res <= 0)
|
||||
res += IDEA_MODULO;
|
||||
|
||||
return (word16) (res & IDEA_MASK);
|
||||
}
|
||||
|
||||
/* x == 0 or y == 0 */
|
||||
return (-x -y + 1);
|
||||
if (!x)
|
||||
return ((IDEA_MODULO - y) & IDEA_MASK);
|
||||
|
||||
/* !y */
|
||||
return ((IDEA_MODULO - x) & IDEA_MASK);
|
||||
}
|
||||
|
||||
/* compute 1/a modulo 2^16+1 using Extended euclidean algorithm
|
||||
@ -94,10 +99,10 @@ static INLINE word16 idea_invmod(word16 x)
|
||||
v -= u;
|
||||
d -= b;
|
||||
}
|
||||
} while (u);
|
||||
|
||||
} while (u != 0);
|
||||
|
||||
/* d is now the inverse, put positive value if required */
|
||||
if (d < 0)
|
||||
while (d < 0)
|
||||
d += IDEA_MODULO;
|
||||
|
||||
return (word16)(d & IDEA_MASK);
|
||||
@ -241,8 +246,8 @@ int wc_IdeaCbcEncrypt(Idea *idea, byte* out, const byte* in, word32 len)
|
||||
|
||||
blocks = len / IDEA_BLOCK_SIZE;
|
||||
while (blocks--) {
|
||||
xorbuf(idea->reg, in, IDEA_BLOCK_SIZE);
|
||||
wc_IdeaCipher(idea, idea->reg, idea->reg);
|
||||
xorbuf((byte*)idea->reg, in, IDEA_BLOCK_SIZE);
|
||||
wc_IdeaCipher(idea, (byte*)idea->reg, (byte*)idea->reg);
|
||||
XMEMCPY(out, idea->reg, IDEA_BLOCK_SIZE);
|
||||
|
||||
out += IDEA_BLOCK_SIZE;
|
||||
@ -255,17 +260,16 @@ int wc_IdeaCbcEncrypt(Idea *idea, byte* out, const byte* in, word32 len)
|
||||
int wc_IdeaCbcDecrypt(Idea *idea, byte* out, const byte* in, word32 len)
|
||||
{
|
||||
int blocks;
|
||||
byte tmp[IDEA_BLOCK_SIZE];
|
||||
|
||||
if (idea == NULL || out == NULL || in == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
blocks = len / IDEA_BLOCK_SIZE;
|
||||
while (blocks--) {
|
||||
XMEMCPY(tmp, in, IDEA_BLOCK_SIZE);
|
||||
wc_IdeaCipher(idea, out, tmp);
|
||||
xorbuf(out, idea->reg, IDEA_BLOCK_SIZE);
|
||||
XMEMCPY(idea->reg, tmp, IDEA_BLOCK_SIZE);
|
||||
XMEMCPY((byte*)idea->tmp, in, IDEA_BLOCK_SIZE);
|
||||
wc_IdeaCipher(idea, out, (byte*)idea->tmp);
|
||||
xorbuf(out, (byte*)idea->reg, IDEA_BLOCK_SIZE);
|
||||
XMEMCPY(idea->reg, idea->tmp, IDEA_BLOCK_SIZE);
|
||||
|
||||
out += IDEA_BLOCK_SIZE;
|
||||
in += IDEA_BLOCK_SIZE;
|
||||
|
@ -45,8 +45,9 @@ enum {
|
||||
|
||||
/* IDEA encryption and decryption */
|
||||
typedef struct Idea {
|
||||
byte reg[IDEA_BLOCK_SIZE]; /* for CBC mode */
|
||||
word16 skey[IDEA_SK_NUM]; /* 832 bits expanded key */
|
||||
word32 reg[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||
word32 tmp[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
|
||||
word16 skey[IDEA_SK_NUM]; /* 832 bits expanded key */
|
||||
} Idea;
|
||||
|
||||
WOLFSSL_API int wc_IdeaSetKey(Idea *idea, const byte* key, word16 keySz,
|
||||
|
Reference in New Issue
Block a user