Retail products


Traffic interception SDK

Control every TCP/IP network connection

  • Route connections via proxy
  • Redirect connections and modify the data
  • Block connections and applications
SSL interception SDK

View SSL in plaintext and modify it

  • View the SSL stream decrypted in plaintext
  • Redirect SSL connection and modify decrypted data
  • Browser shows "SSL lock" without warnings

Documentation


blowfish Namespace Reference


Namespaces

namespace  core
 Low-level utilities - for advanced users only.

Classes

struct  Block
 Unit of encryption. Block of data processed together during an encryption cycle. More...
struct  Pad
 Data pad used for encryption. Pseudo-random block used to have varying encryption results. More...

Typedefs

typedef core::BlockIterator DIter
 Iterator used to traverse data in all encryption routines below.

Enumerations

enum  { kBlockSize = 2*4 }
 Source and destination data sizes must be multiples of this value. More...

Functions

Pad generatePad (void const *keyPtr, int keyLen)
 Returns an encription pad generated using the specified key/password.
Block operator^ (Block const &a, Block const &b)
 Returns a new block made of the xor-ed fields of a and b.
void encrypt_ECB (Pad const &pad, void const *src, void *dst, size_t byteSize)
void decrypt_ECB (Pad const &pad, void const *src, void *dst, size_t byteSize)
void encrypt_CBC (Pad const &pad, void const *src, void *dst, size_t byteSize, Block *pChain)
void decrypt_CBC (Pad const &pad, void const *src, void *dst, size_t byteSize, Block *pChain)
void encrypt_CFB (Pad const &pad, void const *src, void *dst, size_t byteSize, Block *pChain)
void decrypt_CFB (Pad const &pad, void const *src, void *dst, size_t byteSize, Block *pChain)

Typedef Documentation

typedef core::BlockIterator blowfish::DIter

Iterator used to traverse data in all encryption routines below.

Definition at line 471 of file blowfish.cpp.


Enumeration Type Documentation

anonymous enum

Source and destination data sizes must be multiples of this value.

Enumerator:
kBlockSize 

Definition at line 24 of file blowfish.h.

00024 { kBlockSize = 2*4 }; ///< two 4-byte words.


Function Documentation

void blowfish::decrypt_CBC ( Pad const &  pad,
void const *  src,
void *  dst,
size_t  byteSize,
Block pChain 
)

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 }

void blowfish::decrypt_CFB ( Pad const &  pad,
void const *  src,
void *  dst,
size_t  byteSize,
Block pChain 
)

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 }

void blowfish::decrypt_ECB ( Pad const &  pad,
void const *  src,
void *  dst,
size_t  byteSize 
)

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 }

void blowfish::encrypt_CBC ( Pad const &  pad,
void const *  src,
void *  dst,
size_t  byteSize,
Block pChain 
)

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 }

void blowfish::encrypt_CFB ( Pad const &  pad,
void const *  src,
void *  dst,
size_t  byteSize,
Block pChain 
)

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 }

void blowfish::encrypt_ECB ( Pad const &  pad,
void const *  src,
void *  dst,
size_t  byteSize 
)

Encryption Modes
  • ECB : Direct encryption of independent blocks (no data chaining).
  • CBC : Encrypt after xor-ing source with previous encrypted result.
  • CFB : Destination is source xor-ed with encrypted previous result.

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 }

Pad blowfish::generatePad ( void const *const   keyPtr,
int const   keyLen 
)

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 }

Block blowfish::operator^ ( Block const &  a,
Block const &  b 
) [inline]

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 ); }