Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/libecc/src/sig/dbign.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_DBIGN
18
19
#if !defined(WITH_HMAC)
20
#error "DBIGN signature needs HMAC, please activate it!"
21
#endif
22
#include <libecc/hash/hmac.h>
23
24
#include <libecc/nn/nn_rand.h>
25
#include <libecc/nn/nn_mul_public.h>
26
#include <libecc/nn/nn_logical.h>
27
28
#include <libecc/sig/sig_algs_internal.h>
29
#include <libecc/sig/ec_key.h>
30
#include <libecc/utils/utils.h>
31
#ifdef VERBOSE_INNER_VALUES
32
#define EC_SIG_ALG "DBIGN"
33
#endif
34
#include <libecc/utils/dbg_sig.h>
35
36
int dbign_init_pub_key(ec_pub_key *out_pub, const ec_priv_key *in_priv)
37
{
38
return __bign_init_pub_key(out_pub, in_priv, DBIGN);
39
}
40
41
int dbign_siglen(u16 p_bit_len, u16 q_bit_len, u8 hsize, u8 blocksize, u8 *siglen)
42
{
43
return __bign_siglen(p_bit_len, q_bit_len, hsize, blocksize, siglen);
44
}
45
46
int _dbign_sign_init(struct ec_sign_context *ctx)
47
{
48
int ret;
49
50
/* Override our random source with NULL since we want a deterministic
51
* generation.
52
*/
53
MUST_HAVE((ctx != NULL), ret, err);
54
55
ctx->rand = NULL;
56
ret = __bign_sign_init(ctx, DBIGN);
57
58
err:
59
return ret;
60
}
61
62
int _dbign_sign_update(struct ec_sign_context *ctx,
63
const u8 *chunk, u32 chunklen)
64
{
65
int ret;
66
67
/* NOTE: for deterministic ECDSA, the random source MUST be NULL, hence
68
* the following check.
69
*/
70
MUST_HAVE((ctx != NULL) && (ctx->rand == NULL), ret, err);
71
72
ret = __bign_sign_update(ctx, chunk, chunklen, DBIGN);
73
74
err:
75
return ret;
76
}
77
78
int _dbign_sign_finalize(struct ec_sign_context *ctx, u8 *sig, u8 siglen)
79
{
80
int ret;
81
82
/* NOTE: for deterministic ECDSA, the random source MUST be NULL, hence
83
* the following check.
84
*/
85
MUST_HAVE((ctx != NULL) && (ctx->rand == NULL), ret, err);
86
87
ret = __bign_sign_finalize(ctx, sig, siglen, DBIGN);
88
89
err:
90
return ret;
91
}
92
93
int _dbign_verify_init(struct ec_verify_context *ctx, const u8 *sig, u8 siglen)
94
{
95
return __bign_verify_init(ctx, sig, siglen, DBIGN);
96
}
97
98
int _dbign_verify_update(struct ec_verify_context *ctx,
99
const u8 *chunk, u32 chunklen)
100
{
101
return __bign_verify_update(ctx, chunk, chunklen, DBIGN);
102
}
103
104
int _dbign_verify_finalize(struct ec_verify_context *ctx)
105
{
106
return __bign_verify_finalize(ctx, DBIGN);
107
}
108
109
#else /* WITH_SIG_DBIGN */
110
111
/*
112
* Dummy definition to avoid the empty translation unit ISO C warning
113
*/
114
typedef int dummy;
115
#endif /* WITH_SIG_DBIGN */
116
117