summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/StringCodecs/PBKDF2.h')
-rw-r--r--Swiften/StringCodecs/PBKDF2.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/Swiften/StringCodecs/PBKDF2.h b/Swiften/StringCodecs/PBKDF2.h
index b1a5986..0c04145 100644
--- a/Swiften/StringCodecs/PBKDF2.h
+++ b/Swiften/StringCodecs/PBKDF2.h
@@ -7,10 +7,25 @@
#pragma once
#include <Swiften/Base/SafeByteArray.h>
+#include <Swiften/Base/Concat.h>
namespace Swift {
class PBKDF2 {
public:
- static ByteArray encode(const SafeByteArray& password, const ByteArray& salt, int iterations);
+ template<typename PRF>
+ static ByteArray encode(const SafeByteArray& password, const ByteArray& salt, int iterations) {
+ PRF prf;
+ ByteArray u = prf(password, concat(salt, createByteArray("\0\0\0\1", 4)));
+ ByteArray result(u);
+ int i = 1;
+ while (i < iterations) {
+ u = prf(password, u);
+ for (unsigned int j = 0; j < u.size(); ++j) {
+ result[j] ^= u[j];
+ }
+ ++i;
+ }
+ return result;
+ }
};
}