xref: /freebsd/crypto/libecc/src/examples/sig/gostr34_10_94/gostr34_10_94.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 __GOSTR34_10_94_H__
12 #define __GOSTR34_10_94_H__
13 
14 /*
15  * NOTE: although we only need libarith for GOSTR34_10_94 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 GOSTR34_10_94.
28  */
29 
30 /* GOSTR34_10_94 public key, composed of:
31  *       p        the GOSTR34_10_94 prime modulus
32  *       q        the GOSTR34_10_94 prime order (prime divisor of (p-1))
33  *       g        the GOSTR34_10_94 generator
34  *       y        the public key = g^x (p)
35  *
36  * NOTE: the GOST public key is mapped to a DSA public key
37  * as the parameters are the same.
38  */
39 typedef dsa_pub_key gostr34_10_94_pub_key;
40 
41 /* GOSTR34_10_94 private key, composed of:
42  *       p        the GOSTR34_10_94 prime modulus
43  *       q        the GOSTR34_10_94 prime order (prime divisor of (p-1))
44  *       g        the GOSTR34_10_94 generator
45  *       x        the secret key
46  *
47  * NOTE: the GOST private key is mapped to a DSA private key
48  * as the parameters are the same.
49  */
50 typedef dsa_priv_key gostr34_10_94_priv_key;
51 
52 ATTRIBUTE_WARN_UNUSED_RET int gostr34_10_94_import_priv_key(gostr34_10_94_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 gostr34_10_94_import_pub_key(gostr34_10_94_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 gostr34_10_94_compute_pub_from_priv(gostr34_10_94_pub_key *pub,
63 							const gostr34_10_94_priv_key *priv);
64 
65 ATTRIBUTE_WARN_UNUSED_RET int gostr34_10_94_sign(const gostr34_10_94_priv_key *priv, const u8 *msg, u32 msglen,
66 			               const u8 *nonce, u16 noncelen,
67 			               u8 *sig, u16 siglen, gen_hash_alg_type gostr34_10_94_hash);
68 
69 ATTRIBUTE_WARN_UNUSED_RET int gostr34_10_94_verify(const gostr34_10_94_pub_key *pub, const u8 *msg, u32 msglen,
70 			                 const u8 *sig, u16 siglen, gen_hash_alg_type gostr34_10_94_hash);
71 
72 #endif /* __GOSTR34_10_94_H__ */
73