CryptoSys API Library Manual

TDEA_Update

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().

VBA/VB6 Syntax

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)

C/C++ Syntax

long __stdcall TDEA_Update(long hContext, unsigned char *lpData, long nDataLen);

Parameters

hContext
[in] handle to the TDEA context set up by an earlier call to TDEA_Init() or TDEA_InitHex().
lpData
[in,out] array containing the input data.
nDataLen
[in] equal to length of the input data in bytes.

Returns (VBA/C)

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

.NET Equivalent

Tdea.Update Method (Byte[])

Remarks

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.

Example

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

See Also

TDEA_Init TDEA_InitHex TDEA_UpdateHex TDEA_Final

[Contents] [Index]

[PREV: TDEA_InitHex...]   [Contents]   [Index]   
   [NEXT: TDEA_UpdateHex...]

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