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  * Generates a key pair for ECDSA with curve P-256.
35  *
36  * The caller should allocate and partially populate the blinded key struct,
37  * including populating the key configuration and allocating space for the
38  * keyblob. For a hardware-backed key, use the private key handle returned by
39  * `otcrypto_hw_backed_key`. Otherwise, the mode should indicate ECDSA with
40  * P-256 and the keyblob should be 80 bytes. The value in the `checksum` field
41  * of the blinded key struct will be populated by the key generation function.
42  *
43  * @param[out] private_key Pointer to the blinded private key (d) struct.
44  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
45  * @return Result of the ECDSA key generation.
46  */
49  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
50 
51 /**
52  * Generates a key pair for ECDSA with curve P-384.
53  *
54  * The caller should allocate and partially populate the blinded key struct,
55  * including populating the key configuration and allocating space for the
56  * keyblob. For a hardware-backed key, use the private key handle returned by
57  * `otcrypto_hw_backed_key`. Otherwise, the mode should indicate ECDSA with
58  * P-384 and the keyblob should be 112 bytes. The value in the `checksum` field
59  * of the blinded key struct will be populated by the key generation function.
60  *
61  * @param[out] private_key Pointer to the blinded private key (d) struct.
62  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
63  * @return Result of the ECDSA key generation.
64  */
67  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
68 
69 /**
70  * Generates an ECDSA signature with curve P-256.
71  *
72  * The message digest must be exactly 256 bits (32 bytes) long, but may use any
73  * hash mode. The caller is responsible for ensuring that the security
74  * strength of the hash function is at least equal to the security strength of
75  * the curve, but in some cases it may be truncated. See FIPS 186-5 for
76  * details.
77  *
78  * @param private_key Pointer to the blinded private key (d) struct.
79  * @param message_digest Message digest to be signed (pre-hashed).
80  * @param[out] signature Pointer to the signature struct with (r,s) values.
81  * @return Result of the ECDSA signature generation.
82  */
85  const otcrypto_blinded_key_t *private_key,
86  const otcrypto_hash_digest_t message_digest,
87  otcrypto_word32_buf_t signature);
88 
89 /**
90  * Generates an ECDSA signature with curve P-384.
91 
92  * The message digest must be exactly 384 bits (48 bytes) long, but may use any
93  * hash mode. The caller is responsible for ensuring that the security
94  * strength of the hash function is at least equal to the security strength of
95  * the curve, but in some cases it may be truncated. See FIPS 186-5 for
96  * details.
97  *
98  * @param private_key Pointer to the blinded private key (d) struct.
99  * @param message_digest Message digest to be signed (pre-hashed).
100  * @param[out] signature Pointer to the signature struct with (r,s) values.
101  * @return Result of the ECDSA signature generation.
102  */
105  const otcrypto_blinded_key_t *private_key,
106  const otcrypto_hash_digest_t message_digest,
107  otcrypto_word32_buf_t signature);
108 
109 /**
110  * Verifies an ECDSA/P-256 signature.
111  *
112  * The message digest must be exactly 256 bits (32 bytes) long, but may use any
113  * hash mode. The caller is responsible for ensuring that the security
114  * strength of the hash function is at least equal to the security strength of
115  * the curve, but in some cases it may be truncated. See FIPS 186-5 for
116  * details.
117  *
118  * The caller must check the `verification_result` parameter, NOT only the
119  * returned status code, to know if the signature passed verification. The
120  * status code, as for other operations, only indicates whether errors were
121  * encountered, and may return OK even when the signature is invalid.
122  *
123  * @param public_key Pointer to the unblinded public key (Q) struct.
124  * @param message_digest Message digest to be verified (pre-hashed).
125  * @param signature Pointer to the signature to be verified.
126  * @param[out] verification_result Whether the signature passed verification.
127  * @return Result of the ECDSA verification operation.
128  */
131  const otcrypto_unblinded_key_t *public_key,
132  const otcrypto_hash_digest_t message_digest,
133  otcrypto_const_word32_buf_t signature,
134  hardened_bool_t *verification_result);
135 
136 /**
137  * Verifies an ECDSA/P-384 signature.
138  *
139  * The message digest must be exactly 384 bits (48 bytes) long, but may use any
140  * hash mode. The caller is responsible for ensuring that the security
141  * strength of the hash function is at least equal to the security strength of
142  * the curve, but in some cases it may be truncated. See FIPS 186-5 for
143  * details.
144  *
145  * The caller must check the `verification_result` parameter, NOT only the
146  * returned status code, to know if the signature passed verification. The
147  * status code, as for other operations, only indicates whether errors were
148  * encountered, and may return OK even when the signature is invalid.
149  *
150  * @param public_key Pointer to the unblinded public key (Q) struct.
151  * @param message_digest Message digest to be verified (pre-hashed).
152  * @param signature Pointer to the signature to be verified.
153  * @param[out] verification_result Whether the signature passed verification.
154  * @return Result of the ECDSA verification operation.
155  */
158  const otcrypto_unblinded_key_t *public_key,
159  const otcrypto_hash_digest_t message_digest,
160  otcrypto_const_word32_buf_t signature,
161  hardened_bool_t *verification_result);
162 
163 /**
164  * Generates a key pair for ECDH with curve P-256.
165  *
166  * The caller should allocate and partially populate the blinded key struct,
167  * including populating the key configuration and allocating space for the
168  * keyblob. For a hardware-backed key, use the private key handle returned by
169  * `otcrypto_hw_backed_key`. Otherwise, the mode should indicate ECDH with
170  * P-256 and the keyblob should be 80 bytes. The value in the `checksum` field
171  * of the blinded key struct will be populated by the key generation function.
172  *
173  * @param[out] private_key Pointer to the blinded private key (d) struct.
174  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
175  * @return Result of the ECDH key generation.
176  */
179  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
180 
181 /**
182  * Generates a key pair for ECDH with curve P-384.
183  *
184  * The caller should allocate and partially populate the blinded key struct,
185  * including populating the key configuration and allocating space for the
186  * keyblob. For a hardware-backed key, use the private key handle returned by
187  * `otcrypto_hw_backed_key`. Otherwise, the mode should indicate ECDH with
188  * P-384 and the keyblob should be 112 bytes. The value in the `checksum` field
189  * of the blinded key struct will be populated by the key generation function.
190  *
191  * @param[out] private_key Pointer to the blinded private key (d) struct.
192  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
193  * @return Result of the ECDH key generation.
194  */
197  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
198 
199 /**
200  * Elliptic Curve Diffie Hellman shared secret generation with curve P-256.
201  *
202  * @param private_key Pointer to the blinded private key (d) struct.
203  * @param public_key Pointer to the unblinded public key (Q) struct.
204  * @param[out] shared_secret Pointer to generated blinded shared key struct.
205  * @return Result of ECDH shared secret generation.
206  */
209  const otcrypto_unblinded_key_t *public_key,
210  otcrypto_blinded_key_t *shared_secret);
211 
212 /**
213  * Elliptic Curve Diffie Hellman shared secret generation with curve P-384.
214  *
215  * @param private_key Pointer to the blinded private key (d) struct.
216  * @param public_key Pointer to the unblinded public key (Q) struct.
217  * @param[out] shared_secret Pointer to generated blinded shared key struct.
218  * @return Result of ECDH shared secret generation.
219  */
222  const otcrypto_unblinded_key_t *public_key,
223  otcrypto_blinded_key_t *shared_secret);
224 
225 /**
226  * Generates a new Ed25519 key pair.
227  *
228  * Computes the private exponent (d) and public key (Q) based on
229  * Curve25519.
230  *
231  * No `domain_parameter` is needed and is automatically set for Ed25519.
232  *
233  * The caller should allocate and partially populate the blinded key struct,
234  * including populating the key configuration and allocating space for the
235  * keyblob. The caller should indicate the length of the allocated keyblob;
236  * this function will return an error if the keyblob length does not match
237  * expectations. If the key is hardware-backed, the caller should pass a fully
238  * populated private key handle as returned by `otcrypto_hw_backed_key`. For
239  * non-hardware-backed keys, the keyblob should be twice the length of the key.
240  * The value in the `checksum` field of the blinded key struct will be
241  * populated by the key generation function.
242  *
243  * @param[out] private_key Pointer to the blinded private key struct.
244  * @param[out] public_key Pointer to the unblinded public key struct.
245  * @return Result of the Ed25519 key generation.
246  */
249  otcrypto_unblinded_key_t *public_key);
250 
251 /**
252  * Generates an Ed25519 digital signature.
253  *
254  * @param private_key Pointer to the blinded private key struct.
255  * @param input_message Input message to be signed.
256  * @param sign_mode Parameter for EdDSA or Hash EdDSA sign mode.
257  * @param[out] signature Pointer to the EdDSA signature with (r,s) values.
258  * @return Result of the EdDSA signature generation.
259  */
262  const otcrypto_blinded_key_t *private_key,
263  otcrypto_const_byte_buf_t input_message,
265 
266 /**
267  * Verifies an Ed25519 signature.
268  *
269  * @param public_key Pointer to the unblinded public key struct.
270  * @param input_message Input message to be signed for verification.
271  * @param sign_mode Parameter for EdDSA or Hash EdDSA sign mode.
272  * @param signature Pointer to the signature to be verified.
273  * @param[out] verification_result Result of signature verification
274  * (Pass/Fail).
275  * @return Result of the EdDSA verification operation.
276  */
279  const otcrypto_unblinded_key_t *public_key,
280  otcrypto_const_byte_buf_t input_message,
282  hardened_bool_t *verification_result);
283 
284 /**
285  * Generates a new key pair for X25519 key exchange.
286  *
287  * Computes the private scalar (d) and public key (Q) based on
288  * Curve25519.
289  *
290  * No `domain_parameter` is needed and is automatically set for X25519.
291  *
292  * The caller should allocate and partially populate the blinded key struct,
293  * including populating the key configuration and allocating space for the
294  * keyblob. The caller should indicate the length of the allocated keyblob;
295  * this function will return an error if the keyblob length does not match
296  * expectations. If the key is hardware-backed, the caller should pass a fully
297  * populated private key handle as returned by `otcrypto_hw_backed_key`. For
298  * non-hardware-backed keys, the keyblob should be twice the length of the key.
299  * The value in the `checksum` field of the blinded key struct will be
300  * populated by the key generation function.
301  *
302  * @param[out] private_key Pointer to the blinded private key struct.
303  * @param[out] public_key Pointer to the unblinded public key struct.
304  * @return Result of the X25519 key generation.
305  */
308  otcrypto_unblinded_key_t *public_key);
309 
310 /**
311  * Performs the X25519 Diffie Hellman shared secret generation.
312  *
313  * @param private_key Pointer to blinded private key (u-coordinate).
314  * @param public_key Pointer to the public scalar from the sender.
315  * @param[out] shared_secret Pointer to shared secret key (u-coordinate).
316  * @return Result of the X25519 operation.
317  */
320  const otcrypto_unblinded_key_t *public_key,
321  otcrypto_blinded_key_t *shared_secret);
322 
323 /**
324  * Starts asynchronous key generation for ECDSA/P-256.
325  *
326  * See `otcrypto_ecdsa_p256_keygen` for requirements on input values.
327  *
328  * @param private_key Destination structure for private key, or key handle.
329  * @return Result of asynchronous ECDSA keygen start operation.
330  */
333  const otcrypto_blinded_key_t *private_key);
334 
335 /**
336  * Finalizes asynchronous key generation for ECDSA/P-256.
337  *
338  * See `otcrypto_ecdsa_p256_keygen` for requirements on input values.
339  *
340  * May block until the operation is complete.
341  *
342  * The caller should ensure that the private key configuration matches that
343  * passed to the `_start` function.
344  *
345  * @param[out] private_key Pointer to the blinded private key (d) struct.
346  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
347  * @return Result of asynchronous ECDSA keygen finalize operation.
348  */
351  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
352 
353 /**
354  * Starts asynchronous key generation for ECDSA/P-384.
355  *
356  * See `otcrypto_ecdsa_p384_keygen` for requirements on input values.
357  *
358  * @param private_key Destination structure for private key, or key handle.
359  * @return Result of asynchronous ECDSA keygen start operation.
360  */
363  const otcrypto_blinded_key_t *private_key);
364 
365 /**
366  * Finalizes asynchronous key generation for ECDSA/P-384.
367  *
368  * See `otcrypto_ecdsa_p384_keygen` for requirements on input values.
369  *
370  * May block until the operation is complete.
371  *
372  * The caller should ensure that the private key configuration matches that
373  * passed to the `_start` function.
374  *
375  * @param[out] private_key Pointer to the blinded private key (d) struct.
376  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
377  * @return Result of asynchronous ECDSA keygen finalize operation.
378  */
381  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
382 
383 /**
384  * Starts asynchronous signature generation for ECDSA/P-256.
385  *
386  * See `otcrypto_ecdsa_p256_sign` for requirements on input values.
387  *
388  * @param private_key Pointer to the blinded private key (d) struct.
389  * @param message_digest Message digest to be signed (pre-hashed).
390  * @param elliptic_curve Pointer to the elliptic curve to be used.
391  * @return Result of async ECDSA start operation.
392  */
395  const otcrypto_blinded_key_t *private_key,
396  const otcrypto_hash_digest_t message_digest);
397 
398 /**
399  * Finalizes asynchronous signature generation for ECDSA/P-256.
400  *
401  * See `otcrypto_ecdsa_p256_sign` for requirements on input values.
402  *
403  * May block until the operation is complete.
404  *
405  * @param[out] signature Pointer to the signature struct with (r,s) values.
406  * @return Result of async ECDSA finalize operation.
407  */
410  otcrypto_word32_buf_t signature);
411 
412 /**
413  * Starts asynchronous signature generation for ECDSA/P-384.
414  *
415  * See `otcrypto_ecdsa_p384_sign` for requirements on input values.
416  *
417  * @param private_key Pointer to the blinded private key (d) struct.
418  * @param message_digest Message digest to be signed (pre-hashed).
419  * @param elliptic_curve Pointer to the elliptic curve to be used.
420  * @return Result of async ECDSA start operation.
421  */
424  const otcrypto_blinded_key_t *private_key,
425  const otcrypto_hash_digest_t message_digest);
426 
427 /**
428  * Finalizes asynchronous signature generation for ECDSA/P-384.
429  *
430  * See `otcrypto_ecdsa_p384_sign` for requirements on input values.
431  *
432  * May block until the operation is complete.
433  *
434  * @param[out] signature Pointer to the signature struct with (r,s) values.
435  * @return Result of async ECDSA finalize operation.
436  */
439  otcrypto_word32_buf_t signature);
440 
441 /**
442  * Starts asynchronous signature verification for ECDSA/P-256.
443  *
444  * See `otcrypto_ecdsa_p256_verify` for requirements on input values.
445  *
446  * @param public_key Pointer to the unblinded public key (Q) struct.
447  * @param message_digest Message digest to be verified (pre-hashed).
448  * @param signature Pointer to the signature to be verified.
449  * @return Result of async ECDSA verify start function.
450  */
453  const otcrypto_unblinded_key_t *public_key,
454  const otcrypto_hash_digest_t message_digest,
455  otcrypto_const_word32_buf_t signature);
456 
457 /**
458  * Finalizes asynchronous signature verification for ECDSA/P-256.
459  *
460  * See `otcrypto_ecdsa_p256_verify` for requirements on input values.
461  *
462  * May block until the operation is complete.
463  *
464  * @param[out] verification_result Whether the signature passed verification.
465  * @return Result of async ECDSA verify finalize operation.
466  */
469  otcrypto_const_word32_buf_t signature,
470  hardened_bool_t *verification_result);
471 
472 /**
473  * Starts asynchronous signature verification for ECDSA/P-384.
474  *
475  * See `otcrypto_ecdsa_p384_verify` for requirements on input values.
476  *
477  * @param public_key Pointer to the unblinded public key (Q) struct.
478  * @param message_digest Message digest to be verified (pre-hashed).
479  * @param signature Pointer to the signature to be verified.
480  * @return Result of async ECDSA verify start function.
481  */
484  const otcrypto_unblinded_key_t *public_key,
485  const otcrypto_hash_digest_t message_digest,
486  otcrypto_const_word32_buf_t signature);
487 
488 /**
489  * Finalizes asynchronous signature verification for ECDSA/P-384.
490  *
491  * See `otcrypto_ecdsa_p384_verify` for requirements on input values.
492  *
493  * May block until the operation is complete.
494  *
495  * @param[out] verification_result Whether the signature passed verification.
496  * @return Result of async ECDSA verify finalize operation.
497  */
500  otcrypto_const_word32_buf_t signature,
501  hardened_bool_t *verification_result);
502 
503 /**
504  * Starts asynchronous key generation for ECDH/P-256.
505  *
506  * See `otcrypto_ecdh_p256_keygen` for requirements on input values.
507  *
508  * @param private_key Destination structure for private key, or key handle.
509  * @return Result of asynchronous ECDH keygen start operation.
510  */
513  const otcrypto_blinded_key_t *private_key);
514 
515 /**
516  * Finalizes asynchronous key generation for ECDH/P-256.
517  *
518  * See `otcrypto_ecdh_p256_keygen` for requirements on input values.
519  *
520  * May block until the operation is complete.
521  *
522  * The caller should ensure that the private key configuration matches that
523  * passed to the `_start` function.
524  *
525  * @param[out] private_key Pointer to the blinded private key (d) struct.
526  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
527  * @return Result of asynchronous ECDH keygen finalize operation.
528  */
531  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
532 
533 /**
534  * Starts asynchronous key generation for ECDH/P-384.
535  *
536  * See `otcrypto_ecdh_p384_keygen` for requirements on input values.
537  *
538  * @param private_key Destination structure for private key, or key handle.
539  * @return Result of asynchronous ECDH keygen start operation.
540  */
543  const otcrypto_blinded_key_t *private_key);
544 
545 /**
546  * Finalizes asynchronous key generation for ECDH/P-384.
547  *
548  * See `otcrypto_ecdh_p384_keygen` for requirements on input values.
549  *
550  * May block until the operation is complete.
551  *
552  * The caller should ensure that the private key configuration matches that
553  * passed to the `_start` function.
554  *
555  * @param[out] private_key Pointer to the blinded private key (d) struct.
556  * @param[out] public_key Pointer to the unblinded public key (Q) struct.
557  * @return Result of asynchronous ECDH keygen finalize operation.
558  */
561  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
562 
563 /**
564  * Starts asynchronous shared secret generation for ECDH/P-256.
565  *
566  * See `otcrypto_ecdh_p256` for requirements on input values.
567  *
568  * @param private_key Pointer to the blinded private key (d) struct.
569  * @param public_key Pointer to the unblinded public key (Q) struct.
570  * @return Result of async ECDH start operation.
571  */
574  const otcrypto_blinded_key_t *private_key,
575  const otcrypto_unblinded_key_t *public_key);
576 
577 /**
578  * Finalizes asynchronous shared secret generation for ECDH/P-256.
579  *
580  * See `otcrypto_ecdh_p256` for requirements on input values.
581  *
582  * May block until the operation is complete.
583  *
584  * @param[out] shared_secret Pointer to generated blinded shared key struct.
585  * @return Result of async ECDH finalize operation.
586  */
589  otcrypto_blinded_key_t *shared_secret);
590 
591 /**
592  * Starts asynchronous shared secret generation for ECDH/P-384.
593  *
594  * See `otcrypto_ecdh_p384` for requirements on input values.
595  *
596  * @param private_key Pointer to the blinded private key (d) struct.
597  * @param public_key Pointer to the unblinded public key (Q) struct.
598  * @return Result of async ECDH start operation.
599  */
602  const otcrypto_blinded_key_t *private_key,
603  const otcrypto_unblinded_key_t *public_key);
604 
605 /**
606  * Finalizes asynchronous shared secret generation for ECDH/P-384.
607  *
608  * See `otcrypto_ecdh_p384` for requirements on input values.
609  *
610  * May block until the operation is complete.
611  *
612  * @param[out] shared_secret Pointer to generated blinded shared key struct.
613  * @return Result of async ECDH finalize operation.
614  */
617  otcrypto_blinded_key_t *shared_secret);
618 
619 /**
620  * Starts the asynchronous key generation for Ed25519.
621  *
622  * Initializes OTBN and begins generating an Ed25519 key pair. The caller
623  * should set the `config` field of `private_key` with their desired key
624  * configuration options. If the key is hardware-backed, the caller should pass
625  * a fully populated private key handle such as the kind returned by
626  * `otcrypto_hw_backed_key`.
627  *
628  * No `domain_parameter` is needed and is automatically set for X25519.
629  *
630  * @param private_key Destination structure for private key, or key handle.
631  * @return Result of asynchronous ed25519 keygen start operation.
632  */
635  const otcrypto_blinded_key_t *private_key);
636 
637 /**
638  * Finalizes the asynchronous key generation for Ed25519.
639  *
640  * Returns `kOtcryptoStatusValueOk` and copies private key (d) and public key
641  * (Q), if the OTBN status is done, or `kOtcryptoStatusValueAsyncIncomplete`
642  * if the OTBN is busy or `kOtcryptoStatusValueInternalError` if there is an
643  * error.
644  *
645  * The caller must ensure that `config` matches the key configuration initially
646  * passed to the `_start` complement of this function.
647  *
648  * @param[out] private_key Pointer to the blinded private key struct.
649  * @param[out] public_key Pointer to the unblinded public key struct.
650  * @return Result of asynchronous ed25519 keygen finalize operation.
651  */
654  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
655 
656 /**
657  * Starts the asynchronous Ed25519 digital signature generation.
658  *
659  * Initializes OTBN and starts the OTBN routine to compute the digital
660  * signature on the input message. The `domain_parameter` field for
661  * Ed25519 is automatically set.
662  *
663  * @param private_key Pointer to the blinded private key struct.
664  * @param input_message Input message to be signed.
665  * @param sign_mode Parameter for EdDSA or Hash EdDSA sign mode.
666  * @param[out] signature Pointer to the EdDSA signature to get (r) value.
667  * @return Result of async Ed25519 start operation.
668  */
671  const otcrypto_blinded_key_t *private_key,
672  otcrypto_const_byte_buf_t input_message,
674 
675 /**
676  * Finalizes the asynchronous Ed25519 digital signature generation.
677  *
678  * Returns `kOtcryptoStatusValueOk` and copies the signature if the OTBN
679  * status is done, or `kOtcryptoStatusValueAsyncIncomplete` if the OTBN is
680  * busy or `kOtcryptoStatusValueInternalError` if there is an error.
681  *
682  * @param[out] signature Pointer to the EdDSA signature to get (s) value.
683  * @return Result of async Ed25519 finalize operation.
684  */
687  otcrypto_word32_buf_t signature);
688 
689 /**
690  * Starts the asynchronous Ed25519 digital signature verification.
691  *
692  * Initializes OTBN and starts the OTBN routine to verify the
693  * signature. The `domain_parameter` for Ed25519 is set automatically.
694  *
695  * @param public_key Pointer to the unblinded public key struct.
696  * @param input_message Input message to be signed for verification.
697  * @param sign_mode Parameter for EdDSA or Hash EdDSA sign mode.
698  * @param signature Pointer to the signature to be verified.
699  * @return Result of async Ed25519 verification start operation.
700  */
703  const otcrypto_unblinded_key_t *public_key,
704  otcrypto_const_byte_buf_t input_message,
705  otcrypto_eddsa_sign_mode_t sign_mode,
706  otcrypto_const_word32_buf_t signature);
707 
708 /**
709  * Finalizes the asynchronous Ed25519 digital signature verification.
710  *
711  * Returns `kOtcryptoStatusValueOk` and populates the `verification result`
712  * with a PASS or FAIL, if the OTBN status is done,
713  * `kOtcryptoStatusValueAsyncIncomplete` if the OTBN is busy or
714  * `kOtcryptoStatusValueInternalError` if there is an error.
715  *
716  * @param[out] verification_result Result of signature verification
717  * (Pass/Fail).
718  * @return Result of async Ed25519 verification finalize operation.
719  */
722  hardened_bool_t *verification_result);
723 
724 /**
725  * Starts the asynchronous key generation for X25519.
726  *
727  * Initializes OTBN and begins generating an X25519 key pair. The caller
728  * should set the `config` field of `private_key` with their desired key
729  * configuration options. If the key is hardware-backed, the caller should pass
730  * a fully populated private key handle such as the kind returned by
731  * `otcrypto_hw_backed_key`.
732  *
733  * No `domain_parameter` is needed and is automatically set for X25519.
734  *
735  * @param private_key Destination structure for private key, or key handle.
736  * @return Result of asynchronous X25519 keygen start operation.
737  */
740  const otcrypto_blinded_key_t *private_key);
741 
742 /**
743  * Finalizes the asynchronous key generation for X25519.
744  *
745  * Returns `kOtcryptoStatusValueOk` and copies private key (d) and public key
746  * (Q), if the OTBN status is done, or `kOtcryptoStatusValueAsyncIncomplete`
747  * if the OTBN is busy or `kOtcryptoStatusValueInternalError` if there is an
748  * error.
749  *
750  * The caller must ensure that `config` matches the key configuration initially
751  * passed to the `_start` complement of this function.
752  *
753  * @param[out] private_key Pointer to the blinded private key struct.
754  * @param[out] public_key Pointer to the unblinded public key struct.
755  * @return Result of asynchronous X25519 keygen finalize operation.
756  */
759  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
760 
761 /**
762  * Starts the asynchronous X25519 Diffie Hellman shared secret
763  * generation.
764  *
765  * Initializes OTBN and starts the OTBN routine to perform Diffie
766  * Hellman shared secret generation based on Curve25519. The
767  * domain parameter is automatically set for X25519 API.
768  *
769  * @param private_key Pointer to the blinded private key (u-coordinate).
770  * @param public_key Pointer to the public scalar from the sender.
771  * @return Result of the async X25519 start operation.
772  */
775  const otcrypto_blinded_key_t *private_key,
776  const otcrypto_unblinded_key_t *public_key);
777 
778 /**
779  * Finalizes the asynchronous X25519 Diffie Hellman shared secret
780  * generation.
781  *
782  * Returns `kOtcryptoStatusValueOk` and copies `shared_secret` if the OTBN
783  * status is done, or `kOtcryptoStatusValueAsyncIncomplete` if the OTBN
784  * is busy or `kOtcryptoStatusValueInternalError` if there is an error.
785  *
786  * @param[out] shared_secret Pointer to shared secret key (u-coordinate).
787  * @return Result of async X25519 finalize operation.
788  */
791  otcrypto_blinded_key_t *shared_secret);
792 
793 #ifdef __cplusplus
794 } // extern "C"
795 #endif // __cplusplus
796 
797 #endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_ECC_H_