ReactOS
0.4.17-dev-1005-g171e1de
equal.c
Go to the documentation of this file.
1
//
2
// equal.c Memory comparison routine that is safe against side channels.
3
//
4
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
5
//
6
7
#include "
precomp.h
"
8
9
BOOLEAN
10
SYMCRYPT_CALL
11
SymCryptEqual
(
_In_reads_
( cbBytes )
PCBYTE
pbSrc1,
12
_In_reads_
( cbBytes )
PCBYTE
pbSrc2,
13
SIZE_T
cbBytes )
14
{
15
UINT32
neq = 0;
16
BYTE
b
;
17
volatile
BYTE
* p1 = (
volatile
BYTE
*) pbSrc1;
18
volatile
BYTE
* p2 = (
volatile
BYTE
*) pbSrc2;
19
20
//
21
// We use forced-access memory reads to ensure that the compiler doesn't get
22
// smart and implement an early-out solution.
23
//
24
25
while
( cbBytes >= 4 )
26
{
27
neq |=
SYMCRYPT_FORCE_READ32
( (
volatile
UINT32
*) p1 ) ^
SYMCRYPT_FORCE_READ32
( (
volatile
UINT32
*) p2 );
28
p1 += 4;
29
p2 += 4;
30
cbBytes -= 4;
31
}
32
33
// We have to deal with the remaining bytes using a separate accumulator to work around an issue in the ARM64 compiler.
34
if
( cbBytes > 0 )
35
{
36
b
= 0;
37
while
( cbBytes > 0 )
38
{
39
b
|=
SYMCRYPT_FORCE_READ8
( p1 ) ^
SYMCRYPT_FORCE_READ8
( p2 );
40
p1++;
41
p2++;
42
cbBytes--;
43
}
44
neq |=
b
;
45
}
46
47
return
neq == 0;
48
}
BOOLEAN
unsigned char BOOLEAN
Definition:
actypes.h:127
SymCryptEqual
BOOLEAN SYMCRYPT_CALL SymCryptEqual(_In_reads_(cbBytes) PCBYTE pbSrc1, _In_reads_(cbBytes) PCBYTE pbSrc2, SIZE_T cbBytes)
Definition:
equal.c:11
b
GLboolean GLboolean GLboolean b
Definition:
glext.h:6204
b
#define b
Definition:
ke_i.h:79
_In_reads_
#define _In_reads_(s)
Definition:
no_sal2.h:168
SYMCRYPT_FORCE_READ8
#define SYMCRYPT_FORCE_READ8( _p)
Definition:
symcrypt.h:416
SYMCRYPT_FORCE_READ32
#define SYMCRYPT_FORCE_READ32(_p)
Definition:
symcrypt.h:418
SYMCRYPT_CALL
#define SYMCRYPT_CALL
Definition:
symcrypt_internal.h:167
PCBYTE
const BYTE * PCBYTE
Definition:
symcrypt_internal.h:248
SIZE_T
ULONG_PTR SIZE_T
Definition:
typedefs.h:80
UINT32
uint32_t UINT32
Definition:
typedefs.h:59
precomp.h
BYTE
unsigned char BYTE
Definition:
xxhash.c:193
sdk
lib
3rdparty
symcrypt
lib
equal.c
Generated on Tue Oct 6 2026 06:20:06 for ReactOS by
1.9.6