Calculate Hash (QC3CALHA, Qc3CalculateHash) API
Required Parameter Group:
1 | Input data | Input | Char(*) |
2 | Length of input data | Input | Binary(4) |
3 | Input data format name | Input | Char(8) |
4 | Algorithm description | Input | Char(*) |
5 | Algorithm description format name | Input | Char(8) |
6 | Cryptographic service provider | Input | Char(1) |
7 | Cryptographic device name | Input | Char(10) |
8 | Hash | Output | Char(*) |
9 | Error code | I/O | Char(*) |
Service Program Name: QC3HASH
Default Public Authority: *USE
Threadsafe: Yes
The Calculate Hash (OPM, QC3CALHA; ILE, Qc3CalculateHash) API uses a one-way hash function to produce a fixed-length output string from a variable-length input string. For all practical purposes, one-way hashes are irreversible. This property makes them useful for authentication purposes.
Information on cryptographic standards can be found in Create Algorithm Context (OPM, QC3CRTAX; ILE, Qc3CreateAlgorithmContext) API.
Authorities and Locks
- Required API authority
- *USE
- Required device description authority
- *USE
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 hash 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,
SHA-512).
See Algorithm Description Formats for a description of these formats.
- Cryptographic service provider
- INPUT; CHAR(1)
The cryptographic service provider (CSP) that will perform the hash operation.
0 Any CSP.
The system will choose an appropriate CSP to perform the hash operation.1 Software CSP.
The system will perform the hash operation using software. If the requested algorithm is not available in software, an error is returned.2 Hardware CSP.
The system will perform the hash operation using cryptographic hardware. If the requested algorithm is not available in hardware, an error is returned. A specific cryptographic device can be specified using the cryptographic device name parameter. If the cryptographic device is not specified, the system will choose an appropriate one.
- 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. - Hash
- OUTPUT; CHAR(*)
The area to store the hash. The length of hash is defined by the hash algorithm.
MD5 16 bytes SHA-1 20 bytes SHA-256 32 bytes SHA-384 48 bytes SHA-512 64 bytes
- 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
Offset | Type | Field | |
---|---|---|---|
Dec | Hex | ||
These fields repeat. | PTR(SPP) | Input data pointer | |
BINARY(4) | Input data length | ||
CHAR(12) | Reserved |
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
Offset | Type | Field | |
---|---|---|---|
Dec | Hex | ||
0 | 0 | CHAR(8) | Algorithm context token |
8 | 8 | CHAR(1) | Final operation flag |
ALGD0500 Format
Offset | Type | Field | |
---|---|---|---|
Dec | Hex | ||
0 | 0 | BINARY(4) | Hash algorithm |
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.
- Hash algorithm
- The hash algorithm. Following are the valid hash algorithms.
1 MD5
Documented in RFC 1321.2 SHA-1
Documented in FIPS 180-2.3 SHA-256
Documented in FIPS 180-2.4 SHA-384
Documented in FIPS 180-2.5 SHA-512
Documented in FIPS 180-2.
- Final operation flag
- The final processing indicator.
0 Continue.
The system will not perform final processing and the algorithm context will maintain the state of the operation. The algorithm context can be used on future calls to this API to continue the hash operation. The pointer to the hash parameter may be set to NULL because the hash value will not be returned until the final operation flag is set on.1 Final.
The system will perform final processing. The hash value will be returned and the algorithm context will reset to its initial state. The algorithm context can then be used to begin a new cryptographic operation (hash, HMAC, etc.). When performing a final operation, the pointer to the input data parameter may be set to NULL.
Error Messages
Message ID | Error Message Text |
---|---|
CPF24B4 E | Severe error while addressing parameter list. |
CPF3C1E E | Required parameter &1 omitted. |
CPF3CF1 E | Error code parameter not valid. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
CPF9DC7 E | The output data parameter specifies a NULL pointer. |
CPF9DC8 E | The input data parameter specifies a NULL pointer. |
CPF9DC9 E | The total length of data in the input data array is not valid. |
CPF9DCE E | A data length is not valid. |
CPF9DCF E | A data pointer is not valid. |
CPF9DD1 E | Input data format name not valid. |
CPF9DD2 E | Algorithm description format name not valid. |
CPF9DD5 E | Length of input data not valid. |
CPF9DDA E | Unexpected return code &1. |
CPF9DE0 E | Hash algorithm not valid. |
CPF9DEC E | Cryptographic service provider not valid. |
CPF9DED E | Final operation flag not valid. |
CPF9DEE E | Reserved field not null. |
CPF9DF0 E | Operation, algorithm, or mode not available on the requested CSP (cryptographic service provider). |
CPF9DF1 E | The algorithm context token does not reference a valid algorithm context. |
CPF9DF2 E | The algorithm context is not found or was previously destroyed. |
CPF9DF3 E | Algorithm in algorithm context not valid for requested operation. |
CPF9DF8 E | Cryptographic device name not valid. |
CPF9DF9 E | Cryptographic device not found. |
CPF9DFD E | Not authorized to device. |
CPF9DFE E | Cryptographic device not available. |
API introduced: V5R3
[ Back to top | Cryptographic Services APIs | APIs by category ]