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_ECFSDSA 19 20 #ifndef __ECFSDSA_H__ 21 #define __ECFSDSA_H__ 22 23 #include <libecc/sig/ec_key.h> 24 #include <libecc/hash/hash_algs.h> 25 #include <libecc/curves/curves.h> 26 #include <libecc/utils/utils.h> 27 28 #define ECFSDSA_R_LEN(p_bit_len) (2 * (BYTECEIL(p_bit_len))) 29 #define ECFSDSA_S_LEN(q_bit_len) (BYTECEIL(q_bit_len)) 30 #define ECFSDSA_SIGLEN(p_bit_len, q_bit_len) (ECFSDSA_R_LEN(p_bit_len) + \ 31 ECFSDSA_S_LEN(q_bit_len)) 32 #define ECFSDSA_MAX_SIGLEN ECFSDSA_SIGLEN(CURVES_MAX_P_BIT_LEN, \ 33 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) < (ECFSDSA_MAX_SIGLEN)) 44 #undef EC_MAX_SIGLEN 45 #define EC_MAX_SIGLEN ECFSDSA_MAX_SIGLEN 46 #endif 47 48 typedef struct { 49 nn k; 50 u8 r[2 * NN_MAX_BYTE_LEN]; 51 hash_context h_ctx; 52 word_t magic; 53 } ecfsdsa_sign_data; 54 55 struct ec_sign_context; 56 57 ATTRIBUTE_WARN_UNUSED_RET int ecfsdsa_init_pub_key(ec_pub_key *out_pub, const ec_priv_key *in_priv); 58 59 ATTRIBUTE_WARN_UNUSED_RET int ecfsdsa_siglen(u16 p_bit_len, u16 q_bit_len, u8 hsize, u8 blocksize, 60 u8 *siglen); 61 62 ATTRIBUTE_WARN_UNUSED_RET int _ecfsdsa_sign_init(struct ec_sign_context *ctx); 63 64 ATTRIBUTE_WARN_UNUSED_RET int _ecfsdsa_sign_update(struct ec_sign_context *ctx, 65 const u8 *chunk, u32 chunklen); 66 67 ATTRIBUTE_WARN_UNUSED_RET int _ecfsdsa_sign_finalize(struct ec_sign_context *ctx, u8 *sig, u8 siglen); 68 69 typedef struct { 70 u8 r[2 * NN_MAX_BYTE_LEN]; 71 nn s; 72 hash_context h_ctx; 73 word_t magic; 74 } ecfsdsa_verify_data; 75 76 struct ec_verify_context; 77 78 ATTRIBUTE_WARN_UNUSED_RET int _ecfsdsa_verify_init(struct ec_verify_context *ctx, 79 const u8 *sig, u8 siglen); 80 81 ATTRIBUTE_WARN_UNUSED_RET int _ecfsdsa_verify_update(struct ec_verify_context *ctx, 82 const u8 *chunk, u32 chunklen); 83 84 ATTRIBUTE_WARN_UNUSED_RET int _ecfsdsa_verify_finalize(struct ec_verify_context *ctx); 85 86 /* Batch verification function */ 87 ATTRIBUTE_WARN_UNUSED_RET int ecfsdsa_verify_batch(const u8 **s, const u8 *s_len, const ec_pub_key **pub_keys, 88 const u8 **m, const u32 *m_len, u32 num, ec_alg_type sig_type, 89 hash_alg_type hash_type, const u8 **adata, const u16 *adata_len, 90 verify_batch_scratch_pad *scratch_pad_area, u32 *scratch_pad_area_len); 91 92 93 #endif /* __ECFSDSA_H__ */ 94 #endif /* WITH_SIG_ECFSDSA */ 95