|
| 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