Add BuildVersion and RuntimeVersion functions (Issue 371)
These function are intended to catch mining and matching of library versions. BuildVersion provides CRYPTOPP_VERSION when the shared object was built. RuntimeVersion provides CRYPTOPP_VERSION the app compiled against, which could be different than the shared object's versionpull/378/head
parent
e757fad5ba
commit
6f7339c81b
11
cryptlib.cpp
11
cryptlib.cpp
|
|
@ -313,7 +313,7 @@ word32 RandomNumberGenerator::GenerateWord32(word32 min, word32 max)
|
||||||
|
|
||||||
// Stack recursion below... GenerateIntoBufferedTransformation calls GenerateBlock,
|
// Stack recursion below... GenerateIntoBufferedTransformation calls GenerateBlock,
|
||||||
// and GenerateBlock calls GenerateIntoBufferedTransformation. Ad infinitum. Also
|
// and GenerateBlock calls GenerateIntoBufferedTransformation. Ad infinitum. Also
|
||||||
// see https://github.com/weidai11/cryptopp/issues/38.
|
// see http://github.com/weidai11/cryptopp/issues/38.
|
||||||
//
|
//
|
||||||
// According to Wei, RandomNumberGenerator is an interface, and it should not
|
// According to Wei, RandomNumberGenerator is an interface, and it should not
|
||||||
// be instantiable. Its now spilt milk, and we are going to CRYPTOPP_ASSERT it in Debug
|
// be instantiable. Its now spilt milk, and we are going to CRYPTOPP_ASSERT it in Debug
|
||||||
|
|
@ -945,6 +945,15 @@ void AuthenticatedKeyAgreementDomain::GenerateEphemeralKeyPair(RandomNumberGener
|
||||||
GenerateEphemeralPublicKey(rng, privateKey, publicKey);
|
GenerateEphemeralPublicKey(rng, privateKey, publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow a distro or packager to override the build-time version
|
||||||
|
// http://github.com/weidai11/cryptopp/issues/371
|
||||||
|
#ifndef CRYPTOPP_BUILD_VERSION
|
||||||
|
# define CRYPTOPP_BUILD_VERSION CRYPTOPP_VERSION
|
||||||
|
#endif
|
||||||
|
int BuildVersion()
|
||||||
|
{
|
||||||
|
return CRYPTOPP_BUILD_VERSION;
|
||||||
|
}
|
||||||
NAMESPACE_END
|
NAMESPACE_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
70
cryptlib.h
70
cryptlib.h
|
|
@ -2914,6 +2914,76 @@ public:
|
||||||
virtual void BEREncode(BufferedTransformation &bt) const {DEREncode(bt);}
|
virtual void BEREncode(BufferedTransformation &bt) const {DEREncode(bt);}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \brief Specifies the build-time version of the library
|
||||||
|
//! \returns integer representing the build-time version
|
||||||
|
//! \details BuildVersion can help detect inadvertent mixing and matching of library
|
||||||
|
//! versions. When using Crypto++ distributed by a third party, BuildVersion()
|
||||||
|
//! records the version of the shared object that was built by the third party.
|
||||||
|
//! The BuildVersion() record resides in <tt>cryptlib.o</tt> on Unix compatibles
|
||||||
|
//! and <tt>cryptlib.obj</tt> on Windows. It does not change when an app links
|
||||||
|
//! to the library.
|
||||||
|
//! \details BuildVersion() is declared with C linkage (<tt>extern "C"</tt>) within the
|
||||||
|
//! CryptoPP namespace to help programs locate the symbol. If the symbol is present, then
|
||||||
|
//! the library version is 5.7 or above. If it is missing, then the library version is
|
||||||
|
//! 5.6.5 or below.
|
||||||
|
//! \details The function could be used as shown below.
|
||||||
|
//! <pre>
|
||||||
|
//! if (BuildVersion() != RuntimeVersion())
|
||||||
|
//! {
|
||||||
|
//! cout << "Potential version mismatch" << endl;
|
||||||
|
//!
|
||||||
|
//! const int bmaj = (BuildVersion() / 100U) % 10;
|
||||||
|
//! const int bmin = (BuildVersion() / 10U) % 10;
|
||||||
|
//! const int rmaj = (RuntimeVersion() / 100U) % 10;
|
||||||
|
//! const int rmin = (RuntimeVersion() / 10U) % 10;
|
||||||
|
//!
|
||||||
|
//! if(bmaj != rmaj)
|
||||||
|
//! cout << "Major version mismatch" << endl;
|
||||||
|
//! else if(bmin != rmin)
|
||||||
|
//! cout << "Minor version mismatch" << endl;
|
||||||
|
//! }
|
||||||
|
//! </pre>
|
||||||
|
//! \sa RuntimeVersion(), <A HREF="http://github.com/weidai11/cryptopp/issues/371">GitHub Issue 371</A>.
|
||||||
|
//! \since Crypto++ 5.7
|
||||||
|
extern "C" {
|
||||||
|
int BuildVersion();
|
||||||
|
} // C linkage
|
||||||
|
|
||||||
|
//! \brief Specifies the runtime version of the library
|
||||||
|
//! \returns integer representing the runtime version
|
||||||
|
//! \details RuntimeVersion() can help detect inadvertent mixing and matching of library
|
||||||
|
//! versions. When using Crypto++ distributed by a third party, RuntimeVersion()
|
||||||
|
//! records the version of the headers used by the app when the app is compiled.
|
||||||
|
//! \details RuntimeVersion() is declared with C linkage (<tt>extern "C"</tt>) within the
|
||||||
|
//! CryptoPP namespace to help programs locate the symbol. If the symbol is present, then
|
||||||
|
//! the library version is 5.7 or above. If it is missing, then the library version is
|
||||||
|
//! 5.6.5 or below.
|
||||||
|
//! \details The function could be used as shown below.
|
||||||
|
//! <pre>
|
||||||
|
//! if (BuildVersion() != RuntimeVersion())
|
||||||
|
//! {
|
||||||
|
//! cout << "Potential version mismatch" << endl;
|
||||||
|
//!
|
||||||
|
//! const int bmaj = (BuildVersion() / 100U) % 10;
|
||||||
|
//! const int bmin = (BuildVersion() / 10U) % 10;
|
||||||
|
//! const int rmaj = (RuntimeVersion() / 100U) % 10;
|
||||||
|
//! const int rmin = (RuntimeVersion() / 10U) % 10;
|
||||||
|
//!
|
||||||
|
//! if(bmaj != rmaj)
|
||||||
|
//! cout << "Major version mismatch" << endl;
|
||||||
|
//! else if(bmin != rmin)
|
||||||
|
//! cout << "Minor version mismatch" << endl;
|
||||||
|
//! }
|
||||||
|
//! </pre>
|
||||||
|
//! \sa BuildVersion(), <A HREF="http://github.com/weidai11/cryptopp/issues/371">GitHub Issue 371</A>.
|
||||||
|
//! \since Crypto++ 5.7
|
||||||
|
extern "C" {
|
||||||
|
inline int RuntimeVersion()
|
||||||
|
{
|
||||||
|
return CRYPTOPP_VERSION;
|
||||||
|
}
|
||||||
|
} // C linkage
|
||||||
|
|
||||||
NAMESPACE_END
|
NAMESPACE_END
|
||||||
|
|
||||||
#if CRYPTOPP_MSC_VERSION
|
#if CRYPTOPP_MSC_VERSION
|
||||||
|
|
|
||||||
|
|
@ -399,7 +399,7 @@ private:
|
||||||
//! \tparam T FieldElement type or class
|
//! \tparam T FieldElement type or class
|
||||||
//! \details The Digital Signature Scheme ECGDSA does not define the algorithm over integers. Rather, the
|
//! \details The Digital Signature Scheme ECGDSA does not define the algorithm over integers. Rather, the
|
||||||
//! signature algorithm is only defined over elliptic curves. However, The library design is such that the
|
//! signature algorithm is only defined over elliptic curves. However, The library design is such that the
|
||||||
//! generic algorithm reside in \header gfpcrypt.h.
|
//! generic algorithm reside in <tt>gfpcrypt.h</tt>.
|
||||||
//! \sa Erwin Hess, Marcus Schafheutle, and Pascale Serf <A HREF="http://www.teletrust.de/fileadmin/files/oid/ecgdsa_final.pdf">
|
//! \sa Erwin Hess, Marcus Schafheutle, and Pascale Serf <A HREF="http://www.teletrust.de/fileadmin/files/oid/ecgdsa_final.pdf">
|
||||||
//! The Digital Signature Scheme ECGDSA (October 24, 2006)</A>
|
//! The Digital Signature Scheme ECGDSA (October 24, 2006)</A>
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|
|
||||||
12
validat1.cpp
12
validat1.cpp
|
|
@ -225,6 +225,18 @@ bool TestSettings()
|
||||||
pass = false;
|
pass = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// App and library versions, http://github.com/weidai11/cryptopp/issues/371
|
||||||
|
const int bver = BuildVersion();
|
||||||
|
const int rver = RuntimeVersion();
|
||||||
|
if(bver/10 == rver/10)
|
||||||
|
cout << "passed: ";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "FAILED: ";
|
||||||
|
pass = false;
|
||||||
|
}
|
||||||
|
cout << "Build version (library): " << bver << ", runtime version (app): " << rver << "\n";
|
||||||
|
|
||||||
#ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
|
#ifdef CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS
|
||||||
// Don't assert the alignment of testvals. That's what this test is for.
|
// Don't assert the alignment of testvals. That's what this test is for.
|
||||||
byte testvals[10] = {1,2,2,3,3,3,3,2,2,1};
|
byte testvals[10] = {1,2,2,3,3,3,3,2,2,1};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue