Software APIs
sw
device
sca
lib
prng.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_SCA_LIB_PRNG_H_
6
#define OPENTITAN_SW_DEVICE_SCA_LIB_PRNG_H_
7
8
#include <
stddef.h
>
9
#include <
stdint.h
>
10
11
#ifdef __cplusplus
12
extern
"C"
{
13
#endif
// __cplusplus
14
15
/**
16
* @file
17
* @brief PRNG for side-channel analysis.
18
*
19
* This library provides a Mersenne Twister PRNG that can be used to generate
20
* random plaintexts on the device. Generating random plaintexts on the device
21
* eliminates the overhead of sending them from the host and can significantly
22
* improve capture rate. The host must use the same PRNG to be able to compute
23
* the plaintext and the ciphertext of each trace.
24
*
25
* TODO(alphan): Replace this with a more efficient PRNG after updating
26
* host-side code.
27
*/
28
29
/**
30
* Initializes the random number generator.
31
*
32
* @param seed Seed to initalize with.
33
*/
34
void
prng_seed
(uint32_t seed);
35
36
/**
37
* Generates a random uint32_t.
38
*
39
* The behavior of this function matches the behavior of `random.randint(0,
40
* 0xFFFFFFFF)` in python.
41
*
42
* @return A random uint32_t.
43
*/
44
uint32_t
prng_rand_uint32
(
void
);
45
46
/**
47
* Generates a random byte.
48
*
49
* The behavior of this function matches the behavior of `random.randint(0,
50
* 255)` in python, which is used by ChipWhisperer's `ktp.next()`.
51
*
52
* @return A random byte.
53
*/
54
uint8_t
prng_rand_byte
(
void
);
55
56
/**
57
* Fills a buffer with random bytes.
58
*
59
* The behavior of this function matches the behavior of `random.randint(0,
60
* 255)` in python, which is used by ChipWhisperer's `ktp.next()`.
61
*
62
* @param[out] buffer A buffer.
63
* @param buffer_len Size of the buffer.
64
*
65
* @return A random byte.
66
*/
67
void
prng_rand_bytes
(uint8_t *buffer,
size_t
buffer_len);
68
69
#ifdef __cplusplus
70
}
// extern "C"
71
#endif
// __cplusplus
72
73
#endif
// OPENTITAN_SW_DEVICE_SCA_LIB_PRNG_H_
Return to
OpenTitan Documentation