Gilles Peskine | 80ba850 | 2021-04-03 20:36:37 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file ecp_invasive.h |
| 3 | * |
| 4 | * \brief ECP module: interfaces for invasive testing only. |
| 5 | * |
| 6 | * The interfaces in this file are intended for testing purposes only. |
| 7 | * They SHOULD NOT be made available in library integrations except when |
| 8 | * building the library for testing. |
| 9 | */ |
| 10 | /* |
| 11 | * Copyright The Mbed TLS Contributors |
| 12 | * SPDX-License-Identifier: Apache-2.0 |
| 13 | * |
| 14 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 15 | * not use this file except in compliance with the License. |
| 16 | * You may obtain a copy of the License at |
| 17 | * |
| 18 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 19 | * |
| 20 | * Unless required by applicable law or agreed to in writing, software |
| 21 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 22 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 | * See the License for the specific language governing permissions and |
| 24 | * limitations under the License. |
| 25 | */ |
| 26 | #ifndef MBEDTLS_ECP_INVASIVE_H |
| 27 | #define MBEDTLS_ECP_INVASIVE_H |
| 28 | |
| 29 | #include "common.h" |
Gilles Peskine | 72fcc98 | 2021-03-23 22:31:31 +0100 | [diff] [blame] | 30 | #include "mbedtls/bignum.h" |
Minos Galanakis | dd55692 | 2023-02-03 19:12:21 +0000 | [diff] [blame] | 31 | #include "bignum_mod.h" |
Gilles Peskine | 80ba850 | 2021-04-03 20:36:37 +0200 | [diff] [blame] | 32 | #include "mbedtls/ecp.h" |
| 33 | |
Gilles Peskine | 637c049 | 2023-06-15 19:07:41 +0200 | [diff] [blame] | 34 | /* |
| 35 | * Curve modulus types |
| 36 | */ |
| 37 | typedef enum { |
| 38 | MBEDTLS_ECP_MOD_NONE = 0, |
| 39 | MBEDTLS_ECP_MOD_COORDINATE, |
| 40 | MBEDTLS_ECP_MOD_SCALAR |
| 41 | } mbedtls_ecp_modulus_type; |
| 42 | |
Valerio Setti | 0c477d3 | 2023-04-07 15:54:20 +0200 | [diff] [blame] | 43 | #if defined(MBEDTLS_TEST_HOOKS) && defined(MBEDTLS_ECP_LIGHT) |
Gilles Peskine | 80ba850 | 2021-04-03 20:36:37 +0200 | [diff] [blame] | 44 | |
Gilles Peskine | 72fcc98 | 2021-03-23 22:31:31 +0100 | [diff] [blame] | 45 | #if defined(MBEDTLS_ECP_MONTGOMERY_ENABLED) |
| 46 | /** Generate a private key on a Montgomery curve (Curve25519 or Curve448). |
| 47 | * |
| 48 | * This function implements key generation for the set of secret keys |
| 49 | * specified in [Curve25519] p. 5 and in [Curve448]. The resulting value |
| 50 | * has the lower bits masked but is not necessarily canonical. |
| 51 | * |
| 52 | * \note - [Curve25519] http://cr.yp.to/ecdh/curve25519-20060209.pdf |
| 53 | * - [RFC7748] https://tools.ietf.org/html/rfc7748 |
| 54 | * |
Gilles Peskine | 55c4604 | 2021-03-24 12:34:40 +0100 | [diff] [blame] | 55 | * \p high_bit The position of the high-order bit of the key to generate. |
Gilles Peskine | 72fcc98 | 2021-03-23 22:31:31 +0100 | [diff] [blame] | 56 | * This is the bit-size of the key minus 1: |
| 57 | * 254 for Curve25519 or 447 for Curve448. |
| 58 | * \param d The randomly generated key. This is a number of size |
Xiaokang Qian | a089614 | 2023-04-18 06:49:55 +0000 | [diff] [blame] | 59 | * exactly \p high_bit + 1 bits, with the least significant bits |
Gilles Peskine | 72fcc98 | 2021-03-23 22:31:31 +0100 | [diff] [blame] | 60 | * masked as specified in [Curve25519] and in [RFC7748] ยง5. |
| 61 | * \param f_rng The RNG function. |
| 62 | * \param p_rng The RNG context to be passed to \p f_rng. |
| 63 | * |
| 64 | * \return \c 0 on success. |
| 65 | * \return \c MBEDTLS_ERR_ECP_xxx or MBEDTLS_ERR_MPI_xxx on failure. |
| 66 | */ |
Xiaokang Qian | a089614 | 2023-04-18 06:49:55 +0000 | [diff] [blame] | 67 | int mbedtls_ecp_gen_privkey_mx(size_t high_bit, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 68 | mbedtls_mpi *d, |
| 69 | int (*f_rng)(void *, unsigned char *, size_t), |
| 70 | void *p_rng); |
Gilles Peskine | 72fcc98 | 2021-03-23 22:31:31 +0100 | [diff] [blame] | 71 | |
| 72 | #endif /* MBEDTLS_ECP_MONTGOMERY_ENABLED */ |
| 73 | |
Gabor Mezei | deece2b | 2023-01-25 17:57:36 +0100 | [diff] [blame] | 74 | #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) |
| 75 | |
Gabor Mezei | 9b290b3 | 2023-01-27 11:00:51 +0100 | [diff] [blame] | 76 | /** Fast quasi-reduction modulo p192 (FIPS 186-3 D.2.1) |
| 77 | * |
Gabor Mezei | a264831 | 2023-02-13 16:29:05 +0100 | [diff] [blame] | 78 | * This operation expects a 384 bit MPI and the result of the reduction |
| 79 | * is a 192 bit MPI. |
| 80 | * |
Gabor Mezei | 9b290b3 | 2023-01-27 11:00:51 +0100 | [diff] [blame] | 81 | * \param[in,out] Np The address of the MPI to be converted. |
Gabor Mezei | 0b4b8e3 | 2023-02-14 16:36:38 +0100 | [diff] [blame] | 82 | * Must have twice as many limbs as the modulus. |
| 83 | * Upon return this holds the reduced value. The bitlength |
| 84 | * of the reduced value is the same as that of the modulus |
| 85 | * (192 bits). |
Gabor Mezei | 63aae68 | 2023-02-06 16:24:08 +0100 | [diff] [blame] | 86 | * \param[in] Nn The length of \p Np in limbs. |
Gabor Mezei | 9b290b3 | 2023-01-27 11:00:51 +0100 | [diff] [blame] | 87 | */ |
Gabor Mezei | deece2b | 2023-01-25 17:57:36 +0100 | [diff] [blame] | 88 | MBEDTLS_STATIC_TESTABLE |
Gabor Mezei | 2038ce9 | 2023-01-31 14:33:12 +0100 | [diff] [blame] | 89 | int mbedtls_ecp_mod_p192_raw(mbedtls_mpi_uint *Np, size_t Nn); |
Gabor Mezei | deece2b | 2023-01-25 17:57:36 +0100 | [diff] [blame] | 90 | |
| 91 | #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */ |
| 92 | |
Gabor Mezei | e14b5bd | 2023-02-08 17:23:03 +0100 | [diff] [blame] | 93 | #if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) |
| 94 | |
Gabor Mezei | a835d20 | 2023-02-23 17:38:00 +0100 | [diff] [blame] | 95 | /** Fast quasi-reduction modulo p224 (FIPS 186-3 D.2.2) |
| 96 | * |
Gabor Mezei | 08a9495 | 2023-02-28 18:40:57 +0100 | [diff] [blame] | 97 | * \param[in,out] X The address of the MPI to be converted. |
| 98 | * Must have exact limb size that stores a 448-bit MPI |
| 99 | * (double the bitlength of the modulus). |
| 100 | * Upon return holds the reduced value which is |
| 101 | * in range `0 <= X < 2 * N` (where N is the modulus). |
| 102 | * The bitlength of the reduced value is the same as |
| 103 | * that of the modulus (224 bits). |
| 104 | * \param[in] X_limbs The length of \p X in limbs. |
Gabor Mezei | a835d20 | 2023-02-23 17:38:00 +0100 | [diff] [blame] | 105 | * |
| 106 | * \return \c 0 on success. |
Gabor Mezei | 08a9495 | 2023-02-28 18:40:57 +0100 | [diff] [blame] | 107 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p X_limbs is not the |
| 108 | * limb size that sores a 448-bit MPI. |
Gabor Mezei | a835d20 | 2023-02-23 17:38:00 +0100 | [diff] [blame] | 109 | */ |
Gabor Mezei | e14b5bd | 2023-02-08 17:23:03 +0100 | [diff] [blame] | 110 | MBEDTLS_STATIC_TESTABLE |
Gabor Mezei | 08a9495 | 2023-02-28 18:40:57 +0100 | [diff] [blame] | 111 | int mbedtls_ecp_mod_p224_raw(mbedtls_mpi_uint *X, size_t X_limbs); |
Gabor Mezei | e14b5bd | 2023-02-08 17:23:03 +0100 | [diff] [blame] | 112 | |
| 113 | #endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */ |
| 114 | |
Gabor Mezei | 5221c04 | 2023-03-01 16:05:21 +0100 | [diff] [blame] | 115 | #if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) |
| 116 | |
Gabor Mezei | d1f16b9 | 2023-03-08 15:26:32 +0100 | [diff] [blame] | 117 | /** Fast quasi-reduction modulo p256 (FIPS 186-3 D.2.3) |
| 118 | * |
| 119 | * \param[in,out] X The address of the MPI to be converted. |
| 120 | * Must have exact limb size that stores a 512-bit MPI |
| 121 | * (double the bitlength of the modulus). |
| 122 | * Upon return holds the reduced value which is |
| 123 | * in range `0 <= X < 2 * N` (where N is the modulus). |
| 124 | * The bitlength of the reduced value is the same as |
| 125 | * that of the modulus (256 bits). |
| 126 | * \param[in] X_limbs The length of \p X in limbs. |
| 127 | * |
| 128 | * \return \c 0 on success. |
| 129 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p X_limbs is not the |
| 130 | * limb size that sores a 512-bit MPI. |
| 131 | */ |
Gabor Mezei | 5221c04 | 2023-03-01 16:05:21 +0100 | [diff] [blame] | 132 | MBEDTLS_STATIC_TESTABLE |
Gabor Mezei | ed1acf6 | 2023-03-01 16:09:13 +0100 | [diff] [blame] | 133 | int mbedtls_ecp_mod_p256_raw(mbedtls_mpi_uint *X, size_t X_limbs); |
Gabor Mezei | 5221c04 | 2023-03-01 16:05:21 +0100 | [diff] [blame] | 134 | |
| 135 | #endif |
| 136 | |
Gabor Mezei | 2cb630e | 2023-02-01 14:02:16 +0100 | [diff] [blame] | 137 | #if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) |
| 138 | |
Gabor Mezei | b1c62ca | 2023-02-06 16:02:05 +0100 | [diff] [blame] | 139 | /** Fast quasi-reduction modulo p521 = 2^521 - 1 (FIPS 186-3 D.2.5) |
| 140 | * |
Gabor Mezei | 7e6fcc1 | 2023-02-15 17:51:59 +0100 | [diff] [blame] | 141 | * \param[in,out] X The address of the MPI to be converted. |
| 142 | * Must have twice as many limbs as the modulus |
| 143 | * (the modulus is 521 bits long). Upon return this |
| 144 | * holds the reduced value. The reduced value is |
| 145 | * in range `0 <= X < 2 * N` (where N is the modulus). |
| 146 | * and its the bitlength is one plus the bitlength |
| 147 | * of the modulus. |
| 148 | * \param[in] X_limbs The length of \p X in limbs. |
| 149 | * |
| 150 | * \return \c 0 on success. |
| 151 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p X_limbs does not have |
| 152 | * twice as many limbs as the modulus. |
Gabor Mezei | b1c62ca | 2023-02-06 16:02:05 +0100 | [diff] [blame] | 153 | */ |
Gabor Mezei | 2cb630e | 2023-02-01 14:02:16 +0100 | [diff] [blame] | 154 | MBEDTLS_STATIC_TESTABLE |
Gabor Mezei | 7e6fcc1 | 2023-02-15 17:51:59 +0100 | [diff] [blame] | 155 | int mbedtls_ecp_mod_p521_raw(mbedtls_mpi_uint *X, size_t X_limbs); |
Gabor Mezei | 2cb630e | 2023-02-01 14:02:16 +0100 | [diff] [blame] | 156 | |
| 157 | #endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */ |
| 158 | |
Minos Galanakis | 6fb105f | 2023-02-22 15:28:20 +0000 | [diff] [blame] | 159 | #if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) |
| 160 | |
| 161 | /** Fast quasi-reduction modulo p384 (FIPS 186-3 D.2.4) |
| 162 | * |
| 163 | * \param[in,out] X The address of the MPI to be converted. |
Minos Galanakis | f9fca53 | 2023-03-23 10:36:53 +0000 | [diff] [blame] | 164 | * Must have exact limb size that stores a 768-bit MPI |
| 165 | * (double the bitlength of the modulus). |
Minos Galanakis | 6fb105f | 2023-02-22 15:28:20 +0000 | [diff] [blame] | 166 | * Upon return holds the reduced value which is |
| 167 | * in range `0 <= X < 2 * N` (where N is the modulus). |
| 168 | * The bitlength of the reduced value is the same as |
| 169 | * that of the modulus (384 bits). |
| 170 | * \param[in] X_limbs The length of \p N in limbs. |
| 171 | * |
| 172 | * \return \c 0 on success. |
| 173 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p N_n does not have |
| 174 | * twice as many limbs as the modulus. |
| 175 | */ |
| 176 | MBEDTLS_STATIC_TESTABLE |
| 177 | int mbedtls_ecp_mod_p384_raw(mbedtls_mpi_uint *X, size_t X_limbs); |
| 178 | |
| 179 | #endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */ |
| 180 | |
Gabor Mezei | 1237a34 | 2023-04-11 16:22:35 +0200 | [diff] [blame] | 181 | #if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) |
| 182 | |
Gabor Mezei | fa3f741 | 2023-05-17 17:35:47 +0200 | [diff] [blame] | 183 | /** Fast quasi-reduction modulo p192k1 = 2^192 - R, |
| 184 | * with R = 2^32 + 2^12 + 2^8 + 2^7 + 2^6 + 2^3 + 1 = 0x01000011C9 |
| 185 | * |
| 186 | * \param[in,out] X The address of the MPI to be converted. |
| 187 | * Must have exact limb size that stores a 384-bit MPI |
| 188 | * (double the bitlength of the modulus). |
| 189 | * Upon return holds the reduced value which is |
| 190 | * in range `0 <= X < 2 * N` (where N is the modulus). |
| 191 | * The bitlength of the reduced value is the same as |
| 192 | * that of the modulus (192 bits). |
| 193 | * \param[in] X_limbs The length of \p X in limbs. |
| 194 | * |
| 195 | * \return \c 0 on success. |
Gabor Mezei | d56e6e0 | 2023-05-17 17:51:19 +0200 | [diff] [blame] | 196 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p X does not have |
| 197 | * twice as many limbs as the modulus. |
Gabor Mezei | fa3f741 | 2023-05-17 17:35:47 +0200 | [diff] [blame] | 198 | * \return #MBEDTLS_ERR_ECP_ALLOC_FAILED if memory allocation failed. |
Gabor Mezei | 1237a34 | 2023-04-11 16:22:35 +0200 | [diff] [blame] | 199 | */ |
| 200 | MBEDTLS_STATIC_TESTABLE |
Gabor Mezei | dacfe56 | 2023-05-02 14:05:13 +0200 | [diff] [blame] | 201 | int mbedtls_ecp_mod_p192k1_raw(mbedtls_mpi_uint *X, size_t X_limbs); |
Gabor Mezei | 1237a34 | 2023-04-11 16:22:35 +0200 | [diff] [blame] | 202 | |
| 203 | #endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */ |
Gabor Mezei | e42bb62 | 2023-05-02 14:10:57 +0200 | [diff] [blame] | 204 | |
Minos Galanakis | e5dab97 | 2023-04-11 16:42:06 +0100 | [diff] [blame] | 205 | #if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) |
| 206 | |
Gabor Mezei | fa3f741 | 2023-05-17 17:35:47 +0200 | [diff] [blame] | 207 | /** Fast quasi-reduction modulo p224k1 = 2^224 - R, |
| 208 | * with R = 2^32 + 2^12 + 2^11 + 2^9 + 2^7 + 2^4 + 2 + 1 = 0x0100001A93 |
| 209 | * |
| 210 | * \param[in,out] X The address of the MPI to be converted. |
| 211 | * Must have exact limb size that stores a 448-bit MPI |
| 212 | * (double the bitlength of the modulus). |
| 213 | * Upon return holds the reduced value which is |
| 214 | * in range `0 <= X < 2 * N` (where N is the modulus). |
| 215 | * The bitlength of the reduced value is the same as |
| 216 | * that of the modulus (224 bits). |
| 217 | * \param[in] X_limbs The length of \p X in limbs. |
| 218 | * |
| 219 | * \return \c 0 on success. |
Gabor Mezei | d56e6e0 | 2023-05-17 17:51:19 +0200 | [diff] [blame] | 220 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p X does not have |
| 221 | * twice as many limbs as the modulus. |
Gabor Mezei | fa3f741 | 2023-05-17 17:35:47 +0200 | [diff] [blame] | 222 | * \return #MBEDTLS_ERR_ECP_ALLOC_FAILED if memory allocation failed. |
| 223 | */ |
Minos Galanakis | e5dab97 | 2023-04-11 16:42:06 +0100 | [diff] [blame] | 224 | MBEDTLS_STATIC_TESTABLE |
Gabor Mezei | e42bb62 | 2023-05-02 14:10:57 +0200 | [diff] [blame] | 225 | int mbedtls_ecp_mod_p224k1_raw(mbedtls_mpi_uint *X, size_t X_limbs); |
Minos Galanakis | e5dab97 | 2023-04-11 16:42:06 +0100 | [diff] [blame] | 226 | |
| 227 | #endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */ |
Gabor Mezei | 1237a34 | 2023-04-11 16:22:35 +0200 | [diff] [blame] | 228 | |
Minos Galanakis | d6751dc | 2023-04-11 17:25:31 +0100 | [diff] [blame] | 229 | #if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) |
| 230 | |
Gabor Mezei | fa3f741 | 2023-05-17 17:35:47 +0200 | [diff] [blame] | 231 | /** Fast quasi-reduction modulo p256k1 = 2^256 - R, |
| 232 | * with R = 2^32 + 2^9 + 2^8 + 2^7 + 2^6 + 2^4 + 1 = 0x01000003D1 |
| 233 | * |
| 234 | * \param[in,out] X The address of the MPI to be converted. |
| 235 | * Must have exact limb size that stores a 512-bit MPI |
| 236 | * (double the bitlength of the modulus). |
| 237 | * Upon return holds the reduced value which is |
| 238 | * in range `0 <= X < 2 * N` (where N is the modulus). |
| 239 | * The bitlength of the reduced value is the same as |
| 240 | * that of the modulus (256 bits). |
| 241 | * \param[in] X_limbs The length of \p X in limbs. |
| 242 | * |
| 243 | * \return \c 0 on success. |
Gabor Mezei | d56e6e0 | 2023-05-17 17:51:19 +0200 | [diff] [blame] | 244 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p X does not have |
| 245 | * twice as many limbs as the modulus. |
Gabor Mezei | fa3f741 | 2023-05-17 17:35:47 +0200 | [diff] [blame] | 246 | * \return #MBEDTLS_ERR_ECP_ALLOC_FAILED if memory allocation failed. |
| 247 | */ |
Minos Galanakis | d6751dc | 2023-04-11 17:25:31 +0100 | [diff] [blame] | 248 | MBEDTLS_STATIC_TESTABLE |
Gabor Mezei | 03558b8 | 2023-05-02 14:12:25 +0200 | [diff] [blame] | 249 | int mbedtls_ecp_mod_p256k1_raw(mbedtls_mpi_uint *X, size_t X_limbs); |
Minos Galanakis | d6751dc | 2023-04-11 17:25:31 +0100 | [diff] [blame] | 250 | |
| 251 | #endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */ |
| 252 | |
Minos Galanakis | d0292c2 | 2023-05-10 15:46:47 +0100 | [diff] [blame] | 253 | #if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) |
| 254 | |
Minos Galanakis | 47249fd | 2023-05-18 16:16:17 +0100 | [diff] [blame] | 255 | /** Fast quasi-reduction modulo p255 = 2^255 - 19 |
| 256 | * |
| 257 | * \param[in,out] X The address of the MPI to be converted. |
| 258 | * Must have exact limb size that stores a 510-bit MPI |
| 259 | * (double the bitlength of the modulus). |
| 260 | * Upon return holds the reduced value which is |
| 261 | * in range `0 <= X < 2 * N` (where N is the modulus). |
Minos Galanakis | 47249fd | 2023-05-18 16:16:17 +0100 | [diff] [blame] | 262 | * \param[in] X_limbs The length of \p X in limbs. |
| 263 | * |
| 264 | * \return \c 0 on success. |
| 265 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p X does not have |
| 266 | * twice as many limbs as the modulus. |
| 267 | * \return #MBEDTLS_ERR_ECP_ALLOC_FAILED if memory allocation failed. |
| 268 | */ |
Minos Galanakis | d0292c2 | 2023-05-10 15:46:47 +0100 | [diff] [blame] | 269 | MBEDTLS_STATIC_TESTABLE |
| 270 | int mbedtls_ecp_mod_p255_raw(mbedtls_mpi_uint *X, size_t X_limbs); |
| 271 | |
| 272 | #endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED */ |
| 273 | |
Paul Elliott | 47a3c82 | 2023-04-23 23:18:50 +0100 | [diff] [blame] | 274 | #if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) |
| 275 | |
Paul Elliott | ee86100 | 2023-05-31 12:12:22 +0100 | [diff] [blame] | 276 | /** Fast quasi-reduction modulo p448 = 2^448 - 2^224 - 1 |
| 277 | * Write X as A0 + 2^448 A1 and A1 as B0 + 2^224 B1, and return A0 + A1 + B1 + |
| 278 | * (B0 + B1) * 2^224. |
| 279 | * |
| 280 | * \param[in,out] X The address of the MPI to be converted. |
| 281 | * Must have exact limb size that stores a 896-bit MPI |
| 282 | * (double the bitlength of the modulus). Upon return |
| 283 | * holds the reduced value which is in range `0 <= X < |
| 284 | * N` (where N is the modulus). The bitlength of the |
| 285 | * reduced value is the same as that of the modulus |
| 286 | * (448 bits). |
| 287 | * \param[in] X_limbs The length of \p X in limbs. |
| 288 | * |
| 289 | * \return \c 0 on Success. |
| 290 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p X does not have |
| 291 | * twice as many limbs as the modulus. |
| 292 | * \return #MBEDTLS_ERR_ECP_ALLOC_FAILED if memory allocation |
| 293 | * failed. |
| 294 | */ |
Paul Elliott | 47a3c82 | 2023-04-23 23:18:50 +0100 | [diff] [blame] | 295 | MBEDTLS_STATIC_TESTABLE |
Paul Elliott | a2e48f7 | 2023-06-02 16:00:05 +0100 | [diff] [blame] | 296 | int mbedtls_ecp_mod_p448_raw(mbedtls_mpi_uint *X, size_t X_limbs); |
Paul Elliott | 47a3c82 | 2023-04-23 23:18:50 +0100 | [diff] [blame] | 297 | |
| 298 | #endif /* MBEDTLS_ECP_DP_CURVE448_ENABLED */ |
| 299 | |
Minos Galanakis | a30afe2 | 2023-02-15 15:36:29 +0000 | [diff] [blame] | 300 | /** Initialise a modulus with hard-coded const curve data. |
| 301 | * |
| 302 | * \note The caller is responsible for the \p N modulus' memory. |
| 303 | * mbedtls_mpi_mod_modulus_free(&N) should be invoked at the |
| 304 | * end of its lifecycle. |
| 305 | * |
| 306 | * \param[in,out] N The address of the modulus structure to populate. |
| 307 | * Must be initialized. |
| 308 | * \param[in] id The mbedtls_ecp_group_id for which to initialise the modulus. |
Minos Galanakis | 1d3e332 | 2023-06-09 14:53:30 +0100 | [diff] [blame^] | 309 | * \param[in] ctype The mbedtls_ecp_modulus_type identifier for a coordinate modulus (P) |
Minos Galanakis | a30afe2 | 2023-02-15 15:36:29 +0000 | [diff] [blame] | 310 | * or a scalar modulus (N). |
| 311 | * |
| 312 | * \return \c 0 if successful. |
| 313 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the given MPIs do not |
| 314 | * have the correct number of limbs. |
| 315 | * |
| 316 | */ |
Minos Galanakis | dd55692 | 2023-02-03 19:12:21 +0000 | [diff] [blame] | 317 | MBEDTLS_STATIC_TESTABLE |
| 318 | int mbedtls_ecp_modulus_setup(mbedtls_mpi_mod_modulus *N, |
| 319 | const mbedtls_ecp_group_id id, |
Minos Galanakis | 1d3e332 | 2023-06-09 14:53:30 +0100 | [diff] [blame^] | 320 | const mbedtls_ecp_modulus_type ctype); |
Minos Galanakis | dd55692 | 2023-02-03 19:12:21 +0000 | [diff] [blame] | 321 | |
Gilles Peskine | 80ba850 | 2021-04-03 20:36:37 +0200 | [diff] [blame] | 322 | #endif /* MBEDTLS_TEST_HOOKS && MBEDTLS_ECP_C */ |
| 323 | |
| 324 | #endif /* MBEDTLS_ECP_INVASIVE_H */ |