From 00992ed8fe7805b64d10e35d74f541e36330a7c6 Mon Sep 17 00:00:00 2001 From: Laurence Lundblade Date: Wed, 15 Nov 2023 01:34:45 +0100 Subject: [PATCH] More tests and error handling fixes for COSE_Encrypt (#275) This adds test coverage for most things that can go wrong with a COSE_Encrypt and fixes the error handling for these things. The shell script that processes diag into test input is improved. * More tests and error handling fixes for COSE_Encrypt * Fill out error handling for COSE_Encrypt decoding * Fix left over merge issue * Add .diag files to Xcode project * error checking in script for making test messages * Describe test cases; fix rcpt test case; rename some * straggler files --------- Co-authored-by: Laurence Lundblade --- inc/t_cose/t_cose_common.h | 7 +- inc/t_cose/t_cose_encrypt_enc.h | 3 +- inc/t_cose/t_cose_recipient_dec.h | 2 +- src/t_cose_encrypt_dec.c | 90 ++-- src/t_cose_encrypt_enc.c | 20 +- src/t_cose_recipient_dec_esdh.c | 4 + src/t_cose_util.h | 2 +- t_cose.xcodeproj/project.pbxproj | 50 +++ test/data/aead_in_error.diag | 1 + test/data/cose_encrypt_a128cbc_a128kw.diag | 18 + test/data/cose_encrypt_a128ctr_a128kw.diag | 18 + test/data/cose_encrypt_bad_alg.diag | 24 ++ test/data/cose_encrypt_bad_hdrs.diag | 24 ++ test/data/cose_encrypt_bad_iv.diag | 24 ++ test/data/cose_encrypt_crit.diag | 24 ++ test/data/cose_encrypt_junk_recipient.diag | 1 + test/data/cose_encrypt_p256_wrap_128.diag | 1 + test/data/cose_encrypt_p256_wrap_aescbc.diag | 12 - test/data/cose_encrypt_p256_wrap_aesctr.diag | 12 - test/data/cose_encrypt_wrong_array.diag | 24 ++ test/data/cose_encrypt_wrong_extra.diag | 25 ++ test/data/cose_encrypt_wrong_rcpt_array.diag | 24 ++ .../cose_recipients_map_instead_of_array.diag | 1 + test/data/hmac_big_head.diag | 1 + test/data/hmac_error_header.diag | 1 + test/data/make_test_messages.sh | 11 + test/data/no_tag.diag | 22 + test/data/test_messages.c | 393 ++++++++++++++++-- test/data/test_messages.h | 35 +- test/data/tstr_ciphertext.diag | 1 + test/data/unknown_rcpt_alg.diag | 24 ++ test/data/unknown_symmetric_alg.diag | 1 + test/data/unprot_headers_wrong_type.diag | 1 + test/data/wrong_tag.diag | 24 ++ test/t_cose_encrypt_decrypt_test.c | 105 ++++- 35 files changed, 910 insertions(+), 120 deletions(-) create mode 100644 test/data/cose_encrypt_a128cbc_a128kw.diag create mode 100644 test/data/cose_encrypt_a128ctr_a128kw.diag create mode 100644 test/data/cose_encrypt_bad_alg.diag create mode 100644 test/data/cose_encrypt_bad_hdrs.diag create mode 100644 test/data/cose_encrypt_bad_iv.diag create mode 100644 test/data/cose_encrypt_crit.diag delete mode 100644 test/data/cose_encrypt_p256_wrap_aescbc.diag delete mode 100644 test/data/cose_encrypt_p256_wrap_aesctr.diag create mode 100644 test/data/cose_encrypt_wrong_array.diag create mode 100644 test/data/cose_encrypt_wrong_extra.diag create mode 100644 test/data/cose_encrypt_wrong_rcpt_array.diag create mode 100644 test/data/no_tag.diag create mode 100644 test/data/unknown_rcpt_alg.diag create mode 100644 test/data/wrong_tag.diag diff --git a/inc/t_cose/t_cose_common.h b/inc/t_cose/t_cose_common.h index 32a08682..cacbf46a 100644 --- a/inc/t_cose/t_cose_common.h +++ b/inc/t_cose/t_cose_common.h @@ -328,8 +328,7 @@ enum t_cose_err_t { * when a byte string is expected. */ T_COSE_ERR_PARAMETER_CBOR = 10, - /** No algorithm ID was found when one is needed. For example, - * when verifying a \c COSE_Sign1. */ + /** No algorithm ID found, algorithm ID encoded wrong, not in protected header or such. */ T_COSE_ERR_NO_ALG_ID = 11, /** No kid (key ID) was found when one is needed. For example, @@ -651,6 +650,10 @@ enum t_cose_err_t { /** External AAD is passed as an argument for non AEAD cipher. */ T_COSE_ERR_AAD_WITH_NON_AEAD = 91, + + /** An initialization vector (IV) is empty, wrong type or such. */ + T_COSE_ERR_BAD_IV = 92, + }; diff --git a/inc/t_cose/t_cose_encrypt_enc.h b/inc/t_cose/t_cose_encrypt_enc.h index b500f115..2833018c 100644 --- a/inc/t_cose/t_cose_encrypt_enc.h +++ b/inc/t_cose/t_cose_encrypt_enc.h @@ -188,7 +188,6 @@ struct t_cose_encrypt_enc { * t_cose_recipient_enc being used. You can even have serveral with * different algorithms (but there can only be one payload encryption * algorithm). - * TODO: decode-only mode to get parameters to look up keys */ void t_cose_encypt_enc_init(struct t_cose_encrypt_enc *context, @@ -302,7 +301,7 @@ t_cose_encrypt_set_cek(struct t_cose_encrypt_enc *context, * described in RFC 9052 section 5.2. It needs to be the size of the * CBOR-encoded protected headers, the externally supplied data and some overhead. * - * TODO: size calculation mode that will tell the caller how bit it should be + * TODO: size calculation mode that will tell the caller how big it should be */ static void t_cose_encrypt_set_enc_struct_buffer(struct t_cose_encrypt_enc *context, diff --git a/inc/t_cose/t_cose_recipient_dec.h b/inc/t_cose/t_cose_recipient_dec.h index 4b388f88..3b0dbeda 100644 --- a/inc/t_cose/t_cose_recipient_dec.h +++ b/inc/t_cose/t_cose_recipient_dec.h @@ -51,7 +51,7 @@ struct t_cose_recipient_dec; * \retval T_COSE_ERR_DECLINE * \retval T_COSE_ERR_KID_UNMATCHED * \retval T_COSE_ERR_UNSUPPORTED_KEY_EXCHANGE_ALG - * \retval .... + * \retval T_COSE_ERR_NO_MORE No more recipients to decode. End of recipients array. * * * The error returned is important as it determines whether diff --git a/src/t_cose_encrypt_dec.c b/src/t_cose_encrypt_dec.c index b2025cbc..50093f5e 100644 --- a/src/t_cose_encrypt_dec.c +++ b/src/t_cose_encrypt_dec.c @@ -57,7 +57,7 @@ is_soft_verify_error(enum t_cose_err_t error) * While this is called only once, it is split out for code readability. * * This loops over all the configured recipient decoders calling them - * until one succeeds or has a hard failure. This involve multiple + * until one succeeds or has a hard failure. This performs multiple * attempts at the CBOR decode of the COSE_Recipient. */ static enum t_cose_err_t @@ -76,10 +76,11 @@ decrypt_one_recipient(struct t_cose_encrypt_dec_ctx *me, QCBORDecode_SaveCursor(cbor_decoder, &saved_cursor); /* Loop over the configured recipients */ - for(rcpnt_decoder = me->recipient_list; - rcpnt_decoder != NULL; - rcpnt_decoder = (struct t_cose_recipient_dec *)rcpnt_decoder->base_obj.next) { + rcpnt_decoder = me->recipient_list; + while(1) { + // TODO: decode-only mode for recipients + return_value = rcpnt_decoder->decode_cb( rcpnt_decoder, /* in: me ptr of the recipient decoder */ @@ -92,15 +93,14 @@ decrypt_one_recipient(struct t_cose_encrypt_dec_ctx *me, cek /* out: the returned CEK */ ); - /* This is pretty much the same as for decrypting recipients */ if(return_value == T_COSE_SUCCESS) { - /* Only need to find one success and this is it so done.*/ - return T_COSE_SUCCESS; + /* Only need to find one success. This is it, so we are done. + * We have the CEK. */ + break; } if(return_value == T_COSE_ERR_NO_MORE) { - /* Tried all the recipient decoders. None succeeded and - * none gave a hard failure. */ + /* The end of the recipients array. No more COSE_Recipients. */ return T_COSE_ERR_NO_MORE; } @@ -109,13 +109,19 @@ decrypt_one_recipient(struct t_cose_encrypt_dec_ctx *me, /* Something very wrong. */ } - /* Loop continues on for the next recipient */ - QCBORDecode_RestoreCursor(cbor_decoder, &saved_cursor); + /* Try going on to next configured recipient decoder if there is one */ + rcpnt_decoder = (struct t_cose_recipient_dec *)rcpnt_decoder->base_obj.next; + if(rcpnt_decoder == NULL) { + /* Got to end of list and no recipient decoder succeeded. */ + return T_COSE_ERR_DECLINE; + } + /* Loop continues on for the next recipient decoder */ + QCBORDecode_RestoreCursor(cbor_decoder, &saved_cursor); } /* Got to end of list and no recipient attempted to verify */ - return T_COSE_ERR_DECLINE; + return T_COSE_SUCCESS; } @@ -151,14 +157,21 @@ t_cose_encrypt_dec_detached(struct t_cose_encrypt_dec_ctx* me, Q_USEFUL_BUF_MAKE_STACK_UB( enc_struct_buffer, T_COSE_ENCRYPT_STRUCT_DEFAULT_SIZE); struct q_useful_buf_c enc_structure; bool alg_id_prot; + enum t_cose_err_t previous_return_value; - /* --- Get started decoding array of four and tags --- */ + /* --- Get started decoding array of 4 and tags --- */ QCBORDecode_Init(&cbor_decoder, message, QCBOR_DECODE_MODE_NORMAL); QCBORDecode_EnterArray(&cbor_decoder, &array_item); + cbor_error = QCBORDecode_GetError(&cbor_decoder); + if(cbor_error != QCBOR_SUCCESS) { + goto Done; + } - const uint64_t signing_tag_nums[] = {CBOR_TAG_COSE_ENCRYPT, CBOR_TAG_COSE_ENCRYPT0, CBOR_TAG_INVALID64}; + const uint64_t signing_tag_nums[] = {CBOR_TAG_COSE_ENCRYPT, + CBOR_TAG_COSE_ENCRYPT0, + CBOR_TAG_INVALID64}; return_value = t_cose_tags_and_type(signing_tag_nums, me->option_flags, &array_item, @@ -174,7 +187,7 @@ t_cose_encrypt_dec_detached(struct t_cose_encrypt_dec_ctx* me, /* The location of body header parameters is 0, 0 */ header_location.nesting = 0; header_location.index = 0; - body_params_list = NULL; + body_params_list = NULL; rcpnt_params_list = NULL; return_value = @@ -192,6 +205,10 @@ t_cose_encrypt_dec_detached(struct t_cose_encrypt_dec_ctx* me, } nonce_cbor = t_cose_param_find_iv(body_params_list); + if(q_useful_buf_c_is_empty(nonce_cbor)) { + return T_COSE_ERR_BAD_IV; + } + ce_alg.cose_alg_id = t_cose_param_find_alg_id(body_params_list, &alg_id_prot); if(ce_alg.cose_alg_id == T_COSE_ALGORITHM_NONE) { return T_COSE_ERR_NO_ALG_ID; @@ -201,21 +218,20 @@ t_cose_encrypt_dec_detached(struct t_cose_encrypt_dec_ctx* me, if(!t_cose_params_empty(protected_params)) { return T_COSE_ERR_PROTECTED_NOT_ALLOWED; } - } else { /* Make sure alg id is protected for aead algorithms */ if(alg_id_prot != true) { return T_COSE_ERR_NO_ALG_ID; } } - - all_params_list = body_params_list; - ce_alg.bits_in_key = bits_in_crypto_alg(ce_alg.cose_alg_id); if(ce_alg.bits_in_key == UINT32_MAX) { return T_COSE_ERR_UNSUPPORTED_ENCRYPTION_ALG; } + all_params_list = body_params_list; + + /* --- The Ciphertext --- */ if(!q_useful_buf_c_is_null(detached_ciphertext)) { QCBORDecode_GetNull(&cbor_decoder); @@ -233,6 +249,10 @@ t_cose_encrypt_dec_detached(struct t_cose_encrypt_dec_ctx* me, cek_key = me->cek; } else if (message_type == T_COSE_OPT_MESSAGE_TYPE_ENCRYPT) { + if(me->recipient_list == NULL) { + return T_COSE_ERR_FAIL; // TODO: need better error here + } + header_location.nesting = 1; header_location.index = 0; @@ -240,12 +260,13 @@ t_cose_encrypt_dec_detached(struct t_cose_encrypt_dec_ctx* me, QCBORDecode_EnterArray(&cbor_decoder, NULL); cbor_error = QCBORDecode_GetError(&cbor_decoder); if(cbor_error != QCBOR_SUCCESS) { - return_value = qcbor_decode_error_to_t_cose_error(cbor_error, T_COSE_ERR_ENCRYPT_FORMAT); goto Done; } /* Loop over the array of COSE_Recipients */ while(1) { + previous_return_value = return_value; + return_value = decrypt_one_recipient(me, header_location, ce_alg, @@ -270,6 +291,14 @@ t_cose_encrypt_dec_detached(struct t_cose_encrypt_dec_ctx* me, break; } + if(return_value == T_COSE_ERR_NO_MORE) { + /* Got to the end of the COSE_Recipients array without + * success, so return the error the previous recipient decoder + * returned. */ + return_value = previous_return_value; + goto Done; + } + if(return_value != T_COSE_ERR_DECLINE) { /* Either we got to the end of the list and on * recipient decoder attempted, or some decoder @@ -304,18 +333,15 @@ t_cose_encrypt_dec_detached(struct t_cose_encrypt_dec_ctx* me, } } else { - /* Message type is not right. */ - // TODO: better error here. - return T_COSE_ERR_FAIL; + /* This never happens because of checks in t_cose_tags_and_type() */ } - /* --- Close of CBOR decode --- */ + /* --- Close of CBOR decode of the array of 4 --- */ + /* This tolerates extra items. Someday we'll have a better ExitArray() + * and efficiently catch this (mostly harmless) error. */ QCBORDecode_ExitArray(&cbor_decoder); - cbor_error = QCBORDecode_Finish(&cbor_decoder); if(cbor_error != QCBOR_SUCCESS) { - // TODO: there is probably more to be done here... - return_value = T_COSE_ERR_CBOR_DECODE; goto Done; } if(returned_parameters != NULL) { @@ -351,7 +377,7 @@ t_cose_encrypt_dec_detached(struct t_cose_encrypt_dec_ctx* me, } else { /* --- Make the Enc_structure ---- */ - /* The Enc_structure from RFC 9052 section 5.3 that is AAD input + /* The Enc_structure from RFC 9052 section 5.3 that is input as AAD * to the AEAD to integrity-protect COSE headers and * parameters. */ if(!q_useful_buf_is_null(me->extern_enc_struct_buffer)) { @@ -373,7 +399,6 @@ t_cose_encrypt_dec_detached(struct t_cose_encrypt_dec_ctx* me, goto Done; } - // TODO: handle AE algorithms return_value = t_cose_crypto_aead_decrypt( ce_alg.cose_alg_id, /* in: cose alg id to decrypt payload */ @@ -389,10 +414,9 @@ t_cose_encrypt_dec_detached(struct t_cose_encrypt_dec_ctx* me, t_cose_crypto_free_symmetric_key(cek_key); } - if (message_type != T_COSE_OPT_MESSAGE_TYPE_ENCRYPT0) { - t_cose_crypto_free_symmetric_key(cek_key); - } - Done: + if(cbor_error != QCBOR_SUCCESS) { + return_value = qcbor_decode_error_to_t_cose_error(cbor_error, T_COSE_ERR_ENCRYPT_FORMAT); + } return return_value; } diff --git a/src/t_cose_encrypt_enc.c b/src/t_cose_encrypt_enc.c index 0782bf85..6902decb 100644 --- a/src/t_cose_encrypt_enc.c +++ b/src/t_cose_encrypt_enc.c @@ -139,7 +139,7 @@ t_cose_encrypt_enc_detached(struct t_cose_encrypt_enc *me, cek_bytes, /* in: key bytes */ &cek_handle); /* out: key handle */ } - if (return_value != T_COSE_SUCCESS) { + if(return_value != T_COSE_SUCCESS) { goto Done; } /* At this point cek_handle has the encryption key for the AEAD */ @@ -166,15 +166,15 @@ t_cose_encrypt_enc_detached(struct t_cose_encrypt_enc *me, &encrypt_output /* out: ciphertext */); } else { /* ---- Make the Enc_structure ---- */ - /* Per RFC 9052 section 5.3 the structure that is authenticated - * along with the payload by the AEAD. - * - * Enc_structure = [ - * context : "Encrypt", - * protected : empty_or_serialized_map, - * external_aad : bstr - * ] - */ + /* Per RFC 9052 section 5.3 this is the structure that is authenticated + * along with the payload by the AEAD. + * + * Enc_structure = [ + * context : "Encrypt", + * protected : empty_or_serialized_map, + * external_aad : bstr + * ] + */ if(!q_useful_buf_is_null(me->extern_enc_struct_buffer)) { /* Caller gave us a (bigger) buffer for Enc_structure */ enc_struct_buffer = me->extern_enc_struct_buffer; diff --git a/src/t_cose_recipient_dec_esdh.c b/src/t_cose_recipient_dec_esdh.c index 0c0b1e8e..a77e3d22 100644 --- a/src/t_cose_recipient_dec_esdh.c +++ b/src/t_cose_recipient_dec_esdh.c @@ -141,6 +141,10 @@ t_cose_recipient_dec_esdh_cb_private(struct t_cose_recipient_dec *me_x, /* One recipient */ QCBORDecode_EnterArray(cbor_decoder, NULL); cbor_error = QCBORDecode_GetError(cbor_decoder); + if(cbor_error == QCBOR_ERR_NO_MORE_ITEMS) { + cose_result = T_COSE_ERR_NO_MORE; + goto done; + } if(cbor_error != QCBOR_SUCCESS) { cose_result = qcbor_decode_error_to_t_cose_error(cbor_error, T_COSE_ERR_RECIPIENT_FORMAT); goto done; diff --git a/src/t_cose_util.h b/src/t_cose_util.h index c10db5af..a0b9e914 100644 --- a/src/t_cose_util.h +++ b/src/t_cose_util.h @@ -317,7 +317,7 @@ struct q_useful_buf_c get_short_circuit_kid(void); /** - * \brief Map QCBOR decode error to COSE errors. + * \brief Map QCBOR decode error to t_cose errors. * * \param[in] qcbor_error The QCBOR error to map. * diff --git a/t_cose.xcodeproj/project.pbxproj b/t_cose.xcodeproj/project.pbxproj index 8761c988..7b991e1a 100644 --- a/t_cose.xcodeproj/project.pbxproj +++ b/t_cose.xcodeproj/project.pbxproj @@ -288,6 +288,27 @@ E78555872A5B573F00BA326A /* include */ = {isa = PBXFileReference; lastKnownFileType = folder; name = include; path = "../../openssl-1.1.1t/include"; sourceTree = ""; }; E79383162AFC00FB00C2DF49 /* test_messages.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = test_messages.c; path = data/test_messages.c; sourceTree = ""; }; E79383172AFC00FB00C2DF49 /* test_messages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = test_messages.h; path = data/test_messages.h; sourceTree = ""; }; + E793832D2B02A80B00C2DF49 /* aead_in_error.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = aead_in_error.diag; path = data/aead_in_error.diag; sourceTree = ""; }; + E793832E2B02A80B00C2DF49 /* cose_encrypt_a128cbc_a128kw.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_encrypt_a128cbc_a128kw.diag; path = data/cose_encrypt_a128cbc_a128kw.diag; sourceTree = ""; }; + E793832F2B02A80B00C2DF49 /* cose_encrypt_bad_iv.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_encrypt_bad_iv.diag; path = data/cose_encrypt_bad_iv.diag; sourceTree = ""; }; + E79383302B02A80B00C2DF49 /* tstr_ciphertext.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = tstr_ciphertext.diag; path = data/tstr_ciphertext.diag; sourceTree = ""; }; + E79383312B02A80B00C2DF49 /* cose_encrypt_wrong_rcpt_array.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_encrypt_wrong_rcpt_array.diag; path = data/cose_encrypt_wrong_rcpt_array.diag; sourceTree = ""; }; + E79383322B02A80B00C2DF49 /* cose_encrypt_wrong_extra.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_encrypt_wrong_extra.diag; path = data/cose_encrypt_wrong_extra.diag; sourceTree = ""; }; + E79383332B02A80C00C2DF49 /* cose_encrypt_crit.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_encrypt_crit.diag; path = data/cose_encrypt_crit.diag; sourceTree = ""; }; + E79383342B02A80C00C2DF49 /* unknown_symmetric_alg.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = unknown_symmetric_alg.diag; path = data/unknown_symmetric_alg.diag; sourceTree = ""; }; + E79383352B02A80C00C2DF49 /* cose_encrypt_p256_wrap_128.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_encrypt_p256_wrap_128.diag; path = data/cose_encrypt_p256_wrap_128.diag; sourceTree = ""; }; + E79383362B02A80C00C2DF49 /* hmac_error_header.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = hmac_error_header.diag; path = data/hmac_error_header.diag; sourceTree = ""; }; + E79383372B02A80C00C2DF49 /* cose_encrypt_a128ctr_a128kw.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_encrypt_a128ctr_a128kw.diag; path = data/cose_encrypt_a128ctr_a128kw.diag; sourceTree = ""; }; + E79383382B02A80C00C2DF49 /* cose_recipients_map_instead_of_array.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_recipients_map_instead_of_array.diag; path = data/cose_recipients_map_instead_of_array.diag; sourceTree = ""; }; + E79383392B02A80D00C2DF49 /* cose_encrypt_wrong_array.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_encrypt_wrong_array.diag; path = data/cose_encrypt_wrong_array.diag; sourceTree = ""; }; + E793833A2B02A80D00C2DF49 /* cose_encrypt_bad_alg.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_encrypt_bad_alg.diag; path = data/cose_encrypt_bad_alg.diag; sourceTree = ""; }; + E793833B2B02A80D00C2DF49 /* cose_encrypt_bad_hdrs.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_encrypt_bad_hdrs.diag; path = data/cose_encrypt_bad_hdrs.diag; sourceTree = ""; }; + E793833C2B02A80D00C2DF49 /* hmac_big_head.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = hmac_big_head.diag; path = data/hmac_big_head.diag; sourceTree = ""; }; + E793833D2B02A80D00C2DF49 /* no_tag.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = no_tag.diag; path = data/no_tag.diag; sourceTree = ""; }; + E793833E2B02A80D00C2DF49 /* cose_encrypt_junk_recipient.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = cose_encrypt_junk_recipient.diag; path = data/cose_encrypt_junk_recipient.diag; sourceTree = ""; }; + E793833F2B02A80E00C2DF49 /* unprot_headers_wrong_type.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = unprot_headers_wrong_type.diag; path = data/unprot_headers_wrong_type.diag; sourceTree = ""; }; + E79383402B02A80E00C2DF49 /* unknown_rcpt_alg.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = unknown_rcpt_alg.diag; path = data/unknown_rcpt_alg.diag; sourceTree = ""; }; + E79383412B02A80E00C2DF49 /* wrong_tag.diag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = wrong_tag.diag; path = data/wrong_tag.diag; sourceTree = ""; }; E7AE8848299BCCF80093B326 /* t_cose_sign_verify.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = t_cose_sign_verify.h; path = t_cose/t_cose_sign_verify.h; sourceTree = ""; }; E7AE8849299BCCF80093B326 /* t_cose_sign_sign.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = t_cose_sign_sign.h; path = t_cose/t_cose_sign_sign.h; sourceTree = ""; }; E7AE884A299BCCF80093B326 /* t_cose_sign1_sign.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = t_cose_sign1_sign.h; path = t_cose/t_cose_sign1_sign.h; sourceTree = ""; }; @@ -553,6 +574,34 @@ name = "OSSL Interface"; sourceTree = ""; }; + E793832C2B02A7DA00C2DF49 /* data */ = { + isa = PBXGroup; + children = ( + E793832D2B02A80B00C2DF49 /* aead_in_error.diag */, + E793833A2B02A80D00C2DF49 /* cose_encrypt_bad_alg.diag */, + E793833B2B02A80D00C2DF49 /* cose_encrypt_bad_hdrs.diag */, + E793832F2B02A80B00C2DF49 /* cose_encrypt_bad_iv.diag */, + E79383332B02A80C00C2DF49 /* cose_encrypt_crit.diag */, + E793833E2B02A80D00C2DF49 /* cose_encrypt_junk_recipient.diag */, + E79383352B02A80C00C2DF49 /* cose_encrypt_p256_wrap_128.diag */, + E793832E2B02A80B00C2DF49 /* cose_encrypt_a128cbc_a128kw.diag */, + E79383372B02A80C00C2DF49 /* cose_encrypt_a128ctr_a128kw.diag */, + E79383392B02A80D00C2DF49 /* cose_encrypt_wrong_array.diag */, + E79383322B02A80B00C2DF49 /* cose_encrypt_wrong_extra.diag */, + E79383312B02A80B00C2DF49 /* cose_encrypt_wrong_rcpt_array.diag */, + E79383382B02A80C00C2DF49 /* cose_recipients_map_instead_of_array.diag */, + E793833C2B02A80D00C2DF49 /* hmac_big_head.diag */, + E79383362B02A80C00C2DF49 /* hmac_error_header.diag */, + E793833D2B02A80D00C2DF49 /* no_tag.diag */, + E79383302B02A80B00C2DF49 /* tstr_ciphertext.diag */, + E79383402B02A80E00C2DF49 /* unknown_rcpt_alg.diag */, + E79383342B02A80C00C2DF49 /* unknown_symmetric_alg.diag */, + E793833F2B02A80E00C2DF49 /* unprot_headers_wrong_type.diag */, + E79383412B02A80E00C2DF49 /* wrong_tag.diag */, + ); + name = data; + sourceTree = ""; + }; E7AE88312999E95F0093B326 /* COSE_Sign */ = { isa = PBXGroup; children = ( @@ -878,6 +927,7 @@ E7F17371295D1EC700E5ADF3 /* t_cose_crypto_test.h */, E7AE889129AB72740093B326 /* t_cose_encrypt_decrypt_test.h */, E7AE889229AB72740093B326 /* t_cose_encrypt_decrypt_test.c */, + E793832C2B02A7DA00C2DF49 /* data */, ); path = test; sourceTree = ""; diff --git a/test/data/aead_in_error.diag b/test/data/aead_in_error.diag index b4fc088a..5ee69387 100644 --- a/test/data/aead_in_error.diag +++ b/test/data/aead_in_error.diag @@ -1,3 +1,4 @@ +/ AEAD integrity check will fail / 96( [ h'A10103', diff --git a/test/data/cose_encrypt_a128cbc_a128kw.diag b/test/data/cose_encrypt_a128cbc_a128kw.diag new file mode 100644 index 00000000..33dbfb9e --- /dev/null +++ b/test/data/cose_encrypt_a128cbc_a128kw.diag @@ -0,0 +1,18 @@ +/ Valid COSE_Encrypt with AES-CBC body and A128 KW recipient / +96( + [ + h'' / NOTE: The 'protected' header MUST be a zero-length byte string. /, + { + 1: -65531 / A128CBC /, + 5: h'8262A8D72040A5E09A314586395D5750' + }, + h'B60EC3C9A166D8EEFDAEA598FAB1CEBB7F0D5DDF2237F13A03A91364594983FE', + [ + [ + h'', + {1: -3}, + h'D21A60F7F67BA866F15BE27C983881AA47DF15AE6925A0D1' + ] + ] + ] +) diff --git a/test/data/cose_encrypt_a128ctr_a128kw.diag b/test/data/cose_encrypt_a128ctr_a128kw.diag new file mode 100644 index 00000000..d2eca7ca --- /dev/null +++ b/test/data/cose_encrypt_a128ctr_a128kw.diag @@ -0,0 +1,18 @@ +/ Valid COSE_Encrypt with AES-CTR body and A128 KW recipient / +96( + [ + h'' / NOTE: The 'protected' header MUST be a zero-length byte string. /, + { + 1: -65534 / A128CTR /, + 5: h'77D35242A191E9F9FD26104AB308564E' + }, + h'793A616A5617482BE76F17077858B148241591', + [ + [ + h'', + {1: -3}, + h'316ADA13003FE7C61AD4EA503500B285CACADE5107A8E280' + ] + ] + ] +) diff --git a/test/data/cose_encrypt_bad_alg.diag b/test/data/cose_encrypt_bad_alg.diag new file mode 100644 index 00000000..4d6582b0 --- /dev/null +++ b/test/data/cose_encrypt_bad_alg.diag @@ -0,0 +1,24 @@ +/ Alg ID in recipient is the wrong CBOR type / +96( + [ + h'A10140', + {5: h'02D1F7E6F26C43D4868D87CE'}, + h'256B748DEB647131C12A10AC261DA0628E420492A36F3DED8642B4B6FA1EB15DCEC80A0F', + [ + [ + h'A101381C', + {-1: + { + 1: 2, + -1: 1, + -2: h'E12C938B182258C9D447D41821715261AE99AD77D241943F4A12FF20DD3CE400', + -3: h'48B0588903365733B98D388C6136C04B7FFD1A770CD2611189EE84E9941A7E26' + }, + 4: h'6D65726961646F632E6272616E64796275636B406275636B6C616E642E6578616D706C65' + }, + h'508FAD30A1A95D1380B5167D032799C72477AB60258ABFB71C7AB603A4890EF44F1363ED9F569E85' + ] + ] + ] +) + diff --git a/test/data/cose_encrypt_bad_hdrs.diag b/test/data/cose_encrypt_bad_hdrs.diag new file mode 100644 index 00000000..ca44efd1 --- /dev/null +++ b/test/data/cose_encrypt_bad_hdrs.diag @@ -0,0 +1,24 @@ +/ Protected headers are wrong type, a tstr instead of a bstr / +96( + [ + "bad prot hdrs", + {5: h'02D1F7E6F26C43D4868D87CE'}, + h'256B748DEB647131C12A10AC261DA0628E420492A36F3DED8642B4B6FA1EB15DCEC80A0F', + [ + [ + h'A101381C', + {-1: + { + 1: 2, + -1: 1, + -2: h'E12C938B182258C9D447D41821715261AE99AD77D241943F4A12FF20DD3CE400', + -3: h'48B0588903365733B98D388C6136C04B7FFD1A770CD2611189EE84E9941A7E26' + }, + 4: h'6D65726961646F632E6272616E64796275636B406275636B6C616E642E6578616D706C65' + }, + h'508FAD30A1A95D1380B5167D032799C72477AB60258ABFB71C7AB603A4890EF44F1363ED9F569E85' + ] + ] + ] +) + diff --git a/test/data/cose_encrypt_bad_iv.diag b/test/data/cose_encrypt_bad_iv.diag new file mode 100644 index 00000000..37acba2b --- /dev/null +++ b/test/data/cose_encrypt_bad_iv.diag @@ -0,0 +1,24 @@ +/ IV is is a boolean, not a bstr / +96( + [ + h'A10103', + {5: true}, + h'256B748DEB647131C12A10AC261DA0628E420492A36F3DED8642B4B6FA1EB15DCEC80A0F', + [ + [ + h'A101381C', + {-1: + { + 1: 2, + -1: 1, + -2: h'E12C938B182258C9D447D41821715261AE99AD77D241943F4A12FF20DD3CE400', + -3: h'48B0588903365733B98D388C6136C04B7FFD1A770CD2611189EE84E9941A7E26' + }, + 4: h'6D65726961646F632E6272616E64796275636B406275636B6C616E642E6578616D706C65' + }, + h'508FAD30A1A95D1380B5167D032799C72477AB60258ABFB71C7AB603A4890EF44F1363ED9F569E85' + ] + ] + ] +) + diff --git a/test/data/cose_encrypt_crit.diag b/test/data/cose_encrypt_crit.diag new file mode 100644 index 00000000..26e10ca4 --- /dev/null +++ b/test/data/cose_encrypt_crit.diag @@ -0,0 +1,24 @@ +/ Has an unknow critical header / +96( + [ + h'A301031903e70002811903e7', + {5: h'02D1F7E6F26C43D4868D87CE'}, + h'256B748DEB647131C12A10AC261DA0628E420492A36F3DED8642B4B6FA1EB15DCEC80A0F', + [ + [ + h'A101381C', + {-1: + { + 1: 2, + -1: 1, + -2: h'E12C938B182258C9D447D41821715261AE99AD77D241943F4A12FF20DD3CE400', + -3: h'48B0588903365733B98D388C6136C04B7FFD1A770CD2611189EE84E9941A7E26' + }, + 4: h'6D65726961646F632E6272616E64796275636B406275636B6C616E642E6578616D706C65' + }, + h'508FAD30A1A95D1380B5167D032799C72477AB60258ABFB71C7AB603A4890EF44F1363ED9F569E85' + ] + ] + ] +) + diff --git a/test/data/cose_encrypt_junk_recipient.diag b/test/data/cose_encrypt_junk_recipient.diag index 7571f05c..8c53290d 100644 --- a/test/data/cose_encrypt_junk_recipient.diag +++ b/test/data/cose_encrypt_junk_recipient.diag @@ -1,3 +1,4 @@ +/ First item in a recipients array is a tstr, not an array with a recipient / 96( [ h'A10103', diff --git a/test/data/cose_encrypt_p256_wrap_128.diag b/test/data/cose_encrypt_p256_wrap_128.diag index 87839f8a..b559d15e 100644 --- a/test/data/cose_encrypt_p256_wrap_128.diag +++ b/test/data/cose_encrypt_p256_wrap_128.diag @@ -1,3 +1,4 @@ +/ Fully correct AES-GCM + ECDH on P256 NIST curve / 96( [ h'A10103', diff --git a/test/data/cose_encrypt_p256_wrap_aescbc.diag b/test/data/cose_encrypt_p256_wrap_aescbc.diag deleted file mode 100644 index 069a9fd2..00000000 --- a/test/data/cose_encrypt_p256_wrap_aescbc.diag +++ /dev/null @@ -1,12 +0,0 @@ -96([ - h'' / NOTE: The 'protected' header MUST be a zero-length byte string. /, - {1: -65531 / A128CBC /, 5: h'8262A8D72040A5E09A314586395D5750'}, - h'B60EC3C9A166D8EEFDAEA598FAB1CEBB7F0D5DDF2237F13A03A91364594983FE', - [ - [ - h'', - {1: -3}, - h'D21A60F7F67BA866F15BE27C983881AA47DF15AE6925A0D1' - ] - ] -]) \ No newline at end of file diff --git a/test/data/cose_encrypt_p256_wrap_aesctr.diag b/test/data/cose_encrypt_p256_wrap_aesctr.diag deleted file mode 100644 index 13488748..00000000 --- a/test/data/cose_encrypt_p256_wrap_aesctr.diag +++ /dev/null @@ -1,12 +0,0 @@ -96([ - h'' / NOTE: The 'protected' header MUST be a zero-length byte string. /, - {1: -65534 / A128CTR /, 5: h'77D35242A191E9F9FD26104AB308564E'}, - h'793A616A5617482BE76F17077858B148241591', - [ - [ - h'', - {1: -3}, - h'316ADA13003FE7C61AD4EA503500B285CACADE5107A8E280' - ] - ] -]) \ No newline at end of file diff --git a/test/data/cose_encrypt_wrong_array.diag b/test/data/cose_encrypt_wrong_array.diag new file mode 100644 index 00000000..f8dac1c9 --- /dev/null +++ b/test/data/cose_encrypt_wrong_array.diag @@ -0,0 +1,24 @@ +/ COSE_Encrypt where array of 4 is replaced by map of 2 / +96( + { + h'A10103': + {5: h'02D1F7E6F26C43D4868D87CE'}, + h'256B748DEB647131C12A10AC261DA0628E420492A36F3DED8642B4B6FA1EB15DCEC80A0F': + [ + [ + h'A101381C', + {-1: + { + 1: 2, + -1: 1, + -2: h'E12C938B182258C9D447D41821715261AE99AD77D241943F4A12FF20DD3CE400', + -3: h'48B0588903365733B98D388C6136C04B7FFD1A770CD2611189EE84E9941A7E26' + }, + 4: h'6D65726961646F632E6272616E64796275636B406275636B6C616E642E6578616D706C65' + }, + h'508FAD30A1A95D1380B5167D032799C72477AB60258ABFB71C7AB603A4890EF44F1363ED9F569E85' + ] + ] + } +) + diff --git a/test/data/cose_encrypt_wrong_extra.diag b/test/data/cose_encrypt_wrong_extra.diag new file mode 100644 index 00000000..ea954ed4 --- /dev/null +++ b/test/data/cose_encrypt_wrong_extra.diag @@ -0,0 +1,25 @@ +/ Multiple recipient COSE_Encrypt with extra items at end of array of 4 / +96( + [ + h'A10103', + {5: h'02D1F7E6F26C43D4868D87CE'}, + h'256B748DEB647131C12A10AC261DA0628E420492A36F3DED8642B4B6FA1EB15DCEC80A0F', + [ + [ + h'A101381C', + {-1: + { + 1: 2, + -1: 1, + -2: h'E12C938B182258C9D447D41821715261AE99AD77D241943F4A12FF20DD3CE400', + -3: h'48B0588903365733B98D388C6136C04B7FFD1A770CD2611189EE84E9941A7E26' + }, + 4: h'6D65726961646F632E6272616E64796275636B406275636B6C616E642E6578616D706C65' + }, + h'508FAD30A1A95D1380B5167D032799C72477AB60258ABFB71C7AB603A4890EF44F1363ED9F569E85' + ] + ], + 3.1459 + ] +) + diff --git a/test/data/cose_encrypt_wrong_rcpt_array.diag b/test/data/cose_encrypt_wrong_rcpt_array.diag new file mode 100644 index 00000000..58f22149 --- /dev/null +++ b/test/data/cose_encrypt_wrong_rcpt_array.diag @@ -0,0 +1,24 @@ +/ COSE_Encrypt with recipient array incorrectly replaced by a map / +96( + [ + h'A10103', + {5: h'02D1F7E6F26C43D4868D87CE'}, + h'256B748DEB647131C12A10AC261DA0628E420492A36F3DED8642B4B6FA1EB15DCEC80A0F', + [ + { + 100: h'A101381C', + 101: {-1: + { + 1: 2, + -1: 1, + -2: h'E12C938B182258C9D447D41821715261AE99AD77D241943F4A12FF20DD3CE400', + -3: h'48B0588903365733B98D388C6136C04B7FFD1A770CD2611189EE84E9941A7E26' + }, + 4: h'6D65726961646F632E6272616E64796275636B406275636B6C616E642E6578616D706C65' + }, + 102: h'508FAD30A1A95D1380B5167D032799C72477AB60258ABFB71C7AB603A4890EF44F1363ED9F569E85' + } + ] + ] +) + diff --git a/test/data/cose_recipients_map_instead_of_array.diag b/test/data/cose_recipients_map_instead_of_array.diag index c8e948e8..b1801936 100644 --- a/test/data/cose_recipients_map_instead_of_array.diag +++ b/test/data/cose_recipients_map_instead_of_array.diag @@ -1,3 +1,4 @@ +/ COSE_Encrypt with recipients a map rather than an array / 96( [ h'A10103', diff --git a/test/data/hmac_big_head.diag b/test/data/hmac_big_head.diag index cea62378..a32f7396 100644 --- a/test/data/hmac_big_head.diag +++ b/test/data/hmac_big_head.diag @@ -1,3 +1,4 @@ +/ Correct COSE_HMAC with a lot of headers of different types / 17( [ h'A10105', diff --git a/test/data/hmac_error_header.diag b/test/data/hmac_error_header.diag index f61113de..98100c3e 100644 --- a/test/data/hmac_error_header.diag +++ b/test/data/hmac_error_header.diag @@ -1,3 +1,4 @@ +/ COSE_MAC0 with bad unprotected headers -- param label is float / 17( [ h'A10105', diff --git a/test/data/make_test_messages.sh b/test/data/make_test_messages.sh index 62879fd3..b6e932b5 100755 --- a/test/data/make_test_messages.sh +++ b/test/data/make_test_messages.sh @@ -1,4 +1,6 @@ #!/bin/bash +# Copyright (c) 2023, Laurence Lundblade. All rights reserved. + rm -f test_messages.[ch] @@ -13,6 +15,13 @@ for i in *.diag; do j=${i%.*} diag2cbor.rb $i > $j + fgrep -q '***' $j + st=$? + if [ $st == 0 ]; + then + echo "Error processing file \"$j\"" + exit + fi xxd -c 8 -i $j > $j.tmp size=`grep 'unsigned int' $j.tmp | sed 's/^.*=\ \([0-9]*\);/\1/'` @@ -20,6 +29,8 @@ do sed 's/].*/\];/' | \ sed "s/\[\]/\[$size\]/" >> test_messages.h cat $j.tmp | sed 's/^unsigned/const unsigned/' >> test_messages.c + echo >> test_messages.c + echo >> test_messages.h rm $j $j.tmp diff --git a/test/data/no_tag.diag b/test/data/no_tag.diag new file mode 100644 index 00000000..9a55b930 --- /dev/null +++ b/test/data/no_tag.diag @@ -0,0 +1,22 @@ + / Valid COSE_encrypt with no CBOR tag number / + [ + h'A10103', + {5: h'02D1F7E6F26C43D4868D87CE'}, + h'256B748DEB647131C12A10AC261DA0628E420492A36F3DED8642B4B6FA1EB15DCEC80A0F', + [ + [ + h'A101381C', + {-1: + { + 1: 2, + -1: 1, + -2: h'E12C938B182258C9D447D41821715261AE99AD77D241943F4A12FF20DD3CE400', + -3: h'48B0588903365733B98D388C6136C04B7FFD1A770CD2611189EE84E9941A7E26' + }, + 4: h'6D65726961646F632E6272616E64796275636B406275636B6C616E642E6578616D706C65' + }, + h'508FAD30A1A95D1380B5167D032799C72477AB60258ABFB71C7AB603A4890EF44F1363ED9F569E85' + ] + ] + ] + diff --git a/test/data/test_messages.c b/test/data/test_messages.c index e7b811bc..8f4e2e91 100644 --- a/test/data/test_messages.c +++ b/test/data/test_messages.c @@ -31,6 +31,169 @@ const unsigned char aead_in_error[] = { 0x85 }; const unsigned int aead_in_error_len = 225; + +const unsigned char cose_encrypt_a128cbc_a128kw[] = { + 0xd8, 0x60, 0x84, 0x40, 0xa2, 0x01, 0x39, 0xff, + 0xfa, 0x05, 0x50, 0x82, 0x62, 0xa8, 0xd7, 0x20, + 0x40, 0xa5, 0xe0, 0x9a, 0x31, 0x45, 0x86, 0x39, + 0x5d, 0x57, 0x50, 0x58, 0x20, 0xb6, 0x0e, 0xc3, + 0xc9, 0xa1, 0x66, 0xd8, 0xee, 0xfd, 0xae, 0xa5, + 0x98, 0xfa, 0xb1, 0xce, 0xbb, 0x7f, 0x0d, 0x5d, + 0xdf, 0x22, 0x37, 0xf1, 0x3a, 0x03, 0xa9, 0x13, + 0x64, 0x59, 0x49, 0x83, 0xfe, 0x81, 0x83, 0x40, + 0xa1, 0x01, 0x22, 0x58, 0x18, 0xd2, 0x1a, 0x60, + 0xf7, 0xf6, 0x7b, 0xa8, 0x66, 0xf1, 0x5b, 0xe2, + 0x7c, 0x98, 0x38, 0x81, 0xaa, 0x47, 0xdf, 0x15, + 0xae, 0x69, 0x25, 0xa0, 0xd1 +}; +const unsigned int cose_encrypt_a128cbc_a128kw_len = 93; + +const unsigned char cose_encrypt_a128ctr_a128kw[] = { + 0xd8, 0x60, 0x84, 0x40, 0xa2, 0x01, 0x39, 0xff, + 0xfd, 0x05, 0x50, 0x77, 0xd3, 0x52, 0x42, 0xa1, + 0x91, 0xe9, 0xf9, 0xfd, 0x26, 0x10, 0x4a, 0xb3, + 0x08, 0x56, 0x4e, 0x53, 0x79, 0x3a, 0x61, 0x6a, + 0x56, 0x17, 0x48, 0x2b, 0xe7, 0x6f, 0x17, 0x07, + 0x78, 0x58, 0xb1, 0x48, 0x24, 0x15, 0x91, 0x81, + 0x83, 0x40, 0xa1, 0x01, 0x22, 0x58, 0x18, 0x31, + 0x6a, 0xda, 0x13, 0x00, 0x3f, 0xe7, 0xc6, 0x1a, + 0xd4, 0xea, 0x50, 0x35, 0x00, 0xb2, 0x85, 0xca, + 0xca, 0xde, 0x51, 0x07, 0xa8, 0xe2, 0x80 +}; +const unsigned int cose_encrypt_a128ctr_a128kw_len = 79; + +const unsigned char cose_encrypt_bad_alg[] = { + 0xd8, 0x60, 0x84, 0x43, 0xa1, 0x01, 0x40, 0xa1, + 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, + 0x43, 0xd4, 0x86, 0x8d, 0x87, 0xce, 0x58, 0x24, + 0x25, 0x6b, 0x74, 0x8d, 0xeb, 0x64, 0x71, 0x31, + 0xc1, 0x2a, 0x10, 0xac, 0x26, 0x1d, 0xa0, 0x62, + 0x8e, 0x42, 0x04, 0x92, 0xa3, 0x6f, 0x3d, 0xed, + 0x86, 0x42, 0xb4, 0xb6, 0xfa, 0x1e, 0xb1, 0x5d, + 0xce, 0xc8, 0x0a, 0x0f, 0x81, 0x83, 0x44, 0xa1, + 0x01, 0x38, 0x1c, 0xa2, 0x20, 0xa4, 0x01, 0x02, + 0x20, 0x01, 0x21, 0x58, 0x20, 0xe1, 0x2c, 0x93, + 0x8b, 0x18, 0x22, 0x58, 0xc9, 0xd4, 0x47, 0xd4, + 0x18, 0x21, 0x71, 0x52, 0x61, 0xae, 0x99, 0xad, + 0x77, 0xd2, 0x41, 0x94, 0x3f, 0x4a, 0x12, 0xff, + 0x20, 0xdd, 0x3c, 0xe4, 0x00, 0x22, 0x58, 0x20, + 0x48, 0xb0, 0x58, 0x89, 0x03, 0x36, 0x57, 0x33, + 0xb9, 0x8d, 0x38, 0x8c, 0x61, 0x36, 0xc0, 0x4b, + 0x7f, 0xfd, 0x1a, 0x77, 0x0c, 0xd2, 0x61, 0x11, + 0x89, 0xee, 0x84, 0xe9, 0x94, 0x1a, 0x7e, 0x26, + 0x04, 0x58, 0x24, 0x6d, 0x65, 0x72, 0x69, 0x61, + 0x64, 0x6f, 0x63, 0x2e, 0x62, 0x72, 0x61, 0x6e, + 0x64, 0x79, 0x62, 0x75, 0x63, 0x6b, 0x40, 0x62, + 0x75, 0x63, 0x6b, 0x6c, 0x61, 0x6e, 0x64, 0x2e, + 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x58, + 0x28, 0x50, 0x8f, 0xad, 0x30, 0xa1, 0xa9, 0x5d, + 0x13, 0x80, 0xb5, 0x16, 0x7d, 0x03, 0x27, 0x99, + 0xc7, 0x24, 0x77, 0xab, 0x60, 0x25, 0x8a, 0xbf, + 0xb7, 0x1c, 0x7a, 0xb6, 0x03, 0xa4, 0x89, 0x0e, + 0xf4, 0x4f, 0x13, 0x63, 0xed, 0x9f, 0x56, 0x9e, + 0x85 +}; +const unsigned int cose_encrypt_bad_alg_len = 225; + +const unsigned char cose_encrypt_bad_hdrs[] = { + 0xd8, 0x60, 0x84, 0x6d, 0x62, 0x61, 0x64, 0x20, + 0x70, 0x72, 0x6f, 0x74, 0x20, 0x68, 0x64, 0x72, + 0x73, 0xa1, 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, + 0xf2, 0x6c, 0x43, 0xd4, 0x86, 0x8d, 0x87, 0xce, + 0x58, 0x24, 0x25, 0x6b, 0x74, 0x8d, 0xeb, 0x64, + 0x71, 0x31, 0xc1, 0x2a, 0x10, 0xac, 0x26, 0x1d, + 0xa0, 0x62, 0x8e, 0x42, 0x04, 0x92, 0xa3, 0x6f, + 0x3d, 0xed, 0x86, 0x42, 0xb4, 0xb6, 0xfa, 0x1e, + 0xb1, 0x5d, 0xce, 0xc8, 0x0a, 0x0f, 0x81, 0x83, + 0x44, 0xa1, 0x01, 0x38, 0x1c, 0xa2, 0x20, 0xa4, + 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0xe1, + 0x2c, 0x93, 0x8b, 0x18, 0x22, 0x58, 0xc9, 0xd4, + 0x47, 0xd4, 0x18, 0x21, 0x71, 0x52, 0x61, 0xae, + 0x99, 0xad, 0x77, 0xd2, 0x41, 0x94, 0x3f, 0x4a, + 0x12, 0xff, 0x20, 0xdd, 0x3c, 0xe4, 0x00, 0x22, + 0x58, 0x20, 0x48, 0xb0, 0x58, 0x89, 0x03, 0x36, + 0x57, 0x33, 0xb9, 0x8d, 0x38, 0x8c, 0x61, 0x36, + 0xc0, 0x4b, 0x7f, 0xfd, 0x1a, 0x77, 0x0c, 0xd2, + 0x61, 0x11, 0x89, 0xee, 0x84, 0xe9, 0x94, 0x1a, + 0x7e, 0x26, 0x04, 0x58, 0x24, 0x6d, 0x65, 0x72, + 0x69, 0x61, 0x64, 0x6f, 0x63, 0x2e, 0x62, 0x72, + 0x61, 0x6e, 0x64, 0x79, 0x62, 0x75, 0x63, 0x6b, + 0x40, 0x62, 0x75, 0x63, 0x6b, 0x6c, 0x61, 0x6e, + 0x64, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, + 0x65, 0x58, 0x28, 0x50, 0x8f, 0xad, 0x30, 0xa1, + 0xa9, 0x5d, 0x13, 0x80, 0xb5, 0x16, 0x7d, 0x03, + 0x27, 0x99, 0xc7, 0x24, 0x77, 0xab, 0x60, 0x25, + 0x8a, 0xbf, 0xb7, 0x1c, 0x7a, 0xb6, 0x03, 0xa4, + 0x89, 0x0e, 0xf4, 0x4f, 0x13, 0x63, 0xed, 0x9f, + 0x56, 0x9e, 0x85 +}; +const unsigned int cose_encrypt_bad_hdrs_len = 235; + +const unsigned char cose_encrypt_bad_iv[] = { + 0xd8, 0x60, 0x84, 0x43, 0xa1, 0x01, 0x03, 0xa1, + 0x05, 0xf5, 0x58, 0x24, 0x25, 0x6b, 0x74, 0x8d, + 0xeb, 0x64, 0x71, 0x31, 0xc1, 0x2a, 0x10, 0xac, + 0x26, 0x1d, 0xa0, 0x62, 0x8e, 0x42, 0x04, 0x92, + 0xa3, 0x6f, 0x3d, 0xed, 0x86, 0x42, 0xb4, 0xb6, + 0xfa, 0x1e, 0xb1, 0x5d, 0xce, 0xc8, 0x0a, 0x0f, + 0x81, 0x83, 0x44, 0xa1, 0x01, 0x38, 0x1c, 0xa2, + 0x20, 0xa4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, + 0x20, 0xe1, 0x2c, 0x93, 0x8b, 0x18, 0x22, 0x58, + 0xc9, 0xd4, 0x47, 0xd4, 0x18, 0x21, 0x71, 0x52, + 0x61, 0xae, 0x99, 0xad, 0x77, 0xd2, 0x41, 0x94, + 0x3f, 0x4a, 0x12, 0xff, 0x20, 0xdd, 0x3c, 0xe4, + 0x00, 0x22, 0x58, 0x20, 0x48, 0xb0, 0x58, 0x89, + 0x03, 0x36, 0x57, 0x33, 0xb9, 0x8d, 0x38, 0x8c, + 0x61, 0x36, 0xc0, 0x4b, 0x7f, 0xfd, 0x1a, 0x77, + 0x0c, 0xd2, 0x61, 0x11, 0x89, 0xee, 0x84, 0xe9, + 0x94, 0x1a, 0x7e, 0x26, 0x04, 0x58, 0x24, 0x6d, + 0x65, 0x72, 0x69, 0x61, 0x64, 0x6f, 0x63, 0x2e, + 0x62, 0x72, 0x61, 0x6e, 0x64, 0x79, 0x62, 0x75, + 0x63, 0x6b, 0x40, 0x62, 0x75, 0x63, 0x6b, 0x6c, + 0x61, 0x6e, 0x64, 0x2e, 0x65, 0x78, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x58, 0x28, 0x50, 0x8f, 0xad, + 0x30, 0xa1, 0xa9, 0x5d, 0x13, 0x80, 0xb5, 0x16, + 0x7d, 0x03, 0x27, 0x99, 0xc7, 0x24, 0x77, 0xab, + 0x60, 0x25, 0x8a, 0xbf, 0xb7, 0x1c, 0x7a, 0xb6, + 0x03, 0xa4, 0x89, 0x0e, 0xf4, 0x4f, 0x13, 0x63, + 0xed, 0x9f, 0x56, 0x9e, 0x85 +}; +const unsigned int cose_encrypt_bad_iv_len = 213; + +const unsigned char cose_encrypt_crit[] = { + 0xd8, 0x60, 0x84, 0x4c, 0xa3, 0x01, 0x03, 0x19, + 0x03, 0xe7, 0x00, 0x02, 0x81, 0x19, 0x03, 0xe7, + 0xa1, 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, + 0x6c, 0x43, 0xd4, 0x86, 0x8d, 0x87, 0xce, 0x58, + 0x24, 0x25, 0x6b, 0x74, 0x8d, 0xeb, 0x64, 0x71, + 0x31, 0xc1, 0x2a, 0x10, 0xac, 0x26, 0x1d, 0xa0, + 0x62, 0x8e, 0x42, 0x04, 0x92, 0xa3, 0x6f, 0x3d, + 0xed, 0x86, 0x42, 0xb4, 0xb6, 0xfa, 0x1e, 0xb1, + 0x5d, 0xce, 0xc8, 0x0a, 0x0f, 0x81, 0x83, 0x44, + 0xa1, 0x01, 0x38, 0x1c, 0xa2, 0x20, 0xa4, 0x01, + 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0xe1, 0x2c, + 0x93, 0x8b, 0x18, 0x22, 0x58, 0xc9, 0xd4, 0x47, + 0xd4, 0x18, 0x21, 0x71, 0x52, 0x61, 0xae, 0x99, + 0xad, 0x77, 0xd2, 0x41, 0x94, 0x3f, 0x4a, 0x12, + 0xff, 0x20, 0xdd, 0x3c, 0xe4, 0x00, 0x22, 0x58, + 0x20, 0x48, 0xb0, 0x58, 0x89, 0x03, 0x36, 0x57, + 0x33, 0xb9, 0x8d, 0x38, 0x8c, 0x61, 0x36, 0xc0, + 0x4b, 0x7f, 0xfd, 0x1a, 0x77, 0x0c, 0xd2, 0x61, + 0x11, 0x89, 0xee, 0x84, 0xe9, 0x94, 0x1a, 0x7e, + 0x26, 0x04, 0x58, 0x24, 0x6d, 0x65, 0x72, 0x69, + 0x61, 0x64, 0x6f, 0x63, 0x2e, 0x62, 0x72, 0x61, + 0x6e, 0x64, 0x79, 0x62, 0x75, 0x63, 0x6b, 0x40, + 0x62, 0x75, 0x63, 0x6b, 0x6c, 0x61, 0x6e, 0x64, + 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, + 0x58, 0x28, 0x50, 0x8f, 0xad, 0x30, 0xa1, 0xa9, + 0x5d, 0x13, 0x80, 0xb5, 0x16, 0x7d, 0x03, 0x27, + 0x99, 0xc7, 0x24, 0x77, 0xab, 0x60, 0x25, 0x8a, + 0xbf, 0xb7, 0x1c, 0x7a, 0xb6, 0x03, 0xa4, 0x89, + 0x0e, 0xf4, 0x4f, 0x13, 0x63, 0xed, 0x9f, 0x56, + 0x9e, 0x85 +}; +const unsigned int cose_encrypt_crit_len = 234; + const unsigned char cose_encrypt_junk_recipient[] = { 0xd8, 0x60, 0x84, 0x43, 0xa1, 0x01, 0x03, 0xa1, 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, @@ -66,6 +229,7 @@ const unsigned char cose_encrypt_junk_recipient[] = { 0x56, 0x9e, 0x85 }; const unsigned int cose_encrypt_junk_recipient_len = 251; + const unsigned char cose_encrypt_p256_wrap_128[] = { 0xd8, 0x60, 0x84, 0x43, 0xa1, 0x01, 0x03, 0xa1, 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, @@ -98,34 +262,107 @@ const unsigned char cose_encrypt_p256_wrap_128[] = { 0x85 }; const unsigned int cose_encrypt_p256_wrap_128_len = 225; -const unsigned char cose_encrypt_p256_wrap_aescbc[] = { - 0xd8, 0x60, 0x84, 0x40, 0xa2, 0x01, 0x39, 0xff, - 0xfa, 0x05, 0x50, 0x82, 0x62, 0xa8, 0xd7, 0x20, - 0x40, 0xa5, 0xe0, 0x9a, 0x31, 0x45, 0x86, 0x39, - 0x5d, 0x57, 0x50, 0x58, 0x20, 0xb6, 0x0e, 0xc3, - 0xc9, 0xa1, 0x66, 0xd8, 0xee, 0xfd, 0xae, 0xa5, - 0x98, 0xfa, 0xb1, 0xce, 0xbb, 0x7f, 0x0d, 0x5d, - 0xdf, 0x22, 0x37, 0xf1, 0x3a, 0x03, 0xa9, 0x13, - 0x64, 0x59, 0x49, 0x83, 0xfe, 0x81, 0x83, 0x40, - 0xa1, 0x01, 0x22, 0x58, 0x18, 0xd2, 0x1a, 0x60, - 0xf7, 0xf6, 0x7b, 0xa8, 0x66, 0xf1, 0x5b, 0xe2, - 0x7c, 0x98, 0x38, 0x81, 0xaa, 0x47, 0xdf, 0x15, - 0xae, 0x69, 0x25, 0xa0, 0xd1 + +const unsigned char cose_encrypt_wrong_array[] = { + 0xd8, 0x60, 0xa2, 0x43, 0xa1, 0x01, 0x03, 0xa1, + 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, + 0x43, 0xd4, 0x86, 0x8d, 0x87, 0xce, 0x58, 0x24, + 0x25, 0x6b, 0x74, 0x8d, 0xeb, 0x64, 0x71, 0x31, + 0xc1, 0x2a, 0x10, 0xac, 0x26, 0x1d, 0xa0, 0x62, + 0x8e, 0x42, 0x04, 0x92, 0xa3, 0x6f, 0x3d, 0xed, + 0x86, 0x42, 0xb4, 0xb6, 0xfa, 0x1e, 0xb1, 0x5d, + 0xce, 0xc8, 0x0a, 0x0f, 0x81, 0x83, 0x44, 0xa1, + 0x01, 0x38, 0x1c, 0xa2, 0x20, 0xa4, 0x01, 0x02, + 0x20, 0x01, 0x21, 0x58, 0x20, 0xe1, 0x2c, 0x93, + 0x8b, 0x18, 0x22, 0x58, 0xc9, 0xd4, 0x47, 0xd4, + 0x18, 0x21, 0x71, 0x52, 0x61, 0xae, 0x99, 0xad, + 0x77, 0xd2, 0x41, 0x94, 0x3f, 0x4a, 0x12, 0xff, + 0x20, 0xdd, 0x3c, 0xe4, 0x00, 0x22, 0x58, 0x20, + 0x48, 0xb0, 0x58, 0x89, 0x03, 0x36, 0x57, 0x33, + 0xb9, 0x8d, 0x38, 0x8c, 0x61, 0x36, 0xc0, 0x4b, + 0x7f, 0xfd, 0x1a, 0x77, 0x0c, 0xd2, 0x61, 0x11, + 0x89, 0xee, 0x84, 0xe9, 0x94, 0x1a, 0x7e, 0x26, + 0x04, 0x58, 0x24, 0x6d, 0x65, 0x72, 0x69, 0x61, + 0x64, 0x6f, 0x63, 0x2e, 0x62, 0x72, 0x61, 0x6e, + 0x64, 0x79, 0x62, 0x75, 0x63, 0x6b, 0x40, 0x62, + 0x75, 0x63, 0x6b, 0x6c, 0x61, 0x6e, 0x64, 0x2e, + 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x58, + 0x28, 0x50, 0x8f, 0xad, 0x30, 0xa1, 0xa9, 0x5d, + 0x13, 0x80, 0xb5, 0x16, 0x7d, 0x03, 0x27, 0x99, + 0xc7, 0x24, 0x77, 0xab, 0x60, 0x25, 0x8a, 0xbf, + 0xb7, 0x1c, 0x7a, 0xb6, 0x03, 0xa4, 0x89, 0x0e, + 0xf4, 0x4f, 0x13, 0x63, 0xed, 0x9f, 0x56, 0x9e, + 0x85 }; -const unsigned int cose_encrypt_p256_wrap_aescbc_len = 93; -const unsigned char cose_encrypt_p256_wrap_aesctr[] = { - 0xd8, 0x60, 0x84, 0x40, 0xa2, 0x01, 0x39, 0xff, - 0xfd, 0x05, 0x50, 0x77, 0xd3, 0x52, 0x42, 0xa1, - 0x91, 0xe9, 0xf9, 0xfd, 0x26, 0x10, 0x4a, 0xb3, - 0x08, 0x56, 0x4e, 0x53, 0x79, 0x3a, 0x61, 0x6a, - 0x56, 0x17, 0x48, 0x2b, 0xe7, 0x6f, 0x17, 0x07, - 0x78, 0x58, 0xb1, 0x48, 0x24, 0x15, 0x91, 0x81, - 0x83, 0x40, 0xa1, 0x01, 0x22, 0x58, 0x18, 0x31, - 0x6a, 0xda, 0x13, 0x00, 0x3f, 0xe7, 0xc6, 0x1a, - 0xd4, 0xea, 0x50, 0x35, 0x00, 0xb2, 0x85, 0xca, - 0xca, 0xde, 0x51, 0x07, 0xa8, 0xe2, 0x80 +const unsigned int cose_encrypt_wrong_array_len = 225; + +const unsigned char cose_encrypt_wrong_extra[] = { + 0xd8, 0x60, 0x85, 0x43, 0xa1, 0x01, 0x03, 0xa1, + 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, + 0x43, 0xd4, 0x86, 0x8d, 0x87, 0xce, 0x58, 0x24, + 0x25, 0x6b, 0x74, 0x8d, 0xeb, 0x64, 0x71, 0x31, + 0xc1, 0x2a, 0x10, 0xac, 0x26, 0x1d, 0xa0, 0x62, + 0x8e, 0x42, 0x04, 0x92, 0xa3, 0x6f, 0x3d, 0xed, + 0x86, 0x42, 0xb4, 0xb6, 0xfa, 0x1e, 0xb1, 0x5d, + 0xce, 0xc8, 0x0a, 0x0f, 0x81, 0x83, 0x44, 0xa1, + 0x01, 0x38, 0x1c, 0xa2, 0x20, 0xa4, 0x01, 0x02, + 0x20, 0x01, 0x21, 0x58, 0x20, 0xe1, 0x2c, 0x93, + 0x8b, 0x18, 0x22, 0x58, 0xc9, 0xd4, 0x47, 0xd4, + 0x18, 0x21, 0x71, 0x52, 0x61, 0xae, 0x99, 0xad, + 0x77, 0xd2, 0x41, 0x94, 0x3f, 0x4a, 0x12, 0xff, + 0x20, 0xdd, 0x3c, 0xe4, 0x00, 0x22, 0x58, 0x20, + 0x48, 0xb0, 0x58, 0x89, 0x03, 0x36, 0x57, 0x33, + 0xb9, 0x8d, 0x38, 0x8c, 0x61, 0x36, 0xc0, 0x4b, + 0x7f, 0xfd, 0x1a, 0x77, 0x0c, 0xd2, 0x61, 0x11, + 0x89, 0xee, 0x84, 0xe9, 0x94, 0x1a, 0x7e, 0x26, + 0x04, 0x58, 0x24, 0x6d, 0x65, 0x72, 0x69, 0x61, + 0x64, 0x6f, 0x63, 0x2e, 0x62, 0x72, 0x61, 0x6e, + 0x64, 0x79, 0x62, 0x75, 0x63, 0x6b, 0x40, 0x62, + 0x75, 0x63, 0x6b, 0x6c, 0x61, 0x6e, 0x64, 0x2e, + 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x58, + 0x28, 0x50, 0x8f, 0xad, 0x30, 0xa1, 0xa9, 0x5d, + 0x13, 0x80, 0xb5, 0x16, 0x7d, 0x03, 0x27, 0x99, + 0xc7, 0x24, 0x77, 0xab, 0x60, 0x25, 0x8a, 0xbf, + 0xb7, 0x1c, 0x7a, 0xb6, 0x03, 0xa4, 0x89, 0x0e, + 0xf4, 0x4f, 0x13, 0x63, 0xed, 0x9f, 0x56, 0x9e, + 0x85, 0xfb, 0x40, 0x09, 0x2a, 0xcd, 0x9e, 0x83, + 0xe4, 0x26 }; -const unsigned int cose_encrypt_p256_wrap_aesctr_len = 79; +const unsigned int cose_encrypt_wrong_extra_len = 234; + +const unsigned char cose_encrypt_wrong_rcpt_array[] = { + 0xd8, 0x60, 0x84, 0x43, 0xa1, 0x01, 0x03, 0xa1, + 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, + 0x43, 0xd4, 0x86, 0x8d, 0x87, 0xce, 0x58, 0x24, + 0x25, 0x6b, 0x74, 0x8d, 0xeb, 0x64, 0x71, 0x31, + 0xc1, 0x2a, 0x10, 0xac, 0x26, 0x1d, 0xa0, 0x62, + 0x8e, 0x42, 0x04, 0x92, 0xa3, 0x6f, 0x3d, 0xed, + 0x86, 0x42, 0xb4, 0xb6, 0xfa, 0x1e, 0xb1, 0x5d, + 0xce, 0xc8, 0x0a, 0x0f, 0x81, 0xa3, 0x18, 0x64, + 0x44, 0xa1, 0x01, 0x38, 0x1c, 0x18, 0x65, 0xa2, + 0x20, 0xa4, 0x01, 0x02, 0x20, 0x01, 0x21, 0x58, + 0x20, 0xe1, 0x2c, 0x93, 0x8b, 0x18, 0x22, 0x58, + 0xc9, 0xd4, 0x47, 0xd4, 0x18, 0x21, 0x71, 0x52, + 0x61, 0xae, 0x99, 0xad, 0x77, 0xd2, 0x41, 0x94, + 0x3f, 0x4a, 0x12, 0xff, 0x20, 0xdd, 0x3c, 0xe4, + 0x00, 0x22, 0x58, 0x20, 0x48, 0xb0, 0x58, 0x89, + 0x03, 0x36, 0x57, 0x33, 0xb9, 0x8d, 0x38, 0x8c, + 0x61, 0x36, 0xc0, 0x4b, 0x7f, 0xfd, 0x1a, 0x77, + 0x0c, 0xd2, 0x61, 0x11, 0x89, 0xee, 0x84, 0xe9, + 0x94, 0x1a, 0x7e, 0x26, 0x04, 0x58, 0x24, 0x6d, + 0x65, 0x72, 0x69, 0x61, 0x64, 0x6f, 0x63, 0x2e, + 0x62, 0x72, 0x61, 0x6e, 0x64, 0x79, 0x62, 0x75, + 0x63, 0x6b, 0x40, 0x62, 0x75, 0x63, 0x6b, 0x6c, + 0x61, 0x6e, 0x64, 0x2e, 0x65, 0x78, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x18, 0x66, 0x58, 0x28, 0x50, + 0x8f, 0xad, 0x30, 0xa1, 0xa9, 0x5d, 0x13, 0x80, + 0xb5, 0x16, 0x7d, 0x03, 0x27, 0x99, 0xc7, 0x24, + 0x77, 0xab, 0x60, 0x25, 0x8a, 0xbf, 0xb7, 0x1c, + 0x7a, 0xb6, 0x03, 0xa4, 0x89, 0x0e, 0xf4, 0x4f, + 0x13, 0x63, 0xed, 0x9f, 0x56, 0x9e, 0x85 +}; +const unsigned int cose_encrypt_wrong_rcpt_array_len = 231; + const unsigned char cose_recipients_map_instead_of_array[] = { 0xd8, 0x60, 0x84, 0x43, 0xa1, 0x01, 0x03, 0xa1, 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, @@ -158,6 +395,7 @@ const unsigned char cose_recipients_map_instead_of_array[] = { 0x13, 0x63, 0xed, 0x9f, 0x56, 0x9e, 0x85 }; const unsigned int cose_recipients_map_instead_of_array_len = 231; + const unsigned char hmac_big_head[] = { 0xd1, 0x84, 0x43, 0xa1, 0x01, 0x05, 0xac, 0x0a, 0x18, 0x64, 0x14, 0x18, 0xc8, 0x15, 0xfb, 0x40, @@ -175,6 +413,7 @@ const unsigned char hmac_big_head[] = { 0x9f, 0xc3, 0xa0, 0x8d, 0x8c, 0x58 }; const unsigned int hmac_big_head_len = 110; + const unsigned char hmac_error_header[] = { 0xd1, 0x84, 0x43, 0xa1, 0x01, 0x05, 0xa2, 0x0a, 0x18, 0x64, 0xfb, 0x40, 0x09, 0x1e, 0xb8, 0x51, @@ -188,6 +427,39 @@ const unsigned char hmac_error_header[] = { 0xa0, 0x8d, 0x8c, 0x58 }; const unsigned int hmac_error_header_len = 76; + +const unsigned char no_tag[] = { + 0x84, 0x43, 0xa1, 0x01, 0x03, 0xa1, 0x05, 0x4c, + 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, 0x43, 0xd4, + 0x86, 0x8d, 0x87, 0xce, 0x58, 0x24, 0x25, 0x6b, + 0x74, 0x8d, 0xeb, 0x64, 0x71, 0x31, 0xc1, 0x2a, + 0x10, 0xac, 0x26, 0x1d, 0xa0, 0x62, 0x8e, 0x42, + 0x04, 0x92, 0xa3, 0x6f, 0x3d, 0xed, 0x86, 0x42, + 0xb4, 0xb6, 0xfa, 0x1e, 0xb1, 0x5d, 0xce, 0xc8, + 0x0a, 0x0f, 0x81, 0x83, 0x44, 0xa1, 0x01, 0x38, + 0x1c, 0xa2, 0x20, 0xa4, 0x01, 0x02, 0x20, 0x01, + 0x21, 0x58, 0x20, 0xe1, 0x2c, 0x93, 0x8b, 0x18, + 0x22, 0x58, 0xc9, 0xd4, 0x47, 0xd4, 0x18, 0x21, + 0x71, 0x52, 0x61, 0xae, 0x99, 0xad, 0x77, 0xd2, + 0x41, 0x94, 0x3f, 0x4a, 0x12, 0xff, 0x20, 0xdd, + 0x3c, 0xe4, 0x00, 0x22, 0x58, 0x20, 0x48, 0xb0, + 0x58, 0x89, 0x03, 0x36, 0x57, 0x33, 0xb9, 0x8d, + 0x38, 0x8c, 0x61, 0x36, 0xc0, 0x4b, 0x7f, 0xfd, + 0x1a, 0x77, 0x0c, 0xd2, 0x61, 0x11, 0x89, 0xee, + 0x84, 0xe9, 0x94, 0x1a, 0x7e, 0x26, 0x04, 0x58, + 0x24, 0x6d, 0x65, 0x72, 0x69, 0x61, 0x64, 0x6f, + 0x63, 0x2e, 0x62, 0x72, 0x61, 0x6e, 0x64, 0x79, + 0x62, 0x75, 0x63, 0x6b, 0x40, 0x62, 0x75, 0x63, + 0x6b, 0x6c, 0x61, 0x6e, 0x64, 0x2e, 0x65, 0x78, + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x58, 0x28, 0x50, + 0x8f, 0xad, 0x30, 0xa1, 0xa9, 0x5d, 0x13, 0x80, + 0xb5, 0x16, 0x7d, 0x03, 0x27, 0x99, 0xc7, 0x24, + 0x77, 0xab, 0x60, 0x25, 0x8a, 0xbf, 0xb7, 0x1c, + 0x7a, 0xb6, 0x03, 0xa4, 0x89, 0x0e, 0xf4, 0x4f, + 0x13, 0x63, 0xed, 0x9f, 0x56, 0x9e, 0x85 +}; +const unsigned int no_tag_len = 223; + const unsigned char tstr_ciphertext[] = { 0xd8, 0x60, 0x84, 0x43, 0xa1, 0x01, 0x03, 0xa1, 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, @@ -219,6 +491,40 @@ const unsigned char tstr_ciphertext[] = { 0x13, 0x63, 0xed, 0x9f, 0x56, 0x9e, 0x85 }; const unsigned int tstr_ciphertext_len = 223; + +const unsigned char unknown_rcpt_alg[] = { + 0xd8, 0x60, 0x84, 0x43, 0xa1, 0x01, 0x03, 0xa1, + 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, + 0x43, 0xd4, 0x86, 0x8d, 0x87, 0xce, 0x58, 0x24, + 0x25, 0x6b, 0x74, 0x8d, 0xeb, 0x64, 0x71, 0x31, + 0xc1, 0x2a, 0x10, 0xac, 0x26, 0x1d, 0xa0, 0x62, + 0x8e, 0x42, 0x04, 0x92, 0xa3, 0x6f, 0x3d, 0xed, + 0x86, 0x42, 0xb4, 0xb6, 0xfa, 0x1e, 0xb1, 0x5d, + 0xce, 0xc8, 0x0a, 0x0f, 0x81, 0x83, 0x44, 0xa1, + 0x01, 0x38, 0xaa, 0xa2, 0x20, 0xa4, 0x01, 0x02, + 0x20, 0x01, 0x21, 0x58, 0x20, 0xe1, 0x2c, 0x93, + 0x8b, 0x18, 0x22, 0x58, 0xc9, 0xd4, 0x47, 0xd4, + 0x18, 0x21, 0x71, 0x52, 0x61, 0xae, 0x99, 0xad, + 0x77, 0xd2, 0x41, 0x94, 0x3f, 0x4a, 0x12, 0xff, + 0x20, 0xdd, 0x3c, 0xe4, 0x00, 0x22, 0x58, 0x20, + 0x48, 0xb0, 0x58, 0x89, 0x03, 0x36, 0x57, 0x33, + 0xb9, 0x8d, 0x38, 0x8c, 0x61, 0x36, 0xc0, 0x4b, + 0x7f, 0xfd, 0x1a, 0x77, 0x0c, 0xd2, 0x61, 0x11, + 0x89, 0xee, 0x84, 0xe9, 0x94, 0x1a, 0x7e, 0x26, + 0x04, 0x58, 0x24, 0x6d, 0x65, 0x72, 0x69, 0x61, + 0x64, 0x6f, 0x63, 0x2e, 0x62, 0x72, 0x61, 0x6e, + 0x64, 0x79, 0x62, 0x75, 0x63, 0x6b, 0x40, 0x62, + 0x75, 0x63, 0x6b, 0x6c, 0x61, 0x6e, 0x64, 0x2e, + 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x58, + 0x28, 0x50, 0x8f, 0xad, 0x30, 0xa1, 0xa9, 0x5d, + 0x13, 0x80, 0xb5, 0x16, 0x7d, 0x03, 0x27, 0x99, + 0xc7, 0x24, 0x77, 0xab, 0x60, 0x25, 0x8a, 0xbf, + 0xb7, 0x1c, 0x7a, 0xb6, 0x03, 0xa4, 0x89, 0x0e, + 0xf4, 0x4f, 0x13, 0x63, 0xed, 0x9f, 0x56, 0x9e, + 0x85 +}; +const unsigned int unknown_rcpt_alg_len = 225; + const unsigned char unknown_symmetric_alg[] = { 0xd8, 0x60, 0x84, 0x43, 0xa1, 0x01, 0x08, 0xa1, 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, @@ -251,6 +557,7 @@ const unsigned char unknown_symmetric_alg[] = { 0x85 }; const unsigned int unknown_symmetric_alg_len = 225; + const unsigned char unprot_headers_wrong_type[] = { 0xd8, 0x60, 0x84, 0x43, 0xa1, 0x01, 0x03, 0x82, 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, 0x6c, @@ -283,3 +590,37 @@ const unsigned char unprot_headers_wrong_type[] = { 0x85 }; const unsigned int unprot_headers_wrong_type_len = 225; + +const unsigned char wrong_tag[] = { + 0xd9, 0x02, 0x54, 0x84, 0x43, 0xa1, 0x01, 0x03, + 0xa1, 0x05, 0x4c, 0x02, 0xd1, 0xf7, 0xe6, 0xf2, + 0x6c, 0x43, 0xd4, 0x86, 0x8d, 0x87, 0xce, 0x58, + 0x24, 0x25, 0x6b, 0x74, 0x8d, 0xeb, 0x64, 0x71, + 0x31, 0xc1, 0x2a, 0x10, 0xac, 0x26, 0x1d, 0xa0, + 0x62, 0x8e, 0x42, 0x04, 0x92, 0xa3, 0x6f, 0x3d, + 0xed, 0x86, 0x42, 0xb4, 0xb6, 0xfa, 0x1e, 0xb1, + 0x5d, 0xce, 0xc8, 0x0a, 0x0f, 0x81, 0x83, 0x44, + 0xa1, 0x01, 0x38, 0x1c, 0xa2, 0x20, 0xa4, 0x01, + 0x02, 0x20, 0x01, 0x21, 0x58, 0x20, 0xe1, 0x2c, + 0x93, 0x8b, 0x18, 0x22, 0x58, 0xc9, 0xd4, 0x47, + 0xd4, 0x18, 0x21, 0x71, 0x52, 0x61, 0xae, 0x99, + 0xad, 0x77, 0xd2, 0x41, 0x94, 0x3f, 0x4a, 0x12, + 0xff, 0x20, 0xdd, 0x3c, 0xe4, 0x00, 0x22, 0x58, + 0x20, 0x48, 0xb0, 0x58, 0x89, 0x03, 0x36, 0x57, + 0x33, 0xb9, 0x8d, 0x38, 0x8c, 0x61, 0x36, 0xc0, + 0x4b, 0x7f, 0xfd, 0x1a, 0x77, 0x0c, 0xd2, 0x61, + 0x11, 0x89, 0xee, 0x84, 0xe9, 0x94, 0x1a, 0x7e, + 0x26, 0x04, 0x58, 0x24, 0x6d, 0x65, 0x72, 0x69, + 0x61, 0x64, 0x6f, 0x63, 0x2e, 0x62, 0x72, 0x61, + 0x6e, 0x64, 0x79, 0x62, 0x75, 0x63, 0x6b, 0x40, + 0x62, 0x75, 0x63, 0x6b, 0x6c, 0x61, 0x6e, 0x64, + 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, + 0x58, 0x28, 0x50, 0x8f, 0xad, 0x30, 0xa1, 0xa9, + 0x5d, 0x13, 0x80, 0xb5, 0x16, 0x7d, 0x03, 0x27, + 0x99, 0xc7, 0x24, 0x77, 0xab, 0x60, 0x25, 0x8a, + 0xbf, 0xb7, 0x1c, 0x7a, 0xb6, 0x03, 0xa4, 0x89, + 0x0e, 0xf4, 0x4f, 0x13, 0x63, 0xed, 0x9f, 0x56, + 0x9e, 0x85 +}; +const unsigned int wrong_tag_len = 226; + diff --git a/test/data/test_messages.h b/test/data/test_messages.h index a47aa944..a8e9c467 100644 --- a/test/data/test_messages.h +++ b/test/data/test_messages.h @@ -1,12 +1,43 @@ /* This file is created by make_test_messages.sh from CBOR diag files */ extern const unsigned char aead_in_error[225]; + +extern const unsigned char cose_encrypt_a128cbc_a128kw[93]; + +extern const unsigned char cose_encrypt_a128ctr_a128kw[79]; + +extern const unsigned char cose_encrypt_bad_alg[225]; + +extern const unsigned char cose_encrypt_bad_hdrs[235]; + +extern const unsigned char cose_encrypt_bad_iv[213]; + +extern const unsigned char cose_encrypt_crit[234]; + extern const unsigned char cose_encrypt_junk_recipient[251]; + extern const unsigned char cose_encrypt_p256_wrap_128[225]; -extern const unsigned char cose_encrypt_p256_wrap_aescbc[93]; -extern const unsigned char cose_encrypt_p256_wrap_aesctr[79]; + +extern const unsigned char cose_encrypt_wrong_array[225]; + +extern const unsigned char cose_encrypt_wrong_extra[234]; + +extern const unsigned char cose_encrypt_wrong_rcpt_array[231]; + extern const unsigned char cose_recipients_map_instead_of_array[231]; + extern const unsigned char hmac_big_head[110]; + extern const unsigned char hmac_error_header[76]; + +extern const unsigned char no_tag[223]; + extern const unsigned char tstr_ciphertext[223]; + +extern const unsigned char unknown_rcpt_alg[225]; + extern const unsigned char unknown_symmetric_alg[225]; + extern const unsigned char unprot_headers_wrong_type[225]; + +extern const unsigned char wrong_tag[226]; + diff --git a/test/data/tstr_ciphertext.diag b/test/data/tstr_ciphertext.diag index 57be35bb..cfc1418c 100644 --- a/test/data/tstr_ciphertext.diag +++ b/test/data/tstr_ciphertext.diag @@ -1,3 +1,4 @@ +/ COSE_Encrypt with cipher text that is tstr rather than a bstr / 96( [ h'A10103', diff --git a/test/data/unknown_rcpt_alg.diag b/test/data/unknown_rcpt_alg.diag new file mode 100644 index 00000000..c8f38185 --- /dev/null +++ b/test/data/unknown_rcpt_alg.diag @@ -0,0 +1,24 @@ +/ COSE_Encrypt with COSE_Recipient with unknown algorithm ID / +96( + [ + h'A10103', + {5: h'02D1F7E6F26C43D4868D87CE'}, + h'256B748DEB647131C12A10AC261DA0628E420492A36F3DED8642B4B6FA1EB15DCEC80A0F', + [ + [ + h'A10138AA', + {-1: + { + 1: 2, + -1: 1, + -2: h'E12C938B182258C9D447D41821715261AE99AD77D241943F4A12FF20DD3CE400', + -3: h'48B0588903365733B98D388C6136C04B7FFD1A770CD2611189EE84E9941A7E26' + }, + 4: h'6D65726961646F632E6272616E64796275636B406275636B6C616E642E6578616D706C65' + }, + h'508FAD30A1A95D1380B5167D032799C72477AB60258ABFB71C7AB603A4890EF44F1363ED9F569E85' + ] + ] + ] +) + diff --git a/test/data/unknown_symmetric_alg.diag b/test/data/unknown_symmetric_alg.diag index 24ddda0c..d8afb514 100644 --- a/test/data/unknown_symmetric_alg.diag +++ b/test/data/unknown_symmetric_alg.diag @@ -1,3 +1,4 @@ +/ COSE_Encrypt with unknown body algorithm ID / 96( [ h'A10108', diff --git a/test/data/unprot_headers_wrong_type.diag b/test/data/unprot_headers_wrong_type.diag index 990babfa..fa7976f5 100644 --- a/test/data/unprot_headers_wrong_type.diag +++ b/test/data/unprot_headers_wrong_type.diag @@ -1,3 +1,4 @@ +/ COSE_Encrypt with unprotected headers an array rather than a map / 96( [ h'A10103', diff --git a/test/data/wrong_tag.diag b/test/data/wrong_tag.diag new file mode 100644 index 00000000..7b8bb13d --- /dev/null +++ b/test/data/wrong_tag.diag @@ -0,0 +1,24 @@ +/ COSE_Encrypt with cose tag number that is not a COSE tag number / +596( + [ + h'A10103', + {5: h'02D1F7E6F26C43D4868D87CE'}, + h'256B748DEB647131C12A10AC261DA0628E420492A36F3DED8642B4B6FA1EB15DCEC80A0F', + [ + [ + h'A101381C', + {-1: + { + 1: 2, + -1: 1, + -2: h'E12C938B182258C9D447D41821715261AE99AD77D241943F4A12FF20DD3CE400', + -3: h'48B0588903365733B98D388C6136C04B7FFD1A770CD2611189EE84E9941A7E26' + }, + 4: h'6D65726961646F632E6272616E64796275636B406275636B6C616E642E6578616D706C65' + }, + h'508FAD30A1A95D1380B5167D032799C72477AB60258ABFB71C7AB603A4890EF44F1363ED9F569E85' + ] + ] + ] +) + diff --git a/test/t_cose_encrypt_decrypt_test.c b/test/t_cose_encrypt_decrypt_test.c index 4bea5f5b..5167c609 100644 --- a/test/t_cose_encrypt_decrypt_test.c +++ b/test/t_cose_encrypt_decrypt_test.c @@ -415,11 +415,11 @@ int32_t decrypt_known_good_aeskw_non_aead_test(void) return INT32_MIN; /* Means no testing was actually done */ } - return_value = decrypt_key_wrap(UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_p256_wrap_aesctr)); + return_value = decrypt_key_wrap(UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_a128ctr_a128kw)); if(return_value != 0) { return return_value + 10000; } - return_value = decrypt_key_wrap(UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_p256_wrap_aescbc)); + return_value = decrypt_key_wrap(UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_a128cbc_a128kw)); if(return_value != 0) { return return_value + 20000; } @@ -681,6 +681,9 @@ int32_t run_decrypt_test(const struct decrypt_test *test) &decrypted_payload, ¶ms); + free_fixed_test_ec_encryption_key(pubkey); + free_fixed_test_ec_encryption_key(privatekey); + if(result != test->expected_return_value) { return (int32_t)result + 2000; } @@ -692,19 +695,19 @@ int32_t run_decrypt_test(const struct decrypt_test *test) /* - Unknown symmetric cipher alg - Unknown recipient alg - Unknown critical header - Wrong CBOR tag number + DONE unknown_symmetric_alg.diag: Unknown symmetric cipher alg + DONE unknown_rcpt_alg.diag Unknown recipient alg + DONE cose_encrypt_crit.diag Unknown critical header + DONE wrong_tag.diag Wrong CBOR tag number Header that is not valid CBOR - Top-level CBOR wrong -- a map, not an array - Ciphertext is not the right type -- a text string - Recipients area is a map, not an array - Extra stuff at end of array of 4 - AEAD integrity check fails - IV header header is wrong type -- text string - Symmetric Algorithm ID is the wrong type -- a byte string - Recipient is the wrong type -- a map, not an array + DONE cose_encrypt_wrong_array.diag Top-level CBOR wrong -- a map, not an array + DONE tstr_ciphertext.diag: Ciphertext is not the right type -- a text string + DONE cose_encrypt_wrong_rcpt_array Recipients area is a map, not an array + HALF-DONE cose_encrypt_wrong_extra Extra stuff at end of array of 4 + DONE aead_in_error.diag: AEAD integrity check fails + DONE cose_encrypt_bad_iv.diag IV header header is wrong type -- text string + DONE cose_encrypt_bad_alg.diag Symmetric Algorithm ID is the wrong type -- a byte string + DONE cose_encrypt_junk_recipient.diag: Recipient is the wrong type -- a map, not an array The encrypted CEK is the wrong type -- text string, not byte string Extra stuff at end of recipient array Recipient header is not decodable CBOR @@ -759,13 +762,74 @@ init_decrypt_test_list(struct decrypt_test tests[], int tests_count) tests[test_num].expected_return_value = T_COSE_ERR_ENCRYPT_FORMAT; NEXT_TEST; - tests[test_num].sz_description = "a recipient is a text string, not an array"; tests[test_num].message = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_junk_recipient); tests[test_num].cose_ec_curve_id = T_COSE_ELLIPTIC_CURVE_P_256; tests[test_num].expected_return_value = T_COSE_ERR_RECIPIENT_FORMAT; NEXT_TEST; + tests[test_num].sz_description = "wrong tag number"; + tests[test_num].message = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(wrong_tag); + tests[test_num].cose_ec_curve_id = T_COSE_ELLIPTIC_CURVE_P_256; + tests[test_num].expected_return_value = T_COSE_ERR_CANT_DETERMINE_MESSAGE_TYPE; + NEXT_TEST; + + tests[test_num].sz_description = "no tag number"; + tests[test_num].message = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(no_tag); + tests[test_num].cose_ec_curve_id = T_COSE_ELLIPTIC_CURVE_P_256; + tests[test_num].expected_return_value = T_COSE_ERR_CANT_DETERMINE_MESSAGE_TYPE; + NEXT_TEST; + + tests[test_num].sz_description = "unknown recipient alg"; + tests[test_num].message = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(unknown_rcpt_alg); + tests[test_num].cose_ec_curve_id = T_COSE_ELLIPTIC_CURVE_P_256; + tests[test_num].expected_return_value = T_COSE_ERR_DECLINE; + NEXT_TEST; + +/* + tests[test_num].sz_description = "extra stuff in COSE_Encrypt array of 4"; + tests[test_num].message = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_wrong_extra); + tests[test_num].cose_ec_curve_id = T_COSE_ELLIPTIC_CURVE_P_256; + tests[test_num].expected_return_value = T_COSE_ERR_CANT_DETERMINE_MESSAGE_TYPE; + NEXT_TEST; +*/ + + tests[test_num].sz_description = "array of 4 is map of 2"; + tests[test_num].message = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_wrong_array); + tests[test_num].cose_ec_curve_id = T_COSE_ELLIPTIC_CURVE_P_256; + tests[test_num].expected_return_value = T_COSE_ERR_ENCRYPT_FORMAT; + NEXT_TEST; + + tests[test_num].sz_description = "one recipient array is a map"; + tests[test_num].message = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_wrong_rcpt_array); + tests[test_num].cose_ec_curve_id = T_COSE_ELLIPTIC_CURVE_P_256; + tests[test_num].expected_return_value = T_COSE_ERR_RECIPIENT_FORMAT; + NEXT_TEST; + + tests[test_num].sz_description = "unknown crit header in cose_encrypt"; + tests[test_num].message = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_crit); + tests[test_num].cose_ec_curve_id = T_COSE_ELLIPTIC_CURVE_P_256; + tests[test_num].expected_return_value = T_COSE_ERR_UNKNOWN_CRITICAL_PARAMETER; + NEXT_TEST; + + tests[test_num].sz_description = "Protected headers are a text string"; + tests[test_num].message = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_bad_hdrs); + tests[test_num].cose_ec_curve_id = T_COSE_ELLIPTIC_CURVE_P_256; + tests[test_num].expected_return_value = T_COSE_ERR_PARAMETER_CBOR; + NEXT_TEST; + + tests[test_num].sz_description = "IV is a boolean not bstr"; + tests[test_num].message = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_bad_iv); + tests[test_num].cose_ec_curve_id = T_COSE_ELLIPTIC_CURVE_P_256; + tests[test_num].expected_return_value = T_COSE_ERR_BAD_IV; + NEXT_TEST; + + tests[test_num].sz_description = "algorthm ID is wrong type"; + tests[test_num].message = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(cose_encrypt_bad_alg); + tests[test_num].cose_ec_curve_id = T_COSE_ELLIPTIC_CURVE_P_256; + tests[test_num].expected_return_value = T_COSE_ERR_NO_ALG_ID; + NEXT_TEST; + tests[test_num].sz_description = NULL; return 0; @@ -775,7 +839,7 @@ init_decrypt_test_list(struct decrypt_test tests[], int tests_count) int32_t decrypt_known_bad(void) { int32_t result; - struct decrypt_test test_list[10]; + struct decrypt_test test_list[20]; int32_t i; result = init_decrypt_test_list(test_list, sizeof(test_list)/sizeof(struct decrypt_test)); @@ -784,11 +848,14 @@ int32_t decrypt_known_bad(void) } for(i = 0; test_list[i].sz_description != NULL; i++) { - if(i == 5) { /* For setting break point for a particular test */ + const struct decrypt_test *t = &test_list[i]; + const char *test_to_break_on = "one recipient array is a map"; + if(!strncmp(t->sz_description, test_to_break_on, strlen(test_to_break_on))){ + /* For setting break point for a particular test */ result = 99; } - result = run_decrypt_test(&test_list[i]); + result = run_decrypt_test(t); if(result) { return i * 10000 + (int32_t)result; } @@ -802,7 +869,7 @@ int32_t decrypt_known_bad(void) struct kdf_context_test_input { struct q_useful_buf_c party_u_ident; struct q_useful_buf_c party_v_ident; - bool do_not_send; + bool do_not_send; struct q_useful_buf_c supp_pub_other; struct q_useful_buf_c supp_priv_info; size_t kdf_context_size;