1 /* 2 * Copyright (C) 2017 - 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 * Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr> 8 * 9 * Contributors: 10 * Nicolas VIVET <nicolas.vivet@ssi.gouv.fr> 11 * Karim KHALFALLAH <karim.khalfallah@ssi.gouv.fr> 12 * 13 * This software is licensed under a dual BSD and GPL v2 license. 14 * See LICENSE file at the root folder of the project. 15 */ 16 #include <libecc/lib_ecc_config.h> 17 #include <libecc/lib_ecc_types.h> 18 #ifdef WITH_SIG_ECOSDSA 19 20 #ifndef __ECOSDSA_H__ 21 #define __ECOSDSA_H__ 22 #include <libecc/sig/ecsdsa.h> 23 #include <libecc/words/words.h> 24 #include <libecc/sig/ec_key.h> 25 #include <libecc/utils/utils.h> 26 #include <libecc/hash/hash_algs.h> 27 #include <libecc/curves/curves.h> 28 29 #define ECOSDSA_R_LEN(hsize) (hsize) 30 #define ECOSDSA_S_LEN(q_bit_len) (BYTECEIL(q_bit_len)) 31 #define ECOSDSA_SIGLEN(hsize, q_bit_len) (ECOSDSA_R_LEN(hsize) + \ 32 ECOSDSA_S_LEN(q_bit_len)) 33 #define ECOSDSA_MAX_SIGLEN ECOSDSA_SIGLEN(MAX_DIGEST_SIZE, CURVES_MAX_Q_BIT_LEN) 34 35 /* 36 * Compute max signature length for all the mechanisms enabled 37 * in the library (see lib_ecc_config.h). Having that done during 38 * preprocessing sadly requires some verbosity. 39 */ 40 #ifndef EC_MAX_SIGLEN 41 #define EC_MAX_SIGLEN 0 42 #endif 43 #if ((EC_MAX_SIGLEN) < (ECOSDSA_MAX_SIGLEN)) 44 #undef EC_MAX_SIGLEN 45 #define EC_MAX_SIGLEN ECOSDSA_MAX_SIGLEN 46 #endif 47 48 ATTRIBUTE_WARN_UNUSED_RET int ecosdsa_init_pub_key(ec_pub_key *out_pub, const ec_priv_key *in_priv); 49 50 ATTRIBUTE_WARN_UNUSED_RET int ecosdsa_siglen(u16 p_bit_len, u16 q_bit_len, u8 hsize, u8 blocksize, 51 u8 *siglen); 52 53 ATTRIBUTE_WARN_UNUSED_RET int _ecosdsa_sign_init(struct ec_sign_context *ctx); 54 55 ATTRIBUTE_WARN_UNUSED_RET int _ecosdsa_sign_update(struct ec_sign_context *ctx, 56 const u8 *chunk, u32 chunklen); 57 58 ATTRIBUTE_WARN_UNUSED_RET int _ecosdsa_sign_finalize(struct ec_sign_context *ctx, u8 *sig, u8 siglen); 59 60 ATTRIBUTE_WARN_UNUSED_RET int _ecosdsa_verify_init(struct ec_verify_context *ctx, 61 const u8 *sig, u8 siglen); 62 63 ATTRIBUTE_WARN_UNUSED_RET int _ecosdsa_verify_update(struct ec_verify_context *ctx, 64 const u8 *chunk, u32 chunklen); 65 66 ATTRIBUTE_WARN_UNUSED_RET int _ecosdsa_verify_finalize(struct ec_verify_context *ctx); 67 68 #endif /* __ECOSDSA_H__ */ 69 #endif /* WITH_SIG_ECOSDSA */ 70