Use a single zero buffer
This commit is contained in:
parent
8fd513540f
commit
3c5e296178
@ -23,8 +23,6 @@
|
|||||||
* according to draft-irtf-cfrg-xchacha-03.
|
* according to draft-irtf-cfrg-xchacha-03.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const uint8_t zeropad[16];
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
chacha20_xchacha20_keysetup(struct lc_cipher_ctx *cctx,
|
chacha20_xchacha20_keysetup(struct lc_cipher_ctx *cctx,
|
||||||
uint8_t akey[LC_POLY1305_KEYLEN], void *initparams)
|
uint8_t akey[LC_POLY1305_KEYLEN], void *initparams)
|
||||||
@ -94,7 +92,7 @@ chacha20_poly1305_seal(uint8_t *out, size_t *outlen, void *initparams,
|
|||||||
!lc_auth_update(actx, aad, aadlen))
|
!lc_auth_update(actx, aad, aadlen))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (aadlen % 16 != 0)
|
if (aadlen % 16 != 0)
|
||||||
if (!lc_auth_update(actx, zeropad, 16 - (aadlen % 16)))
|
if (!lc_auth_update(actx, zerobuf, 16 - (aadlen % 16)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
cparams.counter = 1;
|
cparams.counter = 1;
|
||||||
@ -111,7 +109,7 @@ chacha20_poly1305_seal(uint8_t *out, size_t *outlen, void *initparams,
|
|||||||
if (!lc_auth_update(actx, out, inlen))
|
if (!lc_auth_update(actx, out, inlen))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (inlen % 16 != 0)
|
if (inlen % 16 != 0)
|
||||||
if (!lc_auth_update(actx, zeropad, 16 - (inlen % 16)))
|
if (!lc_auth_update(actx, zerobuf, 16 - (inlen % 16)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
store64le(&buf[0], aadlen);
|
store64le(&buf[0], aadlen);
|
||||||
@ -183,7 +181,7 @@ xchacha20_poly1305_seal(uint8_t *out, size_t *outlen, void *initparams,
|
|||||||
!lc_auth_update(actx, aad, aadlen))
|
!lc_auth_update(actx, aad, aadlen))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (aadlen % 16 != 0)
|
if (aadlen % 16 != 0)
|
||||||
if (!lc_auth_update(actx, zeropad, 16 - (aadlen % 16)))
|
if (!lc_auth_update(actx, zerobuf, 16 - (aadlen % 16)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
cparams.counter = 1;
|
cparams.counter = 1;
|
||||||
@ -200,7 +198,7 @@ xchacha20_poly1305_seal(uint8_t *out, size_t *outlen, void *initparams,
|
|||||||
if (!lc_auth_update(actx, out, inlen))
|
if (!lc_auth_update(actx, out, inlen))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (inlen % 16 != 0)
|
if (inlen % 16 != 0)
|
||||||
if (!lc_auth_update(actx, zeropad, 16 - (inlen % 16)))
|
if (!lc_auth_update(actx, zerobuf, 16 - (inlen % 16)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
store64le(&buf[0], aadlen);
|
store64le(&buf[0], aadlen);
|
||||||
@ -274,14 +272,14 @@ chacha20_poly1305_open(uint8_t *out, size_t *outlen, void *initparams,
|
|||||||
!lc_auth_update(actx, aad, aadlen))
|
!lc_auth_update(actx, aad, aadlen))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (aadlen % 16 != 0)
|
if (aadlen % 16 != 0)
|
||||||
if (!lc_auth_update(actx, zeropad, 16 - (aadlen % 16)))
|
if (!lc_auth_update(actx, zerobuf, 16 - (aadlen % 16)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ctlen = inlen - LC_POLY1305_TAGLEN;
|
ctlen = inlen - LC_POLY1305_TAGLEN;
|
||||||
if (!lc_auth_update(actx, in, ctlen))
|
if (!lc_auth_update(actx, in, ctlen))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (ctlen % 16 != 0)
|
if (ctlen % 16 != 0)
|
||||||
if (!lc_auth_update(actx, zeropad, 16 - (ctlen % 16)))
|
if (!lc_auth_update(actx, zerobuf, 16 - (ctlen % 16)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
store64le(&buf[0], aadlen);
|
store64le(&buf[0], aadlen);
|
||||||
@ -369,14 +367,14 @@ xchacha20_poly1305_open(uint8_t *out, size_t *outlen, void *initparams,
|
|||||||
!lc_auth_update(actx, aad, aadlen))
|
!lc_auth_update(actx, aad, aadlen))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (aadlen % 16 != 0)
|
if (aadlen % 16 != 0)
|
||||||
if (!lc_auth_update(actx, zeropad, 16 - (aadlen % 16)))
|
if (!lc_auth_update(actx, zerobuf, 16 - (aadlen % 16)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ctlen = inlen - LC_POLY1305_TAGLEN;
|
ctlen = inlen - LC_POLY1305_TAGLEN;
|
||||||
if (!lc_auth_update(actx, in, ctlen))
|
if (!lc_auth_update(actx, in, ctlen))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (ctlen % 16 != 0)
|
if (ctlen % 16 != 0)
|
||||||
if (!lc_auth_update(actx, zeropad, 16 - (ctlen % 16)))
|
if (!lc_auth_update(actx, zerobuf, 16 - (ctlen % 16)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
store64le(&buf[0], aadlen);
|
store64le(&buf[0], aadlen);
|
||||||
|
@ -208,4 +208,12 @@ void sha256_block(struct sha256_state *);
|
|||||||
|
|
||||||
void sha512_block(struct sha512_state *);
|
void sha512_block(struct sha512_state *);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* VARIABLES
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern uint8_t zerobuf[128];
|
||||||
|
|
||||||
|
|
||||||
#endif /* LC_INTERNAL_H */
|
#endif /* LC_INTERNAL_H */
|
||||||
|
@ -19,9 +19,6 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
|
||||||
static uint8_t zeros[HMAC_HASHLEN_MAX];
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
hkdf_kdf(uint8_t *out, size_t *outlen, void *initparams, size_t len)
|
hkdf_kdf(uint8_t *out, size_t *outlen, void *initparams, size_t len)
|
||||||
{
|
{
|
||||||
@ -51,7 +48,7 @@ hkdf_kdf(uint8_t *out, size_t *outlen, void *initparams, size_t len)
|
|||||||
|
|
||||||
hmacparams.hash = params->hash;
|
hmacparams.hash = params->hash;
|
||||||
if (params->saltlen == 0) {
|
if (params->saltlen == 0) {
|
||||||
hmacparams.key = zeros;
|
hmacparams.key = zerobuf;
|
||||||
hmacparams.keylen = hashlen;
|
hmacparams.keylen = hashlen;
|
||||||
} else {
|
} else {
|
||||||
hmacparams.key = params->salt;
|
hmacparams.key = params->salt;
|
||||||
|
3
util.c
3
util.c
@ -23,6 +23,9 @@
|
|||||||
#define HEXDUMP_BUFSZ 128
|
#define HEXDUMP_BUFSZ 128
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t zerobuf[128] = { 0 };
|
||||||
|
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
hexdump_line(char *buf, const uint8_t *blob, size_t len, size_t off, int pad)
|
hexdump_line(char *buf, const uint8_t *blob, size_t len, size_t off, int pad)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user