(*--------------------------------------------------------------------------- Copyright (c) 2025 Thomas Gazagnaire. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) (** CCSDS security algorithms (CCSDS 350.0-B, 352.0-B). This module holds the encryption, authentication and key derivation algorithms of the CCSDS security algorithm registry, with their registry identifiers. {!Sa.type-ecs} and {!Sa.type-acs} number the algorithms of an SA configuration differently, as SDLS 355.0-B-2 does. *) (** {1 Encryption Algorithms} *) (** The type for encryption algorithms. *) type encryption = | AES_128_GCM (** Algorithm ID 0x01 *) | AES_256_GCM (** Algorithm ID 0x02 *) | AES_128_CCM (** Algorithm ID 0x03 *) | AES_256_CCM (** Algorithm ID 0x04 *) val encryption_of_int : int -> encryption option (** [encryption_of_int n] is the encryption algorithm with identifier [n], and [None] if none has it. *) val int_of_encryption : encryption -> int (** [int_of_encryption e] is the identifier of [e]. *) val pp_encryption : encryption Fmt.t (** [pp_encryption] formats an encryption algorithm. *) (** {1 Authentication Algorithms} *) (** The type for authentication algorithms. *) type authentication = | AES_128_CMAC (** Algorithm ID 0x01 *) | AES_256_CMAC (** Algorithm ID 0x02 *) | HMAC_SHA_256 (** Algorithm ID 0x03 *) | HMAC_SHA_384 (** Algorithm ID 0x04 *) | HMAC_SHA_512 (** Algorithm ID 0x05 *) val authentication_of_int : int -> authentication option (** [authentication_of_int n] is the authentication algorithm with identifier [n], and [None] if none has it. *) val int_of_authentication : authentication -> int (** [int_of_authentication a] is the identifier of [a]. *) val pp_authentication : authentication Fmt.t (** [pp_authentication] formats an authentication algorithm. *) (** {1 Key Derivation Functions (CCSDS 352.0-B)} *) (** The type for key derivation functions. *) type key_derivation = | HKDF_SHA_256 (** The HMAC-based KDF of CCSDS 352.0-B. *) | PBKDF2_SHA_256 (** The password-based KDF of CCSDS 352.0-B. *) val pp_key_derivation : key_derivation Fmt.t (** [pp_key_derivation] formats a key derivation function. *) (** {1 Algorithm Suites} A suite combines an encryption and an authentication algorithm with their lengths, for the configuration of an SA. *) type suite = { encryption : encryption; authentication : authentication; key_len : int; (** The key length in bytes. *) iv_len : int; (** The IV or nonce length in bytes. *) mac_len : int; (** The tag length in bytes. *) } (** The type for algorithm suites. *) val aes_128_gcm_cmac : suite (** [aes_128_gcm_cmac] is AES-128-GCM encryption with AES-128-CMAC authentication. *) val aes_256_gcm_cmac : suite (** [aes_256_gcm_cmac] is AES-256-GCM encryption with AES-256-CMAC authentication. *) val aes_256_gcm_hmac_256 : suite (** [aes_256_gcm_hmac_256] is AES-256-GCM encryption with HMAC-SHA-256 authentication. *) val aes_256_ccm_hmac_256 : suite (** [aes_256_ccm_hmac_256] is AES-256-CCM encryption with HMAC-SHA-256 authentication. *) val pp_suite : suite Fmt.t (** [pp_suite] formats an algorithm suite. *) (** {1 SA Negotiation} The two ends of an SA agree on its algorithms during its establishment, in the key management procedures of SDLS-EP (CCSDS 355.1-B-1). *) type proposal = { encryptions : encryption list; (** The encryption algorithms offered. *) authentications : authentication list; (** The authentication algorithms offered. *) key_derivations : key_derivation list; (** The KDFs offered. *) } (** The type for algorithm proposals, in order of preference. *) type selection = { encryption : encryption; authentication : authentication; key_derivation : key_derivation option; } (** The type for negotiated algorithms. *) val negotiate : proposal -> proposal -> selection option (** [negotiate initiator responder] is the first encryption, the first authentication and the first KDF of [initiator] that [responder] also offers, and [None] when they share no encryption or no authentication algorithm. The KDF is [None] when they share none. *) val pp_proposal : proposal Fmt.t (** [pp_proposal] formats a proposal. *) val pp_selection : selection Fmt.t (** [pp_selection] formats a selection. *)