----------------------------------------------------------------------------- Purpose: Generate a shared secret from two exchanged curve25519 keys -----------------------------------------------------------------------------
| 131 | // Purpose: Generate a shared secret from two exchanged curve25519 keys |
| 132 | //----------------------------------------------------------------------------- |
| 133 | bool 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 | |
| 159 | void CECSigningPrivateKey::GenerateSignature( const void *pData, size_t cbData, CryptoSignature_t *pSignatureOut ) const |
nothing calls this directly
no test coverage detected