3

What signature algorithm does the Node crypto module use in the following example? I can't figure it out from the documentation. The digest algorithm is SHA-256, but am I using ECDSA? Or something else?

const crypto = require('crypto');

const { privateKey, publicKey } = crypto.generateKeyPairSync('ec', { namedCurve: 'sect233k1' });

const sign = crypto.createSign('SHA256');
sign.update('some data to sign');
sign.end();
const signature = sign.sign(privateKey);

const verify = crypto.createVerify('SHA256');
verify.update('some data to sign');
verify.end();
console.log(verify.verify(publicKey, signature));
user16910834
  • 31
  • 1
  • 2
  • **YES** you are doing ECDSA, more specifically ECDSA-with-SHA256 also called SHA256-with-ECDSA. Aside from the facts that almost no-one uses 'characteristic two' i.e. GF(2^m) curves (the `t` in `sect233k1`) or curve fields smaller than 256, the remaining ambiguities are IV source and _format_ of the signature value. nodejs uses OpenSSL which uses random IV (not SIV=synthetic IV) and the ASN.1-DER format defined in RFC3279 (and 5280) not the 'plain' format used by PKCS11, XMLdsig, and JOSE/JWS/JWT -- and bitcoin _sometimes_. – dave_thompson_085 Jul 22 '22 at 13:18
  • Note that `sect233k1` is a binary field curve. Beware that not all software may support all curves, the primary field `secp256r1` aka P-256 curve may have much better support. You can more or less assume ECDSA for EC based signature generation (and ECDH for EC based key agreement). – Maarten Bodewes Jul 25 '22 at 11:16

0 Answers0