ReactOS  0.4.15-dev-3723-g8d70159
RtlEncryptMemory.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Test for RtlEncrypt/DecryptMemory
5  * PROGRAMMER: Timo Kreuzer <timo.kreuzer@reactos.org>
6  */
7 
8 #include "precomp.h"
9 
10 #include <ntsecapi.h>
11 
12 static const CHAR TestData[32] = "This is some test Message!!!";
13 
14 void TestEncrypt(ULONG OptionFlags)
15 {
16  CHAR DECLSPEC_ALIGN(8) Buffer[32];
18 
19  /* Size must be aligned to 8 bytes (aka RTL_ENCRYPT_MEMORY_SIZE) */
21  Status = RtlEncryptMemory(Buffer, 7, OptionFlags);
23 
24  /* Buffer can be unaligned */
26  Status = RtlEncryptMemory(&Buffer[1], 8, OptionFlags);
28  Status = RtlDecryptMemory(&Buffer[1], 8, OptionFlags);
30  ok(RtlEqualMemory(Buffer, TestData, sizeof(Buffer)) == 1,
31  "OptionFlags=%lu, Buffer='%s', TestData='%s'\n",
32  OptionFlags, Buffer, TestData);
33 
35  Status = RtlEncryptMemory(Buffer, sizeof(Buffer), OptionFlags);
38  Status = RtlDecryptMemory(Buffer, sizeof(Buffer), OptionFlags);
41 }
42 
44 {
45  UCHAR Buffer[32] = { 0 };
46  ULONG OptionFlags;
47  PSTR StrData;
48  ULONG i;
50 
51  OptionFlags = Param[3] == '1' ? RTL_ENCRYPT_OPTION_CROSS_PROCESS : RTL_ENCRYPT_OPTION_SAME_LOGON;
52 
53  /* Convert the HEX string to binary ('-cp<1|2>:<data>') */
54  StrData = Param + 5;
55  for (i = 0; i < sizeof(Buffer); i++)
56  {
57  UINT x;
58  sscanf(&StrData[2 * i], "%02X", &x);
59  Buffer[i] = (UCHAR)x;
60  }
61 
62  /* Decrypt the data */
63  Status = RtlDecryptMemory(Buffer, sizeof(Buffer), OptionFlags);
66 }
67 
68 void TestCrossProcessEncrypt(ULONG OptionFlags)
69 {
70  UCHAR Buffer[32];
72  PSTR StrBuffer;
74  ULONG i;
75  INT result;
76 
77  /* Encrypt the test string */
79  Status = RtlEncryptMemory(Buffer, sizeof(Buffer), OptionFlags);
81 
82  /* Start building a command line */
83  sprintf(CmdLine, "advapi32_apitest.exe RtlEncryptMemory -cp%lu:", OptionFlags);
84  StrBuffer = CmdLine + strlen(CmdLine);
85 
86  /* Convert encrypted data into a hex string */
87  for (i = 0; i < sizeof(Buffer); i++)
88  {
89  sprintf(&StrBuffer[2 * i], "%02X", Buffer[i]);
90  }
91 
93  ok_int(result, 0);
94 }
95 
97 {
98  CHAR Buffer[8] = { 0 };
99  PSTR CommandLine, Param;
101 
102  /* Check recursive call */
103  CommandLine = GetCommandLineA();
104  Param = strstr(CommandLine, "-cp");
105  if (Param != NULL)
106  {
108  return;
109  }
110 
114 
115  Status = RtlEncryptMemory(Buffer, sizeof(Buffer), 4);
117 
120 }
void TestCrossProcessDecrypt(PSTR Param)
START_TEST(RtlEncryptMemory)
GLuint64EXT * result
Definition: glext.h:11304
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
#define RTL_ENCRYPT_OPTION_CROSS_PROCESS
Definition: ksecdd.h:26
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
void TestCrossProcessEncrypt(ULONG OptionFlags)
#define DECLSPEC_ALIGN(x)
Definition: ntbasedef.h:251
int32_t INT
Definition: typedefs.h:58
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static const WCHAR CmdLine[]
Definition: install.c:48
#define ok_int(expression, result)
Definition: atltest.h:134
Definition: bufpool.h:45
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
int __cdecl system(_In_opt_z_ const char *_Command)
NTSTATUS WINAPI RtlDecryptMemory(PVOID Memory, ULONG MemorySize, ULONG OptionFlags)
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG NTAPI RtlEqualMemory(CONST VOID *Source1, CONST VOID *Source2, ULONG Length)
#define MAX_PATH
Definition: compat.h:34
void TestEncrypt(ULONG OptionFlags)
#define RTL_ENCRYPT_OPTION_SAME_PROCESS
Definition: ksecdd.h:25
LPSTR WINAPI GetCommandLineA(VOID)
Definition: proc.c:2004
unsigned char UCHAR
Definition: xmlstorage.h:181
#define RTL_ENCRYPT_OPTION_SAME_LOGON
Definition: ksecdd.h:27
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ok(value,...)
Definition: atltest.h:57
signed char * PSTR
Definition: retypes.h:7
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
NTSTATUS WINAPI RtlEncryptMemory(PVOID Memory, ULONG MemorySize, ULONG OptionFlags)
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65