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