Coverage Report

Created: 2025-04-11 06:45

/src/libecc/src/sig/ecsdsa.c
Line
Count
Source (jump to first uncovered line)
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
 */
31
int ecsdsa_init_pub_key(ec_pub_key *out_pub, const ec_priv_key *in_priv)
32
0
{
33
0
  return __ecsdsa_init_pub_key(out_pub, in_priv, ECSDSA);
34
0
}
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
 */
43
int ecsdsa_siglen(u16 p_bit_len, u16 q_bit_len, u8 hsize, u8 blocksize,
44
      u8 *siglen)
45
0
{
46
0
  return __ecsdsa_siglen(p_bit_len, q_bit_len, hsize, blocksize, siglen);
47
0
}
48
49
/*
50
 * ECSDSA signature initialization function. Returns 0 on success, -1 on
51
 * error.
52
 */
53
int _ecsdsa_sign_init(struct ec_sign_context *ctx)
54
0
{
55
0
  return __ecsdsa_sign_init(ctx, ECSDSA, 0);
56
0
}
57
58
/* ECSDSA signature update function. Returns 0 on success, -1 on error. */
59
int _ecsdsa_sign_update(struct ec_sign_context *ctx,
60
      const u8 *chunk, u32 chunklen)
61
0
{
62
0
  return __ecsdsa_sign_update(ctx, chunk, chunklen);
63
0
}
64
65
/* ECSDSA signature finalization function. Returns 0 on success, -1 on error. */
66
int _ecsdsa_sign_finalize(struct ec_sign_context *ctx, u8 *sig, u8 siglen)
67
0
{
68
0
  return __ecsdsa_sign_finalize(ctx, sig, siglen);
69
0
}
70
71
/* ECSDSA verify initialization function. Returns 0 on success, -1 on error. */
72
int _ecsdsa_verify_init(struct ec_verify_context *ctx,
73
      const u8 *sig, u8 siglen)
74
0
{
75
0
  return __ecsdsa_verify_init(ctx, sig, siglen, ECSDSA, 0);
76
0
}
77
78
/* ECSDSA verify update function. Returns 0 on success, -1 on error. */
79
int _ecsdsa_verify_update(struct ec_verify_context *ctx,
80
        const u8 *chunk, u32 chunklen)
81
0
{
82
0
  return __ecsdsa_verify_update(ctx, chunk, chunklen);
83
0
}
84
85
/* ECSDSA verify finalize function. Returns 0 on success, -1 on error. */
86
int _ecsdsa_verify_finalize(struct ec_verify_context *ctx)
87
0
{
88
0
  return __ecsdsa_verify_finalize(ctx);
89
0
}
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 */