33 #include "../crypto/fipsmodule/rand/internal.h"
34 #include "../crypto/fipsmodule/tls/internal.h"
35 #include "../crypto/internal.h"
39 const unsigned char *
in = (
const unsigned char *)
a;
40 for (
size_t i = 0;
i <
len;
i++) {
47 int main(
int argc,
char **argv) {
50 static const uint8_t kAESKey[16] =
"BoringCrypto Key";
52 "BoringCryptoModule FIPS KAT Encryption and Decryption Plaintext!";
53 static const DES_cblock kDESKey1 = {
"BCMDESK1"};
54 static const DES_cblock kDESKey2 = {
"BCMDESK2"};
55 static const DES_cblock kDESKey3 = {
"BCMDESK3"};
57 static const uint8_t kPlaintextSHA256[32] = {
58 0x37, 0xbd, 0x70, 0x53, 0x72, 0xfc, 0xd4, 0x03, 0x79, 0x70, 0xfb,
59 0x06, 0x95, 0xb1, 0x2a, 0x82, 0x48, 0xe1, 0x3e, 0xf2, 0x33, 0xfb,
60 0xef, 0x29, 0x81, 0x22, 0x45, 0x40, 0x43, 0x70, 0xce, 0x0f};
61 const uint8_t kDRBGEntropy[48] =
62 "DBRG Initial Entropy ";
63 const uint8_t kDRBGPersonalization[18] =
"BCMPersonalization";
64 const uint8_t kDRBGAD[16] =
"BCM DRBG AD ";
65 const uint8_t kDRBGEntropy2[48] =
66 "DBRG Reseed Entropy ";
73 memset(aes_iv, 0,
sizeof(aes_iv));
75 printf(
"AES_set_encrypt_key failed\n");
79 printf(
"About to AES-CBC encrypt ");
87 memset(aes_iv, 0,
sizeof(aes_iv));
89 printf(
"AES decrypt failed\n");
92 printf(
"About to AES-CBC decrypt ");
104 sizeof(kAESKey), 0, NULL)) {
105 printf(
"EVP_AEAD_CTX_init failed\n");
110 printf(
"About to AES-GCM seal ");
115 printf(
"AES-GCM encrypt failed\n");
122 printf(
"About to AES-GCM open ");
126 output, out_len, NULL, 0)) {
127 printf(
"AES-GCM decrypt failed\n");
142 memcpy(&des_iv, &kDESIV,
sizeof(des_iv));
143 printf(
"About to 3DES-CBC encrypt ");
151 memcpy(&des_iv, &kDESIV,
sizeof(des_iv));
152 printf(
"About to 3DES-CBC decrypt ");
160 printf(
"About to SHA-1 hash ");
167 printf(
"About to SHA-256 hash ");
174 printf(
"About to SHA-512 hash ");
181 printf(
"About to generate RSA key\n");
183 printf(
"RSA_generate_key_fips failed\n");
189 printf(
"About to RSA sign ");
190 hexdump(kPlaintextSHA256,
sizeof(kPlaintextSHA256));
192 &sig_len, rsa_key)) {
193 printf(
"RSA Sign failed\n");
200 printf(
"About to RSA verify ");
203 output, sig_len, rsa_key)) {
204 printf(
"RSA Verify failed.\n");
211 if (ec_key == NULL) {
212 printf(
"invalid ECDSA key\n");
216 printf(
"About to generate P-256 key\n");
218 printf(
"EC_KEY_generate_key_fips failed\n");
226 printf(
"About to compute key-agreement Z with P-256:\n");
230 z_result,
sizeof(z_result),
231 NULL) !=
sizeof(z_result)) {
232 fprintf(
stderr,
"EC_POINT_mul failed.\n");
238 hexdump(z_result,
sizeof(z_result));
241 printf(
"About to ECDSA sign ");
242 hexdump(kPlaintextSHA256,
sizeof(kPlaintextSHA256));
244 ECDSA_do_sign(kPlaintextSHA256,
sizeof(kPlaintextSHA256), ec_key);
248 printf(
"ECDSA Sign/Verify PWCT failed.\n");
257 printf(
"About to seed CTR-DRBG with ");
258 hexdump(kDRBGEntropy,
sizeof(kDRBGEntropy));
259 if (!
CTR_DRBG_init(&drbg, kDRBGEntropy, kDRBGPersonalization,
260 sizeof(kDRBGPersonalization)) ||
274 printf(
"About to run TLS KDF\n");
277 sizeof(kAESKey),
"foo", 3, kPlaintextSHA256,
278 sizeof(kPlaintextSHA256), kPlaintextSHA256,
279 sizeof(kPlaintextSHA256))) {
280 fprintf(
stderr,
"TLS KDF failed.\n");
284 hexdump(tls_output,
sizeof(tls_output));
287 printf(
"About to compute FFDH key-agreement:\n");
292 sizeof(dh_result) !=
DH_size(dh) ||
295 fprintf(
stderr,
"FFDH failed.\n");
301 hexdump(dh_result,
sizeof(dh_result));