gitee.com/lh-her-team/common@v1.5.1/crypto/hibe/hibe_slow.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_noamd64"
    12  	"gitee.com/lh-her-team/common/crypto/hibe/hibe_noamd64/hibe"
    13  	"gitee.com/lh-her-team/common/crypto/hibe/hibe_noamd64/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_noamd64.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_noamd64.DecryptHibeMsg(localId, hibeParams, prvKey, hibeMsgMap, symKeyType)
    42  }
    43  
    44  // ValidateId is used to validate id format
    45  func ValidateId(id string) error {
    46  	return hibe_noamd64.ValidateId(id)
    47  }
    48  
    49  func Setup(random io.Reader, l int) (*Params, MasterKey, error) {
    50  	return hibe.Setup(random, l)
    51  }
    52  
    53  func KeyGenFromMaster(random io.Reader, params *Params, master MasterKey, id []*big.Int) (*PrivateKey, error) {
    54  	return hibe.KeyGenFromMaster(random, params, master, id)
    55  }
    56  
    57  func KeyGenFromParent(random io.Reader, params *Params, parent *PrivateKey, id []*big.Int) (*PrivateKey, error) {
    58  	return hibe.KeyGenFromParent(random, params, parent, id)
    59  }
    60  
    61  func Encrypt(random io.Reader, params *Params, id []*big.Int, message *bn256.GT) (*Ciphertext, error) {
    62  	return hibe.Encrypt(random, params, id, message)
    63  }
    64  
    65  func Decrypt(key *PrivateKey, ciphertext *Ciphertext) *bn256.GT {
    66  	return hibe.Decrypt(key, ciphertext)
    67  }
    68  
    69  // IdStr2HibeId construct HibeId according to id
    70  func IdStr2HibeId(id string) ([]string, []*big.Int) {
    71  	return hibe_noamd64.IdStr2HibeId(id)
    72  }