Skip to content

Commit 708dd98

Browse files
committed
Add explanation about security in README
1 parent beaec46 commit 708dd98

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,67 @@ gpg: encrypted with 1 passphrase
9292
:~$ passphrase -q -o pass.txt
9393
```
9494

95+
## Is this really secure?
96+
97+
First of all, we will say that a password or passphrase generator algorithm is secure if its output is *trully* random. To achieve that, **Passphrase** relies entirely on known libraries and does not interferes with the random algorithm. The whole program is quite big, but most of it is just the menues and the word list. The generator algorithms are very short and simple:
98+
99+
[For Python 3.6+](https://github.com/HacKanCuBa/passphrase-py/blob/e5f7bf30cc04cd257d1b05dbfad760f676e0b3e6/src/passphrase.py#L7830):
100+
101+
```python
102+
from secrets import choice, randbelow
103+
104+
def generate(wordlist: list, amount_w: int, amount_n: int) -> list:
105+
passphrase = []
106+
for i in range(0, amount_w):
107+
passphrase.append(choice(wordlist))
108+
109+
for i in range(0, amount_n):
110+
passphrase.append(randbelow(MAX_NUM))
111+
112+
return passphrase
113+
114+
def generate_password(length: int) -> str:
115+
characters = digits + ascii_letters + punctuation
116+
return ''.join(choice(characters) for i in range(0, length + 1))
117+
118+
```
119+
120+
The whole magic is done by `choice(wordlist)` or `choice(characters)`, that returns a random value from the given list, and `randbelow(MAX_NUM)`, which returns a random natural number lower than the given maximum.
121+
122+
[For Python 3.2+](https://github.com/HacKanCuBa/passphrase-py/blob/e5f7bf30cc04cd257d1b05dbfad760f676e0b3e6/src/passphrase.py#L7849):
123+
124+
```python
125+
from libnacl import randombytes_uniform
126+
127+
def generate(wordlist: list, amount_w: int, amount_n: int) -> list:
128+
passphrase = []
129+
index = None
130+
num = None
131+
for i in range(0, amount_w):
132+
index = randombytes_uniform(len(wordlist))
133+
passphrase.append(wordlist[index])
134+
135+
for i in range(0, amount_n):
136+
num = randombytes_uniform(MAX_NUM)
137+
passphrase.append(num)
138+
139+
return passphrase
140+
141+
def generate_password(length: int) -> str:
142+
characters = digits + ascii_letters + punctuation
143+
passwd = []
144+
index = None
145+
for i in range(0, length + 1):
146+
index = randombytes_uniform(len(characters))
147+
passwd.append(characters[index])
148+
149+
return ''.join(passwd)
150+
```
151+
152+
The whole magic is done by `randombytes_uniform()`, that returns a random natural number lower than the given value, which is then used as index for the word or character list.
153+
154+
Both algorithms are very similar and pretty straight forward, easy to understand and verify. *Boring crypto is the best crypto*.
155+
95156
## License
96157

97158
**Passphrase** is made by [HacKan](https://hackan.net) under GNU GPL v3.0+. You are free to use, share, modify and share modifications under the terms of that [license](LICENSE).

0 commit comments

Comments
 (0)