summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/constants.c2
-rw-r--r--test/common.mk2
-rw-r--r--test/i-128/test-ae-decrypt.c42
-rw-r--r--test/i-128/test-ae-encrypt.c44
-rw-r--r--test/i-128/test-tbc-decrypt.c9
-rw-r--r--test/i-128/test-tbc-encrypt.c9
-rw-r--r--test/i-128/test-tweakey.c5
-rw-r--r--test/test-helpers.h33
8 files changed, 86 insertions, 60 deletions
diff --git a/src/constants.c b/src/constants.c
index 29da1d8..7a322e4 100644
--- a/src/constants.c
+++ b/src/constants.c
@@ -2,7 +2,7 @@
const uint8_t h[8] = {
- 1, 5, 3, 0, 4, 7, 2, 6
+ 1, 5, 0, 3, 7, 4, 2, 6
};
const uint8_t P[6][256] = {
diff --git a/test/common.mk b/test/common.mk
index be3955f..8ca11a9 100644
--- a/test/common.mk
+++ b/test/common.mk
@@ -51,7 +51,7 @@ $(results_dir)/traces-%: $(results_dir)/test/traces-%.o
@ echo "LD $@"
$(Q) gcc $^ $(LDFLAGS) -o $@
-$(results_dir)/test/%.o: %.c | $(results_dir)/test
+$(results_dir)/test/%.o: %.c $(test_dir)/test-helpers.h | $(results_dir)/test
@ echo "CC $@"
$(Q) gcc -c $< $(CFLAGS) -o $@
diff --git a/test/i-128/test-ae-decrypt.c b/test/i-128/test-ae-decrypt.c
index 8ae6308..446ce14 100644
--- a/test/i-128/test-ae-decrypt.c
+++ b/test/i-128/test-ae-decrypt.c
@@ -47,18 +47,18 @@ const vector VECTORS[] = {
},
.ciphertext_len = 64,
.ciphertext = (uint8_t[]) {
- 0x92, 0xf0, 0xd5, 0x7c, 0x31, 0x0f, 0x73, 0x38,
- 0xbb, 0xc6, 0x11, 0xfb, 0xe7, 0x49, 0xd2, 0xcd,
- 0xae, 0x29, 0x67, 0xeb, 0xcd, 0xca, 0xd1, 0x07,
- 0xf0, 0x2d, 0x2a, 0x14, 0x8e, 0xec, 0x4d, 0xae,
- 0x92, 0xe3, 0x96, 0x65, 0x96, 0x84, 0xe3, 0x8d,
- 0x48, 0x36, 0x0e, 0x11, 0xec, 0xe2, 0x0a, 0x4e,
- 0xe4, 0x3c, 0xc0, 0xb5, 0xf8, 0xe7, 0xb9, 0x7a,
- 0xc1, 0xf4, 0x3b, 0xa7, 0x8b, 0xaa, 0x89, 0xe6
+ 0xd2, 0xff, 0x52, 0x66, 0xd4, 0xe9, 0x1f, 0x54,
+ 0x27, 0x55, 0xf3, 0x6d, 0x7f, 0xb8, 0xcd, 0x32,
+ 0x5d, 0x78, 0xb6, 0x50, 0x16, 0x49, 0xea, 0xf9,
+ 0xb6, 0x3d, 0x09, 0x35, 0x24, 0xc3, 0xea, 0x51,
+ 0x6e, 0xa0, 0x4e, 0x5c, 0xd4, 0x1a, 0x6b, 0x3d,
+ 0x2f, 0x91, 0x26, 0x7a, 0xff, 0xc1, 0xa2, 0xa4,
+ 0x17, 0x53, 0xed, 0x39, 0xbe, 0x2d, 0x81, 0xcf,
+ 0x4d, 0x32, 0xb2, 0x91, 0xe5, 0xee, 0xd8, 0xd2
},
.tag = {
- 0xf3, 0x78, 0x87, 0xc3, 0xb0, 0x4a, 0xe7, 0x10,
- 0x8c, 0x14, 0x67, 0x0b, 0x38, 0x9c, 0xc0, 0x2c
+ 0x11, 0x21, 0x9f, 0x1e, 0x94, 0x0a, 0x7c, 0x80,
+ 0x65, 0xc2, 0x92, 0xf7, 0xc1, 0xc1, 0x18, 0x91
},
.message = (uint8_t[]) {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@@ -95,19 +95,19 @@ const vector VECTORS[] = {
},
.ciphertext_len = 66,
.ciphertext = (uint8_t[]) {
- 0x92, 0xf0, 0xd5, 0x7c, 0x31, 0x0f, 0x73, 0x38,
- 0xbb, 0xc6, 0x11, 0xfb, 0xe7, 0x49, 0xd2, 0xcd,
- 0xae, 0x29, 0x67, 0xeb, 0xcd, 0xca, 0xd1, 0x07,
- 0xf0, 0x2d, 0x2a, 0x14, 0x8e, 0xec, 0x4d, 0xae,
- 0x92, 0xe3, 0x96, 0x65, 0x96, 0x84, 0xe3, 0x8d,
- 0x48, 0x36, 0x0e, 0x11, 0xec, 0xe2, 0x0a, 0x4e,
- 0xe4, 0x3c, 0xc0, 0xb5, 0xf8, 0xe7, 0xb9, 0x7a,
- 0xc1, 0xf4, 0x3b, 0xa7, 0x8b, 0xaa, 0x89, 0xe6,
- 0x2d, 0x48
+ 0xd2, 0xff, 0x52, 0x66, 0xd4, 0xe9, 0x1f, 0x54,
+ 0x27, 0x55, 0xf3, 0x6d, 0x7f, 0xb8, 0xcd, 0x32,
+ 0x5d, 0x78, 0xb6, 0x50, 0x16, 0x49, 0xea, 0xf9,
+ 0xb6, 0x3d, 0x09, 0x35, 0x24, 0xc3, 0xea, 0x51,
+ 0x6e, 0xa0, 0x4e, 0x5c, 0xd4, 0x1a, 0x6b, 0x3d,
+ 0x2f, 0x91, 0x26, 0x7a, 0xff, 0xc1, 0xa2, 0xa4,
+ 0x17, 0x53, 0xed, 0x39, 0xbe, 0x2d, 0x81, 0xcf,
+ 0x4d, 0x32, 0xb2, 0x91, 0xe5, 0xee, 0xd8, 0xd2,
+ 0xea, 0xbc
},
.tag = {
- 0x12, 0x99, 0x0c, 0x33, 0x41, 0x59, 0x34, 0xa7,
- 0xd9, 0xa6, 0xcc, 0xb2, 0x90, 0xfe, 0x6d, 0x3d
+ 0x72, 0x4b, 0xd9, 0x6a, 0x6c, 0xff, 0xc7, 0x32,
+ 0x11, 0xe7, 0x56, 0xe1, 0xb1, 0xb8, 0x47, 0x4a
},
.message = (uint8_t[]) {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
diff --git a/test/i-128/test-ae-encrypt.c b/test/i-128/test-ae-encrypt.c
index 9a7dce0..425303e 100644
--- a/test/i-128/test-ae-encrypt.c
+++ b/test/i-128/test-ae-encrypt.c
@@ -57,18 +57,18 @@ const vector VECTORS[] = {
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0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main()
if (memcmp(ciphertext, v->ciphertext, v->message_len) != 0)
{
REPORT_DIFFERENCE(v->name, "ciphertext");
+ dump_c_initializer(v->message_len, ciphertext);
diff++;
}
if (memcmp(tag, v->tag, TAG_BYTES) != 0)
{
REPORT_DIFFERENCE(v->name, "tag");
+ dump_c_initializer(TAG_BYTES, tag);
diff++;
}
}
diff --git a/test/i-128/test-tbc-decrypt.c b/test/i-128/test-tbc-decrypt.c
index 9bd6996..d888f3c 100644
--- a/test/i-128/test-tbc-decrypt.c
+++ b/test/i-128/test-tbc-decrypt.c
@@ -37,8 +37,8 @@ const vector VECTORS[] = {
0x2d, 0x54, 0x58, 0xc0, 0x1d, 0xcc, 0x8a, 0x25
},
.message = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0xc5, 0xbe, 0x64, 0xec, 0x80, 0x91, 0x49, 0x68,
+ 0x2f, 0x14, 0x10, 0xb0, 0xb8, 0x42, 0xa0, 0x50
}
},
{
@@ -57,8 +57,8 @@ const vector VECTORS[] = {
0xf9, 0xd2, 0xba, 0x6c, 0x41, 0xf4, 0x45, 0x7f
},
.message = {
- 0xbc, 0xd7, 0xf0, 0x29, 0x84, 0xb6, 0xc8, 0xf9,
- 0x9c, 0x9d, 0x1d, 0xbd, 0x0d, 0x30, 0x94, 0x0b
+ 0x3b, 0xfb, 0xdc, 0xae, 0x56, 0x9c, 0x52, 0xfd,
+ 0x50, 0x89, 0x77, 0xf6, 0xcb, 0x6a, 0x26, 0xe9
}
}
};
@@ -76,6 +76,7 @@ int main()
if (memcmp(message, v->message, sizeof(message)) != 0)
{
REPORT_DIFFERENCE(v->name, "decrypted message");
+ dump_c_initializer(BLOCK_BYTES, message);
diff++;
}
}
diff --git a/test/i-128/test-tbc-encrypt.c b/test/i-128/test-tbc-encrypt.c
index 60cc9cf..8d369e3 100644
--- a/test/i-128/test-tbc-encrypt.c
+++ b/test/i-128/test-tbc-encrypt.c
@@ -37,8 +37,8 @@ const vector VECTORS[] = {
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
},
.ciphertext = {
- 0xf9, 0xe3, 0x95, 0x3c, 0x04, 0xf6, 0x2d, 0x9c,
- 0x2d, 0x54, 0x58, 0xc0, 0x1d, 0xcc, 0x8a, 0x25
+ 0x84, 0x04, 0xad, 0x43, 0x63, 0xb5, 0x30, 0xd0,
+ 0x68, 0x4f, 0xb9, 0x4f, 0x2d, 0xeb, 0xb1, 0xd1
}
},
{
@@ -57,8 +57,8 @@ const vector VECTORS[] = {
0x9c, 0x9d, 0x1d, 0xbd, 0x0d, 0x30, 0x94, 0x0b
},
.ciphertext = {
- 0xf4, 0x4a, 0x06, 0x30, 0x7d, 0xd2, 0xb2, 0x5a,
- 0xf9, 0xd2, 0xba, 0x6c, 0x41, 0xf4, 0x45, 0x7f
+ 0xc9, 0xa1, 0xc4, 0x1c, 0xed, 0x4b, 0xc9, 0x86,
+ 0x8d, 0x44, 0xb5, 0x61, 0x53, 0xa4, 0x34, 0xb1
}
}
};
@@ -76,6 +76,7 @@ int main()
if (memcmp(ciphertext, v->ciphertext, sizeof(ciphertext)) != 0)
{
REPORT_DIFFERENCE(v->name, "ciphertext");
+ dump_c_initializer(BLOCK_BYTES, ciphertext);
diff++;
}
}
diff --git a/test/i-128/test-tweakey.c b/test/i-128/test-tweakey.c
index 2b0bad5..e332c66 100644
--- a/test/i-128/test-tweakey.c
+++ b/test/i-128/test-tweakey.c
@@ -63,7 +63,7 @@ const vector VECTORS[] = {
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
},
.last_rtk = {
- 0xa5, 0x92, 0x9b, 0xa7, 0x86, 0x8f, 0xb3, 0xae
+ 0xb8, 0xba, 0x86, 0x8f, 0xae, 0x92, 0x9b, 0xb3
}
},
{
@@ -78,7 +78,7 @@ const vector VECTORS[] = {
0x7f, 0xf4, 0x23, 0x4d, 0x3d, 0xd5, 0xf9, 0x9b
},
.last_rtk = {
- 0xed, 0xe3, 0x39, 0xac, 0x5e, 0xa6, 0xf9, 0xf1
+ 0xb3, 0xf2, 0x5e, 0xa6, 0xf1, 0xe3, 0x39, 0xf9
}
}
};
@@ -105,6 +105,7 @@ int main()
if (memcmp(rtk, v->last_rtk, sizeof(rtk)) != 0)
{
REPORT_DIFFERENCE(v->name, "last RTK");
+ dump_c_initializer(ROUND_TWEAKEY_BYTES, rtk);
diff++;
}
}
diff --git a/test/test-helpers.h b/test/test-helpers.h
index 1991542..67b15a1 100644
--- a/test/test-helpers.h
+++ b/test/test-helpers.h
@@ -1,7 +1,7 @@
#ifndef TEST_HELPERS_H
#define TEST_HELPERS_H
-#include <stdint.h>
+#include <inttypes.h>
#include <stdio.h>
#include "parameters.h"
@@ -21,13 +21,34 @@
} while (0)
-static inline FILE* open_dump_file(const char *folder, const char* vector, const char *name)
+/* Used to update vectors when constants change. */
+static inline void dump_c_initializer(size_t len, uint8_t buf[len])
{
- size_t filename_len = snprintf(NULL, 0, "%s/%s_%s.txt", folder, vector, name);
- char filename[filename_len+1];
- snprintf(filename, sizeof(filename), "%s/%s_%s.txt", folder, vector, name);
- return fopen(filename, "w");
+ printf("{\n");
+
+ const size_t columns = 8;
+
+ for (size_t i=0; i<len; i++)
+ {
+ printf("0x%02"PRIx8, buf[i]);
+
+ if (i == len-1)
+ {
+ printf("\n");
+ }
+ else if (i%columns == columns-1)
+ {
+ printf(",\n");
+ }
+ else
+ {
+ printf(", ");
+ }
+ }
+
+ printf("}\n");
}
+
#endif /* TEST_HELPERS_H */