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_ECKCDSA 19 20 #ifndef __ECKCDSA_H__ 21 #define __ECKCDSA_H__ 22 #include <libecc/words/words.h> 23 #include <libecc/sig/ec_key.h> 24 #include <libecc/utils/utils.h> 25 #include <libecc/hash/hash_algs.h> 26 #include <libecc/curves/curves.h> 27 28 #define ECKCDSA_R_LEN(hsize, q_bit_len) LOCAL_MIN(hsize, BYTECEIL(q_bit_len)) 29 #define ECKCDSA_S_LEN(q_bit_len) (BYTECEIL(q_bit_len)) 30 #define ECKCDSA_SIGLEN(hsize, q_bit_len) (ECKCDSA_R_LEN(hsize, q_bit_len) + \ 31 ECKCDSA_S_LEN(q_bit_len)) 32 #define ECKCDSA_MAX_SIGLEN ECKCDSA_SIGLEN(MAX_DIGEST_SIZE, CURVES_MAX_Q_BIT_LEN) 33 34 /* 35 * Compute max signature length for all the mechanisms enabled 36 * in the library (see lib_ecc_config.h). Having that done during 37 * preprocessing sadly requires some verbosity. 38 */ 39 #ifndef EC_MAX_SIGLEN 40 #define EC_MAX_SIGLEN 0 41 #endif 42 #if ((EC_MAX_SIGLEN) < (ECKCDSA_MAX_SIGLEN)) 43 #undef EC_MAX_SIGLEN 44 #define EC_MAX_SIGLEN ECKCDSA_MAX_SIGLEN 45 #endif 46 47 ATTRIBUTE_WARN_UNUSED_RET int eckcdsa_init_pub_key(ec_pub_key *out_pub, const ec_priv_key *in_priv); 48 49 ATTRIBUTE_WARN_UNUSED_RET int eckcdsa_siglen(u16 p_bit_len, u16 q_bit_len, u8 hsize, u8 blocksize, 50 u8 *siglen); 51 52 typedef struct { 53 hash_context h_ctx; 54 word_t magic; 55 } eckcdsa_sign_data; 56 57 struct ec_sign_context; 58 59 ATTRIBUTE_WARN_UNUSED_RET int _eckcdsa_sign_init(struct ec_sign_context *ctx); 60 61 ATTRIBUTE_WARN_UNUSED_RET int _eckcdsa_sign_update(struct ec_sign_context *ctx, 62 const u8 *chunk, u32 chunklen); 63 64 ATTRIBUTE_WARN_UNUSED_RET int _eckcdsa_sign_finalize(struct ec_sign_context *ctx, u8 *sig, u8 siglen); 65 66 typedef struct { 67 hash_context h_ctx; 68 u8 r[MAX_DIGEST_SIZE]; 69 nn s; 70 word_t magic; 71 } eckcdsa_verify_data; 72 73 struct ec_verify_context; 74 75 ATTRIBUTE_WARN_UNUSED_RET int _eckcdsa_verify_init(struct ec_verify_context *ctx, 76 const u8 *sig, u8 siglen); 77 78 ATTRIBUTE_WARN_UNUSED_RET int _eckcdsa_verify_update(struct ec_verify_context *ctx, 79 const u8 *chunk, u32 chunklen); 80 81 ATTRIBUTE_WARN_UNUSED_RET int _eckcdsa_verify_finalize(struct ec_verify_context *ctx); 82 83 #endif /* __ECKCDSA_H__ */ 84 #endif /* WITH_SIG_ECKCDSA */ 85