-
Notifications
You must be signed in to change notification settings - Fork 0
/
stick20hiddenvolumedialog.cpp
247 lines (205 loc) · 7.48 KB
/
stick20hiddenvolumedialog.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
* Author: Copyright (C) Rudolf Boeddeker Date: 2014-04-13
*
* This file is part of GPF Crypto Stick 2
*
* GPF Crypto Stick 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* GPF Crypto Stick is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GPF Crypto Stick. If not, see <http://www.gnu.org/licenses/>.
*/
#include "math.h"
#include "device.h"
#include "stick20hiddenvolumedialog.h"
#include "ui_stick20hiddenvolumedialog.h"
stick20HiddenVolumeDialog::stick20HiddenVolumeDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::stick20HiddenVolumeDialog)
{
ui->setupUi(this);
HV_Setup_st.SlotNr_u8 = 0;
HV_Setup_st.StartBlockPercent_u8 = 70;
HV_Setup_st.EndBlockPercent_u8 = 90;
HV_Setup_st.HiddenVolumePassword_au8[0] = 0;
ui->comboBox->setCurrentIndex(HV_Setup_st.SlotNr_u8);
ui->StartBlockSpin->setMaximum(89);
ui->StartBlockSpin->setMinimum(10);
ui->StartBlockSpin->setValue(HV_Setup_st.StartBlockPercent_u8);
ui->EndBlockSpin->setMaximum(90);
ui->EndBlockSpin->setMinimum(11);
ui->EndBlockSpin->setValue(HV_Setup_st.EndBlockPercent_u8);
ui->HVPasswordEdit->setMaxLength(MAX_HIDDEN_VOLUME_PASSOWORD_SIZE);
ui->HVPasswordEdit->setText(QString((char*)HV_Setup_st.HiddenVolumePassword_au8));
ui->HVPasswordEdit_2->setMaxLength(MAX_HIDDEN_VOLUME_PASSOWORD_SIZE);
ui->HVPasswordEdit_2->setText(QString((char*)HV_Setup_st.HiddenVolumePassword_au8));
ui->HVPasswordEdit->setFocus();
on_HVPasswordEdit_textChanged ("");
}
stick20HiddenVolumeDialog::~stick20HiddenVolumeDialog()
{
delete ui;
}
void stick20HiddenVolumeDialog::on_ShowPasswordCheckBox_toggled(bool checked)
{
if (checked)
{
ui->HVPasswordEdit_2->setEchoMode(QLineEdit::Normal);
ui->HVPasswordEdit->setEchoMode(QLineEdit::Normal);
}
else
{
ui->HVPasswordEdit_2->setEchoMode(QLineEdit::Password);
ui->HVPasswordEdit->setEchoMode(QLineEdit::Password);
}
}
void stick20HiddenVolumeDialog::on_buttonBox_clicked(QAbstractButton *button)
{
if(button == ui->buttonBox->button(QDialogButtonBox::Ok))
{
if (8 > strlen (ui->HVPasswordEdit->text().toLatin1().data()))
{
QMessageBox msgBox;
msgBox.setText("Your password is too short. Use at least 8 characters.");
msgBox.exec();
return;
}
if (ui->HVPasswordEdit->text().toLatin1() != ui->HVPasswordEdit_2->text().toLatin1())
{
QMessageBox msgBox;
msgBox.setText("The passwords are not identical");
msgBox.exec();
return;
}
HV_Setup_st.SlotNr_u8 = ui->comboBox->currentIndex();
HV_Setup_st.StartBlockPercent_u8 = ui->StartBlockSpin->value();
HV_Setup_st.EndBlockPercent_u8 = ui->EndBlockSpin->value();
if (HV_Setup_st.StartBlockPercent_u8 >= HV_Setup_st.EndBlockPercent_u8)
{
QMessageBox msgBox;
msgBox.setText("Wrong size of hidden volume");
msgBox.exec();
return;
}
strncpy ((char*)HV_Setup_st.HiddenVolumePassword_au8,ui->HVPasswordEdit->text().toLatin1(),MAX_HIDDEN_VOLUME_PASSOWORD_SIZE);
HV_Setup_st.HiddenVolumePassword_au8[MAX_HIDDEN_VOLUME_PASSOWORD_SIZE] = 0;
done (true);
}
if(button == ui->buttonBox->button(QDialogButtonBox::Cancel))
{
done (false);
}
}
// Based from http://www.emoticode.net/c/optimized-c-version-of-the-shannon-entropy-algorithm.html */
int stick20HiddenVolumeDialog::GetCharsetSpace (unsigned char *Password, size_t size)
{
int i;
int HasLowerAlpha;
int HasUpperAlpha;
int HasGermanChars;
int HasNumber;
int HasSpecialChars1;
int HasSpecialChars2;
int HasSpecialChars3;
int CharSpace;
HasLowerAlpha = FALSE;
HasUpperAlpha = FALSE;
HasGermanChars = FALSE;
HasNumber = FALSE;
HasSpecialChars1 = FALSE;
HasSpecialChars2 = FALSE;
HasSpecialChars3 = FALSE;
CharSpace = 0;
for (i=0;i<size;i++)
{
if ((FALSE == HasLowerAlpha) && (0 != strchr ("abcdefghijklmnopqrstuvwxyz",Password[i])))
{
CharSpace += 26;
HasLowerAlpha = TRUE;
}
if ((FALSE == HasUpperAlpha) && (0 != strchr ("ABCDEFGHIJKLMNOPQRSTUVWXYZ",Password[i])))
{
CharSpace += 26;
HasUpperAlpha = TRUE;
}
if ((FALSE == HasGermanChars) && (0 != strchr ("öäüÖÄÜß",Password[i])))
{
CharSpace += 7;
HasGermanChars = TRUE;
}
if ((FALSE == HasNumber) && (0 != strchr ("0123456789",Password[i])))
{
CharSpace += 10;
HasNumber = TRUE;
}
if ((FALSE == HasSpecialChars1) && (0 != strchr ("!\"§$%&/()=?'",Password[i])))
{
CharSpace += 11;
HasSpecialChars1 = TRUE;
}
if ((FALSE == HasSpecialChars2) && (0 != strchr ("',.-#+´;:_*<>^°`",Password[i])))
{
CharSpace += 16;
HasSpecialChars2 = TRUE;
}
if ((FALSE == HasSpecialChars3) && (0 != strchr ("~[{]}\\|€@",Password[i])))
{
CharSpace += 9;
HasSpecialChars3 = TRUE;
}
}
return (CharSpace);
}
double stick20HiddenVolumeDialog::GetEntropy(unsigned char *Password, size_t size)
{
double Entropy = 0.0;
int CharsetSpace;
CharsetSpace = GetCharsetSpace (Password,size);
Entropy = (double)size * (log((double)CharsetSpace)/log(2.0)); // Entropy by CharsetSpace * size
return (Entropy);
}
void stick20HiddenVolumeDialog::on_HVPasswordEdit_textChanged(const QString &arg1)
{
int Len;
double Entropy;
Len = arg1.length();
Entropy = GetEntropy((unsigned char*)arg1.toLatin1().data(),Len);
if (0 < Entropy)
{
ui->HVEntropieLabel->setText(QString ("%1").sprintf("Entropy guess: %3.1lf bits for random chars\nEntropy guess: %3.1lf for real words",Entropy,Entropy/2.0));
}
else
{
ui->HVEntropieLabel->setText(QString ("%1").sprintf("Entropy guess: %3.1lf bits for random chars\nEntropy guess: %3.1lf for real words",0.0,0.0));
}
}
void stick20HiddenVolumeDialog::setHighWaterMarkText (void)
{
uint8_t HighWatermarkMin;
uint8_t HighWatermarkMax;
HighWatermarkMin = SdCardHighWatermark_Write_Min;
HighWatermarkMax = SdCardHighWatermark_Write_Max;
if (5 > HighWatermarkMin) // Set lower limit
{
HighWatermarkMin = 10;
}
if (90 < HighWatermarkMax) // Set higher limit
{
HighWatermarkMax = 90;
}
ui->HVSdCardHighWaterMark->setText(QString ("%1").sprintf("The the unwritten area after plugin is\nbetween %d %% and %d %% of the sd card size",HighWatermarkMin,HighWatermarkMax));
// Set valid input range
ui->StartBlockSpin->setMaximum(HighWatermarkMax-1);
ui->StartBlockSpin->setMinimum(HighWatermarkMin);
ui->StartBlockSpin->setValue(HV_Setup_st.StartBlockPercent_u8);
ui->EndBlockSpin->setMaximum(HighWatermarkMax);
ui->EndBlockSpin->setMinimum(HighWatermarkMin+1);
ui->EndBlockSpin->setValue(HV_Setup_st.EndBlockPercent_u8);
}