CryptoSys API Library Manual

BLF_Update

Carries out the Blowfish transformation function on a byte array according to the direction and mode set up by an earlier call to BLF_Init() or BLF_InitHex().

VBA/VB6 Syntax

Public Declare Function BLF_Update Lib "diCryptoSys.dll" (ByVal hContext As Long, ByRef lpData As Byte, ByVal nDataLen As Long) As Long

nRet = BLF_Update(hContext, abData(0), nDataLen)

C/C++ Syntax

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

Parameters

hContext
[in] handle to the BLF context set up by an earlier call to BLF_Init() or BLF_InitHex().
lpData
[in,out] array containing the input to be processed by the BLF function and to receive the output.
nDataLen
[in] containing length of the data in bytes.

Returns (VBA/C)

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

.NET Equivalent

Blowfish.Update Method (Byte[])

Remarks

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

    ' Contrived example to encrypt sample blocks in CBC mode
    Dim abBlock(7) As Byte
    Dim abKey() As Byte
    Dim nKeyLen As Long
    Dim abInitV() As Byte
    Dim hContext As Long
    Dim nRet As Long
    Dim i As Integer
    Dim j As Integer
   
    ' Specify a key and its length
    abKey = cnvBytesFromHexStr("FEDCBA9876543210")
    nKeyLen = UBound(abKey) - LBound(abKey) + 1
    
    ' And an IV (length is assumed to be 8 bytes)
    abInitV = cnvBytesFromHexStr("0123456789abcdef")
    
    ' Initialise the context
    hContext = BLF_Init(abKey(0), nKeyLen, ENCRYPT, "CBC", abInitV(0))
    If hContext = 0 Then
        nRet = BLF_InitError()
        Debug.Print "BFL_Init Failed: " & apiErrorLookup(nRet)
        Exit Function
    End If
    
    Debug.Print "KY=" & cnvHexStrFromBytes(abKey)
    Debug.Print "IV=" & cnvHexStrFromBytes(abInitV)
    
    ' Create some test blocks and encrypt them
    For i = 1 To 4
        For j = 0 To 7
            abBlock(j) = CByte(i)
        Next
        Debug.Print "PT(" & i & ")=" & cnvHexStrFromBytes(abBlock)
        nRet = BLF_Update(hContext, abBlock(0), 8)
        Debug.Print "CT(" & i & ")=" & cnvHexStrFromBytes(abBlock)
    Next
    
    ' Clear the context
    BLF_Final (hContext)

This should result in output as follows:

KY=FEDCBA9876543210
IV=0123456789ABCDEF
PT(1)=0101010101010101
CT(1)=46733BCD9C72C5E3
PT(2)=0202020202020202
CT(2)=F434DA62B6869A06
PT(3)=0303030303030303
CT(3)=2AE6DFE458559138
PT(4)=0404040404040404
CT(4)=DEEBF97D6F83A5F3

See Also

BLF_Init BLF_InitHex BLF_UpdateHex BLF_Final

[Contents] [Index]

[PREV: BLF_InitHex...]   [Contents]   [Index]   
   [NEXT: BLF_UpdateHex...]

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