mirror of
https://github.com/ValveSoftware/GameNetworkingSockets.git
synced 2026-05-29 16:20:34 +00:00
Make CCrypto::PerformKeyExchange return bool instead of void.
Get crypto_25519_openssl.cpp to compile.
This commit is contained in:
+1
-1
@@ -148,7 +148,7 @@ namespace CCrypto
|
||||
|
||||
// Generate a curve25519 key pair for Diffie-Hellman secure key exchange
|
||||
void GenerateKeyExchangeKeyPair( CECKeyExchangePublicKey *pPublicKey, CECKeyExchangePrivateKey *pPrivateKey );
|
||||
void PerformKeyExchange( const CECKeyExchangePrivateKey &localPrivateKey, const CECKeyExchangePublicKey &remotePublicKey, SHA256Digest_t *pSharedSecretOut );
|
||||
bool PerformKeyExchange( const CECKeyExchangePrivateKey &localPrivateKey, const CECKeyExchangePublicKey &remotePublicKey, SHA256Digest_t *pSharedSecretOut );
|
||||
|
||||
//
|
||||
// Signing and verification (ed25519 elliptic-curve signature scheme)
|
||||
|
||||
@@ -32,7 +32,7 @@ void ed25519_sign_sse2( const unsigned char *m, size_t mlen, const ed25519_secre
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Generate a shared secret from two exchanged curve25519 keys
|
||||
//-----------------------------------------------------------------------------
|
||||
void CCrypto::PerformKeyExchange( const CECKeyExchangePrivateKey &localPrivateKey, const CECKeyExchangePublicKey &remotePublicKey, SHA256Digest_t *pSharedSecretOut )
|
||||
bool CCrypto::PerformKeyExchange( const CECKeyExchangePrivateKey &localPrivateKey, const CECKeyExchangePublicKey &remotePublicKey, SHA256Digest_t *pSharedSecretOut )
|
||||
{
|
||||
Assert( localPrivateKey.IsValid() );
|
||||
Assert( remotePublicKey.IsValid() );
|
||||
@@ -40,13 +40,15 @@ void CCrypto::PerformKeyExchange( const CECKeyExchangePrivateKey &localPrivateKe
|
||||
{
|
||||
// Fail securely - generate something that won't be the same on both sides!
|
||||
GenerateRandomBlock( *pSharedSecretOut, sizeof( SHA256Digest_t ) );
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8 bufSharedSecret[32];
|
||||
CHOOSE_25519_IMPL( curve25519_donna )( bufSharedSecret, localPrivateKey.GetRawDataPtr(), remotePublicKey.GetRawDataPtr() );
|
||||
GenerateSHA256Digest( bufSharedSecret, sizeof(bufSharedSecret), pSharedSecretOut );
|
||||
SecureZeroMemory( bufSharedSecret, 32 );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ uint32 CEC25519KeyBase::GetRawData( void *pData ) const
|
||||
}
|
||||
break;
|
||||
|
||||
default;
|
||||
default:
|
||||
AssertMsg( false, "Invalid 25519 key type" );
|
||||
return 0;
|
||||
}
|
||||
@@ -131,17 +131,17 @@ bool CCrypto::PerformKeyExchange( const CECKeyExchangePrivateKey &localPrivateKe
|
||||
VerifyFatal( EVP_PKEY_derive_init(ctx) == 1 );
|
||||
VerifyFatal( EVP_PKEY_derive_set_peer(ctx, peerkey) == 1 );
|
||||
|
||||
size_t skeylen = sizeof(*pSharedSecretout) );
|
||||
size_t skeylen = sizeof(*pSharedSecretOut);
|
||||
VerifyFatal( EVP_PKEY_derive(ctx, nullptr, &skeylen ) == 1 );
|
||||
AssertFatal( skeylen == sizeof(*pSharedSecretOut) );
|
||||
|
||||
EVP_PKEY_CTX_free(cxt);
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CECSigningPrivateKey::GenerateSignature( const void *pData, size_t cbData, CryptoSignature_t *pSignatureOut )
|
||||
void CECSigningPrivateKey::GenerateSignature( const void *pData, size_t cbData, CryptoSignature_t *pSignatureOut ) const
|
||||
{
|
||||
EVP_PKEY *pkey = (EVP_PKEY*)m_evp_pkey;
|
||||
if ( !pkey )
|
||||
@@ -156,13 +156,13 @@ void CECSigningPrivateKey::GenerateSignature( const void *pData, size_t cbData,
|
||||
VerifyFatal( EVP_PKEY_sign_init( ctx ) == 1 );
|
||||
|
||||
size_t siglen = sizeof(*pSignatureOut);
|
||||
VerifyFatal( EVP_PKEY_sign( ctx, (unsigned char *)pSignatureOut, &siglen, pData, cbData ) == 1 )
|
||||
VerifyFatal( EVP_PKEY_sign( ctx, (unsigned char *)pSignatureOut, &siglen, (const unsigned char *)pData, cbData ) == 1 );
|
||||
AssertFatal( siglen == sizeof(*pSignatureOut) );
|
||||
|
||||
EVP_PKEY_CTX_free(cxt);
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
}
|
||||
|
||||
bool CECSigningPublicKey::VerifySignature( const void *pData, size_t cbData, const CryptoSignature_t &signature )
|
||||
bool CECSigningPublicKey::VerifySignature( const void *pData, size_t cbData, const CryptoSignature_t &signature ) const
|
||||
{
|
||||
EVP_PKEY *pkey = (EVP_PKEY*)m_evp_pkey;
|
||||
if ( !pkey )
|
||||
@@ -175,9 +175,9 @@ bool CECSigningPublicKey::VerifySignature( const void *pData, size_t cbData, con
|
||||
VerifyFatal( ctx );
|
||||
VerifyFatal( EVP_PKEY_verify_init( ctx ) == 1 );
|
||||
|
||||
int r = EVP_PKEY_Verify( ctx, (const unsigned char *)signature, sizeof(signature), (const unsigned char *)pData, cbData );
|
||||
int r = EVP_PKEY_verify( ctx, (const unsigned char *)signature, sizeof(signature), (const unsigned char *)pData, cbData );
|
||||
|
||||
EVP_PKEY_CTX_free(cxt);
|
||||
EVP_PKEY_CTX_free(ctx);
|
||||
|
||||
return r == 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user