diff --git a/allocate.cpp b/allocate.cpp index 745eb781..1cb42d9d 100644 --- a/allocate.cpp +++ b/allocate.cpp @@ -27,12 +27,9 @@ NAMESPACE_BEGIN(CryptoPP) void CallNewHandler() { - using std::new_handler; - using std::set_new_handler; - - new_handler newHandler = set_new_handler(NULLPTR); + std::new_handler newHandler = std::set_new_handler(NULLPTR); if (newHandler) - set_new_handler(newHandler); + std::set_new_handler(newHandler); if (newHandler) newHandler(); diff --git a/authenc.cpp b/authenc.cpp index 89a7142d..081e1e1b 100644 --- a/authenc.cpp +++ b/authenc.cpp @@ -22,7 +22,7 @@ void AuthenticatedSymmetricCipherBase::AuthenticateData(const byte *input, size_ { if (num+len >= blockSize) { - memcpy(data+num, input, blockSize-num); + std::memcpy(data+num, input, blockSize-num); AuthenticateBlocks(data, blockSize); input += (blockSize-num); len -= (blockSize-num); @@ -31,7 +31,7 @@ void AuthenticatedSymmetricCipherBase::AuthenticateData(const byte *input, size_ } else { - memcpy(data+num, input, len); + std::memcpy(data+num, input, len); num += (unsigned int)len; return; } @@ -46,7 +46,7 @@ void AuthenticatedSymmetricCipherBase::AuthenticateData(const byte *input, size_ } if (data && len) - memcpy(data, input, len); + std::memcpy(data, input, len); num = (unsigned int)len; } diff --git a/basecode.cpp b/basecode.cpp index 4d93e910..5b230dd6 100644 --- a/basecode.cpp +++ b/basecode.cpp @@ -51,7 +51,7 @@ size_t BaseN_Encoder::Put2(const byte *begin, size_t length, int messageEnd, boo while (m_inputPosition < length) { if (m_bytePos == 0) - memset(m_outBuf, 0, m_outputBlockSize); + std::memset(m_outBuf, 0, m_outputBlockSize); { unsigned int b = begin[m_inputPosition++], bitsLeftInSource = 8; @@ -103,7 +103,7 @@ size_t BaseN_Encoder::Put2(const byte *begin, size_t length, int messageEnd, boo if (m_padding != -1 && m_bytePos > 0) { - memset(m_outBuf+m_bytePos, m_padding, m_outputBlockSize-m_bytePos); + std::memset(m_outBuf+m_bytePos, m_padding, m_outputBlockSize-m_bytePos); m_bytePos = m_outputBlockSize; } FILTER_OUTPUT(2, m_outBuf, m_bytePos, messageEnd); @@ -141,7 +141,7 @@ size_t BaseN_Decoder::Put2(const byte *begin, size_t length, int messageEnd, boo continue; if (m_bytePos == 0 && m_bitPos == 0) - memset(m_outBuf, 0, m_outputBlockSize); + std::memset(m_outBuf, 0, m_outputBlockSize); { int newBitPos = m_bitPos + m_bitsPerChar; diff --git a/blowfish.cpp b/blowfish.cpp index e615da3b..c51f0845 100644 --- a/blowfish.cpp +++ b/blowfish.cpp @@ -13,8 +13,8 @@ void Blowfish::Base::UncheckedSetKey(const byte *key_string, unsigned int keylen unsigned i, j=0, k; word32 data, dspace[2] = {0, 0}; - memcpy(pbox, p_init, sizeof(p_init)); - memcpy(sbox, s_init, sizeof(s_init)); + std::memcpy(pbox, p_init, sizeof(p_init)); + std::memcpy(sbox, s_init, sizeof(s_init)); // Xor key string into encryption key vector for (i=0 ; i= State_IVSet) m_ctr.Resynchronize(m_buffer, REQUIRED_BLOCKSIZE); @@ -60,7 +60,7 @@ void CCM_Base::UncheckedSpecifyDataLengths(lword headerLength, lword messageLeng cbcBuffer[0] = byte(64*(headerLength>0) + 8*((m_digestSize-2)/2) + (m_L-1)); // flag PutWord(true, BIG_ENDIAN_ORDER, cbcBuffer+REQUIRED_BLOCKSIZE-8, m_messageLength); - memcpy(cbcBuffer+1, m_buffer+1, REQUIRED_BLOCKSIZE-1-m_L); + std::memcpy(cbcBuffer+1, m_buffer+1, REQUIRED_BLOCKSIZE-1-m_L); cipher.ProcessBlock(cbcBuffer); if (headerLength>0) diff --git a/cmac.cpp b/cmac.cpp index 3ff57f1e..717aebc9 100644 --- a/cmac.cpp +++ b/cmac.cpp @@ -87,7 +87,7 @@ void CMAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const Name cipher.ProcessBlock(m_reg, m_reg+blockSize); MulU(m_reg+blockSize, blockSize); - memcpy(m_reg+2*blockSize, m_reg+blockSize, blockSize); + std::memcpy(m_reg+2*blockSize, m_reg+blockSize, blockSize); MulU(m_reg+2*blockSize, blockSize); } @@ -153,10 +153,10 @@ void CMAC_Base::TruncatedFinal(byte *mac, size_t size) // UBsan finding if (mac) - memcpy(mac, m_reg, size); + std::memcpy(mac, m_reg, size); m_counter = 0; - memset(m_reg, 0, blockSize); + std::memset(m_reg, 0, blockSize); } NAMESPACE_END diff --git a/default.cpp b/default.cpp index 4ec5d427..f7a48d78 100644 --- a/default.cpp +++ b/default.cpp @@ -48,7 +48,7 @@ static void Mash(const byte *in, size_t inLen, byte *out, size_t outLen, int ite while (iterations-- > 1) { - memcpy(buf, outBuf, bufSize); + std::memcpy(buf, outBuf, bufSize); for (i=0; i> 8); @@ -59,7 +59,7 @@ static void Mash(const byte *in, size_t inLen, byte *out, size_t outLen, int ite } } - memcpy(out, outBuf, outLen); + std::memcpy(out, outBuf, outLen); } template @@ -68,15 +68,15 @@ static void GenerateKeyIV(const byte *passphrase, size_t passphraseLength, const // UBsan. User supplied params, may be NULL SecByteBlock temp(passphraseLength+saltLength); if (passphrase != NULLPTR) - memcpy(temp, passphrase, passphraseLength); + std::memcpy(temp, passphrase, passphraseLength); if (salt != NULLPTR) - memcpy(temp+passphraseLength, salt, saltLength); + std::memcpy(temp+passphraseLength, salt, saltLength); // OK. Derived params, cannot be NULL SecByteBlock keyIV(EnumToInt(Info::KEYLENGTH)+EnumToInt(+Info::BLOCKSIZE)); Mash(temp, passphraseLength + saltLength, keyIV, EnumToInt(Info::KEYLENGTH)+EnumToInt(+Info::BLOCKSIZE), iterations); - memcpy(key, keyIV, Info::KEYLENGTH); - memcpy(IV, keyIV+Info::KEYLENGTH, Info::BLOCKSIZE); + std::memcpy(key, keyIV, Info::KEYLENGTH); + std::memcpy(IV, keyIV+Info::KEYLENGTH, Info::BLOCKSIZE); } // ******************************************************** diff --git a/des.cpp b/des.cpp index 2a130aa4..2e9fb507 100644 --- a/des.cpp +++ b/des.cpp @@ -304,7 +304,7 @@ void RawDES::RawSetKey(CipherDir dir, const byte *key) ? 1 : 0; /* and store 1-bit result */ } for (i=0; i<16; i++) { /* key chunk for each iteration */ - memset(ks,0,8); /* Clear key schedule */ + std::memset(ks,0,8); /* Clear key schedule */ for (j=0; j<56; j++) /* rotate pc1 the right amount */ pcr[j] = pc1m[(l=j+totrot[i])<(j<28? 28 : 56) ? l: l-28]; /* rotate left and right halves independently */ @@ -450,9 +450,9 @@ void DES_XEX3::Base::UncheckedSetKey(const byte *key, unsigned int length, const if (!m_des.get()) m_des.reset(new DES::Encryption); - memcpy(m_x1, key + (IsForwardTransformation() ? 0 : 16), BLOCKSIZE); + std::memcpy(m_x1, key + (IsForwardTransformation() ? 0 : 16), BLOCKSIZE); m_des->RawSetKey(GetCipherDirection(), key + 8); - memcpy(m_x3, key + (IsForwardTransformation() ? 16 : 0), BLOCKSIZE); + std::memcpy(m_x3, key + (IsForwardTransformation() ? 16 : 0), BLOCKSIZE); } void DES_XEX3::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const diff --git a/dll.cpp b/dll.cpp index 2115f9f5..afd863c8 100644 --- a/dll.cpp +++ b/dll.cpp @@ -66,7 +66,7 @@ NAMESPACE_END USING_NAMESPACE(CryptoPP) -using std::set_new_handler; +using set_new_handler; static PNew s_pNew = NULLPTR; static PDelete s_pDelete = NULLPTR; diff --git a/dlltest.cpp b/dlltest.cpp index addced55..119feae6 100644 --- a/dlltest.cpp +++ b/dlltest.cpp @@ -73,7 +73,7 @@ void FIPS140_SampleApplication() decryption_DES_EDE3_CFB.SetKeyWithIV(key, sizeof(key), iv); decryption_DES_EDE3_CFB.ProcessString(decrypted, ciphertext, 24); - if (memcmp(plaintext, decrypted, 24) != 0) + if (std::memcmp(plaintext, decrypted, 24) != 0) { std::cerr << "DES-EDE3-CFB Encryption/decryption failed.\n"; abort(); @@ -89,7 +89,7 @@ void FIPS140_SampleApplication() sha.Update(message, 3); sha.Final(digest); - if (memcmp(digest, expectedDigest, 20) != 0) + if (std::memcmp(digest, expectedDigest, 20) != 0) { std::cerr << "SHA-1 hash failed.\n"; abort(); diff --git a/dmac.h b/dmac.h index 9d911708..5be16ec3 100644 --- a/dmac.h +++ b/dmac.h @@ -90,7 +90,7 @@ void DMAC_Base::TruncatedFinal(byte *mac, size_t size) byte pad[T::BLOCKSIZE]; byte padByte = byte(T::BLOCKSIZE-m_counter); - memset(pad, padByte, padByte); + std::memset(pad, padByte, padByte); m_mac1.Update(pad, padByte); m_mac1.TruncatedFinal(mac, size); m_f2.ProcessBlock(mac); @@ -102,7 +102,7 @@ template byte *DMAC_Base::GenerateSubKeys(const byte *key, size_t keylength) { typename T::Encryption cipher(key, keylength); - memset(m_subkeys, 0, m_subkeys.size()); + std::memset(m_subkeys, 0, m_subkeys.size()); cipher.ProcessBlock(m_subkeys); m_subkeys[m_subkeys.size()/2 + T::BLOCKSIZE - 1] = 1; cipher.ProcessBlock(m_subkeys+m_subkeys.size()/2); diff --git a/donna_32.cpp b/donna_32.cpp index a8c8adad..6a72beea 100644 --- a/donna_32.cpp +++ b/donna_32.cpp @@ -1286,7 +1286,7 @@ expand256_modm(bignum256modm out, const byte *in, size_t len) { bignum256modm_element_t x[16]; bignum256modm q1; - memcpy(work, in, len); + std::memcpy(work, in, len); x[0] = U8TO32_LE(work + 0); x[1] = U8TO32_LE(work + 4); x[2] = U8TO32_LE(work + 8); @@ -1700,7 +1700,7 @@ ge25519_double_scalarmult_vartime(ge25519 *r, const ge25519 *p1, const bignum256 ge25519_pnielsadd(&pre1[i+1], &d1, &pre1[i]); /* set neutral */ - memset(r, 0, sizeof(ge25519)); + std::memset(r, 0, sizeof(ge25519)); r->y[0] = 1; r->z[0] = 1; @@ -1773,7 +1773,7 @@ ge25519_scalarmult_base_niels(ge25519 *r, const byte basepoint_table[256][96], c ge25519_scalarmult_base_choose_niels(&t, basepoint_table, 0, b[1]); curve25519_sub_reduce(r->x, t.xaddy, t.ysubx); curve25519_add_reduce(r->y, t.xaddy, t.ysubx); - memset(r->z, 0, sizeof(bignum25519)); + std::memset(r->z, 0, sizeof(bignum25519)); curve25519_copy(r->t, t.t2d); r->z[0] = 2; for (i = 3; i < 64; i += 2) { diff --git a/donna_64.cpp b/donna_64.cpp index 2f7f9296..31255384 100644 --- a/donna_64.cpp +++ b/donna_64.cpp @@ -978,7 +978,7 @@ expand256_modm(bignum256modm out, const byte *in, size_t len) { bignum256modm_element_t x[16]; bignum256modm q1; - memcpy(work, in, len); + std::memcpy(work, in, len); x[0] = U8TO64_LE(work + 0); x[1] = U8TO64_LE(work + 8); x[2] = U8TO64_LE(work + 16); @@ -1415,7 +1415,7 @@ ge25519_double_scalarmult_vartime(ge25519 *r, const ge25519 *p1, const bignum256 ge25519_pnielsadd(&pre1[i+1], &d1, &pre1[i]); /* set neutral */ - memset(r, 0, sizeof(ge25519)); + std::memset(r, 0, sizeof(ge25519)); r->y[0] = 1; r->z[0] = 1; @@ -1488,7 +1488,7 @@ ge25519_scalarmult_base_niels(ge25519 *r, const byte basepoint_table[256][96], c ge25519_scalarmult_base_choose_niels(&t, basepoint_table, 0, b[1]); curve25519_sub_reduce(r->x, t.xaddy, t.ysubx); curve25519_add_reduce(r->y, t.xaddy, t.ysubx); - memset(r->z, 0, sizeof(bignum25519)); + std::memset(r->z, 0, sizeof(bignum25519)); curve25519_copy(r->t, t.t2d); r->z[0] = 2; for (i = 3; i < 64; i += 2) { diff --git a/drbg.h b/drbg.h index b56256de..b38a6255 100644 --- a/drbg.h +++ b/drbg.h @@ -654,7 +654,7 @@ void HMAC_DRBG::HMAC_Generate(const byte* additional m_hmac.TruncatedFinal(m_v, m_v.size()); size_t count = STDMIN(size, (size_t)HASH::DIGESTSIZE); - memcpy(output, m_v, count); + std::memcpy(output, m_v, count); size -= count; output += count; } diff --git a/eax.cpp b/eax.cpp index 90b9d90b..496762a9 100644 --- a/eax.cpp +++ b/eax.cpp @@ -16,7 +16,7 @@ void EAX_Base::Resync(const byte *iv, size_t len) MessageAuthenticationCode &mac = AccessMAC(); unsigned int blockSize = mac.TagSize(); - memset(m_buffer, 0, blockSize); + std::memset(m_buffer, 0, blockSize); mac.Update(m_buffer, blockSize); mac.CalculateDigest(m_buffer+blockSize, iv, len); @@ -41,7 +41,7 @@ void EAX_Base::AuthenticateLastHeaderBlock() mac.Final(m_buffer); xorbuf(m_buffer+blockSize, m_buffer, blockSize); - memset(m_buffer, 0, blockSize); + std::memset(m_buffer, 0, blockSize); m_buffer[blockSize-1] = 2; mac.Update(m_buffer, blockSize); } diff --git a/elgamal.h b/elgamal.h index c4e1732d..7e1b7825 100644 --- a/elgamal.h +++ b/elgamal.h @@ -69,7 +69,7 @@ public: SecByteBlock block(modulusLen-1); rng.GenerateBlock(block, modulusLen-2-plainTextLength); - memcpy(block+modulusLen-2-plainTextLength, plainText, plainTextLength); + std::memcpy(block+modulusLen-2-plainTextLength, plainText, plainTextLength); block[modulusLen-2] = (byte)plainTextLength; a_times_b_mod_c(Integer(key, modulusLen), Integer(block, modulusLen-1), p).Encode(cipherText, modulusLen); diff --git a/emsa2.cpp b/emsa2.cpp index dd5173dd..fd2b671c 100644 --- a/emsa2.cpp +++ b/emsa2.cpp @@ -31,7 +31,7 @@ void EMSA2Pad::ComputeMessageRepresentative(RandomNumberGenerator& /*rng*/, size_t representativeByteLength = BitsToBytes(representativeBitLength); representative[0] = messageEmpty ? 0x4b : 0x6b; - memset(representative+1, 0xbb, representativeByteLength-digestSize-4); // pad with 0xbb + std::memset(representative+1, 0xbb, representativeByteLength-digestSize-4); // pad with 0xbb byte *afterP2 = representative+representativeByteLength-digestSize-3; afterP2[0] = 0xba; hash.Final(afterP2+1); diff --git a/esign.cpp b/esign.cpp index 7c69a684..10f4e47b 100644 --- a/esign.cpp +++ b/esign.cpp @@ -112,7 +112,7 @@ void InvertibleESIGNFunction::GenerateRandom(RandomNumberGenerator &rng, const N if (param.GetValue("Seed", seedParam)) { seed.resize(seedParam.size() + 4); - memcpy(seed + 4, seedParam.begin(), seedParam.size()); + std::memcpy(seed + 4, seedParam.begin(), seedParam.size()); PutWord(false, BIG_ENDIAN_ORDER, seed, (word32)0); m_p.GenerateRandom(rng, CombinedNameValuePairs(primeParam, MakeParameters("Seed", ConstByteArrayParameter(seed)))); @@ -177,17 +177,7 @@ Integer InvertibleESIGNFunction::CalculateRandomizedInverse(RandomNumberGenerato Integer t = modp.Divide(w0 * r % m_p, m_e * re % m_p); Integer s = r + t*pq; CRYPTOPP_ASSERT(s < m_n); -#if 0 - using namespace std; - cout << "f = " << x << endl; - cout << "r = " << r << endl; - cout << "z = " << z << endl; - cout << "a = " << a << endl; - cout << "w0 = " << w0 << endl; - cout << "w1 = " << w1 << endl; - cout << "t = " << t << endl; - cout << "s = " << s << endl; -#endif + return s; } diff --git a/fhmqv.h b/fhmqv.h index e247e1f2..b2321562 100644 --- a/fhmqv.h +++ b/fhmqv.h @@ -214,7 +214,7 @@ public: void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const { CRYPTOPP_UNUSED(rng); - memcpy(publicKey, privateKey+StaticPrivateKeyLength(), EphemeralPublicKeyLength()); + std::memcpy(publicKey, privateKey+StaticPrivateKeyLength(), EphemeralPublicKeyLength()); } /// \brief Derive agreed value or shared secret diff --git a/filters.cpp b/filters.cpp index 228a0f77..1dff0d08 100644 --- a/filters.cpp +++ b/filters.cpp @@ -292,8 +292,8 @@ size_t FilterWithBufferedInput::BlockQueue::GetAll(byte *outString) size_t size = m_size; size_t numberOfBytes = m_maxBlocks*m_blockSize; const byte *ptr = GetContigousBlocks(numberOfBytes); - memcpy(outString, ptr, numberOfBytes); - memcpy(PtrAdd(outString, numberOfBytes), m_begin, m_size); + std::memcpy(outString, ptr, numberOfBytes); + std::memcpy(PtrAdd(outString, numberOfBytes), m_begin, m_size); m_size = 0; return size; } @@ -307,9 +307,9 @@ void FilterWithBufferedInput::BlockQueue::Put(const byte *inString, size_t lengt byte *end = (m_size < static_cast(PtrDiff(m_buffer.end(), m_begin)) ? PtrAdd(m_begin, m_size) : PtrAdd(m_begin, m_size - m_buffer.size())); size_t len = STDMIN(length, size_t(m_buffer.end()-end)); - memcpy(end, inString, len); + std::memcpy(end, inString, len); if (len < length) - memcpy(m_buffer, PtrAdd(inString, len), length-len); + std::memcpy(m_buffer, PtrAdd(inString, len), length-len); m_size += length; } @@ -536,13 +536,13 @@ size_t ArraySink::Put2(const byte *begin, size_t length, int messageEnd, bool bl { CRYPTOPP_UNUSED(messageEnd); CRYPTOPP_UNUSED(blocking); - // Avoid passing NULL pointer to memcpy. Using memmove due to + // Avoid passing NULL pointer to memcpy. Using std::memmove due to // Valgrind finding on overlapping buffers. size_t copied = 0; if (m_buf && begin) { copied = STDMIN(length, SaturatingSubtract(m_size, m_total)); - memmove(PtrAdd(m_buf, m_total), begin, copied); + std::memmove(PtrAdd(m_buf, m_total), begin, copied); } m_total += copied; return length - copied; @@ -762,8 +762,8 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length) // do padding size_t blockSize = STDMAX(minLastBlockSize, (size_t)m_mandatoryBlockSize); byte* space = HelpCreatePutSpace(*AttachedTransformation(), DEFAULT_CHANNEL, blockSize); - if (inString) {memcpy(space, inString, length);} - memset(PtrAdd(space, length), 0, blockSize - length); + if (inString) {std::memcpy(space, inString, length);} + std::memset(PtrAdd(space, length), 0, blockSize - length); size_t used = m_cipher.ProcessLastBlock(space, blockSize, space, blockSize); AttachedTransformation()->Put(space, used); } @@ -795,23 +795,23 @@ void StreamTransformationFilter::LastPut(const byte *inString, size_t length) if (m_cipher.IsForwardTransformation()) { CRYPTOPP_ASSERT(length < s); - if (inString) {memcpy(space, inString, length);} + if (inString) {std::memcpy(space, inString, length);} if (m_padding == PKCS_PADDING) { CRYPTOPP_ASSERT(s < 256); byte pad = static_cast(s-length); - memset(PtrAdd(space, length), pad, s-length); + std::memset(PtrAdd(space, length), pad, s-length); } else if (m_padding == W3C_PADDING) { CRYPTOPP_ASSERT(s < 256); - memset(PtrAdd(space, length), 0, s-length-1); + std::memset(PtrAdd(space, length), 0, s-length-1); space[s-1] = static_cast(s-length); } else { space[length] = 0x80; - memset(PtrAdd(space, length+1), 0, s-length-1); + std::memset(PtrAdd(space, length+1), 0, s-length-1); } m_cipher.ProcessData(space, space, s); AttachedTransformation()->Put(space, s); @@ -915,7 +915,7 @@ void HashVerificationFilter::FirstPut(const byte *inString) if (m_flags & HASH_AT_BEGIN) { m_expectedHash.New(m_digestSize); - if (inString) {memcpy(m_expectedHash, inString, m_expectedHash.size());} + if (inString) {std::memcpy(m_expectedHash, inString, m_expectedHash.size());} if (m_flags & PUT_HASH) AttachedTransformation()->Put(inString, m_expectedHash.size()); } @@ -1116,7 +1116,7 @@ void SignatureVerificationFilter::FirstPut(const byte *inString) else { m_signature.New(m_verifier.SignatureLength()); - if (inString) {memcpy(m_signature, inString, m_signature.size());} + if (inString) {std::memcpy(m_signature, inString, m_signature.size());} } if (m_flags & PUT_SIGNATURE) diff --git a/fipsalgt.cpp b/fipsalgt.cpp index db0fc538..be5d9d45 100644 --- a/fipsalgt.cpp +++ b/fipsalgt.cpp @@ -274,7 +274,7 @@ protected: for (int k=0; k= HASH_BLOCKSIZE) { @@ -337,8 +337,8 @@ void GCM_Base::Resync(const byte *iv, size_t len) if (len > 0) { - memcpy(m_buffer, iv, len); - memset(m_buffer+len, 0, HASH_BLOCKSIZE-len); + std::memcpy(m_buffer, iv, len); + std::memset(m_buffer+len, 0, HASH_BLOCKSIZE-len); GCM_Base::AuthenticateBlocks(m_buffer, HASH_BLOCKSIZE); } @@ -355,7 +355,7 @@ void GCM_Base::Resync(const byte *iv, size_t len) m_ctr.Seek(HASH_BLOCKSIZE); - memset(hashBuffer, 0, HASH_BLOCKSIZE); + std::memset(hashBuffer, 0, HASH_BLOCKSIZE); } unsigned int GCM_Base::OptimalDataAlignment() const @@ -830,7 +830,7 @@ void GCM_Base::AuthenticateLastHeaderBlock() { if (m_bufferedDataLength > 0) { - memset(m_buffer+m_bufferedDataLength, 0, HASH_BLOCKSIZE-m_bufferedDataLength); + std::memset(m_buffer+m_bufferedDataLength, 0, HASH_BLOCKSIZE-m_bufferedDataLength); m_bufferedDataLength = 0; GCM_Base::AuthenticateBlocks(m_buffer, HASH_BLOCKSIZE); } diff --git a/gfpcrypt.cpp b/gfpcrypt.cpp index 4c257cbd..a6fdc147 100644 --- a/gfpcrypt.cpp +++ b/gfpcrypt.cpp @@ -93,7 +93,7 @@ void DL_SignatureMessageEncodingMethod_DSA::ComputeMessageRepresentative(RandomN const size_t digestSize = hash.DigestSize(); const size_t paddingLength = SaturatingSubtract(representativeByteLength, digestSize); - memset(representative, 0, paddingLength); + std::memset(representative, 0, paddingLength); hash.TruncatedFinal(representative+paddingLength, STDMIN(representativeByteLength, digestSize)); if (digestSize*8 > representativeBitLength) @@ -119,7 +119,7 @@ void DL_SignatureMessageEncodingMethod_NR::ComputeMessageRepresentative(RandomNu const size_t digestSize = hash.DigestSize(); const size_t paddingLength = SaturatingSubtract(representativeByteLength, digestSize); - memset(representative, 0, paddingLength); + std::memset(representative, 0, paddingLength); hash.TruncatedFinal(representative+paddingLength, STDMIN(representativeByteLength, digestSize)); if (digestSize*8 >= representativeBitLength) diff --git a/gfpcrypt.h b/gfpcrypt.h index 9978ae11..b4ac0bf6 100644 --- a/gfpcrypt.h +++ b/gfpcrypt.h @@ -472,7 +472,7 @@ protected: else // block.size() < rlen { size_t offset = rlen - block.size(); - memset(t, '\x00', offset); + std::memset(t, '\x00', offset); std::memcpy(t + offset, block, rlen - offset); } diff --git a/hmac.cpp b/hmac.cpp index 7648ea9e..4d52adfc 100644 --- a/hmac.cpp +++ b/hmac.cpp @@ -26,7 +26,7 @@ void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, con { // hmac.cpp:26:9: runtime error: null pointer passed as argument 2 if (AccessIpad() && userKey && keylength) - memcpy(AccessIpad(), userKey, keylength); + std::memcpy(AccessIpad(), userKey, keylength); } else { @@ -35,7 +35,7 @@ void HMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, con } CRYPTOPP_ASSERT(keylength <= blockSize); - memset(AccessIpad()+keylength, 0, blockSize-keylength); + std::memset(AccessIpad()+keylength, 0, blockSize-keylength); for (unsigned int i=0; i void IteratedHashBase::PadLastBlock(unsi data[num++] = padFirst; if (num <= lastBlockSize) - memset(data+num, 0, lastBlockSize-num); + std::memset(data+num, 0, lastBlockSize-num); else { - memset(data+num, 0, blockSize-num); + std::memset(data+num, 0, blockSize-num); HashBlock(dataBuf); - memset(data, 0, lastBlockSize); + std::memset(data, 0, lastBlockSize); } } diff --git a/kalyna.cpp b/kalyna.cpp index 14d411e1..28302cb6 100644 --- a/kalyna.cpp +++ b/kalyna.cpp @@ -79,8 +79,8 @@ inline void MakeOddKey(const word64 evenkey[NB], word64 oddkey[NB]) const byte* even = reinterpret_cast(evenkey); byte* odd = reinterpret_cast(oddkey); - memcpy(odd, even + V, U - V); - memcpy(odd + U - V, even, V); + std::memcpy(odd, even + V, U - V); + std::memcpy(odd + U - V, even, V); #endif } @@ -421,7 +421,7 @@ void Kalyna128::Base::SetKey_22(const word64 key[2]) word64 *ks = m_wspace+0, *ksc = m_wspace+2, *t1 = m_wspace+4; word64 *t2 = m_wspace+6, *k = m_wspace+8, *kswapped = m_wspace+10; - memset(t1, 0, 2*8); + std::memset(t1, 0, 2*8); t1[0] = (128 + 128 + 64) / 64; AddKey<2>(t1, t2, key); @@ -432,7 +432,7 @@ void Kalyna128::Base::SetKey_22(const word64 key[2]) word64 constant = W64LIT(0x0001000100010001); // round 0 - memcpy(k, key, 16); + std::memcpy(k, key, 16); kswapped[1] = k[0]; kswapped[0] = k[1]; @@ -496,10 +496,10 @@ void Kalyna128::Base::SetKey_24(const word64 key[4]) word64 *ks = m_wspace+0, *ksc = m_wspace+2, *t1 = m_wspace+4, *t2 = m_wspace+6; word64 *k = m_wspace+8, *ka = m_wspace+12, *ko = m_wspace+14; - memset(t1, 0, 2*8); + std::memset(t1, 0, 2*8); t1[0] = (128 + 256 + 64) / 64; - memcpy(ka, key, 16); - memcpy(ko, key + 2, 16); + std::memcpy(ka, key, 16); + std::memcpy(ko, key + 2, 16); AddKey<2>(t1, t2, ka); G128(t2, t1, ko); @@ -509,7 +509,7 @@ void Kalyna128::Base::SetKey_24(const word64 key[4]) word64 constant = W64LIT(0x0001000100010001); // round 0 - memcpy(k, key, 256 / 8); + std::memcpy(k, key, 256 / 8); AddConstant<2>(ks, ksc, constant); AddKey<2>(k, t2, ksc); G128(t2, t1, ksc); @@ -597,7 +597,7 @@ void Kalyna256::Base::SetKey_44(const word64 key[4]) word64 *ks = m_wspace+0, *ksc = m_wspace+4, *t1 = m_wspace+8; word64 *t2 = m_wspace+12, *k = m_wspace+16; - memset(t1, 0, 32); + std::memset(t1, 0, 32); t1[0] = (256 + 256 + 64) / 64; AddKey<4>(t1, t2, key); @@ -608,7 +608,7 @@ void Kalyna256::Base::SetKey_44(const word64 key[4]) word64 constant = W64LIT(0x0001000100010001); // round 0 - memcpy(k, key, 32); + std::memcpy(k, key, 32); AddConstant<4>(ks, ksc, constant); AddKey<4>(k, t2, ksc); G256(t2, t1, ksc); @@ -700,10 +700,10 @@ void Kalyna256::Base::SetKey_48(const word64 key[8]) word64 *ks = m_wspace+0, *ksc = m_wspace+4, *t1 = m_wspace+8, *t2 = m_wspace+12; word64 *k = m_wspace+16, *ka = m_wspace+24, *ko = m_wspace+28; - memset(t1, 0, 4*8); + std::memset(t1, 0, 4*8); t1[0] = (512 + 256 + 64) / 64; - memcpy(ka, key, 32); - memcpy(ko, key+4, 32); + std::memcpy(ka, key, 32); + std::memcpy(ko, key+4, 32); AddKey<4>(t1, t2, ka); G256(t2, t1, ko); @@ -713,7 +713,7 @@ void Kalyna256::Base::SetKey_48(const word64 key[8]) word64 constant = W64LIT(0x0001000100010001); // round 0 - memcpy(k, key, 512 / 8); + std::memcpy(k, key, 512 / 8); AddConstant<4>(ks, ksc, constant); AddKey<4>(k, t2, ksc); G256(t2, t1, ksc); @@ -822,7 +822,7 @@ void Kalyna512::Base::SetKey_88(const word64 key[8]) word64 *ks = m_wspace+0, *ksc = m_wspace+8, *t1 = m_wspace+16; word64 *t2 = m_wspace+24, *k = m_wspace+32; - memset(t1, 0, 8*8); + std::memset(t1, 0, 8*8); t1[0] = (512 + 512 + 64) / 64; AddKey<8>(t1, t2, key); @@ -833,7 +833,7 @@ void Kalyna512::Base::SetKey_88(const word64 key[8]) word64 constant = W64LIT(0x0001000100010001); // round 0 - memcpy(k, key, 512 / 8); + std::memcpy(k, key, 512 / 8); AddConstant<8>(ks, ksc, constant); AddKey<8>(k, t2, ksc); G512(t2, t1, ksc); diff --git a/keccak.cpp b/keccak.cpp index ed69590e..1d2154f8 100644 --- a/keccak.cpp +++ b/keccak.cpp @@ -48,7 +48,7 @@ void Keccak::Update(const byte *input, size_t length) void Keccak::Restart() { - memset(m_state, 0, m_state.SizeInBytes()); + std::memset(m_state, 0, m_state.SizeInBytes()); m_counter = 0; } diff --git a/lsh256.cpp b/lsh256.cpp index 1826542d..65893a04 100644 --- a/lsh256.cpp +++ b/lsh256.cpp @@ -482,8 +482,8 @@ inline void load_iv(lsh_u32 cv_l[8], lsh_u32 cv_r[8], const lsh_u32 iv[16]) inline void zero_iv(lsh_u32 cv_l[8], lsh_u32 cv_r[8]) { - memset(cv_l, 0x00, 8*sizeof(lsh_u32)); - memset(cv_r, 0x00, 8*sizeof(lsh_u32)); + std::memset(cv_l, 0x00, 8*sizeof(lsh_u32)); + std::memset(cv_r, 0x00, 8*sizeof(lsh_u32)); } inline void zero_submsgs(LSH256_Context* ctx) @@ -491,7 +491,7 @@ inline void zero_submsgs(LSH256_Context* ctx) CRYPTOPP_ASSERT(ctx != NULLPTR); lsh_u32* sub_msgs = ctx->sub_msgs; - memset(sub_msgs, 0x00, 32*sizeof(lsh_u32)); + std::memset(sub_msgs, 0x00, 32*sizeof(lsh_u32)); } inline void init224(LSH256_Context* ctx) @@ -534,7 +534,7 @@ inline void get_hash(LSH256_Context* ctx, lsh_u8* pbHashVal) lsh_uint hash_val_bit_len = LSH_GET_SMALL_HASHBIT(alg_type); // Multiplying by looks odd... - memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); + std::memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); if (hash_val_bit_len){ pbHashVal[hash_val_byte_len-1] &= (((lsh_u8)0xff) << hash_val_bit_len); } @@ -614,7 +614,7 @@ lsh_err lsh256_update(LSH256_Context* ctx, const lsh_u8* data, size_t databitlen if (databytelen + remain_msg_byte < LSH256_MSG_BLK_BYTE_LEN) { - memcpy(ctx->last_block + remain_msg_byte, data, databytelen); + std::memcpy(ctx->last_block + remain_msg_byte, data, databytelen); ctx->remain_databitlen += (lsh_uint)databitlen; remain_msg_byte += (lsh_uint)databytelen; if (pos2){ @@ -625,7 +625,7 @@ lsh_err lsh256_update(LSH256_Context* ctx, const lsh_u8* data, size_t databitlen if (remain_msg_byte > 0){ size_t more_byte = LSH256_MSG_BLK_BYTE_LEN - remain_msg_byte; - memcpy(ctx->last_block + remain_msg_byte, data, more_byte); + std::memcpy(ctx->last_block + remain_msg_byte, data, more_byte); compress(ctx, ctx->last_block); data += more_byte; databytelen -= more_byte; @@ -644,7 +644,7 @@ lsh_err lsh256_update(LSH256_Context* ctx, const lsh_u8* data, size_t databitlen } if (databytelen > 0){ - memcpy(ctx->last_block, data, databytelen); + std::memcpy(ctx->last_block, data, databytelen); ctx->remain_databitlen = (lsh_uint)(databytelen << 3); } @@ -676,7 +676,7 @@ lsh_err lsh256_final(LSH256_Context* ctx, lsh_u8* hashval) else{ ctx->last_block[remain_msg_byte] = 0x80; } - memset(ctx->last_block + remain_msg_byte + 1, 0, LSH256_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); + std::memset(ctx->last_block + remain_msg_byte + 1, 0, LSH256_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); compress(ctx, ctx->last_block); @@ -809,7 +809,7 @@ void LSH256_Base::TruncatedFinal(byte *hash, size_t size) LSH256_Base_TruncatedFinal_CXX(m_state, copyOut ? fullHash : hash, size); if (copyOut) - memcpy(hash, fullHash, size); + std::memcpy(hash, fullHash, size); Restart(); } diff --git a/lsh256_avx.cpp b/lsh256_avx.cpp index a3bac453..88df6a17 100644 --- a/lsh256_avx.cpp +++ b/lsh256_avx.cpp @@ -450,7 +450,7 @@ inline void get_hash(LSH256_AVX2_Context* ctx, lsh_u8* pbHashVal) lsh_uint hash_val_bit_len = LSH_GET_SMALL_HASHBIT(alg_type); // Multiplying by looks odd... - memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); + std::memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); if (hash_val_bit_len){ pbHashVal[hash_val_byte_len-1] &= (((lsh_u8)0xff) << hash_val_bit_len); } @@ -536,7 +536,7 @@ lsh_err lsh256_update_avx2(LSH256_AVX2_Context* ctx, const lsh_u8* data, size_t if (databytelen + remain_msg_byte < LSH256_MSG_BLK_BYTE_LEN) { - memcpy(ctx->last_block + remain_msg_byte, data, databytelen); + std::memcpy(ctx->last_block + remain_msg_byte, data, databytelen); ctx->remain_databitlen += (lsh_uint)databitlen; remain_msg_byte += (lsh_uint)databytelen; if (pos2){ @@ -547,7 +547,7 @@ lsh_err lsh256_update_avx2(LSH256_AVX2_Context* ctx, const lsh_u8* data, size_t if (remain_msg_byte > 0){ size_t more_byte = LSH256_MSG_BLK_BYTE_LEN - remain_msg_byte; - memcpy(ctx->last_block + remain_msg_byte, data, more_byte); + std::memcpy(ctx->last_block + remain_msg_byte, data, more_byte); compress(ctx, ctx->last_block); data += more_byte; databytelen -= more_byte; @@ -566,7 +566,7 @@ lsh_err lsh256_update_avx2(LSH256_AVX2_Context* ctx, const lsh_u8* data, size_t } if (databytelen > 0){ - memcpy(ctx->last_block, data, databytelen); + std::memcpy(ctx->last_block, data, databytelen); ctx->remain_databitlen = (lsh_uint)(databytelen << 3); } @@ -601,7 +601,7 @@ lsh_err lsh256_final_avx2(LSH256_AVX2_Context* ctx, lsh_u8* hashval) else{ ctx->last_block[remain_msg_byte] = 0x80; } - memset(ctx->last_block + remain_msg_byte + 1, 0, LSH256_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); + std::memset(ctx->last_block + remain_msg_byte + 1, 0, LSH256_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); compress(ctx, ctx->last_block); diff --git a/lsh256_sse.cpp b/lsh256_sse.cpp index 639b36ba..fe96b789 100644 --- a/lsh256_sse.cpp +++ b/lsh256_sse.cpp @@ -521,7 +521,7 @@ inline void get_hash(LSH256_SSSE3_Context* ctx, lsh_u8* pbHashVal) lsh_uint hash_val_bit_len = LSH_GET_SMALL_HASHBIT(alg_type); // Multiplying by sizeof(lsh_u8) looks odd... - memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); + std::memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); if (hash_val_bit_len){ pbHashVal[hash_val_byte_len-1] &= (((lsh_u8)0xff) << hash_val_bit_len); } @@ -601,7 +601,7 @@ lsh_err lsh256_ssse3_update(LSH256_SSSE3_Context* ctx, const lsh_u8* data, size_ if (databytelen + remain_msg_byte < LSH256_MSG_BLK_BYTE_LEN) { - memcpy(ctx->last_block + remain_msg_byte, data, databytelen); + std::memcpy(ctx->last_block + remain_msg_byte, data, databytelen); ctx->remain_databitlen += (lsh_uint)databitlen; remain_msg_byte += (lsh_uint)databytelen; if (pos2){ @@ -612,7 +612,7 @@ lsh_err lsh256_ssse3_update(LSH256_SSSE3_Context* ctx, const lsh_u8* data, size_ if (remain_msg_byte > 0){ size_t more_byte = LSH256_MSG_BLK_BYTE_LEN - remain_msg_byte; - memcpy(ctx->last_block + remain_msg_byte, data, more_byte); + std::memcpy(ctx->last_block + remain_msg_byte, data, more_byte); compress(ctx, ctx->last_block); data += more_byte; databytelen -= more_byte; @@ -631,7 +631,7 @@ lsh_err lsh256_ssse3_update(LSH256_SSSE3_Context* ctx, const lsh_u8* data, size_ } if (databytelen > 0){ - memcpy(ctx->last_block, data, databytelen); + std::memcpy(ctx->last_block, data, databytelen); ctx->remain_databitlen = (lsh_uint)(databytelen << 3); } @@ -663,7 +663,7 @@ lsh_err lsh256_ssse3_final(LSH256_SSSE3_Context* ctx, lsh_u8* hashval) else{ ctx->last_block[remain_msg_byte] = 0x80; } - memset(ctx->last_block + remain_msg_byte + 1, 0, LSH256_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); + std::memset(ctx->last_block + remain_msg_byte + 1, 0, LSH256_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); compress(ctx, ctx->last_block); diff --git a/lsh512.cpp b/lsh512.cpp index 00b27cd8..aaf162db 100644 --- a/lsh512.cpp +++ b/lsh512.cpp @@ -539,15 +539,15 @@ inline void load_iv(lsh_u64 cv_l[8], lsh_u64 cv_r[8], const lsh_u64 iv[16]) inline void zero_iv(lsh_u64 cv_l[8], lsh_u64 cv_r[8]) { - memset(cv_l, 0, 8*sizeof(lsh_u64)); - memset(cv_r, 0, 8*sizeof(lsh_u64)); + std::memset(cv_l, 0, 8*sizeof(lsh_u64)); + std::memset(cv_r, 0, 8*sizeof(lsh_u64)); } inline void zero_submsgs(LSH512_Context* ctx) { lsh_u64* sub_msgs = ctx->sub_msgs; - memset(sub_msgs, 0x00, 32*sizeof(lsh_u64)); + std::memset(sub_msgs, 0x00, 32*sizeof(lsh_u64)); } inline void init224(LSH512_Context* ctx) @@ -606,7 +606,7 @@ inline void get_hash(LSH512_Context* ctx, lsh_u8* pbHashVal) lsh_uint hash_val_bit_len = LSH_GET_SMALL_HASHBIT(alg_type); // Multiplying by looks odd... - memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); + std::memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); if (hash_val_bit_len){ pbHashVal[hash_val_byte_len-1] &= (((lsh_u8)0xff) << hash_val_bit_len); } @@ -690,7 +690,7 @@ lsh_err lsh512_update(LSH512_Context* ctx, const lsh_u8* data, size_t databitlen } if (databytelen + remain_msg_byte < LSH512_MSG_BLK_BYTE_LEN){ - memcpy(ctx->last_block + remain_msg_byte, data, databytelen); + std::memcpy(ctx->last_block + remain_msg_byte, data, databytelen); ctx->remain_databitlen += (lsh_uint)databitlen; remain_msg_byte += (lsh_uint)databytelen; if (pos2){ @@ -701,7 +701,7 @@ lsh_err lsh512_update(LSH512_Context* ctx, const lsh_u8* data, size_t databitlen if (remain_msg_byte > 0){ size_t more_byte = LSH512_MSG_BLK_BYTE_LEN - remain_msg_byte; - memcpy(ctx->last_block + remain_msg_byte, data, more_byte); + std::memcpy(ctx->last_block + remain_msg_byte, data, more_byte); compress(ctx, ctx->last_block); data += more_byte; databytelen -= more_byte; @@ -720,7 +720,7 @@ lsh_err lsh512_update(LSH512_Context* ctx, const lsh_u8* data, size_t databitlen } if (databytelen > 0){ - memcpy(ctx->last_block, data, databytelen); + std::memcpy(ctx->last_block, data, databytelen); ctx->remain_databitlen = (lsh_uint)(databytelen << 3); } @@ -751,7 +751,7 @@ lsh_err lsh512_final(LSH512_Context* ctx, lsh_u8* hashval) else{ ctx->last_block[remain_msg_byte] = 0x80; } - memset(ctx->last_block + remain_msg_byte + 1, 0, LSH512_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); + std::memset(ctx->last_block + remain_msg_byte + 1, 0, LSH512_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); compress(ctx, ctx->last_block); @@ -885,7 +885,7 @@ void LSH512_Base::TruncatedFinal(byte *hash, size_t size) LSH512_Base_TruncatedFinal_CXX(m_state, copyOut ? fullHash : hash, size); if (copyOut) - memcpy(hash, fullHash, size); + std::memcpy(hash, fullHash, size); Restart(); } diff --git a/lsh512_avx.cpp b/lsh512_avx.cpp index e73234e4..afb3ba24 100644 --- a/lsh512_avx.cpp +++ b/lsh512_avx.cpp @@ -559,7 +559,7 @@ inline void get_hash(LSH512_AVX2_Context* ctx, lsh_u8* pbHashVal) lsh_uint hash_val_bit_len = LSH_GET_SMALL_HASHBIT(alg_type); // Multiplying by sizeof(lsh_u8) looks odd... - memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); + std::memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); if (hash_val_bit_len){ pbHashVal[hash_val_byte_len-1] &= (((lsh_u8)0xff) << hash_val_bit_len); } @@ -649,7 +649,7 @@ lsh_err lsh512_update_avx2(LSH512_AVX2_Context* ctx, const lsh_u8* data, size_t } if (databytelen + remain_msg_byte < LSH512_MSG_BLK_BYTE_LEN){ - memcpy(ctx->last_block + remain_msg_byte, data, databytelen); + std::memcpy(ctx->last_block + remain_msg_byte, data, databytelen); ctx->remain_databitlen += (lsh_uint)databitlen; remain_msg_byte += (lsh_uint)databytelen; if (pos2){ @@ -660,7 +660,7 @@ lsh_err lsh512_update_avx2(LSH512_AVX2_Context* ctx, const lsh_u8* data, size_t if (remain_msg_byte > 0){ size_t more_byte = LSH512_MSG_BLK_BYTE_LEN - remain_msg_byte; - memcpy(ctx->last_block + remain_msg_byte, data, more_byte); + std::memcpy(ctx->last_block + remain_msg_byte, data, more_byte); compress(ctx, ctx->last_block); data += more_byte; databytelen -= more_byte; @@ -679,7 +679,7 @@ lsh_err lsh512_update_avx2(LSH512_AVX2_Context* ctx, const lsh_u8* data, size_t } if (databytelen > 0){ - memcpy(ctx->last_block, data, databytelen); + std::memcpy(ctx->last_block, data, databytelen); ctx->remain_databitlen = (lsh_uint)(databytelen << 3); } @@ -713,7 +713,7 @@ lsh_err lsh512_final_avx2(LSH512_AVX2_Context* ctx, lsh_u8* hashval) else{ ctx->last_block[remain_msg_byte] = 0x80; } - memset(ctx->last_block + remain_msg_byte + 1, 0, LSH512_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); + std::memset(ctx->last_block + remain_msg_byte + 1, 0, LSH512_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); compress(ctx, ctx->last_block); diff --git a/lsh512_sse.cpp b/lsh512_sse.cpp index c6591239..cc08ccef 100644 --- a/lsh512_sse.cpp +++ b/lsh512_sse.cpp @@ -746,7 +746,7 @@ inline void get_hash(LSH512_SSSE3_Context* ctx, lsh_u8* pbHashVal) lsh_uint hash_val_bit_len = LSH_GET_SMALL_HASHBIT(alg_type); // Multiplying by sizeof(lsh_u8) looks odd... - memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); + std::memcpy(pbHashVal, ctx->cv_l, hash_val_byte_len); if (hash_val_bit_len){ pbHashVal[hash_val_byte_len-1] &= (((lsh_u8)0xff) << hash_val_bit_len); } @@ -830,7 +830,7 @@ lsh_err lsh512_update_ssse3(LSH512_SSSE3_Context* ctx, const lsh_u8* data, size_ } if (databytelen + remain_msg_byte < LSH512_MSG_BLK_BYTE_LEN){ - memcpy(ctx->last_block + remain_msg_byte, data, databytelen); + std::memcpy(ctx->last_block + remain_msg_byte, data, databytelen); ctx->remain_databitlen += (lsh_uint)databitlen; remain_msg_byte += (lsh_uint)databytelen; if (pos2){ @@ -841,7 +841,7 @@ lsh_err lsh512_update_ssse3(LSH512_SSSE3_Context* ctx, const lsh_u8* data, size_ if (remain_msg_byte > 0){ size_t more_byte = LSH512_MSG_BLK_BYTE_LEN - remain_msg_byte; - memcpy(ctx->last_block + remain_msg_byte, data, more_byte); + std::memcpy(ctx->last_block + remain_msg_byte, data, more_byte); compress(ctx, ctx->last_block); data += more_byte; databytelen -= more_byte; @@ -860,7 +860,7 @@ lsh_err lsh512_update_ssse3(LSH512_SSSE3_Context* ctx, const lsh_u8* data, size_ } if (databytelen > 0){ - memcpy(ctx->last_block, data, databytelen); + std::memcpy(ctx->last_block, data, databytelen); ctx->remain_databitlen = (lsh_uint)(databytelen << 3); } @@ -891,7 +891,7 @@ lsh_err lsh512_final_ssse3(LSH512_SSSE3_Context* ctx, lsh_u8* hashval) else{ ctx->last_block[remain_msg_byte] = 0x80; } - memset(ctx->last_block + remain_msg_byte + 1, 0, LSH512_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); + std::memset(ctx->last_block + remain_msg_byte + 1, 0, LSH512_MSG_BLK_BYTE_LEN - remain_msg_byte - 1); compress(ctx, ctx->last_block); diff --git a/lubyrack.h b/lubyrack.h index a5d6a18d..30dbe7cf 100644 --- a/lubyrack.h +++ b/lubyrack.h @@ -115,7 +115,7 @@ class LR : public LR_Info, public BlockCipherDocumentation if (xorBlock) xorbuf(outBlock, xorBlock, this->buffer, 2*this->S); else - memcpy(outBlock, this->buffer, 2*this->S); + std::memcpy(outBlock, this->buffer, 2*this->S); } #undef KL #undef KR diff --git a/md2.cpp b/md2.cpp index b0dc7e8b..f91f3faf 100644 --- a/md2.cpp +++ b/md2.cpp @@ -29,9 +29,9 @@ MD2::MD2() void MD2::Init() { - memset(m_X, 0, 48); - memset(m_C, 0, 16); - memset(m_buf, 0, 16); + std::memset(m_X, 0, 48); + std::memset(m_C, 0, 16); + std::memset(m_buf, 0, 16); m_count = 0; } @@ -61,7 +61,7 @@ void MD2::Update(const byte *buf, size_t len) while (len) { unsigned int L = UnsignedMin(16U-m_count, len); - memcpy(m_buf+m_count, buf, L); + std::memcpy(m_buf+m_count, buf, L); m_count+=L; buf+=L; len-=L; @@ -71,7 +71,7 @@ void MD2::Update(const byte *buf, size_t len) int i,j; m_count=0; - memcpy(m_X+16, m_buf, 16); + std::memcpy(m_X+16, m_buf, 16); t=m_C[15]; for(i=0; i<16; i++) { @@ -111,7 +111,7 @@ void MD2::TruncatedFinal(byte *hash, size_t size) for(i=0; i= 16) { word64 r[2], b[2], m[2]; - memcpy(&b, buf, 16); memcpy(&m, mask, 16); + std::memcpy(&b, buf, 16); std::memcpy(&m, mask, 16); r[0] = b[0] ^ m[0]; r[1] = b[1] ^ m[1]; - memcpy(buf, &r, 16); + std::memcpy(buf, &r, 16); buf += 16; mask += 16; count -= 16; } @@ -128,10 +128,10 @@ void xorbuf(byte *buf, const byte *mask, size_t count) while (count >= 4) { word32 r, b, m; - memcpy(&b, buf, 4); memcpy(&m, mask, 4); + std::memcpy(&b, buf, 4); std::memcpy(&m, mask, 4); r = b ^ m; - memcpy(buf, &r, 4); + std::memcpy(buf, &r, 4); buf += 4; mask += 4; count -= 4; } @@ -186,11 +186,11 @@ void xorbuf(byte *output, const byte *input, const byte *mask, size_t count) while (count >= 16) { word64 b[2], m[2], r[2]; - memcpy(&b, input, 16); memcpy(&m, mask, 16); + std::memcpy(&b, input, 16); std::memcpy(&m, mask, 16); r[0] = b[0] ^ m[0]; r[1] = b[1] ^ m[1]; - memcpy(output, &r, 16); + std::memcpy(output, &r, 16); output += 16; input += 16; mask += 16; count -= 16; } @@ -202,10 +202,10 @@ void xorbuf(byte *output, const byte *input, const byte *mask, size_t count) while (count >= 4) { word32 b, m, r; - memcpy(&b, input, 4); memcpy(&m, mask, 4); + std::memcpy(&b, input, 4); std::memcpy(&m, mask, 4); r = b ^ m; - memcpy(output, &r, 4); + std::memcpy(output, &r, 4); output += 4; input += 4; mask += 4; count -= 4; } @@ -226,7 +226,7 @@ bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count) while (count >= 8) { word64 b, m; - memcpy(&b, buf, 8); memcpy(&m, mask, 8); + std::memcpy(&b, buf, 8); std::memcpy(&m, mask, 8); acc64 |= b ^ m; buf += 8; mask += 8; count -= 8; @@ -240,7 +240,7 @@ bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count) while (count >= 4) { word32 b, m; - memcpy(&b, buf, 4); memcpy(&m, mask, 4); + std::memcpy(&b, buf, 4); std::memcpy(&m, mask, 4); acc32 |= b ^ m; buf += 4; mask += 4; count -= 4; diff --git a/misc.h b/misc.h index 9cdf3aaa..f81e81f4 100644 --- a/misc.h +++ b/misc.h @@ -504,14 +504,14 @@ constexpr int EnumToInt(T v) { #if (!__STDC_WANT_SECURE_LIB__ && !defined(_MEMORY_S_DEFINED)) || defined(CRYPTOPP_WANT_SECURE_LIB) -/// \brief Bounds checking replacement for memcpy() +/// \brief Bounds checking replacement for std::memcpy() /// \param dest pointer to the destination memory block /// \param sizeInBytes size of the destination memory block, in bytes /// \param src pointer to the source memory block /// \param count the number of bytes to copy /// \throw InvalidArgument /// \details ISO/IEC TR-24772 provides bounds checking interfaces for potentially -/// unsafe functions like memcpy(), strcpy() and memmove(). However, +/// unsafe functions like std::memcpy(), strcpy() and std::memmove(). However, /// not all standard libraries provides them, like Glibc. The library's /// memcpy_s() is a near-drop in replacement. Its only a near-replacement /// because the library's version throws an InvalidArgument on a bounds violation. @@ -550,14 +550,14 @@ inline void memcpy_s(void *dest, size_t sizeInBytes, const void *src, size_t cou #endif } -/// \brief Bounds checking replacement for memmove() +/// \brief Bounds checking replacement for std::memmove() /// \param dest pointer to the destination memory block /// \param sizeInBytes size of the destination memory block, in bytes /// \param src pointer to the source memory block /// \param count the number of bytes to copy /// \throw InvalidArgument /// \details ISO/IEC TR-24772 provides bounds checking interfaces for potentially -/// unsafe functions like memcpy(), strcpy() and memmove(). However, +/// unsafe functions like std::memcpy(), strcpy() and std::memmove(). However, /// not all standard libraries provides them, like Glibc. The library's /// memmove_s() is a near-drop in replacement. Its only a near-replacement /// because the library's version throws an InvalidArgument on a bounds violation. @@ -595,7 +595,7 @@ inline void memmove_s(void *dest, size_t sizeInBytes, const void *src, size_t co } #if __BORLANDC__ >= 0x620 -// C++Builder 2010 workaround: can't use std::memcpy_s +// C++Builder 2010 workaround: can't use memcpy_s // because it doesn't allow 0 lengths # define memcpy_s CryptoPP::memcpy_s # define memmove_s CryptoPP::memmove_s @@ -630,7 +630,7 @@ inline void vec_swap(T& a, T& b) /// \param ptr pointer to the memory block being written /// \param val the integer value to write for each byte /// \param num the size of the source memory block, in bytes -/// \details Internally the function calls memset with the value val. +/// \details Internally the function calls std::memset with the value val. /// memset_z can be used to initialize a freshly allocated memory block. /// To zeroize a memory block on destruction use SecureWipeBuffer. /// \return the pointer to the memory block diff --git a/modes.cpp b/modes.cpp index a95e7a95..031e26fb 100644 --- a/modes.cpp +++ b/modes.cpp @@ -44,16 +44,16 @@ void CFB_ModePolicy::Iterate(byte *output, const byte *input, CipherDir dir, siz m_cipher->ProcessAndXorBlock(m_register, input, output); if (iterationCount > 1) m_cipher->AdvancedProcessBlocks(output, PtrAdd(input,s), PtrAdd(output,s), (iterationCount-1)*s, 0); - memcpy(m_register, PtrAdd(output,(iterationCount-1)*s), s); + std::memcpy(m_register, PtrAdd(output,(iterationCount-1)*s), s); } else { // make copy first in case of in-place decryption - memcpy(m_temp, PtrAdd(input,(iterationCount-1)*s), s); + std::memcpy(m_temp, PtrAdd(input,(iterationCount-1)*s), s); if (iterationCount > 1) m_cipher->AdvancedProcessBlocks(input, PtrAdd(input,s), PtrAdd(output,s), (iterationCount-1)*s, BlockTransformation::BT_ReverseDirection); m_cipher->ProcessAndXorBlock(m_register, input, output); - memcpy(m_register, m_temp, s); + std::memcpy(m_register, m_temp, s); } } @@ -108,7 +108,7 @@ void OFB_ModePolicy::WriteKeystream(byte *keystreamBuffer, size_t iterationCount m_cipher->ProcessBlock(m_register, keystreamBuffer); if (iterationCount > 1) m_cipher->AdvancedProcessBlocks(keystreamBuffer, NULLPTR, PtrAdd(keystreamBuffer, s), s*(iterationCount-1), 0); - memcpy(m_register, PtrAdd(keystreamBuffer, (iterationCount-1)*s), s); + std::memcpy(m_register, PtrAdd(keystreamBuffer, (iterationCount-1)*s), s); } void OFB_ModePolicy::CipherResynchronize(byte *keystreamBuffer, const byte *iv, size_t length) @@ -204,7 +204,7 @@ void CBC_Encryption::ProcessData(byte *outString, const byte *inString, size_t l m_cipher->AdvancedProcessBlocks(inString, m_register, outString, blockSize, BlockTransformation::BT_XorInput); if (length > blockSize) m_cipher->AdvancedProcessBlocks(PtrAdd(inString,blockSize), outString, PtrAdd(outString,blockSize), length-blockSize, BlockTransformation::BT_XorInput); - memcpy(m_register, PtrAdd(outString, length - blockSize), blockSize); + std::memcpy(m_register, PtrAdd(outString, length - blockSize), blockSize); } size_t CBC_CTS_Encryption::ProcessLastBlock(byte *outString, size_t outLength, const byte *inString, size_t inLength) @@ -219,7 +219,7 @@ size_t CBC_CTS_Encryption::ProcessLastBlock(byte *outString, size_t outLength, c throw InvalidArgument("CBC_Encryption: message is too short for ciphertext stealing"); // steal from IV - memcpy(outString, m_register, inLength); + std::memcpy(outString, m_register, inLength); outString = m_stolenIV; } else @@ -229,13 +229,13 @@ size_t CBC_CTS_Encryption::ProcessLastBlock(byte *outString, size_t outLength, c m_cipher->ProcessBlock(m_register); inString = PtrAdd(inString, blockSize); inLength -= blockSize; - memcpy(PtrAdd(outString, blockSize), m_register, inLength); + std::memcpy(PtrAdd(outString, blockSize), m_register, inLength); } // output last full ciphertext block xorbuf(m_register, inString, inLength); m_cipher->ProcessBlock(m_register); - memcpy(outString, m_register, blockSize); + std::memcpy(outString, m_register, blockSize); return used; } @@ -253,7 +253,7 @@ void CBC_Decryption::ProcessData(byte *outString, const byte *inString, size_t l // save copy now in case of in-place decryption const unsigned int blockSize = BlockSize(); - memcpy(m_temp, PtrAdd(inString, length-blockSize), blockSize); + std::memcpy(m_temp, PtrAdd(inString, length-blockSize), blockSize); if (length > blockSize) m_cipher->AdvancedProcessBlocks(PtrAdd(inString,blockSize), inString, PtrAdd(outString,blockSize), length-blockSize, BlockTransformation::BT_ReverseDirection|BlockTransformation::BT_AllowParallel); m_cipher->ProcessAndXorBlock(inString, m_register, outString); @@ -281,19 +281,19 @@ size_t CBC_CTS_Decryption::ProcessLastBlock(byte *outString, size_t outLength, c } // decrypt last partial plaintext block - memcpy(m_temp, pn2, blockSize); + std::memcpy(m_temp, pn2, blockSize); m_cipher->ProcessBlock(m_temp); xorbuf(m_temp, pn1, inLength); if (stealIV) { - memcpy(outString, m_temp, inLength); + std::memcpy(outString, m_temp, inLength); } else { - memcpy(PtrAdd(outString, blockSize), m_temp, inLength); + std::memcpy(PtrAdd(outString, blockSize), m_temp, inLength); // decrypt next to last plaintext block - memcpy(m_temp, pn1, inLength); + std::memcpy(m_temp, pn1, inLength); m_cipher->ProcessBlock(m_temp); xorbuf(outString, m_temp, m_register, blockSize); } diff --git a/modes.h b/modes.h index 0bf1131d..baa6f865 100644 --- a/modes.h +++ b/modes.h @@ -201,7 +201,7 @@ inline void CopyOrZero(void *dest, size_t dsize, const void *src, size_t ssize) if (src != NULLPTR) memcpy_s(dest, dsize, src, ssize); else - memset(dest, 0, dsize); + std::memset(dest, 0, dsize); } /// \brief OFB block cipher mode of operation diff --git a/mqueue.cpp b/mqueue.cpp index 814c459d..bcde62bf 100644 --- a/mqueue.cpp +++ b/mqueue.cpp @@ -104,7 +104,7 @@ size_t EqualityComparisonFilter::ChannelPut2(const std::string &channel, const b size_t len = length; const byte *data = q2.Spy(len); len = STDMIN(len, length); - if (memcmp(inString, data, len) != 0) + if (std::memcmp(inString, data, len) != 0) goto mismatch; inString += len; length -= len; diff --git a/mqv.h b/mqv.h index 7ab18e55..b7bfc7d4 100644 --- a/mqv.h +++ b/mqv.h @@ -176,7 +176,7 @@ public: void GenerateEphemeralPublicKey(RandomNumberGenerator &rng, const byte *privateKey, byte *publicKey) const { CRYPTOPP_UNUSED(rng); - memcpy(publicKey, privateKey+StaticPrivateKeyLength(), EphemeralPublicKeyLength()); + std::memcpy(publicKey, privateKey+StaticPrivateKeyLength(), EphemeralPublicKeyLength()); } /// \brief Derive agreed value or shared secret diff --git a/oaep.cpp b/oaep.cpp index fb9e31a0..bb150da6 100644 --- a/oaep.cpp +++ b/oaep.cpp @@ -40,9 +40,9 @@ void OAEP_Base::Pad(RandomNumberGenerator &rng, const byte *input, size_t inputL // DB = pHash || 00 ... || 01 || M pHash->CalculateDigest(maskedDB, encodingParameters.begin(), encodingParameters.size()); - memset(maskedDB+hLen, 0, dbLen-hLen-inputLength-1); + std::memset(maskedDB+hLen, 0, dbLen-hLen-inputLength-1); maskedDB[dbLen-inputLength-1] = 0x01; - memcpy(maskedDB+dbLen-inputLength, input, inputLength); + std::memcpy(maskedDB+dbLen-inputLength, input, inputLength); rng.GenerateBlock(maskedSeed, seedLen); member_ptr pMGF(NewMGF()); @@ -89,7 +89,7 @@ DecodingResult OAEP_Base::Unpad(const byte *oaepBlock, size_t oaepBlockLen, byte return DecodingResult(); M++; - memcpy(output, M, maskedDB+dbLen-M); + std::memcpy(output, M, maskedDB+dbLen-M); return DecodingResult(maskedDB+dbLen-M); } diff --git a/osrng.h b/osrng.h index bd534d58..f8b098b7 100644 --- a/osrng.h +++ b/osrng.h @@ -265,7 +265,7 @@ void AutoSeededX917RNG::Reseed(bool blocking, const byte *input, s key = seed + BlockSize; } // check that seed and key don't have same value - while (memcmp(key, seed, STDMIN((size_t)BlockSize, (size_t)KeyLength)) == 0); + while (std::memcmp(key, seed, STDMIN((size_t)BlockSize, (size_t)KeyLength)) == 0); Reseed(key, KeyLength, seed, NULLPTR); } diff --git a/panama.cpp b/panama.cpp index b6d6a0b6..06023a86 100644 --- a/panama.cpp +++ b/panama.cpp @@ -35,7 +35,7 @@ std::string Panama::AlgorithmProvider() const template void Panama::Reset() { - memset(m_state, 0, m_state.SizeInBytes()); + std::memset(m_state, 0, m_state.SizeInBytes()); #if CRYPTOPP_SSSE3_ASM_AVAILABLE && !defined(CRYPTOPP_DISABLE_PANAMA_ASM) m_state[17] = HasSSSE3(); #endif @@ -449,7 +449,7 @@ void PanamaHash::TruncatedFinal(byte *hash, size_t size) this->Iterate(1, NULLPTR, m_buf.BytePtr(), NULLPTR); - memcpy(hash, m_buf, size); + std::memcpy(hash, m_buf, size); this->Restart(); // reinit for next use } @@ -460,7 +460,7 @@ void PanamaCipherPolicy::CipherSetKey(const NameValuePairs ¶ms, const byt { CRYPTOPP_UNUSED(params); CRYPTOPP_UNUSED(length); CRYPTOPP_ASSERT(length==32); - memcpy(m_key, key, 32); + std::memcpy(m_key, key, 32); } template @@ -476,9 +476,9 @@ void PanamaCipherPolicy::CipherResynchronize(byte *keystreamBuffer, const byt else { if (iv) - memcpy(m_buf, iv, 32); + std::memcpy(m_buf, iv, 32); else - memset(m_buf, 0, 32); + std::memset(m_buf, 0, 32); this->Iterate(1, m_buf); } diff --git a/pkcspad.cpp b/pkcspad.cpp index 5192c109..7f5cd209 100644 --- a/pkcspad.cpp +++ b/pkcspad.cpp @@ -80,7 +80,7 @@ void PKCS_EncryptionPaddingScheme::Pad(RandomNumberGenerator& rng, const byte *i pkcsBlock[i] = (byte)rng.GenerateWord32(1, 0xff); pkcsBlock[pkcsBlockLen-inputLen-1] = 0; // separator - memcpy(pkcsBlock+pkcsBlockLen-inputLen, input, inputLen); + std::memcpy(pkcsBlock+pkcsBlockLen-inputLen, input, inputLen); } DecodingResult PKCS_EncryptionPaddingScheme::Unpad(const byte *pkcsBlock, size_t pkcsBlockLen, byte *output, const NameValuePairs& parameters) const @@ -112,7 +112,7 @@ DecodingResult PKCS_EncryptionPaddingScheme::Unpad(const byte *pkcsBlock, size_t if (invalid) return DecodingResult(); - memcpy (output, pkcsBlock+i, outputLen); + std::memcpy (output, pkcsBlock+i, outputLen); return DecodingResult(outputLen); } @@ -147,9 +147,9 @@ void PKCS1v15_SignatureMessageEncodingMethod::ComputeMessageRepresentative(Rando byte *pSeparator = pHashId - 1; // pad with 0xff - memset(pPadding, 0xff, pSeparator-pPadding); + std::memset(pPadding, 0xff, pSeparator-pPadding); *pSeparator = 0; - memcpy(pHashId, hashIdentifier.first, hashIdentifier.second); + std::memcpy(pHashId, hashIdentifier.first, hashIdentifier.second); hash.Final(pDigest); } diff --git a/poly1305.cpp b/poly1305.cpp index 354d76c4..576c003d 100644 --- a/poly1305.cpp +++ b/poly1305.cpp @@ -250,7 +250,7 @@ void Poly1305_Base::Update(const byte *input, size_t length) } if (rem) - memcpy(m_acc, input, rem); + std::memcpy(m_acc, input, rem); m_idx = rem; } @@ -366,7 +366,7 @@ void Poly1305TLS_Base::Update(const byte *input, size_t length) } if (rem) - memcpy(m_acc, input, rem); + std::memcpy(m_acc, input, rem); m_idx = rem; } diff --git a/pssr.cpp b/pssr.cpp index 753797ba..a9f43051 100644 --- a/pssr.cpp +++ b/pssr.cpp @@ -84,7 +84,7 @@ void PSSR_MEM_Base::ComputeMessageRepresentative(RandomNumberGenerator &rng, xorbuf(xorStart + 1 + recoverableMessageLength, salt, salt.size()); if (hashIdentifier.first && hashIdentifier.second) { - memcpy(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second); + std::memcpy(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second); representative[representativeByteLength - 1] = 0xcc; } else @@ -134,7 +134,7 @@ DecodingResult PSSR_MEM_Base::RecoverMessageFromRepresentative( recoverableMessageLength <= MaxRecoverableLength(representativeBitLength, hashIdentifier.second, digestSize)) { if (recoverableMessage) - memcpy(recoverableMessage, M+1, recoverableMessageLength); + std::memcpy(recoverableMessage, M+1, recoverableMessageLength); } else { diff --git a/queue.cpp b/queue.cpp index 021e86a0..8b302366 100644 --- a/queue.cpp +++ b/queue.cpp @@ -50,7 +50,7 @@ public: if (!begin || !length) return length; size_t l = STDMIN(length, MaxSize()-m_tail); if (m_buf+m_tail != begin) - memcpy(m_buf+m_tail, begin, l); + std::memcpy(m_buf+m_tail, begin, l); m_tail += l; return l; } @@ -67,7 +67,7 @@ public: inline size_t Peek(byte *target, size_t copyMax) const { size_t len = STDMIN(copyMax, m_tail-m_head); - memcpy(target, m_buf+m_head, len); + std::memcpy(target, m_buf+m_head, len); return len; } @@ -410,7 +410,7 @@ void ByteQueue::Unget(const byte *inString, size_t length) size_t len = STDMIN(length, m_head->m_head); length -= len; m_head->m_head = m_head->m_head - len; - memcpy(m_head->m_buf + m_head->m_head, inString + length, len); + std::memcpy(m_head->m_buf + m_head->m_head, inString + length, len); if (length > 0) { diff --git a/rc2.cpp b/rc2.cpp index 1469cc59..9bb428a8 100644 --- a/rc2.cpp +++ b/rc2.cpp @@ -34,7 +34,7 @@ void RC2::Base::UncheckedSetKey(const byte *key, unsigned int keyLen, const Name 197,243,219, 71,229,165,156,119, 10,166, 32,104,254,127,193,173}; SecByteBlock L(128); - memcpy(L, key, keyLen); + std::memcpy(L, key, keyLen); int i; for (i=keyLen; i<128; i++) diff --git a/rng.cpp b/rng.cpp index 1bb525e9..4b85ef76 100644 --- a/rng.cpp +++ b/rng.cpp @@ -69,8 +69,8 @@ X917RNG::X917RNG(BlockTransformation *c, const byte *seed, const byte *determini // Garbage in the tail creates a non-conforming X9.17 or X9.31 generator. if (m_size > 8) { - memset(m_datetime, 0x00, m_size); - memset(m_lastBlock, 0x00, m_size); + std::memset(m_datetime, 0x00, m_size); + std::memset(m_lastBlock, 0x00, m_size); } if (!deterministicTimeVector) @@ -115,7 +115,7 @@ void X917RNG::GenerateIntoBufferedTransformation(BufferedTransformation &target, // generate a new block of random bytes m_cipher->ProcessBlock(m_randseed); - if (memcmp(m_lastBlock, m_randseed, m_size) == 0) + if (std::memcmp(m_lastBlock, m_randseed, m_size) == 0) throw SelfTestFailure("X917RNG: Continuous random number generator test failed."); // output random bytes @@ -124,7 +124,7 @@ void X917RNG::GenerateIntoBufferedTransformation(BufferedTransformation &target, size -= len; // compute new seed vector - memcpy(m_lastBlock, m_randseed, m_size); + std::memcpy(m_lastBlock, m_randseed, m_size); xorbuf(m_randseed, m_datetime, m_size); m_cipher->ProcessBlock(m_randseed); } diff --git a/salsa.cpp b/salsa.cpp index 987cd302..7536a3c1 100644 --- a/salsa.cpp +++ b/salsa.cpp @@ -713,7 +713,7 @@ void XSalsa20_Policy::CipherSetKey(const NameValuePairs ¶ms, const byte *key GetUserKey(LITTLE_ENDIAN_ORDER, m_key.begin(), m_key.size(), key, length); if (length == 16) - memcpy(m_key.begin()+4, m_key.begin(), 16); + std::memcpy(m_key.begin()+4, m_key.begin(), 16); // "expand 32-byte k" m_state[0] = 0x61707865; diff --git a/seal.cpp b/seal.cpp index fea047e7..9328e6dd 100644 --- a/seal.cpp +++ b/seal.cpp @@ -24,7 +24,7 @@ struct SEAL_Gamma : H(5), Z(5), D(16), lastIndex(0xffffffff) { GetUserKey(BIG_ENDIAN_ORDER, H.begin(), 5, key, 20); - memset(D, 0, 64); + std::memset(D, 0, 64); } word32 Apply(word32 i); @@ -38,7 +38,7 @@ word32 SEAL_Gamma::Apply(word32 i) word32 shaIndex = i/5; if (shaIndex != lastIndex) { - memcpy(Z, H, 20); + std::memcpy(Z, H, 20); D[0] = shaIndex; SHA1::Transform(Z, D); lastIndex = shaIndex; diff --git a/secblock.h b/secblock.h index 56b5be6d..64d77690 100644 --- a/secblock.h +++ b/secblock.h @@ -792,7 +792,7 @@ public: if (m_ptr && ptr) memcpy_s(m_ptr, m_size*sizeof(T), ptr, len*sizeof(T)); else if (m_ptr && m_size) - memset(m_ptr, 0, m_size*sizeof(T)); + std::memset(m_ptr, 0, m_size*sizeof(T)); } ~SecBlock() @@ -888,7 +888,7 @@ public: /// \param ptr a pointer to an array of T /// \param len the number of elements in the memory block /// \details The array pointed to by ptr must be distinct - /// from this SecBlock because Assign() calls New() and then memcpy(). + /// from this SecBlock because Assign() calls New() and then std::memcpy(). /// The call to New() will invalidate all pointers and iterators, like /// the pointer returned from data(). /// \details If the memory block is reduced in size, then the reclaimed @@ -941,7 +941,7 @@ public: /// \param len the number of elements in the memory block /// \throw InvalidArgument if resulting size would overflow /// \details The array pointed to by ptr must be distinct - /// from this SecBlock because Append() calls Grow() and then memcpy(). + /// from this SecBlock because Append() calls Grow() and then std::memcpy(). /// The call to Grow() will invalidate all pointers and iterators, like /// the pointer returned from data(). /// \details Append() may be less efficient than a ByteQueue because diff --git a/sha.cpp b/sha.cpp index 167f39dc..97436a5c 100644 --- a/sha.cpp +++ b/sha.cpp @@ -421,7 +421,7 @@ void SHA256_HashBlock_CXX(word32 *state, const word32 *data) { word32 W[16]={0}, T[8]; /* Copy context->state[] to working vars */ - memcpy(T, state, sizeof(T)); + std::memcpy(T, state, sizeof(T)); /* 64 operations, partially loop unrolled */ for (unsigned int j=0; j<64; j+=16) { @@ -503,7 +503,7 @@ void SHA224::InitState(HashWordType *state) static const word32 s[8] = { 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4}; - memcpy(state, s, sizeof(s)); + std::memcpy(state, s, sizeof(s)); } void SHA256::InitState(HashWordType *state) @@ -511,7 +511,7 @@ void SHA256::InitState(HashWordType *state) static const word32 s[8] = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; - memcpy(state, s, sizeof(s)); + std::memcpy(state, s, sizeof(s)); } #endif // Not CRYPTOPP_GENERATE_X64_MASM @@ -1096,7 +1096,7 @@ void SHA384::InitState(HashWordType *state) W64LIT(0x9159015a3070dd17), W64LIT(0x152fecd8f70e5939), W64LIT(0x67332667ffc00b31), W64LIT(0x8eb44a8768581511), W64LIT(0xdb0c2e0d64f98fa7), W64LIT(0x47b5481dbefa4fa4)}; - memcpy(state, s, sizeof(s)); + std::memcpy(state, s, sizeof(s)); } void SHA512::InitState(HashWordType *state) @@ -1106,7 +1106,7 @@ void SHA512::InitState(HashWordType *state) W64LIT(0x3c6ef372fe94f82b), W64LIT(0xa54ff53a5f1d36f1), W64LIT(0x510e527fade682d1), W64LIT(0x9b05688c2b3e6c1f), W64LIT(0x1f83d9abfb41bd6b), W64LIT(0x5be0cd19137e2179)}; - memcpy(state, s, sizeof(s)); + std::memcpy(state, s, sizeof(s)); } #if CRYPTOPP_SSE2_ASM_AVAILABLE && (CRYPTOPP_BOOL_X86) diff --git a/sha3.cpp b/sha3.cpp index 35de1b13..8ed005b0 100644 --- a/sha3.cpp +++ b/sha3.cpp @@ -52,7 +52,7 @@ void SHA3::Update(const byte *input, size_t length) void SHA3::Restart() { - memset(m_state, 0, m_state.SizeInBytes()); + std::memset(m_state, 0, m_state.SizeInBytes()); m_counter = 0; } diff --git a/shake.cpp b/shake.cpp index 65e08235..87e32296 100644 --- a/shake.cpp +++ b/shake.cpp @@ -48,7 +48,7 @@ void SHAKE::Update(const byte *input, size_t length) void SHAKE::Restart() { - memset(m_state, 0, m_state.SizeInBytes()); + std::memset(m_state, 0, m_state.SizeInBytes()); m_counter = 0; } diff --git a/siphash.h b/siphash.h index 767c37ce..996156c9 100644 --- a/siphash.h +++ b/siphash.h @@ -162,7 +162,7 @@ void SipHash_Base::Update(const byte *input, size_t length) if (m_idx) { size_t head = STDMIN(size_t(8U-m_idx), length); - memcpy(m_acc+m_idx, input, head); + std::memcpy(m_acc+m_idx, input, head); m_idx += head; input += head; length -= head; if (m_idx == 8) @@ -197,7 +197,7 @@ void SipHash_Base::Update(const byte *input, size_t length) size_t tail = length % 8; if (tail) { - memcpy(m_acc+m_idx, input, tail); + std::memcpy(m_acc+m_idx, input, tail); m_idx += tail; } } diff --git a/stdcpp.h b/stdcpp.h index 8bda2904..592b5f39 100644 --- a/stdcpp.h +++ b/stdcpp.h @@ -95,7 +95,7 @@ namespace std { // C++Builder's standard library (Dinkumware) do not have C's global log() function // https://github.com/weidai11/cryptopp/issues/520 #ifdef __BORLANDC__ -using std::log; +using log; #endif #endif // CRYPTOPP_STDCPP_H diff --git a/tiger.cpp b/tiger.cpp index c71cdc2f..749818ee 100644 --- a/tiger.cpp +++ b/tiger.cpp @@ -46,7 +46,7 @@ void Tiger::TruncatedFinal(byte *digest, size_t digestSize) Transform(m_state, m_data); CorrectEndianess(m_state, m_state, DigestSize()); - memcpy(digest, m_state, digestSize); + std::memcpy(digest, m_state, digestSize); Restart(); // reinit for next use } diff --git a/ttmac.cpp b/ttmac.cpp index db7e3485..c856d97b 100644 --- a/ttmac.cpp +++ b/ttmac.cpp @@ -44,7 +44,7 @@ void TTMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, co { AssertValidKeyLength(keylength); - memcpy(m_key, userKey, KEYLENGTH); + std::memcpy(m_key, userKey, KEYLENGTH); CorrectEndianess(m_key, m_key, KEYLENGTH); Init(); @@ -105,7 +105,7 @@ void TTMAC_Base::TruncatedFinal(byte *hash, size_t size) } CorrectEndianess(m_digest, m_digest, size); - memcpy(hash, m_digest, size); + std::memcpy(hash, m_digest, size); Restart(); // reinit for next use } diff --git a/validat1.cpp b/validat1.cpp index fa9ae597..d978d17c 100644 --- a/validat1.cpp +++ b/validat1.cpp @@ -846,7 +846,7 @@ bool TestSecBlock() { static const unsigned int SIZE = 8; SecBlockWithHint block(SIZE); - memset(block, 0xaa, block.SizeInBytes()); + std::memset(block, 0xaa, block.SizeInBytes()); temp = true; block.CleanGrow(SIZE*2); @@ -883,7 +883,7 @@ bool TestSecBlock() { static const unsigned int SIZE = 8; SecBlockWithHint block(SIZE); - memset(block, 0xaa, block.SizeInBytes()); + std::memset(block, 0xaa, block.SizeInBytes()); temp = true; block.CleanGrow(SIZE*2); @@ -921,7 +921,7 @@ bool TestSecBlock() { static const unsigned int SIZE = 8; SecBlockWithHint block(SIZE); - memset(block, 0xaa, block.SizeInBytes()); + std::memset(block, 0xaa, block.SizeInBytes()); temp = true; block.CleanGrow(SIZE*2); @@ -960,7 +960,7 @@ bool TestSecBlock() { static const unsigned int SIZE = 8; SecBlock > block(SIZE); - memset(block, 0xaa, block.SizeInBytes()); + std::memset(block, 0xaa, block.SizeInBytes()); temp = true; block.CleanGrow(SIZE*2); diff --git a/validat3.cpp b/validat3.cpp index f941ce5c..b153de1b 100644 --- a/validat3.cpp +++ b/validat3.cpp @@ -997,7 +997,7 @@ bool ValidateHashDRBG() "\xBD\x0F\x05\xF2\x5A\x69\x88\xC1\x74\x36\x39\x62\x27\x18\x4A\xF8\x4A\x56\x43\x35" "\x65\x8E\x2F\x85\x72\xBE\xA3\x33\xEE\xE2\xAB\xFF\x22\xFF\xA6\xDE\x3E\x22\xAC\xA2"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (COUNT=0, E=16, N=8)\n"; @@ -1022,7 +1022,7 @@ bool ValidateHashDRBG() "\x80\x2E\x68\x05\x4A\xAB\xA8\x7C\xD6\x3A\xD3\xE5\xC9\x7C\x06\xE7\xA3\x9F\xF6\xF9" "\x8E\xB3\xD9\x72\xD4\x11\x35\xE5\xE7\x46\x1B\x49\x9C\x56\x45\x6A\xBE\x7F\x77\xD4"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (COUNT=1, E=16, N=8)\n"; @@ -1050,7 +1050,7 @@ bool ValidateHashDRBG() "\x58\x70\xB3\x39\x46\x8C\xDD\x8D\x6F\xAF\x8C\x56\x16\x3A\x70\x0A\x75\xB2\x3E\x59" "\x9B\x5A\xEC\xF1\x6F\x3B\xAF\x6D\x5F\x24\x19\x97\x1F\x24\xF4\x46\x72\x0F\xEA\xBE"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=0, E=16, N=8, A=16)\n"; @@ -1078,7 +1078,7 @@ bool ValidateHashDRBG() "\x06\x94\x41\xD6\xB5\xC5\x44\x60\x54\x07\xE8\xE7\xDC\x1C\xD8\xE4\x70\xAD\x84\x77" "\x5A\x65\x31\xBE\xE0\xFC\x81\x36\xE2\x8F\x0B\xFE\xEB\xE1\x98\x62\x7E\x98\xE0\xC1"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=1, E=16, N=8, A=16)\n"; @@ -1104,7 +1104,7 @@ bool ValidateHashDRBG() "\xB6\xC5\x68\xD8\x40\x6E\x2B\xD4\x3D\x23\xEB\x0F\x10\xBA\x5F\x24\x9C\xC9\xE9\x4A" "\xD3\xA5\xF1\xDF\xA4\xF2\xB4\x80\x40\x91\xED\x8C\xD6\x6D\xE7\xB7\x53\xB2\x09\xD5"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=0, E=16, N=8, A=0, P=16)\n"; @@ -1130,7 +1130,7 @@ bool ValidateHashDRBG() "\xDC\x16\xBC\x5F\x69\xE5\xBB\x05\xD1\x43\x8F\x80\xAB\xC5\x8F\x9C\x3F\x75\x57\xEB" "\x44\x0D\xF5\x0C\xF4\x95\x23\x94\x67\x11\x55\x98\x14\x43\xFF\x13\x14\x85\x5A\xBC"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=1, E=16, N=8, A=0, P=16)\n"; @@ -1159,7 +1159,7 @@ bool ValidateHashDRBG() "\xDD\x92\x33\x78\x6D\x5D\x41\xFF\xFA\xE9\x80\x59\x04\x85\x21\xE2\x52\x84\xBC\x6F" "\xDB\x97\xF3\x4E\x6A\x12\x7A\xCD\x41\x0F\x50\x68\x28\x46\xBE\x56\x9E\x9A\x6B\xC8"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=0, E=16, N=8, A=16, P=16)\n"; @@ -1188,7 +1188,7 @@ bool ValidateHashDRBG() "\x73\x91\x27\xE9\x31\xC0\x55\x55\x11\xE8\xB6\x57\x02\x0D\xCE\x90\xAC\x31\xB9\x00" "\x31\xC1\xD4\x4F\xE7\x12\x3B\xCC\x85\x16\x2F\x12\x8F\xB2\xDF\x84\x4E\xF7\x06\xBE"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA1/128/440 (C0UNT=1, E=16, N=8, A=16, P=16)\n"; @@ -1220,7 +1220,7 @@ bool ValidateHashDRBG() "\xE1\x03\x3A\x76\x54\xFF\xD7\x24\x70\x5E\x8C\xB2\x41\x7D\x92\x0A\x2F\x4F\x27\xB8" "\x45\x13\x7F\xFB\x87\x90\xA9\x49"; - fail = !!memcmp(result, expected, 1024/8); + fail = !!std::memcmp(result, expected, 1024/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA256/128/440 (C0UNT=0, E=32, N=16, A=32, P=32)\n"; @@ -1252,7 +1252,7 @@ bool ValidateHashDRBG() "\xDB\xB1\xED\x94\x12\x6A\x2F\x03\x98\x4A\xD4\xD1\x72\xF3\x7A\x66\x74\x7E\x2A\x5B" "\xDE\xEF\x43\xBC\xB9\x8C\x49\x01"; - fail = !!memcmp(result, expected, 1024/8); + fail = !!std::memcmp(result, expected, 1024/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA256/128/440 (C0UNT=1, E=32, N=16, A=32, P=32)\n"; @@ -1290,7 +1290,7 @@ bool ValidateHashDRBG() "\xF2\x86\xE4\xED\x74\xF2\x5D\x8B\x6C\x4D\xB8\xDE\xD8\x4A\xD6\x5E\xD6\x6D\xAE\xB1" "\x1B\xA2\x94\x52\x54\xAD\x3C\x3D\x25\xBD\x12\x46\x3C\xA0\x45\x9D"; - fail = !!memcmp(result, expected, 2048/8); + fail = !!std::memcmp(result, expected, 2048/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA512/256/888 (C0UNT=0, E=32, N=16, A=32, P=32)\n"; @@ -1328,7 +1328,7 @@ bool ValidateHashDRBG() "\x7D\x21\x14\x34\xA5\x87\x43\xA4\x0A\x96\x77\x00\xCC\xCA\xB1\xDA\xC4\x39\xE0\x66" "\x37\x05\x6E\xAC\xF2\xE6\xC6\xC5\x4F\x79\xD3\xE5\x6A\x3D\x36\x3F"; - fail = !!memcmp(result, expected, 2048/8); + fail = !!std::memcmp(result, expected, 2048/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "Hash_DRBG SHA512/256/888 (C0UNT=1, E=32, N=16, A=32, P=32)\n"; diff --git a/validat4.cpp b/validat4.cpp index e41c1c8b..149a32a6 100644 --- a/validat4.cpp +++ b/validat4.cpp @@ -97,7 +97,7 @@ bool ValidateHmacDRBG() "\x94\xf1\xc1\xa5\xcf\x73\x22\xec\x1a\xe0\x96\x4e\xd4\xbf\x12\x27\x46\xe0\x87\xfd" "\xb5\xb3\xe9\x1b\x34\x93\xd5\xbb\x98\xfa\xed\x49\xe8\x5f\x13\x0f\xc8\xa4\x59\xb7"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=0, E=16, N=8)\n"; @@ -122,7 +122,7 @@ bool ValidateHmacDRBG() "\xf5\x90\xf6\xc9\xb3\x8b\x46\x5b\x78\x3e\xcf\xf1\x3a\x77\x50\x20\x1f\x7e\xcf\x1b" "\x8a\xb3\x93\x60\x4c\x73\xb2\x38\x93\x36\x60\x9a\xf3\x44\x0c\xde\x43\x29\x8b\x84"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=1, E=16, N=8)\n"; @@ -152,7 +152,7 @@ bool ValidateHmacDRBG() "\x9d\xc3\x36\x52\xab\x58\xec\xb7\x65\x0e\xd8\x04\x67\xf7\x6a\x84\x9f\xb1\xcf\xc1" "\xed\x0a\x09\xf7\x15\x50\x86\x06\x4d\xb3\x24\xb1\xe1\x24\xf3\xfc\x9e\x61\x4f\xcb"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=0, E=16, N=8, A=16)\n"; @@ -180,7 +180,7 @@ bool ValidateHmacDRBG() "\xdb\x7a\x6e\x8e\x7a\xb9\x4c\x05\x50\x0b\x4d\x1e\x35\x7d\xf8\xe9\x57\xac\x89\x37" "\xb0\x5f\xb3\xd0\x80\xa0\xf9\x06\x74\xd4\x4d\xe1\xbd\x6f\x94\xd2\x95\xc4\x51\x9d"; - fail = !!memcmp(result, expected, 640/8); + fail = !!std::memcmp(result, expected, 640/8); pass = !fail && pass; std::cout << (fail ? "FAILED " : "passed ") << "HMAC_DRBG SHA1/128/440 (COUNT=1, E=16, N=8, A=16)\n"; @@ -249,11 +249,11 @@ bool BlockTransformationTest(const CipherFactory &cg, BufferedTransformation &va member_ptr transE(cg.NewEncryption(key)); transE->ProcessBlock(plain, out); - fail = memcmp(out, cipher, cg.BlockSize()) != 0; + fail = std::memcmp(out, cipher, cg.BlockSize()) != 0; member_ptr transD(cg.NewDecryption(key)); transD->ProcessBlock(out, outplain); - fail=fail || memcmp(outplain, plain, cg.BlockSize()); + fail=fail || std::memcmp(outplain, plain, cg.BlockSize()); pass = pass && !fail; @@ -522,7 +522,7 @@ bool ValidateCipherModes() modeE.SetStolenIV(stolenIV); fail = !TestFilter(StreamTransformationFilter(modeE).Ref(), plain, 3, encrypted, sizeof(encrypted)); - fail = memcmp(stolenIV, decryptionIV, 8) != 0 || fail; + fail = std::memcmp(stolenIV, decryptionIV, 8) != 0 || fail; pass = pass && !fail; std::cout << (fail ? "FAILED " : "passed ") << "CBC encryption with ciphertext and IV stealing" << std::endl; @@ -690,11 +690,11 @@ bool ValidateRC2() member_ptr transE(new RC2Encryption(key, keyLen, effectiveLen)); transE->ProcessBlock(plain, out); - fail = memcmp(out, cipher, RC2Encryption::BLOCKSIZE) != 0; + fail = std::memcmp(out, cipher, RC2Encryption::BLOCKSIZE) != 0; member_ptr transD(new RC2Decryption(key, keyLen, effectiveLen)); transD->ProcessBlock(out, outplain); - fail=fail || memcmp(outplain, plain, RC2Encryption::BLOCKSIZE); + fail=fail || std::memcmp(outplain, plain, RC2Encryption::BLOCKSIZE); pass = pass && !fail; @@ -843,13 +843,13 @@ bool ValidateARC4() arc4.reset(new Weak::ARC4(Key0, sizeof(Key0))); arc4->ProcessString(Input0, sizeof(Input0)); - fail = memcmp(Input0, Output0, sizeof(Input0)) != 0; + fail = std::memcmp(Input0, Output0, sizeof(Input0)) != 0; std::cout << (fail ? "FAILED" : "passed") << " Test 0" << std::endl; pass = pass && !fail; arc4.reset(new Weak::ARC4(Key1, sizeof(Key1))); arc4->ProcessString(Key1, Input1, sizeof(Key1)); - fail = memcmp(Output1, Key1, sizeof(Key1)) != 0; + fail = std::memcmp(Output1, Key1, sizeof(Key1)) != 0; std::cout << (fail ? "FAILED" : "passed") << " Test 1" << std::endl; pass = pass && !fail; @@ -1107,11 +1107,11 @@ bool ValidateBlowfish() { ECB_Mode::Encryption enc2((byte *)key[i], strlen(key[i])); enc2.ProcessData(out, plain[i], 8); - fail = memcmp(out, cipher[i], 8) != 0; + fail = std::memcmp(out, cipher[i], 8) != 0; ECB_Mode::Decryption dec2((byte *)key[i], strlen(key[i])); dec2.ProcessData(outplain, cipher[i], 8); - fail = fail || memcmp(outplain, plain[i], 8); + fail = fail || std::memcmp(outplain, plain[i], 8); pass3 = pass3 && !fail; std::cout << (fail ? "FAILED " : "passed "); @@ -1320,7 +1320,7 @@ bool ValidateSEAL() unsigned int size = sizeof(input); bool pass = true; - memset(output, 1, size); + std::memset(output, 1, size); seal.ProcessString(output, input, size); for (unsigned int i=0; iInitialize(CombinedNameValuePairs( parameters, diff --git a/validat5.cpp b/validat5.cpp index a35b9562..d3281a1e 100644 --- a/validat5.cpp +++ b/validat5.cpp @@ -65,24 +65,23 @@ struct HashTestTuple : input((byte *)input), output((byte *)output), inputLen(inputLen), repeatTimes(repeatTimes) {} const byte *input, *output; - size_t inputLen; - unsigned int repeatTimes; + size_t inputLen, repeatTimes; }; -bool HashModuleTest(HashTransformation &md, const HashTestTuple *testSet, unsigned int testSetSize) +bool HashModuleTest(HashTransformation &md, const HashTestTuple *testSet, size_t testSetSize) { bool pass=true, fail; std::ostringstream oss; SecByteBlock digest(md.DigestSize()); - for (unsigned int i=0; i::DIGESTSIZE]; // Positive tests - for (unsigned int i=0; i poly1305((const byte*)tests[i].key, tests[i].klen); poly1305.Resynchronize((const byte*)tests[i].nonce, (int)tests[i].nlen); poly1305.Update((const byte*)tests[i].message, tests[i].mlen); poly1305.Final(digest); - fail = memcmp(digest, tests[i].digest, tests[i].dlen) != 0; + fail = std::memcmp(digest, tests[i].digest, tests[i].dlen) != 0; if (fail) { std::cout << "FAILED " << "Poly1305 test set " << count << std::endl; @@ -1088,13 +1087,13 @@ bool ValidatePoly1305() } // Positive tests - for (unsigned int i=0; i poly1305((const byte*)tests[i].key, tests[i].klen,(const byte*)tests[i].nonce, (int)tests[i].nlen); poly1305.Update((const byte*)tests[i].message, tests[i].mlen); poly1305.Final(digest); - fail = memcmp(digest, tests[i].digest, tests[i].dlen) != 0; + fail = std::memcmp(digest, tests[i].digest, tests[i].dlen) != 0; if (fail) { std::cout << "FAILED " << "Poly1305 test set " << count << std::endl; @@ -1105,7 +1104,7 @@ bool ValidatePoly1305() } // Negative tests - for (unsigned int i=0; i poly1305((const byte*)tests[i].key, tests[i].klen); poly1305.Resynchronize((const byte*)tests[i].nonce, (int)tests[i].nlen); @@ -1113,7 +1112,7 @@ bool ValidatePoly1305() poly1305.Final(digest); unsigned int next = (i+1) % COUNTOF(tests); - fail = memcmp(digest, tests[next].digest, tests[next].dlen) == 0; + fail = std::memcmp(digest, tests[next].digest, tests[next].dlen) == 0; if (fail) { std::cout << "FAILED " << "Poly1305 test set " << count << std::endl; @@ -1167,27 +1166,27 @@ bool ValidateSipHash() hash.Update((const byte*)"", 0); hash.Final(digest); - fail = memcmp("\x31\x0E\x0E\xDD\x47\xDB\x6F\x72", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x31\x0E\x0E\xDD\x47\xDB\x6F\x72", digest, COUNTOF(digest)) != 0; pass1 = !fail && pass1; hash.Update((const byte*)"\x00", 1); hash.Final(digest); - fail = memcmp("\xFD\x67\xDC\x93\xC5\x39\xF8\x74", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\xFD\x67\xDC\x93\xC5\x39\xF8\x74", digest, COUNTOF(digest)) != 0; pass1 = !fail && pass1; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06", 7); hash.Final(digest); - fail = memcmp("\x37\xD1\x01\x8B\xF5\x00\x02\xAB", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x37\xD1\x01\x8B\xF5\x00\x02\xAB", digest, COUNTOF(digest)) != 0; pass1 = !fail && pass1; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06\x07", 8); hash.Final(digest); - fail = memcmp("\x62\x24\x93\x9A\x79\xF5\xF5\x93", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x62\x24\x93\x9A\x79\xF5\xF5\x93", digest, COUNTOF(digest)) != 0; pass1 = !fail && pass1; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06\x07\x08", 9); hash.Final(digest); - fail = memcmp("\xB0\xE4\xA9\x0B\xDF\x82\x00\x9E", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\xB0\xE4\xA9\x0B\xDF\x82\x00\x9E", digest, COUNTOF(digest)) != 0; pass1 = !fail && pass1; std::cout << (pass1 ? "passed " : "FAILED ") << "SipHash-2-4 64-bit MAC\n"; @@ -1202,27 +1201,27 @@ bool ValidateSipHash() hash.Update((const byte*)"", 0); hash.Final(digest); - fail = memcmp("\xA3\x81\x7F\x04\xBA\x25\xA8\xE6\x6D\xF6\x72\x14\xC7\x55\x02\x93", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\xA3\x81\x7F\x04\xBA\x25\xA8\xE6\x6D\xF6\x72\x14\xC7\x55\x02\x93", digest, COUNTOF(digest)) != 0; pass3 = !fail && pass3; hash.Update((const byte*)"\x00", 1); hash.Final(digest); - fail = memcmp("\xDA\x87\xC1\xD8\x6B\x99\xAF\x44\x34\x76\x59\x11\x9B\x22\xFC\x45", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\xDA\x87\xC1\xD8\x6B\x99\xAF\x44\x34\x76\x59\x11\x9B\x22\xFC\x45", digest, COUNTOF(digest)) != 0; pass3 = !fail && pass3; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06", 7); hash.Final(digest); - fail = memcmp("\xA1\xF1\xEB\xBE\xD8\xDB\xC1\x53\xC0\xB8\x4A\xA6\x1F\xF0\x82\x39", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\xA1\xF1\xEB\xBE\xD8\xDB\xC1\x53\xC0\xB8\x4A\xA6\x1F\xF0\x82\x39", digest, COUNTOF(digest)) != 0; pass3 = !fail && pass3; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06\x07", 8); hash.Final(digest); - fail = memcmp("\x3B\x62\xA9\xBA\x62\x58\xF5\x61\x0F\x83\xE2\x64\xF3\x14\x97\xB4", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x3B\x62\xA9\xBA\x62\x58\xF5\x61\x0F\x83\xE2\x64\xF3\x14\x97\xB4", digest, COUNTOF(digest)) != 0; pass3 = !fail && pass3; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06\x07\x08", 9); hash.Final(digest); - fail = memcmp("\x26\x44\x99\x06\x0A\xD9\xBA\xAB\xC4\x7F\x8B\x02\xBB\x6D\x71\xED", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x26\x44\x99\x06\x0A\xD9\xBA\xAB\xC4\x7F\x8B\x02\xBB\x6D\x71\xED", digest, COUNTOF(digest)) != 0; pass3 = !fail && pass3; std::cout << (pass3 ? "passed " : "FAILED ") << "SipHash-2-4 128-bit MAC\n"; @@ -1237,27 +1236,27 @@ bool ValidateSipHash() hash.Update((const byte*)"", 0); hash.Final(digest); - fail = memcmp("\x41\xDA\x38\x99\x2B\x05\x79\xC8", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x41\xDA\x38\x99\x2B\x05\x79\xC8", digest, COUNTOF(digest)) != 0; pass2 = !fail && pass2; hash.Update((const byte*)"\x00", 1); hash.Final(digest); - fail = memcmp("\x51\xB8\x95\x52\xF9\x14\x59\xC8", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x51\xB8\x95\x52\xF9\x14\x59\xC8", digest, COUNTOF(digest)) != 0; pass2 = !fail && pass2; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06", 7); hash.Final(digest); - fail = memcmp("\x47\xD7\x3F\x71\x5A\xBE\xFD\x4E", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x47\xD7\x3F\x71\x5A\xBE\xFD\x4E", digest, COUNTOF(digest)) != 0; pass2 = !fail && pass2; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06\x07", 8); hash.Final(digest); - fail = memcmp("\x20\xB5\x8B\x9C\x07\x2F\xDB\x50", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x20\xB5\x8B\x9C\x07\x2F\xDB\x50", digest, COUNTOF(digest)) != 0; pass2 = !fail && pass2; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06\x07\x08", 9); hash.Final(digest); - fail = memcmp("\x36\x31\x9A\xF3\x5E\xE1\x12\x53", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x36\x31\x9A\xF3\x5E\xE1\x12\x53", digest, COUNTOF(digest)) != 0; pass2 = !fail && pass2; std::cout << (pass2 ? "passed " : "FAILED ") << "SipHash-4-8 64-bit MAC\n"; @@ -1272,27 +1271,27 @@ bool ValidateSipHash() hash.Update((const byte*)"", 0); hash.Final(digest); - fail = memcmp("\x1F\x64\xCE\x58\x6D\xA9\x04\xE9\xCF\xEC\xE8\x54\x83\xA7\x0A\x6C", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x1F\x64\xCE\x58\x6D\xA9\x04\xE9\xCF\xEC\xE8\x54\x83\xA7\x0A\x6C", digest, COUNTOF(digest)) != 0; pass4 = !fail && pass4; hash.Update((const byte*)"\x00", 1); hash.Final(digest); - fail = memcmp("\x47\x34\x5D\xA8\xEF\x4C\x79\x47\x6A\xF2\x7C\xA7\x91\xC7\xA2\x80", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x47\x34\x5D\xA8\xEF\x4C\x79\x47\x6A\xF2\x7C\xA7\x91\xC7\xA2\x80", digest, COUNTOF(digest)) != 0; pass4 = !fail && pass4; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06", 7); hash.Final(digest); - fail = memcmp("\xED\x00\xE1\x3B\x18\x4B\xF1\xC2\x72\x6B\x8B\x54\xFF\xD2\xEE\xE0", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\xED\x00\xE1\x3B\x18\x4B\xF1\xC2\x72\x6B\x8B\x54\xFF\xD2\xEE\xE0", digest, COUNTOF(digest)) != 0; pass4 = !fail && pass4; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06\x07", 8); hash.Final(digest); - fail = memcmp("\xA7\xD9\x46\x13\x8F\xF9\xED\xF5\x36\x4A\x5A\x23\xAF\xCA\xE0\x63", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\xA7\xD9\x46\x13\x8F\xF9\xED\xF5\x36\x4A\x5A\x23\xAF\xCA\xE0\x63", digest, COUNTOF(digest)) != 0; pass4 = !fail && pass4; hash.Update((const byte*)"\x00\x01\x02\x03\x04\x05\x06\x07\x08", 9); hash.Final(digest); - fail = memcmp("\x9E\x73\x14\xB7\x54\x5C\xEC\xA3\x8B\x9A\x55\x49\xE4\xFB\x0B\xE8", digest, COUNTOF(digest)) != 0; + fail = std::memcmp("\x9E\x73\x14\xB7\x54\x5C\xEC\xA3\x8B\x9A\x55\x49\xE4\xFB\x0B\xE8", digest, COUNTOF(digest)) != 0; pass4 = !fail && pass4; std::cout << (pass4 ? "passed " : "FAILED ") << "SipHash-4-8 128-bit MAC\n"; @@ -1708,7 +1707,7 @@ bool ValidateBLAKE2s() { byte digest[BLAKE2s::DIGESTSIZE]; - for (unsigned int i=0; i= DSIZE); @@ -377,7 +377,7 @@ unsigned int Deflator::FillWindow(const byte *str, size_t length) CRYPTOPP_ASSERT(maxBlockSize > m_stringStart+m_lookahead); unsigned int accepted = UnsignedMin(maxBlockSize-(m_stringStart+m_lookahead), length); CRYPTOPP_ASSERT(accepted > 0); - memcpy(m_byteBuffer + m_stringStart + m_lookahead, str, accepted); + std::memcpy(m_byteBuffer + m_stringStart + m_lookahead, str, accepted); m_lookahead += accepted; return accepted; } @@ -689,8 +689,8 @@ void Deflator::EncodeBlock(bool eof, unsigned int blockType) unsigned int hdist = (unsigned int)(FindIfNot(RevIt(distanceCodeLengths.end()), RevIt(distanceCodeLengths.begin()+1), 0).base() - (distanceCodeLengths.begin()+1)); SecBlockWithHint combinedLengths(hlit+257+hdist+1); - memcpy(combinedLengths, literalCodeLengths, (hlit+257)*sizeof(unsigned int)); - memcpy(combinedLengths+hlit+257, distanceCodeLengths, (hdist+1)*sizeof(unsigned int)); + std::memcpy(combinedLengths, literalCodeLengths, (hlit+257)*sizeof(unsigned int)); + std::memcpy(combinedLengths+hlit+257, distanceCodeLengths, (hdist+1)*sizeof(unsigned int)); FixedSizeSecBlock codeLengthCodeCounts, codeLengthCodeLengths; std::fill(codeLengthCodeCounts.begin(), codeLengthCodeCounts.end(), 0); diff --git a/zinflate.cpp b/zinflate.cpp index 85991264..d9b36c0e 100644 --- a/zinflate.cpp +++ b/zinflate.cpp @@ -255,7 +255,7 @@ void Inflator::OutputString(const byte *string, size_t length) while (length) { size_t len = UnsignedMin(length, m_window.size() - m_current); - memcpy(m_window + m_current, string, len); + std::memcpy(m_window + m_current, string, len); m_current += len; if (m_current == m_window.size()) { @@ -293,7 +293,7 @@ void Inflator::OutputPast(unsigned int length, unsigned int distance) } else { - memcpy(m_window + m_current, m_window + start, length); + std::memcpy(m_window + m_current, m_window + start, length); m_current += length; } }