Valerio Setti
5f1c8a720f
pkwrite: fix buffer overrun
...
This commit fixes potential buffer overrun in:
- pk_write_rsa_der
- pk_write_ec_pubkey
In both functions, when dealing with opaque keys, there was no
check that the provided buffer was large enough to contain the
key being exported. This commit fixes this problem and it also
adds some testing in test_suite_pkwrite to trigger these checks.
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-14 10:37:00 +02:00
Gilles Peskine
84b9f1b039
mbedtls_ecp_write_key_ext(): migrate internally
...
Stop using mbedtls_ecp_write_key() except to test it.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-02-28 13:19:42 +01:00
Valerio Setti
135ebde273
rsa: rename parse/write functions in order to follow the standard format
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-02-01 17:00:29 +01:00
Valerio Setti
b328c44932
pk/rsa: move RSA parse/write private/public key functions to rsa module
...
These functions are meant to be used internally, so their prototype
declaration is kept into rsa_internal.h.
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-01-23 15:18:57 +01:00
Valerio Setti
429cd50ac8
pkwrite: split pk_write_rsa_der() with a dedicated function for non-opaque RSA key
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-01-23 09:10:22 +01:00
Valerio Setti
7f062a58fb
pkwrite: add newlines when calling mbedtls_pem_write_buffer()
...
New defines, which are shared with the pkparse module, lack the
new line so we manually add it when invoking
mbedtls_pem_write_buffer().
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-12-19 07:48:42 +01:00
Valerio Setti
8aec84f3a7
pkwrite: minor code reshape
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-12-04 16:04:21 +01:00
Valerio Setti
ad6d016b8f
pkwrite: fix return value in pk_get_type_ext()
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-11-30 08:10:36 +01:00
Valerio Setti
bcc004b549
pkwrite: some reshaping for Montgomery keys in mbedtls_pk_write_pubkey_der()
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-11-29 17:16:55 +01:00
Valerio Setti
a4f70fe3fe
pkwrite: simplify management of opaque keys
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-11-29 15:05:47 +01:00
Valerio Setti
f9362b7324
pk_internal: small renaming for mbedtls_pk_get_group_id()
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-11-29 08:42:27 +01:00
Valerio Setti
bcd305913f
pk: move functions to verify RFC8410 group ID to pk_internal
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-11-28 16:27:55 +01:00
Valerio Setti
d5604bacc4
pkwrite: add internal defines for proper key buffer sizes
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-11-28 14:10:43 +01:00
Valerio Setti
605f03cb76
pkwrite: reorganize code
...
This commits just moves code around. The goal is to group together
functions by guards and functionality:
- RSA, EC, Opaque
- internal VS public
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-11-28 12:46:39 +01:00
Valerio Setti
854c737db1
pk: use common header/footer macros for pkwrite and pkparse
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-11-28 08:37:57 +01:00
Dave Rodgman
16799db69a
update headers
...
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-11-02 19:47:20 +00:00
Bence Szépkúti
195411bb17
Merge pull request #8062 from yanrayw/save_stack_usage_pkwrite
...
pkwrite: use heap to save stack usage for writing keys in PEM string
2023-10-13 14:27:13 +00:00
Valerio Setti
db6b4db7a0
Renaming all MBEDTLS_HAVE for curves to MBEDTLS_ECP_HAVE
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-09-25 17:39:41 +02:00
Valerio Setti
6d809cc969
lib/test: use new internal helpers in library's code and tests
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-09-25 17:39:41 +02:00
Dave Rodgman
5a3add2c67
Merge pull request #8234 from kouzhudong/development
...
Fix MSVC error C4703 about possibly uninitialized variable in pkwrite.c
2023-09-25 10:51:46 +01:00
Tom Cosgrove
8d276fbc23
Remove unused variable and unreachable return from mbedtls_pk_write_key_der()
...
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2023-09-21 17:19:36 +01:00
correy
a15b4851d4
Fix MSVC error C4703 about possibly uninitialized variable in pkwrite.c
...
Signed-off-by: correy <112426112@qq.com>
2023-09-21 20:18:52 +08:00
Ronald Cron
b9c7953442
pkwrite: Fix defined but not used warning
...
Fix defined but not used warning when
MBEDTLS_USE_PSA_CRYPTO, MBEDTLS_PK_HAVE_RFC8410_CURVES
and MBEDTLS_PK_HAVE_ECC_KEYS are defined but not
MBEDTLS_PEM_WRITE_C.
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2023-09-07 14:20:49 +02:00
Yanray Wang
044eb16379
pkwrite: zeroize buf containing info of private key
...
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-28 10:35:41 +08:00
Yanray Wang
08d5f46c83
pkwrite.c: call calloc and free properly
...
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-21 15:15:24 +08:00
Yanray Wang
7226df0757
pkwrite.c: add a cleanup label to save code size
...
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-17 15:05:16 +08:00
Yanray Wang
c84086e55c
pkwrite.c: save stack usage for pk_write_key_pem
...
mbedtls_pk_write_key_pem would allocate 5679 bytes in writing a DER
encoded RSA private key. To save stack usage significantly, we use
heap memory instead.
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-11 16:30:37 +08:00
Yanray Wang
45ad306fbf
pkwrite.c: save stack usage for pk_write_pubkey_pem
...
mbedtls_pk_write_pubkey_pem would allocate 2086 bytes in writing a DER
encoded RSA public key. To save stack usage significantly, we use
heap memory instead.
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
2023-08-11 16:30:29 +08:00
Valerio Setti
e1d7c9dabd
pkwrite: fix internal buffer size in pk_write_ec_pubkey()
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-08-10 07:40:18 +02:00
Manuel Pégourié-Gonnard
2be8c63af7
Create psa_util_internal.h
...
Most functions in psa_util.h are going to end up there (except those
that can be static in one file), but I wanted to have separate commits
for file creation and moving code around, so for now the new file's
pretty empty but that will change in the next few commits.
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-07-06 12:42:33 +02:00
Valerio Setti
e1651360c0
pkwrite: fix wrong guard position for pk_get_opaque_ec_family()
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-06-19 19:24:05 +02:00
Valerio Setti
81d75127ba
library: replace occurencies of ECP_LIGHT with PK_HAVE_ECC_KEYS
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-06-19 19:24:05 +02:00
valerio
f9139e55ce
pk: minor code fixes
...
- removing duplicated code
- uninitialized variable usage
Signed-off-by: valerio <valerio.setti@nordicsemi.no>
2023-06-01 11:06:41 +02:00
valerio
c6e6fb320f
pk: fix guard position
...
Signed-off-by: valerio <valerio.setti@nordicsemi.no>
2023-06-01 11:06:41 +02:00
valerio
e279e50a76
pk: optimized/reshape code for writing private key PEM
...
Signed-off-by: valerio <valerio.setti@nordicsemi.no>
2023-06-01 11:06:41 +02:00
valerio
c0bac57ac9
pk: optimized/reshape code for writing private key DER
...
Signed-off-by: valerio <valerio.setti@nordicsemi.no>
2023-06-01 11:06:41 +02:00
valerio
52b675ffc3
pk: extend pk_write_ec_private to support opaque keys
...
Signed-off-by: valerio <valerio.setti@nordicsemi.no>
2023-06-01 11:06:41 +02:00
valerio
ba1fd32eda
pk: optimize/reshape public key writing
...
Signed-off-by: valerio <valerio.setti@nordicsemi.no>
2023-06-01 11:06:41 +02:00
valerio
9ea26173d6
pk: uniformmize public key writing functions
...
Signed-off-by: valerio <valerio.setti@nordicsemi.no>
2023-06-01 11:06:40 +02:00
valerio
b727314133
pk: add internal helpers for opaque keys
...
Signed-off-by: valerio <valerio.setti@nordicsemi.no>
2023-06-01 11:06:40 +02:00
Valerio Setti
449803abff
pkwrite: remove unnecessary code duplication
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-25 09:37:05 +02:00
Valerio Setti
1194ffa82f
pk: minor code fixes/enhancements
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-24 14:00:26 +02:00
Valerio Setti
00e8dd15d2
pk: manage parse and write for the new format
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-23 15:12:07 +02:00
Valerio Setti
e0e6311b64
pk: change location of Montgomery helpers
...
This is to have them available only where they are really required.
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-23 15:12:07 +02:00
Valerio Setti
4064dbbdb2
pk: update pkparse and pkwrite to use the new public key storing solution
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-17 15:33:07 +02:00
Valerio Setti
77a75685ed
pk: align library and tests code to the new internal functions
...
Note = programs are not aligned to this change because:
- the original mbedtls_pk_ec is not ufficially deprecated
- that function is used in tests when ECP_C is defined, so
the legacy version of that function is available in that
case
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-15 11:18:46 +02:00
Valerio Setti
fc90decb74
pkwrite: removing unused/duplicated variables
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-05 12:30:40 +02:00
Valerio Setti
4f387ef277
pk: use better naming for the new key ID field
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-05 10:59:32 +02:00
Valerio Setti
048cd44f77
pk: fix library code for using the new opaque key solution
...
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2023-05-05 10:59:32 +02:00
Jethro Beekman
cb706ea308
Silence bad "maybe unitialized" warning for ec_grp_id
...
Signed-off-by: Jethro Beekman <jethro@fortanix.com>
2023-05-04 13:01:47 +02:00