Package org.bouncycastle.crypto.params
Class Argon2Parameters.Builder
java.lang.Object
org.bouncycastle.crypto.params.Argon2Parameters.Builder
- Enclosing class:
Argon2Parameters
Fluent builder for
Argon2Parameters.-
Constructor Summary
ConstructorsConstructorDescriptionBuilder()Create a builder defaulting toArgon2Parameters.ARGON2_i.Builder(int type) Create a builder for the given Argon2 variant. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Construct an immutableArgon2Parametersfrom the current builder state.voidclear()Zeroise sensitive state (salt, secret, additional) held by this builder.withAdditional(byte[] additional) Set the optional additional/associated data.withBlockPool(Argon2BytesGenerator.BlockPool blockPool) Provide a customArgon2BytesGenerator.BlockPoolfor the generator to source its working blocks from.withCharToByteConverter(CharToByteConverter converter) Override the converter used to turnchar[]passwords into bytes.withIterations(int iterations) Set the number of passes (time cost).withMemoryAsKB(int memory) Set the memory cost expressed directly in KiB.withMemoryPowOfTwo(int memory) Set the memory cost as a power of two: the resulting memory in KiB is1 << memory.withParallelism(int parallelism) Set the parallelism (number of lanes).withSalt(byte[] salt) Set the salt.withSecret(byte[] secret) Set the optional secret (key) value.withVersion(int version) Set the Argon2 version.
-
Constructor Details
-
Builder
public Builder()Create a builder defaulting toArgon2Parameters.ARGON2_i. -
Builder
public Builder(int type) Create a builder for the given Argon2 variant.- Parameters:
type- one ofArgon2Parameters.ARGON2_d,Argon2Parameters.ARGON2_i, orArgon2Parameters.ARGON2_id.
-
-
Method Details
-
withParallelism
Set the parallelism (number of lanes).- Parameters:
parallelism- the degree of parallelism, must be at least 1.- Returns:
- this builder.
-
withSalt
Set the salt. The supplied array is defensively cloned.- Parameters:
salt- salt bytes; may be null.- Returns:
- this builder.
-
withSecret
Set the optional secret (key) value. The supplied array is defensively cloned.- Parameters:
secret- secret bytes; may be null.- Returns:
- this builder.
-
withAdditional
Set the optional additional/associated data. The supplied array is defensively cloned.- Parameters:
additional- additional data bytes; may be null.- Returns:
- this builder.
-
withIterations
Set the number of passes (time cost).- Parameters:
iterations- number of iterations, must be at least 1.- Returns:
- this builder.
-
withMemoryAsKB
Set the memory cost expressed directly in KiB.- Parameters:
memory- memory in KiB; must be in[1, 1 << MAX_MEMORY_EXP].- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the value is out of range.
-
withMemoryPowOfTwo
Set the memory cost as a power of two: the resulting memory in KiB is1 << memory.- Parameters:
memory- exponent; must be in[0, MAX_MEMORY_EXP].- Returns:
- this builder.
- Throws:
IllegalArgumentException- if the exponent is out of range.
-
withVersion
Set the Argon2 version.- Parameters:
version- one ofArgon2Parameters.ARGON2_VERSION_10orArgon2Parameters.ARGON2_VERSION_13.- Returns:
- this builder.
-
withCharToByteConverter
Override the converter used to turnchar[]passwords into bytes. Default isPasswordConverter.UTF8.- Parameters:
converter- the character-to-byte converter to use.- Returns:
- this builder.
-
withBlockPool
Provide a customArgon2BytesGenerator.BlockPoolfor the generator to source its working blocks from. Useful in high-throughput scenarios where the cost of allocating freshlong[]buffers per call dominates. If null (the default) the generator creates a per-call FixedBlockPool. -
build
Construct an immutableArgon2Parametersfrom the current builder state.- Returns:
- the configured parameters.
-
clear
public void clear()Zeroise sensitive state (salt, secret, additional) held by this builder.
-