PLSM2SignDigest

Cryptography

Description

Produces the two parts r and s of a GB/T 32918.2 signature over an already computed 32-byte digest

PLSM2Sign is the convenience wrapper: it hashes the user ID digest ZA and the message with SM3 and passes the result to this function

Syntax

Delphi

Function PLSM2SignDigest(Const Curve: TPLSM2Curve; Const PrivateKey: TPLSM2Int;
  Const Digest: AnsiString; Const RandomK: TPLSM2RandomK;
  Out R, S: AnsiString): Boolean;

Parameters

CurveCurve parameters, normally the SM2P256V1 constant
PrivateKeyThe signer private key d as an 8-word little-endian integer; it must not be zero and must be below the curve order minus one
DigestThe 32-byte digest to sign, big-endian; any other length returns False
RandomKCallback that supplies the ephemeral scalar k as 32 raw big-endian bytes. A fresh value is requested for every attempt, and an unassigned callback returns False
R, SReceive the signature parts r and s, each as 32 raw big-endian bytes

Return values

TrueThe signature parts were produced
FalseThe private key, the digest length or the callback is invalid, or 64 attempts did not produce a valid pair; R and S are empty

Remarks

An attempt is repeated with a new k when k is zero or not below the curve order, when r is zero, when r + k is divisible by the curve order, or when s is zero

Part of the pure-Pascal SM2 suite (GB/T 32918); verification with PLSM2Verify needs the public key point and does not use the callback

See also

PLSM2Sign, PLSM2Verify, PLSM2ComputeZA, PLSM2PublicKeyFromPrivate, SM3ByteArray