Carries out the TDEA transformation function on a hexadecimal string
according to the direction
and mode set up by an earlier call to TDEA_Init()
or TDEA_InitHex()
.
Public Declare Function TDEA_UpdateHex Lib "diCryptoSys.dll"
(ByVal hContext As Long, ByVal strHexString As String) As Long
nRet = TDEA_UpdateHex(hContext, strHexString)
long __stdcall TDEA_UpdateHex(long hContext, char *szHexData);
TDEA_Init()
or TDEA_InitHex()
.If successful, the return value is 0; otherwise it returns a non-zero error code.
Tdea.Update Method (String)
szHexString must be a multiple of 16 hex characters long (i.e. representing a multiple of 8 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.
Dim nRet As Long Dim hContext As Long Dim sBlock As String Dim strKey As String Dim strIV As String Dim sNext As String Dim sLast As String Dim sCorrect As String Dim j As Integer sBlock = "4e6f772069732074" strKey = "0123456789abcdef" & _ "23456789abcdef01" & _ "456789abcdef0123" strIV = "1234567890abcdef" sCorrect = "cb191f85d1ed8439" Debug.Print "TDEA Monte Carlo TCBC Mode Encrypt:" Debug.Print "KY=" & strKey Debug.Print "IV=" & strIV Debug.Print "PT=" & sBlock hContext = TDEA_InitHex(strKey, True, "CBC", strIV) If hContext = 0 Then Exit Function End If ' Do 10,000 times sNext = sBlock For j = 0 To 9999 sBlock = sNext nRet = TDEA_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 = TDEA_Final(hContext)
This should result in output as follows:
TDEA Monte Carlo TCBC Mode Encrypt: KY=0123456789abcdef23456789abcdef01456789abcdef0123 IV=1234567890abcdef PT=4e6f772069732074 CT=CB191F85D1ED8439 OK=cb191f85d1ed8439
TDEA_Init
TDEA_InitHex
TDEA_Update
TDEA_Final