Carries out the AES transformation function on a byte array
according to the direction
and mode set up by an earlier call to AES256_Init()
or AES256_InitHex()
.
Public Declare Function AES256_Update Lib "diCryptoSys.dll"
(ByVal hContext As Long, ByRef lpData As Byte, ByVal nDataLen As Long) As Long
nRet = AES256_Update(hContext, abData(0), nDataLen)
long __stdcall AES256_Update(long hContext, unsigned char *lpData, long nDataLen);
AES256_Init()
or AES256_InitHex()
.If successful, the return value is 0; otherwise it returns a non-zero error code.
Aes256.Update Method (Byte[])
The input array lpData must be a multiple of the block size of 16 bytes long. If not, an error code will be returned. Note that the output overwrites the input.
This example carries out the second Monte Carlo MOVS test in CBC encrypt mode. (Ref: AES Candidate Algorithm Submissions, update 17 Feb 1998, file cbc_e_m.txt [RIJNVALS]).
Dim nRet As Long Dim hContext As Long Dim abBlock() As Byte Dim abKey() As Byte Dim abCorrect() As Byte Dim j As Integer ' File: ecb_d_m.txt ' KEYSIZE=256 I=2 ' KEY=2447EC44111548FBB670B98F182D5DEE109BF5F30D9464ED411F18A63C53A998 ' CT=15173A0EB65F5CC05E704EFE61D9E346 ' PT=85F083ACC676D91EDD1ABFB43935237A ' Convert to Byte format abKey = _ cnvBytesFromHexStr("2447EC44111548FBB670B98F182D5DEE109BF5F30D9464ED411F18A63C53A998") abBlock = cnvBytesFromHexStr("15173A0EB65F5CC05E704EFE61D9E346") abCorrect = cnvBytesFromHexStr("85F083ACC676D91EDD1ABFB43935237A") Debug.Print "AES Monte Carlo ECB Mode Decrypt:" Debug.Print "KY=" & cnvHexStrFromBytes(abKey) Debug.Print "CT=" & cnvHexStrFromBytes(abBlock) hContext = AES256_Init(abKey(0), DECRYPT, "ECB", 0) If hContext = 0 Then MsgBox "Failed to set context", vbCritical Exit Function End If ' Do 10,000 times For j = 0 To 9999 nRet = AES256_Update(hContext, abBlock(0), 16) Next Debug.Print "PT=" & cnvHexStrFromBytes(abBlock) Debug.Print "OK=" & cnvHexStrFromBytes(abCorrect) nRet = AES256_Final(hContext) Debug.Assert (StrConv(abCorrect, vbUnicode) = StrConv(abBlock, vbUnicode))
This should result in output as follows:
AES Monte Carlo ECB Mode Decrypt: KY=2447EC44111548FBB670B98F182D5DEE109BF5F30D9464ED411F18A63C53A998 CT=15173A0EB65F5CC05E704EFE61D9E346 PT=85F083ACC676D91EDD1ABFB43935237A OK=85F083ACC676D91EDD1ABFB43935237A
AES256_Init
AES256_InitHex
AES256_UpdateHex
AES256_Final