0

How set (or get after signing) random number for function openssl_sign?

$pkEcPem = "-----BEGIN EC PRIVATE KEY-----302e0201010420...a00706052b8104000a-----END EC PRIVATE KEY-----"
$pk = openssl_pkey_get_private($pkEcPem);
$signature = null;
openssl_sign($message, $signature, $pk, $algo);
openssl_free_key($pk);

Example of implementation in the PHP library https://github.com/phpecc/phpecc/blob/master/src/Crypto/Signature/Signer.php#L36

Variant names of this value

  • random Key
  • random Number
  • random Point
2
  • The fact that k (the random number) must be generated explicitly is a peculiarity of the linked library. Depending on the value of k, the library controls in this way whether the non-deterministic ECDSA variant (arbitrary k) or the deterministic ECDSA variant (determination of k according to RFC6979) is used (see the ECDSA sample). Commented Apr 8, 2024 at 9:46
  • In most libraries, the generation of k takes place internally (and is not carried out by the user) and different methods or a flag are used to distinguish between the two variants (if the library offers both variants at all). AFAIK, openssl_sign() only supports non-deterministic ECDSA. For deterministic ECDSA you have to use a different library. Commented Apr 8, 2024 at 9:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.