|
9 | 9 | #include "tomcrypt_private.h" |
10 | 10 |
|
11 | 11 | #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 | | -}; |
21 | 12 |
|
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; |
26 | 17 |
|
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" }, |
30 | 23 | }; |
31 | 24 |
|
32 | 25 | /* |
33 | 26 | Returns the OID of the public key algorithm. |
34 | 27 | @return CRYPT_OK if valid |
35 | 28 | */ |
36 | | -int pk_get_oid(int pk, oid_st *st) |
| 29 | +int pk_get_oid(int pk, const char **st) |
37 | 30 | { |
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 | + } |
53 | 38 | } |
54 | | - return CRYPT_OK; |
| 39 | + return CRYPT_INVALID_ARG; |
55 | 40 | } |
56 | 41 | #endif |
57 | 42 |
|
|
0 commit comments