Skip to content

Commit 8e40f0c

Browse files
committed
Simplify state_decrypt_update
1 parent a9bf879 commit 8e40f0c

25 files changed

+84
-187
lines changed

src/aegis128l/aegis128l.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ aegis128l_state_encrypt_final(aegis128l_state *st_, uint8_t *mac, size_t maclen)
122122
}
123123

124124
int
125-
aegis128l_state_decrypt_update(aegis128l_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
126-
const uint8_t *c, size_t clen)
125+
aegis128l_state_decrypt_update(aegis128l_state *st_, uint8_t *m, const uint8_t *c, size_t clen)
127126
{
128-
return implementation->state_decrypt_update(st_, m, mlen_max, written, c, clen);
127+
return implementation->state_decrypt_update(st_, m, c, clen);
129128
}
130129

131130
int

src/aegis128l/aegis128l_common.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,7 @@ state_encrypt_final(aegis128l_state *st_, uint8_t *mac, size_t maclen)
457457
}
458458

459459
static int
460-
state_decrypt_update(aegis128l_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
461-
const uint8_t *c, size_t clen)
460+
state_decrypt_update(aegis128l_state *st_, uint8_t *m, const uint8_t *c, size_t clen)
462461
{
463462
aegis_blocks blocks;
464463
_aegis128l_state *const st =
@@ -469,14 +468,8 @@ state_decrypt_update(aegis128l_state *st_, uint8_t *m, size_t mlen_max, size_t *
469468

470469
memcpy(blocks, st->blocks, sizeof blocks);
471470

472-
*written = 0;
473471
st->mlen += clen;
474472

475-
if (m != NULL && mlen_max < clen) {
476-
errno = ERANGE;
477-
return -1;
478-
}
479-
480473
// Handle leftover keystream from previous call
481474
if (st->pos != 0) {
482475
const size_t available = RATE - st->pos;
@@ -493,7 +486,6 @@ state_decrypt_update(aegis128l_state *st_, uint8_t *m, size_t mlen_max, size_t *
493486
}
494487
}
495488
st->pos += n;
496-
*written += n;
497489
if (m != NULL) {
498490
m += n;
499491
}
@@ -521,7 +513,6 @@ state_decrypt_update(aegis128l_state *st_, uint8_t *m, size_t mlen_max, size_t *
521513
aegis128l_dec(dst, c + i, blocks);
522514
}
523515
}
524-
*written += i;
525516

526517
left = clen - i;
527518
if (left != 0) {
@@ -540,7 +531,6 @@ state_decrypt_update(aegis128l_state *st_, uint8_t *m, size_t mlen_max, size_t *
540531
}
541532
}
542533
st->pos = left;
543-
*written += left;
544534
}
545535

546536
memcpy(st->blocks, blocks, sizeof blocks);

src/aegis128l/implementations.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ typedef struct aegis128l_implementation {
2121
const uint8_t *k);
2222
int (*state_encrypt_update)(aegis128l_state *st_, uint8_t *c, const uint8_t *m, size_t mlen);
2323
int (*state_encrypt_final)(aegis128l_state *st_, uint8_t *mac, size_t maclen);
24-
int (*state_decrypt_update)(aegis128l_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
25-
const uint8_t *c, size_t clen);
24+
int (*state_decrypt_update)(aegis128l_state *st_, uint8_t *m, const uint8_t *c, size_t clen);
2625
int (*state_decrypt_final)(aegis128l_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
2726
const uint8_t *mac, size_t maclen);
2827
void (*state_mac_init)(aegis128l_mac_state *st_, const uint8_t *npub, const uint8_t *k);

src/aegis128x2/aegis128x2.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ aegis128x2_state_encrypt_final(aegis128x2_state *st_, uint8_t *mac, size_t macle
122122
}
123123

124124
int
125-
aegis128x2_state_decrypt_update(aegis128x2_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
126-
const uint8_t *c, size_t clen)
125+
aegis128x2_state_decrypt_update(aegis128x2_state *st_, uint8_t *m, const uint8_t *c, size_t clen)
127126
{
128-
return implementation->state_decrypt_update(st_, m, mlen_max, written, c, clen);
127+
return implementation->state_decrypt_update(st_, m, c, clen);
129128
}
130129

131130
int

src/aegis128x2/aegis128x2_common.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,7 @@ state_encrypt_final(aegis128x2_state *st_, uint8_t *mac, size_t maclen)
561561
}
562562

563563
static int
564-
state_decrypt_update(aegis128x2_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
565-
const uint8_t *c, size_t clen)
564+
state_decrypt_update(aegis128x2_state *st_, uint8_t *m, const uint8_t *c, size_t clen)
566565
{
567566
aegis_blocks blocks;
568567
_aegis128x2_state *const st =
@@ -573,14 +572,8 @@ state_decrypt_update(aegis128x2_state *st_, uint8_t *m, size_t mlen_max, size_t
573572

574573
memcpy(blocks, st->blocks, sizeof blocks);
575574

576-
*written = 0;
577575
st->mlen += clen;
578576

579-
if (m != NULL && mlen_max < clen) {
580-
errno = ERANGE;
581-
return -1;
582-
}
583-
584577
// Handle leftover keystream from previous call
585578
if (st->pos != 0) {
586579
const size_t available = RATE - st->pos;
@@ -597,7 +590,6 @@ state_decrypt_update(aegis128x2_state *st_, uint8_t *m, size_t mlen_max, size_t
597590
}
598591
}
599592
st->pos += n;
600-
*written += n;
601593
if (m != NULL) {
602594
m += n;
603595
}
@@ -625,7 +617,6 @@ state_decrypt_update(aegis128x2_state *st_, uint8_t *m, size_t mlen_max, size_t
625617
aegis128x2_dec(dst, c + i, blocks);
626618
}
627619
}
628-
*written += i;
629620

630621
left = clen - i;
631622
if (left != 0) {
@@ -644,7 +635,6 @@ state_decrypt_update(aegis128x2_state *st_, uint8_t *m, size_t mlen_max, size_t
644635
}
645636
}
646637
st->pos = left;
647-
*written += left;
648638
}
649639

650640
memcpy(st->blocks, blocks, sizeof blocks);
@@ -668,7 +658,6 @@ state_decrypt_final(aegis128x2_state *st_, uint8_t *m, size_t mlen_max, size_t *
668658
memcpy(blocks, st->blocks, sizeof blocks);
669659

670660
if (written != NULL) {
671-
*written = 0;
672661
}
673662

674663
// Plaintext was already output during _update; absorb cached plaintext into state

src/aegis128x2/implementations.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ typedef struct aegis128x2_implementation {
2121
const uint8_t *k);
2222
int (*state_encrypt_update)(aegis128x2_state *st_, uint8_t *c, const uint8_t *m, size_t mlen);
2323
int (*state_encrypt_final)(aegis128x2_state *st_, uint8_t *mac, size_t maclen);
24-
int (*state_decrypt_update)(aegis128x2_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
25-
const uint8_t *c, size_t clen);
24+
int (*state_decrypt_update)(aegis128x2_state *st_, uint8_t *m, const uint8_t *c, size_t clen);
2625
int (*state_decrypt_final)(aegis128x2_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
2726
const uint8_t *mac, size_t maclen);
2827
void (*state_mac_init)(aegis128x2_mac_state *st_, const uint8_t *npub, const uint8_t *k);

src/aegis128x4/aegis128x4.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,9 @@ aegis128x4_state_encrypt_final(aegis128x4_state *st_, uint8_t *mac, size_t macle
123123
}
124124

125125
int
126-
aegis128x4_state_decrypt_update(aegis128x4_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
127-
const uint8_t *c, size_t clen)
126+
aegis128x4_state_decrypt_update(aegis128x4_state *st_, uint8_t *m, const uint8_t *c, size_t clen)
128127
{
129-
return implementation->state_decrypt_update(st_, m, mlen_max, written, c, clen);
128+
return implementation->state_decrypt_update(st_, m, c, clen);
130129
}
131130

132131
int

src/aegis128x4/aegis128x4_common.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,7 @@ state_encrypt_final(aegis128x4_state *st_, uint8_t *mac, size_t maclen)
575575
}
576576

577577
static int
578-
state_decrypt_update(aegis128x4_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
579-
const uint8_t *c, size_t clen)
578+
state_decrypt_update(aegis128x4_state *st_, uint8_t *m, const uint8_t *c, size_t clen)
580579
{
581580
aegis_blocks blocks;
582581
_aegis128x4_state *const st =
@@ -587,14 +586,8 @@ state_decrypt_update(aegis128x4_state *st_, uint8_t *m, size_t mlen_max, size_t
587586

588587
memcpy(blocks, st->blocks, sizeof blocks);
589588

590-
*written = 0;
591589
st->mlen += clen;
592590

593-
if (m != NULL && mlen_max < clen) {
594-
errno = ERANGE;
595-
return -1;
596-
}
597-
598591
// Handle leftover keystream from previous call
599592
if (st->pos != 0) {
600593
const size_t available = RATE - st->pos;
@@ -611,7 +604,6 @@ state_decrypt_update(aegis128x4_state *st_, uint8_t *m, size_t mlen_max, size_t
611604
}
612605
}
613606
st->pos += n;
614-
*written += n;
615607
if (m != NULL) {
616608
m += n;
617609
}
@@ -638,7 +630,6 @@ state_decrypt_update(aegis128x4_state *st_, uint8_t *m, size_t mlen_max, size_t
638630
aegis128x4_dec(dst, c + i, blocks);
639631
}
640632
}
641-
*written += i;
642633

643634
left = clen - i;
644635
if (left != 0) {
@@ -658,7 +649,6 @@ state_decrypt_update(aegis128x4_state *st_, uint8_t *m, size_t mlen_max, size_t
658649
}
659650
}
660651
st->pos = left;
661-
*written += left;
662652
}
663653

664654
memcpy(st->blocks, blocks, sizeof blocks);
@@ -682,7 +672,6 @@ state_decrypt_final(aegis128x4_state *st_, uint8_t *m, size_t mlen_max, size_t *
682672
memcpy(blocks, st->blocks, sizeof blocks);
683673

684674
if (written != NULL) {
685-
*written = 0;
686675
}
687676

688677
if (st->pos != 0) {

src/aegis128x4/implementations.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ typedef struct aegis128x4_implementation {
2121
const uint8_t *k);
2222
int (*state_encrypt_update)(aegis128x4_state *st_, uint8_t *c, const uint8_t *m, size_t mlen);
2323
int (*state_encrypt_final)(aegis128x4_state *st_, uint8_t *mac, size_t maclen);
24-
int (*state_decrypt_update)(aegis128x4_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
25-
const uint8_t *c, size_t clen);
24+
int (*state_decrypt_update)(aegis128x4_state *st_, uint8_t *m, const uint8_t *c, size_t clen);
2625
int (*state_decrypt_final)(aegis128x4_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
2726
const uint8_t *mac, size_t maclen);
2827
void (*state_mac_init)(aegis128x4_mac_state *st_, const uint8_t *npub, const uint8_t *k);

src/aegis256/aegis256.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,9 @@ aegis256_state_encrypt_final(aegis256_state *st_, uint8_t *mac, size_t maclen)
121121
}
122122

123123
int
124-
aegis256_state_decrypt_update(aegis256_state *st_, uint8_t *m, size_t mlen_max, size_t *written,
125-
const uint8_t *c, size_t clen)
124+
aegis256_state_decrypt_update(aegis256_state *st_, uint8_t *m, const uint8_t *c, size_t clen)
126125
{
127-
return implementation->state_decrypt_update(st_, m, mlen_max, written, c, clen);
126+
return implementation->state_decrypt_update(st_, m, c, clen);
128127
}
129128

130129
int

0 commit comments

Comments
 (0)