xref: /freebsd/crypto/libecc/src/sig/ecsdsa.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_ECSDSA
18*f0865ec9SKyle Evans 
19*f0865ec9SKyle Evans #include <libecc/sig/ecsdsa_common.h>
20*f0865ec9SKyle Evans #include <libecc/sig/sig_algs_internal.h>
21*f0865ec9SKyle Evans #include <libecc/sig/ec_key.h>
22*f0865ec9SKyle Evans #ifdef VERBOSE_INNER_VALUES
23*f0865ec9SKyle Evans #define EC_SIG_ALG "ECSDSA"
24*f0865ec9SKyle Evans #endif
25*f0865ec9SKyle Evans #include <libecc/utils/dbg_sig.h>
26*f0865ec9SKyle Evans 
27*f0865ec9SKyle Evans /*
28*f0865ec9SKyle Evans  * Initialize public key 'out_pub' from input private key 'in_priv'. The
29*f0865ec9SKyle Evans  * function returns 0 on success, -1 on error.
30*f0865ec9SKyle Evans  */
ecsdsa_init_pub_key(ec_pub_key * out_pub,const ec_priv_key * in_priv)31*f0865ec9SKyle Evans int ecsdsa_init_pub_key(ec_pub_key *out_pub, const ec_priv_key *in_priv)
32*f0865ec9SKyle Evans {
33*f0865ec9SKyle Evans 	return __ecsdsa_init_pub_key(out_pub, in_priv, ECSDSA);
34*f0865ec9SKyle Evans }
35*f0865ec9SKyle Evans 
36*f0865ec9SKyle Evans /*
37*f0865ec9SKyle Evans  * Helper providing ECSDSA signature length when exported to a buffer based on
38*f0865ec9SKyle Evans  * hash algorithm digest and block size, generator point order bit length, and
39*f0865ec9SKyle Evans  * underlying prime field order bit length. The function returns 0 on success,
40*f0865ec9SKyle Evans  * -1 on error. On success, signature length is provided via 'siglen' out
41*f0865ec9SKyle Evans  * parameter.
42*f0865ec9SKyle Evans  */
ecsdsa_siglen(u16 p_bit_len,u16 q_bit_len,u8 hsize,u8 blocksize,u8 * siglen)43*f0865ec9SKyle Evans int ecsdsa_siglen(u16 p_bit_len, u16 q_bit_len, u8 hsize, u8 blocksize,
44*f0865ec9SKyle Evans 		  u8 *siglen)
45*f0865ec9SKyle Evans {
46*f0865ec9SKyle Evans 	return __ecsdsa_siglen(p_bit_len, q_bit_len, hsize, blocksize, siglen);
47*f0865ec9SKyle Evans }
48*f0865ec9SKyle Evans 
49*f0865ec9SKyle Evans /*
50*f0865ec9SKyle Evans  * ECSDSA signature initialization function. Returns 0 on success, -1 on
51*f0865ec9SKyle Evans  * error.
52*f0865ec9SKyle Evans  */
_ecsdsa_sign_init(struct ec_sign_context * ctx)53*f0865ec9SKyle Evans int _ecsdsa_sign_init(struct ec_sign_context *ctx)
54*f0865ec9SKyle Evans {
55*f0865ec9SKyle Evans 	return __ecsdsa_sign_init(ctx, ECSDSA, 0);
56*f0865ec9SKyle Evans }
57*f0865ec9SKyle Evans 
58*f0865ec9SKyle Evans /* ECSDSA signature update function. Returns 0 on success, -1 on error. */
_ecsdsa_sign_update(struct ec_sign_context * ctx,const u8 * chunk,u32 chunklen)59*f0865ec9SKyle Evans int _ecsdsa_sign_update(struct ec_sign_context *ctx,
60*f0865ec9SKyle Evans 			const u8 *chunk, u32 chunklen)
61*f0865ec9SKyle Evans {
62*f0865ec9SKyle Evans 	return __ecsdsa_sign_update(ctx, chunk, chunklen);
63*f0865ec9SKyle Evans }
64*f0865ec9SKyle Evans 
65*f0865ec9SKyle Evans /* ECSDSA signature finalization function. Returns 0 on success, -1 on error. */
_ecsdsa_sign_finalize(struct ec_sign_context * ctx,u8 * sig,u8 siglen)66*f0865ec9SKyle Evans int _ecsdsa_sign_finalize(struct ec_sign_context *ctx, u8 *sig, u8 siglen)
67*f0865ec9SKyle Evans {
68*f0865ec9SKyle Evans 	return __ecsdsa_sign_finalize(ctx, sig, siglen);
69*f0865ec9SKyle Evans }
70*f0865ec9SKyle Evans 
71*f0865ec9SKyle Evans /* ECSDSA verify initialization function. Returns 0 on success, -1 on error. */
_ecsdsa_verify_init(struct ec_verify_context * ctx,const u8 * sig,u8 siglen)72*f0865ec9SKyle Evans int _ecsdsa_verify_init(struct ec_verify_context *ctx,
73*f0865ec9SKyle Evans 			const u8 *sig, u8 siglen)
74*f0865ec9SKyle Evans {
75*f0865ec9SKyle Evans 	return __ecsdsa_verify_init(ctx, sig, siglen, ECSDSA, 0);
76*f0865ec9SKyle Evans }
77*f0865ec9SKyle Evans 
78*f0865ec9SKyle Evans /* ECSDSA verify update function. Returns 0 on success, -1 on error. */
_ecsdsa_verify_update(struct ec_verify_context * ctx,const u8 * chunk,u32 chunklen)79*f0865ec9SKyle Evans int _ecsdsa_verify_update(struct ec_verify_context *ctx,
80*f0865ec9SKyle Evans 			  const u8 *chunk, u32 chunklen)
81*f0865ec9SKyle Evans {
82*f0865ec9SKyle Evans 	return __ecsdsa_verify_update(ctx, chunk, chunklen);
83*f0865ec9SKyle Evans }
84*f0865ec9SKyle Evans 
85*f0865ec9SKyle Evans /* ECSDSA verify finalize function. Returns 0 on success, -1 on error. */
_ecsdsa_verify_finalize(struct ec_verify_context * ctx)86*f0865ec9SKyle Evans int _ecsdsa_verify_finalize(struct ec_verify_context *ctx)
87*f0865ec9SKyle Evans {
88*f0865ec9SKyle Evans 	return __ecsdsa_verify_finalize(ctx);
89*f0865ec9SKyle Evans }
90*f0865ec9SKyle Evans 
91*f0865ec9SKyle Evans #else /* WITH_SIG_ECSDSA */
92*f0865ec9SKyle Evans 
93*f0865ec9SKyle Evans /*
94*f0865ec9SKyle Evans  * Dummy definition to avoid the empty translation unit ISO C warning
95*f0865ec9SKyle Evans  */
96*f0865ec9SKyle Evans typedef int dummy;
97*f0865ec9SKyle Evans #endif /* WITH_SIG_ECSDSA */
98