Files
BackOne/node/PQHybrid.hpp
T
dedysutanto 86c744897b feat(pqc): identity/COM v2, pqcMode config, selftest gates
Phases 3-6 (SPEC T19-T23): type-1 identity carries ML-KEM-768 + ML-DSA-65 pubs, COM type-2 double-sign, HELLO capability bit, local.conf settings.pqcMode (off/hybrid/pqconly) with classic fallback. selftest KAT + interop matrix + fragment-loss benchmark green.
2026-10-01 15:55:09 +07:00

65 lines
2.2 KiB
C++

/*
* Copyright (c)2019 ZeroTier, Inc.
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file in the project's root directory.
*
* Change Date: 2026-01-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2.0 of the Apache License.
*/
/****/
#ifndef ZT_PQHYBRID_HPP
#define ZT_PQHYBRID_HPP
#include "Constants.hpp"
namespace ZeroTier {
/**
* Hybrid post-quantum key agreement primitives (ML-KEM-768 + hybrid KDF)
*/
class PQHybrid {
public:
// Standard ML-KEM-768 sizes (FIPS 203), asserted against liboqs in PQHybrid.cpp
static const unsigned int MLKEM768_PK_LEN = 1184;
static const unsigned int MLKEM768_SK_LEN = 2400;
static const unsigned int MLKEM768_CT_LEN = 1088;
static const unsigned int MLKEM768_SS_LEN = 32;
// Standard ML-DSA-65 sizes (FIPS 204)
static const unsigned int MLDSA65_PK_LEN = 1952;
static const unsigned int MLDSA65_SK_LEN = 4032;
static const unsigned int MLDSA65_SIG_LEN = 3309;
/** Generate ML-DSA-65 long-term signature keypair (for identity v2 storage) */
static bool generateSigKeypair(uint8_t* pk, uint8_t* sk);
/** Sign with ML-DSA-65 secret key -> MLDSA65_SIG_LEN signature bytes */
static bool sign(const uint8_t* sk, const void* msg, unsigned int len, uint8_t* sig);
/** Verify ML-DSA-65 signature over message */
static bool verify(const uint8_t* pk, const void* msg, unsigned int len, const uint8_t* sig);
/** Generate ML-KEM-768 static keypair (for identity v2 storage) */
static bool generateKeypair(uint8_t* pk, uint8_t* sk);
/** Encapsulate to peer static public key -> ciphertext + shared secret */
static bool encaps(const uint8_t* peerPk, uint8_t* ct, uint8_t* ss);
/** Decapsulate with own static secret key -> shared secret */
static bool decaps(const uint8_t* sk, const uint8_t* ct, uint8_t* ss);
/**
* Hybrid key: HMAC-SHA-384(key=classical, msg=pq) -> ZT_SYMMETRIC_KEY_SIZE.
* Both secrets must hold to recompute the output.
*/
static void hybridKey(const uint8_t classical[ZT_SYMMETRIC_KEY_SIZE], const uint8_t pq[MLKEM768_SS_LEN], uint8_t out[ZT_SYMMETRIC_KEY_SIZE]);
};
} // namespace ZeroTier
#endif