This commit is contained in:
2024-09-12 00:14:30 +02:00
parent 5f40b948ff
commit 524e9026b8
2 changed files with 15 additions and 5 deletions
+8 -4
View File
@@ -89,7 +89,11 @@ export async function hkdf(key: Uint8Array, usage: Usage, context?: string): Pro
}
/** Minimum salt size : 16 bytes */
export async function pbkdf(salt: Uint8Array, password: string, strength: Strength = Strength.moderate): Promise<Uint8Array | null> {
export async function pbkdf(
salt: Uint8Array,
password: string,
strength: Strength = Strength.moderate
): Promise<Uint8Array | null> {
log.trace('PBKDF')
if (salt.length < 16) {
@@ -106,13 +110,13 @@ export async function pbkdf(salt: Uint8Array, password: string, strength: Streng
switch (strength) {
case Strength.weak:
iterations = 100_000
break;
break
case Strength.moderate:
iterations = 250_000
break;
break
case Strength.strong:
iterations = 500_000
break;
break
default:
log.warn('Invalid strength used !')
return null
+7 -1
View File
@@ -1,7 +1,13 @@
import {describe, expect, test} from 'bun:test'
import {kdf, PrivateWrap, SecretBox, SecretWrap} from '..'
async function test_keys(k1: CryptoKey, k2: CryptoKey, usage: kdf.Usage | kdf.DHusage, should_box: boolean, should_unbox: boolean) {
async function test_keys(
k1: CryptoKey,
k2: CryptoKey,
usage: kdf.Usage | kdf.DHusage,
should_box: boolean,
should_unbox: boolean
) {
if (usage === kdf.Usage.wrap || usage == kdf.DHusage.wrap) {
const payload = await SecretBox.gen(true)