ReactOS 0.4.17-dev-1005-g171e1de
xtsaes_pattern.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

VOID SYMCRYPT_CALL SYMCRYPT_XtsAesXxx (_In_ PCSYMCRYPT_XTS_AES_EXPANDED_KEY pExpandedKey, SIZE_T cbDataUnit, _In_reads_(SYMCRYPT_AES_BLOCK_SIZE) PCBYTE pbTweak, _In_reads_(cbData) PCBYTE pbSrc, _Out_writes_(cbData) PBYTE pbDst, SIZE_T cbData, BOOLEAN bOverflow)
 

Function Documentation

◆ SYMCRYPT_XtsAesXxx()

VOID SYMCRYPT_CALL SYMCRYPT_XtsAesXxx ( _In_ PCSYMCRYPT_XTS_AES_EXPANDED_KEY  pExpandedKey,
SIZE_T  cbDataUnit,
_In_reads_(SYMCRYPT_AES_BLOCK_SIZE) PCBYTE  pbTweak,
_In_reads_(cbData) PCBYTE  pbSrc,
_Out_writes_(cbData) PBYTE  pbDst,
SIZE_T  cbData,
BOOLEAN  bOverflow 
)

Definition at line 13 of file xtsaes_pattern.c.

21{
23 // SYMCRYPT_ALIGN BYTE localScratch[N_PARALLEL_TWEAKS * SYMCRYPT_AES_BLOCK_SIZE];
24 // or
25 // /* Defining localScratch as a buffer of __m128is ensures there is required 16B alignment on x86 */
26 // __m128i localScratch[ N_PARALLEL_TWEAKS + 16 ];
27 // Note that the extra 16 __m128i space is used for internal scratch space for SymCryptXtsAesEncryptDataUnitXmm
28 // This allows modified tweak generation to be performed in scalar registers in parallel with AES in Xmm register
29 // which reduces register pressure and increases throughput
30 PBYTE tweakBuf = (PBYTE) &localScratch[0];
31 SIZE_T i, tweakBytes;
32 UINT64 tweakLow64 = SYMCRYPT_LOAD_LSBFIRST64(pbTweak);
33 UINT64 tweakHigh64 = SYMCRYPT_LOAD_LSBFIRST64(pbTweak+8);
34 UINT64 previousTweakLow64;
35
36 SYMCRYPT_ASSERT( cbData % cbDataUnit == 0 );
37
38 while( cbData >= cbDataUnit )
39 {
40 //
41 // We encrypt the tweaks of many data units in parallel for best performance.
42 // In the first loop we build the tweaks and decrement cbData.
43 // In the second loop we use up all the tweaks, and update the pointers.
44 // Both loops are executed the same number of times.
45 //
46 tweakBytes = 0;
47 previousTweakLow64 = tweakLow64;
48
49 do // do-while because we know we are going to go through at least once.
50 {
51 SYMCRYPT_STORE_LSBFIRST64(&tweakBuf[tweakBytes ], tweakLow64);
52 SYMCRYPT_STORE_LSBFIRST64(&tweakBuf[tweakBytes + 8], tweakHigh64);
53 tweakLow64++;
54 cbData -= cbDataUnit;
55 tweakBytes += SYMCRYPT_AES_BLOCK_SIZE;
56 } while( cbData >= cbDataUnit && tweakBytes < SYMCRYPT_AES_BLOCK_SIZE * N_PARALLEL_TWEAKS );
57
58 if( bOverflow && previousTweakLow64 > tweakLow64 )
59 {
60 // Very rare fix-up of tweaks if tweakLow64 overflowed, and should have incremented tweakHigh64
61 // bOverflow=FALSE allows backwards compatibility with old API which wrapped around at 64-bits
62 SYMCRYPT_ASSERT( tweakLow64 < N_PARALLEL_TWEAKS );
63
64 // Increment tweakHigh64 and store new value in high half of the previous tweakLow64 tweaks
65 tweakHigh64++;
66 for( i=0; i<tweakLow64; i++)
67 {
68 SYMCRYPT_STORE_LSBFIRST64(&tweakBuf[tweakBytes - (16*i) - 8], tweakHigh64);
69 }
70 }
71
72 SYMCRYPT_AesEcbEncryptXxx( &pExpandedKey->key2, &tweakBuf[0], &tweakBuf[0], tweakBytes );
73
74 i = 0;
75 while( i < tweakBytes )
76 {
78 // SymCryptXtsAesXxcryptDataUnitXxx( &pExpandedKey->key1, &tweakBuf[i], pbSrc, pbDst, cbDataUnit );
79 // or
80 // SymCryptXtsAesXxcryptDataUnitXxx( &pExpandedKey->key1, &tweakBuf[i], (PBYTE) &localScratch[N_PARALLEL_TWEAKS], pbSrc, pbDst, cbDataUnit );
81 // Note that the scratch space being provided to the DataUnit function is an offset into the localScratch buffer
82
83 pbSrc += cbDataUnit;
84 pbDst += cbDataUnit;
86 }
87 }
88
89 SymCryptWipeKnownSize( localScratch, sizeof( localScratch ) );
90}
COMPILER_DEPENDENT_UINT64 UINT64
Definition: actypes.h:131
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
BYTE * PBYTE
Definition: pedump.c:66
#define SYMCRYPT_ASSERT(_x)
Definition: symcrypt.h:10807
FORCEINLINE VOID SYMCRYPT_CALL SymCryptWipeKnownSize(_Out_writes_bytes_(cbData) PVOID pbData, SIZE_T cbData)
#define SYMCRYPT_LOAD_LSBFIRST64(p)
Definition: symcrypt.h:300
#define SYMCRYPT_AES_BLOCK_SIZE
Definition: symcrypt.h:4255
#define SYMCRYPT_STORE_LSBFIRST64(p, v)
Definition: symcrypt.h:308
PCBYTE pbSrc
PCBYTE PBYTE SIZE_T cbData
PCBYTE PBYTE pbDst
PCVOID pExpandedKey
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define SYMCRYPT_XTS_AES_LOCALSCRATCH_DEFN
Definition: xtsaes.c:79
#define SYMCRYPT_AesEcbEncryptXxx
Definition: xtsaes.c:82
#define N_PARALLEL_TWEAKS
Definition: xtsaes.c:77
#define SYMCRYPT_XTSAESDATAUNIT_INVOKE
Definition: xtsaes.c:92