|
| 1 | +package org.bouncycastle.tls.crypto; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | + |
| 5 | +/** |
| 6 | + * The optional DTLS 1.3 (RFC 9147) record protection extension to {@link TlsCipher}, implemented by ciphers |
| 7 | + * that can protect DTLS 1.3 records. |
| 8 | + */ |
| 9 | +public interface TlsDTLS13Cipher |
| 10 | +{ |
| 11 | + /** |
| 12 | + * Encode the passed in plaintext as a DTLS 1.3 protected record (RFC 9147 4). The supplied unified header is |
| 13 | + * the AEAD additional data; when its L bit is set the (zeroed) length field is filled in by this method. The |
| 14 | + * returned record holds the header, with record number encryption (RFC 9147 4.2.3) applied to its sequence |
| 15 | + * number bytes, followed by the encrypted record. |
| 16 | + * |
| 17 | + * @param seqNo the 64-bit record sequence number (the epoch is not included, unlike DTLS 1.2). |
| 18 | + * @param contentType the true content type, written into the DTLSInnerPlaintext. |
| 19 | + * @param header array holding the unified header with the sequence number in the clear. |
| 20 | + * @param headerOff offset of the header in the array. |
| 21 | + * @param headerLen length of the header. |
| 22 | + * @param plaintext array holding input plaintext to the cipher. |
| 23 | + * @param offset offset into input array the plaintext starts at. |
| 24 | + * @param len length of the plaintext in the array. |
| 25 | + * @return A {@link TlsEncodeResult} whose buffer holds the complete record (header followed by ciphertext), |
| 26 | + * with 'recordType' set to the first byte of the unified header. |
| 27 | + * @throws IOException |
| 28 | + */ |
| 29 | + TlsEncodeResult encodeDTLS13Plaintext(long seqNo, short contentType, byte[] header, int headerOff, int headerLen, |
| 30 | + byte[] plaintext, int offset, int len) throws IOException; |
| 31 | + |
| 32 | + /** |
| 33 | + * Decrypt (in place) the record number of a received DTLS 1.3 protected record (RFC 9147 4.2.3). The record |
| 34 | + * starts with its unified header; at least 16 bytes of ciphertext must follow the header. |
| 35 | + * |
| 36 | + * @param record array holding the received record. |
| 37 | + * @param recordOff offset of the record (its unified header) in the array. |
| 38 | + * @param recordLen length of the record. |
| 39 | + * @throws IOException |
| 40 | + */ |
| 41 | + void decryptDTLS13RecordNumber(byte[] record, int recordOff, int recordLen) throws IOException; |
| 42 | + |
| 43 | + /** |
| 44 | + * Decode a received DTLS 1.3 protected record. The unified header (with the sequence number already decrypted) |
| 45 | + * at 'recordOff' is the AEAD additional data, and the ciphertext immediately follows it. |
| 46 | + * |
| 47 | + * @param seqNo the 64-bit record sequence number reconstructed by the caller (the epoch is not included). |
| 48 | + * @param record array holding the received record. |
| 49 | + * @param recordOff offset of the record (its unified header) in the array. |
| 50 | + * @param headerLen length of the unified header. |
| 51 | + * @param ciphertextLen length of the ciphertext following the header. |
| 52 | + * @return A {@link TlsDecodeResult} containing the result of decoding. |
| 53 | + * @throws IOException |
| 54 | + */ |
| 55 | + TlsDecodeResult decodeDTLS13Ciphertext(long seqNo, byte[] record, int recordOff, int headerLen, int ciphertextLen) |
| 56 | + throws IOException; |
| 57 | +} |
0 commit comments