check hash algorithms used in signatures

This commit is contained in:
Andreas Steffen
2007-09-11 20:10:38 +00:00
parent dd968b9b20
commit 2f9f5149c4
8 changed files with 194 additions and 148 deletions
+42 -1
View File
@@ -24,12 +24,14 @@
#include "hasher.h"
#include <asn1/oid.h>
#include <crypto/hashers/sha1_hasher.h>
#include <crypto/hashers/sha2_hasher.h>
#include <crypto/hashers/md5_hasher.h>
ENUM(hash_algorithm_names, HASH_MD2, HASH_SHA512,
ENUM(hash_algorithm_names, HASH_UNKNOWN, HASH_SHA512,
"HASH_UNKNOWN",
"HASH_MD2",
"HASH_MD5",
"HASH_SHA1",
@@ -63,3 +65,42 @@ hasher_t *hasher_create(hash_algorithm_t hash_algorithm)
return NULL;
}
}
/*
* Described in header.
*/
hash_algorithm_t hasher_algorithm_from_oid(int oid)
{
hash_algorithm_t algorithm;
switch (oid)
{
case OID_MD2:
case OID_MD2_WITH_RSA:
algorithm = HASH_MD2;
break;
case OID_MD5:
case OID_MD5_WITH_RSA:
algorithm = HASH_MD5;
break;
case OID_SHA1:
case OID_SHA1_WITH_RSA:
algorithm = HASH_SHA1;
break;
case OID_SHA256:
case OID_SHA256_WITH_RSA:
algorithm = HASH_SHA256;
break;
case OID_SHA384:
case OID_SHA384_WITH_RSA:
algorithm = HASH_SHA384;
break;
case OID_SHA512:
case OID_SHA512_WITH_RSA:
algorithm = HASH_SHA512;
break;
default:
algorithm = HASH_UNKNOWN;
}
return algorithm;
}
+19 -7
View File
@@ -42,17 +42,18 @@ typedef struct hasher_t hasher_t;
* @ingroup hashers
*/
enum hash_algorithm_t {
HASH_MD2 = 0,
HASH_UNKNOWN = 0,
HASH_MD2 = 1,
/** Implemented in class md5_hasher_t */
HASH_MD5 = 1,
HASH_MD5 = 2,
/** Implemented in class sha1_hasher_t */
HASH_SHA1 = 2,
HASH_SHA1 = 3,
/** Implemented in class sha2_hasher_t */
HASH_SHA256 = 3,
HASH_SHA256 = 4,
/** Implemented in class sha2_hasher_t */
HASH_SHA384 = 4,
HASH_SHA384 = 5,
/** Implemented in class sha2_hasher_t */
HASH_SHA512 = 5,
HASH_SHA512 = 6,
};
#define HASH_SIZE_MD2 16
@@ -68,7 +69,6 @@ enum hash_algorithm_t {
*/
extern enum_name_t *hash_algorithm_names;
/**
* @brief Generic interface for all hash functions.
*
@@ -156,4 +156,16 @@ struct hasher_t {
*/
hasher_t *hasher_create(hash_algorithm_t hash_algorithm);
/**
* @brief Conversion of ASN.1 OID to hash algorithm.
*
* @param oid ASN.1 OID
* @return
* - hash algorithm
* - HASH_UNKNOWN if OID unsuported
*
* @ingroup hashers
*/
hash_algorithm_t hasher_algorithm_from_oid(int oid);
#endif /* HASHER_H_ */