?
This document uses PHP Chinese website manual Release
import "crypto/ecdsa"
概述
索引
軟件包 ecdsa 使用 FIPS 186-3 中定義的橢圓曲線數(shù)字簽名算法。
此實(shí)現(xiàn)從由 ChopMD(256, SHA2-512(priv.D || entropy || hash)) 鍵入的 AES-CTR CSPRNG 派生 nonce。CSPRNG 的關(guān)鍵在于 Coro n 的結(jié)果是IRO;在標(biāo)準(zhǔn)假設(shè)下,AES-CTR 流是IRO。
func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err error)
func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool
type PrivateKey
func GenerateKey(c elliptic.Curve, rand io.Reader) (*PrivateKey, error)
func (priv *PrivateKey) Public() crypto.PublicKey
func (priv *PrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
type PublicKey
ecdsa.go
func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err error)
簽名使用私鑰 priv 來簽名散列(這應(yīng)該是散列較大郵件的結(jié)果)。如果散列長度大于私鑰的曲線順序的位長度,則散列將被截?cái)酁樵撻L度。它將簽名作為一對整數(shù)返回。私鑰的安全性取決于 rand 的熵。
func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool
驗(yàn)證使用公共密鑰 pub,驗(yàn)證散列r,s中的簽名。其返回值記錄簽名是否有效。
PrivateKey 代表 ECDSA 私鑰。
type PrivateKey struct { PublicKey D *big.Int}
func GenerateKey(c elliptic.Curve, rand io.Reader) (*PrivateKey, error)
GenerateKey 生成公鑰和私鑰對。
func (priv *PrivateKey) Public() crypto.PublicKey
公共返回與 priv 相對應(yīng)的公鑰。
func (priv *PrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)
用 priv 簽名 msg,從 rand 中讀取隨機(jī)數(shù)。此方法旨在支持保留私有部分的密鑰,例如,硬件模塊。常見用法應(yīng)直接在此包中使用 Sign 函數(shù)。
PublicKey 表示 ECDSA 公鑰。
type PublicKey struct { elliptic.Curve X, Y *big.Int}