Libjade API documentation
May 2, 2023 ยท View on GitHub
The API documentation is currently still work in progress. So far, only the API documentation
for crypto_kem is complete. Some general remarks that apply to the APIs for all functionalities:
- All memory regions provided to API functions through pointers are assumed to not overlap.
- For all writable memory regions that provided to API functions through pointers, the caller needs to ensure that no other thread has read or write access.
- For all read-only memory regions that provided to API functions through pointers, the caller needs to ensure that no other thread has read access.
- Libjade functions do not require any alignment of pointers provided to API functions.
crypto_kem API
Detailed documentation
Overview of functions and constants
Each implementation in the crypto_kem subdirectory defines in its header file five functions:
int jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_keypair_derand(
uint8_t *public_key,
uint8_t *secret_key,
const uint8_t * coins
);
int jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_keypair(
uint8_t *public_key,
uint8_t *secret_key
);
int jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_enc_derand(
uint8_t *ciphertext,
uint8_t *shared_secret,
const uint8_t *public_key,
const uint8_t *coins
);
int jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_enc(
uint8_t *ciphertext,
uint8_t *shared_secret,
const uint8_t *public_key
);
int jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_dec(
uint8_t *shared_secret,
const uint8_t *ciphertext,
const uint8_t *secret_key
);
where FAMILY is replaced by an (all-lowercase) name of the function family,
ALGORITHM is replaced by an (all-lowercase) name of the specific member of the function family,
ARCH is replaced by an (all-lowercase) name of the target architecture, and
IMPL is replaced by an (all-lowercase) name of the implementation.
For example, for the reference implementation of Kyber768 targeting the AMD64 architecture,
the five function names are
jade_kem_kyber_kyber768_amd64_ref_keypair_derand,
jade_kem_kyber_kyber768_amd64_ref_keypair,
jade_kem_kyber_kyber768_amd64_ref_enc_derand,
jade_kem_kyber_kyber768_amd64_ref_enc, and
jade_kem_kyber_kyber768_amd64_ref_dec.
Additionally, the header file defines six compile-time constants
(through #define):
JADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_SECRETKEYBYTES
JADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_PUBLICKEYBYTES
JADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_CIPHERTEXTBYTES
JADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_KEYPAIRCOINBYTES
JADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_ENCCOINBYTES
JADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_BYTES
where FAMILY, ALGORITHM, ARCH, and IMPL are substituted as in the function names.
So, for example, for the reference implementation of Kyber768 targeting the AMD64 architecture,
the six constants names are
JADE_KEM_kyber_kyber768_amd64_ref_SECRETKEYBYTES,
JADE_KEM_kyber_kyber768_amd64_ref_PUBLICKEYBYTES,
JADE_KEM_kyber_kyber768_amd64_ref_CIPHERTEXTBYTES,
JADE_KEM_kyber_kyber768_amd64_ref_KEYPAIRCOINBYTES,
JADE_KEM_kyber_kyber768_amd64_ref_ENCCOINBYTES, and
JADE_KEM_kyber_kyber768_amd64_ref_BYTES.
Contract for jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_keypair_derand
Caller's reponsibility:
- The caller must ensure that
public_keyis a pointer pointing to an allocated memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_PUBLICKEYBYTESbytes. No other thread must have read or write access to this memory region. - The caller must ensure that
secret_keyis a pointer pointing to an allocated memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_SECRETKEYBYTESbytes. This memory region must not be overlapping with the memory region pointed to bypublic_key. No other thread must have read or write access to this memory region. - The caller must ensure that
coinsis a pointer pointing to a memory region containingJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_KEYPAIRCOINBYTESrandom bytes generated from a cryptographically secure randomness source. The memory region must not be overlapping with the region pointed to bypublic_keyand it must not be overlapping with the region pointed to bysecret_key. No other thread must have write access to this memory region.
Guaranteed properties:
- The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_keypair_derandwill write exactlyJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_PUBLICKEYBYTESto the memory region pointed to bypublic_key; i.e., after the function returns, this memory region is initialized. - The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_keypair_derandwill write exactlyJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_SECRETKEYBYTESto the memory region pointed to bysecret_key; i.e., after the function returns, this memory region is initialized. - The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_keypair_derandwill not write to the memory region pointed to bycoins.
Additional requirements:
None.
Contract for jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_keypair
Caller's reponsibility:
- The caller must ensure that
public_keyis a pointer pointing to an allocated memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_PUBLICKEYBYTESbytes. No other thread must have read or write access to this memory region. - The caller must ensure that
secret_keyis a pointer pointing to an allocated memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_SECRETKEYBYTESbytes. This memory region must not be overlapping with the memory region pointed to bypublic_key. No other thread must have read or write access to this memory region.
Guaranteed properties:
- The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_keypair_derandwill write exactlyJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_PUBLICKEYBYTESto the memory region pointed to bypublic_key; i.e., after the function returns, this memory region is initialized. - The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_keypair_derandwill write exactlyJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_SECRETKEYBYTESto the memory region pointed to bysecret_key; i.e., after the function returns, this memory region is initialized.
Additional requirements:
At linking time, the build system has to provide a function randombytes(uint8_t* _x, uint64_t xlen). See below
for more information about this dependency on randombytes.
Contract for jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_enc_derand
Caller's reponsibility:
- The caller must ensure that
ciphertextis a pointer pointing to an allocated memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_CIPHERTEXTBYTESbytes. No other thread must have read or write access to this memory region. - The caller must ensure that
shared_secretis a pointer pointing to an allocated memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_BYTESbytes. This memory region must not be overlapping with the memory region pointed to byciphertext. No other thread must have read or write access to this memory region. - The caller must ensure that
public_keyis a pointer pointing to an initialized memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_PUBLICKEYBYTESbytes. This memory region must not be overlapping with the memory region pointed to byciphertextand it must not be overlapping with the region pointed to byshared_secret. No other thread must have write access to this memory region. - The caller must ensure that
coinsis a pointer pointing to a memory region containingJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_ENCCOINBYTESrandom bytes generated from a cryptographically secure randomness source. The memory region must not be overlapping with the region pointed to byciphertext, it must not be overlapping with the region pointed to byshared_secret, and it must not be overlapping with the region pointed to bypublic_key. No other thread must have write access to this memory region.
Guaranteed properties:
- The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_enc_derandwill write exactlyJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_CIPHERTEXTKEYBYTESto the memory region pointed to byciphertext; i.e., after the function returns, this memory region is initialized. - The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_enc_derandwill write exactlyJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_BYTESto the memory region pointed to byshared_secret; i.e., after the function returns, this memory region is initialized. - The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_enc_derandwill not write to the memory region pointed to bypublic_key. - The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_enc_derandwill not write to the memory region pointed to bycoins.
Additional requirements:
None.
Contract for jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_enc
Caller's reponsibility:
- The caller must ensure that
ciphertextis a pointer pointing to an allocated memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_CIPHERTEXTBYTESbytes. No other thread must have read or write access to this memory region. - The caller must ensure that
shared_secretis a pointer pointing to an allocated memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_BYTESbytes. This memory region must not be overlapping with the memory region pointed to byciphertext. No other thread must have read or write access to this memory region. - The caller must ensure that
public_keyis a pointer pointing to an initialized memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_PUBLICKEYBYTESbytes. This memory region must not be overlapping with the memory region pointed to byciphertextand it must not be overlapping with the region pointed to byshared_secret. No other thread must have write access to this memory region.
Guaranteed properties:
- The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_encwill write exactlyJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_CIPHERTEXTKEYBYTESto the memory region pointed to byciphertext; i.e., after the function returns, this memory region is initialized. - The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_encwill write exactlyJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_BYTESto the memory region pointed to byshared_secret; i.e., after the function returns, this memory region is initialized. - The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_encwill not write to the memory region pointed to bypublic_key.
Additional requirements:
At linking time, the build system has to provide a function randombytes(uint8_t* _x, uint64_t xlen). See below
for more information about this dependency on randombytes.
Contract for jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_dec
Caller's reponsibility:
- The caller must ensure that
shared_secretis a pointer pointing to an allocated memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_BYTESbytes. No other thread must have read or write access to this memory region. - The caller must ensure that
ciphertextis a pointer pointing to an initialized memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_CIPHERTEXTBYTESbytes. This memory region must not be overlapping with the memory region pointed to byshared_secret. No other thread must have write access to this memory region. - The caller must ensure that
secret_keyis a pointer pointing to an initialized memory region of lengthJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_SECRETKEYBYTESbytes. This memory region must not be overlapping with the memory region pointed to byshared_secretand it must not be overlapping with the region pointed to byciphertext. No other thread must have write access to this memory region.
Guaranteed properties:
- The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_decwill write exactlyJADE_KEM_FAMILY_ALGORITHM_ARCH_IMPL_BYTESto the memory region pointed to byshared_secret; i.e., after the function returns, this memory region is initialized. - The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_decwill not write to the memory region pointed to byciphertext. - The function
jade_kem_FAMILY_ALGORITHM_ARCH_IMPL_decwill not write to the memory region pointed to bysecret_key.
Additional requirements:
None.