updated Doxyfile
[strongswan.git] / src / libstrongswan / crypto / hashers / hasher.c
1 /*
2 * Copyright (C) 2005 Jan Hutter
3 * Copyright (C) 2005-2006 Martin Willi
4 *
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * $Id$
18 */
19
20 #include "hasher.h"
21
22 #include <asn1/oid.h>
23
24 ENUM(hash_algorithm_names, HASH_UNKNOWN, HASH_MD4,
25 "HASH_UNKNOWN",
26 "HASH_PREFERRED",
27 "HASH_MD2",
28 "HASH_MD5",
29 "HASH_SHA1",
30 "HASH_SHA256",
31 "HASH_SHA384",
32 "HASH_SHA512",
33 "HASH_MD4"
34 );
35
36 /*
37 * Described in header.
38 */
39 hash_algorithm_t hasher_algorithm_from_oid(int oid)
40 {
41 switch (oid)
42 {
43 case OID_MD2:
44 case OID_MD2_WITH_RSA:
45 return HASH_MD2;
46 case OID_MD5:
47 case OID_MD5_WITH_RSA:
48 return HASH_MD5;
49 case OID_SHA1:
50 case OID_SHA1_WITH_RSA:
51 return HASH_SHA1;
52 case OID_SHA256:
53 case OID_SHA256_WITH_RSA:
54 return HASH_SHA256;
55 case OID_SHA384:
56 case OID_SHA384_WITH_RSA:
57 return HASH_SHA384;
58 case OID_SHA512:
59 case OID_SHA512_WITH_RSA:
60 return HASH_SHA512;
61 default:
62 return HASH_UNKNOWN;
63 }
64 }
65
66 /*
67 * Described in header.
68 */
69 int hasher_algorithm_to_oid(hash_algorithm_t alg)
70 {
71 int oid;
72
73 switch (alg)
74 {
75 case HASH_MD2:
76 oid = OID_MD2;
77 break;
78 case HASH_MD5:
79 oid = OID_MD5;
80 break;
81 case HASH_SHA1:
82 oid = OID_SHA1;
83 break;
84 case HASH_SHA256:
85 oid = OID_SHA256;
86 break;
87 case HASH_SHA384:
88 oid = OID_SHA384;
89 break;
90 case HASH_SHA512:
91 oid = OID_SHA512;
92 break;
93 default:
94 oid = OID_UNKNOWN;
95 }
96 return oid;
97 }
98
99 /*
100 * Described in header.
101 */
102 int hasher_signature_algorithm_to_oid(hash_algorithm_t alg)
103 {
104 int oid;
105
106 switch (alg)
107 {
108 case HASH_MD2:
109 oid = OID_MD2_WITH_RSA;
110 break;
111 case HASH_MD5:
112 oid = OID_MD5_WITH_RSA;
113 break;
114 case HASH_SHA1:
115 oid = OID_SHA1_WITH_RSA;
116 break;
117 case HASH_SHA256:
118 oid = OID_SHA256_WITH_RSA;
119 break;
120 case HASH_SHA384:
121 oid = OID_SHA384_WITH_RSA;
122 break;
123 case HASH_SHA512:
124 oid = OID_SHA512_WITH_RSA;
125 break;
126 default:
127 oid = OID_UNKNOWN;
128 }
129 return oid;
130 }
131