Skip to content

Commit

Permalink
validation: crypto: test ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP
Browse files Browse the repository at this point in the history
Test session created with the ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP operation
type with both basic and out-of-place operatons.

Signed-off-by: Janne Peltonen <janne.peltonen@nokia.com>
  • Loading branch information
JannePeltonen committed Oct 9, 2023
1 parent 70aed79 commit cdbc7d0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
22 changes: 12 additions & 10 deletions test/validation/api/crypto/crypto_op_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ int crypto_op(odp_packet_t pkt_in,
odp_packet_t *pkt_out,
odp_bool_t *ok,
const odp_crypto_packet_op_param_t *op_params,
odp_crypto_op_type_t session_op_type,
odp_crypto_op_type_t op_type)
{
int rc;
Expand All @@ -69,7 +70,7 @@ int crypto_op(odp_packet_t pkt_in,
} else {
odp_packet_t *out_param = pkt_out;

if (op_type == ODP_CRYPTO_OP_TYPE_BASIC)
if (session_op_type == ODP_CRYPTO_OP_TYPE_BASIC)
out_param = NULL;

rc = odp_crypto_op_enq(&pkt_in, out_param, op_params, 1);
Expand Down Expand Up @@ -337,7 +338,7 @@ static void prepare_ignore_info(const crypto_op_test_param_t *param,
param->session.op == ODP_CRYPTO_OP_DECODE) {
uint32_t offs = param->digest_offset;

if (param->session.op_type != ODP_CRYPTO_OP_TYPE_OOP ||
if (param->op_type != ODP_CRYPTO_OP_TYPE_OOP ||
is_in_range(offs, cipher_offset, cipher_len) ||
is_in_range(offs, auth_offset, auth_len)) {
add_ignored_range(ignore,
Expand All @@ -351,7 +352,7 @@ static void prepare_ignore_info(const crypto_op_test_param_t *param,
param->wrong_digest) {
add_ignored_range(ignore, cipher_offset + shift, cipher_len);
/* In OOP case, auth range may not get copied */
if (param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP)
if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP)
add_ignored_range(ignore, auth_offset + shift, auth_len);
}
}
Expand All @@ -368,9 +369,9 @@ static void prepare_expected_data(const crypto_op_test_param_t *param,
uint32_t cipher_len = cipher_range->length;
uint32_t auth_offset = auth_range->offset;
uint32_t auth_len = auth_range->length;
const int32_t shift = param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP ? param->oop_shift
const int32_t shift = param->op_type == ODP_CRYPTO_OP_TYPE_OOP ? param->oop_shift
: 0;
const odp_packet_t base_pkt = param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP ? pkt_out
const odp_packet_t base_pkt = param->op_type == ODP_CRYPTO_OP_TYPE_OOP ? pkt_out
: pkt_in;
int rc;
uint32_t cipher_offset_in_ref = param->cipher_range.offset;
Expand Down Expand Up @@ -400,7 +401,7 @@ static void prepare_expected_data(const crypto_op_test_param_t *param,
rc = odp_packet_copy_to_mem(base_pkt, 0, ex->len, ex->data);
CU_ASSERT(rc == 0);

if (param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP && auth_len > 0) {
if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP && auth_len > 0) {
/* copy auth range from input packet */
rc = odp_packet_copy_to_mem(pkt_in, auth_offset, auth_len,
ex->data + auth_offset + shift);
Expand Down Expand Up @@ -516,7 +517,7 @@ static void do_test_crypto_op(const crypto_op_test_param_t *param)
if (prepare_input_packet(param, &pkt))
return;

if (param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP) {
if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP) {
prepare_oop_output_packet(param, &pkt_out, odp_packet_len(pkt));

pkt_copy = odp_packet_copy(pkt, suite_context.pool);
Expand All @@ -535,7 +536,7 @@ static void do_test_crypto_op(const crypto_op_test_param_t *param)
prepare_expected_data(param, &op_params.cipher_range, &op_params.auth_range,
pkt, pkt_out, &expected);

if (param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP &&
if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP &&
param->session.op == ODP_CRYPTO_OP_ENCODE) {
/*
* In this type of sessions digest offset is an offset to the output
Expand All @@ -547,12 +548,13 @@ static void do_test_crypto_op(const crypto_op_test_param_t *param)
test_packet_set_md(pkt);
test_packet_get_md(pkt, &md_in);

if (crypto_op(pkt, &pkt_out, &ok, &op_params, param->session.op_type))
if (crypto_op(pkt, &pkt_out, &ok, &op_params,
param->session.op_type, param->op_type))
return;

test_packet_get_md(pkt_out, &md_out);

if (param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP) {
if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP) {
test_packet_md_t md;

/* check that input packet has not changed */
Expand Down
2 changes: 2 additions & 0 deletions test/validation/api/crypto/crypto_op_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct crypto_session_t {

typedef struct crypto_op_test_param_t {
crypto_session_t session;
odp_crypto_op_type_t op_type;
int32_t oop_shift;
crypto_test_reference_t *ref;
odp_packet_data_range_t cipher_range;
Expand All @@ -42,6 +43,7 @@ int crypto_op(odp_packet_t pkt_in,
odp_packet_t *pkt_out,
odp_bool_t *ok,
const odp_crypto_packet_op_param_t *op_params,
odp_crypto_op_type_t session_op_type,
odp_crypto_op_type_t op_type);

#endif
38 changes: 30 additions & 8 deletions test/validation/api/crypto/odp_crypto_test_inp.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ static void print_alg_test_param(const crypto_op_test_param_t *p)
case ODP_CRYPTO_OP_TYPE_OOP:
printf("out-of-place ");
break;
case ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP:
printf("basic-and-out-of-place (%s)",
p->op_type == ODP_CRYPTO_OP_TYPE_BASIC ? "basic" : "oop");
break;
default:
printf("unknown (internal error) ");
break;
Expand All @@ -94,7 +98,7 @@ static void print_alg_test_param(const crypto_op_test_param_t *p)
printf("header length: %d, trailer length: %d\n", p->header_len, p->trailer_len);
if (p->adjust_segmentation)
printf("segmentation adjusted, first_seg_len: %d\n", p->first_seg_len);
if (p->session.op_type == ODP_CRYPTO_OP_TYPE_OOP)
if (p->op_type == ODP_CRYPTO_OP_TYPE_OOP)
printf("oop_shift: %d\n", p->oop_shift);
if (p->session.null_crypto_enable)
printf("null crypto enabled in session\n");
Expand All @@ -121,13 +125,13 @@ static void alg_test_execute_and_print(crypto_op_test_param_t *param)
}
}

static void alg_test_op(crypto_op_test_param_t *param)
static void alg_test_op2(crypto_op_test_param_t *param)
{
int32_t oop_shifts[] = {0, 3, 130, -10};

for (uint32_t n = 0; n < ARRAY_SIZE(oop_shifts); n++) {
if (oop_shifts[n] != 0 &&
param->session.op_type != ODP_CRYPTO_OP_TYPE_OOP)
param->op_type != ODP_CRYPTO_OP_TYPE_OOP)
continue;
if ((int32_t)param->header_len + oop_shifts[n] < 0)
continue;
Expand All @@ -145,12 +149,25 @@ static void alg_test_op(crypto_op_test_param_t *param)

if (!full_test && param->session.null_crypto_enable)
break;
if (!full_test && param->session.op_type == ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP)
break;

param->wrong_digest = true;
alg_test_execute_and_print(param);
}
}

static void alg_test_op(crypto_op_test_param_t *param)
{
param->op_type = param->session.op_type;
if (param->op_type == ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP) {
param->op_type = ODP_CRYPTO_OP_TYPE_BASIC;
alg_test_op2(param);
param->op_type = ODP_CRYPTO_OP_TYPE_OOP;
}
alg_test_op2(param);
}

static int combo_warning_shown;
static int oop_warning_shown;

Expand Down Expand Up @@ -244,9 +261,10 @@ static int session_create(crypto_session_t *session,

/* For now, allow out-of-place sessions not to be supported. */
if (rc < 0 && status == ODP_CRYPTO_SES_ERR_PARAMS &&
ses_params.op_type == ODP_CRYPTO_OP_TYPE_OOP) {
(ses_params.op_type == ODP_CRYPTO_OP_TYPE_OOP ||
ses_params.op_type == ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP)) {
if (!oop_warning_shown)
printf("\n Skipping ODP_CRYPTO_OP_TYPE_OOP tests\n");
printf("\n Skipping out-of-place tests\n");
oop_warning_shown = 1;
return -1;
}
Expand Down Expand Up @@ -316,7 +334,8 @@ static void alg_test_ses(odp_crypto_op_t op,
if (!full_test)
if ((ref->cipher != ODP_CIPHER_ALG_NULL &&
ref->auth != ODP_AUTH_ALG_NULL) ||
test_param.session.null_crypto_enable) {
test_param.session.null_crypto_enable ||
test_param.session.op_type == ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP) {
/* run the loop body just once */
seg_len = max_shift / 2;
max_shift = seg_len;
Expand Down Expand Up @@ -366,6 +385,7 @@ static void alg_test_op_types(odp_crypto_op_t op,
ODP_CRYPTO_OP_TYPE_LEGACY,
ODP_CRYPTO_OP_TYPE_BASIC,
ODP_CRYPTO_OP_TYPE_OOP,
ODP_CRYPTO_OP_TYPE_BASIC_AND_OOP,
};

for (unsigned int n = 0; n < ARRAY_SIZE(op_types); n++) {
Expand Down Expand Up @@ -643,7 +663,8 @@ static int create_hash_test_reference(odp_auth_alg_t auth,
.auth_range = { .offset = 0, .length = auth_bytes },
.dst_offset_shift = 0,
};
rc = crypto_op(pkt, &pkt, &ok, &op_params, ODP_CRYPTO_OP_TYPE_LEGACY);
rc = crypto_op(pkt, &pkt, &ok, &op_params,
ODP_CRYPTO_OP_TYPE_LEGACY, ODP_CRYPTO_OP_TYPE_LEGACY);

CU_ASSERT(rc == 0);
if (rc) {
Expand Down Expand Up @@ -862,7 +883,8 @@ static int crypto_encode_ref(crypto_test_reference_t *ref,
.auth_range = auth_range,
.dst_offset_shift = 0,
};
rc = crypto_op(pkt, &pkt, &ok, &op_params, ODP_CRYPTO_OP_TYPE_LEGACY);
rc = crypto_op(pkt, &pkt, &ok, &op_params,
ODP_CRYPTO_OP_TYPE_LEGACY, ODP_CRYPTO_OP_TYPE_LEGACY);
CU_ASSERT(rc == 0);
if (rc) {
(void)odp_crypto_session_destroy(session.session);
Expand Down

0 comments on commit cdbc7d0

Please sign in to comment.