1 /*
2 chronyd/chronyc - Programs for keeping computer clocks accurate.
3
4 **********************************************************************
5 * Copyright (C) Miroslav Lichvar 2012
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 **********************************************************************
21
22 =======================================================================
23
24 Routines implementing crypto hashing using internal MD5 implementation.
25
26 */
27
28 #include "config.h"
29 #include "sysincl.h"
30 #include "hash.h"
31 #include "memory.h"
32 #include "util.h"
33
34 #include "md5.c"
35
36 static MD5_CTX ctx;
37
38 int
HSH_GetHashId(HSH_Algorithm algorithm)39 HSH_GetHashId(HSH_Algorithm algorithm)
40 {
41 /* only MD5 is supported */
42 if (algorithm != HSH_MD5 && algorithm != HSH_MD5_NONCRYPTO)
43 return -1;
44
45 return 0;
46 }
47
48 int
HSH_Hash(int id,const void * in1,int in1_len,const void * in2,int in2_len,unsigned char * out,int out_len)49 HSH_Hash(int id, const void *in1, int in1_len, const void *in2, int in2_len,
50 unsigned char *out, int out_len)
51 {
52 if (in1_len < 0 || in2_len < 0 || out_len < 0)
53 return 0;
54
55 MD5Init(&ctx);
56 MD5Update(&ctx, in1, in1_len);
57 if (in2)
58 MD5Update(&ctx, in2, in2_len);
59 MD5Final(&ctx);
60
61 out_len = MIN(out_len, 16);
62
63 memcpy(out, ctx.digest, out_len);
64
65 return out_len;
66 }
67
68 void
HSH_Finalise(void)69 HSH_Finalise(void)
70 {
71 }
72