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 __DSA_H__ 12 #define __DSA_H__ 13 14 /* 15 * NOTE: although we only need libarith for DSA 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 /* We define hereafter the types and functions for DSA. 25 * The notations are taken from NIST FIPS 186-4 and should be 26 * compliant with it. 27 */ 28 29 /* DSA public key, composed of: 30 * p the DSA prime modulus 31 * q the DSA prime order (prime divisor of (p-1)) 32 * g the DSA generator 33 * y the public key = g^x (p) 34 */ 35 typedef struct { 36 nn p; 37 nn q; 38 nn g; 39 nn y; 40 } dsa_pub_key; 41 42 /* DSA private key, composed of: 43 * p the DSA prime modulus 44 * q the DSA prime order (prime divisor of (p-1)) 45 * g the DSA generator 46 * x the secret key 47 */ 48 typedef struct { 49 nn p; 50 nn q; 51 nn g; 52 nn x; 53 } dsa_priv_key; 54 55 ATTRIBUTE_WARN_UNUSED_RET int dsa_import_priv_key(dsa_priv_key *priv, const u8 *p, u16 plen, 56 const u8 *q, u16 qlen, 57 const u8 *g, u16 glen, 58 const u8 *x, u16 xlen); 59 60 ATTRIBUTE_WARN_UNUSED_RET int dsa_import_pub_key(dsa_pub_key *pub, const u8 *p, u16 plen, 61 const u8 *q, u16 qlen, 62 const u8 *g, u16 glen, 63 const u8 *y, u16 ylen); 64 65 ATTRIBUTE_WARN_UNUSED_RET int dsa_compute_pub_from_priv(dsa_pub_key *pub, 66 const dsa_priv_key *priv); 67 68 ATTRIBUTE_WARN_UNUSED_RET int dsa_sign(const dsa_priv_key *priv, const u8 *msg, u32 msglen, 69 const u8 *nonce, u16 noncelen, 70 u8 *sig, u16 siglen, gen_hash_alg_type dsa_hash); 71 72 ATTRIBUTE_WARN_UNUSED_RET int dsa_verify(const dsa_pub_key *pub, const u8 *msg, u32 msglen, 73 const u8 *sig, u16 siglen, gen_hash_alg_type dsa_hash); 74 75 #endif /* __DSA_H__ */ 76