xref: /aosp_15_r20/external/boringssl/src/crypto/fipsmodule/ec/p256_test.cc (revision 8fb009dc861624b67b6cdb62ea21f0f22d0c584b)
1 /* Copyright (c) 2023, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #include <gtest/gtest.h>
16 #include "../../internal.h"
17 #include "../../test/abi_test.h"
18 
19 #if !defined(OPENSSL_NO_ASM) && defined(__GNUC__) && defined(__x86_64__) && \
20     defined(SUPPORTS_ABI_TEST)
21 extern "C" {
22 #include "../../../third_party/fiat/p256_64.h"
23 }
24 
TEST(P256Test,AdxMulABI)25 TEST(P256Test, AdxMulABI) {
26   static const uint64_t in1[4] = {0}, in2[4] = {0};
27   uint64_t out[4];
28   if (CRYPTO_is_BMI1_capable() && CRYPTO_is_BMI2_capable() &&
29       CRYPTO_is_ADX_capable()) {
30     CHECK_ABI(fiat_p256_adx_mul, out, in1, in2);
31   } else {
32     GTEST_SKIP() << "Can't test ABI of ADX code without ADX";
33   }
34 }
35 
36 #include <assert.h>
TEST(P256Test,AdxSquareABI)37 TEST(P256Test, AdxSquareABI) {
38   static const uint64_t in[4] = {0};
39   uint64_t out[4];
40   if (CRYPTO_is_BMI1_capable() && CRYPTO_is_BMI2_capable() &&
41       CRYPTO_is_ADX_capable()) {
42     CHECK_ABI(fiat_p256_adx_sqr, out, in);
43   } else {
44     GTEST_SKIP() << "Can't test ABI of ADX code without ADX";
45   }
46 }
47 #endif
48