summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-19 20:54:01 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-19 20:54:20 (GMT)
commit250ede4f32a14f566fbafd634e2024c93677cf19 (patch)
tree7e09ea5c685e046145d5f238409af235798a85f1 /Swiften/StringCodecs/HMACSHA1.cpp
parent1e4a5816db5178b535a4405dd54df4c95491810f (diff)
downloadswift-250ede4f32a14f566fbafd634e2024c93677cf19.zip
swift-250ede4f32a14f566fbafd634e2024c93677cf19.tar.bz2
Added missing files of previous commit.
Diffstat (limited to 'Swiften/StringCodecs/HMACSHA1.cpp')
-rw-r--r--Swiften/StringCodecs/HMACSHA1.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/Swiften/StringCodecs/HMACSHA1.cpp b/Swiften/StringCodecs/HMACSHA1.cpp
new file mode 100644
index 0000000..59f1482
--- /dev/null
+++ b/Swiften/StringCodecs/HMACSHA1.cpp
@@ -0,0 +1,39 @@
+#include "Swiften/StringCodecs/HMACSHA1.h"
+
+#include <cassert>
+
+#include "Swiften/StringCodecs/SHA1.h"
+#include "Swiften/Base/ByteArray.h"
+
+namespace Swift {
+
+static const unsigned int B = 64;
+
+ByteArray HMACSHA1::getResult(const ByteArray& key, const ByteArray& data) {
+ assert(key.getSize() <= B);
+
+ // Create the padded key
+ ByteArray paddedKey(key);
+ paddedKey.resize(B);
+ for (unsigned int i = key.getSize(); i < paddedKey.getSize(); ++i) {
+ paddedKey[i] = 0x0;
+ }
+
+ // Create the first value
+ ByteArray x(paddedKey);
+ for (unsigned int i = 0; i < x.getSize(); ++i) {
+ x[i] ^= 0x36;
+ }
+ x += data;
+
+ // Create the second value
+ ByteArray y(paddedKey);
+ for (unsigned int i = 0; i < y.getSize(); ++i) {
+ y[i] ^= 0x5c;
+ }
+ y += SHA1::getBinaryHash(x);
+
+ return SHA1::getBinaryHash(y);
+}
+
+}