Commit Graph

21 Commits

Author SHA1 Message Date
Achim Kraus
004aba8f7a dtls.c: add cipher_suite_param_t
Use cipher_suite_param_t for cipher-suite specific mac_len and
key_exchange_algorithm. Introduce dtls_cipher_index_t for simplified
cipher-suite parameter lookup. Cleanup old functions.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2023-04-01 10:29:04 +02:00
Achim Kraus
16d3764191 Support zephyr.
Add initial support for zephyr.
Mutex is currently not supported, nor used.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2022-07-08 14:51:05 +02:00
Achim Kraus
6de0b73e53 crypto.c: remove obsolete if.
The second "if handshake" and "if security" are obsolete.

Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
2022-06-23 16:27:06 +02:00
Martine S. Lenders
47289eec09 crypto: remove unnecessary usage of malloc()/dtls_hmac_new()
This has the following optimization potentials which are also applied.

- crypto: only one HMAC context is required
- crypto: integrate last iteration into loop
- hmac: remove dtls_hmac_new()/_free()/_storage_init() as dtls_hmac_new()
  now only is used in tests

Co-Authored-By: Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
Signed-off-by: Martine Lenders <m.lenders@fu-berlin.de>
2022-05-23 10:29:01 +02:00
Jon Shallow
740589ecdc sha256: Better clarification of ec_keys that are in ASN.1 integer format
Rename dtls_ec_key_from_uint32_asn1() to dtls_ec_key_asn1_from_uint32()
to better describe what the function does, as well as add in the ASN.1
header defining it is a ASN.1 positive integer.

Rename dtls_asn1_integer_ec_key() to dtls_asn1_integer_to_ec_key to better
describe what it is actually doing.

Update dtls_add_ecdsa_signature_elem() to handle the updated
dtls_ec_key_asn1_from_uint32() function which now becomes more readable.

Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
2021-06-22 11:57:51 +01:00
Jon Shallow
305ce3cfd1 sha256: Handle r and s values that do not use 32 bytes
In ASN.1, these are positive signed integer values, big-endian encoded.

There is an additional 0x00 prefix if the number has the signed bit set, so
that the number remains positive - hence length can be > 32.

If the leading bits are 0, and there is more than 8 of them, then the leading
0x00 byte(s) can be dropped - hence length can be < 32.

This fix allows the dtls_check_ecdsa_signature_elem() to work correctly.
It also corrects dtls_ec_key_from_uint32_asn1() so that the ASN.1 integer is
built correctly.

Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
2021-06-08 10:40:20 +01:00
Jon Shallow
9ef961d303 crypto.c: Fix L used for nonce sizes
Fix L sizes broken by cbe1810f8c reworking.

Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
2020-06-10 11:58:53 +01:00
Olaf Bergmann
d99fb8c4d9 crypto: Make key and nonce const for dtls_encrypt/decrypt
The key and nonce argument of the (deprecated) functions dtls_encrypt()
and dtls_decrypt() should be const as noted in [1]. This change requires
nonce also to be const in dtls_ccm_params_t.

[1] https://github.com/eclipse/tinydtls/issues/25

Closes #25

Change-Id: Ic6a0801d48eb88c726eee232c8971449c459be29
2020-01-14 10:24:31 +01:00
Olaf Bergmann
cbe1810f8c crypto.[hc]: Support encrypt/decrypt with parameters
The new functions dtls_encrypt_params() and dtls_decrypt_params()
provide an improved interface for AEAD crypto compared to
dtls_encrypt() and dtls_decrypt(). The former take a parameter
set of type dtls_ccm_params_t as first argument, containing the
nonce as well as the M and L values.

The new functions deprecate dtls_encrypt() and dtls_decrypt().

Change-Id: I4bded5da5c433b3192e361d70f23fa563399ae91
2019-10-02 23:06:52 +02:00
Olaf Bergmann
422de29b63 crypto.c: Use dtls_mutex abstraction
Commit c4b7269 adds a new header dtls_mutex.h that wraps mutex
functions for different platforms.

Change-Id: I3a080cc9d4ea5a41e87d776b020c88748d670298
2019-04-05 14:27:00 +02:00
Jon Shallow
02b86be4b4 crypto.c: Remove compiler warning that rand is already defined
Change-Id: I8a8db045028cff5ded03361006266ca2951cd79b
Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
Signed-off-by: Olaf Bergmann <bergmann@tzi.org>
2019-03-21 14:24:09 +01:00
Jon Shallow
5f32f03d95 Move prng functions into separate platform specific functions
This allows for optimizing the prng functions for specific platforms and
makes integration with IoT build environments a lot simpler.

Makefile.in
Makefile.riot
Makefile.tinydtls
crypto.c
dtls.c
dtls_prng.c (new)
dtls_prng.h
platform-specific/Makefile.in
platform-specific/dtls_prng_contiki.c (new)
platform-specific/dtls_prng_espidf.c (new)
platform-specific/dtls_prng_posix.c (new)
platform-specific/dtls_prng_riot.c (new)

Separate out all the old #ifdefs and put the code into the appropriate
places.
Add in the new files to the build process

Change-Id: I955315defd55fd3db2dc58fd88c7aa283e3b9984
Signed-off-by: Jon Shallow <supjps-libcoap@jpshallow.com>
Signed-off-by: Olaf Bergmann <bergmann@tzi.org>
2019-03-21 14:22:30 +01:00
Olaf Bergmann
e2da1e159d RIOT: include memarray.h
Removal of the MEMARRAY code from riot-boards.h now requires
including the memarray header in every file where memarray_init()
and memarray_alloc() are used.

Change-Id: I96f881c540da098174561fac6533d05b127ca00f
2018-04-12 12:02:56 +02:00
Raul Fuentes
b3ca285c3f RIOT: Updating initialization for memarray blocks
Signed-off-by: Raul Fuentes <ra.fuentes.sam@gmail.com>
Signed-off-by: Olaf Bergmann <bergmann@tzi.org>
2018-04-11 12:09:01 +02:00
Olaf Bergmann
9c51d136a1 riot-boards.h: helper macro for memarray initialization
The pre-processor macro MEMARRAY helps declaring and initializing the
buffer and memarray_t structure that are required by memarray_init().

Change-Id: I9f9732881469d7163c5710b3ffd0e46d86a9fb66
2018-03-06 12:25:22 +01:00
Olaf Bergmann
de4b5fd365 RIOT: fix memarray use
This change fixes the invocation of the MEMARRAY macro and
memarray_init() to conform with the proposed API in [1].

[1] https://github.com/RIOT-OS/RIOT/pull/7651/

Change-Id: Iaede8ac17dfef758e54cd4072d58212c64ca4b08
2018-03-02 17:17:44 +01:00
Raul Fuentes
6b432ec4fb crypto.c: Support for RIOT OS (and its static memory allocator)
Change-Id: If538b7b166eb94b1648426ee966d7bc2ec903620
Signed-off-by: Raul Fuentes <ra.fuentes.sam@gmail.com>
2018-02-16 10:27:27 +01:00
Olaf Bergmann
320c04b96d Fixes for compiler warnings
The code has been cleaned up to
1. provide proper prototypes for functions that take no arguments (void),
2. avoid signedness issues, and
3. provide missing cases for switch statements.

Change-Id: I9e84ddb9ef6594c374ad817330a43b22642ebb33
2017-03-01 13:32:14 +01:00
Gaëtan Harter
c9adbab655 tinydtls.h: include dtls_config.h in tinydtls.h
Fixes dtls_config.h not visible in headers
Include dtls_config.h in tinydtls.h and include tinydtls.h in all necessary
headers.

Remaining headers do not use 'ifdef', but they may require it too.

Change-Id: I39c86dffc8bbc8bd7551e74386994f92f49d00ec
Signed-off-by: Gaëtan Harter <gaetan.harter@inria.fr>
2017-02-27 18:05:10 +01:00
Olaf Bergmann
f623c23ba4 renamed debug.[hc] to dtls_debug.[hc] to avoid naming conflicts 2016-03-08 12:47:11 +01:00
Olaf Bergmann
e1388b3980 New initial commit 2016-02-02 18:39:21 +01:00