forked from microsoft/SymCrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aes-asm.c
56 lines (48 loc) · 2.08 KB
/
aes-asm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// aes-asm.c code for AES implementation
//
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
//
#include "precomp.h"
VOID
SYMCRYPT_CALL
SymCryptAesEcbEncryptAsm(
_In_ PCSYMCRYPT_AES_EXPANDED_KEY pExpandedKey,
_In_reads_( cbData ) PCBYTE pbSrc,
_Out_writes_( cbData ) PBYTE pbDst,
SIZE_T cbData )
{
SIZE_T cbToDo = cbData & ~(SYMCRYPT_AES_BLOCK_SIZE - 1);
SIZE_T i;
//
// This loop condition is slightly strange.
// If I use i < cbToDo (which is correct) then Prefast complains about buffer overflows.
// Even using SYMCRYPT_ASSERT which does an _Analysis_assume_ I can't fix the Prefast issue.
// The +15 in the code is slightly slower but it solves the Prefast issue.
//
for( i=0; (i+SYMCRYPT_AES_BLOCK_SIZE-1) < cbToDo; i+= SYMCRYPT_AES_BLOCK_SIZE )
{
SymCryptAesEncryptAsm( pExpandedKey, pbSrc + i, pbDst + i );
}
}
VOID
SYMCRYPT_CALL
SymCryptAesEcbDecryptAsm(
_In_ PCSYMCRYPT_AES_EXPANDED_KEY pExpandedKey,
_In_reads_( cbData ) PCBYTE pbSrc,
_Out_writes_( cbData ) PBYTE pbDst,
SIZE_T cbData )
{
SIZE_T cbToDo = cbData & ~(SYMCRYPT_AES_BLOCK_SIZE - 1);
SIZE_T i;
//
// This loop condition is slightly strange.
// If I use i < cbToDo (which is correct) then Prefast complains about buffer overflows.
// Even using SYMCRYPT_ASSERT which does an _Analysis_assume_ I can't fix the Prefast issue.
// The +15 in the code is slightly slower but it solves the Prefast issue.
//
for( i=0; (i+SYMCRYPT_AES_BLOCK_SIZE-1) < cbToDo; i+= SYMCRYPT_AES_BLOCK_SIZE )
{
SymCryptAesDecryptAsm( pExpandedKey, pbSrc + i, pbDst + i );
}
}