forked from ANSSI-FR/libecc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sig_algs.h
89 lines (70 loc) · 3.4 KB
/
sig_algs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright (C) 2017 - This file is part of libecc project
*
* Authors:
* Ryad BENADJILA <[email protected]>
* Arnaud EBALARD <[email protected]>
* Jean-Pierre FLORI <[email protected]>
*
* Contributors:
* Nicolas VIVET <[email protected]>
* Karim KHALFALLAH <[email protected]>
*
* This software is licensed under a dual BSD and GPL v2 license.
* See LICENSE file at the root folder of the project.
*/
#ifndef __SIG_ALGS_H__
#define __SIG_ALGS_H__
#include "sig_algs_internal.h"
/*
* Generic function to init a uninitialized public key from an initialized
* private key. The function uses the expected logic to derive the key
* (e.g. Y=xG, Y=(x^-1)G, etc). It returns -1 on error (i.e. if the signature
* alg is unknown) in which case the public key has not been initialized.
*/
int init_pubkey_from_privkey(ec_pub_key *pub_key, ec_priv_key *priv_key);
const ec_sig_mapping *get_sig_by_name(const char *ec_sig_name);
const ec_sig_mapping *get_sig_by_type(ec_sig_alg_type sig_type);
/* Sanity checks for calbacks */
int ec_sig_mapping_callbacks_sanity_check(const ec_sig_mapping *sig);
int ec_sig_ctx_callbacks_sanity_check(const struct ec_sign_context *sig_ctx);
int ec_verify_ctx_callbacks_sanity_check(const struct ec_verify_context *verify_ctx);
/*
* Compute generic effective signature length depending on the curve parameters,
* the signature algorithm and the hash function
*/
int ec_get_sig_len(const ec_params *params, ec_sig_alg_type sig_type,
hash_alg_type hash_type, u8 *siglen);
/* Generic signature */
int ec_sign_init(struct ec_sign_context *ctx, const ec_key_pair *key_pair,
ec_sig_alg_type sig_type, hash_alg_type hash_type);
int ec_sign_update(struct ec_sign_context *ctx, const u8 *chunk, u32 chunklen);
int ec_sign_finalize(struct ec_sign_context *ctx, u8 *sig, u8 siglen);
int _ec_sign(u8 *sig, u8 siglen, const ec_key_pair *key_pair,
const u8 *m, u32 mlen, int (*rand) (nn_t out, nn_src_t q),
ec_sig_alg_type sig_type, hash_alg_type hash_type);
int ec_sign(u8 *sig, u8 siglen, const ec_key_pair *key_pair,
const u8 *m, u32 mlen, ec_sig_alg_type sig_type,
hash_alg_type hash_type);
/* Generic signature verification */
int ec_verify_init(struct ec_verify_context *ctx, const ec_pub_key *pub_key,
const u8 *sig, u8 siglen, ec_sig_alg_type sig_type,
hash_alg_type hash_type);
int ec_verify_update(struct ec_verify_context *ctx,
const u8 *chunk, u32 chunklen);
int ec_verify_finalize(struct ec_verify_context *ctx);
int ec_verify(const u8 *sig, u8 siglen, const ec_pub_key *pub_key,
const u8 *m, u32 mlen, ec_sig_alg_type sig_type,
hash_alg_type hash_type);
int ec_structured_sig_import_from_buf(u8 *sig, u32 siglen,
const u8 *out_buf, u32 outlen,
ec_sig_alg_type * sig_type,
hash_alg_type * hash_type,
u8 curve_name[MAX_CURVE_NAME_LEN]);
int ec_structured_sig_export_to_buf(const u8 *sig, u32 siglen,
u8 *out_buf, u32 outlen,
ec_sig_alg_type sig_type,
hash_alg_type hash_type,
const u8
curve_name[MAX_CURVE_NAME_LEN]);
#endif /* __SIG_ALGS_H__ */