sm9

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// hashmode used in h1: 0x01
	H1 hashMode = iota + 1
	// hashmode used in h2: 0x02
	H2
)

Variables

View Source
var KDFSalt = []byte{137, 14, 177, 175, 197, 56, 31, 254, 10, 223, 157, 232, 91, 149, 124, 75, 34, 90, 160, 85, 193, 47, 144, 90, 253, 139, 90, 135, 101, 233, 182, 250}

Functions

func Decrypt

func Decrypt(C, uid2 []byte, uke *UserKey) (M []byte, err error)

func Encrypt

func Encrypt(M, uid2 []byte, mpk *MasterPubKey) (C []byte, err error)

func Verify

func Verify(sig *Sm9Sig, msg []byte, id []byte, hid byte, mpk *MasterPubKey) bool

sm9 verify algorithm(given sig (h',S'), message M' and user's id): B1:compute g = e(P1,Ppub); B2:compute t = g^h'; B3:compute h1 = H1(id||hid,n); B4:compute P = h1·P2+Ppub; B5:compute u = e(S',P); B6:compute w' = u·t; B7:compute h2 = H2(M'||w',n), check if h2 = h'.

Types

type EncMasterKey

type EncMasterKey struct {
	Msk *big.Int
	EncMasterPubKey
}

type EncMasterPubKey

type EncMasterPubKey struct {
	Mpk *sm9curve.G1
}

type EncUserKey

type EncUserKey struct {
	Sk *sm9curve.G2
}

type MasterKey

type MasterKey struct {
	Msk *big.Int
	MasterPubKey
}

MasterKey contains a master secret key and a master public key.

func MasterKeyGen

func MasterKeyGen(rand io.Reader) (mk *MasterKey, err error)

generate master key for KGC(Key Generate Center).

type MasterPubKey

type MasterPubKey struct {
	MpkG1 *sm9curve.G1
	Mpk   *sm9curve.G2
}

type Sm9Sig

type Sm9Sig struct {
	H *big.Int
	S *sm9curve.G1
}

Sm9Sig contains a big number and an element in G1.

func Sign

func Sign(uk *UserKey, mpk *MasterPubKey, msg []byte) (sig *Sm9Sig, err error)

sm9 sign algorithm: A1:compute g = e(P1,Ppub); A2:choose random num r in [1,n-1]; A3:compute w = g^r; A4:compute h = H2(M||w,n); A5:compute l = (r-h) mod n, if l = 0 goto A2; A6:compute S = l·sk.

type UserKey

type UserKey struct {
	Sk   *sm9curve.G1
	SkG2 *sm9curve.G2
}

UserKey contains a secret key.

func UserKeyGen

func UserKeyGen(mk *MasterKey, id []byte, hid byte) (uk *UserKey, err error)

generate user's secret key.

Directories

Path Synopsis
Package bn256 implements a particular bilinear group.
Package bn256 implements a particular bilinear group.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL