Platform SDK: Cryptography

Signature Sample

This section steps through the signature process. It uses the hash value from the Key Derivation Sample, the MD5 hash of the "124-kelp" string. This hash value is as follows:

73 40 e6 e2 74 b8 ea 39
93 95 aa 29 d6 38 b5 2a

This example uses "Test Signature" as the description string.

First, the CSP adds this string to the hash object being signed. The description string, "Test Signature," is received by the CSP in Unicode format as the following hexadecimal bytes:

54 00 65 00 73 00 74 00
20 00 53 00 69 00 67 00.
6e 00 61 00 74 00 75 00
18 72 00 65 00

After the description string has been added to the hash, the hash value is:

a8 2b df c2 c9 f1 bb 62
38 78 d4 60 fa ce 5c 2a

Next, a PKCS signature block is built. Details of the PKCS standards can be found on the RSA Security Standards Web page. The signature block is always the same size as the public key's modulus (64 bytes) and contains the following fields.

Field Bytes Description
To be signed 1 to 16 Hash of data to be signed. The size of this field varies depending on the hash algorithm used.

The bytes in the hash value are reversed before they are placed in the encryption block because the operating system formats data in little-endian format, and the encryption block must be built in big-endian format.

Algorithm specifier 17 to 34 ASN.1 encoded hash algorithm specifier. The size of this field depends on the hash algorithm used. Note that this data is also reversed. For more information on ASN.1, see the PKCS documentation.
Reserved 35 Zero value.
Padding 36 to 62 Padding data (0xff's). The size of this field is adjusted as necessary so that the signature block's overall length is correct.
Block type 63 The PKCS block type (0x01).
Reserved 64 Zero value.

The order of this table is reversed from the diagram found in the PKCS documentation because the signature block is built in big-endian on a little-endian computer.

The completed signature block in this example is:

2a 5c ce fa 60 d4 78 38
62 bb f1 c9 c2 df 2b a8
10 04 00 05 05 02 0d f7
86 48 86 2a 08 06 0c 30
20 30 00 ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff 01 00

Next, the block is encrypted with the appropriate private key. This example uses a typical but unspecified private key. This encryption results in a completed digital signature:

64 f6 46 3a 97 2e 83 38
09 57 43 cb ca 41 59 0d
03 35 d6 e4 36 6f 2c fc
63 43 95 c4 fd e2 c4 ed
06 da 9a 21 98 fc 0a 6e
3f 1c ad 3a db 7c 83 2f
14 d0 58 80 02 df dc 96
70 09 00 e3 5b bd 2b 45