|
| 1 | +/* |
| 2 | + * Hardware entropy collector for the K66F, using Freescale's RNGA |
| 3 | + * |
| 4 | + * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
| 5 | + * SPDX-License-Identifier: Apache-2.0 |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | + * not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * |
| 19 | + */ |
| 20 | + |
| 21 | +/* |
| 22 | + * Reference: "K66 Sub-Family Reference Manual, Rev. 2", chapter 38 |
| 23 | + */ |
| 24 | + |
| 25 | +#include <stdlib.h> |
| 26 | +#include "cmsis.h" |
| 27 | +#include "fsl_trng.h" |
| 28 | +#include "trng_api.h" |
| 29 | + |
| 30 | +void trng_init(trng_t *obj) |
| 31 | +{ |
| 32 | + (void)obj; |
| 33 | + trng_config_t trngConfig; |
| 34 | + TRNG_GetDefaultConfig(&trngConfig); |
| 35 | + TRNG_Init(TRNG, &trngConfig); |
| 36 | +} |
| 37 | + |
| 38 | +void trng_free(trng_t *obj) |
| 39 | +{ |
| 40 | + (void)obj; |
| 41 | + TRNG_Deinit(TRNG); |
| 42 | +} |
| 43 | + |
| 44 | +int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length) |
| 45 | +{ |
| 46 | + (void)obj; |
| 47 | + |
| 48 | + if(TRNG_GetRandomData(TRNG, output, length) != kStatus_Success) { |
| 49 | + return -1; |
| 50 | + } |
| 51 | + *output_length = length; |
| 52 | + |
| 53 | + return 0; |
| 54 | +} |
0 commit comments