MCPcopy Create free account
hub / github.com/ValveSoftware/GameNetworkingSockets / PerformKeyExchange

Method PerformKeyExchange

src/common/crypto_25519_donna.cpp:133–156  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: Generate a shared secret from two exchanged curve25519 keys -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

131// Purpose: Generate a shared secret from two exchanged curve25519 keys
132//-----------------------------------------------------------------------------
133bool CCrypto::PerformKeyExchange( const CECKeyExchangePrivateKey &localPrivateKey, const CECKeyExchangePublicKey &remotePublicKey, SHA256Digest_t *pSharedSecretOut )
134{
135 Assert( localPrivateKey.IsValid() );
136 Assert( remotePublicKey.IsValid() );
137 if ( !localPrivateKey.IsValid() || !remotePublicKey.IsValid() )
138 {
139 // Fail securely - generate something that won't be the same on both sides!
140 GenerateRandomBlock( *pSharedSecretOut, sizeof( SHA256Digest_t ) );
141 return false;
142 }
143
144 uint8 bufSharedSecret[32];
145 uint8 bufLocalPrivate[32];
146 uint8 bufRemotePublic[32];
147 localPrivateKey.GetRawData(bufLocalPrivate);
148 remotePublicKey.GetRawData(bufRemotePublic);
149 CHOOSE_25519_IMPL( curve25519_donna )( bufSharedSecret, bufLocalPrivate, bufRemotePublic );
150 SecureZeroMemory( bufLocalPrivate, 32 );
151 SecureZeroMemory( bufRemotePublic, 32 );
152 GenerateSHA256Digest( bufSharedSecret, sizeof(bufSharedSecret), pSharedSecretOut );
153 SecureZeroMemory( bufSharedSecret, 32 );
154
155 return true;
156}
157
158
159void CECSigningPrivateKey::GenerateSignature( const void *pData, size_t cbData, CryptoSignature_t *pSignatureOut ) const

Callers

nothing calls this directly

Calls 3

SecureZeroMemoryFunction · 0.85
IsValidMethod · 0.45
GetRawDataMethod · 0.45

Tested by

no test coverage detected