From 46bfd602ab63ee4b89b6b6283bdc2c6fb102e110 Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 29 Sep 2008 04:01:02 +0000 Subject: Normalize asm names --- src/hash/md4_ia32/md4.cpp | 2 +- src/hash/md4_ia32/md4_ia32.S | 135 +++++++++++++++++++++++ src/hash/md4_ia32/md4core.S | 135 ----------------------- src/hash/md5_ia32/md5.cpp | 2 +- src/hash/md5_ia32/md5_ia32.S | 164 ++++++++++++++++++++++++++++ src/hash/md5_ia32/md5core.S | 164 ---------------------------- src/hash/sha1_amd64/sha160.cpp | 2 +- src/hash/sha1_amd64/sha1_asm.S | 4 +- src/hash/sha1_ia32/sha1_asm.S | 242 ----------------------------------------- src/hash/sha1_ia32/sha1_ia32.S | 242 +++++++++++++++++++++++++++++++++++++++++ 10 files changed, 546 insertions(+), 546 deletions(-) create mode 100644 src/hash/md4_ia32/md4_ia32.S delete mode 100644 src/hash/md4_ia32/md4core.S create mode 100644 src/hash/md5_ia32/md5_ia32.S delete mode 100644 src/hash/md5_ia32/md5core.S delete mode 100644 src/hash/sha1_ia32/sha1_asm.S create mode 100644 src/hash/sha1_ia32/sha1_ia32.S (limited to 'src/hash') diff --git a/src/hash/md4_ia32/md4.cpp b/src/hash/md4_ia32/md4.cpp index e3dc79012..12466e86e 100644 --- a/src/hash/md4_ia32/md4.cpp +++ b/src/hash/md4_ia32/md4.cpp @@ -8,7 +8,7 @@ namespace Botan { -extern "C" void md4_core(u32bit[4], const byte[64], u32bit[16]); +extern "C" void botan_md4_core_asm(u32bit[4], const byte[64], u32bit[16]); /************************************************* * MD4 Compression Function * diff --git a/src/hash/md4_ia32/md4_ia32.S b/src/hash/md4_ia32/md4_ia32.S new file mode 100644 index 000000000..410c540e9 --- /dev/null +++ b/src/hash/md4_ia32/md4_ia32.S @@ -0,0 +1,135 @@ +/************************************************* +* MD4 Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include + +START_LISTING(md4_ia32.S) + +START_FUNCTION(botan_md4_core_asm) + SPILL_REGS() + +#define PUSHED 4 + + ASSIGN(EBP, ARG(2)) /* input block */ + ASSIGN(EDI, ARG(3)) /* expanded words */ + + ZEROIZE(ESI) + +START_LOOP(.LOAD_INPUT) + ADD_IMM(ESI, 4) + + ASSIGN(EAX, ARRAY4(EBP, 0)) + ASSIGN(EBX, ARRAY4(EBP, 1)) + ASSIGN(ECX, ARRAY4(EBP, 2)) + ASSIGN(EDX, ARRAY4(EBP, 3)) + + ADD_IMM(EBP, 16) + + ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-4), EAX) + ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-3), EBX) + ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-2), ECX) + ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-1), EDX) +LOOP_UNTIL_EQ(ESI, 16, .LOAD_INPUT) + + ASSIGN(EBP, ARG(1)) + ASSIGN(EAX, ARRAY4(EBP, 0)) + ASSIGN(EBX, ARRAY4(EBP, 1)) + ASSIGN(ECX, ARRAY4(EBP, 2)) + ASSIGN(EDX, ARRAY4(EBP, 3)) + +#define MSG EDI +#define T1 ESI +#define T2 EBP + +#define FF(A, B, C, D, N, S) \ + ASSIGN(T1, ARRAY4(MSG, N)) ; \ + ASSIGN(T2, C) ; \ + XOR(T2, D) ; \ + AND(T2, B) ; \ + XOR(T2, D) ; \ + ADD(A, T1) ; \ + ADD(A, T2) ; \ + ROTL_IMM(A, S) ; + +#define GG(A, B, C, D, N, S) \ + ASSIGN(T1, ARRAY4(MSG, N)) ; \ + ASSIGN(T2, B) ; \ + OR(T2, C) ; \ + AND(T2, D) ; \ + ADD3_IMM(A, T1, 0x5A827999) ; \ + ASSIGN(T1, B) ; \ + AND(T1, C) ; \ + OR(T2, T1) ; \ + ADD(A, T2) ; \ + ROTL_IMM(A, S) ; + +#define HH(A, B, C, D, N, S) \ + ASSIGN(T1, ARRAY4(MSG, N)) ; \ + ASSIGN(T2, B) ; \ + XOR(T2, C) ; \ + XOR(T2, D) ; \ + ADD3_IMM(A, T1, 0x6ED9EBA1) ; \ + ADD(A, T2) ; \ + ROTL_IMM(A, S) ; + + FF(EAX,EBX,ECX,EDX, 0, 3); + FF(EDX,EAX,EBX,ECX, 1, 7); + FF(ECX,EDX,EAX,EBX, 2,11); + FF(EBX,ECX,EDX,EAX, 3,19); + FF(EAX,EBX,ECX,EDX, 4, 3); + FF(EDX,EAX,EBX,ECX, 5, 7); + FF(ECX,EDX,EAX,EBX, 6,11); + FF(EBX,ECX,EDX,EAX, 7,19); + FF(EAX,EBX,ECX,EDX, 8, 3); + FF(EDX,EAX,EBX,ECX, 9, 7); + FF(ECX,EDX,EAX,EBX,10,11); + FF(EBX,ECX,EDX,EAX,11,19); + FF(EAX,EBX,ECX,EDX,12, 3); + FF(EDX,EAX,EBX,ECX,13, 7); + FF(ECX,EDX,EAX,EBX,14,11); + FF(EBX,ECX,EDX,EAX,15,19); + + GG(EAX,EBX,ECX,EDX, 0, 3); + GG(EDX,EAX,EBX,ECX, 4, 5); + GG(ECX,EDX,EAX,EBX, 8, 9); + GG(EBX,ECX,EDX,EAX,12,13); + GG(EAX,EBX,ECX,EDX, 1, 3); + GG(EDX,EAX,EBX,ECX, 5, 5); + GG(ECX,EDX,EAX,EBX, 9, 9); + GG(EBX,ECX,EDX,EAX,13,13); + GG(EAX,EBX,ECX,EDX, 2, 3); + GG(EDX,EAX,EBX,ECX, 6, 5); + GG(ECX,EDX,EAX,EBX,10, 9); + GG(EBX,ECX,EDX,EAX,14,13); + GG(EAX,EBX,ECX,EDX, 3, 3); + GG(EDX,EAX,EBX,ECX, 7, 5); + GG(ECX,EDX,EAX,EBX,11, 9); + GG(EBX,ECX,EDX,EAX,15,13); + + HH(EAX,EBX,ECX,EDX, 0, 3); + HH(EDX,EAX,EBX,ECX, 8, 9); + HH(ECX,EDX,EAX,EBX, 4,11); + HH(EBX,ECX,EDX,EAX,12,15); + HH(EAX,EBX,ECX,EDX, 2, 3); + HH(EDX,EAX,EBX,ECX,10, 9); + HH(ECX,EDX,EAX,EBX, 6,11); + HH(EBX,ECX,EDX,EAX,14,15); + HH(EAX,EBX,ECX,EDX, 1, 3); + HH(EDX,EAX,EBX,ECX, 9, 9); + HH(ECX,EDX,EAX,EBX, 5,11); + HH(EBX,ECX,EDX,EAX,13,15); + HH(EAX,EBX,ECX,EDX, 3, 3); + HH(EDX,EAX,EBX,ECX,11, 9); + HH(ECX,EDX,EAX,EBX, 7,11); + HH(EBX,ECX,EDX,EAX,15,15); + + ASSIGN(EBP, ARG(1)) + ADD(ARRAY4(EBP, 0), EAX) + ADD(ARRAY4(EBP, 1), EBX) + ADD(ARRAY4(EBP, 2), ECX) + ADD(ARRAY4(EBP, 3), EDX) + + RESTORE_REGS() +END_FUNCTION(botan_md4_core_asm) diff --git a/src/hash/md4_ia32/md4core.S b/src/hash/md4_ia32/md4core.S deleted file mode 100644 index 662e9924a..000000000 --- a/src/hash/md4_ia32/md4core.S +++ /dev/null @@ -1,135 +0,0 @@ -/************************************************* -* MD4 Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include - -START_LISTING(md4core.S) - -START_FUNCTION(md4_core) - SPILL_REGS() - -#define PUSHED 4 - - ASSIGN(EBP, ARG(2)) /* input block */ - ASSIGN(EDI, ARG(3)) /* expanded words */ - - ZEROIZE(ESI) - -START_LOOP(.LOAD_INPUT) - ADD_IMM(ESI, 4) - - ASSIGN(EAX, ARRAY4(EBP, 0)) - ASSIGN(EBX, ARRAY4(EBP, 1)) - ASSIGN(ECX, ARRAY4(EBP, 2)) - ASSIGN(EDX, ARRAY4(EBP, 3)) - - ADD_IMM(EBP, 16) - - ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-4), EAX) - ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-3), EBX) - ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-2), ECX) - ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-1), EDX) -LOOP_UNTIL_EQ(ESI, 16, .LOAD_INPUT) - - ASSIGN(EBP, ARG(1)) - ASSIGN(EAX, ARRAY4(EBP, 0)) - ASSIGN(EBX, ARRAY4(EBP, 1)) - ASSIGN(ECX, ARRAY4(EBP, 2)) - ASSIGN(EDX, ARRAY4(EBP, 3)) - -#define MSG EDI -#define T1 ESI -#define T2 EBP - -#define FF(A, B, C, D, N, S) \ - ASSIGN(T1, ARRAY4(MSG, N)) ; \ - ASSIGN(T2, C) ; \ - XOR(T2, D) ; \ - AND(T2, B) ; \ - XOR(T2, D) ; \ - ADD(A, T1) ; \ - ADD(A, T2) ; \ - ROTL_IMM(A, S) ; - -#define GG(A, B, C, D, N, S) \ - ASSIGN(T1, ARRAY4(MSG, N)) ; \ - ASSIGN(T2, B) ; \ - OR(T2, C) ; \ - AND(T2, D) ; \ - ADD3_IMM(A, T1, 0x5A827999) ; \ - ASSIGN(T1, B) ; \ - AND(T1, C) ; \ - OR(T2, T1) ; \ - ADD(A, T2) ; \ - ROTL_IMM(A, S) ; - -#define HH(A, B, C, D, N, S) \ - ASSIGN(T1, ARRAY4(MSG, N)) ; \ - ASSIGN(T2, B) ; \ - XOR(T2, C) ; \ - XOR(T2, D) ; \ - ADD3_IMM(A, T1, 0x6ED9EBA1) ; \ - ADD(A, T2) ; \ - ROTL_IMM(A, S) ; - - FF(EAX,EBX,ECX,EDX, 0, 3); - FF(EDX,EAX,EBX,ECX, 1, 7); - FF(ECX,EDX,EAX,EBX, 2,11); - FF(EBX,ECX,EDX,EAX, 3,19); - FF(EAX,EBX,ECX,EDX, 4, 3); - FF(EDX,EAX,EBX,ECX, 5, 7); - FF(ECX,EDX,EAX,EBX, 6,11); - FF(EBX,ECX,EDX,EAX, 7,19); - FF(EAX,EBX,ECX,EDX, 8, 3); - FF(EDX,EAX,EBX,ECX, 9, 7); - FF(ECX,EDX,EAX,EBX,10,11); - FF(EBX,ECX,EDX,EAX,11,19); - FF(EAX,EBX,ECX,EDX,12, 3); - FF(EDX,EAX,EBX,ECX,13, 7); - FF(ECX,EDX,EAX,EBX,14,11); - FF(EBX,ECX,EDX,EAX,15,19); - - GG(EAX,EBX,ECX,EDX, 0, 3); - GG(EDX,EAX,EBX,ECX, 4, 5); - GG(ECX,EDX,EAX,EBX, 8, 9); - GG(EBX,ECX,EDX,EAX,12,13); - GG(EAX,EBX,ECX,EDX, 1, 3); - GG(EDX,EAX,EBX,ECX, 5, 5); - GG(ECX,EDX,EAX,EBX, 9, 9); - GG(EBX,ECX,EDX,EAX,13,13); - GG(EAX,EBX,ECX,EDX, 2, 3); - GG(EDX,EAX,EBX,ECX, 6, 5); - GG(ECX,EDX,EAX,EBX,10, 9); - GG(EBX,ECX,EDX,EAX,14,13); - GG(EAX,EBX,ECX,EDX, 3, 3); - GG(EDX,EAX,EBX,ECX, 7, 5); - GG(ECX,EDX,EAX,EBX,11, 9); - GG(EBX,ECX,EDX,EAX,15,13); - - HH(EAX,EBX,ECX,EDX, 0, 3); - HH(EDX,EAX,EBX,ECX, 8, 9); - HH(ECX,EDX,EAX,EBX, 4,11); - HH(EBX,ECX,EDX,EAX,12,15); - HH(EAX,EBX,ECX,EDX, 2, 3); - HH(EDX,EAX,EBX,ECX,10, 9); - HH(ECX,EDX,EAX,EBX, 6,11); - HH(EBX,ECX,EDX,EAX,14,15); - HH(EAX,EBX,ECX,EDX, 1, 3); - HH(EDX,EAX,EBX,ECX, 9, 9); - HH(ECX,EDX,EAX,EBX, 5,11); - HH(EBX,ECX,EDX,EAX,13,15); - HH(EAX,EBX,ECX,EDX, 3, 3); - HH(EDX,EAX,EBX,ECX,11, 9); - HH(ECX,EDX,EAX,EBX, 7,11); - HH(EBX,ECX,EDX,EAX,15,15); - - ASSIGN(EBP, ARG(1)) - ADD(ARRAY4(EBP, 0), EAX) - ADD(ARRAY4(EBP, 1), EBX) - ADD(ARRAY4(EBP, 2), ECX) - ADD(ARRAY4(EBP, 3), EDX) - - RESTORE_REGS() -END_FUNCTION(md4_core) diff --git a/src/hash/md5_ia32/md5.cpp b/src/hash/md5_ia32/md5.cpp index cfe48e7e9..04e7673c1 100644 --- a/src/hash/md5_ia32/md5.cpp +++ b/src/hash/md5_ia32/md5.cpp @@ -8,7 +8,7 @@ namespace Botan { -extern "C" void md5_core(u32bit[4], const byte[64], u32bit[16]); +extern "C" void botan_md5_core_asm(u32bit[4], const byte[64], u32bit[16]); /************************************************* * MD5 Compression Function * diff --git a/src/hash/md5_ia32/md5_ia32.S b/src/hash/md5_ia32/md5_ia32.S new file mode 100644 index 000000000..8e1ec2e79 --- /dev/null +++ b/src/hash/md5_ia32/md5_ia32.S @@ -0,0 +1,164 @@ +/************************************************* +* MD5 Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include + +START_LISTING(md5_ia32.S) + +START_FUNCTION(botan_md5_core_asm) + SPILL_REGS() + +#define PUSHED 4 + + ASSIGN(EBP, ARG(2)) /* input block */ + ASSIGN(EDI, ARG(3)) /* expanded words */ + + ZEROIZE(ESI) + +START_LOOP(.LOAD_INPUT) + ADD_IMM(ESI, 4) + + ASSIGN(EAX, ARRAY4(EBP, 0)) + ASSIGN(EBX, ARRAY4(EBP, 1)) + ASSIGN(ECX, ARRAY4(EBP, 2)) + ASSIGN(EDX, ARRAY4(EBP, 3)) + + ADD_IMM(EBP, 16) + + ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-4), EAX) + ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-3), EBX) + ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-2), ECX) + ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-1), EDX) +LOOP_UNTIL_EQ(ESI, 16, .LOAD_INPUT) + + ASSIGN(EBP, ARG(1)) + ASSIGN(EAX, ARRAY4(EBP, 0)) + ASSIGN(EBX, ARRAY4(EBP, 1)) + ASSIGN(ECX, ARRAY4(EBP, 2)) + ASSIGN(EDX, ARRAY4(EBP, 3)) + +#define MSG EDI +#define T1 ESI +#define T2 EBP + +#define FF(A, B, C, D, N, S, MAGIC) \ + ASSIGN(T1, ARRAY4(MSG, N)) ; \ + ASSIGN(T2, C) ; \ + XOR(T2, D) ; \ + AND(T2, B) ; \ + XOR(T2, D) ; \ + ADD3_IMM(A, T1, MAGIC) ; \ + ADD(A, T2) ; \ + ROTL_IMM(A, S) ; \ + ADD(A, B) ; + +#define GG(A, B, C, D, N, S, MAGIC) \ + ASSIGN(T1, ARRAY4(MSG, N)) ; \ + ASSIGN(T2, B) ; \ + XOR(T2, C) ; \ + AND(T2, D) ; \ + XOR(T2, C) ; \ + ADD3_IMM(A, T1, MAGIC) ; \ + ADD(A, T2) ; \ + ROTL_IMM(A, S) ; \ + ADD(A, B) ; + +#define HH(A, B, C, D, N, S, MAGIC) \ + ASSIGN(T1, ARRAY4(MSG, N)) ; \ + ASSIGN(T2, B) ; \ + XOR(T2, C) ; \ + XOR(T2, D) ; \ + ADD3_IMM(A, T1, MAGIC) ; \ + ADD(A, T2) ; \ + ROTL_IMM(A, S) ; \ + ADD(A, B) ; + +#define II(A, B, C, D, N, S, MAGIC) \ + ASSIGN(T1, ARRAY4(MSG, N)) ; \ + ASSIGN(T2, D) ; \ + NOT(T2) ; \ + OR(T2, B) ; \ + XOR(T2, C) ; \ + ADD3_IMM(A, T1, MAGIC) ; \ + ADD(A, T2) ; \ + ROTL_IMM(A, S) ; \ + ADD(A, B) ; + + FF(EAX,EBX,ECX,EDX, 0, 7,0xD76AA478); + FF(EDX,EAX,EBX,ECX, 1,12,0xE8C7B756); + FF(ECX,EDX,EAX,EBX, 2,17,0x242070DB); + FF(EBX,ECX,EDX,EAX, 3,22,0xC1BDCEEE); + FF(EAX,EBX,ECX,EDX, 4, 7,0xF57C0FAF); + FF(EDX,EAX,EBX,ECX, 5,12,0x4787C62A); + FF(ECX,EDX,EAX,EBX, 6,17,0xA8304613); + FF(EBX,ECX,EDX,EAX, 7,22,0xFD469501); + FF(EAX,EBX,ECX,EDX, 8, 7,0x698098D8); + FF(EDX,EAX,EBX,ECX, 9,12,0x8B44F7AF); + FF(ECX,EDX,EAX,EBX,10,17,0xFFFF5BB1); + FF(EBX,ECX,EDX,EAX,11,22,0x895CD7BE); + FF(EAX,EBX,ECX,EDX,12, 7,0x6B901122); + FF(EDX,EAX,EBX,ECX,13,12,0xFD987193); + FF(ECX,EDX,EAX,EBX,14,17,0xA679438E); + FF(EBX,ECX,EDX,EAX,15,22,0x49B40821); + + GG(EAX,EBX,ECX,EDX, 1, 5,0xF61E2562); + GG(EDX,EAX,EBX,ECX, 6, 9,0xC040B340); + GG(ECX,EDX,EAX,EBX,11,14,0x265E5A51); + GG(EBX,ECX,EDX,EAX, 0,20,0xE9B6C7AA); + GG(EAX,EBX,ECX,EDX, 5, 5,0xD62F105D); + GG(EDX,EAX,EBX,ECX,10, 9,0x02441453); + GG(ECX,EDX,EAX,EBX,15,14,0xD8A1E681); + GG(EBX,ECX,EDX,EAX, 4,20,0xE7D3FBC8); + GG(EAX,EBX,ECX,EDX, 9, 5,0x21E1CDE6); + GG(EDX,EAX,EBX,ECX,14, 9,0xC33707D6); + GG(ECX,EDX,EAX,EBX, 3,14,0xF4D50D87); + GG(EBX,ECX,EDX,EAX, 8,20,0x455A14ED); + GG(EAX,EBX,ECX,EDX,13, 5,0xA9E3E905); + GG(EDX,EAX,EBX,ECX, 2, 9,0xFCEFA3F8); + GG(ECX,EDX,EAX,EBX, 7,14,0x676F02D9); + GG(EBX,ECX,EDX,EAX,12,20,0x8D2A4C8A); + + HH(EAX,EBX,ECX,EDX, 5, 4,0xFFFA3942); + HH(EDX,EAX,EBX,ECX, 8,11,0x8771F681); + HH(ECX,EDX,EAX,EBX,11,16,0x6D9D6122); + HH(EBX,ECX,EDX,EAX,14,23,0xFDE5380C); + HH(EAX,EBX,ECX,EDX, 1, 4,0xA4BEEA44); + HH(EDX,EAX,EBX,ECX, 4,11,0x4BDECFA9); + HH(ECX,EDX,EAX,EBX, 7,16,0xF6BB4B60); + HH(EBX,ECX,EDX,EAX,10,23,0xBEBFBC70); + HH(EAX,EBX,ECX,EDX,13, 4,0x289B7EC6); + HH(EDX,EAX,EBX,ECX, 0,11,0xEAA127FA); + HH(ECX,EDX,EAX,EBX, 3,16,0xD4EF3085); + HH(EBX,ECX,EDX,EAX, 6,23,0x04881D05); + HH(EAX,EBX,ECX,EDX, 9, 4,0xD9D4D039); + HH(EDX,EAX,EBX,ECX,12,11,0xE6DB99E5); + HH(ECX,EDX,EAX,EBX,15,16,0x1FA27CF8); + HH(EBX,ECX,EDX,EAX, 2,23,0xC4AC5665); + + II(EAX,EBX,ECX,EDX, 0, 6,0xF4292244); + II(EDX,EAX,EBX,ECX, 7,10,0x432AFF97); + II(ECX,EDX,EAX,EBX,14,15,0xAB9423A7); + II(EBX,ECX,EDX,EAX, 5,21,0xFC93A039); + II(EAX,EBX,ECX,EDX,12, 6,0x655B59C3); + II(EDX,EAX,EBX,ECX, 3,10,0x8F0CCC92); + II(ECX,EDX,EAX,EBX,10,15,0xFFEFF47D); + II(EBX,ECX,EDX,EAX, 1,21,0x85845DD1); + II(EAX,EBX,ECX,EDX, 8, 6,0x6FA87E4F); + II(EDX,EAX,EBX,ECX,15,10,0xFE2CE6E0); + II(ECX,EDX,EAX,EBX, 6,15,0xA3014314); + II(EBX,ECX,EDX,EAX,13,21,0x4E0811A1); + II(EAX,EBX,ECX,EDX, 4, 6,0xF7537E82); + II(EDX,EAX,EBX,ECX,11,10,0xBD3AF235); + II(ECX,EDX,EAX,EBX, 2,15,0x2AD7D2BB); + II(EBX,ECX,EDX,EAX, 9,21,0xEB86D391); + + ASSIGN(EBP, ARG(1)) + ADD(ARRAY4(EBP, 0), EAX) + ADD(ARRAY4(EBP, 1), EBX) + ADD(ARRAY4(EBP, 2), ECX) + ADD(ARRAY4(EBP, 3), EDX) + + RESTORE_REGS() +END_FUNCTION(botan_md5_core_asm) diff --git a/src/hash/md5_ia32/md5core.S b/src/hash/md5_ia32/md5core.S deleted file mode 100644 index 8ebe469f3..000000000 --- a/src/hash/md5_ia32/md5core.S +++ /dev/null @@ -1,164 +0,0 @@ -/************************************************* -* MD5 Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include - -START_LISTING(md5core.S) - -START_FUNCTION(md5_core) - SPILL_REGS() - -#define PUSHED 4 - - ASSIGN(EBP, ARG(2)) /* input block */ - ASSIGN(EDI, ARG(3)) /* expanded words */ - - ZEROIZE(ESI) - -START_LOOP(.LOAD_INPUT) - ADD_IMM(ESI, 4) - - ASSIGN(EAX, ARRAY4(EBP, 0)) - ASSIGN(EBX, ARRAY4(EBP, 1)) - ASSIGN(ECX, ARRAY4(EBP, 2)) - ASSIGN(EDX, ARRAY4(EBP, 3)) - - ADD_IMM(EBP, 16) - - ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-4), EAX) - ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-3), EBX) - ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-2), ECX) - ASSIGN(ARRAY4_INDIRECT(EDI,ESI,-1), EDX) -LOOP_UNTIL_EQ(ESI, 16, .LOAD_INPUT) - - ASSIGN(EBP, ARG(1)) - ASSIGN(EAX, ARRAY4(EBP, 0)) - ASSIGN(EBX, ARRAY4(EBP, 1)) - ASSIGN(ECX, ARRAY4(EBP, 2)) - ASSIGN(EDX, ARRAY4(EBP, 3)) - -#define MSG EDI -#define T1 ESI -#define T2 EBP - -#define FF(A, B, C, D, N, S, MAGIC) \ - ASSIGN(T1, ARRAY4(MSG, N)) ; \ - ASSIGN(T2, C) ; \ - XOR(T2, D) ; \ - AND(T2, B) ; \ - XOR(T2, D) ; \ - ADD3_IMM(A, T1, MAGIC) ; \ - ADD(A, T2) ; \ - ROTL_IMM(A, S) ; \ - ADD(A, B) ; - -#define GG(A, B, C, D, N, S, MAGIC) \ - ASSIGN(T1, ARRAY4(MSG, N)) ; \ - ASSIGN(T2, B) ; \ - XOR(T2, C) ; \ - AND(T2, D) ; \ - XOR(T2, C) ; \ - ADD3_IMM(A, T1, MAGIC) ; \ - ADD(A, T2) ; \ - ROTL_IMM(A, S) ; \ - ADD(A, B) ; - -#define HH(A, B, C, D, N, S, MAGIC) \ - ASSIGN(T1, ARRAY4(MSG, N)) ; \ - ASSIGN(T2, B) ; \ - XOR(T2, C) ; \ - XOR(T2, D) ; \ - ADD3_IMM(A, T1, MAGIC) ; \ - ADD(A, T2) ; \ - ROTL_IMM(A, S) ; \ - ADD(A, B) ; - -#define II(A, B, C, D, N, S, MAGIC) \ - ASSIGN(T1, ARRAY4(MSG, N)) ; \ - ASSIGN(T2, D) ; \ - NOT(T2) ; \ - OR(T2, B) ; \ - XOR(T2, C) ; \ - ADD3_IMM(A, T1, MAGIC) ; \ - ADD(A, T2) ; \ - ROTL_IMM(A, S) ; \ - ADD(A, B) ; - - FF(EAX,EBX,ECX,EDX, 0, 7,0xD76AA478); - FF(EDX,EAX,EBX,ECX, 1,12,0xE8C7B756); - FF(ECX,EDX,EAX,EBX, 2,17,0x242070DB); - FF(EBX,ECX,EDX,EAX, 3,22,0xC1BDCEEE); - FF(EAX,EBX,ECX,EDX, 4, 7,0xF57C0FAF); - FF(EDX,EAX,EBX,ECX, 5,12,0x4787C62A); - FF(ECX,EDX,EAX,EBX, 6,17,0xA8304613); - FF(EBX,ECX,EDX,EAX, 7,22,0xFD469501); - FF(EAX,EBX,ECX,EDX, 8, 7,0x698098D8); - FF(EDX,EAX,EBX,ECX, 9,12,0x8B44F7AF); - FF(ECX,EDX,EAX,EBX,10,17,0xFFFF5BB1); - FF(EBX,ECX,EDX,EAX,11,22,0x895CD7BE); - FF(EAX,EBX,ECX,EDX,12, 7,0x6B901122); - FF(EDX,EAX,EBX,ECX,13,12,0xFD987193); - FF(ECX,EDX,EAX,EBX,14,17,0xA679438E); - FF(EBX,ECX,EDX,EAX,15,22,0x49B40821); - - GG(EAX,EBX,ECX,EDX, 1, 5,0xF61E2562); - GG(EDX,EAX,EBX,ECX, 6, 9,0xC040B340); - GG(ECX,EDX,EAX,EBX,11,14,0x265E5A51); - GG(EBX,ECX,EDX,EAX, 0,20,0xE9B6C7AA); - GG(EAX,EBX,ECX,EDX, 5, 5,0xD62F105D); - GG(EDX,EAX,EBX,ECX,10, 9,0x02441453); - GG(ECX,EDX,EAX,EBX,15,14,0xD8A1E681); - GG(EBX,ECX,EDX,EAX, 4,20,0xE7D3FBC8); - GG(EAX,EBX,ECX,EDX, 9, 5,0x21E1CDE6); - GG(EDX,EAX,EBX,ECX,14, 9,0xC33707D6); - GG(ECX,EDX,EAX,EBX, 3,14,0xF4D50D87); - GG(EBX,ECX,EDX,EAX, 8,20,0x455A14ED); - GG(EAX,EBX,ECX,EDX,13, 5,0xA9E3E905); - GG(EDX,EAX,EBX,ECX, 2, 9,0xFCEFA3F8); - GG(ECX,EDX,EAX,EBX, 7,14,0x676F02D9); - GG(EBX,ECX,EDX,EAX,12,20,0x8D2A4C8A); - - HH(EAX,EBX,ECX,EDX, 5, 4,0xFFFA3942); - HH(EDX,EAX,EBX,ECX, 8,11,0x8771F681); - HH(ECX,EDX,EAX,EBX,11,16,0x6D9D6122); - HH(EBX,ECX,EDX,EAX,14,23,0xFDE5380C); - HH(EAX,EBX,ECX,EDX, 1, 4,0xA4BEEA44); - HH(EDX,EAX,EBX,ECX, 4,11,0x4BDECFA9); - HH(ECX,EDX,EAX,EBX, 7,16,0xF6BB4B60); - HH(EBX,ECX,EDX,EAX,10,23,0xBEBFBC70); - HH(EAX,EBX,ECX,EDX,13, 4,0x289B7EC6); - HH(EDX,EAX,EBX,ECX, 0,11,0xEAA127FA); - HH(ECX,EDX,EAX,EBX, 3,16,0xD4EF3085); - HH(EBX,ECX,EDX,EAX, 6,23,0x04881D05); - HH(EAX,EBX,ECX,EDX, 9, 4,0xD9D4D039); - HH(EDX,EAX,EBX,ECX,12,11,0xE6DB99E5); - HH(ECX,EDX,EAX,EBX,15,16,0x1FA27CF8); - HH(EBX,ECX,EDX,EAX, 2,23,0xC4AC5665); - - II(EAX,EBX,ECX,EDX, 0, 6,0xF4292244); - II(EDX,EAX,EBX,ECX, 7,10,0x432AFF97); - II(ECX,EDX,EAX,EBX,14,15,0xAB9423A7); - II(EBX,ECX,EDX,EAX, 5,21,0xFC93A039); - II(EAX,EBX,ECX,EDX,12, 6,0x655B59C3); - II(EDX,EAX,EBX,ECX, 3,10,0x8F0CCC92); - II(ECX,EDX,EAX,EBX,10,15,0xFFEFF47D); - II(EBX,ECX,EDX,EAX, 1,21,0x85845DD1); - II(EAX,EBX,ECX,EDX, 8, 6,0x6FA87E4F); - II(EDX,EAX,EBX,ECX,15,10,0xFE2CE6E0); - II(ECX,EDX,EAX,EBX, 6,15,0xA3014314); - II(EBX,ECX,EDX,EAX,13,21,0x4E0811A1); - II(EAX,EBX,ECX,EDX, 4, 6,0xF7537E82); - II(EDX,EAX,EBX,ECX,11,10,0xBD3AF235); - II(ECX,EDX,EAX,EBX, 2,15,0x2AD7D2BB); - II(EBX,ECX,EDX,EAX, 9,21,0xEB86D391); - - ASSIGN(EBP, ARG(1)) - ADD(ARRAY4(EBP, 0), EAX) - ADD(ARRAY4(EBP, 1), EBX) - ADD(ARRAY4(EBP, 2), ECX) - ADD(ARRAY4(EBP, 3), EDX) - - RESTORE_REGS() -END_FUNCTION(md5_core) diff --git a/src/hash/sha1_amd64/sha160.cpp b/src/hash/sha1_amd64/sha160.cpp index cfac02f45..c7fbea25a 100644 --- a/src/hash/sha1_amd64/sha160.cpp +++ b/src/hash/sha1_amd64/sha160.cpp @@ -8,7 +8,7 @@ namespace Botan { -extern "C" void botan_sha160_asm_amd64(u32bit[5], const byte[64], u32bit[80]); +extern "C" void botan_sha160_core_asm(u32bit[5], const byte[64], u32bit[80]); /************************************************* * SHA-160 Compression Function * diff --git a/src/hash/sha1_amd64/sha1_asm.S b/src/hash/sha1_amd64/sha1_asm.S index ecf4a18ce..b94dfbadc 100644 --- a/src/hash/sha1_amd64/sha1_asm.S +++ b/src/hash/sha1_amd64/sha1_asm.S @@ -7,7 +7,7 @@ START_LISTING(sha1_asm.S) -START_FUNCTION(botan_sha160_asm_amd64) +START_FUNCTION(botan_sha160_core_asm) #define DIGEST_ARR %rdi #define INPUT %rsi @@ -255,4 +255,4 @@ ALIGN; ADD(ARRAY4(DIGEST_ARR, 3), B) ADD(ARRAY4(DIGEST_ARR, 4), C) -END_FUNCTION(botan_sha160_asm_amd64) +END_FUNCTION(botan_core_sha160_asm) diff --git a/src/hash/sha1_ia32/sha1_asm.S b/src/hash/sha1_ia32/sha1_asm.S deleted file mode 100644 index 85bc9dc2c..000000000 --- a/src/hash/sha1_ia32/sha1_asm.S +++ /dev/null @@ -1,242 +0,0 @@ -/************************************************* -* SHA-160 Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include - -START_LISTING(sha1_asm.S) - -START_FUNCTION(botan_sha160_asm_ia32) - SPILL_REGS() - -#define PUSHED 4 - - ASSIGN(EDI, ARG(2)) - ASSIGN(EBP, ARG(3)) - - ZEROIZE(ESI) - -START_LOOP(.LOAD_INPUT) - ADD_IMM(ESI, 4) - - ASSIGN(EAX, ARRAY4(EDI, 0)) - ASSIGN(EBX, ARRAY4(EDI, 1)) - ASSIGN(ECX, ARRAY4(EDI, 2)) - ASSIGN(EDX, ARRAY4(EDI, 3)) - - ADD_IMM(EDI, 16) - - BSWAP(EAX) - BSWAP(EBX) - BSWAP(ECX) - BSWAP(EDX) - - ASSIGN(ARRAY4_INDIRECT(EBP,ESI,-4), EAX) - ASSIGN(ARRAY4_INDIRECT(EBP,ESI,-3), EBX) - ASSIGN(ARRAY4_INDIRECT(EBP,ESI,-2), ECX) - ASSIGN(ARRAY4_INDIRECT(EBP,ESI,-1), EDX) -LOOP_UNTIL_EQ(ESI, 16, .LOAD_INPUT) - - ADD2_IMM(EDI, EBP, 64) - -START_LOOP(.EXPANSION) - ADD_IMM(ESI, 4) - - ZEROIZE(EAX) - ASSIGN(EBX, ARRAY4(EDI, -1)) - ASSIGN(ECX, ARRAY4(EDI, -2)) - ASSIGN(EDX, ARRAY4(EDI, -3)) - - XOR(EAX, ARRAY4(EDI, -5)) - XOR(EBX, ARRAY4(EDI, -6)) - XOR(ECX, ARRAY4(EDI, -7)) - XOR(EDX, ARRAY4(EDI, -8)) - - XOR(EAX, ARRAY4(EDI, -11)) - XOR(EBX, ARRAY4(EDI, -12)) - XOR(ECX, ARRAY4(EDI, -13)) - XOR(EDX, ARRAY4(EDI, -14)) - - XOR(EAX, ARRAY4(EDI, -13)) - XOR(EBX, ARRAY4(EDI, -14)) - XOR(ECX, ARRAY4(EDI, -15)) - XOR(EDX, ARRAY4(EDI, -16)) - - ROTL_IMM(EDX, 1) - ROTL_IMM(ECX, 1) - ROTL_IMM(EBX, 1) - XOR(EAX, EDX) - ROTL_IMM(EAX, 1) - - ASSIGN(ARRAY4(EDI, 0), EDX) - ASSIGN(ARRAY4(EDI, 1), ECX) - ASSIGN(ARRAY4(EDI, 2), EBX) - ASSIGN(ARRAY4(EDI, 3), EAX) - - ADD_IMM(EDI, 16) -LOOP_UNTIL_EQ(ESI, 80, .EXPANSION) - -#define MAGIC1 0x5A827999 -#define MAGIC2 0x6ED9EBA1 -#define MAGIC3 0x8F1BBCDC -#define MAGIC4 0xCA62C1D6 - -#define MSG ESP -#define T2 EBP - -#define F1(A, B, C, D, E, F, N) \ - ASSIGN(T2, ARRAY4(MSG, N)) ; \ - ASSIGN(A, F) ; \ - ROTL_IMM(F, 5) ; \ - ADD(F, E) ; \ - ASSIGN(E, C) ; \ - XOR(E, D) ; \ - ADD3_IMM(F, T2, MAGIC1) ; \ - AND(E, B) ; \ - XOR(E, D) ; \ - ROTR_IMM(B, 2) ; \ - ADD(E, F) ; - -#define F2_4(A, B, C, D, E, F, N, MAGIC) \ - ASSIGN(T2, ARRAY4(MSG, N)) ; \ - ASSIGN(A, F) ; \ - ROTL_IMM(F, 5) ; \ - ADD(F, E) ; \ - ASSIGN(E, B) ; \ - XOR(E, C) ; \ - ADD3_IMM(F, T2, MAGIC) ; \ - XOR(E, D) ; \ - ROTR_IMM(B, 2) ; \ - ADD(E, F) ; - -#define F3(A, B, C, D, E, F, N) \ - ASSIGN(T2, ARRAY4(MSG, N)) ; \ - ASSIGN(A, F) ; \ - ROTL_IMM(F, 5) ; \ - ADD(F, E) ; \ - ASSIGN(E, B) ; \ - OR(E, C) ; \ - AND(E, D) ; \ - ADD3_IMM(F, T2, MAGIC3) ; \ - ASSIGN(T2, B) ; \ - AND(T2, C) ; \ - OR(E, T2) ; \ - ROTR_IMM(B, 2) ; \ - ADD(E, F) ; - -#define F2(A, B, C, D, E, F, MSG) \ - F2_4(A, B, C, D, E, F, MSG, MAGIC2) - -#define F4(A, B, C, D, E, F, MSG) \ - F2_4(A, B, C, D, E, F, MSG, MAGIC4) - - ASSIGN(EAX, ARG(1)) - ASSIGN(EDI, ARRAY4(EAX, 0)) - ASSIGN(EBX, ARRAY4(EAX, 1)) - ASSIGN(ECX, ARRAY4(EAX, 2)) - ASSIGN(EDX, ARRAY4(EAX, 3)) - ASSIGN(ESI, ARRAY4(EAX, 4)) - - ASSIGN(ARRAY4(EBP, 80), ESP) - ASSIGN(ESP, EBP) - - /* First Round */ - F1(EAX, EBX, ECX, EDX, ESI, EDI, 0) - F1(EDI, EAX, EBX, ECX, EDX, ESI, 1) - F1(ESI, EDI, EAX, EBX, ECX, EDX, 2) - F1(EDX, ESI, EDI, EAX, EBX, ECX, 3) - F1(ECX, EDX, ESI, EDI, EAX, EBX, 4) - F1(EBX, ECX, EDX, ESI, EDI, EAX, 5) - F1(EAX, EBX, ECX, EDX, ESI, EDI, 6) - F1(EDI, EAX, EBX, ECX, EDX, ESI, 7) - F1(ESI, EDI, EAX, EBX, ECX, EDX, 8) - F1(EDX, ESI, EDI, EAX, EBX, ECX, 9) - F1(ECX, EDX, ESI, EDI, EAX, EBX, 10) - F1(EBX, ECX, EDX, ESI, EDI, EAX, 11) - F1(EAX, EBX, ECX, EDX, ESI, EDI, 12) - F1(EDI, EAX, EBX, ECX, EDX, ESI, 13) - F1(ESI, EDI, EAX, EBX, ECX, EDX, 14) - F1(EDX, ESI, EDI, EAX, EBX, ECX, 15) - F1(ECX, EDX, ESI, EDI, EAX, EBX, 16) - F1(EBX, ECX, EDX, ESI, EDI, EAX, 17) - F1(EAX, EBX, ECX, EDX, ESI, EDI, 18) - F1(EDI, EAX, EBX, ECX, EDX, ESI, 19) - - /* Second Round */ - F2(ESI, EDI, EAX, EBX, ECX, EDX, 20) - F2(EDX, ESI, EDI, EAX, EBX, ECX, 21) - F2(ECX, EDX, ESI, EDI, EAX, EBX, 22) - F2(EBX, ECX, EDX, ESI, EDI, EAX, 23) - F2(EAX, EBX, ECX, EDX, ESI, EDI, 24) - F2(EDI, EAX, EBX, ECX, EDX, ESI, 25) - F2(ESI, EDI, EAX, EBX, ECX, EDX, 26) - F2(EDX, ESI, EDI, EAX, EBX, ECX, 27) - F2(ECX, EDX, ESI, EDI, EAX, EBX, 28) - F2(EBX, ECX, EDX, ESI, EDI, EAX, 29) - F2(EAX, EBX, ECX, EDX, ESI, EDI, 30) - F2(EDI, EAX, EBX, ECX, EDX, ESI, 31) - F2(ESI, EDI, EAX, EBX, ECX, EDX, 32) - F2(EDX, ESI, EDI, EAX, EBX, ECX, 33) - F2(ECX, EDX, ESI, EDI, EAX, EBX, 34) - F2(EBX, ECX, EDX, ESI, EDI, EAX, 35) - F2(EAX, EBX, ECX, EDX, ESI, EDI, 36) - F2(EDI, EAX, EBX, ECX, EDX, ESI, 37) - F2(ESI, EDI, EAX, EBX, ECX, EDX, 38) - F2(EDX, ESI, EDI, EAX, EBX, ECX, 39) - - /* Third Round */ - F3(ECX, EDX, ESI, EDI, EAX, EBX, 40) - F3(EBX, ECX, EDX, ESI, EDI, EAX, 41) - F3(EAX, EBX, ECX, EDX, ESI, EDI, 42) - F3(EDI, EAX, EBX, ECX, EDX, ESI, 43) - F3(ESI, EDI, EAX, EBX, ECX, EDX, 44) - F3(EDX, ESI, EDI, EAX, EBX, ECX, 45) - F3(ECX, EDX, ESI, EDI, EAX, EBX, 46) - F3(EBX, ECX, EDX, ESI, EDI, EAX, 47) - F3(EAX, EBX, ECX, EDX, ESI, EDI, 48) - F3(EDI, EAX, EBX, ECX, EDX, ESI, 49) - F3(ESI, EDI, EAX, EBX, ECX, EDX, 50) - F3(EDX, ESI, EDI, EAX, EBX, ECX, 51) - F3(ECX, EDX, ESI, EDI, EAX, EBX, 52) - F3(EBX, ECX, EDX, ESI, EDI, EAX, 53) - F3(EAX, EBX, ECX, EDX, ESI, EDI, 54) - F3(EDI, EAX, EBX, ECX, EDX, ESI, 55) - F3(ESI, EDI, EAX, EBX, ECX, EDX, 56) - F3(EDX, ESI, EDI, EAX, EBX, ECX, 57) - F3(ECX, EDX, ESI, EDI, EAX, EBX, 58) - F3(EBX, ECX, EDX, ESI, EDI, EAX, 59) - - /* Fourth Round */ - F4(EAX, EBX, ECX, EDX, ESI, EDI, 60) - F4(EDI, EAX, EBX, ECX, EDX, ESI, 61) - F4(ESI, EDI, EAX, EBX, ECX, EDX, 62) - F4(EDX, ESI, EDI, EAX, EBX, ECX, 63) - F4(ECX, EDX, ESI, EDI, EAX, EBX, 64) - F4(EBX, ECX, EDX, ESI, EDI, EAX, 65) - F4(EAX, EBX, ECX, EDX, ESI, EDI, 66) - F4(EDI, EAX, EBX, ECX, EDX, ESI, 67) - F4(ESI, EDI, EAX, EBX, ECX, EDX, 68) - F4(EDX, ESI, EDI, EAX, EBX, ECX, 69) - F4(ECX, EDX, ESI, EDI, EAX, EBX, 70) - F4(EBX, ECX, EDX, ESI, EDI, EAX, 71) - F4(EAX, EBX, ECX, EDX, ESI, EDI, 72) - F4(EDI, EAX, EBX, ECX, EDX, ESI, 73) - F4(ESI, EDI, EAX, EBX, ECX, EDX, 74) - F4(EDX, ESI, EDI, EAX, EBX, ECX, 75) - F4(ECX, EDX, ESI, EDI, EAX, EBX, 76) - F4(EBX, ECX, EDX, ESI, EDI, EAX, 77) - F4(EAX, EBX, ECX, EDX, ESI, EDI, 78) - F4(EDI, EAX, EBX, ECX, EDX, ESI, 79) - - ASSIGN(ESP, ARRAY4(ESP, 80)) - - ASSIGN(EBP, ARG(1)) - ADD(ARRAY4(EBP, 0), EDX) - ADD(ARRAY4(EBP, 1), EDI) - ADD(ARRAY4(EBP, 2), EAX) - ADD(ARRAY4(EBP, 3), EBX) - ADD(ARRAY4(EBP, 4), ECX) - - RESTORE_REGS() -END_FUNCTION(botan_sha160_asm_ia32) diff --git a/src/hash/sha1_ia32/sha1_ia32.S b/src/hash/sha1_ia32/sha1_ia32.S new file mode 100644 index 000000000..ddd72e316 --- /dev/null +++ b/src/hash/sha1_ia32/sha1_ia32.S @@ -0,0 +1,242 @@ +/************************************************* +* SHA-160 Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include + +START_LISTING(sha1_asm.S) + +START_FUNCTION(botan_sha160_core_asm) + SPILL_REGS() + +#define PUSHED 4 + + ASSIGN(EDI, ARG(2)) + ASSIGN(EBP, ARG(3)) + + ZEROIZE(ESI) + +START_LOOP(.LOAD_INPUT) + ADD_IMM(ESI, 4) + + ASSIGN(EAX, ARRAY4(EDI, 0)) + ASSIGN(EBX, ARRAY4(EDI, 1)) + ASSIGN(ECX, ARRAY4(EDI, 2)) + ASSIGN(EDX, ARRAY4(EDI, 3)) + + ADD_IMM(EDI, 16) + + BSWAP(EAX) + BSWAP(EBX) + BSWAP(ECX) + BSWAP(EDX) + + ASSIGN(ARRAY4_INDIRECT(EBP,ESI,-4), EAX) + ASSIGN(ARRAY4_INDIRECT(EBP,ESI,-3), EBX) + ASSIGN(ARRAY4_INDIRECT(EBP,ESI,-2), ECX) + ASSIGN(ARRAY4_INDIRECT(EBP,ESI,-1), EDX) +LOOP_UNTIL_EQ(ESI, 16, .LOAD_INPUT) + + ADD2_IMM(EDI, EBP, 64) + +START_LOOP(.EXPANSION) + ADD_IMM(ESI, 4) + + ZEROIZE(EAX) + ASSIGN(EBX, ARRAY4(EDI, -1)) + ASSIGN(ECX, ARRAY4(EDI, -2)) + ASSIGN(EDX, ARRAY4(EDI, -3)) + + XOR(EAX, ARRAY4(EDI, -5)) + XOR(EBX, ARRAY4(EDI, -6)) + XOR(ECX, ARRAY4(EDI, -7)) + XOR(EDX, ARRAY4(EDI, -8)) + + XOR(EAX, ARRAY4(EDI, -11)) + XOR(EBX, ARRAY4(EDI, -12)) + XOR(ECX, ARRAY4(EDI, -13)) + XOR(EDX, ARRAY4(EDI, -14)) + + XOR(EAX, ARRAY4(EDI, -13)) + XOR(EBX, ARRAY4(EDI, -14)) + XOR(ECX, ARRAY4(EDI, -15)) + XOR(EDX, ARRAY4(EDI, -16)) + + ROTL_IMM(EDX, 1) + ROTL_IMM(ECX, 1) + ROTL_IMM(EBX, 1) + XOR(EAX, EDX) + ROTL_IMM(EAX, 1) + + ASSIGN(ARRAY4(EDI, 0), EDX) + ASSIGN(ARRAY4(EDI, 1), ECX) + ASSIGN(ARRAY4(EDI, 2), EBX) + ASSIGN(ARRAY4(EDI, 3), EAX) + + ADD_IMM(EDI, 16) +LOOP_UNTIL_EQ(ESI, 80, .EXPANSION) + +#define MAGIC1 0x5A827999 +#define MAGIC2 0x6ED9EBA1 +#define MAGIC3 0x8F1BBCDC +#define MAGIC4 0xCA62C1D6 + +#define MSG ESP +#define T2 EBP + +#define F1(A, B, C, D, E, F, N) \ + ASSIGN(T2, ARRAY4(MSG, N)) ; \ + ASSIGN(A, F) ; \ + ROTL_IMM(F, 5) ; \ + ADD(F, E) ; \ + ASSIGN(E, C) ; \ + XOR(E, D) ; \ + ADD3_IMM(F, T2, MAGIC1) ; \ + AND(E, B) ; \ + XOR(E, D) ; \ + ROTR_IMM(B, 2) ; \ + ADD(E, F) ; + +#define F2_4(A, B, C, D, E, F, N, MAGIC) \ + ASSIGN(T2, ARRAY4(MSG, N)) ; \ + ASSIGN(A, F) ; \ + ROTL_IMM(F, 5) ; \ + ADD(F, E) ; \ + ASSIGN(E, B) ; \ + XOR(E, C) ; \ + ADD3_IMM(F, T2, MAGIC) ; \ + XOR(E, D) ; \ + ROTR_IMM(B, 2) ; \ + ADD(E, F) ; + +#define F3(A, B, C, D, E, F, N) \ + ASSIGN(T2, ARRAY4(MSG, N)) ; \ + ASSIGN(A, F) ; \ + ROTL_IMM(F, 5) ; \ + ADD(F, E) ; \ + ASSIGN(E, B) ; \ + OR(E, C) ; \ + AND(E, D) ; \ + ADD3_IMM(F, T2, MAGIC3) ; \ + ASSIGN(T2, B) ; \ + AND(T2, C) ; \ + OR(E, T2) ; \ + ROTR_IMM(B, 2) ; \ + ADD(E, F) ; + +#define F2(A, B, C, D, E, F, MSG) \ + F2_4(A, B, C, D, E, F, MSG, MAGIC2) + +#define F4(A, B, C, D, E, F, MSG) \ + F2_4(A, B, C, D, E, F, MSG, MAGIC4) + + ASSIGN(EAX, ARG(1)) + ASSIGN(EDI, ARRAY4(EAX, 0)) + ASSIGN(EBX, ARRAY4(EAX, 1)) + ASSIGN(ECX, ARRAY4(EAX, 2)) + ASSIGN(EDX, ARRAY4(EAX, 3)) + ASSIGN(ESI, ARRAY4(EAX, 4)) + + ASSIGN(ARRAY4(EBP, 80), ESP) + ASSIGN(ESP, EBP) + + /* First Round */ + F1(EAX, EBX, ECX, EDX, ESI, EDI, 0) + F1(EDI, EAX, EBX, ECX, EDX, ESI, 1) + F1(ESI, EDI, EAX, EBX, ECX, EDX, 2) + F1(EDX, ESI, EDI, EAX, EBX, ECX, 3) + F1(ECX, EDX, ESI, EDI, EAX, EBX, 4) + F1(EBX, ECX, EDX, ESI, EDI, EAX, 5) + F1(EAX, EBX, ECX, EDX, ESI, EDI, 6) + F1(EDI, EAX, EBX, ECX, EDX, ESI, 7) + F1(ESI, EDI, EAX, EBX, ECX, EDX, 8) + F1(EDX, ESI, EDI, EAX, EBX, ECX, 9) + F1(ECX, EDX, ESI, EDI, EAX, EBX, 10) + F1(EBX, ECX, EDX, ESI, EDI, EAX, 11) + F1(EAX, EBX, ECX, EDX, ESI, EDI, 12) + F1(EDI, EAX, EBX, ECX, EDX, ESI, 13) + F1(ESI, EDI, EAX, EBX, ECX, EDX, 14) + F1(EDX, ESI, EDI, EAX, EBX, ECX, 15) + F1(ECX, EDX, ESI, EDI, EAX, EBX, 16) + F1(EBX, ECX, EDX, ESI, EDI, EAX, 17) + F1(EAX, EBX, ECX, EDX, ESI, EDI, 18) + F1(EDI, EAX, EBX, ECX, EDX, ESI, 19) + + /* Second Round */ + F2(ESI, EDI, EAX, EBX, ECX, EDX, 20) + F2(EDX, ESI, EDI, EAX, EBX, ECX, 21) + F2(ECX, EDX, ESI, EDI, EAX, EBX, 22) + F2(EBX, ECX, EDX, ESI, EDI, EAX, 23) + F2(EAX, EBX, ECX, EDX, ESI, EDI, 24) + F2(EDI, EAX, EBX, ECX, EDX, ESI, 25) + F2(ESI, EDI, EAX, EBX, ECX, EDX, 26) + F2(EDX, ESI, EDI, EAX, EBX, ECX, 27) + F2(ECX, EDX, ESI, EDI, EAX, EBX, 28) + F2(EBX, ECX, EDX, ESI, EDI, EAX, 29) + F2(EAX, EBX, ECX, EDX, ESI, EDI, 30) + F2(EDI, EAX, EBX, ECX, EDX, ESI, 31) + F2(ESI, EDI, EAX, EBX, ECX, EDX, 32) + F2(EDX, ESI, EDI, EAX, EBX, ECX, 33) + F2(ECX, EDX, ESI, EDI, EAX, EBX, 34) + F2(EBX, ECX, EDX, ESI, EDI, EAX, 35) + F2(EAX, EBX, ECX, EDX, ESI, EDI, 36) + F2(EDI, EAX, EBX, ECX, EDX, ESI, 37) + F2(ESI, EDI, EAX, EBX, ECX, EDX, 38) + F2(EDX, ESI, EDI, EAX, EBX, ECX, 39) + + /* Third Round */ + F3(ECX, EDX, ESI, EDI, EAX, EBX, 40) + F3(EBX, ECX, EDX, ESI, EDI, EAX, 41) + F3(EAX, EBX, ECX, EDX, ESI, EDI, 42) + F3(EDI, EAX, EBX, ECX, EDX, ESI, 43) + F3(ESI, EDI, EAX, EBX, ECX, EDX, 44) + F3(EDX, ESI, EDI, EAX, EBX, ECX, 45) + F3(ECX, EDX, ESI, EDI, EAX, EBX, 46) + F3(EBX, ECX, EDX, ESI, EDI, EAX, 47) + F3(EAX, EBX, ECX, EDX, ESI, EDI, 48) + F3(EDI, EAX, EBX, ECX, EDX, ESI, 49) + F3(ESI, EDI, EAX, EBX, ECX, EDX, 50) + F3(EDX, ESI, EDI, EAX, EBX, ECX, 51) + F3(ECX, EDX, ESI, EDI, EAX, EBX, 52) + F3(EBX, ECX, EDX, ESI, EDI, EAX, 53) + F3(EAX, EBX, ECX, EDX, ESI, EDI, 54) + F3(EDI, EAX, EBX, ECX, EDX, ESI, 55) + F3(ESI, EDI, EAX, EBX, ECX, EDX, 56) + F3(EDX, ESI, EDI, EAX, EBX, ECX, 57) + F3(ECX, EDX, ESI, EDI, EAX, EBX, 58) + F3(EBX, ECX, EDX, ESI, EDI, EAX, 59) + + /* Fourth Round */ + F4(EAX, EBX, ECX, EDX, ESI, EDI, 60) + F4(EDI, EAX, EBX, ECX, EDX, ESI, 61) + F4(ESI, EDI, EAX, EBX, ECX, EDX, 62) + F4(EDX, ESI, EDI, EAX, EBX, ECX, 63) + F4(ECX, EDX, ESI, EDI, EAX, EBX, 64) + F4(EBX, ECX, EDX, ESI, EDI, EAX, 65) + F4(EAX, EBX, ECX, EDX, ESI, EDI, 66) + F4(EDI, EAX, EBX, ECX, EDX, ESI, 67) + F4(ESI, EDI, EAX, EBX, ECX, EDX, 68) + F4(EDX, ESI, EDI, EAX, EBX, ECX, 69) + F4(ECX, EDX, ESI, EDI, EAX, EBX, 70) + F4(EBX, ECX, EDX, ESI, EDI, EAX, 71) + F4(EAX, EBX, ECX, EDX, ESI, EDI, 72) + F4(EDI, EAX, EBX, ECX, EDX, ESI, 73) + F4(ESI, EDI, EAX, EBX, ECX, EDX, 74) + F4(EDX, ESI, EDI, EAX, EBX, ECX, 75) + F4(ECX, EDX, ESI, EDI, EAX, EBX, 76) + F4(EBX, ECX, EDX, ESI, EDI, EAX, 77) + F4(EAX, EBX, ECX, EDX, ESI, EDI, 78) + F4(EDI, EAX, EBX, ECX, EDX, ESI, 79) + + ASSIGN(ESP, ARRAY4(ESP, 80)) + + ASSIGN(EBP, ARG(1)) + ADD(ARRAY4(EBP, 0), EDX) + ADD(ARRAY4(EBP, 1), EDI) + ADD(ARRAY4(EBP, 2), EAX) + ADD(ARRAY4(EBP, 3), EBX) + ADD(ARRAY4(EBP, 4), ECX) + + RESTORE_REGS() +END_FUNCTION(botan_sha160_core_asm) -- cgit v1.2.3