PSA Crypto error code definitions

Removed the psa_status_t enum and defined error codes as defines.
Conditionally defining PSA_SUCCESS and psa_status_t.
This commit is contained in:
itayzafrir 2018-06-18 16:20:16 +03:00
parent 781afb4b07
commit c2a7976886

View file

@ -50,212 +50,232 @@ extern "C" {
* *
* Zero indicates success, anything else indicates an error. * Zero indicates success, anything else indicates an error.
*/ */
typedef enum { #if defined(PSA_SUCCESS)
/** The action was completed successfully. */ typedef psa_error_t psa_status_t;
PSA_SUCCESS = 0, #else
/** The requested operation or a parameter is not supported typedef int32_t psa_status_t;
* by this implementation. /** The action was completed successfully. */
* #define PSA_SUCCESS ((psa_status_t)0)
* Implementations should return this error code when an enumeration #endif // PSA_SUCCESS
* parameter such as a key type, algorithm, etc. is not recognized.
* If a combination of parameters is recognized and identified as /** The requested operation or a parameter is not supported
* not valid, return #PSA_ERROR_INVALID_ARGUMENT instead. */ * by this implementation.
PSA_ERROR_NOT_SUPPORTED, *
/** The requested action is denied by a policy. * Implementations should return this error code when an enumeration
* * parameter such as a key type, algorithm, etc. is not recognized.
* Implementations should return this error code when the parameters * If a combination of parameters is recognized and identified as
* are recognized as valid and supported, and a policy explicitly * not valid, return #PSA_ERROR_INVALID_ARGUMENT instead. */
* denies the requested operation. #define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)1)
*
* If a subset of the parameters of a function call identify a /** The requested action is denied by a policy.
* forbidden operation, and another subset of the parameters are *
* not valid or not supported, it is unspecified whether the function * Implementations should return this error code when the parameters
* returns #PSA_ERROR_NOT_PERMITTED, #PSA_ERROR_NOT_SUPPORTED or * are recognized as valid and supported, and a policy explicitly
* #PSA_ERROR_INVALID_ARGUMENT. */ * denies the requested operation.
PSA_ERROR_NOT_PERMITTED, *
/** An output buffer is too small. * If a subset of the parameters of a function call identify a
* * forbidden operation, and another subset of the parameters are
* Applications can call the `PSA_xxx_SIZE` macro listed in the function * not valid or not supported, it is unspecified whether the function
* description to determine a sufficient buffer size. * returns #PSA_ERROR_NOT_PERMITTED, #PSA_ERROR_NOT_SUPPORTED or
* * #PSA_ERROR_INVALID_ARGUMENT. */
* Implementations should preferably return this error code only #define PSA_ERROR_NOT_PERMITTED ((psa_status_t)2)
* in cases when performing the operation with a larger output
* buffer would succeed. However implementations may return this /** An output buffer is too small.
* error if a function has invalid or unsupported parameters in addition *
* to the parameters that determine the necessary output buffer size. */ * Applications can call the `PSA_xxx_SIZE` macro listed in the function
PSA_ERROR_BUFFER_TOO_SMALL, * description to determine a sufficient buffer size.
/** A slot is occupied, but must be empty to carry out the *
* requested action. * Implementations should preferably return this error code only
* * in cases when performing the operation with a larger output
* If the slot number is invalid (i.e. the requested action could * buffer would succeed. However implementations may return this
* not be performed even after erasing the slot's content), * error if a function has invalid or unsupported parameters in addition
* implementations shall return #PSA_ERROR_INVALID_ARGUMENT instead. */ * to the parameters that determine the necessary output buffer size. */
PSA_ERROR_OCCUPIED_SLOT, #define PSA_ERROR_BUFFER_TOO_SMALL ((psa_status_t)3)
/** A slot is empty, but must be occupied to carry out the
* requested action. /** A slot is occupied, but must be empty to carry out the
* * requested action.
* If the slot number is invalid (i.e. the requested action could *
* not be performed even after creating appropriate content in the slot), * If the slot number is invalid (i.e. the requested action could
* implementations shall return #PSA_ERROR_INVALID_ARGUMENT instead. */ * not be performed even after erasing the slot's content),
PSA_ERROR_EMPTY_SLOT, * implementations shall return #PSA_ERROR_INVALID_ARGUMENT instead. */
/** The requested action cannot be performed in the current state. #define PSA_ERROR_OCCUPIED_SLOT ((psa_status_t)4)
*
* Multipart operations return this error when one of the /** A slot is empty, but must be occupied to carry out the
* functions is called out of sequence. Refer to the function * requested action.
* descriptions for permitted sequencing of functions. *
* * If the slot number is invalid (i.e. the requested action could
* Implementations shall not return this error code to indicate * not be performed even after creating appropriate content in the slot),
* that a key slot is occupied when it needs to be free or vice versa, * implementations shall return #PSA_ERROR_INVALID_ARGUMENT instead. */
* but shall return #PSA_ERROR_OCCUPIED_SLOT or #PSA_ERROR_EMPTY_SLOT #define PSA_ERROR_EMPTY_SLOT ((psa_status_t)5)
* as applicable. */
PSA_ERROR_BAD_STATE, /** The requested action cannot be performed in the current state.
/** The parameters passed to the function are invalid. *
* * Multipart operations return this error when one of the
* Implementations may return this error any time a parameter or * functions is called out of sequence. Refer to the function
* combination of parameters are recognized as invalid. * descriptions for permitted sequencing of functions.
* *
* Implementations shall not return this error code to indicate * Implementations shall not return this error code to indicate
* that a key slot is occupied when it needs to be free or vice versa, * that a key slot is occupied when it needs to be free or vice versa,
* but shall return #PSA_ERROR_OCCUPIED_SLOT or #PSA_ERROR_EMPTY_SLOT * but shall return #PSA_ERROR_OCCUPIED_SLOT or #PSA_ERROR_EMPTY_SLOT
* as applicable. */ * as applicable. */
PSA_ERROR_INVALID_ARGUMENT, #define PSA_ERROR_BAD_STATE ((psa_status_t)6)
/** There is not enough runtime memory.
* /** The parameters passed to the function are invalid.
* If the action is carried out across multiple security realms, this *
* error can refer to available memory in any of the security realms. */ * Implementations may return this error any time a parameter or
PSA_ERROR_INSUFFICIENT_MEMORY, * combination of parameters are recognized as invalid.
/** There is not enough persistent storage. *
* * Implementations shall not return this error code to indicate
* Functions that modify the key storage return this error code if * that a key slot is occupied when it needs to be free or vice versa,
* there is insufficient storage space on the host media. In addition, * but shall return #PSA_ERROR_OCCUPIED_SLOT or #PSA_ERROR_EMPTY_SLOT
* many functions that do not otherwise access storage may return this * as applicable. */
* error code if the implementation requires a mandatory log entry for #define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)7)
* the requested action and the log storage space is full. */
PSA_ERROR_INSUFFICIENT_STORAGE, /** There is not enough runtime memory.
/** There was a communication failure inside the implementation. *
* * If the action is carried out across multiple security realms, this
* This can indicate a communication failure between the application * error can refer to available memory in any of the security realms. */
* and an external cryptoprocessor or between the cryptoprocessor and #define PSA_ERROR_INSUFFICIENT_MEMORY ((psa_status_t)8)
* an external volatile or persistent memory. A communication failure
* may be transient or permanent depending on the cause. /** There is not enough persistent storage.
* *
* \warning If a function returns this error, it is undetermined * Functions that modify the key storage return this error code if
* whether the requested action has completed or not. Implementations * there is insufficient storage space on the host media. In addition,
* should return #PSA_SUCCESS on successful completion whenver * many functions that do not otherwise access storage may return this
* possible, however functions may return #PSA_ERROR_COMMUNICATION_FAILURE * error code if the implementation requires a mandatory log entry for
* if the requested action was completed successfully in an external * the requested action and the log storage space is full. */
* cryptoprocessor but there was a breakdown of communication before #define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)9)
* the cryptoprocessor could report the status to the application.
*/ /** There was a communication failure inside the implementation.
PSA_ERROR_COMMUNICATION_FAILURE, *
/** There was a storage failure that may have led to data loss. * This can indicate a communication failure between the application
* * and an external cryptoprocessor or between the cryptoprocessor and
* This error indicates that some persistent storage is corrupted. * an external volatile or persistent memory. A communication failure
* It should not be used for a corruption of volatile memory * may be transient or permanent depending on the cause.
* (use #PSA_ERROR_TAMPERING_DETECTED), for a communication error *
* between the cryptoprocessor and its external storage (use * \warning If a function returns this error, it is undetermined
* #PSA_ERROR_COMMUNICATION_FAILURE), or when the storage is * whether the requested action has completed or not. Implementations
* in a valid state but is full (use #PSA_ERROR_INSUFFICIENT_STORAGE). * should return #PSA_SUCCESS on successful completion whenver
* * possible, however functions may return #PSA_ERROR_COMMUNICATION_FAILURE
* Note that a storage failure does not indicate that any data that was * if the requested action was completed successfully in an external
* previously read is invalid. However this previously read data may no * cryptoprocessor but there was a breakdown of communication before
* longer be readable from storage. * the cryptoprocessor could report the status to the application.
* */
* When a storage failure occurs, it is no longer possible to ensure #define PSA_ERROR_COMMUNICATION_FAILURE ((psa_status_t)10)
* the global integrity of the keystore. Depending on the global
* integrity guarantees offered by the implementation, access to other /** There was a storage failure that may have led to data loss.
* data may or may not fail even if the data is still readable but *
* its integrity canont be guaranteed. * This error indicates that some persistent storage is corrupted.
* * It should not be used for a corruption of volatile memory
* Implementations should only use this error code to report a * (use #PSA_ERROR_TAMPERING_DETECTED), for a communication error
* permanent storage corruption. However application writers should * between the cryptoprocessor and its external storage (use
* keep in mind that transient errors while reading the storage may be * #PSA_ERROR_COMMUNICATION_FAILURE), or when the storage is
* reported using this error code. */ * in a valid state but is full (use #PSA_ERROR_INSUFFICIENT_STORAGE).
PSA_ERROR_STORAGE_FAILURE, *
/** A hardware failure was detected. * Note that a storage failure does not indicate that any data that was
* * previously read is invalid. However this previously read data may no
* A hardware failure may be transient or permanent depending on the * longer be readable from storage.
* cause. */ *
PSA_ERROR_HARDWARE_FAILURE, * When a storage failure occurs, it is no longer possible to ensure
/** A tampering attempt was detected. * the global integrity of the keystore. Depending on the global
* * integrity guarantees offered by the implementation, access to other
* If an application receives this error code, there is no guarantee * data may or may not fail even if the data is still readable but
* that previously accessed or computed data was correct and remains * its integrity canont be guaranteed.
* confidential. Applications should not perform any security function *
* and should enter a safe failure state. * Implementations should only use this error code to report a
* * permanent storage corruption. However application writers should
* Implementations may return this error code if they detect an invalid * keep in mind that transient errors while reading the storage may be
* state that cannot happen during normal operation and that indicates * reported using this error code. */
* that the implementation's security guarantees no longer hold. Depending #define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)11)
* on the implementation architecture and on its security and safety goals,
* the implementation may forcibly terminate the application. /** A hardware failure was detected.
* *
* This error code is intended as a last resort when a security breach * A hardware failure may be transient or permanent depending on the
* is detected and it is unsure whether the keystore data is still * cause. */
* protected. Implementations shall only return this error code #define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)12)
* to report an alarm from a tampering detector, to indicate that
* the confidentiality of stored data can no longer be guaranteed, /** A tampering attempt was detected.
* or to indicate that the integrity of previously returned data is now *
* considered compromised. Implementations shall not use this error code * If an application receives this error code, there is no guarantee
* to indicate a hardware failure that merely makes it impossible to * that previously accessed or computed data was correct and remains
* perform the requested operation (use #PSA_ERROR_COMMUNICATION_FAILURE, * confidential. Applications should not perform any security function
* #PSA_ERROR_STORAGE_FAILURE, #PSA_ERROR_HARDWARE_FAILURE, * and should enter a safe failure state.
* #PSA_ERROR_INSUFFICIENT_ENTROPY or other applicable error code *
* instead). * Implementations may return this error code if they detect an invalid
* * state that cannot happen during normal operation and that indicates
* This error indicates an attack against the application. Implementations * that the implementation's security guarantees no longer hold. Depending
* shall not return this error code as a consequence of the behavior of * on the implementation architecture and on its security and safety goals,
* the application itself. */ * the implementation may forcibly terminate the application.
PSA_ERROR_TAMPERING_DETECTED, *
/** There is not enough entropy to generate random data needed * This error code is intended as a last resort when a security breach
* for the requested action. * is detected and it is unsure whether the keystore data is still
* * protected. Implementations shall only return this error code
* This error indicates a failure of a hardware random generator. * to report an alarm from a tampering detector, to indicate that
* Application writers should note that this error can be returned not * the confidentiality of stored data can no longer be guaranteed,
* only by functions whose purpose is to generate random data, such * or to indicate that the integrity of previously returned data is now
* as key, IV or nonce generation, but also by functions that execute * considered compromised. Implementations shall not use this error code
* an algorithm with a randomized result, as well as functions that * to indicate a hardware failure that merely makes it impossible to
* use randomization of intermediate computations as a countermeasure * perform the requested operation (use #PSA_ERROR_COMMUNICATION_FAILURE,
* to certain attacks. * #PSA_ERROR_STORAGE_FAILURE, #PSA_ERROR_HARDWARE_FAILURE,
* * #PSA_ERROR_INSUFFICIENT_ENTROPY or other applicable error code
* Implementations should avoid returning this error after psa_crypto_init() * instead).
* has succeeded. Implementations should generate sufficient *
* entropy during initialization and subsequently use a cryptographically * This error indicates an attack against the application. Implementations
* secure pseudorandom generator (PRNG). However implementations may return * shall not return this error code as a consequence of the behavior of
* this error at any time if a policy requires the PRNG to be reseeded * the application itself. */
* during normal operation. */ #define PSA_ERROR_TAMPERING_DETECTED ((psa_status_t)13)
PSA_ERROR_INSUFFICIENT_ENTROPY,
/** The signature, MAC or hash is incorrect. /** There is not enough entropy to generate random data needed
* * for the requested action.
* Verification functions return this error if the verification *
* calculations completed successfully, and the value to be verified * This error indicates a failure of a hardware random generator.
* was determined to be incorrect. * Application writers should note that this error can be returned not
* * only by functions whose purpose is to generate random data, such
* If the value to verify has an invalid size, implementations may return * as key, IV or nonce generation, but also by functions that execute
* either #PSA_ERROR_INVALID_ARGUMENT or #PSA_ERROR_INVALID_SIGNATURE. */ * an algorithm with a randomized result, as well as functions that
PSA_ERROR_INVALID_SIGNATURE, * use randomization of intermediate computations as a countermeasure
/** The decrypted padding is incorrect. * to certain attacks.
* *
* \warning In some protocols, when decrypting data, it is essential that * Implementations should avoid returning this error after psa_crypto_init()
* the behavior of the application does not depend on whether the padding * has succeeded. Implementations should generate sufficient
* is correct, down to precise timing. Applications should prefer * entropy during initialization and subsequently use a cryptographically
* protocols that use authenticated encryption rather than plain * secure pseudorandom generator (PRNG). However implementations may return
* encryption. If the application must perform a decryption of * this error at any time if a policy requires the PRNG to be reseeded
* unauthenticated data, the application writer should take care not * during normal operation. */
* to reveal whether the padding is invalid. #define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)14)
*
* Implementations should strive to make valid and invalid padding /** The signature, MAC or hash is incorrect.
* as close as possible to indistinguishable to an external observer. *
* In particular, the timing of a decryption operation should not * Verification functions return this error if the verification
* depend on the validity of the padding. */ * calculations completed successfully, and the value to be verified
PSA_ERROR_INVALID_PADDING, * was determined to be incorrect.
/** An error occurred that does not correspond to any defined *
* failure cause. * If the value to verify has an invalid size, implementations may return
* * either #PSA_ERROR_INVALID_ARGUMENT or #PSA_ERROR_INVALID_SIGNATURE. */
* Implementations may use this error code if none of the other standard #define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)15)
* error codes are applicable. */
PSA_ERROR_UNKNOWN_ERROR, /** The decrypted padding is incorrect.
} psa_status_t; *
* \warning In some protocols, when decrypting data, it is essential that
* the behavior of the application does not depend on whether the padding
* is correct, down to precise timing. Applications should prefer
* protocols that use authenticated encryption rather than plain
* encryption. If the application must perform a decryption of
* unauthenticated data, the application writer should take care not
* to reveal whether the padding is invalid.
*
* Implementations should strive to make valid and invalid padding
* as close as possible to indistinguishable to an external observer.
* In particular, the timing of a decryption operation should not
* depend on the validity of the padding. */
#define PSA_ERROR_INVALID_PADDING ((psa_status_t)16)
/** An error occurred that does not correspond to any defined
* failure cause.
*
* Implementations may use this error code if none of the other standard
* error codes are applicable. */
#define PSA_ERROR_UNKNOWN_ERROR ((psa_status_t)17)
/** /**
* \brief Library initialization. * \brief Library initialization.