mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-06-25 12:41:56 +03:00
Add testing for extra calls during a round
Test that extra calls to psa_pake_input() and psa_pake_output() during a round return the correct error. Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
@ -210,6 +210,14 @@ PSA PAKE: inject ERR_INJECT_ROUND2_SERVER_ZK_PROOF
|
|||||||
depends_on:MBEDTLS_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_LEGACY:PSA_WANT_ECC_SECP_R1_256:PSA_WANT_ALG_SHA_256
|
depends_on:MBEDTLS_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_LEGACY:PSA_WANT_ECC_SECP_R1_256:PSA_WANT_ALG_SHA_256
|
||||||
ecjpake_rounds_inject:PSA_ALG_JPAKE:PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, 256):PSA_ALG_SHA_256:0:"abcdef":ERR_INJECT_ROUND2_SERVER_ZK_PROOF:PSA_ERROR_DATA_INVALID
|
ecjpake_rounds_inject:PSA_ALG_JPAKE:PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, 256):PSA_ALG_SHA_256:0:"abcdef":ERR_INJECT_ROUND2_SERVER_ZK_PROOF:PSA_ERROR_DATA_INVALID
|
||||||
|
|
||||||
|
PSA PAKE: inject ERR_INJECT_EXTRA_OUTPUT
|
||||||
|
depends_on:PSA_WANT_KEY_TYPE_ECC_KEY_PAIR:PSA_WANT_ECC_SECP_R1_256:PSA_WANT_ALG_SHA_256
|
||||||
|
ecjpake_rounds_inject:PSA_ALG_JPAKE:PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, 256):PSA_ALG_SHA_256:0:"abcdef":ERR_INJECT_EXTRA_OUTPUT:PSA_ERROR_BAD_STATE
|
||||||
|
|
||||||
|
PSA PAKE: inject ERR_INJECT_EXTRA_INPUT
|
||||||
|
depends_on:PSA_WANT_KEY_TYPE_ECC_KEY_PAIR:PSA_WANT_ECC_SECP_R1_256:PSA_WANT_ALG_SHA_256
|
||||||
|
ecjpake_rounds_inject:PSA_ALG_JPAKE:PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, 256):PSA_ALG_SHA_256:1:"abcdef":ERR_INJECT_EXTRA_INPUT:PSA_ERROR_BAD_STATE
|
||||||
|
|
||||||
PSA PAKE: ecjpake size macros
|
PSA PAKE: ecjpake size macros
|
||||||
depends_on:MBEDTLS_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_LEGACY:PSA_WANT_ECC_SECP_R1_256
|
depends_on:MBEDTLS_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_LEGACY:PSA_WANT_ECC_SECP_R1_256
|
||||||
ecjpake_size_macros:
|
ecjpake_size_macros:
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "psa/crypto.h"
|
#include "psa/crypto.h"
|
||||||
|
#include "psa/crypto_extra.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ERR_NONE = 0,
|
ERR_NONE = 0,
|
||||||
@ -39,6 +40,8 @@ typedef enum {
|
|||||||
ERR_INJECT_ROUND2_SERVER_KEY_SHARE,
|
ERR_INJECT_ROUND2_SERVER_KEY_SHARE,
|
||||||
ERR_INJECT_ROUND2_SERVER_ZK_PUBLIC,
|
ERR_INJECT_ROUND2_SERVER_ZK_PUBLIC,
|
||||||
ERR_INJECT_ROUND2_SERVER_ZK_PROOF,
|
ERR_INJECT_ROUND2_SERVER_ZK_PROOF,
|
||||||
|
ERR_INJECT_EXTRA_OUTPUT,
|
||||||
|
ERR_INJECT_EXTRA_INPUT,
|
||||||
/* erros issued from the .data file */
|
/* erros issued from the .data file */
|
||||||
ERR_IN_SETUP,
|
ERR_IN_SETUP,
|
||||||
ERR_IN_SET_USER,
|
ERR_IN_SET_USER,
|
||||||
@ -69,6 +72,13 @@ static const uint8_t jpake_client_id[] = { 'c', 'l', 'i', 'e', 'n', 't' };
|
|||||||
*(buf + 7) ^= 1; \
|
*(buf + 7) ^= 1; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DO_ROUND_CONDITIONAL_CHECK_FAILURE(this_stage, function) \
|
||||||
|
if (this_stage == err_stage) \
|
||||||
|
{ \
|
||||||
|
TEST_EQUAL(function, expected_error_arg); \
|
||||||
|
break; \
|
||||||
|
}
|
||||||
|
|
||||||
#define DO_ROUND_UPDATE_OFFSETS(main_buf_offset, step_offset, step_size) \
|
#define DO_ROUND_UPDATE_OFFSETS(main_buf_offset, step_offset, step_size) \
|
||||||
{ \
|
{ \
|
||||||
step_offset = main_buf_offset; \
|
step_offset = main_buf_offset; \
|
||||||
@ -185,6 +195,12 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
|
|||||||
buffer0 + buffer0_off);
|
buffer0 + buffer0_off);
|
||||||
DO_ROUND_UPDATE_OFFSETS(buffer0_off, s_x2_pr_off, s_x2_pr_len);
|
DO_ROUND_UPDATE_OFFSETS(buffer0_off, s_x2_pr_off, s_x2_pr_len);
|
||||||
|
|
||||||
|
size_t extra_output_len;
|
||||||
|
DO_ROUND_CONDITIONAL_CHECK_FAILURE(
|
||||||
|
ERR_INJECT_EXTRA_OUTPUT,
|
||||||
|
psa_pake_output(server, PSA_PAKE_STEP_KEY_SHARE,
|
||||||
|
buffer0 + s_g2_off, 512 - s_g2_off, &extra_output_len));
|
||||||
|
(void) extra_output_len;
|
||||||
/*
|
/*
|
||||||
* When injecting errors in inputs, the implementation is
|
* When injecting errors in inputs, the implementation is
|
||||||
* free to detect it right away of with a delay.
|
* free to detect it right away of with a delay.
|
||||||
@ -223,6 +239,12 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
|
|||||||
s_x2_pr_len);
|
s_x2_pr_len);
|
||||||
DO_ROUND_CHECK_FAILURE();
|
DO_ROUND_CHECK_FAILURE();
|
||||||
|
|
||||||
|
/* Note: Must have client_input_first == 1 to inject extra input */
|
||||||
|
DO_ROUND_CONDITIONAL_CHECK_FAILURE(
|
||||||
|
ERR_INJECT_EXTRA_INPUT,
|
||||||
|
psa_pake_input(client, PSA_PAKE_STEP_KEY_SHARE,
|
||||||
|
buffer0 + s_g2_off, s_g2_len));
|
||||||
|
|
||||||
/* Error didn't trigger, make test fail */
|
/* Error didn't trigger, make test fail */
|
||||||
if ((err_stage >= ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART1) &&
|
if ((err_stage >= ERR_INJECT_ROUND1_SERVER_KEY_SHARE_PART1) &&
|
||||||
(err_stage <= ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART2)) {
|
(err_stage <= ERR_INJECT_ROUND1_SERVER_ZK_PROOF_PART2)) {
|
||||||
|
Reference in New Issue
Block a user