Commit Graph

8280 Commits

Author SHA1 Message Date
Gilles Peskine
9a05634558 psa_crypto_free: destroy the last slot
The last slot in the array was not freed due to an off-by-one error.

Amend the fill_slots test to serve as a non-regression test for this
issue: without this bug fix, it would cause a memory leak.
2018-09-14 10:02:29 +01:00
Gilles Peskine
cb6adbb750 fixup sizes 2018-09-14 10:02:29 +01:00
Gilles Peskine
996deb18cc Fix buffer overflow in the slot array
Slots are numbered from 1, but the slot array is a C array so it's
numbered from 0.

Add a non-regression test.
2018-09-14 10:02:29 +01:00
Gilles Peskine
4f6c77b0a9 fixup format spec 2018-09-14 10:02:29 +01:00
Gilles Peskine
d14664a79b Move export key sanity check from generate to exercise
Move the code to perform sanity checks on the exported key from
generate_key to exercise_key. This way the sanity checks can be
performed after importing or deriving a key as well.

In addition to checking the exported key if its usage allows it, check
the exported public key if the key is asymmetric.
2018-09-14 10:02:29 +01:00
Gilles Peskine
1be949b846 New macro PSA_KEY_EXPORT_MAX_SIZE
Sufficient buffer size for psa_export_key() and psa_export_public_key().
2018-09-14 10:02:29 +01:00
Gilles Peskine
4e1e9beb56 Define the encoding of ECC and DSA keys 2018-09-14 10:02:29 +01:00
Gilles Peskine
e877974794 Move key type feature test macros to a more logical place 2018-09-14 10:02:29 +01:00
Gilles Peskine
78b3bb670d Change the bitwise encoding of key type categories
There were only 5 categories (now 4). Reduce the category mask from 7
bits to 3.

Combine unformatted, not-necessarily-uniform keys (HMAC, derivation)
with raw data.

Reintroduce a KEY_TYPE_IS_UNSTRUCTURED macro (which used to exist
under the name KEY_TYPE_IS_RAW_DATA macro) for key types that don't
have any structure, including both should-be-uniform keys (such as
block cipher and stream cipher keys) and not-necessarily-uniform
keys (such as HMAC keys and secrets for key derivation).
2018-09-14 10:02:29 +01:00
Gilles Peskine
c32f0304db Fix bad key type constant that worked by accident 2018-09-14 10:02:29 +01:00
Jaeden Amero
4fddbe36fe Merge pull request #120 from ARMmbed/dev/dgreen-arm/conversion-warnings
Fix key parameter in psa_key_derivation to use correct type
2018-09-14 10:02:28 +01:00
Darryl Green
80bed236de Change psa_structs to use unsigned ints
These structs are using bitfields of length one, which can only represent 0 and -1 for signed ints.
Changing these to unsigned int lets them represent 0 and 1, which is what we want.
2018-09-14 10:02:28 +01:00
Jaeden Amero
8be946d602 Merge pull request #118 from ARMmbed/dev/Patater/add-license-header
psa: Add license header to crypto.h
2018-09-14 10:02:28 +01:00
Darryl Green
8800136156 Fix key parameter in psa_key_derivation to use correct type 2018-09-14 10:02:28 +01:00
Darryl Green
9e2d7a09f1 Add ifdefs for psa_internal_export_key function
MBEDTLS_PK_WRITE_C only requires either MBEDTLS_RSA_C or MBEDTLS_ECP_C to be defined.
Added wrappers to handle the cases where only one has been defined.
Moved mbedtls_pk_init to be within the ifdefs, so it's only called if appropriate.
2018-09-14 10:02:28 +01:00
Jaeden Amero
423e20430f Merge pull request #117 from ARMmbed/dev/Patater/generate-visualc
Update generate_visualc_files.pl for PSA
2018-09-14 10:02:28 +01:00
Jaeden Amero
cab5494b12 psa: Add license header to crypto.h 2018-09-14 10:02:28 +01:00
Darryl Green
10ccc641ac Add missing dependencies on MBEDTLS_ECDSA_C 2018-09-14 10:02:28 +01:00
Darryl Green
8f8aa8f931 Add ifdef for MBEDTLS_ECP_C around ecc_group_to_psa functions
These are unused if MBEDTLS_ECP_C isn't defined.
2018-09-14 10:02:28 +01:00
Darryl Green
efb52d53bf Add missing dependency on MBEDTLS_PKCS1_V15 2018-09-14 10:02:28 +01:00
Darryl Green
5cc689a821 Add handling for (sometimes) unused parameters 2018-09-14 10:02:28 +01:00
Darryl Green
77b33b2926 Add missing dependencies on MBEDTLS_SHA256_C 2018-09-14 10:02:28 +01:00
Darryl Green
9c862253cc Add handling for zero-length buffers in tests
The buffer can be NULL if the length is zero, so we only check it's not NULL if the length is nonzero
2018-09-14 10:02:28 +01:00
Darryl Green
13a61f705e Add psa header files to yotta build 2018-09-14 10:02:28 +01:00
Darryl Green
1692363b3e Add visualc files generated by generate_visualc_files.pl 2018-09-14 10:02:25 +01:00
Jaeden Amero
b5c740707f Merge pull request #116 from ARMmbed/psa-doc-fix_doxygen_for_alpha1
Fix doxygen warnings
2018-09-12 16:50:07 +03:00
Darryl Green
588e8cb940 Add psa headers to generate_visualc_files.pl 2018-09-12 16:50:07 +03:00
Jaeden Amero
cfc1957408 Merge pull request #110 from ARMmbed/psa-readme
README file for Mbed Crypto
2018-09-12 16:50:07 +03:00
Gilles Peskine
edd768775f Fix doxygen warnings
* Broken link #PSA_ALG_SHA_256
* Duplicate group name "generators"
* Missing documentation in psa_generate_key_extra_rsa due to bad magic
  comment marker
2018-09-12 16:50:07 +03:00
Jaeden Amero
0d7a4f91c5 Merge pull request #99 from ARMmbed/dev/Patater/exporter
exporter: Prepare a potentially releasable distribution tarball of Mbed Crypto
2018-09-12 16:50:07 +03:00
Gilles Peskine
ff01a8d947 Merge pull request #107 from ARMmbed/psa-derive_hkdf-sample
Sample app with key derivation
2018-09-12 16:50:07 +03:00
Jaeden Amero
2fba767b77 Merge pull request #104 from ARMmbed/psa-crypto-examples
Crypto examples
2018-09-12 16:50:07 +03:00
Jaeden Amero
65731b8e08 gitignore: Ignore Mbed Crypto exported files 2018-09-12 16:50:07 +03:00
Gilles Peskine
9f900a8b25 Merge pull request #105 from ARMmbed/psa-derive_hkdf
PSA key derivation: simple-ish interface, HKDF
2018-09-12 16:50:07 +03:00
Gilles Peskine
f0fa436b65 New sample program key_ladder_demo
Demo of a key derivation ladder.

Sample run in key_ladder_demo.sh.
2018-09-12 16:50:07 +03:00
Jaeden Amero
22e232ec04 Merge pull request #109 from ARMmbed/IAR-feature-psa
Ensure release testing job passes IAR tests
2018-09-12 16:50:07 +03:00
itayzafrir
18ac331e15 psa: programs: Add cipher example fallback main
When dependencies are missing, print an error message from the example
about missing dependencies at run-time.
2018-09-12 16:50:07 +03:00
Jaeden Amero
80e317af15 all.sh: Test the Mbed Crypto exporter
Ensure that the exporter creates a "crypto" folder where "make test"
runs and passes. Ensure that cleanup also runs without error.
2018-09-12 16:50:07 +03:00
Gilles Peskine
08542d8037 Fix psa_generator_import_key for DES
In psa_generator_import_key, if generating a DES or 3DES key, set the
parity bits.

Add tests for deriving a DES key. Also test deriving an AES key while
I'm at it.
2018-09-12 16:50:07 +03:00
itayzafrir
44b09d2a67 psa: programs: Add cipher AES CTR multipart 2018-09-12 16:50:07 +03:00
Jaeden Amero
debb2c0d12 crypto: Add an Mbed Crypto exporter script
Create a tarball-based ditribution of the Mbed Crypto source code using the
code from Mbed TLS. Only export the files needed by Mbed Crypto to
implement the PSA Crypto API. Rename "mbedtls_*" and "MBEDTLS_*" symbols to
"mbedcrypto_*" and "MBEDCRYPTO_*".

The exported distribution can stand alone, without any Mbed TLS repository
needing to be present. "make test" will continue to work as before and will
run only the PSA Crypto test suite.
2018-09-12 16:50:07 +03:00
Gilles Peskine
9fb0e01177 Fix nonstandard whitespace 2018-09-12 16:50:07 +03:00
itayzafrir
a2d0804b33 psa: programs: Add cipher AES CBC PKCS7 multipart 2018-09-12 16:50:07 +03:00
Jaeden Amero
1ff639d37c crypto: Add a Makefile 2018-09-12 16:50:07 +03:00
itayzafrir
10366708d6 psa: programs: Add cipher AES CBC no padding 2018-09-12 16:50:07 +03:00
Jaeden Amero
5a6ade8ab6 crypto/programs: Add a Makefile 2018-09-12 16:50:07 +03:00
itayzafrir
a3ff8a6ed5 psa: programs: Add cipher example
Add `programs/psa/crypto_examples.c`. Update relevant Makefiles,
CMakeLists.txt, and .gitignore files.
2018-09-12 16:50:07 +03:00
Jaeden Amero
1efc5fe6c5 crypto/tests: Add a Makefile 2018-09-12 16:50:07 +03:00
Jaeden Amero
50a058c9f3 crypto/library: Add a Makefile 2018-09-12 16:50:07 +03:00
Gilles Peskine
d54931c7c4 HKDF: be more robust if we reach the maximum ouptut length
In psa_generator_hkdf_read, return BAD_STATE if we're trying to
construct more output than the algorithm allows. This can't happen
through the API due to the capacity limit, but it could potentially
happen in an internal call.

Also add a test case that verifies that we can set up HKDF with its
maximum capacity and read up to the maximum capacity.
2018-09-12 16:50:05 +03:00