Commit Graph

2178 Commits

Author SHA1 Message Date
Steffen Jaeckel
e83b9ced72 Re-order struct members
In order to memory-align the used buffers for keys, IVs etc. we re-order
the struct members of ciphers, modes and encauth.

There's no guarantee that this works, but it improves the chances.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:03:01 +00:00
Steffen Jaeckel
61f764d37f Always determine manually whether CC is clang
This is required
1. when cross-compiling
2. to enable/disable the specific compiler warnings

Tested on `bash`, `dash`, `zsh` and FreeBSD `sh`.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:03:01 +00:00
Steffen Jaeckel
4be2367a5a Add option to disable AES-NI at compile time
One can now define `LTC_NO_AES_NI` to disable AES-NI.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:03:01 +00:00
Steffen Jaeckel
2f6282919f Ensure that AES key is always correctly aligned
Aligning a `struct` member via `attribute(align(<n>))` is not guaranteed
to work.
Change the approach to use an opaque buffer and always manually align
the start pointers of the keys.

c.f. https://github.com/DCIT/perl-CryptX/issues/95

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:03:01 +00:00
Steffen Jaeckel
62add4d0ce Add LTC_ALIGN_BUF()
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:03:01 +00:00
Steffen Jaeckel
f39db7cb0a Fix #627
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:03:01 +00:00
Steffen Jaeckel
9a05c23516 Add Testcase for #627
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:03:01 +00:00
Steffen Jaeckel
17372d2e88 Fix build for Windows ARM (UWP)
This fixes #576

Patch inspired by the same, but modified.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:03:01 +00:00
Steffen Jaeckel
29d29ca170 Add support for reading random data from "bcrypt" on Windows
This fixes #577

Patch inspired by the same, but simplified after reading the docs.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:03:01 +00:00
Steffen Jaeckel
c3a9a04c1b Add empty stub for s_der_tests_print_flexi()
So we don't have to `#ifdef` whether it's available or not.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Steffen Jaeckel
d463dab6d6 Fix DER decoding of UTF-8 Strings
Don't read more than the length indicated by the length field.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Steffen Jaeckel
d8d99887b5 Add Testcase that UTF-8 decoding respects the ASN.1 length
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Steffen Jaeckel
fc6be6b4f5 Fix some pkg-config related things
* use a separate `libtomcrypt` folder to install the headers to
* use `INCPATH` and `LIBPATH` when installing `libtomcrypt.pc`
* fix `libtomcrypt.pc` generation for `makefile.unix`

This fixes #625

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Steffen Jaeckel
d4cc1e5214 Port CMake changes from libtommath for Debian packaging
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
ycaibb
6741c76089 fix missing mutex unlock
Fixes a missing mutex unlock on an out of memory error
in ltc_ecc_fp_save_state().

Originates from: 4af447d408

Fixes #571

Comment by sj:
This patch version slightly deviates from the original patch to OP-TEE
since we don't call `XFREE(NULL)` as there exist implementations of
`free()` that don't support it.

Signed-off-by: Ryan Cai <ycaibb@gmail.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Modified-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Ulrich Koschella
03b3538830 Fixed size check in ecc_get_key, Fixes #630 2024-02-18 17:02:10 +00:00
Steffen Jaeckel
71c93ed301 Add Testcase for #630
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Ulrich Koschella
a96794c9c5 Fixed wrong sign in docu of ECC Extended Key Generation, Fixes #628 2024-02-18 17:02:10 +00:00
Steffen Jaeckel
0920839c68 Update makefiles
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Steffen Jaeckel
33a26c4959 introduce separate aes_desc
`aes_desc` and `aes_enc_desc` now do auto-detection of the best suitable
AES implementation for the platform.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Steffen Jaeckel
2a8e6a229c Disable warnings from clang
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Steffen Jaeckel
a0388ef11f add CI testrun with AESNI
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Steffen Jaeckel
13fd324a3b add support for AES-NI instructions
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Steffen Jaeckel
1bfb07a0c8 Add LTC_TMPVAR() macro
Use unique names for variables declared in macros.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:10 +00:00
Steffen Jaeckel
a27da4aa22 cmake: add ccache support
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
a5249753ce Add correct MPI provider defines to pkg-config cflags
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
ce021c898c cmake: Add TomsFastMath support
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
a8081c5641 also update pkg-config file generated by cmake
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
046443467d update Libs part of pkg-config file with configured MPI providers
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
e9c0b9f34c Remove pre-installed libtommath
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
c2e27cf9a5 More error logs on CI failure
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
2156b240e8 Fix missing include paths of ltm and tfm
Default include paths of ltm and tfm have changed.
Try to get include paths from pkg-config.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
410bd9188f Fix Valgrind CI run when building with Clang
Clang creates now DWARFv5 debug infos which isn't supported in old Valgrind
versions. Instruct Clang to create DWARFv4 debug infos, so we can run our
tests in Valgrind.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
bebf2ffd65 Calm scan-build static analyser
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
024392e941 Update base OS version of CI
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
4e8fc0e04e ensure that input-data pointer is non-NULL
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
effe0e8e21 allow input-data pointer to be NULL
If we allow the length to be 0, we should also prepare for the case where
the user doesn't want to provide a valid input-data pointer.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Safae Ouajih
af5fffb8a7 fix pkcs_1_v1_5_decode() when empty message
In case of EME-PKCS1-v1_5 decoding, the encoded message
format is as follow : EM = 0x00 || 0x02 || PS || 0x00 || M.
When using an empty message, the 0x00 octet that separates
the padding string and message is located at the end. Thus,
update the condition to pass the check in case of empty message.

This fixes the following AOSP cts test:
Module: CtsKeystoreTestCases
Test: testEmptyPlaintextEncryptsAndDecrypts
Link: https://android.googlesource.com/platform/cts/+/refs/tags/android-cts-12.0_r6/tests/tests/keystore/src/android/keystore/cts/CipherTest.java

Signed-off-by: Safae Ouajih <souajih@baylibre.com>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
299a9eb565 fix help message of aesgcm demo
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steve Manley
316c07b31c Fix CMakeLists.txt which still used variables from the ltm port
It still used `LTM_{C,LD}_FLAGS` instead of `LTC_{C,LD}_FLAGS`.
2024-02-18 17:02:09 +00:00
Jin
9bb2608aa1 Added gcm_reset() to gcm_memory() to avoid key leakage 2024-02-18 17:02:09 +00:00
Steffen Jaeckel
f37aad3f06 create developer manual in CI
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
c9348e43a0 use correct Build Status badge in README
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
5a33be0dbc improve MPI providers section in documentation
.. also add a checkbox regarding MPI providers to the issue template

This closes #605

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Steffen Jaeckel
97d0f61491 port cmake integration changes from libtommath
... also enable building of tests.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:09 +00:00
Adrian Antonana
d07a66f9b2 introduce initial cmake support 2024-02-18 17:02:09 +00:00
Steffen Jaeckel
82ec3fea54 remove camellia tests if LTC_TEST is not defined
Fixes #600

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:08 +00:00
Steffen Jaeckel
3c05f2b65a fix incompatibility issues with LLP64 data models
This is also a fixup of a921112fe32fce1d5cce386ab09d3edcaa004c51

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:08 +00:00
Steffen Jaeckel
791e5e7098 don't overwrite arguments
There's no need to store those values first somewhere else.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:08 +00:00
Steffen Jaeckel
1c303e8c13 optimize stack arrays
* minimize stack usage
* no need to zero-initialize the arrays

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
2024-02-18 17:02:08 +00:00