mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-28 08:37:25 +00:00
Introduce mbedtls_xor
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
339406daf9
commit
c3d8041fe7
@ -26,6 +26,7 @@
|
|||||||
#include "mbedtls/build_info.h"
|
#include "mbedtls/build_info.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
/** Helper to define a function as static except when building invasive tests.
|
/** Helper to define a function as static except when building invasive tests.
|
||||||
*
|
*
|
||||||
@ -390,6 +391,32 @@ extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const c
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a fast block XOR operation, such that
|
||||||
|
* r[i] = a[i] ^ b[i] where 0 <= i < n
|
||||||
|
*
|
||||||
|
* \param r Pointer to result (buffer of at least \p n bytes). \p r
|
||||||
|
* may be equal to either \p a or \p b, but behaviour when
|
||||||
|
* it overlaps in other ways is undefined.
|
||||||
|
* \param a Pointer to input (buffer of at least \p n bytes)
|
||||||
|
* \param b Pointer to input (buffer of at least \p n bytes)
|
||||||
|
* \param n Number of bytes to process.
|
||||||
|
*/
|
||||||
|
static inline void mbedtls_xor( unsigned char* r, unsigned char const *a, unsigned char const *b, size_t n )
|
||||||
|
{
|
||||||
|
uint32_t *a32 = (uint32_t*)a;
|
||||||
|
uint32_t *b32 = (uint32_t*)b;
|
||||||
|
uint32_t *r32 = (uint32_t*)r;
|
||||||
|
for ( size_t i = 0; i < (n >> 2); i++ )
|
||||||
|
{
|
||||||
|
r32[i] = a32[i] ^ b32[i];
|
||||||
|
}
|
||||||
|
for ( size_t i = n - (n % 4) ; i < n; i++ )
|
||||||
|
{
|
||||||
|
r[i] = a[i] ^ b[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Fix MSVC C99 compatible issue
|
/* Fix MSVC C99 compatible issue
|
||||||
* MSVC support __func__ from visual studio 2015( 1900 )
|
* MSVC support __func__ from visual studio 2015( 1900 )
|
||||||
* Use MSVC predefine macro to avoid name check fail.
|
* Use MSVC predefine macro to avoid name check fail.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user