X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=test_keyexpimp.c;h=0e61b6f43c3d0453331416278ecdfbc9cdbdf61a;hb=HEAD;hp=5e3528d99b93b43e32cf4b12ad5f0175ebf14b31;hpb=d02ac6b47941f4b49fa70edad3419fa5a81eb284;p=openssl-gost%2Fengine.git diff --git a/test_keyexpimp.c b/test_keyexpimp.c index 5e3528d..0e61b6f 100644 --- a/test_keyexpimp.c +++ b/test_keyexpimp.c @@ -1,4 +1,18 @@ -#include +/* + * Copyright (c) 2019-2020 Dmitry Belyavskiy + * + * Contents licensed under the terms of the OpenSSL license + * See https://www.openssl.org/source/license.html for details + */ +#ifdef _MSC_VER +# pragma warning(push, 3) +# include +# pragma warning(pop) +# include +# include +#else +# include +#endif #include #include #include @@ -9,6 +23,12 @@ #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 +112,19 @@ int main(void) unsigned char tlsseq[8]; unsigned char out[32]; - OpenSSL_add_all_algorithms(); +#ifdef _MSC_VER + _putenv_s("OPENSSL_ENGINES", ENGINE_DIR); +#else + setenv("OPENSSL_ENGINES", ENGINE_DIR, 0); +#endif + 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); @@ -111,12 +137,12 @@ int main(void) if (ret <= 0) { ERR_print_errors_fp(stderr); - err = 1; + err = 1; } else { hexdump(stdout, "Magma key export", buf, 40); if (memcmp(buf, magma_export, 40) != 0) { fprintf(stdout, "ERROR! test failed\n"); - err = 2; + err = 2; } } @@ -126,12 +152,12 @@ int main(void) if (ret <= 0) { ERR_print_errors_fp(stderr); - err = 3; + err = 3; } else { hexdump(stdout, "Magma key import", buf, 32); if (memcmp(buf, shared_key, 32) != 0) { fprintf(stdout, "ERROR! test failed\n"); - err = 4; + err = 4; } } @@ -139,26 +165,29 @@ int main(void) kdf_seed, 8, 1); if (ret <= 0) { ERR_print_errors_fp(stderr); - err = 5; + err = 5; } else { hexdump(stdout, "KDF TREE", kdf_result, 64); if (memcmp(kdf_result, kdf_etalon, 64) != 0) { fprintf(stdout, "ERROR! test failed\n"); - err = 6; + err = 6; } } ret = gost_tlstree(NID_grasshopper_cbc, kroot, out, tlsseq); if (ret <= 0) { ERR_print_errors_fp(stderr); - err = 7; + err = 7; } else { hexdump(stdout, "Gost TLSTREE - grasshopper", out, 32); if (memcmp(out, tlstree_gh_etalon, 32) != 0) { fprintf(stdout, "ERROR! test failed\n"); - err = 8; + err = 8; } } + ENGINE_finish(eng); + ENGINE_free(eng); + return err; }