blowfish Namespace Reference
Typedef Documentation
Iterator used to traverse data in all encryption routines below.
Definition at line 471 of file blowfish.cpp.
Enumeration Type Documentation
Source and destination data sizes must be multiples of this value.
Definition at line 24 of file blowfish.h. 00024 { kBlockSize = 2*4 }; ///< two 4-byte words.
Function Documentation
Definition at line 513 of file blowfish.cpp. 00514 { 00515 Block chain(0,0); 00516 if( pChain ) chain = *pChain; 00517 DIter srcScan(src); 00518 DIter const srcEnd (src, byteSize); 00519 DIter dstScan(dst); 00520 for( ; srcScan != srcEnd ; ++srcScan, ++dstScan ) 00521 { 00522 Block crypt = *srcScan; 00523 *dstScan = chain ^ core::decipherBlock( pad, crypt ); 00524 chain = crypt; 00525 } 00526 if( pChain ) *pChain = chain; 00527 }
Definition at line 542 of file blowfish.cpp. 00543 { 00544 Block chain(0,0); 00545 if( pChain ) chain = *pChain; 00546 DIter srcScan(src); 00547 DIter const srcEnd (src, byteSize); 00548 DIter dstScan(dst); 00549 for( ; srcScan != srcEnd ; ++srcScan, ++dstScan ) 00550 { 00551 Block crypt = *srcScan; 00552 *dstScan = crypt ^ core::encipherBlock( pad, chain ); 00553 chain = crypt; 00554 } 00555 if( pChain ) *pChain = chain; 00556 }
Definition at line 491 of file blowfish.cpp. 00492 { 00493 DIter srcScan(src); 00494 DIter const srcEnd (src, byteSize); 00495 DIter dstScan(dst); 00496 for( ; srcScan != srcEnd ; ++srcScan, ++dstScan ) 00497 *dstScan = core::decipherBlock( pad, *srcScan ); 00498 }
Definition at line 501 of file blowfish.cpp. 00502 { 00503 Block chain(0,0); 00504 if( pChain ) chain = *pChain; 00505 DIter srcScan(src); 00506 DIter const srcEnd (src, byteSize); 00507 DIter dstScan(dst); 00508 for( ; srcScan != srcEnd ; ++srcScan, ++dstScan ) 00509 *dstScan = chain = core::encipherBlock( pad, *srcScan ^ chain ); 00510 if( pChain ) *pChain = chain; 00511 }
Definition at line 530 of file blowfish.cpp. 00531 { 00532 Block chain(0,0); 00533 if( pChain ) chain = *pChain; 00534 DIter srcScan(src); 00535 DIter const srcEnd (src, byteSize); 00536 DIter dstScan(dst); 00537 for( ; srcScan != srcEnd ; ++srcScan, ++dstScan ) 00538 *dstScan = chain = ( *srcScan ^ core::encipherBlock( pad, chain ) ); 00539 if( pChain ) *pChain = chain; 00540 }
Definition at line 482 of file blowfish.cpp. 00483 { 00484 DIter srcScan(src); 00485 DIter const srcEnd (src, byteSize); 00486 DIter dstScan(dst); 00487 for( ; srcScan != srcEnd ; ++srcScan, ++dstScan ) 00488 *dstScan = core::encipherBlock( pad, *srcScan ); 00489 }
Returns an encription pad generated using the specified key/password.
Definition at line 432 of file blowfish.cpp. 00433 { 00434 if( keyLen < 1 || keyLen > 56 ) 00435 throw std::exception("Invalid key length used to initialize BlowFish."); 00436 00437 Pad ans = core::defaultPiPad; 00438 00439 // Load P boxes with key bytes, by xor-ing the entire array with key data (which is cycled through). 00440 unsigned char const* const keyBase = reinterpret_cast<const uint8*>(keyPtr); 00441 unsigned char const* const keyEnd = keyBase + keyLen; 00442 unsigned char const* keyScan = keyBase; 00443 uint32* boxScan = ans.P; 00444 uint32* const boxEnd = ans.P+18; 00445 do { 00446 uint32 word = 0; // need to work on a block-by-block basis, as endianness within the P buffer may vary 00447 for( unsigned i = 4 ; i ; --i ) 00448 { 00449 word = (word<<8) | *keyScan++; 00450 if( keyScan == keyEnd ) keyScan = keyBase; 00451 } 00452 *boxScan++ ^= word; 00453 } while( boxScan != boxEnd ); 00454 00455 // Use blowfish to reflectively scramble P and S boxes, while evolving the Blowfish pad. 00456 Block block(0,0); //zeroed start block 00457 uint32* scanPad = reinterpret_cast<uint32*>( &ans ); 00458 uint32* const endPad = reinterpret_cast<uint32*>( &ans + 1 ); 00459 do { 00460 block = core::encipherBlock( ans, block ); 00461 *scanPad++ = block.L; 00462 *scanPad++ = block.R; 00463 } while( scanPad != endPad ); 00464 00465 return ans; 00466 }
Returns a new block made of the xor-ed fields of a and b.
Definition at line 476 of file blowfish.cpp. 00477 { return Block( a.L ^ b.L , a.R ^ b.R ); }
|