Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cECPGroupParams Class Reference

#include <cECPGroupParams.h>

Inheritance diagram for GrayLib::cECPGroupParams:
GrayLib::cECPGroup

Public Member Functions

 cECPGroupParams ()
 
ECP_CurveType_t get_ECP_CurveType () const
 
size_t get_SizeP () const
 
void DoModPLo (OUT cBigInteger &N) const
 
void DoModPHi (OUT cBigInteger &N) const
 
bool IsMatchECPParams (const cECPGroupParams &ref) const
 
HRESULT IsValidPrivateKey (const cBigUnsigned &d) const
 
void UpdateBits ()
 
void InjectCommon ()
 
HRESULT SetCopyECP (const THIS_t &rSrc)
 
void SetEmptyECPGroup ()
 
HRESULT ReadSpecifiedECDomain (cASNReader &r)
 
HRESULT SetECPGroupFromStr (RADIX_t radix, const char *p, const char *b, const char *gx, const char *gy, const char *n)
 
HRESULT ReadBigIntECDSA (OUT cBigInteger &x, const BYTE *buf, size_t nSizeBuffer) const
 

Public Attributes

cBigInteger m_P
 prime modulus of the base field More...
 
BIT_ENUM_t m_nPBits
 number of used bits in P. m_P.get_Highest1Bit(); More...
 
cBigInteger m_A
 
cBigInteger m_B
 
cECPPoint m_G
 generator of the (sub)group used More...
 
cBigInteger m_N
 
BIT_ENUM_t m_nNBits
 number of used bits get_Highest1Bit() in 1. m_N, or 2. private keys More...
 

Static Public Attributes

static const char * k_pszPEM = "EC PARAMETERS"
 "EC PARAMETERS" More...
 
static const WORD k_ECP_MAX_BITS = 521
 Maximum bit size of groups (that is, of N and P) More...
 
static const WORD k_ECP_MAX_BYTES = GETSIZEBYTES(k_ECP_MAX_BITS)
 
static const WORD k_COMB_MAX_D = (k_ECP_MAX_BITS + 1) / 2
 

Detailed Description

Define EC params similar to SpecifiedECDomain (SEC 1 C.2) For any ECP_CurveType_t https://tools.ietf.org/html/draft-ietf-pkix-ecc-pkalgs-01

Constructor & Destructor Documentation

◆ cECPGroupParams()

GrayLib::cECPGroupParams::cECPGroupParams ( )
inline

Member Function Documentation

◆ DoModPHi()

void GrayLib::cECPGroupParams::DoModPHi ( OUT cBigInteger N) const
inline

Reduce a cBigInteger mod m_P in-place, to use after InitAdd and OpMultiply. We known P, N and the result are positive, so InitSubU is correct, and a bit faster.

◆ DoModPLo()

void GrayLib::cECPGroupParams::DoModPLo ( OUT cBigInteger N) const
inline

Reduce a cBigInteger mod m_P in-place, to use after InitSubtract N.s < 0 is a very fast test, which fails only if N is 0

◆ get_ECP_CurveType()

ECP_CurveType_t GrayLib::cECPGroupParams::get_ECP_CurveType ( ) const
inline

Get the type of a curve. ECP_CurveType_t

◆ get_SizeP()

size_t GrayLib::cECPGroupParams::get_SizeP ( ) const
inline

◆ InjectCommon()

void GrayLib::cECPGroupParams::InjectCommon ( )

Assume p,n,a,b,g are all set.

◆ IsMatchECPParams()

bool GrayLib::cECPGroupParams::IsMatchECPParams ( const cECPGroupParams ref) const

Compare to the group we were given, starting with easy tests

◆ IsValidPrivateKey()

HRESULT GrayLib::cECPGroupParams::IsValidPrivateKey ( const cBigUnsigned d) const

Check that an cBigInteger is a valid private key for this curve type.

  • d = Integer to check
    Returns
    0 if point is a valid private key, NTE_BAD_KEY otherwise.

◆ ReadBigIntECDSA()

HRESULT GrayLib::cECPGroupParams::ReadBigIntECDSA ( OUT cBigInteger x,
const BYTE *  buf,
size_t  nSizeBuffer 
) const

Derive a suitable integer for group pGroup from a buffer of length nSizeBuffer SEC1 4.1.3 step 5 aka SEC1 4.1.4 step 3

◆ ReadSpecifiedECDomain()

HRESULT GrayLib::cECPGroupParams::ReadSpecifiedECDomain ( cASNReader r)

Parse a SpecifiedECDomain (SEC 1 C.2) and (mostly) fill the group with it. WARNING: the resulting group should only be used with put_ECPGroupId(), since its base point may not be set correctly if it was encoded compressed.

SpecifiedECDomain ::= SEQUENCE { version SpecifiedECDomainVersion(ecdpVer1 | ecdpVer2 | ecdpVer3, ...), fieldID FieldID {{FieldTypes}}, curve Curve, base ECPoint, order INTEGER, cofactor INTEGER OPTIONAL, hash HashAlgorithm OPTIONAL, ... }

We only support prime-field as field type, and ignore hash and cofactor.

◆ SetCopyECP()

HRESULT GrayLib::cECPGroupParams::SetCopyECP ( const THIS_t rSrc)

Copy custom params. not used for predefined curve.

Todo:
SetCopyECP

◆ SetECPGroupFromStr()

HRESULT GrayLib::cECPGroupParams::SetECPGroupFromStr ( RADIX_t  radix,
const char *  p,
const char *  b,
const char *  gx,
const char *  gy,
const char *  n 
)

Import an ECP group from ASCII strings, case A == -3

  • radix = Input numeric base
  • p = Prime modulus of the base field
  • b = Constant term in the equation
  • gx = The generator's X coordinate
  • gy = The generator's Y coordinate
  • n = The generator's order
    Returns
    0 if successful, or <0 = error
    Note
    Sets all fields except modp. m_pECPGroupDef is now wrong ??

◆ SetEmptyECPGroup()

void GrayLib::cECPGroupParams::SetEmptyECPGroup ( )

like cMem::ZeroSecure(this, sizeof(cECPGroup));

◆ UpdateBits()

void GrayLib::cECPGroupParams::UpdateBits ( )

Always call this after loading or changing values.

Member Data Documentation

◆ k_COMB_MAX_D

const WORD GrayLib::cECPGroupParams::k_COMB_MAX_D = (k_ECP_MAX_BITS + 1) / 2
static

◆ k_ECP_MAX_BITS

const WORD GrayLib::cECPGroupParams::k_ECP_MAX_BITS = 521
static

Maximum bit size of groups (that is, of N and P)

◆ k_ECP_MAX_BYTES

const WORD GrayLib::cECPGroupParams::k_ECP_MAX_BYTES = GETSIZEBYTES(k_ECP_MAX_BITS)
static

◆ k_pszPEM

const char * GrayLib::cECPGroupParams::k_pszPEM = "EC PARAMETERS"
static

"EC PARAMETERS"

◆ m_A

cBigInteger GrayLib::cECPGroupParams::m_A
  1. A in the equation, or 2. (A + 2) / 4. (Set to -3 if not used?)

◆ m_B

cBigInteger GrayLib::cECPGroupParams::m_B
  1. B in the equation, or 2. unused

◆ m_G

cECPPoint GrayLib::cECPGroupParams::m_G

generator of the (sub)group used

◆ m_N

cBigInteger GrayLib::cECPGroupParams::m_N
  1. the order of G, or 2. unused

◆ m_nNBits

BIT_ENUM_t GrayLib::cECPGroupParams::m_nNBits

number of used bits get_Highest1Bit() in 1. m_N, or 2. private keys

◆ m_nPBits

BIT_ENUM_t GrayLib::cECPGroupParams::m_nPBits

number of used bits in P. m_P.get_Highest1Bit();

◆ m_P

cBigInteger GrayLib::cECPGroupParams::m_P

prime modulus of the base field


The documentation for this class was generated from the following files: