[tarantool-patches] Re: [PATCH 3/3] crypto: implement crypto codec API and AES 128 encryption
Vladislav Shpilevoy
v.shpilevoy at tarantool.org
Sun Apr 28 19:52:52 MSK 2019
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 ***
====================================================================================
More information about the Tarantool-patches
mailing list