Carries out the AES transformation function on a hexadecimal string
according to the direction
and mode set up by an earlier call to AES256_Init()
or AES256_InitHex()
.
Public Declare Function AES256_UpdateHex Lib "diCryptoSys.dll"
(ByVal hContext As Long, ByVal strHexString As String) As Long
nRet = AES256_UpdateHex(hContext, strHexString)
long __stdcall AES256_UpdateHex(long hContext, char *szHexData);
AES256_Init()
or AES256_InitHex()
.If successful, the return value is 0; otherwise it returns a non-zero error code.
Aes256.Update Method (String)
The length of the input string szHexString must be a multiple of 32 hex characters long (i.e. representing a multiple of the block size of 16 bytes). If not, an error code will be returned. Valid hexadecimal characters are [0-9A-Fa-f]. Note that the output overwrites the input. szHexString must be a variable that can receive the output, not a constant.
This example carries out the second [MOVS] Monte Carlo 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 sBlock As String Dim strHexKey As String Dim strIV As String Dim sNext As String Dim sLast As String Dim sCorrect As String Dim j As Integer ' cbc_e_m.txt ' KEYSIZE=256 I=2 ' KEY=33A36646FE56F70DC0C51A3117E639F182DEF8CAB5C06671EEA0407C48A9C757 ' IV=7CE2ABAF8BEF23C4816DC8CE842048A7 ' PT=81EA5BA46945C1705F6F89778868CC67 ' CT=50CD14A12C6852D39654C816BFAF9AC2 strHexKey = _ "33A36646FE56F70DC0C51A3117E639F182DEF8CAB5C06671EEA0407C48A9C757" strIV = "7CE2ABAF8BEF23C4816DC8CE842048A7" sBlock = "81EA5BA46945C1705F6F89778868CC67" sCorrect = "50CD14A12C6852D39654C816BFAF9AC2" Debug.Print "AES Monte Carlo CBC Mode Encrypt:" Debug.Print "KY=" & strHexKey Debug.Print "IV=" & strIV Debug.Print "PT=" & sBlock hContext = AES256_InitHex(strHexKey, ENCRYPT, "CBC", strIV) If hContext = 0 Then MsgBox "Failed to set context", vbCritical Exit Function End If ' Do 10,000 times sNext = sBlock For j = 0 To 9999 sBlock = sNext nRet = AES256_UpdateHex(hContext, sBlock) If j = 0 Then sNext = strIV Else sNext = sLast End If sLast = sBlock Next Debug.Print "CT=" & sBlock Debug.Print "OK=" & sCorrect nRet = AES256_Final(hContext) Debug.Assert (sCorrect = sBlock)
This should result in output as follows:
AES Monte Carlo CBC Mode Encrypt: KY=33A36646FE56F70DC0C51A3117E639F182DEF8CAB5C06671EEA0407C48A9C757 IV=7CE2ABAF8BEF23C4816DC8CE842048A7 PT=81EA5BA46945C1705F6F89778868CC67 CT=50CD14A12C6852D39654C816BFAF9AC2 OK=50CD14A12C6852D39654C816BFAF9AC2
AES256_Init
AES256_InitHex
AES256_Update
AES256_Final