extended hasher_signature_algorithm_to_oid() function

This commit is contained in:
Andreas Steffen
2009-09-13 21:41:51 +02:00
parent ba274c2343
commit 210d287368
5 changed files with 47 additions and 76 deletions
+37 -27
View File
@@ -104,36 +104,46 @@ int hasher_algorithm_to_oid(hash_algorithm_t alg)
/*
* Described in header.
*/
int hasher_signature_algorithm_to_oid(hash_algorithm_t alg)
int hasher_signature_algorithm_to_oid(hash_algorithm_t alg, key_type_t key)
{
int oid;
switch (alg)
switch (key)
{
case HASH_MD2:
oid = OID_MD2_WITH_RSA;
break;
case HASH_MD5:
oid = OID_MD5_WITH_RSA;
break;
case HASH_SHA1:
oid = OID_SHA1_WITH_RSA;
break;
case HASH_SHA224:
oid = OID_SHA224_WITH_RSA;
break;
case HASH_SHA256:
oid = OID_SHA256_WITH_RSA;
break;
case HASH_SHA384:
oid = OID_SHA384_WITH_RSA;
break;
case HASH_SHA512:
oid = OID_SHA512_WITH_RSA;
break;
case KEY_RSA:
switch (alg)
{
case HASH_MD2:
return OID_MD2_WITH_RSA;
case HASH_MD5:
return OID_MD5_WITH_RSA;
case HASH_SHA1:
return OID_SHA1_WITH_RSA;
case HASH_SHA224:
return OID_SHA224_WITH_RSA;
case HASH_SHA256:
return OID_SHA256_WITH_RSA;
case HASH_SHA384:
return OID_SHA384_WITH_RSA;
case HASH_SHA512:
return OID_SHA512_WITH_RSA;
default:
return OID_UNKNOWN;
}
case KEY_ECDSA:
switch (alg)
{
case HASH_SHA1:
return OID_ECDSA_WITH_SHA1;
case HASH_SHA256:
return OID_ECDSA_WITH_SHA256;
case HASH_SHA384:
return OID_ECDSA_WITH_SHA384;
case HASH_SHA512:
return OID_ECDSA_WITH_SHA512;
default:
return OID_UNKNOWN;
}
default:
oid = OID_UNKNOWN;
return OID_UNKNOWN;
}
return oid;
}
+3 -1
View File
@@ -27,6 +27,7 @@ typedef enum hash_algorithm_t hash_algorithm_t;
typedef struct hasher_t hasher_t;
#include <library.h>
#include <credentials/keys/public_key.h>
/**
* Algorithms to use for hashing.
@@ -129,8 +130,9 @@ int hasher_algorithm_to_oid(hash_algorithm_t alg);
* Conversion of hash signature algorithm into ASN.1 OID.
*
* @param alg hash algorithm
* @param alg public key type
* @return ASN.1 OID if, or OID_UNKNOW
*/
int hasher_signature_algorithm_to_oid(hash_algorithm_t alg);
int hasher_signature_algorithm_to_oid(hash_algorithm_t alg, key_type_t key);
#endif /** HASHER_H_ @}*/