1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4
5 #ifdef LTC_DER
6
7 /*
8 Compare an OID string to an array of `unsigned long`.
9 @return CRYPT_OK if equal
10 */
pk_oid_cmp_with_ulong(const char * o1,const unsigned long * o2,unsigned long o2size)11 int pk_oid_cmp_with_ulong(const char *o1, const unsigned long *o2, unsigned long o2size)
12 {
13 unsigned long i;
14 char tmp[256] = { 0 };
15 int err;
16
17 if (o1 == NULL || o2 == NULL) return CRYPT_ERROR;
18
19 i = sizeof(tmp);
20 if ((err = pk_oid_num_to_str(o2, o2size, tmp, &i)) != CRYPT_OK) {
21 return err;
22 }
23
24 if (XSTRCMP(o1, tmp) != 0) {
25 return CRYPT_PK_INVALID_TYPE;
26 }
27
28 return CRYPT_OK;
29 }
30
31 /*
32 Compare an OID string to an OID element decoded from ASN.1.
33 @return CRYPT_OK if equal
34 */
pk_oid_cmp_with_asn1(const char * o1,const ltc_asn1_list * o2)35 int pk_oid_cmp_with_asn1(const char *o1, const ltc_asn1_list *o2)
36 {
37 if (o1 == NULL || o2 == NULL) return CRYPT_ERROR;
38
39 if (o2->type != LTC_ASN1_OBJECT_IDENTIFIER) return CRYPT_INVALID_ARG;
40
41 return pk_oid_cmp_with_ulong(o1, o2->data, o2->size);
42 }
43
44 #endif
45