Classes | Macros | Functions | Variables
bn_test.cc File Reference
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <utility>
#include <gtest/gtest.h>
#include <openssl/bio.h>
#include <openssl/bn.h>
#include <openssl/bytestring.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/mem.h>
#include <openssl/rand.h>
#include "./internal.h"
#include "./rsaz_exp.h"
#include "../../internal.h"
#include "../../test/abi_test.h"
#include "../../test/file_test.h"
#include "../../test/test_util.h"
#include "../../test/wycheproof_util.h"
Include dependency graph for bn_test.cc:

Go to the source code of this file.

Classes

struct  ASN1InvalidTest
 
struct  ASN1Test
 
class  BIGNUMFileTest
 
class  BNTest
 
struct  MPITest
 

Macros

#define EXPECT_BIGNUMS_EQUAL(op, a, b)   EXPECT_PRED_FORMAT3(AssertBIGNUMSEqual, op, a, b)
 

Functions

static bssl::UniquePtr< BIGNUMASCIIToBIGNUM (const char *in)
 
static testing::AssertionResult AssertBIGNUMSEqual (const char *operation_expr, const char *expected_expr, const char *actual_expr, const char *operation, const BIGNUM *expected, const BIGNUM *actual)
 
static int DecimalToBIGNUM (bssl::UniquePtr< BIGNUM > *out, const char *in)
 
static int HexToBIGNUM (bssl::UniquePtr< BIGNUM > *out, const char *in)
 
 TEST_F (BNTest, ASC2BN)
 
 TEST_F (BNTest, ASN1)
 
 TEST_F (BNTest, BadModulus)
 
 TEST_F (BNTest, BN2BinPadded)
 
 TEST_F (BNTest, BN2Dec)
 
 TEST_F (BNTest, CmpWord)
 
 TEST_F (BNTest, CountLowZeroBits)
 
 TEST_F (BNTest, Dec2BN)
 
 TEST_F (BNTest, DISABLED_WycheproofPrimality)
 
 TEST_F (BNTest, ExpZeroModOne)
 
 TEST_F (BNTest, Hex2BN)
 
 TEST_F (BNTest, LessThanWords)
 
 TEST_F (BNTest, LittleEndian)
 
 TEST_F (BNTest, MillerRabinIteration)
 
 TEST_F (BNTest, MPI)
 
 TEST_F (BNTest, NegativeZero)
 
 TEST_F (BNTest, NonMinimal)
 
 TEST_F (BNTest, NumBitsWord)
 
 TEST_F (BNTest, Pow2)
 
 TEST_F (BNTest, PrimeChecking)
 
 TEST_F (BNTest, Rand)
 
 TEST_F (BNTest, RandRange)
 
 TEST_F (BNTest, SetGetU64)
 
 TEST_F (BNTest, SmallPrime)
 
 TEST_F (BNTest, TestVectors)
 
 TEST_F (BNTest, WriteIntoNegative)
 
static void TestExp (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestGCD (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestLShift (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestLShift1 (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestModExp (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestModInv (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestModMul (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestModSqrt (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestModSquare (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestNotModSquare (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestProduct (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestQuotient (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestRShift (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestSquare (BIGNUMFileTest *t, BN_CTX *ctx)
 
static void TestSum (BIGNUMFileTest *t, BN_CTX *ctx)
 

Variables

static const ASN1InvalidTest kASN1InvalidTests []
 
static const ASN1Test kASN1Tests []
 
static const MPITest kMPITests []
 
static const int kPrimes []
 

Macro Definition Documentation

◆ EXPECT_BIGNUMS_EQUAL

#define EXPECT_BIGNUMS_EQUAL (   op,
  a,
  b 
)    EXPECT_PRED_FORMAT3(AssertBIGNUMSEqual, op, a, b)

Definition at line 183 of file bn_test.cc.

Function Documentation

◆ ASCIIToBIGNUM()

static bssl::UniquePtr<BIGNUM> ASCIIToBIGNUM ( const char *  in)
static

Definition at line 1194 of file bn_test.cc.

◆ AssertBIGNUMSEqual()

static testing::AssertionResult AssertBIGNUMSEqual ( const char *  operation_expr,
const char *  expected_expr,
const char *  actual_expr,
const char *  operation,
const BIGNUM expected,
const BIGNUM actual 
)
static

Definition at line 162 of file bn_test.cc.

◆ DecimalToBIGNUM()

static int DecimalToBIGNUM ( bssl::UniquePtr< BIGNUM > *  out,
const char *  in 
)
static

Definition at line 1131 of file bn_test.cc.

◆ HexToBIGNUM()

static int HexToBIGNUM ( bssl::UniquePtr< BIGNUM > *  out,
const char *  in 
)
static

Definition at line 98 of file bn_test.cc.

◆ TEST_F() [1/26]

TEST_F ( BNTest  ,
ASC2BN   
)

Definition at line 1202 of file bn_test.cc.

◆ TEST_F() [2/26]

TEST_F ( BNTest  ,
ASN1   
)

Definition at line 1417 of file bn_test.cc.

◆ TEST_F() [3/26]

TEST_F ( BNTest  ,
BadModulus   
)

Definition at line 1533 of file bn_test.cc.

◆ TEST_F() [4/26]

TEST_F ( BNTest  ,
BN2BinPadded   
)

Definition at line 1035 of file bn_test.cc.

◆ TEST_F() [5/26]

TEST_F ( BNTest  ,
BN2Dec   
)

Definition at line 1680 of file bn_test.cc.

◆ TEST_F() [6/26]

TEST_F ( BNTest  ,
CmpWord   
)

Definition at line 1638 of file bn_test.cc.

◆ TEST_F() [7/26]

TEST_F ( BNTest  ,
CountLowZeroBits   
)

Definition at line 2650 of file bn_test.cc.

◆ TEST_F() [8/26]

TEST_F ( BNTest  ,
Dec2BN   
)

Definition at line 1138 of file bn_test.cc.

◆ TEST_F() [9/26]

TEST_F ( BNTest  ,
DISABLED_WycheproofPrimality   
)

Definition at line 2354 of file bn_test.cc.

◆ TEST_F() [10/26]

TEST_F ( BNTest  ,
ExpZeroModOne   
)

Definition at line 1592 of file bn_test.cc.

◆ TEST_F() [11/26]

TEST_F ( BNTest  ,
Hex2BN   
)

Definition at line 1166 of file bn_test.cc.

◆ TEST_F() [12/26]

TEST_F ( BNTest  ,
LessThanWords   
)

Definition at line 2425 of file bn_test.cc.

◆ TEST_F() [13/26]

TEST_F ( BNTest  ,
LittleEndian   
)

Definition at line 1088 of file bn_test.cc.

◆ TEST_F() [14/26]

TEST_F ( BNTest  ,
MillerRabinIteration   
)

Definition at line 2325 of file bn_test.cc.

◆ TEST_F() [15/26]

TEST_F ( BNTest  ,
MPI   
)

Definition at line 1259 of file bn_test.cc.

◆ TEST_F() [16/26]

TEST_F ( BNTest  ,
NegativeZero   
)

Definition at line 1464 of file bn_test.cc.

◆ TEST_F() [17/26]

TEST_F ( BNTest  ,
NonMinimal   
)

Definition at line 2515 of file bn_test.cc.

◆ TEST_F() [18/26]

TEST_F ( BNTest  ,
NumBitsWord   
)

Definition at line 2389 of file bn_test.cc.

◆ TEST_F() [19/26]

TEST_F ( BNTest  ,
Pow2   
)

Definition at line 1747 of file bn_test.cc.

◆ TEST_F() [20/26]

TEST_F ( BNTest  ,
PrimeChecking   
)

Definition at line 2008 of file bn_test.cc.

◆ TEST_F() [21/26]

TEST_F ( BNTest  ,
Rand   
)

Definition at line 1280 of file bn_test.cc.

◆ TEST_F() [22/26]

TEST_F ( BNTest  ,
RandRange   
)

Definition at line 1349 of file bn_test.cc.

◆ TEST_F() [23/26]

TEST_F ( BNTest  ,
SetGetU64   
)

Definition at line 1705 of file bn_test.cc.

◆ TEST_F() [24/26]

TEST_F ( BNTest  ,
SmallPrime   
)

Definition at line 1628 of file bn_test.cc.

◆ TEST_F() [25/26]

TEST_F ( BNTest  ,
TestVectors   
)

Definition at line 981 of file bn_test.cc.

◆ TEST_F() [26/26]

TEST_F ( BNTest  ,
WriteIntoNegative   
)

Definition at line 2690 of file bn_test.cc.

◆ TestExp()

static void TestExp ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 833 of file bn_test.cc.

◆ TestGCD()

static void TestGCD ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 913 of file bn_test.cc.

◆ TestLShift()

static void TestLShift ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 356 of file bn_test.cc.

◆ TestLShift1()

static void TestLShift1 ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 297 of file bn_test.cc.

◆ TestModExp()

static void TestModExp ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 782 of file bn_test.cc.

◆ TestModInv()

static void TestModInv ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 889 of file bn_test.cc.

◆ TestModMul()

static void TestModMul ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 629 of file bn_test.cc.

◆ TestModSqrt()

static void TestModSqrt ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 847 of file bn_test.cc.

◆ TestModSquare()

static void TestModSquare ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 708 of file bn_test.cc.

◆ TestNotModSquare()

static void TestNotModSquare ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 872 of file bn_test.cc.

◆ TestProduct()

static void TestProduct ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 479 of file bn_test.cc.

◆ TestQuotient()

static void TestQuotient ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 542 of file bn_test.cc.

◆ TestRShift()

static void TestRShift ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 380 of file bn_test.cc.

◆ TestSquare()

static void TestSquare ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 406 of file bn_test.cc.

◆ TestSum()

static void TestSum ( BIGNUMFileTest t,
BN_CTX ctx 
)
static

Definition at line 186 of file bn_test.cc.

Variable Documentation

◆ kASN1InvalidTests

const ASN1InvalidTest kASN1InvalidTests[]
static
Initial value:
= {
{"\x03\x01\x00", 3},
{"\x02\x00", 2},
{"\x02\x01\x80", 3},
{"\x02\x01\xff", 3},
{"\x02\x02\x00\x01", 4},
}

Definition at line 1405 of file bn_test.cc.

◆ kASN1Tests

const ASN1Test kASN1Tests[]
static
Initial value:
= {
{"0", "\x02\x01\x00", 3},
{"1", "\x02\x01\x01", 3},
{"127", "\x02\x01\x7f", 3},
{"128", "\x02\x02\x00\x80", 4},
{"0xdeadbeef", "\x02\x05\x00\xde\xad\xbe\xef", 7},
{"0x0102030405060708",
"\x02\x08\x01\x02\x03\x04\x05\x06\x07\x08", 10},
{"0xffffffffffffffff",
"\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff", 11},
}

Definition at line 1388 of file bn_test.cc.

◆ kMPITests

const MPITest kMPITests[]
static
Initial value:
= {
{ "0", "\x00\x00\x00\x00", 4 },
{ "1", "\x00\x00\x00\x01\x01", 5 },
{ "-1", "\x00\x00\x00\x01\x81", 5 },
{ "128", "\x00\x00\x00\x02\x00\x80", 6 },
{ "256", "\x00\x00\x00\x02\x01\x00", 6 },
{ "-256", "\x00\x00\x00\x02\x81\x00", 6 },
}

Definition at line 1250 of file bn_test.cc.

◆ kPrimes

const int kPrimes[]
static

Definition at line 1799 of file bn_test.cc.



grpc
Author(s):
autogenerated on Fri May 16 2025 03:01:04