Documentation ¶
Overview ¶
Copyright Suzhou Tongji Fintech Research Institute 2017 All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright Suzhou Tongji Fintech Research Institute 2017 All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func BytesCombine(pBytes ...[]byte) []byte
- func CipherMarshal(data []byte) ([]byte, error)
- func CipherUnmarshal(data []byte) ([]byte, error)
- func Compress(a *PublicKey) []byte
- func Decrypt(priv *PrivateKey, data []byte) ([]byte, error)
- func DecryptAsn1(pub *PrivateKey, data []byte) ([]byte, error)
- func Encrypt(pub *PublicKey, data []byte, random io.Reader) ([]byte, error)
- func EncryptAsn1(pub *PublicKey, data []byte, rand io.Reader) ([]byte, error)
- func KeyExchangeA(klen int, ida, idb []byte, priA *PrivateKey, pubB *PublicKey, rpri *PrivateKey, ...) (k, s1, s2 []byte, err error)
- func KeyExchangeB(klen int, ida, idb []byte, priB *PrivateKey, pubA *PublicKey, rpri *PrivateKey, ...) (k, s1, s2 []byte, err error)
- func P256Sm2() elliptic.Curve
- func SignDataToSignDigit(sign []byte) (*big.Int, *big.Int, error)
- func SignDigitToSignData(r, s *big.Int) ([]byte, error)
- func Sm2Sign(priv *PrivateKey, msg, uid []byte, random io.Reader, hashFn hash.Hash) (r, s *big.Int, err error)
- func Sm2Verify(pub *PublicKey, msg, uid []byte, r, s *big.Int, hashFn hash.Hash) bool
- func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool
- func WNafReversed(wnaf []int8) []int8
- func ZA(pub *PublicKey, uid []byte, hashFn hash.Hash) ([]byte, error)
- type PrivateKey
- func (priv *PrivateKey) Decrypt(_ io.Reader, msg []byte, _ crypto.DecrypterOpts) (plaintext []byte, err error)
- func (priv *PrivateKey) DecryptAsn1(data []byte) ([]byte, error)
- func (priv *PrivateKey) Public() crypto.PublicKey
- func (priv *PrivateKey) Sign(random io.Reader, msg []byte, signer crypto.SignerOpts) ([]byte, error)
- type PublicKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesCombine ¶
func CipherMarshal ¶
*sm2密文转asn.1编码格式 *sm2密文结构如下: * x * y * hash * CipherText
func CipherUnmarshal ¶
sm2密文asn.1编码格式转C1|C3|C2拼接格式
func DecryptAsn1 ¶
func DecryptAsn1(pub *PrivateKey, data []byte) ([]byte, error)
sm2解密,解析asn.1编码格式的密文内容
func EncryptAsn1 ¶
sm2加密,返回asn.1编码格式的密文内容
func KeyExchangeA ¶
func KeyExchangeA(klen int, ida, idb []byte, priA *PrivateKey, pubB *PublicKey, rpri *PrivateKey, rpubB *PublicKey, hashFn hash.Hash) (k, s1, s2 []byte, err error)
KeyExchangeA 协商第二部,用户A调用,返回共享密钥k
func KeyExchangeB ¶
func KeyExchangeB(klen int, ida, idb []byte, priB *PrivateKey, pubA *PublicKey, rpri *PrivateKey, rpubA *PublicKey, hashFn hash.Hash) (k, s1, s2 []byte, err error)
**************************Key agreement algorithm**************************// KeyExchangeB 协商第二部,用户B调用, 返回共享密钥k
func Verify ¶
za, err := ZA(pub, uid) if err != nil { return } e, err := msgHash(za, msg) hash=e.getBytes()
func WNafReversed ¶
Types ¶
type PrivateKey ¶
func GenerateKey ¶
func GenerateKey(random io.Reader) (*PrivateKey, error)
func (*PrivateKey) Decrypt ¶
func (priv *PrivateKey) Decrypt(_ io.Reader, msg []byte, _ crypto.DecrypterOpts) (plaintext []byte, err error)
crypto.Decrypter
func (*PrivateKey) DecryptAsn1 ¶
func (priv *PrivateKey) DecryptAsn1(data []byte) ([]byte, error)
func (*PrivateKey) Public ¶
func (priv *PrivateKey) Public() crypto.PublicKey
The SM2's private key contains the public key
func (*PrivateKey) Sign ¶
func (priv *PrivateKey) Sign(random io.Reader, msg []byte, signer crypto.SignerOpts) ([]byte, error)
sign format = 30 + len(z) + 02 + len(r) + r + 02 + len(s) + s, z being what follows its size, ie 02+len(r)+r+02+len(s)+s
type PublicKey ¶
func Decompress ¶
func (*PublicKey) EncryptAsn1 ¶
****************************Encryption algorithm****************************//