mbed client on ethernet with LWIP
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbedtls/source/entropy_hardware_poll.c@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* |
mbedAustin | 11:cada08fc8a70 | 2 | * Temporary "entropy" collector for Cortex-M4 |
mbedAustin | 11:cada08fc8a70 | 3 | * |
mbedAustin | 11:cada08fc8a70 | 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
mbedAustin | 11:cada08fc8a70 | 5 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 6 | * |
mbedAustin | 11:cada08fc8a70 | 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
mbedAustin | 11:cada08fc8a70 | 8 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 9 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 10 | * |
mbedAustin | 11:cada08fc8a70 | 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 12 | * |
mbedAustin | 11:cada08fc8a70 | 13 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 16 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 17 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 18 | * |
mbedAustin | 11:cada08fc8a70 | 19 | * This file is part of mbed TLS (https://tls.mbed.org) |
mbedAustin | 11:cada08fc8a70 | 20 | */ |
mbedAustin | 11:cada08fc8a70 | 21 | |
mbedAustin | 11:cada08fc8a70 | 22 | /* |
mbedAustin | 11:cada08fc8a70 | 23 | * WARNING: this is a temporary hack! |
mbedAustin | 11:cada08fc8a70 | 24 | * 1. Currently does not provide strong entropy, should be replaced to use the |
mbedAustin | 11:cada08fc8a70 | 25 | * on-board hardware RNG (see IOTSSL-303) |
mbedAustin | 11:cada08fc8a70 | 26 | * 2. This should be in a separete yotta module which would be a target |
mbedAustin | 11:cada08fc8a70 | 27 | * dependency of mbedtls (see IOTSSL-313) |
mbedAustin | 11:cada08fc8a70 | 28 | */ |
mbedAustin | 11:cada08fc8a70 | 29 | |
mbedAustin | 11:cada08fc8a70 | 30 | #if defined(TARGET_LIKE_CORTEX_M4) |
mbedAustin | 11:cada08fc8a70 | 31 | |
mbedAustin | 11:cada08fc8a70 | 32 | #include "MK64F12.h" |
mbedAustin | 11:cada08fc8a70 | 33 | #include "core_cm4.h" |
mbedAustin | 11:cada08fc8a70 | 34 | #include <string.h> |
mbedAustin | 11:cada08fc8a70 | 35 | |
mbedAustin | 11:cada08fc8a70 | 36 | unsigned long hardclock( void ) |
mbedAustin | 11:cada08fc8a70 | 37 | { |
mbedAustin | 11:cada08fc8a70 | 38 | static int dwt_started = 0; |
mbedAustin | 11:cada08fc8a70 | 39 | |
mbedAustin | 11:cada08fc8a70 | 40 | if( dwt_started == 0 ) |
mbedAustin | 11:cada08fc8a70 | 41 | { |
mbedAustin | 11:cada08fc8a70 | 42 | CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; |
mbedAustin | 11:cada08fc8a70 | 43 | DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; |
mbedAustin | 11:cada08fc8a70 | 44 | } |
mbedAustin | 11:cada08fc8a70 | 45 | |
mbedAustin | 11:cada08fc8a70 | 46 | return( DWT->CYCCNT ); |
mbedAustin | 11:cada08fc8a70 | 47 | } |
mbedAustin | 11:cada08fc8a70 | 48 | |
mbedAustin | 11:cada08fc8a70 | 49 | int mbedtls_hardware_poll( void *data, |
mbedAustin | 11:cada08fc8a70 | 50 | unsigned char *output, size_t len, size_t *olen ) |
mbedAustin | 11:cada08fc8a70 | 51 | { |
mbedAustin | 11:cada08fc8a70 | 52 | unsigned long timer = hardclock(); |
mbedAustin | 11:cada08fc8a70 | 53 | ((void) data); |
mbedAustin | 11:cada08fc8a70 | 54 | *olen = 0; |
mbedAustin | 11:cada08fc8a70 | 55 | |
mbedAustin | 11:cada08fc8a70 | 56 | if( len < sizeof(unsigned long) ) |
mbedAustin | 11:cada08fc8a70 | 57 | return( 0 ); |
mbedAustin | 11:cada08fc8a70 | 58 | |
mbedAustin | 11:cada08fc8a70 | 59 | memcpy( output, &timer, sizeof(unsigned long) ); |
mbedAustin | 11:cada08fc8a70 | 60 | *olen = sizeof(unsigned long); |
mbedAustin | 11:cada08fc8a70 | 61 | |
mbedAustin | 11:cada08fc8a70 | 62 | return( 0 ); |
mbedAustin | 11:cada08fc8a70 | 63 | } |
mbedAustin | 11:cada08fc8a70 | 64 | |
mbedAustin | 11:cada08fc8a70 | 65 | #endif |