Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/libecc/src/sig/ecosdsa.c
2066 views
1
/*
2
* Copyright (C) 2017 - This file is part of libecc project
3
*
4
* Authors:
5
* Ryad BENADJILA <[email protected]>
6
* Arnaud EBALARD <[email protected]>
7
* Jean-Pierre FLORI <[email protected]>
8
*
9
* Contributors:
10
* Nicolas VIVET <[email protected]>
11
* Karim KHALFALLAH <[email protected]>
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_ECOSDSA
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 "ECOSDSA"
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 ecosdsa_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, ECOSDSA);
34
}
35
36
/*
37
* Helper providing ECOSDSA 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 ecosdsa_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
* ECOSDSA signature initialization function. Returns 0 on success, -1 on
51
* error.
52
*/
53
int _ecosdsa_sign_init(struct ec_sign_context *ctx)
54
{
55
return __ecsdsa_sign_init(ctx, ECOSDSA, 1);
56
}
57
58
/* ECOSDSA signature update function. Returns 0 on success, -1 on error. */
59
int _ecosdsa_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
/*
66
* ECOSDSA signature finalization function. Returns 0 on success, -1 on error.
67
*/
68
int _ecosdsa_sign_finalize(struct ec_sign_context *ctx, u8 *sig, u8 siglen)
69
{
70
return __ecsdsa_sign_finalize(ctx, sig, siglen);
71
}
72
73
/* ECOSDSA verify initialization function. Returns 0 on success, -1 on error. */
74
int _ecosdsa_verify_init(struct ec_verify_context *ctx,
75
const u8 *sig, u8 siglen)
76
{
77
return __ecsdsa_verify_init(ctx, sig, siglen, ECOSDSA, 1);
78
}
79
80
/* ECOSDSA verify update function. Returns 0 on success, -1 on error. */
81
int _ecosdsa_verify_update(struct ec_verify_context *ctx,
82
const u8 *chunk, u32 chunklen)
83
{
84
return __ecsdsa_verify_update(ctx, chunk, chunklen);
85
}
86
87
/* ECOSDSA verify finalization function. Returns 0 on success, -1 on error. */
88
int _ecosdsa_verify_finalize(struct ec_verify_context *ctx)
89
{
90
return __ecsdsa_verify_finalize(ctx);
91
}
92
93
#else /* WITH_SIG_ECOSDSA */
94
95
/*
96
* Dummy definition to avoid the empty translation unit ISO C warning
97
*/
98
typedef int dummy;
99
#endif /* WITH_SIG_ECOSDSA */
100
101