summaryrefslogtreecommitdiffstats
path: root/providers
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2020-07-09 08:37:46 +0200
committerRichard Levitte <levitte@openssl.org>2020-07-11 10:00:33 +0200
commite23d850ff3281220f33ed78d9ca4fcadfa279565 (patch)
tree4e7f73d978bb1a7986e0ac27ee61bdab23d66ed2 /providers
parentd685fc7a59699aeb17120aebd17a9175ce5930cd (diff)
Add and use internal header that implements endianness check
This moves test/ossl_test_endian.h to include/internal/endian.h and thereby makes the macros in there our standard way to check endianness in run-time. Reviewed-by: Kurt Roeckx <kurt@roeckx.be> (Merged from https://github.com/openssl/openssl/pull/12390)
Diffstat (limited to 'providers')
-rw-r--r--providers/implementations/ciphers/cipher_chacha20_poly1305_hw.c15
-rw-r--r--providers/implementations/digests/blake2_impl.h29
-rw-r--r--providers/implementations/kdfs/kbkdf.c8
3 files changed, 17 insertions, 35 deletions
diff --git a/providers/implementations/ciphers/cipher_chacha20_poly1305_hw.c b/providers/implementations/ciphers/cipher_chacha20_poly1305_hw.c
index 70ffaf1588..bd99a9fb4e 100644
--- a/providers/implementations/ciphers/cipher_chacha20_poly1305_hw.c
+++ b/providers/implementations/ciphers/cipher_chacha20_poly1305_hw.c
@@ -9,6 +9,7 @@
/* chacha20_poly1305 cipher implementation */
+#include "internal/endian.h"
#include "cipher_chacha20_poly1305.h"
static int chacha_poly1305_tls_init(PROV_CIPHER_CTX *bctx,
@@ -117,10 +118,7 @@ static int chacha20_poly1305_tls_cipher(PROV_CIPHER_CTX *bctx,
size_t tail, tohash_len, buf_len, plen = ctx->tls_payload_length;
unsigned char *buf, *tohash, *ctr, storage[sizeof(zero) + 32];
- const union {
- long one;
- char little;
- } is_endian = { 1 };
+ DECLARE_IS_ENDIAN;
if (len != plen + POLY1305_BLOCK_SIZE)
return 0;
@@ -214,7 +212,7 @@ static int chacha20_poly1305_tls_cipher(PROV_CIPHER_CTX *bctx,
Poly1305_Update(poly, zero, tail);
}
- if (is_endian.little) {
+ if (IS_LITTLE_ENDIAN) {
memcpy(ctr, (unsigned char *)&ctx->len, POLY1305_BLOCK_SIZE);
} else {
ctr[0] = (unsigned char)(ctx->len.aad);
@@ -273,10 +271,7 @@ static int chacha20_poly1305_aead_cipher(PROV_CIPHER_CTX *bctx,
size_t olen = 0;
int rv = 0;
- const union {
- long one;
- char little;
- } is_endian = { 1 };
+ DECLARE_IS_ENDIAN;
if (!ctx->mac_inited) {
#if !defined(OPENSSL_SMALL_FOOTPRINT)
@@ -347,7 +342,7 @@ static int chacha20_poly1305_aead_cipher(PROV_CIPHER_CTX *bctx,
if ((rem = (size_t)ctx->len.text % POLY1305_BLOCK_SIZE))
Poly1305_Update(poly, zero, POLY1305_BLOCK_SIZE - rem);
- if (is_endian.little) {
+ if (IS_LITTLE_ENDIAN) {
Poly1305_Update(poly, (unsigned char *)&ctx->len,
POLY1305_BLOCK_SIZE);
} else {
diff --git a/providers/implementations/digests/blake2_impl.h b/providers/implementations/digests/blake2_impl.h
index 52477a8fe2..aa6d8a3075 100644
--- a/providers/implementations/digests/blake2_impl.h
+++ b/providers/implementations/digests/blake2_impl.h
@@ -15,15 +15,13 @@
*/
#include <string.h>
+#include "internal/endian.h"
static ossl_inline uint32_t load32(const uint8_t *src)
{
- const union {
- long one;
- char little;
- } is_endian = { 1 };
+ DECLARE_IS_ENDIAN;
- if (is_endian.little) {
+ if (IS_LITTLE_ENDIAN) {
uint32_t w;
memcpy(&w, src, sizeof(w));
return w;
@@ -38,12 +36,9 @@ static ossl_inline uint32_t load32(const uint8_t *src)
static ossl_inline uint64_t load64(const uint8_t *src)
{
- const union {
- long one;
- char little;
- } is_endian = { 1 };
+ DECLARE_IS_ENDIAN;
- if (is_endian.little) {
+ if (IS_LITTLE_ENDIAN) {
uint64_t w;
memcpy(&w, src, sizeof(w));
return w;
@@ -62,12 +57,9 @@ static ossl_inline uint64_t load64(const uint8_t *src)
static ossl_inline void store32(uint8_t *dst, uint32_t w)
{
- const union {
- long one;
- char little;
- } is_endian = { 1 };
+ DECLARE_IS_ENDIAN;
- if (is_endian.little) {
+ if (IS_LITTLE_ENDIAN) {
memcpy(dst, &w, sizeof(w));
} else {
uint8_t *p = (uint8_t *)dst;
@@ -80,12 +72,9 @@ static ossl_inline void store32(uint8_t *dst, uint32_t w)
static ossl_inline void store64(uint8_t *dst, uint64_t w)
{
- const union {
- long one;
- char little;
- } is_endian = { 1 };
+ DECLARE_IS_ENDIAN;
- if (is_endian.little) {
+ if (IS_LITTLE_ENDIAN) {
memcpy(dst, &w, sizeof(w));
} else {
uint8_t *p = (uint8_t *)dst;
diff --git a/providers/implementations/kdfs/kbkdf.c b/providers/implementations/kdfs/kbkdf.c
index f3f3d9a609..9cf18d84a2 100644
--- a/providers/implementations/kdfs/kbkdf.c
+++ b/providers/implementations/kdfs/kbkdf.c
@@ -37,6 +37,7 @@
#include "internal/cryptlib.h"
#include "crypto/evp.h"
#include "internal/numbers.h"
+#include "internal/endian.h"
#include "prov/implementations.h"
#include "prov/provider_ctx.h"
#include "prov/provider_util.h"
@@ -80,12 +81,9 @@ static OSSL_FUNC_kdf_set_ctx_params_fn kbkdf_set_ctx_params;
static uint32_t be32(uint32_t host)
{
uint32_t big = 0;
- const union {
- long one;
- char little;
- } is_endian = { 1 };
+ DECLARE_IS_ENDIAN;
- if (!is_endian.little)
+ if (!IS_LITTLE_ENDIAN)
return host;
big |= (host & 0xff000000) >> 24;