/* SBox8: 8 bit Pseudo-Random Number Generator Algorithm/Source Code */ /* Copyright(c) 2015, Karl-Uwe Frank All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #** SBox8 algorithm designed and developed by Karl-Uwe Frank 06.01.2016: Update of the Shifting Function inside SBox8_PIA thanks to the recommendation of Bob Harris on sci.crpyt */ //********************************************************************** //----------------------------------------- // // rm -f ./SBox8_keystream; gcc -std=c99 -O3 -fomit-frame-pointer -mtune=native SBox8_keystream.c -o SBox8_keystream // // Usage: // ./SBox8_keystream seed key out_size-in-64bit > SBox8_keystream_out.bin // // ./SBox8_keystream 0x2ddd6a2c 0c8c8279b04c4430d69a6454d069458e 256 > SBox8_keystream_out.bin // // ./SBox8_keystream 0xdeadbeef 04c7a580a0c8e7bf7ec5a0c9aef63c81 1024000 > SBox8_keystream_out.bin // //----------------------------------------- // // ./SBox8_keystream 00f75bce 50617373776f7264 16 | xxd -g 1 // // 0000000: d2 89 ea 66 f9 01 33 56 ca e8 d5 4f e0 72 49 e8 // //----------------------------------------- // // ./SBox8_keystream 0 00 10000000 > SBox8_keystream_out.bin // // dieharder -a -g 201 -f SBox8_keystream_out.bin #include #include #include #include // needed to generate uint32 on a 64bit OS #include /////////////////////////////////////////// #define swap(X,Y) { uint8_t T = X; X = Y; Y = T; } int main (int argc, char *argv[]) { uint8_t a, b, c, d, j, t, out_8bit; uint8_t SBox[256]; uint32_t seed; uint64_t output_size, i; // Check if a Seed is passed through if (argc < 4) { fprintf(stderr,"\nError: seed (hex in format) value can be < 0x%08x and > 0x0", 0xffffffff); fprintf(stderr,"\n key (hex in format) > 00\n"); fprintf(stderr,"\n and size of output must be > 0 and max. 64bit\n\n"); return 1; } seed = (int)strtoul(argv[1], NULL, 16); output_size = (uint64_t)strtoul(argv[3], NULL, 0); if (output_size == 0) { fprintf(stderr,"\nError: size of output must be > 0 and max. 64bit\n\n"); exit(1); } if (seed == 0) { a = 14; b = 59; c = 23; d = 77; } else { a = ( seed & 0xff); b = ((seed >> 8) & 0xff); c = ((seed >> 16) & 0xff); d = ((seed >> 24) & 0xff); } // We have a key uint8_t key[256]; uint8_t keyLen; uint8_t hexKey[256]; uint8_t hex[3]; // Make sure the arrays get initialised properly // and wipe out anything which might be there memset(key, 0, 256); memset(hexKey, 0, 256); memset(hex, 0, 3); // Rebuild key[] from KeyHash strncpy(hexKey, argv[2], strlen(argv[2])); keyLen = strlen(hexKey); hexKey[keyLen] = 0; keyLen = keyLen/2; for (uint16_t i=0; i