Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file lmots.h |
| 3 | * |
| 4 | * \brief This file provides an API for the LM-OTS post-quantum-safe one-time |
Raef Coles | 2ad6e61 | 2022-08-24 13:33:35 +0100 | [diff] [blame] | 5 | * public-key signature scheme as defined in RFC8554 and NIST.SP.200-208. |
| 6 | * This implementation currently only supports a single parameter set |
| 7 | * MBEDTLS_LMOTS_SHA256_N32_W8 in order to reduce complexity. |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 8 | */ |
| 9 | /* |
| 10 | * Copyright The Mbed TLS Contributors |
| 11 | * SPDX-License-Identifier: Apache-2.0 |
| 12 | * |
| 13 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 14 | * not use this file except in compliance with the License. |
| 15 | * You may obtain a copy of the License at |
| 16 | * |
| 17 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 18 | * |
| 19 | * Unless required by applicable law or agreed to in writing, software |
| 20 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 21 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | * See the License for the specific language governing permissions and |
| 23 | * limitations under the License. |
| 24 | */ |
| 25 | |
| 26 | #ifndef MBEDTLS_LMOTS_H |
| 27 | #define MBEDTLS_LMOTS_H |
| 28 | |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 29 | #include "mbedtls/build_info.h" |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 30 | |
Raef Coles | c8f9604 | 2022-08-25 13:49:54 +0100 | [diff] [blame] | 31 | #include "psa/crypto.h" |
| 32 | |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 33 | #include <stdint.h> |
| 34 | #include <stddef.h> |
| 35 | |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 36 | #define MBEDTLS_LMOTS_N_HASH_LEN (32) |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 37 | #define MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT (34) |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 38 | #define MBEDTLS_LMOTS_TYPE_LEN (4) |
| 39 | #define MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN (MBEDTLS_LMOTS_N_HASH_LEN) |
| 40 | #define MBEDTLS_LMOTS_I_KEY_ID_LEN (16) |
| 41 | #define MBEDTLS_LMOTS_Q_LEAF_ID_LEN (4) |
| 42 | |
| 43 | #define MBEDTLS_LMOTS_SIG_LEN (MBEDTLS_LMOTS_TYPE_LEN + MBEDTLS_LMOTS_C_RANDOM_VALUE_LEN + \ |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 44 | (MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT * MBEDTLS_LMOTS_N_HASH_LEN)) |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 45 | |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 46 | #define MBEDTLS_LMOTS_PUBLIC_KEY_LEN (MBEDTLS_LMOTS_TYPE_LEN + MBEDTLS_LMOTS_I_KEY_ID_LEN + \ |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 47 | MBEDTLS_LMOTS_Q_LEAF_ID_LEN + MBEDTLS_LMOTS_N_HASH_LEN) |
| 48 | |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 49 | #define MBEDTLS_LMOTS_SIG_TYPE_OFFSET (0) |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 50 | |
| 51 | #ifdef __cplusplus |
| 52 | extern "C" { |
| 53 | #endif |
| 54 | |
Raef Coles | c464746 | 2022-06-15 12:17:51 +0100 | [diff] [blame] | 55 | /* https://www.iana.org/assignments/leighton-micali-signatures/leighton-micali-signatures.xhtml |
| 56 | * We are only implementing a subset of the types, particularly n32_w8, for the sake of simplicty. |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 57 | */ |
| 58 | typedef enum { |
| 59 | MBEDTLS_LMOTS_SHA256_N32_W8 = 4 |
| 60 | } mbedtls_lmots_algorithm_type_t; |
| 61 | |
| 62 | |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 63 | /** LMOTS parameters structure. |
| 64 | * |
| 65 | * This contains the metadata associated with an LMOTS key, detailing the |
| 66 | * algorithm type, the key ID, and the leaf identifier should be key be part of |
| 67 | * a LMS key. |
| 68 | */ |
| 69 | typedef struct { |
| 70 | unsigned char MBEDTLS_PRIVATE(I_key_identifier[MBEDTLS_LMOTS_I_KEY_ID_LEN]); /*!< The key |
| 71 | identifier. */ |
| 72 | unsigned char MBEDTLS_PRIVATE(q_leaf_identifier[MBEDTLS_LMOTS_Q_LEAF_ID_LEN]); /*!< Which |
| 73 | leaf of the LMS key this is. |
| 74 | 0 if the key is not part of an LMS key. */ |
| 75 | mbedtls_lmots_algorithm_type_t MBEDTLS_PRIVATE(type); /*!< The LM-OTS key type identifier as |
| 76 | per IANA. Only SHA256_N32_W8 is |
| 77 | currently supported. */ |
| 78 | } mbedtls_lmots_parameters_t; |
| 79 | |
| 80 | /** LMOTS public context structure. |
| 81 | * |
| 82 | * A LMOTS public key is a hash output, and the applicable parameter set. |
Raef Coles | 2ad6e61 | 2022-08-24 13:33:35 +0100 | [diff] [blame] | 83 | * |
| 84 | * The context must be initialized before it is used. A public key must either |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 85 | * be imported or generated from a private context. |
Raef Coles | 2ad6e61 | 2022-08-24 13:33:35 +0100 | [diff] [blame] | 86 | * |
| 87 | * \dot |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 88 | * digraph lmots_public_t { |
Raef Coles | 2ad6e61 | 2022-08-24 13:33:35 +0100 | [diff] [blame] | 89 | * UNINITIALIZED -> INIT [label="init"]; |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 90 | * HAVE_PUBLIC_KEY -> INIT [label="free"]; |
| 91 | * INIT -> HAVE_PUBLIC_KEY [label="import_public_key"]; |
| 92 | * INIT -> HAVE_PUBLIC_KEY [label="calculate_public_key from private key"]; |
| 93 | * HAVE_PUBLIC_KEY -> HAVE_PUBLIC_KEY [label="export_public_key"]; |
Raef Coles | 2ad6e61 | 2022-08-24 13:33:35 +0100 | [diff] [blame] | 94 | * } |
| 95 | * \enddot |
| 96 | */ |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 97 | typedef struct { |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 98 | mbedtls_lmots_parameters_t MBEDTLS_PRIVATE(params); |
| 99 | unsigned char MBEDTLS_PRIVATE(public_key)[32]; |
| 100 | unsigned char MBEDTLS_PRIVATE(have_public_key); /*!< Whether the context contains a public key. |
Raef Coles | c464746 | 2022-06-15 12:17:51 +0100 | [diff] [blame] | 101 | Boolean values only. */ |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 102 | } mbedtls_lmots_public_t; |
| 103 | |
Raef Coles | ab4f874 | 2022-09-01 12:24:31 +0100 | [diff] [blame^] | 104 | #ifdef MBEDTLS_LMS_PRIVATE |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 105 | /** LMOTS private context structure. |
| 106 | * |
| 107 | * A LMOTS private key is one hash output for each of digit of the digest + |
| 108 | * checksum, and the applicable parameter set. |
| 109 | * |
| 110 | * The context must be initialized before it is used. A public key must either |
| 111 | * be imported or generated from a private context. |
| 112 | * |
| 113 | * \dot |
| 114 | * digraph lmots_public_t { |
| 115 | * UNINITIALIZED -> INIT [label="init"]; |
| 116 | * HAVE_PRIVATE_KEY -> INIT [label="free"]; |
| 117 | * INIT -> HAVE_PRIVATE_KEY [label="generate_private_key"]; |
| 118 | * HAVE_PRIVATE_KEY -> INIT [label="sign"]; |
| 119 | * } |
| 120 | * \enddot |
| 121 | */ |
| 122 | typedef struct { |
| 123 | mbedtls_lmots_parameters_t MBEDTLS_PRIVATE(params); |
| 124 | unsigned char MBEDTLS_PRIVATE(private_key)[MBEDTLS_LMOTS_P_SIG_DIGIT_COUNT][32]; |
| 125 | unsigned char MBEDTLS_PRIVATE(have_private_key); /*!< Whether the context contains a private key. |
Raef Coles | c464746 | 2022-06-15 12:17:51 +0100 | [diff] [blame] | 126 | Boolean values only. */ |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 127 | } mbedtls_lmots_private_t; |
Raef Coles | ab4f874 | 2022-09-01 12:24:31 +0100 | [diff] [blame^] | 128 | #endif /* MBEDTLS_LMS_PRIVATE */ |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * \brief This function converts an unsigned int into a |
| 132 | * network-byte-order (big endian) string. |
| 133 | * |
| 134 | * \param val The unsigned integer value |
| 135 | * \param len The length of the string. |
| 136 | * \param bytes The string to output into. |
| 137 | * |
| 138 | * \return The corresponding LMS error code. |
| 139 | */ |
| 140 | void unsigned_int_to_network_bytes(unsigned int val, size_t len, unsigned char *bytes); |
| 141 | |
| 142 | /** |
| 143 | * \brief This function converts a network-byte-order |
| 144 | * (big endian) string into an unsigned integer. |
| 145 | * |
| 146 | * \param len The length of the string. |
| 147 | * \param bytes The string. |
| 148 | * |
| 149 | * \return The corresponding LMS error code. |
| 150 | */ |
| 151 | unsigned int network_bytes_to_unsigned_int(size_t len, const unsigned char *bytes); |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 152 | |
Raef Coles | c8f9604 | 2022-08-25 13:49:54 +0100 | [diff] [blame] | 153 | /** |
| 154 | * \brief This function converts a \ref psa_status_t to a |
| 155 | * low-level LMS error code. |
| 156 | * |
| 157 | * \param status The psa_status_t to convert |
| 158 | * |
| 159 | * \return The corresponding LMS error code. |
| 160 | */ |
| 161 | int mbedtls_lms_error_from_psa(psa_status_t status); |
| 162 | |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 163 | |
| 164 | /** |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 165 | * \brief This function initializes a public LMOTS context |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 166 | * |
| 167 | * \param ctx The uninitialized LMOTS context that will then be |
| 168 | * initialized. |
| 169 | */ |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 170 | void mbedtls_lmots_init_public( mbedtls_lmots_public_t *ctx ); |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 171 | |
| 172 | /** |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 173 | * \brief This function uninitializes a public LMOTS context |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 174 | * |
| 175 | * \param ctx The initialized LMOTS context that will then be |
| 176 | * uninitialized. |
| 177 | */ |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 178 | void mbedtls_lmots_free_public( mbedtls_lmots_public_t *ctx ); |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 179 | |
| 180 | /** |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 181 | * \brief This function imports an LMOTS public key into a |
| 182 | * LMOTS context. |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 183 | * |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 184 | * \note Before this function is called, the context must |
| 185 | * have been initialized. |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 186 | * |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 187 | * \note See IETF RFC8554 for details of the encoding of |
| 188 | * this public key. |
| 189 | * |
| 190 | * \param ctx The initialized LMOTS context store the key in. |
| 191 | * \param key The buffer from which the key will be read. |
| 192 | * #MBEDTLS_LMOTS_PUBLIC_KEY_LEN bytes will be read from |
| 193 | * this. |
Raef Coles | c8f9604 | 2022-08-25 13:49:54 +0100 | [diff] [blame] | 194 | * |
| 195 | * \return \c 0 on success. |
| 196 | * \return A non-zero error code on failure. |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 197 | */ |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 198 | int mbedtls_lmots_import_public_key( mbedtls_lmots_public_t *ctx, |
| 199 | const unsigned char *key, size_t key_size ); |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 200 | |
| 201 | /** |
| 202 | * \brief This function creates a candidate public key from |
| 203 | * an LMOTS signature. This can then be compared to |
| 204 | * the real public key to determine the validity of |
| 205 | * the signature. |
| 206 | * |
| 207 | * \note This function is exposed publicly to be used in LMS |
| 208 | * signature verification, it is expected that |
| 209 | * mbedtls_lmots_verify will be used for LMOTS |
| 210 | * signature verification. |
| 211 | * |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 212 | * \param params The LMOTS parameter set, q and I values as an |
| 213 | * mbedtls_lmots_parameters_t struct. |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 214 | * \param msg The buffer from which the message will be read. |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 215 | * \param msg_size The size of the message that will be read. |
Raef Coles | 2ad6e61 | 2022-08-24 13:33:35 +0100 | [diff] [blame] | 216 | * \param sig The buffer from which the signature will be read. |
| 217 | * #MBEDTLS_LMOTS_SIG_LEN bytes will be read from this. |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 218 | * \param out The buffer where the candidate public key will be |
| 219 | * stored. Must be at least #MBEDTLS_LMOTS_N_HASH_LEN |
| 220 | * bytes in size. |
| 221 | * |
| 222 | * \return \c 0 on success. |
| 223 | * \return A non-zero error code on failure. |
| 224 | */ |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 225 | int mbedtls_lmots_calculate_public_key_candidate( const mbedtls_lmots_parameters_t *params, |
| 226 | const unsigned char *msg, |
| 227 | size_t msg_size, |
| 228 | const unsigned char *sig, |
| 229 | size_t sig_size, |
| 230 | unsigned char *out, |
| 231 | size_t out_size, |
| 232 | size_t *out_len); |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 233 | |
| 234 | /** |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 235 | * \brief This function verifies a LMOTS signature, using a |
| 236 | * LMOTS context that contains a public key. |
| 237 | * |
| 238 | * \warning This function is **not intended for use in |
| 239 | * production**, due to as-yet unsolved problems with |
| 240 | * handling stateful keys. |
| 241 | * |
| 242 | * \note Before this function is called, the context must |
| 243 | * have been initialized and must contain a public key |
| 244 | * (either by import or calculation from a private key). |
| 245 | * |
| 246 | * \param ctx The initialized LMOTS context from which the public |
| 247 | * key will be read. |
| 248 | * \param msg The buffer from which the message will be read. |
| 249 | * \param msg_size The size of the message that will be read. |
| 250 | * \param sig The buf from which the signature will be read. |
| 251 | * #MBEDTLS_LMOTS_SIG_LEN bytes will be read from |
| 252 | * this. |
| 253 | * |
| 254 | * \return \c 0 on successful verification. |
| 255 | * \return A non-zero error code on failure. |
| 256 | */ |
| 257 | int mbedtls_lmots_verify( mbedtls_lmots_public_t *ctx, const unsigned char *msg, |
| 258 | size_t msg_size, const unsigned char *sig, |
| 259 | size_t sig_size ); |
| 260 | |
Raef Coles | ab4f874 | 2022-09-01 12:24:31 +0100 | [diff] [blame^] | 261 | #ifdef MBEDTLS_LMS_PRIVATE |
| 262 | |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 263 | /** |
| 264 | * \brief This function initializes a private LMOTS context |
| 265 | * |
| 266 | * \param ctx The uninitialized LMOTS context that will then be |
| 267 | * initialized. |
| 268 | */ |
| 269 | void mbedtls_lmots_init_private( mbedtls_lmots_private_t *ctx ); |
| 270 | |
| 271 | /** |
| 272 | * \brief This function uninitializes a private LMOTS context |
| 273 | * |
| 274 | * \param ctx The initialized LMOTS context that will then be |
| 275 | * uninitialized. |
| 276 | */ |
| 277 | void mbedtls_lmots_free_private( mbedtls_lmots_private_t *ctx ); |
| 278 | |
| 279 | /** |
| 280 | * \brief This function generates an LMOTS private key, and |
| 281 | * stores in into an LMOTS context. |
| 282 | * |
| 283 | * \warning This function is **not intended for use in |
| 284 | * production**, due to as-yet unsolved problems with |
| 285 | * handling stateful keys. |
| 286 | * |
| 287 | * \note The seed must have at least 256 bits of entropy. |
| 288 | * |
| 289 | * \param ctx The initialized LMOTS context to generate the key |
| 290 | * into. |
| 291 | * \param I_key_identifier The key identifier of the key, as a 16-byte string. |
| 292 | * \param q_leaf_identifier The leaf identifier of key. If this LMOTS key is |
| 293 | * not being used as part of an LMS key, this should |
| 294 | * be set to 0. |
| 295 | * \param seed The seed used to deterministically generate the |
| 296 | * key. |
| 297 | * \param seed_size The length of the seed. |
| 298 | * |
| 299 | * \return \c 0 on success. |
| 300 | * \return A non-zero error code on failure. |
| 301 | */ |
| 302 | int mbedtls_lmots_generate_private_key( mbedtls_lmots_private_t *ctx, |
| 303 | mbedtls_lmots_algorithm_type_t type, |
| 304 | const unsigned char I_key_identifier[MBEDTLS_LMOTS_I_KEY_ID_LEN], |
| 305 | uint32_t q_leaf_identifier, |
| 306 | const unsigned char *seed, |
| 307 | size_t seed_size ); |
| 308 | |
| 309 | /** |
| 310 | * \brief This function generates an LMOTS public key from a |
| 311 | * LMOTS context that already contains a private key. |
| 312 | * |
| 313 | * \note Before this function is called, the context must |
| 314 | * have been initialized and the context must contain |
| 315 | * a private key. |
| 316 | * |
| 317 | * \param ctx The initialized LMOTS context to generate the key |
| 318 | * from and store it into. |
| 319 | * |
| 320 | * \return \c 0 on success. |
| 321 | * \return A non-zero error code on failure. |
| 322 | */ |
| 323 | int mbedtls_lmots_calculate_public_key( mbedtls_lmots_public_t *ctx, |
| 324 | mbedtls_lmots_private_t *priv_ctx); |
| 325 | |
| 326 | |
| 327 | /** |
| 328 | * \brief This function exports an LMOTS public key from a |
| 329 | * LMOTS context that already contains a public key. |
| 330 | * |
| 331 | * \note Before this function is called, the context must |
| 332 | * have been initialized and the context must contain |
| 333 | * a public key. |
| 334 | * |
| 335 | * \note See IETF RFC8554 for details of the encoding of |
| 336 | * this public key. |
| 337 | * |
| 338 | * \param ctx The initialized LMOTS context that contains the |
| 339 | * publc key. |
| 340 | * \param key The buffer into which the key will be output. Must |
| 341 | * be at least #MBEDTLS_LMOTS_PUBLIC_KEY_LEN in size. |
| 342 | * |
| 343 | * \return \c 0 on success. |
| 344 | * \return A non-zero error code on failure. |
| 345 | */ |
| 346 | int mbedtls_lmots_export_public_key( mbedtls_lmots_public_t *ctx, |
| 347 | unsigned char *key, size_t key_size, |
| 348 | size_t *key_len ); |
| 349 | /** |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 350 | * \brief This function creates a LMOTS signature, using a |
| 351 | * LMOTS context that contains a private key. |
| 352 | * |
| 353 | * \note Before this function is called, the context must |
| 354 | * have been initialized and must contain a private |
| 355 | * key. |
| 356 | * |
| 357 | * \note LMOTS private keys can only be used once, otherwise |
| 358 | * attackers may be able to create forged signatures. |
| 359 | * If the signing operation is successful, the private |
| 360 | * key in the context will be erased, and no further |
| 361 | * signing will be possible until another private key |
| 362 | * is loaded |
| 363 | * |
| 364 | * \param ctx The initialized LMOTS context from which the |
| 365 | * private key will be read. |
| 366 | * \param f_rng The RNG function to be used for signature |
| 367 | * generation. |
| 368 | * \param p_rng The RNG context to be passed to f_rng |
| 369 | * \param msg The buffer from which the message will be read. |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 370 | * \param msg_size The size of the message that will be read. |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 371 | * \param sig The buf into which the signature will be stored. |
| 372 | * Must be at least #MBEDTLS_LMOTS_SIG_LEN in size. |
| 373 | * |
| 374 | * \return \c 0 on success. |
| 375 | * \return A non-zero error code on failure. |
| 376 | */ |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 377 | int mbedtls_lmots_sign( mbedtls_lmots_private_t *ctx, |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 378 | int (*f_rng)(void *, unsigned char *, size_t), |
Raef Coles | 01c71a1 | 2022-08-31 15:55:00 +0100 | [diff] [blame] | 379 | void *p_rng, const unsigned char *msg, size_t msg_size, |
| 380 | unsigned char *sig, size_t sig_size, size_t* sig_len ); |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 381 | |
Raef Coles | ab4f874 | 2022-09-01 12:24:31 +0100 | [diff] [blame^] | 382 | #endif /* MBEDTLS_LMS_PRIVATE */ |
Raef Coles | 8ff6df5 | 2021-07-21 12:42:15 +0100 | [diff] [blame] | 383 | |
| 384 | #ifdef __cplusplus |
| 385 | } |
| 386 | #endif |
| 387 | |
| 388 | #endif /* MBEDTLS_LMOTS_H */ |