xref: /freebsd/crypto/libecc/include/libecc/sig/ecrdsa.h (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
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 #include <libecc/lib_ecc_types.h>
18 #ifdef WITH_SIG_ECRDSA
19 
20 #ifndef __ECRDSA_H__
21 #define __ECRDSA_H__
22 
23 #include <libecc/words/words.h>
24 #include <libecc/sig/ec_key.h>
25 #include <libecc/hash/hash_algs.h>
26 #include <libecc/curves/curves.h>
27 #include <libecc/utils/utils.h>
28 
29 #define ECRDSA_R_LEN(q_bit_len)  (BYTECEIL(q_bit_len))
30 #define ECRDSA_S_LEN(q_bit_len)  (BYTECEIL(q_bit_len))
31 #define ECRDSA_SIGLEN(q_bit_len) (ECRDSA_R_LEN(q_bit_len) + \
32 				  ECRDSA_S_LEN(q_bit_len))
33 #define ECRDSA_MAX_SIGLEN ECRDSA_SIGLEN(CURVES_MAX_Q_BIT_LEN)
34 
35 /*
36  * Compute max signature length for all the mechanisms enabled
37  * in the library (see lib_ecc_config.h). Having that done during
38  * preprocessing sadly requires some verbosity.
39  */
40 #ifndef EC_MAX_SIGLEN
41 #define EC_MAX_SIGLEN 0
42 #endif
43 #if ((EC_MAX_SIGLEN) < (ECRDSA_MAX_SIGLEN))
44 #undef EC_MAX_SIGLEN
45 #define EC_MAX_SIGLEN ECRDSA_MAX_SIGLEN
46 #endif
47 
48 ATTRIBUTE_WARN_UNUSED_RET int ecrdsa_init_pub_key(ec_pub_key *out_pub, const ec_priv_key *in_priv);
49 
50 ATTRIBUTE_WARN_UNUSED_RET int ecrdsa_siglen(u16 p_bit_len, u16 q_bit_len, u8 hsize, u8 blocksize,
51 		  u8 *siglen);
52 
53 typedef struct {
54 	hash_context h_ctx;
55 	word_t magic;
56 } ecrdsa_sign_data;
57 
58 struct ec_sign_context;
59 
60 ATTRIBUTE_WARN_UNUSED_RET int _ecrdsa_sign_init(struct ec_sign_context *ctx);
61 
62 ATTRIBUTE_WARN_UNUSED_RET int _ecrdsa_sign_update(struct ec_sign_context *ctx,
63 			const u8 *chunk, u32 chunklen);
64 
65 ATTRIBUTE_WARN_UNUSED_RET int _ecrdsa_sign_finalize(struct ec_sign_context *ctx, u8 *sig, u8 siglen);
66 
67 typedef struct {
68 	hash_context h_ctx;
69 	nn r;
70 	nn s;
71 	word_t magic;
72 } ecrdsa_verify_data;
73 
74 struct ec_verify_context;
75 
76 ATTRIBUTE_WARN_UNUSED_RET int _ecrdsa_verify_init(struct ec_verify_context *ctx,
77 			const u8 *sig, u8 siglen);
78 
79 ATTRIBUTE_WARN_UNUSED_RET int _ecrdsa_verify_update(struct ec_verify_context *ctx,
80 			  const u8 *chunk, u32 chunklen);
81 
82 ATTRIBUTE_WARN_UNUSED_RET int _ecrdsa_verify_finalize(struct ec_verify_context *ctx);
83 
84 #endif /* __ECRDSA_H__ */
85 #endif /* WITH_SIG_ECRDSA */
86