pQCee SafeQuard API v1.1.0
Post-quantum cryptographic library.
Loading...
Searching...
No Matches
pqcee_safequard_api.h
Go to the documentation of this file.
1/* Author: pQCee
2 *
3 * Description : SafeQuard
4 *
5 * Copyright 2026 pQCee Pte Ltd. All rights reserved. Confidential.
6 *
7 * "Commons Clause" License Condition v1.0
8 *
9 * The Software is provided to you by the Licensor under the License, as defined
10 * below, subject to the following condition.
11 *
12 * Without limiting other conditions in the License, the grant of rights under
13 * the License will not include, and the License does not grant to you, the
14 * right to Sell the Software.
15 *
16 * For purposes of the foregoing, "Sell" means practicing any or all of the
17 * rights granted to you under the License to provide to third parties, for a
18 * fee or other consideration (including without limitation fees for hosting or
19 * consulting/ support services related to the Software), a product or service
20 * whose value derives, entirely or substantially, from the functionality of the
21 * Software. Any license notice or attribution required by the License must also
22 * include this Commons Clause License Condition notice.
23 *
24 * Do not attempt to reverse engineer, disassemble, or decompile any prototypes,
25 * software, or other items of Confidential Information that are provided here. In
26 * addition, you agree not to attempt to reconstruct, identify or discover any
27 * source code, underlying ideas, techniques or algorithms in Confidential
28 * Information by any means whatever, except as may be specifically authorized in
29 * advance by pQCee in writing.
30 *
31 * Software : SafeQuard
32 *
33 * Licensor: pQCee Pte Ltd
34*/
35
43
44
45#ifndef PQCEE_SAFEQUARD_API_H
46#define PQCEE_SAFEQUARD_API_H
47
48/* Auto-generated by cbindgen. Do not edit manually. */
49
50#include <stdint.h>
51#include <stdlib.h>
52
56#define DLMS_CHALLENGE_SIZE 64
57
61#define AES_256_KEY_SIZE 32
62
66#define ML_DSA_65_SEED_SIZE 32
67
71#define ML_DSA_65_PUBLIC_KEY_SIZE 1952
72
76#define ML_DSA_65_SIGNATURE_SIZE 3309
77
81#define ML_KEM_768_SEED_SIZE 64
82
86#define ML_KEM_768_ENCAP_KEY_SIZE 1184
87
91#define ML_KEM_768_DECAP_KEY_SIZE 2400
92
96#define ML_KEM_768_CIPHERTEXT_SIZE 1088
97
101#define ML_KEM_SHARED_SECRET_SIZE 32
102
106#define ML_KEM_SHARED_SECRET_IV_SIZE 16
107
111#define ML_KEM_SHARED_SECRET_AUTH_IV_SIZE 12
112
116#define ML_KEM_SHARED_SECRET_AUTH_TAG_SIZE 16
117
121#define SHA_512_BLOCK_SIZE 128
122
126#define SHA_512_DIGEST_SIZE 64
127
131#define SAFEQUARD_SUCCESS 0
132
136#define SAFEQUARD_ERROR_INVALID_LOG_LEVEL -1
137
141#define SAFEQUARD_ERROR_GENERIC -1000
142
146#define SAFEQUARD_ERROR_NOT_SUPPORTED -1001
147
151#define SAFEQUARD_ERROR_NOT_PERMITTED -1002
152
156#define SAFEQUARD_ERROR_BUFFER_TOO_SMALL -1003
157
161#define SAFEQUARD_ERROR_ALREADY_EXISTS -1004
162
166#define SAFEQUARD_ERROR_DOES_NOT_EXIST -1005
167
171#define SAFEQUARD_ERROR_BAD_STATE -1006
172
176#define SAFEQUARD_ERROR_INVALID_ARGUMENT -1007
177
181#define SAFEQUARD_ERROR_INSUFFICIENT_MEMORY -1008
182
186#define SAFEQUARD_ERROR_INSUFFICIENT_STORAGE -1009
187
191#define SAFEQUARD_ERROR_COMMUNICATION_FAILURE -1010
192
196#define SAFEQUARD_ERROR_STORAGE_FAILURE -1011
197
201#define SAFEQUARD_ERROR_DATA_CORRUPT -1012
202
206#define SAFEQUARD_ERROR_DATA_INVALID -1013
207
211#define SAFEQUARD_ERROR_HARDWARE_FAILURE -1014
212
216#define SAFEQUARD_ERROR_CORRUPTION_DETECTED -1015
217
221#define SAFEQUARD_ERROR_INSUFFICIENT_ENTROPY -1016
222
226#define SAFEQUARD_ERROR_INVALID_SIGNATURE -1017
227
231#define SAFEQUARD_ERROR_INVALID_PADDING -1018
232
236#define SAFEQUARD_ERROR_INSUFFICIENT_DATA -1019
237
241#define SAFEQUARD_ERROR_INVALID_HANDLE -1020
242
246#define SAFEQUARD_ERROR_BACKEND -1099
247
252#define SAFEQUARD_ERROR_MALFORMED_DER -1100
253
257#define SAFEQUARD_ERROR_TRAILING_DATA -1101
258
264#define SAFEQUARD_ERROR_UNSUPPORTED_ALGORITHM -1102
265
270#define SAFEQUARD_ERROR_INVALID_PUBLIC_KEY -1103
271
277#define SAFEQUARD_ERROR_ROOT_NOT_SELF_ISSUED -1105
278
286#define SAFEQUARD_ERROR_INVALID_ROOT_SIGNATURE -1106
287
292#define SAFEQUARD_ERROR_INVALID_TIME -1107
293
297#define SAFEQUARD_ERROR_TIME_SOURCE_UNAVAILABLE -1108
298
303#define SAFEQUARD_ERROR_CERTIFICATE_NOT_YET_VALID -1109
304
309#define SAFEQUARD_ERROR_CERTIFICATE_EXPIRED -1110
310
315#define SAFEQUARD_ERROR_ISSUER_MISMATCH -1111
316
323#define SAFEQUARD_ERROR_CERTIFICATE_MUST_BE_V3 -1112
324
329#define SAFEQUARD_ERROR_DUPLICATE_EXTENSION -1113
330
338#define SAFEQUARD_ERROR_UNKNOWN_CRITICAL_EXTENSION -1114
339
344#define SAFEQUARD_ERROR_MISSING_BASIC_CONSTRAINTS -1115
345
349#define SAFEQUARD_ERROR_BASIC_CONSTRAINTS_NOT_CRITICAL -1116
350
355#define SAFEQUARD_ERROR_EXPECTED_CA -1117
356
360#define SAFEQUARD_ERROR_LEAF_IS_CA -1118
361
365#define SAFEQUARD_ERROR_MISSING_KEY_USAGE -1119
366
370#define SAFEQUARD_ERROR_KEY_USAGE_NOT_CRITICAL -1120
371
376#define SAFEQUARD_ERROR_INVALID_CA_KEY_USAGE -1121
377
385#define SAFEQUARD_ERROR_INVALID_LEAF_KEY_USAGE -1122
386
391#define SAFEQUARD_ERROR_MISSING_EXTENDED_KEY_USAGE -1123
392
397#define SAFEQUARD_ERROR_EXTENDED_KEY_USAGE_NOT_CRITICAL -1124
398
403#define SAFEQUARD_ERROR_INVALID_CODE_SIGNING_USAGE -1125
404
409#define SAFEQUARD_ERROR_PATH_LENGTH_EXCEEDED -1126
410
415#define SAFEQUARD_ERROR_TOO_MANY_INTERMEDIATES -1127
416
421#define SAFEQUARD_ERROR_INVALID_PKCS8 -1128
422
430#define SAFEQUARD_ERROR_PKCS8_DECRYPTION_FAILED -1129
431
436#define SAFEQUARD_ERROR_INVALID_PRIVATE_KEY_ALGORITHM -1130
437
444#define SAFEQUARD_ERROR_SEED_NOT_AVAILABLE -1131
445
450#define SAFEQUARD_ERROR_INVALID_SEED_ENCODING -1132
451
455#define SAFEQUARD_LOG_LEVEL_ERROR 1
456
460#define SAFEQUARD_LOG_LEVEL_WARN 2
461
465#define SAFEQUARD_LOG_LEVEL_INFO 3
466
470#define SAFEQUARD_LOG_LEVEL_DEBUG 4
471
478#define SAFEQUARD_LOG_MESSAGE_CAPACITY 64
479
480#ifdef __cplusplus
481extern "C" {
482#endif // __cplusplus
483
492extern void safequard_panic_wrap(void);
493
502int safequard_init(uint32_t max_log_level);
503
522int safequard_mldsa65_sign(const uint8_t *seed,
523 size_t seed_size,
524 const uint8_t *data,
525 size_t data_size,
526 uint8_t *signature,
527 size_t signature_size);
528
547int safequard_mldsa65_verify(const uint8_t *public_key,
548 size_t public_key_size,
549 const uint8_t *data,
550 size_t data_size,
551 const uint8_t *signature,
552 size_t signature_size);
553
580int safequard_fv_import_key(uint8_t *context,
581 size_t context_size,
582 const uint8_t *trusted_cert,
583 size_t trusted_cert_size,
584 const uint8_t *leaf_cert,
585 size_t leaf_cert_size,
586 size_t *out);
587
610int safequard_fv_verify(const uint8_t *context,
611 size_t context_size,
612 const uint8_t *data,
613 size_t data_size,
614 const uint8_t *signature,
615 size_t signature_size);
616
645int safequard_mlkem768_init(uint8_t *context,
646 size_t context_size,
647 uint8_t *encap_key,
648 size_t encap_key_size,
649 size_t *out);
650
687int safequard_dlms_key_agreement_encap(const uint8_t *encap_key,
688 size_t encap_key_size,
689 const uint8_t *other_info,
690 size_t other_info_size,
691 uint8_t *ciphertext,
692 size_t ciphertext_size,
693 uint8_t *context,
694 size_t context_size,
695 size_t *out);
696
737int safequard_dlms_key_agreement_decap(const uint8_t *context,
738 size_t context_size,
739 const uint8_t *other_info,
740 size_t other_info_size,
741 const uint8_t *ciphertext,
742 size_t ciphertext_size,
743 uint8_t *ss_context,
744 size_t ss_context_size,
745 size_t *out);
746
768int safequard_mlkem768_encrypt(const uint8_t *message,
769 size_t message_size,
770 const uint8_t *encap_key,
771 size_t encap_key_size,
772 uint8_t *ciphertext,
773 size_t ciphertext_size,
774 uint8_t *encrypted_message,
775 size_t encrypted_message_size);
776
801int safequard_mlkem768_decrypt(const uint8_t *context,
802 size_t context_size,
803 const uint8_t *encrypted_message,
804 size_t encrypted_message_size,
805 const uint8_t *ciphertext,
806 size_t ciphertext_size,
807 uint8_t *message,
808 size_t message_size);
809
834int safequard_dlms_auth_encrypt(const uint8_t *context,
835 size_t context_size,
836 const uint8_t *aad,
837 size_t aad_size,
838 const uint8_t *message,
839 size_t message_size,
840 uint8_t *encrypted_message,
841 size_t encrypted_message_size);
842
868int safequard_dlms_auth_decrypt(const uint8_t *context,
869 size_t context_size,
870 const uint8_t *aad,
871 size_t aad_size,
872 const uint8_t *encrypted_message,
873 size_t encrypted_message_size,
874 uint8_t *message,
875 size_t message_size);
876
886int safequard_mlkem768_finalise(uint8_t *context, size_t context_size);
887
908int safequard_sha512_init(uint8_t *context,
909 size_t context_size,
910 size_t *out);
911
931int safequard_sha512_update(uint8_t *context,
932 size_t context_size,
933 const uint8_t *chunk,
934 size_t chunk_size);
935
951int safequard_sha512_finalise(uint8_t *context,
952 size_t context_size,
953 uint8_t *hash,
954 size_t hash_size);
955
970int safequard_sha512(const uint8_t *message,
971 size_t message_size,
972 uint8_t *hash,
973 size_t hash_size);
974
984int safequard_dlms_generate_challenge(uint8_t *challenge, size_t challenge_size);
985
1000extern void safequard_log_message(uint32_t level, const char *message, size_t message_length);
1001
1012extern int64_t get_current_time(void);
1013
1014#ifdef __cplusplus
1015} // extern "C"
1016#endif // __cplusplus
1017
1018#endif /* PQCEE_SAFEQUARD_API_H */
int safequard_dlms_key_agreement_decap(const uint8_t *context, size_t context_size, const uint8_t *other_info, size_t other_info_size, const uint8_t *ciphertext, size_t ciphertext_size, uint8_t *ss_context, size_t ss_context_size, size_t *out)
Decap an ML-KEM-768 decapsulation key for DLMS key agreement.
void safequard_panic_wrap(void)
Panic the current thread.
int safequard_mlkem768_init(uint8_t *context, size_t context_size, uint8_t *encap_key, size_t encap_key_size, size_t *out)
Generate a new ML-KEM-768 keypair for encrypting and decrypting messages.
int safequard_sha512_update(uint8_t *context, size_t context_size, const uint8_t *chunk, size_t chunk_size)
Update a SHA-512 context for streaming hashing operations.
int safequard_mlkem768_finalise(uint8_t *context, size_t context_size)
Finalise the decryption process.
int safequard_mldsa65_sign(const uint8_t *seed, size_t seed_size, const uint8_t *data, size_t data_size, uint8_t *signature, size_t signature_size)
Sign an ML-DSA-65 message.
int safequard_dlms_auth_encrypt(const uint8_t *context, size_t context_size, const uint8_t *aad, size_t aad_size, const uint8_t *message, size_t message_size, uint8_t *encrypted_message, size_t encrypted_message_size)
Encrypt with authentication a message using AES-256-GCM.
int safequard_sha512(const uint8_t *message, size_t message_size, uint8_t *hash, size_t hash_size)
Compute a SHA-512 digest of a message.
int safequard_init(uint32_t max_log_level)
Initialise the safequard_api library.
int safequard_mlkem768_decrypt(const uint8_t *context, size_t context_size, const uint8_t *encrypted_message, size_t encrypted_message_size, const uint8_t *ciphertext, size_t ciphertext_size, uint8_t *message, size_t message_size)
Decrypt an ML-KEM-768 encrypted message.
int safequard_sha512_init(uint8_t *context, size_t context_size, size_t *out)
Generate a new SHA-512 context for streaming hash operations.
int safequard_mlkem768_encrypt(const uint8_t *message, size_t message_size, const uint8_t *encap_key, size_t encap_key_size, uint8_t *ciphertext, size_t ciphertext_size, uint8_t *encrypted_message, size_t encrypted_message_size)
Encrypt a message using an encapsulation key.
int safequard_dlms_generate_challenge(uint8_t *challenge, size_t challenge_size)
Generate a 64-byte challenge for DLMS authentication.
int safequard_fv_import_key(uint8_t *context, size_t context_size, const uint8_t *trusted_cert, size_t trusted_cert_size, const uint8_t *leaf_cert, size_t leaf_cert_size, size_t *out)
Import an ML-DSA-65 public key to prepare for verification.
int safequard_sha512_finalise(uint8_t *context, size_t context_size, uint8_t *hash, size_t hash_size)
Finalise a SHA-512 operation and receive the hash. context is reset if the operation is successful.
void safequard_log_message(uint32_t level, const char *message, size_t message_length)
Log a message.
int safequard_dlms_key_agreement_encap(const uint8_t *encap_key, size_t encap_key_size, const uint8_t *other_info, size_t other_info_size, uint8_t *ciphertext, size_t ciphertext_size, uint8_t *context, size_t context_size, size_t *out)
Encap an ML-KEM-768 encapsulation key for DLMS key agreement.
int safequard_fv_verify(const uint8_t *context, size_t context_size, const uint8_t *data, size_t data_size, const uint8_t *signature, size_t signature_size)
Verify an ML-DSA-65-signed data using a certificate trust chain.
int64_t get_current_time(void)
Get the current unix time.
int safequard_dlms_auth_decrypt(const uint8_t *context, size_t context_size, const uint8_t *aad, size_t aad_size, const uint8_t *encrypted_message, size_t encrypted_message_size, uint8_t *message, size_t message_size)
Decrypt with authentication a message using AES-256-GCM.
int safequard_mldsa65_verify(const uint8_t *public_key, size_t public_key_size, const uint8_t *data, size_t data_size, const uint8_t *signature, size_t signature_size)
Verify an ML-DSA-65-signed data.