chromium/third_party/boringssl/src/crypto/fipsmodule/self_check/self_check.c.inc

/* Copyright (c) 2017, Google Inc.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */

#include <openssl/crypto.h>

#include <stdio.h>
#include <stdlib.h>

#include <openssl/aead.h>
#include <openssl/aes.h>
#include <openssl/bn.h>
#include <openssl/ctrdrbg.h>
#include <openssl/dh.h>
#include <openssl/digest.h>
#include <openssl/ec.h>
#include <openssl/ecdsa.h>
#include <openssl/ec_key.h>
#include <openssl/hkdf.h>
#include <openssl/hmac.h>
#include <openssl/nid.h>
#include <openssl/rsa.h>
#include <openssl/sha.h>

#include "../../internal.h"
#include "../dh/internal.h"
#include "../ec/internal.h"
#include "../ecdsa/internal.h"
#include "../rand/internal.h"
#include "../rsa/internal.h"
#include "../service_indicator/internal.h"
#include "../tls/internal.h"


// MSVC wants to put a NUL byte at the end of non-char arrays and so cannot
// compile the real logic.
#if defined(_MSC_VER)

int BORINGSSL_self_test(void) {
  return 0;
}

#else

static void hexdump(const uint8_t *in, size_t len) {}

static int check_test(const void *expected, const void *actual,
                      size_t expected_len, const char *name) {}

static int set_bignum(BIGNUM **out, const uint8_t *in, size_t len) {}

static RSA *self_test_rsa_key(void) {}

static EC_KEY *self_test_ecdsa_key(void) {}

static DH *self_test_dh(void) {}


// Lazy self-tests
//
// Self tests that are slow are deferred until the corresponding algorithm is
// actually exercised, in FIPS mode. (In non-FIPS mode these tests are only run
// when requested by |BORINGSSL_self_test|.)

static int boringssl_self_test_rsa(void) {}

static int boringssl_self_test_ecc(void) {}

static int boringssl_self_test_ffdh(void) {}

#if defined(BORINGSSL_FIPS)

static void run_self_test_rsa(void) {
  FIPS_service_indicator_lock_state();
  if (!boringssl_self_test_rsa()) {
    BORINGSSL_FIPS_abort();
  }
  FIPS_service_indicator_unlock_state();
}

DEFINE_STATIC_ONCE(g_self_test_once_rsa);

void boringssl_ensure_rsa_self_test(void) {
  CRYPTO_once(g_self_test_once_rsa_bss_get(), run_self_test_rsa);
}

static void run_self_test_ecc(void) {
  FIPS_service_indicator_lock_state();
  if (!boringssl_self_test_ecc()) {
    BORINGSSL_FIPS_abort();
  }
  FIPS_service_indicator_unlock_state();
}

DEFINE_STATIC_ONCE(g_self_test_once_ecc);

void boringssl_ensure_ecc_self_test(void) {
  CRYPTO_once(g_self_test_once_ecc_bss_get(), run_self_test_ecc);
}

static void run_self_test_ffdh(void) {
  FIPS_service_indicator_lock_state();
  if (!boringssl_self_test_ffdh()) {
    BORINGSSL_FIPS_abort();
  }
  FIPS_service_indicator_unlock_state();
}

DEFINE_STATIC_ONCE(g_self_test_once_ffdh);

void boringssl_ensure_ffdh_self_test(void) {
  CRYPTO_once(g_self_test_once_ffdh_bss_get(), run_self_test_ffdh);
}

#endif  // BORINGSSL_FIPS


// Startup self tests.
//
// These tests are run at process start when in FIPS mode.

int boringssl_self_test_sha256(void) {}

int boringssl_self_test_sha512(void) {}

int boringssl_self_test_hmac_sha256(void) {}

static int boringssl_self_test_fast(void) {}

int BORINGSSL_self_test(void) {}

#if defined(BORINGSSL_FIPS)
int boringssl_self_test_startup(void) {
  return boringssl_self_test_fast();
}
#endif

#endif  // !_MSC_VER