[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.1

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