edhoc 1.0.5 → 1.1.1

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.
Files changed (313) hide show
  1. package/README.md +170 -0
  2. package/binding.gyp +13 -11
  3. package/dist/crypto.d.ts +9 -2
  4. package/dist/crypto.d.ts.map +1 -1
  5. package/dist/crypto.js +112 -84
  6. package/dist/edhoc.d.ts +31 -9
  7. package/dist/edhoc.d.ts.map +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/x509credentials.d.ts +20 -0
  12. package/dist/x509credentials.d.ts.map +1 -0
  13. package/dist/x509credentials.js +140 -0
  14. package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_decode.h +1 -1
  15. package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_encode.h +1 -1
  16. package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_types.h +1 -1
  17. package/external/libedhoc/backends/cbor/include/backend_cbor_ead_decode.h +2 -2
  18. package/external/libedhoc/backends/cbor/include/backend_cbor_ead_encode.h +2 -2
  19. package/external/libedhoc/backends/cbor/include/backend_cbor_edhoc_types.h +48 -43
  20. package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_decode.h +1 -1
  21. package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_encode.h +1 -1
  22. package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_types.h +3 -3
  23. package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_decode.h +1 -1
  24. package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_encode.h +1 -1
  25. package/external/libedhoc/backends/cbor/include/backend_cbor_info_decode.h +1 -1
  26. package/external/libedhoc/backends/cbor/include/backend_cbor_info_encode.h +1 -1
  27. package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_decode.h +1 -1
  28. package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_encode.h +1 -1
  29. package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_types.h +1 -1
  30. package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_decode.h +1 -1
  31. package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_encode.h +1 -1
  32. package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_decode.h +1 -1
  33. package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_encode.h +1 -1
  34. package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_decode.h +1 -1
  35. package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_encode.h +1 -1
  36. package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_decode.h +1 -1
  37. package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_encode.h +1 -1
  38. package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_decode.h +1 -1
  39. package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_encode.h +1 -1
  40. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_decode.h +1 -1
  41. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_encode.h +1 -1
  42. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_decode.h +1 -1
  43. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_encode.h +1 -1
  44. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_decode.h +3 -3
  45. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_encode.h +3 -3
  46. package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_decode.h +1 -1
  47. package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_encode.h +1 -1
  48. package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_types.h +4 -4
  49. package/external/libedhoc/backends/cbor/include/backend_cbor_x509_types.h +93 -83
  50. package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_decode.c +11 -20
  51. package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_encode.c +11 -20
  52. package/external/libedhoc/backends/cbor/src/backend_cbor_ead_decode.c +27 -32
  53. package/external/libedhoc/backends/cbor/src/backend_cbor_ead_encode.c +27 -32
  54. package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_decode.c +14 -23
  55. package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_encode.c +14 -23
  56. package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_decode.c +63 -52
  57. package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_encode.c +62 -51
  58. package/external/libedhoc/backends/cbor/src/backend_cbor_info_decode.c +14 -23
  59. package/external/libedhoc/backends/cbor/src/backend_cbor_info_encode.c +14 -23
  60. package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_decode.c +11 -20
  61. package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_encode.c +11 -20
  62. package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_decode.c +54 -51
  63. package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_encode.c +54 -51
  64. package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_decode.c +11 -20
  65. package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_encode.c +11 -20
  66. package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_decode.c +11 -20
  67. package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_encode.c +11 -20
  68. package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_decode.c +11 -20
  69. package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_encode.c +11 -20
  70. package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_decode.c +36 -37
  71. package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_encode.c +36 -37
  72. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_decode.c +103 -80
  73. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_encode.c +102 -79
  74. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_decode.c +99 -76
  75. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_encode.c +98 -75
  76. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_decode.c +40 -41
  77. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_encode.c +40 -41
  78. package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_decode.c +15 -24
  79. package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_encode.c +15 -24
  80. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.c +31 -0
  81. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.h +10 -0
  82. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.c +18 -0
  83. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.h +9 -0
  84. package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode.c +69 -0
  85. package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode2.c +38 -0
  86. package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c +53 -0
  87. package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c +57 -0
  88. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.c +31 -0
  89. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.h +10 -0
  90. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.c +18 -0
  91. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.h +9 -0
  92. package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode.c +71 -0
  93. package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode2.c +40 -0
  94. package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c +16 -0
  95. package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c +18 -0
  96. package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/all_tests.c +19 -0
  97. package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.c +17 -0
  98. package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.h +19 -0
  99. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.c +31 -0
  100. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.h +10 -0
  101. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.c +18 -0
  102. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.h +9 -0
  103. package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode.c +69 -0
  104. package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode2.c +38 -0
  105. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.c +31 -0
  106. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.h +10 -0
  107. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.c +18 -0
  108. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.h +9 -0
  109. package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode.c +70 -0
  110. package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode2.c +42 -0
  111. package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode2_Runner.c +53 -0
  112. package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode_Runner.c +57 -0
  113. package/external/libedhoc/externals/Unity/examples/unity_config.h +251 -0
  114. package/external/libedhoc/externals/Unity/extras/bdd/src/unity_bdd.h +44 -0
  115. package/external/libedhoc/externals/Unity/extras/bdd/test/test_bdd.c +129 -0
  116. package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.c +310 -0
  117. package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.h +95 -0
  118. package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture_internals.h +51 -0
  119. package/external/libedhoc/externals/Unity/extras/fixture/test/main/AllTests.c +20 -0
  120. package/external/libedhoc/externals/Unity/extras/fixture/test/template_fixture_tests.c +40 -0
  121. package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_Test.c +246 -0
  122. package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_TestRunner.c +33 -0
  123. package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.c +203 -0
  124. package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.h +61 -0
  125. package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_Test.c +326 -0
  126. package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_TestRunner.c +50 -0
  127. package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.c +57 -0
  128. package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.h +17 -0
  129. package/external/libedhoc/externals/Unity/src/unity.c +2501 -0
  130. package/external/libedhoc/externals/Unity/src/unity.h +698 -0
  131. package/external/libedhoc/externals/Unity/src/unity_internals.h +1183 -0
  132. package/external/libedhoc/externals/Unity/test/expectdata/testsample_cmd.c +61 -0
  133. package/external/libedhoc/externals/Unity/test/expectdata/testsample_def.c +57 -0
  134. package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.c +55 -0
  135. package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.h +15 -0
  136. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_cmd.c +80 -0
  137. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_def.c +76 -0
  138. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.c +75 -0
  139. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.h +13 -0
  140. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new1.c +89 -0
  141. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new2.c +89 -0
  142. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_param.c +77 -0
  143. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run1.c +89 -0
  144. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run2.c +89 -0
  145. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_yaml.c +90 -0
  146. package/external/libedhoc/externals/Unity/test/expectdata/testsample_new1.c +67 -0
  147. package/external/libedhoc/externals/Unity/test/expectdata/testsample_new2.c +70 -0
  148. package/external/libedhoc/externals/Unity/test/expectdata/testsample_param.c +58 -0
  149. package/external/libedhoc/externals/Unity/test/expectdata/testsample_run1.c +67 -0
  150. package/external/libedhoc/externals/Unity/test/expectdata/testsample_run2.c +70 -0
  151. package/external/libedhoc/externals/Unity/test/expectdata/testsample_yaml.c +71 -0
  152. package/external/libedhoc/externals/Unity/test/testdata/CException.h +18 -0
  153. package/external/libedhoc/externals/Unity/test/testdata/Defs.h +16 -0
  154. package/external/libedhoc/externals/Unity/test/testdata/cmock.h +21 -0
  155. package/external/libedhoc/externals/Unity/test/testdata/mockMock.h +20 -0
  156. package/external/libedhoc/externals/Unity/test/testdata/testRunnerGenerator.c +204 -0
  157. package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorSmall.c +73 -0
  158. package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorWithMocks.c +200 -0
  159. package/external/libedhoc/externals/Unity/test/tests/self_assessment_utils.h +151 -0
  160. package/external/libedhoc/externals/Unity/test/tests/test_unity_arrays.c +2941 -0
  161. package/external/libedhoc/externals/Unity/test/tests/test_unity_core.c +375 -0
  162. package/external/libedhoc/externals/Unity/test/tests/test_unity_doubles.c +1285 -0
  163. package/external/libedhoc/externals/Unity/test/tests/test_unity_floats.c +1395 -0
  164. package/external/libedhoc/externals/Unity/test/tests/test_unity_integers.c +2863 -0
  165. package/external/libedhoc/externals/Unity/test/tests/test_unity_integers_64.c +783 -0
  166. package/external/libedhoc/externals/Unity/test/tests/test_unity_memory.c +82 -0
  167. package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterized.c +309 -0
  168. package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterizedDemo.c +28 -0
  169. package/external/libedhoc/externals/Unity/test/tests/test_unity_strings.c +330 -0
  170. package/external/libedhoc/externals/Unity/test/tests/types_for_test.h +21 -0
  171. package/external/libedhoc/externals/zcbor/include/zcbor_common.h +147 -60
  172. package/external/libedhoc/externals/zcbor/include/zcbor_decode.h +291 -202
  173. package/external/libedhoc/externals/zcbor/include/zcbor_encode.h +100 -156
  174. package/external/libedhoc/externals/zcbor/include/zcbor_print.h +165 -0
  175. package/external/libedhoc/externals/zcbor/samples/hello_world/src/main.c +1 -1
  176. package/external/libedhoc/externals/zcbor/samples/pet/include/pet_decode.h +1 -1
  177. package/external/libedhoc/externals/zcbor/samples/pet/include/pet_encode.h +1 -1
  178. package/external/libedhoc/externals/zcbor/samples/pet/include/pet_types.h +4 -4
  179. package/external/libedhoc/externals/zcbor/samples/pet/src/main.c +4 -4
  180. package/external/libedhoc/externals/zcbor/samples/pet/src/pet_decode.c +15 -24
  181. package/external/libedhoc/externals/zcbor/samples/pet/src/pet_encode.c +14 -23
  182. package/external/libedhoc/externals/zcbor/src/zcbor_common.c +202 -29
  183. package/external/libedhoc/externals/zcbor/src/zcbor_decode.c +633 -173
  184. package/external/libedhoc/externals/zcbor/src/zcbor_encode.c +71 -184
  185. package/external/libedhoc/externals/zcbor/tests/decode/test1_suit_old_formats/src/main.c +152 -153
  186. package/external/libedhoc/externals/zcbor/tests/decode/test2_suit/src/main.c +64 -64
  187. package/external/libedhoc/externals/zcbor/tests/decode/test3_simple/src/main.c +15 -16
  188. package/external/libedhoc/externals/zcbor/tests/decode/test5_corner_cases/src/main.c +228 -84
  189. package/external/libedhoc/externals/zcbor/tests/decode/test7_suit9_simple/src/main.c +9 -9
  190. package/external/libedhoc/externals/zcbor/tests/decode/test8_suit12/src/main.c +0 -1
  191. package/external/libedhoc/externals/zcbor/tests/decode/test9_manifest14/src/main.c +172 -173
  192. package/external/libedhoc/externals/zcbor/tests/encode/test1_suit/src/main.c +73 -73
  193. package/external/libedhoc/externals/zcbor/tests/encode/test2_simple/src/main.c +1 -2
  194. package/external/libedhoc/externals/zcbor/tests/encode/test3_corner_cases/src/main.c +83 -56
  195. package/external/libedhoc/externals/zcbor/tests/encode/test4_senml/src/main.c +15 -16
  196. package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_everything.c +12 -0
  197. package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_manifest12.c +69 -69
  198. package/external/libedhoc/externals/zcbor/tests/unit/test1_unit_tests/src/main.c +448 -55
  199. package/external/libedhoc/externals/zcbor/tests/unit/test3_float16/src/main.c +49 -48
  200. package/external/libedhoc/include/edhoc.h +348 -54
  201. package/external/libedhoc/include/edhoc_common.h +289 -0
  202. package/external/libedhoc/include/edhoc_context.h +60 -35
  203. package/external/libedhoc/include/edhoc_credentials.h +55 -7
  204. package/external/libedhoc/include/edhoc_crypto.h +10 -10
  205. package/external/libedhoc/include/edhoc_ead.h +13 -10
  206. package/external/libedhoc/include/edhoc_macros.h +20 -11
  207. package/external/libedhoc/include/edhoc_values.h +2 -2
  208. package/external/libedhoc/library/edhoc.c +70 -36
  209. package/external/libedhoc/library/edhoc_common.c +1314 -0
  210. package/external/libedhoc/library/edhoc_exporter.c +45 -46
  211. package/external/libedhoc/library/edhoc_message_1.c +107 -72
  212. package/external/libedhoc/library/edhoc_message_2.c +396 -1693
  213. package/external/libedhoc/library/edhoc_message_3.c +465 -1656
  214. package/external/libedhoc/library/edhoc_message_4.c +93 -91
  215. package/external/libedhoc/library/edhoc_message_error.c +41 -41
  216. package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_0.h → cipher_suite_0.h} +131 -134
  217. package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_2.h → cipher_suite_2.h} +139 -140
  218. package/external/libedhoc/tests/include/{edhoc_trace_1/test_vector_1.h → test_vector_rfc9529_chapter_2.h} +786 -738
  219. package/external/libedhoc/tests/include/{edhoc_trace_2/test_vector_2.h → test_vector_rfc9529_chapter_3.h} +14 -10
  220. 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
  221. 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
  222. 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
  223. 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
  224. package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_0.c → cipher_suite_0.c} +445 -447
  225. package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_2.c → cipher_suite_2.c} +600 -600
  226. package/external/libedhoc/tests/src/module_test_api.c +430 -0
  227. package/external/libedhoc/tests/src/module_test_cipher_suite_0.c +395 -0
  228. package/external/libedhoc/tests/src/module_test_cipher_suite_2.c +392 -0
  229. package/external/libedhoc/tests/src/{error_message/test_edhoc_error_message.c → module_test_error_message.c} +94 -69
  230. package/external/libedhoc/tests/src/module_test_main.c +49 -0
  231. package/external/libedhoc/tests/src/{cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.c → module_test_rfc9528_suites_negotiation.c} +224 -227
  232. package/external/libedhoc/tests/src/module_test_rfc9529_chapter_2.c +2681 -0
  233. package/external/libedhoc/tests/src/module_test_rfc9529_chapter_3.c +1635 -0
  234. package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_0.c +1135 -0
  235. package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_2.c +1249 -0
  236. package/external/libedhoc/tests/src/module_test_x5chain_static_dh_keys_suite_2.c +798 -0
  237. package/external/libedhoc/tests/src/module_test_x5t_sign_keys_suite_2.c +956 -0
  238. package/include/EdhocComposeAsyncWorker.h +8 -6
  239. package/include/EdhocCredentialManager.h +16 -11
  240. package/include/EdhocCryptoManager.h +28 -21
  241. package/include/EdhocEadManager.h +3 -6
  242. package/include/{EdhocExportAsyncWorker.h → EdhocExportOscoreAsyncWorker.h} +20 -17
  243. package/include/EdhocKeyExporterAsyncWorker.h +76 -0
  244. package/include/EdhocKeyUpdateAsyncWorker.h +72 -0
  245. package/include/EdhocProcessAsyncWorker.h +14 -10
  246. package/include/LibEDHOC.h +44 -20
  247. package/include/UserContext.h +7 -9
  248. package/include/Utils.h +31 -27
  249. package/package.json +14 -3
  250. package/prebuilds/android-arm/edhoc.armv7.node +0 -0
  251. package/prebuilds/android-arm64/edhoc.armv8.node +0 -0
  252. package/prebuilds/darwin-arm64/edhoc.node +0 -0
  253. package/prebuilds/darwin-x64/edhoc.node +0 -0
  254. package/prebuilds/linux-arm/edhoc.armv6.node +0 -0
  255. package/prebuilds/linux-arm/edhoc.armv7.node +0 -0
  256. package/prebuilds/linux-arm64/edhoc.armv8.node +0 -0
  257. package/prebuilds/linux-x64/edhoc.glibc.node +0 -0
  258. package/prebuilds/linux-x64/edhoc.musl.node +0 -0
  259. package/prebuilds/win32-ia32/edhoc.node +0 -0
  260. package/prebuilds/win32-x64/edhoc.node +0 -0
  261. package/src/EdhocComposeAsyncWorker.cpp +18 -35
  262. package/src/EdhocCredentialManager.cpp +160 -187
  263. package/src/EdhocCryptoManager.cpp +386 -586
  264. package/src/EdhocEadManager.cpp +10 -18
  265. package/src/EdhocExportOscoreAsyncWorker.cpp +77 -0
  266. package/src/EdhocKeyExporterAsyncWorker.cpp +49 -0
  267. package/src/EdhocKeyUpdateAsyncWorker.cpp +41 -0
  268. package/src/EdhocProcessAsyncWorker.cpp +72 -19
  269. package/src/LibEDHOC.cpp +213 -174
  270. package/src/Suites.cpp +39 -72
  271. package/src/Utils.cpp +32 -56
  272. package/test/basic.test.ts +64 -0
  273. package/test/vectors.test.ts +111 -0
  274. package/dist/credentials.d.ts +0 -16
  275. package/dist/credentials.d.ts.map +0 -1
  276. package/dist/credentials.js +0 -84
  277. package/external/libedhoc/externals/zcbor/include/zcbor_debug.h +0 -69
  278. package/external/libedhoc/tests/include/cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.h +0 -37
  279. package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_0.h +0 -48
  280. package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_2.h +0 -48
  281. package/external/libedhoc/tests/include/edhoc_trace_1/authentication_credentials_1.h +0 -60
  282. package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_1.h +0 -208
  283. package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_ead_1.h +0 -59
  284. package/external/libedhoc/tests/include/edhoc_trace_2/authentication_credentials_2.h +0 -60
  285. package/external/libedhoc/tests/include/edhoc_trace_2/test_edhoc_handshake_2.h +0 -199
  286. package/external/libedhoc/tests/include/error_message/test_edhoc_error_message.h +0 -48
  287. package/external/libedhoc/tests/include/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.h +0 -92
  288. package/external/libedhoc/tests/include/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.h +0 -96
  289. package/external/libedhoc/tests/include/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.h +0 -58
  290. package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.h +0 -56
  291. package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.h +0 -57
  292. package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.h +0 -59
  293. package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.h +0 -57
  294. package/external/libedhoc/tests/include/x509_hash_cs_2/authentication_credentials_x5t_cs_2.h +0 -60
  295. package/external/libedhoc/tests/include/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.h +0 -57
  296. package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_0.c +0 -475
  297. package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_2.c +0 -473
  298. package/external/libedhoc/tests/src/edhoc_trace_1/authentication_credentials_1.c +0 -252
  299. package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_1.c +0 -1829
  300. package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_ead_1.c +0 -1247
  301. package/external/libedhoc/tests/src/edhoc_trace_2/authentication_credentials_2.c +0 -170
  302. package/external/libedhoc/tests/src/edhoc_trace_2/test_edhoc_handshake_2.c +0 -1783
  303. package/external/libedhoc/tests/src/tests.c +0 -228
  304. package/external/libedhoc/tests/src/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.c +0 -332
  305. package/external/libedhoc/tests/src/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.c +0 -936
  306. package/external/libedhoc/tests/src/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.c +0 -166
  307. package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.c +0 -587
  308. package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.c +0 -917
  309. package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.c +0 -186
  310. package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.c +0 -743
  311. package/external/libedhoc/tests/src/x509_hash_cs_2/authentication_credentials_x5t_cs_2.c +0 -261
  312. package/external/libedhoc/tests/src/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.c +0 -854
  313. package/src/EdhocExportAsyncWorker.cpp +0 -82
@@ -0,0 +1,1635 @@
1
+ /**
2
+ * \file module_test_rfc9529_chapter_3.c
3
+ * \author Kamil Kielbasa
4
+ * \brief Module tests according to RFC 9529, chapter 3.
5
+ * \version 0.6
6
+ * \date 2024-08-05
7
+ *
8
+ * \copyright Copyright (c) 2024
9
+ *
10
+ */
11
+
12
+ /* Include files ----------------------------------------------------------- */
13
+
14
+ /* Test vector header: */
15
+ #include "test_vector_rfc9529_chapter_3.h"
16
+
17
+ /* Cipher suite 2 header: */
18
+ #include "cipher_suite_2.h"
19
+
20
+ /* Standard library headers: */
21
+ #include <stdio.h>
22
+ #include <stdint.h>
23
+ #include <stddef.h>
24
+ #include <string.h>
25
+ #include <stdbool.h>
26
+
27
+ /* EDHOC header: */
28
+ #define EDHOC_ALLOW_PRIVATE_ACCESS
29
+ #include <edhoc.h>
30
+
31
+ /* PSA crypto header: */
32
+ #include <psa/crypto.h>
33
+
34
+ /* Unity headers: */
35
+ #include <unity.h>
36
+ #include <unity_fixture.h>
37
+
38
+ /* Module defines ---------------------------------------------------------- */
39
+ /* Module types and type definitiones -------------------------------------- */
40
+ /* Module interface variables and constants -------------------------------- */
41
+ /* Static function declarations -------------------------------------------- */
42
+
43
+ /**
44
+ * \brief Mocked EDHOC crypto function ECDH make key pair for initiator.
45
+ */
46
+ static int cipher_suite_2_make_key_pair_init(
47
+ void *user_context, const void *key_id, uint8_t *private_key,
48
+ size_t private_key_size, size_t *private_key_length,
49
+ uint8_t *public_key, size_t public_key_size, size_t *public_key_length);
50
+
51
+ /**
52
+ * \brief Mocked EDHOC crypto function ECDH make key pair for responder.
53
+ */
54
+ static int cipher_suite_2_make_key_pair_resp(
55
+ void *user_context, const void *key_id, uint8_t *private_key,
56
+ size_t private_key_size, size_t *private_key_length,
57
+ uint8_t *public_key, size_t public_key_size, size_t *public_key_length);
58
+
59
+ /**
60
+ * \brief Authentication credentials fetch callback for initiator.
61
+ */
62
+ static int auth_cred_fetch_init(void *user_ctx,
63
+ struct edhoc_auth_creds *auth_cred);
64
+
65
+ /**
66
+ * \brief Authentication credentials fetch callback for initiator.
67
+ *
68
+ * \note It will use already cborised credentials.
69
+ */
70
+ static int auth_cred_fetch_init_any(void *user_ctx,
71
+ struct edhoc_auth_creds *auth_cred);
72
+
73
+ /**
74
+ * \brief Authentication credentials fetch callback for responder.
75
+ */
76
+ static int auth_cred_fetch_resp(void *user_ctx,
77
+ struct edhoc_auth_creds *auth_cred);
78
+
79
+ /**
80
+ * \brief Authentication credentials fetch callback for responder.
81
+ *
82
+ * \note It will use already cborised credentials.
83
+ */
84
+ static int auth_cred_fetch_resp_any(void *user_ctx,
85
+ struct edhoc_auth_creds *auth_cred);
86
+
87
+ /**
88
+ * \brief Authentication credentials verify callback for initiator.
89
+ */
90
+ static int auth_cred_verify_init(void *user_ctx,
91
+ struct edhoc_auth_creds *auth_cred,
92
+ const uint8_t **pub_key_ref,
93
+ size_t *pub_key_len);
94
+
95
+ /**
96
+ * \brief Authentication credentials verify callback for responder.
97
+ */
98
+ static int auth_cred_verify_resp(void *user_ctx,
99
+ struct edhoc_auth_creds *auth_cred,
100
+ const uint8_t **pub_key_ref,
101
+ size_t *pub_key_len);
102
+
103
+ /**
104
+ * \brief Helper function for printing arrays.
105
+ */
106
+ static inline void print_array(void *user_context, const char *name,
107
+ const uint8_t *buffer, size_t buffer_length);
108
+
109
+ /* Static variables and constants ------------------------------------------ */
110
+
111
+ static int ret = EDHOC_ERROR_GENERIC_ERROR;
112
+ static enum edhoc_error_code error_code_recv =
113
+ EDHOC_ERROR_CODE_UNSPECIFIED_ERROR;
114
+
115
+ static struct edhoc_context edhoc_initiator_context = { 0 };
116
+ static struct edhoc_context *init_ctx = &edhoc_initiator_context;
117
+
118
+ static struct edhoc_context edhoc_responder_context = { 0 };
119
+ static struct edhoc_context *resp_ctx = &edhoc_responder_context;
120
+
121
+ static const struct edhoc_cipher_suite edhoc_cipher_suites_init[] = {
122
+ {
123
+ .value = 6,
124
+ .aead_key_length = 16,
125
+ .aead_tag_length = 8,
126
+ .aead_iv_length = 13,
127
+ .hash_length = 32,
128
+ .mac_length = 8,
129
+ .ecc_key_length = 32,
130
+ .ecc_sign_length = 64,
131
+ },
132
+ {
133
+ .value = 2,
134
+ .aead_key_length = 16,
135
+ .aead_tag_length = 8,
136
+ .aead_iv_length = 13,
137
+ .hash_length = 32,
138
+ .mac_length = 8,
139
+ .ecc_key_length = 32,
140
+ .ecc_sign_length = 64,
141
+ },
142
+ };
143
+
144
+ static const struct edhoc_cipher_suite edhoc_cipher_suites_resp[] = {
145
+ {
146
+ .value = 2,
147
+ .aead_key_length = 16,
148
+ .aead_tag_length = 8,
149
+ .aead_iv_length = 13,
150
+ .hash_length = 32,
151
+ .mac_length = 8,
152
+ .ecc_key_length = 32,
153
+ .ecc_sign_length = 64,
154
+ },
155
+ };
156
+
157
+ static const struct edhoc_keys edhoc_keys = {
158
+ .import_key = cipher_suite_2_key_import,
159
+ .destroy_key = cipher_suite_2_key_destroy,
160
+ };
161
+
162
+ static const struct edhoc_crypto edhoc_crypto_mocked_init = {
163
+ .make_key_pair = cipher_suite_2_make_key_pair_init,
164
+ .key_agreement = cipher_suite_2_key_agreement,
165
+ .signature = cipher_suite_2_signature,
166
+ .verify = cipher_suite_2_verify,
167
+ .extract = cipher_suite_2_extract,
168
+ .expand = cipher_suite_2_expand,
169
+ .encrypt = cipher_suite_2_encrypt,
170
+ .decrypt = cipher_suite_2_decrypt,
171
+ .hash = cipher_suite_2_hash,
172
+ };
173
+
174
+ static const struct edhoc_crypto edhoc_crypto_mocked_resp = {
175
+ .make_key_pair = cipher_suite_2_make_key_pair_resp,
176
+ .key_agreement = cipher_suite_2_key_agreement,
177
+ .signature = cipher_suite_2_signature,
178
+ .verify = cipher_suite_2_verify,
179
+ .extract = cipher_suite_2_extract,
180
+ .expand = cipher_suite_2_expand,
181
+ .encrypt = cipher_suite_2_encrypt,
182
+ .decrypt = cipher_suite_2_decrypt,
183
+ .hash = cipher_suite_2_hash,
184
+ };
185
+
186
+ static const struct edhoc_crypto edhoc_crypto = {
187
+ .make_key_pair = cipher_suite_2_make_key_pair,
188
+ .key_agreement = cipher_suite_2_key_agreement,
189
+ .signature = cipher_suite_2_signature,
190
+ .verify = cipher_suite_2_verify,
191
+ .extract = cipher_suite_2_extract,
192
+ .expand = cipher_suite_2_expand,
193
+ .encrypt = cipher_suite_2_encrypt,
194
+ .decrypt = cipher_suite_2_decrypt,
195
+ .hash = cipher_suite_2_hash,
196
+ };
197
+
198
+ static const struct edhoc_credentials edhoc_auth_cred_mocked_init = {
199
+ .fetch = auth_cred_fetch_init,
200
+ .verify = auth_cred_verify_init,
201
+ };
202
+
203
+ static const struct edhoc_credentials edhoc_auth_cred_mocked_init_any = {
204
+ .fetch = auth_cred_fetch_init_any,
205
+ .verify = auth_cred_verify_init,
206
+ };
207
+
208
+ static const struct edhoc_credentials edhoc_auth_cred_mocked_resp = {
209
+ .fetch = auth_cred_fetch_resp,
210
+ .verify = auth_cred_verify_resp,
211
+ };
212
+
213
+ static const struct edhoc_credentials edhoc_auth_cred_mocked_resp_any = {
214
+ .fetch = auth_cred_fetch_resp_any,
215
+ .verify = auth_cred_verify_resp,
216
+ };
217
+
218
+ /* Static function definitions --------------------------------------------- */
219
+
220
+ static int
221
+ cipher_suite_2_make_key_pair_init(void *user_ctx, const void *kid,
222
+ uint8_t *priv_key, size_t priv_key_size,
223
+ size_t *priv_key_len, uint8_t *pub_key,
224
+ size_t pub_key_size, size_t *pub_key_len)
225
+ {
226
+ (void)user_ctx;
227
+
228
+ if (NULL == kid || NULL == priv_key || 0 == priv_key_size ||
229
+ NULL == priv_key_len || NULL == pub_key || 0 == pub_key_size ||
230
+ NULL == pub_key_len)
231
+ return EDHOC_ERROR_INVALID_ARGUMENT;
232
+
233
+ *priv_key_len = ARRAY_SIZE(X);
234
+ memcpy(priv_key, X, ARRAY_SIZE(X));
235
+
236
+ *pub_key_len = ARRAY_SIZE(G_X);
237
+ memcpy(pub_key, G_X, ARRAY_SIZE(G_X));
238
+
239
+ return EDHOC_SUCCESS;
240
+ }
241
+
242
+ static int
243
+ cipher_suite_2_make_key_pair_resp(void *user_ctx, const void *kid,
244
+ uint8_t *priv_key, size_t priv_key_size,
245
+ size_t *priv_key_len, uint8_t *pub_key,
246
+ size_t pub_key_size, size_t *pub_key_len)
247
+ {
248
+ (void)user_ctx;
249
+
250
+ if (NULL == kid || NULL == priv_key || 0 == priv_key_size ||
251
+ NULL == priv_key_len || NULL == pub_key || 0 == pub_key_size ||
252
+ NULL == pub_key_len)
253
+ return EDHOC_ERROR_INVALID_ARGUMENT;
254
+
255
+ *priv_key_len = ARRAY_SIZE(Y);
256
+ memcpy(priv_key, Y, ARRAY_SIZE(Y));
257
+
258
+ *pub_key_len = ARRAY_SIZE(G_X);
259
+ memcpy(pub_key, G_Y, ARRAY_SIZE(G_Y));
260
+
261
+ return EDHOC_SUCCESS;
262
+ }
263
+
264
+ static int auth_cred_fetch_init(void *user_ctx,
265
+ struct edhoc_auth_creds *auth_cred)
266
+ {
267
+ (void)user_ctx;
268
+
269
+ auth_cred->label = EDHOC_COSE_HEADER_KID;
270
+ auth_cred->key_id.cred = CRED_I_cborised;
271
+ auth_cred->key_id.cred_len = ARRAY_SIZE(CRED_I_cborised);
272
+ auth_cred->key_id.cred_is_cbor = true;
273
+ auth_cred->key_id.encode_type = EDHOC_ENCODE_TYPE_BYTE_STRING;
274
+ memcpy(auth_cred->key_id.key_id_bstr, ID_CRED_I_raw_cborised,
275
+ ARRAY_SIZE(ID_CRED_I_raw_cborised));
276
+ auth_cred->key_id.key_id_bstr_length =
277
+ ARRAY_SIZE(ID_CRED_I_raw_cborised);
278
+
279
+ const int ret = cipher_suite_2_key_import(NULL, EDHOC_KT_KEY_AGREEMENT,
280
+ SK_I, ARRAY_SIZE(SK_I),
281
+ auth_cred->priv_key_id);
282
+
283
+ if (EDHOC_SUCCESS != ret)
284
+ return EDHOC_ERROR_CREDENTIALS_FAILURE;
285
+
286
+ return EDHOC_SUCCESS;
287
+ }
288
+
289
+ static int auth_cred_fetch_init_any(void *user_ctx,
290
+ struct edhoc_auth_creds *auth_cred)
291
+ {
292
+ (void)user_ctx;
293
+
294
+ auth_cred->label = EDHOC_COSE_ANY;
295
+ auth_cred->any.id_cred = ID_CRED_I_cborised;
296
+ auth_cred->any.id_cred_len = ARRAY_SIZE(ID_CRED_I_cborised);
297
+ auth_cred->any.is_id_cred_comp_enc = true;
298
+ auth_cred->any.encode_type = EDHOC_ENCODE_TYPE_BYTE_STRING;
299
+ auth_cred->any.id_cred_comp_enc = ID_CRED_I_raw_cborised;
300
+ auth_cred->any.id_cred_comp_enc_length =
301
+ ARRAY_SIZE(ID_CRED_I_raw_cborised);
302
+ auth_cred->any.cred = CRED_I_cborised;
303
+ auth_cred->any.cred_len = ARRAY_SIZE(CRED_I_cborised);
304
+
305
+ const int ret = cipher_suite_2_key_import(NULL, EDHOC_KT_KEY_AGREEMENT,
306
+ SK_I, ARRAY_SIZE(SK_I),
307
+ auth_cred->priv_key_id);
308
+
309
+ if (EDHOC_SUCCESS != ret)
310
+ return EDHOC_ERROR_CREDENTIALS_FAILURE;
311
+
312
+ return EDHOC_SUCCESS;
313
+ }
314
+
315
+ static int auth_cred_fetch_resp(void *user_ctx,
316
+ struct edhoc_auth_creds *auth_cred)
317
+ {
318
+ (void)user_ctx;
319
+
320
+ auth_cred->label = EDHOC_COSE_HEADER_KID;
321
+ auth_cred->key_id.cred = CRED_R_cborised;
322
+ auth_cred->key_id.cred_len = ARRAY_SIZE(CRED_R_cborised);
323
+ auth_cred->key_id.cred_is_cbor = true;
324
+ auth_cred->key_id.encode_type = EDHOC_ENCODE_TYPE_BYTE_STRING;
325
+ memcpy(auth_cred->key_id.key_id_bstr, ID_CRED_R_raw_cborised,
326
+ ARRAY_SIZE(ID_CRED_R_raw_cborised));
327
+ auth_cred->key_id.key_id_bstr_length =
328
+ ARRAY_SIZE(ID_CRED_R_raw_cborised);
329
+
330
+ const int ret = cipher_suite_2_key_import(NULL, EDHOC_KT_KEY_AGREEMENT,
331
+ SK_R, ARRAY_SIZE(SK_R),
332
+ auth_cred->priv_key_id);
333
+
334
+ if (EDHOC_SUCCESS != ret)
335
+ return EDHOC_ERROR_CREDENTIALS_FAILURE;
336
+
337
+ return EDHOC_SUCCESS;
338
+ }
339
+
340
+ static int auth_cred_fetch_resp_any(void *user_ctx,
341
+ struct edhoc_auth_creds *auth_cred)
342
+ {
343
+ (void)user_ctx;
344
+
345
+ auth_cred->label = EDHOC_COSE_ANY;
346
+ auth_cred->any.id_cred = ID_CRED_R_cborised;
347
+ auth_cred->any.id_cred_len = ARRAY_SIZE(ID_CRED_R_cborised);
348
+ auth_cred->any.is_id_cred_comp_enc = true;
349
+ auth_cred->any.encode_type = EDHOC_ENCODE_TYPE_BYTE_STRING;
350
+ auth_cred->any.id_cred_comp_enc = ID_CRED_R_raw_cborised;
351
+ auth_cred->any.id_cred_comp_enc_length =
352
+ ARRAY_SIZE(ID_CRED_R_raw_cborised);
353
+ auth_cred->any.cred = CRED_R_cborised;
354
+ auth_cred->any.cred_len = ARRAY_SIZE(CRED_R_cborised);
355
+
356
+ const int ret = cipher_suite_2_key_import(NULL, EDHOC_KT_KEY_AGREEMENT,
357
+ SK_R, ARRAY_SIZE(SK_R),
358
+ auth_cred->priv_key_id);
359
+
360
+ if (EDHOC_SUCCESS != ret)
361
+ return EDHOC_ERROR_CREDENTIALS_FAILURE;
362
+
363
+ return EDHOC_SUCCESS;
364
+ }
365
+
366
+ static int auth_cred_verify_init(void *user_ctx,
367
+ struct edhoc_auth_creds *auth_cred,
368
+ const uint8_t **pub_key_ref,
369
+ size_t *pub_key_len)
370
+ {
371
+ (void)user_ctx;
372
+
373
+ if (NULL == auth_cred)
374
+ return EDHOC_ERROR_INVALID_ARGUMENT;
375
+
376
+ if (EDHOC_COSE_HEADER_KID != auth_cred->label)
377
+ return EDHOC_ERROR_CREDENTIALS_FAILURE;
378
+
379
+ if (EDHOC_ENCODE_TYPE_INTEGER != auth_cred->key_id.encode_type)
380
+ return EDHOC_ERROR_CREDENTIALS_FAILURE;
381
+
382
+ if (ID_CRED_R_raw != auth_cred->key_id.key_id_int)
383
+ return EDHOC_ERROR_CREDENTIALS_FAILURE;
384
+
385
+ auth_cred->key_id.encode_type = EDHOC_ENCODE_TYPE_BYTE_STRING;
386
+ auth_cred->key_id.key_id_bstr_length =
387
+ ARRAY_SIZE(ID_CRED_R_raw_cborised);
388
+ memcpy(auth_cred->key_id.key_id_bstr, ID_CRED_R_raw_cborised,
389
+ ARRAY_SIZE(ID_CRED_R_raw_cborised));
390
+
391
+ auth_cred->key_id.cred = CRED_R_cborised;
392
+ auth_cred->key_id.cred_len = ARRAY_SIZE(CRED_R_cborised);
393
+ auth_cred->key_id.cred_is_cbor = true;
394
+
395
+ *pub_key_ref = PK_R;
396
+ *pub_key_len = ARRAY_SIZE(PK_R);
397
+
398
+ return EDHOC_SUCCESS;
399
+ }
400
+
401
+ static int auth_cred_verify_resp(void *user_ctx,
402
+ struct edhoc_auth_creds *auth_cred,
403
+ const uint8_t **pub_key_ref,
404
+ size_t *pub_key_len)
405
+ {
406
+ (void)user_ctx;
407
+
408
+ if (NULL == auth_cred)
409
+ return EDHOC_ERROR_INVALID_ARGUMENT;
410
+
411
+ if (EDHOC_COSE_HEADER_KID != auth_cred->label)
412
+ return EDHOC_ERROR_CREDENTIALS_FAILURE;
413
+
414
+ if (EDHOC_ENCODE_TYPE_INTEGER != auth_cred->key_id.encode_type)
415
+ return EDHOC_ERROR_CREDENTIALS_FAILURE;
416
+
417
+ if (ID_CRED_I_raw != auth_cred->key_id.key_id_int)
418
+ return EDHOC_ERROR_CREDENTIALS_FAILURE;
419
+
420
+ auth_cred->key_id.encode_type = EDHOC_ENCODE_TYPE_BYTE_STRING;
421
+ auth_cred->key_id.key_id_bstr_length =
422
+ ARRAY_SIZE(ID_CRED_I_raw_cborised);
423
+ memcpy(auth_cred->key_id.key_id_bstr, ID_CRED_I_raw_cborised,
424
+ ARRAY_SIZE(ID_CRED_I_raw_cborised));
425
+
426
+ auth_cred->key_id.cred = CRED_I_cborised;
427
+ auth_cred->key_id.cred_len = ARRAY_SIZE(CRED_I_cborised);
428
+ auth_cred->key_id.cred_is_cbor = true;
429
+
430
+ *pub_key_ref = PK_I;
431
+ *pub_key_len = ARRAY_SIZE(PK_I);
432
+
433
+ return EDHOC_SUCCESS;
434
+ }
435
+
436
+ static inline void print_array(void *user_context, const char *name,
437
+ const uint8_t *buffer, size_t buffer_length)
438
+ {
439
+ (void)user_context;
440
+
441
+ printf("%s:\tLEN( %zu )\n", name, buffer_length);
442
+
443
+ for (size_t i = 0; i < buffer_length; ++i) {
444
+ if (0 == i % 16 && i > 0) {
445
+ printf("\n");
446
+ }
447
+
448
+ printf("%02x ", buffer[i]);
449
+ }
450
+
451
+ printf("\n\n");
452
+ }
453
+
454
+ /* Module interface function definitions ----------------------------------- */
455
+
456
+ TEST_GROUP(rfc9529_chapter_3);
457
+
458
+ TEST_SETUP(rfc9529_chapter_3)
459
+ {
460
+ ret = psa_crypto_init();
461
+ TEST_ASSERT_EQUAL(PSA_SUCCESS, ret);
462
+
463
+ const enum edhoc_method methods[] = { METHOD };
464
+
465
+ const struct edhoc_connection_id init_cid = {
466
+ .encode_type = EDHOC_CID_TYPE_ONE_BYTE_INTEGER,
467
+ .int_value = (int8_t)C_I[0],
468
+ };
469
+
470
+ const struct edhoc_connection_id resp_cid = {
471
+ .encode_type = EDHOC_CID_TYPE_ONE_BYTE_INTEGER,
472
+ .int_value = (int8_t)C_R[0],
473
+ };
474
+
475
+ ret = edhoc_context_init(init_ctx);
476
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
477
+
478
+ ret = edhoc_set_methods(init_ctx, methods, ARRAY_SIZE(methods));
479
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
480
+
481
+ ret = edhoc_set_cipher_suites(init_ctx, edhoc_cipher_suites_init,
482
+ ARRAY_SIZE(edhoc_cipher_suites_init));
483
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
484
+
485
+ ret = edhoc_set_connection_id(init_ctx, &init_cid);
486
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
487
+
488
+ ret = edhoc_bind_keys(init_ctx, &edhoc_keys);
489
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
490
+
491
+ ret = edhoc_bind_crypto(init_ctx, &edhoc_crypto_mocked_init);
492
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
493
+
494
+ ret = edhoc_bind_credentials(init_ctx, &edhoc_auth_cred_mocked_init);
495
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
496
+
497
+ ret = edhoc_context_init(resp_ctx);
498
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
499
+
500
+ ret = edhoc_set_methods(resp_ctx, methods, ARRAY_SIZE(methods));
501
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
502
+
503
+ ret = edhoc_set_cipher_suites(resp_ctx, edhoc_cipher_suites_resp,
504
+ ARRAY_SIZE(edhoc_cipher_suites_resp));
505
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
506
+
507
+ ret = edhoc_set_connection_id(resp_ctx, &resp_cid);
508
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
509
+
510
+ ret = edhoc_bind_keys(resp_ctx, &edhoc_keys);
511
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
512
+
513
+ ret = edhoc_bind_crypto(resp_ctx, &edhoc_crypto_mocked_resp);
514
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
515
+
516
+ ret = edhoc_bind_credentials(resp_ctx, &edhoc_auth_cred_mocked_resp);
517
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
518
+
519
+ #if defined(TEST_TRACES)
520
+ init_ctx->logger = print_array;
521
+ resp_ctx->logger = print_array;
522
+ #endif
523
+ }
524
+
525
+ TEST_TEAR_DOWN(rfc9529_chapter_3)
526
+ {
527
+ mbedtls_psa_crypto_free();
528
+
529
+ ret = edhoc_context_deinit(init_ctx);
530
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
531
+
532
+ ret = edhoc_context_deinit(resp_ctx);
533
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
534
+ }
535
+
536
+ TEST(rfc9529_chapter_3, message_1_compose)
537
+ {
538
+ size_t msg_1_len = 0;
539
+ uint8_t msg_1[ARRAY_SIZE(message_1)] = { 0 };
540
+
541
+ ret = edhoc_message_1_compose(init_ctx, msg_1, ARRAY_SIZE(msg_1),
542
+ &msg_1_len);
543
+
544
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
545
+ TEST_ASSERT_EQUAL(EDHOC_SM_WAIT_M2, init_ctx->status);
546
+ TEST_ASSERT_EQUAL(false, init_ctx->is_oscore_export_allowed);
547
+
548
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
549
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
550
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
551
+
552
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(message_1), msg_1_len);
553
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(message_1, msg_1, msg_1_len);
554
+
555
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_1, init_ctx->th_state);
556
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(H_message_1), init_ctx->th_len);
557
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(H_message_1, init_ctx->th,
558
+ init_ctx->th_len);
559
+
560
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_INVALID, init_ctx->prk_state);
561
+ TEST_ASSERT_EQUAL(0, init_ctx->prk_len);
562
+
563
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(X), init_ctx->dh_priv_key_len);
564
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(X, init_ctx->dh_priv_key,
565
+ init_ctx->dh_priv_key_len);
566
+ }
567
+
568
+ TEST(rfc9529_chapter_3, message_1_process)
569
+ {
570
+ ret = edhoc_message_1_process(resp_ctx, message_1,
571
+ ARRAY_SIZE(message_1));
572
+
573
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
574
+ TEST_ASSERT_EQUAL(EDHOC_SM_RECEIVED_M1, resp_ctx->status);
575
+ TEST_ASSERT_EQUAL(false, resp_ctx->is_oscore_export_allowed);
576
+
577
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
578
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
579
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
580
+
581
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_1, resp_ctx->th_state);
582
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(H_message_1), resp_ctx->th_len);
583
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(H_message_1, resp_ctx->th,
584
+ resp_ctx->th_len);
585
+
586
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_INVALID, resp_ctx->prk_state);
587
+ TEST_ASSERT_EQUAL(0, resp_ctx->prk_len);
588
+
589
+ TEST_ASSERT_EQUAL(EDHOC_CID_TYPE_ONE_BYTE_INTEGER,
590
+ resp_ctx->peer_cid.encode_type);
591
+ TEST_ASSERT_EQUAL((int8_t)C_I[0], resp_ctx->peer_cid.int_value);
592
+
593
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(G_X), resp_ctx->dh_peer_pub_key_len);
594
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(G_X, resp_ctx->dh_peer_pub_key,
595
+ resp_ctx->dh_peer_pub_key_len);
596
+ }
597
+
598
+ TEST(rfc9529_chapter_3, message_2_compose)
599
+ {
600
+ /* Required injections. */
601
+ resp_ctx->status = EDHOC_SM_RECEIVED_M1;
602
+ resp_ctx->chosen_method = METHOD;
603
+
604
+ resp_ctx->th_state = EDHOC_TH_STATE_1;
605
+ resp_ctx->th_len = ARRAY_SIZE(H_message_1);
606
+ memcpy(resp_ctx->th, H_message_1, sizeof(H_message_1));
607
+
608
+ resp_ctx->dh_peer_pub_key_len = ARRAY_SIZE(G_X);
609
+ memcpy(resp_ctx->dh_peer_pub_key, G_X, ARRAY_SIZE(G_X));
610
+
611
+ resp_ctx->peer_cid.encode_type = EDHOC_CID_TYPE_ONE_BYTE_INTEGER;
612
+ resp_ctx->peer_cid.int_value = (int8_t)C_I[0];
613
+
614
+ size_t msg_2_len = 0;
615
+ uint8_t msg_2[ARRAY_SIZE(message_2)] = { 0 };
616
+
617
+ ret = edhoc_message_2_compose(resp_ctx, msg_2, ARRAY_SIZE(msg_2),
618
+ &msg_2_len);
619
+
620
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
621
+ TEST_ASSERT_EQUAL(EDHOC_SM_WAIT_M3, resp_ctx->status);
622
+ TEST_ASSERT_EQUAL(false, resp_ctx->is_oscore_export_allowed);
623
+
624
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
625
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
626
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
627
+
628
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(message_2), msg_2_len);
629
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(msg_2, message_2, msg_2_len);
630
+
631
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_3, resp_ctx->th_state);
632
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_3), resp_ctx->th_len);
633
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(resp_ctx->th, TH_3, resp_ctx->th_len);
634
+
635
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_3E2M, resp_ctx->prk_state);
636
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_3e2m), resp_ctx->prk_len);
637
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_3e2m, resp_ctx->prk,
638
+ resp_ctx->prk_len);
639
+
640
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(G_XY), resp_ctx->dh_secret_len);
641
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(G_XY, resp_ctx->dh_secret,
642
+ resp_ctx->dh_secret_len);
643
+ }
644
+
645
+ TEST(rfc9529_chapter_3, message_2_compose_any)
646
+ {
647
+ /* Required injections. */
648
+ ret = edhoc_bind_credentials(resp_ctx,
649
+ &edhoc_auth_cred_mocked_resp_any);
650
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
651
+
652
+ resp_ctx->status = EDHOC_SM_RECEIVED_M1;
653
+ resp_ctx->chosen_method = METHOD;
654
+
655
+ resp_ctx->th_state = EDHOC_TH_STATE_1;
656
+ resp_ctx->th_len = ARRAY_SIZE(H_message_1);
657
+ memcpy(resp_ctx->th, H_message_1, sizeof(H_message_1));
658
+
659
+ resp_ctx->dh_peer_pub_key_len = ARRAY_SIZE(G_X);
660
+ memcpy(resp_ctx->dh_peer_pub_key, G_X, ARRAY_SIZE(G_X));
661
+
662
+ resp_ctx->peer_cid.encode_type = EDHOC_CID_TYPE_ONE_BYTE_INTEGER;
663
+ resp_ctx->peer_cid.int_value = (int8_t)C_I[0];
664
+
665
+ size_t msg_2_len = 0;
666
+ uint8_t msg_2[ARRAY_SIZE(message_2)] = { 0 };
667
+
668
+ ret = edhoc_message_2_compose(resp_ctx, msg_2, ARRAY_SIZE(msg_2),
669
+ &msg_2_len);
670
+
671
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
672
+ TEST_ASSERT_EQUAL(EDHOC_SM_WAIT_M3, resp_ctx->status);
673
+ TEST_ASSERT_EQUAL(false, resp_ctx->is_oscore_export_allowed);
674
+
675
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
676
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
677
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
678
+
679
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(message_2), msg_2_len);
680
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(msg_2, message_2, msg_2_len);
681
+
682
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_3, resp_ctx->th_state);
683
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_3), resp_ctx->th_len);
684
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(resp_ctx->th, TH_3, resp_ctx->th_len);
685
+
686
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_3E2M, resp_ctx->prk_state);
687
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_3e2m), resp_ctx->prk_len);
688
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_3e2m, resp_ctx->prk,
689
+ resp_ctx->prk_len);
690
+
691
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(G_XY), resp_ctx->dh_secret_len);
692
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(G_XY, resp_ctx->dh_secret,
693
+ resp_ctx->dh_secret_len);
694
+ }
695
+
696
+ TEST(rfc9529_chapter_3, message_2_process)
697
+ {
698
+ /* Required injections. */
699
+ init_ctx->status = EDHOC_SM_WAIT_M2;
700
+ init_ctx->chosen_method = METHOD;
701
+
702
+ init_ctx->th_state = EDHOC_TH_STATE_1;
703
+ init_ctx->th_len = ARRAY_SIZE(H_message_1);
704
+ memcpy(init_ctx->th, H_message_1, ARRAY_SIZE(H_message_1));
705
+
706
+ init_ctx->dh_priv_key_len = ARRAY_SIZE(X);
707
+ memcpy(init_ctx->dh_priv_key, X, ARRAY_SIZE(X));
708
+
709
+ ret = edhoc_message_2_process(init_ctx, message_2,
710
+ ARRAY_SIZE(message_2));
711
+
712
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
713
+ TEST_ASSERT_EQUAL(EDHOC_SM_VERIFIED_M2, init_ctx->status);
714
+ TEST_ASSERT_EQUAL(false, init_ctx->is_oscore_export_allowed);
715
+
716
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
717
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
718
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
719
+
720
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_3, init_ctx->th_state);
721
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_3), init_ctx->th_len);
722
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_ctx->th, TH_3, init_ctx->th_len);
723
+
724
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_3E2M, init_ctx->prk_state);
725
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_3e2m), init_ctx->prk_len);
726
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_3e2m, init_ctx->prk,
727
+ init_ctx->prk_len);
728
+
729
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(G_XY), init_ctx->dh_secret_len);
730
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_ctx->dh_secret, G_XY,
731
+ sizeof(init_ctx->dh_secret));
732
+
733
+ TEST_ASSERT_EQUAL(EDHOC_CID_TYPE_ONE_BYTE_INTEGER,
734
+ init_ctx->peer_cid.encode_type);
735
+ TEST_ASSERT_EQUAL((int8_t)C_R[0], init_ctx->peer_cid.int_value);
736
+ }
737
+
738
+ TEST(rfc9529_chapter_3, message_3_compose)
739
+ {
740
+ /* Required injections. */
741
+ init_ctx->status = EDHOC_SM_VERIFIED_M2;
742
+ init_ctx->chosen_method = METHOD;
743
+
744
+ init_ctx->th_state = EDHOC_TH_STATE_3;
745
+ init_ctx->th_len = ARRAY_SIZE(TH_3);
746
+ memcpy(init_ctx->th, TH_3, ARRAY_SIZE(TH_3));
747
+
748
+ init_ctx->prk_state = EDHOC_PRK_STATE_3E2M;
749
+ init_ctx->prk_len = ARRAY_SIZE(PRK_3e2m);
750
+ memcpy(init_ctx->prk, PRK_3e2m, ARRAY_SIZE(PRK_3e2m));
751
+
752
+ init_ctx->dh_peer_pub_key_len = ARRAY_SIZE(G_Y);
753
+ memcpy(init_ctx->dh_peer_pub_key, G_Y, ARRAY_SIZE(G_Y));
754
+
755
+ init_ctx->dh_secret_len = ARRAY_SIZE(G_XY);
756
+ memcpy(init_ctx->dh_secret, G_XY, ARRAY_SIZE(G_XY));
757
+
758
+ size_t msg_3_len = 0;
759
+ uint8_t msg_3[ARRAY_SIZE(message_3)] = { 0 };
760
+
761
+ ret = edhoc_message_3_compose(init_ctx, msg_3, ARRAY_SIZE(msg_3),
762
+ &msg_3_len);
763
+
764
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
765
+ TEST_ASSERT_EQUAL(EDHOC_SM_COMPLETED, init_ctx->status);
766
+ TEST_ASSERT_EQUAL(true, init_ctx->is_oscore_export_allowed);
767
+
768
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
769
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
770
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
771
+
772
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(message_3), msg_3_len);
773
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(message_3, msg_3, msg_3_len);
774
+
775
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, init_ctx->th_state);
776
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_4), init_ctx->th_len);
777
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(TH_4, init_ctx->th, init_ctx->th_len);
778
+
779
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, init_ctx->prk_state);
780
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_4e3m), init_ctx->prk_len);
781
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_4e3m, init_ctx->prk,
782
+ init_ctx->prk_len);
783
+ }
784
+
785
+ TEST(rfc9529_chapter_3, message_3_compose_any)
786
+ {
787
+ ret = edhoc_bind_credentials(init_ctx,
788
+ &edhoc_auth_cred_mocked_init_any);
789
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
790
+
791
+ /* Required injections. */
792
+ init_ctx->status = EDHOC_SM_VERIFIED_M2;
793
+ init_ctx->chosen_method = METHOD;
794
+
795
+ init_ctx->th_state = EDHOC_TH_STATE_3;
796
+ init_ctx->th_len = ARRAY_SIZE(TH_3);
797
+ memcpy(init_ctx->th, TH_3, ARRAY_SIZE(TH_3));
798
+
799
+ init_ctx->prk_state = EDHOC_PRK_STATE_3E2M;
800
+ init_ctx->prk_len = ARRAY_SIZE(PRK_3e2m);
801
+ memcpy(init_ctx->prk, PRK_3e2m, ARRAY_SIZE(PRK_3e2m));
802
+
803
+ init_ctx->dh_peer_pub_key_len = ARRAY_SIZE(G_Y);
804
+ memcpy(init_ctx->dh_peer_pub_key, G_Y, ARRAY_SIZE(G_Y));
805
+
806
+ init_ctx->dh_secret_len = ARRAY_SIZE(G_XY);
807
+ memcpy(init_ctx->dh_secret, G_XY, ARRAY_SIZE(G_XY));
808
+
809
+ size_t msg_3_len = 0;
810
+ uint8_t msg_3[ARRAY_SIZE(message_3)] = { 0 };
811
+
812
+ ret = edhoc_message_3_compose(init_ctx, msg_3, ARRAY_SIZE(msg_3),
813
+ &msg_3_len);
814
+
815
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
816
+ TEST_ASSERT_EQUAL(EDHOC_SM_COMPLETED, init_ctx->status);
817
+ TEST_ASSERT_EQUAL(true, init_ctx->is_oscore_export_allowed);
818
+
819
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
820
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
821
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
822
+
823
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(message_3), msg_3_len);
824
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(message_3, msg_3, msg_3_len);
825
+
826
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, init_ctx->th_state);
827
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_4), init_ctx->th_len);
828
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(TH_4, init_ctx->th, init_ctx->th_len);
829
+
830
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, init_ctx->prk_state);
831
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_4e3m), init_ctx->prk_len);
832
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_4e3m, init_ctx->prk,
833
+ init_ctx->prk_len);
834
+ }
835
+
836
+ TEST(rfc9529_chapter_3, message_3_process)
837
+ {
838
+ /* Required injections. */
839
+ resp_ctx->status = EDHOC_SM_WAIT_M3;
840
+ resp_ctx->chosen_method = METHOD;
841
+
842
+ resp_ctx->th_state = EDHOC_TH_STATE_3;
843
+ resp_ctx->th_len = ARRAY_SIZE(TH_3);
844
+ memcpy(resp_ctx->th, TH_3, ARRAY_SIZE(TH_3));
845
+
846
+ resp_ctx->prk_state = EDHOC_PRK_STATE_3E2M;
847
+ resp_ctx->prk_len = ARRAY_SIZE(PRK_3e2m);
848
+ memcpy(resp_ctx->prk, PRK_3e2m, ARRAY_SIZE(PRK_3e2m));
849
+
850
+ resp_ctx->dh_priv_key_len = ARRAY_SIZE(Y);
851
+ memcpy(resp_ctx->dh_priv_key, Y, ARRAY_SIZE(Y));
852
+
853
+ resp_ctx->dh_secret_len = ARRAY_SIZE(G_XY);
854
+ memcpy(resp_ctx->dh_secret, G_XY, ARRAY_SIZE(G_XY));
855
+
856
+ ret = edhoc_message_3_process(resp_ctx, message_3,
857
+ ARRAY_SIZE(message_3));
858
+
859
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
860
+ TEST_ASSERT_EQUAL(EDHOC_SM_COMPLETED, resp_ctx->status);
861
+ TEST_ASSERT_EQUAL(true, resp_ctx->is_oscore_export_allowed);
862
+
863
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
864
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
865
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
866
+
867
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, resp_ctx->th_state);
868
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_4), resp_ctx->th_len);
869
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(TH_4, resp_ctx->th, resp_ctx->th_len);
870
+
871
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, resp_ctx->prk_state);
872
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_4e3m), resp_ctx->prk_len);
873
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_4e3m, resp_ctx->prk,
874
+ resp_ctx->prk_len);
875
+ }
876
+
877
+ TEST(rfc9529_chapter_3, message_4_compose)
878
+ {
879
+ /* Required injections. */
880
+ resp_ctx->status = EDHOC_SM_COMPLETED;
881
+ resp_ctx->is_oscore_export_allowed = true;
882
+
883
+ resp_ctx->th_state = EDHOC_TH_STATE_4;
884
+ resp_ctx->th_len = ARRAY_SIZE(TH_4);
885
+ memcpy(resp_ctx->th, TH_4, ARRAY_SIZE(TH_4));
886
+
887
+ resp_ctx->prk_state = EDHOC_PRK_STATE_4E3M;
888
+ resp_ctx->prk_len = ARRAY_SIZE(PRK_4e3m);
889
+ memcpy(resp_ctx->prk, PRK_4e3m, ARRAY_SIZE(PRK_4e3m));
890
+
891
+ size_t msg_4_len = 0;
892
+ uint8_t msg_4[ARRAY_SIZE(message_4) + 1] = { 0 };
893
+
894
+ ret = edhoc_message_4_compose(resp_ctx, msg_4, ARRAY_SIZE(msg_4),
895
+ &msg_4_len);
896
+
897
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
898
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, resp_ctx->status);
899
+ TEST_ASSERT_EQUAL(true, resp_ctx->is_oscore_export_allowed);
900
+
901
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
902
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
903
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
904
+
905
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(message_4), msg_4_len);
906
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(message_4, msg_4, msg_4_len);
907
+
908
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, resp_ctx->th_state);
909
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_4), resp_ctx->th_len);
910
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(TH_4, resp_ctx->th, resp_ctx->th_len);
911
+
912
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, resp_ctx->prk_state);
913
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_4e3m), resp_ctx->prk_len);
914
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_4e3m, resp_ctx->prk,
915
+ resp_ctx->prk_len);
916
+ }
917
+
918
+ TEST(rfc9529_chapter_3, message_4_process)
919
+ {
920
+ /* Required injections. */
921
+ init_ctx->status = EDHOC_SM_COMPLETED;
922
+ init_ctx->is_oscore_export_allowed = true;
923
+
924
+ init_ctx->th_state = EDHOC_TH_STATE_4;
925
+ init_ctx->th_len = ARRAY_SIZE(TH_4);
926
+ memcpy(init_ctx->th, TH_4, ARRAY_SIZE(TH_4));
927
+
928
+ init_ctx->prk_state = EDHOC_PRK_STATE_4E3M;
929
+ init_ctx->prk_len = ARRAY_SIZE(PRK_4e3m);
930
+ memcpy(init_ctx->prk, PRK_4e3m, ARRAY_SIZE(PRK_4e3m));
931
+
932
+ ret = edhoc_message_4_process(init_ctx, message_4,
933
+ ARRAY_SIZE(message_4));
934
+
935
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
936
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, init_ctx->status);
937
+ TEST_ASSERT_EQUAL(true, init_ctx->is_oscore_export_allowed);
938
+
939
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
940
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
941
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
942
+
943
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, init_ctx->th_state);
944
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_4), init_ctx->th_len);
945
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(TH_4, init_ctx->th, init_ctx->th_len);
946
+
947
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, init_ctx->prk_state);
948
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_4e3m), init_ctx->prk_len);
949
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_4e3m, init_ctx->prk,
950
+ init_ctx->prk_len);
951
+ }
952
+
953
+ TEST(rfc9529_chapter_3, handshake)
954
+ {
955
+ uint8_t buffer[200] = { 0 };
956
+
957
+ memset(buffer, 0, sizeof(buffer));
958
+ size_t msg_1_len = 0;
959
+ uint8_t *msg_1 = buffer;
960
+
961
+ /* EDHOC message 1 compose. */
962
+ ret = edhoc_message_1_compose(init_ctx, msg_1, ARRAY_SIZE(buffer),
963
+ &msg_1_len);
964
+
965
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
966
+ TEST_ASSERT_EQUAL(EDHOC_SM_WAIT_M2, init_ctx->status);
967
+ TEST_ASSERT_EQUAL(false, init_ctx->is_oscore_export_allowed);
968
+
969
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
970
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
971
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
972
+
973
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(message_1), msg_1_len);
974
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(message_1, msg_1, msg_1_len);
975
+
976
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_INVALID, init_ctx->prk_state);
977
+ TEST_ASSERT_EQUAL(0, init_ctx->prk_len);
978
+
979
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_1, init_ctx->th_state);
980
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(H_message_1), init_ctx->th_len);
981
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(H_message_1, init_ctx->th,
982
+ init_ctx->th_len);
983
+
984
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(X), init_ctx->dh_priv_key_len);
985
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(X, init_ctx->dh_priv_key,
986
+ init_ctx->dh_priv_key_len);
987
+
988
+ /* EDHOC message 1 process. */
989
+ ret = edhoc_message_1_process(resp_ctx, msg_1, msg_1_len);
990
+
991
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
992
+ TEST_ASSERT_EQUAL(EDHOC_SM_RECEIVED_M1, resp_ctx->status);
993
+ TEST_ASSERT_EQUAL(false, resp_ctx->is_oscore_export_allowed);
994
+
995
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
996
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
997
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
998
+
999
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_1, resp_ctx->th_state);
1000
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(H_message_1), resp_ctx->th_len);
1001
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(H_message_1, resp_ctx->th,
1002
+ resp_ctx->th_len);
1003
+
1004
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_INVALID, resp_ctx->prk_state);
1005
+ TEST_ASSERT_EQUAL(0, resp_ctx->prk_len);
1006
+
1007
+ TEST_ASSERT_EQUAL(EDHOC_CID_TYPE_ONE_BYTE_INTEGER,
1008
+ resp_ctx->peer_cid.encode_type);
1009
+ TEST_ASSERT_EQUAL((int8_t)C_I[0], resp_ctx->peer_cid.int_value);
1010
+
1011
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(G_X), resp_ctx->dh_peer_pub_key_len);
1012
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(G_X, resp_ctx->dh_peer_pub_key,
1013
+ resp_ctx->dh_peer_pub_key_len);
1014
+
1015
+ memset(buffer, 0, sizeof(buffer));
1016
+ size_t msg_2_len = 0;
1017
+ uint8_t *msg_2 = buffer;
1018
+
1019
+ /* EDHOC message 2 compose. */
1020
+ ret = edhoc_message_2_compose(resp_ctx, msg_2, ARRAY_SIZE(buffer),
1021
+ &msg_2_len);
1022
+
1023
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1024
+ TEST_ASSERT_EQUAL(EDHOC_SM_WAIT_M3, resp_ctx->status);
1025
+ TEST_ASSERT_EQUAL(false, resp_ctx->is_oscore_export_allowed);
1026
+
1027
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
1028
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1029
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1030
+
1031
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(message_2), msg_2_len);
1032
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(message_2, msg_2, msg_2_len);
1033
+
1034
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_3, resp_ctx->th_state);
1035
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_3), resp_ctx->th_len);
1036
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(TH_3, resp_ctx->th, resp_ctx->th_len);
1037
+
1038
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_3E2M, resp_ctx->prk_state);
1039
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_3e2m), resp_ctx->prk_len);
1040
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_3e2m, resp_ctx->prk,
1041
+ resp_ctx->prk_len);
1042
+
1043
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(G_XY), resp_ctx->dh_secret_len);
1044
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(G_XY, resp_ctx->dh_secret,
1045
+ resp_ctx->dh_secret_len);
1046
+
1047
+ /* EDHOC message 2 process. */
1048
+ ret = edhoc_message_2_process(init_ctx, msg_2, msg_2_len);
1049
+
1050
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1051
+ TEST_ASSERT_EQUAL(EDHOC_SM_VERIFIED_M2, init_ctx->status);
1052
+
1053
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
1054
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1055
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1056
+
1057
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_3, init_ctx->th_state);
1058
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_3), init_ctx->th_len);
1059
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(TH_3, init_ctx->th, init_ctx->th_len);
1060
+ TEST_ASSERT_EQUAL(false, init_ctx->is_oscore_export_allowed);
1061
+
1062
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_3E2M, init_ctx->prk_state);
1063
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_3e2m), init_ctx->prk_len);
1064
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_3e2m, init_ctx->prk,
1065
+ init_ctx->prk_len);
1066
+
1067
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(G_XY), init_ctx->dh_secret_len);
1068
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(G_XY, init_ctx->dh_secret,
1069
+ init_ctx->dh_secret_len);
1070
+
1071
+ TEST_ASSERT_EQUAL(EDHOC_CID_TYPE_ONE_BYTE_INTEGER,
1072
+ init_ctx->peer_cid.encode_type);
1073
+ TEST_ASSERT_EQUAL((int8_t)C_R[0], init_ctx->peer_cid.int_value);
1074
+
1075
+ memset(buffer, 0, sizeof(buffer));
1076
+ size_t msg_3_len = 0;
1077
+ uint8_t *msg_3 = buffer;
1078
+
1079
+ /* EDHOC message 3 compose. */
1080
+ ret = edhoc_message_3_compose(init_ctx, msg_3, ARRAY_SIZE(buffer),
1081
+ &msg_3_len);
1082
+
1083
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1084
+ TEST_ASSERT_EQUAL(EDHOC_SM_COMPLETED, init_ctx->status);
1085
+ TEST_ASSERT_EQUAL(true, init_ctx->is_oscore_export_allowed);
1086
+
1087
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
1088
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1089
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1090
+
1091
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(message_3), msg_3_len);
1092
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(message_3, msg_3, msg_3_len);
1093
+
1094
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, init_ctx->th_state);
1095
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_4), init_ctx->th_len);
1096
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(TH_4, init_ctx->th, init_ctx->th_len);
1097
+
1098
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, init_ctx->prk_state);
1099
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_4e3m), init_ctx->prk_len);
1100
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_4e3m, init_ctx->prk,
1101
+ init_ctx->prk_len);
1102
+
1103
+ /* EDHOC message 3 process. */
1104
+ ret = edhoc_message_3_process(resp_ctx, msg_3, msg_3_len);
1105
+
1106
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1107
+ TEST_ASSERT_EQUAL(EDHOC_SM_COMPLETED, resp_ctx->status);
1108
+ TEST_ASSERT_EQUAL(true, resp_ctx->is_oscore_export_allowed);
1109
+
1110
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
1111
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1112
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1113
+
1114
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, resp_ctx->th_state);
1115
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_4), resp_ctx->th_len);
1116
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(TH_4, resp_ctx->th, resp_ctx->th_len);
1117
+
1118
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, resp_ctx->prk_state);
1119
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_4e3m), resp_ctx->prk_len);
1120
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_4e3m, resp_ctx->prk,
1121
+ resp_ctx->prk_len);
1122
+
1123
+ memset(buffer, 0, sizeof(buffer));
1124
+ size_t msg_4_len = 0;
1125
+ uint8_t *msg_4 = buffer;
1126
+
1127
+ /* EDHOC message 4 compose. */
1128
+ ret = edhoc_message_4_compose(resp_ctx, msg_4, ARRAY_SIZE(buffer),
1129
+ &msg_4_len);
1130
+
1131
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1132
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, resp_ctx->status);
1133
+ TEST_ASSERT_EQUAL(true, resp_ctx->is_oscore_export_allowed);
1134
+
1135
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
1136
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1137
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1138
+
1139
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(message_4), msg_4_len);
1140
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(message_4, msg_4, msg_4_len);
1141
+
1142
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, resp_ctx->th_state);
1143
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_4), resp_ctx->th_len);
1144
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(TH_4, resp_ctx->th, resp_ctx->th_len);
1145
+
1146
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, resp_ctx->prk_state);
1147
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_4e3m), resp_ctx->prk_len);
1148
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_4e3m, resp_ctx->prk,
1149
+ resp_ctx->prk_len);
1150
+
1151
+ /* EDHOC message 4 process. */
1152
+ ret = edhoc_message_4_process(init_ctx, msg_4, msg_4_len);
1153
+
1154
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1155
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, init_ctx->status);
1156
+ TEST_ASSERT_EQUAL(true, init_ctx->is_oscore_export_allowed);
1157
+
1158
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
1159
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1160
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1161
+
1162
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, init_ctx->th_state);
1163
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(TH_4), init_ctx->th_len);
1164
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(TH_4, init_ctx->th, init_ctx->th_len);
1165
+
1166
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, init_ctx->prk_state);
1167
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_4e3m), init_ctx->prk_len);
1168
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_4e3m, init_ctx->prk,
1169
+ init_ctx->prk_len);
1170
+
1171
+ /* Derive OSCORE master secret and master salt. */
1172
+ uint8_t init_master_secret[ARRAY_SIZE(OSCORE_Master_Secret)] = { 0 };
1173
+ uint8_t init_master_salt[ARRAY_SIZE(OSCORE_Master_Salt)] = { 0 };
1174
+ size_t init_sender_id_len = 0;
1175
+ uint8_t init_sender_id[ARRAY_SIZE(C_R)] = { 0 };
1176
+ size_t init_recipient_id_len = 0;
1177
+ uint8_t init_recipient_id[ARRAY_SIZE(C_I)] = { 0 };
1178
+
1179
+ ret = edhoc_export_oscore_session(
1180
+ init_ctx, init_master_secret, ARRAY_SIZE(init_master_secret),
1181
+ init_master_salt, ARRAY_SIZE(init_master_salt), init_sender_id,
1182
+ ARRAY_SIZE(init_sender_id), &init_sender_id_len,
1183
+ init_recipient_id, ARRAY_SIZE(init_recipient_id),
1184
+ &init_recipient_id_len);
1185
+
1186
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1187
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, init_ctx->status);
1188
+ TEST_ASSERT_EQUAL(false, init_ctx->is_oscore_export_allowed);
1189
+
1190
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_OUT, init_ctx->prk_state);
1191
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_out), init_ctx->prk_len);
1192
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_out, init_ctx->prk,
1193
+ init_ctx->prk_len);
1194
+
1195
+ /* Derive OSCORE master secret and master salt. */
1196
+ uint8_t resp_master_secret[ARRAY_SIZE(OSCORE_Master_Secret)] = { 0 };
1197
+ uint8_t resp_master_salt[ARRAY_SIZE(OSCORE_Master_Salt)] = { 0 };
1198
+ size_t resp_sender_id_len = 0;
1199
+ uint8_t resp_sender_id[ARRAY_SIZE(C_I)] = { 0 };
1200
+ size_t resp_recipient_id_len = 0;
1201
+ uint8_t resp_recipient_id[ARRAY_SIZE(C_R)] = { 0 };
1202
+
1203
+ ret = edhoc_export_oscore_session(
1204
+ resp_ctx, resp_master_secret, ARRAY_SIZE(resp_master_secret),
1205
+ resp_master_salt, ARRAY_SIZE(resp_master_salt), resp_sender_id,
1206
+ ARRAY_SIZE(resp_sender_id), &resp_sender_id_len,
1207
+ resp_recipient_id, ARRAY_SIZE(resp_recipient_id),
1208
+ &resp_recipient_id_len);
1209
+
1210
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1211
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, resp_ctx->status);
1212
+ TEST_ASSERT_EQUAL(false, resp_ctx->is_oscore_export_allowed);
1213
+
1214
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_OUT, resp_ctx->prk_state);
1215
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(PRK_out), resp_ctx->prk_len);
1216
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(PRK_out, resp_ctx->prk,
1217
+ resp_ctx->prk_len);
1218
+
1219
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_master_secret, resp_master_secret,
1220
+ sizeof(resp_master_secret));
1221
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(OSCORE_Master_Secret, init_master_secret,
1222
+ sizeof(init_master_secret));
1223
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(OSCORE_Master_Secret, resp_master_secret,
1224
+ sizeof(resp_master_secret));
1225
+
1226
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_master_salt, resp_master_salt,
1227
+ sizeof(resp_master_salt));
1228
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(OSCORE_Master_Salt, init_master_salt,
1229
+ sizeof(init_master_salt));
1230
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(OSCORE_Master_Salt, resp_master_salt,
1231
+ sizeof(resp_master_salt));
1232
+
1233
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(C_I), init_recipient_id_len);
1234
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(C_I, init_recipient_id,
1235
+ init_recipient_id_len);
1236
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(C_I), resp_sender_id_len);
1237
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(C_I, resp_sender_id, resp_sender_id_len);
1238
+
1239
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(C_R), init_sender_id_len);
1240
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(C_R, init_sender_id, init_sender_id_len);
1241
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(C_R), resp_recipient_id_len);
1242
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(C_R, resp_recipient_id,
1243
+ resp_recipient_id_len);
1244
+
1245
+ TEST_ASSERT_EQUAL(init_sender_id_len, resp_recipient_id_len);
1246
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_sender_id, resp_recipient_id,
1247
+ init_sender_id_len);
1248
+ TEST_ASSERT_EQUAL(init_recipient_id_len, resp_sender_id_len);
1249
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_recipient_id, resp_sender_id,
1250
+ resp_sender_id_len);
1251
+
1252
+ /* EDHOC key update method. */
1253
+ ret = edhoc_export_key_update(init_ctx, keyUpdate_context,
1254
+ ARRAY_SIZE(keyUpdate_context));
1255
+
1256
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1257
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, init_ctx->status);
1258
+ TEST_ASSERT_EQUAL(true, init_ctx->is_oscore_export_allowed);
1259
+
1260
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_OUT, init_ctx->prk_state);
1261
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(keyUpdate_PRK_out), init_ctx->prk_len);
1262
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(keyUpdate_PRK_out, init_ctx->prk,
1263
+ init_ctx->prk_len);
1264
+
1265
+ /* EDHOC key update method. */
1266
+ ret = edhoc_export_key_update(resp_ctx, keyUpdate_context,
1267
+ ARRAY_SIZE(keyUpdate_context));
1268
+
1269
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1270
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, resp_ctx->status);
1271
+ TEST_ASSERT_EQUAL(true, resp_ctx->is_oscore_export_allowed);
1272
+
1273
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_OUT, resp_ctx->prk_state);
1274
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(keyUpdate_PRK_out), resp_ctx->prk_len);
1275
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(keyUpdate_PRK_out, resp_ctx->prk,
1276
+ resp_ctx->prk_len);
1277
+
1278
+ /* Derive OSCORE master secret and master salt. */
1279
+ memset(init_master_secret, 0, sizeof(init_master_secret));
1280
+ memset(init_master_salt, 0, sizeof(init_master_salt));
1281
+ init_sender_id_len = 0;
1282
+ memset(init_sender_id, 0, sizeof(init_sender_id));
1283
+ init_recipient_id_len = 0;
1284
+ memset(init_recipient_id, 0, sizeof(init_recipient_id));
1285
+
1286
+ ret = edhoc_export_oscore_session(
1287
+ init_ctx, init_master_secret, ARRAY_SIZE(init_master_secret),
1288
+ init_master_salt, ARRAY_SIZE(init_master_salt), init_sender_id,
1289
+ ARRAY_SIZE(init_sender_id), &init_sender_id_len,
1290
+ init_recipient_id, ARRAY_SIZE(init_recipient_id),
1291
+ &init_recipient_id_len);
1292
+
1293
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1294
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, init_ctx->status);
1295
+ TEST_ASSERT_EQUAL(false, init_ctx->is_oscore_export_allowed);
1296
+
1297
+ /* Derive OSCORE master secret and master salt. */
1298
+ memset(resp_master_secret, 0, sizeof(resp_master_secret));
1299
+ memset(resp_master_salt, 0, sizeof(resp_master_salt));
1300
+ resp_sender_id_len = 0;
1301
+ memset(resp_sender_id, 0, sizeof(resp_sender_id));
1302
+ resp_recipient_id_len = 0;
1303
+ memset(resp_recipient_id, 0, sizeof(resp_recipient_id));
1304
+
1305
+ ret = edhoc_export_oscore_session(
1306
+ resp_ctx, resp_master_secret, ARRAY_SIZE(resp_master_secret),
1307
+ resp_master_salt, ARRAY_SIZE(resp_master_salt), resp_sender_id,
1308
+ ARRAY_SIZE(resp_sender_id), &resp_sender_id_len,
1309
+ resp_recipient_id, ARRAY_SIZE(resp_recipient_id),
1310
+ &resp_recipient_id_len);
1311
+
1312
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1313
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, resp_ctx->status);
1314
+ TEST_ASSERT_EQUAL(false, resp_ctx->is_oscore_export_allowed);
1315
+
1316
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_master_secret, resp_master_secret,
1317
+ sizeof(resp_master_secret));
1318
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(keyUpdate_OSCORE_Master_Secret,
1319
+ init_master_secret,
1320
+ sizeof(init_master_secret));
1321
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(keyUpdate_OSCORE_Master_Secret,
1322
+ resp_master_secret,
1323
+ sizeof(resp_master_secret));
1324
+
1325
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_master_salt, resp_master_salt,
1326
+ sizeof(resp_master_salt));
1327
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(keyUpdate_OSCORE_Master_Salt,
1328
+ init_master_salt,
1329
+ sizeof(init_master_salt));
1330
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(keyUpdate_OSCORE_Master_Salt,
1331
+ resp_master_salt,
1332
+ sizeof(resp_master_salt));
1333
+
1334
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(C_I), init_recipient_id_len);
1335
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(C_I, init_recipient_id,
1336
+ init_recipient_id_len);
1337
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(C_I), resp_sender_id_len);
1338
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(C_I, resp_sender_id, resp_sender_id_len);
1339
+
1340
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(C_R), init_sender_id_len);
1341
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(C_R, init_sender_id, init_sender_id_len);
1342
+ TEST_ASSERT_EQUAL(ARRAY_SIZE(C_R), resp_recipient_id_len);
1343
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(C_R, resp_recipient_id,
1344
+ resp_recipient_id_len);
1345
+
1346
+ TEST_ASSERT_EQUAL(init_sender_id_len, resp_recipient_id_len);
1347
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_sender_id, resp_recipient_id,
1348
+ init_sender_id_len);
1349
+ TEST_ASSERT_EQUAL(init_recipient_id_len, resp_sender_id_len);
1350
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_recipient_id, resp_sender_id,
1351
+ resp_sender_id_len);
1352
+ }
1353
+
1354
+ TEST(rfc9529_chapter_3, handshake_real_crypto)
1355
+ {
1356
+ uint8_t buffer[200] = { 0 };
1357
+
1358
+ memset(buffer, 0, sizeof(buffer));
1359
+ size_t msg_1_len = 0;
1360
+ uint8_t *msg_1 = buffer;
1361
+
1362
+ /* EDHOC message 1 compose. */
1363
+ ret = edhoc_message_1_compose(init_ctx, msg_1, ARRAY_SIZE(buffer),
1364
+ &msg_1_len);
1365
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1366
+ TEST_ASSERT_EQUAL(EDHOC_SM_WAIT_M2, init_ctx->status);
1367
+ TEST_ASSERT_EQUAL(false, init_ctx->is_oscore_export_allowed);
1368
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_INVALID, init_ctx->prk_state);
1369
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_1, init_ctx->th_state);
1370
+
1371
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
1372
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1373
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1374
+
1375
+ /* EDHOC message 1 process. */
1376
+ ret = edhoc_message_1_process(resp_ctx, msg_1, msg_1_len);
1377
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1378
+ TEST_ASSERT_EQUAL(EDHOC_SM_RECEIVED_M1, resp_ctx->status);
1379
+ TEST_ASSERT_EQUAL(false, resp_ctx->is_oscore_export_allowed);
1380
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_1, resp_ctx->th_state);
1381
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_INVALID, resp_ctx->prk_state);
1382
+
1383
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
1384
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1385
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1386
+
1387
+ TEST_ASSERT_EQUAL(EDHOC_CID_TYPE_ONE_BYTE_INTEGER,
1388
+ resp_ctx->peer_cid.encode_type);
1389
+ TEST_ASSERT_EQUAL((int8_t)C_I[0], resp_ctx->peer_cid.int_value);
1390
+
1391
+ memset(buffer, 0, sizeof(buffer));
1392
+ size_t msg_2_len = 0;
1393
+ uint8_t *msg_2 = buffer;
1394
+
1395
+ /* EDHOC message 2 compose. */
1396
+ ret = edhoc_message_2_compose(resp_ctx, msg_2, ARRAY_SIZE(buffer),
1397
+ &msg_2_len);
1398
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1399
+ TEST_ASSERT_EQUAL(EDHOC_SM_WAIT_M3, resp_ctx->status);
1400
+ TEST_ASSERT_EQUAL(false, resp_ctx->is_oscore_export_allowed);
1401
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_3, resp_ctx->th_state);
1402
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_3E2M, resp_ctx->prk_state);
1403
+
1404
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
1405
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1406
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1407
+
1408
+ /* EDHOC message 2 process. */
1409
+ ret = edhoc_message_2_process(init_ctx, msg_2, msg_2_len);
1410
+
1411
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1412
+ TEST_ASSERT_EQUAL(EDHOC_SM_VERIFIED_M2, init_ctx->status);
1413
+ TEST_ASSERT_EQUAL(false, init_ctx->is_oscore_export_allowed);
1414
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_3, init_ctx->th_state);
1415
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_3E2M, init_ctx->prk_state);
1416
+
1417
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
1418
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1419
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1420
+
1421
+ TEST_ASSERT_EQUAL(EDHOC_CID_TYPE_ONE_BYTE_INTEGER,
1422
+ init_ctx->peer_cid.encode_type);
1423
+ TEST_ASSERT_EQUAL((int8_t)C_R[0], init_ctx->peer_cid.int_value);
1424
+
1425
+ TEST_ASSERT_EQUAL(edhoc_cipher_suites_init[1].ecc_key_length,
1426
+ init_ctx->dh_secret_len);
1427
+ TEST_ASSERT_EQUAL(edhoc_cipher_suites_resp[0].ecc_key_length,
1428
+ resp_ctx->dh_secret_len);
1429
+ TEST_ASSERT_EQUAL(init_ctx->dh_secret_len, resp_ctx->dh_secret_len);
1430
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(
1431
+ init_ctx->dh_secret, resp_ctx->dh_secret,
1432
+ edhoc_cipher_suites_resp[0].ecc_key_length);
1433
+
1434
+ memset(buffer, 0, sizeof(buffer));
1435
+ size_t msg_3_len = 0;
1436
+ uint8_t *msg_3 = buffer;
1437
+
1438
+ /* EDHOC message 3 compose. */
1439
+ ret = edhoc_message_3_compose(init_ctx, msg_3, ARRAY_SIZE(buffer),
1440
+ &msg_3_len);
1441
+
1442
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1443
+ TEST_ASSERT_EQUAL(EDHOC_SM_COMPLETED, init_ctx->status);
1444
+ TEST_ASSERT_EQUAL(true, init_ctx->is_oscore_export_allowed);
1445
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, init_ctx->th_state);
1446
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, init_ctx->prk_state);
1447
+
1448
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
1449
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1450
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1451
+
1452
+ /* EDHOC message 3 process. */
1453
+ ret = edhoc_message_3_process(resp_ctx, msg_3, msg_3_len);
1454
+
1455
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1456
+ TEST_ASSERT_EQUAL(EDHOC_SM_COMPLETED, resp_ctx->status);
1457
+ TEST_ASSERT_EQUAL(true, resp_ctx->is_oscore_export_allowed);
1458
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, resp_ctx->th_state);
1459
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, resp_ctx->prk_state);
1460
+
1461
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
1462
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1463
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1464
+
1465
+ memset(buffer, 0, sizeof(buffer));
1466
+ size_t msg_4_len = 0;
1467
+ uint8_t *msg_4 = buffer;
1468
+
1469
+ /* EDHOC message 4 compose. */
1470
+ ret = edhoc_message_4_compose(resp_ctx, msg_4, ARRAY_SIZE(buffer),
1471
+ &msg_4_len);
1472
+
1473
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1474
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, resp_ctx->status);
1475
+ TEST_ASSERT_EQUAL(true, resp_ctx->is_oscore_export_allowed);
1476
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, resp_ctx->th_state);
1477
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, resp_ctx->prk_state);
1478
+
1479
+ ret = edhoc_error_get_code(resp_ctx, &error_code_recv);
1480
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1481
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1482
+
1483
+ /* EDHOC message 4 process. */
1484
+ ret = edhoc_message_4_process(init_ctx, msg_4, msg_4_len);
1485
+
1486
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1487
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, init_ctx->status);
1488
+ TEST_ASSERT_EQUAL(true, init_ctx->is_oscore_export_allowed);
1489
+ TEST_ASSERT_EQUAL(EDHOC_TH_STATE_4, init_ctx->th_state);
1490
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_4E3M, init_ctx->prk_state);
1491
+
1492
+ ret = edhoc_error_get_code(init_ctx, &error_code_recv);
1493
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1494
+ TEST_ASSERT_EQUAL(EDHOC_ERROR_CODE_SUCCESS, error_code_recv);
1495
+
1496
+ /* Derive OSCORE master secret and master salt. */
1497
+ uint8_t init_master_secret[ARRAY_SIZE(OSCORE_Master_Secret)] = { 0 };
1498
+ uint8_t init_master_salt[ARRAY_SIZE(OSCORE_Master_Salt)] = { 0 };
1499
+ size_t init_sender_id_len = 0;
1500
+ uint8_t init_sender_id[ARRAY_SIZE(C_R)] = { 0 };
1501
+ size_t init_recipient_id_len = 0;
1502
+ uint8_t init_recipient_id[ARRAY_SIZE(C_I)] = { 0 };
1503
+
1504
+ ret = edhoc_export_oscore_session(
1505
+ init_ctx, init_master_secret, ARRAY_SIZE(init_master_secret),
1506
+ init_master_salt, ARRAY_SIZE(init_master_salt), init_sender_id,
1507
+ ARRAY_SIZE(init_sender_id), &init_sender_id_len,
1508
+ init_recipient_id, ARRAY_SIZE(init_recipient_id),
1509
+ &init_recipient_id_len);
1510
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1511
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, init_ctx->status);
1512
+ TEST_ASSERT_EQUAL(false, init_ctx->is_oscore_export_allowed);
1513
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_OUT, init_ctx->prk_state);
1514
+
1515
+ /* Derive OSCORE master secret and master salt. */
1516
+ uint8_t resp_master_secret[ARRAY_SIZE(OSCORE_Master_Secret)] = { 0 };
1517
+ uint8_t resp_master_salt[ARRAY_SIZE(OSCORE_Master_Salt)] = { 0 };
1518
+ size_t resp_sender_id_len = 0;
1519
+ uint8_t resp_sender_id[ARRAY_SIZE(C_I)] = { 0 };
1520
+ size_t resp_recipient_id_len = 0;
1521
+ uint8_t resp_recipient_id[ARRAY_SIZE(C_R)] = { 0 };
1522
+
1523
+ ret = edhoc_export_oscore_session(
1524
+ resp_ctx, resp_master_secret, ARRAY_SIZE(resp_master_secret),
1525
+ resp_master_salt, ARRAY_SIZE(resp_master_salt), resp_sender_id,
1526
+ ARRAY_SIZE(resp_sender_id), &resp_sender_id_len,
1527
+ resp_recipient_id, ARRAY_SIZE(resp_recipient_id),
1528
+ &resp_recipient_id_len);
1529
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1530
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, resp_ctx->status);
1531
+ TEST_ASSERT_EQUAL(false, resp_ctx->is_oscore_export_allowed);
1532
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_OUT, resp_ctx->prk_state);
1533
+
1534
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_master_secret, resp_master_secret,
1535
+ sizeof(resp_master_secret));
1536
+
1537
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_master_salt, resp_master_salt,
1538
+ sizeof(resp_master_salt));
1539
+
1540
+ TEST_ASSERT_EQUAL(init_sender_id_len, resp_recipient_id_len);
1541
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_sender_id, resp_recipient_id,
1542
+ init_sender_id_len);
1543
+ TEST_ASSERT_EQUAL(init_recipient_id_len, resp_sender_id_len);
1544
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_recipient_id, resp_sender_id,
1545
+ resp_sender_id_len);
1546
+
1547
+ /* EDHOC key update method. */
1548
+ ret = edhoc_export_key_update(init_ctx, keyUpdate_context,
1549
+ ARRAY_SIZE(keyUpdate_context));
1550
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1551
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, init_ctx->status);
1552
+ TEST_ASSERT_EQUAL(true, init_ctx->is_oscore_export_allowed);
1553
+
1554
+ /* EDHOC key update method. */
1555
+ ret = edhoc_export_key_update(resp_ctx, keyUpdate_context,
1556
+ ARRAY_SIZE(keyUpdate_context));
1557
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1558
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, resp_ctx->status);
1559
+ TEST_ASSERT_EQUAL(true, resp_ctx->is_oscore_export_allowed);
1560
+
1561
+ TEST_ASSERT_EQUAL(init_ctx->prk_state, resp_ctx->prk_state);
1562
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_OUT, init_ctx->prk_state);
1563
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_OUT, resp_ctx->prk_state);
1564
+
1565
+ TEST_ASSERT_EQUAL(init_ctx->prk_len, resp_ctx->prk_len);
1566
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_ctx->prk, resp_ctx->prk,
1567
+ resp_ctx->prk_len);
1568
+
1569
+ /* Derive OSCORE master secret and master salt. */
1570
+ memset(init_master_secret, 0, sizeof(init_master_secret));
1571
+ memset(init_master_salt, 0, sizeof(init_master_salt));
1572
+ init_sender_id_len = 0;
1573
+ memset(init_sender_id, 0, sizeof(init_sender_id));
1574
+ init_recipient_id_len = 0;
1575
+ memset(init_recipient_id, 0, sizeof(init_recipient_id));
1576
+
1577
+ ret = edhoc_export_oscore_session(
1578
+ init_ctx, init_master_secret, ARRAY_SIZE(init_master_secret),
1579
+ init_master_salt, ARRAY_SIZE(init_master_salt), init_sender_id,
1580
+ ARRAY_SIZE(init_sender_id), &init_sender_id_len,
1581
+ init_recipient_id, ARRAY_SIZE(init_recipient_id),
1582
+ &init_recipient_id_len);
1583
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1584
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, init_ctx->status);
1585
+ TEST_ASSERT_EQUAL(false, init_ctx->is_oscore_export_allowed);
1586
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_OUT, init_ctx->prk_state);
1587
+
1588
+ /* Derive OSCORE master secret and master salt. */
1589
+ memset(resp_master_secret, 0, sizeof(resp_master_secret));
1590
+ memset(resp_master_salt, 0, sizeof(resp_master_salt));
1591
+ resp_sender_id_len = 0;
1592
+ memset(resp_sender_id, 0, sizeof(resp_sender_id));
1593
+ resp_recipient_id_len = 0;
1594
+ memset(resp_recipient_id, 0, sizeof(resp_recipient_id));
1595
+
1596
+ ret = edhoc_export_oscore_session(
1597
+ resp_ctx, resp_master_secret, ARRAY_SIZE(resp_master_secret),
1598
+ resp_master_salt, ARRAY_SIZE(resp_master_salt), resp_sender_id,
1599
+ ARRAY_SIZE(resp_sender_id), &resp_sender_id_len,
1600
+ resp_recipient_id, ARRAY_SIZE(resp_recipient_id),
1601
+ &resp_recipient_id_len);
1602
+ TEST_ASSERT_EQUAL(EDHOC_SUCCESS, ret);
1603
+ TEST_ASSERT_EQUAL(EDHOC_SM_PERSISTED, resp_ctx->status);
1604
+ TEST_ASSERT_EQUAL(false, resp_ctx->is_oscore_export_allowed);
1605
+ TEST_ASSERT_EQUAL(EDHOC_PRK_STATE_OUT, resp_ctx->prk_state);
1606
+
1607
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_master_secret, resp_master_secret,
1608
+ sizeof(resp_master_secret));
1609
+
1610
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_master_salt, resp_master_salt,
1611
+ sizeof(resp_master_salt));
1612
+
1613
+ TEST_ASSERT_EQUAL(init_sender_id_len, resp_recipient_id_len);
1614
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_sender_id, resp_recipient_id,
1615
+ init_sender_id_len);
1616
+ TEST_ASSERT_EQUAL(init_recipient_id_len, resp_sender_id_len);
1617
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(init_recipient_id, resp_sender_id,
1618
+ resp_sender_id_len);
1619
+ }
1620
+
1621
+ TEST_GROUP_RUNNER(rfc9529_chapter_3)
1622
+ {
1623
+ RUN_TEST_CASE(rfc9529_chapter_3, message_1_compose);
1624
+ RUN_TEST_CASE(rfc9529_chapter_3, message_1_process);
1625
+ RUN_TEST_CASE(rfc9529_chapter_3, message_2_compose);
1626
+ RUN_TEST_CASE(rfc9529_chapter_3, message_2_compose_any);
1627
+ RUN_TEST_CASE(rfc9529_chapter_3, message_2_process);
1628
+ RUN_TEST_CASE(rfc9529_chapter_3, message_3_compose);
1629
+ RUN_TEST_CASE(rfc9529_chapter_3, message_3_compose_any);
1630
+ RUN_TEST_CASE(rfc9529_chapter_3, message_3_process);
1631
+ RUN_TEST_CASE(rfc9529_chapter_3, message_4_compose);
1632
+ RUN_TEST_CASE(rfc9529_chapter_3, message_4_process);
1633
+ RUN_TEST_CASE(rfc9529_chapter_3, handshake);
1634
+ RUN_TEST_CASE(rfc9529_chapter_3, handshake_real_crypto);
1635
+ }