Skip to content

Commit 4bbbad3

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
FASTMODEL: add simulated TRNG implementation to fastmodel
1 parent ba7b479 commit 4bbbad3

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/objects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ struct flash_s {
7878
uint8_t not_used;
7979
};
8080

81+
struct trng_s {
82+
uint8_t not_used;
83+
};
84+
8185
#include "gpio_object.h"
8286

8387
#ifdef __cplusplus
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2017-2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing software
12+
* distributed under the License is distributed on an "AS IS" BASIS
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "trng_api.h"
19+
#include "device.h"
20+
#include <stdlib.h>
21+
22+
23+
24+
void trng_init(trng_t *obj)
25+
{
26+
srand(0);
27+
(void)obj;
28+
}
29+
30+
31+
void trng_free(trng_t *obj)
32+
{
33+
(void)obj;
34+
}
35+
36+
/** Get random data from TRNG peripheral
37+
*
38+
* @param obj The TRNG object
39+
* @param output The pointer to an output array
40+
* @param length The size of output data, to avoid buffer overwrite
41+
* @param output_length The length of generated data
42+
* @return 0 success, -1 fail
43+
*/
44+
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
45+
{
46+
(void)obj;
47+
(void)output;
48+
49+
for (int i = 0; i < length; ++i) {
50+
output[i] = rand() % 256;
51+
}
52+
*output_length = length;
53+
54+
return 0;
55+
56+
}

0 commit comments

Comments
 (0)