MPHELL  5.0.0
Data Structures | Macros | Typedefs | Functions
mphell_tuto_ecdsa.c File Reference

Tutorial for ecdsa signature and verification (with precomputation) using mphell. More...

#include <stdio.h>
#include "mphell/mphell.h"
Include dependency graph for mphell_tuto_ecdsa.c:

Go to the source code of this file.

Data Structures

struct  ecdsa_sig
 Define an ECDSA signature. More...
 
struct  ecdsa_precomp
 Precomputation structure. More...
 

Macros

#define PRECOMP_WIN_SIZE   9
 
#define PRECOMP_SIZE   256
 

Typedefs

typedef struct ecdsa_sig ecdsa_sig_t
 Define the ECDSA signature type.
 
typedef ecdsa_sig_t ecdsa_sig[1]
 Pointer on an allocated ecdsa_sig_t structure.
 
typedef struct ecdsa_precomp ecdsa_precomp_t
 Precomputation structure type.
 
typedef ecdsa_precomp_t ecdsa_precomp[1]
 Pointer on an allocated ecdsa_precomp_t structure.
 

Functions

void ecdsa_sign_alloc (ecdsa_sig *sig, uint8_t size)
 Allocate a signature structure. More...
 
void ecdsa_sign_free (ecdsa_sig *sig)
 Free a used signature structure. More...
 
void ecdsa_precal (ecdsa_precomp *precomp, ec_point *key, ec_curve_ptr E)
 Compute 1*G, 2*G, 3*G, 4*G, 5*G, 6*G, 7*G and 1*Q, 2*Q, 3*Q, 4*Q, 5*Q, 6*Q, 7*Q where G is the base point and Q the public key. More...
 
void ecdsa_precal_free (ecdsa_precomp *precomp, ec_curve_ptr E)
 Free memory of the ecdsa_precomp structure. More...
 
void ecdsa_sign (unsigned char *hash, ecdsa_sig *sig, number_ptr priv_key, ec_curve *curve)
 Sign "hash" with ECDSA algorithm using the EC "curve" and the private key "key". More...
 
int8_t ecdsa_pub_key_validation (ec_point *pub_key, ec_curve *curve)
 Verify that the public key is valid (id est check taht pub_key belongs to the curve, that pub_key is not the neutral element and that pub_key is of ordre n) More...
 
int8_t ecdsa_verify (unsigned char *hash, ecdsa_sig *sig, ec_point *pub_key, ec_curve *curve, ecdsa_precomp precomp)
 Verify the signature "sig" of hash "hash" using public key "pub_key" and the EC "curve". More...
 
int main ()
 

Detailed Description

Tutorial for ecdsa signature and verification (with precomputation) using mphell.

Definition in file mphell_tuto_ecdsa.c.

Function Documentation

◆ ecdsa_precal()

void ecdsa_precal ( ecdsa_precomp precomp,
ec_point key,
ec_curve_ptr  E 
)

Compute 1*G, 2*G, 3*G, 4*G, 5*G, 6*G, 7*G and 1*Q, 2*Q, 3*Q, 4*Q, 5*Q, 6*Q, 7*Q where G is the base point and Q the public key.

Parameters
precompPointer on an allocated ecdsa_precomp structure
keyPublic key
EElliptic curve

Definition at line 137 of file mphell_tuto_ecdsa.c.

◆ ecdsa_precal_free()

void ecdsa_precal_free ( ecdsa_precomp precomp,
ec_curve_ptr  E 
)

Free memory of the ecdsa_precomp structure.

Parameters
precompPointer on an allocated ecdsa_precomp structure

Definition at line 171 of file mphell_tuto_ecdsa.c.

◆ ecdsa_pub_key_validation()

int8_t ecdsa_pub_key_validation ( ec_point pub_key,
ec_curve curve 
)

Verify that the public key is valid (id est check taht pub_key belongs to the curve, that pub_key is not the neutral element and that pub_key is of ordre n)

Parameters
hashH(m) where H is a cryptographic hash function and m the message to sign. Must be written under hexadecimal form. ex: 64 hexadecimal characters for sha256.
pub_keyPublic key
curveElliptic curve
Returns
1 on success, 0 on failure

Definition at line 269 of file mphell_tuto_ecdsa.c.

◆ ecdsa_sign()

void ecdsa_sign ( unsigned char *  hash,
ecdsa_sig sig,
number_ptr  priv_key,
ec_curve curve 
)

Sign "hash" with ECDSA algorithm using the EC "curve" and the private key "key".

Parameters
hashH(m) where H is a cryptographic hash function and m the message to sign. Must be written under hexadecimal form. ex: 64 hexadecimal characters for sha256.
sigDestination signature. Pointer on an allocated ecdsa_sig structure.
priv_keyPrivate key
curveElliptic curve

Definition at line 191 of file mphell_tuto_ecdsa.c.

◆ ecdsa_sign_alloc()

void ecdsa_sign_alloc ( ecdsa_sig sig,
uint8_t  size 
)

Allocate a signature structure.

Parameters
sigSignature
sigSignature
sizeSize of the prime field (in blocks)

Definition at line 98 of file mphell_tuto_ecdsa.c.

◆ ecdsa_sign_free()

void ecdsa_sign_free ( ecdsa_sig sig)

Free a used signature structure.

Parameters
sigSignature
sizeSize (in block) of the signature
sigSignature

Definition at line 115 of file mphell_tuto_ecdsa.c.

◆ ecdsa_verify()

int8_t ecdsa_verify ( unsigned char *  hash,
ecdsa_sig sig,
ec_point pub_key,
ec_curve curve,
ecdsa_precomp  precomp 
)

Verify the signature "sig" of hash "hash" using public key "pub_key" and the EC "curve".

Parameters
hashH(m) where H is a cryptographic hash function and m the message to sign. Must be written under hexadecimal form. ex: 64 hexadecimal characters for sha256.
sigSignature of hash
pub_keyPublic key
curveElliptic curve
precompPrecomputation structure, used in the wNAF multiplication point method
Returns
1 on success, 0 on failure

Definition at line 306 of file mphell_tuto_ecdsa.c.