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 __KCDSA_H__ 12 #define __KCDSA_H__ 13 14 /* 15 * NOTE: although we only need libarith for KCDSA 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 KCDSA. 28 */ 29 30 /* KCDSA public key, composed of: 31 * p the KCDSA prime modulus 32 * q the KCDSA prime order (prime divisor of (p-1)) 33 * g the KCDSA generator 34 * y the public key = g^x (p) 35 * 36 * NOTE: the KCDSA (Schnorr DSA) public key is mapped to a DSA public key 37 * as the parameters are the same. 38 */ 39 typedef dsa_pub_key kcdsa_pub_key; 40 41 /* KCDSA private key, composed of: 42 * p the KCDSA prime modulus 43 * q the KCDSA prime order (prime divisor of (p-1)) 44 * g the KCDSA generator 45 * x the secret key 46 * 47 * NOTE: the KCDSA (Schnorr DSA) private key is mapped to a DSA private key 48 * as the parameters are the same. 49 */ 50 typedef dsa_priv_key kcdsa_priv_key; 51 52 ATTRIBUTE_WARN_UNUSED_RET int kcdsa_import_priv_key(kcdsa_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 kcdsa_import_pub_key(kcdsa_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 kcdsa_compute_pub_from_priv(kcdsa_pub_key *pub, 63 const kcdsa_priv_key *priv); 64 65 ATTRIBUTE_WARN_UNUSED_RET int kcdsa_sign(const kcdsa_priv_key *priv, const u8 *msg, u32 msglen, 66 const u8 *nonce, u16 noncelen, 67 u8 *sig, u16 siglen, gen_hash_alg_type kcdsa_hash); 68 69 ATTRIBUTE_WARN_UNUSED_RET int kcdsa_verify(const kcdsa_pub_key *pub, const u8 *msg, u32 msglen, 70 const u8 *sig, u16 siglen, gen_hash_alg_type kcdsa_hash); 71 72 #endif /* __KCDSA_H__ */ 73