From 6d017269616c6b295a0a17bc58bc32640af12565 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 1 Nov 2017 10:20:11 -0400 Subject: [PATCH] use AES-CBC for ECICS --- libi2pd/Crypto.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libi2pd/Crypto.cpp b/libi2pd/Crypto.cpp index 329bd5ea..eaa4b17e 100644 --- a/libi2pd/Crypto.cpp +++ b/libi2pd/Crypto.cpp @@ -389,11 +389,12 @@ namespace crypto bn2buf (x, encrypted, len); bn2buf (y, encrypted + len, len); RAND_bytes (encrypted + 2*len, 256 - 2*len); - // ecryption key + // ecryption key and iv EC_POINT_mul (curve, p, nullptr, key, k, ctx); EC_POINT_get_affine_coordinates_GFp (curve, p, x, y, nullptr); - uint8_t keyBuf[64], shared[32]; + uint8_t keyBuf[64], iv[64], shared[32]; bn2buf (x, keyBuf, len); + bn2buf (y, iv, len); SHA256 (keyBuf, len, shared); // create buffer uint8_t m[256]; @@ -401,9 +402,10 @@ namespace crypto memcpy (m+33, data, 222); SHA256 (m+33, 222, m+1); // encrypt - AES_KEY aesKey; - AES_set_encrypt_key (shared, 256, &aesKey); - AES_encrypt (m, encrypted + 256, &aesKey); + CBCEncryption encryption; + encryption.SetKey (shared); + encryption.SetIV (iv); + encryption.Encrypt (m, 256, encrypted + 256); EC_POINT_free (p); BN_CTX_end (ctx); }