hu_AESKeyWrap()

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

Synopsis:

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

Since:

BlackBerry 10.0.0

Arguments:

aesParams

The AES parameters object.

aesKey

The AES key object.

plaintextLength

The length (in bytes) of plaintext.

plaintext

Plaintext buffer.

ciphertextLength

The length (in bytes) of ciphertext.

ciphertext

The ciphertext 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 plaintext must be a multiple of SB_AES_KEYWRAP_BLOCK_BYTES and at least 2 * SB_AES_KEYWRAP_BLOCK_BYTES. The length of the ciphertext will be SB_AES_KEYWRAP_BLOCK_BYTES bytes longer than the plaintext length. The plaintext and ciphertext buffers may overlap in memory subject to the constraints described in the API Reference section on overlapping buffers.

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

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

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

The plaintext buffer is NULL.

SB_ERR_BAD_INPUT_BUF_LEN

plaintextLength is incorrect.

SB_ERR_NULL_OUTPUT_BUF_LEN

The ciphertextLength pointer is NULL.

SB_ERR_BAD_OUTPUT_BUF_LEN

ciphertextLength is invalid.

SB_FAIL_ALLOC

Memory allocation failure.

SB_SUCCESS

Success.