aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Chikunov <vt@altlinux.org>2019-07-12 03:23:10 +0300
committerVitaly Chikunov <vt@altlinux.org>2019-07-12 03:40:12 +0300
commit034066376d4b3743368a5907d2cbec20983af3e0 (patch)
tree06f24205f235d819849bcbfad585474ed27b331c
parente37273980388332884e53744e4300f48ac62f772 (diff)
downloadgost-engine-034066376d4b3743368a5907d2cbec20983af3e0.zip
gost-engine-034066376d4b3743368a5907d2cbec20983af3e0.tar.gz
gost-engine-034066376d4b3743368a5907d2cbec20983af3e0.tar.bz2
Fix test_grasshopper and test_keyexpimp engine init
Make proper engine initialization for tests instead of EVP_add_cipher/EVP_add_digest hack. Fixes #151.
-rw-r--r--test_grasshopper.c15
-rw-r--r--test_keyexpimp.c22
2 files changed, 28 insertions, 9 deletions
diff --git a/test_grasshopper.c b/test_grasshopper.c
index b148ef1..5329129 100644
--- a/test_grasshopper.c
+++ b/test_grasshopper.c
@@ -368,6 +368,14 @@ int main(int argc, char **argv)
int ret = 0;
const struct testcase *t;
+ setenv("OPENSSL_ENGINES", ENGINE_DIR, 0);
+ OPENSSL_add_all_algorithms_conf();
+ ERR_load_crypto_strings();
+ ENGINE *eng;
+ T(eng = ENGINE_by_id("gost"));
+ T(ENGINE_init(eng));
+ T(ENGINE_set_default(eng, ENGINE_METHOD_ALL));
+
for (t = testcases; t->name; t++) {
int inplace;
const char *standard = t->acpkm? "R 23565.1.017-2018" : "GOST R 34.13-2015";
@@ -383,9 +391,7 @@ int main(int argc, char **argv)
t->iv, t->iv_size, t->acpkm);
}
- /* preload cbc cipher for omac set key */
- EVP_add_cipher(cipher_gost_grasshopper_cbc());
-
+ printf(cBLUE "# Tests for omac\n" cNORM);
ret |= test_mac("OMAC", "GOST R 34.13-2015", grasshopper_omac(), 0, 0,
P, sizeof(P), MAC_omac, sizeof(MAC_omac));
ret |= test_mac("OMAC-ACPKM", "R 1323565.1.017-2018 A.4.1",
@@ -397,6 +403,9 @@ int main(int argc, char **argv)
P_omac_acpkm2, sizeof(P_omac_acpkm2),
MAC_omac_acpkm2, sizeof(MAC_omac_acpkm2));
+ ENGINE_finish(eng);
+ ENGINE_free(eng);
+
if (ret)
printf(cDRED "= Some tests FAILED!\n" cNORM);
else
diff --git a/test_keyexpimp.c b/test_keyexpimp.c
index 5e3528d..de7b1fa 100644
--- a/test_keyexpimp.c
+++ b/test_keyexpimp.c
@@ -9,6 +9,11 @@
#include "e_gost_err.h"
#include "gost_grasshopper_cipher.h"
+#define T(e) if (!(e)) {\
+ ERR_print_errors_fp(stderr);\
+ OpenSSLDie(__FILE__, __LINE__, #e);\
+ }
+
static void hexdump(FILE *f, const char *title, const unsigned char *s, int l)
{
int n = 0;
@@ -92,13 +97,15 @@ int main(void)
unsigned char tlsseq[8];
unsigned char out[32];
- OpenSSL_add_all_algorithms();
+ setenv("OPENSSL_ENGINES", ENGINE_DIR, 0);
+ OPENSSL_add_all_algorithms_conf();
+ ERR_load_crypto_strings();
+ ENGINE *eng;
+ T(eng = ENGINE_by_id("gost"));
+ T(ENGINE_init(eng));
+ T(ENGINE_set_default(eng, ENGINE_METHOD_ALL));
+
memset(buf, 0, sizeof(buf));
- /* Make test work without config. */
- EVP_add_cipher(cipher_magma_ctr());
- EVP_add_cipher(cipher_magma_cbc());
- EVP_add_digest(digest_gost2012_256());
- EVP_add_digest(magma_omac());
memset(kroot, 0xFF, 32);
memset(tlsseq, 0, 8);
@@ -160,5 +167,8 @@ int main(void)
}
}
+ ENGINE_finish(eng);
+ ENGINE_free(eng);
+
return err;
}