]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Make it compileable
authorDmitry Belyavskiy <beldmit@gmail.com>
Fri, 12 Oct 2018 19:31:31 +0000 (22:31 +0300)
committerDmitry Belyavskiy <beldmit@gmail.com>
Fri, 12 Oct 2018 19:31:31 +0000 (22:31 +0300)
test_gost2814789.c

index 688a3edc969608d55a929115e2392426f5906a93..20e3fe03078b5c85b5b9d78ffaee458276d077b9 100644 (file)
@@ -9,14 +9,6 @@
  */
 #include <stdio.h>
 
-#if defined(OPENSSL_NO_ENGINE) || defined(OPENSSL_NO_GOST)
-int main(int argc, char *argv[])
-{
-    printf("No GOST 28147-89 support\n");
-    return 0;
-}
-#else
-
 #include <stdlib.h>
 #include <string.h>
 #include <openssl/conf.h>
@@ -27,9 +19,9 @@ int main(int argc, char *argv[])
 #include <openssl/obj_mac.h>
 
 #define CCGOST_ID "gost"
-#define CCGOST_DIR "../engines/ccgost"
+#define CCGOST_DIR "."
 
-#include "../engines/ccgost/gost89.h"
+#include "gost89.h"
 
 #define G89_MAX_TC_LEN (2048)
 #define G89_BLOCK_LEN (8)
@@ -61,15 +53,15 @@ typedef struct g89_tc_ {
 }   g89_tc;
 
 const g89_tc tcs[] = {
-  /* 
-   * GOST R 34.11-94 Test cases 
+  /*
+   * GOST R 34.11-94 Test cases
    */
     { /* see p. A.3.1 [GOSTR341194], p. 7.3.1 [ENG-GOSTR341194] */
       /* <http://tools.ietf.org/html/rfc5831#section-7.3.1> */
       /* Iteration 1, K[1], see Errata for RFC 5831 */
-       8, 
-       { 
-           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
+       8,
+       {
+           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
        },
        "id-GostR3410-94-TestParamSet",
        NULL,
@@ -88,9 +80,9 @@ const g89_tc tcs[] = {
     { /* see p. A.3.1 [GOSTR341194], p. 7.3.1 [ENG-GOSTR341194] */
       /* <http://tools.ietf.org/html/rfc5831#section-7.3.1> */
       /* Iteration 1, K[4] */
-       8, 
-       { 
-           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
+       8,
+       {
+           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
        },
        "id-GostR3410-94-TestParamSet",
        NULL,
@@ -109,8 +101,8 @@ const g89_tc tcs[] = {
     { /* see p. A.3.1 [GOSTR341194], p. 7.3.1 [ENG-GOSTR341194] */
       /* <http://tools.ietf.org/html/rfc5831#section-7.3.1> */
       /* Iteration 2, K[1] */
-       8, 
-       { 
+       8,
+       {
            0x34, 0xc0, 0x15, 0x33, 0xe3, 0x7d, 0x1c, 0x56
        },
        "id-GostR3410-94-TestParamSet",
@@ -127,7 +119,7 @@ const g89_tc tcs[] = {
            0x86, 0x3e, 0x78, 0xdd, 0x2d, 0x60, 0xd1, 0x3c
        }
     },
-  /* 
+  /*
    * id-Gost28147-89-CryptoPro-A-ParamSet (1.2.643.2.2.31.1)
    * Test cases
    */
@@ -218,7 +210,7 @@ const g89_tc tcs[] = {
            0xf8, 0x1f, 0x08, 0xa3
        }
     },
-  /* 
+  /*
    * Other paramsets and key meshing test cases.
    */
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
@@ -545,7 +537,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       5242880+8, 
+       5242880+8,
        { 0 },
        "id-Gost28147-89-CryptoPro-A-ParamSet",
        "test5Mcfb",
@@ -556,7 +548,7 @@ const g89_tc tcs[] = {
            0x85, 0xb4, 0xf0, 0xf9, 0x43, 0xa2, 0x7d, 0x9a
        },
        G89_CFB,
-       { 
+       {
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
        },
        {
@@ -565,7 +557,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       4294967296ULL+16, 
+       4294967296ULL+16,
        { 0 },
        "id-Gost28147-89-CryptoPro-A-ParamSet",
        "test4Gcfb",
@@ -576,11 +568,11 @@ const g89_tc tcs[] = {
            0xc1, 0x12, 0x6a, 0xb0, 0x9a, 0x26, 0xe8, 0x06
        },
        G89_CFB,
-       { 
+       {
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
        },
        {
-           0x2e, 0x62, 0xb0, 0x2e, 0xc7, 0x87, 0x4b, 0x29, 
+           0x2e, 0x62, 0xb0, 0x2e, 0xc7, 0x87, 0x4b, 0x29,
            0x33, 0x16, 0x6b, 0xb4, 0xd6, 0x61, 0x66, 0xd9
        }
     },
@@ -864,7 +856,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       5242880+8, 
+       5242880+8,
        { 0 },
        "id-Gost28147-89-CryptoPro-A-ParamSet",
        "test5Mcnt",
@@ -875,7 +867,7 @@ const g89_tc tcs[] = {
            0x7e, 0x09, 0x9d, 0x4e, 0xb5, 0xc9, 0x84, 0x2e
        },
        G89_CNT,
-       { 
+       {
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
        },
        {
@@ -884,7 +876,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       4294967296ULL+16, 
+       4294967296ULL+16,
        { 0 },
        "id-Gost28147-89-CryptoPro-A-ParamSet",
        "test4Gcnt",
@@ -895,11 +887,11 @@ const g89_tc tcs[] = {
            0xf2, 0x6c, 0xed, 0xda, 0x8f, 0xe4, 0x88, 0xe9
        },
        G89_CNT,
-       { 
+       {
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
        },
        {
-           0xfa, 0x6c, 0x96, 0x78, 0xe2, 0xf8, 0xdd, 0xaa, 
+           0xfa, 0x6c, 0x96, 0x78, 0xe2, 0xf8, 0xdd, 0xaa,
            0x67, 0x5a, 0xc9, 0x5d, 0x57, 0xf1, 0xbd, 0x99
        }
     },
@@ -1091,7 +1083,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       16, 
+       16,
        {
            0x02, 0xf8, 0xec, 0x2b, 0x4d, 0x1f, 0xbc, 0x7c,
            0x6e, 0x47, 0xe3, 0x87, 0x22, 0x75, 0x41, 0xa7
@@ -1111,7 +1103,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       8, 
+       8,
        {
            0xf3, 0xb2, 0x29, 0xd2, 0x7a, 0x37, 0x03, 0x12
        },
@@ -1130,7 +1122,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       0, 
+       0,
        {
            0
        },
@@ -1149,7 +1141,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       5242880, 
+       5242880,
        { 0 },
        "id-Gost28147-89-CryptoPro-A-ParamSet",
        "test5Mimit",
@@ -1166,7 +1158,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       3221225472ULL + 16, 
+       3221225472ULL + 16,
        { 0 },
        "id-Gost28147-89-CryptoPro-A-ParamSet",
        "test3Gimit1",
@@ -1183,7 +1175,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       4ULL*1024*1024*1024ULL, 
+       4ULL*1024*1024*1024ULL,
        { 0 },
        "id-Gost28147-89-CryptoPro-A-ParamSet",
        "test4Gimit3",
@@ -1200,7 +1192,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       4ULL*1024*1024*1024+4ULL, 
+       4ULL*1024*1024*1024+4ULL,
        { 0 },
        "id-Gost28147-89-CryptoPro-A-ParamSet",
        "test4Gimit1",
@@ -1217,7 +1209,7 @@ const g89_tc tcs[] = {
        }
     },
     { /* Calculated by libcapi10, CryptoPro CSP 3.6R2, Mac OSX */
-       4ULL*1024*1024*1024+10ULL, 
+       4ULL*1024*1024*1024+10ULL,
        { 0 },
        "id-Gost28147-89-CryptoPro-A-ParamSet",
        "test4Gimit2",
@@ -1241,8 +1233,8 @@ int main(int argc, char *argv[])
     unsigned long long ullMaxLen = 6*1000*1000;
     int ignore = 0;
     ENGINE *impl = NULL;
-    EVP_MD_CTX mctx;
-    EVP_CIPHER_CTX ectx;
+    EVP_MD_CTX *mctx = NULL;
+    EVP_CIPHER_CTX *ectx = NULL;
     EVP_PKEY *mac_key;
     byte bDerive[EVP_MAX_KEY_LENGTH];
     byte bTest[G89_MAX_TC_LEN];
@@ -1254,7 +1246,7 @@ int main(int argc, char *argv[])
     int enlu = 0;
     int enlf = 0;
     size_t siglen;
-    size_t l;
+    size_t l = 0;
 
     const EVP_MD *md_gost94 = NULL;
     const EVP_CIPHER *cp_g89cfb = NULL;
@@ -1265,7 +1257,7 @@ int main(int argc, char *argv[])
     long lErrLine;
     CONF *pConfig = NCONF_new(NULL);
     BIO *bpConf;
-    char sConf[] = 
+    char sConf[] =
            "openssl_conf = openssl_def\n"
            "\n"
            "[openssl_def]\n"
@@ -1283,16 +1275,16 @@ int main(int argc, char *argv[])
 
     if(1 < argc) {
        if(1 != sscanf(argv[1], "%llu", &ullMaxLen) ||
-          ( 2 < argc ? 
+          ( 2 < argc ?
             1 != sscanf(argv[2], "%d", &ignore) : 0)) {
            fflush(NULL);
-           fprintf(stderr, "Usage: %s [maxlen [ignore-error]]\n", 
+           fprintf(stderr, "Usage: %s [maxlen [ignore-error]]\n",
                                argv[0]);
            return 1;
        }
     }
 
-    /* 
+    /*
      * Internal function test on GostR3411_94_TestParamSet
      */
     #ifdef OPENSSL_NO_DYNAMIC_ENGINE
@@ -1345,11 +1337,11 @@ int main(int argc, char *argv[])
                 */
                continue;
            case G89_IMIT:
-               gost_mac(&ctx, 32, tcs[t].bIn, 
-                                   (unsigned int)tcs[t].ullLen, 
+               gost_mac(&ctx, 32, tcs[t].bIn,
+                                   (unsigned int)tcs[t].ullLen,
                                    bTest);
-               gost_mac_iv(&ctx, 32, tcs[t].bIV, tcs[t].bIn, 
-                                   (unsigned int)tcs[t].ullLen, 
+               gost_mac_iv(&ctx, 32, tcs[t].bIV, tcs[t].bIn,
+                                   (unsigned int)tcs[t].ullLen,
                                    bTest1);
                if(0 != memcmp(bTest, bTest1, 4)) {
                    fflush(NULL);
@@ -1381,7 +1373,7 @@ int main(int argc, char *argv[])
     }
     #endif
 
-    /* 
+    /*
      * ccgost engine test on GostR3411_94_CryptoProParamSet
      */
     #ifndef OPENSSL_NO_DYNAMIC_ENGINE
@@ -1395,7 +1387,7 @@ int main(int argc, char *argv[])
     if(!NCONF_load_bio(pConfig, bpConf, &lErrLine)) {
        fflush(NULL);
        fprintf(stderr, "NCONF_load_bio: ErrLine=%ld: %s\n",
-               lErrLine, 
+               lErrLine,
                ERR_error_string(ERR_get_error(), NULL));
        return 4;
     }
@@ -1452,7 +1444,7 @@ int main(int argc, char *argv[])
        }
        memset(bDerive, 0x3c, sizeof(bDerive));
        mdl = sizeof(bDerive);
-       EVP_Digest(tcs[t].szDerive, strlen(tcs[t].szDerive), 
+       EVP_Digest(tcs[t].szDerive, strlen(tcs[t].szDerive),
                        bDerive, &mdl,
                        md_gost94, impl);
        if(0 != memcmp(tcs[t].bRawKey, bDerive, mdl)) {
@@ -1468,7 +1460,7 @@ int main(int argc, char *argv[])
        }
        memset(bTest, 0xa5, sizeof(bTest));
        memset(bTest1, 0x5a, sizeof(bTest1));
-       if(!ENGINE_ctrl_cmd_string(impl, 
+       if(!ENGINE_ctrl_cmd_string(impl,
                    "CRYPT_PARAMS",
                    tcs[t].szParamSet, 0)) {
            fflush(NULL);
@@ -1493,35 +1485,35 @@ int main(int argc, char *argv[])
            }
            ctype = cp_g89cnt;
 engine_cipher_check:
-           EVP_CIPHER_CTX_init(&ectx);
-           EVP_EncryptInit_ex(&ectx, ctype, impl,
+           EVP_CIPHER_CTX_init(ectx);
+           EVP_EncryptInit_ex(ectx, ctype, impl,
                                    bDerive, tcs[t].bIV);
            if(G89_MAX_TC_LEN >= tcs[t].ullLen) {
                enlu = sizeof(bTest);
-               EVP_EncryptUpdate(&ectx, bTest, &enlu, 
+               EVP_EncryptUpdate(ectx, bTest, &enlu,
                                    tcs[t].bIn, (int)tcs[t].ullLen);
                l = (size_t)tcs[t].ullLen;
            } else {
-               for(ullLeft = tcs[t].ullLen; 
-                           ullLeft >= sizeof(bZB); 
+               for(ullLeft = tcs[t].ullLen;
+                           ullLeft >= sizeof(bZB);
                                    ullLeft -= sizeof(bZB)) {
-                   printf("B"); 
+                   printf("B");
                    fflush(NULL);
                    enlu = sizeof(bTS);
-                   EVP_EncryptUpdate(&ectx, bTS, &enlu, 
+                   EVP_EncryptUpdate(ectx, bTS, &enlu,
                                            bZB, sizeof(bZB));
                }
-               printf("b%llu/%llu", ullLeft, tcs[t].ullLen); 
+               printf("b%llu/%llu", ullLeft, tcs[t].ullLen);
                fflush(NULL);
-               EVP_EncryptUpdate(&ectx, bTS, &enlu, 
+               EVP_EncryptUpdate(ectx, bTS, &enlu,
                                        bZB, (int)ullLeft);
                memcpy(bTest, &bTS[enlu-16], 16);
                enlu = (int)tcs[t].ullLen;
                l = 16;
            }
            enlf = sizeof(bTest1);
-           EVP_EncryptFinal_ex(&ectx, bTest1, &enlf);
-           EVP_CIPHER_CTX_cleanup(&ectx);
+           EVP_EncryptFinal_ex(ectx, bTest1, &enlf);
+           EVP_CIPHER_CTX_cleanup(ectx);
            break;
        case G89_IMIT:
            if(0 != strcmp("id-Gost28147-89-CryptoPro-A-ParamSet",
@@ -1531,31 +1523,31 @@ engine_cipher_check:
                 */
                continue;
            }
-           EVP_MD_CTX_init(&mctx);
+           EVP_MD_CTX_init(mctx);
            mac_key = EVP_PKEY_new_mac_key(
                                NID_id_Gost28147_89_MAC, NULL,
                                bDerive, mdl);
-            EVP_DigestSignInit(&mctx, NULL, 
+            EVP_DigestSignInit(mctx, NULL,
                                    md_g89imit, impl, mac_key);
            if(G89_MAX_TC_LEN >= tcs[t].ullLen) {
-               EVP_DigestSignUpdate(&mctx, tcs[t].bIn, 
+               EVP_DigestSignUpdate(mctx, tcs[t].bIn,
                                    (unsigned int)tcs[t].ullLen);
            } else {
-               for(ullLeft = tcs[t].ullLen; 
-                           ullLeft >= sizeof(bZB); 
+               for(ullLeft = tcs[t].ullLen;
+                           ullLeft >= sizeof(bZB);
                                    ullLeft -= sizeof(bZB)) {
-                   printf("B"); 
+                   printf("B");
                    fflush(NULL);
-                   EVP_DigestSignUpdate(&mctx, bZB, sizeof(bZB));
+                   EVP_DigestSignUpdate(mctx, bZB, sizeof(bZB));
                }
-               printf("b%llu/%llu", ullLeft, tcs[t].ullLen); 
+               printf("b%llu/%llu", ullLeft, tcs[t].ullLen);
                fflush(NULL);
-               EVP_DigestSignUpdate(&mctx, bZB, 
+               EVP_DigestSignUpdate(mctx, bZB,
                                        (unsigned int)ullLeft);
            }
            siglen = 4;
-           EVP_DigestSignFinal(&mctx, bTest, &siglen);
-           EVP_MD_CTX_cleanup(&mctx);
+           EVP_DigestSignFinal(mctx, bTest, &siglen);
+           EVP_MD_CTX_free(mctx);
            enlu = (int)tcs[t].ullLen;
            enlf = 0;
            l = siglen;
@@ -1580,4 +1572,3 @@ engine_cipher_check:
 
     return EXIT_SUCCESS;
 }
-#endif