Operators#
cuHash operators are used to describe the operation to be performed, and configure the execution.
They are combined via addition (+
) to form a cuHash descriptor.
cuHash Operators#
Description Operators#
Algorithm#
Sets the algorithm Alg
to use. Valid values are:
-
enum algorithm#
-
-
enumerator SHA2_32#
SHA-2 32-bit word size hash functions (FIPS-180-4)
-
enumerator SHA2_64#
SHA-2 64-bit word size hash functions (FIPS-180-4)
-
enumerator POSEIDON2#
Poseidon2 hash functions
-
enumerator MERKLE#
Tells the operator to use the Merkle Tree API
-
enumerator SHA2_32#
There is no default value.
SecurityCategory#
-
template<unsigned int Category>
SecurityCategory()#
Sets the NIST security category, which determines the parameter set of the algorithm to be used.
The valid values of Category
depend on the value of the Algorithm
operator.
Poseidon2 and Merkle Tree do not require a security category.
There is no default value.
Name |
Alias |
||
---|---|---|---|
SHA2-224 |
|
|
|
SHA2-256 |
|
|
|
SHA2-384 |
|
|
|
SHA2-512 |
|
|
|
SHA2-512/224 |
|
|
|
SHA2-512/256 |
|
|
|
SHA3-224 |
|
|
|
SHA3-256 |
|
|
|
SHA3-384 |
|
|
|
SHA3-512 |
|
|
|
SHAKE-128 |
|
|
|
SHAKE-256 |
|
|
Poseidon2 Specific Operators#
Currently, we only support Poseidon2-BabyBear with field 231 - 227 + 1. The round constants and Maximum Distance Separable (MDS) matrix that are used in the algorithm can be accessed from here.
Width#
-
template<unsigned int Width>
Width()#
Sets the width of the Poseidon2 function. Currently, the only supported widths are 16 and 24. The default value is 16.
Capacity#
-
template<unsigned int Capacity>
Capacity()#
Sets the capacity of the Poseidon2 function. Currently, the only supported capacity is 8. The default value is 8.
For Poseidon2 we have the following combinations:
Merkle Tree Specific Operators#
MerkleSize#
-
template<unsigned int Size>
MerkleSize()#
Sets the size of the Merkle Tree. Sizes 2 to 2^21 are supported. The default value is 2048.
Precision#
-
template<typename Precision>
Precision()#
Sets the precision of the Merkle Tree. Currently, the only supported precisions are uint8_t, and uint32_t. SHA2, SHA3, and SHAKE hashes use uint8_t, and Poseidon2 uses uint32_t. The default value is uint8_t.
Merkle Tree Aliases#
For convenience, we provide aliases for Merkle Trees with the supported sizes and precisions. They are in the following format:
MERKLE_<PRECISION>_<SIZE>
where <PRECISION>
takes the values BYTE
or FIELD
representing uint8_t or uint32_t respectively, and <SIZE>
is the size
as a raw number, not the power of 2 exponent.
For example, MERKLE_BYTE_2048
is an alias for decltype(Algorithm<algorithm::MERKLE>() + MerkleSize<2048>() + Precision<uint8_t>() + Function<function::Merkle>() + Block())
.
Recall that the precision is tied to the respective hash algorithm that will be used in tandem with the Merkle Tree, in the case of our example, this Merkle Tree will be used with SHA2, SHA3, or SHAKE.
Execution Operators#
Thread execution#
-
Thread()#
Specifies that the operator will execute independently for each thread.
Warp execution#
-
Warp()#
Specifies that the operator will execute on each CUDA warp (group of 32 threads). The device methods should be called with the same arguments for all threads in the warp.
Only the algorithm::SHA3
and algorithm::SHAKE
algorithms are supported for this execution mode.
Block execution#
-
Block()#
Specifies that the operator will execute on each CUDA block.
Only the algorithm::MERKLE
algorithm is supported for this execution mode with cuHash.
Essentially, the MERKLE algorithm will utilize a thread based Hash function to generate the Merkle Tree using a full block.