Crypto completion event is now sole responsibility of the implementation when API is operating asynchrnously. Synchronous mode can now return results directly without involving completion event at all.
Signed-off-by: Robbie King <[email protected]> --- example/ipsec/odp_ipsec.c | 85 ++++++++++------- platform/linux-generic/include/api/odp_crypto.h | 102 ++++++++++---------- platform/linux-generic/include/api/odp_event.h | 2 + .../linux-generic/include/odp_crypto_internal.h | 6 +- platform/linux-generic/odp_crypto.c | 106 ++++++++++----------- test/validation/crypto/odp_crypto_test_async_inp.c | 95 ++++-------------- test/validation/crypto/odp_crypto_test_sync_inp.c | 14 ++- 7 files changed, 184 insertions(+), 226 deletions(-) diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c index f2d2fc7..d22d7cb 100644 --- a/example/ipsec/odp_ipsec.c +++ b/example/ipsec/odp_ipsec.c @@ -674,7 +674,8 @@ pkt_disposition_e do_route_fwd_db(odp_packet_t pkt, pkt_ctx_t *ctx) static pkt_disposition_e do_ipsec_in_classify(odp_packet_t pkt, pkt_ctx_t *ctx, - bool *skip) + bool *skip, + odp_crypto_op_result_t *result) { uint8_t *buf = odp_packet_data(pkt); odph_ipv4hdr_t *ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL); @@ -704,6 +705,7 @@ pkt_disposition_e do_ipsec_in_classify(odp_packet_t pkt, /* Initialize parameters block */ memset(¶ms, 0, sizeof(params)); + params.ctx = ctx; params.session = entry->state.session; params.pkt = pkt; params.out_pkt = entry->in_place ? pkt : ODP_PACKET_INVALID; @@ -740,7 +742,7 @@ pkt_disposition_e do_ipsec_in_classify(odp_packet_t pkt, *skip = FALSE; if (odp_crypto_operation(¶ms, &posted, - odp_packet_to_event(pkt))) { + result)) { abort(); } return (posted) ? PKT_POSTED : PKT_CONTINUE; @@ -756,22 +758,20 @@ pkt_disposition_e do_ipsec_in_classify(odp_packet_t pkt, */ static pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt, - pkt_ctx_t *ctx) + pkt_ctx_t *ctx, + odp_crypto_op_result_t *result) { - odp_event_t event; - odp_crypto_compl_status_t cipher_rc; - odp_crypto_compl_status_t auth_rc; odph_ipv4hdr_t *ip; int hdr_len = ctx->ipsec.hdr_len; int trl_len = 0; /* Check crypto result */ - event = odp_packet_to_event(pkt); - odp_crypto_get_operation_compl_status(event, &auth_rc, &cipher_rc); - if (!is_crypto_compl_status_ok(&cipher_rc)) - return PKT_DROP; - if (!is_crypto_compl_status_ok(&auth_rc)) - return PKT_DROP; + if (!result->ok) { + if (!is_crypto_compl_status_ok(&result->cipher_status)) + return PKT_DROP; + if (!is_crypto_compl_status_ok(&result->auth_status)) + return PKT_DROP; + } ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL); /* @@ -865,6 +865,7 @@ pkt_disposition_e do_ipsec_out_classify(odp_packet_t pkt, /* Initialize parameters block */ memset(¶ms, 0, sizeof(params)); params.session = entry->state.session; + params.ctx = ctx; params.pkt = pkt; params.out_pkt = entry->in_place ? pkt : ODP_PACKET_INVALID; @@ -952,7 +953,8 @@ pkt_disposition_e do_ipsec_out_classify(odp_packet_t pkt, */ static pkt_disposition_e do_ipsec_out_seq(odp_packet_t pkt, - pkt_ctx_t *ctx) + pkt_ctx_t *ctx, + odp_crypto_op_result_t *result) { uint8_t *buf = odp_packet_data(pkt); bool posted = 0; @@ -974,7 +976,7 @@ pkt_disposition_e do_ipsec_out_seq(odp_packet_t pkt, /* Issue crypto request */ if (odp_crypto_operation(&ctx->ipsec.params, &posted, - odp_packet_to_event(pkt))) { + result)) { abort(); } return (posted) ? PKT_POSTED : PKT_CONTINUE; @@ -990,20 +992,18 @@ pkt_disposition_e do_ipsec_out_seq(odp_packet_t pkt, */ static pkt_disposition_e do_ipsec_out_finish(odp_packet_t pkt, - pkt_ctx_t *ctx) + pkt_ctx_t *ctx, + odp_crypto_op_result_t *result) { - odp_event_t event; - odp_crypto_compl_status_t cipher_rc; - odp_crypto_compl_status_t auth_rc; odph_ipv4hdr_t *ip; /* Check crypto result */ - event = odp_packet_to_event(pkt); - odp_crypto_get_operation_compl_status(event, &auth_rc, &cipher_rc); - if (!is_crypto_compl_status_ok(&cipher_rc)) - return PKT_DROP; - if (!is_crypto_compl_status_ok(&auth_rc)) - return PKT_DROP; + if (!result->ok) { + if (!is_crypto_compl_status_ok(&result->cipher_status)) + return PKT_DROP; + if (!is_crypto_compl_status_ok(&result->auth_status)) + return PKT_DROP; + } ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL); /* Finalize the IPv4 header */ @@ -1051,17 +1051,27 @@ void *pktio_thread(void *arg EXAMPLE_UNUSED) pkt_disposition_e rc; pkt_ctx_t *ctx; odp_queue_t dispatchq; + odp_crypto_op_result_t result; - /* Use schedule to get buf from any input queue */ - ev = SCHEDULE(&dispatchq, ODP_SCHED_WAIT); - pkt = odp_packet_from_event(ev); + /* Use schedule to get event from any input queue */ + ev = SCHEDULE(&dispatchq, ODP_SCHED_WAIT); /* Determine new work versus completion or sequence number */ - if ((completionq != dispatchq) && (seqnumq != dispatchq)) { + if (seqnumq == dispatchq) { + pkt = odp_packet_from_event(ev); + ctx = get_pkt_ctx_from_pkt(pkt); + } else if (completionq == dispatchq) { + odp_crypto_compl_t compl; + + compl = odp_crypto_compl_from_event(ev); + odp_crypto_compl_result(compl, &result); + odp_crypto_compl_free(compl); + pkt = result.pkt; + ctx = result.ctx; + } else { + pkt = odp_packet_from_event(ev); ctx = alloc_pkt_ctx(pkt); ctx->state = PKT_STATE_INPUT_VERIFY; - } else { - ctx = get_pkt_ctx_from_pkt(pkt); } /* @@ -1088,7 +1098,10 @@ void *pktio_thread(void *arg EXAMPLE_UNUSED) case PKT_STATE_IPSEC_IN_CLASSIFY: - rc = do_ipsec_in_classify(pkt, ctx, &skip); + rc = do_ipsec_in_classify(pkt, + ctx, + &skip, + &result); ctx->state = (skip) ? PKT_STATE_ROUTE_LOOKUP : PKT_STATE_IPSEC_IN_FINISH; @@ -1096,7 +1109,7 @@ void *pktio_thread(void *arg EXAMPLE_UNUSED) case PKT_STATE_IPSEC_IN_FINISH: - rc = do_ipsec_in_finish(pkt, ctx); + rc = do_ipsec_in_finish(pkt, ctx, &result); ctx->state = PKT_STATE_ROUTE_LOOKUP; break; @@ -1108,7 +1121,9 @@ void *pktio_thread(void *arg EXAMPLE_UNUSED) case PKT_STATE_IPSEC_OUT_CLASSIFY: - rc = do_ipsec_out_classify(pkt, ctx, &skip); + rc = do_ipsec_out_classify(pkt, + ctx, + &skip); if (odp_unlikely(skip)) { ctx->state = PKT_STATE_TRANSMIT; } else { @@ -1119,13 +1134,13 @@ void *pktio_thread(void *arg EXAMPLE_UNUSED) case PKT_STATE_IPSEC_OUT_SEQ: - rc = do_ipsec_out_seq(pkt, ctx); + rc = do_ipsec_out_seq(pkt, ctx, &result); ctx->state = PKT_STATE_IPSEC_OUT_FINISH; break; case PKT_STATE_IPSEC_OUT_FINISH: - rc = do_ipsec_out_finish(pkt, ctx); + rc = do_ipsec_out_finish(pkt, ctx, &result); ctx->state = PKT_STATE_TRANSMIT; break; diff --git a/platform/linux-generic/include/api/odp_crypto.h b/platform/linux-generic/include/api/odp_crypto.h index da6041c..978c7c0 100644 --- a/platform/linux-generic/include/api/odp_crypto.h +++ b/platform/linux-generic/include/api/odp_crypto.h @@ -38,6 +38,11 @@ extern "C" { typedef uint64_t odp_crypto_session_t; /** +* Crypto API completion event (platform dependent). +*/ +typedef odp_packet_t odp_crypto_compl_t; + +/** * Crypto API operation mode */ enum odp_crypto_op_mode { @@ -141,6 +146,7 @@ typedef struct odp_crypto_session_params { */ typedef struct odp_crypto_op_params { odp_crypto_session_t session; /**< Session handle from creation */ + void *ctx; /**< User context */ odp_packet_t pkt; /**< Input packet buffer */ odp_packet_t out_pkt; /**< Output packet buffer */ uint8_t *override_iv_ptr; /**< Override session IV pointer */ @@ -210,6 +216,16 @@ typedef struct odp_crypto_compl_status { enum crypto_hw_err hw_err; /**< Hardware specific return code */ } odp_crypto_compl_status_t; +/** + * Crypto API operation result + */ +typedef struct odp_crypto_op_result { + odp_bool_t ok; /**< Request completed successfully */ + void *ctx; /**< User context from request */ + odp_packet_t pkt; /**< Output packet */ + odp_crypto_compl_status_t cipher_status; /**< Cipher status */ + odp_crypto_compl_status_t auth_status; /**< Authentication status */ +} odp_crypto_op_result_t; /** * Crypto session creation (synchronous) @@ -225,76 +241,64 @@ odp_crypto_session_create(odp_crypto_session_params_t *params, odp_crypto_session_t *session, enum odp_crypto_ses_create_err *status); +/** + * Return crypto completion handle that is associated with event + * + * Note: any invalid parameters will cause undefined behavior and may cause + * the application to abort or crash. + * + * @param ev An event of type ODP_EVENT_CRYPTO_COMPL + * + * @return crypto completion handle + */ +odp_crypto_compl_t odp_crypto_compl_from_event(odp_event_t ev); + +/** + * Convert crypto completion handle to event handle + * + * @param completion_event Completion event to convert to generic event + * + * @return Event handle + */ +odp_event_t odp_crypto_compl_to_event(odp_crypto_compl_t completion_event); + +/** + * Release crypto completion event + * + * @param completion_event Completion event we are done accessing + */ +void +odp_crypto_compl_free(odp_crypto_compl_t completion_event); /** * Crypto per packet operation * * Performs the cryptographic operations specified during session creation * on the packet. If the operation is performed synchronously, "posted" - * will return FALSE and the result of the operation is immediately available - * in the completion event. If "posted" returns TRUE the result will be - * delivered via the completion queue specified when the session was created. - * - * @todo Resolve if completion_event is necessary, can/should the output - * packet buffer always be used instead. + * will return FALSE and the result of the operation is immediately available. + * If "posted" returns TRUE the result will be delivered via the completion + * queue specified when the session was created. * * @param params Operation parameters * @param posted Pointer to return posted, TRUE for async operation - * @param completion_event Event by which the operation results are delivered. + * @param result Results of operation (when posted returns FALSE) * * @return 0 if successful else -1 */ int odp_crypto_operation(odp_crypto_op_params_t *params, bool *posted, - odp_event_t completion_event); + odp_crypto_op_result_t *result); /** - * Crypto per packet operation set user context in completion event + * Crypto per packet operation query result from completion event * * @param completion_event Event containing operation results - * @param ctx User data + * @param result Pointer to result structure */ void -odp_crypto_set_operation_compl_ctx(odp_event_t completion_event, - void *ctx); - -/** - * Crypto per packet operation completion status - * - * Accessor function for obtaining operation status from the completion event. - * - * @param completion_event Event containing operation results - * @param auth Pointer to store authentication results - * @param cipher Pointer to store cipher results - */ -void -odp_crypto_get_operation_compl_status(odp_event_t completion_event, - odp_crypto_compl_status_t *auth, - odp_crypto_compl_status_t *cipher); - -/** - * Crypto per packet operation query completed operation packet - * - * Accessor function for obtaining current packet buffer, can be - * different from input packet buffer on some systems - * - * @param completion_event Event containing operation results - * - * @return Packet structure where data now resides - */ -odp_packet_t -odp_crypto_get_operation_compl_packet(odp_event_t completion_event); - -/** - * Crypto per packet operation query user context in completion event - * - * @param completion_event Event containing operation results - * - * @return User data - */ -void * -odp_crypto_get_operation_compl_ctx(odp_event_t completion_event); +odp_crypto_compl_result(odp_crypto_compl_t completion_event, + odp_crypto_op_result_t *result); /** * Generate random byte string diff --git a/platform/linux-generic/include/api/odp_event.h b/platform/linux-generic/include/api/odp_event.h index 209d968..36fe44d 100644 --- a/platform/linux-generic/include/api/odp_event.h +++ b/platform/linux-generic/include/api/odp_event.h @@ -45,6 +45,8 @@ int odp_event_type(odp_event_t event); #define ODP_EVENT_PACKET 2 /** Timeout event */ #define ODP_EVENT_TIMEOUT 3 +/** Crypto completion event */ +#define ODP_EVENT_CRYPTO_COMPL 4 diff --git a/platform/linux-generic/include/odp_crypto_internal.h b/platform/linux-generic/include/odp_crypto_internal.h index 429c6c2..a474b94 100644 --- a/platform/linux-generic/include/odp_crypto_internal.h +++ b/platform/linux-generic/include/odp_crypto_internal.h @@ -59,7 +59,6 @@ struct odp_crypto_generic_session { } data; crypto_func_t func; } auth; - }; /** @@ -67,10 +66,7 @@ struct odp_crypto_generic_session { */ typedef struct odp_crypto_generic_op_result { uint32_t magic; - odp_crypto_compl_status_t cipher; - odp_crypto_compl_status_t auth; - void *op_context; - odp_packet_t out_pkt; + odp_crypto_op_result_t result; } odp_crypto_generic_op_result_t; /** diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 4436a0c..acf2f12 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -345,18 +345,16 @@ odp_crypto_session_create(odp_crypto_session_params_t *params, return 0; } - int odp_crypto_operation(odp_crypto_op_params_t *params, bool *posted, - odp_event_t completion_event) + odp_crypto_op_result_t *result) { enum crypto_alg_err rc_cipher = ODP_CRYPTO_ALG_ERR_NONE; enum crypto_alg_err rc_auth = ODP_CRYPTO_ALG_ERR_NONE; odp_crypto_generic_session_t *session; - odp_crypto_generic_op_result_t *result; + odp_crypto_op_result_t local_result; - *posted = 0; session = (odp_crypto_generic_session_t *)(intptr_t)params->session; /* Resolve output buffer */ @@ -370,9 +368,6 @@ odp_crypto_operation(odp_crypto_op_params_t *params, ODP_ABORT(); _odp_packet_copy_to_packet(params->pkt, 0, params->out_pkt, 0, odp_packet_len(params->pkt)); - if (completion_event == odp_packet_to_event(params->pkt)) - completion_event = - odp_packet_to_event(params->out_pkt); odp_packet_free(params->pkt); params->pkt = ODP_PACKET_INVALID; } @@ -386,19 +381,39 @@ odp_crypto_operation(odp_crypto_op_params_t *params, rc_cipher = session->cipher.func(params, session); } - /* Build Result (no HW so no errors) */ - result = get_op_result_from_event(completion_event); - result->magic = OP_RESULT_MAGIC; - result->cipher.alg_err = rc_cipher; - result->cipher.hw_err = ODP_CRYPTO_HW_ERR_NONE; - result->auth.alg_err = rc_auth; - result->auth.hw_err = ODP_CRYPTO_HW_ERR_NONE; - result->out_pkt = params->out_pkt; + /* Fill in result */ + local_result.ctx = params->ctx; + local_result.pkt = params->out_pkt; + local_result.cipher_status.alg_err = rc_cipher; + local_result.cipher_status.hw_err = ODP_CRYPTO_HW_ERR_NONE; + local_result.auth_status.alg_err = rc_auth; + local_result.auth_status.hw_err = ODP_CRYPTO_HW_ERR_NONE; + local_result.ok = + (rc_cipher == ODP_CRYPTO_ALG_ERR_NONE) && + (rc_auth == ODP_CRYPTO_ALG_ERR_NONE); /* If specified during creation post event to completion queue */ if (ODP_QUEUE_INVALID != session->compl_queue) { + odp_event_t completion_event; + odp_crypto_generic_op_result_t *op_result; + + /* Linux generic will always use packet for completion event */ + completion_event = odp_packet_to_event(params->out_pkt); + + /* Asynchronous, build result (no HW so no errors) and send it*/ + op_result = get_op_result_from_event(completion_event); + op_result->magic = OP_RESULT_MAGIC; + op_result->result = local_result; odp_queue_enq(session->compl_queue, completion_event); + + /* Indicate to caller operation was async */ *posted = 1; + } else { + /* Synchronous, simply return results */ + *result = local_result; + + /* Indicate to caller operation was sync */ + *posted = 0; } return 0; } @@ -436,56 +451,33 @@ odp_hw_random_get(uint8_t *buf, size_t *len, bool use_entropy ODP_UNUSED) return ((1 == rc) ? 0 : -1); } +odp_crypto_compl_t odp_crypto_compl_from_event(odp_event_t ev) +{ + return (odp_crypto_compl_t)ev; +} + +odp_event_t odp_crypto_compl_to_event(odp_crypto_compl_t completion_event) +{ + return (odp_event_t)completion_event; +} + void -odp_crypto_get_operation_compl_status(odp_event_t completion_event, - odp_crypto_compl_status_t *auth, - odp_crypto_compl_status_t *cipher) +odp_crypto_compl_result(odp_crypto_compl_t completion_event, + odp_crypto_op_result_t *result) { - odp_crypto_generic_op_result_t *result; + odp_event_t ev = odp_crypto_compl_to_event(completion_event); + odp_crypto_generic_op_result_t *op_result; - result = get_op_result_from_event(completion_event); + op_result = get_op_result_from_event(ev); - if (OP_RESULT_MAGIC != result->magic) + if (OP_RESULT_MAGIC != op_result->magic) ODP_ABORT(); - memcpy(auth, &result->auth, sizeof(*auth)); - memcpy(cipher, &result->cipher, sizeof(*cipher)); -} - - -void -odp_crypto_set_operation_compl_ctx(odp_event_t completion_event, - void *ctx) -{ - odp_crypto_generic_op_result_t *result; - - result = get_op_result_from_event(completion_event); - /* - * Completion event magic can't be checked here, because it is filled - * later in odp_crypto_operation() function. - */ - - result->op_context = ctx; + memcpy(result, &op_result->result, sizeof(*result)); } void -*odp_crypto_get_operation_compl_ctx(odp_event_t completion_event) +odp_crypto_compl_free(odp_crypto_compl_t completion_event ODP_UNUSED) { - odp_crypto_generic_op_result_t *result; - - result = get_op_result_from_event(completion_event); - ODP_ASSERT(OP_RESULT_MAGIC == result->magic, "Bad completion magic"); - - return result->op_context; -} - -odp_packet_t -odp_crypto_get_operation_compl_packet(odp_event_t completion_event) -{ - odp_crypto_generic_op_result_t *result; - - result = get_op_result_from_event(completion_event); - ODP_ASSERT(OP_RESULT_MAGIC == result->magic, "Bad completion magic"); - - return result->out_pkt; + /* We use the packet as the completion event so nothing to do here */ } diff --git a/test/validation/crypto/odp_crypto_test_async_inp.c b/test/validation/crypto/odp_crypto_test_async_inp.c index 424c589..d74586f 100644 --- a/test/validation/crypto/odp_crypto_test_async_inp.c +++ b/test/validation/crypto/odp_crypto_test_async_inp.c @@ -25,7 +25,6 @@ static void alg_test(enum odp_crypto_op op, odp_crypto_key_t cipher_key, enum odp_auth_alg auth_alg, odp_crypto_key_t auth_key, - odp_event_t compl_new, uint8_t *input_vec, unsigned int input_vec_len, uint8_t *output_vec, @@ -35,7 +34,9 @@ static void alg_test(enum odp_crypto_op op, int rc; enum odp_crypto_ses_create_err status; bool posted; - odp_event_t compl_event; + odp_event_t event; + odp_crypto_compl_t compl_event; + odp_crypto_op_result_t result; odp_queue_t compl_queue = odp_queue_lookup("crypto-out"); CU_ASSERT(compl_queue != ODP_QUEUE_INVALID); @@ -73,6 +74,7 @@ static void alg_test(enum odp_crypto_op op, op_params.session = session; op_params.pkt = pkt; op_params.out_pkt = pkt; + op_params.ctx = (void *)0xdeadbeef; if (cipher_alg != ODP_CIPHER_ALG_NULL && auth_alg == ODP_AUTH_ALG_NULL) { op_params.cipher_range.offset = data_off; @@ -88,43 +90,29 @@ static void alg_test(enum odp_crypto_op op, CU_FAIL("%s : not implemented for combined alg mode\n"); } - if (compl_new == ODP_EVENT_INVALID) { - odp_event_t ev = odp_packet_to_event(pkt); - odp_crypto_set_operation_compl_ctx(ev, (void *)0xdeadbeef); - rc = odp_crypto_operation(&op_params, &posted, ev); - } else { - odp_crypto_set_operation_compl_ctx(compl_new, - (void *)0xdeadbeef); - rc = odp_crypto_operation(&op_params, &posted, compl_new); - } + rc = odp_crypto_operation(&op_params, &posted, NULL); CU_ASSERT(posted); /* Poll completion queue for results */ do { - compl_event = odp_queue_deq(compl_queue); - } while (compl_event == ODP_EVENT_INVALID); + event = odp_queue_deq(compl_queue); + } while (event == ODP_EVENT_INVALID); - if (compl_new == ODP_EVENT_INVALID) - CU_ASSERT(compl_event == odp_packet_to_event(pkt)) - else - CU_ASSERT(compl_event == compl_new) + compl_event = odp_crypto_compl_from_event(event); + odp_crypto_compl_result(compl_event, &result); + odp_crypto_compl_free(compl_event); - struct odp_crypto_compl_status auth_status, cipher_status; - odp_crypto_get_operation_compl_status(compl_event, - &auth_status, &cipher_status); - CU_ASSERT(auth_status.alg_err == ODP_CRYPTO_ALG_ERR_NONE); - CU_ASSERT(auth_status.hw_err == ODP_CRYPTO_HW_ERR_NONE); - CU_ASSERT(cipher_status.alg_err == ODP_CRYPTO_ALG_ERR_NONE); - CU_ASSERT(cipher_status.hw_err == ODP_CRYPTO_HW_ERR_NONE); + CU_ASSERT(result.ok); + CU_ASSERT(result.auth_status.alg_err == ODP_CRYPTO_ALG_ERR_NONE); + CU_ASSERT(result.auth_status.hw_err == ODP_CRYPTO_HW_ERR_NONE); + CU_ASSERT(result.cipher_status.alg_err == ODP_CRYPTO_ALG_ERR_NONE); + CU_ASSERT(result.cipher_status.hw_err == ODP_CRYPTO_HW_ERR_NONE); - odp_packet_t out_pkt; - out_pkt = odp_crypto_get_operation_compl_packet(compl_event); - CU_ASSERT(out_pkt == pkt); + CU_ASSERT(result.pkt == pkt); CU_ASSERT(!memcmp(data_addr, output_vec, output_vec_len)); - void *ctx = odp_crypto_get_operation_compl_ctx(compl_event); - CU_ASSERT(ctx == (void *)0xdeadbeef); + CU_ASSERT(result.ctx == (void *)0xdeadbeef); odp_packet_free(pkt); } @@ -156,7 +144,6 @@ static void enc_alg_3des_cbc(void) cipher_key, ODP_AUTH_ALG_NULL, auth_key, - ODP_EVENT_INVALID, tdes_cbc_reference_plaintext[i], tdes_cbc_reference_length[i], tdes_cbc_reference_ciphertext[i], @@ -188,7 +175,6 @@ static void enc_alg_3des_cbc_ovr_iv(void) cipher_key, ODP_AUTH_ALG_NULL, auth_key, - ODP_EVENT_INVALID, tdes_cbc_reference_plaintext[i], tdes_cbc_reference_length[i], tdes_cbc_reference_ciphertext[i], @@ -225,7 +211,6 @@ static void dec_alg_3des_cbc(void) cipher_key, ODP_AUTH_ALG_NULL, auth_key, - ODP_EVENT_INVALID, tdes_cbc_reference_ciphertext[i], tdes_cbc_reference_length[i], tdes_cbc_reference_plaintext[i], @@ -259,7 +244,6 @@ static void dec_alg_3des_cbc_ovr_iv(void) cipher_key, ODP_AUTH_ALG_NULL, auth_key, - ODP_EVENT_INVALID, tdes_cbc_reference_ciphertext[i], tdes_cbc_reference_length[i], tdes_cbc_reference_plaintext[i], @@ -297,7 +281,6 @@ static void alg_hmac_md5(void) cipher_key, ODP_AUTH_ALG_MD5_96, auth_key, - ODP_EVENT_INVALID, hmac_md5_reference_plaintext[i], hmac_md5_reference_length[i], hmac_md5_reference_digest[i], @@ -305,55 +288,11 @@ static void alg_hmac_md5(void) } } -/* This test verifies the correctness of encode (plaintext -> ciphertext) - * operation for 3DES_CBC algorithm. IV for the operation is the session IV. - * Uses a separate buffer for completion event - * */ -#define ASYNC_INP_ENC_ALG_3DES_CBC_COMPL_NEW "ENC_ALG_3DES_CBC_COMPL_NEW" -static void enc_alg_3des_cbc_compl_new(void) -{ - odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, - auth_key = { .data = NULL, .length = 0 }; - odp_crypto_iv_t iv; - unsigned int test_vec_num = (sizeof(tdes_cbc_reference_length)/ - sizeof(tdes_cbc_reference_length[0])); - - odp_pool_t pool = odp_pool_lookup("compl_pool"); - CU_ASSERT(pool != ODP_POOL_INVALID); - - unsigned int i; - odp_buffer_t compl_new; - for (i = 0; i < test_vec_num; i++) { - compl_new = odp_buffer_alloc(pool); - CU_ASSERT(compl_new != ODP_BUFFER_INVALID); - - cipher_key.data = tdes_cbc_reference_key[i]; - cipher_key.length = sizeof(tdes_cbc_reference_key[i]); - iv.data = tdes_cbc_reference_iv[i]; - iv.length = sizeof(tdes_cbc_reference_iv[i]); - - alg_test(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_3DES_CBC, - iv, - NULL, - cipher_key, - ODP_AUTH_ALG_NULL, - auth_key, - odp_buffer_to_event(compl_new), - tdes_cbc_reference_plaintext[i], - tdes_cbc_reference_length[i], - tdes_cbc_reference_ciphertext[i], - tdes_cbc_reference_length[i]); - odp_buffer_free(compl_new); - } -} - CU_TestInfo test_array_async[] = { {ASYNC_INP_ENC_ALG_3DES_CBC, enc_alg_3des_cbc }, {ASYNC_INP_DEC_ALG_3DES_CBC, dec_alg_3des_cbc }, {ASYNC_INP_ENC_ALG_3DES_CBC_OVR_IV, enc_alg_3des_cbc_ovr_iv }, {ASYNC_INP_DEC_ALG_3DES_CBC_OVR_IV, dec_alg_3des_cbc_ovr_iv }, {ASYNC_INP_ALG_HMAC_MD5, alg_hmac_md5 }, - {ASYNC_INP_ENC_ALG_3DES_CBC_COMPL_NEW, enc_alg_3des_cbc_compl_new }, CU_TEST_INFO_NULL, }; diff --git a/test/validation/crypto/odp_crypto_test_sync_inp.c b/test/validation/crypto/odp_crypto_test_sync_inp.c index 2300c8d..424dd97 100644 --- a/test/validation/crypto/odp_crypto_test_sync_inp.c +++ b/test/validation/crypto/odp_crypto_test_sync_inp.c @@ -24,6 +24,7 @@ static void alg_test(enum odp_crypto_op op, int rc; enum odp_crypto_ses_create_err status; bool posted; + odp_crypto_op_result_t result; odp_queue_t compl_queue = odp_queue_lookup("crypto-out"); CU_ASSERT(compl_queue != ODP_QUEUE_INVALID); @@ -62,6 +63,7 @@ static void alg_test(enum odp_crypto_op op, op_params.session = session; op_params.pkt = pkt; op_params.out_pkt = pkt; + op_params.ctx = (void *)0xdeadbeef; if (cipher_alg != ODP_CIPHER_ALG_NULL && auth_alg == ODP_AUTH_ALG_NULL) { op_params.cipher_range.offset = data_off; @@ -78,14 +80,22 @@ static void alg_test(enum odp_crypto_op op, } /* TEST : odp_crypto_operation */ - rc = odp_crypto_operation(&op_params, &posted, - odp_packet_to_event(pkt)); + rc = odp_crypto_operation(&op_params, &posted, &result); CU_ASSERT(!rc); /* indication that the operation completed */ CU_ASSERT(!posted); + /* TEST: results were ok */ + CU_ASSERT(result.ok); + CU_ASSERT(result.auth_status.alg_err == ODP_CRYPTO_ALG_ERR_NONE); + CU_ASSERT(result.auth_status.hw_err == ODP_CRYPTO_HW_ERR_NONE); + CU_ASSERT(result.cipher_status.alg_err == ODP_CRYPTO_ALG_ERR_NONE); + CU_ASSERT(result.cipher_status.hw_err == ODP_CRYPTO_HW_ERR_NONE); + /* TEST : operation output was correct */ CU_ASSERT(!memcmp(data_addr, output_vec, output_vec_len)); + + CU_ASSERT(result.ctx == (void *)0xdeadbeef); } #define SYNC_INP_ENC_ALG_3DES_CBC "ENC_ALG_3DES_CBC" -- 1.9.1 _______________________________________________ lng-odp mailing list [email protected] http://lists.linaro.org/mailman/listinfo/lng-odp
