TPLSM2RandomK

Data types, cryptography

Description

TPLSM2RandomK is the procedural type through which PLSM2Sign obtains each nonce. The signer calls it once per signing attempt and expects K to receive exactly 32 raw big-endian bytes.

A production callback normally reads from a CSPRNG; a test can inject a fixed value. The signer clears its local copy of the nonce when it finishes and never caches the callback.

Syntax

Delphi

TPLSM2RandomK = Procedure(Out K: AnsiString);

Parameters

KReceives the nonce as exactly 32 raw big-endian bytes

Return values

NoneThe procedure has no return value; an unusable or wrong-length K simply causes that attempt to be skipped

Remarks

PLSM2Sign retries with a new nonce when k, r or s is degenerate, up to 64 attempts; a callback that never produces a usable nonce makes the call return False.

The nonce bytes pass through PLSM2BE32ToInt, which accepts only 32-byte input, so a callback that returns another length cannot produce a valid signature.

A nil callback is rejected immediately and PLSM2Sign returns False without calling it.

Never reuse a nonce for two signatures under the same private key; repeating k exposes the key in SM2 just as it does in other ECDSA-style schemes.

See also

PLSM2Sign, PLSM2Verify, PLSM2PublicKeyFromPrivate, PLSM2IntToBE32