Debian Codegraph @

dh/groups.go

raw symbols SCIP
1 // Use of this source code is governed by a license
2 // that can be found in the LICENSE file.
3
4 package dh
5
6 import (
7 "math/big"
8 "sync"
9 )
10
11 // DH groups defined in https://www.ietf.org/rfc/rfc3526.txt
12 const (
13 // The 2048 bit prime form 3.
14 rfc3526_2048G = "02"
15 rfc3526_2048P = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3" +
16 "404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BF" +
17 "B5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C6" +
18 "2F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28" +
19 "FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF"
20
21 // The 3072 bit prime form 4.
22 rfc3526_3072G = "02"
23 rfc3526_3072P = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3" +
24 "404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BF" +
25 "B5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C6" +
26 "2F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28" +
27 "FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1" +
28 "CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA0" +
29 "6D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B8" +
30 "2D120A93AD2CAFFFFFFFFFFFFFFFF"
31
32 // The 4096 bit prime form 5.
33 rfc3526_4096G = "02"
34 rfc3526_4096P = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3" +
35 "404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BF" +
36 "B5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C6" +
37 "2F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28" +
38 "FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1" +
39 "CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA0" +
40 "6D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B8" +
41 "2D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF" +
42 "92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B" +
43 "05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFFFFF"
44 )
45
46 var once sync.Once
47 var rfc3526_2048 *Group
48 var rfc3526_3072 *Group
49 var rfc3526_4096 *Group
50
51 func initRFC3526_2048() {
52 rfc3526_2048 = &Group{}
53 rfc3526_2048.G, _ = new(big.Int).SetString(rfc3526_2048G, 16)
54 rfc3526_2048.P, _ = new(big.Int).SetString(rfc3526_2048P, 16)
55
56 }
57
58 func initRFC3526_3072() {
59 rfc3526_3072 = &Group{}
60 rfc3526_3072.G, _ = new(big.Int).SetString(rfc3526_3072G, 16)
61 rfc3526_3072.P, _ = new(big.Int).SetString(rfc3526_3072P, 16)
62
63 }
64
65 func initRFC3526_4096() {
66 rfc3526_4096 = &Group{}
67 rfc3526_4096.G, _ = new(big.Int).SetString(rfc3526_4096G, 16)
68 rfc3526_4096.P, _ = new(big.Int).SetString(rfc3526_4096P, 16)
69 }
70
71 // Initialize the primes and generators
72 func initAll() {
73 initRFC3526_2048()
74 initRFC3526_3072()
75 initRFC3526_4096()
76 }
77
78 // RFC3526_2048 creates a new dh.Group consisting of the prime
79 // and the generator. The prime (and generator) are
80 // described in RFC 3526 (3.). The prime is a 2048 bit value.
81 func RFC3526_2048() *Group {
82 once.Do(initAll)
83 g := &Group{
84 P: new(big.Int).Set(rfc3526_2048.P),
85 G: new(big.Int).Set(rfc3526_2048.G),
86 }
87 return g
88 }
89
90 // RFC3526_3072 creates a new dh.Group consisting of the prime
91 // and the generator. The prime (and generator) are
92 // described in RFC 3526 (4.). The prime is a 3072 bit value.
93 func RFC3526_3072() *Group {
94 once.Do(initAll)
95 g := &Group{
96 P: new(big.Int).Set(rfc3526_3072.P),
97 G: new(big.Int).Set(rfc3526_3072.G),
98 }
99 return g
100 }
101
102 // RFC3526_4096 creates a new dh.Group consisting of the prime
103 // and the generator. The prime (and generator) are
104 // described in RFC 3526 (5.). The prime is a 4096 bit value.
105 func RFC3526_4096() *Group {
106 once.Do(initAll)
107 g := &Group{
108 P: new(big.Int).Set(rfc3526_4096.P),
109 G: new(big.Int).Set(rfc3526_4096.G),
110 }
111 return g
112 }