]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
gost_grasshopper_cipher: Rework cipher registration
authorVitaly Chikunov <vt@altlinux.org>
Tue, 12 May 2020 01:58:03 +0000 (04:58 +0300)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Tue, 12 May 2020 09:55:47 +0000 (12:55 +0300)
This only adds registering via tables, but not removing obsolete code.

gost_eng.c
gost_grasshopper_cipher.c
gost_lcl.h

index 84c0937235b1afd7ee4ff3bf8f0e7c30c7e8df0a..09fc4b27c2b9500b2a3eb62f9a11a781bebb8c8c 100644 (file)
@@ -133,23 +133,28 @@ static struct gost_cipher_minfo {
     },
     {
         NID_grasshopper_ecb,
-        cipher_gost_grasshopper_ecb,
+        NULL,
+       &grasshopper_ecb_cipher,
     },
     {
         NID_grasshopper_cbc,
-        cipher_gost_grasshopper_cbc,
+        NULL,
+       &grasshopper_cbc_cipher,
     },
     {
         NID_grasshopper_cfb,
-        cipher_gost_grasshopper_cfb,
+        NULL,
+       &grasshopper_cfb_cipher,
     },
     {
         NID_grasshopper_ofb,
-        cipher_gost_grasshopper_ofb,
+        NULL,
+       &grasshopper_ofb_cipher,
     },
     {
         NID_grasshopper_ctr,
-        cipher_gost_grasshopper_ctr,
+        NULL,
+       &grasshopper_ctr_cipher,
     },
     {
         NID_magma_cbc,
@@ -172,12 +177,14 @@ static struct gost_cipher_minfo {
        &magma_ctr_acpkm_omac_cipher,
     },
     {
-        NID_id_tc26_cipher_gostr3412_2015_kuznyechik_ctracpkm,
-        cipher_gost_grasshopper_ctracpkm,
+        NID_kuznyechik_ctr_acpkm,
+        NULL,
+       &grasshopper_ctr_acpkm_cipher,
     },
     {
         NID_kuznyechik_ctr_acpkm_omac,
-        cipher_gost_grasshopper_ctracpkm_omac,
+        NULL,
+       &grasshopper_ctr_acpkm_omac_cipher,
     },
     {
         NID_magma_kexp15,
index 2c2ea88119b411dd2d08775a6d035ba01eeae0e2..2b3d112fa6e1a7a02876c85fcb13c036feed8644 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Maxim Tishkov 2016
+ * Copyright (c) 2020 Vitaly Chikunov <vt@altlinux.org>
  * This file is distributed under the same license as OpenSSL
  */
 
@@ -46,6 +47,103 @@ struct GRASSHOPPER_CIPHER_PARAMS {
     int extra_flags;
 };
 
+static GOST_cipher grasshopper_template_cipher = {
+    .block_size = GRASSHOPPER_BLOCK_SIZE,
+    .key_len = GRASSHOPPER_KEY_SIZE,
+    .flags = EVP_CIPH_RAND_KEY |
+        EVP_CIPH_ALWAYS_CALL_INIT,
+    .do_cipher = gost_grasshopper_cipher_do,
+    .cleanup = gost_grasshopper_cipher_cleanup,
+    .ctx_size = sizeof(gost_grasshopper_cipher_ctx),
+    .set_asn1_parameters = gost_grasshopper_set_asn1_parameters,
+    .get_asn1_parameters = gost_grasshopper_get_asn1_parameters,
+    .ctrl = gost_grasshopper_cipher_ctl,
+};
+
+GOST_cipher grasshopper_ecb_cipher = {
+    .nid = NID_grasshopper_ecb,
+    .template = &grasshopper_template_cipher,
+    .flags = EVP_CIPH_ECB_MODE,
+    .init = gost_grasshopper_cipher_init_ecb,
+    .do_cipher = gost_grasshopper_cipher_do_ecb,
+};
+
+GOST_cipher grasshopper_cbc_cipher = {
+    .nid = NID_grasshopper_cbc,
+    .template = &grasshopper_template_cipher,
+    .iv_len = 16,
+    .flags = EVP_CIPH_CBC_MODE |
+        EVP_CIPH_CUSTOM_IV,
+    .init = gost_grasshopper_cipher_init_cbc,
+    .do_cipher = gost_grasshopper_cipher_do_cbc,
+};
+
+GOST_cipher grasshopper_ofb_cipher = {
+    .nid = NID_grasshopper_ofb,
+    .template = &grasshopper_template_cipher,
+    .block_size = 1,
+    .iv_len = 16,
+    .flags = EVP_CIPH_OFB_MODE |
+        EVP_CIPH_NO_PADDING |
+        EVP_CIPH_CUSTOM_IV,
+    .init = gost_grasshopper_cipher_init_ofb,
+    .do_cipher = gost_grasshopper_cipher_do_ofb,
+};
+
+GOST_cipher grasshopper_cfb_cipher = {
+    .nid = NID_grasshopper_cfb,
+    .template = &grasshopper_template_cipher,
+    .block_size = 1,
+    .iv_len = 16,
+    .flags = EVP_CIPH_CFB_MODE |
+        EVP_CIPH_NO_PADDING |
+        EVP_CIPH_CUSTOM_IV,
+    .init = gost_grasshopper_cipher_init_cfb,
+    .do_cipher = gost_grasshopper_cipher_do_cfb,
+};
+
+GOST_cipher grasshopper_ctr_cipher = {
+    .nid = NID_grasshopper_ctr,
+    .template = &grasshopper_template_cipher,
+    .block_size = 1,
+    .iv_len = 8,
+    .flags = EVP_CIPH_CTR_MODE |
+        EVP_CIPH_NO_PADDING |
+        EVP_CIPH_CUSTOM_IV,
+    .init = gost_grasshopper_cipher_init_ctr,
+    .do_cipher = gost_grasshopper_cipher_do_ctr,
+    .ctx_size = sizeof(gost_grasshopper_cipher_ctx_ctr),
+};
+
+GOST_cipher grasshopper_ctr_acpkm_cipher = {
+    .nid = NID_kuznyechik_ctr_acpkm,
+    .template = &grasshopper_template_cipher,
+    .block_size = 1,
+    .iv_len = 8,
+    .flags = EVP_CIPH_CTR_MODE |
+        EVP_CIPH_NO_PADDING |
+        EVP_CIPH_CUSTOM_IV,
+    .init = gost_grasshopper_cipher_init_ctracpkm,
+    .do_cipher = gost_grasshopper_cipher_do_ctracpkm,
+    .ctx_size = sizeof(gost_grasshopper_cipher_ctx_ctr),
+};
+
+GOST_cipher grasshopper_ctr_acpkm_omac_cipher = {
+    .nid = NID_kuznyechik_ctr_acpkm_omac,
+    .template = &grasshopper_template_cipher,
+    .block_size = 1,
+    .iv_len = 8,
+    .flags = EVP_CIPH_CTR_MODE |
+        EVP_CIPH_NO_PADDING |
+        EVP_CIPH_CUSTOM_IV |
+        EVP_CIPH_FLAG_CUSTOM_CIPHER |
+        EVP_CIPH_FLAG_CIPHER_WITH_MAC |
+        EVP_CIPH_CUSTOM_COPY,
+    .init = gost_grasshopper_cipher_init_ctracpkm_omac,
+    .do_cipher = gost_grasshopper_cipher_do_ctracpkm_omac,
+    .ctx_size = sizeof(gost_grasshopper_cipher_ctx_ctr),
+};
+
 static struct GRASSHOPPER_CIPHER_PARAMS gost_cipher_params[7] = {
        {
                NID_grasshopper_ecb,
@@ -1069,3 +1167,4 @@ void cipher_gost_grasshopper_destroy(void)
     EVP_CIPHER_meth_free(gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CTRACPKMOMAC]);
     gost_grasshopper_ciphers[GRASSHOPPER_CIPHER_CTRACPKMOMAC] = NULL;
 }
+/* vim: set expandtab cinoptions=\:0,l1,t0,g0,(0 sw=4 : */
index a9cb8b0032b0159517cc9ea1b5129644401ba4a4..3aafd9eca47405e281ec8c2dd7e690e9ccddfdc0 100644 (file)
@@ -350,5 +350,13 @@ extern GOST_cipher magma_ctr_cipher;
 extern GOST_cipher magma_ctr_acpkm_cipher;
 extern GOST_cipher magma_ctr_acpkm_omac_cipher;
 extern GOST_cipher magma_cbc_cipher;
+extern GOST_cipher grasshopper_ecb_cipher;
+extern GOST_cipher grasshopper_cbc_cipher;
+extern GOST_cipher grasshopper_cfb_cipher;
+extern GOST_cipher grasshopper_ofb_cipher;
+extern GOST_cipher grasshopper_ctr_cipher;
+extern GOST_cipher grasshopper_ctr_acpkm_cipher;
+extern GOST_cipher grasshopper_ctr_acpkm_omac_cipher;
+
 #endif
 /* vim: set expandtab cinoptions=\:0,l1,t0,g0,(0 sw=4 : */