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 #include <libecc/lib_ecc_config.h> 12 #include <libecc/lib_ecc_types.h> 13 14 #if defined(WITH_X25519) || defined(WITH_X448) 15 16 #ifndef __X25519_448_H__ 17 #define __X25519_448_H__ 18 19 #include <libecc/words/words.h> 20 21 /* Size of X25519 values */ 22 #define X25519_SIZE 32 23 /* Size of X448 values */ 24 #define X448_SIZE 56 25 26 #if defined(WITH_X25519) 27 /* The X25519 function as specified in RFC7748. 28 * 29 * NOTE: the user of this primitive should be warned and aware that is is not fully compliant with the 30 * RFC7748 description as u coordinates on the quadratic twist of the curve are rejected as well as non 31 * canonical u. 32 * See the explanations in the implementation of the function for more context and explanations. 33 */ 34 ATTRIBUTE_WARN_UNUSED_RET int x25519(const u8 k[X25519_SIZE], const u8 u[X25519_SIZE], u8 res[X25519_SIZE]); 35 36 ATTRIBUTE_WARN_UNUSED_RET int x25519_gen_priv_key(u8 priv_key[X25519_SIZE]); 37 38 ATTRIBUTE_WARN_UNUSED_RET int x25519_init_pub_key(const u8 priv_key[X25519_SIZE], u8 pub_key[X25519_SIZE]); 39 40 ATTRIBUTE_WARN_UNUSED_RET int x25519_derive_secret(const u8 priv_key[X25519_SIZE], const u8 peer_pub_key[X25519_SIZE], u8 shared_secret[X25519_SIZE]); 41 #endif 42 43 #if defined(WITH_X448) 44 /* The X448 function as specified in RFC7748. 45 * 46 * NOTE: the user of this primitive should be warned and aware that is is not fully compliant with the 47 * RFC7748 description as u coordinates on the quadratic twist of the curve are rejected as well as non 48 * canonical u. 49 * See the explanations in the implementation of the function for more context and explanations. 50 */ 51 ATTRIBUTE_WARN_UNUSED_RET int x448(const u8 k[X448_SIZE], const u8 u[X448_SIZE], u8 res[X448_SIZE]); 52 53 ATTRIBUTE_WARN_UNUSED_RET int x448_gen_priv_key(u8 priv_key[X448_SIZE]); 54 55 ATTRIBUTE_WARN_UNUSED_RET int x448_init_pub_key(const u8 priv_key[X448_SIZE], u8 pub_key[X448_SIZE]); 56 57 ATTRIBUTE_WARN_UNUSED_RET int x448_derive_secret(const u8 priv_key[X448_SIZE], const u8 peer_pub_key[X448_SIZE], u8 shared_secret[X448_SIZE]); 58 #endif 59 60 #endif /* __X25519_448_H__ */ 61 62 #endif /* defined(WITH_X25519) || defined(WITH_X448) */ 63