22 #define BLOWFISH_EXPANDED_KEYSIZE sizeof( BF_KEY )
30 #ifndef CONFIG_NO_SELFTEST
35 static int selfTest(
void )
39 BYTE *plain1 = (
BYTE * )
"BLOWFISH";
40 BYTE *key1 = (
BYTE * )
"abcdefghijklmnopqrstuvwxyz";
41 BYTE cipher1[] = { 0x32, 0x4E, 0xD0, 0xFE, 0xF4, 0x13, 0xA2, 0x03 };
42 BYTE plain2[] = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 };
43 BYTE *key2 = (
BYTE * )
"Who is John Galt?";
44 BYTE cipher2[] = { 0xCC, 0x91, 0x73, 0x2B, 0x80, 0x22, 0xF6, 0x84 };
45 BYTE plain3[] = { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 };
46 BYTE key3[] = { 0x41, 0x79, 0x6E, 0xA0, 0x52, 0x61, 0x6E, 0xE4 };
47 BYTE cipher3[] = { 0xE1, 0x13, 0xF4, 0x10, 0x2C, 0xFC, 0xCE, 0x43 };
51 status = testCipher( capabilityInfo, keyData, key1,
52 strlen( (
char * ) key1 ), plain1, cipher1 );
54 status = testCipher( capabilityInfo, keyData, key2,
55 strlen( (
char * ) key2 ), plain2, cipher2 );
57 status = testCipher( capabilityInfo, keyData, key3, 8, plain3,
79 assert( contextInfoPtr == NULL || \
81 assert( ( length == 0 &&
isWritePtr( data,
sizeof(
int ) ) ) || \
82 ( length > 0 &&
isWritePtr( data, length ) ) );
90 *valuePtr = BLOWFISH_EXPANDED_KEYSIZE;
95 return( getDefaultInfo( type, contextInfoPtr, data, length ) );
109 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
111 int blockCount = noBytes /
BF_BLOCK;
113 while( blockCount-- > 0 )
128 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
130 int blockCount = noBytes /
BF_BLOCK;
132 while( blockCount-- > 0 )
149 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
160 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
173 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
175 int i, ivCount = convInfo->
ivCount;
184 if( noBytes < bytesToUse )
185 bytesToUse = noBytes;
188 for( i = 0; i < bytesToUse; i++ )
189 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
190 memcpy( convInfo->currentIV + ivCount, buffer, bytesToUse );
193 noBytes -= bytesToUse;
194 buffer += bytesToUse;
195 ivCount += bytesToUse;
207 for( i = 0; i < ivCount; i++ )
208 buffer[ i ] ^= convInfo->currentIV[ i ];
211 memcpy( convInfo->currentIV, buffer, ivCount );
231 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
234 int i, ivCount = convInfo->
ivCount;
243 if( noBytes < bytesToUse )
244 bytesToUse = noBytes;
247 memcpy( temp, buffer, bytesToUse );
248 for( i = 0; i < bytesToUse; i++ )
249 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
250 memcpy( convInfo->currentIV + ivCount, temp, bytesToUse );
253 noBytes -= bytesToUse;
254 buffer += bytesToUse;
255 ivCount += bytesToUse;
267 memcpy( temp, buffer, ivCount );
270 for( i = 0; i < ivCount; i++ )
271 buffer[ i ] ^= convInfo->currentIV[ i ];
274 memcpy( convInfo->currentIV, temp, ivCount );
295 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
297 int i, ivCount = convInfo->
ivCount;
306 if( noBytes < bytesToUse )
307 bytesToUse = noBytes;
310 for( i = 0; i < bytesToUse; i++ )
311 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
314 noBytes -= bytesToUse;
315 buffer += bytesToUse;
316 ivCount += bytesToUse;
328 for( i = 0; i < ivCount; i++ )
329 buffer[ i ] ^= convInfo->currentIV[ i ];
347 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
349 int i, ivCount = convInfo->
ivCount;
358 if( noBytes < bytesToUse )
359 bytesToUse = noBytes;
362 for( i = 0; i < bytesToUse; i++ )
363 buffer[ i ] ^= convInfo->currentIV[ i + ivCount ];
366 noBytes -= bytesToUse;
367 buffer += bytesToUse;
368 ivCount += bytesToUse;
380 for( i = 0; i < ivCount; i++ )
381 buffer[ i ] ^= convInfo->currentIV[ i ];
405 CONV_INFO *convInfo = contextInfoPtr->ctxConv;
408 if( convInfo->userKey != key )
409 memcpy( convInfo->userKey, key, keyLength );
425 selfTest, getInfo, NULL, initGenericParams, initKey, NULL,
426 encryptECB, decryptECB, encryptCBC, decryptCBC,
427 encryptCFB, decryptCFB, encryptOFB, decryptOFB
432 return( &capabilityInfo );