Carries out the AES transformation function on a byte array
according to the direction
and mode set up by an earlier call to AES128_Init
or AES128_InitHex.
Public Declare Function AES128_Update Lib "diCryptoSys.dll"
(ByVal hContext As Long, ByRef abData As Byte, ByVal nDataLen As Long) As Long
nRet = AES128_Update(hContext, abData(0), nDataLen)
Long handle to the AES context set up by an earlier call to
AES128_Init or AES128_InitHex.Byte array containing the input
to be processed by the AES function and to receive the output.Long containing length of the data in bytes.
long _stdcall AES128_Update(long ctx_handle, unsigned char *data, long dataLen);
Long: If successful, the return value is 0;
otherwise it returns a non-zero error code.
Aes128.Update Method (Byte[])
The input array abData must be an exact multiple of 16 bytes long. If not, an error code will be returned. Note that the output overwrites the input.
This example carries out the third (I=2) Monte Carlo MOVS test in ECB decrypt 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=128 I=2
' KEY=A7BC3BD0EABD9EBA981E23E6FFC9C9C2
' CT=E3FD51123B48A2E2AB1DB29894202222
' PT=877B88A77AEF04F05546539E17259F53
' Convert to Byte format
abKey = cnvBytesFromHexStr("A7BC3BD0EABD9EBA981E23E6FFC9C9C2")
abBlock = cnvBytesFromHexStr("E3FD51123B48A2E2AB1DB29894202222")
abCorrect = cnvBytesFromHexStr("877B88A77AEF04F05546539E17259F53")
Debug.Print "AES Monte Carlo ECB Mode Decrypt:"
Debug.Print "KY="; cnvHexStrFromBytes(abKey)
Debug.Print "CT="; cnvHexStrFromBytes(abBlock)
hContext = AES128_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 = AES128_Update(hContext, abBlock(0), 16)
Next
Debug.Print "PT="; cnvHexStrFromBytes(abBlock)
Debug.Print "OK="; cnvHexStrFromBytes(abCorrect)
nRet = AES128_Final(hContext)
Debug.Assert (StrConv(abCorrect, vbUnicode) = StrConv(abBlock, vbUnicode))
This should result in output as follows:
AES Monte Carlo ECB Mode Decrypt: KY=A7BC3BD0EABD9EBA981E23E6FFC9C9C2 CT=E3FD51123B48A2E2AB1DB29894202222 PT=877B88A77AEF04F05546539E17259F53 OK=877B88A77AEF04F05546539E17259F53
AES128_Init
AES128_InitHex
AES128_UpdateHex
AES128_Final