mbedtls ported to mbed-classic

Fork of mbedtls by Christopher Haster

Committer:
Christopher Haster
Date:
Fri Jan 22 16:44:49 2016 -0600
Revision:
1:24750b9ad5ef
Initial move of mbedtls to mercurial

Who changed what in which revision?

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