Sign in

    justinwongcn/moonpgp/cipher does not have a README file

    AeadMode

    pub(all) enum AeadMode {
    Eax
    Ocb
    Gcm
    } derive(Eq,
    Debug
    )

    AEAD algorithm IDs (RFC 9580 §9.6).

    AeadMode::equal

    fn AeadMode::equal(AeadMode, AeadMode) -> Bool

    AeadMode::iv_length

    fn AeadMode::iv_length(self : AeadMode) -> Int

    IV/nonce length of the mode (RFC 9580 §9.6).

    AeadMode::not_equal

    fn AeadMode::not_equal(x : AeadMode, y : AeadMode) -> Bool

    AeadMode::number

    fn AeadMode::number(self : AeadMode) -> Int

    AeadMode::tag_length

    fn AeadMode::tag_length(_self : AeadMode) -> Int

    Tag length — 16 octets for every registered mode.

    AeadMode::to_repr

    aead_chunk_size

    fn aead_chunk_size(chunk_octet : Int) -> Int64 raise

    Chunk size for the chunk-size octet: 2^(c + 6) octets. Computed as an Int64 (Int is 32 bits here and the octet can encode up to 2^56); callers clamp it against the remaining payload.

    aead_mode_of_number

    fn aead_mode_of_number(n : Int) -> AeadMode?

    aead_open

    fn aead_open(bc : &
    BlockCipher
    , mode : AeadMode, header5 : BytesView, iv : BytesView, chunk_octet : Int, cipher : BytesView) -> Bytes raise

    Open a full AEAD payload (the inverse of aead_seal). The final tag must verify against the total plaintext length; any chunk tag failure raises.

    aead_seal

    fn aead_seal(bc : &
    BlockCipher
    , mode : AeadMode, header5 : BytesView, iv : BytesView, chunk_octet : Int, plain : BytesView) -> Bytes raise

    Seal a full AEAD payload (the OpenPGP chunk layer). header5 is 0xD4 | version | cipher | aead | chunk-octet; iv is the packet IV. Returns the packet body tail: chunk ciphertexts+tags followed by the final tag. An empty payload still produces one empty chunk tag plus the final tag (what go-crypto/OpenPGP.js emit).

    aes_key_unwrap

    fn aes_key_unwrap(kek : BytesView, ciphertext : BytesView) -> Bytes raise

    Unwrap an RFC 3394 key-wrap ciphertext; raises when the integrity check value (the unwrapped A) does not match the default IV.

    aes_key_wrap

    fn aes_key_wrap(kek : BytesView, plaintext : BytesView) -> Bytes raise

    Wrap plaintext (a positive multiple of 8 octets) under kek, returning (n+1) 8-octet blocks.

    cfb_decrypt

    fn cfb_decrypt(bc : &
    BlockCipher
    , iv : BytesView, data : BytesView) -> Bytes raise

    Full-block CFB decryption with a caller-provided IV. The final block may be partial.

    cfb_encrypt

    fn cfb_encrypt(bc : &
    BlockCipher
    , iv : BytesView, data : BytesView) -> Bytes raise

    Full-block CFB encryption (NIST SP 800-38A CFB128) with a caller-provided IV. The final block may be partial; only the needed keystream octets are consumed.

    eax_decrypt

    fn eax_decrypt(bc : &
    BlockCipher
    , nonce : BytesView, ad : BytesView, cipher : BytesView) -> Bytes raise

    EAX decrypt: cipher is ciphertext || tag; the tag must verify.

    eax_encrypt

    fn eax_encrypt(bc : &
    BlockCipher
    , nonce : BytesView, ad : BytesView, plain : BytesView) -> Bytes raise

    EAX encrypt: returns ciphertext || tag.

    Example

    test {
    // RFC 9580 §5.13.3 mode/IV/tag sizes.
    inspect(@cipher.Eax.iv_length(), content="16")
    inspect(@cipher.Eax.tag_length(), content="16")
    }

    gcm_decrypt

    fn gcm_decrypt(bc : &
    BlockCipher
    , iv : BytesView, ad : BytesView, cipher : BytesView) -> Bytes raise

    GCM-DECRYPT (SP 800-38D §7.2). cipher is ciphertext || 16-octet tag; raises when the tag does not verify, and only then is no plaintext returned.

    gcm_encrypt

    fn gcm_encrypt(bc : &
    BlockCipher
    , iv : BytesView, ad : BytesView, plain : BytesView) -> Bytes raise

    GCM-ENCRYPT (SP 800-38D §7.1). Returns ciphertext || 16-octet tag.

    ocb_decrypt

    fn ocb_decrypt(bc : &
    BlockCipher
    , nonce : BytesView, ad : BytesView, cipher : BytesView) -> Bytes raise

    OCB-DECRYPT (RFC 7253 §4.3). cipher is ciphertext || 16-octet tag; raises when the tag does not verify, and only then is no plaintext returned.

    ocb_encrypt

    fn ocb_encrypt(bc : &
    BlockCipher
    , nonce : BytesView, ad : BytesView, plain : BytesView, tag_len? : Int) -> Bytes raise

    OCB-ENCRYPT (RFC 7253 §4.2). Returns ciphertext || tag (tag_len octets, default 16 as OpenPGP requires).

    openpgp_cfb_decrypt_resync

    fn openpgp_cfb_decrypt_resync(bc : &
    BlockCipher
    , ciphertext : BytesView) -> Bytes raise

    Decrypt the resynchronized OpenPGP CFB variant. Verifies the two check octets of the prefix and returns the data (prefix stripped).

    openpgp_cfb_encrypt_resync

    fn openpgp_cfb_encrypt_resync(bc : &
    BlockCipher
    , prefix : BytesView, data : BytesView) -> Bytes raise

    Encrypt with the legacy OpenPGP CFB variant used by the obsolete Symmetrically Encrypted Data packet (tag 9): the 18-octet prefix is encrypted in one CFB context with an all-zero IV, then the CFB state is resynchronized with the last block-size octets of ciphertext (RFC 9580 §5.7).

    random_prefix

    fn random_prefix(bs : Int) -> Bytes raise

    The random prefix of SEIPD v1 / OpenPGP CFB: bs random octets then a copy of the last two (RFC 9580 §5.13.1). bs is the block size of the session-key cipher — 16 for AES but 8 for the legacy CAST5/3DES, where the old hardcoded 16 quietly produced an invalid prefix.

    seipd_v1_decrypt

    fn seipd_v1_decrypt(bc : &
    BlockCipher
    , ciphertext : BytesView) -> Bytes raise

    Decrypt and integrity-check a SEIPD v1 ciphertext. Returns the inner packet stream (prefix and MDC stripped). Raises when the quick check octets or the MDC do not match.

    seipd_v1_encrypt

    fn seipd_v1_encrypt(bc : &
    BlockCipher
    , inner : BytesView) -> Bytes raise

    Build and encrypt the plaintext of a SEIPD v1 packet (RFC 9580 §5.13.1): random prefix (bs+2 octets) || inner packets || 0xD3 0x14 || SHA-1 MDC, all in one CFB context with an all-zero IV and no resynchronization.

    seipd_v2_kdf

    fn seipd_v2_kdf(session_key : BytesView, salt : BytesView, key_len : Int, mode : AeadMode, header5 : BytesView) -> (Bytes, Bytes) raise

    Derive the message key and the fixed part of the AEAD nonce for a v2 SEIPD (RFC 9580 §5.13.2): HKDF-SHA256 with the session key as IKM, the packet salt as salt, and 0xD2 | version | cipher | aead | chunk (the packet header, header5) as info. The leftmost key_len octets are the message key; the remaining mode.iv_length() - 8 are the nonce prefix, whose low 64 bits carry the chunk index.

    seipd_v2_open

    fn seipd_v2_open(bc : &
    BlockCipher
    , mode : AeadMode, header5 : BytesView, iv : BytesView, chunk_octet : Int, cipher : BytesView) -> Bytes raise

    Open a v2 SEIPD payload (the inverse of seipd_v2_seal). Every chunk tag and the final tag must verify.

    seipd_v2_seal

    fn seipd_v2_seal(bc : &
    BlockCipher
    , mode : AeadMode, header5 : BytesView, iv : BytesView, chunk_octet : Int, plain : BytesView) -> Bytes raise

    Seal a v2 SEIPD payload. header5 is 0xD2 | 0x02 | cipher | aead | chunk-octet; iv is the HKDF nonce prefix (mode.iv_length() - 8 octets). Returns the packet tail: chunk ciphertexts+tags followed by the final tag.