-
Notifications
You must be signed in to change notification settings - Fork 3
/
dh.go
56 lines (50 loc) · 2.22 KB
/
dh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package otr4
import "math/big"
var (
p *big.Int // prime field, assigned in RFC3526 with id 15
pMinusTwo *big.Int // for the interval [2, p−2]
q *big.Int // prime order
g3 *big.Int // group generator for Diffie-Hellman
)
func init() {
p, _ = new(big.Int).SetString(
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"+
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD"+
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"+
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"+
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"+
"C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"+
"83655D23DCA3AD961C62F356208552BB9ED529077096966D"+
"670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"+
"E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"+
"DE2BCBF6955817183995497CEA956AE515D2261898FA0510"+
"15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64"+
"ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7"+
"ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B"+
"F12FFA06D98A0864D87602733EC86A64521F2B18177B200C"+
"BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31"+
"43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF", 16)
q, _ = new(big.Int).SetString(
"7FFFFFFFFFFFFFFFE487ED5110B4611A62633145C06E0E68"+
"948127044533E63A0105DF531D89CD9128A5043CC71A026E"+
"F7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E122"+
"F242DABB312F3F637A262174D31BF6B585FFAE5B7A035BF6"+
"F71C35FDAD44CFD2D74F9208BE258FF324943328F6722D9E"+
"E1003E5C50B1DF82CC6D241B0E2AE9CD348B1FD47E9267AF"+
"C1B2AE91EE51D6CB0E3179AB1042A95DCF6A9483B84B4B36"+
"B3861AA7255E4C0278BA3604650C10BE19482F23171B671D"+
"F1CF3B960C074301CD93C1D17603D147DAE2AEF837A62964"+
"EF15E5FB4AAC0B8C1CCAA4BE754AB5728AE9130C4C7D0288"+
"0AB9472D45556216D6998B8682283D19D42A90D5EF8E5D32"+
"767DC2822C6DF785457538ABAE83063ED9CB87C2D370F263"+
"D5FAD7466D8499EB8F464A702512B0CEE771E9130D697735"+
"F897FD036CC504326C3B01399F643532290F958C0BBD9006"+
"5DF08BABBD30AEB63B84C4605D6CA371047127D03A72D598"+
"A1EDADFE707E884725C16890549D69657FFFFFFFFFFFFFFF", 16)
// for checking
pMinusTwo = sub(p, big.NewInt(2))
g3 = big.NewInt(2)
}
func isGroupElement(n *big.Int) bool {
return greatOrEqual(n, g3) && lessOrEqual(n, pMinusTwo)
}