xref: /freebsd/crypto/libecc/src/sig/ecdsa.c (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
1*f0865ec9SKyle Evans /*
2*f0865ec9SKyle Evans  *  Copyright (C) 2017 - This file is part of libecc project
3*f0865ec9SKyle Evans  *
4*f0865ec9SKyle Evans  *  Authors:
5*f0865ec9SKyle Evans  *      Ryad BENADJILA <ryadbenadjila@gmail.com>
6*f0865ec9SKyle Evans  *      Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
7*f0865ec9SKyle Evans  *      Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr>
8*f0865ec9SKyle Evans  *
9*f0865ec9SKyle Evans  *  Contributors:
10*f0865ec9SKyle Evans  *      Nicolas VIVET <nicolas.vivet@ssi.gouv.fr>
11*f0865ec9SKyle Evans  *      Karim KHALFALLAH <karim.khalfallah@ssi.gouv.fr>
12*f0865ec9SKyle Evans  *
13*f0865ec9SKyle Evans  *  This software is licensed under a dual BSD and GPL v2 license.
14*f0865ec9SKyle Evans  *  See LICENSE file at the root folder of the project.
15*f0865ec9SKyle Evans  */
16*f0865ec9SKyle Evans #include <libecc/lib_ecc_config.h>
17*f0865ec9SKyle Evans #ifdef WITH_SIG_ECDSA
18*f0865ec9SKyle Evans 
19*f0865ec9SKyle Evans #include <libecc/nn/nn_rand.h>
20*f0865ec9SKyle Evans #include <libecc/nn/nn_mul_public.h>
21*f0865ec9SKyle Evans #include <libecc/nn/nn_logical.h>
22*f0865ec9SKyle Evans 
23*f0865ec9SKyle Evans #include <libecc/sig/sig_algs_internal.h>
24*f0865ec9SKyle Evans #include <libecc/sig/ec_key.h>
25*f0865ec9SKyle Evans #include <libecc/utils/utils.h>
26*f0865ec9SKyle Evans #ifdef VERBOSE_INNER_VALUES
27*f0865ec9SKyle Evans #define EC_SIG_ALG "ECDSA"
28*f0865ec9SKyle Evans #endif
29*f0865ec9SKyle Evans #include <libecc/utils/dbg_sig.h>
30*f0865ec9SKyle Evans 
ecdsa_init_pub_key(ec_pub_key * out_pub,const ec_priv_key * in_priv)31*f0865ec9SKyle Evans int ecdsa_init_pub_key(ec_pub_key *out_pub, const ec_priv_key *in_priv)
32*f0865ec9SKyle Evans {
33*f0865ec9SKyle Evans 	return __ecdsa_init_pub_key(out_pub, in_priv, ECDSA);
34*f0865ec9SKyle Evans }
35*f0865ec9SKyle Evans 
ecdsa_siglen(u16 p_bit_len,u16 q_bit_len,u8 hsize,u8 blocksize,u8 * siglen)36*f0865ec9SKyle Evans int ecdsa_siglen(u16 p_bit_len, u16 q_bit_len, u8 hsize, u8 blocksize, u8 *siglen)
37*f0865ec9SKyle Evans {
38*f0865ec9SKyle Evans 	return __ecdsa_siglen(p_bit_len, q_bit_len, hsize, blocksize, siglen);
39*f0865ec9SKyle Evans }
40*f0865ec9SKyle Evans 
_ecdsa_sign_init(struct ec_sign_context * ctx)41*f0865ec9SKyle Evans int _ecdsa_sign_init(struct ec_sign_context *ctx)
42*f0865ec9SKyle Evans {
43*f0865ec9SKyle Evans 	return __ecdsa_sign_init(ctx, ECDSA);
44*f0865ec9SKyle Evans }
45*f0865ec9SKyle Evans 
_ecdsa_sign_update(struct ec_sign_context * ctx,const u8 * chunk,u32 chunklen)46*f0865ec9SKyle Evans int _ecdsa_sign_update(struct ec_sign_context *ctx,
47*f0865ec9SKyle Evans 		       const u8 *chunk, u32 chunklen)
48*f0865ec9SKyle Evans {
49*f0865ec9SKyle Evans 	return __ecdsa_sign_update(ctx, chunk, chunklen, ECDSA);
50*f0865ec9SKyle Evans }
51*f0865ec9SKyle Evans 
_ecdsa_sign_finalize(struct ec_sign_context * ctx,u8 * sig,u8 siglen)52*f0865ec9SKyle Evans int _ecdsa_sign_finalize(struct ec_sign_context *ctx, u8 *sig, u8 siglen)
53*f0865ec9SKyle Evans {
54*f0865ec9SKyle Evans 	return __ecdsa_sign_finalize(ctx, sig, siglen, ECDSA);
55*f0865ec9SKyle Evans }
56*f0865ec9SKyle Evans 
_ecdsa_verify_init(struct ec_verify_context * ctx,const u8 * sig,u8 siglen)57*f0865ec9SKyle Evans int _ecdsa_verify_init(struct ec_verify_context *ctx, const u8 *sig, u8 siglen)
58*f0865ec9SKyle Evans {
59*f0865ec9SKyle Evans 	return __ecdsa_verify_init(ctx, sig, siglen, ECDSA);
60*f0865ec9SKyle Evans }
61*f0865ec9SKyle Evans 
_ecdsa_verify_update(struct ec_verify_context * ctx,const u8 * chunk,u32 chunklen)62*f0865ec9SKyle Evans int _ecdsa_verify_update(struct ec_verify_context *ctx,
63*f0865ec9SKyle Evans 			 const u8 *chunk, u32 chunklen)
64*f0865ec9SKyle Evans {
65*f0865ec9SKyle Evans 	return __ecdsa_verify_update(ctx, chunk, chunklen, ECDSA);
66*f0865ec9SKyle Evans }
67*f0865ec9SKyle Evans 
_ecdsa_verify_finalize(struct ec_verify_context * ctx)68*f0865ec9SKyle Evans int _ecdsa_verify_finalize(struct ec_verify_context *ctx)
69*f0865ec9SKyle Evans {
70*f0865ec9SKyle Evans 	return __ecdsa_verify_finalize(ctx, ECDSA);
71*f0865ec9SKyle Evans }
72*f0865ec9SKyle Evans 
ecdsa_public_key_from_sig(ec_pub_key * out_pub1,ec_pub_key * out_pub2,const ec_params * params,const u8 * sig,u8 siglen,const u8 * hash,u8 hsize)73*f0865ec9SKyle Evans int ecdsa_public_key_from_sig(ec_pub_key *out_pub1, ec_pub_key *out_pub2, const ec_params *params,
74*f0865ec9SKyle Evans                               const u8 *sig, u8 siglen, const u8 *hash, u8 hsize)
75*f0865ec9SKyle Evans {
76*f0865ec9SKyle Evans 	return __ecdsa_public_key_from_sig(out_pub1, out_pub2, params, sig, siglen, hash, hsize, ECDSA);
77*f0865ec9SKyle Evans }
78*f0865ec9SKyle Evans 
79*f0865ec9SKyle Evans #else /* WITH_SIG_ECDSA */
80*f0865ec9SKyle Evans 
81*f0865ec9SKyle Evans /*
82*f0865ec9SKyle Evans  * Dummy definition to avoid the empty translation unit ISO C warning
83*f0865ec9SKyle Evans  */
84*f0865ec9SKyle Evans typedef int dummy;
85*f0865ec9SKyle Evans #endif /* WITH_SIG_ECDSA */
86