Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
7a573754
Commit
7a573754
authored
11 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Interleave samples to get a better estimate of PBKDF2 running time.
parent
a9c46e6e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
briar-core/src/net/sf/briar/crypto/CryptoComponentImpl.java
+10
-8
10 additions, 8 deletions
briar-core/src/net/sf/briar/crypto/CryptoComponentImpl.java
with
10 additions
and
8 deletions
briar-core/src/net/sf/briar/crypto/CryptoComponentImpl.java
+
10
−
8
View file @
7a573754
...
...
@@ -61,6 +61,7 @@ class CryptoComponentImpl implements CryptoComponent {
private
static
final
int
STORAGE_IV_BYTES
=
16
;
// 128 bits
private
static
final
int
PBKDF_SALT_BYTES
=
16
;
// 128 bits
private
static
final
int
PBKDF_TARGET_MILLIS
=
500
;
private
static
final
int
PBKDF_SAMPLES
=
30
;
// Labels for secret derivation
private
static
final
byte
[]
MASTER
=
{
'M'
,
'A'
,
'S'
,
'T'
,
'E'
,
'R'
,
'\0'
};
...
...
@@ -463,18 +464,19 @@ class CryptoComponentImpl implements CryptoComponent {
// Package access for testing
int
chooseIterationCount
(
int
targetMillis
)
{
List
<
Long
>
quickSamples
=
new
ArrayList
<
Long
>();
List
<
Long
>
slowSamples
=
new
ArrayList
<
Long
>();
List
<
Long
>
quickSamples
=
new
ArrayList
<
Long
>(
PBKDF_SAMPLES
);
List
<
Long
>
slowSamples
=
new
ArrayList
<
Long
>(
PBKDF_SAMPLES
);
long
iterationNanos
=
0
,
initNanos
=
0
;
while
(
iterationNanos
<=
0
||
initNanos
<=
0
)
{
// Take ten samples of the running time with one iteration
for
(
int
i
=
0
;
i
<
10
;
i
++)
quickSamples
.
add
(
sampleRunningTime
(
1
));
// Take ten samples of the running time with eleven iterations
for
(
int
i
=
0
;
i
<
10
;
i
++)
slowSamples
.
add
(
sampleRunningTime
(
11
));
// Sample the running time with one iteration and two iterations
for
(
int
i
=
0
;
i
<
PBKDF_SAMPLES
;
i
++)
{
quickSamples
.
add
(
sampleRunningTime
(
1
));
slowSamples
.
add
(
sampleRunningTime
(
2
));
}
// Calculate the iteration time and the initialisation time
long
quickMedian
=
median
(
quickSamples
);
long
slowMedian
=
median
(
slowSamples
);
iterationNanos
=
(
slowMedian
-
quickMedian
)
/
10
;
iterationNanos
=
slowMedian
-
quickMedian
;
initNanos
=
quickMedian
-
iterationNanos
;
if
(
LOG
.
isLoggable
(
INFO
))
{
LOG
.
info
(
"Init: "
+
initNanos
+
", iteration: "
...
...
@@ -483,7 +485,7 @@ class CryptoComponentImpl implements CryptoComponent {
}
long
targetNanos
=
targetMillis
*
1000L
*
1000L
;
long
iterations
=
(
targetNanos
-
initNanos
)
/
iterationNanos
;
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
"
Raw
iterations: "
+
iterations
);
if
(
LOG
.
isLoggable
(
INFO
))
LOG
.
info
(
"
Target
iterations: "
+
iterations
);
if
(
iterations
<
1
)
return
1
;
if
(
iterations
>
Integer
.
MAX_VALUE
)
return
Integer
.
MAX_VALUE
;
return
(
int
)
iterations
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment