22 #define RC2_BLOCKSIZE RC2_BLOCK
23 #define RC2_EXPANDED_KEYSIZE sizeof( RC2_KEY )
34 #define effectiveKeysizeBits( keySize ) bytesToBits( keySize )
42 #ifndef CONFIG_NO_SELFTEST
46 static const struct RC2_TEST {
51 { { 0x88, 0xBC, 0xA9, 0x0E, 0x90, 0x87, 0x5A, 0x7F,
52 0x0F, 0x79, 0xC3, 0x84, 0x62, 0x7B, 0xAF, 0xB2 },
53 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
54 { 0x22, 0x69, 0x55, 0x2A, 0xB0, 0xF8, 0x5C, 0xA6 } }
59 static int selfTest(
void )
65 for( i = 0; i <
sizeof( testRC2 ) /
sizeof(
struct RC2_TEST ); i++ )
67 status = testCipher( capabilityInfo, keyData, testRC2[ i ].
key,
94 assert( contextInfoPtr == NULL || \
96 assert( ( length == 0 &&
isWritePtr( data,
sizeof(
int ) ) ) || \
97 ( length > 0 &&
isWritePtr( data, length ) ) );
105 *valuePtr = RC2_EXPANDED_KEYSIZE;
110 return( getDefaultInfo( type, contextInfoPtr, data, length ) );
124 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
126 int blockCount = noBytes / RC2_BLOCKSIZE;
128 while( blockCount-- > 0 )
134 buffer += RC2_BLOCKSIZE;
143 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
145 int blockCount = noBytes / RC2_BLOCKSIZE;
147 while( blockCount-- > 0 )
153 buffer += RC2_BLOCKSIZE;
164 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
176 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
190 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
192 int i, ivCount = convInfo->
ivCount;
200 bytesToUse = RC2_BLOCKSIZE - ivCount;
201 if( noBytes < bytesToUse )
202 bytesToUse = noBytes;
205 for( i = 0; i < bytesToUse; i++ )
206 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
207 memcpy( convInfo->currentIV + ivCount, buffer, bytesToUse );
210 noBytes -= bytesToUse;
211 buffer += bytesToUse;
212 ivCount += bytesToUse;
217 ivCount = ( noBytes > RC2_BLOCKSIZE ) ? RC2_BLOCKSIZE : noBytes;
224 for( i = 0; i < ivCount; i++ )
225 buffer[ i ] ^= convInfo->currentIV[ i ];
228 memcpy( convInfo->currentIV, buffer, ivCount );
236 convInfo->
ivCount = ( ivCount % RC2_BLOCKSIZE );
248 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
250 BYTE temp[ RC2_BLOCKSIZE + 8 ];
251 int i, ivCount = convInfo->
ivCount;
259 bytesToUse = RC2_BLOCKSIZE - ivCount;
260 if( noBytes < bytesToUse )
261 bytesToUse = noBytes;
264 memcpy( temp, buffer, bytesToUse );
265 for( i = 0; i < bytesToUse; i++ )
266 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
267 memcpy( convInfo->currentIV + ivCount, temp, bytesToUse );
270 noBytes -= bytesToUse;
271 buffer += bytesToUse;
272 ivCount += bytesToUse;
277 ivCount = ( noBytes > RC2_BLOCKSIZE ) ? RC2_BLOCKSIZE : noBytes;
284 memcpy( temp, buffer, ivCount );
287 for( i = 0; i < ivCount; i++ )
288 buffer[ i ] ^= convInfo->currentIV[ i ];
291 memcpy( convInfo->currentIV, temp, ivCount );
299 convInfo->
ivCount = ( ivCount % RC2_BLOCKSIZE );
302 zeroise( temp, RC2_BLOCKSIZE );
312 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
314 int i, ivCount = convInfo->
ivCount;
322 bytesToUse = RC2_BLOCKSIZE - ivCount;
323 if( noBytes < bytesToUse )
324 bytesToUse = noBytes;
327 for( i = 0; i < bytesToUse; i++ )
328 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
331 noBytes -= bytesToUse;
332 buffer += bytesToUse;
333 ivCount += bytesToUse;
338 ivCount = ( noBytes > RC2_BLOCKSIZE ) ? RC2_BLOCKSIZE : noBytes;
345 for( i = 0; i < ivCount; i++ )
346 buffer[ i ] ^= convInfo->currentIV[ i ];
354 convInfo->
ivCount = ( ivCount % RC2_BLOCKSIZE );
364 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
366 int i, ivCount = convInfo->
ivCount;
374 bytesToUse = RC2_BLOCKSIZE - ivCount;
375 if( noBytes < bytesToUse )
376 bytesToUse = noBytes;
379 for( i = 0; i < bytesToUse; i++ )
380 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
383 noBytes -= bytesToUse;
384 buffer += bytesToUse;
385 ivCount += bytesToUse;
390 ivCount = ( noBytes > RC2_BLOCKSIZE ) ? RC2_BLOCKSIZE : noBytes;
397 for( i = 0; i < ivCount; i++ )
398 buffer[ i ] ^= convInfo->currentIV[ i ];
406 convInfo->
ivCount = ( ivCount % RC2_BLOCKSIZE );
421 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
425 static const BYTE *
plaintext =
"\x11\x1C\xDB\x36\xDC\x6E\x19\xF5";
426 static const BYTE *
ciphertext =
"\x9C\x4E\x66\x8A\xC7\x6B\x97\xF5";
428 static const BYTE *
plaintext =
"\x69\xAB\x54\x23\x2D\x86\x92\x61";
429 static const BYTE *
ciphertext =
"\x34\xAA\xF1\x83\xBD\x9C\xC0\x15";
451 for( i = 0; i < 256; i++ )
455 printf(
"Trying keys %02X xx.\n", i );
457 while(
key[ 0 ] == i )
464 printf(
"Found at %02X %02X %02X %02X %02X.\n",
469 for( keyIndex = 4; keyIndex >= 0; keyIndex-- )
472 if(
key[ keyIndex ] > 0 )
477 printf(
"Trying keys %02X %02X %02X %02X %02X.\n",
493 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
497 if( !memcmp( key,
"crackcrackcrack", 15 ) )
498 keyCrack( contextInfoPtr );
502 if( convInfo->userKey != key )
503 memcpy( convInfo->userKey, key, keyLength );
515 !memcmp( convInfo->userKey,
"PKCS#12PKCS#12", 14 ) )
517 memmove( convInfo->userKey, convInfo->userKey + 14,
527 RC2_set_key( rc2Key, keyLength, key, effectiveKeysizeBits( keyLength ) );
540 selfTest, getInfo, NULL, initGenericParams, initKey, NULL,
541 encryptECB, decryptECB, encryptCBC, decryptCBC,
542 encryptCFB, decryptCFB, encryptOFB, decryptOFB
547 return( &capabilityInfo );