Crypt-Twofish2

 view release on metacpan or  search on metacpan

platform.h  view on Meta::CPAN

/* BYTEORDER comes from perl's config.h */
#if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678 || defined(__LITTLE_ENDIAN__) 
#define		LittleEndian			1
#define		Bswap(x)			(x)		/* NOP for little-endian machines */
#define		ADDR_XOR			0		/* NOP for little-endian machines */
#else
#define		Bswap(x)			((ROR(x,8) & 0xFF00FF00) | (ROL(x,8) & 0x00FF00FF))
#define		ADDR_XOR			3		/* convert byte address in dword */
#endif

/*	Macros for extracting bytes from dwords (correct for endianness) */
#define	_b(x,N)	(((BYTE *)&x)[((N) & 3) ^ ADDR_XOR]) /* pick bytes out of a dword */

#define		b0(x)			_b(x,0)		/* extract LSB of DWORD */
#define		b1(x)			_b(x,1)
#define		b2(x)			_b(x,2)
#define		b3(x)			_b(x,3)		/* extract MSB of DWORD */

#endif

table.h  view on Meta::CPAN

   g(x) = x**4 + (a + 1/a) x**3 + a x**2 + (a + 1/a) x + 1
   where a = primitive root of field generator 0x14D */
#define	RS_GF_FDBK		0x14D	/* field generator */
#define	RS_rem(x)		\
	{ BYTE  b  = (BYTE) (x >> 24);											 \
	  DWORD g2 = ((b << 1) ^ ((b & 0x80) ? RS_GF_FDBK : 0 )) & 0xFF;		 \
	  DWORD g3 = ((b >> 1) & 0x7F) ^ ((b & 1) ? RS_GF_FDBK >> 1 : 0 ) ^ g2 ; \
	  x = (x << 8) ^ (g3 << 24) ^ (g2 << 16) ^ (g3 << 8) ^ b;				 \
	}

/*      Macros for the MDS matrix
   *    The MDS matrix is (using primitive polynomial 169):
   *      01  EF  5B  5B
   *      5B  EF  EF  01
   *      EF  5B  01  EF
   *      EF  01  EF  5B
   *----------------------------------------------------------------
   * More statistical properties of this matrix (from MDS.EXE output):
   *
   * Min Hamming weight (one byte difference) =  8. Max=26.  Total =  1020.
   * Prob[8]:      7    23    42    20    52    95    88    94   121   128    91

twofish.c  view on Meta::CPAN

typedef int cdecl KeySetupProc(keyInstance *key);

extern CipherProc   *blockEncrypt_86;   /* ptr to ASM functions */
extern CipherProc   *blockDecrypt_86;
extern KeySetupProc *reKey_86;
extern DWORD        cdecl TwofishAsmCodeSize(void);
#endif

/*
+*****************************************************************************
*           Constants/Macros/Tables
-****************************************************************************/

#define     CONST                   /* help syntax from C++, NOP here */

static CONST       fullSbox MDStab;        /* not actually const.  Initialized ONE time */
static int         needToBuildMDS=1;       /* is MDStab initialized yet? */

#define     BIG_TAB     0

#if BIG_TAB



( run in 0.767 second using v1.01-cache-2.11-cpan-49f99fa48dc )