Commit graph

14686 commits

Author SHA1 Message Date
Gilles Peskine
397b0287b1 Create sample key material for symmetric keys
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-02-17 14:50:16 +01:00
Gilles Peskine
df63968c0c Enumerate sizes to test for each key type
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-02-17 14:50:16 +01:00
Gilles Peskine
0156a15190 Framework for knowledge about key types
New Python module intended to gather knowledge about key types and
cryptographic mechanisms, such as the ability to create test data for
a given key type and the determination of whether an algorithm is
compatible with a key type.

This commit just creates a class for knowledge about key types.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-02-17 14:50:16 +01:00
Gilles Peskine
8c8325bba9 Allow longer method names
Older versions of Pylint (<2.1.0) limited the names of various things
to 30 characters. We allowed up to 35 characters for method name due
to pre-existing identifiers.

Modern versions of Pylint no longer have an upper limit. Let's not be
pickier than Pylint's default configuration.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-02-17 14:50:16 +01:00
Gilles Peskine
0655b4f1e0 Check if the last word is 'MASK', not if it ends with 'MASK'
At the moment it makes no difference, but it could if e.g. a new
algorithm was called 'foomask'.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-02-17 14:50:16 +01:00
Gilles Peskine
13d60eb4fc MacroCollector: default to not including intermediate macros
By default, exclude macros whose numerical value is not a valid member
of the semantic type (e.g. PSA_ALG_xxx_BASE is not itself an
algorithm, only an intermediate value used to construct others). But
do include them with include_intermediate=True, which
generate_psa_constants.py does.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-02-17 14:50:16 +01:00
Gilles Peskine
f8deb759ba Factor out is_internal_name as a separate method
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-02-17 14:50:16 +01:00
Gilles Peskine
e7c445542d Move PSAMacroCollector to a module of its own
This will make it possible to use the class from other scripts.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-02-17 14:50:16 +01:00
Gilles Peskine
7bb85c2640 Separate the parsing and generation parts of MacroCollector
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-02-17 14:50:16 +01:00
Ronald Cron
58fd20c464
Merge pull request #4009 from d3zd3z/pr/psa-symm
PSA configs for symmetric crypto
2021-02-17 13:43:59 +01:00
Bence Szépkúti
7921cceec8 Fix typo in config_psa.h
The correct macro is PSA_WANT_ALG_CFB

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2021-02-17 11:47:40 +01:00
David Brown
9a594e8023 Update psa crypto_config to include recent configs
Update with CHACHA20_POLY1305, CHACHA20.  Add in CTR, which was missing,
and move ALG_XTS to its proper location alphabetically.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:26:57 -07:00
David Brown
1bfe4d7fca Use new PSA builtin defines for CHACHA20
Change the psa_crypto use of the CHACHA20 cipher to also use the new
MBEDTLS_PSA_BUILTIN_KE_TYPE_CHACHA20.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:26:57 -07:00
David Brown
8107e31b74 Fix 2 endif comments
Two endif comments didn't match the ifdef.  Fix these to match.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:26:56 -07:00
David Brown
12ca50307f Change some conditionals of PSA to use BUILTIN
Change a few conditionals in the psa library to be based on the
MBEDTLS_PSA_BUILTIN_KEY_TYPE_DES instead of the WANT macros.  Future
additions of HW acceleration will need to be mindful of these
definitions if any of this code is needed in those instances.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:26:20 -07:00
David Brown
db01e0271f Remove an unnecessary #else and commented line
With the else branch commented out, both lines are unnecessary.  We
could check for the invalid configuration in the future, once tests were
made to exclude this combination.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
be380c1e0f Remove incorrect PSA ECB definition
There is no PSA ALG_ECB, only ALG_ECB_NO_PADDING.  Fix one incorrect
declaration, and remove another that is just redundant.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
8de6437bb6 Cleanup PSA CBC padding defines
Only define MBEDTLS_CIPHER_MODE_CBC if one of the CBC modes is requested
and everything isn't covered by an accelerated version.  This keeps this
from being defined in cases where everything needed would be
accelerated.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
7807bf7404 Use proper conditional for software DES
When converting definitions to use the new PSA defines, one erroneously
was conditionalized on the WANT macro instead of on the BUILTIN macro.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
288a96e169 Fix mistyped endif comment
Correct the endif comment to match the condition used in the ifdef.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
9f3e7749d9 Revert "Change some examples to use new PSA crypto config"
This reverts commit 4192e9a90c210005f6b558ec51c6a694c902b51d.

Converting conditional compliation for PSA configuration will come
later.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
86730a8d50 Add missing MBEDTLS_PSA_BUILTIN for ChaCha20-Poly1305
Add these missing definitions when this configration is chosen.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
fc46818eeb Cleanup PSA ifdefs for CBC block mode
Try to make these definitions clearer given the complexity of the
mapping between the PSA config options and the MBEDTLS ones.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
10cb81c0a0 Add some missing MBEDTLS_PSA_BUILTIN_ definitions
Add a few instances where the builtin macros for these algorithms were
missed.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
f84a0f691e Simplify block cipher PSA definitions
If any of the software block ciphers are selected, define an internal
macro to indicate this.  This eliminates some redundancy that needs to
check for this.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
e1f91f07cd Consolidate PSA ifdefs for block ciphers
Combine some separate ifdef blocks to make it clearer when various
internal values are defined.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
18658a7896 Disable error on CHACHAPOLY misconfiguration
As the test tries this in multiple configurations, an #error here will
fail CI.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
ac4fa07fa3 Add PSA config support for ChaCha20+Poly1305
Add checks for PSA_WANT_ALG_CHACHA20_POLY1305.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
b16727a603 Add PSA config for ChaCha20
Add checks for PSA_WANT_KEY_TYPE_CHACHA20, both with and without
MBEDTLS_PSA_CRYPTO_CONFIG.  This only adds support for the ciphers
itself, presumably as a stream cipher (and not yet AEAD).

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
b781f75401 Define SW crypto algorithms if block modes need it
Even if there is an accelerated version of a (block) key type, enable
the SW implementation if there are block modes that don't have
acceleration.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
5256e69cda Fix typo in psa config comment
Change "are" to "aren't" to avoid making the comment misleading.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
4869dcdc90 Change some examples to use new PSA crypto config
Change a few instances of MBEDTLS_AES_C to PSA_WANT_KEY_TYPE_AES for
PSA-specific demos.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:34 -07:00
David Brown
0baa7b5e98 Change ifdefs in psa_crypto.c to new WANT macros
There are a few instances of MBEDTLS_*_C (specifically for DES) in
psa_crypto.c.  Change to the PSA_WANT_KEY_TYPE_DES macros to reflect the
new PSA crypto config.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:25:32 -07:00
David Brown
4b9ec7a598 Add checks for HW acceleration of ciphers and padding
Add additional ifdef checks in the PSA config to detect when an
algorithm is entirely implemented in hardware.  If there is any
combination of cipher and padding type that is not supported by the HW
acceleration, enable the SW acceleration.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
63ca260827 Change psa_crypto.c ifdefs for cipher modes
Change to use the MBEDTLS_PSA_BUILTIN... macros defined by the cipher
modes.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
12f45f99da Add definitions for builtins for cipher modes
Create these definitions for the various cipher modes.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
da7dbb72ed Add building definitions for non-crypto-config case
Ensure that the builtin definitions are defined when selected by the
traditional configuration options.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
e04acc271c Use PSA definitions in PSA file
This file will always be used with the PSA configurations, so use the
MBEDTLS_PSA_BUILTIN... definitions for the symmetric cyphers.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
bc1731b24e Fix small error in a comment
Use '||' instead of 'or' for consistency.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
db003f31fc Remove unused definition
PSA defines CBC with no padding, and CBC with PKCS7 padding.  The bare
"ALG_CBC" is not defined, so remove this definition.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
78a429b89a Add _BUILTIN defines for new features
For the new features conditionalized on MBEDTLS_PSA_ACCEL_..., define a
correlated MBEDTLS_PSA_BUILTIN_... if it is not defined.  This prevents
check_names from considering these new defines as typos.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
9984427b4a Add feature support for block modes to PSA crypto config
Add support for supported block modes using the PSA crypto config.
These are mapped to Mbed TLS config options as best as possible.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
a9f1d83d31 Add symmetric ciphers and block modes
Update the psa/crypto_config.h with the newly defined PSA_WANT_
definitions for symmetric ciphers and block modes.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
b65a7f7b52 Add feature support for DES for PSA crypto config
Basic support for enabling DES through PSA_WANT_KEY_TYPE_DES.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
686e6e83d3 Add feature support for Camelia for PSA crypto config
Basic support for enabling Camelia through PSA_WANT_KEY_TYPE_CAMELIA.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
ec258cfae1 Add feature support for ARC4 for PSA crypto config
Basic support for enabling ARC4 through PSA_WANT_KEY_TYPE_ARC4.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
David Brown
949330827c Add feature support for AES for PSA crypto config
Basic support for enabling AES through PSA_WANT_KEY_TYPE_AES.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-02-16 13:24:19 -07:00
Dave Rodgman
e31fb03310
Merge pull request #4136 from daverodgman/ssl-opt-gnutls-priority
ssl-opt.sh: add --priority=normal to gnutls-serv
2021-02-16 14:37:51 +00:00
Ronald Cron
010d7c72c3
Merge pull request #3744 from ronald-cron-arm/psa-generate-key-internal
Rework psa_generate_key
2021-02-16 13:29:21 +01:00
Gilles Peskine
bb86d0c61c
Merge pull request #3995 from stevew817/feature/psa_configurable_static_ram_usage
Allow tweaking PSA_KEY_SLOT_COUNT
2021-02-16 12:52:24 +01:00