|
@@ -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 */
|