Skip to content

Commit 2e723af

Browse files
clearified use of JceAesBlockCipher
1 parent a785b65 commit 2e723af

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/main/java/org/cryptomator/siv/JceAesBlockCipher.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,28 @@
2424

2525
/**
2626
* Adapter class between BouncyCastle's {@link BlockCipher} and JCE's {@link Cipher} API.
27+
*
28+
* <p>
29+
* As per contract of {@link BlockCipher#processBlock(byte[], int, byte[], int)}, this class is designed to encrypt or decrypt just <b>one single block</b> at a time.
30+
* JCE doesn't allow us to retrieve the plain cipher without a mode, so we explicitly request {@value #SINGLE_BLOCK_PLAIN_AES_JCE_CIPHER_NAME}.
31+
* This is by design, because we want the plain cipher for a single 128 bit block without any mode. We're not actually using ECB mode.
32+
*
33+
* <p>
34+
* This is a package-private class only used to encrypt the 128 bit counter during SIV mode.
2735
*/
28-
class JceAesBlockCipher implements BlockCipher {
36+
final class JceAesBlockCipher implements BlockCipher {
2937

3038
private static final String ALG_NAME = "AES";
3139
private static final String KEY_DESIGNATION = "AES";
32-
private static final String JCE_CIPHER_NAME = "AES/ECB/NoPadding";
40+
private static final String SINGLE_BLOCK_PLAIN_AES_JCE_CIPHER_NAME = "AES/ECB/NoPadding";
3341

3442
private final Cipher cipher;
3543
private Key key;
3644
private int opmode;
3745

3846
public JceAesBlockCipher() {
3947
try {
40-
this.cipher = Cipher.getInstance(JCE_CIPHER_NAME); // defaults to SunJCE but allows to configure different providers
48+
this.cipher = Cipher.getInstance(SINGLE_BLOCK_PLAIN_AES_JCE_CIPHER_NAME); // defaults to SunJCE but allows to configure different providers
4149
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
4250
throw new IllegalStateException("Every implementation of the Java platform is required to support AES/ECB/NoPadding.");
4351
}

0 commit comments

Comments
 (0)