-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from serenity-kit/maximkott-feat/reintroduce-c…
…rypto-pwhash feat: reintroduce crypto_pwhash
- Loading branch information
Showing
10 changed files
with
795 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { | ||
crypto_pwhash, | ||
crypto_pwhash_ALG_DEFAULT, | ||
crypto_pwhash_BYTES_MIN, | ||
crypto_pwhash_MEMLIMIT_INTERACTIVE, | ||
crypto_pwhash_OPSLIMIT_INTERACTIVE, | ||
crypto_pwhash_SALTBYTES, | ||
randombytes_buf, | ||
} from 'react-native-libsodium'; | ||
import { isEqualUint8Array } from '../utils/isEqualUint8Array'; | ||
import { expect, test } from '../utils/testRunner'; | ||
|
||
test('crypto_pwhash', () => { | ||
const password = 'password123'; | ||
const salt = new Uint8Array([ | ||
149, 177, 121, 247, 17, 38, 67, 49, 150, 68, 118, 228, 16, 98, 110, 175, | ||
]); | ||
const randomSalt = randombytes_buf(crypto_pwhash_SALTBYTES); | ||
|
||
expect(() => | ||
crypto_pwhash( | ||
crypto_pwhash_BYTES_MIN, | ||
password, | ||
salt, | ||
crypto_pwhash_OPSLIMIT_INTERACTIVE, | ||
crypto_pwhash_MEMLIMIT_INTERACTIVE, | ||
200 | ||
) | ||
).toThrow(); | ||
|
||
expect(() => | ||
crypto_pwhash( | ||
15, | ||
password, | ||
salt, | ||
crypto_pwhash_OPSLIMIT_INTERACTIVE, | ||
crypto_pwhash_MEMLIMIT_INTERACTIVE, | ||
crypto_pwhash_ALG_DEFAULT | ||
) | ||
).toThrow(); | ||
|
||
expect(() => | ||
crypto_pwhash( | ||
crypto_pwhash_BYTES_MIN, | ||
password, | ||
new Uint8Array([10]), | ||
crypto_pwhash_OPSLIMIT_INTERACTIVE, | ||
crypto_pwhash_MEMLIMIT_INTERACTIVE, | ||
crypto_pwhash_ALG_DEFAULT | ||
) | ||
).toThrow(); | ||
|
||
expect( | ||
isEqualUint8Array( | ||
crypto_pwhash( | ||
crypto_pwhash_BYTES_MIN, | ||
password, | ||
salt, | ||
crypto_pwhash_OPSLIMIT_INTERACTIVE, | ||
crypto_pwhash_MEMLIMIT_INTERACTIVE, | ||
crypto_pwhash_ALG_DEFAULT | ||
), | ||
new Uint8Array([ | ||
75, 92, 252, 55, 217, 21, 210, 156, 216, 33, 97, 101, 153, 119, 14, 177, | ||
]) | ||
) | ||
).toBe(true); | ||
|
||
expect( | ||
isEqualUint8Array( | ||
crypto_pwhash( | ||
crypto_pwhash_BYTES_MIN, | ||
new Uint8Array([100, 100, 100]), | ||
salt, | ||
crypto_pwhash_OPSLIMIT_INTERACTIVE, | ||
crypto_pwhash_MEMLIMIT_INTERACTIVE, | ||
crypto_pwhash_ALG_DEFAULT | ||
), | ||
new Uint8Array([ | ||
136, 232, 104, 134, 32, 193, 138, 249, 192, 236, 243, 239, 248, 70, 117, | ||
160, | ||
]) | ||
) | ||
).toBe(true); | ||
|
||
expect( | ||
isEqualUint8Array( | ||
crypto_pwhash( | ||
crypto_pwhash_BYTES_MIN, | ||
password, | ||
randomSalt, | ||
crypto_pwhash_OPSLIMIT_INTERACTIVE, | ||
crypto_pwhash_MEMLIMIT_INTERACTIVE, | ||
crypto_pwhash_ALG_DEFAULT | ||
), | ||
crypto_pwhash( | ||
crypto_pwhash_BYTES_MIN, | ||
password, | ||
randomSalt, | ||
crypto_pwhash_OPSLIMIT_INTERACTIVE, | ||
crypto_pwhash_MEMLIMIT_INTERACTIVE, | ||
crypto_pwhash_ALG_DEFAULT | ||
) | ||
) | ||
).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.