edhoc 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -0
- package/binding.gyp +13 -11
- package/dist/bindings.d.ts +5 -0
- package/dist/bindings.d.ts.map +1 -0
- package/dist/bindings.js +10 -0
- package/dist/crypto.d.ts +29 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +205 -0
- package/dist/edhoc.d.ts +368 -0
- package/dist/edhoc.d.ts.map +1 -0
- package/dist/edhoc.js +76 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/x509credentials.d.ts +20 -0
- package/dist/x509credentials.d.ts.map +1 -0
- package/dist/x509credentials.js +140 -0
- package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_types.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_ead_decode.h +2 -2
- package/external/libedhoc/backends/cbor/include/backend_cbor_ead_encode.h +2 -2
- package/external/libedhoc/backends/cbor/include/backend_cbor_edhoc_types.h +48 -43
- package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_types.h +3 -3
- package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_info_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_info_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_types.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_decode.h +3 -3
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_encode.h +3 -3
- package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_types.h +4 -4
- package/external/libedhoc/backends/cbor/include/backend_cbor_x509_types.h +93 -83
- package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_ead_decode.c +27 -32
- package/external/libedhoc/backends/cbor/src/backend_cbor_ead_encode.c +27 -32
- package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_decode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_encode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_decode.c +63 -52
- package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_encode.c +62 -51
- package/external/libedhoc/backends/cbor/src/backend_cbor_info_decode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_info_encode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_decode.c +54 -51
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_encode.c +54 -51
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_decode.c +36 -37
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_encode.c +36 -37
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_decode.c +103 -80
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_encode.c +102 -79
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_decode.c +99 -76
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_encode.c +98 -75
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_decode.c +40 -41
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_encode.c +40 -41
- package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_decode.c +15 -24
- package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_encode.c +15 -24
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode.c +69 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode2.c +38 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c +53 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c +57 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode.c +71 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode2.c +40 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c +16 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/all_tests.c +19 -0
- package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.c +17 -0
- package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.h +19 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode.c +69 -0
- package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode2.c +38 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode.c +70 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode2.c +42 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode2_Runner.c +53 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode_Runner.c +57 -0
- package/external/libedhoc/externals/Unity/examples/unity_config.h +251 -0
- package/external/libedhoc/externals/Unity/extras/bdd/src/unity_bdd.h +44 -0
- package/external/libedhoc/externals/Unity/extras/bdd/test/test_bdd.c +129 -0
- package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.c +310 -0
- package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.h +95 -0
- package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture_internals.h +51 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/main/AllTests.c +20 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/template_fixture_tests.c +40 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_Test.c +246 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_TestRunner.c +33 -0
- package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.c +203 -0
- package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.h +61 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_Test.c +326 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_TestRunner.c +50 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.c +57 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.h +17 -0
- package/external/libedhoc/externals/Unity/src/unity.c +2501 -0
- package/external/libedhoc/externals/Unity/src/unity.h +698 -0
- package/external/libedhoc/externals/Unity/src/unity_internals.h +1183 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_cmd.c +61 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_def.c +57 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.c +55 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.h +15 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_cmd.c +80 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_def.c +76 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.c +75 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.h +13 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new1.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new2.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_param.c +77 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run1.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run2.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_yaml.c +90 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_new1.c +67 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_new2.c +70 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_param.c +58 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_run1.c +67 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_run2.c +70 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_yaml.c +71 -0
- package/external/libedhoc/externals/Unity/test/testdata/CException.h +18 -0
- package/external/libedhoc/externals/Unity/test/testdata/Defs.h +16 -0
- package/external/libedhoc/externals/Unity/test/testdata/cmock.h +21 -0
- package/external/libedhoc/externals/Unity/test/testdata/mockMock.h +20 -0
- package/external/libedhoc/externals/Unity/test/testdata/testRunnerGenerator.c +204 -0
- package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorSmall.c +73 -0
- package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorWithMocks.c +200 -0
- package/external/libedhoc/externals/Unity/test/tests/self_assessment_utils.h +151 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_arrays.c +2941 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_core.c +375 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_doubles.c +1285 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_floats.c +1395 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_integers.c +2863 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_integers_64.c +783 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_memory.c +82 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterized.c +309 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterizedDemo.c +28 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_strings.c +330 -0
- package/external/libedhoc/externals/Unity/test/tests/types_for_test.h +21 -0
- package/external/libedhoc/externals/zcbor/include/zcbor_common.h +147 -60
- package/external/libedhoc/externals/zcbor/include/zcbor_decode.h +291 -202
- package/external/libedhoc/externals/zcbor/include/zcbor_encode.h +100 -156
- package/external/libedhoc/externals/zcbor/include/zcbor_print.h +165 -0
- package/external/libedhoc/externals/zcbor/samples/hello_world/src/main.c +1 -1
- package/external/libedhoc/externals/zcbor/samples/pet/include/pet_decode.h +1 -1
- package/external/libedhoc/externals/zcbor/samples/pet/include/pet_encode.h +1 -1
- package/external/libedhoc/externals/zcbor/samples/pet/include/pet_types.h +4 -4
- package/external/libedhoc/externals/zcbor/samples/pet/src/main.c +4 -4
- package/external/libedhoc/externals/zcbor/samples/pet/src/pet_decode.c +15 -24
- package/external/libedhoc/externals/zcbor/samples/pet/src/pet_encode.c +14 -23
- package/external/libedhoc/externals/zcbor/src/zcbor_common.c +202 -29
- package/external/libedhoc/externals/zcbor/src/zcbor_decode.c +633 -173
- package/external/libedhoc/externals/zcbor/src/zcbor_encode.c +71 -184
- package/external/libedhoc/externals/zcbor/tests/decode/test1_suit_old_formats/src/main.c +152 -153
- package/external/libedhoc/externals/zcbor/tests/decode/test2_suit/src/main.c +64 -64
- package/external/libedhoc/externals/zcbor/tests/decode/test3_simple/src/main.c +15 -16
- package/external/libedhoc/externals/zcbor/tests/decode/test5_corner_cases/src/main.c +228 -84
- package/external/libedhoc/externals/zcbor/tests/decode/test7_suit9_simple/src/main.c +9 -9
- package/external/libedhoc/externals/zcbor/tests/decode/test8_suit12/src/main.c +0 -1
- package/external/libedhoc/externals/zcbor/tests/decode/test9_manifest14/src/main.c +172 -173
- package/external/libedhoc/externals/zcbor/tests/encode/test1_suit/src/main.c +73 -73
- package/external/libedhoc/externals/zcbor/tests/encode/test2_simple/src/main.c +1 -2
- package/external/libedhoc/externals/zcbor/tests/encode/test3_corner_cases/src/main.c +83 -56
- package/external/libedhoc/externals/zcbor/tests/encode/test4_senml/src/main.c +15 -16
- package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_everything.c +12 -0
- package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_manifest12.c +69 -69
- package/external/libedhoc/externals/zcbor/tests/unit/test1_unit_tests/src/main.c +448 -55
- package/external/libedhoc/externals/zcbor/tests/unit/test3_float16/src/main.c +49 -48
- package/external/libedhoc/include/edhoc.h +348 -54
- package/external/libedhoc/include/edhoc_common.h +289 -0
- package/external/libedhoc/include/edhoc_context.h +60 -35
- package/external/libedhoc/include/edhoc_credentials.h +55 -7
- package/external/libedhoc/include/edhoc_crypto.h +10 -10
- package/external/libedhoc/include/edhoc_ead.h +13 -10
- package/external/libedhoc/include/edhoc_macros.h +20 -11
- package/external/libedhoc/include/edhoc_values.h +2 -2
- package/external/libedhoc/library/edhoc.c +70 -36
- package/external/libedhoc/library/edhoc_common.c +1314 -0
- package/external/libedhoc/library/edhoc_exporter.c +45 -46
- package/external/libedhoc/library/edhoc_message_1.c +107 -72
- package/external/libedhoc/library/edhoc_message_2.c +396 -1693
- package/external/libedhoc/library/edhoc_message_3.c +465 -1656
- package/external/libedhoc/library/edhoc_message_4.c +93 -91
- package/external/libedhoc/library/edhoc_message_error.c +41 -41
- package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_0.h → cipher_suite_0.h} +131 -134
- package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_2.h → cipher_suite_2.h} +139 -140
- package/external/libedhoc/tests/include/{edhoc_trace_1/test_vector_1.h → test_vector_rfc9529_chapter_2.h} +786 -738
- package/external/libedhoc/tests/include/{edhoc_trace_2/test_vector_2.h → test_vector_rfc9529_chapter_3.h} +14 -10
- package/external/libedhoc/tests/include/{x509_chain_cs_0/test_vector_x5chain_cs_0.h → test_vector_x5chain_sign_keys_suite_0.h} +137 -140
- package/external/libedhoc/tests/include/{x509_chain_cs_2/test_vector_x5chain_cs_2.h → test_vector_x5chain_sign_keys_suite_2.h} +7 -8
- package/external/libedhoc/tests/include/{x509_chain_cs_2_static_dh/test_vector_x5chain_cs_2_static_dh.h → test_vector_x5chain_static_dh_keys_suite_2.h} +7 -8
- package/external/libedhoc/tests/include/{x509_hash_cs_2/test_vector_x5t_cs_2.h → test_vector_x5t_sign_keys_suite_2.h} +6 -7
- package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_0.c → cipher_suite_0.c} +445 -447
- package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_2.c → cipher_suite_2.c} +600 -600
- package/external/libedhoc/tests/src/module_test_api.c +430 -0
- package/external/libedhoc/tests/src/module_test_cipher_suite_0.c +395 -0
- package/external/libedhoc/tests/src/module_test_cipher_suite_2.c +392 -0
- package/external/libedhoc/tests/src/{error_message/test_edhoc_error_message.c → module_test_error_message.c} +94 -69
- package/external/libedhoc/tests/src/module_test_main.c +49 -0
- package/external/libedhoc/tests/src/{cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.c → module_test_rfc9528_suites_negotiation.c} +224 -227
- package/external/libedhoc/tests/src/module_test_rfc9529_chapter_2.c +2681 -0
- package/external/libedhoc/tests/src/module_test_rfc9529_chapter_3.c +1635 -0
- package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_0.c +1135 -0
- package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_2.c +1249 -0
- package/external/libedhoc/tests/src/module_test_x5chain_static_dh_keys_suite_2.c +798 -0
- package/external/libedhoc/tests/src/module_test_x5t_sign_keys_suite_2.c +956 -0
- package/include/EdhocComposeAsyncWorker.h +8 -6
- package/include/EdhocCredentialManager.h +16 -11
- package/include/EdhocCryptoManager.h +28 -21
- package/include/EdhocEadManager.h +3 -6
- package/include/{EdhocExportAsyncWorker.h → EdhocExportOscoreAsyncWorker.h} +20 -17
- package/include/EdhocKeyExporterAsyncWorker.h +76 -0
- package/include/EdhocKeyUpdateAsyncWorker.h +72 -0
- package/include/EdhocProcessAsyncWorker.h +14 -10
- package/include/LibEDHOC.h +44 -20
- package/include/UserContext.h +7 -9
- package/include/Utils.h +31 -27
- package/package.json +14 -3
- package/prebuilds/android-arm/edhoc.armv7.node +0 -0
- package/prebuilds/android-arm64/edhoc.armv8.node +0 -0
- package/prebuilds/darwin-arm64/edhoc.node +0 -0
- package/prebuilds/darwin-x64/edhoc.node +0 -0
- package/prebuilds/linux-arm/edhoc.armv6.node +0 -0
- package/prebuilds/linux-arm/edhoc.armv7.node +0 -0
- package/prebuilds/linux-arm64/edhoc.armv8.node +0 -0
- package/prebuilds/linux-x64/edhoc.glibc.node +0 -0
- package/prebuilds/linux-x64/edhoc.musl.node +0 -0
- package/prebuilds/win32-ia32/edhoc.node +0 -0
- package/prebuilds/win32-x64/edhoc.node +0 -0
- package/src/EdhocComposeAsyncWorker.cpp +18 -35
- package/src/EdhocCredentialManager.cpp +160 -187
- package/src/EdhocCryptoManager.cpp +386 -586
- package/src/EdhocEadManager.cpp +10 -18
- package/src/EdhocExportOscoreAsyncWorker.cpp +77 -0
- package/src/EdhocKeyExporterAsyncWorker.cpp +49 -0
- package/src/EdhocKeyUpdateAsyncWorker.cpp +41 -0
- package/src/EdhocProcessAsyncWorker.cpp +72 -19
- package/src/LibEDHOC.cpp +213 -174
- package/src/Suites.cpp +39 -72
- package/src/Utils.cpp +32 -56
- package/test/basic.test.ts +64 -0
- package/test/vectors.test.ts +111 -0
- package/external/libedhoc/externals/zcbor/include/zcbor_debug.h +0 -69
- package/external/libedhoc/tests/include/cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.h +0 -37
- package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_0.h +0 -48
- package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_2.h +0 -48
- package/external/libedhoc/tests/include/edhoc_trace_1/authentication_credentials_1.h +0 -60
- package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_1.h +0 -208
- package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_ead_1.h +0 -59
- package/external/libedhoc/tests/include/edhoc_trace_2/authentication_credentials_2.h +0 -60
- package/external/libedhoc/tests/include/edhoc_trace_2/test_edhoc_handshake_2.h +0 -199
- package/external/libedhoc/tests/include/error_message/test_edhoc_error_message.h +0 -48
- package/external/libedhoc/tests/include/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.h +0 -92
- package/external/libedhoc/tests/include/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.h +0 -96
- package/external/libedhoc/tests/include/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.h +0 -58
- package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.h +0 -56
- package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.h +0 -57
- package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.h +0 -59
- package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.h +0 -57
- package/external/libedhoc/tests/include/x509_hash_cs_2/authentication_credentials_x5t_cs_2.h +0 -60
- package/external/libedhoc/tests/include/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.h +0 -57
- package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_0.c +0 -475
- package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_2.c +0 -473
- package/external/libedhoc/tests/src/edhoc_trace_1/authentication_credentials_1.c +0 -252
- package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_1.c +0 -1829
- package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_ead_1.c +0 -1247
- package/external/libedhoc/tests/src/edhoc_trace_2/authentication_credentials_2.c +0 -170
- package/external/libedhoc/tests/src/edhoc_trace_2/test_edhoc_handshake_2.c +0 -1783
- package/external/libedhoc/tests/src/tests.c +0 -228
- package/external/libedhoc/tests/src/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.c +0 -332
- package/external/libedhoc/tests/src/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.c +0 -936
- package/external/libedhoc/tests/src/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.c +0 -166
- package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.c +0 -587
- package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.c +0 -917
- package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.c +0 -186
- package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.c +0 -743
- package/external/libedhoc/tests/src/x509_hash_cs_2/authentication_credentials_x5t_cs_2.c +0 -261
- package/external/libedhoc/tests/src/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.c +0 -854
- package/src/EdhocExportAsyncWorker.cpp +0 -82
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* \file edhoc_message_3.c
|
|
3
3
|
* \author Kamil Kielbasa
|
|
4
4
|
* \brief EDHOC message 3.
|
|
5
|
-
* \version 0.
|
|
6
|
-
* \date 2024-
|
|
5
|
+
* \version 0.6
|
|
6
|
+
* \date 2024-08-05
|
|
7
7
|
*
|
|
8
8
|
* \copyright Copyright (c) 2024
|
|
9
9
|
*
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
/* EDHOC header: */
|
|
15
15
|
#define EDHOC_ALLOW_PRIVATE_ACCESS
|
|
16
16
|
#include "edhoc.h"
|
|
17
|
+
#include "edhoc_common.h"
|
|
17
18
|
|
|
18
19
|
/* Standard library headers: */
|
|
19
20
|
#include <stdint.h>
|
|
@@ -52,133 +53,13 @@
|
|
|
52
53
|
|
|
53
54
|
/* Module defines ---------------------------------------------------------- */
|
|
54
55
|
/* Module types and type definitiones -------------------------------------- */
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* \brief Helper structure for CBOR encoded elements for context_3.
|
|
58
|
-
*/
|
|
59
|
-
struct cbor_items {
|
|
60
|
-
bool id_cred_i_is_cob; // cob = cbor one byte
|
|
61
|
-
int32_t id_cred_i_cob_val; // cob = cbor one byte
|
|
62
|
-
uint8_t *id_cred_i;
|
|
63
|
-
size_t id_cred_i_len;
|
|
64
|
-
|
|
65
|
-
bool id_cred_i_is_comp_enc; // cob = cbor one byte
|
|
66
|
-
enum edhoc_encode_type id_cred_i_enc_type;
|
|
67
|
-
int32_t id_cred_i_int;
|
|
68
|
-
uint8_t id_cred_i_bstr[EDHOC_CRED_KEY_ID_LEN + 1];
|
|
69
|
-
size_t id_cred_i_bstr_len;
|
|
70
|
-
|
|
71
|
-
uint8_t *th_3;
|
|
72
|
-
size_t th_3_len;
|
|
73
|
-
|
|
74
|
-
uint8_t *cred_i;
|
|
75
|
-
size_t cred_i_len;
|
|
76
|
-
|
|
77
|
-
bool is_ead_3;
|
|
78
|
-
uint8_t *ead_3;
|
|
79
|
-
size_t ead_3_len;
|
|
80
|
-
|
|
81
|
-
size_t buf_len;
|
|
82
|
-
uint8_t buf[];
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* \brief Helper structure for parsed PLAINTEXT_3.
|
|
87
|
-
*/
|
|
88
|
-
struct plaintext {
|
|
89
|
-
struct edhoc_auth_creds auth_creds;
|
|
90
|
-
|
|
91
|
-
const uint8_t *sign_or_mac;
|
|
92
|
-
size_t sign_or_mac_len;
|
|
93
|
-
|
|
94
|
-
const uint8_t *ead;
|
|
95
|
-
size_t ead_len;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* \brief Processing side.
|
|
100
|
-
*/
|
|
101
|
-
enum edhoc_role {
|
|
102
|
-
initiator,
|
|
103
|
-
responder,
|
|
104
|
-
};
|
|
105
|
-
|
|
106
56
|
/* Module interface variables and constants -------------------------------- */
|
|
107
57
|
/* Static variables and constants ------------------------------------------ */
|
|
108
58
|
/* Static function declarations -------------------------------------------- */
|
|
109
59
|
|
|
110
|
-
/**
|
|
111
|
-
* \brief CBOR integer memory requirements.
|
|
112
|
-
*
|
|
113
|
-
* \param val Raw integer value.
|
|
114
|
-
*
|
|
115
|
-
* \return Number of bytes.
|
|
116
|
-
*/
|
|
117
|
-
static inline size_t cbor_int_mem_req(int32_t val);
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* \brief CBOR text stream overhead.
|
|
121
|
-
*
|
|
122
|
-
* \param len Length of buffer to CBOR as tstr.
|
|
123
|
-
*
|
|
124
|
-
* \return Number of bytes.
|
|
125
|
-
*/
|
|
126
|
-
static inline size_t cbor_tstr_overhead(size_t len);
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* \brief CBOR byte stream overhead.
|
|
130
|
-
*
|
|
131
|
-
* \param len Length of buffer to CBOR as bstr.
|
|
132
|
-
*
|
|
133
|
-
* \return Number of bytes.
|
|
134
|
-
*/
|
|
135
|
-
static inline size_t cbor_bstr_overhead(size_t len);
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* \brief CBOR map overhead.
|
|
139
|
-
*
|
|
140
|
-
* \param items Number of items for map.
|
|
141
|
-
*
|
|
142
|
-
* \return Number of bytes.
|
|
143
|
-
*/
|
|
144
|
-
static inline size_t cbor_map_overhead(size_t items);
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* \brief CBOR array overhead.
|
|
148
|
-
*
|
|
149
|
-
* \param items Number of items for array.
|
|
150
|
-
*
|
|
151
|
-
* \return Number of bytes.
|
|
152
|
-
*/
|
|
153
|
-
static inline size_t cbor_array_overhead(size_t items);
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* \brief Check if integer might be encoded as CBOR one byte.
|
|
157
|
-
*
|
|
158
|
-
* \param val Value for cbor encoding.
|
|
159
|
-
*
|
|
160
|
-
* \retval True if might be encoded as one byte cbor integer,
|
|
161
|
-
* otherwise false.
|
|
162
|
-
*/
|
|
163
|
-
static inline bool is_cbor_one_byte_int(int32_t val);
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* \brief Compute memory required for input (context_3) for for MAC_3.
|
|
167
|
-
*
|
|
168
|
-
* \param[in] ctx EDHOC context.
|
|
169
|
-
* \param[in] auth_creds Authentication credentials.
|
|
170
|
-
* \param[out] context_3_len On success, length of context_3.
|
|
171
|
-
*
|
|
172
|
-
* \retval EDHOC_SUCCESS on success, otherwise failure.
|
|
173
|
-
*/
|
|
174
|
-
static int comp_mac_3_input_len(const struct edhoc_context *ctx,
|
|
175
|
-
const struct edhoc_auth_creds *auth_creds,
|
|
176
|
-
size_t *context_3_len);
|
|
177
|
-
|
|
178
60
|
/**
|
|
179
61
|
* \brief Compute psuedo random key (PRK_4e3m).
|
|
180
62
|
*
|
|
181
|
-
* \param[in] role EDHOC role.
|
|
182
63
|
* \param[in,out] ctx EDHOC context.
|
|
183
64
|
* \param[in] auth_cred Authentication credentials.
|
|
184
65
|
* \param[in] pub_key Peer public static DH key.
|
|
@@ -186,99 +67,28 @@ static int comp_mac_3_input_len(const struct edhoc_context *ctx,
|
|
|
186
67
|
*
|
|
187
68
|
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
188
69
|
*/
|
|
189
|
-
static int comp_prk_4e3m(
|
|
70
|
+
static int comp_prk_4e3m(struct edhoc_context *ctx,
|
|
190
71
|
const struct edhoc_auth_creds *auth_cred,
|
|
191
72
|
const uint8_t *pub_key, size_t pub_key_len);
|
|
192
73
|
|
|
193
|
-
/**
|
|
194
|
-
* \brief Generate context_3.
|
|
195
|
-
*
|
|
196
|
-
* \param[in] ctx EDHOC context.
|
|
197
|
-
* \param[in] auth_creds Authentication credentials.
|
|
198
|
-
* \param[out] cbor_items Buffer where the generated context_3 is to be written.
|
|
199
|
-
*
|
|
200
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
201
|
-
*/
|
|
202
|
-
static int gen_mac_3_context(const struct edhoc_context *ctx,
|
|
203
|
-
const struct edhoc_auth_creds *auth_creds,
|
|
204
|
-
struct cbor_items *cbor_items);
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* \brief Compute memory required for MAC_3.
|
|
208
|
-
*
|
|
209
|
-
* \param role EDHOC role.
|
|
210
|
-
* \param[in] ctx EDHOC context.
|
|
211
|
-
* \param[out] mac_3_len On success, length of MAC_3.
|
|
212
|
-
*
|
|
213
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
214
|
-
*/
|
|
215
|
-
static int comp_mac_3_len(enum edhoc_role role, const struct edhoc_context *ctx,
|
|
216
|
-
size_t *mac_3_len);
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* \brief Compute MAC_3.
|
|
220
|
-
*
|
|
221
|
-
* \param[in] ctx EDHOC context.
|
|
222
|
-
* \param[in] cbor_items Buffer containing the context_3.
|
|
223
|
-
* \param[out] mac_3 Buffer where the generated MAC_3 is to be written.
|
|
224
|
-
* \param mac_3_len Size of the \p mac_3 buffer in bytes.
|
|
225
|
-
*
|
|
226
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
227
|
-
*/
|
|
228
|
-
static int comp_mac_3(const struct edhoc_context *ctx,
|
|
229
|
-
const struct cbor_items *cbor_items, uint8_t *mac_3,
|
|
230
|
-
size_t mac_3_len);
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* \brief Compute memory required Signature_or_MAC_3.
|
|
234
|
-
*
|
|
235
|
-
* \param role EDHOC role.
|
|
236
|
-
* \param[in] ctx EDHOC context.
|
|
237
|
-
* \param[out] sign_or_mac_3_len On success, length of Signature_or_MAC_3.
|
|
238
|
-
*
|
|
239
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
240
|
-
*/
|
|
241
|
-
static int comp_sign_or_mac_3_len(enum edhoc_role role,
|
|
242
|
-
const struct edhoc_context *ctx,
|
|
243
|
-
size_t *sign_or_mac_3_len);
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* \brief Compute Signature_or_MAC_3.
|
|
247
|
-
*
|
|
248
|
-
* \param[in] ctx EDHOC context.
|
|
249
|
-
* \param[in] auth_creds Authentication credentials.
|
|
250
|
-
* \param[in] cbor_items Buffer containing the context_3.
|
|
251
|
-
* \param[in] mac_3 Buffer containing the MAC_3.
|
|
252
|
-
* \param mac_3_len Size of the \p mac_3 buffer in bytes.
|
|
253
|
-
* \param[out] sign Buffer where the generated signature is to be written.
|
|
254
|
-
* \param sign_len Size of the \p sign buffer in bytes.
|
|
255
|
-
*
|
|
256
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
257
|
-
*/
|
|
258
|
-
static int comp_sign_or_mac_3(const struct edhoc_context *ctx,
|
|
259
|
-
const struct edhoc_auth_creds *auth_creds,
|
|
260
|
-
const struct cbor_items *cbor_items,
|
|
261
|
-
const uint8_t *mac_3, size_t mac_3_len,
|
|
262
|
-
uint8_t *sign, size_t sign_len);
|
|
263
|
-
|
|
264
74
|
/**
|
|
265
75
|
* \brief Compute memory required for PLAINTEXT_3.
|
|
266
76
|
*
|
|
267
77
|
* \param[in] ctx EDHOC context.
|
|
268
|
-
* \param[in]
|
|
78
|
+
* \param[in] mac_ctx MAC context.
|
|
269
79
|
* \param sign_len Size of the signature buffer in bytes.
|
|
270
80
|
* \param[out] plaintext_3_len On success, length of PLAINTEXT_3.
|
|
271
81
|
*
|
|
272
82
|
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
273
83
|
*/
|
|
274
84
|
static int comp_plaintext_3_len(const struct edhoc_context *ctx,
|
|
275
|
-
const struct
|
|
85
|
+
const struct mac_context *mac_ctx,
|
|
276
86
|
size_t sign_len, size_t *plaintext_3_len);
|
|
277
87
|
|
|
278
88
|
/**
|
|
279
89
|
* \brief Prepare PLAINTEXT_3.
|
|
280
90
|
*
|
|
281
|
-
* \param[in]
|
|
91
|
+
* \param[in] mac_ctx MAC context.
|
|
282
92
|
* \param[in] sign Buffer containing the signature.
|
|
283
93
|
* \param sign_len Size of the \p sign buffer in bytes.
|
|
284
94
|
* \param[out] ptxt Buffer where the generated plaintext is to be written.
|
|
@@ -287,7 +97,7 @@ static int comp_plaintext_3_len(const struct edhoc_context *ctx,
|
|
|
287
97
|
*
|
|
288
98
|
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
289
99
|
*/
|
|
290
|
-
static int prepare_plaintext_3(const struct
|
|
100
|
+
static int prepare_plaintext_3(const struct mac_context *mac_ctx,
|
|
291
101
|
const uint8_t *sign, size_t sign_len,
|
|
292
102
|
uint8_t *ptxt, size_t ptxt_size,
|
|
293
103
|
size_t *ptxt_len);
|
|
@@ -337,1046 +147,204 @@ static int comp_key_iv_aad(const struct edhoc_context *ctx, uint8_t *key,
|
|
|
337
147
|
* \param[out] ctxt_len On success, the number of bytes that make up the CIPHERTEXT_3.
|
|
338
148
|
*
|
|
339
149
|
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
340
|
-
*/
|
|
341
|
-
static int comp_ciphertext(const struct edhoc_context *ctx, const uint8_t *key,
|
|
342
|
-
size_t key_len, const uint8_t *iv, size_t iv_len,
|
|
343
|
-
const uint8_t *aad, size_t aad_len,
|
|
344
|
-
const uint8_t *ptxt, size_t ptxt_len, uint8_t *ctxt,
|
|
345
|
-
size_t ctxt_size, size_t *ctxt_len);
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* \brief Compute transcript hash 4.
|
|
349
|
-
*
|
|
350
|
-
* \param[in,out] ctx EDHOC context.
|
|
351
|
-
* \param[in] cbor_items Structure containing the context_3.
|
|
352
|
-
* \param[in] ptxt Buffer containing the PLAINTEXT_3.
|
|
353
|
-
* \param ptxt_len Size of the \p ptxt buffer in bytes.
|
|
354
|
-
*
|
|
355
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
356
|
-
*/
|
|
357
|
-
static int comp_th_4(struct edhoc_context *ctx,
|
|
358
|
-
const struct cbor_items *cbor_items, const uint8_t *ptxt,
|
|
359
|
-
size_t ptxt_len);
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* \brief Generate edhoc message 3.
|
|
363
|
-
*
|
|
364
|
-
* \param[in] ctxt Buffer continas the ciphertext.
|
|
365
|
-
* \param ctxt_len Size of the \p ctxt buffer in bytes.
|
|
366
|
-
* \param[out] msg_3 Buffer where the generated message 3 is to be written.
|
|
367
|
-
* \param msg_3_size Size of the \p msg_3 buffer in bytes.
|
|
368
|
-
* \param[out] msg_3_len On success, the number of bytes that make up the message 3.
|
|
369
|
-
*
|
|
370
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
371
|
-
*/
|
|
372
|
-
static int gen_msg_3(const uint8_t *ctxt, size_t ctxt_len, uint8_t *msg_3,
|
|
373
|
-
size_t msg_3_size, size_t *msg_3_len);
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* \brief CBOR decode message 3 and save address and length for CIPHERTEXT_3.
|
|
377
|
-
*
|
|
378
|
-
* \param[in] msg_3 Buffer containing the message 3.
|
|
379
|
-
* \param msg_3_len Size of the \p msg_3 buffer in bytes.
|
|
380
|
-
* \param[out] ctxt_3 Pointer to buffer containing the CIPHERTEXT_3.
|
|
381
|
-
* \param[out] ctxt_3_len Size of the \p ctxt_3 buffer in bytes.
|
|
382
|
-
*
|
|
383
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
384
|
-
*/
|
|
385
|
-
static int parse_msg_3(const uint8_t *msg_3, size_t msg_3_len,
|
|
386
|
-
const uint8_t **ctxt_3, size_t *ctxt_3_len);
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* \brief Decrypt CIPHERTEXT_3.
|
|
390
|
-
*
|
|
391
|
-
* \param[in] ctx EDHOC context.
|
|
392
|
-
* \param[in] key Buffer containing the K_3.
|
|
393
|
-
* \param key_len Size of the \p key buffer in bytes.
|
|
394
|
-
* \param[in] iv Buffer containing the IV_3.
|
|
395
|
-
* \param iv_len Size of the \p iv buffer in bytes.
|
|
396
|
-
* \param[in] aad Buffer containing the AAD_3.
|
|
397
|
-
* \param aad_len Size of the \p aad buffer in bytes.
|
|
398
|
-
* \param[in] ctxt Pointer to buffer containing the CIPHERTEXT_3.
|
|
399
|
-
* \param ctxt_len Size of the \p ctxt buffer in bytes.
|
|
400
|
-
* \param[out] ptxt Buffer where the decrypted PLAINTEXT_3 is to be written.
|
|
401
|
-
* \param ptxt_len Size of the \p ptxt buffer in bytes.
|
|
402
|
-
*
|
|
403
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
404
|
-
*/
|
|
405
|
-
static int decrypt_ciphertext(const struct edhoc_context *ctx,
|
|
406
|
-
const uint8_t *key, size_t key_len,
|
|
407
|
-
const uint8_t *iv, size_t iv_len,
|
|
408
|
-
const uint8_t *aad, size_t aad_len,
|
|
409
|
-
const uint8_t *ctxt, size_t ctxt_len,
|
|
410
|
-
uint8_t *ptxt, size_t ptxt_len);
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* \brief Parsed cborised PLAINTEXT_3 for separate buffers.
|
|
414
|
-
*
|
|
415
|
-
* \param[in] ctx EDHOC context.
|
|
416
|
-
* \param[in] ptxt Buffer containing the PLAINTEXT_3.
|
|
417
|
-
* \param ptxt_len Size of the \p ptxt buffer in bytes.
|
|
418
|
-
* \param[out] parsed_ptxt Structure where parsed PLAINTEXT_3 is to be written.
|
|
419
|
-
*
|
|
420
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
421
|
-
*/
|
|
422
|
-
static int parse_plaintext(struct edhoc_context *ctx, const uint8_t *ptxt,
|
|
423
|
-
size_t ptxt_len, struct plaintext *parsed_ptxt);
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* \brief Verify Signature_or_MAC_3.
|
|
427
|
-
*
|
|
428
|
-
* \param[in] ctx EDHOC context.
|
|
429
|
-
* \param[in] cbor_items Structure containing the context_3.
|
|
430
|
-
* \param[in] parsed_ptxt Structure containing the parsed PLAINTEXT_3.
|
|
431
|
-
* \param[in] pub_key Buffer containing the public key from peer credentials.
|
|
432
|
-
* \param pub_key_len Size of the \p pub_key buffer in bytes.
|
|
433
|
-
* \param[in] mac_3 Buffer containing the MAC_3.
|
|
434
|
-
* \param mac_3_len Size of the \p mac_3 buffer in bytes.
|
|
435
|
-
*
|
|
436
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
437
|
-
*/
|
|
438
|
-
static int verify_sign_or_mac_3(const struct edhoc_context *ctx,
|
|
439
|
-
const struct cbor_items *cbor_items,
|
|
440
|
-
const struct plaintext *parsed_ptxt,
|
|
441
|
-
const uint8_t *pub_key, size_t pub_key_len,
|
|
442
|
-
const uint8_t *mac_3, size_t mac_3_len);
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* \brief Perform compact encoding described in:
|
|
446
|
-
* - RFC 9528: 3.5.3.2. Compact Encoding of ID_CRED Fields for 'kid'.
|
|
447
|
-
*
|
|
448
|
-
* \param[in] auth_cred Authentication credentials.
|
|
449
|
-
* \param[in,out] cbor_items Structure containing the context_2.
|
|
450
|
-
*
|
|
451
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
452
|
-
*/
|
|
453
|
-
static int kid_compact_encoding(const struct edhoc_auth_creds *auth_cred,
|
|
454
|
-
struct cbor_items *cbor_items);
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* \brief Compute SALT_4e3m.
|
|
458
|
-
*
|
|
459
|
-
* \param[in] ctx EDHOC context.
|
|
460
|
-
* \param[out] salt Buffer where the generated salt is to be written.
|
|
461
|
-
* \param salt_len Size of the \p salt buffer in bytes.
|
|
462
|
-
*
|
|
463
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
464
|
-
*/
|
|
465
|
-
static int comp_salt_4e3m(const struct edhoc_context *ctx, uint8_t *salt,
|
|
466
|
-
size_t salt_len);
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* \brief Compute G_IY for PRK_4e3m.
|
|
470
|
-
*
|
|
471
|
-
* \param role EDHOC role.
|
|
472
|
-
* \param[in,out] ctx EDHOC context.
|
|
473
|
-
* \param[in] auth_cred Authentication credentials.
|
|
474
|
-
* \param[in] pub_key Peer public key.
|
|
475
|
-
* \param pub_key_len Peer public key length.
|
|
476
|
-
* \param[out] giy Buffer where the generated G_IY is to be written.
|
|
477
|
-
* \param giy_len Size of the \p giy buffer in bytes.
|
|
478
|
-
*
|
|
479
|
-
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
480
|
-
*/
|
|
481
|
-
static int comp_giy(enum edhoc_role role, struct edhoc_context *ctx,
|
|
482
|
-
const struct edhoc_auth_creds *auth_cred,
|
|
483
|
-
const uint8_t *pub_key, size_t pub_key_len, uint8_t *giy,
|
|
484
|
-
size_t giy_len);
|
|
485
|
-
|
|
486
|
-
/* Static function definitions --------------------------------------------- */
|
|
487
|
-
|
|
488
|
-
static inline size_t cbor_int_mem_req(int32_t val)
|
|
489
|
-
{
|
|
490
|
-
if (val >= ONE_BYTE_CBOR_INT_MIN_VALUE &&
|
|
491
|
-
val <= ONE_BYTE_CBOR_INT_MAX_VALUE) {
|
|
492
|
-
return 1;
|
|
493
|
-
} else if (val >= -(UINT8_MAX + 1) && val <= UINT8_MAX) {
|
|
494
|
-
return 2;
|
|
495
|
-
} else if (val >= -(UINT16_MAX + 1) && val <= UINT16_MAX) {
|
|
496
|
-
return 3;
|
|
497
|
-
} else {
|
|
498
|
-
return 4;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
static inline size_t cbor_tstr_overhead(size_t len)
|
|
503
|
-
{
|
|
504
|
-
if (len <= 23) {
|
|
505
|
-
return 1;
|
|
506
|
-
} else if (len <= UINT8_MAX) {
|
|
507
|
-
return 2;
|
|
508
|
-
} else if (len <= UINT16_MAX) {
|
|
509
|
-
return 3;
|
|
510
|
-
} else if (len <= UINT32_MAX) {
|
|
511
|
-
return 4;
|
|
512
|
-
} else {
|
|
513
|
-
return 5;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
static inline size_t cbor_bstr_overhead(size_t len)
|
|
518
|
-
{
|
|
519
|
-
if (len <= 23) {
|
|
520
|
-
return 1;
|
|
521
|
-
} else if (len <= UINT8_MAX) {
|
|
522
|
-
return 2;
|
|
523
|
-
} else if (len <= UINT16_MAX) {
|
|
524
|
-
return 3;
|
|
525
|
-
} else if (len <= UINT32_MAX) {
|
|
526
|
-
return 4;
|
|
527
|
-
} else {
|
|
528
|
-
return 5;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
static inline size_t cbor_map_overhead(size_t items)
|
|
533
|
-
{
|
|
534
|
-
(void)items;
|
|
535
|
-
|
|
536
|
-
return 3;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
static inline size_t cbor_array_overhead(size_t items)
|
|
540
|
-
{
|
|
541
|
-
if (items < 24)
|
|
542
|
-
return 1;
|
|
543
|
-
if (items < 256)
|
|
544
|
-
return 2;
|
|
545
|
-
if (items < 65535)
|
|
546
|
-
return 3;
|
|
547
|
-
|
|
548
|
-
return 4;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
static inline bool is_cbor_one_byte_int(int32_t val)
|
|
552
|
-
{
|
|
553
|
-
return (ONE_BYTE_CBOR_INT_MIN_VALUE < val &&
|
|
554
|
-
ONE_BYTE_CBOR_INT_MAX_VALUE > val);
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
static int comp_mac_3_input_len(const struct edhoc_context *ctx,
|
|
558
|
-
const struct edhoc_auth_creds *auth_cred,
|
|
559
|
-
size_t *context_3_len)
|
|
560
|
-
{
|
|
561
|
-
if (NULL == ctx || NULL == auth_cred || NULL == context_3_len)
|
|
562
|
-
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
563
|
-
|
|
564
|
-
const size_t nr_of_items = 1;
|
|
565
|
-
size_t len = 0;
|
|
566
|
-
|
|
567
|
-
/* ID_CRED_I. */
|
|
568
|
-
switch (auth_cred->label) {
|
|
569
|
-
case EDHOC_COSE_HEADER_KID:
|
|
570
|
-
len += cbor_map_overhead(nr_of_items);
|
|
571
|
-
|
|
572
|
-
switch (auth_cred->key_id.encode_type) {
|
|
573
|
-
case EDHOC_ENCODE_TYPE_INTEGER:
|
|
574
|
-
len += cbor_int_mem_req(auth_cred->key_id.key_id_int);
|
|
575
|
-
break;
|
|
576
|
-
case EDHOC_ENCODE_TYPE_BYTE_STRING:
|
|
577
|
-
len += auth_cred->key_id.key_id_bstr_length;
|
|
578
|
-
len += cbor_bstr_overhead(
|
|
579
|
-
auth_cred->key_id.key_id_bstr_length);
|
|
580
|
-
break;
|
|
581
|
-
default:
|
|
582
|
-
return EDHOC_ERROR_NOT_PERMITTED;
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
break;
|
|
586
|
-
|
|
587
|
-
case EDHOC_COSE_HEADER_X509_CHAIN: {
|
|
588
|
-
if (1 == auth_cred->x509_chain.nr_of_certs) {
|
|
589
|
-
len += cbor_map_overhead(nr_of_items);
|
|
590
|
-
len += auth_cred->x509_chain.cert_len[0];
|
|
591
|
-
len += cbor_bstr_overhead(
|
|
592
|
-
auth_cred->x509_chain.cert_len[0]);
|
|
593
|
-
} else {
|
|
594
|
-
for (size_t i = 0;
|
|
595
|
-
i < auth_cred->x509_chain.nr_of_certs; ++i) {
|
|
596
|
-
len += cbor_map_overhead(nr_of_items);
|
|
597
|
-
len += auth_cred->x509_chain.cert_len[i];
|
|
598
|
-
len += cbor_bstr_overhead(
|
|
599
|
-
auth_cred->x509_chain.cert_len[i]);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
break;
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
case EDHOC_COSE_HEADER_X509_HASH:
|
|
607
|
-
len += cbor_map_overhead(nr_of_items);
|
|
608
|
-
len += cbor_array_overhead(nr_of_items);
|
|
609
|
-
|
|
610
|
-
switch (auth_cred->x509_hash.encode_type) {
|
|
611
|
-
case EDHOC_ENCODE_TYPE_INTEGER:
|
|
612
|
-
len += cbor_int_mem_req(auth_cred->x509_hash.alg_int);
|
|
613
|
-
break;
|
|
614
|
-
case EDHOC_ENCODE_TYPE_BYTE_STRING:
|
|
615
|
-
len += auth_cred->x509_hash.alg_bstr_length;
|
|
616
|
-
len += cbor_bstr_overhead(
|
|
617
|
-
auth_cred->x509_hash.alg_bstr_length);
|
|
618
|
-
break;
|
|
619
|
-
default:
|
|
620
|
-
return EDHOC_ERROR_NOT_PERMITTED;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
len += auth_cred->x509_hash.cert_fp_len;
|
|
624
|
-
len += cbor_bstr_overhead(auth_cred->x509_hash.cert_fp_len);
|
|
625
|
-
break;
|
|
626
|
-
|
|
627
|
-
default:
|
|
628
|
-
return EDHOC_ERROR_NOT_SUPPORTED;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
/* TH_3. */
|
|
632
|
-
len += ctx->th_len;
|
|
633
|
-
len += cbor_bstr_overhead(ctx->th_len);
|
|
634
|
-
|
|
635
|
-
/* CRED_I. */
|
|
636
|
-
switch (auth_cred->label) {
|
|
637
|
-
case EDHOC_COSE_HEADER_KID:
|
|
638
|
-
len += auth_cred->key_id.cred_len;
|
|
639
|
-
len += cbor_bstr_overhead(auth_cred->key_id.cred_len);
|
|
640
|
-
break;
|
|
641
|
-
|
|
642
|
-
case EDHOC_COSE_HEADER_X509_CHAIN: {
|
|
643
|
-
const size_t end_entity_idx =
|
|
644
|
-
auth_cred->x509_chain.nr_of_certs - 1;
|
|
645
|
-
len += auth_cred->x509_chain.cert_len[end_entity_idx];
|
|
646
|
-
len += cbor_bstr_overhead(
|
|
647
|
-
auth_cred->x509_chain.cert_len[end_entity_idx]);
|
|
648
|
-
break;
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
case EDHOC_COSE_HEADER_X509_HASH:
|
|
652
|
-
len += auth_cred->x509_hash.cert_len;
|
|
653
|
-
len += cbor_bstr_overhead(auth_cred->x509_hash.cert_len);
|
|
654
|
-
break;
|
|
655
|
-
|
|
656
|
-
default:
|
|
657
|
-
return EDHOC_ERROR_NOT_SUPPORTED;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
/* EAD_3. */
|
|
661
|
-
for (size_t i = 0; i < ctx->nr_of_ead_tokens; ++i) {
|
|
662
|
-
len += cbor_int_mem_req(ctx->ead_token[i].label);
|
|
663
|
-
len += ctx->ead_token[i].value_len;
|
|
664
|
-
len += cbor_bstr_overhead(ctx->ead_token[i].value_len);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
*context_3_len = len;
|
|
668
|
-
return EDHOC_SUCCESS;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
static int comp_prk_4e3m(enum edhoc_role role, struct edhoc_context *ctx,
|
|
672
|
-
const struct edhoc_auth_creds *auth_cred,
|
|
673
|
-
const uint8_t *pub_key, size_t pub_key_len)
|
|
674
|
-
{
|
|
675
|
-
if (NULL == ctx)
|
|
676
|
-
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
677
|
-
|
|
678
|
-
if (EDHOC_PRK_STATE_3E2M != ctx->prk_state)
|
|
679
|
-
return EDHOC_ERROR_BAD_STATE;
|
|
680
|
-
|
|
681
|
-
if (initiator == role) {
|
|
682
|
-
switch (ctx->method) {
|
|
683
|
-
case EDHOC_METHOD_0:
|
|
684
|
-
case EDHOC_METHOD_1:
|
|
685
|
-
ctx->prk_state = EDHOC_PRK_STATE_4E3M;
|
|
686
|
-
return EDHOC_SUCCESS;
|
|
687
|
-
|
|
688
|
-
case EDHOC_METHOD_2:
|
|
689
|
-
case EDHOC_METHOD_3: {
|
|
690
|
-
const size_t hash_len =
|
|
691
|
-
ctx->csuite[ctx->chosen_csuite_idx].hash_length;
|
|
692
|
-
|
|
693
|
-
ALLOCATE_ARRAY(uint8_t, salt_4e3m, hash_len);
|
|
694
|
-
memset(salt_4e3m, 0, ALLOCATE_ARRAY_SIZEOF(salt_4e3m));
|
|
695
|
-
|
|
696
|
-
int ret = comp_salt_4e3m(ctx, salt_4e3m,
|
|
697
|
-
ARRAY_SIZE_VLA(salt_4e3m));
|
|
698
|
-
|
|
699
|
-
if (EDHOC_SUCCESS != ret)
|
|
700
|
-
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
701
|
-
|
|
702
|
-
if (NULL != ctx->logger)
|
|
703
|
-
ctx->logger(ctx->user_ctx, "SALT_4e3m",
|
|
704
|
-
salt_4e3m, ARRAY_SIZE_VLA(salt_4e3m));
|
|
705
|
-
|
|
706
|
-
const size_t ecc_key_len =
|
|
707
|
-
ctx->csuite[ctx->chosen_csuite_idx]
|
|
708
|
-
.ecc_key_length;
|
|
709
|
-
|
|
710
|
-
ALLOCATE_ARRAY(uint8_t, giy, ecc_key_len);
|
|
711
|
-
memset(giy, 0, ALLOCATE_ARRAY_SIZEOF(giy));
|
|
712
|
-
|
|
713
|
-
ret = comp_giy(role, ctx, auth_cred, pub_key,
|
|
714
|
-
pub_key_len, giy, ARRAY_SIZE_VLA(giy));
|
|
715
|
-
|
|
716
|
-
if (EDHOC_SUCCESS != ret)
|
|
717
|
-
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
718
|
-
|
|
719
|
-
if (NULL != ctx->logger)
|
|
720
|
-
ctx->logger(ctx->user_ctx, "G_IY", giy,
|
|
721
|
-
ARRAY_SIZE_VLA(giy));
|
|
722
|
-
|
|
723
|
-
ctx->prk_len =
|
|
724
|
-
ctx->csuite[ctx->chosen_csuite_idx].hash_length;
|
|
725
|
-
|
|
726
|
-
uint8_t key_id[EDHOC_KID_LEN] = { 0 };
|
|
727
|
-
ret = ctx->keys.generate_key(ctx->user_ctx,
|
|
728
|
-
EDHOC_KT_EXTRACT, giy,
|
|
729
|
-
ARRAY_SIZE_VLA(giy), key_id);
|
|
730
|
-
memset(giy, 0, sizeof(giy));
|
|
731
|
-
|
|
732
|
-
if (EDHOC_SUCCESS != ret)
|
|
733
|
-
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
734
|
-
|
|
735
|
-
size_t out_len = 0;
|
|
736
|
-
ret = ctx->crypto.extract(ctx->user_ctx, key_id,
|
|
737
|
-
salt_4e3m,
|
|
738
|
-
ARRAY_SIZE_VLA(salt_4e3m),
|
|
739
|
-
ctx->prk, ctx->prk_len,
|
|
740
|
-
&out_len);
|
|
741
|
-
ctx->keys.destroy_key(ctx->user_ctx, key_id);
|
|
742
|
-
|
|
743
|
-
if (EDHOC_SUCCESS != ret || ctx->prk_len != out_len)
|
|
744
|
-
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
745
|
-
|
|
746
|
-
ctx->prk_state = EDHOC_PRK_STATE_4E3M;
|
|
747
|
-
return EDHOC_SUCCESS;
|
|
748
|
-
}
|
|
749
|
-
default:
|
|
750
|
-
return EDHOC_ERROR_NOT_PERMITTED;
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
if (responder == role) {
|
|
755
|
-
switch (ctx->method) {
|
|
756
|
-
case EDHOC_METHOD_0:
|
|
757
|
-
case EDHOC_METHOD_1:
|
|
758
|
-
ctx->prk_state = EDHOC_PRK_STATE_4E3M;
|
|
759
|
-
return EDHOC_SUCCESS;
|
|
760
|
-
|
|
761
|
-
case EDHOC_METHOD_2:
|
|
762
|
-
case EDHOC_METHOD_3: {
|
|
763
|
-
const size_t hash_len =
|
|
764
|
-
ctx->csuite[ctx->chosen_csuite_idx].hash_length;
|
|
765
|
-
|
|
766
|
-
ALLOCATE_ARRAY(uint8_t, salt_4e3m, hash_len);
|
|
767
|
-
memset(salt_4e3m, 0, ALLOCATE_ARRAY_SIZEOF(salt_4e3m));
|
|
768
|
-
|
|
769
|
-
int ret = comp_salt_4e3m(ctx, salt_4e3m,
|
|
770
|
-
ARRAY_SIZE_VLA(salt_4e3m));
|
|
771
|
-
|
|
772
|
-
if (EDHOC_SUCCESS != ret)
|
|
773
|
-
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
774
|
-
|
|
775
|
-
if (NULL != ctx->logger)
|
|
776
|
-
ctx->logger(ctx->user_ctx, "SALT_4e3m",
|
|
777
|
-
salt_4e3m, ARRAY_SIZE_VLA(salt_4e3m));
|
|
778
|
-
|
|
779
|
-
const size_t ecc_key_len =
|
|
780
|
-
ctx->csuite[ctx->chosen_csuite_idx]
|
|
781
|
-
.ecc_key_length;
|
|
782
|
-
|
|
783
|
-
ALLOCATE_ARRAY(uint8_t, giy, ecc_key_len);
|
|
784
|
-
memset(giy, 0, ALLOCATE_ARRAY_SIZEOF(giy));
|
|
785
|
-
|
|
786
|
-
ret = comp_giy(role, ctx, auth_cred, pub_key,
|
|
787
|
-
pub_key_len, giy, ARRAY_SIZE_VLA(giy));
|
|
788
|
-
|
|
789
|
-
if (EDHOC_SUCCESS != ret)
|
|
790
|
-
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
791
|
-
|
|
792
|
-
if (NULL != ctx->logger)
|
|
793
|
-
ctx->logger(ctx->user_ctx, "G_IY", giy,
|
|
794
|
-
ARRAY_SIZE_VLA(giy));
|
|
795
|
-
|
|
796
|
-
ctx->prk_len =
|
|
797
|
-
ctx->csuite[ctx->chosen_csuite_idx].hash_length;
|
|
798
|
-
|
|
799
|
-
uint8_t key_id[EDHOC_KID_LEN] = { 0 };
|
|
800
|
-
ret = ctx->keys.generate_key(ctx->user_ctx,
|
|
801
|
-
EDHOC_KT_EXTRACT, giy,
|
|
802
|
-
ARRAY_SIZE_VLA(giy), key_id);
|
|
803
|
-
memset(giy, 0, ALLOCATE_ARRAY_SIZEOF(giy));
|
|
804
|
-
|
|
805
|
-
if (EDHOC_SUCCESS != ret)
|
|
806
|
-
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
807
|
-
|
|
808
|
-
size_t out_len = 0;
|
|
809
|
-
ret = ctx->crypto.extract(ctx->user_ctx, key_id,
|
|
810
|
-
salt_4e3m,
|
|
811
|
-
ARRAY_SIZE_VLA(salt_4e3m),
|
|
812
|
-
ctx->prk, ctx->prk_len,
|
|
813
|
-
&out_len);
|
|
814
|
-
ctx->keys.destroy_key(ctx->user_ctx, key_id);
|
|
815
|
-
|
|
816
|
-
if (EDHOC_SUCCESS != ret || ctx->prk_len != out_len)
|
|
817
|
-
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
818
|
-
|
|
819
|
-
ctx->prk_state = EDHOC_PRK_STATE_4E3M;
|
|
820
|
-
return EDHOC_SUCCESS;
|
|
821
|
-
}
|
|
822
|
-
default:
|
|
823
|
-
return EDHOC_ERROR_NOT_PERMITTED;
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
return EDHOC_ERROR_NOT_PERMITTED;
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
static int gen_mac_3_context(const struct edhoc_context *ctx,
|
|
831
|
-
const struct edhoc_auth_creds *auth_cred,
|
|
832
|
-
struct cbor_items *cbor_items)
|
|
833
|
-
{
|
|
834
|
-
if (NULL == ctx || NULL == auth_cred || NULL == cbor_items)
|
|
835
|
-
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
836
|
-
|
|
837
|
-
if (EDHOC_TH_STATE_3 != ctx->th_state)
|
|
838
|
-
return EDHOC_ERROR_BAD_STATE;
|
|
839
|
-
|
|
840
|
-
const size_t nr_of_items = 1;
|
|
841
|
-
|
|
842
|
-
int ret = EDHOC_ERROR_GENERIC_ERROR;
|
|
843
|
-
size_t len = 0;
|
|
844
|
-
|
|
845
|
-
/* ID_CRED_R length. */
|
|
846
|
-
cbor_items->id_cred_i = &cbor_items->buf[0];
|
|
847
|
-
|
|
848
|
-
switch (auth_cred->label) {
|
|
849
|
-
case EDHOC_COSE_HEADER_KID:
|
|
850
|
-
len += cbor_map_overhead(nr_of_items);
|
|
851
|
-
switch (auth_cred->key_id.encode_type) {
|
|
852
|
-
case EDHOC_ENCODE_TYPE_INTEGER:
|
|
853
|
-
len += cbor_int_mem_req(auth_cred->key_id.key_id_int);
|
|
854
|
-
break;
|
|
855
|
-
case EDHOC_ENCODE_TYPE_BYTE_STRING:
|
|
856
|
-
len += auth_cred->key_id.key_id_bstr_length;
|
|
857
|
-
len += cbor_bstr_overhead(
|
|
858
|
-
auth_cred->key_id.key_id_bstr_length);
|
|
859
|
-
break;
|
|
860
|
-
default:
|
|
861
|
-
return EDHOC_ERROR_NOT_PERMITTED;
|
|
862
|
-
}
|
|
863
|
-
if (is_cbor_one_byte_int(auth_cred->key_id.key_id_int))
|
|
864
|
-
cbor_items->id_cred_i_is_cob = true;
|
|
865
|
-
|
|
866
|
-
break;
|
|
867
|
-
|
|
868
|
-
case EDHOC_COSE_HEADER_X509_CHAIN: {
|
|
869
|
-
len += cbor_map_overhead(nr_of_items);
|
|
870
|
-
|
|
871
|
-
for (size_t i = 0; i < auth_cred->x509_chain.nr_of_certs; ++i) {
|
|
872
|
-
len += auth_cred->x509_chain.cert_len[i];
|
|
873
|
-
len += cbor_bstr_overhead(
|
|
874
|
-
auth_cred->x509_chain.cert_len[i]);
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
if (1 < auth_cred->x509_chain.nr_of_certs)
|
|
878
|
-
len += cbor_array_overhead(
|
|
879
|
-
auth_cred->x509_chain.nr_of_certs);
|
|
880
|
-
|
|
881
|
-
break;
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
case EDHOC_COSE_HEADER_X509_HASH:
|
|
885
|
-
len += cbor_map_overhead(nr_of_items);
|
|
886
|
-
len += cbor_array_overhead(nr_of_items);
|
|
887
|
-
|
|
888
|
-
switch (auth_cred->x509_hash.encode_type) {
|
|
889
|
-
case EDHOC_ENCODE_TYPE_INTEGER:
|
|
890
|
-
len += cbor_int_mem_req(auth_cred->x509_hash.alg_int);
|
|
891
|
-
break;
|
|
892
|
-
case EDHOC_ENCODE_TYPE_BYTE_STRING:
|
|
893
|
-
len += auth_cred->x509_hash.alg_bstr_length;
|
|
894
|
-
len += cbor_bstr_overhead(
|
|
895
|
-
auth_cred->x509_hash.alg_bstr_length);
|
|
896
|
-
break;
|
|
897
|
-
default:
|
|
898
|
-
return EDHOC_ERROR_NOT_PERMITTED;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
len += auth_cred->x509_hash.cert_fp_len + 1;
|
|
902
|
-
len += cbor_bstr_overhead(auth_cred->x509_hash.cert_fp_len);
|
|
903
|
-
break;
|
|
904
|
-
|
|
905
|
-
default:
|
|
906
|
-
return EDHOC_ERROR_CREDENTIALS_FAILURE;
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
cbor_items->id_cred_i_len = len;
|
|
910
|
-
|
|
911
|
-
/* Cborise ID_CRED_R. */
|
|
912
|
-
struct id_cred_x cbor_id_cred_i = { 0 };
|
|
913
|
-
|
|
914
|
-
switch (auth_cred->label) {
|
|
915
|
-
case EDHOC_COSE_HEADER_KID: {
|
|
916
|
-
cbor_id_cred_i._id_cred_x_kid_present = true;
|
|
917
|
-
|
|
918
|
-
switch (auth_cred->key_id.encode_type) {
|
|
919
|
-
case EDHOC_ENCODE_TYPE_INTEGER:
|
|
920
|
-
cbor_id_cred_i._id_cred_x_kid._id_cred_x_kid_choice =
|
|
921
|
-
_id_cred_x_kid_int;
|
|
922
|
-
cbor_id_cred_i._id_cred_x_kid._id_cred_x_kid_int =
|
|
923
|
-
auth_cred->key_id.key_id_int;
|
|
924
|
-
break;
|
|
925
|
-
case EDHOC_ENCODE_TYPE_BYTE_STRING:
|
|
926
|
-
cbor_id_cred_i._id_cred_x_kid._id_cred_x_kid_choice =
|
|
927
|
-
_id_cred_x_kid_bstr;
|
|
928
|
-
cbor_id_cred_i._id_cred_x_kid._id_cred_x_kid_bstr.value =
|
|
929
|
-
auth_cred->key_id.key_id_bstr;
|
|
930
|
-
cbor_id_cred_i._id_cred_x_kid._id_cred_x_kid_bstr.len =
|
|
931
|
-
auth_cred->key_id.key_id_bstr_length;
|
|
932
|
-
break;
|
|
933
|
-
default:
|
|
934
|
-
return EDHOC_ERROR_NOT_PERMITTED;
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
break;
|
|
938
|
-
}
|
|
939
|
-
case EDHOC_COSE_HEADER_X509_CHAIN: {
|
|
940
|
-
cbor_id_cred_i._id_cred_x_x5chain_present = true;
|
|
941
|
-
|
|
942
|
-
struct COSE_X509_ *cose_x509 =
|
|
943
|
-
&cbor_id_cred_i._id_cred_x_x5chain._id_cred_x_x5chain;
|
|
944
|
-
|
|
945
|
-
if (1 == auth_cred->x509_chain.nr_of_certs) {
|
|
946
|
-
cose_x509->_COSE_X509_choice = _COSE_X509_bstr;
|
|
947
|
-
cose_x509->_COSE_X509_bstr.value =
|
|
948
|
-
auth_cred->x509_chain.cert[0];
|
|
949
|
-
cose_x509->_COSE_X509_bstr.len =
|
|
950
|
-
auth_cred->x509_chain.cert_len[0];
|
|
951
|
-
} else {
|
|
952
|
-
cose_x509->_COSE_X509_choice = _COSE_X509__certs;
|
|
953
|
-
cose_x509->_COSE_X509__certs_certs_count =
|
|
954
|
-
auth_cred->x509_chain.nr_of_certs;
|
|
955
|
-
|
|
956
|
-
for (size_t i = 0;
|
|
957
|
-
i < auth_cred->x509_chain.nr_of_certs; ++i) {
|
|
958
|
-
cose_x509->_COSE_X509__certs_certs[i].value =
|
|
959
|
-
auth_cred->x509_chain.cert[i];
|
|
960
|
-
cose_x509->_COSE_X509__certs_certs[i].len =
|
|
961
|
-
auth_cred->x509_chain.cert_len[i];
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
break;
|
|
966
|
-
}
|
|
967
|
-
case EDHOC_COSE_HEADER_X509_HASH: {
|
|
968
|
-
cbor_id_cred_i._id_cred_x_x5t_present = true;
|
|
969
|
-
|
|
970
|
-
struct COSE_CertHash *cose_x509 =
|
|
971
|
-
&cbor_id_cred_i._id_cred_x_x5t._id_cred_x_x5t;
|
|
972
|
-
|
|
973
|
-
cose_x509->_COSE_CertHash_hashValue.value =
|
|
974
|
-
auth_cred->x509_hash.cert_fp;
|
|
975
|
-
cose_x509->_COSE_CertHash_hashValue.len =
|
|
976
|
-
auth_cred->x509_hash.cert_fp_len;
|
|
977
|
-
|
|
978
|
-
switch (auth_cred->x509_hash.encode_type) {
|
|
979
|
-
case EDHOC_ENCODE_TYPE_INTEGER:
|
|
980
|
-
cose_x509->_COSE_CertHash_hashAlg_choice =
|
|
981
|
-
_COSE_CertHash_hashAlg_int;
|
|
982
|
-
cose_x509->_COSE_CertHash_hashAlg_int =
|
|
983
|
-
auth_cred->x509_hash.alg_int;
|
|
984
|
-
break;
|
|
985
|
-
case EDHOC_ENCODE_TYPE_BYTE_STRING:
|
|
986
|
-
cose_x509->_COSE_CertHash_hashAlg_choice =
|
|
987
|
-
_COSE_CertHash_hashAlg_tstr;
|
|
988
|
-
cose_x509->_COSE_CertHash_hashAlg_tstr.value =
|
|
989
|
-
auth_cred->x509_hash.alg_bstr;
|
|
990
|
-
cose_x509->_COSE_CertHash_hashAlg_tstr.len =
|
|
991
|
-
auth_cred->x509_hash.alg_bstr_length;
|
|
992
|
-
break;
|
|
993
|
-
default:
|
|
994
|
-
return EDHOC_ERROR_NOT_PERMITTED;
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
break;
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
default:
|
|
1001
|
-
return EDHOC_ERROR_CREDENTIALS_FAILURE;
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
len = 0;
|
|
1005
|
-
ret = cbor_encode_id_cred_x(cbor_items->id_cred_i,
|
|
1006
|
-
cbor_items->id_cred_i_len, &cbor_id_cred_i,
|
|
1007
|
-
&len);
|
|
1008
|
-
if (ZCBOR_SUCCESS != ret)
|
|
1009
|
-
return EDHOC_ERROR_CBOR_FAILURE;
|
|
1010
|
-
|
|
1011
|
-
cbor_items->id_cred_i_len = len;
|
|
1012
|
-
|
|
1013
|
-
/* Check compact encoding of ID_CRED_I. */
|
|
1014
|
-
if (EDHOC_COSE_HEADER_KID == auth_cred->label) {
|
|
1015
|
-
ret = kid_compact_encoding(auth_cred, cbor_items);
|
|
1016
|
-
|
|
1017
|
-
if (EDHOC_SUCCESS != ret)
|
|
1018
|
-
return EDHOC_ERROR_CBOR_FAILURE;
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
/* TH_3 length. */
|
|
1022
|
-
len = ctx->th_len;
|
|
1023
|
-
cbor_items->th_3 = &cbor_items->id_cred_i[cbor_items->id_cred_i_len];
|
|
1024
|
-
cbor_items->th_3_len = cbor_bstr_overhead(len) + len;
|
|
1025
|
-
|
|
1026
|
-
/* Cborise TH_3. */
|
|
1027
|
-
const struct zcbor_string cbor_th_3 = {
|
|
1028
|
-
.value = ctx->th,
|
|
1029
|
-
.len = ctx->th_len,
|
|
1030
|
-
};
|
|
1031
|
-
|
|
1032
|
-
len = 0;
|
|
1033
|
-
ret = cbor_encode_byte_string_type_bstr_type(
|
|
1034
|
-
cbor_items->th_3, cbor_items->th_3_len, &cbor_th_3, &len);
|
|
1035
|
-
|
|
1036
|
-
if (ZCBOR_SUCCESS != ret || cbor_items->th_3_len != len)
|
|
1037
|
-
return EDHOC_ERROR_CBOR_FAILURE;
|
|
1038
|
-
|
|
1039
|
-
/* CRED_R length. */
|
|
1040
|
-
cbor_items->cred_i = &cbor_items->th_3[cbor_items->th_3_len];
|
|
1041
|
-
len = 0;
|
|
1042
|
-
|
|
1043
|
-
switch (auth_cred->label) {
|
|
1044
|
-
case EDHOC_COSE_HEADER_KID:
|
|
1045
|
-
len += auth_cred->key_id.cred_len;
|
|
1046
|
-
len += cbor_bstr_overhead(auth_cred->key_id.cred_len);
|
|
1047
|
-
break;
|
|
1048
|
-
|
|
1049
|
-
case EDHOC_COSE_HEADER_X509_CHAIN: {
|
|
1050
|
-
const size_t end_entity_idx =
|
|
1051
|
-
auth_cred->x509_chain.nr_of_certs - 1;
|
|
1052
|
-
len += auth_cred->x509_chain.cert_len[end_entity_idx];
|
|
1053
|
-
len += cbor_bstr_overhead(
|
|
1054
|
-
auth_cred->x509_chain.cert_len[end_entity_idx]);
|
|
1055
|
-
break;
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
case EDHOC_COSE_HEADER_X509_HASH:
|
|
1059
|
-
len += auth_cred->x509_hash.cert_len;
|
|
1060
|
-
len += cbor_bstr_overhead(auth_cred->x509_hash.cert_len);
|
|
1061
|
-
break;
|
|
1062
|
-
|
|
1063
|
-
default:
|
|
1064
|
-
return EDHOC_ERROR_CREDENTIALS_FAILURE;
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
cbor_items->cred_i_len = len;
|
|
1068
|
-
|
|
1069
|
-
/* Cborise CRED_R. */
|
|
1070
|
-
struct zcbor_string cbor_cred_i = { 0 };
|
|
1071
|
-
|
|
1072
|
-
switch (auth_cred->label) {
|
|
1073
|
-
case EDHOC_COSE_HEADER_KID:
|
|
1074
|
-
cbor_cred_i.value = auth_cred->key_id.cred;
|
|
1075
|
-
cbor_cred_i.len = auth_cred->key_id.cred_len;
|
|
1076
|
-
break;
|
|
1077
|
-
|
|
1078
|
-
case EDHOC_COSE_HEADER_X509_CHAIN: {
|
|
1079
|
-
const size_t end_entity_idx =
|
|
1080
|
-
auth_cred->x509_chain.nr_of_certs - 1;
|
|
1081
|
-
cbor_cred_i.value = auth_cred->x509_chain.cert[end_entity_idx];
|
|
1082
|
-
cbor_cred_i.len =
|
|
1083
|
-
auth_cred->x509_chain.cert_len[end_entity_idx];
|
|
1084
|
-
break;
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
case EDHOC_COSE_HEADER_X509_HASH:
|
|
1088
|
-
cbor_cred_i.value = auth_cred->x509_hash.cert;
|
|
1089
|
-
cbor_cred_i.len = auth_cred->x509_hash.cert_len;
|
|
1090
|
-
break;
|
|
1091
|
-
|
|
1092
|
-
default:
|
|
1093
|
-
return EDHOC_ERROR_CREDENTIALS_FAILURE;
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
if (EDHOC_COSE_HEADER_KID == auth_cred->label &&
|
|
1097
|
-
true == auth_cred->key_id.cred_is_cbor) {
|
|
1098
|
-
memcpy(cbor_items->cred_i, auth_cred->key_id.cred,
|
|
1099
|
-
auth_cred->key_id.cred_len);
|
|
1100
|
-
cbor_items->cred_i_len = auth_cred->key_id.cred_len;
|
|
1101
|
-
} else {
|
|
1102
|
-
len = 0;
|
|
1103
|
-
ret = cbor_encode_byte_string_type_bstr_type(
|
|
1104
|
-
cbor_items->cred_i, cbor_items->cred_i_len,
|
|
1105
|
-
&cbor_cred_i, &len);
|
|
1106
|
-
|
|
1107
|
-
if (ZCBOR_SUCCESS != ret || cbor_items->cred_i_len != len)
|
|
1108
|
-
return EDHOC_ERROR_CBOR_FAILURE;
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
/* EAD_3 length. */
|
|
1112
|
-
if (0 != ctx->nr_of_ead_tokens) {
|
|
1113
|
-
len = 0;
|
|
1114
|
-
for (size_t i = 0; i < ctx->nr_of_ead_tokens; ++i) {
|
|
1115
|
-
len += cbor_int_mem_req(ctx->ead_token[i].label);
|
|
1116
|
-
len += 1; // cbor boolean
|
|
1117
|
-
len += ctx->ead_token[i].value_len;
|
|
1118
|
-
len += cbor_bstr_overhead(ctx->ead_token[i].value_len);
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
cbor_items->is_ead_3 = true;
|
|
1122
|
-
cbor_items->ead_3 = &cbor_items->cred_i[cbor_items->cred_i_len];
|
|
1123
|
-
cbor_items->ead_3_len = len;
|
|
1124
|
-
} else {
|
|
1125
|
-
cbor_items->is_ead_3 = false;
|
|
1126
|
-
cbor_items->ead_3 = NULL;
|
|
1127
|
-
cbor_items->ead_3_len = 0;
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
/* Cborise EAD_3 if present. */
|
|
1131
|
-
if (true == cbor_items->is_ead_3) {
|
|
1132
|
-
struct ead_ ead_tokens = { ._ead_count =
|
|
1133
|
-
ctx->nr_of_ead_tokens };
|
|
1134
|
-
|
|
1135
|
-
for (size_t i = 0; i < ctx->nr_of_ead_tokens; ++i) {
|
|
1136
|
-
ead_tokens._ead[i]._ead_label = ctx->ead_token[i].label;
|
|
1137
|
-
ead_tokens._ead[i]._ead_value_present =
|
|
1138
|
-
(NULL != ctx->ead_token[i].value);
|
|
1139
|
-
ead_tokens._ead[i]._ead_value.value =
|
|
1140
|
-
ctx->ead_token[i].value;
|
|
1141
|
-
ead_tokens._ead[i]._ead_value.len =
|
|
1142
|
-
ctx->ead_token[i].value_len;
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
len = 0;
|
|
1146
|
-
ret = cbor_encode_ead(cbor_items->ead_3, cbor_items->ead_3_len,
|
|
1147
|
-
&ead_tokens, &len);
|
|
1148
|
-
|
|
1149
|
-
if (ZCBOR_SUCCESS != ret)
|
|
1150
|
-
return EDHOC_ERROR_CBOR_FAILURE;
|
|
1151
|
-
|
|
1152
|
-
cbor_items->ead_3_len = len;
|
|
1153
|
-
}
|
|
150
|
+
*/
|
|
151
|
+
static int comp_ciphertext(const struct edhoc_context *ctx, const uint8_t *key,
|
|
152
|
+
size_t key_len, const uint8_t *iv, size_t iv_len,
|
|
153
|
+
const uint8_t *aad, size_t aad_len,
|
|
154
|
+
const uint8_t *ptxt, size_t ptxt_len, uint8_t *ctxt,
|
|
155
|
+
size_t ctxt_size, size_t *ctxt_len);
|
|
1154
156
|
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
157
|
+
/**
|
|
158
|
+
* \brief Compute transcript hash 4.
|
|
159
|
+
*
|
|
160
|
+
* \param[in,out] ctx EDHOC context.
|
|
161
|
+
* \param[in] mac_ctx MAC context.
|
|
162
|
+
* \param[in] ptxt Buffer containing the PLAINTEXT_3.
|
|
163
|
+
* \param ptxt_len Size of the \p ptxt buffer in bytes.
|
|
164
|
+
*
|
|
165
|
+
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
166
|
+
*/
|
|
167
|
+
static int comp_th_4(struct edhoc_context *ctx,
|
|
168
|
+
const struct mac_context *mac_ctx, const uint8_t *ptxt,
|
|
169
|
+
size_t ptxt_len);
|
|
1158
170
|
|
|
1159
|
-
|
|
1160
|
-
|
|
171
|
+
/**
|
|
172
|
+
* \brief Generate edhoc message 3.
|
|
173
|
+
*
|
|
174
|
+
* \param[in] ctxt Buffer continas the ciphertext.
|
|
175
|
+
* \param ctxt_len Size of the \p ctxt buffer in bytes.
|
|
176
|
+
* \param[out] msg_3 Buffer where the generated message 3 is to be written.
|
|
177
|
+
* \param msg_3_size Size of the \p msg_3 buffer in bytes.
|
|
178
|
+
* \param[out] msg_3_len On success, the number of bytes that make up the message 3.
|
|
179
|
+
*
|
|
180
|
+
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
181
|
+
*/
|
|
182
|
+
static int gen_msg_3(const uint8_t *ctxt, size_t ctxt_len, uint8_t *msg_3,
|
|
183
|
+
size_t msg_3_size, size_t *msg_3_len);
|
|
1161
184
|
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
185
|
+
/**
|
|
186
|
+
* \brief CBOR decode message 3 and save address and length for CIPHERTEXT_3.
|
|
187
|
+
*
|
|
188
|
+
* \param[in] msg_3 Buffer containing the message 3.
|
|
189
|
+
* \param msg_3_len Size of the \p msg_3 buffer in bytes.
|
|
190
|
+
* \param[out] ctxt_3 Pointer to buffer containing the CIPHERTEXT_3.
|
|
191
|
+
* \param[out] ctxt_3_len Size of the \p ctxt_3 buffer in bytes.
|
|
192
|
+
*
|
|
193
|
+
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
194
|
+
*/
|
|
195
|
+
static int parse_msg_3(const uint8_t *msg_3, size_t msg_3_len,
|
|
196
|
+
const uint8_t **ctxt_3, size_t *ctxt_3_len);
|
|
1165
197
|
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
198
|
+
/**
|
|
199
|
+
* \brief Decrypt CIPHERTEXT_3.
|
|
200
|
+
*
|
|
201
|
+
* \param[in] ctx EDHOC context.
|
|
202
|
+
* \param[in] key Buffer containing the K_3.
|
|
203
|
+
* \param key_len Size of the \p key buffer in bytes.
|
|
204
|
+
* \param[in] iv Buffer containing the IV_3.
|
|
205
|
+
* \param iv_len Size of the \p iv buffer in bytes.
|
|
206
|
+
* \param[in] aad Buffer containing the AAD_3.
|
|
207
|
+
* \param aad_len Size of the \p aad buffer in bytes.
|
|
208
|
+
* \param[in] ctxt Pointer to buffer containing the CIPHERTEXT_3.
|
|
209
|
+
* \param ctxt_len Size of the \p ctxt buffer in bytes.
|
|
210
|
+
* \param[out] ptxt Buffer where the decrypted PLAINTEXT_3 is to be written.
|
|
211
|
+
* \param ptxt_len Size of the \p ptxt buffer in bytes.
|
|
212
|
+
*
|
|
213
|
+
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
214
|
+
*/
|
|
215
|
+
static int decrypt_ciphertext(const struct edhoc_context *ctx,
|
|
216
|
+
const uint8_t *key, size_t key_len,
|
|
217
|
+
const uint8_t *iv, size_t iv_len,
|
|
218
|
+
const uint8_t *aad, size_t aad_len,
|
|
219
|
+
const uint8_t *ctxt, size_t ctxt_len,
|
|
220
|
+
uint8_t *ptxt, size_t ptxt_len);
|
|
1171
221
|
|
|
1172
|
-
|
|
1173
|
-
|
|
222
|
+
/**
|
|
223
|
+
* \brief Parsed cborised PLAINTEXT_3 for separate buffers.
|
|
224
|
+
*
|
|
225
|
+
* \param[in] ctx EDHOC context.
|
|
226
|
+
* \param[in] ptxt Buffer containing the PLAINTEXT_3.
|
|
227
|
+
* \param ptxt_len Size of the \p ptxt buffer in bytes.
|
|
228
|
+
* \param[out] parsed_ptxt Structure where parsed PLAINTEXT_3 is to be written.
|
|
229
|
+
*
|
|
230
|
+
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
231
|
+
*/
|
|
232
|
+
static int parse_plaintext(struct edhoc_context *ctx, const uint8_t *ptxt,
|
|
233
|
+
size_t ptxt_len, struct plaintext *parsed_ptxt);
|
|
1174
234
|
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
235
|
+
/**
|
|
236
|
+
* \brief Compute SALT_4e3m.
|
|
237
|
+
*
|
|
238
|
+
* \param[in] ctx EDHOC context.
|
|
239
|
+
* \param[out] salt Buffer where the generated salt is to be written.
|
|
240
|
+
* \param salt_len Size of the \p salt buffer in bytes.
|
|
241
|
+
*
|
|
242
|
+
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
243
|
+
*/
|
|
244
|
+
static int comp_salt_4e3m(const struct edhoc_context *ctx, uint8_t *salt,
|
|
245
|
+
size_t salt_len);
|
|
1188
246
|
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
247
|
+
/**
|
|
248
|
+
* \brief Compute G_IY for PRK_4e3m.
|
|
249
|
+
*
|
|
250
|
+
* \param[in,out] ctx EDHOC context.
|
|
251
|
+
* \param[in] auth_cred Authentication credentials.
|
|
252
|
+
* \param[in] pub_key Peer public key.
|
|
253
|
+
* \param pub_key_len Peer public key length.
|
|
254
|
+
* \param[out] giy Buffer where the generated G_IY is to be written.
|
|
255
|
+
* \param giy_len Size of the \p giy buffer in bytes.
|
|
256
|
+
*
|
|
257
|
+
* \return EDHOC_SUCCESS on success, otherwise failure.
|
|
258
|
+
*/
|
|
259
|
+
static int comp_giy(struct edhoc_context *ctx,
|
|
260
|
+
const struct edhoc_auth_creds *auth_cred,
|
|
261
|
+
const uint8_t *pub_key, size_t pub_key_len, uint8_t *giy,
|
|
262
|
+
size_t giy_len);
|
|
1202
263
|
|
|
1203
|
-
|
|
1204
|
-
}
|
|
264
|
+
/* Static function definitions --------------------------------------------- */
|
|
1205
265
|
|
|
1206
|
-
static int
|
|
1207
|
-
|
|
1208
|
-
|
|
266
|
+
static int comp_prk_4e3m(struct edhoc_context *ctx,
|
|
267
|
+
const struct edhoc_auth_creds *auth_cred,
|
|
268
|
+
const uint8_t *pub_key, size_t pub_key_len)
|
|
1209
269
|
{
|
|
1210
|
-
if (NULL == ctx || NULL ==
|
|
1211
|
-
0 == mac_3_len)
|
|
270
|
+
if (NULL == ctx || NULL == auth_cred)
|
|
1212
271
|
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
1213
272
|
|
|
1214
|
-
if (
|
|
273
|
+
if (EDHOC_PRK_STATE_3E2M != ctx->prk_state)
|
|
1215
274
|
return EDHOC_ERROR_BAD_STATE;
|
|
1216
275
|
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
._info_context.len = cbor_items->buf_len,
|
|
1223
|
-
._info_length = (uint32_t)mac_3_len,
|
|
1224
|
-
};
|
|
1225
|
-
|
|
1226
|
-
/* Calculate struct info cbor overhead. */
|
|
1227
|
-
size_t len = 0;
|
|
1228
|
-
len += cbor_int_mem_req(EDHOC_EXTRACT_PRK_INFO_LABEL_MAC_3);
|
|
1229
|
-
len += cbor_items->buf_len + cbor_bstr_overhead(cbor_items->buf_len);
|
|
1230
|
-
len += cbor_int_mem_req((int32_t)mac_3_len);
|
|
1231
|
-
|
|
1232
|
-
ALLOCATE_ARRAY(uint8_t, info, len);
|
|
1233
|
-
memset(info, 0, ALLOCATE_ARRAY_SIZEOF(info));
|
|
1234
|
-
|
|
1235
|
-
len = 0;
|
|
1236
|
-
ret = cbor_encode_info(info, ARRAY_SIZE_VLA(info), &input_info, &len);
|
|
276
|
+
switch (ctx->chosen_method) {
|
|
277
|
+
case EDHOC_METHOD_0:
|
|
278
|
+
case EDHOC_METHOD_1:
|
|
279
|
+
ctx->prk_state = EDHOC_PRK_STATE_4E3M;
|
|
280
|
+
return EDHOC_SUCCESS;
|
|
1237
281
|
|
|
1238
|
-
|
|
1239
|
-
|
|
282
|
+
case EDHOC_METHOD_2:
|
|
283
|
+
case EDHOC_METHOD_3: {
|
|
284
|
+
const size_t hash_len =
|
|
285
|
+
ctx->csuite[ctx->chosen_csuite_idx].hash_length;
|
|
1240
286
|
|
|
1241
|
-
|
|
1242
|
-
|
|
287
|
+
VLA_ALLOC(uint8_t, salt_4e3m, hash_len);
|
|
288
|
+
memset(salt_4e3m, 0, VLA_SIZEOF(salt_4e3m));
|
|
1243
289
|
|
|
1244
|
-
|
|
1245
|
-
ret = ctx->keys.generate_key(ctx->user_ctx, EDHOC_KT_EXPAND, ctx->prk,
|
|
1246
|
-
ctx->prk_len, key_id);
|
|
290
|
+
int ret = comp_salt_4e3m(ctx, salt_4e3m, VLA_SIZE(salt_4e3m));
|
|
1247
291
|
|
|
1248
|
-
|
|
1249
|
-
|
|
292
|
+
if (EDHOC_SUCCESS != ret)
|
|
293
|
+
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
1250
294
|
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
memset(key_id, 0, sizeof(key_id));
|
|
295
|
+
if (NULL != ctx->logger)
|
|
296
|
+
ctx->logger(ctx->user_ctx, "SALT_4e3m", salt_4e3m,
|
|
297
|
+
VLA_SIZE(salt_4e3m));
|
|
1255
298
|
|
|
1256
|
-
|
|
1257
|
-
|
|
299
|
+
const size_t ecc_key_len =
|
|
300
|
+
ctx->csuite[ctx->chosen_csuite_idx].ecc_key_length;
|
|
1258
301
|
|
|
1259
|
-
|
|
1260
|
-
|
|
302
|
+
VLA_ALLOC(uint8_t, giy, ecc_key_len);
|
|
303
|
+
memset(giy, 0, VLA_SIZEOF(giy));
|
|
1261
304
|
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
size_t *sign_or_mac_3_len)
|
|
1265
|
-
{
|
|
1266
|
-
if (NULL == ctx || NULL == sign_or_mac_3_len)
|
|
1267
|
-
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
305
|
+
ret = comp_giy(ctx, auth_cred, pub_key, pub_key_len, giy,
|
|
306
|
+
VLA_SIZE(giy));
|
|
1268
307
|
|
|
1269
|
-
|
|
1270
|
-
|
|
308
|
+
if (EDHOC_SUCCESS != ret)
|
|
309
|
+
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
1271
310
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
case EDHOC_METHOD_0:
|
|
1275
|
-
case EDHOC_METHOD_1:
|
|
1276
|
-
*sign_or_mac_3_len = csuite.ecc_sign_length;
|
|
1277
|
-
return EDHOC_SUCCESS;
|
|
1278
|
-
|
|
1279
|
-
case EDHOC_METHOD_2:
|
|
1280
|
-
case EDHOC_METHOD_3:
|
|
1281
|
-
*sign_or_mac_3_len = csuite.mac_length;
|
|
1282
|
-
return EDHOC_SUCCESS;
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
311
|
+
if (NULL != ctx->logger)
|
|
312
|
+
ctx->logger(ctx->user_ctx, "G_IY", giy, VLA_SIZE(giy));
|
|
1285
313
|
|
|
1286
|
-
|
|
1287
|
-
switch (ctx->method) {
|
|
1288
|
-
case EDHOC_METHOD_0:
|
|
1289
|
-
case EDHOC_METHOD_1:
|
|
1290
|
-
*sign_or_mac_3_len = csuite.ecc_sign_length;
|
|
1291
|
-
return EDHOC_SUCCESS;
|
|
1292
|
-
|
|
1293
|
-
case EDHOC_METHOD_2:
|
|
1294
|
-
case EDHOC_METHOD_3:
|
|
1295
|
-
*sign_or_mac_3_len = csuite.mac_length;
|
|
1296
|
-
return EDHOC_SUCCESS;
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
314
|
+
ctx->prk_len = ctx->csuite[ctx->chosen_csuite_idx].hash_length;
|
|
1299
315
|
|
|
1300
|
-
|
|
1301
|
-
|
|
316
|
+
uint8_t key_id[CONFIG_LIBEDHOC_KEY_ID_LEN] = { 0 };
|
|
317
|
+
ret = ctx->keys.import_key(ctx->user_ctx, EDHOC_KT_EXTRACT, giy,
|
|
318
|
+
VLA_SIZE(giy), key_id);
|
|
319
|
+
memset(giy, 0, VLA_SIZEOF(giy));
|
|
1302
320
|
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
const struct cbor_items *cbor_items,
|
|
1306
|
-
const uint8_t *mac_3, size_t mac_3_len,
|
|
1307
|
-
uint8_t *sign, size_t sign_len)
|
|
1308
|
-
{
|
|
1309
|
-
if (NULL == ctx || NULL == auth_creds || NULL == cbor_items ||
|
|
1310
|
-
NULL == mac_3 || 0 == mac_3_len || NULL == sign || 0 == sign_len)
|
|
1311
|
-
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
321
|
+
if (EDHOC_SUCCESS != ret)
|
|
322
|
+
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
1312
323
|
|
|
1313
|
-
|
|
324
|
+
size_t out_len = 0;
|
|
325
|
+
ret = ctx->crypto.extract(ctx->user_ctx, key_id, salt_4e3m,
|
|
326
|
+
VLA_SIZE(salt_4e3m), ctx->prk,
|
|
327
|
+
ctx->prk_len, &out_len);
|
|
328
|
+
ctx->keys.destroy_key(ctx->user_ctx, key_id);
|
|
1314
329
|
|
|
1315
|
-
|
|
1316
|
-
case EDHOC_METHOD_0:
|
|
1317
|
-
case EDHOC_METHOD_1: {
|
|
1318
|
-
const struct sig_structure cose_sign_1 = {
|
|
1319
|
-
._sig_structure_protected.value = cbor_items->id_cred_i,
|
|
1320
|
-
._sig_structure_protected.len =
|
|
1321
|
-
cbor_items->id_cred_i_len,
|
|
1322
|
-
._sig_structure_external_aad.value = cbor_items->th_3,
|
|
1323
|
-
._sig_structure_external_aad.len =
|
|
1324
|
-
cbor_items->th_3_len + cbor_items->cred_i_len +
|
|
1325
|
-
cbor_items->ead_3_len,
|
|
1326
|
-
._sig_structure_payload.value = mac_3,
|
|
1327
|
-
._sig_structure_payload.len = mac_3_len,
|
|
1328
|
-
};
|
|
1329
|
-
|
|
1330
|
-
size_t len = 0;
|
|
1331
|
-
len += sizeof("Signature1") +
|
|
1332
|
-
cbor_tstr_overhead(sizeof("Signature1"));
|
|
1333
|
-
len += cbor_items->id_cred_i_len +
|
|
1334
|
-
cbor_bstr_overhead(cbor_items->id_cred_i_len);
|
|
1335
|
-
len += cbor_items->th_3_len + cbor_items->cred_i_len +
|
|
1336
|
-
cbor_items->ead_3_len +
|
|
1337
|
-
cbor_bstr_overhead(cbor_items->th_3_len +
|
|
1338
|
-
cbor_items->cred_i_len +
|
|
1339
|
-
cbor_items->ead_3_len);
|
|
1340
|
-
len += mac_3_len + cbor_bstr_overhead(mac_3_len);
|
|
1341
|
-
|
|
1342
|
-
ALLOCATE_ARRAY(uint8_t, cose_sign_1_buf, len);
|
|
1343
|
-
memset(cose_sign_1_buf, 0, ALLOCATE_ARRAY_SIZEOF(cose_sign_1_buf));
|
|
1344
|
-
|
|
1345
|
-
len = 0;
|
|
1346
|
-
ret = cbor_encode_sig_structure(cose_sign_1_buf,
|
|
1347
|
-
ARRAY_SIZE_VLA(cose_sign_1_buf),
|
|
1348
|
-
&cose_sign_1, &len);
|
|
1349
|
-
|
|
1350
|
-
if (ZCBOR_SUCCESS != ret)
|
|
1351
|
-
return EDHOC_ERROR_CBOR_FAILURE;
|
|
1352
|
-
|
|
1353
|
-
const size_t cose_sign_1_buf_len = len;
|
|
1354
|
-
|
|
1355
|
-
len = 0;
|
|
1356
|
-
ret = ctx->crypto.signature(
|
|
1357
|
-
ctx->user_ctx, auth_creds->priv_key_id, cose_sign_1_buf,
|
|
1358
|
-
cose_sign_1_buf_len, sign, sign_len, &len);
|
|
1359
|
-
|
|
1360
|
-
if (EDHOC_SUCCESS != ret || sign_len != len)
|
|
330
|
+
if (EDHOC_SUCCESS != ret || ctx->prk_len != out_len)
|
|
1361
331
|
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
1362
332
|
|
|
333
|
+
ctx->prk_state = EDHOC_PRK_STATE_4E3M;
|
|
1363
334
|
return EDHOC_SUCCESS;
|
|
1364
335
|
}
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
case EDHOC_METHOD_3:
|
|
1368
|
-
memcpy(sign, mac_3, mac_3_len);
|
|
1369
|
-
return EDHOC_SUCCESS;
|
|
336
|
+
case EDHOC_METHOD_MAX:
|
|
337
|
+
return EDHOC_ERROR_NOT_PERMITTED;
|
|
1370
338
|
}
|
|
1371
339
|
|
|
1372
|
-
return
|
|
340
|
+
return EDHOC_ERROR_NOT_PERMITTED;
|
|
1373
341
|
}
|
|
1374
342
|
|
|
1375
343
|
static int comp_plaintext_3_len(const struct edhoc_context *ctx,
|
|
1376
|
-
const struct
|
|
344
|
+
const struct mac_context *mac_ctx,
|
|
1377
345
|
size_t sign_len, size_t *plaintext_3_len)
|
|
1378
346
|
{
|
|
1379
|
-
if (NULL == ctx || NULL ==
|
|
347
|
+
if (NULL == ctx || NULL == mac_ctx || 0 == sign_len ||
|
|
1380
348
|
NULL == plaintext_3_len)
|
|
1381
349
|
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
1382
350
|
|
|
@@ -1384,65 +352,67 @@ static int comp_plaintext_3_len(const struct edhoc_context *ctx,
|
|
|
1384
352
|
|
|
1385
353
|
switch (ctx->cid.encode_type) {
|
|
1386
354
|
case EDHOC_CID_TYPE_ONE_BYTE_INTEGER:
|
|
1387
|
-
len +=
|
|
355
|
+
len += edhoc_cbor_int_mem_req(ctx->cid.int_value);
|
|
1388
356
|
break;
|
|
1389
357
|
case EDHOC_CID_TYPE_BYTE_STRING:
|
|
1390
358
|
len += ctx->cid.bstr_length;
|
|
1391
|
-
len +=
|
|
359
|
+
len += edhoc_cbor_bstr_oh(ctx->cid.bstr_length);
|
|
1392
360
|
break;
|
|
1393
361
|
}
|
|
1394
362
|
|
|
1395
|
-
if (true ==
|
|
1396
|
-
switch (
|
|
363
|
+
if (true == mac_ctx->id_cred_is_comp_enc) {
|
|
364
|
+
switch (mac_ctx->id_cred_enc_type) {
|
|
1397
365
|
case EDHOC_ENCODE_TYPE_INTEGER:
|
|
1398
|
-
len +=
|
|
366
|
+
len += edhoc_cbor_int_mem_req(mac_ctx->id_cred_int);
|
|
1399
367
|
break;
|
|
1400
368
|
case EDHOC_ENCODE_TYPE_BYTE_STRING:
|
|
1401
|
-
len +=
|
|
1402
|
-
len +=
|
|
1403
|
-
cbor_items->id_cred_i_bstr_len);
|
|
369
|
+
len += mac_ctx->id_cred_bstr_len;
|
|
370
|
+
len += edhoc_cbor_bstr_oh(mac_ctx->id_cred_bstr_len);
|
|
1404
371
|
break;
|
|
1405
372
|
}
|
|
1406
373
|
} else {
|
|
1407
|
-
len +=
|
|
374
|
+
len += mac_ctx->id_cred_len;
|
|
1408
375
|
}
|
|
1409
376
|
|
|
1410
377
|
len += sign_len;
|
|
1411
|
-
len +=
|
|
1412
|
-
len +=
|
|
378
|
+
len += edhoc_cbor_bstr_oh(sign_len);
|
|
379
|
+
len += mac_ctx->ead_len;
|
|
1413
380
|
|
|
1414
381
|
*plaintext_3_len = len;
|
|
1415
382
|
return EDHOC_SUCCESS;
|
|
1416
383
|
}
|
|
1417
384
|
|
|
1418
|
-
static int prepare_plaintext_3(const struct
|
|
385
|
+
static int prepare_plaintext_3(const struct mac_context *mac_ctx,
|
|
1419
386
|
const uint8_t *sign, size_t sign_len,
|
|
1420
387
|
uint8_t *ptxt, size_t ptxt_size,
|
|
1421
388
|
size_t *ptxt_len)
|
|
1422
389
|
{
|
|
390
|
+
if (NULL == mac_ctx || NULL == sign || 0 == sign_len || NULL == ptxt ||
|
|
391
|
+
0 == ptxt_size || NULL == ptxt_len)
|
|
392
|
+
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
393
|
+
|
|
1423
394
|
int ret = EDHOC_ERROR_GENERIC_ERROR;
|
|
1424
395
|
|
|
1425
396
|
size_t offset = 0;
|
|
1426
397
|
|
|
1427
398
|
/* ID_CRED_I. */
|
|
1428
|
-
if (
|
|
1429
|
-
switch (
|
|
399
|
+
if (mac_ctx->id_cred_is_comp_enc) {
|
|
400
|
+
switch (mac_ctx->id_cred_enc_type) {
|
|
1430
401
|
case EDHOC_ENCODE_TYPE_INTEGER:
|
|
1431
|
-
memcpy(&ptxt[offset], &
|
|
402
|
+
memcpy(&ptxt[offset], &mac_ctx->id_cred_int, 1);
|
|
1432
403
|
offset += 1;
|
|
1433
404
|
break;
|
|
1434
405
|
case EDHOC_ENCODE_TYPE_BYTE_STRING:
|
|
1435
|
-
memcpy(&ptxt[offset], &
|
|
1436
|
-
|
|
1437
|
-
offset +=
|
|
406
|
+
memcpy(&ptxt[offset], &mac_ctx->id_cred_bstr,
|
|
407
|
+
mac_ctx->id_cred_bstr_len);
|
|
408
|
+
offset += mac_ctx->id_cred_bstr_len;
|
|
1438
409
|
break;
|
|
1439
410
|
default:
|
|
1440
411
|
return EDHOC_ERROR_NOT_PERMITTED;
|
|
1441
412
|
}
|
|
1442
413
|
} else {
|
|
1443
|
-
memcpy(&ptxt[offset],
|
|
1444
|
-
|
|
1445
|
-
offset += cbor_items->id_cred_i_len;
|
|
414
|
+
memcpy(&ptxt[offset], mac_ctx->id_cred, mac_ctx->id_cred_len);
|
|
415
|
+
offset += mac_ctx->id_cred_len;
|
|
1446
416
|
}
|
|
1447
417
|
const struct zcbor_string cbor_sign_or_mac_3 = {
|
|
1448
418
|
.value = sign,
|
|
@@ -1451,19 +421,18 @@ static int prepare_plaintext_3(const struct cbor_items *cbor_items,
|
|
|
1451
421
|
|
|
1452
422
|
size_t len = 0;
|
|
1453
423
|
ret = cbor_encode_byte_string_type_bstr_type(
|
|
1454
|
-
&ptxt[offset], sign_len +
|
|
424
|
+
&ptxt[offset], sign_len + edhoc_cbor_bstr_oh(sign_len),
|
|
1455
425
|
&cbor_sign_or_mac_3, &len);
|
|
1456
426
|
|
|
1457
|
-
if (ZCBOR_SUCCESS != ret
|
|
1458
|
-
(sign_len + cbor_bstr_overhead(sign_len)) != len)
|
|
427
|
+
if (ZCBOR_SUCCESS != ret)
|
|
1459
428
|
return EDHOC_ERROR_CBOR_FAILURE;
|
|
1460
429
|
|
|
1461
430
|
offset += len;
|
|
1462
431
|
|
|
1463
432
|
/* EAD_3 if present. */
|
|
1464
|
-
if (
|
|
1465
|
-
memcpy(&ptxt[offset],
|
|
1466
|
-
offset +=
|
|
433
|
+
if (mac_ctx->is_ead) {
|
|
434
|
+
memcpy(&ptxt[offset], mac_ctx->ead, mac_ctx->ead_len);
|
|
435
|
+
offset += mac_ctx->ead_len;
|
|
1467
436
|
}
|
|
1468
437
|
|
|
1469
438
|
if (offset > ptxt_size)
|
|
@@ -1481,9 +450,9 @@ static int comp_aad_3_len(const struct edhoc_context *ctx, size_t *aad_3_len)
|
|
|
1481
450
|
|
|
1482
451
|
size_t len = 0;
|
|
1483
452
|
|
|
1484
|
-
len += sizeof("Encrypt0") +
|
|
1485
|
-
len += 0
|
|
1486
|
-
len += ctx->th_len +
|
|
453
|
+
len += sizeof("Encrypt0") + edhoc_cbor_tstr_oh(sizeof("Encrypt0"));
|
|
454
|
+
len += 1; /* One byte for cbor bstr with 0 value. */
|
|
455
|
+
len += ctx->th_len + edhoc_cbor_bstr_oh(ctx->th_len);
|
|
1487
456
|
|
|
1488
457
|
*aad_3_len = len;
|
|
1489
458
|
return EDHOC_SUCCESS;
|
|
@@ -1505,35 +474,35 @@ static int comp_key_iv_aad(const struct edhoc_context *ctx, uint8_t *key,
|
|
|
1505
474
|
const struct edhoc_cipher_suite csuite =
|
|
1506
475
|
ctx->csuite[ctx->chosen_csuite_idx];
|
|
1507
476
|
|
|
1508
|
-
uint8_t key_id[
|
|
477
|
+
uint8_t key_id[CONFIG_LIBEDHOC_KEY_ID_LEN] = { 0 };
|
|
1509
478
|
struct info input_info = { 0 };
|
|
1510
479
|
|
|
1511
480
|
/* Calculate struct info cbor overhead. */
|
|
1512
481
|
size_t len = 0;
|
|
1513
|
-
len +=
|
|
1514
|
-
len += ctx->th_len +
|
|
1515
|
-
len +=
|
|
482
|
+
len += edhoc_cbor_int_mem_req(EDHOC_EXTRACT_PRK_INFO_LABEL_IV_3);
|
|
483
|
+
len += ctx->th_len + edhoc_cbor_bstr_oh(ctx->th_len);
|
|
484
|
+
len += edhoc_cbor_int_mem_req((int32_t)csuite.aead_key_length);
|
|
1516
485
|
|
|
1517
|
-
|
|
1518
|
-
memset(info, 0,
|
|
486
|
+
VLA_ALLOC(uint8_t, info, len);
|
|
487
|
+
memset(info, 0, VLA_SIZEOF(info));
|
|
1519
488
|
|
|
1520
489
|
/* Generate K_3. */
|
|
1521
490
|
input_info = (struct info){
|
|
1522
|
-
.
|
|
1523
|
-
.
|
|
1524
|
-
.
|
|
1525
|
-
.
|
|
491
|
+
.info_label = EDHOC_EXTRACT_PRK_INFO_LABEL_K_3,
|
|
492
|
+
.info_context.value = ctx->th,
|
|
493
|
+
.info_context.len = ctx->th_len,
|
|
494
|
+
.info_length = (uint32_t)csuite.aead_key_length,
|
|
1526
495
|
};
|
|
1527
496
|
|
|
1528
|
-
memset(info, 0,
|
|
497
|
+
memset(info, 0, VLA_SIZEOF(info));
|
|
1529
498
|
len = 0;
|
|
1530
|
-
ret = cbor_encode_info(info,
|
|
499
|
+
ret = cbor_encode_info(info, VLA_SIZE(info), &input_info, &len);
|
|
1531
500
|
|
|
1532
501
|
if (ZCBOR_SUCCESS != ret)
|
|
1533
502
|
return EDHOC_ERROR_CBOR_FAILURE;
|
|
1534
503
|
|
|
1535
|
-
ret = ctx->keys.
|
|
1536
|
-
|
|
504
|
+
ret = ctx->keys.import_key(ctx->user_ctx, EDHOC_KT_EXPAND, ctx->prk,
|
|
505
|
+
ctx->prk_len, key_id);
|
|
1537
506
|
|
|
1538
507
|
if (EDHOC_SUCCESS != ret)
|
|
1539
508
|
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
@@ -1548,21 +517,21 @@ static int comp_key_iv_aad(const struct edhoc_context *ctx, uint8_t *key,
|
|
|
1548
517
|
|
|
1549
518
|
/* Generate IV_3. */
|
|
1550
519
|
input_info = (struct info){
|
|
1551
|
-
.
|
|
1552
|
-
.
|
|
1553
|
-
.
|
|
1554
|
-
.
|
|
520
|
+
.info_label = EDHOC_EXTRACT_PRK_INFO_LABEL_IV_3,
|
|
521
|
+
.info_context.value = ctx->th,
|
|
522
|
+
.info_context.len = ctx->th_len,
|
|
523
|
+
.info_length = (uint32_t)csuite.aead_iv_length,
|
|
1555
524
|
};
|
|
1556
525
|
|
|
1557
|
-
memset(info, 0,
|
|
526
|
+
memset(info, 0, VLA_SIZEOF(info));
|
|
1558
527
|
len = 0;
|
|
1559
|
-
ret = cbor_encode_info(info,
|
|
528
|
+
ret = cbor_encode_info(info, VLA_SIZE(info), &input_info, &len);
|
|
1560
529
|
|
|
1561
530
|
if (ZCBOR_SUCCESS != ret)
|
|
1562
531
|
return EDHOC_ERROR_CBOR_FAILURE;
|
|
1563
532
|
|
|
1564
|
-
ret = ctx->keys.
|
|
1565
|
-
|
|
533
|
+
ret = ctx->keys.import_key(ctx->user_ctx, EDHOC_KT_EXPAND, ctx->prk,
|
|
534
|
+
ctx->prk_len, key_id);
|
|
1566
535
|
|
|
1567
536
|
if (EDHOC_SUCCESS != ret)
|
|
1568
537
|
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
@@ -1576,10 +545,10 @@ static int comp_key_iv_aad(const struct edhoc_context *ctx, uint8_t *key,
|
|
|
1576
545
|
|
|
1577
546
|
/* Generate AAD_3. */
|
|
1578
547
|
struct enc_structure cose_enc_0 = {
|
|
1579
|
-
.
|
|
1580
|
-
.
|
|
1581
|
-
.
|
|
1582
|
-
.
|
|
548
|
+
.enc_structure_protected.value = NULL,
|
|
549
|
+
.enc_structure_protected.len = 0,
|
|
550
|
+
.enc_structure_external_aad.value = ctx->th,
|
|
551
|
+
.enc_structure_external_aad.len = ctx->th_len,
|
|
1583
552
|
};
|
|
1584
553
|
|
|
1585
554
|
len = 0;
|
|
@@ -1597,11 +566,16 @@ static int comp_ciphertext(const struct edhoc_context *ctx, const uint8_t *key,
|
|
|
1597
566
|
const uint8_t *ptxt, size_t ptxt_len, uint8_t *ctxt,
|
|
1598
567
|
size_t ctxt_size, size_t *ctxt_len)
|
|
1599
568
|
{
|
|
569
|
+
if (NULL == ctx || NULL == key || 0 == key_len || NULL == iv ||
|
|
570
|
+
0 == iv_len || NULL == aad || 0 == aad_len || NULL == ptxt ||
|
|
571
|
+
0 == ptxt_len || NULL == ctxt || 0 == ctxt_size || NULL == ctxt_len)
|
|
572
|
+
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
573
|
+
|
|
1600
574
|
int ret = EDHOC_ERROR_GENERIC_ERROR;
|
|
1601
575
|
|
|
1602
|
-
uint8_t key_id[
|
|
1603
|
-
ret = ctx->keys.
|
|
1604
|
-
|
|
576
|
+
uint8_t key_id[CONFIG_LIBEDHOC_KEY_ID_LEN] = { 0 };
|
|
577
|
+
ret = ctx->keys.import_key(ctx->user_ctx, EDHOC_KT_ENCRYPT, key,
|
|
578
|
+
key_len, key_id);
|
|
1605
579
|
|
|
1606
580
|
if (EDHOC_SUCCESS != ret)
|
|
1607
581
|
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
@@ -1619,10 +593,10 @@ static int comp_ciphertext(const struct edhoc_context *ctx, const uint8_t *key,
|
|
|
1619
593
|
}
|
|
1620
594
|
|
|
1621
595
|
static int comp_th_4(struct edhoc_context *ctx,
|
|
1622
|
-
const struct
|
|
596
|
+
const struct mac_context *mac_ctx, const uint8_t *ptxt,
|
|
1623
597
|
size_t ptxt_len)
|
|
1624
598
|
{
|
|
1625
|
-
if (NULL == ctx || NULL ==
|
|
599
|
+
if (NULL == ctx || NULL == mac_ctx || NULL == ptxt || 0 == ptxt_len)
|
|
1626
600
|
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
1627
601
|
|
|
1628
602
|
if (EDHOC_TH_STATE_3 != ctx->th_state)
|
|
@@ -1634,12 +608,12 @@ static int comp_th_4(struct edhoc_context *ctx,
|
|
|
1634
608
|
|
|
1635
609
|
/* Calculate required buffer length for TH_4. */
|
|
1636
610
|
len = 0;
|
|
1637
|
-
len += ctx->th_len +
|
|
611
|
+
len += ctx->th_len + edhoc_cbor_bstr_oh(ctx->th_len);
|
|
1638
612
|
len += ptxt_len;
|
|
1639
|
-
len +=
|
|
613
|
+
len += mac_ctx->cred_len;
|
|
1640
614
|
|
|
1641
|
-
|
|
1642
|
-
memset(th_4, 0,
|
|
615
|
+
VLA_ALLOC(uint8_t, th_4, len);
|
|
616
|
+
memset(th_4, 0, VLA_SIZEOF(th_4));
|
|
1643
617
|
|
|
1644
618
|
/* TH_3. */
|
|
1645
619
|
const struct zcbor_string cbor_th_3 = {
|
|
@@ -1649,7 +623,7 @@ static int comp_th_4(struct edhoc_context *ctx,
|
|
|
1649
623
|
|
|
1650
624
|
len = 0;
|
|
1651
625
|
ret = cbor_encode_byte_string_type_bstr_type(
|
|
1652
|
-
&th_4[offset],
|
|
626
|
+
&th_4[offset], VLA_SIZE(th_4), &cbor_th_3, &len);
|
|
1653
627
|
|
|
1654
628
|
if (EDHOC_SUCCESS != ret)
|
|
1655
629
|
return EDHOC_ERROR_CBOR_FAILURE;
|
|
@@ -1661,17 +635,17 @@ static int comp_th_4(struct edhoc_context *ctx,
|
|
|
1661
635
|
offset += ptxt_len;
|
|
1662
636
|
|
|
1663
637
|
/* CRED_I. */
|
|
1664
|
-
memcpy(&th_4[offset],
|
|
1665
|
-
offset +=
|
|
638
|
+
memcpy(&th_4[offset], mac_ctx->cred, mac_ctx->cred_len);
|
|
639
|
+
offset += mac_ctx->cred_len;
|
|
1666
640
|
|
|
1667
|
-
if (
|
|
641
|
+
if (VLA_SIZE(th_4) < offset)
|
|
1668
642
|
return EDHOC_ERROR_BUFFER_TOO_SMALL;
|
|
1669
643
|
|
|
1670
644
|
/* Calculate TH_4. */
|
|
1671
645
|
ctx->th_len = ctx->csuite[ctx->chosen_csuite_idx].hash_length;
|
|
1672
646
|
|
|
1673
647
|
size_t hash_length = 0;
|
|
1674
|
-
ret = ctx->crypto.hash(ctx->user_ctx, th_4,
|
|
648
|
+
ret = ctx->crypto.hash(ctx->user_ctx, th_4, VLA_SIZE(th_4), ctx->th,
|
|
1675
649
|
ctx->th_len, &hash_length);
|
|
1676
650
|
|
|
1677
651
|
if (EDHOC_SUCCESS != ret || ctx->th_len != hash_length)
|
|
@@ -1734,11 +708,16 @@ static int decrypt_ciphertext(const struct edhoc_context *ctx,
|
|
|
1734
708
|
const uint8_t *ctxt, size_t ctxt_len,
|
|
1735
709
|
uint8_t *ptxt, size_t ptxt_len)
|
|
1736
710
|
{
|
|
711
|
+
if (NULL == ctx || NULL == key || 0 == key_len || NULL == iv ||
|
|
712
|
+
0 == iv_len || NULL == aad || 0 == aad_len || 0 == ctxt_len ||
|
|
713
|
+
NULL == ptxt || 0 == ptxt_len)
|
|
714
|
+
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
715
|
+
|
|
1737
716
|
int ret = EDHOC_ERROR_GENERIC_ERROR;
|
|
1738
717
|
|
|
1739
|
-
uint8_t key_id[
|
|
1740
|
-
ret = ctx->keys.
|
|
1741
|
-
|
|
718
|
+
uint8_t key_id[CONFIG_LIBEDHOC_KEY_ID_LEN] = { 0 };
|
|
719
|
+
ret = ctx->keys.import_key(ctx->user_ctx, EDHOC_KT_DECRYPT, key,
|
|
720
|
+
key_len, key_id);
|
|
1742
721
|
|
|
1743
722
|
if (EDHOC_SUCCESS != ret)
|
|
1744
723
|
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
@@ -1772,71 +751,71 @@ static int parse_plaintext(struct edhoc_context *ctx, const uint8_t *ptxt,
|
|
|
1772
751
|
return EDHOC_ERROR_CBOR_FAILURE;
|
|
1773
752
|
|
|
1774
753
|
/* ID_CRED_I */
|
|
1775
|
-
switch (cbor_ptxt_3.
|
|
1776
|
-
case
|
|
1777
|
-
parsed_ptxt->
|
|
1778
|
-
parsed_ptxt->
|
|
754
|
+
switch (cbor_ptxt_3.plaintext_3_ID_CRED_I_choice) {
|
|
755
|
+
case plaintext_3_ID_CRED_I_int_c: {
|
|
756
|
+
parsed_ptxt->auth_cred.label = EDHOC_COSE_HEADER_KID;
|
|
757
|
+
parsed_ptxt->auth_cred.key_id.encode_type =
|
|
1779
758
|
EDHOC_ENCODE_TYPE_INTEGER;
|
|
1780
|
-
parsed_ptxt->
|
|
1781
|
-
cbor_ptxt_3.
|
|
759
|
+
parsed_ptxt->auth_cred.key_id.key_id_int =
|
|
760
|
+
cbor_ptxt_3.plaintext_3_ID_CRED_I_int;
|
|
1782
761
|
break;
|
|
1783
762
|
}
|
|
1784
763
|
|
|
1785
|
-
case
|
|
1786
|
-
parsed_ptxt->
|
|
1787
|
-
parsed_ptxt->
|
|
764
|
+
case plaintext_3_ID_CRED_I_bstr_c:
|
|
765
|
+
parsed_ptxt->auth_cred.label = EDHOC_COSE_HEADER_KID;
|
|
766
|
+
parsed_ptxt->auth_cred.key_id.encode_type =
|
|
1788
767
|
EDHOC_ENCODE_TYPE_BYTE_STRING;
|
|
1789
|
-
parsed_ptxt->
|
|
1790
|
-
cbor_ptxt_3.
|
|
1791
|
-
memcpy(parsed_ptxt->
|
|
1792
|
-
cbor_ptxt_3.
|
|
1793
|
-
cbor_ptxt_3.
|
|
768
|
+
parsed_ptxt->auth_cred.key_id.key_id_bstr_length =
|
|
769
|
+
cbor_ptxt_3.plaintext_3_ID_CRED_I_bstr.len;
|
|
770
|
+
memcpy(parsed_ptxt->auth_cred.key_id.key_id_bstr,
|
|
771
|
+
cbor_ptxt_3.plaintext_3_ID_CRED_I_bstr.value,
|
|
772
|
+
cbor_ptxt_3.plaintext_3_ID_CRED_I_bstr.len);
|
|
1794
773
|
break;
|
|
1795
774
|
|
|
1796
|
-
case
|
|
775
|
+
case plaintext_3_ID_CRED_I_map_m_c: {
|
|
1797
776
|
const struct map *cbor_map =
|
|
1798
|
-
&cbor_ptxt_3.
|
|
777
|
+
&cbor_ptxt_3.plaintext_3_ID_CRED_I_map_m;
|
|
1799
778
|
|
|
1800
|
-
if (cbor_map->
|
|
1801
|
-
const struct
|
|
1802
|
-
&cbor_map->
|
|
779
|
+
if (cbor_map->map_x5chain_present) {
|
|
780
|
+
const struct COSE_X509_r *cose_x509 =
|
|
781
|
+
&cbor_map->map_x5chain.map_x5chain;
|
|
1803
782
|
|
|
1804
|
-
parsed_ptxt->
|
|
783
|
+
parsed_ptxt->auth_cred.label =
|
|
1805
784
|
EDHOC_COSE_HEADER_X509_CHAIN;
|
|
1806
785
|
|
|
1807
|
-
switch (cose_x509->
|
|
1808
|
-
case
|
|
1809
|
-
parsed_ptxt->
|
|
786
|
+
switch (cose_x509->COSE_X509_choice) {
|
|
787
|
+
case COSE_X509_bstr_c:
|
|
788
|
+
parsed_ptxt->auth_cred.x509_chain.nr_of_certs =
|
|
1810
789
|
1;
|
|
1811
|
-
parsed_ptxt->
|
|
1812
|
-
cose_x509->
|
|
1813
|
-
parsed_ptxt->
|
|
1814
|
-
cose_x509->
|
|
790
|
+
parsed_ptxt->auth_cred.x509_chain.cert[0] =
|
|
791
|
+
cose_x509->COSE_X509_bstr.value;
|
|
792
|
+
parsed_ptxt->auth_cred.x509_chain.cert_len[0] =
|
|
793
|
+
cose_x509->COSE_X509_bstr.len;
|
|
1815
794
|
break;
|
|
1816
795
|
|
|
1817
|
-
case
|
|
1818
|
-
parsed_ptxt->
|
|
1819
|
-
cose_x509->
|
|
796
|
+
case COSE_X509_certs_l_c: {
|
|
797
|
+
parsed_ptxt->auth_cred.x509_chain.nr_of_certs =
|
|
798
|
+
cose_x509->COSE_X509_certs_l_certs_count;
|
|
1820
799
|
|
|
1821
|
-
if (ARRAY_SIZE(parsed_ptxt->
|
|
1822
|
-
.
|
|
1823
|
-
cose_x509->
|
|
800
|
+
if (ARRAY_SIZE(parsed_ptxt->auth_cred.x509_chain
|
|
801
|
+
.cert) <
|
|
802
|
+
cose_x509->COSE_X509_certs_l_certs_count)
|
|
1824
803
|
return EDHOC_ERROR_BUFFER_TOO_SMALL;
|
|
1825
804
|
|
|
1826
805
|
for (size_t i = 0;
|
|
1827
806
|
i <
|
|
1828
|
-
cose_x509->
|
|
807
|
+
cose_x509->COSE_X509_certs_l_certs_count;
|
|
1829
808
|
++i) {
|
|
1830
|
-
parsed_ptxt->
|
|
809
|
+
parsed_ptxt->auth_cred.x509_chain
|
|
1831
810
|
.cert[i] =
|
|
1832
811
|
cose_x509
|
|
1833
|
-
->
|
|
812
|
+
->COSE_X509_certs_l_certs
|
|
1834
813
|
[i]
|
|
1835
814
|
.value;
|
|
1836
|
-
parsed_ptxt->
|
|
815
|
+
parsed_ptxt->auth_cred.x509_chain
|
|
1837
816
|
.cert_len[i] =
|
|
1838
817
|
cose_x509
|
|
1839
|
-
->
|
|
818
|
+
->COSE_X509_certs_l_certs
|
|
1840
819
|
[i]
|
|
1841
820
|
.len;
|
|
1842
821
|
}
|
|
@@ -1848,42 +827,41 @@ static int parse_plaintext(struct edhoc_context *ctx, const uint8_t *ptxt,
|
|
|
1848
827
|
break;
|
|
1849
828
|
}
|
|
1850
829
|
|
|
1851
|
-
if (cbor_map->
|
|
1852
|
-
parsed_ptxt->
|
|
830
|
+
if (cbor_map->map_x5t_present) {
|
|
831
|
+
parsed_ptxt->auth_cred.label =
|
|
1853
832
|
EDHOC_COSE_HEADER_X509_HASH;
|
|
1854
833
|
|
|
1855
834
|
const struct COSE_CertHash *cose_x509 =
|
|
1856
|
-
&cbor_map->
|
|
835
|
+
&cbor_map->map_x5t.map_x5t;
|
|
1857
836
|
|
|
1858
|
-
parsed_ptxt->
|
|
1859
|
-
cose_x509->
|
|
1860
|
-
parsed_ptxt->
|
|
1861
|
-
cose_x509->
|
|
837
|
+
parsed_ptxt->auth_cred.x509_hash.cert_fp =
|
|
838
|
+
cose_x509->COSE_CertHash_hashValue.value;
|
|
839
|
+
parsed_ptxt->auth_cred.x509_hash.cert_fp_len =
|
|
840
|
+
cose_x509->COSE_CertHash_hashValue.len;
|
|
1862
841
|
|
|
1863
|
-
switch (cose_x509->
|
|
1864
|
-
case
|
|
1865
|
-
parsed_ptxt->
|
|
842
|
+
switch (cose_x509->COSE_CertHash_hashAlg_choice) {
|
|
843
|
+
case COSE_CertHash_hashAlg_int_c:
|
|
844
|
+
parsed_ptxt->auth_cred.x509_hash.encode_type =
|
|
1866
845
|
EDHOC_ENCODE_TYPE_INTEGER;
|
|
1867
|
-
parsed_ptxt->
|
|
1868
|
-
cose_x509->
|
|
846
|
+
parsed_ptxt->auth_cred.x509_hash.alg_int =
|
|
847
|
+
cose_x509->COSE_CertHash_hashAlg_int;
|
|
1869
848
|
break;
|
|
1870
|
-
case
|
|
1871
|
-
if (ARRAY_SIZE(parsed_ptxt->
|
|
849
|
+
case COSE_CertHash_hashAlg_tstr_c:
|
|
850
|
+
if (ARRAY_SIZE(parsed_ptxt->auth_cred.x509_hash
|
|
1872
851
|
.alg_bstr) <
|
|
1873
|
-
cose_x509->
|
|
852
|
+
cose_x509->COSE_CertHash_hashAlg_tstr.len)
|
|
1874
853
|
return EDHOC_ERROR_BUFFER_TOO_SMALL;
|
|
1875
854
|
|
|
1876
|
-
parsed_ptxt->
|
|
855
|
+
parsed_ptxt->auth_cred.x509_hash.encode_type =
|
|
1877
856
|
EDHOC_ENCODE_TYPE_BYTE_STRING;
|
|
1878
|
-
parsed_ptxt->
|
|
857
|
+
parsed_ptxt->auth_cred.x509_hash
|
|
1879
858
|
.alg_bstr_length =
|
|
1880
|
-
cose_x509->
|
|
859
|
+
cose_x509->COSE_CertHash_hashAlg_tstr
|
|
1881
860
|
.len;
|
|
1882
|
-
memcpy(parsed_ptxt->
|
|
1883
|
-
|
|
1884
|
-
cose_x509->_COSE_CertHash_hashAlg_tstr
|
|
861
|
+
memcpy(parsed_ptxt->auth_cred.x509_hash.alg_bstr,
|
|
862
|
+
cose_x509->COSE_CertHash_hashAlg_tstr
|
|
1885
863
|
.value,
|
|
1886
|
-
cose_x509->
|
|
864
|
+
cose_x509->COSE_CertHash_hashAlg_tstr
|
|
1887
865
|
.len);
|
|
1888
866
|
break;
|
|
1889
867
|
default:
|
|
@@ -1897,189 +875,26 @@ static int parse_plaintext(struct edhoc_context *ctx, const uint8_t *ptxt,
|
|
|
1897
875
|
|
|
1898
876
|
/* Sign_or_MAC_3 */
|
|
1899
877
|
parsed_ptxt->sign_or_mac =
|
|
1900
|
-
cbor_ptxt_3.
|
|
878
|
+
cbor_ptxt_3.plaintext_3_Signature_or_MAC_3.value;
|
|
1901
879
|
parsed_ptxt->sign_or_mac_len =
|
|
1902
|
-
cbor_ptxt_3.
|
|
880
|
+
cbor_ptxt_3.plaintext_3_Signature_or_MAC_3.len;
|
|
1903
881
|
|
|
1904
882
|
/* EAD_3 if present */
|
|
1905
|
-
if (cbor_ptxt_3.
|
|
883
|
+
if (cbor_ptxt_3.plaintext_3_EAD_3_m_present) {
|
|
1906
884
|
ctx->nr_of_ead_tokens =
|
|
1907
|
-
cbor_ptxt_3.
|
|
885
|
+
cbor_ptxt_3.plaintext_3_EAD_3_m.EAD_3_count;
|
|
1908
886
|
|
|
1909
887
|
for (size_t i = 0; i < ctx->nr_of_ead_tokens; ++i) {
|
|
1910
888
|
ctx->ead_token[i].label =
|
|
1911
|
-
cbor_ptxt_3.
|
|
1912
|
-
.
|
|
889
|
+
cbor_ptxt_3.plaintext_3_EAD_3_m.EAD_3[i]
|
|
890
|
+
.ead_y_ead_label;
|
|
1913
891
|
ctx->ead_token[i].value =
|
|
1914
|
-
cbor_ptxt_3.
|
|
1915
|
-
.
|
|
892
|
+
cbor_ptxt_3.plaintext_3_EAD_3_m.EAD_3[i]
|
|
893
|
+
.ead_y_ead_value.value;
|
|
1916
894
|
ctx->ead_token[i].value_len =
|
|
1917
|
-
cbor_ptxt_3.
|
|
1918
|
-
.
|
|
1919
|
-
}
|
|
1920
|
-
}
|
|
1921
|
-
|
|
1922
|
-
return EDHOC_SUCCESS;
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
|
-
static int verify_sign_or_mac_3(const struct edhoc_context *ctx,
|
|
1926
|
-
const struct cbor_items *cbor_items,
|
|
1927
|
-
const struct plaintext *parsed_ptxt,
|
|
1928
|
-
const uint8_t *pub_key, size_t pub_key_len,
|
|
1929
|
-
const uint8_t *mac_3, size_t mac_3_len)
|
|
1930
|
-
{
|
|
1931
|
-
if (NULL == ctx || NULL == cbor_items || NULL == parsed_ptxt ||
|
|
1932
|
-
NULL == pub_key || 0 == pub_key_len || NULL == mac_3 ||
|
|
1933
|
-
0 == mac_3_len)
|
|
1934
|
-
return EDHOC_ERROR_INVALID_ARGUMENT;
|
|
1935
|
-
|
|
1936
|
-
int ret = EDHOC_ERROR_GENERIC_ERROR;
|
|
1937
|
-
|
|
1938
|
-
switch (ctx->method) {
|
|
1939
|
-
case EDHOC_METHOD_0:
|
|
1940
|
-
case EDHOC_METHOD_1: {
|
|
1941
|
-
size_t len = 0;
|
|
1942
|
-
|
|
1943
|
-
const struct sig_structure cose_sign_1 = {
|
|
1944
|
-
._sig_structure_protected.value = cbor_items->id_cred_i,
|
|
1945
|
-
._sig_structure_protected.len =
|
|
1946
|
-
cbor_items->id_cred_i_len,
|
|
1947
|
-
._sig_structure_external_aad.value = cbor_items->th_3,
|
|
1948
|
-
._sig_structure_external_aad.len =
|
|
1949
|
-
cbor_items->th_3_len + cbor_items->cred_i_len +
|
|
1950
|
-
cbor_items->ead_3_len,
|
|
1951
|
-
._sig_structure_payload.value = mac_3,
|
|
1952
|
-
._sig_structure_payload.len = mac_3_len,
|
|
1953
|
-
};
|
|
1954
|
-
|
|
1955
|
-
len = 0;
|
|
1956
|
-
len += sizeof("Signature1") +
|
|
1957
|
-
cbor_tstr_overhead(sizeof("Signature1"));
|
|
1958
|
-
len += cbor_items->id_cred_i_len +
|
|
1959
|
-
cbor_bstr_overhead(cbor_items->id_cred_i_len);
|
|
1960
|
-
len += cbor_items->th_3_len + cbor_items->cred_i_len +
|
|
1961
|
-
cbor_items->ead_3_len +
|
|
1962
|
-
cbor_bstr_overhead(cbor_items->th_3_len +
|
|
1963
|
-
cbor_items->cred_i_len +
|
|
1964
|
-
cbor_items->ead_3_len);
|
|
1965
|
-
len += mac_3_len + cbor_bstr_overhead(mac_3_len);
|
|
1966
|
-
|
|
1967
|
-
ALLOCATE_ARRAY(uint8_t, cose_sign_1_buf, len);
|
|
1968
|
-
memset(cose_sign_1_buf, 0, ALLOCATE_ARRAY_SIZEOF(cose_sign_1_buf));
|
|
1969
|
-
|
|
1970
|
-
len = 0;
|
|
1971
|
-
ret = cbor_encode_sig_structure(cose_sign_1_buf,
|
|
1972
|
-
ARRAY_SIZE_VLA(cose_sign_1_buf),
|
|
1973
|
-
&cose_sign_1, &len);
|
|
1974
|
-
|
|
1975
|
-
if (ZCBOR_SUCCESS != ret)
|
|
1976
|
-
return EDHOC_ERROR_CBOR_FAILURE;
|
|
1977
|
-
|
|
1978
|
-
uint8_t key_id[EDHOC_KID_LEN] = { 0 };
|
|
1979
|
-
ret = ctx->keys.generate_key(ctx->user_ctx, EDHOC_KT_VERIFY,
|
|
1980
|
-
pub_key, pub_key_len, key_id);
|
|
1981
|
-
|
|
1982
|
-
if (EDHOC_SUCCESS != ret)
|
|
1983
|
-
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
1984
|
-
|
|
1985
|
-
ret = ctx->crypto.verify(ctx->user_ctx, key_id, cose_sign_1_buf,
|
|
1986
|
-
len, parsed_ptxt->sign_or_mac,
|
|
1987
|
-
parsed_ptxt->sign_or_mac_len);
|
|
1988
|
-
ctx->keys.destroy_key(ctx->user_ctx, key_id);
|
|
1989
|
-
|
|
1990
|
-
if (EDHOC_SUCCESS != ret)
|
|
1991
|
-
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
1992
|
-
|
|
1993
|
-
return EDHOC_SUCCESS;
|
|
1994
|
-
}
|
|
1995
|
-
|
|
1996
|
-
case EDHOC_METHOD_2:
|
|
1997
|
-
case EDHOC_METHOD_3: {
|
|
1998
|
-
if (mac_3_len != parsed_ptxt->sign_or_mac_len ||
|
|
1999
|
-
0 != memcmp(parsed_ptxt->sign_or_mac, mac_3, mac_3_len))
|
|
2000
|
-
return EDHOC_ERROR_INVALID_SIGN_OR_MAC_2;
|
|
2001
|
-
|
|
2002
|
-
return EDHOC_SUCCESS;
|
|
2003
|
-
}
|
|
2004
|
-
default:
|
|
2005
|
-
return EDHOC_ERROR_NOT_PERMITTED;
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
|
|
2009
|
-
static int kid_compact_encoding(const struct edhoc_auth_creds *auth_cred,
|
|
2010
|
-
struct cbor_items *cbor_items)
|
|
2011
|
-
{
|
|
2012
|
-
int ret = EDHOC_ERROR_GENERIC_ERROR;
|
|
2013
|
-
size_t len = 0;
|
|
2014
|
-
|
|
2015
|
-
cbor_items->id_cred_i_is_comp_enc = true;
|
|
2016
|
-
|
|
2017
|
-
switch (auth_cred->key_id.encode_type) {
|
|
2018
|
-
case EDHOC_ENCODE_TYPE_INTEGER: {
|
|
2019
|
-
cbor_items->id_cred_i_enc_type = EDHOC_ENCODE_TYPE_INTEGER;
|
|
2020
|
-
if (true == auth_cred->key_id.cred_is_cbor) {
|
|
2021
|
-
cbor_items->id_cred_i_int =
|
|
2022
|
-
auth_cred->key_id.key_id_int;
|
|
2023
|
-
} else {
|
|
2024
|
-
len = 0;
|
|
2025
|
-
ret = cbor_encode_integer_type_int_type(
|
|
2026
|
-
(uint8_t *)&cbor_items->id_cred_i_int,
|
|
2027
|
-
sizeof(cbor_items->id_cred_i_int),
|
|
2028
|
-
&auth_cred->key_id.key_id_int, &len);
|
|
2029
|
-
|
|
2030
|
-
if (ZCBOR_SUCCESS != ret)
|
|
2031
|
-
return EDHOC_ERROR_CBOR_FAILURE;
|
|
2032
|
-
}
|
|
2033
|
-
break;
|
|
2034
|
-
}
|
|
2035
|
-
|
|
2036
|
-
case EDHOC_ENCODE_TYPE_BYTE_STRING: {
|
|
2037
|
-
cbor_items->id_cred_i_enc_type = EDHOC_ENCODE_TYPE_BYTE_STRING;
|
|
2038
|
-
|
|
2039
|
-
if (true == auth_cred->key_id.cred_is_cbor) {
|
|
2040
|
-
if (1 == auth_cred->key_id.key_id_bstr_length) {
|
|
2041
|
-
int32_t val = auth_cred->key_id.key_id_bstr[0];
|
|
2042
|
-
int32_t result = 0;
|
|
2043
|
-
|
|
2044
|
-
len = 0;
|
|
2045
|
-
ret = cbor_decode_integer_type_int_type(
|
|
2046
|
-
(uint8_t *)&val, sizeof(val), &result,
|
|
2047
|
-
&len);
|
|
2048
|
-
|
|
2049
|
-
if (ZCBOR_SUCCESS != ret)
|
|
2050
|
-
return EDHOC_ERROR_CBOR_FAILURE;
|
|
2051
|
-
|
|
2052
|
-
if (true == is_cbor_one_byte_int(result)) {
|
|
2053
|
-
cbor_items->id_cred_i_int = val;
|
|
2054
|
-
cbor_items->id_cred_i_enc_type =
|
|
2055
|
-
EDHOC_ENCODE_TYPE_INTEGER;
|
|
2056
|
-
break;
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2059
|
-
|
|
2060
|
-
cbor_items->id_cred_i_bstr_len =
|
|
2061
|
-
auth_cred->key_id.key_id_bstr_length;
|
|
2062
|
-
memcpy(cbor_items->id_cred_i_bstr,
|
|
2063
|
-
auth_cred->key_id.key_id_bstr,
|
|
2064
|
-
auth_cred->key_id.key_id_bstr_length);
|
|
2065
|
-
} else {
|
|
2066
|
-
const struct zcbor_string input = {
|
|
2067
|
-
.value = auth_cred->key_id.key_id_bstr,
|
|
2068
|
-
.len = auth_cred->key_id.key_id_bstr_length,
|
|
2069
|
-
};
|
|
2070
|
-
|
|
2071
|
-
ret = cbor_encode_byte_string_type_bstr_type(
|
|
2072
|
-
cbor_items->id_cred_i_bstr,
|
|
2073
|
-
ARRAY_SIZE(cbor_items->id_cred_i_bstr) - 1,
|
|
2074
|
-
&input, &cbor_items->id_cred_i_bstr_len);
|
|
2075
|
-
|
|
2076
|
-
if (ZCBOR_SUCCESS != ret)
|
|
2077
|
-
return EDHOC_ERROR_CBOR_FAILURE;
|
|
895
|
+
cbor_ptxt_3.plaintext_3_EAD_3_m.EAD_3[i]
|
|
896
|
+
.ead_y_ead_value.len;
|
|
2078
897
|
}
|
|
2079
|
-
break;
|
|
2080
|
-
}
|
|
2081
|
-
default:
|
|
2082
|
-
return EDHOC_ERROR_NOT_PERMITTED;
|
|
2083
898
|
}
|
|
2084
899
|
|
|
2085
900
|
return EDHOC_SUCCESS;
|
|
@@ -2099,34 +914,34 @@ static int comp_salt_4e3m(const struct edhoc_context *ctx, uint8_t *salt,
|
|
|
2099
914
|
const size_t hash_len = ctx->csuite[ctx->chosen_csuite_idx].hash_length;
|
|
2100
915
|
|
|
2101
916
|
const struct info input_info = {
|
|
2102
|
-
.
|
|
2103
|
-
.
|
|
2104
|
-
.
|
|
2105
|
-
.
|
|
917
|
+
.info_label = EDHOC_EXTRACT_PRK_INFO_LABEL_SALT_4E3M,
|
|
918
|
+
.info_context.value = ctx->th,
|
|
919
|
+
.info_context.len = ctx->th_len,
|
|
920
|
+
.info_length = (uint32_t)hash_len,
|
|
2106
921
|
};
|
|
2107
922
|
|
|
2108
923
|
size_t len = 0;
|
|
2109
|
-
len +=
|
|
2110
|
-
len += ctx->th_len +
|
|
2111
|
-
len +=
|
|
924
|
+
len += edhoc_cbor_int_mem_req(EDHOC_EXTRACT_PRK_INFO_LABEL_SALT_4E3M);
|
|
925
|
+
len += ctx->th_len + edhoc_cbor_bstr_oh(ctx->th_len);
|
|
926
|
+
len += edhoc_cbor_int_mem_req((int32_t)hash_len);
|
|
2112
927
|
|
|
2113
|
-
|
|
2114
|
-
memset(info, 0,
|
|
928
|
+
VLA_ALLOC(uint8_t, info, len);
|
|
929
|
+
memset(info, 0, VLA_SIZEOF(info));
|
|
2115
930
|
|
|
2116
931
|
len = 0;
|
|
2117
|
-
ret = cbor_encode_info(info,
|
|
932
|
+
ret = cbor_encode_info(info, VLA_SIZE(info), &input_info, &len);
|
|
2118
933
|
|
|
2119
|
-
if (ZCBOR_SUCCESS != ret ||
|
|
934
|
+
if (ZCBOR_SUCCESS != ret || VLA_SIZE(info) != len)
|
|
2120
935
|
return EDHOC_ERROR_CBOR_FAILURE;
|
|
2121
936
|
|
|
2122
|
-
uint8_t key_id[
|
|
2123
|
-
ret = ctx->keys.
|
|
2124
|
-
|
|
937
|
+
uint8_t key_id[CONFIG_LIBEDHOC_KEY_ID_LEN] = { 0 };
|
|
938
|
+
ret = ctx->keys.import_key(ctx->user_ctx, EDHOC_KT_EXPAND, ctx->prk,
|
|
939
|
+
ctx->prk_len, key_id);
|
|
2125
940
|
|
|
2126
941
|
if (EDHOC_SUCCESS != ret)
|
|
2127
942
|
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
2128
943
|
|
|
2129
|
-
ret = ctx->crypto.expand(ctx->user_ctx, key_id, info,
|
|
944
|
+
ret = ctx->crypto.expand(ctx->user_ctx, key_id, info, VLA_SIZE(info),
|
|
2130
945
|
salt, salt_len);
|
|
2131
946
|
ctx->keys.destroy_key(ctx->user_ctx, key_id);
|
|
2132
947
|
|
|
@@ -2136,7 +951,7 @@ static int comp_salt_4e3m(const struct edhoc_context *ctx, uint8_t *salt,
|
|
|
2136
951
|
return EDHOC_SUCCESS;
|
|
2137
952
|
}
|
|
2138
953
|
|
|
2139
|
-
static int comp_giy(
|
|
954
|
+
static int comp_giy(struct edhoc_context *ctx,
|
|
2140
955
|
const struct edhoc_auth_creds *auth_cred,
|
|
2141
956
|
const uint8_t *pub_key, size_t pub_key_len, uint8_t *giy,
|
|
2142
957
|
size_t giy_len)
|
|
@@ -2146,8 +961,8 @@ static int comp_giy(enum edhoc_role role, struct edhoc_context *ctx,
|
|
|
2146
961
|
|
|
2147
962
|
int ret = EDHOC_ERROR_GENERIC_ERROR;
|
|
2148
963
|
|
|
2149
|
-
switch (role) {
|
|
2150
|
-
case
|
|
964
|
+
switch (ctx->role) {
|
|
965
|
+
case EDHOC_INITIATOR: {
|
|
2151
966
|
size_t secret_len = 0;
|
|
2152
967
|
ret = ctx->crypto.key_agreement(ctx->user_ctx,
|
|
2153
968
|
auth_cred->priv_key_id,
|
|
@@ -2161,12 +976,12 @@ static int comp_giy(enum edhoc_role role, struct edhoc_context *ctx,
|
|
|
2161
976
|
return EDHOC_SUCCESS;
|
|
2162
977
|
}
|
|
2163
978
|
|
|
2164
|
-
case
|
|
2165
|
-
uint8_t key_id[
|
|
2166
|
-
ret = ctx->keys.
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
979
|
+
case EDHOC_RESPONDER: {
|
|
980
|
+
uint8_t key_id[CONFIG_LIBEDHOC_KEY_ID_LEN] = { 0 };
|
|
981
|
+
ret = ctx->keys.import_key(ctx->user_ctx,
|
|
982
|
+
EDHOC_KT_KEY_AGREEMENT,
|
|
983
|
+
ctx->dh_priv_key,
|
|
984
|
+
ctx->dh_priv_key_len, key_id);
|
|
2170
985
|
ctx->dh_priv_key_len = 0;
|
|
2171
986
|
memset(ctx->dh_priv_key, 0, ARRAY_SIZE(ctx->dh_priv_key));
|
|
2172
987
|
|
|
@@ -2227,6 +1042,8 @@ int edhoc_message_3_compose(struct edhoc_context *ctx, uint8_t *msg_3,
|
|
|
2227
1042
|
|
|
2228
1043
|
ctx->status = EDHOC_SM_ABORTED;
|
|
2229
1044
|
ctx->error_code = EDHOC_ERROR_CODE_UNSPECIFIED_ERROR;
|
|
1045
|
+
ctx->message = EDHOC_MSG_3;
|
|
1046
|
+
ctx->role = EDHOC_INITIATOR;
|
|
2230
1047
|
|
|
2231
1048
|
int ret = EDHOC_ERROR_GENERIC_ERROR;
|
|
2232
1049
|
|
|
@@ -2236,7 +1053,7 @@ int edhoc_message_3_compose(struct edhoc_context *ctx, uint8_t *msg_3,
|
|
|
2236
1053
|
|
|
2237
1054
|
/* 2. Compose EAD_3 if present. */
|
|
2238
1055
|
if (NULL != ctx->ead.compose && 0 != ARRAY_SIZE(ctx->ead_token) - 1) {
|
|
2239
|
-
ret = ctx->ead.compose(ctx->user_ctx,
|
|
1056
|
+
ret = ctx->ead.compose(ctx->user_ctx, ctx->message,
|
|
2240
1057
|
ctx->ead_token,
|
|
2241
1058
|
ARRAY_SIZE(ctx->ead_token) - 1,
|
|
2242
1059
|
&ctx->nr_of_ead_tokens);
|
|
@@ -2271,35 +1088,35 @@ int edhoc_message_3_compose(struct edhoc_context *ctx, uint8_t *msg_3,
|
|
|
2271
1088
|
return EDHOC_ERROR_CREDENTIALS_FAILURE;
|
|
2272
1089
|
|
|
2273
1090
|
/* 4. Compute K_3, IV_3 and AAD_3. */
|
|
2274
|
-
|
|
2275
|
-
memset(key, 0,
|
|
1091
|
+
VLA_ALLOC(uint8_t, key, csuite.aead_key_length);
|
|
1092
|
+
memset(key, 0, VLA_SIZEOF(key));
|
|
2276
1093
|
|
|
2277
|
-
|
|
2278
|
-
memset(iv, 0,
|
|
1094
|
+
VLA_ALLOC(uint8_t, iv, csuite.aead_iv_length);
|
|
1095
|
+
memset(iv, 0, VLA_SIZEOF(iv));
|
|
2279
1096
|
|
|
2280
1097
|
size_t aad_len = 0;
|
|
2281
1098
|
ret = comp_aad_3_len(ctx, &aad_len);
|
|
2282
1099
|
|
|
2283
1100
|
if (EDHOC_SUCCESS != ret)
|
|
2284
|
-
return
|
|
1101
|
+
return ret;
|
|
2285
1102
|
|
|
2286
|
-
|
|
2287
|
-
memset(aad, 0,
|
|
1103
|
+
VLA_ALLOC(uint8_t, aad, aad_len);
|
|
1104
|
+
memset(aad, 0, VLA_SIZEOF(aad));
|
|
2288
1105
|
|
|
2289
|
-
ret = comp_key_iv_aad(ctx, key,
|
|
2290
|
-
|
|
1106
|
+
ret = comp_key_iv_aad(ctx, key, VLA_SIZE(key), iv, VLA_SIZE(iv), aad,
|
|
1107
|
+
VLA_SIZE(aad));
|
|
2291
1108
|
|
|
2292
1109
|
if (EDHOC_SUCCESS != ret)
|
|
2293
1110
|
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
2294
1111
|
|
|
2295
1112
|
if (NULL != ctx->logger) {
|
|
2296
|
-
ctx->logger(ctx->user_ctx, "K_3", key,
|
|
2297
|
-
ctx->logger(ctx->user_ctx, "IV_3", iv,
|
|
2298
|
-
ctx->logger(ctx->user_ctx, "AAD_3", aad,
|
|
1113
|
+
ctx->logger(ctx->user_ctx, "K_3", key, VLA_SIZE(key));
|
|
1114
|
+
ctx->logger(ctx->user_ctx, "IV_3", iv, VLA_SIZE(iv));
|
|
1115
|
+
ctx->logger(ctx->user_ctx, "AAD_3", aad, VLA_SIZE(aad));
|
|
2299
1116
|
}
|
|
2300
1117
|
|
|
2301
1118
|
/* 5. Compute PRK_4e3m. */
|
|
2302
|
-
ret = comp_prk_4e3m(
|
|
1119
|
+
ret = comp_prk_4e3m(ctx, &auth_creds, NULL, 0);
|
|
2303
1120
|
|
|
2304
1121
|
if (EDHOC_SUCCESS != ret)
|
|
2305
1122
|
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
@@ -2307,88 +1124,82 @@ int edhoc_message_3_compose(struct edhoc_context *ctx, uint8_t *msg_3,
|
|
|
2307
1124
|
if (NULL != ctx->logger)
|
|
2308
1125
|
ctx->logger(ctx->user_ctx, "PRK_4e3m", ctx->prk, ctx->prk_len);
|
|
2309
1126
|
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
1127
|
+
size_t mac_context_length = 0;
|
|
1128
|
+
ret = edhoc_comp_mac_context_length(ctx, &auth_creds,
|
|
1129
|
+
&mac_context_length);
|
|
2313
1130
|
|
|
2314
1131
|
if (EDHOC_SUCCESS != ret)
|
|
2315
|
-
return
|
|
2316
|
-
|
|
2317
|
-
ALLOCATE_ARRAY(uint8_t, mac_3_content, sizeof(struct cbor_items) + context_3_len);
|
|
2318
|
-
memset(mac_3_content, 0, ALLOCATE_ARRAY_SIZEOF(mac_3_content));
|
|
2319
|
-
|
|
2320
|
-
struct cbor_items *cbor_items = (struct cbor_items *)mac_3_content;
|
|
2321
|
-
cbor_items->buf_len = context_3_len;
|
|
1132
|
+
return ret;
|
|
2322
1133
|
|
|
2323
1134
|
/* 6b. Cborise items required by context_3. */
|
|
2324
|
-
|
|
1135
|
+
VLA_ALLOC(uint8_t, mac_3_context_buf,
|
|
1136
|
+
sizeof(struct mac_context) + mac_context_length);
|
|
1137
|
+
memset(mac_3_context_buf, 0, VLA_SIZEOF(mac_3_context_buf));
|
|
1138
|
+
|
|
1139
|
+
struct mac_context *mac_context = (void *)mac_3_context_buf;
|
|
1140
|
+
mac_context->buf_len = mac_context_length;
|
|
2325
1141
|
|
|
1142
|
+
ret = edhoc_comp_mac_context(ctx, &auth_creds, mac_context);
|
|
2326
1143
|
if (EDHOC_SUCCESS != ret)
|
|
2327
|
-
return
|
|
1144
|
+
return ret;
|
|
2328
1145
|
|
|
2329
1146
|
if (NULL != ctx->logger) {
|
|
2330
|
-
ctx->logger(ctx->user_ctx, "ID_CRED_I",
|
|
2331
|
-
|
|
2332
|
-
ctx->logger(ctx->user_ctx, "TH_3",
|
|
2333
|
-
|
|
2334
|
-
ctx->logger(ctx->user_ctx, "CRED_I",
|
|
2335
|
-
|
|
2336
|
-
ctx->logger(ctx->user_ctx, "context_3",
|
|
2337
|
-
|
|
1147
|
+
ctx->logger(ctx->user_ctx, "ID_CRED_I", mac_context->id_cred,
|
|
1148
|
+
mac_context->id_cred_len);
|
|
1149
|
+
ctx->logger(ctx->user_ctx, "TH_3", mac_context->th,
|
|
1150
|
+
mac_context->th_len);
|
|
1151
|
+
ctx->logger(ctx->user_ctx, "CRED_I", mac_context->cred,
|
|
1152
|
+
mac_context->cred_len);
|
|
1153
|
+
ctx->logger(ctx->user_ctx, "context_3", mac_context->buf,
|
|
1154
|
+
mac_context->buf_len);
|
|
2338
1155
|
}
|
|
2339
1156
|
|
|
2340
1157
|
/* 6c. Compute Message Authentication Code (MAC_3). */
|
|
2341
|
-
size_t
|
|
2342
|
-
ret =
|
|
2343
|
-
|
|
1158
|
+
size_t mac_length = 0;
|
|
1159
|
+
ret = edhoc_comp_mac_length(ctx, &mac_length);
|
|
2344
1160
|
if (EDHOC_SUCCESS != ret)
|
|
2345
1161
|
return EDHOC_ERROR_INVALID_MAC_3;
|
|
2346
1162
|
|
|
2347
|
-
|
|
2348
|
-
memset(
|
|
2349
|
-
|
|
2350
|
-
ret = comp_mac_3(ctx, cbor_items, mac_3, ARRAY_SIZE_VLA(mac_3));
|
|
2351
|
-
|
|
1163
|
+
VLA_ALLOC(uint8_t, mac_buf, mac_length);
|
|
1164
|
+
memset(mac_buf, 0, VLA_SIZEOF(mac_buf));
|
|
1165
|
+
ret = edhoc_comp_mac(ctx, mac_context, mac_buf, mac_length);
|
|
2352
1166
|
if (EDHOC_SUCCESS != ret)
|
|
2353
1167
|
return EDHOC_ERROR_INVALID_MAC_3;
|
|
2354
1168
|
|
|
2355
|
-
if (NULL != ctx->logger)
|
|
2356
|
-
ctx->logger(ctx->user_ctx, "MAC_3", mac_3, ARRAY_SIZE_VLA(mac_3));
|
|
2357
|
-
|
|
2358
1169
|
/* 7. Compute signature if needed (Signature_or_MAC_3). */
|
|
2359
|
-
size_t
|
|
2360
|
-
ret =
|
|
2361
|
-
|
|
1170
|
+
size_t sign_or_mac_length = 0;
|
|
1171
|
+
ret = edhoc_comp_sign_or_mac_length(ctx, &sign_or_mac_length);
|
|
2362
1172
|
if (EDHOC_SUCCESS != ret)
|
|
2363
|
-
return
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
ret =
|
|
2369
|
-
|
|
2370
|
-
|
|
1173
|
+
return ret;
|
|
1174
|
+
|
|
1175
|
+
size_t signature_length = 0;
|
|
1176
|
+
VLA_ALLOC(uint8_t, signature, sign_or_mac_length);
|
|
1177
|
+
memset(signature, 0, VLA_SIZEOF(signature));
|
|
1178
|
+
ret = edhoc_comp_sign_or_mac(ctx, &auth_creds, mac_context, mac_buf,
|
|
1179
|
+
mac_length, signature, VLA_SIZE(signature),
|
|
1180
|
+
&signature_length);
|
|
2371
1181
|
if (EDHOC_SUCCESS != ret)
|
|
2372
|
-
return
|
|
1182
|
+
return ret;
|
|
2373
1183
|
|
|
2374
1184
|
if (NULL != ctx->logger)
|
|
2375
|
-
ctx->logger(ctx->user_ctx, "Signature_or_MAC_3",
|
|
2376
|
-
|
|
1185
|
+
ctx->logger(ctx->user_ctx, "Signature_or_MAC_3", signature,
|
|
1186
|
+
signature_length);
|
|
2377
1187
|
|
|
2378
1188
|
/* 8. Prepare plaintext (PLAINTEXT_3). */
|
|
2379
1189
|
size_t plaintext_len = 0;
|
|
2380
|
-
ret = comp_plaintext_3_len(ctx,
|
|
1190
|
+
ret = comp_plaintext_3_len(ctx, mac_context, signature_length,
|
|
2381
1191
|
&plaintext_len);
|
|
2382
1192
|
|
|
2383
1193
|
if (EDHOC_SUCCESS != ret)
|
|
2384
|
-
return
|
|
1194
|
+
return ret;
|
|
2385
1195
|
|
|
2386
|
-
|
|
2387
|
-
memset(plaintext, 0,
|
|
1196
|
+
VLA_ALLOC(uint8_t, plaintext, plaintext_len);
|
|
1197
|
+
memset(plaintext, 0, VLA_SIZEOF(plaintext));
|
|
2388
1198
|
|
|
2389
1199
|
plaintext_len = 0;
|
|
2390
|
-
ret = prepare_plaintext_3(
|
|
2391
|
-
|
|
1200
|
+
ret = prepare_plaintext_3(mac_context, signature, signature_length,
|
|
1201
|
+
plaintext, VLA_SIZE(plaintext),
|
|
1202
|
+
&plaintext_len);
|
|
2392
1203
|
|
|
2393
1204
|
if (EDHOC_SUCCESS != ret)
|
|
2394
1205
|
return EDHOC_ERROR_CBOR_FAILURE;
|
|
@@ -2399,12 +1210,12 @@ int edhoc_message_3_compose(struct edhoc_context *ctx, uint8_t *msg_3,
|
|
|
2399
1210
|
|
|
2400
1211
|
/* 9. Compute ciphertext. */
|
|
2401
1212
|
size_t ciphertext_len = 0;
|
|
2402
|
-
|
|
2403
|
-
memset(ciphertext, 0,
|
|
1213
|
+
VLA_ALLOC(uint8_t, ciphertext, plaintext_len + csuite.aead_tag_length);
|
|
1214
|
+
memset(ciphertext, 0, VLA_SIZEOF(ciphertext));
|
|
2404
1215
|
|
|
2405
|
-
ret = comp_ciphertext(ctx, key,
|
|
2406
|
-
|
|
2407
|
-
ciphertext,
|
|
1216
|
+
ret = comp_ciphertext(ctx, key, VLA_SIZE(key), iv, VLA_SIZE(iv), aad,
|
|
1217
|
+
VLA_SIZE(aad), plaintext, plaintext_len,
|
|
1218
|
+
ciphertext, VLA_SIZE(ciphertext),
|
|
2408
1219
|
&ciphertext_len);
|
|
2409
1220
|
|
|
2410
1221
|
if (EDHOC_SUCCESS != ret)
|
|
@@ -2415,7 +1226,7 @@ int edhoc_message_3_compose(struct edhoc_context *ctx, uint8_t *msg_3,
|
|
|
2415
1226
|
ciphertext_len);
|
|
2416
1227
|
|
|
2417
1228
|
/* 10. Compute transcript hash 4. */
|
|
2418
|
-
ret = comp_th_4(ctx,
|
|
1229
|
+
ret = comp_th_4(ctx, mac_context, plaintext, plaintext_len);
|
|
2419
1230
|
|
|
2420
1231
|
if (EDHOC_SUCCESS != ret)
|
|
2421
1232
|
return EDHOC_ERROR_TRANSCRIPT_HASH_FAILURE;
|
|
@@ -2473,6 +1284,8 @@ int edhoc_message_3_process(struct edhoc_context *ctx, const uint8_t *msg_3,
|
|
|
2473
1284
|
|
|
2474
1285
|
ctx->status = EDHOC_SM_ABORTED;
|
|
2475
1286
|
ctx->error_code = EDHOC_ERROR_CODE_UNSPECIFIED_ERROR;
|
|
1287
|
+
ctx->message = EDHOC_MSG_3;
|
|
1288
|
+
ctx->role = EDHOC_RESPONDER;
|
|
2476
1289
|
|
|
2477
1290
|
int ret = EDHOC_ERROR_GENERIC_ERROR;
|
|
2478
1291
|
|
|
@@ -2490,11 +1303,11 @@ int edhoc_message_3_process(struct edhoc_context *ctx, const uint8_t *msg_3,
|
|
|
2490
1303
|
return EDHOC_ERROR_MSG_3_PROCESS_FAILURE;
|
|
2491
1304
|
|
|
2492
1305
|
/* 3. Compute K_3, IV_3 and AAD_3. */
|
|
2493
|
-
|
|
2494
|
-
memset(key, 0,
|
|
1306
|
+
VLA_ALLOC(uint8_t, key, csuite.aead_key_length);
|
|
1307
|
+
memset(key, 0, VLA_SIZEOF(key));
|
|
2495
1308
|
|
|
2496
|
-
|
|
2497
|
-
memset(iv, 0,
|
|
1309
|
+
VLA_ALLOC(uint8_t, iv, csuite.aead_iv_length);
|
|
1310
|
+
memset(iv, 0, VLA_SIZEOF(iv));
|
|
2498
1311
|
|
|
2499
1312
|
size_t aad_len = 0;
|
|
2500
1313
|
ret = comp_aad_3_len(ctx, &aad_len);
|
|
@@ -2502,39 +1315,38 @@ int edhoc_message_3_process(struct edhoc_context *ctx, const uint8_t *msg_3,
|
|
|
2502
1315
|
if (EDHOC_SUCCESS != ret)
|
|
2503
1316
|
return EDHOC_ERROR_BUFFER_TOO_SMALL;
|
|
2504
1317
|
|
|
2505
|
-
|
|
2506
|
-
memset(aad, 0,
|
|
1318
|
+
VLA_ALLOC(uint8_t, aad, aad_len);
|
|
1319
|
+
memset(aad, 0, VLA_SIZEOF(aad));
|
|
2507
1320
|
|
|
2508
|
-
ret = comp_key_iv_aad(ctx, key,
|
|
2509
|
-
|
|
1321
|
+
ret = comp_key_iv_aad(ctx, key, VLA_SIZE(key), iv, VLA_SIZE(iv), aad,
|
|
1322
|
+
VLA_SIZE(aad));
|
|
2510
1323
|
|
|
2511
1324
|
if (EDHOC_SUCCESS != ret)
|
|
2512
1325
|
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
2513
1326
|
|
|
2514
1327
|
if (NULL != ctx->logger) {
|
|
2515
|
-
ctx->logger(ctx->user_ctx, "K_3", key,
|
|
2516
|
-
ctx->logger(ctx->user_ctx, "IV_3", iv,
|
|
2517
|
-
ctx->logger(ctx->user_ctx, "AAD_3", aad,
|
|
1328
|
+
ctx->logger(ctx->user_ctx, "K_3", key, VLA_SIZE(key));
|
|
1329
|
+
ctx->logger(ctx->user_ctx, "IV_3", iv, VLA_SIZE(iv));
|
|
1330
|
+
ctx->logger(ctx->user_ctx, "AAD_3", aad, VLA_SIZE(aad));
|
|
2518
1331
|
}
|
|
2519
1332
|
|
|
2520
1333
|
/* 4. Decrypt ciphertext. */
|
|
2521
|
-
|
|
2522
|
-
memset(ptxt, 0,
|
|
1334
|
+
VLA_ALLOC(uint8_t, ptxt, ctxt_len - csuite.aead_tag_length);
|
|
1335
|
+
memset(ptxt, 0, VLA_SIZEOF(ptxt));
|
|
2523
1336
|
|
|
2524
|
-
ret = decrypt_ciphertext(ctx, key,
|
|
2525
|
-
|
|
2526
|
-
|
|
1337
|
+
ret = decrypt_ciphertext(ctx, key, VLA_SIZE(key), iv, VLA_SIZE(iv), aad,
|
|
1338
|
+
VLA_SIZE(aad), ctxt, ctxt_len, ptxt,
|
|
1339
|
+
VLA_SIZE(ptxt));
|
|
2527
1340
|
|
|
2528
1341
|
if (EDHOC_SUCCESS != ret)
|
|
2529
1342
|
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
2530
1343
|
|
|
2531
1344
|
if (NULL != ctx->logger)
|
|
2532
|
-
ctx->logger(ctx->user_ctx, "PLAINTEXT_3", ptxt,
|
|
2533
|
-
ARRAY_SIZE_VLA(ptxt));
|
|
1345
|
+
ctx->logger(ctx->user_ctx, "PLAINTEXT_3", ptxt, VLA_SIZE(ptxt));
|
|
2534
1346
|
|
|
2535
1347
|
/* 5. Parse CBOR plaintext (PLAINTEXT_3). */
|
|
2536
1348
|
struct plaintext parsed_ptxt = { 0 };
|
|
2537
|
-
ret = parse_plaintext(ctx, ptxt,
|
|
1349
|
+
ret = parse_plaintext(ctx, ptxt, VLA_SIZE(ptxt), &parsed_ptxt);
|
|
2538
1350
|
|
|
2539
1351
|
if (EDHOC_SUCCESS != ret)
|
|
2540
1352
|
return EDHOC_ERROR_CBOR_FAILURE;
|
|
@@ -2542,7 +1354,7 @@ int edhoc_message_3_process(struct edhoc_context *ctx, const uint8_t *msg_3,
|
|
|
2542
1354
|
/* 6. Process EAD_3 if present. */
|
|
2543
1355
|
if (NULL != ctx->ead.process && 0 != ARRAY_SIZE(ctx->ead_token) - 1 &&
|
|
2544
1356
|
0 != ctx->nr_of_ead_tokens) {
|
|
2545
|
-
ret = ctx->ead.process(ctx->user_ctx,
|
|
1357
|
+
ret = ctx->ead.process(ctx->user_ctx, ctx->message,
|
|
2546
1358
|
ctx->ead_token, ctx->nr_of_ead_tokens);
|
|
2547
1359
|
|
|
2548
1360
|
if (EDHOC_SUCCESS != ret)
|
|
@@ -2569,7 +1381,7 @@ int edhoc_message_3_process(struct edhoc_context *ctx, const uint8_t *msg_3,
|
|
|
2569
1381
|
/* 7. Verify if credentials from peer are trusted. */
|
|
2570
1382
|
const uint8_t *pub_key = NULL;
|
|
2571
1383
|
size_t pub_key_len = 0;
|
|
2572
|
-
ret = ctx->cred.verify(ctx->user_ctx, &parsed_ptxt.
|
|
1384
|
+
ret = ctx->cred.verify(ctx->user_ctx, &parsed_ptxt.auth_cred, &pub_key,
|
|
2573
1385
|
&pub_key_len);
|
|
2574
1386
|
|
|
2575
1387
|
if (EDHOC_SUCCESS != ret) {
|
|
@@ -2579,70 +1391,67 @@ int edhoc_message_3_process(struct edhoc_context *ctx, const uint8_t *msg_3,
|
|
|
2579
1391
|
}
|
|
2580
1392
|
|
|
2581
1393
|
/* 8. Compute PRK_4e3m. */
|
|
2582
|
-
ret = comp_prk_4e3m(
|
|
2583
|
-
pub_key_len);
|
|
1394
|
+
ret = comp_prk_4e3m(ctx, &parsed_ptxt.auth_cred, pub_key, pub_key_len);
|
|
2584
1395
|
|
|
2585
1396
|
if (EDHOC_SUCCESS != ret)
|
|
2586
1397
|
return EDHOC_ERROR_CRYPTO_FAILURE;
|
|
2587
1398
|
|
|
2588
1399
|
/* 9a. Compute required buffer length for context_3. */
|
|
2589
|
-
size_t
|
|
2590
|
-
ret =
|
|
2591
|
-
|
|
1400
|
+
size_t mac_context_len = 0;
|
|
1401
|
+
ret = edhoc_comp_mac_context_length(ctx, &parsed_ptxt.auth_cred,
|
|
1402
|
+
&mac_context_len);
|
|
2592
1403
|
|
|
2593
1404
|
if (EDHOC_SUCCESS != ret)
|
|
2594
1405
|
return EDHOC_ERROR_INVALID_MAC_3;
|
|
2595
1406
|
|
|
2596
|
-
ALLOCATE_ARRAY(uint8_t, mac_3_content, sizeof(struct cbor_items) + context_3_len);
|
|
2597
|
-
memset(mac_3_content, 0, ALLOCATE_ARRAY_SIZEOF(mac_3_content));
|
|
2598
|
-
|
|
2599
|
-
struct cbor_items *cbor_items = (struct cbor_items *)mac_3_content;
|
|
2600
|
-
cbor_items->buf_len = context_3_len;
|
|
2601
|
-
|
|
2602
1407
|
/* 9b. Cborise items required by context_3. */
|
|
2603
|
-
|
|
1408
|
+
VLA_ALLOC(uint8_t, mac_3_context_buf,
|
|
1409
|
+
sizeof(struct mac_context) + mac_context_len);
|
|
1410
|
+
memset(mac_3_context_buf, 0, VLA_SIZEOF(mac_3_context_buf));
|
|
1411
|
+
|
|
1412
|
+
struct mac_context *mac_context = (void *)mac_3_context_buf;
|
|
1413
|
+
mac_context->buf_len = mac_context_len;
|
|
2604
1414
|
|
|
1415
|
+
ret = edhoc_comp_mac_context(ctx, &parsed_ptxt.auth_cred, mac_context);
|
|
2605
1416
|
if (EDHOC_SUCCESS != ret)
|
|
2606
|
-
return
|
|
1417
|
+
return ret;
|
|
2607
1418
|
|
|
2608
1419
|
if (NULL != ctx->logger) {
|
|
2609
|
-
ctx->logger(ctx->user_ctx, "
|
|
2610
|
-
|
|
2611
|
-
ctx->logger(ctx->user_ctx, "
|
|
2612
|
-
|
|
2613
|
-
ctx->logger(ctx->user_ctx, "
|
|
2614
|
-
|
|
2615
|
-
ctx->logger(ctx->user_ctx, "
|
|
2616
|
-
|
|
1420
|
+
ctx->logger(ctx->user_ctx, "C_I", mac_context->conn_id,
|
|
1421
|
+
mac_context->conn_id_len);
|
|
1422
|
+
ctx->logger(ctx->user_ctx, "ID_CRED_I", mac_context->id_cred,
|
|
1423
|
+
mac_context->id_cred_len);
|
|
1424
|
+
ctx->logger(ctx->user_ctx, "TH_3", mac_context->th,
|
|
1425
|
+
mac_context->th_len);
|
|
1426
|
+
ctx->logger(ctx->user_ctx, "CRED_I", mac_context->cred,
|
|
1427
|
+
mac_context->cred_len);
|
|
1428
|
+
ctx->logger(ctx->user_ctx, "context_3", mac_context->buf,
|
|
1429
|
+
mac_context->buf_len);
|
|
2617
1430
|
}
|
|
2618
1431
|
|
|
2619
1432
|
/* 9c. Compute Message Authentication Code (MAC_3). */
|
|
2620
|
-
size_t
|
|
2621
|
-
ret =
|
|
2622
|
-
|
|
1433
|
+
size_t mac_length = 0;
|
|
1434
|
+
ret = edhoc_comp_mac_length(ctx, &mac_length);
|
|
2623
1435
|
if (EDHOC_SUCCESS != ret)
|
|
2624
1436
|
return EDHOC_ERROR_INVALID_MAC_3;
|
|
2625
1437
|
|
|
2626
|
-
|
|
2627
|
-
memset(
|
|
2628
|
-
|
|
2629
|
-
ret = comp_mac_3(ctx, cbor_items, mac_3, ARRAY_SIZE_VLA(mac_3));
|
|
2630
|
-
|
|
1438
|
+
VLA_ALLOC(uint8_t, mac_buf, mac_length);
|
|
1439
|
+
memset(mac_buf, 0, VLA_SIZEOF(mac_buf));
|
|
1440
|
+
ret = edhoc_comp_mac(ctx, mac_context, mac_buf, mac_length);
|
|
2631
1441
|
if (EDHOC_SUCCESS != ret)
|
|
2632
1442
|
return EDHOC_ERROR_INVALID_MAC_3;
|
|
2633
1443
|
|
|
2634
|
-
if (NULL != ctx->logger)
|
|
2635
|
-
ctx->logger(ctx->user_ctx, "MAC_3", mac_3, ARRAY_SIZE_VLA(mac_3));
|
|
2636
|
-
|
|
2637
1444
|
/* 10. Verify Signature_or_MAC_3. */
|
|
2638
|
-
ret =
|
|
2639
|
-
|
|
1445
|
+
ret = edhoc_verify_sign_or_mac(ctx, mac_context, pub_key, pub_key_len,
|
|
1446
|
+
parsed_ptxt.sign_or_mac,
|
|
1447
|
+
parsed_ptxt.sign_or_mac_len, mac_buf,
|
|
1448
|
+
mac_length);
|
|
2640
1449
|
|
|
2641
1450
|
if (EDHOC_SUCCESS != ret)
|
|
2642
|
-
return
|
|
1451
|
+
return EDHOC_ERROR_INVALID_SIGN_OR_MAC_2;
|
|
2643
1452
|
|
|
2644
1453
|
/* 11. Compute transcript hash 4. */
|
|
2645
|
-
ret = comp_th_4(ctx,
|
|
1454
|
+
ret = comp_th_4(ctx, mac_context, ptxt, VLA_SIZE(ptxt));
|
|
2646
1455
|
|
|
2647
1456
|
if (EDHOC_SUCCESS != ret)
|
|
2648
1457
|
return EDHOC_ERROR_TRANSCRIPT_HASH_FAILURE;
|