-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
4 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ |