monotone

monotone Mtn Source Tree

Root/botan/dl_group.cpp

1/*************************************************
2* DL Groups Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/dl_param.h>
7
8namespace Botan {
9
10namespace {
11
12/*************************************************
13* IETF 768-bit DL modulus *
14*************************************************/
15const char* IETF_768_PRIME =
16 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1"
17 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD"
18 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245"
19 "E485B576 625E7EC6 F44C42E9 A63A3620 FFFFFFFF FFFFFFFF";
20
21/*************************************************
22* IETF 1024-bit DL modulus *
23*************************************************/
24const char* IETF_1024_PRIME =
25 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1"
26 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD"
27 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245"
28 "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED"
29 "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381"
30 "FFFFFFFF FFFFFFFF";
31
32/*************************************************
33* IETF 1536-bit DL modulus *
34*************************************************/
35const char* IETF_1536_PRIME =
36 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1"
37 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD"
38 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245"
39 "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED"
40 "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D"
41 "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F"
42 "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D"
43 "670C354E 4ABC9804 F1746C08 CA237327 FFFFFFFF FFFFFFFF";
44
45/*************************************************
46* IETF 2048-bit DL modulus *
47*************************************************/
48const char* IETF_2048_PRIME =
49 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1"
50 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD"
51 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245"
52 "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED"
53 "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D"
54 "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F"
55 "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D"
56 "670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B"
57 "E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9"
58 "DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510"
59 "15728E5A 8AACAA68 FFFFFFFF FFFFFFFF";
60
61/*************************************************
62* IETF 3072-bit DL modulus *
63*************************************************/
64const char* IETF_3072_PRIME =
65 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1"
66 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD"
67 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245"
68 "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED"
69 "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D"
70 "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F"
71 "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D"
72 "670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B"
73 "E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9"
74 "DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510"
75 "15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64"
76 "ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7"
77 "ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B"
78 "F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C"
79 "BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31"
80 "43DB5BFC E0FD108E 4B82D120 A93AD2CA FFFFFFFF FFFFFFFF";
81
82/*************************************************
83* IETF 4096-bit DL modulus *
84*************************************************/
85const char* IETF_4096_PRIME =
86 "FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1"
87 "29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD"
88 "EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245"
89 "E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED"
90 "EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE45B3D"
91 "C2007CB8 A163BF05 98DA4836 1C55D39A 69163FA8 FD24CF5F"
92 "83655D23 DCA3AD96 1C62F356 208552BB 9ED52907 7096966D"
93 "670C354E 4ABC9804 F1746C08 CA18217C 32905E46 2E36CE3B"
94 "E39E772C 180E8603 9B2783A2 EC07A28F B5C55DF0 6F4C52C9"
95 "DE2BCBF6 95581718 3995497C EA956AE5 15D22618 98FA0510"
96 "15728E5A 8AAAC42D AD33170D 04507A33 A85521AB DF1CBA64"
97 "ECFB8504 58DBEF0A 8AEA7157 5D060C7D B3970F85 A6E1E4C7"
98 "ABF5AE8C DB0933D7 1E8C94E0 4A25619D CEE3D226 1AD2EE6B"
99 "F12FFA06 D98A0864 D8760273 3EC86A64 521F2B18 177B200C"
100 "BBE11757 7A615D6C 770988C0 BAD946E2 08E24FA0 74E5AB31"
101 "43DB5BFC E0FD108E 4B82D120 A9210801 1A723C12 A787E6D7"
102 "88719A10 BDBA5B26 99C32718 6AF4E23C 1A946834 B6150BDA"
103 "2583E9CA 2AD44CE8 DBBBC2DB 04DE8EF9 2E8EFC14 1FBECAA6"
104 "287C5947 4E6BC05D 99B2964F A090C3A2 233BA186 515BE7ED"
105 "1F612970 CEE2D7AF B81BDD76 2170481C D0069127 D5B05AA9"
106 "93B4EA98 8D8FDDC1 86FFB7DC 90A6C08F 4DF435C9 34063199"
107 "FFFFFFFF FFFFFFFF";
108
109/*************************************************
110* JCE default 512-bit DSA group *
111*************************************************/
112const char* JCE_512_PRIME_P =
113 "FCA682CE 8E12CABA 26EFCCF7 110E526D B078B05E DECBCD1E"
114 "B4A208F3 AE1617AE 01F35B91 A47E6DF6 3413C5E1 2ED0899B"
115 "CD132ACD 50D99151 BDC43EE7 37592E17";
116const char* JCE_512_PRIME_Q =
117 "962EDDCC 369CBA8E BB260EE6 B6A126D9 346E38C5";
118
119/*************************************************
120* JCE default 768-bit DSA group *
121*************************************************/
122const char* JCE_768_PRIME_P =
123 "E9E64259 9D355F37 C97FFD35 67120B8E 25C9CD43 E927B3A9"
124 "670FBEC5 D8901419 22D2C3B3 AD248009 3799869D 1E846AAB"
125 "49FAB0AD 26D2CE6A 22219D47 0BCE7D77 7D4A21FB E9C270B5"
126 "7F607002 F3CEF839 3694CF45 EE3688C1 1A8C56AB 127A3DAF";
127const char* JCE_768_PRIME_Q =
128 "9CDBD84C 9F1AC2F3 8D0F80F4 2AB952E7 338BF511";
129
130/*************************************************
131* JCE default 1024-bit DSA group *
132*************************************************/
133const char* JCE_1024_PRIME_P =
134 "FD7F5381 1D751229 52DF4A9C 2EECE4E7 F611B752 3CEF4400"
135 "C31E3F80 B6512669 455D4022 51FB593D 8D58FABF C5F5BA30"
136 "F6CB9B55 6CD7813B 801D346F F26660B7 6B9950A5 A49F9FE8"
137 "047B1022 C24FBBA9 D7FEB7C6 1BF83B57 E7C6A8A6 150F04FB"
138 "83F6D3C5 1EC30235 54135A16 9132F675 F3AE2B61 D72AEFF2"
139 "2203199D D14801C7";
140const char* JCE_1024_PRIME_Q =
141 "9760508F 15230BCC B292B982 A2EB840B F0581CF5";
142
143/*************************************************
144* Decode the modulus string *
145*************************************************/
146BigInt decode(const char* prime)
147 {
148 return BigInt::decode((const byte*)prime, std::strlen(prime),
149 BigInt::Hexadecimal);
150 }
151
152}
153
154/*************************************************
155* Try to obtain a particular DL group *
156*************************************************/
157DL_Group try_to_get_dl_group(const std::string& name)
158 {
159 if(name == "DSA-512" || name == "DSA-768" || name == "DSA-1024")
160 {
161 const char* P = 0;
162 const char* Q = 0;
163 if(name == "DSA-512") { P = JCE_512_PRIME_P; Q = JCE_512_PRIME_Q; }
164 if(name == "DSA-768") { P = JCE_768_PRIME_P; Q = JCE_768_PRIME_Q; }
165 if(name == "DSA-1024") { P = JCE_1024_PRIME_P; Q = JCE_1024_PRIME_Q; }
166
167 BigInt p = decode(P), q = decode(Q);
168 BigInt g = DL_Group::make_dsa_generator(p, q);
169 return DL_Group(p, q, g);
170 }
171
172 BigInt p, g;
173
174 if(name == "IETF-768") { g = 2; p = decode(IETF_768_PRIME); }
175 if(name == "IETF-1024") { g = 2; p = decode(IETF_1024_PRIME); }
176 if(name == "IETF-1536") { g = 2; p = decode(IETF_1536_PRIME); }
177 if(name == "IETF-2048") { g = 2; p = decode(IETF_2048_PRIME); }
178 if(name == "IETF-3072") { g = 2; p = decode(IETF_3072_PRIME); }
179 if(name == "IETF-4096") { g = 2; p = decode(IETF_4096_PRIME); }
180
181 if(p > 0 && g > 0)
182 return DL_Group(p, g);
183
184 throw Lookup_Error("DL group \"" + name + "\" not found");
185 }
186
187}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status