xref: /freebsd/crypto/libecc/src/examples/sig/kcdsa/kcdsa.h (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
1*f0865ec9SKyle Evans /*
2*f0865ec9SKyle Evans  *  Copyright (C) 2021 - This file is part of libecc project
3*f0865ec9SKyle Evans  *
4*f0865ec9SKyle Evans  *  Authors:
5*f0865ec9SKyle Evans  *      Ryad BENADJILA <ryadbenadjila@gmail.com>
6*f0865ec9SKyle Evans  *      Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
7*f0865ec9SKyle Evans  *
8*f0865ec9SKyle Evans  *  This software is licensed under a dual BSD and GPL v2 license.
9*f0865ec9SKyle Evans  *  See LICENSE file at the root folder of the project.
10*f0865ec9SKyle Evans  */
11*f0865ec9SKyle Evans #ifndef __KCDSA_H__
12*f0865ec9SKyle Evans #define __KCDSA_H__
13*f0865ec9SKyle Evans 
14*f0865ec9SKyle Evans /*
15*f0865ec9SKyle Evans  * NOTE: although we only need libarith for KCDSA as we
16*f0865ec9SKyle Evans  * manipulate a ring of integers, we include libsig for
17*f0865ec9SKyle Evans  * the hash algorithms.
18*f0865ec9SKyle Evans  */
19*f0865ec9SKyle Evans #include <libecc/lib_ecc_config.h>
20*f0865ec9SKyle Evans 
21*f0865ec9SKyle Evans /* The hash algorithms wrapper */
22*f0865ec9SKyle Evans #include "../../hash/hash.h"
23*f0865ec9SKyle Evans 
24*f0865ec9SKyle Evans /* The DSA include file as we reuse DSA primitives internally */
25*f0865ec9SKyle Evans #include "../dsa/dsa.h"
26*f0865ec9SKyle Evans 
27*f0865ec9SKyle Evans /* We define hereafter the types and functions for KCDSA.
28*f0865ec9SKyle Evans  */
29*f0865ec9SKyle Evans 
30*f0865ec9SKyle Evans /* KCDSA public key, composed of:
31*f0865ec9SKyle Evans  *       p        the KCDSA prime modulus
32*f0865ec9SKyle Evans  *       q        the KCDSA prime order (prime divisor of (p-1))
33*f0865ec9SKyle Evans  *       g        the KCDSA generator
34*f0865ec9SKyle Evans  *       y        the public key = g^x (p)
35*f0865ec9SKyle Evans  *
36*f0865ec9SKyle Evans  * NOTE: the KCDSA (Schnorr DSA) public key is mapped to a DSA public key
37*f0865ec9SKyle Evans  * as the parameters are the same.
38*f0865ec9SKyle Evans  */
39*f0865ec9SKyle Evans typedef dsa_pub_key kcdsa_pub_key;
40*f0865ec9SKyle Evans 
41*f0865ec9SKyle Evans /* KCDSA private key, composed of:
42*f0865ec9SKyle Evans  *       p        the KCDSA prime modulus
43*f0865ec9SKyle Evans  *       q        the KCDSA prime order (prime divisor of (p-1))
44*f0865ec9SKyle Evans  *       g        the KCDSA generator
45*f0865ec9SKyle Evans  *       x        the secret key
46*f0865ec9SKyle Evans  *
47*f0865ec9SKyle Evans  * NOTE: the KCDSA (Schnorr DSA) private key is mapped to a DSA private key
48*f0865ec9SKyle Evans  * as the parameters are the same.
49*f0865ec9SKyle Evans  */
50*f0865ec9SKyle Evans typedef dsa_priv_key kcdsa_priv_key;
51*f0865ec9SKyle Evans 
52*f0865ec9SKyle Evans ATTRIBUTE_WARN_UNUSED_RET int kcdsa_import_priv_key(kcdsa_priv_key *priv, const u8 *p, u16 plen,
53*f0865ec9SKyle Evans 			                          const u8 *q, u16 qlen,
54*f0865ec9SKyle Evans 			                          const u8 *g, u16 glen,
55*f0865ec9SKyle Evans 			                          const u8 *x, u16 xlen);
56*f0865ec9SKyle Evans 
57*f0865ec9SKyle Evans ATTRIBUTE_WARN_UNUSED_RET int kcdsa_import_pub_key(kcdsa_pub_key *pub, const u8 *p, u16 plen,
58*f0865ec9SKyle Evans 			                         const u8 *q, u16 qlen,
59*f0865ec9SKyle Evans 			                         const u8 *g, u16 glen,
60*f0865ec9SKyle Evans 			                         const u8 *y, u16 ylen);
61*f0865ec9SKyle Evans 
62*f0865ec9SKyle Evans ATTRIBUTE_WARN_UNUSED_RET int kcdsa_compute_pub_from_priv(kcdsa_pub_key *pub,
63*f0865ec9SKyle Evans 							const kcdsa_priv_key *priv);
64*f0865ec9SKyle Evans 
65*f0865ec9SKyle Evans ATTRIBUTE_WARN_UNUSED_RET int kcdsa_sign(const kcdsa_priv_key *priv, const u8 *msg, u32 msglen,
66*f0865ec9SKyle Evans 			               const u8 *nonce, u16 noncelen,
67*f0865ec9SKyle Evans 			               u8 *sig, u16 siglen, gen_hash_alg_type kcdsa_hash);
68*f0865ec9SKyle Evans 
69*f0865ec9SKyle Evans ATTRIBUTE_WARN_UNUSED_RET int kcdsa_verify(const kcdsa_pub_key *pub, const u8 *msg, u32 msglen,
70*f0865ec9SKyle Evans 			                 const u8 *sig, u16 siglen, gen_hash_alg_type kcdsa_hash);
71*f0865ec9SKyle Evans 
72*f0865ec9SKyle Evans #endif /* __KCDSA_H__ */
73