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.
This commit is contained in:
1 parent
d4568326af
commit
86c744897b
19 files changed
+1371
-126
No files matched your search
+148
-6
@@ -81,7 +81,7 @@ struct _Identity_generate_cond
|
||||
char *genmem;
|
||||
};
|
||||
|
||||
void Identity::generate()
|
||||
void Identity::generate(bool pq, int pqcMode)
|
||||
{
|
||||
unsigned char digest[64];
|
||||
char *genmem = new char[ZT_IDENTITY_GEN_MEMORY];
|
||||
@@ -99,6 +99,28 @@ void Identity::generate()
|
||||
*_privateKey = kp.priv;
|
||||
|
||||
delete [] genmem;
|
||||
|
||||
// V12: mode off never carries v2 material; pqconly always does.
|
||||
// Hybrid leaves it to the caller (daemon passes a mode-derived flag once
|
||||
// Node::pqcMode is plumbed) so bare generate() stays classic.
|
||||
if (pqcMode == ZT_PQC_MODE_CLASSIC) {
|
||||
pq = false;
|
||||
}
|
||||
else if (pqcMode == ZT_PQC_MODE_PQCONLY) {
|
||||
pq = true;
|
||||
}
|
||||
// Identity type 1: ML-KEM-768 key exchange + ML-DSA-65 signature key pairs.
|
||||
// Address derivation stays over the C25519 material only (V10).
|
||||
if (pq) {
|
||||
if (! _pq) {
|
||||
_pq = new PQKeys();
|
||||
}
|
||||
if ((! PQHybrid::generateKeypair(_pq->mlkemPk, _pq->mlkemSk)) || (! PQHybrid::generateSigKeypair(_pq->mldsaPk, _pq->mldsaSk))) {
|
||||
Utils::burn(_pq, sizeof(PQKeys));
|
||||
delete _pq;
|
||||
_pq = (PQKeys*)0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Identity::locallyValidate() const
|
||||
@@ -130,7 +152,7 @@ char *Identity::toString(bool includePrivate,char buf[ZT_IDENTITY_STRING_BUFFER_
|
||||
Utils::hex10(_address.toInt(),p);
|
||||
p += 10;
|
||||
*(p++) = ':';
|
||||
*(p++) = '0';
|
||||
*(p++) = (_pq) ? '1' : '0';
|
||||
*(p++) = ':';
|
||||
Utils::hex(_publicKey.data,ZT_C25519_PUBLIC_KEY_LEN,p);
|
||||
p += ZT_C25519_PUBLIC_KEY_LEN * 2;
|
||||
@@ -139,6 +161,32 @@ char *Identity::toString(bool includePrivate,char buf[ZT_IDENTITY_STRING_BUFFER_
|
||||
Utils::hex(_privateKey->data,ZT_C25519_PRIVATE_KEY_LEN,p);
|
||||
p += ZT_C25519_PRIVATE_KEY_LEN * 2;
|
||||
}
|
||||
// Type 1 appends the public ML-KEM-768 + ML-DSA-65 keys, and, when the
|
||||
// private key is included, their private halves after it.
|
||||
if (_pq) {
|
||||
if ((_privateKey) && (includePrivate)) {
|
||||
*(p++) = ':';
|
||||
Utils::hex(_pq->mlkemPk, PQHybrid::MLKEM768_PK_LEN, p);
|
||||
p += PQHybrid::MLKEM768_PK_LEN * 2;
|
||||
*(p++) = ':';
|
||||
Utils::hex(_pq->mlkemSk, PQHybrid::MLKEM768_SK_LEN, p);
|
||||
p += PQHybrid::MLKEM768_SK_LEN * 2;
|
||||
*(p++) = ':';
|
||||
Utils::hex(_pq->mldsaPk, PQHybrid::MLDSA65_PK_LEN, p);
|
||||
p += PQHybrid::MLDSA65_PK_LEN * 2;
|
||||
*(p++) = ':';
|
||||
Utils::hex(_pq->mldsaSk, PQHybrid::MLDSA65_SK_LEN, p);
|
||||
p += PQHybrid::MLDSA65_SK_LEN * 2;
|
||||
}
|
||||
else {
|
||||
*(p++) = ':';
|
||||
Utils::hex(_pq->mlkemPk, PQHybrid::MLKEM768_PK_LEN, p);
|
||||
p += PQHybrid::MLKEM768_PK_LEN * 2;
|
||||
*(p++) = ':';
|
||||
Utils::hex(_pq->mldsaPk, PQHybrid::MLDSA65_PK_LEN, p);
|
||||
p += PQHybrid::MLDSA65_PK_LEN * 2;
|
||||
}
|
||||
}
|
||||
*p = (char)0;
|
||||
return buf;
|
||||
}
|
||||
@@ -155,8 +203,22 @@ bool Identity::fromString(const char *str)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Field counts are fixed per identity type, which removes any ambiguity
|
||||
// about whether field 3 is a private key or PQ material.
|
||||
int nfields = 1;
|
||||
for (const char* s = str; *s; ++s) {
|
||||
if (*s == ':') {
|
||||
++nfields;
|
||||
}
|
||||
}
|
||||
|
||||
delete _privateKey;
|
||||
_privateKey = (C25519::Private *)0;
|
||||
if (_pq) {
|
||||
Utils::burn(_pq, sizeof(PQKeys));
|
||||
delete _pq;
|
||||
_pq = (PQKeys*)0;
|
||||
}
|
||||
|
||||
int fno = 0;
|
||||
char *saveptr = (char *)0;
|
||||
@@ -170,7 +232,26 @@ bool Identity::fromString(const char *str)
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ((f[0] != '0')||(f[1])) {
|
||||
if (f[1]) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
if (f[0] == '0') {
|
||||
if ((nfields != 3) && (nfields != 4)) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (f[0] == '1') {
|
||||
// V10: a type 0 parser must reject this cleanly.
|
||||
if ((nfields != 5) && (nfields != 8)) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
_pq = new PQKeys();
|
||||
memset(_pq, 0, sizeof(PQKeys));
|
||||
}
|
||||
else {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
@@ -182,8 +263,69 @@ bool Identity::fromString(const char *str)
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
_privateKey = new C25519::Private();
|
||||
if (Utils::unhex(f,_privateKey->data,ZT_C25519_PRIVATE_KEY_LEN) != ZT_C25519_PRIVATE_KEY_LEN) {
|
||||
if ((_pq) && (nfields == 8)) {
|
||||
_privateKey = new C25519::Private();
|
||||
if (Utils::unhex(f, _privateKey->data, ZT_C25519_PRIVATE_KEY_LEN) != ZT_C25519_PRIVATE_KEY_LEN) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (_pq) {
|
||||
if (Utils::unhex(f, _pq->mlkemPk, PQHybrid::MLKEM768_PK_LEN) != PQHybrid::MLKEM768_PK_LEN) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
_privateKey = new C25519::Private();
|
||||
if (Utils::unhex(f, _privateKey->data, ZT_C25519_PRIVATE_KEY_LEN) != ZT_C25519_PRIVATE_KEY_LEN) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (! _pq) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
if (nfields == 5) {
|
||||
if (Utils::unhex(f, _pq->mldsaPk, PQHybrid::MLDSA65_PK_LEN) != PQHybrid::MLDSA65_PK_LEN) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (Utils::unhex(f, _pq->mlkemPk, PQHybrid::MLKEM768_PK_LEN) != PQHybrid::MLKEM768_PK_LEN) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if ((! _pq) || (nfields != 8)) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
if (Utils::unhex(f, _pq->mlkemSk, PQHybrid::MLKEM768_SK_LEN) != PQHybrid::MLKEM768_SK_LEN) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if ((! _pq) || (nfields != 8)) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
if (Utils::unhex(f, _pq->mldsaPk, PQHybrid::MLDSA65_PK_LEN) != PQHybrid::MLDSA65_PK_LEN) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if ((! _pq) || (nfields != 8)) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
if (Utils::unhex(f, _pq->mldsaSk, PQHybrid::MLDSA65_SK_LEN) != PQHybrid::MLDSA65_SK_LEN) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
@@ -193,7 +335,7 @@ bool Identity::fromString(const char *str)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (fno < 3) {
|
||||
if ((fno < 3) || (fno != nfields)) {
|
||||
_address.zero();
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user