mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-25 09:22:33 +00:00
fix rfc7539 padding
This commit is contained in:
parent
1a7483d43d
commit
afbe3e7551
@ -26,6 +26,7 @@ void rfc7539_init(chacha20poly1305_ctx *ctx, uint8_t key[32], uint8_t nonce[12])
|
|||||||
void rfc7539_auth(chacha20poly1305_ctx *ctx, uint8_t *in, size_t n) {
|
void rfc7539_auth(chacha20poly1305_ctx *ctx, uint8_t *in, size_t n) {
|
||||||
uint8_t padding[16] = {0};
|
uint8_t padding[16] = {0};
|
||||||
poly1305_update(&ctx->poly1305, in, n);
|
poly1305_update(&ctx->poly1305, in, n);
|
||||||
|
if (n % 16 != 0)
|
||||||
poly1305_update(&ctx->poly1305, padding, 16 - n%16);
|
poly1305_update(&ctx->poly1305, padding, 16 - n%16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ void rfc7539_finish(chacha20poly1305_ctx *ctx, int64_t alen, int64_t plen, uint8
|
|||||||
memcpy(lengths, &alen, sizeof(int64_t));
|
memcpy(lengths, &alen, sizeof(int64_t));
|
||||||
memcpy(lengths + 8, &plen, sizeof(int64_t));
|
memcpy(lengths + 8, &plen, sizeof(int64_t));
|
||||||
|
|
||||||
|
if (plen % 16 != 0)
|
||||||
poly1305_update(&ctx->poly1305, padding, 16 - plen%16);
|
poly1305_update(&ctx->poly1305, padding, 16 - plen%16);
|
||||||
poly1305_update(&ctx->poly1305, lengths, 16);
|
poly1305_update(&ctx->poly1305, lengths, 16);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user