Skip to content

Commit beb7c09

Browse files
authored
Update README.md
1 parent bc81d3f commit beb7c09

File tree

1 file changed

+42
-65
lines changed

1 file changed

+42
-65
lines changed

README.md

Lines changed: 42 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
## What is it?
88

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/>
1010
Original DiffieHellman is [_here_.](https://github.com/vladimirrogozin/DiffieHellman)<br/>
1111
It is also a part of [_RedLibrary_](https://github.com/Red-company/RedLibrary).
1212

1313
## Why I decided to concept that?
1414

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_.
1616

17-
## How it works by DH colors?
17+
## How _2lDH_ works by DH colors method?
1818

1919
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/>
2020

@@ -82,7 +82,7 @@ Shared key = hab
8282
----------
8383
```
8484
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_.
8686
8787
## Math behind it
8888
@@ -110,55 +110,65 @@ BobPublic1 = 2 ** BobKey1 mod P
110110
~~~~~~~~~~~~~~~~~~
111111
112112
/// Getting the same reminder.
113-
AliceShared = BobPublic1 ** AliceKey1 mod 2
113+
AliceShared = BobPublic1 ** AliceKey1 mod 998 + 2 // Shared (E [2;100].
114114
115-
BobShared = AlicePublic1 ** BobKey1 mod 2
115+
BobShared = AlicePublic1 ** BobKey1 mod 998 + 2 // Shared (E [2;100].
116116
117-
/// Getting a base num.
118-
if (*u == 0) {
119-
m_base = 2;
120-
121-
} else if (*u == 1) {
122-
m_base = 3;
123-
}
124117
125118
126119
Part 2(getting the shared secret)
127120
---------------------------------
128121
129-
SharedBase = m_base // Just copied, let's abbreviate.
122+
SharedBase is our base num.
130123
131124
1) Public keys.
132125
~~~~~~~~~~~~~~~
133126
134127
/// 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.
139133
140134
2) Symmetric Secret.
141135
~~~~~~~~~~~~~~~~~~~~
142136
143137
/// Getting the symmetric pair.
144-
AliceSymmetric = BobPublic2 ** AliceKey2 mod P
138+
AliceSymmetric = BobPublic2 ** (rand() % (standard / log2(SharedBase))) + 1
139+
"""""""""""""""""""""""""""""""""""""""""""" // Same.
145140
146-
BobSymmetric = AlicePublic2 ** BobKey2 mod P
141+
BobSymmetric = AlicePublic2 ** (rand() % (standard / log2(SharedBase))) + 1
142+
"""""""""""""""""""""""""""""""""""""""""""" // Same.
147143
148144
149145
/// Finally.
150146
AliceSymmetric = BobSymmetric
151147
-------------- ------------
152148
```
153149

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).
155151

156152
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):
157153

158154
```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.
160164
```
165+
<br/>
166+
So, as that is so, we can conclude:
161167
168+
```C
169+
Est. chance of getting the one we need = lim[x->0]
170+
```
171+
<br/>
162172
As we use _2lDH_ that is like 2x _DiffieHellman_, that can be wrote as funny math like:
163173

164174
```C
@@ -195,60 +205,27 @@ I made some _standards_ for each part to use _2lDH_ in way you need. *Let's chec
195205

196206
As it can use different bases, I've separated these tables.
197207

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...
207209

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
216211

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) |
218213
|------|--------------------------------------|-----------|----------------------------|
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 |
223218

224-
#### 693m
219+
So, it's possible to spend a lot of time calculating this.
225220

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 |
241221

242222
## Example
243223

244-
First of all, let me show that all _bases_ works:
245-
246-
![plot](./Screenshots/2lDH_different_bases.png)
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):
249225

250226
![plot](./Screenshots/2lDH_1.png)
251227
![plot](./Screenshots/2lDH_2.png)
228+
![plot](./Screenshots/2lDH_3.png)
252229

253230
## Where to use?
254231

0 commit comments

Comments
 (0)