API Reference | developer.brewmp.com API Reference | developer.brewmp.com

Developer

API Reference

IPUBKEY_DECRYPT()

Brew Release
Brew MP 1.0.2
See Also
IPubKey_Encrypt(), IPubKey_SetParam()
Description

Call this method to perform decryption using a private key. The data in the input buffer is decrypted, padding is removed and the result is placed in the output buffer.

Many of the details depend on the algorithm, the implementation, and the cryptographic standard (e.g. RSA using PKCS1). These details are documented with each specific implementation using this interface.

Note that decryption is usually the exact reverse of encryption for a given padding mode and encryption standard, but not always. See implementation documentation.
Params
pif
[]:
Pointer to the IPubKey interface
pucInBuf
[]:
[in] pointer to buffer of data to decrypt
nInBufLen
[]:
[in] length of input buffer
pucOutBuf
[]:
[out] Pointer to buffer to store encrpypted data, caller allocated
pnOutBufLen
[]:
[in/out] Length of output buffer on input, length of data on output
nPadType
[]:
[in] Type of padding to use
pnResult
[]:
[out] Result code
pCB
[]:
[in] Pointer to callback record (called when async operation completes) Return
AEE_SUCCESS
[]:
Decrypt successful
AEESEC_CRYPT_BUFFER_TOO_SMALL
[]:
Output buffer to small
AEESEC_CRYPT_INVALID_KEY
[]:
Private key not set, SetParam not called
AEESEC_CRYPT_INVALID_PADTYPE
[]:
Padding type given was wrong
AEESEC_CRYPT_PAD_ERROR
[]:
After decryption, padding decoding failed (probably means decryption was with wrong key or otherwise failed)
AEESEC_CRYPT_INVALID_SIZE
[]:
nInBufLen is not equal to the modulus size or pucInBuf is bigger than the modulus
AEE_EUNSUPPORTED
[]:
If Decryption is not supported by this implementation
AEE_ENOMEMORY
[]:
Ran out of memory while processing
Other error codes as returned by engine
Interface
Prototype
  •    void IPubKey_Decrypt
       (
          IPubKey *pif,
          const uint8 * pucInBuf,
          int nInBufLen,
          uint8 *pucOutBuf,
          int *pnOutBufLen,
          int nPadType,
          int *pnResult,
          AEECallback *pCB
       )
    
Side Effect
  • None
Comments
The key used to decrypt must have been set before the operation is attempted. It is usually set by calling IPubKey_SetParam(), but it may be pre set in some implementations such as hardware key stores. It is also usually the private key of the key pair. The specific parameter IDs depend on the algorithm and implementation. A typical RSA implementation will require the parameter IDs IPUBKEY_PARAM_RSA_PRIV_EXPONENT and IPUBKEY_PARAM_RSA_MODULUS to be set as they make up the public key. The input data, pucInBuf, must be valid until the operation completes. The data is not copied. The input buffer and output buffer cannot be the same. Decryption is not in place. The nPadType parameter specifies the padding type expected after decryption. The padding is usually removed. The possible padding types depends on the implementation. See the specific implementation documentation. Note that with the RSA algorithm private key operations with some implementations, usually software only, are very slow. Five error codes listed above, AEESEC_CRYPT_BUFFER_TOO_SMALL through AEESEC_CRYPT_INVALID_SIZE, result only from bad input, either a bad key or bad padding or such in the input buffer. Usually these inputs come from external sources like a server. All the other errors are hard errors that result from resource issues like lack of memory or from incorrect calling. If a hard error occurs there is no point in calling IPubKey_Decrypt() again even with a different input as it will fail for the same reason. See the general comments on the IPubkey interface for more details on this error convention.