/* chacha20_poly1305 cipher implementation */
+#include "internal/endian.h"
#include "cipher_chacha20_poly1305.h"
static int chacha_poly1305_tls_init(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;
ctx->len.text = plen;
if (plen) {
- if (ctx->enc)
+ if (bctx->enc)
ctr = xor128_encrypt_n_pad(out, in, ctr, plen);
else
ctr = xor128_decrypt_n_pad(out, in, ctr, plen);
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);
len - POLY1305_BLOCK_SIZE);
return 0;
}
+ /* Strip the tag */
+ len -= POLY1305_BLOCK_SIZE;
}
*out_padlen = len;
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)
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 {