aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/common.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2015-05-25 02:39:39 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2015-05-25 02:39:39 +0300
commitd331218958ff2aed6bd6fffa4154413f3ccd3f7d (patch)
tree51285eba7bb8dabe09873696d2b51548893e248d /src/common.c
parentexamples: aes128 -> aes128ecb, aes192 -> aes192ecb (diff)
downloadaes-tools-d331218958ff2aed6bd6fffa4154413f3ccd3f7d.tar.gz
aes-tools-d331218958ff2aed6bd6fffa4154413f3ccd3f7d.zip
add block parsing functions
Diffstat (limited to '')
-rw-r--r--src/common.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c
index a221eb3..5f87155 100644
--- a/src/common.c
+++ b/src/common.c
@@ -11,6 +11,7 @@
#include <intrin.h>
#include <stdio.h>
+#include <string.h>
AesBlock128 make_aes_block128(int hi3, int hi2, int lo1, int lo0)
{
@@ -225,3 +226,36 @@ void print_aes_block256_fips_matrix_style(AesBlock256* block)
{
printf("%s", format_aes_block256_fips_matrix_style(block).str);
}
+
+int parse_aes_block128(AesBlock128* block, const char* src)
+{
+ int n;
+ int xs[4];
+ if (sscanf(src, "%8x%8x%8x%8x%n", &xs[0], &xs[1], &xs[2], &xs[3], &n) != 4
+ || n != strlen(src))
+ return 1;
+ *block = make_aes_block128(xs[0], xs[1], xs[2], xs[3]);
+ return 0;
+}
+
+int parse_aes_block192(AesBlock192* block, const char* src)
+{
+ int n;
+ int xs[6];
+ if (sscanf(src, "%8x%8x%8x%8x%8x%8x%n", &xs[0], &xs[1], &xs[2], &xs[3], &xs[4], &xs[5], &n) != 6
+ || n != strlen(src))
+ return 1;
+ *block = make_aes_block192(xs[0], xs[1], xs[2], xs[3], xs[4], xs[5]);
+ return 0;
+}
+
+int parse_aes_block256(AesBlock256* block, const char* src)
+{
+ int n;
+ int xs[8];
+ if (sscanf(src, "%8x%8x%8x%8x%8x%8x%8x%8x%n", &xs[0], &xs[1], &xs[2], &xs[3], &xs[4], &xs[5], &xs[6], &xs[7], &n) != 8
+ || n != strlen(src))
+ return 1;
+ *block = make_aes_block256(xs[0], xs[1], xs[2], xs[3], xs[4], xs[5], xs[6], xs[7]);
+ return 0;
+}