forked from google/conscrypt
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Sere-Fu/add_chacha
Add ChaCha20(&Poly1305) Support
- Loading branch information
Showing
8 changed files
with
345 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
common/src/main/java/org/conscrypt/OpenSSLAeadCipherChaCha20.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.conscrypt; | ||
|
||
import java.security.InvalidKeyException; | ||
import java.util.Locale; | ||
|
||
public class OpenSSLAeadCipherChaCha20 extends OpenSSLAeadCipher { | ||
|
||
public OpenSSLAeadCipherChaCha20() { | ||
super(Mode.POLY1305); | ||
} | ||
|
||
@Override | ||
String getCipherName(int keyLength, Mode mode) { | ||
return "chacha20-" + mode.toString().toLowerCase(Locale.US); | ||
} | ||
|
||
@Override | ||
String getBaseCipherName() { | ||
return "ChaCha20"; | ||
} | ||
|
||
@Override | ||
void checkSupportedKeySize(int keySize) throws InvalidKeyException { | ||
if (keySize != 32) { | ||
throw new InvalidKeyException("Unsupported key size: " + keySize | ||
+ " bytes (must be 32)"); | ||
} | ||
} | ||
|
||
@Override | ||
int getCipherBlockSize() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
boolean allowsNonceReuse() { | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
common/src/main/java/org/conscrypt/OpenSSLEvpCipherChaCha20.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2023 The Tongsuo Project Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License 2.0 (the "License"). You may not use | ||
* this file except in compliance with the License. You can obtain a copy | ||
* in the file LICENSE in the source distribution or at | ||
* https://github.com/Tongsuo-Project/Tongsuo/blob/master/LICENSE.txt | ||
*/ | ||
|
||
package org.conscrypt; | ||
|
||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
import javax.crypto.NoSuchPaddingException; | ||
|
||
public class OpenSSLEvpCipherChaCha20 extends OpenSSLEvpCipher { | ||
|
||
public OpenSSLEvpCipherChaCha20() {} | ||
|
||
@Override | ||
String getCipherName(int keySize, Mode mode) { | ||
return "chacha20"; | ||
} | ||
|
||
@Override | ||
String getBaseCipherName() { | ||
return "ChaCha20"; | ||
} | ||
|
||
@Override | ||
void checkSupportedKeySize(int keySize) throws InvalidKeyException { | ||
if (keySize != 32) { | ||
throw new InvalidKeyException("Unsupported key size: " + keySize | ||
+ " bytes (must be 32)"); | ||
} | ||
} | ||
|
||
@Override | ||
void checkSupportedMode(Mode mode) throws NoSuchAlgorithmException { | ||
if (mode != Mode.NONE) { | ||
throw new NoSuchAlgorithmException("Mode must be NONE"); | ||
} | ||
} | ||
|
||
@Override | ||
void checkSupportedPadding(Padding padding) throws NoSuchPaddingException { | ||
if (padding != Padding.NOPADDING) { | ||
throw new NoSuchPaddingException("Must be NoPadding"); | ||
} | ||
} | ||
|
||
@Override | ||
int getCipherBlockSize() { | ||
return 0; | ||
} | ||
|
||
} |
Oops, something went wrong.