22 #define RC5_DEFAULT_ROUNDS RC5_12_ROUNDS
26 #define RC5_BLOCKSIZE RC5_32_BLOCK
27 #define RC5_KEY RC5_32_KEY
28 #define RC5_EXPANDED_KEYSIZE sizeof( RC5_KEY )
36 #ifndef CONFIG_NO_SELFTEST
40 static const struct RC5_TEST {
45 { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
47 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
48 { 0x21, 0xA5, 0xDB, 0xEE, 0x15, 0x4B, 0x8F, 0x6D } },
49 { { 0x91, 0x5F, 0x46, 0x19, 0xBE, 0x41, 0xB2, 0x51,
50 0x63, 0x55, 0xA5, 0x01, 0x10, 0xA9, 0xCE, 0x91 },
51 { 0x21, 0xA5, 0xDB, 0xEE, 0x15, 0x4B, 0x8F, 0x6D },
52 { 0xF7, 0xC0, 0x13, 0xAC, 0x5B, 0x2B, 0x89, 0x52 } },
53 { { 0x78, 0x33, 0x48, 0xE7, 0x5A, 0xEB, 0x0F, 0x2F,
54 0xD7, 0xB1, 0x69, 0xBB, 0x8D, 0xC1, 0x67, 0x87 },
55 { 0xF7, 0xC0, 0x13, 0xAC, 0x5B, 0x2B, 0x89, 0x52 },
56 { 0x2F, 0x42, 0xB3, 0xB7, 0x03, 0x69, 0xFC, 0x92 } },
57 { { 0xDC, 0x49, 0xDB, 0x13, 0x75, 0xA5, 0x58, 0x4F,
58 0x64, 0x85, 0xB4, 0x13, 0xB5, 0xF1, 0x2B, 0xAF },
59 { 0x2F, 0x42, 0xB3, 0xB7, 0x03, 0x69, 0xFC, 0x92 },
60 { 0x65, 0xC1, 0x78, 0xB2, 0x84, 0xD1, 0x97, 0xCC } },
61 { { 0x52, 0x69, 0xF1, 0x49, 0xD4, 0x1B, 0xA0, 0x15,
62 0x24, 0x97, 0x57, 0x4D, 0x7F, 0x15, 0x31, 0x25 },
63 { 0x65, 0xC1, 0x78, 0xB2, 0x84, 0xD1, 0x97, 0xCC },
64 { 0xEB, 0x44, 0xE4, 0x15, 0xDA, 0x31, 0x98, 0x24 } }
69 static int selfTest(
void )
75 for( i = 0; i <
sizeof( testRC5 ) /
sizeof(
struct RC5_TEST ); i++ )
77 status = testCipher( capabilityInfo, keyData, testRC5[ i ].
key,
104 assert( contextInfoPtr == NULL || \
106 assert( ( length == 0 &&
isWritePtr( data,
sizeof(
int ) ) ) || \
107 ( length > 0 &&
isWritePtr( data, length ) ) );
115 *valuePtr = RC5_EXPANDED_KEYSIZE;
120 return( getDefaultInfo( type, contextInfoPtr, data, length ) );
134 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
135 RC5_KEY *rc5Key = ( RC5_KEY * ) convInfo->
key;
136 int blockCount = noBytes / RC5_BLOCKSIZE;
138 while( blockCount-- > 0 )
144 buffer += RC5_BLOCKSIZE;
153 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
154 RC5_KEY *rc5Key = ( RC5_KEY * ) convInfo->
key;
155 int blockCount = noBytes / RC5_BLOCKSIZE;
157 while( blockCount-- > 0 )
163 buffer += RC5_BLOCKSIZE;
174 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
185 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
198 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
199 RC5_KEY *rc5Key = ( RC5_KEY * ) convInfo->
key;
200 int i, ivCount = convInfo->
ivCount;
208 bytesToUse = RC5_BLOCKSIZE - ivCount;
209 if( noBytes < bytesToUse )
210 bytesToUse = noBytes;
213 for( i = 0; i < bytesToUse; i++ )
214 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
215 memcpy( convInfo->currentIV + ivCount, buffer, bytesToUse );
218 noBytes -= bytesToUse;
219 buffer += bytesToUse;
220 ivCount += bytesToUse;
225 ivCount = ( noBytes > RC5_BLOCKSIZE ) ? RC5_BLOCKSIZE : noBytes;
232 for( i = 0; i < ivCount; i++ )
233 buffer[ i ] ^= convInfo->currentIV[ i ];
236 memcpy( convInfo->currentIV, buffer, ivCount );
244 convInfo->
ivCount = ( ivCount % RC5_BLOCKSIZE );
256 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
257 RC5_KEY *rc5Key = ( RC5_KEY * ) convInfo->
key;
258 BYTE temp[ RC5_BLOCKSIZE + 8 ];
259 int i, ivCount = convInfo->
ivCount;
267 bytesToUse = RC5_BLOCKSIZE - ivCount;
268 if( noBytes < bytesToUse )
269 bytesToUse = noBytes;
272 memcpy( temp, buffer, bytesToUse );
273 for( i = 0; i < bytesToUse; i++ )
274 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
275 memcpy( convInfo->currentIV + ivCount, temp, bytesToUse );
278 noBytes -= bytesToUse;
279 buffer += bytesToUse;
280 ivCount += bytesToUse;
285 ivCount = ( noBytes > RC5_BLOCKSIZE ) ? RC5_BLOCKSIZE : noBytes;
292 memcpy( temp, buffer, ivCount );
295 for( i = 0; i < ivCount; i++ )
296 buffer[ i ] ^= convInfo->currentIV[ i ];
299 memcpy( convInfo->currentIV, temp, ivCount );
307 convInfo->
ivCount = ( ivCount % RC5_BLOCKSIZE );
310 zeroise( temp, RC5_BLOCKSIZE );
320 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
321 RC5_KEY *rc5Key = ( RC5_KEY * ) convInfo->
key;
322 int i, ivCount = convInfo->
ivCount;
330 bytesToUse = RC5_BLOCKSIZE - ivCount;
331 if( noBytes < bytesToUse )
332 bytesToUse = noBytes;
335 for( i = 0; i < bytesToUse; i++ )
336 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
339 noBytes -= bytesToUse;
340 buffer += bytesToUse;
341 ivCount += bytesToUse;
346 ivCount = ( noBytes > RC5_BLOCKSIZE ) ? RC5_BLOCKSIZE : noBytes;
353 for( i = 0; i < ivCount; i++ )
354 buffer[ i ] ^= convInfo->currentIV[ i ];
362 convInfo->
ivCount = ( ivCount % RC5_BLOCKSIZE );
372 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
373 RC5_KEY *rc5Key = ( RC5_KEY * ) convInfo->
key;
374 int i, ivCount = convInfo->
ivCount;
382 bytesToUse = RC5_BLOCKSIZE - ivCount;
383 if( noBytes < bytesToUse )
384 bytesToUse = noBytes;
387 for( i = 0; i < bytesToUse; i++ )
388 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
391 noBytes -= bytesToUse;
392 buffer += bytesToUse;
393 ivCount += bytesToUse;
398 ivCount = ( noBytes > RC5_BLOCKSIZE ) ? RC5_BLOCKSIZE : noBytes;
405 for( i = 0; i < ivCount; i++ )
406 buffer[ i ] ^= convInfo->currentIV[ i ];
414 convInfo->
ivCount = ( ivCount % RC5_BLOCKSIZE );
430 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
431 RC5_KEY *rc5Key = ( RC5_KEY * ) convInfo->
key;
434 if( convInfo->userKey != key )
435 memcpy( convInfo->userKey, key, keyLength );
451 selfTest, getInfo, NULL, initGenericParams, initKey, NULL,
452 encryptECB, decryptECB, encryptCBC, decryptCBC,
453 encryptCFB, decryptCFB, encryptOFB, decryptOFB
458 return( &capabilityInfo );