tgen_salt.c - tomb - the crypto undertaker
 (HTM) git clone git://parazyd.org/tomb.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       tgen_salt.c (727B)
       ---
            1 #include <stdio.h>
            2 #include <stdlib.h>
            3 #include <string.h>
            4 
            5 void print_hex(unsigned char *buf, int len)
            6 {
            7   int i;
            8 
            9   for(i=0;i<len;i++){
           10     printf("%02x", buf[i]);
           11   }
           12 }
           13 
           14 int main(int argc, char **argv) {
           15         int len=32;
           16         int res;
           17         unsigned char *buf;
           18         FILE *rand;
           19         if(argc>=2) {
           20                 if(sscanf(argv[1], "%d", &len) != 1) {
           21                         fprintf(stderr, "Error: len must be an integer\n");
           22                         return 1;
           23                 }
           24         }
           25         buf = calloc(len, sizeof(char));
           26         memset(buf, 9, len);
           27         rand = fopen("/dev/random", "r");
           28         res = fread(buf, sizeof(char), len, rand);
           29         if( res != len) {
           30                 fprintf(stderr, "Error reading /dev/random: %d != %d, \n", res, len);
           31                 fclose(rand);
           32                 free(buf);
           33                 return 2;
           34         }
           35         fclose(rand);
           36         print_hex(buf, len);
           37         free(buf);
           38         return 0;
           39 }