Skip to content

Commit 516e30a

Browse files
Merge branch 'release/1.4.0'
2 parents 440ebc1 + e33a3f7 commit 516e30a

File tree

9 files changed

+306
-124
lines changed

9 files changed

+306
-124
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RFC 5297 SIV mode of operation in Java
1+
# Java RFC 5297 SIV Authenticated Encryption
22

33
[![Build Status](https://travis-ci.org/cryptomator/siv-mode.svg?branch=develop)](https://travis-ci.org/cryptomator/siv-mode)
44
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8b274788dab046259a40e56688236790)](https://www.codacy.com/app/cryptomator/siv-mode)
@@ -14,7 +14,7 @@
1414
- Defaults on AES, but supports any block cipher with a 128-bit block size.
1515
- Supports any key sizes that the block cipher supports (e.g. 128/192/256-bit keys for AES)
1616
- Thread-safe
17-
- Compatible with Android API Level 16 (since version 1.2.0)
17+
- Compatible with Android API Level 24 (since version 1.4.0)
1818

1919
## Audits
2020
- [Version 1.0.8 audit by Tim McLean](https://www.chosenplaintext.ca/publications/20161104-siv-mode-report.pdf) (Issues fixed with 1.1.0)
@@ -47,14 +47,14 @@ public void encryptWithAssociatedData() {
4747
<dependency>
4848
<groupId>org.cryptomator</groupId>
4949
<artifactId>siv-mode</artifactId>
50-
<version>1.3.0</version>
50+
<version>1.3.2</version>
5151
</dependency>
5252
</dependencies>
5353
```
5454

5555
## JPMS
5656

57-
From version 1.3.0 onwards this library is an explicit module with the name `org.cryptomator.siv`. You can use it by adding the following line to your `module-info.java`.
57+
From version 1.3.2 onwards this library is an explicit module with the name `org.cryptomator.siv`. You can use it by adding the following line to your `module-info.java`.
5858

5959
```java
6060
requires org.cryptomator.siv;
@@ -66,7 +66,7 @@ Because BouncyCastle classes are shaded, this library only depends on `java.base
6666

6767
This is a Maven project. To build it, run `mvn clean install`.
6868

69-
Requires JDK 9+ at build time due to JPMS support.
69+
Requires JDK 11.0.3 or newer at build time due to JPMS support.
7070

7171
## License
7272
Distributed under the MIT X Consortium license. See the LICENSE file for more info.

pom.xml

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.cryptomator</groupId>
55
<artifactId>siv-mode</artifactId>
6-
<version>1.3.2</version>
6+
<version>1.4.0</version>
77

88
<name>SIV Mode</name>
99
<description>RFC 5297 SIV mode: deterministic authenticated encryption</description>
@@ -112,8 +112,7 @@
112112
<artifactId>maven-compiler-plugin</artifactId>
113113
<version>3.8.1</version>
114114
<configuration>
115-
<release>7</release>
116-
<testRelease>8</testRelease>
115+
<release>8</release>
117116
<encoding>UTF-8</encoding>
118117
<showWarnings>true</showWarnings>
119118
</configuration>
@@ -164,7 +163,8 @@
164163
<minimizeJar>true</minimizeJar>
165164
<keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
166165
<createDependencyReducedPom>false</createDependencyReducedPom>
167-
<createSourcesJar>false</createSourcesJar>
166+
<createSourcesJar>true</createSourcesJar>
167+
<shadeSourcesContent>true</shadeSourcesContent>
168168
<artifactSet>
169169
<includes>
170170
<include>org.bouncycastle:bcprov-jdk15on</include>
@@ -178,13 +178,9 @@
178178
</relocations>
179179
<filters>
180180
<filter>
181-
<artifact>*:*</artifact>
181+
<artifact>org.bouncycastle:bcprov-jdk15on</artifact>
182182
<excludes>
183-
<exclude>META-INF/MANIFEST.MF</exclude>
184-
<exclude>META-INF/*.SF</exclude>
185-
<exclude>META-INF/*.DSA</exclude>
186-
<exclude>META-INF/*.RSA</exclude>
187-
<exclude>META-INF/services/**</exclude>
183+
<exclude>META-INF/**</exclude>
188184
</excludes>
189185
</filter>
190186
</filters>
@@ -196,31 +192,6 @@
196192
</build>
197193

198194
<profiles>
199-
<profile>
200-
<id>intellij</id>
201-
<!-- workaround for intellij bug: https://youtrack.jetbrains.com/issue/IDEA-85478 -->
202-
<activation>
203-
<activeByDefault>false</activeByDefault>
204-
<property>
205-
<name>idea.maven.embedder.version</name>
206-
</property>
207-
</activation>
208-
<build>
209-
<plugins>
210-
<plugin>
211-
<groupId>org.apache.maven.plugins</groupId>
212-
<artifactId>maven-compiler-plugin</artifactId>
213-
<version>3.8.1</version>
214-
<configuration>
215-
<release>8</release>
216-
<source>1.8</source>
217-
<target>1.8</target>
218-
</configuration>
219-
</plugin>
220-
</plugins>
221-
</build>
222-
</profile>
223-
224195
<profile>
225196
<id>dependency-check</id>
226197
<build>
@@ -282,6 +253,7 @@
282253
<executions>
283254
<execution>
284255
<id>attach-sources</id>
256+
<phase>prepare-package</phase>
285257
<goals>
286258
<goal>jar-no-fork</goal>
287259
</goals>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.cryptomator.siv;
2+
3+
import org.bouncycastle.crypto.BlockCipher;
4+
import org.bouncycastle.crypto.CipherParameters;
5+
import org.bouncycastle.crypto.OutputLengthException;
6+
import org.bouncycastle.crypto.modes.SICBlockCipher;
7+
import org.bouncycastle.crypto.params.KeyParameter;
8+
import org.bouncycastle.crypto.params.ParametersWithIV;
9+
10+
import java.util.function.Supplier;
11+
12+
/**
13+
* Performs CTR Mode computations facilitating BouncyCastle's {@link SICBlockCipher}.
14+
*/
15+
class CustomCtrComputer implements SivMode.CtrComputer {
16+
17+
private final Supplier<BlockCipher> blockCipherSupplier;
18+
19+
public CustomCtrComputer(Supplier<BlockCipher> blockCipherSupplier) {
20+
this.blockCipherSupplier = blockCipherSupplier;
21+
}
22+
23+
@Override
24+
public byte[] computeCtr(byte[] input, byte[] key, byte[] iv) {
25+
SICBlockCipher cipher = new SICBlockCipher(blockCipherSupplier.get());
26+
CipherParameters params = new ParametersWithIV(new KeyParameter(key), iv);
27+
cipher.init(true, params);
28+
try {
29+
byte[] output = new byte[input.length];
30+
cipher.processBytes(input, 0, input.length, output, 0);
31+
return output;
32+
} catch (OutputLengthException e) {
33+
throw new IllegalStateException("In CTR mode output length must be equal to input length", e);
34+
}
35+
}
36+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.cryptomator.siv;
2+
3+
import javax.crypto.BadPaddingException;
4+
import javax.crypto.Cipher;
5+
import javax.crypto.IllegalBlockSizeException;
6+
import javax.crypto.NoSuchPaddingException;
7+
import javax.crypto.spec.IvParameterSpec;
8+
import javax.crypto.spec.SecretKeySpec;
9+
import java.security.InvalidAlgorithmParameterException;
10+
import java.security.InvalidKeyException;
11+
import java.security.NoSuchAlgorithmException;
12+
import java.security.Provider;
13+
14+
/**
15+
* Performs CTR Mode computations facilitating a cipher returned by JCE's <code>Cipher.getInstance("AES/CTR/NoPadding")</code>.
16+
*/
17+
final class JceAesCtrComputer implements SivMode.CtrComputer {
18+
19+
private final ThreadLocal<Cipher> threadLocalCipher;
20+
21+
public JceAesCtrComputer(final Provider jceSecurityProvider) {
22+
this.threadLocalCipher = new ThreadLocal<Cipher>(){
23+
@Override
24+
protected Cipher initialValue() {
25+
try {
26+
if (jceSecurityProvider == null) {
27+
return Cipher.getInstance("AES/CTR/NoPadding");
28+
} else {
29+
return Cipher.getInstance("AES/CTR/NoPadding", jceSecurityProvider);
30+
}
31+
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
32+
throw new IllegalStateException("AES/CTR/NoPadding not available on this platform.", e);
33+
}
34+
}
35+
};
36+
}
37+
38+
@Override
39+
public byte[] computeCtr(byte[] input, byte[] key, final byte[] iv) {
40+
try {
41+
Cipher cipher = threadLocalCipher.get();
42+
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "AES"), new IvParameterSpec(iv));
43+
return cipher.doFinal(input);
44+
} catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
45+
throw new IllegalArgumentException("Key or IV invalid.");
46+
} catch (BadPaddingException e) {
47+
throw new IllegalStateException("Cipher doesn't require padding.", e);
48+
} catch (IllegalBlockSizeException e) {
49+
throw new IllegalStateException("Block size irrelevant for stream ciphers.", e);
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)