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
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#include <string.h>
|
|
11
11
|
#include "zcbor_encode.h"
|
|
12
12
|
#include "zcbor_common.h"
|
|
13
|
+
#include "zcbor_print.h"
|
|
13
14
|
|
|
14
15
|
_Static_assert((sizeof(size_t) == sizeof(void *)),
|
|
15
16
|
"This code needs size_t to be the same length as pointers.");
|
|
@@ -28,7 +29,7 @@ static uint8_t log2ceil(size_t val)
|
|
|
28
29
|
case 8: return 3;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
zcbor_log("Should not come here.\r\n");
|
|
32
33
|
return 0;
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -45,101 +46,57 @@ static bool encode_header_byte(zcbor_state_t *state,
|
|
|
45
46
|
ZCBOR_CHECK_ERROR();
|
|
46
47
|
ZCBOR_CHECK_PAYLOAD();
|
|
47
48
|
|
|
48
|
-
zcbor_assert_state(additional < 32,
|
|
49
|
+
zcbor_assert_state(additional < 32, "Unsupported additional value: %d\r\n", additional);
|
|
49
50
|
|
|
50
51
|
*(state->payload_mut++) = (uint8_t)((major_type << 5) | (additional & 0x1F));
|
|
51
52
|
return true;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
|
|
55
|
-
static size_t get_encoded_len(const void *const result, size_t result_len);
|
|
56
|
-
|
|
57
|
-
|
|
58
56
|
/** Encode a single value.
|
|
59
57
|
*/
|
|
60
58
|
static bool value_encode_len(zcbor_state_t *state, zcbor_major_type_t major_type,
|
|
61
59
|
const void *const result, size_t result_len)
|
|
62
60
|
{
|
|
63
61
|
uint8_t *u8_result = (uint8_t *)result;
|
|
64
|
-
size_t encoded_len = get_encoded_len(result, result_len);
|
|
65
62
|
|
|
66
|
-
if ((state->payload + 1 +
|
|
63
|
+
if ((state->payload + 1 + result_len) > state->payload_end) {
|
|
67
64
|
ZCBOR_ERR(ZCBOR_ERR_NO_PAYLOAD);
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
if (!encode_header_byte(state, major_type,
|
|
71
|
-
get_additional(
|
|
68
|
+
get_additional(result_len, u8_result[0]))) {
|
|
72
69
|
ZCBOR_FAIL();
|
|
73
70
|
}
|
|
74
71
|
state->payload_mut--;
|
|
75
|
-
zcbor_trace();
|
|
72
|
+
zcbor_trace(state, "value_encode_len");
|
|
76
73
|
state->payload_mut++;
|
|
77
74
|
|
|
78
|
-
#ifdef
|
|
79
|
-
memcpy(state->payload_mut, u8_result,
|
|
80
|
-
state->payload_mut +=
|
|
75
|
+
#ifdef ZCBOR_BIG_ENDIAN
|
|
76
|
+
memcpy(state->payload_mut, u8_result, result_len);
|
|
77
|
+
state->payload_mut += result_len;
|
|
81
78
|
#else
|
|
82
|
-
for (;
|
|
83
|
-
*(state->payload_mut++) = u8_result[
|
|
79
|
+
for (; result_len > 0; result_len--) {
|
|
80
|
+
*(state->payload_mut++) = u8_result[result_len - 1];
|
|
84
81
|
}
|
|
85
|
-
#endif /*
|
|
82
|
+
#endif /* ZCBOR_BIG_ENDIAN */
|
|
86
83
|
|
|
87
84
|
state->elem_count++;
|
|
88
85
|
return true;
|
|
89
86
|
}
|
|
90
87
|
|
|
91
88
|
|
|
92
|
-
static size_t get_result_len(const void *const input, size_t max_result_len)
|
|
93
|
-
{
|
|
94
|
-
uint8_t *u8_result = (uint8_t *)input;
|
|
95
|
-
size_t len = max_result_len;
|
|
96
|
-
|
|
97
|
-
for (; len > 0; len--) {
|
|
98
|
-
#ifdef CONFIG_BIG_ENDIAN
|
|
99
|
-
if (u8_result[max_result_len - len] != 0) {
|
|
100
|
-
#else
|
|
101
|
-
if (u8_result[len - 1] != 0) {
|
|
102
|
-
#endif /* CONFIG_BIG_ENDIAN */
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/* Round up to nearest power of 2. */
|
|
108
|
-
return len <= 2 ? len : (uint8_t)(1 << log2ceil(len));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
static const void *get_result(const void *const input, size_t max_result_len,
|
|
113
|
-
size_t result_len)
|
|
114
|
-
{
|
|
115
|
-
#ifdef CONFIG_BIG_ENDIAN
|
|
116
|
-
return &((uint8_t *)input)[max_result_len - (result_len ? result_len : 1)];
|
|
117
|
-
#else
|
|
118
|
-
(void)max_result_len;
|
|
119
|
-
(void)result_len;
|
|
120
|
-
return input;
|
|
121
|
-
#endif
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
static size_t get_encoded_len(const void *const result, size_t result_len)
|
|
126
|
-
{
|
|
127
|
-
const uint8_t *u8_result = (const uint8_t *)result;
|
|
128
|
-
|
|
129
|
-
if ((result_len == 1) && (u8_result[0] <= ZCBOR_VALUE_IN_HEADER)) {
|
|
130
|
-
return 0;
|
|
131
|
-
}
|
|
132
|
-
return result_len;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
89
|
static bool value_encode(zcbor_state_t *state, zcbor_major_type_t major_type,
|
|
137
90
|
const void *const input, size_t max_result_len)
|
|
138
91
|
{
|
|
139
92
|
zcbor_assert_state(max_result_len != 0, "0-length result not supported.\r\n");
|
|
140
93
|
|
|
141
|
-
size_t result_len =
|
|
142
|
-
const void *
|
|
94
|
+
size_t result_len = zcbor_header_len_ptr(input, max_result_len) - 1;
|
|
95
|
+
const void *result = input;
|
|
96
|
+
|
|
97
|
+
#ifdef ZCBOR_BIG_ENDIAN
|
|
98
|
+
result = (uint8_t *)input + max_result_len - (result_len ? result_len : 1);
|
|
99
|
+
#endif
|
|
143
100
|
|
|
144
101
|
return value_encode_len(state, major_type, result, result_len);
|
|
145
102
|
}
|
|
@@ -157,7 +114,7 @@ bool zcbor_int_encode(zcbor_state_t *state, const void *input_int, size_t int_si
|
|
|
157
114
|
ZCBOR_ERR(ZCBOR_ERR_INT_SIZE);
|
|
158
115
|
}
|
|
159
116
|
|
|
160
|
-
#ifdef
|
|
117
|
+
#ifdef ZCBOR_BIG_ENDIAN
|
|
161
118
|
if (input_int8[0] < 0) {
|
|
162
119
|
#else
|
|
163
120
|
if (input_int8[int_size - 1] < 0) {
|
|
@@ -184,7 +141,7 @@ bool zcbor_int_encode(zcbor_state_t *state, const void *input_int, size_t int_si
|
|
|
184
141
|
bool zcbor_uint_encode(zcbor_state_t *state, const void *input_uint, size_t uint_size)
|
|
185
142
|
{
|
|
186
143
|
if (!value_encode(state, ZCBOR_MAJOR_TYPE_PINT, input_uint, uint_size)) {
|
|
187
|
-
|
|
144
|
+
zcbor_log("uint with size %zu failed.\r\n", uint_size);
|
|
188
145
|
ZCBOR_FAIL();
|
|
189
146
|
}
|
|
190
147
|
return true;
|
|
@@ -255,8 +212,8 @@ bool zcbor_size_encode(zcbor_state_t *state, const size_t *input)
|
|
|
255
212
|
static bool str_start_encode(zcbor_state_t *state,
|
|
256
213
|
const struct zcbor_string *input, zcbor_major_type_t major_type)
|
|
257
214
|
{
|
|
258
|
-
if (input->value && ((
|
|
259
|
-
+
|
|
215
|
+
if (input->value && ((zcbor_header_len_ptr(&input->len, sizeof(input->len))
|
|
216
|
+
+ input->len + (size_t)state->payload)
|
|
260
217
|
> (size_t)state->payload_end)) {
|
|
261
218
|
ZCBOR_ERR(ZCBOR_ERR_NO_PAYLOAD);
|
|
262
219
|
}
|
|
@@ -271,7 +228,7 @@ static bool str_start_encode(zcbor_state_t *state,
|
|
|
271
228
|
static size_t remaining_str_len(zcbor_state_t *state)
|
|
272
229
|
{
|
|
273
230
|
size_t max_len = (size_t)state->payload_end - (size_t)state->payload;
|
|
274
|
-
size_t result_len =
|
|
231
|
+
size_t result_len = zcbor_header_len_ptr(&max_len, sizeof(max_len)) - 1;
|
|
275
232
|
|
|
276
233
|
return max_len - result_len - 1;
|
|
277
234
|
}
|
|
@@ -352,6 +309,34 @@ bool zcbor_tstr_encode(zcbor_state_t *state, const struct zcbor_string *input)
|
|
|
352
309
|
}
|
|
353
310
|
|
|
354
311
|
|
|
312
|
+
bool zcbor_bstr_encode_ptr(zcbor_state_t *state, const char *str, size_t len)
|
|
313
|
+
{
|
|
314
|
+
const struct zcbor_string zs = { .value = (const uint8_t *)str, .len = len };
|
|
315
|
+
|
|
316
|
+
return zcbor_bstr_encode(state, &zs);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
bool zcbor_tstr_encode_ptr(zcbor_state_t *state, const char *str, size_t len)
|
|
321
|
+
{
|
|
322
|
+
const struct zcbor_string zs = { .value = (const uint8_t *)str, .len = len };
|
|
323
|
+
|
|
324
|
+
return zcbor_tstr_encode(state, &zs);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
bool zcbor_bstr_put_term(zcbor_state_t *state, char const *str, size_t maxlen)
|
|
329
|
+
{
|
|
330
|
+
return zcbor_bstr_encode_ptr(state, str, strnlen(str, maxlen));
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
bool zcbor_tstr_put_term(zcbor_state_t *state, char const *str, size_t maxlen)
|
|
335
|
+
{
|
|
336
|
+
return zcbor_tstr_encode_ptr(state, str, strnlen(str, maxlen));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
|
|
355
340
|
static bool list_map_start_encode(zcbor_state_t *state, size_t max_num,
|
|
356
341
|
zcbor_major_type_t major_type)
|
|
357
342
|
{
|
|
@@ -388,17 +373,6 @@ bool zcbor_map_start_encode(zcbor_state_t *state, size_t max_num)
|
|
|
388
373
|
}
|
|
389
374
|
|
|
390
375
|
|
|
391
|
-
#ifdef ZCBOR_CANONICAL
|
|
392
|
-
static size_t get_encoded_len2(const void *const input, size_t max_result_len)
|
|
393
|
-
{
|
|
394
|
-
size_t result_len = get_result_len(input, max_result_len);
|
|
395
|
-
const void *const result = get_result(input, max_result_len, result_len);
|
|
396
|
-
|
|
397
|
-
return get_encoded_len(result, result_len);
|
|
398
|
-
}
|
|
399
|
-
#endif
|
|
400
|
-
|
|
401
|
-
|
|
402
376
|
static bool list_map_end_encode(zcbor_state_t *state, size_t max_num,
|
|
403
377
|
zcbor_major_type_t major_type)
|
|
404
378
|
{
|
|
@@ -409,21 +383,21 @@ static bool list_map_end_encode(zcbor_state_t *state, size_t max_num,
|
|
|
409
383
|
|
|
410
384
|
const uint8_t *payload = state->payload;
|
|
411
385
|
|
|
412
|
-
size_t max_header_len =
|
|
413
|
-
size_t header_len =
|
|
386
|
+
size_t max_header_len = zcbor_header_len_ptr(&max_num, 4) - 1;
|
|
387
|
+
size_t header_len = zcbor_header_len_ptr(&list_count, 4) - 1;
|
|
414
388
|
|
|
415
389
|
if (!zcbor_process_backup(state, ZCBOR_FLAG_RESTORE | ZCBOR_FLAG_CONSUME, 0xFFFFFFFF)) {
|
|
416
390
|
ZCBOR_FAIL();
|
|
417
391
|
}
|
|
418
392
|
|
|
419
|
-
|
|
393
|
+
zcbor_log("list_count: %zu\r\n", list_count);
|
|
420
394
|
|
|
421
395
|
|
|
422
396
|
/** If max_num is smaller than the actual number of encoded elements,
|
|
423
397
|
* the value_encode() below will corrupt the data if the encoded
|
|
424
398
|
* header is larger than the previously encoded header. */
|
|
425
399
|
if (header_len > max_header_len) {
|
|
426
|
-
|
|
400
|
+
zcbor_log("max_num too small.\r\n");
|
|
427
401
|
ZCBOR_ERR(ZCBOR_ERR_HIGH_ELEM_COUNT);
|
|
428
402
|
}
|
|
429
403
|
|
|
@@ -482,7 +456,7 @@ bool zcbor_list_map_end_force_encode(zcbor_state_t *state)
|
|
|
482
456
|
bool zcbor_simple_encode(zcbor_state_t *state, uint8_t *input)
|
|
483
457
|
{
|
|
484
458
|
if (!value_encode(state, ZCBOR_MAJOR_TYPE_SIMPLE, input, sizeof(*input))) {
|
|
485
|
-
|
|
459
|
+
zcbor_log("Error encoding %u (0x%p)\r\n", *input, input);
|
|
486
460
|
ZCBOR_FAIL();
|
|
487
461
|
}
|
|
488
462
|
return true;
|
|
@@ -560,87 +534,10 @@ bool zcbor_float16_encode(zcbor_state_t *state, const float *input)
|
|
|
560
534
|
return zcbor_float16_put(state, *input);
|
|
561
535
|
}
|
|
562
536
|
|
|
563
|
-
/* Float16: */
|
|
564
|
-
#define F16_SIGN_OFFS 15 /* Bit offset of the sign bit. */
|
|
565
|
-
#define F16_EXPO_OFFS 10 /* Bit offset of the exponent. */
|
|
566
|
-
#define F16_EXPO_MSK 0x1F /* Bitmask for the exponent (right shifted by F16_EXPO_OFFS). */
|
|
567
|
-
#define F16_MANTISSA_MSK 0x3FF /* Bitmask for the mantissa. */
|
|
568
|
-
#define F16_MAX 65520 /* Lowest float32 value that rounds up to float16 infinity.
|
|
569
|
-
* (65519.996 rounds to 65504) */
|
|
570
|
-
#define F16_MIN_EXPO 24 /* Negative exponent of the non-zero float16 value closest to 0 (2^-24) */
|
|
571
|
-
#define F16_MIN (1.0 / (1 << F16_MIN_EXPO)) /* The non-zero float16 value closest to 0 (2^-24) */
|
|
572
|
-
#define F16_MIN_NORM (1.0 / (1 << 14)) /* The normalized float16 value closest to 0 (2^-14) */
|
|
573
|
-
#define F16_BIAS 15 /* The exponent bias of normalized float16 values. */
|
|
574
|
-
|
|
575
|
-
/* Float32: */
|
|
576
|
-
#define F32_SIGN_OFFS 31 /* Bit offset of the sign bit. */
|
|
577
|
-
#define F32_EXPO_OFFS 23 /* Bit offset of the exponent. */
|
|
578
|
-
#define F32_EXPO_MSK 0xFF /* Bitmask for the exponent (right shifted by F32_EXPO_OFFS). */
|
|
579
|
-
#define F32_MANTISSA_MSK 0x7FFFFF /* Bitmask for the mantissa. */
|
|
580
|
-
#define F32_BIAS 127 /* The exponent bias of normalized float32 values. */
|
|
581
|
-
|
|
582
|
-
/* Rounding: */
|
|
583
|
-
#define SUBNORM_ROUND_MSK (F32_MANTISSA_MSK | (1 << F32_EXPO_OFFS)) /* mantissa + lsb of expo for
|
|
584
|
-
* tiebreak. */
|
|
585
|
-
#define SUBNORM_ROUND_BIT_MSK (1 << (F32_EXPO_OFFS - 1)) /* msb of mantissa (0x400000) */
|
|
586
|
-
#define NORM_ROUND_MSK (F32_MANTISSA_MSK >> (F16_EXPO_OFFS - 1)) /* excess mantissa when going from
|
|
587
|
-
* float32 to float16 + 1 extra bit
|
|
588
|
-
* for tiebreak. */
|
|
589
|
-
#define NORM_ROUND_BIT_MSK (1 << (F32_EXPO_OFFS - F16_EXPO_OFFS - 1)) /* bit 12 (0x1000) */
|
|
590
537
|
|
|
591
538
|
bool zcbor_float16_put(zcbor_state_t *state, float input)
|
|
592
539
|
{
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
uint32_t sign = value32 >> F32_SIGN_OFFS;
|
|
596
|
-
uint32_t expo = (value32 >> F32_EXPO_OFFS) & F32_EXPO_MSK;
|
|
597
|
-
uint32_t mantissa = value32 & F32_MANTISSA_MSK;
|
|
598
|
-
|
|
599
|
-
uint16_t value16 = (uint16_t)(sign << F16_SIGN_OFFS);
|
|
600
|
-
|
|
601
|
-
float abs_input;
|
|
602
|
-
*(uint32_t *)&abs_input = value32 & ~(1 << F32_SIGN_OFFS);
|
|
603
|
-
|
|
604
|
-
if (abs_input <= (F16_MIN / 2)) {
|
|
605
|
-
/* 0 or too small for float16. Round down to 0. value16 is already correct. */
|
|
606
|
-
} else if (abs_input < F16_MIN) {
|
|
607
|
-
/* Round up to 2^(-24) (F16_MIN), has other rounding rules than larger values. */
|
|
608
|
-
value16 |= 0x0001;
|
|
609
|
-
} else if (abs_input < F16_MIN_NORM) {
|
|
610
|
-
/* Subnormal float16 (normal float32) */
|
|
611
|
-
uint32_t adjusted_mantissa =
|
|
612
|
-
/* Adjust for the purposes of checking rounding. */
|
|
613
|
-
/* The lsb of expo is needed for the cases where expo is 103 (minimum). */
|
|
614
|
-
((value32 << (expo - (F32_BIAS - F16_MIN_EXPO))) & SUBNORM_ROUND_MSK);
|
|
615
|
-
uint16_t rounding_bit =
|
|
616
|
-
/* "Round to nearest, ties to even". */
|
|
617
|
-
/* 0x400000 means ties go down towards even. (0xC00000 means ties go up.) */
|
|
618
|
-
(adjusted_mantissa & SUBNORM_ROUND_BIT_MSK)
|
|
619
|
-
&& (adjusted_mantissa != SUBNORM_ROUND_BIT_MSK);
|
|
620
|
-
value16 |= ((uint16_t)(abs_input * (1 << 24)) + rounding_bit); /* expo is 0 */
|
|
621
|
-
} else if (abs_input < F16_MAX) {
|
|
622
|
-
/* Normal float16 (normal float32) */
|
|
623
|
-
uint16_t rounding_bit =
|
|
624
|
-
/* Bit 13 of the mantissa represents which way to round, except for the */
|
|
625
|
-
/* special case where bits 0-12 and 14 are 0. */
|
|
626
|
-
/* This is because of "Round to nearest, ties to even". */
|
|
627
|
-
/* 0x1000 means ties go down towards even. (0x3000 means ties go up.) */
|
|
628
|
-
((mantissa & NORM_ROUND_BIT_MSK)
|
|
629
|
-
&& ((mantissa & NORM_ROUND_MSK) != NORM_ROUND_BIT_MSK));
|
|
630
|
-
value16 |= (uint16_t)((expo - (F32_BIAS - F16_BIAS)) << F16_EXPO_OFFS);
|
|
631
|
-
value16 |= (uint16_t)(mantissa >> (F32_EXPO_OFFS - F16_EXPO_OFFS));
|
|
632
|
-
value16 += rounding_bit; /* Might propagate to exponent. */
|
|
633
|
-
} else if (expo != F32_EXPO_MSK || !mantissa) {
|
|
634
|
-
/* Infinite, or finite normal float32 too large for float16. Round up to inf. */
|
|
635
|
-
value16 |= (F16_EXPO_MSK << F16_EXPO_OFFS);
|
|
636
|
-
} else {
|
|
637
|
-
/* NaN */
|
|
638
|
-
/* Preserve msbit of mantissa. */
|
|
639
|
-
uint16_t new_mantissa = (uint16_t)(mantissa >> (F32_EXPO_OFFS - F16_EXPO_OFFS));
|
|
640
|
-
value16 |= (F16_EXPO_MSK << F16_EXPO_OFFS) | (new_mantissa ? new_mantissa : 1);
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
return zcbor_float16_bytes_put(state, value16);
|
|
540
|
+
return zcbor_float16_bytes_put(state, zcbor_float32_to_16(input));
|
|
644
541
|
}
|
|
645
542
|
|
|
646
543
|
|
|
@@ -661,7 +558,7 @@ bool zcbor_float16_bytes_put(zcbor_state_t *state, uint16_t input)
|
|
|
661
558
|
}
|
|
662
559
|
|
|
663
560
|
|
|
664
|
-
bool
|
|
561
|
+
bool zcbor_tag_put(zcbor_state_t *state, uint32_t tag)
|
|
665
562
|
{
|
|
666
563
|
if (!value_encode(state, ZCBOR_MAJOR_TYPE_TAG, &tag, sizeof(tag))) {
|
|
667
564
|
ZCBOR_FAIL();
|
|
@@ -672,13 +569,15 @@ bool zcbor_tag_encode(zcbor_state_t *state, uint32_t tag)
|
|
|
672
569
|
}
|
|
673
570
|
|
|
674
571
|
|
|
675
|
-
bool
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
572
|
+
bool zcbor_tag_encode(zcbor_state_t *state, uint32_t *tag)
|
|
573
|
+
{
|
|
574
|
+
return zcbor_tag_put(state, *tag);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
bool zcbor_multi_encode_minmax(size_t min_encode, size_t max_encode,
|
|
579
|
+
const size_t *num_encode, zcbor_encoder_t encoder,
|
|
580
|
+
zcbor_state_t *state, const void *input, size_t result_len)
|
|
682
581
|
{
|
|
683
582
|
|
|
684
583
|
if ((*num_encode >= min_encode) && (*num_encode <= max_encode)) {
|
|
@@ -689,11 +588,8 @@ bool zcbor_multi_encode_minmax(size_t min_encode,
|
|
|
689
588
|
}
|
|
690
589
|
|
|
691
590
|
|
|
692
|
-
bool zcbor_multi_encode(size_t num_encode,
|
|
693
|
-
|
|
694
|
-
zcbor_state_t *state,
|
|
695
|
-
const void *input,
|
|
696
|
-
size_t result_len)
|
|
591
|
+
bool zcbor_multi_encode(const size_t num_encode, zcbor_encoder_t encoder,
|
|
592
|
+
zcbor_state_t *state, const void *input, size_t result_len)
|
|
697
593
|
{
|
|
698
594
|
ZCBOR_CHECK_ERROR();
|
|
699
595
|
for (size_t i = 0; i < num_encode; i++) {
|
|
@@ -701,22 +597,13 @@ bool zcbor_multi_encode(size_t num_encode,
|
|
|
701
597
|
ZCBOR_FAIL();
|
|
702
598
|
}
|
|
703
599
|
}
|
|
704
|
-
|
|
600
|
+
zcbor_log("Encoded %zu elements.\n", num_encode);
|
|
705
601
|
return true;
|
|
706
602
|
}
|
|
707
603
|
|
|
708
604
|
|
|
709
|
-
bool zcbor_present_encode(const bool *present,
|
|
710
|
-
zcbor_encoder_t encoder,
|
|
711
|
-
zcbor_state_t *state,
|
|
712
|
-
const void *input)
|
|
713
|
-
{
|
|
714
|
-
return zcbor_multi_encode(!!*present, encoder, state, input, 0);
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
|
|
718
605
|
void zcbor_new_encode_state(zcbor_state_t *state_array, size_t n_states,
|
|
719
606
|
uint8_t *payload, size_t payload_len, size_t elem_count)
|
|
720
607
|
{
|
|
721
|
-
zcbor_new_state(state_array, n_states, payload, payload_len, elem_count);
|
|
608
|
+
zcbor_new_state(state_array, n_states, payload, payload_len, elem_count, NULL, 0);
|
|
722
609
|
}
|