1 #ifndef CRYPTOPP_DLL_ONLY 2 # define CRYPTOPP_DEFAULT_NO_DLL 16 cerr <<
"FIPS 140-2 compliance was turned off at compile time.\n";
23 cerr <<
"Automatic power-up self test failed.\n";
26 cout <<
"0. Automatic power-up self test passed.\n";
36 cerr <<
"Use of AES failed to cause an exception after power-up self test error.\n";
41 cout <<
"1. Caught expected exception when simulating self test failure. Exception message follows: ";
42 cout << e.
what() << endl;
49 cerr <<
"Re-do power-up self test failed.\n";
52 cout <<
"2. Re-do power-up self test passed.\n";
55 const byte key[] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
56 const byte iv[] = {0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
57 const byte plaintext[] = {
58 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
59 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
60 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20};
65 encryption_DES_EDE3_CFB.SetKeyWithIV(key,
sizeof(key), iv);
66 encryption_DES_EDE3_CFB.ProcessString(ciphertext, plaintext, 24);
69 decryption_DES_EDE3_CFB.SetKeyWithIV(key,
sizeof(key), iv);
70 decryption_DES_EDE3_CFB.ProcessString(decrypted, ciphertext, 24);
72 if (memcmp(plaintext, decrypted, 24) != 0)
74 cerr <<
"DES-EDE3-CFB Encryption/decryption failed.\n";
77 cout <<
"3. DES-EDE3-CFB Encryption/decryption succeeded.\n";
80 const byte message[] = {
'a',
'b',
'c'};
81 const byte expectedDigest[] = {0xA9,0x99,0x3E,0x36,0x47,0x06,0x81,0x6A,0xBA,0x3E,0x25,0x71,0x78,0x50,0xC2,0x6C,0x9C,0xD0,0xD8,0x9D};
88 if (memcmp(digest, expectedDigest, 20) != 0)
90 cerr <<
"SHA-1 hash failed.\n";
93 cout <<
"4. SHA-1 hash succeeded.\n";
96 #ifdef OS_RNG_AVAILABLE 97 AutoSeededX917RNG<AES> rng;
105 dsaPrivateKey.GenerateRandomWithKeySize(rng, 1024);
108 if (!dsaPrivateKey.Validate(rng, 3) || !dsaPublicKey.
Validate(rng, 3))
110 cerr <<
"DSA key generation failed.\n";
113 cout <<
"5. DSA key generation succeeded.\n";
116 std::string encodedDsaPublicKey, encodedDsaPrivateKey;
118 dsaPrivateKey.DEREncode(
StringSink(encodedDsaPrivateKey).Ref());
122 decodedDsaPrivateKey.BERDecode(
StringStore(encodedDsaPrivateKey).Ref());
126 if (!decodedDsaPrivateKey.Validate(rng, 3) || !decodedDsaPublicKey.
Validate(rng, 3))
128 cerr <<
"DSA key encode/decode failed.\n";
131 cout <<
"6. DSA key encode/decode succeeded.\n";
137 signer.SignMessage(rng, message, 3, signature);
140 if (!verifier.VerifyMessage(message, 3, signature,
sizeof(signature)))
142 cerr <<
"DSA signature and verification failed.\n";
145 cout <<
"7. DSA signature and verification succeeded.\n";
150 if (verifier.VerifyMessage(message, 3, signature,
sizeof(signature)))
152 cerr <<
"DSA signature verification failed to detect bad signature.\n";
155 cout <<
"8. DSA signature verification successfully detected bad signature.\n";
161 encryption_DES_EDE3_ECB.SetKey(key, 5);
164 cerr <<
"DES-EDE3 implementation did not detect use of invalid key length.\n";
169 cout <<
"9. Caught expected exception when using invalid key length. Exception message follows: ";
170 cout << e.
what() << endl;
173 cout <<
"\nFIPS 140-2 Sample Application completed normally.\n";
176 #ifdef CRYPTOPP_IMPORTS 178 static PNew s_pNew = NULL;
179 static PDelete s_pDelete = NULL;
183 (void)(pSetNewHandler);
188 void * __cdecl
operator new (
size_t size)
193 void __cdecl
operator delete (
void * p)
200 #ifdef CRYPTOPP_DLL_ONLY Append input to a string object.
The self tests were executed via DoPowerUpSelfTest() or DoDllPowerUpSelfTest(), and the result was su...
An invalid argument was detected.
const char * what() const
Retrieves a C-string describing the exception.
void BERDecode(BufferedTransformation &bt)
Decode this object from a BufferedTransformation.
void DEREncode(BufferedTransformation &bt) const
Encode this object into a BufferedTransformation.
bool FIPS_140_2_ComplianceEnabled()
Determines whether the library provides FIPS validated cryptography.
PowerUpSelfTestStatus CRYPTOPP_API GetPowerUpSelfTestStatus()
Provides the current power-up self test status.
Abstract base classes that provide a uniform interface to this library.
void Update(const byte *input, size_t length)
Updates a hash with additional input.
std::hash for asio::adress
Interface for random number generators.
std::new_handler(CRYPTOPP_API * PSetNewHandler)(std::new_handler)
Block cipher mode of operation aggregate.
Exception thrown when a crypto algorithm is used after a self test fails.
int main(int argc, char **argv)
bool Validate(RandomNumberGenerator &rng, unsigned int level) const
Check this object for errors.
void *(CRYPTOPP_API * PNew)(size_t)
void(CRYPTOPP_API * PDelete)(void *)
void SimulatePowerUpSelfTestFailure()
Sets the power-up self test status to POWER_UP_SELF_TEST_FAILED.
String-based implementation of Store interface.
#define CRYPTOPP_ASSERT(exp)
void FIPS140_SampleApplication()
Discrete Log (DL) public key in GF(p) groups.
Implementation of BufferedTransformation's attachment interface.
#define USING_NAMESPACE(x)
void AssignFrom(const NameValuePairs &source)
Assign values to this object.
PDelete PSetNewHandler pSetNewHandler
uint8_t const size_t const size
RandomNumberGenerator & NullRNG()
Random Number Generator that does not produce random numbers.
CRYPTOPP_DLL void CRYPTOPP_API DoDllPowerUpSelfTest()
Performs the power-up self test on the DLL.
__declspec(dllexport) void __cdecl SetNewAndDeleteFromCryptoPP(PNew pNew
Functions and definitions required for building the FIPS-140 DLL on Windows.
Template implementing constructors for public key algorithm classes.