From d092b21da7c4a63b44b59a4ddd24e7ded7f6de63 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 24 Nov 2016 16:02:14 -0500 Subject: [PATCH] assume ElGamal data size as 222 bytes --- Crypto.cpp | 4 ++-- Crypto.h | 2 +- Garlic.cpp | 2 +- TunnelConfig.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Crypto.cpp b/Crypto.cpp index 54180677..91b0ad08 100644 --- a/Crypto.cpp +++ b/Crypto.cpp @@ -308,12 +308,12 @@ namespace crypto BN_free (b1); } - void ElGamalEncryption::Encrypt (const uint8_t * data, int len, uint8_t * encrypted, bool zeroPadding) const + void ElGamalEncryption::Encrypt (const uint8_t * data, uint8_t * encrypted, bool zeroPadding) const { // create m uint8_t m[255]; m[0] = 0xFF; - memcpy (m+33, data, len); + memcpy (m+33, data, 222); SHA256 (m+33, 222, m+1); // calculate b = b1*m mod p BIGNUM * b = BN_new (); diff --git a/Crypto.h b/Crypto.h index ee5f49ca..a04a93da 100644 --- a/Crypto.h +++ b/Crypto.h @@ -54,7 +54,7 @@ namespace crypto ElGamalEncryption (const uint8_t * key); ~ElGamalEncryption (); - void Encrypt (const uint8_t * data, int len, uint8_t * encrypted, bool zeroPadding = false) const; + void Encrypt (const uint8_t * data, uint8_t * encrypted, bool zeroPadding = false) const; private: diff --git a/Garlic.cpp b/Garlic.cpp index 94ca82eb..306ac816 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -188,7 +188,7 @@ namespace garlic RAND_bytes (elGamal.preIV, 32); // Pre-IV uint8_t iv[32]; // IV is first 16 bytes SHA256(elGamal.preIV, 32, iv); - m_ElGamalEncryption->Encrypt ((uint8_t *)&elGamal, sizeof(elGamal), buf, true); + m_ElGamalEncryption->Encrypt ((uint8_t *)&elGamal, buf, true); m_Encryption.SetIV (iv); buf += 514; len += 514; diff --git a/TunnelConfig.h b/TunnelConfig.h index 23417ed9..cb31243f 100644 --- a/TunnelConfig.h +++ b/TunnelConfig.h @@ -102,7 +102,7 @@ namespace tunnel htobe32buf (clearText + BUILD_REQUEST_RECORD_SEND_MSG_ID_OFFSET, replyMsgID); RAND_bytes (clearText + BUILD_REQUEST_RECORD_PADDING_OFFSET, BUILD_REQUEST_RECORD_CLEAR_TEXT_SIZE - BUILD_REQUEST_RECORD_PADDING_OFFSET); i2p::crypto::ElGamalEncryption elGamalEncryption (ident->GetEncryptionPublicKey ()); - elGamalEncryption.Encrypt (clearText, BUILD_REQUEST_RECORD_CLEAR_TEXT_SIZE, record + BUILD_REQUEST_RECORD_ENCRYPTED_OFFSET); + elGamalEncryption.Encrypt (clearText, record + BUILD_REQUEST_RECORD_ENCRYPTED_OFFSET); memcpy (record + BUILD_REQUEST_RECORD_TO_PEER_OFFSET, (const uint8_t *)ident->GetIdentHash (), 16); } };