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