22 #define IDEA_BLOCKSIZE IDEA_BLOCK
32 #define IDEA_EXPANDED_KEYSIZE sizeof( IDEA_KEY )
40 #ifndef CONFIG_NO_SELFTEST
52 static const IDEA_TEST
FAR_BSS testIdea[] = {
53 { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04,
54 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 },
55 { 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03 },
56 { 0x11, 0xFB, 0xED, 0x2B, 0x01, 0x98, 0x6D, 0xE5 } },
57 { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04,
58 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 },
59 { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 },
60 { 0x54, 0x0E, 0x5F, 0xEA, 0x18, 0xC2, 0xF8, 0xB1 } },
61 { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04,
62 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 },
63 { 0x00, 0x19, 0x32, 0x4B, 0x64, 0x7D, 0x96, 0xAF },
64 { 0x9F, 0x0A, 0x0A, 0xB6, 0xE1, 0x0C, 0xED, 0x78 } },
65 { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04,
66 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 },
67 { 0xF5, 0x20, 0x2D, 0x5B, 0x9C, 0x67, 0x1B, 0x08 },
68 { 0xCF, 0x18, 0xFD, 0x73, 0x55, 0xE2, 0xC5, 0xC5 } },
69 { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04,
70 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 },
71 { 0xFA, 0xE6, 0xD2, 0xBE, 0xAA, 0x96, 0x82, 0x6E },
72 { 0x85, 0xDF, 0x52, 0x00, 0x56, 0x08, 0x19, 0x3D } },
73 { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04,
74 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 },
75 { 0x0A, 0x14, 0x1E, 0x28, 0x32, 0x3C, 0x46, 0x50 },
76 { 0x2F, 0x7D, 0xE7, 0x50, 0x21, 0x2F, 0xB7, 0x34 } },
77 { { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04,
78 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 },
79 { 0x05, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x23, 0x28 },
80 { 0x7B, 0x73, 0x14, 0x92, 0x5D, 0xE5, 0x9C, 0x09 } },
81 { { 0x00, 0x05, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x14,
82 0x00, 0x19, 0x00, 0x1E, 0x00, 0x23, 0x00, 0x28 },
83 { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 },
84 { 0x3E, 0xC0, 0x47, 0x80, 0xBE, 0xFF, 0x6E, 0x20 } },
85 { { 0x3A, 0x98, 0x4E, 0x20, 0x00, 0x19, 0x5D, 0xB3,
86 0x2E, 0xE5, 0x01, 0xC8, 0xC4, 0x7C, 0xEA, 0x60 },
87 { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 },
88 { 0x97, 0xBC, 0xD8, 0x20, 0x07, 0x80, 0xDA, 0x86 } },
89 { { 0x00, 0x64, 0x00, 0xC8, 0x01, 0x2C, 0x01, 0x90,
90 0x01, 0xF4, 0x02, 0x58, 0x02, 0xBC, 0x03, 0x20 },
91 { 0x05, 0x32, 0x0A, 0x64, 0x14, 0xC8, 0x19, 0xFA },
92 { 0x65, 0xBE, 0x87, 0xE7, 0xA2, 0x53, 0x8A, 0xED } },
93 { { 0x9D, 0x40, 0x75, 0xC1, 0x03, 0xBC, 0x32, 0x2A,
94 0xFB, 0x03, 0xE7, 0xBE, 0x6A, 0xB3, 0x00, 0x06 },
95 { 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 },
96 { 0xF5, 0xDB, 0x1A, 0xC4, 0x5E, 0x5E, 0xF9, 0xF9 } }
102 static int selfTest(
void )
108 for( i = 0; i <
sizeof( testIdea ) /
sizeof( IDEA_TEST ); i++ )
110 status = testCipher( capabilityInfo, keyData, testIdea[ i ].
key,
120 #define selfTest NULL
137 assert( contextInfoPtr == NULL || \
139 assert( ( length == 0 &&
isWritePtr( data,
sizeof(
int ) ) ) || \
140 ( length > 0 &&
isWritePtr( data, length ) ) );
148 *valuePtr = IDEA_EXPANDED_KEYSIZE;
153 return( getDefaultInfo( type, contextInfoPtr, data, length ) );
167 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
168 IDEA_KEY *ideaKey = ( IDEA_KEY * ) convInfo->
key;
169 int blockCount = noBytes / IDEA_BLOCKSIZE;
171 while( blockCount-- > 0 )
177 buffer += IDEA_BLOCKSIZE;
186 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
187 IDEA_KEY *ideaKey = ( IDEA_KEY * ) convInfo->
key;
188 int blockCount = noBytes / IDEA_BLOCKSIZE;
190 while( blockCount-- > 0 )
196 buffer += IDEA_BLOCKSIZE;
207 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
210 &( ( IDEA_KEY * ) convInfo->
key )->eKey,
219 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
222 &( ( IDEA_KEY * ) convInfo->
key )->dKey,
233 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
234 IDEA_KEY *ideaKey = ( IDEA_KEY * ) convInfo->
key;
235 int i, ivCount = convInfo->
ivCount;
243 bytesToUse = IDEA_BLOCKSIZE - ivCount;
244 if( noBytes < bytesToUse )
245 bytesToUse = noBytes;
248 for( i = 0; i < bytesToUse; i++ )
249 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
250 memcpy( convInfo->currentIV + ivCount, buffer, bytesToUse );
253 noBytes -= bytesToUse;
254 buffer += bytesToUse;
255 ivCount += bytesToUse;
260 ivCount = ( noBytes > IDEA_BLOCKSIZE ) ? IDEA_BLOCKSIZE : noBytes;
267 for( i = 0; i < ivCount; i++ )
268 buffer[ i ] ^= convInfo->currentIV[ i ];
271 memcpy( convInfo->currentIV, buffer, ivCount );
279 convInfo->
ivCount = ( ivCount % IDEA_BLOCKSIZE );
291 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
292 IDEA_KEY *ideaKey = ( IDEA_KEY * ) convInfo->
key;
293 BYTE temp[ IDEA_BLOCKSIZE + 8 ];
294 int i, ivCount = convInfo->
ivCount;
302 bytesToUse = IDEA_BLOCKSIZE - ivCount;
303 if( noBytes < bytesToUse )
304 bytesToUse = noBytes;
307 memcpy( temp, buffer, bytesToUse );
308 for( i = 0; i < bytesToUse; i++ )
309 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
310 memcpy( convInfo->currentIV + ivCount, temp, bytesToUse );
313 noBytes -= bytesToUse;
314 buffer += bytesToUse;
315 ivCount += bytesToUse;
320 ivCount = ( noBytes > IDEA_BLOCKSIZE ) ? IDEA_BLOCKSIZE : noBytes;
327 memcpy( temp, buffer, ivCount );
330 for( i = 0; i < ivCount; i++ )
331 buffer[ i ] ^= convInfo->currentIV[ i ];
334 memcpy( convInfo->currentIV, temp, ivCount );
342 convInfo->
ivCount = ( ivCount % IDEA_BLOCKSIZE );
345 zeroise( temp, IDEA_BLOCKSIZE );
355 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
356 IDEA_KEY *ideaKey = ( IDEA_KEY * ) convInfo->
key;
357 int i, ivCount = convInfo->
ivCount;
365 bytesToUse = IDEA_BLOCKSIZE - ivCount;
366 if( noBytes < bytesToUse )
367 bytesToUse = noBytes;
370 for( i = 0; i < bytesToUse; i++ )
371 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
374 noBytes -= bytesToUse;
375 buffer += bytesToUse;
376 ivCount += bytesToUse;
381 ivCount = ( noBytes > IDEA_BLOCKSIZE ) ? IDEA_BLOCKSIZE : noBytes;
388 for( i = 0; i < ivCount; i++ )
389 buffer[ i ] ^= convInfo->currentIV[ i ];
397 convInfo->
ivCount = ( ivCount % IDEA_BLOCKSIZE );
407 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
408 IDEA_KEY *ideaKey = ( IDEA_KEY * ) convInfo->
key;
409 int i, ivCount = convInfo->
ivCount;
417 bytesToUse = IDEA_BLOCKSIZE - ivCount;
418 if( noBytes < bytesToUse )
419 bytesToUse = noBytes;
422 for( i = 0; i < bytesToUse; i++ )
423 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
426 noBytes -= bytesToUse;
427 buffer += bytesToUse;
428 ivCount += bytesToUse;
433 ivCount = ( noBytes > IDEA_BLOCKSIZE ) ? IDEA_BLOCKSIZE : noBytes;
440 for( i = 0; i < ivCount; i++ )
441 buffer[ i ] ^= convInfo->currentIV[ i ];
449 convInfo->
ivCount = ( ivCount % IDEA_BLOCKSIZE );
465 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
466 IDEA_KEY *ideaKey = ( IDEA_KEY * ) convInfo->
key;
469 if( convInfo->userKey != key )
470 memcpy( convInfo->userKey, key, keyLength );
489 selfTest, getInfo, NULL, initGenericParams, initKey, NULL,
490 encryptECB, decryptECB, encryptCBC, decryptCBC,
491 encryptCFB, decryptCFB, encryptOFB, decryptOFB
496 return( &capabilityInfo );