2 * Copyright (C) 2012-2015 Tobias Brunner
3 * Copyright (C) 2005-2006 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
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>.
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
22 ENUM_BEGIN(hash_algorithm_names
, HASH_SHA1
, HASH_SHA512
,
27 ENUM_NEXT(hash_algorithm_names
, HASH_UNKNOWN
, HASH_SHA3_512
, HASH_SHA512
,
37 ENUM_END(hash_algorithm_names
, HASH_SHA3_512
);
39 ENUM_BEGIN(hash_algorithm_short_names
, HASH_SHA1
, HASH_SHA512
,
44 ENUM_NEXT(hash_algorithm_short_names
, HASH_UNKNOWN
, HASH_SHA3_512
, HASH_SHA512
,
54 ENUM_END(hash_algorithm_short_names
, HASH_SHA3_512
);
57 * Described in header.
59 hash_algorithm_t
hasher_algorithm_from_oid(int oid
)
64 case OID_MD2_WITH_RSA
:
67 case OID_MD5_WITH_RSA
:
70 case OID_SHA1_WITH_RSA
:
73 case OID_SHA224_WITH_RSA
:
76 case OID_SHA256_WITH_RSA
:
79 case OID_SHA384_WITH_RSA
:
82 case OID_SHA512_WITH_RSA
:
98 * Described in header.
100 hash_algorithm_t
hasher_algorithm_from_prf(pseudo_random_function_t alg
)
107 case PRF_FIPS_SHA1_160
:
110 case PRF_HMAC_SHA2_256
:
112 case PRF_HMAC_SHA2_384
:
114 case PRF_HMAC_SHA2_512
:
117 case PRF_AES128_XCBC
:
118 case PRF_AES128_CMAC
:
120 case PRF_CAMELLIA128_XCBC
:
128 * Described in header.
130 hash_algorithm_t
hasher_algorithm_from_integrity(integrity_algorithm_t alg
,
137 case AUTH_HMAC_MD5_96
:
138 case AUTH_HMAC_SHA1_96
:
139 case AUTH_HMAC_SHA2_256_96
:
142 case AUTH_HMAC_MD5_128
:
143 case AUTH_HMAC_SHA1_128
:
144 case AUTH_HMAC_SHA2_256_128
:
147 case AUTH_HMAC_SHA1_160
:
150 case AUTH_HMAC_SHA2_384_192
:
153 case AUTH_HMAC_SHA2_256_256
:
154 case AUTH_HMAC_SHA2_512_256
:
157 case AUTH_HMAC_SHA2_384_384
:
160 case AUTH_HMAC_SHA2_512_512
:
169 case AUTH_HMAC_MD5_96
:
170 case AUTH_HMAC_MD5_128
:
173 case AUTH_HMAC_SHA1_96
:
174 case AUTH_HMAC_SHA1_128
:
175 case AUTH_HMAC_SHA1_160
:
177 case AUTH_HMAC_SHA2_256_96
:
178 case AUTH_HMAC_SHA2_256_128
:
179 case AUTH_HMAC_SHA2_256_256
:
181 case AUTH_HMAC_SHA2_384_192
:
182 case AUTH_HMAC_SHA2_384_384
:
184 case AUTH_HMAC_SHA2_512_256
:
185 case AUTH_HMAC_SHA2_512_512
:
187 case AUTH_AES_CMAC_96
:
188 case AUTH_AES_128_GMAC
:
189 case AUTH_AES_192_GMAC
:
190 case AUTH_AES_256_GMAC
:
191 case AUTH_AES_XCBC_96
:
193 case AUTH_CAMELLIA_XCBC_96
:
201 * Described in header.
203 integrity_algorithm_t
hasher_algorithm_to_integrity(hash_algorithm_t alg
,
212 return AUTH_HMAC_MD5_96
;
214 return AUTH_HMAC_MD5_128
;
221 return AUTH_HMAC_SHA1_96
;
223 return AUTH_HMAC_SHA1_128
;
225 return AUTH_HMAC_SHA1_160
;
232 return AUTH_HMAC_SHA2_256_96
;
234 return AUTH_HMAC_SHA2_256_128
;
236 return AUTH_HMAC_SHA2_256_256
;
243 return AUTH_HMAC_SHA2_384_192
;
245 return AUTH_HMAC_SHA2_384_384
;
253 return AUTH_HMAC_SHA2_512_256
;
255 return AUTH_HMAC_SHA2_512_512
;
268 return AUTH_UNDEFINED
;
272 * Described in header.
274 bool hasher_algorithm_for_ikev2(hash_algorithm_t alg
)
298 * Described in header.
300 int hasher_algorithm_to_oid(hash_algorithm_t alg
)
346 * Described in header.
348 int hasher_signature_algorithm_to_oid(hash_algorithm_t alg
, key_type_t key
)
356 return OID_MD2_WITH_RSA
;
358 return OID_MD5_WITH_RSA
;
360 return OID_SHA1_WITH_RSA
;
362 return OID_SHA224_WITH_RSA
;
364 return OID_SHA256_WITH_RSA
;
366 return OID_SHA384_WITH_RSA
;
368 return OID_SHA512_WITH_RSA
;
376 return OID_ECDSA_WITH_SHA1
;
378 return OID_ECDSA_WITH_SHA256
;
380 return OID_ECDSA_WITH_SHA384
;
382 return OID_ECDSA_WITH_SHA512
;
390 return OID_BLISS_WITH_SHA2_256
;
392 return OID_BLISS_WITH_SHA2_384
;
394 return OID_BLISS_WITH_SHA2_512
;
396 return OID_BLISS_WITH_SHA3_256
;
398 return OID_BLISS_WITH_SHA3_384
;
400 return OID_BLISS_WITH_SHA3_512
;
412 hash_algorithm_t
hasher_from_signature_scheme(signature_scheme_t scheme
)
417 case SIGN_RSA_EMSA_PKCS1_NULL
:
418 case SIGN_ECDSA_WITH_NULL
:
420 case SIGN_RSA_EMSA_PKCS1_MD5
:
422 case SIGN_RSA_EMSA_PKCS1_SHA1
:
423 case SIGN_ECDSA_WITH_SHA1_DER
:
425 case SIGN_RSA_EMSA_PKCS1_SHA224
:
427 case SIGN_RSA_EMSA_PKCS1_SHA256
:
428 case SIGN_ECDSA_WITH_SHA256_DER
:
430 case SIGN_BLISS_WITH_SHA2_256
:
431 case SIGN_BLISS_WITH_SHA3_256
:
433 case SIGN_RSA_EMSA_PKCS1_SHA384
:
434 case SIGN_ECDSA_WITH_SHA384_DER
:
436 case SIGN_BLISS_WITH_SHA2_384
:
437 case SIGN_BLISS_WITH_SHA3_384
:
439 case SIGN_RSA_EMSA_PKCS1_SHA512
:
440 case SIGN_ECDSA_WITH_SHA512_DER
:
442 case SIGN_BLISS_WITH_SHA2_512
:
443 case SIGN_BLISS_WITH_SHA3_512
: