Closed ghost closed 10 years ago
Are you encoding the string to a Uint8Array when signing? This is producing the same signature for me in both js-nacl and ed25519-donna:
var nacl = nacl_factory.instantiate()
var s = nacl.from_hex( "7776555BE320201162A9D9AD22D933176F0A7FCFE90E3009C6644041AAECDA35" )
var hello = nacl.encode_utf8( "hello" );
var k = nacl.crypto_sign_keypair_from_seed( s )
var sig = nacl.crypto_sign_detached( hello, k.signSk );
console.log( nacl.to_hex( k.signSk ) )
console.log( "sign" )
console.log( nacl.to_hex( k.signPk ) )
console.log( "public" )
console.log( nacl.to_hex( sig ) )
console.log( "sig" )
output:
"7776555be320201162a9d9ad22d933176f0a7fcfe90e3009c6644041aaecda3529d5a572d0d289b48776702dca4d5d9473785e12bb9aa79c8932f5131069ea6c"
sign
"29d5a572d0d289b48776702dca4d5d9473785e12bb9aa79c8932f5131069ea6c"
public
"a3b1cbbd9e537556263fab92bf4df6bcc48be23e2d3430542c197080118501b70db772c0069a1a9278d51b630721a7baaa318877060f03512df1957837e3ca0a"
sig
C++:
std::string message = "hello";
ed25519_secret_key sk = {0x77,0x76,0x55,0x5B,0xE3,0x20,0x20,0x11,0x62,0xA9,0xD9,0xAD,0x22,0xD9,0x33,0x17,0x6F,0x0A,0x7F,0xCF,0xE9,0x0E,0x30,0x09,0xC6,0x64,0x40,0x41,0xAA,0xEC,0xDA,0x35};
ed25519_public_key pk;
ed25519_signature sig;
ed25519_publickey(sk, pk);
ed25519_sign((const unsigned char *)message.c_str(), message.length(), sk, pk, sig);
floodberry, you're a genius!
I was sizeofing the const unsigned char* instead of taking string.length().
I can't thank you enough for this lib! It is unbelievably fast!
I've been able to produce the same public key from seed on both, but the signatures do not match up.
tonyg says that his library manages C-language interface's padding requirements. https://github.com/tonyg/js-nacl/issues/27
Do I need to compensate somehow in my c++ code? I don't think I'm converting from strings to const unsigned char*s incorrectly because couting both prints the same to the terminal.
Crosspost: http://stackoverflow.com/questions/22032282/uint8array-equivalent-of-a-c-string-converted-to-const-unsigned-char