peerplays-fc/src/crypto/scrypt.cpp
Vikram Rajkumar e442b29f6e Fix scrypt
2014-07-14 13:40:33 -04:00

22 lines
736 B
C++

#include <fc/crypto/scrypt.hpp>
#include <fc/exception/exception.hpp>
#include "scrypt-jane.h"
namespace fc {
unsigned log2( unsigned n )
{
if( n <= 0 ) FC_THROW_EXCEPTION( exception, "cannot take log2(${n})", ("n",n) );
unsigned i = 0;
while( n >>= 1 ) ++i;
return i;
}
void scrypt_derive_key( const std::vector<unsigned char>& passphrase, const std::vector<unsigned char>& salt,
unsigned int n, unsigned int r, unsigned int p, std::vector<unsigned char>& key )
{
scrypt( passphrase.data(), passphrase.size(), salt.data(), salt.size(),
log2( n ) - 1, log2( r ), log2( p ), key.data(), key.capacity() );
}
} // namespace fc