---
mingw-w64-headers/include/wincrypt.h | 12 +--
mingw-w64-libraries/winstorecompat/Makefile.am | 1 +
mingw-w64-libraries/winstorecompat/src/Crypto.c | 113 ++++++++++++++++++++++++
3 files changed, 121 insertions(+), 5 deletions(-)
create mode 100644 mingw-w64-libraries/winstorecompat/src/Crypto.c
diff --git a/mingw-w64-headers/include/wincrypt.h
b/mingw-w64-headers/include/wincrypt.h
index a4d4055..3bd84ce 100644
--- a/mingw-w64-headers/include/wincrypt.h
+++ b/mingw-w64-headers/include/wincrypt.h
@@ -697,6 +697,13 @@ extern "C" {
#endif
#endif
+#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP) ||
defined(WINSTORECOMPAT)
+ WINIMPM WINBOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR
szContainer, LPCSTR szProvider, DWORD dwProvType, DWORD dwFlags);
+ WINIMPM WINBOOL WINAPI CryptAcquireContextW (HCRYPTPROV *phProv, LPCWSTR
szContainer, LPCWSTR szProvider, DWORD dwProvType, DWORD dwFlags);
+#define CryptAcquireContext __MINGW_NAME_AW(CryptAcquireContext)
+ WINIMPM WINBOOL WINAPI CryptReleaseContext (HCRYPTPROV hProv, DWORD dwFlags);
+ WINIMPM WINBOOL WINAPI CryptGenRandom (HCRYPTPROV hProv, DWORD dwLen, BYTE
*pbBuffer);
+#endif
#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP)
typedef struct _CMS_DH_KEY_INFO {
DWORD dwVersion;
@@ -706,7 +713,6 @@ extern "C" {
void *pReserved;
} CMS_DH_KEY_INFO,*PCMS_DH_KEY_INFO;
-#define CryptAcquireContext __MINGW_NAME_AW(CryptAcquireContext)
#define CryptSignHash __MINGW_NAME_AW(CryptSignHash)
#define CryptVerifySignature __MINGW_NAME_AW(CryptVerifySignature)
#define CryptSetProvider __MINGW_NAME_AW(CryptSetProvider)
@@ -715,9 +721,6 @@ extern "C" {
#define CryptEnumProviderTypes __MINGW_NAME_AW(CryptEnumProviderTypes)
#define CryptEnumProviders __MINGW_NAME_AW(CryptEnumProviders)
- WINIMPM WINBOOL WINAPI CryptAcquireContextA (HCRYPTPROV *phProv, LPCSTR
szContainer, LPCSTR szProvider, DWORD dwProvType, DWORD dwFlags);
- WINIMPM WINBOOL WINAPI CryptAcquireContextW (HCRYPTPROV *phProv, LPCWSTR
szContainer, LPCWSTR szProvider, DWORD dwProvType, DWORD dwFlags);
- WINIMPM WINBOOL WINAPI CryptReleaseContext (HCRYPTPROV hProv, DWORD dwFlags);
WINIMPM WINBOOL WINAPI CryptGenKey (HCRYPTPROV hProv, ALG_ID Algid, DWORD
dwFlags, HCRYPTKEY *phKey);
WINIMPM WINBOOL WINAPI CryptDeriveKey (HCRYPTPROV hProv, ALG_ID Algid,
HCRYPTHASH hBaseData, DWORD dwFlags, HCRYPTKEY *phKey);
WINIMPM WINBOOL WINAPI CryptDestroyKey (HCRYPTKEY hKey);
@@ -727,7 +730,6 @@ extern "C" {
WINIMPM WINBOOL WINAPI CryptGetHashParam (HCRYPTHASH hHash, DWORD dwParam,
BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags);
WINIMPM WINBOOL WINAPI CryptSetProvParam (HCRYPTPROV hProv, DWORD dwParam,
CONST BYTE *pbData, DWORD dwFlags);
WINIMPM WINBOOL WINAPI CryptGetProvParam (HCRYPTPROV hProv, DWORD dwParam,
BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags);
- WINIMPM WINBOOL WINAPI CryptGenRandom (HCRYPTPROV hProv, DWORD dwLen, BYTE
*pbBuffer);
WINIMPM WINBOOL WINAPI CryptGetUserKey (HCRYPTPROV hProv, DWORD dwKeySpec,
HCRYPTKEY *phUserKey);
WINIMPM WINBOOL WINAPI CryptExportKey (HCRYPTKEY hKey, HCRYPTKEY hExpKey,
DWORD dwBlobType, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen);
WINIMPM WINBOOL WINAPI CryptImportKey (HCRYPTPROV hProv, CONST BYTE *pbData,
DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey);
diff --git a/mingw-w64-libraries/winstorecompat/Makefile.am
b/mingw-w64-libraries/winstorecompat/Makefile.am
index 33d411e..332cae5 100644
--- a/mingw-w64-libraries/winstorecompat/Makefile.am
+++ b/mingw-w64-libraries/winstorecompat/Makefile.am
@@ -35,4 +35,5 @@ libwinstorecompat_a_SOURCES = \
src/Tls.c \
src/SHGetFolderPathW.c \
src/QueueTimer.c \
+ src/Crypto.c \
$(NULL)
diff --git a/mingw-w64-libraries/winstorecompat/src/Crypto.c
b/mingw-w64-libraries/winstorecompat/src/Crypto.c
new file mode 100644
index 0000000..4d58e9e
--- /dev/null
+++ b/mingw-w64-libraries/winstorecompat/src/Crypto.c
@@ -0,0 +1,113 @@
+/*
+ Copyright (c) 2016 mingw-w64 project
+
+ Contributing authors: Steve Lhomme, Hugo Beauzée-Luyssen
+
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the "Software"),
+ to deal in the Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ and/or sell copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ DEALINGS IN THE SOFTWARE.
+*/
+
+#define _WIN32_WINNT 0x602
+
+#define CryptAcquireContextW __CryptAcquireContextW
+#define CryptAcquireContextA __CryptAcquireContextA
+#define CryptReleaseContext __CryptReleaseContext
+#define CryptGenRandom __CryptGenRandom
+#define COBJMACROS
+#define INITGUID
+#include <windef.h>
+#include <windows.h>
+#include <windows.security.cryptography.h>
+#include <winstring.h>
+#include <roapi.h>
+#undef CertOpenSystemStore
+#undef CryptGenRandom
+#undef CryptReleaseContext
+#undef CryptAcquireContextA
+#undef CryptAcquireContextW
+
+#define HCRYPTPROV ICryptographicBufferStatics *
+
+BOOL WINAPI CryptAcquireContextW(HCRYPTPROV *phProv, LPCTSTR pszContainer,
LPCTSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
+{
+ static const WCHAR *className =
L"Windows.Security.Cryptography.CryptographicBuffer";
+ const UINT32 clen = wcslen(className);
+
+ HSTRING hClassName = NULL;
+ HSTRING_HEADER header;
+ HRESULT hr = WindowsCreateStringReference(className, clen, &header,
&hClassName);
+ if (FAILED(hr)) {
+ WindowsDeleteString(hClassName);
+ return FALSE;
+ }
+
+ ICryptographicBufferStatics *cryptoStatics = NULL;
+ hr = RoGetActivationFactory(hClassName, &IID_ICryptographicBufferStatics,
(void**)&cryptoStatics);
+ WindowsDeleteString(hClassName);
+
+ if (FAILED(hr))
+ return FALSE;
+
+ *phProv = cryptoStatics;
+
+ return TRUE;
+}
+
+BOOL WINAPI CryptAcquireContextA(HCRYPTPROV *phProv, LPCTSTR pszContainer,
LPCTSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
+{
+ return FALSE;
+}
+
+BOOL WINAPI CryptReleaseContext(HCRYPTPROV phProv, DWORD dwFlags)
+{
+ HRESULT hr = ICryptographicBufferStatics_Release(phProv);
+ return SUCCEEDED(hr) && dwFlags==0;
+}
+
+BOOL WINAPI CryptGenRandom(HCRYPTPROV phProv, DWORD dwLen, BYTE *pbBuffer)
+{
+ IBuffer *buffer = NULL;
+ HRESULT hr = ICryptographicBufferStatics_GenerateRandom(phProv, dwLen,
&buffer);
+ if (FAILED(hr)) {
+ return FALSE;
+ }
+
+ UINT32 olength;
+ unsigned char *rnd = NULL;
+ hr = ICryptographicBufferStatics_CopyToByteArray(phProv, buffer, &olength,
(BYTE**)&rnd);
+ if (FAILED(hr)) {
+ IBuffer_Release(buffer);
+ return FALSE;
+ }
+ memcpy(pbBuffer, rnd, dwLen);
+
+ IBuffer_Release(buffer);
+ return TRUE;
+}
+
+#ifndef _WIN64
+BOOL (WINAPI *__MINGW_IMP_SYMBOL(CryptAcquireContextW))(HCRYPTPROV*, LPCTSTR,
LPCTSTR, DWORD, DWORD) asm("__imp__CryptAcquireContextW@20") =
CryptAcquireContextW;
+BOOL (WINAPI *__MINGW_IMP_SYMBOL(CryptAcquireContextA))(HCRYPTPROV*, LPCTSTR,
LPCTSTR, DWORD, DWORD) asm("__imp__CryptAcquireContextA@20") =
CryptAcquireContextA;
+BOOL (WINAPI *__MINGW_IMP_SYMBOL(CryptReleaseContext))(HCRYPTPROV, DWORD)
asm("__imp__CryptReleaseContext@8") = CryptReleaseContext;
+BOOL (WINAPI *__MINGW_IMP_SYMBOL(CryptGenRandom))(HCRYPTPROV, DWORD, BYTE*)
asm("__imp__CryptGenRandom@12") = CryptGenRandom;
+#else
+BOOL (WINAPI *__MINGW_IMP_SYMBOL(CryptAcquireContextW))(HCRYPTPROV*, LPCTSTR,
LPCTSTR, DWORD, DWORD) asm("__imp_CryptAcquireContextW") = CryptAcquireContextW;
+BOOL (WINAPI *__MINGW_IMP_SYMBOL(CryptAcquireContextA))(HCRYPTPROV*, LPCTSTR,
LPCTSTR, DWORD, DWORD) asm("__imp_CryptAcquireContextA") = CryptAcquireContextA;
+BOOL (WINAPI *__MINGW_IMP_SYMBOL(CryptReleaseContext))(HCRYPTPROV, DWORD)
asm("__imp_CryptReleaseContext") = CryptReleaseContext;
+BOOL (WINAPI *__MINGW_IMP_SYMBOL(CryptGenRandom))(HCRYPTPROV, DWORD, BYTE*)
asm("__imp_CryptGenRandom") = CryptGenRandom;
+#endif
--
2.8.1
------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public