summaryrefslogtreecommitdiff
path: root/kerberosIV/des/random_key.c
blob: cca29fb33a3018d1859197aabb6ffd48585ba2ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*	$Id: random_key.c,v 1.2 1995/12/17 19:12:05 tholo Exp $	*/

/* Copyright (C) 1992 Eric Young - see COPYING for more details */
#include "des_locl.h"

void des_random_key(ret)
des_cblock ret;
	{
	des_key_schedule ks;
	static u_int32_t c=0;
	static pid_t pid=0;
	static des_cblock data={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
	des_cblock key;

#ifdef MSDOS
	pid=1;
#else
	if (!pid) pid=getpid();
#endif
	((u_int32_t *)key)[0]=(u_int32_t)time(NULL);
	((u_int32_t *)key)[1]=(u_int32_t)((pid)|((c++)<<16));

	des_set_odd_parity((des_cblock *)data);
	des_set_key_schedule((des_cblock *)data,ks);
	des_cbc_cksum((des_cblock *)key,(des_cblock *)key,
		(int32_t)sizeof(key),ks,(des_cblock *)data);
	des_set_odd_parity((des_cblock *)key);
	des_cbc_cksum((des_cblock *)key,(des_cblock *)key,
		(int32_t)sizeof(key),ks,(des_cblock *)data);

	bcopy(key,ret,sizeof(key));
	bzero(key,sizeof(key));
	bzero(ks,sizeof(ks));
	}