Skip to content

Commit caff4ce

Browse files
committed
change pk_get_oid() to return a string
1 parent 41599db commit caff4ce

File tree

2 files changed

+19
-34
lines changed

2 files changed

+19
-34
lines changed

src/headers/tomcrypt_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void copy_or_zeromem(const unsigned char* src, unsigned char* dest, unsigned lon
179179
int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng);
180180
int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng);
181181

182-
int pk_get_oid(int pk, oid_st *st);
182+
int pk_get_oid(int pk, const char **st);
183183
int pk_oid_str_to_num(const char *OID, unsigned long *oid, unsigned long *oidlen);
184184
int pk_oid_num_to_str(const unsigned long *oid, unsigned long oidlen, char *OID, unsigned long *outlen);
185185

src/pk/asn1/oid/pk_get_oid.c

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,34 @@
99
#include "tomcrypt_private.h"
1010

1111
#ifdef LTC_DER
12-
static const oid_st rsa_oid = {
13-
{ 1, 2, 840, 113549, 1, 1, 1 },
14-
7,
15-
};
16-
17-
static const oid_st dsa_oid = {
18-
{ 1, 2, 840, 10040, 4, 1 },
19-
6,
20-
};
2112

22-
static const oid_st ec_oid = {
23-
{ 1, 2, 840, 10045, 2, 1 },
24-
6,
25-
};
13+
typedef struct {
14+
int pka;
15+
const char* oid;
16+
} pka_oid;
2617

27-
static const oid_st ec_primef = {
28-
{ 1, 2, 840, 10045, 1, 1 },
29-
6,
18+
static const pka_oid oids[] = {
19+
{ PKA_RSA, "1.2.840.113549.1.1.1" },
20+
{ PKA_DSA, "1.2.840.10040.4.1" },
21+
{ PKA_EC, "1.2.840.10045.2.1" },
22+
{ PKA_EC_PRIMEF, "1.2.840.10045.1.1" },
3023
};
3124

3225
/*
3326
Returns the OID of the public key algorithm.
3427
@return CRYPT_OK if valid
3528
*/
36-
int pk_get_oid(int pk, oid_st *st)
29+
int pk_get_oid(int pk, const char **st)
3730
{
38-
switch (pk) {
39-
case PKA_RSA:
40-
XMEMCPY(st, &rsa_oid, sizeof(*st));
41-
break;
42-
case PKA_DSA:
43-
XMEMCPY(st, &dsa_oid, sizeof(*st));
44-
break;
45-
case PKA_EC:
46-
XMEMCPY(st, &ec_oid, sizeof(*st));
47-
break;
48-
case PKA_EC_PRIMEF:
49-
XMEMCPY(st, &ec_primef, sizeof(*st));
50-
break;
51-
default:
52-
return CRYPT_INVALID_ARG;
31+
unsigned int i;
32+
LTC_ARGCHK(st != NULL);
33+
for (i = 0; i < sizeof(oids)/sizeof(oids[0]); ++i) {
34+
if (oids[i].pka == pk) {
35+
*st = oids[i].oid;
36+
return CRYPT_OK;
37+
}
5338
}
54-
return CRYPT_OK;
39+
return CRYPT_INVALID_ARG;
5540
}
5641
#endif
5742

0 commit comments

Comments
 (0)