coffin

secure lan file storage on a device
git clone git://parazyd.org/coffin.git
Log | Files | Refs | Submodules | README | LICENSE

tomb-kdb-pbkdf2-gensalt.c (722B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 void
      6 print_hex(unsigned char *buf, int len) {
      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 }