Package org.bouncycastle.crypto.params
Class Argon2Parameters.Builder
- java.lang.Object
-
- org.bouncycastle.crypto.params.Argon2Parameters.Builder
-
- Enclosing class:
- Argon2Parameters
public static class Argon2Parameters.Builder extends java.lang.ObjectFluent builder forArgon2Parameters.
-
-
Constructor Summary
Constructors Constructor Description Builder()Create a builder defaulting toArgon2Parameters.ARGON2_i.Builder(int type)Create a builder for the given Argon2 variant.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Argon2Parametersbuild()Construct an immutableArgon2Parametersfrom the current builder state.voidclear()Zeroise sensitive state (salt, secret, additional) held by this builder.Argon2Parameters.BuilderwithAdditional(byte[] additional)Set the optional additional/associated data.Argon2Parameters.BuilderwithBlockPool(Argon2BytesGenerator.BlockPool blockPool)Provide a customArgon2BytesGenerator.BlockPoolfor the generator to source its working blocks from.Argon2Parameters.BuilderwithCharToByteConverter(CharToByteConverter converter)Override the converter used to turnchar[]passwords into bytes.Argon2Parameters.BuilderwithIterations(int iterations)Set the number of passes (time cost).Argon2Parameters.BuilderwithMemoryAsKB(int memory)Set the memory cost expressed directly in KiB.Argon2Parameters.BuilderwithMemoryPowOfTwo(int memory)Set the memory cost as a power of two: the resulting memory in KiB is1 << memory.Argon2Parameters.BuilderwithParallelism(int parallelism)Set the parallelism (number of lanes).Argon2Parameters.BuilderwithSalt(byte[] salt)Set the salt.Argon2Parameters.BuilderwithSecret(byte[] secret)Set the optional secret (key) value.Argon2Parameters.BuilderwithVersion(int version)Set the Argon2 version.
-
-
-
Constructor Detail
-
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 Detail
-
withParallelism
public Argon2Parameters.Builder withParallelism(int parallelism)
Set the parallelism (number of lanes).- Parameters:
parallelism- the degree of parallelism, must be at least 1.- Returns:
- this builder.
-
withSalt
public Argon2Parameters.Builder withSalt(byte[] salt)
Set the salt. The supplied array is defensively cloned.- Parameters:
salt- salt bytes; may be null.- Returns:
- this builder.
-
withSecret
public Argon2Parameters.Builder withSecret(byte[] secret)
Set the optional secret (key) value. The supplied array is defensively cloned.- Parameters:
secret- secret bytes; may be null.- Returns:
- this builder.
-
withAdditional
public Argon2Parameters.Builder withAdditional(byte[] additional)
Set the optional additional/associated data. The supplied array is defensively cloned.- Parameters:
additional- additional data bytes; may be null.- Returns:
- this builder.
-
withIterations
public Argon2Parameters.Builder withIterations(int iterations)
Set the number of passes (time cost).- Parameters:
iterations- number of iterations, must be at least 1.- Returns:
- this builder.
-
withMemoryAsKB
public Argon2Parameters.Builder withMemoryAsKB(int memory)
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:
java.lang.IllegalArgumentException- if the value is out of range.
-
withMemoryPowOfTwo
public Argon2Parameters.Builder withMemoryPowOfTwo(int memory)
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:
java.lang.IllegalArgumentException- if the exponent is out of range.
-
withVersion
public Argon2Parameters.Builder withVersion(int version)
Set the Argon2 version.- Parameters:
version- one ofArgon2Parameters.ARGON2_VERSION_10orArgon2Parameters.ARGON2_VERSION_13.- Returns:
- this builder.
-
withCharToByteConverter
public Argon2Parameters.Builder withCharToByteConverter(CharToByteConverter converter)
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
public Argon2Parameters.Builder withBlockPool(Argon2BytesGenerator.BlockPool blockPool)
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
public Argon2Parameters 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.
-
-