rename enum public_key_algorithms to something more generic

This commit is contained in:
Steffen Jaeckel 2018-09-07 09:50:39 +02:00
parent 4cf2e80346
commit fb7b8799cd
2 changed files with 14 additions and 14 deletions

View File

@ -19,7 +19,7 @@
* Internal Enums * Internal Enums
*/ */
enum public_key_algorithms { enum ltc_oid_id {
PKA_RSA, PKA_RSA,
PKA_DSA, PKA_DSA,
PKA_EC, PKA_EC,
@ -173,7 +173,7 @@ void copy_or_zeromem(const unsigned char* src, unsigned char* dest, unsigned lon
int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng); int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng);
int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng); int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng);
int pk_get_oid(int pk, const char **st); int pk_get_oid(enum ltc_oid_id id, const char **st);
int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen); int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen);
int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen); int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen);

View File

@ -11,28 +11,28 @@
#ifdef LTC_DER #ifdef LTC_DER
typedef struct { typedef struct {
int pka; enum ltc_oid_id id;
const char* oid; const char* oid;
} pka_oid; } oid_table_entry;
static const pka_oid oids[] = { static const oid_table_entry pka_oids[] = {
{ PKA_RSA, "1.2.840.113549.1.1.1" }, { PKA_RSA, "1.2.840.113549.1.1.1" },
{ PKA_DSA, "1.2.840.10040.4.1" }, { PKA_DSA, "1.2.840.10040.4.1" },
{ PKA_EC, "1.2.840.10045.2.1" }, { PKA_EC, "1.2.840.10045.2.1" },
{ PKA_EC_PRIMEF, "1.2.840.10045.1.1" }, { PKA_EC_PRIMEF, "1.2.840.10045.1.1" },
}; };
/* /*
Returns the OID of the public key algorithm. Returns the OID requested.
@return CRYPT_OK if valid @return CRYPT_OK if valid
*/ */
int pk_get_oid(int pk, const char **st) int pk_get_oid(enum ltc_oid_id id, const char **st)
{ {
unsigned int i; unsigned int i;
LTC_ARGCHK(st != NULL); LTC_ARGCHK(st != NULL);
for (i = 0; i < sizeof(oids)/sizeof(oids[0]); ++i) { for (i = 0; i < sizeof(pka_oids)/sizeof(pka_oids[0]); ++i) {
if (oids[i].pka == pk) { if (pka_oids[i].id == id) {
*st = oids[i].oid; *st = pka_oids[i].oid;
return CRYPT_OK; return CRYPT_OK;
} }
} }