]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Move tests from gost89.c into test_gost89.c. 100/head
authorVitaly Chikunov <vt@altlinux.org>
Fri, 21 Dec 2018 17:56:35 +0000 (20:56 +0300)
committerVitaly Chikunov <vt@altlinux.org>
Fri, 21 Dec 2018 18:38:46 +0000 (21:38 +0300)
CMakeLists.txt
gost89.c
gost89.h
test_gost89.c [new file with mode: 0644]

index d8f618c418537be6527927d996b012c836c11996..3aa5e733c98227f4ba022a481cdd7b91c463e835 100644 (file)
@@ -144,6 +144,11 @@ target_link_libraries(test_keyexpimp gost_engine gost_core ${OPENSSL_CRYPTO_LIBR
 add_test(NAME keyexpimp
        COMMAND test_keyexpimp)
 
+add_executable(test_gost89 test_gost89.c)
+target_link_libraries(test_gost89 gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
+add_test(NAME gost89
+       COMMAND test_gost89)
+
 add_test(NAME engine
         COMMAND perl run_tests
         WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)
index 670dfb55f5da84e9fe683edbda09e5a625e5b179..c670bb61cb6bf8eefdc7fda790882db55cc28de0 100644 (file)
--- a/gost89.c
+++ b/gost89.c
@@ -250,7 +250,7 @@ const byte ACPKM_D_const[] = {
 };
 
 /* Initialization of gost_ctx subst blocks*/
-static void kboxinit(gost_ctx * c, const gost_subst_block * b)
+void kboxinit(gost_ctx * c, const gost_subst_block * b)
 {
     int i;
 
@@ -649,65 +649,3 @@ void acpkm_magma_key_meshing(gost_ctx * ctx)
     /* set new key */
     gost_key(ctx, newkey);
 }
-
-#ifdef ENABLE_UNIT_TESTS
-# include <stdio.h>
-# include <string.h>
-
-static void hexdump(FILE *f, const char *title, const unsigned char *s, int l)
-{
-    int n = 0;
-
-    fprintf(f, "%s", title);
-    for (; n < l; ++n) {
-        if ((n % 16) == 0)
-            fprintf(f, "\n%04x", n);
-        fprintf(f, " %02x", s[n]);
-    }
-    fprintf(f, "\n");
-}
-
-int main(void)
-{
-    const unsigned char initial_key[] = {
-        0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
-        0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
-        0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
-        0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
-    };
-
-    const unsigned char meshed_key[] = {
-        0x86, 0x3E, 0xA0, 0x17, 0x84, 0x2C, 0x3D, 0x37,
-        0x2B, 0x18, 0xA8, 0x5A, 0x28, 0xE2, 0x31, 0x7D,
-        0x74, 0xBE, 0xFC, 0x10, 0x77, 0x20, 0xDE, 0x0C,
-        0x9E, 0x8A, 0xB9, 0x74, 0xAB, 0xD0, 0x0C, 0xA0,
-    };
-
-    unsigned char buf[32];
-
-    gost_ctx ctx;
-    kboxinit(&ctx, &Gost28147_TC26ParamSetZ);
-    magma_key(&ctx, initial_key);
-    magma_get_key(&ctx, buf);
-
-    hexdump(stdout, "Initial key", buf, 32);
-
-    acpkm_magma_key_meshing(&ctx);
-    magma_get_key(&ctx, buf);
-    hexdump(stdout, "Meshed key - K2", buf, 32);
-
-    if (memcmp(meshed_key, buf, 32)) {
-        fprintf(stderr, "Magma meshing failed");
-    }
-
-    acpkm_magma_key_meshing(&ctx);
-    magma_get_key(&ctx, buf);
-    hexdump(stdout, "Meshed key - K3", buf, 32);
-
-    acpkm_magma_key_meshing(&ctx);
-    magma_get_key(&ctx, buf);
-    hexdump(stdout, "Meshed key - K4", buf, 32);
-
-}
-
-#endif
index 59a938fa311cc69a934befbefb93ebee3c6cd625..b8a947e1bdd014cf1a091c5d2745042f771234fc 100644 (file)
--- a/gost89.h
+++ b/gost89.h
@@ -97,5 +97,8 @@ extern gost_subst_block Gost28147_CryptoProParamSetD;
 extern gost_subst_block Gost28147_TC26ParamSetZ;
 extern const byte CryptoProKeyMeshingKey[];
 typedef unsigned int word32;
-
+/* For tests. */
+void kboxinit(gost_ctx * c, const gost_subst_block * b);
+void magma_get_key(gost_ctx * c, byte * k);
+void acpkm_magma_key_meshing(gost_ctx * ctx);
 #endif
diff --git a/test_gost89.c b/test_gost89.c
new file mode 100644 (file)
index 0000000..cdba842
--- /dev/null
@@ -0,0 +1,73 @@
+/**********************************************************************
+ *                        gost89.c                                    *
+ *             Copyright (c) 2005-2006 Cryptocom LTD                  *
+ *         This file is distributed under the same license as OpenSSL *
+ *                                                                    *
+ *          Implementation of GOST 28147-89 encryption algorithm      *
+ *            No OpenSSL libraries required to compile and use        *
+ *                              this code                             *
+ **********************************************************************/
+#include <string.h>
+#include "gost89.h"
+#include <stdio.h>
+#include <string.h>
+
+static void hexdump(FILE *f, const char *title, const unsigned char *s, int l)
+{
+    int n = 0;
+
+    fprintf(f, "%s", title);
+    for (; n < l; ++n) {
+        if ((n % 16) == 0)
+            fprintf(f, "\n%04x", n);
+        fprintf(f, " %02x", s[n]);
+    }
+    fprintf(f, "\n");
+}
+
+int main(void)
+{
+    int ret = 0;
+
+    const unsigned char initial_key[] = {
+        0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
+        0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+        0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10,
+        0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
+    };
+
+    const unsigned char meshed_key[] = {
+        0x86, 0x3E, 0xA0, 0x17, 0x84, 0x2C, 0x3D, 0x37,
+        0x2B, 0x18, 0xA8, 0x5A, 0x28, 0xE2, 0x31, 0x7D,
+        0x74, 0xBE, 0xFC, 0x10, 0x77, 0x20, 0xDE, 0x0C,
+        0x9E, 0x8A, 0xB9, 0x74, 0xAB, 0xD0, 0x0C, 0xA0,
+    };
+
+    unsigned char buf[32];
+
+    gost_ctx ctx;
+    kboxinit(&ctx, &Gost28147_TC26ParamSetZ);
+    magma_key(&ctx, initial_key);
+    magma_get_key(&ctx, buf);
+
+    hexdump(stdout, "Initial key", buf, 32);
+
+    acpkm_magma_key_meshing(&ctx);
+    magma_get_key(&ctx, buf);
+    hexdump(stdout, "Meshed key - K2", buf, 32);
+
+    if (memcmp(meshed_key, buf, 32)) {
+        fprintf(stderr, "Magma meshing failed");
+       ret = 1;
+    }
+
+    acpkm_magma_key_meshing(&ctx);
+    magma_get_key(&ctx, buf);
+    hexdump(stdout, "Meshed key - K3", buf, 32);
+
+    acpkm_magma_key_meshing(&ctx);
+    magma_get_key(&ctx, buf);
+    hexdump(stdout, "Meshed key - K4", buf, 32);
+
+    return ret;
+}