-
Notifications
You must be signed in to change notification settings - Fork 620
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
More flexible crypto config #196
Comments
Hey @past-due, I was looking at refactoring the crypto code to introduce those abstract interfaces (since that's the sort of refactor I can imagine you not wanting to do.) One quick question: My understanding is that ChaCha20 works similarly AES-GCM, in that the cipher doesn't really operate directly on the data, but instead produces a keystream, which is then combined with the plaintext in a simple way. Because of this, there isn't really a "block size", it can encrypt N plaintext bytes to N ciphertext bytes. And then there is a tag. Can you confirm if my understanding is right about this? Or perhaps more directly, is there any difference in the "interface" to these two ciphers, with respect to block size, tag size, the ability to accommodate Additional Authenticated Data, etc? I was hoping to be able to keep the interface extremely simple for now:
This assumes that all concrete types will have the same characteristics regarding any block size (there is none), tag size, and support for AAD. (Actually, the tag size could differ in the existing code without too much hassle -- unencrypted mode doesn't have a tag, and that is supported). |
Hi @fletcherdvalve, Apologies - I had not yet had a chance to dig into this. From initial looks at libsodium, it appears to have exactly the same interface for both AES-GCM: int crypto_aead_aes256gcm_encrypt(unsigned char *c,
unsigned long long *clen_p,
const unsigned char *m,
unsigned long long mlen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k); As well as IETF ChaCha20-Poly1305: int crypto_aead_chacha20poly1305_ietf_encrypt(unsigned char *c,
unsigned long long *clen_p,
const unsigned char *m,
unsigned long long mlen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k); (It looks like the combined + precomputed interface is used for AES-GCM by this library, but that's also basically the same.) The public nonce size for both ( The same recommendation applies for generating the public nonce for both:
One general point of note:
Although I can't imagine that's likely to be a problem. 😄 So overall this does appear to be compatible with such an abstract interface. |
Introduce ISymmetricEncryptContext and ISymmetricDecryptContext abstract interfaces. Connection class will hold a pointer to these, instead of having members to AES-GCM concrete types directly. In a few places we no longer need a switch on the cipher type, since we will rely on virtual function dispatch instead. This should make it much easier to address #196 P4:6878145
Alrighty, take a look at that change. I think it should be pretty straightforward. |
With the protocol supporting negotiable cipher suites, some additional changes to support a more flexible crypto config seem like they could be useful.
Motivations:
There may be situations where:
k_ESteamNetworkingSocketsCipher_CHACHA20_POLY1305
) with different performance characteristics or system / crypto library compatibility are desired.Additionally (although not considered in-scope at this time, but the work in this should help):
Tasks (WIP):
(AES-GCM runtime availability check, Advertise / initialize AES-GCM cipher only if supported #197)
(AES-GCM runtime availability check, Advertise / initialize AES-GCM cipher only if supported #197)
k_ESteamNetworkingSocketsCipher_CHACHA20_POLY1305
. (@fletcherdvalve: Should this be theIETF variant of ChaCha20-Poly1305?)
The text was updated successfully, but these errors were encountered: