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