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_ECOSDSA
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 "ECOSDSA"
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 */
ecosdsa_init_pub_key(ec_pub_key * out_pub,const ec_priv_key * in_priv)31*f0865ec9SKyle Evans int ecosdsa_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, ECOSDSA);
34*f0865ec9SKyle Evans }
35*f0865ec9SKyle Evans
36*f0865ec9SKyle Evans /*
37*f0865ec9SKyle Evans * Helper providing ECOSDSA 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 */
ecosdsa_siglen(u16 p_bit_len,u16 q_bit_len,u8 hsize,u8 blocksize,u8 * siglen)43*f0865ec9SKyle Evans int ecosdsa_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 * ECOSDSA signature initialization function. Returns 0 on success, -1 on
51*f0865ec9SKyle Evans * error.
52*f0865ec9SKyle Evans */
_ecosdsa_sign_init(struct ec_sign_context * ctx)53*f0865ec9SKyle Evans int _ecosdsa_sign_init(struct ec_sign_context *ctx)
54*f0865ec9SKyle Evans {
55*f0865ec9SKyle Evans return __ecsdsa_sign_init(ctx, ECOSDSA, 1);
56*f0865ec9SKyle Evans }
57*f0865ec9SKyle Evans
58*f0865ec9SKyle Evans /* ECOSDSA signature update function. Returns 0 on success, -1 on error. */
_ecosdsa_sign_update(struct ec_sign_context * ctx,const u8 * chunk,u32 chunklen)59*f0865ec9SKyle Evans int _ecosdsa_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 /*
66*f0865ec9SKyle Evans * ECOSDSA signature finalization function. Returns 0 on success, -1 on error.
67*f0865ec9SKyle Evans */
_ecosdsa_sign_finalize(struct ec_sign_context * ctx,u8 * sig,u8 siglen)68*f0865ec9SKyle Evans int _ecosdsa_sign_finalize(struct ec_sign_context *ctx, u8 *sig, u8 siglen)
69*f0865ec9SKyle Evans {
70*f0865ec9SKyle Evans return __ecsdsa_sign_finalize(ctx, sig, siglen);
71*f0865ec9SKyle Evans }
72*f0865ec9SKyle Evans
73*f0865ec9SKyle Evans /* ECOSDSA verify initialization function. Returns 0 on success, -1 on error. */
_ecosdsa_verify_init(struct ec_verify_context * ctx,const u8 * sig,u8 siglen)74*f0865ec9SKyle Evans int _ecosdsa_verify_init(struct ec_verify_context *ctx,
75*f0865ec9SKyle Evans const u8 *sig, u8 siglen)
76*f0865ec9SKyle Evans {
77*f0865ec9SKyle Evans return __ecsdsa_verify_init(ctx, sig, siglen, ECOSDSA, 1);
78*f0865ec9SKyle Evans }
79*f0865ec9SKyle Evans
80*f0865ec9SKyle Evans /* ECOSDSA verify update function. Returns 0 on success, -1 on error. */
_ecosdsa_verify_update(struct ec_verify_context * ctx,const u8 * chunk,u32 chunklen)81*f0865ec9SKyle Evans int _ecosdsa_verify_update(struct ec_verify_context *ctx,
82*f0865ec9SKyle Evans const u8 *chunk, u32 chunklen)
83*f0865ec9SKyle Evans {
84*f0865ec9SKyle Evans return __ecsdsa_verify_update(ctx, chunk, chunklen);
85*f0865ec9SKyle Evans }
86*f0865ec9SKyle Evans
87*f0865ec9SKyle Evans /* ECOSDSA verify finalization function. Returns 0 on success, -1 on error. */
_ecosdsa_verify_finalize(struct ec_verify_context * ctx)88*f0865ec9SKyle Evans int _ecosdsa_verify_finalize(struct ec_verify_context *ctx)
89*f0865ec9SKyle Evans {
90*f0865ec9SKyle Evans return __ecsdsa_verify_finalize(ctx);
91*f0865ec9SKyle Evans }
92*f0865ec9SKyle Evans
93*f0865ec9SKyle Evans #else /* WITH_SIG_ECOSDSA */
94*f0865ec9SKyle Evans
95*f0865ec9SKyle Evans /*
96*f0865ec9SKyle Evans * Dummy definition to avoid the empty translation unit ISO C warning
97*f0865ec9SKyle Evans */
98*f0865ec9SKyle Evans typedef int dummy;
99*f0865ec9SKyle Evans #endif /* WITH_SIG_ECOSDSA */
100