summaryrefslogtreecommitdiff
path: root/src/skey/skey.c
blob: fde2d15caeb7810020c070cd79f487c15392c938 (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
35
36
37
38
39
#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "md4.h"
#include "md5.h"
#include "sha1.h"
#include "skey.h"
#include "btoe.h"

struct skey_hash
{
	int (*Keycrunch) (char *, const char *, const char *);
	void (*Skey) (char *);
};
static struct skey_hash hash_table[] =
{
	{ MD4Keycrunch,  MD4SKey },
	{ MD5Keycrunch,  MD5SKey },
	{ SHA1Keycrunch, SHA1SKey }
};


char *skey(SKeyAlgorithm algorithm, int seq, const char *seed, const char *passphrase)
{
	char key[SKEY_SIZE];
	int i;
	g_assert (algorithm < G_N_ELEMENTS (hash_table));
	if (hash_table[algorithm].Keycrunch(key, seed, passphrase) == -1)
		return NULL;

	for (i = 0; i < seq; i++)
		hash_table[algorithm].Skey(key);

	return strdup(btoe((unsigned char *)key));
}