undo.1: Add some words about the new fake transaction id warning.
[dragonfly.git] / contrib / opie / libopie / hashlen.c
blob926e583c63ecb4da9851f084744af14cfa505dfd
1 /* hashlen.c: The opiehashlen() library function.
3 %%% copyright-cmetz-96
4 This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
5 The Inner Net License Version 3 applies to this software.
6 You should have received a copy of the license with this software. If
7 you didn't get a copy, you may request one from <license@inner.net>.
9 History:
11 Modified by cmetz for OPIE 2.4. Use struct opie_otpkey, isolate variables.
12 Created by cmetz for OPIE 2.3.
14 $FreeBSD: src/contrib/opie/libopie/hashlen.c,v 1.3.6.2 2002/07/15 14:48:47 des Exp $
15 $DragonFly: src/contrib/opie/libopie/hashlen.c,v 1.2 2003/06/17 04:24:05 dillon Exp $
18 #include "opie_cfg.h"
19 #include "opie.h"
21 #include <sha.h>
22 #include <md4.h>
23 #include <md5.h>
25 VOIDRET opiehashlen FUNCTION((algorithm, in, out, n), int algorithm AND
26 VOIDPTR in AND struct opie_otpkey *out AND int n)
28 UINT4 *results = (UINT4 *)out;
29 UINT4 mdx_tmp[4];
31 switch(algorithm) {
32 case 3: {
33 SHA_CTX sha;
34 UINT4 digest[5];
35 SHA1_Init(&sha);
36 SHA1_Update(&sha, (unsigned char *)in, n);
37 SHA1_Final((unsigned char *)digest, &sha);
38 results[0] = digest[0] ^ digest[2] ^ digest[4];
39 results[1] = digest[1] ^ digest[3];
40 break;
42 case 4: {
43 MD4_CTX mdx;
44 MD4Init(&mdx);
45 MD4Update(&mdx, (unsigned char *)in, n);
46 MD4Final((unsigned char *)mdx_tmp, &mdx);
47 results[0] = mdx_tmp[0] ^ mdx_tmp[2];
48 results[1] = mdx_tmp[1] ^ mdx_tmp[3];
49 break;
51 case 5: {
52 MD5_CTX mdx;
53 MD5Init(&mdx);
54 MD5Update(&mdx, (unsigned char *)in, n);
55 MD5Final((unsigned char *)mdx_tmp, &mdx);
56 results[0] = mdx_tmp[0] ^ mdx_tmp[2];
57 results[1] = mdx_tmp[1] ^ mdx_tmp[3];
58 break;