From ac489608905aeee93fad5aee8d20acf690d0312a Mon Sep 17 00:00:00 2001 From: Fela Ameghino Date: Sun, 21 May 2017 11:52:03 +0200 Subject: [PATCH 1/3] Fixed uwp project to always use libopus in release configuration --- libtgvoip.UWP.vcxproj | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libtgvoip.UWP.vcxproj b/libtgvoip.UWP.vcxproj index e3de8a8..a4ad693 100644 --- a/libtgvoip.UWP.vcxproj +++ b/libtgvoip.UWP.vcxproj @@ -135,15 +135,15 @@ false - Debug + Release false - ARM\Debug + ARM\Release false - x64\Debug + x64\Release false @@ -597,6 +597,11 @@ + + + {904ac506-51a0-474e-9f55-ec3febbcccd9} + + \ No newline at end of file From 1e953d73d753295ce6304f3a407d42fea27bef22 Mon Sep 17 00:00:00 2001 From: Fela Ameghino Date: Mon, 22 May 2017 10:22:58 +0200 Subject: [PATCH 2/3] Revert "Fixed uwp project to always use libopus in release configuration" This reverts commit ac489608905aeee93fad5aee8d20acf690d0312a. --- libtgvoip.UWP.vcxproj | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/libtgvoip.UWP.vcxproj b/libtgvoip.UWP.vcxproj index a4ad693..e3de8a8 100644 --- a/libtgvoip.UWP.vcxproj +++ b/libtgvoip.UWP.vcxproj @@ -135,15 +135,15 @@ false - Release + Debug false - ARM\Release + ARM\Debug false - x64\Release + x64\Debug false @@ -597,11 +597,6 @@ - - - {904ac506-51a0-474e-9f55-ec3febbcccd9} - - \ No newline at end of file From 4c653d07901392662e0163166078e169c90b93f1 Mon Sep 17 00:00:00 2001 From: Fela Ameghino Date: Mon, 12 Jun 2017 12:59:35 +0200 Subject: [PATCH 3/3] - Added Evgeny's aes_ctr_encrypt implementation - API availability check for AudioRoutingManager on UWP --- libtgvoip.UWP.vcxproj | 111 ++++----------------------------------- os/windows/CXWrapper.cpp | 41 +++++++++++++++ os/windows/CXWrapper.h | 1 + 3 files changed, 51 insertions(+), 102 deletions(-) diff --git a/libtgvoip.UWP.vcxproj b/libtgvoip.UWP.vcxproj index e3de8a8..aa4c104 100644 --- a/libtgvoip.UWP.vcxproj +++ b/libtgvoip.UWP.vcxproj @@ -25,18 +25,6 @@ Release x64 - - Preview - ARM - - - Preview - Win32 - - - Preview - x64 - {88803693-7606-484b-9d2f-4bb789d57c29} @@ -85,51 +73,30 @@ true v141 - - DynamicLibrary - false - true - v141 - - - DynamicLibrary - false - true - v141 - - - DynamicLibrary - false - true - v141 - + + + + + - - - - - - - - - + @@ -157,18 +124,6 @@ false x64\Release - - false - Preview - - - false - ARM\Preview - - - false - x64\Preview - NotUsing @@ -272,57 +227,6 @@ $(SolutionDir)$(MappedPlatform)\libopus\;%(AdditionalLibraryDirectories) - - - NotUsing - _WINRT_DLL;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;NOMINMAX;WEBRTC_APM_DEBUG_DUMP=0;NDEBUG;TGVOIP_USE_CUSTOM_CRYPTO;%(PreprocessorDefinitions) - pch.h - $(IntDir)pch.pch - /bigobj %(AdditionalOptions) - 28204 - webrtc_dsp;../libopus/include;%(AdditionalIncludeDirectories) - - - Console - false - libopus.lib;ws2_32.lib;mmdevapi.lib;%(AdditionalDependencies) - $(SolutionDir)$(MappedPlatform)\libopus\;%(AdditionalLibraryDirectories) - - - - - NotUsing - _WINRT_DLL;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;NOMINMAX;WEBRTC_APM_DEBUG_DUMP=0;NDEBUG;TGVOIP_USE_CUSTOM_CRYPTO;%(PreprocessorDefinitions) - pch.h - $(IntDir)pch.pch - /bigobj %(AdditionalOptions) - 28204 - webrtc_dsp;../libopus/include;%(AdditionalIncludeDirectories) - - - Console - false - libopus.lib;ws2_32.lib;mmdevapi.lib;%(AdditionalDependencies) - $(SolutionDir)$(MappedPlatform)\libopus\;%(AdditionalLibraryDirectories) - - - - - NotUsing - _WINRT_DLL;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;NOMINMAX;WEBRTC_APM_DEBUG_DUMP=0;NDEBUG;TGVOIP_USE_CUSTOM_CRYPTO;%(PreprocessorDefinitions) - pch.h - $(IntDir)pch.pch - /bigobj %(AdditionalOptions) - 28204 - webrtc_dsp;../libopus/include;%(AdditionalIncludeDirectories) - - - Console - false - libopus.lib;ws2_32.lib;mmdevapi.lib;%(AdditionalDependencies) - $(SolutionDir)$(MappedPlatform)\libopus\;%(AdditionalLibraryDirectories) - - @@ -597,6 +501,9 @@ + + + \ No newline at end of file diff --git a/os/windows/CXWrapper.cpp b/os/windows/CXWrapper.cpp index 96655c0..dc380ca 100644 --- a/os/windows/CXWrapper.cpp +++ b/os/windows/CXWrapper.cpp @@ -30,6 +30,7 @@ SymmetricKeyAlgorithmProvider^ MicrosoftCryptoImpl::aesKeyProvider; };*/ VoIPControllerWrapper::VoIPControllerWrapper(){ + VoIPController::crypto.aes_ctr_encrypt=MicrosoftCryptoImpl::AesCtrEncrypt; VoIPController::crypto.aes_ige_decrypt=MicrosoftCryptoImpl::AesIgeDecrypt; VoIPController::crypto.aes_ige_encrypt=MicrosoftCryptoImpl::AesIgeEncrypt; VoIPController::crypto.sha1=MicrosoftCryptoImpl::SHA1; @@ -180,6 +181,11 @@ void VoIPControllerWrapper::UpdateServerConfig(Platform::String^ json){ } void VoIPControllerWrapper::SwitchSpeaker(bool external){ +#if WINAPI_FAMILY!=WINAPI_FAMILY_PHONE_APP + if (!Windows::Foundation::Metadata::ApiInformation::IsApiContractPresent("Windows.Phone.PhoneContract", 1)){ + return; + } +#endif auto routingManager = AudioRoutingManager::GetDefault(); if (external){ routingManager->SetAudioEndpoint(AudioRoutingEndpoint::Speakerphone); @@ -194,6 +200,41 @@ void VoIPControllerWrapper::SwitchSpeaker(bool external){ } } +#define GETU32(pt) (((uint32_t)(pt)[0] << 24) ^ ((uint32_t)(pt)[1] << 16) ^ ((uint32_t)(pt)[2] << 8) ^ ((uint32_t)(pt)[3])) +#define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); } typedef uint8_t u8; +#define L_ENDIAN /* increment counter (128-bit int) by 2^64 */ +static void AES_ctr128_inc(unsigned char *counter) +{ + unsigned long c; /* Grab 3rd dword of counter and increment */ +#ifdef L_ENDIAN c = GETU32(counter + 8); c++; PUTU32(counter + 8, c); +#else c = GETU32(counter + 4); c++; PUTU32(counter + 4, c); +#endif /* if no overflow, we're done */ if (c) return; /* Grab top dword of counter and increment */ +#ifdef L_ENDIAN c = GETU32(counter + 12); c++; PUTU32(counter + 12, c); +#else c = GETU32(counter + 0); c++; PUTU32(counter + 0, c); +#endif +} + +void MicrosoftCryptoImpl::AesCtrEncrypt(uint8_t* inout, size_t len, uint8_t* key, uint8_t* counter, uint8_t* ecount_buf, uint32_t* num) +{ + unsigned int n; + unsigned long l=len; + IBuffer^ keybuf = IBufferFromPtr(key, 32); + CryptographicKey^ _key = aesKeyProvider->CreateSymmetricKey(keybuf); + n=*num; + while (l--){ + if (n==0) + { + IBuffer^ inbuf=IBufferFromPtr(counter, 16); + IBuffer^ outbuf=CryptographicEngine::Encrypt(_key, inbuf, nullptr); + IBufferToPtr(outbuf, 16, ecount_buf); + AES_ctr128_inc(counter); + } + *inout=*(inout++)^ecount_buf[n]; + n=(n+1)%16; + } + *num=n; +} + void MicrosoftCryptoImpl::AesIgeEncrypt(uint8_t* in, uint8_t* out, size_t len, uint8_t* key, uint8_t* iv){ IBuffer^ keybuf=IBufferFromPtr(key, 32); CryptographicKey^ _key=aesKeyProvider->CreateSymmetricKey(keybuf); diff --git a/os/windows/CXWrapper.h b/os/windows/CXWrapper.h index 3bb25f5..e2395d8 100644 --- a/os/windows/CXWrapper.h +++ b/os/windows/CXWrapper.h @@ -86,6 +86,7 @@ namespace libtgvoip{ ref class MicrosoftCryptoImpl{ public: + static void AesCtrEncrypt(uint8_t* inout, size_t len, uint8_t* key, uint8_t* counter, uint8_t* ecount_buf, uint32_t* num); static void AesIgeEncrypt(uint8_t* in, uint8_t* out, size_t len, uint8_t* key, uint8_t* iv); static void AesIgeDecrypt(uint8_t* in, uint8_t* out, size_t len, uint8_t* key, uint8_t* iv); static void SHA1(uint8_t* msg, size_t len, uint8_t* out);