-1

Recently, I was trying to do something with the code of ECDSA. I want to change the key length of it but in vain. I checked the internet and found some source code of ECDSA, but somehow it only allows 32 bytes.

For example, I found this:

var crypto = require("crypto");
var eccrypto = require("eccrypto");     

// A new random 32-byte private key.
var privateKey = crypto.randomBytes(32);

// Corresponding uncompressed (65-byte) public key.
var publicKey = eccrypto.getPublic(privateKey);

var str = "message to sign";

// Always hash you message to sign!    
var msg = crypto.createHash("sha256").update(str).digest();

eccrypto.sign(privateKey, msg).then(function(sig) {
   console.log("Signature in DER format:", sig);
   eccrypto.verify(publicKey, msg, sig).then(function() {    
      console.log("Signature is OK");
   }).catch(function() {    
      console.log("Signature is BAD");
   });
});

from this website. I tried to change the privateKey from 32 bytes to 16 bytes and other values. It ended up giving me errors.

Recently I discovered that to have different key length you need different curves. Does anybody know how to change the curve in the above code? If not, would someone provide source code that can use different key lengths of ECDSA?

(I'm quite new to ECC, so if I used wrong terms or I completely misunderstood the concept of it, please forgive).

halfer
  • 18,701
  • 13
  • 79
  • 158
  • 1
    Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Oct 13 '17 at 16:30

1 Answers1

1

According to https://github.com/bitchan/eccrypto#implementation-details (which looks like the right library for your code) the library only supports the secp256k1 curve.

Most other libraries, if given no context other than the curve being a 256-bit curvespace, will assume it is secp256r1 (r instead of k), meaning that the library you chose doesn't interoperate with a lot of libraries. (For example, Windows 7, 8, and 8.1 cannot do secp256k1 using the OS-provided cryptographic libraries)

So for "how do I use a different sized key with this library?" the answer is "you can't, sorry". And for "what library can I use, then?" the answer is "sorry, that's outside the scope of StackOverflow".

bartonjs
  • 23,118
  • 2
  • 51
  • 90
  • Does it mean that I need to use separate code and find a separate library for each number of key length? – YMbrothers Oct 13 '17 at 15:36
  • As a rule, no. Most libraries handle multiple curves. You just happen to have found one that only supports one. – bartonjs Oct 13 '17 at 15:55