-
Notifications
You must be signed in to change notification settings - Fork 13
Add AES-CCM from tinydtls #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dce3dd8
AES-CCM: Definitions and dispatch
chrysn 2faf45b
Add glue code for tinyDTLS' AES-CCM-16-64-128
chrysn d2e3d78
Avoid sign-mixed comparison
chrysn cb4264e
fixup! AES-CCM: Definitions and dispatch
chrysn d65716e
void-cast sign/verify arguments in default handler
chrysn 5d1ec74
tests: Don't attempt to sign when no algorithms are available
chrysn aa03794
tinydtls: Add test integration
chrysn cd4c910
Run tests for tinydtls in CI
chrysn f9da347
CI: Insall gcc-dev library available on buster
chrysn c09e819
tinydtls tests: Fixes for Clang
chrysn 522d918
fixup! tinydtls: Add test integration
chrysn 7987061
fixup! Add glue code for tinyDTLS' AES-CCM-16-64-128
chrysn a3ea7be
tinydtls: Update to tinydtls 0.9 API
chrysn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright (C) 2018 Freie Universitat Berlin | ||
| * Copyright (C) 2018 Inria | ||
| * Copyright (C) 2020 Christian Amsüss <christian@amsuess.com> and Ericsson AB | ||
| * | ||
| * This file is subject to the terms and conditions of the GNU Lesser | ||
| * General Public License v2.1. See the file LICENSE in the top level | ||
| * directory for more details. | ||
| */ | ||
|
|
||
| /** | ||
| * @defgroup cose_cryto_tinydtls Crypto glue layer, tinydtls definitions | ||
| * @ingroup cose_crypto | ||
| * | ||
| * Crypto function api for glueing tinydtls' AEAD functions. | ||
| * @{ | ||
| * | ||
| * @file | ||
| * @brief Crypto function api for glueing tinydtls. | ||
| * | ||
| * @author Christian Amsüss <christian@amsuess.com> | ||
| */ | ||
|
|
||
| #ifndef COSE_CRYPTO_TINYDTLS_H | ||
| #define COSE_CRYPTO_TINYDTLS_H | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @name list of provided algorithms | ||
| * | ||
| * @{ | ||
| */ | ||
| #define HAVE_ALGO_AESCCM_16_64_128 /**< AES-CCM mode 128-bit key, 64-bit tag, 13-byte nonce */ | ||
| /** @} */ | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif | ||
|
|
||
| /** @} */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| TINYDTLS_DIR ?= ../tinydtls | ||
| TINYDTLS_CONFIGDIR ?= makefiles/tinydtls_config/ | ||
| CFLAGS += -DCRYPTO_TINYDTLS | ||
| CRYPTOSRC += $(SRC_DIR)/crypt/tinydtls.c | ||
| CFLAGS_CRYPTO += -I$(TINYDTLS_DIR) | ||
| CFLAGS_CRYPTO += -I$(TINYDTLS_CONFIGDIR) | ||
| CRYPTOOBJS += $(TINYDTLS_DIR)/crypto.o | ||
| CRYPTOOBJS += $(TINYDTLS_DIR)/aes/rijndael.o | ||
| CRYPTOOBJS += $(TINYDTLS_DIR)/aes/rijndael_wrap.o | ||
| CRYPTOOBJS += $(TINYDTLS_DIR)/hmac.o | ||
| CRYPTOOBJS += $(TINYDTLS_DIR)/ccm.o | ||
| CRYPTOOBJS += $(TINYDTLS_DIR)/sha2/sha2.o | ||
| CRYPTOOBJS += $(TINYDTLS_DIR)/netq.o | ||
| $(CRYPTOOBJS): CFLAGS += -Wno-gnu-zero-variadic-macro-arguments -Wno-unused-function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Not that we'd need *that* code, but if neither ECC nro PSK is defined, | ||
| // there's empty unions and such (and newer verisons of the library complain | ||
| // more explicitly) | ||
| #define DTLS_PSK | ||
|
|
||
| // Similarly, without a SHA algorithm, there's unused variables and such | ||
|
chrysn marked this conversation as resolved.
Outdated
|
||
| #define WITH_SHA256 | ||
|
|
||
| // Without, we get a #warning that is escalated to an #error by -Werror | ||
|
chrysn marked this conversation as resolved.
Outdated
|
||
| #define HAVE_ASSERT_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Copyright (C) 2020 Christian Amsüss <christian@amsuess.com> and Ericsson AB | ||
| * | ||
| * This file is subject to the terms and conditions of the GNU Lesser | ||
| * General Public License v2.1. See the file LICENSE in the top level | ||
| * directory for more details. | ||
| */ | ||
|
|
||
| /** | ||
| * Glue layer between libcose and tinydtls | ||
| */ | ||
|
|
||
| #include "cose.h" | ||
| #include "cose/crypto.h" | ||
|
|
||
| #include <crypto.h> /* tinydtls', that is */ | ||
|
|
||
| int cose_crypto_aead_encrypt_aesccm(uint8_t *c, | ||
| size_t *clen, | ||
| const uint8_t *msg, | ||
| size_t msglen, | ||
| const uint8_t *aad, | ||
| size_t aadlen, | ||
| const uint8_t *npub, | ||
| const uint8_t *k, | ||
| size_t keysize) | ||
| { | ||
| // Casts: discarding const -- see https://github.com/eclipse/tinydtls/issues/25 | ||
|
chrysn marked this conversation as resolved.
Outdated
|
||
| int ret = dtls_encrypt(msg, msglen, c, (uint8_t*)npub, (uint8_t*)k, keysize, aad, aadlen); | ||
| if (ret >= 0 && (size_t)ret == msglen + COSE_CRYPTO_AEAD_AESCCM_16_64_128_ABYTES) { | ||
| *clen = ret; | ||
| return COSE_OK; | ||
| } else { | ||
| return COSE_ERR_CRYPTO; | ||
| } | ||
| } | ||
|
|
||
| int cose_crypto_aead_decrypt_aesccm(uint8_t *msg, | ||
| size_t *msglen, | ||
| const uint8_t *c, | ||
| size_t clen, | ||
| const uint8_t *aad, | ||
| size_t aadlen, | ||
| const uint8_t *npub, | ||
| const uint8_t *k, | ||
| size_t keysize) | ||
| { | ||
| // Casts: discarding const -- see https://github.com/eclipse/tinydtls/issues/25 | ||
|
chrysn marked this conversation as resolved.
Outdated
|
||
| int ret = dtls_decrypt(c, clen, msg, (uint8_t*)npub, (uint8_t*)k, keysize, aad, aadlen); | ||
| if (ret >= 0 && (size_t)ret == clen - COSE_CRYPTO_AEAD_AESCCM_16_64_128_ABYTES) { | ||
| *msglen = ret; | ||
| return COSE_OK; | ||
| } else { | ||
| return COSE_ERR_CRYPTO; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.