Skip to content

Commit 414fe31

Browse files
author
David Saada
committed
Replace PSA error code definitions with the ones defined in PSA spec
1 parent 2d7e5fe commit 414fe31

File tree

4 files changed

+32
-33
lines changed

4 files changed

+32
-33
lines changed

include/psa/crypto_values.h

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,17 @@
4040
* @{
4141
*/
4242

43-
#if !defined(PSA_SUCCESS)
44-
/* If PSA_SUCCESS is defined, assume that PSA crypto is being used
45-
* together with PSA IPC, which also defines the identifier
46-
* PSA_SUCCESS. We must not define PSA_SUCCESS ourselves in that case;
47-
* the other error code names don't clash. This is a temporary hack
48-
* until we unify error reporting in PSA IPC and PSA crypto.
49-
*
50-
* Note that psa_defs.h must be included before this header!
51-
*/
43+
/* PSA error codes */
44+
5245
/** The action was completed successfully. */
5346
#define PSA_SUCCESS ((psa_status_t)0)
54-
#endif /* !defined(PSA_SUCCESS) */
5547

5648
/** An error occurred that does not correspond to any defined
5749
* failure cause.
5850
*
5951
* Implementations may use this error code if none of the other standard
6052
* error codes are applicable. */
61-
#define PSA_ERROR_UNKNOWN_ERROR ((psa_status_t)1)
53+
#define PSA_ERROR_GENERIC_ERROR ((psa_status_t)-132)
6254

6355
/** The requested operation or a parameter is not supported
6456
* by this implementation.
@@ -67,7 +59,7 @@
6759
* parameter such as a key type, algorithm, etc. is not recognized.
6860
* If a combination of parameters is recognized and identified as
6961
* not valid, return #PSA_ERROR_INVALID_ARGUMENT instead. */
70-
#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)2)
62+
#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)-134)
7163

7264
/** The requested action is denied by a policy.
7365
*
@@ -80,7 +72,7 @@
8072
* not valid or not supported, it is unspecified whether the function
8173
* returns #PSA_ERROR_NOT_PERMITTED, #PSA_ERROR_NOT_SUPPORTED or
8274
* #PSA_ERROR_INVALID_ARGUMENT. */
83-
#define PSA_ERROR_NOT_PERMITTED ((psa_status_t)3)
75+
#define PSA_ERROR_NOT_PERMITTED ((psa_status_t)-133)
8476

8577
/** An output buffer is too small.
8678
*
@@ -92,23 +84,29 @@
9284
* buffer would succeed. However implementations may return this
9385
* error if a function has invalid or unsupported parameters in addition
9486
* to the parameters that determine the necessary output buffer size. */
95-
#define PSA_ERROR_BUFFER_TOO_SMALL ((psa_status_t)4)
87+
#define PSA_ERROR_BUFFER_TOO_SMALL ((psa_status_t)-138)
88+
89+
/** Asking for an item that doesn't exist
90+
*
91+
* Implementations should return this error, if a requested item (like
92+
* a key) does not exist. */
93+
#define PSA_ERROR_DOES_NOT_EXIST ((psa_status_t)-140)
9694

9795
/** A slot is occupied, but must be empty to carry out the
9896
* requested action.
9997
*
10098
* If a handle is invalid, it does not designate an occupied slot.
10199
* The error for an invalid handle is #PSA_ERROR_INVALID_HANDLE.
102100
*/
103-
#define PSA_ERROR_OCCUPIED_SLOT ((psa_status_t)5)
101+
#define PSA_ERROR_OCCUPIED_SLOT ((psa_status_t)-153)
104102

105103
/** A slot is empty, but must be occupied to carry out the
106104
* requested action.
107105
*
108106
* If a handle is invalid, it does not designate an empty slot.
109107
* The error for an invalid handle is #PSA_ERROR_INVALID_HANDLE.
110108
*/
111-
#define PSA_ERROR_EMPTY_SLOT ((psa_status_t)6)
109+
#define PSA_ERROR_EMPTY_SLOT ((psa_status_t)-154)
112110

113111
/** The requested action cannot be performed in the current state.
114112
*
@@ -120,7 +118,7 @@
120118
* that a key slot is occupied when it needs to be free or vice versa,
121119
* but shall return #PSA_ERROR_OCCUPIED_SLOT or #PSA_ERROR_EMPTY_SLOT
122120
* as applicable. */
123-
#define PSA_ERROR_BAD_STATE ((psa_status_t)7)
121+
#define PSA_ERROR_BAD_STATE ((psa_status_t)-137)
124122

125123
/** The parameters passed to the function are invalid.
126124
*
@@ -136,13 +134,13 @@
136134
* key handle is invalid, but shall return #PSA_ERROR_INVALID_HANDLE
137135
* instead.
138136
*/
139-
#define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)8)
137+
#define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)-135)
140138

141139
/** There is not enough runtime memory.
142140
*
143141
* If the action is carried out across multiple security realms, this
144142
* error can refer to available memory in any of the security realms. */
145-
#define PSA_ERROR_INSUFFICIENT_MEMORY ((psa_status_t)9)
143+
#define PSA_ERROR_INSUFFICIENT_MEMORY ((psa_status_t)-141)
146144

147145
/** There is not enough persistent storage.
148146
*
@@ -151,7 +149,7 @@
151149
* many functions that do not otherwise access storage may return this
152150
* error code if the implementation requires a mandatory log entry for
153151
* the requested action and the log storage space is full. */
154-
#define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)10)
152+
#define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)-142)
155153

156154
/** There was a communication failure inside the implementation.
157155
*
@@ -168,7 +166,7 @@
168166
* cryptoprocessor but there was a breakdown of communication before
169167
* the cryptoprocessor could report the status to the application.
170168
*/
171-
#define PSA_ERROR_COMMUNICATION_FAILURE ((psa_status_t)11)
169+
#define PSA_ERROR_COMMUNICATION_FAILURE ((psa_status_t)-145)
172170

173171
/** There was a storage failure that may have led to data loss.
174172
*
@@ -193,13 +191,13 @@
193191
* permanent storage corruption. However application writers should
194192
* keep in mind that transient errors while reading the storage may be
195193
* reported using this error code. */
196-
#define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)12)
194+
#define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)-146)
197195

198196
/** A hardware failure was detected.
199197
*
200198
* A hardware failure may be transient or permanent depending on the
201199
* cause. */
202-
#define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)13)
200+
#define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)-147)
203201

204202
/** A tampering attempt was detected.
205203
*
@@ -230,7 +228,7 @@
230228
* This error indicates an attack against the application. Implementations
231229
* shall not return this error code as a consequence of the behavior of
232230
* the application itself. */
233-
#define PSA_ERROR_TAMPERING_DETECTED ((psa_status_t)14)
231+
#define PSA_ERROR_TAMPERING_DETECTED ((psa_status_t)-151)
234232

235233
/** There is not enough entropy to generate random data needed
236234
* for the requested action.
@@ -249,7 +247,7 @@
249247
* secure pseudorandom generator (PRNG). However implementations may return
250248
* this error at any time if a policy requires the PRNG to be reseeded
251249
* during normal operation. */
252-
#define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)15)
250+
#define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)-148)
253251

254252
/** The signature, MAC or hash is incorrect.
255253
*
@@ -259,7 +257,7 @@
259257
*
260258
* If the value to verify has an invalid size, implementations may return
261259
* either #PSA_ERROR_INVALID_ARGUMENT or #PSA_ERROR_INVALID_SIGNATURE. */
262-
#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)16)
260+
#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149)
263261

264262
/** The decrypted padding is incorrect.
265263
*
@@ -275,17 +273,17 @@
275273
* as close as possible to indistinguishable to an external observer.
276274
* In particular, the timing of a decryption operation should not
277275
* depend on the validity of the padding. */
278-
#define PSA_ERROR_INVALID_PADDING ((psa_status_t)17)
276+
#define PSA_ERROR_INVALID_PADDING ((psa_status_t)-150)
279277

280278
/** The generator has insufficient capacity left.
281279
*
282280
* Once a function returns this error, attempts to read from the
283281
* generator will always return this error. */
284-
#define PSA_ERROR_INSUFFICIENT_CAPACITY ((psa_status_t)18)
282+
#define PSA_ERROR_INSUFFICIENT_CAPACITY ((psa_status_t)-155)
285283

286284
/** The key handle is not valid.
287285
*/
288-
#define PSA_ERROR_INVALID_HANDLE ((psa_status_t)19)
286+
#define PSA_ERROR_INVALID_HANDLE ((psa_status_t)-136)
289287

290288
/**@}*/
291289

library/psa_crypto.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static psa_status_t mbedtls_to_psa_error( int ret )
346346
return( PSA_ERROR_HARDWARE_FAILURE );
347347

348348
default:
349-
return( PSA_ERROR_UNKNOWN_ERROR );
349+
return( PSA_ERROR_GENERIC_ERROR );
350350
}
351351
}
352352

@@ -3098,7 +3098,7 @@ psa_status_t psa_cipher_finish( psa_cipher_operation_t *operation,
30983098
size_t output_size,
30993099
size_t *output_length )
31003100
{
3101-
psa_status_t status = PSA_ERROR_UNKNOWN_ERROR;
3101+
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
31023102
int cipher_ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
31033103
uint8_t temp_output_buffer[MBEDTLS_MAX_BLOCK_LENGTH];
31043104

@@ -4420,7 +4420,7 @@ static psa_status_t its_to_psa_error( psa_its_status_t ret )
44204420
return( PSA_ERROR_OCCUPIED_SLOT );
44214421

44224422
default:
4423-
return( PSA_ERROR_UNKNOWN_ERROR );
4423+
return( PSA_ERROR_GENERIC_ERROR );
44244424
}
44254425
}
44264426

library/psa_crypto_storage_its.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_ITS_C)
2929

30+
#include "psa/error.h"
3031
#include "psa/crypto.h"
3132
#include "psa_crypto_storage_backend.h"
3233
#include "psa/internal_trusted_storage.h"

tests/suites/test_suite_psa_crypto.function

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static psa_status_t key_agreement_with_self( psa_crypto_generator_t *generator,
422422
/* Return UNKNOWN_ERROR if something other than the final call to
423423
* psa_key_agreement fails. This isn't fully satisfactory, but it's
424424
* good enough: callers will report it as a failed test anyway. */
425-
psa_status_t status = PSA_ERROR_UNKNOWN_ERROR;
425+
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
426426

427427
PSA_ASSERT( psa_get_key_information( handle,
428428
&private_key_type,

0 commit comments

Comments
 (0)