scclib
Stable Cloud Computing C++ Library
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
scc::crypto::EccGfp Class Reference

Elliptic curve cryptography over Galois prime field GF(p) curve. More...

#include <ecc.h>

Public Types

enum class  Type {
  std_p192r1 , std_p224r1 , std_p256r1 , std_p384r1 ,
  std_p521r1 , std_p256sm2
}
 Standard field type. More...
 

Public Member Functions

 EccGfp (Type type=Type::std_p256r1)
 
void reset (Type type)
 Reset the curve to a new standard type.
 
bool valid () const
 
int bit_width () const
 Elliptic curve ordinal bit width.
 
void generate_key_pair (Bignum &priv_key, EccGfpPoint &pub_key)
 Generate a private and public key pair for this curve. More...
 
void private_key (Bignum &)
 Generate a private key. More...
 
void public_key (const Bignum &, EccGfpPoint &)
 Generate a public key corresponding to a private key. More...
 
void generate_public_key (const Bignum &, EccGfpPoint &)
 Generate a public key from the private key.
 

Static Public Member Functions

static bool valid (const EccGfp &)
 Verify the curve. More...
 
static bool validate_key_pair (const Bignum &, const EccGfpPoint &)
 Validate a key pair. More...
 
static void sign_ecdsa (const void *, int, const EccGfp &, const scc::crypto::Bignum &, scc::crypto::Bignum &, scc::crypto::Bignum &, scc::crypto::Bignum &)
 Sign a message using ECDSA. More...
 
static void sign_ecdsa (const void *loc, int len, const EccGfp::Type &t, const scc::crypto::Bignum &rk, scc::crypto::Bignum &tk, scc::crypto::Bignum &x, scc::crypto::Bignum &y)
 
static bool verify_ecdsa (const void *, int, const EccGfpPoint &, const scc::crypto::Bignum &, const scc::crypto::Bignum &)
 Verify a message using the ECDSA. More...
 
static void dh_shared_secret (const scc::crypto::Bignum &, const EccGfpPoint &, scc::crypto::Bignum &)
 Calculate a shared secret using the Diffie-Hellman scheme. More...
 

Friends

class EccGfpPoint
 

Detailed Description

Elliptic curve cryptography over Galois prime field GF(p) curve.

Uses standard fields only, does not allow custom parameters.

See https://www.secg.org/ for details on ec cryptography.

For X25519 and X448 (montgomery curves), see: https://tools.ietf.org/html/rfc7748

For security considerations, see: https://www.websecurity.digicert.com/content/dam/websitesecurity/digitalassets/desktop/pdfs/whitepaper/Elliptic_Curve_Cryptography_ECC_WP_en_us.pdf

Security level means the equivalent security strength to a symmetric key with the stated bit size. Use of algorithms with security below 128 bits is not recommended.

Definition at line 76 of file ecc.h.

Member Enumeration Documentation

◆ Type

Standard field type.

Enumerator
std_p192r1 

standard curve secp192r1 (96 bit security level)

std_p224r1 

standard curve secp224r1 (112 bit security level)

std_p256r1 

standard curve secp256r1 (128 bit security level)

std_p384r1 

standard curve secp384r1 (192 bit security level)

std_p521r1 

standard curve secp521r1 (256 bit security level)

std_p256sm2 

standard curve secp256sm2

Definition at line 85 of file ecc.h.

Member Function Documentation

◆ dh_shared_secret()

static void scc::crypto::EccGfp::dh_shared_secret ( const scc::crypto::Bignum ,
const EccGfpPoint ,
scc::crypto::Bignum  
)
static

Calculate a shared secret using the Diffie-Hellman scheme.

Parameters
my_privateMy private key.
other_publicOther public key.
shared_secretShared private key.

Given a private key and other parties public key on a curve, generate a shared secreet key (x coordinate on the curve), which will be the same for both parties.

◆ generate_key_pair()

void scc::crypto::EccGfp::generate_key_pair ( Bignum priv_key,
EccGfpPoint pub_key 
)
inline

Generate a private and public key pair for this curve.

Parameters
priv_keyPrivate key on the elliptic curve
pub_keyPublic key point corresponding to the private key

Definition at line 117 of file ecc.h.

◆ private_key()

void scc::crypto::EccGfp::private_key ( Bignum )

Generate a private key.

Parameters
priv_keyPrivate key on the elliptic curve

◆ public_key()

void scc::crypto::EccGfp::public_key ( const Bignum ,
EccGfpPoint  
)

Generate a public key corresponding to a private key.

Parameters
priv_keyPrivate key on the elliptic curve.
pub_keyPublic key point corresponding to the private key

◆ sign_ecdsa()

static void scc::crypto::EccGfp::sign_ecdsa ( const void *  ,
int  ,
const EccGfp ,
const scc::crypto::Bignum ,
scc::crypto::Bignum ,
scc::crypto::Bignum ,
scc::crypto::Bignum  
)
static

Sign a message using ECDSA.

A curve, temporary private and public key, and a regular private key should be provided.

The signature output is two coordinate points on the elliptic curve.

Generating a signature using ecdsa_secp256r1_sha256 (for example), is a two step process. First generate a hash of the data using sha256, then sign_ecdsa with the hash value.

Parameters
locSigning data buffer.
lenSigning data size. Must be > 0.
curveElliptical curve.
reg_privateRegular private key derived from the curve.
temp_privateTemporary (ephemeral) private key derived from the curve. Must be different than the regular key.
sig_xSignature X coordinate output.
sig_ySignature Y coordinate output.

◆ valid()

static bool scc::crypto::EccGfp::valid ( const EccGfp )
static

Verify the curve.

Failure means the curve parameters are invalid or insecure.

◆ validate_key_pair()

static bool scc::crypto::EccGfp::validate_key_pair ( const Bignum ,
const EccGfpPoint  
)
static

Validate a key pair.

Both must be a key pair on the public key's elliptical curve.

Parameters
priv_keyPrivate key
pub_keyPublic key

Public key must be valid on the elliptic curve.

◆ verify_ecdsa()

static bool scc::crypto::EccGfp::verify_ecdsa ( const void *  ,
int  ,
const EccGfpPoint ,
const scc::crypto::Bignum ,
const scc::crypto::Bignum  
)
static

Verify a message using the ECDSA.

Parameters
locSigning data buffer.
lenSigning data size. Must be > 0.
reg_publicRegular public key corresponding to the regular private key used to sign.
sig_xSignature X coordinate.
sig_ySignature Y coordinate.

Uses the curve associated with the point.


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