hu_AESKeyUnwrap()

Unwraps a ciphertext buffer according to the AES Key Wrap algorithm with the given AES parameters and key objects.

Synopsis:

#include "huaes.h"
 
int hu_AESKeyUnwrap(sb_Params aesParams, sb_Key aesKey, size_t ciphertextLength, const unsigned char *ciphertext, size_t *plaintextLength, unsigned char *plaintext, sb_GlobalCtx sbCtx)

Since:

BlackBerry 10.0.0

Arguments:

aesParams

The AES parameters object.

aesKey

The AES key object.

ciphertextLength

The length (in bytes) of ciphertext.

ciphertext

The ciphertext buffer.

plaintextLength

The length (in bytes) of plaintext.

plaintext

The plaintext buffer.

sbCtx

A global context.

Library:

libhuapi (For the qcc command, use the -l huapi option to link against this library)

Description:

The AES parameters must have been created with SB_AES_KEYWRAP mode. The length of the ciphertext must be a multiple of SB_AES_KEYWRAP_BLOCK_BYTES and at least 3 * SB_AES_KEYWRAP_BLOCK_BYTES. The length of the plaintext will be SB_AES_KEYWRAP_BLOCK_BYTES bytes shorter than the ciphertext length. The ciphertext and plaintext buffers may overlap in memory subject to the constraints described in the API Reference section on overlapping buffers.

If the length of the plaintext is known, a pointer to a buffer large enough to hold the plaintext should be passed in plaintext and its length in plaintextLength. This function will copy the plaintext value into plaintext and set the actual length of the plaintext in plaintextLength.

If plaintext is NULL, then this function will set the correct length of the plaintext value in plaintextLen. If plaintext is not NULL but plaintextLen is too small, this function will return an error and also will set the correct length of the plaintext value in plaintextLen.

Returns:

SB_ERR_NULL_PARAMS

The aesParams object is NULL.

SB_ERR_BAD_PARAMS

The tag for the params object is not of the expected type.

SB_ERR_NULL_KEY

The aesKey object is NULL.

SB_ERR_BAD_KEY

The aesKey object is invalid.

SB_ERR_BAD_MODE

aesParams uses an invalid mode of operation.

SB_ERR_NULL_INPUT_BUF

ciphertext is NULL.

SB_ERR_BAD_INPUT_BUF_LEN

ciphertextLength is incorrect.

SB_ERR_NULL_OUTPUT_BUF_LEN

The plaintextLength pointer is NULL.

SB_ERR_BAD_OUTPUT_BUF_LEN

plaintextLength is invalid.

SB_FAIL_ALLOC

Memory allocation failure.

SB_SUCCESS

Success.