package sm

  1. Overview
  2. Docs
Pure OCaml Chinese National Cryptographic Algorithm Library (SM2/SM3/SM4/ZUC)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

sm-0.1.1.tbz
sha256=4d85071a2448f91c7d6d792c1563ca2690c20e22ba188ed7bd20356e4ba684dc
sha512=0e2bbcaaeeab12a9af1287ff4ae3e0197eb6f2eafdcc337d8baf9feefca0b1575fbc043517033b22b78918d214e9ae613c2db033fd51c97a5ca5a8d28cd2198c

doc/sm/Sm2/index.html

Module Sm2Source

Sourcetype scalar
Sourcetype point
Sourcetype private_key = {
  1. private_scalar : scalar;
  2. public_point : point;
}
Sourcetype key_exchange_role = [
  1. | `Initiator
  2. | `Responder
]
Sourcetype key_exchange_result = {
  1. shared_key : string;
  2. confirmation_in : string;
  3. confirmation_out : string;
}
Sourceval scalar_of_hex : string -> scalar
Sourceval scalar_to_hex : scalar -> string
Sourceval point_of_hex : x:string -> y:string -> point
Sourceval point_to_hex : point -> string * string
Sourceval derive_public_key : scalar -> point
Sourceval za : id:string -> point -> string
Sourceval digest_for_sign : id:string -> point -> string -> string
Sourceval sign_digest : k:scalar -> priv:scalar -> digest:string -> scalar * scalar
Sourceval verify_digest : pub:point -> digest:string -> signature:(scalar * scalar) -> bool
Sourceval encrypt : k:scalar -> pub:point -> string -> string
Sourceval decrypt : priv:scalar -> string -> string option
Sourceval private_key_of_scalar : scalar -> private_key
Sourceval ephemeral_public_key : scalar -> point
Sourceval key_exchange : role:key_exchange_role -> self_id:string -> self_static:private_key -> self_ephemeral:scalar -> peer_id:string -> peer_static:point -> peer_ephemeral:point -> key_length:int -> key_exchange_result option
Sourceval encode_signature_der : (scalar * scalar) -> string
Sourceval decode_signature_der : string -> (scalar * scalar) option
Sourceval encode_private_key_sec1_der : private_key -> string
Sourceval decode_private_key_sec1_der : string -> private_key option
Sourceval encode_private_key_pkcs8_der : private_key -> string
Sourceval decode_private_key_pkcs8_der : string -> private_key option
Sourceval encode_public_key_der : point -> string
Sourceval decode_public_key_der : string -> point option
Sourceval encode_private_key_pem : [ `Sec1 | `Pkcs8 ] -> private_key -> string
Sourceval decode_private_key_pem : string -> private_key option
Sourceval encode_private_key_encrypted_pem : password:string -> salt:bytes -> iv:bytes -> iterations:int -> private_key -> string
Sourceval decode_private_key_encrypted_pem : password:string -> string -> private_key option
Sourceval encode_public_key_pem : point -> string
Sourceval decode_public_key_pem : string -> point option
Sourceval validate_public_key : ?check_order:bool -> point -> bool

Validate a public key point according to GM/T 0003.1-2012. Checks that the point is not at infinity, coordinates are in range 0, p-1, and satisfy the curve equation y^2 = x^3 + a*x + b (mod p). Optionally performs the expensive order check nP = O if check_order is true.

  • parameter point

    public key point to validate

  • parameter check_order

    if true, also verify that the point has order n (default false)

  • returns

    true if the point is a valid public key