Skip to content

Commit

Permalink
Added scrypthash, which does sha256(scrypt(sha256(message, salt)))
Browse files Browse the repository at this point in the history
  • Loading branch information
Grandpa-Jones committed Oct 27, 2015
1 parent 6d90245 commit df02c93
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bitcoinrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ static const CRPCCommand vRPCCommands[] =
{ "importwallet", &importwallet, false, false },
{ "importprivkey", &importprivkey, false, false },
{ "encodebase58", &encodebase58, false, false },
{ "scrypthash", &scrypthash, false, false },
{ "listunspent", &listunspent, false, false },
{ "getrawtransaction", &getrawtransaction, false, false },
{ "createrawtransaction", &createrawtransaction, false, false },
Expand Down Expand Up @@ -1232,6 +1233,9 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "getblocktemplate" && n > 0) ConvertTo<Object>(params[0]);
if (strMethod == "listsinceblock" && n > 1) ConvertTo<boost::int64_t>(params[1]);

if (strMethod == "scrypthash" && n > 2) ConvertTo<boost::int64_t>(params[2]);
if (strMethod == "scrypthash" && n > 3) ConvertTo<bool>(params[3]);

if (strMethod == "sendalert" && n > 2) ConvertTo<boost::int64_t>(params[2]);
if (strMethod == "sendalert" && n > 3) ConvertTo<boost::int64_t>(params[3]);
if (strMethod == "sendalert" && n > 4) ConvertTo<boost::int64_t>(params[4]);
Expand Down
1 change: 1 addition & 0 deletions src/bitcoinrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fH
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value encodebase58(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value scrypthash(const json_spirit::Array& params, bool fHelp);

extern json_spirit::Value sendalert(const json_spirit::Array& params, bool fHelp);

Expand Down
49 changes: 49 additions & 0 deletions src/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,52 @@ Value encodebase58(const Array& params, bool fHelp)
}
return EncodeBase58(decoded);
}

Value scrypthash(const Array& params, bool fHelp)
{
if (fHelp || params.size() < 3 || params.size() > 4)
throw runtime_error(
"scrypthash <message> <salt> <rounds> [force=false]\n"
"The <message> and <salt> arguments are strings, <rounds> is an integer.\n"
"If [force] is false, then <rounds> bigger than 1024 trigger an error.\n"
"Creates a scrypt hash and returns the result as hex.");

Value value;

std::string sMessage = params[0].get_str();
std::string sSalt = params[1].get_str();
int nRounds = params[2].get_int();

bool fForce = false;

if (params.size() > 3)
{
fForce = params[3].get_bool();
}

if (sMessage.size() == 0)
{
throw runtime_error("<message> has no content");
}

if (sSalt.size() == 0)
{
throw runtime_error("<salt> has no content");
}

if (nRounds < 1)
{
throw runtime_error(strprintf("<rounds> should be greater than 0 not %d", nRounds));
}

if ((nRounds > 1024) && (fForce == false))
{
throw runtime_error(strprintf("<rounds> are more than 1024 (%d)", nRounds));
}


uint256 uHash = scrypt_salted_multiround_hash((const void *)sMessage.c_str(), sMessage.size(),
(const void *)sSalt.c_str(), sSalt.size(), nRounds);

return uHash.ToString();
}

0 comments on commit df02c93

Please sign in to comment.