diff options
author | Richard Levitte <levitte@openssl.org> | 2020-07-09 08:37:46 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-07-11 10:00:33 +0200 |
commit | e23d850ff3281220f33ed78d9ca4fcadfa279565 (patch) | |
tree | 4e7f73d978bb1a7986e0ac27ee61bdab23d66ed2 /crypto/evp/e_chacha20_poly1305.c | |
parent | d685fc7a59699aeb17120aebd17a9175ce5930cd (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 'crypto/evp/e_chacha20_poly1305.c')
-rw-r--r-- | crypto/evp/e_chacha20_poly1305.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/crypto/evp/e_chacha20_poly1305.c b/crypto/evp/e_chacha20_poly1305.c index b7340b147d..95319245b6 100644 --- a/crypto/evp/e_chacha20_poly1305.c +++ b/crypto/evp/e_chacha20_poly1305.c @@ -9,6 +9,7 @@ #include <stdio.h> #include "internal/cryptlib.h" +#include "internal/endian.h" #ifndef OPENSSL_NO_CHACHA @@ -310,12 +311,9 @@ static int chacha20_poly1305_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, } { - const union { - long one; - char little; - } is_endian = { 1 }; + DECLARE_IS_ENDIAN; - if (is_endian.little) { + if (IS_LITTLE_ENDIAN) { memcpy(ctr, (unsigned char *)&actx->len, POLY1305_BLOCK_SIZE); } else { ctr[0] = (unsigned char)(actx->len.aad); @@ -426,10 +424,7 @@ static int chacha20_poly1305_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, } if (in == NULL /* explicit final */ || plen != len) { /* or tls mode */ - const union { - long one; - char little; - } is_endian = { 1 }; + DECLARE_IS_ENDIAN; unsigned char temp[POLY1305_BLOCK_SIZE]; if (actx->aad) { /* wrap up aad */ @@ -443,7 +438,7 @@ static int chacha20_poly1305_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, Poly1305_Update(POLY1305_ctx(actx), zero, POLY1305_BLOCK_SIZE - rem); - if (is_endian.little) { + if (IS_LITTLE_ENDIAN) { Poly1305_Update(POLY1305_ctx(actx), (unsigned char *)&actx->len, POLY1305_BLOCK_SIZE); } else { |