MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / keyGen

Method keyGen

cipher/dsa/dsa.go:108–119  ·  view source on GitHub ↗

keyGen is key generation for DSA 1. Choose a random integer x from the range [1, q-1] 2. Compute y = g^x mod p

()

Source from the content-addressed store, hash-verified

106// 1. Choose a random integer x from the range [1, q-1]
107// 2. Compute y = g^x mod p
108func (dsa *dsa) keyGen() {
109 // 1. Choose a random integer x from the range [1, q-1]
110 x, err := rand.Int(rand.Reader, new(big.Int).Sub(dsa.Q, big.NewInt(1)))
111 if err != nil {
112 panic(err)
113 }
114
115 dsa.privKey = x
116
117 // 2. Compute y = g^x mod p
118 dsa.pubKey = new(big.Int).Exp(dsa.G, x, dsa.P)
119}
120
121// Sign is signature generation for DSA
122// 1. Choose a random integer k from the range [1, q-1]

Callers 1

NewFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected