-
Notifications
You must be signed in to change notification settings - Fork 3k
RNG HAL addition #2765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RNG HAL addition #2765
Changes from all commits
6da5515
132a5bb
7d68492
02fd613
72fac61
5e351c2
1d9cacb
ee344ab
e8ca16d
a225baf
da1b423
ea1041e
9048113
f8c6c23
48544fc
88b2220
1f8da7d
ef58562
1b95c67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* mbed Microcontroller Library | ||
* Copyright (c) 2016 ARM Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#if defined(DEVICE_TRNG) | ||
|
||
#include "hal/trng_api.h" | ||
|
||
int mbedtls_hardware_poll( void *data, unsigned char *output, size_t len, size_t *olen ) { | ||
trng_t trng_obj; | ||
trng_init(&trng_obj); | ||
int ret = trng_get_bytes(&trng_obj, output, len, olen); | ||
trng_free(&trng_obj); | ||
return ret; | ||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* mbed Microcontroller Library | ||
* Copyright (c) 2016 ARM Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef MBED_TRNG_API_H | ||
#define MBED_TRNG_API_H | ||
|
||
#include <stddef.h> | ||
#include "device.h" | ||
|
||
#if DEVICE_TRNG | ||
|
||
/** TRNG HAL structure. trng_s is declared in the target's HAL | ||
*/ | ||
typedef struct trng_s trng_t; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* \defgroup hal_trng TRNG hal functions | ||
* @{ | ||
*/ | ||
|
||
/** Initialize the TRNG peripheral | ||
* | ||
* @param obj The TRNG object | ||
*/ | ||
void trng_init(trng_t *obj); | ||
|
||
/** Deinitialize the TRNG peripheral | ||
* | ||
* @param obj The TRNG object | ||
*/ | ||
void trng_free(trng_t *obj); | ||
|
||
/** Get random data from TRNG peripheral | ||
* | ||
* @param obj The TRNG object | ||
* @param output The pointer to an output array | ||
* @param length The size of output data, to avoid buffer overwrite | ||
* @param output_length The length of generated data | ||
* @return 0 success, -1 fail | ||
*/ | ||
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length); | ||
|
||
/**@}*/ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also would need a mbed TLS will call this function automatically and use this value to calculate how many times we have to poll to achieve the configured level of cryptographic strength. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to put a reference in a comment on how to estimate the entropy of a source. Section 6 in the standard: http://csrc.nist.gov/publications/drafts/800-90/sp800-90b_second_draft.pdf describes it in great detail with easy to follow implementation instructions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You probably discussed this with the others, but just to be sure I write it here too: The |
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,10 @@ struct sleep_s { | |
int powerdown; | ||
}; | ||
|
||
struct trng_s { | ||
uint8_t dummy; | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might just be a cosmetic change, but perhaps this should be
#if defined(DEVICE_TRNG)
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to change it this morning then realized this is how it is within HAL (if we go that path, should be fixed everywhere). lets keep it as it is