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