summaryrefslogtreecommitdiff
authorplurSKI <black.gavin@gmail.com>2010-10-25 00:53:04 (GMT)
committer plurSKI <black.gavin@gmail.com>2010-10-25 00:53:04 (GMT)
commitd4362861790bfdca9e440ac78bc3e53ead90c8a1 (patch)
treec8ca331ed7228b62890b7c545fe01637ae2be3ef
downloadprngCompare-master.zip
prngCompare-master.tar.gz
Initial Commitmaster
-rw-r--r--aesRng.c64
-rw-r--r--clockDrift.c22
-rwxr-xr-xcompareScript26
-rw-r--r--makefile17
-rw-r--r--parseNumbers.c20
-rwxr-xr-xrandomScript19
-rw-r--r--xorFiles.c112
7 files changed, 280 insertions, 0 deletions
diff --git a/aesRng.c b/aesRng.c
new file mode 100644
index 0000000..50d22dd
--- a/dev/null
+++ b/aesRng.c
@@ -0,0 +1,64 @@
+/* aesrng.c - AES-based random number generator
+ *
+ * Copyright (c) 2009 Christopher Wellons <mosquitopsu@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for
+ * any purpose with or without fee is hereby granted, provided that
+ * the above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <gcrypt.h>
+
+int main (int argc, char **argv)
+{
+ size_t bytes = 1;
+ if (argc > 1)
+ bytes = atoi (argv[1]);
+
+ /* Initialize the cipher */
+ gcry_cipher_hd_t aes;
+ gcry_cipher_open(&aes, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CBC, 0);
+
+ /* Initialize the cipher key and iv */
+ char key[32], iv[16];
+ gcry_randomize (&key[0], 32, GCRY_STRONG_RANDOM);
+ gcry_create_nonce (&iv[0], 16);
+ gcry_cipher_setkey (aes, key, 32);
+ gcry_cipher_setiv (aes, iv, 16);
+
+ /* Initialize the counter */
+ unsigned char counter_iv[16];
+ gcry_create_nonce (&counter_iv[0], 16);
+ gcry_mpi_t counter = gcry_mpi_new (16);
+ gcry_mpi_scan (&counter, GCRYMPI_FMT_USG, &counter_iv[0], 16, NULL);
+
+ unsigned char in[16], out[16];
+ while (bytes)
+ {
+ gcry_mpi_add_ui (counter, counter, 1);
+ gcry_mpi_print (GCRYMPI_FMT_USG, &in[0], 16, NULL, counter);
+ gcry_cipher_encrypt (aes, &out[0], 16, &in[0], 16);
+
+ /* Print out the bytes. */
+ size_t nout = 16;
+ if (nout > bytes)
+ nout = bytes;
+ fwrite (&out[0], nout, 1, stdout);
+
+ bytes -= nout;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/clockDrift.c b/clockDrift.c
new file mode 100644
index 0000000..5cc6542
--- a/dev/null
+++ b/clockDrift.c
@@ -0,0 +1,22 @@
+#include<stdio.h>
+#include<time.h>
+
+#define TICKS_TO_WAIT 32
+
+int main( int argc, char** argv)
+{
+ int i;
+ int bytes = 1024;
+ unsigned long long counter = 1;
+ clock_t tick_old, tick_new;
+
+ if(argc > 1) bytes = atoi(argv[1]);
+ for( i = 0; i < bytes; i ++ )
+ {
+ tick_old = clock();
+ while(clock() < tick_old + TICKS_TO_WAIT) counter ++;
+ printf("%c", counter % 256);
+ }
+ return 0;
+}
+
diff --git a/compareScript b/compareScript
new file mode 100755
index 0000000..3fec98d
--- a/dev/null
+++ b/compareScript
@@ -0,0 +1,26 @@
+#!/bin/bash
+#This script only sorta works...it will properly make all the raw data
+# but randomly screws up calculations
+
+
+MAX_COUNT=20
+SIZE=1024
+
+PATH="$PATH:."
+COUNT=0
+
+mkdir rawData
+
+while [ $COUNT -lt $MAX_COUNT ]
+do
+ wget -q "http://www.random.org/integers/?num=$SIZE&min=0&max=255&col=1&base=10&format=plain&rnd=new" -O rawData/wget_unformatted$COUNT
+ parseNumbers rawData/wget_unformatted$COUNT > rawData/wget$COUNT
+ clockDrift $SIZE > rawData/clock$COUNT
+ aesRng $SIZE > rawData/aes$COUNT
+ cat /dev/random | head -c $SIZE > rawData/dev$COUNT
+ cat /dev/urandom | head -c $SIZE > rawData/urand$COUNT
+ xorFiles rawData/clock$COUNT rawData/clock$COUNT rawData/aes$COUNT rawData/dev$COUNT -n=$SIZE > rawData/owr$COUNT
+
+ COUNT=`expr $COUNT + 1`
+ echo "$COUNT of $MAX_COUNT"
+done
diff --git a/makefile b/makefile
new file mode 100644
index 0000000..024193f
--- a/dev/null
+++ b/makefile
@@ -0,0 +1,17 @@
+all: clockDrift xorFiles parseNumbers aesRng
+
+clockDrift: clockDrift.c
+ gcc -o clockDrift clockDrift.c
+
+xorFiles: xorFiles.c
+ gcc -o xorFiles xorFiles.c
+
+parseNumbers: parseNumbers.c
+ gcc -o parseNumbers parseNumbers.c
+
+aesRng: aesRng.c
+ gcc -o aesRng aesRng.c -lgcrypt
+
+clean:
+ rm clockDrift xorFiles aesRng parseNumbers
+
diff --git a/parseNumbers.c b/parseNumbers.c
new file mode 100644
index 0000000..81f39e4
--- a/dev/null
+++ b/parseNumbers.c
@@ -0,0 +1,20 @@
+#include<stdio.h>
+#include<stdlib.h>
+
+int main( int argc, char** argv )
+{
+ FILE* fp;
+ char tmp_str[16];
+
+ fp = fopen(argv[1], "r");
+ if( fp == NULL)
+ {
+ fprintf(stderr, "Could not open file: %s\n", argv[1]);
+ return -1;
+ }
+
+ while(fscanf(fp, "%s", tmp_str ) != EOF)
+ printf("%c", (unsigned char)(atoi(tmp_str)));
+
+ return 0;
+}
diff --git a/randomScript b/randomScript
new file mode 100755
index 0000000..79c9bce
--- a/dev/null
+++ b/randomScript
@@ -0,0 +1,19 @@
+#!/bin/bash
+PATH="$PATH:."
+
+if [ $# -lt "1" ]
+then
+ echo "Usage: $0 <num_bytes>"
+ exit
+fi
+
+wget -q "http://www.random.org/integers/?num=$1&min=0&max=255&col=1&base=10&format=plain&rnd=new" -O /tmp/wget_unformatted
+parseNumbers /tmp/wget_unformatted > /tmp/wget_rnd
+clockDrift $1 > /tmp/clock_rnd
+aesRng $1 > /tmp/aes_rnd
+xorFiles /tmp/clock_rnd /tmp/wget_rnd /tmp/aes_rnd /dev/random -n=$1
+
+shred -uzn 30 /tmp/wget_rnd
+shred -uzn 30 /tmp/wget_unformatted
+shred -uzn 30 /tmp/clock_rnd
+shred -uzn 30 /tmp/aes_rnd
diff --git a/xorFiles.c b/xorFiles.c
new file mode 100644
index 0000000..16b12af
--- a/dev/null
+++ b/xorFiles.c
@@ -0,0 +1,112 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
+#define TILL_EOF -1
+
+typedef enum { FALSE, TRUE } boolean;
+
+struct file_list
+{
+ FILE* fp;
+ struct file_list* next;
+};
+typedef struct file_list file_item;
+
+
+int main( int argc, char** argv )
+{
+ file_item *head = NULL;
+ file_item *curr = NULL;
+ int i;
+ char x, c;
+ int bytesOut = TILL_EOF; // Number of bytes to output
+ boolean printableOnly = FALSE;
+ boolean foundEOF = FALSE;
+
+ for( i = 0; i < argc; i ++ )
+ {
+ // Handle command line options
+ if ( strstr( argv[i], "-p") == argv[i] )
+ {
+ printableOnly = TRUE;
+ }
+ else if ( strstr( argv[i], "--help") == argv[i] )
+ {
+ printf("Usage: %s [-p] [-n=####] file1 file2 ... fileN\n-p == only display printable characters\n-n=#### number of bytes to output, if not specified then it will go till the first EOF is encountered\n");
+ return 0;
+ }
+ else if ( strstr( argv[i], "-n=" ) == argv[i] )
+ {
+ bytesOut = atoi(argv[i]+3);
+ }
+ else
+ {
+ // Open the file and store it in the linked list
+ curr = (file_item*) malloc(sizeof(file_item));
+ curr->fp = fopen(argv[i], "r");
+ if( curr->fp == NULL)
+ {
+ fprintf(stderr, "Could not open file: %s\n", argv[i]);
+ return -1;
+ }
+ curr->next = head;
+ head = curr;
+ }
+ }
+
+ // Start the xor of the files
+ while ( bytesOut != 0 )
+ {
+ if(bytesOut != TILL_EOF) bytesOut --;
+
+ // Step through every file
+ x = 0;
+ curr = head;
+ while(curr != NULL && curr->next != NULL)
+ {
+ // Must store in integer to catch EOF
+ i = fgetc(curr->fp);
+ c = (char)i;
+ if( i == EOF )
+ {
+ // If only going to the EOF quit
+ if( bytesOut == TILL_EOF )
+ {
+ curr = NULL;
+ bytesOut = 0;
+ foundEOF = TRUE; // Don't want to put the EOF it will screw up the filesize
+ continue;
+ }
+ else
+ {
+ rewind( curr->fp ); // Go back to the file's beginning
+ }
+ }
+ else
+ {
+ x ^= c;
+ }
+ curr = curr->next;
+ }
+
+ if( printableOnly == TRUE)
+ {
+ if( x >= 0x20 && x <= 0x7E) printf("%c", x);
+ else bytesOut ++; // Will need another byte
+ }
+ else if( foundEOF == FALSE )
+ {
+ printf("%c", x);
+ }
+
+ }
+
+ // Close open files
+ curr = head;
+ while( curr != NULL && curr->next != NULL )
+ {
+ fclose(curr->fp);
+ curr = curr->next;
+ }
+ return 0;
+}