2121
2222/**
2323 * Implements the RFC 5297 SIV mode.
24+ * <p>
25+ * Note: Instances of this class are not thread-safe.
26+ *
27+ * @see <a href="https://tools.ietf.org/html/rfc5297">RFC 5297</a>
28+ * @since 2.0
2429 */
2530public final class SivEngine {
2631
@@ -86,6 +91,17 @@ public byte[] encrypt(byte[] plaintext, byte[]... associatedData) {
8691 return ciphertext ;
8792 }
8893
94+ /**
95+ * Encrypts plaintext using SIV mode and writes the result to the provided output buffer.
96+ *
97+ * @param plaintext Your plaintext, which shall be encrypted.
98+ * @param output The output buffer to write IV + ciphertext to.
99+ * @param outputOffset The offset in the output buffer to start writing at.
100+ * @param associatedData Optional associated data, which gets authenticated but not encrypted.
101+ * @return The number of bytes written to the output buffer (should always be {@value IV_LENGTH} + plaintext length).
102+ * @throws ShortBufferException If the output buffer is too small.
103+ * @throws IllegalArgumentException if either param exceeds the limits for safe use.
104+ */
89105 public int encrypt (byte [] plaintext , byte [] output , int outputOffset , byte []... associatedData ) throws ShortBufferException {
90106 // Check if plaintext length will cause overflows
91107 if (plaintext .length > (Integer .MAX_VALUE - IV_LENGTH )) {
@@ -104,11 +120,12 @@ public int encrypt(byte[] plaintext, byte[] output, int outputOffset, byte[]...
104120 /**
105121 * Decrypts ciphertext using SIV mode. A block cipher defined by the constructor is being used.<br>
106122 *
107- * @param ciphertext Your ciphertext, which shall be encrypted .
123+ * @param ciphertext Your ciphertext, which shall be decrypted .
108124 * @param associatedData Optional associated data, which needs to be authenticated during decryption.
109125 * @return Plaintext byte array.
110- * @throws AEADBadTagException If the authentication failed, e.g. because ciphertext and/or associatedData are corrupted.
111- * @throws IllegalBlockSizeException If the provided ciphertext is of invalid length.
126+ * @throws AEADBadTagException If the authentication failed, e.g. because ciphertext and/or associatedData are corrupted.
127+ * @throws IllegalBlockSizeException If the provided ciphertext is shorter than 16 bytes.
128+ * @throws IllegalArgumentException If number of associatedData fields exceed the limits for safe use.
112129 */
113130 public byte [] decrypt (byte [] ciphertext , byte []... associatedData ) throws AEADBadTagException , IllegalBlockSizeException {
114131 if (ciphertext .length < IV_LENGTH ) {
0 commit comments