Skip to content

Commit af85964

Browse files
danny4478mohammad1603
authored andcommitted
Add a weak implementation for trng_get_bytes()
1 parent da6c9ea commit af85964

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* Copyright (c) 2018 ARM Limited
2+
*
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 "crypto.h"
20+
21+
#if DEVICE_TRNG
22+
23+
__WEAK void trng_init(trng_t *obj)
24+
{
25+
(void)(obj);
26+
}
27+
28+
29+
__WEAK void trng_free(trng_t *obj)
30+
{
31+
(void)(obj);
32+
}
33+
34+
__WEAK int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
35+
{
36+
if (output == NULL){
37+
return -1;
38+
}
39+
40+
if(psa_crypto_init() != PSA_SUCCESS) {
41+
return -1;
42+
}
43+
44+
if (psa_generate_random(output, length) != PSA_SUCCESS) {
45+
return -1;
46+
}
47+
48+
mbedtls_psa_crypto_free();
49+
50+
((void)(obj));
51+
((void)(output_length));
52+
53+
return 0;
54+
}
55+
56+
#endif // DEVICE_TRNG

targets/targets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"NSPE_Target": {
9999
"inherits": ["PSA_Target"],
100100
"components": ["PSA_SRV_IPC", "NSPE"],
101+
"device_has_add": ["TRNG"],
101102
"public": false
102103
},
103104
"SPE_Target": {

0 commit comments

Comments
 (0)