Documentation
¶
Index ¶
- Variables
- func DecryptInt32(priv *sm2.PrivateKey, ciphertext *Ciphertext) (int32, error)
- func DecryptUint32(priv *sm2.PrivateKey, ciphertext *Ciphertext) (uint32, error)
- func Marshal(c *Ciphertext) ([]byte, error)
- type Ciphertext
- func (ret *Ciphertext) Add(c1, c2 *Ciphertext) *Ciphertext
- func (ret *Ciphertext) ScalarMultInt32(c *Ciphertext, m int32) *Ciphertext
- func (ret *Ciphertext) ScalarMultUint32(c *Ciphertext, m uint32) *Ciphertext
- func (ret *Ciphertext) Sub(c1, c2 *Ciphertext) *Ciphertext
- func (ret *Ciphertext) Sum(values ...*Ciphertext) *Ciphertext
- type PrivateKey
- type TwistedElgamal
- func (te *TwistedElgamal) EncryptInt32(random io.Reader, pub *ecdsa.PublicKey, m int32) (*Ciphertext, error)
- func (te *TwistedElgamal) EncryptUint32(random io.Reader, pub *ecdsa.PublicKey, m uint32) (*Ciphertext, error)
- func (te *TwistedElgamal) GenerateKey(rand io.Reader) (*TwistedPrivateKey, error)
- type TwistedPrivateKey
- func (priv *TwistedPrivateKey) DecryptInt32(ciphertext *Ciphertext) (int32, error)
- func (priv *TwistedPrivateKey) DecryptUint32(ciphertext *Ciphertext) (uint32, error)
- func (priv *TwistedPrivateKey) EncryptInt32(random io.Reader, m int32) (*Ciphertext, error)
- func (priv *TwistedPrivateKey) EncryptUint32(random io.Reader, m uint32) (*Ciphertext, error)
- func (priv *TwistedPrivateKey) Equal(x crypto.PrivateKey) bool
- func (priv *TwistedPrivateKey) GetCurve() elliptic.Curve
- func (priv *TwistedPrivateKey) GetD() *big.Int
Constants ¶
This section is empty.
Variables ¶
var ErrOverflow = fmt.Errorf("the value is overflow")
Functions ¶
func DecryptInt32 ¶
func DecryptInt32(priv *sm2.PrivateKey, ciphertext *Ciphertext) (int32, error)
DecryptInt32 decrypts ciphertext to int32, if the value overflow, it returns ErrOverflow. The negative value will be slower than positive value.
func DecryptUint32 ¶
func DecryptUint32(priv *sm2.PrivateKey, ciphertext *Ciphertext) (uint32, error)
DecryptUint32 decrypts ciphertext to uint32, if the value overflow, it returns ErrOverflow.
func Marshal ¶
func Marshal(c *Ciphertext) ([]byte, error)
Marshal converts the ciphertext to ASN.1 DER form.
Types ¶
type Ciphertext ¶
type Ciphertext struct {
// contains filtered or unexported fields
}
Ciphertext sturcture represents EL-Gamal ecnryption result.
func EncryptInt32 ¶
EncryptInt32 encrypts m with the publickey.
func EncryptUint32 ¶
EncryptUint32 encrypts m with the publickey.
func Unmarshal ¶
func Unmarshal(der []byte) (*Ciphertext, error)
Unmarshal parses ciphertext in ASN.1 DER form.
func (*Ciphertext) Add ¶
func (ret *Ciphertext) Add(c1, c2 *Ciphertext) *Ciphertext
Add returns c1 + c2.
func (*Ciphertext) ScalarMultInt32 ¶
func (ret *Ciphertext) ScalarMultInt32(c *Ciphertext, m int32) *Ciphertext
ScalarMultInt32 scalar mutiples the ciphertext with m.
func (*Ciphertext) ScalarMultUint32 ¶
func (ret *Ciphertext) ScalarMultUint32(c *Ciphertext, m uint32) *Ciphertext
ScalarMultUint32 scalar mutiples the ciphertext with m.
func (*Ciphertext) Sub ¶
func (ret *Ciphertext) Sub(c1, c2 *Ciphertext) *Ciphertext
Sub returns c1 - c2.
func (*Ciphertext) Sum ¶ added in v0.2.0
func (ret *Ciphertext) Sum(values ...*Ciphertext) *Ciphertext
Sum returns cumulative sum value
type PrivateKey ¶ added in v0.2.0
type PrivateKey interface { // GetCurve returns this private key's Curve GetCurve() elliptic.Curve // GetD returns this private key's value GetD() *big.Int }
PrivateKey is an interface for elgamal decription requirement abstraction
type TwistedElgamal ¶ added in v0.2.0
TwistedElgamal is a struct for Twisted Elagaml context which contains H and curve information.
func FromPrivateKey ¶ added in v0.2.0
func FromPrivateKey(priv *TwistedPrivateKey) *TwistedElgamal
FromPrivateKey creates related SM2 Twisted Elgamal context.
func NewTwistedElgamal ¶ added in v0.2.0
func NewTwistedElgamal(rand io.Reader) (*TwistedElgamal, error)
NewTwistedElgamal creates one SM2 Twisted Elgamal context.
func (*TwistedElgamal) EncryptInt32 ¶ added in v0.2.0
func (te *TwistedElgamal) EncryptInt32(random io.Reader, pub *ecdsa.PublicKey, m int32) (*Ciphertext, error)
EncryptInt32 encrypts m with the publickey.
func (*TwistedElgamal) EncryptUint32 ¶ added in v0.2.0
func (te *TwistedElgamal) EncryptUint32(random io.Reader, pub *ecdsa.PublicKey, m uint32) (*Ciphertext, error)
EncryptUint32 encrypts m with the publickey.
func (*TwistedElgamal) GenerateKey ¶ added in v0.2.0
func (te *TwistedElgamal) GenerateKey(rand io.Reader) (*TwistedPrivateKey, error)
GenerateKey generates a public and private key pair.
type TwistedPrivateKey ¶ added in v0.2.0
type TwistedPrivateKey struct {
ecdsa.PrivateKey
}
TwistedPrivateKey is a struct for Twisted private key, its public key can't be derived from D value without H.
func (*TwistedPrivateKey) DecryptInt32 ¶ added in v0.2.0
func (priv *TwistedPrivateKey) DecryptInt32(ciphertext *Ciphertext) (int32, error)
DecryptInt32 decrypts ciphertext to int32, if the value overflow, it returns ErrOverflow. The negative value will be slower than positive value.
func (*TwistedPrivateKey) DecryptUint32 ¶ added in v0.2.0
func (priv *TwistedPrivateKey) DecryptUint32(ciphertext *Ciphertext) (uint32, error)
DecryptUint32 decrypts ciphertext to uint32, if the value overflow, it returns ErrOverflow.
func (*TwistedPrivateKey) EncryptInt32 ¶ added in v0.2.0
func (priv *TwistedPrivateKey) EncryptInt32(random io.Reader, m int32) (*Ciphertext, error)
EncryptInt32 encrypts m with the publickey.
func (*TwistedPrivateKey) EncryptUint32 ¶ added in v0.2.0
func (priv *TwistedPrivateKey) EncryptUint32(random io.Reader, m uint32) (*Ciphertext, error)
EncryptInt32 encrypts m with the publickey.
func (*TwistedPrivateKey) Equal ¶ added in v0.2.0
func (priv *TwistedPrivateKey) Equal(x crypto.PrivateKey) bool
func (*TwistedPrivateKey) GetCurve ¶ added in v0.2.0
func (priv *TwistedPrivateKey) GetCurve() elliptic.Curve
func (*TwistedPrivateKey) GetD ¶ added in v0.2.0
func (priv *TwistedPrivateKey) GetD() *big.Int