mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-28 19:21:08 +00:00
Prevent perf regressions in mbedtls_xor
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
051225d07a
commit
b9cd19bc8c
@ -29,6 +29,19 @@
|
|||||||
|
|
||||||
#include "mbedtls/build_info.h"
|
#include "mbedtls/build_info.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define MBEDTLS_EFFICIENT_UNALIGNED_ACCESS for architectures where unaligned memory
|
||||||
|
* accesses are known to be safe and efficient.
|
||||||
|
*/
|
||||||
|
#if defined(__ARM_FEATURE_UNALIGNED) \
|
||||||
|
|| defined(__i386__) || defined(__amd64__) || defined(__x86_64__)
|
||||||
|
/*
|
||||||
|
* __ARM_FEATURE_UNALIGNED is defined where appropriate by armcc, gcc 7, clang 9
|
||||||
|
* (and later versions); all x86 platforms should have efficient unaligned access.
|
||||||
|
*/
|
||||||
|
#define MBEDTLS_EFFICIENT_UNALIGNED_ACCESS
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the unsigned 16 bits integer from the given address, which need not
|
* Read the unsigned 16 bits integer from the given address, which need not
|
||||||
* be aligned.
|
* be aligned.
|
||||||
|
@ -122,11 +122,13 @@ static inline const unsigned char *mbedtls_buffer_offset_const(
|
|||||||
*/
|
*/
|
||||||
inline void mbedtls_xor(unsigned char *r, const unsigned char *a, const unsigned char *b, size_t n)
|
inline void mbedtls_xor(unsigned char *r, const unsigned char *a, const unsigned char *b, size_t n)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i = 0;
|
||||||
for (i = 0; (i + 4) <= n; i += 4) {
|
#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS)
|
||||||
|
for (; (i + 4) <= n; i += 4) {
|
||||||
uint32_t x = mbedtls_get_unaligned_uint32(a + i) ^ mbedtls_get_unaligned_uint32(b + i);
|
uint32_t x = mbedtls_get_unaligned_uint32(a + i) ^ mbedtls_get_unaligned_uint32(b + i);
|
||||||
mbedtls_put_unaligned_uint32(r + i, x);
|
mbedtls_put_unaligned_uint32(r + i, x);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
for (; i < n; i++) {
|
for (; i < n; i++) {
|
||||||
r[i] = a[i] ^ b[i];
|
r[i] = a[i] ^ b[i];
|
||||||
}
|
}
|
||||||
|
@ -47,15 +47,6 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/*
|
|
||||||
* Define MBEDTLS_EFFICIENT_UNALIGNED_ACCESS for architectures where unaligned memory
|
|
||||||
* accesses are known to be safe and efficient.
|
|
||||||
*/
|
|
||||||
#if defined(__ARM_FEATURE_UNALIGNED)
|
|
||||||
/* __ARM_FEATURE_UNALIGNED is defined by armcc, gcc 7, clang 9 and later versions */
|
|
||||||
#define MBEDTLS_EFFICIENT_UNALIGNED_ACCESS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define MBEDTLS_EFFICIENT_UNALIGNED_VOLATILE_ACCESS where assembly is present to
|
* Define MBEDTLS_EFFICIENT_UNALIGNED_VOLATILE_ACCESS where assembly is present to
|
||||||
* perform fast unaligned access to volatile data.
|
* perform fast unaligned access to volatile data.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user