Merge libtomcrypt v1.18.2

This commit is contained in:
Matt Johnston
2020-06-10 23:16:13 +08:00
parent 615885be01
commit 4b305c5721
45 changed files with 388 additions and 138 deletions

View File

@@ -16,9 +16,11 @@ extern prng_state yarrow_prng;
#ifdef LTC_VERBOSE
#define DO(x) do { fprintf(stderr, "%s:\n", #x); run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0)
#define DOX(x, str) do { fprintf(stderr, "%s - %s:\n", #x, (str)); run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0)
#define SHOULD_FAIL(x) do { fprintf(stderr, "%s:\n", #x); run_cmd((x) != CRYPT_OK ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR, __LINE__, __FILE__, #x, NULL); } while (0)
#else
#define DO(x) do { run_cmd((x), __LINE__, __FILE__, #x, NULL); } while (0)
#define DOX(x, str) do { run_cmd((x), __LINE__, __FILE__, #x, (str)); } while (0)
#define SHOULD_FAIL(x) do { run_cmd((x) != CRYPT_OK ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR, __LINE__, __FILE__, #x, NULL); } while (0)
#endif
void run_cmd(int res, int line, const char *file, const char *cmd, const char *algorithm);

View File

@@ -1094,6 +1094,25 @@ static int der_choice_test(void)
}
static void _der_recursion_limit(void)
{
int failed = 0;
unsigned int n;
unsigned long integer = 123, s;
ltc_asn1_list seqs[LTC_DER_MAX_RECURSION + 2], dummy[1], *flexi;
unsigned char buf[2048];
LTC_SET_ASN1(dummy, 0, LTC_ASN1_SHORT_INTEGER, &integer, 1);
LTC_SET_ASN1(seqs, LTC_DER_MAX_RECURSION + 1, LTC_ASN1_SEQUENCE, dummy, 1);
for (n = 0; n < LTC_DER_MAX_RECURSION + 1; ++n) {
LTC_SET_ASN1(seqs, LTC_DER_MAX_RECURSION - n, LTC_ASN1_SEQUENCE, &seqs[LTC_DER_MAX_RECURSION - n + 1], 1);
}
s = sizeof(buf);
DO(der_encode_sequence(seqs, 1, buf, &s));
DO(der_decode_sequence(buf, s, seqs, 1));
SHOULD_FAIL(der_decode_sequence_flexi(buf, &s, &flexi));
if (failed) exit(EXIT_FAILURE);
}
int der_test(void)
{
unsigned long x, y, z, zz, oid[2][32];
@@ -1126,6 +1145,8 @@ int der_test(void)
unsigned char utf8_buf[32];
wchar_t utf8_out[32];
_der_recursion_limit();
der_cacert_test();
DO(mp_init_multi(&a, &b, &c, &d, &e, &f, &g, NULL));