summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-08-12 20:31:47 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-08-12 20:31:47 (GMT)
commita17d7fdf1d3c2cf6dceebc6fa2d71879ce838a3f (patch)
tree89066088e392b5029cedf03125dd353e598f6958 /Swiften
parent353e9d5cd422779888d21e3780a0cb8f299f0a93 (diff)
downloadswift-a17d7fdf1d3c2cf6dceebc6fa2d71879ce838a3f.zip
swift-a17d7fdf1d3c2cf6dceebc6fa2d71879ce838a3f.tar.bz2
Added HMAC-SHA256.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/StringCodecs/HMAC_SHA256.h14
-rw-r--r--Swiften/StringCodecs/UnitTest/HMACTest.cpp13
2 files changed, 27 insertions, 0 deletions
diff --git a/Swiften/StringCodecs/HMAC_SHA256.h b/Swiften/StringCodecs/HMAC_SHA256.h
new file mode 100644
index 0000000..2d856cb
--- /dev/null
+++ b/Swiften/StringCodecs/HMAC_SHA256.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/StringCodecs/HMAC.h>
+#include <Swiften/StringCodecs/SHA256.h>
+
+namespace Swift {
+ typedef HMAC<SHA256, 64> HMAC_SHA256;
+}
diff --git a/Swiften/StringCodecs/UnitTest/HMACTest.cpp b/Swiften/StringCodecs/UnitTest/HMACTest.cpp
index 75ae23e..50b1330 100644
--- a/Swiften/StringCodecs/UnitTest/HMACTest.cpp
+++ b/Swiften/StringCodecs/UnitTest/HMACTest.cpp
@@ -12,6 +12,7 @@
#include <Swiften/Base/ByteArray.h>
#include <Swiften/StringCodecs/HMAC_SHA1.h>
+#include <Swiften/StringCodecs/HMAC_SHA256.h>
using namespace Swift;
@@ -19,6 +20,8 @@ class HMACTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(HMACTest);
CPPUNIT_TEST(testGetResult);
CPPUNIT_TEST(testGetResult_KeyLongerThanBlockSize);
+ CPPUNIT_TEST(testGetResult_RFC4231_1);
+ CPPUNIT_TEST(testGetResult_RFC4231_7);
CPPUNIT_TEST_SUITE_END();
public:
@@ -31,6 +34,16 @@ class HMACTest : public CppUnit::TestFixture {
ByteArray result(HMAC_SHA1()(createSafeByteArray("---------|---------|---------|---------|---------|----------|---------|"), createByteArray("foobar")));
CPPUNIT_ASSERT_EQUAL(createByteArray("\xd6""n""\x8f""P|1""\xd3"",""\x6"" ""\xb9\xe3""gg""\x8e\xcf"" ]+""\xa"), result);
}
+
+ void testGetResult_RFC4231_1() {
+ ByteArray result(HMAC_SHA256()(createSafeByteArray("\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 20), createByteArray("Hi There")));
+ CPPUNIT_ASSERT_EQUAL(createByteArray("\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7", 32), result);
+ }
+
+ void testGetResult_RFC4231_7() {
+ ByteArray result(HMAC_SHA256()(createSafeByteArray("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa", 131), createByteArray("This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm.")));
+ CPPUNIT_ASSERT_EQUAL(createByteArray("\x9b\x09\xff\xa7\x1b\x94\x2f\xcb\x27\x63\x5f\xbc\xd5\xb0\xe9\x44\xbf\xdc\x63\x64\x4f\x07\x13\x93\x8a\x7f\x51\x53\x5c\x3a\x35\xe2", 32), result);
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(HMACTest);