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