aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/hash/sha2_32
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-05-22 22:18:21 -0400
committerJack Lloyd <[email protected]>2017-05-22 22:18:21 -0400
commitcb91be3967edab3688b744e150a98d96db89b2fd (patch)
treead818dc31b2a6b2c1fb894cbf3cfcf2a70213bca /src/lib/hash/sha2_32
parent22797129ff2f746f96d3725ab45e043c506664f3 (diff)
parentb136d4e7ca350bb388a1a6d638b1010a2b1e5b73 (diff)
Merge GH #1056 Add HashFunction::copy_state and port to OpenSSL 1.1.0
Diffstat (limited to 'src/lib/hash/sha2_32')
-rw-r--r--src/lib/hash/sha2_32/sha2_32.cpp35
-rw-r--r--src/lib/hash/sha2_32/sha2_32.h2
2 files changed, 37 insertions, 0 deletions
diff --git a/src/lib/hash/sha2_32/sha2_32.cpp b/src/lib/hash/sha2_32/sha2_32.cpp
index ab6903fa7..58977b617 100644
--- a/src/lib/hash/sha2_32/sha2_32.cpp
+++ b/src/lib/hash/sha2_32/sha2_32.cpp
@@ -11,6 +11,41 @@
namespace Botan {
+std::unique_ptr<HashFunction> SHA_224::copy_state() const
+ {
+ return std::unique_ptr<HashFunction>(new SHA_224(*this));
+ }
+
+std::unique_ptr<HashFunction> SHA_256::copy_state() const
+ {
+ return std::unique_ptr<HashFunction>(new SHA_256(*this));
+ }
+
+namespace {
+
+namespace SHA2_32 {
+
+/*
+* SHA-256 Rho Function
+*/
+inline uint32_t rho(uint32_t X, uint32_t rot1, uint32_t rot2, uint32_t rot3)
+ {
+ return (rotate_right(X, rot1) ^ rotate_right(X, rot2) ^
+ rotate_right(X, rot3));
+ }
+
+/*
+* SHA-256 Sigma Function
+*/
+inline uint32_t sigma(uint32_t X, uint32_t rot1, uint32_t rot2, uint32_t shift)
+ {
+ return (rotate_right(X, rot1) ^ rotate_right(X, rot2) ^ (X >> shift));
+ }
+
+}
+
+}
+
/*
* SHA-256 F1 Function
*
diff --git a/src/lib/hash/sha2_32/sha2_32.h b/src/lib/hash/sha2_32/sha2_32.h
index ecf2e0ece..a6619f0fc 100644
--- a/src/lib/hash/sha2_32/sha2_32.h
+++ b/src/lib/hash/sha2_32/sha2_32.h
@@ -22,6 +22,7 @@ class BOTAN_DLL SHA_224 final : public MDx_HashFunction
std::string name() const override { return "SHA-224"; }
size_t output_length() const override { return 28; }
HashFunction* clone() const override { return new SHA_224; }
+ std::unique_ptr<HashFunction> copy_state() const override;
void clear() override;
@@ -43,6 +44,7 @@ class BOTAN_DLL SHA_256 final : public MDx_HashFunction
std::string name() const override { return "SHA-256"; }
size_t output_length() const override { return 32; }
HashFunction* clone() const override { return new SHA_256; }
+ std::unique_ptr<HashFunction> copy_state() const override;
void clear() override;