Carries out the TDEA transformation function on a byte array
according to the direction
and mode set up by an earlier call to TDEA_Init() or TDEA_InitHex().
Public Declare Function TDEA_Update Lib "diCryptoSys.dll"
(ByVal hContext As Long, ByRef lpData As Byte, ByVal nDataLen As Long) As Long
nRet = TDEA_Update(hContext, abData(0), nDataLen)
long __stdcall TDEA_Update(long hContext, unsigned char *lpData, long nDataLen);
TDEA_Init() or TDEA_InitHex().If successful, the return value is 0; otherwise it returns a non-zero error code.
Tdea.Update Method (Byte[])
The input data lpData must be an exact multiple of 8 bytes long. If not, an error code will be returned. Note that the output overwrites the input.
This example carries out one of the Monte Carlo tests from NIST 800-20 [SP80020].
Dim nRet As Long
Dim hContext As Long
Dim sCorrect As String
Dim j As Integer
Dim abKey() As Byte
Dim abInitV() As Byte
Dim aBlock() As Byte
Dim aNext() As Byte
Dim aLast() As Byte
aBlock() = StrConv("Now is t", vbFromUnicode)
abKey = cnvBytesFromHexStr( _
"0123456789abcdef23456789abcdef01456789abcdef0123")
abInitV = cnvBytesFromHexStr("1234567890abcdef")
sCorrect = "cb191f85d1ed8439"
Debug.Print "TDEA Monte Carlo TCBC Mode Encrypt:"
Debug.Print "KY=" & cnvHexStrFromBytes(abKey)
Debug.Print "IV=" & cnvHexStrFromBytes(abInitV)
Debug.Print "PT=" & cnvHexStrFromBytes(aBlock)
hContext = TDEA_Init(abKey(0), True, "CBC", abInitV(0))
If hContext = 0 Then
nRet = TDEA_InitError()
Debug.Print "TDEA_Init Failed: " & apiErrorLookup(nRet)
Exit Function
End If
' Do 10,000 times
aNext() = aBlock()
For j = 0 To 9999
aBlock() = aNext()
nRet = TDEA_Update(hContext, aBlock(0), 8)
If j = 0 Then
aNext() = abInitV()
Else
aNext() = aLast()
End If
aLast() = aBlock()
Next
Debug.Print "CT=" & cnvHexStrFromBytes(aBlock)
Debug.Print "OK=" & sCorrect
nRet = TDEA_Final(hContext)
Debug.Assert (sCorrect = cnvHexStrFromBytes(aBlock))
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_UpdateHex
TDEA_Final