Software APIs
x25519.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_X25519_H_
6 #define OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_X25519_H_
7 
8 #include "datatypes.h"
9 
10 /**
11  * @file
12  * @brief X25519 operations for OpenTitan cryptography library.
13  */
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif // __cplusplus
18 
19 /**
20  * Generates a key pair for X25519.
21  *
22  * The caller should allocate and partially populate the blinded key struct,
23  * including populating the key configuration and allocating space for the
24  * keyblob. For a hardware-backed key, use the private key handle returned by
25  * `otcrypto_hw_backed_key`. Otherwise, the mode should indicate X25519 and the
26  * keyblob should be 80 bytes. The value in the `checksum` field of the blinded
27  * key struct will be populated by the key generation function.
28  *
29  * @param[out] private_key Pointer to the blinded private key struct.
30  * @param[out] public_key Pointer to the unblinded public key struct.
31  * @return Result of the X25519 key generation.
32  */
35  otcrypto_unblinded_key_t *public_key);
36 
37 /**
38  * Elliptic-curve Diffie Hellman shared secret generation with Curve25519.
39  *
40  * @param private_key Pointer to blinded private key (u-coordinate).
41  * @param public_key Pointer to the public scalar from the sender.
42  * @param[out] shared_secret Pointer to shared secret key (u-coordinate).
43  * @return Result of the X25519 operation.
44  */
47  const otcrypto_unblinded_key_t *public_key,
48  otcrypto_blinded_key_t *shared_secret);
49 
50 /**
51  * Starts asynchronous key generation for X25519.
52  *
53  * See `otcrypto_x25519_keygen` for requirements on input values.
54  *
55  * @param private_key Destination structure for private key, or key handle.
56  * @return Result of asynchronous X25519 keygen start operation.
57  */
60  const otcrypto_blinded_key_t *private_key);
61 
62 /**
63  * Finalizes the asynchronous key generation for X25519.
64  *
65  * See `otcrypto_x25519_keygen` for requirements on input values.
66  *
67  * May block until the operation is complete.
68  *
69  * The caller should ensure that the private key configuration matches that
70  * passed to the `_start` function.
71  *
72  * @param[out] private_key Pointer to the blinded private key struct.
73  * @param[out] public_key Pointer to the unblinded public key struct.
74  * @return Result of asynchronous ECDSA keygen finalize operation.
75  */
78  otcrypto_blinded_key_t *private_key, otcrypto_unblinded_key_t *public_key);
79 
80 /**
81  * Starts asynchronous shared secret generation for X25519.
82  *
83  * See `otcrypto_x25519` for requirements on input values.
84  *
85  * @param private_key Pointer to the blinded private key (u-coordinate).
86  * @param public_key Pointer to the public scalar from the sender.
87  * @return Result of the async X25519 start operation.
88  */
91  const otcrypto_blinded_key_t *private_key,
92  const otcrypto_unblinded_key_t *public_key);
93 
94 /**
95  * Finalizes asynchronous shared secret generation for X25519.
96  *
97  * See `otcrypto_x25519` for requirements on input values.
98  *
99  * May block until the operation is complete.
100  *
101  * @param[out] shared_secret Pointer to shared secret key (u-coordinate).
102  * @return Result of async X25519 finalize operation.
103  */
106  otcrypto_blinded_key_t *shared_secret);
107 
108 #ifdef __cplusplus
109 } // extern "C"
110 #endif // __cplusplus
111 
112 #endif // OPENTITAN_SW_DEVICE_LIB_CRYPTO_INCLUDE_X25519_H_