1 /* 2 * Copyright (c) 2001-2022, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef MBEDTLS_DHM_ALT_H 8 #define MBEDTLS_DHM_ALT_H 9 10 11 #if defined(MBEDTLS_DHM_ALT) 12 13 #include "mbedtls/build_info.h" 14 15 #include <stddef.h> 16 17 /* 18 * DHM Error codes 19 */ 20 #define MBEDTLS_ERR_DHM_BAD_INPUT_DATA -0x3080 /**< Bad input parameters. */ 21 #define MBEDTLS_ERR_DHM_READ_PARAMS_FAILED -0x3100 /**< Reading of the DHM parameters failed. */ 22 #define MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED -0x3180 /**< Making of the DHM parameters failed. */ 23 #define MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED -0x3200 /**< Reading of the public values failed. */ 24 #define MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280 /**< Making of the public value failed. */ 25 #define MBEDTLS_ERR_DHM_CALC_SECRET_FAILED -0x3300 /**< Calculation of the DHM secret failed. */ 26 #define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380 /**< The ASN.1 data is not formatted correctly. */ 27 #define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400 /**< Allocation of memory failed. */ 28 #define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480 /**< Read or write of file failed. */ 29 #define MBEDTLS_ERR_DHM_HW_ACCEL_FAILED -0x3500 /**< DHM hardware accelerator failed. */ 30 #define MBEDTLS_ERR_DHM_SET_GROUP_FAILED -0x3580 /**< Setting the modulus and generator failed. */ 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /** 37 * \brief The DHM context structure. 38 */ 39 typedef struct 40 { 41 size_t len; /*!< The size of \p P in Bytes. */ 42 mbedtls_mpi P; /*!< The prime modulus. */ 43 mbedtls_mpi G; /*!< The generator. */ 44 mbedtls_mpi X; /*!< Our secret value. */ 45 mbedtls_mpi GX; /*!< Our public key = \c G^X mod \c P. */ 46 mbedtls_mpi GY; /*!< The public key of the peer = \c G^Y mod \c P. */ 47 mbedtls_mpi K; /*!< The shared secret = \c G^(XY) mod \c P. */ 48 mbedtls_mpi RP; /*!< The cached value = \c R^2 mod \c P. */ 49 mbedtls_mpi Vi; /*!< The blinding value. */ 50 mbedtls_mpi Vf; /*!< The unblinding value. */ 51 mbedtls_mpi pX; /*!< The previous \c X. */ 52 } 53 mbedtls_dhm_context; 54 55 #ifdef __cplusplus 56 } 57 #endif 58 59 #endif /* MBEDTLS_DHM_ALT - use alternative code */ 60 #endif /* MBEDTLS_DHM_ALT_H - include only once */ 61