SM3StreamRange
Cryptography
Description
Computes the SM3 digest over two byte ranges of a stream and packs the 32-byte digest into an AnsiString
The hashed input is the byte range [0, FirstLength) followed by the byte range [SecondStart, SecondStart + SecondLength), matching the PDF signature /ByteRange layout where the /Contents hole must be skipped; the result is raw binary with one digest byte per character, not hexadecimal text
Syntax
Delphi
Function SM3StreamRange(Input: TStream; FirstLength, SecondStart, SecondLength: Int64): AnsiString;Parameters
| Input | Stream to hash; the function seeks before each segment, so the stream position on entry does not matter |
|---|---|
| FirstLength | Number of bytes hashed from stream position 0, the half-open range [0, FirstLength); 0 skips the first segment |
| SecondStart | Stream offset where the second hashed segment begins, normally the first byte after the signature /Contents hole |
| SecondLength | Number of bytes hashed from SecondStart, the half-open range [SecondStart, SecondStart + SecondLength); 0 skips the second segment |
Return values
The raw 32-byte SM3 digest in an AnsiString, or an empty string when a range is negative, the stream is unassigned or a read comes up short |
Remarks
Part of the pure-Pascal SM3 digest (GB/T 32905-2016) that also backs the SM2 signing path; the implementation passes the standard test vectors
Example
Digest:= SM3StreamRange(FS, ByteRange[0], ByteRange[2], ByteRange[3]);