CryptoSys API Library Manual

AES256_UpdateHex

Carries out the AES transformation function on a hexadecimal string 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_UpdateHex Lib "diCryptoSys.dll" (ByVal hContext As Long, ByVal strHexString As String) As Long

nRet = AES256_UpdateHex(hContext, strHexString)

C/C++ Syntax

long __stdcall AES256_UpdateHex(long hContext, char *szHexData);

Parameters

hContext
[in] handle to the AES context set up by an earlier call to AES256_Init() or AES256_InitHex().
szHexData
[in,out] containing input in hexadecimal format to be processed by the AES function and to receive the output.

Returns (VBA/C)

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

.NET Equivalent

Aes256.Update Method (String)

Remarks

The length of the input string szHexString must be a multiple of 32 hex characters long (i.e. representing a multiple of the block size of 16 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.

Example

This example carries out the second [MOVS] Monte Carlo 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 sBlock As String
    Dim strHexKey As String
    Dim strIV As String
    Dim sNext As String
    Dim sLast As String
    Dim sCorrect As String
    Dim j As Integer
  
' cbc_e_m.txt
' KEYSIZE=256 I=2
' KEY=33A36646FE56F70DC0C51A3117E639F182DEF8CAB5C06671EEA0407C48A9C757
' IV=7CE2ABAF8BEF23C4816DC8CE842048A7
' PT=81EA5BA46945C1705F6F89778868CC67
' CT=50CD14A12C6852D39654C816BFAF9AC2
    
    strHexKey = _
    "33A36646FE56F70DC0C51A3117E639F182DEF8CAB5C06671EEA0407C48A9C757"
    strIV = "7CE2ABAF8BEF23C4816DC8CE842048A7"
    sBlock = "81EA5BA46945C1705F6F89778868CC67"
    sCorrect = "50CD14A12C6852D39654C816BFAF9AC2"
    
    Debug.Print "AES Monte Carlo CBC Mode Encrypt:"
    Debug.Print "KY=" & strHexKey
    Debug.Print "IV=" & strIV
    Debug.Print "PT=" & sBlock
    
    hContext = AES256_InitHex(strHexKey, ENCRYPT, "CBC", strIV)
    If hContext = 0 Then
        MsgBox "Failed to set context", vbCritical
        Exit Function
    End If
    ' Do 10,000 times
    sNext = sBlock
    For j = 0 To 9999
        sBlock = sNext
        nRet = AES256_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 = AES256_Final(hContext)
    
    Debug.Assert (sCorrect = sBlock)

This should result in output as follows:

AES Monte Carlo CBC Mode Encrypt:
KY=33A36646FE56F70DC0C51A3117E639F182DEF8CAB5C06671EEA0407C48A9C757
IV=7CE2ABAF8BEF23C4816DC8CE842048A7
PT=81EA5BA46945C1705F6F89778868CC67
CT=50CD14A12C6852D39654C816BFAF9AC2
OK=50CD14A12C6852D39654C816BFAF9AC2

See Also

AES256_Init AES256_InitHex AES256_Update AES256_Final

[Contents] [Index]

[PREV: AES256_Update...]   [Contents]   [Index]   
   [NEXT: API_CompileTime...]

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