Skip to content

Commit

Permalink
Add the ability to clone MAC states
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed May 11, 2024
1 parent a59935d commit 7ed815a
Show file tree
Hide file tree
Showing 50 changed files with 291 additions and 29 deletions.
6 changes: 6 additions & 0 deletions src/aegis128l/aegis128l.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ aegis128l_mac_verify(aegis128l_state *st_, const uint8_t *mac, size_t maclen)
}
}

void
aegis128l_mac_state_clone(aegis128l_state *dst, const aegis128l_state *src)
{
implementation->state_clone(dst, src);
}

int
aegis128l_pick_best_implementation(void)
{
Expand Down
1 change: 1 addition & 0 deletions src/aegis128l/aegis128l_aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct aegis128l_implementation aegis128l_aesni_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis128l/aegis128l_armcrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct aegis128l_implementation aegis128l_armcrypto_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
11 changes: 11 additions & 0 deletions src/aegis128l/aegis128l_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,4 +573,15 @@ state_mac_final(aegis128l_state *st_, uint8_t *mac, size_t maclen)
aegis128l_mac(mac, maclen, st->adlen, 0, st->state);

return 0;
}

static void
state_clone(aegis128l_state *dst, const aegis128l_state *src)
{
_aegis128l_state *const dst_ =
(_aegis128l_state *) ((((uintptr_t) &dst->opaque) + (RATE - 1)) & ~(uintptr_t) (RATE - 1));
const _aegis128l_state *const src_ =
(const _aegis128l_state *) ((((uintptr_t) &src->opaque) + (RATE - 1)) &
~(uintptr_t) (RATE - 1));
*dst_ = *src_;
}
1 change: 1 addition & 0 deletions src/aegis128l/aegis128l_soft.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct aegis128l_implementation aegis128l_soft_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

#endif
1 change: 1 addition & 0 deletions src/aegis128l/implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct aegis128l_implementation {
size_t *written, const uint8_t *mac, size_t maclen);
int (*state_mac_update)(aegis128l_state *st_, const uint8_t *ad, size_t adlen);
int (*state_mac_final)(aegis128l_state *st_, uint8_t *mac, size_t maclen);
void (*state_clone)(aegis128l_state *dst, const aegis128l_state *src);
} aegis128l_implementation;

#endif
6 changes: 6 additions & 0 deletions src/aegis128x2/aegis128x2.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ aegis128x2_mac_verify(aegis128x2_state *st_, const uint8_t *mac, size_t maclen)
}
}

void
aegis128x2_mac_state_clone(aegis128x2_state *dst, const aegis128x2_state *src)
{
implementation->state_clone(dst, src);
}

int
aegis128x2_pick_best_implementation(void)
{
Expand Down
1 change: 1 addition & 0 deletions src/aegis128x2/aegis128x2_aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct aegis128x2_implementation aegis128x2_aesni_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis128x2/aegis128x2_armcrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct aegis128x2_implementation aegis128x2_armcrypto_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis128x2/aegis128x2_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct aegis128x2_implementation aegis128x2_avx2_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
11 changes: 11 additions & 0 deletions src/aegis128x2/aegis128x2_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,4 +607,15 @@ state_mac_final(aegis128x2_state *st_, uint8_t *mac, size_t maclen)
aegis128x2_mac(mac, maclen, st->adlen, 0, st->state);

return 0;
}

static void
state_clone(aegis128x2_state *dst, const aegis128x2_state *src)
{
_aegis128x2_state *const dst_ =
(_aegis128x2_state *) ((((uintptr_t) &dst->opaque) + (RATE - 1)) & ~(uintptr_t) (RATE - 1));
const _aegis128x2_state *const src_ =
(const _aegis128x2_state *) ((((uintptr_t) &src->opaque) + (RATE - 1)) &
~(uintptr_t) (RATE - 1));
*dst_ = *src_;
}
1 change: 1 addition & 0 deletions src/aegis128x2/aegis128x2_soft.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct aegis128x2_implementation aegis128x2_soft_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

#endif
2 changes: 1 addition & 1 deletion src/aegis128x2/implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct aegis128x2_implementation {
size_t *written, const uint8_t *mac, size_t maclen);
int (*state_mac_update)(aegis128x2_state *st_, const uint8_t *ad, size_t adlen);
int (*state_mac_final)(aegis128x2_state *st_, uint8_t *mac, size_t maclen);

void (*state_clone)(aegis128x2_state *dst, const aegis128x2_state *src);
} aegis128x2_implementation;

#endif
6 changes: 6 additions & 0 deletions src/aegis128x4/aegis128x4.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ aegis128x4_mac_verify(aegis128x4_state *st_, const uint8_t *mac, size_t maclen)
}
}

void
aegis128x4_mac_state_clone(aegis128x4_state *dst, const aegis128x4_state *src)
{
implementation->state_clone(dst, src);
}

int
aegis128x4_pick_best_implementation(void)
{
Expand Down
1 change: 1 addition & 0 deletions src/aegis128x4/aegis128x4_aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct aegis128x4_implementation aegis128x4_aesni_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis128x4/aegis128x4_armcrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct aegis128x4_implementation aegis128x4_armcrypto_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis128x4/aegis128x4_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct aegis128x4_implementation aegis128x4_avx2_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis128x4/aegis128x4_avx512.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct aegis128x4_implementation aegis128x4_avx512_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
11 changes: 11 additions & 0 deletions src/aegis128x4/aegis128x4_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,15 @@ state_mac_final(aegis128x4_state *st_, uint8_t *mac, size_t maclen)
aegis128x4_mac(mac, maclen, st->adlen, 0, st->state);

return 0;
}

static void
state_clone(aegis128x4_state *dst, const aegis128x4_state *src)
{
_aegis128x4_state *const dst_ =
(_aegis128x4_state *) ((((uintptr_t) &dst->opaque) + (RATE - 1)) & ~(uintptr_t) (RATE - 1));
const _aegis128x4_state *const src_ =
(const _aegis128x4_state *) ((((uintptr_t) &src->opaque) + (RATE - 1)) &
~(uintptr_t) (RATE - 1));
*dst_ = *src_;
}
1 change: 1 addition & 0 deletions src/aegis128x4/aegis128x4_soft.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct aegis128x4_implementation aegis128x4_soft_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

#endif
1 change: 1 addition & 0 deletions src/aegis128x4/implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct aegis128x4_implementation {
size_t *written, const uint8_t *mac, size_t maclen);
int (*state_mac_update)(aegis128x4_state *st_, const uint8_t *ad, size_t adlen);
int (*state_mac_final)(aegis128x4_state *st_, uint8_t *mac, size_t maclen);
void (*state_clone)(aegis128x4_state *dst, const aegis128x4_state *src);
} aegis128x4_implementation;

#endif
6 changes: 6 additions & 0 deletions src/aegis256/aegis256.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ aegis256_mac_verify(aegis256_state *st_, const uint8_t *mac, size_t maclen)
}
}

void
aegis256_mac_state_clone(aegis256_state *dst, const aegis256_state *src)
{
implementation->state_clone(dst, src);
}

int
aegis256_pick_best_implementation(void)
{
Expand Down
1 change: 1 addition & 0 deletions src/aegis256/aegis256_aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct aegis256_implementation aegis256_aesni_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis256/aegis256_armcrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct aegis256_implementation aegis256_armcrypto_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
11 changes: 11 additions & 0 deletions src/aegis256/aegis256_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,15 @@ state_mac_final(aegis256_state *st_, uint8_t *mac, size_t maclen)
aegis256_mac(mac, maclen, st->adlen, 0, st->state);

return 0;
}

static void
state_clone(aegis256_state *dst, const aegis256_state *src)
{
_aegis256_state *const dst_ =
(_aegis256_state *) ((((uintptr_t) &dst->opaque) + (RATE - 1)) & ~(uintptr_t) (RATE - 1));
const _aegis256_state *const src_ =
(const _aegis256_state *) ((((uintptr_t) &src->opaque) + (RATE - 1)) &
~(uintptr_t) (RATE - 1));
*dst_ = *src_;
}
1 change: 1 addition & 0 deletions src/aegis256/aegis256_soft.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct aegis256_implementation aegis256_soft_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

#endif
1 change: 1 addition & 0 deletions src/aegis256/implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct aegis256_implementation {
size_t *written, const uint8_t *mac, size_t maclen);
int (*state_mac_update)(aegis256_state *st_, const uint8_t *ad, size_t adlen);
int (*state_mac_final)(aegis256_state *st_, uint8_t *mac, size_t maclen);
void (*state_clone)(aegis256_state *dst, const aegis256_state *src);
} aegis256_implementation;

#endif
6 changes: 6 additions & 0 deletions src/aegis256x2/aegis256x2.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ aegis256x2_mac_verify(aegis256x2_state *st_, const uint8_t *mac, size_t maclen)
}
}

void
aegis256x2_mac_state_clone(aegis256x2_state *dst, const aegis256x2_state *src)
{
implementation->state_clone(dst, src);
}

int
aegis256x2_pick_best_implementation(void)
{
Expand Down
1 change: 1 addition & 0 deletions src/aegis256x2/aegis256x2_aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct aegis256x2_implementation aegis256x2_aesni_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis256x2/aegis256x2_armcrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct aegis256x2_implementation aegis256x2_armcrypto_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis256x2/aegis256x2_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct aegis256x2_implementation aegis256x2_avx2_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
11 changes: 11 additions & 0 deletions src/aegis256x2/aegis256x2_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -608,4 +608,15 @@ state_mac_final(aegis256x2_state *st_, uint8_t *mac, size_t maclen)
aegis256x2_mac(mac, maclen, st->adlen, 0, st->state);

return 0;
}

static void
state_clone(aegis256x2_state *dst, const aegis256x2_state *src)
{
_aegis256x2_state *const dst_ =
(_aegis256x2_state *) ((((uintptr_t) &dst->opaque) + (RATE - 1)) & ~(uintptr_t) (RATE - 1));
const _aegis256x2_state *const src_ =
(const _aegis256x2_state *) ((((uintptr_t) &src->opaque) + (RATE - 1)) &
~(uintptr_t) (RATE - 1));
*dst_ = *src_;
}
1 change: 1 addition & 0 deletions src/aegis256x2/aegis256x2_soft.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct aegis256x2_implementation aegis256x2_soft_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

#endif
1 change: 1 addition & 0 deletions src/aegis256x2/implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct aegis256x2_implementation {
size_t *written, const uint8_t *mac, size_t maclen);
int (*state_mac_update)(aegis256x2_state *st_, const uint8_t *ad, size_t adlen);
int (*state_mac_final)(aegis256x2_state *st_, uint8_t *mac, size_t maclen);
void (*state_clone)(aegis256x2_state *dst, const aegis256x2_state *src);
} aegis256x2_implementation;

#endif
6 changes: 6 additions & 0 deletions src/aegis256x4/aegis256x4.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ aegis256x4_mac_verify(aegis256x4_state *st_, const uint8_t *mac, size_t maclen)
}
}

void
aegis256x4_mac_state_clone(aegis256x4_state *dst, const aegis256x4_state *src)
{
implementation->state_clone(dst, src);
}

int
aegis256x4_pick_best_implementation(void)
{
Expand Down
1 change: 1 addition & 0 deletions src/aegis256x4/aegis256x4_aesni.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ struct aegis256x4_implementation aegis256x4_aesni_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis256x4/aegis256x4_armcrypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct aegis256x4_implementation aegis256x4_armcrypto_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis256x4/aegis256x4_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct aegis256x4_implementation aegis256x4_avx2_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
1 change: 1 addition & 0 deletions src/aegis256x4/aegis256x4_avx512.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct aegis256x4_implementation aegis256x4_avx512_implementation = {
.state_decrypt_detached_final = state_decrypt_detached_final,
.state_mac_update = state_mac_update,
.state_mac_final = state_mac_final,
.state_clone = state_clone,
};

# ifdef __clang__
Expand Down
Loading

0 comments on commit 7ed815a

Please sign in to comment.