|
| 1 | +/* |
| 2 | + * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | + * |
| 4 | + * The MIT License (MIT) |
| 5 | + * |
| 6 | + * Copyright (c) 2024-2025 OpenMV LLC. |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | + * of this software and associated documentation files (the "Software"), to deal |
| 10 | + * in the Software without restriction, including without limitation the rights |
| 11 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | + * copies of the Software, and to permit persons to whom the Software is |
| 13 | + * furnished to do so, subject to the following conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be included in |
| 16 | + * all copies or substantial portions of the Software. |
| 17 | + * |
| 18 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | + * THE SOFTWARE. |
| 25 | + */ |
| 26 | + |
| 27 | +#include "py/obj.h" |
| 28 | +#include "se_services.h" |
| 29 | +#include "mbedtls_config_port.h" |
| 30 | + |
| 31 | +#if defined(MBEDTLS_HAVE_TIME) |
| 32 | +#include "shared/timeutils/timeutils.h" |
| 33 | +#include "mbedtls/platform_time.h" |
| 34 | +#endif |
| 35 | + |
| 36 | +int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen) { |
| 37 | + uint32_t val = 0; |
| 38 | + int n = 0; |
| 39 | + *olen = len; |
| 40 | + while (len--) { |
| 41 | + if (!n) { |
| 42 | + val = se_services_rand64(); |
| 43 | + n = 4; |
| 44 | + } |
| 45 | + *output++ = val; |
| 46 | + val >>= 8; |
| 47 | + --n; |
| 48 | + } |
| 49 | + return 0; |
| 50 | +} |
| 51 | + |
| 52 | +#if defined(MBEDTLS_HAVE_TIME) |
| 53 | + |
| 54 | +time_t alif_mbedtls_time(time_t *timer) { |
| 55 | + // TODO implement proper RTC time |
| 56 | + unsigned int year = 2025; |
| 57 | + unsigned int month = 1; |
| 58 | + unsigned int date = 1; |
| 59 | + unsigned int hours = 12; |
| 60 | + unsigned int minutes = 0; |
| 61 | + unsigned int seconds = 0; |
| 62 | + return timeutils_seconds_since_epoch(year, month, date, hours, minutes, seconds); |
| 63 | +} |
| 64 | + |
| 65 | +#endif |
0 commit comments