13
13
#include "psa_crypto_rsa.h"
14
14
#include "string.h"
15
15
#include "test/drivers/asymmetric_encryption.h"
16
+ #include "test/drivers/key_management.h"
16
17
17
18
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1 )
18
19
#include "libtestdriver1/library/psa_crypto_rsa.h"
19
20
#endif
20
21
22
+ #define PSA_RSA_KEY_PAIR_MAX_SIZE \
23
+ PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS)
24
+
21
25
mbedtls_test_driver_asymmetric_encryption_hooks_t mbedtls_test_driver_asymmetric_encryption_hooks =
22
26
MBEDTLS_TEST_DRIVER_ASYMMETRIC_ENCRYPTION_INIT ;
23
27
@@ -104,25 +108,39 @@ psa_status_t mbedtls_test_transparent_asymmetric_decrypt(
104
108
}
105
109
106
110
/*
107
- * opaque versions - TODO
111
+ * opaque versions
108
112
*/
109
113
psa_status_t mbedtls_test_opaque_asymmetric_encrypt (
110
114
const psa_key_attributes_t * attributes , const uint8_t * key ,
111
115
size_t key_length , psa_algorithm_t alg , const uint8_t * input ,
112
116
size_t input_length , const uint8_t * salt , size_t salt_length ,
113
117
uint8_t * output , size_t output_size , size_t * output_length )
114
118
{
115
- (void ) attributes ;
116
- (void ) key ;
117
- (void ) key_length ;
118
- (void ) alg ;
119
- (void ) input ;
120
- (void ) input_length ;
121
- (void ) salt ;
122
- (void ) salt_length ;
123
- (void ) output ;
124
- (void ) output_size ;
125
- (void ) output_length ;
119
+ unsigned char unwrapped_key [PSA_RSA_KEY_PAIR_MAX_SIZE ];
120
+ size_t unwrapped_key_length ;
121
+ psa_status_t status ;
122
+
123
+ status = mbedtls_test_opaque_unwrap_key (key , key_length ,
124
+ unwrapped_key , sizeof (unwrapped_key ),
125
+ & unwrapped_key_length );
126
+ if (status != PSA_SUCCESS ) {
127
+ return status ;
128
+ }
129
+
130
+ #if defined(MBEDTLS_TEST_LIBTESTDRIVER1 ) && \
131
+ (defined(MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP ) || defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT ))
132
+ return libtestdriver1_mbedtls_psa_asymmetric_encrypt (
133
+ (const libtestdriver1_psa_key_attributes_t * ) attributes ,
134
+ unwrapped_key , unwrapped_key_length ,
135
+ alg , input , input_length , salt , salt_length ,
136
+ output , output_size , output_length );
137
+ #else
138
+ return mbedtls_psa_asymmetric_encrypt (
139
+ attributes , unwrapped_key , unwrapped_key_length ,
140
+ alg , input , input_length , salt , salt_length ,
141
+ output , output_size , output_length );
142
+ #endif
143
+
126
144
return PSA_ERROR_NOT_SUPPORTED ;
127
145
}
128
146
@@ -132,17 +150,31 @@ psa_status_t mbedtls_test_opaque_asymmetric_decrypt(
132
150
size_t input_length , const uint8_t * salt , size_t salt_length ,
133
151
uint8_t * output , size_t output_size , size_t * output_length )
134
152
{
135
- (void ) attributes ;
136
- (void ) key ;
137
- (void ) key_length ;
138
- (void ) alg ;
139
- (void ) input ;
140
- (void ) input_length ;
141
- (void ) salt ;
142
- (void ) salt_length ;
143
- (void ) output ;
144
- (void ) output_size ;
145
- (void ) output_length ;
153
+ unsigned char unwrapped_key [PSA_RSA_KEY_PAIR_MAX_SIZE ];
154
+ size_t unwrapped_key_length ;
155
+ psa_status_t status ;
156
+
157
+ status = mbedtls_test_opaque_unwrap_key (key , key_length ,
158
+ unwrapped_key , sizeof (unwrapped_key ),
159
+ & unwrapped_key_length );
160
+ if (status != PSA_SUCCESS ) {
161
+ return status ;
162
+ }
163
+
164
+ #if defined(MBEDTLS_TEST_LIBTESTDRIVER1 ) && \
165
+ (defined(MBEDTLS_PSA_ACCEL_ALG_RSA_OAEP ) || defined(MBEDTLS_PSA_ACCEL_ALG_RSA_PKCS1V15_CRYPT ))
166
+ return libtestdriver1_mbedtls_psa_asymmetric_decrypt (
167
+ (const libtestdriver1_psa_key_attributes_t * ) attributes ,
168
+ unwrapped_key , unwrapped_key_length ,
169
+ alg , input , input_length , salt , salt_length ,
170
+ output , output_size , output_length );
171
+ #else
172
+ return mbedtls_psa_asymmetric_decrypt (
173
+ attributes , unwrapped_key , unwrapped_key_length ,
174
+ alg , input , input_length , salt , salt_length ,
175
+ output , output_size , output_length );
176
+ #endif
177
+
146
178
return PSA_ERROR_NOT_SUPPORTED ;
147
179
}
148
180
0 commit comments