Guomi.SM2 (guomi v0.5.1)

Copy Markdown View Source

Pure Elixir SM2 cryptographic operations (GM/T 0003-2012).

SM2 is a Chinese commercial cryptographic algorithm standard for:

  • Key pair generation (ECDH)
  • Digital signature (ECDSA with SM3 pre-hash)
  • Encryption/decryption (ECDH + SM3 KDF + XOR + SM3 MAC)

This is a pure Elixir implementation with no external dependencies.

Summary

Types

error_reason()

@type error_reason() ::
  :invalid_key | :invalid_signature | :invalid_ciphertext | :decryption_failed

Functions

decrypt(ciphertext, private_key)

@spec decrypt(binary(), binary()) :: {:ok, binary()} | {:error, error_reason()}

encrypt(plaintext, public_key)

@spec encrypt(binary() | iodata(), binary()) ::
  {:ok, binary()} | {:error, error_reason()}

generate_keypair()

@spec generate_keypair() :: {:ok, binary(), binary()}

sign(message, private_key)

@spec sign(binary() | iodata(), binary()) ::
  {:ok, binary()} | {:error, error_reason()}

supported?()

@spec supported?() :: boolean()

verify(message, signature, public_key)

@spec verify(binary() | iodata(), binary(), binary()) ::
  {:ok, boolean()} | {:error, error_reason()}