Go to the documentation of this file.
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
40 #if (IDEA_SUPPORT == ENABLED)
65 static uint16_t ideaMul(uint16_t
a, uint16_t
b)
92 static uint16_t ideaInv(uint16_t
a)
144 if(context == NULL || key == NULL)
156 for(i = 0; i < 8; i++)
162 for(i = 8; i < 52; i++)
166 ek[i] = (ek[i - 7] << 9) | (ek[i - 14] >> 7);
168 else if((i % 8) == 7)
170 ek[i] = (ek[i - 15] << 9) | (ek[i - 14] >> 7);
174 ek[i] = (ek[i - 7] << 9) | (ek[i - 6] >> 7);
179 for(i = 0; i < 52; i += 6)
181 dk[i] = ideaInv(ek[48 - i]);
183 if(i == 0 || i == 48)
185 dk[i + 1] = -ek[49 - i];
186 dk[i + 2] = -ek[50 - i];
190 dk[i + 1] = -ek[50 - i];
191 dk[i + 2] = -ek[49 - i];
194 dk[i + 3] = ideaInv(ek[51 - i]);
198 dk[i + 4] = ek[46 - i];
199 dk[i + 5] = ek[47 - i];
233 for(i = 0; i < 8; i++)
236 a = ideaMul(
a, k[0]);
239 d = ideaMul(d, k[3]);
244 e = ideaMul(e, k[4]);
246 f = ideaMul(f, k[5]);
263 a = ideaMul(
a, k[0]);
266 d = ideaMul(d, k[3]);
302 for(i = 0; i < 8; i++)
305 a = ideaMul(
a, k[0]);
308 d = ideaMul(d, k[3]);
313 e = ideaMul(e, k[4]);
315 f = ideaMul(f, k[5]);
332 a = ideaMul(
a, k[0]);
335 d = ideaMul(d, k[3]);
void(* CipherAlgoEncryptBlock)(void *context, const uint8_t *input, uint8_t *output)
@ ERROR_INVALID_PARAMETER
Invalid parameter.
void(* CipherAlgoDecryptBlock)(void *context, const uint8_t *input, uint8_t *output)
@ ERROR_INVALID_KEY_LENGTH
General definitions for cryptographic algorithms.
IDEA encryption algorithm.
error_t(* CipherAlgoInit)(void *context, const uint8_t *key, size_t keyLen)
void ideaDecryptBlock(IdeaContext *context, const uint8_t *input, uint8_t *output)
Decrypt a 8-byte block using IDEA algorithm.
void ideaEncryptBlock(IdeaContext *context, const uint8_t *input, uint8_t *output)
Encrypt a 8-byte block using IDEA algorithm.
Common interface for encryption algorithms.
const CipherAlgo ideaCipherAlgo
#define osMemset(p, value, length)
void(* CipherAlgoDeinit)(void *context)
error_t ideaInit(IdeaContext *context, const uint8_t *key, size_t keyLen)
Initialize a IDEA context using the supplied key.
void ideaDeinit(IdeaContext *context)
Release IDEA context.