diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-05-25 02:39:39 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-05-25 02:39:39 +0300 |
commit | d331218958ff2aed6bd6fffa4154413f3ccd3f7d (patch) | |
tree | 51285eba7bb8dabe09873696d2b51548893e248d | |
parent | examples: aes128 -> aes128ecb, aes192 -> aes192ecb (diff) | |
download | aes-tools-d331218958ff2aed6bd6fffa4154413f3ccd3f7d.tar.gz aes-tools-d331218958ff2aed6bd6fffa4154413f3ccd3f7d.zip |
add block parsing functions
Diffstat (limited to '')
-rw-r--r-- | include/aesni/data.h | 4 | ||||
-rw-r--r-- | src/common.c | 34 |
2 files changed, 38 insertions, 0 deletions
diff --git a/include/aesni/data.h b/include/aesni/data.h index f039192..49cf5e5 100644 --- a/include/aesni/data.h +++ b/include/aesni/data.h @@ -61,3 +61,7 @@ void print_aes_block256_fips_style(AesBlock256*); void print_aes_block128_fips_matrix_style(AesBlock128*); void print_aes_block192_fips_matrix_style(AesBlock192*); void print_aes_block256_fips_matrix_style(AesBlock256*); + +int parse_aes_block128(AesBlock128*, const char*); +int parse_aes_block192(AesBlock192*, const char*); +int parse_aes_block256(AesBlock256*, const char*); 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; +} |