Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AES Encryption for Voice #897

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

viztea
Copy link
Contributor

@viztea viztea commented Dec 12, 2023

AES for voice receive is currently unsupported.

I tested voice send/receive for all 3 xsalsa20 poly1305 nonce strategies, all work as expected.

Copy link
Member

@DRSchlaubi DRSchlaubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please run ./gradlew apiDump

@lukellmann
Copy link
Member

i'm not very familiar with voice connections, can you explain a bit why this is needed?

@viztea
Copy link
Contributor Author

viztea commented Dec 20, 2023

i'm not very familiar with voice connections, can you explain a bit why this is needed?

It kinda is and kinda isn't. I initially wanted to implement AES because it was faster than xsalsa but after doing a couple benchmarks it looks like xsalsa is a little bit more consistent and a couple microseconds faster.

This isn't really that surprising considering Kord Voice isn't the most efficient voice library, it doesn't help that Java relies on ByteBuffers to be performant.

Comment on lines +170 to +174
val encryption = if ((receiveVoice || streams != null) && encryption?.supportsDecryption != true) {
VoiceEncryption.XSalsaPoly1305()
} else {
encryption ?: VoiceEncryption.AeadAes256Gcm
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to log if the user's chosen encryption method ends up not being used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or even throw an exception? but logging a warning is probably best.

@lost-illusi0n
Copy link
Contributor

Functionality-wise LGTM. It likely will make adding/working with encryption a bit easier in the future too, if (or rather when) Discord decides to change things up.

Comment on lines +170 to +174
val encryption = if ((receiveVoice || streams != null) && encryption?.supportsDecryption != true) {
VoiceEncryption.XSalsaPoly1305()
} else {
encryption ?: VoiceEncryption.AeadAes256Gcm
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or even throw an exception? but logging a warning is probably best.

voice/src/main/kotlin/encryption/VoiceEncryption.kt Outdated Show resolved Hide resolved
voice/src/main/kotlin/encryption/VoiceEncryption.kt Outdated Show resolved Hide resolved
@@ -27,4 +23,17 @@ public sealed interface NonceStrategy {
* Writes the [nonce] to [cursor] in the correct relative position.
*/
public fun append(nonce: ByteArrayView, cursor: MutableByteArrayCursor)

public interface Factory {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this factory? i'd rather not add it if not needed.

voice/src/main/kotlin/encryption/VoiceEncryption.kt Outdated Show resolved Hide resolved
voice/src/main/kotlin/encryption/VoiceEncryption.kt Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants