aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/common.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common.c54
1 files changed, 21 insertions, 33 deletions
diff --git a/src/common.c b/src/common.c
index 5f87155..332c66a 100644
--- a/src/common.c
+++ b/src/common.c
@@ -36,11 +36,10 @@ AesBlock256 make_aes_block256(int hi7, int hi6, int hi5, int hi4, int lo3, int l
AesBlockString128 format_aes_block128(AesBlock128* block)
{
- int i;
- char *cursor;
AesBlockString128 result;
+ char *cursor = result.str;
- for (i = 0, cursor = result.str; i < 16; ++i, cursor += 2)
+ for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", *((unsigned char*) block + 15 - i));
*cursor = '\0';
@@ -49,13 +48,12 @@ AesBlockString128 format_aes_block128(AesBlock128* block)
AesBlockString192 format_aes_block192(AesBlock192* block)
{
- int i;
AesBlockString192 result;
char *cursor = result.str;
- for (i = 0; i < 8; ++i, cursor += 2)
+ for (int i = 0; i < 8; ++i, cursor += 2)
sprintf(cursor, "%02x", *((unsigned char*) &block->hi + 7 - i));
- for (i = 0; i < 16; ++i, cursor += 2)
+ for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", *((unsigned char*) &block->lo + 15 - i));
*cursor = '\0';
@@ -64,13 +62,12 @@ AesBlockString192 format_aes_block192(AesBlock192* block)
AesBlockString256 format_aes_block256(AesBlock256* block)
{
- int i;
AesBlockString256 result;
char *cursor = result.str;
- for (i = 0; i < 16; ++i, cursor += 2)
+ for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", *((unsigned char*) &block->hi + 15 - i));
- for (i = 0; i < 16; ++i, cursor += 2)
+ for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", *((unsigned char*) &block->lo + 15 - i));
*cursor = '\0';
@@ -79,11 +76,10 @@ AesBlockString256 format_aes_block256(AesBlock256* block)
AesBlockString128 format_aes_block128_fips_style(AesBlock128* block)
{
- int i;
- char *cursor;
AesBlockString128 result;
+ char *cursor = result.str;
- for (i = 0, cursor = result.str; i < 16; ++i, cursor += 2)
+ for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", *((unsigned char*) block + i));
*cursor = '\0';
@@ -92,13 +88,12 @@ AesBlockString128 format_aes_block128_fips_style(AesBlock128* block)
AesBlockString192 format_aes_block192_fips_style(AesBlock192* block)
{
- int i;
AesBlockString192 result;
char *cursor = result.str;
- for (i = 0; i < 16; ++i, cursor += 2)
+ for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", *((unsigned char*) &block->lo + i));
- for (i = 0; i < 8; ++i, cursor += 2)
+ for (int i = 0; i < 8; ++i, cursor += 2)
sprintf(cursor, "%02x", *((unsigned char*) &block->hi + i));
*cursor = '\0';
@@ -107,13 +102,12 @@ AesBlockString192 format_aes_block192_fips_style(AesBlock192* block)
AesBlockString256 format_aes_block256_fips_style(AesBlock256* block)
{
- int i;
AesBlockString256 result;
char *cursor = result.str;
- for (i = 0; i < 16; ++i, cursor += 2)
+ for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", *((unsigned char*) &block->lo + i));
- for (i = 0; i < 16; ++i, cursor += 2)
+ for (int i = 0; i < 16; ++i, cursor += 2)
sprintf(cursor, "%02x", *((unsigned char*) &block->hi + i));
*cursor = '\0';
@@ -122,16 +116,15 @@ AesBlockString256 format_aes_block256_fips_style(AesBlock256* block)
AesBlockMatrixString128 format_aes_block128_fips_matrix_style(AesBlock128* block)
{
- int i, j;
__declspec(align(16)) unsigned char bytes[4][4];
AesBlockMatrixString128 result;
char* cursor = result.str;
_mm_store_si128((AesBlock128*) bytes, *block);
- for (i = 0; i < 4; ++i, cursor += 3)
+ for (int i = 0; i < 4; ++i, cursor += 3)
{
- for (j = 0; j < 3; ++j, cursor += 3)
+ for (int j = 0; j < 3; ++j, cursor += 3)
sprintf(cursor, "%02x ", bytes[j][i]);
sprintf(cursor, "%02x\n", bytes[3][i]);
}
@@ -142,7 +135,6 @@ AesBlockMatrixString128 format_aes_block128_fips_matrix_style(AesBlock128* block
AesBlockMatrixString192 format_aes_block192_fips_matrix_style(AesBlock192* block)
{
- int i, j;
__declspec(align(16)) unsigned char bytes[8][4];
AesBlockMatrixString192 result;
char* cursor = result.str;
@@ -150,9 +142,9 @@ AesBlockMatrixString192 format_aes_block192_fips_matrix_style(AesBlock192* block
_mm_store_si128((AesBlock128*) bytes, block->lo);
_mm_store_si128((AesBlock128*) bytes + 1, block->hi);
- for (i = 0; i < 4; ++i, cursor += 3)
+ for (int i = 0; i < 4; ++i, cursor += 3)
{
- for (j = 0; j < 5; ++j, cursor += 3)
+ for (int j = 0; j < 5; ++j, cursor += 3)
sprintf(cursor, "%02x ", bytes[j][i]);
sprintf(cursor, "%02x\n", bytes[5][i]);
}
@@ -163,7 +155,6 @@ AesBlockMatrixString192 format_aes_block192_fips_matrix_style(AesBlock192* block
AesBlockMatrixString256 format_aes_block256_fips_matrix_style(AesBlock256* block)
{
- int i, j;
__declspec(align(16)) unsigned char bytes[8][4];
AesBlockMatrixString256 result;
char* cursor = result.str;
@@ -171,9 +162,9 @@ AesBlockMatrixString256 format_aes_block256_fips_matrix_style(AesBlock256* block
_mm_store_si128((AesBlock128*) bytes, block->lo);
_mm_store_si128((AesBlock128*) bytes + 1, block->hi);
- for (i = 0; i < 4; ++i, cursor += 3)
+ for (int i = 0; i < 4; ++i, cursor += 3)
{
- for (j = 0; j < 7; ++j, cursor += 3)
+ for (int j = 0; j < 7; ++j, cursor += 3)
sprintf(cursor, "%02x ", bytes[j][i]);
sprintf(cursor, "%02x\n", bytes[7][i]);
}
@@ -229,8 +220,7 @@ void print_aes_block256_fips_matrix_style(AesBlock256* block)
int parse_aes_block128(AesBlock128* block, const char* src)
{
- int n;
- int xs[4];
+ int n, 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;
@@ -240,8 +230,7 @@ int parse_aes_block128(AesBlock128* block, const char* src)
int parse_aes_block192(AesBlock192* block, const char* src)
{
- int n;
- int xs[6];
+ int n, 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;
@@ -251,8 +240,7 @@ int parse_aes_block192(AesBlock192* block, const char* src)
int parse_aes_block256(AesBlock256* block, const char* src)
{
- int n;
- int xs[8];
+ int n, 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;