MPHELL
5.0.0
|
Tutorial for ecdsa signature and verification (with precomputation) using mphell. More...
#include <stdio.h>
#include "mphell/mphell.h"
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 () |
Tutorial for ecdsa signature and verification (with precomputation) using mphell.
Definition in file mphell_tuto_ecdsa.c.
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.
precomp | Pointer on an allocated ecdsa_precomp structure |
key | Public key |
E | Elliptic curve |
Definition at line 137 of file mphell_tuto_ecdsa.c.
void ecdsa_precal_free | ( | ecdsa_precomp * | precomp, |
ec_curve_ptr | E | ||
) |
Free memory of the ecdsa_precomp structure.
precomp | Pointer on an allocated ecdsa_precomp structure |
Definition at line 171 of file mphell_tuto_ecdsa.c.
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)
hash | H(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_key | Public key |
curve | Elliptic curve |
Definition at line 269 of file mphell_tuto_ecdsa.c.
Sign "hash" with ECDSA algorithm using the EC "curve" and the private key "key".
hash | H(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. |
sig | Destination signature. Pointer on an allocated ecdsa_sig structure. |
priv_key | Private key |
curve | Elliptic curve |
Definition at line 191 of file mphell_tuto_ecdsa.c.
void ecdsa_sign_alloc | ( | ecdsa_sig * | sig, |
uint8_t | size | ||
) |
Allocate a signature structure.
sig | Signature |
sig | Signature |
size | Size of the prime field (in blocks) |
Definition at line 98 of file mphell_tuto_ecdsa.c.
void ecdsa_sign_free | ( | ecdsa_sig * | sig | ) |
Free a used signature structure.
sig | Signature |
size | Size (in block) of the signature |
sig | Signature |
Definition at line 115 of file mphell_tuto_ecdsa.c.
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".
hash | H(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. |
sig | Signature of hash |
pub_key | Public key |
curve | Elliptic curve |
precomp | Precomputation structure, used in the wNAF multiplication point method |
Definition at line 306 of file mphell_tuto_ecdsa.c.