summaryrefslogtreecommitdiff
path: root/crypto_aead/lilliputaei128v1/ref/tweakey.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto_aead/lilliputaei128v1/ref/tweakey.c')
-rw-r--r--crypto_aead/lilliputaei128v1/ref/tweakey.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/crypto_aead/lilliputaei128v1/ref/tweakey.c b/crypto_aead/lilliputaei128v1/ref/tweakey.c
index 79fa225..173f4be 100644
--- a/crypto_aead/lilliputaei128v1/ref/tweakey.c
+++ b/crypto_aead/lilliputaei128v1/ref/tweakey.c
@@ -1,8 +1,14 @@
+#include <stdbool.h>
#include <string.h>
+#include <inttypes.h> /* debug */
#include "tweakey.h"
+#define LANE_BITS 64
+#define LANE_BYTES (LANE_BITS/8)
+
+
static void _dump_buffer(FILE *output, size_t len, const uint8_t buf[len], int indent)
{
for (size_t line=0; line<len/8; line++)
@@ -31,6 +37,8 @@ void tweakey_state_init(
memcpy(TK->TK, tweak, TWEAK_BYTES);
memcpy(TK->TK+TWEAK_BYTES, key, KEY_BYTES);
+ TK->debug = debug;
+
fprintf(debug, " Tweak is :\n");
_dump_buffer(debug, TWEAK_BYTES, tweak, 5);
fprintf(debug, " Key is :\n");
@@ -41,16 +49,36 @@ void tweakey_state_init(
void tweakey_state_extract(
- __attribute__((unused)) const tweakey_state *TK,
- __attribute__((unused)) uint8_t round_tweakey[ROUND_TWEAKEY_BYTES], /* output */
- __attribute__((unused)) uint8_t i /* round constant */
+ const tweakey_state *TK,
+ uint8_t round_tweakey[ROUND_TWEAKEY_BYTES], /* output */
+ uint8_t i /* round constant */
)
{
-
+ memset(round_tweakey, 0, ROUND_TWEAKEY_BYTES);
+
+ for (const uint8_t *lane=TK->TK; lane<TK->TK+TWEAKEY_BYTES; lane+=LANE_BYTES)
+ {
+ for (size_t j=0; j<LANE_BYTES; j++)
+ {
+ round_tweakey[j] ^= lane[j];
+ }
+ }
+
+ round_tweakey[0] ^= i;
+
+ fprintf(TK->debug, " Extracting Subtweakey round %"PRIu8"\n", i);
+ _dump_buffer(TK->debug, sizeof(TK->TK), TK->TK, 5);
+ fprintf(TK->debug, " Subtweakey :\n");
+ _dump_buffer(TK->debug, ROUND_TWEAKEY_BYTES, round_tweakey, 5);
}
-void tweakey_state_update(__attribute__((unused)) tweakey_state *TK)
+void tweakey_state_update(tweakey_state *TK)
{
-
+ fprintf(TK->debug, " Input Tweakey :\n");
+ _dump_buffer(TK->debug, sizeof(TK->TK), TK->TK, 10);
+ fprintf(TK->debug, " Post permutation Tweakey :\n");
+ _dump_buffer(TK->debug, sizeof(TK->TK), TK->TK, 10);
+ fprintf(TK->debug, " Post multiplication Tweakey :\n");
+ _dump_buffer(TK->debug, sizeof(TK->TK), TK->TK, 10);
}