aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/sha1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/sha1.cpp')
-rw-r--r--src/crypto/sha1.cpp17
1 files changed, 2 insertions, 15 deletions
diff --git a/src/crypto/sha1.cpp b/src/crypto/sha1.cpp
index 4b2e3e19d1..e0f32b7d1d 100644
--- a/src/crypto/sha1.cpp
+++ b/src/crypto/sha1.cpp
@@ -4,24 +4,12 @@
#include "crypto/sha1.h"
+#include "crypto/common.h"
#include <string.h>
// Internal implementation code.
namespace {
-/** Read 4 bytes, and interpret them as a 32-bit unsigned big-endian integer. */
-uint32_t inline ReadBE32(const unsigned char *data) {
- return ((uint32_t)data[0] << 24 | (uint32_t)data[1] << 16 | (uint32_t)data[2] << 8 | (uint32_t)data[3]);
-}
-
-/** Write a 32-bit unsigned big-endian integer. */
-void inline WriteBE32(unsigned char *data, uint32_t x) {
- data[0] = x >> 24;
- data[1] = x >> 16;
- data[2] = x >> 8;
- data[3] = x;
-}
-
/// Internal SHA-1 implementation.
namespace sha1 {
@@ -187,8 +175,7 @@ CSHA1& CSHA1::Write(const unsigned char *data, size_t len) {
void CSHA1::Finalize(unsigned char *hash) {
static const unsigned char pad[64] = {0x80};
unsigned char sizedesc[8];
- WriteBE32(sizedesc, bytes >> 29);
- WriteBE32(sizedesc+4, bytes << 3);
+ WriteBE64(sizedesc, bytes << 3);
Write(pad, 1 + ((119 - (bytes % 64)) % 64));
Write(sizedesc, 8);
WriteBE32(hash, s[0]);