Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ int der_decode_object_identifier(const unsigned char *in, unsigned long inle
y++;
} else {
if (y == 0) {
words[0] = t / 40;
words[1] = t % 40;
if (t <= 79) {
words[0] = t / 40;
words[1] = t % 40;
} else {
words[0] = 2;
words[1] = t - 80;
}
y = 2;
} else {
words[y++] = t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ int der_length_object_identifier(const unsigned long *words, unsigned long nword
return CRYPT_INVALID_ARG;
}

/* word1 = 0,1,2,3 and word2 0..39 */
if (words[0] > 3 || (words[0] < 2 && words[1] > 39)) {
/* word1 = 0,1,2 and word2 0..39 */
if (words[0] > 2 || (words[0] < 2 && words[1] > 39)) {
return CRYPT_INVALID_ARG;
}

Expand Down
30 changes: 30 additions & 0 deletions tests/der_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,34 @@ static void der_set_test(void)

*/

static void _der_oid_test(void)
{
static const unsigned char oid_x690_8_19_5_example[] = { 0x06, 0x03, 0x88, 0x37, 0x03 };
unsigned long len, oid[3];
unsigned char buf[64];

ltc_asn1_list *decoded_list, static_list[1];

len = sizeof(oid_x690_8_19_5_example);
DO(der_decode_sequence_flexi(oid_x690_8_19_5_example, &len, &decoded_list));

LTC_SET_ASN1(static_list, 0, LTC_ASN1_OBJECT_IDENTIFIER, (void *)decoded_list->data, decoded_list->size);
len = sizeof(buf);
DO(der_encode_object_identifier(decoded_list->data, decoded_list->size, buf, &len));
der_sequence_free(decoded_list);

DO(do_compare_testvector(buf, len, oid_x690_8_19_5_example, sizeof(oid_x690_8_19_5_example), "OID X6.90 Ch. 8.19.5 Example", 0));

oid[0] = 3;
oid[1] = 4;
oid[2] = 5;

len = sizeof(buf);
SHOULD_FAIL(der_encode_object_identifier(oid, 3, buf, &len));
len = sizeof(buf);
SHOULD_FAIL(der_length_object_identifier(oid, 3, &len));
}

static void der_flexi_test(void)
{
static const char printable_str[] = "printable";
Expand Down Expand Up @@ -1589,6 +1617,8 @@ int der_test(void)

der_cacert_test();

_der_oid_test();

y = 0xffffff00;
#if ULONG_MAX == ULLONG_MAX
y <<= 32;
Expand Down