-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
55 lines (46 loc) · 1.25 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <sodium.h>
#include <cstring>
#define PASSWORD "Correct Horse Battery Staple"
int main(int argc, char **argv)
{
std::cout << "Hello sodium" << std::endl;
if (sodium_init() == -1) {
std::cout << "Sodium not initiated" << std::endl;
} else {
std::cout << "Sodium initiated" << std::endl;
char hashed_password[crypto_pwhash_STRBYTES];
if (crypto_pwhash_str(
hashed_password,
PASSWORD,
strlen(PASSWORD),
crypto_pwhash_OPSLIMIT_INTERACTIVE,
crypto_pwhash_MEMLIMIT_INTERACTIVE) != 0) {
/* out of memory */
}
std::cout << "Hashed pass: " << hashed_password << std::endl;
if (0 != crypto_pwhash_str_verify(
hashed_password,
PASSWORD,
strlen(PASSWORD)
)) {
std::cout << "Wrong password" << std::endl;
}
else
{
std::cout << "Password OK" << std::endl;
}
if(crypto_pwhash_str_needs_rehash(
hashed_password,
crypto_pwhash_OPSLIMIT_INTERACTIVE,
crypto_pwhash_MEMLIMIT_INTERACTIVE) != 0)
{
std::cout << "It needs rehash" << std::endl;
}
else
{
std::cout << "It doesn't need rehash" << std::endl;
}
}
return 0;
}