static int test_alphaComp_speed(void)
{
	BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT]);
	BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT]);
	BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT]);
	char testStr[256];
	UINT32* ptr;
	UINT32 i;
	testStr[0] = '\0';
	winpr_RAND((BYTE*)src1, sizeof(src1));
	/* Special-case the first two values */
	src1[0] &= 0x00FFFFFFU;
	src1[1] |= 0xFF000000U;
	winpr_RAND((BYTE*)src2, sizeof(src2));
	/* Set the second operand to fully-opaque. */
	ptr = (UINT32*)src2;

	for (i = 0; i < sizeof(src2) / 4; ++i) *ptr++ |= 0xFF000000U;

	memset(dst1, 0, sizeof(dst1));

	if (!speed_test("add16s", "aligned", g_Iterations,
	                (speed_test_fkt)generic->alphaComp_argb,
	                (speed_test_fkt)optimized->alphaComp_argb,
	                src1, 4 * SRC1_WIDTH,
	                src2, 4 * SRC2_WIDTH,
	                dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT))
		return FALSE;

	return TRUE;
}
Example #2
0
static void get_size(UINT32* width, UINT32* height)
{
	winpr_RAND((BYTE*)width, sizeof(*width));
	winpr_RAND((BYTE*)height, sizeof(*height));
	// TODO: Algorithm only works on even resolutions...
	*width = (*width % 64) << 1;
	*height = (*height % 64 << 1);
}
Example #3
0
void license_generate_randoms(rdpLicense* license)
{
    ZeroMemory(license->ClientRandom, CLIENT_RANDOM_LENGTH); /* ClientRandom */
    ZeroMemory(license->PremasterSecret, PREMASTER_SECRET_LENGTH); /* PremasterSecret */
#ifndef LICENSE_NULL_CLIENT_RANDOM
    winpr_RAND(license->ClientRandom, CLIENT_RANDOM_LENGTH); /* ClientRandom */
#endif
#ifndef LICENSE_NULL_PREMASTER_SECRET
    winpr_RAND(license->PremasterSecret, PREMASTER_SECRET_LENGTH); /* PremasterSecret */
#endif
}
/* ------------------------------------------------------------------------- */
static BOOL test_RGBToRGB_16s8u_P3AC4R_func(void)
{
	INT16 ALIGN(r[4096]), ALIGN(g[4096]), ALIGN(b[4096]);
	UINT32 ALIGN(out1[4096]);
	UINT32 ALIGN(out2[4096]);
	int i;
	BOOL failed = FALSE;
	INT16* ptrs[3];
	prim_size_t roi = { 64, 64 };

	winpr_RAND((BYTE*)r, sizeof(r));
	winpr_RAND((BYTE*)g, sizeof(g));
	winpr_RAND((BYTE*)b, sizeof(b));

	/* clear upper bytes */
	for (i = 0; i < 4096; ++i)
	{
		r[i] &= 0x00FFU;
		g[i] &= 0x00FFU;
		b[i] &= 0x00FFU;
	}

	ptrs[0] = r;
	ptrs[1] = g;
	ptrs[2] = b;
	if (generic->RGBToRGB_16s8u_P3AC4R((const INT16**) ptrs, 64 * 2,
				      (BYTE*) out1, 64 * 4, PIXEL_FORMAT_RGBA32,
				       &roi) != PRIMITIVES_SUCCESS)
		return FALSE;

	if (optimized->RGBToRGB_16s8u_P3AC4R((const INT16**) ptrs, 64 * 2,
					 (BYTE*) out2, 64 * 4, PIXEL_FORMAT_RGBA32,
					  &roi) != PRIMITIVES_SUCCESS)
		return FALSE;

	for (i = 0; i < 4096; ++i)
	{
		if (out1[i] != out2[i])
		{
			printf("RGBToRGB-SSE FAIL: out1[%d]=0x%08"PRIx32" out2[%d]=0x%08"PRIx32"\n",
			       i, out1[i], i, out2[i]);
			failed = TRUE;
		}
	}

	return !failed;
}
static BOOL test_alphaComp_func(void)
{
	pstatus_t status;
	BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT * 4]);
	BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT * 4]);
	BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT * 4]);
	UINT32* ptr;
	UINT32 i;
	winpr_RAND((BYTE*)src1, sizeof(src1));
	/* Special-case the first two values */
	src1[0] &= 0x00FFFFFFU;
	src1[1] |= 0xFF000000U;
	winpr_RAND((BYTE*)src2, sizeof(src2));
	/* Set the second operand to fully-opaque. */
	ptr = (UINT32*)src2;

	for (i = 0; i < sizeof(src2) / 4; ++i) *ptr++ |= 0xFF000000U;

	memset(dst1, 0, sizeof(dst1));
	status = generic->alphaComp_argb(src1, 4 * SRC1_WIDTH,
	                                 src2, 4 * SRC2_WIDTH,
	                                 dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT);

	if (status != PRIMITIVES_SUCCESS)
		return FALSE;

	if (!check(src1, 4 * SRC1_WIDTH,
	           src2, 4 * SRC2_WIDTH,
	           dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT))
		return FALSE;

	status = optimized->alphaComp_argb((const BYTE*) src1, 4 * SRC1_WIDTH,
	                                   (const BYTE*) src2, 4 * SRC2_WIDTH,
	                                   (BYTE*) dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT);

	if (status != PRIMITIVES_SUCCESS)
		return FALSE;

	if (!check(src1, 4 * SRC1_WIDTH,
	           src2, 4 * SRC2_WIDTH,
	           dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT))
		return FALSE;

	return TRUE;
}
Example #6
0
static BOOL autodetect_send_bandwidth_measure_stop(rdpContext* context, UINT16 payloadLength, UINT16 sequenceNumber, UINT16 requestType)
{
	wStream* s;
	UCHAR *buffer = NULL;
	BOOL bResult = FALSE;

	s = rdp_message_channel_pdu_init(context->rdp);

	if (!s)
		return FALSE;

	WLog_VRB(AUTODETECT_TAG, "sending Bandwidth Measure Stop PDU -> payloadLength=%u", payloadLength);

	/* 4-bytes aligned */
	payloadLength &= ~3;

	Stream_Write_UINT8(s, requestType == RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME ? 0x08 : 0x06); /* headerLength (1 byte) */
	Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_REQUEST); /* headerTypeId (1 byte) */
	Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */
	Stream_Write_UINT16(s, requestType); /* requestType (2 bytes) */
	if (requestType == RDP_BW_STOP_REQUEST_TYPE_CONNECTTIME)
	{
		Stream_Write_UINT16(s, payloadLength); /* payloadLength (2 bytes) */
		if (payloadLength > 0)
		{
			if (!Stream_EnsureRemainingCapacity(s, payloadLength))
			{
				Stream_Release(s);
				return FALSE;
			}

			/* Random data (better measurement in case the line is compressed) */
			buffer = malloc(payloadLength);
			if (NULL == buffer)
			{
				Stream_Release(s);
				return FALSE;
			}

			winpr_RAND(buffer, payloadLength);
			Stream_Write(s, buffer, payloadLength);
		}
	}

	bResult = rdp_send_message_channel_pdu(context->rdp, s, SEC_AUTODETECT_REQ);
	if (!bResult)
	{
		Stream_Release(s);
	}
	free(buffer);

	return bResult;
}
/* ------------------------------------------------------------------------- */
static BOOL test_RGBToRGB_16s8u_P3AC4R_speed(void)
{
	const prim_size_t roi64x64 = { 64, 64 };
	INT16 ALIGN(r[4096+1]), ALIGN(g[4096+1]), ALIGN(b[4096+1]);
	UINT32 ALIGN(dst[4096+1]);
	int i;
	INT16* ptrs[3];

	winpr_RAND((BYTE*)r, sizeof(r));
	winpr_RAND((BYTE*)g, sizeof(g));
	winpr_RAND((BYTE*)b, sizeof(b));

	/* clear upper bytes */
	for (i = 0; i < 4096; ++i)
	{
		r[i] &= 0x00FFU;
		g[i] &= 0x00FFU;
		b[i] &= 0x00FFU;
	}

	ptrs[0] = r+1;
	ptrs[1] = g+1;
	ptrs[2] = b+1;

	if (!speed_test("RGBToRGB_16s8u_P3AC4R", "aligned", g_Iterations,
			(speed_test_fkt)generic->RGBToRGB_16s8u_P3AC4R,
			(speed_test_fkt)optimized->RGBToRGB_16s8u_P3AC4R,
			(const INT16**) ptrs, 64 * 2, (BYTE*) dst, 64 * 4, &roi64x64))
		return FALSE;

	if (!speed_test("RGBToRGB_16s8u_P3AC4R", "unaligned", g_Iterations,
			(speed_test_fkt)generic->RGBToRGB_16s8u_P3AC4R,
			(speed_test_fkt)optimized->RGBToRGB_16s8u_P3AC4R,
			(const INT16**) ptrs, 64 * 2, ((BYTE*) dst)+1, 64 * 4, &roi64x64))
		return FALSE;

	return TRUE;
}
Example #8
0
int TestPrimitivesYCoCg(int argc, char* argv[])
{
	prim_test_setup(FALSE);

	/* Random resolution tests */
	if (argc < 2)
	{
		UINT32 x;

		for (x = 0; x < 10; x++)
		{
			UINT32 w, h;

			do
			{
				winpr_RAND((BYTE*)&w, sizeof(w));
				w %= 2048;
			}
			while (w < 16);

			do
			{
				winpr_RAND((BYTE*)&h, sizeof(h));
				h %= 2048;
			}
			while (h < 16);

			if (!test_YCoCgRToRGB_8u_AC4R_func(w, h))
				return 1;
		}
	}

	/* Test once with full HD */
	if (!test_YCoCgRToRGB_8u_AC4R_func(1920, 1080))
		return 1;

	return 0;
}
/* ------------------------------------------------------------------------- */
static int test_yCbCrToRGB_16s16s_P3P3_speed(void)
{
	prim_size_t roi = { 64, 64 };
	INT16 ALIGN(y[4096]), ALIGN(cb[4096]), ALIGN(cr[4096]);
	INT16 ALIGN(r[4096]), ALIGN(g[4096]), ALIGN(b[4096]);
	int i;
	const INT16* input[3];
	INT16* output[3];

	winpr_RAND((BYTE*)y, sizeof(y));
	winpr_RAND((BYTE*)cb, sizeof(cb));
	winpr_RAND((BYTE*)cr, sizeof(cr));

	/* Normalize to 11.5 fixed radix */
	for (i = 0; i < 4096; ++i)
	{
		y[i]  &= 0x1FE0U;
		cb[i] &= 0x1FE0U;
		cr[i] &= 0x1FE0U;
	}

	input[0] = y;
	input[1] = cb;
	input[2] = cr;
	output[0] = r;
	output[1] = g;
	output[2] = b;

	if (!speed_test("yCbCrToRGB_16s16s_P3P3", "aligned", g_Iterations,
			(speed_test_fkt)generic->yCbCrToRGB_16s16s_P3P3,
			(speed_test_fkt)optimized->yCbCrToRGB_16s16s_P3P3,
			input, 64 * 2, output, 64 * 2, &roi))
		return FALSE;

	return TRUE;
}
Example #10
0
static int test_YCoCgRToRGB_8u_AC4R_speed(void)
{
	INT32 ALIGN(in[4096]);
	INT32 ALIGN(out[4096]);

	winpr_RAND((BYTE*)in, sizeof(in));

	if (!speed_test("YCoCgToRGB_8u_AC4R", "aligned", g_Iterations,
			(speed_test_fkt)generic->YCoCgToRGB_8u_AC4R,
			(speed_test_fkt)optimized->YCoCgToRGB_8u_AC4R,
			in, 64 * 4, out, 64 * 4, 64, 64, 2, FALSE, FALSE))
		return FALSE;

	return TRUE;
}
Example #11
0
/* ------------------------------------------------------------------------- */
static BOOL test_or_32u_speed(void)
{
	UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]), ALIGN(dst[FUNC_TEST_SIZE + 3]);
	char testStr[256];
	testStr[0] = '\0';
	winpr_RAND((BYTE*)src, sizeof(src));

	if (!speed_test("add16s", "aligned", g_Iterations,
			(speed_test_fkt)generic->orC_32u,
			(speed_test_fkt)optimized->orC_32u,
			src + 1, VALUE, dst + 1, FUNC_TEST_SIZE))
		return FALSE;

	return TRUE;
}
Example #12
0
/* ------------------------------------------------------------------------- */
static BOOL test_and_32u_speed(void)
{
	UINT32 ALIGN(src[MAX_TEST_SIZE + 3]), ALIGN(dst[MAX_TEST_SIZE + 3]);

	winpr_RAND((BYTE*)src, sizeof(src));

	if (!speed_test("andC_32u", "aligned", g_Iterations,
			(speed_test_fkt)generic->andC_32u,
			(speed_test_fkt)optimized->andC_32u,
			src + 1, VALUE, dst + 1, MAX_TEST_SIZE))
		return FALSE;
	if (!speed_test("andC_32u", "unaligned", g_Iterations,
			(speed_test_fkt)generic->andC_32u,
			(speed_test_fkt)optimized->andC_32u,
			src + 1, VALUE, dst + 2, MAX_TEST_SIZE))
		return FALSE;

	return TRUE;
}
Example #13
0
BOOL autodetect_send_bandwidth_measure_payload(rdpContext* context, UINT16 payloadLength,
        UINT16 sequenceNumber)
{
	wStream* s;
	UCHAR* buffer = NULL;
	BOOL bResult = FALSE;
	s = rdp_message_channel_pdu_init(context->rdp);

	if (!s)
		return FALSE;

	WLog_VRB(AUTODETECT_TAG, "sending Bandwidth Measure Payload PDU -> payloadLength=%"PRIu16"",
	         payloadLength);
	/* 4-bytes aligned */
	payloadLength &= ~3;

	if (!Stream_EnsureRemainingCapacity(s, 8 + payloadLength))
	{
		Stream_Release(s);
		return FALSE;
	}

	Stream_Write_UINT8(s, 0x08); /* headerLength (1 byte) */
	Stream_Write_UINT8(s, TYPE_ID_AUTODETECT_REQUEST); /* headerTypeId (1 byte) */
	Stream_Write_UINT16(s, sequenceNumber); /* sequenceNumber (2 bytes) */
	Stream_Write_UINT16(s, RDP_BW_PAYLOAD_REQUEST_TYPE); /* requestType (2 bytes) */
	Stream_Write_UINT16(s, payloadLength); /* payloadLength (2 bytes) */
	/* Random data (better measurement in case the line is compressed) */
	buffer = (UCHAR*)malloc(payloadLength);

	if (NULL == buffer)
	{
		Stream_Release(s);
		return FALSE;
	}

	winpr_RAND(buffer, payloadLength);
	Stream_Write(s, buffer, payloadLength);
	bResult = rdp_send_message_channel_pdu(context->rdp, s, SEC_AUTODETECT_REQ);
	free(buffer);
	return bResult;
}
Example #14
0
int TestCryptoRand(int argc, char* argv[])
{
	char* str;
	BYTE rnd[16];

	ZeroMemory(rnd, sizeof(rnd));

	winpr_RAND(rnd, sizeof(rnd));

	str = winpr_BinToHexString(rnd, sizeof(rnd), FALSE);
	//fprintf(stderr, "Rand: %s\n", str);
	free(str);

	if (memcmp(rnd, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16) == 0)
	{
		return -1;
	}

	return 0;
}
Example #15
0
static BOOL test_and_32u_func(void)
{
	UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]), ALIGN(dst[FUNC_TEST_SIZE + 3]);

	winpr_RAND((BYTE*)src, sizeof(src));

	if (!test_and_32u_impl("generic->andC_32u aligned", generic->andC_32u,
			       src + 1, VALUE, dst + 1, FUNC_TEST_SIZE))
		return FALSE;
	if (!test_and_32u_impl("generic->andC_32u unaligned", generic->andC_32u,
			       src + 1, VALUE, dst + 2, FUNC_TEST_SIZE))
		return FALSE;
	if (!test_and_32u_impl("optimized->andC_32u aligned", optimized->andC_32u,
			       src + 1, VALUE, dst + 1, FUNC_TEST_SIZE))
		return FALSE;
	if (!test_and_32u_impl("optimized->andC_32u unaligned", optimized->andC_32u,
			       src + 1, VALUE, dst + 2, FUNC_TEST_SIZE))
		return FALSE;

	return TRUE;
}
Example #16
0
static BOOL test_or_32u_func(void)
{
	pstatus_t status;
	UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]), ALIGN(dst[FUNC_TEST_SIZE + 3]);

	winpr_RAND((BYTE*)src, sizeof(src));

	status = generic->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE);
	if (status != PRIMITIVES_SUCCESS)
		return FALSE;

	if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE))
		return FALSE;

	status = optimized->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE);
	if (status != PRIMITIVES_SUCCESS)
		return FALSE;

	if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE))
		return FALSE;

	return TRUE;
}
Example #17
0
void rts_generate_cookie(BYTE* cookie)
{
	winpr_RAND(cookie, 16);
}
Example #18
0
void ntlm_generate_random_session_key(NTLM_CONTEXT* context)
{
	winpr_RAND(context->RandomSessionKey, 16);
}
Example #19
0
void ntlm_generate_server_challenge(NTLM_CONTEXT* context)
{
	if (memcmp(context->ServerChallenge, NTLM_NULL_BUFFER, 8) == 0)
		winpr_RAND(context->ServerChallenge, 8);
}
Example #20
0
void ntlm_generate_client_challenge(NTLM_CONTEXT* context)
{
	/* ClientChallenge is used in computation of LMv2 and NTLMv2 responses */
	if (memcmp(context->ClientChallenge, NTLM_NULL_BUFFER, 8) == 0)
		winpr_RAND(context->ClientChallenge, 8);
}
Example #21
0
/* ------------------------------------------------------------------------- */
static BOOL test_YCoCgRToRGB_8u_AC4R_func(UINT32 width, UINT32 height)
{
	pstatus_t status = -1;
	BYTE* out_sse = NULL;
	BYTE* in = NULL;
	BYTE* out_c = NULL;
	UINT32 i, x;
	const UINT32 srcStride = width * 4;
	const UINT32 size = srcStride * height;
	const UINT32 formats[] =
	{
		PIXEL_FORMAT_ARGB32,
		PIXEL_FORMAT_ABGR32,
		PIXEL_FORMAT_RGBA32,
		PIXEL_FORMAT_RGBX32,
		PIXEL_FORMAT_BGRA32,
		PIXEL_FORMAT_BGRX32
	};
	PROFILER_DEFINE(genericProf);
	PROFILER_DEFINE(optProf);
	in = _aligned_malloc(size, 16);
	out_c = _aligned_malloc(size, 16);
	out_sse = _aligned_malloc(size, 16);

	if (!in || !out_c || !out_sse)
		goto fail;

	winpr_RAND(in, size);

	for (x = 0; x < sizeof(formats) / sizeof(formats[0]); x++)
	{
		const UINT32 format = formats[x];
		const UINT32 dstStride = width * GetBytesPerPixel(format);
		const char* formatName = GetColorFormatName(format);
		PROFILER_CREATE(genericProf, "YCoCgRToRGB_8u_AC4R-GENERIC");
		PROFILER_CREATE(optProf, "YCoCgRToRGB_8u_AC4R-OPT");
		PROFILER_ENTER(genericProf);
		status = generic->YCoCgToRGB_8u_AC4R(
		             in, srcStride,
		             out_c, format, dstStride, width, height, 2, TRUE);
		PROFILER_EXIT(genericProf);

		if (status != PRIMITIVES_SUCCESS)
			goto loop_fail;

		PROFILER_ENTER(optProf);
		status = optimized->YCoCgToRGB_8u_AC4R(
		             in, srcStride,
		             out_sse, format, dstStride, width, height, 2, TRUE);
		PROFILER_EXIT(optProf);

		if (status != PRIMITIVES_SUCCESS)
			goto loop_fail;

		if (memcmp(out_c, out_sse, dstStride * height) != 0)
		{
			for (i = 0; i < width * height; ++i)
			{
				const UINT32 c = ReadColor(out_c + 4 * i, format);
				const UINT32 sse = ReadColor(out_sse + 4 * i, format);

				if (c != sse)
				{
					printf("optimized->YCoCgRToRGB FAIL[%s] [%"PRIu32"]: 0x%08"PRIx32" -> C 0x%08"PRIx32" vs optimized 0x%08"PRIx32"\n",
					       formatName, i, in[i + 1], c, sse);
					status = -1;
				}
			}
		}

		printf("--------------------------- [%s] [%"PRIu32"x%"PRIu32"] ---------------------------\n",
		       formatName, width, height);
		PROFILER_PRINT_HEADER;
		PROFILER_PRINT(genericProf);
		PROFILER_PRINT(optProf);
		PROFILER_PRINT_FOOTER;
	loop_fail:
		PROFILER_FREE(genericProf);
		PROFILER_FREE(optProf);

		if (status != PRIMITIVES_SUCCESS)
			goto fail;
	}

fail:
	_aligned_free(in);
	_aligned_free(out_c);
	_aligned_free(out_sse);
	return status == PRIMITIVES_SUCCESS;
}
Example #22
0
/* ------------------------------------------------------------------------- */
static BOOL test_YCoCgRToRGB_8u_AC4R_func(void)
{
	BOOL result = TRUE;
	pstatus_t status;
	INT32 ALIGN(out_sse[4098]), ALIGN(out_sse_inv[4098]);
	INT32 ALIGN(in[4098]);
	INT32 ALIGN(out_c[4098]), ALIGN(out_c_inv[4098]);

	UINT32 i, x;
	const UINT32 formats[] = {
		PIXEL_FORMAT_ARGB32,
		PIXEL_FORMAT_ABGR32,
		PIXEL_FORMAT_RGBA32,
		PIXEL_FORMAT_RGBX32,
		PIXEL_FORMAT_BGRA32,
		PIXEL_FORMAT_BGRX32
	};

	winpr_RAND((BYTE*)in, sizeof(in));

	for (x=0; x<sizeof(formats)/sizeof(formats[0]); x++)
	{
		UINT32 format = formats[x];

		status = generic->YCoCgToRGB_8u_AC4R(
				 (const BYTE*)(in + 1), 63 * 4,
				 (BYTE*) out_c, format, 63 * 4, 63, 61, 2, TRUE);
		if (status != PRIMITIVES_SUCCESS)
			return FALSE;
		status = generic->YCoCgToRGB_8u_AC4R(
				 (const BYTE*)(in + 1), 63 * 4,
				 (BYTE*) out_c_inv, format, 63 * 4, 63, 61, 2, TRUE);
		if (status != PRIMITIVES_SUCCESS)
			return FALSE;

		status = optimized->YCoCgToRGB_8u_AC4R(
				 (const BYTE*)(in + 1), 63 * 4,
				 (BYTE*) out_sse, format, 63 * 4, 63, 61, 2, TRUE);
		if (status != PRIMITIVES_SUCCESS)
			return FALSE;
		status = optimized->YCoCgToRGB_8u_AC4R(
				 (const BYTE*)(in + 1), 63 * 4,
				 (BYTE*) out_sse_inv, format, 63 * 4, 63, 61, 2, TRUE);
		if (status != PRIMITIVES_SUCCESS)
			return FALSE;

		for (i = 0; i < 63 * 61; ++i)
		{
			if (out_c[i] != out_sse[i])
			{
				printf("optimized->YCoCgRToRGB FAIL[%"PRIu32"]: 0x%08"PRIx32" -> C 0x%08"PRIx32" vs optimized 0x%08"PRIx32"\n",
					   i, in[i + 1], out_c[i], out_sse[i]);
				result = FALSE;
			}
		}

		for (i = 0; i < 63 * 61; ++i)
		{
			if (out_c_inv[i] != out_sse_inv[i])
			{
				printf("optimized->YCoCgRToRGB inverted FAIL[%"PRIu32"]: 0x%08"PRIu32" -> C 0x%08"PRIx32" vs optimized 0x%08"PRIx32"\n",
				       i, in[i + 1], out_c_inv[i], out_sse_inv[i]);
				result = FALSE;
			}
		}
	}
	return result;
}
Example #23
0
BOOL CryptProtectMemory(LPVOID pData, DWORD cbData, DWORD dwFlags)
{
	BYTE* pCipherText;
	size_t cbOut, cbFinal;
	WINPR_CIPHER_CTX* enc = NULL;
	BYTE randomKey[256];
	WINPR_PROTECTED_MEMORY_BLOCK* pMemBlock;

	if (dwFlags != CRYPTPROTECTMEMORY_SAME_PROCESS)
		return FALSE;

	if (!g_ProtectedMemoryBlocks)
	{
		g_ProtectedMemoryBlocks = ListDictionary_New(TRUE);

		if (!g_ProtectedMemoryBlocks)
			return FALSE;
	}

	pMemBlock = (WINPR_PROTECTED_MEMORY_BLOCK*) calloc(1, sizeof(WINPR_PROTECTED_MEMORY_BLOCK));

	if (!pMemBlock)
		return FALSE;

	pMemBlock->pData = pData;
	pMemBlock->cbData = cbData;
	pMemBlock->dwFlags = dwFlags;

	winpr_RAND(pMemBlock->salt, 8);
	winpr_RAND(randomKey, sizeof(randomKey));

	winpr_openssl_BytesToKey(WINPR_CIPHER_AES_256_CBC, WINPR_MD_SHA1,
			pMemBlock->salt, randomKey, sizeof(randomKey), 4, pMemBlock->key, pMemBlock->iv);

	SecureZeroMemory(randomKey, sizeof(randomKey));

	cbOut = pMemBlock->cbData + 16 - 1;
	pCipherText = (BYTE*) malloc(cbOut);

	if (!pCipherText)
		goto out;

	if ((enc = winpr_Cipher_New(WINPR_CIPHER_AES_256_CBC, WINPR_ENCRYPT,
				    pMemBlock->key, pMemBlock->iv)) == NULL)
		goto out;
	if (!winpr_Cipher_Update(enc, pMemBlock->pData, pMemBlock->cbData, pCipherText, &cbOut))
		goto out;
	if (!winpr_Cipher_Final(enc, pCipherText + cbOut, &cbFinal))
		goto out;
	winpr_Cipher_Free(enc);

	CopyMemory(pMemBlock->pData, pCipherText, pMemBlock->cbData);
	free(pCipherText);

	return ListDictionary_Add(g_ProtectedMemoryBlocks, pData, pMemBlock);
out:
	free (pMemBlock);
	free (pCipherText);
	winpr_Cipher_Free(enc);

	return FALSE;
}
Example #24
0
/* ========================================================================= */
static BOOL test_yCbCrToRGB_16s16s_P3P3_func(void)
{
	pstatus_t status;
	INT16 ALIGN(y[4096]), ALIGN(cb[4096]), ALIGN(cr[4096]);
	INT16 ALIGN(r1[4096]), ALIGN(g1[4096]), ALIGN(b1[4096]);
	INT16 ALIGN(r2[4096]), ALIGN(g2[4096]), ALIGN(b2[4096]);
	int i;
	const INT16* in[3];
	INT16* out1[3];
	INT16* out2[3];
	prim_size_t roi = { 64, 64 };

	winpr_RAND((BYTE*)y, sizeof(y));
	winpr_RAND((BYTE*)cb, sizeof(cb));
	winpr_RAND((BYTE*)cr, sizeof(cr));

	/* Normalize to 11.5 fixed radix */
	for (i = 0; i < 4096; ++i)
	{
		y[i]  &= 0x1FE0U;
		cb[i] &= 0x1FE0U;
		cr[i] &= 0x1FE0U;
	}

	memset(r1, 0, sizeof(r1));
	memset(g1, 0, sizeof(g1));
	memset(b1, 0, sizeof(b1));
	memset(r2, 0, sizeof(r2));
	memset(g2, 0, sizeof(g2));
	memset(b2, 0, sizeof(b2));
	in[0] = y;
	in[1] = cb;
	in[2] = cr;
	out1[0] = r1;
	out1[1] = g1;
	out1[2] = b1;
	out2[0] = r2;
	out2[1] = g2;
	out2[2] = b2;

	status = generic->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out1, 64 * 2, &roi);
	if (status != PRIMITIVES_SUCCESS)
		return FALSE;

	status = optimized->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out2, 64 * 2, &roi);
	if (status != PRIMITIVES_SUCCESS)
		return FALSE;

	for (i = 0; i < 4096; ++i)
	{
		if ((ABS(r1[i] - r2[i]) > 1)
		    || (ABS(g1[i] - g2[i]) > 1)
		    || (ABS(b1[i] - b2[i]) > 1))
		{
			printf("YCbCrToRGB-SSE FAIL[%d]: %"PRId16",%"PRId16",%"PRId16" vs %"PRId16",%"PRId16",%"PRId16"\n", i,
			       r1[i], g1[i], b1[i], r2[i], g2[i], b2[i]);
			return FALSE;
		}
	}

	return TRUE;
}
Example #25
0
static BOOL rdp_client_establish_keys(rdpRdp* rdp)
{
	BYTE* mod;
	BYTE* exp;
	wStream* s;
	UINT32 length;
	UINT32 key_len;
	int status = 0;
	BOOL ret = FALSE;
	rdpSettings* settings;
	BYTE* crypt_client_random = NULL;

	settings = rdp->settings;

	if (!settings->UseRdpSecurityLayer)
	{
		/* no RDP encryption */
		return TRUE;
	}

	/* encrypt client random */

	free(settings->ClientRandom);

	settings->ClientRandomLength = CLIENT_RANDOM_LENGTH;
	settings->ClientRandom = malloc(settings->ClientRandomLength);

	if (!settings->ClientRandom)
		return FALSE;

	winpr_RAND(settings->ClientRandom, settings->ClientRandomLength);
	key_len = settings->RdpServerCertificate->cert_info.ModulusLength;
	mod = settings->RdpServerCertificate->cert_info.Modulus;
	exp = settings->RdpServerCertificate->cert_info.exponent;

	/*
	 * client random must be (bitlen / 8) + 8 - see [MS-RDPBCGR] 5.3.4.1
	 * for details
	 */
	crypt_client_random = calloc(1, key_len + 8);

	if (!crypt_client_random)
		return FALSE;

	crypto_rsa_public_encrypt(settings->ClientRandom, settings->ClientRandomLength, key_len, mod, exp, crypt_client_random);

	/* send crypt client random to server */
	length = RDP_PACKET_HEADER_MAX_LENGTH + RDP_SECURITY_HEADER_LENGTH + 4 + key_len + 8;
	s = Stream_New(NULL, length);

	if (!s)
	{
		WLog_ERR(TAG, "Stream_New failed!");
		goto end;
	}

	rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID);
	rdp_write_security_header(s, SEC_EXCHANGE_PKT | SEC_LICENSE_ENCRYPT_SC);
	length = key_len + 8;

	Stream_Write_UINT32(s, length);
	Stream_Write(s, crypt_client_random, length);
	Stream_SealLength(s);

	status = transport_write(rdp->mcs->transport, s);
	Stream_Free(s, TRUE);

	if (status < 0)
		goto end;

	rdp->do_crypt_license = TRUE;

	/* now calculate encrypt / decrypt and update keys */
	if (!security_establish_keys(settings->ClientRandom, rdp))
		goto end;

	rdp->do_crypt = TRUE;

	if (settings->SaltedChecksum)
		rdp->do_secure_checksum = TRUE;

	if (settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
	{
		rdp->fips_encrypt = winpr_Cipher_New( WINPR_CIPHER_DES_EDE3_CBC,
							WINPR_ENCRYPT,
							rdp->fips_encrypt_key,
							fips_ivec);
		if (!rdp->fips_encrypt)
		{
			WLog_ERR(TAG, "unable to allocate des3 encrypt key");
			goto end;
		}
		rdp->fips_decrypt = winpr_Cipher_New(WINPR_CIPHER_DES_EDE3_CBC,
						     WINPR_DECRYPT,
						     rdp->fips_decrypt_key,
						     fips_ivec);
		if (!rdp->fips_decrypt)
		{
			WLog_ERR(TAG, "unable to allocate des3 decrypt key");
			goto end;
		}

		rdp->fips_hmac = calloc(1, sizeof(WINPR_HMAC_CTX));
		if (!rdp->fips_hmac)
		{
			WLog_ERR(TAG, "unable to allocate fips hmac");
			goto end;
		}
		ret = TRUE;
		goto end;
	}

	rdp->rc4_decrypt_key = winpr_RC4_New(rdp->decrypt_key, rdp->rc4_key_len);
	rdp->rc4_encrypt_key = winpr_RC4_New(rdp->encrypt_key, rdp->rc4_key_len);
	if (!rdp->rc4_decrypt_key || !rdp->rc4_encrypt_key)
		goto end;

	ret = TRUE;
end:
	free(crypt_client_random);
	if (!ret)
	{
		winpr_Cipher_Free(rdp->fips_decrypt);
		winpr_Cipher_Free(rdp->fips_encrypt);
		winpr_RC4_Free(rdp->rc4_decrypt_key);
		winpr_RC4_Free(rdp->rc4_encrypt_key);

		rdp->fips_decrypt = NULL;
		rdp->fips_encrypt = NULL;
		rdp->rc4_decrypt_key = NULL;
		rdp->rc4_encrypt_key = NULL;
	}

	return ret;
}