Commit Graph

27 Commits

Author SHA1 Message Date
Abtin Keshavarzian 0fbee98fd5 [crypto] simplify AesCcm public APIs and introduce internal Engine (#13215)
This commit refactors the `AesCcm` class to simplify its public interface,
decoupling the high-level API from the underlying cryptographic execution.

Key improvements:
- Redesigned the API from a series of procedural method calls
  (`Init()`, `Header()`, `Payload()`, `Finalize()`) into a unified,
  stateful model. Callers now pre-configure the operation parameters using
  dedicated setters (`SetKey()`, `SetNonce()`, `SetAuthData()`,
  `SetTagLength()`) and execute the entire cryptographic operation in a
  single step via unified `Process()` methods.
- Introduced a nested `Engine` class to encapsulate the low-level AES-CCM
  mathematical and cryptographic state. The `Engine` provides clean internal
  interfaces for both optimized one-shot (single-part) and multi-part
  operations.
- This architectural separation allows the outer `AesCcm` class to focus on
  parameter validation, high-level buffer management, and complex `Message`
  chunk iterations, while the `Engine` remains focused purely on the
  cryptographic core. This also provides a clean extension point to easily
  route one-shot operations to platform-specific hardware acceleration APIs
  in the future.
- Updated `Mac` and `Mle` modules to use the simplified APIs, reducing
   boilerplate code.
- Retained a static `Perform()` wrapper to support the legacy public
  `otCrypto` API.
- Updated unit tests to validate the new stateful interfaces, including
  robust in-place message chunk processing and separate-buffer
  validations.
2026-06-10 10:24:34 -07:00
Abtin Keshavarzian 9f6921cf04 [core] optimize #include directives in core cpp files (#10717)
This commit removes unnecessary `#include` directives in core `cpp`
files that already include `instance.hpp`. The `instance.hpp` header
itself includes all necessary OT core headers and definitions as they
are contained within an `ot::Instance`.
2024-09-18 12:03:54 -07:00
Abtin Keshavarzian 5ff30d7cef [core] move locator Get<Type> definitions to instance.hpp (#10711)
This commit moves the locator `GetProvider::Get<Type>()` and its
related `Timer` and `Tasklet` methods to `instance.hpp`. With this
change we can remove `locator_getters.hpp` header fully thus
simplifying the code.
2024-09-16 10:10:51 -07:00
Eduardo Montoya 768072a6e0 [crypto] remove legacy otCryptoEcdsaSign (#8514)
This API was introduced for convenience but it's not used anymore.
2022-12-10 08:02:47 -08:00
Jonathan Hui 9c467a23ae [clang-format] apply v14 changes (#8490) 2022-12-07 16:23:20 -08:00
Abtin Keshavarzian 897a29565e [api] harmonize nullptr assert check of pointer input parameters (#8031)
This commit harmonizes and simplifies the code related to asserting
that the OT API pointer parameters are valid and not `nullptr`.
`OPENTHREAD_CONFIG_ASSERT_CHECK_API_POINTER_PARAM_FOR_NULL` is added
which when used performs assert check on all pointer inputs to APIs.
This is either done within `AsCoreType()` when the pointer is
converted to its related core type, or by a direct call to newly added
macro `AssertPointerIsNotNull()`.

Since enabling assert checks on every API parameter can increase code
size, this config is disabled by default and it is recommended to use
it during debugging only.
2022-08-17 20:22:19 -07:00
Abtin Keshavarzian 961fd9ae95 [common] adding AsCoreType() to covert from public to core types (#6993)
This commit adds header file `common/as_core_type.hpp` which adds
helper functions `AsCoreType()` which help convert from a
public C OpenThread type to its corresponding C++ core type (e.g.,
`otIp6Address` to `Ip6::Address`). This commit also adds `MapEnum()`
function to convert between public and core `enum` definitions (e.g.,
`otMacFilterAddressMode` and `Mac::Filter::Mode`). These helper
function act as syntactic sugar helping simplify the implementations
of OT API functions (in `api/{module}_api.cpp` files).
2021-09-16 21:15:37 -07:00
hemanth-silabs cf452fbf7c [crypto] adding ARM PSA (Platform Security Architecture) support (#6862)
- New format for MAC keys, as a union between literal key and keyrefs.
- Modified key_manager to handle both literal keys or keyrefs.
- Modified MAC and sub_mac modules to handle both Literal Keys or keyrefs.
- Updated Crypto Modules to use abstracted APIs.
- New CLIs to handle networkkey and pskc references.
2021-09-08 14:47:46 -07:00
Abtin Keshavarzian f7802d60a1 [style] rename header file to locator_getters.hpp (#6422)
This commit renames the `Locator` header file to follow the same style
used by other core modules (i.e., use underscore between words in a
file name).
2021-04-10 10:16:01 -07:00
Abtin Keshavarzian 743e91361c [style] harmonize feature check and header includes (#6399)
This commit harmonizes how the feature config checks are done within
OT core modules. In header `.hpp` files, any related `#if` config
check is done immediately after the `"openthread-core-config.h"` is
included. This way the rest of definitions are skipped over if the
feature is not being used. In `cpp` source files the `#if` check is
done immediately after including the related header file.
2021-04-05 14:13:24 -07:00
Abtin Keshavarzian 6b48c74787 [crypto] add 'Sha256::Hash' type (#5946)
This commit adds new public type 'otCryptoSha256Hash' and its internal
mirror `Sha256::Hash` type which represent a SHA-256 hash value.
2020-12-12 11:09:54 -08:00
Jonathan Hui 1326d64a64 [style] replace NULL with nullptr (#5109) 2020-06-17 22:44:54 -07:00
Abtin Keshavarzian 19e2d148a1 [ecdsa] use reference (instead of pointer) for output length (#5015) 2020-05-28 22:02:22 -07:00
Abtin Keshavarzian f640774684 [aes-ccm] misc enhancements (#5015)
- add a new enumeration type `Mode` to indicate the encryption vs.
  decryption mode in `AesCcm::Payload()` method.
- add `GetTagLength()` method and simplify `Finalize()`.
- change `AesCcm::Init()` to assert on bad tag length input param
  instead of returning `OT_ERROR_INVALID_ARGS`.
- reorder AesCcm member variable to help with alignments
- use CHAR_BIT
- remove check of tag length from Finalize
- use `memcpy`/`memset` to copy/clear buffers
2020-05-28 22:02:22 -07:00
Abtin Keshavarzian 5903117da5 [debug] adding OT_ASSERT() macro (#4665)
This commit adds a new OpenThread specific `OT_ASSERT()` macro along
with a new config OPENTHREAD_CONFIG_ASSERT_ENABLE option which allows
the assert to be enabled or disabled. This allows a release build to
consider disabling the assert reducing code size. This commit also
adds a new travis (simulation platform) build with asserts disabled.
2020-03-11 17:30:41 -07:00
Jonathan Hui 02da206f39 [config] remaining configure options (#4020) 2019-07-31 14:16:30 -07:00
Abtin Keshavarzian 8f112eeb5a [locator] adding Get<Type> to InstanceLocator (#3714)
This commit changes how the objects in OpenThread access each other.
It adds a template `Get<Type>()` method in `InstanceLocator`. This
method returns a reference to a given `Type` object belonging to the
OpenThread instance (e.g. `Get<MeshForwarder>()` returns a reference
to `MeshForwarder` object on the OpenThread instance). The
`InstanceLocator` is used as base class of all OpenThread classes so
every class can easily access any other object. This commit also
changes how the main instance is retrieved in `InstanceLocator` for
the single-instance case. The method `GetInstance()` directly uses the
raw buffer `gInstanceRaw`. This change helps make the `GetInstance()`
and in turn all `Get<Type>()` methods in-line. This commit also
removes the existing getters across all classes to use the new
`Get<Type>()` model.
2019-04-02 09:07:25 -07:00
Jonathan Hui ac89fd5496 [style] return void where code always returns OT_ERROR_NONE (#3543) 2019-02-01 09:03:24 -08:00
Łukasz Duda 014514442d [crypto] add support for ECDSA signing (#3218) 2018-10-30 12:23:10 -07:00
Jonathan Hui 69d98d4a53 [code-style] apply clang-format 2018-02-09 21:43:42 +00:00
Abtin Keshavarzian 2ea56446a4 [config-header] simplify config header file includes (#2255)
This commit simplifies the config header files includes in
OpenThread core and non-public source files. With this change the
"openthread-core-config.h" becomes the main config header file. This
header file includes all other config ones:
1) The `configure` generated `<openthread/config.h>;
2) The project specific one by `OPENTHREAD_PROJECT_CORE_CONFIG_FILE`;
3) The "openthread-core-default-config.h" defining default settings.

With the change in this commit, all header files include "openthread-
core-config.h" as the first `#include`, and in `.cpp` files, the first
`#include` continues to be the unit's corresponding header file. The
new model ensures that the configuration settings are visible and
consistent in all the source files. This commit also updates the
style guide document accordingly.
2017-10-17 09:46:34 -07:00
Jonathan Hui 702ec2551f [aes-ccm] add lower-bound check for tag length (#2008) 2017-07-18 08:32:36 -07:00
Mike 8dc31d6e27 Enable defines (#1877)
* Add dhcp6 client define, and update openthred-config include scheme

* #1663 - update include to use quotes instead of angle brackets

* #1663 - update file to use underscore instead of dash

* #1663 - remove extra space

* #1663 - update location of new header file and update files to point to it

* #1663 - update location of new header file and update files to point to it

* #1663 update makefile.am to include new header

* update for make pretty changes

* more pretty fixes

* cleanup, and remove automatic mbedtls change

* remove debugging change

* #1663 - Remove extra space, and change include to use angle brackets instead of quotes.

* rename the enable defines file to openthred_config

* #1663 clean up for code review

* #1663 - clean up last nits

* #1663 - missed merge conflicts - file openthread-config.h -> openthread/openthread_config.h
2017-06-12 13:26:44 -07:00
Jonathan Hui fbfd76a990 Apply #include code style. (#1723) 2017-05-05 11:28:29 -07:00
Jonathan Hui 1eabda6a08 Change top-level namespace from 'Thread' to 'ot'. (#1664) 2017-04-27 22:29:05 -07:00
Jonathan Hui b36358a362 Remove extern "C" from cpp files. (#1595) 2017-04-17 10:48:56 -07:00
Jonathan Hui 51c7253e4a Crypto API cleanup. 2017-03-02 10:24:55 -08:00