static OPENSSL_NOINLINE int boringssl_self_test_fast()

in crypto/fipsmodule/self_check/self_check.c [2650:2983]


static OPENSSL_NOINLINE int boringssl_self_test_fast(void) {
  static const uint8_t kAESKey[16] = {'B', 'o', 'r', 'i', 'n', 'g', 'C', 'r',
                                      'y', 'p', 't', 'o', ' ', 'K', 'e', 'y'};
  // Older versions of the gcc release build on ARM will optimize out the
  // assembly label for kAESIV, if we define it with {0}. The assembler
  // will set the value of kAESIV to another static constant in the
  // fipsmodule, kZeroIV, since they have the same value, then skip creating
  // a label for kAESIV. This does not mesh well with delocate.go, since we
  // use these labels to determine if the symbol is "known". Expanding the
  // definition of kAESIV gets around the unwanted assembler optimization.
  static const uint8_t kAESIV[16] = {
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  };

  EVP_AEAD_CTX aead_ctx;
  EVP_AEAD_CTX_zero(&aead_ctx);
  int ret = 0;

  AES_KEY aes_key;
  uint8_t aes_iv[16];
  uint8_t output[256];

  // AES-CBC Encryption KAT
  static const uint8_t kAESCBCEncPlaintext[32] = {
      0x07, 0x86, 0x09, 0xa6, 0xc5, 0xac, 0x25, 0x44, 0x69, 0x9a, 0xdf,
      0x68, 0x2f, 0xa3, 0x77, 0xf9, 0xbe, 0x8a, 0xb6, 0xae, 0xf5, 0x63,
      0xe8, 0xc5, 0x6a, 0x36, 0xb8, 0x4f, 0x55, 0x7f, 0xad, 0xd3,
  };
  static const uint8_t kAESCBCEncCiphertext[sizeof(kAESCBCEncPlaintext)] = {
      0x56, 0x46, 0xc1, 0x41, 0xf4, 0x13, 0xd6, 0xff, 0x62, 0x92, 0x41,
      0x7a, 0x26, 0xc6, 0x86, 0xbd, 0x30, 0x5f, 0xb6, 0x57, 0xa7, 0xd2,
      0x50, 0x3a, 0xc5, 0x5e, 0x8e, 0x93, 0x40, 0xf2, 0x10, 0xd8,
  };
  memcpy(aes_iv, kAESIV, sizeof(kAESIV));
  if (AES_set_encrypt_key(kAESKey, 8 * sizeof(kAESKey), &aes_key) != 0) {
    fprintf(stderr, "AES_set_encrypt_key failed.\n");
    goto err;
  }
  AES_cbc_encrypt(kAESCBCEncPlaintext, output, sizeof(kAESCBCEncPlaintext),
                  &aes_key, aes_iv, AES_ENCRYPT);
  if (!check_test(kAESCBCEncCiphertext, output, sizeof(kAESCBCEncCiphertext),
                  "AES-CBC-encrypt KAT")) {
    goto err;
  }

  // AES-CBC Decryption KAT
  static const uint8_t kAESCBCDecCiphertext[32] = {
      0x34, 0x7a, 0xa5, 0xa0, 0x24, 0xb2, 0x82, 0x57, 0xb3, 0x65, 0x10,
      0xbe, 0x58, 0x3d, 0x4f, 0x47, 0xad, 0xb7, 0xbb, 0xee, 0xdc, 0x60,
      0x05, 0xbb, 0xbd, 0x0d, 0x0a, 0x9f, 0x06, 0xbb, 0x7b, 0x10,
  };
  static const uint8_t kAESCBCDecPlaintext[sizeof(kAESCBCDecCiphertext)] = {
      0x51, 0xa7, 0xa0, 0x1f, 0x6b, 0x79, 0x6c, 0xcd, 0x48, 0x03, 0xa1,
      0x41, 0xdc, 0x56, 0xa6, 0xc2, 0x16, 0xb5, 0xd1, 0xd3, 0xb7, 0x06,
      0xb2, 0x25, 0x6f, 0xa6, 0xd0, 0xd2, 0x0e, 0x6f, 0x19, 0xb5,
  };
  memcpy(aes_iv, kAESIV, sizeof(kAESIV));
  if (AES_set_decrypt_key(kAESKey, 8 * sizeof(kAESKey), &aes_key) != 0) {
    fprintf(stderr, "AES_set_decrypt_key failed.\n");
    goto err;
  }
  AES_cbc_encrypt(kAESCBCDecCiphertext, output, sizeof(kAESCBCDecCiphertext),
                  &aes_key, aes_iv, AES_DECRYPT);
  if (!check_test(kAESCBCDecPlaintext, output, sizeof(kAESCBCDecPlaintext),
                  "AES-CBC-decrypt KAT")) {
    goto err;
  }

  size_t out_len;
  uint8_t nonce[EVP_AEAD_MAX_NONCE_LENGTH];
  OPENSSL_memset(nonce, 0, sizeof(nonce));
  if (!EVP_AEAD_CTX_init(&aead_ctx, EVP_aead_aes_128_gcm(), kAESKey,
                         sizeof(kAESKey), 0, NULL)) {
    fprintf(stderr, "EVP_AEAD_CTX_init for AES-128-GCM failed.\n");
    goto err;
  }

  // AES-GCM Encryption KAT
  static const uint8_t kAESGCMEncPlaintext[32] = {
      0x8f, 0xcc, 0x40, 0x99, 0x80, 0x8e, 0x75, 0xca, 0xaf, 0xf5, 0x82,
      0x89, 0x88, 0x48, 0xa8, 0x8d, 0x80, 0x8b, 0x55, 0xab, 0x4e, 0x93,
      0x70, 0x79, 0x7d, 0x94, 0x0b, 0xe8, 0xcc, 0x1d, 0x78, 0x84,
  };
  static const uint8_t kAESGCMCiphertext[sizeof(kAESGCMEncPlaintext) + 16] = {
      0x87, 0x7b, 0xd5, 0x8d, 0x96, 0x3e, 0x4b, 0xe6, 0x64, 0x94, 0x40, 0x2f,
      0x61, 0x9b, 0x7e, 0x56, 0x52, 0x7d, 0xa4, 0x5a, 0xf9, 0xa6, 0xe2, 0xdb,
      0x1c, 0x63, 0x2e, 0x97, 0x93, 0x0f, 0xfb, 0xed, 0xb5, 0x9e, 0x1c, 0x20,
      0xb2, 0xb0, 0x58, 0xda, 0x48, 0x07, 0x2d, 0xbd, 0x96, 0x0d, 0x34, 0xc6,
  };
  if (!EVP_AEAD_CTX_seal(&aead_ctx, output, &out_len, sizeof(output), nonce,
                         EVP_AEAD_nonce_length(EVP_aead_aes_128_gcm()),
                         kAESGCMEncPlaintext, sizeof(kAESGCMEncPlaintext), NULL,
                         0) ||
      !check_test(kAESGCMCiphertext, output, sizeof(kAESGCMCiphertext),
                  "AES-GCM-encrypt KAT")) {
    fprintf(stderr, "EVP_AEAD_CTX_seal for AES-128-GCM failed.\n");
    goto err;
  }

  // AES-GCM Decryption KAT
  static const uint8_t kAESGCMDecCiphertext[48] = {
      0x35, 0xf3, 0x05, 0x8f, 0x87, 0x57, 0x60, 0xff, 0x09, 0xd3, 0x12, 0x0f,
      0x70, 0xc4, 0xbc, 0x9e, 0xd7, 0xa8, 0x68, 0x72, 0xe1, 0x34, 0x52, 0x20,
      0x21, 0x76, 0xf7, 0x37, 0x1a, 0xe0, 0x4f, 0xaa, 0xe1, 0xdd, 0x39, 0x19,
      0x20, 0xf5, 0xd1, 0x39, 0x53, 0xd8, 0x96, 0x78, 0x59, 0x94, 0x82, 0x3c,
  };
  static const uint8_t kAESGCMDecPlaintext[sizeof(kAESGCMDecCiphertext) - 16] =
      {
          0x3d, 0x44, 0x90, 0x9b, 0x91, 0xe7, 0x5e, 0xd3, 0xc2, 0xb2, 0xd0,
          0xa9, 0x99, 0x17, 0x6a, 0x45, 0x05, 0x5e, 0x99, 0x83, 0x56, 0x01,
          0xc0, 0x82, 0x40, 0x81, 0xd2, 0x48, 0x45, 0xf2, 0xcc, 0xc3,
      };
  if (!EVP_AEAD_CTX_open(&aead_ctx, output, &out_len, sizeof(output), nonce,
                         EVP_AEAD_nonce_length(EVP_aead_aes_128_gcm()),
                         kAESGCMDecCiphertext, sizeof(kAESGCMDecCiphertext),
                         NULL, 0) ||
      !check_test(kAESGCMDecPlaintext, output, sizeof(kAESGCMDecPlaintext),
                  "AES-GCM-decrypt KAT")) {
    AWS_LC_FIPS_failure("AES-GCM-decrypt KAT failed because EVP_AEAD_CTX_open failed");
    goto err;
  }

  // SHA-1 KAT
  static const uint8_t kSHA1Input[16] = {
      0x13, 0x2f, 0xd9, 0xba, 0xd5, 0xc1, 0x82, 0x62,
      0x63, 0xba, 0xfb, 0xb6, 0x99, 0xf7, 0x07, 0xa5,
  };
  static const uint8_t kSHA1Digest[20] = {
      0x94, 0x19, 0x55, 0x93, 0x0a, 0x58, 0x29, 0x38, 0xeb, 0xf5,
      0x09, 0x11, 0x6d, 0x1a, 0xfd, 0x0f, 0x1e, 0x11, 0xe3, 0xcb,
  };
  SHA1(kSHA1Input, sizeof(kSHA1Input), output);
  if (!check_test(kSHA1Digest, output, sizeof(kSHA1Digest),
                  "SHA-1 KAT")) {
    goto err;
  }

  if (!boringssl_self_test_sha512() ||
      !boringssl_self_test_sha3_256() ||
      !boringssl_self_test_hkdf_sha256()) {
    goto err;
  }

  // DBRG KAT
  static const uint8_t kDRBGEntropy[48] = {
      0xc4, 0xda, 0x07, 0x40, 0xd5, 0x05, 0xf1, 0xee, 0x28, 0x0b, 0x95, 0xe5,
      0x8c, 0x49, 0x31, 0xac, 0x6d, 0xe8, 0x46, 0xa0, 0x15, 0x2f, 0xbb, 0x4a,
      0x3f, 0x17, 0x4c, 0xf4, 0x78, 0x7a, 0x4f, 0x1a, 0x40, 0xc2, 0xb5, 0x0b,
      0xab, 0xe1, 0x4a, 0xae, 0x53, 0x0b, 0xe5, 0x88, 0x6d, 0x91, 0x0a, 0x27,
  };
  static const uint8_t kDRBGPersonalization[18] = {
      'B', 'C', 'M', 'P', 'e', 'r', 's', 'o', 'n',
      'a', 'l', 'i', 'z', 'a', 't', 'i', 'o', 'n'};
  static const uint8_t kDRBGAD[16] = {'B', 'C', 'M', ' ', 'D', 'R', 'B', 'G',
                                      ' ', 'K', 'A', 'T', ' ', 'A', 'D', ' '};
  static const uint8_t kDRBGOutput[64] = {
      0x19, 0x1f, 0x2b, 0x49, 0x76, 0x85, 0xfd, 0x51, 0xb6, 0x56, 0xbc,
      0x1c, 0x7d, 0xd5, 0xdd, 0x44, 0x76, 0xa3, 0x5e, 0x17, 0x9b, 0x8e,
      0xb8, 0x98, 0x65, 0x12, 0xca, 0x35, 0x6c, 0xa0, 0x6f, 0xa0, 0x22,
      0xe4, 0xf6, 0xd8, 0x43, 0xed, 0x4e, 0x2d, 0x97, 0x39, 0x43, 0x3b,
      0x57, 0xfc, 0x23, 0x3f, 0x71, 0x0a, 0xe0, 0xed, 0xfe, 0xd5, 0xb8,
      0x67, 0x7a, 0x00, 0x39, 0xb2, 0x6e, 0xa9, 0x25, 0x97,
  };
  static const uint8_t kDRBGEntropy2[48] = {
      0xc7, 0x16, 0x1c, 0xa3, 0x6c, 0x23, 0x09, 0xb7, 0x16, 0xe9, 0x85, 0x9b,
      0xb9, 0x6c, 0x6d, 0x49, 0xbd, 0xc8, 0x35, 0x21, 0x03, 0xa1, 0x8c, 0xd2,
      0x4e, 0xf4, 0x2e, 0xc9, 0x7e, 0xf4, 0x6b, 0xf4, 0x46, 0xeb, 0x1a, 0x45,
      0x76, 0xc1, 0x86, 0xe9, 0x35, 0x18, 0x03, 0x76, 0x3a, 0x79, 0x12, 0xfe,
  };
  static const uint8_t kDRBGReseedOutput[64] = {
      0x00, 0xf2, 0x05, 0xaa, 0xfd, 0x11, 0x6c, 0x77, 0xbc, 0x81, 0x86,
      0x99, 0xca, 0x51, 0xcf, 0x80, 0x15, 0x9f, 0x02, 0x9e, 0x0b, 0xcd,
      0x26, 0xc8, 0x4b, 0x87, 0x8a, 0x15, 0x1a, 0xdd, 0xf2, 0xf3, 0xeb,
      0x94, 0x0b, 0x08, 0xc8, 0xc9, 0x57, 0xa4, 0x0b, 0x4b, 0x0f, 0x13,
      0xde, 0x7c, 0x0c, 0x6a, 0xac, 0x34, 0x4a, 0x9a, 0xf2, 0xd0, 0x83,
      0x02, 0x05, 0x17, 0xc9, 0x81, 0x8f, 0x2a, 0x81, 0x92,
  };
  CTR_DRBG_STATE drbg;
  if (!CTR_DRBG_init(&drbg, kDRBGEntropy, kDRBGPersonalization,
                     sizeof(kDRBGPersonalization)) ||
      !CTR_DRBG_generate(&drbg, output, sizeof(kDRBGOutput), kDRBGAD,
                         sizeof(kDRBGAD)) ||
      !check_test(kDRBGOutput, output, sizeof(kDRBGOutput),
                  "DRBG Generate KAT") ||
      !CTR_DRBG_reseed(&drbg, kDRBGEntropy2, kDRBGAD, sizeof(kDRBGAD)) ||
      !CTR_DRBG_generate(&drbg, output, sizeof(kDRBGReseedOutput), kDRBGAD,
                         sizeof(kDRBGAD)) ||
      !check_test(kDRBGReseedOutput, output, sizeof(kDRBGReseedOutput),
                  "DRBG-reseed KAT")) {
    AWS_LC_FIPS_failure("CTR-DRBG failed");
    goto err;
  }
  CTR_DRBG_clear(&drbg);

  CTR_DRBG_STATE kZeroDRBG;
  memset(&kZeroDRBG, 0, sizeof(kZeroDRBG));
  if (!check_test(&kZeroDRBG, &drbg, sizeof(drbg), "DRBG Clear KAT")) {
    goto err;
  }

  // TLS KDF KAT
  static const uint8_t kTLSSecret[32] = {
      0xab, 0xc3, 0x65, 0x7b, 0x09, 0x4c, 0x76, 0x28, 0xa0, 0xb2, 0x82,
      0x99, 0x6f, 0xe7, 0x5a, 0x75, 0xf4, 0x98, 0x4f, 0xd9, 0x4d, 0x4e,
      0xcc, 0x2f, 0xcf, 0x53, 0xa2, 0xc4, 0x69, 0xa3, 0xf7, 0x31,
  };
  static const char kTLSLabel[] = "FIPS self test";
  static const uint8_t kTLSSeed1[16] = {
      0x8f, 0x0d, 0xe8, 0xb6, 0x90, 0x8f, 0xb1, 0xd2,
      0x6d, 0x51, 0xf4, 0x79, 0x18, 0x63, 0x51, 0x65,
  };
  static const uint8_t kTLSSeed2[16] = {
      0x7d, 0x24, 0x1a, 0x9d, 0x3c, 0x59, 0xbf, 0x3c,
      0x31, 0x1e, 0x2b, 0x21, 0x41, 0x8d, 0x32, 0x81,
  };
  static const uint8_t kTLSOutput[32] = {
      0xe2, 0x1d, 0xd6, 0xc2, 0x68, 0xc7, 0x57, 0x03, 0x2c, 0x2c, 0xeb,
      0xbb, 0xb8, 0xa9, 0x7d, 0xe9, 0xee, 0xe6, 0xc9, 0x47, 0x83, 0x0a,
      0xbd, 0x11, 0x60, 0x5d, 0xd5, 0x2c, 0x47, 0xb6, 0x05, 0x88,
  };
  uint8_t tls_output[sizeof(kTLSOutput)];
  if (!CRYPTO_tls1_prf(EVP_sha256(), tls_output, sizeof(tls_output), kTLSSecret,
                       sizeof(kTLSSecret), kTLSLabel, sizeof(kTLSLabel),
                       kTLSSeed1, sizeof(kTLSSeed1), kTLSSeed2,
                       sizeof(kTLSSeed2)) ||
      !check_test(kTLSOutput, tls_output, sizeof(kTLSOutput), "TLS-KDF KAT")) {
    goto err;
  }

  static const uint8_t kPBKDF2Password[] = {
    'A', 'W', 'S', '-', 'L', 'C', 'F', 'I', 'P', 'S', 'p', 'a', 's', 's', 'w',
    'o', 'r', 'd'
  };
  static const uint8_t kPBKDF2Salt[] = {
    's', 'a', 'l', 't', 'S', 'A', 'L', 'T', 's', 'a', 'l', 't', 'S', 'A', 'L',
    'T', 's', 'a', 'l', 't', 'S', 'A', 'L', 'T', 's', 'a', 'l', 't', 'S', 'A',
    'L', 'T', 's', 'a', 'l', 't'
  };
  const unsigned kPBKDF2Iterations = 2;
  static const uint8_t kPBKDF2DerivedKey[] = {
    0xc6, 0xac, 0x07, 0x79, 0xe4, 0xa1, 0x17, 0xc9, 0x22, 0x28, 0x7f, 0x5e,
    0x10, 0xe7, 0xee, 0x6b, 0xa7, 0x4d, 0x8b, 0x19, 0x51, 0x9b, 0x4c, 0xc7,
    0x38
  };
  uint8_t pbkdf2_output[sizeof(kPBKDF2DerivedKey)];
  if (!PKCS5_PBKDF2_HMAC((const char *)kPBKDF2Password, sizeof(kPBKDF2Password),
                         kPBKDF2Salt, sizeof(kPBKDF2Salt), kPBKDF2Iterations,
                         EVP_sha256(), sizeof(kPBKDF2DerivedKey),
                         pbkdf2_output) ||
      !check_test(kPBKDF2DerivedKey, pbkdf2_output, sizeof(kPBKDF2DerivedKey),
                  "PBKDF2 KAT")) {
    goto err;
  }

  static const uint8_t kSSKDFDigestInfo[] = {
      0xaf, 0x85, 0xce, 0x3e, 0xa3, 0x03, 0x35, 0x0a, 0x2a, 0xa1, 0x31,
      0xb8, 0x79, 0xea, 0x95, 0x4e, 0x1e, 0xe1, 0xe6, 0x85, 0xd2, 0xbf,
      0x9d, 0xb7, 0x95, 0x42, 0x02, 0xe2, 0xf5, 0xec, 0x30, 0x96};
  static const uint8_t kSSKDFDigestSharedSecret[] = {
      0x39, 0xa1, 0xe2, 0xb3, 0x89, 0x9e, 0x87, 0xef, 0xec, 0xf6, 0x27,
      0x12, 0x82, 0xd8, 0xf8, 0x00, 0x8f, 0x25, 0x26, 0x86, 0xdd, 0x35,
      0xbf, 0xc3, 0x9a, 0x0f, 0x71, 0x47, 0x8d, 0xa4, 0x8c, 0x69, 0x15,
      0x65, 0xce, 0xe4, 0x31, 0x25, 0x4d, 0xd5, 0x0c, 0xab, 0x74, 0x62,
      0xc6, 0xcf, 0x19, 0x9b, 0xe9, 0xbf, 0x5c};
  static const uint8_t kSSKDFDigestDerivedKey[] = {
      0x5a, 0x2e, 0x26, 0x64, 0x4d, 0x16, 0x22, 0x2c, 0xd6, 0x36, 0xa1, 0xfd,
      0xb5, 0x7b, 0xfa, 0xa1, 0x7f, 0x94, 0x44, 0x91, 0x27, 0x61, 0x2b, 0xcd,
      0x7b, 0xe1, 0xbb, 0x39, 0xcc, 0x18, 0xf3, 0x28, 0x93, 0xd3, 0xc6, 0x48,
      0xc1, 0x63, 0x72, 0xfb, 0x6e, 0x9c, 0x63, 0xde, 0x54, 0x33, 0xb1, 0xcc,
      0xde, 0xb5, 0x1b, 0xb5, 0xf1, 0x53, 0x68, 0xc8, 0xa8, 0x49, 0xa1, 0xe5,
      0xa4, 0xef, 0xc6, 0x66, 0xfd, 0x33, 0xee, 0xb9, 0xf6, 0x72, 0x8b, 0x04,
      0x79, 0xf7, 0x66, 0x68, 0xcf, 0xaf, 0xc1, 0x3a, 0x91, 0x36, 0x70, 0x74,
      0xde, 0xf2, 0xb5, 0x0e, 0x9d, 0x9a, 0x91, 0x8a, 0x12, 0x02, 0x10, 0x82,
      0x41, 0x65, 0xd5, 0x96, 0xad, 0x4f, 0x94, 0xa3, 0x23, 0x6e, 0xf7, 0xcf,
      0x58, 0x43, 0x28, 0x2a, 0x0a, 0x57, 0xa4, 0x83, 0x81, 0x9f, 0x63, 0xe0,
      0xcf, 0xb2, 0x08, 0x1d, 0xaf, 0x9c, 0xcf, 0x35, 0xc6, 0x6a, 0x03, 0xe7,
      0xa0, 0x2d, 0x38, 0x91, 0xf4, 0x50, 0x22, 0xe1, 0xc8, 0x9d, 0x88, 0x8a,
      0xa8, 0x08, 0x7e, 0x08, 0xf4, 0x5b, 0xab, 0xbc, 0x52, 0x06, 0x2b, 0x18,
      0xe6, 0xfb, 0x70, 0xc1, 0x2d, 0xcb, 0x29, 0xa1, 0x94, 0xd2, 0x3a, 0xbc,
      0x35, 0x1c, 0xfb, 0x3c, 0xf4, 0xf1, 0x61, 0xcc, 0x77, 0x5a, 0x3e, 0x71,
      0x1b, 0xb1, 0x50, 0x2d, 0x69, 0x01, 0xf6, 0x93, 0x14, 0x07, 0xa9, 0xae,
      0x86, 0x84, 0x76, 0xf9, 0x98, 0xd1, 0xca, 0x4c, 0xca, 0x29, 0x6a, 0x9f,
      0x14, 0x75, 0x2d, 0x14, 0xf4, 0x74, 0x27, 0xe6, 0x66, 0x28, 0x9f, 0x80,
      0x89, 0x2a, 0x3d, 0x14, 0xa8, 0x4f, 0xe3, 0x43, 0xfd, 0x78, 0xd0, 0xda,
      0xdb, 0xde, 0x18, 0x19, 0xac, 0xa9, 0x15, 0xf7, 0xc0, 0xc0, 0x24, 0x37,
      0x6b, 0x40, 0xcb, 0x34, 0xba, 0xe2, 0xd2, 0x6e, 0x9f, 0x45, 0x52, 0xb6,
      0xb1, 0xa2, 0x6f, 0xa5};  // 256 bytes
  uint8_t sskdf_digest_output[sizeof(kSSKDFDigestDerivedKey)];
  if (!SSKDF_digest(&sskdf_digest_output[0], sizeof(kSSKDFDigestDerivedKey),
                    EVP_sha256(), &kSSKDFDigestSharedSecret[0],
                    sizeof(kSSKDFDigestSharedSecret), &kSSKDFDigestInfo[0],
                    sizeof(kSSKDFDigestInfo)) ||
      !check_test(kSSKDFDigestDerivedKey, sskdf_digest_output,
                  sizeof(kSSKDFDigestDerivedKey), "SSKDF_digest KAT")) {
    fprintf(stderr, "SSKDF_digest failed.\n");
    goto err;
  }

  // KBKDF counter HMAC-SHA-256
  static const uint8_t kKBKDF_ctr_hmac_secret[] = {
    0xdd, 0x1d, 0x91, 0xb7, 0xd9, 0x0b, 0x2b, 0xd3, 0x13, 0x85, 0x33, 0xce,
    0x92, 0xb2, 0x72, 0xfb, 0xf8, 0xa3, 0x69, 0x31, 0x6a, 0xef, 0xe2, 0x42,
    0xe6, 0x59, 0xcc, 0x0a, 0xe2, 0x38, 0xaf, 0xe0
  };
  static const uint8_t kKBKDF_ctr_hmac_info[] = {
    0x01, 0x32, 0x2b, 0x96, 0xb3, 0x0a, 0xcd, 0x19, 0x79, 0x79, 0x44, 0x4e,
    0x46, 0x8e, 0x1c, 0x5c, 0x68, 0x59, 0xbf, 0x1b, 0x1c, 0xf9, 0x51, 0xb7,
    0xe7, 0x25, 0x30, 0x3e, 0x23, 0x7e, 0x46, 0xb8, 0x64, 0xa1, 0x45, 0xfa,
    0xb2, 0x5e, 0x51, 0x7b, 0x08, 0xf8, 0x68, 0x3d, 0x03, 0x15, 0xbb, 0x29,
    0x11, 0xd8, 0x0a, 0x0e, 0x8a, 0xba, 0x17, 0xf3, 0xb4, 0x13, 0xfa, 0xac
  };
  static const uint8_t kKBKDF_ctr_hmac_output[] = {
    0x10, 0x62, 0x13, 0x42, 0xbf, 0xb0, 0xfd, 0x40, 0x04, 0x6c, 0x0e, 0x29,
    0xf2, 0xcf, 0xdb, 0xf0
  };

  uint8_t kbkdf_ctr_hmac_output[sizeof(kKBKDF_ctr_hmac_output)];
  if (!KBKDF_ctr_hmac(kbkdf_ctr_hmac_output, sizeof(kbkdf_ctr_hmac_output),
                      EVP_sha256(),
                      kKBKDF_ctr_hmac_secret, sizeof(kKBKDF_ctr_hmac_secret),
                      kKBKDF_ctr_hmac_info, sizeof(kKBKDF_ctr_hmac_info)) ||
      !check_test(kKBKDF_ctr_hmac_output, kbkdf_ctr_hmac_output,
                  sizeof(kbkdf_ctr_hmac_output),
                  "KBKDF-CTR-HMAC-SHA-256 KAT")) {
    goto err;
  }
  ret = 1;

err:
  EVP_AEAD_CTX_cleanup(&aead_ctx);

  return ret;
}