-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsignetcliapplication.cpp
More file actions
85 lines (75 loc) · 1.93 KB
/
signetcliapplication.cpp
File metadata and controls
85 lines (75 loc) · 1.93 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "signetcliapplication.h"
extern "C" {
#include "signetdev/host/signetdev.h"
#include "crypto_scrypt.h"
};
#include "qtsinglecoreapplication.h"
SignetCLIApplication *SignetCLIApplication::g_singleton = NULL;
SignetCLIApplication::SignetCLIApplication(int &argc, char **argv) :
QtSingleCoreApplication("qtsingle-app-signetdev-" + QString(USB_VENDOR_ID) + "-" + QString(USB_SIGNET_DESKTOP_PRODUCT_ID) ,argc, argv)
{
g_singleton = this;
}
void SignetCLIApplication::generateScryptKey(const QString &password, u8 *key, const u8 *salt, unsigned int N, unsigned int r, unsigned int s)
{
QByteArray password_utf8 = password.toUtf8();
crypto_scrypt((u8 *)password_utf8.data(), password_utf8.size(),
salt, SALT_SZ_V2,
N, r, s,
key, LOGIN_KEY_SZ);
}
void SignetCLIApplication::deviceStateToString(int deviceState ,std::string &str)
{
switch (deviceState) {
case DISCONNECTED:
str = "No connection";
break;
case UNINITIALIZED:
str = "uninitialized";
break;
case LOGGED_OUT:
str = "locked";
break;
case LOGGED_IN:
str = "unlocked";
break;
case INITIALIZING:
str = "initializing";
break;
case WIPING:
str = "wiping";
break;
case ERASING_PAGES:
str = "writing firmware - erasing";
break;
case FIRMWARE_UPDATE:
str = "writing firmware";
break;
case BACKING_UP_DEVICE:
str = "backing up device";
break;
case RESTORING_DEVICE:
str = "restoring device";
break;
default:
str = "<unknown state>";
break;
}
}
void SignetCLIApplication::generateKey(const QString &password, u8 *key, const u8 *hashfn, const u8 *salt)
{
QByteArray s = password.toUtf8();
memset(key, 0, LOGIN_KEY_SZ);
int fn = hashfn[0];
switch(fn) {
case 1: {
unsigned int N = ((unsigned int )1) << hashfn[1];
unsigned int r = ((unsigned int)hashfn[2]) + (((unsigned int)hashfn[3])<<8);
unsigned int p = (unsigned int)hashfn[4];
generateScryptKey(password, key, salt, N, r, p);
}
break;
default:
break;
}
}