CryptoSys API Library Manual

AES128_UpdateHex

Carries out the AES transformation function on a hexadecimal string according to the direction and mode set up by an earlier call to AES128_Init() or AES128_InitHex().

VBA/VB6 Syntax

Public Declare Function AES128_UpdateHex Lib "diCryptoSys.dll" (ByVal hContext As Long, ByVal strHexString As String) As Long

nRet = AES128_UpdateHex(hContext, strHexString)

C/C++ Syntax

long __stdcall AES128_UpdateHex(long hContext, char *szHexData);

Parameters

hContext
[in] handle to the AES context set up by an earlier call to AES128_Init() or AES128_InitHex().
szHexData
[in,out] containing input in hexadecimal format to be processed by the AES function and to receive the output.

Returns (VBA/C)

If successful, the return value is 0; otherwise it returns a non-zero error code.

.NET Equivalent

Aes128.Update Method (String)

Remarks

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.

Example

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=128 I=2
' KEY=93286764A85146730E641888DB34EB47
' IV=192D9B3AA10BB2F7846CCBA0085C657A
' PT=983BF6F5A6DFBCDAA19370666E83A99A
' CT=40D8DAF6D1FDA0A073B3BD18B7695D2E

strHexKey = "93286764A85146730E641888DB34EB47"
strIV = "192D9B3AA10BB2F7846CCBA0085C657A"
sBlock = "983BF6F5A6DFBCDAA19370666E83A99A"
sCorrect = "40D8DAF6D1FDA0A073B3BD18B7695D2E"

Debug.Print "AES Monte Carlo CBC Mode Encrypt:"
Debug.Print "KY=" & strHexKey
Debug.Print "IV=" & strIV
Debug.Print "PT=" & sBlock

hContext = AES128_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 = AES128_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 = AES128_Final(hContext)

Debug.Assert (sCorrect = sBlock)

This should result in output as follows:

AES Monte Carlo CBC Mode Encrypt:
KY=93286764A85146730E641888DB34EB47
IV=192D9B3AA10BB2F7846CCBA0085C657A
PT=983BF6F5A6DFBCDAA19370666E83A99A
CT=40D8DAF6D1FDA0A073B3BD18B7695D2E
OK=40D8DAF6D1FDA0A073B3BD18B7695D2E

See Also

AES128_Init AES128_InitHex AES128_Update AES128_Final

[Contents] [Index]

[PREV: AES128_Update...]   [Contents]   [Index]   
   [NEXT: AES192_B64Mode...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.