|
@@ -620,7 +620,8 @@ static void der_set_test(void)
|
|
|
static const unsigned char bin_str[] = { 1, 0, 0, 1 };
|
|
|
static const unsigned long int_val = 12345678UL;
|
|
|
|
|
|
- unsigned char strs[10][10], outbuf[128];
|
|
|
+ char strs[10][10];
|
|
|
+ unsigned char outbuf[128];
|
|
|
unsigned long x, val, outlen;
|
|
|
|
|
|
/* make structure and encode it */
|
|
@@ -655,19 +656,19 @@ static void der_set_test(void)
|
|
|
exit(EXIT_FAILURE);
|
|
|
}
|
|
|
|
|
|
- strcpy((char*)strs[0], "one");
|
|
|
- strcpy((char*)strs[1], "one2");
|
|
|
- strcpy((char*)strs[2], "two");
|
|
|
- strcpy((char*)strs[3], "aaa");
|
|
|
- strcpy((char*)strs[4], "aaaa");
|
|
|
- strcpy((char*)strs[5], "aab");
|
|
|
- strcpy((char*)strs[6], "aaab");
|
|
|
- strcpy((char*)strs[7], "bbb");
|
|
|
- strcpy((char*)strs[8], "bbba");
|
|
|
- strcpy((char*)strs[9], "bbbb");
|
|
|
+ strcpy(strs[0], "one");
|
|
|
+ strcpy(strs[1], "one2");
|
|
|
+ strcpy(strs[2], "two");
|
|
|
+ strcpy(strs[3], "aaa");
|
|
|
+ strcpy(strs[4], "aaaa");
|
|
|
+ strcpy(strs[5], "aab");
|
|
|
+ strcpy(strs[6], "aaab");
|
|
|
+ strcpy(strs[7], "bbb");
|
|
|
+ strcpy(strs[8], "bbba");
|
|
|
+ strcpy(strs[9], "bbbb");
|
|
|
|
|
|
for (x = 0; x < 10; x++) {
|
|
|
- LTC_SET_ASN1(list, x, LTC_ASN1_PRINTABLE_STRING, strs[x], XSTRLEN((char*)strs[x]));
|
|
|
+ LTC_SET_ASN1(list, x, LTC_ASN1_PRINTABLE_STRING, strs[x], XSTRLEN(strs[x]));
|
|
|
}
|
|
|
|
|
|
outlen = sizeof(outbuf);
|
|
@@ -682,7 +683,7 @@ static void der_set_test(void)
|
|
|
|
|
|
/* now compare */
|
|
|
for (x = 1; x < 10; x++) {
|
|
|
- if (!(XSTRLEN((char*)strs[x-1]) <= XSTRLEN((char*)strs[x])) && strcmp((char*)strs[x-1], (char*)strs[x]) >= 0) {
|
|
|
+ if (!(XSTRLEN(strs[x-1]) <= XSTRLEN(strs[x])) && strcmp(strs[x-1], strs[x]) >= 0) {
|
|
|
fprintf(stderr, "error SET OF order at %lu is wrong\n", x);
|
|
|
exit(EXIT_FAILURE);
|
|
|
}
|
|
@@ -1626,30 +1627,32 @@ int der_test(void)
|
|
|
unsigned char buf[3][2048];
|
|
|
void *a, *b, *c, *d, *e, *f, *g;
|
|
|
|
|
|
- static const unsigned char rsa_oid_der[] = { 0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d };
|
|
|
- static const unsigned long rsa_oid[] = { 1, 2, 840, 113549 };
|
|
|
+ const unsigned char rsa_oid_der[] = { 0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d };
|
|
|
+ const unsigned long rsa_oid[] = { 1, 2, 840, 113549 };
|
|
|
|
|
|
- static const unsigned char rsa_ia5[] = "[email protected]";
|
|
|
- static const unsigned char rsa_ia5_der[] = { 0x16, 0x0d, 0x74, 0x65, 0x73, 0x74, 0x31,
|
|
|
+ const unsigned char rsa_ia5[] = "[email protected]";
|
|
|
+ const unsigned char rsa_ia5_der[] = { 0x16, 0x0d, 0x74, 0x65, 0x73, 0x74, 0x31,
|
|
|
0x40, 0x72, 0x73, 0x61, 0x2e, 0x63, 0x6f, 0x6d };
|
|
|
+ unsigned long rsa_ia5_len = XSTRLEN((char*)rsa_ia5);
|
|
|
|
|
|
- static const unsigned char rsa_printable[] = "Test User 1";
|
|
|
- static const unsigned char rsa_printable_der[] = { 0x13, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x20, 0x55,
|
|
|
+ const unsigned char rsa_printable[] = "Test User 1";
|
|
|
+ const unsigned char rsa_printable_der[] = { 0x13, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x20, 0x55,
|
|
|
0x73, 0x65, 0x72, 0x20, 0x31 };
|
|
|
+ unsigned long rsa_printable_len = XSTRLEN((char*)rsa_printable);
|
|
|
|
|
|
- static const ltc_utctime rsa_time1 = { 91, 5, 6, 16, 45, 40, 1, 7, 0 };
|
|
|
- static const ltc_utctime rsa_time2 = { 91, 5, 6, 23, 45, 40, 0, 0, 0 };
|
|
|
+ const ltc_utctime rsa_time1 = { 91, 5, 6, 16, 45, 40, 1, 7, 0 };
|
|
|
+ const ltc_utctime rsa_time2 = { 91, 5, 6, 23, 45, 40, 0, 0, 0 };
|
|
|
ltc_utctime tmp_time;
|
|
|
|
|
|
- static const unsigned char rsa_time1_der[] = { 0x17, 0x11, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x31, 0x36, 0x34, 0x35, 0x34, 0x30, 0x2D, 0x30, 0x37, 0x30, 0x30 };
|
|
|
- static const unsigned char rsa_time2_der[] = { 0x17, 0x0d, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x32, 0x33, 0x34, 0x35, 0x34, 0x30, 0x5a };
|
|
|
+ const unsigned char rsa_time1_der[] = { 0x17, 0x11, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x31, 0x36, 0x34, 0x35, 0x34, 0x30, 0x2D, 0x30, 0x37, 0x30, 0x30 };
|
|
|
+ const unsigned char rsa_time2_der[] = { 0x17, 0x0d, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x32, 0x33, 0x34, 0x35, 0x34, 0x30, 0x5a };
|
|
|
|
|
|
- static const wchar_t utf8_1[] = { 0x0041, 0x2262, 0x0391, 0x002E };
|
|
|
- static const unsigned char utf8_1_der[] = { 0x0C, 0x07, 0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E };
|
|
|
- static const wchar_t utf8_2[] = { 0xD55C, 0xAD6D, 0xC5B4 };
|
|
|
- static const unsigned char utf8_2_der[] = { 0x0C, 0x09, 0xED, 0x95, 0x9C, 0xEA, 0xB5, 0xAD, 0xEC, 0x96, 0xB4 };
|
|
|
- static const wchar_t utf8_3[] = { 0x05E9, 0x05DC, 0x05D5, 0x05DD };
|
|
|
- static const unsigned char utf8_3_der[] = { 0x0C, 0x08, 0xD7, 0xA9, 0xD7, 0x9C, 0xD7, 0x95, 0xD7, 0x9D };
|
|
|
+ const wchar_t utf8_1[] = { 0x0041, 0x2262, 0x0391, 0x002E };
|
|
|
+ const unsigned char utf8_1_der[] = { 0x0C, 0x07, 0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E };
|
|
|
+ const wchar_t utf8_2[] = { 0xD55C, 0xAD6D, 0xC5B4 };
|
|
|
+ const unsigned char utf8_2_der[] = { 0x0C, 0x09, 0xED, 0x95, 0x9C, 0xEA, 0xB5, 0xAD, 0xEC, 0x96, 0xB4 };
|
|
|
+ const wchar_t utf8_3[] = { 0x05E9, 0x05DC, 0x05D5, 0x05DD };
|
|
|
+ const unsigned char utf8_3_der[] = { 0x0C, 0x08, 0xD7, 0xA9, 0xD7, 0x9C, 0xD7, 0x95, 0xD7, 0x9D };
|
|
|
|
|
|
unsigned char utf8_buf[32];
|
|
|
wchar_t utf8_out[32];
|
|
@@ -1863,38 +1866,38 @@ int der_test(void)
|
|
|
|
|
|
/* IA5 string */
|
|
|
x = sizeof(buf[0]);
|
|
|
- DO(der_encode_ia5_string(rsa_ia5, XSTRLEN((char*)rsa_ia5), buf[0], &x));
|
|
|
+ DO(der_encode_ia5_string(rsa_ia5, rsa_ia5_len, buf[0], &x));
|
|
|
if (x != sizeof(rsa_ia5_der) || memcmp(buf[0], rsa_ia5_der, x)) {
|
|
|
fprintf(stderr, "IA5 encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_ia5_der));
|
|
|
return 1;
|
|
|
}
|
|
|
- DO(der_length_ia5_string(rsa_ia5, XSTRLEN((char*)rsa_ia5), &y));
|
|
|
+ DO(der_length_ia5_string(rsa_ia5, rsa_ia5_len, &y));
|
|
|
if (y != x) {
|
|
|
fprintf(stderr, "IA5 length failed to match: %lu, %lu\n", x, y);
|
|
|
return 1;
|
|
|
}
|
|
|
y = sizeof(buf[1]);
|
|
|
DO(der_decode_ia5_string(buf[0], x, buf[1], &y));
|
|
|
- if (y != XSTRLEN((char*)rsa_ia5) || memcmp(buf[1], rsa_ia5, XSTRLEN((char*)rsa_ia5))) {
|
|
|
+ if (y != rsa_ia5_len || memcmp(buf[1], rsa_ia5, rsa_ia5_len)) {
|
|
|
fprintf(stderr, "DER IA5 failed test vector\n");
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
/* Printable string */
|
|
|
x = sizeof(buf[0]);
|
|
|
- DO(der_encode_printable_string(rsa_printable, XSTRLEN((char*)rsa_printable), buf[0], &x));
|
|
|
+ DO(der_encode_printable_string(rsa_printable, rsa_printable_len, buf[0], &x));
|
|
|
if (x != sizeof(rsa_printable_der) || memcmp(buf[0], rsa_printable_der, x)) {
|
|
|
fprintf(stderr, "PRINTABLE encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_printable_der));
|
|
|
return 1;
|
|
|
}
|
|
|
- DO(der_length_printable_string(rsa_printable, XSTRLEN((char*)rsa_printable), &y));
|
|
|
+ DO(der_length_printable_string(rsa_printable, rsa_printable_len, &y));
|
|
|
if (y != x) {
|
|
|
fprintf(stderr, "printable length failed to match: %lu, %lu\n", x, y);
|
|
|
return 1;
|
|
|
}
|
|
|
y = sizeof(buf[1]);
|
|
|
DO(der_decode_printable_string(buf[0], x, buf[1], &y));
|
|
|
- if (y != XSTRLEN((char*)rsa_printable) || memcmp(buf[1], rsa_printable, XSTRLEN((char*)rsa_printable))) {
|
|
|
+ if (y != rsa_printable_len || memcmp(buf[1], rsa_printable, rsa_printable_len)) {
|
|
|
fprintf(stderr, "DER printable failed test vector\n");
|
|
|
return 1;
|
|
|
}
|