uwp.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* Snippets extracted from https://github.com/Microsoft/openssl/blob/ec7e430e06e4e3ac87c183dee33cb216814cf980/ms/winrt.cpp
  2. * Adapted for Godot definitions
  3. */
  4. /* uwp.cpp
  5. * Copyright 2014 Microsoft Corporation
  6. * C++/CX Entropy/shims for Windows Phone/Windows Store platform
  7. * written by Alejandro Jimenez Martinez
  8. * (aljim@microsoft.com) for the OpenSSL project 2014.
  9. */
  10. #include <windows.h>
  11. #if defined(WINAPI_FAMILY)
  12. extern "C"
  13. {
  14. unsigned entropyRT(BYTE *buffer, unsigned len);
  15. void RAND_add(const void *buf,int num,double entropy);
  16. int RAND_poll(void);
  17. }
  18. #endif
  19. unsigned entropyRT(BYTE *buffer, unsigned len)
  20. {
  21. using namespace Platform;
  22. using namespace Windows::Foundation;
  23. using namespace Windows::Foundation::Collections;
  24. using namespace Windows::Security::Cryptography;
  25. using namespace Windows::Storage::Streams;
  26. IBuffer ^buf = CryptographicBuffer::GenerateRandom(len);
  27. Array<unsigned char> ^arr;
  28. CryptographicBuffer::CopyToByteArray(buf, &arr);
  29. unsigned arrayLen = arr->Length;
  30. // Make sure not to overflow the copy
  31. arrayLen = (arrayLen > len) ? len : arrayLen;
  32. memcpy(buffer, arr->Data, arrayLen);
  33. return arrayLen;
  34. }
  35. int RAND_poll(void)
  36. {
  37. BYTE buf[60];
  38. unsigned collected = entropyRT(buf , sizeof(buf));
  39. RAND_add(buf, collected, collected);
  40. return 1;
  41. }
  42. #if defined(UWP_ENABLED)
  43. extern "C"
  44. {
  45. #include<stdio.h>
  46. #include<string.h>
  47. #include<stdlib.h>
  48. void* GetModuleHandle(
  49. _In_opt_ LPCTSTR lpModuleName
  50. )
  51. {
  52. return NULL;
  53. }
  54. //no log for phone
  55. int RegisterEventSource(
  56. _In_ LPCTSTR lpUNCServerName,
  57. _In_ LPCTSTR lpSourceName
  58. )
  59. {
  60. return NULL;
  61. }
  62. int ReportEvent(
  63. _In_ HANDLE hEventLog,
  64. _In_ WORD wType,
  65. _In_ WORD wCategory,
  66. _In_ DWORD dwEventID,
  67. _In_ PSID lpUserSid,
  68. _In_ WORD wNumStrings,
  69. _In_ DWORD dwDataSize,
  70. _In_ LPCTSTR *lpStrings,
  71. _In_ LPVOID lpRawData
  72. )
  73. {
  74. return 0;
  75. }
  76. int MessageBox(
  77. _In_opt_ HWND hWnd,
  78. _In_opt_ LPCTSTR lpText,
  79. _In_opt_ LPCTSTR lpCaption,
  80. _In_ UINT uType
  81. )
  82. {
  83. return 0;
  84. }
  85. int __cdecl GetProcessWindowStation(void)
  86. {
  87. return NULL;
  88. }
  89. BOOL __cdecl GetUserObjectInformationW(
  90. _In_ HANDLE hObj,
  91. _In_ int nIndex,
  92. _Out_opt_ PVOID pvInfo,
  93. _In_ DWORD nLength,
  94. _Out_opt_ LPDWORD lpnLengthNeeded
  95. )
  96. {
  97. return 0;
  98. }
  99. int __cdecl GetStdHandle(
  100. _In_ DWORD nStdHandle
  101. )
  102. {
  103. return 0;
  104. }
  105. BOOL DeregisterEventSource(
  106. _Inout_ HANDLE hEventLog
  107. )
  108. {
  109. return 0;
  110. }
  111. char *getenv(
  112. const char *varname
  113. )
  114. {
  115. //hardcoded environmental variables used for the appx testing application for store/phone
  116. if (!strcmp(varname, "OPENSSL_CONF"))
  117. {
  118. return "./openssl.cnf";
  119. }
  120. return 0;
  121. }
  122. int setenv(const char *envname, const char *envval, int overwrite)
  123. {
  124. return -1;
  125. }
  126. int _getch(void)
  127. {
  128. return 0;
  129. }
  130. int _kbhit()
  131. {
  132. return 0;
  133. }
  134. BOOL __cdecl FlushConsoleInputBuffer(
  135. _In_ HANDLE hConsoleInput
  136. )
  137. {
  138. return 0;
  139. }
  140. int uwp_GetTickCount(void)
  141. {
  142. LARGE_INTEGER t;
  143. return(int) (QueryPerformanceCounter(&t) ? t.QuadPart : 0);
  144. }
  145. void *OPENSSL_UplinkTable [26]= {0};
  146. } //extern C
  147. #endif /*defined(UWP_ENABLED)*/