bcrypt: Implemented BCryptGetFipsAlgorithmMode
Kai Blaschke
kai.blaschke at kb-dev.net
Fri Sep 19 15:24:22 CDT 2014
Added a working implementation of the BCryptGetFipsAlgorithmMode stub
plus the associated test.
-------------- next part --------------
>From 23256a9208809ac7c35cdaffc87bfe5e6d4e6bcf Mon Sep 17 00:00:00 2001
From: Kai Blaschke <kai.blaschke at kb-dev.net>
Date: Fri, 19 Sep 2014 20:14:49 +0000
Subject: Implemented BCryptGetFipsAlgorithmMode and the associated test
---
dlls/bcrypt/bcrypt_main.c | 41 ++++++++++++++++++++++-
dlls/bcrypt/tests/bcrypt.c | 82 +++++++++++++++++++++++++++++++++++++++-------
2 files changed, 111 insertions(+), 12 deletions(-)
diff --git a/dlls/bcrypt/bcrypt_main.c b/dlls/bcrypt/bcrypt_main.c
index 35a640a..3f922ed 100644
--- a/dlls/bcrypt/bcrypt_main.c
+++ b/dlls/bcrypt/bcrypt_main.c
@@ -25,6 +25,7 @@
#define WIN32_NO_STATUS
#include "windef.h"
#include "winbase.h"
+#include "winreg.h"
#include "ntsecapi.h"
#include "bcrypt.h"
#include "wine/debug.h"
@@ -100,11 +101,49 @@ NTSTATUS WINAPI BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE algorithm, DWORD
NTSTATUS WINAPI BCryptGetFipsAlgorithmMode(BOOLEAN *enabled)
{
- FIXME("%p - semi-stub\n", enabled);
+ static const WCHAR policyKeyVistaW[] = {
+ 'S','y','s','t','e','m','\\',
+ 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
+ 'C','o','n','t','r','o','l','\\',
+ 'L','s','a','\\',
+ 'F','I','P','S','A','l','g','o','r','i','t','h','m','P','o','l','i','c','y',0};
+ static const WCHAR policyValueVistaW[] = {'E','n','a','b','l','e','d',0};
+ static const WCHAR policyKeyXPW[] = {
+ 'S','y','s','t','e','m','\\',
+ 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
+ 'C','o','n','t','r','o','l','\\',
+ 'L','s','a',0};
+ static const WCHAR policyValueXPW[] = {
+ 'F','I','P','S','A','l','g','o','r','i','t','h','m','P','o','l','i','c','y',0};
+ HKEY hkey;
if (!enabled)
+ {
return STATUS_INVALID_PARAMETER;
+ }
*enabled = FALSE;
+
+ if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, policyKeyVistaW, &hkey))
+ {
+ DWORD regEnabled;
+ DWORD count = sizeof(enabled);
+ if (!RegGetValueW(HKEY_LOCAL_MACHINE, policyKeyVistaW, policyValueVistaW,
+ RRF_RT_REG_DWORD, NULL, ®Enabled, &count))
+ {
+ *enabled = (BOOLEAN)regEnabled != 0;
+ }
+ }
+ else if (!RegOpenKeyW(HKEY_LOCAL_MACHINE, policyKeyXPW, &hkey))
+ {
+ DWORD regEnabled;
+ DWORD count = sizeof(enabled);
+ if (!RegGetValueW(HKEY_LOCAL_MACHINE, policyKeyXPW, policyValueXPW,
+ RRF_RT_REG_DWORD, NULL, ®Enabled, &count))
+ {
+ *enabled = (BOOLEAN)regEnabled != 0;
+ }
+ }
+
return STATUS_SUCCESS;
}
diff --git a/dlls/bcrypt/tests/bcrypt.c b/dlls/bcrypt/tests/bcrypt.c
index 9e659d6..c9d8800 100644
--- a/dlls/bcrypt/tests/bcrypt.c
+++ b/dlls/bcrypt/tests/bcrypt.c
@@ -25,9 +25,19 @@
#include "wine/test.h"
+#include "windef.h"
+#include "winbase.h"
+#include "winreg.h"
+#include "winternl.h"
+
static NTSTATUS (WINAPI *pBCryptGenRandom)(BCRYPT_ALG_HANDLE hAlgorithm, PUCHAR pbBuffer,
ULONG cbBuffer, ULONG dwFlags);
static NTSTATUS (WINAPI *pBCryptGetFipsAlgorithmMode)(BOOLEAN *enabled);
+static LONG (WINAPI * pRegOpenKeyW) (HKEY, LPCWSTR, PHKEY);
+static LONG (WINAPI * pRegGetValueW) (HKEY, LPCWSTR, LPCWSTR, DWORD, LPDWORD, PVOID, LPDWORD);
+
+#define GET_PROC(handle, func) \
+ p ## func = (void*)GetProcAddress(handle, #func)
static BOOL Init(void)
{
@@ -37,9 +47,18 @@ static BOOL Init(void)
win_skip("bcrypt library not available\n");
return FALSE;
}
+ HMODULE hadvapi32 = LoadLibraryA("advapi32.dll");
+ if (!hadvapi32)
+ {
+ win_skip("advapi32 library not available\n");
+ return FALSE;
+ }
+
+ GET_PROC(hbcrypt, BCryptGenRandom);
+ GET_PROC(hbcrypt, BCryptGetFipsAlgorithmMode);
- pBCryptGenRandom = (void *)GetProcAddress(hbcrypt, "BCryptGenRandom");
- pBCryptGetFipsAlgorithmMode = (void *)GetProcAddress(hbcrypt, "BCryptGetFipsAlgorithmMode");
+ GET_PROC(hadvapi32, RegOpenKeyW);
+ GET_PROC(hadvapi32, RegGetValueW);
return TRUE;
}
@@ -82,20 +101,61 @@ static void test_BCryptGenRandom(void)
static void test_BCryptGetFipsAlgorithmMode(void)
{
- NTSTATUS ret;
- BOOLEAN enabled;
-
- if (!pBCryptGetFipsAlgorithmMode)
+ static const WCHAR policyKeyVistaW[] = {
+ 'S','y','s','t','e','m','\\',
+ 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
+ 'C','o','n','t','r','o','l','\\',
+ 'L','s','a','\\',
+ 'F','I','P','S','A','l','g','o','r','i','t','h','m','P','o','l','i','c','y',0};
+ static const WCHAR policyValueVistaW[] = {'E','n','a','b','l','e','d',0};
+ static const WCHAR policyKeyXPW[] = {
+ 'S','y','s','t','e','m','\\',
+ 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
+ 'C','o','n','t','r','o','l','\\',
+ 'L','s','a',0};
+ static const WCHAR policyValueXPW[] = {
+ 'F','I','P','S','A','l','g','o','r','i','t','h','m','P','o','l','i','c','y',0};
+ HKEY hkey;
+ BOOLEAN expected;
+ BOOLEAN result;
+ NTSTATUS status;
+
+ if (!pBCryptGetFipsAlgorithmMode || !pRegOpenKeyW || !pRegGetValueW)
{
- win_skip("BCryptGetFipsAlgorithmMode is not available\n");
+ win_skip("Can't perform BCryptGetFipsAlgorithmMode tests\n");
return;
}
- ret = pBCryptGetFipsAlgorithmMode(&enabled);
- ok(ret == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got 0x%x\n", ret);
+ expected = FALSE;
- ret = pBCryptGetFipsAlgorithmMode(NULL);
- ok(ret == STATUS_INVALID_PARAMETER, "Expected STATUS_INVALID_PARAMETER, got 0x%x\n", ret);
+ if (!pRegOpenKeyW(HKEY_LOCAL_MACHINE, policyKeyVistaW, &hkey))
+ {
+ DWORD enabled;
+ DWORD count = sizeof(enabled);
+ if (!pRegGetValueW(HKEY_LOCAL_MACHINE, policyKeyVistaW, policyValueVistaW,
+ RRF_RT_REG_DWORD, NULL, &enabled, &count))
+ {
+ expected = (BOOLEAN)enabled != 0;
+ }
+ }
+ else if (!pRegOpenKeyW(HKEY_LOCAL_MACHINE, policyKeyXPW, &hkey))
+ {
+ DWORD enabled;
+ DWORD count = sizeof(enabled);
+ if (!pRegGetValueW(HKEY_LOCAL_MACHINE, policyKeyXPW, policyValueXPW,
+ RRF_RT_REG_DWORD, NULL, &enabled, &count))
+ {
+ expected = (BOOLEAN)enabled != 0;
+ }
+ }
+
+ status = pBCryptGetFipsAlgorithmMode(&result);
+ ok(!status, "expected status STATUS_SUCCESS(0), got 0x%08X\n", status);
+ ok(result == expected, "expected result %d, got %d\n", expected, result);
+
+ status = pBCryptGetFipsAlgorithmMode(NULL);
+ ok(status == STATUS_INVALID_PARAMETER,
+ "expected status STATUS_INVALID_PARAMETER(0xC000000D), got 0x%08X\n", status);
}
START_TEST(bcrypt)
--
2.0.0
More information about the wine-patches
mailing list