pqc-binary-format 1.0.14

Standardized binary format for post-quantum cryptography encrypted data interchange
Documentation
/* PQC Binary Format v1.0 - C/C++ Bindings */
/* Auto-generated header file - DO NOT EDIT */


#ifndef PQC_BINARY_FORMAT_H
#define PQC_BINARY_FORMAT_H

#pragma once

/* Warning: This file is auto-generated by cbindgen. */


#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

/**
 * Current version of the PQC Binary Format specification
 */
#define PQC_BINARY_VERSION 1

/**
 * C-compatible byte buffer
 */
typedef struct ByteBuffer {
  unsigned char *data;
  uintptr_t len;
  uintptr_t capacity;
} ByteBuffer;

/**
 * Opaque handle to PqcBinaryFormat
 */
typedef struct PqcFormatHandle {
  uint8_t _private[0];
} PqcFormatHandle;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/**
 * Algorithm ID for Classical (X25519 + Ed25519 + AES-256-GCM)
 */
extern const uint16_t PQC_ALGORITHM_CLASSICAL;

/**
 * Algorithm ID for Password-based Classical encryption
 */
extern const uint16_t PQC_ALGORITHM_PASSWORD_CLASSICAL;

/**
 * Algorithm ID for Hybrid (ML-KEM-1024 + X25519 + ML-DSA-87 + Ed25519)
 */
extern const uint16_t PQC_ALGORITHM_HYBRID;

/**
 * Algorithm ID for Post-Quantum (ML-KEM-1024 + ML-DSA-87)
 */
extern const uint16_t PQC_ALGORITHM_POST_QUANTUM;

/**
 * Algorithm ID for ML-KEM-1024 pure implementation
 */
extern const uint16_t PQC_ALGORITHM_ML_KEM_1024;

/**
 * Algorithm ID for Multi-KEM (multiple key encapsulation layers)
 */
extern const uint16_t PQC_ALGORITHM_MULTI_KEM;

/**
 * Algorithm ID for Multi-KEM Triple Layer
 */
extern const uint16_t PQC_ALGORITHM_MULTI_KEM_TRIPLE;

/**
 * Algorithm ID for Quad-Layer redundant encryption
 */
extern const uint16_t PQC_ALGORITHM_QUAD_LAYER;

/**
 * Algorithm ID for PQ3-Stack with forward secrecy
 */
extern const uint16_t PQC_ALGORITHM_PQ3_STACK;

/**
 * Algorithm ID for Lattice-Code Hybrid Stack
 */
extern const uint16_t PQC_ALGORITHM_LATTICE_CODE_HYBRID;

/**
 * Algorithm ID for HQC-128 (NIST Level 1, 128-bit security)
 */
extern const uint16_t PQC_ALGORITHM_HQC_128;

/**
 * Algorithm ID for HQC-192 (NIST Level 3, 192-bit security)
 */
extern const uint16_t PQC_ALGORITHM_HQC_192;

/**
 * Algorithm ID for HQC-256 (NIST Level 5, 256-bit security)
 */
extern const uint16_t PQC_ALGORITHM_HQC_256;

/**
 * Free a byte buffer allocated by this library
 *
 * # Safety
 * The buffer must have been allocated by this library
 */
void pqc_free_buffer(struct ByteBuffer buffer);

/**
 * Free a string allocated by this library
 *
 * # Safety
 * The string must have been allocated by this library
 */
void pqc_free_string(char *s);

/**
 * Create a new PQC Binary Format structure
 *
 * # Parameters
 * - `algorithm_id`: Algorithm identifier (see Algorithm enum)
 * - `iv`: IV/nonce bytes
 * - `iv_len`: Length of IV
 * - `tag`: Authentication tag bytes
 * - `tag_len`: Length of tag
 * - `data`: Encrypted data bytes
 * - `data_len`: Length of encrypted data
 *
 * # Returns
 * Opaque handle to PqcBinaryFormat, or NULL on error
 *
 * # Safety
 * All pointers must be valid. The returned handle must be freed with `pqc_format_free`.
 */
struct PqcFormatHandle *pqc_format_new(uint16_t algorithm_id, const unsigned char *iv, uintptr_t iv_len, const unsigned char *tag, uintptr_t tag_len, const unsigned char *data, uintptr_t data_len);

/**
 * Create PQC Binary Format with KEM parameters
 *
 * # Safety
 * All pointers must be valid
 */
struct PqcFormatHandle *pqc_format_new_with_kem(uint16_t algorithm_id, const unsigned char *iv, uintptr_t iv_len, const unsigned char *tag, uintptr_t tag_len, const unsigned char *kem_public_key, uintptr_t kem_public_key_len, const unsigned char *kem_ciphertext, uintptr_t kem_ciphertext_len, const unsigned char *data, uintptr_t data_len);

/**
 * Serialize PQC Binary Format to bytes
 *
 * # Parameters
 * - `handle`: Handle to PqcBinaryFormat
 *
 * # Returns
 * ByteBuffer containing serialized data, or NULL buffer on error
 *
 * # Safety
 * Handle must be valid. Returned buffer must be freed with `pqc_free_buffer`.
 */
struct ByteBuffer pqc_format_to_bytes(const struct PqcFormatHandle *handle);

/**
 * Deserialize PQC Binary Format from bytes
 *
 * # Parameters
 * - `data`: Bytes to deserialize
 * - `len`: Length of data
 *
 * # Returns
 * Handle to PqcBinaryFormat, or NULL on error
 *
 * # Safety
 * Data pointer must be valid. Returned handle must be freed with `pqc_format_free`.
 */
struct PqcFormatHandle *pqc_format_from_bytes(const unsigned char *data, uintptr_t len);

/**
 * Get algorithm ID from format
 *
 * # Safety
 * Handle must be valid
 */
uint16_t pqc_format_get_algorithm_id(const struct PqcFormatHandle *handle);

/**
 * Get algorithm name from format
 *
 * # Returns
 * Null-terminated string. Must be freed with `pqc_free_string`.
 *
 * # Safety
 * Handle must be valid
 */
char *pqc_format_get_algorithm_name(const struct PqcFormatHandle *handle);

/**
 * Get encrypted data from format
 *
 * # Returns
 * ByteBuffer containing data. Must be freed with `pqc_free_buffer`.
 *
 * # Safety
 * Handle must be valid
 */
struct ByteBuffer pqc_format_get_data(const struct PqcFormatHandle *handle);

/**
 * Validate format structure
 *
 * # Returns
 * 0 on success, -1 on error
 *
 * # Safety
 * Handle must be valid
 */
int pqc_format_validate(const struct PqcFormatHandle *handle);

/**
 * Get total size of serialized format
 *
 * # Safety
 * Handle must be valid
 */
uintptr_t pqc_format_get_total_size(const struct PqcFormatHandle *handle);

/**
 * Free a PqcBinaryFormat handle
 *
 * # Safety
 * Handle must have been allocated by this library and not previously freed
 */
void pqc_format_free(struct PqcFormatHandle *handle);

/**
 * Get library version string
 *
 * # Returns
 * Null-terminated version string. Must be freed with `pqc_free_string`.
 */
char *pqc_get_version(void);

/**
 * Get binary format version
 */
uint8_t pqc_get_binary_version(void);

#ifdef __cplusplus
}  // extern "C"
#endif  // __cplusplus

#endif  /* PQC_BINARY_FORMAT_H */