]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Openssl 1.1.0 has separate constants for managing key meshing and sbox values.
authorDmitry Belyavskiy <beldmit@gmail.com>
Mon, 4 Jan 2016 19:40:02 +0000 (22:40 +0300)
committerDmitry Belyavskiy <beldmit@gmail.com>
Mon, 4 Jan 2016 19:40:02 +0000 (22:40 +0300)
Added support for managing key meshing and sbox values into GOST89 ciphers.

gost_crypt.c

index e90ce5a04d024d0245d9aa8d4c8f2620b7303dae..a0125eae40ba5bc324c4ee77fc09ef6b8bb716cc 100644 (file)
@@ -553,6 +553,7 @@ int gost_cipher_cleanup(EVP_CIPHER_CTX *ctx)
 int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
 {
     switch (type) {
+#if 0
     case EVP_CTRL_INIT:
         {
             struct ossl_gost_cipher_ctx *c = ctx->cipher_data;
@@ -561,6 +562,7 @@ int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
             }
             return gost_cipher_set_param(c, arg);
         }
+#endif
     case EVP_CTRL_RAND_KEY:
         {
             if (RAND_bytes((unsigned char *)ptr, ctx->key_len) <= 0) {
@@ -588,6 +590,48 @@ int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
             return 0;
         }
 
+    case EVP_CTRL_SET_SBOX:
+        if (ptr) {
+            struct ossl_gost_cipher_ctx *c = ctx->cipher_data;
+            int nid;
+            int cur_meshing;
+            int ret;
+
+            if (c == NULL) {
+                return -1;
+            }
+
+            if (c->count != 0) {
+                return -1;
+            }
+
+            nid = OBJ_txt2nid(ptr);
+            if (nid == NID_undef) {
+                return 0;
+            }
+
+            cur_meshing = c->key_meshing;
+            ret = gost_cipher_set_param(c, nid);
+            c->key_meshing = cur_meshing;
+            return ret;
+        } else {
+          return 0;
+        }
+    case EVP_CTRL_KEY_MESH:
+        {
+            struct ossl_gost_cipher_ctx *c = ctx->cipher_data;
+
+            if (c == NULL) {
+                return -1;
+            }
+
+            if (c->count != 0) {
+                return -1;
+            }
+
+            c->key_meshing = arg;
+            return 1;
+        }
     default:
         GOSTerr(GOST_F_GOST_CIPHER_CTL,
                 GOST_R_UNSUPPORTED_CIPHER_CTL_COMMAND);