1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 *
4 * LibTomCrypt is a library that provides various cryptographic
5 * algorithms in a highly modular and flexible manner.
6 *
7 * The library is free for all purposes without any express
8 * guarantee it works.
9 */
10 #include "tomcrypt_private.h"
11
12 #ifdef LTC_DER
13
14 /*
15 Compare an OID string to an array of `unsigned long`.
16 @return CRYPT_OK if equal
17 */
pk_oid_cmp_with_ulong(const char * o1,const unsigned long * o2,unsigned long o2size)18 int pk_oid_cmp_with_ulong(const char *o1, const unsigned long *o2, unsigned long o2size)
19 {
20 unsigned long i;
21 char tmp[256] = { 0 };
22 int err;
23
24 if (o1 == NULL || o2 == NULL) return CRYPT_ERROR;
25
26 i = sizeof(tmp);
27 if ((err = pk_oid_num_to_str(o2, o2size, tmp, &i)) != CRYPT_OK) {
28 return err;
29 }
30
31 if (XSTRCMP(o1, tmp) != 0) {
32 return CRYPT_PK_INVALID_TYPE;
33 }
34
35 return CRYPT_OK;
36 }
37
38 /*
39 Compare an OID string to an OID element decoded from ASN.1.
40 @return CRYPT_OK if equal
41 */
pk_oid_cmp_with_asn1(const char * o1,const ltc_asn1_list * o2)42 int pk_oid_cmp_with_asn1(const char *o1, const ltc_asn1_list *o2)
43 {
44 if (o1 == NULL || o2 == NULL) return CRYPT_ERROR;
45
46 if (o2->type != LTC_ASN1_OBJECT_IDENTIFIER) return CRYPT_INVALID_ARG;
47
48 return pk_oid_cmp_with_ulong(o1, o2->data, o2->size);
49 }
50
51 #endif
52
53 /* ref: $Format:%D$ */
54 /* git commit: $Format:%H$ */
55 /* commit time: $Format:%ai$ */
56