?
本文檔使用 php中文網(wǎng)手冊 發(fā)布
import "crypto/dsa"
概述
索引
軟件包dsa 實現(xiàn)了 FIPS 186-3 中定義的數(shù)字簽名算法。
此包中的 DSA 操作不是使用恒定時間算法實現(xiàn)的。
Variables
func GenerateKey(priv *PrivateKey, rand io.Reader) error
func GenerateParameters(params *Parameters, rand io.Reader, sizes ParameterSizes) error
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 ParameterSizes
type Parameters
type PrivateKey
type PublicKey
dsa.go
ErrInvalidPublicKey 結(jié)果是公鑰不可用于此代碼。FIPS 對 DSA 密鑰的格式非常嚴格,但其他代碼可能不那么重要。因此,當使用可能由其他代碼生成的密鑰時,必須處理該錯誤。
var ErrInvalidPublicKey = errors.New("crypto/dsa: invalid public key")
func GenerateKey(priv *PrivateKey, rand io.Reader) error
GenerateKey 生成公鑰和私鑰對。PrivateKey 的參數(shù)必須已經(jīng)有效(請參閱 GenerateParameters)。
func GenerateParameters(params *Parameters, rand io.Reader, sizes ParameterSizes) error
GenerateParameters 將一組隨機有效的 DSA 參數(shù)放入?yún)?shù)中。即使在快速機器上,此功能也可能需要幾秒鐘的時間。
func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err error)
Sign 使用私鑰 priv 來簽名任意長度的散列(這應(yīng)該是散列較大的消息的結(jié)果)。它將簽名作為一對整數(shù)返回。私鑰的安全性取決于 rand 的熵。
請注意,F(xiàn)IPS 186-3 第4.6節(jié)指定散列應(yīng)該被截斷為子組的字節(jié)長度。該函數(shù)本身不執(zhí)行截斷。
請注意,使用 attacker-controlled 的 PrivateKey 調(diào)用 Sign 可能需要任意數(shù)量的 CPU。
func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool
驗證使用公共密鑰 pub,驗證散列 r,s 中的簽名。它報告簽名是否有效。
請注意,F(xiàn)IPS 186-3 第4.6節(jié)指定散列應(yīng)該被截斷為子組的字節(jié)長度。該函數(shù)本身不執(zhí)行截斷。
ParameterSizes 是一組 DSA 參數(shù)中素數(shù)的可接受比特長度的枚舉。參見 FIPS 186-3,第4.2節(jié)。
type ParameterSizes int
const ( L1024N160 ParameterSizes = iota L2048N224 L2048N256 L3072N256)
參數(shù)表示密鑰的域參數(shù)。這些參數(shù)可以通過許多密鑰共享。Q 的位長度必須是8的倍數(shù)。
type Parameters struct { P, Q, G *big.Int}
PrivateKey 代表 DSA 私鑰。
type PrivateKey struct { PublicKey X *big.Int}
PublicKey 代表 DSA 公鑰。
type PublicKey struct { Parameters Y *big.Int}