java.lang.Object
net.i2p.crypto.SessionKeyManager
net.i2p.router.crypto.ratchet.MuxedPQSKM
Post-quantum hybrid session key manager combining ECIES and ML-KEM operations.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final RatchetSKMThe ratcheted ECIES session keys.private final AtomicIntegerCounts the ECIES keys handed out.private final LogLogger for this class.private final RatchetSKMThe ratcheted post-quantum session keys.private final AtomicIntegerCounts the post-quantum keys handed out.(package private) static final intHow much slower the PQ slow decrypt is than the ratchet one, so its success count is divided by this much before the two are compared.(package private) static final intSize of the sampling window.Constructor Summary
ConstructorsConstructorDescriptionMuxedPQSKM(RatchetSKM ec, RatchetSKM pq) Combines ECIES and PQ SKMs with adaptive decrypt ordering.Method Summary
Modifier and TypeMethodDescriptionconsumeNextAvailableTag(PublicKey target) EC/PQ.consumeNextAvailableTag(PublicKey target, SessionKey key) ElG only.consumeTag(SessionTag tag) Tries ECIES tag lookup first, falls back to PQ lookup.createSession(PublicKey target) ElG only.voidcreateSession(PublicKey target, SessionKey key) ElG only.voidfailTags(PublicKey target, SessionKey key, TagSetHandle ts) ElG only.intgetAvailableTags(PublicKey target, SessionKey key) Delegates to the appropriate key manager by encryption type.longgetAvailableTimeLeft(PublicKey target, SessionKey key) Delegates to the appropriate key manager by encryption type.getCurrentKey(PublicKey target) ElG only.getCurrentOrNewKey(PublicKey target) ElG only.long[]Sums the debug stats of both key managers, null if neither tracks them.getECSKM()The ECIES ratchet key manager combined into this hybrid.intNot used; thresholds are not used for ratchet sessions.getPQSKM()The post-quantum ratchet key manager combined into this hybrid.intNot used; tag management is handled by the ratchet protocol.(package private) static booleanneedsRestart(int ec, int pq) Whether the sampling window is full and both counters should start over, so the ordering tracks recent traffic rather than the whole session.(package private) booleanShould we try the Ratchet slow decrypt before PQ slow decrypt? Adaptive test based on previous mix of traffic for this SKM, as reported by reportDecryptResult().(package private) static booleanpreferRatchet(int ec, int pq) The ordering the current window favours, with the PQ count discounted because the ratchet slow decrypt is the cheaper of the two to try first.(package private) booleanThe ordering the current window favours, without rolling the sampling window over.voidrenderStatusHTML(Writer out) Renders debug status for both key managers.(package private) voidreportDecryptResult(boolean isRatchet, boolean success) Report the result of a slow decrypt attempt.(package private) static booleanrollOver(AtomicInteger counter, int expected) Reset one counter to start a fresh window, only if nothing was recorded since the value the decision was taken on.booleanshouldSendTags(PublicKey target, SessionKey key) ElG only.booleanshouldSendTags(PublicKey target, SessionKey key, int lowThreshold) ElG only.voidshutdown()Shuts down both ECIES and PQ key managers.voidtagsAcked(PublicKey target, SessionKey key, TagSetHandle ts) ElG only.tagsDelivered(PublicKey target, SessionKey key, Set<SessionTag> sessionTags) ElG only.voidtagsReceived(SessionKey key, Set<SessionTag> sessionTags) ElG only.voidtagsReceived(SessionKey key, Set<SessionTag> sessionTags, long expire) ElG only.voidtagsReceived(SessionKey key, RatchetSessionTag tag, long expire) EC only.Methods inherited from class SessionKeyManager
failTags
Field Details
_ec
The ratcheted ECIES session keys._pq
The ratcheted post-quantum session keys._ecCounter
Counts the ECIES keys handed out._pqCounter
Counts the post-quantum keys handed out._log
Logger for this class.PQ_SLOW_FACTOR
static final int PQ_SLOW_FACTORHow much slower the PQ slow decrypt is than the ratchet one, so its success count is divided by this much before the two are compared.- See Also:
RESTART_COUNTERS
static final int RESTART_COUNTERSSize of the sampling window. Once both counters are individually meaningful and their sum passes this, the window rolls over so the ordering tracks recent traffic instead of the whole session.- See Also:
Constructor Details
MuxedPQSKM
Combines ECIES and PQ SKMs with adaptive decrypt ordering.- Parameters:
ec- the ECIES ratchet key managerpq- the post-quantum ratchet key manager
Method Details
getECSKM
The ECIES ratchet key manager combined into this hybrid.- Returns:
- the ECIES ratchet key manager
getPQSKM
The post-quantum ratchet key manager combined into this hybrid.- Returns:
- the post-quantum ratchet key manager
preferRatchet
boolean preferRatchet()Should we try the Ratchet slow decrypt before PQ slow decrypt? Adaptive test based on previous mix of traffic for this SKM, as reported by reportDecryptResult().- Returns:
- true if the Ratchet decrypt is tried first, false for PQ
preferRatchetNow
boolean preferRatchetNow()The ordering the current window favours, without rolling the sampling window over. Reporting has to use this rather than preferRatchet(): a log line that resets the counters changes which decrypt the next message tries first, and the value it prints is not the one that decision used.- Returns:
- true if the Ratchet decrypt would be tried first right now
needsRestart
static boolean needsRestart(int ec, int pq) Whether the sampling window is full and both counters should start over, so the ordering tracks recent traffic rather than the whole session.- Parameters:
ec- successful ratchet decrypts in the current windowpq- successful PQ decrypts in the current window- Returns:
- true if the window has run its course
preferRatchet
static boolean preferRatchet(int ec, int pq) The ordering the current window favours, with the PQ count discounted because the ratchet slow decrypt is the cheaper of the two to try first.- Parameters:
ec- successful ratchet decrypts in the current windowpq- successful PQ decrypts in the current window- Returns:
- true if the ratchet slow decrypt should go first
rollOver
Reset one counter to start a fresh window, only if nothing was recorded since the value the decision was taken on. A plain set(0) would discard any success logged between that read and the reset, which is how the counters used to lose counts under concurrent decrypts.- Parameters:
counter- the counter to roll overexpected- the value read when the decision was taken- Returns:
- true if the counter was reset, false if it moved in the meantime
reportDecryptResult
void reportDecryptResult(boolean isRatchet, boolean success) Report the result of a slow decrypt attempt.- Parameters:
isRatchet- true for EC, false for PQsuccess- true for successful decrypt
getCurrentKey
ElG only.- Overrides:
getCurrentKeyin classSessionKeyManager- Parameters:
target- the destination whose current session key is wanted- Returns:
- the current key
getCurrentOrNewKey
ElG only.- Overrides:
getCurrentOrNewKeyin classSessionKeyManager- Parameters:
target- the destination to start or continue a session with- Returns:
- the current or new key
createSession
ElG only.- Overrides:
createSessionin classSessionKeyManager- Parameters:
target- the destination the session is established withkey- the session key to associate, whose expiry metrics start at this call
createSession
ElG only.- Overrides:
createSessionin classSessionKeyManager- Parameters:
target- the destination to establish a freshly generated session with- Returns:
- the session key
consumeNextAvailableTag
ElG only.- Overrides:
consumeNextAvailableTagin classSessionKeyManager- Parameters:
target- the destination the tag was sent tokey- the session key whose use the tag identifies- Returns:
- the next available tag, or null
consumeNextAvailableTag
EC/PQ.- Parameters:
target- the target peer's ephemeral key; its type picks the SKM- Returns:
- the next available tag, or null
getTagsToSend
public int getTagsToSend()Not used; tag management is handled by the ratchet protocol.- Overrides:
getTagsToSendin classSessionKeyManager- Returns:
- 0, tag management is handled by ratchet protocol
getLowThreshold
public int getLowThreshold()Not used; thresholds are not used for ratchet sessions.- Overrides:
getLowThresholdin classSessionKeyManager- Returns:
- 0, threshold not used for ratchet sessions
shouldSendTags
ElG only.- Overrides:
shouldSendTagsin classSessionKeyManager- Parameters:
target- the destination whose tags are being consideredkey- the session key- Returns:
- whether send tags
shouldSendTags
ElG only.- Overrides:
shouldSendTagsin classSessionKeyManager- Parameters:
target- the destination whose tags are being consideredkey- the session keylowThreshold- the low threshold- Returns:
- whether send tags
getAvailableTags
Delegates to the appropriate key manager by encryption type.- Overrides:
getAvailableTagsin classSessionKeyManager- Parameters:
target- the destination the tags were sent tokey- the session key those tags were issued under- Returns:
- the available tags
getAvailableTimeLeft
Delegates to the appropriate key manager by encryption type.- Overrides:
getAvailableTimeLeftin classSessionKeyManager- Parameters:
target- the destination the tags were sent tokey- the session key those tags were issued under- Returns:
- the available time left
tagsDelivered
ElG only.- Overrides:
tagsDeliveredin classSessionKeyManager- Parameters:
target- the destination that acknowledged the tagskey- the session key the acknowledged tags were issued undersessionTags- modifiable; NOT copied- Returns:
- the tag set handle
tagsReceived
ElG only.- Overrides:
tagsReceivedin classSessionKeyManager- Parameters:
key- the session key the tags were received forsessionTags- modifiable; NOT copied
tagsReceived
ElG only.- Overrides:
tagsReceivedin classSessionKeyManager- Parameters:
key- the session key the tags were received forsessionTags- modifiable; NOT copiedexpire- time from now
tagsReceived
EC only. One time session We do not support PQ one-time sessions on MuxedPQSKM.- Parameters:
key- the session key the tag was received undertag- the ratchet session tag to store for the sessionexpire- time from now
consumeTag
Tries ECIES tag lookup first, falls back to PQ lookup.- Overrides:
consumeTagin classSessionKeyManager- Parameters:
tag- the session tag whose delivered key is consumed- Returns:
- the session key, or null
shutdown
public void shutdown()Shuts down both ECIES and PQ key managers.- Overrides:
shutdownin classSessionKeyManager
renderStatusHTML
Renders debug status for both key managers.- Overrides:
renderStatusHTMLin classSessionKeyManager- Parameters:
out- the writer to render to- Throws:
IOException- if an I/O error occurs
getDebugStats
public long[] getDebugStats()Sums the debug stats of both key managers, null if neither tracks them.- Overrides:
getDebugStatsin classSessionKeyManager- Returns:
- the stats, or null
failTags
ElG only.- Overrides:
failTagsin classSessionKeyManager- Parameters:
target- the destination whose tags are being consideredkey- the session keyts- the tag set handle
tagsAcked
ElG only.- Overrides:
tagsAckedin classSessionKeyManager- Parameters:
target- the destination whose tags are being consideredkey- the session keyts- the tag set handle