Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / apple / XCFramework / e2ee_pqc.reference.h
e2ee_pqc.reference.h84 lines · 3.7 KiBRaw
| 1 | /* EverySync — reference C header for the 10 bound PQC functions. |
| 2 | * |
| 3 | * Generated from `library/e2ee-p2p/src/main/rust/src/c_bridge.rs` via |
| 4 | * cbindgen at Rust build time (see BUILD_NOTES.md step 2). This REFERENCE |
| 5 | * copy pins the exact signatures the Kotlin cinterop actual + the `.def` |
| 6 | * bind — the live `e2ee_pqc.h` lands next to `e2eePqc.def` on the Mac. |
| 7 | * |
| 8 | * Conventions (from c_bridge.rs): |
| 9 | * - Return 1 on success / 0 on failure, EXCEPT pqc_dsa_verify: |
| 10 | * 1 = valid, 0 = invalid, -1 = parse error. |
| 11 | * - Every `out` buffer is Box::into_raw: caller copies, then pqc_free. |
| 12 | * - Priv/SS bytes must be zeroed with pqc_secure_zero after use. |
| 13 | * - Lengths are size_t (cbindgen `usize_is_size_t = true`). |
| 14 | */ |
| 15 | #ifndef EVERYSYNC_PQC_REFERENCE_H |
| 16 | #define EVERYSYNC_PQC_REFERENCE_H |
| 17 | |
| 18 | #include <stddef.h> |
| 19 | #include <stdint.h> |
| 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | /* Frees a buffer previously returned through an out-param. */ |
| 26 | void pqc_free(uint8_t *ptr, size_t len); |
| 27 | |
| 28 | /* Best-effort secure zero of a buffer (private keys / shared secrets). */ |
| 29 | void pqc_secure_zero(uint8_t *ptr, size_t len); |
| 30 | |
| 31 | /* ML-KEM-768 keypair. Out params filled on success (caller frees via pqc_free). */ |
| 32 | int32_t pqc_kem_keygen(uint8_t **pub_out, size_t *pub_len_out, |
| 33 | uint8_t **priv_out, size_t *priv_len_out); |
| 34 | |
| 35 | /* ML-DSA-65 keypair. Out params filled on success (caller frees). */ |
| 36 | int32_t pqc_dsa_keygen(uint8_t **pub_out, size_t *pub_len_out, |
| 37 | uint8_t **priv_out, size_t *priv_len_out); |
| 38 | |
| 39 | /* Public bundle: len_prefix(kem_pub, dsa_pub) = [4B BE len][kem][dsa]. */ |
| 40 | int32_t pqc_bundle_build(const uint8_t *kem_pub, size_t kem_pub_len, |
| 41 | const uint8_t *dsa_pub, size_t dsa_pub_len, |
| 42 | uint8_t **out, size_t *out_len); |
| 43 | |
| 44 | /* Splits a public bundle (caller frees each half via pqc_free). */ |
| 45 | int32_t pqc_bundle_split(const uint8_t *bundle, size_t bundle_len, |
| 46 | uint8_t **kem_pub_out, size_t *kem_pub_len_out, |
| 47 | uint8_t **dsa_pub_out, size_t *dsa_pub_len_out); |
| 48 | |
| 49 | /* Encapsulates to a KEM public DER: (ciphertext(1088), sharedSecret(32)). */ |
| 50 | int32_t pqc_kem_encaps(const uint8_t *kem_pub, size_t kem_pub_len, |
| 51 | uint8_t **ct_out, size_t *ct_len_out, |
| 52 | uint8_t **ss_out, size_t *ss_len_out); |
| 53 | |
| 54 | /* Decapsulates with a KEM private DER + ciphertext -> sharedSecret(32). */ |
| 55 | int32_t pqc_kem_decaps(const uint8_t *kem_priv, size_t kem_priv_len, |
| 56 | const uint8_t *ct, size_t ct_len, |
| 57 | uint8_t **ss_out, size_t *ss_len_out); |
| 58 | |
| 59 | /* Signs with a DSA private DER. */ |
| 60 | int32_t pqc_dsa_sign(const uint8_t *dsa_priv, size_t dsa_priv_len, |
| 61 | const uint8_t *msg, size_t msg_len, |
| 62 | uint8_t **sig_out, size_t *sig_len_out); |
| 63 | |
| 64 | /* Verifies with a DSA public DER: 1 valid / 0 invalid / -1 parse error. */ |
| 65 | int32_t pqc_dsa_verify(const uint8_t *dsa_pub, size_t dsa_pub_len, |
| 66 | const uint8_t *msg, size_t msg_len, |
| 67 | const uint8_t *sig, size_t sig_len); |
| 68 | |
| 69 | /* CryptoKit AES-GCM bridge (../Shared/EverysyncCoreCrypto.swift). |
| 70 | * Same Box::into_raw discipline, freed via everysync_crypto_free. |
| 71 | * Layout: [12B nonce][ciphertext][16B tag] (== SealedBox.combined). */ |
| 72 | int32_t everysync_aes_gcm_encrypt(const uint8_t *key, size_t key_len, |
| 73 | const uint8_t *pt, size_t pt_len, |
| 74 | uint8_t **out, size_t *out_len); |
| 75 | int32_t everysync_aes_gcm_decrypt(const uint8_t *key, size_t key_len, |
| 76 | const uint8_t *ct, size_t ct_len, |
| 77 | uint8_t **out, size_t *out_len); |
| 78 | void everysync_crypto_free(uint8_t *ptr, size_t len); |
| 79 | |
| 80 | #ifdef __cplusplus |
| 81 | } |
| 82 | #endif |
| 83 | |
| 84 | #endif /* EVERYSYNC_PQC_REFERENCE_H */ |