zupt/vendor/vuptsdk/include/zupt_mlkem.h
Cristian Cezar Moisés 51fa068f50 sdk: integrate libvuptsdk (renamed libzuptsdk); decouple --pq-box
libvuptsdk (git.securityops.co/cristiancmoises/libvuptsdk) is the renamed
libzuptsdk: only the .so filename/SONAME changed (libzuptsdk.so.2 ->
libvuptsdk.so.2); the C API (zuptsdk_* symbols, zuptsdk.h) is unchanged.

- Rename vendor/zuptsdk -> vendor/vuptsdk with libvuptsdk's headers.
- Makefile WITH_SDK=1 now links -lvuptsdk (+ its transitive libcrypto/libargon2
  deps via SDK_DEPLIBS) instead of -lzuptsdk, and installs libvuptsdk.so.*.
- DECOUPLE --pq-box: it needs the SEPARATE libpqvaptvupt, which libvuptsdk does
  NOT provide, so gate it behind a new WITH_PQBOX=1 (was folded into WITH_SDK).
  zupt_crypto_pqbox.c now keys on ZUPT_WITH_PQBOX; WITH_SDK=1 alone builds and
  links cleanly with just libvuptsdk and enables --pq-sdk + Argon2id.
- Banner/help renamed libzuptsdk -> libvuptsdk; the machine-readable 'Build:'
  line lists --pq-box only under WITH_PQBOX. GUI _get_caps matches on 'vuptsdk'.

Validated on Guix: WITH_SDK=1 links libvuptsdk + libcrypto + libargon2, runs,
banner 'Build: full (libvuptsdk: Argon2id, --pq-sdk available)', keygen --sdk +
--pq-sdk encrypt/decrypt byte-exact roundtrip. Default source-only build
unchanged (make check 16/16).
2026-07-12 14:47:40 -03:00

77 lines
2.8 KiB
C

/*
* Zupt — Backup-oriented compression with AES-256 encryption
* Copyright (c) 2026 Cristian Cezar Moisés
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* ML-KEM-768 (FIPS 203, formerly CRYSTALS-Kyber).
* Post-quantum key encapsulation mechanism.
*
* Parameters (ML-KEM-768):
* k = 3, η₁ = 2, η₂ = 2, d_u = 10, d_v = 4
* Public key: 1184 bytes
* Secret key: 2400 bytes
* Ciphertext: 1088 bytes
* Shared secret: 32 bytes
*
* SECURITY NOTE: This implementation must undergo independent review
* before deployment in high-assurance contexts. It targets correctness
* against NIST test vectors and constant-time operation.
*/
#ifndef ZUPT_MLKEM_H
#define ZUPT_MLKEM_H
#include <stdint.h>
#include <stddef.h>
#define MLKEM_K 3
#define MLKEM_N 256
#define MLKEM_Q 3329
#define MLKEM_ETA1 2
#define MLKEM_ETA2 2
#define MLKEM_DU 10
#define MLKEM_DV 4
#define MLKEM_PUBLICKEYBYTES 1184
#define MLKEM_SECRETKEYBYTES 2400
#define MLKEM_CIPHERTEXTBYTES 1088
#define MLKEM_SSBYTES 32
/* KeyGen: generate public/secret keypair.
* pk: output public key (1184 bytes)
* sk: output secret key (2400 bytes)
* Returns 0 on success. */
int zupt_mlkem768_keygen(uint8_t pk[MLKEM_PUBLICKEYBYTES],
uint8_t sk[MLKEM_SECRETKEYBYTES]);
/* Encapsulate: produce ciphertext and shared secret from public key.
* ct: output ciphertext (1088 bytes)
* ss: output shared secret (32 bytes)
* pk: input public key (1184 bytes)
* Returns 0 on success, non-zero if pk fails the FIPS 203 §7.2
* encapsulation-key modulus check (malformed key). */
int zupt_mlkem768_encaps(uint8_t ct[MLKEM_CIPHERTEXTBYTES],
uint8_t ss[MLKEM_SSBYTES],
const uint8_t pk[MLKEM_PUBLICKEYBYTES]);
/* Decapsulate: recover shared secret from ciphertext and secret key.
* ss: output shared secret (32 bytes)
* ct: input ciphertext (1088 bytes)
* sk: input secret key (2400 bytes)
* Returns 0 on success.
* CT-REQUIRED: Implicit rejection — invalid ciphertext produces a
* pseudorandom shared secret (no distinguishable failure). */
int zupt_mlkem768_decaps(uint8_t ss[MLKEM_SSBYTES],
const uint8_t ct[MLKEM_CIPHERTEXTBYTES],
const uint8_t sk[MLKEM_SECRETKEYBYTES]);
/* FIPS 203 §7.2 encapsulation-key check (modulus check).
* Returns 0 iff `ek` is `len`==1184 bytes and every 12-bit coefficient is
* reduced mod q. Non-zero => malformed key; do not encapsulate against it. */
int zupt_mlkem768_check_ek(const uint8_t *ek, size_t len);
/* FIPS 203 §7.3 decapsulation-key check (hash check).
* Returns 0 iff `dk` is `len`==2400 bytes and the embedded H(ek) matches the
* SHA3-256 of the embedded encapsulation key. Non-zero => corrupt/forged key. */
int zupt_mlkem768_check_dk(const uint8_t *dk, size_t len);
#endif