aboutsummaryrefslogtreecommitdiffstats
path: root/src/hash
diff options
context:
space:
mode:
Diffstat (limited to 'src/hash')
-rw-r--r--src/hash/bmw_512/bmw_512.cpp (renamed from src/hash/bmw/bmw_512.cpp)0
-rw-r--r--src/hash/bmw_512/bmw_512.h (renamed from src/hash/bmw/bmw_512.h)0
-rw-r--r--src/hash/bmw_512/info.txt (renamed from src/hash/bmw/info.txt)0
-rw-r--r--src/hash/md4_x86_32/info.txt (renamed from src/hash/md4_ia32/info.txt)6
-rw-r--r--src/hash/md4_x86_32/md4_x86_32.cpp (renamed from src/hash/md4_ia32/md4_ia32.cpp)12
-rw-r--r--src/hash/md4_x86_32/md4_x86_32.h (renamed from src/hash/md4_ia32/md4_ia32.h)10
-rw-r--r--src/hash/md4_x86_32/md4_x86_32_imp.S (renamed from src/hash/md4_ia32/md4_ia32_imp.S)10
-rw-r--r--src/hash/md5_x86_32/info.txt (renamed from src/hash/md5_ia32/info.txt)6
-rw-r--r--src/hash/md5_x86_32/md5_x86_32.cpp (renamed from src/hash/md5_ia32/md5_ia32.cpp)10
-rw-r--r--src/hash/md5_x86_32/md5_x86_32.h (renamed from src/hash/md5_ia32/md5_ia32.h)10
-rw-r--r--src/hash/md5_x86_32/md5_x86_32_imp.S (renamed from src/hash/md5_ia32/md5_ia32_imp.S)10
-rw-r--r--src/hash/sha1/sha160.cpp8
-rw-r--r--src/hash/sha1_ia32/sha1_ia32.h31
-rw-r--r--src/hash/sha1_sse2/sha1_sse2.cpp11
-rw-r--r--src/hash/sha1_x86_32/info.txt (renamed from src/hash/sha1_ia32/info.txt)6
-rw-r--r--src/hash/sha1_x86_32/sha1_x86_32.cpp (renamed from src/hash/sha1_ia32/sha1_ia32.cpp)10
-rw-r--r--src/hash/sha1_x86_32/sha1_x86_32.h31
-rw-r--r--src/hash/sha1_x86_32/sha1_x86_32_imp.S (renamed from src/hash/sha1_ia32/sha1_ia32_imp.S)14
-rw-r--r--src/hash/sha1_x86_64/info.txt (renamed from src/hash/sha1_amd64/info.txt)6
-rw-r--r--src/hash/sha1_x86_64/sha1_x86_64.cpp (renamed from src/hash/sha1_amd64/sha1_amd64.cpp)8
-rw-r--r--src/hash/sha1_x86_64/sha1_x86_64.h (renamed from src/hash/sha1_amd64/sha1_amd64.h)8
-rw-r--r--src/hash/sha1_x86_64/sha1_x86_64_imp.S (renamed from src/hash/sha1_amd64/sha1_amd64_imp.S)8
-rw-r--r--src/hash/sha2_32/sha2_32.cpp200
-rw-r--r--src/hash/sha2_32/sha2_32.h10
-rw-r--r--src/hash/sha2_64/sha2_64.cpp234
-rw-r--r--src/hash/sha2_64/sha2_64.h8
-rw-r--r--src/hash/skein/skein_512.cpp12
27 files changed, 351 insertions, 328 deletions
diff --git a/src/hash/bmw/bmw_512.cpp b/src/hash/bmw_512/bmw_512.cpp
index 40338fdf0..40338fdf0 100644
--- a/src/hash/bmw/bmw_512.cpp
+++ b/src/hash/bmw_512/bmw_512.cpp
diff --git a/src/hash/bmw/bmw_512.h b/src/hash/bmw_512/bmw_512.h
index 474b607bb..474b607bb 100644
--- a/src/hash/bmw/bmw_512.h
+++ b/src/hash/bmw_512/bmw_512.h
diff --git a/src/hash/bmw/info.txt b/src/hash/bmw_512/info.txt
index 7170223d7..7170223d7 100644
--- a/src/hash/bmw/info.txt
+++ b/src/hash/bmw_512/info.txt
diff --git a/src/hash/md4_ia32/info.txt b/src/hash/md4_x86_32/info.txt
index 5d14188f2..fdc534df4 100644
--- a/src/hash/md4_ia32/info.txt
+++ b/src/hash/md4_x86_32/info.txt
@@ -1,12 +1,12 @@
-define MD4_IA32
+define MD4_X86_32
load_on asm_ok
<arch>
-ia32
+x86_32
</arch>
<requires>
-asm_ia32
+asm_x86_32
md4
</requires>
diff --git a/src/hash/md4_ia32/md4_ia32.cpp b/src/hash/md4_x86_32/md4_x86_32.cpp
index 98d3c7a19..750e65a95 100644
--- a/src/hash/md4_ia32/md4_ia32.cpp
+++ b/src/hash/md4_x86_32/md4_x86_32.cpp
@@ -1,32 +1,32 @@
/*
-* MD4 (IA-32)
+* MD4 (x86-32)
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#include <botan/md4_ia32.h>
+#include <botan/md4_x86_32.h>
namespace Botan {
/**
-* MD4 compression function in IA-32 asm
+* MD4 compression function in x86-32 asm
* @param digest the current digest
* @param input the input block
* @param M the message buffer
*/
-extern "C" void botan_md4_ia32_compress(u32bit digest[4],
+extern "C" void botan_md4_x86_32_compress(u32bit digest[4],
const byte input[64],
u32bit M[16]);
/*
* MD4 Compression Function
*/
-void MD4_IA32::compress_n(const byte input[], size_t blocks)
+void MD4_X86_32::compress_n(const byte input[], size_t blocks)
{
for(size_t i = 0; i != blocks; ++i)
{
- botan_md4_ia32_compress(digest, input, M);
+ botan_md4_x86_32_compress(digest, input, M);
input += hash_block_size();
}
}
diff --git a/src/hash/md4_ia32/md4_ia32.h b/src/hash/md4_x86_32/md4_x86_32.h
index 4bb8f1add..a9f23e94f 100644
--- a/src/hash/md4_ia32/md4_ia32.h
+++ b/src/hash/md4_x86_32/md4_x86_32.h
@@ -1,12 +1,12 @@
/*
-* MD4 (IA-32)
+* MD4 (x86-32)
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#ifndef BOTAN_MD4_IA32_H__
-#define BOTAN_MD4_IA32_H__
+#ifndef BOTAN_MD4_X86_32_H__
+#define BOTAN_MD4_X86_32_H__
#include <botan/md4.h>
@@ -15,10 +15,10 @@ namespace Botan {
/**
* MD4 using x86 assembly
*/
-class BOTAN_DLL MD4_IA32 : public MD4
+class BOTAN_DLL MD4_X86_32 : public MD4
{
public:
- HashFunction* clone() const { return new MD4_IA32; }
+ HashFunction* clone() const { return new MD4_X86_32; }
private:
void compress_n(const byte[], size_t blocks);
};
diff --git a/src/hash/md4_ia32/md4_ia32_imp.S b/src/hash/md4_x86_32/md4_x86_32_imp.S
index c7e108147..192751166 100644
--- a/src/hash/md4_ia32/md4_ia32_imp.S
+++ b/src/hash/md4_x86_32/md4_x86_32_imp.S
@@ -1,15 +1,15 @@
/*
-* MD4 in IA-32 assembler
+* MD4 in x86-32 assembler
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#include <botan/internal/asm_macr_ia32.h>
+#include <botan/internal/asm_x86_32.h>
-START_LISTING(md4_ia32.S)
+START_LISTING(md4_x86_32_imp.S)
-START_FUNCTION(botan_md4_ia32_compress)
+START_FUNCTION(botan_md4_x86_32_compress)
SPILL_REGS()
#define PUSHED 4
@@ -134,4 +134,4 @@ LOOP_UNTIL_EQ(ESI, 16, .LOAD_INPUT)
ADD(ARRAY4(EBP, 3), EDX)
RESTORE_REGS()
-END_FUNCTION(botan_md4_ia32_compress)
+END_FUNCTION(botan_md4_x86_32_compress)
diff --git a/src/hash/md5_ia32/info.txt b/src/hash/md5_x86_32/info.txt
index 9be698a3f..adec65f81 100644
--- a/src/hash/md5_ia32/info.txt
+++ b/src/hash/md5_x86_32/info.txt
@@ -1,12 +1,12 @@
-define MD5_IA32
+define MD5_X86_32
load_on asm_ok
<arch>
-ia32
+x86_32
</arch>
<requires>
-asm_ia32
+asm_x86_32
md5
</requires>
diff --git a/src/hash/md5_ia32/md5_ia32.cpp b/src/hash/md5_x86_32/md5_x86_32.cpp
index 6ae235d2b..123fcff77 100644
--- a/src/hash/md5_ia32/md5_ia32.cpp
+++ b/src/hash/md5_x86_32/md5_x86_32.cpp
@@ -1,29 +1,29 @@
/*
-* MD5 (IA-32)
+* MD5 (x86-32)
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#include <botan/md5_ia32.h>
+#include <botan/md5_x86_32.h>
namespace Botan {
namespace {
extern "C"
-void botan_md5_ia32_compress(u32bit[4], const byte[64], u32bit[16]);
+void botan_md5_x86_32_compress(u32bit[4], const byte[64], u32bit[16]);
}
/*
* MD5 Compression Function
*/
-void MD5_IA32::compress_n(const byte input[], size_t blocks)
+void MD5_X86_32::compress_n(const byte input[], size_t blocks)
{
for(size_t i = 0; i != blocks; ++i)
{
- botan_md5_ia32_compress(digest, input, M);
+ botan_md5_x86_32_compress(digest, input, M);
input += hash_block_size();
}
}
diff --git a/src/hash/md5_ia32/md5_ia32.h b/src/hash/md5_x86_32/md5_x86_32.h
index bf4b4c505..0150249ae 100644
--- a/src/hash/md5_ia32/md5_ia32.h
+++ b/src/hash/md5_x86_32/md5_x86_32.h
@@ -1,12 +1,12 @@
/*
-* MD5 (IA-32)
+* MD5 (x86-32)
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#ifndef BOTAN_MD5_IA32_H__
-#define BOTAN_MD5_IA32_H__
+#ifndef BOTAN_MD5_X86_32_H__
+#define BOTAN_MD5_X86_32_H__
#include <botan/md5.h>
@@ -15,10 +15,10 @@ namespace Botan {
/**
* MD5 in x86 assembly
*/
-class BOTAN_DLL MD5_IA32 : public MD5
+class BOTAN_DLL MD5_X86_32 : public MD5
{
public:
- HashFunction* clone() const { return new MD5_IA32; }
+ HashFunction* clone() const { return new MD5_X86_32; }
private:
void compress_n(const byte[], size_t blocks);
};
diff --git a/src/hash/md5_ia32/md5_ia32_imp.S b/src/hash/md5_x86_32/md5_x86_32_imp.S
index e77836353..f41aaccbf 100644
--- a/src/hash/md5_ia32/md5_ia32_imp.S
+++ b/src/hash/md5_x86_32/md5_x86_32_imp.S
@@ -1,15 +1,15 @@
/*
-* MD5 in IA-32 assembler
+* MD5 in x86-32 assembler
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#include <botan/internal/asm_macr_ia32.h>
+#include <botan/internal/asm_x86_32.h>
-START_LISTING(md5_ia32.S)
+START_LISTING(md5_x86_32.S)
-START_FUNCTION(botan_md5_ia32_compress)
+START_FUNCTION(botan_md5_x86_32_compress)
SPILL_REGS()
#define PUSHED 4
@@ -163,4 +163,4 @@ LOOP_UNTIL_EQ(ESI, 16, .LOAD_INPUT)
ADD(ARRAY4(EBP, 3), EDX)
RESTORE_REGS()
-END_FUNCTION(botan_md5_ia32_compress)
+END_FUNCTION(botan_md5_x86_32_compress)
diff --git a/src/hash/sha1/sha160.cpp b/src/hash/sha1/sha160.cpp
index 7a42ca867..f5daaadb2 100644
--- a/src/hash/sha1/sha160.cpp
+++ b/src/hash/sha1/sha160.cpp
@@ -1,6 +1,6 @@
/*
* SHA-160
-* (C) 1999-2008 Jack Lloyd
+* (C) 1999-2008,2011 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -11,6 +11,8 @@
namespace Botan {
+namespace SHA1_F {
+
namespace {
/*
@@ -51,11 +53,15 @@ inline void F4(u32bit A, u32bit& B, u32bit C, u32bit D, u32bit& E, u32bit msg)
}
+}
+
/*
* SHA-160 Compression Function
*/
void SHA_160::compress_n(const byte input[], size_t blocks)
{
+ using namespace SHA1_F;
+
u32bit A = digest[0], B = digest[1], C = digest[2],
D = digest[3], E = digest[4];
diff --git a/src/hash/sha1_ia32/sha1_ia32.h b/src/hash/sha1_ia32/sha1_ia32.h
deleted file mode 100644
index 5cff03016..000000000
--- a/src/hash/sha1_ia32/sha1_ia32.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-* SHA-160 (IA-32)
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#ifndef BOTAN_SHA_160_IA32_H__
-#define BOTAN_SHA_160_IA32_H__
-
-#include <botan/sha160.h>
-
-namespace Botan {
-
-/**
-* SHA-160 in x86 assembly
-*/
-class BOTAN_DLL SHA_160_IA32 : public SHA_160
- {
- public:
- HashFunction* clone() const { return new SHA_160_IA32; }
-
- // Note 81 instead of normal 80: IA-32 asm needs an extra temp
- SHA_160_IA32() : SHA_160(81) {}
- private:
- void compress_n(const byte[], size_t blocks);
- };
-
-}
-
-#endif
diff --git a/src/hash/sha1_sse2/sha1_sse2.cpp b/src/hash/sha1_sse2/sha1_sse2.cpp
index e890967c6..f96afd9ce 100644
--- a/src/hash/sha1_sse2/sha1_sse2.cpp
+++ b/src/hash/sha1_sse2/sha1_sse2.cpp
@@ -1,6 +1,6 @@
/*
* SHA-1 using SSE2
-* (C) 2009-2010 Jack Lloyd
+* (C) 2009-2011 Jack Lloyd
*
* Distributed under the terms of the Botan license
*
@@ -14,6 +14,8 @@
namespace Botan {
+namespace SHA1_SSE2_F {
+
namespace {
/*
@@ -146,11 +148,15 @@ inline void F4(u32bit A, u32bit& B, u32bit C, u32bit D, u32bit& E, u32bit msg)
}
+}
+
/*
* SHA-160 Compression Function using SSE for message expansion
*/
void SHA_160_SSE2::compress_n(const byte input_bytes[], size_t blocks)
{
+ using namespace SHA1_SSE2_F;
+
const __m128i K00_19 = _mm_set1_epi32(0x5A827999);
const __m128i K20_39 = _mm_set1_epi32(0x6ED9EBA1);
const __m128i K40_59 = _mm_set1_epi32(0x8F1BBCDC);
@@ -323,4 +329,7 @@ void SHA_160_SSE2::compress_n(const byte input_bytes[], size_t blocks)
#undef GET_P_32
}
+#undef prep00_15
+#undef prep
+
}
diff --git a/src/hash/sha1_ia32/info.txt b/src/hash/sha1_x86_32/info.txt
index 47d8e753e..7359a6754 100644
--- a/src/hash/sha1_ia32/info.txt
+++ b/src/hash/sha1_x86_32/info.txt
@@ -1,12 +1,12 @@
-define SHA1_IA32
+define SHA1_X86_32
load_on asm_ok
<arch>
-ia32
+x86_32
</arch>
<requires>
-asm_ia32
+asm_x86_32
sha1
</requires>
diff --git a/src/hash/sha1_ia32/sha1_ia32.cpp b/src/hash/sha1_x86_32/sha1_x86_32.cpp
index 3e9cff047..6a4dc2a1d 100644
--- a/src/hash/sha1_ia32/sha1_ia32.cpp
+++ b/src/hash/sha1_x86_32/sha1_x86_32.cpp
@@ -1,29 +1,29 @@
/*
-* SHA-160 (IA-32)
+* SHA-160 in x86-32
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#include <botan/sha1_ia32.h>
+#include <botan/sha1_x86_32.h>
namespace Botan {
namespace {
extern "C"
-void botan_sha160_ia32_compress(u32bit[5], const byte[64], u32bit[81]);
+void botan_sha160_x86_32_compress(u32bit[5], const byte[64], u32bit[81]);
}
/*
* SHA-160 Compression Function
*/
-void SHA_160_IA32::compress_n(const byte input[], size_t blocks)
+void SHA_160_X86_32::compress_n(const byte input[], size_t blocks)
{
for(size_t i = 0; i != blocks; ++i)
{
- botan_sha160_ia32_compress(&digest[0], input, &W[0]);
+ botan_sha160_x86_32_compress(&digest[0], input, &W[0]);
input += hash_block_size();
}
}
diff --git a/src/hash/sha1_x86_32/sha1_x86_32.h b/src/hash/sha1_x86_32/sha1_x86_32.h
new file mode 100644
index 000000000..b344d4ae2
--- /dev/null
+++ b/src/hash/sha1_x86_32/sha1_x86_32.h
@@ -0,0 +1,31 @@
+/*
+* SHA-160 in x86-32 asm
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_SHA_160_X86_32_H__
+#define BOTAN_SHA_160_X86_32_H__
+
+#include <botan/sha160.h>
+
+namespace Botan {
+
+/**
+* SHA-160 in x86 assembly
+*/
+class BOTAN_DLL SHA_160_X86_32 : public SHA_160
+ {
+ public:
+ HashFunction* clone() const { return new SHA_160_X86_32; }
+
+ // Note 81 instead of normal 80: x86-32 asm needs an extra temp
+ SHA_160_X86_32() : SHA_160(81) {}
+ private:
+ void compress_n(const byte[], size_t blocks);
+ };
+
+}
+
+#endif
diff --git a/src/hash/sha1_ia32/sha1_ia32_imp.S b/src/hash/sha1_x86_32/sha1_x86_32_imp.S
index c2777b4b5..775ef6854 100644
--- a/src/hash/sha1_ia32/sha1_ia32_imp.S
+++ b/src/hash/sha1_x86_32/sha1_x86_32_imp.S
@@ -1,15 +1,15 @@
/*
-* SHA-1 in IA-32 assembler
+* SHA-1 in x86-32 asm
* (C) 1999-2007 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
-#include <botan/internal/asm_macr_ia32.h>
+#include <botan/internal/asm_x86_32.h>
-START_LISTING(sha1_ia32.S)
+START_LISTING(sha1_x86_32_imp.S)
-START_FUNCTION(botan_sha160_ia32_compress)
+START_FUNCTION(botan_sha160_x86_32_compress)
SPILL_REGS()
#define PUSHED 4
@@ -42,7 +42,7 @@ LOOP_UNTIL_EQ(ESI, 16, .LOAD_INPUT)
ADD2_IMM(EDI, EBP, 64)
-START_LOOP(.EXPANSION)
+START_LOOP(.L_SHA_EXPANSION)
ADD_IMM(ESI, 4)
ZEROIZE(EAX)
@@ -77,7 +77,7 @@ START_LOOP(.EXPANSION)
ASSIGN(ARRAY4(EDI, 3), EAX)
ADD_IMM(EDI, 16)
-LOOP_UNTIL_EQ(ESI, 80, .EXPANSION)
+LOOP_UNTIL_EQ(ESI, 80, .L_SHA_EXPANSION)
#define MAGIC1 0x5A827999
#define MAGIC2 0x6ED9EBA1
@@ -241,4 +241,4 @@ LOOP_UNTIL_EQ(ESI, 80, .EXPANSION)
ADD(ARRAY4(EBP, 4), ECX)
RESTORE_REGS()
-END_FUNCTION(botan_sha160_ia32_compress)
+END_FUNCTION(botan_sha160_x86_32_compress)
diff --git a/src/hash/sha1_amd64/info.txt b/src/hash/sha1_x86_64/info.txt
index 78eaa23c2..3d54c0baa 100644
--- a/src/hash/sha1_amd64/info.txt
+++ b/src/hash/sha1_x86_64/info.txt
@@ -1,13 +1,13 @@
-define SHA1_AMD64
+define SHA1_X86_64
load_on asm_ok
<arch>
-amd64
+x86_64
</arch>
<requires>
asm_engine
-asm_amd64
+asm_x86_64
sha1
</requires>
diff --git a/src/hash/sha1_amd64/sha1_amd64.cpp b/src/hash/sha1_x86_64/sha1_x86_64.cpp
index d32b44901..a3e92e313 100644
--- a/src/hash/sha1_amd64/sha1_amd64.cpp
+++ b/src/hash/sha1_x86_64/sha1_x86_64.cpp
@@ -5,25 +5,25 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/sha1_amd64.h>
+#include <botan/sha1_x86_64.h>
namespace Botan {
namespace {
extern "C"
-void botan_sha160_amd64_compress(u32bit[5], const byte[64], u32bit[80]);
+void botan_sha160_x86_64_compress(u32bit[5], const byte[64], u32bit[80]);
}
/*
* SHA-160 Compression Function
*/
-void SHA_160_AMD64::compress_n(const byte input[], size_t blocks)
+void SHA_160_X86_64::compress_n(const byte input[], size_t blocks)
{
for(size_t i = 0; i != blocks; ++i)
{
- botan_sha160_amd64_compress(&digest[0], input, &W[0]);
+ botan_sha160_x86_64_compress(&digest[0], input, &W[0]);
input += hash_block_size();
}
}
diff --git a/src/hash/sha1_amd64/sha1_amd64.h b/src/hash/sha1_x86_64/sha1_x86_64.h
index 6b741184d..068a94595 100644
--- a/src/hash/sha1_amd64/sha1_amd64.h
+++ b/src/hash/sha1_x86_64/sha1_x86_64.h
@@ -5,8 +5,8 @@
* Distributed under the terms of the Botan license
*/
-#ifndef BOTAN_SHA_160_AMD64_H__
-#define BOTAN_SHA_160_AMD64_H__
+#ifndef BOTAN_SHA_160_X86_64_H__
+#define BOTAN_SHA_160_X86_64_H__
#include <botan/sha160.h>
@@ -15,10 +15,10 @@ namespace Botan {
/**
* SHA-160 in x86-64 assembly
*/
-class BOTAN_DLL SHA_160_AMD64 : public SHA_160
+class BOTAN_DLL SHA_160_X86_64 : public SHA_160
{
public:
- HashFunction* clone() const { return new SHA_160_AMD64; }
+ HashFunction* clone() const { return new SHA_160_X86_64; }
private:
void compress_n(const byte[], size_t blocks);
};
diff --git a/src/hash/sha1_amd64/sha1_amd64_imp.S b/src/hash/sha1_x86_64/sha1_x86_64_imp.S
index 4eea75f11..ee35f0d85 100644
--- a/src/hash/sha1_amd64/sha1_amd64_imp.S
+++ b/src/hash/sha1_x86_64/sha1_x86_64_imp.S
@@ -5,11 +5,11 @@
* Distributed under the terms of the Botan license
*/
-#include <botan/internal/asm_macr_amd64.h>
+#include <botan/internal/asm_x86_64.h>
-START_LISTING(sha1_amd64.S)
+START_LISTING(sha1_x86_64_imp.S)
-START_FUNCTION(botan_sha160_amd64_compress)
+START_FUNCTION(botan_sha160_x86_64_compress)
#define DIGEST_ARR %rdi
#define INPUT %rsi
@@ -263,4 +263,4 @@ ALIGN;
ADD(ARRAY4(DIGEST_ARR, 3), B)
ADD(ARRAY4(DIGEST_ARR, 4), C)
-END_FUNCTION(botan_sha160_amd64_compress)
+END_FUNCTION(botan_sha160_x86_64_compress)
diff --git a/src/hash/sha2_32/sha2_32.cpp b/src/hash/sha2_32/sha2_32.cpp
index 4e5f2b38c..6dd780e64 100644
--- a/src/hash/sha2_32/sha2_32.cpp
+++ b/src/hash/sha2_32/sha2_32.cpp
@@ -14,6 +14,8 @@ namespace Botan {
namespace {
+namespace SHA2_32 {
+
/*
* SHA-256 Rho Function
*/
@@ -33,22 +35,23 @@ inline u32bit sigma(u32bit X, u32bit rot1, u32bit rot2, u32bit shift)
/*
* SHA-256 F1 Function
+*
+* Use a macro as many compilers won't inline a function this big,
+* even though it is much faster if inlined.
*/
-inline void F1(u32bit A, u32bit B, u32bit C, u32bit& D,
- u32bit E, u32bit F, u32bit G, u32bit& H,
- u32bit msg, u32bit magic)
- {
- H += magic + rho(E, 6, 11, 25) + ((E & F) ^ (~E & G)) + msg;
- D += H;
- H += rho(A, 2, 13, 22) + ((A & B) | ((A | B) & C));
- }
+#define SHA2_32_F(A, B, C, D, E, F, G, H, M1, M2, M3, M4, magic) \
+ do { \
+ H += magic + rho(E, 6, 11, 25) + ((E & F) ^ (~E & G)) + M1; \
+ D += H; \
+ H += rho(A, 2, 13, 22) + ((A & B) | ((A | B) & C)); \
+ M1 += sigma(M2, 17, 19, 10) + M3 + sigma(M4, 7, 18, 3); \
+ } while(0);
/*
* SHA-224 / SHA-256 compression function
*/
-void sha2_32_compress(MemoryRegion<u32bit>& W,
- MemoryRegion<u32bit>& digest,
- const byte input[], size_t blocks)
+void compress(MemoryRegion<u32bit>& digest,
+ const byte input[], size_t blocks)
{
u32bit A = digest[0], B = digest[1], C = digest[2],
D = digest[3], E = digest[4], F = digest[5],
@@ -56,92 +59,87 @@ void sha2_32_compress(MemoryRegion<u32bit>& W,
for(size_t i = 0; i != blocks; ++i)
{
- load_be(&W[0], input, 16);
-
- for(size_t j = 16; j != 64; j += 8)
- {
- W[j ] = sigma(W[j- 2], 17, 19, 10) + W[j-7] +
- sigma(W[j-15], 7, 18, 3) + W[j-16];
- W[j+1] = sigma(W[j- 1], 17, 19, 10) + W[j-6] +
- sigma(W[j-14], 7, 18, 3) + W[j-15];
- W[j+2] = sigma(W[j ], 17, 19, 10) + W[j-5] +
- sigma(W[j-13], 7, 18, 3) + W[j-14];
- W[j+3] = sigma(W[j+ 1], 17, 19, 10) + W[j-4] +
- sigma(W[j-12], 7, 18, 3) + W[j-13];
- W[j+4] = sigma(W[j+ 2], 17, 19, 10) + W[j-3] +
- sigma(W[j-11], 7, 18, 3) + W[j-12];
- W[j+5] = sigma(W[j+ 3], 17, 19, 10) + W[j-2] +
- sigma(W[j-10], 7, 18, 3) + W[j-11];
- W[j+6] = sigma(W[j+ 4], 17, 19, 10) + W[j-1] +
- sigma(W[j- 9], 7, 18, 3) + W[j-10];
- W[j+7] = sigma(W[j+ 5], 17, 19, 10) + W[j ] +
- sigma(W[j- 8], 7, 18, 3) + W[j- 9];
- }
-
- F1(A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98);
- F1(H, A, B, C, D, E, F, G, W[ 1], 0x71374491);
- F1(G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF);
- F1(F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5);
- F1(E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B);
- F1(D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1);
- F1(C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4);
- F1(B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5);
- F1(A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98);
- F1(H, A, B, C, D, E, F, G, W[ 9], 0x12835B01);
- F1(G, H, A, B, C, D, E, F, W[10], 0x243185BE);
- F1(F, G, H, A, B, C, D, E, W[11], 0x550C7DC3);
- F1(E, F, G, H, A, B, C, D, W[12], 0x72BE5D74);
- F1(D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE);
- F1(C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7);
- F1(B, C, D, E, F, G, H, A, W[15], 0xC19BF174);
- F1(A, B, C, D, E, F, G, H, W[16], 0xE49B69C1);
- F1(H, A, B, C, D, E, F, G, W[17], 0xEFBE4786);
- F1(G, H, A, B, C, D, E, F, W[18], 0x0FC19DC6);
- F1(F, G, H, A, B, C, D, E, W[19], 0x240CA1CC);
- F1(E, F, G, H, A, B, C, D, W[20], 0x2DE92C6F);
- F1(D, E, F, G, H, A, B, C, W[21], 0x4A7484AA);
- F1(C, D, E, F, G, H, A, B, W[22], 0x5CB0A9DC);
- F1(B, C, D, E, F, G, H, A, W[23], 0x76F988DA);
- F1(A, B, C, D, E, F, G, H, W[24], 0x983E5152);
- F1(H, A, B, C, D, E, F, G, W[25], 0xA831C66D);
- F1(G, H, A, B, C, D, E, F, W[26], 0xB00327C8);
- F1(F, G, H, A, B, C, D, E, W[27], 0xBF597FC7);
- F1(E, F, G, H, A, B, C, D, W[28], 0xC6E00BF3);
- F1(D, E, F, G, H, A, B, C, W[29], 0xD5A79147);
- F1(C, D, E, F, G, H, A, B, W[30], 0x06CA6351);
- F1(B, C, D, E, F, G, H, A, W[31], 0x14292967);
- F1(A, B, C, D, E, F, G, H, W[32], 0x27B70A85);
- F1(H, A, B, C, D, E, F, G, W[33], 0x2E1B2138);
- F1(G, H, A, B, C, D, E, F, W[34], 0x4D2C6DFC);
- F1(F, G, H, A, B, C, D, E, W[35], 0x53380D13);
- F1(E, F, G, H, A, B, C, D, W[36], 0x650A7354);
- F1(D, E, F, G, H, A, B, C, W[37], 0x766A0ABB);
- F1(C, D, E, F, G, H, A, B, W[38], 0x81C2C92E);
- F1(B, C, D, E, F, G, H, A, W[39], 0x92722C85);
- F1(A, B, C, D, E, F, G, H, W[40], 0xA2BFE8A1);
- F1(H, A, B, C, D, E, F, G, W[41], 0xA81A664B);
- F1(G, H, A, B, C, D, E, F, W[42], 0xC24B8B70);
- F1(F, G, H, A, B, C, D, E, W[43], 0xC76C51A3);
- F1(E, F, G, H, A, B, C, D, W[44], 0xD192E819);
- F1(D, E, F, G, H, A, B, C, W[45], 0xD6990624);
- F1(C, D, E, F, G, H, A, B, W[46], 0xF40E3585);
- F1(B, C, D, E, F, G, H, A, W[47], 0x106AA070);
- F1(A, B, C, D, E, F, G, H, W[48], 0x19A4C116);
- F1(H, A, B, C, D, E, F, G, W[49], 0x1E376C08);
- F1(G, H, A, B, C, D, E, F, W[50], 0x2748774C);
- F1(F, G, H, A, B, C, D, E, W[51], 0x34B0BCB5);
- F1(E, F, G, H, A, B, C, D, W[52], 0x391C0CB3);
- F1(D, E, F, G, H, A, B, C, W[53], 0x4ED8AA4A);
- F1(C, D, E, F, G, H, A, B, W[54], 0x5B9CCA4F);
- F1(B, C, D, E, F, G, H, A, W[55], 0x682E6FF3);
- F1(A, B, C, D, E, F, G, H, W[56], 0x748F82EE);
- F1(H, A, B, C, D, E, F, G, W[57], 0x78A5636F);
- F1(G, H, A, B, C, D, E, F, W[58], 0x84C87814);
- F1(F, G, H, A, B, C, D, E, W[59], 0x8CC70208);
- F1(E, F, G, H, A, B, C, D, W[60], 0x90BEFFFA);
- F1(D, E, F, G, H, A, B, C, W[61], 0xA4506CEB);
- F1(C, D, E, F, G, H, A, B, W[62], 0xBEF9A3F7);
- F1(B, C, D, E, F, G, H, A, W[63], 0xC67178F2);
+ u32bit W00 = load_be<u32bit>(input, 0);
+ u32bit W01 = load_be<u32bit>(input, 1);
+ u32bit W02 = load_be<u32bit>(input, 2);
+ u32bit W03 = load_be<u32bit>(input, 3);
+ u32bit W04 = load_be<u32bit>(input, 4);
+ u32bit W05 = load_be<u32bit>(input, 5);
+ u32bit W06 = load_be<u32bit>(input, 6);
+ u32bit W07 = load_be<u32bit>(input, 7);
+ u32bit W08 = load_be<u32bit>(input, 8);
+ u32bit W09 = load_be<u32bit>(input, 9);
+ u32bit W10 = load_be<u32bit>(input, 10);
+ u32bit W11 = load_be<u32bit>(input, 11);
+ u32bit W12 = load_be<u32bit>(input, 12);
+ u32bit W13 = load_be<u32bit>(input, 13);
+ u32bit W14 = load_be<u32bit>(input, 14);
+ u32bit W15 = load_be<u32bit>(input, 15);
+
+ SHA2_32_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0x428A2F98);
+ SHA2_32_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0x71374491);
+ SHA2_32_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0xB5C0FBCF);
+ SHA2_32_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0xE9B5DBA5);
+ SHA2_32_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x3956C25B);
+ SHA2_32_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x59F111F1);
+ SHA2_32_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x923F82A4);
+ SHA2_32_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0xAB1C5ED5);
+ SHA2_32_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0xD807AA98);
+ SHA2_32_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0x12835B01);
+ SHA2_32_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0x243185BE);
+ SHA2_32_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0x550C7DC3);
+ SHA2_32_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0x72BE5D74);
+ SHA2_32_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0x80DEB1FE);
+ SHA2_32_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0x9BDC06A7);
+ SHA2_32_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0xC19BF174);
+ SHA2_32_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0xE49B69C1);
+ SHA2_32_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0xEFBE4786);
+ SHA2_32_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0x0FC19DC6);
+ SHA2_32_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0x240CA1CC);
+ SHA2_32_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x2DE92C6F);
+ SHA2_32_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x4A7484AA);
+ SHA2_32_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x5CB0A9DC);
+ SHA2_32_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0x76F988DA);
+ SHA2_32_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0x983E5152);
+ SHA2_32_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0xA831C66D);
+ SHA2_32_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0xB00327C8);
+ SHA2_32_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0xBF597FC7);
+ SHA2_32_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0xC6E00BF3);
+ SHA2_32_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0xD5A79147);
+ SHA2_32_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0x06CA6351);
+ SHA2_32_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0x14292967);
+ SHA2_32_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0x27B70A85);
+ SHA2_32_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0x2E1B2138);
+ SHA2_32_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0x4D2C6DFC);
+ SHA2_32_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0x53380D13);
+ SHA2_32_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x650A7354);
+ SHA2_32_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x766A0ABB);
+ SHA2_32_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x81C2C92E);
+ SHA2_32_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0x92722C85);
+ SHA2_32_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0xA2BFE8A1);
+ SHA2_32_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0xA81A664B);
+ SHA2_32_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0xC24B8B70);
+ SHA2_32_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0xC76C51A3);
+ SHA2_32_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0xD192E819);
+ SHA2_32_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0xD6990624);
+ SHA2_32_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0xF40E3585);
+ SHA2_32_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0x106AA070);
+ SHA2_32_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0x19A4C116);
+ SHA2_32_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0x1E376C08);
+ SHA2_32_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0x2748774C);
+ SHA2_32_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0x34B0BCB5);
+ SHA2_32_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x391C0CB3);
+ SHA2_32_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x4ED8AA4A);
+ SHA2_32_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x5B9CCA4F);
+ SHA2_32_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0x682E6FF3);
+ SHA2_32_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0x748F82EE);
+ SHA2_32_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0x78A5636F);
+ SHA2_32_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0x84C87814);
+ SHA2_32_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0x8CC70208);
+ SHA2_32_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0x90BEFFFA);
+ SHA2_32_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0xA4506CEB);
+ SHA2_32_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0xBEF9A3F7);
+ SHA2_32_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0xC67178F2);
A = (digest[0] += A);
B = (digest[1] += B);
@@ -158,12 +156,14 @@ void sha2_32_compress(MemoryRegion<u32bit>& W,
}
+}
+
/*
* SHA-224 compression function
*/
void SHA_224::compress_n(const byte input[], size_t blocks)
{
- sha2_32_compress(W, digest, input, blocks);
+ SHA2_32::compress(digest, input, blocks);
}
/*
@@ -181,7 +181,6 @@ void SHA_224::copy_out(byte output[])
void SHA_224::clear()
{
MDx_HashFunction::clear();
- zeroise(W);
digest[0] = 0xC1059ED8;
digest[1] = 0x367CD507;
digest[2] = 0x3070DD17;
@@ -197,7 +196,7 @@ void SHA_224::clear()
*/
void SHA_256::compress_n(const byte input[], size_t blocks)
{
- sha2_32_compress(W, digest, input, blocks);
+ SHA2_32::compress(digest, input, blocks);
}
/*
@@ -215,7 +214,6 @@ void SHA_256::copy_out(byte output[])
void SHA_256::clear()
{
MDx_HashFunction::clear();
- zeroise(W);
digest[0] = 0x6A09E667;
digest[1] = 0xBB67AE85;
digest[2] = 0x3C6EF372;
diff --git a/src/hash/sha2_32/sha2_32.h b/src/hash/sha2_32/sha2_32.h
index ffda11772..807b979d1 100644
--- a/src/hash/sha2_32/sha2_32.h
+++ b/src/hash/sha2_32/sha2_32.h
@@ -1,6 +1,6 @@
/*
* SHA-{224,256}
-* (C) 1999-2010 Jack Lloyd
+* (C) 1999-2011 Jack Lloyd
* 2007 FlexSecure GmbH
*
* Distributed under the terms of the Botan license
@@ -25,13 +25,13 @@ class BOTAN_DLL SHA_224 : public MDx_HashFunction
void clear();
- SHA_224() : MDx_HashFunction(64, true, true), W(64), digest(8)
+ SHA_224() : MDx_HashFunction(64, true, true), digest(8)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);
void copy_out(byte[]);
- SecureVector<u32bit> W, digest;
+ SecureVector<u32bit> digest;
};
/**
@@ -46,13 +46,13 @@ class BOTAN_DLL SHA_256 : public MDx_HashFunction
void clear();
- SHA_256() : MDx_HashFunction(64, true, true), W(64), digest(8)
+ SHA_256() : MDx_HashFunction(64, true, true), digest(8)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);
void copy_out(byte[]);
- SecureVector<u32bit> W, digest;
+ SecureVector<u32bit> digest;
};
}
diff --git a/src/hash/sha2_64/sha2_64.cpp b/src/hash/sha2_64/sha2_64.cpp
index 3c1df9be6..3026c3a39 100644
--- a/src/hash/sha2_64/sha2_64.cpp
+++ b/src/hash/sha2_64/sha2_64.cpp
@@ -1,6 +1,6 @@
/*
* SHA-{384,512}
-* (C) 1999-2010 Jack Lloyd
+* (C) 1999-2011 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -13,6 +13,8 @@ namespace Botan {
namespace {
+namespace SHA2_64 {
+
/*
* SHA-{384,512} Rho Function
*/
@@ -23,18 +25,6 @@ inline u64bit rho(u64bit X, u32bit rot1, u32bit rot2, u32bit rot3)
}
/*
-* SHA-{384,512} F1 Function
-*/
-inline void F1(u64bit A, u64bit B, u64bit C, u64bit& D,
- u64bit E, u64bit F, u64bit G, u64bit& H,
- u64bit msg, u64bit magic)
- {
- magic += rho(E, 14, 18, 41) + ((E & F) ^ (~E & G)) + msg;
- D += magic + H;
- H += magic + rho(A, 28, 34, 39) + ((A & B) ^ (A & C) ^ (B & C));
- }
-
-/*
* SHA-{384,512} Sigma Function
*/
inline u64bit sigma(u64bit X, u32bit rot1, u32bit rot2, u32bit shift)
@@ -43,11 +33,24 @@ inline u64bit sigma(u64bit X, u32bit rot1, u32bit rot2, u32bit shift)
}
/*
+* SHA-512 F1 Function
+*
+* Use a macro as many compilers won't inline a function this big,
+* even though it is much faster if inlined.
+*/
+#define SHA2_64_F(A, B, C, D, E, F, G, H, M1, M2, M3, M4, magic) \
+ do { \
+ H += magic + rho(E, 14, 18, 41) + ((E & F) ^ (~E & G)) + M1; \
+ D += H; \
+ H += rho(A, 28, 34, 39) + ((A & B) | ((A | B) & C)); \
+ M1 += sigma(M2, 19, 61, 6) + M3 + sigma(M4, 1, 8, 7); \
+ } while(0);
+
+/*
* SHA-{384,512} Compression Function
*/
-void sha2_64_compress(MemoryRegion<u64bit>& W,
- MemoryRegion<u64bit>& digest,
- const byte input[], size_t blocks)
+void compress(MemoryRegion<u64bit>& digest,
+ const byte input[], size_t blocks)
{
u64bit A = digest[0], B = digest[1], C = digest[2],
D = digest[3], E = digest[4], F = digest[5],
@@ -55,100 +58,103 @@ void sha2_64_compress(MemoryRegion<u64bit>& W,
for(size_t i = 0; i != blocks; ++i)
{
- load_be(&W[0], input, 16);
-
- for(size_t j = 16; j != 80; j += 8)
- {
- W[j ] = sigma(W[j-2], 19, 61, 6) + W[j-7] + sigma(W[j-15], 1, 8, 7) + W[j-16];
- W[j+1] = sigma(W[j-1], 19, 61, 6) + W[j-6] + sigma(W[j-14], 1, 8, 7) + W[j-15];
- W[j+2] = sigma(W[j ], 19, 61, 6) + W[j-5] + sigma(W[j-13], 1, 8, 7) + W[j-14];
- W[j+3] = sigma(W[j+1], 19, 61, 6) + W[j-4] + sigma(W[j-12], 1, 8, 7) + W[j-13];
- W[j+4] = sigma(W[j+2], 19, 61, 6) + W[j-3] + sigma(W[j-11], 1, 8, 7) + W[j-12];
- W[j+5] = sigma(W[j+3], 19, 61, 6) + W[j-2] + sigma(W[j-10], 1, 8, 7) + W[j-11];
- W[j+6] = sigma(W[j+4], 19, 61, 6) + W[j-1] + sigma(W[j- 9], 1, 8, 7) + W[j-10];
- W[j+7] = sigma(W[j+5], 19, 61, 6) + W[j ] + sigma(W[j- 8], 1, 8, 7) + W[j- 9];
- }
-
- F1(A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98D728AE22);
- F1(H, A, B, C, D, E, F, G, W[ 1], 0x7137449123EF65CD);
- F1(G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCFEC4D3B2F);
- F1(F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA58189DBBC);
- F1(E, F, G, H, A, B, C, D, W[ 4], 0x3956C25BF348B538);
- F1(D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1B605D019);
- F1(C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4AF194F9B);
- F1(B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5DA6D8118);
- F1(A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98A3030242);
- F1(H, A, B, C, D, E, F, G, W[ 9], 0x12835B0145706FBE);
- F1(G, H, A, B, C, D, E, F, W[10], 0x243185BE4EE4B28C);
- F1(F, G, H, A, B, C, D, E, W[11], 0x550C7DC3D5FFB4E2);
- F1(E, F, G, H, A, B, C, D, W[12], 0x72BE5D74F27B896F);
- F1(D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE3B1696B1);
- F1(C, D, E, F, G, H, A, B, W[14], 0x9BDC06A725C71235);
- F1(B, C, D, E, F, G, H, A, W[15], 0xC19BF174CF692694);
- F1(A, B, C, D, E, F, G, H, W[16], 0xE49B69C19EF14AD2);
- F1(H, A, B, C, D, E, F, G, W[17], 0xEFBE4786384F25E3);
- F1(G, H, A, B, C, D, E, F, W[18], 0x0FC19DC68B8CD5B5);
- F1(F, G, H, A, B, C, D, E, W[19], 0x240CA1CC77AC9C65);
- F1(E, F, G, H, A, B, C, D, W[20], 0x2DE92C6F592B0275);
- F1(D, E, F, G, H, A, B, C, W[21], 0x4A7484AA6EA6E483);
- F1(C, D, E, F, G, H, A, B, W[22], 0x5CB0A9DCBD41FBD4);
- F1(B, C, D, E, F, G, H, A, W[23], 0x76F988DA831153B5);
- F1(A, B, C, D, E, F, G, H, W[24], 0x983E5152EE66DFAB);
- F1(H, A, B, C, D, E, F, G, W[25], 0xA831C66D2DB43210);
- F1(G, H, A, B, C, D, E, F, W[26], 0xB00327C898FB213F);
- F1(F, G, H, A, B, C, D, E, W[27], 0xBF597FC7BEEF0EE4);
- F1(E, F, G, H, A, B, C, D, W[28], 0xC6E00BF33DA88FC2);
- F1(D, E, F, G, H, A, B, C, W[29], 0xD5A79147930AA725);
- F1(C, D, E, F, G, H, A, B, W[30], 0x06CA6351E003826F);
- F1(B, C, D, E, F, G, H, A, W[31], 0x142929670A0E6E70);
- F1(A, B, C, D, E, F, G, H, W[32], 0x27B70A8546D22FFC);
- F1(H, A, B, C, D, E, F, G, W[33], 0x2E1B21385C26C926);
- F1(G, H, A, B, C, D, E, F, W[34], 0x4D2C6DFC5AC42AED);
- F1(F, G, H, A, B, C, D, E, W[35], 0x53380D139D95B3DF);
- F1(E, F, G, H, A, B, C, D, W[36], 0x650A73548BAF63DE);
- F1(D, E, F, G, H, A, B, C, W[37], 0x766A0ABB3C77B2A8);
- F1(C, D, E, F, G, H, A, B, W[38], 0x81C2C92E47EDAEE6);
- F1(B, C, D, E, F, G, H, A, W[39], 0x92722C851482353B);
- F1(A, B, C, D, E, F, G, H, W[40], 0xA2BFE8A14CF10364);
- F1(H, A, B, C, D, E, F, G, W[41], 0xA81A664BBC423001);
- F1(G, H, A, B, C, D, E, F, W[42], 0xC24B8B70D0F89791);
- F1(F, G, H, A, B, C, D, E, W[43], 0xC76C51A30654BE30);
- F1(E, F, G, H, A, B, C, D, W[44], 0xD192E819D6EF5218);
- F1(D, E, F, G, H, A, B, C, W[45], 0xD69906245565A910);
- F1(C, D, E, F, G, H, A, B, W[46], 0xF40E35855771202A);
- F1(B, C, D, E, F, G, H, A, W[47], 0x106AA07032BBD1B8);
- F1(A, B, C, D, E, F, G, H, W[48], 0x19A4C116B8D2D0C8);
- F1(H, A, B, C, D, E, F, G, W[49], 0x1E376C085141AB53);
- F1(G, H, A, B, C, D, E, F, W[50], 0x2748774CDF8EEB99);
- F1(F, G, H, A, B, C, D, E, W[51], 0x34B0BCB5E19B48A8);
- F1(E, F, G, H, A, B, C, D, W[52], 0x391C0CB3C5C95A63);
- F1(D, E, F, G, H, A, B, C, W[53], 0x4ED8AA4AE3418ACB);
- F1(C, D, E, F, G, H, A, B, W[54], 0x5B9CCA4F7763E373);
- F1(B, C, D, E, F, G, H, A, W[55], 0x682E6FF3D6B2B8A3);
- F1(A, B, C, D, E, F, G, H, W[56], 0x748F82EE5DEFB2FC);
- F1(H, A, B, C, D, E, F, G, W[57], 0x78A5636F43172F60);
- F1(G, H, A, B, C, D, E, F, W[58], 0x84C87814A1F0AB72);
- F1(F, G, H, A, B, C, D, E, W[59], 0x8CC702081A6439EC);
- F1(E, F, G, H, A, B, C, D, W[60], 0x90BEFFFA23631E28);
- F1(D, E, F, G, H, A, B, C, W[61], 0xA4506CEBDE82BDE9);
- F1(C, D, E, F, G, H, A, B, W[62], 0xBEF9A3F7B2C67915);
- F1(B, C, D, E, F, G, H, A, W[63], 0xC67178F2E372532B);
- F1(A, B, C, D, E, F, G, H, W[64], 0xCA273ECEEA26619C);
- F1(H, A, B, C, D, E, F, G, W[65], 0xD186B8C721C0C207);
- F1(G, H, A, B, C, D, E, F, W[66], 0xEADA7DD6CDE0EB1E);
- F1(F, G, H, A, B, C, D, E, W[67], 0xF57D4F7FEE6ED178);
- F1(E, F, G, H, A, B, C, D, W[68], 0x06F067AA72176FBA);
- F1(D, E, F, G, H, A, B, C, W[69], 0x0A637DC5A2C898A6);
- F1(C, D, E, F, G, H, A, B, W[70], 0x113F9804BEF90DAE);
- F1(B, C, D, E, F, G, H, A, W[71], 0x1B710B35131C471B);
- F1(A, B, C, D, E, F, G, H, W[72], 0x28DB77F523047D84);
- F1(H, A, B, C, D, E, F, G, W[73], 0x32CAAB7B40C72493);
- F1(G, H, A, B, C, D, E, F, W[74], 0x3C9EBE0A15C9BEBC);
- F1(F, G, H, A, B, C, D, E, W[75], 0x431D67C49C100D4C);
- F1(E, F, G, H, A, B, C, D, W[76], 0x4CC5D4BECB3E42B6);
- F1(D, E, F, G, H, A, B, C, W[77], 0x597F299CFC657E2A);
- F1(C, D, E, F, G, H, A, B, W[78], 0x5FCB6FAB3AD6FAEC);
- F1(B, C, D, E, F, G, H, A, W[79], 0x6C44198C4A475817);
+ u64bit W00 = load_be<u64bit>(input, 0);
+ u64bit W01 = load_be<u64bit>(input, 1);
+ u64bit W02 = load_be<u64bit>(input, 2);
+ u64bit W03 = load_be<u64bit>(input, 3);
+ u64bit W04 = load_be<u64bit>(input, 4);
+ u64bit W05 = load_be<u64bit>(input, 5);
+ u64bit W06 = load_be<u64bit>(input, 6);
+ u64bit W07 = load_be<u64bit>(input, 7);
+ u64bit W08 = load_be<u64bit>(input, 8);
+ u64bit W09 = load_be<u64bit>(input, 9);
+ u64bit W10 = load_be<u64bit>(input, 10);
+ u64bit W11 = load_be<u64bit>(input, 11);
+ u64bit W12 = load_be<u64bit>(input, 12);
+ u64bit W13 = load_be<u64bit>(input, 13);
+ u64bit W14 = load_be<u64bit>(input, 14);
+ u64bit W15 = load_be<u64bit>(input, 15);
+
+ SHA2_64_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0x428A2F98D728AE22);
+ SHA2_64_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0x7137449123EF65CD);
+ SHA2_64_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0xB5C0FBCFEC4D3B2F);
+ SHA2_64_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0xE9B5DBA58189DBBC);
+ SHA2_64_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x3956C25BF348B538);
+ SHA2_64_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x59F111F1B605D019);
+ SHA2_64_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x923F82A4AF194F9B);
+ SHA2_64_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0xAB1C5ED5DA6D8118);
+ SHA2_64_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0xD807AA98A3030242);
+ SHA2_64_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0x12835B0145706FBE);
+ SHA2_64_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0x243185BE4EE4B28C);
+ SHA2_64_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0x550C7DC3D5FFB4E2);
+ SHA2_64_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0x72BE5D74F27B896F);
+ SHA2_64_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0x80DEB1FE3B1696B1);
+ SHA2_64_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0x9BDC06A725C71235);
+ SHA2_64_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0xC19BF174CF692694);
+ SHA2_64_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0xE49B69C19EF14AD2);
+ SHA2_64_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0xEFBE4786384F25E3);
+ SHA2_64_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0x0FC19DC68B8CD5B5);
+ SHA2_64_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0x240CA1CC77AC9C65);
+ SHA2_64_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x2DE92C6F592B0275);
+ SHA2_64_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x4A7484AA6EA6E483);
+ SHA2_64_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x5CB0A9DCBD41FBD4);
+ SHA2_64_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0x76F988DA831153B5);
+ SHA2_64_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0x983E5152EE66DFAB);
+ SHA2_64_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0xA831C66D2DB43210);
+ SHA2_64_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0xB00327C898FB213F);
+ SHA2_64_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0xBF597FC7BEEF0EE4);
+ SHA2_64_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0xC6E00BF33DA88FC2);
+ SHA2_64_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0xD5A79147930AA725);
+ SHA2_64_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0x06CA6351E003826F);
+ SHA2_64_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0x142929670A0E6E70);
+ SHA2_64_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0x27B70A8546D22FFC);
+ SHA2_64_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0x2E1B21385C26C926);
+ SHA2_64_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0x4D2C6DFC5AC42AED);
+ SHA2_64_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0x53380D139D95B3DF);
+ SHA2_64_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x650A73548BAF63DE);
+ SHA2_64_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x766A0ABB3C77B2A8);
+ SHA2_64_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x81C2C92E47EDAEE6);
+ SHA2_64_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0x92722C851482353B);
+ SHA2_64_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0xA2BFE8A14CF10364);
+ SHA2_64_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0xA81A664BBC423001);
+ SHA2_64_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0xC24B8B70D0F89791);
+ SHA2_64_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0xC76C51A30654BE30);
+ SHA2_64_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0xD192E819D6EF5218);
+ SHA2_64_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0xD69906245565A910);
+ SHA2_64_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0xF40E35855771202A);
+ SHA2_64_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0x106AA07032BBD1B8);
+ SHA2_64_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0x19A4C116B8D2D0C8);
+ SHA2_64_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0x1E376C085141AB53);
+ SHA2_64_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0x2748774CDF8EEB99);
+ SHA2_64_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0x34B0BCB5E19B48A8);
+ SHA2_64_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x391C0CB3C5C95A63);
+ SHA2_64_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x4ED8AA4AE3418ACB);
+ SHA2_64_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x5B9CCA4F7763E373);
+ SHA2_64_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0x682E6FF3D6B2B8A3);
+ SHA2_64_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0x748F82EE5DEFB2FC);
+ SHA2_64_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0x78A5636F43172F60);
+ SHA2_64_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0x84C87814A1F0AB72);
+ SHA2_64_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0x8CC702081A6439EC);
+ SHA2_64_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0x90BEFFFA23631E28);
+ SHA2_64_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0xA4506CEBDE82BDE9);
+ SHA2_64_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0xBEF9A3F7B2C67915);
+ SHA2_64_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0xC67178F2E372532B);
+ SHA2_64_F(A, B, C, D, E, F, G, H, W00, W14, W09, W01, 0xCA273ECEEA26619C);
+ SHA2_64_F(H, A, B, C, D, E, F, G, W01, W15, W10, W02, 0xD186B8C721C0C207);
+ SHA2_64_F(G, H, A, B, C, D, E, F, W02, W00, W11, W03, 0xEADA7DD6CDE0EB1E);
+ SHA2_64_F(F, G, H, A, B, C, D, E, W03, W01, W12, W04, 0xF57D4F7FEE6ED178);
+ SHA2_64_F(E, F, G, H, A, B, C, D, W04, W02, W13, W05, 0x06F067AA72176FBA);
+ SHA2_64_F(D, E, F, G, H, A, B, C, W05, W03, W14, W06, 0x0A637DC5A2C898A6);
+ SHA2_64_F(C, D, E, F, G, H, A, B, W06, W04, W15, W07, 0x113F9804BEF90DAE);
+ SHA2_64_F(B, C, D, E, F, G, H, A, W07, W05, W00, W08, 0x1B710B35131C471B);
+ SHA2_64_F(A, B, C, D, E, F, G, H, W08, W06, W01, W09, 0x28DB77F523047D84);
+ SHA2_64_F(H, A, B, C, D, E, F, G, W09, W07, W02, W10, 0x32CAAB7B40C72493);
+ SHA2_64_F(G, H, A, B, C, D, E, F, W10, W08, W03, W11, 0x3C9EBE0A15C9BEBC);
+ SHA2_64_F(F, G, H, A, B, C, D, E, W11, W09, W04, W12, 0x431D67C49C100D4C);
+ SHA2_64_F(E, F, G, H, A, B, C, D, W12, W10, W05, W13, 0x4CC5D4BECB3E42B6);
+ SHA2_64_F(D, E, F, G, H, A, B, C, W13, W11, W06, W14, 0x597F299CFC657E2A);
+ SHA2_64_F(C, D, E, F, G, H, A, B, W14, W12, W07, W15, 0x5FCB6FAB3AD6FAEC);
+ SHA2_64_F(B, C, D, E, F, G, H, A, W15, W13, W08, W00, 0x6C44198C4A475817);
A = (digest[0] += A);
B = (digest[1] += B);
@@ -165,12 +171,14 @@ void sha2_64_compress(MemoryRegion<u64bit>& W,
}
+}
+
/*
* SHA-384 compression function
*/
void SHA_384::compress_n(const byte input[], size_t blocks)
{
- sha2_64_compress(W, digest, input, blocks);
+ SHA2_64::compress(digest, input, blocks);
}
/*
@@ -188,7 +196,6 @@ void SHA_384::copy_out(byte output[])
void SHA_384::clear()
{
MDx_HashFunction::clear();
- zeroise(W);
digest[0] = 0xCBBB9D5DC1059ED8;
digest[1] = 0x629A292A367CD507;
digest[2] = 0x9159015A3070DD17;
@@ -204,7 +211,7 @@ void SHA_384::clear()
*/
void SHA_512::compress_n(const byte input[], size_t blocks)
{
- sha2_64_compress(W, digest, input, blocks);
+ SHA2_64::compress(digest, input, blocks);
}
/*
@@ -222,7 +229,6 @@ void SHA_512::copy_out(byte output[])
void SHA_512::clear()
{
MDx_HashFunction::clear();
- zeroise(W);
digest[0] = 0x6A09E667F3BCC908;
digest[1] = 0xBB67AE8584CAA73B;
digest[2] = 0x3C6EF372FE94F82B;
diff --git a/src/hash/sha2_64/sha2_64.h b/src/hash/sha2_64/sha2_64.h
index dcfb7224c..124d4bbfb 100644
--- a/src/hash/sha2_64/sha2_64.h
+++ b/src/hash/sha2_64/sha2_64.h
@@ -24,13 +24,13 @@ class BOTAN_DLL SHA_384 : public MDx_HashFunction
void clear();
- SHA_384() : MDx_HashFunction(128, true, true, 16), W(80), digest(8)
+ SHA_384() : MDx_HashFunction(128, true, true, 16), digest(8)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);
void copy_out(byte[]);
- SecureVector<u64bit> W, digest;
+ SecureVector<u64bit> digest;
};
/**
@@ -45,13 +45,13 @@ class BOTAN_DLL SHA_512 : public MDx_HashFunction
void clear();
- SHA_512() : MDx_HashFunction(128, true, true, 16), W(80), digest(8)
+ SHA_512() : MDx_HashFunction(128, true, true, 16), digest(8)
{ clear(); }
private:
void compress_n(const byte[], size_t blocks);
void copy_out(byte[]);
- SecureVector<u64bit> W, digest;
+ SecureVector<u64bit> digest;
};
}
diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp
index 92acf0814..b5f7677db 100644
--- a/src/hash/skein/skein_512.cpp
+++ b/src/hash/skein/skein_512.cpp
@@ -43,7 +43,7 @@ void ubi_512(MemoryRegion<u64bit>& H,
if(to_proc % 8)
{
for(size_t j = 0; j != to_proc % 8; ++j)
- M[to_proc/8] |= ((u64bit)msg[8*(to_proc/8)+j] << (8*j));
+ M[to_proc/8] |= static_cast<u64bit>(msg[8*(to_proc/8)+j]) << (8*j);
}
H[8] = H[0] ^ H[1] ^ H[2] ^ H[3] ^
@@ -117,7 +117,8 @@ void ubi_512(MemoryRegion<u64bit>& H,
H[6] = X6 ^ M[6];
H[7] = X7 ^ M[7];
- T[1] &= ~((u64bit)1 << 62); // clear first flag if set
+ // clear first flag if set
+ T[1] &= ~(static_cast<u64bit>(1) << 62);
msg_len -= to_proc;
msg += to_proc;
@@ -128,7 +129,10 @@ void reset_tweak(MemoryRegion<u64bit>& T,
type_code type, bool final)
{
T[0] = 0;
- T[1] = ((u64bit)type << 56) | ((u64bit)1 << 62) | ((u64bit)final << 63);
+
+ T[1] = (static_cast<u64bit>(type) << 56) |
+ (static_cast<u64bit>(1) << 62) |
+ (static_cast<u64bit>(final) << 63);
}
void initial_block(MemoryRegion<u64bit>& H,
@@ -227,7 +231,7 @@ void Skein_512::add_data(const byte input[], size_t length)
void Skein_512::final_result(byte out[])
{
- T[1] |= ((u64bit)1 << 63); // final block flag
+ T[1] |= (static_cast<u64bit>(1) << 63); // final block flag
for(size_t i = buf_pos; i != buffer.size(); ++i)
buffer[i] = 0;