Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a8bbfc2
Gradle
minebreaker Feb 15, 2019
1e912f2
Removed Factory
minebreaker Feb 16, 2019
3cf847f
wip
minebreaker Feb 16, 2019
1a3f0fd
added tests
minebreaker Feb 17, 2019
c5e7ae5
encode
minebreaker Feb 17, 2019
fc42a47
encode
minebreaker Feb 17, 2019
5f8cbad
removed guava
minebreaker Feb 17, 2019
5dd25f5
fixed typo
minebreaker Feb 17, 2019
77a39cd
Added test to compare Argon2 implementation with the reference
dbusche Apr 26, 2019
79ceb6b
Fixed class comment.
dbusche Apr 26, 2019
b9024f0
Added main method to invoke benchmark.
haumacher Apr 27, 2019
8239147
Added memory allocation benchmark.
haumacher Apr 27, 2019
8ce3656
Simplified int to long conversion.
haumacher Apr 27, 2019
c65a3b8
Reduced excessive memory allocation in Block to byte conversion.
haumacher Apr 27, 2019
67830f9
Refactoring: Extracted flushing from update.
haumacher Apr 27, 2019
eb6100c
Reduced excessive memory allocation in hash initialization.
haumacher Apr 27, 2019
822a5dc
Reduced excessive memory allocation in length encoding.
haumacher Apr 27, 2019
db13e2f
Reduced excessive memory allocation in block initialization.
haumacher Apr 27, 2019
0cf51e8
Reduced excessive memory allocation in Block to byte conversion.
haumacher Apr 27, 2019
f2d8b33
Reduced excessive temporary block allocation.
haumacher Apr 27, 2019
a784a48
Moved computations on a single block to Block class.
haumacher Apr 27, 2019
6935f81
Removed ugly multiplications.
haumacher Apr 27, 2019
c53fa7c
Updated documentation.
haumacher Apr 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ aws.properties

.vagrant/
Vagrantfile

.gradle/
build/
68 changes: 30 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Argon2 Java implementation

This is a pure Java implementation of [Argon2](https://github.com/P-H-C/phc-winner-argon2). It targets Java 6.
This is a pure Java implementation of [Argon2](https://github.com/P-H-C/phc-winner-argon2). It targets Java 8.

Many parts are just taken from the C code and converted to Java syntax - there shouldn't be any major performance bottlenecks anymore, but speed can't keep up quite with the C implementation.
Many parts are just taken from the C code and converted to Java syntax. Runtime overhead compared to the C implementation is within 20 percent.

Fair warning: this code is not well tested and not reviewed. It is not ready for production, use it on your own risk. Same applies for underlying Blake2b implementation.
Fair warning: This code is neither excessively tested nor reviewed. Use it at your own risk. Same applies to the underlying Blake2b cryptographic hash implementation.

## Benchmarks
[Rplots.pdf](benchmarks/Rplots.pdf)
Old benchmark before memory optimization of the Java implementation: [Rplots.pdf](benchmarks/Rplots.pdf)

Red is java, green the reference implementation and blue the optimized implementation with SSE-instructions - run on a i7-7700HQ with 16GB RAM.

Expand All @@ -33,67 +33,59 @@ Clone and install it:
</dependency>
```

<!---
## Gradle

```groovy
compile 'at.gadermaier:argon2:1.0-SNAPSHOT'
```
-->
## Usage

## Usage

```
// Read password
### Create encoded hash when a user is setting it's password
```java
char[] password = readPassword();

// Generate salt
String salt = generateRandomSalt();

// Hash password - Builder pattern
String hash = Argon2Factory.create()
.setIterations(2)
.setMemory(14)
.setParallelism(1)
.hash(password, salt);

```
String encodedHash = Argon2Factory.create()
.setIterations(2)
.setMemory(14)
.setParallelism(1)
.hash(password, salt).
.asEncoded();

storeToDataBase(encodedHash);
```
% java -jar argon2-0.1.jar
usage: argon2 salt [-d | -i | -id] [-e | -r] [-h] [-k <N> | -m <N>] [-l
<N>] [-p <N>] [-t <N>]
-d Use Argon2d instead of Argon2i
-e Output only encoded hash
-h Print usage
-i Use Argon2i (this is the default)
-id Use Argon2id instead of Argon2i
-k <N> Sets the memory usage of N KiB (default 2^12)
-l <N> Sets hash output length to N bytes (default 32)
-m <N> Sets the memory usage of 2^N KiB (default 12)
-p <N> Sets parallelism to N (default 1)
-r Output only the raw bytes of the hash
-t <N> Sets the number of iterations to N (default = 3)
Password is read from stdin

### Verify that a user entered a correct password
```java
String password = readFromUser();
String encodedHash = readFromDatabase();

boolean match = Argon2().checkHash(encodedHash, password);
if (match) {
loginUser();
} else {
printInvalidUsernameOrPassword();
}
```

## Blake2b
The [blake2b Java implementation](https://github.com/alphazero/Blake2b) of [@alphazero](https://github.com/alphazero/) is used. Because no artifact is available on maven central, I copied the relevant class file into this project - for the sake of simplicity.
The [blake2b Java implementation](https://github.com/alphazero/Blake2b) from [@alphazero](https://github.com/alphazero/) is used. Because no artifact is available on Maven Central the relevant class file is embedded in this project.

## License
[MIT](https://opensource.org/licenses/MIT)

## TODO
* Verification
* Encoded result
* Performance
* Can we get closer to the C implementation?
* in Block.xorBlock(), the JIT actually already creates vector operations
* Fix the build
* Build library without commons-dependency, build executable with
* maven central
* add gradle support
* Add Tests
* ..

* Add more Tests

## Contact
[@andreas1327250](https://github.com/andreas1327250)
Expand Down
44 changes: 44 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id 'java'
}

group 'rip.deadcode.argon2'
version '0.1-SNAPSHOT'

repositories {
mavenCentral()
maven {
url = "https://dl.bintray.com/minebreaker/test"
}
}

dependencies {
testCompile(
'org.junit.jupiter:junit-jupiter-api:5.3.2',
'de.mkammerer:argon2-jvm:2.5',
'com.google.truth:truth:0.42',
// 'com.google.truth.extensions:truth-java8-extension:0.42',
// 'org.mockito:mockito-core:2.23.4',
// 'rip.deadcode:izvestia:0.2',
// 'com.google.jimfs:jimfs:1.1'
)
testRuntime(
'org.junit.jupiter:junit-jupiter-engine:5.3.2',
'de.mkammerer:argon2-jvm:2.5'
)
}

test {
useJUnitPlatform()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

compileJava {
options.encoding = 'UTF-8'
}

compileTestJava {
options.encoding = 'UTF-8'
}
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
172 changes: 172 additions & 0 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading