Software APIs
nonce.h
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_SILICON_CREATOR_LIB_NONCE_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_NONCE_H_
7 
8 #include <stdbool.h>
9 #include <stdint.h>
10 
11 /**
12  * A nonce value used for challenge/response in boot services message.
13  */
14 typedef struct nonce {
15  uint32_t value[2];
16 } nonce_t;
17 
18 /**
19  * Generate a new nonce random nonce value.
20  *
21  * @param nonce Pointer to a nonce.
22  */
23 void nonce_new(nonce_t *nonce);
24 
25 /**
26  * Check nonces for equality.
27  *
28  * @param a Nonce to compare.
29  * @param b Nonce to compare.
30  * @return bool true if equal, false otherwise.
31  */
32 inline bool nonce_equal(const nonce_t *a, const nonce_t *b) {
33  return a->value[0] == b->value[0] && a->value[1] == b->value[1];
34 }
35 
36 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_NONCE_H_