diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-08-12 17:29:21 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-08-12 17:32:17 (GMT) |
commit | c6ffcd27e94d2f90fd4a3bcb5d2d3c6550ead59c (patch) | |
tree | 5968399a0d1ae73c1f197630bef3a0960e8525b5 /Swiften/StringCodecs/PBKDF2.h | |
parent | 08cfaa06859238449d6848df4e170ffb6dc605d3 (diff) | |
download | swift-contrib-c6ffcd27e94d2f90fd4a3bcb5d2d3c6550ead59c.zip swift-contrib-c6ffcd27e94d2f90fd4a3bcb5d2d3c6550ead59c.tar.bz2 |
Refactored stringcodec functions to make them independent of hash algos.
Diffstat (limited to 'Swiften/StringCodecs/PBKDF2.h')
-rw-r--r-- | Swiften/StringCodecs/PBKDF2.h | 17 |
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; + } }; } |