summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/StringCodecs/HMACSHA1.cpp')
-rw-r--r--Swiften/StringCodecs/HMACSHA1.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/Swiften/StringCodecs/HMACSHA1.cpp b/Swiften/StringCodecs/HMACSHA1.cpp
index e583e3b..fd951ae 100644
--- a/Swiften/StringCodecs/HMACSHA1.cpp
+++ b/Swiften/StringCodecs/HMACSHA1.cpp
@@ -9,37 +9,51 @@
#include <cassert>
#include <Swiften/StringCodecs/SHA1.h>
-#include <Swiften/Base/ByteArray.h>
#include <Swiften/Base/Algorithm.h>
-namespace Swift {
+using namespace Swift;
-static const unsigned int B = 64;
+namespace {
+ static const unsigned int B = 64;
-ByteArray HMACSHA1::getResult(const ByteArray& key, const ByteArray& data) {
- assert(key.size() <= B);
+ template<typename SourceType>
+ ByteArray getHMACSHA1(const SourceType& key, const ByteArray& data) {
+ assert(key.size() <= B);
- // Create the padded key
- ByteArray paddedKey(key);
- paddedKey.resize(B, 0x0);
+ // Create the padded key
+ SourceType paddedKey(key);
+ paddedKey.resize(B, 0x0);
- // Create the first value
- ByteArray x(paddedKey);
- for (unsigned int i = 0; i < x.size(); ++i) {
- x[i] ^= 0x36;
- }
- append(x, data);
+ // Create the first value
+ SourceType x(paddedKey);
+ for (unsigned int i = 0; i < x.size(); ++i) {
+ x[i] ^= 0x36;
+ }
+ append(x, data);
- // Create the second value
- ByteArray y(paddedKey);
- for (unsigned int i = 0; i < y.size(); ++i) {
- y[i] ^= 0x5c;
+ // Create the second value
+ SourceType y(paddedKey);
+ for (unsigned int i = 0; i < y.size(); ++i) {
+ y[i] ^= 0x5c;
+ }
+ append(y, SHA1::getHash(x));
+
+ return SHA1::getHash(y);
}
- append(y, SHA1::getHash(x));
+}
- return SHA1::getHash(y);
+namespace Swift {
+
+ByteArray HMACSHA1::getResult(const SafeByteArray& key, const ByteArray& data) {
+ return getHMACSHA1(key, data);
+}
+
+ByteArray HMACSHA1::getResult(const ByteArray& key, const ByteArray& data) {
+ return getHMACSHA1(key, data);
}
+
+
#if 0
// A tweaked version of HMACSHA1 that is more than twice as fast as the one above.