mirror of https://github.com/ARMmbed/mbed-os.git
mbedtls: Add an alt implementation of timing
Implement the MBEDTLS_TIMING_ALT interface for Mbed OS. This implementation is sufficient to run the Mbed TLS benchmarking application.pull/14756/head
parent
386f197040
commit
b8781e527b
|
@ -16,6 +16,7 @@ target_sources(mbed-mbedtls
|
||||||
platform/src/mbed_trng.cpp
|
platform/src/mbed_trng.cpp
|
||||||
platform/src/platform_alt.cpp
|
platform/src/platform_alt.cpp
|
||||||
platform/src/shared_rng.cpp
|
platform/src/shared_rng.cpp
|
||||||
|
platform/src/timing.cpp
|
||||||
|
|
||||||
source/aes.c
|
source/aes.c
|
||||||
source/aesni.c
|
source/aesni.c
|
||||||
|
|
|
@ -55,9 +55,8 @@
|
||||||
#endif
|
#endif
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#if defined(TARGET_LIKE_MBED) && \
|
#if defined(TARGET_LIKE_MBED) && defined(MBEDTLS_NET_C)
|
||||||
( defined(MBEDTLS_NET_C) || defined(MBEDTLS_TIMING_C) )
|
#error "The NET module is not available for mbed OS - please use the network functions provided by mbed OS"
|
||||||
#error "The NET and TIMING modules are not available for mbed OS - please use the network and timing functions provided by mbed OS"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_DEPRECATED_WARNING) && \
|
#if defined(MBEDTLS_DEPRECATED_WARNING) && \
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* timing_alt.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021, Arm Limited, All Rights Reserved
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TIMING_ALT_H
|
||||||
|
#define TIMING_ALT_H
|
||||||
|
|
||||||
|
#include "mbedtls/timing.h"
|
||||||
|
#if defined(MBEDTLS_TIMING_ALT)
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
struct mbedtls_timing_hr_time
|
||||||
|
{
|
||||||
|
struct timeval start;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct mbedtls_timing_delay_context
|
||||||
|
{
|
||||||
|
struct mbedtls_timing_hr_time timer;
|
||||||
|
uint32_t int_ms;
|
||||||
|
uint32_t fin_ms;
|
||||||
|
} mbedtls_timing_delay_context;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* timing.cpp
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021, Arm Limited, All Rights Reserved
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||||
|
#include "mbedtls/config.h"
|
||||||
|
#else
|
||||||
|
#include MBEDTLS_CONFIG_FILE
|
||||||
|
#endif
|
||||||
|
#include "mbedtls/timing.h"
|
||||||
|
#include "drivers/Timeout.h"
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
volatile int mbedtls_timing_alarmed = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void handle_alarm(void)
|
||||||
|
{
|
||||||
|
mbedtls_timing_alarmed = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void mbedtls_set_alarm(int seconds)
|
||||||
|
{
|
||||||
|
static mbed::Timeout t;
|
||||||
|
mbedtls_timing_alarmed = 0;
|
||||||
|
|
||||||
|
t.attach(handle_alarm, std::chrono::seconds(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(HAVE_HARDCLOCK)
|
||||||
|
#define HAVE_HARDCLOCK
|
||||||
|
#include "platform/mbed_rtc_time.h"
|
||||||
|
static int hardclock_init = 0;
|
||||||
|
static struct timeval tv_init;
|
||||||
|
|
||||||
|
extern "C" unsigned long mbedtls_timing_hardclock(void)
|
||||||
|
{
|
||||||
|
struct timeval tv_cur;
|
||||||
|
|
||||||
|
if (hardclock_init == 0)
|
||||||
|
{
|
||||||
|
gettimeofday(&tv_init, NULL);
|
||||||
|
hardclock_init = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gettimeofday(&tv_cur, NULL);
|
||||||
|
return((tv_cur.tv_sec - tv_init.tv_sec) * 1000000
|
||||||
|
+ (tv_cur.tv_usec - tv_init.tv_usec));
|
||||||
|
}
|
||||||
|
#endif /* !HAVE_HARDCLOCK */
|
Loading…
Reference in New Issue