pQCee SafeQuard API v1.0.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 for Kimbal Smart Meters
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 for Kimbal Smart Meters
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 SAFEQUARD_LOG_LEVEL_ERROR 1
57
61#define SAFEQUARD_LOG_LEVEL_WARN 2
62
66#define SAFEQUARD_LOG_LEVEL_INFO 3
67
71#define SAFEQUARD_LOG_LEVEL_DEBUG 4
72
79#define SAFEQUARD_LOG_MESSAGE_CAPACITY 64
80
84#define ML_DSA_65_SEED_SIZE 32
85
89#define ML_DSA_65_PUBLIC_KEY_SIZE 1952
90
94#define ML_DSA_65_SIGNATURE_SIZE 3309
95
99#define ML_KEM_768_SEED_SIZE 64
100
104#define ML_KEM_768_ENCAP_KEY_SIZE 1184
105
109#define ML_KEM_768_DECAP_KEY_SIZE 2400
110
114#define ML_KEM_768_CIPHERTEXT_SIZE 1088
115
119#define ML_KEM_SHARED_SECRET_SIZE 32
120
124#define ML_KEM_SHARED_SECRET_IV_SIZE 16
125
129#define SHA_512_BLOCK_SIZE 128
130
134#define SHA_512_DIGEST_SIZE 64
135
139#define SAFEQUARD_SUCCESS 0
140
144#define SAFEQUARD_ERROR_INVALID_LOG_LEVEL -1
145
149#define SAFEQUARD_ERROR_GENERIC -1000
150
154#define SAFEQUARD_ERROR_NOT_SUPPORTED -1001
155
159#define SAFEQUARD_ERROR_NOT_PERMITTED -1002
160
164#define SAFEQUARD_ERROR_BUFFER_TOO_SMALL -1003
165
169#define SAFEQUARD_ERROR_ALREADY_EXISTS -1004
170
174#define SAFEQUARD_ERROR_DOES_NOT_EXIST -1005
175
179#define SAFEQUARD_ERROR_BAD_STATE -1006
180
184#define SAFEQUARD_ERROR_INVALID_ARGUMENT -1007
185
189#define SAFEQUARD_ERROR_INSUFFICIENT_MEMORY -1008
190
194#define SAFEQUARD_ERROR_INSUFFICIENT_STORAGE -1009
195
199#define SAFEQUARD_ERROR_COMMUNICATION_FAILURE -1010
200
204#define SAFEQUARD_ERROR_STORAGE_FAILURE -1011
205
209#define SAFEQUARD_ERROR_DATA_CORRUPT -1012
210
214#define SAFEQUARD_ERROR_DATA_INVALID -1013
215
219#define SAFEQUARD_ERROR_HARDWARE_FAILURE -1014
220
224#define SAFEQUARD_ERROR_CORRUPTION_DETECTED -1015
225
229#define SAFEQUARD_ERROR_INSUFFICIENT_ENTROPY -1016
230
234#define SAFEQUARD_ERROR_INVALID_SIGNATURE -1017
235
239#define SAFEQUARD_ERROR_INVALID_PADDING -1018
240
244#define SAFEQUARD_ERROR_INSUFFICIENT_DATA -1019
245
249#define SAFEQUARD_ERROR_INVALID_HANDLE -1020
250
254#define SAFEQUARD_ERROR_BACKEND -1099
255
260#define SAFEQUARD_ERROR_MALFORMED_DER -1100
261
265#define SAFEQUARD_ERROR_TRAILING_DATA -1101
266
272#define SAFEQUARD_ERROR_UNSUPPORTED_ALGORITHM -1102
273
278#define SAFEQUARD_ERROR_INVALID_PUBLIC_KEY -1103
279
285#define SAFEQUARD_ERROR_ROOT_NOT_SELF_ISSUED -1105
286
294#define SAFEQUARD_ERROR_INVALID_ROOT_SIGNATURE -1106
295
300#define SAFEQUARD_ERROR_INVALID_TIME -1107
301
305#define SAFEQUARD_ERROR_TIME_SOURCE_UNAVAILABLE -1108
306
311#define SAFEQUARD_ERROR_CERTIFICATE_NOT_YET_VALID -1109
312
317#define SAFEQUARD_ERROR_CERTIFICATE_EXPIRED -1110
318
323#define SAFEQUARD_ERROR_ISSUER_MISMATCH -1111
324
331#define SAFEQUARD_ERROR_CERTIFICATE_MUST_BE_V3 -1112
332
337#define SAFEQUARD_ERROR_DUPLICATE_EXTENSION -1113
338
346#define SAFEQUARD_ERROR_UNKNOWN_CRITICAL_EXTENSION -1114
347
352#define SAFEQUARD_ERROR_MISSING_BASIC_CONSTRAINTS -1115
353
357#define SAFEQUARD_ERROR_BASIC_CONSTRAINTS_NOT_CRITICAL -1116
358
363#define SAFEQUARD_ERROR_EXPECTED_CA -1117
364
368#define SAFEQUARD_ERROR_LEAF_IS_CA -1118
369
373#define SAFEQUARD_ERROR_MISSING_KEY_USAGE -1119
374
378#define SAFEQUARD_ERROR_KEY_USAGE_NOT_CRITICAL -1120
379
384#define SAFEQUARD_ERROR_INVALID_CA_KEY_USAGE -1121
385
393#define SAFEQUARD_ERROR_INVALID_LEAF_KEY_USAGE -1122
394
399#define SAFEQUARD_ERROR_MISSING_EXTENDED_KEY_USAGE -1123
400
405#define SAFEQUARD_ERROR_EXTENDED_KEY_USAGE_NOT_CRITICAL -1124
406
411#define SAFEQUARD_ERROR_INVALID_CODE_SIGNING_USAGE -1125
412
417#define SAFEQUARD_ERROR_PATH_LENGTH_EXCEEDED -1126
418
423#define SAFEQUARD_ERROR_TOO_MANY_INTERMEDIATES -1127
424
429#define SAFEQUARD_ERROR_INVALID_PKCS8 -1128
430
438#define SAFEQUARD_ERROR_PKCS8_DECRYPTION_FAILED -1129
439
444#define SAFEQUARD_ERROR_INVALID_PRIVATE_KEY_ALGORITHM -1130
445
452#define SAFEQUARD_ERROR_SEED_NOT_AVAILABLE -1131
453
458#define SAFEQUARD_ERROR_INVALID_SEED_ENCODING -1132
459
460#ifdef __cplusplus
461extern "C" {
462#endif // __cplusplus
463
472extern void safequard_panic_wrap(void);
473
482int safequard_init(uint32_t max_log_level);
483
502int safequard_mldsa65_sign(const uint8_t *seed,
503 size_t seed_size,
504 const uint8_t *data,
505 size_t data_size,
506 uint8_t *signature,
507 size_t signature_size);
508
528int safequard_mldsa65_verify(const uint8_t *public_key,
529 size_t public_key_size,
530 const uint8_t *data,
531 size_t data_size,
532 const uint8_t *signature,
533 size_t signature_size);
534
561int safequard_fv_import_key(uint8_t *context,
562 size_t context_size,
563 const uint8_t *trusted_cert,
564 size_t trusted_cert_size,
565 const uint8_t *leaf_cert,
566 size_t leaf_cert_size,
567 size_t *out);
568
591int safequard_fv_verify(const uint8_t *context,
592 size_t context_size,
593 const uint8_t *data,
594 size_t data_size,
595 const uint8_t *signature,
596 size_t signature_size);
597
626int safequard_mlkem768_init(uint8_t *context,
627 size_t context_size,
628 uint8_t *encap_key,
629 size_t encap_key_size,
630 size_t *out);
631
647int safequard_mlkem768_encrypt(const uint8_t *message,
648 size_t message_size,
649 const uint8_t *encap_key,
650 size_t encap_key_size,
651 uint8_t *ciphertext,
652 size_t ciphertext_size,
653 uint8_t *encrypted_message,
654 size_t encrypted_message_size);
655
674int safequard_mlkem768_decrypt(const uint8_t *context,
675 size_t context_size,
676 const uint8_t *encrypted_message,
677 size_t encrypted_message_size,
678 const uint8_t *ciphertext,
679 size_t ciphertext_size,
680 uint8_t *message,
681 size_t message_size);
682
692int safequard_mlkem768_finalise(uint8_t *context, size_t context_size);
693
714int safequard_sha512_init(uint8_t *context,
715 size_t context_size,
716 size_t *out);
717
738int safequard_sha512_update(uint8_t *context,
739 size_t context_size,
740 const uint8_t *chunk,
741 size_t chunk_size);
742
757int safequard_sha512_finalise(uint8_t *context,
758 size_t context_size,
759 uint8_t *hash,
760 size_t hash_size);
761
776int safequard_sha512(const uint8_t *message,
777 size_t message_size,
778 uint8_t *hash,
779 size_t hash_size);
780
795extern void safequard_log_message(uint32_t level, const char *message, size_t message_length);
796
807extern int64_t get_current_time(void);
808
809#ifdef __cplusplus
810} // extern "C"
811#endif // __cplusplus
812
813#endif /* PQCEE_SAFEQUARD_API_H */
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_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_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.
void safequard_log_message(uint32_t level, const char *message, size_t message_length)
Log a message.
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_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.