Calculate HMAC (QC3CALHM, Qc3CalculateHMAC) API


  Required Parameter Group:


  Service Program Name: QC3HMAC

  Default Public Authority: *USE

  Threadsafe: Yes

The Calculate HMAC (OPM, QC3CALHM; ILE Qc3CalculateHMAC) API uses a one-way hash function and a secret shared key to produce an authentication value. The HMAC function is documented in RFC 2104.

Information on cryptographic standards can be found in Create Algorithm Context (OPM, QC3CRTAX; ILE, Qc3CreateAlgorithmContext) API.


Authorities and Locks

Required device description authority
*USE

Required file authority
*OBJOPR, *READ

Required Parameter Group

Input data
INPUT; CHAR(*)

The data to hash.
The format of the input data is specified in the input data format name parameter

Length of input data
INPUT; BINARY(4)

For input data format DATA0100, this is the length of the data to hash.
For input data format DATA0200, this is the number of entries in the array.

Input data format name
INPUT; CHAR(8)

The format of the input data parameter.
The possible format names follow.

DATA0100
The input data parameter contains the data to hash.

DATA0200
The input data parameter contains an array of pointers and lengths to the data to hash.
See Input Data Formats for a description of this format.

Algorithm description
INPUT; CHAR(*)

The algorithm and associated parameters for hashing the data.
The format of the algorithm description is specified in the algorithm description format name parameter.

Algorithm description format name
INPUT; CHAR(8)

The format of the algorithm description.
The possible format names follow.

ALGD0100
The token for an algorithm context. This format must be used when performing the HMAC operation over multiple calls. After the last call (when the final operation flag is on), the context will reset to its initial state and can be used in another API.

ALGD0500
Parameters for a hash algorithm (MD5, SHA-1, SHA-256, SHA-384, or SHA512)

See Algorithm Description Formats for a description of these formats.

Key description
INPUT; CHAR(*)

The key and associated parameters for the HMAC operation.
The format of the key description is specified in the key description format name parameter.
If the HMAC operation extends over multiple calls (see ALGD0100 description above), only the key description from the first call will be used. Therefore, on subsequent calls, you may set the pointer to this parameter to NULL.

Key description format name
INPUT; CHAR(8)

The format of the key description.
If the pointer to the key description parameter is NULL, this parameter will be ignored.
The possible format names follow.

KEYD0100
The token for a key context. This format identifies a key context. A key context is used to store a key value so it need not be recreated or retrieved every time it is used. To create a key context, use the Create Key Context (OPM, QC3CRTKX; ILE, Qc3CreateKeyContext) API.

KEYD0200
Key parameters.

KEYD0400
Keystore label. This format identifies a key from keystore. For more information about cryptographic services keystore, see Cryptographic Services Keystore.

KEYD0500
PKCS5 passphrase. This format derives a key using RSA Data Security, Inc. Public-Key Cryptography Standard (PKCS) #5.

See Key Description Formats for a description of these formats.

Cryptographic service provider
INPUT; CHAR(1)

The cryptographic service provider (CSP) that will perform the decryption operation.


Cryptographic device name
INPUT; CHAR(10)

The name of a cryptographic device description.
This parameter is valid when the cryptographic service provider parameter specifies 2 (hardware CSP). Otherwise, this parameter must be blanks or the pointer to this parameter set to NULL.

HMAC
OUTPUT; CHAR(*)

The area to store the HMAC. The length of HMAC is defined by the hash algorithm.


Error code
I/O; CHAR(*)

The structure in which to return error information.
For the format of the structure, see Error code parameter.


Input Data Formats

For detailed descriptions of the table fields, see Input Data Formats Field Descriptions.

DATA0200 Format



Input Data Formats Field Descriptions

Input data length
The length of data to hash.
Input data pointer
A space pointer to the data to hash.
Reserved
Must be null (binary 0s).

Algorithm Description Formats

For detailed descriptions of the table fields, see Algorithm Description Formats Field Descriptions.

ALGD0100 Format

ALGD0500 Format



Algorithm Description Formats Field Descriptions

Algorithm context token
A token for an algorithm context. The algorithm context is created by using the Create Algorithm Context (OPM, QC3CRTAX; ILE, Qc3CreateAlgorithmContext) API.

Final operation flag
The final processing indicator.


Hash algorithm
The hash algorithm. Following are the valid hash algorithms.


Key Description Formats

For detailed descriptions of the table fields, see Key Description Formats Field Descriptions.

KEYD0100 Format

KEYD0200 Format

KEYD0400 Format

KEYD0500 Format



Key Description Formats Field Descriptions

Derived key length
The length of key requested. The minimum allowed length is 1.

Iteration count
Used to greatly increase the cost of an exhaustive search while modestly increasing the cost of key derivation. The minimum allowed value is 1. The standard recommends a minimum of 1000. The maximum allowed length is 100,000.

Key context token
A token for a key context. The key context is created by using the Create Key Context (OPM, QC3CRTKX; ILE, Qc3CreateKeyContext) API.

Key format
The format of the key string field. Following are the valid values.
Key string
The key to use in the HMAC operation.

Key string length
Length of the key string specified in the key string field. Refer to the key type field for more information.

Key type
The type of key. Following are the valid values.

A key longer than the minimum length does not significantly increase the function strength unless the randomness of the key is considered weak. A key longer than 64 bytes for MD5, SHA-1, and SHA-256, or longer the 128 bytes for SHA-384 and SHA-512 will be hashed before it is used.

Passphrase
A text string.

Passphrase CCSID
INPUT; BINARY(4)

The CCSID of the passphrase. The passphrase will be converted from the specified CCSID to Unicode before calling the PKCS5 algorithm.


Passphrase length
The length of passphrase. The length must be in the range of 1 to 256.

Qualified keystore file name
The keystore file where the key is stored. Keystore files are created by using the Create Keystore (OPM, QC3CRTKS; ILE, Qc3CreateKeyStore) API. The first 10 characters contain the file name. The second 10 characters contain the name of the library where the keystore file is located. You can use the following special values for the library name.
Record label
The label of a key record in a keystore file. The label will be converted from the job CCSID, or if 65535, the job default CCSID (DFTCCSID) job attribute to CCSID 1200 (Unicode UTF-16). Key records are created by using the Write Key Record (OPM, QC3WRTKR; ILE, Qc3WriteKeyRecord) API or the Generate Key Record (OPM, QC3GENKR; ILE, Qc3GenKeyRecord) API.

Reserved
Must be null (binary 0s).

Salt
Used to help thwart attacks by producing a large set of keys for each passphrase. The standard recommends the salt be generated at random and be at least 8 bytes long. You can use the Generate Pseudorandom Numbers (OPM, QC3GENPRN; ILE, Qc3GenPRNs) API to obtain a random value. Additionally, data that distinguishes between various operations can be added to the salt for additional security. Refer to the standard for more information.

Salt length
The length of salt. The length must be in the range of 1 to 16.

Error Messages




API introduced: V5R3

[ Back to top | Cryptographic Services APIs | APIs by category ]