• Main Page
  • Classes
  • Files
  • File List

Swiften/StringCodecs/PBKDF2.h

00001 /*
00002  * Copyright (c) 2010 Remko Tronçon
00003  * Licensed under the GNU General Public License v3.
00004  * See Documentation/Licenses/GPLv3.txt for more information.
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 }

Generated on Fri Oct 12 2012 21:00:19 for Swiften by  doxygen 1.7.1