|
6 | 6 |
|
7 | 7 | ## What is it? |
8 | 8 |
|
9 | | -This is my conception, implementation and tests of advanced(2-layer) _DiifieHellman_(_'2lDH'_ if abbreviated) key exchange _protocol_ that works with _very long inegers_(like 19.729 chars long, can work with bigger ones if needed without any problems). You can find an _example file(main.cpp)_ at this repository with it's description. <br/><br/> |
| 9 | +This is my conception, implementation and tests of advanced(2-layer) _DiifieHellman_(_'2lDH'_ abbreviated) key exchange _protocol_ that works with _very long inegers_(like 19.729+ chars long without any problems). You can find an _example file(main.cpp)_ at this repository with it's description. <br/><br/> |
10 | 10 | Original DiffieHellman is [_here_.](https://github.com/vladimirrogozin/DiffieHellman)<br/> |
11 | 11 | It is also a part of [_RedLibrary_](https://github.com/Red-company/RedLibrary). |
12 | 12 |
|
13 | 13 | ## Why I decided to concept that? |
14 | 14 |
|
15 | | -I was understanding how _DiffieHellman_ works and some time later I thought, _DH_ is really good for making _secure client-server messaging channels_, but _I did have an idea_ how to make the algorithm longer but get an opportunity _to hide the base number_ you use. That makes it _more difficult to calculate the shared key_. |
| 15 | +I was understanding how _DiffieHellman_ works and I thought, _DH_ is really good for making _secure client-server messaging channels_, but _I did have an idea_ how to make the algorithm longer but get an opportunity _to hide the base number_ you use and get a _really good level of safety_. |
16 | 16 |
|
17 | | -## How it works by DH colors? |
| 17 | +## How _2lDH_ works by DH colors method? |
18 | 18 |
|
19 | 19 | Basically, _it is the DH_, but 2lDH firstly calculates _the base number_, and _the shared key_ after that. So, that is why it was named _"2-layer DiffieHellman"_. <br/> |
20 | 20 |
|
@@ -82,7 +82,7 @@ Shared key = hab |
82 | 82 | ---------- |
83 | 83 | ``` |
84 | 84 |
|
85 | | -So, as you can see, that looks like a doubled _DiffieHellman_, and yeah, it is, but, first of all, our _Base Num_ is hidden now, secondly, this _DH_ edition is more secure(check out standards and tests), and, thirdly, we spend _reasonable time_ to get well secured. In fact, there are some _difficulcy modes_ in this library, which gives it an _ability_ to it to be rather _wide-usable_. |
| 85 | +So, as you can see, that looks like a doubled _DiffieHellman_, and yeah, it is, but, first of all, our _Base Num_ is hidden now, secondly, this _DH_ edition is more secure(it's _not as fast_ as _original DiffieHellman_), and, thirdly, we spend _reasonable time_ to get well secured. In fact, there are some _difficulcy modes_ in this library, which gives it an _ability_ to it to be rather _wide-usable_. |
86 | 86 |
|
87 | 87 | ## Math behind it |
88 | 88 |
|
@@ -110,55 +110,65 @@ BobPublic1 = 2 ** BobKey1 mod P |
110 | 110 | ~~~~~~~~~~~~~~~~~~ |
111 | 111 |
|
112 | 112 | /// Getting the same reminder. |
113 | | -AliceShared = BobPublic1 ** AliceKey1 mod 2 |
| 113 | +AliceShared = BobPublic1 ** AliceKey1 mod 998 + 2 // Shared (E [2;100]. |
114 | 114 |
|
115 | | -BobShared = AlicePublic1 ** BobKey1 mod 2 |
| 115 | +BobShared = AlicePublic1 ** BobKey1 mod 998 + 2 // Shared (E [2;100]. |
116 | 116 |
|
117 | | -/// Getting a base num. |
118 | | -if (*u == 0) { |
119 | | - m_base = 2; |
120 | | -
|
121 | | -} else if (*u == 1) { |
122 | | - m_base = 3; |
123 | | -} |
124 | 117 |
|
125 | 118 |
|
126 | 119 | Part 2(getting the shared secret) |
127 | 120 | --------------------------------- |
128 | 121 |
|
129 | | -SharedBase = m_base // Just copied, let's abbreviate. |
| 122 | +SharedBase is our base num. |
130 | 123 |
|
131 | 124 | 1) Public keys. |
132 | 125 | ~~~~~~~~~~~~~~~ |
133 | 126 |
|
134 | 127 | /// Getting a public keys. |
135 | | -AlicePublic2 = SharedBase ** AliceKey2 mod P |
136 | | -
|
137 | | -BobPublic2 = SharedBase ** BobKey2 mod P |
138 | | -
|
| 128 | +AlicePublic2 = SharedBase ** (rand() % (standard / log2(SharedBase))) + 1 |
| 129 | + """""""""""""""""""""""""""""""""""""""""""" // Same. |
| 130 | + |
| 131 | +BobPublic2 = SharedBase ** (rand() % (standard / log2(SharedBase))) + 1 |
| 132 | + """""""""""""""""""""""""""""""""""""""""""" // Same. |
139 | 133 |
|
140 | 134 | 2) Symmetric Secret. |
141 | 135 | ~~~~~~~~~~~~~~~~~~~~ |
142 | 136 |
|
143 | 137 | /// Getting the symmetric pair. |
144 | | -AliceSymmetric = BobPublic2 ** AliceKey2 mod P |
| 138 | +AliceSymmetric = BobPublic2 ** (rand() % (standard / log2(SharedBase))) + 1 |
| 139 | + """""""""""""""""""""""""""""""""""""""""""" // Same. |
145 | 140 |
|
146 | | -BobSymmetric = AlicePublic2 ** BobKey2 mod P |
| 141 | +BobSymmetric = AlicePublic2 ** (rand() % (standard / log2(SharedBase))) + 1 |
| 142 | + """""""""""""""""""""""""""""""""""""""""""" // Same. |
147 | 143 |
|
148 | 144 |
|
149 | 145 | /// Finally. |
150 | 146 | AliceSymmetric = BobSymmetric |
151 | 147 | -------------- ------------ |
152 | 148 | ``` |
153 | 149 |
|
154 | | -I am using _Prime number_ equal to _-1_, because I want the algorithm _to be un-cutted in range_ in all operations, at the end especially. |
| 150 | +In the example file I used _Prime number_ equal to _-1_, because I wanted the algorithm _to be un-cutted in range_ in all operations(I wanted to get a pair of fingerprints that can be used for encryption functions). |
155 | 151 |
|
156 | 152 | The crucial thing in classic DiffieHellman is that you're exchanging something, that it's impossible to calculate sqrt from(or at least toooooooooo difficult, as difficult that useless): |
157 | 153 |
|
158 | 154 | ```C |
159 | | -Est. chance of getting the one we need = lim[x->0] |
| 155 | + 6k. |
| 156 | +------- |
| 157 | + |
| 158 | +Time spent to calculate for example = 4s. |
| 159 | + |
| 160 | +Max value is about (2 ** (6.000 * 6.000)). |
| 161 | + |
| 162 | +Just imagine how much time that takes. |
| 163 | +Or calculate in a big num calculator. |
160 | 164 | ``` |
| 165 | +<br/> |
| 166 | +So, as that is so, we can conclude: |
161 | 167 |
|
| 168 | +```C |
| 169 | +Est. chance of getting the one we need = lim[x->0] |
| 170 | +``` |
| 171 | +<br/> |
162 | 172 | As we use _2lDH_ that is like 2x _DiffieHellman_, that can be wrote as funny math like: |
163 | 173 |
|
164 | 174 | ```C |
@@ -195,60 +205,27 @@ I made some _standards_ for each part to use _2lDH_ in way you need. *Let's chec |
195 | 205 |
|
196 | 206 | As it can use different bases, I've separated these tables. |
197 | 207 |
|
198 | | -#### 140m |
199 | | - |
200 | | -| base | num of possible variations, millions | sqrt(max) | Max time spend(in seconds) | |
201 | | -|------|--------------------------------------|-----------|----------------------------| |
202 | | -| 2 | 36m | 8.366 | 2,577 | |
203 | | -| 3 | 36m | 5.916 | 2,671 | |
204 | | - |
205 | | - |
206 | | -#### 280m |
| 208 | +We have a problem in fact, I don't know how to calculate the nums here. They differs a lot(exponent can equal to 1, or to the max one), so, let me write just the range I got by executing the examples some times... |
207 | 209 |
|
208 | | -| base | num of possible variations, millions | sqrt(max) | Max time spend(in seconds) | |
209 | | -|------|--------------------------------------|-----------|----------------------------| |
210 | | -| 2 | 126m | 11.224 | 7,556 | |
211 | | -| 4 | 70m | 8.366 | 8,081 | |
212 | | -| 8 | 49m | 7.000 | 8,849 | |
213 | | -| 16 | 35m | 5.916 | 8,435 | |
214 | | - |
215 | | -#### 490m |
| 210 | +#### Table |
216 | 211 |
|
217 | | -| base | num of possible variations, millions | sqrt(max) | Max time spend(in seconds) | |
| 212 | +| difficulcy mode | num of possible variations | sqrt(max) | Time spent(in seconds) | |
218 | 213 | |------|--------------------------------------|-----------|----------------------------| |
219 | | -| 2 | 238m | 15.427 | 20,362 | |
220 | | -| 4 | 119m | 10.908 | 20,686 | |
221 | | -| 8 | 77m | 8.774 | 19,613 | |
222 | | -| 16 | 56m | 7.483 | 19,165 | |
| 214 | +| 6k | 36.000.000 | 6.000 | 0.8-4 | |
| 215 | +| 8k | 64.000.000 | 8.000 | 0-4 | |
| 216 | +| 11k | 121.000.000 | 11.000 | 1-??? | |
| 217 | +| 16k | 256.000.000 | 16.000 | 1-16 | |
223 | 218 |
|
224 | | -#### 693m |
| 219 | +So, it's possible to spend a lot of time calculating this. |
225 | 220 |
|
226 | | -| base | num of possible variations, millions | sqrt(max) | Max time spend(in seconds) | |
227 | | -|------|--------------------------------------|-----------|----------------------------| |
228 | | -| 2 | 336m | 18.330 | 40,834 | |
229 | | -| 4 | 161m | 12.688 | 41,172 | |
230 | | -| 8 | 112m | 10.583 | 41,572 | |
231 | | -| 16 | 84m | 9.165 | 39,664 | |
232 | | - |
233 | | -#### 1543m |
234 | | - |
235 | | -| base | num of possible variations, millions | sqrt(max) | Max time spend(in seconds) | |
236 | | -|------|--------------------------------------|-----------|----------------------------| |
237 | | -| 2 | 721m | 26.851 | 197,268 | |
238 | | -| 4 | 364m | 19.078 | 199,839 | |
239 | | -| 8 | 283m | 15.427 | 196,951 | |
240 | | -| 16 | 175m | 13.228 | 221,794 | |
241 | 221 |
|
242 | 222 | ## Example |
243 | 223 |
|
244 | | -First of all, let me show that all _bases_ works: |
245 | | - |
246 | | - |
247 | | - |
248 | | -And now, let's get _the shared secret_ from _0 point_: |
| 224 | +I had to spend 25 seconds to calculate a pair(16k mode): |
249 | 225 |
|
250 | 226 |  |
251 | 227 |  |
| 228 | + |
252 | 229 |
|
253 | 230 | ## Where to use? |
254 | 231 |
|
|
0 commit comments