[BACK]Return to gentcfskey.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tcfs

Annotation of src/usr.bin/tcfs/gentcfskey.c, Revision 1.4

1.4     ! fgsch       1: /*     $OpenBSD: gentcfskey.c,v 1.3 2000/06/19 23:06:24 aaron Exp $    */
1.2       fgsch       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:
1.4     ! fgsch      15: #include <sys/time.h>
        !            16: #include <err.h>
        !            17: #include <fcntl.h>
        !            18: #include <md5.h>
1.1       provos     19: #include <stdio.h>
1.4     ! fgsch      20: #include <stdlib.h>
1.1       provos     21: #include <termios.h>
                     22: #include <unistd.h>
                     23:
                     24: #include <miscfs/tcfs/tcfs.h>
                     25: #include "tcfsdefines.h"
                     26:
                     27: u_char *
1.3       aaron      28: gentcfskey(void)
1.1       provos     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: }