Add testing of the MAC driver entry points

Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
Steven Cooreman 2021-04-29 21:10:11 +02:00
parent 939102e7a3
commit c7f0a576b6
7 changed files with 757 additions and 14 deletions

View file

@ -1318,7 +1318,7 @@ psa_status_t psa_driver_wrapper_mac_compute(
* cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
status = mbedtls_transparent_test_driver_mac_compute(
status = mbedtls_test_transparent_mac_compute(
attributes, key_buffer, key_buffer_size, alg,
input, input_length,
mac, mac_size, mac_length );
@ -1342,7 +1342,7 @@ psa_status_t psa_driver_wrapper_mac_compute(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
status = mbedtls_opaque_test_driver_mac_compute(
status = mbedtls_test_opaque_mac_compute(
attributes, key_buffer, key_buffer_size, alg,
input, input_length,
mac, mac_size, mac_length );
@ -1382,7 +1382,7 @@ psa_status_t psa_driver_wrapper_mac_sign_setup(
* cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
status = mbedtls_transparent_test_driver_mac_sign_setup(
status = mbedtls_test_transparent_mac_sign_setup(
&operation->ctx.transparent_test_driver_ctx,
attributes,
key_buffer, key_buffer_size,
@ -1413,7 +1413,7 @@ psa_status_t psa_driver_wrapper_mac_sign_setup(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
status = mbedtls_opaque_test_driver_mac_sign_setup(
status = mbedtls_test_opaque_mac_sign_setup(
&operation->ctx.opaque_test_driver_ctx,
attributes,
key_buffer, key_buffer_size,
@ -1453,7 +1453,7 @@ psa_status_t psa_driver_wrapper_mac_verify_setup(
* cycle through all known transparent accelerators */
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
status = mbedtls_transparent_test_driver_mac_verify_setup(
status = mbedtls_test_transparent_mac_verify_setup(
&operation->ctx.transparent_test_driver_ctx,
attributes,
key_buffer, key_buffer_size,
@ -1484,7 +1484,7 @@ psa_status_t psa_driver_wrapper_mac_verify_setup(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TEST_DRIVER_LOCATION:
status = mbedtls_opaque_test_driver_mac_sign_setup(
status = mbedtls_test_opaque_mac_verify_setup(
&operation->ctx.opaque_test_driver_ctx,
attributes,
key_buffer, key_buffer_size,
@ -1522,12 +1522,12 @@ psa_status_t psa_driver_wrapper_mac_update(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( mbedtls_transparent_test_driver_mac_update(
return( mbedtls_test_transparent_mac_update(
&operation->ctx.transparent_test_driver_ctx,
input, input_length ) );
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
return( mbedtls_opaque_test_driver_mac_update(
return( mbedtls_test_opaque_mac_update(
&operation->ctx.opaque_test_driver_ctx,
input, input_length ) );
#endif /* PSA_CRYPTO_DRIVER_TEST */
@ -1556,12 +1556,12 @@ psa_status_t psa_driver_wrapper_mac_sign_finish(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( mbedtls_transparent_test_driver_mac_sign_finish(
return( mbedtls_test_transparent_mac_sign_finish(
&operation->ctx.transparent_test_driver_ctx,
mac, mac_size, mac_length ) );
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
return( mbedtls_opaque_test_driver_mac_sign_finish(
return( mbedtls_test_opaque_mac_sign_finish(
&operation->ctx.opaque_test_driver_ctx,
mac, mac_size, mac_length ) );
#endif /* PSA_CRYPTO_DRIVER_TEST */
@ -1590,12 +1590,12 @@ psa_status_t psa_driver_wrapper_mac_verify_finish(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( mbedtls_transparent_test_driver_mac_verify_finish(
return( mbedtls_test_transparent_mac_verify_finish(
&operation->ctx.transparent_test_driver_ctx,
mac, mac_length ) );
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
return( mbedtls_opaque_test_driver_mac_verify_finish(
return( mbedtls_test_opaque_mac_verify_finish(
&operation->ctx.opaque_test_driver_ctx,
mac, mac_length ) );
#endif /* PSA_CRYPTO_DRIVER_TEST */
@ -1620,10 +1620,10 @@ psa_status_t psa_driver_wrapper_mac_abort(
#if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
#if defined(PSA_CRYPTO_DRIVER_TEST)
case PSA_CRYPTO_TRANSPARENT_TEST_DRIVER_ID:
return( mbedtls_transparent_test_driver_mac_abort(
return( mbedtls_test_transparent_mac_abort(
&operation->ctx.transparent_test_driver_ctx ) );
case PSA_CRYPTO_OPAQUE_TEST_DRIVER_ID:
return( mbedtls_opaque_test_driver_mac_abort(
return( mbedtls_test_opaque_mac_abort(
&operation->ctx.opaque_test_driver_ctx ) );
#endif /* PSA_CRYPTO_DRIVER_TEST */
#endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */

View file

@ -0,0 +1,140 @@
/*
* Test driver for MAC driver entry points.
*/
/* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PSA_CRYPTO_TEST_DRIVERS_MAC_H
#define PSA_CRYPTO_TEST_DRIVERS_MAC_H
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#if defined(PSA_CRYPTO_DRIVER_TEST)
#include <psa/crypto_driver_common.h>
typedef struct {
/* If not PSA_SUCCESS, return this error code instead of processing the
* function call. */
psa_status_t forced_status;
/* Count the amount of times MAC driver functions are called. */
unsigned long hits;
/* Status returned by the last MAC driver function call. */
psa_status_t driver_status;
} test_driver_mac_hooks_t;
#define MBEDTLS_TEST_DRIVER_MAC_INIT { 0, 0, 0 }
static inline test_driver_mac_hooks_t test_driver_mac_hooks_init( void )
{
const test_driver_mac_hooks_t v = MBEDTLS_TEST_DRIVER_MAC_INIT;
return( v );
}
extern test_driver_mac_hooks_t test_driver_mac_hooks;
psa_status_t mbedtls_test_transparent_mac_compute(
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg,
const uint8_t *input,
size_t input_length,
uint8_t *mac,
size_t mac_size,
size_t *mac_length );
psa_status_t mbedtls_test_transparent_mac_sign_setup(
mbedtls_transparent_test_driver_mac_operation_t *operation,
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg );
psa_status_t mbedtls_test_transparent_mac_verify_setup(
mbedtls_transparent_test_driver_mac_operation_t *operation,
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg );
psa_status_t mbedtls_test_transparent_mac_update(
mbedtls_transparent_test_driver_mac_operation_t *operation,
const uint8_t *input,
size_t input_length );
psa_status_t mbedtls_test_transparent_mac_sign_finish(
mbedtls_transparent_test_driver_mac_operation_t *operation,
uint8_t *mac,
size_t mac_size,
size_t *mac_length );
psa_status_t mbedtls_test_transparent_mac_verify_finish(
mbedtls_transparent_test_driver_mac_operation_t *operation,
const uint8_t *mac,
size_t mac_length );
psa_status_t mbedtls_test_transparent_mac_abort(
mbedtls_transparent_test_driver_mac_operation_t *operation );
psa_status_t mbedtls_test_opaque_mac_compute(
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg,
const uint8_t *input,
size_t input_length,
uint8_t *mac,
size_t mac_size,
size_t *mac_length );
psa_status_t mbedtls_test_opaque_mac_sign_setup(
mbedtls_opaque_test_driver_mac_operation_t *operation,
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg );
psa_status_t mbedtls_test_opaque_mac_verify_setup(
mbedtls_opaque_test_driver_mac_operation_t *operation,
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg );
psa_status_t mbedtls_test_opaque_mac_update(
mbedtls_opaque_test_driver_mac_operation_t *operation,
const uint8_t *input,
size_t input_length );
psa_status_t mbedtls_test_opaque_mac_sign_finish(
mbedtls_opaque_test_driver_mac_operation_t *operation,
uint8_t *mac,
size_t mac_size,
size_t *mac_length );
psa_status_t mbedtls_test_opaque_mac_verify_finish(
mbedtls_opaque_test_driver_mac_operation_t *operation,
const uint8_t *mac,
size_t mac_length );
psa_status_t mbedtls_test_opaque_mac_abort(
mbedtls_opaque_test_driver_mac_operation_t *operation );
#endif /* PSA_CRYPTO_DRIVER_TEST */
#endif /* PSA_CRYPTO_TEST_DRIVERS_MAC_H */

View file

@ -25,6 +25,7 @@
#include "test/drivers/aead.h"
#include "test/drivers/cipher.h"
#include "test/drivers/hash.h"
#include "test/drivers/mac.h"
#include "test/drivers/key_management.h"
#include "test/drivers/signature.h"
#include "test/drivers/size.h"

View file

@ -0,0 +1,361 @@
/*
* Test driver for MAC entry points.
*/
/* Copyright The Mbed TLS Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST)
#include "psa_crypto_mac.h"
#include "test/drivers/mac.h"
test_driver_mac_hooks_t test_driver_mac_hooks = MBEDTLS_TEST_DRIVER_MAC_INIT;
psa_status_t mbedtls_test_transparent_mac_compute(
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg,
const uint8_t *input,
size_t input_length,
uint8_t *mac,
size_t mac_size,
size_t *mac_length )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_compute(
attributes, key_buffer, key_buffer_size, alg,
input, input_length,
mac, mac_size, mac_length );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_sign_setup(
mbedtls_transparent_test_driver_mac_operation_t *operation,
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_sign_setup(
operation, attributes, key_buffer, key_buffer_size, alg );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_verify_setup(
mbedtls_transparent_test_driver_mac_operation_t *operation,
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_verify_setup(
operation, attributes, key_buffer, key_buffer_size, alg );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_update(
mbedtls_transparent_test_driver_mac_operation_t *operation,
const uint8_t *input,
size_t input_length )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_update(
operation, input, input_length );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_sign_finish(
mbedtls_transparent_test_driver_mac_operation_t *operation,
uint8_t *mac,
size_t mac_size,
size_t *mac_length )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_sign_finish(
operation, mac, mac_size, mac_length );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_verify_finish(
mbedtls_transparent_test_driver_mac_operation_t *operation,
const uint8_t *mac,
size_t mac_length )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_verify_finish(
operation, mac, mac_length );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_transparent_mac_abort(
mbedtls_transparent_test_driver_mac_operation_t *operation )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_transparent_test_driver_mac_abort( operation );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_compute(
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg,
const uint8_t *input,
size_t input_length,
uint8_t *mac,
size_t mac_size,
size_t *mac_length )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_compute(
attributes, key_buffer, key_buffer_size, alg,
input, input_length,
mac, mac_size, mac_length );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_sign_setup(
mbedtls_opaque_test_driver_mac_operation_t *operation,
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_sign_setup(
operation, attributes, key_buffer, key_buffer_size, alg );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_verify_setup(
mbedtls_opaque_test_driver_mac_operation_t *operation,
const psa_key_attributes_t *attributes,
const uint8_t *key_buffer,
size_t key_buffer_size,
psa_algorithm_t alg )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_verify_setup(
operation, attributes, key_buffer, key_buffer_size, alg );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_update(
mbedtls_opaque_test_driver_mac_operation_t *operation,
const uint8_t *input,
size_t input_length )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_update(
operation, input, input_length );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_sign_finish(
mbedtls_opaque_test_driver_mac_operation_t *operation,
uint8_t *mac,
size_t mac_size,
size_t *mac_length )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_sign_finish(
operation, mac, mac_size, mac_length );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_verify_finish(
mbedtls_opaque_test_driver_mac_operation_t *operation,
const uint8_t *mac,
size_t mac_length )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_verify_finish(
operation, mac, mac_length );
}
return( test_driver_mac_hooks.driver_status );
}
psa_status_t mbedtls_test_opaque_mac_abort(
mbedtls_opaque_test_driver_mac_operation_t *operation )
{
test_driver_mac_hooks.hits++;
if( test_driver_mac_hooks.forced_status != PSA_SUCCESS )
{
test_driver_mac_hooks.driver_status =
test_driver_mac_hooks.forced_status;
}
else
{
test_driver_mac_hooks.driver_status =
mbedtls_opaque_test_driver_mac_abort( operation );
}
return( test_driver_mac_hooks.driver_status );
}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */

View file

@ -244,6 +244,54 @@ PSA AEAD decrypt, AES-GCM, 144 bytes #1, INSUFFICIENT_MEMORY
depends_on:MBEDTLS_AES_C:MBEDTLS_GCM_C
aead_decrypt:PSA_KEY_TYPE_AES:"a0ec7b0052541d9e9c091fb7fc481409":PSA_ALG_GCM:"00e440846db73a490573deaf3728c94f":"a3cfcb832e935eb5bc3812583b3a1b2e82920c07fda3668a35d939d8f11379bb606d39e6416b2ef336fffb15aec3f47a71e191f4ff6c56ff15913562619765b26ae094713d60bab6ab82bfc36edaaf8c7ce2cf5906554dcc5933acdb9cb42c1d24718efdc4a09256020b024b224cfe602772bd688c6c8f1041a46f7ec7d51208":"3b6de52f6e582d317f904ee768895bd4d0790912efcf27b58651d0eb7eb0b2f07222c6ffe9f7e127d98ccb132025b098a67dc0ec0083235e9f83af1ae1297df4319547cbcb745cebed36abc1f32a059a05ede6c00e0da097521ead901ad6a73be20018bda4c323faa135169e21581e5106ac20853642e9d6b17f1dd925c872814365847fe0b7b7fbed325953df344a96":"5431d93278c35cfcd7ffa9ce2de5c6b922edffd5055a9eaa5b54cae088db007cf2d28efaf9edd1569341889073e87c0a88462d77016744be62132fd14a243ed6e30e12cd2f7d08a8daeec161691f3b27d4996df8745d74402ee208e4055615a8cb069d495cf5146226490ac615d7b17ab39fb4fdd098e4e7ee294d34c1312826":PSA_ERROR_INSUFFICIENT_MEMORY
PSA MAC sign, through driver: HMAC-SHA-224
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_224:PSA_WANT_KEY_TYPE_HMAC
mac_sign:PSA_KEY_TYPE_HMAC:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_ALG_HMAC(PSA_ALG_SHA_224):"4869205468657265":"896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22":PSA_SUCCESS
PSA MAC sign, fallback: HMAC-SHA-224
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_224:PSA_WANT_KEY_TYPE_HMAC
mac_sign:PSA_KEY_TYPE_HMAC:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_ALG_HMAC(PSA_ALG_SHA_224):"4869205468657265":"896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22":PSA_ERROR_NOT_SUPPORTED
PSA MAC sign, driver reports error: RFC4231 Test case 1 - HMAC-SHA-224
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_224:PSA_WANT_KEY_TYPE_HMAC
mac_sign:PSA_KEY_TYPE_HMAC:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_ALG_HMAC(PSA_ALG_SHA_224):"4869205468657265":"896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22":PSA_ERROR_GENERIC_ERROR
PSA MAC sign, through driver: CMAC-AES-128
depends_on:PSA_WANT_ALG_CMAC:PSA_WANT_KEY_TYPE_AES
mac_sign:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":PSA_ALG_CMAC:"6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411":"dfa66747de9ae63030ca32611497c827":PSA_SUCCESS
PSA MAC sign, fallback: CMAC-AES-128
depends_on:PSA_WANT_ALG_CMAC:PSA_WANT_KEY_TYPE_AES
mac_sign:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":PSA_ALG_CMAC:"6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411":"dfa66747de9ae63030ca32611497c827":PSA_ERROR_NOT_SUPPORTED
PSA MAC sign, driver reports error: CMAC-AES-128
depends_on:PSA_WANT_ALG_CMAC:PSA_WANT_KEY_TYPE_AES
mac_sign:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":PSA_ALG_CMAC:"6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411":"dfa66747de9ae63030ca32611497c827":PSA_ERROR_GENERIC_ERROR
PSA MAC verify, through driver: HMAC-SHA-224
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_224:PSA_WANT_KEY_TYPE_HMAC
mac_verify:PSA_KEY_TYPE_HMAC:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_ALG_HMAC(PSA_ALG_SHA_224):"4869205468657265":"896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22":PSA_SUCCESS
PSA MAC verify, fallback: HMAC-SHA-224
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_224:PSA_WANT_KEY_TYPE_HMAC
mac_verify:PSA_KEY_TYPE_HMAC:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_ALG_HMAC(PSA_ALG_SHA_224):"4869205468657265":"896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22":PSA_ERROR_NOT_SUPPORTED
PSA MAC verify, driver reports error: RFC4231 Test case 1 - HMAC-SHA-224
depends_on:PSA_WANT_ALG_HMAC:PSA_WANT_ALG_SHA_224:PSA_WANT_KEY_TYPE_HMAC
mac_verify:PSA_KEY_TYPE_HMAC:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":PSA_ALG_HMAC(PSA_ALG_SHA_224):"4869205468657265":"896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22":PSA_ERROR_GENERIC_ERROR
PSA MAC verify, through driver: CMAC-AES-128
depends_on:PSA_WANT_ALG_CMAC:PSA_WANT_KEY_TYPE_AES
mac_verify:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":PSA_ALG_CMAC:"6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411":"dfa66747de9ae63030ca32611497c827":PSA_SUCCESS
PSA MAC verify, fallback: CMAC-AES-128
depends_on:PSA_WANT_ALG_CMAC:PSA_WANT_KEY_TYPE_AES
mac_verify:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":PSA_ALG_CMAC:"6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411":"dfa66747de9ae63030ca32611497c827":PSA_ERROR_NOT_SUPPORTED
PSA MAC verify, driver reports error: CMAC-AES-128
depends_on:PSA_WANT_ALG_CMAC:PSA_WANT_KEY_TYPE_AES
mac_verify:PSA_KEY_TYPE_AES:"2b7e151628aed2a6abf7158809cf4f3c":PSA_ALG_CMAC:"6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411":"dfa66747de9ae63030ca32611497c827":PSA_ERROR_GENERIC_ERROR
PSA opaque driver builtin key export: AES
builtin_key_export:MBEDTLS_PSA_KEY_ID_BUILTIN_MIN:PSA_KEY_TYPE_AES:128:PSA_ALG_CTR:"3677397A24432646294A404E63526655":PSA_SUCCESS

View file

@ -963,6 +963,197 @@ exit:
}
/* END_CASE */
/* BEGIN_CASE */
void mac_sign( int key_type_arg,
data_t *key_data,
int alg_arg,
data_t *input,
data_t *expected_mac,
int forced_status_arg )
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t *actual_mac = NULL;
size_t mac_buffer_size =
PSA_MAC_LENGTH( key_type, PSA_BYTES_TO_BITS( key_data->len ), alg );
size_t mac_length = 0;
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
psa_status_t forced_status = forced_status_arg;
test_driver_mac_hooks = test_driver_mac_hooks_init();
TEST_ASSERT( mac_buffer_size <= PSA_MAC_MAX_SIZE );
/* We expect PSA_MAC_LENGTH to be exact. */
TEST_ASSERT( expected_mac->len == mac_buffer_size );
PSA_ASSERT( psa_crypto_init( ) );
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
psa_set_key_algorithm( &attributes, alg );
psa_set_key_type( &attributes, key_type );
PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
&key ) );
ASSERT_ALLOC( actual_mac, mac_buffer_size );
test_driver_mac_hooks.forced_status = forced_status;
/* Calculate the MAC. */
status = psa_mac_sign_setup( &operation, key, alg );
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
{
PSA_ASSERT( status );
}
else
TEST_EQUAL( forced_status, status );
status = psa_mac_update( &operation,
input->x, input->len );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 2 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
{
PSA_ASSERT( status );
}
else
TEST_EQUAL( PSA_ERROR_BAD_STATE, status );
status = psa_mac_sign_finish( &operation,
actual_mac, mac_buffer_size,
&mac_length );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 4 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
{
PSA_ASSERT( status );
}
else
TEST_EQUAL( PSA_ERROR_BAD_STATE, status );
PSA_ASSERT( psa_mac_abort( &operation ) );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 4 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS )
{
ASSERT_COMPARE( expected_mac->x, expected_mac->len,
actual_mac, mac_length );
}
mbedtls_free( actual_mac );
actual_mac = NULL;
exit:
psa_mac_abort( &operation );
psa_destroy_key( key );
PSA_DONE( );
mbedtls_free( actual_mac );
test_driver_mac_hooks = test_driver_mac_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE */
void mac_verify( int key_type_arg,
data_t *key_data,
int alg_arg,
data_t *input,
data_t *expected_mac,
int forced_status_arg )
{
mbedtls_svc_key_id_t key = MBEDTLS_SVC_KEY_ID_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
psa_status_t forced_status = forced_status_arg;
test_driver_mac_hooks = test_driver_mac_hooks_init();
TEST_ASSERT( expected_mac->len <= PSA_MAC_MAX_SIZE );
PSA_ASSERT( psa_crypto_init( ) );
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
psa_set_key_algorithm( &attributes, alg );
psa_set_key_type( &attributes, key_type );
PSA_ASSERT( psa_import_key( &attributes, key_data->x, key_data->len,
&key ) );
test_driver_mac_hooks.forced_status = forced_status;
/* Test the correct MAC. */
status = psa_mac_verify_setup( &operation, key, alg );
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
{
PSA_ASSERT( status );
}
else
TEST_EQUAL( forced_status, status );
status = psa_mac_update( &operation,
input->x, input->len );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 2 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
{
PSA_ASSERT( status );
}
else
TEST_EQUAL( PSA_ERROR_BAD_STATE, status );
status = psa_mac_verify_finish( &operation,
expected_mac->x,
expected_mac->len );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 4 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
if( forced_status == PSA_SUCCESS ||
forced_status == PSA_ERROR_NOT_SUPPORTED )
{
PSA_ASSERT( status );
}
else
TEST_EQUAL( PSA_ERROR_BAD_STATE, status );
PSA_ASSERT( psa_mac_abort( &operation ) );
if( forced_status == PSA_SUCCESS )
TEST_EQUAL( test_driver_mac_hooks.hits, 4 );
else
TEST_EQUAL( test_driver_mac_hooks.hits, 1 );
exit:
psa_mac_abort( &operation );
psa_destroy_key( key );
PSA_DONE( );
test_driver_mac_hooks = test_driver_mac_hooks_init();
}
/* END_CASE */
/* BEGIN_CASE depends_on:PSA_CRYPTO_DRIVER_TEST:MBEDTLS_PSA_CRYPTO_DRIVERS:MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS */
void builtin_key_export( int builtin_key_id_arg,
int builtin_key_type_arg,

View file

@ -236,6 +236,7 @@
<ClInclude Include="..\..\tests\include\test\drivers\cipher.h" />
<ClInclude Include="..\..\tests\include\test\drivers\hash.h" />
<ClInclude Include="..\..\tests\include\test\drivers\key_management.h" />
<ClInclude Include="..\..\tests\include\test\drivers\mac.h" />
<ClInclude Include="..\..\tests\include\test\drivers\signature.h" />
<ClInclude Include="..\..\tests\include\test\drivers\size.h" />
<ClInclude Include="..\..\tests\include\test\drivers\test_driver.h" />
@ -384,6 +385,7 @@
<ClCompile Include="..\..\tests\src\drivers\test_driver_aead.c" />
<ClCompile Include="..\..\tests\src\drivers\test_driver_cipher.c" />
<ClCompile Include="..\..\tests\src\drivers\test_driver_key_management.c" />
<ClCompile Include="..\..\tests\src\drivers\test_driver_mac.c" />
<ClCompile Include="..\..\tests\src\drivers\test_driver_signature.c" />
<ClCompile Include="..\..\tests\src\drivers\test_driver_size.c" />
<ClCompile Include="..\..\3rdparty\everest\library\everest.c" />