// PureNoise CryptoLib (c) 1997-2004, PureNoise Ltd Vaduz // Ruptor's Chaos (Six-In-One) Package Version 0.9 (strongly recommended over any HASH or PRNG or linear block chaining) definition file #ifndef _crypto_chaos_h_ #define _crypto_chaos_h_ #include #ifndef $_chaos_prng #define $_chaos_prng typedef struct _chaos_prng { unsigned long *state; unsigned long state_words; unsigned long X,Y,Z,K; } chaos_prng; #endif /// Effectively one full round of CHAOS-32 cipher / hash / non-linear chaining function. /// /// TODO: Develop 64 bit attach/detach functions for this project to provide optimum speed*security performance. /// /// Every bit of Y must depend on all the bits of X, all the bits of Z, all the bits of K, and at least 1 bit of Y /// Y dependancy on X, Z and K must be irreversible and collision resistant /// more than one keystream word is allowed /// Maximum 512 clocks per 16 subsequent 64 bit attach calls; less than 256 clocks preferred /// One attach call must pass all the DIEHARD randomness tests for: /// /// 1) constant X, Y, Z, variable K (both incremental and 1-bit difference) /// 2) constant X, Y, K, variable Z (both incremental and 1-bit difference) /// 3) constant K, Y, Z, variable X (both incremental and 1-bit difference) static __forceinline unsigned long attach32 (unsigned long x, const unsigned long y, unsigned long z, unsigned long k) { unsigned long a, c; x += 0xC4A60B29, z += 0x1DF6907A, k += 0xE5F8D137; c = ((k + x) ^ z) | 1; a = bswap32 (x * c) ^ z; c = ((c + a) ^ k) | 1; a = bswap32 (a * c) ^ k; c = ((c + a) ^ x) | 1; a = bswap32 (a * c); return bswap32 ((rotl32 (y ^ a, c) + 0x86C02E59) * 0xD37AF41B); } static __forceinline unsigned long detach32 (unsigned long x, const unsigned long y, unsigned long z, unsigned long k) { unsigned long a, c; x += 0xC4A60B29, z += 0x1DF6907A, k += 0xE5F8D137; c = ((k + x) ^ z) | 1; a = bswap32 (x * c) ^ z; c = ((c + a) ^ k) | 1; a = bswap32 (a * c) ^ k; c = ((c + a) ^ x) | 1; a = bswap32 (a * c); return rotr32 (bswap32 (y) * 0xA269C613 + 0x793FD1A7, c) ^ a; } /// block cipher encryption function for blocks of data of any size /// can be also used as a hash function with data being the constant-initialized hash and key being the input /// can be also used as a MAC function with data being the key-initialized hash and key being the keyed input /// the total number of rounds is 3 times max (data_words, key_words, 17) EXTERN void chaos_block (unsigned long *data, const unsigned long data_words, const unsigned long *key, const unsigned long key_words); /// block cipher decryption function EXTERN void order_block (unsigned long *data, const unsigned long data_words, const unsigned long *key, const unsigned long key_words); /// a hassle-free fast True Random Number Generator EXTERN unsigned long rand32 (void); /// a hassle-free slow cryptographically secure True Random Large Number Generator EXTERN void big_rand (unsigned long *x, const unsigned long words); /// a Stream Cipher with data being its internal state generated by pseudo_chaos_init EXTERN unsigned long chaos_rand32 (chaos_prng *prng, const unsigned long *key, const unsigned long key_words); /// Stream Cipher (PRNG) Initialization (called automatically by rand32) EXTERN void pseudo_chaos_init (chaos_prng *prng, const unsigned long *key, const unsigned long key_words, const unsigned long incremental); /// a hassle-free RNG initialization function (called automatically by chaos_rand32) EXTERN void chaos_init (void); #endif // _crypto_chaos_h_