00001
00002
00003
00004
00005
00006
00007 #pragma once
00008
00009 #include <Swiften/Base/SafeByteArray.h>
00010 #include <Swiften/Base/Concat.h>
00011
00012 namespace Swift {
00013 class PBKDF2 {
00014 public:
00015 template<typename PRF>
00016 static ByteArray encode(const SafeByteArray& password, const ByteArray& salt, int iterations) {
00017 PRF prf;
00018 ByteArray u = prf(password, concat(salt, createByteArray("\0\0\0\1", 4)));
00019 ByteArray result(u);
00020 int i = 1;
00021 while (i < iterations) {
00022 u = prf(password, u);
00023 for (unsigned int j = 0; j < u.size(); ++j) {
00024 result[j] ^= u[j];
00025 }
00026 ++i;
00027 }
00028 return result;
00029 }
00030 };
00031 }