chromium/third_party/boringssl/src/crypto/fipsmodule/ec/ec_test.cc

/* Copyright (c) 2014, 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 <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <vector>

#include <gtest/gtest.h>

#include <openssl/bn.h>
#include <openssl/bytestring.h>
#include <openssl/crypto.h>
#include <openssl/ec_key.h>
#include <openssl/err.h>
#include <openssl/mem.h>
#include <openssl/nid.h>
#include <openssl/obj.h>
#include <openssl/span.h>

#include "../../ec_extra/internal.h"
#include "../../test/file_test.h"
#include "../../test/test_util.h"
#include "../bn/internal.h"
#include "internal.h"


// kECKeyWithoutPublic is an ECPrivateKey with the optional publicKey field
// omitted.
static const uint8_t kECKeyWithoutPublic[] =;

// kECKeySpecifiedCurve is the above key with P-256's parameters explicitly
// spelled out rather than using a named curve.
static const uint8_t kECKeySpecifiedCurve[] =;

// kECKeyMissingZeros is an ECPrivateKey containing a degenerate P-256 key where
// the private key is one. The private key is incorrectly encoded without zero
// padding.
static const uint8_t kECKeyMissingZeros[] =;

// kECKeyMissingZeros is an ECPrivateKey containing a degenerate P-256 key where
// the private key is one. The private key is encoded with the required zero
// padding.
static const uint8_t kECKeyWithZeros[] =;

static const uint8_t kECKeyWithZerosPublic[] =;

static const uint8_t kECKeyWithZerosRawPrivate[] =;

// DecodeECPrivateKey decodes |in| as an ECPrivateKey structure and returns the
// result or nullptr on error.
static bssl::UniquePtr<EC_KEY> DecodeECPrivateKey(const uint8_t *in,
                                                  size_t in_len) {}

// EncodeECPrivateKey encodes |key| as an ECPrivateKey structure into |*out|. It
// returns true on success or false on error.
static bool EncodeECPrivateKey(std::vector<uint8_t> *out, const EC_KEY *key) {}

static bool EncodeECPoint(std::vector<uint8_t> *out, const EC_GROUP *group,
                          const EC_POINT *p, point_conversion_form_t form) {}

TEST(ECTest, Encoding) {}

TEST(ECTest, ZeroPadding) {}

TEST(ECTest, SpecifiedCurve) {}

TEST(ECTest, ArbitraryCurve) {}

TEST(ECTest, SetKeyWithoutGroup) {}

TEST(ECTest, SetNULLKey) {}

TEST(ECTest, GroupMismatch) {}

TEST(ECTest, EmptyKey) {}

static bssl::UniquePtr<BIGNUM> HexToBIGNUM(const char *hex) {}

// Test that point arithmetic works with custom curves using an arbitrary |a|,
// rather than -3, as is common (and more efficient).
TEST(ECTest, BrainpoolP256r1) {}

class ECCurveTest : public testing::TestWithParam<int> {};

TEST_P(ECCurveTest, SetAffine) {}

TEST_P(ECCurveTest, IsOnCurve) {}

TEST_P(ECCurveTest, Compare) {}

TEST_P(ECCurveTest, GenerateFIPS) {}

TEST_P(ECCurveTest, AddingEqualPoints) {}

TEST_P(ECCurveTest, MulZero) {}

// Test that multiplying by the order produces ∞ and, moreover, that callers may
// do so. |EC_POINT_mul| is almost exclusively used with reduced scalars, with
// this exception. This comes from consumers following NIST SP 800-56A section
// 5.6.2.3.2. (Though all our curves have cofactor one, so this check isn't
// useful.)
TEST_P(ECCurveTest, MulOrder) {}

// Test that |EC_POINT_mul| works with out-of-range scalars. The operation will
// not be constant-time, but we'll compute the right answer.
TEST_P(ECCurveTest, MulOutOfRange) {}

// Test that 10×∞ + G = G.
TEST_P(ECCurveTest, Mul) {}

TEST_P(ECCurveTest, MulNonMinimal) {}

// Test that EC_KEY_set_private_key rejects invalid values.
TEST_P(ECCurveTest, SetInvalidPrivateKey) {}

TEST_P(ECCurveTest, IgnoreOct2PointReturnValue) {}

TEST_P(ECCurveTest, DoubleSpecialCase) {}

// This a regression test for a P-224 bug, but we may as well run it for all
// curves.
TEST_P(ECCurveTest, P224Bug) {}

TEST_P(ECCurveTest, GPlusMinusG) {}

// Test that we refuse to encode or decode the point at infinity.
TEST_P(ECCurveTest, EncodeInfinity) {}

static std::vector<int> AllCurves() {}

static std::string CurveToString(const testing::TestParamInfo<int> &params) {}

INSTANTIATE_TEST_SUITE_P();

static const EC_GROUP *GetCurve(FileTest *t, const char *key) {}

static bssl::UniquePtr<BIGNUM> GetBIGNUM(FileTest *t, const char *key) {}

TEST(ECTest, ScalarBaseMultVectors) {}

// These tests take a very long time, but are worth running when we make
// non-trivial changes to the EC code.
TEST(ECTest, DISABLED_ScalarBaseMultVectorsTwoPoint) {}

static std::vector<uint8_t> HexToBytes(const char *str) {}

TEST(ECTest, DeriveFromSecret) {}

TEST(ECTest, HashToCurve) {}

TEST(ECTest, HashToScalar) {}