00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Rafal Jaroszkiewicz 00008 * Side Effects Software Inc 00009 * 123 Front Street West, Suite 1401 00010 * Toronto, Ontario 00011 * Canada M5J 2M2 00012 * 416-504-9876 00013 * 00014 * NAME: UT_Blowfish.h ( Library, C++) 00015 * 00016 * COMMENTS: 00017 * Based on a free source code from: 00018 * http://www.schneier.com/blowfish.html 00019 * http://www.schneier.com/blowfish-download.html 00020 * 00021 * blowfish.h interface file for blowfish.cpp 00022 * _THE BLOWFISH ENCRYPTION ALGORITHM_ 00023 * by Bruce Schneier 00024 * Revised code--3/20/94 00025 * Converted to C++ class 5/96, Jim Conger 00026 */ 00027 00028 #ifndef __UT_Blowfish__ 00029 #define __UT_Blowfish__ 00030 00031 #include "UT_API.h" 00032 #include <SYS/SYS_Types.h> 00033 00034 00035 // the size of the s-box used by the blofish: 00036 #define UT_BLOWFISH_SBOX_SIZE 256 00037 00038 00039 class UT_API UT_Blowfish 00040 { 00041 public: 00042 // Construct an encryptor/decryptor object with a given secret key. 00043 UT_Blowfish( const uint8 key[], int key_size ); 00044 ~UT_Blowfish() ; 00045 00046 // Get output cipher length given the input message length. The output 00047 // cipher length must be divisible by 8 because it consists of 64-bit blocks 00048 // (8 bytes x 8 bits = 64 bit block). 00049 static int getEncryptionOutputSize( int input_size ); 00050 00051 // Gets the maximum data chunk size on which the algorithm can work and that 00052 // is no larger than the specifies 'max_buffer_size'. This is a convenience 00053 // method that returns the size that is the multiple of the block size. 00054 static int getCryptBufferSize( int max_buffer_size ); 00055 00056 // Gets the block size. The alogrithm will work on sizes that are multiples 00057 // of the block size. 00058 static int getBlockSize(); 00059 00060 // Eencrypt input into output. Input length is input_size. Returned value 00061 // is length of output (which will be divisible by 8 bytes). 00062 // Input and output buffers can be the same, but be sure buffer length 00063 // is divisible by 8, so that it can contain the output cipher. 00064 int encrypt( const uint8 * input, uint8 * output, 00065 int input_size ); 00066 00067 // Decrypt input into output. Input length in input_size (and is divisible 00068 // by 8, since it contains a number of 64-bit (8-byte) blocks). 00069 // Input and output buffer can be the same. The length of output buffer must 00070 // be the same as (or larger than) the input buffer. The amount of data 00071 // in the output buffer is the same as 'input_size'. 00072 // Returns true if all is OK; false if errors occured 00073 bool decrypt( const uint8 * input, uint8 * output, 00074 int input_size ); 00075 00076 00077 private: 00078 // Constructs the enctryption sieve using the secret key. 00079 void initialize( const uint8 key[], int key_size ); 00080 00081 // Encrypts the 64-bit block that has been split into left and right 32-bit 00082 // halves. The encrypted cipher replaces the original data in the block. 00083 void encipherBlock( uint32 *xl, uint32 *xr ); 00084 00085 // Decrypts the 64-bit block that has been split into left and right 32-bit 00086 // halves. The decrypted text replaces the original cipher in the block. 00087 void decipherBlock( uint32 *xl, uint32 *xr ); 00088 00089 // Encrypts the 64-bit block from the input source into the destination 00090 // output. The source and destination can be the same. The pointers 00091 // point to an 8-byte (64-bit) memory chunk. 00092 void encipherBlock( const uint8 *input, uint8 *output ); 00093 00094 // Decrypts the 64-bit block from the input source into the destination 00095 // output. The source and destination can be the same. The pointers 00096 // point to an 8-byte (64-bit) memory chunk. 00097 void decipherBlock( const uint8 *input, uint8 *output ); 00098 00099 // Array (p-array) containing the subkeys used for xor'ing block's xL half. 00100 uint32 *myPArray; 00101 00102 // Lookup tables (S-boxes) that implement non-reversible function F. 00103 uint32 (*mySBoxes)[ UT_BLOWFISH_SBOX_SIZE ]; 00104 }; 00105 00106 #endif // __UT_Blowfish__ 00107 00108 00109
1.5.9