diff --git a/validat1.cpp b/validat1.cpp index 44e2779f..3033a0a1 100644 --- a/validat1.cpp +++ b/validat1.cpp @@ -87,6 +87,8 @@ bool ValidateAll(bool thorough) pass=TestSecBlock() && pass; // http://github.com/weidai11/cryptopp/issues/64 pass=TestPolynomialMod2() && pass; + // http://github.com/weidai11/cryptopp/pull/242 + pass=TestHuffmanCodes() && pass; #endif pass=ValidateCRC32() && pass; @@ -806,6 +808,37 @@ bool TestSecBlock() } #endif +#if !defined(NDEBUG) && !defined(CRYPTOPP_IMPORTS) +bool TestHuffmanCodes() +{ + cout << "\nTesting Huffman codes...\n\n"; + + static const size_t nCodes = 30; + const unsigned int codeCounts[nCodes] = { + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + + static const unsigned int maxCodeBits = nCodes >> 1; + unsigned int codeBits[nCodes] = { + ~0u, ~0u, ~0u, ~0u, ~0u, + ~0u, ~0u, ~0u, ~0u, ~0u, + ~0u, ~0u, ~0u, ~0u, ~0u, + }; + + try + { + HuffmanEncoder::GenerateCodeLengths(codeBits, maxCodeBits, codeCounts, nCodes); + } + catch(const Exception& ex) + { + return false; + } + + return true; +} +#endif + bool TestOS_RNG() { bool pass = true; diff --git a/validate.h b/validate.h index 6c0c4793..b053216a 100644 --- a/validate.h +++ b/validate.h @@ -91,6 +91,7 @@ bool ValidateESIGN(); #if !defined(NDEBUG) bool TestSecBlock(); bool TestPolynomialMod2(); +bool TestHuffmanCodes(); #endif // Coverity finding