Skip to content

Commit 419d56b

Browse files
Merge pull request #85 from cryptomator/feature/zero-deps
* Internalize CMAC * reduce allocations * implement JCA `CMAC` Mac * implement JCA `AES/SIV/NoPadding` Cipher * restructure tests * deprecate legacy API
2 parents dd0123a + b629ddf commit 419d56b

37 files changed

+1739
-1684
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ jobs:
140140
token: ${{ secrets.CRYPTOBOT_RELEASE_TOKEN }}
141141
generate_release_notes: true
142142
body: |-
143+
### Full Changelog
144+
See [CHANGELOG.md](https://github.com/cryptomator/siv-mode/blob/develop/CHANGELOG.md).
145+
143146
### Maven Coordinates
144147
```xml
145148
<dependency>

CHANGELOG.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,44 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased](https://github.com/cryptomator/siv-mode/compare/1.6.0...HEAD)
8+
## [Unreleased](https://github.com/cryptomator/siv-mode/compare/1.6.1...HEAD)
9+
10+
### Added
11+
- new low-level API:
12+
* `new SivEngine(key).encrypt(plaintext, associatedData...)`
13+
* `new SivEngine(key).decrypt(plaintext, associatedData...)`
14+
- implement JCA `Cipher` SPI:
15+
```java
16+
Cipher siv = Cipher.getInstance("AES/SIV/NoPadding");
17+
siv.init(Cipher.ENCRYPT_MODE, key);
18+
siv.updateAAD(aad1);
19+
siv.updateAAD(aad2);
20+
byte[] ciphertext = siv.doFinal(plaintext);
21+
```
22+
23+
### Changed
24+
- remove dependencies on BouncyCastle and Jetbrains Annotations
25+
- simplify build by removing `maven-shade-plugin`
26+
- update test dependencies
27+
- update build plugins
28+
29+
### Deprecated
30+
- old low-level API:
31+
* `new SivMode().encrypt(key, plaintext, associatedData...)`
32+
* `new SivMode().encrypt(ctrKey, macKey, plaintext, associatedData...)`
33+
* `new SivMode().decrypt(key, ciphertext, associatedData...)`
34+
* `new SivMode().decrypt(ctrKey, macKey, ciphertext, associatedData...)`
35+
36+
## [1.6.1](https://github.com/cryptomator/siv-mode/compare/1.6.0...1.6.1)
37+
38+
### Changed
39+
- update dependencies
940

1041
## [1.6.0](https://github.com/cryptomator/siv-mode/compare/1.5.2...1.6.0)
1142

1243
### Added
13-
1444
- This CHANGELOG file
1545
- `encrypt(SecretKey key, byte[] plaintext, byte[]... associatedData)` and `decrypt(SecretKey key, byte[] ciphertext, byte[]... associatedData)` using a single 256, 384, or 512 bit key
1646

1747
### Changed
18-
1948
- use `maven-gpg-plugin`'s bc-based signer

README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
[![Javadocs](http://www.javadoc.io/badge/org.cryptomator/siv-mode.svg)](http://www.javadoc.io/doc/org.cryptomator/siv-mode)
99

1010
## Features
11-
- No dependencies (required BouncyCastle classes are repackaged)
11+
- No dependencies
1212
- Passes official RFC 5297 test vectors
1313
- Constant time authentication
14-
- Defaults on AES, but supports any block cipher with a 128-bit block size.
15-
- Supports any key sizes that the block cipher supports (e.g. 128/192/256-bit keys for AES)
16-
- Thread-safe
1714
- [Fast](https://github.com/cryptomator/siv-mode/issues/15)
1815
- Requires JDK 8+ or Android API Level 24+ (since version 1.4.0)
1916

@@ -28,16 +25,16 @@
2825

2926
## Usage
3027
```java
31-
private static final SivMode AES_SIV = new SivMode();
28+
SivMode AES_SIV = new SivMode(key);
3229

3330
public void encrypt() {
34-
byte[] encrypted = AES_SIV.encrypt(ctrKey, macKey, "hello world".getBytes());
35-
byte[] decrypted = AES_SIV.decrypt(ctrKey, macKey, encrypted);
31+
byte[] encrypted = AES_SIV.encrypt("hello world".getBytes());
32+
byte[] decrypted = AES_SIV.decrypt(encrypted);
3633
}
3734

3835
public void encryptWithAssociatedData() {
39-
byte[] encrypted = AES_SIV.encrypt(ctrKey, macKey, "hello world".getBytes(), "associated".getBytes(), "data".getBytes());
40-
byte[] decrypted = AES_SIV.decrypt(ctrKey, macKey, encrypted, "associated".getBytes(), "data".getBytes());
36+
byte[] encrypted = AES_SIV.encrypt("hello world".getBytes(), "associated".getBytes(), "data".getBytes());
37+
byte[] decrypted = AES_SIV.decrypt(encrypted, "associated".getBytes(), "data".getBytes());
4138
}
4239
```
4340

@@ -48,7 +45,7 @@ public void encryptWithAssociatedData() {
4845
<dependency>
4946
<groupId>org.cryptomator</groupId>
5047
<artifactId>siv-mode</artifactId>
51-
<version>1.4.0</version>
48+
<version>2.0.0</version>
5249
</dependency>
5350
</dependencies>
5451
```
@@ -61,8 +58,6 @@ From version 1.3.2 onwards this library is an explicit module with the name `org
6158
requires org.cryptomator.siv;
6259
```
6360

64-
Because BouncyCastle classes are shaded, this library only depends on `java.base`.
65-
6661
## Reproducible Builds
6762

6863
This is a Maven project that can be built using `mvn install`. However, if you want to build this reproducibly, please make sure:

pom.xml

Lines changed: 33 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45
<groupId>org.cryptomator</groupId>
56
<artifactId>siv-mode</artifactId>
6-
<version>1.7.0-SNAPSHOT</version>
7+
<version>2.0.0-SNAPSHOT</version>
78

89
<name>SIV Mode</name>
910
<description>RFC 5297 SIV mode: deterministic authenticated encryption</description>
@@ -37,9 +38,6 @@
3738
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3839
<project.build.outputTimestamp>2025-03-14T12:02:43Z</project.build.outputTimestamp>
3940

40-
<!-- dependencies -->
41-
<bouncycastle.version>1.82</bouncycastle.version>
42-
4341
<!-- test dependencies -->
4442
<junit.version>6.0.1</junit.version>
4543
<mockito.version>5.20.0</mockito.version>
@@ -49,23 +47,12 @@
4947

5048
<!-- maven plugins -->
5149
<dependency-check.version>12.1.8</dependency-check.version>
50+
51+
<!-- Property used by surefire to determine jacoco engine -->
52+
<surefire.jacoco.args/>
5253
</properties>
5354

5455
<dependencies>
55-
<dependency>
56-
<groupId>org.bouncycastle</groupId>
57-
<artifactId>bcprov-jdk18on</artifactId>
58-
<version>${bouncycastle.version}</version>
59-
<!-- see maven-shade-plugin; we don't want this as a transitive dependency in other projects -->
60-
<optional>true</optional>
61-
</dependency>
62-
<dependency>
63-
<groupId>org.jetbrains</groupId>
64-
<artifactId>annotations</artifactId>
65-
<version>26.0.2-1</version>
66-
<scope>provided</scope>
67-
</dependency>
68-
6956
<!-- Tests -->
7057
<dependency>
7158
<groupId>org.junit.jupiter</groupId>
@@ -134,13 +121,33 @@
134121
</execution>
135122
</executions>
136123
</plugin>
124+
<plugin>
125+
<groupId>org.apache.maven.plugins</groupId>
126+
<artifactId>maven-dependency-plugin</artifactId>
127+
<executions>
128+
<execution>
129+
<id>jar-paths-to-properties</id>
130+
<phase>validate</phase>
131+
<goals>
132+
<goal>properties</goal>
133+
</goals>
134+
</execution>
135+
</executions>
136+
</plugin>
137137
<plugin>
138138
<artifactId>maven-compiler-plugin</artifactId>
139139
<version>3.14.1</version>
140140
<configuration>
141141
<release>8</release>
142142
<encoding>UTF-8</encoding>
143143
<showWarnings>true</showWarnings>
144+
<annotationProcessorPaths>
145+
<path>
146+
<groupId>org.openjdk.jmh</groupId>
147+
<artifactId>jmh-generator-annprocess</artifactId>
148+
<version>${jmh.version}</version>
149+
</path>
150+
</annotationProcessorPaths>
144151
</configuration>
145152
<executions>
146153
<execution>
@@ -163,6 +170,9 @@
163170
<groupId>org.apache.maven.plugins</groupId>
164171
<artifactId>maven-surefire-plugin</artifactId>
165172
<version>3.5.4</version>
173+
<configuration>
174+
<argLine>@{surefire.jacoco.args} -javaagent:${org.mockito:mockito-core:jar}</argLine>
175+
</configuration>
166176
</plugin>
167177
<plugin>
168178
<artifactId>maven-jar-plugin</artifactId>
@@ -208,43 +218,6 @@
208218
<release>8</release>
209219
</configuration>
210220
</plugin>
211-
<plugin>
212-
<artifactId>maven-shade-plugin</artifactId>
213-
<version>3.6.1</version>
214-
<executions>
215-
<execution>
216-
<phase>package</phase>
217-
<goals>
218-
<goal>shade</goal>
219-
</goals>
220-
<configuration>
221-
<minimizeJar>true</minimizeJar>
222-
<keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
223-
<createDependencyReducedPom>false</createDependencyReducedPom>
224-
<createSourcesJar>false</createSourcesJar>
225-
<artifactSet>
226-
<includes>
227-
<include>org.bouncycastle:bcprov-jdk18on</include>
228-
</includes>
229-
</artifactSet>
230-
<relocations>
231-
<relocation>
232-
<pattern>org.bouncycastle</pattern>
233-
<shadedPattern>org.cryptomator.siv.org.bouncycastle</shadedPattern>
234-
</relocation>
235-
</relocations>
236-
<filters>
237-
<filter>
238-
<artifact>org.bouncycastle:bcprov-jdk18on</artifact>
239-
<excludes>
240-
<exclude>META-INF/**</exclude>
241-
</excludes>
242-
</filter>
243-
</filters>
244-
</configuration>
245-
</execution>
246-
</executions>
247-
</plugin>
248221
</plugins>
249222
</build>
250223

@@ -292,6 +265,9 @@
292265
<goals>
293266
<goal>prepare-agent</goal>
294267
</goals>
268+
<configuration>
269+
<propertyName>surefire.jacoco.args</propertyName>
270+
</configuration>
295271
</execution>
296272
</executions>
297273
<!-- workaround for https://github.com/jacoco/jacoco/issues/407 -->
@@ -353,7 +329,7 @@
353329
<extensions>true</extensions>
354330
<configuration>
355331
<publishingServerId>central</publishingServerId>
356-
<autoPublish>true</autoPublish>
332+
<autoPublish>true</autoPublish>
357333
</configuration>
358334
</plugin>
359335
</plugins>

0 commit comments

Comments
 (0)