gitee.com/lh-her-team/common@v1.5.1/crypto/hibe/hibe_fast.go (about) 1 //go:build linux && amd64 2 // +build linux,amd64 3 4 package hibe 5 6 import ( 7 "io" 8 "math/big" 9 10 "gitee.com/lh-her-team/common/crypto" 11 "gitee.com/lh-her-team/common/crypto/hibe/hibe_amd64" 12 "gitee.com/lh-her-team/common/crypto/hibe/hibe_amd64/hibe" 13 "gitee.com/lh-her-team/common/crypto/hibe/hibe_amd64/hibe/bn256" 14 ) 15 16 type Params = hibe.Params 17 type MasterKey = hibe.MasterKey 18 type Ciphertext = hibe.Ciphertext 19 type PrivateKey = hibe.PrivateKey 20 type G1 = bn256.G1 21 22 // EncryptHibeMsg is used to encrypt plainText by receiverIds and their paramsList 23 // plaintext: plain text bytes 24 // receiverIds: message receivers' id list, using "/" to separate hierarchy identity in each id string 25 // paramsList: HIBE parameters list of the message receiver, len(paramsList) should be equal to len(receiverIds), 26 // paramsList[i] are the HIBE parameters of receiverIds[i] 27 // symKeyType: symmetric key type (aes or sm4), used to symmetric encrypt the plain text first 28 func EncryptHibeMsg(plaintext []byte, receiverIds []string, paramsList []*Params, 29 symKeyType crypto.KeyType) (map[string]string, error) { 30 return hibe_amd64.EncryptHibeMsg(plaintext, receiverIds, paramsList, symKeyType) 31 } 32 33 // DecryptHibeMsg is used to decrypt the HIBE message constructed by EncryptHibeMsg 34 // localId: hibe Id 35 // hibeParams: HIBE parameters of the HIBE system to which ID belongs 36 // prvKey: the localId's hibe private Key 37 // hibeMsgMap: HIBE message encrypt by EncryptHibeMsg 38 // symKeyType: symmetric key type (aes or sm4), used to symmetric encrypt the plain text first 39 func DecryptHibeMsg(localId string, hibeParams *Params, prvKey *PrivateKey, 40 hibeMsgMap map[string]string, symKeyType crypto.KeyType) ([]byte, error) { 41 return hibe_amd64.DecryptHibeMsg(localId, hibeParams, prvKey, hibeMsgMap, symKeyType) 42 } 43 44 func Setup(random io.Reader, l int) (*Params, MasterKey, error) { 45 return hibe.Setup(random, l) 46 } 47 48 func KeyGenFromMaster(random io.Reader, params *Params, master MasterKey, id []*big.Int) (*PrivateKey, error) { 49 return hibe.KeyGenFromMaster(random, params, master, id) 50 } 51 52 func KeyGenFromParent(random io.Reader, params *Params, parent *PrivateKey, id []*big.Int) (*PrivateKey, error) { 53 return hibe.KeyGenFromParent(random, params, parent, id) 54 } 55 56 func Encrypt(random io.Reader, params *Params, id []*big.Int, message *bn256.GT) (*Ciphertext, error) { 57 return hibe.Encrypt(random, params, id, message) 58 } 59 60 func Decrypt(key *PrivateKey, ciphertext *Ciphertext) *bn256.GT { 61 return hibe.Decrypt(key, ciphertext) 62 } 63 64 // ValidateId is used to validate id format 65 func ValidateId(id string) error { 66 return hibe_amd64.ValidateId(id) 67 } 68 69 // IdStr2HibeId construct HibeId according to id 70 func IdStr2HibeId(id string) ([]string, []*big.Int) { 71 return hibe_amd64.IdStr2HibeId(id) 72 }