CryptoSys API Library Manual

XOF_Bytes

Generate bytes using an eXtendable Output Function (XOF).

VBA/VB6 Syntax

Public Declare Function XOF_Bytes Lib "diCryptoSys.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByRef lpMessage As Byte, ByVal nMsgLen As Long, ByVal nOptions As Long) As Long

nRet = XOF_Bytes(lpOutput(0), nOutBytes, abMessage(0), nMsgLen, nOptions) ' Note the "(0)" after the byte array parameters

C/C++ Syntax

long __stdcall XOF_Bytes(unsigned char *lpOutput, long nOutBytes, const void *lpMessage, long nMsgLen, long nOptions);

Parameters

lpOutput
[out] byte buffer to receive the output.
nOutBytes
[in] size of output buffer in bytes.
lpMessage
[in] byte array containing the input data.
nMsgLen
[in] length of the input data in bytes.
nOptions
[in] Option flags. Select one of:
API_XOF_SHAKE128 to use SHAKE128
API_XOF_SHAKE256 to use SHAKE256
API_XOF_MGF1_SHA1 to use MGF1-SHA-1
API_XOF_MGF1_SHA256 to use MGF1-SHA-256
API_XOF_MGF1_SHA512 to use MGF1-SHA-512
API_XOF_ASCON_XOF to use ASCON-XOF
API_XOF_ASCON_XOFA to use ASCON-XOFA

Returns (VBA/C)

If successful, the return value is the number of bytes in the output; otherwise it returns a negative error code.

VBA Wrapper Syntax

Public Function xofBytes(nBytes As Long, lpMessage() As Byte, nOptions As Long) As Byte()

.NET Equivalent

Xof.Bytes Method

C++ (STL) Equivalent

static bvec_t crsysapi::Xof::Bytes (int numBytes, const bvec_t &message, XofAlg xofalg)

Python Equivalent

static Xof.bytes(numbytes, msg, xofalg)

Remarks

The output buffer lpOutput must exist. It will be filled with exactly nOutBytes bytes. Note there is no zero option for nOptions: a valid option flag must be specified.

SHAKE128 and SHAKE256 are described in the SHA-3 Standard [FIPS202]. MGF1, despite its name as a Mask Generation Function (MGF), is also an eXtendable Output Function (XOF) using the SHA1/SHA-2 hash functions, and is described in [PKCS1]. The extendable output functions Ascon-Xof and Ascon-Xofa are from the cipher suite ASCON and are provisional subject to final approval by NIST.

Example (VBA core function)

Dim strMsgHex As String
Dim nOutBits As Long
Dim nOutBytes As Long
Dim abOut() As Byte
Dim abMsg() As Byte
Dim nMsgLen As Long
Dim strOK As String
Dim nRet As Long
 
' Ref: "SHA-3 XOF Test Vectors for Byte-Oriented Output"
' File `SHAKE256VariableOut.rsp` COUNT = 1244
' <https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/sha3/shakebytetestvectors.zip>

' Input in hex form
strMsgHex = "6ae23f058f0f2264a18cd609acc26dd4dbc00f5c3ee9e13ecaea2bb5a2f0bb6b"
nOutBits = 2000
strOK = "b9b92544fb25cfe4ec6fe437d8da2bbe00f7bdaface3de97b8775a44d753c3adca3f7c6f183cc8647e229070439aa9539ae1f8f13470c9d3527fffdeef6c94f9f0520ff0c1ba8b16e16014e1af43ac6d94cb7929188cce9d7b02f81a2746f52ba16988e5f6d93298d778dfe05ea0ef256ae3728643ce3e29c794a0370e9ca6a8bf3e7a41e86770676ac106f7ae79e67027ce7b7b38efe27d253a52b5cb54d6eb4367a87736ed48cb45ef27f42683da140ed3295dfc575d3ea38cfc2a3697cc92864305407369b4abac054e497378dd9fd0c4b352ea3185ce1178b3dc1599df69db29259d4735320c8e7d33e8226620c9a1d22761f1d35bdff79a"
' Convert to byte array form
abMsg = cnvBytesFromHexStr(strMsgHex)
nMsgLen = UBound(abMsg) + 1

nOutBytes = (nOutBits / 8)
ReDim abOut(nOutBytes - 1)
nRet = XOF_Bytes(abOut(0), nOutBytes, abMsg(0), nMsgLen, API_XOF_SHAKE256)
If nRet > 0 Then
    Debug.Print "OUT=" & cnvHexStrFromBytes(abOut)
    Debug.Print "OK =" & strOK
Else
   Debug.Print "Error code " & nRet
End If

This should result in output as follows:

OUT=B9B92544FB25CFE4EC6FE437D8DA2BBE00F7BDAFACE3DE97B8775A44D753C3ADCA3F7C6F183CC8647E229070439AA9539AE1F8F13470C9D3527FFFDEEF6C94F9F0520FF0C1BA8B16E16014E1AF43AC6D94CB7929188CCE9D7B02F81A2746F52BA16988E5F6D93298D778DFE05EA0EF256AE3728643CE3E29C794A0370E9CA6A8BF3E7A41E86770676AC106F7AE79E67027CE7B7B38EFE27D253A52B5CB54D6EB4367A87736ED48CB45EF27F42683DA140ED3295DFC575D3EA38CFC2A3697CC92864305407369B4ABAC054E497378DD9FD0C4B352EA3185CE1178B3DC1599DF69DB29259D4735320C8E7D33E8226620C9A1D22761F1D35BDFF79A
OK =b9b92544fb25cfe4ec6fe437d8da2bbe00f7bdaface3de97b8775a44d753c3adca3f7c6f183cc8647e229070439aa9539ae1f8f13470c9d3527fffdeef6c94f9f0520ff0c1ba8b16e16014e1af43ac6d94cb7929188cce9d7b02f81a2746f52ba16988e5f6d93298d778dfe05ea0ef256ae3728643ce3e29c794a0370e9ca6a8bf3e7a41e86770676ac106f7ae79e67027ce7b7b38efe27d253a52b5cb54d6eb4367a87736ed48cb45ef27f42683da140ed3295dfc575d3ea38cfc2a3697cc92864305407369b4abac054e497378dd9fd0c4b352ea3185ce1178b3dc1599df69db29259d4735320c8e7d33e8226620c9a1d22761f1d35bdff79a

Example (VBA wrapper function)

Dim lpMessage() As Byte
Dim lpOut() As Byte
lpMessage = cnvBytesFromHexStr("6ae23f058f0f2264a18cd609acc26dd4dbc00f5c3ee9e13ecaea2bb5a2f0bb6b")
' Output 2000 bits
lpOut = xofBytes(2000 \ 8, lpMessage, API_XOF_SHAKE256)
Debug.Print "OUT=" & cnvHexStrFromBytes(lpOut)
Debug.Print "OK =" & "b9b92544fb25cf...f1d35bdff79a"

See Also

MAC_Bytes PRF_Bytes

[Contents] [Index]

[PREV: WIPE_File...]   [Contents]   [Index]   
   [NEXT: ZLIB_Deflate...]

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