Hi
I found this email on ARM MBED support forum.
Could you help to resolve our issue?
On the PSoC6 device we are using mbedtls_rsa_gen_key function with a good hardware TRNG passed FIPS 140-2 verification.
This function verifies generated random pair and requests new pair if they don't follow FIPS 186-4 criteria.
The number of verification loops is between 1 and 6 in worst case.
Is it expected behavior?
The arithmetic of one loop takes a lots of time.
How can we improve the random number to have always pass FIPS 186-4 in a one loop?
Thanks
Nazar
This message and any attachments may contain confidential information from Cypress or its subsidiaries. If it has been received in error, please advise the sender and immediately delete this message.
Like with timing (see my message in the timing thread,
https://lists.trustedfirmware.org/pipermail/mbed-tls/2020-April/000061.html),
I have a strong preference for the library to be usable out of the box
on typical platforms. This means keeping the abstractions that are
currently in the net_sockets module, or similar abstractions. This
doesn't mean keeping the net_sockets module as such: these abstractions
could be in platform.c.
I lean towards having a platform_posix.c and a platform_windows.c (and
any other we care to support), chosen at build time based on the target
platform. I'm not sure exactly what they should look like. In
particular, if you have an embedded platform that's sort of POSIX-like,
but doesn't have every POSIX feature and does a few differently, should
you be able to customize platform_posix.c through #defines, or should
you copy it and modify it to suit your platform?
--
Gilles Peskine
Mbed TLS developer
On 20/04/2020 11:52, Manuel Pegourie-Gonnard via mbed-tls wrote:
> Hi all,
>
> [ Context: https://developer.trustedfirmware.org/w/mbed-tls/tech-plans-3.0/ ]
>
> Currently the SSL/TLS library includes a module called net_sockets.c (formerly
> net.c), enabled by default in config.h (but disabled by config.py baremetal),
> that contains some networking functions based on POSIX or Windows sockets,
> including functions suitable for use as I/O callbacks with our SSL/TLS
> modules.
>
> Those functions are used only in example/testing programs, but nowhere in the
> library itself.
>
> In Mbed TLS 3.0, as part of our effort to clean up and minimize our API,
> we're considering removing (parts of) this module from the library, and
> moving its parts to a variety of other places, such as example programs (or
> a library/file shared by them, like the current query_config mechanism).
>
> Reasons for removing this module from the library include:
>
> - overall the module is less portable and perhaps of lesser quality than the
> rest of the library
> - it's currently entirely untested on Windows (despite being very
> platform-specific)
> - there are often confusions about whether the module is meant to be a
> general-purpose networking library, or just provide basic support for our
> example and test, as well a simple prototypes
> - it's not our core area of expertise, let's do one thing and to it well
>
> Reasons for keeping (parts of) it in the library include:
>
> - having mbedtls_net_recv{,_timeout}() and mbedtls_net_send() available right
> in the library makes it easier to test and develop prototype
> - this module is listed as a component in our high-level design document [2],
> so perhaps removing it from the library can be seen as a bigger change?
>
> [2]: https://tls.mbed.org/high-level-design
>
> What do you think? Should we remove the entire module from the library, keep
> it all, or just keep some parts? In that case, which parts and where?
>
> Regards,
> Manuel.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
I have a strong preference for the library, the tests and companion
programs to build out of the box on officially supported platforms. On
platforms that don't work out of the box, users should be able to drop
in platform support code in the form of #defines or extra modules to
link with.
Ok, we don't have an official list of supported platforms. But inasmuch
as we do have officially supported platforms, they include Linux and
other modern Unix-like or POSIX environments, Windows, and Mbed OS. Mbed
OS is a special case because Mbed TLS is part of the build tree there,
so the mbedtls tree doesn't have to contain Mbed OS support.
This doesn't mean that the library should have a timing module. I think
the timing wrappers that the library needs, i.e.
mbedtls_timing_{get,set}_delay, should be in platform.c.
For platform features that are only used by test or sample programs, I
think we should have a separate platform support file, and separate
#defines so that you can build the library even if you can't build all
the programs. For example, it makes sense to build DTLS support without
having the timing functions used by the benchmark program.
--
Gilles Peskine
Mbed TLS developer
On 21/04/2020 10:46, Manuel Pegourie-Gonnard via mbed-tls wrote:
> Hi all,
>
> So personally I'm quite strongly inclined to remove timing.c from the
> library, and move most of its content elsewhere, with one possible
> exception:
>
>> - mbedtls_timing_set_delay() and mbedtls_timing_get_delay() are an example
>> implementation (only for Unix and Windows) of timer callbacks for DTLS, only
>> used in programs/ssl/*.c
> Since timer callbacks are a hard requirement for using DTLS, and it seems
> quite desirable to be able to support DTLS out of the box at least on
> some platforms, I was thinking this pair of function (and the associated
> context type) could be kept in the library, in a new module that would
> be called something like ssl_dtls_timer.c.
>
> This would be somewhat similar to ssl_cookies.c, ssl_tickets.c and
> ssl_cache.c: they all provide implementations of callbacks that can be
> used with the main SSL/(D)TLS module, but users are obviously free to
> compile them out and use their own implementation if the one we provide
> does not meet their needs.
>
> As it happens, all three of these support modules work best if
> MBEDTLS_HAVE_TIME is defined, but can work without it.
>
> For the new ssl_dtls_timer.c I'm suggesting, the situation would be
> different: the module could have a hard dependency on MBEDTLS_HAVE_TIME,
> but work better on selected platforms (say, C11, POSIX and
> Windows) where we know how to access sub-second timing information. (Or
> alternatively, have a hard dependency on C11-or-Posix-or-Windows.)
>
> For the record, mbedtls_ssl_conf_handshake_timeout() accepts timeout
> values in milliseconds, but recommended values for use over the general
> internet start at 1 second:
> https://tools.ietf.org/html/rfc6347#section-4.2.4.1
> So it might make sense to provide this module even when we only have
> second resolution - we'd just have to work out how the timer function
> would behave when passed sub-second values. (My first thought it
> rounding up to the next second would be quite OK.)
>
> What do you'all think? Personnally, I don't have a strong opinion
> between the three following options, though I have a slight preference
> for the first one:
>
> 1. Provide ssl_dtls_timer.c in the library with hard dep on HAVE_TIME
> and enhanced features with C11/Posix/Windows.
> 2. Provide ssl_dtls_timer.c in the library with hard dep on
> C11/Posix/Windows.
> 3. Move it all out of the library and let the thing live somewhere under
> programs/ as it's only used by example/testing programs.
>
> Note though that we could also choose to go with option 3 for Mbed TLS
> 3.0, see how it goes, and later switch to option 2 or 1 if we want, as
> adding modules can be done at any time. (In the same vein, we could
> start with 2 and switch to 1 at any time as well.)
>
> Regards,
> Manuel.
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Hi,
> [I'm assuming didn't mean to reply on the list and not just to me, so I'm replying on the list.]
Oops, I misinterpreted the information presented by my mail client, you did reply on the list. Sorry for the noise (and for breaking the thread by not replying to the correct email.)
Manuel.
Hi again,
In the first email of the thread I tried giving a fair exposition of the
question, now I'm going to give my personal opinion.
Similarly to what I suggested for timing.c, I'm inclined to remove net.c as
such, move most of its content (net_bind(), net_accept(), etc.) out of the
library (most probably into a new file in programs/ssl, shared by SSL
examples), and keep in the library only the 3 functions that can be used as
SSL callbacks (and a supporting context type), but in a new module named for
example ssl_io_sockets.c.
This would also be similar to the other SSL modules that provide a
reference/example implementation of some SSL callback but can easily be
disabled (or jsut disregarded) in favour of a custom implementation for custom
needs or unsupported platforms. Just like the current net_sockets.c, this new
reduced module would probably only be supported on platforms with sockets,
which is Posix platforms and Windows.
Advantages include:
- Reduce the amount of code and API surface in the library. Things like
binding and accepting are hardly related to (D)TLS so there is little
justification for having them in the library. Also, things in the library are
bound by API stability rules which are sometimes a constraint.
- It would clarify that we're not providing a general-purpose socket
abstraction, as general socket management would be out of the library, and
only the bits for plugging a socket into our SSL layer would be in the
library.
- (By the way currently net_sockets.h includes ssl.h, so it's already quite
specific to our SSL module rather than generic, but moving the remaining
bits of it into the SSL namespace would make that clearer.)
- User would still have the convenience (on supported platforms) of
ready-for-use callbacks. If you have an application already working with
sockets without TLS, then we provide all the bits needed to turn that into an
application using TLS on top of those sockets.
I think that would be a good compromise between convenience for users, and
reduced surface for the library.
Regards,
Manuel.
Hi,
I support this.
Could certs.c live in `tests/data_files`? We should also make sure this file is automatically synced with the actual CRT and key files in that directory. There is a script which does that, but IIRC it's not called as part of the CI, which lead to certs.c and the data files get out of sync multiple times in the past.
Best
Hanno
________________________________
From: mbed-tls <mbed-tls-bounces(a)lists.trustedfirmware.org> on behalf of Manuel Pegourie-Gonnard via mbed-tls <mbed-tls(a)lists.trustedfirmware.org>
Sent: Monday, April 20, 2020 10:49 AM
To: mbed-tls(a)lists.trustedfirmware.org <mbed-tls(a)lists.trustedfirmware.org>
Cc: nd <nd(a)arm.com>
Subject: [mbed-tls] 3.0 plans - move certs.c out of the library
Hi all,
In this new installment of "let's discuss ideas for Mbed TLS 3.0" [1]:
should we move certs.c out of the library?
[1]: https://developer.trustedfirmware.org/w/mbed-tls/tech-plans-3.0/
Currently the X.509 library includes test certificates and keys, which are
enabled by default in config.h - `MBEDTLS_CERTS_C`.
These are used in the following places:
- in library/x509.c in mbedtls_x509_self_test()
- in tests/suites/test_suite_ssl.function
- in programs/fuzz and programs/ssl
In Mbed TLS 3.0, as part of our effort to clean up and minimize our API, we'd
like to remove certs.h and the certificates it contains from the library
(except perhaps one static cert for mbedtls_x509_self_test()). Tests and
example programs that need built-in certificates could still get them using
any mechanism, included a file certs.c similar to the current one - but this
file would no longer live in library or be included when building libmbedx509.
Reasons include:
- Including test certificates and keys in the library provides little value, as
users will want to use their own certificates and keys anyway.
- Shipping private keys as part of the library is bad practice, even under the
`mbedtls_test_` sub-namespace. There's a slight risk that some users could
use them for prototyping and then inadvertently keep using unsafe private keys
in production.
If you disagree or have concerns, please speak up! Also, if want to suggest
ideas for where the replacement to library/certs.c should live or how it
could be maintained, now's a good time as well!
Regards,
Manuel.
--
mbed-tls mailing list
mbed-tls(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/mbed-tls
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Hi all,
So personally I'm quite strongly inclined to remove timing.c from the
library, and move most of its content elsewhere, with one possible
exception:
> - mbedtls_timing_set_delay() and mbedtls_timing_get_delay() are an example
> implementation (only for Unix and Windows) of timer callbacks for DTLS, only
> used in programs/ssl/*.c
Since timer callbacks are a hard requirement for using DTLS, and it seems
quite desirable to be able to support DTLS out of the box at least on
some platforms, I was thinking this pair of function (and the associated
context type) could be kept in the library, in a new module that would
be called something like ssl_dtls_timer.c.
This would be somewhat similar to ssl_cookies.c, ssl_tickets.c and
ssl_cache.c: they all provide implementations of callbacks that can be
used with the main SSL/(D)TLS module, but users are obviously free to
compile them out and use their own implementation if the one we provide
does not meet their needs.
As it happens, all three of these support modules work best if
MBEDTLS_HAVE_TIME is defined, but can work without it.
For the new ssl_dtls_timer.c I'm suggesting, the situation would be
different: the module could have a hard dependency on MBEDTLS_HAVE_TIME,
but work better on selected platforms (say, C11, POSIX and
Windows) where we know how to access sub-second timing information. (Or
alternatively, have a hard dependency on C11-or-Posix-or-Windows.)
For the record, mbedtls_ssl_conf_handshake_timeout() accepts timeout
values in milliseconds, but recommended values for use over the general
internet start at 1 second:
https://tools.ietf.org/html/rfc6347#section-4.2.4.1
So it might make sense to provide this module even when we only have
second resolution - we'd just have to work out how the timer function
would behave when passed sub-second values. (My first thought it
rounding up to the next second would be quite OK.)
What do you'all think? Personnally, I don't have a strong opinion
between the three following options, though I have a slight preference
for the first one:
1. Provide ssl_dtls_timer.c in the library with hard dep on HAVE_TIME
and enhanced features with C11/Posix/Windows.
2. Provide ssl_dtls_timer.c in the library with hard dep on
C11/Posix/Windows.
3. Move it all out of the library and let the thing live somewhere under
programs/ as it's only used by example/testing programs.
Note though that we could also choose to go with option 3 for Mbed TLS
3.0, see how it goes, and later switch to option 2 or 1 if we want, as
adding modules can be done at any time. (In the same vein, we could
start with 2 and switch to 1 at any time as well.)
Regards,
Manuel.
Hi Torsten,
[I'm assuming didn't mean to reply on the list and not just to me, so I'm
replying on the list.]
> On 20/04/2020 11:51, Manuel Pegourie-Gonnard via mbed-tls wrote:
>> For reference, this module includes the following functions, which are used
>> in the following places:
>>
>> - mbedtls_timing_hardclock() implements cycle counting (on selected
>> architectures, not including M-class), used only in
>> programs/test/benchmark.c
>
> I used mbedtls_timing_hardclock() for my own benchmarking experiments on
> Linux and Windows, but couldn't get it to run on the target machine. So
> I've use my own ms counter instead. So, it could be easily removed as
> part of the library.
>
Good to know, thanks for sharing this data point.
> Question: How do you want to do the benchmarking instead? With the same
> code, but outside the library?
>
Yes, I was thinking that the functions that are only used in benchmark.c
could be defined in benchmark.c, and the functions that are only used in
udp_proxy.c could be defined in udp_proxy.c.
(Or actually for the latter, we might want to start using them in
ssl_client2.c and ssl_server2.c as well, as including millisecond
timestamps in the debug output would be usefull to debug some issues. In
that case, we'll probably put those functions in a new file, used by
udp_proxy, ssl_client2 and ssl_server2 (just like query_config.c is
currently used by ssl_client2, ssl_server2 and
query_compile_time_config).)
Regards,
Manuel.
Hi Torsten,
> this will be a long mail. Sorry for that.
>
On the contrary, thank you so much for this extensive and well though-out
feedback, that's very helpful!
I'll try to complement Gilles's reply, and skip the points he already answered
unless I have something to add, as I'm generally in full agreement with what
he wrote.
> 3. For certification and evaluation purposes I need some test vectors
> for each crypto function on target. While I know about the
> comprehensive self-test program I'm now talking about built-in
> functions like mbedtls_sha512_self_test(), etc to be enabled with
> #define MBEDTLS_SELF_TEST.
>
> These self-tests are very different in coverage. For SHA-384 and
> SHA-512 they are fine, for HMAC-SHA-384 and HMAC-SHA-512 I couldn't
> find any as well as for HKDF-HMAC-SHA-256 (in RFC 5869) or
> HKDF-HMAC-SHA-384/512 (official test vectors difficult to find).
> AES-CTR and AES-XTS are only tested with key length 128 bit, not with
> 256 bit. AES-CCM is not tested with 256 bit and even for 128 bit,
> the test vector from the standard NIST SP 800-38C with long
> additional data is not used.
> The builtin self-test for GCM is the best I've seen with mbedtls:
> all three key lengths are tested as well as the IUF-interface and
> the comfort function. Bravo!
>
Indeed so far we don't have clear guidelines on self-test functions, and we
should try to have more consistency here. Since this is incremental,
backwards-compatible improvements, it can be done at any time (unlike some API
improvements that can only be done when preparing major versions).
Contributions in this area are certainly welcome!
> 7. While at Elliptic Curve Cryptography: I assume that some of you
> know that projectives coordinates as outer interface to ECC are
> dangerous, see David Naccache, Nigel P. Smart, Jacques Stern:
> Projective Coordinates Leak, Eurocrypt 2004, pp. 257–267.
Yes, and as it happens this was revisited recently by researchers, and brought
back to our attention:
https://tls.mbed.org/tech-updates/security-advisories/mbedtls-security-advi…
> you have Jacobian coordinates, i.e. projective coordinates, as outer
> interface. In the comment, its is noted that only the affine part is
> used, but can this be assured? In all circumstances?
>
In practice, I'm pretty confident this is the case, because both
ecp_normalize_jac() and ecp_normalize_mxz() set Z to 1, these functions are
always called before returning data, and if we forgot to call those functions,
we'd get incorrect X and Y coordinates and fail unit test and interop tests.
But as a matter of principle, I agree that exposing Jacobian coordinates in
the API was a poor decision. Fortunately, we already intended to start phasing
out the existing ECP interface in 3.0 (to which extend exactly is still to be
discussed), and in the future is should be fully removed in favour of the PSA
Crypto API, which doesn't have this problem.
> 8. In my personal opinion the definition
> [...]
> mbedtls_ecp_keypair;
>
> is dangerous. Why not differentiate between private and public key
> and domain parameters?
I agree, and I think it's a generally accepted opinion in the crypto
implementation community that private and public keys should be clearly
distinguished from one another, for example by using distinct types (in typed
languages).
This is by the way a long-standing problem that existed in the RSA module from
the start, and when ECC was added it followed a similar pattern.
Again, I think the transition of the PSA Crypto API is going to be the answer
here, as it will provide much cleaner key management.
> 9. Regarding ECC examples: I found it very difficult that there isn't
> a single example with known test vectors as in the relevant crypto
> standards, i.e. FIPS 186-4 and ANSI X9.62-2005, with raw public
> keys. What I mean are (defined) curves, public key value Q=(Qx,Qy)
> and known signature values r and s. In the example ecdsa.c you
> generate your own key pair and read/write the signature in
> serialized form. In the example programs/pkey/pk_sign.c and
> pk_verify.c you use a higher interface pk.h and keys in PEM format.
>
> So, it took me a while for a program to verify (all) known answer
> tests in the standards (old standards as ANSI X9.62 1998 have more
> detailed known answer tests). One needs this interface with raw
> public keys for example for CAVP tests, see The FIPS 186-4 Elliptic
> Curve Digital Signature Algorithm Validation System (ECDSA2VS).
>
> 11. In the moment, there is no single known answer tests for ECDSA
> (which could be activated with #define MBEDTLS_SELF_TEST). I
> wouldn't say that you need an example for every curve and hash
> combination, as it is done in ECDSA2VS CAVP, but one example for
> one of the NIST curves and one for Curve25519 and - if I have a
> wish free - one for Brainpool would be fine. And this would solve
> #9 above.
>
I might be misunderstanding, but isn't the function
ecdsa_prim_test_vectors() in tests/suites/test_suite_ecdsa.function close to
what you're looking for? I mean, except for the fact that it's not in the
self-test function, and that it's using data from RFCs rather than from NIST
or ANSI?
But I agree this is a bit messy and could be made cleaner.
Also, if you ever feel like contributing your dream self-test function for
ECDSA as PR, this will be a very welcome contribution!
> 13. Feature request: Since it was irrelevant for my task (only
> verification, no generation) I didn't have a detailed look a your
> ECC side-channel countermeasures. But obviously you use the same
> protected code for scalar multiplication in verify and sign,
> right? Wouldn't it be possible to use Shamir's trick in
> verification with fast unprotected multi-scalar multiplication. In
> the moment, mbedtls_ecdsa_verify is a factor 4-5 slower than
> mbedtls_ecdsa_sign, while OpenSSLs verify is faster than sign.
>
Yes, this was done to save both on code size and developer time, but I agree
it's suboptimal for performance. As Gilles wrote, as a general rule we tend to
favour code size and security/maintainability over performance, but in that
instance if we provide an option for a verify-only ECDSA build (which I agree
we should), then we're likely to reach smaller code size by having a
standalone unprotected implementation of multi-scalar multiplication, so that
would probably be a great option: better performance _and_ smaller code.
Unfortunately we're already quite busy with other things, so this kind of
optimisation will probably have to wait for a bit more, but we're taking good
note of the suggestion and will try to implement it in the future.
Again, thanks for this comprehensive and useful feedback.
Regards,
Manuel.
On 20/04/2020 11:51, Manuel Pegourie-Gonnard via mbed-tls wrote:
> [ Context: https://developer.trustedfirmware.org/w/mbed-tls/tech-plans-3.0/ ]
>
> Currently the crypto library includes a module called timing.c, enabled by
> default in config.h (but disabled by config.py baremetal), containing various
> functions related to timing (not to be confused with the time abstration
> present in the platorm module).
>
> In Mbed TLS 3.0, as part of our effort to clean up and minimize our API,
> we're considering removing (parts of) this module from the library, and
> moving its parts to a variety of other places, such as example programs (or
> a library/file shared by them, like the current query_config mechanism).
>
> For reference, this module includes the following functions, which are used in
> the following places:
>
> - mbedtls_timing_hardclock() implements cycle counting (on selected
> architectures, not including M-class), used only in
> programs/test/benchmark.c
I used mbedtls_timing_hardclock() for my own benchmarking experiments on
Linux and Windows, but couldn't get it to run on the target machine. So
I've use my own ms counter instead. So, it could be easily removed as
part of the library.
Question: How do you want to do the benchmarking instead? With the same
code, but outside the library?
Torsten