Device Methods#
cuPQC Library Device Methods#
Methods can be accessed from instances of a descriptor PQC
.
execute#
-
PQC::execute(...)#
A descriptor objects defines an
execute
method, the signature of which depends on theFunction
operator. Common arguments:- Parameters:
entropy – Source of cryptographic entropy of length
PQC::entropy_size
, and 8-byte aligned. Should be created byget_entropy
.workspace – Global memory workspace of length
PQC::workspace_size
, and 8-byte aligned.. Can be allocated bymake_workspace
.smem_workspace –
Shared memory workspace of length
PQC::shared_memory_size
, and 8-byte aligned. Typically allocated by :__shared__ uint8_t smem_workspace[PQC::shared_memory_size];
Keygen#
- __device__ void PQC::execute(
- uint8_t *public_key,
- uint8_t *secret_key,
- uint8_t *entropy,
- uint8_t *workspace,
- uint8_t *smem_workspace,
Generate public and secret key pair.
- Parameters:
public_key – Buffer to which the public key will be written. Must be of length
PQC::public_key_size
, and 8-byte aligned.secret_key – Buffer to which the secret key will be written. Must be of length
PQC::secret_key_size
, and 8-byte aligned.
Encaps#
- __device__ void PQC::execute(
- uint8_t *ciphertext,
- uint8_t *shared_secret,
- const uint8_t *public_key,
- uint8_t *entropy,
- uint8_t *workspace,
- uint8_t *smem_workspace,
Perform encapsulation: generate a shared secret and encrypt it as a ciphertext using the public key.
- Parameters:
ciphertext – Buffer to which the ciphertext will be written. Must be of length
PQC::ciphertext_size
, and 8-byte aligned.shared_secret – Buffer to which the shared secret will be written. Must be of length
PQC::shared_secret_size
, and 8-byte aligned.public_key – Buffer containing the public key. Must be of length
PQC::public_key_size
, and 8-byte aligned.
Decaps#
- __device__ void PQC::execute(
- uint8_t *shared_secret,
- const uint8_t *ciphertext,
- const uint8_t *secret_key,
- uint8_t *workspace,
- uint8_t *smem_workspace,
Perform decapsulation: derive the shared secret from the ciphertext and secret key.
- Parameters:
shared_secret – Buffer to which the shared secret will be written. Must be of length
PQC::shared_secret_size
, and 8-byte aligned.ciphertext – Buffer containing the ciphertext. Must be of length
PQC::ciphertext_size
, and 8-byte aligned.secret_key – Buffer containing the secret key. Must be of length
PQC::secret_key_size
, and 8-byte aligned.
Sign#
- __device__ void PQC::execute(
- uint8_t *signature,
- const uint8_t *message,
- const size_t message_length,
- const uint8_t *secret_key,
- uint8_t *entropy,
- uint8_t *workspace,
- uint8_t *smem_workspace,
Sign a message using the secret key.
- Parameters:
signature – Buffer to which the signature will be written. Must be of length
PQC::signature_size
, and 8-byte aligned.message – Buffer containing the message.
message_length – Length of the
message
buffer.secret_key – Buffer containing the secret key. Must be of length
PQC::secret_key_size
, and 8-byte aligned.
Note
For
algorithm::ML_DSA
,PQC::signature_size
is not a multiple of 8. If performing batches of operations, padding may be required to ensure thesignature
argument is correctly aligned.
Verify#
- __device__ bool PQC::execute(
- const uint8_t *message,
- const size_t message_length,
- const uint8_t *signature,
- const uint8_t *public_key,
- uint8_t *workspace,
- uint8_t *smem_workspace,
Verify the signature of a message using the public key.
- Parameters:
message – Buffer containing the message.
message_length – Length of the
message
buffer.signature – Buffer containing the signature. Must be of length
PQC::signature_size
, and 8-byte aligned.public_key – Buffer containing the public key. Must be of length
PQC::public_key_size
, and 8-byte aligned.
- Returns:
true
if the signature is valid for the given message and public key,false
otherwise.
Note
For
algorithm::ML_DSA
,PQC::signature_size
is not a multiple of 8. If performing batches of operations, padding may be required to ensure thesignature
argument is correctly aligned.
cuHash Device Methods#
In the following method descriptions, HASH
is used as a placeholder for the cuHash descriptor object that is instantiated with a specific hash algorithm.
reset#
update#
- __device__ void HASH::update(
- const uint8_t *message,
- const size_t message_length,
Append a message into the hash state. This may be called multiple times to incrementally update a single message.
- Parameters:
message – Buffer containing the message.
message_length – Length of the
message
buffer.
finalize#
digest#
- __device__ void HASH::digest(
- uint8_t *digest,
- const size_t digest_length,
Extract the hash state into a digest. This may be called multiple times to incrementally digest a single message.
- Parameters:
digest – Buffer to which the digest will be written. Must be of length
digest_length
, and 8-byte aligned.digest_length – Length of the
digest
buffer.