From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 011FC2B604 for ; Sun, 28 Apr 2019 12:52:56 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id No9n38z1FFud for ; Sun, 28 Apr 2019 12:52:55 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 3AD122686C for ; Sun, 28 Apr 2019 12:52:55 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH 3/3] crypto: implement crypto codec API and AES 128 encryption From: Vladislav Shpilevoy References: <0e95f1eff6e2caaab4a2ed344bfdf9e67a9f23b5.1556226152.git.v.shpilevoy@tarantool.org> Message-ID: Date: Sun, 28 Apr 2019 19:52:52 +0300 MIME-Version: 1.0 In-Reply-To: <0e95f1eff6e2caaab4a2ed344bfdf9e67a9f23b5.1556226152.git.v.shpilevoy@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: kostja@tarantool.org Found a typo. The fix is below and force pushed on the branch: ==================================================================================== diff --git a/src/lib/crypto/crypto.c b/src/lib/crypto/crypto.c index 35e53e238..557c92916 100644 --- a/src/lib/crypto/crypto.c +++ b/src/lib/crypto/crypto.c @@ -79,7 +79,7 @@ crypto_codec_new(enum crypto_algo algo, const char *key) diag_set(OutOfMemory, sizeof(*c), "malloc", "c"); return NULL; } - memcmp(c->key, key, sizeof(c->key)); + memcpy(c->key, key, sizeof(c->key)); memset(c->iv, 0, sizeof(c->iv)); c->type = EVP_aes_128_cbc(); return c; diff --git a/test/unit/crypto.c b/test/unit/crypto.c index 4d51e21a2..1ea843664 100644 --- a/test/unit/crypto.c +++ b/test/unit/crypto.c @@ -39,7 +39,7 @@ static void test_aes128_codec(void) { header(); - plan(20); + plan(22); char key[CRYPTO_AES128_KEY_SIZE]; random_bytes(key, sizeof(key)); @@ -99,6 +99,15 @@ test_aes128_codec(void) is(rc, plain_size, "decode works with correct but another IV"); is(memcmp(buffer1, plain, plain_size), 0, "data is the same"); + struct crypto_codec *c2 = crypto_codec_new(CRYPTO_AES128, key); + rc = crypto_codec_encode(c, plain, plain_size, buffer1, buffer_size); + memset(buffer2, 0, rc); + rc = crypto_codec_decode(c2, iv2, buffer1, rc, buffer2, buffer_size); + is(rc, plain_size, "encode with one codec, but decode with another "\ + "codec and the same key"); + is(memcmp(plain, buffer2, plain_size), 0, "data is the same"); + + crypto_codec_delete(c2); crypto_codec_delete(c); check_plan(); diff --git a/test/unit/crypto.result b/test/unit/crypto.result index a3f479be8..735105914 100644 --- a/test/unit/crypto.result +++ b/test/unit/crypto.result @@ -1,7 +1,7 @@ *** main *** 1..2 *** test_aes128_codec *** - 1..20 + 1..22 ok 1 - crypto does not support non-128 AES ok 2 - 128 is supported ok 3 - encode returns needed number of bytes @@ -22,6 +22,8 @@ ok 18 - the encoded data looks different ok 19 - decode works with correct but another IV ok 20 - data is the same + ok 21 - encode with one codec, but decode with another codec and the same key + ok 22 - data is the same ok 1 - subtests *** test_aes128_codec: done *** *** test_aes128_stress *** ====================================================================================