CryptoSys PKI Pro Manual

XOF_Bytes

Generate bytes using an extendable output function (XOF).

VBA/VB6 Syntax

Public Declare Function XOF_Bytes Lib "diCrPKI.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(abOutput(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:
PKI_XOF_SHAKE128 to use SHAKE128
PKI_XOF_SHAKE256 to use SHAKE256
PKI_XOF_MGF1_SHA1 to use MGF1-SHA-1
PKI_XOF_MGF1_SHA256 to use MGF1-SHA-256
PKI_XOF_MGF1_SHA512 to use MGF1-SHA-512

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 dipki::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 [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].

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, PKI_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 = cnvFromHex("6ae23f058f0f2264a18cd609acc26dd4dbc00f5c3ee9e13ecaea2bb5a2f0bb6b")
' Output 2000 bits
lpOut = xofBytes(2000 \ 8, lpMessage, PKI_XOF_SHAKE256)
Debug.Print "OUT=" & cnvToHex(lpOut)
Debug.Print "OK =" & "b9b92544fb25cf...f1d35bdff79a"
' MGF1-SHA-256
lpMessage = cnvFromHex("3b5c056af3ebba70d4c805380420585562b32410a778f558ff951252407647e3")
Debug.Print cnvToHex(lpMessage)
lpOut = xofBytes(34, lpMessage, PKI_XOF_MGF1_SHA256)
Debug.Print "OUT=" & cnvToHex(lpOut)
Debug.Print "OK =" & "5b7eb772aecf04c74af07d9d9c1c1f8d3a90dcda00d5bab1dc28daecdc86eb87611e"

See Also

PRF_Bytes

[Contents] [Index]

[PREV: X509_VerifyCert...]   [Contents]   [Index]   
   [NEXT: VBA Wrapper Functions...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.