25 Commits

Author SHA1 Message Date
Fletcher Dunn 7dc6f6d523 Add some test coverage for SHA256 and HMACs
These had no test coverage and the bcrypt version is busted
2026-04-18 22:39:55 -07:00
Fletcher Dunn bfd3d6e95b A few small crypto compeil fixes and cleanup from Steam
P4:8088063
2023-05-27 18:32:03 -07:00
Fletcher Dunn 0307add013 Move 25519 crypto to a separate header.
Getting things closer to how they are organized in the Steam main branch
so I can stop having these files diverge so much.

Also tweaked defines.
2020-02-04 16:28:53 -08:00
Andrew Simpson b2ae48a260 implement libsodium support
- Added support for using libsodium for encryption rather than OpenSSL
 - Removed AES-GCM tests with keys shorter than 256; libsodium only supports 256
 - Added a build with libsodium to the CI matrix

Signed-off-by: Andrew Simpson <andy@aiusepsi.co.uk>

steven@ edited and rebased:

 - integrated with new USE_CRYPTO/USE_CRYPTO25519 options in CMake/meson
 - separated using libsodium for ed25519/curve25519 and AES/SHA256.
 - ensured libsodium simple crypto tests run on all builders instead of
   a single isolated builder.
 - prevented building with -DUSE_CRYPTO=libsodium for non-x86 hardware,
   as libsodium's AES implementation depends on AES-NI. it is still
   possible to configure with -DUSE_CRYPTO25519=libsodium on arbitrary
   hardware targets.

Fixes #88.

Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2020-01-21 05:02:07 -08:00
Steven Noonan 707a451fcb test_crypto: add comment about tag/iv length check
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-02-06 14:17:22 -08:00
Steven Noonan 4cd958f42a test_crypto: check return values in chdir_to_bindir
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-30 21:06:13 -08:00
Steven Noonan f746995cbb test_crypto: cosmetic readability improvements, NFC
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-30 21:06:13 -08:00
Steven Noonan f008d05bff implement BCrypt support
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-30 17:36:15 -08:00
Fletcher Dunn 403e9c4562 Delete unused code and tests for AES-CBC encryption.
We're using AES-GCM now.

Also:
- Tests now check the return value of CCrypto::PerformKeyExchange
- Fix some MSVC compiler warnings in tests
- Delete some more dead code
2019-01-22 09:57:27 -08:00
Steven Noonan 978a0bc6f1 test_crypto: ensure EC data buffer is random-filled
Otherwise the sanitizers (and valgrind) will see things touching
uninitialized data.

Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-21 21:49:02 -08:00
Steven Noonan 42c015dc04 test_crypto: ensure aliceSharedSecret/bobSharedSecret are initialized, and to different values
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-21 20:59:13 -08:00
Steven Noonan e95340ed8c test_crypto: ensure aliceSharedSecret and bobSharedSecret are identical
Even if they don't match the expected result, this can be useful data.

Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-21 20:48:09 -08:00
Steven Noonan 98335ec128 test_crypto: move AES-GCM to AES_GCM_{En,De}cryptContext API
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-21 15:56:39 -08:00
Steven Noonan dc0d4f2e6f test_crypto: move AES-GCM test vectors to using AES_GCM_{En,De}cryptContext
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-21 15:56:39 -08:00
Steven Noonan 7ffb909eed test_crypto: ensure that failing checks cause a failing Travis build
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-21 15:56:39 -08:00
Steven Noonan cb8e4b6979 make AES-GCM tests less sensitive to current working directory
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-21 14:59:54 -08:00
Fletcher Dunn db6f93c4e7 Fix accidental clobber of @tycho's changes.
I'm using P4 and git to merge code between Steam and github, and I accidentally stomped 83720f77f1 and 818f85c492.
2019-01-21 13:52:37 -08:00
Fletcher Dunn 83720f77f1 Refactor storage of crypto key pairs.
The basic change is that the base class will no longer store the raw key bytes in a buffer.  Instead, we have virtual functions to get and set the raw bytes, with the storage being specific to the key type and crypto provider.

The main purpose of these changes is to make it easier to get 25519 working in OpenSSL and bcrypt.

NOTE: This broke libsodium support.  We could fix it.  But I'm not sure we want to support libsodium or not.  If we support it, we should support it for all crypto needs, including per-packet encryption.  And that means accepting the 12-byte IV and 16-byte tag.  If that's what TLS does, there is some potential advantage to doing exactly what TLS does.  At the same time, I don't add 12 bytes to every packet lightly.

Reorganize 25519 files, made a placeholder for OpenSSL with a bunch of FIXMEs.  (Working on issue #46.)

Also, deleted RSA key support, since we don't need it for thiis project.
2019-01-21 08:07:08 -08:00
Steven Noonan 98d73f703d test_crypto.cpp: change test buffer sizes to match realistic GNS payload sizes
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-20 15:19:41 -08:00
Steven Noonan 818f85c492 test_crypto: add GCM benchmark
Using similar behavior to what GNS uses (no AAD, 4 byte tag).

Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-20 15:15:21 -08:00
Fletcher Dunn 049563560d Rename function to match maming convention.
There is a function in the Steam branch with "Chosen" in the name, and I was confused about exactly what it did.
2019-01-19 10:05:05 -08:00
Fletcher Dunn 6048226d1e Add AES-GCM to crypto layer using OpenSSL EVP.
Also add a EVP_CIPHER_CTX_safe structure to manage allocating and cleaning up
EVP_CIPHER_CTX struct.  IN older versions of OpenSSL you could just declare an
EVP_CIPHER_CTX struct on the stack.  Now you have to go through a generic
allocation mechanism!?  SO we're going to be doing a heap allocation for every
single packet.  That is....terrible.  We should try to find a way around this,
even if it's gross, because doing a heap allocation per packet is not acceptible.
2019-01-19 09:06:12 -08:00
Steven Noonan 38a35c90b6 test_crypto: add MB/sec rates for encrypt/decrypt
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-15 17:01:51 -08:00
fletcherdvalve 66de37b0b9 Minor compile fix. 2019-01-10 17:41:28 -08:00
Steven Noonan 045a9b4c52 add test_crypto from Steam
Heavily modified, since we only use Symmetric*WithIV in
GameNetworkingSockets.

Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-10 16:39:01 -08:00