Skip to content

Commit 72a0b2f

Browse files
committed
v3 update, update core and refactor naming accordingly
1 parent a78b6e4 commit 72a0b2f

File tree

8 files changed

+85
-77
lines changed

8 files changed

+85
-77
lines changed

.idea/codeStyles/Project.xml

-22
This file was deleted.

.idea/discord.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Dart_Packages.xml

+14-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.0
2+
- BREAKING: `sync` methods are no longer supported to allow web integration
3+
- Migrated to the `dargon2_interface` under the core
4+
15
## 2.1.0
26
- Migrated to use a shared dargon2_core plugin
37
- More modular and allows for custom Library Loader definitions

lib/src/argon2.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ import 'package:dargon2_core/dargon2_core.dart';
88

99
/// The globally accessible instance of [DArgon2] with Dart
1010
/// native library loading
11-
final argon2 = DArgon2(DartLibLoader());
11+
final argon2 = DArgon2Native(DartLibLoader());

pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: dargon2
22
description: Provides bindings for hashing and verifying with Argon2, the winner of the Password Hashing Competition.
3-
version: 2.1.0
3+
version: 3.0.0
44
homepage: https://github.com/tmthecoder/dargon2
55
repository: https://github.com/tmthecoder/dargon2
66

77
environment:
8-
sdk: '>=2.12.0 <3.0.0'
8+
sdk: '>=2.15.0 <3.0.0'
99

1010
dependencies:
11-
dargon2_core: '^1.0.0'
11+
dargon2_core: '^2.0.1'
1212

1313
dev_dependencies:
1414
pedantic: ^1.9.0

test/dargon2_test.dart

+46-45
Original file line numberDiff line numberDiff line change
@@ -12,80 +12,80 @@ import 'package:test/test.dart';
1212
void main() {
1313
// Argon2i test group
1414
group('Hash Tests - Argon2i', () {
15-
test('v = ${0x13}, t = 2, m = 16, p = 1,', () {
16-
var code = hashTest(Argon2Version.V13, 2, 16, 1, 'password', 'somesalt',
15+
test('v = ${0x13}, t = 2, m = 16, p = 1,', () async {
16+
var code = await hashTest(Argon2Version.V13, 2, 16, 1, 'password', 'somesalt',
1717
'03df1d13e10203bcc663405e31ab1687939730c9152459bca28fd10c23e38f50',
1818
'\$argon2i\$v=19\$m=16,t=2,p=1\$c29tZXNhbHQ\$A98dE+ECA7zGY0BeMasWh5OXMMkVJFm8oo/RDCPjj1A', Argon2Type.i);
1919
expect(code, DArgon2ErrorCode.ARGON2_OK);
2020
});
21-
test('v = ${0x13}, t = 2, m = 18, p = 1,', () {
22-
var code = hashTest(Argon2Version.V13, 2, 18, 1, 'password', 'somesalt',
21+
test('v = ${0x13}, t = 2, m = 18, p = 1,', () async {
22+
var code = await hashTest(Argon2Version.V13, 2, 18, 1, 'password', 'somesalt',
2323
'3b1b4ad0a66b3f00b4cd04225e4e6da950ee152bf0d29aabcb123c2f1a90567a',
2424
'\$argon2i\$v=19\$m=18,t=2,p=1\$c29tZXNhbHQ\$OxtK0KZrPwC0zQQiXk5tqVDuFSvw0pqryxI8LxqQVno', Argon2Type.i);
2525
expect(code, DArgon2ErrorCode.ARGON2_OK);
2626
});
27-
test('v = ${0x13}, t = 2, m = 8, p = 1,', () {
28-
var code = hashTest(Argon2Version.V13, 2, 8, 1, 'password', 'somesalt',
27+
test('v = ${0x13}, t = 2, m = 8, p = 1,', () async {
28+
var code = await hashTest(Argon2Version.V13, 2, 8, 1, 'password', 'somesalt',
2929
'48cc13c16c5a2d254a278e2c44420ba0fb2d0f070661e35d6486604a7a2ff1a9',
3030
'\$argon2i\$v=19\$m=8,t=2,p=1\$c29tZXNhbHQ\$SMwTwWxaLSVKJ44sREILoPstDwcGYeNdZIZgSnov8ak', Argon2Type.i);
3131
expect(code, DArgon2ErrorCode.ARGON2_OK);
3232
});
33-
test('v = ${0x13}, t = 2, m = 16, p = 2,', () {
34-
var code = hashTest(Argon2Version.V13, 2, 16, 2, 'password', 'somesalt',
33+
test('v = ${0x13}, t = 2, m = 16, p = 2,', () async {
34+
var code = await hashTest(Argon2Version.V13, 2, 16, 2, 'password', 'somesalt',
3535
'7fbb85db7e9636115f2fd0f29ea4214baaada18b39fffed7875eeb9fa9b308c5',
3636
'\$argon2i\$v=19\$m=16,t=2,p=2\$c29tZXNhbHQ\$f7uF236WNhFfL9DynqQhS6qtoYs5//7Xh17rn6mzCMU', Argon2Type.i);
3737
expect(code, DArgon2ErrorCode.ARGON2_OK);
3838
});
3939
});
4040
// Argon2d test group
4141
group('Hash Tests - Argon2d', () {
42-
test('v = ${0x13}, t = 2, m = 16, p = 1,', () {
43-
var code = hashTest(Argon2Version.V13, 2, 16, 1, 'password', 'somesalt',
42+
test('v = ${0x13}, t = 2, m = 16, p = 1,', () async {
43+
var code = await hashTest(Argon2Version.V13, 2, 16, 1, 'password', 'somesalt',
4444
'e742c05880c44c4df5fe79937be77897a6e41ca758affc42301f1e4040e35bd2',
4545
'\$argon2d\$v=19\$m=16,t=2,p=1\$c29tZXNhbHQ\$50LAWIDETE31/nmTe+d4l6bkHKdYr/xCMB8eQEDjW9I', Argon2Type.d);
4646
expect(code, DArgon2ErrorCode.ARGON2_OK);
4747
});
48-
test('v = ${0x13}, t = 2, m = 18, p = 1,', () {
49-
var code = hashTest(Argon2Version.V13, 2, 18, 1, 'password', 'somesalt',
48+
test('v = ${0x13}, t = 2, m = 18, p = 1,', () async {
49+
var code = await hashTest(Argon2Version.V13, 2, 18, 1, 'password', 'somesalt',
5050
'd24d7d614122db6458d66b4f35dc45b1cca59f9b71945db207e78062601d2dd5',
5151
'\$argon2d\$v=19\$m=18,t=2,p=1\$c29tZXNhbHQ\$0k19YUEi22RY1mtPNdxFscyln5txlF2yB+eAYmAdLdU', Argon2Type.d);
5252
expect(code, DArgon2ErrorCode.ARGON2_OK);
5353
});
54-
test('v = ${0x13}, t = 2, m = 8, p = 1,', () {
55-
var code = hashTest(Argon2Version.V13, 2, 8, 1, 'password', 'somesalt',
54+
test('v = ${0x13}, t = 2, m = 8, p = 1,', () async {
55+
var code = await hashTest(Argon2Version.V13, 2, 8, 1, 'password', 'somesalt',
5656
'7d124315b3ba588668393b2e2d6867bd9f211a4eebd240d0023e540a783a69f0',
5757
'\$argon2d\$v=19\$m=8,t=2,p=1\$c29tZXNhbHQ\$fRJDFbO6WIZoOTsuLWhnvZ8hGk7r0kDQAj5UCng6afA', Argon2Type.d);
5858
expect(code, DArgon2ErrorCode.ARGON2_OK);
5959
});
60-
test('v = ${0x13}, t = 2, m = 16, p = 2,', () {
61-
var code = hashTest(Argon2Version.V13, 2, 16, 2, 'password', 'somesalt',
60+
test('v = ${0x13}, t = 2, m = 16, p = 2,', () async {
61+
var code = await hashTest(Argon2Version.V13, 2, 16, 2, 'password', 'somesalt',
6262
'59f20a66a4c31bf0438a2f494867c32120409a91380f0687aefee984ba86bda8',
6363
'\$argon2d\$v=19\$m=16,t=2,p=2\$c29tZXNhbHQ\$WfIKZqTDG/BDii9JSGfDISBAmpE4DwaHrv7phLqGvag', Argon2Type.d);
6464
expect(code, DArgon2ErrorCode.ARGON2_OK);
6565
});
6666
});
6767
// Argon2id test group
6868
group('Hash Tests - Argon2id', () {
69-
test('v = ${0x13}, t = 2, m = 16, p = 1,', () {
70-
var code = hashTest(Argon2Version.V13, 2, 16, 1, 'password', 'somesalt',
69+
test('v = ${0x13}, t = 2, m = 16, p = 1,', () async {
70+
var code = await hashTest(Argon2Version.V13, 2, 16, 1, 'password', 'somesalt',
7171
'058202c0723cd88c24408ccac1cbf828dee63bcf3843a150ea364a1e0b4e1ff8',
7272
'\$argon2id\$v=19\$m=16,t=2,p=1\$c29tZXNhbHQ\$BYICwHI82IwkQIzKwcv4KN7mO884Q6FQ6jZKHgtOH/g', Argon2Type.id);
7373
expect(code, DArgon2ErrorCode.ARGON2_OK);
7474
});
75-
test('v = ${0x13}, t = 2, m = 18, p = 1,', () {
76-
var code = hashTest(Argon2Version.V13, 2, 18, 1, 'password', 'somesalt',
75+
test('v = ${0x13}, t = 2, m = 18, p = 1,', () async {
76+
var code = await hashTest(Argon2Version.V13, 2, 18, 1, 'password', 'somesalt',
7777
'0e6408c954c4980f6313756ea01ee7ddebb362efbb20d49d08a6859787024e3f',
7878
'\$argon2id\$v=19\$m=18,t=2,p=1\$c29tZXNhbHQ\$DmQIyVTEmA9jE3VuoB7n3euzYu+7INSdCKaFl4cCTj8', Argon2Type.id);
7979
expect(code, DArgon2ErrorCode.ARGON2_OK);
8080
});
81-
test('v = ${0x13}, t = 2, m = 8, p = 1,', () {
82-
var code = hashTest(Argon2Version.V13, 2, 8, 1, 'password', 'somesalt',
81+
test('v = ${0x13}, t = 2, m = 8, p = 1,', () async {
82+
var code = await hashTest(Argon2Version.V13, 2, 8, 1, 'password', 'somesalt',
8383
'fdb4ddb6d5887131b66f0b2a3740c077dd05b755845861f6b5a1dde8b1071646',
8484
'\$argon2id\$v=19\$m=8,t=2,p=1\$c29tZXNhbHQ\$/bTdttWIcTG2bwsqN0DAd90Ft1WEWGH2taHd6LEHFkY', Argon2Type.id);
8585
expect(code, DArgon2ErrorCode.ARGON2_OK);
8686
});
87-
test('v = ${0x13}, t = 2, m = 16, p = 2,', () {
88-
var code = hashTest(Argon2Version.V13, 2, 16, 2, 'password', 'somesalt',
87+
test('v = ${0x13}, t = 2, m = 16, p = 2,', () async {
88+
var code = await hashTest(Argon2Version.V13, 2, 16, 2, 'password', 'somesalt',
8989
'747d7631b182faf749d7efc31aec31df4ecfe3b57c792f53800ac2c9978b4888',
9090
'\$argon2id\$v=19\$m=16,t=2,p=2\$c29tZXNhbHQ\$dH12MbGC+vdJ1+/DGuwx307P47V8eS9TgArCyZeLSIg', Argon2Type.id);
9191
expect(code, DArgon2ErrorCode.ARGON2_OK);
@@ -94,42 +94,43 @@ void main() {
9494
}
9595

9696
//Testing method to check the argon2 tester hashes
97-
DArgon2ErrorCode hashTest(Argon2Version version, int iterations, int memory, int parallelism, String password, String salt, String hexHash, String encodedHash, Argon2Type type) {
97+
Future<DArgon2ErrorCode> hashTest(Argon2Version version, int iterations, int memory, int parallelism, String password, String salt, String hexHash, String encodedHash, Argon2Type type) async {
9898
var s = Salt(utf8.encode(salt));
9999
DArgon2Result resultString;
100100
DArgon2Result resultBytes;
101101
// get hashed results
102102
try {
103-
resultString = argon2.hashPasswordStringSync(password, salt: s,
103+
resultString = await argon2.hashPasswordString(password, salt: s,
104104
iterations: iterations,
105105
memory: memory,
106106
parallelism: parallelism,
107107
version: version,
108108
type: type);
109-
resultBytes = argon2.hashPasswordBytesSync(utf8.encode(password), salt: s,
109+
resultBytes = await argon2.hashPasswordBytes(utf8.encode(password), salt: s,
110110
iterations: iterations,
111111
memory: memory,
112112
parallelism: parallelism,
113113
version: version,
114114
type: type);
115+
// Test both bytes and string for equaluty
116+
if (resultString.encodedString != resultBytes.encodedString) {
117+
return DArgon2ErrorCode.ARGON2_UNKNOWN_ERROR;
118+
}
119+
// Check if both hex strings are equivalent to the one given
120+
if (resultBytes.hexString != hexHash || resultString.hexString != hexHash) {
121+
return DArgon2ErrorCode.ARGON2_UNKNOWN_ERROR;
122+
}
123+
// Check if both are verified
124+
if (!await argon2.verifyHashString(password, encodedHash, type: type) || !await argon2.verifyHashBytes(utf8.encode(password), utf8.encode(encodedHash), type: type)) {
125+
return DArgon2ErrorCode.ARGON2_UNKNOWN_ERROR;
126+
}
127+
// Check if both are verified against each other
128+
if (!await argon2.verifyHashString(password, resultBytes.encodedString, type: type) || !await argon2.verifyHashString(password, resultString.encodedString, type: type)) {
129+
return DArgon2ErrorCode.ARGON2_UNKNOWN_ERROR;
130+
}
131+
return DArgon2ErrorCode.ARGON2_OK;
132+
115133
} on DArgon2Exception catch (e) {
116134
return e.errorCode;
117135
}
118-
// Test both bytes and string for equaluty
119-
if (resultString.encodedString != resultBytes.encodedString) {
120-
return DArgon2ErrorCode.ARGON2_UNKNOWN_ERROR;
121-
}
122-
// Check if both hex strings are equivalent to the one given
123-
if (resultBytes.hexString != hexHash || resultString.hexString != hexHash) {
124-
return DArgon2ErrorCode.ARGON2_UNKNOWN_ERROR;
125-
}
126-
// Check if both are verified
127-
if (!argon2.verifyHashStringSync(password, encodedHash, type: type) || !argon2.verifyHashBytesSync(utf8.encode(password), utf8.encode(encodedHash), type: type)) {
128-
return DArgon2ErrorCode.ARGON2_UNKNOWN_ERROR;
129-
}
130-
// Check if both are verified against each other
131-
if (!argon2.verifyHashStringSync(password, resultBytes.encodedString, type: type) || !argon2.verifyHashStringSync(password, resultString.encodedString, type: type)) {
132-
return DArgon2ErrorCode.ARGON2_UNKNOWN_ERROR;
133-
}
134-
return DArgon2ErrorCode.ARGON2_OK;
135-
}
136+
}

0 commit comments

Comments
 (0)