Carries out the AES transformation function on a hexadecimal string
according to the direction
and mode set up by an earlier call to AES192_Init()
or AES192_InitHex()
.
Public Declare Function AES192_UpdateHex Lib "diCryptoSys.dll"
(ByVal hContext As Long, ByVal strHexString As String) As Long
nRet = AES192_UpdateHex(hContext, strHexString)
long __stdcall AES192_UpdateHex(long hContext, char *szHexData);
AES192_Init()
or AES192_InitHex()
.If successful, the return value is 0; otherwise it returns a non-zero error code.
Aes192.Update Method (String)
szHexString 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 third (I=2) [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=192 I=2 ' KEY=74D3414C2374367BFD4560CED3172B0E57571D88A2E13874 ' IV=869C061BE9CFEAB5D285B0724A9A8970 ' PT=C6FB25A188CF7F3F24B07896C0C76D90 ' CT=9E58A52B3840DBE16E8063A18220FEE4 strHexKey = "74D3414C2374367BFD4560CED3172B0E57571D88A2E13874" strIV = "869C061BE9CFEAB5D285B0724A9A8970" sBlock = "C6FB25A188CF7F3F24B07896C0C76D90" sCorrect = "9E58A52B3840DBE16E8063A18220FEE4" Debug.Print "AES Monte Carlo CBC Mode Encrypt:" Debug.Print "KY=" & strHexKey Debug.Print "IV=" & strIV Debug.Print "PT=" & sBlock hContext = AES192_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 = AES192_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 = AES192_Final(hContext) Debug.Assert (sCorrect = sBlock)
This should result in output as follows:
AES Monte Carlo CBC Mode Encrypt: KY=74D3414C2374367BFD4560CED3172B0E57571D88A2E13874 IV=869C061BE9CFEAB5D285B0724A9A8970 PT=C6FB25A188CF7F3F24B07896C0C76D90 CT=9E58A52B3840DBE16E8063A18220FEE4 OK=9E58A52B3840DBE16E8063A18220FEE4
AES192_Init
AES192_InitHex
AES192_Update
AES192_Final