CryptoSys API Library Manual

AES256_Update

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

VBA/VB6 Syntax

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

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

C/C++ Syntax

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

Parameters

hContext
[in] handle to the AES context set up by an earlier call to AES256_Init() or AES256_InitHex().
lpData
[in,out] array containing the input to be processed by the AES 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

Aes256.Update Method (Byte[])

Remarks

The input array lpData must be a multiple of the block size of 16 bytes long. If not, an error code will be returned. Note that the output overwrites the input.

Example

This example carries out the second Monte Carlo MOVS 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 abBlock() As Byte
    Dim abKey() As Byte
    Dim abCorrect() As Byte
    Dim j As Integer
    
' File: ecb_d_m.txt
' KEYSIZE=256 I=2
' KEY=2447EC44111548FBB670B98F182D5DEE109BF5F30D9464ED411F18A63C53A998
' CT=15173A0EB65F5CC05E704EFE61D9E346
' PT=85F083ACC676D91EDD1ABFB43935237A
    ' Convert to Byte format
    abKey = _
    cnvBytesFromHexStr("2447EC44111548FBB670B98F182D5DEE109BF5F30D9464ED411F18A63C53A998")
    abBlock = cnvBytesFromHexStr("15173A0EB65F5CC05E704EFE61D9E346")
    abCorrect = cnvBytesFromHexStr("85F083ACC676D91EDD1ABFB43935237A")
    
    Debug.Print "AES Monte Carlo ECB Mode Decrypt:"
    Debug.Print "KY=" & cnvHexStrFromBytes(abKey)
    Debug.Print "CT=" & cnvHexStrFromBytes(abBlock)
    
    hContext = AES256_Init(abKey(0), DECRYPT, "ECB", 0)
    If hContext = 0 Then
        MsgBox "Failed to set context", vbCritical
        Exit Function
    End If
    ' Do 10,000 times
    For j = 0 To 9999
        nRet = AES256_Update(hContext, abBlock(0), 16)
    Next
    Debug.Print "PT=" & cnvHexStrFromBytes(abBlock)
    Debug.Print "OK=" & cnvHexStrFromBytes(abCorrect)
    nRet = AES256_Final(hContext)
    
    Debug.Assert (StrConv(abCorrect, vbUnicode) = StrConv(abBlock, vbUnicode))

This should result in output as follows:

AES Monte Carlo ECB Mode Decrypt:
KY=2447EC44111548FBB670B98F182D5DEE109BF5F30D9464ED411F18A63C53A998
CT=15173A0EB65F5CC05E704EFE61D9E346
PT=85F083ACC676D91EDD1ABFB43935237A
OK=85F083ACC676D91EDD1ABFB43935237A

See Also

AES256_Init AES256_InitHex AES256_UpdateHex AES256_Final

[Contents] [Index]

[PREV: AES256_InitHex...]   [Contents]   [Index]   
   [NEXT: AES256_UpdateHex...]

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