Browse Source

use AES-CBC for ECICS

pull/986/head
orignal 7 years ago
parent
commit
6d01726961
  1. 12
      libi2pd/Crypto.cpp

12
libi2pd/Crypto.cpp

@ -389,11 +389,12 @@ namespace crypto
bn2buf (x, encrypted, len); bn2buf (x, encrypted, len);
bn2buf (y, encrypted + len, len); bn2buf (y, encrypted + len, len);
RAND_bytes (encrypted + 2*len, 256 - 2*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_mul (curve, p, nullptr, key, k, ctx);
EC_POINT_get_affine_coordinates_GFp (curve, p, x, y, nullptr); 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 (x, keyBuf, len);
bn2buf (y, iv, len);
SHA256 (keyBuf, len, shared); SHA256 (keyBuf, len, shared);
// create buffer // create buffer
uint8_t m[256]; uint8_t m[256];
@ -401,9 +402,10 @@ namespace crypto
memcpy (m+33, data, 222); memcpy (m+33, data, 222);
SHA256 (m+33, 222, m+1); SHA256 (m+33, 222, m+1);
// encrypt // encrypt
AES_KEY aesKey; CBCEncryption encryption;
AES_set_encrypt_key (shared, 256, &aesKey); encryption.SetKey (shared);
AES_encrypt (m, encrypted + 256, &aesKey); encryption.SetIV (iv);
encryption.Encrypt (m, 256, encrypted + 256);
EC_POINT_free (p); EC_POINT_free (p);
BN_CTX_end (ctx); BN_CTX_end (ctx);
} }

Loading…
Cancel
Save