"Fossies" - the Fresh Open Source Software Archive

Member "src/Crypto/Twofish.h" (10 Oct 2018, 1755 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Twofish.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.21_Source_vs_1.22_Source.

    1 #ifndef TWOFISH_H
    2 #define TWOFISH_H
    3 
    4 #include "Common/Tcdefs.h"
    5 #include "config.h"
    6 
    7 #if defined(__cplusplus)
    8 extern "C"
    9 {
   10 #endif
   11 
   12 #ifndef u4byte
   13 #define u4byte  unsigned __int32
   14 #endif
   15 #ifndef u1byte
   16 #define u1byte  unsigned char
   17 #endif
   18 
   19 #ifndef extract_byte
   20 #define extract_byte(x,n)   ((u1byte)((x) >> (8 * n)))
   21 #endif
   22 
   23 #ifndef rotl
   24 
   25 #ifdef _WIN32
   26 #include <stdlib.h>
   27 #pragma intrinsic(_lrotr,_lrotl)
   28 #define rotr(x,n) _lrotr(x,n)
   29 #define rotl(x,n) _lrotl(x,n)
   30 #else
   31 #define rotr(x,n) (((x)>>(n))|((x)<<(32-(n))))
   32 #define rotl(x,n) (((x)<<(n))|((x)>>(32-(n))))
   33 #endif
   34 
   35 #endif
   36 typedef struct
   37 {
   38 #if CRYPTOPP_BOOL_X64
   39    u4byte mk_tab[4][256], w[8], k[32];
   40 #else
   41     u4byte l_key[40];
   42 #ifdef TC_MINIMIZE_CODE_SIZE
   43     u4byte s_key[4];
   44 #ifdef TC_WINDOWS_BOOT_TWOFISH
   45     u4byte mk_tab[4 * 256];
   46 #endif
   47 #else
   48    u4byte mk_tab[4][256];
   49 #endif
   50 #endif
   51 } TwofishInstance;
   52 
   53 #define TWOFISH_KS      sizeof(TwofishInstance)
   54 
   55 /* in_key must be 32-bytes long */
   56 void twofish_set_key(TwofishInstance *instance, const u4byte in_key[]);
   57 #if CRYPTOPP_BOOL_X64
   58 void twofish_encrypt_blocks(TwofishInstance *instance, const byte* in_blk, byte* out_blk, uint32 blockCount);
   59 void twofish_decrypt_blocks(TwofishInstance *instance, const byte* in_blk, byte* out_blk, uint32 blockCount);
   60 #define twofish_encrypt(instance,in_blk,out_blk)   twofish_encrypt_blocks(instance, (const byte*) in_blk, (byte*) out_blk, 1)
   61 #define twofish_decrypt(instance,in_blk,out_blk)   twofish_decrypt_blocks(instance, (const byte*) in_blk, (byte*) out_blk, 1)
   62 #else
   63 void twofish_encrypt(TwofishInstance *instance, const u4byte in_blk[4], u4byte out_blk[4]);
   64 void twofish_decrypt(TwofishInstance *instance, const u4byte in_blk[4], u4byte out_blk[4]);
   65 #endif
   66 
   67 #if defined(__cplusplus)
   68 }
   69 #endif
   70 
   71 #endif // TWOFISH_H