Skip to content

Commit

Permalink
keep chacha20 usage separate from poly1305 (combined algorithm in JCE
Browse files Browse the repository at this point in the history
seems to be buggy, using it together as separate algorithms seems to
work fine)
  • Loading branch information
subes committed Jan 27, 2023
1 parent a8b9416 commit b13e220
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
*/
@Immutable
public enum ChaCha20Algorithm implements ISymmetricCipherAlgorithm {
/**
* Encryption only
*/
ChaCha20("ChaCha20", 12, 0) {
@Override
public AlgorithmParameterSpec wrapParam(final byte[] iv) {
Expand All @@ -35,25 +32,9 @@ public AlgorithmParameterSpec wrapParam(final byte[] iv) {
public AlgorithmParameterSpec wrapParam(final MutableIvParameterSpec iv) {
return wrapParam(iv.getIV());
}
},
/**
* Authenticated Encryption
*
* https://mkyong.com/java/java-11-chacha20-poly1305-encryption-examples/
*/
ChaCha20_Poly1305("ChaCha20-Poly1305", 12, 16) {
@Override
public AlgorithmParameterSpec wrapParam(final byte[] iv) {
return new MutableIvParameterSpec(iv);
}

@Override
public AlgorithmParameterSpec wrapParam(final MutableIvParameterSpec iv) {
return iv;
}
};

public static final ChaCha20Algorithm DEFAULT = ChaCha20_Poly1305;
public static final ChaCha20Algorithm DEFAULT = ChaCha20;

private final String algorithm;
private final int ivSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public void testCipher() {
random.nextBytes(key);
derivedKeyProvider = DerivedKeyProvider
.fromRandom(AsymmetricEncryptionFactoryTest.class.getSimpleName().getBytes(), key);
final byte[] cipherKey = derivedKeyProvider.newDerivedKey("cipher-key".getBytes(),
AesKeySize.DEFAULT.getBits());
for (final ISymmetricCipherAlgorithm symmetricAlgorithm : ISymmetricCipherAlgorithm.values()) {
final byte[] cipherKey = derivedKeyProvider.newDerivedKey("cipher-key".getBytes(),
symmetricAlgorithm.getDefaultKeySizeBits());
final CipherDerivedIV derivedIV = new CipherDerivedIV(symmetricAlgorithm, derivedKeyProvider);
final CipherCountedIV countedIV = new CipherCountedIV(symmetricAlgorithm);
final CipherPresharedIV presharedIV = new CipherPresharedIV(symmetricAlgorithm, derivedKeyProvider
Expand Down

0 comments on commit b13e220

Please sign in to comment.