Annotation of src/usr.bin/tcfs/gentcfskey.c, Revision 1.2
1.2 ! fgsch 1: /* $OpenBSD$ */
! 2:
1.1 provos 3: /*
4: * Transparent Cryptographic File System (TCFS) for NetBSD
5: * Author and mantainer: Luigi Catuogno [luicat@tcfs.unisa.it]
6: *
7: * references: http://tcfs.dia.unisa.it
8: * tcfs-bsd@tcfs.unisa.it
9: */
10:
11: /*
12: * Base utility set v0.1
13: */
14:
15: #include <stdio.h>
16: #include <sys/time.h>
17: #include <termios.h>
18: #include <unistd.h>
19: #include <stdlib.h>
20: #include <fcntl.h>
21: #include <err.h>
22: #include <md5.h>
23:
24: #include <miscfs/tcfs/tcfs.h>
25: #include "tcfsdefines.h"
26:
27: u_char *
28: gentcfskey (void)
29: {
30: u_char *buff;
31: MD5_CTX ctx, ctx2;
32: u_int32_t tmp[KEYSIZE];
33: u_char digest[16];
34: int i;
35:
36: buff = (u_char *)calloc(KEYSIZE + 1, sizeof(char));
37:
38: /* Generate random key */
39: for (i = 0; i < KEYSIZE; i ++)
40: tmp[i] = arc4random();
41:
42: MD5Init(&ctx);
43: for (i = 0; i < KEYSIZE; i += 16) {
44: MD5Update(&ctx, (u_char *)tmp, sizeof(tmp));
45: ctx2 = ctx;
46: MD5Final(digest, &ctx2);
47: memcpy(buff + i, digest, KEYSIZE - i > 16 ? 16 : KEYSIZE - i);
48: }
49: buff[KEYSIZE] = '\0';
50: memset(&ctx, 0, sizeof(ctx));
51:
52: return (buff);
53: }