mirror of
https://github.com/libtom/libtomcrypt
synced 2026-08-25 20:26:07 -04:00
add testvectors from [1]
[1] https://misc.daniel-marschall.de/asn.1/oid_facts.html
This commit is contained in:
parent
756bc7fa21
commit
7e2d163d1d
20 changed files with 144 additions and 0 deletions
BIN
tests/asn1/0x00.crt
Normal file
BIN
tests/asn1/0x00.crt
Normal file
Binary file not shown.
BIN
tests/asn1/0x80.crt
Normal file
BIN
tests/asn1/0x80.crt
Normal file
Binary file not shown.
BIN
tests/asn1/0xff.crt
Normal file
BIN
tests/asn1/0xff.crt
Normal file
Binary file not shown.
BIN
tests/asn1/illegal_padding1.crt
Normal file
BIN
tests/asn1/illegal_padding1.crt
Normal file
Binary file not shown.
BIN
tests/asn1/illegal_padding2.crt
Normal file
BIN
tests/asn1/illegal_padding2.crt
Normal file
Binary file not shown.
BIN
tests/asn1/illegal_padding3.crt
Normal file
BIN
tests/asn1/illegal_padding3.crt
Normal file
Binary file not shown.
BIN
tests/asn1/oid_overflow_test.der
Normal file
BIN
tests/asn1/oid_overflow_test.der
Normal file
Binary file not shown.
BIN
tests/asn1/oid_size_test.der
Normal file
BIN
tests/asn1/oid_size_test.der
Normal file
Binary file not shown.
BIN
tests/asn1/private.der
Normal file
BIN
tests/asn1/private.der
Normal file
Binary file not shown.
BIN
tests/asn1/root-ca.der
Normal file
BIN
tests/asn1/root-ca.der
Normal file
Binary file not shown.
BIN
tests/asn1/type0x08.crt
Normal file
BIN
tests/asn1/type0x08.crt
Normal file
Binary file not shown.
|
|
@ -17,6 +17,10 @@ int der_test(void)
|
|||
|
||||
#else
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
static const unsigned char _der_tests_stinky_root_cert[] =
|
||||
"MIIFETCCA/mgAwIBAgIQbv53JNmv518t5lkCHE272jANBgkqhkiG9w0BAQUFADCB"
|
||||
"lTELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAlVUMRcwFQYDVQQHEw5TYWx0IExha2Ug"
|
||||
|
|
@ -1306,6 +1310,68 @@ static void der_Xcode_test(void)
|
|||
mp_clear(mpinteger);
|
||||
}
|
||||
|
||||
static off_t fsize(const char *filename)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(filename, &st) == 0) return st.st_size;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void der_asn1_test(void)
|
||||
{
|
||||
DIR *d = opendir("tests/asn1");
|
||||
struct dirent *de;
|
||||
char fname[PATH_MAX];
|
||||
void* buf = NULL;
|
||||
FILE *f = NULL;
|
||||
off_t fsz;
|
||||
unsigned long sz;
|
||||
ltc_asn1_list *list;
|
||||
int err;
|
||||
if (d == NULL)
|
||||
return;
|
||||
while((de = readdir(d)) != NULL) {
|
||||
fname[0] = '\0';
|
||||
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
|
||||
continue;
|
||||
strcat(fname, "tests/asn1/");
|
||||
strcat(fname, de->d_name);
|
||||
fsz = fsize(fname);
|
||||
if (fsz == -1)
|
||||
break;
|
||||
#if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 1
|
||||
fprintf(stderr, "Try to decode %s\n", fname);
|
||||
#endif
|
||||
f = fopen(fname, "rb");
|
||||
sz = fsz;
|
||||
buf = XMALLOC(fsz);
|
||||
if (fread(buf, 1, sz, f) != sz)
|
||||
break;
|
||||
|
||||
if ((err = der_decode_sequence_flexi(buf, &sz, &list)) == CRYPT_OK) {
|
||||
#ifdef LTC_DER_TESTS_PRINT_FLEXI
|
||||
fprintf(stderr, "\n\n");
|
||||
_der_tests_print_flexi(list, 0);
|
||||
fprintf(stderr, "\n\n");
|
||||
#endif
|
||||
der_sequence_free(list);
|
||||
} else {
|
||||
#if defined(LTC_TEST_DBG)
|
||||
fprintf(stderr, "Could not decode %s: %s\n\n", fname, error_to_string(err));
|
||||
#endif
|
||||
}
|
||||
XFREE(buf);
|
||||
buf = NULL;
|
||||
fclose(f);
|
||||
f = NULL;
|
||||
}
|
||||
if (buf != NULL) XFREE(buf);
|
||||
if (f != NULL) fclose(f);
|
||||
closedir(d);
|
||||
}
|
||||
|
||||
|
||||
static void _der_regression_test(void)
|
||||
{
|
||||
|
|
@ -1463,6 +1529,8 @@ int der_test(void)
|
|||
|
||||
der_Xcode_test();
|
||||
|
||||
der_asn1_test();
|
||||
|
||||
der_custom_test();
|
||||
|
||||
_der_regression_test();
|
||||
|
|
|
|||
BIN
tests/rsa/rsa_size_1024_bits.der
Normal file
BIN
tests/rsa/rsa_size_1024_bits.der
Normal file
Binary file not shown.
BIN
tests/rsa/rsa_size_16384_bits.der
Normal file
BIN
tests/rsa/rsa_size_16384_bits.der
Normal file
Binary file not shown.
BIN
tests/rsa/rsa_size_1999_bits.der
Normal file
BIN
tests/rsa/rsa_size_1999_bits.der
Normal file
Binary file not shown.
BIN
tests/rsa/rsa_size_2048_bits.der
Normal file
BIN
tests/rsa/rsa_size_2048_bits.der
Normal file
Binary file not shown.
BIN
tests/rsa/rsa_size_4096_bits.der
Normal file
BIN
tests/rsa/rsa_size_4096_bits.der
Normal file
Binary file not shown.
BIN
tests/rsa/rsa_size_512_bits.der
Normal file
BIN
tests/rsa/rsa_size_512_bits.der
Normal file
Binary file not shown.
BIN
tests/rsa/rsa_size_8192_bits.der
Normal file
BIN
tests/rsa/rsa_size_8192_bits.der
Normal file
Binary file not shown.
|
|
@ -10,6 +10,10 @@
|
|||
|
||||
#if defined(LTC_MRSA)
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#define RSA_MSGSIZE 78
|
||||
|
||||
/* These are test keys [see file test.key] that I use to test my import/export against */
|
||||
|
|
@ -343,6 +347,76 @@ static int _rsa_issue_301(int prng_idx)
|
|||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
static off_t fsize(const char *filename)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(filename, &st) == 0) return st.st_size;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int _rsa_size_test(void)
|
||||
{
|
||||
DIR *d = opendir("tests/rsa");
|
||||
struct dirent *de;
|
||||
char fname[PATH_MAX];
|
||||
void* buf = NULL;
|
||||
FILE *f = NULL;
|
||||
off_t fsz;
|
||||
unsigned long sz;
|
||||
int err = CRYPT_FILE_NOTFOUND;
|
||||
rsa_key k;
|
||||
if (d == NULL)
|
||||
return CRYPT_FILE_NOTFOUND;
|
||||
while((de = readdir(d)) != NULL) {
|
||||
fname[0] = '\0';
|
||||
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
|
||||
continue;
|
||||
strcat(fname, "tests/rsa/");
|
||||
strcat(fname, de->d_name);
|
||||
fsz = fsize(fname);
|
||||
if (fsz == -1)
|
||||
break;
|
||||
/* here we use the filesize as indicator for the rsa size
|
||||
* that would fail to import for tfm because it's fixed-size
|
||||
*/
|
||||
if ((strcmp(ltc_mp.name, "TomsFastMath") == 0) && (fsz > 2048)) {
|
||||
#if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 1
|
||||
fprintf(stderr, "TomsFastMath skip: %s\n", fname);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
#if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 1
|
||||
fprintf(stderr, "Try to import %s\n", fname);
|
||||
#endif
|
||||
f = fopen(fname, "rb");
|
||||
sz = fsz;
|
||||
buf = XMALLOC(fsz);
|
||||
if (fread(buf, 1, sz, f) != sz) {
|
||||
err = CRYPT_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((err = rsa_import_x509(buf, sz, &k)) == CRYPT_OK) {
|
||||
rsa_free(&k);
|
||||
} else {
|
||||
#if defined(LTC_TEST_DBG)
|
||||
fprintf(stderr, "Could not import RSA key of %s: %s\n\n", fname, error_to_string(err));
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
XFREE(buf);
|
||||
buf = NULL;
|
||||
fclose(f);
|
||||
f = NULL;
|
||||
}
|
||||
if (buf != NULL) XFREE(buf);
|
||||
if (f != NULL) fclose(f);
|
||||
closedir(d);
|
||||
return err;
|
||||
}
|
||||
|
||||
int rsa_test(void)
|
||||
{
|
||||
unsigned char in[1024], out[1024], tmp[3072];
|
||||
|
|
@ -368,6 +442,8 @@ int rsa_test(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
DO(_rsa_size_test());
|
||||
|
||||
DO(_rsa_issue_301(prng_idx));
|
||||
|
||||
/* make 10 random key */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue