diff options
Diffstat (limited to '')
-rw-r--r-- | src/aes192.asm | 32 | ||||
-rw-r--r-- | src/aes256.asm | 78 | ||||
-rw-r--r-- | src/common.c | 54 |
3 files changed, 76 insertions, 88 deletions
diff --git a/src/aes192.asm b/src/aes192.asm index 21e0fa1..2cba7ba 100644 --- a/src/aes192.asm +++ b/src/aes192.asm @@ -114,22 +114,22 @@ movdqa [ecx + 10h], xmm1 ; sets w[4], w[5] add ecx, 18h ; ecx = &w[6] - aeskeygenassist xmm7, xmm1, 1 ; xmm7[63:32] = RotWord(SubWord(w[5]))^Rcon, - call gen_round_key ; sets w[6], w[7], w[8], w[9], w[10], w[11] - aeskeygenassist xmm7, xmm1, 2 ; xmm7[63:32] = RotWord(SubWord(w[11]))^Rcon - call gen_round_key ; sets w[12], w[13], w[14], w[15], w[16], w[17] - aeskeygenassist xmm7, xmm1, 4 ; xmm7[63:32] = RotWord(SubWord(w[17]))^Rcon - call gen_round_key ; sets w[18], w[19], w[20], w[21], w[22], w[23] - aeskeygenassist xmm7, xmm1, 8 ; xmm7[63:32] = RotWord(SubWord(w[23]))^Rcon - call gen_round_key ; sets w[24], w[25], w[26], w[27], w[28], w[29] - aeskeygenassist xmm7, xmm1, 10h ; xmm7[63:32] = RotWord(SubWord(w[29]))^Rcon - call gen_round_key ; sets w[30], w[31], w[32], w[33], w[34], w[35] - aeskeygenassist xmm7, xmm1, 20h ; xmm7[63:32] = RotWord(SubWord(w[35]))^Rcon - call gen_round_key ; sets w[36], w[37], w[38], w[39], w[40], w[41] - aeskeygenassist xmm7, xmm1, 40h ; xmm7[63:32] = RotWord(SubWord(w[41]))^Rcon - call gen_round_key ; sets w[42], w[43], w[44], w[45], w[46], w[47] - aeskeygenassist xmm7, xmm1, 80h ; xmm7[63:32] = RotWord(SubWord(w[49]))^Rcon - call gen_round_key ; sets w[48], w[49], w[50], w[51], w[52], w[53] // FIXME + aeskeygenassist xmm7, xmm1, 1 ; xmm7[63:32] = RotWord(SubWord(w[5]))^Rcon, + call gen_round_key ; sets w[6], w[7], w[8], w[9], w[10], w[11] + aeskeygenassist xmm7, xmm1, 2 ; xmm7[63:32] = RotWord(SubWord(w[11]))^Rcon + call gen_round_key ; sets w[12], w[13], w[14], w[15], w[16], w[17] + aeskeygenassist xmm7, xmm1, 4 ; xmm7[63:32] = RotWord(SubWord(w[17]))^Rcon + call gen_round_key ; sets w[18], w[19], w[20], w[21], w[22], w[23] + aeskeygenassist xmm7, xmm1, 8 ; xmm7[63:32] = RotWord(SubWord(w[23]))^Rcon + call gen_round_key ; sets w[24], w[25], w[26], w[27], w[28], w[29] + aeskeygenassist xmm7, xmm1, 10h ; xmm7[63:32] = RotWord(SubWord(w[29]))^Rcon + call gen_round_key ; sets w[30], w[31], w[32], w[33], w[34], w[35] + aeskeygenassist xmm7, xmm1, 20h ; xmm7[63:32] = RotWord(SubWord(w[35]))^Rcon + call gen_round_key ; sets w[36], w[37], w[38], w[39], w[40], w[41] + aeskeygenassist xmm7, xmm1, 40h ; xmm7[63:32] = RotWord(SubWord(w[41]))^Rcon + call gen_round_key ; sets w[42], w[43], w[44], w[45], w[46], w[47] + aeskeygenassist xmm7, xmm1, 80h ; xmm7[63:32] = RotWord(SubWord(w[49]))^Rcon + call gen_round_key ; sets w[48], w[49], w[50], w[51], w[52], w[53] ret diff --git a/src/aes256.asm b/src/aes256.asm index e59a253..a2bee04 100644 --- a/src/aes256.asm +++ b/src/aes256.asm @@ -128,57 +128,57 @@ movdqa [ecx + 10h], xmm1 ; sets w[4], w[5], w[6], w[7] lea ecx, [ecx + 20h] ; ecx = &w[8] - aeskeygenassist xmm7, xmm1, 1h ; xmm7[127:96] = RotWord(SubWord(w[7]))^Rcon - pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] - call gen_round_key ; sets w[8], w[9], w[10], w[11] + aeskeygenassist xmm7, xmm1, 1h ; xmm7[127:96] = RotWord(SubWord(w[7]))^Rcon + pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] + call gen_round_key ; sets w[8], w[9], w[10], w[11] - aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[11]) - pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] - call gen_round_key ; sets w[12], w[13], w[14], w[15] + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[11]) + pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] + call gen_round_key ; sets w[12], w[13], w[14], w[15] - aeskeygenassist xmm7, xmm1, 2h ; xmm7[127:96] = RotWord(SubWord(w[15]))^Rcon - pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] - call gen_round_key ; sets w[16], w[17], w[18], w[19] + aeskeygenassist xmm7, xmm1, 2h ; xmm7[127:96] = RotWord(SubWord(w[15]))^Rcon + pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] + call gen_round_key ; sets w[16], w[17], w[18], w[19] - aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[19]) - pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] - call gen_round_key ; sets w[20], w[21], w[22], w[23] + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[19]) + pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] + call gen_round_key ; sets w[20], w[21], w[22], w[23] - aeskeygenassist xmm7, xmm1, 4h ; xmm7[127:96] = RotWord(SubWord(w[23]))^Rcon - pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] - call gen_round_key ; sets w[24], w[25], w[26], w[27] + aeskeygenassist xmm7, xmm1, 4h ; xmm7[127:96] = RotWord(SubWord(w[23]))^Rcon + pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] + call gen_round_key ; sets w[24], w[25], w[26], w[27] - aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[27]) - pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] - call gen_round_key ; sets w[28], w[29], w[30], w[31] + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[27]) + pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] + call gen_round_key ; sets w[28], w[29], w[30], w[31] - aeskeygenassist xmm7, xmm1, 8h ; xmm7[127:96] = RotWord(SubWord(w[31]))^Rcon - pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] - call gen_round_key ; sets w[32], w[33], w[34], w[35] + aeskeygenassist xmm7, xmm1, 8h ; xmm7[127:96] = RotWord(SubWord(w[31]))^Rcon + pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] + call gen_round_key ; sets w[32], w[33], w[34], w[35] - aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[35]) - pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] - call gen_round_key ; sets w[36], w[37], w[38], w[39] + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[35]) + pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] + call gen_round_key ; sets w[36], w[37], w[38], w[39] - aeskeygenassist xmm7, xmm1, 10h ; xmm7[127:96] = RotWord(SubWord(w[39]))^Rcon - pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] - call gen_round_key ; sets w[40], w[41], w[42], w[43] + aeskeygenassist xmm7, xmm1, 10h ; xmm7[127:96] = RotWord(SubWord(w[39]))^Rcon + pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] + call gen_round_key ; sets w[40], w[41], w[42], w[43] - aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[43]) - pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] - call gen_round_key ; sets w[44], w[45], w[46], w[47] + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[43]) + pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] + call gen_round_key ; sets w[44], w[45], w[46], w[47] - aeskeygenassist xmm7, xmm1, 20h ; xmm7[127:96] = RotWord(SubWord(w[47]))^Rcon - pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] - call gen_round_key ; sets w[48], w[49], w[50], w[51] + aeskeygenassist xmm7, xmm1, 20h ; xmm7[127:96] = RotWord(SubWord(w[47]))^Rcon + pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] + call gen_round_key ; sets w[48], w[49], w[50], w[51] - aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[51]) - pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] - call gen_round_key ; sets w[52], w[53], w[54], w[55] + aeskeygenassist xmm7, xmm1, 0 ; xmm7[95:64] = SubWord(w[51]) + pshufd xmm7, xmm7, 0AAh ; xmm7[127:96] = xmm7[63:32] = xmm7[31:0] = xmm7[95:64] + call gen_round_key ; sets w[52], w[53], w[54], w[55] - aeskeygenassist xmm7, xmm1, 40h ; xmm7[127:96] = RotWord(SubWord(w[55]))^Rcon - pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] - call gen_round_key ; sets w[56], w[57], w[58], w[59] + aeskeygenassist xmm7, xmm1, 40h ; xmm7[127:96] = RotWord(SubWord(w[55]))^Rcon + pshufd xmm7, xmm7, 0FFh ; xmm7[95:64] = xmm7[63:32] = xmm7[31:0] = xmm7[127:96] + call gen_round_key ; sets w[56], w[57], w[58], w[59] ret 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; |