diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-05-24 17:34:58 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-05-24 17:34:58 +0300 |
commit | db3d9ced588c5b65472df5df450cd3df015551bc (patch) | |
tree | 40f7b48beea3832454c1ee26c8ffd04106d657b7 | |
parent | add block formatting/printing functions (diff) | |
download | aes-tools-db3d9ced588c5b65472df5df450cd3df015551bc.tar.gz aes-tools-db3d9ced588c5b65472df5df450cd3df015551bc.zip |
bugfix
Diffstat (limited to '')
-rw-r--r-- | src/common.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/common.c b/src/common.c index c15da4e..50d9886 100644 --- a/src/common.c +++ b/src/common.c @@ -49,11 +49,13 @@ AesBlockString128 format_aes_block128(AesBlock128* block) AesBlockString192 format_aes_block192(AesBlock192* block) { int i; - char *cursor; AesBlockString192 result; + char *cursor = result.str; - for (i = 0, cursor = result.str; i < 24; ++i, cursor += 2) - sprintf(cursor, "%02x", *((unsigned char*) block + 15 - i)); + for (i = 0; i < 8; ++i, cursor += 2) + sprintf(cursor, "%02x", *((unsigned char*) &block->hi + 7 - i)); + for (i = 0; i < 16; ++i, cursor += 2) + sprintf(cursor, "%02x", *((unsigned char*) &block->lo + 15 - i)); *cursor = '\0'; return result; @@ -62,11 +64,13 @@ AesBlockString192 format_aes_block192(AesBlock192* block) AesBlockString256 format_aes_block256(AesBlock256* block) { int i; - char *cursor; AesBlockString256 result; + char *cursor = result.str; - for (i = 0, cursor = result.str; i < 32; ++i, cursor += 2) - sprintf(cursor, "%02x", *((unsigned char*) block + 15 - i)); + for (i = 0; i < 16; ++i, cursor += 2) + sprintf(cursor, "%02x", *((unsigned char*) &block->hi + 15 - i)); + for (i = 0; i < 16; ++i, cursor += 2) + sprintf(cursor, "%02x", *((unsigned char*) &block->lo + 15 - i)); *cursor = '\0'; return result; @@ -88,11 +92,13 @@ AesBlockString128 format_aes_block128_fips_style(AesBlock128* block) AesBlockString192 format_aes_block192_fips_style(AesBlock192* block) { int i; - char *cursor; AesBlockString192 result; + char *cursor = result.str; - for (i = 0, cursor = result.str; i < 24; ++i, cursor += 2) - sprintf(cursor, "%02x", *((unsigned char*) block + i)); + for (i = 0; i < 16; ++i, cursor += 2) + sprintf(cursor, "%02x", *((unsigned char*) &block->lo + i)); + for (i = 0; i < 8; ++i, cursor += 2) + sprintf(cursor, "%02x", *((unsigned char*) &block->hi + i)); *cursor = '\0'; return result; @@ -101,11 +107,13 @@ AesBlockString192 format_aes_block192_fips_style(AesBlock192* block) AesBlockString256 format_aes_block256_fips_style(AesBlock256* block) { int i; - char *cursor; AesBlockString256 result; + char *cursor = result.str; - for (i = 0, cursor = result.str; i < 32; ++i, cursor += 2) - sprintf(cursor, "%02x", *((unsigned char*) block + i)); + for (i = 0; i < 16; ++i, cursor += 2) + sprintf(cursor, "%02x", *((unsigned char*) &block->lo + i)); + for (i = 0; i < 16; ++i, cursor += 2) + sprintf(cursor, "%02x", *((unsigned char*) &block->hi + i)); *cursor = '\0'; return result; |