| 5 | #include <cstring> |
| 6 | #include <string> |
| 7 | #include <vector> |
| 8 | #include <windows.h> |
| 9 | #include <wrl.h> |
| 10 |
| 11 | using namespace Windows::Storage::Streams; |
| 12 | using namespace Microsoft::WRL; |
| 13 | using namespace libtgvoip; |
| 14 | using namespace Platform; |
| 15 | using namespace tgvoip; |
| 16 | using namespace Windows::Security::Cryptography; |
| 17 | using namespace Windows::Security::Cryptography::Core; |
| 18 | using namespace Windows::Storage::Streams; |
| 19 | using namespace Windows::Data::Json; |
| 20 | using namespace Windows::Phone::Media::Devices; |
| 21 |
| 22 | //CryptographicHash^ MicrosoftCryptoImpl::sha1Hash; |
| 23 | //CryptographicHash^ MicrosoftCryptoImpl::sha256Hash; |
| 24 | HashAlgorithmProvider ^ MicrosoftCryptoImpl::sha1Provider; |
| 25 | HashAlgorithmProvider ^ MicrosoftCryptoImpl::sha256Provider; |
| 26 | SymmetricKeyAlgorithmProvider ^ MicrosoftCryptoImpl::aesKeyProvider; |
| 27 |
| 28 | /*struct tgvoip_cx_data{ |
| 29 | VoIPControllerWrapper^ self; |
| 30 | };*/ |
| 31 |
| 32 | VoIPControllerWrapper::VoIPControllerWrapper() |
| 33 | { |
| 34 | VoIPController::crypto.aes_ige_decrypt = MicrosoftCryptoImpl::AesIgeDecrypt; |
| 35 | VoIPController::crypto.aes_ige_encrypt = MicrosoftCryptoImpl::AesIgeEncrypt; |
| 36 | VoIPController::crypto.aes_ctr_encrypt = MicrosoftCryptoImpl::AesCtrEncrypt; |
| 37 | VoIPController::crypto.sha1 = MicrosoftCryptoImpl::SHA1; |
| 38 | VoIPController::crypto.sha256 = MicrosoftCryptoImpl::SHA256; |
| 39 | VoIPController::crypto.rand_bytes = MicrosoftCryptoImpl::RandBytes; |
| 40 | MicrosoftCryptoImpl::Init(); |
| 41 | controller = new VoIPController(); |
| 42 | controller->implData = (void*)this; |
| 43 | VoIPController::Callbacks callbacks = {0}; |
| 44 | callbacks.connectionStateChanged = VoIPControllerWrapper::OnStateChanged; |
| 45 | callbacks.signalBarCountChanged = VoIPControllerWrapper::OnSignalBarsChanged; |
| 46 | controller->SetCallbacks(callbacks); |
| 47 | } |
| 48 |
| 49 | VoIPControllerWrapper::~VoIPControllerWrapper() |
| 50 | { |
| 51 | controller->Stop(); |
| 52 | delete controller; |
| 53 | } |
| 54 |
| 55 | void VoIPControllerWrapper::Start() |
| 56 | { |
| 57 | controller->Start(); |
| 58 | } |
| 59 |
| 60 | void VoIPControllerWrapper::Connect() |
| 61 | { |
| 62 | controller->Connect(); |
| 63 | } |
| 64 |
| 65 | void VoIPControllerWrapper::SetPublicEndpoints(const Platform::Array<libtgvoip::Endpoint ^> ^ endpoints, bool allowP2P, std::int32_t connectionMaxLayer) |
| 66 | { |
| 67 | std::vector<tgvoip::Endpoint> eps; |
| 68 | for (unsigned int i = 0; i < endpoints->Length; i++) |
| 69 | { |
| 70 | libtgvoip::Endpoint ^ _ep = endpoints[i]; |
| 71 | tgvoip::Endpoint ep; |
| 72 | ep.id = _ep->id; |
| 73 | ep.type = tgvoip::Endpoint::Type::UDP_RELAY; |
| 74 | char buf[128]; |
| 75 | if (_ep->ipv4) |
| 76 | { |
| 77 | WideCharToMultiByte(CP_UTF8, 0, _ep->ipv4->Data(), -1, buf, sizeof(buf), nullptr, nullptr); |
| 78 | ep.address = NetworkAddress::IPv4(buf); |
| 79 | } |
| 80 | if (_ep->ipv6) |
| 81 | { |
| 82 | WideCharToMultiByte(CP_UTF8, 0, _ep->ipv6->Data(), -1, buf, sizeof(buf), nullptr, nullptr); |
| 83 | ep.v6address = NetworkAddress::IPv6(buf); |
| 84 | } |
| 85 | ep.port = _ep->port; |
| 86 | if (_ep->peerTag->Length != 16) |
| 87 | throw ref new Platform::InvalidArgumentException("Peer tag must be exactly 16 bytes long"); |
| 88 | std::memcpy(ep.peerTag, _ep->peerTag->Data, 16); |
| 89 | eps.emplace_back(ep); |
| 90 | } |
| 91 | controller->SetRemoteEndpoints(eps, allowP2P, connectionMaxLayer); |
| 92 | } |
| 93 |
| 94 | void VoIPControllerWrapper::SetNetworkType(NetworkType type) |
| 95 | { |
| 96 | controller->SetNetworkType((int)type); |
| 97 | } |
| 98 |
| 99 | void VoIPControllerWrapper::SetMicMute(bool mute) |
| 100 | { |
| 101 | controller->SetMicMute(mute); |
| 102 | } |
| 103 |
| 104 | int64 VoIPControllerWrapper::GetPreferredRelayID() |
| 105 | { |
| 106 | return controller->GetPreferredRelayID(); |
| 107 | } |
| 108 |
| 109 | std::int32_t VoIPControllerWrapper::GetConnectionMaxLayer() |
| 110 | { |
| 111 | return tgvoip::VoIPController::GetConnectionMaxLayer(); |
| 112 | } |
| 113 |
| 114 | void VoIPControllerWrapper::SetEncryptionKey(const Platform::Array<uint8> ^ key, bool isOutgoing) |
| 115 | { |
| 116 | if (key->Length != 256) |
| 117 | throw ref new Platform::InvalidArgumentException("Encryption key must be exactly 256 bytes long"); |
| 118 | controller->SetEncryptionKey((char*)key->Data, isOutgoing); |
| 119 | } |
| 120 |
| 121 | int VoIPControllerWrapper::GetSignalBarsCount() |
| 122 | { |
| 123 | return controller->GetSignalBarsCount(); |
| 124 | } |
| 125 |
| 126 | CallState VoIPControllerWrapper::GetConnectionState() |
| 127 | { |
| 128 | return (CallState)controller->GetConnectionState(); |
| 129 | } |
| 130 |
| 131 | TrafficStats ^ VoIPControllerWrapper::GetStats() |
| 132 | { |
| 133 | tgvoip::VoIPController::TrafficStats _stats; |
| 134 | controller->GetStats(&_stats); |
| 135 |
| 136 | TrafficStats ^ stats = ref new TrafficStats(); |
| 137 | stats->bytesSentWifi = _stats.bytesSentWifi; |
| 138 | stats->bytesSentMobile = _stats.bytesSentMobile; |
| 139 | stats->bytesRecvdWifi = _stats.bytesRecvdWifi; |
| 140 | stats->bytesRecvdMobile = _stats.bytesRecvdMobile; |
| 141 |
| 142 | return stats; |
| 143 | } |
| 144 |
| 145 | Platform::String ^ VoIPControllerWrapper::GetDebugString() |
| 146 | { |
| 147 | std::string log = controller->GetDebugString(); |
| 148 | std::size_t len = sizeof(wchar_t) * (log.length() + 1); |
| 149 | wchar_t* wlog = (wchar_t*)std::malloc(len); |
| 150 | MultiByteToWideChar(CP_UTF8, 0, log.c_str(), -1, wlog, len / sizeof(wchar_t)); |
| 151 | Platform::String ^ res = ref new Platform::String(wlog); |
| 152 | std::free(wlog); |
| 153 | return res; |
| 154 | } |
| 155 |
| 156 | Platform::String ^ VoIPControllerWrapper::GetDebugLog() |
| 157 | { |
| 158 | std::string log = controller->GetDebugLog(); |
| 159 | std::size_t len = sizeof(wchar_t) * (log.length() + 1); |
| 160 | wchar_t* wlog = (wchar_t*)std::malloc(len); |
| 161 | MultiByteToWideChar(CP_UTF8, 0, log.c_str(), -1, wlog, len / sizeof(wchar_t)); |
| 162 | Platform::String ^ res = ref new Platform::String(wlog); |
| 163 | std::free(wlog); |
| 164 | return res; |
| 165 | } |
| 166 |
| 167 | Error VoIPControllerWrapper::GetLastError() |
| 168 | { |
| 169 | return (Error)controller->GetLastError(); |
| 170 | } |
| 171 |
| 172 | Platform::String ^ VoIPControllerWrapper::GetVersion() |
| 173 | { |
| 174 | const char* v = VoIPController::GetVersion(); |
| 175 | wchar_t buf[32]; |
| 176 | MultiByteToWideChar(CP_UTF8, 0, v, -1, buf, sizeof(buf)); |
| 177 | return ref new Platform::String(buf); |
| 178 | } |
| 179 |
| 180 | void VoIPControllerWrapper::OnStateChanged(VoIPController* c, int state) |
| 181 | { |
| 182 | reinterpret_cast<VoIPControllerWrapper ^>(c->implData)->OnStateChangedInternal(state); |
| 183 | } |
| 184 |
| 185 | void VoIPControllerWrapper::OnSignalBarsChanged(VoIPController* c, int count) |
| 186 | { |
| 187 | reinterpret_cast<VoIPControllerWrapper ^>(c->implData)->OnSignalBarsChangedInternal(count); |
| 188 | } |
| 189 |
| 190 | void VoIPControllerWrapper::OnStateChangedInternal(int state) |
| 191 | { |
| 192 | CallStateChanged(this, (CallState)state); |
| 193 | } |
| 194 |
| 195 | void VoIPControllerWrapper::OnSignalBarsChangedInternal(int count) |
| 196 | { |
| 197 | SignalBarsChanged(this, count); |
| 198 | } |
| 199 |
| 200 | void VoIPControllerWrapper::SetConfig(VoIPConfig ^ wrapper) |
| 201 | { |
| 202 | VoIPController::Config config {0}; |
| 203 | config.initTimeout = wrapper->initTimeout; |
| 204 | config.recvTimeout = wrapper->recvTimeout; |
| 205 | config.dataSaving = (int)wrapper->dataSaving; |
| 206 | config.logFilePath; |
| 207 | config.statsDumpFilePath; |
| 208 |
| 209 | config.enableAEC = wrapper->enableAEC; |
| 210 | config.enableNS = wrapper->enableNS; |
| 211 | config.enableAGC = wrapper->enableAGC; |
| 212 |
| 213 | config.enableCallUpgrade = wrapper->enableCallUpgrade; |
| 214 |
| 215 | config.logPacketStats = wrapper->logPacketStats; |
| 216 | config.enableVolumeControl = wrapper->enableVolumeControl; |
| 217 |
| 218 | config.enableVideoSend = wrapper->enableVideoSend; |
| 219 | config.enableVideoReceive = wrapper->enableVideoReceive; |
| 220 |
| 221 | if (wrapper->logFilePath != nullptr && !wrapper->logFilePath->IsEmpty()) |
| 222 | { |
| 223 | config.logFilePath = wstring(wrapper->logFilePath->Data()); |
| 224 | } |
| 225 | if (wrapper->statsDumpFilePath != nullptr && !wrapper->statsDumpFilePath->IsEmpty()) |
| 226 | { |
| 227 | config.statsDumpFilePath = wstring(wrapper->statsDumpFilePath->Data()); |
| 228 | } |
| 229 |
| 230 | controller->SetConfig(config); |
| 231 | } |
| 232 |
| 233 | void VoIPControllerWrapper::SetProxy(ProxyProtocol protocol, Platform::String ^ address, std::uint16_t port, Platform::String ^ username, Platform::String ^ password) |
| 234 | { |
| 235 | char _address[2000]; |
| 236 | char _username[256]; |
| 237 | char _password[256]; |
| 238 |
| 239 | WideCharToMultiByte(CP_UTF8, 0, address->Data(), -1, _address, sizeof(_address), nullptr, nullptr); |
| 240 | WideCharToMultiByte(CP_UTF8, 0, username->Data(), -1, _username, sizeof(_username), nullptr, nullptr); |
| 241 | WideCharToMultiByte(CP_UTF8, 0, password->Data(), -1, _password, sizeof(_password), nullptr, nullptr); |
| 242 |
| 243 | controller->SetProxy((int)protocol, _address, port, _username, _password); |
| 244 | } |
| 245 |
| 246 | void VoIPControllerWrapper::SetAudioOutputGainControlEnabled(bool enabled) |
| 247 | { |
| 248 | controller->SetAudioOutputGainControlEnabled(enabled); |
| 249 | } |
| 250 |
| 251 | void VoIPControllerWrapper::SetInputVolume(float level) |
| 252 | { |
| 253 | controller->SetInputVolume(level); |
| 254 | } |
| 255 |
| 256 | void VoIPControllerWrapper::SetOutputVolume(float level) |
| 257 | { |
| 258 | controller->SetOutputVolume(level); |
| 259 | } |
| 260 |
| 261 | void VoIPControllerWrapper::UpdateServerConfig(Platform::String ^ json) |
| 262 | { |
| 263 | std::string config = ToUtf8(json->Data(), json->Length()); |
| 264 | ServerConfig::GetSharedInstance()->Update(config); |
| 265 | } |
| 266 |
| 267 | void VoIPControllerWrapper::SwitchSpeaker(bool external) |
| 268 | { |
| 269 | auto routingManager = AudioRoutingManager::GetDefault(); |
| 270 | if (external) |
| 271 | { |
| 272 | routingManager->SetAudioEndpoint(AudioRoutingEndpoint::Speakerphone); |
| 273 | } |
| 274 | else |
| 275 | { |
| 276 | if ((routingManager->AvailableAudioEndpoints & AvailableAudioRoutingEndpoints::Bluetooth) == AvailableAudioRoutingEndpoints::Bluetooth) |
| 277 | { |
| 278 | routingManager->SetAudioEndpoint(AudioRoutingEndpoint::Bluetooth); |
| 279 | } |
| 280 | else if ((routingManager->AvailableAudioEndpoints & AvailableAudioRoutingEndpoints::Earpiece) == AvailableAudioRoutingEndpoints::Earpiece) |
| 281 | { |
| 282 | routingManager->SetAudioEndpoint(AudioRoutingEndpoint::Earpiece); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 |
| 287 | void MicrosoftCryptoImpl::AesIgeEncrypt(std::uint8_t* in, std::uint8_t* out, std::size_t len, std::uint8_t* key, std::uint8_t* iv) |
| 288 | { |
| 289 | IBuffer ^ keybuf = IBufferFromPtr(key, 32); |
| 290 | CryptographicKey ^ _key = aesKeyProvider->CreateSymmetricKey(keybuf); |
| 291 | std::uint8_t tmpOut[16]; |
| 292 | std::uint8_t* xPrev = iv + 16; |
| 293 | std::uint8_t* yPrev = iv; |
| 294 | std::uint8_t x[16]; |
| 295 | std::uint8_t y[16]; |
| 296 | for (std::size_t offset = 0; offset < len; offset += 16) |
| 297 | { |
| 298 | for (std::size_t i = 0; i < 16; i++) |
| 299 | { |
| 300 | if (offset + i < len) |
| 301 | { |
| 302 | x[i] = in[offset + i]; |
| 303 | } |
| 304 | else |
| 305 | { |
| 306 | x[i] = 0; |
| 307 | } |
| 308 | } |
| 309 | XorInt128(x, yPrev, y); |
| 310 | IBuffer ^ inbuf = IBufferFromPtr(y, 16); |
| 311 | IBuffer ^ outbuf = CryptographicEngine::Encrypt(_key, inbuf, nullptr); |
| 312 | IBufferToPtr(outbuf, 16, tmpOut); |
| 313 | XorInt128(tmpOut, xPrev, y); |
| 314 | std::memcpy(xPrev, x, 16); |
| 315 | std::memcpy(yPrev, y, 16); |
| 316 | std::memcpy(out + offset, y, 16); |
| 317 | } |
| 318 | } |
| 319 |
| 320 | void MicrosoftCryptoImpl::AesIgeDecrypt(std::uint8_t* in, std::uint8_t* out, std::size_t len, std::uint8_t* key, std::uint8_t* iv) |
| 321 | { |
| 322 | IBuffer ^ keybuf = IBufferFromPtr(key, 32); |
| 323 | CryptographicKey ^ _key = aesKeyProvider->CreateSymmetricKey(keybuf); |
| 324 | std::uint8_t tmpOut[16]; |
| 325 | std::uint8_t* xPrev = iv; |
| 326 | std::uint8_t* yPrev = iv + 16; |
| 327 | std::uint8_t x[16]; |
| 328 | std::uint8_t y[16]; |
| 329 | for (std::size_t offset = 0; offset < len; offset += 16) |
| 330 | { |
| 331 | for (std::size_t i = 0; i < 16; i++) |
| 332 | { |
| 333 | if (offset + i < len) |
| 334 | { |
| 335 | x[i] = in[offset + i]; |
| 336 | } |
| 337 | else |
| 338 | { |
| 339 | x[i] = 0; |
| 340 | } |
| 341 | } |
| 342 | XorInt128(x, yPrev, y); |
| 343 | IBuffer ^ inbuf = IBufferFromPtr(y, 16); |
| 344 | IBuffer ^ outbuf = CryptographicEngine::Decrypt(_key, inbuf, nullptr); |
| 345 | IBufferToPtr(outbuf, 16, tmpOut); |
| 346 | XorInt128(tmpOut, xPrev, y); |
| 347 | std::memcpy(xPrev, x, 16); |
| 348 | std::memcpy(yPrev, y, 16); |
| 349 | std::memcpy(out + offset, y, 16); |
| 350 | } |
| 351 | } |
| 352 |
| 353 | #define GETU32(pt) (((std::uint32_t)(pt)[0] << 24) ^ ((std::uint32_t)(pt)[1] << 16) ^ ((std::uint32_t)(pt)[2] << 8) ^ ((std::uint32_t)(pt)[3])) |
| 354 | #define PUTU32(ct, st) \ |
| 355 | { \ |
| 356 | (ct)[0] = (u8)((st) >> 24); \ |
| 357 | (ct)[1] = (u8)((st) >> 16); \ |
| 358 | (ct)[2] = (u8)((st) >> 8); \ |
| 359 | (ct)[3] = (u8)(st); \ |
| 360 | } |
| 361 |
| 362 | typedef std::uint8_t u8; |
| 363 |
| 364 | #define L_ENDIAN |
| 365 |
| 366 | /* increment counter (128-bit int) by 2^64 */ |
| 367 | static void AES_ctr128_inc(std::uint8_t* counter) |
| 368 | { |
| 369 | unsigned long c; |
| 370 |
| 371 | /* Grab 3rd dword of counter and increment */ |
| 372 | #ifdef L_ENDIAN |
| 373 | c = GETU32(counter + 8); |
| 374 | c++; |
| 375 | PUTU32(counter + 8, c); |
| 376 | #else |
| 377 | c = GETU32(counter + 4); |
| 378 | c++; |
| 379 | PUTU32(counter + 4, c); |
| 380 | #endif |
| 381 |
| 382 | /* if no overflow, we're done */ |
| 383 | if (c) |
| 384 | return; |
| 385 |
| 386 | /* Grab top dword of counter and increment */ |
| 387 | #ifdef L_ENDIAN |
| 388 | c = GETU32(counter + 12); |
| 389 | c++; |
| 390 | PUTU32(counter + 12, c); |
| 391 | #else |
| 392 | c = GETU32(counter + 0); |
| 393 | c++; |
| 394 | PUTU32(counter + 0, c); |
| 395 | #endif |
| 396 | } |
| 397 |
| 398 | void MicrosoftCryptoImpl::AesCtrEncrypt(std::uint8_t* inout, std::size_t len, std::uint8_t* key, std::uint8_t* counter, std::uint8_t* ecount_buf, std::uint32_t* num) |
| 399 | { |
| 400 | unsigned int n; |
| 401 | unsigned long l = len; |
| 402 |
| 403 | //assert(in && out && key && counter && num); |
| 404 | //assert(*num < AES_BLOCK_SIZE); |
| 405 |
| 406 | IBuffer ^ keybuf = IBufferFromPtr(key, 32); |
| 407 | CryptographicKey ^ _key = aesKeyProvider->CreateSymmetricKey(keybuf); |
| 408 |
| 409 | n = *num; |
| 410 |
| 411 | while (l--) |
| 412 | { |
| 413 | if (n == 0) |
| 414 | { |
| 415 | IBuffer ^ inbuf = IBufferFromPtr(counter, 16); |
| 416 | IBuffer ^ outbuf = CryptographicEngine::Encrypt(_key, inbuf, nullptr); |
| 417 | IBufferToPtr(outbuf, 16, ecount_buf); |
| 418 | //AES_encrypt(counter, ecount_buf, key); |
| 419 | AES_ctr128_inc(counter); |
| 420 | } |
| 421 | *inout = *(inout++) ^ ecount_buf[n]; |
| 422 | n = (n + 1) % 16; |
| 423 | } |
| 424 |
| 425 | *num = n; |
| 426 | } |
| 427 |
| 428 | void MicrosoftCryptoImpl::SHA1(std::uint8_t* msg, std::size_t len, std::uint8_t* out) |
| 429 | { |
| 430 | //EnterCriticalSection(&hashMutex); |
| 431 |
| 432 | IBuffer ^ arr = IBufferFromPtr(msg, len); |
| 433 | CryptographicHash ^ hash = sha1Provider->CreateHash(); |
| 434 | hash->Append(arr); |
| 435 | IBuffer ^ res = hash->GetValueAndReset(); |
| 436 | IBufferToPtr(res, 20, out); |
| 437 |
| 438 | //LeaveCriticalSection(&hashMutex); |
| 439 | } |
| 440 |
| 441 | void MicrosoftCryptoImpl::SHA256(std::uint8_t* msg, std::size_t len, std::uint8_t* out) |
| 442 | { |
| 443 | //EnterCriticalSection(&hashMutex); |
| 444 |
| 445 | IBuffer ^ arr = IBufferFromPtr(msg, len); |
| 446 | CryptographicHash ^ hash = sha256Provider->CreateHash(); |
| 447 | hash->Append(arr); |
| 448 | IBuffer ^ res = hash->GetValueAndReset(); |
| 449 | IBufferToPtr(res, 32, out); |
| 450 | //LeaveCriticalSection(&hashMutex); |
| 451 | } |
| 452 |
| 453 | void MicrosoftCryptoImpl::RandBytes(std::uint8_t* buffer, std::size_t len) |
| 454 | { |
| 455 | IBuffer ^ res = CryptographicBuffer::GenerateRandom(len); |
| 456 | IBufferToPtr(res, len, buffer); |
| 457 | } |
| 458 |
| 459 | void MicrosoftCryptoImpl::Init() |
| 460 | { |
| 461 | /*sha1Hash=HashAlgorithmProvider::OpenAlgorithm(HashAlgorithmNames::Sha1)->CreateHash(); |
| 462 | sha256Hash=HashAlgorithmProvider::OpenAlgorithm(HashAlgorithmNames::Sha256)->CreateHash();*/ |
| 463 | sha1Provider = HashAlgorithmProvider::OpenAlgorithm(HashAlgorithmNames::Sha1); |
| 464 | sha256Provider = HashAlgorithmProvider::OpenAlgorithm(HashAlgorithmNames::Sha256); |
| 465 | aesKeyProvider = SymmetricKeyAlgorithmProvider::OpenAlgorithm(SymmetricAlgorithmNames::AesEcb); |
| 466 | } |
| 467 |
| 468 | void MicrosoftCryptoImpl::XorInt128(std::uint8_t* a, std::uint8_t* b, std::uint8_t* out) |
| 469 | { |
| 470 | std::uint64_t* _a = reinterpret_cast<std::uint64_t*>(a); |
| 471 | std::uint64_t* _b = reinterpret_cast<std::uint64_t*>(b); |
| 472 | std::uint64_t* _out = reinterpret_cast<std::uint64_t*>(out); |
| 473 | _out[0] = _a[0] ^ _b[0]; |
| 474 | _out[1] = _a[1] ^ _b[1]; |
| 475 | } |
| 476 |
| 477 | void MicrosoftCryptoImpl::IBufferToPtr(IBuffer ^ buffer, std::size_t len, std::uint8_t* out) |
| 478 | { |
| 479 | ComPtr<IBufferByteAccess> bufferByteAccess; |
| 480 | reinterpret_cast<IInspectable*>(buffer)->QueryInterface(IID_PPV_ARGS(&bufferByteAccess)); |
| 481 |
| 482 | byte* hashBuffer; |
| 483 | bufferByteAccess->Buffer(&hashBuffer); |
| 484 | CopyMemory(out, hashBuffer, len); |
| 485 | } |
| 486 |
| 487 | IBuffer ^ MicrosoftCryptoImpl::IBufferFromPtr(std::uint8_t* msg, std::size_t len) |
| 488 | { |
| 489 | ComPtr<NativeBuffer> nativeBuffer = Make<NativeBuffer>((byte*)msg, len); |
| 490 | return reinterpret_cast<IBuffer ^>(nativeBuffer.Get()); |
| 491 | } |
| 492 |
| 493 | /*Platform::String^ VoIPControllerWrapper::TestAesIge(){ |
| 494 | MicrosoftCryptoImpl::Init(); |
| 495 | Platform::String^ res=""; |
| 496 | Platform::Array<uint8>^ data=ref new Platform::Array<uint8>(32); |
| 497 | Platform::Array<uint8>^ out=ref new Platform::Array<uint8>(32); |
| 498 | Platform::Array<uint8>^ key=ref new Platform::Array<uint8>(16); |
| 499 | Platform::Array<uint8>^ iv=ref new Platform::Array<uint8>(32); |
| 500 |
| 501 |
| 502 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("0000000000000000000000000000000000000000000000000000000000000000"), &data); |
| 503 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"), &iv); |
| 504 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("000102030405060708090a0b0c0d0e0f"), &key); |
| 505 | MicrosoftCryptoImpl::AesIgeEncrypt(data->Data, out->Data, 32, key->Data, iv->Data); |
| 506 | res+=CryptographicBuffer::EncodeToHexString(CryptographicBuffer::CreateFromByteArray(out)); |
| 507 | res+="\n"; |
| 508 |
| 509 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("1A8519A6557BE652E9DA8E43DA4EF4453CF456B4CA488AA383C79C98B34797CB"), &data); |
| 510 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"), &iv); |
| 511 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("000102030405060708090a0b0c0d0e0f"), &key); |
| 512 | MicrosoftCryptoImpl::AesIgeDecrypt(data->Data, out->Data, 32, key->Data, iv->Data); |
| 513 | res+=CryptographicBuffer::EncodeToHexString(CryptographicBuffer::CreateFromByteArray(out)); |
| 514 | res+="\n"; |
| 515 |
| 516 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("99706487A1CDE613BC6DE0B6F24B1C7AA448C8B9C3403E3467A8CAD89340F53B"), &data); |
| 517 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("6D656E746174696F6E206F6620494745206D6F646520666F72204F70656E5353"), &iv); |
| 518 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("5468697320697320616E20696D706C65"), &key); |
| 519 | MicrosoftCryptoImpl::AesIgeEncrypt(data->Data, out->Data, 32, key->Data, iv->Data); |
| 520 | res+=CryptographicBuffer::EncodeToHexString(CryptographicBuffer::CreateFromByteArray(out)); |
| 521 | res+="\n"; |
| 522 |
| 523 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("4C2E204C6574277320686F70652042656E20676F74206974207269676874210A"), &data); |
| 524 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("6D656E746174696F6E206F6620494745206D6F646520666F72204F70656E5353"), &iv); |
| 525 | CryptographicBuffer::CopyToByteArray(CryptographicBuffer::DecodeFromHexString("5468697320697320616E20696D706C65"), &key); |
| 526 | MicrosoftCryptoImpl::AesIgeDecrypt(data->Data, out->Data, 32, key->Data, iv->Data); |
| 527 | res+=CryptographicBuffer::EncodeToHexString(CryptographicBuffer::CreateFromByteArray(out)); |
| 528 | return res; |
| 529 | }*/ |
| 530 |