derive
Derives Sender Key, Recipient Key and Common IV with HKDF (RFC 8613 §3.2.1) and restores the Sender Sequence Number from sequenceStore (Appendix B.1.1).
sequenceStore has no default, because the safe choice depends on where the keys come from:
A provisioned Master Secret that outlives the process needs a durable store. With EphemeralSequenceNumberStore a restarted process starts at sequence number 0 again and reuses AEAD nonces, which breaks the confidentiality and integrity of AES-CCM.
Keys that are new in this process run, such as EDHOC output, use EphemeralSequenceNumberStore.
At most one live context may exist per store and context name. Deriving again from the same store, after a restart or within the process, is a restore: it is safe only once the previous context for these parameters is discarded and no call is still running on it. A context still in use goes on handing out numbers from the block it reserved, and the new one reserves the next block, which the old one reaches later: the same nonce under the same Sender Key. Two derivations that run at the same time both find no value and both start at
The library does not detect either case.
The store is read, and a new context recorded, before any key exists, so a failing store leaves no key material behind. When the backend cannot build the AEAD, the derived keys and the Common IV are wiped before the exception reaches the caller.
Parameters
where the Sender Sequence Number is persisted; see SequenceNumberStore.
how many sequence numbers to reserve per write to sequenceStore (K in Appendix B.1.1), from 1 to 2^40. A restart skips at most this many numbers.
whether the replay window is trusted from the start or only after a request proved its freshness with Echo (Appendix B.1.2). FreshnessPolicy.AUTO requires the proof for a context restored from sequenceStore and for any store but the ephemeral one.
who the peer of the context is, for authorization (SecurityContext.identity); null for its OscoreIdentity.
Throws
when persistInterval is out of range, or sequenceStore returns a value outside 0 to 2^40. Exceptions of sequenceStore and of crypto reach the caller unchanged. When the first write for a new context throws after it became durable, the next derivation counts as a restore. @Throws lists KcoapException and CancellationException, as on kcoap's other entry points, so Swift calls it with try; the exceptions named here are not in that list, and on Apple platforms they end the process, as a failed precondition does.