Source File
dsa.go
Belonging Package
crypto/dsa
package dsa
import (
)
type PublicKey struct {
Parameters
Y *big.Int
}
type PrivateKey struct {
PublicKey
X *big.Int
}
var ErrInvalidPublicKey = errors.New("crypto/dsa: invalid public key")
type ParameterSizes int
const (
L1024N160 ParameterSizes = iota
L2048N224
L2048N256
L3072N256
)
const numMRTests = 64
var , int
switch {
case L1024N160:
= 1024
= 160
case L2048N224:
= 2048
= 224
case L2048N256:
= 2048
= 256
case L3072N256:
= 3072
= 256
default:
return errors.New("crypto/dsa: invalid ParameterSizes")
}
:= make([]byte, /8)
:= make([]byte, /8)
:= new(big.Int)
:= new(big.Int)
:= new(big.Int)
:= new(big.Int)
.SetInt64(1)
:
for {
if , := io.ReadFull(, ); != nil {
return
}
[len()-1] |= 1
[0] |= 0x80
.SetBytes()
if !.ProbablyPrime(numMRTests) {
continue
}
for := 0; < 4*; ++ {
if , := io.ReadFull(, ); != nil {
return
}
[len()-1] |= 1
[0] |= 0x80
.SetBytes()
.Mod(, )
.Sub(, )
.Sub(, )
if .BitLen() < {
continue
}
if !.ProbablyPrime(numMRTests) {
continue
}
.P =
.Q =
break
}
}
:= new(big.Int)
.SetInt64(2)
:= new(big.Int)
:= new(big.Int).Sub(, )
:= new(big.Int).Div(, )
for {
.Exp(, , )
if .Cmp() == 0 {
.Add(, )
continue
}
.G =
return nil
}
}
func ( *PrivateKey, io.Reader) error {
if .P == nil || .Q == nil || .G == nil {
return errors.New("crypto/dsa: parameters not set up before generating key")
}
:= new(big.Int)
:= make([]byte, .Q.BitLen()/8)
for {
, := io.ReadFull(, )
if != nil {
return
}
.SetBytes()
if .Sign() != 0 && .Cmp(.Q) < 0 {
break
}
}
.X =
.Y = new(big.Int)
.Y.Exp(.G, , .P)
return nil
}
func ( io.Reader, *PrivateKey, []byte) (, *big.Int, error) {
randutil.MaybeReadByte()
if == 0 {
return nil, nil, ErrInvalidPublicKey
}
return
}
if .P.Sign() == 0 {
return false
}
if .Sign() < 1 || .Cmp(.Q) >= 0 {
return false
}
if .Sign() < 1 || .Cmp(.Q) >= 0 {
return false
}
:= new(big.Int).ModInverse(, .Q)
if == nil {
return false
}
:= .Q.BitLen()
if %8 != 0 {
return false
}
:= new(big.Int).SetBytes()
:= new(big.Int).Mul(, )
.Mod(, .Q)
:= .Mul(, )
.Mod(, .Q)
:= .Exp(.G, , .P)
.Exp(.Y, , .P)
.Mul(, )
.Mod(, .P)
.Mod(, .Q)
return .Cmp() == 0
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |