RXS_HMAC()

Performs HMAC calculation.

Requires both a secret as well as a configured RXS_HMACDS_t data structure to be passed in as parameters.

Subprocedure Prototype

CopyrpgleD RXS_HMAC...
D                 PR                  Extproc('RXS_HMAC') Opdesc
D                                     Like(RXS_Var1Kv_t)

Returns a calculated HMAC string. Note that if OutputStmf is set to an IFS path in the configuration data structure, the HMAC string will be written there instead.

CopyrpgleD pInput                              Like(RXS_Var16Mv_t) Const
D                                     Options(*Varsize:*Omit)

Holds the data to be encrypted as part of HMAC calculation. Note that if InputStmf is set to an IFS path in the configuration data structure, the input will be read from there instead.

CopyrpgleD pSecret                             Like(RXS_Var1Kv_t) Const
D                                     Options(*Varsize)

The secret used for HMAC calculation.

CopyrpgleD pDS                                 LikeDS(RXS_HMACDS_t)
D                                     Options(*Varsize)

Controls how HMAC calculation is performed. Uses RXS_HMACDS_t as a template.

Example Code

Copyrpgle*--------------------------------------------------------------
* This example demonstrates how to perform a simple SHA-1 HMAC
* calculation with RXS_HMAC. This example returns the HMAC string
* as text.
* This example is based on a test case from RFC 2202: 
*  https://www.rfc-editor.org/rfc/rfc2202
*--------------------------------------------------------------
Ctl-Opt ActGrp(*New) BndDir('RXSBND');

/COPY QRPGLECPY,RXSCB

Dcl-Ds HMACDS LikeDS(RXS_HMACDS_t);

Dcl-S Input Like(RXS_Var1Kv_t) Inz;
Dcl-S Secret Like(RXS_Var1Kv_t) Inz;
Dcl-S Output Like(RXS_Var1Kv_t) Inz;

RXS_ResetDS( HMACDS : RXS_DS_TYPE_HMAC );

Input = 'what do ya want for nothing?';
Secret = 'Jefe';

HMACDS.InputCcsid = RXS_CCSID_EBCDIC;
HMACDS.SecretCcsid = RXS_CCSID_EBCDIC;
HMACDS.EncryptAsCcsid = RXS_CCSID_ISO88591;

HMACDS.Algorithm = RXS_HMAC_SHA1;

Output = RXS_HMAC( Input : Secret : HMACDS );

Data Structures

CopyrpgleD RXS_HMACDS_t...
D                 DS                  Qualified Template Inz
 
CopyrpgleD   ReturnedErrorInfo...
D                                     LikeDS(RXS_ReturnedErrorInfoDS_t) Inz

If an error occurs during processing, additional error information may be returned in this data structure.

CopyrpgleD   DataStructureType...
D                                5I 0 Inz(RXS_DS_TYPE_HMAC)

Internal use only

CopyrpgleD   OnErrorMessageType...
D                                5I 0
 
CopyrpgleD   Algorithm                    3I 0

Determines which algorithm to use when encrypting.

Valid Values:

  • RXS_HMAC_MD5
  • RXS_HMAC_SHA1
  • RXS_HMAC_SHA256
  • RXS_HMAC_SHA384
  • RXS_HMAC_SHA512

CopyrpgleD   InputCcsid                  10I 0 Inz(RXS_CCSID_JOB)

CCSID of input data. Used when the input data is of a different CCSID than the job CCSID. Not necessary if using InputStmf.

Default Value: RXS_CCSID_JOB

CopyrpgleD   SecretCcsid                 10I 0 Inz(RXS_CCSID_JOB)

CCSID of secret used for HMAC calculation. Used when the secret is of a different CCSID than the job CCSID.

Default Value: RXS_CCSID_JOB

CopyrpgleD   EncryptAsCcsid...
D                               10I 0 Inz(RXS_CCSID_ISO88591)

When performing HMAC calculation, this field will specify the CCSID in which the data should be encrypted. If this value is different than the InputCcsid value, the data will be converted before encryption.

Default Value: RXS_CCSID_ISO88591

CopyrpgleD   ReturnAsChar...
D                                 N   Inz(RXS_YES)

Specifies whether to return the character representation of the hexadecimal binary data.

Valid Values:

  • RXS_YES
  • RXS_NO

Default Value: RXS_YES

CopyrpgleD   InputStmf                         Like(RXS_Var1Kv_t)

Optional IFS stream file to use as input data for HMAC calculation.

CopyrpgleD   OutputStmf                        Like(RXS_Var1Kv_t)

Optional IFS stream file where HMAC output will be written.

CopyrpgleD   InputPointer...
D                                 *

Internal use only

CopyrpgleD   InputLength                 10I 0

Internal use only

CopyrpgleD   OutputPointer...
D                                 *

Internal use only

CopyrpgleD   OutputLength                10I 0

Internal use only