mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 08:14:15 +00:00
assume ElGamal data size as 222 bytes
This commit is contained in:
parent
a8061003dd
commit
d092b21da7
@ -308,12 +308,12 @@ namespace crypto
|
|||||||
BN_free (b1);
|
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
|
// create m
|
||||||
uint8_t m[255];
|
uint8_t m[255];
|
||||||
m[0] = 0xFF;
|
m[0] = 0xFF;
|
||||||
memcpy (m+33, data, len);
|
memcpy (m+33, data, 222);
|
||||||
SHA256 (m+33, 222, m+1);
|
SHA256 (m+33, 222, m+1);
|
||||||
// calculate b = b1*m mod p
|
// calculate b = b1*m mod p
|
||||||
BIGNUM * b = BN_new ();
|
BIGNUM * b = BN_new ();
|
||||||
|
2
Crypto.h
2
Crypto.h
@ -54,7 +54,7 @@ namespace crypto
|
|||||||
ElGamalEncryption (const uint8_t * key);
|
ElGamalEncryption (const uint8_t * key);
|
||||||
~ElGamalEncryption ();
|
~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:
|
private:
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ namespace garlic
|
|||||||
RAND_bytes (elGamal.preIV, 32); // Pre-IV
|
RAND_bytes (elGamal.preIV, 32); // Pre-IV
|
||||||
uint8_t iv[32]; // IV is first 16 bytes
|
uint8_t iv[32]; // IV is first 16 bytes
|
||||||
SHA256(elGamal.preIV, 32, iv);
|
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);
|
m_Encryption.SetIV (iv);
|
||||||
buf += 514;
|
buf += 514;
|
||||||
len += 514;
|
len += 514;
|
||||||
|
@ -102,7 +102,7 @@ namespace tunnel
|
|||||||
htobe32buf (clearText + BUILD_REQUEST_RECORD_SEND_MSG_ID_OFFSET, replyMsgID);
|
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);
|
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 ());
|
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);
|
memcpy (record + BUILD_REQUEST_RECORD_TO_PEER_OFFSET, (const uint8_t *)ident->GetIdentHash (), 16);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user