]> www.wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - gost_crypt.c
gost_crypt: Fix IV length for Magma CTR mode
[openssl-gost/engine.git] / gost_crypt.c
index 930d40adc76941aedef3479efb841c44d7e55801..268e3116c6d68bc22007375088da80686bb9beb4 100644 (file)
@@ -201,7 +201,7 @@ const EVP_CIPHER *cipher_magma_ctr(void)
         && ((_hidden_magma_ctr =
              EVP_CIPHER_meth_new(NID_magma_ctr, 1 /* block_size */ ,
                                  32 /* key_size */ )) == NULL
-            || !EVP_CIPHER_meth_set_iv_length(_hidden_magma_ctr, 8)
+            || !EVP_CIPHER_meth_set_iv_length(_hidden_magma_ctr, 4)
             || !EVP_CIPHER_meth_set_flags(_hidden_magma_ctr,
                                           EVP_CIPH_CTR_MODE |
                                           EVP_CIPH_NO_PADDING |
@@ -302,7 +302,7 @@ EVP_MD *imit_gost_cpa(void)
             || !EVP_MD_meth_set_input_blocksize(md, 8)
             || !EVP_MD_meth_set_app_datasize(md,
                                              sizeof(struct ossl_gost_imit_ctx))
-            || !EVP_MD_meth_set_flags(md, 0)
+            || !EVP_MD_meth_set_flags(md, EVP_MD_FLAG_XOF)
             || !EVP_MD_meth_set_init(md, gost_imit_init_cpa)
             || !EVP_MD_meth_set_update(md, gost_imit_update)
             || !EVP_MD_meth_set_final(md, gost_imit_final)
@@ -333,7 +333,7 @@ EVP_MD *imit_gost_cp_12(void)
             || !EVP_MD_meth_set_input_blocksize(md, 8)
             || !EVP_MD_meth_set_app_datasize(md,
                                              sizeof(struct ossl_gost_imit_ctx))
-            || !EVP_MD_meth_set_flags(md, 0)
+            || !EVP_MD_meth_set_flags(md, EVP_MD_FLAG_XOF)
             || !EVP_MD_meth_set_init(md, gost_imit_init_cp_12)
             || !EVP_MD_meth_set_update(md, gost_imit_update)
             || !EVP_MD_meth_set_final(md, gost_imit_final)
@@ -876,7 +876,7 @@ int gost_cipher_ctl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
 #endif
     case EVP_CTRL_RAND_KEY:
         {
-            if (RAND_bytes
+            if (RAND_priv_bytes
                 ((unsigned char *)ptr, EVP_CIPHER_CTX_key_length(ctx)) <= 0) {
                 GOSTerr(GOST_F_GOST_CIPHER_CTL, GOST_R_RNG_ERROR);
                 return -1;
@@ -1001,7 +1001,6 @@ int gost89_set_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
 /* Store parameters into ASN1 structure */
 int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
 {
-    int ret = -1;
     int len;
     GOST_CIPHER_PARAMS *gcp = NULL;
     unsigned char *p;
@@ -1009,7 +1008,7 @@ int gost89_get_asn1_parameters(EVP_CIPHER_CTX *ctx, ASN1_TYPE *params)
     int nid;
 
     if (ASN1_TYPE_get(params) != V_ASN1_SEQUENCE) {
-        return ret;
+        return -1;
     }
 
     p = params->value.sequence->data;
@@ -1071,15 +1070,14 @@ static int gost_imit_init_cp_12(EVP_MD_CTX *ctx)
 static void mac_block_mesh(struct ossl_gost_imit_ctx *c,
                            const unsigned char *data)
 {
-    unsigned char buffer[8];
     /*
-     * We are using local buffer for iv because CryptoPro doesn't interpret
+     * We are using NULL for iv because CryptoPro doesn't interpret
      * internal state of MAC algorithm as iv during keymeshing (but does
      * initialize internal state from iv in key transport
      */
     assert(c->count % 8 == 0 && c->count <= 1024);
     if (c->key_meshing && c->count == 1024) {
-        cryptopro_key_meshing(&(c->cctx), buffer);
+        cryptopro_key_meshing(&(c->cctx), NULL);
     }
     mac_block(&(c->cctx), c->buffer, data);
     c->count = c->count % 1024 + 8;
@@ -1089,12 +1087,13 @@ int gost_imit_update(EVP_MD_CTX *ctx, const void *data, size_t count)
 {
     struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx);
     const unsigned char *p = data;
-    size_t bytes = count, i;
+    size_t bytes = count;
     if (!(c->key_set)) {
         GOSTerr(GOST_F_GOST_IMIT_UPDATE, GOST_R_MAC_KEY_NOT_SET);
         return 0;
     }
     if (c->bytes_left) {
+        size_t i;
         for (i = c->bytes_left; i < 8 && bytes > 0; bytes--, i++, p++) {
             c->partial_block[i] = *p;
         }
@@ -1180,7 +1179,7 @@ int gost_imit_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr)
             GOSTerr(GOST_F_GOST_IMIT_CTRL, GOST_R_INVALID_MAC_KEY_SIZE);
             return 0;
         }
-    case EVP_MD_CTRL_MAC_LEN:
+    case EVP_MD_CTRL_XOF_LEN:
         {
             struct ossl_gost_imit_ctx *c = EVP_MD_CTX_md_data(ctx);
             if (arg < 1 || arg > 8) {