crypto/ecdsa

ecdsa包

  • import "crypto/ecdsa"

  • 概述

  • 索引

概述

软件包 ecdsa 使用 FIPS 186-3 中定义的椭圆曲线数字签名算法。

此实现从由 ChopMD(256, SHA2-512(priv.D || entropy || hash)) 键入的 AES-CTR CSPRNG 派生 nonce。CSPRNG 的关键在于 Coro n 的结果是IRO;在标准假设下,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(查看源代码)

func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err error)

签名使用私钥 priv 来签名散列(这应该是散列较大邮件的结果)。如果散列长度大于私钥的曲线顺序的位长度,则散列将被截断为该长度。它将签名作为一对整数返回。私钥的安全性取决于 rand 的熵。

func Verify(查看源代码)

func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool

验证使用公共密钥 pub,验证散列r,s中的签名。其返回值记录签名是否有效。

type PrivateKey(查看源代码)

PrivateKey 代表 ECDSA 私钥。

type PrivateKey struct { PublicKey D *big.Int }

func GenerateKey(查看源代码)

func GenerateKey(c elliptic.Curve, rand io.Reader) (*PrivateKey, error)

GenerateKey 生成公钥和私钥对。

func (*PrivateKey) Public(查看源代码)

func (priv *PrivateKey) Public() crypto.PublicKey

公共返回与 priv 相对应的公钥。

func (*PrivateKey) Sign(查看源代码)

func (priv *PrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error)

用 priv 签名 msg,从 rand 中读取随机数。此方法旨在支持保留私有部分的密钥,例如,硬件模块。常见用法应直接在此包中使用 Sign 函数。

type PublicKey(查看源代码)

PublicKey 表示 ECDSA 公钥。

type PublicKey struct { elliptic.Curve X, Y *big.Int }