Skip to content
Alver edited this page Mar 29, 2018 · 2 revisions

SM2 is an elliptic curve based public key cryptography family. Ontology crypto supports SM2 digital signature and encryption currently.

The recommended curve for SM2 is sm2p256v1, which is defined on a 256 bits prime field Fp.

Key pair

The SM2 key pair is just the same structure as ECDSA, as well as the serialization formats, except for the algorithm id be 0x13.

Signature

SM2 signature is similar to DSA type signatures, consists of two integers (r, s).

In generating or verifying SM2 signature, besides private/public key and the message data, another parameter is needed, which is the signer ID. Therefor when serializing a SM2 signature, the singer ID should be included:

SIGNATURE_SCHEME || ID || 0 || R || S
  • SIGNATURE_SCHEME should be SM3withSM2.
  • ID could be empty, which means using the default ID.
  • 0 is the terminator of the preceding ID.
  • R and S are the byte representation of r and s in little endian with length of 32 (sm2p256v1 defined bit length is 256).

The default ID is "1234567812345678".

Clone this wiki locally