Use MAC::DIGESTSIZE in ECIES SymmetricEncrypt/SymmetricDecrypt

Fixes #856
pull/857/head
Andrew Wason 2019-07-02 10:47:46 -04:00
parent 18d5e5528f
commit 9c307ff4ba
4 changed files with 48 additions and 3 deletions

View File

@ -716,7 +716,7 @@ public:
if (DHAES_MODE)
{
macKey = key;
cipherKey = key + MAC::DEFAULT_KEYLENGTH;
cipherKey = key + MAC::DIGESTSIZE;
}
else
{
@ -748,7 +748,7 @@ public:
if (DHAES_MODE)
{
macKey = key;
cipherKey = key + MAC::DEFAULT_KEYLENGTH;
cipherKey = key + MAC::DIGESTSIZE;
}
else
{

View File

@ -254,7 +254,7 @@ bool ValidateECP()
}
std::cout << "\nECP validation suite running...\n\n";
return ValidateECP_Agreement() && ValidateECP_Encrypt() && ValidateECP_Sign() && pass;
return ValidateECP_Agreement() && ValidateECP_Encrypt() && ValidateECP_NULLDigest_Encrypt() && ValidateECP_Sign() && pass;
}
bool ValidateEC2N()

View File

@ -139,6 +139,49 @@ bool ValidateECP_Encrypt()
return pass;
}
class NULLHash : public CryptoPP::IteratedHashWithStaticTransform
<CryptoPP::word32, CryptoPP::BigEndian, 32, 0, NULLHash, 0>
{
public:
static void InitState(HashWordType *state) {}
static void Transform(CryptoPP::word32 *digest, const CryptoPP::word32 *data) {}
static const char *StaticAlgorithmName() {return "NULL HASH";}
};
template <class EC, class HASH = SHA1, class COFACTOR_OPTION = NoCofactorMultiplication, bool DHAES_MODE = true, bool LABEL_OCTETS = false>
struct ECIES_NULLDigest
: public DL_ES<
DL_Keys_EC<EC>,
DL_KeyAgreementAlgorithm_DH<typename EC::Point, COFACTOR_OPTION>,
DL_KeyDerivationAlgorithm_P1363<typename EC::Point, DHAES_MODE, P1363_KDF2<HASH> >,
DL_EncryptionAlgorithm_Xor<HMAC<NULLHash>, DHAES_MODE, LABEL_OCTETS>,
ECIES<EC> >
{
// TODO: fix this after name is standardized
CRYPTOPP_STATIC_CONSTEXPR const char* CRYPTOPP_API StaticAlgorithmName() {return "ECIES NULLDigest";}
};
bool ValidateECP_NULLDigest_Encrypt()
{
ECIES_NULLDigest<ECP>::Decryptor cpriv(GlobalRNG(), ASN1::secp256k1());
ECIES_NULLDigest<ECP>::Encryptor cpub(cpriv);
ByteQueue bq;
cpriv.GetKey().DEREncode(bq);
cpub.AccessKey().AccessGroupParameters().SetEncodeAsOID(true);
cpub.GetKey().DEREncode(bq);
cpub.AccessKey().Precompute();
cpriv.AccessKey().Precompute();
bool pass = CryptoSystemValidate(cpriv, cpub);
std::cout << "Turning on point compression..." << std::endl;
cpriv.AccessKey().AccessGroupParameters().SetPointCompression(true);
cpub.AccessKey().AccessGroupParameters().SetPointCompression(true);
pass = CryptoSystemValidate(cpriv, cpub) && pass;
return pass;
}
bool ValidateEC2N_Encrypt()
{
// DEREncode() changed to Save() at Issue 569.

View File

@ -372,6 +372,8 @@ bool ValidateECP_Agreement();
bool ValidateECP_Encrypt();
bool ValidateECP_Sign();
bool ValidateECP_NULLDigest_Encrypt();
bool ValidateEC2N();
bool ValidateEC2N_Agreement();
bool ValidateEC2N_Encrypt();