Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org
Subject: [tarantool-patches] Re: [PATCH 3/3] crypto: implement crypto codec API and AES 128 encryption
Date: Sun, 28 Apr 2019 19:52:52 +0300	[thread overview]
Message-ID: <aa743e76-d682-f92d-3590-8eb161b75d08@tarantool.org> (raw)
In-Reply-To: <0e95f1eff6e2caaab4a2ed344bfdf9e67a9f23b5.1556226152.git.v.shpilevoy@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 ***
====================================================================================

  reply	other threads:[~2019-04-28 16:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25 21:05 [tarantool-patches] [PATCH 0/3] swim encryption preparation Vladislav Shpilevoy
2019-04-25 21:05 ` [tarantool-patches] [PATCH 1/3] crypto: move crypto business into a separate library Vladislav Shpilevoy
2019-04-25 21:05 ` [tarantool-patches] [PATCH 2/3] crypto: make exported methods conform code style Vladislav Shpilevoy
2019-04-25 21:05 ` [tarantool-patches] [PATCH 3/3] crypto: implement crypto codec API and AES 128 encryption Vladislav Shpilevoy
2019-04-28 16:52   ` Vladislav Shpilevoy [this message]
2019-04-29 11:07   ` [tarantool-patches] " Vladislav Shpilevoy
2019-04-29 12:25     ` Konstantin Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa743e76-d682-f92d-3590-8eb161b75d08@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH 3/3] crypto: implement crypto codec API and AES 128 encryption' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox