ReactOS 0.4.15-dev-8061-g57b775e
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
12static const CHAR TestData[32] = "This is some test Message!!!";
13
14void TestEncrypt(ULONG OptionFlags)
15{
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
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
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)
void TestEncrypt(ULONG OptionFlags)
void TestCrossProcessEncrypt(ULONG OptionFlags)
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
LPSTR WINAPI GetCommandLineA(VOID)
Definition: proc.c:2003
static const WCHAR CmdLine[]
Definition: install.c:48
Status
Definition: gdiplustypes.h:25
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLuint64EXT * result
Definition: glext.h:11304
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
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define RtlEqualMemory(a, b, c)
Definition: kdvm.h:18
#define RTL_ENCRYPT_OPTION_SAME_LOGON
Definition: ksecdd.h:27
#define RTL_ENCRYPT_OPTION_SAME_PROCESS
Definition: ksecdd.h:25
#define RTL_ENCRYPT_OPTION_CROSS_PROCESS
Definition: ksecdd.h:26
#define sprintf(buf, format,...)
Definition: sprintf.c:55
unsigned int UINT
Definition: ndis.h:50
#define DECLSPEC_ALIGN(x)
Definition: ntbasedef.h:251
#define RtlEncryptMemory
Definition: ntsecapi.h:692
#define RtlDecryptMemory
Definition: ntsecapi.h:693
int __cdecl system(_In_opt_z_ const char *_Command)
#define STATUS_SUCCESS
Definition: shellext.h:65
char * PSTR
Definition: typedefs.h:51
int32_t INT
Definition: typedefs.h:58
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned char UCHAR
Definition: xmlstorage.h:181
char CHAR
Definition: xmlstorage.h:175