Software APIs
ecc.h
Go to the documentation of this file.
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_ECC_H_
6 #define OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_ECC_H_
7 
8 #include "datatypes.h"
9 
10 /**
11  * @file
12  * @brief Elliptic curve operations for OpenTitan cryptography library.
13  *
14  * Includes ECDSA, ECDH, Ed25519, and X25519.
15  */
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif // __cplusplus
20 
21 /**
22  * Enum to define EdDSA mode for signature.
23  *
24  * Values are hardened.
25  */
27  // Signature mode EdDSA.
28  kOtcryptoEddsaSignModeEddsa = 0xae1,
29  // Signature mode Hashed EdDSA.
30  kOtcryptoEddsaSignModeHashEddsa = 0x9a6,
32 
33 /**
34  * Struct for domain parameters of a custom Weierstrass curve.
35  */
36 typedef struct otcrypto_ecc_domain {
37  // Prime P (modulus of coordinate finite field).
39  // Coefficient a.
41  // Coefficient b.
43  // q (order of G).
45  // Value of x coordinate of G (basepoint). Same length as p.
46  const uint32_t *gx;
47  // Value of y coordinate of G (basepoint). Same length as p.
48  const uint32_t *gy;
49  // Cofactor of the curve.
50  const uint32_t cofactor;
51  // Checksum value of the parameters.
52  uint32_t checksum;
54 
55 /**
56  * Enum to define the type of elliptic curve used for the operation.
57  *
58  * Values are hardened.
59  */
61  // Generic Weierstrass curve, with custom domain parameters.
62  kOtcryptoEccCurveTypeCustom = 0xbf7,
63  // Named Weierstrass curve - NIST P256.
64  kOtcryptoEccCurveTypeNistP256 = 0xec8,
65  // Named Weierstrass curve - NIST P384.
66  kOtcryptoEccCurveTypeNistP384 = 0x1bc,
67  // Named Weierstrass curve - Brainpool P256r1.
68  kEccCurveTypeBrainpoolP256R1 = 0xc1e,
70 
71 /**
72  * Struct for ECC curve used for ECDSA / ECDH operation.
73  *
74  * Values are hardened.
75  */
76 typedef struct otcrypto_ecc_curve {
77  // Type of the Weierstrass curve, custom curve or named curve.
78  otcrypto_ecc_curve_type_t curve_type;
79  // Domain parameters for a custom Weierstrass curve. May be NULL for a named
80  // curve.
81  const otcrypto_ecc_domain_t *const domain_parameter;
83 
84 /**
85  * Performs the key generation for ECDSA operation.
86  *
87  * Computes private key (d) and public key (Q) keys for ECDSA operation.
88  *
89  * The caller should allocate and partially populate the blinded key struct,
90  * including populating the key configuration and allocating space for the
91  * keyblob. The caller should indicate the length of the allocated keyblob;
92  * this function will return an error if the keyblob length does not match
93  * expectations. If the key is hardware-backed, the caller should pass a fully
94  * populated private key handle as returned by `otcrypto_hw_backed_key`. For
95  * non-hardware-backed keys, the keyblob should be twice the length of the key.
96  * The value in the `checksum` field of the blinded key struct will be
97  * populated by the key generation function.
98  *
99  * The `domain_parameter` field of the `elliptic_curve` is required only for a
100  * custom curve. For named curves this field is ignored and can be set to
101  * `NULL`.
102  *
103  * @param elliptic_curve Pointer to the elliptic curve to be used.
104  * @param[out] private_key Pointer to the blinded private key (d) struct.
105  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
106  * @return Result of the ECDSA key generation.
107  */
110  const otcrypto_ecc_curve_t *elliptic_curve,
111  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
112 
113 /**
114  * Performs the ECDSA digital signature generation.
115  *
116  * The `domain_parameter` field of the `elliptic_curve` is required
117  * only for a custom curve. For named curves this field is ignored
118  * and can be set to `NULL`.
119  *
120  * The message digest must be exactly the right length for the curve in use
121  * (e.g. 256 bits for P-256), but may use any hash mode. The caller is
122  * responsible for ensuring that the security strength of the hash function is
123  * at least equal to the security strength of the curve. See FIPS 186-5 for
124  * details.
125  *
126  * @param private_key Pointer to the blinded private key (d) struct.
127  * @param message_digest Message digest to be signed (pre-hashed).
128  * @param elliptic_curve Pointer to the elliptic curve to be used.
129  * @param[out] signature Pointer to the signature struct with (r,s) values.
130  * @return Result of the ECDSA signature generation.
131  */
134  const otcrypto_blinded_key_t *private_key,
135  const otcrypto_hash_digest_t message_digest,
136  const otcrypto_ecc_curve_t *elliptic_curve,
137  otcrypto_word32_buf_t signature);
138 
139 /**
140  * Performs the ECDSA digital signature verification.
141  *
142  * The `domain_parameter` field of the `elliptic_curve` is required
143  * only for a custom curve. For named curves this field is ignored
144  * and can be set to `NULL`.
145  *
146  * The message digest must be exactly the right length for the curve in use
147  * (e.g. 256 bits for P-256), but may use any hash mode. The caller is
148  * responsible for ensuring that the security strength of the hash function is
149  * at least equal to the security strength of the curve. See FIPS 186-5 for
150  * details.
151  *
152  * @param public_key Pointer to the unblinded public key (Q) struct.
153  * @param message_digest Message digest to be verified (pre-hashed).
154  * @param signature Pointer to the signature to be verified.
155  * @param elliptic_curve Pointer to the elliptic curve to be used.
156  * @param[out] verification_result Result of signature verification
157  * (Pass/Fail).
158  * @return Result of the ECDSA verification operation.
159  */
162  const otcrypto_unblinded_key_t *public_key,
163  const otcrypto_hash_digest_t message_digest,
164  otcrypto_const_word32_buf_t signature,
165  const otcrypto_ecc_curve_t *elliptic_curve,
166  hardened_bool_t *verification_result);
167 
168 /**
169  * Performs the key generation for ECDH key agreement.
170  *
171  * Computes private key (d) and public key (Q) keys for ECDSA operation.
172  *
173  * The `domain_parameter` field of the `elliptic_curve` is required only for a
174  * custom curve. For named curves this field is ignored and can be set to
175  * `NULL`.
176  *
177  * The caller should allocate and partially populate the blinded key struct,
178  * including populating the key configuration and allocating space for the
179  * keyblob. The caller should indicate the length of the allocated keyblob;
180  * this function will return an error if the keyblob length does not match
181  * expectations. If the key is hardware-backed, the caller should pass a fully
182  * populated private key handle as returned by `otcrypto_hw_backed_key`. For
183  * non-hardware-backed keys, the keyblob should be twice the length of the key.
184  * The value in the `checksum` field of the blinded key struct will be
185  * populated by the key generation function.
186  *
187  * @param elliptic_curve Pointer to the elliptic curve to be used.
188  * @param[out] private_key Pointer to the blinded private key (d) struct.
189  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
190  * @return Result of the ECDH key generation.
191  */
194  const otcrypto_ecc_curve_t *elliptic_curve,
195  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
196 
197 /**
198  * Performs Elliptic Curve Diffie Hellman shared secret generation.
199  *
200  * The `domain_parameter` field of the `elliptic_curve` is required
201  * only for a custom curve. For named curves this field is ignored
202  * and can be set to `NULL`.
203  *
204  * @param private_key Pointer to the blinded private key (d) struct.
205  * @param public_key Pointer to the unblinded public key (Q) struct.
206  * @param elliptic_curve Pointer to the elliptic curve to be used.
207  * @param[out] shared_secret Pointer to generated blinded shared key struct.
208  * @return Result of ECDH shared secret generation.
209  */
212  const otcrypto_unblinded_key_t *public_key,
213  const otcrypto_ecc_curve_t *elliptic_curve,
214  otcrypto_blinded_key_t *shared_secret);
215 
216 /**
217  * Generates a new Ed25519 key pair.
218  *
219  * Computes the private exponent (d) and public key (Q) based on
220  * Curve25519.
221  *
222  * No `domain_parameter` is needed and is automatically set for Ed25519.
223  *
224  * The caller should allocate and partially populate the blinded key struct,
225  * including populating the key configuration and allocating space for the
226  * keyblob. The caller should indicate the length of the allocated keyblob;
227  * this function will return an error if the keyblob length does not match
228  * expectations. If the key is hardware-backed, the caller should pass a fully
229  * populated private key handle as returned by `otcrypto_hw_backed_key`. For
230  * non-hardware-backed keys, the keyblob should be twice the length of the key.
231  * The value in the `checksum` field of the blinded key struct will be
232  * populated by the key generation function.
233  *
234  * @param[out] private_key Pointer to the blinded private key struct.
235  * @param[out] public_key Pointer to the unblinded public key struct.
236  * @return Result of the Ed25519 key generation.
237  */
240  otcrypto_unblinded_key_t *public_key);
241 
242 /**
243  * Generates an Ed25519 digital signature.
244  *
245  * @param private_key Pointer to the blinded private key struct.
246  * @param input_message Input message to be signed.
247  * @param sign_mode Parameter for EdDSA or Hash EdDSA sign mode.
248  * @param[out] signature Pointer to the EdDSA signature with (r,s) values.
249  * @return Result of the EdDSA signature generation.
250  */
253  const otcrypto_blinded_key_t *private_key,
254  otcrypto_const_byte_buf_t input_message,
256 
257 /**
258  * Verifies an Ed25519 signature.
259  *
260  * @param public_key Pointer to the unblinded public key struct.
261  * @param input_message Input message to be signed for verification.
262  * @param sign_mode Parameter for EdDSA or Hash EdDSA sign mode.
263  * @param signature Pointer to the signature to be verified.
264  * @param[out] verification_result Result of signature verification
265  * (Pass/Fail).
266  * @return Result of the EdDSA verification operation.
267  */
270  const otcrypto_unblinded_key_t *public_key,
271  otcrypto_const_byte_buf_t input_message,
273  hardened_bool_t *verification_result);
274 
275 /**
276  * Generates a new key pair for X25519 key exchange.
277  *
278  * Computes the private scalar (d) and public key (Q) based on
279  * Curve25519.
280  *
281  * No `domain_parameter` is needed and is automatically set for X25519.
282  *
283  * The caller should allocate and partially populate the blinded key struct,
284  * including populating the key configuration and allocating space for the
285  * keyblob. The caller should indicate the length of the allocated keyblob;
286  * this function will return an error if the keyblob length does not match
287  * expectations. If the key is hardware-backed, the caller should pass a fully
288  * populated private key handle as returned by `otcrypto_hw_backed_key`. For
289  * non-hardware-backed keys, the keyblob should be twice the length of the key.
290  * The value in the `checksum` field of the blinded key struct will be
291  * populated by the key generation function.
292  *
293  * @param[out] private_key Pointer to the blinded private key struct.
294  * @param[out] public_key Pointer to the unblinded public key struct.
295  * @return Result of the X25519 key generation.
296  */
299  otcrypto_unblinded_key_t *public_key);
300 
301 /**
302  * Performs the X25519 Diffie Hellman shared secret generation.
303  *
304  * @param private_key Pointer to blinded private key (u-coordinate).
305  * @param public_key Pointer to the public scalar from the sender.
306  * @param[out] shared_secret Pointer to shared secret key (u-coordinate).
307  * @return Result of the X25519 operation.
308  */
311  const otcrypto_unblinded_key_t *public_key,
312  otcrypto_blinded_key_t *shared_secret);
313 
314 /**
315  * Starts the asynchronous key generation for ECDSA operation.
316  *
317  * Initializes OTBN and begins generating an ECDSA key pair. The caller should
318  * set the `config` field of `private_key` with their desired key configuration
319  * options. If the key is hardware-backed, the caller should pass a fully
320  * populated private key handle such as the kind returned by
321  * `otcrypto_hw_backed_key`.
322  *
323  * The `domain_parameter` field of the `elliptic_curve` is required
324  * only for a custom curve. For named curves this field is ignored
325  * and can be set to `NULL`.
326  *
327  * Returns `kOtcryptoStatusValueOk` if the operation was successfully
328  * started, or`kOtcryptoStatusValueInternalError` if the operation cannot be
329  * started.
330  *
331  * @param elliptic_curve Pointer to the elliptic curve to be used.
332  * @param private_key Destination structure for private key, or key handle.
333  * @return Result of asynchronous ECDSA keygen start operation.
334  */
337  const otcrypto_ecc_curve_t *elliptic_curve,
338  const otcrypto_blinded_key_t *private_key);
339 
340 /**
341  * Finalizes the asynchronous key generation for ECDSA operation.
342  *
343  * Returns `kOtcryptoStatusValueOk` and copies the private key (d) and public
344  * key (Q), if the OTBN status is done, or
345  * `kOtcryptoStatusValueAsyncIncomplete` if the OTBN is busy or
346  * `kOtcryptoStatusValueInternalError` if there is an error.
347  *
348  * The caller must ensure that the `elliptic_curve` parameter matches the one
349  * that was previously passed to the corresponding `_start` function; a
350  * mismatch will cause inconsistencies. Similarly, the private key
351  * configuration must match the one originally passed to `_start`.
352  *
353  * @param elliptic_curve Pointer to the elliptic curve that is being used.
354  * @param[out] private_key Pointer to the blinded private key (d) struct.
355  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
356  * @return Result of asynchronous ECDSA keygen finalize operation.
357  */
360  const otcrypto_ecc_curve_t *elliptic_curve,
361  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
362 
363 /**
364  * Starts the asynchronous ECDSA digital signature generation.
365  *
366  * Initializes OTBN and starts the OTBN routine to compute the digital
367  * signature on the input message. The `domain_parameter` field of the
368  * `elliptic_curve` is required only for a custom curve. For named
369  * curves this field is ignored and can be set to `NULL`.
370  *
371  * @param private_key Pointer to the blinded private key (d) struct.
372  * @param message_digest Message digest to be signed (pre-hashed).
373  * @param elliptic_curve Pointer to the elliptic curve to be used.
374  * @return Result of async ECDSA start operation.
375  */
378  const otcrypto_blinded_key_t *private_key,
379  const otcrypto_hash_digest_t message_digest,
380  const otcrypto_ecc_curve_t *elliptic_curve);
381 
382 /**
383  * Finalizes the asynchronous ECDSA digital signature generation.
384  *
385  * Returns `kOtcryptoStatusValueOk` and copies the signature if the OTBN
386  * status is done, or `kOtcryptoStatusValueAsyncIncomplete` if the OTBN is
387  * busy or `kOtcryptoStatusValueInternalError` if there is an error.
388  *
389  * The caller must ensure that the `elliptic_curve` parameter matches the one
390  * that was previously passed to the corresponding `_start` function; a
391  * mismatch will cause inconsistencies.
392  *
393  * @param elliptic_curve Pointer to the elliptic curve that is being used.
394  * @param[out] signature Pointer to the signature struct with (r,s) values.
395  * @return Result of async ECDSA finalize operation.
396  */
399  const otcrypto_ecc_curve_t *elliptic_curve,
400  otcrypto_word32_buf_t signature);
401 
402 /**
403  * Starts the asynchronous ECDSA digital signature verification.
404  *
405  * Initializes OTBN and starts the OTBN routine to recover ‘r’ value
406  * from the input signature ‘s’ value. The `domain_parameter` field of
407  * `elliptic_curve` is required only for a custom curve. For named
408  * curves this field is ignored and can be set to `NULL`.
409  *
410  * @param public_key Pointer to the unblinded public key (Q) struct.
411  * @param message_digest Message digest to be verified (pre-hashed).
412  * @param signature Pointer to the signature to be verified.
413  * @param elliptic_curve Pointer to the elliptic curve to be used.
414  * @return Result of async ECDSA verify start function.
415  */
418  const otcrypto_unblinded_key_t *public_key,
419  const otcrypto_hash_digest_t message_digest,
420  otcrypto_const_word32_buf_t signature,
421  const otcrypto_ecc_curve_t *elliptic_curve);
422 
423 /**
424  * Finalizes the asynchronous ECDSA digital signature verification.
425  *
426  * Returns `kOtcryptoStatusValueOk` and populates the `verification result`
427  * if the OTBN status is done. `kOtcryptoStatusValueAsyncIncomplete` if the
428  * OTBN is busy or `kOtcryptoStatusValueInternalError` if there is an error.
429  * The computed signature is compared against the input signature
430  * and a PASS or FAIL is returned.
431  *
432  * The caller must ensure that the `elliptic_curve` and `signature` parameters
433  * matches the ones that were previously passed to the corresponding `_start`
434  * function; a mismatch will cause inconsistencies.
435  *
436  * @param elliptic_curve Pointer to the elliptic curve that is being used.
437  * @param[out] verification_result Result of signature verification
438  * (Pass/Fail).
439  * @return Result of async ECDSA verify finalize operation.
440  */
443  const otcrypto_ecc_curve_t *elliptic_curve,
444  otcrypto_const_word32_buf_t signature,
445  hardened_bool_t *verification_result);
446 
447 /**
448  * Starts the asynchronous key generation for ECDH operation.
449  *
450  * Initializes OTBN and begins generating an ECDH key pair. The caller should
451  * set the `config` field of `private_key` with their desired key configuration
452  * options. If the key is hardware-backed, the caller should pass a fully
453  * populated private key handle such as the kind returned by
454  * `otcrypto_hw_backed_key`.
455  *
456  * The `domain_parameter` field of the `elliptic_curve` is required
457  * only for a custom curve. For named curves this field is ignored
458  * and can be set to `NULL`.
459  *
460  * Returns `kOtcryptoStatusValueOk` if the operation was successfully
461  * started, or`kOtcryptoStatusValueInternalError` if the operation cannot be
462  * started.
463  *
464  * @param elliptic_curve Pointer to the elliptic curve to be used.
465  * @param private_key Destination structure for private key, or key handle.
466  * @return Result of asynchronous ECDH keygen start operation.
467  */
470  const otcrypto_ecc_curve_t *elliptic_curve,
471  const otcrypto_blinded_key_t *private_key);
472 
473 /**
474  * Finalizes the asynchronous key generation for ECDSA operation.
475  *
476  * Returns `kOtcryptoStatusValueOk` and copies the private key (d) and public
477  * key (Q), if the OTBN status is done, or
478  * `kOtcryptoStatusValueAsyncIncomplete` if the OTBN is busy or
479  * `kOtcryptoStatusValueInternalError` if there is an error.
480  *
481  * The caller must ensure that the `elliptic_curve` parameter matches the one
482  * that was previously passed to the corresponding `_start` function; a
483  * mismatch will cause inconsistencies. Similarly, the private key
484  * configuration must match the one originally passed to `_start`.
485  *
486  * @param elliptic_curve Pointer to the elliptic curve that is being used.
487  * @param[out] private_key Pointer to the blinded private key (d) struct.
488  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
489  * @return Result of asynchronous ECDH keygen finalize operation.
490  */
493  const otcrypto_ecc_curve_t *elliptic_curve,
494  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
495 
496 /**
497  * Starts the asynchronous Elliptic Curve Diffie Hellman shared
498  * secret generation.
499  *
500  * The `domain_parameter` field of the `elliptic_curve` is required
501  * only for a custom curve. For named curves this field is ignored
502  * and can be set to `NULL`.
503  *
504  * @param private_key Pointer to the blinded private key (d) struct.
505  * @param public_key Pointer to the unblinded public key (Q) struct.
506  * @param elliptic_curve Pointer to the elliptic curve to be used.
507  * @return Result of async ECDH start operation.
508  */
511  const otcrypto_blinded_key_t *private_key,
512  const otcrypto_unblinded_key_t *public_key,
513  const otcrypto_ecc_curve_t *elliptic_curve);
514 
515 /**
516  * Finalizes the asynchronous Elliptic Curve Diffie Hellman shared
517  * secret generation.
518  *
519  * Returns `kOtcryptoStatusValueOk` and copies `shared_secret` if the OTBN
520  * status is done, or `kOtcryptoStatusValueAsyncIncomplete` if the OTBN
521  * is busy or `kOtcryptoStatusValueInternalError` if there is an error.
522  *
523  * The caller must ensure that the `elliptic_curve` parameter matches the one
524  * that was previously passed to the corresponding `_start` function; a
525  * mismatch will cause inconsistencies.
526  *
527  * @param elliptic_curve Pointer to the elliptic curve that is being used.
528  * @param[out] shared_secret Pointer to generated blinded shared key struct.
529  * @return Result of async ECDH finalize operation.
530  */
533  const otcrypto_ecc_curve_t *elliptic_curve,
534  otcrypto_blinded_key_t *shared_secret);
535 
536 /**
537  * Starts the asynchronous key generation for Ed25519.
538  *
539  * Initializes OTBN and begins generating an Ed25519 key pair. The caller
540  * should set the `config` field of `private_key` with their desired key
541  * configuration options. If the key is hardware-backed, the caller should pass
542  * a fully populated private key handle such as the kind returned by
543  * `otcrypto_hw_backed_key`.
544  *
545  * No `domain_parameter` is needed and is automatically set for X25519.
546  *
547  * @param private_key Destination structure for private key, or key handle.
548  * @return Result of asynchronous ed25519 keygen start operation.
549  */
552  const otcrypto_blinded_key_t *private_key);
553 
554 /**
555  * Finalizes the asynchronous key generation for Ed25519.
556  *
557  * Returns `kOtcryptoStatusValueOk` and copies private key (d) and public key
558  * (Q), if the OTBN status is done, or `kOtcryptoStatusValueAsyncIncomplete`
559  * if the OTBN is busy or `kOtcryptoStatusValueInternalError` if there is an
560  * error.
561  *
562  * The caller must ensure that `config` matches the key configuration initially
563  * passed to the `_start` complement of this function.
564  *
565  * @param[out] private_key Pointer to the blinded private key struct.
566  * @param[out] public_key Pointer to the unblinded public key struct.
567  * @return Result of asynchronous ed25519 keygen finalize operation.
568  */
571  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
572 
573 /**
574  * Starts the asynchronous Ed25519 digital signature generation.
575  *
576  * Initializes OTBN and starts the OTBN routine to compute the digital
577  * signature on the input message. The `domain_parameter` field for
578  * Ed25519 is automatically set.
579  *
580  * @param private_key Pointer to the blinded private key struct.
581  * @param input_message Input message to be signed.
582  * @param sign_mode Parameter for EdDSA or Hash EdDSA sign mode.
583  * @param[out] signature Pointer to the EdDSA signature to get (r) value.
584  * @return Result of async Ed25519 start operation.
585  */
588  const otcrypto_blinded_key_t *private_key,
589  otcrypto_const_byte_buf_t input_message,
591 
592 /**
593  * Finalizes the asynchronous Ed25519 digital signature generation.
594  *
595  * Returns `kOtcryptoStatusValueOk` and copies the signature if the OTBN
596  * status is done, or `kOtcryptoStatusValueAsyncIncomplete` if the OTBN is
597  * busy or `kOtcryptoStatusValueInternalError` if there is an error.
598  *
599  * @param[out] signature Pointer to the EdDSA signature to get (s) value.
600  * @return Result of async Ed25519 finalize operation.
601  */
604  otcrypto_word32_buf_t signature);
605 
606 /**
607  * Starts the asynchronous Ed25519 digital signature verification.
608  *
609  * Initializes OTBN and starts the OTBN routine to verify the
610  * signature. The `domain_parameter` for Ed25519 is set automatically.
611  *
612  * @param public_key Pointer to the unblinded public key struct.
613  * @param input_message Input message to be signed for verification.
614  * @param sign_mode Parameter for EdDSA or Hash EdDSA sign mode.
615  * @param signature Pointer to the signature to be verified.
616  * @return Result of async Ed25519 verification start operation.
617  */
620  const otcrypto_unblinded_key_t *public_key,
621  otcrypto_const_byte_buf_t input_message,
622  otcrypto_eddsa_sign_mode_t sign_mode,
623  otcrypto_const_word32_buf_t signature);
624 
625 /**
626  * Finalizes the asynchronous Ed25519 digital signature verification.
627  *
628  * Returns `kOtcryptoStatusValueOk` and populates the `verification result`
629  * with a PASS or FAIL, if the OTBN status is done,
630  * `kOtcryptoStatusValueAsyncIncomplete` if the OTBN is busy or
631  * `kOtcryptoStatusValueInternalError` if there is an error.
632  *
633  * @param[out] verification_result Result of signature verification
634  * (Pass/Fail).
635  * @return Result of async Ed25519 verification finalize operation.
636  */
639  hardened_bool_t *verification_result);
640 
641 /**
642  * Starts the asynchronous key generation for X25519.
643  *
644  * Initializes OTBN and begins generating an X25519 key pair. The caller
645  * should set the `config` field of `private_key` with their desired key
646  * configuration options. If the key is hardware-backed, the caller should pass
647  * a fully populated private key handle such as the kind returned by
648  * `otcrypto_hw_backed_key`.
649  *
650  * No `domain_parameter` is needed and is automatically set for X25519.
651  *
652  * @param private_key Destination structure for private key, or key handle.
653  * @return Result of asynchronous X25519 keygen start operation.
654  */
657  const otcrypto_blinded_key_t *private_key);
658 
659 /**
660  * Finalizes the asynchronous key generation for X25519.
661  *
662  * Returns `kOtcryptoStatusValueOk` and copies private key (d) and public key
663  * (Q), if the OTBN status is done, or `kOtcryptoStatusValueAsyncIncomplete`
664  * if the OTBN is busy or `kOtcryptoStatusValueInternalError` if there is an
665  * error.
666  *
667  * The caller must ensure that `config` matches the key configuration initially
668  * passed to the `_start` complement of this function.
669  *
670  * @param[out] private_key Pointer to the blinded private key struct.
671  * @param[out] public_key Pointer to the unblinded public key struct.
672  * @return Result of asynchronous X25519 keygen finalize operation.
673  */
676  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
677 
678 /**
679  * Starts the asynchronous X25519 Diffie Hellman shared secret
680  * generation.
681  *
682  * Initializes OTBN and starts the OTBN routine to perform Diffie
683  * Hellman shared secret generation based on Curve25519. The
684  * domain parameter is automatically set for X25519 API.
685  *
686  * @param private_key Pointer to the blinded private key (u-coordinate).
687  * @param public_key Pointer to the public scalar from the sender.
688  * @return Result of the async X25519 start operation.
689  */
692  const otcrypto_blinded_key_t *private_key,
693  const otcrypto_unblinded_key_t *public_key);
694 
695 /**
696  * Finalizes the asynchronous X25519 Diffie Hellman shared secret
697  * generation.
698  *
699  * Returns `kOtcryptoStatusValueOk` and copies `shared_secret` if the OTBN
700  * status is done, or `kOtcryptoStatusValueAsyncIncomplete` if the OTBN
701  * is busy or `kOtcryptoStatusValueInternalError` if there is an error.
702  *
703  * @param[out] shared_secret Pointer to shared secret key (u-coordinate).
704  * @return Result of async X25519 finalize operation.
705  */
708  otcrypto_blinded_key_t *shared_secret);
709 
710 #ifdef __cplusplus
711 } // extern "C"
712 #endif // __cplusplus
713 
714 #endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_ECC_H_