From ece5971c6f6b4ba59f30dcbd3e84bcd6aaafe1e1 Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Wed, 11 Sep 2019 13:57:11 -0700 Subject: [PATCH 001/420] Add proposed quorum rules Adapted from Stephen Walli's document, except that "majority" is changed to "super majority" for consistency with existing text in this doc. Signed-off-by: Dave Thaler --- docs/Maintainers.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/Maintainers.md b/docs/Maintainers.md index bdbecdc0bf..9046d913b1 100644 --- a/docs/Maintainers.md +++ b/docs/Maintainers.md @@ -13,6 +13,22 @@ but when that fails, the Committee calls for a vote where the super majority (two-thirds) wins. This is to prevent obstructionism by removing the possibility of a one person veto. +Quorum for Community Maintenance Committee meetings requires at least fifty +percent of all members of the Community Maintenance Committee to be present. The +Community Maintenance Committee may continue to meet if quorum is not met but will +be prevented from making any decisions at the meeting. + +Except for the cases below, decisions by vote at a meeting require a super majority +vote of those in attendance, provided quorum is met: + +* Revisions to this document +* Decisions regarding open source licence(s) for Open Enclave code or dependencies + from Open Enclave code. + +Decisions made by electronic vote without a meeting, and all decisions on the topics +above, require a super majority vote of all members of the Community Maintenance Committee. + + Committee Members ----------------- From 83793ce5680ab73215cfdd81585c675e37471c89 Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Wed, 11 Sep 2019 14:13:25 -0700 Subject: [PATCH 002/420] Rename Community Maintenance Committee Given the confusion between Maintainer vs CMC member, Maintainers Group for example might be clearer. Mike and John indicated initial support for this term. Another term used by many projects is "Technical Steering Committee", which is the term that also appears in Stephen Walli's doc. I would be ok with that term, just for consistency with other open source projects, if the group prefers that term. However, it has the same confusion between Maintainer vs TSC member. One way that could be resolved, should the TSC name be used, would be to remove the term "Maintainer" and only use "TSC member", "Committer", and "Contributor" as roles, which is the approach Stephen's doc takes. Signed-off-by: Dave Thaler --- docs/GovernanceModel.md | 16 +++++++-------- docs/Maintainers.md | 43 +++++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/docs/GovernanceModel.md b/docs/GovernanceModel.md index 8f187d335c..0938bd185e 100644 --- a/docs/GovernanceModel.md +++ b/docs/GovernanceModel.md @@ -17,9 +17,9 @@ In order to maintain a pleasant and welcoming environment, we want to reiterate that it is imperative that all community members adhere to our [Code of Conduct](Contributing.md#code-of-conduct). Anyone failing to follow the Code of Conduct will be removed from the community -by the [Community Maintenance Committee](Maintainers.md). If you are made to +by the [Maintainers Group](Maintainers.md). If you are made to feel uncomfortable, or have any concerns about behavior within the community, we -encourage you to reach out to members of the Community Maintenance Committee. +encourage you to reach out to members of the Maintainers Group. Design and Development Discussions ---------------------------------- @@ -44,17 +44,17 @@ Issues](Contributing.md#reporting-security-issues). Maintainers, Committers, and Contributors ----------------------------------------- -We define "maintainer" as members of the Open Enclave "Community Maintenance -Committee", as listed in the [maintainers document](Maintainers.md). A +We define "maintainer" as members of the Open Enclave "Maintainers +Group", as listed in the [maintainers document](Maintainers.md). A "committer" is anyone with direct write access to the Open Enclave repository on -GitHub, as granted by the Committee. All maintainers are committers, but not all +GitHub, as granted by the Maintainers Group. All maintainers are committers, but not all committers are maintainers. Finally, "contributor" is anyone else making contributions to the project, including: creating or commenting on issues, opening or reviewing pull requests, or other useful contributions such as providing support in forums or chats. -See the [maintainers document](Maintainers.md) for the Community Maintenance -Committee, our process for adding new committers and maintainers, as well the +See the [maintainers document](Maintainers.md) for the Maintainers +Group, our process for adding new committers and maintainers, as well the areas of expertise for each of the committers. Accepting Contributions @@ -69,7 +69,7 @@ Committers may revert changes if they are found to be breaking. We make most decisions through a consensus seeking process, rather than a formal voting process. For example, committers can merge contributions that were reviewed without objections. If there are objections that cannot be resolved, an -issue can be escalated to the Community Maintenance Committee to make a +issue can be escalated to the Maintaines Group to make a decision, which handles issues as discussed in the [maintainers document](Maintainers.md). diff --git a/docs/Maintainers.md b/docs/Maintainers.md index bdbecdc0bf..f7e4c9f98e 100644 --- a/docs/Maintainers.md +++ b/docs/Maintainers.md @@ -1,20 +1,21 @@ -Community Maintenance Committee -=============================== +Maintainers Group +================= -This document describes the Community Maintenance Committee of Open Enclave. By +This document describes the Open Enclave Maintainers Group, which in some open source +projects is also known as a Technical Steering Committee. By our liberal contribution policy outlined in our [governance model](GovernanceModel.md), maintainers are committers that are trusted to grant new committer rights, and grant new membership into the -Committee. +Maintainers Group. -When making decisions, the Community Maintenance Committee uses a "consensus +When making decisions, the Maintainers Group uses a "consensus seeking" process. This means that most decisions should be reached by consensus, -but when that fails, the Committee calls for a vote where the super majority +but when that fails, the Maintainers Group calls for a vote where the super majority (two-thirds) wins. This is to prevent obstructionism by removing the possibility of a one person veto. -Committee Members ------------------ +Maintainers +----------- | Name | Company | Email | GitHub Alias | |----------------------|-----------|-------------------------------|----------------| @@ -27,33 +28,33 @@ Committee Members | Mike Brasher | Microsoft | mikbras@microsoft.com | mikbras | | Simon Leet | Microsoft | simon.leet@microsoft.com | CodeMonkeyLeet | -Committee Responsibilities --------------------------- +Responsibilities +---------------- -The primary responsibility of the Committee is to grant new committer rights +The primary responsibility of the Maintainers Group is to grant new committer rights (that is, write access to the main Open Enclave SDK repository or related -repositories), and to grant new membership into the committee. Conversely, the -Committee must also remove committer rights and membership from those found to +repositories), and to grant new membership into the Maintainers Group. Conversely, the +Group must also remove committer rights and membership from those found to be violating the project's Code of Conduct or otherwise negatively affecting the project's community health. -This Committee is not intended to make every technical decision, as those should +This Group is not intended to make every technical decision, as those should generally be made by agreement among committers as PRs are reviewed and merged. Where disagreements take place and need further resolution, those can be brought -up with the Committee as part of its responsibility to maintain the project's +up with the Group as part of its responsibility to maintain the project's community health. Otherwise technical decisions are left to the active committers (by virtue of the liberal contribution policy). -The Community Maintenance Committee should meet regularly, for example, once a +The Maintainers Group should meet regularly, for example, once a month. This meeting is a private meeting among just the maintainers to nominate new committers and maintainer members. Priority consideration should be given to -those actively contributing to the project. The Committee uses the consensus +those actively contributing to the project. The Group uses the consensus seeking process outlined above when making decisions, including adding or -removing any members. The Committee should also discuss the community's health +removing any members. The Group should also discuss the community's health and work to resolve any negative issues. In order to maintain a healthy developer community, it is recommended that the -Committee also host a regular public community meeting. This meeting should be +Group also host a regular public community meeting. This meeting should be open all members of the community, and start with an open forum to hear questions or concerns from the community. Any remaining time in the meeting should be used to discuss and review open pull requests or issues (especially @@ -63,12 +64,12 @@ Project Committers ================== The following people have been granted commit permissions (that is, write -access) to the Open Enclave SDK by the Community Maintenance Committee. The area +access) to the Open Enclave SDK by the Maintainers Group. The area column describes which technical areas each committer is most interested in, and therefore should usually be consulted for changes relating to that area. However, it is up to each committer to determine who should review which PR, and when to merge it. Remember that a PR must not be merged if a committer objects; -instead, it should be brought up with the Community Maintenance Committee. +instead, it should be brought up with the Maintainers Group. | Name | GitHub Alias | Area | |-----------------------|---------------------|--------------------------------| From d79c431d71e7792e9c0e25476160bcfb8ad330ab Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Wed, 11 Sep 2019 15:02:14 -0700 Subject: [PATCH 003/420] Add developer guidance around abbreviations and doxygen Signed-off-by: Dave Thaler --- docs/DevelopmentGuide.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/DevelopmentGuide.md b/docs/DevelopmentGuide.md index df26880aaa..b02b6a0764 100644 --- a/docs/DevelopmentGuide.md +++ b/docs/DevelopmentGuide.md @@ -11,8 +11,18 @@ Coding Conventions * **DO** use `const` and `static` and visibility modifiers to scope exposure of variables and methods as much as possible. +* **DO** use doxygen comments, with \[in,out\] + [direction annotation](http://www.doxygen.nl/manual/commands.html#cmdparam) in all public API + headers. This is also encouraged, but not strictly required, for internal API + headers as well. + * **DON'T** use global variables where possible. +* **DON'T** use abbreviations unless they are already well-known terms known by + users (e.g., "app", "info"), or are already required for use by developers (e.g, + "min", "max", "args"). Examples of bad use would be `num_widgets` instead of + `widget_count`, and `opt_widgets` instead of `option_widgets` or `optional_widgets`. + Style Guide ----------- From 28232e4c52524a875493bdd6b433731d939b14ca Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Thu, 12 Sep 2019 11:25:44 -0700 Subject: [PATCH 004/420] Accept Simon's proposed change Signed-off-by: Dave Thaler --- docs/Maintainers.md | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/docs/Maintainers.md b/docs/Maintainers.md index 9046d913b1..2a3733dec4 100644 --- a/docs/Maintainers.md +++ b/docs/Maintainers.md @@ -13,20 +13,13 @@ but when that fails, the Committee calls for a vote where the super majority (two-thirds) wins. This is to prevent obstructionism by removing the possibility of a one person veto. -Quorum for Community Maintenance Committee meetings requires at least fifty -percent of all members of the Community Maintenance Committee to be present. The +Quorum for Community Maintenance Committee meetings requires at least two-thirds +all members of the Community Maintenance Committee to be present. The Community Maintenance Committee may continue to meet if quorum is not met but will be prevented from making any decisions at the meeting. -Except for the cases below, decisions by vote at a meeting require a super majority -vote of those in attendance, provided quorum is met: - -* Revisions to this document -* Decisions regarding open source licence(s) for Open Enclave code or dependencies - from Open Enclave code. - -Decisions made by electronic vote without a meeting, and all decisions on the topics -above, require a super majority vote of all members of the Community Maintenance Committee. +All decisions by vote, whether during a meeting or otherwise, require a super majority +vote of all members of the Community Maintenance Committee. Committee Members From 15e397cbdd5ed5cecbdb91c0798790141246753d Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Thu, 12 Sep 2019 16:38:52 -0700 Subject: [PATCH 005/420] Remove all use of Maintainer as a term Per review discussion so far Signed-off-by: Dave Thaler --- docs/Maintainers.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/Maintainers.md b/docs/Maintainers.md index f7e4c9f98e..689480e689 100644 --- a/docs/Maintainers.md +++ b/docs/Maintainers.md @@ -1,21 +1,21 @@ -Maintainers Group -================= +Community Governance Committee +============================== -This document describes the Open Enclave Maintainers Group, which in some open source +This document describes the Open Enclave Community Governance Committee, which in some open source projects is also known as a Technical Steering Committee. By our liberal contribution policy outlined in our [governance model](GovernanceModel.md), maintainers are committers that are trusted to grant new committer rights, and grant new membership into the -Maintainers Group. +Committee. -When making decisions, the Maintainers Group uses a "consensus +When making decisions, the Community Governance Committee uses a "consensus seeking" process. This means that most decisions should be reached by consensus, -but when that fails, the Maintainers Group calls for a vote where the super majority +but when that fails, the Committee calls for a vote where the super majority (two-thirds) wins. This is to prevent obstructionism by removing the possibility of a one person veto. -Maintainers ------------ +Committee Members +----------------- | Name | Company | Email | GitHub Alias | |----------------------|-----------|-------------------------------|----------------| @@ -28,33 +28,33 @@ Maintainers | Mike Brasher | Microsoft | mikbras@microsoft.com | mikbras | | Simon Leet | Microsoft | simon.leet@microsoft.com | CodeMonkeyLeet | -Responsibilities ----------------- +Committee Responsibilities +-------------------------- -The primary responsibility of the Maintainers Group is to grant new committer rights +The primary responsibility of the Committee is to grant new committer rights (that is, write access to the main Open Enclave SDK repository or related -repositories), and to grant new membership into the Maintainers Group. Conversely, the -Group must also remove committer rights and membership from those found to +repositories), and to grant new membership into the Committee. Conversely, the +Commitee must also remove committer rights and membership from those found to be violating the project's Code of Conduct or otherwise negatively affecting the project's community health. -This Group is not intended to make every technical decision, as those should +This Committee is not intended to make every technical decision, as those should generally be made by agreement among committers as PRs are reviewed and merged. Where disagreements take place and need further resolution, those can be brought -up with the Group as part of its responsibility to maintain the project's +up with the Committee as part of its responsibility to maintain the project's community health. Otherwise technical decisions are left to the active committers (by virtue of the liberal contribution policy). -The Maintainers Group should meet regularly, for example, once a +The Community Governance Committee should meet regularly, for example, once a month. This meeting is a private meeting among just the maintainers to nominate new committers and maintainer members. Priority consideration should be given to -those actively contributing to the project. The Group uses the consensus +those actively contributing to the project. The Committee uses the consensus seeking process outlined above when making decisions, including adding or -removing any members. The Group should also discuss the community's health +removing any members. The Committee should also discuss the community's health and work to resolve any negative issues. In order to maintain a healthy developer community, it is recommended that the -Group also host a regular public community meeting. This meeting should be +Committee also host a regular public community meeting. This meeting should be open all members of the community, and start with an open forum to hear questions or concerns from the community. Any remaining time in the meeting should be used to discuss and review open pull requests or issues (especially @@ -64,12 +64,12 @@ Project Committers ================== The following people have been granted commit permissions (that is, write -access) to the Open Enclave SDK by the Maintainers Group. The area +access) to the Open Enclave SDK by the Community Governance Committee. The area column describes which technical areas each committer is most interested in, and therefore should usually be consulted for changes relating to that area. However, it is up to each committer to determine who should review which PR, and when to merge it. Remember that a PR must not be merged if a committer objects; -instead, it should be brought up with the Maintainers Group. +instead, it should be brought up with the Community Governance Committee. | Name | GitHub Alias | Area | |-----------------------|---------------------|--------------------------------| From 5bc22b544c41a49d7988c7204c6445903ad5fe51 Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Thu, 12 Sep 2019 16:39:50 -0700 Subject: [PATCH 006/420] Remove use of Maintainers as a term Signed-off-by: Dave Thaler --- docs/GovernanceModel.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/GovernanceModel.md b/docs/GovernanceModel.md index 0938bd185e..6e7001ad27 100644 --- a/docs/GovernanceModel.md +++ b/docs/GovernanceModel.md @@ -17,9 +17,9 @@ In order to maintain a pleasant and welcoming environment, we want to reiterate that it is imperative that all community members adhere to our [Code of Conduct](Contributing.md#code-of-conduct). Anyone failing to follow the Code of Conduct will be removed from the community -by the [Maintainers Group](Maintainers.md). If you are made to +by the [Community Governance Committee](Maintainers.md). If you are made to feel uncomfortable, or have any concerns about behavior within the community, we -encourage you to reach out to members of the Maintainers Group. +encourage you to reach out to members of the Community Governance Committee. Design and Development Discussions ---------------------------------- @@ -41,20 +41,18 @@ Remember that security issues should be reported through a separate channel, and will receive a response within 24 hours. See [Reporting Security Issues](Contributing.md#reporting-security-issues). -Maintainers, Committers, and Contributors ------------------------------------------ +Community Maintenance Commitee Members, Committers, and Contributors +-------------------------------------------------------------------- -We define "maintainer" as members of the Open Enclave "Maintainers -Group", as listed in the [maintainers document](Maintainers.md). A -"committer" is anyone with direct write access to the Open Enclave repository on -GitHub, as granted by the Maintainers Group. All maintainers are committers, but not all -committers are maintainers. Finally, "contributor" is anyone else making +A "committer" is anyone with direct write access to the Open Enclave repository on +GitHub, as granted by the Committee. All Committee members are committers, but not all +committers are Committee members. Finally, "contributor" is anyone else making contributions to the project, including: creating or commenting on issues, opening or reviewing pull requests, or other useful contributions such as providing support in forums or chats. -See the [maintainers document](Maintainers.md) for the Maintainers -Group, our process for adding new committers and maintainers, as well the +See the [Community Governance Committee document](Maintainers.md) for more information +on the Community Governance Committee, our process for adding new committers and maintainers, as well the areas of expertise for each of the committers. Accepting Contributions @@ -69,11 +67,11 @@ Committers may revert changes if they are found to be breaking. We make most decisions through a consensus seeking process, rather than a formal voting process. For example, committers can merge contributions that were reviewed without objections. If there are objections that cannot be resolved, an -issue can be escalated to the Maintaines Group to make a +issue can be escalated to the Community Governance Committee to make a decision, which handles issues as discussed in the -[maintainers document](Maintainers.md). +[Community Governance Committee document](Maintainers.md). -See the [maintainers document](Maintainers.md) for the list of project +See the [Community Governance Committee document](Maintainers.md) for the list of project committers, and how to become one. Community Approval of Releases From af902ca1cf7d82dc582c979a391afcfbf8373a5c Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Thu, 12 Sep 2019 16:42:13 -0700 Subject: [PATCH 007/420] Remove use of Maintainer as a term Signed-off-by: Dave Thaler --- docs/Contributing.md | 6 +++--- docs/DevelopmentGuide.md | 2 +- docs/GovernanceModel.md | 2 +- docs/Maintainers.md | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/Contributing.md b/docs/Contributing.md index 653e21feac..c2f09f1156 100644 --- a/docs/Contributing.md +++ b/docs/Contributing.md @@ -39,7 +39,7 @@ You are encouraged to start a discussion with us through a GitHub issue before implementing any major changes. We want your contributions, but we also want to make sure the community is in agreement before you invest your time. -You may be asked by maintainers to provide a design document before writing an +You may be asked by Committers to provide a design document before writing an implementation. The simplest way to provide this is through a Pull Request to our repository with a Markdown style document (like this one) to the [docs/DesignDocs](DesignDocs) folder, and see its [readme](DesignDocs/README.md) @@ -81,7 +81,7 @@ Please do: - **DO** submit all code changes via pull requests (PRs) rather than through a direct commit. PRs will be reviewed and potentially merged by the repo - maintainers after a peer review that includes at least one maintainer. + Committers after a peer review that includes at least one Committer. - **DO** give PRs short-but-descriptive names (e.g. "Improve code coverage for System.Console by 10%", not "Fix #1234"). - **DO** add breaking changes, new features, deprecations, and bug @@ -134,7 +134,7 @@ Merging Pull Requests Instead of merging pull requests with "the big green button" on GitHub, we use an automated system called [Bors](https://bors.tech/). The Bors bot is the _only_ approved mechanism of merging code to `master`. When a PR is ready to be -merged, a maintainer will comment on it with `bors r+`. +merged, a Committer will comment on it with `bors r+`. Bors will automatically: 1. Apply the PR's commits to a `staging` branch based on `master`. diff --git a/docs/DevelopmentGuide.md b/docs/DevelopmentGuide.md index df26880aaa..500ca3ad4d 100644 --- a/docs/DevelopmentGuide.md +++ b/docs/DevelopmentGuide.md @@ -97,7 +97,7 @@ in that file takes precedence. Note that we _no longer_ use `CamelCase` nor double underscores (`__`), but you may find remnants and so again should prefer the local style. This is especially the case for classes, which are still using `PascalCase`. For now, follow the -existing style. The project maintainers prefer to fix style issues in bulk using +existing style. The project Committers prefer to fix style issues in bulk using automation, so avoid submitting PRs intended to fix only a few instances of the inconsistent style. diff --git a/docs/GovernanceModel.md b/docs/GovernanceModel.md index 6e7001ad27..3cbfdcc7b6 100644 --- a/docs/GovernanceModel.md +++ b/docs/GovernanceModel.md @@ -52,7 +52,7 @@ opening or reviewing pull requests, or other useful contributions such as providing support in forums or chats. See the [Community Governance Committee document](Maintainers.md) for more information -on the Community Governance Committee, our process for adding new committers and maintainers, as well the +on the Community Governance Committee, our process for adding new committers and Committee members, as well the areas of expertise for each of the committers. Accepting Contributions diff --git a/docs/Maintainers.md b/docs/Maintainers.md index 689480e689..248d1f7b52 100644 --- a/docs/Maintainers.md +++ b/docs/Maintainers.md @@ -4,7 +4,7 @@ Community Governance Committee This document describes the Open Enclave Community Governance Committee, which in some open source projects is also known as a Technical Steering Committee. By our liberal contribution policy outlined in our -[governance model](GovernanceModel.md), maintainers are committers that are +[governance model](GovernanceModel.md), Committee members are committers that are trusted to grant new committer rights, and grant new membership into the Committee. @@ -46,8 +46,8 @@ community health. Otherwise technical decisions are left to the active committers (by virtue of the liberal contribution policy). The Community Governance Committee should meet regularly, for example, once a -month. This meeting is a private meeting among just the maintainers to nominate -new committers and maintainer members. Priority consideration should be given to +month. This meeting is a private meeting among just the Committee members to nominate +new committers and Committee members. Priority consideration should be given to those actively contributing to the project. The Committee uses the consensus seeking process outlined above when making decisions, including adding or removing any members. The Committee should also discuss the community's health From 4dafeb9c724ddbca288fe1605afb24001b376031 Mon Sep 17 00:00:00 2001 From: Simon Leet Date: Fri, 13 Sep 2019 00:26:37 +0000 Subject: [PATCH 008/420] Clone mbedTLS v2.7.11 into 3rdparty/mbedtls/mbedtls --- 3rdparty/mbedtls/mbedtls/.globalrc | 3 + 3rdparty/mbedtls/mbedtls/.travis.yml | 3 +- 3rdparty/mbedtls/mbedtls/CMakeLists.txt | 26 +- 3rdparty/mbedtls/mbedtls/ChangeLog | 94 ++ 3rdparty/mbedtls/mbedtls/Makefile | 9 + 3rdparty/mbedtls/mbedtls/circle.yml | 44 - .../mbedtls/doxygen/input/doc_mainpage.h | 2 +- .../mbedtls/mbedtls/doxygen/mbedtls.doxyfile | 2 +- .../mbedtls/mbedtls/include/CMakeLists.txt | 2 +- .../mbedtls/mbedtls/include/mbedtls/aesni.h | 6 + .../mbedtls/include/mbedtls/asn1write.h | 31 +- .../mbedtls/mbedtls/include/mbedtls/base64.h | 6 + .../mbedtls/mbedtls/include/mbedtls/bn_mul.h | 8 +- .../mbedtls/mbedtls/include/mbedtls/ccm.h | 6 + .../mbedtls/mbedtls/include/mbedtls/certs.h | 6 + .../mbedtls/mbedtls/include/mbedtls/cmac.h | 6 + .../mbedtls/include/mbedtls/compat-1.3.h | 6 + .../mbedtls/mbedtls/include/mbedtls/config.h | 20 + .../mbedtls/include/mbedtls/ctr_drbg.h | 6 + .../mbedtls/mbedtls/include/mbedtls/ecdh.h | 6 + .../mbedtls/mbedtls/include/mbedtls/ecdsa.h | 6 + .../mbedtls/mbedtls/include/mbedtls/ecjpake.h | 5 + .../mbedtls/mbedtls/include/mbedtls/ecp.h | 6 + .../mbedtls/include/mbedtls/ecp_internal.h | 6 + .../mbedtls/mbedtls/include/mbedtls/error.h | 6 + .../mbedtls/mbedtls/include/mbedtls/gcm.h | 6 + .../mbedtls/mbedtls/include/mbedtls/havege.h | 6 + .../mbedtls/include/mbedtls/hmac_drbg.h | 6 + .../mbedtls/mbedtls/include/mbedtls/net.h | 5 + .../mbedtls/mbedtls/include/mbedtls/padlock.h | 6 + .../mbedtls/mbedtls/include/mbedtls/pem.h | 6 + .../mbedtls/mbedtls/include/mbedtls/pkcs12.h | 6 + .../mbedtls/mbedtls/include/mbedtls/pkcs5.h | 6 + .../mbedtls/mbedtls/include/mbedtls/ssl.h | 21 +- .../mbedtls/include/mbedtls/ssl_cache.h | 6 + .../include/mbedtls/ssl_ciphersuites.h | 6 + .../mbedtls/include/mbedtls/ssl_cookie.h | 6 + .../mbedtls/include/mbedtls/ssl_internal.h | 6 + .../mbedtls/include/mbedtls/ssl_ticket.h | 6 + .../mbedtls/mbedtls/include/mbedtls/version.h | 8 +- .../mbedtls/include/mbedtls/x509_crt.h | 2 +- .../mbedtls/include/mbedtls/x509_csr.h | 8 + .../mbedtls/mbedtls/library/CMakeLists.txt | 12 +- 3rdparty/mbedtls/mbedtls/library/asn1write.c | 28 +- 3rdparty/mbedtls/mbedtls/library/bignum.c | 66 +- 3rdparty/mbedtls/mbedtls/library/certs.c | 94 +- 3rdparty/mbedtls/mbedtls/library/debug.c | 44 +- 3rdparty/mbedtls/mbedtls/library/ecdh.c | 16 +- 3rdparty/mbedtls/mbedtls/library/ecdsa.c | 9 +- .../mbedtls/library/ssl_ciphersuites.c | 57 +- 3rdparty/mbedtls/mbedtls/library/ssl_tls.c | 143 +- .../mbedtls/library/version_features.c | 3 + 3rdparty/mbedtls/mbedtls/library/x509.c | 51 +- 3rdparty/mbedtls/mbedtls/library/x509_crl.c | 10 +- 3rdparty/mbedtls/mbedtls/library/x509_crt.c | 13 +- 3rdparty/mbedtls/mbedtls/library/x509_csr.c | 15 +- .../mbedtls/mbedtls/library/x509write_crt.c | 190 ++- .../mbedtls/mbedtls/library/x509write_csr.c | 36 +- 3rdparty/mbedtls/mbedtls/programs/Makefile | 6 +- .../mbedtls/programs/pkey/key_app_writer.c | 2 +- .../mbedtls/programs/pkey/rsa_sign_pss.c | 1 - .../mbedtls/programs/ssl/ssl_client2.c | 62 +- .../mbedtls/programs/ssl/ssl_mail_client.c | 30 +- .../mbedtls/programs/ssl/ssl_server2.c | 55 +- .../mbedtls/programs/test/CMakeLists.txt | 4 +- .../mbedtls/programs/test/ssl_cert_test.c | 261 ---- .../mbedtls/mbedtls/programs/test/udp_proxy.c | 29 +- .../mbedtls/mbedtls/programs/x509/cert_req.c | 98 +- .../mbedtls/programs/x509/cert_write.c | 6 +- 3rdparty/mbedtls/mbedtls/scripts/abi_check.py | 406 ++++++ 3rdparty/mbedtls/mbedtls/scripts/config.pl | 2 + 3rdparty/mbedtls/mbedtls/tests/CMakeLists.txt | 13 +- 3rdparty/mbedtls/mbedtls/tests/Makefile | 3 +- 3rdparty/mbedtls/mbedtls/tests/compat.sh | 7 +- .../mbedtls/mbedtls/tests/data_files/Makefile | 58 + .../mbedtls/tests/data_files/cert_md2.crt | 91 +- .../mbedtls/tests/data_files/cert_md4.crt | 89 +- .../mbedtls/tests/data_files/cert_md5.crt | 89 +- .../tests/data_files/server1-ms.req.sha256 | 16 + .../tests/data_files/server1.cert_type.crt | 12 +- .../data_files/server1.cert_type_noauthid.crt | 14 +- .../tests/data_files/server1.key_usage.crt | 14 +- .../data_files/server1.key_usage_noauthid.crt | 14 +- .../tests/data_files/server1.req.cert_type | 14 +- .../data_files/server1.req.cert_type_empty | 17 + .../tests/data_files/server1.req.key_usage | 14 +- .../data_files/server1.req.key_usage_empty | 17 + .../tests/data_files/server1.req.ku-ct | 14 +- .../tests/data_files/server5.req.ku.sha1 | 6 +- 3rdparty/mbedtls/mbedtls/tests/scripts/all.sh | 1252 ++++++++++------- .../mbedtls/tests/scripts/basic-build-test.sh | 2 +- .../mbedtls/tests/scripts/check-files.py | 156 +- .../mbedtls/tests/scripts/check-names.sh | 42 +- .../mbedtls/tests/scripts/list-identifiers.sh | 32 +- .../mbedtls/tests/scripts/list-symbols.sh | 15 +- .../mbedtls/tests/scripts/run-test-suites.pl | 68 +- 3rdparty/mbedtls/mbedtls/tests/ssl-opt.sh | 33 +- .../mbedtls/tests/suites/helpers.function | 1 + .../mbedtls/tests/suites/test_suite_ccm.data | 1 + .../tests/suites/test_suite_cipher.function | 7 +- .../mbedtls/tests/suites/test_suite_ecdh.data | 16 + .../tests/suites/test_suite_ecdh.function | 150 ++ .../mbedtls/tests/suites/test_suite_mpi.data | 3 + .../tests/suites/test_suite_mpi.function | 3 + .../tests/suites/test_suite_timing.data | 48 +- .../tests/suites/test_suite_timing.function | 391 +---- .../tests/suites/test_suite_version.data | 4 +- .../tests/suites/test_suite_x509parse.data | 402 +++--- .../suites/test_suite_x509parse.function | 11 + .../tests/suites/test_suite_x509write.data | 46 +- .../suites/test_suite_x509write.function | 16 +- .../mbedtls/visualc/VS2010/mbedTLS.sln | 13 - .../visualc/VS2010/ssl_cert_test.vcxproj | 174 --- 113 files changed, 3130 insertions(+), 2444 deletions(-) create mode 100644 3rdparty/mbedtls/mbedtls/.globalrc delete mode 100644 3rdparty/mbedtls/mbedtls/circle.yml delete mode 100644 3rdparty/mbedtls/mbedtls/programs/test/ssl_cert_test.c create mode 100755 3rdparty/mbedtls/mbedtls/scripts/abi_check.py create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server1-ms.req.sha256 create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.cert_type_empty create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.key_usage_empty delete mode 100644 3rdparty/mbedtls/mbedtls/visualc/VS2010/ssl_cert_test.vcxproj diff --git a/3rdparty/mbedtls/mbedtls/.globalrc b/3rdparty/mbedtls/mbedtls/.globalrc new file mode 100644 index 0000000000..01b2ea5a31 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/.globalrc @@ -0,0 +1,3 @@ +default:\ + :langmap=c\:.c.h.function:\ + diff --git a/3rdparty/mbedtls/mbedtls/.travis.yml b/3rdparty/mbedtls/mbedtls/.travis.yml index 4d23652c67..b4f21a30f0 100644 --- a/3rdparty/mbedtls/mbedtls/.travis.yml +++ b/3rdparty/mbedtls/mbedtls/.travis.yml @@ -24,7 +24,8 @@ after_failure: - tests/scripts/travis-log-failure.sh env: global: - secure: "barHldniAfXyoWOD/vcO+E6/Xm4fmcaUoC9BeKW+LwsHqlDMLvugaJnmLXkSpkbYhVL61Hzf3bo0KPJn88AFc5Rkf8oYHPjH4adMnVXkf3B9ghHCgznqHsAH3choo6tnPxaFgOwOYmLGb382nQxfE5lUdvnM/W/psQjWt66A1+k=" + - SEED=1 + - secure: "barHldniAfXyoWOD/vcO+E6/Xm4fmcaUoC9BeKW+LwsHqlDMLvugaJnmLXkSpkbYhVL61Hzf3bo0KPJn88AFc5Rkf8oYHPjH4adMnVXkf3B9ghHCgznqHsAH3choo6tnPxaFgOwOYmLGb382nQxfE5lUdvnM/W/psQjWt66A1+k=" addons: apt: diff --git a/3rdparty/mbedtls/mbedtls/CMakeLists.txt b/3rdparty/mbedtls/mbedtls/CMakeLists.txt index 0ade1d4cb8..7309d02e70 100644 --- a/3rdparty/mbedtls/mbedtls/CMakeLists.txt +++ b/3rdparty/mbedtls/mbedtls/CMakeLists.txt @@ -65,8 +65,14 @@ set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} # to the corresponding path in the source directory. function(link_to_source base_name) # Get OS dependent path to use in `execute_process` - file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${base_name}" link) - file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${base_name}" target) + if (CMAKE_HOST_WIN32) + #mklink is an internal command of cmd.exe it can only work with \ + string(REPLACE "/" "\\" link "${CMAKE_CURRENT_BINARY_DIR}/${base_name}") + string(REPLACE "/" "\\" target "${CMAKE_CURRENT_SOURCE_DIR}/${base_name}") + else() + set(link "${CMAKE_CURRENT_BINARY_DIR}/${base_name}") + set(target "${CMAKE_CURRENT_SOURCE_DIR}/${base_name}") + endif() if (NOT EXISTS ${link}) if (CMAKE_HOST_UNIX) @@ -200,13 +206,13 @@ if(ENABLE_TESTING) COMMAND mv DartConfiguration.tcl.bak DartConfiguration.tcl ) endif(UNIX) -endif() -# Make scripts needed for testing available in an out-of-source build. -if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) - link_to_source(scripts) - # Copy (don't link) DartConfiguration.tcl, needed for memcheck, to - # keep things simple with the sed commands in the memcheck target. - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/DartConfiguration.tcl - ${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl COPYONLY) + # Make scripts needed for testing available in an out-of-source build. + if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + link_to_source(scripts) + # Copy (don't link) DartConfiguration.tcl, needed for memcheck, to + # keep things simple with the sed commands in the memcheck target. + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/DartConfiguration.tcl + ${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl COPYONLY) + endif() endif() diff --git a/3rdparty/mbedtls/mbedtls/ChangeLog b/3rdparty/mbedtls/mbedtls/ChangeLog index 661eb82510..857cc4036a 100644 --- a/3rdparty/mbedtls/mbedtls/ChangeLog +++ b/3rdparty/mbedtls/mbedtls/ChangeLog @@ -1,5 +1,99 @@ mbed TLS ChangeLog (Sorted per branch, date) += mbed TLS 2.7.11 branch released 2019-06-11 + +Security + * Make mbedtls_ecdh_get_params return an error if the second key + belongs to a different group from the first. Before, if an application + passed keys that belonged to different group, the first key's data was + interpreted according to the second group, which could lead to either + an error or a meaningless output from mbedtls_ecdh_get_params. In the + latter case, this could expose at most 5 bits of the private key. + +Bugfix + * Server's RSA certificate in certs.c was SHA-1 signed. In the default + mbedTLS configuration only SHA-2 signed certificates are accepted. + This certificate is used in the demo server programs, which lead the + client programs to fail at the peer's certificate verification + due to an unacceptable hash signature. The certificate has been + updated to one that is SHA-256 signed. Fix contributed by + Illya Gerasymchuk. + * Fix private key DER output in the key_app_writer example. File contents + were shifted by one byte, creating an invalid ASN.1 tag. Fixed by + Christian Walther in #2239. + * Fix potential memory leak in X.509 self test. Found and fixed by + Junhwan Park, #2106. + * Fix 1-byte buffer overflow in mbedtls_mpi_write_string() when + used with negative inputs. Found by Guido Vranken in #2404. Credit to + OSS-Fuzz. + * Fix bugs in the AEAD test suite which would be exposed by ciphers which + either used both encrypt and decrypt key schedules, or which perform padding. + GCM and CCM were not affected. Fixed by Jack Lloyd. + * Fix incorrect default port number in ssl_mail_client example's usage. + Found and fixed by irwir. #2337 + * Add missing parentheses around parameters in the definition of the + public macro MBEDTLS_X509_ID_FLAG. This could lead to invalid evaluation + in case operators binding less strongly than subtraction were used + for the parameter. + * Add a check for MBEDTLS_X509_CRL_PARSE_C in ssl_server2, guarding the crl + sni entry parameter. Reported by inestlerode in #560. + * Fix missing bounds checks in X.509 parsing functions that could + lead to successful parsing of ill-formed X.509 CRTs. Fixes #2437. + * Fix multiple X.509 functions previously returning ASN.1 low-level error + codes to always wrap these codes into X.509 high level error codes before + returning. Fixes #2431. + +Changes + * Return from various debugging routines immediately if the + provided SSL context is unset. + * Remove dead code from bignum.c in the default configuration. + Found by Coverity, reported and fixed by Peter Kolbus (Garmin). Fixes #2309. + * Add test for minimal value of MBEDTLS_MPI_WINDOW_SIZE to all.sh. + Contributed by Peter Kolbus (Garmin). + * Change wording in the `mbedtls_ssl_conf_max_frag_len()`'s documentation to + improve clarity. Fixes #2258. + * Improve debug output of ssl_client2 and ssl_server2 in case suitable + test CRTs are available because MBEDTLS_PEM_PARSE_C is disabled. + Fixes #2254. + * Replace multiple uses of MD2 by SHA-256 in X.509 test suite. Fixes #821. + += mbed TLS 2.7.10 branch released 2019-03-19 + +Features + * Add MBEDTLS_REMOVE_3DES_CIPHERSUITES to allow removing 3DES ciphersuites + from the default list (enabled by default). See + https://sweet32.info/SWEET32_CCS16.pdf. + +Bugfix + * Run the AD too long test only if MBEDTLS_CCM_ALT is not defined. + Raised as a comment in #1996. + * Fix returning the value 1 when mbedtls_ecdsa_genkey failed. + * Remove a duplicate #include in a sample program. Fixed by Masashi Honma #2326. + * Reduce stack usage of `mpi_write_hlp()` by eliminating recursion. + Fixes #2190. + * Ensure that unused bits are zero when writing ASN.1 bitstrings when using + mbedtls_asn1_write_bitstring(). + * Fix issue when writing the named bitstrings in KeyUsage and NsCertType + extensions in CSRs and CRTs that caused these bitstrings to not be encoded + correctly as trailing zeroes were not accounted for as unused bits in the + leading content octet. Fixes #1610. + +Changes + * Include configuration file in all header files that use configuration, + instead of relying on other header files that they include. + Inserted as an enhancement for #1371 + * Add support for alternative CSR headers, as used by Microsoft and defined + in RFC 7468. Found by Michael Ernst. Fixes #767. + * Fix clobber list in MIPS assembly for large integer multiplication. + Previously, this could lead to functionally incorrect assembly being + produced by some optimizing compilers, showing up as failures in + e.g. RSA or ECC signature operations. Reported in #1722, fix suggested + by Aurelien Jarno and submitted by Jeffrey Martin. + * Reduce the complexity of the timing tests. They were assuming more than the + underlying OS actually guarantees. + * Ciphersuites based on 3DES now have the lowest priority by default when + they are enabled. + = mbed TLS 2.7.9 branch released 2018-12-21 Bugfix diff --git a/3rdparty/mbedtls/mbedtls/Makefile b/3rdparty/mbedtls/mbedtls/Makefile index a0fcb2bc56..6014597a97 100644 --- a/3rdparty/mbedtls/mbedtls/Makefile +++ b/3rdparty/mbedtls/mbedtls/Makefile @@ -108,3 +108,12 @@ apidoc: apidoc_clean: rm -rf apidoc endif + +## Editor navigation files +C_SOURCE_FILES = $(wildcard include/*/*.h library/*.[hc] programs/*/*.[hc] tests/suites/*.function) +tags: $(C_SOURCE_FILES) + ctags -o $@ $(C_SOURCE_FILES) +TAGS: $(C_SOURCE_FILES) + etags -o $@ $(C_SOURCE_FILES) +GPATH GRTAGS GSYMS GTAGS: $(C_SOURCE_FILES) + ls $(C_SOURCE_FILES) | gtags -f - --gtagsconf .globalrc diff --git a/3rdparty/mbedtls/mbedtls/circle.yml b/3rdparty/mbedtls/mbedtls/circle.yml deleted file mode 100644 index eaed02a815..0000000000 --- a/3rdparty/mbedtls/mbedtls/circle.yml +++ /dev/null @@ -1,44 +0,0 @@ -# Purpose: -# - To test and prove that a new commit in the mbed TLS repository builds -# and integrates with mbed-os properly. -# AND -# - To test and prove that the current development head of mbed TLS builds -# and integrates with the current mbed-os master branch. -# -# The script fetches all the prerequisites and builds the mbed TLS 'tls-client' -# example. This script is triggered by every commit and once each night and the -# exact behaviour depends on how it was triggered: -# - If it is a nightly build then it builds the mbed TLS development head with -# mbed-os master. -# - If it was triggered by the commit, then it builds the example with mbed TLS -# at that commit and mbed-os at the commit pointed by mbed-os.lib in the -# example repository. - -test: - override: - - cd ../mbed-os-example-tls/tls-client/ && mbed compile -m K64F -t GCC_ARM -c - -dependencies: - pre: - # Install gcc-arm - - cd .. && wget "https://launchpad.net/gcc-arm-embedded/4.9/4.9-2015-q3-update/+download/gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2" - - cd .. && tar -xvjf gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2 - - ln -s ../gcc-arm-none-eabi-4_9-2015q3/bin/* ../bin/ - # Install mbed-cli - - cd ../ && git clone https://github.com/ARMmbed/mbed-cli.git - - cd ../mbed-cli && sudo -H pip install -e . - # Get the sample application - - cd ../ && git clone git@github.com:ARMmbed/mbed-os-example-tls.git - # Get mbed-os - - cd ../mbed-os-example-tls/tls-client && mbed deploy - # Update mbed-os to master only if it is a nightly build - - > - if [ -n "${RUN_NIGHTLY_BUILD}" ]; then - cd ../mbed-os-example-tls/tls-client/mbed-os/ && mbed update master; - fi - # Import mbedtls current revision - - ln -s ../../../../../../../mbedtls/ ../mbed-os-example-tls/tls-client/mbed-os/features/mbedtls/importer/TARGET_IGNORE/mbedtls - - cd ../mbed-os-example-tls/tls-client/mbed-os/features/mbedtls/importer/ && make - override: - # Install the missing python packages - - cd ../mbed-os-example-tls/tls-client/mbed-os/ && sudo -H pip install -r requirements.txt diff --git a/3rdparty/mbedtls/mbedtls/doxygen/input/doc_mainpage.h b/3rdparty/mbedtls/mbedtls/doxygen/input/doc_mainpage.h index 0038615fef..bb5987137c 100644 --- a/3rdparty/mbedtls/mbedtls/doxygen/input/doc_mainpage.h +++ b/3rdparty/mbedtls/mbedtls/doxygen/input/doc_mainpage.h @@ -24,7 +24,7 @@ */ /** - * @mainpage mbed TLS v2.7.9 source code documentation + * @mainpage mbed TLS v2.7.11 source code documentation * * This documentation describes the internal structure of mbed TLS. It was * automatically generated from specially formatted comment blocks in diff --git a/3rdparty/mbedtls/mbedtls/doxygen/mbedtls.doxyfile b/3rdparty/mbedtls/mbedtls/doxygen/mbedtls.doxyfile index 54e446398c..22ae878ee8 100644 --- a/3rdparty/mbedtls/mbedtls/doxygen/mbedtls.doxyfile +++ b/3rdparty/mbedtls/mbedtls/doxygen/mbedtls.doxyfile @@ -28,7 +28,7 @@ DOXYFILE_ENCODING = UTF-8 # identify the project. Note that if you do not use Doxywizard you need # to put quotes around the project name if it contains spaces. -PROJECT_NAME = "mbed TLS v2.7.9" +PROJECT_NAME = "mbed TLS v2.7.11" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or diff --git a/3rdparty/mbedtls/mbedtls/include/CMakeLists.txt b/3rdparty/mbedtls/mbedtls/include/CMakeLists.txt index 1b581a54dd..c2f2bd4e6f 100644 --- a/3rdparty/mbedtls/mbedtls/include/CMakeLists.txt +++ b/3rdparty/mbedtls/mbedtls/include/CMakeLists.txt @@ -11,6 +11,6 @@ if(INSTALL_MBEDTLS_HEADERS) endif(INSTALL_MBEDTLS_HEADERS) # Make config.h available in an out-of-source build. ssl-opt.sh requires it. -if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) +if (ENABLE_TESTING AND NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) link_to_source(mbedtls) endif() diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/aesni.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/aesni.h index 746baa0e17..7b16b4bad0 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/aesni.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/aesni.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_AESNI_H #define MBEDTLS_AESNI_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "aes.h" #define MBEDTLS_AESNI_AES 0x02000000u diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/asn1write.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/asn1write.h index f76fc807d0..083601af32 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/asn1write.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/asn1write.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_ASN1_WRITE_H #define MBEDTLS_ASN1_WRITE_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "asn1.h" #define MBEDTLS_ASN1_CHK_ADD(g, f) do { if( ( ret = f ) < 0 ) return( ret ); else \ @@ -183,24 +189,27 @@ int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start, const char *text, size_t text_len ); /** - * \brief Write a bitstring tag (MBEDTLS_ASN1_BIT_STRING) and - * value in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write a bitstring tag (#MBEDTLS_ASN1_BIT_STRING) and + * value in ASN.1 format. * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param buf the bitstring - * \param bits the total number of bits in the bitstring + * \note This function works backwards in data buffer. * - * \return the length written or a negative error code + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param buf The bitstring to write. + * \param bits The total number of bits in the bitstring. + * + * \return The number of bytes written to \p p on success. + * \return A negative error code on failure. */ int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start, const unsigned char *buf, size_t bits ); /** - * \brief Write an octet string tag (MBEDTLS_ASN1_OCTET_STRING) and - * value in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write an octet string tag (#MBEDTLS_ASN1_OCTET_STRING) + * and value in ASN.1 format. + * + * \note This function works backwards in data buffer. * * \param p reference to current position pointer * \param start start of the buffer (for bounds-checking) diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/base64.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/base64.h index 7a64f52163..10e4145ee6 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/base64.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/base64.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_BASE64_H #define MBEDTLS_BASE64_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include #define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/bn_mul.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/bn_mul.h index 80e4b380d1..3a254aae9d 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/bn_mul.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/bn_mul.h @@ -38,6 +38,12 @@ #ifndef MBEDTLS_BN_MUL_H #define MBEDTLS_BN_MUL_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "bignum.h" #if defined(MBEDTLS_HAVE_ASM) @@ -734,7 +740,7 @@ "sw $10, %2 \n\t" \ : "=m" (c), "=m" (d), "=m" (s) \ : "m" (s), "m" (d), "m" (c), "m" (b) \ - : "$9", "$10", "$11", "$12", "$13", "$14", "$15" \ + : "$9", "$10", "$11", "$12", "$13", "$14", "$15", "lo", "hi" \ ); #endif /* MIPS */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ccm.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ccm.h index 630b7fdf6c..e311e751d5 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ccm.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ccm.h @@ -34,6 +34,12 @@ #ifndef MBEDTLS_CCM_H #define MBEDTLS_CCM_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "cipher.h" #define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to the function. */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/certs.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/certs.h index 8dab7b5ce8..b7c5708f85 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/certs.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/certs.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_CERTS_H #define MBEDTLS_CERTS_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include #ifdef __cplusplus diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/cmac.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/cmac.h index 24839a20eb..adfe1c3e01 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/cmac.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/cmac.h @@ -26,6 +26,12 @@ #ifndef MBEDTLS_CMAC_H #define MBEDTLS_CMAC_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "cipher.h" #ifdef __cplusplus diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/compat-1.3.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/compat-1.3.h index 600a0f154c..94de845dd8 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/compat-1.3.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/compat-1.3.h @@ -25,6 +25,12 @@ * This file is part of mbed TLS (https://tls.mbed.org) */ +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #if ! defined(MBEDTLS_DEPRECATED_REMOVED) #if defined(MBEDTLS_DEPRECATED_WARNING) diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/config.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/config.h index 50239e1ff5..f3039f937f 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/config.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/config.h @@ -556,6 +556,26 @@ */ #define MBEDTLS_REMOVE_ARC4_CIPHERSUITES +/** + * \def MBEDTLS_REMOVE_3DES_CIPHERSUITES + * + * Remove 3DES ciphersuites by default in SSL / TLS. + * This flag removes the ciphersuites based on 3DES from the default list as + * returned by mbedtls_ssl_list_ciphersuites(). However, it is still possible + * to enable (some of) them with mbedtls_ssl_conf_ciphersuites() by including + * them explicitly. + * + * A man-in-the-browser attacker can recover authentication tokens sent through + * a TLS connection using a 3DES based cipher suite (see "On the Practical + * (In-)Security of 64-bit Block Ciphers" by Karthikeyan Bhargavan and GaĆ«tan + * Leurent, see https://sweet32.info/SWEET32_CCS16.pdf). If this attack falls + * in your threat model or you are unsure, then you should keep this option + * enabled to remove 3DES based cipher suites. + * + * Comment this macro to keep 3DES in the default ciphersuite list. + */ +#define MBEDTLS_REMOVE_3DES_CIPHERSUITES + /** * \def MBEDTLS_ECP_DP_SECP192R1_ENABLED * diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h index 2b4dc73d3f..5a32843152 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h @@ -28,6 +28,12 @@ #ifndef MBEDTLS_CTR_DRBG_H #define MBEDTLS_CTR_DRBG_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "aes.h" #if defined(MBEDTLS_THREADING_C) diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdh.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdh.h index 99cfde00d0..d16bad2d8e 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdh.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdh.h @@ -33,6 +33,12 @@ #ifndef MBEDTLS_ECDH_H #define MBEDTLS_ECDH_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "ecp.h" #ifdef __cplusplus diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdsa.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdsa.h index ff6efbc3ff..cfd1370120 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdsa.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdsa.h @@ -31,6 +31,12 @@ #ifndef MBEDTLS_ECDSA_H #define MBEDTLS_ECDSA_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "ecp.h" #include "md.h" diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecjpake.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecjpake.h index d86e8207f1..8d09bf2293 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecjpake.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecjpake.h @@ -40,6 +40,11 @@ * The payloads are serialized in a way suitable for use in TLS, but could * also be use outside TLS. */ +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif #include "ecp.h" #include "md.h" diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp.h index 7b8ffff44e..6c43c00693 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_ECP_H #define MBEDTLS_ECP_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "bignum.h" /* diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp_internal.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp_internal.h index 18040697ad..7625ed48e1 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp_internal.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp_internal.h @@ -61,6 +61,12 @@ #ifndef MBEDTLS_ECP_INTERNAL_H #define MBEDTLS_ECP_INTERNAL_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #if defined(MBEDTLS_ECP_INTERNAL_ALT) /** diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/error.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/error.h index 8b4d3a8755..ef22bc6842 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/error.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/error.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_ERROR_H #define MBEDTLS_ERROR_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include /** diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/gcm.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/gcm.h index 00ed42190c..bd258aae54 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/gcm.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/gcm.h @@ -31,6 +31,12 @@ #ifndef MBEDTLS_GCM_H #define MBEDTLS_GCM_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "cipher.h" #include diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/havege.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/havege.h index d4cb3ed38d..e6bf6fae8e 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/havege.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/havege.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_HAVEGE_H #define MBEDTLS_HAVEGE_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include #define MBEDTLS_HAVEGE_COLLECT_SIZE 1024 diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h index dd31fc8fdd..f58b1e31d8 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_HMAC_DRBG_H #define MBEDTLS_HMAC_DRBG_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "md.h" #if defined(MBEDTLS_THREADING_C) diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/net.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/net.h index 6c13b53fb9..8cead58e5d 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/net.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/net.h @@ -23,6 +23,11 @@ * * This file is part of mbed TLS (https://tls.mbed.org) */ +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif #if !defined(MBEDTLS_DEPRECATED_REMOVED) #include "net_sockets.h" diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/padlock.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/padlock.h index 677936ebf8..918e6195ad 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/padlock.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/padlock.h @@ -25,6 +25,12 @@ #ifndef MBEDTLS_PADLOCK_H #define MBEDTLS_PADLOCK_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "aes.h" #define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/pem.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/pem.h index 2cf4c0a709..81918503e9 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/pem.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/pem.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_PEM_H #define MBEDTLS_PEM_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include /** diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs12.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs12.h index 69f04177c8..d441357b7f 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs12.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs12.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_PKCS12_H #define MBEDTLS_PKCS12_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "md.h" #include "cipher.h" #include "asn1.h" diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs5.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs5.h index d4bb36dfae..f201250046 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs5.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs5.h @@ -26,6 +26,12 @@ #ifndef MBEDTLS_PKCS5_H #define MBEDTLS_PKCS5_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "asn1.h" #include "md.h" diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl.h index 5593a5282a..5fd6969da9 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl.h @@ -2106,12 +2106,27 @@ void mbedtls_ssl_conf_cert_req_ca_list( mbedtls_ssl_config *conf, #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH) /** - * \brief Set the maximum fragment length to emit and/or negotiate - * (Default: MBEDTLS_SSL_MAX_CONTENT_LEN, usually 2^14 bytes) + * \brief Set the maximum fragment length to emit and/or negotiate. + * (Typical: #MBEDTLS_SSL_MAX_CONTENT_LEN, by default that is + * set to `2^14` bytes) * (Server: set maximum fragment length to emit, - * usually negotiated by the client during handshake + * usually negotiated by the client during handshake) * (Client: set maximum fragment length to emit *and* * negotiate with the server during handshake) + * (Default: #MBEDTLS_SSL_MAX_FRAG_LEN_NONE) + * + * \note With TLS, this currently only affects ApplicationData (sent + * with \c mbedtls_ssl_read()), not handshake messages. + * With DTLS, this affects both ApplicationData and handshake. + * + * \note On the client side, the maximum fragment length extension + * *will not* be used, unless the maximum fragment length has + * been set via this function to a value different than + * #MBEDTLS_SSL_MAX_FRAG_LEN_NONE. + * + * \note This sets the maximum length for a record's payload, + * excluding record overhead that will be added to it, see + * \c mbedtls_ssl_get_record_expansion(). * * \param conf SSL configuration * \param mfl_code Code for maximum fragment length (allowed values: diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_cache.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_cache.h index ec081e6d24..52ba0948c5 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_cache.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_cache.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_SSL_CACHE_H #define MBEDTLS_SSL_CACHE_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "ssl.h" #if defined(MBEDTLS_THREADING_C) diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_ciphersuites.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_ciphersuites.h index 1d2aabc372..655d130b7c 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_ciphersuites.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_ciphersuites.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_SSL_CIPHERSUITES_H #define MBEDTLS_SSL_CIPHERSUITES_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "pk.h" #include "cipher.h" #include "md.h" diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_cookie.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_cookie.h index 80b65bbbb9..6a7ff9c757 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_cookie.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_cookie.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_SSL_COOKIE_H #define MBEDTLS_SSL_COOKIE_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "ssl.h" #if defined(MBEDTLS_THREADING_C) diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_internal.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_internal.h index 2b5a61637b..168d4a2568 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_internal.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_internal.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_SSL_INTERNAL_H #define MBEDTLS_SSL_INTERNAL_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + #include "ssl.h" #include "cipher.h" diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_ticket.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_ticket.h index 93ad46ac9c..ff7eccbb8c 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_ticket.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ssl_ticket.h @@ -24,6 +24,12 @@ #ifndef MBEDTLS_SSL_TICKET_H #define MBEDTLS_SSL_TICKET_H +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + /* * This implementation of the session ticket callbacks includes key * management, rotating the keys periodically in order to preserve forward diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/version.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/version.h index 36feff0d82..79b651387a 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/version.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/version.h @@ -40,16 +40,16 @@ */ #define MBEDTLS_VERSION_MAJOR 2 #define MBEDTLS_VERSION_MINOR 7 -#define MBEDTLS_VERSION_PATCH 9 +#define MBEDTLS_VERSION_PATCH 11 /** * The single version number has the following structure: * MMNNPP00 * Major version | Minor version | Patch version */ -#define MBEDTLS_VERSION_NUMBER 0x02070900 -#define MBEDTLS_VERSION_STRING "2.7.9" -#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.7.9" +#define MBEDTLS_VERSION_NUMBER 0x02070B00 +#define MBEDTLS_VERSION_STRING "2.7.11" +#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.7.11" #if defined(MBEDTLS_VERSION_C) diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/x509_crt.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/x509_crt.h index 2c3c758e9e..e72231ee8c 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/x509_crt.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/x509_crt.h @@ -98,7 +98,7 @@ mbedtls_x509_crt; * Build flag from an algorithm/curve identifier (pk, md, ecp) * Since 0 is always XXX_NONE, ignore it. */ -#define MBEDTLS_X509_ID_FLAG( id ) ( 1 << ( id - 1 ) ) +#define MBEDTLS_X509_ID_FLAG( id ) ( 1 << ( ( id ) - 1 ) ) /** * Security profile for certificate verification. diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/x509_csr.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/x509_csr.h index 0c6ccad78d..a3c28048e0 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/x509_csr.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/x509_csr.h @@ -205,6 +205,14 @@ void mbedtls_x509write_csr_set_md_alg( mbedtls_x509write_csr *ctx, mbedtls_md_ty * \param key_usage key usage flags to set * * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED + * + * \note The decipherOnly flag from the Key Usage + * extension is represented by bit 8 (i.e. + * 0x8000), which cannot typically be represented + * in an unsigned char. Therefore, the flag + * decipherOnly (i.e. + * #MBEDTLS_X509_KU_DECIPHER_ONLY) cannot be set using this + * function. */ int mbedtls_x509write_csr_set_key_usage( mbedtls_x509write_csr *ctx, unsigned char key_usage ); diff --git a/3rdparty/mbedtls/mbedtls/library/CMakeLists.txt b/3rdparty/mbedtls/mbedtls/library/CMakeLists.txt index 59df9589a4..f1c9a59d9a 100644 --- a/3rdparty/mbedtls/mbedtls/library/CMakeLists.txt +++ b/3rdparty/mbedtls/mbedtls/library/CMakeLists.txt @@ -91,6 +91,12 @@ if(CMAKE_COMPILER_IS_CLANG) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code") endif(CMAKE_COMPILER_IS_CLANG) +if(UNSAFE_BUILD) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error") + set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_ASAN} -Wno-error") + set(CMAKE_C_FLAGS_ASANDBG "${CMAKE_C_FLAGS_ASANDBG} -Wno-error") +endif(UNSAFE_BUILD) + if(WIN32) set(libs ${libs} ws2_32) endif(WIN32) @@ -141,15 +147,15 @@ endif(USE_STATIC_MBEDTLS_LIBRARY) if(USE_SHARED_MBEDTLS_LIBRARY) add_library(mbedcrypto SHARED ${src_crypto}) - set_target_properties(mbedcrypto PROPERTIES VERSION 2.7.9 SOVERSION 2) + set_target_properties(mbedcrypto PROPERTIES VERSION 2.7.11 SOVERSION 2) target_link_libraries(mbedcrypto ${libs}) add_library(mbedx509 SHARED ${src_x509}) - set_target_properties(mbedx509 PROPERTIES VERSION 2.7.9 SOVERSION 0) + set_target_properties(mbedx509 PROPERTIES VERSION 2.7.11 SOVERSION 0) target_link_libraries(mbedx509 ${libs} mbedcrypto) add_library(mbedtls SHARED ${src_tls}) - set_target_properties(mbedtls PROPERTIES VERSION 2.7.9 SOVERSION 10) + set_target_properties(mbedtls PROPERTIES VERSION 2.7.11 SOVERSION 10) target_link_libraries(mbedtls ${libs} mbedx509) install(TARGETS mbedtls mbedx509 mbedcrypto diff --git a/3rdparty/mbedtls/mbedtls/library/asn1write.c b/3rdparty/mbedtls/mbedtls/library/asn1write.c index c13e85e56a..b451887ed3 100644 --- a/3rdparty/mbedtls/mbedtls/library/asn1write.c +++ b/3rdparty/mbedtls/mbedtls/library/asn1write.c @@ -294,22 +294,28 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start, const unsigned char *buf, size_t bits ) { int ret; - size_t len = 0, size; + size_t len = 0; + size_t unused_bits, byte_len; - size = ( bits / 8 ) + ( ( bits % 8 ) ? 1 : 0 ); + byte_len = ( bits + 7 ) / 8; + unused_bits = ( byte_len * 8 ) - bits; - // Calculate byte length - // - if( *p < start || (size_t)( *p - start ) < size + 1 ) + if( *p < start || (size_t)( *p - start ) < byte_len + 1 ) return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); - len = size + 1; - (*p) -= size; - memcpy( *p, buf, size ); + len = byte_len + 1; - // Write unused bits - // - *--(*p) = (unsigned char) (size * 8 - bits); + /* Write the bitstring. Ensure the unused bits are zeroed */ + if( byte_len > 0 ) + { + byte_len--; + *--( *p ) = buf[byte_len] & ~( ( 0x1 << unused_bits ) - 1 ); + ( *p ) -= byte_len; + memcpy( *p, buf, byte_len ); + } + + /* Write unused bits */ + *--( *p ) = (unsigned char)unused_bits; MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, MBEDTLS_ASN1_BIT_STRING ) ); diff --git a/3rdparty/mbedtls/mbedtls/library/bignum.c b/3rdparty/mbedtls/mbedtls/library/bignum.c index 18daea2589..d142fe69b8 100644 --- a/3rdparty/mbedtls/mbedtls/library/bignum.c +++ b/3rdparty/mbedtls/mbedtls/library/bignum.c @@ -500,26 +500,38 @@ int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s ) } /* - * Helper to write the digits high-order first + * Helper to write the digits high-order first. */ -static int mpi_write_hlp( mbedtls_mpi *X, int radix, char **p ) +static int mpi_write_hlp( mbedtls_mpi *X, int radix, + char **p, const size_t buflen ) { int ret; mbedtls_mpi_uint r; + size_t length = 0; + char *p_end = *p + buflen; - if( radix < 2 || radix > 16 ) - return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + do + { + if( length >= buflen ) + { + return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); + } - MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, radix ) ); - MBEDTLS_MPI_CHK( mbedtls_mpi_div_int( X, NULL, X, radix ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, radix ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_div_int( X, NULL, X, radix ) ); + /* + * Write the residue in the current position, as an ASCII character. + */ + if( r < 0xA ) + *(--p_end) = (char)( '0' + r ); + else + *(--p_end) = (char)( 'A' + ( r - 0xA ) ); - if( mbedtls_mpi_cmp_int( X, 0 ) != 0 ) - MBEDTLS_MPI_CHK( mpi_write_hlp( X, radix, p ) ); + length++; + } while( mbedtls_mpi_cmp_int( X, 0 ) != 0 ); - if( r < 10 ) - *(*p)++ = (char)( r + 0x30 ); - else - *(*p)++ = (char)( r + 0x37 ); + memmove( *p, p_end, length ); + *p += length; cleanup: @@ -540,15 +552,20 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix, if( radix < 2 || radix > 16 ) return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); - n = mbedtls_mpi_bitlen( X ); - if( radix >= 4 ) n >>= 1; - if( radix >= 16 ) n >>= 1; - /* - * Round up the buffer length to an even value to ensure that there is - * enough room for hexadecimal values that can be represented in an odd - * number of digits. - */ - n += 3 + ( ( n + 1 ) & 1 ); + n = mbedtls_mpi_bitlen( X ); /* Number of bits necessary to present `n`. */ + if( radix >= 4 ) n >>= 1; /* Number of 4-adic digits necessary to present + * `n`. If radix > 4, this might be a strict + * overapproximation of the number of + * radix-adic digits needed to present `n`. */ + if( radix >= 16 ) n >>= 1; /* Number of hexadecimal digits necessary to + * present `n`. */ + + n += 1; /* Terminating null byte */ + n += 1; /* Compensate for the divisions above, which round down `n` + * in case it's not even. */ + n += 1; /* Potential '-'-sign. */ + n += ( n & 1 ); /* Make n even to have enough space for hexadecimal writing, + * which always uses an even number of hex-digits. */ if( buflen < n ) { @@ -560,7 +577,10 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix, mbedtls_mpi_init( &T ); if( X->s == -1 ) + { *p++ = '-'; + buflen--; + } if( radix == 16 ) { @@ -589,7 +609,7 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix, if( T.s == -1 ) T.s = 1; - MBEDTLS_MPI_CHK( mpi_write_hlp( &T, radix, &p ) ); + MBEDTLS_MPI_CHK( mpi_write_hlp( &T, radix, &p, buflen ) ); } *p++ = '\0'; @@ -1667,8 +1687,10 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi wsize = ( i > 671 ) ? 6 : ( i > 239 ) ? 5 : ( i > 79 ) ? 4 : ( i > 23 ) ? 3 : 1; +#if( MBEDTLS_MPI_WINDOW_SIZE < 6 ) if( wsize > MBEDTLS_MPI_WINDOW_SIZE ) wsize = MBEDTLS_MPI_WINDOW_SIZE; +#endif j = N->n + 1; MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, j ) ); diff --git a/3rdparty/mbedtls/mbedtls/library/certs.c b/3rdparty/mbedtls/mbedtls/library/certs.c index f1379b8cb1..2c6fbdfedb 100644 --- a/3rdparty/mbedtls/mbedtls/library/certs.c +++ b/3rdparty/mbedtls/mbedtls/library/certs.c @@ -116,7 +116,6 @@ const size_t mbedtls_test_cli_key_ec_len = sizeof( mbedtls_test_cli_key_ec ); #endif /* MBEDTLS_ECDSA_C */ #if defined(MBEDTLS_RSA_C) - #if defined(MBEDTLS_SHA256_C) #define TEST_CA_CRT_RSA_SHA256 \ "-----BEGIN CERTIFICATE-----\r\n" \ @@ -141,13 +140,11 @@ const size_t mbedtls_test_cli_key_ec_len = sizeof( mbedtls_test_cli_key_ec ); "n20NRVA1Vjs6GAROr4NqW4k/+LofY9y0LLDE+p0oIEKXIsIvhPr39swxSA==\r\n" \ "-----END CERTIFICATE-----\r\n" +static const char mbedtls_test_ca_crt_rsa_sha256[] = TEST_CA_CRT_RSA_SHA256; const char mbedtls_test_ca_crt_rsa[] = TEST_CA_CRT_RSA_SHA256; const size_t mbedtls_test_ca_crt_rsa_len = sizeof( mbedtls_test_ca_crt_rsa ); #define TEST_CA_CRT_RSA_SOME - -static const char mbedtls_test_ca_crt_rsa_sha256[] = TEST_CA_CRT_RSA_SHA256; - -#endif +#endif /* MBEDTLS_SHA256_C */ #if !defined(TEST_CA_CRT_RSA_SOME) || defined(MBEDTLS_SHA1_C) #define TEST_CA_CRT_RSA_SHA1 \ @@ -173,14 +170,72 @@ static const char mbedtls_test_ca_crt_rsa_sha256[] = TEST_CA_CRT_RSA_SHA256; "7Z2mCGDNMhjQc+BYcdnl0lPXjdDK6V0qCg1dVewhUBcW5gZKzV7e9+DpVA==\r\n" \ "-----END CERTIFICATE-----\r\n" +static const char mbedtls_test_ca_crt_rsa_sha1[] = TEST_CA_CRT_RSA_SHA1; + #if !defined (TEST_CA_CRT_RSA_SOME) const char mbedtls_test_ca_crt_rsa[] = TEST_CA_CRT_RSA_SHA1; const size_t mbedtls_test_ca_crt_rsa_len = sizeof( mbedtls_test_ca_crt_rsa ); -#endif +#endif /* !TEST_CA_CRT_RSA_SOME */ +#endif /* !TEST_CA_CRT_RSA_COME || MBEDTLS_SHA1_C */ -static const char mbedtls_test_ca_crt_rsa_sha1[] = TEST_CA_CRT_RSA_SHA1; +#if defined(MBEDTLS_SHA256_C) +/* tests/data_files/server2-sha256.crt */ +#define TEST_SRV_CRT_RSA_SHA256 \ +"-----BEGIN CERTIFICATE-----\r\n" \ +"MIIDNzCCAh+gAwIBAgIBAjANBgkqhkiG9w0BAQsFADA7MQswCQYDVQQGEwJOTDER\r\n" \ +"MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \ +"MTEwMjEyMTQ0NDA2WhcNMjEwMjEyMTQ0NDA2WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n" \ +"A1UECgwIUG9sYXJTU0wxEjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcN\r\n" \ +"AQEBBQADggEPADCCAQoCggEBAMFNo93nzR3RBNdJcriZrA545Do8Ss86ExbQWuTN\r\n" \ +"owCIp+4ea5anUrSQ7y1yej4kmvy2NKwk9XfgJmSMnLAofaHa6ozmyRyWvP7BBFKz\r\n" \ +"NtSj+uGxdtiQwWG0ZlI2oiZTqqt0Xgd9GYLbKtgfoNkNHC1JZvdbJXNG6AuKT2kM\r\n" \ +"tQCQ4dqCEGZ9rlQri2V5kaHiYcPNQEkI7mgM8YuG0ka/0LiqEQMef1aoGh5EGA8P\r\n" \ +"hYvai0Re4hjGYi/HZo36Xdh98yeJKQHFkA4/J/EwyEoO79bex8cna8cFPXrEAjya\r\n" \ +"HT4P6DSYW8tzS1KW2BGiLICIaTla0w+w3lkvEcf36hIBMJcCAwEAAaNNMEswCQYD\r\n" \ +"VR0TBAIwADAdBgNVHQ4EFgQUpQXoZLjc32APUBJNYKhkr02LQ5MwHwYDVR0jBBgw\r\n" \ +"FoAUtFrkpbPe0lL2udWmlQ/rPrzH/f8wDQYJKoZIhvcNAQELBQADggEBAGGEshT5\r\n" \ +"kvnRmLVScVeUEdwIrvW7ezbGbUvJ8VxeJ79/HSjlLiGbMc4uUathwtzEdi9R/4C5\r\n" \ +"DXBNeEPTkbB+fhG1W06iHYj/Dp8+aaG7fuDxKVKHVZSqBnmQLn73ymyclZNHii5A\r\n" \ +"3nTS8WUaHAzxN/rajOtoM7aH1P9tULpHrl+7HOeLMpxUnwI12ZqZaLIzxbcdJVcr\r\n" \ +"ra2F00aXCGkYVLvyvbZIq7LC+yVysej5gCeQYD7VFOEks0jhFjrS06gP0/XnWv6v\r\n" \ +"eBoPez9d+CCjkrhseiWzXOiriIMICX48EloO/DrsMRAtvlwq7EDz4QhILz6ffndm\r\n" \ +"e4K1cVANRPN2o9Y=\r\n" \ +"-----END CERTIFICATE-----\r\n" -#endif +const char mbedtls_test_srv_crt_rsa[] = TEST_SRV_CRT_RSA_SHA256; +const size_t mbedtls_test_srv_crt_rsa_len = sizeof( mbedtls_test_srv_crt_rsa ); +#define TEST_SRV_CRT_RSA_SOME +#endif /* MBEDTLS_SHA256_C */ + +#if !defined(TEST_SRV_CRT_RSA_SOME) || defined(MBEDTLS_SHA1_C) +/* tests/data_files/server2.crt */ +#define TEST_SRV_CRT_RSA_SHA1 \ +"-----BEGIN CERTIFICATE-----\r\n" \ +"MIIDNzCCAh+gAwIBAgIBAjANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGEwJOTDER\r\n" \ +"MA8GA1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" \ +"MTEwMjEyMTQ0NDA2WhcNMjEwMjEyMTQ0NDA2WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n" \ +"A1UEChMIUG9sYXJTU0wxEjAQBgNVBAMTCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcN\r\n" \ +"AQEBBQADggEPADCCAQoCggEBAMFNo93nzR3RBNdJcriZrA545Do8Ss86ExbQWuTN\r\n" \ +"owCIp+4ea5anUrSQ7y1yej4kmvy2NKwk9XfgJmSMnLAofaHa6ozmyRyWvP7BBFKz\r\n" \ +"NtSj+uGxdtiQwWG0ZlI2oiZTqqt0Xgd9GYLbKtgfoNkNHC1JZvdbJXNG6AuKT2kM\r\n" \ +"tQCQ4dqCEGZ9rlQri2V5kaHiYcPNQEkI7mgM8YuG0ka/0LiqEQMef1aoGh5EGA8P\r\n" \ +"hYvai0Re4hjGYi/HZo36Xdh98yeJKQHFkA4/J/EwyEoO79bex8cna8cFPXrEAjya\r\n" \ +"HT4P6DSYW8tzS1KW2BGiLICIaTla0w+w3lkvEcf36hIBMJcCAwEAAaNNMEswCQYD\r\n" \ +"VR0TBAIwADAdBgNVHQ4EFgQUpQXoZLjc32APUBJNYKhkr02LQ5MwHwYDVR0jBBgw\r\n" \ +"FoAUtFrkpbPe0lL2udWmlQ/rPrzH/f8wDQYJKoZIhvcNAQEFBQADggEBAJxnXClY\r\n" \ +"oHkbp70cqBrsGXLybA74czbO5RdLEgFs7rHVS9r+c293luS/KdliLScZqAzYVylw\r\n" \ +"UfRWvKMoWhHYKp3dEIS4xTXk6/5zXxhv9Rw8SGc8qn6vITHk1S1mPevtekgasY5Y\r\n" \ +"iWQuM3h4YVlRH3HHEMAD1TnAexfXHHDFQGe+Bd1iAbz1/sH9H8l4StwX6egvTK3M\r\n" \ +"wXRwkKkvjKaEDA9ATbZx0mI8LGsxSuCqe9r9dyjmttd47J1p1Rulz3CLzaRcVIuS\r\n" \ +"RRQfaD8neM9c1S/iJ/amTVqJxA1KOdOS5780WhPfSArA+g4qAmSjelc3p4wWpha8\r\n" \ +"zhuYwjVuX6JHG0c=\r\n" \ +"-----END CERTIFICATE-----\r\n"; + +#if !defined(TEST_SRV_CRT_RSA_SOME) +const char mbedtls_test_srv_crt_rsa[] = TEST_SRV_CRT_RSA_SHA1; +const size_t mbedtls_test_srv_crt_rsa_len = sizeof( mbedtls_test_srv_crt_rsa ); +#endif /* TEST_SRV_CRT_RSA_SOME */ +#endif /* !TEST_CA_CRT_RSA_SOME || MBEDTLS_SHA1_C */ const char mbedtls_test_ca_key_rsa[] = "-----BEGIN RSA PRIVATE KEY-----\r\n" @@ -218,29 +273,6 @@ const size_t mbedtls_test_ca_key_rsa_len = sizeof( mbedtls_test_ca_key_rsa ); const char mbedtls_test_ca_pwd_rsa[] = "PolarSSLTest"; const size_t mbedtls_test_ca_pwd_rsa_len = sizeof( mbedtls_test_ca_pwd_rsa ) - 1; -const char mbedtls_test_srv_crt_rsa[] = -"-----BEGIN CERTIFICATE-----\r\n" -"MIIDNzCCAh+gAwIBAgIBAjANBgkqhkiG9w0BAQUFADA7MQswCQYDVQQGEwJOTDER\r\n" -"MA8GA1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwHhcN\r\n" -"MTEwMjEyMTQ0NDA2WhcNMjEwMjEyMTQ0NDA2WjA0MQswCQYDVQQGEwJOTDERMA8G\r\n" -"A1UEChMIUG9sYXJTU0wxEjAQBgNVBAMTCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcN\r\n" -"AQEBBQADggEPADCCAQoCggEBAMFNo93nzR3RBNdJcriZrA545Do8Ss86ExbQWuTN\r\n" -"owCIp+4ea5anUrSQ7y1yej4kmvy2NKwk9XfgJmSMnLAofaHa6ozmyRyWvP7BBFKz\r\n" -"NtSj+uGxdtiQwWG0ZlI2oiZTqqt0Xgd9GYLbKtgfoNkNHC1JZvdbJXNG6AuKT2kM\r\n" -"tQCQ4dqCEGZ9rlQri2V5kaHiYcPNQEkI7mgM8YuG0ka/0LiqEQMef1aoGh5EGA8P\r\n" -"hYvai0Re4hjGYi/HZo36Xdh98yeJKQHFkA4/J/EwyEoO79bex8cna8cFPXrEAjya\r\n" -"HT4P6DSYW8tzS1KW2BGiLICIaTla0w+w3lkvEcf36hIBMJcCAwEAAaNNMEswCQYD\r\n" -"VR0TBAIwADAdBgNVHQ4EFgQUpQXoZLjc32APUBJNYKhkr02LQ5MwHwYDVR0jBBgw\r\n" -"FoAUtFrkpbPe0lL2udWmlQ/rPrzH/f8wDQYJKoZIhvcNAQEFBQADggEBAJxnXClY\r\n" -"oHkbp70cqBrsGXLybA74czbO5RdLEgFs7rHVS9r+c293luS/KdliLScZqAzYVylw\r\n" -"UfRWvKMoWhHYKp3dEIS4xTXk6/5zXxhv9Rw8SGc8qn6vITHk1S1mPevtekgasY5Y\r\n" -"iWQuM3h4YVlRH3HHEMAD1TnAexfXHHDFQGe+Bd1iAbz1/sH9H8l4StwX6egvTK3M\r\n" -"wXRwkKkvjKaEDA9ATbZx0mI8LGsxSuCqe9r9dyjmttd47J1p1Rulz3CLzaRcVIuS\r\n" -"RRQfaD8neM9c1S/iJ/amTVqJxA1KOdOS5780WhPfSArA+g4qAmSjelc3p4wWpha8\r\n" -"zhuYwjVuX6JHG0c=\r\n" -"-----END CERTIFICATE-----\r\n"; -const size_t mbedtls_test_srv_crt_rsa_len = sizeof( mbedtls_test_srv_crt_rsa ); - const char mbedtls_test_srv_key_rsa[] = "-----BEGIN RSA PRIVATE KEY-----\r\n" "MIIEpAIBAAKCAQEAwU2j3efNHdEE10lyuJmsDnjkOjxKzzoTFtBa5M2jAIin7h5r\r\n" diff --git a/3rdparty/mbedtls/mbedtls/library/debug.c b/3rdparty/mbedtls/mbedtls/library/debug.c index db3924ac54..30c8c7bb81 100644 --- a/3rdparty/mbedtls/mbedtls/library/debug.c +++ b/3rdparty/mbedtls/mbedtls/library/debug.c @@ -86,8 +86,13 @@ void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level, char str[DEBUG_BUF_SIZE]; int ret; - if( NULL == ssl || NULL == ssl->conf || NULL == ssl->conf->f_dbg || level > debug_threshold ) + if( NULL == ssl || + NULL == ssl->conf || + NULL == ssl->conf->f_dbg || + level > debug_threshold ) + { return; + } va_start( argp, format ); #if defined(_WIN32) @@ -121,8 +126,13 @@ void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level, { char str[DEBUG_BUF_SIZE]; - if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold ) + if( NULL == ssl || + NULL == ssl->conf || + NULL == ssl->conf->f_dbg || + level > debug_threshold ) + { return; + } /* * With non-blocking I/O and examples that just retry immediately, @@ -146,8 +156,13 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level, char txt[17]; size_t i, idx = 0; - if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold ) + if( NULL == ssl || + NULL == ssl->conf || + NULL == ssl->conf->f_dbg || + level > debug_threshold ) + { return; + } mbedtls_snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n", text, (unsigned int) len ); @@ -199,8 +214,13 @@ void mbedtls_debug_print_ecp( const mbedtls_ssl_context *ssl, int level, { char str[DEBUG_BUF_SIZE]; - if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || level > debug_threshold ) + if( NULL == ssl || + NULL == ssl->conf || + NULL == ssl->conf->f_dbg || + level > debug_threshold ) + { return; + } mbedtls_snprintf( str, sizeof( str ), "%s(X)", text ); mbedtls_debug_print_mpi( ssl, level, file, line, str, &X->X ); @@ -219,8 +239,14 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level, int j, k, zeros = 1; size_t i, n, idx = 0; - if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || X == NULL || level > debug_threshold ) + if( NULL == ssl || + NULL == ssl->conf || + NULL == ssl->conf->f_dbg || + NULL == X || + level > debug_threshold ) + { return; + } for( n = X->n - 1; n > 0; n-- ) if( X->p[n] != 0 ) @@ -345,8 +371,14 @@ void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level, char str[DEBUG_BUF_SIZE]; int i = 0; - if( ssl->conf == NULL || ssl->conf->f_dbg == NULL || crt == NULL || level > debug_threshold ) + if( NULL == ssl || + NULL == ssl->conf || + NULL == ssl->conf->f_dbg || + NULL == crt || + level > debug_threshold ) + { return; + } while( crt != NULL ) { diff --git a/3rdparty/mbedtls/mbedtls/library/ecdh.c b/3rdparty/mbedtls/mbedtls/library/ecdh.c index 61380b6936..75630bd356 100644 --- a/3rdparty/mbedtls/mbedtls/library/ecdh.c +++ b/3rdparty/mbedtls/mbedtls/library/ecdh.c @@ -179,8 +179,20 @@ int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypai { int ret; - if( ( ret = mbedtls_ecp_group_copy( &ctx->grp, &key->grp ) ) != 0 ) - return( ret ); + if( ctx->grp.id == MBEDTLS_ECP_DP_NONE ) + { + /* This is the first call to get_params(). Copy the group information + * into the context. */ + if( ( ret = mbedtls_ecp_group_copy( &ctx->grp, &key->grp ) ) != 0 ) + return( ret ); + } + else + { + /* This is not the first call to get_params(). Check that the group + * is the same as the first time. */ + if( ctx->grp.id != key->grp.id ) + return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA ); + } /* If it's not our key, just import the public part as Qp */ if( side == MBEDTLS_ECDH_THEIRS ) diff --git a/3rdparty/mbedtls/mbedtls/library/ecdsa.c b/3rdparty/mbedtls/mbedtls/library/ecdsa.c index 17a88bdd29..ab75620b37 100644 --- a/3rdparty/mbedtls/mbedtls/library/ecdsa.c +++ b/3rdparty/mbedtls/mbedtls/library/ecdsa.c @@ -420,8 +420,13 @@ int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx, int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { - return( mbedtls_ecp_group_load( &ctx->grp, gid ) || - mbedtls_ecp_gen_keypair( &ctx->grp, &ctx->d, &ctx->Q, f_rng, p_rng ) ); + int ret = 0; + ret = mbedtls_ecp_group_load( &ctx->grp, gid ); + if( ret != 0 ) + return( ret ); + + return( mbedtls_ecp_gen_keypair( &ctx->grp, &ctx->d, + &ctx->Q, f_rng, p_rng ) ); } #endif /* MBEDTLS_ECDSA_GENKEY_ALT */ diff --git a/3rdparty/mbedtls/mbedtls/library/ssl_ciphersuites.c b/3rdparty/mbedtls/mbedtls/library/ssl_ciphersuites.c index 800b5f84d8..01d1c458a2 100644 --- a/3rdparty/mbedtls/mbedtls/library/ssl_ciphersuites.c +++ b/3rdparty/mbedtls/mbedtls/library/ssl_ciphersuites.c @@ -43,11 +43,11 @@ /* * Ordered from most preferred to least preferred in terms of security. * - * Current rule (except rc4, weak and null which come last): + * Current rule (except RC4 and 3DES, weak and null which come last): * 1. By key exchange: * Forward-secure non-PSK > forward-secure PSK > ECJPAKE > other non-PSK > other PSK * 2. By key length and cipher: - * AES-256 > Camellia-256 > AES-128 > Camellia-128 > 3DES + * AES-256 > Camellia-256 > AES-128 > Camellia-128 * 3. By cipher mode when relevant GCM > CCM > CBC > CCM_8 * 4. By hash function used when relevant * 5. By key exchange/auth again: EC > non-EC @@ -105,11 +105,6 @@ static const int ciphersuite_preference[] = MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256, MBEDTLS_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA, - /* All remaining >= 128-bit ephemeral suites */ - MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, - MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, - MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA, - /* The PSK ephemeral suites */ MBEDTLS_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_DHE_PSK_WITH_AES_256_CCM, @@ -133,9 +128,6 @@ static const int ciphersuite_preference[] = MBEDTLS_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256, MBEDTLS_TLS_DHE_PSK_WITH_AES_128_CCM_8, - MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA, - MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA, - /* The ECJPAKE suite */ MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8, @@ -183,11 +175,6 @@ static const int ciphersuite_preference[] = MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256, MBEDTLS_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256, - /* All remaining >= 128-bit suites */ - MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA, - MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, - MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, - /* The RSA PSK suites */ MBEDTLS_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384, @@ -201,8 +188,6 @@ static const int ciphersuite_preference[] = MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256, MBEDTLS_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256, - MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA, - /* The PSK suites */ MBEDTLS_TLS_PSK_WITH_AES_256_GCM_SHA384, MBEDTLS_TLS_PSK_WITH_AES_256_CCM, @@ -220,6 +205,16 @@ static const int ciphersuite_preference[] = MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256, MBEDTLS_TLS_PSK_WITH_AES_128_CCM_8, + /* 3DES suites */ + MBEDTLS_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_RSA_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, + MBEDTLS_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA, MBEDTLS_TLS_PSK_WITH_3DES_EDE_CBC_SHA, /* RC4 suites */ @@ -1704,6 +1699,26 @@ const int *mbedtls_ssl_list_ciphersuites( void ) static int supported_ciphersuites[MAX_CIPHERSUITES]; static int supported_init = 0; +static int ciphersuite_is_removed( const mbedtls_ssl_ciphersuite_t *cs_info ) +{ + (void)cs_info; + +#if defined(MBEDTLS_REMOVE_ARC4_CIPHERSUITES) + if( cs_info->cipher == MBEDTLS_CIPHER_ARC4_128 ) + return( 1 ); +#endif /* MBEDTLS_REMOVE_ARC4_CIPHERSUITES */ + +#if defined(MBEDTLS_REMOVE_3DES_CIPHERSUITES) + if( cs_info->cipher == MBEDTLS_CIPHER_DES_EDE3_ECB || + cs_info->cipher == MBEDTLS_CIPHER_DES_EDE3_CBC ) + { + return( 1 ); + } +#endif /* MBEDTLS_REMOVE_3DES_CIPHERSUITES */ + + return( 0 ); +} + const int *mbedtls_ssl_list_ciphersuites( void ) { /* @@ -1719,14 +1734,12 @@ const int *mbedtls_ssl_list_ciphersuites( void ) *p != 0 && q < supported_ciphersuites + MAX_CIPHERSUITES - 1; p++ ) { -#if defined(MBEDTLS_REMOVE_ARC4_CIPHERSUITES) const mbedtls_ssl_ciphersuite_t *cs_info; if( ( cs_info = mbedtls_ssl_ciphersuite_from_id( *p ) ) != NULL && - cs_info->cipher != MBEDTLS_CIPHER_ARC4_128 ) -#else - if( mbedtls_ssl_ciphersuite_from_id( *p ) != NULL ) -#endif + !ciphersuite_is_removed( cs_info ) ) + { *(q++) = *p; + } } *q = 0; diff --git a/3rdparty/mbedtls/mbedtls/library/ssl_tls.c b/3rdparty/mbedtls/mbedtls/library/ssl_tls.c index 6956b5f31b..1270ee9b85 100644 --- a/3rdparty/mbedtls/mbedtls/library/ssl_tls.c +++ b/3rdparty/mbedtls/mbedtls/library/ssl_tls.c @@ -3702,81 +3702,23 @@ static int ssl_parse_record_header( mbedtls_ssl_context *ssl ) return( MBEDTLS_ERR_SSL_INVALID_RECORD ); } - /* Check length against bounds of the current transform and version */ - if( ssl->transform_in == NULL ) - { - if( ssl->in_msglen < 1 || - ssl->in_msglen > MBEDTLS_SSL_MAX_CONTENT_LEN ) - { - MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad message length" ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); - } - } - else - { - if( ssl->in_msglen < ssl->transform_in->minlen ) - { - MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad message length" ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); - } - -#if defined(MBEDTLS_SSL_PROTO_SSL3) - if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 && - ssl->in_msglen > ssl->transform_in->minlen + MBEDTLS_SSL_MAX_CONTENT_LEN ) - { - MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad message length" ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); - } -#endif -#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \ - defined(MBEDTLS_SSL_PROTO_TLS1_2) - /* - * TLS encrypted messages can have up to 256 bytes of padding - */ - if( ssl->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 && - ssl->in_msglen > ssl->transform_in->minlen + - MBEDTLS_SSL_MAX_CONTENT_LEN + 256 ) - { - MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad message length" ) ); - return( MBEDTLS_ERR_SSL_INVALID_RECORD ); - } -#endif - } - /* - * DTLS-related tests done last, because most of them may result in - * silently dropping the record (but not the whole datagram), and we only - * want to consider that after ensuring that the "basic" fields (type, - * version, length) are sane. + * DTLS-related tests. + * Check epoch before checking length constraint because + * the latter varies with the epoch. E.g., if a ChangeCipherSpec + * message gets duplicated before the corresponding Finished message, + * the second ChangeCipherSpec should be discarded because it belongs + * to an old epoch, but not because its length is shorter than + * the minimum record length for packets using the new record transform. + * Note that these two kinds of failures are handled differently, + * as an unexpected record is silently skipped but an invalid + * record leads to the entire datagram being dropped. */ #if defined(MBEDTLS_SSL_PROTO_DTLS) if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) { unsigned int rec_epoch = ( ssl->in_ctr[0] << 8 ) | ssl->in_ctr[1]; - /* Drop unexpected ChangeCipherSpec messages */ - if( ssl->in_msgtype == MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC && - ssl->state != MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC && - ssl->state != MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC ) - { - MBEDTLS_SSL_DEBUG_MSG( 1, ( "dropping unexpected ChangeCipherSpec" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_RECORD ); - } - - /* Drop unexpected ApplicationData records, - * except at the beginning of renegotiations */ - if( ssl->in_msgtype == MBEDTLS_SSL_MSG_APPLICATION_DATA && - ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER -#if defined(MBEDTLS_SSL_RENEGOTIATION) - && ! ( ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && - ssl->state == MBEDTLS_SSL_SERVER_HELLO ) -#endif - ) - { - MBEDTLS_SSL_DEBUG_MSG( 1, ( "dropping unexpected ApplicationData" ) ); - return( MBEDTLS_ERR_SSL_UNEXPECTED_RECORD ); - } - /* Check epoch (and sequence number) with DTLS */ if( rec_epoch != ssl->in_epoch ) { @@ -3816,9 +3758,74 @@ static int ssl_parse_record_header( mbedtls_ssl_context *ssl ) return( MBEDTLS_ERR_SSL_UNEXPECTED_RECORD ); } #endif + + /* Drop unexpected ChangeCipherSpec messages */ + if( ssl->in_msgtype == MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC && + ssl->state != MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC && + ssl->state != MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC ) + { + MBEDTLS_SSL_DEBUG_MSG( 1, ( "dropping unexpected ChangeCipherSpec" ) ); + return( MBEDTLS_ERR_SSL_UNEXPECTED_RECORD ); + } + + /* Drop unexpected ApplicationData records, + * except at the beginning of renegotiations */ + if( ssl->in_msgtype == MBEDTLS_SSL_MSG_APPLICATION_DATA && + ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER +#if defined(MBEDTLS_SSL_RENEGOTIATION) + && ! ( ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS && + ssl->state == MBEDTLS_SSL_SERVER_HELLO ) +#endif + ) + { + MBEDTLS_SSL_DEBUG_MSG( 1, ( "dropping unexpected ApplicationData" ) ); + return( MBEDTLS_ERR_SSL_UNEXPECTED_RECORD ); + } } #endif /* MBEDTLS_SSL_PROTO_DTLS */ + + /* Check length against bounds of the current transform and version */ + if( ssl->transform_in == NULL ) + { + if( ssl->in_msglen < 1 || + ssl->in_msglen > MBEDTLS_SSL_MAX_CONTENT_LEN ) + { + MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad message length" ) ); + return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + } + } + else + { + if( ssl->in_msglen < ssl->transform_in->minlen ) + { + MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad message length" ) ); + return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + } + +#if defined(MBEDTLS_SSL_PROTO_SSL3) + if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 && + ssl->in_msglen > ssl->transform_in->minlen + MBEDTLS_SSL_MAX_CONTENT_LEN ) + { + MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad message length" ) ); + return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + } +#endif +#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1) || \ + defined(MBEDTLS_SSL_PROTO_TLS1_2) + /* + * TLS encrypted messages can have up to 256 bytes of padding + */ + if( ssl->minor_ver >= MBEDTLS_SSL_MINOR_VERSION_1 && + ssl->in_msglen > ssl->transform_in->minlen + + MBEDTLS_SSL_MAX_CONTENT_LEN + 256 ) + { + MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad message length" ) ); + return( MBEDTLS_ERR_SSL_INVALID_RECORD ); + } +#endif + } + return( 0 ); } diff --git a/3rdparty/mbedtls/mbedtls/library/version_features.c b/3rdparty/mbedtls/mbedtls/library/version_features.c index da47e3d753..d6deb01498 100644 --- a/3rdparty/mbedtls/mbedtls/library/version_features.c +++ b/3rdparty/mbedtls/mbedtls/library/version_features.c @@ -270,6 +270,9 @@ static const char *features[] = { #if defined(MBEDTLS_REMOVE_ARC4_CIPHERSUITES) "MBEDTLS_REMOVE_ARC4_CIPHERSUITES", #endif /* MBEDTLS_REMOVE_ARC4_CIPHERSUITES */ +#if defined(MBEDTLS_REMOVE_3DES_CIPHERSUITES) + "MBEDTLS_REMOVE_3DES_CIPHERSUITES", +#endif /* MBEDTLS_REMOVE_3DES_CIPHERSUITES */ #if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) "MBEDTLS_ECP_DP_SECP192R1_ENABLED", #endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */ diff --git a/3rdparty/mbedtls/mbedtls/library/x509.c b/3rdparty/mbedtls/mbedtls/library/x509.c index 264c7fb0c6..59b6ba3bdd 100644 --- a/3rdparty/mbedtls/mbedtls/library/x509.c +++ b/3rdparty/mbedtls/mbedtls/library/x509.c @@ -357,6 +357,8 @@ static int x509_get_attr_type_value( unsigned char **p, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) return( MBEDTLS_ERR_X509_INVALID_NAME + ret ); + end = *p + len; + if( ( end - *p ) < 1 ) return( MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA ); @@ -390,6 +392,12 @@ static int x509_get_attr_type_value( unsigned char **p, val->p = *p; *p += val->len; + if( *p != end ) + { + return( MBEDTLS_ERR_X509_INVALID_NAME + + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); + } + cur->next = NULL; return( 0 ); @@ -696,30 +704,25 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50 * be either manually updated or extensions should be parsed!) */ int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end, - mbedtls_x509_buf *ext, int tag ) + mbedtls_x509_buf *ext, int tag ) { int ret; size_t len; - if( *p == end ) - return( 0 ); - - ext->tag = **p; - - if( ( ret = mbedtls_asn1_get_tag( p, end, &ext->len, - MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag ) ) != 0 ) - return( ret ); + /* Extension structure use EXPLICIT tagging. That is, the actual + * `Extensions` structure is wrapped by a tag-length pair using + * the respective context-specific tag. */ + ret = mbedtls_asn1_get_tag( p, end, &ext->len, + MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag ); + if( ret != 0 ) + return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + ret ); - ext->p = *p; - end = *p + ext->len; + ext->tag = MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | tag; + ext->p = *p; + end = *p + ext->len; /* * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension - * - * Extension ::= SEQUENCE { - * extnID OBJECT IDENTIFIER, - * critical BOOLEAN DEFAULT FALSE, - * extnValue OCTET STRING } */ if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) @@ -1032,8 +1035,8 @@ int mbedtls_x509_time_is_future( const mbedtls_x509_time *from ) */ int mbedtls_x509_self_test( int verbose ) { + int ret = 0; #if defined(MBEDTLS_CERTS_C) && defined(MBEDTLS_SHA256_C) - int ret; uint32_t flags; mbedtls_x509_crt cacert; mbedtls_x509_crt clicert; @@ -1041,6 +1044,7 @@ int mbedtls_x509_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( " X.509 certificate load: " ); + mbedtls_x509_crt_init( &cacert ); mbedtls_x509_crt_init( &clicert ); ret = mbedtls_x509_crt_parse( &clicert, (const unsigned char *) mbedtls_test_cli_crt, @@ -1050,11 +1054,9 @@ int mbedtls_x509_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - return( ret ); + goto cleanup; } - mbedtls_x509_crt_init( &cacert ); - ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_test_ca_crt, mbedtls_test_ca_crt_len ); if( ret != 0 ) @@ -1062,7 +1064,7 @@ int mbedtls_x509_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - return( ret ); + goto cleanup; } if( verbose != 0 ) @@ -1074,20 +1076,19 @@ int mbedtls_x509_self_test( int verbose ) if( verbose != 0 ) mbedtls_printf( "failed\n" ); - return( ret ); + goto cleanup; } if( verbose != 0 ) mbedtls_printf( "passed\n\n"); +cleanup: mbedtls_x509_crt_free( &cacert ); mbedtls_x509_crt_free( &clicert ); - - return( 0 ); #else ((void) verbose); - return( 0 ); #endif /* MBEDTLS_CERTS_C && MBEDTLS_SHA1_C */ + return( ret ); } #endif /* MBEDTLS_SELF_TEST */ diff --git a/3rdparty/mbedtls/mbedtls/library/x509_crl.c b/3rdparty/mbedtls/mbedtls/library/x509_crl.c index b0f39d428b..3ceb77091e 100644 --- a/3rdparty/mbedtls/mbedtls/library/x509_crl.c +++ b/3rdparty/mbedtls/mbedtls/library/x509_crl.c @@ -107,17 +107,17 @@ static int x509_get_crl_ext( unsigned char **p, { int ret; + if( *p == end ) + return( 0 ); + /* * crlExtensions [0] EXPLICIT Extensions OPTIONAL * -- if present, version MUST be v2 */ if( ( ret = mbedtls_x509_get_ext( p, end, ext, 0 ) ) != 0 ) - { - if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) - return( 0 ); - return( ret ); - } + + end = ext->p + ext->len; while( *p < end ) { diff --git a/3rdparty/mbedtls/mbedtls/library/x509_crt.c b/3rdparty/mbedtls/mbedtls/library/x509_crt.c index d64d7279a5..3ad53a7156 100644 --- a/3rdparty/mbedtls/mbedtls/library/x509_crt.c +++ b/3rdparty/mbedtls/mbedtls/library/x509_crt.c @@ -234,7 +234,7 @@ static int x509_get_version( unsigned char **p, return( 0 ); } - return( ret ); + return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret ); } end = *p + len; @@ -301,7 +301,7 @@ static int x509_get_uid( unsigned char **p, if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) return( 0 ); - return( ret ); + return( MBEDTLS_ERR_X509_INVALID_FORMAT + ret ); } uid->p = *p; @@ -540,14 +540,13 @@ static int x509_get_crt_ext( unsigned char **p, size_t len; unsigned char *end_ext_data, *end_ext_octet; - if( ( ret = mbedtls_x509_get_ext( p, end, &crt->v3_ext, 3 ) ) != 0 ) - { - if( ret == MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) - return( 0 ); + if( *p == end ) + return( 0 ); + if( ( ret = mbedtls_x509_get_ext( p, end, &crt->v3_ext, 3 ) ) != 0 ) return( ret ); - } + end = crt->v3_ext.p + crt->v3_ext.len; while( *p < end ) { /* diff --git a/3rdparty/mbedtls/mbedtls/library/x509_csr.c b/3rdparty/mbedtls/mbedtls/library/x509_csr.c index 779098d4e9..87c179e3d4 100644 --- a/3rdparty/mbedtls/mbedtls/library/x509_csr.c +++ b/3rdparty/mbedtls/mbedtls/library/x509_csr.c @@ -283,15 +283,24 @@ int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, siz { mbedtls_pem_init( &pem ); ret = mbedtls_pem_read_buffer( &pem, - "-----BEGIN CERTIFICATE REQUEST-----", - "-----END CERTIFICATE REQUEST-----", - buf, NULL, 0, &use_len ); + "-----BEGIN CERTIFICATE REQUEST-----", + "-----END CERTIFICATE REQUEST-----", + buf, NULL, 0, &use_len ); + if( ret == MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) + { + ret = mbedtls_pem_read_buffer( &pem, + "-----BEGIN NEW CERTIFICATE REQUEST-----", + "-----END NEW CERTIFICATE REQUEST-----", + buf, NULL, 0, &use_len ); + } if( ret == 0 ) + { /* * Was PEM encoded, parse the result */ ret = mbedtls_x509_csr_parse_der( csr, pem.buf, pem.buflen ); + } mbedtls_pem_free( &pem ); if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) diff --git a/3rdparty/mbedtls/mbedtls/library/x509write_crt.c b/3rdparty/mbedtls/mbedtls/library/x509write_crt.c index de7bf0c70f..4cdb941a10 100644 --- a/3rdparty/mbedtls/mbedtls/library/x509write_crt.c +++ b/3rdparty/mbedtls/mbedtls/library/x509write_crt.c @@ -222,26 +222,51 @@ int mbedtls_x509write_crt_set_authority_key_identifier( mbedtls_x509write_cert * } #endif /* MBEDTLS_SHA1_C */ +static size_t crt_get_unused_bits_for_named_bitstring( unsigned char bitstring, + size_t bit_offset ) +{ + size_t unused_bits; + + /* Count the unused bits removing trailing 0s */ + for( unused_bits = bit_offset; unused_bits < 8; unused_bits++ ) + if( ( ( bitstring >> unused_bits ) & 0x1 ) != 0 ) + break; + + return( unused_bits ); +} + int mbedtls_x509write_crt_set_key_usage( mbedtls_x509write_cert *ctx, unsigned int key_usage ) { unsigned char buf[4], ku; unsigned char *c; int ret; - - /* We currently only support 7 bits, from 0x80 to 0x02 */ - if( ( key_usage & ~0xfe ) != 0 ) + size_t unused_bits; + const unsigned int allowed_bits = MBEDTLS_X509_KU_DIGITAL_SIGNATURE | + MBEDTLS_X509_KU_NON_REPUDIATION | + MBEDTLS_X509_KU_KEY_ENCIPHERMENT | + MBEDTLS_X509_KU_DATA_ENCIPHERMENT | + MBEDTLS_X509_KU_KEY_AGREEMENT | + MBEDTLS_X509_KU_KEY_CERT_SIGN | + MBEDTLS_X509_KU_CRL_SIGN; + + /* Check that nothing other than the allowed flags is set */ + if( ( key_usage & ~allowed_bits ) != 0 ) return( MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE ); c = buf + 4; - ku = (unsigned char) key_usage; + ku = (unsigned char)key_usage; + unused_bits = crt_get_unused_bits_for_named_bitstring( ku, 1 ); + ret = mbedtls_asn1_write_bitstring( &c, buf, &ku, 8 - unused_bits ); - if( ( ret = mbedtls_asn1_write_bitstring( &c, buf, &ku, 7 ) ) != 4 ) + if( ret < 0 ) return( ret ); + else if( ret < 3 || ret > 4 ) + return( MBEDTLS_ERR_X509_INVALID_FORMAT ); ret = mbedtls_x509write_crt_set_extension( ctx, MBEDTLS_OID_KEY_USAGE, MBEDTLS_OID_SIZE( MBEDTLS_OID_KEY_USAGE ), - 1, buf, 4 ); + 1, c, (size_t)ret ); if( ret != 0 ) return( ret ); @@ -253,16 +278,22 @@ int mbedtls_x509write_crt_set_ns_cert_type( mbedtls_x509write_cert *ctx, { unsigned char buf[4]; unsigned char *c; + size_t unused_bits; int ret; c = buf + 4; - if( ( ret = mbedtls_asn1_write_bitstring( &c, buf, &ns_cert_type, 8 ) ) != 4 ) + unused_bits = crt_get_unused_bits_for_named_bitstring( ns_cert_type, 0 ); + ret = mbedtls_asn1_write_bitstring( &c, + buf, + &ns_cert_type, + 8 - unused_bits ); + if( ret < 3 || ret > 4 ) return( ret ); ret = mbedtls_x509write_crt_set_extension( ctx, MBEDTLS_OID_NS_CERT_TYPE, MBEDTLS_OID_SIZE( MBEDTLS_OID_NS_CERT_TYPE ), - 0, buf, 4 ); + 0, c, (size_t)ret ); if( ret != 0 ) return( ret ); @@ -298,10 +329,9 @@ static int x509_write_time( unsigned char **p, unsigned char *start, return( (int) len ); } -int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, - unsigned char *buf, size_t size, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng ) +int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { int ret; const char *sig_oid; @@ -309,14 +339,15 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *c, *c2; unsigned char hash[64]; unsigned char sig[MBEDTLS_MPI_MAX_SIZE]; + unsigned char tmp_buf[2048]; size_t sub_len = 0, pub_len = 0, sig_and_oid_len = 0, sig_len; size_t len = 0; mbedtls_pk_type_t pk_alg; /* - * Prepare data to be signed at the end of the target buffer + * Prepare data to be signed in tmp_buf */ - c = buf + size; + c = tmp_buf + sizeof( tmp_buf ); /* Signature algorithm needed in TBS, and later for actual signature */ @@ -342,36 +373,27 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, /* Only for v3 */ if( ctx->version == MBEDTLS_X509_CRT_VERSION_3 ) { - MBEDTLS_ASN1_CHK_ADD( len, - mbedtls_x509_write_extensions( &c, - buf, ctx->extensions ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, - mbedtls_asn1_write_tag( &c, buf, - MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SEQUENCE ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, - mbedtls_asn1_write_tag( &c, buf, - MBEDTLS_ASN1_CONTEXT_SPECIFIC | - MBEDTLS_ASN1_CONSTRUCTED | 3 ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_extensions( &c, tmp_buf, ctx->extensions ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED | + MBEDTLS_ASN1_SEQUENCE ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | + MBEDTLS_ASN1_CONSTRUCTED | 3 ) ); } /* * SubjectPublicKeyInfo */ - MBEDTLS_ASN1_CHK_ADD( pub_len, - mbedtls_pk_write_pubkey_der( ctx->subject_key, - buf, c - buf ) ); + MBEDTLS_ASN1_CHK_ADD( pub_len, mbedtls_pk_write_pubkey_der( ctx->subject_key, + tmp_buf, c - tmp_buf ) ); c -= pub_len; len += pub_len; /* * Subject ::= Name */ - MBEDTLS_ASN1_CHK_ADD( len, - mbedtls_x509_write_names( &c, buf, - ctx->subject ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c, tmp_buf, ctx->subject ) ); /* * Validity ::= SEQUENCE { @@ -380,39 +402,32 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, */ sub_len = 0; - MBEDTLS_ASN1_CHK_ADD( sub_len, - x509_write_time( &c, buf, ctx->not_after, - MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); + MBEDTLS_ASN1_CHK_ADD( sub_len, x509_write_time( &c, tmp_buf, ctx->not_after, + MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); - MBEDTLS_ASN1_CHK_ADD( sub_len, - x509_write_time( &c, buf, ctx->not_before, - MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); + MBEDTLS_ASN1_CHK_ADD( sub_len, x509_write_time( &c, tmp_buf, ctx->not_before, + MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); len += sub_len; - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, sub_len ) ); - MBEDTLS_ASN1_CHK_ADD( len, - mbedtls_asn1_write_tag( &c, buf, - MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SEQUENCE ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, sub_len ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED | + MBEDTLS_ASN1_SEQUENCE ) ); /* * Issuer ::= Name */ - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c, buf, - ctx->issuer ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c, tmp_buf, ctx->issuer ) ); /* * Signature ::= AlgorithmIdentifier */ - MBEDTLS_ASN1_CHK_ADD( len, - mbedtls_asn1_write_algorithm_identifier( &c, buf, - sig_oid, strlen( sig_oid ), 0 ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_algorithm_identifier( &c, tmp_buf, + sig_oid, strlen( sig_oid ), 0 ) ); /* * Serial ::= INTEGER */ - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_mpi( &c, buf, - &ctx->serial ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_mpi( &c, tmp_buf, &ctx->serial ) ); /* * Version ::= INTEGER { v1(0), v2(1), v3(2) } @@ -422,67 +437,48 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, if( ctx->version != MBEDTLS_X509_CRT_VERSION_1 ) { sub_len = 0; - MBEDTLS_ASN1_CHK_ADD( sub_len, - mbedtls_asn1_write_int( &c, buf, ctx->version ) ); + MBEDTLS_ASN1_CHK_ADD( sub_len, mbedtls_asn1_write_int( &c, tmp_buf, ctx->version ) ); len += sub_len; - MBEDTLS_ASN1_CHK_ADD( len, - mbedtls_asn1_write_len( &c, buf, sub_len ) ); - MBEDTLS_ASN1_CHK_ADD( len, - mbedtls_asn1_write_tag( &c, buf, - MBEDTLS_ASN1_CONTEXT_SPECIFIC | - MBEDTLS_ASN1_CONSTRUCTED | 0 ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, sub_len ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | + MBEDTLS_ASN1_CONSTRUCTED | 0 ) ); } - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, - mbedtls_asn1_write_tag( &c, buf, MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SEQUENCE ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED | + MBEDTLS_ASN1_SEQUENCE ) ); /* * Make signature */ - - /* Compute hash of CRT. */ if( ( ret = mbedtls_md( mbedtls_md_info_from_type( ctx->md_alg ), c, len, hash ) ) != 0 ) { return( ret ); } - if( ( ret = mbedtls_pk_sign( ctx->issuer_key, ctx->md_alg, - hash, 0, sig, &sig_len, - f_rng, p_rng ) ) != 0 ) + if( ( ret = mbedtls_pk_sign( ctx->issuer_key, ctx->md_alg, hash, 0, sig, &sig_len, + f_rng, p_rng ) ) != 0 ) { return( ret ); } - /* Move CRT to the front of the buffer to have space - * for the signature. */ - memmove( buf, c, len ); - c = buf + len; - - /* Add signature at the end of the buffer, - * making sure that it doesn't underflow - * into the CRT buffer. */ + /* + * Write data to output buffer + */ c2 = buf + size; - MBEDTLS_ASN1_CHK_ADD( sig_and_oid_len, mbedtls_x509_write_sig( &c2, c, + MBEDTLS_ASN1_CHK_ADD( sig_and_oid_len, mbedtls_x509_write_sig( &c2, buf, sig_oid, sig_oid_len, sig, sig_len ) ); - /* - * Memory layout after this step: - * - * buf c=buf+len c2 buf+size - * [CRT0,...,CRTn, UNUSED, ..., UNUSED, SIG0, ..., SIGm] - */ + if( len > (size_t)( c2 - buf ) ) + return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); - /* Move raw CRT to just before the signature. */ - c = c2 - len; - memmove( c, buf, len ); + c2 -= len; + memcpy( c2, c, len ); len += sig_and_oid_len; - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, buf, - MBEDTLS_ASN1_CONSTRUCTED | + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c2, buf, len ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c2, buf, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ); return( (int) len ); @@ -492,23 +488,23 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, #define PEM_END_CRT "-----END CERTIFICATE-----\n" #if defined(MBEDTLS_PEM_WRITE_C) -int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *crt, - unsigned char *buf, size_t size, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng ) +int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *crt, unsigned char *buf, size_t size, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { int ret; - size_t olen; + unsigned char output_buf[4096]; + size_t olen = 0; - if( ( ret = mbedtls_x509write_crt_der( crt, buf, size, + if( ( ret = mbedtls_x509write_crt_der( crt, output_buf, sizeof(output_buf), f_rng, p_rng ) ) < 0 ) { return( ret ); } if( ( ret = mbedtls_pem_write_buffer( PEM_BEGIN_CRT, PEM_END_CRT, - buf + size - ret, ret, - buf, size, &olen ) ) != 0 ) + output_buf + sizeof(output_buf) - ret, + ret, buf, size, &olen ) ) != 0 ) { return( ret ); } diff --git a/3rdparty/mbedtls/mbedtls/library/x509write_csr.c b/3rdparty/mbedtls/mbedtls/library/x509write_csr.c index e80053828f..d59354dc4f 100644 --- a/3rdparty/mbedtls/mbedtls/library/x509write_csr.c +++ b/3rdparty/mbedtls/mbedtls/library/x509write_csr.c @@ -85,20 +85,39 @@ int mbedtls_x509write_csr_set_extension( mbedtls_x509write_csr *ctx, 0, val, val_len ); } +static size_t csr_get_unused_bits_for_named_bitstring( unsigned char bitstring, + size_t bit_offset ) +{ + size_t unused_bits; + + /* Count the unused bits removing trailing 0s */ + for( unused_bits = bit_offset; unused_bits < 8; unused_bits++ ) + if( ( ( bitstring >> unused_bits ) & 0x1 ) != 0 ) + break; + + return( unused_bits ); +} + int mbedtls_x509write_csr_set_key_usage( mbedtls_x509write_csr *ctx, unsigned char key_usage ) { unsigned char buf[4]; unsigned char *c; + size_t unused_bits; int ret; c = buf + 4; - if( ( ret = mbedtls_asn1_write_bitstring( &c, buf, &key_usage, 7 ) ) != 4 ) + unused_bits = csr_get_unused_bits_for_named_bitstring( key_usage, 0 ); + ret = mbedtls_asn1_write_bitstring( &c, buf, &key_usage, 8 - unused_bits ); + + if( ret < 0 ) return( ret ); + else if( ret < 3 || ret > 4 ) + return( MBEDTLS_ERR_X509_INVALID_FORMAT ); ret = mbedtls_x509write_csr_set_extension( ctx, MBEDTLS_OID_KEY_USAGE, MBEDTLS_OID_SIZE( MBEDTLS_OID_KEY_USAGE ), - buf, 4 ); + c, (size_t)ret ); if( ret != 0 ) return( ret ); @@ -110,16 +129,25 @@ int mbedtls_x509write_csr_set_ns_cert_type( mbedtls_x509write_csr *ctx, { unsigned char buf[4]; unsigned char *c; + size_t unused_bits; int ret; c = buf + 4; - if( ( ret = mbedtls_asn1_write_bitstring( &c, buf, &ns_cert_type, 8 ) ) != 4 ) + unused_bits = csr_get_unused_bits_for_named_bitstring( ns_cert_type, 0 ); + ret = mbedtls_asn1_write_bitstring( &c, + buf, + &ns_cert_type, + 8 - unused_bits ); + + if( ret < 0 ) + return( ret ); + else if( ret < 3 || ret > 4 ) return( ret ); ret = mbedtls_x509write_csr_set_extension( ctx, MBEDTLS_OID_NS_CERT_TYPE, MBEDTLS_OID_SIZE( MBEDTLS_OID_NS_CERT_TYPE ), - buf, 4 ); + c, (size_t)ret ); if( ret != 0 ) return( ret ); diff --git a/3rdparty/mbedtls/mbedtls/programs/Makefile b/3rdparty/mbedtls/mbedtls/programs/Makefile index 25f184f8c3..b4a553a934 100644 --- a/3rdparty/mbedtls/mbedtls/programs/Makefile +++ b/3rdparty/mbedtls/mbedtls/programs/Makefile @@ -65,7 +65,7 @@ APPS = aes/aescrypt2$(EXEXT) aes/crypt_and_hash$(EXEXT) \ ssl/ssl_mail_client$(EXEXT) random/gen_entropy$(EXEXT) \ random/gen_random_havege$(EXEXT) \ random/gen_random_ctr_drbg$(EXEXT) \ - test/ssl_cert_test$(EXEXT) test/benchmark$(EXEXT) \ + test/benchmark$(EXEXT) \ test/selftest$(EXEXT) test/udp_proxy$(EXEXT) \ util/pem2der$(EXEXT) util/strerror$(EXEXT) \ x509/cert_app$(EXEXT) x509/crl_app$(EXEXT) \ @@ -233,10 +233,6 @@ ssl/mini_client$(EXEXT): ssl/mini_client.c $(DEP) echo " CC ssl/mini_client.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/mini_client.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -test/ssl_cert_test$(EXEXT): test/ssl_cert_test.c $(DEP) - echo " CC test/ssl_cert_test.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/ssl_cert_test.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ - test/benchmark$(EXEXT): test/benchmark.c $(DEP) echo " CC test/benchmark.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/benchmark.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ diff --git a/3rdparty/mbedtls/mbedtls/programs/pkey/key_app_writer.c b/3rdparty/mbedtls/mbedtls/programs/pkey/key_app_writer.c index cd0c230644..0450a17101 100644 --- a/3rdparty/mbedtls/mbedtls/programs/pkey/key_app_writer.c +++ b/3rdparty/mbedtls/mbedtls/programs/pkey/key_app_writer.c @@ -175,7 +175,7 @@ static int write_private_key( mbedtls_pk_context *key, const char *output_file ) return( ret ); len = ret; - c = output_buf + sizeof(output_buf) - len - 1; + c = output_buf + sizeof(output_buf) - len; } if( ( f = fopen( output_file, "w" ) ) == NULL ) diff --git a/3rdparty/mbedtls/mbedtls/programs/pkey/rsa_sign_pss.c b/3rdparty/mbedtls/mbedtls/programs/pkey/rsa_sign_pss.c index b0b0f7ecf4..e1c8ef6fe1 100644 --- a/3rdparty/mbedtls/mbedtls/programs/pkey/rsa_sign_pss.c +++ b/3rdparty/mbedtls/mbedtls/programs/pkey/rsa_sign_pss.c @@ -54,7 +54,6 @@ int main( void ) #include "mbedtls/ctr_drbg.h" #include "mbedtls/md.h" #include "mbedtls/rsa.h" -#include "mbedtls/md.h" #include "mbedtls/x509.h" #include diff --git a/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_client2.c b/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_client2.c index 81514321ff..c63c4f75a1 100644 --- a/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_client2.c +++ b/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_client2.c @@ -1072,20 +1072,20 @@ int main( int argc, char *argv[] ) mbedtls_printf( " . Loading the CA root certificate ..." ); fflush( stdout ); + if( strcmp( opt.ca_path, "none" ) == 0 || + strcmp( opt.ca_file, "none" ) == 0 ) + { + ret = 0; + } + else #if defined(MBEDTLS_FS_IO) if( strlen( opt.ca_path ) ) - if( strcmp( opt.ca_path, "none" ) == 0 ) - ret = 0; - else - ret = mbedtls_x509_crt_parse_path( &cacert, opt.ca_path ); + ret = mbedtls_x509_crt_parse_path( &cacert, opt.ca_path ); else if( strlen( opt.ca_file ) ) - if( strcmp( opt.ca_file, "none" ) == 0 ) - ret = 0; - else - ret = mbedtls_x509_crt_parse_file( &cacert, opt.ca_file ); + ret = mbedtls_x509_crt_parse_file( &cacert, opt.ca_file ); else #endif -#if defined(MBEDTLS_CERTS_C) +#if defined(MBEDTLS_CERTS_C) && defined(MBEDTLS_PEM_PARSE_C) for( i = 0; mbedtls_test_cas[i] != NULL; i++ ) { ret = mbedtls_x509_crt_parse( &cacert, @@ -1097,9 +1097,13 @@ int main( int argc, char *argv[] ) #else { ret = 1; - mbedtls_printf("MBEDTLS_CERTS_C not defined."); +#if !defined(MBEDTLS_CERTS_C) + mbedtls_printf( "MBEDTLS_CERTS_C not defined." ); +#else + mbedtls_printf( "All test CRTs loaded via MBEDTLS_CERTS_C are PEM-encoded, but MBEDTLS_PEM_PARSE_C is disabled." ); } -#endif +#endif /* MBEDTLS_CERTS_C */ +#endif /* MBEDTLS_CERTS_C && MBEDTLS_PEM_PARSE_C */ if( ret < 0 ) { mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret ); @@ -1116,46 +1120,54 @@ int main( int argc, char *argv[] ) mbedtls_printf( " . Loading the client cert. and key..." ); fflush( stdout ); + if( strcmp( opt.crt_file, "none" ) == 0 ) + ret = 0; + else #if defined(MBEDTLS_FS_IO) if( strlen( opt.crt_file ) ) - if( strcmp( opt.crt_file, "none" ) == 0 ) - ret = 0; - else - ret = mbedtls_x509_crt_parse_file( &clicert, opt.crt_file ); + ret = mbedtls_x509_crt_parse_file( &clicert, opt.crt_file ); else #endif -#if defined(MBEDTLS_CERTS_C) +#if defined(MBEDTLS_CERTS_C) && defined(MBEDTLS_PEM_PARSE_C) ret = mbedtls_x509_crt_parse( &clicert, (const unsigned char *) mbedtls_test_cli_crt, mbedtls_test_cli_crt_len ); #else { ret = 1; - mbedtls_printf("MBEDTLS_CERTS_C not defined."); +#if !defined(MBEDTLS_CERTS_C) + mbedtls_printf( "MBEDTLS_CERTS_C not defined." ); +#else + mbedtls_printf( "All test CRTs loaded via MBEDTLS_CERTS_C are PEM-encoded, but MBEDTLS_PEM_PARSE_C is disabled." ); } -#endif +#endif /* MBEDTLS_CERTS_C */ +#endif /* MBEDTLS_CERTS_C && MBEDTLS_PEM_PARSE_C */ if( ret != 0 ) { mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret ); goto exit; } + if( strcmp( opt.key_file, "none" ) == 0 ) + ret = 0; + else #if defined(MBEDTLS_FS_IO) if( strlen( opt.key_file ) ) - if( strcmp( opt.key_file, "none" ) == 0 ) - ret = 0; - else - ret = mbedtls_pk_parse_keyfile( &pkey, opt.key_file, "" ); + ret = mbedtls_pk_parse_keyfile( &pkey, opt.key_file, "" ); else #endif -#if defined(MBEDTLS_CERTS_C) +#if defined(MBEDTLS_CERTS_C) && defined(MBEDTLS_PEM_PARSE_C) ret = mbedtls_pk_parse_key( &pkey, (const unsigned char *) mbedtls_test_cli_key, mbedtls_test_cli_key_len, NULL, 0 ); #else { ret = 1; - mbedtls_printf("MBEDTLS_CERTS_C not defined."); +#if !defined(MBEDTLS_CERTS_C) + mbedtls_printf( "MBEDTLS_CERTS_C not defined." ); +#else + mbedtls_printf( "All test keys loaded via MBEDTLS_CERTS_C are PEM-encoded, but MBEDTLS_PEM_PARSE_C is disabled." ); } -#endif +#endif /* MBEDTLS_CERTS_C */ +#endif /* MBEDTLS_CERTS_C && MBEDTLS_PEM_PARSE_C */ if( ret != 0 ) { mbedtls_printf( " failed\n ! mbedtls_pk_parse_key returned -0x%x\n\n", -ret ); diff --git a/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_mail_client.c b/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_mail_client.c index 7214dc2631..8ec6079d59 100644 --- a/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_mail_client.c +++ b/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_mail_client.c @@ -104,9 +104,9 @@ int main( void ) #if defined(MBEDTLS_BASE64_C) #define USAGE_AUTH \ - " authentication=%%d default: 0 (disabled)\n" \ - " user_name=%%s default: \"user\"\n" \ - " user_pwd=%%s default: \"password\"\n" + " authentication=%%d default: 0 (disabled)\n" \ + " user_name=%%s default: \"" DFL_USER_NAME "\"\n" \ + " user_pwd=%%s default: \"" DFL_USER_PWD "\"\n" #else #define USAGE_AUTH \ " authentication options disabled. (Require MBEDTLS_BASE64_C)\n" @@ -123,17 +123,17 @@ int main( void ) #endif /* MBEDTLS_FS_IO */ #define USAGE \ - "\n usage: ssl_mail_client param=<>...\n" \ - "\n acceptable parameters:\n" \ - " server_name=%%s default: localhost\n" \ - " server_port=%%d default: 4433\n" \ - " debug_level=%%d default: 0 (disabled)\n" \ + "\n usage: ssl_mail_client param=<>...\n" \ + "\n acceptable parameters:\n" \ + " server_name=%%s default: " DFL_SERVER_NAME "\n" \ + " server_port=%%d default: " DFL_SERVER_PORT "\n" \ + " debug_level=%%d default: 0 (disabled)\n" \ " mode=%%d default: 0 (SSL/TLS) (1 for STARTTLS)\n" \ - USAGE_AUTH \ - " mail_from=%%s default: \"\"\n" \ - " mail_to=%%s default: \"\"\n" \ - USAGE_IO \ - " force_ciphersuite= default: all enabled\n"\ + USAGE_AUTH \ + " mail_from=%%s default: \"\"\n" \ + " mail_to=%%s default: \"\"\n" \ + USAGE_IO \ + " force_ciphersuite= default: all enabled\n" \ " acceptable ciphersuite names:\n" /* @@ -306,7 +306,7 @@ static int write_and_get_response( mbedtls_net_context *sock_fd, unsigned char * mbedtls_printf("\n%s", buf); if( len && ( ret = mbedtls_net_send( sock_fd, buf, len ) ) <= 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ssl_write returned %d\n\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_net_send returned %d\n\n", ret ); return -1; } @@ -318,7 +318,7 @@ static int write_and_get_response( mbedtls_net_context *sock_fd, unsigned char * if( ret <= 0 ) { - mbedtls_printf( "failed\n ! read returned %d\n\n", ret ); + mbedtls_printf( "failed\n ! mbedtls_net_recv returned %d\n\n", ret ); return -1; } diff --git a/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_server2.c b/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_server2.c index b6e8a1d146..ae57f1fda0 100644 --- a/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_server2.c +++ b/3rdparty/mbedtls/mbedtls/programs/ssl/ssl_server2.c @@ -201,8 +201,12 @@ int main( void ) #endif /* MBEDTLS_X509_CRT_PARSE_C */ #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) -#define USAGE_PSK \ - " psk=%%s default: \"\" (in hex, without 0x)\n" \ +#define USAGE_PSK \ + " psk=%%s default: \"\" (in hex, without 0x)\n" \ + " psk_list=%%s default: \"\"\n" \ + " A list of (PSK identity, PSK value) pairs.\n" \ + " The PSK values are in hex, without 0x.\n" \ + " id1,psk1[,id2,psk2[,...]]\n" \ " psk_identity=%%s default: \"Client_identity\"\n" #else #define USAGE_PSK "" @@ -225,8 +229,14 @@ int main( void ) #endif /* MBEDTLS_SSL_CACHE_C */ #if defined(SNI_OPTION) +#if defined(MBEDTLS_X509_CRL_PARSE_C) +#define SNI_CRL ",crl" +#else +#define SNI_CRL "" +#endif + #define USAGE_SNI \ - " sni=%%s name1,cert1,key1,ca1,crl1,auth1[,...]\n" \ + " sni=%%s name1,cert1,key1,ca1"SNI_CRL",auth1[,...]\n" \ " default: disabled\n" #else #define USAGE_SNI "" @@ -561,10 +571,10 @@ void sni_free( sni_entry *head ) mbedtls_x509_crt_free( cur->ca ); mbedtls_free( cur->ca ); - +#if defined(MBEDTLS_X509_CRL_PARSE_C) mbedtls_x509_crl_free( cur->crl ); mbedtls_free( cur->crl ); - +#endif next = cur->next; mbedtls_free( cur ); cur = next; @@ -583,7 +593,10 @@ sni_entry *sni_parse( char *sni_string ) sni_entry *cur = NULL, *new = NULL; char *p = sni_string; char *end = p; - char *crt_file, *key_file, *ca_file, *crl_file, *auth_str; + char *crt_file, *key_file, *ca_file, *auth_str; +#if defined(MBEDTLS_X509_CRL_PARSE_C) + char *crl_file; +#endif while( *end != '\0' ) ++end; @@ -601,7 +614,9 @@ sni_entry *sni_parse( char *sni_string ) GET_ITEM( crt_file ); GET_ITEM( key_file ); GET_ITEM( ca_file ); +#if defined(MBEDTLS_X509_CRL_PARSE_C) GET_ITEM( crl_file ); +#endif GET_ITEM( auth_str ); if( ( new->cert = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) ) ) == NULL || @@ -626,6 +641,7 @@ sni_entry *sni_parse( char *sni_string ) goto error; } +#if defined(MBEDTLS_X509_CRL_PARSE_C) if( strcmp( crl_file, "-" ) != 0 ) { if( ( new->crl = mbedtls_calloc( 1, sizeof( mbedtls_x509_crl ) ) ) == NULL ) @@ -636,6 +652,7 @@ sni_entry *sni_parse( char *sni_string ) if( mbedtls_x509_crl_parse_file( new->crl, crl_file ) != 0 ) goto error; } +#endif if( strcmp( auth_str, "-" ) != 0 ) { @@ -1578,20 +1595,20 @@ int main( int argc, char *argv[] ) mbedtls_printf( " . Loading the CA root certificate ..." ); fflush( stdout ); + if( strcmp( opt.ca_path, "none" ) == 0 || + strcmp( opt.ca_file, "none" ) == 0 ) + { + ret = 0; + } + else #if defined(MBEDTLS_FS_IO) if( strlen( opt.ca_path ) ) - if( strcmp( opt.ca_path, "none" ) == 0 ) - ret = 0; - else - ret = mbedtls_x509_crt_parse_path( &cacert, opt.ca_path ); + ret = mbedtls_x509_crt_parse_path( &cacert, opt.ca_path ); else if( strlen( opt.ca_file ) ) - if( strcmp( opt.ca_file, "none" ) == 0 ) - ret = 0; - else - ret = mbedtls_x509_crt_parse_file( &cacert, opt.ca_file ); + ret = mbedtls_x509_crt_parse_file( &cacert, opt.ca_file ); else #endif -#if defined(MBEDTLS_CERTS_C) +#if defined(MBEDTLS_CERTS_C) && defined(MBEDTLS_PEM_PARSE_C) for( i = 0; mbedtls_test_cas[i] != NULL; i++ ) { ret = mbedtls_x509_crt_parse( &cacert, @@ -1603,9 +1620,13 @@ int main( int argc, char *argv[] ) #else { ret = 1; - mbedtls_printf("MBEDTLS_CERTS_C not defined."); +#if !defined(MBEDTLS_CERTS_C) + mbedtls_printf( "MBEDTLS_CERTS_C not defined." ); +#else + mbedtls_printf( "All test CRTs loaded via MBEDTLS_CERTS_C are PEM-encoded, but MBEDTLS_PEM_PARSE_C is disabled." ); } -#endif +#endif /* MBEDTLS_CERTS_C */ +#endif /* MBEDTLS_CERTS_C && MBEDTLS_PEM_PARSE_C */ if( ret < 0 ) { mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret ); diff --git a/3rdparty/mbedtls/mbedtls/programs/test/CMakeLists.txt b/3rdparty/mbedtls/mbedtls/programs/test/CMakeLists.txt index 0ed7145466..64b963719a 100644 --- a/3rdparty/mbedtls/mbedtls/programs/test/CMakeLists.txt +++ b/3rdparty/mbedtls/mbedtls/programs/test/CMakeLists.txt @@ -16,12 +16,10 @@ target_link_libraries(selftest ${libs}) add_executable(benchmark benchmark.c) target_link_libraries(benchmark ${libs}) -add_executable(ssl_cert_test ssl_cert_test.c) -target_link_libraries(ssl_cert_test ${libs}) add_executable(udp_proxy udp_proxy.c) target_link_libraries(udp_proxy ${libs}) -install(TARGETS selftest benchmark ssl_cert_test udp_proxy +install(TARGETS selftest benchmark udp_proxy DESTINATION "bin" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) diff --git a/3rdparty/mbedtls/mbedtls/programs/test/ssl_cert_test.c b/3rdparty/mbedtls/mbedtls/programs/test/ssl_cert_test.c deleted file mode 100644 index fd3526f7fe..0000000000 --- a/3rdparty/mbedtls/mbedtls/programs/test/ssl_cert_test.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * SSL certificate functionality tests - * - * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This file is part of mbed TLS (https://tls.mbed.org) - */ - -#if !defined(MBEDTLS_CONFIG_FILE) -#include "mbedtls/config.h" -#else -#include MBEDTLS_CONFIG_FILE -#endif - -#if defined(MBEDTLS_PLATFORM_C) -#include "mbedtls/platform.h" -#else -#include -#include -#define mbedtls_snprintf snprintf -#define mbedtls_printf printf -#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS -#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE -#endif /* MBEDTLS_PLATFORM_C */ - -#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_X509_CRT_PARSE_C) && \ - defined(MBEDTLS_FS_IO) && defined(MBEDTLS_X509_CRL_PARSE_C) -#include "mbedtls/certs.h" -#include "mbedtls/x509_crt.h" - -#include -#include -#endif - -#define MAX_CLIENT_CERTS 8 - -#if !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_X509_CRT_PARSE_C) || \ - !defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_X509_CRL_PARSE_C) -int main( void ) -{ - mbedtls_printf("MBEDTLS_RSA_C and/or MBEDTLS_X509_CRT_PARSE_C " - "MBEDTLS_FS_IO and/or MBEDTLS_X509_CRL_PARSE_C " - "not defined.\n"); - return( 0 ); -} -#else -const char *client_certificates[MAX_CLIENT_CERTS] = -{ - "client1.crt", - "client2.crt", - "server1.crt", - "server2.crt", - "cert_sha224.crt", - "cert_sha256.crt", - "cert_sha384.crt", - "cert_sha512.crt" -}; - -const char *client_private_keys[MAX_CLIENT_CERTS] = -{ - "client1.key", - "client2.key", - "server1.key", - "server2.key", - "cert_digest.key", - "cert_digest.key", - "cert_digest.key", - "cert_digest.key" -}; - -int main( void ) -{ - int ret = 1, i; - int exit_code = MBEDTLS_EXIT_FAILURE; - mbedtls_x509_crt cacert; - mbedtls_x509_crl crl; - char buf[10240]; - - mbedtls_x509_crt_init( &cacert ); - mbedtls_x509_crl_init( &crl ); - - /* - * 1.1. Load the trusted CA - */ - mbedtls_printf( "\n . Loading the CA root certificate ..." ); - fflush( stdout ); - - /* - * Alternatively, you may load the CA certificates from a .pem or - * .crt file by calling mbedtls_x509_crt_parse_file( &cacert, "myca.crt" ). - */ - ret = mbedtls_x509_crt_parse_file( &cacert, "ssl/test-ca/test-ca.crt" ); - if( ret != 0 ) - { - mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_file returned %d\n\n", ret ); - goto exit; - } - - mbedtls_printf( " ok\n" ); - - mbedtls_x509_crt_info( buf, 1024, "CRT: ", &cacert ); - mbedtls_printf("%s\n", buf ); - - /* - * 1.2. Load the CRL - */ - mbedtls_printf( " . Loading the CRL ..." ); - fflush( stdout ); - - ret = mbedtls_x509_crl_parse_file( &crl, "ssl/test-ca/crl.pem" ); - if( ret != 0 ) - { - mbedtls_printf( " failed\n ! mbedtls_x509_crl_parse_file returned %d\n\n", ret ); - goto exit; - } - - mbedtls_printf( " ok\n" ); - - mbedtls_x509_crl_info( buf, 1024, "CRL: ", &crl ); - mbedtls_printf("%s\n", buf ); - - for( i = 0; i < MAX_CLIENT_CERTS; i++ ) - { - /* - * 1.3. Load own certificate - */ - char name[512]; - uint32_t flags; - mbedtls_x509_crt clicert; - mbedtls_pk_context pk; - - mbedtls_x509_crt_init( &clicert ); - mbedtls_pk_init( &pk ); - - mbedtls_snprintf(name, 512, "ssl/test-ca/%s", client_certificates[i]); - - mbedtls_printf( " . Loading the client certificate %s...", name ); - fflush( stdout ); - - ret = mbedtls_x509_crt_parse_file( &clicert, name ); - if( ret != 0 ) - { - mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_file returned %d\n\n", ret ); - goto exit; - } - - mbedtls_printf( " ok\n" ); - - /* - * 1.4. Verify certificate validity with CA certificate - */ - mbedtls_printf( " . Verify the client certificate with CA certificate..." ); - fflush( stdout ); - - ret = mbedtls_x509_crt_verify( &clicert, &cacert, &crl, NULL, &flags, NULL, - NULL ); - if( ret != 0 ) - { - if( ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED ) - { - char vrfy_buf[512]; - - mbedtls_printf( " failed\n" ); - mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), " ! ", flags ); - mbedtls_printf( "%s\n", vrfy_buf ); - } - else - { - mbedtls_printf( " failed\n ! mbedtls_x509_crt_verify returned %d\n\n", ret ); - goto exit; - } - } - - mbedtls_printf( " ok\n" ); - - /* - * 1.5. Load own private key - */ - mbedtls_snprintf(name, 512, "ssl/test-ca/%s", client_private_keys[i]); - - mbedtls_printf( " . Loading the client private key %s...", name ); - fflush( stdout ); - - ret = mbedtls_pk_parse_keyfile( &pk, name, NULL ); - if( ret != 0 ) - { - mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned %d\n\n", ret ); - goto exit; - } - - mbedtls_printf( " ok\n" ); - - /* - * 1.6. Verify certificate validity with private key - */ - mbedtls_printf( " . Verify the client certificate with private key..." ); - fflush( stdout ); - - - /* EC NOT IMPLEMENTED YET */ - if( ! mbedtls_pk_can_do( &clicert.pk, MBEDTLS_PK_RSA ) ) - { - mbedtls_printf( " failed\n ! certificate's key is not RSA\n\n" ); - goto exit; - } - - ret = mbedtls_mpi_cmp_mpi(&mbedtls_pk_rsa( pk )->N, &mbedtls_pk_rsa( clicert.pk )->N); - if( ret != 0 ) - { - mbedtls_printf( " failed\n ! mbedtls_mpi_cmp_mpi for N returned %d\n\n", ret ); - goto exit; - } - - ret = mbedtls_mpi_cmp_mpi(&mbedtls_pk_rsa( pk )->E, &mbedtls_pk_rsa( clicert.pk )->E); - if( ret != 0 ) - { - mbedtls_printf( " failed\n ! mbedtls_mpi_cmp_mpi for E returned %d\n\n", ret ); - goto exit; - } - - ret = mbedtls_rsa_check_privkey( mbedtls_pk_rsa( pk ) ); - if( ret != 0 ) - { - mbedtls_printf( " failed\n ! mbedtls_rsa_check_privkey returned %d\n\n", ret ); - goto exit; - } - - mbedtls_printf( " ok\n" ); - - mbedtls_x509_crt_free( &clicert ); - mbedtls_pk_free( &pk ); - } - - exit_code = MBEDTLS_EXIT_SUCCESS; - -exit: - mbedtls_x509_crt_free( &cacert ); - mbedtls_x509_crl_free( &crl ); - -#if defined(_WIN32) - mbedtls_printf( " + Press Enter to exit this program.\n" ); - fflush( stdout ); getchar(); -#endif - - return( exit_code ); -} -#endif /* MBEDTLS_RSA_C && MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_FS_IO && - MBEDTLS_X509_CRL_PARSE_C */ diff --git a/3rdparty/mbedtls/mbedtls/programs/test/udp_proxy.c b/3rdparty/mbedtls/mbedtls/programs/test/udp_proxy.c index 1865b0f1b9..02428b9dd0 100644 --- a/3rdparty/mbedtls/mbedtls/programs/test/udp_proxy.c +++ b/3rdparty/mbedtls/mbedtls/programs/test/udp_proxy.c @@ -372,32 +372,17 @@ void clear_pending( void ) static unsigned char dropped[2048] = { 0 }; #define DROP_MAX 2 -/* - * OpenSSL groups packets in a datagram the first time it sends them, but not - * when it resends them. Count every record as seen the first time. - */ +/* We only drop packets at the level of entire datagrams, not at the level + * of records. In particular, if the peer changes the way it packs multiple + * records into a single datagram, we don't necessarily count the number of + * times a record has been dropped correctly. However, the only known reason + * why a peer would change datagram packing is disabling the latter on + * retransmission, in which case we'd drop involved records at most + * DROP_MAX + 1 times. */ void update_dropped( const packet *p ) { size_t id = p->len % sizeof( dropped ); - const unsigned char *end = p->buf + p->len; - const unsigned char *cur = p->buf; - size_t len = ( ( cur[11] << 8 ) | cur[12] ) + 13; - ++dropped[id]; - - /* Avoid counting single record twice */ - if( len == p->len ) - return; - - while( cur < end ) - { - len = ( ( cur[11] << 8 ) | cur[12] ) + 13; - - id = len % sizeof( dropped ); - ++dropped[id]; - - cur += len; - } } int handle_message( const char *way, diff --git a/3rdparty/mbedtls/mbedtls/programs/x509/cert_req.c b/3rdparty/mbedtls/mbedtls/programs/x509/cert_req.c index a32ac505f2..784f719330 100644 --- a/3rdparty/mbedtls/mbedtls/programs/x509/cert_req.c +++ b/3rdparty/mbedtls/mbedtls/programs/x509/cert_req.c @@ -63,7 +63,10 @@ int main( void ) #define DFL_OUTPUT_FILENAME "cert.req" #define DFL_SUBJECT_NAME "CN=Cert,O=mbed TLS,C=UK" #define DFL_KEY_USAGE 0 +#define DFL_FORCE_KEY_USAGE 0 #define DFL_NS_CERT_TYPE 0 +#define DFL_FORCE_NS_CERT_TYPE 0 +#define DFL_MD_ALG MBEDTLS_MD_SHA256 #define USAGE \ "\n usage: cert_req param=<>...\n" \ @@ -81,6 +84,8 @@ int main( void ) " key_agreement\n" \ " key_cert_sign\n" \ " crl_sign\n" \ + " force_key_usage=0/1 default: off\n" \ + " Add KeyUsage even if it is empty\n" \ " ns_cert_type=%%s default: (empty)\n" \ " Comma-separated-list of values:\n" \ " ssl_client\n" \ @@ -90,6 +95,13 @@ int main( void ) " ssl_ca\n" \ " email_ca\n" \ " object_signing_ca\n" \ + " force_ns_cert_type=0/1 default: off\n" \ + " Add NsCertType even if it is empty\n" \ + " md=%%s default: SHA256\n" \ + " possible values:\n" \ + " MD2, MD4, MD5, SHA1\n" \ + " SHA224, SHA256\n" \ + " SHA384, SHA512\n" \ "\n" /* @@ -102,7 +114,10 @@ struct options const char *output_file; /* where to store the constructed key file */ const char *subject_name; /* subject name for certificate request */ unsigned char key_usage; /* key usage flags */ + int force_key_usage; /* Force adding the KeyUsage extension */ unsigned char ns_cert_type; /* NS cert type */ + int force_ns_cert_type; /* Force adding NsCertType extension */ + mbedtls_md_type_t md_alg; /* Hash algorithm used for signature. */ } opt; int write_certificate_request( mbedtls_x509write_csr *req, const char *output_file, @@ -151,7 +166,6 @@ int main( int argc, char *argv[] ) * Set to sane values */ mbedtls_x509write_csr_init( &req ); - mbedtls_x509write_csr_set_md_alg( &req, MBEDTLS_MD_SHA256 ); mbedtls_pk_init( &key ); mbedtls_ctr_drbg_init( &ctr_drbg ); memset( buf, 0, sizeof( buf ) ); @@ -168,7 +182,10 @@ int main( int argc, char *argv[] ) opt.output_file = DFL_OUTPUT_FILENAME; opt.subject_name = DFL_SUBJECT_NAME; opt.key_usage = DFL_KEY_USAGE; + opt.force_key_usage = DFL_FORCE_KEY_USAGE; opt.ns_cert_type = DFL_NS_CERT_TYPE; + opt.force_ns_cert_type = DFL_FORCE_NS_CERT_TYPE; + opt.md_alg = DFL_MD_ALG; for( i = 1; i < argc; i++ ) { @@ -192,6 +209,61 @@ int main( int argc, char *argv[] ) { opt.subject_name = q; } + else if( strcmp( p, "md" ) == 0 ) + { + if( strcmp( q, "SHA256" ) == 0 ) + { + opt.md_alg = MBEDTLS_MD_SHA256; + } + else if( strcmp( q, "SHA224" ) == 0 ) + { + opt.md_alg = MBEDTLS_MD_SHA224; + } + else +#if defined(MBEDTLS_MD5_C) + if( strcmp( q, "MD5" ) == 0 ) + { + opt.md_alg = MBEDTLS_MD_MD5; + } + else +#endif /* MBEDTLS_MD5_C */ +#if defined(MBEDTLS_MD4_C) + if( strcmp( q, "MD4" ) == 0 ) + { + opt.md_alg = MBEDTLS_MD_MD4; + } + else +#endif /* MBEDTLS_MD5_C */ +#if defined(MBEDTLS_MD2_C) + if( strcmp( q, "MD2" ) == 0 ) + { + opt.md_alg = MBEDTLS_MD_MD2; + } + else +#endif /* MBEDTLS_MD2_C */ +#if defined(MBEDTLS_SHA1_C) + if( strcmp( q, "SHA1" ) == 0 ) + { + opt.md_alg = MBEDTLS_MD_SHA1; + } + else +#endif /* MBEDTLS_SHA1_C */ +#if defined(MBEDTLS_SHA512_C) + if( strcmp( q, "SHA384" ) == 0 ) + { + opt.md_alg = MBEDTLS_MD_SHA384; + } + else + if( strcmp( q, "SHA512" ) == 0 ) + { + opt.md_alg = MBEDTLS_MD_SHA512; + } + else +#endif /* MBEDTLS_SHA512_C */ + { + goto usage; + } + } else if( strcmp( p, "key_usage" ) == 0 ) { while( q != NULL ) @@ -219,6 +291,15 @@ int main( int argc, char *argv[] ) q = r; } } + else if( strcmp( p, "force_key_usage" ) == 0 ) + { + switch( atoi( q ) ) + { + case 0: opt.force_key_usage = 0; break; + case 1: opt.force_key_usage = 1; break; + default: goto usage; + } + } else if( strcmp( p, "ns_cert_type" ) == 0 ) { while( q != NULL ) @@ -246,14 +327,25 @@ int main( int argc, char *argv[] ) q = r; } } + else if( strcmp( p, "force_ns_cert_type" ) == 0 ) + { + switch( atoi( q ) ) + { + case 0: opt.force_ns_cert_type = 0; break; + case 1: opt.force_ns_cert_type = 1; break; + default: goto usage; + } + } else goto usage; } - if( opt.key_usage ) + mbedtls_x509write_csr_set_md_alg( &req, opt.md_alg ); + + if( opt.key_usage || opt.force_key_usage == 1 ) mbedtls_x509write_csr_set_key_usage( &req, opt.key_usage ); - if( opt.ns_cert_type ) + if( opt.ns_cert_type || opt.force_ns_cert_type == 1 ) mbedtls_x509write_csr_set_ns_cert_type( &req, opt.ns_cert_type ); /* diff --git a/3rdparty/mbedtls/mbedtls/programs/x509/cert_write.c b/3rdparty/mbedtls/mbedtls/programs/x509/cert_write.c index 527d9ec74d..adade1c868 100644 --- a/3rdparty/mbedtls/mbedtls/programs/x509/cert_write.c +++ b/3rdparty/mbedtls/mbedtls/programs/x509/cert_write.c @@ -120,7 +120,7 @@ int main( void ) " max_pathlen=%%d default: -1 (none)\n" \ " md=%%s default: SHA256\n" \ " Supported values:\n" \ - " MD5, SHA1, SHA256, SHA512\n"\ + " MD2, MD4, MD5, SHA1, SHA256, SHA512\n"\ " version=%%d default: 3\n" \ " Possible values: 1, 2, 3\n"\ " subject_identifier=%%s default: 1\n" \ @@ -359,6 +359,10 @@ int main( int argc, char *argv[] ) opt.md = MBEDTLS_MD_SHA256; else if( strcmp( q, "SHA512" ) == 0 ) opt.md = MBEDTLS_MD_SHA512; + else if( strcmp( q, "MD2" ) == 0 ) + opt.md = MBEDTLS_MD_MD2; + else if( strcmp( q, "MD4" ) == 0 ) + opt.md = MBEDTLS_MD_MD4; else if( strcmp( q, "MD5" ) == 0 ) opt.md = MBEDTLS_MD_MD5; else diff --git a/3rdparty/mbedtls/mbedtls/scripts/abi_check.py b/3rdparty/mbedtls/mbedtls/scripts/abi_check.py new file mode 100755 index 0000000000..502c7ae02e --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/scripts/abi_check.py @@ -0,0 +1,406 @@ +#!/usr/bin/env python3 +""" +This file is part of Mbed TLS (https://tls.mbed.org) + +Copyright (c) 2018, Arm Limited, All Rights Reserved + +Purpose + +This script is a small wrapper around the abi-compliance-checker and +abi-dumper tools, applying them to compare the ABI and API of the library +files from two different Git revisions within an Mbed TLS repository. +The results of the comparison are either formatted as HTML and stored at +a configurable location, or are given as a brief list of problems. +Returns 0 on success, 1 on ABI/API non-compliance, and 2 if there is an error +while running the script. Note: must be run from Mbed TLS root. +""" + +import os +import sys +import traceback +import shutil +import subprocess +import argparse +import logging +import tempfile +import fnmatch +from types import SimpleNamespace + +import xml.etree.ElementTree as ET + + +class AbiChecker(object): + """API and ABI checker.""" + + def __init__(self, old_version, new_version, configuration): + """Instantiate the API/ABI checker. + + old_version: RepoVersion containing details to compare against + new_version: RepoVersion containing details to check + configuration.report_dir: directory for output files + configuration.keep_all_reports: if false, delete old reports + configuration.brief: if true, output shorter report to stdout + configuration.skip_file: path to file containing symbols and types to skip + """ + self.repo_path = "." + self.log = None + self.verbose = configuration.verbose + self._setup_logger() + self.report_dir = os.path.abspath(configuration.report_dir) + self.keep_all_reports = configuration.keep_all_reports + self.can_remove_report_dir = not (os.path.exists(self.report_dir) or + self.keep_all_reports) + self.old_version = old_version + self.new_version = new_version + self.skip_file = configuration.skip_file + self.brief = configuration.brief + self.git_command = "git" + self.make_command = "make" + + @staticmethod + def check_repo_path(): + current_dir = os.path.realpath('.') + root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + if current_dir != root_dir: + raise Exception("Must be run from Mbed TLS root") + + def _setup_logger(self): + self.log = logging.getLogger() + if self.verbose: + self.log.setLevel(logging.DEBUG) + else: + self.log.setLevel(logging.INFO) + self.log.addHandler(logging.StreamHandler()) + + @staticmethod + def check_abi_tools_are_installed(): + for command in ["abi-dumper", "abi-compliance-checker"]: + if not shutil.which(command): + raise Exception("{} not installed, aborting".format(command)) + + def _get_clean_worktree_for_git_revision(self, version): + """Make a separate worktree with version.revision checked out. + Do not modify the current worktree.""" + git_worktree_path = tempfile.mkdtemp() + if version.repository: + self.log.debug( + "Checking out git worktree for revision {} from {}".format( + version.revision, version.repository + ) + ) + fetch_output = subprocess.check_output( + [self.git_command, "fetch", + version.repository, version.revision], + cwd=self.repo_path, + stderr=subprocess.STDOUT + ) + self.log.debug(fetch_output.decode("utf-8")) + worktree_rev = "FETCH_HEAD" + else: + self.log.debug("Checking out git worktree for revision {}".format( + version.revision + )) + worktree_rev = version.revision + worktree_output = subprocess.check_output( + [self.git_command, "worktree", "add", "--detach", + git_worktree_path, worktree_rev], + cwd=self.repo_path, + stderr=subprocess.STDOUT + ) + self.log.debug(worktree_output.decode("utf-8")) + return git_worktree_path + + def _update_git_submodules(self, git_worktree_path, version): + """If the crypto submodule is present, initialize it. + if version.crypto_revision exists, update it to that revision, + otherwise update it to the default revision""" + update_output = subprocess.check_output( + [self.git_command, "submodule", "update", "--init", '--recursive'], + cwd=git_worktree_path, + stderr=subprocess.STDOUT + ) + self.log.debug(update_output.decode("utf-8")) + if not (os.path.exists(os.path.join(git_worktree_path, "crypto")) + and version.crypto_revision): + return + + if version.crypto_repository: + fetch_output = subprocess.check_output( + [self.git_command, "fetch", version.crypto_repository, + version.crypto_revision], + cwd=os.path.join(git_worktree_path, "crypto"), + stderr=subprocess.STDOUT + ) + self.log.debug(fetch_output.decode("utf-8")) + crypto_rev = "FETCH_HEAD" + else: + crypto_rev = version.crypto_revision + + checkout_output = subprocess.check_output( + [self.git_command, "checkout", crypto_rev], + cwd=os.path.join(git_worktree_path, "crypto"), + stderr=subprocess.STDOUT + ) + self.log.debug(checkout_output.decode("utf-8")) + + def _build_shared_libraries(self, git_worktree_path, version): + """Build the shared libraries in the specified worktree.""" + my_environment = os.environ.copy() + my_environment["CFLAGS"] = "-g -Og" + my_environment["SHARED"] = "1" + if os.path.exists(os.path.join(git_worktree_path, "crypto")): + my_environment["USE_CRYPTO_SUBMODULE"] = "1" + make_output = subprocess.check_output( + [self.make_command, "lib"], + env=my_environment, + cwd=git_worktree_path, + stderr=subprocess.STDOUT + ) + self.log.debug(make_output.decode("utf-8")) + for root, _dirs, files in os.walk(git_worktree_path): + for file in fnmatch.filter(files, "*.so"): + version.modules[os.path.splitext(file)[0]] = ( + os.path.join(root, file) + ) + + def _get_abi_dumps_from_shared_libraries(self, version): + """Generate the ABI dumps for the specified git revision. + The shared libraries must have been built and the module paths + present in version.modules.""" + for mbed_module, module_path in version.modules.items(): + output_path = os.path.join( + self.report_dir, "{}-{}-{}.dump".format( + mbed_module, version.revision, version.version + ) + ) + abi_dump_command = [ + "abi-dumper", + module_path, + "-o", output_path, + "-lver", version.revision + ] + abi_dump_output = subprocess.check_output( + abi_dump_command, + stderr=subprocess.STDOUT + ) + self.log.debug(abi_dump_output.decode("utf-8")) + version.abi_dumps[mbed_module] = output_path + + def _cleanup_worktree(self, git_worktree_path): + """Remove the specified git worktree.""" + shutil.rmtree(git_worktree_path) + worktree_output = subprocess.check_output( + [self.git_command, "worktree", "prune"], + cwd=self.repo_path, + stderr=subprocess.STDOUT + ) + self.log.debug(worktree_output.decode("utf-8")) + + def _get_abi_dump_for_ref(self, version): + """Generate the ABI dumps for the specified git revision.""" + git_worktree_path = self._get_clean_worktree_for_git_revision(version) + self._update_git_submodules(git_worktree_path, version) + self._build_shared_libraries(git_worktree_path, version) + self._get_abi_dumps_from_shared_libraries(version) + self._cleanup_worktree(git_worktree_path) + + def _remove_children_with_tag(self, parent, tag): + children = parent.getchildren() + for child in children: + if child.tag == tag: + parent.remove(child) + else: + self._remove_children_with_tag(child, tag) + + def _remove_extra_detail_from_report(self, report_root): + for tag in ['test_info', 'test_results', 'problem_summary', + 'added_symbols', 'affected']: + self._remove_children_with_tag(report_root, tag) + + for report in report_root: + for problems in report.getchildren()[:]: + if not problems.getchildren(): + report.remove(problems) + + def get_abi_compatibility_report(self): + """Generate a report of the differences between the reference ABI + and the new ABI. ABI dumps from self.old_version and self.new_version + must be available.""" + compatibility_report = "" + compliance_return_code = 0 + shared_modules = list(set(self.old_version.modules.keys()) & + set(self.new_version.modules.keys())) + for mbed_module in shared_modules: + output_path = os.path.join( + self.report_dir, "{}-{}-{}.html".format( + mbed_module, self.old_version.revision, + self.new_version.revision + ) + ) + abi_compliance_command = [ + "abi-compliance-checker", + "-l", mbed_module, + "-old", self.old_version.abi_dumps[mbed_module], + "-new", self.new_version.abi_dumps[mbed_module], + "-strict", + "-report-path", output_path, + ] + if self.skip_file: + abi_compliance_command += ["-skip-symbols", self.skip_file, + "-skip-types", self.skip_file] + if self.brief: + abi_compliance_command += ["-report-format", "xml", + "-stdout"] + try: + subprocess.check_output( + abi_compliance_command, + stderr=subprocess.STDOUT + ) + except subprocess.CalledProcessError as err: + if err.returncode == 1: + compliance_return_code = 1 + if self.brief: + self.log.info( + "Compatibility issues found for {}".format(mbed_module) + ) + report_root = ET.fromstring(err.output.decode("utf-8")) + self._remove_extra_detail_from_report(report_root) + self.log.info(ET.tostring(report_root).decode("utf-8")) + else: + self.can_remove_report_dir = False + compatibility_report += ( + "Compatibility issues found for {}, " + "for details see {}\n".format(mbed_module, output_path) + ) + else: + raise err + else: + compatibility_report += ( + "No compatibility issues for {}\n".format(mbed_module) + ) + if not (self.keep_all_reports or self.brief): + os.remove(output_path) + for version in [self.old_version, self.new_version]: + for mbed_module, mbed_module_dump in version.abi_dumps.items(): + os.remove(mbed_module_dump) + if self.can_remove_report_dir: + os.rmdir(self.report_dir) + self.log.info(compatibility_report) + return compliance_return_code + + def check_for_abi_changes(self): + """Generate a report of ABI differences + between self.old_rev and self.new_rev.""" + self.check_repo_path() + self.check_abi_tools_are_installed() + self._get_abi_dump_for_ref(self.old_version) + self._get_abi_dump_for_ref(self.new_version) + return self.get_abi_compatibility_report() + + +def run_main(): + try: + parser = argparse.ArgumentParser( + description=( + """This script is a small wrapper around the + abi-compliance-checker and abi-dumper tools, applying them + to compare the ABI and API of the library files from two + different Git revisions within an Mbed TLS repository. + The results of the comparison are either formatted as HTML and + stored at a configurable location, or are given as a brief list + of problems. Returns 0 on success, 1 on ABI/API non-compliance, + and 2 if there is an error while running the script. + Note: must be run from Mbed TLS root.""" + ) + ) + parser.add_argument( + "-v", "--verbose", action="store_true", + help="set verbosity level", + ) + parser.add_argument( + "-r", "--report-dir", type=str, default="reports", + help="directory where reports are stored, default is reports", + ) + parser.add_argument( + "-k", "--keep-all-reports", action="store_true", + help="keep all reports, even if there are no compatibility issues", + ) + parser.add_argument( + "-o", "--old-rev", type=str, help="revision for old version.", + required=True, + ) + parser.add_argument( + "-or", "--old-repo", type=str, help="repository for old version." + ) + parser.add_argument( + "-oc", "--old-crypto-rev", type=str, + help="revision for old crypto submodule." + ) + parser.add_argument( + "-ocr", "--old-crypto-repo", type=str, + help="repository for old crypto submodule." + ) + parser.add_argument( + "-n", "--new-rev", type=str, help="revision for new version", + required=True, + ) + parser.add_argument( + "-nr", "--new-repo", type=str, help="repository for new version." + ) + parser.add_argument( + "-nc", "--new-crypto-rev", type=str, + help="revision for new crypto version" + ) + parser.add_argument( + "-ncr", "--new-crypto-repo", type=str, + help="repository for new crypto submodule." + ) + parser.add_argument( + "-s", "--skip-file", type=str, + help="path to file containing symbols and types to skip" + ) + parser.add_argument( + "-b", "--brief", action="store_true", + help="output only the list of issues to stdout, instead of a full report", + ) + abi_args = parser.parse_args() + if os.path.isfile(abi_args.report_dir): + print("Error: {} is not a directory".format(abi_args.report_dir)) + parser.exit() + old_version = SimpleNamespace( + version="old", + repository=abi_args.old_repo, + revision=abi_args.old_rev, + crypto_repository=abi_args.old_crypto_repo, + crypto_revision=abi_args.old_crypto_rev, + abi_dumps={}, + modules={} + ) + new_version = SimpleNamespace( + version="new", + repository=abi_args.new_repo, + revision=abi_args.new_rev, + crypto_repository=abi_args.new_crypto_repo, + crypto_revision=abi_args.new_crypto_rev, + abi_dumps={}, + modules={} + ) + configuration = SimpleNamespace( + verbose=abi_args.verbose, + report_dir=abi_args.report_dir, + keep_all_reports=abi_args.keep_all_reports, + brief=abi_args.brief, + skip_file=abi_args.skip_file + ) + abi_check = AbiChecker(old_version, new_version, configuration) + return_code = abi_check.check_for_abi_changes() + sys.exit(return_code) + except Exception: # pylint: disable=broad-except + # Print the backtrace and exit explicitly so as to exit with + # status 2, not 1. + traceback.print_exc() + sys.exit(2) + + +if __name__ == "__main__": + run_main() diff --git a/3rdparty/mbedtls/mbedtls/scripts/config.pl b/3rdparty/mbedtls/mbedtls/scripts/config.pl index 468aeb93e1..ab4322bab3 100755 --- a/3rdparty/mbedtls/mbedtls/scripts/config.pl +++ b/3rdparty/mbedtls/mbedtls/scripts/config.pl @@ -29,6 +29,7 @@ # MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES # MBEDTLS_NO_PLATFORM_ENTROPY # MBEDTLS_REMOVE_ARC4_CIPHERSUITES +# MBEDTLS_REMOVE_3DES_CIPHERSUITES # MBEDTLS_SSL_HW_RECORD_ACCEL # MBEDTLS_RSA_NO_CRT # MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 @@ -89,6 +90,7 @@ MBEDTLS_NO_PLATFORM_ENTROPY MBEDTLS_RSA_NO_CRT MBEDTLS_REMOVE_ARC4_CIPHERSUITES +MBEDTLS_REMOVE_3DES_CIPHERSUITES MBEDTLS_SSL_HW_RECORD_ACCEL MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION diff --git a/3rdparty/mbedtls/mbedtls/tests/CMakeLists.txt b/3rdparty/mbedtls/mbedtls/tests/CMakeLists.txt index 9fd4916bbd..0f3c58f6a8 100644 --- a/3rdparty/mbedtls/mbedtls/tests/CMakeLists.txt +++ b/3rdparty/mbedtls/mbedtls/tests/CMakeLists.txt @@ -15,6 +15,13 @@ if(NOT PERL_FOUND) message(FATAL_ERROR "Cannot build test suites without Perl") endif() +# Test suites caught by SKIP_TEST_SUITES are built but not executed. +# "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar" +# but not "test_suite_foobar". +string(REGEX REPLACE "[ ,;]" "|" SKIP_TEST_SUITES_REGEX "${SKIP_TEST_SUITES}") +string(REPLACE "." "\\." SKIP_TEST_SUITES_REGEX "${SKIP_TEST_SUITES_REGEX}") +set(SKIP_TEST_SUITES_REGEX "^(${SKIP_TEST_SUITES_REGEX})(\$|\\.)") + function(add_test_suite suite_name) if(ARGV1) set(data_name ${ARGV1}) @@ -31,7 +38,11 @@ function(add_test_suite suite_name) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_executable(test_suite_${data_name} test_suite_${data_name}.c) target_link_libraries(test_suite_${data_name} ${libs}) - add_test(${data_name}-suite test_suite_${data_name} --verbose) + if(${data_name} MATCHES ${SKIP_TEST_SUITES_REGEX}) + message(STATUS "The test suite ${data_name} will not be executed.") + else() + add_test(${data_name}-suite test_suite_${data_name} --verbose) + endif() endfunction(add_test_suite) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) diff --git a/3rdparty/mbedtls/mbedtls/tests/Makefile b/3rdparty/mbedtls/mbedtls/tests/Makefile index d85617fdca..03f1a7f2fc 100644 --- a/3rdparty/mbedtls/mbedtls/tests/Makefile +++ b/3rdparty/mbedtls/mbedtls/tests/Makefile @@ -444,7 +444,8 @@ else del /Q /F *.c *.exe endif +# Test suites caught by SKIP_TEST_SUITES are built but not executed. check: $(APPS) - perl scripts/run-test-suites.pl + perl scripts/run-test-suites.pl --skip=$(SKIP_TEST_SUITES) test: check diff --git a/3rdparty/mbedtls/mbedtls/tests/compat.sh b/3rdparty/mbedtls/mbedtls/tests/compat.sh index a2b2d5ba12..df499dcf01 100755 --- a/3rdparty/mbedtls/mbedtls/tests/compat.sh +++ b/3rdparty/mbedtls/mbedtls/tests/compat.sh @@ -53,7 +53,12 @@ MODES="tls1 tls1_1 tls1_2 dtls1 dtls1_2" VERIFIES="NO YES" TYPES="ECDSA RSA PSK" FILTER="" -EXCLUDE='NULL\|DES-CBC-\|RC4\|ARCFOUR' # avoid plain DES but keep 3DES-EDE-CBC (mbedTLS), DES-CBC3 (OpenSSL) +# exclude: +# - NULL: excluded from our default config +# - RC4, single-DES: requires legacy OpenSSL/GnuTLS versions +# avoid plain DES but keep 3DES-EDE-CBC (mbedTLS), DES-CBC3 (OpenSSL) +# - 3DES: not in default config +EXCLUDE='NULL\|DES\|RC4\|ARCFOUR' VERBOSE="" MEMCHECK=0 PEERS="OpenSSL$PEER_GNUTLS mbedTLS" diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/Makefile b/3rdparty/mbedtls/mbedtls/tests/data_files/Makefile index 2a7a50c2e1..c10020c040 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/Makefile +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/Makefile @@ -14,6 +14,7 @@ OPENSSL ?= openssl FAKETIME ?= faketime MBEDTLS_CERT_WRITE ?= $(PWD)/../../programs/x509/cert_write +MBEDTLS_CERT_REQ ?= $(PWD)/../../programs/x509/cert_req ## Build the generated test data. Note that since the final outputs ## are committed to the repository, this target should do nothing on a @@ -701,6 +702,37 @@ ec_prv.pk8param.pem: ec_prv.pk8param.der $(OPENSSL) pkey -in $< -inform DER -out $@ all_final += ec_prv.pk8param.pem +# server5* + +# The use of 'Server 1' in the DN is intentional here, as the DN is hardcoded in the x509_write test suite.' +server5.req.ku.sha1: server5.key + $(MBEDTLS_CERT_REQ) output_file=$@ filename=$< key_usage=digital_signature,non_repudiation subject_name="C=NL,O=PolarSSL,CN=PolarSSL Server 1" md=SHA1 +all_final += server5.req.ku.sha1 + +################################################################ +### Generate CSRs for X.509 write test suite +################################################################ + +server1.req.cert_type: server1.key + $(MBEDTLS_CERT_REQ) output_file=$@ filename=$< ns_cert_type=ssl_server subject_name="C=NL,O=PolarSSL,CN=PolarSSL Server 1" md=SHA1 +all_final += server1.req.cert_type + +server1.req.key_usage: server1.key + $(MBEDTLS_CERT_REQ) output_file=$@ filename=$< key_usage=digital_signature,non_repudiation,key_encipherment subject_name="C=NL,O=PolarSSL,CN=PolarSSL Server 1" md=SHA1 +all_final += server1.req.key_usage + +server1.req.ku-ct: server1.key + $(MBEDTLS_CERT_REQ) output_file=$@ filename=$< key_usage=digital_signature,non_repudiation,key_encipherment ns_cert_type=ssl_server subject_name="C=NL,O=PolarSSL,CN=PolarSSL Server 1" md=SHA1 +all_final += server1.req.ku-ct + +server1.req.key_usage_empty: server1.key + $(MBEDTLS_CERT_REQ) output_file=$@ filename=$< subject_name="C=NL,O=PolarSSL,CN=PolarSSL Server 1" md=SHA1 force_key_usage=1 +all_final += server1.req.key_usage_empty + +server1.req.cert_type_empty: server1.key + $(MBEDTLS_CERT_REQ) output_file=$@ filename=$< subject_name="C=NL,O=PolarSSL,CN=PolarSSL Server 1" md=SHA1 force_ns_cert_type=1 +all_final += server1.req.cert_type_empty + ################################################################ ### Generate certificates for CRT write check tests ################################################################ @@ -776,7 +808,33 @@ server1.v1.der.openssl: server1.v1.crt.openssl server1_all: server1.csr server1.crt server1.noauthid.crt server1.crt.openssl server1.v1.crt server1.v1.crt.openssl server1.key_usage.crt server1.key_usage_noauthid.crt server1.key_usage.crt.openssl server1.cert_type.crt server1.cert_type_noauthid.crt server1.cert_type.crt.openssl server1.der server1.der.openssl server1.v1.der server1.v1.der.openssl server1.key_usage.der server1.key_usage.der.openssl server1.cert_type.der server1.cert_type.der.openssl +# MD2, MD4, MD5 test certificates + +cert_md_test_key = $(cli_crt_key_file_rsa) + +cert_md2.csr: $(cert_md_test_key) + $(MBEDTLS_CERT_REQ) output_file=$@ filename=$< subject_name="C=NL,O=PolarSSL,CN=PolarSSL Cert MD2" md=MD2 +all_intermediate += cert_md2.csr + +cert_md2.crt: cert_md2.csr + $(MBEDTLS_CERT_WRITE) request_file=$< serial=9 issuer_crt=$(test_ca_crt) issuer_key=$(test_ca_key_file_rsa) issuer_pwd=$(test_ca_pwd_rsa) not_before=20000101121212 not_after=20300101121212 md=MD2 version=3 output_file=$@ +all_final += cert_md2.crt + +cert_md4.csr: $(cert_md_test_key) + $(MBEDTLS_CERT_REQ) output_file=$@ filename=$< subject_name="C=NL,O=PolarSSL,CN=PolarSSL Cert MD4" md=MD4 +all_intermediate += cert_md4.csr + +cert_md4.crt: cert_md4.csr + $(MBEDTLS_CERT_WRITE) request_file=$< serial=5 issuer_crt=$(test_ca_crt) issuer_key=$(test_ca_key_file_rsa) issuer_pwd=$(test_ca_pwd_rsa) not_before=20000101121212 not_after=20300101121212 md=MD4 version=3 output_file=$@ +all_final += cert_md4.crt + +cert_md5.csr: $(cert_md_test_key) + $(MBEDTLS_CERT_REQ) output_file=$@ filename=$< subject_name="C=NL,O=PolarSSL,CN=PolarSSL Cert MD5" md=MD5 +all_intermediate += cert_md5.csr +cert_md5.crt: cert_md5.csr + $(MBEDTLS_CERT_WRITE) request_file=$< serial=6 issuer_crt=$(test_ca_crt) issuer_key=$(test_ca_key_file_rsa) issuer_pwd=$(test_ca_pwd_rsa) not_before=20000101121212 not_after=20300101121212 md=MD5 version=3 output_file=$@ +all_final += cert_md5.crt ################################################################ #### Meta targets diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md2.crt b/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md2.crt index bfea77b6f3..94b89afce3 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md2.crt +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md2.crt @@ -1,77 +1,20 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 9 (0x9) - Signature Algorithm: md2WithRSAEncryption - Issuer: C=NL, O=PolarSSL, CN=PolarSSL Test CA - Validity - Not Before: Jul 12 10:56:59 2009 GMT - Not After : Jul 12 10:56:59 2011 GMT - Subject: C=NL, O=PolarSSL, CN=PolarSSL Cert MD2 - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - RSA Public Key: (2048 bit) - Modulus (2048 bit): - 00:dc:13:74:81:c6:12:f6:67:5d:a1:66:72:ed:dc: - 79:b6:58:5c:32:58:b3:d4:14:fd:6c:02:61:9e:0b: - 99:46:63:a3:0a:41:d4:42:33:21:e6:ed:43:07:5a: - 1d:a2:3b:64:29:a8:2a:c1:66:28:00:59:d8:0c:49: - 2d:30:b7:3d:8c:bb:60:62:31:83:27:7f:4b:95:92: - 2e:a0:d6:c6:84:94:4b:b3:e4:a6:cc:ff:32:3a:c5: - ec:4c:c9:24:58:bf:b3:33:77:6a:b5:17:8b:02:10: - 29:8e:95:aa:91:60:17:43:42:87:a8:7c:da:09:83: - 98:9d:7a:65:5e:20:52:07:2e:65:a5:31:fd:d9:74: - 1e:00:c9:ae:9d:81:56:8b:08:0a:f5:1e:9c:dc:a2: - 5e:6c:db:ff:11:83:15:f4:d1:24:57:9b:0f:eb:35: - c9:f1:aa:46:4e:74:7f:fe:1d:b0:91:1f:89:4a:84: - cb:df:75:e3:cd:77:82:62:09:e5:9f:6d:29:de:2e: - 25:d8:48:b6:20:be:51:97:4c:2d:20:65:2d:2a:50: - 9e:24:5d:72:95:e0:a2:06:41:8c:61:e4:50:57:74: - 96:b1:29:b5:a1:88:37:f1:5c:9e:b2:9e:8e:83:8d: - 72:3b:b5:5c:fe:bb:12:89:72:5c:a1:f9:d8:18:29: - b2:27 - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - X509v3 Subject Key Identifier: - B7:51:D4:E5:20:D5:45:54:F4:C5:51:1B:E0:82:B5:61:05:AF:9B:B6 - X509v3 Authority Key Identifier: - keyid:CF:22:31:27:91:D8:C2:54:FF:1E:DA:D9:EE:8A:C5:89:32:AD:0C:21 - - Signature Algorithm: md2WithRSAEncryption - 28:5a:dd:48:fb:ec:80:fe:de:b7:20:c0:4c:05:a9:4b:51:e9: - a7:d1:4b:5e:76:42:d2:5d:9a:14:19:3b:cb:f9:91:d7:0f:11: - c9:cd:dd:00:8b:2c:76:73:22:a0:19:49:81:63:40:30:48:27: - 62:90:ca:b8:dc:33:35:b3:4b:58:ca:dc:07:66:87:2e:ea:44: - 2a:6a:13:67:7a:32:5e:48:1d:88:88:c5:70:e6:e7:ec:1b:2f: - a7:f4:61:71:29:f6:66:93:30:60:7e:b3:4c:01:c8:2c:53:ce: - 00:11:ec:bf:f6:f2:ce:51:97:d8:ed:ed:dc:c9:6b:b8:19:15: - c8:9a:61:6d:12:9a:99:25:d8:03:1d:a6:4c:20:a5:f8:46:a3: - 05:32:bb:1a:8e:1a:65:0d:f3:13:35:1d:6f:73:28:31:12:d7: - c4:9e:73:a0:a7:ce:82:25:d1:40:e8:1b:77:60:f3:3e:81:7f: - 19:ee:cf:97:4d:c8:c3:35:9b:72:98:3b:c3:35:43:14:0a:04: - 21:7b:f7:db:e6:5f:ce:21:d1:ce:bf:b7:ef:c1:63:21:c2:78: - e1:37:aa:b1:e0:31:b3:b6:63:4c:fd:66:c8:e6:cf:f8:d9:97: - 2f:cf:92:81:3f:d4:bf:ec:e2:ad:6e:39:c7:a6:a8:e0:32:b0: - 2e:0d:e1:30 -----BEGIN CERTIFICATE----- MIIDPzCCAiegAwIBAgIBCTANBgkqhkiG9w0BAQIFADA7MQswCQYDVQQGEwJOTDER -MA8GA1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwHhcN -MDkwNzEyMTA1NjU5WhcNMTEwNzEyMTA1NjU5WjA8MQswCQYDVQQGEwJOTDERMA8G -A1UEChMIUG9sYXJTU0wxGjAYBgNVBAMTEVBvbGFyU1NMIENlcnQgTUQyMIIBIjAN -BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3BN0gcYS9mddoWZy7dx5tlhcMliz -1BT9bAJhnguZRmOjCkHUQjMh5u1DB1odojtkKagqwWYoAFnYDEktMLc9jLtgYjGD -J39LlZIuoNbGhJRLs+SmzP8yOsXsTMkkWL+zM3dqtReLAhApjpWqkWAXQ0KHqHza -CYOYnXplXiBSBy5lpTH92XQeAMmunYFWiwgK9R6c3KJebNv/EYMV9NEkV5sP6zXJ -8apGTnR//h2wkR+JSoTL33XjzXeCYgnln20p3i4l2Ei2IL5Rl0wtIGUtKlCeJF1y -leCiBkGMYeRQV3SWsSm1oYg38Vyesp6Og41yO7Vc/rsSiXJcofnYGCmyJwIDAQAB -o00wSzAJBgNVHRMEAjAAMB0GA1UdDgQWBBS3UdTlINVFVPTFURvggrVhBa+btjAf -BgNVHSMEGDAWgBTPIjEnkdjCVP8e2tnuisWJMq0MITANBgkqhkiG9w0BAQIFAAOC -AQEAKFrdSPvsgP7etyDATAWpS1Hpp9FLXnZC0l2aFBk7y/mR1w8Ryc3dAIssdnMi -oBlJgWNAMEgnYpDKuNwzNbNLWMrcB2aHLupEKmoTZ3oyXkgdiIjFcObn7Bsvp/Rh -cSn2ZpMwYH6zTAHILFPOABHsv/byzlGX2O3t3MlruBkVyJphbRKamSXYAx2mTCCl -+EajBTK7Go4aZQ3zEzUdb3MoMRLXxJ5zoKfOgiXRQOgbd2DzPoF/Ge7Pl03IwzWb -cpg7wzVDFAoEIXv32+ZfziHRzr+378FjIcJ44TeqseAxs7ZjTP1myObP+NmXL8+S -gT/Uv+zirW45x6ao4DKwLg3hMA== +MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN +MDAwMTAxMTIxMjEyWhcNMzAwMTAxMTIxMjEyWjA8MQswCQYDVQQGEwJOTDERMA8G +A1UECgwIUG9sYXJTU0wxGjAYBgNVBAMMEVBvbGFyU1NMIENlcnQgTUQyMIIBIjAN +BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyHTEzLn5tXnpRdkUYLB9u5Pyax6f +M60Nj4o8VmXl3ETZzGaFB9X4J7BKNdBjngpuG7fa8H6r7gwQk4ZJGDTzqCrSV/Uu +1C93KYRhTYJQj6eVSHD1bk2y1RPD0hrt5kPqQhTrdOrA7R/UV06p86jt0uDBMHEw +MjDV0/YI0FZPRo7yX/k9Z5GIMC5Cst99++UMd//sMcB4j7/Cf8qtbCHWjdmLao5v +4Jv4EFbMs44TFeY0BGbH7vk2DmqV9gmaBmf0ZXH4yqSxJeD+PIs1BGe64E92hfx/ +/DZrtenNLQNiTrM9AM+vdqBpVoNq0qjU51Bx5rU2BXcFbXvI5MT9TNUhXwIDAQAB +o00wSzAJBgNVHRMEAjAAMB0GA1UdDgQWBBRxoQBzckAvVHZeM/xSj7zx3WtGITAf +BgNVHSMEGDAWgBS0WuSls97SUva51aaVD+s+vMf9/zANBgkqhkiG9w0BAQIFAAOC +AQEAXLWqy34iaZ2YV+5eE1QMV/9m9nQI2X/yumRH1MT1R3oYde/YDV7+HSOM6qLs +qSgH1DSyXv1YnJww2OyTtAVhPalICLjVjUQCyeUCiFpAIO6Xz1VE6v4GMFLqhlV1 +Nox9dDtR5Go2zwPaH64Ze9GxuDZfW+VnPRNgYOrqqCBnuhnp2uPRfOewus2AAo50 +dx1XTooCEqElQlB9EIPWbvPdJZjRjruCUtDbz+oxG4J4Ml4KCYm+/MyXNPqxV9+H +5A9oQltuHMWasMWSfXeimQI5PPpdjndmJOhfT4RGmvTw/uNC/Xuy1kPxXQKoocz6 +93U8RQvyJxdIPtQuARNMRZ7G+Q== -----END CERTIFICATE----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md4.crt b/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md4.crt index 16f166b815..7d0f7cb1b4 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md4.crt +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md4.crt @@ -1,77 +1,20 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 5 (0x5) - Signature Algorithm: md4WithRSAEncryption - Issuer: C=NL, O=PolarSSL, CN=PolarSSL Test CA - Validity - Not Before: Feb 12 14:44:07 2011 GMT - Not After : Feb 12 14:44:07 2021 GMT - Subject: C=NL, O=PolarSSL, CN=PolarSSL Cert MD4 - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - RSA Public Key: (2048 bit) - Modulus (2048 bit): - 00:b9:3c:4a:c5:c8:a3:8e:90:17:a4:9e:52:aa:71: - 75:26:61:80:e7:c7:b5:6d:8c:ff:aa:b6:41:26:b7: - be:11:ad:5c:73:16:0c:64:11:48:04:ff:d6:e1:3b: - 05:db:89:bb:b3:97:09:d5:1c:14:dd:68:87:39:b0: - 3d:71:cb:e2:76:d0:1a:d8:18:2d:80:1b:54:f6:e5: - 44:9a:f1:cb:af:61:2e:df:49:0d:9d:09:b7:ed:b1: - fd:3c:fd:3c:fa:24:cf:5d:bf:7c:e4:53:e7:25:b5: - ea:44:22:e9:26:d3:ea:20:94:9e:e6:61:67:ba:2e: - 07:67:0b:03:2f:a2:09:ed:f0:33:8f:0b:ce:10:ef: - 67:a4:c6:08:da:c1:ed:c2:3f:d7:4a:dd:15:3d:f9: - 5e:1c:81:60:46:3e:b5:b3:3d:2f:a6:de:47:1c:bc: - 92:ae:eb:df:27:6b:16:56:b7:dc:ec:d1:55:57:a5: - 6e:ec:75:25:f5:b7:7b:df:ab:d2:3a:5a:91:98:7d: - 97:17:0b:13:0a:a7:6b:4a:8b:c1:47:30:fb:3a:f8: - 41:04:d5:c1:df:b8:1d:bf:7b:01:a5:65:a2:e0:1e: - 36:b7:a6:5c:cc:30:5a:f8:cd:6f:cd:f1:19:62:25: - ca:01:e3:35:7f:fa:20:f5:dc:fd:69:b2:6a:00:7d: - 17:f7 - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - X509v3 Subject Key Identifier: - 7D:E4:9C:6B:E6:F9:71:7D:46:D2:12:3D:AD:6B:1D:FD:C2:AA:78:4C - X509v3 Authority Key Identifier: - keyid:B4:5A:E4:A5:B3:DE:D2:52:F6:B9:D5:A6:95:0F:EB:3E:BC:C7:FD:FF - - Signature Algorithm: md4WithRSAEncryption - 94:db:e1:86:71:2d:43:d6:51:61:a7:95:bc:e8:73:da:ff:e4: - fd:41:0f:5c:de:14:f4:c4:ba:5d:2c:30:2c:a6:dc:2d:e8:87: - 45:f1:c5:fe:d1:4a:64:99:19:09:2f:72:7c:3f:8d:c8:31:22: - dd:0a:69:03:3d:12:8c:4d:c3:f7:a3:c5:d1:5d:c9:ff:4b:83: - 6b:d6:b4:e5:d8:ce:94:5e:ec:bf:68:c5:b2:63:8e:5c:cb:f3: - 8d:62:73:82:62:7e:df:db:7d:0b:8d:21:10:db:9a:a1:62:4d: - 46:42:d1:bb:38:32:ef:c1:fc:a1:e2:7f:60:08:37:32:20:2c: - 7c:a2:c9:12:0d:89:fe:2b:15:08:91:79:e2:a9:79:a4:da:cd: - 81:43:01:e2:09:2d:1a:f4:16:ef:af:4d:50:46:5e:2d:dd:48: - 27:10:c0:42:b7:a5:9e:c2:1f:6e:50:36:03:ed:95:77:9a:a3: - d9:4c:d7:23:93:b1:24:2a:63:27:28:7a:de:3d:59:d2:92:c8: - 8f:f6:39:1d:65:ab:09:78:05:46:90:a9:f6:10:b1:ef:c8:8c: - 4d:7d:8d:f2:78:b7:88:15:09:7e:df:e9:87:a8:64:c1:95:53: - fb:da:05:b7:62:bc:ad:fb:d9:a4:a9:06:6c:6b:98:01:b9:39: - 78:d3:4e:87 -----BEGIN CERTIFICATE----- MIIDPzCCAiegAwIBAgIBBTANBgkqhkiG9w0BAQMFADA7MQswCQYDVQQGEwJOTDER -MA8GA1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwHhcN -MTEwMjEyMTQ0NDA3WhcNMjEwMjEyMTQ0NDA3WjA8MQswCQYDVQQGEwJOTDERMA8G -A1UEChMIUG9sYXJTU0wxGjAYBgNVBAMTEVBvbGFyU1NMIENlcnQgTUQ0MIIBIjAN -BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuTxKxcijjpAXpJ5SqnF1JmGA58e1 -bYz/qrZBJre+Ea1ccxYMZBFIBP/W4TsF24m7s5cJ1RwU3WiHObA9ccvidtAa2Bgt -gBtU9uVEmvHLr2Eu30kNnQm37bH9PP08+iTPXb985FPnJbXqRCLpJtPqIJSe5mFn -ui4HZwsDL6IJ7fAzjwvOEO9npMYI2sHtwj/XSt0VPfleHIFgRj61sz0vpt5HHLyS -ruvfJ2sWVrfc7NFVV6Vu7HUl9bd736vSOlqRmH2XFwsTCqdrSovBRzD7OvhBBNXB -37gdv3sBpWWi4B42t6ZczDBa+M1vzfEZYiXKAeM1f/og9dz9abJqAH0X9wIDAQAB -o00wSzAJBgNVHRMEAjAAMB0GA1UdDgQWBBR95Jxr5vlxfUbSEj2tax39wqp4TDAf +MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN +MDAwMTAxMTIxMjEyWhcNMzAwMTAxMTIxMjEyWjA8MQswCQYDVQQGEwJOTDERMA8G +A1UECgwIUG9sYXJTU0wxGjAYBgNVBAMMEVBvbGFyU1NMIENlcnQgTUQ0MIIBIjAN +BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyHTEzLn5tXnpRdkUYLB9u5Pyax6f +M60Nj4o8VmXl3ETZzGaFB9X4J7BKNdBjngpuG7fa8H6r7gwQk4ZJGDTzqCrSV/Uu +1C93KYRhTYJQj6eVSHD1bk2y1RPD0hrt5kPqQhTrdOrA7R/UV06p86jt0uDBMHEw +MjDV0/YI0FZPRo7yX/k9Z5GIMC5Cst99++UMd//sMcB4j7/Cf8qtbCHWjdmLao5v +4Jv4EFbMs44TFeY0BGbH7vk2DmqV9gmaBmf0ZXH4yqSxJeD+PIs1BGe64E92hfx/ +/DZrtenNLQNiTrM9AM+vdqBpVoNq0qjU51Bx5rU2BXcFbXvI5MT9TNUhXwIDAQAB +o00wSzAJBgNVHRMEAjAAMB0GA1UdDgQWBBRxoQBzckAvVHZeM/xSj7zx3WtGITAf BgNVHSMEGDAWgBS0WuSls97SUva51aaVD+s+vMf9/zANBgkqhkiG9w0BAQMFAAOC -AQEAlNvhhnEtQ9ZRYaeVvOhz2v/k/UEPXN4U9MS6XSwwLKbcLeiHRfHF/tFKZJkZ -CS9yfD+NyDEi3QppAz0SjE3D96PF0V3J/0uDa9a05djOlF7sv2jFsmOOXMvzjWJz -gmJ+39t9C40hENuaoWJNRkLRuzgy78H8oeJ/YAg3MiAsfKLJEg2J/isVCJF54ql5 -pNrNgUMB4gktGvQW769NUEZeLd1IJxDAQrelnsIfblA2A+2Vd5qj2UzXI5OxJCpj -Jyh63j1Z0pLIj/Y5HWWrCXgFRpCp9hCx78iMTX2N8ni3iBUJft/ph6hkwZVT+9oF -t2K8rfvZpKkGbGuYAbk5eNNOhw== +AQEArXIW7Dy1hBXMKY8/TAfACqkFZzbGDJdD5ohQknENk6FzUHVw9SVibhi5J+nh +/mhUhoczFg78T8ZopDcsPHKQTuy0LNcLWhZDD4S4CJCibmsf+8BWmPcSp1tsS9Zj +etO5qNuUarL74W+rRa3qQcCXcglYTubv/PcCV+LGVqZ4XDlO5EBFJJREAREzG+iK +Epm2y0mi1WTwjy7m7rxYHs5i5ybDHDDwU55H5wh50Vs4/vDx2kZab2K9gx6V2ggY +CCYmRWKQHdI4XZBkpYFbbREZxMY4Y5c2PUMlr8GUq6s6eu9/GvmnIx/+EySSfxgv +9GpN+gnyx03hjYNGO7iX8nPnXA== -----END CERTIFICATE----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md5.crt b/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md5.crt index 13d43f1acb..e514fd631c 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md5.crt +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/cert_md5.crt @@ -1,77 +1,20 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 6 (0x6) - Signature Algorithm: md5WithRSAEncryption - Issuer: C=NL, O=PolarSSL, CN=PolarSSL Test CA - Validity - Not Before: Feb 12 14:44:07 2011 GMT - Not After : Feb 12 14:44:07 2021 GMT - Subject: C=NL, O=PolarSSL, CN=PolarSSL Cert MD5 - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - RSA Public Key: (2048 bit) - Modulus (2048 bit): - 00:b9:3c:4a:c5:c8:a3:8e:90:17:a4:9e:52:aa:71: - 75:26:61:80:e7:c7:b5:6d:8c:ff:aa:b6:41:26:b7: - be:11:ad:5c:73:16:0c:64:11:48:04:ff:d6:e1:3b: - 05:db:89:bb:b3:97:09:d5:1c:14:dd:68:87:39:b0: - 3d:71:cb:e2:76:d0:1a:d8:18:2d:80:1b:54:f6:e5: - 44:9a:f1:cb:af:61:2e:df:49:0d:9d:09:b7:ed:b1: - fd:3c:fd:3c:fa:24:cf:5d:bf:7c:e4:53:e7:25:b5: - ea:44:22:e9:26:d3:ea:20:94:9e:e6:61:67:ba:2e: - 07:67:0b:03:2f:a2:09:ed:f0:33:8f:0b:ce:10:ef: - 67:a4:c6:08:da:c1:ed:c2:3f:d7:4a:dd:15:3d:f9: - 5e:1c:81:60:46:3e:b5:b3:3d:2f:a6:de:47:1c:bc: - 92:ae:eb:df:27:6b:16:56:b7:dc:ec:d1:55:57:a5: - 6e:ec:75:25:f5:b7:7b:df:ab:d2:3a:5a:91:98:7d: - 97:17:0b:13:0a:a7:6b:4a:8b:c1:47:30:fb:3a:f8: - 41:04:d5:c1:df:b8:1d:bf:7b:01:a5:65:a2:e0:1e: - 36:b7:a6:5c:cc:30:5a:f8:cd:6f:cd:f1:19:62:25: - ca:01:e3:35:7f:fa:20:f5:dc:fd:69:b2:6a:00:7d: - 17:f7 - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - X509v3 Subject Key Identifier: - 7D:E4:9C:6B:E6:F9:71:7D:46:D2:12:3D:AD:6B:1D:FD:C2:AA:78:4C - X509v3 Authority Key Identifier: - keyid:B4:5A:E4:A5:B3:DE:D2:52:F6:B9:D5:A6:95:0F:EB:3E:BC:C7:FD:FF - - Signature Algorithm: md5WithRSAEncryption - 92:13:81:0c:ff:ac:ab:98:52:6c:28:c9:c6:3e:80:c6:ec:77: - d0:13:e1:a2:29:1d:2f:b7:c5:95:41:83:60:d9:50:9c:d0:d6: - 09:f7:0f:97:cd:c0:e6:b2:68:fa:31:c9:2a:a3:d3:1e:53:ae: - 79:dc:35:ba:b0:d9:e5:7a:37:1b:2a:92:fa:d2:59:90:43:1b: - 6a:91:c1:db:36:da:e9:39:d3:f5:ac:e3:46:01:ca:55:04:17: - 1a:b1:97:28:e8:ff:1b:e7:e1:10:c9:b5:31:d8:ce:a6:89:6a: - 4a:df:78:7b:02:2f:83:b3:41:d5:ef:0b:b6:44:ff:32:a6:cf: - 1b:c2:f4:b0:75:66:a9:da:6f:7c:a5:e3:c6:c1:3a:2f:bf:f8: - 12:6f:04:2c:37:f2:4e:fc:b9:09:ff:a4:5b:40:19:e9:58:91: - 64:82:d6:ad:b9:7f:c0:12:c2:ce:b7:b6:ba:fb:10:a2:3f:74: - 97:10:39:d4:dc:4a:e5:5c:f7:e5:3a:d9:68:d7:17:6b:f5:51: - 08:b4:a2:30:0d:cc:36:10:6d:4e:1d:22:cc:48:d1:38:44:ba: - cc:2b:47:99:f7:c6:8b:41:24:f3:f1:2c:10:1a:f2:88:bb:b2: - e0:fd:44:26:3d:ad:ea:af:1d:d0:00:56:41:4e:f4:b0:3b:9d: - 32:6f:48:c7 -----BEGIN CERTIFICATE----- MIIDPzCCAiegAwIBAgIBBjANBgkqhkiG9w0BAQQFADA7MQswCQYDVQQGEwJOTDER -MA8GA1UEChMIUG9sYXJTU0wxGTAXBgNVBAMTEFBvbGFyU1NMIFRlc3QgQ0EwHhcN -MTEwMjEyMTQ0NDA3WhcNMjEwMjEyMTQ0NDA3WjA8MQswCQYDVQQGEwJOTDERMA8G -A1UEChMIUG9sYXJTU0wxGjAYBgNVBAMTEVBvbGFyU1NMIENlcnQgTUQ1MIIBIjAN -BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuTxKxcijjpAXpJ5SqnF1JmGA58e1 -bYz/qrZBJre+Ea1ccxYMZBFIBP/W4TsF24m7s5cJ1RwU3WiHObA9ccvidtAa2Bgt -gBtU9uVEmvHLr2Eu30kNnQm37bH9PP08+iTPXb985FPnJbXqRCLpJtPqIJSe5mFn -ui4HZwsDL6IJ7fAzjwvOEO9npMYI2sHtwj/XSt0VPfleHIFgRj61sz0vpt5HHLyS -ruvfJ2sWVrfc7NFVV6Vu7HUl9bd736vSOlqRmH2XFwsTCqdrSovBRzD7OvhBBNXB -37gdv3sBpWWi4B42t6ZczDBa+M1vzfEZYiXKAeM1f/og9dz9abJqAH0X9wIDAQAB -o00wSzAJBgNVHRMEAjAAMB0GA1UdDgQWBBR95Jxr5vlxfUbSEj2tax39wqp4TDAf +MA8GA1UECgwIUG9sYXJTU0wxGTAXBgNVBAMMEFBvbGFyU1NMIFRlc3QgQ0EwHhcN +MDAwMTAxMTIxMjEyWhcNMzAwMTAxMTIxMjEyWjA8MQswCQYDVQQGEwJOTDERMA8G +A1UECgwIUG9sYXJTU0wxGjAYBgNVBAMMEVBvbGFyU1NMIENlcnQgTUQ1MIIBIjAN +BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyHTEzLn5tXnpRdkUYLB9u5Pyax6f +M60Nj4o8VmXl3ETZzGaFB9X4J7BKNdBjngpuG7fa8H6r7gwQk4ZJGDTzqCrSV/Uu +1C93KYRhTYJQj6eVSHD1bk2y1RPD0hrt5kPqQhTrdOrA7R/UV06p86jt0uDBMHEw +MjDV0/YI0FZPRo7yX/k9Z5GIMC5Cst99++UMd//sMcB4j7/Cf8qtbCHWjdmLao5v +4Jv4EFbMs44TFeY0BGbH7vk2DmqV9gmaBmf0ZXH4yqSxJeD+PIs1BGe64E92hfx/ +/DZrtenNLQNiTrM9AM+vdqBpVoNq0qjU51Bx5rU2BXcFbXvI5MT9TNUhXwIDAQAB +o00wSzAJBgNVHRMEAjAAMB0GA1UdDgQWBBRxoQBzckAvVHZeM/xSj7zx3WtGITAf BgNVHSMEGDAWgBS0WuSls97SUva51aaVD+s+vMf9/zANBgkqhkiG9w0BAQQFAAOC -AQEAkhOBDP+sq5hSbCjJxj6Axux30BPhoikdL7fFlUGDYNlQnNDWCfcPl83A5rJo -+jHJKqPTHlOuedw1urDZ5Xo3GyqS+tJZkEMbapHB2zba6TnT9azjRgHKVQQXGrGX -KOj/G+fhEMm1MdjOpolqSt94ewIvg7NB1e8LtkT/MqbPG8L0sHVmqdpvfKXjxsE6 -L7/4Em8ELDfyTvy5Cf+kW0AZ6ViRZILWrbl/wBLCzre2uvsQoj90lxA51NxK5Vz3 -5TrZaNcXa/VRCLSiMA3MNhBtTh0izEjROES6zCtHmffGi0Ek8/EsEBryiLuy4P1E -Jj2t6q8d0ABWQU70sDudMm9Ixw== +AQEAF4QcMshVtVbYgvvU7f2lWakubbAISM/k+FW/f7u63m0MSSoSFeYflBOC1Wf4 +imgDEnWcWTH5V7sxsLNogxfpfTuFUaKfHeQmRhAK4UgqbDEs4dZvgo3wZ/w92G0/ +QNntJefnqaFiITXZTn6J8hxeoEq4QbucbWgeY6fTAwXtIv40BvMOSakkuIFAyIvV +90VY1j4vnx0/xv5lIBAxah1HdtXhqtDu/sUfdCtWX5SCcVUwwM3gZ4Q1ZdWQmlvF +737ZG7XaINxsDaI04sJxc7qvuRYhLdCwUPnZL5TGEQJ8jNa/39eEbnkvs7hbTU98 +6qG8UAYsSI7aMe1j7DZpkoPL9w== -----END CERTIFICATE----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/server1-ms.req.sha256 b/3rdparty/mbedtls/mbedtls/tests/data_files/server1-ms.req.sha256 new file mode 100644 index 0000000000..b0d9414a25 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/server1-ms.req.sha256 @@ -0,0 +1,16 @@ +-----BEGIN NEW CERTIFICATE REQUEST----- +MIICgTCCAWkCAQAwPDELMAkGA1UEBhMCTkwxETAPBgNVBAoTCFBvbGFyU1NMMRow +GAYDVQQDExFQb2xhclNTTCBTZXJ2ZXIgMTCCASIwDQYJKoZIhvcNAQEBBQADggEP +ADCCAQoCggEBAKkCHz1AatVVU4v9Nu6CZS4VYV6Jv7joRZDb7ogWUtPxQ1BHlhJZ +ZIdr/SvgRvlzvt3PkuGRW+1moG+JKXlFgNCDatVBQ3dfOXwJBEeCsFc5cO2j7BUZ +HqgzCEfBBUKp/UzDtN/dBh9NEFFAZ3MTD0D4bYElXwqxU8YwfhU5rPla7n+SnqYF +W+cTl4W1I5LZ1CQG1QkliXUH3aYajz8JGb6tZSxk65Wb3P5BXhem2mxbacwCuhQs +FiScStzN0PdSZ3PxLaAj/X70McotcMqJCwTbLqZPcG6ezr1YieJTWZ5uWpJl4og/ +DJQZo93l6J2VE+0p26twEtxaymsXq1KCVLECAwEAAaAAMA0GCSqGSIb3DQEBCwUA +A4IBAQBY/1nnYQ3ThVyeZb1Z2wLYoHZ5rfeJCedyP7N/gjJZjhrMbwioUft2uHpb ++OZQfxRXJTbtj/1wpRMCoUMLWzapS7/xGx3IjoPtl42aM4M+xVYvbLjExL13kUAr +eE4JWcMIbTEPol2zSdX/LuB+m27jEp5VsvM2ty9qOw/T4iKwjFSe6pcYZ2spks19 +3ltgjnaamwqKcN9zUA3IERTsWjr5exKYgfXm2OeeuSP0tHr7Dh+w/2XA9dGcLhrm +TA4P8QjIgSDlyzmhYYmsrioFPuCfdi1uzs8bxmbLXbiCGZ8TDMy5oLqLo1K+j2pF +ox+ATHKxQ/XpRQP+2OTb9sw1kM59 +-----END NEW CERTIFICATE REQUEST----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.cert_type.crt b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.cert_type.crt index 91c3a90213..107328edf0 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.cert_type.crt +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.cert_type.crt @@ -11,10 +11,10 @@ lZvc/kFeF6babFtpzAK6FCwWJJxK3M3Q91Jnc/EtoCP9fvQxyi1wyokLBNsupk9w bp7OvViJ4lNZnm5akmXiiD8MlBmj3eXonZUT7Snbq3AS3FrKaxerUoJUsQIDAQAB o2AwXjAJBgNVHRMEAjAAMB0GA1UdDgQWBBQfdNY/KcF0dEU7BRIsPai9Q1kCpjAf BgNVHSMEGDAWgBS0WuSls97SUva51aaVD+s+vMf9/zARBglghkgBhvhCAQEEBAMC -AEAwDQYJKoZIhvcNAQEFBQADggEBAJ28VuktjDGkUWcVpM/W+YjohFDay676Yozx -BbBLU3QZiDkcdXZbX/jOaKKBGWrjWiB6txchV4XrlvEtVtPgPrQLil2xaD20LOqJ -e/ZEFIAIndf06CAcimdQaPD6mww04v3gZw3cwPQd/aMQCw9tm93tyf6YU4uIh/o8 -evG1ZBrNHRyiW18kbuueLNZ2daYQIISRJSIFrAERacfOvA8r7yXJCqZnB6AU5j9u -V+ySNW3sdZIOTfs1nWKU6SECWo72dd89Yvs7wCf3NSZNM2UemLeOjQOmZIHBiR8L -PAhDxhra5B/QBKaWeTVQohEvKz75pLAWouUGIKlgHiqJ4cvBGcg= +BkAwDQYJKoZIhvcNAQEFBQADggEBAL+IvLnq101fUrpfWA1s9HhyOrnJH+N2gO1F +6UnLmDw4NuX9pttIK60Xesb5pEhtU76y2hP2EAICe8tTQgGgZG4MW4TxIvAliuHl +qvUB/lfmAAGJoQ9WrKriL90IxcKnH3I4aIzNyG2TSIHYo6L8FXVoSrPAuL3X133D +JF6Ie0H8GUK7UOY0pZ0c6x8LCium4Ho/1UNfouSW3x7uq8gEz8lUn2blWUr0HlQr +HDyxTV4tjZ1jKPh0VHYBmcpxdNbObK4NRZanYRKAUCIUCD+kHi67akMAukv0qjbm +Y8DPy+gTLyl89BHnXDR/xCzlta5KkG1oKh3jgV7QQ6BS2+mR7+4= -----END CERTIFICATE----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.cert_type_noauthid.crt b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.cert_type_noauthid.crt index ed8b80baaf..0f71ecb141 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.cert_type_noauthid.crt +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.cert_type_noauthid.crt @@ -10,11 +10,11 @@ CrFTxjB+FTms+Vruf5KepgVb5xOXhbUjktnUJAbVCSWJdQfdphqPPwkZvq1lLGTr lZvc/kFeF6babFtpzAK6FCwWJJxK3M3Q91Jnc/EtoCP9fvQxyi1wyokLBNsupk9w bp7OvViJ4lNZnm5akmXiiD8MlBmj3eXonZUT7Snbq3AS3FrKaxerUoJUsQIDAQAB oz8wPTAJBgNVHRMEAjAAMB0GA1UdDgQWBBQfdNY/KcF0dEU7BRIsPai9Q1kCpjAR -BglghkgBhvhCAQEEBAMCAEAwDQYJKoZIhvcNAQEFBQADggEBABNT+r+6vvlpjtyz -mewrGOKPt5iwb8w2aReJ0AWuyQzTiduN26MhXq93cXHV0pHj2rD7MfiBEwBSWnf9 -FcxkE0g77GVyM9Vs9Uy/MspIqOce7JD0c36G4EI8lYce2TYwQLE9CGNl+LDxqkLy -prijXBl/FaD+IO/SNMr3VVnfFEZqPUxg+BSTaGgD+52Z7B4nPP0xGPjlW367RGDv -9dIkr1thve2WOeC9ixxl9K/864I7/0GdbgKSf77xl3/5vnQUOY7kugRvkvxWIgHS -HNVnmEN2I2Nb0M8lQNF1sFDbpFwVbh9CkBF5LJNesy0VWd67Ho6EntPEb7vBFF/x -jz0b2l4= +BglghkgBhvhCAQEEBAMCBkAwDQYJKoZIhvcNAQEFBQADggEBADAWS7qdGNShzKm+ +AO7vfM3/+6YyIq7Jelm4T7n1GkmiGJ0bf2KhX3ohvaRz5gl0165teWVhLAivaIqB +lK3wLU9TSEaLAtgCMxw+TZhq11qq07FuaawH3nbdMAo4qA2UT0eu2CM1NJjgg8iL +b5FYGwsNcaCmmQYWVRbKlqkA1VNY2p/4PDn8xgRcgVgmqrHf7BUrEPoRA5RXBAhM +huceZxFpA+15x789xKUZHmMoOYvDeZNYw2Fg6Dk4jV403kxzrcP8sSx8Abu6aROb +b2ktuUS5hS8FjrbhDgeosDTU10PQR0Ov9LpMYO4WshkYUBpgC3pSR81pGOKxJuuH +8EV3rhc= -----END CERTIFICATE----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.key_usage.crt b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.key_usage.crt index 8f4e59f2dd..303a222077 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.key_usage.crt +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.key_usage.crt @@ -10,11 +10,11 @@ CrFTxjB+FTms+Vruf5KepgVb5xOXhbUjktnUJAbVCSWJdQfdphqPPwkZvq1lLGTr lZvc/kFeF6babFtpzAK6FCwWJJxK3M3Q91Jnc/EtoCP9fvQxyi1wyokLBNsupk9w bp7OvViJ4lNZnm5akmXiiD8MlBmj3eXonZUT7Snbq3AS3FrKaxerUoJUsQIDAQAB o10wWzAJBgNVHRMEAjAAMB0GA1UdDgQWBBQfdNY/KcF0dEU7BRIsPai9Q1kCpjAf -BgNVHSMEGDAWgBS0WuSls97SUva51aaVD+s+vMf9/zAOBgNVHQ8BAf8EBAMCAeAw -DQYJKoZIhvcNAQEFBQADggEBABKC/1x0m57EY4H412ue3ghCWgg07VcRKamnUSTs -tnqI5T0mSvuPrxhINdQB6360ibctBkXP3S9rxGHiUdeK/JqxYs2YamCs50TSWpon -p4Hzcmjsw1YgXsQ6pmYwkzU03zqs361gt7JSOzL2dN0IjwIy47qfLQb/AXhX2Ims -7gBuqVpYqJuSHR0qsN/c6WgIE3IrbK1MB6CJTkxBfcSc5E4oUIBHmww+RSVLOczM -nGk3U13dmfG0ndhMtrMyyxBZZSUwoZLjRZ6J5mHSv+k8oo1PYQeiivNEP53mgVaY -ha0gLUIk6zNBRpY1uUmxQ+RQSMIyYPBb1RedHn2s8El2mlo= +BgNVHSMEGDAWgBS0WuSls97SUva51aaVD+s+vMf9/zAOBgNVHQ8BAf8EBAMCBeAw +DQYJKoZIhvcNAQEFBQADggEBAFqG4NbAqtsec3lFOiUDKQiGmMCO4Yq3NHhnRWkD +e9r9jWo+gfLgfUJKe02a76ciE5forJRFxG4+pa3Lo38WsF5/2YRz3IfQLOjcK6c6 +DdHrTEsPXgdqhVYJZgZbCeD5Yu5YBXlegGOrlXB9+71BKX0H+AkrR2oXsdg/31Kn +R17yP84tLucQpLdh079ecE8QTZ/21n0VTag6fQFHMeMY35MWkT4K6eRrz/Dta2tm +keHSq/coKsmm0poYPzoMPcbh/D+kSa05Ut03NL2Y+2Q9uTjv5/K/zOgGef/mJbV2 +QxB+1as+WLTtpwc20IqAz3PVBoxbRyN2Z6vjiqqAzGlfB4M= -----END CERTIFICATE----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.key_usage_noauthid.crt b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.key_usage_noauthid.crt index d66e515352..7ff26924a7 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.key_usage_noauthid.crt +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.key_usage_noauthid.crt @@ -10,11 +10,11 @@ CrFTxjB+FTms+Vruf5KepgVb5xOXhbUjktnUJAbVCSWJdQfdphqPPwkZvq1lLGTr lZvc/kFeF6babFtpzAK6FCwWJJxK3M3Q91Jnc/EtoCP9fvQxyi1wyokLBNsupk9w bp7OvViJ4lNZnm5akmXiiD8MlBmj3eXonZUT7Snbq3AS3FrKaxerUoJUsQIDAQAB ozwwOjAJBgNVHRMEAjAAMB0GA1UdDgQWBBQfdNY/KcF0dEU7BRIsPai9Q1kCpjAO -BgNVHQ8BAf8EBAMCAeAwDQYJKoZIhvcNAQEFBQADggEBAJZRIISo4+rDvHXXaS43 -shfSkyJyur588mNJFzty1WVfhaIkwjMIGHeGlHS29fwgPsBUgelZ3Qv3J7wsm42+ -3BwQet0l36FIBIJtFhcrTGlaCFUo/5bZJUPGgiOFB9ec/8lOszVlX8cH34UimWqg -q2wXRGoXWPbuRnUWlJhI2bAv5ri9Mt7Rs4nK4wyS1ZjC8ByXMn4tk3yMjkUEqu0o -37zoQiF+FJApu0eTKK5goA2hisyfCX9eJMppAbcyvJwoj/AmiBkXW8J3kEMJtLmZ -VoxXYknnXumxBLxUrGuamR/3cmbaJHIHE1Dqox7hB+9miyp4lue1/uXHCocGAIeF -JTo= +BgNVHQ8BAf8EBAMCBeAwDQYJKoZIhvcNAQEFBQADggEBALIkgZjEfQcV7d7zovec +tNVvaPO5hSE8kDVjMCdUZsKgZjMxpY8gJ4CLNIOamkIqN8sSd1zdhdexMdn3iE/O +z5y3rQBQLs8UjLippm3abKksKrpTEkM9x7Z1X8KS7GOrnOgBWLzoE9D4F/2ay7yk +H57qRUXEw1NlnAwKYS6hmEwf497szNKXvgr7MGbahQ/N+WfQbILW6+OSUttuoDrD +t2uBZsGAVQGDzcQGyOuo7k8CE0D62HHZqA+ZPo/xicvyTbkk+lUfY6q6QA8sojaU +2LuU0nBtd+LmY8odaUsQItwbIyfYZrZbXKruevVHfMKb9VuoYj6anA5jEl0pe7wN +Tu0= -----END CERTIFICATE----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.cert_type b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.cert_type index 5677f32bec..3feb1fc9bf 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.cert_type +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.cert_type @@ -7,11 +7,11 @@ HqgzCEfBBUKp/UzDtN/dBh9NEFFAZ3MTD0D4bYElXwqxU8YwfhU5rPla7n+SnqYF W+cTl4W1I5LZ1CQG1QkliXUH3aYajz8JGb6tZSxk65Wb3P5BXhem2mxbacwCuhQs FiScStzN0PdSZ3PxLaAj/X70McotcMqJCwTbLqZPcG6ezr1YieJTWZ5uWpJl4og/ DJQZo93l6J2VE+0p26twEtxaymsXq1KCVLECAwEAAaAkMCIGCSqGSIb3DQEJDjEV -MBMwEQYJYIZIAYb4QgEBBAQDAgBAMA0GCSqGSIb3DQEBBQUAA4IBAQB95Pkjpg/N -Jbgl5nZcAk8maGMpUFlrhJS4kGutQKZugNX9v8cfABW905IHYXV1dm6zxVcyeqZM -FiOgbV943fu5JbufoazdYXnnR2/iKMigqX4CzZrK3F5ZzegxkfDIfDrn/shC+rWb -SS5WBVLJ3QNj9vwn3/b66IRbp/ViOwHx7+9JT4K/rLId/ynjYf2T57AsmNd/jptc -Zs19fGgtrUXweWkliEZN2zE47Cc53jkx6+Li4TNs4Bjk5P/aXrCP0fBwgGt2K6YW -dQ/nr0PwIbXzVlgUukSTHkJJfhF4Y/WqcUfOPrRdw+zxOLusJ9nzJBR0FOohcBxM -kPBVna0dze/o +MBMwEQYJYIZIAYb4QgEBBAQDAgZAMA0GCSqGSIb3DQEBBQUAA4IBAQBfm+BA0PSA +9EFSFgdVODuBtjVoe+RzjiwrHVjja9/GAMurams5WSeJ0g3n0QJuNPf4m3vpSgQE +qXZrkn2aNYSRPipiPYFUj0NMvji2gmyzmvy6VJyyerZ/saPfuySiVSJbCycA88/V +vSv93qVHQ7QGwXlwg5dkhw4VNn1NK5CtA0DSEsGITKhdLZUZKkEdylwdjFdi+NTf +Qx/LQ+cEECBM31s/88C6+ynd4ni42/YYRRcpj5+4TAyKt+nl9a0osrR1y3MmBeo3 +/9s9QEIpXPHMJnJDVq0q03FZwAkgGTaKI8bRsf125eh1CSBynvC6vC+LJSkPrW9g +HUYYkPMQiQ2C -----END CERTIFICATE REQUEST----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.cert_type_empty b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.cert_type_empty new file mode 100644 index 0000000000..d61ef6bcf4 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.cert_type_empty @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE REQUEST----- +MIICpDCCAYwCAQAwPDELMAkGA1UEBhMCTkwxETAPBgNVBAoTCFBvbGFyU1NMMRow +GAYDVQQDExFQb2xhclNTTCBTZXJ2ZXIgMTCCASIwDQYJKoZIhvcNAQEBBQADggEP +ADCCAQoCggEBAKkCHz1AatVVU4v9Nu6CZS4VYV6Jv7joRZDb7ogWUtPxQ1BHlhJZ +ZIdr/SvgRvlzvt3PkuGRW+1moG+JKXlFgNCDatVBQ3dfOXwJBEeCsFc5cO2j7BUZ +HqgzCEfBBUKp/UzDtN/dBh9NEFFAZ3MTD0D4bYElXwqxU8YwfhU5rPla7n+SnqYF +W+cTl4W1I5LZ1CQG1QkliXUH3aYajz8JGb6tZSxk65Wb3P5BXhem2mxbacwCuhQs +FiScStzN0PdSZ3PxLaAj/X70McotcMqJCwTbLqZPcG6ezr1YieJTWZ5uWpJl4og/ +DJQZo93l6J2VE+0p26twEtxaymsXq1KCVLECAwEAAaAjMCEGCSqGSIb3DQEJDjEU +MBIwEAYJYIZIAYb4QgEBBAMDAQAwDQYJKoZIhvcNAQEFBQADggEBAFsbkVHizurV +Ub9uDSTEEFm7R/TcCYjqAbP243sEOVfyCwZh49E7hrjq7lp1n/myILHX+keaxKEY +hUq9B0Rpa61H5lTJPG3Iy1mDHcF0et4cPkDEsQw4GgjZ/A0RCNfYD+OZLATsDKMy +AgGCZcYhjoL/8iZaYljfuE+a8Bo3xMePo+jignUhB+hEK2cNmUN2m7HqT22Ba4ag +eJQtY0NUmBoXGJlNaDbzO79mwLl0HHxDmanLVnSzKXqzrH4U0fuoGZFuxY7Dn7AM +vJujuWOxN1FtHOfJIimnVepuEG6wvDXMLgEPJTXSKbW6CMTgaz6fudEZzgVB6OKR +zIbUGFi6kLg= +-----END CERTIFICATE REQUEST----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.key_usage b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.key_usage index 053aed909b..5df41e1d25 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.key_usage +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.key_usage @@ -7,11 +7,11 @@ HqgzCEfBBUKp/UzDtN/dBh9NEFFAZ3MTD0D4bYElXwqxU8YwfhU5rPla7n+SnqYF W+cTl4W1I5LZ1CQG1QkliXUH3aYajz8JGb6tZSxk65Wb3P5BXhem2mxbacwCuhQs FiScStzN0PdSZ3PxLaAj/X70McotcMqJCwTbLqZPcG6ezr1YieJTWZ5uWpJl4og/ DJQZo93l6J2VE+0p26twEtxaymsXq1KCVLECAwEAAaAeMBwGCSqGSIb3DQEJDjEP -MA0wCwYDVR0PBAQDAgHgMA0GCSqGSIb3DQEBBQUAA4IBAQCj6jCu0wE5OQ1JGQwZ -FNwPqZrvKntSq2yLIbgmGxwlvDLxOzn0KmidSFiKRqh0KXwj9siodlz5C0d9tUqq -7xUXg+j+wDHqUV8zo42Jke+UmWXFPpnXx/fDFGTITdLSn8ZDxkt31ESLTEVZvPFD -odm+C+zWJtKpyL+9op4KvyBQ1MZ9nWZpwMaK4g4mdtOIsz75gMa74w8ZT7VzhGMY -cZGmafsl7x++GDDtf0oCPgrj9xy+Ovv/GyUBaB+6lweflTfPDTRSoN0meFlP5ynF -vqcBM5JKH2FUQIizfc9o6Z8tKxe9FCov3x8szAuoMRA7bjhVngeQIrEkTcaQBvBY -NalC +MA0wCwYDVR0PBAQDAgXgMA0GCSqGSIb3DQEBBQUAA4IBAQCn0RjrgOyNn5ZQ9Hfn +zhN5q7EAMBYdKBQayeJQQkmreqTdzG/rCHZtt3bIZ/8SWIPNiIOkvsnsGzdBLp8B +zAAwINhcDIQtIQVObgTLZmvC1syjXfjdH02mYKAccP9OxlnWIVivSPRp9jr9IwYO +cnT6pzGvP/RWoQen+DougM2WwiZ8YJTrtoe8DlzDq+hbTgoGeQuEGhOnxMlkiLzs ++g6yoi/1F3nsUwJI+QhBxG7Xf74gCCHZckCtSs2MBEavhcPu7o9QjuWR0YFRTaCf +5uBL7/gNIVmrWnsQLcH1+DexxzW7lPBN1iFXUXNcweoo0fX3ykkvBYdKKicF7bM1 +zZzQ -----END CERTIFICATE REQUEST----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.key_usage_empty b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.key_usage_empty new file mode 100644 index 0000000000..1ac1bc3d4e --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.key_usage_empty @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE REQUEST----- +MIICnjCCAYYCAQAwPDELMAkGA1UEBhMCTkwxETAPBgNVBAoTCFBvbGFyU1NMMRow +GAYDVQQDExFQb2xhclNTTCBTZXJ2ZXIgMTCCASIwDQYJKoZIhvcNAQEBBQADggEP +ADCCAQoCggEBAKkCHz1AatVVU4v9Nu6CZS4VYV6Jv7joRZDb7ogWUtPxQ1BHlhJZ +ZIdr/SvgRvlzvt3PkuGRW+1moG+JKXlFgNCDatVBQ3dfOXwJBEeCsFc5cO2j7BUZ +HqgzCEfBBUKp/UzDtN/dBh9NEFFAZ3MTD0D4bYElXwqxU8YwfhU5rPla7n+SnqYF +W+cTl4W1I5LZ1CQG1QkliXUH3aYajz8JGb6tZSxk65Wb3P5BXhem2mxbacwCuhQs +FiScStzN0PdSZ3PxLaAj/X70McotcMqJCwTbLqZPcG6ezr1YieJTWZ5uWpJl4og/ +DJQZo93l6J2VE+0p26twEtxaymsXq1KCVLECAwEAAaAdMBsGCSqGSIb3DQEJDjEO +MAwwCgYDVR0PBAMDAQAwDQYJKoZIhvcNAQEFBQADggEBAHkw230TfJnAoc+6j/5R +oGfXR92g/k2DTlDaFQywO2j03h97isp47bEq/peOlKhAuMA+aHt5n8J1w6eWsr8B +VpoQ079jDnMtlLVAtgsEAjhwEPZchB9oZzfGztzBC4kVKchMGiSHLVQptIM3DiOT +/5JBlfGkAfap4V4V6qRYiNESBSpEdU/wGctg4ELgQgdpRSlqRud2LgClmMy3+A3o +rHjyAY+1oANNNOV+TBwA58OKqwsniyqmSWkhlj4c0O4n8FdE+o1eKyrsQfH9LBx7 +DBo2ilAkp0O/+G0n9Wisov2i6QuOraxW3g5/YBdfrqoVpJ5+8YZvoSGJFYDYoWvN +CvU= +-----END CERTIFICATE REQUEST----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.ku-ct b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.ku-ct index 0e057d58aa..4a0eab88ed 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.ku-ct +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/server1.req.ku-ct @@ -7,11 +7,11 @@ HqgzCEfBBUKp/UzDtN/dBh9NEFFAZ3MTD0D4bYElXwqxU8YwfhU5rPla7n+SnqYF W+cTl4W1I5LZ1CQG1QkliXUH3aYajz8JGb6tZSxk65Wb3P5BXhem2mxbacwCuhQs FiScStzN0PdSZ3PxLaAj/X70McotcMqJCwTbLqZPcG6ezr1YieJTWZ5uWpJl4og/ DJQZo93l6J2VE+0p26twEtxaymsXq1KCVLECAwEAAaAxMC8GCSqGSIb3DQEJDjEi -MCAwCwYDVR0PBAQDAgHgMBEGCWCGSAGG+EIBAQQEAwIAQDANBgkqhkiG9w0BAQUF -AAOCAQEANlNG9hW852OzVKj2Z8TtU9jxstAoSCH9yc9Coj4Vw2TTjs1zcuBWsMl1 -2bf2I6ZvEH6ZhcQY7i7nyHQyPlqE4l6U9D8ct967QN7smuAHNY2HiQ2++eCBTHck -PdtGJAzIvNlXcoqNi8UC5fGepNtI1usNo41SKMvbg6nGA5gdcQKk7CVlk8lrD0qI -Xn/HvjSRoDE4ZGxAtNvPXWorGSxtgcy8EMPoXVUab5fNt8q//x/NQ4yEQKPrexmR -IuOiQ8VW8QZtkORGpZbGSvskU0WfKANui4zCcXYRc4mVR4Wf0C+fyHeihhjslSnT -RbC7nQn5HSHp31qJlr80QodywaK1Dg== +MCAwCwYDVR0PBAQDAgXgMBEGCWCGSAGG+EIBAQQEAwIGQDANBgkqhkiG9w0BAQUF +AAOCAQEAKIF06WMMbkfDi6z3FzG0OVqGVgCIdQjJUK2S8VrVXJ74goM8SD7jp2RC +2d5nszk0do3ruAqaI3YOk5U9HQR0qHMSXEcAeB/qqIYWXrlZKacdzSk6vd88VC01 +uAWBSE2IQ4TWPSiWLCN54VtO8AXuF5wJgjGOh4yixVqKzcQh5b+mJs3e7cgMsC5a +3iPt0EemCT+irT4cXtcJe9/DAvnvvvCZ5UCcvc3shBIA5pBsOOmd1yCYCbxrq3aL +PhFf/vbbf9eORMwWsqOWopnRgBkPpVnTu9G27t/Nyjencjfk8NEaM9q8YnF0x5lD +elCFyt+HGwoCeOBN9odfQmKQpW+eGg== -----END CERTIFICATE REQUEST----- diff --git a/3rdparty/mbedtls/mbedtls/tests/data_files/server5.req.ku.sha1 b/3rdparty/mbedtls/mbedtls/tests/data_files/server5.req.ku.sha1 index 7556d1a052..6f3b7aaf4e 100644 --- a/3rdparty/mbedtls/mbedtls/tests/data_files/server5.req.ku.sha1 +++ b/3rdparty/mbedtls/mbedtls/tests/data_files/server5.req.ku.sha1 @@ -1,8 +1,8 @@ -----BEGIN CERTIFICATE REQUEST----- -MIIBFjCBvAIBADA8MQswCQYDVQQGEwJOTDERMA8GA1UEChMIUG9sYXJTU0wxGjAY +MIIBFzCBvAIBADA8MQswCQYDVQQGEwJOTDERMA8GA1UEChMIUG9sYXJTU0wxGjAY BgNVBAMTEVBvbGFyU1NMIFNlcnZlciAxMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD QgAEN8xW2XYJHlpyPsdZLf8gbu58+QaRdNCtFLX3aCJZYpJO5QDYIxH/6i/SNF1d Fr2KiMJrdw1VzYoqDvoByLTt/6AeMBwGCSqGSIb3DQEJDjEPMA0wCwYDVR0PBAQD -AgHAMAsGByqGSM49BAEFAANIADBFAiBjnnD7nwsFnCL+MpPPFJE3K/Tgj+5rAgXj -e5UejDX2CAIhAKdbigWJL/ZatvG9CFHq7ykrRns2x8JEXehWu8DsXdx9 +AgbAMAsGByqGSM49BAEFAANJADBGAiEAmhkNVnF6mGzzyHxGMMuUM2tYw5/y5tlF +3424Bs7DbG8CIQCJteTtpZ8RJ7PjpxcmVpP4fcYHFTR50zoc9jOV0AYPLQ== -----END CERTIFICATE REQUEST----- diff --git a/3rdparty/mbedtls/mbedtls/tests/scripts/all.sh b/3rdparty/mbedtls/mbedtls/tests/scripts/all.sh index 391de195be..30e6d5f424 100755 --- a/3rdparty/mbedtls/mbedtls/tests/scripts/all.sh +++ b/3rdparty/mbedtls/mbedtls/tests/scripts/all.sh @@ -55,21 +55,46 @@ # Notes for maintainers # --------------------- # +# The bulk of the code is organized into functions that follow one of the +# following naming conventions: +# * pre_XXX: things to do before running the tests, in order. +# * component_XXX: independent components. They can be run in any order. +# * component_check_XXX: quick tests that aren't worth parallelizing. +# * component_build_XXX: build things but don't run them. +# * component_test_XXX: build and test. +# * support_XXX: if support_XXX exists and returns false then +# component_XXX is not run by default. +# * post_XXX: things to do after running the tests. +# * other: miscellaneous support functions. +# +# Each component must start by invoking `msg` with a short informative message. +# +# The framework performs some cleanup tasks after each component. This +# means that components can assume that the working directory is in a +# cleaned-up state, and don't need to perform the cleanup themselves. +# * Run `make clean`. +# * Restore `include/mbedtks/config.h` from a backup made before running +# the component. +# * Check out `Makefile`, `library/Makefile`, `programs/Makefile` and +# `tests/Makefile` from git. This cleans up after an in-tree use of +# CMake. +# +# Any command that is expected to fail must be protected so that the +# script keeps running in --keep-going mode despite `set -e`. In keep-going +# mode, if a protected command fails, this is logged as a failure and the +# script will exit with a failure status once it has run all components. +# Commands can be protected in any of the following ways: +# * `make` is a function which runs the `make` command with protection. +# Note that you must write `make VAR=value`, not `VAR=value make`, +# because the `VAR=value make` syntax doesn't work with functions. +# * Put `report_status` before the command to protect it. +# * Put `if_build_successful` before a command. This protects it, and +# additionally skips it if a prior invocation of `make` in the same +# component failed. +# # The tests are roughly in order from fastest to slowest. This doesn't # have to be exact, but in general you should add slower tests towards # the end and fast checks near the beginning. -# -# Sanity checks have the following form: -# 1. msg "short description of what is about to be done" -# 2. run sanity check (failure stops the script) -# -# Build or build-and-test steps have the following form: -# 1. msg "short description of what is about to be done" -# 2. cleanup -# 3. preparation (config.pl, cmake, ...) (failure stops the script) -# 4. make -# 5. Run tests if relevant. All tests must be prefixed with -# if_build_successful for the sake of --keep-going. @@ -80,50 +105,93 @@ # Abort on errors (and uninitialised variables) set -eu -if [ "$( uname )" != "Linux" ]; then - echo "This script only works in Linux" >&2 - exit 1 -elif [ -d library -a -d include -a -d tests ]; then :; else - echo "Must be run from mbed TLS root" >&2 - exit 1 -fi +pre_check_environment () { + if [ -d library -a -d include -a -d tests ]; then :; else + echo "Must be run from mbed TLS root" >&2 + exit 1 + fi +} -CONFIG_H='include/mbedtls/config.h' -CONFIG_BAK="$CONFIG_H.bak" - -MEMORY=0 -FORCE=0 -KEEP_GOING=0 -RUN_ARMCC=1 -YOTTA=1 - -# Default commands, can be overriden by the environment -: ${OPENSSL:="openssl"} -: ${OPENSSL_LEGACY:="$OPENSSL"} -: ${GNUTLS_CLI:="gnutls-cli"} -: ${GNUTLS_SERV:="gnutls-serv"} -: ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"} -: ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"} -: ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build} -: ${ARMC5_BIN_DIR:=/usr/bin} -: ${ARMC6_BIN_DIR:=/usr/bin} - -# if MAKEFLAGS is not set add the -j option to speed up invocations of make -if [ -n "${MAKEFLAGS+set}" ]; then - export MAKEFLAGS="-j" -fi +pre_initialize_variables () { + CONFIG_H='include/mbedtls/config.h' + CONFIG_BAK="$CONFIG_H.bak" + + MEMORY=0 + FORCE=0 + KEEP_GOING=0 + YOTTA=1 + + # Default commands, can be overriden by the environment + : ${OPENSSL:="openssl"} + : ${OPENSSL_LEGACY:="$OPENSSL"} + : ${GNUTLS_CLI:="gnutls-cli"} + : ${GNUTLS_SERV:="gnutls-serv"} + : ${GNUTLS_LEGACY_CLI:="$GNUTLS_CLI"} + : ${GNUTLS_LEGACY_SERV:="$GNUTLS_SERV"} + : ${OUT_OF_SOURCE_DIR:=./mbedtls_out_of_source_build} + : ${ARMC5_BIN_DIR:=/usr/bin} + : ${ARMC6_BIN_DIR:=/usr/bin} + + # if MAKEFLAGS is not set add the -j option to speed up invocations of make + if [ -z "${MAKEFLAGS+set}" ]; then + export MAKEFLAGS="-j" + fi + + # Gather the list of available components. These are the functions + # defined in this script whose name starts with "component_". + # Parse the script with sed, because in sh there is no way to list + # defined functions. + ALL_COMPONENTS=$(sed -n 's/^ *component_\([0-9A-Z_a-z]*\) *().*/\1/p' <"$0") + + # Exclude components that are not supported on this platform. + SUPPORTED_COMPONENTS= + for component in $ALL_COMPONENTS; do + case $(type "support_$component" 2>&1) in + *' function'*) + if ! support_$component; then continue; fi;; + esac + SUPPORTED_COMPONENTS="$SUPPORTED_COMPONENTS $component" + done +} + +# Test whether the component $1 is included in the command line patterns. +is_component_included() +{ + set -f + for pattern in $COMMAND_LINE_COMPONENTS; do + set +f + case ${1#component_} in $pattern) return 0;; esac + done + set +f + return 1 +} usage() { cat <&2 "Unknown option: $1" - echo >&2 "Run $0 --help for usage." - exit 120 - ;; - esac - shift -done +pre_parse_command_line () { + COMMAND_LINE_COMPONENTS= + all_except=0 + no_armcc= + + while [ $# -gt 0 ]; do + case "$1" in + --armcc) no_armcc=;; + --armc5-bin-dir) shift; ARMC5_BIN_DIR="$1";; + --armc6-bin-dir) shift; ARMC6_BIN_DIR="$1";; + --except) all_except=1;; + --force|-f) FORCE=1;; + --gnutls-cli) shift; GNUTLS_CLI="$1";; + --gnutls-legacy-cli) shift; GNUTLS_LEGACY_CLI="$1";; + --gnutls-legacy-serv) shift; GNUTLS_LEGACY_SERV="$1";; + --gnutls-serv) shift; GNUTLS_SERV="$1";; + --help|-h) usage; exit;; + --keep-going|-k) KEEP_GOING=1;; + --list-all-components) printf '%s\n' $ALL_COMPONENTS; exit;; + --list-components) printf '%s\n' $SUPPORTED_COMPONENTS; exit;; + --memory|-m) MEMORY=1;; + --no-armcc) no_armcc=1;; + --no-force) FORCE=0;; + --no-keep-going) KEEP_GOING=0;; + --no-memory) MEMORY=0;; + --no-yotta) YOTTA=0;; + --openssl) shift; OPENSSL="$1";; + --openssl-legacy) shift; OPENSSL_LEGACY="$1";; + --out-of-source-dir) shift; OUT_OF_SOURCE_DIR="$1";; + --random-seed) unset SEED;; + --release-test|-r) SEED=1;; + --seed|-s) shift; SEED="$1";; + --yotta) YOTTA=1;; + -*) + echo >&2 "Unknown option: $1" + echo >&2 "Run $0 --help for usage." + exit 120 + ;; + *) COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS $1";; + esac + shift + done -if [ $FORCE -eq 1 ]; then - if [ $YOTTA -eq 1 ]; then - rm -rf yotta/module "$OUT_OF_SOURCE_DIR" + # With no list of components, run everything. + if [ -z "$COMMAND_LINE_COMPONENTS" ]; then + all_except=1 fi - git checkout-index -f -q $CONFIG_H - cleanup -else - if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then - err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'" - echo "You can either delete your work and retry, or force the test to overwrite the" - echo "test by rerunning the script as: $0 --force" - exit 1 + # --no-armcc is a legacy option. The modern way is --except '*_armcc*'. + # Ignore it if components are listed explicitly on the command line. + if [ -n "$no_armcc" ] && [ $all_except -eq 1 ]; then + COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_armcc*" + # --no-armcc also disables yotta. + COMMAND_LINE_COMPONENTS="$COMMAND_LINE_COMPONENTS *_yotta*" fi - if [ -d "$OUT_OF_SOURCE_DIR" ]; then - echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2 - echo "You can either delete this directory manually, or force the test by rerunning" - echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR" - exit 1 - fi + # Build the list of components to run. + RUN_COMPONENTS= + for component in $SUPPORTED_COMPONENTS; do + if is_component_included "$component"; [ $? -eq $all_except ]; then + RUN_COMPONENTS="$RUN_COMPONENTS $component" + fi + done - if ! git diff-files --quiet include/mbedtls/config.h; then - err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. " - echo "You can either delete or preserve your work, or force the test by rerunning the" - echo "script as: $0 --force" - exit 1 + unset all_except + unset no_armcc +} + +pre_check_git () { + if [ $FORCE -eq 1 ]; then + rm -rf "$OUT_OF_SOURCE_DIR" + if [ $YOTTA -eq 1 ]; then + rm -rf yotta/module + fi + git checkout-index -f -q $CONFIG_H + cleanup + else + + if [ $YOTTA -ne 0 ] && [ -d yotta/module ]; then + err_msg "Warning - there is an existing yotta module in the directory 'yotta/module'" + echo "You can either delete your work and retry, or force the test to overwrite the" + echo "test by rerunning the script as: $0 --force" + exit 1 + fi + + if [ -d "$OUT_OF_SOURCE_DIR" ]; then + echo "Warning - there is an existing directory at '$OUT_OF_SOURCE_DIR'" >&2 + echo "You can either delete this directory manually, or force the test by rerunning" + echo "the script as: $0 --force --out-of-source-dir $OUT_OF_SOURCE_DIR" + exit 1 + fi + + if ! git diff --quiet include/mbedtls/config.h; then + err_msg "Warning - the configuration file 'include/mbedtls/config.h' has been edited. " + echo "You can either delete or preserve your work, or force the test by rerunning the" + echo "script as: $0 --force" + exit 1 + fi fi -fi +} -build_status=0 -if [ $KEEP_GOING -eq 1 ]; then +pre_setup_keep_going () { failure_summary= failure_count=0 start_red= @@ -344,53 +450,94 @@ $text" echo "Killed by SIG$1." fi } -else - record_status () { - "$@" - } -fi +} + if_build_succeeded () { if [ $build_status -eq 0 ]; then record_status "$@" fi } -msg "info: $0 configuration" -echo "MEMORY: $MEMORY" -echo "FORCE: $FORCE" -echo "SEED: ${SEED-"UNSET"}" -echo "OPENSSL: $OPENSSL" -echo "OPENSSL_LEGACY: $OPENSSL_LEGACY" -echo "GNUTLS_CLI: $GNUTLS_CLI" -echo "GNUTLS_SERV: $GNUTLS_SERV" -echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI" -echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV" -echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR" -echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR" - -ARMC5_CC="$ARMC5_BIN_DIR/armcc" -ARMC5_AR="$ARMC5_BIN_DIR/armar" -ARMC6_CC="$ARMC6_BIN_DIR/armclang" -ARMC6_AR="$ARMC6_BIN_DIR/armar" - -# To avoid setting OpenSSL and GnuTLS for each call to compat.sh and ssl-opt.sh -# we just export the variables they require -export OPENSSL_CMD="$OPENSSL" -export GNUTLS_CLI="$GNUTLS_CLI" -export GNUTLS_SERV="$GNUTLS_SERV" - -# Avoid passing --seed flag in every call to ssl-opt.sh -if [ -n "${SEED-}" ]; then - export SEED -fi +# to be used instead of ! for commands run with +# record_status or if_build_succeeded +not() { + ! "$@" +} + + +pre_print_configuration () { + msg "info: $0 configuration" + echo "MEMORY: $MEMORY" + echo "FORCE: $FORCE" + echo "SEED: ${SEED-"UNSET"}" + echo "OPENSSL: $OPENSSL" + echo "OPENSSL_LEGACY: $OPENSSL_LEGACY" + echo "GNUTLS_CLI: $GNUTLS_CLI" + echo "GNUTLS_SERV: $GNUTLS_SERV" + echo "GNUTLS_LEGACY_CLI: $GNUTLS_LEGACY_CLI" + echo "GNUTLS_LEGACY_SERV: $GNUTLS_LEGACY_SERV" + echo "ARMC5_BIN_DIR: $ARMC5_BIN_DIR" + echo "ARMC6_BIN_DIR: $ARMC6_BIN_DIR" +} # Make sure the tools we need are available. -check_tools "$OPENSSL" "$OPENSSL_LEGACY" "$GNUTLS_CLI" "$GNUTLS_SERV" \ - "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" "doxygen" "dot" \ - "arm-none-eabi-gcc" "i686-w64-mingw32-gcc" -if [ $RUN_ARMCC -ne 0 ]; then - check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR" -fi +pre_check_tools () { + # Build the list of variables to pass to output_env.sh. + set env + + case " $RUN_COMPONENTS " in + # Require OpenSSL and GnuTLS if running any tests (as opposed to + # only doing builds). Not all tests run OpenSSL and GnuTLS, but this + # is a good enough approximation in practice. + *" test_"*) + # To avoid setting OpenSSL and GnuTLS for each call to compat.sh + # and ssl-opt.sh, we just export the variables they require. + export OPENSSL_CMD="$OPENSSL" + export GNUTLS_CLI="$GNUTLS_CLI" + export GNUTLS_SERV="$GNUTLS_SERV" + # Avoid passing --seed flag in every call to ssl-opt.sh + if [ -n "${SEED-}" ]; then + export SEED + fi + set "$@" OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" + set "$@" GNUTLS_CLI="$GNUTLS_CLI" GNUTLS_SERV="$GNUTLS_SERV" + set "$@" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" + set "$@" GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" + check_tools "$OPENSSL" "$OPENSSL_LEGACY" \ + "$GNUTLS_CLI" "$GNUTLS_SERV" \ + "$GNUTLS_LEGACY_CLI" "$GNUTLS_LEGACY_SERV" + ;; + esac + + case " $RUN_COMPONENTS " in + *_doxygen[_\ ]*) check_tools "doxygen" "dot";; + esac + + case " $RUN_COMPONENTS " in + *_arm_none_eabi_gcc[_\ ]*) check_tools "arm-none-eabi-gcc";; + esac + + case " $RUN_COMPONENTS " in + *_mingw[_\ ]*) check_tools "i686-w64-mingw32-gcc";; + esac + + case " $RUN_COMPONENTS " in + *_armcc*|*_yotta*) + ARMC5_CC="$ARMC5_BIN_DIR/armcc" + ARMC5_AR="$ARMC5_BIN_DIR/armar" + ARMC6_CC="$ARMC6_BIN_DIR/armclang" + ARMC6_AR="$ARMC6_BIN_DIR/armar" + check_tools "$ARMC5_CC" "$ARMC5_AR" "$ARMC6_CC" "$ARMC6_AR";; + esac + + msg "info: output_env.sh" + case $RUN_COMPONENTS in + *_armcc*|*_yotta*) + set "$@" ARMC5_CC="$ARMC5_CC" ARMC6_CC="$ARMC6_CC" RUN_ARMCC=1;; + *) set "$@" RUN_ARMCC=0;; + esac + "$@" scripts/output_env.sh +} @@ -409,378 +556,425 @@ fi # # Indicative running times are given for reference. -msg "info: output_env.sh" -OPENSSL="$OPENSSL" OPENSSL_LEGACY="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_CLI" \ - GNUTLS_SERV="$GNUTLS_SERV" GNUTLS_LEGACY_CLI="$GNUTLS_LEGACY_CLI" \ - GNUTLS_LEGACY_SERV="$GNUTLS_LEGACY_SERV" ARMC5_CC="$ARMC5_CC" \ - ARMC6_CC="$ARMC6_CC" RUN_ARMCC="$RUN_ARMCC" scripts/output_env.sh - -msg "test: recursion.pl" # < 1s -record_status tests/scripts/recursion.pl library/*.c - -msg "test: freshness of generated source files" # < 1s -record_status tests/scripts/check-generated-files.sh +component_check_recursion () { + msg "test: recursion.pl" # < 1s + record_status tests/scripts/recursion.pl library/*.c +} -msg "test: doxygen markup outside doxygen blocks" # < 1s -record_status tests/scripts/check-doxy-blocks.pl +component_check_generated_files () { + msg "test: freshness of generated source files" # < 1s + record_status tests/scripts/check-generated-files.sh +} -msg "test: check-files.py" # < 1s -cleanup -record_status tests/scripts/check-files.py +component_check_doxy_blocks () { + msg "test: doxygen markup outside doxygen blocks" # < 1s + record_status tests/scripts/check-doxy-blocks.pl +} -msg "test/build: declared and exported names" # < 3s -cleanup -record_status tests/scripts/check-names.sh +component_check_files () { + msg "test: check-files.py" # < 1s + record_status tests/scripts/check-files.py +} -msg "test: doxygen warnings" # ~ 3s -cleanup -record_status tests/scripts/doxygen.sh +component_check_names () { + msg "test/build: declared and exported names" # < 3s + record_status tests/scripts/check-names.sh -v +} +component_check_doxygen_warnings () { + msg "test: doxygen warnings" # ~ 3s + record_status tests/scripts/doxygen.sh +} ################################################################ #### Build and test many configurations and targets ################################################################ -if [ $RUN_ARMCC -ne 0 ] && [ $YOTTA -ne 0 ]; then +component_test_default_out_of_box () { + msg "build: make, default config (out-of-box)" # ~1min + make + + msg "test: main suites make, default config (out-of-box)" # ~10s + make test + + msg "selftest: make, default config (out-of-box)" # ~10s + programs/test/selftest +} + +component_build_yotta () { # Note - use of yotta is deprecated, and yotta also requires armcc to be on the # path, and uses whatever version of armcc it finds there. msg "build: create and build yotta module" # ~ 30s - cleanup record_status tests/scripts/yotta-build.sh -fi +} +support_build_yotta () { + [ $YOTTA -ne 0 ] +} -msg "build: cmake, gcc, ASan" # ~ 1 min 50s -cleanup -CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . -make +component_test_default_cmake_gcc_asan () { + msg "build: cmake, gcc, ASan" # ~ 1 min 50s + CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . + make -msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s -make test + msg "test: main suites (inc. selftests) (ASan build)" # ~ 50s + make test -msg "test: ssl-opt.sh (ASan build)" # ~ 1 min -if_build_succeeded tests/ssl-opt.sh + msg "test: ssl-opt.sh (ASan build)" # ~ 1 min + if_build_succeeded tests/ssl-opt.sh -msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s -record_status tests/scripts/test-ref-configs.pl + msg "test: compat.sh (ASan build)" # ~ 6 min + if_build_succeeded tests/compat.sh +} -msg "build: with ASan (rebuild after ref-configs)" # ~ 1 min -make +component_test_ref_configs () { + msg "test/build: ref-configs (ASan build)" # ~ 6 min 20s + CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . + record_status tests/scripts/test-ref-configs.pl +} -msg "test: compat.sh (ASan build)" # ~ 6 min -if_build_succeeded tests/compat.sh +component_test_sslv3 () { + msg "build: Default + SSLv3 (ASan build)" # ~ 6 min + scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3 + CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . + make -msg "build: Default + SSLv3 (ASan build)" # ~ 6 min -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl set MBEDTLS_SSL_PROTO_SSL3 -CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . -make + msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s + make test -msg "test: SSLv3 - main suites (inc. selftests) (ASan build)" # ~ 50s -make test + msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min + if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2' + if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3' -msg "build: SSLv3 - compat.sh (ASan build)" # ~ 6 min -if_build_succeeded tests/compat.sh -m 'tls1 tls1_1 tls1_2 dtls1 dtls1_2' -if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" tests/compat.sh -m 'ssl3' + msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min + if_build_succeeded tests/ssl-opt.sh +} -msg "build: SSLv3 - ssl-opt.sh (ASan build)" # ~ 6 min -if_build_succeeded tests/ssl-opt.sh +component_test_no_renegotiation () { + msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min + scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION + CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . + make -msg "build: Default + !MBEDTLS_SSL_RENEGOTIATION (ASan build)" # ~ 6 min -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl unset MBEDTLS_SSL_RENEGOTIATION -CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . -make + msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s + make test -msg "test: !MBEDTLS_SSL_RENEGOTIATION - main suites (inc. selftests) (ASan build)" # ~ 50s -make test + msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min + if_build_succeeded tests/ssl-opt.sh +} -msg "test: !MBEDTLS_SSL_RENEGOTIATION - ssl-opt.sh (ASan build)" # ~ 6 min -if_build_succeeded tests/ssl-opt.sh +component_test_rsa_no_crt () { + msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min + scripts/config.pl set MBEDTLS_RSA_NO_CRT + CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . + make -msg "build: Default + RSA_NO_CRT (ASan build)" # ~ 6 min -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl set MBEDTLS_RSA_NO_CRT -CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . -make + msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s + make test -msg "test: RSA_NO_CRT - main suites (inc. selftests) (ASan build)" # ~ 50s -make test + msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s + if_build_succeeded tests/ssl-opt.sh -f RSA -msg "test: RSA_NO_CRT - RSA-related part of ssl-opt.sh (ASan build)" # ~ 5s -if_build_succeeded tests/ssl-opt.sh -f RSA + msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min + if_build_succeeded tests/compat.sh -t RSA +} -msg "test: RSA_NO_CRT - RSA-related part of compat.sh (ASan build)" # ~ 3 min -if_build_succeeded tests/compat.sh -t RSA +component_test_full_cmake_clang () { + msg "build: cmake, full config, clang" # ~ 50s + scripts/config.pl full + scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests + CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On . + make -msg "build: cmake, full config, clang" # ~ 50s -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl full -scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # too slow for tests -CC=clang cmake -D CMAKE_BUILD_TYPE:String=Check -D ENABLE_TESTING=On . -make + msg "test: main suites (full config)" # ~ 5s + make test -msg "test: main suites (full config)" # ~ 5s -make test + msg "test: ssl-opt.sh default (full config)" # ~ 1s + if_build_succeeded tests/ssl-opt.sh -f Default -msg "test: ssl-opt.sh default (full config)" # ~ 1s -if_build_succeeded tests/ssl-opt.sh -f Default + msg "test: compat.sh RC4, DES, 3DES & NULL (full config)" # ~ 2 min + if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR' +} -msg "test: compat.sh RC4, DES & NULL (full config)" # ~ 2 min -if_build_succeeded env OPENSSL_CMD="$OPENSSL_LEGACY" GNUTLS_CLI="$GNUTLS_LEGACY_CLI" GNUTLS_SERV="$GNUTLS_LEGACY_SERV" tests/compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR' +component_build_deprecated () { + msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s + scripts/config.pl full + scripts/config.pl set MBEDTLS_DEPRECATED_WARNING + # Build with -O -Wextra to catch a maximum of issues. + make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs + make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests -msg "build: make, full config + DEPRECATED_WARNING, gcc -O" # ~ 30s -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl full -scripts/config.pl set MBEDTLS_DEPRECATED_WARNING -# Build with -O -Wextra to catch a maximum of issues. -make CC=gcc CFLAGS='-O -Werror -Wall -Wextra' lib programs -make CC=gcc CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests - -msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s -# No cleanup, just tweak the configuration and rebuild -make clean -scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING -scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED -# Build with -O -Wextra to catch a maximum of issues. -make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs -make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests - -msg "test/build: curves.pl (gcc)" # ~ 4 min -cleanup -record_status tests/scripts/curves.pl + msg "build: make, full config + DEPRECATED_REMOVED, clang -O" # ~ 30s + # No cleanup, just tweak the configuration and rebuild + make clean + scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING + scripts/config.pl set MBEDTLS_DEPRECATED_REMOVED + # Build with -O -Wextra to catch a maximum of issues. + make CC=clang CFLAGS='-O -Werror -Wall -Wextra' lib programs + make CC=clang CFLAGS='-O -Werror -Wall -Wextra -Wno-unused-function' tests +} -msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min -cleanup -record_status tests/scripts/depends-hashes.pl +component_test_depends_curves () { + msg "test/build: curves.pl (gcc)" # ~ 4 min + record_status tests/scripts/curves.pl +} -msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min -cleanup -record_status tests/scripts/depends-pkalgs.pl +component_test_depends_hashes () { + msg "test/build: depends-hashes.pl (gcc)" # ~ 2 min + record_status tests/scripts/depends-hashes.pl +} -msg "test/build: key-exchanges (gcc)" # ~ 1 min -cleanup -record_status tests/scripts/key-exchanges.pl +component_test_depends_pkalgs () { + msg "test/build: depends-pkalgs.pl (gcc)" # ~ 2 min + record_status tests/scripts/depends-pkalgs.pl +} -msg "build: Unix make, -Os (gcc)" # ~ 30s -cleanup -make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' +component_build_key_exchanges () { + msg "test/build: key-exchanges (gcc)" # ~ 1 min + record_status tests/scripts/key-exchanges.pl +} -# Full configuration build, without platform support, file IO and net sockets. -# This should catch missing mbedtls_printf definitions, and by disabling file -# IO, it should catch missing '#include ' -msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl full -scripts/config.pl unset MBEDTLS_PLATFORM_C -scripts/config.pl unset MBEDTLS_NET_C -scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY -scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT -scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT -scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT -scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT -scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT -scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED -scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C -scripts/config.pl unset MBEDTLS_FS_IO -# Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19, -# to re-enable platform integration features otherwise disabled in C99 builds -make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs -make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test - -# catch compile bugs in _uninit functions -msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl full -scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS -scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED -make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' +component_build_default_make_gcc () { + msg "build: Unix make, -Os (gcc)" # ~ 30s + make CC=gcc CFLAGS='-Werror -Wall -Wextra -Os' +} -msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl full -scripts/config.pl unset MBEDTLS_SSL_SRV_C -make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' +component_test_no_platform () { + # Full configuration build, without platform support, file IO and net sockets. + # This should catch missing mbedtls_printf definitions, and by disabling file + # IO, it should catch missing '#include ' + msg "build: full config except platform/fsio/net, make, gcc, C99" # ~ 30s + scripts/config.pl full + scripts/config.pl unset MBEDTLS_PLATFORM_C + scripts/config.pl unset MBEDTLS_NET_C + scripts/config.pl unset MBEDTLS_PLATFORM_MEMORY + scripts/config.pl unset MBEDTLS_PLATFORM_PRINTF_ALT + scripts/config.pl unset MBEDTLS_PLATFORM_FPRINTF_ALT + scripts/config.pl unset MBEDTLS_PLATFORM_SNPRINTF_ALT + scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT + scripts/config.pl unset MBEDTLS_PLATFORM_EXIT_ALT + scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED + scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C + scripts/config.pl unset MBEDTLS_FS_IO + # Note, _DEFAULT_SOURCE needs to be defined for platforms using glibc version >2.19, + # to re-enable platform integration features otherwise disabled in C99 builds + make CC=gcc CFLAGS='-Werror -Wall -Wextra -std=c99 -pedantic -O0 -D_DEFAULT_SOURCE' lib programs + make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' test +} -msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl full -scripts/config.pl unset MBEDTLS_SSL_CLI_C -make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' - -# Note, C99 compliance can also be tested with the sockets support disabled, -# as that requires a POSIX platform (which isn't the same as C99). -msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl full -scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc. -scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux -make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib +component_build_no_std_function () { + # catch compile bugs in _uninit functions + msg "build: full config with NO_STD_FUNCTION, make, gcc" # ~ 30s + scripts/config.pl full + scripts/config.pl set MBEDTLS_PLATFORM_NO_STD_FUNCTIONS + scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED + make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' +} -msg "build: default config except MFL extension (ASan build)" # ~ 30s -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH -CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . -make +component_build_no_ssl_srv () { + msg "build: full config except ssl_srv.c, make, gcc" # ~ 30s + scripts/config.pl full + scripts/config.pl unset MBEDTLS_SSL_SRV_C + make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' +} -msg "test: ssl-opt.sh, MFL-related tests" -if_build_succeeded tests/ssl-opt.sh -f "Max fragment length" +component_build_no_ssl_cli () { + msg "build: full config except ssl_cli.c, make, gcc" # ~ 30s + scripts/config.pl full + scripts/config.pl unset MBEDTLS_SSL_CLI_C + make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0' +} -msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)" -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY -scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES -scripts/config.pl set MBEDTLS_ENTROPY_C -scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED -scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT -scripts/config.pl unset MBEDTLS_HAVEGE_C -CC=gcc cmake -D UNSAFE_BUILD=ON -D CMAKE_C_FLAGS:String="-fsanitize=address -fno-common -O3" . -make - -msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)" -make test - -msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)" -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl set MBEDTLS_PLATFORM_MEMORY -scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc -scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free -CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . -make +component_build_no_sockets () { + # Note, C99 compliance can also be tested with the sockets support disabled, + # as that requires a POSIX platform (which isn't the same as C99). + msg "build: full config except net_sockets.c, make, gcc -std=c99 -pedantic" # ~ 30s + scripts/config.pl full + scripts/config.pl unset MBEDTLS_NET_C # getaddrinfo() undeclared, etc. + scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY # uses syscall() on GNU/Linux + make CC=gcc CFLAGS='-Werror -Wall -Wextra -O0 -std=c99 -pedantic' lib +} + +component_test_no_max_fragment_length () { + msg "build: default config except MFL extension (ASan build)" # ~ 30s + scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH + CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . + make + + msg "test: ssl-opt.sh, MFL-related tests" + if_build_succeeded tests/ssl-opt.sh -f "Max fragment length" +} + +component_test_null_entropy () { + msg "build: default config with MBEDTLS_TEST_NULL_ENTROPY (ASan build)" + scripts/config.pl set MBEDTLS_TEST_NULL_ENTROPY + scripts/config.pl set MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES + scripts/config.pl set MBEDTLS_ENTROPY_C + scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED + scripts/config.pl unset MBEDTLS_ENTROPY_HARDWARE_ALT + scripts/config.pl unset MBEDTLS_HAVEGE_C + CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan -D UNSAFE_BUILD=ON . + make + + msg "test: MBEDTLS_TEST_NULL_ENTROPY - main suites (inc. selftests) (ASan build)" + make test +} -msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)" -make test +component_test_platform_calloc_macro () { + msg "build: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)" + scripts/config.pl set MBEDTLS_PLATFORM_MEMORY + scripts/config.pl set MBEDTLS_PLATFORM_CALLOC_MACRO calloc + scripts/config.pl set MBEDTLS_PLATFORM_FREE_MACRO free + CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . + make + + msg "test: MBEDTLS_PLATFORM_{CALLOC/FREE}_MACRO enabled (ASan build)" + make test +} -if uname -a | grep -F Linux >/dev/null; then +component_test_make_shared () { msg "build/test: make shared" # ~ 40s - cleanup make SHARED=1 all check -fi +} -if uname -a | grep -F x86_64 >/dev/null; then +component_test_m32_o0 () { # Build once with -O0, to compile out the i386 specific inline assembly msg "build: i386, make, gcc -O0 (ASan build)" # ~ 30s - cleanup - cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl full make CC=gcc CFLAGS='-O0 -Werror -Wall -Wextra -m32 -fsanitize=address' msg "test: i386, make, gcc -O0 (ASan build)" make test +} +support_test_m32_o0 () { + case $(uname -m) in + *64*) true;; + *) false;; + esac +} +component_test_m32_o1 () { # Build again with -O1, to compile in the i386 specific inline assembly msg "build: i386, make, gcc -O1 (ASan build)" # ~ 30s - cleanup - cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl full + scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE + scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C + scripts/config.pl unset MBEDTLS_MEMORY_DEBUG make CC=gcc CFLAGS='-O1 -Werror -Wall -Wextra -m32 -fsanitize=address' msg "test: i386, make, gcc -O1 (ASan build)" make test + msg "test ssl-opt.sh, i386, make, gcc-O1" + if_build_succeeded tests/ssl-opt.sh +} +support_test_m32_o1 () { + support_test_m32_o0 "$@" +} + +component_test_mx32 () { msg "build: 64-bit ILP32, make, gcc" # ~ 30s - cleanup - cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl full make CC=gcc CFLAGS='-Werror -Wall -Wextra -mx32' msg "test: 64-bit ILP32, make, gcc" make test -fi # x86_64 +} +support_test_mx32 () { + case $(uname -m) in + amd64|x86_64) true;; + *) false;; + esac +} -msg "build: gcc, force 32-bit bignum limbs" -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl unset MBEDTLS_HAVE_ASM -scripts/config.pl unset MBEDTLS_AESNI_C -scripts/config.pl unset MBEDTLS_PADLOCK_C -make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32' +component_test_min_mpi_window_size () { + msg "build: Default + MBEDTLS_MPI_WINDOW_SIZE=1 (ASan build)" # ~ 10s + scripts/config.pl set MBEDTLS_MPI_WINDOW_SIZE 1 + CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . + make -msg "test: gcc, force 32-bit bignum limbs" -make test + msg "test: MBEDTLS_MPI_WINDOW_SIZE=1 - main suites (inc. selftests) (ASan build)" # ~ 10s + make test +} -msg "build: gcc, force 64-bit bignum limbs" -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl unset MBEDTLS_HAVE_ASM -scripts/config.pl unset MBEDTLS_AESNI_C -scripts/config.pl unset MBEDTLS_PADLOCK_C -make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64' +component_test_have_int32 () { + msg "build: gcc, force 32-bit bignum limbs" + scripts/config.pl unset MBEDTLS_HAVE_ASM + scripts/config.pl unset MBEDTLS_AESNI_C + scripts/config.pl unset MBEDTLS_PADLOCK_C + make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT32' -msg "test: gcc, force 64-bit bignum limbs" -make test + msg "test: gcc, force 32-bit bignum limbs" + make test +} + +component_test_have_int64 () { + msg "build: gcc, force 64-bit bignum limbs" + scripts/config.pl unset MBEDTLS_HAVE_ASM + scripts/config.pl unset MBEDTLS_AESNI_C + scripts/config.pl unset MBEDTLS_PADLOCK_C + make CC=gcc CFLAGS='-Werror -Wall -Wextra -DMBEDTLS_HAVE_INT64' + + msg "test: gcc, force 64-bit bignum limbs" + make test +} + +component_build_arm_none_eabi_gcc () { + msg "build: arm-none-eabi-gcc, make" # ~ 10s + scripts/config.pl full + scripts/config.pl unset MBEDTLS_NET_C + scripts/config.pl unset MBEDTLS_TIMING_C + scripts/config.pl unset MBEDTLS_FS_IO + scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED + scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY + # following things are not in the default config + scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c + scripts/config.pl unset MBEDTLS_THREADING_PTHREAD + scripts/config.pl unset MBEDTLS_THREADING_C + scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h + scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit + make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib +} + +component_build_arm_none_eabi_gcc_no_udbl_division () { + msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s + scripts/config.pl full + scripts/config.pl unset MBEDTLS_NET_C + scripts/config.pl unset MBEDTLS_TIMING_C + scripts/config.pl unset MBEDTLS_FS_IO + scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED + scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY + # following things are not in the default config + scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c + scripts/config.pl unset MBEDTLS_THREADING_PTHREAD + scripts/config.pl unset MBEDTLS_THREADING_C + scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h + scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit + scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION + make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib + echo "Checking that software 64-bit division is not required" + if_build_succeeded not grep __aeabi_uldiv library/*.o +} + +component_build_armcc () { + msg "build: ARM Compiler 5, make" + scripts/config.pl full + scripts/config.pl unset MBEDTLS_NET_C + scripts/config.pl unset MBEDTLS_TIMING_C + scripts/config.pl unset MBEDTLS_FS_IO + scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED + scripts/config.pl unset MBEDTLS_HAVE_TIME + scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE + scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY + # following things are not in the default config + scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING + scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c + scripts/config.pl unset MBEDTLS_THREADING_PTHREAD + scripts/config.pl unset MBEDTLS_THREADING_C + scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h + scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit + scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME -msg "build: arm-none-eabi-gcc, make" # ~ 10s -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl full -scripts/config.pl unset MBEDTLS_NET_C -scripts/config.pl unset MBEDTLS_TIMING_C -scripts/config.pl unset MBEDTLS_FS_IO -scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED -scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY -# following things are not in the default config -scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c -scripts/config.pl unset MBEDTLS_THREADING_PTHREAD -scripts/config.pl unset MBEDTLS_THREADING_C -scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h -scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit -make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib - -msg "build: arm-none-eabi-gcc -DMBEDTLS_NO_UDBL_DIVISION, make" # ~ 10s -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl full -scripts/config.pl unset MBEDTLS_NET_C -scripts/config.pl unset MBEDTLS_TIMING_C -scripts/config.pl unset MBEDTLS_FS_IO -scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED -scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY -# following things are not in the default config -scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c -scripts/config.pl unset MBEDTLS_THREADING_PTHREAD -scripts/config.pl unset MBEDTLS_THREADING_C -scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h -scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit -scripts/config.pl set MBEDTLS_NO_UDBL_DIVISION -make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar LD=arm-none-eabi-ld CFLAGS='-Werror -Wall -Wextra' lib -echo "Checking that software 64-bit division is not required" -! grep __aeabi_uldiv library/*.o - -msg "build: ARM Compiler 5, make" -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl full -scripts/config.pl unset MBEDTLS_NET_C -scripts/config.pl unset MBEDTLS_TIMING_C -scripts/config.pl unset MBEDTLS_FS_IO -scripts/config.pl unset MBEDTLS_ENTROPY_NV_SEED -scripts/config.pl unset MBEDTLS_HAVE_TIME -scripts/config.pl unset MBEDTLS_HAVE_TIME_DATE -scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY -# following things are not in the default config -scripts/config.pl unset MBEDTLS_DEPRECATED_WARNING -scripts/config.pl unset MBEDTLS_HAVEGE_C # depends on timing.c -scripts/config.pl unset MBEDTLS_THREADING_PTHREAD -scripts/config.pl unset MBEDTLS_THREADING_C -scripts/config.pl unset MBEDTLS_MEMORY_BACKTRACE # execinfo.h -scripts/config.pl unset MBEDTLS_MEMORY_BUFFER_ALLOC_C # calls exit -scripts/config.pl unset MBEDTLS_PLATFORM_TIME_ALT # depends on MBEDTLS_HAVE_TIME - -if [ $RUN_ARMCC -ne 0 ]; then make CC="$ARMC5_CC" AR="$ARMC5_AR" WARNING_CFLAGS='--strict --c99' lib make clean @@ -798,46 +992,33 @@ if [ $RUN_ARMCC -ne 0 ]; then # ARM Compiler 6 - Target ARMv8-A - AArch64 armc6_build_test "--target=aarch64-arm-none-eabi -march=armv8.2-a" -fi - -msg "build: allow SHA1 in certificates by default" -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES -make CFLAGS='-Werror -Wall -Wextra' -msg "test: allow SHA1 in certificates by default" -make test -if_build_succeeded tests/ssl-opt.sh -f SHA-1 - -msg "build: Default + MBEDTLS_RSA_NO_CRT (ASan build)" # ~ 6 min -cleanup -cp "$CONFIG_H" "$CONFIG_BAK" -scripts/config.pl set MBEDTLS_RSA_NO_CRT -CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan . -make - -msg "test: MBEDTLS_RSA_NO_CRT - main suites (inc. selftests) (ASan build)" -make test +} -msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s -cleanup -make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs +component_test_allow_sha1 () { + msg "build: allow SHA1 in certificates by default" + scripts/config.pl set MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES + make CFLAGS='-Werror -Wall -Wextra' + msg "test: allow SHA1 in certificates by default" + make test + if_build_succeeded tests/ssl-opt.sh -f SHA-1 +} -# note Make tests only builds the tests, but doesn't run them -make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests -make WINDOWS_BUILD=1 clean +component_build_mingw () { + msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s + make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 lib programs -msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s -make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs -make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests -make WINDOWS_BUILD=1 clean + # note Make tests only builds the tests, but doesn't run them + make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror' WINDOWS_BUILD=1 tests + make WINDOWS_BUILD=1 clean -# MemSan currently only available on Linux 64 bits -if uname -a | grep 'Linux.*x86_64' >/dev/null; then + msg "build: Windows cross build - mingw64, make (DLL)" # ~ 30s + make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 lib programs + make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra' WINDOWS_BUILD=1 SHARED=1 tests + make WINDOWS_BUILD=1 clean +} +component_test_memsan () { msg "build: MSan (clang)" # ~ 1 min 20s - cleanup - cp "$CONFIG_H" "$CONFIG_BAK" scripts/config.pl unset MBEDTLS_AESNI_C # memsan doesn't grok asm CC=clang cmake -D CMAKE_BUILD_TYPE:String=MemSan . make @@ -854,21 +1035,18 @@ if uname -a | grep 'Linux.*x86_64' >/dev/null; then msg "test: compat.sh (MSan)" # ~ 6 min 20s if_build_succeeded tests/compat.sh fi +} -else # no MemSan - +component_test_valgrind () { msg "build: Release (clang)" - cleanup CC=clang cmake -D CMAKE_BUILD_TYPE:String=Release . make msg "test: main suites valgrind (Release)" make memcheck - # Optional part(s) - # Currently broken, programs don't seem to receive signals - # under valgrind on OS X - + # Optional parts (slow; currently broken on OS X because programs don't + # seem to receive signals under valgrind on OS X). if [ "$MEMORY" -gt 0 ]; then msg "test: ssl-opt.sh --memcheck (Release)" if_build_succeeded tests/ssl-opt.sh --memcheck @@ -878,33 +1056,33 @@ else # no MemSan msg "test: compat.sh --memcheck (Release)" if_build_succeeded tests/compat.sh --memcheck fi +} -fi # MemSan +component_test_cmake_out_of_source () { + msg "build: cmake 'out-of-source' build" + MBEDTLS_ROOT_DIR="$PWD" + mkdir "$OUT_OF_SOURCE_DIR" + cd "$OUT_OF_SOURCE_DIR" + cmake "$MBEDTLS_ROOT_DIR" + make -msg "build: cmake 'out-of-source' build" -cleanup -MBEDTLS_ROOT_DIR="$PWD" -mkdir "$OUT_OF_SOURCE_DIR" -cd "$OUT_OF_SOURCE_DIR" -cmake "$MBEDTLS_ROOT_DIR" -make - -msg "test: cmake 'out-of-source' build" -make test -# Test an SSL option that requires an auxiliary script in test/scripts/. -# Also ensure that there are no error messages such as -# "No such file or directory", which would indicate that some required -# file is missing (ssl-opt.sh tolerates the absence of some files so -# may exit with status 0 but emit errors). -if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err -if [ -s ssl-opt.err ]; then - cat ssl-opt.err >&2 - record_status [ ! -s ssl-opt.err ] - rm ssl-opt.err -fi -cd "$MBEDTLS_ROOT_DIR" -rm -rf "$OUT_OF_SOURCE_DIR" -unset MBEDTLS_ROOT_DIR + msg "test: cmake 'out-of-source' build" + make test + # Test an SSL option that requires an auxiliary script in test/scripts/. + # Also ensure that there are no error messages such as + # "No such file or directory", which would indicate that some required + # file is missing (ssl-opt.sh tolerates the absence of some files so + # may exit with status 0 but emit errors). + if_build_succeeded ./tests/ssl-opt.sh -f 'Fallback SCSV: beginning of list' 2>ssl-opt.err + if [ -s ssl-opt.err ]; then + cat ssl-opt.err >&2 + record_status [ ! -s ssl-opt.err ] + rm ssl-opt.err + fi + cd "$MBEDTLS_ROOT_DIR" + rm -rf "$OUT_OF_SOURCE_DIR" + unset MBEDTLS_ROOT_DIR +} @@ -912,7 +1090,51 @@ unset MBEDTLS_ROOT_DIR #### Termination ################################################################ -msg "Done, cleaning up" +post_report () { + msg "Done, cleaning up" + cleanup + + final_report +} + + + +################################################################ +#### Run all the things +################################################################ + +# Run one component and clean up afterwards. +run_component () { + # Back up the configuration in case the component modifies it. + # The cleanup function will restore it. + cp -p "$CONFIG_H" "$CONFIG_BAK" + current_component="$1" + "$@" + cleanup +} + +# Preliminary setup +pre_check_environment +pre_initialize_variables +pre_parse_command_line "$@" + +pre_check_git +build_status=0 +if [ $KEEP_GOING -eq 1 ]; then + pre_setup_keep_going +else + record_status () { + "$@" + } +fi +pre_print_configuration +pre_check_tools cleanup -final_report +# Run the requested tests. +for component in $RUN_COMPONENTS; do + run_component "component_$component" +done + +# We're done. +post_report diff --git a/3rdparty/mbedtls/mbedtls/tests/scripts/basic-build-test.sh b/3rdparty/mbedtls/mbedtls/tests/scripts/basic-build-test.sh index fbe757d9ef..97120ea84d 100755 --- a/3rdparty/mbedtls/mbedtls/tests/scripts/basic-build-test.sh +++ b/3rdparty/mbedtls/mbedtls/tests/scripts/basic-build-test.sh @@ -91,7 +91,7 @@ OPENSSL_CMD="$OPENSSL_LEGACY" \ OPENSSL_CMD="$OPENSSL_LEGACY" \ GNUTLS_CLI="$GNUTLS_LEGACY_CLI" \ GNUTLS_SERV="$GNUTLS_LEGACY_SERV" \ - sh compat.sh -e '3DES\|DES-CBC3' -f 'NULL\|DES\|RC4\|ARCFOUR' | \ + sh compat.sh -e '^$' -f 'NULL\|DES\|RC4\|ARCFOUR' | \ tee -a compat-test-$TEST_OUTPUT echo diff --git a/3rdparty/mbedtls/mbedtls/tests/scripts/check-files.py b/3rdparty/mbedtls/mbedtls/tests/scripts/check-files.py index 7ea321f880..0bf01206e4 100755 --- a/3rdparty/mbedtls/mbedtls/tests/scripts/check-files.py +++ b/3rdparty/mbedtls/mbedtls/tests/scripts/check-files.py @@ -19,14 +19,23 @@ import sys -class IssueTracker(object): - """Base class for issue tracking. Issues should inherit from this and - overwrite either issue_with_line if they check the file line by line, or - overwrite check_file_for_issue if they check the file as a whole.""" +class FileIssueTracker(object): + """Base class for file-wide issue tracking. + + To implement a checker that processes a file as a whole, inherit from + this class and implement `check_file_for_issue` and define ``heading``. + + ``files_exemptions``: files whose name ends with a string in this set + will not be checked. + + ``heading``: human-readable description of the issue + """ + + files_exemptions = frozenset() + # heading must be defined in derived classes. + # pylint: disable=no-member def __init__(self): - self.heading = "" - self.files_exemptions = [] self.files_with_issues = {} def should_check_file(self, filepath): @@ -35,23 +44,14 @@ def should_check_file(self, filepath): return False return True - def issue_with_line(self, line): - raise NotImplementedError - def check_file_for_issue(self, filepath): - with open(filepath, "rb") as f: - for i, line in enumerate(iter(f.readline, b"")): - self.check_file_line(filepath, line, i + 1) + raise NotImplementedError def record_issue(self, filepath, line_number): if filepath not in self.files_with_issues.keys(): self.files_with_issues[filepath] = [] self.files_with_issues[filepath].append(line_number) - def check_file_line(self, filepath, line, line_number): - if self.issue_with_line(line): - self.record_issue(filepath, line_number) - def output_file_issues(self, logger): if self.files_with_issues.values(): logger.info(self.heading) @@ -64,24 +64,44 @@ def output_file_issues(self, logger): logger.info(filename) logger.info("") +class LineIssueTracker(FileIssueTracker): + """Base class for line-by-line issue tracking. -class PermissionIssueTracker(IssueTracker): + To implement a checker that processes files line by line, inherit from + this class and implement `line_with_issue`. + """ - def __init__(self): - super().__init__() - self.heading = "Incorrect permissions:" + def issue_with_line(self, line, filepath): + raise NotImplementedError + + def check_file_line(self, filepath, line, line_number): + if self.issue_with_line(line, filepath): + self.record_issue(filepath, line_number) + + def check_file_for_issue(self, filepath): + with open(filepath, "rb") as f: + for i, line in enumerate(iter(f.readline, b"")): + self.check_file_line(filepath, line, i + 1) + +class PermissionIssueTracker(FileIssueTracker): + """Track files with bad permissions. + + Files that are not executable scripts must not be executable.""" + + heading = "Incorrect permissions:" def check_file_for_issue(self, filepath): - if not (os.access(filepath, os.X_OK) == - filepath.endswith((".sh", ".pl", ".py"))): + is_executable = os.access(filepath, os.X_OK) + should_be_executable = filepath.endswith((".sh", ".pl", ".py")) + if is_executable != should_be_executable: self.files_with_issues[filepath] = None -class EndOfFileNewlineIssueTracker(IssueTracker): +class EndOfFileNewlineIssueTracker(FileIssueTracker): + """Track files that end with an incomplete line + (no newline character at the end of the last line).""" - def __init__(self): - super().__init__() - self.heading = "Missing newline at end of file:" + heading = "Missing newline at end of file:" def check_file_for_issue(self, filepath): with open(filepath, "rb") as f: @@ -89,11 +109,11 @@ def check_file_for_issue(self, filepath): self.files_with_issues[filepath] = None -class Utf8BomIssueTracker(IssueTracker): +class Utf8BomIssueTracker(FileIssueTracker): + """Track files that start with a UTF-8 BOM. + Files should be ASCII or UTF-8. Valid UTF-8 does not start with a BOM.""" - def __init__(self): - super().__init__() - self.heading = "UTF-8 BOM present:" + heading = "UTF-8 BOM present:" def check_file_for_issue(self, filepath): with open(filepath, "rb") as f: @@ -101,77 +121,76 @@ def check_file_for_issue(self, filepath): self.files_with_issues[filepath] = None -class LineEndingIssueTracker(IssueTracker): +class LineEndingIssueTracker(LineIssueTracker): + """Track files with non-Unix line endings (i.e. files with CR).""" - def __init__(self): - super().__init__() - self.heading = "Non Unix line endings:" + heading = "Non Unix line endings:" - def issue_with_line(self, line): + def issue_with_line(self, line, _filepath): return b"\r" in line -class TrailingWhitespaceIssueTracker(IssueTracker): +class TrailingWhitespaceIssueTracker(LineIssueTracker): + """Track lines with trailing whitespace.""" - def __init__(self): - super().__init__() - self.heading = "Trailing whitespace:" - self.files_exemptions = [".md"] + heading = "Trailing whitespace:" + files_exemptions = frozenset(".md") - def issue_with_line(self, line): + def issue_with_line(self, line, _filepath): return line.rstrip(b"\r\n") != line.rstrip() -class TabIssueTracker(IssueTracker): +class TabIssueTracker(LineIssueTracker): + """Track lines with tabs.""" - def __init__(self): - super().__init__() - self.heading = "Tabs present:" - self.files_exemptions = [ - "Makefile", "generate_visualc_files.pl" - ] + heading = "Tabs present:" + files_exemptions = frozenset([ + "Makefile", + "generate_visualc_files.pl", + ]) - def issue_with_line(self, line): + def issue_with_line(self, line, _filepath): return b"\t" in line -class MergeArtifactIssueTracker(IssueTracker): +class MergeArtifactIssueTracker(LineIssueTracker): + """Track lines with merge artifacts. + These are leftovers from a ``git merge`` that wasn't fully edited.""" - def __init__(self): - super().__init__() - self.heading = "Merge artifact:" + heading = "Merge artifact:" - def issue_with_line(self, filepath, line): + def issue_with_line(self, line, _filepath): # Detect leftover git conflict markers. if line.startswith(b'<<<<<<< ') or line.startswith(b'>>>>>>> '): return True if line.startswith(b'||||||| '): # from merge.conflictStyle=diff3 return True if line.rstrip(b'\r\n') == b'=======' and \ - not filepath.endswith('.md'): + not _filepath.endswith('.md'): return True return False - def check_file_line(self, filepath, line, line_number): - if self.issue_with_line(filepath, line): - self.record_issue(filepath, line_number) - -class TodoIssueTracker(IssueTracker): +class TodoIssueTracker(LineIssueTracker): + """Track lines containing ``TODO``.""" - def __init__(self): - super().__init__() - self.heading = "TODO present:" - self.files_exemptions = [ - __file__, "benchmark.c", "pull_request_template.md" - ] + heading = "TODO present:" + files_exemptions = frozenset([ + os.path.basename(__file__), + "benchmark.c", + "pull_request_template.md", + ]) - def issue_with_line(self, line): + def issue_with_line(self, line, _filepath): return b"todo" in line.lower() class IntegrityChecker(object): + """Sanity-check files under the current directory.""" def __init__(self, log_file): + """Instantiate the sanity checker. + Check files under the current directory. + Write a report of issues to log_file.""" self.check_repo_path() self.logger = None self.setup_logger(log_file) @@ -196,7 +215,8 @@ def __init__(self, log_file): TodoIssueTracker(), ] - def check_repo_path(self): + @staticmethod + def check_repo_path(): if not all(os.path.isdir(d) for d in ["include", "library", "tests"]): raise Exception("Must be run from Mbed TLS root") diff --git a/3rdparty/mbedtls/mbedtls/tests/scripts/check-names.sh b/3rdparty/mbedtls/mbedtls/tests/scripts/check-names.sh index 4c66440e25..66c487cffd 100755 --- a/3rdparty/mbedtls/mbedtls/tests/scripts/check-names.sh +++ b/3rdparty/mbedtls/mbedtls/tests/scripts/check-names.sh @@ -2,26 +2,42 @@ # # This file is part of mbed TLS (https://tls.mbed.org) # -# Copyright (c) 2015-2016, ARM Limited, All Rights Reserved -# -# Purpose -# -# This script confirms that the naming of all symbols and identifiers in mbed -# TLS are consistent with the house style and are also self-consistent. -# +# Copyright (c) 2015-2019, ARM Limited, All Rights Reserved + set -eu +if [ $# -ne 0 ] && [ "$1" = "--help" ]; then + cat </dev/null; then :; else echo "This script requires GNU grep.">&2 exit 1 fi +trace= +if [ $# -ne 0 ] && [ "$1" = "-v" ]; then + shift + trace='-x' + exec 2>check-names.err + trap 'echo "FAILED UNEXPECTEDLY, status=$?"; + cat check-names.err' EXIT + set -x +fi + printf "Analysing source code...\n" -tests/scripts/list-macros.sh +sh $trace tests/scripts/list-macros.sh tests/scripts/list-enum-consts.pl -tests/scripts/list-identifiers.sh -tests/scripts/list-symbols.sh +sh $trace tests/scripts/list-identifiers.sh +sh $trace tests/scripts/list-symbols.sh FAIL=0 @@ -82,6 +98,12 @@ else FAIL=1 fi +if [ -n "$trace" ]; then + set +x + trap - EXIT + rm check-names.err +fi + printf "\nOverall: " if [ "$FAIL" -eq 0 ]; then rm macros actual-macros enum-consts identifiers exported-symbols diff --git a/3rdparty/mbedtls/mbedtls/tests/scripts/list-identifiers.sh b/3rdparty/mbedtls/mbedtls/tests/scripts/list-identifiers.sh index 130d9d63f6..cc9c54fad6 100755 --- a/3rdparty/mbedtls/mbedtls/tests/scripts/list-identifiers.sh +++ b/3rdparty/mbedtls/mbedtls/tests/scripts/list-identifiers.sh @@ -1,4 +1,10 @@ -#!/bin/sh +#!/bin/bash +# +# Create a file named identifiers containing identifiers from internal header +# files or all header files, based on --internal flag. +# Outputs the line count of the file to stdout. +# +# Usage: list-identifiers.sh [ -i | --internal ] set -eu @@ -7,7 +13,29 @@ if [ -d include/mbedtls ]; then :; else exit 1 fi -HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' ) +INTERNAL="" + +until [ -z "${1-}" ] +do + case "$1" in + -i|--internal) + INTERNAL="1" + ;; + *) + # print error + echo "Unknown argument: '$1'" + exit 1 + ;; + esac + shift +done + +if [ $INTERNAL ] +then + HEADERS=$( ls include/mbedtls/*_internal.h | egrep -v 'compat-1\.3\.h|bn_mul' ) +else + HEADERS=$( ls include/mbedtls/*.h | egrep -v 'compat-1\.3\.h|bn_mul' ) +fi rm -f identifiers diff --git a/3rdparty/mbedtls/mbedtls/tests/scripts/list-symbols.sh b/3rdparty/mbedtls/mbedtls/tests/scripts/list-symbols.sh index c258719429..930722c1bb 100755 --- a/3rdparty/mbedtls/mbedtls/tests/scripts/list-symbols.sh +++ b/3rdparty/mbedtls/mbedtls/tests/scripts/list-symbols.sh @@ -14,8 +14,21 @@ fi cp include/mbedtls/config.h include/mbedtls/config.h.bak scripts/config.pl full -CFLAGS=-fno-asynchronous-unwind-tables make clean lib >/dev/null 2>&1 +make clean +make_ret= +CFLAGS=-fno-asynchronous-unwind-tables make lib \ + >list-symbols.make.log 2>&1 || + { + make_ret=$? + echo "Build failure: CFLAGS=-fno-asynchronous-unwind-tables make lib" + cat list-symbols.make.log >&2 + } +rm list-symbols.make.log mv include/mbedtls/config.h.bak include/mbedtls/config.h +if [ -n "$make_ret" ]; then + exit "$make_ret" +fi + if uname | grep -F Darwin >/dev/null; then nm -gUj library/libmbed*.a 2>/dev/null | sed -n -e 's/^_//p' elif uname | grep -F Linux >/dev/null; then diff --git a/3rdparty/mbedtls/mbedtls/tests/scripts/run-test-suites.pl b/3rdparty/mbedtls/mbedtls/tests/scripts/run-test-suites.pl index d0d4046215..1c9dc1dfcb 100755 --- a/3rdparty/mbedtls/mbedtls/tests/scripts/run-test-suites.pl +++ b/3rdparty/mbedtls/mbedtls/tests/scripts/run-test-suites.pl @@ -4,19 +4,24 @@ # # This file is part of mbed TLS (https://tls.mbed.org) # -# Copyright (c) 2015-2016, ARM Limited, All Rights Reserved -# -# Purpose -# -# Executes all the available test suites, and provides a basic summary of the -# results. -# -# Usage: run-test-suites.pl [-v] -# -# Options : -# -v|--verbose - Provide a pass/fail/skip breakdown per test suite and -# in total -# +# Copyright (c) 2015-2018, ARM Limited, All Rights Reserved + +=head1 SYNOPSIS + +Execute all the test suites and print a summary of the results. + + run-test-suites.pl [[-v|--verbose] [VERBOSITY]] [--skip=SUITE[...]] + +Options: + + -v|--verbose Print detailed failure information. + -v 2|--verbose=2 Print detailed failure information and summary messages. + -v 3|--verbose=3 Print detailed information about every test case. + --skip=SUITE[,SUITE...] + Skip the specified SUITE(s). This option can be used + multiple times. + +=cut use warnings; use strict; @@ -24,10 +29,15 @@ use utf8; use open qw(:std utf8); -use Getopt::Long; +use Getopt::Long qw(:config auto_help gnu_compat); +use Pod::Usage; my $verbose = 0; -GetOptions( "verbose|v:1" => \$verbose ); +my @skip_patterns = (); +GetOptions( + 'skip=s' => \@skip_patterns, + 'verbose|v:1' => \$verbose, + ) or die; # All test suites = executable files, excluding source files, debug # and profiling information, etc. We can't just grep {! /\./} because @@ -36,6 +46,17 @@ @suites = grep { !/\.c$/ && !/\.data$/ && -f } @suites; die "$0: no test suite found\n" unless @suites; +# "foo" as a skip pattern skips "test_suite_foo" and "test_suite_foo.bar" +# but not "test_suite_foobar". +my $skip_re = + ( '\Atest_suite_(' . + join('|', map { + s/[ ,;]/|/g; # allow any of " ,;|" as separators + s/\./\./g; # "." in the input means ".", not "any character" + $_ + } @skip_patterns) . + ')(\z|\.)' ); + # in case test suites are linked dynamically $ENV{'LD_LIBRARY_PATH'} = '../library'; $ENV{'DYLD_LIBRARY_PATH'} = '../library'; @@ -45,6 +66,7 @@ my ($failed_suites, $total_tests_run, $failed, $suite_cases_passed, $suite_cases_failed, $suite_cases_skipped, $total_cases_passed, $total_cases_failed, $total_cases_skipped ); +my $suites_skipped = 0; sub pad_print_center { my( $width, $padchar, $string ) = @_; @@ -55,6 +77,12 @@ sub pad_print_center { for my $suite (@suites) { print "$suite ", "." x ( 72 - length($suite) - 2 - 4 ), " "; + if( $suite =~ /$skip_re/o ) { + print "SKIP\n"; + ++$suites_skipped; + next; + } + my $command = "$prefix$suite"; if( $verbose ) { $command .= ' -v'; @@ -101,7 +129,10 @@ sub pad_print_center { print "-" x 72, "\n"; print $failed_suites ? "FAILED" : "PASSED"; -printf " (%d suites, %d tests run)\n", scalar @suites, $total_tests_run; +printf( " (%d suites, %d tests run%s)\n", + scalar(@suites) - $suites_skipped, + $total_tests_run, + $suites_skipped ? ", $suites_skipped suites skipped" : "" ); if( $verbose > 1 ) { print " test cases passed :", $total_cases_passed, "\n"; @@ -111,8 +142,11 @@ sub pad_print_center { "\n"; print " of available tests :", ( $total_cases_passed + $total_cases_failed + $total_cases_skipped ), - "\n" + "\n"; + if( $suites_skipped != 0 ) { + print "Note: $suites_skipped suites were skipped.\n"; } +} exit( $failed_suites ? 1 : 0 ); diff --git a/3rdparty/mbedtls/mbedtls/tests/ssl-opt.sh b/3rdparty/mbedtls/mbedtls/tests/ssl-opt.sh index ae98ae9862..fbd03673cf 100755 --- a/3rdparty/mbedtls/mbedtls/tests/ssl-opt.sh +++ b/3rdparty/mbedtls/mbedtls/tests/ssl-opt.sh @@ -3708,26 +3708,37 @@ run_test "ECJPAKE: working, DTLS, nolog" \ # Tests for ciphersuites per version requires_config_enabled MBEDTLS_SSL_PROTO_SSL3 +requires_config_enabled MBEDTLS_CAMELLIA_C +requires_config_enabled MBEDTLS_AES_C run_test "Per-version suites: SSL3" \ - "$P_SRV min_version=ssl3 version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \ + "$P_SRV min_version=ssl3 version_suites=TLS-RSA-WITH-CAMELLIA-128-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \ "$P_CLI force_version=ssl3" \ 0 \ - -c "Ciphersuite is TLS-RSA-WITH-3DES-EDE-CBC-SHA" + -c "Ciphersuite is TLS-RSA-WITH-CAMELLIA-128-CBC-SHA" +requires_config_enabled MBEDTLS_SSL_PROTO_TLS1 +requires_config_enabled MBEDTLS_CAMELLIA_C +requires_config_enabled MBEDTLS_AES_C run_test "Per-version suites: TLS 1.0" \ - "$P_SRV arc4=1 version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \ + "$P_SRV version_suites=TLS-RSA-WITH-CAMELLIA-128-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \ "$P_CLI force_version=tls1 arc4=1" \ 0 \ -c "Ciphersuite is TLS-RSA-WITH-AES-256-CBC-SHA" +requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_1 +requires_config_enabled MBEDTLS_CAMELLIA_C +requires_config_enabled MBEDTLS_AES_C run_test "Per-version suites: TLS 1.1" \ - "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \ + "$P_SRV version_suites=TLS-RSA-WITH-CAMELLIA-128-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \ "$P_CLI force_version=tls1_1" \ 0 \ -c "Ciphersuite is TLS-RSA-WITH-AES-128-CBC-SHA" +requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 +requires_config_enabled MBEDTLS_CAMELLIA_C +requires_config_enabled MBEDTLS_AES_C run_test "Per-version suites: TLS 1.2" \ - "$P_SRV version_suites=TLS-RSA-WITH-3DES-EDE-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \ + "$P_SRV version_suites=TLS-RSA-WITH-CAMELLIA-128-CBC-SHA,TLS-RSA-WITH-AES-256-CBC-SHA,TLS-RSA-WITH-AES-128-CBC-SHA,TLS-RSA-WITH-AES-128-GCM-SHA256" \ "$P_CLI force_version=tls1_2" \ 0 \ -c "Ciphersuite is TLS-RSA-WITH-AES-128-GCM-SHA256" @@ -3736,7 +3747,7 @@ run_test "Per-version suites: TLS 1.2" \ requires_gnutls run_test "ClientHello without extensions, SHA-1 allowed" \ - "$P_SRV debug_level=3" \ + "$P_SRV debug_level=3 key_file=data_files/server2.key crt_file=data_files/server2.crt" \ "$G_CLI --priority=NORMAL:%NO_EXTENSIONS:%DISABLE_SAFE_RENEGOTIATION" \ 0 \ -s "dumping 'client hello extensions' (0 bytes)" @@ -5126,8 +5137,8 @@ run_test "DTLS proxy: duplicate every packet" \ 0 \ -c "replayed record" \ -s "replayed record" \ - -c "discarding invalid record" \ - -s "discarding invalid record" \ + -c "record from another epoch" \ + -s "record from another epoch" \ -S "resend" \ -s "Extra-header:" \ -c "HTTP/1.0 200 OK" @@ -5139,8 +5150,8 @@ run_test "DTLS proxy: duplicate every packet, server anti-replay off" \ 0 \ -c "replayed record" \ -S "replayed record" \ - -c "discarding invalid record" \ - -s "discarding invalid record" \ + -c "record from another epoch" \ + -s "record from another epoch" \ -c "resend" \ -s "resend" \ -s "Extra-header:" \ @@ -5201,8 +5212,6 @@ run_test "DTLS proxy: delay ChangeCipherSpec" \ 0 \ -c "record from another epoch" \ -s "record from another epoch" \ - -c "discarding invalid record" \ - -s "discarding invalid record" \ -s "Extra-header:" \ -c "HTTP/1.0 200 OK" diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/helpers.function b/3rdparty/mbedtls/mbedtls/tests/suites/helpers.function index eef41c79a6..755c3eabd4 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/helpers.function +++ b/3rdparty/mbedtls/mbedtls/tests/suites/helpers.function @@ -144,6 +144,7 @@ static int redirect_output( FILE** out_stream, const char* path ) if( *out_stream == NULL ) { + close( stdout_fd ); return -1; } diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ccm.data b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ccm.data index 90ba42d83c..65dc382432 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ccm.data +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ccm.data @@ -36,6 +36,7 @@ CCM lengths #6 tag length not even ccm_lengths:5:10:5:7:MBEDTLS_ERR_CCM_BAD_INPUT CCM lenghts #7 AD too long (2^16 - 2^8 + 1) +depends_on:!MBEDTLS_CCM_ALT ccm_lengths:5:10:65281:8:MBEDTLS_ERR_CCM_BAD_INPUT CCM lengths #8 msg too long for this IV length (2^16, q = 2) diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_cipher.function b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_cipher.function index 343dd78635..2518ba5761 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_cipher.function +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_cipher.function @@ -627,6 +627,9 @@ void auth_crypt_tv( int cipher_id, char *hex_key, char *hex_iv, TEST_ASSERT( memcmp( output, clear, clear_len ) == 0 ); /* then encrypt the clear and make sure we get the same ciphertext and tag */ + TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key, 8 * key_len, + MBEDTLS_ENCRYPT ) ); + memset( output, 0xFF, sizeof( output ) ); outlen = 0; @@ -635,8 +638,8 @@ void auth_crypt_tv( int cipher_id, char *hex_key, char *hex_iv, my_tag, tag_len ); TEST_ASSERT( ret == 0 ); - TEST_ASSERT( outlen == clear_len ); - TEST_ASSERT( memcmp( output, cipher, clear_len ) == 0 ); + TEST_ASSERT( outlen == cipher_len ); + TEST_ASSERT( memcmp( output, cipher, cipher_len ) == 0 ); TEST_ASSERT( memcmp( my_tag, tag, tag_len ) == 0 ); /* make sure we didn't overwrite */ diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ecdh.data b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ecdh.data index f7119de416..4ed32219b7 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ecdh.data +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ecdh.data @@ -37,3 +37,19 @@ ecdh_exchange:MBEDTLS_ECP_DP_SECP192R1 ECDH exchange #2 depends_on:MBEDTLS_ECP_DP_SECP521R1_ENABLED ecdh_exchange:MBEDTLS_ECP_DP_SECP521R1 + +ECDH calc_secret: ours first, SECP256R1 (RFC 5903) +depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED +ecdh_exchange_calc_secret:MBEDTLS_ECP_DP_SECP256R1:"c6ef9c5d78ae012a011164acb397ce2088685d8f06bf9be0b283ab46476bee53":"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":0:"d6840f6b42f6edafd13116e0e12565202fef8e9ece7dce03812464d04b9442de" + +ECDH calc_secret: theirs first, SECP256R1 (RFC 5903) +depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED +ecdh_exchange_calc_secret:MBEDTLS_ECP_DP_SECP256R1:"c6ef9c5d78ae012a011164acb397ce2088685d8f06bf9be0b283ab46476bee53":"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":1:"d6840f6b42f6edafd13116e0e12565202fef8e9ece7dce03812464d04b9442de" + +ECDH get_params with mismatched groups: our BP256R1, their SECP256R1 +depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_BP256R1_ENABLED +ecdh_exchange_get_params_fail:MBEDTLS_ECP_DP_BP256R1:"1234567812345678123456781234567812345678123456781234567812345678":MBEDTLS_ECP_DP_SECP256R1:"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":0:MBEDTLS_ERR_ECP_BAD_INPUT_DATA + +ECDH get_params with mismatched groups: their SECP256R1, our BP256R1 +depends_on:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_ECP_DP_BP256R1_ENABLED +ecdh_exchange_get_params_fail:MBEDTLS_ECP_DP_BP256R1:"1234567812345678123456781234567812345678123456781234567812345678":MBEDTLS_ECP_DP_SECP256R1:"04dad0b65394221cf9b051e1feca5787d098dfe637fc90b9ef945d0c37725811805271a0461cdb8252d61f1c456fa3e59ab1f45b33accf5f58389e0577b8990bb3":1:MBEDTLS_ERR_ECP_BAD_INPUT_DATA diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ecdh.function b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ecdh.function index 4c6a97baf0..0645ce798b 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ecdh.function +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_ecdh.function @@ -1,5 +1,47 @@ /* BEGIN_HEADER */ #include "mbedtls/ecdh.h" + +static int load_public_key( int grp_id, const char *point_str, + mbedtls_ecp_keypair *ecp ) +{ + int ok = 0; + unsigned char point_buf[MBEDTLS_ECP_MAX_PT_LEN]; + size_t point_len = unhexify( point_buf, point_str ); + + TEST_ASSERT( mbedtls_ecp_group_load( &ecp->grp, grp_id ) == 0 ); + TEST_ASSERT( mbedtls_ecp_point_read_binary( &ecp->grp, + &ecp->Q, + point_buf, + point_len ) == 0 ); + TEST_ASSERT( mbedtls_ecp_check_pubkey( &ecp->grp, + &ecp->Q ) == 0 ); + ok = 1; +exit: + return( ok ); +} + +static int load_private_key( int grp_id, const char *private_key_str, + mbedtls_ecp_keypair *ecp, + rnd_pseudo_info *rnd_info ) +{ + int ok = 0; + unsigned char private_key_buf[MBEDTLS_ECP_MAX_BYTES]; + size_t private_key_len = unhexify( private_key_buf, private_key_str ); + + TEST_ASSERT( mbedtls_ecp_group_load( &ecp->grp, grp_id ) == 0 ); + TEST_ASSERT( mbedtls_mpi_read_binary( &ecp->d, + private_key_buf, + private_key_len ) == 0 ); + TEST_ASSERT( mbedtls_ecp_check_privkey( &ecp->grp, &ecp->d ) == 0 ); + /* Calculate the public key from the private key. */ + TEST_ASSERT( mbedtls_ecp_mul( &ecp->grp, &ecp->Q, &ecp->d, + &ecp->grp.G, + &rnd_pseudo_rand, rnd_info ) == 0 ); + ok = 1; +exit: + return( ok ); +} + /* END_HEADER */ /* BEGIN_DEPENDENCIES @@ -158,3 +200,111 @@ exit: mbedtls_ecdh_free( &cli ); } /* END_CASE */ + +/* BEGIN_CASE */ +void ecdh_exchange_calc_secret( int grp_id, + char *our_private_key, + char *their_point, + int ours_first, + char *expected_str ) +{ + rnd_pseudo_info rnd_info; + unsigned char expected_buf[MBEDTLS_ECP_MAX_BYTES]; + size_t expected_len; + mbedtls_ecp_keypair our_key; + mbedtls_ecp_keypair their_key; + mbedtls_ecdh_context ecdh; + unsigned char shared_secret[MBEDTLS_ECP_MAX_BYTES]; + size_t shared_secret_length = 0; + + memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) ); + mbedtls_ecdh_init( &ecdh ); + mbedtls_ecp_keypair_init( &our_key ); + mbedtls_ecp_keypair_init( &their_key ); + + expected_len = unhexify( expected_buf, expected_str ); + + if( ! load_private_key( grp_id, our_private_key, &our_key, &rnd_info ) ) + goto exit; + if( ! load_public_key( grp_id, their_point, &their_key ) ) + goto exit; + + /* Import the keys to the ECDH calculation. */ + if( ours_first ) + { + TEST_ASSERT( mbedtls_ecdh_get_params( + &ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 ); + TEST_ASSERT( mbedtls_ecdh_get_params( + &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 ); + } + else + { + TEST_ASSERT( mbedtls_ecdh_get_params( + &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 ); + TEST_ASSERT( mbedtls_ecdh_get_params( + &ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 ); + } + + /* Perform the ECDH calculation. */ + TEST_ASSERT( mbedtls_ecdh_calc_secret( + &ecdh, + &shared_secret_length, + shared_secret, sizeof( shared_secret ), + &rnd_pseudo_rand, &rnd_info ) == 0 ); + TEST_ASSERT( shared_secret_length == expected_len ); + TEST_ASSERT( memcmp( expected_buf, shared_secret, + shared_secret_length ) == 0 ); + +exit: + mbedtls_ecdh_free( &ecdh ); + mbedtls_ecp_keypair_free( &our_key ); + mbedtls_ecp_keypair_free( &their_key ); +} +/* END_CASE */ + +/* BEGIN_CASE */ +void ecdh_exchange_get_params_fail( int our_grp_id, + char *our_private_key, + int their_grp_id, + char *their_point, + int ours_first, + int expected_ret ) +{ + rnd_pseudo_info rnd_info; + mbedtls_ecp_keypair our_key; + mbedtls_ecp_keypair their_key; + mbedtls_ecdh_context ecdh; + + memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) ); + mbedtls_ecdh_init( &ecdh ); + mbedtls_ecp_keypair_init( &our_key ); + mbedtls_ecp_keypair_init( &their_key ); + + if( ! load_private_key( our_grp_id, our_private_key, &our_key, &rnd_info ) ) + goto exit; + if( ! load_public_key( their_grp_id, their_point, &their_key ) ) + goto exit; + + if( ours_first ) + { + TEST_ASSERT( mbedtls_ecdh_get_params( + &ecdh, &our_key, MBEDTLS_ECDH_OURS ) == 0 ); + TEST_ASSERT( mbedtls_ecdh_get_params( + &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == + expected_ret ); + } + else + { + TEST_ASSERT( mbedtls_ecdh_get_params( + &ecdh, &their_key, MBEDTLS_ECDH_THEIRS ) == 0 ); + TEST_ASSERT( mbedtls_ecdh_get_params( + &ecdh, &our_key, MBEDTLS_ECDH_OURS ) == + expected_ret ); + } + +exit: + mbedtls_ecdh_free( &ecdh ); + mbedtls_ecp_keypair_free( &our_key ); + mbedtls_ecp_keypair_free( &their_key ); +} +/* END_CASE */ diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_mpi.data b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_mpi.data index 296064196c..b8d7ad14ce 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_mpi.data +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_mpi.data @@ -19,6 +19,9 @@ mpi_read_write_string:16:"-20":10:"-32":100:0:0 Base test mpi_read_write_string #3 (Negative decimal) mpi_read_write_string:16:"-23":16:"-23":100:0:0 +Base test mpi_read_write_string #4 (Buffer just fits) +mpi_read_write_string:16:"-4":4:"-10":4:0:0 + Test mpi_read_write_string #1 (Invalid character) mpi_read_write_string:10:"a28":0:"":100:MBEDTLS_ERR_MPI_INVALID_CHARACTER:0 diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_mpi.function b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_mpi.function index 04dca0fcb2..aa3c332bbc 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_mpi.function +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_mpi.function @@ -81,6 +81,8 @@ void mpi_read_write_string( int radix_X, char *input_X, int radix_A, mbedtls_mpi_init( &X ); + memset( str, '!', sizeof( str ) ); + TEST_ASSERT( mbedtls_mpi_read_string( &X, radix_X, input_X ) == result_read ); if( result_read == 0 ) { @@ -88,6 +90,7 @@ void mpi_read_write_string( int radix_X, char *input_X, int radix_A, if( result_write == 0 ) { TEST_ASSERT( strcasecmp( str, input_A ) == 0 ); + TEST_ASSERT( str[len] == '!' ); } } diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_timing.data b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_timing.data index 4dddcf7fc1..2522da1eaf 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_timing.data +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_timing.data @@ -1,41 +1,17 @@ -Timing: basic timer operation -timing_timer_simple: - -Timing: timer reset -timing_timer_reset: - -Timing: two parallel timers, delay 0 -timing_two_timers:0: - -Timing: two parallel timers, delay 100 -timing_two_timers:100: - -Timing: two parallel timers, delay 1000 -timing_two_timers:1000: - -Timing: two parallel timers, delay 10000 -timing_two_timers:10000: - -Timing: delay 0ms, 0ms -timing_delay:0:0: - -Timing: delay 0ms, 50ms -timing_delay:0:50: - -Timing: delay 50ms, 50ms -timing_delay:50:50: +Timing: hardclock +timing_hardclock: -Timing: delay 50ms, 100ms -timing_delay:50:100: +Timing: get timer +timing_get_timer: -Timing: delay 50ms, 200ms -timing_delay:50:200: +Timing: set alarm with no delay +timing_set_alarm:0: -Timing: alarm in 0 second -timing_alarm:0: +Timing: set alarm with 1s delay +timing_set_alarm:1: -Timing: alarm in 1 second -timing_alarm:1: +Timing: delay 0ms +timing_delay:0: -Timing: hardclock -timing_hardclock: +Timing: delay 100ms +timing_delay:100: diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_timing.function b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_timing.function index 1610155fbf..74dc823171 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_timing.function +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_timing.function @@ -1,51 +1,14 @@ /* BEGIN_HEADER */ -/* This test module exercises the timing module. One of the expected failure - modes is for timers to never expire, which could lead to an infinite loop. - The function timing_timer_simple is protected against this failure mode and - checks that timers do expire. Other functions will terminate if their - timers do expire. Therefore it is recommended to run timing_timer_simple - first and run other test functions only if that timing_timer_simple - succeeded. */ +/* This test module exercises the timing module. Since, depending on the + * underlying operating system, the timing routines are not always reliable, + * this suite only performs very basic sanity checks of the timing API. + */ #include #include "mbedtls/timing.h" -/* Wait this many milliseconds for a short timing test. This duration - should be large enough that, in practice, if you read the timer - value twice in a row, it won't have jumped by that much. */ -#define TIMING_SHORT_TEST_MS 100 - -/* A loop that waits TIMING_SHORT_TEST_MS must not take more than this many - iterations. This value needs to be large enough to accommodate fast - platforms (e.g. at 4GHz and 10 cycles/iteration a CPU can run through 20 - million iterations in 50ms). The only motivation to keep this value low is - to avoid having an infinite loop if the timer functions are not implemented - correctly. Ideally this value should be based on the processor speed but we - don't have this information! */ -#define TIMING_SHORT_TEST_ITERATIONS_MAX 1e8 - -/* alarm(0) must fire in no longer than this amount of time. */ -#define TIMING_ALARM_0_DELAY_MS TIMING_SHORT_TEST_MS - -static int expected_delay_status( uint32_t int_ms, uint32_t fin_ms, - unsigned long actual_ms ) -{ - return( fin_ms == 0 ? -1 : - actual_ms >= fin_ms ? 2 : - actual_ms >= int_ms ? 1 : - 0 ); -} - -/* Some conditions in timing_timer_simple suggest that timers are unreliable. - Most other test cases rely on timers to terminate, and could loop - indefinitely if timers are too broken. So if timing_timer_simple detected a - timer that risks not terminating (going backwards, or not reaching the - desired count in the alloted clock cycles), set this flag to immediately - fail those other tests without running any timers. */ -static int timers_are_badly_broken = 0; - /* END_HEADER */ /* BEGIN_DEPENDENCIES @@ -54,350 +17,58 @@ static int timers_are_badly_broken = 0; */ /* BEGIN_CASE */ -void timing_timer_simple( ) +void timing_hardclock( ) { - struct mbedtls_timing_hr_time timer; - unsigned long millis = 0; - unsigned long new_millis = 0; - unsigned long iterations = 0; - /* Start the timer. */ - (void) mbedtls_timing_get_timer( &timer, 1 ); - /* Busy-wait loop for a few milliseconds. */ - do - { - new_millis = mbedtls_timing_get_timer( &timer, 0 ); - ++iterations; - /* Check that the timer didn't go backwards */ - TEST_ASSERT( new_millis >= millis ); - millis = new_millis; - } - while( millis < TIMING_SHORT_TEST_MS && - iterations <= TIMING_SHORT_TEST_ITERATIONS_MAX ); - /* The wait duration should have been large enough for at least a - few runs through the loop, even on the slowest realistic platform. */ - TEST_ASSERT( iterations >= 2 ); - /* The wait duration shouldn't have overflowed the iteration count. */ - TEST_ASSERT( iterations < TIMING_SHORT_TEST_ITERATIONS_MAX ); - return; - -exit: - if( iterations >= TIMING_SHORT_TEST_ITERATIONS_MAX || - new_millis < millis ) - { - /* The timer was very unreliable: it didn't increment and the loop ran - out, or it went backwards. Other tests that use timers might go - into an infinite loop, so we'll skip them. */ - timers_are_badly_broken = 1; - } - - /* No cleanup needed, but show some diagnostic iterations, because timing - problems can be hard to reproduce. */ - mbedtls_fprintf( stdout, " Finished with millis=%lu new_millis=%lu get(timer)<=%lu iterations=%lu\n", - millis, new_millis, mbedtls_timing_get_timer( &timer, 0 ), - iterations ); + (void) mbedtls_timing_hardclock(); + /* This goto is added to avoid warnings from the generated code. */ + goto exit; } /* END_CASE */ /* BEGIN_CASE */ -void timing_timer_reset( ) +void timing_get_timer( ) { - struct mbedtls_timing_hr_time timer; - unsigned long millis = 0; - unsigned long iterations = 0; - - /* Skip this test if it looks like timers don't work at all, to avoid an - infinite loop below. */ - TEST_ASSERT( !timers_are_badly_broken ); - - /* Start the timer. Timers are always reset to 0. */ - TEST_ASSERT( mbedtls_timing_get_timer( &timer, 1 ) == 0 ); - /* Busy-wait loop for a few milliseconds */ - do - { - ++iterations; - millis = mbedtls_timing_get_timer( &timer, 0 ); - } - while( millis < TIMING_SHORT_TEST_MS ); - - /* Reset the timer and check that it has restarted. */ - TEST_ASSERT( mbedtls_timing_get_timer( &timer, 1 ) == 0 ); - /* Read the timer immediately after reset. It should be 0 or close - to it. */ - TEST_ASSERT( mbedtls_timing_get_timer( &timer, 0 ) < TIMING_SHORT_TEST_MS ); - return; - -exit: - /* No cleanup needed, but show some diagnostic information, because timing - problems can be hard to reproduce. */ - if( !timers_are_badly_broken ) - mbedtls_fprintf( stdout, " Finished with millis=%lu get(timer)<=%lu iterations=%lu\n", - millis, mbedtls_timing_get_timer( &timer, 0 ), - iterations ); + struct mbedtls_timing_hr_time time; + (void) mbedtls_timing_get_timer( &time, 1 ); + (void) mbedtls_timing_get_timer( &time, 0 ); + /* This goto is added to avoid warnings from the generated code. */ + goto exit; } /* END_CASE */ /* BEGIN_CASE */ -void timing_two_timers( int delta ) +void timing_set_alarm( int seconds ) { - struct mbedtls_timing_hr_time timer1, timer2; - unsigned long millis1 = 0, millis2 = 0; - - /* Skip this test if it looks like timers don't work at all, to avoid an - infinite loop below. */ - TEST_ASSERT( !timers_are_badly_broken ); - - /* Start the first timer and wait for a short time. */ - (void) mbedtls_timing_get_timer( &timer1, 1 ); - do - { - millis1 = mbedtls_timing_get_timer( &timer1, 0 ); - } - while( millis1 < TIMING_SHORT_TEST_MS ); - - /* Do a short busy-wait, so that the difference between timer1 and timer2 - doesn't practically always end up being very close to a whole number of - milliseconds. */ - while( delta > 0 ) - --delta; - - /* Start the second timer and compare it with the first. */ - mbedtls_timing_get_timer( &timer2, 1 ); - do + if( seconds == 0 ) { - millis1 = mbedtls_timing_get_timer( &timer1, 0 ); - millis2 = mbedtls_timing_get_timer( &timer2, 0 ); - /* The first timer should always be ahead of the first. */ - TEST_ASSERT( millis1 > millis2 ); - /* The timers shouldn't drift apart, i.e. millis2-millis1 should stay - roughly constant, but this is hard to test reliably, especially in - a busy environment such as an overloaded continuous integration - system, so we don't test it it. */ + mbedtls_set_alarm( seconds ); + TEST_ASSERT( mbedtls_timing_alarmed == 1 ); } - while( millis2 < TIMING_SHORT_TEST_MS ); - - return; - -exit: - /* No cleanup needed, but show some diagnostic iterations, because timing - problems can be hard to reproduce. */ - if( !timers_are_badly_broken ) - mbedtls_fprintf( stdout, " Finished with millis1=%lu get(timer1)<=%lu millis2=%lu get(timer2)<=%lu\n", - millis1, mbedtls_timing_get_timer( &timer1, 0 ), - millis2, mbedtls_timing_get_timer( &timer2, 0 ) ); -} -/* END_CASE */ - -/* BEGIN_CASE */ -void timing_alarm( int seconds ) -{ - struct mbedtls_timing_hr_time timer; - unsigned long millis = 0; - /* We check that about the desired number of seconds has elapsed. Be - slightly liberal with the lower bound, so as to allow platforms where - the alarm (with second resolution) and the timer (with millisecond - resolution) are based on different clocks. Be very liberal with the - upper bound, because the platform might be busy. */ - unsigned long millis_min = ( seconds > 0 ? - seconds * 900 : - 0 ); - unsigned long millis_max = ( seconds > 0 ? - seconds * 1100 + 400 : - TIMING_ALARM_0_DELAY_MS ); - unsigned long iterations = 0; - - /* Skip this test if it looks like timers don't work at all, to avoid an - infinite loop below. */ - TEST_ASSERT( !timers_are_badly_broken ); - - /* Set an alarm and count how long it takes with a timer. */ - (void) mbedtls_timing_get_timer( &timer, 1 ); - mbedtls_set_alarm( seconds ); - - if( seconds > 0 ) - { - /* We set the alarm for at least 1 second. It should not have fired - immediately, even on a slow and busy platform. */ - TEST_ASSERT( !mbedtls_timing_alarmed ); - } - /* A 0-second alarm should fire quickly, but we don't guarantee that it - fires immediately, so mbedtls_timing_alarmed may or may not be set at - this point. */ - - /* Busy-wait until the alarm rings */ - do + else { - ++iterations; - millis = mbedtls_timing_get_timer( &timer, 0 ); + mbedtls_set_alarm( seconds ); + TEST_ASSERT( mbedtls_timing_alarmed == 0 || + mbedtls_timing_alarmed == 1 ); } - while( !mbedtls_timing_alarmed && millis <= millis_max ); - - TEST_ASSERT( mbedtls_timing_alarmed ); - TEST_ASSERT( millis >= millis_min ); - TEST_ASSERT( millis <= millis_max ); - - mbedtls_timing_alarmed = 0; - return; - -exit: - /* Show some diagnostic iterations, because timing - problems can be hard to reproduce. */ - if( !timers_are_badly_broken ) - mbedtls_fprintf( stdout, " Finished with alarmed=%d millis=%lu get(timer)<=%lu iterations=%lu\n", - mbedtls_timing_alarmed, - millis, mbedtls_timing_get_timer( &timer, 0 ), - iterations ); - /* Cleanup */ - mbedtls_timing_alarmed = 0; } /* END_CASE */ /* BEGIN_CASE */ -void timing_delay( int int_ms, int fin_ms ) +void timing_delay( int fin_ms ) { - /* This function assumes that if int_ms is nonzero then it is large - enough that we have time to read all timers at least once in an - interval of time lasting int_ms milliseconds, and likewise for (fin_ms - - int_ms). So don't call it with arguments that are too small. */ - - mbedtls_timing_delay_context delay; - struct mbedtls_timing_hr_time timer; - unsigned long delta = 0; /* delay started between timer=0 and timer=delta */ - unsigned long before = 0, after = 0; - unsigned long iterations = 0; - int status = -2; - int saw_status_1 = 0; - int warn_inconclusive = 0; - - assert( int_ms >= 0 ); - assert( fin_ms >= 0 ); - - /* Skip this test if it looks like timers don't work at all, to avoid an - infinite loop below. */ - TEST_ASSERT( !timers_are_badly_broken ); - - /* Start a reference timer. Program a delay, and verify that the status of - the delay is consistent with the time given by the reference timer. */ - (void) mbedtls_timing_get_timer( &timer, 1 ); - mbedtls_timing_set_delay( &delay, int_ms, fin_ms ); - /* Set delta to an upper bound for the interval between the start of timer - and the start of delay. Reading timer after starting delay gives us an - upper bound for the interval, rounded to a 1ms precision. Since this - might have been rounded down, but we need an upper bound, we add 1. */ - delta = mbedtls_timing_get_timer( &timer, 0 ) + 1; - - status = mbedtls_timing_get_delay( &delay ); + mbedtls_timing_delay_context ctx; + int result; if( fin_ms == 0 ) { - /* Cancelled timer. Just check the correct status for this case. */ - TEST_ASSERT( status == -1 ); - return; - } - - /* Initially, none of the delays must be passed yet if they're nonzero. - This could fail for very small values of int_ms and fin_ms, where "very - small" depends how fast and how busy the platform is. */ - if( int_ms > 0 ) - { - TEST_ASSERT( status == 0 ); + mbedtls_timing_set_delay( &ctx, 0, 0 ); + result = mbedtls_timing_get_delay( &ctx ); + TEST_ASSERT( result == -1 ); } else { - TEST_ASSERT( status == 1 ); + mbedtls_timing_set_delay( &ctx, fin_ms / 2, fin_ms ); + result = mbedtls_timing_get_delay( &ctx ); + TEST_ASSERT( result >= 0 && result <= 2 ); } - - do - { - unsigned long delay_min, delay_max; - int status_min, status_max; - ++iterations; - before = mbedtls_timing_get_timer( &timer, 0 ); - status = mbedtls_timing_get_delay( &delay ); - after = mbedtls_timing_get_timer( &timer, 0 ); - /* At a time between before and after, the delay's status was status. - Check that this is consistent given that the delay was started - between times 0 and delta. */ - delay_min = ( before > delta ? before - delta : 0 ); - status_min = expected_delay_status( int_ms, fin_ms, delay_min ); - delay_max = after; - status_max = expected_delay_status( int_ms, fin_ms, delay_max ); - TEST_ASSERT( status >= status_min ); - TEST_ASSERT( status <= status_max ); - if( status == 1 ) - saw_status_1 = 1; - } - while ( before <= fin_ms + delta && status != 2 ); - - /* Since we've waited at least fin_ms, the delay must have fully - expired. */ - TEST_ASSERT( status == 2 ); - - /* If the second delay is more than the first, then there must have been a - point in time when the first delay was passed but not the second delay. - This could fail for very small values of (fin_ms - int_ms), where "very - small" depends how fast and how busy the platform is. In practice, this - is the test that's most likely to fail on a heavily loaded machine. */ - if( fin_ms > int_ms ) - { - warn_inconclusive = 1; - TEST_ASSERT( saw_status_1 ); - } - - return; - -exit: - /* No cleanup needed, but show some diagnostic iterations, because timing - problems can be hard to reproduce. */ - if( !timers_are_badly_broken ) - mbedtls_fprintf( stdout, " Finished with delta=%lu before=%lu after=%lu status=%d iterations=%lu\n", - delta, before, after, status, iterations ); - if( warn_inconclusive ) - mbedtls_fprintf( stdout, " Inconclusive test, try running it on a less heavily loaded machine.\n" ); - } -/* END_CASE */ - -/* BEGIN_CASE */ -void timing_hardclock( ) -{ - /* We make very few guarantees about mbedtls_timing_hardclock: its rate is - platform-dependent, it can wrap around. So there isn't much we can - test. But we do at least test that it doesn't crash, stall or return - completely nonsensical values. */ - - struct mbedtls_timing_hr_time timer; - unsigned long hardclock0 = -1, hardclock1 = -1, delta1 = -1; - - /* Skip this test if it looks like timers don't work at all, to avoid an - infinite loop below. */ - TEST_ASSERT( !timers_are_badly_broken ); - - hardclock0 = mbedtls_timing_hardclock( ); - /* Wait 2ms to ensure a nonzero delay. Since the timer interface has 1ms - resolution and unspecified precision, waiting 1ms might be a very small - delay that's rounded up. */ - (void) mbedtls_timing_get_timer( &timer, 1 ); - while( mbedtls_timing_get_timer( &timer, 0 ) < 2 ) - /*busy-wait loop*/; - hardclock1 = mbedtls_timing_hardclock( ); - - /* Although the hardclock counter can wrap around, the difference - (hardclock1 - hardclock0) is taken modulo the type size, so it is - correct as long as the counter only wrapped around at most once. We - further require the difference to be nonzero (after a wait of more than - 1ms, the counter must have changed), and not to be overly large (after - a wait of less than 3ms, plus time lost because other processes were - scheduled on the CPU). If the hardclock counter runs at 4GHz, then - 1000000000 (which is 1/4 of the counter wraparound on a 32-bit machine) - allows 250ms. */ - delta1 = hardclock1 - hardclock0; - TEST_ASSERT( delta1 > 0 ); - TEST_ASSERT( delta1 < 1000000000 ); - return; - -exit: - /* No cleanup needed, but show some diagnostic iterations, because timing - problems can be hard to reproduce. */ - if( !timers_are_badly_broken ) - mbedtls_fprintf( stdout, " Finished with hardclock=%lu,%lu\n", - hardclock0, hardclock1 ); } /* END_CASE */ diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_version.data b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_version.data index eafceb3e84..1aa9c5333a 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_version.data +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_version.data @@ -1,8 +1,8 @@ Check compiletime library version -check_compiletime_version:"2.7.9" +check_compiletime_version:"2.7.11" Check runtime library version -check_runtime_version:"2.7.9" +check_runtime_version:"2.7.11" Check for MBEDTLS_VERSION_C check_feature:"MBEDTLS_VERSION_C":0 diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509parse.data b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509parse.data index 19a8af31c4..0fe68cb06f 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509parse.data +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509parse.data @@ -12,15 +12,15 @@ x509_cert_info:"data_files/test-ca.crt":"cert. version \: 3\nserial number X509 Certificate information MD2 Digest depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509_cert_info:"data_files/cert_md2.crt":"cert. version \: 3\nserial number \: 09\nissuer name \: C=NL, O=PolarSSL, CN=PolarSSL Test CA\nsubject name \: C=NL, O=PolarSSL, CN=PolarSSL Cert MD2\nissued on \: 2009-07-12 10\:56\:59\nexpires on \: 2011-07-12 10\:56\:59\nsigned using \: RSA with MD2\nRSA key size \: 2048 bits\nbasic constraints \: CA=false\n" +x509_cert_info:"data_files/cert_md2.crt":"cert. version \: 3\nserial number \: 09\nissuer name \: C=NL, O=PolarSSL, CN=PolarSSL Test CA\nsubject name \: C=NL, O=PolarSSL, CN=PolarSSL Cert MD2\nissued on \: 2000-01-01 12\:12\:12\nexpires on \: 2030-01-01 12\:12\:12\nsigned using \: RSA with MD2\nRSA key size \: 2048 bits\nbasic constraints \: CA=false\n" X509 Certificate information MD4 Digest depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_MD4_C -x509_cert_info:"data_files/cert_md4.crt":"cert. version \: 3\nserial number \: 05\nissuer name \: C=NL, O=PolarSSL, CN=PolarSSL Test CA\nsubject name \: C=NL, O=PolarSSL, CN=PolarSSL Cert MD4\nissued on \: 2011-02-12 14\:44\:07\nexpires on \: 2021-02-12 14\:44\:07\nsigned using \: RSA with MD4\nRSA key size \: 2048 bits\nbasic constraints \: CA=false\n" +x509_cert_info:"data_files/cert_md4.crt":"cert. version \: 3\nserial number \: 05\nissuer name \: C=NL, O=PolarSSL, CN=PolarSSL Test CA\nsubject name \: C=NL, O=PolarSSL, CN=PolarSSL Cert MD4\nissued on \: 2000-01-01 12\:12\:12\nexpires on \: 2030-01-01 12\:12\:12\nsigned using \: RSA with MD4\nRSA key size \: 2048 bits\nbasic constraints \: CA=false\n" X509 Certificate information MD5 Digest depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_MD5_C -x509_cert_info:"data_files/cert_md5.crt":"cert. version \: 3\nserial number \: 06\nissuer name \: C=NL, O=PolarSSL, CN=PolarSSL Test CA\nsubject name \: C=NL, O=PolarSSL, CN=PolarSSL Cert MD5\nissued on \: 2011-02-12 14\:44\:07\nexpires on \: 2021-02-12 14\:44\:07\nsigned using \: RSA with MD5\nRSA key size \: 2048 bits\nbasic constraints \: CA=false\n" +x509_cert_info:"data_files/cert_md5.crt":"cert. version \: 3\nserial number \: 06\nissuer name \: C=NL, O=PolarSSL, CN=PolarSSL Test CA\nsubject name \: C=NL, O=PolarSSL, CN=PolarSSL Cert MD5\nissued on \: 2000-01-01 12\:12\:12\nexpires on \: 2030-01-01 12\:12\:12\nsigned using \: RSA with MD5\nRSA key size \: 2048 bits\nbasic constraints \: CA=false\n" X509 Certificate information SHA1 Digest depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_SHA1_C @@ -226,7 +226,7 @@ X509 CSR Information RSA with SHA224 depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA256_C:MBEDTLS_RSA_C mbedtls_x509_csr_info:"data_files/server1.req.sha224":"CSR version \: 1\nsubject name \: C=NL, O=PolarSSL, CN=PolarSSL Server 1\nsigned using \: RSA with SHA-224\nRSA key size \: 2048 bits\n" -X509 CSR Information RSA with SHA256 +X509 CSR Information RSA with SHA-256 depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA256_C:MBEDTLS_RSA_C mbedtls_x509_csr_info:"data_files/server1.req.sha256":"CSR version \: 1\nsubject name \: C=NL, O=PolarSSL, CN=PolarSSL Server 1\nsigned using \: RSA with SHA-256\nRSA key size \: 2048 bits\n" @@ -278,6 +278,10 @@ X509 CSR Information RSA-PSS with SHA512 depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_X509_RSASSA_PSS_SUPPORT:MBEDTLS_SHA512_C mbedtls_x509_csr_info:"data_files/server9.req.sha512":"CSR version \: 1\nsubject name \: C=NL, O=PolarSSL, CN=localhost\nsigned using \: RSASSA-PSS (SHA512, MGF1-SHA512, 0x3E)\nRSA key size \: 1024 bits\n" +X509 CSR Information RSA with SHA-256 - Microsoft header +depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA256_C:MBEDTLS_RSA_C +mbedtls_x509_csr_info:"data_files/server1-ms.req.sha256":"CSR version \: 1\nsubject name \: C=NL, O=PolarSSL, CN=PolarSSL Server 1\nsigned using \: RSA with SHA-256\nRSA key size \: 2048 bits\n" + X509 Verify Information: empty x509_verify_info:0:"":"" @@ -447,14 +451,30 @@ X509 Certificate verification #10 (Not trusted Cert, Expired CRL) depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15:MBEDTLS_SHA1_C x509_verify:"data_files/server2.crt":"data_files/server1.crt":"data_files/crl_expired.pem":"NULL":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCERT_NOT_TRUSTED:"compat":"NULL" -X509 Certificate verification #12 (Valid Cert MD4 Digest) +X509 Certificate verification #12 (Valid Cert MD2 Digest, MD2 forbidden) +depends_on:MBEDTLS_MD2_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 +x509_verify:"data_files/cert_md2.crt":"data_files/test-ca.crt":"data_files/crl.pem":"NULL":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCERT_BAD_MD:"compat":"NULL" + +X509 Certificate verification #12 (Valid Cert MD4 Digest, MD4 forbidden) depends_on:MBEDTLS_MD4_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 x509_verify:"data_files/cert_md4.crt":"data_files/test-ca.crt":"data_files/crl.pem":"NULL":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCERT_BAD_MD:"compat":"NULL" -X509 Certificate verification #13 (Valid Cert MD5 Digest) +X509 Certificate verification #13 (Valid Cert MD5 Digest, MD5 forbidden) depends_on:MBEDTLS_MD5_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 x509_verify:"data_files/cert_md5.crt":"data_files/test-ca.crt":"data_files/crl.pem":"NULL":MBEDTLS_ERR_X509_CERT_VERIFY_FAILED:MBEDTLS_X509_BADCERT_BAD_MD:"compat":"NULL" +X509 Certificate verification #12 (Valid Cert MD2 Digest, MD2 allowed) +depends_on:MBEDTLS_MD2_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 +x509_verify:"data_files/cert_md2.crt":"data_files/test-ca.crt":"data_files/crl.pem":"NULL":0:0:"all":"NULL" + +X509 Certificate verification #12 (Valid Cert MD4 Digest, MD4 allowed) +depends_on:MBEDTLS_MD4_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 +x509_verify:"data_files/cert_md4.crt":"data_files/test-ca.crt":"data_files/crl.pem":"NULL":0:0:"all":"NULL" + +X509 Certificate verification #13 (Valid Cert MD5 Digest, MD5 allowed) +depends_on:MBEDTLS_MD5_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 +x509_verify:"data_files/cert_md5.crt":"data_files/test-ca.crt":"data_files/crl.pem":"NULL":0:0:"all":"NULL" + X509 Certificate verification #14 (Valid Cert SHA1 Digest explicitly allowed in profile) depends_on:MBEDTLS_SHA1_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 x509_verify:"data_files/cert_sha1.crt":"data_files/test-ca.crt":"data_files/crl.pem":"NULL":0:0:"compat":"NULL" @@ -972,171 +992,171 @@ X509 Certificate ASN1 (TBSCertificate, correct alg, unknown alg_id) x509parse_crt:"30173015a0030201028204deadbeef30080604cafed00d0500":"":MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG + MBEDTLS_ERR_OID_NOT_FOUND X509 Certificate ASN1 (TBSCertificate, correct alg, specific alg_id) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"301c301aa0030201028204deadbeef300d06092a864886f70d0101020500":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"301c301aa0030201028204deadbeef300d06092a864886f70d01010b0500":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, correct alg, unknown specific alg_id) x509parse_crt:"301c301aa0030201028204deadbeef300d06092a864886f70d0101010500":"":MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG + MBEDTLS_ERR_OID_NOT_FOUND X509 Certificate ASN1 (TBSCertificate, correct alg, bad RSASSA-PSS params) depends_on:MBEDTLS_X509_RSASSA_PSS_SUPPORT -x509parse_crt:"30193017A003020102020118300D06092A864886F70D01010A3100":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +x509parse_crt:"30193017a003020102020118300d06092a864886f70d01010a3100":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 Certificate ASN1 (TBSCertificate, issuer no set data) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"301e301ca0030201028204deadbeef300d06092a864886f70d01010205003000":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"301e301ca0030201028204deadbeef300d06092a864886f70d01010b05003000":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, issuer no inner seq data) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"3020301ea0030201028204deadbeef300d06092a864886f70d010102050030023100":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"3020301ea0030201028204deadbeef300d06092a864886f70d01010b050030023100":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, issuer no inner set data) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30223020a0030201028204deadbeef300d06092a864886f70d0101020500300431023000":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30223020a0030201028204deadbeef300d06092a864886f70d01010b0500300431023000":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, issuer two inner set datas) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30243022a0030201028204deadbeef300d06092a864886f70d01010205003006310430003000":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30243022a0030201028204deadbeef300d06092a864886f70d01010b05003006310430003000":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, issuer no oid data) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30243022a0030201028204deadbeef300d06092a864886f70d01010205003006310430020600":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30243022a0030201028204deadbeef300d06092a864886f70d01010b05003006310430020600":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, issuer invalid tag) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"302a3028a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600060454657374":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"302a3028a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600060454657374":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 Certificate ASN1 (TBSCertificate, issuer, no string data) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30253023a0030201028204deadbeef300d06092a864886f70d0101020500300731053003060013":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30253023a0030201028204deadbeef300d06092a864886f70d01010b0500300731053003060013":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, issuer, no full following string) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"302b3029a0030201028204deadbeef300d06092a864886f70d0101020500300d310b3009060013045465737400":"":MBEDTLS_ERR_X509_INVALID_NAME+MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"302b3029a0030201028204deadbeef300d06092a864886f70d01010b0500300d310b3009060013045465737400":"":MBEDTLS_ERR_X509_INVALID_NAME+MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 Certificate ASN1 (TBSCertificate, valid issuer, no validity) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"302a3028a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374":"":MBEDTLS_ERR_X509_INVALID_DATE + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"302a3028a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374":"":MBEDTLS_ERR_X509_INVALID_DATE + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, too much date data) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30493047a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301d170c303930313031303030303030170c30393132333132333539353900":"":MBEDTLS_ERR_X509_INVALID_DATE + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30493047a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301d170c303930313031303030303030170c30393132333132333539353900":"":MBEDTLS_ERR_X509_INVALID_DATE + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 Certificate ASN1 (TBSCertificate, invalid from date) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30483046a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303000000000170c303931323331323300000000":"":MBEDTLS_ERR_X509_INVALID_DATE +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30483046a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303000000000170c303931323331323300000000":"":MBEDTLS_ERR_X509_INVALID_DATE X509 Certificate ASN1 (TBSCertificate, invalid to date) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30483046a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323300000000":"":MBEDTLS_ERR_X509_INVALID_DATE +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30483046a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323300000000":"":MBEDTLS_ERR_X509_INVALID_DATE X509 Certificate ASN1 (TBSCertificate, valid validity, no subject) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30493047a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c30393132333132333539353930":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30493047a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c30393132333132333539353930":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, valid subject, no pubkeyinfo) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30563054a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374":"":MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30563054a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374":"":MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, pubkey, no alg) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30583056a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a300806001304546573743000":"":MBEDTLS_ERR_PK_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30583056a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a300806001304546573743000":"":MBEDTLS_ERR_PK_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, valid subject, unknown pk alg) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30673065a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374300f300d06092A864886F70D0101000500":"":MBEDTLS_ERR_PK_UNKNOWN_PK_ALG +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30673065a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374300f300d06092a864886f70d0101000500":"":MBEDTLS_ERR_PK_UNKNOWN_PK_ALG X509 Certificate ASN1 (TBSCertificate, pubkey, no bitstring) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30673065a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374300f300d06092A864886F70D0101010500":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30673065a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374300f300d06092a864886f70d0101010500":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate, pubkey, no bitstring data) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30693067a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a300806001304546573743011300d06092A864886F70D01010105000300":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_INVALID_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30693067a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a300806001304546573743011300d06092a864886f70d01010105000300":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_INVALID_DATA X509 Certificate ASN1 (TBSCertificate, pubkey, invalid bitstring start) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"306a3068a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a300806001304546573743012300d06092A864886F70D0101010500030101":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_INVALID_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"306a3068a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a300806001304546573743012300d06092a864886f70d0101010500030101":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_INVALID_DATA X509 Certificate ASN1 (TBSCertificate, pubkey, invalid internal bitstring length) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"306d306ba0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a300806001304546573743015300d06092A864886F70D0101010500030400300000":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"306d306ba0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a300806001304546573743015300d06092a864886f70d0101010500030400300000":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 Certificate ASN1 (TBSCertificate, pubkey, invalid internal bitstring tag) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"306d306ba0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a300806001304546573743015300d06092A864886F70D0101010500030400310000":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"306d306ba0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a300806001304546573743015300d06092a864886f70d0101010500030400310000":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 Certificate ASN1 (TBSCertificate, pubkey, invalid mbedtls_mpi) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30743072a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374301c300d06092A864886F70D0101010500030b0030080202ffff0302ffff":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30743072a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374301c300d06092a864886f70d0101010500030b0030080202ffff0302ffff":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 Certificate ASN1 (TBSCertificate, pubkey, total length mismatch) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30753073a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374301d300d06092A864886F70D0101010500030b0030080202ffff0202ffff00":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30753073a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374301d300d06092a864886f70d0101010500030b0030080202ffff0202ffff00":"":MBEDTLS_ERR_PK_INVALID_PUBKEY + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 Certificate ASN1 (TBSCertificate, pubkey, check failed) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30743072a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374301c300d06092A864886F70D0101010500030b0030080202ffff0202ffff":"":MBEDTLS_ERR_PK_INVALID_PUBKEY +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30743072a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374301c300d06092a864886f70d0101010500030b0030080202ffff0202ffff":"":MBEDTLS_ERR_PK_INVALID_PUBKEY X509 Certificate ASN1 (TBSCertificate, pubkey, check failed, expanded length notation) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308183308180a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210fffffffffffffffffffffffffffffffe0202ffff":"":MBEDTLS_ERR_PK_INVALID_PUBKEY +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308183308180a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210fffffffffffffffffffffffffffffffe0202ffff":"":MBEDTLS_ERR_PK_INVALID_PUBKEY X509 Certificate ASN1 (TBSCertificate v3, Optional UIDs, Extensions not present) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308183308180a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308183308180a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate v3, issuerID wrong tag) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308184308181a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff00":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308184308181a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff00":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 Certificate ASN1 (TBSCertificate v3, UIDs, no ext) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308189308186a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bb":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308189308186a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bb":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate v3, UIDs, invalid length) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308189308186a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa185aaa201bb":"":MBEDTLS_ERR_ASN1_INVALID_LENGTH +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308189308186a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa185aaa201bb":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_INVALID_LENGTH X509 Certificate ASN1 (TBSCertificate v3, ext empty) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30818b308188a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba300":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30818b308188a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba300":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate v3, ext length mismatch) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30818e30818ba0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba303300000":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30818e30818ba0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba303300000":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 Certificate ASN1 (TBSCertificate v3, first ext invalid) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30818f30818ca0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba30330023000":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30818f30818ca0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba30330023000":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate v3, first ext invalid tag) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30819030818da0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba3043002310000":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30819030818da0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba3043002310000":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 Certificate ASN1 (TBSCertificate v3, ext BasicContraint tag, bool len missing) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308198308195a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba30c300a30060603551d1301010100":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308198308195a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba30c300a30060603551d1301010100":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate v3, ext BasicContraint tag, data missing) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308198308195a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba30c300a30080603551d1301010100":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308198308195a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba30c300a30080603551d1301010100":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate v3, ext BasicContraint tag, no octet present) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308198308195a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba30d300b30090603551d1301010100":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308198308195a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba30d300b30090603551d1301010100":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 Certificate ASN1 (TBSCertificate v3, ext BasicContraint tag, octet data missing) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30819c308199a0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba311300f300d0603551d130101010403300100":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30819c308199a0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba311300f300d0603551d130101010403300100":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 Certificate ASN1 (TBSCertificate v3, ext BasicContraint tag, no pathlen) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30819f30819ca0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba314301230100603551d130101010406300402010102":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30819f30819ca0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba314301230100603551d130101010406300402010102":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (TBSCertificate v3, ext BasicContraint tag, octet len mismatch) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"3081a230819fa0030201028204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba317301530130603551d130101010409300702010102010100":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"3081a230819fa0030201028204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffffa101aaa201bba317301530130603551d130101010409300702010102010100":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 Certificate ASN1 (ExtKeyUsage, bad second tag) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA1_C @@ -1144,101 +1164,101 @@ x509parse_crt:"3081de3081dba003020102020900ebdbcd14105e1839300906072a8648ce3d040 X509 Certificate ASN1 (SubjectAltName repeated) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA1_C -x509parse_crt:"3081fd3081faa003020102020900a8b31ff37d09a37f300906072a8648ce3d0401300f310d300b0603550403130454657374301e170d3134313131313231333731365a170d3234313130383231333731365a300f310d300b06035504031304546573743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa321301f301d0603551d11041630148208666f6f2e7465737482086261722e74657374301d0603551d11041630148208666f6f2e7465737482086261722e74657374":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS +x509parse_crt:"3081fd3081faa003020102020900a8b31ff37d09a37f300906072a8648ce3d0401300f310d300b0603550403130454657374301e170d3134313131313231333731365a170d3234313130383231333731365a300f310d300b06035504031304546573743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa340303e301d0603551d11041630148208666f6f2e7465737482086261722e74657374301d0603551d11041630148208666f6f2e7465737482086261722e74657374":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS X509 Certificate ASN1 (ExtKeyUsage repeated) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA1_C x509parse_crt:"3081fd3081faa003020102020900ebdbcd14105e1839300906072a8648ce3d0401300f310d300b0603550403130454657374301e170d3134313131313230353935345a170d3234313130383230353935345a300f310d300b06035504031304546573743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa340303e301d0603551d250416301406082b0601050507030106082b06010505070302301d0603551d250416301406082b0601050507030106082b06010505070302":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS X509 Certificate ASN1 (correct pubkey, no sig_alg) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308183308180a0030201008204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308183308180a0030201008204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (sig_alg mismatch) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308192308180a0030201008204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0102020500":"":MBEDTLS_ERR_X509_SIG_MISMATCH +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308192308180a0030201008204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0102020500":"":MBEDTLS_ERR_X509_SIG_MISMATCH X509 Certificate ASN1 (sig_alg, no sig) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308192308180a0030201008204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500":"":MBEDTLS_ERR_X509_INVALID_SIGNATURE + MBEDTLS_ERR_ASN1_OUT_OF_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308192308180a0030201008204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500":"":MBEDTLS_ERR_X509_INVALID_SIGNATURE + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 Certificate ASN1 (signature, invalid sig data) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308195308180a0030201008204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030100":"":MBEDTLS_ERR_X509_INVALID_SIGNATURE + MBEDTLS_ERR_ASN1_INVALID_DATA +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308195308180a0030201008204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030100":"":MBEDTLS_ERR_X509_INVALID_SIGNATURE + MBEDTLS_ERR_ASN1_INVALID_DATA X509 Certificate ASN1 (signature, data left) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308197308180a0030201008204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff00":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308197308180a0030201008204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff00":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH -X509 Certificate ASN1 (correct) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308196308180a0030201008204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: ?\?=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with MD2\nRSA key size \: 128 bits\n":0 +X509 Certificate ASN1 (well-formed) +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308196308180a0030201008204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: ?\?=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 128 bits\n":0 X509 Certificate ASN1 (GeneralizedTime instead of UTCTime) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308198308182a0030201008204deadbeef300d06092a864886f70d0101020500300c310a30080600130454657374301e180e3230313030313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: ?\?=Test\nsubject name \: ?\?=Test\nissued on \: 2010-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with MD2\nRSA key size \: 128 bits\n":0 +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308198308182a0030201008204deadbeef300d06092a864886f70d01010b0500300c310a30080600130454657374301e180e3230313030313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: ?\?=Test\nsubject name \: ?\?=Test\nissued on \: 2010-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 128 bits\n":0 X509 Certificate ASN1 (Name with X520 CN) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d0101020500300f310d300b0603550403130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: CN=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with MD2\nRSA key size \: 128 bits\n":0 +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d01010b0500300f310d300b0603550403130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: CN=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 128 bits\n":0 X509 Certificate ASN1 (Name with X520 C) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d0101020500300f310d300b0603550406130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: C=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with MD2\nRSA key size \: 128 bits\n":0 +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d01010b0500300f310d300b0603550406130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: C=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 128 bits\n":0 X509 Certificate ASN1 (Name with X520 L) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d0101020500300f310d300b0603550407130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: L=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with MD2\nRSA key size \: 128 bits\n":0 +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d01010b0500300f310d300b0603550407130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: L=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 128 bits\n":0 X509 Certificate ASN1 (Name with X520 ST) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d0101020500300f310d300b0603550408130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: ST=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with MD2\nRSA key size \: 128 bits\n":0 +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d01010b0500300f310d300b0603550408130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: ST=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 128 bits\n":0 X509 Certificate ASN1 (Name with X520 O) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d0101020500300f310d300b060355040a130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: O=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with MD2\nRSA key size \: 128 bits\n":0 +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d01010b0500300f310d300b060355040a130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: O=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 128 bits\n":0 X509 Certificate ASN1 (Name with X520 OU) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d0101020500300f310d300b060355040b130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: OU=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with MD2\nRSA key size \: 128 bits\n":0 +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d01010b0500300f310d300b060355040b130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: OU=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 128 bits\n":0 X509 Certificate ASN1 (Name with unknown X520 part) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d0101020500300f310d300b06035504de130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: ?\?=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with MD2\nRSA key size \: 128 bits\n":0 +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"308199308183a0030201008204deadbeef300d06092a864886f70d01010b0500300f310d300b06035504de130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: ?\?=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 128 bits\n":0 X509 Certificate ASN1 (Name with composite RDN) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA1_C x509parse_crt:"3082029f30820208a00302010202044c20e3bd300d06092a864886f70d01010505003056310b3009060355040613025553310b300906035504080c0243413121301f060355040a0c18496e7465726e6574205769646769747320507479204c74643117301506035504030c0e4672616e6b656e63657274204341301e170d3133303830323135313433375a170d3135303831373035353433315a3081d1310b3009060355040613025553311330110603550408130a57617368696e67746f6e31133011060b2b0601040182373c0201031302555331193017060b2b0601040182373c020102130844656c6177617265311a3018060355040a1311417574686f72697a652e4e6574204c4c43311d301b060355040f131450726976617465204f7267616e697a6174696f6e312a300e06035504051307343336393139313018060355040313117777772e617574686f72697a652e6e6574311630140603550407130d53616e204672616e636973636f30819f300d06092a864886f70d010101050003818d0030818902818100d885c62e209b6ac005c64f0bcfdaac1f2b67a18802f75b08851ff933deed888b7b68a62fcabdb21d4a8914becfeaaa1b7e08a09ffaf9916563586dc95e2877262b0b5f5ec27eb4d754aa6facd1d39d25b38a2372891bacdd3e919f791ed25704e8920e380e5623a38e6a23935978a3aec7a8e761e211d42effa2713e44e7de0b0203010001300d06092a864886f70d010105050003818100092f7424d3f6da4b8553829d958ed1980b9270b42c0d3d5833509a28c66bb207df9f3c51d122065e00b87c08c2730d2745fe1c279d16fae4d53b4bf5bdfa3631fceeb2e772b6b08a3eca5a2e2c687aefd23b4b73bf77ac6099711342cf070b35c6f61333a7cbf613d8dd4bd73e9df34bcd4284b0b4df57c36c450613f11e5dac":"cert. version \: 3\nserial number \: 4C\:20\:E3\:BD\nissuer name \: C=US, ST=CA, O=Internet Widgits Pty Ltd, CN=Frankencert CA\nsubject name \: C=US, ST=Washington, ??=US, ??=Delaware, O=Authorize.Net LLC, ??=Private Organization, serialNumber=4369191 + CN=www.authorize.net, L=San Francisco\nissued on \: 2013-08-02 15\:14\:37\nexpires on \: 2015-08-17 05\:54\:31\nsigned using \: RSA with SHA1\nRSA key size \: 1024 bits\n":0 X509 Certificate ASN1 (Name with PKCS9 email) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30819f308189a0030201008204deadbeef300d06092a864886f70d010102050030153113301106092a864886f70d010901130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: emailAddress=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with MD2\nRSA key size \: 128 bits\n":0 +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30819f308189a0030201008204deadbeef300d06092a864886f70d01010b050030153113301106092a864886f70d010901130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: emailAddress=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 128 bits\n":0 X509 Certificate ASN1 (Name with unknown PKCS9 part) -depends_on:MBEDTLS_RSA_C:MBEDTLS_MD2_C -x509parse_crt:"30819f308189a0030201008204deadbeef300d06092a864886f70d010102050030153113301106092a864886f70d0109ab130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092A864886F70D010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d0101020500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: ?\?=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with MD2\nRSA key size \: 128 bits\n":0 +depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C +x509parse_crt:"30819f308189a0030201008204deadbeef300d06092a864886f70d01010b050030153113301106092a864886f70d0109ab130454657374301c170c303930313031303030303030170c303931323331323335393539300c310a30080600130454657374302a300d06092a864886f70d010101050003190030160210ffffffffffffffffffffffffffffffff0202ffff300d06092a864886f70d01010b0500030200ff":"cert. version \: 1\nserial number \: DE\:AD\:BE\:EF\nissuer name \: ?\?=Test\nsubject name \: ?\?=Test\nissued on \: 2009-01-01 00\:00\:00\nexpires on \: 2009-12-31 23\:59\:59\nsigned using \: RSA with SHA-256\nRSA key size \: 128 bits\n":0 X509 Certificate ASN1 (ECDSA signature, RSA key) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA1_C:MBEDTLS_ECDSA_C -x509parse_crt:"3081E630819E020103300906072A8648CE3D0401300F310D300B0603550403130454657374301E170D3133303731303039343631385A170D3233303730383039343631385A300F310D300B0603550403130454657374304C300D06092A864886F70D0101010500033B003038023100E8F546061D3B49BC2F6B7524B7EA4D73A8D5293EE8C64D9407B70B5D16BAEBC32B8205591EAB4E1EB57E9241883701250203010001300906072A8648CE3D0401033800303502186E18209AFBED14A0D9A796EFCAD68891E3CCD5F75815C833021900E92B4FD460B1994693243B9FFAD54729DE865381BDA41D25":"cert. version \: 1\nserial number \: 03\nissuer name \: CN=Test\nsubject name \: CN=Test\nissued on \: 2013-07-10 09\:46\:18\nexpires on \: 2023-07-08 09\:46\:18\nsigned using \: ECDSA with SHA1\nRSA key size \: 384 bits\n":0 +x509parse_crt:"3081e630819e020103300906072a8648ce3d0401300f310d300b0603550403130454657374301e170d3133303731303039343631385a170d3233303730383039343631385a300f310d300b0603550403130454657374304c300d06092a864886f70d0101010500033b003038023100e8f546061d3b49bc2f6b7524b7ea4d73a8d5293ee8c64d9407b70b5d16baebc32b8205591eab4e1eb57e9241883701250203010001300906072a8648ce3d0401033800303502186e18209afbed14a0d9a796efcad68891e3ccd5f75815c833021900e92b4fd460b1994693243b9ffad54729de865381bda41d25":"cert. version \: 1\nserial number \: 03\nissuer name \: CN=Test\nsubject name \: CN=Test\nissued on \: 2013-07-10 09\:46\:18\nexpires on \: 2023-07-08 09\:46\:18\nsigned using \: ECDSA with SHA1\nRSA key size \: 384 bits\n":0 X509 Certificate ASN1 (ECDSA signature, EC key) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP192R1_ENABLED:MBEDTLS_SHA1_C -x509parse_crt:"3081EB3081A3020900F41534662EC7E912300906072A8648CE3D0401300F310D300B0603550403130454657374301E170D3133303731303039343031395A170D3233303730383039343031395A300F310D300B06035504031304546573743049301306072A8648CE3D020106082A8648CE3D030101033200042137969FABD4E370624A0E1A33E379CAB950CCE00EF8C3C3E2ADAEB7271C8F07659D65D3D777DCF21614363AE4B6E617300906072A8648CE3D04010338003035021858CC0F957946FE6A303D92885A456AA74C743C7B708CBD37021900FE293CAC21AF352D16B82EB8EA54E9410B3ABAADD9F05DD6":"cert. version \: 1\nserial number \: F4\:15\:34\:66\:2E\:C7\:E9\:12\nissuer name \: CN=Test\nsubject name \: CN=Test\nissued on \: 2013-07-10 09\:40\:19\nexpires on \: 2023-07-08 09\:40\:19\nsigned using \: ECDSA with SHA1\nEC key size \: 192 bits\n":0 +x509parse_crt:"3081eb3081a3020900f41534662ec7e912300906072a8648ce3d0401300f310d300b0603550403130454657374301e170d3133303731303039343031395a170d3233303730383039343031395a300f310d300b06035504031304546573743049301306072a8648ce3d020106082a8648ce3d030101033200042137969fabd4e370624a0e1a33e379cab950cce00ef8c3c3e2adaeb7271c8f07659d65d3d777dcf21614363ae4b6e617300906072a8648ce3d04010338003035021858cc0f957946fe6a303d92885a456aa74c743c7b708cbd37021900fe293cac21af352d16b82eb8ea54e9410b3abaadd9f05dd6":"cert. version \: 1\nserial number \: F4\:15\:34\:66\:2E\:C7\:E9\:12\nissuer name \: CN=Test\nsubject name \: CN=Test\nissued on \: 2013-07-10 09\:40\:19\nexpires on \: 2023-07-08 09\:40\:19\nsigned using \: ECDSA with SHA1\nEC key size \: 192 bits\n":0 X509 Certificate ASN1 (RSA signature, EC key) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP192R1_ENABLED:MBEDTLS_SHA1_C:MBEDTLS_RSA_C -x509parse_crt:"3081E430819F020104300D06092A864886F70D0101050500300F310D300B0603550403130454657374301E170D3133303731303135303233375A170D3233303730383135303233375A300F310D300B06035504031304546573743049301306072A8648CE3D020106082A8648CE3D03010103320004E962551A325B21B50CF6B990E33D4318FD16677130726357A196E3EFE7107BCB6BDC6D9DB2A4DF7C964ACFE81798433D300D06092A864886F70D01010505000331001A6C18CD1E457474B2D3912743F44B571341A7859A0122774A8E19A671680878936949F904C9255BDD6FFFDB33A7E6D8":"cert. version \: 1\nserial number \: 04\nissuer name \: CN=Test\nsubject name \: CN=Test\nissued on \: 2013-07-10 15\:02\:37\nexpires on \: 2023-07-08 15\:02\:37\nsigned using \: RSA with SHA1\nEC key size \: 192 bits\n":0 +x509parse_crt:"3081e430819f020104300d06092a864886f70d0101050500300f310d300b0603550403130454657374301e170d3133303731303135303233375a170d3233303730383135303233375a300f310d300b06035504031304546573743049301306072a8648ce3d020106082a8648ce3d03010103320004e962551a325b21b50cf6b990e33d4318fd16677130726357a196e3efe7107bcb6bdc6d9db2a4df7c964acfe81798433d300d06092a864886f70d01010505000331001a6c18cd1e457474b2d3912743f44b571341a7859a0122774a8e19a671680878936949f904c9255bdd6fffdb33a7e6d8":"cert. version \: 1\nserial number \: 04\nissuer name \: CN=Test\nsubject name \: CN=Test\nissued on \: 2013-07-10 15\:02\:37\nexpires on \: 2023-07-08 15\:02\:37\nsigned using \: RSA with SHA1\nEC key size \: 192 bits\n":0 X509 Certificate ASN1 (invalid version 3) x509parse_crt:"30173015a0030201038204deadbeef30080604cafed00d0500":"":MBEDTLS_ERR_X509_UNKNOWN_VERSION X509 Certificate ASN1 (invalid version overflow) -x509parse_crt:"301A3018a00602047FFFFFFF8204deadbeef30080604cafed00d0500":"":MBEDTLS_ERR_X509_UNKNOWN_VERSION +x509parse_crt:"301a3018a00602047fffffff8204deadbeef30080604cafed00d0500":"":MBEDTLS_ERR_X509_UNKNOWN_VERSION X509 Certificate ASN1 (invalid SubjectAltNames tag) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA1_C -x509parse_crt:"308203723082025AA003020102020111300D06092A864886F70D0101050500303B310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C3119301706035504031310506F6C617253534C2054657374204341301E170D3132303531303133323334315A170D3232303531313133323334315A303A310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C311830160603550403130F7777772E6578616D706C652E636F6D30820122300D06092A864886F70D01010105000382010F003082010A0282010100B93C4AC5C8A38E9017A49E52AA7175266180E7C7B56D8CFFAAB64126B7BE11AD5C73160C64114804FFD6E13B05DB89BBB39709D51C14DD688739B03D71CBE276D01AD8182D801B54F6E5449AF1CBAF612EDF490D9D09B7EDB1FD3CFD3CFA24CF5DBF7CE453E725B5EA4422E926D3EA20949EE66167BA2E07670B032FA209EDF0338F0BCE10EF67A4C608DAC1EDC23FD74ADD153DF95E1C8160463EB5B33D2FA6DE471CBC92AEEBDF276B1656B7DCECD15557A56EEC7525F5B77BDFABD23A5A91987D97170B130AA76B4A8BC14730FB3AF84104D5C1DFB81DBF7B01A565A2E01E36B7A65CCC305AF8CD6FCDF1196225CA01E3357FFA20F5DCFD69B26A007D17F70203010001A38181307F30090603551D1304023000301D0603551D0E041604147DE49C6BE6F9717D46D2123DAD6B1DFDC2AA784C301F0603551D23041830168014B45AE4A5B3DED252F6B9D5A6950FEB3EBCC7FDFF30320603551D11042B3029C20B6578616D706C652E636F6D820B6578616D706C652E6E6574820D2A2E6578616D706C652E6F7267300D06092A864886F70D010105050003820101004F09CB7AD5EEF5EF620DDC7BA285D68CCA95B46BDA115B92007513B9CA0BCEEAFBC31FE23F7F217479E2E6BCDA06E52F6FF655C67339CF48BC0D2F0CD27A06C34A4CD9485DA0D07389E4D4851D969A0E5799C66F1D21271F8D0529E840AE823968C39707CF3C934C1ADF2FA6A455487F7C8C1AC922DA24CD9239C68AECB08DF5698267CB04EEDE534196C127DC2FFE33FAD30EB8D432A9842853A5F0D189D5A298E71691BB9CC0418E8C58ACFFE3DD2E7AABB0B97176AD0F2733F7A929D3C076C0BF06407C0ED5A47C8AE2326E16AEDA641FB0557CDBDDF1A4BA447CB39958D2346E00EA976C143AF2101E0AA249107601F4F2C818FDCC6346128B091BF194E6":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +x509parse_crt:"308203723082025aa003020102020111300d06092a864886f70d0101050500303b310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c3119301706035504031310506f6c617253534c2054657374204341301e170d3132303531303133323334315a170d3232303531313133323334315a303a310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c311830160603550403130f7777772e6578616d706c652e636f6d30820122300d06092a864886f70d01010105000382010f003082010a0282010100b93c4ac5c8a38e9017a49e52aa7175266180e7c7b56d8cffaab64126b7be11ad5c73160c64114804ffd6e13b05db89bbb39709d51c14dd688739b03d71cbe276d01ad8182d801b54f6e5449af1cbaf612edf490d9d09b7edb1fd3cfd3cfa24cf5dbf7ce453e725b5ea4422e926d3ea20949ee66167ba2e07670b032fa209edf0338f0bce10ef67a4c608dac1edc23fd74add153df95e1c8160463eb5b33d2fa6de471cbc92aeebdf276b1656b7dcecd15557a56eec7525f5b77bdfabd23a5a91987d97170b130aa76b4a8bc14730fb3af84104d5c1dfb81dbf7b01a565a2e01e36b7a65ccc305af8cd6fcdf1196225ca01e3357ffa20f5dcfd69b26a007d17f70203010001a38181307f30090603551d1304023000301d0603551d0e041604147de49c6be6f9717d46d2123dad6b1dfdc2aa784c301f0603551d23041830168014b45ae4a5b3ded252f6b9d5a6950feb3ebcc7fdff30320603551d11042b3029c20b6578616d706c652e636f6d820b6578616d706c652e6e6574820d2a2e6578616d706c652e6f7267300d06092a864886f70d010105050003820101004f09cb7ad5eef5ef620ddc7ba285d68cca95b46bda115b92007513b9ca0bceeafbc31fe23f7f217479e2e6bcda06e52f6ff655c67339cf48bc0d2f0cd27a06c34a4cd9485da0d07389e4d4851d969a0e5799c66f1d21271f8d0529e840ae823968c39707cf3c934c1adf2fa6a455487f7c8c1ac922da24cd9239c68aecb08df5698267cb04eede534196c127dc2ffe33fad30eb8d432a9842853a5f0d189d5a298e71691bb9cc0418e8c58acffe3dd2e7aabb0b97176ad0f2733f7a929d3c076c0bf06407c0ed5a47c8ae2326e16aeda641fb0557cdbddf1a4ba447cb39958d2346e00ea976c143af2101e0aa249107601f4f2c818fdcc6346128b091bf194e6":"":MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 CRL ASN1 (Incorrect first tag) x509parse_crl:"":"":MBEDTLS_ERR_X509_INVALID_FORMAT @@ -1308,7 +1328,7 @@ X509 CRL ASN1 (invalid version 2) x509parse_crl:"30463031020102300d06092a864886f70d01010e0500300f310d300b0603550403130441424344170c303930313031303030303030300d06092a864886f70d01010e050003020001":"":MBEDTLS_ERR_X509_UNKNOWN_VERSION X509 CRL ASN1 (invalid version overflow) -x509parse_crl:"3049303102047FFFFFFF300d06092a864886f70d01010e0500300f310d300b0603550403130441424344170c303930313031303030303030300d06092a864886f70d01010e050003020001":"":MBEDTLS_ERR_X509_UNKNOWN_VERSION +x509parse_crl:"3049303102047fffffff300d06092a864886f70d01010e0500300f310d300b0603550403130441424344170c303930313031303030303030300d06092a864886f70d01010e050003020001":"":MBEDTLS_ERR_X509_UNKNOWN_VERSION X509 CRL ASN1 (extension seq too long, crl-idp.pem byte 121) depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_RSA_C:MBEDTLS_SHA256_C @@ -1463,28 +1483,28 @@ depends_on:MBEDTLS_SHA256_C:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBE mbedtls_x509_crt_verify_chain:"data_files/server10_int3_int-ca2_ca.crt":"data_files/test-ca2.crt":-1:-4:"":8 X509 OID description #1 -x509_oid_desc:"2B06010505070301":"TLS Web Server Authentication" +x509_oid_desc:"2b06010505070301":"TLS Web Server Authentication" X509 OID description #2 -x509_oid_desc:"2B0601050507030f":"notfound" +x509_oid_desc:"2b0601050507030f":"notfound" X509 OID description #3 -x509_oid_desc:"2B0601050507030100":"notfound" +x509_oid_desc:"2b0601050507030100":"notfound" X509 OID numstring #1 (wide buffer) -x509_oid_numstr:"2B06010505070301":"1.3.6.1.5.5.7.3.1":20:17 +x509_oid_numstr:"2b06010505070301":"1.3.6.1.5.5.7.3.1":20:17 X509 OID numstring #2 (buffer just fits) -x509_oid_numstr:"2B06010505070301":"1.3.6.1.5.5.7.3.1":18:17 +x509_oid_numstr:"2b06010505070301":"1.3.6.1.5.5.7.3.1":18:17 X509 OID numstring #3 (buffer too small) -x509_oid_numstr:"2B06010505070301":"1.3.6.1.5.5.7.3.1":17:MBEDTLS_ERR_OID_BUF_TOO_SMALL +x509_oid_numstr:"2b06010505070301":"1.3.6.1.5.5.7.3.1":17:MBEDTLS_ERR_OID_BUF_TOO_SMALL X509 OID numstring #4 (larger number) -x509_oid_numstr:"2A864886F70D":"1.2.840.113549":15:14 +x509_oid_numstr:"2a864886f70d":"1.2.840.113549":15:14 X509 OID numstring #5 (arithmetic overflow) -x509_oid_numstr:"2A8648F9F8F7F6F5F4F3F2F1F001":"":100:MBEDTLS_ERR_OID_BUF_TOO_SMALL +x509_oid_numstr:"2a8648f9f8f7f6f5f4f3f2f1f001":"":100:MBEDTLS_ERR_OID_BUF_TOO_SMALL X509 crt keyUsage #1 (no extension, expected KU) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA1_C @@ -1532,31 +1552,31 @@ x509_check_key_usage:"data_files/keyUsage.decipherOnly.crt":MBEDTLS_X509_KU_DIGI X509 crt extendedKeyUsage #1 (no extension, serverAuth) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C -x509_check_extended_key_usage:"data_files/server5.crt":"2B06010505070301":0 +x509_check_extended_key_usage:"data_files/server5.crt":"2b06010505070301":0 X509 crt extendedKeyUsage #2 (single value, present) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C -x509_check_extended_key_usage:"data_files/server5.eku-srv.crt":"2B06010505070301":0 +x509_check_extended_key_usage:"data_files/server5.eku-srv.crt":"2b06010505070301":0 X509 crt extendedKeyUsage #3 (single value, absent) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C -x509_check_extended_key_usage:"data_files/server5.eku-cli.crt":"2B06010505070301":MBEDTLS_ERR_X509_BAD_INPUT_DATA +x509_check_extended_key_usage:"data_files/server5.eku-cli.crt":"2b06010505070301":MBEDTLS_ERR_X509_BAD_INPUT_DATA X509 crt extendedKeyUsage #4 (two values, first) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C -x509_check_extended_key_usage:"data_files/server5.eku-srv_cli.crt":"2B06010505070301":0 +x509_check_extended_key_usage:"data_files/server5.eku-srv_cli.crt":"2b06010505070301":0 X509 crt extendedKeyUsage #5 (two values, second) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C -x509_check_extended_key_usage:"data_files/server5.eku-srv_cli.crt":"2B06010505070302":0 +x509_check_extended_key_usage:"data_files/server5.eku-srv_cli.crt":"2b06010505070302":0 X509 crt extendedKeyUsage #6 (two values, other) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C -x509_check_extended_key_usage:"data_files/server5.eku-srv_cli.crt":"2B06010505070303":MBEDTLS_ERR_X509_BAD_INPUT_DATA +x509_check_extended_key_usage:"data_files/server5.eku-srv_cli.crt":"2b06010505070303":MBEDTLS_ERR_X509_BAD_INPUT_DATA X509 crt extendedKeyUsage #7 (any, random) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C -x509_check_extended_key_usage:"data_files/server5.eku-cs_any.crt":"2B060105050703FF":0 +x509_check_extended_key_usage:"data_files/server5.eku-cs_any.crt":"2b060105050703ff":0 X509 RSASSA-PSS parameters ASN1 (good, all defaults) x509_parse_rsassa_pss_params:"":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:0 @@ -1565,113 +1585,113 @@ X509 RSASSA-PSS parameters ASN1 (wrong initial tag) x509_parse_rsassa_pss_params:"":MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 RSASSA-PSS parameters ASN1 (unknown tag in top-level sequence) -x509_parse_rsassa_pss_params:"A400":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +x509_parse_rsassa_pss_params:"a400":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 RSASSA-PSS parameters ASN1 (good, HashAlg SHA256) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C -x509_parse_rsassa_pss_params:"A00D300B0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA256:MBEDTLS_MD_SHA1:20:0 +x509_parse_rsassa_pss_params:"a00d300b0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA256:MBEDTLS_MD_SHA1:20:0 X509 RSASSA-PSS parameters ASN1 (good, explicit HashAlg = default) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA1_C -x509_parse_rsassa_pss_params:"A009300706052B0E03021A":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:0 +x509_parse_rsassa_pss_params:"a009300706052b0e03021a":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:0 X509 RSASSA-PSS parameters ASN1 (HashAlg wrong len #1) -x509_parse_rsassa_pss_params:"A00A300706052B0E03021A":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +x509_parse_rsassa_pss_params:"a00a300706052b0e03021a":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 RSASSA-PSS parameters ASN1 (HashAlg wrong len #2) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA1_C -x509_parse_rsassa_pss_params:"A00A300706052B0E03021A00":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +x509_parse_rsassa_pss_params:"a00a300706052b0e03021a00":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 RSASSA-PSS parameters ASN1 (HashAlg with parameters) -x509_parse_rsassa_pss_params:"A00F300D06096086480165030402013000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA256:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_INVALID_DATA +x509_parse_rsassa_pss_params:"a00f300d06096086480165030402013000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA256:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_INVALID_DATA X509 RSASSA-PSS parameters ASN1 (HashAlg unknown OID) -x509_parse_rsassa_pss_params:"A00D300B06096086480165030402FF":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA256:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_OID_NOT_FOUND +x509_parse_rsassa_pss_params:"a00d300b06096086480165030402ff":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA256:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_OID_NOT_FOUND X509 RSASSA-PSS parameters ASN1 (good, MGAlg = MGF1-SHA256) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C -x509_parse_rsassa_pss_params:"A11A301806092A864886F70D010108300B0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:0 +x509_parse_rsassa_pss_params:"a11a301806092a864886f70d010108300b0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:0 X509 RSASSA-PSS parameters ASN1 (good, explicit MGAlg = default) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA1_C -x509_parse_rsassa_pss_params:"A116301406092A864886F70D010108300706052B0E03021A":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:0 +x509_parse_rsassa_pss_params:"a116301406092a864886f70d010108300706052b0e03021a":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:0 X509 RSASSA-PSS parameters ASN1 (MGAlg wrong len #1) -x509_parse_rsassa_pss_params:"A11B301806092A864886F70D010108300B0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +x509_parse_rsassa_pss_params:"a11b301806092a864886f70d010108300b0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 RSASSA-PSS parameters ASN1 (MGAlg wrong len #2) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C -x509_parse_rsassa_pss_params:"A11B301806092A864886F70D010108300B060960864801650304020100":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +x509_parse_rsassa_pss_params:"a11b301806092a864886f70d010108300b060960864801650304020100":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 RSASSA-PSS parameters ASN1 (MGAlg AlgId wrong len #1) -x509_parse_rsassa_pss_params:"A11A301906092A864886F70D010108300B0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +x509_parse_rsassa_pss_params:"a11a301906092a864886f70d010108300b0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 RSASSA-PSS parameters ASN1 (MGAlg OID != MGF1) -x509_parse_rsassa_pss_params:"A11A301806092A864886F70D010109300B0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE + MBEDTLS_ERR_OID_NOT_FOUND +x509_parse_rsassa_pss_params:"a11a301806092a864886f70d010109300b0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE + MBEDTLS_ERR_OID_NOT_FOUND X509 RSASSA-PSS parameters ASN1 (MGAlg.params wrong tag) -x509_parse_rsassa_pss_params:"A11A301806092A864886F70D010108310B0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +x509_parse_rsassa_pss_params:"a11a301806092a864886f70d010108310b0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 RSASSA-PSS parameters ASN1 (MGAlg.params wrong len #1a) -x509_parse_rsassa_pss_params:"A10F300D06092A864886F70D0101083000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +x509_parse_rsassa_pss_params:"a10f300d06092a864886f70d0101083000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 RSASSA-PSS parameters ASN1 (MGAlg.params wrong len #1b) -x509_parse_rsassa_pss_params:"A11B301906092A864886F70D010108300C0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +x509_parse_rsassa_pss_params:"a11b301906092a864886f70d010108300c0609608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 RSASSA-PSS parameters ASN1 (MGAlg.params.alg not an OID) -x509_parse_rsassa_pss_params:"A11A301806092A864886F70D010108300B0709608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +x509_parse_rsassa_pss_params:"a11a301806092a864886f70d010108300b0709608648016503040201":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 RSASSA-PSS parameters ASN1 (MGAlg.params.alg unknown OID) -x509_parse_rsassa_pss_params:"A11A301806092A864886F70D010108300B06096086480165030402FF":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_OID_NOT_FOUND +x509_parse_rsassa_pss_params:"a11a301806092a864886f70d010108300b06096086480165030402ff":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_OID_NOT_FOUND X509 RSASSA-PSS parameters ASN1 (MGAlg.params.params NULL) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C -x509_parse_rsassa_pss_params:"A11C301A06092A864886F70D010108300D06096086480165030402010500":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:0 +x509_parse_rsassa_pss_params:"a11c301a06092a864886f70d010108300d06096086480165030402010500":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:0 X509 RSASSA-PSS parameters ASN1 (MGAlg.params.params wrong tag) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C -x509_parse_rsassa_pss_params:"A11C301A06092A864886F70D010108300D06096086480165030402013000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +x509_parse_rsassa_pss_params:"a11c301a06092a864886f70d010108300d06096086480165030402013000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 RSASSA-PSS parameters ASN1 (MGAlg.params wrong len #1c) -x509_parse_rsassa_pss_params:"A11D301B06092A864886F70D010108300E06096086480165030402010500":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +x509_parse_rsassa_pss_params:"a11d301b06092a864886f70d010108300e06096086480165030402010500":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 RSASSA-PSS parameters ASN1 (MGAlg.params wrong len #2) depends_on:MBEDTLS_RSA_C:MBEDTLS_SHA256_C -x509_parse_rsassa_pss_params:"A11D301B06092A864886F70D010108300E0609608648016503040201050000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +x509_parse_rsassa_pss_params:"a11d301b06092a864886f70d010108300e0609608648016503040201050000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA256:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 RSASSA-PSS parameters ASN1 (good, saltLen = 94) -x509_parse_rsassa_pss_params:"A20302015E":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:94:0 +x509_parse_rsassa_pss_params:"a20302015e":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:94:0 X509 RSASSA-PSS parameters ASN1 (good, explicit saltLen = default) -x509_parse_rsassa_pss_params:"A203020114":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:0 +x509_parse_rsassa_pss_params:"a203020114":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:0 X509 RSASSA-PSS parameters ASN1 (saltLen wrong len #1) -x509_parse_rsassa_pss_params:"A20402015E":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:94:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +x509_parse_rsassa_pss_params:"a20402015e":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:94:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 RSASSA-PSS parameters ASN1 (saltLen wrong len #2) -x509_parse_rsassa_pss_params:"A20402015E00":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:94:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +x509_parse_rsassa_pss_params:"a20402015e00":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:94:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 RSASSA-PSS parameters ASN1 (saltLen not an int) -x509_parse_rsassa_pss_params:"A2023000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:94:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +x509_parse_rsassa_pss_params:"a2023000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:94:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 RSASSA-PSS parameters ASN1 (good, explicit trailerField = default) -x509_parse_rsassa_pss_params:"A303020101":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:0 +x509_parse_rsassa_pss_params:"a303020101":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:0 X509 RSASSA-PSS parameters ASN1 (trailerField wrong len #1) -x509_parse_rsassa_pss_params:"A304020101":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +x509_parse_rsassa_pss_params:"a304020101":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 RSASSA-PSS parameters ASN1 (trailerField wrong len #2) -x509_parse_rsassa_pss_params:"A30402010100":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +x509_parse_rsassa_pss_params:"a30402010100":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 RSASSA-PSS parameters ASN1 (trailerField not an int) -x509_parse_rsassa_pss_params:"A3023000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +x509_parse_rsassa_pss_params:"a3023000":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 RSASSA-PSS parameters ASN1 (trailerField not 1) -x509_parse_rsassa_pss_params:"A303020102":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG +x509_parse_rsassa_pss_params:"a303020102":MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE:MBEDTLS_MD_SHA1:MBEDTLS_MD_SHA1:20:MBEDTLS_ERR_X509_INVALID_ALG X509 CSR ASN.1 (OK) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA1_C -mbedtls_x509_csr_parse:"308201183081BF0201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFFA029302706092A864886F70D01090E311A301830090603551D1304023000300B0603551D0F0404030205E0300906072A8648CE3D04010349003046022100B49FD8C8F77ABFA871908DFBE684A08A793D0F490A43D86FCF2086E4F24BB0C2022100F829D5CCD3742369299E6294394717C4B723A0F68B44E831B6E6C3BCABF97243":"CSR version \: 1\nsubject name \: C=NL, O=PolarSSL, CN=localhost\nsigned using \: ECDSA with SHA1\nEC key size \: 256 bits\n":0 +mbedtls_x509_csr_parse:"308201183081bf0201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa029302706092a864886f70d01090e311a301830090603551d1304023000300b0603551d0f0404030205e0300906072a8648ce3d04010349003046022100b49fd8c8f77abfa871908dfbe684a08a793d0f490a43d86fcf2086e4f24bb0c2022100f829d5ccd3742369299e6294394717c4b723a0f68b44e831b6e6c3bcabf97243":"CSR version \: 1\nsubject name \: C=NL, O=PolarSSL, CN=localhost\nsigned using \: ECDSA with SHA1\nEC key size \: 256 bits\n":0 X509 CSR ASN.1 (bad first tag) mbedtls_x509_csr_parse:"3100":"":MBEDTLS_ERR_X509_INVALID_FORMAT @@ -1704,63 +1724,63 @@ X509 CSR ASN.1 (bad CRI.Name payload: not a set) mbedtls_x509_csr_parse:"3009300702010030023000":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 CSR ASN.1 (bad CRI.Name payload: overlong) -mbedtls_x509_csr_parse:"300A30080201003002310100":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA +mbedtls_x509_csr_parse:"300a30080201003002310100":"":MBEDTLS_ERR_X509_INVALID_NAME + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 CSR ASN.1 (bad SubjectPublicKeyInfo: missing) -mbedtls_x509_csr_parse:"30143012020100300D310B3009060355040613024E4C":"":MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA +mbedtls_x509_csr_parse:"30143012020100300d310b3009060355040613024e4c":"":MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 CSR ASN.1 (bad SubjectPublicKeyInfo: not a sequence) -mbedtls_x509_csr_parse:"30163014020100300D310B3009060355040613024E4C3100":"":MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +mbedtls_x509_csr_parse:"30163014020100300d310b3009060355040613024e4c3100":"":MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 CSR ASN.1 (bad SubjectPublicKeyInfo: overlong) -mbedtls_x509_csr_parse:"30173014020100300D310B3009060355040613024E4C300100":"":MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA +mbedtls_x509_csr_parse:"30173014020100300d310b3009060355040613024e4c300100":"":MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 CSR ASN.1 (bad attributes: missing) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED -mbedtls_x509_csr_parse:"3081973081940201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFF":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA +mbedtls_x509_csr_parse:"3081973081940201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edff":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 CSR ASN.1 (bad attributes: bad tag) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED -mbedtls_x509_csr_parse:"3081993081960201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFF0500":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +mbedtls_x509_csr_parse:"3081993081960201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edff0500":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 CSR ASN.1 (bad attributes: overlong) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED -mbedtls_x509_csr_parse:"30819A3081960201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFFA00100":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA +mbedtls_x509_csr_parse:"30819a3081960201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa00100":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 CSR ASN.1 (bad sigAlg: missing) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED -mbedtls_x509_csr_parse:"3081C23081BF0201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFFA029302706092A864886F70D01090E311A301830090603551D1304023000300B0603551D0F0404030205E0":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +mbedtls_x509_csr_parse:"3081c23081bf0201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa029302706092a864886f70d01090e311a301830090603551d1304023000300b0603551d0f0404030205e0":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 CSR ASN.1 (bad sigAlg: not a sequence) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED -mbedtls_x509_csr_parse:"3081C43081BF0201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFFA029302706092A864886F70D01090E311A301830090603551D1304023000300B0603551D0F0404030205E03100":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +mbedtls_x509_csr_parse:"3081c43081bf0201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa029302706092a864886f70d01090e311a301830090603551d1304023000300b0603551d0f0404030205e03100":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 CSR ASN.1 (bad sigAlg: overlong) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED -mbedtls_x509_csr_parse:"3081C43081BF0201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFFA029302706092A864886F70D01090E311A301830090603551D1304023000300B0603551D0F0404030205E03001":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA +mbedtls_x509_csr_parse:"3081c43081bf0201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa029302706092a864886f70d01090e311a301830090603551d1304023000300b0603551d0f0404030205e03001":"":MBEDTLS_ERR_X509_INVALID_ALG + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 CSR ASN.1 (bad sigAlg: unknown) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED -mbedtls_x509_csr_parse:"3081CD3081BF0201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFFA029302706092A864886F70D01090E311A301830090603551D1304023000300B0603551D0F0404030205E0300906072A8648CE3D04FF":"":MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG +mbedtls_x509_csr_parse:"3081cd3081bf0201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa029302706092a864886f70d01090e311a301830090603551d1304023000300b0603551d0f0404030205e0300906072a8648ce3d04ff":"":MBEDTLS_ERR_X509_UNKNOWN_SIG_ALG X509 CSR ASN.1 (bad sig: missing) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA1_C -mbedtls_x509_csr_parse:"3081CD3081BF0201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFFA029302706092A864886F70D01090E311A301830090603551D1304023000300B0603551D0F0404030205E0300906072A8648CE3D0401":"":MBEDTLS_ERR_X509_INVALID_SIGNATURE + MBEDTLS_ERR_ASN1_OUT_OF_DATA +mbedtls_x509_csr_parse:"3081cd3081bf0201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa029302706092a864886f70d01090e311a301830090603551d1304023000300b0603551d0f0404030205e0300906072a8648ce3d0401":"":MBEDTLS_ERR_X509_INVALID_SIGNATURE + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 CSR ASN.1 (bad sig: not a bit string) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA1_C -mbedtls_x509_csr_parse:"3081CF3081BF0201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFFA029302706092A864886F70D01090E311A301830090603551D1304023000300B0603551D0F0404030205E0300906072A8648CE3D04010400":"":MBEDTLS_ERR_X509_INVALID_SIGNATURE + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG +mbedtls_x509_csr_parse:"3081cf3081bf0201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa029302706092a864886f70d01090e311a301830090603551d1304023000300b0603551d0f0404030205e0300906072a8648ce3d04010400":"":MBEDTLS_ERR_X509_INVALID_SIGNATURE + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG X509 CSR ASN.1 (bad sig: overlong) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA1_C -mbedtls_x509_csr_parse:"3081CF3081BF0201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFFA029302706092A864886F70D01090E311A301830090603551D1304023000300B0603551D0F0404030205E0300906072A8648CE3D04010301":"":MBEDTLS_ERR_X509_INVALID_SIGNATURE + MBEDTLS_ERR_ASN1_OUT_OF_DATA +mbedtls_x509_csr_parse:"3081cf3081bf0201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa029302706092a864886f70d01090e311a301830090603551d1304023000300b0603551d0f0404030205e0300906072a8648ce3d04010301":"":MBEDTLS_ERR_X509_INVALID_SIGNATURE + MBEDTLS_ERR_ASN1_OUT_OF_DATA X509 CSR ASN.1 (extra data after signature) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA1_C -mbedtls_x509_csr_parse:"308201193081BF0201003034310B3009060355040613024E4C3111300F060355040A1308506F6C617253534C31123010060355040313096C6F63616C686F73743059301306072A8648CE3D020106082A8648CE3D0301070342000437CC56D976091E5A723EC7592DFF206EEE7CF9069174D0AD14B5F768225962924EE500D82311FFEA2FD2345D5D16BD8A88C26B770D55CD8A2A0EFA01C8B4EDFFA029302706092A864886F70D01090E311A301830090603551D1304023000300B0603551D0F0404030205E0300906072A8648CE3D04010349003046022100B49FD8C8F77ABFA871908DFBE684A08A793D0F490A43D86FCF2086E4F24BB0C2022100F829D5CCD3742369299E6294394717C4B723A0F68B44E831B6E6C3BCABF9724300":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH +mbedtls_x509_csr_parse:"308201193081bf0201003034310b3009060355040613024e4c3111300f060355040a1308506f6c617253534c31123010060355040313096c6f63616c686f73743059301306072a8648ce3d020106082a8648ce3d0301070342000437cc56d976091e5a723ec7592dff206eee7cf9069174d0ad14b5f768225962924ee500d82311ffea2fd2345d5d16bd8a88c26b770d55cd8a2a0efa01c8b4edffa029302706092a864886f70d01090e311a301830090603551d1304023000300b0603551d0f0404030205e0300906072a8648ce3d04010349003046022100b49fd8c8f77abfa871908dfbe684a08a793d0f490a43d86fcf2086e4f24bb0c2022100f829d5ccd3742369299e6294394717c4b723a0f68b44e831b6e6c3bcabf9724300":"":MBEDTLS_ERR_X509_INVALID_FORMAT + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH X509 CSR ASN.1 (invalid version overflow) -mbedtls_x509_csr_parse:"3008300602047FFFFFFF":"":MBEDTLS_ERR_X509_UNKNOWN_VERSION +mbedtls_x509_csr_parse:"3008300602047fffffff":"":MBEDTLS_ERR_X509_UNKNOWN_VERSION X509 File parse (no issues) depends_on:MBEDTLS_ECDSA_C:MBEDTLS_ECP_DP_SECP256R1_ENABLED:MBEDTLS_SHA256_C:MBEDTLS_RSA_C diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509parse.function b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509parse.function index 06f0108280..584ee822b6 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509parse.function +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509parse.function @@ -13,6 +13,15 @@ than the current threshold 19. To test larger values, please \ adapt the script tests/data_files/dir-max/long.sh." #endif +/* Test-only profile allowing all digests, PK algorithms, and curves. */ +const mbedtls_x509_crt_profile profile_all = +{ + 0xFFFFFFFF, /* Any MD */ + 0xFFFFFFFF, /* Any PK alg */ + 0xFFFFFFFF, /* Any curve */ + 1024, +}; + /* Profile for backward compatibility. Allows SHA-1, unlike the default profile. */ const mbedtls_x509_crt_profile compat_profile = @@ -291,6 +300,8 @@ void x509_verify( char *crt_file, char *ca_file, char *crl_file, profile = &mbedtls_x509_crt_profile_suiteb; else if( strcmp( profile_str, "compat" ) == 0 ) profile = &compat_profile; + else if( strcmp( profile_str, "all" ) == 0 ) + profile = &profile_all; else TEST_ASSERT( "Unknown algorithm profile" == 0 ); diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509write.data b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509write.data index 5b54d85885..c196625037 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509write.data +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509write.data @@ -1,78 +1,86 @@ Certificate Request check Server1 SHA1 depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 -x509_csr_check:"data_files/server1.key":"data_files/server1.req.sha1":MBEDTLS_MD_SHA1:0:0 +x509_csr_check:"data_files/server1.key":"data_files/server1.req.sha1":MBEDTLS_MD_SHA1:0:0:0:0 Certificate Request check Server1 SHA224 depends_on:MBEDTLS_SHA256_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 -x509_csr_check:"data_files/server1.key":"data_files/server1.req.sha224":MBEDTLS_MD_SHA224:0:0 +x509_csr_check:"data_files/server1.key":"data_files/server1.req.sha224":MBEDTLS_MD_SHA224:0:0:0:0 Certificate Request check Server1 SHA256 depends_on:MBEDTLS_SHA256_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 -x509_csr_check:"data_files/server1.key":"data_files/server1.req.sha256":MBEDTLS_MD_SHA256:0:0 +x509_csr_check:"data_files/server1.key":"data_files/server1.req.sha256":MBEDTLS_MD_SHA256:0:0:0:0 Certificate Request check Server1 SHA384 depends_on:MBEDTLS_SHA512_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 -x509_csr_check:"data_files/server1.key":"data_files/server1.req.sha384":MBEDTLS_MD_SHA384:0:0 +x509_csr_check:"data_files/server1.key":"data_files/server1.req.sha384":MBEDTLS_MD_SHA384:0:0:0:0 Certificate Request check Server1 SHA512 depends_on:MBEDTLS_SHA512_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 -x509_csr_check:"data_files/server1.key":"data_files/server1.req.sha512":MBEDTLS_MD_SHA512:0:0 +x509_csr_check:"data_files/server1.key":"data_files/server1.req.sha512":MBEDTLS_MD_SHA512:0:0:0:0 Certificate Request check Server1 MD4 depends_on:MBEDTLS_MD4_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 -x509_csr_check:"data_files/server1.key":"data_files/server1.req.md4":MBEDTLS_MD_MD4:0:0 +x509_csr_check:"data_files/server1.key":"data_files/server1.req.md4":MBEDTLS_MD_MD4:0:0:0:0 Certificate Request check Server1 MD5 depends_on:MBEDTLS_MD5_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 -x509_csr_check:"data_files/server1.key":"data_files/server1.req.md5":MBEDTLS_MD_MD5:0:0 +x509_csr_check:"data_files/server1.key":"data_files/server1.req.md5":MBEDTLS_MD_MD5:0:0:0:0 Certificate Request check Server1 key_usage depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 -x509_csr_check:"data_files/server1.key":"data_files/server1.req.key_usage":MBEDTLS_MD_SHA1:MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION | MBEDTLS_X509_KU_KEY_ENCIPHERMENT:0 +x509_csr_check:"data_files/server1.key":"data_files/server1.req.key_usage":MBEDTLS_MD_SHA1:MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION | MBEDTLS_X509_KU_KEY_ENCIPHERMENT:1:0:0 + +Certificate Request check Server1 key_usage empty +depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 +x509_csr_check:"data_files/server1.key":"data_files/server1.req.key_usage_empty":MBEDTLS_MD_SHA1:0:1:0:0 Certificate Request check Server1 ns_cert_type depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 -x509_csr_check:"data_files/server1.key":"data_files/server1.req.cert_type":MBEDTLS_MD_SHA1:0:MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER +x509_csr_check:"data_files/server1.key":"data_files/server1.req.cert_type":MBEDTLS_MD_SHA1:0:0:MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER:1 + +Certificate Request check Server1 ns_cert_type empty +depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 +x509_csr_check:"data_files/server1.key":"data_files/server1.req.cert_type_empty":MBEDTLS_MD_SHA1:0:0:0:1 Certificate Request check Server1 key_usage + ns_cert_type depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15 -x509_csr_check:"data_files/server1.key":"data_files/server1.req.ku-ct":MBEDTLS_MD_SHA1:MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION | MBEDTLS_X509_KU_KEY_ENCIPHERMENT:MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER +x509_csr_check:"data_files/server1.key":"data_files/server1.req.ku-ct":MBEDTLS_MD_SHA1:MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION | MBEDTLS_X509_KU_KEY_ENCIPHERMENT:1:MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER:1 Certificate Request check Server5 ECDSA, key_usage depends_on:MBEDTLS_SHA1_C:MBEDTLS_ECDSA_C:MBEDTLS_ECDSA_DETERMINISTIC:MBEDTLS_ECP_DP_SECP256R1_ENABLED -x509_csr_check:"data_files/server5.key":"data_files/server5.req.ku.sha1":MBEDTLS_MD_SHA1:MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION:0 +x509_csr_check:"data_files/server5.key":"data_files/server5.req.ku.sha1":MBEDTLS_MD_SHA1:MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION:1:0:0 Certificate write check Server1 SHA1 depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_MD5_C -x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:0:1:-1:"data_files/server1.crt":0 +x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:0:0:0:1:-1:"data_files/server1.crt":0 Certificate write check Server1 SHA1, key_usage depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_MD5_C -x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION | MBEDTLS_X509_KU_KEY_ENCIPHERMENT:0:1:-1:"data_files/server1.key_usage.crt":0 +x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION | MBEDTLS_X509_KU_KEY_ENCIPHERMENT:1:0:0:1:-1:"data_files/server1.key_usage.crt":0 Certificate write check Server1 SHA1, ns_cert_type depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_MD5_C -x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER:1:-1:"data_files/server1.cert_type.crt":0 +x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:0:MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER:1:1:-1:"data_files/server1.cert_type.crt":0 Certificate write check Server1 SHA1, version 1 depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_MD5_C -x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:0:1:MBEDTLS_X509_CRT_VERSION_1:"data_files/server1.v1.crt":0 +x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:0:0:0:1:MBEDTLS_X509_CRT_VERSION_1:"data_files/server1.v1.crt":0 Certificate write check Server1 SHA1, RSA_ALT depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_MD5_C -x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:0:0:-1:"data_files/server1.noauthid.crt":1 +x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:0:0:0:0:-1:"data_files/server1.noauthid.crt":1 Certificate write check Server1 SHA1, RSA_ALT, key_usage depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_MD5_C -x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION | MBEDTLS_X509_KU_KEY_ENCIPHERMENT:0:0:-1:"data_files/server1.key_usage_noauthid.crt":1 +x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_NON_REPUDIATION | MBEDTLS_X509_KU_KEY_ENCIPHERMENT:1:0:0:0:-1:"data_files/server1.key_usage_noauthid.crt":1 Certificate write check Server1 SHA1, RSA_ALT, ns_cert_type depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_MD5_C -x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER:0:-1:"data_files/server1.cert_type_noauthid.crt":1 +x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:0:MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER:1:0:-1:"data_files/server1.cert_type_noauthid.crt":1 Certificate write check Server1 SHA1, RSA_ALT, version 1 depends_on:MBEDTLS_SHA1_C:MBEDTLS_RSA_C:MBEDTLS_PKCS1_V15:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC:MBEDTLS_MD5_C -x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:0:0:MBEDTLS_X509_CRT_VERSION_1:"data_files/server1.v1.crt":1 +x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":MBEDTLS_MD_SHA1:0:0:0:0:0:MBEDTLS_X509_CRT_VERSION_1:"data_files/server1.v1.crt":1 X509 String to Names #1 mbedtls_x509_string_to_names:"C=NL,O=Offspark\, Inc., OU=PolarSSL":"C=NL, O=Offspark, Inc., OU=PolarSSL":0 diff --git a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509write.function b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509write.function index 62f82e8a05..aba23d4c91 100644 --- a/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509write.function +++ b/3rdparty/mbedtls/mbedtls/tests/suites/test_suite_x509write.function @@ -35,8 +35,9 @@ size_t mbedtls_rsa_key_len_func( void *ctx ) */ /* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C:MBEDTLS_X509_CSR_WRITE_C */ -void x509_csr_check( char *key_file, char *cert_req_check_file, - int md_type, int key_usage, int cert_type ) +void x509_csr_check( char * key_file, char * cert_req_check_file, int md_type, + int key_usage, int set_key_usage, int cert_type, + int set_cert_type ) { mbedtls_pk_context key; mbedtls_x509write_csr req; @@ -58,9 +59,9 @@ void x509_csr_check( char *key_file, char *cert_req_check_file, mbedtls_x509write_csr_set_md_alg( &req, md_type ); mbedtls_x509write_csr_set_key( &req, &key ); TEST_ASSERT( mbedtls_x509write_csr_set_subject_name( &req, subject_name ) == 0 ); - if( key_usage != 0 ) + if( set_key_usage != 0 ) TEST_ASSERT( mbedtls_x509write_csr_set_key_usage( &req, key_usage ) == 0 ); - if( cert_type != 0 ) + if( set_cert_type != 0 ) TEST_ASSERT( mbedtls_x509write_csr_set_ns_cert_type( &req, cert_type ) == 0 ); ret = mbedtls_x509write_csr_pem( &req, buf, sizeof( buf ), @@ -99,7 +100,8 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd, char *subject_name, char *issuer_key_file, char *issuer_pwd, char *issuer_name, char *serial_str, char *not_before, char *not_after, - int md_type, int key_usage, int cert_type, int auth_ident, + int md_type, int key_usage, int set_key_usage, + int cert_type, int set_cert_type, int auth_ident, int ver, char *cert_check_file, int rsa_alt ) { mbedtls_pk_context subject_key, issuer_key, issuer_key_alt; @@ -167,9 +169,9 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd, TEST_ASSERT( mbedtls_x509write_crt_set_subject_key_identifier( &crt ) == 0 ); if( auth_ident ) TEST_ASSERT( mbedtls_x509write_crt_set_authority_key_identifier( &crt ) == 0 ); - if( key_usage != 0 ) + if( set_key_usage != 0 ) TEST_ASSERT( mbedtls_x509write_crt_set_key_usage( &crt, key_usage ) == 0 ); - if( cert_type != 0 ) + if( set_cert_type != 0 ) TEST_ASSERT( mbedtls_x509write_crt_set_ns_cert_type( &crt, cert_type ) == 0 ); } diff --git a/3rdparty/mbedtls/mbedtls/visualc/VS2010/mbedTLS.sln b/3rdparty/mbedtls/mbedtls/visualc/VS2010/mbedTLS.sln index 686091c7f7..89178cc2d5 100644 --- a/3rdparty/mbedtls/mbedtls/visualc/VS2010/mbedTLS.sln +++ b/3rdparty/mbedtls/mbedtls/visualc/VS2010/mbedTLS.sln @@ -183,11 +183,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gen_random_ctr_drbg", "gen_ {46CF2D25-6A36-4189-B59C-E4815388E554} = {46CF2D25-6A36-4189-B59C-E4815388E554} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ssl_cert_test", "ssl_cert_test.vcxproj", "{3FE0C0E1-D9BA-6A26-380C-F293E543B914}" - ProjectSection(ProjectDependencies) = postProject - {46CF2D25-6A36-4189-B59C-E4815388E554} = {46CF2D25-6A36-4189-B59C-E4815388E554} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "benchmark", "benchmark.vcxproj", "{90EFD9A4-C6B0-3EE8-1F06-0A0E0D55AEDA}" ProjectSection(ProjectDependencies) = postProject {46CF2D25-6A36-4189-B59C-E4815388E554} = {46CF2D25-6A36-4189-B59C-E4815388E554} @@ -542,14 +537,6 @@ Global {5FCC71F6-FF33-EBCF-FBA2-8FC783D5318E}.Release|Win32.Build.0 = Release|Win32 {5FCC71F6-FF33-EBCF-FBA2-8FC783D5318E}.Release|x64.ActiveCfg = Release|x64 {5FCC71F6-FF33-EBCF-FBA2-8FC783D5318E}.Release|x64.Build.0 = Release|x64 - {3FE0C0E1-D9BA-6A26-380C-F293E543B914}.Debug|Win32.ActiveCfg = Debug|Win32 - {3FE0C0E1-D9BA-6A26-380C-F293E543B914}.Debug|Win32.Build.0 = Debug|Win32 - {3FE0C0E1-D9BA-6A26-380C-F293E543B914}.Debug|x64.ActiveCfg = Debug|x64 - {3FE0C0E1-D9BA-6A26-380C-F293E543B914}.Debug|x64.Build.0 = Debug|x64 - {3FE0C0E1-D9BA-6A26-380C-F293E543B914}.Release|Win32.ActiveCfg = Release|Win32 - {3FE0C0E1-D9BA-6A26-380C-F293E543B914}.Release|Win32.Build.0 = Release|Win32 - {3FE0C0E1-D9BA-6A26-380C-F293E543B914}.Release|x64.ActiveCfg = Release|x64 - {3FE0C0E1-D9BA-6A26-380C-F293E543B914}.Release|x64.Build.0 = Release|x64 {90EFD9A4-C6B0-3EE8-1F06-0A0E0D55AEDA}.Debug|Win32.ActiveCfg = Debug|Win32 {90EFD9A4-C6B0-3EE8-1F06-0A0E0D55AEDA}.Debug|Win32.Build.0 = Debug|Win32 {90EFD9A4-C6B0-3EE8-1F06-0A0E0D55AEDA}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/3rdparty/mbedtls/mbedtls/visualc/VS2010/ssl_cert_test.vcxproj b/3rdparty/mbedtls/mbedtls/visualc/VS2010/ssl_cert_test.vcxproj deleted file mode 100644 index b8f014e367..0000000000 --- a/3rdparty/mbedtls/mbedtls/visualc/VS2010/ssl_cert_test.vcxproj +++ /dev/null @@ -1,174 +0,0 @@ -ļ»æ - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - - - - - {46cf2d25-6a36-4189-b59c-e4815388e554} - true - - - - {3FE0C0E1-D9BA-6A26-380C-F293E543B914} - Win32Proj - ssl_cert_test - - - - Application - true - Unicode - - - Application - true - Unicode - - - Application - false - true - Unicode - - - Application - false - true - Unicode - Windows7.1SDK - - - - - - - - - - - - - - - - - - - true - $(Configuration)\$(TargetName)\ - - - true - $(Configuration)\$(TargetName)\ - - - false - $(Configuration)\$(TargetName)\ - - - false - $(Configuration)\$(TargetName)\ - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - ../../include - - - Console - true - NotSet - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - Debug - - - false - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - ../../include - - - Console - true - NotSet - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - Debug - - - false - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - ../../include - - - Console - true - true - true - Release - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - - - Level3 - - - MaxSpeed - true - true - WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - ../../include - - - Console - true - true - true - Release - %(AdditionalDependencies); - - - - - - From ac71ba6b49546330fdebff41f76d4860d81599ef Mon Sep 17 00:00:00 2001 From: Simon Leet Date: Fri, 13 Sep 2019 02:24:30 +0000 Subject: [PATCH 009/420] Integrate mbedTLS v2.7.11 into OE SDK - Update CHANGELOG.md to reflect move to mbedTLS v2.7.11. - Update mbedtls/update.make to move to mbedTLS v2.7.11. - Patch mbedtls/library/x509write_crt.c to support attested TLS. - Add patch file of required changes for future updates. - Update .check-license.ignore to ignore .patch files. - Add README.md for 3rdparty/mbedtls folder to document modifications to mbedtls for enclaves. --- ...atch-x509write_crt.c-for-attestedTLS.patch | 264 ++++++++++++++++++ 3rdparty/mbedtls/README.md | 21 ++ .../mbedtls/mbedtls/library/x509write_crt.c | 143 ++++++---- 3rdparty/mbedtls/update.make | 2 +- CHANGELOG.md | 1 + scripts/.check-license.ignore | 1 + 6 files changed, 377 insertions(+), 55 deletions(-) create mode 100644 3rdparty/mbedtls/0001-Patch-x509write_crt.c-for-attestedTLS.patch create mode 100644 3rdparty/mbedtls/README.md diff --git a/3rdparty/mbedtls/0001-Patch-x509write_crt.c-for-attestedTLS.patch b/3rdparty/mbedtls/0001-Patch-x509write_crt.c-for-attestedTLS.patch new file mode 100644 index 0000000000..6bf2af9a97 --- /dev/null +++ b/3rdparty/mbedtls/0001-Patch-x509write_crt.c-for-attestedTLS.patch @@ -0,0 +1,264 @@ +From cede0947eb335c4f2d425fa113adbf093efe8f6b Mon Sep 17 00:00:00 2001 +From: Simon Leet +Date: Fri, 13 Sep 2019 01:20:45 +0000 +Subject: [PATCH] Patch x509write_crt.c for attestedTLS + +--- + .../mbedtls/mbedtls/library/x509write_crt.c | 143 +++++++++++------- + 1 file changed, 89 insertions(+), 54 deletions(-) + +diff --git a/3rdparty/mbedtls/mbedtls/library/x509write_crt.c b/3rdparty/mbedtls/mbedtls/library/x509write_crt.c +index 41dfe87b7..de7bf0c70 100644 +--- a/3rdparty/mbedtls/mbedtls/library/x509write_crt.c ++++ b/3rdparty/mbedtls/mbedtls/library/x509write_crt.c +@@ -298,9 +298,10 @@ static int x509_write_time( unsigned char **p, unsigned char *start, + return( (int) len ); + } + +-int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size, +- int (*f_rng)(void *, unsigned char *, size_t), +- void *p_rng ) ++int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, ++ unsigned char *buf, size_t size, ++ int (*f_rng)(void *, unsigned char *, size_t), ++ void *p_rng ) + { + int ret; + const char *sig_oid; +@@ -308,15 +309,14 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, + unsigned char *c, *c2; + unsigned char hash[64]; + unsigned char sig[MBEDTLS_MPI_MAX_SIZE]; +- unsigned char tmp_buf[2048]; + size_t sub_len = 0, pub_len = 0, sig_and_oid_len = 0, sig_len; + size_t len = 0; + mbedtls_pk_type_t pk_alg; + + /* +- * Prepare data to be signed in tmp_buf ++ * Prepare data to be signed at the end of the target buffer + */ +- c = tmp_buf + sizeof( tmp_buf ); ++ c = buf + size; + + /* Signature algorithm needed in TBS, and later for actual signature */ + +@@ -342,27 +342,36 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, + /* Only for v3 */ + if( ctx->version == MBEDTLS_X509_CRT_VERSION_3 ) + { +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_extensions( &c, tmp_buf, ctx->extensions ) ); +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) ); +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED | +- MBEDTLS_ASN1_SEQUENCE ) ); +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) ); +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | +- MBEDTLS_ASN1_CONSTRUCTED | 3 ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, ++ mbedtls_x509_write_extensions( &c, ++ buf, ctx->extensions ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, ++ mbedtls_asn1_write_tag( &c, buf, ++ MBEDTLS_ASN1_CONSTRUCTED | ++ MBEDTLS_ASN1_SEQUENCE ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, ++ mbedtls_asn1_write_tag( &c, buf, ++ MBEDTLS_ASN1_CONTEXT_SPECIFIC | ++ MBEDTLS_ASN1_CONSTRUCTED | 3 ) ); + } + + /* + * SubjectPublicKeyInfo + */ +- MBEDTLS_ASN1_CHK_ADD( pub_len, mbedtls_pk_write_pubkey_der( ctx->subject_key, +- tmp_buf, c - tmp_buf ) ); ++ MBEDTLS_ASN1_CHK_ADD( pub_len, ++ mbedtls_pk_write_pubkey_der( ctx->subject_key, ++ buf, c - buf ) ); + c -= pub_len; + len += pub_len; + + /* + * Subject ::= Name + */ +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c, tmp_buf, ctx->subject ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, ++ mbedtls_x509_write_names( &c, buf, ++ ctx->subject ) ); + + /* + * Validity ::= SEQUENCE { +@@ -371,32 +380,39 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, + */ + sub_len = 0; + +- MBEDTLS_ASN1_CHK_ADD( sub_len, x509_write_time( &c, tmp_buf, ctx->not_after, +- MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); ++ MBEDTLS_ASN1_CHK_ADD( sub_len, ++ x509_write_time( &c, buf, ctx->not_after, ++ MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); + +- MBEDTLS_ASN1_CHK_ADD( sub_len, x509_write_time( &c, tmp_buf, ctx->not_before, +- MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); ++ MBEDTLS_ASN1_CHK_ADD( sub_len, ++ x509_write_time( &c, buf, ctx->not_before, ++ MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); + + len += sub_len; +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, sub_len ) ); +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED | +- MBEDTLS_ASN1_SEQUENCE ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, sub_len ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, ++ mbedtls_asn1_write_tag( &c, buf, ++ MBEDTLS_ASN1_CONSTRUCTED | ++ MBEDTLS_ASN1_SEQUENCE ) ); + + /* + * Issuer ::= Name + */ +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c, tmp_buf, ctx->issuer ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c, buf, ++ ctx->issuer ) ); + + /* + * Signature ::= AlgorithmIdentifier + */ +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_algorithm_identifier( &c, tmp_buf, +- sig_oid, strlen( sig_oid ), 0 ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, ++ mbedtls_asn1_write_algorithm_identifier( &c, buf, ++ sig_oid, strlen( sig_oid ), 0 ) ); + + /* + * Serial ::= INTEGER + */ +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_mpi( &c, tmp_buf, &ctx->serial ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_mpi( &c, buf, ++ &ctx->serial ) ); + + /* + * Version ::= INTEGER { v1(0), v2(1), v3(2) } +@@ -406,48 +422,67 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, + if( ctx->version != MBEDTLS_X509_CRT_VERSION_1 ) + { + sub_len = 0; +- MBEDTLS_ASN1_CHK_ADD( sub_len, mbedtls_asn1_write_int( &c, tmp_buf, ctx->version ) ); ++ MBEDTLS_ASN1_CHK_ADD( sub_len, ++ mbedtls_asn1_write_int( &c, buf, ctx->version ) ); + len += sub_len; +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, sub_len ) ); +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | +- MBEDTLS_ASN1_CONSTRUCTED | 0 ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, ++ mbedtls_asn1_write_len( &c, buf, sub_len ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, ++ mbedtls_asn1_write_tag( &c, buf, ++ MBEDTLS_ASN1_CONTEXT_SPECIFIC | ++ MBEDTLS_ASN1_CONSTRUCTED | 0 ) ); + } + +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) ); +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED | +- MBEDTLS_ASN1_SEQUENCE ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, ++ mbedtls_asn1_write_tag( &c, buf, MBEDTLS_ASN1_CONSTRUCTED | ++ MBEDTLS_ASN1_SEQUENCE ) ); + + /* + * Make signature + */ ++ ++ /* Compute hash of CRT. */ + if( ( ret = mbedtls_md( mbedtls_md_info_from_type( ctx->md_alg ), c, + len, hash ) ) != 0 ) + { + return( ret ); + } + +- if( ( ret = mbedtls_pk_sign( ctx->issuer_key, ctx->md_alg, hash, 0, sig, &sig_len, +- f_rng, p_rng ) ) != 0 ) ++ if( ( ret = mbedtls_pk_sign( ctx->issuer_key, ctx->md_alg, ++ hash, 0, sig, &sig_len, ++ f_rng, p_rng ) ) != 0 ) + { + return( ret ); + } + +- /* +- * Write data to output buffer +- */ ++ /* Move CRT to the front of the buffer to have space ++ * for the signature. */ ++ memmove( buf, c, len ); ++ c = buf + len; ++ ++ /* Add signature at the end of the buffer, ++ * making sure that it doesn't underflow ++ * into the CRT buffer. */ + c2 = buf + size; +- MBEDTLS_ASN1_CHK_ADD( sig_and_oid_len, mbedtls_x509_write_sig( &c2, buf, ++ MBEDTLS_ASN1_CHK_ADD( sig_and_oid_len, mbedtls_x509_write_sig( &c2, c, + sig_oid, sig_oid_len, sig, sig_len ) ); + +- if( len > (size_t)( c2 - buf ) ) +- return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); ++ /* ++ * Memory layout after this step: ++ * ++ * buf c=buf+len c2 buf+size ++ * [CRT0,...,CRTn, UNUSED, ..., UNUSED, SIG0, ..., SIGm] ++ */ + +- c2 -= len; +- memcpy( c2, c, len ); ++ /* Move raw CRT to just before the signature. */ ++ c = c2 - len; ++ memmove( c, buf, len ); + + len += sig_and_oid_len; +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c2, buf, len ) ); +- MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c2, buf, MBEDTLS_ASN1_CONSTRUCTED | ++ MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); ++ MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, buf, ++ MBEDTLS_ASN1_CONSTRUCTED | + MBEDTLS_ASN1_SEQUENCE ) ); + + return( (int) len ); +@@ -457,23 +492,23 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, + #define PEM_END_CRT "-----END CERTIFICATE-----\n" + + #if defined(MBEDTLS_PEM_WRITE_C) +-int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *crt, unsigned char *buf, size_t size, +- int (*f_rng)(void *, unsigned char *, size_t), +- void *p_rng ) ++int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *crt, ++ unsigned char *buf, size_t size, ++ int (*f_rng)(void *, unsigned char *, size_t), ++ void *p_rng ) + { + int ret; +- unsigned char output_buf[4096]; +- size_t olen = 0; ++ size_t olen; + +- if( ( ret = mbedtls_x509write_crt_der( crt, output_buf, sizeof(output_buf), ++ if( ( ret = mbedtls_x509write_crt_der( crt, buf, size, + f_rng, p_rng ) ) < 0 ) + { + return( ret ); + } + + if( ( ret = mbedtls_pem_write_buffer( PEM_BEGIN_CRT, PEM_END_CRT, +- output_buf + sizeof(output_buf) - ret, +- ret, buf, size, &olen ) ) != 0 ) ++ buf + size - ret, ret, ++ buf, size, &olen ) ) != 0 ) + { + return( ret ); + } +-- +2.17.1 diff --git a/3rdparty/mbedtls/README.md b/3rdparty/mbedtls/README.md new file mode 100644 index 0000000000..659a570819 --- /dev/null +++ b/3rdparty/mbedtls/README.md @@ -0,0 +1,21 @@ +mbedTLS: +======== + +This directory contains the **mbedTLS** crypto library for enclaves. +The `./mbedtls` subdirectory contains a clone of the sources downloaded +from https://tls.mbed.org/download-archive. + +The version of mbedTLS currently in use is reflected in `update.make`. + +The enclave version of mbedTLS builds the cloned sources with the following +changes: + +- It uses a custom, scoped-down `config.h` defined in this folder. + +- It compiles in `mbedtls_hardware_poll.c` extension to provide the custom + entropy implementation mbedTLS libraries to avoid a circular dependency + with the Open Enclave core runtime. + +- It patches `mbedtls/library/x509write_crt.c` with + `0001-Patch-x509write_crt.c-for-attestedTLS.patch` to add support for writing + certificates that support using TLS with enclave attestation for auth. diff --git a/3rdparty/mbedtls/mbedtls/library/x509write_crt.c b/3rdparty/mbedtls/mbedtls/library/x509write_crt.c index 4cdb941a10..64b3d2c2fb 100644 --- a/3rdparty/mbedtls/mbedtls/library/x509write_crt.c +++ b/3rdparty/mbedtls/mbedtls/library/x509write_crt.c @@ -329,9 +329,10 @@ static int x509_write_time( unsigned char **p, unsigned char *start, return( (int) len ); } -int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, size_t size, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng ) +int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, + unsigned char *buf, size_t size, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { int ret; const char *sig_oid; @@ -339,15 +340,14 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, unsigned char *c, *c2; unsigned char hash[64]; unsigned char sig[MBEDTLS_MPI_MAX_SIZE]; - unsigned char tmp_buf[2048]; size_t sub_len = 0, pub_len = 0, sig_and_oid_len = 0, sig_len; size_t len = 0; mbedtls_pk_type_t pk_alg; /* - * Prepare data to be signed in tmp_buf + * Prepare data to be signed at the end of the target buffer */ - c = tmp_buf + sizeof( tmp_buf ); + c = buf + size; /* Signature algorithm needed in TBS, and later for actual signature */ @@ -373,27 +373,36 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, /* Only for v3 */ if( ctx->version == MBEDTLS_X509_CRT_VERSION_3 ) { - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_extensions( &c, tmp_buf, ctx->extensions ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SEQUENCE ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | - MBEDTLS_ASN1_CONSTRUCTED | 3 ) ); + MBEDTLS_ASN1_CHK_ADD( len, + mbedtls_x509_write_extensions( &c, + buf, ctx->extensions ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); + MBEDTLS_ASN1_CHK_ADD( len, + mbedtls_asn1_write_tag( &c, buf, + MBEDTLS_ASN1_CONSTRUCTED | + MBEDTLS_ASN1_SEQUENCE ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); + MBEDTLS_ASN1_CHK_ADD( len, + mbedtls_asn1_write_tag( &c, buf, + MBEDTLS_ASN1_CONTEXT_SPECIFIC | + MBEDTLS_ASN1_CONSTRUCTED | 3 ) ); } /* * SubjectPublicKeyInfo */ - MBEDTLS_ASN1_CHK_ADD( pub_len, mbedtls_pk_write_pubkey_der( ctx->subject_key, - tmp_buf, c - tmp_buf ) ); + MBEDTLS_ASN1_CHK_ADD( pub_len, + mbedtls_pk_write_pubkey_der( ctx->subject_key, + buf, c - buf ) ); c -= pub_len; len += pub_len; /* * Subject ::= Name */ - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c, tmp_buf, ctx->subject ) ); + MBEDTLS_ASN1_CHK_ADD( len, + mbedtls_x509_write_names( &c, buf, + ctx->subject ) ); /* * Validity ::= SEQUENCE { @@ -402,32 +411,39 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, */ sub_len = 0; - MBEDTLS_ASN1_CHK_ADD( sub_len, x509_write_time( &c, tmp_buf, ctx->not_after, - MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); + MBEDTLS_ASN1_CHK_ADD( sub_len, + x509_write_time( &c, buf, ctx->not_after, + MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); - MBEDTLS_ASN1_CHK_ADD( sub_len, x509_write_time( &c, tmp_buf, ctx->not_before, - MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); + MBEDTLS_ASN1_CHK_ADD( sub_len, + x509_write_time( &c, buf, ctx->not_before, + MBEDTLS_X509_RFC5280_UTC_TIME_LEN ) ); len += sub_len; - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, sub_len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SEQUENCE ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, sub_len ) ); + MBEDTLS_ASN1_CHK_ADD( len, + mbedtls_asn1_write_tag( &c, buf, + MBEDTLS_ASN1_CONSTRUCTED | + MBEDTLS_ASN1_SEQUENCE ) ); /* * Issuer ::= Name */ - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c, tmp_buf, ctx->issuer ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_x509_write_names( &c, buf, + ctx->issuer ) ); /* * Signature ::= AlgorithmIdentifier */ - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_algorithm_identifier( &c, tmp_buf, - sig_oid, strlen( sig_oid ), 0 ) ); + MBEDTLS_ASN1_CHK_ADD( len, + mbedtls_asn1_write_algorithm_identifier( &c, buf, + sig_oid, strlen( sig_oid ), 0 ) ); /* * Serial ::= INTEGER */ - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_mpi( &c, tmp_buf, &ctx->serial ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_mpi( &c, buf, + &ctx->serial ) ); /* * Version ::= INTEGER { v1(0), v2(1), v3(2) } @@ -437,48 +453,67 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, if( ctx->version != MBEDTLS_X509_CRT_VERSION_1 ) { sub_len = 0; - MBEDTLS_ASN1_CHK_ADD( sub_len, mbedtls_asn1_write_int( &c, tmp_buf, ctx->version ) ); + MBEDTLS_ASN1_CHK_ADD( sub_len, + mbedtls_asn1_write_int( &c, buf, ctx->version ) ); len += sub_len; - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, sub_len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONTEXT_SPECIFIC | - MBEDTLS_ASN1_CONSTRUCTED | 0 ) ); + MBEDTLS_ASN1_CHK_ADD( len, + mbedtls_asn1_write_len( &c, buf, sub_len ) ); + MBEDTLS_ASN1_CHK_ADD( len, + mbedtls_asn1_write_tag( &c, buf, + MBEDTLS_ASN1_CONTEXT_SPECIFIC | + MBEDTLS_ASN1_CONSTRUCTED | 0 ) ); } - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, tmp_buf, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, tmp_buf, MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SEQUENCE ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); + MBEDTLS_ASN1_CHK_ADD( len, + mbedtls_asn1_write_tag( &c, buf, MBEDTLS_ASN1_CONSTRUCTED | + MBEDTLS_ASN1_SEQUENCE ) ); /* * Make signature */ + + /* Compute hash of CRT. */ if( ( ret = mbedtls_md( mbedtls_md_info_from_type( ctx->md_alg ), c, len, hash ) ) != 0 ) { return( ret ); } - if( ( ret = mbedtls_pk_sign( ctx->issuer_key, ctx->md_alg, hash, 0, sig, &sig_len, - f_rng, p_rng ) ) != 0 ) + if( ( ret = mbedtls_pk_sign( ctx->issuer_key, ctx->md_alg, + hash, 0, sig, &sig_len, + f_rng, p_rng ) ) != 0 ) { return( ret ); } - /* - * Write data to output buffer - */ + /* Move CRT to the front of the buffer to have space + * for the signature. */ + memmove( buf, c, len ); + c = buf + len; + + /* Add signature at the end of the buffer, + * making sure that it doesn't underflow + * into the CRT buffer. */ c2 = buf + size; - MBEDTLS_ASN1_CHK_ADD( sig_and_oid_len, mbedtls_x509_write_sig( &c2, buf, + MBEDTLS_ASN1_CHK_ADD( sig_and_oid_len, mbedtls_x509_write_sig( &c2, c, sig_oid, sig_oid_len, sig, sig_len ) ); - if( len > (size_t)( c2 - buf ) ) - return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + /* + * Memory layout after this step: + * + * buf c=buf+len c2 buf+size + * [CRT0,...,CRTn, UNUSED, ..., UNUSED, SIG0, ..., SIGm] + */ - c2 -= len; - memcpy( c2, c, len ); + /* Move raw CRT to just before the signature. */ + c = c2 - len; + memmove( c, buf, len ); len += sig_and_oid_len; - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c2, buf, len ) ); - MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c2, buf, MBEDTLS_ASN1_CONSTRUCTED | + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, buf, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ); return( (int) len ); @@ -488,23 +523,23 @@ int mbedtls_x509write_crt_der( mbedtls_x509write_cert *ctx, unsigned char *buf, #define PEM_END_CRT "-----END CERTIFICATE-----\n" #if defined(MBEDTLS_PEM_WRITE_C) -int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *crt, unsigned char *buf, size_t size, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng ) +int mbedtls_x509write_crt_pem( mbedtls_x509write_cert *crt, + unsigned char *buf, size_t size, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { int ret; - unsigned char output_buf[4096]; - size_t olen = 0; + size_t olen; - if( ( ret = mbedtls_x509write_crt_der( crt, output_buf, sizeof(output_buf), + if( ( ret = mbedtls_x509write_crt_der( crt, buf, size, f_rng, p_rng ) ) < 0 ) { return( ret ); } if( ( ret = mbedtls_pem_write_buffer( PEM_BEGIN_CRT, PEM_END_CRT, - output_buf + sizeof(output_buf) - ret, - ret, buf, size, &olen ) ) != 0 ) + buf + size - ret, ret, + buf, size, &olen ) ) != 0 ) { return( ret ); } diff --git a/3rdparty/mbedtls/update.make b/3rdparty/mbedtls/update.make index bdd96f6892..4b5c353837 100755 --- a/3rdparty/mbedtls/update.make +++ b/3rdparty/mbedtls/update.make @@ -4,7 +4,7 @@ # Licensed under the MIT License. # mbedTLS library definitions -VERSION=2.7.9 +VERSION=2.7.11 BASE=mbedtls-$(VERSION) PKG=$(BASE)-apache.tgz diff --git a/CHANGELOG.md b/CHANGELOG.md index 99abbf50e9..2e7adaa0ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Transferred repository from [microsoft/openenclave](https://github.com/microsoft/openenclave) to [openenclave/openenclave](https://github.com/openenclave/openenclave). - Change debugging contract for oegdb. Enclaves and hosts built prior to this release cannot be debugged with this version of oegdb and vice versa. - Update LLVM libcxx to version 8.0.0. +- Update mbedTLS to version 2.7.11. [v0.6.0] - 2019-06-29 --------------------- diff --git a/scripts/.check-license.ignore b/scripts/.check-license.ignore index 4edcbbb6a4..90623840c7 100644 --- a/scripts/.check-license.ignore +++ b/scripts/.check-license.ignore @@ -6,6 +6,7 @@ .*\.html$ .*\.json$ .*\.md$ +.*\.patch$ .*\.pdf$ .*\.pem$ .*\.png$ From bbbb68aea20befdd8e152b58648429c17e2a4526 Mon Sep 17 00:00:00 2001 From: Radhika Jandhyala Date: Mon, 26 Aug 2019 11:03:00 -0700 Subject: [PATCH 010/420] Update docs for Windows Consistent formatting More formatting Add todo: Provide link for 2.2 PSW install Address comments and remove instructions for SGX1 without FLC Remove Windows Server 2016 More cleanup More cleanup Change prereqs to include VS build tools instead or VS itself Specify workload while installing build tools Fix typo Address comments Fix docs Fix docs Fix PSW 2.3 to 2.4 Add issue #for EnclaveCommonAPI Add SGX1 documents Add SGX1 documentation --- .../libcxx/libcxx/utils/libcxx/test/config.py | 2 +- .../Contributors/SGX1FLCGettingStarted.md | 7 +- .../Contributors/SGX1GettingStarted.md | 4 +- .../Contributors/SimulatorGettingStarted.md | 6 +- .../WindowsManualInstallPrereqs.md | 83 +++++++++++ .../WindowsManualSGX1FLCDCAPPrereqs.md | 53 +++++++ .../Contributors/WindowsManualSGX1Prereqs.md | 25 ++++ .../WindowsSGX1FLCGettingStarted.md | 131 ++++++++++++++++++ .../Contributors/WindowsSGX1GettingStarted.md | 118 ++++++++++++++++ .../Contributors/building_oe_sdk.md | 18 +-- scripts/test-build-config | 14 +- 11 files changed, 437 insertions(+), 24 deletions(-) create mode 100644 docs/GettingStartedDocs/Contributors/WindowsManualInstallPrereqs.md create mode 100644 docs/GettingStartedDocs/Contributors/WindowsManualSGX1FLCDCAPPrereqs.md create mode 100644 docs/GettingStartedDocs/Contributors/WindowsManualSGX1Prereqs.md create mode 100644 docs/GettingStartedDocs/Contributors/WindowsSGX1FLCGettingStarted.md create mode 100644 docs/GettingStartedDocs/Contributors/WindowsSGX1GettingStarted.md diff --git a/3rdparty/libcxx/libcxx/utils/libcxx/test/config.py b/3rdparty/libcxx/libcxx/utils/libcxx/test/config.py index 1aa52ddbbd..228af73d49 100644 --- a/3rdparty/libcxx/libcxx/utils/libcxx/test/config.py +++ b/3rdparty/libcxx/libcxx/utils/libcxx/test/config.py @@ -420,7 +420,7 @@ def configure_features(self): # Insert the platform name into the available features as a lower case. self.config.available_features.add(target_platform) - # Simulator testing can take a really long time for some of these tests + # Simulation mode testing can take a really long time for some of these tests # so add a feature check so we can REQUIRES: long_tests in them self.long_tests = self.get_lit_bool('long_tests') if self.long_tests is None: diff --git a/docs/GettingStartedDocs/Contributors/SGX1FLCGettingStarted.md b/docs/GettingStartedDocs/Contributors/SGX1FLCGettingStarted.md index 16cc2b870e..cb13e60161 100644 --- a/docs/GettingStartedDocs/Contributors/SGX1FLCGettingStarted.md +++ b/docs/GettingStartedDocs/Contributors/SGX1FLCGettingStarted.md @@ -59,9 +59,6 @@ or cmake -G "Ninja" .. ninja ``` - -Open Enclave will support attestation workflows outside of Azure using DCAP in an upcoming release. - Refer to the [Advanced Build Information](AdvancedBuildInfo.md) documentation for further information. ## Run unittests @@ -96,9 +93,9 @@ Test project /home/youradminusername/openenclave/build 100% tests passed, 0 tests failed out of 123 Total Test time (real) = 83.61 sec -``` +```A clean pass of the above unit tests is an indication that your Open Enclave setup was successful. -A clean pass of the above unitests run is an indication that your Open Enclave setup was successful. You can start playing with the Open Enclave samples after following the instructions in the "Install" section below to configure samples for building, +You can start playing with the Open Enclave samples after following the instructions in the "Install" section below to configure samples for building, For more information refer to the [Advanced Test Info](AdvancedTestInfo.md) document. diff --git a/docs/GettingStartedDocs/Contributors/SGX1GettingStarted.md b/docs/GettingStartedDocs/Contributors/SGX1GettingStarted.md index 82a08909b4..abba31fa7b 100644 --- a/docs/GettingStartedDocs/Contributors/SGX1GettingStarted.md +++ b/docs/GettingStartedDocs/Contributors/SGX1GettingStarted.md @@ -102,7 +102,9 @@ Test project /home/youradminusername/openenclave/build Total Test time (real) = 83.61 sec ``` -A clean pass of the above unitests run is an indication that your Open Enclave setup was successful. You can start playing with the Open Enclave samples after following the instructions in the "Install" section below to configure samples for building, +A clean pass of the above unitests run is an indication that your Open Enclave setup was successful. + +You can start playing with the Open Enclave samples after following the instructions in the "Install" section below to configure samples for building, For more information refer to the [Advanced Test Info](AdvancedTestInfo.md) document. diff --git a/docs/GettingStartedDocs/Contributors/SimulatorGettingStarted.md b/docs/GettingStartedDocs/Contributors/SimulatorGettingStarted.md index dedf6ec797..01dd367ee5 100644 --- a/docs/GettingStartedDocs/Contributors/SimulatorGettingStarted.md +++ b/docs/GettingStartedDocs/Contributors/SimulatorGettingStarted.md @@ -1,4 +1,4 @@ -# Getting Started with Open Enclave in Simulator mode +# Getting Started with Open Enclave in Simulation mode ## Platform requirement @@ -98,7 +98,9 @@ Errors while running CTest Some of the tests are skipped (Not Run) by design because the current simulator is not fully featured yet. -A clean pass of the above unitests run is an indication that your Open Enclave setup was successful. You can start playing with those Open Enclave samples after following the instructions in the "Install" section below to configure samples for building, +A clean pass of the above unit tests is an indication that your Open Enclave setup was successful. + +You can start playing with those Open Enclave samples after following the instructions in the "Install" section below to configure samples for building, For more information refer to the [Advanced Test Info](AdvancedTestInfo.md) document. diff --git a/docs/GettingStartedDocs/Contributors/WindowsManualInstallPrereqs.md b/docs/GettingStartedDocs/Contributors/WindowsManualInstallPrereqs.md new file mode 100644 index 0000000000..02380313a1 --- /dev/null +++ b/docs/GettingStartedDocs/Contributors/WindowsManualInstallPrereqs.md @@ -0,0 +1,83 @@ + +# Manually Installing Open Enclave Prerequisites for Windows on a System which supports SGX + +## Platform requirements +- A system with support for SGX1 or SGX1 with Flexible Launch Control (FLC). + Note: To check if your system has support for SGX1 with or without FLC, please look [here](../SGXSupportLevel.md). + +- A version of Windows OS with native support for SGX features: + - For server: Windows Server 2016 + - For client: Windows 10 64-bit version 1709 or newer + - To check your Windows version, run `winver` on the command line. + +## Software prerequisites +- [Microsoft Visual Studio Build Tools 2017](https://aka.ms/vs/15/release/vs_buildtools.exe) +- [Git for Windows 64-bit](https://git-scm.com/download/win) +- [OCaml for Windows 64-bit](https://www.ocamlpro.com/pub/ocpwin/ocpwin-builds/ocpwin64/20160113/) +- [Clang/LLVM for Windows 64-bit](http://releases.llvm.org/7.0.1/LLVM-7.0.1-win64.exe) + +## Prerequisites specific to SGX support on your system +- For systems with support for SGX1 - [Intel's PSW 2.2](WindowsManualSGX1Prereqs.md) +- For systems with support for SGX1 + FLC - + [Intel's PSW 2.4, Intel's Data Center Attestation primitives and related dependencies](WindowsManualSGX1FLCDCAPPrereqs.md) + +## Microsoft Visual Studio Build Tools 2017 + +Install [Visual Studio Build Tools 2017](https://aka.ms/vs/15/release/vs_buildtools.exe). Choose the "Visual C++ build tools" workload. +Visual Studio Build Tools 2017's CMake support (ver 3.12 or above) is required for building the Open Enclave SDK. +Note that cmake in Visual Studio 2019 is not fully supported yet. +For more information about cmake support, refer to +https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/ + +## Git for Windows 64-bit + +Install Git and add Git's bash to the path. +Typically, Git's bash is located in C:\Program Files\Git\bin. +Currently the Open Enclave SDK build system uses bash scripts to configure +and build Linux-based 3rd-party libraries. + +Open a command prompt and ensure that bash is available in the path: +```cmd +C:\>where bash +C:\Program Files\Git\bin\bash.exe +``` + +Tools available in the Git bash environment are also used for test and sample +builds. For example, OpenSSL is used to generate test certificates, so it is +also useful to have the `Git\mingw64\bin` folder pathed. This can be checked +from the command prompt as well: + +```cmd +C:\>where openssl +C:\Program Files\Git\mingw64\bin\openssl.exe +``` + +## Clang + +Install Clang 7.0.1 and add the LLVM folder (typically C:\Program Files\LLVM\bin) +to the path. Open Enclave SDK uses clang to build the enclave binaries. + +Open up a command prompt and ensure that clang is available in the path: +```cmd +C:\> where clang +C:\Program Files\LLVM\bin\clang.exe +C:\> where llvm-ar +C:\Program Files\LLVM\bin\llvm-ar.exe +C:\> where ld.lld +C:\Program Files\LLVM\bin\ld.lld.exe +``` + +## OCaml + +Install [OCaml for Windows (64-bit)](https://www.ocamlpro.com/pub/ocpwin/ocpwin-builds/ocpwin64/20160113/). +Please download and install the [mingw64 exe for OCaml](https://www.ocamlpro.com/pub/ocpwin/ocpwin-builds/ocpwin64/20160113/ocpwin64-20160113-4.02.1+ocp1-mingw64.exe). + +[Alternate OCaml Web-site](https://fdopen.github.io/opam-repository-mingw/installation/) + +OCaml is used to build the oeedger8r tool as part of the OE SDK. + +Open up a command prompt and ensure that ocaml is available in the path: +```cmd +C:\> where ocaml +C:\Program Files\ocpwin64\4.02.1+ocp1-msvc64-20160113\bin\ocaml.exe +``` \ No newline at end of file diff --git a/docs/GettingStartedDocs/Contributors/WindowsManualSGX1FLCDCAPPrereqs.md b/docs/GettingStartedDocs/Contributors/WindowsManualSGX1FLCDCAPPrereqs.md new file mode 100644 index 0000000000..7513ca86f7 --- /dev/null +++ b/docs/GettingStartedDocs/Contributors/WindowsManualSGX1FLCDCAPPrereqs.md @@ -0,0 +1,53 @@ +# SGX1 with Flexible Launch Control (FLC) Prerequisites on Windows + +## [Intel Platform Software for Windows (PSW) v2.4](http://registrationcenter-download.intel.com/akdlm/irc_nas/15654/Intel%20SGX%20PSW%20for%20Windows%20v2.4.100.51291.exe) + +After unpacking the self-extracting ZIP executable, install the *PSW_EXE_RS2_and_before* version: +```cmd +C:\Intel SGX PSW for Windows v2.4.100.51291\PSW_EXE_RS2_and_before\Intel(R)_SGX_Windows_x64_PSW_2.4.100.51291.exe" +``` + +## [Azure DCAP client for Windows](https://github.com/Microsoft/Azure-DCAP-Client/tree/master/src/Windows) [optional] + +Note that this is optional since you can choose an alternate implementation of the DCAP client or create your own. +The Azure DCAP client for Windows is necessary if you would like to perform enclave attestation on a Azure Confidential Computing VM. it is available from [nuget.org](https://www.nuget.org/packages/Azure.DCAP.Windows/) and can be installed directly via: + +```cmd +nuget.exe install Azure.DCAP.Windows -ExcludeVersion -Version 0.0.2 -OutputDirectory C:\openenclave\prereqs\nuget +``` + +##### [Intel Data Center Attestation Primitives (DCAP) Libraries v1.2](http://registrationcenter-download.intel.com/akdlm/irc_nas/15650/Intel%20SGX%20DCAP%20for%20Windows%20v1.2.100.49925.exe) +After unpacking the self-extracting ZIP executable, you can refer to the *Intel SGX DCAP Windows SW Installation Guide.pdf* +for more details on how to install the contents of the package. + +The following summary will assume that the contents were extracted to `C:\Intel SGX DCAP for Windows v1.2.100.49925`: + +1. Unzip the required drivers from the extracted subfolders: + - `LC_driver_WinServer2016\Signed_1152921504628095185.zip` + - `DCAP_INF\WinServer2016\Signed_1152921504628099289.zip` + + The following instructions will assume that these have been unzipped into the `LC_driver` and `DCAP_INF` folders respectively. + +2. Allow the SGX Launch Configuration driver (LC_driver) to run: + - From an elevated command prompt: + ```cmd + reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\sgx_lc_msr\Parameters /v "SGX_Launch_Config_Optin" /t REG_DWORD /d 1 + reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\sgx_lc_msr\Parameters /v "SGX_Launch_Config_Optin" + ``` + - If the driver is already installed and running, the machine will need to be rebooted for the change to take effect. + +3. Install the drivers: + - `devcon.exe` from the [Windows Driver Kit for Windows 10](https://go.microsoft.com/fwlink/?linkid=2026156) + can be used to install the drivers from an elevated command prompt: + ```cmd + devcon.exe install LC_driver\drivers\b361e4d8-bc01-43fc-b8a6-8d101e659ed1\sgx_base_dev.inf root\SgxLCDevice + devcon.exe install DCAP_INF\drivers\226fdf07-49d3-46aa-a0ce-f21b6d4a05cf\sgx_dcap_dev.inf root\SgxLCDevice_DCAP + ``` + - Note that `devcon.exe` is usually installed to `C:\Program Files (x86)\Windows Kits\10\tools\x64` which is not in the PATH environment variable by default. +4. Install the DCAP nuget packages: + - The standalone `nuget.exe` [CLI tool](https://dist.nuget.org/win-x86-commandline/latest/nuget.exe) can be used to do this from the command prompt: + ```cmd + nuget.exe install DCAP_Components -ExcludeVersion -Source "C:\Intel SGX DCAP for Windows v1.2.100.49925\nuget" -OutputDirectory C\openenclave\prereqs\nuget + nuget.exe install EnclaveCommonAPI -ExcludeVersion -Source "C:\Intel SGX DCAP for Windows v1.2.100.49925\nuget" -OutputDirectory C:\openenclave\prereqs\nuget + ``` + - *Note:* EnclaveCommonAPI should be installed as the *very last* nuget package as a temporary workaround for a dependency issue. Please see issue #2170, for more details. \ No newline at end of file diff --git a/docs/GettingStartedDocs/Contributors/WindowsManualSGX1Prereqs.md b/docs/GettingStartedDocs/Contributors/WindowsManualSGX1Prereqs.md new file mode 100644 index 0000000000..8783f6d456 --- /dev/null +++ b/docs/GettingStartedDocs/Contributors/WindowsManualSGX1Prereqs.md @@ -0,0 +1,25 @@ +# SGX1 Prerequisites on Windows + +## Intel SGX Platform Software for Windows (PSW) v2.2 + +The PSW should be installed automatically on Windows 10 version 1709 or newer, or on a Windows Server 2016 image for an Azure ConfidentialCompute VM. You can verify that is the case on the command line as follows: + +```cmd +sc query aesmservice +``` + +The state of the service should be "running" (4). Follow Intel's documentation for troubleshooting. + +If you have a Windows Server 2016 image that does not have Intel PSW 2.2, please get the PSW 2.2 [zipped executable](https://oejenkins.blob.core.windows.net/oejenkins/intel_sgx_win_2.2.100.47975_PV.zip). + +After downloading and extracting the zipped executable, run the executable to install PSW 2.2. + +```cmd +C:\Intel SGX PSW for Windows v2.2.100.48339.exe\PSW_EXE_RS2_and_before\Intel(R)Intel(R)_SGX_Windows_x64_PSW_2.2.100.48339.exe +``` + +Start the AESM service by running the following command from Powershell. + +```powershell +Start-Service "AESMService" +``` \ No newline at end of file diff --git a/docs/GettingStartedDocs/Contributors/WindowsSGX1FLCGettingStarted.md b/docs/GettingStartedDocs/Contributors/WindowsSGX1FLCGettingStarted.md new file mode 100644 index 0000000000..b58a2d8317 --- /dev/null +++ b/docs/GettingStartedDocs/Contributors/WindowsSGX1FLCGettingStarted.md @@ -0,0 +1,131 @@ +# Getting Started with Open Enclave on Windows for systems with support for SGX1 with Flexible Launch Control(FLC) + +## Platform requirements + +IntelĀ® X86-64bit architecture with SGX1 and Flexible Launch Control (FLC) support. (e.g. Intel Coffee Lake CPU) + +Note: To check if your system has support for SGX1 with FLC, please look [here](../SGXSupportLevel.md) + +A version of Windows OS with native support for SGX features: +- For server: Windows Server 2016 +- For client: Windows 10 64-bit version 1709 or newer +- To check your Windows version, run `winver` on the command line. + +## Install Git and Clone the Open Enclave SDK repo + +Download and install Git for Windows from [here](https://git-scm.com/download/win) + +Clone the Open Enclave SDK + +```powershell +git clone https://github.com/openenclave/openenclave.git +``` + +This creates a source tree under the directory called openenclave. + +## Install project prerequisites + +First, change directory into the openenclave repository: + +```powershell +cd openenclave +``` + +Run the following from powershell to deploy all the prerequisites for building Open Enclave (including Intel's DCAP primitives and Azure's DCAP library). + +```scripts/install-windows-prereqs.ps1``` + +To install the prerequisites along with the Azure Data Center Attestation Primitives (DCAP) Client, use the below command. The Azure DCAP Client is necessary to perform attestation on an Azure Confidential Computing VM. + +```powershell +cd scripts +.\install-windows-prereqs.ps1 -InstallPath YOUR_WORKSPACE_PATH_HERE -LaunchConfiguration SGX1FLC -DCAPClientType Azure +``` +If you would like to skip the installation of the Azure DCAP Client, use the command below. + +```powershell +cd scripts +.\install-windows-prereqs.ps1 -InstallPath YOUR_WORKSPACE_PATH_HERE -LaunchConfiguration SGX1FLC -DCAPClientType None +``` +If there is another DCAP Client type that you would like to install, you are welcome to submit a pull request to add support for that DCAP Client. + +As an example, if you cloned the Open Enclave SDK repo into C:\openenclave and want to install the Azure DCAP Client, you would run the following command. + +```powershell +cd scripts +.\install-windows-prereqs.ps1 -InstallPath C:\openenclave -LaunchConfiguration SGX1FLC -DCAPClientType Azure +``` + +If you prefer to manually install prerequisites, please refer to this [document](WindowsManualInstallPrereqs.md). + +## Build + +Launch the [x64 Native Tools Command Prompt for VS 2017]( +https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs) +Normally this is accessible under the `Visual Studio 2017` folder in the Start Menu. +To build, first create a build directory ("build" in the example below) and change directory into it. +Then run `cmake` to configure the build and generate the Makefiles, and then build by running `ninja`. + +To build debug enclaves +```cmd +cd C:\openenclave +mkdir build\x64-Debug +cd build\x64-Debug +cmake -G Ninja -DBUILD_ENCLAVES=1 -DUSE_LIBSGX=1 ..\.. +ninja +``` + +Similarly, to build release enclaves +```cmd +cd C:\openenclave +mkdir build\x64-Release +cd build\x64-Release +cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_ENCLAVES=1 ../.. +ninja +``` + +## Run unittests + +After building, run all unit test cases using `ctest` to confirm the SDK is built and working as expected. + +Run the following command from the build directory to run tests(In this example, we are testing the debug build): + +```cmd +ctest +``` + +You will see test logs similar to the following: + +```cmd + Test project C:/openenclave/build/x64-Debug + Start 1: tests/lockless_queue + 1/107 Test #1: tests/lockless_queue .................................. Passed 3.49 sec + Start 2: tests/mem + 2/107 Test #2: tests/mem ............................................. Passed 0.01 sec + ... + .... +100% tests passed, 0 tests failed out of 107 +``` + +A clean pass of the above unit tests run is an indication that your Open Enclave setup was successful. + +You can start playing with the Open Enclave samples after following the instructions in the "Install" section below to configure samples for building, + +For more information refer to the [Advanced Test Info](AdvancedTestInfo.md) document. + +## Installing the SDK on local machine + +To install the SDK on the local machine use the following: + +```cmd +cd build\x64-Debug +ninja install +``` + +This installs the SDK in c:\opt\openenclave. + +## Known Issues + +Samples have not yet been ported to Windows. + +Not all tests currently run on Windows. See tests\MakeLists.txt for a list of supported tests. diff --git a/docs/GettingStartedDocs/Contributors/WindowsSGX1GettingStarted.md b/docs/GettingStartedDocs/Contributors/WindowsSGX1GettingStarted.md new file mode 100644 index 0000000000..9fdce89559 --- /dev/null +++ b/docs/GettingStartedDocs/Contributors/WindowsSGX1GettingStarted.md @@ -0,0 +1,118 @@ +# Getting Started with Open Enclave on Windows for systems with support for SGX1 + +## Platform requirements + +IntelĀ® X86-64bit architecture with SGX1 + +A version of Windows OS with native support for SGX features: +- For server: Windows Server 2016 +- For client: Windows 10 64-bit version 1709 or newer +- To check your Windows version, run winver on the command line. + +## Install Git and Clone the Open Enclave SDK repo + +Download and install Git for Windows from [here](https://git-scm.com/download/win) + +Clone the Open Enclave SDK + +```powershell +git clone https://github.com/openenclave/openenclave.git +``` + +This creates a source tree under the directory called openenclave. + +## Install project prerequisites + +First, change directory into the openenclave repository: + +```powershell +cd openenclave +``` + +To deploy all the prerequisities for building Open Enclave, you can run the following from powershell. Note that the Data Center Attestation Primitives Client is not used for attestation on systems which have support for SGX1 without support for Flexible Launch Control (FLC). + +```powershell +cd scripts +.\install-windows-prereqs.ps1 -InstallPath PATH_TO_OE_REPO -LaunchConfiguration SGX1 -DCAPClientType None +``` + +As an example, if you cloned Open Enclave SDK repo into C:\openenclave, you would run the following: + +```powershell +cd scripts +.\install-windows-prereqs.ps1 -InstallPath C:\openenclave -LaunchConfiguration SGX1 -DCAPClientType None +``` + +If you prefer to manually install prerequisites, please refer to this [document](WindowsManualInstallPrereqs.md). + +## Building on Windows using Developer Command Prompt + +1. Launch the [x64 Native Tools Command Prompt for VS 2017]( +https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs) +Normally this is accessible under the `Visual Studio 2017` folder in the Start Menu. + +2. At the x64 Native Tools command prompt, use cmake and ninja to build the debug version: + + ```cmd + cd C:\openenclave + mkdir build\x64-Debug + cd build\x64-Debug + cmake -G Ninja -DBUILD_ENCLAVES=1 ..\. + ninja + ``` + + Similarly, build the release version with: + + ```cmd + cd C:\openenclave + mkdir build\x64-Release + cd build\x64-Release + cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_ENCLAVES=1 ..\.. + ninja + ``` + +## Run unittests + +After building, run all unit test cases using `ctest` to confirm the SDK is built and working as expected. In this example, we are testing the debug build. + +Run the following command from the build directory: + +```cmd +ctest +``` + +You will see test logs similar to the following: + +```cmd + Test project C:/openenclave/build/x64-Debug + Start 1: tests/lockless_queue + 1/107 Test #1: tests/lockless_queue .................................. Passed 3.49 sec + Start 2: tests/mem + 2/107 Test #2: tests/mem ............................................. Passed 0.01 sec + ... + .... +100% tests passed, 0 tests failed out of 107 +``` + +A clean pass of the above unit tests is an indication that your Open Enclave setup was successful. + +You can start playing with the Open Enclave samples after following the instructions in the "Install" section below to configure samples for building, + +For more information refer to the [Advanced Test Info](AdvancedTestInfo.md) document. + +## Installing the SDK on local machine + +To install the SDK on the local machine use the following: + +```cmd +cd build\x64-Debug +ninja install +``` + +This installs the SDK in c:\opt\openenclave. + +## Known Issues + +Samples have not yet been ported to Windows. + +Not all tests currently run on Windows. See tests\MakeLists.txt for a list of supported tests. diff --git a/docs/GettingStartedDocs/Contributors/building_oe_sdk.md b/docs/GettingStartedDocs/Contributors/building_oe_sdk.md index ecbe134884..5058caf4dc 100644 --- a/docs/GettingStartedDocs/Contributors/building_oe_sdk.md +++ b/docs/GettingStartedDocs/Contributors/building_oe_sdk.md @@ -21,7 +21,7 @@ Please refer to the following [documentation](/docs/GettingStartedDocs/SGXSuppor - `SGX1+FLC`: In this mode, the Open Enclave SDK takes advantage of the Flexible Launch Control mode for better managing architectural enclaves. - - `Simulator`: Open Enclave comes with a SGX software simulator that simulates a subset of + - `Simulation`: Open Enclave comes with a SGX software simulation mode that simulates a subset of the SGX feature set. This simulator enables the Open Enclave SDK to run on systems without actual SGX hardware support. @@ -31,10 +31,10 @@ Please refer to the following [documentation](/docs/GettingStartedDocs/SGXSuppor |:---------------------------|:-----------------------------------:| | SGX1+FLC | SGX1+FLC | | SGX1 | SGX1 or SGX1+FLC | - | Simulator | Any level | + | Simulation | Any level | - On Linux, if your target system does not have any SGX hardware support, you may want to choose "Simulator" mode. - On Windows, Open Enclave SDK does not support "Simulator" mode. + On Linux, if your target system does not have any SGX hardware support, you may want to choose simulation. + On Windows, Open Enclave SDK does not support simulation mode. #### 3. Build, install and run @@ -42,12 +42,14 @@ Please refer to the following [documentation](/docs/GettingStartedDocs/SGXSuppor The links below contain instructions on how to set up Open Enclave SDK environment for a given mode. On Linux - - [Setup Open Enclave SDK for SGX1+FLC mode](SGX1FLCGettingStarted.md) - - [Setup Open Enclave SDK for SGX1 mode](SGX1GettingStarted.md) - - [Setup Open Enclave SDK for Simulator mode](SimulatorGettingStarted.md) + - [Setup Open Enclave SDK for SGX1+FLC](SGX1FLCGettingStarted.md) + - [Setup Open Enclave SDK for SGX1](SGX1GettingStarted.md) + - [Setup Open Enclave SDK for simulation mode](SimulatorGettingStarted.md) On Windows - - [Set up Open Enclave SDK](/docs/GettingStartedDocs/GettingStarted.Windows.md) + - [Set up Open Enclave SDK for SGX1+FLC](WindowsSGX1FLCGettingStarted.md) + - [Set up Open Enclave SDK for SGX1](WindowsSGX1GettingStarted.md) + - Simulation mode is not supported on Windows ## Samples diff --git a/scripts/test-build-config b/scripts/test-build-config index ff75176fd0..263143a823 100755 --- a/scripts/test-build-config +++ b/scripts/test-build-config @@ -6,9 +6,9 @@ ##==================================================================================== ## ## This script fires OE build and test for specified build-type, platform and -## simulator/hardware mode. +## simulation/hardware mode. ## Default run with no parameters builds with Debug build-type and for SGX1 -## platform and will test in Simulator mode. +## platform and will test in simulation. ## Run this from the root of the source tree as sudo. ## Please note that this script does not install any packages needed for build/test. ## Please install all packages necessary for your test before invoking this script. @@ -19,7 +19,7 @@ if [[ $1 == "-h" || $1 == "--help" ]]; then echo "Script to fire OE build and test with specified platform/build-type/test mode" echo " Usage: " echo " ./scripts/test-build-config" - echo " -d or --disable_sim to Disable Simulator Test Mode" + echo " -d or --disable_sim to Disable Simulation Test Mode" echo " -p SGX1FLC or -p=SGX1FLC to build for SGX1FLC platform" echo " -b Debug|RelWithDebInfo|Release or -b=Debug|RelWithDebInfo|Release" echo " -h or --help to Display usage and exit" @@ -28,14 +28,14 @@ if [[ $1 == "-h" || $1 == "--help" ]]; then echo " --enable_full_libcxx_tests to Enable libcxx tests" echo " --enable_full_libc_tests to Enable libc tests" echo " Default is to build for SGX1 platform, Debug Build type & test in" - echo " simulator mode" + echo " simulation" echo "" exit 0 fi # Default values for the arguments -# Disable Simulator test mode to run on SGX hardware -# Default test mode is Simulator, disable Simulator test mode with -d or --disable_sim +# Disable Simulation test mode to run on SGX hardware +# Default test mode is simulation, disable simulation test mode with -d or --disable_sim DISABLE_SIM=0 # Valid PLATFORM_MODE values are SGX1 or SGX1FLC PLATFORM_MODE="SGX1" @@ -156,7 +156,7 @@ if ! make; then exit 1 fi -# Finally run the tests in Simulator mode or on Hardware +# Finally run the tests in simulation or on Hardware if [[ ${DISABLE_SIM} -ne 1 ]]; then SIMULATION_MODE_TEXT="simulation" export OE_SIMULATION=1 From 3dbc8b6856d785b436e6ad437a04acd79d9ddb7a Mon Sep 17 00:00:00 2001 From: Radhika Jandhyala Date: Fri, 13 Sep 2019 11:57:44 -0700 Subject: [PATCH 011/420] Update manual instructions with VS2019 --- .../Contributors/SGX1FLCGettingStarted.md | 4 +-- .../Contributors/SGX1GettingStarted.md | 4 +-- .../WindowsManualInstallPrereqs.md | 34 +++++++++---------- .../WindowsManualSGX1FLCDCAPPrereqs.md | 2 +- .../Contributors/WindowsManualSGX1Prereqs.md | 2 +- .../WindowsSGX1FLCGettingStarted.md | 31 ++++++++--------- .../Contributors/WindowsSGX1GettingStarted.md | 20 ++++++----- .../Contributors/building_oe_sdk.md | 7 ++-- 8 files changed, 52 insertions(+), 52 deletions(-) diff --git a/docs/GettingStartedDocs/Contributors/SGX1FLCGettingStarted.md b/docs/GettingStartedDocs/Contributors/SGX1FLCGettingStarted.md index cb13e60161..8e5b1f21c4 100644 --- a/docs/GettingStartedDocs/Contributors/SGX1FLCGettingStarted.md +++ b/docs/GettingStartedDocs/Contributors/SGX1FLCGettingStarted.md @@ -61,7 +61,7 @@ ninja ``` Refer to the [Advanced Build Information](AdvancedBuildInfo.md) documentation for further information. -## Run unittests +## Run unit tests After building, run all unit test cases using `ctest` to confirm the SDK is built and working as expected. @@ -93,7 +93,7 @@ Test project /home/youradminusername/openenclave/build 100% tests passed, 0 tests failed out of 123 Total Test time (real) = 83.61 sec -```A clean pass of the above unit tests is an indication that your Open Enclave setup was successful. +A clean pass of the above unit tests is an indication that your Open Enclave setup was successful. You can start playing with the Open Enclave samples after following the instructions in the "Install" section below to configure samples for building, diff --git a/docs/GettingStartedDocs/Contributors/SGX1GettingStarted.md b/docs/GettingStartedDocs/Contributors/SGX1GettingStarted.md index abba31fa7b..f487189d9d 100644 --- a/docs/GettingStartedDocs/Contributors/SGX1GettingStarted.md +++ b/docs/GettingStartedDocs/Contributors/SGX1GettingStarted.md @@ -68,7 +68,7 @@ make Refer to the [Advanced Build Information](AdvancedBuildInfo.md) documentation for further information. -## Run unittests +## Run unit tests After building, run all unit test cases using `ctest` to confirm the SDK is built and working as expected. @@ -102,7 +102,7 @@ Test project /home/youradminusername/openenclave/build Total Test time (real) = 83.61 sec ``` -A clean pass of the above unitests run is an indication that your Open Enclave setup was successful. +A clean pass of the above unit tests is an indication that your Open Enclave setup was successful. You can start playing with the Open Enclave samples after following the instructions in the "Install" section below to configure samples for building, diff --git a/docs/GettingStartedDocs/Contributors/WindowsManualInstallPrereqs.md b/docs/GettingStartedDocs/Contributors/WindowsManualInstallPrereqs.md index 02380313a1..6937210d5e 100644 --- a/docs/GettingStartedDocs/Contributors/WindowsManualInstallPrereqs.md +++ b/docs/GettingStartedDocs/Contributors/WindowsManualInstallPrereqs.md @@ -1,8 +1,8 @@ - # Manually Installing Open Enclave Prerequisites for Windows on a System which supports SGX ## Platform requirements - A system with support for SGX1 or SGX1 with Flexible Launch Control (FLC). + Note: To check if your system has support for SGX1 with or without FLC, please look [here](../SGXSupportLevel.md). - A version of Windows OS with native support for SGX features: @@ -11,32 +11,29 @@ - To check your Windows version, run `winver` on the command line. ## Software prerequisites -- [Microsoft Visual Studio Build Tools 2017](https://aka.ms/vs/15/release/vs_buildtools.exe) +- [Microsoft Visual Studio Build Tools 2019](https://aka.ms/vs/15/release/vs_buildtools.exe) - [Git for Windows 64-bit](https://git-scm.com/download/win) - [OCaml for Windows 64-bit](https://www.ocamlpro.com/pub/ocpwin/ocpwin-builds/ocpwin64/20160113/) - [Clang/LLVM for Windows 64-bit](http://releases.llvm.org/7.0.1/LLVM-7.0.1-win64.exe) ## Prerequisites specific to SGX support on your system -- For systems with support for SGX1 - [Intel's PSW 2.2](WindowsManualSGX1Prereqs.md) -- For systems with support for SGX1 + FLC - - [Intel's PSW 2.4, Intel's Data Center Attestation primitives and related dependencies](WindowsManualSGX1FLCDCAPPrereqs.md) -## Microsoft Visual Studio Build Tools 2017 +For systems with support for SGX1 - [Intel's PSW 2.2](WindowsManualSGX1Prereqs.md) + +For systems with support for SGX1 + FLC - [Intel's PSW 2.4, Intel's Data Center Attestation Primitives and related dependencies](WindowsManualSGX1FLCDCAPPrereqs.md) -Install [Visual Studio Build Tools 2017](https://aka.ms/vs/15/release/vs_buildtools.exe). Choose the "Visual C++ build tools" workload. -Visual Studio Build Tools 2017's CMake support (ver 3.12 or above) is required for building the Open Enclave SDK. -Note that cmake in Visual Studio 2019 is not fully supported yet. -For more information about cmake support, refer to -https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/ +## Microsoft Visual Studio Build Tools 2019 +Install [Visual Studio Build Tools 2019](https://aka.ms/vs/16/release/vs_buildtools.exe). Choose the " C++ build tools" workload. Visual Studio Build Tools 2019has support for CMake Version 3.15 (CMake ver 3.12 or above is required for building Open Enclave SDK). For more information about CMake support, look [here](https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/). ## Git for Windows 64-bit -Install Git and add Git's bash to the path. -Typically, Git's bash is located in C:\Program Files\Git\bin. +Install Git and add Git Bash to the PATH environment variable. +Typically, Git Bash is located in `C:\Program Files\Git\bin`. Currently the Open Enclave SDK build system uses bash scripts to configure and build Linux-based 3rd-party libraries. -Open a command prompt and ensure that bash is available in the path: +Open a command prompt and ensure that Git Bash is added to PATH. + ```cmd C:\>where bash C:\Program Files\Git\bin\bash.exe @@ -44,7 +41,7 @@ C:\Program Files\Git\bin\bash.exe Tools available in the Git bash environment are also used for test and sample builds. For example, OpenSSL is used to generate test certificates, so it is -also useful to have the `Git\mingw64\bin` folder pathed. This can be checked +also useful to have the `Git\mingw64\bin` folder added to PATH. This can be checked from the command prompt as well: ```cmd @@ -55,9 +52,10 @@ C:\Program Files\Git\mingw64\bin\openssl.exe ## Clang Install Clang 7.0.1 and add the LLVM folder (typically C:\Program Files\LLVM\bin) -to the path. Open Enclave SDK uses clang to build the enclave binaries. +to PATH. Open Enclave SDK uses clang to build the enclave binaries. + +Open up a command prompt and ensure that clang is added to PATH. -Open up a command prompt and ensure that clang is available in the path: ```cmd C:\> where clang C:\Program Files\LLVM\bin\clang.exe @@ -76,7 +74,7 @@ Please download and install the [mingw64 exe for OCaml](https://www.ocamlpro.com OCaml is used to build the oeedger8r tool as part of the OE SDK. -Open up a command prompt and ensure that ocaml is available in the path: +Open up a command prompt and ensure that ocaml is added to PATH. ```cmd C:\> where ocaml C:\Program Files\ocpwin64\4.02.1+ocp1-msvc64-20160113\bin\ocaml.exe diff --git a/docs/GettingStartedDocs/Contributors/WindowsManualSGX1FLCDCAPPrereqs.md b/docs/GettingStartedDocs/Contributors/WindowsManualSGX1FLCDCAPPrereqs.md index 7513ca86f7..5a00c6da70 100644 --- a/docs/GettingStartedDocs/Contributors/WindowsManualSGX1FLCDCAPPrereqs.md +++ b/docs/GettingStartedDocs/Contributors/WindowsManualSGX1FLCDCAPPrereqs.md @@ -10,7 +10,7 @@ C:\Intel SGX PSW for Windows v2.4.100.51291\PSW_EXE_RS2_and_before\Intel(R)_SGX_ ## [Azure DCAP client for Windows](https://github.com/Microsoft/Azure-DCAP-Client/tree/master/src/Windows) [optional] Note that this is optional since you can choose an alternate implementation of the DCAP client or create your own. -The Azure DCAP client for Windows is necessary if you would like to perform enclave attestation on a Azure Confidential Computing VM. it is available from [nuget.org](https://www.nuget.org/packages/Azure.DCAP.Windows/) and can be installed directly via: +The Azure DCAP client for Windows is necessary if you would like to perform enclave attestation on a Azure Confidential Computing VM. It is available from [nuget.org](https://www.nuget.org/packages/Azure.DCAP.Windows/) and can be installed directly via: ```cmd nuget.exe install Azure.DCAP.Windows -ExcludeVersion -Version 0.0.2 -OutputDirectory C:\openenclave\prereqs\nuget diff --git a/docs/GettingStartedDocs/Contributors/WindowsManualSGX1Prereqs.md b/docs/GettingStartedDocs/Contributors/WindowsManualSGX1Prereqs.md index 8783f6d456..e9fb083fef 100644 --- a/docs/GettingStartedDocs/Contributors/WindowsManualSGX1Prereqs.md +++ b/docs/GettingStartedDocs/Contributors/WindowsManualSGX1Prereqs.md @@ -12,7 +12,7 @@ The state of the service should be "running" (4). Follow Intel's documentation f If you have a Windows Server 2016 image that does not have Intel PSW 2.2, please get the PSW 2.2 [zipped executable](https://oejenkins.blob.core.windows.net/oejenkins/intel_sgx_win_2.2.100.47975_PV.zip). -After downloading and extracting the zipped executable, run the executable to install PSW 2.2. +After downloading and extracting the zipped executable, run the executable to install PSW 2.2. ```cmd C:\Intel SGX PSW for Windows v2.2.100.48339.exe\PSW_EXE_RS2_and_before\Intel(R)Intel(R)_SGX_Windows_x64_PSW_2.2.100.48339.exe diff --git a/docs/GettingStartedDocs/Contributors/WindowsSGX1FLCGettingStarted.md b/docs/GettingStartedDocs/Contributors/WindowsSGX1FLCGettingStarted.md index b58a2d8317..5bd69b082e 100644 --- a/docs/GettingStartedDocs/Contributors/WindowsSGX1FLCGettingStarted.md +++ b/docs/GettingStartedDocs/Contributors/WindowsSGX1FLCGettingStarted.md @@ -4,7 +4,7 @@ IntelĀ® X86-64bit architecture with SGX1 and Flexible Launch Control (FLC) support. (e.g. Intel Coffee Lake CPU) -Note: To check if your system has support for SGX1 with FLC, please look [here](../SGXSupportLevel.md) +Note: To check if your system has support for SGX1 with FLC, please look [here](../SGXSupportLevel.md). A version of Windows OS with native support for SGX features: - For server: Windows Server 2016 @@ -13,15 +13,15 @@ A version of Windows OS with native support for SGX features: ## Install Git and Clone the Open Enclave SDK repo -Download and install Git for Windows from [here](https://git-scm.com/download/win) +- Download and install Git for Windows from [here](https://git-scm.com/download/win). -Clone the Open Enclave SDK +- Clone the Open Enclave SDK. -```powershell -git clone https://github.com/openenclave/openenclave.git -``` + ```powershell + git clone https://github.com/openenclave/openenclave.git + ``` -This creates a source tree under the directory called openenclave. + This creates a source tree under the directory called openenclave. ## Install project prerequisites @@ -31,23 +31,23 @@ First, change directory into the openenclave repository: cd openenclave ``` -Run the following from powershell to deploy all the prerequisites for building Open Enclave (including Intel's DCAP primitives and Azure's DCAP library). +Run the following from Powershell to deploy all the prerequisites for building Open Enclave ```scripts/install-windows-prereqs.ps1``` -To install the prerequisites along with the Azure Data Center Attestation Primitives (DCAP) Client, use the below command. The Azure DCAP Client is necessary to perform attestation on an Azure Confidential Computing VM. +To install the prerequisites along with the Azure DCAP Client, use the below command. The Azure DCAP Client is necessary to perform attestation on an Azure Confidential Computing VM. ```powershell cd scripts .\install-windows-prereqs.ps1 -InstallPath YOUR_WORKSPACE_PATH_HERE -LaunchConfiguration SGX1FLC -DCAPClientType Azure ``` + If you would like to skip the installation of the Azure DCAP Client, use the command below. ```powershell cd scripts .\install-windows-prereqs.ps1 -InstallPath YOUR_WORKSPACE_PATH_HERE -LaunchConfiguration SGX1FLC -DCAPClientType None ``` -If there is another DCAP Client type that you would like to install, you are welcome to submit a pull request to add support for that DCAP Client. As an example, if you cloned the Open Enclave SDK repo into C:\openenclave and want to install the Azure DCAP Client, you would run the following command. @@ -60,13 +60,12 @@ If you prefer to manually install prerequisites, please refer to this [document] ## Build -Launch the [x64 Native Tools Command Prompt for VS 2017]( +Launch the [x64 Native Tools Command Prompt for VS(2017 or 2019)]( https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs) -Normally this is accessible under the `Visual Studio 2017` folder in the Start Menu. To build, first create a build directory ("build" in the example below) and change directory into it. Then run `cmake` to configure the build and generate the Makefiles, and then build by running `ninja`. -To build debug enclaves +To build debug enclaves: ```cmd cd C:\openenclave mkdir build\x64-Debug @@ -75,7 +74,7 @@ cmake -G Ninja -DBUILD_ENCLAVES=1 -DUSE_LIBSGX=1 ..\.. ninja ``` -Similarly, to build release enclaves +Similarly, to build release enclaves: ```cmd cd C:\openenclave mkdir build\x64-Release @@ -84,7 +83,7 @@ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_ENCLAVES=1 ../.. ninja ``` -## Run unittests +## Run unit tests After building, run all unit test cases using `ctest` to confirm the SDK is built and working as expected. @@ -113,7 +112,7 @@ You can start playing with the Open Enclave samples after following the instruct For more information refer to the [Advanced Test Info](AdvancedTestInfo.md) document. -## Installing the SDK on local machine +## Installing the SDK on the local machine To install the SDK on the local machine use the following: diff --git a/docs/GettingStartedDocs/Contributors/WindowsSGX1GettingStarted.md b/docs/GettingStartedDocs/Contributors/WindowsSGX1GettingStarted.md index 9fdce89559..2faa4d784b 100644 --- a/docs/GettingStartedDocs/Contributors/WindowsSGX1GettingStarted.md +++ b/docs/GettingStartedDocs/Contributors/WindowsSGX1GettingStarted.md @@ -2,16 +2,18 @@ ## Platform requirements -IntelĀ® X86-64bit architecture with SGX1 +IntelĀ® X86-64bit architecture with SGX1. + +Note: To check if your system has support for SGX1, please look [here](../SGXSupportLevel.md). A version of Windows OS with native support for SGX features: - For server: Windows Server 2016 - For client: Windows 10 64-bit version 1709 or newer -- To check your Windows version, run winver on the command line. +- To check your Windows version, run `winver` on the command line. ## Install Git and Clone the Open Enclave SDK repo -Download and install Git for Windows from [here](https://git-scm.com/download/win) +Download and install Git for Windows from [here](https://git-scm.com/download/win). Clone the Open Enclave SDK @@ -29,14 +31,14 @@ First, change directory into the openenclave repository: cd openenclave ``` -To deploy all the prerequisities for building Open Enclave, you can run the following from powershell. Note that the Data Center Attestation Primitives Client is not used for attestation on systems which have support for SGX1 without support for Flexible Launch Control (FLC). +To deploy all the prerequisities for building Open Enclave, you can run the following from Powershell. Note that the Data Center Attestation Primitives (DCAP) Client is not used for attestation on systems which have support for SGX1 without support for Flexible Launch Control (FLC). ```powershell cd scripts .\install-windows-prereqs.ps1 -InstallPath PATH_TO_OE_REPO -LaunchConfiguration SGX1 -DCAPClientType None ``` -As an example, if you cloned Open Enclave SDK repo into C:\openenclave, you would run the following: +As an example, if you cloned Open Enclave SDK repo into `C:\openenclave`, you would run the following: ```powershell cd scripts @@ -51,13 +53,13 @@ If you prefer to manually install prerequisites, please refer to this [document] https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs) Normally this is accessible under the `Visual Studio 2017` folder in the Start Menu. -2. At the x64 Native Tools command prompt, use cmake and ninja to build the debug version: +2. At the x64 Native Tools command prompt, use CMake and ninja to build the debug version: ```cmd cd C:\openenclave mkdir build\x64-Debug cd build\x64-Debug - cmake -G Ninja -DBUILD_ENCLAVES=1 ..\. + cmake -G Ninja -DBUILD_ENCLAVES=1 ..\.. ninja ``` @@ -71,7 +73,7 @@ Normally this is accessible under the `Visual Studio 2017` folder in the Start M ninja ``` -## Run unittests +## Run unit tests After building, run all unit test cases using `ctest` to confirm the SDK is built and working as expected. In this example, we are testing the debug build. @@ -100,7 +102,7 @@ You can start playing with the Open Enclave samples after following the instruct For more information refer to the [Advanced Test Info](AdvancedTestInfo.md) document. -## Installing the SDK on local machine +## Installing the SDK on the local machine To install the SDK on the local machine use the following: diff --git a/docs/GettingStartedDocs/Contributors/building_oe_sdk.md b/docs/GettingStartedDocs/Contributors/building_oe_sdk.md index 5058caf4dc..877627f1d0 100644 --- a/docs/GettingStartedDocs/Contributors/building_oe_sdk.md +++ b/docs/GettingStartedDocs/Contributors/building_oe_sdk.md @@ -21,7 +21,7 @@ Please refer to the following [documentation](/docs/GettingStartedDocs/SGXSuppor - `SGX1+FLC`: In this mode, the Open Enclave SDK takes advantage of the Flexible Launch Control mode for better managing architectural enclaves. - - `Simulation`: Open Enclave comes with a SGX software simulation mode that simulates a subset of + - `Simulation`: Open Enclave comes with an SGX software simulation mode that simulates a subset of the SGX feature set. This simulator enables the Open Enclave SDK to run on systems without actual SGX hardware support. @@ -34,6 +34,7 @@ Please refer to the following [documentation](/docs/GettingStartedDocs/SGXSuppor | Simulation | Any level | On Linux, if your target system does not have any SGX hardware support, you may want to choose simulation. + On Windows, Open Enclave SDK does not support simulation mode. #### 3. Build, install and run @@ -41,12 +42,12 @@ Please refer to the following [documentation](/docs/GettingStartedDocs/SGXSuppor Choose an operating mode that is compatible with the SGX support level of your target system. The links below contain instructions on how to set up Open Enclave SDK environment for a given mode. -On Linux +On Linux: - [Setup Open Enclave SDK for SGX1+FLC](SGX1FLCGettingStarted.md) - [Setup Open Enclave SDK for SGX1](SGX1GettingStarted.md) - [Setup Open Enclave SDK for simulation mode](SimulatorGettingStarted.md) -On Windows +On Windows: - [Set up Open Enclave SDK for SGX1+FLC](WindowsSGX1FLCGettingStarted.md) - [Set up Open Enclave SDK for SGX1](WindowsSGX1GettingStarted.md) - Simulation mode is not supported on Windows From 54ff2075023682a18dbbf1cd80952f423fdeebf2 Mon Sep 17 00:00:00 2001 From: Cheng-mean Liu Date: Sat, 14 Sep 2019 02:13:32 -0500 Subject: [PATCH 012/420] Fixed QE Idenity regression --- host/sgx/ocalls.c | 3 ++- host/sgx/sgxquoteprovider.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/host/sgx/ocalls.c b/host/sgx/ocalls.c index 2f2d91fa2b..d11a3ae249 100644 --- a/host/sgx/ocalls.c +++ b/host/sgx/ocalls.c @@ -260,7 +260,7 @@ oe_result_t oe_get_revocation_info_ocall( &buffer_too_small)); if (buffer_too_small) - OE_RAISE(OE_BUFFER_TOO_SMALL); + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); result = OE_OK; @@ -308,6 +308,7 @@ oe_result_t oe_get_qe_identify_info_ocall( memcpy(issuer_chain, args.issuer_chain, args.issuer_chain_size); *issuer_chain_size_out = args.issuer_chain_size; + result = OE_OK; done: diff --git a/host/sgx/sgxquoteprovider.h b/host/sgx/sgxquoteprovider.h index ba3858bb9c..1658800f3e 100644 --- a/host/sgx/sgxquoteprovider.h +++ b/host/sgx/sgxquoteprovider.h @@ -28,8 +28,8 @@ typedef struct _oe_sgx_quote_provider #define SGX_QL_GET_REVOCATION_INFO_NAME "sgx_ql_get_revocation_info" #define SGX_QL_FREE_REVOCATION_INFO_NAME "sgx_ql_free_revocation_info" -#define SGX_QL_GET_QE_IDENTITY_INFO_NAME "sgx_ql_get_qe_identity_info" -#define SGX_QL_FREE_QE_IDENTITY_INFO_NAME "sgx_ql_free_qe_identity_info" +#define SGX_QL_GET_QE_IDENTITY_INFO_NAME "sgx_get_qe_identity_info" +#define SGX_QL_FREE_QE_IDENTITY_INFO_NAME "sgx_free_qe_identity_info" #define SGX_QL_SET_LOGGING_FUNCTION_NAME "sgx_ql_set_logging_function" OE_EXTERNC_END From b8b637bd7fd53f0f39caf322b4204fc6fa905c19 Mon Sep 17 00:00:00 2001 From: Marius Oprin Date: Mon, 16 Sep 2019 13:09:28 +0300 Subject: [PATCH 013/420] Clean copied sources and binaries from ExternalProject_Add rules --- 3rdparty/CMakeLists.txt | 4 ++++ 3rdparty/libcxx/CMakeLists.txt | 4 ++++ 3rdparty/libcxx/libcxx/benchmarks/CMakeLists.txt | 6 ++++++ .../libcxx/utils/google-benchmark/cmake/HandleGTest.cmake | 4 +++- 3rdparty/musl/CMakeLists.txt | 5 +++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index cee4b76f40..189589a712 100755 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -79,6 +79,10 @@ if (OE_TRUSTZONE) BYPRODUCTS /libteec/libteec.a) + set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES + ${CMAKE_CURRENT_BINARY_DIR}/optee_client + ${CMAKE_BINARY_DIR}/libteec/libteec.a + ) ExternalProject_Get_property(optee_client-wrap SOURCE_DIR) ExternalProject_Get_property(optee_client-wrap BINARY_DIR) diff --git a/3rdparty/libcxx/CMakeLists.txt b/3rdparty/libcxx/CMakeLists.txt index 710955e404..68e73b9298 100644 --- a/3rdparty/libcxx/CMakeLists.txt +++ b/3rdparty/libcxx/CMakeLists.txt @@ -11,6 +11,10 @@ ExternalProject_Add(libcxx_includes COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_LIST_DIR}/__config ${LIBCXX_INCLUDES}/__config INSTALL_COMMAND "") +set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES + ${LIBCXX_INCLUDES} +) + add_library(libcxx OBJECT __dso_handle.cpp libcxx/src/algorithm.cpp diff --git a/3rdparty/libcxx/libcxx/benchmarks/CMakeLists.txt b/3rdparty/libcxx/libcxx/benchmarks/CMakeLists.txt index 3823b87b39..414bde48fd 100644 --- a/3rdparty/libcxx/libcxx/benchmarks/CMakeLists.txt +++ b/3rdparty/libcxx/libcxx/benchmarks/CMakeLists.txt @@ -38,6 +38,9 @@ ExternalProject_Add(google-benchmark-libcxx -DBENCHMARK_USE_LIBCXX:BOOL=ON -DBENCHMARK_ENABLE_TESTING:BOOL=OFF) +set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES + ${CMAKE_CURRENT_BINARY_DIR}/benchmark-libcxx +) #============================================================================== # Build Google Benchmark for the native stdlib #============================================================================== @@ -61,6 +64,9 @@ if (LIBCXX_BENCHMARK_NATIVE_STDLIB) -DCMAKE_BUILD_TYPE:STRING=RELEASE -DCMAKE_INSTALL_PREFIX:PATH= -DBENCHMARK_ENABLE_TESTING:BOOL=OFF) + set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES + ${CMAKE_CURRENT_BINARY_DIR}/benchmark-native + ) endif() diff --git a/3rdparty/libcxx/libcxx/utils/google-benchmark/cmake/HandleGTest.cmake b/3rdparty/libcxx/libcxx/utils/google-benchmark/cmake/HandleGTest.cmake index b9c14436db..751ed6704f 100644 --- a/3rdparty/libcxx/libcxx/utils/google-benchmark/cmake/HandleGTest.cmake +++ b/3rdparty/libcxx/libcxx/utils/google-benchmark/cmake/HandleGTest.cmake @@ -50,7 +50,9 @@ macro(build_external_gtest) -DCMAKE_CXX_FLAGS:STRING=${GTEST_FLAGS} -Dgtest_force_shared_crt:BOOL=ON ) - + set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES + ${CMAKE_BINARY_DIR}/googletest + ) ExternalProject_Get_Property(googletest install_dir) set(GTEST_INCLUDE_DIRS ${install_dir}/include) file(MAKE_DIRECTORY ${GTEST_INCLUDE_DIRS}) diff --git a/3rdparty/musl/CMakeLists.txt b/3rdparty/musl/CMakeLists.txt index 9186035ed0..037f5e33c0 100644 --- a/3rdparty/musl/CMakeLists.txt +++ b/3rdparty/musl/CMakeLists.txt @@ -95,6 +95,11 @@ ExternalProject_Add(musl_includes ${MUSL_INCLUDES} ${MUSL_DIR} INSTALL_COMMAND "") +set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES + ${MUSL_INCLUDES} + ${MUSL_DIR} +) + add_library(oelibc_includes INTERFACE) add_dependencies(oelibc_includes musl_includes) From df0e37fa5a571119af76e9ff0601bcdb1d756dfd Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 12 Sep 2019 23:11:01 +0000 Subject: [PATCH 014/420] Setup CODEOWNERS This will make PRs automatically ping people! --- docs/CODEOWNERS | 52 +++++++++++++++++++++++++++++++++++ scripts/.check-license.ignore | 1 + 2 files changed, 53 insertions(+) create mode 100644 docs/CODEOWNERS diff --git a/docs/CODEOWNERS b/docs/CODEOWNERS new file mode 100644 index 0000000000..ca0e35fef7 --- /dev/null +++ b/docs/CODEOWNERS @@ -0,0 +1,52 @@ +# Each line is a file pattern followed by one or more owners. +# Refer to https://help.github.com/en/articles/about-code-owners + +# Order is important; the last matching pattern takes the most +# precedence. Try to keep at least two owners per pattern. + +# These owners will be the default owners for everything in the repo. +# Unless a later match takes precedence, they will be requested for +# review when someone opens a pull request. +* @openenclave/committers + +/3rdparty/ @mikbras @CodeMonkeyLeet +/cmake/ @andschwa @BRMcLaren +/common/ @CodeMonkeyLeet @gupta-ak @mikbras +/debugger/ @anakrish @jxyang +/enclave/ @CodeMonkeyLeet @gupta-ak @mikbras +/host/ @CodeMonkeyLeet @gupta-ak @mikbras +# TODO: Break this folder out? +/include/ @achamayou @dthaler @mikbras @CodeMonkeyLeet +/libc/ @mikbras @CodeMonkeyLeet +/scripts/ @achamayou @andschwa @johnkord +/samples/ @andschwa @dthaler @soccerGB +/syscall/ @mikbras @yakman2020 +# TODO: Break this folder out? +/tests/ @EmilAlexandruStoica @mikbras +/tools/ @anakrish @CodeMonkeyLeet +/tools/oeedger8r/ @andschwa @anakrish @jxyang +/pkgconfig/ @gupta-ak @mikbras +/prereqs/ @johnkord @CodeMonkeyLeet + +# Matches all folders with these names, not just in root. +optee/ @Britel @dthaler @HernanGatta +sgx/ @CodeMonkeyLeet @gupta-ak @mikbras +linux/ @mikbras @yakman2020 +windows/ @CodeMonkeyLeet @yakman2020 +crypto/ @CodeMonkeyLeet @gupta-ak + +# Match all CMake, anywhere. +CMakeLists.txt @andschwa @BRMcLaren @EmilAlexandruStoica +*.cmake @andschwa @BRMcLaren @EmilAlexandruStoica + +# Match all Markdown, anywhere. +*.md @CodeMonkeyLeet @johnkord @andschwa @radhikaj + +# Except design reviews, which should be everyone. +/docs/DesignDocs/ @openenclave/committers + +# And governance documents. +/docs/Contributing.md @openenclave/maintainers +/docs/GovernanceModel.md @openenclave/maintainers +/docs/Maintainers.md @openenclave/maintainers +/docs/Releasing.md @openenclave/maintainers diff --git a/scripts/.check-license.ignore b/scripts/.check-license.ignore index 4edcbbb6a4..a096f080b3 100644 --- a/scripts/.check-license.ignore +++ b/scripts/.check-license.ignore @@ -42,6 +42,7 @@ tools/oeedger8r/intel/.* 3rdparty/musl/endian\.h\.suffix 3rdparty/optee/optee_client 3rdparty/optee/optee_os +docs/CODEOWNERS LICENSE THIRD_PARTY_NOTICES VERSION From 79cae813ff92cb45cfce70be8f88c299ba447a2d Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Mon, 16 Sep 2019 11:33:15 -0700 Subject: [PATCH 015/420] Fix typos Signed-off-by: Dave Thaler --- docs/GovernanceModel.md | 2 +- docs/Maintainers.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/GovernanceModel.md b/docs/GovernanceModel.md index 3cbfdcc7b6..3acffa0260 100644 --- a/docs/GovernanceModel.md +++ b/docs/GovernanceModel.md @@ -41,7 +41,7 @@ Remember that security issues should be reported through a separate channel, and will receive a response within 24 hours. See [Reporting Security Issues](Contributing.md#reporting-security-issues). -Community Maintenance Commitee Members, Committers, and Contributors +Community Governance Committee Members, Committers, and Contributors -------------------------------------------------------------------- A "committer" is anyone with direct write access to the Open Enclave repository on diff --git a/docs/Maintainers.md b/docs/Maintainers.md index 248d1f7b52..d9222ba353 100644 --- a/docs/Maintainers.md +++ b/docs/Maintainers.md @@ -34,7 +34,7 @@ Committee Responsibilities The primary responsibility of the Committee is to grant new committer rights (that is, write access to the main Open Enclave SDK repository or related repositories), and to grant new membership into the Committee. Conversely, the -Commitee must also remove committer rights and membership from those found to +Committee must also remove committer rights and membership from those found to be violating the project's Code of Conduct or otherwise negatively affecting the project's community health. From 033c8c988efb9d5e9c317fbb9ef7384a98aaae0c Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Mon, 16 Sep 2019 11:34:21 -0700 Subject: [PATCH 016/420] Omit reference to a TSC Signed-off-by: Dave Thaler --- docs/Maintainers.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/Maintainers.md b/docs/Maintainers.md index d9222ba353..0d927b330b 100644 --- a/docs/Maintainers.md +++ b/docs/Maintainers.md @@ -1,8 +1,7 @@ Community Governance Committee ============================== -This document describes the Open Enclave Community Governance Committee, which in some open source -projects is also known as a Technical Steering Committee. By +This document describes the Open Enclave Community Governance Committee. By our liberal contribution policy outlined in our [governance model](GovernanceModel.md), Committee members are committers that are trusted to grant new committer rights, and grant new membership into the From 136afafbe16270be803e4a087e1464f3a8d7558a Mon Sep 17 00:00:00 2001 From: Radoslav Gerganov Date: Tue, 17 Sep 2019 11:29:40 +0300 Subject: [PATCH 017/420] Fix file-encryptor README The file-encryptor sample doesn't use oe_is_outside_enclave API. This patch fixes the README file for this sample. Signed-off-by: Radoslav Gerganov --- samples/file-encryptor/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/file-encryptor/README.md b/samples/file-encryptor/README.md index fdf6069b68..f07d04c4dc 100644 --- a/samples/file-encryptor/README.md +++ b/samples/file-encryptor/README.md @@ -17,7 +17,6 @@ It has the following properties: - mbedtls_entropy_* - mbedtls_ctr_drbg_* - mbedtls_sha256_* - - oe_is_outside_enclave - Also runs in OE simulation mode ## Host application From 076b19c5857f826e64592ca8472538756e59f6f9 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 17 Sep 2019 22:07:47 +0000 Subject: [PATCH 018/420] Update CGC team name in CODEOWNERS --- docs/CODEOWNERS | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/CODEOWNERS b/docs/CODEOWNERS index ca0e35fef7..f35b4d8c5a 100644 --- a/docs/CODEOWNERS +++ b/docs/CODEOWNERS @@ -46,7 +46,7 @@ CMakeLists.txt @andschwa @BRMcLaren @EmilAlexandruStoica /docs/DesignDocs/ @openenclave/committers # And governance documents. -/docs/Contributing.md @openenclave/maintainers -/docs/GovernanceModel.md @openenclave/maintainers -/docs/Maintainers.md @openenclave/maintainers -/docs/Releasing.md @openenclave/maintainers +/docs/Contributing.md @openenclave/committee +/docs/GovernanceModel.md @openenclave/committee +/docs/Maintainers.md @openenclave/committee +/docs/Releasing.md @openenclave/committee From d4fb942541599ae6b33d15017762e0ed57f217b7 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 17 Sep 2019 22:12:25 +0000 Subject: [PATCH 019/420] Rename Maintainers.md to Committers.md --- docs/CODEOWNERS | 2 +- docs/{Maintainers.md => Committers.md} | 0 docs/GovernanceModel.md | 8 ++++---- 3 files changed, 5 insertions(+), 5 deletions(-) rename docs/{Maintainers.md => Committers.md} (100%) diff --git a/docs/CODEOWNERS b/docs/CODEOWNERS index f35b4d8c5a..c261a0b1a2 100644 --- a/docs/CODEOWNERS +++ b/docs/CODEOWNERS @@ -48,5 +48,5 @@ CMakeLists.txt @andschwa @BRMcLaren @EmilAlexandruStoica # And governance documents. /docs/Contributing.md @openenclave/committee /docs/GovernanceModel.md @openenclave/committee -/docs/Maintainers.md @openenclave/committee +/docs/Committers.md @openenclave/committee /docs/Releasing.md @openenclave/committee diff --git a/docs/Maintainers.md b/docs/Committers.md similarity index 100% rename from docs/Maintainers.md rename to docs/Committers.md diff --git a/docs/GovernanceModel.md b/docs/GovernanceModel.md index 3acffa0260..d4e4669d75 100644 --- a/docs/GovernanceModel.md +++ b/docs/GovernanceModel.md @@ -17,7 +17,7 @@ In order to maintain a pleasant and welcoming environment, we want to reiterate that it is imperative that all community members adhere to our [Code of Conduct](Contributing.md#code-of-conduct). Anyone failing to follow the Code of Conduct will be removed from the community -by the [Community Governance Committee](Maintainers.md). If you are made to +by the [Community Governance Committee](Committers.md). If you are made to feel uncomfortable, or have any concerns about behavior within the community, we encourage you to reach out to members of the Community Governance Committee. @@ -51,7 +51,7 @@ contributions to the project, including: creating or commenting on issues, opening or reviewing pull requests, or other useful contributions such as providing support in forums or chats. -See the [Community Governance Committee document](Maintainers.md) for more information +See the [Community Governance Committee document](Committers.md) for more information on the Community Governance Committee, our process for adding new committers and Committee members, as well the areas of expertise for each of the committers. @@ -69,9 +69,9 @@ voting process. For example, committers can merge contributions that were reviewed without objections. If there are objections that cannot be resolved, an issue can be escalated to the Community Governance Committee to make a decision, which handles issues as discussed in the -[Community Governance Committee document](Maintainers.md). +[Community Governance Committee document](Committers.md). -See the [Community Governance Committee document](Maintainers.md) for the list of project +See the [Community Governance Committee document](Committers.md) for the list of project committers, and how to become one. Community Approval of Releases From 2ad99e075cdecb75974e7e832e9d14e7d2f1e0db Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 17 Sep 2019 22:13:47 +0000 Subject: [PATCH 020/420] Rename GovernanceModel.md to Governance.md For consistency --- README.md | 2 +- docs/CODEOWNERS | 2 +- docs/Committers.md | 2 +- docs/Contributing.md | 4 ++-- docs/{GovernanceModel.md => Governance.md} | 0 docs/Releasing.md | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) rename docs/{GovernanceModel.md => Governance.md} (100%) diff --git a/README.md b/README.md index 6b29d8172a..c78d6c5cd5 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ additional questions or comments. See the [Development Guide](docs/DevelopmentGuide.md) for details about contributing code to this project, such as coding style and development -processes. Also see our [Governance Model](docs/GovernanceModel.md) for how we +processes. Also see our [Governance Model](docs/Governance.md) for how we maintain the project. Licensing diff --git a/docs/CODEOWNERS b/docs/CODEOWNERS index c261a0b1a2..a44e5aa0f8 100644 --- a/docs/CODEOWNERS +++ b/docs/CODEOWNERS @@ -47,6 +47,6 @@ CMakeLists.txt @andschwa @BRMcLaren @EmilAlexandruStoica # And governance documents. /docs/Contributing.md @openenclave/committee -/docs/GovernanceModel.md @openenclave/committee +/docs/Governance.md @openenclave/committee /docs/Committers.md @openenclave/committee /docs/Releasing.md @openenclave/committee diff --git a/docs/Committers.md b/docs/Committers.md index 0d927b330b..e227fdb645 100644 --- a/docs/Committers.md +++ b/docs/Committers.md @@ -3,7 +3,7 @@ Community Governance Committee This document describes the Open Enclave Community Governance Committee. By our liberal contribution policy outlined in our -[governance model](GovernanceModel.md), Committee members are committers that are +[governance model](Governance.md), Committee members are committers that are trusted to grant new committer rights, and grant new membership into the Committee. diff --git a/docs/Contributing.md b/docs/Contributing.md index c2f09f1156..8e52b43a8b 100644 --- a/docs/Contributing.md +++ b/docs/Contributing.md @@ -9,7 +9,7 @@ filing an issue. General contribution guidance is included in this document. Additional guidance is defined in the documents linked below: -- [Governance Model](GovernanceModel.md) describes how we intend our +- [Governance Model](Governance.md) describes how we intend our collaboration to happen. - [Development Guide](DevelopmentGuide.md) describes the coding style and other development practices applied to this project. @@ -59,7 +59,7 @@ General Guidelines Please do: - **DO** open an issue for design discussion before making any major changes. -- **DO** read our [Governance Model](GovernanceModel.md) to understand how our +- **DO** read our [Governance Model](Governance.md) to understand how our community works. - **DO** follow our coding style described in the [Development Guide]( DevelopmentGuide.md). diff --git a/docs/GovernanceModel.md b/docs/Governance.md similarity index 100% rename from docs/GovernanceModel.md rename to docs/Governance.md diff --git a/docs/Releasing.md b/docs/Releasing.md index 45ca22a533..19fa1694ad 100644 --- a/docs/Releasing.md +++ b/docs/Releasing.md @@ -97,7 +97,7 @@ release. These notes should be suitable for a blog post. Community Approval ------------------ -See the [Governance Model](GovernanceModel.md#community-approval-of-releases) +See the [Governance Model](Governance.md#community-approval-of-releases) documentation for the necessary steps to approve the release with the community. GitHub Release and Git Tag Creation @@ -146,5 +146,5 @@ notes, and any social media we currently use). Servicing --------- -See the [Governance Model](GovernanceModel.md#servicing-of-releases) +See the [Governance Model](Governance.md#servicing-of-releases) documentation for our intended servicing model. From a66872cfbbdba6dd777a47e6d09e8913bcbdd723 Mon Sep 17 00:00:00 2001 From: Xuejun Yang Date: Fri, 23 Aug 2019 19:44:37 +0000 Subject: [PATCH 021/420] The 2nd half installment of switchless ocalls * Create threads to service switchless ocalls * Necessary sychronizations between threads * Add generic handling of configurations during enclave creation * Use switchless specific struct to configure and start switchless * Add a switchless test case and measure its performance * Expose the changes related to enclave configuration in the public API (marked as experimental) * Tear down per-thread shared memory arenas during EEXIT (previously during enclave termination) * Protect sync variable accesses with memory barriers * Add OS agnostic thread and atomic routines for better readability (#2098) This also fixes issue 2098. --- common/result.c | 9 ++ enclave/core/CMakeLists.txt | 3 +- enclave/core/arena.c | 98 +++++++++++++++ enclave/core/arena.h | 27 ++++ enclave/core/hostcalls.c | 6 +- enclave/core/optee/gp.c | 6 + enclave/core/optee/hostcalls.c | 6 +- enclave/core/sgx/calls.c | 80 ++++++------ enclave/core/sgx/hostcalls.c | 6 +- enclave/core/shm.c | 111 ----------------- enclave/core/shm.h | 28 ----- enclave/core/switchlesscalls.c | 143 ++++++++++++++++++++++ enclave/core/switchlesscalls.h | 15 +++ host/CMakeLists.txt | 3 +- host/calls.h | 2 + host/hostthread.h | 29 ++++- host/linux/hostthread.c | 13 +- host/optee/linux/enclave.c | 18 ++- host/sgx/calls.c | 15 +-- host/sgx/create.c | 72 ++++++++++- host/sgx/enclave.h | 6 +- host/sgx/switchless.c | 135 ++++++++++++++++++++ host/traceh.c | 2 +- host/windows/hostthread.c | 27 +++- include/openenclave/bits/result.h | 15 +++ include/openenclave/host.h | 70 ++++++++++- include/openenclave/internal/atomic.h | 36 ++++++ include/openenclave/internal/calls.h | 1 + include/openenclave/internal/switchless.h | 32 +++++ include/openenclave/internal/thread.h | 4 +- include/openenclave/internal/utils.h | 10 ++ tests/create-errors/host/host.c | 27 +++- tests/switchless/enc/CMakeLists.txt | 4 +- tests/switchless/enc/enc.c | 79 +++++++----- tests/switchless/host/CMakeLists.txt | 4 +- tests/switchless/host/host.c | 92 +++++++++----- tests/switchless/switchless.edl | 20 ++- tools/oeedger8r/Emitter.ml | 15 +++ 38 files changed, 971 insertions(+), 298 deletions(-) create mode 100644 enclave/core/arena.c create mode 100644 enclave/core/arena.h delete mode 100644 enclave/core/shm.c delete mode 100644 enclave/core/shm.h create mode 100644 enclave/core/switchlesscalls.c create mode 100644 enclave/core/switchlesscalls.h create mode 100644 host/sgx/switchless.c create mode 100644 include/openenclave/internal/switchless.h diff --git a/common/result.c b/common/result.c index 1802738ced..9a77b863a1 100644 --- a/common/result.c +++ b/common/result.c @@ -118,6 +118,12 @@ const char* oe_result_str(oe_result_t result) return "QE_QUOTE_ENCLAVE_IDENTITY_PRODUCTID_MISMATCH"; case OE_VERIFY_FAILED_AES_CMAC_MISMATCH: return "OE_VERIFY_FAILED_AES_CMAC_MISMATCH"; + case OE_CONTEXT_SWITCHLESS_OCALL_MISSED: + return "OE_CONTEXT_SWITCHLESS_OCALL_MISSED"; + case OE_THREAD_CREATE_ERROR: + return "OE_THREAD_CREATE_ERROR"; + case OE_THREAD_JOIN_ERROR: + return "OE_THREAD_JOIN_ERROR"; case __OE_RESULT_MAX: break; } @@ -180,6 +186,9 @@ bool oe_is_valid_result(uint32_t result) case OE_QUOTE_ENCLAVE_IDENTITY_UNIQUEID_MISMATCH: case QE_QUOTE_ENCLAVE_IDENTITY_PRODUCTID_MISMATCH: case OE_VERIFY_FAILED_AES_CMAC_MISMATCH: + case OE_CONTEXT_SWITCHLESS_OCALL_MISSED: + case OE_THREAD_CREATE_ERROR: + case OE_THREAD_JOIN_ERROR: { return true; } diff --git a/enclave/core/CMakeLists.txt b/enclave/core/CMakeLists.txt index 9b63d123bb..c12447fdd3 100644 --- a/enclave/core/CMakeLists.txt +++ b/enclave/core/CMakeLists.txt @@ -136,12 +136,13 @@ add_library(oecore STATIC pthread.c result.c sbrk.c - shm.c + arena.c stdio.c strerror.c string.c strtok_r.c strtoul.c + switchlesscalls.c tee_t_wrapper.c time.c tracee.c diff --git a/enclave/core/arena.c b/enclave/core/arena.c new file mode 100644 index 0000000000..1b0877d955 --- /dev/null +++ b/enclave/core/arena.c @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include "arena.h" +#include +#include +#include +#include +#include +#include + +// The per-thread shared memory arena +static __thread shared_memory_arena_t _arena = {0}; + +// Default shared memory arena capacity is 1 mb +static size_t _capacity = 1024 * 1024; + +static const size_t _max_capacity = 1 << 30; + +void* oe_allocate_arena(size_t capacity); +void oe_deallocate_arena(void* buffer); + +bool oe_configure_arena_capacity(size_t cap) +{ + if (cap > _max_capacity) + { + return false; + } + _capacity = cap; + return true; +} + +void* oe_arena_malloc(size_t size) +{ + oe_result_t result = OE_UNEXPECTED; + size_t total_size = 0; + const size_t align = OE_EDGER8R_BUFFER_ALIGNMENT; + + // Create the anera if it hasn't been created. + if (_arena.buffer == NULL) + { + void* buffer = oe_allocate_arena(_capacity); + if (buffer == NULL) + return NULL; + _arena.buffer = (uint8_t*)buffer; + _arena.capacity = _capacity; + _arena.used = 0; + } + + // Round up to the nearest alignment size. + total_size = oe_round_up_to_multiple(size, align); + + // check for overflow + if (total_size < size) + return NULL; + + // check for capacity + size_t used_after; + OE_CHECK(oe_safe_add_sizet(_arena.used, total_size, &used_after)); + + // Ok if the incoming malloc puts us below the capacity. + if (used_after <= _arena.capacity) + { + uint8_t* addr = _arena.buffer + _arena.used; + _arena.used = used_after; + return addr; + } + +done: + return NULL; +} + +void* oe_arena_calloc(size_t num, size_t size) +{ + size_t total = 0; + if (oe_safe_mul_sizet(num, size, &total) != OE_OK) + return NULL; + + void* ptr = oe_arena_malloc(total); + if (ptr != NULL) + { + memset(ptr, 0, total); + } + return ptr; +} + +void oe_arena_free_all() +{ + _arena.used = 0; +} + +// Free the arena in the current thread. +void oe_teardown_arena() +{ + if (_arena.buffer != NULL) + oe_deallocate_arena(_arena.buffer); + memset(&_arena, 0, sizeof(_arena)); +} diff --git a/enclave/core/arena.h b/enclave/core/arena.h new file mode 100644 index 0000000000..214bf525e7 --- /dev/null +++ b/enclave/core/arena.h @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#ifndef _OE_ARENA_H +#define _OE_ARENA_H + +#include + +typedef struct _shared_memory_arena_t +{ + /* Buffer holding the shared memory pool */ + uint8_t* buffer; + size_t capacity; + size_t used; +} shared_memory_arena_t; + +bool oe_configure_arena_capacity(size_t cap); + +void* oe_arena_malloc(size_t size); + +void* oe_arena_calloc(size_t num, size_t size); + +void oe_arena_free_all(); + +void oe_teardown_arena(); + +#endif /* _OE_ARENA_H */ diff --git a/enclave/core/hostcalls.c b/enclave/core/hostcalls.c index 584ee5fc1c..531f0dfbe0 100644 --- a/enclave/core/hostcalls.c +++ b/enclave/core/hostcalls.c @@ -11,7 +11,7 @@ #include #include -#include "shm.h" +#include "arena.h" #include "tee_t.h" void* oe_host_malloc(size_t size) @@ -160,14 +160,14 @@ int oe_host_fprintf(int device, const char* fmt, ...) // A stack-based allocation scheme is the most efficient in this case. void* oe_allocate_switchless_ocall_buffer(size_t size) { - return oe_shm_malloc(size); + return oe_arena_malloc(size); } // Function used by oeedger8r for freeing ocall buffers. void oe_free_switchless_ocall_buffer(void* buffer) { OE_UNUSED(buffer); - /* Do nothing. Buffer will be freed on ECALL RETURN */ + oe_arena_free_all(); } int oe_host_write(int device, const char* str, size_t len) diff --git a/enclave/core/optee/gp.c b/enclave/core/optee/gp.c index dbd6f41d6b..a786cc36b0 100644 --- a/enclave/core/optee/gp.c +++ b/enclave/core/optee/gp.c @@ -469,6 +469,12 @@ TEE_Result TA_InvokeCommandEntryPoint( result = TEE_ERROR_BAD_STATE; break; } + case OE_ECALL_INIT_CONTEXT_SWITCHLESS: + { + /* TODO: initialize switchless calls */ + result = TEE_ERROR_NOT_IMPLEMENTED; + break; + } default: { /* No function found with the number */ diff --git a/enclave/core/optee/hostcalls.c b/enclave/core/optee/hostcalls.c index 9ea093e243..fb29802efb 100644 --- a/enclave/core/optee/hostcalls.c +++ b/enclave/core/optee/hostcalls.c @@ -24,14 +24,14 @@ void oe_free_ocall_buffer(void* buffer) } // TODO -void* oe_reserve_shm(size_t capacity) +void* oe_allocate_arena(size_t capacity) { OE_UNUSED(capacity); return NULL; } // TODO -void oe_unreserve_shm(void* buffer) +void oe_deallocate_arena(void* buffer) { OE_UNUSED(buffer); -} \ No newline at end of file +} diff --git a/enclave/core/sgx/calls.c b/enclave/core/sgx/calls.c index 08eb0e804e..533fe89fd4 100644 --- a/enclave/core/sgx/calls.c +++ b/enclave/core/sgx/calls.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -20,8 +21,9 @@ #include #include #include "../../sgx/report.h" +#include "../arena.h" #include "../atexit.h" -#include "../shm.h" +#include "../switchlesscalls.h" #include "asmdefs.h" #include "cpuid.h" #include "init.h" @@ -386,8 +388,6 @@ static void _handle_ecall( case OE_ECALL_CALL_ENCLAVE_FUNCTION: { arg_out = _handle_call_enclave_function(arg_in); - /* clear up shared memory upon ERET */ - oe_shm_clear(); break; } case OE_ECALL_DESTRUCTOR: @@ -398,9 +398,6 @@ static void _handle_ecall( /* Call all finalization functions */ oe_call_fini_functions(); - /* Free shared memory upon destroying enclave */ - oe_shm_destroy(); - #if defined(OE_USE_DEBUG_MALLOC) /* If memory still allocated, print a trace and return an error */ @@ -421,6 +418,11 @@ static void _handle_ecall( arg_out = _handle_init_enclave(arg_in); break; } + case OE_ECALL_INIT_CONTEXT_SWITCHLESS: + { + arg_out = oe_handle_init_switchless(arg_in); + break; + } default: { /* No function found with the number */ @@ -431,6 +433,12 @@ static void _handle_ecall( done: + /* Free shared memory arena before we clear TLS */ + if (td->depth == 1) + { + oe_teardown_arena(); + } + /* Remove ECALL context from front of td_t.ecalls list */ td_pop_callsite(td); @@ -566,7 +574,7 @@ oe_result_t oe_call_host_function_by_table_id( OE_RAISE(OE_INVALID_PARAMETER); /* Initialize the arguments */ - args = switchless ? oe_shm_calloc(sizeof(*args)) + args = switchless ? oe_arena_calloc(1, sizeof(*args)) : oe_host_calloc(1, sizeof(*args)); if (args == NULL) @@ -585,9 +593,31 @@ oe_result_t oe_call_host_function_by_table_id( args->result = OE_UNEXPECTED; /* Call the host function with this address */ - // TODO: for switchessless calls, push the job (wrapped in args) to an - // available worker thread, and wait for result - // if (!switchless) + if (switchless && oe_is_switchless_initialized()) + { + oe_result_t post_result = oe_post_switchless_ocall(args); + + // Fall back to regular OCALL if host worker threads are unavailable + if (post_result == OE_CONTEXT_SWITCHLESS_OCALL_MISSED) + OE_CHECK( + oe_ocall(OE_OCALL_CALL_HOST_FUNCTION, (uint64_t)args, NULL)); + else + { + OE_CHECK(post_result); + // Wait until args.result is set by the host worker. + while (true) + { + OE_ATOMIC_MEMORY_BARRIER_ACQUIRE(); + if (__atomic_load_n(&args->result, __ATOMIC_SEQ_CST) != + __OE_RESULT_MAX) + break; + + /* Yield to CPU */ + asm volatile("pause"); + } + } + } + else { OE_CHECK(oe_ocall(OE_OCALL_CALL_HOST_FUNCTION, (uint64_t)args, NULL)); } @@ -635,34 +665,6 @@ oe_result_t oe_call_host_function( false /* non-switchless */); } -/* -**============================================================================== -** -** oe_switchless_call_host_function() -** This is the preferred way to call host functions switchlessly. -** -**============================================================================== -*/ - -oe_result_t oe_switchless_call_host_function( - size_t function_id, - const void* input_buffer, - size_t input_buffer_size, - void* output_buffer, - size_t output_buffer_size, - size_t* output_bytes_written) -{ - return oe_call_host_function_by_table_id( - OE_UINT64_MAX, - function_id, - input_buffer, - input_buffer_size, - output_buffer, - output_buffer_size, - output_bytes_written, - true /* switchless */); -} - /* **============================================================================== ** @@ -900,7 +902,7 @@ void oe_abort(void) } // Free the shared memory pools - oe_shm_destroy(); + oe_teardown_arena(); // Return to the latest ECALL. _handle_exit(OE_CODE_ERET, 0, __oe_enclave_status); diff --git a/enclave/core/sgx/hostcalls.c b/enclave/core/sgx/hostcalls.c index 260fdfc2fc..8f2712ea52 100644 --- a/enclave/core/sgx/hostcalls.c +++ b/enclave/core/sgx/hostcalls.c @@ -18,12 +18,12 @@ void oe_free_ocall_buffer(void* buffer) oe_host_free(buffer); } -void* oe_reserve_shm(size_t capacity) +void* oe_allocate_arena(size_t capacity) { return oe_host_malloc(capacity); } -void oe_unreserve_shm(void* buffer) +void oe_deallocate_arena(void* buffer) { oe_host_free(buffer); -} \ No newline at end of file +} diff --git a/enclave/core/shm.c b/enclave/core/shm.c deleted file mode 100644 index 024c76454e..0000000000 --- a/enclave/core/shm.c +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#include "shm.h" -#include -#include -#include -#include -#include - -#define ALIGNMENT sizeof(uint64_t) - -// the per-thread shared memory pool -__thread Shared_memory_pool shm = {0}; - -// the global list of shared memory pools -Shared_memory_pool* _shm_list = NULL; - -static oe_spinlock_t _shm_list_lock = OE_SPINLOCK_INITIALIZER; - -// default shared memory pool capacity is 1 mb -size_t capacity = 1024 * 1024; - -size_t max_capacity = 1 << 30; - -void* oe_reserve_shm(size_t capacity); -void oe_unreserve_shm(void* buffer); - -bool oe_configure_shm_capacity(size_t cap) -{ - if (cap > max_capacity) - { - return false; - } - capacity = cap; - return true; -} - -void* oe_shm_malloc(size_t size) -{ - oe_result_t result = OE_UNEXPECTED; - size_t total_size = 0; - - if (shm.buffer == NULL) - { - void* buffer = oe_reserve_shm(capacity); - if (buffer == NULL) - OE_RAISE(OE_OUT_OF_MEMORY); - shm.buffer = (uint8_t*)buffer; - shm.capacity = capacity; - shm.used = 0; - - // add the newly created pool to the global list - oe_spin_lock(&_shm_list_lock); - shm.next = _shm_list; - _shm_list = &shm; - oe_spin_unlock(&_shm_list_lock); - } - - // Round up to the nearest alignment size. - total_size = oe_round_up_to_multiple(size, ALIGNMENT); - - // check for overflow - OE_CHECK(total_size < size); - - // check for capacity - size_t used_after; - OE_CHECK(oe_safe_add_sizet(shm.used, total_size, &used_after)); - - // Ok if the incoming malloc puts us below the capacity. - if (used_after <= shm.capacity) - { - uint8_t* addr = shm.buffer + shm.used; - shm.used = used_after; - return addr; - } - else - OE_RAISE(OE_OUT_OF_MEMORY); - -done: - return NULL; -} - -void* oe_shm_calloc(size_t size) -{ - void* ptr = oe_shm_malloc(size); - if (ptr != NULL) - { - memset(ptr, 0, size); - } - return ptr; -} - -void oe_shm_clear() -{ - shm.used = 0; -} - -// Free all shared memory pools in the global list -void oe_shm_destroy() -{ - Shared_memory_pool* next = _shm_list; - while (next != NULL) - { - oe_unreserve_shm(next->buffer); - Shared_memory_pool* current = next; - next = next->next; - memset(current, 0, sizeof(shm)); - } - _shm_list = NULL; -} \ No newline at end of file diff --git a/enclave/core/shm.h b/enclave/core/shm.h deleted file mode 100644 index c873409dc8..0000000000 --- a/enclave/core/shm.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#ifndef _OE_SHM_H -#define _OE_SHM_H - -#include - -typedef struct _shared_memory_pool -{ - /* Buffer holding the shared memory pool */ - uint8_t* buffer; - size_t capacity; - size_t used; - struct _shared_memory_pool* next; -} Shared_memory_pool; - -bool oe_configure_shm_capacity(size_t cap); - -void* oe_shm_malloc(size_t size); - -void* oe_shm_calloc(size_t size); - -void oe_shm_clear(); - -void oe_shm_destroy(); - -#endif /* _OE_SHM_H */ \ No newline at end of file diff --git a/enclave/core/switchlesscalls.c b/enclave/core/switchlesscalls.c new file mode 100644 index 0000000000..40c5c38f0f --- /dev/null +++ b/enclave/core/switchlesscalls.c @@ -0,0 +1,143 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include "switchlesscalls.h" +#include +#include +#include +#include +#include + +// The number of host thread workers. Initialized by host through ECALL +static size_t _host_worker_count = 0; + +// The array of host worker contexts. Initialized by host through ECALL +static oe_host_worker_context_t* _host_worker_contexts = NULL; + +/* +**============================================================================== +** +** oe_is_switchless_initialized +** +** Return whether oe_handle_init_switchless has been called or not. +** +**============================================================================== +*/ +bool oe_is_switchless_initialized() +{ + return _host_worker_count != 0; +} + +/* +**============================================================================== +** +** oe_handle_init_switchless() +** +** Handle the OE_ECALL_INIT_CONTEXT_SWITCHLESS from host. +** +**============================================================================== +*/ +oe_result_t oe_handle_init_switchless(uint64_t arg_in) +{ + oe_result_t result = OE_UNEXPECTED; + oe_switchless_call_manager_t* manager = NULL; + oe_switchless_call_manager_t safe_manager; + size_t contexts_size, threads_size; + + if (arg_in == 0) + OE_RAISE(OE_INVALID_PARAMETER); + + manager = (oe_switchless_call_manager_t*)arg_in; + safe_manager = *manager; + + contexts_size = + sizeof(oe_host_worker_context_t) * safe_manager.num_host_workers; + threads_size = sizeof(oe_thread_t) * safe_manager.num_host_workers; + + // Ensure the switchless manager and its arrays are outside of enclave + if (!oe_is_outside_enclave(manager, sizeof(oe_switchless_call_manager_t)) || + !oe_is_outside_enclave( + safe_manager.host_worker_contexts, contexts_size) || + !oe_is_outside_enclave( + safe_manager.host_worker_threads, threads_size) || + safe_manager.num_host_workers == 0) + { + OE_RAISE(OE_INVALID_PARAMETER); + } + + /* lfence after checks. */ + oe_lfence(); + + // Copy the worker context array pointer and its size to avoid TOCTOU + _host_worker_count = safe_manager.num_host_workers; + _host_worker_contexts = safe_manager.host_worker_contexts; + result = OE_OK; + +done: + return result; +} + +/* +**============================================================================== +** +** oe_post_switchless_ocall() +** +** Post the function call (wrapped in args) to a free host worker thread +** by writing to its context. +** +**============================================================================== +*/ +oe_result_t oe_post_switchless_ocall(oe_call_host_function_args_t* args) +{ + oe_result_t result = OE_UNEXPECTED; + + OE_ATOMIC_MEMORY_BARRIER_RELEASE(); + args->result = __OE_RESULT_MAX; // Means the call hasn't been processed. + + // Cycle through the worker contexts until we find a free worker. + size_t tries = _host_worker_count; + while (tries--) + { + if (_host_worker_contexts[tries].call_arg == NULL) + { + if (oe_atomic_compare_and_swap_ptr( + (void* volatile*)&_host_worker_contexts[tries].call_arg, + NULL, + args)) + { + return OE_OK; + } + } + } + + result = OE_CONTEXT_SWITCHLESS_OCALL_MISSED; + + return result; +} + +/* +**============================================================================== +** +** oe_switchless_call_host_function() +** +**============================================================================== +*/ + +oe_result_t oe_switchless_call_host_function( + size_t function_id, + const void* input_buffer, + size_t input_buffer_size, + void* output_buffer, + size_t output_buffer_size, + size_t* output_bytes_written) +{ + return oe_call_host_function_by_table_id( + OE_UINT64_MAX, + function_id, + input_buffer, + input_buffer_size, + output_buffer, + output_buffer_size, + output_bytes_written, + true /* switchless */); +} diff --git a/enclave/core/switchlesscalls.h b/enclave/core/switchlesscalls.h new file mode 100644 index 0000000000..5893d54adf --- /dev/null +++ b/enclave/core/switchlesscalls.h @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#ifndef _OE_SWITCHLESSCALLS_H +#define _OE_SWITCHLESSCALLS_H + +#include + +bool oe_is_switchless_initialized(); + +oe_result_t oe_handle_init_switchless(uint64_t arg_in); + +oe_result_t oe_post_switchless_ocall(oe_call_host_function_args_t* args); + +#endif // _OE_SWITCHLESSCALLS_H diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index bd10b4e6d8..4a75a4e2c2 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -147,7 +147,8 @@ if (OE_SGX) sgx/sgxmeasure.c sgx/sgxquote.c sgx/sgxsign.c - sgx/sgxtypes.c) + sgx/sgxtypes.c + sgx/switchless.c) # OS specific as well. if (UNIX) diff --git a/host/calls.h b/host/calls.h index c152354ef8..38daa10d76 100644 --- a/host/calls.h +++ b/host/calls.h @@ -17,4 +17,6 @@ typedef struct _ocall_table extern ocall_table_t _ocall_tables[]; +oe_result_t oe_handle_call_host_function(uint64_t arg, oe_enclave_t* enclave); + #endif /* OE_HOST_CALLS_H */ diff --git a/host/hostthread.h b/host/hostthread.h index 65f206a5f2..5e23df5460 100644 --- a/host/hostthread.h +++ b/host/hostthread.h @@ -11,7 +11,9 @@ #define _HOSTTHREAD_H #include +#include #include +#include #if __GNUC__ #include @@ -28,8 +30,6 @@ OE_EXTERNC_BEGIN typedef pthread_once_t oe_once_type; #define OE_H_ONCE_INITIALIZER PTHREAD_ONCE_INIT -typedef pthread_t oe_thread; - typedef pthread_mutex_t oe_mutex; #define OE_H_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP @@ -40,8 +40,6 @@ typedef pthread_key_t oe_thread_key; typedef INIT_ONCE oe_once_type; #define OE_H_ONCE_INITIALIZER INIT_ONCE_STATIC_INIT -typedef DWORD oe_thread; - typedef HANDLE oe_mutex; #define OE_H_MUTEX_INITIALIZER INVALID_HANDLE_VALUE @@ -49,6 +47,25 @@ typedef DWORD oe_thread_key; #endif +/** + * Create a platform-specific thread. + * + * @param func The pointer to the start routine. + * @param arg The argument to the start routine. + * + * @returns Returns zero on success. + */ +int oe_thread_create(oe_thread_t* thread, void* (*func)(void*), void* arg); + +/** + * Join a platform-specific thread. + * + * @param thread The thread to be joined. + * + * @returns Returns zero on success. + */ +int oe_thread_join(oe_thread_t thread); + /** * Returns the identifier of the current thread. * @@ -57,7 +74,7 @@ typedef DWORD oe_thread_key; * * @returns Returns the thread identifier of the calling thread. */ -oe_thread oe_thread_self(void); +oe_thread_t oe_thread_self(void); /** * Checks two thread identifiers for equality. @@ -70,7 +87,7 @@ oe_thread oe_thread_self(void); * * @returns Returns non-zero if the thread identifiers are equal. */ -int oe_thread_equal(oe_thread thread1, oe_thread thread2); +int oe_thread_equal(oe_thread_t thread1, oe_thread_t thread2); /** * Calls the given function exactly once. diff --git a/host/linux/hostthread.c b/host/linux/hostthread.c index 644755768a..65a87251fb 100644 --- a/host/linux/hostthread.c +++ b/host/linux/hostthread.c @@ -13,13 +13,22 @@ ** **============================================================================== */ +int oe_thread_create(oe_thread_t* thread, void* (*func)(void*), void* arg) +{ + return pthread_create(thread, NULL, func, arg); +} + +int oe_thread_join(oe_thread_t thread) +{ + return pthread_join(thread, NULL); +} -oe_thread oe_thread_self(void) +oe_thread_t oe_thread_self(void) { return pthread_self(); } -int oe_thread_equal(oe_thread thread1, oe_thread thread2) +int oe_thread_equal(oe_thread_t thread1, oe_thread_t thread2) { return pthread_equal(thread1, thread2); } diff --git a/host/optee/linux/enclave.c b/host/optee/linux/enclave.c index 06c8c80019..cda2e3bf3f 100644 --- a/host/optee/linux/enclave.c +++ b/host/optee/linux/enclave.c @@ -399,10 +399,15 @@ oe_result_t oe_create_enclave( const char* enclave_path, oe_enclave_type_t enclave_type, uint32_t flags, +#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE + const oe_enclave_config_t* configs, + uint32_t config_count, +#else const void* config, uint32_t config_size, +#endif const oe_ocall_func_t* ocall_table, - uint32_t ocall_table_size, + uint32_t ocall_count, oe_enclave_t** enclave_out) { oe_result_t result = OE_UNEXPECTED; @@ -425,10 +430,15 @@ oe_result_t oe_create_enclave( if (!enclave_path || !enclave_out || ((enclave_type != OE_ENCLAVE_TYPE_OPTEE) && (enclave_type != OE_ENCLAVE_TYPE_AUTO)) || +#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE + (config_count > 0 && configs == NULL) || + (config_count == 0 && configs != NULL) || +#else + config || config_size > 0 || +#endif (flags & OE_ENCLAVE_FLAG_RESERVED) || (!(flags & OE_ENCLAVE_FLAG_SIMULATE) && - (flags & OE_ENCLAVE_FLAG_DEBUG)) || - config || config_size > 0) + (flags & OE_ENCLAVE_FLAG_DEBUG))) OE_RAISE(OE_INVALID_PARAMETER); /* Convert the path into a TEE UUID. */ @@ -482,7 +492,7 @@ oe_result_t oe_create_enclave( enclave->path = strndup( enclave_path, 38); // 37 + 1 = length of a UUID + NULL terminator enclave->ocalls = (const oe_ocall_func_t*)ocall_table; - enclave->num_ocalls = ocall_table_size; + enclave->num_ocalls = ocall_count; *enclave_out = enclave; result = OE_OK; diff --git a/host/sgx/calls.c b/host/sgx/calls.c index 4c21d96ae3..a3fdb0f25f 100644 --- a/host/sgx/calls.c +++ b/host/sgx/calls.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "../calls.h" #include "../hostthread.h" @@ -245,16 +246,14 @@ static oe_result_t _do_eenter( /* **============================================================================== ** -** _handle_call_host_function() +** oe_handle_call_host_function() ** ** Handle calls from the enclave. ** **============================================================================== */ -static oe_result_t _handle_call_host_function( - uint64_t arg, - oe_enclave_t* enclave) +oe_result_t oe_handle_call_host_function(uint64_t arg, oe_enclave_t* enclave) { oe_call_host_function_args_t* args_ptr = NULL; oe_result_t result = OE_OK; @@ -320,6 +319,7 @@ static oe_result_t _handle_call_host_function( &args_ptr->output_bytes_written); // The ocall succeeded. + OE_ATOMIC_MEMORY_BARRIER_RELEASE(); args_ptr->result = OE_OK; result = OE_OK; done: @@ -359,7 +359,8 @@ static const char* oe_ecall_str(oe_func_t ecall) "DESTRUCTOR", "INIT_ENCLAVE", "CALL_ENCLAVE_FUNCTION", - "VIRTUAL_EXCEPTION_HANDLER" + "VIRTUAL_EXCEPTION_HANDLER", + "INIT_CONTEXT_SWITCHLESS", }; // clang-format on @@ -408,7 +409,7 @@ static oe_result_t _handle_ocall( switch ((oe_func_t)func) { case OE_OCALL_CALL_HOST_FUNCTION: - _handle_call_host_function(arg_in, enclave); + OE_CHECK(oe_handle_call_host_function(arg_in, enclave)); break; case OE_OCALL_MALLOC: @@ -567,7 +568,7 @@ static void* _assign_tcs(oe_enclave_t* enclave) { void* tcs = NULL; size_t i; - oe_thread thread = oe_thread_self(); + oe_thread_t thread = oe_thread_self(); oe_mutex_lock(&enclave->lock); { diff --git a/host/sgx/create.c b/host/sgx/create.c index 71d3977893..1a437abb12 100644 --- a/host/sgx/create.c +++ b/host/sgx/create.c @@ -45,6 +45,7 @@ static char* get_fullpath(const char* path) #include #include #include +#include #include #include #include @@ -401,6 +402,52 @@ static oe_result_t _initialize_enclave(oe_enclave_t* enclave) return result; } +/* +** _config_enclave() +** +** Config the enclave with an array of configurations. +*/ +#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE + +static oe_result_t _configure_enclave( + oe_enclave_t* enclave, + const oe_enclave_config_t* configs, + uint32_t config_count) +{ + oe_result_t result = OE_UNEXPECTED; + + for (uint32_t i = 0; i < config_count; i++) + { + switch (configs[i].config_type) + { + // Configure the switchless ocalls, such as the number of workers. + case OE_ENCLAVE_CONFIG_CONTEXT_SWITCHLESS: + { + size_t max_host_workers = + configs[i].u.context_switchless_config->max_host_workers; + size_t max_enclave_workers = + configs[i].u.context_switchless_config->max_enclave_workers; + + // Switchless ecalls are not enabled yet. Make sure the max + // number of enclave workers is always 0. + if (max_enclave_workers != 0) + OE_RAISE(OE_INVALID_PARAMETER); + + OE_CHECK( + oe_start_switchless_manager(enclave, max_host_workers)); + break; + } + default: + OE_RAISE(OE_INVALID_PARAMETER); + } + } + result = OE_OK; + +done: + return result; +} +#endif + oe_result_t oe_sgx_validate_enclave_properties( const oe_sgx_enclave_properties_t* properties, const char** field_name) @@ -644,10 +691,15 @@ oe_result_t oe_create_enclave( const char* enclave_path, oe_enclave_type_t enclave_type, uint32_t flags, +#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE + const oe_enclave_config_t* configs, + uint32_t config_count, +#else const void* config, uint32_t config_size, +#endif const oe_ocall_func_t* ocall_table, - uint32_t ocall_table_size, + uint32_t ocall_count, oe_enclave_t** enclave_out) { oe_result_t result = OE_UNEXPECTED; @@ -663,7 +715,13 @@ oe_result_t oe_create_enclave( if (!enclave_path || !enclave_out || ((enclave_type != OE_ENCLAVE_TYPE_SGX) && (enclave_type != OE_ENCLAVE_TYPE_AUTO)) || - (flags & OE_ENCLAVE_FLAG_RESERVED) || config || config_size > 0) +#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE + (config_count > 0 && configs == NULL) || + (config_count == 0 && configs != NULL) || +#else + config || config_size > 0 || +#endif + (flags & OE_ENCLAVE_FLAG_RESERVED)) OE_RAISE(OE_INVALID_PARAMETER); /* Allocate and zero-fill the enclave structure */ @@ -747,11 +805,16 @@ oe_result_t oe_create_enclave( /* Enclave initialization invokes global constructors which could make * ocalls. Therefore setup ocall table prior to initialization. */ enclave->ocalls = (const oe_ocall_func_t*)ocall_table; - enclave->num_ocalls = ocall_table_size; + enclave->num_ocalls = ocall_count; /* Invoke enclave initialization. */ OE_CHECK(_initialize_enclave(enclave)); +#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE + /* Apply the list of configurations to the enclave */ + OE_CHECK(_configure_enclave(enclave, configs, config_count)); +#endif + /* Setup logging configuration */ oe_log_enclave_init(enclave); @@ -794,6 +857,9 @@ oe_result_t oe_terminate_enclave(oe_enclave_t* enclave) /* Remove this enclave from the global list. */ oe_remove_enclave_instance(enclave); + /* Shut down the switchless manager */ + OE_CHECK(oe_stop_switchless_manager(enclave)); + /* Clear the magic number */ enclave->magic = 0; diff --git a/host/sgx/enclave.h b/host/sgx/enclave.h index e684a3d4a6..b914b488b4 100644 --- a/host/sgx/enclave.h +++ b/host/sgx/enclave.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "../hostthread.h" #include "asmdefs.h" @@ -56,7 +57,7 @@ typedef struct _thread_binding uint64_t tcs; /* The thread this slot is assigned to */ - oe_thread thread; + oe_thread_t thread; /* Flags */ uint64_t flags; @@ -124,6 +125,9 @@ struct _oe_enclave /* Meta-data needed by debugrt */ oe_debug_enclave_t* debug_enclave; + + /* Manager for switchless calls */ + oe_switchless_call_manager_t* switchless_manager; }; // Static asserts for consistency with diff --git a/host/sgx/switchless.c b/host/sgx/switchless.c new file mode 100644 index 0000000000..bd21754dd6 --- /dev/null +++ b/host/sgx/switchless.c @@ -0,0 +1,135 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include +#include +#include +#include +#include "../calls.h" +#include "../hostthread.h" +#include "../ocalls.h" +#include "enclave.h" + +/* +** The thread function that handles switchless ocalls +** +*/ +static void* _switchless_ocall_worker(void* arg) +{ + oe_host_worker_context_t* context = (oe_host_worker_context_t*)arg; + + while (!context->is_stopping) + { + volatile oe_call_host_function_args_t* local_call_arg = NULL; + if ((local_call_arg = context->call_arg) != NULL) + { + context->call_arg = NULL; + oe_handle_call_host_function( + (uint64_t)local_call_arg, context->enclave); + } + } + return NULL; +} + +static oe_result_t oe_stop_worker_threads(oe_switchless_call_manager_t* manager) +{ + oe_result_t result = OE_UNEXPECTED; + for (size_t i = 0; i < manager->num_host_workers; i++) + { + manager->host_worker_contexts[i].is_stopping = true; + } + + for (size_t i = 0; i < manager->num_host_workers; i++) + { + if (manager->host_worker_threads[i] != (oe_thread_t)NULL) + if (oe_thread_join(manager->host_worker_threads[i])) + OE_RAISE(OE_THREAD_JOIN_ERROR); + } + + result = OE_OK; +done: + return result; +} + +oe_result_t oe_start_switchless_manager( + oe_enclave_t* enclave, + size_t num_host_workers) +{ + oe_result_t result = OE_UNEXPECTED; + uint64_t result_out = 0; + oe_switchless_call_manager_t* manager = NULL; + oe_host_worker_context_t* contexts = NULL; + oe_thread_t* threads = NULL; + + if (num_host_workers < 1 || enclave == NULL) + OE_RAISE(OE_INVALID_PARAMETER); + + if (enclave->switchless_manager != NULL) + OE_RAISE(OE_UNEXPECTED); + + // Limit the number of host workers to the number of thread bindings + // because the maximum parallelism is dictated by the latter for + // synchronous ocalls. We may need to revisit this for asynchronous + // calls later. + if (num_host_workers > enclave->num_bindings) + num_host_workers = (uint32_t)enclave->num_bindings; + + // Allocate memory for the manager and its arrays + manager = calloc(1, sizeof(oe_switchless_call_manager_t)); + if (manager == NULL) + OE_RAISE(OE_OUT_OF_MEMORY); + + contexts = calloc(num_host_workers, sizeof(oe_host_worker_context_t)); + if (contexts == NULL) + OE_RAISE(OE_OUT_OF_MEMORY); + + threads = calloc(num_host_workers, sizeof(oe_thread_t)); + if (threads == NULL) + OE_RAISE(OE_OUT_OF_MEMORY); + + manager->num_host_workers = num_host_workers; + manager->host_worker_contexts = contexts; + manager->host_worker_threads = threads; + + // Start the worker threads, and assign each one a private context. + for (size_t i = 0; i < num_host_workers; i++) + { + manager->host_worker_contexts[i].enclave = enclave; + if (oe_thread_create( + &manager->host_worker_threads[i], + _switchless_ocall_worker, + &manager->host_worker_contexts[i]) != 0) + { + oe_stop_worker_threads(manager); + OE_RAISE(OE_THREAD_CREATE_ERROR); + } + } + + // Each enclave has at most one switchless manager. + enclave->switchless_manager = manager; + + // Inform the enclave about the switchless manager through an ECALL + OE_CHECK(oe_ecall( + enclave, + OE_ECALL_INIT_CONTEXT_SWITCHLESS, + (uint64_t)manager, + &result_out)); + OE_CHECK((oe_result_t)result_out); + + result = OE_OK; + +done: + return result; +} + +oe_result_t oe_stop_switchless_manager(oe_enclave_t* enclave) +{ + oe_result_t result = OE_UNEXPECTED; + if (enclave != NULL && enclave->switchless_manager != NULL) + { + OE_CHECK(oe_stop_worker_threads(enclave->switchless_manager)); + } + result = OE_OK; +done: + return result; +} diff --git a/host/traceh.c b/host/traceh.c index e0114eb28d..1d5bc2f9ff 100644 --- a/host/traceh.c +++ b/host/traceh.c @@ -101,7 +101,7 @@ static void _write_message_to_stream( struct tm* t = localtime(<); #endif - oe_thread thread_id = oe_thread_self(); + oe_thread_t thread_id = oe_thread_self(); fprintf( stream, diff --git a/host/windows/hostthread.c b/host/windows/hostthread.c index a7aae96e36..2c42368385 100644 --- a/host/windows/hostthread.c +++ b/host/windows/hostthread.c @@ -3,8 +3,11 @@ #include "../hostthread.h" #include +#include #include +typedef DWORD (*start_routine_t)(void*); + /* **============================================================================== ** @@ -13,12 +16,30 @@ **============================================================================== */ -oe_thread oe_thread_self(void) +int oe_thread_create(oe_thread_t* thread, void* (*func)(void*), void* arg) +{ + start_routine_t start_routine = (start_routine_t)func; + *thread = (oe_thread_t)CreateThread(NULL, 0, start_routine, arg, 0, NULL); + return *thread == (oe_thread_t)NULL ? OE_EINVAL : 0; +} + +int oe_thread_join(oe_thread_t thread) +{ + HANDLE handle = (HANDLE)thread; + if (WaitForSingleObject(handle, INFINITE) == WAIT_OBJECT_0) + { + CloseHandle(handle); + return 0; + } + return OE_EINVAL; +} + +oe_thread_t oe_thread_self(void) { - return GetCurrentThreadId(); + return (oe_thread_t)GetCurrentThreadId(); } -int oe_thread_equal(oe_thread thread1, oe_thread thread2) +int oe_thread_equal(oe_thread_t thread1, oe_thread_t thread2) { return thread1 == thread2; } diff --git a/include/openenclave/bits/result.h b/include/openenclave/bits/result.h index 77aef25bde..9116b48714 100644 --- a/include/openenclave/bits/result.h +++ b/include/openenclave/bits/result.h @@ -314,6 +314,21 @@ typedef enum _oe_result */ OE_VERIFY_FAILED_AES_CMAC_MISMATCH, + /** + * Failed to post a switchless call to host workers + */ + OE_CONTEXT_SWITCHLESS_OCALL_MISSED, + + /** + * Thread creation failed. + */ + OE_THREAD_CREATE_ERROR, + + /** + * Thread join failed. + */ + OE_THREAD_JOIN_ERROR, + __OE_RESULT_MAX = OE_ENUM_MAX, } oe_result_t; /**< typedef enum _oe_result oe_result_t*/ diff --git a/include/openenclave/host.h b/include/openenclave/host.h index 45172e0c89..1f17488e7d 100644 --- a/include/openenclave/host.h +++ b/include/openenclave/host.h @@ -50,6 +50,7 @@ OE_EXTERNC_BEGIN */ #define OE_ENCLAVE_FLAG_RESERVED \ (~(OE_ENCLAVE_FLAG_DEBUG | OE_ENCLAVE_FLAG_SIMULATE)) + /** * @endcond */ @@ -64,6 +65,60 @@ typedef void (*oe_ocall_func_t)( size_t output_buffer_size, size_t* output_bytes_written); +/** + * The following structures are used by context-switchless calls, which is + * experimental, and subject to changes. + */ +#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE + +/** + * Types of configurations passed into **oe_create_enclave** + */ +typedef enum _oe_enclave_config_type +{ + OE_ENCLAVE_CONFIG_CONTEXT_SWITCHLESS = 0xdc73a628, +} oe_enclave_config_type_t; + +/** + * The configuration for context-switchless calls. + */ +typedef struct _oe_enclave_config_context_switchless +{ + /** + * The max number of worker threads for context-switchless ocalls. + * The actual number of threads launched could be capped for performance + * reasons. + */ + size_t max_host_workers; + /** + * Context-switchless ecalls are not enabled yet. The max number of enclave + * workers should be 0. + */ + size_t max_enclave_workers; +} oe_enclave_config_context_switchless_t; + +/** + * The uniform structure type containing a specific type of enclave + * configuration. + */ +typedef struct _oe_enclave_config +{ + /** + * The type of the configuration in **u** + */ + oe_enclave_config_type_t config_type; + /** + * The specific configuration for the enclave, such as configuring + * context-switchless calls. + */ + union { + const oe_enclave_config_context_switchless_t* context_switchless_config; + /* Add new configuration types here. */ + } u; +} oe_enclave_config_t; + +#endif /* OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE */ + /** * Create an enclave from an enclave image file. * @@ -83,15 +138,15 @@ typedef void (*oe_ocall_func_t)( * - OE_ENCLAVE_FLAG_DEBUG - runs the enclave in debug mode. * DO NOT SHIP CODE with this flag * - * @param config Additional enclave creation configuration data for the specific - * enclave type. This parameter is reserved and must be NULL. + * @param configs Array of additional enclave creation configurations for + * the specific enclave type. * - * @param config_size The size of the **config** data buffer in bytes. + * @param config_count The number of configurations in the **configs**. * * @param ocall_table Pointer to table of ocall functions generated by * oeedger8r. * - * @param ocall_table_size The size of the **ocall_table**. + * @param ocall_count The number of functions in the **ocall_table**. * * @param enclave This points to the enclave instance upon success. * @@ -102,10 +157,15 @@ oe_result_t oe_create_enclave( const char* path, oe_enclave_type_t type, uint32_t flags, +#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE + const oe_enclave_config_t* configs, + uint32_t config_count, +#else const void* config, uint32_t config_size, +#endif const oe_ocall_func_t* ocall_table, - uint32_t ocall_table_size, + uint32_t ocall_count, oe_enclave_t** enclave); /** diff --git a/include/openenclave/internal/atomic.h b/include/openenclave/internal/atomic.h index 754babeddf..5e177bc786 100644 --- a/include/openenclave/internal/atomic.h +++ b/include/openenclave/internal/atomic.h @@ -10,8 +10,12 @@ #if defined(_MSC_VER) #pragma intrinsic(_InterlockedIncrement64) #pragma intrinsic(_InterlockedDecrement64) +#pragma intrinsic(_InterlockedCompareExchange64) +#pragma intrinsic(_InterlockedCompareExchangePointer) __int64 _InterlockedIncrement64(__int64* lpAddend); __int64 _InterlockedDecrement64(__int64* lpAddend); +__int64 _InterlockedCompareExchange64(__int64* Dest, __int64 val, __int64 old); +void* _InterlockedCompareExchangePointer(void** Dest, void* newptr, void* old); #endif /* Atomically increment **x** and return its new value */ @@ -38,4 +42,36 @@ OE_INLINE uint64_t oe_atomic_decrement(volatile uint64_t* x) #endif } +OE_INLINE +bool oe_atomic_compare_and_swap( + int64_t volatile* dest, + int64_t old, + int64_t newval) +{ +#if defined(__GNUC__) + return __atomic_compare_exchange_n( + dest, &old, newval, 1, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE); +#elif defined(_MSC_VER) + return _InterlockedCompareExchange64(dest, newval, old) == old; +#else +#error "unsupported" +#endif +} + +OE_INLINE +bool oe_atomic_compare_and_swap_ptr( + void* volatile* dest, + void* old, + void* newptr) +{ +#if defined(__GNUC__) + return __atomic_compare_exchange_n( + dest, &old, newptr, 1, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE); +#elif defined(_MSC_VER) + return _InterlockedCompareExchangePointer(dest, newptr, old) == old; +#else +#error "unsupported" +#endif +} + #endif /* _OE_ATOMIC_H */ diff --git a/include/openenclave/internal/calls.h b/include/openenclave/internal/calls.h index fc9e97c70e..7cf7d91fce 100644 --- a/include/openenclave/internal/calls.h +++ b/include/openenclave/internal/calls.h @@ -75,6 +75,7 @@ typedef enum _oe_func OE_ECALL_INIT_ENCLAVE, OE_ECALL_CALL_ENCLAVE_FUNCTION, OE_ECALL_VIRTUAL_EXCEPTION_HANDLER, + OE_ECALL_INIT_CONTEXT_SWITCHLESS, /* Caution: always add new ECALL function numbers here */ OE_ECALL_MAX, diff --git a/include/openenclave/internal/switchless.h b/include/openenclave/internal/switchless.h new file mode 100644 index 0000000000..7b8d214231 --- /dev/null +++ b/include/openenclave/internal/switchless.h @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#ifndef _OE_SWITCHLESS_H +#define _OE_SWITCHLESS_H + +#include +#include +#include +#include + +typedef struct _host_worker_thread_context +{ + volatile oe_call_host_function_args_t* call_arg; + volatile bool is_stopping; + oe_enclave_t* enclave; +} oe_host_worker_context_t; + +typedef struct _oe_switchless_call_manager +{ + oe_host_worker_context_t* host_worker_contexts; + oe_thread_t* host_worker_threads; + size_t num_host_workers; +} oe_switchless_call_manager_t; + +oe_result_t oe_start_switchless_manager( + oe_enclave_t* enclave, + size_t num_host_workers); + +oe_result_t oe_stop_switchless_manager(oe_enclave_t* enclave); + +#endif /* _OE_SWITCHLESS_H */ diff --git a/include/openenclave/internal/thread.h b/include/openenclave/internal/thread.h index bd848625cc..4371010dc7 100644 --- a/include/openenclave/internal/thread.h +++ b/include/openenclave/internal/thread.h @@ -8,11 +8,11 @@ #include #include +typedef uint64_t oe_thread_t; + #ifdef OE_BUILD_ENCLAVE OE_EXTERNC_BEGIN -typedef uint64_t oe_thread_t; - /* * Note that all the __impl[] fields in the below implementations are * all larger than what is actually needed. This is to account for diff --git a/include/openenclave/internal/utils.h b/include/openenclave/internal/utils.h index 46d8c4ae1e..42c0379c4a 100644 --- a/include/openenclave/internal/utils.h +++ b/include/openenclave/internal/utils.h @@ -6,6 +6,9 @@ #include #include +#if defined(_MSC_VER) +#include +#endif OE_EXTERNC_BEGIN @@ -126,10 +129,17 @@ OE_INLINE uint64_t StrCode(const char* s, uint64_t n) * understanding see "C++ and the Perils of Double-Checked Locking" * http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf. */ +#if defined(__linux__) #define OE_ATOMIC_MEMORY_BARRIER_ACQUIRE() \ __atomic_thread_fence(__ATOMIC_ACQUIRE) #define OE_ATOMIC_MEMORY_BARRIER_RELEASE() \ __atomic_thread_fence(__ATOMIC_RELEASE) +#elif defined(_MSC_VER) +#define OE_ATOMIC_MEMORY_BARRIER_ACQUIRE() _ReadBarrier() +#define OE_ATOMIC_MEMORY_BARRIER_RELEASE() _WriteBarrier() +#else +#error "Unsupported platform" +#endif #if __x86_64__ || _M_X64 #define OE_CPU_RELAX() asm volatile("pause" ::: "memory") diff --git a/tests/create-errors/host/host.c b/tests/create-errors/host/host.c index 2867b4b9be..9222148155 100644 --- a/tests/create-errors/host/host.c +++ b/tests/create-errors/host/host.c @@ -13,6 +13,15 @@ static void _test_invalid_param(const char* path, uint32_t flags) { oe_enclave_t* enclave = NULL; +#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE + oe_enclave_config_t invalid_config = {0, {NULL}}; + oe_enclave_config_context_switchless_t config = {2, 0}; + oe_enclave_config_t configs[] = {{ + .config_type = OE_ENCLAVE_CONFIG_CONTEXT_SWITCHLESS, + .u.context_switchless_config = &config, + }}; +#endif + /* Null path. */ oe_result_t result = oe_create_create_errors_enclave( NULL, OE_ENCLAVE_TYPE_AUTO, flags, NULL, 0, &enclave); @@ -36,11 +45,25 @@ static void _test_invalid_param(const char* path, uint32_t flags) OE_TEST(result == OE_INVALID_PARAMETER); - /* Content field filled. */ +#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE + /* Invalid configuration with incorrect **config_count** */ + result = oe_create_create_errors_enclave( + path, OE_ENCLAVE_TYPE_SGX, flags, &invalid_config, 0, &enclave); + + OE_TEST(result == OE_INVALID_PARAMETER); + + /* Invalid configuration with correct **config_count** */ + result = oe_create_create_errors_enclave( + path, OE_ENCLAVE_TYPE_SGX, flags, &invalid_config, 1, &enclave); + + OE_TEST(result == OE_INVALID_PARAMETER); + + /* Valid configuration with incorrect **config_count** */ result = oe_create_create_errors_enclave( - path, OE_ENCLAVE_TYPE_AUTO, flags, &enclave, 0, &enclave); + path, OE_ENCLAVE_TYPE_SGX, flags, configs, 0, &enclave); OE_TEST(result == OE_INVALID_PARAMETER); +#endif /* Content size non-zero. */ result = oe_create_create_errors_enclave( diff --git a/tests/switchless/enc/CMakeLists.txt b/tests/switchless/enc/CMakeLists.txt index 0e4c7ec0f2..d60a56b861 100644 --- a/tests/switchless/enc/CMakeLists.txt +++ b/tests/switchless/enc/CMakeLists.txt @@ -3,7 +3,9 @@ add_custom_command( OUTPUT switchless_t.h switchless_t.c switchless_args.h - DEPENDS ../switchless.edl + DEPENDS + edger8r + ../switchless.edl COMMAND edger8r --experimental --trusted --search-path ${CMAKE_CURRENT_SOURCE_DIR}/.. switchless.edl) # Dummy target used for generating from EDL on demand. diff --git a/tests/switchless/enc/enc.c b/tests/switchless/enc/enc.c index 1829f26c40..3c7041075e 100644 --- a/tests/switchless/enc/enc.c +++ b/tests/switchless/enc/enc.c @@ -6,56 +6,71 @@ #include #include "switchless_t.h" -char* oe_host_strdup(const char* str) -{ - size_t n = oe_strlen(str); - - char* dup = (char*)oe_host_calloc(1, n + 1); - - if (dup) - memcpy(dup, str, n + 1); +#define STRING_LEN 100 +#define STRING_HELLO "Hello World" +#define HOST_PARAM_STRING "host string parameter" +#define HOST_STACK_STRING "host string on stack" - return dup; -} - -int enc_echo(char* in, char out[100]) +int enc_echo_switchless(char* in, char out[STRING_LEN], int repeats) { oe_result_t result; - if (oe_strcmp(in, "Hello World") != 0) + if (oe_strcmp(in, STRING_HELLO) != 0) { return -1; } - char* host_allocated_str = oe_host_strdup("oe_host_strdup2"); - if (host_allocated_str == NULL) + char stack_allocated_str[STRING_LEN] = HOST_STACK_STRING; + int return_val; + + for (int i = 0; i < repeats; i++) { - return -1; + result = host_echo_switchless( + &return_val, in, out, HOST_PARAM_STRING, stack_allocated_str); + if (result != OE_OK) + { + return -1; + } + + if (return_val != 0) + { + return -1; + } } - char stack_allocated_str[100] = "oe_host_strdup3"; - int return_val; + oe_host_printf("Hello from switchless Echo function!\n"); - result = host_echo( - &return_val, - in, - out, - "oe_host_strdup1", - host_allocated_str, - stack_allocated_str); - if (result != OE_OK) + return 0; +} + +int enc_echo_regular(char* in, char out[STRING_LEN], int repeats) +{ + oe_result_t result; + + if (oe_strcmp(in, STRING_HELLO) != 0) { return -1; } - if (return_val != 0) + char stack_allocated_str[STRING_LEN] = HOST_STACK_STRING; + int return_val; + + for (int i = 0; i < repeats; i++) { - return -1; - } + result = host_echo_regular( + &return_val, in, out, HOST_PARAM_STRING, stack_allocated_str); + if (result != OE_OK) + { + return -1; + } - oe_host_printf("Hello from Echo function!\n"); + if (return_val != 0) + { + return -1; + } + } - oe_host_free(host_allocated_str); + oe_host_printf("Hello from regular Echo function!\n"); return 0; } @@ -66,4 +81,4 @@ OE_SET_ENCLAVE_SGX( true, /* AllowDebug */ 1024, /* HeapPageCount */ 1024, /* StackPageCount */ - 16); /* TCSCount */ + 2); /* TCSCount */ diff --git a/tests/switchless/host/CMakeLists.txt b/tests/switchless/host/CMakeLists.txt index 3464b68275..bd9dcd8019 100644 --- a/tests/switchless/host/CMakeLists.txt +++ b/tests/switchless/host/CMakeLists.txt @@ -3,7 +3,9 @@ add_custom_command( OUTPUT switchless_u.h switchless_u.c switchless_args.h - DEPENDS ../switchless.edl + DEPENDS + edger8r + ../switchless.edl COMMAND edger8r --experimental --untrusted --search-path ${CMAKE_CURRENT_SOURCE_DIR}/.. switchless.edl) # Dummy target used for generating from EDL on demand. diff --git a/tests/switchless/host/host.c b/tests/switchless/host/host.c index 907c245f1d..38706fa597 100644 --- a/tests/switchless/host/host.c +++ b/tests/switchless/host/host.c @@ -9,40 +9,31 @@ #include #include #include +#include #include "../../../host/strings.h" #include "switchless_u.h" #define NUM_HOST_THREADS 16 +#define STRING_LEN 100 -int host_echo(char* in, char* out, char* str1, char* str2, char str3[100]) +int host_echo_switchless(char* in, char* out, char* str1, char str2[STRING_LEN]) { - OE_TEST(strcmp(str1, "oe_host_strdup1") == 0); - OE_TEST(strcmp(str2, "oe_host_strdup2") == 0); - OE_TEST(strcmp(str3, "oe_host_strdup3") == 0); + OE_TEST(strcmp(str1, "host string parameter") == 0); + OE_TEST(strcmp(str2, "host string on stack") == 0); strcpy(out, in); return 0; } -void* host_thread(void* arg) +int host_echo_regular(char* in, char* out, char* str1, char str2[STRING_LEN]) { - char out[100]; - int return_val; - - oe_enclave_t* enclave = (oe_enclave_t*)arg; - oe_result_t result = enc_echo(enclave, &return_val, "Hello World", out); - - if (result != OE_OK) - oe_put_err("oe_call_enclave() failed: result=%u", result); - - if (return_val != 0) - oe_put_err("ECALL failed args.result=%d", return_val); + OE_TEST(strcmp(str1, "host string parameter") == 0); + OE_TEST(strcmp(str2, "host string on stack") == 0); - if (strcmp("Hello World", out) != 0) - oe_put_err("ecall failed: %s != %s\n", "Hello World", out); + strcpy(out, in); - return NULL; + return 0; } int main(int argc, const char* argv[]) @@ -58,30 +49,63 @@ int main(int argc, const char* argv[]) const uint32_t flags = oe_get_create_flags(); +#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE + // Enable switchless and configure host worker number + oe_enclave_config_context_switchless_t config = {2, 0}; + oe_enclave_config_t configs[] = {{ + .config_type = OE_ENCLAVE_CONFIG_CONTEXT_SWITCHLESS, + .u.context_switchless_config = &config, + }}; + + if ((result = oe_create_switchless_enclave( + argv[1], + OE_ENCLAVE_TYPE_SGX, + flags, + configs, + OE_COUNTOF(configs), + &enclave)) != OE_OK) +#else if ((result = oe_create_switchless_enclave( argv[1], OE_ENCLAVE_TYPE_SGX, flags, NULL, 0, &enclave)) != OE_OK) +#endif oe_put_err("oe_create_enclave(): result=%u", result); - pthread_t threads[NUM_HOST_THREADS]; - for (int i = 0; i < NUM_HOST_THREADS; i++) - { - int ret = 0; - if ((ret = pthread_create(&threads[i], 0, host_thread, enclave))) - { - oe_put_err("pthread_create(host): ret=%u", ret); - } - else - printf("created thread %u\n", i); - } + char out[STRING_LEN]; + int return_val; - for (int i = 0; i < NUM_HOST_THREADS; i++) - { - pthread_join(threads[i], NULL); - } + double switchless_microseconds = 0; + struct timespec start, end; + + // Increase this number to have a meaningful performance measurement + int repeats = 10; + + clock_gettime(CLOCK_REALTIME, &start); + OE_TEST( + enc_echo_switchless( + enclave, &return_val, "Hello World", out, repeats) == OE_OK); + clock_gettime(CLOCK_REALTIME, &end); + switchless_microseconds += (double)(end.tv_sec - start.tv_sec) * 1000000.0 + + (double)(end.tv_nsec - start.tv_nsec) / 1000.0; + + double regular_microseconds = 0; + clock_gettime(CLOCK_REALTIME, &start); + OE_TEST( + enc_echo_regular(enclave, &return_val, "Hello World", out, repeats) == + OE_OK); + clock_gettime(CLOCK_REALTIME, &end); + regular_microseconds += (double)(end.tv_sec - start.tv_sec) * 1000000.0 + + (double)(end.tv_nsec - start.tv_nsec) / 1000.0; result = oe_terminate_enclave(enclave); OE_TEST(result == OE_OK); + printf( + "Time spent in repeating OCALL %d times: switchless %d vs " + "regular %d ms, speed up: %.2f\n", + repeats, + (int)switchless_microseconds / 1000, + (int)regular_microseconds / 1000, + (double)regular_microseconds / switchless_microseconds); printf("=== passed all tests (switchless)\n"); return 0; diff --git a/tests/switchless/switchless.edl b/tests/switchless/switchless.edl index 6cc0cf7dd9..eeb038ffbb 100644 --- a/tests/switchless/switchless.edl +++ b/tests/switchless/switchless.edl @@ -3,18 +3,28 @@ enclave { trusted { - public int enc_echo( + public int enc_echo_switchless( [string, in] char* in, - [out] char out[100]); + [out] char out[100], + int repeats); + public int enc_echo_regular( + [string, in] char* in, + [out] char out[100], + int repeats); }; untrusted { - int host_echo( + int host_echo_switchless( [string, in] char* in, [out] char out[100], [string, in] char* str1, - [user_check] char* str2, - [in] char str3[100]) + [in] char str2[100]) transition_using_threads; + + int host_echo_regular( + [string, in] char* in, + [out] char out[100], + [string, in] char* str1, + [in] char str2[100]); }; }; diff --git a/tools/oeedger8r/Emitter.ml b/tools/oeedger8r/Emitter.ml index ec641db196..07bbb8de60 100644 --- a/tools/oeedger8r/Emitter.ml +++ b/tools/oeedger8r/Emitter.ml @@ -1368,8 +1368,13 @@ let gen_enclave_code (ec : enclave_content) (ep : edger8r_params) = ; " const char* path," ; " oe_enclave_type_t type," ; " uint32_t flags," + ; "#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE" + ; " const oe_enclave_config_t* configs," + ; " uint32_t config_count," + ; "#else" ; " const void* config," ; " uint32_t config_size," + ; "#endif" ; " oe_enclave_t** enclave);" ; "" ; "/**** ECALL prototypes. ****/" @@ -1427,16 +1432,26 @@ let gen_enclave_code (ec : enclave_content) (ep : edger8r_params) = ; " const char* path," ; " oe_enclave_type_t type," ; " uint32_t flags," + ; "#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE" + ; " const oe_enclave_config_t* configs," + ; " uint32_t config_count," + ; "#else" ; " const void* config," ; " uint32_t config_size," + ; "#endif" ; " oe_enclave_t** enclave)" ; "{" ; " return oe_create_enclave(" ; " path," ; " type," ; " flags," + ; "#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE" + ; " configs," + ; " config_count," + ; "#else" ; " config," ; " config_size," + ; "#endif" ; sprintf " __%s_ocall_function_table," ec.enclave_name ; sprintf " %d," (List.length ufs) ; " enclave);" From 10ea77d9cf22b2690bb2109fb4dba6eef216563b Mon Sep 17 00:00:00 2001 From: Oprin Date: Wed, 18 Sep 2019 15:04:18 +0300 Subject: [PATCH 022/420] OpenSSL standalone install on Windows --- scripts/install-windows-prereqs.ps1 | 34 +++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/scripts/install-windows-prereqs.ps1 b/scripts/install-windows-prereqs.ps1 index 0248eec0d3..a65318f790 100644 --- a/scripts/install-windows-prereqs.ps1 +++ b/scripts/install-windows-prereqs.ps1 @@ -5,6 +5,8 @@ Param( [string]$GitURL = 'https://github.com/git-for-windows/git/releases/download/v2.19.1.windows.1/Git-2.19.1-64-bit.exe', [string]$GitHash = '5E11205840937DD4DFA4A2A7943D08DA7443FAA41D92CCC5DAFBB4F82E724793', + [string]$OpenSSLURL = 'https://slproweb.com/download/Win64OpenSSL-1_1_1d.exe', + [string]$OpenSSLHash = '6AFA17D0768CF91B6F69F31FBC67CAB1AC2E3F40CCAAADB7A9D6C7FC37B38492', [string]$SevenZipURL = 'https://www.7-zip.org/a/7z1806-x64.msi', [string]$SevenZipHash = 'F00E1588ED54DDF633D8652EB89D0A8F95BD80CCCFC3EED362D81927BEC05AA5', [string]$VSBuildToolsURL = 'https://aka.ms/vs/15/release/vs_buildtools.exe', @@ -110,6 +112,10 @@ $PACKAGES = @{ "hash" = $AzureDCAPNupkgHash "local_file" = Join-Path $PACKAGES_DIRECTORY "Azure.DCAP.Windows.nupkg" } + "openssl" = @{ + "url" = $OpenSSLURL + "local_file" = Join-Path $PACKAGES_DIRECTORY "Win64OpenSSL-1_1_1d.exe" + } } filter Timestamp { "[$(Get-Date -Format o)] $_" } @@ -318,6 +324,29 @@ function Install-Git { -EnvironmentPath @("$installDir\cmd", "$installDir\bin", "$installDir\mingw64\bin") } +function Install-OpenSSL { + $installDir = $installDir = Join-Path $env:ProgramFiles "OpenSSL-Win64" + Install-Tool -InstallerPath $PACKAGES["openssl"]["local_file"] ` + -InstallDirectory $installDir ` + -ArgumentList @("/silent", "/eula=accept") ` + -EnvironmentPath @($installDir) + + $binDir = Join-Path $installDir "bin" + $systemPath = [System.Environment]::GetEnvironmentVariable('Path', 'Machine') + $currentPath = $env:PATH + if($binDir -notin $systemPath) { + $systemPath = "$binDir;$systemPath" + } + if($binDir -notin $currentPath) { + $currentPath = "$binDir;$currentPath" + } + $env:PATH = $currentPath + setx.exe /M PATH $systemPath + if($LASTEXITCODE) { + Throw "Failed to set the new system path" + } +} + function Install-7Zip { $installDir = Join-Path $env:ProgramFiles "7-Zip" Install-Tool -InstallerPath $PACKAGES["7z"]["local_file"] ` @@ -585,16 +614,17 @@ try { Install-7Zip Install-Nuget Install-VisualStudio + Install-OpenSSL Install-LLVM Install-Git Install-OCaml Install-Shellcheck Install-PSW - + if ($DCAPClientType -eq "Azure") { Write-Host "*** Installing Azure.DCAP.Windows ***" - Install-AzureDCAPWindows + Install-AzureDCAPWindows } else { From 5d100018f576f49eea3320511092ac10d68748c5 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 18 Sep 2019 22:18:13 +0000 Subject: [PATCH 023/420] Fix some language in contributing and governance --- docs/Contributing.md | 23 +++++++++++++---------- docs/Governance.md | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/Contributing.md b/docs/Contributing.md index 8e52b43a8b..58e541511a 100644 --- a/docs/Contributing.md +++ b/docs/Contributing.md @@ -82,15 +82,17 @@ Please do: - **DO** submit all code changes via pull requests (PRs) rather than through a direct commit. PRs will be reviewed and potentially merged by the repo Committers after a peer review that includes at least one Committer. -- **DO** give PRs short-but-descriptive names (e.g. "Improve code coverage for - System.Console by 10%", not "Fix #1234"). +- **DO** give PRs short but descriptive names (e.g. "Improve code coverage for + edger8r", not "Fix #1234"). - **DO** add breaking changes, new features, deprecations, and bug - fixes to the [unreleased section of the - changelog](../CHANGELOG.md#unreleased). + fixes to the [unreleased section of the changelog](../CHANGELOG.md#unreleased). - **DO** refer to any relevant issues and include [keywords]( https://help.github.com/articles/closing-issues-via-commit-messages/) that automatically close issues when the PR is merged. -- **DO** tag any users that should know about and/or review the change. +- **DO** tag any users that should know about and/or review the change. While + [CODEOWNERS](https://help.github.com/en/articles/about-code-owners) should + automatically tag reviewers, if you know of specific people that should look + at a PR, add them too. - **DO** ensure each commit successfully builds on all platforms and passes all unit tests. - **DO** rebase and squash unnecessary commits before opening the PR, so that @@ -103,8 +105,8 @@ Please do: Please do not: - **DON'T** make PRs for style changes. For example, do not send PRs that are - focused on changing usage of ```Int32``` to ```int```. The team would prefer - to address these holistically with tooling. + focused on changing usage of `SomeVar` to `some_var`. The team would prefer + to address these with automated tooling. - **DON'T** surprise us with big pull requests. Instead, file an issue and start a discussion so we can agree on a direction before you invest a large amount of time. @@ -120,11 +122,12 @@ Please do not: discuss it. - **DON'T** submit changes to the public API without filing an issue and discussing with us first. -- **DON'T** submit "work in progress" PRs. A PR should only be submitted when - it is considered ready for review and subsequent merging by the contributor. +- **DON'T** use GitHub [_Draft_ pull + requests](https://help.github.com/en/articles/about-pull-requests#draft-pull-requests) + to share work-in-progress. This will suppress CODEOWNER notifications - **DON'T** fix merge conflicts using a merge commit. Prefer `git rebase`. - **DON'T** mix independent, unrelated changes in one PR. Separate real - product/test code changes from larger code formatting/dead code removal + project/test code changes from larger code formatting/dead code removal changes. Separate unrelated fixes into separate PRs, especially if they are in different libraries. diff --git a/docs/Governance.md b/docs/Governance.md index d4e4669d75..d909cb9212 100644 --- a/docs/Governance.md +++ b/docs/Governance.md @@ -58,7 +58,7 @@ areas of expertise for each of the committers. Accepting Contributions ----------------------- -Project committers will merge changes that improve the product significantly and +Project committers will merge changes that improve the project significantly and broadly and that align with the [Open Enclave roadmap](https://github.com/openenclave/openenclave/projects). Contributions must also satisfy the other [published guidelines](Contributing.md). From 3be0dff179b0ebcfca6124aaeac362a9f09d7577 Mon Sep 17 00:00:00 2001 From: Xuejun Yang Date: Sun, 22 Sep 2019 03:47:18 +0000 Subject: [PATCH 024/420] Add a sample and a multi-threaded test for switchless * Add a sample to illustrade switchless calls * Explain the concept of switchless calls in the sameple readme * Remove the experimental feature guard for switchless * Add a multi-threaded switchless test case * Enable both single-threaded and multi-threaded switchless tests on Windows --- host/optee/linux/enclave.c | 9 - host/sgx/create.c | 13 -- include/openenclave/host.h | 13 -- samples/CMakeLists.txt | 2 +- samples/README.md | 7 + samples/switchless/CMakeLists.txt | 35 ++++ samples/switchless/Makefile | 20 +++ samples/switchless/README.md | 133 +++++++++++++++ samples/switchless/enclave/CMakeLists.txt | 16 ++ samples/switchless/enclave/Makefile | 40 +++++ samples/switchless/enclave/enc.c | 31 ++++ samples/switchless/enclave/switchless.conf | 10 ++ samples/switchless/host/CMakeLists.txt | 14 ++ samples/switchless/host/Makefile | 28 ++++ samples/switchless/host/host.c | 77 +++++++++ samples/switchless/switchless.edl | 13 ++ samples/test-samples.cmake | 2 +- tests/CMakeLists.txt | 3 +- tests/create-errors/host/host.c | 4 - tests/switchless/host/host.c | 52 ++++-- tests/switchless_threads/CMakeLists.txt | 12 ++ tests/switchless_threads/enc/CMakeLists.txt | 17 ++ tests/switchless_threads/enc/enc.c | 75 +++++++++ tests/switchless_threads/host/CMakeLists.txt | 17 ++ tests/switchless_threads/host/host.c | 156 ++++++++++++++++++ .../switchless_threads/switchless_threads.edl | 29 ++++ tools/oeedger8r/Emitter.ml | 15 -- 27 files changed, 770 insertions(+), 73 deletions(-) create mode 100644 samples/switchless/CMakeLists.txt create mode 100644 samples/switchless/Makefile create mode 100644 samples/switchless/README.md create mode 100644 samples/switchless/enclave/CMakeLists.txt create mode 100644 samples/switchless/enclave/Makefile create mode 100644 samples/switchless/enclave/enc.c create mode 100644 samples/switchless/enclave/switchless.conf create mode 100644 samples/switchless/host/CMakeLists.txt create mode 100644 samples/switchless/host/Makefile create mode 100644 samples/switchless/host/host.c create mode 100644 samples/switchless/switchless.edl create mode 100644 tests/switchless_threads/CMakeLists.txt create mode 100644 tests/switchless_threads/enc/CMakeLists.txt create mode 100644 tests/switchless_threads/enc/enc.c create mode 100644 tests/switchless_threads/host/CMakeLists.txt create mode 100644 tests/switchless_threads/host/host.c create mode 100644 tests/switchless_threads/switchless_threads.edl diff --git a/host/optee/linux/enclave.c b/host/optee/linux/enclave.c index cda2e3bf3f..bba574714d 100644 --- a/host/optee/linux/enclave.c +++ b/host/optee/linux/enclave.c @@ -399,13 +399,8 @@ oe_result_t oe_create_enclave( const char* enclave_path, oe_enclave_type_t enclave_type, uint32_t flags, -#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE const oe_enclave_config_t* configs, uint32_t config_count, -#else - const void* config, - uint32_t config_size, -#endif const oe_ocall_func_t* ocall_table, uint32_t ocall_count, oe_enclave_t** enclave_out) @@ -430,12 +425,8 @@ oe_result_t oe_create_enclave( if (!enclave_path || !enclave_out || ((enclave_type != OE_ENCLAVE_TYPE_OPTEE) && (enclave_type != OE_ENCLAVE_TYPE_AUTO)) || -#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE (config_count > 0 && configs == NULL) || (config_count == 0 && configs != NULL) || -#else - config || config_size > 0 || -#endif (flags & OE_ENCLAVE_FLAG_RESERVED) || (!(flags & OE_ENCLAVE_FLAG_SIMULATE) && (flags & OE_ENCLAVE_FLAG_DEBUG))) diff --git a/host/sgx/create.c b/host/sgx/create.c index 1a437abb12..42c15f5d1a 100644 --- a/host/sgx/create.c +++ b/host/sgx/create.c @@ -407,7 +407,6 @@ static oe_result_t _initialize_enclave(oe_enclave_t* enclave) ** ** Config the enclave with an array of configurations. */ -#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE static oe_result_t _configure_enclave( oe_enclave_t* enclave, @@ -446,7 +445,6 @@ static oe_result_t _configure_enclave( done: return result; } -#endif oe_result_t oe_sgx_validate_enclave_properties( const oe_sgx_enclave_properties_t* properties, @@ -691,13 +689,8 @@ oe_result_t oe_create_enclave( const char* enclave_path, oe_enclave_type_t enclave_type, uint32_t flags, -#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE const oe_enclave_config_t* configs, uint32_t config_count, -#else - const void* config, - uint32_t config_size, -#endif const oe_ocall_func_t* ocall_table, uint32_t ocall_count, oe_enclave_t** enclave_out) @@ -715,12 +708,8 @@ oe_result_t oe_create_enclave( if (!enclave_path || !enclave_out || ((enclave_type != OE_ENCLAVE_TYPE_SGX) && (enclave_type != OE_ENCLAVE_TYPE_AUTO)) || -#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE (config_count > 0 && configs == NULL) || (config_count == 0 && configs != NULL) || -#else - config || config_size > 0 || -#endif (flags & OE_ENCLAVE_FLAG_RESERVED)) OE_RAISE(OE_INVALID_PARAMETER); @@ -810,10 +799,8 @@ oe_result_t oe_create_enclave( /* Invoke enclave initialization. */ OE_CHECK(_initialize_enclave(enclave)); -#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE /* Apply the list of configurations to the enclave */ OE_CHECK(_configure_enclave(enclave, configs, config_count)); -#endif /* Setup logging configuration */ oe_log_enclave_init(enclave); diff --git a/include/openenclave/host.h b/include/openenclave/host.h index 1f17488e7d..c5bf4cc045 100644 --- a/include/openenclave/host.h +++ b/include/openenclave/host.h @@ -65,12 +65,6 @@ typedef void (*oe_ocall_func_t)( size_t output_buffer_size, size_t* output_bytes_written); -/** - * The following structures are used by context-switchless calls, which is - * experimental, and subject to changes. - */ -#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE - /** * Types of configurations passed into **oe_create_enclave** */ @@ -117,8 +111,6 @@ typedef struct _oe_enclave_config } u; } oe_enclave_config_t; -#endif /* OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE */ - /** * Create an enclave from an enclave image file. * @@ -157,13 +149,8 @@ oe_result_t oe_create_enclave( const char* path, oe_enclave_type_t type, uint32_t flags, -#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE const oe_enclave_config_t* configs, uint32_t config_count, -#else - const void* config, - uint32_t config_size, -#endif const oe_ocall_func_t* ocall_table, uint32_t ocall_count, oe_enclave_t** enclave); diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index fdd493a7ef..edb5621b1f 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -9,7 +9,7 @@ if (USE_LIBSGX) GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ) endif () -install(DIRECTORY helloworld file-encryptor data-sealing +install(DIRECTORY helloworld file-encryptor data-sealing switchless DESTINATION ${CMAKE_INSTALL_DATADIR}/openenclave/samples) install(FILES README.md diff --git a/samples/README.md b/samples/README.md index c90c3e129d..fdcdd1c772 100644 --- a/samples/README.md +++ b/samples/README.md @@ -147,3 +147,10 @@ The following samples demonstrate how to develop enclave applications using OE A - between two enclaves - between one non-enclave client and an enclave +#### [Switchless Calls](switchless/README.md) + +- Explain the concept of switchless calls +- Demonstrate how to enable switchless calls in an enclave application in steps: + - Mark a function as `transition_using_threads` + - Enable and configure switchless for an enclave + - Making a switchless call diff --git a/samples/switchless/CMakeLists.txt b/samples/switchless/CMakeLists.txt new file mode 100644 index 0000000000..740d88835d --- /dev/null +++ b/samples/switchless/CMakeLists.txt @@ -0,0 +1,35 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +cmake_minimum_required(VERSION 3.11) + +project("Switchless Call Sample" LANGUAGES C CXX) + +find_package(OpenEnclave CONFIG REQUIRED) + +set(CMAKE_CXX_STANDARD 11) + +add_subdirectory(enclave) +add_subdirectory(host) + +# Generate key +add_custom_command(OUTPUT private.pem public.pem + COMMAND openssl genrsa -out private.pem -3 3072 + COMMAND openssl rsa -in private.pem -pubout -out public.pem) + +# Sign enclave +add_custom_command(OUTPUT enclave/enclave.signed + DEPENDS enclave enclave/switchless.conf private.pem + COMMAND openenclave::oesign sign -e $ -c ${CMAKE_SOURCE_DIR}/enclave/switchless.conf -k private.pem) + +add_custom_target(sign ALL DEPENDS enclave/enclave.signed) + +if ((NOT DEFINED ENV{OE_SIMULATION}) OR (NOT $ENV{OE_SIMULATION})) + add_custom_target(run + DEPENDS switchless_host sign + COMMAND switchless_host ${CMAKE_BINARY_DIR}/enclave/enclave.signed) +endif () + +add_custom_target(simulate + DEPENDS switchless_host sign + COMMAND switchless_host ${CMAKE_BINARY_DIR}/enclave/enclave.signed --simulate) diff --git a/samples/switchless/Makefile b/samples/switchless/Makefile new file mode 100644 index 0000000000..5ec9108611 --- /dev/null +++ b/samples/switchless/Makefile @@ -0,0 +1,20 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +.PHONY: all build clean run simulate + +all: build + +build: + $(MAKE) -C enclave + $(MAKE) -C host + +clean: + $(MAKE) -C enclave clean + $(MAKE) -C host clean + +run: + host/switchlesshost ./enclave/switchlessenc.signed + +simulate: + host/switchlesshost ./enclave/switchlessenc.signed --simulate diff --git a/samples/switchless/README.md b/samples/switchless/README.md new file mode 100644 index 0000000000..93af5368bd --- /dev/null +++ b/samples/switchless/README.md @@ -0,0 +1,133 @@ +# Switchless Calls Sample + +This sample demonstrates how to make switchless calls to host from inside an enclave. It is built on top of the [`Hello World`](../helloworld/README.md) sample. The addition is a host function `host_helloworld_switchless` which is called from the enclave switchlessly. + +It has the following properties: + +- Explain the concept of switchless calls +- Demonstrate how to mark a function as `transition_using_threads` in EDL, and use [`oeedger8r`](https://github.com/openenclave/openenclave/tree/master/docs/GettingStartedDocs/Edger8rGettingStarted.md) tool to compile it +- Demonstrate how to configure an enclave to enable switchless calls within it + +Prerequisite: you may want to read [Common Sample Information](../README.md#common-sample-information) before going further. + +## Switchless Calls + +In an enclave application, the host makes **ECALL**s into functions exposed by the enclaves it created. Likewise, the enclaves make **OCALL**s into functions exposed by the host that created them. In either case, the execution has to be transitioned from an untrusted environment to a trusted environment, or vice versa. Since the transition is costly due to heavy security checks, it might be more performance advantageous to make the calls **context-switchless**: the caller delegates the function call to a worker thread in the other environment, which does the real job of calling the function and post the result to the caller. Both the calling thread and the worker thread never leave their respective execution contexts during the perceived function call. + +The calling thread and the worker thread need to exchange information twice during the call. When the switchless call is initiated, the caller needs to pass the `job` (representing the function call) to the worker thread. And when the call finishes, the worker thread needs to pass the result back to the caller. Both exchanges need to be synchronized. + +## How does OE support switchless OCALLs + +OE only supports synchronous switchless OCALLs currently. When the caller within an enclave makes a switchless OCALL, the trusted OE runtime creates a `job` out of the function call. The `job` object includes information such as the function ID, the parameters marshaled into a buffer, and a buffer for holding the return value(s). The job is posted to a shared memory region which both the enclave and the host can access. + +A host worker thread checks and retrieves `job` from the shared memory region. It uses the untrusted OE runtime to process the `job` by unmarshaling the parameters, then dispatching to the callee function, and finally relaying the result back to the trusted OE runtime, which is further forwarded back to the caller. + +To support simultaneous switchless OCALLs made from enclaves, the host workers are multi-threaded. OE allows users to configure how many host worker threads are to be created for servicing switchless OCALLs. The following example illustrates how to do that. A word of caution is that too many host worker threads might increase competition of cores between threads and degrade the performance. Therefore, if a enclave has switchless calls enabled, OE caps the number of host worker threads for it to the number of enclave threads specified. + +## About the EDL + +First we need to define the functions we want to call between the host and the enclave. To do this we create a `switchless.edl` file: + +```edl +enclave { + trusted { + public void enclave_helloworld(); + + }; + + untrusted { + void host_helloworld(); + void host_helloworld_switchless() transition_using_threads; + }; +}; +``` + +Function `host_helloworld_switchless`'s declaration ends with keyword `transition_using_threads`, indicating it should be called switchlessly at run time. However, this a best-effort directive. OE runtime may still choose to fall back to a tradition OCALL if switchless call resources are unavailable, e.g., the enclave is not configured as switchless-capable, or the host worker threads are busy servicing other switchless OCALLs. + +To generate the functions with the marshaling code, the `oeedger8r` tool is called in both the host and enclave directories from their Makefiles. For example: + +```bash +cd host +oeedger8r ../switchless.edl --untrusted --experimental +``` + +`oeedger8r` needs the command line flag `--experimental` to be able to recognize the keyword `transition_using_threads`. + +## About the host + +The host first defines a structure specifically for configuring switchless calls. In this case, we specify the first field `2` as the number of host worker threads for switchless OCALLs. The 2nd field specifies the number of enclave threads for switchless ECALLs. Since switchless ECALL is not yet implementated, we require the 2nd field to be `0`. + +```c +oe_enclave_config_context_switchless_t config = {2, 0}; +``` + +The host then puts the structure address and the configuration type in an array of configurations for the enclave to be created. Even though we only have one configuration (for switchless) for the enclave, we'd like the flexibility of adding more than one configurations (with different types) for an enclave in the future. + +```c +oe_enclave_config_t configs[] = {{ + .config_type = OE_ENCLAVE_CONFIG_CONTEXT_SWITCHLESS, + .u.context_switchless_config = &config, + }}; +``` + +To make the configurations created above effective, we need to pass the array `configs` into `oe_create_enclave` in the following way: + +```c +oe_create_switchless_enclave( + argv[1], + OE_ENCLAVE_TYPE_SGX, + flags, + configs, + OE_COUNTOF(configs), + &enclave); +``` + +The host then makes an ECALL of `enclave_helloworld` to transition into the enclave. After the ECALL returns, the host terminates the enclave. + +As shown in the EDL file, the host exposes two host functions: `host_helloworld` and `host_helloworld_switchless`. The former prints "Hello world from regular OCALL", and the latter prints "Hello world from switchless OCALL". + +## About the enclave + +The enclave exposes only one function `enclave_helloworld`. The function prints "Hello world from the enclave" first, then call the host function `host_helloworld`, followed by calling host function `host_helloworld_switchless`. Internally, the last call is fulfilled switchlessly. If everything work as expected, the output of this enclave function would be: + +``` +Hello world from the enclave +Hello world from regular OCALL +Hello world from switchless OCALL +``` + +## Build and run + +Note that there are two different build systems supported, one using GNU Make and +`pkg-config`, the other using CMake. + +### CMake + +This uses the CMake package provided by the Open Enclave SDK. + +```bash +cd switchless +mkdir build && cd build +cmake .. +make run +``` + +### GNU Make + +```bash +cd helloworld +make build +make run +``` +#### Note + +switchless sample can run under OE simulation mode. + +To run the switchless sample in simulation mode from the command like, use the following: + +```bash +# if built with cmake +./host/switchless_host ./enclave/switchless_enc.signed --simulate +# or, if built with GNU Make and pkg-config +make simulate +``` diff --git a/samples/switchless/enclave/CMakeLists.txt b/samples/switchless/enclave/CMakeLists.txt new file mode 100644 index 0000000000..51770083ef --- /dev/null +++ b/samples/switchless/enclave/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +# Use the edger8r to generate C bindings from the EDL file. +add_custom_command(OUTPUT switchless_t.h switchless_t.c switchless_args.h + DEPENDS ${CMAKE_SOURCE_DIR}/switchless.edl + COMMAND openenclave::oeedger8r --experimental --trusted ${CMAKE_SOURCE_DIR}/switchless.edl) + +add_executable(enclave enc.c ${CMAKE_CURRENT_BINARY_DIR}/switchless_t.c) + +target_compile_definitions(enclave PUBLIC OE_API_VERSION=2) + +# Need for the generated file switchless_t.h +target_include_directories(enclave PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + +target_link_libraries(enclave openenclave::oeenclave openenclave::oelibc) diff --git a/samples/switchless/enclave/Makefile b/samples/switchless/enclave/Makefile new file mode 100644 index 0000000000..2fb5e4121f --- /dev/null +++ b/samples/switchless/enclave/Makefile @@ -0,0 +1,40 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +# Detect C and C++ compiler options +# if not gcc, default to clang-7 + +COMPILER=$(notdir $(CC)) +ifeq ($(COMPILER), gcc) + USE_GCC = true +endif + +ifeq ($(USE_GCC),) + CC = clang-7 + COMPILER=clang +endif + +CFLAGS=$(shell pkg-config oeenclave-$(COMPILER) --cflags) +LDFLAGS=$(shell pkg-config oeenclave-$(COMPILER) --libs) + +all: + $(MAKE) build + $(MAKE) keys + $(MAKE) sign + +build: + @ echo "Compilers used: $(CC), $(CXX)" + oeedger8r ../switchless.edl --trusted --experimental + $(CC) -g -c $(CFLAGS) -DOE_API_VERSION=2 enc.c -o enc.o + $(CC) -g -c $(CFLAGS) -DOE_API_VERSION=2 switchless_t.c -o switchless_t.o + $(CC) -o switchlessenc switchless_t.o enc.o $(LDFLAGS) + +sign: + oesign sign -e switchlessenc -c switchless.conf -k private.pem + +clean: + rm -f enc.o switchlessenc switchlessenc.signed private.pem public.pem switchless_t.o switchless_t.h switchless_t.c switchless_args.h + +keys: + openssl genrsa -out private.pem -3 3072 + openssl rsa -in private.pem -pubout -out public.pem diff --git a/samples/switchless/enclave/enc.c b/samples/switchless/enclave/enc.c new file mode 100644 index 0000000000..483562c7a9 --- /dev/null +++ b/samples/switchless/enclave/enc.c @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include +#include "switchless_t.h" + +void enclave_helloworld() +{ + fprintf(stdout, "Hello world from the enclave\n"); + + // Call back into the host + oe_result_t result = host_helloworld(); + if (result != OE_OK) + { + fprintf(stderr, "host_helloworld(): result=%u", result); + } + + result = host_helloworld_switchless(); + if (result != OE_OK) + { + fprintf(stderr, "host_helloworld_switchless(): result=%u", result); + } +} + +OE_SET_ENCLAVE_SGX( + 1, /* ProductID */ + 1, /* SecurityVersion */ + true, /* AllowDebug */ + 1024, /* HeapPageCount */ + 1024, /* StackPageCount */ + 2); /* TCSCount */ diff --git a/samples/switchless/enclave/switchless.conf b/samples/switchless/enclave/switchless.conf new file mode 100644 index 0000000000..5d4ce9ef95 --- /dev/null +++ b/samples/switchless/enclave/switchless.conf @@ -0,0 +1,10 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +# Enclave settings: +Debug=1 +NumHeapPages=1024 +NumStackPages=1024 +NumTCS=1 +ProductID=1 +SecurityVersion=1 diff --git a/samples/switchless/host/CMakeLists.txt b/samples/switchless/host/CMakeLists.txt new file mode 100644 index 0000000000..79ba9764e2 --- /dev/null +++ b/samples/switchless/host/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +add_custom_command(OUTPUT switchless_u.h switchless_u.c switchless_args.h + DEPENDS ${CMAKE_SOURCE_DIR}/switchless.edl + COMMAND openenclave::oeedger8r --experimental --untrusted ${CMAKE_SOURCE_DIR}/switchless.edl) + +add_executable(switchless_host host.c ${CMAKE_CURRENT_BINARY_DIR}/switchless_u.c) + +target_include_directories(switchless_host PRIVATE + # Needed for the generated file switchless_u.h + ${CMAKE_CURRENT_BINARY_DIR}) + +target_link_libraries(switchless_host openenclave::oehostapp) diff --git a/samples/switchless/host/Makefile b/samples/switchless/host/Makefile new file mode 100644 index 0000000000..cceb1a40e5 --- /dev/null +++ b/samples/switchless/host/Makefile @@ -0,0 +1,28 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +# Detect C and C++ compiler options +# if not gcc, default to clang-7 + +COMPILER=$(notdir $(CC)) +ifeq ($(COMPILER), gcc) + USE_GCC = true +endif + +ifeq ($(USE_GCC),) + CC = clang-7 + COMPILER=clang +endif + +CFLAGS=$(shell pkg-config oehost-$(COMPILER) --cflags) +LDFLAGS=$(shell pkg-config oehost-$(COMPILER) --libs) + +build: + @ echo "Compilers used: $(CC), $(CXX)" + oeedger8r ../switchless.edl --untrusted --experimental + $(CC) -g -c $(CFLAGS) host.c + $(CC) -g -c $(CFLAGS) switchless_u.c + $(CC) -o switchlesshost switchless_u.o host.o $(LDFLAGS) + +clean: + rm -f switchlesshost host.o switchless_u.o switchless_u.c switchless_u.h switchless_args.h diff --git a/samples/switchless/host/host.c b/samples/switchless/host/host.c new file mode 100644 index 0000000000..9b39ab2af1 --- /dev/null +++ b/samples/switchless/host/host.c @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include +#include +#include +#include "switchless_u.h" + +void host_helloworld() +{ + fprintf(stdout, "Hello world from regular OCALL\n"); +} + +void host_helloworld_switchless() +{ + fprintf(stdout, "Hello world from switchless OCALL\n"); +} + +static bool check_simulate_opt(int* argc, const char* argv[]) +{ + for (int i = 0; i < *argc; i++) + { + if (strcmp(argv[i], "--simulate") == 0) + { + fprintf(stderr, "Running in simulation mode\n"); + memmove(&argv[i], &argv[i + 1], (*argc - i) * sizeof(char*)); + (*argc)--; + return true; + } + } + return false; +} + +int main(int argc, const char* argv[]) +{ + oe_enclave_t* enclave = NULL; + oe_result_t result; + int ret = 1; + + if (argc != 2 && argc != 3) + { + fprintf(stderr, "Usage: %s ENCLAVE_PATH [--simulate]\n", argv[0]); + return 1; + } + + uint32_t flags = OE_ENCLAVE_FLAG_DEBUG; + if (check_simulate_opt(&argc, argv)) + { + flags |= OE_ENCLAVE_FLAG_SIMULATE; + } + + // Enable switchless and configure host worker number + oe_enclave_config_context_switchless_t config = {2, 0}; + oe_enclave_config_t configs[] = {{ + .config_type = OE_ENCLAVE_CONFIG_CONTEXT_SWITCHLESS, + .u.context_switchless_config = &config, + }}; + + if ((result = oe_create_switchless_enclave( + argv[1], + OE_ENCLAVE_TYPE_SGX, + flags, + configs, + OE_COUNTOF(configs), + &enclave)) != OE_OK) + fprintf(stderr, "oe_create_enclave(): result=%u", result); + + // Call into the enclave + result = enclave_helloworld(enclave); + if (result != OE_OK) + fprintf(stderr, "enclave_helloworld(): result=%u", result); + + ret = result != OE_OK ? 1 : 0; + oe_terminate_enclave(enclave); + + return ret; +} diff --git a/samples/switchless/switchless.edl b/samples/switchless/switchless.edl new file mode 100644 index 0000000000..b8df7cebd8 --- /dev/null +++ b/samples/switchless/switchless.edl @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +enclave { + trusted { + public void enclave_helloworld(); + }; + + untrusted { + void host_helloworld(); + void host_helloworld_switchless() transition_using_threads; + }; +}; diff --git a/samples/test-samples.cmake b/samples/test-samples.cmake index 5338bc4e7b..d814ed795d 100644 --- a/samples/test-samples.cmake +++ b/samples/test-samples.cmake @@ -7,7 +7,7 @@ # cmake -DUSE_LIBSGX=ON -DSOURCE_DIR=~/openenclave -DBUILD_DIR=~/openenclave/build -DPREFIX_DIR=/opt/openenclave -P ~/openenclave/samples/test-samples.cmake # These two samples can run in simulation, and therefore run in every configuration. -set(SAMPLES_LIST helloworld file-encryptor) +set(SAMPLES_LIST helloworld file-encryptor switchless) if ($ENV{OE_SIMULATION}) message(WARNING "Running only sample simulation tests due to OE_SIMULATION=$ENV{OE_SIMULATION}!") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 04f5d7fbba..cb4d4af8aa 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,6 +27,8 @@ if (OE_SGX) add_subdirectory(aesm) add_subdirectory(debugger) add_subdirectory(host_verify) + add_subdirectory(switchless) + add_subdirectory(switchless_threads) endif() if (UNIX OR ADD_WINDOWS_ENCLAVE_TESTS OR USE_CLANGW) @@ -96,5 +98,4 @@ if (OE_SGX AND UNIX) # Attestation supported only on Linux add_subdirectory(tls_e2e) - add_subdirectory(switchless) endif() diff --git a/tests/create-errors/host/host.c b/tests/create-errors/host/host.c index 9222148155..7b0dc3af69 100644 --- a/tests/create-errors/host/host.c +++ b/tests/create-errors/host/host.c @@ -13,14 +13,12 @@ static void _test_invalid_param(const char* path, uint32_t flags) { oe_enclave_t* enclave = NULL; -#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE oe_enclave_config_t invalid_config = {0, {NULL}}; oe_enclave_config_context_switchless_t config = {2, 0}; oe_enclave_config_t configs[] = {{ .config_type = OE_ENCLAVE_CONFIG_CONTEXT_SWITCHLESS, .u.context_switchless_config = &config, }}; -#endif /* Null path. */ oe_result_t result = oe_create_create_errors_enclave( @@ -45,7 +43,6 @@ static void _test_invalid_param(const char* path, uint32_t flags) OE_TEST(result == OE_INVALID_PARAMETER); -#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE /* Invalid configuration with incorrect **config_count** */ result = oe_create_create_errors_enclave( path, OE_ENCLAVE_TYPE_SGX, flags, &invalid_config, 0, &enclave); @@ -63,7 +60,6 @@ static void _test_invalid_param(const char* path, uint32_t flags) path, OE_ENCLAVE_TYPE_SGX, flags, configs, 0, &enclave); OE_TEST(result == OE_INVALID_PARAMETER); -#endif /* Content size non-zero. */ result = oe_create_create_errors_enclave( diff --git a/tests/switchless/host/host.c b/tests/switchless/host/host.c index 38706fa597..d6ff0290f9 100644 --- a/tests/switchless/host/host.c +++ b/tests/switchless/host/host.c @@ -5,17 +5,35 @@ #include #include #include -#include #include #include #include #include +#if _MSC_VER +#include +#endif #include "../../../host/strings.h" #include "switchless_u.h" -#define NUM_HOST_THREADS 16 #define STRING_LEN 100 +#if _MSC_VER +static double frequency; +#endif + +double get_relative_time_in_microseconds() +{ +#if __GNUC__ + struct timespec current_time; + clock_gettime(CLOCK_REALTIME, ¤t_time); + return current_time.tv_sec * 1000000 + current_time.tv_nsec / 1000.0; +#elif _MSC_VER + double current_time; + QueryPerformanceCounter(¤t_time); + return current_time / frequency; +#endif +} + int host_echo_switchless(char* in, char* out, char* str1, char str2[STRING_LEN]) { OE_TEST(strcmp(str1, "host string parameter") == 0); @@ -47,9 +65,13 @@ int main(int argc, const char* argv[]) return 1; } +#if _MSC_VER + QueryPerformanceFrequency(&frequency); + frequency /= 1000000; // convert to microseconds +#endif + const uint32_t flags = oe_get_create_flags(); -#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE // Enable switchless and configure host worker number oe_enclave_config_context_switchless_t config = {2, 0}; oe_enclave_config_t configs[] = {{ @@ -64,37 +86,35 @@ int main(int argc, const char* argv[]) configs, OE_COUNTOF(configs), &enclave)) != OE_OK) -#else - if ((result = oe_create_switchless_enclave( - argv[1], OE_ENCLAVE_TYPE_SGX, flags, NULL, 0, &enclave)) != OE_OK) -#endif oe_put_err("oe_create_enclave(): result=%u", result); char out[STRING_LEN]; int return_val; double switchless_microseconds = 0; - struct timespec start, end; + double start, end; // Increase this number to have a meaningful performance measurement int repeats = 10; - clock_gettime(CLOCK_REALTIME, &start); + start = get_relative_time_in_microseconds(); + OE_TEST( enc_echo_switchless( enclave, &return_val, "Hello World", out, repeats) == OE_OK); - clock_gettime(CLOCK_REALTIME, &end); - switchless_microseconds += (double)(end.tv_sec - start.tv_sec) * 1000000.0 + - (double)(end.tv_nsec - start.tv_nsec) / 1000.0; + + end = get_relative_time_in_microseconds(); + switchless_microseconds = end - start; double regular_microseconds = 0; - clock_gettime(CLOCK_REALTIME, &start); + start = get_relative_time_in_microseconds(); + OE_TEST( enc_echo_regular(enclave, &return_val, "Hello World", out, repeats) == OE_OK); - clock_gettime(CLOCK_REALTIME, &end); - regular_microseconds += (double)(end.tv_sec - start.tv_sec) * 1000000.0 + - (double)(end.tv_nsec - start.tv_nsec) / 1000.0; + + end = get_relative_time_in_microseconds(); + regular_microseconds = end - start; result = oe_terminate_enclave(enclave); OE_TEST(result == OE_OK); diff --git a/tests/switchless_threads/CMakeLists.txt b/tests/switchless_threads/CMakeLists.txt new file mode 100644 index 0000000000..3627f2c6ce --- /dev/null +++ b/tests/switchless_threads/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +add_custom_target(switchless_threads_gen DEPENDS switchless_threads_enc_gen switchless_threads_host_gen) + +add_subdirectory(host) + +if (BUILD_ENCLAVES) + add_subdirectory(enc) +endif() + +add_enclave_test(tests/switchless_threads switchless_threads_host switchless_threads_enc) \ No newline at end of file diff --git a/tests/switchless_threads/enc/CMakeLists.txt b/tests/switchless_threads/enc/CMakeLists.txt new file mode 100644 index 0000000000..b6f6895238 --- /dev/null +++ b/tests/switchless_threads/enc/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +add_custom_command( + OUTPUT switchless_threads_t.h switchless_threads_t.c switchless_threads_args.h + DEPENDS + edger8r + ../switchless_threads.edl + COMMAND edger8r --experimental --trusted --search-path ${CMAKE_CURRENT_SOURCE_DIR}/.. switchless_threads.edl) + +# Dummy target used for generating from EDL on demand. +add_custom_target(switchless_threads_enc_gen DEPENDS switchless_threads_t.h switchless_threads_t.c switchless_threads_args.h) + +add_enclave(TARGET switchless_threads_enc UUID 6e818629-0ce7-46cd-822a-6c7e081fc68b SOURCES enc.c switchless_threads_t.c) + +target_include_directories(switchless_threads_enc PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(switchless_threads_enc oelibc) diff --git a/tests/switchless_threads/enc/enc.c b/tests/switchless_threads/enc/enc.c new file mode 100644 index 0000000000..bd582a528e --- /dev/null +++ b/tests/switchless_threads/enc/enc.c @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include +#include +#include +#include "switchless_threads_t.h" + +#define STRING_LEN 100 +#define STRING_HELLO "Hello World" +#define HOST_PARAM_STRING "host string parameter" +#define HOST_STACK_STRING "host string on stack" + +int enc_echo_single(char* in, char out[100]) +{ + oe_result_t result; + + if (oe_strcmp(in, STRING_HELLO) != 0) + { + return -1; + } + + char stack_allocated_str[STRING_LEN] = HOST_STACK_STRING; + int return_val; + + result = host_echo_regular( + &return_val, in, out, HOST_PARAM_STRING, stack_allocated_str); + + if (result != OE_OK || return_val != 0) + return -1; + + result = host_echo_switchless( + &return_val, in, out, HOST_PARAM_STRING, stack_allocated_str); + + if (result != OE_OK || return_val != 0) + return -1; + + return 0; +} + +int enc_echo_multiple(char* in, char out[STRING_LEN], int repeats) +{ + oe_result_t result; + + if (oe_strcmp(in, STRING_HELLO) != 0) + { + return -1; + } + + char stack_allocated_str[STRING_LEN] = HOST_STACK_STRING; + int return_val; + + for (int i = 0; i < repeats; i++) + { + result = host_echo_regular( + &return_val, in, out, HOST_PARAM_STRING, stack_allocated_str); + if (result != OE_OK || return_val != 0) + return -1; + + result = host_echo_switchless( + &return_val, in, out, HOST_PARAM_STRING, stack_allocated_str); + if (result != OE_OK || return_val != 0) + return -1; + } + + return 0; +} + +OE_SET_ENCLAVE_SGX( + 1, /* ProductID */ + 1, /* SecurityVersion */ + true, /* AllowDebug */ + 1024, /* HeapPageCount */ + 1024, /* StackPageCount */ + 8); /* TCSCount */ diff --git a/tests/switchless_threads/host/CMakeLists.txt b/tests/switchless_threads/host/CMakeLists.txt new file mode 100644 index 0000000000..99f3d8b81e --- /dev/null +++ b/tests/switchless_threads/host/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +add_custom_command( + OUTPUT switchless_threads_u.h switchless_threads_u.c switchless_threads_args.h + DEPENDS + edger8r + ../switchless_threads.edl + COMMAND edger8r --experimental --untrusted --search-path ${CMAKE_CURRENT_SOURCE_DIR}/.. switchless_threads.edl) + +# Dummy target used for generating from EDL on demand. +add_custom_target(switchless_threads_host_gen DEPENDS switchless_threads_u.h switchless_threads_u.c switchless_threads_args.h) + +add_executable(switchless_threads_host host.c switchless_threads_u.c) + +target_include_directories(switchless_threads_host PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(switchless_threads_host oehostapp) diff --git a/tests/switchless_threads/host/host.c b/tests/switchless_threads/host/host.c new file mode 100644 index 0000000000..0651601862 --- /dev/null +++ b/tests/switchless_threads/host/host.c @@ -0,0 +1,156 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include +#include +#include +#include + +#include +#include +#include +#if __GNUC__ +#include +#elif _MSC_VER +#include +#endif +#include "switchless_threads_u.h" + +#define NUM_HOST_THREADS 7 +#define STRING_LEN 100 +#define STRING_HELLO "Hello World" +#define HOST_PARAM_STRING "host string parameter" +#define HOST_STACK_STRING "host string on stack" + +static int thread_create(oe_thread_t* thread, void* (*func)(void*), void* arg) +{ +#if __GNUC__ + return pthread_create(thread, NULL, func, arg); +#elif _MSC_VER + typedef DWORD (*start_routine_t)(void*); + start_routine_t start_routine = (start_routine_t)func; + *thread = (oe_thread_t)CreateThread(NULL, 0, start_routine, arg, 0, NULL); + return *thread == (oe_thread_t)NULL ? 1 : 0; +#endif +} + +static int thread_join(oe_thread_t thread) +{ +#if __GNUC__ + return pthread_join(thread, NULL); +#elif _MSC_VER + HANDLE handle = (HANDLE)thread; + if (WaitForSingleObject(handle, INFINITE) == WAIT_OBJECT_0) + { + CloseHandle(handle); + return 0; + } + return 1; +#endif +} + +int host_echo_switchless(char* in, char* out, char* str1, char str2[STRING_LEN]) +{ + OE_TEST(strcmp(str1, HOST_PARAM_STRING) == 0); + OE_TEST(strcmp(str2, HOST_STACK_STRING) == 0); + + strcpy(out, in); + + return 0; +} + +int host_echo_regular(char* in, char* out, char* str1, char str2[STRING_LEN]) +{ + OE_TEST(strcmp(str1, HOST_PARAM_STRING) == 0); + OE_TEST(strcmp(str2, HOST_STACK_STRING) == 0); + + strcpy(out, in); + + return 0; +} + +void* thread_func(void* arg) +{ + char out[100]; + int return_val; + + oe_enclave_t* enclave = (oe_enclave_t*)arg; + oe_result_t result = + enc_echo_single(enclave, &return_val, "Hello World", out); + + if (result != OE_OK) + oe_put_err("oe_call_enclave() failed: result=%u", result); + + if (return_val != 0) + oe_put_err("ECALL failed args.result=%d", return_val); + + if (strcmp("Hello World", out) != 0) + oe_put_err("ecall failed: %s != %s\n", "Hello World", out); + + return NULL; +} + +int main(int argc, const char* argv[]) +{ + oe_enclave_t* enclave = NULL; + oe_result_t result; + + if (argc != 2) + { + fprintf(stderr, "Usage: %s ENCLAVE_PATH\n", argv[0]); + return 1; + } + + const uint32_t flags = oe_get_create_flags(); + + // Enable switchless and configure host worker number + oe_enclave_config_context_switchless_t config = {2, 0}; + oe_enclave_config_t configs[] = {{ + .config_type = OE_ENCLAVE_CONFIG_CONTEXT_SWITCHLESS, + .u.context_switchless_config = &config, + }}; + + if ((result = oe_create_switchless_threads_enclave( + argv[1], + OE_ENCLAVE_TYPE_SGX, + flags, + configs, + OE_COUNTOF(configs), + &enclave)) != OE_OK) + oe_put_err("oe_create_enclave(): result=%u", result); + + oe_thread_t threads[NUM_HOST_THREADS]; + + // Start threads that each invokes 'enc_echo_single', an ECALL that makes + // only one regular OCALL and one switchless OCALL. + for (int i = 0; i < NUM_HOST_THREADS; i++) + { + int ret = 0; + if ((ret = thread_create(&threads[i], thread_func, enclave))) + { + oe_put_err("thread_create(host): ret=%u", ret); + } + } + + // Invoke 'enc_echo_multiple` which makes multiple regular OCALLs and + // multiple switchless OCALLs. + char out[STRING_LEN]; + int return_val; + int repeats = 10; + OE_TEST( + enc_echo_multiple(enclave, &return_val, "Hello World", out, repeats) == + OE_OK); + + // Wait for the threads to complete. + for (int i = 0; i < NUM_HOST_THREADS; i++) + { + thread_join(threads[i]); + } + + result = oe_terminate_enclave(enclave); + OE_TEST(result == OE_OK); + + printf("=== passed all tests (switchless_threads)\n"); + + return 0; +} diff --git a/tests/switchless_threads/switchless_threads.edl b/tests/switchless_threads/switchless_threads.edl new file mode 100644 index 0000000000..b5921c9a0f --- /dev/null +++ b/tests/switchless_threads/switchless_threads.edl @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +enclave { + trusted { + public int enc_echo_single( + [string, in] char* in, + [out] char out[100]); + public int enc_echo_multiple( + [string, in] char* in, + [out] char out[100], + int repeats); + }; + + untrusted { + int host_echo_switchless( + [string, in] char* in, + [out] char out[100], + [string, in] char* str1, + [in] char str2[100]) + transition_using_threads; + + int host_echo_regular( + [string, in] char* in, + [out] char out[100], + [string, in] char* str1, + [in] char str2[100]); + }; +}; diff --git a/tools/oeedger8r/Emitter.ml b/tools/oeedger8r/Emitter.ml index 07bbb8de60..76e0d71e1c 100644 --- a/tools/oeedger8r/Emitter.ml +++ b/tools/oeedger8r/Emitter.ml @@ -1368,13 +1368,8 @@ let gen_enclave_code (ec : enclave_content) (ep : edger8r_params) = ; " const char* path," ; " oe_enclave_type_t type," ; " uint32_t flags," - ; "#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE" ; " const oe_enclave_config_t* configs," ; " uint32_t config_count," - ; "#else" - ; " const void* config," - ; " uint32_t config_size," - ; "#endif" ; " oe_enclave_t** enclave);" ; "" ; "/**** ECALL prototypes. ****/" @@ -1432,26 +1427,16 @@ let gen_enclave_code (ec : enclave_content) (ep : edger8r_params) = ; " const char* path," ; " oe_enclave_type_t type," ; " uint32_t flags," - ; "#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE" ; " const oe_enclave_config_t* configs," ; " uint32_t config_count," - ; "#else" - ; " const void* config," - ; " uint32_t config_size," - ; "#endif" ; " oe_enclave_t** enclave)" ; "{" ; " return oe_create_enclave(" ; " path," ; " type," ; " flags," - ; "#ifdef OE_CONTEXT_SWITCHLESS_EXPERIMENTAL_FEATURE" ; " configs," ; " config_count," - ; "#else" - ; " config," - ; " config_size," - ; "#endif" ; sprintf " __%s_ocall_function_table," ec.enclave_name ; sprintf " %d," (List.length ufs) ; " enclave);" From ef6cd1f0bb925e1f9e550e6ea5d4f0a0cef3acfe Mon Sep 17 00:00:00 2001 From: Simon Leet Date: Mon, 16 Sep 2019 20:55:19 +0000 Subject: [PATCH 025/420] Update mbedtls_hardware_poll to use RDSEED According to the [Intel DRNG implementation guide]( https://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide), Open Enclave can provide stronger prediction resistance by seeding the mbedTLS random number generator with RDSEED, or by condensing the entropy provided by RDRAND through several rounds of reseeding of its internal DRNG. This changeset applies this guidance: - Update rand.asm/rand.S files to support RDSEED via `oe_rdseed`. - Also update the `oe_rdrand` instruction to PAUSE prior to each retry as suggested by the DRNG implementation guide. - Change `oe_get_entropy` API to return the source of entropy provided. - This allows the entropy intialization function in the crypto library to compensate for the lower quality of RDRAND by condensing it. - This responsibility is delegated to the crypto library as condensing the entropy requires a cryptographic hashing function (e.g. AES-CBC-CMAC, SHA2) which is not available in `oecore` for `oe_get_entropy`. - Update `mbedtls_hardware_poll` implementation to condense entropy from RDRAND as suggested by the Intel DRNG implementation guide when RDSEED is not available. - While most SGX-capable systems will have RDSEED available, this is not guaranteed for all Intel SKUs, or in simulation mode. - Update tests/crypto to also test `oe_rdseed` implementation. - Also rename `TestRdrand` to `TestCpuEntropy` to reflect this. - Reduced the number of iterations for oe_rdrand as it does not manage to saturate the RDRAND interface single-threaded anyway. See #2188. Fixes #242. --- 3rdparty/mbedtls/mbedtls_hardware_poll.c | 118 ++++++++++++++++++++++- common/sgx/rand.S | 25 +++-- common/sgx/rand.asm | 32 +++--- enclave/core/optee/entropy.c | 4 +- enclave/core/sgx/entropy.c | 94 ++++++++++++------ include/openenclave/internal/cpuid.h | 4 +- include/openenclave/internal/entropy.h | 21 +++- include/openenclave/internal/rdrand.h | 2 +- include/openenclave/internal/rdseed.h | 24 +++++ tests/crypto/cpu_entropy_test.c | 57 +++++++++++ tests/crypto/enclave/enc/CMakeLists.txt | 2 +- tests/crypto/host/CMakeLists.txt | 2 +- tests/crypto/rdrand_test.c | 28 ------ tests/crypto/tests.c | 4 +- tests/crypto/tests.h | 2 +- 15 files changed, 332 insertions(+), 87 deletions(-) create mode 100644 include/openenclave/internal/rdseed.h create mode 100644 tests/crypto/cpu_entropy_test.c delete mode 100644 tests/crypto/rdrand_test.c diff --git a/3rdparty/mbedtls/mbedtls_hardware_poll.c b/3rdparty/mbedtls/mbedtls_hardware_poll.c index d8dcb18c6b..06a2e8b48a 100644 --- a/3rdparty/mbedtls/mbedtls_hardware_poll.c +++ b/3rdparty/mbedtls/mbedtls_hardware_poll.c @@ -3,9 +3,90 @@ #include #include +#include +#include "mbedtls/include/mbedtls/platform.h" +#include "mbedtls/include/mbedtls/sha512.h" + +/* Per https://software.intel.com/en-us/articles/intel-digital-random-number + * -generator-drng-software-implementation-guide, reading 512 x 128-bit values + * causes RDRAND to reseed */ +#define RDRAND_RESEED_SIZE_BYTES 8192 + +#define SHA512_HASH_LENGTH_BYTES 64 int mbedtls_hardware_poll(void*, unsigned char*, size_t, size_t*); +static void _fill_buffer( + uint8_t* source, + size_t source_size, + uint8_t** target, + size_t* target_size) +{ + size_t copy_size = + (*target_size > source_size) ? source_size : *target_size; + memcpy(*target, source, copy_size); + *target += copy_size; + *target_size -= copy_size; +} + +static int _get_seed_from_rdrand(uint8_t** seed, size_t* seed_size) +{ + int ret = -1; + uint8_t* rdrand_seed = NULL; + uint8_t* rdrand_bytes = NULL; + oe_entropy_kind_t kind = OE_ENTROPY_KIND_NONE; + + /* Per Intel's DRNG software implementation guide we try to obtain an + * equivalent amount of entropy by condensing several reseed windows of + * RDRAND into a single value. + * + * The DRBG that underlies RDRAND is limited to 128-bit security, so the + * seed for each consecutive RDRAND_RESEED_SIZE_BYTES of data can be + * recovered with 2^128 rounds of work. In general, to achieve N*128 bits + * of security, we need a buffer of (N+1)*RDRAND_RESEED_SIZE_BYTES bytes. + * To get to 256-bit security, similar to RDSEED for 32-bytes, we use N=3. + * + * Note that we hash this down to a 512-bit (64-byte) value via SHA-512 to + * avoid loss of entropy that would otherwise occur in hash collisions when + * mapping 256-bits of unique values into a 256-bit hash space. + */ + size_t rdrand_bytes_size = RDRAND_RESEED_SIZE_BYTES * 3; + rdrand_bytes = (uint8_t*)mbedtls_calloc(1, rdrand_bytes_size); + if (!rdrand_bytes) + goto done; + + if (oe_get_entropy(rdrand_bytes, rdrand_bytes_size, &kind) != OE_OK || + kind != OE_ENTROPY_KIND_RDRAND) + goto done; + + /* Hash the bytes down to a single 64-byte seed value */ + rdrand_seed = (uint8_t*)mbedtls_calloc(1, SHA512_HASH_LENGTH_BYTES); + if (!rdrand_seed) + goto done; + + if (mbedtls_sha512_ret(rdrand_bytes, rdrand_bytes_size, rdrand_seed, 0) != + 0) + goto done; + + *seed_size = SHA512_HASH_LENGTH_BYTES; + *seed = rdrand_seed; + rdrand_seed = NULL; + ret = 0; + +done: + if (rdrand_bytes) + { + mbedtls_free(rdrand_bytes); + rdrand_bytes = NULL; + } + if (rdrand_seed) + { + mbedtls_free(rdrand_seed); + rdrand_seed = NULL; + } + return ret; +} + /* * MBEDTLS links this function definition when MBEDTLS_ENTROPY_HARDWARE_ALT * is defined in the MBEDTLS config.h file. This is the sole source of entropy @@ -19,13 +100,48 @@ int mbedtls_hardware_poll( size_t* olen) { int ret = -1; + oe_entropy_kind_t kind = OE_ENTROPY_KIND_NONE; OE_UNUSED(data); if (olen) *olen = 0; - if (oe_get_entropy(output, len) != OE_OK) + if (oe_get_entropy(output, len, &kind) != OE_OK) + goto done; + + if (kind == OE_ENTROPY_KIND_RDSEED || kind == OE_ENTROPY_KIND_OPTEE) + { + /* According to Intel's DRNG software implementation guide, RDSEED + * produces values that are already passed through a conditioner that + * hashes pairs of 256-bit raw entropy samples via AES-CBC-MAC, so no + * further work needs to be done. + * + * For OPTEE TEE_GenerateRandom, the actual predictive resistance of + * underlying implementation may vary, so this simply takes the value + * provided as is. */ + } + else if (kind == OE_ENTROPY_KIND_RDRAND) + { + /* If RDSEED is not supported, fallback to using RDRAND to obtain a + * seed for entropy. */ + unsigned char* p = (unsigned char*)output; + size_t bytes_left = len; + while (bytes_left > 0) + { + uint8_t* seed_bytes = NULL; + size_t seed_size = 0; + + if (_get_seed_from_rdrand(&seed_bytes, &seed_size) != OE_OK) + goto done; + + _fill_buffer(seed_bytes, seed_size, &p, &bytes_left); + mbedtls_free(seed_bytes); + } + } + else + { goto done; + } if (olen) *olen = len; diff --git a/common/sgx/rand.S b/common/sgx/rand.S index 948a7d08db..154a29b6d8 100644 --- a/common/sgx/rand.S +++ b/common/sgx/rand.S @@ -3,15 +3,28 @@ .text .globl oe_rdrand +.type oe_rdrand, @function +.globl oe_rdseed +.type oe_rdseed, @function oe_rdrand: - pushq %rbp - movq %rsp, %rbp - +.cfi_startproc _rdrand_retry: rdrand %rax - jnc _rdrand_retry - - leave + jc _rdrand_epilogue + pause + jmp _rdrand_retry +_rdrand_epilogue: ret +.cfi_endproc +oe_rdseed: +.cfi_startproc +_rdseed_retry: + rdseed %rax + jc _rdseed_epilogue + pause + jmp _rdseed_retry +_rdseed_epilogue: + ret +.cfi_endproc diff --git a/common/sgx/rand.asm b/common/sgx/rand.asm index 9045b7907a..ff7bdc413d 100644 --- a/common/sgx/rand.asm +++ b/common/sgx/rand.asm @@ -4,22 +4,30 @@ PUBLIC oe_rdrand oe_rdrand PROC -;; Subroutine Prologue - push rbp ;; Save the old base pointer value. - mov rbp, rsp ;; Set the new base pointer value. - sub rsp, 4 ;; Make room for one 4-byte local variable. -;; Subroutine Body _rdrand_retry: - rdrand rax - jnc _rdrand_retry + rdrand rax + jc _rdrand_epilogue + pause + jmp _rdrand_retry -;; Subroutine Epilogue - mov rsp, rbp ;; Deallocate local variables - pop rbp ;; Restore the caller's base pointer value - - ret +_rdrand_epilogue: + ret oe_rdrand ENDP +PUBLIC oe_rdseed +oe_rdseed PROC + +_rdseed_retry: + rdseed rax + jc _rdseed_epilogue + pause + jmp _rdseed_retry + +_rdseed_epilogue: + ret + +oe_rdseed ENDP + END diff --git a/enclave/core/optee/entropy.c b/enclave/core/optee/entropy.c index 174d625fd0..131ac8b55d 100644 --- a/enclave/core/optee/entropy.c +++ b/enclave/core/optee/entropy.c @@ -7,12 +7,12 @@ #include -oe_result_t oe_get_entropy(void* output, size_t len) +oe_result_t oe_get_entropy(void* output, size_t len, oe_entropy_kind_t* kind) { if (len > OE_UINT32_MAX) return OE_OUT_OF_BOUNDS; TEE_GenerateRandom(output, (uint32_t)len); - + *kind = OE_ENTROPY_KIND_OPTEE; return OE_OK; } diff --git a/enclave/core/sgx/entropy.c b/enclave/core/sgx/entropy.c index b526bf872d..bdf5c31836 100644 --- a/enclave/core/sgx/entropy.c +++ b/enclave/core/sgx/entropy.c @@ -1,48 +1,86 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include +#include #include #include +#include #include +#include +#include "cpuid.h" -/* TODO: This should use RDSEED instead. See issue #242. */ -oe_result_t oe_get_entropy(void* output, size_t len) +typedef uint64_t (*_entropy_function_t)(void); + +OE_INLINE bool _has_cpuid_feature( + uint32_t leaf, + uint32_t feature, + uint32_t feature_register) { - oe_result_t ret = OE_UNEXPECTED; - unsigned char* p = (unsigned char*)output; + oe_assert(feature_register < OE_CPUID_REG_COUNT); + uint64_t r[OE_CPUID_REG_COUNT] = {0}; + r[OE_CPUID_RAX] = leaf; + return ( + (oe_emulate_cpuid( + &r[OE_CPUID_RAX], + &r[OE_CPUID_RBX], + &r[OE_CPUID_RCX], + &r[OE_CPUID_RDX]) == 0) && + (r[feature_register] & feature)); +} - if (!output) - goto done; +static oe_entropy_kind_t _get_entropy_kind() +{ + oe_entropy_kind_t result = OE_ENTROPY_KIND_NONE; - /* Copy 64-bit random integers to output */ - { - size_t n = len / sizeof(uint64_t); + /* The ordering of checks is important: we want the presence of + * stronger entropy sources to supersede the weaker ones, so + * go from least to most preferred sources. + */ + if (_has_cpuid_feature(1, OE_CPUID_RDRAND_FEATURE, OE_CPUID_RCX)) + result = OE_ENTROPY_KIND_RDRAND; - while (n--) - { - uint64_t x = oe_rdrand(); + if (_has_cpuid_feature(7, OE_CPUID_RDSEED_FEATURE, OE_CPUID_RBX)) + result = OE_ENTROPY_KIND_RDSEED; - if (oe_memcpy_s(p, len, &x, sizeof(uint64_t)) != OE_OK) - goto done; + return result; +} - p += sizeof(uint64_t); - len -= sizeof(uint64_t); - } - } +oe_result_t oe_get_entropy(void* output, size_t len, oe_entropy_kind_t* kind) +{ + oe_result_t result = OE_UNEXPECTED; + _entropy_function_t get_entropy = NULL; + unsigned char* p = (unsigned char*)output; + size_t bytes_left = len; - /* Copy remaining random bytes to output */ - { - size_t r = len % sizeof(uint64_t); - uint64_t x = oe_rdrand(); - const unsigned char* q = (const unsigned char*)&x; + if (kind) + *kind = OE_ENTROPY_KIND_NONE; + + if (output) + memset(output, 0, len); - if (oe_memcpy_s(p, len, q, r) != OE_OK) - goto done; + if (!output || !kind) + OE_RAISE(OE_INVALID_PARAMETER); + + *kind = _get_entropy_kind(); + if (*kind == OE_ENTROPY_KIND_RDSEED) + get_entropy = oe_rdseed; + else if (*kind == OE_ENTROPY_KIND_RDRAND) + get_entropy = oe_rdrand; + else + OE_RAISE(OE_UNSUPPORTED); + + while (bytes_left > 0) + { + uint64_t random = get_entropy(); + size_t copy_size = + (sizeof(random) > bytes_left) ? bytes_left : sizeof(random); + memcpy(p, &random, copy_size); + p += copy_size; + bytes_left -= copy_size; } - ret = OE_OK; + result = OE_OK; done: - return ret; + return result; } diff --git a/include/openenclave/internal/cpuid.h b/include/openenclave/internal/cpuid.h index e6c9c669b1..9a79509e51 100644 --- a/include/openenclave/internal/cpuid.h +++ b/include/openenclave/internal/cpuid.h @@ -16,7 +16,9 @@ #define OE_CPUID_RDX 3 #define OE_CPUID_REG_COUNT 4 -#define OE_CPUID_AESNI_FEATURE 0x02000000u +#define OE_CPUID_AESNI_FEATURE 0x02000000u /* Leaf 1, subleaf 0, ECX */ +#define OE_CPUID_RDRAND_FEATURE 0x40000000u /* Leaf 1, subleaf 0, ECX */ +#define OE_CPUID_RDSEED_FEATURE 0x00040000u /* Leaf 7, subleaf 0, EBX */ /** * The list of cpuid leafs that are emulated. diff --git a/include/openenclave/internal/entropy.h b/include/openenclave/internal/entropy.h index bdd3bdf95e..6ea2ad21a4 100644 --- a/include/openenclave/internal/entropy.h +++ b/include/openenclave/internal/entropy.h @@ -9,18 +9,33 @@ OE_EXTERNC_BEGIN +/** + * The kind of entropy returned by the oe_get_entropy method, as classified + * by the Digital Random Number Generator (DRNG) implementation used. + */ +typedef enum _oe_entropy_kind +{ + OE_ENTROPY_KIND_NONE = 0, + OE_ENTROPY_KIND_RDRAND = 1, + OE_ENTROPY_KIND_RDSEED = 2, + OE_ENTROPY_KIND_OPTEE = 3, + __OE_ENTROPY_KIND_MAX = OE_ENUM_MAX +} oe_entropy_kind_t; + /** * Generates a sequence of high quality sequence of random bytes that * is suitable for a seed to a pseudorandom number generator (PRNG). * * This function will block if there is insufficient hardware entropy. * - * @param data the buffer that will be filled with random bytes - * @param size the size of the buffer + * @param data The buffer that will be filled with random bytes + * @param size The size of the buffer + * @param kind The kind of entropy returned as classified by the Digital + * Random Number Generator (DRNG) implementation used. * * @return OE_OK on success */ -oe_result_t oe_get_entropy(void* data, size_t size); +oe_result_t oe_get_entropy(void* data, size_t size, oe_entropy_kind_t* kind); OE_EXTERNC_END diff --git a/include/openenclave/internal/rdrand.h b/include/openenclave/internal/rdrand.h index 5814082e01..1189026843 100644 --- a/include/openenclave/internal/rdrand.h +++ b/include/openenclave/internal/rdrand.h @@ -15,7 +15,7 @@ OE_EXTERNC_BEGIN * instruction. This method will block if there is insufficient hardware * entropy to provide the full 64-bits of randomness. * - * @return OE_OK on success + * @return uint64_t 8-bytes of randomness. */ uint64_t oe_rdrand(void); diff --git a/include/openenclave/internal/rdseed.h b/include/openenclave/internal/rdseed.h new file mode 100644 index 0000000000..6e1618c042 --- /dev/null +++ b/include/openenclave/internal/rdseed.h @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#ifndef _OE_RDSEED_H +#define _OE_RDSEED_H + +#include + +OE_EXTERNC_BEGIN + +/** + * Generate a sequence of random bytes using Intel RDSEED instruction + * + * This function generates 8 random bytes using direct call to Intel's RDSEED + * instruction. This method will block if there is insufficient hardware + * entropy to provide the full 64-bits of randomness. + * + * @return uint64_t 8-bytes of randomness. + */ +uint64_t oe_rdseed(void); + +OE_EXTERNC_END + +#endif /* _OE_RDSEED_H */ diff --git a/tests/crypto/cpu_entropy_test.c b/tests/crypto/cpu_entropy_test.c new file mode 100644 index 0000000000..a657b16510 --- /dev/null +++ b/tests/crypto/cpu_entropy_test.c @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#define MAX_LOOP_SIZE 1000 + +#include +#include +#include +#include +#include +#include +#include + +// Test that RDSEED and RDRAND functions synchronously block and +// retry until the sufficient entropy exists to be returned. +void TestCpuEntropy() +{ + uint64_t rand_num = 0; + printf("=== begin %s()\n", __FUNCTION__); + + /* TODO: This test does not actually manage to exhaust the RDRAND + * entropy pool regardless of the number of iterations run since + * the operation of retrieving the RDRAND value through the bus + * architecture is slow enough that a single thread can't saturate + * the interface regardless of the number of iterations run. + */ + for (uint64_t i = 0; i < MAX_LOOP_SIZE; i++) + { + rand_num = oe_rdrand(); + + /* 0 is a legal random value that could be returned, but the + * odds of this happening twice in a row are very unlikely + * unless we've run out of hardware entropy and are returning + * without retrying until we have sufficient entropy. + */ + if (rand_num == 0) + { + rand_num = oe_rdrand(); + OE_TEST(rand_num != 0); + } + } + + /* Empirically, RDSEED will start to run out ~20 iterations, on a + * Coffeelake device, so the MAX_LOOP_SIZE should be plenty. + */ + for (uint64_t i = 0; i < MAX_LOOP_SIZE; i++) + { + rand_num = oe_rdseed(); + if (rand_num == 0) + { + rand_num = oe_rdseed(); + OE_TEST(rand_num != 0); + } + } + + printf("=== passed %s()\n", __FUNCTION__); +} diff --git a/tests/crypto/enclave/enc/CMakeLists.txt b/tests/crypto/enclave/enc/CMakeLists.txt index fca04fbb39..82638f3161 100644 --- a/tests/crypto/enclave/enc/CMakeLists.txt +++ b/tests/crypto/enclave/enc/CMakeLists.txt @@ -21,7 +21,7 @@ set(SRCS if (OE_SGX) list(APPEND SRCS ../../../../common/sgx/rand.S - ../../rdrand_test.c) + ../../cpu_entropy_test.c) endif () add_enclave(TARGET cryptoenc UUID f0be7db0-ce7c-4dc4-b8c8-b161f4216225 diff --git a/tests/crypto/host/CMakeLists.txt b/tests/crypto/host/CMakeLists.txt index bb87c5fd72..fa75d83153 100644 --- a/tests/crypto/host/CMakeLists.txt +++ b/tests/crypto/host/CMakeLists.txt @@ -21,7 +21,7 @@ endif() if (OE_SGX) list(APPEND PLATFORM_SRC - ../rdrand_test.c) + ../cpu_entropy_test.c) endif () add_executable(hostcrypto diff --git a/tests/crypto/rdrand_test.c b/tests/crypto/rdrand_test.c deleted file mode 100644 index b365a54df5..0000000000 --- a/tests/crypto/rdrand_test.c +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#define MAX_LOOP_SIZE 100000000 -#include -#include -#include -#include -#include -#include - -// TestRdrand is trying to ensure that oe_rdrand function incorporates blocking -// wait to retry if the RDRAND instruction is out of entropy -void TestRdrand() -{ - uint64_t rand_num = 0; - printf("=== begin %s()\n", __FUNCTION__); - for (uint64_t i = 0; i < MAX_LOOP_SIZE; i++) - { - rand_num = oe_rdrand(); - if (rand_num == 0) - { - rand_num = oe_rdrand(); - OE_TEST(rand_num != 0); - } - } - printf("=== passed %s()\n", __FUNCTION__); -} diff --git a/tests/crypto/tests.c b/tests/crypto/tests.c index bb1816f7a2..b3110fa6a1 100644 --- a/tests/crypto/tests.c +++ b/tests/crypto/tests.c @@ -13,8 +13,8 @@ void TestAll() TestRSA(); TestRandom(); #if defined(__x86_64__) || defined(__i386__) - // This test exercises the rdrand instruction, which is x86/64-specific. - TestRdrand(); + // Test the RDRAND/RDSEED instructions, which are x86/64-specific. + TestCpuEntropy(); #endif TestHMAC(); TestKDF(); diff --git a/tests/crypto/tests.h b/tests/crypto/tests.h index 5ad9c907c9..d893d91660 100644 --- a/tests/crypto/tests.h +++ b/tests/crypto/tests.h @@ -9,7 +9,7 @@ void TestCRL(void); void TestEC(void); void TestKDF(void); void TestRandom(void); -void TestRdrand(void); +void TestCpuEntropy(void); void TestRSA(void); void TestSHA(void); void TestHMAC(void); From 5a011c46cd324d687ae088b497d7b5727db8e94c Mon Sep 17 00:00:00 2001 From: Xuejun Yang Date: Wed, 25 Sep 2019 04:48:40 +0000 Subject: [PATCH 026/420] Address review comments --- samples/switchless/README.md | 109 ++++++++++++++++++++++-------- samples/switchless/enclave/enc.c | 19 ++---- samples/switchless/host/host.c | 20 +++--- samples/switchless/switchless.edl | 5 +- 4 files changed, 98 insertions(+), 55 deletions(-) diff --git a/samples/switchless/README.md b/samples/switchless/README.md index 93af5368bd..e75900541b 100644 --- a/samples/switchless/README.md +++ b/samples/switchless/README.md @@ -1,48 +1,90 @@ # Switchless Calls Sample -This sample demonstrates how to make switchless calls to host from inside an enclave. It is built on top of the [`Hello World`](../helloworld/README.md) sample. The addition is a host function `host_helloworld_switchless` which is called from the enclave switchlessly. - +This sample demonstrates how to make switchless calls to host from inside an enclave. It has the following properties: - Explain the concept of switchless calls +- Identify cases where switchless calls are appropriate - Demonstrate how to mark a function as `transition_using_threads` in EDL, and use [`oeedger8r`](https://github.com/openenclave/openenclave/tree/master/docs/GettingStartedDocs/Edger8rGettingStarted.md) tool to compile it -- Demonstrate how to configure an enclave to enable switchless calls within it +- Demonstrate how to configure an enclave to enable switchless calls originated within it +- Recommend the number of host worker threads required for switchless calls in practice Prerequisite: you may want to read [Common Sample Information](../README.md#common-sample-information) before going further. ## Switchless Calls -In an enclave application, the host makes **ECALL**s into functions exposed by the enclaves it created. Likewise, the enclaves make **OCALL**s into functions exposed by the host that created them. In either case, the execution has to be transitioned from an untrusted environment to a trusted environment, or vice versa. Since the transition is costly due to heavy security checks, it might be more performance advantageous to make the calls **context-switchless**: the caller delegates the function call to a worker thread in the other environment, which does the real job of calling the function and post the result to the caller. Both the calling thread and the worker thread never leave their respective execution contexts during the perceived function call. +In an enclave application, the host makes **ECALL**s into functions exposed by the enclaves it created. Likewise, +the enclaves may make **OCALL**s into functions exposed by the host that created them. In either case, the +execution has to be transitioned from an untrusted environment to a trusted environment, or vice versa. Since the +transition is costly due to heavy security checks, it might be more performance advantageous to make the calls +**context-switchless**: the caller delegates the function call to a worker thread in the other environment, which does the real job of calling the function and post the result to the caller. Both the calling thread and the +worker thread never leave their respective execution contexts during the perceived function call. + +The calling thread and the worker thread need to exchange information twice during the call. When the switchless +call is initiated, the caller needs to pass the `job` (encapsulating information regarding the function call in a + single object, for details see the next section) to the worker thread. And when the call finishes, the worker +thread needs to pass the result back to the caller. Both exchanges need to be synchronized. + +While switchless calls save transition time, they require at least one additional thread to service the calls. +More threads typically means more competition of the CPU cores and more context switches, hurting the performance. +Whether to make a particular function switchless has to weigh the associated costs and savings. In general, the +good candidates for switchless calls are functions that are: 1) short, thus the transition takes relatively high +percentage of the overall execution time of the call; and 2) called frequently, so the savings in transition time +add up. + +## How does OpenEnclave support switchless OCALLs + +OpenEnclave only supports synchronous switchless OCALLs currently. When the caller within an enclave makes a +switchless OCALL, the trusted OpenEnclave runtime creates a `job` out of the function call. The `job` object +includes information such as the function ID, the parameters marshaled into a buffer, and a buffer for holding the +return value(s). The job is posted to a shared memory region which both the enclave and the host can access. -The calling thread and the worker thread need to exchange information twice during the call. When the switchless call is initiated, the caller needs to pass the `job` (representing the function call) to the worker thread. And when the call finishes, the worker thread needs to pass the result back to the caller. Both exchanges need to be synchronized. +A host worker thread checks and retrieves `job` from the shared memory region. It uses the untrusted OpenEnclave +runtime to process the `job` by unmarshaling the parameters, then dispatching to the callee function, and finally +relaying the result back to the trusted OpenEnclave runtime, which is further forwarded back to the caller. -## How does OE support switchless OCALLs +To support simultaneous switchless OCALLs made from enclaves, the host workers are multi-threaded. OpenEnclave +allows users to configure how many host worker threads are to be created for servicing switchless OCALLs. The +following example illustrates how to do that. A word of caution is that too many host worker threads might increase +competition of cores between threads and degrade the performance. Therefore, if a enclave has switchless calls +enabled, OpenEnclave caps the number of host worker threads for it to the number of enclave threads specified. -OE only supports synchronous switchless OCALLs currently. When the caller within an enclave makes a switchless OCALL, the trusted OE runtime creates a `job` out of the function call. The `job` object includes information such as the function ID, the parameters marshaled into a buffer, and a buffer for holding the return value(s). The job is posted to a shared memory region which both the enclave and the host can access. +With the current implementation, we recommend users to avoid using more host worker threads than the minimum of: -A host worker thread checks and retrieves `job` from the shared memory region. It uses the untrusted OE runtime to process the `job` by unmarshaling the parameters, then dispatching to the callee function, and finally relaying the result back to the trusted OE runtime, which is further forwarded back to the caller. +1. the number of simultaneously active enclave threads, and +2. the number of cores that are potentially available to host worker threads. -To support simultaneous switchless OCALLs made from enclaves, the host workers are multi-threaded. OE allows users to configure how many host worker threads are to be created for servicing switchless OCALLs. The following example illustrates how to do that. A word of caution is that too many host worker threads might increase competition of cores between threads and degrade the performance. Therefore, if a enclave has switchless calls enabled, OE caps the number of host worker threads for it to the number of enclave threads specified. +For example, on a 4-core machine, if the number of the simultaneously active enclave threads is 2, and there is no +host threads other than the two threads making ECALLs and the switchless worker threads, both 1) and 2) would be 2. So we recommend setting the number of host worker threads to 2. + +The exception to the above rule happens when 1) or 2) is zero or negative. For example, if the host starts two more +additional threads that are expected to be active along with the two enclave threads, the number of cores available +to the worker threads is actually 0, and the minimum of 1) and 2) would be 0. In this case, we recommend setting +the number of host worker threads to 1 nevertheless, to ensure switchless calls are serviced by at least one thread. + +The above recommendation may change when we modify the behavior of worker threads in the future. ## About the EDL +In this sample, we pretend the enclave doesn't know addition. It relies on a host function `host_increment` to +increment a number by 1, and repeat calling it `N` times to add `N` to a given number. Since `host_increment` is +short and called frequently, it is appropriate to make it a switchless function. + First we need to define the functions we want to call between the host and the enclave. To do this we create a `switchless.edl` file: ```edl enclave { trusted { - public void enclave_helloworld(); - + public void enclave_add_N([in, out] int* m, int n); }; untrusted { - void host_helloworld(); - void host_helloworld_switchless() transition_using_threads; + void host_increment([in, out] int* m) transition_using_threads; }; }; ``` -Function `host_helloworld_switchless`'s declaration ends with keyword `transition_using_threads`, indicating it should be called switchlessly at run time. However, this a best-effort directive. OE runtime may still choose to fall back to a tradition OCALL if switchless call resources are unavailable, e.g., the enclave is not configured as switchless-capable, or the host worker threads are busy servicing other switchless OCALLs. +Function `host_increment`'s declaration ends with keyword `transition_using_threads`, indicating it should be called switchlessly at run time. However, this a best-effort directive. OpenEnclave runtime may still choose to fall back to a tradition OCALL if switchless call resources are unavailable, e.g., the enclave is not configured as switchless-capable, or the host worker threads are busy servicing other switchless OCALLs. To generate the functions with the marshaling code, the `oeedger8r` tool is called in both the host and enclave directories from their Makefiles. For example: @@ -55,13 +97,18 @@ oeedger8r ../switchless.edl --untrusted --experimental ## About the host -The host first defines a structure specifically for configuring switchless calls. In this case, we specify the first field `2` as the number of host worker threads for switchless OCALLs. The 2nd field specifies the number of enclave threads for switchless ECALLs. Since switchless ECALL is not yet implementated, we require the 2nd field to be `0`. +The host first defines a structure specifically for configuring switchless calls. In this case, we specify the +first field `1` as the number of host worker threads for switchless OCALLs. In this example, 1) There is at most +1 enclave thread all the time, and 2) The number of cores available to the host worker threads is 1 (assuming a +2-core machine) or 3 (assuming a 4-core machine). In any case, The minimum of 1) and 2) is 1, which we choose to +be the number of host worker threads. The 2nd field specifies the number of enclave threads for switchless ECALLs. +Since switchless ECALL is not yet implemented, we require the 2nd field to be `0`. ```c -oe_enclave_config_context_switchless_t config = {2, 0}; +oe_enclave_config_context_switchless_t config = {1, 0}; ``` -The host then puts the structure address and the configuration type in an array of configurations for the enclave to be created. Even though we only have one configuration (for switchless) for the enclave, we'd like the flexibility of adding more than one configurations (with different types) for an enclave in the future. +The host then puts the structure address and the configuration type in an array of configurations for the enclave to be created. Even though we only have one configuration (for switchless) for the enclave, we'd like the flexibility of adding more than one configuration (with different types) for an enclave in the future. ```c oe_enclave_config_t configs[] = {{ @@ -70,7 +117,8 @@ oe_enclave_config_t configs[] = {{ }}; ``` -To make the configurations created above effective, we need to pass the array `configs` into `oe_create_enclave` in the following way: +To make the configurations created above effective, we need to pass the array `configs` into `oe_create_enclave` +in the following way: ```c oe_create_switchless_enclave( @@ -82,25 +130,28 @@ oe_create_switchless_enclave( &enclave); ``` -The host then makes an ECALL of `enclave_helloworld` to transition into the enclave. After the ECALL returns, the host terminates the enclave. +The host then makes an ECALL of `enclave_add_N` to transition into the enclave. After the ECALL returns, the +host prints the returned value and terminates the enclave. -As shown in the EDL file, the host exposes two host functions: `host_helloworld` and `host_helloworld_switchless`. The former prints "Hello world from regular OCALL", and the latter prints "Hello world from switchless OCALL". +As shown in the EDL file, the host exposes a host function `host_increment` which takes an integer `n`, and returns the result of `n+1`. ## About the enclave -The enclave exposes only one function `enclave_helloworld`. The function prints "Hello world from the enclave" first, then call the host function `host_helloworld`, followed by calling host function `host_helloworld_switchless`. Internally, the last call is fulfilled switchlessly. If everything work as expected, the output of this enclave function would be: - -``` -Hello world from the enclave -Hello world from regular OCALL -Hello world from switchless OCALL -``` +The enclave exposes only one function `enclave_add_N`. The function takes two parameter `m` and `n`. It calls +the host function `host_increment` switchlessly in a loop of `n` iterations. ## Build and run Note that there are two different build systems supported, one using GNU Make and `pkg-config`, the other using CMake. +If the build and run succeed, the following output is expected: + +```bash +host/switchlesshost ./enclave/switchlessenc.signed +enclave_add_N(): 10000 + 10000 = 20000 +``` + ### CMake This uses the CMake package provided by the Open Enclave SDK. @@ -115,13 +166,13 @@ make run ### GNU Make ```bash -cd helloworld +cd switchless make build make run ``` #### Note -switchless sample can run under OE simulation mode. +switchless sample can run under OpenEnclave simulation mode. To run the switchless sample in simulation mode from the command like, use the following: diff --git a/samples/switchless/enclave/enc.c b/samples/switchless/enclave/enc.c index 483562c7a9..4d3442ebd7 100644 --- a/samples/switchless/enclave/enc.c +++ b/samples/switchless/enclave/enc.c @@ -4,21 +4,16 @@ #include #include "switchless_t.h" -void enclave_helloworld() +void enclave_add_N(int* m, int n) { - fprintf(stdout, "Hello world from the enclave\n"); - // Call back into the host - oe_result_t result = host_helloworld(); - if (result != OE_OK) - { - fprintf(stderr, "host_helloworld(): result=%u", result); - } - - result = host_helloworld_switchless(); - if (result != OE_OK) + for (int i = 0; i < n; i++) { - fprintf(stderr, "host_helloworld_switchless(): result=%u", result); + oe_result_t result = host_increment(m); + if (result != OE_OK) + { + fprintf(stderr, "host_increment(): result=%u", result); + } } } diff --git a/samples/switchless/host/host.c b/samples/switchless/host/host.c index 9b39ab2af1..fbaa070b47 100644 --- a/samples/switchless/host/host.c +++ b/samples/switchless/host/host.c @@ -6,14 +6,9 @@ #include #include "switchless_u.h" -void host_helloworld() +void host_increment(int* n) { - fprintf(stdout, "Hello world from regular OCALL\n"); -} - -void host_helloworld_switchless() -{ - fprintf(stdout, "Hello world from switchless OCALL\n"); + *n = *n + 1; } static bool check_simulate_opt(int* argc, const char* argv[]) @@ -35,7 +30,8 @@ int main(int argc, const char* argv[]) { oe_enclave_t* enclave = NULL; oe_result_t result; - int ret = 1; + int ret = 1, m = 10000, n = 10000; + int oldm = m; if (argc != 2 && argc != 3) { @@ -50,7 +46,7 @@ int main(int argc, const char* argv[]) } // Enable switchless and configure host worker number - oe_enclave_config_context_switchless_t config = {2, 0}; + oe_enclave_config_context_switchless_t config = {1, 0}; oe_enclave_config_t configs[] = {{ .config_type = OE_ENCLAVE_CONFIG_CONTEXT_SWITCHLESS, .u.context_switchless_config = &config, @@ -66,9 +62,11 @@ int main(int argc, const char* argv[]) fprintf(stderr, "oe_create_enclave(): result=%u", result); // Call into the enclave - result = enclave_helloworld(enclave); + result = enclave_add_N(enclave, &m, n); if (result != OE_OK) - fprintf(stderr, "enclave_helloworld(): result=%u", result); + fprintf(stderr, "enclave_add_N(): result=%u", result); + + fprintf(stderr, "enclave_add_N(): %d + %d = %d\n", oldm, n, m); ret = result != OE_OK ? 1 : 0; oe_terminate_enclave(enclave); diff --git a/samples/switchless/switchless.edl b/samples/switchless/switchless.edl index b8df7cebd8..c2753b0999 100644 --- a/samples/switchless/switchless.edl +++ b/samples/switchless/switchless.edl @@ -3,11 +3,10 @@ enclave { trusted { - public void enclave_helloworld(); + public void enclave_add_N([in, out] int* m, int n); }; untrusted { - void host_helloworld(); - void host_helloworld_switchless() transition_using_threads; + void host_increment([in, out] int* m) transition_using_threads; }; }; From ed638898a9e1d5184f712cda4ae641bd1e612ca0 Mon Sep 17 00:00:00 2001 From: Sergio Wong Date: Tue, 10 Sep 2019 23:22:05 +0000 Subject: [PATCH 027/420] Attestation security updates during quote verification: 1. Added validity checks for all certs, CRLs and QE identity info. 2. Refactored code with additional error details. 3. Added cert functions to get cert validity datetimes. --- common/datetime.c | 46 +- common/result.c | 3 + common/sgx/collaterals.c | 152 ++++++ common/sgx/collaterals.h | 35 ++ common/sgx/qeidentity.c | 170 ++++--- common/sgx/qeidentity.h | 25 +- common/sgx/quote.c | 548 +++++++++++++++++---- common/sgx/quote.h | 78 ++- common/sgx/revocation.c | 372 ++++++++++---- common/sgx/revocation.h | 59 ++- enclave/CMakeLists.txt | 1 + enclave/core/CMakeLists.txt | 1 + enclave/crypto/cert.c | 43 ++ enclave/sgx/qeidinfo.c | 2 +- enclave/sgx/report.c | 4 +- enclave/sgx/revocationinfo.c | 2 +- host/CMakeLists.txt | 2 + host/crypto/bcrypt/cert.c | 42 +- host/crypto/bcrypt/crl.c | 29 +- host/crypto/bcrypt/util.c | 31 ++ host/crypto/bcrypt/util.h | 22 + host/crypto/openssl/asn1.c | 92 ++++ host/crypto/openssl/asn1.h | 28 ++ host/crypto/openssl/cert.c | 44 ++ host/crypto/openssl/crl.c | 98 +--- host/sgx/hostverify_report.c | 6 +- host/sgx/report.c | 7 +- host/sgx/sgxquoteprovider.c | 4 +- include/openenclave/bits/result.h | 5 + include/openenclave/internal/crypto/cert.h | 14 + include/openenclave/internal/datetime.h | 10 + include/openenclave/internal/report.h | 51 ++ tests/host_verify/host/host.cpp | 230 +++++++-- tests/report/common/tests.cpp | 464 +++++++++++++++++ tests/report/common/tests.h | 1 + tests/report/enc/enc.cpp | 9 + tests/report/host/host.cpp | 4 + tests/report/tests.edl | 1 + tests/tools/oecert/host/host.cpp | 65 ++- 39 files changed, 2370 insertions(+), 430 deletions(-) create mode 100644 common/sgx/collaterals.c create mode 100644 common/sgx/collaterals.h create mode 100644 host/crypto/bcrypt/util.c create mode 100644 host/crypto/bcrypt/util.h create mode 100644 host/crypto/openssl/asn1.h diff --git a/common/datetime.c b/common/datetime.c index 7a420f04e3..e7c1fcf8d5 100644 --- a/common/datetime.c +++ b/common/datetime.c @@ -3,8 +3,10 @@ #include #include +#include #define UNIX_EPOCH_YEAR (1970) +#define OE_DATETIME_STR_SIZE (21) oe_result_t oe_datetime_is_valid(const oe_datetime_t* datetime) { @@ -121,10 +123,10 @@ oe_result_t oe_datetime_to_string( if (datetime == NULL || str_length == NULL) OE_RAISE(OE_INVALID_PARAMETER); - if (str == NULL || *str_length < 21) + if (str == NULL || *str_length < OE_DATETIME_STR_SIZE) { - *str_length = 21; - OE_RAISE(OE_BUFFER_TOO_SMALL); + *str_length = OE_DATETIME_STR_SIZE; + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } OE_CHECK(oe_datetime_is_valid(datetime)); @@ -149,7 +151,7 @@ oe_result_t oe_datetime_to_string( // Null terminator. *p++ = 0; - *str_length = 21; + *str_length = OE_DATETIME_STR_SIZE; result = OE_OK; done: return result; @@ -221,3 +223,39 @@ int32_t oe_datetime_compare( return 0; } + +oe_result_t oe_datetime_now(oe_datetime_t* value) +{ + oe_result_t result = OE_UNEXPECTED; + time_t now; + struct tm* timeinfo; + + if (value == NULL) + OE_RAISE(OE_INVALID_PARAMETER); + + time(&now); + timeinfo = gmtime(&now); + + value->year = (uint32_t)timeinfo->tm_year + 1900; + value->month = (uint32_t)timeinfo->tm_mon + 1; + value->day = (uint32_t)timeinfo->tm_mday; + value->hours = (uint32_t)timeinfo->tm_hour; + value->minutes = (uint32_t)timeinfo->tm_min; + value->seconds = (uint32_t)timeinfo->tm_sec; + + result = OE_OK; +done: + + return result; +} + +void oe_datetime_log_info(const char* msg, const oe_datetime_t* date) +{ + if (oe_get_current_logging_level() >= OE_LOG_LEVEL_INFO) + { + char str[OE_DATETIME_STR_SIZE]; + size_t size = sizeof(str); + oe_datetime_to_string(date, str, &size); + OE_TRACE_INFO("%s %s\n", msg, str); + } +} diff --git a/common/result.c b/common/result.c index 9a77b863a1..490ee7297e 100644 --- a/common/result.c +++ b/common/result.c @@ -100,6 +100,8 @@ const char* oe_result_str(oe_result_t result) return "OE_UNSUPPORTED_ENCLAVE_IMAGE"; case OE_VERIFY_CRL_EXPIRED: return "OE_VERIFY_CRL_EXPIRED"; + case OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD: + return "OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD"; case OE_VERIFY_CRL_MISSING: return "OE_VERIFY_CRL_MISSING"; case OE_VERIFY_REVOKED: @@ -177,6 +179,7 @@ bool oe_is_valid_result(uint32_t result) case OE_INVALID_QE_IDENTITY_INFO: case OE_UNSUPPORTED_ENCLAVE_IMAGE: case OE_VERIFY_CRL_EXPIRED: + case OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD: case OE_VERIFY_CRL_MISSING: case OE_VERIFY_REVOKED: case OE_CRYPTO_ERROR: diff --git a/common/sgx/collaterals.c b/common/sgx/collaterals.c new file mode 100644 index 0000000000..c3adce1f7c --- /dev/null +++ b/common/sgx/collaterals.c @@ -0,0 +1,152 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include "collaterals.h" +#include +#include +#include "../common.h" + +#include "qeidentity.h" +#include "quote.h" +#include "revocation.h" + +oe_result_t oe_get_collaterals_internal( + const uint8_t* remote_report, + size_t remote_report_size, + uint8_t** collaterals_buffer, + size_t* collaterals_buffer_size) +{ + oe_result_t result = OE_UNEXPECTED; + uint8_t* buffer = NULL; + oe_collaterals_header_t* header = NULL; + oe_collaterals_t* collaterals = NULL; + + const uint8_t* pem_pck_certificate = NULL; + size_t pem_pck_certificate_size = 0; + oe_cert_chain_t pck_cert_chain = {0}; + oe_cert_t leaf_cert = {0}; + oe_cert_t intermediate_cert = {0}; + + OE_TRACE_INFO("Enter call %s\n", __FUNCTION__); + + if ((collaterals_buffer == NULL) || (collaterals_buffer_size == NULL)) + { + OE_RAISE(OE_INVALID_PARAMETER); + } + + *collaterals_buffer = NULL; + *collaterals_buffer_size = 0; + + buffer = (uint8_t*)oe_calloc(1, OE_COLLATERALS_SIZE); + if (buffer == NULL) + { + OE_RAISE(OE_OUT_OF_MEMORY); + } + + header = (oe_collaterals_header_t*)buffer; + collaterals = (oe_collaterals_t*)(buffer + OE_COLLATERALS_HEADER_SIZE); + + // Collateral header initialization + header->collaterals_size = OE_COLLATERALS_BODY_SIZE; + + // + // Get the uri from the quote certificates, and then get the + // CRL (oe_get_revocation_info_from_certs) + // + + // Get PCK cert chain from the quote. + OE_CHECK_MSG( + oe_get_quote_cert_chain_internal( + remote_report, + remote_report_size, + &pem_pck_certificate, + &pem_pck_certificate_size, + &pck_cert_chain), + "Failed to get certificate chain from quote. %s", + oe_result_str(result)); + + // Fetch leaf and intermediate certificates. + OE_CHECK_MSG( + oe_cert_chain_get_leaf_cert(&pck_cert_chain, &leaf_cert), + "Failed to get leaf certificate. %s", + oe_result_str(result)); + OE_CHECK_MSG( + oe_cert_chain_get_cert(&pck_cert_chain, 1, &intermediate_cert), + "Failed to get intermediate certificate. %s", + oe_result_str(result)); + + // Get revocation information + OE_CHECK_MSG( + oe_get_revocation_info_from_certs( + &leaf_cert, &intermediate_cert, &(collaterals->revocation_info)), + "Failed to get certificate revocation information. %s", + oe_result_str(result)); + + // Application specific collaterals + collaterals->app_collaterals_size = 0; + + // + // QE identify info + // + OE_CHECK_MSG( + oe_get_qe_identity_info(&(collaterals->qe_id_info)), + "Failed to get quote enclave identity information. %s", + oe_result_str(result)); + + // Record creation datetime. + { + oe_datetime_t datetime_now = {0}; + size_t datetime_size = sizeof(collaterals->creation_datetime); + + OE_CHECK(oe_datetime_now(&datetime_now)); + + OE_CHECK_MSG( + oe_datetime_to_string( + &datetime_now, collaterals->creation_datetime, &datetime_size), + "Failed to update collateral creation time. %s", + oe_result_str(result)); + } + + result = OE_OK; +done: + oe_cert_free(&leaf_cert); + oe_cert_free(&intermediate_cert); + oe_cert_chain_free(&pck_cert_chain); + + if (result == OE_OK) + { + *collaterals_buffer = buffer; + *collaterals_buffer_size = OE_COLLATERALS_SIZE; + } + else if (buffer) + { + oe_free_get_revocation_info_args(&(collaterals->revocation_info)); + oe_free_qe_identity_info_args(&(collaterals->qe_id_info)); + + oe_free(buffer); + } + + OE_TRACE_INFO( + "Exit call %s: %d(%s)\n", __FUNCTION__, result, oe_result_str(result)); + + return result; +} + +/** + * Free up any resources allocated by oe_get_collateras() + * + * @param collaterals_buffer The buffer containing the collaterals. + */ +void oe_free_collaterals_internal(uint8_t* collaterals_buffer) +{ + if (collaterals_buffer) + { + oe_collaterals_t* collaterals = + (oe_collaterals_t*)(collaterals_buffer + OE_COLLATERALS_HEADER_SIZE); + + oe_free_qe_identity_info_args(&collaterals->qe_id_info); + oe_free_get_revocation_info_args(&collaterals->revocation_info); + + oe_free(collaterals_buffer); + } +} \ No newline at end of file diff --git a/common/sgx/collaterals.h b/common/sgx/collaterals.h new file mode 100644 index 0000000000..ba413efa7a --- /dev/null +++ b/common/sgx/collaterals.h @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#ifndef _OE_COMMON_OE_COLLATERALS_H +#define _OE_COMMON_OE_COLLATERALS_H + +#include +#include + +OE_EXTERNC_BEGIN + +/** + * Get the collaterals for the respective remote report. + * + * @param remote_report[in] The remote report. + * @param remote_report_size[in] The size of the remote report. + * @param collaterals_buffer[out] The buffer where to store the collaterals. + * @param collaterals_buffer_size[out] The size of the collaterals. + */ +oe_result_t oe_get_collaterals_internal( + const uint8_t* remote_report, + size_t remote_report_size, + uint8_t** collaterals_buffer, + size_t* collaterals_buffer_size); + +/** + * Free up any resources allocated by oe_get_collateras() + * + * @param collaterals_buffer The buffer containing the collaterals. + */ +void oe_free_collaterals_internal(uint8_t* collaterals_buffer); + +OE_EXTERNC_END + +#endif /* _OE_COMMON_OE_COLLATERALS_H */ diff --git a/common/sgx/qeidentity.c b/common/sgx/qeidentity.c index 8d5876b730..bb96c9bf4c 100644 --- a/common/sgx/qeidentity.c +++ b/common/sgx/qeidentity.c @@ -32,84 +32,97 @@ void dump_info(const char* title, const uint8_t* data, const uint8_t count) } } -oe_result_t oe_enforce_qe_identity(sgx_report_body_t* qe_report_body) +oe_result_t oe_validate_qe_report_body(sgx_report_body_t* qe_report_body) +{ + oe_result_t result = OE_UNEXPECTED; + + if (qe_report_body == NULL) + OE_RAISE(OE_INVALID_PARAMETER); + + // No qe_identity info returned from the quote provider, this could be + // because either get_qe_identity_info API was not supported or + // unexpected error. In both cases, check against hardcoded quoting + // enclave properties instead Assert that the qe report's MRSIGNER + // matches Intel's quoting. We will remove these hardcoded values once + // the libdcap_quoteprov.so was updated to support qe identity feature. + + // enclave's mrsigner. + if (!oe_constant_time_mem_equal( + qe_report_body->mrsigner, g_qe_mrsigner, sizeof(g_qe_mrsigner))) + { + dump_info("Expected mrsigner", g_qe_mrsigner, sizeof(g_qe_mrsigner)); + dump_info( + "Actual mrsigner", + qe_report_body->mrsigner, + sizeof(qe_report_body->mrsigner)); + OE_RAISE_MSG( + OE_QUOTE_ENCLAVE_IDENTITY_UNIQUEID_MISMATCH, + "mrsigner mismatch", + NULL); + } + + if (qe_report_body->isvprodid != g_qe_isvprodid) + OE_RAISE_MSG( + QE_QUOTE_ENCLAVE_IDENTITY_PRODUCTID_MISMATCH, + "isvprodid mismatch. Expected 0x%04X, actual 0x%04X", + g_qe_isvprodid, + qe_report_body->isvprodid); + + if (qe_report_body->isvsvn < g_qeisvsvn) + OE_RAISE_MSG( + OE_QUOTE_ENCLAVE_IDENTITY_VERIFICATION_FAILED, + "isvsvn is out-of-date. Required SVN 0x%08X, actual SVN 0x%08X", + g_qeisvsvn, + qe_report_body->isvsvn); + + // Ensure that the QE is not a debug supporting enclave. + if (qe_report_body->attributes.flags & SGX_FLAGS_DEBUG) + OE_RAISE_MSG( + OE_QUOTE_ENCLAVE_IDENTITY_VERIFICATION_FAILED, + "QE has SGX_FLAGS_DEBUG set!!", + NULL); + + result = OE_OK; + +done: + + return result; +} + +oe_result_t oe_validate_qe_identity( + sgx_report_body_t* qe_report_body, + oe_get_qe_identity_info_args_t* qe_id_args, + oe_datetime_t* validity_from, + oe_datetime_t* validity_until) { oe_result_t result = OE_FAILURE; - oe_get_qe_identity_info_args_t qe_id_args = {0}; const uint8_t* pem_pck_certificate = NULL; size_t pem_pck_certificate_size = 0; oe_cert_chain_t pck_cert_chain = {0}; + oe_cert_t leaf_cert = {0}; oe_parsed_qe_identity_info_t parsed_info = {0}; + oe_datetime_t from = {0}; + oe_datetime_t until = {0}; OE_TRACE_INFO("Calling %s\n", __FUNCTION__); - // fetch qe identity information - result = oe_get_qe_identity_info(&qe_id_args); - if (result == OE_QUOTE_PROVIDER_CALL_ERROR) - { - // No qe_identity info returned from the quote provider, this could be - // because either get_qe_identity_info API was not supported or - // unexpected error. In both cases, check against hardcoded quoting - // enclave properties instead Assert that the qe report's MRSIGNER - // matches Intel's quoting. We will remove these hardcoded values once - // the libdcap_quoteprov.so was updated to support qe identity feature. - - // enclave's mrsigner. - if (!oe_constant_time_mem_equal( - qe_report_body->mrsigner, g_qe_mrsigner, sizeof(g_qe_mrsigner))) - { - dump_info( - "Expected mrsigner", g_qe_mrsigner, sizeof(g_qe_mrsigner)); - dump_info( - "Actual mrsigner", - qe_report_body->mrsigner, - sizeof(qe_report_body->mrsigner)); - OE_RAISE_MSG( - OE_QUOTE_ENCLAVE_IDENTITY_UNIQUEID_MISMATCH, - "mrsigner mismatch", - NULL); - } - - if (qe_report_body->isvprodid != g_qe_isvprodid) - OE_RAISE_MSG( - QE_QUOTE_ENCLAVE_IDENTITY_PRODUCTID_MISMATCH, - "isvprodid mismatch. Expected 0x%04X, actual 0x%04X", - g_qe_isvprodid, - qe_report_body->isvprodid); - - if (qe_report_body->isvsvn < g_qeisvsvn) - OE_RAISE_MSG( - OE_QUOTE_ENCLAVE_IDENTITY_VERIFICATION_FAILED, - "isvsvn is out-of-date. Required SVN 0x%08X, actual SVN 0x%08X", - g_qeisvsvn, - qe_report_body->isvsvn); - - // Ensure that the QE is not a debug supporting enclave. - if (qe_report_body->attributes.flags & SGX_FLAGS_DEBUG) - OE_RAISE_MSG( - OE_QUOTE_ENCLAVE_IDENTITY_VERIFICATION_FAILED, - "QE has SGX_FLAGS_DEBUG set!!", - NULL); - - result = OE_OK; - goto done; - } - OE_CHECK(result); + if (qe_id_args == NULL) + OE_RAISE(OE_INVALID_PARAMETER); // Use QE Identity info to validate QE // Check against fetched qe identityinfo - OE_TRACE_INFO("qe_identity.issuer_chain:[%s]\n", qe_id_args.issuer_chain); - pem_pck_certificate = qe_id_args.issuer_chain; - pem_pck_certificate_size = qe_id_args.issuer_chain_size; + OE_TRACE_INFO("qe_identity.issuer_chain:[%s]\n", qe_id_args->issuer_chain); + pem_pck_certificate = qe_id_args->issuer_chain; + pem_pck_certificate_size = qe_id_args->issuer_chain_size; // validate the cert chain. OE_CHECK(oe_cert_chain_read_pem( &pck_cert_chain, pem_pck_certificate, pem_pck_certificate_size)); // parse identity info json blob - OE_TRACE_INFO("*qe_identity.qe_id_info:[%s]\n", qe_id_args.qe_id_info); + OE_TRACE_INFO("*qe_identity.qe_id_info:[%s]\n", qe_id_args->qe_id_info); OE_CHECK(oe_parse_qe_identity_info_json( - qe_id_args.qe_id_info, qe_id_args.qe_id_info_size, &parsed_info)); + qe_id_args->qe_id_info, qe_id_args->qe_id_info_size, &parsed_info)); // verify qe identity signature OE_TRACE_INFO("Calling oe_verify_ecdsa256_signature\n"); @@ -120,14 +133,24 @@ oe_result_t oe_enforce_qe_identity(sgx_report_body_t* qe_report_body) &pck_cert_chain)); OE_TRACE_INFO("oe_verify_ecdsa256_signature succeeded\n"); + // Get leaf certificate + OE_CHECK_MSG( + oe_cert_chain_get_leaf_cert(&pck_cert_chain, &leaf_cert), + "Failed to get leaf certificate.", + NULL); + oe_cert_get_validity_dates(&leaf_cert, &from, &until); + + oe_datetime_log_info("QE identity cert issue date: ", &from); + oe_datetime_log_info("QE identity cert next update: ", &until); + // Check that issue_date and next_update are after the earliest date that // the enclave accepts. if (oe_datetime_compare( - &parsed_info.issue_date, &_sgx_minimim_crl_tcb_issue_date) != 1) + &parsed_info.issue_date, &_sgx_minimim_crl_tcb_issue_date) < 0) OE_RAISE(OE_INVALID_QE_IDENTITY_INFO); if (oe_datetime_compare( - &parsed_info.next_update, &_sgx_minimim_crl_tcb_issue_date) != 1) + &parsed_info.next_update, &_sgx_minimim_crl_tcb_issue_date) < 0) OE_RAISE(OE_INVALID_QE_IDENTITY_INFO); // Assert that the qe report's MRSIGNER matches Intel's quoting enclave's @@ -195,11 +218,34 @@ oe_result_t oe_enforce_qe_identity(sgx_report_body_t* qe_report_body) parsed_info.attributes_xfrm_mask, parsed_info.attributes.xfrm); - oe_cleanup_qe_identity_info_args(&qe_id_args); + if (qe_report_body->attributes.flags & SGX_FLAGS_DEBUG) + OE_RAISE_MSG( + OE_QUOTE_ENCLAVE_IDENTITY_VERIFICATION_FAILED, + "QE has SGX_FLAGS_DEBUG set!!", + NULL); + + if (oe_datetime_compare(&parsed_info.issue_date, &from) > 0) + from = parsed_info.issue_date; + if (oe_datetime_compare(&parsed_info.next_update, &until) < 0) + until = parsed_info.next_update; + + oe_datetime_log_info("QE identity overall issue date: ", &from); + oe_datetime_log_info("QE identity overall next update: ", &until); + if (oe_datetime_compare(&from, &until) > 0) + OE_RAISE_MSG( + OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD, + "Failed to find an overall QE identity validity period.", + NULL); + + *validity_from = from; + *validity_until = until; + result = OE_OK; done: if (pck_cert_chain.impl[0] != 0) oe_cert_chain_free(&pck_cert_chain); + oe_cert_free(&leaf_cert); + return result; } diff --git a/common/sgx/qeidentity.h b/common/sgx/qeidentity.h index ef4ad7970a..1327da2b3a 100644 --- a/common/sgx/qeidentity.h +++ b/common/sgx/qeidentity.h @@ -12,13 +12,34 @@ OE_EXTERNC_BEGIN -oe_result_t oe_enforce_qe_identity(sgx_report_body_t* qe_report_body); +/** + * This is needed to be backwards compatible + * with the older quote provider. + * + * @param[in] qe_report_body The QE report body from the quote. + */ +oe_result_t oe_validate_qe_report_body(sgx_report_body_t* qe_report_body); + +/** + * Validate the QE identity information. Returns the validity time range + * for the caller to validate. + * + * @param[in] qe_report_body The QE report body from the quote. + * @param[in] qe_id_args The QE identity info. + * @param[out] validity_from The date from which the QE identity info is valid. + * @param[out] validity_until The date which the QE identity info expires. + */ +oe_result_t oe_validate_qe_identity( + sgx_report_body_t* qe_report_body, + oe_get_qe_identity_info_args_t* qe_id_args, + oe_datetime_t* validity_from, + oe_datetime_t* validity_until); // Fetch qe identity info using the specified args structure. oe_result_t oe_get_qe_identity_info(oe_get_qe_identity_info_args_t* args); // Cleanup the args structure. -void oe_cleanup_qe_identity_info_args(oe_get_qe_identity_info_args_t* args); +void oe_free_qe_identity_info_args(oe_get_qe_identity_info_args_t* args); void dump_info(const char* title, const uint8_t* data, const uint8_t count); diff --git a/common/sgx/quote.c b/common/sgx/quote.c index 7fd01324ec..cf6d95e313 100644 --- a/common/sgx/quote.c +++ b/common/sgx/quote.c @@ -9,9 +9,12 @@ #include #include #include "../common.h" +#include "collaterals.h" #include "qeidentity.h" #include "revocation.h" +#include + // Public key of Intel's root certificate. static const char* g_expected_root_certificate_key = "-----BEGIN PUBLIC KEY-----\n" @@ -29,6 +32,49 @@ OE_INLINE uint32_t ReadUint32(const uint8_t* p) return (uint32_t)(p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24)); } +static oe_result_t _validate_sgx_quote(const sgx_quote_t* sgx_quote) +{ + oe_result_t result = OE_OK; + + if (sgx_quote->version != OE_SGX_QUOTE_VERSION) + { + OE_RAISE_MSG( + OE_QUOTE_VERIFICATION_ERROR, + "Unexpected quote version sgx_quote->version=%d", + sgx_quote->version); + } + +done: + return result; +} + +static oe_result_t _validate_qe_cert_data( + const sgx_qe_cert_data_t* qe_cert_data) +{ + oe_result_t result = OE_OK; + + // The certificate provided in the quote is preferred. + if (qe_cert_data->type != OE_SGX_PCK_ID_PCK_CERT_CHAIN) + OE_RAISE_MSG( + OE_MISSING_CERTIFICATE_CHAIN, + "Unexpected certificate type (qe_cert_data->type=%d)", + qe_cert_data->type); + + if (qe_cert_data->size == 0) + OE_RAISE_MSG( + OE_QUOTE_VERIFICATION_ERROR, + "Quoting enclave certificate data is empty.", + NULL); + + if (qe_cert_data->data == NULL) + OE_RAISE_MSG( + OE_MISSING_CERTIFICATE_CHAIN, + "No PCK certificate found in SGX quote.", + NULL); +done: + return result; +} + static oe_result_t _parse_quote( const uint8_t* quote, size_t quote_size, @@ -43,20 +89,27 @@ static oe_result_t _parse_quote( const uint8_t* const quote_end = quote + quote_size; if (quote_end < p) - { // Pointer wrapped around. - OE_RAISE(OE_REPORT_PARSE_ERROR); - } + OE_RAISE_MSG( + OE_REPORT_PARSE_ERROR, + "Parsing error. Pointer wrapper around.", + NULL); *sgx_quote = NULL; *sgx_quote = (sgx_quote_t*)p; p += sizeof(sgx_quote_t); if (p > quote_end) - OE_RAISE(OE_REPORT_PARSE_ERROR); + OE_RAISE_MSG( + OE_REPORT_PARSE_ERROR, + "Parse error after parsing SGX quote, before signature.", + NULL); if (p + (*sgx_quote)->signature_len != quote_end) - OE_RAISE(OE_REPORT_PARSE_ERROR); + OE_RAISE_MSG( + OE_REPORT_PARSE_ERROR, + "Parse error after parsing SGX signature.", + NULL); *quote_auth_data = (sgx_quote_auth_data_t*)(*sgx_quote)->signature; p += sizeof(sgx_quote_auth_data_t); @@ -67,7 +120,10 @@ static oe_result_t _parse_quote( p += qe_auth_data->size; if (p > quote_end) - OE_RAISE(OE_REPORT_PARSE_ERROR); + OE_RAISE_MSG( + OE_REPORT_PARSE_ERROR, + "Parse error after parsing QE authorization data.", + NULL); qe_cert_data->type = ReadUint16(p); p += 2; @@ -77,7 +133,21 @@ static oe_result_t _parse_quote( p += qe_cert_data->size; if (p != quote_end) - OE_RAISE(OE_REPORT_PARSE_ERROR); + OE_RAISE_MSG( + OE_REPORT_PARSE_ERROR, + "Unexpected quote length while parsing.", + NULL); + + // + // Validation + // + OE_CHECK_MSG( + _validate_sgx_quote(*sgx_quote), "SGX quote validation failed.", NULL); + + OE_CHECK_MSG( + _validate_qe_cert_data(qe_cert_data), + "Failed to validate QE certificate data.", + NULL); result = OE_OK; done: @@ -134,15 +204,10 @@ static oe_result_t _ecdsa_verify( return result; } -oe_result_t oe_verify_quote_internal( +static oe_result_t oe_verify_quote_internal( const uint8_t* quote, size_t quote_size, - const uint8_t* pem_pck_certificate, - size_t pem_pck_certificate_size, - const uint8_t* pck_crl, - size_t pck_crl_size, - const uint8_t* tcb_info_json, - size_t tcb_info_json_size) + bool no_collaterals) { oe_result_t result = OE_UNEXPECTED; sgx_quote_t* sgx_quote = NULL; @@ -161,84 +226,89 @@ oe_result_t oe_verify_quote_internal( oe_ec_public_key_t expected_root_public_key = {0}; bool key_equal = false; - OE_UNUSED(pck_crl); - OE_UNUSED(pck_crl_size); - OE_UNUSED(tcb_info_json); - OE_UNUSED(tcb_info_json_size); - - OE_CHECK(_parse_quote( - quote, - quote_size, - &sgx_quote, - "e_auth_data, - &qe_auth_data, - &qe_cert_data)); + uint8_t* pem_pck_certificate = NULL; + size_t pem_pck_certificate_size = 0; - if (sgx_quote->version != OE_SGX_QUOTE_VERSION) - { - OE_RAISE_MSG( - OE_QUOTE_VERIFICATION_ERROR, - "Unexpected quote version sgx_quote->version=%d", - sgx_quote->version); - } - - // The certificate provided in the quote is preferred. - if (qe_cert_data.type == OE_SGX_PCK_ID_PCK_CERT_CHAIN) - { - if (qe_cert_data.size == 0) - OE_RAISE(OE_QUOTE_VERIFICATION_ERROR); - pem_pck_certificate = qe_cert_data.data; - pem_pck_certificate_size = qe_cert_data.size; - } - else - { - OE_RAISE_MSG( - OE_MISSING_CERTIFICATE_CHAIN, - "Unexpected certificate type (qe_cert_data.type=%d)", - qe_cert_data.type); - } - - if (pem_pck_certificate == NULL) - OE_RAISE_MSG( - OE_MISSING_CERTIFICATE_CHAIN, "No certificate found", NULL); + OE_CHECK_MSG( + _parse_quote( + quote, + quote_size, + &sgx_quote, + "e_auth_data, + &qe_auth_data, + &qe_cert_data), + "Failed to parse quote. %s", + oe_result_str(result)); + + pem_pck_certificate = qe_cert_data.data; + pem_pck_certificate_size = qe_cert_data.size; // PckCertificate Chain validations. { // Read and validate the chain. - OE_CHECK(oe_cert_chain_read_pem( - &pck_cert_chain, pem_pck_certificate, pem_pck_certificate_size)); + OE_CHECK_MSG( + oe_cert_chain_read_pem( + &pck_cert_chain, pem_pck_certificate, pem_pck_certificate_size), + "Failed to parse certificate chain.", + NULL); // Fetch leaf and root certificates. - OE_CHECK(oe_cert_chain_get_leaf_cert(&pck_cert_chain, &leaf_cert)); - OE_CHECK(oe_cert_chain_get_root_cert(&pck_cert_chain, &root_cert)); - OE_CHECK( - oe_cert_chain_get_cert(&pck_cert_chain, 1, &intermediate_cert)); + OE_CHECK_MSG( + oe_cert_chain_get_leaf_cert(&pck_cert_chain, &leaf_cert), + "Failed to get leaf certificate.", + NULL); + OE_CHECK_MSG( + oe_cert_chain_get_root_cert(&pck_cert_chain, &root_cert), + "Failed to get root certificate.", + NULL); + OE_CHECK_MSG( + oe_cert_chain_get_cert(&pck_cert_chain, 1, &intermediate_cert), + "Failed to get intermediate certificate.", + NULL); - OE_CHECK(oe_cert_get_ec_public_key(&leaf_cert, &leaf_public_key)); - OE_CHECK(oe_cert_get_ec_public_key(&root_cert, &root_public_key)); + // Get public keys. + OE_CHECK_MSG( + oe_cert_get_ec_public_key(&leaf_cert, &leaf_public_key), + "Failed to get leaf cert public key.", + NULL); + OE_CHECK_MSG( + oe_cert_get_ec_public_key(&root_cert, &root_public_key), + "Failed to get root cert public key.", + NULL); // Ensure that the root certificate matches root of trust. - OE_CHECK(oe_ec_public_key_read_pem( - &expected_root_public_key, - (const uint8_t*)g_expected_root_certificate_key, - oe_strlen(g_expected_root_certificate_key) + 1)); - - OE_CHECK(oe_ec_public_key_equal( - &root_public_key, &expected_root_public_key, &key_equal)); - if (!key_equal) - OE_RAISE(OE_QUOTE_VERIFICATION_ERROR); - OE_CHECK_MSG( - oe_enforce_revocation( - &leaf_cert, &intermediate_cert, &pck_cert_chain), - "enforcing CRL", + oe_ec_public_key_read_pem( + &expected_root_public_key, + (const uint8_t*)g_expected_root_certificate_key, + oe_strlen(g_expected_root_certificate_key) + 1), + "Failed to read expected root cert key.", NULL); + OE_CHECK_MSG( + oe_ec_public_key_equal( + &root_public_key, &expected_root_public_key, &key_equal), + "Failed to compare keys.", + NULL); + if (!key_equal) + OE_RAISE_MSG( + OE_QUOTE_VERIFICATION_ERROR, + "Failed to verify root public key.", + NULL); + + if (no_collaterals) + OE_CHECK_MSG( + oe_enforce_revocation(&leaf_cert, &intermediate_cert), + "Failed when enforcing CRL", + NULL); } // Quote validations. { // Verify SHA256 ECDSA (qe_report_body_signature, qe_report_body, // PckCertificate.pub_key) + // + // Hash with PCK(QE report body) == QE report body signature + // OE_CHECK_MSG( _ecdsa_verify( &leaf_public_key, @@ -257,23 +327,26 @@ oe_result_t oe_verify_quote_internal( (const uint8_t*)"e_auth_data->attestation_key, sizeof(quote_auth_data->attestation_key))); if (qe_auth_data.size > 0) - { OE_CHECK(oe_sha256_update( &sha256_ctx, qe_auth_data.data, qe_auth_data.size)); - } OE_CHECK(oe_sha256_final(&sha256_ctx, &sha256)); if (!oe_constant_time_mem_equal( &sha256, "e_auth_data->qe_report_body.report_data, sizeof(sha256))) - OE_RAISE(OE_QUOTE_VERIFICATION_ERROR); + OE_RAISE_MSG( + OE_QUOTE_VERIFICATION_ERROR, + "QE authentication data signature verification failed.", + NULL); // Verify SHA256 ECDSA (attestation_key, SGX_QUOTE_SIGNED_DATA, // signature) + // + // Hash with attestation_key(sgx_quote) == quote_auth_data signature + // OE_CHECK(_read_public_key( "e_auth_data->attestation_key, &attestation_key)); - OE_CHECK_MSG( _ecdsa_verify( &attestation_key, @@ -284,11 +357,12 @@ oe_result_t oe_verify_quote_internal( NULL); } - // Quoting Enclave validations. - OE_CHECK_MSG( - oe_enforce_qe_identity("e_auth_data->qe_report_body), - "Quoting enclave identity checking", - NULL); + if (no_collaterals) + OE_CHECK_MSG( + oe_validate_qe_report_body("e_auth_data->qe_report_body), + "Quoting enclave identity checking", + NULL); + result = OE_OK; done: @@ -302,3 +376,311 @@ oe_result_t oe_verify_quote_internal( oe_cert_chain_free(&pck_cert_chain); return result; } + +oe_result_t oe_get_quote_cert_chain_internal( + const uint8_t* quote, + const size_t quote_size, + const uint8_t** pem_pck_certificate, + size_t* pem_pck_certificate_size, + oe_cert_chain_t* pck_cert_chain) +{ + oe_result_t result = OE_UNEXPECTED; + sgx_quote_t* sgx_quote = NULL; + sgx_quote_auth_data_t* quote_auth_data = NULL; + sgx_qe_auth_data_t qe_auth_data = {0}; + sgx_qe_cert_data_t qe_cert_data = {0}; + + if (quote == NULL || pem_pck_certificate == NULL || pck_cert_chain == NULL) + { + OE_RAISE(OE_INVALID_PARAMETER); + } + + OE_CHECK_MSG( + _parse_quote( + quote, + quote_size, + &sgx_quote, + "e_auth_data, + &qe_auth_data, + &qe_cert_data), + "Failed to parse quote. %s", + oe_result_str(result)); + + *pem_pck_certificate = qe_cert_data.data; + *pem_pck_certificate_size = qe_cert_data.size; + + // Read and validate the chain. + OE_CHECK(oe_cert_chain_read_pem( + pck_cert_chain, *pem_pck_certificate, *pem_pck_certificate_size)); + + result = OE_OK; +done: + + return result; +} + +static void _update_validity( + oe_datetime_t* latest_from, + oe_datetime_t* earliest_until, + oe_datetime_t* from, + oe_datetime_t* until) +{ + if (oe_datetime_compare(from, latest_from) > 0) + { + *latest_from = *from; + } + + if (oe_datetime_compare(until, earliest_until) < 0) + { + *earliest_until = *until; + } +} + +oe_result_t oe_verify_quote_internal_with_collaterals( + const uint8_t* quote, + size_t quote_size, + const uint8_t* collaterals, + size_t collaterals_size, + oe_datetime_t* validation_time) +{ + oe_result_t result = OE_UNEXPECTED; + + uint8_t* local_collaterals = NULL; + size_t local_collaterals_size = 0; + oe_datetime_t validity_from = {0}; + oe_datetime_t validity_until = {0}; + oe_datetime_t creation_time = {0}; + + bool no_collaterals = false; + + if (quote == NULL) + OE_RAISE(OE_INVALID_PARAMETER); + + if (collaterals == NULL) + { + result = oe_get_collaterals_internal( + quote, + quote_size, + (uint8_t**)&local_collaterals, + &local_collaterals_size); + + if (result == OE_QUOTE_PROVIDER_CALL_ERROR) + { + // No qe_identity info returned from the quote provider, this could + // be because either get_qe_identity_info API was not supported or + // unexpected error. In both cases, check against hardcoded quoting + // enclave properties instead Assert that the qe report's MRSIGNER + // matches Intel's quoting. We will remove these hardcoded values + // once the libdcap_quoteprov.so was updated to support qe identity + // feature. + no_collaterals = true; + } + else + { + OE_CHECK_MSG( + result, "Failed to get collaterals. %s", oe_result_str(result)); + collaterals = local_collaterals; + collaterals_size = local_collaterals_size; + } + } + + OE_CHECK_MSG( + oe_verify_quote_internal(quote, quote_size, no_collaterals), + "Failed to verify remote quote.", + NULL); + + if (!no_collaterals) + { + oe_collaterals_t* collaterals_body = + (oe_collaterals_t*)(collaterals + OE_COLLATERALS_HEADER_SIZE); + + OE_CHECK_MSG( + oe_get_quote_validity_with_collaterals_internal( + quote, + quote_size, + collaterals, + collaterals_size, + &validity_from, + &validity_until), + "Failed to validate quote. %s", + oe_result_str(result)); + + // Verify quote/collaterals for the given time. Use collateral creation + // time if one was not provided. + if (validation_time == NULL) + { + OE_CHECK_MSG( + oe_datetime_from_string( + collaterals_body->creation_datetime, + sizeof(collaterals_body->creation_datetime), + &creation_time), + "Invalid creation time in collaterals.", + NULL); + validation_time = &creation_time; + } + + oe_datetime_log_info("Validation datetime: ", validation_time); + if (oe_datetime_compare(validation_time, &validity_from) < 0) + { + oe_datetime_log_info("Latests valid datetime: ", &validity_from); + OE_RAISE_MSG( + OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD, + "Time to validate quote is earlier than the " + "latest 'valid from' value.", + NULL); + } + if (oe_datetime_compare(validation_time, &validity_until) > 0) + { + oe_datetime_log_info( + "Earliest expiration datetime: ", &validity_until); + OE_RAISE_MSG( + OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD, + "Time to validate quoteis later than the " + "earliest 'valid to' value.", + NULL); + } + } + + result = OE_OK; + +done: + if (local_collaterals) + oe_free_collaterals_internal(local_collaterals); + + return result; +} + +oe_result_t oe_get_quote_validity_with_collaterals_internal( + const uint8_t* quote, + const size_t quote_size, + const uint8_t* collaterals, + size_t collaterals_size, + oe_datetime_t* valid_from, + oe_datetime_t* valid_until) +{ + oe_result_t result = OE_UNEXPECTED; + + sgx_quote_t* sgx_quote = NULL; + sgx_quote_auth_data_t* quote_auth_data = NULL; + sgx_qe_auth_data_t qe_auth_data = {0}; + sgx_qe_cert_data_t qe_cert_data = {0}; + + const uint8_t* pem_pck_certificate = NULL; + size_t pem_pck_certificate_size = 0; + oe_cert_chain_t pck_cert_chain = {0}; + + oe_collaterals_header_t* col_header = (oe_collaterals_header_t*)collaterals; + oe_collaterals_t* col = + (oe_collaterals_t*)(collaterals + OE_COLLATERALS_HEADER_SIZE); + + oe_cert_t root_cert = {0}; + oe_cert_t intermediate_cert = {0}; + oe_cert_t pck_cert = {0}; + + oe_datetime_t latest_from = {0}; + oe_datetime_t earliest_until = {0}; + oe_datetime_t from; + oe_datetime_t until; + + if ((quote == NULL) || (collaterals == NULL) || (valid_from == NULL) || + (valid_until == NULL)) + OE_RAISE(OE_INVALID_PARAMETER); + + if ((col_header->collaterals_size != OE_COLLATERALS_BODY_SIZE) || + (collaterals_size != OE_COLLATERALS_SIZE)) + OE_RAISE_MSG(OE_INVALID_PARAMETER, "Invalid collaterals size.", NULL); + + OE_TRACE_INFO("Call enter %s\n", __FUNCTION__); + + OE_CHECK_MSG( + _parse_quote( + quote, + quote_size, + &sgx_quote, + "e_auth_data, + &qe_auth_data, + &qe_cert_data), + "Failed to parse quote. %s", + oe_result_str(result)); + + pem_pck_certificate = qe_cert_data.data; + pem_pck_certificate_size = qe_cert_data.size; + + OE_CHECK_MSG( + oe_get_quote_cert_chain_internal( + quote, + quote_size, + &pem_pck_certificate, + &pem_pck_certificate_size, + &pck_cert_chain), + "Failed to retreive PCK cert chain. %s", + oe_result_str(result)); + + // Fetch certificates. + OE_CHECK_MSG( + oe_cert_chain_get_leaf_cert(&pck_cert_chain, &pck_cert), + "Failed to get leaf certificate.", + NULL); + OE_CHECK_MSG( + oe_cert_chain_get_root_cert(&pck_cert_chain, &root_cert), + "Failed to get root certificate.", + NULL); + OE_CHECK_MSG( + oe_cert_chain_get_cert(&pck_cert_chain, 1, &intermediate_cert), + "Failed to get intermediate certificate.", + NULL); + + // Process certs validity dates. + OE_CHECK_MSG( + oe_cert_get_validity_dates(&root_cert, &latest_from, &earliest_until), + "Failed to get validity info from cert. %s", + oe_result_str(result)); + OE_CHECK_MSG( + oe_cert_get_validity_dates(&intermediate_cert, &from, &until), + "Failed to get validity info from cert. %s", + oe_result_str(result)); + _update_validity(&latest_from, &earliest_until, &from, &until); + + OE_CHECK_MSG( + oe_cert_get_validity_dates(&pck_cert, &from, &until), + "Failed to get validity info from cert. %s", + oe_result_str(result)); + _update_validity(&latest_from, &earliest_until, &from, &until); + + // Fetch revocation info validity dates. + OE_CHECK_MSG( + oe_validate_revocation_list( + &pck_cert, &col->revocation_info, &from, &until), + "Failed to validate revocation info. %s", + oe_result_str(result)); + _update_validity(&latest_from, &earliest_until, &from, &until); + + // QE identity info validity dates. + OE_CHECK_MSG( + oe_validate_qe_identity( + "e_auth_data->qe_report_body, &col->qe_id_info, &from, &until), + "Failed quoting enclave identity checking. %s", + oe_result_str(result)); + _update_validity(&latest_from, &earliest_until, &from, &until); + + oe_datetime_log_info("Quote overall issue date: ", &latest_from); + oe_datetime_log_info("Quote overall next update: ", &earliest_until); + if (oe_datetime_compare(&latest_from, &earliest_until) > 0) + OE_RAISE_MSG( + OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD, + "Failed to find an overall validity period in quote.", + NULL); + + *valid_from = latest_from; + *valid_until = earliest_until; + + result = OE_OK; + +done: + oe_cert_free(&pck_cert); + oe_cert_free(&intermediate_cert); + oe_cert_free(&root_cert); + oe_cert_chain_free(&pck_cert_chain); + + return result; +} diff --git a/common/sgx/quote.h b/common/sgx/quote.h index bf279e25de..a1aa93357b 100644 --- a/common/sgx/quote.h +++ b/common/sgx/quote.h @@ -7,18 +7,80 @@ #include #include #include +#include OE_EXTERNC_BEGIN -oe_result_t oe_verify_quote_internal( - const uint8_t* enc_quote, +/*! + * Verify quote with optional collaterals. + * + * @param quote[in] Input quote. + * @param quote_size[in] The size of the quote. + * @param collaterals[in] Optional collaterals related to the quote. + * @param collatterals_size[in] The size of the collaterals. + * @param input_validation_time[in] Optional time to use for validation, + * defaults to the time the collaterals were created. + */ +oe_result_t oe_verify_quote_internal_with_collaterals( + const uint8_t* quote, size_t quote_size, - const uint8_t* enc_pem_pck_certificate, - size_t pem_pck_certificate_size, - const uint8_t* enc_pck_crl, - size_t enc_pck_crl_size, - const uint8_t* enc_tcb_info_json, - size_t enc_tcb_info_json_size); + const uint8_t* collaterals, + size_t collaterals_size, + oe_datetime_t* input_validation_time); + +/*! + * Retrieves certifate chain from the quote. + * + * Caller is responsible for deallocating memory in pck_cert_chain. + * + * @param quote[in] Input quote. + * @param quote_size[in] The size of the quote. + * @param pem_pck_certifcate[out] Pointer to the quote where the certificate PCK + * starts. + * @param pem_pck_certificate_size[out] Size of the PCK certificate. + * @param pck_cert_chain[out] Reference to an instance of oe_cert_chain_t where + * to store the chain. Caller needs to free resources by calling + * oe_cert_chain_free() + */ +oe_result_t oe_get_quote_cert_chain_internal( + const uint8_t* quote, + const size_t quote_size, + const uint8_t** pem_pck_certificate, + size_t* pem_pck_certificate_size, + oe_cert_chain_t* pck_cert_chain); + +/*! + * Find the valid datetime range for the given quote, collaterals. This + * function accounts for the following items: + * + * 1. From the quote: + * a) Root CA. + * b) Intermediate CA. + * b) PCK CA. + * 2. From the revocation info: + * a) Root CA CRL. + * b) Intermediate CA CRL. + * c) PCK CA CRL. + * d) TCB info cert. + * e) TCB info. + * 3. From QE identity info + * a) QE identity cert. + * b) QE identity. + * + * @param quote[in] Input quote. + * @param quote_size[in] The size of the quote. + * @param collaterals[in] Optional collaterals related to the quote. + * @param collatterals_size[in] The size of the collaterals. + * @param valid_from[out] validity_from The date from which the quote is valid. + * @param valid_until[out] validity_until The date which the quote expires. + */ +oe_result_t oe_get_quote_validity_with_collaterals_internal( + const uint8_t* quote, + const size_t quote_size, + const uint8_t* collaterals, + size_t collaterals_size, + oe_datetime_t* valid_from, + oe_datetime_t* valid_until); OE_EXTERNC_END diff --git a/common/sgx/revocation.c b/common/sgx/revocation.c index 1b0884211c..9e968b8d3b 100644 --- a/common/sgx/revocation.c +++ b/common/sgx/revocation.c @@ -42,6 +42,104 @@ oe_result_t __oe_sgx_set_minimum_crl_tcb_issue_date( return result; } +static oe_result_t _get_tcb_info_validity( + const oe_parsed_tcb_info_t* parsed_tcb_info, + oe_datetime_t* from, + oe_datetime_t* until) +{ + *from = parsed_tcb_info->issue_date; + *until = parsed_tcb_info->next_update; + + return OE_OK; +} + +static oe_result_t _get_crl_validity( + const oe_crl_t* crls, + const uint32_t crls_count, + oe_datetime_t* from, + oe_datetime_t* until) +{ + oe_result_t result = OE_UNEXPECTED; + oe_datetime_t crl_this_update_date = {0}; + oe_datetime_t crl_next_update_date = {0}; + + if (crls_count > 0) + { + OE_CHECK_MSG( + oe_crl_get_update_dates(&crls[0], from, until), + "Failed to get CRL update dates. %s", + oe_result_str(result)); + + for (uint32_t i = 0; i < crls_count; ++i) + { + OE_CHECK_MSG( + oe_crl_get_update_dates( + &crls[0], &crl_this_update_date, &crl_next_update_date), + "Failed to get CRL update dates. %s", + oe_result_str(result)); + + if (oe_datetime_compare(&crl_this_update_date, from) > 0) + { + *from = crl_this_update_date; + } + if (oe_datetime_compare(&crl_next_update_date, until) < 0) + { + *until = crl_next_update_date; + } + } + + result = OE_OK; + } + +done: + return result; +} + +static oe_result_t _get_revocation_validity( + const oe_parsed_tcb_info_t* parsed_tcb_info, + const oe_crl_t* crls, + const uint32_t crls_count, + oe_datetime_t* from, + oe_datetime_t* until) +{ + oe_result_t result = OE_UNEXPECTED; + oe_datetime_t latest_from = {0}; + oe_datetime_t earliest_until = {0}; + oe_datetime_t current_from = {0}; + oe_datetime_t current_until = {0}; + + OE_CHECK_MSG( + _get_tcb_info_validity(parsed_tcb_info, &latest_from, &earliest_until), + "Failed to get TCB info validity datetime info. %s", + oe_result_str(result)); + oe_datetime_log_info("TCB info validity from date: ", &latest_from); + oe_datetime_log_info("TCB info validity until date: ", &earliest_until); + + OE_CHECK_MSG( + _get_crl_validity(crls, crls_count, ¤t_from, ¤t_until), + "Failed to get CRL validity datetime info. %s", + oe_result_str(result)); + oe_datetime_log_info("CRL validity from date: ", ¤t_from); + oe_datetime_log_info("CRL validity until date: ", ¤t_until); + + // Currently we are ignoring TCB Info validity dates because + // the data is expired. See Icm 148493545 + latest_from = current_from; + earliest_until = current_until; + + oe_datetime_log_info( + "Revocation overall validity from date: ", &latest_from); + oe_datetime_log_info( + "Revocation overall validity until date: ", &earliest_until); + + *from = latest_from; + *until = earliest_until; + result = OE_OK; + +done: + return result; +} + /** * Parse sgx extensions from given cert. */ @@ -141,50 +239,28 @@ static oe_result_t _get_crl_distribution_point(oe_cert_t* cert, char** url) return result; } -static void _trace_datetime(const char* msg, const oe_datetime_t* date) -{ - if (oe_get_current_logging_level() >= OE_LOG_LEVEL_INFO) - { - char str[21]; - size_t size = sizeof(str); - oe_datetime_to_string(date, str, &size); - OE_TRACE_INFO("%s%s\n", msg, str); - } -} - -oe_result_t oe_enforce_revocation( +/** + * Call into host to fetch revocation information given the CA and PCK + * certificates. + */ +oe_result_t oe_get_revocation_info_from_certs( oe_cert_t* leaf_cert, oe_cert_t* intermediate_cert, - oe_cert_chain_t* pck_cert_chain) + oe_get_revocation_info_args_t* args) { oe_result_t result = OE_FAILURE; ParsedExtensionInfo parsed_extension_info = {{0}}; - oe_get_revocation_info_args_t revocation_args = {0}; - oe_cert_chain_t tcb_issuer_chain = {0}; - oe_cert_chain_t crl_issuer_chain[3] = {{{0}}}; - oe_parsed_tcb_info_t parsed_tcb_info = {0}; - oe_tcb_level_t platform_tcb_level = {{0}}; char* intermediate_crl_url = NULL; char* leaf_crl_url = NULL; - oe_crl_t crls[2] = {{{0}}}; - const oe_crl_t* crl_ptrs[2] = {&crls[0], &crls[1]}; - oe_datetime_t crl_this_update_date = {0}; - oe_datetime_t crl_next_update_date = {0}; - - OE_UNUSED(pck_cert_chain); if (intermediate_cert == NULL || leaf_cert == NULL) OE_RAISE(OE_INVALID_PARAMETER); - OE_STATIC_ASSERT( - OE_COUNTOF(crl_issuer_chain) == - OE_COUNTOF(revocation_args.crl_issuer_chain)); - // Gather fmspc. OE_CHECK(_parse_sgx_extensions(leaf_cert, &parsed_extension_info)); OE_CHECK(oe_memcpy_s( - revocation_args.fmspc, - sizeof(revocation_args.fmspc), + args->fmspc, + sizeof(args->fmspc), parsed_extension_info.fmspc, sizeof(parsed_extension_info.fmspc))); @@ -193,32 +269,109 @@ oe_result_t oe_enforce_revocation( _get_crl_distribution_point(intermediate_cert, &intermediate_crl_url)); OE_CHECK(_get_crl_distribution_point(leaf_cert, &leaf_crl_url)); - revocation_args.crl_urls[0] = leaf_crl_url; - revocation_args.crl_urls[1] = intermediate_crl_url; - revocation_args.num_crl_urls = 2; + args->crl_urls[0] = leaf_crl_url; + args->crl_urls[1] = intermediate_crl_url; + args->num_crl_urls = 2; - OE_CHECK(oe_get_revocation_info(&revocation_args)); + OE_CHECK(oe_get_revocation_info(args)); + + result = OE_OK; +done: + + oe_free(leaf_crl_url); + oe_free(intermediate_crl_url); + + return result; +} + +oe_result_t oe_enforce_revocation( + oe_cert_t* leaf_cert, + oe_cert_t* intermediate_cert) +{ + oe_result_t result = OE_UNEXPECTED; + oe_get_revocation_info_args_t revocation_args = {0}; + oe_datetime_t validity_from = {0}; + oe_datetime_t validity_until = {0}; + + OE_CHECK(oe_get_revocation_info_from_certs( + leaf_cert, intermediate_cert, &revocation_args)); + + OE_CHECK(oe_validate_revocation_list( + leaf_cert, &revocation_args, &validity_from, &validity_until)); + + result = OE_OK; + +done: + oe_free_get_revocation_info_args(&revocation_args); + + return result; +} + +oe_result_t oe_validate_revocation_list( + oe_cert_t* pck_cert, + oe_get_revocation_info_args_t* revocation_args, + oe_datetime_t* validity_from, + oe_datetime_t* validity_until) +{ + oe_result_t result = OE_UNEXPECTED; + + ParsedExtensionInfo parsed_extension_info = {{0}}; + oe_cert_chain_t tcb_issuer_chain = {0}; + oe_cert_chain_t crl_issuer_chain[3] = {{{0}}}; + oe_cert_t tcb_cert = {0}; + oe_parsed_tcb_info_t parsed_tcb_info = {0}; + oe_tcb_level_t platform_tcb_level = {{0}}; + + oe_crl_t crls[2] = {{{0}}}; + const oe_crl_t* crl_ptrs[2] = {&crls[0], &crls[1]}; + oe_datetime_t from = {0}; + oe_datetime_t until = {0}; + oe_datetime_t latest_from = {0}; + oe_datetime_t earliest_until = {0}; + + if (pck_cert == NULL || revocation_args == NULL) + OE_RAISE(OE_INVALID_PARAMETER); + + OE_STATIC_ASSERT( + OE_COUNTOF(crl_issuer_chain) == + OE_COUNTOF(revocation_args->crl_issuer_chain)); + + OE_CHECK_MSG( + _parse_sgx_extensions(pck_cert, &parsed_extension_info), + "Failed to parse SGX extensions from leaf cert. %s", + oe_result_str(result)); // Apply revocation info. - OE_CHECK(oe_cert_chain_read_pem( - &tcb_issuer_chain, - revocation_args.tcb_issuer_chain, - revocation_args.tcb_issuer_chain_size)); + OE_CHECK_MSG( + oe_cert_chain_read_pem( + &tcb_issuer_chain, + revocation_args->tcb_issuer_chain, + revocation_args->tcb_issuer_chain_size), + "Failed to read TCB chain certificate. %s", + oe_result_str(result)); // Read CRLs for each cert other than root. If any CRL is missing, the read // will error out. - for (uint32_t i = 0; i < revocation_args.num_crl_urls; ++i) + for (uint32_t i = 0; i < revocation_args->num_crl_urls; ++i) { - OE_CHECK(oe_crl_read_der( - &crls[i], revocation_args.crl[i], revocation_args.crl_size[i])); - OE_CHECK(oe_cert_chain_read_pem( - &crl_issuer_chain[i], - revocation_args.crl_issuer_chain[i], - revocation_args.crl_issuer_chain_size[i])); + OE_CHECK_MSG( + oe_crl_read_der( + &crls[i], + revocation_args->crl[i], + revocation_args->crl_size[i]), + "Failed to read CRL. %s", + oe_result_str(result)); + OE_CHECK_MSG( + oe_cert_chain_read_pem( + &crl_issuer_chain[i], + revocation_args->crl_issuer_chain[i], + revocation_args->crl_issuer_chain_size[i]), + "Failed to read CRL cert chain. %s", + oe_result_str(result)); OE_TRACE_VERBOSE( "CRL certificate[%d]: \n[%s]\n", i, - revocation_args.crl_issuer_chain[i]); + revocation_args->crl_issuer_chain[i]); } // Verify the leaf cert. @@ -236,8 +389,11 @@ oe_result_t oe_enforce_revocation( // constraint. If the crl_issuer_chain was different from the certificate // chain, then verification would fail because the CRLs will not be found // for certificates in the chain. - OE_CHECK(oe_cert_verify( - leaf_cert, crl_issuer_chain, crl_ptrs, OE_COUNTOF(crl_ptrs))); + OE_CHECK_MSG( + oe_cert_verify( + pck_cert, crl_issuer_chain, crl_ptrs, OE_COUNTOF(crl_ptrs)), + "Failed to verify leaf certificate. %s", + oe_result_str(result)); for (uint32_t i = 0; i < OE_COUNTOF(platform_tcb_level.sgx_tcb_comp_svn); ++i) @@ -248,62 +404,96 @@ oe_result_t oe_enforce_revocation( platform_tcb_level.pce_svn = parsed_extension_info.pce_svn; platform_tcb_level.status = OE_TCB_LEVEL_STATUS_UNKNOWN; - OE_CHECK(oe_parse_tcb_info_json( - revocation_args.tcb_info, - revocation_args.tcb_info_size, - &platform_tcb_level, - &parsed_tcb_info)); - - OE_CHECK(oe_verify_ecdsa256_signature( - parsed_tcb_info.tcb_info_start, - parsed_tcb_info.tcb_info_size, - (sgx_ecdsa256_signature_t*)parsed_tcb_info.signature, - &tcb_issuer_chain)); - - // Check that the tcb has been issued after the earliest date that the - // enclave accepts. - if (oe_datetime_compare( - &parsed_tcb_info.issue_date, &_sgx_minimim_crl_tcb_issue_date) != 1) - OE_RAISE(OE_INVALID_REVOCATION_INFO); - - // Check that the CRLs have not expired. - // The next update of the CRL must be after the earliest date that - // the enclave accepts. - for (uint32_t i = 0; i < OE_COUNTOF(crls); ++i) + OE_CHECK_MSG( + oe_parse_tcb_info_json( + revocation_args->tcb_info, + revocation_args->tcb_info_size, + &platform_tcb_level, + &parsed_tcb_info), + "Failed to parse TCB info. %s", + oe_result_str(result)); + + OE_CHECK_MSG( + oe_verify_ecdsa256_signature( + parsed_tcb_info.tcb_info_start, + parsed_tcb_info.tcb_info_size, + (sgx_ecdsa256_signature_t*)parsed_tcb_info.signature, + &tcb_issuer_chain), + "Failed to verify ECDSA 256 signature in TCB. %s", + oe_result_str(result)); + + OE_CHECK_MSG( + _get_revocation_validity( + &parsed_tcb_info, + crls, + OE_COUNTOF(crls), + &latest_from, + &earliest_until), + "Failed to get revocation validity datetime info. %s", + oe_result_str(result)); + + if (oe_datetime_compare(&latest_from, &_sgx_minimim_crl_tcb_issue_date) < 0) { - OE_CHECK(oe_crl_get_update_dates( - &crls[i], &crl_this_update_date, &crl_next_update_date)); - - _trace_datetime("crl this update date ", &crl_this_update_date); - _trace_datetime("crl next update date ", &crl_next_update_date); - - // CRL must be issued after minimum date. - if (oe_datetime_compare( - &crl_this_update_date, &_sgx_minimim_crl_tcb_issue_date) != 1) - OE_RAISE(OE_INVALID_REVOCATION_INFO); + oe_datetime_log_info("Latest issue date : ", &latest_from); + oe_datetime_log_info( + " is earlier than minimum issue date: ", + &_sgx_minimim_crl_tcb_issue_date); + OE_RAISE_MSG( + OE_INVALID_REVOCATION_INFO, + "Revocation validation failed minimum issue date. %s", + oe_result_str(result)); + } - // Also check that next update date is after minimum date. - if (oe_datetime_compare( - &crl_next_update_date, &_sgx_minimim_crl_tcb_issue_date) != 1) - OE_RAISE(OE_INVALID_REVOCATION_INFO); + if (oe_datetime_compare(&earliest_until, &_sgx_minimim_crl_tcb_issue_date) < + 0) + { + oe_datetime_log_info("Next update date : ", &earliest_until); + oe_datetime_log_info( + " is earlier than minimum issue date: ", + &_sgx_minimim_crl_tcb_issue_date); + OE_RAISE_MSG( + OE_INVALID_REVOCATION_INFO, + "Revocation validation failed minimum issue date. %s", + oe_result_str(result)); } + // Get TCB cert validity period. + OE_CHECK_MSG( + oe_cert_chain_get_leaf_cert(&tcb_issuer_chain, &tcb_cert), + "Failed to get TCB certificate.", + NULL); + oe_cert_get_validity_dates(&tcb_cert, &from, &until); + oe_datetime_log_info("TCB cert issue date: ", &from); + oe_datetime_log_info("TCB cert next update: ", &until); + + if (oe_datetime_compare(&from, &latest_from) > 0) + latest_from = from; + if (oe_datetime_compare(&until, &earliest_until) < 0) + earliest_until = until; + oe_datetime_log_info("Revocation overall issue date: ", &latest_from); + oe_datetime_log_info("Revocation overall next update: ", &earliest_until); + + if (oe_datetime_compare(&latest_from, &earliest_until) > 0) + OE_RAISE_MSG( + OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD, + "Failed to find an overall revocation validity period.", + NULL); + + *validity_from = latest_from; + *validity_until = earliest_until; result = OE_OK; done: - for (int32_t i = (int32_t)revocation_args.num_crl_urls - 1; i >= 0; --i) + for (int32_t i = (int32_t)revocation_args->num_crl_urls - 1; i >= 0; --i) { oe_crl_free(&crls[i]); } - for (uint32_t i = 0; i < revocation_args.num_crl_urls; ++i) + for (uint32_t i = 0; i < revocation_args->num_crl_urls; ++i) { oe_cert_chain_free(&crl_issuer_chain[i]); } oe_cert_chain_free(&tcb_issuer_chain); - - oe_free(leaf_crl_url); - oe_free(intermediate_crl_url); - oe_cleanup_get_revocation_info_args(&revocation_args); + oe_cert_free(&tcb_cert); return result; -} +} \ No newline at end of file diff --git a/common/sgx/revocation.h b/common/sgx/revocation.h index e5abbe24df..fc2e2436fe 100644 --- a/common/sgx/revocation.h +++ b/common/sgx/revocation.h @@ -12,16 +12,67 @@ OE_EXTERNC_BEGIN +/** + * This function gets the revocation information from the given + * PCK Cert and CA cert and does validation. + * + * @param[in] leaf_cert The PCK certificate. + * @param[in] revocation_args The revocation information. + */ oe_result_t oe_enforce_revocation( + oe_cert_t* leaf_cert, + oe_cert_t* intermediate_cert); + +/** Validate revocation info. Make sure the following: + * + * 1. TCB info. + * 2. CRL. + * + * Are valid and returns the validity dates for this + * revocation information for the caller to validate. + * + * @param pck_cert[in] The PCK certificate. + * @param revocation_args[in] The revocation information. + * @param validity_from[out] The date from which the revocation info is valid. + * @param validity_until[out] The date which the revocation info expires. + */ +oe_result_t oe_validate_revocation_list( + oe_cert_t* pck_cert, + oe_get_revocation_info_args_t* revocation_args, + oe_datetime_t* validity_from, + oe_datetime_t* validity_until); + +/** + * Fetch revocation info for the PCK certificate and CA + * certificate. + * + * Caller is responsbile for freeing the revocation info resources + * by calling oe_free_get_revocation_info_args(). + * + * @param leaf_cert[in] the PCK certificate. + * @param intermediate_cert[in] the CA certificate. + * @param args[out] the revocation info. + */ +oe_result_t oe_get_revocation_info_from_certs( oe_cert_t* leaf_cert, oe_cert_t* intermediate_cert, - oe_cert_chain_t* pck_cert_chain); + oe_get_revocation_info_args_t* args); -// Fetch revocation info using the specified args structure. +/** + * Get the revocation info. Caller is responsible for + * configuring the revocation info input parameters. + * + * @param args[in/out] the revocation info. + */ oe_result_t oe_get_revocation_info(oe_get_revocation_info_args_t* args); -// Cleanup the args structure. -void oe_cleanup_get_revocation_info_args(oe_get_revocation_info_args_t* args); +/** + * Free resources allocated by oe_get_revocation_info() and + * oe_get_revocation_info_from_certs(). + * + * @param args[in] the revocation info. + */ +void oe_free_get_revocation_info_args(oe_get_revocation_info_args_t* args); OE_EXTERNC_END diff --git a/enclave/CMakeLists.txt b/enclave/CMakeLists.txt index 84891f5a51..30ce23569f 100644 --- a/enclave/CMakeLists.txt +++ b/enclave/CMakeLists.txt @@ -6,6 +6,7 @@ add_subdirectory(crypto) if (OE_SGX) set(PLATFORM_SRC + ../common/sgx/collaterals.c ../common/sgx/qeidentity.c ../common/sgx/quote.c ../common/sgx/report.c diff --git a/enclave/core/CMakeLists.txt b/enclave/core/CMakeLists.txt index c12447fdd3..4afb255ffd 100644 --- a/enclave/core/CMakeLists.txt +++ b/enclave/core/CMakeLists.txt @@ -50,6 +50,7 @@ set(MUSL_SRC_DIR ${PROJECT_SOURCE_DIR}/3rdparty/musl/musl/src) if (OE_SGX) list(APPEND PLATFORM_SRC + ../../common/sgx/collaterals.c sgx/backtrace.c sgx/calls.c sgx/cpuid.c diff --git a/enclave/crypto/cert.c b/enclave/crypto/cert.c index 9b562eb890..4416cc7698 100644 --- a/enclave/crypto/cert.c +++ b/enclave/crypto/cert.c @@ -1181,3 +1181,46 @@ oe_result_t oe_gen_custom_x509_cert( return result; } + +oe_result_t oe_cert_get_validity_dates( + const oe_cert_t* cert, + oe_datetime_t* not_before, + oe_datetime_t* not_after) +{ + oe_result_t result = OE_UNEXPECTED; + const Cert* impl = (const Cert*)cert; + + if (not_before) + memset(not_before, 0, sizeof(oe_datetime_t)); + + if (not_after) + memset(not_after, 0, sizeof(oe_datetime_t)); + + /* Reject invalid parameters */ + if (!_cert_is_valid(impl)) + OE_RAISE(OE_INVALID_PARAMETER); + + if (not_before) + { + not_before->year = (uint32_t)impl->cert->valid_from.year; + not_before->month = (uint32_t)impl->cert->valid_from.mon; + not_before->day = (uint32_t)impl->cert->valid_from.day; + not_before->hours = (uint32_t)impl->cert->valid_from.hour; + not_before->minutes = (uint32_t)impl->cert->valid_from.min; + not_before->seconds = (uint32_t)impl->cert->valid_from.sec; + } + + if (not_after) + { + not_after->year = (uint32_t)impl->cert->valid_to.year; + not_after->month = (uint32_t)impl->cert->valid_to.mon; + not_after->day = (uint32_t)impl->cert->valid_to.day; + not_after->hours = (uint32_t)impl->cert->valid_to.hour; + not_after->minutes = (uint32_t)impl->cert->valid_to.min; + not_after->seconds = (uint32_t)impl->cert->valid_to.sec; + } + result = OE_OK; + +done: + return result; +} diff --git a/enclave/sgx/qeidinfo.c b/enclave/sgx/qeidinfo.c index 78d6c37899..6f4bdd45a3 100644 --- a/enclave/sgx/qeidinfo.c +++ b/enclave/sgx/qeidinfo.c @@ -117,7 +117,7 @@ oe_result_t oe_get_qe_identity_info(oe_get_qe_identity_info_args_t* args_out) } // Cleanup the args structure. -void oe_cleanup_qe_identity_info_args(oe_get_qe_identity_info_args_t* args) +void oe_free_qe_identity_info_args(oe_get_qe_identity_info_args_t* args) { if (!args) return; diff --git a/enclave/sgx/report.c b/enclave/sgx/report.c index d86a685849..a667d8e770 100644 --- a/enclave/sgx/report.c +++ b/enclave/sgx/report.c @@ -66,8 +66,8 @@ oe_result_t oe_verify_report( if (header->report_type == OE_REPORT_TYPE_SGX_REMOTE) { - OE_CHECK(oe_verify_quote_internal( - header->report, header->report_size, NULL, 0, NULL, 0, NULL, 0)); + OE_CHECK(oe_verify_quote_internal_with_collaterals( + header->report, header->report_size, NULL, 0, NULL)); } else if (header->report_type == OE_REPORT_TYPE_SGX_LOCAL) { diff --git a/enclave/sgx/revocationinfo.c b/enclave/sgx/revocationinfo.c index 0b1d1689dd..c82ea664d4 100644 --- a/enclave/sgx/revocationinfo.c +++ b/enclave/sgx/revocationinfo.c @@ -152,7 +152,7 @@ oe_result_t oe_get_revocation_info(oe_get_revocation_info_args_t* args) return result; } -void oe_cleanup_get_revocation_info_args(oe_get_revocation_info_args_t* args) +void oe_free_get_revocation_info_args(oe_get_revocation_info_args_t* args) { if (args) { diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 4a75a4e2c2..cfc0bbb4b1 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -93,6 +93,7 @@ elseif (WIN32) crypto/bcrypt/rsa.c crypto/bcrypt/sha.c crypto/bcrypt/pem.c + crypto/bcrypt/util.c windows/hostthread.c) set(PLATFORM_SDK_ONLY_SRC @@ -118,6 +119,7 @@ endif() # SGX specific files. if (OE_SGX) list(APPEND PLATFORM_HOST_ONLY_SRC + ../common/sgx/collaterals.c ../common/sgx/qeidentity.c ../common/sgx/quote.c ../common/sgx/report.c diff --git a/host/crypto/bcrypt/cert.c b/host/crypto/bcrypt/cert.c index fef8edcf78..e5ca149d21 100644 --- a/host/crypto/bcrypt/cert.c +++ b/host/crypto/bcrypt/cert.c @@ -17,6 +17,7 @@ #include "key.h" #include "pem.h" #include "rsa.h" +#include "util.h" /* **============================================================================== @@ -28,9 +29,8 @@ #define _OE_CERT_CHAIN_LENGTH_ANY 0 -static const DWORD _OE_DEFAULT_GET_CRL_FLAGS = CERT_STORE_SIGNATURE_FLAG | - CERT_STORE_TIME_VALIDITY_FLAG | - CERT_STORE_BASE_CRL_FLAG; +static const DWORD _OE_DEFAULT_GET_CRL_FLAGS = + CERT_STORE_SIGNATURE_FLAG | CERT_STORE_TIME_VALIDITY_FLAG; static const CERT_CHAIN_POLICY_PARA _OE_DEFAULT_CERT_CHAIN_POLICY = { .cbSize = sizeof(CERT_CHAIN_POLICY_PARA), @@ -1296,3 +1296,39 @@ oe_result_t oe_cert_find_extension( done: return result; } + +oe_result_t oe_cert_get_validity_dates( + const oe_cert_t* cert, + oe_datetime_t* not_before, + oe_datetime_t* not_after) +{ + oe_result_t result = OE_UNEXPECTED; + const cert_t* impl = (const cert_t*)cert; + + if (not_before) + memset(not_before, 0, sizeof(oe_datetime_t)); + + if (not_after) + memset(not_after, 0, sizeof(oe_datetime_t)); + + if (!_cert_is_valid(impl)) + OE_RAISE(OE_INVALID_PARAMETER); + + if (not_before) + { + OE_CHECK(oe_util_filetime_to_oe_datetime( + &impl->cert->pCertInfo->NotBefore, not_before)); + } + + if (not_after) + { + OE_CHECK(oe_util_filetime_to_oe_datetime( + &impl->cert->pCertInfo->NotAfter, not_after)); + } + + result = OE_OK; + +done: + + return result; +} diff --git a/host/crypto/bcrypt/crl.c b/host/crypto/bcrypt/crl.c index 658806e80c..cb8bd53b18 100644 --- a/host/crypto/bcrypt/crl.c +++ b/host/crypto/bcrypt/crl.c @@ -38,31 +38,6 @@ OE_INLINE void _crl_destroy(crl_t* impl) } } -static oe_result_t _filetime_to_oe_datetime( - const FILETIME* filetime, - oe_datetime_t* datetime) -{ - oe_result_t result = OE_UNEXPECTED; - SYSTEMTIME systime = {0}; - if (!FileTimeToSystemTime(filetime, &systime)) - OE_RAISE_MSG( - OE_INVALID_UTC_DATE_TIME, - "FileTimeToSystemTime failed, err=%#x\n", - GetLastError()); - - datetime->year = systime.wYear; - datetime->month = systime.wMonth; - datetime->day = systime.wDay; - datetime->hours = systime.wHour; - datetime->minutes = systime.wMinute; - datetime->seconds = systime.wSecond; - - result = OE_OK; - -done: - return result; -} - oe_result_t oe_crl_get_context(const oe_crl_t* crl, PCCRL_CONTEXT* crl_context) { oe_result_t result = OE_UNEXPECTED; @@ -151,10 +126,10 @@ oe_result_t oe_crl_get_update_dates( PCRL_INFO crl_info = impl->crl->pCrlInfo; if (last) - OE_CHECK(_filetime_to_oe_datetime(&crl_info->ThisUpdate, last)); + OE_CHECK(oe_util_filetime_to_oe_datetime(&crl_info->ThisUpdate, last)); if (next) - OE_CHECK(_filetime_to_oe_datetime(&crl_info->NextUpdate, next)); + OE_CHECK(oe_util_filetime_to_oe_datetime(&crl_info->NextUpdate, next)); result = OE_OK; diff --git a/host/crypto/bcrypt/util.c b/host/crypto/bcrypt/util.c new file mode 100644 index 0000000000..910f375cdf --- /dev/null +++ b/host/crypto/bcrypt/util.c @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#include + +#include "util.h" + +oe_result_t oe_util_filetime_to_oe_datetime( + const FILETIME* filetime, + oe_datetime_t* datetime) +{ + oe_result_t result = OE_UNEXPECTED; + SYSTEMTIME systime = {0}; + if (!FileTimeToSystemTime(filetime, &systime)) + OE_RAISE_MSG( + OE_INVALID_UTC_DATE_TIME, + "FileTimeToSystemTime failed, err=%#x\n", + GetLastError()); + + datetime->year = systime.wYear; + datetime->month = systime.wMonth; + datetime->day = systime.wDay; + datetime->hours = systime.wHour; + datetime->minutes = systime.wMinute; + datetime->seconds = systime.wSecond; + + result = OE_OK; + +done: + return result; +} diff --git a/host/crypto/bcrypt/util.h b/host/crypto/bcrypt/util.h new file mode 100644 index 0000000000..2a4ab51ec3 --- /dev/null +++ b/host/crypto/bcrypt/util.h @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#ifndef _OE_HOST_CRYPTO_UTIL_H +#define _OE_HOST_CRYPTO_UTIL_H + +#include +#include + +#include + +/** + * Convert FILETIME to oe_datetime_t. + * + * @param filetime[in] The FILETIME to convert. + * @param datetime[out] The corresponding oe_datetime_t. + */ +oe_result_t oe_util_filetime_to_oe_datetime( + const FILETIME* filetime, + oe_datetime_t* datetime); + +#endif /* _OE_HOST_CRYPTO_UTIL_H */ \ No newline at end of file diff --git a/host/crypto/openssl/asn1.c b/host/crypto/openssl/asn1.c index babcc2d01f..4a93e72309 100644 --- a/host/crypto/openssl/asn1.c +++ b/host/crypto/openssl/asn1.c @@ -4,6 +4,7 @@ #include "../common/asn1.h" #include #include +#include #include #include #include @@ -11,6 +12,8 @@ #include #include +#include "asn1.h" + OE_STATIC_ASSERT(V_ASN1_CONSTRUCTED == OE_ASN1_TAG_CONSTRUCTED); OE_STATIC_ASSERT(V_ASN1_SEQUENCE == OE_ASN1_TAG_SEQUENCE); OE_STATIC_ASSERT(V_ASN1_INTEGER == OE_ASN1_TAG_INTEGER); @@ -179,3 +182,92 @@ oe_result_t oe_asn1_get_octet_string( done: return result; } + +oe_result_t oe_asn1_string_to_date(const char* str, oe_datetime_t* date) +{ + oe_result_t result = OE_UNEXPECTED; + char month[4]; + + memset(date, 0, sizeof(oe_datetime_t)); + + /* Convert the string to oe_datetime_t struct */ + if (sscanf( + str, + "%3s %02u %02u:%02u:%02u %04u", + month, + &date->day, + &date->hours, + &date->minutes, + &date->seconds, + &date->year) != 6) + { + OE_RAISE(OE_FAILURE); + } + + /* Convert the month string to integer */ + { + static const char* _month[] = {"Jan", + "Feb", + "Mar", + "Apr", + "May", + "Jun", + "Jul", + "Aug", + "Sep", + "Oct", + "Nov", + "Dec"}; + + date->month = UINT_MAX; + + for (uint32_t i = 0; i < OE_COUNTOF(_month); i++) + { + if (strncmp(month, _month[i], 3) == 0) + { + date->month = i + 1; + break; + } + } + + if (date->month == UINT_MAX) + OE_RAISE(OE_FAILURE); + } + + result = OE_OK; + +done: + return result; +} + +oe_result_t oe_asn1_time_to_date(const ASN1_TIME* time, oe_datetime_t* date) +{ + oe_result_t result = OE_UNEXPECTED; + struct tm; + BIO* bio = NULL; + BUF_MEM* mem; + const char null_terminator = '\0'; + + if (!(bio = BIO_new(BIO_s_mem()))) + OE_RAISE(OE_CRYPTO_ERROR); + + if (!ASN1_TIME_print(bio, time)) + OE_RAISE(OE_CRYPTO_ERROR); + + if (!BIO_get_mem_ptr(bio, &mem)) + OE_RAISE(OE_CRYPTO_ERROR); + + if (BIO_write(bio, &null_terminator, sizeof(null_terminator)) <= 0) + OE_RAISE(OE_CRYPTO_ERROR); + + OE_CHECK(oe_asn1_string_to_date(mem->data, date)); + + result = OE_OK; + +done: + + if (bio) + BIO_free(bio); + + return result; +} \ No newline at end of file diff --git a/host/crypto/openssl/asn1.h b/host/crypto/openssl/asn1.h new file mode 100644 index 0000000000..325d0eb01d --- /dev/null +++ b/host/crypto/openssl/asn1.h @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +#ifndef _OE_HOST_CRYPTO_ASN1_OPENSSL_H +#define _OE_HOST_CRYPTO_ASN1_OPENSSL_H + +#include +#include +#include + +/** + * Parse a string into a oe_datetime_t: example: "May 30 10:23:42 2018 GMT". + * This format is specific to OpenSSL: produced by ASN1_TIME_print(). + * + * @param str[in] string to parse into a oe_datetime_t + * @param date[out] output datetime. + */ +oe_result_t oe_asn1_string_to_date(const char* str, oe_datetime_t* date); + +/** + * Convert an ASN1_TIME in openSSL format ta a oe_datetime_t. + * + * @param time[in] The time to convert. + * @param date[out] The output datetime. + */ +oe_result_t oe_asn1_time_to_date(const ASN1_TIME* time, oe_datetime_t* date); + +#endif /* _OE_HOST_CRYPTO_ASN1_OPENSSL_H */ \ No newline at end of file diff --git a/host/crypto/openssl/cert.c b/host/crypto/openssl/cert.c index 97833dca13..274dd329df 100644 --- a/host/crypto/openssl/cert.c +++ b/host/crypto/openssl/cert.c @@ -17,6 +17,7 @@ #include #include #include "../magic.h" +#include "asn1.h" #include "crl.h" #include "ec.h" #include "init.h" @@ -958,3 +959,46 @@ oe_result_t oe_cert_find_extension( done: return result; } + +oe_result_t oe_cert_get_validity_dates( + const oe_cert_t* cert, + oe_datetime_t* not_before, + oe_datetime_t* not_after) +{ + oe_result_t result = OE_UNEXPECTED; + const cert_t* impl = (const cert_t*)cert; + + if (not_before) + memset(not_before, 0, sizeof(oe_datetime_t)); + + if (not_after) + memset(not_after, 0, sizeof(oe_datetime_t)); + + if (!_cert_is_valid(impl)) + OE_RAISE(OE_INVALID_PARAMETER); + + if (not_before) + { + const ASN1_TIME* time; + + if (!(time = X509_get_notBefore(impl->x509))) + OE_RAISE(OE_CRYPTO_ERROR); + + OE_CHECK(oe_asn1_time_to_date(time, not_before)); + } + + if (not_after) + { + const ASN1_TIME* time; + + if (!(time = X509_get_notAfter(impl->x509))) + OE_RAISE(OE_CRYPTO_ERROR); + + OE_CHECK(oe_asn1_time_to_date(time, not_after)); + } + + result = OE_OK; +done: + + return result; +} diff --git a/host/crypto/openssl/crl.c b/host/crypto/openssl/crl.c index d38ad214d7..aa627b33e8 100644 --- a/host/crypto/openssl/crl.c +++ b/host/crypto/openssl/crl.c @@ -14,6 +14,7 @@ #include #include "../magic.h" +#include "asn1.h" #include "crl.h" #if OPENSSL_VERSION_NUMBER < 0x10100000L @@ -118,99 +119,6 @@ oe_result_t oe_crl_free(oe_crl_t* crl) return result; } -// Parse a string into a oe_datetime_t: example: "May 30 10:23:42 2018 GMT". -// This format is specific to OpenSSL: produced by ASN1_TIME_print(). -static oe_result_t _string_to_date(const char* str, oe_datetime_t* date) -{ - oe_result_t result = OE_UNEXPECTED; - char month[4]; - - memset(date, 0, sizeof(oe_datetime_t)); - - /* Convert the string to oe_datetime_t struct */ - if (sscanf( - str, - "%3s %02u %02u:%02u:%02u %04u", - month, - &date->day, - &date->hours, - &date->minutes, - &date->seconds, - &date->year) != 6) - { - OE_RAISE(OE_FAILURE); - } - - /* Convert the month string to integer */ - { - static const char* _month[] = {"Jan", - "Feb", - "Mar", - "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec"}; - - date->month = UINT_MAX; - - for (uint32_t i = 0; i < OE_COUNTOF(_month); i++) - { - if (strncmp(month, _month[i], 3) == 0) - { - date->month = i + 1; - break; - } - } - - if (date->month == UINT_MAX) - OE_RAISE(OE_FAILURE); - } - - result = OE_OK; - -done: - return result; -} - -static oe_result_t _asn1_time_to_date( - const ASN1_TIME* time, - oe_datetime_t* date) -{ - oe_result_t result = OE_UNEXPECTED; - struct tm; - BIO* bio = NULL; - BUF_MEM* mem; - const char null_terminator = '\0'; - - if (!(bio = BIO_new(BIO_s_mem()))) - OE_RAISE(OE_CRYPTO_ERROR); - - if (!ASN1_TIME_print(bio, time)) - OE_RAISE(OE_CRYPTO_ERROR); - - if (!BIO_get_mem_ptr(bio, &mem)) - OE_RAISE(OE_CRYPTO_ERROR); - - if (BIO_write(bio, &null_terminator, sizeof(null_terminator)) <= 0) - OE_RAISE(OE_CRYPTO_ERROR); - - OE_CHECK(_string_to_date(mem->data, date)); - - result = OE_OK; - -done: - - if (bio) - BIO_free(bio); - - return result; -} - oe_result_t oe_crl_get_update_dates( const oe_crl_t* crl, oe_datetime_t* last, @@ -235,7 +143,7 @@ oe_result_t oe_crl_get_update_dates( if (!(time = X509_CRL_get0_lastUpdate(impl->crl))) OE_RAISE(OE_CRYPTO_ERROR); - OE_CHECK(_asn1_time_to_date(time, last)); + OE_CHECK(oe_asn1_time_to_date(time, last)); } if (next) @@ -245,7 +153,7 @@ oe_result_t oe_crl_get_update_dates( if (!(time = X509_CRL_get0_nextUpdate(impl->crl))) OE_RAISE(OE_CRYPTO_ERROR); - OE_CHECK(_asn1_time_to_date(time, next)); + OE_CHECK(oe_asn1_time_to_date(time, next)); } result = OE_OK; diff --git a/host/sgx/hostverify_report.c b/host/sgx/hostverify_report.c index 68b3c65b4e..4448a0733d 100644 --- a/host/sgx/hostverify_report.c +++ b/host/sgx/hostverify_report.c @@ -36,8 +36,8 @@ oe_result_t oe_verify_remote_report( OE_RAISE(OE_UNSUPPORTED); // Quote attestation can be done entirely on the host side. - OE_CHECK(oe_verify_quote_internal( - header->report, header->report_size, NULL, 0, NULL, 0, NULL, 0)); + OE_CHECK(oe_verify_quote_internal_with_collaterals( + header->report, header->report_size, NULL, 0, NULL)); // Optionally return parsed report. if (parsed_report != NULL) @@ -47,4 +47,4 @@ oe_result_t oe_verify_remote_report( done: return result; -} +} \ No newline at end of file diff --git a/host/sgx/report.c b/host/sgx/report.c index 0ac6b07014..1fcb9dedd4 100644 --- a/host/sgx/report.c +++ b/host/sgx/report.c @@ -43,7 +43,7 @@ static oe_result_t _get_local_report( if (report_buffer == NULL || *report_buffer_size < sizeof(sgx_report_t)) { *report_buffer_size = sizeof(sgx_report_t); - OE_RAISE(OE_BUFFER_TOO_SMALL); + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } OE_CHECK(oe_get_sgx_report_ecall( @@ -294,8 +294,8 @@ oe_result_t oe_verify_report( OE_CHECK(oe_initialize_quote_provider()); // Quote attestation can be done entirely on the host side. - OE_CHECK(oe_verify_quote_internal( - header->report, header->report_size, NULL, 0, NULL, 0, NULL, 0)); + OE_CHECK(oe_verify_quote_internal_with_collaterals( + header->report, header->report_size, NULL, 0, NULL)); } else if (header->report_type == OE_REPORT_TYPE_SGX_LOCAL) { @@ -308,7 +308,6 @@ oe_result_t oe_verify_report( OE_CHECK(retval); } - else { OE_RAISE(OE_INVALID_PARAMETER); diff --git a/host/sgx/sgxquoteprovider.c b/host/sgx/sgxquoteprovider.c index 29e7dfa504..12116c12b8 100644 --- a/host/sgx/sgxquoteprovider.c +++ b/host/sgx/sgxquoteprovider.c @@ -232,7 +232,7 @@ oe_result_t oe_get_revocation_info(oe_get_revocation_info_args_t* args) return result; } -void oe_cleanup_get_revocation_info_args(oe_get_revocation_info_args_t* args) +void oe_free_get_revocation_info_args(oe_get_revocation_info_args_t* args) { if (args) { @@ -329,7 +329,7 @@ oe_result_t oe_get_qe_identity_info(oe_get_qe_identity_info_args_t* args) return result; } -void oe_cleanup_qe_identity_info_args(oe_get_qe_identity_info_args_t* args) +void oe_free_qe_identity_info_args(oe_get_qe_identity_info_args_t* args) { if (args) { diff --git a/include/openenclave/bits/result.h b/include/openenclave/bits/result.h index 9116b48714..f931aca9b4 100644 --- a/include/openenclave/bits/result.h +++ b/include/openenclave/bits/result.h @@ -279,6 +279,11 @@ typedef enum _oe_result */ OE_VERIFY_REVOKED, + /** + * Could not find a valid validity period. + */ + OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD, + /** * An underlying crypto provider returned an error. */ diff --git a/include/openenclave/internal/crypto/cert.h b/include/openenclave/internal/crypto/cert.h index 9a432939ca..ee9bf8d8b2 100644 --- a/include/openenclave/internal/crypto/cert.h +++ b/include/openenclave/internal/crypto/cert.h @@ -345,6 +345,20 @@ oe_result_t oe_get_crl_distribution_points( uint8_t* buffer, size_t* buffer_size); +/** + * Gets the validation datetimes from the certificate. + * + * @param cert[in] the certificate. + * @param not_before the date when the certificate validate starts (may be + * null). + * @param not_after the date at which this CRL should be considered invalid + * (may be null). + */ +oe_result_t oe_cert_get_validity_dates( + const oe_cert_t* cert, + oe_datetime_t* not_before, + oe_datetime_t* not_after); + #ifdef OE_BUILD_ENCLAVE typedef struct _oe_cert_config diff --git a/include/openenclave/internal/datetime.h b/include/openenclave/internal/datetime.h index b7dfdb6301..384a0e6113 100644 --- a/include/openenclave/internal/datetime.h +++ b/include/openenclave/internal/datetime.h @@ -52,6 +52,16 @@ int32_t oe_datetime_compare( const oe_datetime_t* date1, const oe_datetime_t* date2); +/** + * Return the current system time in GMT time. + */ +oe_result_t oe_datetime_now(oe_datetime_t* value); + +/** + * Log date at the INFO level. + */ +void oe_datetime_log_info(const char* msg, const oe_datetime_t* date); + OE_EXTERNC_END #endif /* _OE_INTERNAL_DATETIME_H */ diff --git a/include/openenclave/internal/report.h b/include/openenclave/internal/report.h index 4ed83a63fb..00b24c465f 100644 --- a/include/openenclave/internal/report.h +++ b/include/openenclave/internal/report.h @@ -47,6 +47,57 @@ typedef struct _oe_get_qe_identity_info_args uint8_t* host_out_buffer; /* out */ } oe_get_qe_identity_info_args_t; +/* +**============================================================================== +** +** oe_collaterals_header_t +** +**============================================================================== +*/ +typedef struct _oe_collaterals_header +{ + /** Size of the collaterals */ + uint32_t collaterals_size; + + /** Collaterals data **/ + uint8_t collaterals[]; + +} oe_collaterals_header_t; + +OE_STATIC_ASSERT(sizeof(oe_collaterals_header_t) == 4); + +/* +**============================================================================== +** +** oe_collaterals_t +** +** Structure with the collateral contents. The collaterals are used during +** the verification of the oe_report_t. +** +**============================================================================== +*/ +typedef struct _oe_collaterals +{ + oe_get_qe_identity_info_args_t qe_id_info; + oe_get_revocation_info_args_t revocation_info; + + /* Time the collaterals were generated */ + char creation_datetime[24]; + + uint64_t app_collaterals_size; + uint8_t app_collaterals[]; + +} oe_collaterals_t; + +OE_STATIC_ASSERT( + OE_OFFSETOF(oe_collaterals_header_t, collaterals) == + sizeof(oe_collaterals_header_t)); + +#define OE_COLLATERALS_HEADER_SIZE (sizeof(oe_collaterals_header_t)) +#define OE_COLLATERALS_BODY_SIZE (sizeof(oe_collaterals_t)) +#define OE_COLLATERALS_SIZE \ + (OE_COLLATERALS_HEADER_SIZE + OE_COLLATERALS_BODY_SIZE) + /* **============================================================================== ** diff --git a/tests/host_verify/host/host.cpp b/tests/host_verify/host/host.cpp index cd3c7eabb4..d15b2b5e29 100644 --- a/tests/host_verify/host/host.cpp +++ b/tests/host_verify/host/host.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -14,6 +15,9 @@ #include #include +#include "../../../common/sgx/quote.h" +#include "../../../host/sgx/sgxquoteprovider.h" + #if defined(__linux__) #include #elif defined(_WIN32) @@ -32,6 +36,14 @@ #define REPORT_FILENAME "sgx_report.bin" #define REPORT_BAD_FILENAME "sgx_report_bad.bin" +// +// TODO: Report with collaterals tests. Will to refactor the contentns +// of the collaterals to be self-contained in order to support +// serialization. +// +//#define COLLATERALS_FILENAME "sgx_report.bin.col" +//#define COLLATERALS_BAD_FILENAME "sgx_report_bad.bin.col" + #define SKIP_RETURN_CODE 2 oe_result_t enclave_identity_verifier(oe_identity_t* identity, void* arg) @@ -110,54 +122,185 @@ static oe_result_t _verify_cert(const char* filename, bool pass) return oe_ret; } -static int _verify_report(const char* report_filename, bool pass) +/** + * Verify the integrity of the remote report and its signature, + * with optional collateral data. + * + * This function verifies that the report signature is valid. It + * verifies that the signing authority is rooted to a trusted authority + * such as the enclave platform manufacturer. + * + * @param report The buffer containing the report to verify. + * @param report_size The size of the **report** buffer. + * @param collaterals The collateral data that is associated with the report. + * @param collaterals_size The size of the **collaterals** buffer. + * @param parsed_report Optional **oe_report_t** structure to populate + * with the report properties in a standard format. + * + * @retval OE_OK The report was successfully verified. + * @retval OE_INVALID_PARAMETER At least one parameter is invalid. + * + */ +static oe_result_t oe_verify_remote_report_with_collaterals( + const uint8_t* report, + size_t report_size, + const uint8_t* collaterals, + size_t collaterals_size, + oe_report_t* parsed_report) { - FILE* report_fp = NULL; - int ret = -1; - size_t file_size = 0; - uint8_t* data = NULL; - oe_result_t result = OE_FAILURE; + oe_result_t result = OE_UNEXPECTED; + oe_report_t oe_report = {0}; + oe_report_header_t* header = (oe_report_header_t*)report; + + if (report == NULL) + OE_RAISE(OE_INVALID_PARAMETER); + + if (report_size == 0 || report_size > OE_MAX_REPORT_SIZE) + OE_RAISE(OE_INVALID_PARAMETER); - OE_TRACE_INFO("\n\nVerifying report %s\n", report_filename); - report_fp = fopen(report_filename, "rb"); - if (report_fp == NULL) - OE_TRACE_ERROR("Failed to find file: %s\n", report_fp); + // The two host side attestation API's are oe_get_report and + // oe_verify_report. Initialize the quote provider in both these APIs. + OE_CHECK(oe_initialize_quote_provider()); - OE_TEST(report_fp != NULL); + // Ensure that the report is parseable before using the header. + OE_CHECK(oe_parse_report(report, report_size, &oe_report)); + + if (header->report_type != OE_REPORT_TYPE_SGX_REMOTE) + OE_RAISE(OE_UNSUPPORTED); + + // Quote attestation can be done entirely on the host side. + OE_CHECK(oe_verify_quote_internal_with_collaterals( + header->report, + header->report_size, + collaterals, + collaterals_size, + NULL)); + + // Optionally return parsed report. + if (parsed_report != NULL) + OE_CHECK(oe_parse_report(report, report_size, parsed_report)); + + result = OE_OK; + +done: + return result; +} + +static size_t _get_filesize(FILE* fp) +{ + size_t size = 0; + fseek(fp, 0, SEEK_END); + size = (size_t)ftell(fp); + fseek(fp, 0, SEEK_SET); + + return size; +} + +static void _read_binary_file( + const char* filename, + uint8_t** data_ptr, + size_t* size_ptr) +{ + FILE* fp = fopen(filename, "rb"); + size_t size = 0; + uint8_t* data = NULL; + + if (fp == NULL) + OE_TRACE_ERROR("Failed to find file: %s\n", filename); + OE_TEST(fp != NULL); // Find file size - fseek(report_fp, 0, SEEK_END); - file_size = (size_t)ftell(report_fp); - fseek(report_fp, 0, SEEK_SET); + size = _get_filesize(fp); - data = (uint8_t*)malloc((size_t)file_size); + data = (uint8_t*)malloc(size); OE_TEST(data != NULL); - size_t bytes_read = fread(data, sizeof(uint8_t), file_size, report_fp); - OE_TEST(bytes_read == file_size); + size_t bytes_read = fread(data, sizeof(uint8_t), size, fp); + OE_TEST(bytes_read == size); - result = oe_verify_remote_report(data, file_size, NULL); - if (pass) - OE_TEST(result == OE_OK); + if (fp) + fclose(fp); + + *data_ptr = data; + *size_ptr = bytes_read; +} + +static int _verify_report( + const char* report_filename, + const char* collaterals_filename, + bool pass) +{ + int ret = -1; + size_t report_file_size = 0; + size_t collaterals_file_size = 0; + uint8_t* report_data = NULL; + uint8_t* collaterals_data = NULL; + oe_result_t result = OE_FAILURE; + + OE_TRACE_INFO( + "\n\nVerifying report %s, collaterals: %s\n", + report_filename, + collaterals_filename); + + _read_binary_file(report_filename, &report_data, &report_file_size); + + if (collaterals_filename == NULL) + { + result = oe_verify_remote_report(report_data, report_file_size, NULL); + if (pass) + OE_TEST(result == OE_OK); + else + { + // Note: The failure result code is different between linux vs + // windows. + // + OE_TEST(result != OE_OK); + OE_TRACE_INFO( + "Report %s verification failed as expected. Failure %d(%s)\n", + report_filename, + result, + oe_result_str(result)); + } + + OE_TRACE_INFO("Report %s verified successfully!\n\n", report_filename); + } else { - // Note: Failure results are different when running in linux vs windows. - OE_TEST(result != OE_OK); - OE_TRACE_INFO( - "Report %s verification failed as expected. Failure %d(%s)\n", - report_filename, - result, - oe_result_str(result)); + _read_binary_file( + collaterals_filename, &collaterals_data, &collaterals_file_size); + + result = oe_verify_remote_report_with_collaterals( + report_data, + report_file_size, + collaterals_data, + collaterals_file_size, + NULL); + + if (pass) + OE_TEST(result == OE_OK); + else + { + // Note: The failure result code is different between linux vs + // windows. + // + OE_TEST(result != OE_OK); + OE_TRACE_INFO( + "Report %s and collateral %s verification failed as expected. " + "Failure %d(%s)\n", + report_filename, + collaterals_filename, + result, + oe_result_str(result)); + } + + OE_TRACE_INFO("Report %s verified successfully!\n\n", report_filename); } - - OE_TRACE_INFO("Report %s verified successfully!\n\n", report_filename); ret = 0; - if (report_fp != NULL) - fclose(report_fp); - - if (data != NULL) - free(data); + if (report_data != NULL) + free(report_data); + if (collaterals_data != NULL) + free(collaterals_data); return ret; } @@ -172,6 +315,10 @@ int main() return SKIP_RETURN_CODE; } + // + // Report only tests + // + // These files are generated by oecert and do not always exists. // Run these tests if the file exists. The Jenkins CI/CD system // is responsible for running oecert to generate these files. @@ -183,7 +330,7 @@ int main() _verify_cert(CERT_RSA_FILENAME, true); if (_validate_file(REPORT_FILENAME, false)) - _verify_report(REPORT_FILENAME, true); + _verify_report(REPORT_FILENAME, NULL, true); // These files are checked in and should always exist. if (_validate_file(CERT_EC_BAD_FILENAME, true)) @@ -193,7 +340,18 @@ int main() _verify_cert(CERT_RSA_BAD_FILENAME, false); if (_validate_file(REPORT_BAD_FILENAME, true)) - _verify_report(REPORT_BAD_FILENAME, false); + _verify_report(REPORT_BAD_FILENAME, NULL, false); + + // + // TODO: Report with collaterals tests. Will to refactor the contentns + // of the collaterals to be self-contained in order to support + // serialization. + // + // if (_validate_file(REPORT_FILENAME, false)) + // _verify_report(REPORT_FILENAME, COLLATERALS_FILENAME, true); + + // if (_validate_file(REPORT_BAD_FILENAME, true)) + // _verify_report(REPORT_FILENAME, COLLATERALS_BAD_FILENAME, false); return 0; } diff --git a/tests/report/common/tests.cpp b/tests/report/common/tests.cpp index cd2517e19a..c6bcf8f5c8 100644 --- a/tests/report/common/tests.cpp +++ b/tests/report/common/tests.cpp @@ -2,15 +2,292 @@ // Licensed under the MIT License. #include "../common/tests.h" +#include +#include +#include #include +#ifndef OE_BUILD_ENCLAVE +#include "../../../host/sgx/sgxquoteprovider.h" +#endif +#include "../../../common/oe_host_stdlib.h" +#include "../../../common/sgx/collaterals.h" +#include "../../../common/sgx/qeidentity.h" +#include "../../../common/sgx/quote.h" +#include "../../../common/sgx/revocation.h" + +#include + +/** + * Get collateral data which can be used with future function + * oe_verify_report_with_collaterals(). + * + * @param collaterals_buffer The buffer containing the collaterals to parse. + * @param collaterals_buffer_size The size of the **collaterals_buffer**. + * + * @retval OE_OK The collaterals were successfully retrieved. + */ +oe_result_t oe_get_collaterals( +#ifndef OE_BUILD_ENCLAVE + oe_enclave_t* enclave, +#endif + uint8_t** collaterals_buffer, + size_t* collaterals_buffer_size) +{ + oe_result_t result = OE_UNEXPECTED; + size_t report_size = OE_MAX_REPORT_SIZE; + uint8_t* remote_report = NULL; + oe_report_t* parsed_report = NULL; + oe_report_header_t* header = NULL; + + OE_TRACE_INFO("Enter enclave call %s\n", __FUNCTION__); + + if ((collaterals_buffer == NULL) || (collaterals_buffer_size == NULL)) + { + OE_RAISE(OE_INVALID_PARAMETER); + } + + *collaterals_buffer = NULL; + *collaterals_buffer_size = 0; + +#ifdef OE_BUILD_ENCLAVE + // Get a remote OE report. + // We need a report in order to fetch the uris of the certificates in the + // sgx quote. + OE_CHECK_MSG( + oe_get_report( + OE_REPORT_FLAGS_REMOTE_ATTESTATION, + NULL, + 0, + NULL, + 0, + (uint8_t**)&remote_report, + &report_size), + "Failed to get OE remote report. %s", + oe_result_str(result)); + header = (oe_report_header_t*)remote_report; + + OE_CHECK_MSG( + oe_verify_report(remote_report, report_size, parsed_report), + "Failed to verify OE remote report. %s", + oe_result_str(result)); +#else + OE_CHECK_MSG( + oe_initialize_quote_provider(), + "Failed to initialize quote provider. %s", + oe_result_str(result)); + + OE_CHECK_MSG( + oe_get_report( + enclave, + OE_REPORT_FLAGS_REMOTE_ATTESTATION, + NULL, + 0, + (uint8_t**)&remote_report, + &report_size), + "Failed to get OE remote report. %s", + oe_result_str(result)); + header = (oe_report_header_t*)remote_report; + + OE_CHECK_MSG( + oe_verify_report(enclave, remote_report, report_size, parsed_report), + "Failed to verify OE remote report. %s", + oe_result_str(result)); +#endif + + OE_CHECK_MSG( + oe_get_collaterals_internal( + header->report, + header->report_size, + collaterals_buffer, + collaterals_buffer_size), + "Failed to get collaterals. %s", + oe_result_str(result)); + + result = OE_OK; +done: + if (remote_report) + oe_free_report(remote_report); + + OE_TRACE_INFO( + "Exit enclave call %s: %d(%s)\n", + __FUNCTION__, + result, + oe_result_str(result)); + + return result; +} + +/** + * Verify the integrity of the report and its signature, + * with optional collateral data that is associated with the report. + * + * This function verifies that the report signature is valid. If the report is + * local, it verifies that it is correctly signed by the enclave + * platform. If the report is remote, it verifies that the signing authority is + * rooted to a trusted authority such as the enclave platform manufacturer. + * + * @param enclave The instance of the enclave that will be used to + * verify a local report. For remote reports, this parameter can be NULL. + * @param report The buffer containing the report to verify. + * @param report_size The size of the **report** buffer. + * @param collaterals The collateral data that is associated with the report. + * @param collaterals_size The size of the **collaterals** buffer. + * @param parsed_report Optional **oe_report_t** structure to populate with the + * report properties in a standard format. + * + * @retval OE_OK The report was successfully created. + * @retval OE_INVALID_PARAMETER At least one parameter is invalid. + * + */ +static oe_result_t oe_verify_report_with_collaterals( +#ifndef OE_BUILD_ENCLAVE + oe_enclave_t* enclave, +#endif + const uint8_t* report, + size_t report_size, + const uint8_t* collaterals, + size_t collaterals_size, + oe_datetime_t* input_validation_time, + oe_report_t* parsed_report) +{ + oe_result_t result = OE_UNEXPECTED; + oe_report_t oe_report = {0}; + oe_report_header_t* header = (oe_report_header_t*)report; + + if (report == NULL) + OE_RAISE(OE_INVALID_PARAMETER); + + if (report_size == 0 || report_size > OE_MAX_REPORT_SIZE) + OE_RAISE(OE_INVALID_PARAMETER); + + // Ensure that the report is parseable before using the header. + OE_CHECK(oe_parse_report(report, report_size, &oe_report)); + + if (header->report_type == OE_REPORT_TYPE_SGX_REMOTE) + { +#ifndef OE_BUILD_ENCLAVE + // Intialize the quote provider if we want to verify a remote quote. + // Note that we don't have the OE_USE_LIBSGX guard here since we don't + // need the sgx libraries to verify the quote. All we need is the quote + // provider. + OE_CHECK(oe_initialize_quote_provider()); +#endif + + // Quote attestation can be done entirely on the host side. + OE_CHECK(oe_verify_quote_internal_with_collaterals( + header->report, + header->report_size, + collaterals, + collaterals_size, + input_validation_time)); + + // Optionally return parsed report. + if (parsed_report != NULL) + OE_CHECK(oe_parse_report(report, report_size, parsed_report)); + } + else if (header->report_type == OE_REPORT_TYPE_SGX_LOCAL) + { + if (collaterals != NULL || collaterals_size > 0) + { + OE_RAISE_MSG( + OE_UNSUPPORTED, + "Local reports should not have collaterals.", + NULL); + } + +#ifndef OE_BUILD_ENCLAVE + if (enclave == NULL) + OE_RAISE(OE_INVALID_PARAMETER); + + OE_CHECK(oe_verify_report(enclave, report, report_size, parsed_report)); +#else + OE_CHECK(oe_verify_report(report, report_size, parsed_report)); +#endif + } + else + { + OE_RAISE(OE_INVALID_PARAMETER); + } + + result = OE_OK; +done: + return result; +} + +/** + * Free up any resources allocated by oe_get_collateras() + * + * @param collaterals_buffer The buffer containing the collaterals. + */ +static void oe_free_collaterals(uint8_t* collaterals_buffer) +{ + oe_free_collaterals_internal(collaterals_buffer); +} + +static oe_result_t oe_get_quote_validity_with_collaterals( + const uint8_t* report, + const size_t report_size, + const uint8_t* collaterals, + size_t collaterals_size, + oe_datetime_t* valid_from, + oe_datetime_t* valid_until) +{ + oe_result_t result = OE_UNEXPECTED; + oe_report_t oe_report = {0}; + oe_report_header_t* header = (oe_report_header_t*)report; + + if (report == NULL || collaterals == NULL || valid_from == NULL || + valid_until == NULL) + OE_RAISE(OE_INVALID_PARAMETER); + + if (report_size == 0 || report_size > OE_MAX_REPORT_SIZE || + collaterals_size == 0) + OE_RAISE(OE_INVALID_PARAMETER); + + // Ensure that the report is parseable before using the header. + OE_CHECK(oe_parse_report(report, report_size, &oe_report)); + + if (header->report_type == OE_REPORT_TYPE_SGX_REMOTE) + { +#ifndef OE_BUILD_ENCLAVE + // Intialize the quote provider if we want to verify a remote quote. + // Note that we don't have the OE_USE_LIBSGX guard here since we don't + // need the sgx libraries to verify the quote. All we need is the quote + // provider. + OE_CHECK(oe_initialize_quote_provider()); +#endif + + // Quote attestation can be done entirely on the host side. + OE_CHECK(oe_get_quote_validity_with_collaterals_internal( + header->report, + header->report_size, + collaterals, + collaterals_size, + valid_from, + valid_until)); + } + else + { + OE_RAISE(OE_INVALID_PARAMETER); + } + + result = OE_OK; +done: + return result; +} + #ifdef OE_BUILD_ENCLAVE #include #define GetReport oe_get_report #define GetReport_v2 oe_get_report_v2 +#define GetCollaterals oe_get_collaterals + #define VerifyReport oe_verify_report +#define VerifyReportWithCollaterals oe_verify_report_with_collaterals +#define GetQuoteValidityWithCollaterals oe_get_quote_validity_with_collaterals #else @@ -24,6 +301,10 @@ oe_enclave_t* g_enclave = NULL; #define GetReport_v2(flags, rd, rds, op, ops, rb, rbs) \ oe_get_report_v2(g_enclave, flags, op, ops, rb, rbs) +// Get collateral macros. Host side API has an additional enclave object. +#define GetCollaterals(data, data_size) \ + oe_get_collaterals(g_enclave, data, data_size) + oe_result_t VerifyReport( const uint8_t* report, size_t report_size, @@ -43,6 +324,61 @@ oe_result_t VerifyReport( return oe_verify_report(g_enclave, report, report_size, parsed_report); } +oe_result_t VerifyReportWithCollaterals( + const uint8_t* report, + size_t report_size, + const uint8_t* collaterals, + size_t collaterals_size, + oe_datetime_t* input_validation_time, + oe_report_t* parsed_report) +{ + oe_report_t tmp_report = {0}; + OE_TEST(oe_parse_report(report, report_size, &tmp_report) == OE_OK); + + if (tmp_report.identity.attributes & OE_REPORT_ATTRIBUTES_REMOTE) + { + return oe_verify_report_with_collaterals( + g_enclave, + report, + report_size, + collaterals, + collaterals_size, + input_validation_time, + parsed_report); + } + else + { + return OE_UNSUPPORTED; + } +} + +oe_result_t GetQuoteValidityWithCollaterals( + const uint8_t* report, + size_t report_size, + const uint8_t* collaterals, + size_t collaterals_size, + oe_datetime_t* valid_from, + oe_datetime_t* valid_until) +{ + oe_report_t tmp_report = {0}; + OE_TEST(oe_parse_report(report, report_size, &tmp_report) == OE_OK); + + if (tmp_report.identity.attributes & OE_REPORT_ATTRIBUTES_REMOTE) + { + return oe_get_quote_validity_with_collaterals( + report, + report_size, + collaterals, + collaterals_size, + valid_from, + valid_until); + } + else + { + return OE_UNSUPPORTED; + } +} + #endif #define OE_LOCAL_REPORT_SIZE (sizeof(oe_report_header_t) + sizeof(sgx_report_t)) @@ -887,3 +1223,131 @@ void test_remote_verify_report() #endif } } + +void test_verify_report_with_collaterals() +{ + uint32_t flags = OE_REPORT_FLAGS_REMOTE_ATTESTATION; + + size_t report_ptr_size; + uint8_t* report_buffer_ptr; + + size_t collaterals_ptr_size = 0; + uint8_t* collaterals_buffer_ptr = NULL; + + /* Test 1: Verify report with collaterals */ + OE_TEST( + GetReport_v2( + flags, NULL, 0, NULL, 0, &report_buffer_ptr, &report_ptr_size) == + OE_OK); + + /* Verify report without collaterals */ + OE_TEST( + VerifyReportWithCollaterals( + report_buffer_ptr, report_ptr_size, NULL, 0, NULL, NULL) == OE_OK); + + if (GetCollaterals(&collaterals_buffer_ptr, &collaterals_ptr_size) == OE_OK) + { + OE_TEST( + VerifyReportWithCollaterals( + report_buffer_ptr, + report_ptr_size, + collaterals_buffer_ptr, + collaterals_ptr_size, + NULL, // Validate using current time + NULL) == OE_OK); + + /* Test with time in the past */ + time_t t; + struct tm* timeinfo; + time(&t); + timeinfo = gmtime(&t); + + // convert tm to oe_datetime_t + oe_datetime_t past = {(uint32_t)timeinfo->tm_year + 1890, + (uint32_t)timeinfo->tm_mon + 1, + (uint32_t)timeinfo->tm_mday, + (uint32_t)timeinfo->tm_hour, + (uint32_t)timeinfo->tm_min, + (uint32_t)timeinfo->tm_sec}; + OE_TEST( + VerifyReportWithCollaterals( + report_buffer_ptr, + report_ptr_size, + collaterals_buffer_ptr, + collaterals_ptr_size, + &past, + NULL) == OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD); + + /* Test with time in the future */ + oe_datetime_t future = {(uint32_t)timeinfo->tm_year + 1910, + (uint32_t)timeinfo->tm_mon + 1, + (uint32_t)timeinfo->tm_mday, + (uint32_t)timeinfo->tm_hour, + (uint32_t)timeinfo->tm_min, + (uint32_t)timeinfo->tm_sec}; + OE_TEST( + VerifyReportWithCollaterals( + report_buffer_ptr, + report_ptr_size, + collaterals_buffer_ptr, + collaterals_ptr_size, + &future, + NULL) == OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD); + + /* Get validity range and use it to validate edge cases.*/ + oe_datetime_t valid_from = {0}; + oe_datetime_t valid_until = {0}; + OE_TEST( + GetQuoteValidityWithCollaterals( + report_buffer_ptr, + report_ptr_size, + collaterals_buffer_ptr, + collaterals_ptr_size, + &valid_from, + &valid_until) == OE_OK); + /* At latest valid from date */ + OE_TEST( + VerifyReportWithCollaterals( + report_buffer_ptr, + report_ptr_size, + collaterals_buffer_ptr, + collaterals_ptr_size, + &valid_from, + NULL) == OE_OK); + /* At earliest expiration date */ + OE_TEST( + VerifyReportWithCollaterals( + report_buffer_ptr, + report_ptr_size, + collaterals_buffer_ptr, + collaterals_ptr_size, + &valid_until, + NULL) == OE_OK); + + valid_from.seconds -= 1; + OE_TEST( + VerifyReportWithCollaterals( + report_buffer_ptr, + report_ptr_size, + collaterals_buffer_ptr, + collaterals_ptr_size, + &valid_from, + NULL) == OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD); + + valid_until.seconds += 1; + OE_TEST( + VerifyReportWithCollaterals( + report_buffer_ptr, + report_ptr_size, + collaterals_buffer_ptr, + collaterals_ptr_size, + &valid_until, + NULL) == OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD); + } + + oe_free_collaterals(collaterals_buffer_ptr); + oe_free_report(report_buffer_ptr); + + collaterals_buffer_ptr = NULL; + report_buffer_ptr = NULL; +} \ No newline at end of file diff --git a/tests/report/common/tests.h b/tests/report/common/tests.h index c8a4911bd4..4c1544fc18 100644 --- a/tests/report/common/tests.h +++ b/tests/report/common/tests.h @@ -25,5 +25,6 @@ void test_remote_report(); void test_parse_report_negative(); void test_local_verify_report(); void test_remote_verify_report(); +void test_verify_report_with_collaterals(); #endif diff --git a/tests/report/enc/enc.cpp b/tests/report/enc/enc.cpp index 3e71365de1..34581752b1 100644 --- a/tests/report/enc/enc.cpp +++ b/tests/report/enc/enc.cpp @@ -94,6 +94,10 @@ void test_minimum_issue_date(oe_datetime_t now) oe_verify_report(report_v2, report_v2_size, NULL) == OE_INVALID_REVOCATION_INFO); + // Restore default minimum CRL/TCB issue date + OE_TEST( + __oe_sgx_set_minimum_crl_tcb_issue_date(2017, 3, 17, 0, 0, 0) == OE_OK); + oe_free_report(report); oe_free_report(report_v2); @@ -128,6 +132,11 @@ void enclave_test_remote_verify_report() test_remote_verify_report(); } +void enclave_test_verify_report_with_collaterals() +{ + test_verify_report_with_collaterals(); +} + OE_SET_ENCLAVE_SGX( 0, /* ProductID */ 0, /* SecurityVersion */ diff --git a/tests/report/host/host.cpp b/tests/report/host/host.cpp index 5c17b0a9f6..538cb8e176 100644 --- a/tests/report/host/host.cpp +++ b/tests/report/host/host.cpp @@ -161,6 +161,8 @@ int main(int argc, const char* argv[]) test_remote_verify_report(); + test_verify_report_with_collaterals(); + OE_TEST(test_iso8601_time(enclave) == OE_OK); OE_TEST(test_iso8601_time_negative(enclave) == OE_OK); @@ -176,6 +178,8 @@ int main(int argc, const char* argv[]) OE_TEST(enclave_test_remote_verify_report(enclave) == OE_OK); + OE_TEST(enclave_test_verify_report_with_collaterals(enclave) == OE_OK); + TestVerifyTCBInfo(enclave, "./data/tcbInfo.json"); TestVerifyTCBInfo(enclave, "./data/tcbInfo_with_pceid.json"); diff --git a/tests/report/tests.edl b/tests/report/tests.edl index e5e791e117..590035bf51 100644 --- a/tests/report/tests.edl +++ b/tests/report/tests.edl @@ -24,6 +24,7 @@ enclave { public void enclave_test_parse_report_negative(); public void enclave_test_local_verify_report(); public void enclave_test_remote_verify_report(); + public void enclave_test_verify_report_with_collaterals(); }; untrusted { diff --git a/tests/tools/oecert/host/host.cpp b/tests/tools/oecert/host/host.cpp index 0dd6424a0b..a76a1a0cf5 100644 --- a/tests/tools/oecert/host/host.cpp +++ b/tests/tools/oecert/host/host.cpp @@ -3,17 +3,21 @@ #include #include +#include #include #include #include #include #include "oecert_u.h" +#include "../../../../common/sgx/collaterals.h" + #ifdef OE_USE_LIBSGX #define INPUT_PARAM_OPTION_CERT "--cert" #define INPUT_PARAM_OPTION_REPORT "--report" #define INPUT_PARAM_OPTION_OUT_FILE "--out" +#define INPUT_PARAM_OPTION_COLLATERALS "--collaterals" // Structure to store input parameters // @@ -25,6 +29,7 @@ typedef struct _input_params const char* out_filename; bool gen_cert; bool gen_report; + bool gen_collaterals; } input_params_t; static input_params_t _params; @@ -189,6 +194,55 @@ static oe_result_t _gen_report( // TODO: Dump report. } } + + // Check if collaterals need to be generated + if (_params.gen_collaterals) + { + char collateral_filename[1024 + 1]; + + if (strlen(report_filename) < (1024 - 4)) + { + uint8_t* collaterals = NULL; + size_t collaterals_size = 0; + oe_report_header_t* header = (oe_report_header_t*)remote_report; + + sprintf(collateral_filename, "%s.col", report_filename); + printf( + "Generatting collateral file: %s\n", collateral_filename); + + result = oe_get_collaterals_internal( + header->report, + header->report_size, + &collaterals, + &collaterals_size); + if (result != OE_OK) + { + printf("ERROR: Failed to get collaterals\n"); + goto exit; + } + + // TODO: Current collateral structure is not self contained. + // Needs to be updated to be serialisable. + // + FILE* col_fp = fopen(collateral_filename, "wb"); + if (!col_fp) + { + printf( + "Failed to open collateral file %s\n", + collateral_filename); + result = OE_FAILURE; + goto exit; + } + fwrite(collaterals, collaterals_size, 1, col_fp); + fclose(col_fp); + printf("collaterals_size = %zu\n", collaterals_size); + } + else + { + printf("ERROR: Report filename is too long.\n"); + exit(1); + } + } } else { @@ -211,6 +265,10 @@ static void _display_help(const char* cmd) INPUT_PARAM_OPTION_CERT); printf( "\t%s : generate binary enclave report.\n", INPUT_PARAM_OPTION_REPORT); + printf( + "\t%s : generate binary collaterals. Valid only if %s is specified.\n", + INPUT_PARAM_OPTION_COLLATERALS, + INPUT_PARAM_OPTION_REPORT); printf("\t%s : output filename.\n", INPUT_PARAM_OPTION_OUT_FILE); // TODO: Add option to display certs @@ -271,7 +329,6 @@ static int _parse_args(int argc, const char* argv[]) if (argc >= i) { _params.gen_report = true; - i += 1; } else @@ -283,12 +340,16 @@ static int _parse_args(int argc, const char* argv[]) return 1; } } + else if (strcmp(INPUT_PARAM_OPTION_COLLATERALS, argv[i]) == 0) + { + _params.gen_collaterals = true; + i += 1; + } else if (strcmp(INPUT_PARAM_OPTION_OUT_FILE, argv[i]) == 0) { if (argc >= i + 1) { _params.out_filename = argv[i + 1]; - i += 2; } else From 12136b0e9a97a9f6aa730dcaa53745ef14ce1e4f Mon Sep 17 00:00:00 2001 From: Jay Chetty Date: Wed, 25 Sep 2019 09:16:59 -0700 Subject: [PATCH 028/420] Fixed issue with decrypting the encryption key with the password key The current code was using the previous encryption key generated from previous encrypt operation which was cached in the global dispatcher object. The decrypt operation didn't alter the encryption key due to couple of reasons. --- samples/file-encryptor/enclave/encryptor.cpp | 1 + samples/file-encryptor/enclave/keys.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/samples/file-encryptor/enclave/encryptor.cpp b/samples/file-encryptor/enclave/encryptor.cpp index 2eaa4e874d..2067005f8a 100644 --- a/samples/file-encryptor/enclave/encryptor.cpp +++ b/samples/file-encryptor/enclave/encryptor.cpp @@ -38,6 +38,7 @@ int ecall_dispatcher::initialize( encrypt ? "encrypting" : "decrypting"); m_encrypt = encrypt; + memset((void*)m_encryption_key, 0, ENCRYPTION_KEY_SIZE_IN_BYTES); ret = process_encryption_header(encrypt, password, password_len, header); if (ret != 0) diff --git a/samples/file-encryptor/enclave/keys.cpp b/samples/file-encryptor/enclave/keys.cpp index 250e71b8fe..b930c8f877 100644 --- a/samples/file-encryptor/enclave/keys.cpp +++ b/samples/file-encryptor/enclave/keys.cpp @@ -226,7 +226,12 @@ int ecall_dispatcher::cipher_encryption_key( mbedtls_aes_init(&aescontext); // set aes key - ret = mbedtls_aes_setkey_enc(&aescontext, encrypt_key, ENCRYPTION_KEY_SIZE); + if (encrypt){ + ret = mbedtls_aes_setkey_enc(&aescontext, encrypt_key, ENCRYPTION_KEY_SIZE); + } + else { + ret = mbedtls_aes_setkey_dec(&aescontext, encrypt_key, ENCRYPTION_KEY_SIZE); + } if (ret != 0) { TRACE_ENCLAVE("mbedtls_aes_setkey_enc failed with %d", ret); @@ -371,8 +376,8 @@ int ecall_dispatcher::parse_encryption_header( DECRYPT_OPERATION, header->encrypted_key, ENCRYPTION_KEY_SIZE_IN_BYTES, - (unsigned char*)m_encryption_key, password_key, + (unsigned char*)m_encryption_key, ENCRYPTION_KEY_SIZE_IN_BYTES); if (ret != 0) { From 4858e03787b9701b3e4d8f955d4d4711fdf2f569 Mon Sep 17 00:00:00 2001 From: Sergio Wong Date: Wed, 25 Sep 2019 17:11:23 +0000 Subject: [PATCH 029/420] Code review changes. --- common/datetime.c | 6 ++--- common/sgx/collaterals.c | 12 ++++----- common/sgx/qeidentity.c | 34 +++++++++++++++++-------- common/sgx/qeidentity.h | 2 +- common/sgx/quote.c | 16 ++++++------ common/sgx/revocation.c | 29 ++++++++++----------- enclave/crypto/cert.c | 10 +++----- host/crypto/bcrypt/cert.c | 12 ++++----- host/crypto/bcrypt/util.h | 2 +- host/crypto/openssl/asn1.c | 2 +- host/crypto/openssl/asn1.h | 2 +- host/crypto/openssl/cert.c | 10 +++----- include/openenclave/internal/datetime.h | 4 +-- tests/host_verify/host/host.cpp | 19 -------------- tests/report/common/tests.cpp | 2 +- 15 files changed, 74 insertions(+), 88 deletions(-) diff --git a/common/datetime.c b/common/datetime.c index e7c1fcf8d5..fdb8e5bdae 100644 --- a/common/datetime.c +++ b/common/datetime.c @@ -249,13 +249,13 @@ oe_result_t oe_datetime_now(oe_datetime_t* value) return result; } -void oe_datetime_log_info(const char* msg, const oe_datetime_t* date) +void oe_datetime_log(const char* msg, const oe_datetime_t* date) { - if (oe_get_current_logging_level() >= OE_LOG_LEVEL_INFO) + if (oe_get_current_logging_level() >= OE_LOG_LEVEL_VERBOSE) { char str[OE_DATETIME_STR_SIZE]; size_t size = sizeof(str); oe_datetime_to_string(date, str, &size); - OE_TRACE_INFO("%s %s\n", msg, str); + OE_TRACE_VERBOSE("%s %s\n", msg, str); } } diff --git a/common/sgx/collaterals.c b/common/sgx/collaterals.c index c3adce1f7c..759ff0691b 100644 --- a/common/sgx/collaterals.c +++ b/common/sgx/collaterals.c @@ -107,18 +107,16 @@ oe_result_t oe_get_collaterals_internal( oe_result_str(result)); } + *collaterals_buffer = buffer; + *collaterals_buffer_size = OE_COLLATERALS_SIZE; result = OE_OK; + done: oe_cert_free(&leaf_cert); oe_cert_free(&intermediate_cert); oe_cert_chain_free(&pck_cert_chain); - if (result == OE_OK) - { - *collaterals_buffer = buffer; - *collaterals_buffer_size = OE_COLLATERALS_SIZE; - } - else if (buffer) + if ((result != OE_OK) && buffer) { oe_free_get_revocation_info_args(&(collaterals->revocation_info)); oe_free_qe_identity_info_args(&(collaterals->qe_id_info)); @@ -133,7 +131,7 @@ oe_result_t oe_get_collaterals_internal( } /** - * Free up any resources allocated by oe_get_collateras() + * Free up any resources allocated by oe_get_collaterals() * * @param collaterals_buffer The buffer containing the collaterals. */ diff --git a/common/sgx/qeidentity.c b/common/sgx/qeidentity.c index bb96c9bf4c..99a9cbf28a 100644 --- a/common/sgx/qeidentity.c +++ b/common/sgx/qeidentity.c @@ -106,7 +106,8 @@ oe_result_t oe_validate_qe_identity( OE_TRACE_INFO("Calling %s\n", __FUNCTION__); - if (qe_id_args == NULL) + if ((qe_id_args == NULL) || (validity_from == NULL) || + (validity_until == NULL)) OE_RAISE(OE_INVALID_PARAMETER); // Use QE Identity info to validate QE @@ -136,22 +137,33 @@ oe_result_t oe_validate_qe_identity( // Get leaf certificate OE_CHECK_MSG( oe_cert_chain_get_leaf_cert(&pck_cert_chain, &leaf_cert), - "Failed to get leaf certificate.", - NULL); - oe_cert_get_validity_dates(&leaf_cert, &from, &until); + "Failed to get leaf certificate. %s", + oe_result_str(result)); + OE_CHECK_MSG( + oe_cert_get_validity_dates(&leaf_cert, &from, &until), + "Failed to get validity dates from cert. %s", + oe_result_str(result)); - oe_datetime_log_info("QE identity cert issue date: ", &from); - oe_datetime_log_info("QE identity cert next update: ", &until); + oe_datetime_log("QE identity cert issue date: ", &from); + oe_datetime_log("QE identity cert next update: ", &until); // Check that issue_date and next_update are after the earliest date that // the enclave accepts. if (oe_datetime_compare( &parsed_info.issue_date, &_sgx_minimim_crl_tcb_issue_date) < 0) - OE_RAISE(OE_INVALID_QE_IDENTITY_INFO); + OE_RAISE_MSG( + OE_INVALID_QE_IDENTITY_INFO, + "QE identity info issue date does not meet CRL/TCB minimum issue " + "date.", + NULL); if (oe_datetime_compare( &parsed_info.next_update, &_sgx_minimim_crl_tcb_issue_date) < 0) - OE_RAISE(OE_INVALID_QE_IDENTITY_INFO); + OE_RAISE_MSG( + OE_INVALID_QE_IDENTITY_INFO, + "QE identity info next update does not meet CRL/TCB minimum issue " + "date.", + NULL); // Assert that the qe report's MRSIGNER matches Intel's quoting enclave's // mrsigner. @@ -229,8 +241,10 @@ oe_result_t oe_validate_qe_identity( if (oe_datetime_compare(&parsed_info.next_update, &until) < 0) until = parsed_info.next_update; - oe_datetime_log_info("QE identity overall issue date: ", &from); - oe_datetime_log_info("QE identity overall next update: ", &until); + oe_datetime_log("QE identity issue date: ", &parsed_info.issue_date); + oe_datetime_log("QE identity next update date: ", &parsed_info.next_update); + oe_datetime_log("QE identity overall issue date: ", &from); + oe_datetime_log("QE identity overall next update: ", &until); if (oe_datetime_compare(&from, &until) > 0) OE_RAISE_MSG( OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD, diff --git a/common/sgx/qeidentity.h b/common/sgx/qeidentity.h index 1327da2b3a..96c62a8472 100644 --- a/common/sgx/qeidentity.h +++ b/common/sgx/qeidentity.h @@ -14,7 +14,7 @@ OE_EXTERNC_BEGIN /** * This is needed to be backwards compatible - * with the older quote provider. + * with providers that do not support QE identity. * * @param[in] qe_report_body The QE report body from the quote. */ diff --git a/common/sgx/quote.c b/common/sgx/quote.c index cf6d95e313..01b735f04d 100644 --- a/common/sgx/quote.c +++ b/common/sgx/quote.c @@ -514,15 +514,16 @@ oe_result_t oe_verify_quote_internal_with_collaterals( collaterals_body->creation_datetime, sizeof(collaterals_body->creation_datetime), &creation_time), - "Invalid creation time in collaterals.", - NULL); + "Invalid creation time in collaterals: %s", + collaterals_body->creation_datetime); + validation_time = &creation_time; } - oe_datetime_log_info("Validation datetime: ", validation_time); + oe_datetime_log("Validation datetime: ", validation_time); if (oe_datetime_compare(validation_time, &validity_from) < 0) { - oe_datetime_log_info("Latests valid datetime: ", &validity_from); + oe_datetime_log("Latests valid datetime: ", &validity_from); OE_RAISE_MSG( OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD, "Time to validate quote is earlier than the " @@ -531,8 +532,7 @@ oe_result_t oe_verify_quote_internal_with_collaterals( } if (oe_datetime_compare(validation_time, &validity_until) > 0) { - oe_datetime_log_info( - "Earliest expiration datetime: ", &validity_until); + oe_datetime_log("Earliest expiration datetime: ", &validity_until); OE_RAISE_MSG( OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD, "Time to validate quoteis later than the " @@ -663,8 +663,8 @@ oe_result_t oe_get_quote_validity_with_collaterals_internal( oe_result_str(result)); _update_validity(&latest_from, &earliest_until, &from, &until); - oe_datetime_log_info("Quote overall issue date: ", &latest_from); - oe_datetime_log_info("Quote overall next update: ", &earliest_until); + oe_datetime_log("Quote overall issue date: ", &latest_from); + oe_datetime_log("Quote overall next update: ", &earliest_until); if (oe_datetime_compare(&latest_from, &earliest_until) > 0) OE_RAISE_MSG( OE_VERIFY_FAILED_TO_FIND_VALIDITY_PERIOD, diff --git a/common/sgx/revocation.c b/common/sgx/revocation.c index 9e968b8d3b..3bd08d9608 100644 --- a/common/sgx/revocation.c +++ b/common/sgx/revocation.c @@ -112,24 +112,23 @@ static oe_result_t _get_revocation_validity( _get_tcb_info_validity(parsed_tcb_info, &latest_from, &earliest_until), "Failed to get TCB info validity datetime info. %s", oe_result_str(result)); - oe_datetime_log_info("TCB info validity from date: ", &latest_from); - oe_datetime_log_info("TCB info validity until date: ", &earliest_until); + oe_datetime_log("TCB info validity from date: ", &latest_from); + oe_datetime_log("TCB info validity until date: ", &earliest_until); OE_CHECK_MSG( _get_crl_validity(crls, crls_count, ¤t_from, ¤t_until), "Failed to get CRL validity datetime info. %s", oe_result_str(result)); - oe_datetime_log_info("CRL validity from date: ", ¤t_from); - oe_datetime_log_info("CRL validity until date: ", ¤t_until); + oe_datetime_log("CRL validity from date: ", ¤t_from); + oe_datetime_log("CRL validity until date: ", ¤t_until); // Currently we are ignoring TCB Info validity dates because // the data is expired. See Icm 148493545 latest_from = current_from; earliest_until = current_until; - oe_datetime_log_info( - "Revocation overall validity from date: ", &latest_from); - oe_datetime_log_info( + oe_datetime_log("Revocation overall validity from date: ", &latest_from); + oe_datetime_log( "Revocation overall validity until date: ", &earliest_until); *from = latest_from; @@ -434,8 +433,8 @@ oe_result_t oe_validate_revocation_list( if (oe_datetime_compare(&latest_from, &_sgx_minimim_crl_tcb_issue_date) < 0) { - oe_datetime_log_info("Latest issue date : ", &latest_from); - oe_datetime_log_info( + oe_datetime_log("Latest issue date : ", &latest_from); + oe_datetime_log( " is earlier than minimum issue date: ", &_sgx_minimim_crl_tcb_issue_date); OE_RAISE_MSG( @@ -447,8 +446,8 @@ oe_result_t oe_validate_revocation_list( if (oe_datetime_compare(&earliest_until, &_sgx_minimim_crl_tcb_issue_date) < 0) { - oe_datetime_log_info("Next update date : ", &earliest_until); - oe_datetime_log_info( + oe_datetime_log("Next update date : ", &earliest_until); + oe_datetime_log( " is earlier than minimum issue date: ", &_sgx_minimim_crl_tcb_issue_date); OE_RAISE_MSG( @@ -463,15 +462,15 @@ oe_result_t oe_validate_revocation_list( "Failed to get TCB certificate.", NULL); oe_cert_get_validity_dates(&tcb_cert, &from, &until); - oe_datetime_log_info("TCB cert issue date: ", &from); - oe_datetime_log_info("TCB cert next update: ", &until); + oe_datetime_log("TCB cert issue date: ", &from); + oe_datetime_log("TCB cert next update: ", &until); if (oe_datetime_compare(&from, &latest_from) > 0) latest_from = from; if (oe_datetime_compare(&until, &earliest_until) < 0) earliest_until = until; - oe_datetime_log_info("Revocation overall issue date: ", &latest_from); - oe_datetime_log_info("Revocation overall next update: ", &earliest_until); + oe_datetime_log("Revocation overall issue date: ", &latest_from); + oe_datetime_log("Revocation overall next update: ", &earliest_until); if (oe_datetime_compare(&latest_from, &earliest_until) > 0) OE_RAISE_MSG( diff --git a/enclave/crypto/cert.c b/enclave/crypto/cert.c index 4416cc7698..061a678d86 100644 --- a/enclave/crypto/cert.c +++ b/enclave/crypto/cert.c @@ -1190,18 +1190,14 @@ oe_result_t oe_cert_get_validity_dates( oe_result_t result = OE_UNEXPECTED; const Cert* impl = (const Cert*)cert; - if (not_before) - memset(not_before, 0, sizeof(oe_datetime_t)); - - if (not_after) - memset(not_after, 0, sizeof(oe_datetime_t)); - /* Reject invalid parameters */ if (!_cert_is_valid(impl)) OE_RAISE(OE_INVALID_PARAMETER); if (not_before) { + memset(not_before, 0, sizeof(oe_datetime_t)); + not_before->year = (uint32_t)impl->cert->valid_from.year; not_before->month = (uint32_t)impl->cert->valid_from.mon; not_before->day = (uint32_t)impl->cert->valid_from.day; @@ -1212,6 +1208,8 @@ oe_result_t oe_cert_get_validity_dates( if (not_after) { + memset(not_after, 0, sizeof(oe_datetime_t)); + not_after->year = (uint32_t)impl->cert->valid_to.year; not_after->month = (uint32_t)impl->cert->valid_to.mon; not_after->day = (uint32_t)impl->cert->valid_to.day; diff --git a/host/crypto/bcrypt/cert.c b/host/crypto/bcrypt/cert.c index e5ca149d21..53661c903e 100644 --- a/host/crypto/bcrypt/cert.c +++ b/host/crypto/bcrypt/cert.c @@ -30,7 +30,7 @@ #define _OE_CERT_CHAIN_LENGTH_ANY 0 static const DWORD _OE_DEFAULT_GET_CRL_FLAGS = - CERT_STORE_SIGNATURE_FLAG | CERT_STORE_TIME_VALIDITY_FLAG; + CERT_STORE_SIGNATURE_FLAG | CERT_STORE_BASE_CRL_FLAG; static const CERT_CHAIN_POLICY_PARA _OE_DEFAULT_CERT_CHAIN_POLICY = { .cbSize = sizeof(CERT_CHAIN_POLICY_PARA), @@ -1305,23 +1305,21 @@ oe_result_t oe_cert_get_validity_dates( oe_result_t result = OE_UNEXPECTED; const cert_t* impl = (const cert_t*)cert; - if (not_before) - memset(not_before, 0, sizeof(oe_datetime_t)); - - if (not_after) - memset(not_after, 0, sizeof(oe_datetime_t)); - if (!_cert_is_valid(impl)) OE_RAISE(OE_INVALID_PARAMETER); if (not_before) { + memset(not_before, 0, sizeof(oe_datetime_t)); + OE_CHECK(oe_util_filetime_to_oe_datetime( &impl->cert->pCertInfo->NotBefore, not_before)); } if (not_after) { + memset(not_after, 0, sizeof(oe_datetime_t)); + OE_CHECK(oe_util_filetime_to_oe_datetime( &impl->cert->pCertInfo->NotAfter, not_after)); } diff --git a/host/crypto/bcrypt/util.h b/host/crypto/bcrypt/util.h index 2a4ab51ec3..ab237b54cf 100644 --- a/host/crypto/bcrypt/util.h +++ b/host/crypto/bcrypt/util.h @@ -19,4 +19,4 @@ oe_result_t oe_util_filetime_to_oe_datetime( const FILETIME* filetime, oe_datetime_t* datetime); -#endif /* _OE_HOST_CRYPTO_UTIL_H */ \ No newline at end of file +#endif /* _OE_HOST_CRYPTO_UTIL_H */ diff --git a/host/crypto/openssl/asn1.c b/host/crypto/openssl/asn1.c index 4a93e72309..a4b595438b 100644 --- a/host/crypto/openssl/asn1.c +++ b/host/crypto/openssl/asn1.c @@ -270,4 +270,4 @@ oe_result_t oe_asn1_time_to_date(const ASN1_TIME* time, oe_datetime_t* date) BIO_free(bio); return result; -} \ No newline at end of file +} diff --git a/host/crypto/openssl/asn1.h b/host/crypto/openssl/asn1.h index 325d0eb01d..a6121c5ba2 100644 --- a/host/crypto/openssl/asn1.h +++ b/host/crypto/openssl/asn1.h @@ -25,4 +25,4 @@ oe_result_t oe_asn1_string_to_date(const char* str, oe_datetime_t* date); */ oe_result_t oe_asn1_time_to_date(const ASN1_TIME* time, oe_datetime_t* date); -#endif /* _OE_HOST_CRYPTO_ASN1_OPENSSL_H */ \ No newline at end of file +#endif /* _OE_HOST_CRYPTO_ASN1_OPENSSL_H */ diff --git a/host/crypto/openssl/cert.c b/host/crypto/openssl/cert.c index 274dd329df..b44cf0f58e 100644 --- a/host/crypto/openssl/cert.c +++ b/host/crypto/openssl/cert.c @@ -968,12 +968,6 @@ oe_result_t oe_cert_get_validity_dates( oe_result_t result = OE_UNEXPECTED; const cert_t* impl = (const cert_t*)cert; - if (not_before) - memset(not_before, 0, sizeof(oe_datetime_t)); - - if (not_after) - memset(not_after, 0, sizeof(oe_datetime_t)); - if (!_cert_is_valid(impl)) OE_RAISE(OE_INVALID_PARAMETER); @@ -981,6 +975,8 @@ oe_result_t oe_cert_get_validity_dates( { const ASN1_TIME* time; + memset(not_before, 0, sizeof(oe_datetime_t)); + if (!(time = X509_get_notBefore(impl->x509))) OE_RAISE(OE_CRYPTO_ERROR); @@ -991,6 +987,8 @@ oe_result_t oe_cert_get_validity_dates( { const ASN1_TIME* time; + memset(not_after, 0, sizeof(oe_datetime_t)); + if (!(time = X509_get_notAfter(impl->x509))) OE_RAISE(OE_CRYPTO_ERROR); diff --git a/include/openenclave/internal/datetime.h b/include/openenclave/internal/datetime.h index 384a0e6113..4b426fd42e 100644 --- a/include/openenclave/internal/datetime.h +++ b/include/openenclave/internal/datetime.h @@ -58,9 +58,9 @@ int32_t oe_datetime_compare( oe_result_t oe_datetime_now(oe_datetime_t* value); /** - * Log date at the INFO level. + * Log the given datetime. */ -void oe_datetime_log_info(const char* msg, const oe_datetime_t* date); +void oe_datetime_log(const char* msg, const oe_datetime_t* date); OE_EXTERNC_END diff --git a/tests/host_verify/host/host.cpp b/tests/host_verify/host/host.cpp index d15b2b5e29..331862d737 100644 --- a/tests/host_verify/host/host.cpp +++ b/tests/host_verify/host/host.cpp @@ -36,14 +36,6 @@ #define REPORT_FILENAME "sgx_report.bin" #define REPORT_BAD_FILENAME "sgx_report_bad.bin" -// -// TODO: Report with collaterals tests. Will to refactor the contentns -// of the collaterals to be self-contained in order to support -// serialization. -// -//#define COLLATERALS_FILENAME "sgx_report.bin.col" -//#define COLLATERALS_BAD_FILENAME "sgx_report_bad.bin.col" - #define SKIP_RETURN_CODE 2 oe_result_t enclave_identity_verifier(oe_identity_t* identity, void* arg) @@ -342,16 +334,5 @@ int main() if (_validate_file(REPORT_BAD_FILENAME, true)) _verify_report(REPORT_BAD_FILENAME, NULL, false); - // - // TODO: Report with collaterals tests. Will to refactor the contentns - // of the collaterals to be self-contained in order to support - // serialization. - // - // if (_validate_file(REPORT_FILENAME, false)) - // _verify_report(REPORT_FILENAME, COLLATERALS_FILENAME, true); - - // if (_validate_file(REPORT_BAD_FILENAME, true)) - // _verify_report(REPORT_FILENAME, COLLATERALS_BAD_FILENAME, false); - return 0; } diff --git a/tests/report/common/tests.cpp b/tests/report/common/tests.cpp index c6bcf8f5c8..13049adaa5 100644 --- a/tests/report/common/tests.cpp +++ b/tests/report/common/tests.cpp @@ -1350,4 +1350,4 @@ void test_verify_report_with_collaterals() collaterals_buffer_ptr = NULL; report_buffer_ptr = NULL; -} \ No newline at end of file +} From 2d57a50ea297da253099c964374c33e026e4491f Mon Sep 17 00:00:00 2001 From: Simon Leet Date: Mon, 16 Sep 2019 21:12:45 +0000 Subject: [PATCH 030/420] Clone mbedTLS v2.16.2 into 3rdparty/mbedtls/mbedtls --- 3rdparty/mbedtls/mbedtls/.pylintrc | 52 + 3rdparty/mbedtls/mbedtls/.travis.yml | 9 +- 3rdparty/mbedtls/mbedtls/CMakeLists.txt | 24 +- 3rdparty/mbedtls/mbedtls/CONTRIBUTING.md | 95 + 3rdparty/mbedtls/mbedtls/ChangeLog | 436 ++- 3rdparty/mbedtls/mbedtls/Makefile | 14 +- 3rdparty/mbedtls/mbedtls/README.md | 49 +- .../mbedtls/configs/config-ccm-psk-tls1_2.h | 2 +- .../mbedtls/configs/config-no-entropy.h | 1 + .../mbedtls/mbedtls/configs/config-picocoin.h | 74 - .../mbedtls/doxygen/input/doc_mainpage.h | 2 +- .../mbedtls/mbedtls/doxygen/mbedtls.doxyfile | 2 +- .../mbedtls/mbedtls/include/mbedtls/aes.h | 325 +- .../mbedtls/mbedtls/include/mbedtls/aesni.h | 46 +- .../mbedtls/mbedtls/include/mbedtls/arc4.h | 29 +- .../mbedtls/mbedtls/include/mbedtls/aria.h | 370 +++ .../mbedtls/include/mbedtls/asn1write.h | 286 +- .../mbedtls/mbedtls/include/mbedtls/base64.h | 3 + .../mbedtls/mbedtls/include/mbedtls/bignum.h | 822 +++-- .../mbedtls/include/mbedtls/blowfish.h | 200 +- .../mbedtls/mbedtls/include/mbedtls/bn_mul.h | 22 +- .../mbedtls/include/mbedtls/camellia.h | 253 +- .../mbedtls/mbedtls/include/mbedtls/ccm.h | 222 +- .../mbedtls/mbedtls/include/mbedtls/certs.h | 234 +- .../mbedtls/include/mbedtls/chacha20.h | 226 ++ .../mbedtls/include/mbedtls/chachapoly.h | 358 +++ .../mbedtls/include/mbedtls/check_config.h | 22 +- .../mbedtls/mbedtls/include/mbedtls/cipher.h | 594 ++-- .../mbedtls/include/mbedtls/cipher_internal.h | 15 + .../mbedtls/mbedtls/include/mbedtls/cmac.h | 55 +- .../mbedtls/include/mbedtls/compat-1.3.h | 3 +- .../mbedtls/mbedtls/include/mbedtls/config.h | 488 ++- .../mbedtls/include/mbedtls/ctr_drbg.h | 131 +- .../mbedtls/mbedtls/include/mbedtls/debug.h | 36 + .../mbedtls/mbedtls/include/mbedtls/des.h | 31 +- .../mbedtls/mbedtls/include/mbedtls/dhm.h | 247 +- .../mbedtls/mbedtls/include/mbedtls/ecdh.h | 363 ++- .../mbedtls/mbedtls/include/mbedtls/ecdsa.h | 439 ++- .../mbedtls/mbedtls/include/mbedtls/ecjpake.h | 165 +- .../mbedtls/mbedtls/include/mbedtls/ecp.h | 1188 +++++--- .../mbedtls/mbedtls/include/mbedtls/entropy.h | 6 +- .../mbedtls/mbedtls/include/mbedtls/error.h | 24 +- .../mbedtls/mbedtls/include/mbedtls/gcm.h | 165 +- .../mbedtls/mbedtls/include/mbedtls/havege.h | 2 +- .../mbedtls/mbedtls/include/mbedtls/hkdf.h | 141 + .../mbedtls/include/mbedtls/hmac_drbg.h | 44 +- 3rdparty/mbedtls/mbedtls/include/mbedtls/md.h | 111 +- .../mbedtls/mbedtls/include/mbedtls/md2.h | 31 +- .../mbedtls/mbedtls/include/mbedtls/md4.h | 31 +- .../mbedtls/mbedtls/include/mbedtls/md5.h | 31 +- .../mbedtls/include/mbedtls/net_sockets.h | 48 +- .../mbedtls/mbedtls/include/mbedtls/nist_kw.h | 184 ++ .../mbedtls/mbedtls/include/mbedtls/oid.h | 26 +- .../mbedtls/mbedtls/include/mbedtls/padlock.h | 36 +- .../mbedtls/mbedtls/include/mbedtls/pem.h | 2 +- 3rdparty/mbedtls/mbedtls/include/mbedtls/pk.h | 221 +- .../mbedtls/include/mbedtls/pk_internal.h | 23 + .../mbedtls/mbedtls/include/mbedtls/pkcs11.h | 3 +- .../mbedtls/mbedtls/include/mbedtls/pkcs5.h | 4 + .../mbedtls/include/mbedtls/platform.h | 77 +- .../mbedtls/include/mbedtls/platform_util.h | 185 ++ .../mbedtls/include/mbedtls/poly1305.h | 192 ++ .../mbedtls/include/mbedtls/ripemd160.h | 32 +- .../mbedtls/mbedtls/include/mbedtls/rsa.h | 995 ++++--- .../mbedtls/mbedtls/include/mbedtls/sha1.h | 196 +- .../mbedtls/mbedtls/include/mbedtls/sha256.h | 137 +- .../mbedtls/mbedtls/include/mbedtls/sha512.h | 142 +- .../mbedtls/mbedtls/include/mbedtls/ssl.h | 780 ++++- .../include/mbedtls/ssl_ciphersuites.h | 48 + .../mbedtls/include/mbedtls/ssl_cookie.h | 2 +- .../mbedtls/include/mbedtls/ssl_internal.h | 159 +- .../mbedtls/include/mbedtls/ssl_ticket.h | 4 +- .../mbedtls/include/mbedtls/threading.h | 17 +- .../mbedtls/mbedtls/include/mbedtls/timing.h | 26 +- .../mbedtls/mbedtls/include/mbedtls/version.h | 10 +- .../mbedtls/mbedtls/include/mbedtls/x509.h | 4 + .../mbedtls/include/mbedtls/x509_crt.h | 104 +- .../mbedtls/mbedtls/include/mbedtls/xtea.h | 30 +- .../mbedtls/mbedtls/library/CMakeLists.txt | 24 +- 3rdparty/mbedtls/mbedtls/library/Makefile | 71 +- 3rdparty/mbedtls/mbedtls/library/aes.c | 837 +++++- 3rdparty/mbedtls/mbedtls/library/aesni.c | 6 + 3rdparty/mbedtls/mbedtls/library/arc4.c | 8 +- 3rdparty/mbedtls/mbedtls/library/aria.c | 1079 +++++++ 3rdparty/mbedtls/mbedtls/library/asn1parse.c | 10 +- 3rdparty/mbedtls/mbedtls/library/asn1write.c | 34 +- 3rdparty/mbedtls/mbedtls/library/bignum.c | 451 ++- 3rdparty/mbedtls/mbedtls/library/blowfish.c | 64 +- 3rdparty/mbedtls/mbedtls/library/camellia.c | 76 +- 3rdparty/mbedtls/mbedtls/library/ccm.c | 94 +- 3rdparty/mbedtls/mbedtls/library/certs.c | 2073 ++++++++++--- 3rdparty/mbedtls/mbedtls/library/chacha20.c | 570 ++++ 3rdparty/mbedtls/mbedtls/library/chachapoly.c | 540 ++++ 3rdparty/mbedtls/mbedtls/library/cipher.c | 343 ++- .../mbedtls/mbedtls/library/cipher_wrap.c | 821 +++++ 3rdparty/mbedtls/mbedtls/library/cmac.c | 36 +- 3rdparty/mbedtls/mbedtls/library/ctr_drbg.c | 129 +- 3rdparty/mbedtls/mbedtls/library/debug.c | 50 + 3rdparty/mbedtls/mbedtls/library/des.c | 97 +- 3rdparty/mbedtls/mbedtls/library/dhm.c | 87 +- 3rdparty/mbedtls/mbedtls/library/ecdh.c | 570 +++- 3rdparty/mbedtls/mbedtls/library/ecdsa.c | 563 +++- 3rdparty/mbedtls/mbedtls/library/ecjpake.c | 38 +- 3rdparty/mbedtls/mbedtls/library/ecp.c | 1259 ++++++-- 3rdparty/mbedtls/mbedtls/library/ecp_curves.c | 203 +- 3rdparty/mbedtls/mbedtls/library/entropy.c | 18 +- .../mbedtls/mbedtls/library/entropy_poll.c | 11 +- 3rdparty/mbedtls/mbedtls/library/error.c | 114 +- 3rdparty/mbedtls/mbedtls/library/gcm.c | 60 +- 3rdparty/mbedtls/mbedtls/library/havege.c | 10 +- 3rdparty/mbedtls/mbedtls/library/hkdf.c | 192 ++ 3rdparty/mbedtls/mbedtls/library/hmac_drbg.c | 47 +- 3rdparty/mbedtls/mbedtls/library/md.c | 15 +- 3rdparty/mbedtls/mbedtls/library/md2.c | 8 +- 3rdparty/mbedtls/mbedtls/library/md4.c | 38 +- 3rdparty/mbedtls/mbedtls/library/md5.c | 29 +- .../mbedtls/library/memory_buffer_alloc.c | 20 +- .../mbedtls/mbedtls/library/net_sockets.c | 82 +- 3rdparty/mbedtls/mbedtls/library/nist_kw.c | 755 +++++ 3rdparty/mbedtls/mbedtls/library/oid.c | 53 +- 3rdparty/mbedtls/mbedtls/library/pem.c | 34 +- 3rdparty/mbedtls/mbedtls/library/pk.c | 216 +- 3rdparty/mbedtls/mbedtls/library/pk_wrap.c | 213 +- 3rdparty/mbedtls/mbedtls/library/pkcs12.c | 20 +- 3rdparty/mbedtls/mbedtls/library/pkparse.c | 132 +- 3rdparty/mbedtls/mbedtls/library/pkwrite.c | 32 +- 3rdparty/mbedtls/mbedtls/library/platform.c | 29 +- .../mbedtls/mbedtls/library/platform_util.c | 136 + 3rdparty/mbedtls/mbedtls/library/poly1305.c | 559 ++++ 3rdparty/mbedtls/mbedtls/library/ripemd160.c | 47 +- 3rdparty/mbedtls/mbedtls/library/rsa.c | 319 +- .../mbedtls/mbedtls/library/rsa_internal.c | 9 +- 3rdparty/mbedtls/mbedtls/library/sha1.c | 64 +- 3rdparty/mbedtls/mbedtls/library/sha256.c | 64 +- 3rdparty/mbedtls/mbedtls/library/sha512.c | 54 +- .../mbedtls/library/ssl_ciphersuites.c | 485 ++- 3rdparty/mbedtls/mbedtls/library/ssl_cli.c | 222 +- 3rdparty/mbedtls/mbedtls/library/ssl_cookie.c | 10 +- 3rdparty/mbedtls/mbedtls/library/ssl_srv.c | 612 ++-- 3rdparty/mbedtls/mbedtls/library/ssl_ticket.c | 10 +- 3rdparty/mbedtls/mbedtls/library/ssl_tls.c | 2631 ++++++++++++----- 3rdparty/mbedtls/mbedtls/library/threading.c | 44 +- 3rdparty/mbedtls/mbedtls/library/timing.c | 3 +- 3rdparty/mbedtls/mbedtls/library/version.c | 2 +- .../mbedtls/library/version_features.c | 57 + 3rdparty/mbedtls/mbedtls/library/x509.c | 50 +- .../mbedtls/mbedtls/library/x509_create.c | 171 +- 3rdparty/mbedtls/mbedtls/library/x509_crl.c | 17 +- 3rdparty/mbedtls/mbedtls/library/x509_crt.c | 1351 +++++---- 3rdparty/mbedtls/mbedtls/library/x509_csr.c | 14 +- .../mbedtls/mbedtls/library/x509write_crt.c | 151 +- .../mbedtls/mbedtls/library/x509write_csr.c | 8 +- 3rdparty/mbedtls/mbedtls/library/xtea.c | 8 +- 3rdparty/mbedtls/mbedtls/programs/Makefile | 28 +- 3rdparty/mbedtls/mbedtls/programs/README.md | 123 + .../mbedtls/mbedtls/programs/aes/aescrypt2.c | 32 +- .../mbedtls/programs/aes/crypt_and_hash.c | 32 +- .../mbedtls/programs/hash/generic_sum.c | 14 + .../mbedtls/mbedtls/programs/hash/hello.c | 14 + .../mbedtls/mbedtls/programs/pkey/dh_client.c | 14 + .../mbedtls/programs/pkey/dh_genprime.c | 15 +- .../mbedtls/mbedtls/programs/pkey/dh_server.c | 14 + .../mbedtls/programs/pkey/ecdh_curve25519.c | 17 +- .../mbedtls/mbedtls/programs/pkey/ecdsa.c | 13 + .../mbedtls/mbedtls/programs/pkey/gen_key.c | 14 + .../mbedtls/mbedtls/programs/pkey/key_app.c | 14 + .../mbedtls/programs/pkey/key_app_writer.c | 14 + .../mbedtls/mbedtls/programs/pkey/mpi_demo.c | 14 + .../mbedtls/programs/pkey/pk_decrypt.c | 14 + .../mbedtls/programs/pkey/pk_encrypt.c | 14 + .../mbedtls/mbedtls/programs/pkey/pk_sign.c | 13 + .../mbedtls/mbedtls/programs/pkey/pk_verify.c | 13 + .../mbedtls/programs/pkey/rsa_decrypt.c | 13 + .../mbedtls/programs/pkey/rsa_encrypt.c | 13 + .../mbedtls/programs/pkey/rsa_genkey.c | 14 + .../mbedtls/mbedtls/programs/pkey/rsa_sign.c | 13 + .../mbedtls/programs/pkey/rsa_sign_pss.c | 13 + .../mbedtls/programs/pkey/rsa_verify.c | 13 + .../mbedtls/programs/pkey/rsa_verify_pss.c | 13 + .../mbedtls/programs/random/gen_entropy.c | 14 + .../programs/random/gen_random_ctr_drbg.c | 14 + .../programs/random/gen_random_havege.c | 14 + .../mbedtls/programs/ssl/CMakeLists.txt | 2 + .../mbedtls/programs/ssl/dtls_client.c | 15 + .../mbedtls/programs/ssl/dtls_server.c | 15 + .../mbedtls/programs/ssl/mini_client.c | 36 +- .../mbedtls/programs/ssl/query_config.c | 2515 ++++++++++++++++ .../mbedtls/programs/ssl/ssl_client1.c | 13 + .../mbedtls/programs/ssl/ssl_client2.c | 514 +++- .../mbedtls/programs/ssl/ssl_fork_server.c | 13 + .../mbedtls/programs/ssl/ssl_mail_client.c | 18 + .../mbedtls/programs/ssl/ssl_pthread_server.c | 16 + .../mbedtls/mbedtls/programs/ssl/ssl_server.c | 15 + .../mbedtls/programs/ssl/ssl_server2.c | 770 ++++- .../mbedtls/programs/test/CMakeLists.txt | 13 +- .../mbedtls/mbedtls/programs/test/benchmark.c | 256 +- .../mbedtls/programs/test/cpp_dummy_build.cpp | 119 + .../programs/test/query_compile_time_config.c | 56 + .../mbedtls/mbedtls/programs/test/selftest.c | 32 + .../mbedtls/mbedtls/programs/test/udp_proxy.c | 405 ++- .../programs/test/udp_proxy_wrapper.sh | 117 + .../mbedtls/mbedtls/programs/test/zeroize.c | 101 + .../mbedtls/mbedtls/programs/util/pem2der.c | 14 + .../mbedtls/mbedtls/programs/x509/cert_app.c | 13 + .../mbedtls/mbedtls/programs/x509/cert_req.c | 20 +- .../mbedtls/programs/x509/cert_write.c | 19 +- .../mbedtls/mbedtls/programs/x509/crl_app.c | 13 + .../mbedtls/mbedtls/programs/x509/req_app.c | 13 + .../mbedtls/mbedtls/scripts/bump_version.sh | 3 + 3rdparty/mbedtls/mbedtls/scripts/config.pl | 1 + .../scripts/data_files/query_config.fmt | 139 + .../data_files/vs2010-app-template.vcxproj | 3 +- 3rdparty/mbedtls/mbedtls/scripts/footprint.sh | 5 - .../mbedtls/scripts/generate_errors.pl | 8 +- .../mbedtls/scripts/generate_query_config.pl | 75 + .../mbedtls/scripts/generate_visualc_files.pl | 8 +- .../mbedtls/mbedtls/scripts/output_env.sh | 5 + 3rdparty/mbedtls/mbedtls/tests/CMakeLists.txt | 21 +- 3rdparty/mbedtls/mbedtls/tests/Makefile | 446 +-- 3rdparty/mbedtls/mbedtls/tests/compat.sh | 172 +- .../mbedtls/mbedtls/tests/data_files/Makefile | 253 +- .../mbedtls/tests/data_files/Readme-x509.txt | 42 +- .../mbedtls/tests/data_files/cli-rsa-sha1.crt | 21 +- .../tests/data_files/cli-rsa-sha256.crt | 21 +- .../tests/data_files/cli-rsa-sha256.crt.der | Bin 0 -> 835 bytes .../tests/data_files/cli-rsa-sha256.key.der | Bin 0 -> 1192 bytes .../mbedtls/tests/data_files/cli-rsa.key.der | Bin 0 -> 1192 bytes .../mbedtls/tests/data_files/cli2.crt.der | Bin 0 -> 560 bytes .../mbedtls/tests/data_files/cli2.key.der | Bin 0 -> 121 bytes .../data_files/rsa_pkcs1_2048_public.der | Bin 0 -> 270 bytes .../data_files/rsa_pkcs1_2048_public.pem | 8 + .../data_files/rsa_pkcs8_1024_public.der | Bin 0 -> 162 bytes .../data_files/rsa_pkcs8_2048_public.der | Bin 0 -> 294 bytes .../data_files/rsa_pkcs8_2048_public.pem | 9 + .../tests/data_files/server1.cert_type.crt | 16 +- .../data_files/server1.cert_type_noauthid.crt | 18 +- .../mbedtls/tests/data_files/server1.crt | 16 +- .../mbedtls/tests/data_files/server1.crt.der | Bin 0 -> 835 bytes .../tests/data_files/server1.key_usage.crt | 16 +- .../data_files/server1.key_usage_noauthid.crt | 18 +- .../tests/data_files/server1.noauthid.crt | 16 +- .../tests/data_files/server1.req.cert_type | 18 +- .../data_files/server1.req.cert_type_empty | 18 +- .../tests/data_files/server1.req.key_usage | 18 +- .../data_files/server1.req.key_usage_empty | 18 +- .../tests/data_files/server1.req.ku-ct | 16 +- .../mbedtls/tests/data_files/server1.req.md4 | 16 +- .../mbedtls/tests/data_files/server1.req.md5 | 16 +- .../mbedtls/tests/data_files/server1.req.sha1 | 16 +- .../tests/data_files/server1.req.sha224 | 16 +- .../tests/data_files/server1.req.sha256 | 16 +- .../tests/data_files/server1.req.sha384 | 16 +- .../tests/data_files/server1.req.sha512 | 16 +- .../mbedtls/tests/data_files/server1.v1.crt | 18 +- .../tests/data_files/server10-badsign.crt | 10 + .../tests/data_files/server10-bs_int3.pem | 22 + .../mbedtls/tests/data_files/server10.crt | 10 + .../tests/data_files/server10_int3-bs.pem | 22 + .../tests/data_files/server2-sha256.crt | 23 +- .../tests/data_files/server2-sha256.crt.der | Bin 0 -> 827 bytes .../mbedtls/tests/data_files/server2.crt | 75 +- .../mbedtls/tests/data_files/server2.crt.der | Bin 0 -> 827 bytes .../mbedtls/tests/data_files/server2.key.der | Bin 0 -> 1192 bytes .../mbedtls/tests/data_files/server5.crt.der | Bin 0 -> 547 bytes .../mbedtls/tests/data_files/server5.key.der | Bin 0 -> 121 bytes .../tests/data_files/server5.req.ku.sha1 | 8 +- .../tests/data_files/test-ca-alt-good.crt | 21 +- .../tests/data_files/test-ca-good-alt.crt | 21 +- .../mbedtls/tests/data_files/test-ca-sha1.crt | 21 +- .../tests/data_files/test-ca-sha1.crt.der | Bin 0 -> 837 bytes .../tests/data_files/test-ca-sha256.crt | 21 +- .../tests/data_files/test-ca-sha256.crt.der | Bin 0 -> 837 bytes .../mbedtls/tests/data_files/test-ca.crt | 82 +- .../mbedtls/tests/data_files/test-ca.crt.der | Bin 0 -> 837 bytes .../mbedtls/tests/data_files/test-ca.key.der | Bin 0 -> 1192 bytes .../mbedtls/tests/data_files/test-ca2.crt.der | Bin 0 -> 598 bytes .../mbedtls/tests/data_files/test-ca2.key.der | Bin 0 -> 167 bytes .../mbedtls/tests/data_files/test-ca2.key.enc | 9 + .../tests/data_files/test-ca_cat12.crt | 82 +- .../tests/data_files/test-ca_cat21.crt | 82 +- .../tests/data_files/test-int-ca3-badsign.crt | 12 + 3rdparty/mbedtls/mbedtls/tests/scripts/all.sh | 275 +- .../mbedtls/tests/scripts/basic-build-test.sh | 3 + .../mbedtls/tests/scripts/check-files.py | 1 - .../tests/scripts/check-generated-files.sh | 1 + .../mbedtls/tests/scripts/check-names.sh | 2 +- .../tests/scripts/check-python-files.sh | 12 + .../mbedtls/tests/scripts/generate_code.pl | 411 --- .../tests/scripts/generate_test_code.py | 1152 ++++++++ .../mbedtls/tests/scripts/mbedtls_test.py | 379 +++ .../mbedtls/tests/scripts/test-ref-configs.pl | 2 - .../tests/scripts/test_generate_test_code.py | 1755 +++++++++++ .../mbedtls/tests/scripts/test_zeroize.gdb | 71 + .../mbedtls/tests/scripts/yotta-build.sh | 61 - 3rdparty/mbedtls/mbedtls/tests/ssl-opt.sh | 2414 +++++++++++++-- .../mbedtls/tests/suites/helpers.function | 261 +- .../mbedtls/tests/suites/host_test.function | 672 +++++ .../mbedtls/tests/suites/main_test.function | 663 ++--- .../mbedtls/tests/suites/target_test.function | 413 +++ .../tests/suites/test_suite_aes.function | 615 +++- .../tests/suites/test_suite_aes.ofb.data | 35 + .../tests/suites/test_suite_aes.rest.data | 6 + .../tests/suites/test_suite_aes.xts.data | 158 + .../tests/suites/test_suite_arc4.function | 22 +- .../mbedtls/tests/suites/test_suite_aria.data | 104 + .../tests/suites/test_suite_aria.function | 527 ++++ .../suites/test_suite_asn1write.function | 46 +- .../tests/suites/test_suite_base64.function | 41 +- .../tests/suites/test_suite_blowfish.data | 14 +- .../tests/suites/test_suite_blowfish.function | 315 +- .../tests/suites/test_suite_camellia.data | 10 +- .../tests/suites/test_suite_camellia.function | 302 +- .../mbedtls/tests/suites/test_suite_ccm.data | 231 +- .../tests/suites/test_suite_ccm.function | 436 ++- .../tests/suites/test_suite_chacha20.data | 29 + .../tests/suites/test_suite_chacha20.function | 136 + .../tests/suites/test_suite_chachapoly.data | 27 + .../suites/test_suite_chachapoly.function | 337 +++ .../tests/suites/test_suite_cipher.aes.data | 394 ++- .../tests/suites/test_suite_cipher.ccm.data | 240 +- .../suites/test_suite_cipher.chacha20.data | 111 + .../suites/test_suite_cipher.chachapoly.data | 123 + .../tests/suites/test_suite_cipher.function | 718 +++-- .../tests/suites/test_suite_cipher.misc.data | 5 + .../suites/test_suite_cipher.padding.data | 3 - .../tests/suites/test_suite_cmac.function | 108 +- .../tests/suites/test_suite_ctr_drbg.data | 713 +++-- .../tests/suites/test_suite_ctr_drbg.function | 201 +- .../tests/suites/test_suite_debug.function | 27 +- .../tests/suites/test_suite_des.function | 196 +- .../mbedtls/tests/suites/test_suite_dhm.data | 3 + .../tests/suites/test_suite_dhm.function | 111 +- .../mbedtls/tests/suites/test_suite_ecdh.data | 42 + .../tests/suites/test_suite_ecdh.function | 382 ++- .../tests/suites/test_suite_ecdsa.data | 95 +- .../tests/suites/test_suite_ecdsa.function | 368 ++- .../tests/suites/test_suite_ecjpake.data | 3 + .../tests/suites/test_suite_ecjpake.function | 169 +- .../mbedtls/tests/suites/test_suite_ecp.data | 56 +- .../tests/suites/test_suite_ecp.function | 591 +++- .../tests/suites/test_suite_entropy.function | 19 +- .../tests/suites/test_suite_error.function | 2 +- .../suites/test_suite_gcm.aes128_de.data | 336 +-- .../suites/test_suite_gcm.aes192_de.data | 336 +-- .../suites/test_suite_gcm.aes256_de.data | 336 +-- .../tests/suites/test_suite_gcm.camellia.data | 72 +- .../tests/suites/test_suite_gcm.function | 279 +- .../tests/suites/test_suite_gcm.misc.data | 5 + .../mbedtls/tests/suites/test_suite_hkdf.data | 98 + .../tests/suites/test_suite_hkdf.function | 174 ++ .../suites/test_suite_hmac_drbg.function | 126 +- .../tests/suites/test_suite_md.function | 129 +- .../tests/suites/test_suite_mdx.function | 36 +- .../test_suite_memory_buffer_alloc.function | 11 +- .../mbedtls/tests/suites/test_suite_mpi.data | 38 +- .../tests/suites/test_suite_mpi.function | 430 ++- .../tests/suites/test_suite_nist_kw.data | 483 +++ .../tests/suites/test_suite_nist_kw.function | 347 +++ .../tests/suites/test_suite_pem.function | 14 +- .../mbedtls/tests/suites/test_suite_pk.data | 42 + .../tests/suites/test_suite_pk.function | 697 ++++- .../suites/test_suite_pkcs1_v15.function | 101 +- .../tests/suites/test_suite_pkcs1_v21.data | 48 +- .../suites/test_suite_pkcs1_v21.function | 121 +- .../tests/suites/test_suite_pkcs5.function | 48 +- .../tests/suites/test_suite_pkparse.data | 14 +- .../tests/suites/test_suite_pkparse.function | 18 +- .../tests/suites/test_suite_pkwrite.function | 4 +- .../tests/suites/test_suite_poly1305.data | 42 + .../tests/suites/test_suite_poly1305.function | 135 + .../mbedtls/tests/suites/test_suite_rsa.data | 26 +- .../tests/suites/test_suite_rsa.function | 838 ++++-- .../mbedtls/tests/suites/test_suite_shax.data | 18 + .../tests/suites/test_suite_shax.function | 230 +- .../mbedtls/tests/suites/test_suite_ssl.data | 32 +- .../tests/suites/test_suite_ssl.function | 12 +- .../tests/suites/test_suite_version.data | 4 +- .../tests/suites/test_suite_version.function | 4 +- .../tests/suites/test_suite_x509parse.data | 114 +- .../suites/test_suite_x509parse.function | 144 +- .../suites/test_suite_x509write.function | 4 +- .../tests/suites/test_suite_xtea.function | 90 +- .../mbedtls/visualc/VS2010/mbedTLS.sln | 26 + .../mbedtls/visualc/VS2010/mbedTLS.vcxproj | 14 + .../VS2010/query_compile_time_config.vcxproj | 175 ++ .../visualc/VS2010/ssl_client2.vcxproj | 1 + .../visualc/VS2010/ssl_server2.vcxproj | 1 + .../mbedtls/visualc/VS2010/zeroize.vcxproj | 174 ++ .../mbedtls/mbedtls/yotta/create-module.sh | 47 - 3rdparty/mbedtls/mbedtls/yotta/data/README.md | 103 - .../mbedtls/yotta/data/adjust-config.sh | 77 - .../yotta/data/entropy_hardware_poll.c | 88 - .../yotta/data/example-authcrypt/README.md | 68 - .../yotta/data/example-authcrypt/main.cpp | 197 -- .../yotta/data/example-benchmark/README.md | 100 - .../yotta/data/example-benchmark/main.cpp | 951 ------ .../yotta/data/example-hashing/README.md | 67 - .../yotta/data/example-hashing/main.cpp | 177 -- .../yotta/data/example-selftest/README.md | 82 - .../yotta/data/example-selftest/main.cpp | 268 -- .../mbedtls/mbedtls/yotta/data/module.json | 18 - .../mbedtls/yotta/data/target_config.h | 35 - 402 files changed, 50094 insertions(+), 14567 deletions(-) create mode 100644 3rdparty/mbedtls/mbedtls/.pylintrc create mode 100644 3rdparty/mbedtls/mbedtls/CONTRIBUTING.md delete mode 100644 3rdparty/mbedtls/mbedtls/configs/config-picocoin.h create mode 100644 3rdparty/mbedtls/mbedtls/include/mbedtls/aria.h create mode 100644 3rdparty/mbedtls/mbedtls/include/mbedtls/chacha20.h create mode 100644 3rdparty/mbedtls/mbedtls/include/mbedtls/chachapoly.h create mode 100644 3rdparty/mbedtls/mbedtls/include/mbedtls/hkdf.h create mode 100644 3rdparty/mbedtls/mbedtls/include/mbedtls/nist_kw.h create mode 100644 3rdparty/mbedtls/mbedtls/include/mbedtls/platform_util.h create mode 100644 3rdparty/mbedtls/mbedtls/include/mbedtls/poly1305.h create mode 100644 3rdparty/mbedtls/mbedtls/library/aria.c create mode 100644 3rdparty/mbedtls/mbedtls/library/chacha20.c create mode 100644 3rdparty/mbedtls/mbedtls/library/chachapoly.c create mode 100644 3rdparty/mbedtls/mbedtls/library/hkdf.c create mode 100644 3rdparty/mbedtls/mbedtls/library/nist_kw.c create mode 100644 3rdparty/mbedtls/mbedtls/library/platform_util.c create mode 100644 3rdparty/mbedtls/mbedtls/library/poly1305.c create mode 100644 3rdparty/mbedtls/mbedtls/programs/README.md create mode 100644 3rdparty/mbedtls/mbedtls/programs/ssl/query_config.c create mode 100644 3rdparty/mbedtls/mbedtls/programs/test/cpp_dummy_build.cpp create mode 100644 3rdparty/mbedtls/mbedtls/programs/test/query_compile_time_config.c create mode 100755 3rdparty/mbedtls/mbedtls/programs/test/udp_proxy_wrapper.sh create mode 100644 3rdparty/mbedtls/mbedtls/programs/test/zeroize.c create mode 100644 3rdparty/mbedtls/mbedtls/scripts/data_files/query_config.fmt create mode 100755 3rdparty/mbedtls/mbedtls/scripts/generate_query_config.pl create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/cli-rsa-sha256.crt.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/cli-rsa-sha256.key.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/cli-rsa.key.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/cli2.crt.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/cli2.key.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/rsa_pkcs1_2048_public.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/rsa_pkcs1_2048_public.pem create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/rsa_pkcs8_1024_public.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/rsa_pkcs8_2048_public.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/rsa_pkcs8_2048_public.pem create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server1.crt.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server10-badsign.crt create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server10-bs_int3.pem create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server10.crt create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server10_int3-bs.pem create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server2-sha256.crt.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server2.crt.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server2.key.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server5.crt.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/server5.key.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/test-ca-sha1.crt.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/test-ca-sha256.crt.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/test-ca.crt.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/test-ca.key.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/test-ca2.crt.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/test-ca2.key.der create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/test-ca2.key.enc create mode 100644 3rdparty/mbedtls/mbedtls/tests/data_files/test-int-ca3-badsign.crt create mode 100755 3rdparty/mbedtls/mbedtls/tests/scripts/check-python-files.sh delete mode 100755 3rdparty/mbedtls/mbedtls/tests/scripts/generate_code.pl create mode 100755 3rdparty/mbedtls/mbedtls/tests/scripts/generate_test_code.py create mode 100755 3rdparty/mbedtls/mbedtls/tests/scripts/mbedtls_test.py create mode 100755 3rdparty/mbedtls/mbedtls/tests/scripts/test_generate_test_code.py create mode 100644 3rdparty/mbedtls/mbedtls/tests/scripts/test_zeroize.gdb delete mode 100755 3rdparty/mbedtls/mbedtls/tests/scripts/yotta-build.sh create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/host_test.function create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/target_test.function create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_aes.ofb.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_aes.xts.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_aria.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_aria.function create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_chacha20.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_chacha20.function create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_chachapoly.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_chachapoly.function create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_cipher.chacha20.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_cipher.chachapoly.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_cipher.misc.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_gcm.misc.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_hkdf.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_hkdf.function create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_nist_kw.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_nist_kw.function create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_poly1305.data create mode 100644 3rdparty/mbedtls/mbedtls/tests/suites/test_suite_poly1305.function create mode 100644 3rdparty/mbedtls/mbedtls/visualc/VS2010/query_compile_time_config.vcxproj create mode 100644 3rdparty/mbedtls/mbedtls/visualc/VS2010/zeroize.vcxproj delete mode 100755 3rdparty/mbedtls/mbedtls/yotta/create-module.sh delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/README.md delete mode 100755 3rdparty/mbedtls/mbedtls/yotta/data/adjust-config.sh delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/entropy_hardware_poll.c delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/example-authcrypt/README.md delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/example-authcrypt/main.cpp delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/example-benchmark/README.md delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/example-benchmark/main.cpp delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/example-hashing/README.md delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/example-hashing/main.cpp delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/example-selftest/README.md delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/example-selftest/main.cpp delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/module.json delete mode 100644 3rdparty/mbedtls/mbedtls/yotta/data/target_config.h diff --git a/3rdparty/mbedtls/mbedtls/.pylintrc b/3rdparty/mbedtls/mbedtls/.pylintrc new file mode 100644 index 0000000000..168e0b7590 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/.pylintrc @@ -0,0 +1,52 @@ +[BASIC] +# We're ok with short funtion argument names. +# [invalid-name] +argument-rgx=[a-z_][a-z0-9_]*$ + +# Allow filter and map. +# [bad-builtin] +bad-functions=input + +# We prefer docstrings, but we don't require them on all functions. +# Require them only on long functions (for some value of long). +# [missing-docstring] +docstring-min-length=10 + +# Allow longer methods than the default. +# [invalid-name] +method-rgx=[a-z_][a-z0-9_]{2,35}$ + +# Allow module names containing a dash (but no underscore or uppercase letter). +# They are whole programs, not meant to be included by another module. +# [invalid-name] +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+)|[a-z][-0-9a-z]+)$ + +# Some functions don't need docstrings. +# [missing-docstring] +no-docstring-rgx=(run_)main$ + +# We're ok with short local or global variable names. +# [invalid-name] +variable-rgx=[a-z_][a-z0-9_]*$ + +[DESIGN] +# Allow more than the default 7 attributes. +# [too-many-instance-attributes] +max-attributes=15 + +[FORMAT] +# Allow longer modules than the default recommended maximum. +# [too-many-lines] +max-module-lines=2000 + +[MESSAGES CONTROL] +disable= + +[REPORTS] +# Don't diplay statistics. Just the facts. +reports=no + +[VARIABLES] +# Allow unused variables if their name starts with an underscore. +# [unused-argument] +dummy-variables-rgx=_.* diff --git a/3rdparty/mbedtls/mbedtls/.travis.yml b/3rdparty/mbedtls/mbedtls/.travis.yml index b4f21a30f0..c45d4081d0 100644 --- a/3rdparty/mbedtls/mbedtls/.travis.yml +++ b/3rdparty/mbedtls/mbedtls/.travis.yml @@ -4,6 +4,13 @@ compiler: - gcc sudo: false cache: ccache + +# blocklist +branches: + except: + - development-psa + - coverity_scan + script: - tests/scripts/recursion.pl library/*.c - tests/scripts/check-generated-files.sh @@ -35,7 +42,7 @@ addons: coverity_scan: project: name: "ARMmbed/mbedtls" - notification_email: p.j.bakker@polarssl.org + notification_email: simon.butcher@arm.com build_command_prepend: build_command: make branch_pattern: coverity_scan diff --git a/3rdparty/mbedtls/mbedtls/CMakeLists.txt b/3rdparty/mbedtls/mbedtls/CMakeLists.txt index 7309d02e70..5f7d0d8862 100644 --- a/3rdparty/mbedtls/mbedtls/CMakeLists.txt +++ b/3rdparty/mbedtls/mbedtls/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 2.6) -project("mbed TLS" C) +if(TEST_CPP) + project("mbed TLS" C CXX) +else() + project("mbed TLS" C) +endif() option(USE_PKCS11_HELPER_LIBRARY "Build mbed TLS with the pkcs11-helper library." OFF) option(ENABLE_ZLIB_SUPPORT "Build mbed TLS with zlib library." OFF) @@ -32,9 +36,27 @@ set(NULL_ENTROPY_WARNING "${WARNING_BORDER}" "${NULL_ENTROPY_WARN_L3}" "${WARNING_BORDER}") +set(CTR_DRBG_128_BIT_KEY_WARN_L1 "**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined!\n") +set(CTR_DRBG_128_BIT_KEY_WARN_L2 "**** Using 128-bit keys for CTR_DRBG limits the security of generated\n") +set(CTR_DRBG_128_BIT_KEY_WARN_L3 "**** keys and operations that use random values generated to 128-bit security\n") + +set(CTR_DRBG_128_BIT_KEY_WARNING "${WARNING_BORDER}" + "${CTR_DRBG_128_BIT_KEY_WARN_L1}" + "${CTR_DRBG_128_BIT_KEY_WARN_L2}" + "${CTR_DRBG_128_BIT_KEY_WARN_L3}" + "${WARNING_BORDER}") + +find_package(PythonInterp) find_package(Perl) if(PERL_FOUND) + # If 128-bit keys are configured for CTR_DRBG, display an appropriate warning + execute_process(COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/config.pl -f ${CMAKE_CURRENT_SOURCE_DIR}/include/mbedtls/config.h get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY + RESULT_VARIABLE result) + if(${result} EQUAL 0) + message(WARNING ${CTR_DRBG_128_BIT_KEY_WARNING}) + endif() + # If NULL Entropy is configured, display an appropriate warning execute_process(COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/config.pl -f ${CMAKE_CURRENT_SOURCE_DIR}/include/mbedtls/config.h get MBEDTLS_TEST_NULL_ENTROPY RESULT_VARIABLE result) diff --git a/3rdparty/mbedtls/mbedtls/CONTRIBUTING.md b/3rdparty/mbedtls/mbedtls/CONTRIBUTING.md new file mode 100644 index 0000000000..010dffc638 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/CONTRIBUTING.md @@ -0,0 +1,95 @@ +Contributing +============ +We gratefully accept bug reports and contributions from the community. There are some requirements we need to fulfill in order to be able to integrate contributions: + + - As with any open source project, contributions will be reviewed by the project team and community and may need some modifications to be accepted. + - The contribution should not break API or ABI, unless there is a real justification for that. If there is an API change, the contribution, if accepted, will be merged only when there will be a major release. + +Contributor License Agreement (CLA) +----------------------------------- +- All contributions, whether large or small, require a Contributor's License Agreement (CLA) to be accepted. This is because source code can possibly fall under copyright law and we need your consent to share in the ownership of the copyright. +- To accept the Contributorā€™s License Agreement (CLA), individual contributors can do this by creating an Mbed account and [accepting the online agreement here with a click through](https://developer.mbed.org/contributor_agreement/). Alternatively, for contributions from corporations, or those that do not wish to create an Mbed account, a slightly different agreement can be found [here](https://www.mbed.com/en/about-mbed/contributor-license-agreements/). This agreement should be signed and returned to Arm as described in the instructions given. + +Coding Standards +---------------- +- We would ask that contributions conform to [our coding standards](https://tls.mbed.org/kb/development/mbedtls-coding-standards), and that contributions are fully tested before submission, as mentioned in the [Tests](#tests) and [Continuous Integration](#continuous-integration-tests) sections. +- The code should be written in a clean and readable style. +- The code should be written in a portable generic way, that will benefit the whole community, and not only your own needs. +- The code should be secure, and will be reviewed from a security point of view as well. + +Making a Contribution +--------------------- +1. [Check for open issues](https://github.com/ARMmbed/mbedtls/issues) or [start a discussion](https://tls.mbed.org/discussions) around a feature idea or a bug. +1. Fork the [Mbed TLS repository on GitHub](https://github.com/ARMmbed/mbedtls) to start making your changes. As a general rule, you should use the ["development" branch](https://github.com/ARMmbed/mbedtls/tree/development) as a basis. +1. Write a test which shows that the bug was fixed or that the feature works as expected. +1. Send a pull request (PR) and work with us until it gets merged and published. Contributions may need some modifications, so a few rounds of review and fixing may be necessary. We will include your name in the ChangeLog :) +1. For quick merging, the contribution should be short, and concentrated on a single feature or topic. The larger the contribution is, the longer it would take to review it and merge it. +1. Mbed TLS is released under the Apache license, and as such, all the added files should include the Apache license header. + +API/ABI Compatibility +--------------------- +The project aims to minimise the impact on users upgrading to newer versions of the library and it should not be necessary for a user to make any changes to their own code to work with a newer version of the library. Unless the user has made an active decision to use newer features, a newer generation of the library or a change has been necessary due to a security issue or other significant software defect, no modifications to their own code should be necessary. To achieve this, API compatibility is maintained between different versions of Mbed TLS on the main development branch and in LTS (Long Term Support) branches. + +To minimise such disruption to users, where a change to the interface is required, all changes to the ABI or API, even on the main development branch where new features are added, need to be justifiable by either being a significant enhancement, new feature or bug fix which is best resolved by an interface change. + +Where changes to an existing interface are necessary, functions in the public interface which need to be changed, are marked as 'deprecated'. This is done with the preprocessor symbols `MBEDTLS_DEPRECATED_WARNING` and `MBEDTLS_DEPRECATED_REMOVED`. Then, a new function with a new name but similar if not identical behaviour to the original function containing the necessary changes should be created alongside the existing deprecated function. + +When a build is made with the deprecation preprocessor symbols defined, a compiler warning will be generated to warn a user that the function will be removed at some point in the future, notifying users that they should change from the older deprecated function to the newer function at their own convenience. + +Therefore, no changes are permitted to the definition of functions in the public interface which will change the API. Instead the interface can only be changed by its extension. As described above, if a function needs to be changed, a new function needs to be created alongside it, with a new name, and whatever change is necessary, such as a new parameter or the addition of a return value. + +Periodically, the library will remove deprecated functions from the library which will be a breaking change in the API, but such changes will be made only in a planned, structured way that gives sufficient notice to users of the library. + +Long Term Support Branches +-------------------------- +Mbed TLS maintains several LTS (Long Term Support) branches, which are maintained continuously for a given period. The LTS branches are provided to allow users of the library to have a maintained, stable version of the library which contains only security fixes and fixes for other defects, without encountering additional features or API extensions which may introduce issues or change the code size or RAM usage, which can be significant considerations on some platforms. To allow users to take advantage of the LTS branches, these branches maintain backwards compatibility for both the public API and ABI. + +When backporting to these branches please observe the following rules: + + 1. Any change to the library which changes the API or ABI cannot be backported. + + 2. All bug fixes that correct a defect that is also present in an LTS branch must be backported to that LTS branch. If a bug fix introduces a change to the API such as a new function, the fix should be reworked to avoid the API change. API changes without very strong justification are unlikely to be accepted. + + 3. If a contribution is a new feature or enhancement, no backporting is required. Exceptions to this may be addtional test cases or quality improvements such as changes to build or test scripts. + +It would be highly appreciated if contributions are backported to LTS branches in addition to the [development branch](https://github.com/ARMmbed/mbedtls/tree/development) by contributors. + +Currently maintained LTS branches are: + +1. [mbedtls-2.7](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.7) + +1. [mbedtls-2.16](https://github.com/ARMmbed/mbedtls/tree/mbedtls-2.16) + + +Tests +----- +As mentioned, tests that show the correctness of the feature or bug fix should be added to the pull request, if no such tests exist. + +Mbed TLS includes a comprehensive set of test suites in the `tests/` directory that are dynamically generated to produce the actual test source files (e.g. `test_suite_mpi.c`). These files are generated from a `function file` (e.g. `suites/test_suite_mpi.function`) and a `data file` (e.g. `suites/test_suite_mpi.data`). The function file contains the test functions. The data file contains the test cases, specified as parameters that will be passed to the test function. + +[A Knowledge Base article describing how to add additional tests is available on the Mbed TLS website](https://tls.mbed.org/kb/development/test_suites). + +A test script `tests/scripts/basic-build-test.sh` is available to show test coverage of the library. New code contributions should provide a similar level of code coverage to that which already exists for the library. + +Sample applications, if needed, should be modified as well. + +Continuous Integration Tests +---------------------------- +Once a PR has been made, the Continuous Integration (CI) tests are triggered and run. You should follow the result of the CI tests, and fix failures. + +It is advised to enable the [githooks scripts](https://github.com/ARMmbed/mbedtls/tree/development/tests/git-scripts) prior to pushing your changes, for catching some of the issues as early as possible. + +Documentation +------------- +Mbed TLS is well documented, but if you think documentation is needed, speak out! + +1. All interfaces should be documented through Doxygen. New APIs should introduce Doxygen documentation. + +2. Complex parts in the code should include comments. + +3. If needed, a Readme file is advised. + +4. If a [Knowledge Base (KB)](https://tls.mbed.org/kb) article should be added, write this as a comment in the PR description. + +5. A [ChangeLog](https://github.com/ARMmbed/mbedtls/blob/development/ChangeLog) entry should be added for this contribution. + diff --git a/3rdparty/mbedtls/mbedtls/ChangeLog b/3rdparty/mbedtls/mbedtls/ChangeLog index 857cc4036a..8c1d03c0ba 100644 --- a/3rdparty/mbedtls/mbedtls/ChangeLog +++ b/3rdparty/mbedtls/mbedtls/ChangeLog @@ -1,6 +1,6 @@ mbed TLS ChangeLog (Sorted per branch, date) -= mbed TLS 2.7.11 branch released 2019-06-11 += mbed TLS 2.16.2 branch released 2019-06-11 Security * Make mbedtls_ecdh_get_params return an error if the second key @@ -23,6 +23,7 @@ Bugfix Christian Walther in #2239. * Fix potential memory leak in X.509 self test. Found and fixed by Junhwan Park, #2106. + * Reduce stack usage of hkdf tests. Fixes #2195. * Fix 1-byte buffer overflow in mbedtls_mpi_write_string() when used with negative inputs. Found by Guido Vranken in #2404. Credit to OSS-Fuzz. @@ -37,6 +38,9 @@ Bugfix for the parameter. * Add a check for MBEDTLS_X509_CRL_PARSE_C in ssl_server2, guarding the crl sni entry parameter. Reported by inestlerode in #560. + * Add DER-encoded test CRTs to library/certs.c, allowing + the example programs ssl_server2 and ssl_client2 to be run + if MBEDTLS_FS_IO and MBEDTLS_PEM_PARSE_C are unset. Fixes #2254. * Fix missing bounds checks in X.509 parsing functions that could lead to successful parsing of ill-formed X.509 CRTs. Fixes #2437. * Fix multiple X.509 functions previously returning ASN.1 low-level error @@ -52,12 +56,9 @@ Changes Contributed by Peter Kolbus (Garmin). * Change wording in the `mbedtls_ssl_conf_max_frag_len()`'s documentation to improve clarity. Fixes #2258. - * Improve debug output of ssl_client2 and ssl_server2 in case suitable - test CRTs are available because MBEDTLS_PEM_PARSE_C is disabled. - Fixes #2254. * Replace multiple uses of MD2 by SHA-256 in X.509 test suite. Fixes #821. -= mbed TLS 2.7.10 branch released 2019-03-19 += mbed TLS 2.16.1 branch released 2019-03-19 Features * Add MBEDTLS_REMOVE_3DES_CIPHERSUITES to allow removing 3DES ciphersuites @@ -65,12 +66,29 @@ Features https://sweet32.info/SWEET32_CCS16.pdf. Bugfix + * Fix a compilation issue with mbedtls_ecp_restart_ctx not being defined + when MBEDTLS_ECP_ALT is defined. Reported by jwhui. Fixes #2242. * Run the AD too long test only if MBEDTLS_CCM_ALT is not defined. Raised as a comment in #1996. - * Fix returning the value 1 when mbedtls_ecdsa_genkey failed. - * Remove a duplicate #include in a sample program. Fixed by Masashi Honma #2326. + * Reduce the stack consumption of mbedtls_mpi_fill_random() which could + previously lead to a stack overflow on constrained targets. + * Add `MBEDTLS_SELF_TEST` for the mbedtls_self_test functions + in the header files, which missed the precompilation check. #971 + * Fix clobber list in MIPS assembly for large integer multiplication. + Previously, this could lead to functionally incorrect assembly being + produced by some optimizing compilers, showing up as failures in + e.g. RSA or ECC signature operations. Reported in #1722, fix suggested + by Aurelien Jarno and submitted by Jeffrey Martin. + * Fix signed-to-unsigned integer conversion warning + in X.509 module. Fixes #2212. * Reduce stack usage of `mpi_write_hlp()` by eliminating recursion. Fixes #2190. + * Remove a duplicate #include in a sample program. Fixed by Masashi Honma #2326. + * Remove the mbedtls namespacing from the header file, to fix a "file not found" + build error. Fixed by Haijun Gu #2319. + * Fix returning the value 1 when mbedtls_ecdsa_genkey failed. + * Fix false failure in all.sh when backup files exist in include/mbedtls + (e.g. config.h.bak). Fixed by Peter Kolbus (Garmin) #2407. * Ensure that unused bits are zero when writing ASN.1 bitstrings when using mbedtls_asn1_write_bitstring(). * Fix issue when writing the named bitstrings in KeyUsage and NsCertType @@ -84,17 +102,53 @@ Changes Inserted as an enhancement for #1371 * Add support for alternative CSR headers, as used by Microsoft and defined in RFC 7468. Found by Michael Ernst. Fixes #767. - * Fix clobber list in MIPS assembly for large integer multiplication. - Previously, this could lead to functionally incorrect assembly being - produced by some optimizing compilers, showing up as failures in - e.g. RSA or ECC signature operations. Reported in #1722, fix suggested - by Aurelien Jarno and submitted by Jeffrey Martin. + * Fix configuration queries in ssl-opt.h. #2030 + * Ensure that ssl-opt.h can be run in OS X. #2029 * Reduce the complexity of the timing tests. They were assuming more than the underlying OS actually guarantees. + * Re-enable certain interoperability tests in ssl-opt.sh which had previously + been disabled for lack of a sufficiently recent version of GnuTLS on the CI. * Ciphersuites based on 3DES now have the lowest priority by default when they are enabled. -= mbed TLS 2.7.9 branch released 2018-12-21 += mbed TLS 2.16.0 branch released 2018-12-21 + +Features + * Add a new config.h option of MBEDTLS_CHECK_PARAMS that enables validation + of parameters in the API. This allows detection of obvious misuses of the + API, such as passing NULL pointers. The API of existing functions hasn't + changed, but requirements on parameters have been made more explicit in + the documentation. See the corresponding API documentation for each + function to see for which parameter values it is defined. This feature is + disabled by default. See its API documentation in config.h for additional + steps you have to take when enabling it. + +API Changes + * The following functions in the random generator modules have been + deprecated and replaced as shown below. The new functions change + the return type from void to int to allow returning error codes when + using MBEDTLS__ALT for the underlying AES or message digest + primitive. Fixes #1798. + mbedtls_ctr_drbg_update() -> mbedtls_ctr_drbg_update_ret() + mbedtls_hmac_drbg_update() -> mbedtls_hmac_drbg_update_ret() + * Extend ECDH interface to enable alternative implementations. + * Deprecate error codes of the form MBEDTLS_ERR_xxx_INVALID_KEY_LENGTH for + ARIA, CAMELLIA and Blowfish. These error codes will be replaced by + the more generic per-module error codes MBEDTLS_ERR_xxx_BAD_INPUT_DATA. + * Additional parameter validation checks have been added for the following + modules - AES, ARIA, Blowfish, CAMELLIA, CCM, GCM, DHM, ECP, ECDSA, ECDH, + ECJPAKE, SHA, Chacha20 and Poly1305, cipher, pk, RSA, and MPI. + Where modules have had parameter validation added, existing parameter + checks may have changed. Some modules, such as Chacha20 had existing + parameter validation whereas other modules had little. This has now been + changed so that the same level of validation is present in all modules, and + that it is now optional with the MBEDTLS_CHECK_PARAMS flag which by default + is off. That means that checks which were previously present by default + will no longer be. + +New deprecations + * Deprecate mbedtls_ctr_drbg_update and mbedtls_hmac_drbg_update + in favor of functions that can return an error code. Bugfix * Fix for Clang, which was reporting a warning for the bignum.c inline @@ -109,10 +163,12 @@ Bugfix * Add explicit integer to enumeration type casts to example program programs/pkey/gen_key which previously led to compilation failure on some toolchains. Reported by phoenixmcallister. Fixes #2170. + * Fix double initialization of ECC hardware that made some accelerators + hang. * Clarify documentation of mbedtls_ssl_set_own_cert() regarding the absence of check for certificate/key matching. Reported by Attila Molnar, #507. -= mbed TLS 2.7.8 branch released 2018-11-30 += mbed TLS 2.14.1 branch released 2018-11-30 Security * Fix timing variations and memory access variations in RSA PKCS#1 v1.5 @@ -141,7 +197,7 @@ API Changes report errors whereas the old functions return void. We recommend that applications use the new functions. -= mbed TLS 2.7.7 branch released 2018-11-19 += mbed TLS 2.14.0 branch released 2018-11-19 Security * Fix overly strict DN comparison when looking for CRLs belonging to a @@ -154,7 +210,7 @@ Security incoming message buffer was placed within the first 64KiB of address space and a PSK-(EC)DHE ciphersuite was used, this allowed an attacker to trigger a memory access up to 64KiB beyond the incoming message buffer, - potentially leading to application crash or information disclosure. + potentially leading to an application crash or information disclosure. * Fix mbedtls_mpi_is_prime() to use more rounds of probabilistic testing. The previous settings for the number of rounds made it practical for an adversary to construct non-primes that would be erroneously accepted as @@ -167,31 +223,79 @@ Security See "Prime and Prejudice" by by Martin R. Albrecht and Jake Massimo and Kenneth G. Paterson and Juraj Somorovsky. +Features + * Add support for temporarily suspending expensive ECC computations after + some configurable amount of operations. This is intended to be used in + constrained, single-threaded systems where ECC is time consuming and can + block other operations until they complete. This is disabled by default, + but can be enabled by MBEDTLS_ECP_RESTARTABLE at compile time and + configured by mbedtls_ecp_set_max_ops() at runtime. It applies to the new + xxx_restartable functions in ECP, ECDSA, PK and X.509 (CRL not supported + yet), and to existing functions in ECDH and SSL (currently only + implemented client-side, for ECDHE-ECDSA ciphersuites in TLS 1.2, + including client authentication). + * Add support for Arm CPU DSP extensions to accelerate asymmetric key + operations. On CPUs where the extensions are available, they can accelerate + MPI multiplications used in ECC and RSA cryptography. Contributed by + Aurelien Jarno. + * Extend RSASSA-PSS signature to allow a smaller salt size. Previously, PSS + signature always used a salt with the same length as the hash, and returned + an error if this was not possible. Now the salt size may be up to two bytes + shorter. This allows the library to support all hash and signature sizes + that comply with FIPS 186-4, including SHA-512 with a 1024-bit key. + * Add support for 128-bit keys in CTR_DRBG. Note that using keys shorter + than 256 bits limits the security of generated material to 128 bits. + +API Changes + * Add a common error code of `MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED` for + a feature that is not supported by underlying alternative + implementations implementing cryptographic primitives. This is useful for + hardware accelerators that don't implement all options or features. + +New deprecations + * All module specific errors following the form + MBEDTLS_ERR_XXX_FEATURE_UNAVAILABLE that indicate a feature is not + supported are deprecated and are now replaced by the new equivalent + platform error. + * All module specific generic hardware acceleration errors following the + form MBEDTLS_ERR_XXX_HW_ACCEL_FAILED that are deprecated and are replaced + by the equivalent plaform error. + * Deprecate the function mbedtls_mpi_is_prime() in favor of + mbedtls_mpi_is_prime_ext() which allows specifying the number of + Miller-Rabin rounds. + Bugfix - * Fix failure in hmac_drbg in the benchmark sample application, when - MBEDTLS_THREADING_C is defined. Found by TrinityTonic, #1095 - * Fix a bug in the update function for SSL ticket keys which previously - invalidated keys of a lifetime of less than a 1s. Fixes #1968. - * Fix a bug in the record decryption routine ssl_decrypt_buf() - which led to accepting properly authenticated but improperly - padded records in case of CBC ciphersuites using Encrypt-then-MAC. * Fix wrong order of freeing in programs/ssl/ssl_server2 example application leading to a memory leak in case both MBEDTLS_MEMORY_BUFFER_ALLOC_C and MBEDTLS_MEMORY_BACKTRACE are set. Fixes #2069. + * Fix a bug in the update function for SSL ticket keys which previously + invalidated keys of a lifetime of less than a 1s. Fixes #1968. + * Fix failure in hmac_drbg in the benchmark sample application, when + MBEDTLS_THREADING_C is defined. Found by TrinityTonic, #1095 + * Fix a bug in the record decryption routine ssl_decrypt_buf() + which lead to accepting properly authenticated but improperly + padded records in case of CBC ciphersuites using Encrypt-then-MAC. * Fix memory leak and freeing without initialization in the example program programs/x509/cert_write. Fixes #1422. * Ignore IV in mbedtls_cipher_set_iv() when the cipher mode is - MBEDTLS_MODE_ECB. Found by ezdevelop. Fixes for #1091. - * Zeroize memory used for reassembling handshake messages after use. - * Use `mbedtls_zeroize()` instead of `memset()` for zeroization of - sensitive data in the example programs aescrypt2 and crypt_and_hash. + MBEDTLS_MODE_ECB. Found by ezdevelop. Fixes #1091. + * Zeroize memory used for buffering or reassembling handshake messages + after use. + * Use `mbedtls_platform_zeroize()` instead of `memset()` for zeroization + of sensitive data in the example programs aescrypt2 and crypt_and_hash. + * Change the default string format used for various X.509 DN attributes to + UTF8String. Previously, the use of the PrintableString format led to + wildcards and non-ASCII characters being unusable in some DN attributes. + Reported by raprepo in #1860 and by kevinpt in #468. Fix contributed by + Thomas-Dee. * Fix compilation failure for configurations which use compile time replacements of standard calloc/free functions through the macros MBEDTLS_PLATFORM_CALLOC_MACRO and MBEDTLS_PLATFORM_FREE_MACRO. Reported by ole-de and ddhome2006. Fixes #882, #1642 and #1706. Changes + * Removed support for Yotta as a build tool. * Add tests for session resumption in DTLS. * Close a test gap in (D)TLS between the client side and the server side: test the handling of large packets and small packets on the client side @@ -201,10 +305,35 @@ Changes * Change the use of Windows threading to use Microsoft Visual C++ runtime calls, rather than Win32 API calls directly. This is necessary to avoid conflict with C runtime usage. Found and fixed by irwir. + * Remember the string format of X.509 DN attributes when replicating + X.509 DNs. Previously, DN attributes were always written in their default + string format (mostly PrintableString), which could lead to CRTs being + created which used PrintableStrings in the issuer field even though the + signing CA used UTF8Strings in its subject field; while X.509 compliant, + such CRTs were rejected in some applications, e.g. some versions of + Firefox, curl and GnuTLS. Reported in #1033 by Moschn. Fix contributed by + Thomas-Dee. * Improve documentation of mbedtls_ssl_get_verify_result(). Fixes #517 reported by github-monoculture. + * Add MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR flag to mbedtls_mpi_gen_prime() and + use it to reduce error probability in RSA key generation to levels mandated + by FIPS-186-4. + += mbed TLS 2.13.1 branch released 2018-09-06 -= mbed TLS 2.7.6 branch released 2018-08-31 +API Changes + * Extend the platform module with an abstraction mbedtls_platform_gmtime_r() + whose implementation should behave as a thread-safe version of gmtime(). + This allows users to configure such an implementation at compile time when + the target system cannot be deduced automatically, by setting the option + MBEDTLS_PLATFORM_GMTIME_R_ALT. At this stage Mbed TLS is only able to + automatically select implementations for Windows and POSIX C libraries. + +Bugfix + * Fix build failures on platforms where only gmtime() is available but + neither gmtime_r() nor gmtime_s() are present. Fixes #1907. + += mbed TLS 2.13.0 branch released 2018-08-31 Security * Fix an issue in the X.509 module which could lead to a buffer overread @@ -212,35 +341,66 @@ Security input (extensions length field equal to 0), an illegal read of one byte beyond the input buffer is made. Found and analyzed by Nathan Crandall. +Features + * Add support for fragmentation of outgoing DTLS handshake messages. This + is controlled by the maximum fragment length as set locally or negotiated + with the peer, as well as by a new per-connection MTU option, set using + mbedtls_ssl_set_mtu(). + * Add support for auto-adjustment of MTU to a safe value during the + handshake when flights do not get through (RFC 6347, section 4.1.1.1, + last paragraph). + * Add support for packing multiple records within a single datagram, + enabled by default. + * Add support for buffering out-of-order handshake messages in DTLS. + The maximum amount of RAM used for this can be controlled by the + compile-time constant MBEDTLS_SSL_DTLS_MAX_BUFFERING defined + in mbedtls/config.h. + +API Changes + * Add function mbedtls_ssl_set_datagram_packing() to configure + the use of datagram packing (enabled by default). + Bugfix * Fix a potential memory leak in mbedtls_ssl_setup() function. An allocation failure in the function could lead to other buffers being leaked. - * Fixes a missing test dependency on MBEDTLS_ARC4_C. #1890 + * Fixes an issue with MBEDTLS_CHACHAPOLY_C which would not compile if + MBEDTLS_ARC4_C and MBEDTLS_CIPHER_NULL_CIPHER weren't also defined. #1890 * Fix a memory leak in ecp_mul_comb() if ecp_precompute_comb() fails. Fix contributed by Espressif Systems. * Add ecc extensions only if an ecc based ciphersuite is used. This improves compliance to RFC 4492, and as a result, solves interoperability issues with BouncyCastle. Raised by milenamil in #1157. + * Replace printf with mbedtls_printf in the ARIA module. Found by + TrinityTonic in #1908. * Fix potential use-after-free in mbedtls_ssl_get_max_frag_len() and mbedtls_ssl_get_record_expansion() after a session reset. Fixes #1941. - * Fix a miscalculation of the maximum record expansion in - mbedtls_ssl_get_record_expansion() in case of CBC ciphersuites - in (D)TLS versions 1.1 or higher. Fixes #1914. * Fix a bug that caused SSL/TLS clients to incorrectly abort the handshake with TLS versions 1.1 and earlier when the server requested authentication without providing a list of CAs. This was due to an overly strict bounds - check in parsing the CertificateRequest message, introduced in - Mbed TLS 2.12.0. Fixes #1954. + check in parsing the CertificateRequest message, + introduced in Mbed TLS 2.12.0. Fixes #1954. + * Fix a miscalculation of the maximum record expansion in + mbedtls_ssl_get_record_expansion() in case of ChachaPoly ciphersuites, + or CBC ciphersuites in (D)TLS versions 1.1 or higher. Fixes #1913, #1914. * Fix undefined shifts with negative values in certificates parsing (found by Catena cyber using oss-fuzz) * Fix memory leak and free without initialization in pk_encrypt and pk_decrypt example programs. Reported by Brace Stout. Fixes #1128. + * Remove redundant else statement. Raised by irwir. Fixes #1776. Changes + * Copy headers preserving timestamps when doing a "make install". + Contributed by xueruini. + * Allow the forward declaration of public structs. Contributed by Dawid + Drozd. Fixes #1215 raised by randombit. * Improve compatibility with some alternative CCM implementations by using CCM test vectors from RAM. + * Add support for buffering of out-of-order handshake messages. + * Add warnings to the documentation of the HKDF module to reduce the risk + of misusing the mbedtls_hkdf_extract() and mbedtls_hkdf_expand() + functions. Fixes #1775. Reported by Brian J. Murray. -= mbed TLS 2.7.5 branch released 2018-07-25 += mbed TLS 2.12.0 branch released 2018-07-25 Security * Fix a vulnerability in TLS ciphersuites based on CBC and using SHA-384, @@ -275,23 +435,40 @@ Security Encrypt-then-Mac (RFC 7366) were not affected. Found by Kenny Paterson, Eyal Ronen and Adi Shamir. +Features + * Add new crypto primitives from RFC 7539: stream cipher Chacha20, one-time + authenticator Poly1305 and AEAD construct Chacha20-Poly1305. Contributed + by Daniel King. + * Add support for CHACHA20-POLY1305 ciphersuites from RFC 7905. + * Add platform support for the Haiku OS. (https://www.haiku-os.org). + Contributed by Augustin Cavalier. + * Make the receive and transmit buffers independent sizes, for situations + where the outgoing buffer can be fixed at a smaller size than the incoming + buffer, which can save some RAM. If buffer lengths are kept equal, there + is no functional difference. Contributed by Angus Gratton, and also + independently contributed again by Paul Sokolovsky. + * Add support for key wrapping modes based on AES as defined by + NIST SP 800-38F algorithms KW and KWP and by RFC 3394 and RFC 5649. + Bugfix + * Fix the key_app_writer example which was writing a leading zero byte which + was creating an invalid ASN.1 tag. Found by Aryeh R. Fixes #1257. * Fix compilation error on C++, because of a variable named new. Found and fixed by Hirotaka Niisato in #1783. - * Fix the inline assembly for the MPI multiply helper function for i386 and - i386 with SSE2. Found by LĆ”szlĆ³ LangĆ³. Fixes #1550 - * Fix a memory leak in mbedtls_x509_csr_parse(), found by catenacyber, - Philippe Antoine. Fixes #1623. + * Fix "no symbols" warning issued by ranlib when building on Mac OS X. Fix + contributed by tabascoeye. * Clarify documentation for mbedtls_ssl_write() to include 0 as a valid return value. Found by @davidwu2000. #839 - * Fix the key_app_writer example which was writing a leading zero byte which - was creating an invalid ASN.1 tag. Found by Aryeh R. Fixes #1257. + * Fix a memory leak in mbedtls_x509_csr_parse(), found by catenacyber, + Philippe Antoine. Fixes #1623. * Remove unused headers included in x509.c. Found by Chris Hanson and fixed by Brendan Shanks. Part of a fix for #992. * Fix compilation error when MBEDTLS_ARC4_C is disabled and MBEDTLS_CIPHER_NULL_CIPHER is enabled. Found by TrinityTonic in #1719. * Added length checks to some TLS parsing functions. Found and fixed by Philippe Antoine from Catena cyber. #1663. + * Fix the inline assembly for the MPI multiply helper function for i386 and + i386 with SSE2. Found by LĆ”szlĆ³ LangĆ³. Fixes #1550 * Fix namespacing in header files. Remove the `mbedtls` namespacing in the `#include` in the header files. Resolves #857 * Fix compiler warning of 'use before initialisation' in @@ -308,34 +485,76 @@ Bugfix Fixes #1833. * Correct the documentation for `mbedtls_ssl_get_session()`. This API has deep copy of the session, and the peer certificate is not lost. Fixes #926. + * Fix build using -std=c99. Fixed by Nick Wilson. Changes * Fail when receiving a TLS alert message with an invalid length, or invalid zero-length messages when using TLS 1.2. Contributed by Espressif Systems. + * Change the default behaviour of mbedtls_hkdf_extract() to return an error + when calling with a NULL salt and non-zero salt_len. Contributed by + Brian J Murray * Change the shebang line in Perl scripts to look up perl in the PATH. - Contributed by fbrosson in #1533. + Contributed by fbrosson. + * Allow overriding the time on Windows via the platform-time abstraction. + Fixed by Nick Wilson. + * Use gmtime_r/gmtime_s for thread-safety. Fixed by Nick Wilson. + += mbed TLS 2.11.0 branch released 2018-06-18 -= mbed TLS 2.7.4 branch released 2018-06-18 +Features + * Add additional block mode, OFB (Output Feedback), to the AES module and + cipher abstraction module. + * Implement the HMAC-based extract-and-expand key derivation function + (HKDF) per RFC 5869. Contributed by Thomas Fossati. + * Add support for the CCM* block cipher mode as defined in IEEE Std. 802.15.4. + * Add support for the XTS block cipher mode with AES (AES-XTS). + Contributed by Aorimn in pull request #414. + * In TLS servers, support offloading private key operations to an external + cryptoprocessor. Private key operations can be asynchronous to allow + non-blocking operation of the TLS server stack. Bugfix - * Fix redundant declaration of mbedtls_ssl_list_ciphersuites. Raised by - TrinityTonic. #1359. + * Fix the cert_write example to handle certificates signed with elliptic + curves as well as RSA. Fixes #777 found by dbedev. * Fix for redefinition of _WIN32_WINNT to avoid overriding a definition used by user applications. Found and fixed by Fabio Alessandrelli. - * Fix braces in mbedtls_memory_buffer_alloc_status(). Found by sbranden, #552. - * Fix an issue with MicroBlaze support in bn_mul.h which was causing the - build to fail. Found by zv-io. Fixes #1651. * Fix compilation warnings with IAR toolchain, on 32 bit platform. Reported by rahmanih in #683 + * Fix braces in mbedtls_memory_buffer_alloc_status(). Found by sbranden, #552. Changes - * Support TLS testing in out-of-source builds using cmake. Fixes #1193. * Changed CMake defaults for IAR to treat all compiler warnings as errors. * Changed the Clang parameters used in the CMake build files to work for versions later than 3.6. Versions of Clang earlier than this may no longer work. Fixes #1072 -= mbed TLS 2.7.3 branch released 2018-04-30 += mbed TLS 2.10.0 branch released 2018-06-06 + +Features + * Add support for ARIA cipher (RFC 5794) and associated TLS ciphersuites + (RFC 6209). Disabled by default, see MBEDTLS_ARIA_C in config.h + +API Changes + * Extend the platform module with a util component that contains + functionality shared by multiple Mbed TLS modules. At this stage + platform_util.h (and its associated platform_util.c) only contain + mbedtls_platform_zeroize(), which is a critical function from a security + point of view. mbedtls_platform_zeroize() needs to be regularly tested + against compilers to ensure that calls to it are not removed from the + output binary as part of redundant code elimination optimizations. + Therefore, mbedtls_platform_zeroize() is moved to the platform module to + facilitate testing and maintenance. + +Bugfix + * Fix an issue with MicroBlaze support in bn_mul.h which was causing the + build to fail. Found by zv-io. Fixes #1651. + +Changes + * Support TLS testing in out-of-source builds using cmake. Fixes #1193. + * Fix redundant declaration of mbedtls_ssl_list_ciphersuites. Raised by + TrinityTonic. #1359. + += mbed TLS 2.9.0 branch released 2018-04-30 Security * Fix an issue in the X.509 module which could lead to a buffer overread @@ -357,6 +576,25 @@ Security chosen by the server. This could lead to corruption of internal data structures for some configurations. +Features + * Add an option, MBEDTLS_AES_FEWER_TABLES, to dynamically compute smaller AES + tables during runtime, thereby reducing the RAM/ROM footprint by ~6KiB. + Suggested and contributed by jkivilin in pull request #394. + * Add initial support for Curve448 (RFC 7748). Only mbedtls_ecp_mul() and + ECDH primitive functions (mbedtls_ecdh_gen_public(), + mbedtls_ecdh_compute_shared()) are supported for now. Contributed by + Nicholas Wilson in pull request #348. + +API Changes + * Extend the public API with the function of mbedtls_net_poll() to allow user + applications to wait for a network context to become ready before reading + or writing. + * Add function mbedtls_ssl_check_pending() to the public API to allow + a check for whether more more data is pending to be processed in the + internal message buffers. + This function is necessary to determine when it is safe to idle on the + underlying transport in case event-driven IO is used. + Bugfix * Fix a spurious uninitialized variable warning in cmac.c. Fix independently contributed by Brian J Murray and David Brown. @@ -378,13 +616,25 @@ Bugfix Andy Leiserson. * Fix overriding and ignoring return values when parsing and writing to a file in pk_sign program. Found by kevlut in #1142. + * Restrict usage of error code MBEDTLS_ERR_SSL_WANT_READ to situations + where data needs to be fetched from the underlying transport in order + to make progress. Previously, this error code was also occasionally + returned when unexpected messages were being discarded, ignoring that + further messages could potentially already be pending to be processed + in the internal buffers; these cases led to deadlocks when event-driven + I/O was used. Found and reported by Hubert Mis in #772. * Fix buffer length assertions in the ssl_parse_certificate_request() function which leads to a potential one byte overread of the message buffer. * Fix invalid buffer sizes passed to zlib during record compression and decompression. + * Fix the soversion of libmbedcrypto to match the soversion of the + maintained 2.7 branch. The soversion was increased in Mbed TLS + version 2.7.1 to reflect breaking changes in that release, but the + increment was missed in 2.8.0 and later releases outside of the 2.7 branch. Changes + * Remove some redundant code in bignum.c. Contributed by Alexey Skalozub. * Support cmake builds where Mbed TLS is a subproject. Fix contributed independently by Matthieu Volat and Arne Schwabe. * Improve testing in configurations that omit certain hashes or @@ -393,9 +643,16 @@ Changes * Do not define global mutexes around readdir() and gmtime() in configurations where the feature is disabled. Found and fixed by Gergely Budai. + * Harden the function mbedtls_ssl_config_free() against misuse, so that it + doesn't leak memory if the user doesn't use mbedtls_ssl_conf_psk() and + instead incorrectly manipulates the configuration structure directly. + Found and fix submitted by junyeonLEE in #1220. * Provide an empty implementation of mbedtls_pkcs5_pbes2() when MBEDTLS_ASN1_PARSE_C is not enabled. This allows the use of PBKDF2 without PBES2. Fixed by Marcos Del Sol Vives. + * Add the order of the base point as N in the mbedtls_ecp_group structure + for Curve25519 (other curves had it already). Contributed by Nicholas + Wilson #481 * Improve the documentation of mbedtls_net_accept(). Contributed by Ivan Krylov. * Improve the documentation of mbedtls_ssl_write(). Suggested by @@ -405,16 +662,40 @@ Changes Alex Hixon. * Allow configuring the shared library extension by setting the DLEXT environment variable when using the project makefiles. + * Optimize unnecessary zeroing in mbedtls_mpi_copy. Based on a contribution + by Alexey Skalozub in #405. * In the SSL module, when f_send, f_recv or f_recv_timeout report transmitting more than the required length, return an error. Raised by Sam O'Connor in #1245. * Improve robustness of mbedtls_ssl_derive_keys against the use of HMAC functions with non-HMAC ciphersuites. Independently contributed by Jiayuan Chen in #1377. Fixes #1437. + * Improve security of RSA key generation by including criteria from + FIPS 186-4. Contributed by Jethro Beekman. #1380 + * Declare functions in header files even when an alternative implementation + of the corresponding module is activated by defining the corresponding + MBEDTLS_XXX_ALT macro. This means that alternative implementations do + not need to copy the declarations, and ensures that they will have the + same API. + * Add platform setup and teardown calls in test suites. + += mbed TLS 2.8.0 branch released 2018-03-16 -= mbed TLS 2.7.2 branch released 2018-03-16 +Default behavior changes + * The truncated HMAC extension now conforms to RFC 6066. This means + that when both sides of a TLS connection negotiate the truncated + HMAC extension, Mbed TLS can now interoperate with other + compliant implementations, but this breaks interoperability with + prior versions of Mbed TLS. To restore the old behavior, enable + the (deprecated) option MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT in + config.h. Found by Andreas Walz (ivESK, Offenburg University of + Applied Sciences). Security + * Fix implementation of the truncated HMAC extension. The previous + implementation allowed an offline 2^80 brute force attack on the + HMAC key of a single, uninterrupted connection (with no + resumption of the session). * Verify results of RSA private key operations to defend against Bellcore glitch attack. * Fix a buffer overread in ssl_parse_server_key_exchange() that could cause @@ -430,8 +711,21 @@ Features This allows reading encrypted PEM files produced by software that uses PBKDF2-SHA2, such as OpenSSL 1.1. Submitted by Antonio Quartulli, OpenVPN Inc. Fixes #1339 + * Add support for public keys encoded in PKCS#1 format. #1122 + +New deprecations + * Deprecate support for record compression (configuration option + MBEDTLS_ZLIB_SUPPORT). Bugfix + * Fix the name of a DHE parameter that was accidentally changed in 2.7.0. + Fixes #1358. + * Fix test_suite_pk to work on 64-bit ILP32 systems. #849 + * Fix mbedtls_x509_crt_profile_suiteb, which used to reject all certificates + with flag MBEDTLS_X509_BADCERT_BAD_PK even when the key type was correct. + In the context of SSL, this resulted in handshake failure. Reported by + daniel in the Mbed TLS forum. #1351 + * Fix Windows x64 builds with the included mbedTLS.sln file. #1347 * Fix setting version TLSv1 as minimal version, even if TLS 1 is not enabled. Set MBEDTLS_SSL_MIN_MAJOR_VERSION and MBEDTLS_SSL_MIN_MINOR_VERSION instead of @@ -455,43 +749,16 @@ Bugfix * Fix a 1-byte heap buffer overflow (read-only) during private key parsing. Found through fuzz testing. -Changes - * Clarify the documentation of mbedtls_ssl_setup. - -= mbed TLS 2.7.1 branch released 2018-02-23 - -Default behavior changes - * The truncated HMAC extension now conforms to RFC 6066. This means - that when both sides of a TLS connection negotiate the truncated - HMAC extension, Mbed TLS can now interoperate with other - compliant implementations, but this breaks interoperability with - prior versions of Mbed TLS. To restore the old behavior, enable - the (deprecated) option MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT in - config.h. Found by Andreas Walz (ivESK, Offenburg University of - Applied Sciences). - -Security - * Fix implementation of the truncated HMAC extension. The previous - implementation allowed an offline 2^80 brute force attack on the - HMAC key of a single, uninterrupted connection (with no - resumption of the session). - -Bugfix - * Fix the name of a DHE parameter that was accidentally changed in 2.7.0. - Fixes #1358. - * Fix test_suite_pk to work on 64-bit ILP32 systems. #849 - * Fix mbedtls_x509_crt_profile_suiteb, which used to reject all certificates - with flag MBEDTLS_X509_BADCERT_BAD_PK even when the key type was correct. - In the context of SSL, this resulted in handshake failure. Reported by - daniel in the Mbed TLS forum. #1351 - * Fix Windows x64 builds with the included mbedTLS.sln file. #1347 - Changes * Fix tag lengths and value ranges in the documentation of CCM encryption. Contributed by Mathieu Briand. * Fix typo in a comment ctr_drbg.c. Contributed by Paul Sokolovsky. + * Remove support for the library reference configuration for picocoin. * MD functions deprecated in 2.7.0 are no longer inline, to provide a migration path for those depending on the library's ABI. + * Clarify the documentation of mbedtls_ssl_setup. + * Use (void) when defining functions with no parameters. Contributed by + Joris Aerts. #678 = mbed TLS 2.7.0 branch released 2018-02-03 @@ -608,7 +875,7 @@ Bugfix * Fix ssl_parse_record_header() to silently discard invalid DTLS records as recommended in RFC 6347 Section 4.1.2.7. * Fix memory leak in mbedtls_ssl_set_hostname() when called multiple times. - Found by projectgus and jethrogb, #836. + Found by projectgus and Jethro Beekman, #836. * Fix usage help in ssl_server2 example. Found and fixed by Bei Lin. * Parse signature algorithm extension when renegotiating. Previously, renegotiated handshakes would only accept signatures using SHA-1 @@ -802,8 +1069,7 @@ Bugfix Previous behaviour was to keep processing data even after the alert has been sent. * Accept empty trusted CA chain in authentication mode - MBEDTLS_SSL_VERIFY_OPTIONAL. - Found by jethrogb. #864 + MBEDTLS_SSL_VERIFY_OPTIONAL. Found by Jethro Beekman. #864 * Fix implementation of mbedtls_ssl_parse_certificate() to not annihilate fatal errors in authentication mode MBEDTLS_SSL_VERIFY_OPTIONAL and to reflect bad EC curves within verification result. diff --git a/3rdparty/mbedtls/mbedtls/Makefile b/3rdparty/mbedtls/mbedtls/Makefile index 6014597a97..1ae6bd9917 100644 --- a/3rdparty/mbedtls/mbedtls/Makefile +++ b/3rdparty/mbedtls/mbedtls/Makefile @@ -23,7 +23,7 @@ tests: lib ifndef WINDOWS install: no_test mkdir -p $(DESTDIR)/include/mbedtls - cp -r include/mbedtls $(DESTDIR)/include + cp -rp include/mbedtls $(DESTDIR)/include mkdir -p $(DESTDIR)/lib cp -RP library/libmbedtls.* $(DESTDIR)/lib @@ -61,9 +61,21 @@ NULL_ENTROPY_WARN_L3=**** AND IS *NOT* SUITABLE FOR PRODUCTION USE ****\n NULL_ENTROPY_WARNING=\n$(WARNING_BORDER)$(NULL_ENTROPY_WARN_L1)$(NULL_ENTROPY_WARN_L2)$(NULL_ENTROPY_WARN_L3)$(WARNING_BORDER) +WARNING_BORDER_LONG =**********************************************************************************\n +CTR_DRBG_128_BIT_KEY_WARN_L1=**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined! ****\n +CTR_DRBG_128_BIT_KEY_WARN_L2=**** Using 128-bit keys for CTR_DRBG limits the security of generated ****\n +CTR_DRBG_128_BIT_KEY_WARN_L3=**** keys and operations that use random values generated to 128-bit security ****\n + +CTR_DRBG_128_BIT_KEY_WARNING=\n$(WARNING_BORDER_LONG)$(CTR_DRBG_128_BIT_KEY_WARN_L1)$(CTR_DRBG_128_BIT_KEY_WARN_L2)$(CTR_DRBG_128_BIT_KEY_WARN_L3)$(WARNING_BORDER_LONG) + # Post build steps post_build: ifndef WINDOWS + + # If 128-bit keys are configured for CTR_DRBG, display an appropriate warning + -scripts/config.pl get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY && ([ $$? -eq 0 ]) && \ + echo '$(CTR_DRBG_128_BIT_KEY_WARNING)' + # If NULL Entropy is configured, display an appropriate warning -scripts/config.pl get MBEDTLS_TEST_NULL_ENTROPY && ([ $$? -eq 0 ]) && \ echo '$(NULL_ENTROPY_WARNING)' diff --git a/3rdparty/mbedtls/mbedtls/README.md b/3rdparty/mbedtls/mbedtls/README.md index ced36e1921..94ea84b9d5 100644 --- a/3rdparty/mbedtls/mbedtls/README.md +++ b/3rdparty/mbedtls/mbedtls/README.md @@ -11,47 +11,16 @@ Compiler options can be set using conventional environment variables such as `CC Compiling --------- -There are currently four active build systems used within Mbed TLS releases: +There are currently three active build systems used within Mbed TLS releases: -- yotta - GNU Make - CMake - Microsoft Visual Studio (Microsoft Visual Studio 2010 or later) The main systems used for development are CMake and GNU Make. Those systems are always complete and up-to-date. The others should reflect all changes present in the CMake and Make build system, although features may not be ported there automatically. -Yotta, as a build system, is slightly different from the other build systems: - -- it provides a minimalistic configuration file by default -- depending on the yotta target, features of Mbed OS may be used in examples and tests - The Make and CMake build systems create three libraries: libmbedcrypto, libmbedx509, and libmbedtls. Note that libmbedtls depends on libmbedx509 and libmbedcrypto, and libmbedx509 depends on libmbedcrypto. As a result, some linkers will expect flags to be in a specific order, for example the GNU linker wants `-lmbedtls -lmbedx509 -lmbedcrypto`. Also, when loading shared libraries using dlopen(), you'll need to load libmbedcrypto first, then libmbedx509, before you can load libmbedtls. -### Yotta - -[yotta](http://yottabuild.org) is a package manager and build system developed by Mbed, and is the build system of Mbed OS 16.03. To install it on your platform, please follow the yotta [installation instructions](http://docs.yottabuild.org/#installing). - -Once yotta is installed, you can use it to download the latest version of Mbed TLS from the yotta registry with: - - yotta install mbedtls - -and build it with: - - yotta build - -If, on the other hand, you already have a copy of Mbed TLS from a source other than the yotta registry, for example from cloning our GitHub repository, or from downloading a tarball of the standalone edition, then you'll first need to generate the yotta module by running: - - yotta/create-module.sh - -This should be executed from the root Mbed TLS project directory. This will create the yotta module in the `yotta/module` directory within it. You can then change to that directory and build as usual: - - cd yotta/module - yotta build - -In any case, you'll probably want to set the yotta target before building unless it has already been set globally. For more information on using yotta, please consult the [yotta documentation](http://docs.yottabuild.org/). - -For more details on the yotta/Mbed OS edition of Mbed TLS, including example programs, please consult the [Readme at the root of the yotta module](https://github.com/ARMmbed/mbedtls/blob/development/yotta/data/README.md). - ### Make We require GNU Make. To build the library and the sample programs, GNU Make and a C compiler are sufficient. Some of the more advanced build targets require some Unix/Linux tools. @@ -66,7 +35,7 @@ In order to run the tests, enter: make check -The tests need Perl to be built and run. If you don't have Perl installed, you can skip building the tests with: +The tests need Python to be built and Perl to be run. If you don't have one of them installed, you can skip building the tests with: make no_test @@ -78,11 +47,11 @@ In order to build for a Windows platform, you should use `WINDOWS_BUILD=1` if th Setting the variable `SHARED` in your environment will build shared libraries in addition to the static libraries. Setting `DEBUG` gives you a debug build. You can override `CFLAGS` and `LDFLAGS` by setting them in your environment or on the make command line; compiler warning options may be overridden separately using `WARNING_CFLAGS`. Some directory-specific options (for example, `-I` directives) are still preserved. -Please note that setting `CFLAGS` overrides its default value of `-O2` and setting `WARNING_CFLAGS` overrides its default value (starting with `-Wall -W`), so it you just want to add some warning options to the default ones, you can do so by setting `CFLAGS=-O2 -Werror` for example. Setting `WARNING_CFLAGS` is useful when you want to get rid of its default content (for example because your compiler doesn't accept `-Wall` as an option). Directory-specific options cannot be overriden from the command line. +Please note that setting `CFLAGS` overrides its default value of `-O2` and setting `WARNING_CFLAGS` overrides its default value (starting with `-Wall -W`), so if you just want to add some warning options to the default ones, you can do so by setting `CFLAGS=-O2 -Werror` for example. Setting `WARNING_CFLAGS` is useful when you want to get rid of its default content (for example because your compiler doesn't accept `-Wall` as an option). Directory-specific options cannot be overriden from the command line. Depending on your platform, you might run into some issues. Please check the Makefiles in `library/`, `programs/` and `tests/` for options to manually add or remove for specific platforms. You can also check [the Mbed TLS Knowledge Base](https://tls.mbed.org/kb) for articles on your platform or issue. -In case you find that you need to do something else as well, please let us know what, so we can add it to the [Mbed TLS knowledge base](https://tls.mbed.org/kb). +In case you find that you need to do something else as well, please let us know what, so we can add it to the [Mbed TLS Knowledge Base](https://tls.mbed.org/kb). ### CMake @@ -96,7 +65,7 @@ In order to run the tests, enter: make test -The test suites need Perl to be built. If you don't have Perl installed, you'll want to disable the test suites with: +The test suites need Python to be built and Perl to be executed. If you don't have one of these installed, you'll want to disable the test suites with: cmake -DENABLE_TESTING=Off /path/to/mbedtls_source @@ -164,17 +133,17 @@ on the build mode as seen above), it's merely prepended to it. The build files for Microsoft Visual Studio are generated for Visual Studio 2010. -The solution file `mbedTLS.sln` contains all the basic projects needed to build the library and all the programs. The files in tests are not generated and compiled, as these need a perl environment as well. However, the selftest program in `programs/test/` is still available. +The solution file `mbedTLS.sln` contains all the basic projects needed to build the library and all the programs. The files in tests are not generated and compiled, as these need Python and perl environments as well. However, the selftest program in `programs/test/` is still available. Example programs ---------------- -We've included example programs for a lot of different features and uses in `programs/`. Most programs only focus on a single feature or usage scenario, so keep that in mind when copying parts of the code. +We've included example programs for a lot of different features and uses in [`programs/`](programs/README.md). Most programs only focus on a single feature or usage scenario, so keep that in mind when copying parts of the code. Tests ----- -Mbed TLS includes an elaborate test suite in `tests/` that initially requires Perl to generate the tests files (e.g. `test\_suite\_mpi.c`). These files are generated from a `function file` (e.g. `suites/test\_suite\_mpi.function`) and a `data file` (e.g. `suites/test\_suite\_mpi.data`). The `function file` contains the test functions. The `data file` contains the test cases, specified as parameters that will be passed to the test function. +Mbed TLS includes an elaborate test suite in `tests/` that initially requires Python to generate the tests files (e.g. `test\_suite\_mpi.c`). These files are generated from a `function file` (e.g. `suites/test\_suite\_mpi.function`) and a `data file` (e.g. `suites/test\_suite\_mpi.data`). The `function file` contains the test functions. The `data file` contains the test cases, specified as parameters that will be passed to the test function. For machines with a Unix shell and OpenSSL (and optionally GnuTLS) installed, additional test scripts are available: @@ -192,7 +161,7 @@ We provide some non-standard configurations focused on specific use cases in the Porting Mbed TLS ---------------- -Mbed TLS can be ported to many different architectures, OS's and platforms. Before starting a port, you may find the following knowledge base articles useful: +Mbed TLS can be ported to many different architectures, OS's and platforms. Before starting a port, you may find the following Knowledge Base articles useful: - [Porting Mbed TLS to a new environment or OS](https://tls.mbed.org/kb/how-to/how-do-i-port-mbed-tls-to-a-new-environment-OS) - [What external dependencies does Mbed TLS rely on?](https://tls.mbed.org/kb/development/what-external-dependencies-does-mbedtls-rely-on) diff --git a/3rdparty/mbedtls/mbedtls/configs/config-ccm-psk-tls1_2.h b/3rdparty/mbedtls/mbedtls/configs/config-ccm-psk-tls1_2.h index a783e6b73b..c9b58dd538 100644 --- a/3rdparty/mbedtls/mbedtls/configs/config-ccm-psk-tls1_2.h +++ b/3rdparty/mbedtls/mbedtls/configs/config-ccm-psk-tls1_2.h @@ -81,7 +81,7 @@ * both ends of the connection! (See comments in "mbedtls/ssl.h".) * The optimal size here depends on the typical size of records. */ -#define MBEDTLS_SSL_MAX_CONTENT_LEN 512 +#define MBEDTLS_SSL_MAX_CONTENT_LEN 1024 #include "mbedtls/check_config.h" diff --git a/3rdparty/mbedtls/mbedtls/configs/config-no-entropy.h b/3rdparty/mbedtls/mbedtls/configs/config-no-entropy.h index b4a0930b9c..7d34ad52ec 100644 --- a/3rdparty/mbedtls/mbedtls/configs/config-no-entropy.h +++ b/3rdparty/mbedtls/mbedtls/configs/config-no-entropy.h @@ -82,6 +82,7 @@ #define MBEDTLS_X509_USE_C #define MBEDTLS_X509_CRT_PARSE_C #define MBEDTLS_X509_CRL_PARSE_C +//#define MBEDTLS_CMAC_C /* Miscellaneous options */ #define MBEDTLS_AES_ROM_TABLES diff --git a/3rdparty/mbedtls/mbedtls/configs/config-picocoin.h b/3rdparty/mbedtls/mbedtls/configs/config-picocoin.h deleted file mode 100644 index 5d41f282f1..0000000000 --- a/3rdparty/mbedtls/mbedtls/configs/config-picocoin.h +++ /dev/null @@ -1,74 +0,0 @@ -/** - * \file config-picocoin.h - * - * \brief Reduced configuration used by Picocoin. - */ -/* - * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * This file is part of mbed TLS (https://tls.mbed.org) - */ -/* - * Reduced configuration used by Picocoin. - * - * See README.txt for usage instructions. - * - * Distinguishing features: - * - no SSL/TLS; - * - no X.509; - * - ECDSA/PK and some other chosen crypto bits. - */ - -#ifndef MBEDTLS_CONFIG_H -#define MBEDTLS_CONFIG_H - -/* System support */ -#define MBEDTLS_HAVE_ASM -#define MBEDTLS_HAVE_TIME - -/* mbed TLS feature support */ -#define MBEDTLS_CIPHER_MODE_CBC -#define MBEDTLS_CIPHER_PADDING_PKCS7 -#define MBEDTLS_ECP_DP_SECP256K1_ENABLED -#define MBEDTLS_ECDSA_DETERMINISTIC -#define MBEDTLS_PK_PARSE_EC_EXTENDED -#define MBEDTLS_ERROR_STRERROR_DUMMY -#define MBEDTLS_FS_IO - -/* mbed TLS modules */ -#define MBEDTLS_AESNI_C -#define MBEDTLS_AES_C -#define MBEDTLS_ASN1_PARSE_C -#define MBEDTLS_ASN1_WRITE_C -#define MBEDTLS_BASE64_C -#define MBEDTLS_BIGNUM_C -#define MBEDTLS_ECDSA_C -#define MBEDTLS_ECP_C -#define MBEDTLS_ENTROPY_C -#define MBEDTLS_HMAC_DRBG_C -#define MBEDTLS_MD_C -#define MBEDTLS_OID_C -#define MBEDTLS_PADLOCK_C -#define MBEDTLS_PK_C -#define MBEDTLS_PK_PARSE_C -#define MBEDTLS_PK_WRITE_C -#define MBEDTLS_RIPEMD160_C -#define MBEDTLS_SHA1_C -#define MBEDTLS_SHA256_C - -#include "mbedtls/check_config.h" - -#endif /* MBEDTLS_CONFIG_H */ diff --git a/3rdparty/mbedtls/mbedtls/doxygen/input/doc_mainpage.h b/3rdparty/mbedtls/mbedtls/doxygen/input/doc_mainpage.h index bb5987137c..3336f0fcaa 100644 --- a/3rdparty/mbedtls/mbedtls/doxygen/input/doc_mainpage.h +++ b/3rdparty/mbedtls/mbedtls/doxygen/input/doc_mainpage.h @@ -24,7 +24,7 @@ */ /** - * @mainpage mbed TLS v2.7.11 source code documentation + * @mainpage mbed TLS v2.16.2 source code documentation * * This documentation describes the internal structure of mbed TLS. It was * automatically generated from specially formatted comment blocks in diff --git a/3rdparty/mbedtls/mbedtls/doxygen/mbedtls.doxyfile b/3rdparty/mbedtls/mbedtls/doxygen/mbedtls.doxyfile index 22ae878ee8..40a1cabb33 100644 --- a/3rdparty/mbedtls/mbedtls/doxygen/mbedtls.doxyfile +++ b/3rdparty/mbedtls/mbedtls/doxygen/mbedtls.doxyfile @@ -28,7 +28,7 @@ DOXYFILE_ENCODING = UTF-8 # identify the project. Note that if you do not use Doxywizard you need # to put quotes around the project name if it contains spaces. -PROJECT_NAME = "mbed TLS v2.7.11" +PROJECT_NAME = "mbed TLS v2.16.2" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/aes.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/aes.h index 46016dcb7f..94e7282d36 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/aes.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/aes.h @@ -1,7 +1,9 @@ /** * \file aes.h * - * \brief The Advanced Encryption Standard (AES) specifies a FIPS-approved + * \brief This file contains AES definitions and functions. + * + * The Advanced Encryption Standard (AES) specifies a FIPS-approved * cryptographic algorithm that can be used to protect electronic * data. * @@ -11,7 +13,13 @@ * ISO/IEC 18033-2:2006: Information technology -- Security * techniques -- Encryption algorithms -- Part 2: Asymmetric * ciphers. + * + * The AES-XTS block mode is standardized by NIST SP 800-38E + * + * and described in detail by IEEE P1619 + * . */ + /* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 * @@ -50,8 +58,13 @@ #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */ #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */ -/* Error codes in range 0x0023-0x0025 */ +/* Error codes in range 0x0021-0x0025 */ +#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */ + +/* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */ #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */ + +/* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */ #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ @@ -59,18 +72,18 @@ #define inline __inline #endif -#if !defined(MBEDTLS_AES_ALT) -// Regular implementation -// - #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_AES_ALT) +// Regular implementation +// + /** * \brief The AES context-type definition. */ -typedef struct +typedef struct mbedtls_aes_context { int nr; /*!< The number of rounds. */ uint32_t *rk; /*!< AES round keys. */ @@ -85,13 +98,30 @@ typedef struct } mbedtls_aes_context; +#if defined(MBEDTLS_CIPHER_MODE_XTS) +/** + * \brief The AES XTS context-type definition. + */ +typedef struct mbedtls_aes_xts_context +{ + mbedtls_aes_context crypt; /*!< The AES context to use for AES block + encryption or decryption. */ + mbedtls_aes_context tweak; /*!< The AES context used for tweak + computation. */ +} mbedtls_aes_xts_context; +#endif /* MBEDTLS_CIPHER_MODE_XTS */ + +#else /* MBEDTLS_AES_ALT */ +#include "aes_alt.h" +#endif /* MBEDTLS_AES_ALT */ + /** * \brief This function initializes the specified AES context. * * It must be the first API called before using * the context. * - * \param ctx The AES context to initialize. + * \param ctx The AES context to initialize. This must not be \c NULL. */ void mbedtls_aes_init( mbedtls_aes_context *ctx ); @@ -99,21 +129,46 @@ void mbedtls_aes_init( mbedtls_aes_context *ctx ); * \brief This function releases and clears the specified AES context. * * \param ctx The AES context to clear. + * If this is \c NULL, this function does nothing. + * Otherwise, the context must have been at least initialized. */ void mbedtls_aes_free( mbedtls_aes_context *ctx ); +#if defined(MBEDTLS_CIPHER_MODE_XTS) +/** + * \brief This function initializes the specified AES XTS context. + * + * It must be the first API called before using + * the context. + * + * \param ctx The AES XTS context to initialize. This must not be \c NULL. + */ +void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx ); + +/** + * \brief This function releases and clears the specified AES XTS context. + * + * \param ctx The AES XTS context to clear. + * If this is \c NULL, this function does nothing. + * Otherwise, the context must have been at least initialized. + */ +void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx ); +#endif /* MBEDTLS_CIPHER_MODE_XTS */ + /** * \brief This function sets the encryption key. * * \param ctx The AES context to which the key should be bound. + * It must be initialized. * \param key The encryption key. + * This must be a readable buffer of size \p keybits bits. * \param keybits The size of data passed in bits. Valid options are: *
  • 128 bits
  • *
  • 192 bits
  • *
  • 256 bits
* - * \return \c 0 on success or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH - * on failure. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. */ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits ); @@ -122,17 +177,62 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, * \brief This function sets the decryption key. * * \param ctx The AES context to which the key should be bound. + * It must be initialized. * \param key The decryption key. + * This must be a readable buffer of size \p keybits bits. * \param keybits The size of data passed. Valid options are: *
  • 128 bits
  • *
  • 192 bits
  • *
  • 256 bits
* - * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. */ int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits ); +#if defined(MBEDTLS_CIPHER_MODE_XTS) +/** + * \brief This function prepares an XTS context for encryption and + * sets the encryption key. + * + * \param ctx The AES XTS context to which the key should be bound. + * It must be initialized. + * \param key The encryption key. This is comprised of the XTS key1 + * concatenated with the XTS key2. + * This must be a readable buffer of size \p keybits bits. + * \param keybits The size of \p key passed in bits. Valid options are: + *
  • 256 bits (each of key1 and key2 is a 128-bit key)
  • + *
  • 512 bits (each of key1 and key2 is a 256-bit key)
+ * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. + */ +int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx, + const unsigned char *key, + unsigned int keybits ); + +/** + * \brief This function prepares an XTS context for decryption and + * sets the decryption key. + * + * \param ctx The AES XTS context to which the key should be bound. + * It must be initialized. + * \param key The decryption key. This is comprised of the XTS key1 + * concatenated with the XTS key2. + * This must be a readable buffer of size \p keybits bits. + * \param keybits The size of \p key passed in bits. Valid options are: + *
  • 256 bits (each of key1 and key2 is a 128-bit key)
  • + *
  • 512 bits (each of key1 and key2 is a 256-bit key)
+ * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. + */ +int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx, + const unsigned char *key, + unsigned int keybits ); +#endif /* MBEDTLS_CIPHER_MODE_XTS */ + /** * \brief This function performs an AES single-block encryption or * decryption operation. @@ -146,10 +246,13 @@ int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, * call to this API with the same context. * * \param ctx The AES context to use for encryption or decryption. + * It must be initialized and bound to a key. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or * #MBEDTLS_AES_DECRYPT. - * \param input The 16-Byte buffer holding the input data. - * \param output The 16-Byte buffer holding the output data. + * \param input The buffer holding the input data. + * It must be readable and at least \c 16 Bytes long. + * \param output The buffer where the output data will be written. + * It must be writeable and at least \c 16 Bytes long. * \return \c 0 on success. */ @@ -172,8 +275,8 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called * before the first call to this API with the same context. * - * \note This function operates on aligned blocks, that is, the input size - * must be a multiple of the AES block size of 16 Bytes. + * \note This function operates on full blocks, that is, the input size + * must be a multiple of the AES block size of \c 16 Bytes. * * \note Upon exit, the content of the IV is updated so that you can * call the same function again on the next @@ -184,15 +287,20 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, * * * \param ctx The AES context to use for encryption or decryption. + * It must be initialized and bound to a key. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or * #MBEDTLS_AES_DECRYPT. * \param length The length of the input data in Bytes. This must be a - * multiple of the block size (16 Bytes). + * multiple of the block size (\c 16 Bytes). * \param iv Initialization vector (updated after use). + * It must be a readable and writeable buffer of \c 16 Bytes. * \param input The buffer holding the input data. + * It must be readable and of size \p length Bytes. * \param output The buffer holding the output data. + * It must be writeable and of size \p length Bytes. * - * \return \c 0 on success, or #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH + * \return \c 0 on success. + * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH * on failure. */ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, @@ -203,6 +311,50 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, unsigned char *output ); #endif /* MBEDTLS_CIPHER_MODE_CBC */ +#if defined(MBEDTLS_CIPHER_MODE_XTS) +/** + * \brief This function performs an AES-XTS encryption or decryption + * operation for an entire XTS data unit. + * + * AES-XTS encrypts or decrypts blocks based on their location as + * defined by a data unit number. The data unit number must be + * provided by \p data_unit. + * + * NIST SP 800-38E limits the maximum size of a data unit to 2^20 + * AES blocks. If the data unit is larger than this, this function + * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH. + * + * \param ctx The AES XTS context to use for AES XTS operations. + * It must be initialized and bound to a key. + * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or + * #MBEDTLS_AES_DECRYPT. + * \param length The length of a data unit in Bytes. This can be any + * length between 16 bytes and 2^24 bytes inclusive + * (between 1 and 2^20 block cipher blocks). + * \param data_unit The address of the data unit encoded as an array of 16 + * bytes in little-endian format. For disk encryption, this + * is typically the index of the block device sector that + * contains the data. + * \param input The buffer holding the input data (which is an entire + * data unit). This function reads \p length Bytes from \p + * input. + * \param output The buffer holding the output data (which is an entire + * data unit). This function writes \p length Bytes to \p + * output. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is + * smaller than an AES block in size (16 Bytes) or if \p + * length is larger than 2^20 blocks (16 MiB). + */ +int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, + int mode, + size_t length, + const unsigned char data_unit[16], + const unsigned char *input, + unsigned char *output ); +#endif /* MBEDTLS_CIPHER_MODE_XTS */ + #if defined(MBEDTLS_CIPHER_MODE_CFB) /** * \brief This function performs an AES-CFB128 encryption or decryption @@ -228,13 +380,18 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, * * * \param ctx The AES context to use for encryption or decryption. + * It must be initialized and bound to a key. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or * #MBEDTLS_AES_DECRYPT. - * \param length The length of the input data. + * \param length The length of the input data in Bytes. * \param iv_off The offset in IV (updated after use). + * It must point to a valid \c size_t. * \param iv The initialization vector (updated after use). + * It must be a readable and writeable buffer of \c 16 Bytes. * \param input The buffer holding the input data. + * It must be readable and of size \p length Bytes. * \param output The buffer holding the output data. + * It must be writeable and of size \p length Bytes. * * \return \c 0 on success. */ @@ -269,12 +426,16 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, * * * \param ctx The AES context to use for encryption or decryption. + * It must be initialized and bound to a key. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or * #MBEDTLS_AES_DECRYPT * \param length The length of the input data. * \param iv The initialization vector (updated after use). + * It must be a readable and writeable buffer of \c 16 Bytes. * \param input The buffer holding the input data. + * It must be readable and of size \p length Bytes. * \param output The buffer holding the output data. + * It must be writeable and of size \p length Bytes. * * \return \c 0 on success. */ @@ -286,6 +447,61 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, unsigned char *output ); #endif /*MBEDTLS_CIPHER_MODE_CFB */ +#if defined(MBEDTLS_CIPHER_MODE_OFB) +/** + * \brief This function performs an AES-OFB (Output Feedback Mode) + * encryption or decryption operation. + * + * For OFB, you must set up the context with + * mbedtls_aes_setkey_enc(), regardless of whether you are + * performing an encryption or decryption operation. This is + * because OFB mode uses the same key schedule for encryption and + * decryption. + * + * The OFB operation is identical for encryption or decryption, + * therefore no operation mode needs to be specified. + * + * \note Upon exit, the content of iv, the Initialisation Vector, is + * updated so that you can call the same function again on the next + * block(s) of data and get the same result as if it was encrypted + * in one call. This allows a "streaming" usage, by initialising + * iv_off to 0 before the first call, and preserving its value + * between calls. + * + * For non-streaming use, the iv should be initialised on each call + * to a unique value, and iv_off set to 0 on each call. + * + * If you need to retain the contents of the initialisation vector, + * you must either save it manually or use the cipher module + * instead. + * + * \warning For the OFB mode, the initialisation vector must be unique + * every encryption operation. Reuse of an initialisation vector + * will compromise security. + * + * \param ctx The AES context to use for encryption or decryption. + * It must be initialized and bound to a key. + * \param length The length of the input data. + * \param iv_off The offset in IV (updated after use). + * It must point to a valid \c size_t. + * \param iv The initialization vector (updated after use). + * It must be a readable and writeable buffer of \c 16 Bytes. + * \param input The buffer holding the input data. + * It must be readable and of size \p length Bytes. + * \param output The buffer holding the output data. + * It must be writeable and of size \p length Bytes. + * + * \return \c 0 on success. + */ +int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, + size_t length, + size_t *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); + +#endif /* MBEDTLS_CIPHER_MODE_OFB */ + #if defined(MBEDTLS_CIPHER_MODE_CTR) /** * \brief This function performs an AES-CTR encryption or decryption @@ -300,20 +516,68 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, * must use the context initialized with mbedtls_aes_setkey_enc() * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT. * - * \warning You must keep the maximum use of your counter in mind. + * \warning You must never reuse a nonce value with the same key. Doing so + * would void the encryption for the two messages encrypted with + * the same nonce and key. + * + * There are two common strategies for managing nonces with CTR: + * + * 1. You can handle everything as a single message processed over + * successive calls to this function. In that case, you want to + * set \p nonce_counter and \p nc_off to 0 for the first call, and + * then preserve the values of \p nonce_counter, \p nc_off and \p + * stream_block across calls to this function as they will be + * updated by this function. + * + * With this strategy, you must not encrypt more than 2**128 + * blocks of data with the same key. + * + * 2. You can encrypt separate messages by dividing the \p + * nonce_counter buffer in two areas: the first one used for a + * per-message nonce, handled by yourself, and the second one + * updated by this function internally. + * + * For example, you might reserve the first 12 bytes for the + * per-message nonce, and the last 4 bytes for internal use. In that + * case, before calling this function on a new message you need to + * set the first 12 bytes of \p nonce_counter to your chosen nonce + * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p + * stream_block to be ignored). That way, you can encrypt at most + * 2**96 messages of up to 2**32 blocks each with the same key. + * + * The per-message nonce (or information sufficient to reconstruct + * it) needs to be communicated with the ciphertext and must be unique. + * The recommended way to ensure uniqueness is to use a message + * counter. An alternative is to generate random nonces, but this + * limits the number of messages that can be securely encrypted: + * for example, with 96-bit random nonces, you should not encrypt + * more than 2**32 messages with the same key. + * + * Note that for both stategies, sizes are measured in blocks and + * that an AES block is 16 bytes. + * + * \warning Upon return, \p stream_block contains sensitive data. Its + * content must not be written to insecure storage and should be + * securely discarded as soon as it's no longer needed. * * \param ctx The AES context to use for encryption or decryption. + * It must be initialized and bound to a key. * \param length The length of the input data. * \param nc_off The offset in the current \p stream_block, for * resuming within the current cipher stream. The * offset pointer should be 0 at the start of a stream. + * It must point to a valid \c size_t. * \param nonce_counter The 128-bit nonce and counter. + * It must be a readable-writeable buffer of \c 16 Bytes. * \param stream_block The saved stream block for resuming. This is * overwritten by the function. + * It must be a readable-writeable buffer of \c 16 Bytes. * \param input The buffer holding the input data. + * It must be readable and of size \p length Bytes. * \param output The buffer holding the output data. + * It must be writeable and of size \p length Bytes. * - * \return \c 0 on success. + * \return \c 0 on success. */ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, size_t length, @@ -364,7 +628,7 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx, * \brief Deprecated internal AES block encryption function * without return value. * - * \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0. + * \deprecated Superseded by mbedtls_internal_aes_encrypt() * * \param ctx The AES context to use for encryption. * \param input Plaintext block. @@ -378,7 +642,7 @@ MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx, * \brief Deprecated internal AES block decryption function * without return value. * - * \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0. + * \deprecated Superseded by mbedtls_internal_aes_decrypt() * * \param ctx The AES context to use for decryption. * \param input Ciphertext block. @@ -391,25 +655,18 @@ MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx, #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ -#ifdef __cplusplus -} -#endif - -#else /* MBEDTLS_AES_ALT */ -#include "aes_alt.h" -#endif /* MBEDTLS_AES_ALT */ - -#ifdef __cplusplus -extern "C" { -#endif +#if defined(MBEDTLS_SELF_TEST) /** * \brief Checkup routine. * - * \return \c 0 on success, or \c 1 on failure. + * \return \c 0 on success. + * \return \c 1 on failure. */ int mbedtls_aes_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/aesni.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/aesni.h index 7b16b4bad0..a4ca012f8a 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/aesni.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/aesni.h @@ -2,6 +2,9 @@ * \file aesni.h * * \brief AES-NI for hardware AES acceleration on some Intel processors + * + * \warning These functions are only for internal use by other library + * functions; you must not call them directly. */ /* * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved @@ -48,7 +51,10 @@ extern "C" { #endif /** - * \brief AES-NI features detection routine + * \brief Internal function to detect the AES-NI feature in CPUs. + * + * \note This function is only for internal use by other library + * functions; you must not call it directly. * * \param what The feature to detect * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL) @@ -58,7 +64,10 @@ extern "C" { int mbedtls_aesni_has_support( unsigned int what ); /** - * \brief AES-NI AES-ECB block en(de)cryption + * \brief Internal AES-NI AES-ECB block encryption and decryption + * + * \note This function is only for internal use by other library + * functions; you must not call it directly. * * \param ctx AES context * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT @@ -68,12 +77,15 @@ int mbedtls_aesni_has_support( unsigned int what ); * \return 0 on success (cannot fail) */ int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx, - int mode, - const unsigned char input[16], - unsigned char output[16] ); + int mode, + const unsigned char input[16], + unsigned char output[16] ); /** - * \brief GCM multiplication: c = a * b in GF(2^128) + * \brief Internal GCM multiplication: c = a * b in GF(2^128) + * + * \note This function is only for internal use by other library + * functions; you must not call it directly. * * \param c Result * \param a First operand @@ -83,21 +95,29 @@ int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx, * elements of GF(2^128) as per the GCM spec. */ void mbedtls_aesni_gcm_mult( unsigned char c[16], - const unsigned char a[16], - const unsigned char b[16] ); + const unsigned char a[16], + const unsigned char b[16] ); /** - * \brief Compute decryption round keys from encryption round keys + * \brief Internal round key inversion. This function computes + * decryption round keys from the encryption round keys. + * + * \note This function is only for internal use by other library + * functions; you must not call it directly. * * \param invkey Round keys for the equivalent inverse cipher * \param fwdkey Original round keys (for encryption) * \param nr Number of rounds (that is, number of round keys minus one) */ void mbedtls_aesni_inverse_key( unsigned char *invkey, - const unsigned char *fwdkey, int nr ); + const unsigned char *fwdkey, + int nr ); /** - * \brief Perform key expansion (for encryption) + * \brief Internal key expansion for encryption + * + * \note This function is only for internal use by other library + * functions; you must not call it directly. * * \param rk Destination buffer where the round keys are written * \param key Encryption key @@ -106,8 +126,8 @@ void mbedtls_aesni_inverse_key( unsigned char *invkey, * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH */ int mbedtls_aesni_setkey_enc( unsigned char *rk, - const unsigned char *key, - size_t bits ); + const unsigned char *key, + size_t bits ); #ifdef __cplusplus } diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/arc4.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/arc4.h index f9d93f822f..fb044d5b7f 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/arc4.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/arc4.h @@ -36,16 +36,17 @@ #include +/* MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_ARC4_HW_ACCEL_FAILED -0x0019 /**< ARC4 hardware accelerator failed. */ -#if !defined(MBEDTLS_ARC4_ALT) -// Regular implementation -// - #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_ARC4_ALT) +// Regular implementation +// + /** * \brief ARC4 context structure * @@ -53,7 +54,7 @@ extern "C" { * security risk. We recommend considering stronger ciphers instead. * */ -typedef struct +typedef struct mbedtls_arc4_context { int x; /*!< permutation index */ int y; /*!< permutation index */ @@ -61,6 +62,10 @@ typedef struct } mbedtls_arc4_context; +#else /* MBEDTLS_ARC4_ALT */ +#include "arc4_alt.h" +#endif /* MBEDTLS_ARC4_ALT */ + /** * \brief Initialize ARC4 context * @@ -118,17 +123,7 @@ void mbedtls_arc4_setup( mbedtls_arc4_context *ctx, const unsigned char *key, int mbedtls_arc4_crypt( mbedtls_arc4_context *ctx, size_t length, const unsigned char *input, unsigned char *output ); -#ifdef __cplusplus -} -#endif - -#else /* MBEDTLS_ARC4_ALT */ -#include "arc4_alt.h" -#endif /* MBEDTLS_ARC4_ALT */ - -#ifdef __cplusplus -extern "C" { -#endif +#if defined(MBEDTLS_SELF_TEST) /** * \brief Checkup routine @@ -142,6 +137,8 @@ extern "C" { */ int mbedtls_arc4_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/aria.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/aria.h new file mode 100644 index 0000000000..1e8956ed13 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/aria.h @@ -0,0 +1,370 @@ +/** + * \file aria.h + * + * \brief ARIA block cipher + * + * The ARIA algorithm is a symmetric block cipher that can encrypt and + * decrypt information. It is defined by the Korean Agency for + * Technology and Standards (KATS) in KS X 1213:2004 (in + * Korean, but see http://210.104.33.10/ARIA/index-e.html in English) + * and also described by the IETF in RFC 5794. + */ +/* Copyright (C) 2006-2018, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ + +#ifndef MBEDTLS_ARIA_H +#define MBEDTLS_ARIA_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include +#include + +#include "platform_util.h" + +#define MBEDTLS_ARIA_ENCRYPT 1 /**< ARIA encryption. */ +#define MBEDTLS_ARIA_DECRYPT 0 /**< ARIA decryption. */ + +#define MBEDTLS_ARIA_BLOCKSIZE 16 /**< ARIA block size in bytes. */ +#define MBEDTLS_ARIA_MAX_ROUNDS 16 /**< Maxiumum number of rounds in ARIA. */ +#define MBEDTLS_ARIA_MAX_KEYSIZE 32 /**< Maximum size of an ARIA key in bytes. */ + +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +#define MBEDTLS_ERR_ARIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x005C ) +#endif /* !MBEDTLS_DEPRECATED_REMOVED */ +#define MBEDTLS_ERR_ARIA_BAD_INPUT_DATA -0x005C /**< Bad input data. */ + +#define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E /**< Invalid data input length. */ + +/* MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE is deprecated and should not be used. + */ +#define MBEDTLS_ERR_ARIA_FEATURE_UNAVAILABLE -0x005A /**< Feature not available. For example, an unsupported ARIA key size. */ + +/* MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED is deprecated and should not be used. */ +#define MBEDTLS_ERR_ARIA_HW_ACCEL_FAILED -0x0058 /**< ARIA hardware accelerator failed. */ + +#if !defined(MBEDTLS_ARIA_ALT) +// Regular implementation +// + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief The ARIA context-type definition. + */ +typedef struct mbedtls_aria_context +{ + unsigned char nr; /*!< The number of rounds (12, 14 or 16) */ + /*! The ARIA round keys. */ + uint32_t rk[MBEDTLS_ARIA_MAX_ROUNDS + 1][MBEDTLS_ARIA_BLOCKSIZE / 4]; +} +mbedtls_aria_context; + +#else /* MBEDTLS_ARIA_ALT */ +#include "aria_alt.h" +#endif /* MBEDTLS_ARIA_ALT */ + +/** + * \brief This function initializes the specified ARIA context. + * + * It must be the first API called before using + * the context. + * + * \param ctx The ARIA context to initialize. This must not be \c NULL. + */ +void mbedtls_aria_init( mbedtls_aria_context *ctx ); + +/** + * \brief This function releases and clears the specified ARIA context. + * + * \param ctx The ARIA context to clear. This may be \c NULL, in which + * case this function returns immediately. If it is not \c NULL, + * it must point to an initialized ARIA context. + */ +void mbedtls_aria_free( mbedtls_aria_context *ctx ); + +/** + * \brief This function sets the encryption key. + * + * \param ctx The ARIA context to which the key should be bound. + * This must be initialized. + * \param key The encryption key. This must be a readable buffer + * of size \p keybits Bits. + * \param keybits The size of \p key in Bits. Valid options are: + *
  • 128 bits
  • + *
  • 192 bits
  • + *
  • 256 bits
+ * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx, + const unsigned char *key, + unsigned int keybits ); + +/** + * \brief This function sets the decryption key. + * + * \param ctx The ARIA context to which the key should be bound. + * This must be initialized. + * \param key The decryption key. This must be a readable buffer + * of size \p keybits Bits. + * \param keybits The size of data passed. Valid options are: + *
  • 128 bits
  • + *
  • 192 bits
  • + *
  • 256 bits
+ * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_setkey_dec( mbedtls_aria_context *ctx, + const unsigned char *key, + unsigned int keybits ); + +/** + * \brief This function performs an ARIA single-block encryption or + * decryption operation. + * + * It performs encryption or decryption (depending on whether + * the key was set for encryption on decryption) on the input + * data buffer defined in the \p input parameter. + * + * mbedtls_aria_init(), and either mbedtls_aria_setkey_enc() or + * mbedtls_aria_setkey_dec() must be called before the first + * call to this API with the same context. + * + * \param ctx The ARIA context to use for encryption or decryption. + * This must be initialized and bound to a key. + * \param input The 16-Byte buffer holding the input data. + * \param output The 16-Byte buffer holding the output data. + + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_crypt_ecb( mbedtls_aria_context *ctx, + const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE], + unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] ); + +#if defined(MBEDTLS_CIPHER_MODE_CBC) +/** + * \brief This function performs an ARIA-CBC encryption or decryption operation + * on full blocks. + * + * It performs the operation defined in the \p mode + * parameter (encrypt/decrypt), on the input data buffer defined in + * the \p input parameter. + * + * It can be called as many times as needed, until all the input + * data is processed. mbedtls_aria_init(), and either + * mbedtls_aria_setkey_enc() or mbedtls_aria_setkey_dec() must be called + * before the first call to this API with the same context. + * + * \note This function operates on aligned blocks, that is, the input size + * must be a multiple of the ARIA block size of 16 Bytes. + * + * \note Upon exit, the content of the IV is updated so that you can + * call the same function again on the next + * block(s) of data and get the same result as if it was + * encrypted in one call. This allows a "streaming" usage. + * If you need to retain the contents of the IV, you should + * either save it manually or use the cipher module instead. + * + * + * \param ctx The ARIA context to use for encryption or decryption. + * This must be initialized and bound to a key. + * \param mode The mode of operation. This must be either + * #MBEDTLS_ARIA_ENCRYPT for encryption, or + * #MBEDTLS_ARIA_DECRYPT for decryption. + * \param length The length of the input data in Bytes. This must be a + * multiple of the block size (16 Bytes). + * \param iv Initialization vector (updated after use). + * This must be a readable buffer of size 16 Bytes. + * \param input The buffer holding the input data. This must + * be a readable buffer of length \p length Bytes. + * \param output The buffer holding the output data. This must + * be a writable buffer of length \p length Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_crypt_cbc( mbedtls_aria_context *ctx, + int mode, + size_t length, + unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE], + const unsigned char *input, + unsigned char *output ); +#endif /* MBEDTLS_CIPHER_MODE_CBC */ + +#if defined(MBEDTLS_CIPHER_MODE_CFB) +/** + * \brief This function performs an ARIA-CFB128 encryption or decryption + * operation. + * + * It performs the operation defined in the \p mode + * parameter (encrypt or decrypt), on the input data buffer + * defined in the \p input parameter. + * + * For CFB, you must set up the context with mbedtls_aria_setkey_enc(), + * regardless of whether you are performing an encryption or decryption + * operation, that is, regardless of the \p mode parameter. This is + * because CFB mode uses the same key schedule for encryption and + * decryption. + * + * \note Upon exit, the content of the IV is updated so that you can + * call the same function again on the next + * block(s) of data and get the same result as if it was + * encrypted in one call. This allows a "streaming" usage. + * If you need to retain the contents of the + * IV, you must either save it manually or use the cipher + * module instead. + * + * + * \param ctx The ARIA context to use for encryption or decryption. + * This must be initialized and bound to a key. + * \param mode The mode of operation. This must be either + * #MBEDTLS_ARIA_ENCRYPT for encryption, or + * #MBEDTLS_ARIA_DECRYPT for decryption. + * \param length The length of the input data \p input in Bytes. + * \param iv_off The offset in IV (updated after use). + * This must not be larger than 15. + * \param iv The initialization vector (updated after use). + * This must be a readable buffer of size 16 Bytes. + * \param input The buffer holding the input data. This must + * be a readable buffer of length \p length Bytes. + * \param output The buffer holding the output data. This must + * be a writable buffer of length \p length Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_crypt_cfb128( mbedtls_aria_context *ctx, + int mode, + size_t length, + size_t *iv_off, + unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE], + const unsigned char *input, + unsigned char *output ); +#endif /* MBEDTLS_CIPHER_MODE_CFB */ + +#if defined(MBEDTLS_CIPHER_MODE_CTR) +/** + * \brief This function performs an ARIA-CTR encryption or decryption + * operation. + * + * This function performs the operation defined in the \p mode + * parameter (encrypt/decrypt), on the input data buffer + * defined in the \p input parameter. + * + * Due to the nature of CTR, you must use the same key schedule + * for both encryption and decryption operations. Therefore, you + * must use the context initialized with mbedtls_aria_setkey_enc() + * for both #MBEDTLS_ARIA_ENCRYPT and #MBEDTLS_ARIA_DECRYPT. + * + * \warning You must never reuse a nonce value with the same key. Doing so + * would void the encryption for the two messages encrypted with + * the same nonce and key. + * + * There are two common strategies for managing nonces with CTR: + * + * 1. You can handle everything as a single message processed over + * successive calls to this function. In that case, you want to + * set \p nonce_counter and \p nc_off to 0 for the first call, and + * then preserve the values of \p nonce_counter, \p nc_off and \p + * stream_block across calls to this function as they will be + * updated by this function. + * + * With this strategy, you must not encrypt more than 2**128 + * blocks of data with the same key. + * + * 2. You can encrypt separate messages by dividing the \p + * nonce_counter buffer in two areas: the first one used for a + * per-message nonce, handled by yourself, and the second one + * updated by this function internally. + * + * For example, you might reserve the first 12 bytes for the + * per-message nonce, and the last 4 bytes for internal use. In that + * case, before calling this function on a new message you need to + * set the first 12 bytes of \p nonce_counter to your chosen nonce + * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p + * stream_block to be ignored). That way, you can encrypt at most + * 2**96 messages of up to 2**32 blocks each with the same key. + * + * The per-message nonce (or information sufficient to reconstruct + * it) needs to be communicated with the ciphertext and must be unique. + * The recommended way to ensure uniqueness is to use a message + * counter. An alternative is to generate random nonces, but this + * limits the number of messages that can be securely encrypted: + * for example, with 96-bit random nonces, you should not encrypt + * more than 2**32 messages with the same key. + * + * Note that for both stategies, sizes are measured in blocks and + * that an ARIA block is 16 bytes. + * + * \warning Upon return, \p stream_block contains sensitive data. Its + * content must not be written to insecure storage and should be + * securely discarded as soon as it's no longer needed. + * + * \param ctx The ARIA context to use for encryption or decryption. + * This must be initialized and bound to a key. + * \param length The length of the input data \p input in Bytes. + * \param nc_off The offset in Bytes in the current \p stream_block, + * for resuming within the current cipher stream. The + * offset pointer should be \c 0 at the start of a + * stream. This must not be larger than \c 15 Bytes. + * \param nonce_counter The 128-bit nonce and counter. This must point to + * a read/write buffer of length \c 16 bytes. + * \param stream_block The saved stream block for resuming. This must + * point to a read/write buffer of length \c 16 bytes. + * This is overwritten by the function. + * \param input The buffer holding the input data. This must + * be a readable buffer of length \p length Bytes. + * \param output The buffer holding the output data. This must + * be a writable buffer of length \p length Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_crypt_ctr( mbedtls_aria_context *ctx, + size_t length, + size_t *nc_off, + unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE], + unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE], + const unsigned char *input, + unsigned char *output ); +#endif /* MBEDTLS_CIPHER_MODE_CTR */ + +#if defined(MBEDTLS_SELF_TEST) +/** + * \brief Checkup routine. + * + * \return \c 0 on success, or \c 1 on failure. + */ +int mbedtls_aria_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + +#ifdef __cplusplus +} +#endif + +#endif /* aria.h */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/asn1write.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/asn1write.h index 083601af32..a194243696 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/asn1write.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/asn1write.h @@ -32,161 +32,239 @@ #include "asn1.h" -#define MBEDTLS_ASN1_CHK_ADD(g, f) do { if( ( ret = f ) < 0 ) return( ret ); else \ - g += ret; } while( 0 ) +#define MBEDTLS_ASN1_CHK_ADD(g, f) \ + do \ + { \ + if( ( ret = (f) ) < 0 ) \ + return( ret ); \ + else \ + (g) += ret; \ + } while( 0 ) #ifdef __cplusplus extern "C" { #endif /** - * \brief Write a length field in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write a length field in ASN.1 format. * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param len the length to write + * \note This function works backwards in data buffer. + * + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param len The length value to write. * - * \return the length written or a negative error code + * \return The number of bytes written to \p p on success. + * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ -int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, size_t len ); - +int mbedtls_asn1_write_len( unsigned char **p, unsigned char *start, + size_t len ); /** - * \brief Write a ASN.1 tag in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write an ASN.1 tag in ASN.1 format. * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param tag the tag to write + * \note This function works backwards in data buffer. * - * \return the length written or a negative error code + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param tag The tag to write. + * + * \return The number of bytes written to \p p on success. + * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ int mbedtls_asn1_write_tag( unsigned char **p, unsigned char *start, - unsigned char tag ); + unsigned char tag ); /** - * \brief Write raw buffer data - * Note: function works backwards in data buffer + * \brief Write raw buffer data. * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param buf data buffer to write - * \param size length of the data buffer + * \note This function works backwards in data buffer. * - * \return the length written or a negative error code + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param buf The data buffer to write. + * \param size The length of the data buffer. + * + * \return The number of bytes written to \p p on success. + * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ int mbedtls_asn1_write_raw_buffer( unsigned char **p, unsigned char *start, - const unsigned char *buf, size_t size ); + const unsigned char *buf, size_t size ); #if defined(MBEDTLS_BIGNUM_C) /** - * \brief Write a big number (MBEDTLS_ASN1_INTEGER) in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write a arbitrary-precision number (#MBEDTLS_ASN1_INTEGER) + * in ASN.1 format. * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param X the MPI to write + * \note This function works backwards in data buffer. * - * \return the length written or a negative error code + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param X The MPI to write. + * + * \return The number of bytes written to \p p on success. + * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ -int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start, const mbedtls_mpi *X ); +int mbedtls_asn1_write_mpi( unsigned char **p, unsigned char *start, + const mbedtls_mpi *X ); #endif /* MBEDTLS_BIGNUM_C */ /** - * \brief Write a NULL tag (MBEDTLS_ASN1_NULL) with zero data in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write a NULL tag (#MBEDTLS_ASN1_NULL) with zero data + * in ASN.1 format. * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) + * \note This function works backwards in data buffer. + * + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. * - * \return the length written or a negative error code + * \return The number of bytes written to \p p on success. + * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ int mbedtls_asn1_write_null( unsigned char **p, unsigned char *start ); /** - * \brief Write an OID tag (MBEDTLS_ASN1_OID) and data in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write an OID tag (#MBEDTLS_ASN1_OID) and data + * in ASN.1 format. * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param oid the OID to write - * \param oid_len length of the OID + * \note This function works backwards in data buffer. * - * \return the length written or a negative error code + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param oid The OID to write. + * \param oid_len The length of the OID. + * + * \return The number of bytes written to \p p on success. + * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ int mbedtls_asn1_write_oid( unsigned char **p, unsigned char *start, - const char *oid, size_t oid_len ); + const char *oid, size_t oid_len ); /** - * \brief Write an AlgorithmIdentifier sequence in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write an AlgorithmIdentifier sequence in ASN.1 format. * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param oid the OID of the algorithm - * \param oid_len length of the OID - * \param par_len length of parameters, which must be already written. + * \note This function works backwards in data buffer. + * + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param oid The OID of the algorithm to write. + * \param oid_len The length of the algorithm's OID. + * \param par_len The length of the parameters, which must be already written. * If 0, NULL parameters are added * - * \return the length written or a negative error code + * \return The number of bytes written to \p p on success. + * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ -int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, unsigned char *start, - const char *oid, size_t oid_len, - size_t par_len ); +int mbedtls_asn1_write_algorithm_identifier( unsigned char **p, + unsigned char *start, + const char *oid, size_t oid_len, + size_t par_len ); /** - * \brief Write a boolean tag (MBEDTLS_ASN1_BOOLEAN) and value in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write a boolean tag (#MBEDTLS_ASN1_BOOLEAN) and value + * in ASN.1 format. + * + * \note This function works backwards in data buffer. * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param boolean 0 or 1 + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param boolean The boolean value to write, either \c 0 or \c 1. * - * \return the length written or a negative error code + * \return The number of bytes written to \p p on success. + * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ -int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start, int boolean ); +int mbedtls_asn1_write_bool( unsigned char **p, unsigned char *start, + int boolean ); /** - * \brief Write an int tag (MBEDTLS_ASN1_INTEGER) and value in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write an int tag (#MBEDTLS_ASN1_INTEGER) and value + * in ASN.1 format. + * + * \note This function works backwards in data buffer. * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param val the integer value + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param val The integer value to write. * - * \return the length written or a negative error code + * \return The number of bytes written to \p p on success. + * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ int mbedtls_asn1_write_int( unsigned char **p, unsigned char *start, int val ); /** - * \brief Write a printable string tag (MBEDTLS_ASN1_PRINTABLE_STRING) and - * value in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write a string in ASN.1 format using a specific + * string encoding tag. + + * \note This function works backwards in data buffer. + * + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param tag The string encoding tag to write, e.g. + * #MBEDTLS_ASN1_UTF8_STRING. + * \param text The string to write. + * \param text_len The length of \p text in bytes (which might + * be strictly larger than the number of characters). + * + * \return The number of bytes written to \p p on success. + * \return A negative error code on failure. + */ +int mbedtls_asn1_write_tagged_string( unsigned char **p, unsigned char *start, + int tag, const char *text, + size_t text_len ); + +/** + * \brief Write a string in ASN.1 format using the PrintableString + * string encoding tag (#MBEDTLS_ASN1_PRINTABLE_STRING). + * + * \note This function works backwards in data buffer. + * + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param text The string to write. + * \param text_len The length of \p text in bytes (which might + * be strictly larger than the number of characters). + * + * \return The number of bytes written to \p p on success. + * \return A negative error code on failure. + */ +int mbedtls_asn1_write_printable_string( unsigned char **p, + unsigned char *start, + const char *text, size_t text_len ); + +/** + * \brief Write a UTF8 string in ASN.1 format using the UTF8String + * string encoding tag (#MBEDTLS_ASN1_PRINTABLE_STRING). * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param text the text to write - * \param text_len length of the text + * \note This function works backwards in data buffer. * - * \return the length written or a negative error code + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param text The string to write. + * \param text_len The length of \p text in bytes (which might + * be strictly larger than the number of characters). + * + * \return The number of bytes written to \p p on success. + * \return A negative error code on failure. */ -int mbedtls_asn1_write_printable_string( unsigned char **p, unsigned char *start, - const char *text, size_t text_len ); +int mbedtls_asn1_write_utf8_string( unsigned char **p, unsigned char *start, + const char *text, size_t text_len ); /** - * \brief Write an IA5 string tag (MBEDTLS_ASN1_IA5_STRING) and - * value in ASN.1 format - * Note: function works backwards in data buffer + * \brief Write a string in ASN.1 format using the IA5String + * string encoding tag (#MBEDTLS_ASN1_IA5_STRING). * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param text the text to write - * \param text_len length of the text + * \note This function works backwards in data buffer. * - * \return the length written or a negative error code + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param text The string to write. + * \param text_len The length of \p text in bytes (which might + * be strictly larger than the number of characters). + * + * \return The number of bytes written to \p p on success. + * \return A negative error code on failure. */ int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start, - const char *text, size_t text_len ); + const char *text, size_t text_len ); /** * \brief Write a bitstring tag (#MBEDTLS_ASN1_BIT_STRING) and @@ -203,7 +281,7 @@ int mbedtls_asn1_write_ia5_string( unsigned char **p, unsigned char *start, * \return A negative error code on failure. */ int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start, - const unsigned char *buf, size_t bits ); + const unsigned char *buf, size_t bits ); /** * \brief Write an octet string tag (#MBEDTLS_ASN1_OCTET_STRING) @@ -211,15 +289,16 @@ int mbedtls_asn1_write_bitstring( unsigned char **p, unsigned char *start, * * \note This function works backwards in data buffer. * - * \param p reference to current position pointer - * \param start start of the buffer (for bounds-checking) - * \param buf data buffer to write - * \param size length of the data buffer + * \param p The reference to the current position pointer. + * \param start The start of the buffer, for bounds-checking. + * \param buf The buffer holding the data to write. + * \param size The length of the data buffer \p buf. * - * \return the length written or a negative error code + * \return The number of bytes written to \p p on success. + * \return A negative error code on failure. */ int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start, - const unsigned char *buf, size_t size ); + const unsigned char *buf, size_t size ); /** * \brief Create or find a specific named_data entry for writing in a @@ -227,15 +306,16 @@ int mbedtls_asn1_write_octet_string( unsigned char **p, unsigned char *start, * a new entry is added to the head of the list. * Warning: Destructive behaviour for the val data! * - * \param list Pointer to the location of the head of the list to seek - * through (will be updated in case of a new entry) - * \param oid The OID to look for - * \param oid_len Size of the OID - * \param val Data to store (can be NULL if you want to fill it by hand) - * \param val_len Minimum length of the data buffer needed + * \param list The pointer to the location of the head of the list to seek + * through (will be updated in case of a new entry). + * \param oid The OID to look for. + * \param oid_len The size of the OID. + * \param val The data to store (can be \c NULL if you want to fill + * it by hand). + * \param val_len The minimum length of the data buffer needed. * - * \return NULL if if there was a memory allocation error, or a pointer - * to the new / existing entry. + * \return A pointer to the new / existing entry on success. + * \return \c NULL if if there was a memory allocation error. */ mbedtls_asn1_named_data *mbedtls_asn1_store_named_data( mbedtls_asn1_named_data **list, const char *oid, size_t oid_len, diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/base64.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/base64.h index 10e4145ee6..0d024164c5 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/base64.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/base64.h @@ -81,6 +81,7 @@ int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen ); +#if defined(MBEDTLS_SELF_TEST) /** * \brief Checkup routine * @@ -88,6 +89,8 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, */ int mbedtls_base64_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/bignum.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/bignum.h index 3bf02a7ee1..1c8607264f 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/bignum.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/bignum.h @@ -46,7 +46,12 @@ #define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E /**< The input arguments are not acceptable. */ #define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010 /**< Memory allocation failed. */ -#define MBEDTLS_MPI_CHK(f) do { if( ( ret = f ) != 0 ) goto cleanup; } while( 0 ) +#define MBEDTLS_MPI_CHK(f) \ + do \ + { \ + if( ( ret = (f) ) != 0 ) \ + goto cleanup; \ + } while( 0 ) /* * Maximum size MPIs are allowed to grow to in number of limbs. @@ -177,7 +182,7 @@ extern "C" { /** * \brief MPI structure */ -typedef struct +typedef struct mbedtls_mpi { int s; /*!< integer sign */ size_t n; /*!< total # of limbs */ @@ -186,90 +191,115 @@ typedef struct mbedtls_mpi; /** - * \brief Initialize one MPI (make internal references valid) - * This just makes it ready to be set or freed, + * \brief Initialize an MPI context. + * + * This makes the MPI ready to be set or freed, * but does not define a value for the MPI. * - * \param X One MPI to initialize. + * \param X The MPI context to initialize. This must not be \c NULL. */ void mbedtls_mpi_init( mbedtls_mpi *X ); /** - * \brief Unallocate one MPI + * \brief This function frees the components of an MPI context. * - * \param X One MPI to unallocate. + * \param X The MPI context to be cleared. This may be \c NULL, + * in which case this function is a no-op. If it is + * not \c NULL, it must point to an initialized MPI. */ void mbedtls_mpi_free( mbedtls_mpi *X ); /** - * \brief Enlarge to the specified number of limbs + * \brief Enlarge an MPI to the specified number of limbs. + * + * \note This function does nothing if the MPI is + * already large enough. * - * \param X MPI to grow - * \param nblimbs The target number of limbs + * \param X The MPI to grow. It must be initialized. + * \param nblimbs The target number of limbs. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. + * \return Another negative error code on other kinds of failure. */ int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs ); /** - * \brief Resize down, keeping at least the specified number of limbs + * \brief This function resizes an MPI downwards, keeping at least the + * specified number of limbs. + * + * If \c X is smaller than \c nblimbs, it is resized up + * instead. * - * \param X MPI to shrink - * \param nblimbs The minimum number of limbs to keep + * \param X The MPI to shrink. This must point to an initialized MPI. + * \param nblimbs The minimum number of limbs to keep. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * (this can only happen when resizing up). + * \return Another negative error code on other kinds of failure. */ int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs ); /** - * \brief Copy the contents of Y into X + * \brief Make a copy of an MPI. * - * \param X Destination MPI - * \param Y Source MPI + * \param X The destination MPI. This must point to an initialized MPI. + * \param Y The source MPI. This must point to an initialized MPI. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \note The limb-buffer in the destination MPI is enlarged + * if necessary to hold the value in the source MPI. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. + * \return Another negative error code on other kinds of failure. */ int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y ); /** - * \brief Swap the contents of X and Y + * \brief Swap the contents of two MPIs. * - * \param X First MPI value - * \param Y Second MPI value + * \param X The first MPI. It must be initialized. + * \param Y The second MPI. It must be initialized. */ void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y ); /** - * \brief Safe conditional assignement X = Y if assign is 1 - * - * \param X MPI to conditionally assign to - * \param Y Value to be assigned - * \param assign 1: perform the assignment, 0: keep X's original value + * \brief Perform a safe conditional copy of MPI which doesn't + * reveal whether the condition was true or not. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * \param X The MPI to conditionally assign to. This must point + * to an initialized MPI. + * \param Y The MPI to be assigned from. This must point to an + * initialized MPI. + * \param assign The condition deciding whether to perform the + * assignment or not. Possible values: + * * \c 1: Perform the assignment `X = Y`. + * * \c 0: Keep the original value of \p X. * * \note This function is equivalent to - * if( assign ) mbedtls_mpi_copy( X, Y ); + * `if( assign ) mbedtls_mpi_copy( X, Y );` * except that it avoids leaking any information about whether * the assignment was done or not (the above code may leak * information through branch prediction and/or memory access * patterns analysis). + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. + * \return Another negative error code on other kinds of failure. */ int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign ); /** - * \brief Safe conditional swap X <-> Y if swap is 1 - * - * \param X First mbedtls_mpi value - * \param Y Second mbedtls_mpi value - * \param assign 1: perform the swap, 0: keep X and Y's original values + * \brief Perform a safe conditional swap which doesn't + * reveal whether the condition was true or not. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, + * \param X The first MPI. This must be initialized. + * \param Y The second MPI. This must be initialized. + * \param assign The condition deciding whether to perform + * the swap or not. Possible values: + * * \c 1: Swap the values of \p X and \p Y. + * * \c 0: Keep the original values of \p X and \p Y. * * \note This function is equivalent to * if( assign ) mbedtls_mpi_swap( X, Y ); @@ -277,415 +307,512 @@ int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned * the assignment was done or not (the above code may leak * information through branch prediction and/or memory access * patterns analysis). + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. + * \return Another negative error code on other kinds of failure. + * */ int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign ); /** - * \brief Set value from integer + * \brief Store integer value in MPI. * - * \param X MPI to set - * \param z Value to use + * \param X The MPI to set. This must be initialized. + * \param z The value to use. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. + * \return Another negative error code on other kinds of failure. */ int mbedtls_mpi_lset( mbedtls_mpi *X, mbedtls_mpi_sint z ); /** - * \brief Get a specific bit from X + * \brief Get a specific bit from an MPI. * - * \param X MPI to use - * \param pos Zero-based index of the bit in X + * \param X The MPI to query. This must be initialized. + * \param pos Zero-based index of the bit to query. * - * \return Either a 0 or a 1 + * \return \c 0 or \c 1 on success, depending on whether bit \c pos + * of \c X is unset or set. + * \return A negative error code on failure. */ int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos ); /** - * \brief Set a bit of X to a specific value of 0 or 1 + * \brief Modify a specific bit in an MPI. * - * \note Will grow X if necessary to set a bit to 1 in a not yet - * existing limb. Will not grow if bit should be set to 0 + * \note This function will grow the target MPI if necessary to set a + * bit to \c 1 in a not yet existing limb. It will not grow if + * the bit should be set to \c 0. * - * \param X MPI to use - * \param pos Zero-based index of the bit in X - * \param val The value to set the bit to (0 or 1) + * \param X The MPI to modify. This must be initialized. + * \param pos Zero-based index of the bit to modify. + * \param val The desired value of bit \c pos: \c 0 or \c 1. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, - * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if val is not 0 or 1 + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. + * \return Another negative error code on other kinds of failure. */ int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val ); /** - * \brief Return the number of zero-bits before the least significant - * '1' bit + * \brief Return the number of bits of value \c 0 before the + * least significant bit of value \c 1. * - * Note: Thus also the zero-based index of the least significant '1' bit + * \note This is the same as the zero-based index of + * the least significant bit of value \c 1. * - * \param X MPI to use + * \param X The MPI to query. + * + * \return The number of bits of value \c 0 before the least significant + * bit of value \c 1 in \p X. */ size_t mbedtls_mpi_lsb( const mbedtls_mpi *X ); /** * \brief Return the number of bits up to and including the most - * significant '1' bit' + * significant bit of value \c 1. + * + * * \note This is same as the one-based index of the most + * significant bit of value \c 1. * - * Note: Thus also the one-based index of the most significant '1' bit + * \param X The MPI to query. This must point to an initialized MPI. * - * \param X MPI to use + * \return The number of bits up to and including the most + * significant bit of value \c 1. */ size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X ); /** - * \brief Return the total size in bytes + * \brief Return the total size of an MPI value in bytes. + * + * \param X The MPI to use. This must point to an initialized MPI. + * + * \note The value returned by this function may be less than + * the number of bytes used to store \p X internally. + * This happens if and only if there are trailing bytes + * of value zero. * - * \param X MPI to use + * \return The least number of bytes capable of storing + * the absolute value of \p X. */ size_t mbedtls_mpi_size( const mbedtls_mpi *X ); /** - * \brief Import from an ASCII string + * \brief Import an MPI from an ASCII string. * - * \param X Destination MPI - * \param radix Input numeric base - * \param s Null-terminated string buffer + * \param X The destination MPI. This must point to an initialized MPI. + * \param radix The numeric base of the input string. + * \param s Null-terminated string buffer. * - * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s ); /** - * \brief Export into an ASCII string + * \brief Export an MPI to an ASCII string. * - * \param X Source MPI - * \param radix Output numeric base - * \param buf Buffer to write the string to - * \param buflen Length of buf - * \param olen Length of the string written, including final NUL byte + * \param X The source MPI. This must point to an initialized MPI. + * \param radix The numeric base of the output string. + * \param buf The buffer to write the string to. This must be writable + * buffer of length \p buflen Bytes. + * \param buflen The available size in Bytes of \p buf. + * \param olen The address at which to store the length of the string + * written, including the final \c NULL byte. This must + * not be \c NULL. * - * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code. - * *olen is always updated to reflect the amount - * of data that has (or would have) been written. + * \note You can call this function with `buflen == 0` to obtain the + * minimum required buffer size in `*olen`. * - * \note Call this function with buflen = 0 to obtain the - * minimum required buffer size in *olen. + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if the target buffer \p buf + * is too small to hold the value of \p X in the desired base. + * In this case, `*olen` is nonetheless updated to contain the + * size of \p buf required for a successful call. + * \return Another negative error code on different kinds of failure. */ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix, char *buf, size_t buflen, size_t *olen ); #if defined(MBEDTLS_FS_IO) /** - * \brief Read MPI from a line in an opened file + * \brief Read an MPI from a line in an opened file. * - * \param X Destination MPI - * \param radix Input numeric base - * \param fin Input file handle - * - * \return 0 if successful, MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if - * the file read buffer is too small or a - * MBEDTLS_ERR_MPI_XXX error code + * \param X The destination MPI. This must point to an initialized MPI. + * \param radix The numeric base of the string representation used + * in the source line. + * \param fin The input file handle to use. This must not be \c NULL. * * \note On success, this function advances the file stream * to the end of the current line or to EOF. * - * The function returns 0 on an empty line. + * The function returns \c 0 on an empty line. * * Leading whitespaces are ignored, as is a - * '0x' prefix for radix 16. + * '0x' prefix for radix \c 16. * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if the file read buffer + * is too small. + * \return Another negative error code on failure. */ int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin ); /** - * \brief Write X into an opened file, or stdout if fout is NULL - * - * \param p Prefix, can be NULL - * \param X Source MPI - * \param radix Output numeric base - * \param fout Output file handle (can be NULL) + * \brief Export an MPI into an opened file. * - * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code + * \param p A string prefix to emit prior to the MPI data. + * For example, this might be a label, or "0x" when + * printing in base \c 16. This may be \c NULL if no prefix + * is needed. + * \param X The source MPI. This must point to an initialized MPI. + * \param radix The numeric base to be used in the emitted string. + * \param fout The output file handle. This may be \c NULL, in which case + * the output is written to \c stdout. * - * \note Set fout == NULL to print X on the console. + * \return \c 0 if successful. + * \return A negative error code on failure. */ -int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE *fout ); +int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, + int radix, FILE *fout ); #endif /* MBEDTLS_FS_IO */ /** - * \brief Import X from unsigned binary data, big endian + * \brief Import an MPI from unsigned big endian binary data. * - * \param X Destination MPI - * \param buf Input buffer - * \param buflen Input buffer size + * \param X The destination MPI. This must point to an initialized MPI. + * \param buf The input buffer. This must be a readable buffer of length + * \p buflen Bytes. + * \param buflen The length of the input buffer \p p in Bytes. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. + * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, size_t buflen ); +int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, + size_t buflen ); /** - * \brief Export X into unsigned binary data, big endian. - * Always fills the whole buffer, which will start with zeros - * if the number is smaller. + * \brief Export an MPI into unsigned big endian binary data + * of fixed size. * - * \param X Source MPI - * \param buf Output buffer - * \param buflen Output buffer size + * \param X The source MPI. This must point to an initialized MPI. + * \param buf The output buffer. This must be a writable buffer of length + * \p buflen Bytes. + * \param buflen The size of the output buffer \p buf in Bytes. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p buf isn't + * large enough to hold the value of \p X. + * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf, size_t buflen ); +int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf, + size_t buflen ); /** - * \brief Left-shift: X <<= count + * \brief Perform a left-shift on an MPI: X <<= count * - * \param X MPI to shift - * \param count Amount to shift + * \param X The MPI to shift. This must point to an initialized MPI. + * \param count The number of bits to shift by. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return Another negative error code on different kinds of failure. */ int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count ); /** - * \brief Right-shift: X >>= count + * \brief Perform a right-shift on an MPI: X >>= count * - * \param X MPI to shift - * \param count Amount to shift + * \param X The MPI to shift. This must point to an initialized MPI. + * \param count The number of bits to shift by. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return Another negative error code on different kinds of failure. */ int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count ); /** - * \brief Compare unsigned values + * \brief Compare the absolute values of two MPIs. * - * \param X Left-hand MPI - * \param Y Right-hand MPI + * \param X The left-hand MPI. This must point to an initialized MPI. + * \param Y The right-hand MPI. This must point to an initialized MPI. * - * \return 1 if |X| is greater than |Y|, - * -1 if |X| is lesser than |Y| or - * 0 if |X| is equal to |Y| + * \return \c 1 if `|X|` is greater than `|Y|`. + * \return \c -1 if `|X|` is lesser than `|Y|`. + * \return \c 0 if `|X|` is equal to `|Y|`. */ int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y ); /** - * \brief Compare signed values + * \brief Compare two MPIs. * - * \param X Left-hand MPI - * \param Y Right-hand MPI + * \param X The left-hand MPI. This must point to an initialized MPI. + * \param Y The right-hand MPI. This must point to an initialized MPI. * - * \return 1 if X is greater than Y, - * -1 if X is lesser than Y or - * 0 if X is equal to Y + * \return \c 1 if \p X is greater than \p Y. + * \return \c -1 if \p X is lesser than \p Y. + * \return \c 0 if \p X is equal to \p Y. */ int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y ); /** - * \brief Compare signed values + * \brief Compare an MPI with an integer. * - * \param X Left-hand MPI - * \param z The integer value to compare to + * \param X The left-hand MPI. This must point to an initialized MPI. + * \param z The integer value to compare \p X to. * - * \return 1 if X is greater than z, - * -1 if X is lesser than z or - * 0 if X is equal to z + * \return \c 1 if \p X is greater than \p z. + * \return \c -1 if \p X is lesser than \p z. + * \return \c 0 if \p X is equal to \p z. */ int mbedtls_mpi_cmp_int( const mbedtls_mpi *X, mbedtls_mpi_sint z ); /** - * \brief Unsigned addition: X = |A| + |B| + * \brief Perform an unsigned addition of MPIs: X = |A| + |B| * - * \param X Destination MPI - * \param A Left-hand MPI - * \param B Right-hand MPI + * \param X The destination MPI. This must point to an initialized MPI. + * \param A The first summand. This must point to an initialized MPI. + * \param B The second summand. This must point to an initialized MPI. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); +int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** - * \brief Unsigned subtraction: X = |A| - |B| + * \brief Perform an unsigned subtraction of MPIs: X = |A| - |B| * - * \param X Destination MPI - * \param A Left-hand MPI - * \param B Right-hand MPI + * \param X The destination MPI. This must point to an initialized MPI. + * \param A The minuend. This must point to an initialized MPI. + * \param B The subtrahend. This must point to an initialized MPI. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_NEGATIVE_VALUE if \p B is greater than \p A. + * \return Another negative error code on different kinds of failure. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if B is greater than A */ -int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); +int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** - * \brief Signed addition: X = A + B + * \brief Perform a signed addition of MPIs: X = A + B * - * \param X Destination MPI - * \param A Left-hand MPI - * \param B Right-hand MPI + * \param X The destination MPI. This must point to an initialized MPI. + * \param A The first summand. This must point to an initialized MPI. + * \param B The second summand. This must point to an initialized MPI. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); +int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** - * \brief Signed subtraction: X = A - B + * \brief Perform a signed subtraction of MPIs: X = A - B * - * \param X Destination MPI - * \param A Left-hand MPI - * \param B Right-hand MPI + * \param X The destination MPI. This must point to an initialized MPI. + * \param A The minuend. This must point to an initialized MPI. + * \param B The subtrahend. This must point to an initialized MPI. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); +int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** - * \brief Signed addition: X = A + b + * \brief Perform a signed addition of an MPI and an integer: X = A + b * - * \param X Destination MPI - * \param A Left-hand MPI - * \param b The integer value to add + * \param X The destination MPI. This must point to an initialized MPI. + * \param A The first summand. This must point to an initialized MPI. + * \param b The second summand. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b ); +int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, + mbedtls_mpi_sint b ); /** - * \brief Signed subtraction: X = A - b + * \brief Perform a signed subtraction of an MPI and an integer: + * X = A - b * - * \param X Destination MPI - * \param A Left-hand MPI - * \param b The integer value to subtract + * \param X The destination MPI. This must point to an initialized MPI. + * \param A The minuend. This must point to an initialized MPI. + * \param b The subtrahend. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b ); +int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, + mbedtls_mpi_sint b ); /** - * \brief Baseline multiplication: X = A * B + * \brief Perform a multiplication of two MPIs: X = A * B + * + * \param X The destination MPI. This must point to an initialized MPI. + * \param A The first factor. This must point to an initialized MPI. + * \param B The second factor. This must point to an initialized MPI. * - * \param X Destination MPI - * \param A Left-hand MPI - * \param B Right-hand MPI + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return Another negative error code on different kinds of failure. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed */ -int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ); +int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** - * \brief Baseline multiplication: X = A * b + * \brief Perform a multiplication of an MPI with an unsigned integer: + * X = A * b * - * \param X Destination MPI - * \param A Left-hand MPI - * \param b The unsigned integer value to multiply with + * \param X The destination MPI. This must point to an initialized MPI. + * \param A The first factor. This must point to an initialized MPI. + * \param b The second factor. * - * \note b is unsigned + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return Another negative error code on different kinds of failure. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed */ -int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b ); +int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, + mbedtls_mpi_uint b ); /** - * \brief Division by mbedtls_mpi: A = Q * B + R + * \brief Perform a division with remainder of two MPIs: + * A = Q * B + R * - * \param Q Destination MPI for the quotient - * \param R Destination MPI for the rest value - * \param A Left-hand MPI - * \param B Right-hand MPI + * \param Q The destination MPI for the quotient. + * This may be \c NULL if the value of the + * quotient is not needed. + * \param R The destination MPI for the remainder value. + * This may be \c NULL if the value of the + * remainder is not needed. + * \param A The dividend. This must point to an initialized MPi. + * \param B The divisor. This must point to an initialized MPI. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, - * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if B == 0 - * - * \note Either Q or R can be NULL. + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. + * \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p B equals zero. + * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B ); +int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** - * \brief Division by int: A = Q * b + R - * - * \param Q Destination MPI for the quotient - * \param R Destination MPI for the rest value - * \param A Left-hand MPI - * \param b Integer to divide by + * \brief Perform a division with remainder of an MPI by an integer: + * A = Q * b + R * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, - * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if b == 0 + * \param Q The destination MPI for the quotient. + * This may be \c NULL if the value of the + * quotient is not needed. + * \param R The destination MPI for the remainder value. + * This may be \c NULL if the value of the + * remainder is not needed. + * \param A The dividend. This must point to an initialized MPi. + * \param b The divisor. * - * \note Either Q or R can be NULL. + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. + * \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p b equals zero. + * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, mbedtls_mpi_sint b ); +int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, + mbedtls_mpi_sint b ); /** - * \brief Modulo: R = A mod B + * \brief Perform a modular reduction. R = A mod B * - * \param R Destination MPI for the rest value - * \param A Left-hand MPI - * \param B Right-hand MPI + * \param R The destination MPI for the residue value. + * This must point to an initialized MPI. + * \param A The MPI to compute the residue of. + * This must point to an initialized MPI. + * \param B The base of the modular reduction. + * This must point to an initialized MPI. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p B equals zero. + * \return #MBEDTLS_ERR_MPI_NEGATIVE_VALUE if \p B is negative. + * \return Another negative error code on different kinds of failure. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, - * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if B == 0, - * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if B < 0 */ -int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B ); +int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** - * \brief Modulo: r = A mod b + * \brief Perform a modular reduction with respect to an integer. + * r = A mod b * - * \param r Destination mbedtls_mpi_uint - * \param A Left-hand MPI - * \param b Integer to divide by + * \param r The address at which to store the residue. + * This must not be \c NULL. + * \param A The MPI to compute the residue of. + * This must point to an initialized MPi. + * \param b The integer base of the modular reduction. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, - * MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if b == 0, - * MBEDTLS_ERR_MPI_NEGATIVE_VALUE if b < 0 + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p b equals zero. + * \return #MBEDTLS_ERR_MPI_NEGATIVE_VALUE if \p b is negative. + * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b ); +int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, + mbedtls_mpi_sint b ); /** - * \brief Sliding-window exponentiation: X = A^E mod N - * - * \param X Destination MPI - * \param A Left-hand MPI - * \param E Exponent MPI - * \param N Modular MPI - * \param _RR Speed-up MPI used for recalculations + * \brief Perform a sliding-window exponentiation: X = A^E mod N * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, - * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is negative or even or - * if E is negative + * \param X The destination MPI. This must point to an initialized MPI. + * \param A The base of the exponentiation. + * This must point to an initialized MPI. + * \param E The exponent MPI. This must point to an initialized MPI. + * \param N The base for the modular reduction. This must point to an + * initialized MPI. + * \param _RR A helper MPI depending solely on \p N which can be used to + * speed-up multiple modular exponentiations for the same value + * of \p N. This may be \c NULL. If it is not \c NULL, it must + * point to an initialized MPI. If it hasn't been used after + * the call to mbedtls_mpi_init(), this function will compute + * the helper value and store it in \p _RR for reuse on + * subsequent calls to this function. Otherwise, the function + * will assume that \p _RR holds the helper value set by a + * previous call to mbedtls_mpi_exp_mod(), and reuse it. + * + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \c N is negative or + * even, or if \c E is negative. + * \return Another negative error code on different kinds of failures. * - * \note _RR is used to avoid re-computing R*R mod N across - * multiple calls, which speeds up things a bit. It can - * be set to NULL if the extra performance is unneeded. */ -int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_mpi *N, mbedtls_mpi *_RR ); +int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *E, const mbedtls_mpi *N, + mbedtls_mpi *_RR ); /** - * \brief Fill an MPI X with size bytes of random + * \brief Fill an MPI with a number of random bytes. * - * \param X Destination MPI - * \param size Size in bytes - * \param f_rng RNG function - * \param p_rng RNG parameter + * \param X The destination MPI. This must point to an initialized MPI. + * \param size The number of random bytes to generate. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG parameter to be passed to \p f_rng. This may be + * \c NULL if \p f_rng doesn't need a context argument. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return Another negative error code on failure. * - * \note The bytes obtained from the PRNG are interpreted + * \note The bytes obtained from the RNG are interpreted * as a big-endian representation of an MPI; this can * be relevant in applications like deterministic ECDSA. */ @@ -694,64 +821,135 @@ int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size, void *p_rng ); /** - * \brief Greatest common divisor: G = gcd(A, B) - * - * \param G Destination MPI - * \param A Left-hand MPI - * \param B Right-hand MPI - * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed - */ -int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B ); - -/** - * \brief Modular inverse: X = A^-1 mod N + * \brief Compute the greatest common divisor: G = gcd(A, B) * - * \param X Destination MPI - * \param A Left-hand MPI - * \param N Right-hand MPI + * \param G The destination MPI. This must point to an initialized MPI. + * \param A The first operand. This must point to an initialized MPI. + * \param B The second operand. This must point to an initialized MPI. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, - * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if N is <= 1, - MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N. + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N ); +int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** - * \brief Miller-Rabin primality test + * \brief Compute the modular inverse: X = A^-1 mod N * - * \param X MPI to check - * \param f_rng RNG function - * \param p_rng RNG parameter + * \param X The destination MPI. This must point to an initialized MPI. + * \param A The MPI to calculate the modular inverse of. This must point + * to an initialized MPI. + * \param N The base of the modular inversion. This must point to an + * initialized MPI. * - * \return 0 if successful (probably prime), - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, - * MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if X is not prime + * \return \c 0 if successful. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p N is less than + * or equal to one. + * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p has no modular inverse + * with respect to \p N. */ -int mbedtls_mpi_is_prime( const mbedtls_mpi *X, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng ); +int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *N ); +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +#if defined(MBEDTLS_DEPRECATED_WARNING) +#define MBEDTLS_DEPRECATED __attribute__((deprecated)) +#else +#define MBEDTLS_DEPRECATED +#endif /** - * \brief Prime number generation - * - * \param X Destination MPI - * \param nbits Required size of X in bits - * ( 3 <= nbits <= MBEDTLS_MPI_MAX_BITS ) - * \param dh_flag If 1, then (X-1)/2 will be prime too - * \param f_rng RNG function - * \param p_rng RNG parameter - * - * \return 0 if successful (probably prime), - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, - * MBEDTLS_ERR_MPI_BAD_INPUT_DATA if nbits is < 3 - */ -int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int dh_flag, + * \brief Perform a Miller-Rabin primality test with error + * probability of 2-80. + * + * \deprecated Superseded by mbedtls_mpi_is_prime_ext() which allows + * specifying the number of Miller-Rabin rounds. + * + * \param X The MPI to check for primality. + * This must point to an initialized MPI. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG parameter to be passed to \p f_rng. + * This may be \c NULL if \p f_rng doesn't use a + * context parameter. + * + * \return \c 0 if successful, i.e. \p X is probably prime. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p X is not prime. + * \return Another negative error code on other kinds of failure. + */ +MBEDTLS_DEPRECATED int mbedtls_mpi_is_prime( const mbedtls_mpi *X, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); +#undef MBEDTLS_DEPRECATED +#endif /* !MBEDTLS_DEPRECATED_REMOVED */ + +/** + * \brief Miller-Rabin primality test. + * + * \warning If \p X is potentially generated by an adversary, for example + * when validating cryptographic parameters that you didn't + * generate yourself and that are supposed to be prime, then + * \p rounds should be at least the half of the security + * strength of the cryptographic algorithm. On the other hand, + * if \p X is chosen uniformly or non-adversially (as is the + * case when mbedtls_mpi_gen_prime calls this function), then + * \p rounds can be much lower. + * + * \param X The MPI to check for primality. + * This must point to an initialized MPI. + * \param rounds The number of bases to perform the Miller-Rabin primality + * test for. The probability of returning 0 on a composite is + * at most 2-2*\p rounds. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG parameter to be passed to \p f_rng. + * This may be \c NULL if \p f_rng doesn't use + * a context parameter. + * + * \return \c 0 if successful, i.e. \p X is probably prime. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p X is not prime. + * \return Another negative error code on other kinds of failure. + */ +int mbedtls_mpi_is_prime_ext( const mbedtls_mpi *X, int rounds, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); +/** + * \brief Flags for mbedtls_mpi_gen_prime() + * + * Each of these flags is a constraint on the result X returned by + * mbedtls_mpi_gen_prime(). + */ +typedef enum { + MBEDTLS_MPI_GEN_PRIME_FLAG_DH = 0x0001, /**< (X-1)/2 is prime too */ + MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR = 0x0002, /**< lower error rate from 2-80 to 2-128 */ +} mbedtls_mpi_gen_prime_flag_t; + +/** + * \brief Generate a prime number. + * + * \param X The destination MPI to store the generated prime in. + * This must point to an initialized MPi. + * \param nbits The required size of the destination MPI in bits. + * This must be between \c 3 and #MBEDTLS_MPI_MAX_BITS. + * \param flags A mask of flags of type #mbedtls_mpi_gen_prime_flag_t. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG parameter to be passed to \p f_rng. + * This may be \c NULL if \p f_rng doesn't use + * a context parameter. + * + * \return \c 0 if successful, in which case \p X holds a + * probably prime number. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. + * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if `nbits` is not between + * \c 3 and #MBEDTLS_MPI_MAX_BITS. + */ +int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); +#if defined(MBEDTLS_SELF_TEST) + /** * \brief Checkup routine * @@ -759,6 +957,8 @@ int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int dh_flag, */ int mbedtls_mpi_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/blowfish.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/blowfish.h index c0ef5a04cc..f01573dcaf 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/blowfish.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/blowfish.h @@ -33,6 +33,8 @@ #include #include +#include "platform_util.h" + #define MBEDTLS_BLOWFISH_ENCRYPT 1 #define MBEDTLS_BLOWFISH_DECRYPT 0 #define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448 @@ -40,63 +42,87 @@ #define MBEDTLS_BLOWFISH_ROUNDS 16 /**< Rounds to use. When increasing this value, make sure to extend the initialisation vectors */ #define MBEDTLS_BLOWFISH_BLOCKSIZE 8 /* Blowfish uses 64 bit blocks */ -#define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016 /**< Invalid key length. */ -#define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017 /**< Blowfish hardware accelerator failed. */ -#define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 /**< Invalid data input length. */ +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +#define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0016 ) +#endif /* !MBEDTLS_DEPRECATED_REMOVED */ +#define MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA -0x0016 /**< Bad input data. */ -#if !defined(MBEDTLS_BLOWFISH_ALT) -// Regular implementation -// +#define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 /**< Invalid data input length. */ + +/* MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED is deprecated and should not be used. + */ +#define MBEDTLS_ERR_BLOWFISH_HW_ACCEL_FAILED -0x0017 /**< Blowfish hardware accelerator failed. */ #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_BLOWFISH_ALT) +// Regular implementation +// + /** * \brief Blowfish context structure */ -typedef struct +typedef struct mbedtls_blowfish_context { uint32_t P[MBEDTLS_BLOWFISH_ROUNDS + 2]; /*!< Blowfish round keys */ uint32_t S[4][256]; /*!< key dependent S-boxes */ } mbedtls_blowfish_context; +#else /* MBEDTLS_BLOWFISH_ALT */ +#include "blowfish_alt.h" +#endif /* MBEDTLS_BLOWFISH_ALT */ + /** - * \brief Initialize Blowfish context + * \brief Initialize a Blowfish context. * - * \param ctx Blowfish context to be initialized + * \param ctx The Blowfish context to be initialized. + * This must not be \c NULL. */ void mbedtls_blowfish_init( mbedtls_blowfish_context *ctx ); /** - * \brief Clear Blowfish context + * \brief Clear a Blowfish context. * - * \param ctx Blowfish context to be cleared + * \param ctx The Blowfish context to be cleared. + * This may be \c NULL, in which case this function + * returns immediately. If it is not \c NULL, it must + * point to an initialized Blowfish context. */ void mbedtls_blowfish_free( mbedtls_blowfish_context *ctx ); /** - * \brief Blowfish key schedule + * \brief Perform a Blowfish key schedule operation. * - * \param ctx Blowfish context to be initialized - * \param key encryption key - * \param keybits must be between 32 and 448 bits + * \param ctx The Blowfish context to perform the key schedule on. + * \param key The encryption key. This must be a readable buffer of + * length \p keybits Bits. + * \param keybits The length of \p key in Bits. This must be between + * \c 32 and \c 448 and a multiple of \c 8. * - * \return 0 if successful, or MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_blowfish_setkey( mbedtls_blowfish_context *ctx, const unsigned char *key, unsigned int keybits ); /** - * \brief Blowfish-ECB block encryption/decryption + * \brief Perform a Blowfish-ECB block encryption/decryption operation. * - * \param ctx Blowfish context - * \param mode MBEDTLS_BLOWFISH_ENCRYPT or MBEDTLS_BLOWFISH_DECRYPT - * \param input 8-byte input block - * \param output 8-byte output block + * \param ctx The Blowfish context to use. This must be initialized + * and bound to a key. + * \param mode The mode of operation. Possible values are + * #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or + * #MBEDTLS_BLOWFISH_DECRYPT for decryption. + * \param input The input block. This must be a readable buffer + * of size \c 8 Bytes. + * \param output The output block. This must be a writable buffer + * of size \c 8 Bytes. * - * \return 0 if successful + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_blowfish_crypt_ecb( mbedtls_blowfish_context *ctx, int mode, @@ -105,9 +131,7 @@ int mbedtls_blowfish_crypt_ecb( mbedtls_blowfish_context *ctx, #if defined(MBEDTLS_CIPHER_MODE_CBC) /** - * \brief Blowfish-CBC buffer encryption/decryption - * Length should be a multiple of the block - * size (8 bytes) + * \brief Perform a Blowfish-CBC buffer encryption/decryption operation. * * \note Upon exit, the content of the IV is updated so that you can * call the function same function again on the following @@ -117,15 +141,22 @@ int mbedtls_blowfish_crypt_ecb( mbedtls_blowfish_context *ctx, * IV, you should either save it manually or use the cipher * module instead. * - * \param ctx Blowfish context - * \param mode MBEDTLS_BLOWFISH_ENCRYPT or MBEDTLS_BLOWFISH_DECRYPT - * \param length length of the input data - * \param iv initialization vector (updated after use) - * \param input buffer holding the input data - * \param output buffer holding the output data + * \param ctx The Blowfish context to use. This must be initialized + * and bound to a key. + * \param mode The mode of operation. Possible values are + * #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or + * #MBEDTLS_BLOWFISH_DECRYPT for decryption. + * \param length The length of the input data in Bytes. This must be + * multiple of \c 8. + * \param iv The initialization vector. This must be a read/write buffer + * of length \c 8 Bytes. It is updated by this function. + * \param input The input data. This must be a readable buffer of length + * \p length Bytes. + * \param output The output data. This must be a writable buffer of length + * \p length Bytes. * - * \return 0 if successful, or - * MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx, int mode, @@ -137,7 +168,7 @@ int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx, #if defined(MBEDTLS_CIPHER_MODE_CFB) /** - * \brief Blowfish CFB buffer encryption/decryption. + * \brief Perform a Blowfish CFB buffer encryption/decryption operation. * * \note Upon exit, the content of the IV is updated so that you can * call the function same function again on the following @@ -147,15 +178,25 @@ int mbedtls_blowfish_crypt_cbc( mbedtls_blowfish_context *ctx, * IV, you should either save it manually or use the cipher * module instead. * - * \param ctx Blowfish context - * \param mode MBEDTLS_BLOWFISH_ENCRYPT or MBEDTLS_BLOWFISH_DECRYPT - * \param length length of the input data - * \param iv_off offset in IV (updated after use) - * \param iv initialization vector (updated after use) - * \param input buffer holding the input data - * \param output buffer holding the output data + * \param ctx The Blowfish context to use. This must be initialized + * and bound to a key. + * \param mode The mode of operation. Possible values are + * #MBEDTLS_BLOWFISH_ENCRYPT for encryption, or + * #MBEDTLS_BLOWFISH_DECRYPT for decryption. + * \param length The length of the input data in Bytes. + * \param iv_off The offset in the initialiation vector. + * The value pointed to must be smaller than \c 8 Bytes. + * It is updated by this function to support the aforementioned + * streaming usage. + * \param iv The initialization vector. This must be a read/write buffer + * of size \c 8 Bytes. It is updated after use. + * \param input The input data. This must be a readable buffer of length + * \p length Bytes. + * \param output The output data. This must be a writable buffer of length + * \p length Bytes. * - * \return 0 if successful + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx, int mode, @@ -168,22 +209,67 @@ int mbedtls_blowfish_crypt_cfb64( mbedtls_blowfish_context *ctx, #if defined(MBEDTLS_CIPHER_MODE_CTR) /** - * \brief Blowfish-CTR buffer encryption/decryption + * \brief Perform a Blowfish-CTR buffer encryption/decryption operation. + * + * \warning You must never reuse a nonce value with the same key. Doing so + * would void the encryption for the two messages encrypted with + * the same nonce and key. + * + * There are two common strategies for managing nonces with CTR: + * + * 1. You can handle everything as a single message processed over + * successive calls to this function. In that case, you want to + * set \p nonce_counter and \p nc_off to 0 for the first call, and + * then preserve the values of \p nonce_counter, \p nc_off and \p + * stream_block across calls to this function as they will be + * updated by this function. + * + * With this strategy, you must not encrypt more than 2**64 + * blocks of data with the same key. + * + * 2. You can encrypt separate messages by dividing the \p + * nonce_counter buffer in two areas: the first one used for a + * per-message nonce, handled by yourself, and the second one + * updated by this function internally. + * + * For example, you might reserve the first 4 bytes for the + * per-message nonce, and the last 4 bytes for internal use. In that + * case, before calling this function on a new message you need to + * set the first 4 bytes of \p nonce_counter to your chosen nonce + * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p + * stream_block to be ignored). That way, you can encrypt at most + * 2**32 messages of up to 2**32 blocks each with the same key. * - * Warning: You have to keep the maximum use of your counter in mind! + * The per-message nonce (or information sufficient to reconstruct + * it) needs to be communicated with the ciphertext and must be unique. + * The recommended way to ensure uniqueness is to use a message + * counter. * - * \param ctx Blowfish context - * \param length The length of the data + * Note that for both stategies, sizes are measured in blocks and + * that a Blowfish block is 8 bytes. + * + * \warning Upon return, \p stream_block contains sensitive data. Its + * content must not be written to insecure storage and should be + * securely discarded as soon as it's no longer needed. + * + * \param ctx The Blowfish context to use. This must be initialized + * and bound to a key. + * \param length The length of the input data in Bytes. * \param nc_off The offset in the current stream_block (for resuming - * within current cipher stream). The offset pointer to - * should be 0 at the start of a stream. - * \param nonce_counter The 64-bit nonce and counter. - * \param stream_block The saved stream-block for resuming. Is overwritten - * by the function. - * \param input The input data stream - * \param output The output data stream - * - * \return 0 if successful + * within current cipher stream). The offset pointer + * should be \c 0 at the start of a stream and must be + * smaller than \c 8. It is updated by this function. + * \param nonce_counter The 64-bit nonce and counter. This must point to a + * read/write buffer of length \c 8 Bytes. + * \param stream_block The saved stream-block for resuming. This must point to + * a read/write buffer of length \c 8 Bytes. + * \param input The input data. This must be a readable buffer of + * length \p length Bytes. + * \param output The output data. This must be a writable buffer of + * length \p length Bytes. + * + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx, size_t length, @@ -198,8 +284,4 @@ int mbedtls_blowfish_crypt_ctr( mbedtls_blowfish_context *ctx, } #endif -#else /* MBEDTLS_BLOWFISH_ALT */ -#include "blowfish_alt.h" -#endif /* MBEDTLS_BLOWFISH_ALT */ - #endif /* blowfish.h */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/bn_mul.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/bn_mul.h index 3a254aae9d..c33bd8d4ab 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/bn_mul.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/bn_mul.h @@ -571,9 +571,8 @@ #endif /* TriCore */ /* - * gcc -O0 by default uses r7 for the frame pointer, so it complains about our - * use of r7 below, unless -fomit-frame-pointer is passed. Unfortunately, - * passing that option is not easy when building with yotta. + * Note, gcc -O0 by default uses r7 for the frame pointer, so it complains about + * our use of r7 below, unless -fomit-frame-pointer is passed. * * On the other hand, -fomit-frame-pointer is implied by any -Ox options with * x !=0, which we can detect using __OPTIMIZE__ (which is also defined by @@ -643,6 +642,23 @@ "r6", "r7", "r8", "r9", "cc" \ ); +#elif defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1) + +#define MULADDC_INIT \ + asm( + +#define MULADDC_CORE \ + "ldr r0, [%0], #4 \n\t" \ + "ldr r1, [%1] \n\t" \ + "umaal r1, %2, %3, r0 \n\t" \ + "str r1, [%1], #4 \n\t" + +#define MULADDC_STOP \ + : "=r" (s), "=r" (d), "=r" (c) \ + : "r" (b), "0" (s), "1" (d), "2" (c) \ + : "r0", "r1", "memory" \ + ); + #else #define MULADDC_INIT \ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/camellia.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/camellia.h index cf07629d9b..3eeb66366d 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/camellia.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/camellia.h @@ -33,78 +33,107 @@ #include #include +#include "platform_util.h" + #define MBEDTLS_CAMELLIA_ENCRYPT 1 #define MBEDTLS_CAMELLIA_DECRYPT 0 -#define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0024 /**< Invalid key length. */ -#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */ -#define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027 /**< Camellia hardware accelerator failed. */ +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +#define MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( -0x0024 ) +#endif /* !MBEDTLS_DEPRECATED_REMOVED */ +#define MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA -0x0024 /**< Bad input data. */ -#if !defined(MBEDTLS_CAMELLIA_ALT) -// Regular implementation -// +#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */ + +/* MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED is deprecated and should not be used. + */ +#define MBEDTLS_ERR_CAMELLIA_HW_ACCEL_FAILED -0x0027 /**< Camellia hardware accelerator failed. */ #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_CAMELLIA_ALT) +// Regular implementation +// + /** * \brief CAMELLIA context structure */ -typedef struct +typedef struct mbedtls_camellia_context { int nr; /*!< number of rounds */ uint32_t rk[68]; /*!< CAMELLIA round keys */ } mbedtls_camellia_context; +#else /* MBEDTLS_CAMELLIA_ALT */ +#include "camellia_alt.h" +#endif /* MBEDTLS_CAMELLIA_ALT */ + /** - * \brief Initialize CAMELLIA context + * \brief Initialize a CAMELLIA context. * - * \param ctx CAMELLIA context to be initialized + * \param ctx The CAMELLIA context to be initialized. + * This must not be \c NULL. */ void mbedtls_camellia_init( mbedtls_camellia_context *ctx ); /** - * \brief Clear CAMELLIA context + * \brief Clear a CAMELLIA context. * - * \param ctx CAMELLIA context to be cleared + * \param ctx The CAMELLIA context to be cleared. This may be \c NULL, + * in which case this function returns immediately. If it is not + * \c NULL, it must be initialized. */ void mbedtls_camellia_free( mbedtls_camellia_context *ctx ); /** - * \brief CAMELLIA key schedule (encryption) + * \brief Perform a CAMELLIA key schedule operation for encryption. * - * \param ctx CAMELLIA context to be initialized - * \param key encryption key - * \param keybits must be 128, 192 or 256 + * \param ctx The CAMELLIA context to use. This must be initialized. + * \param key The encryption key to use. This must be a readable buffer + * of size \p keybits Bits. + * \param keybits The length of \p key in Bits. This must be either \c 128, + * \c 192 or \c 256. * - * \return 0 if successful, or MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH + * \return \c 0 if successful. + * \return A negative error code on failure. */ -int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, const unsigned char *key, - unsigned int keybits ); +int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, + const unsigned char *key, + unsigned int keybits ); /** - * \brief CAMELLIA key schedule (decryption) + * \brief Perform a CAMELLIA key schedule operation for decryption. * - * \param ctx CAMELLIA context to be initialized - * \param key decryption key - * \param keybits must be 128, 192 or 256 + * \param ctx The CAMELLIA context to use. This must be initialized. + * \param key The decryption key. This must be a readable buffer + * of size \p keybits Bits. + * \param keybits The length of \p key in Bits. This must be either \c 128, + * \c 192 or \c 256. * - * \return 0 if successful, or MBEDTLS_ERR_CAMELLIA_INVALID_KEY_LENGTH + * \return \c 0 if successful. + * \return A negative error code on failure. */ -int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, const unsigned char *key, - unsigned int keybits ); +int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, + const unsigned char *key, + unsigned int keybits ); /** - * \brief CAMELLIA-ECB block encryption/decryption + * \brief Perform a CAMELLIA-ECB block encryption/decryption operation. * - * \param ctx CAMELLIA context - * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT - * \param input 16-byte input block - * \param output 16-byte output block + * \param ctx The CAMELLIA context to use. This must be initialized + * and bound to a key. + * \param mode The mode of operation. This must be either + * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT. + * \param input The input block. This must be a readable buffer + * of size \c 16 Bytes. + * \param output The output block. This must be a writable buffer + * of size \c 16 Bytes. * - * \return 0 if successful + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx, int mode, @@ -113,9 +142,7 @@ int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx, #if defined(MBEDTLS_CIPHER_MODE_CBC) /** - * \brief CAMELLIA-CBC buffer encryption/decryption - * Length should be a multiple of the block - * size (16 bytes) + * \brief Perform a CAMELLIA-CBC buffer encryption/decryption operation. * * \note Upon exit, the content of the IV is updated so that you can * call the function same function again on the following @@ -125,15 +152,22 @@ int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx, * IV, you should either save it manually or use the cipher * module instead. * - * \param ctx CAMELLIA context - * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT - * \param length length of the input data - * \param iv initialization vector (updated after use) - * \param input buffer holding the input data - * \param output buffer holding the output data + * \param ctx The CAMELLIA context to use. This must be initialized + * and bound to a key. + * \param mode The mode of operation. This must be either + * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT. + * \param length The length in Bytes of the input data \p input. + * This must be a multiple of \c 16 Bytes. + * \param iv The initialization vector. This must be a read/write buffer + * of length \c 16 Bytes. It is updated to allow streaming + * use as explained above. + * \param input The buffer holding the input data. This must point to a + * readable buffer of length \p length Bytes. + * \param output The buffer holding the output data. This must point to a + * writable buffer of length \p length Bytes. * - * \return 0 if successful, or - * MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx, int mode, @@ -145,11 +179,14 @@ int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx, #if defined(MBEDTLS_CIPHER_MODE_CFB) /** - * \brief CAMELLIA-CFB128 buffer encryption/decryption + * \brief Perform a CAMELLIA-CFB128 buffer encryption/decryption + * operation. * - * Note: Due to the nature of CFB you should use the same key schedule for - * both encryption and decryption. So a context initialized with - * mbedtls_camellia_setkey_enc() for both MBEDTLS_CAMELLIA_ENCRYPT and CAMELLIE_DECRYPT. + * \note Due to the nature of CFB mode, you should use the same + * key for both encryption and decryption. In particular, calls + * to this function should be preceded by a key-schedule via + * mbedtls_camellia_setkey_enc() regardless of whether \p mode + * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT. * * \note Upon exit, the content of the IV is updated so that you can * call the function same function again on the following @@ -159,16 +196,24 @@ int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx, * IV, you should either save it manually or use the cipher * module instead. * - * \param ctx CAMELLIA context - * \param mode MBEDTLS_CAMELLIA_ENCRYPT or MBEDTLS_CAMELLIA_DECRYPT - * \param length length of the input data - * \param iv_off offset in IV (updated after use) - * \param iv initialization vector (updated after use) - * \param input buffer holding the input data - * \param output buffer holding the output data + * \param ctx The CAMELLIA context to use. This must be initialized + * and bound to a key. + * \param mode The mode of operation. This must be either + * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT. + * \param length The length of the input data \p input. Any value is allowed. + * \param iv_off The current offset in the IV. This must be smaller + * than \c 16 Bytes. It is updated after this call to allow + * the aforementioned streaming usage. + * \param iv The initialization vector. This must be a read/write buffer + * of length \c 16 Bytes. It is updated after this call to + * allow the aforementioned streaming usage. + * \param input The buffer holding the input data. This must be a readable + * buffer of size \p length Bytes. + * \param output The buffer to hold the output data. This must be a writable + * buffer of length \p length Bytes. * - * \return 0 if successful, or - * MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx, int mode, @@ -181,26 +226,78 @@ int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx, #if defined(MBEDTLS_CIPHER_MODE_CTR) /** - * \brief CAMELLIA-CTR buffer encryption/decryption + * \brief Perform a CAMELLIA-CTR buffer encryption/decryption operation. + * + * *note Due to the nature of CTR mode, you should use the same + * key for both encryption and decryption. In particular, calls + * to this function should be preceded by a key-schedule via + * mbedtls_camellia_setkey_enc() regardless of whether \p mode + * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT. + * + * \warning You must never reuse a nonce value with the same key. Doing so + * would void the encryption for the two messages encrypted with + * the same nonce and key. + * + * There are two common strategies for managing nonces with CTR: * - * Warning: You have to keep the maximum use of your counter in mind! + * 1. You can handle everything as a single message processed over + * successive calls to this function. In that case, you want to + * set \p nonce_counter and \p nc_off to 0 for the first call, and + * then preserve the values of \p nonce_counter, \p nc_off and \p + * stream_block across calls to this function as they will be + * updated by this function. * - * Note: Due to the nature of CTR you should use the same key schedule for - * both encryption and decryption. So a context initialized with - * mbedtls_camellia_setkey_enc() for both MBEDTLS_CAMELLIA_ENCRYPT and MBEDTLS_CAMELLIA_DECRYPT. + * With this strategy, you must not encrypt more than 2**128 + * blocks of data with the same key. * - * \param ctx CAMELLIA context - * \param length The length of the data - * \param nc_off The offset in the current stream_block (for resuming + * 2. You can encrypt separate messages by dividing the \p + * nonce_counter buffer in two areas: the first one used for a + * per-message nonce, handled by yourself, and the second one + * updated by this function internally. + * + * For example, you might reserve the first \c 12 Bytes for the + * per-message nonce, and the last \c 4 Bytes for internal use. + * In that case, before calling this function on a new message you + * need to set the first \c 12 Bytes of \p nonce_counter to your + * chosen nonce value, the last four to \c 0, and \p nc_off to \c 0 + * (which will cause \p stream_block to be ignored). That way, you + * can encrypt at most \c 2**96 messages of up to \c 2**32 blocks + * each with the same key. + * + * The per-message nonce (or information sufficient to reconstruct + * it) needs to be communicated with the ciphertext and must be + * unique. The recommended way to ensure uniqueness is to use a + * message counter. An alternative is to generate random nonces, + * but this limits the number of messages that can be securely + * encrypted: for example, with 96-bit random nonces, you should + * not encrypt more than 2**32 messages with the same key. + * + * Note that for both stategies, sizes are measured in blocks and + * that a CAMELLIA block is \c 16 Bytes. + * + * \warning Upon return, \p stream_block contains sensitive data. Its + * content must not be written to insecure storage and should be + * securely discarded as soon as it's no longer needed. + * + * \param ctx The CAMELLIA context to use. This must be initialized + * and bound to a key. + * \param length The length of the input data \p input in Bytes. + * Any value is allowed. + * \param nc_off The offset in the current \p stream_block (for resuming * within current cipher stream). The offset pointer to - * should be 0 at the start of a stream. - * \param nonce_counter The 128-bit nonce and counter. - * \param stream_block The saved stream-block for resuming. Is overwritten - * by the function. - * \param input The input data stream - * \param output The output data stream - * - * \return 0 if successful + * should be \c 0 at the start of a stream. It is updated + * at the end of this call. + * \param nonce_counter The 128-bit nonce and counter. This must be a read/write + * buffer of length \c 16 Bytes. + * \param stream_block The saved stream-block for resuming. This must be a + * read/write buffer of length \c 16 Bytes. + * \param input The input data stream. This must be a readable buffer of + * size \p length Bytes. + * \param output The output data stream. This must be a writable buffer + * of size \p length Bytes. + * + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx, size_t length, @@ -211,17 +308,7 @@ int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx, unsigned char *output ); #endif /* MBEDTLS_CIPHER_MODE_CTR */ -#ifdef __cplusplus -} -#endif - -#else /* MBEDTLS_CAMELLIA_ALT */ -#include "camellia_alt.h" -#endif /* MBEDTLS_CAMELLIA_ALT */ - -#ifdef __cplusplus -extern "C" { -#endif +#if defined(MBEDTLS_SELF_TEST) /** * \brief Checkup routine @@ -230,6 +317,8 @@ extern "C" { */ int mbedtls_camellia_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ccm.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ccm.h index e311e751d5..f03e3b580e 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ccm.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ccm.h @@ -1,8 +1,11 @@ /** * \file ccm.h * - * \brief CCM combines Counter mode encryption with CBC-MAC authentication - * for 128-bit block ciphers. + * \brief This file provides an API for the CCM authenticated encryption + * mode for block ciphers. + * + * CCM combines Counter mode encryption with CBC-MAC authentication + * for 128-bit block ciphers. * * Input to CCM includes the following elements: *
  • Payload - data that is both authenticated and encrypted.
  • @@ -11,6 +14,18 @@ *
  • Nonce - A unique value that is assigned to the payload and the * associated data.
* + * Definition of CCM: + * http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf + * RFC 3610 "Counter with CBC-MAC (CCM)" + * + * Related: + * RFC 5116 "An Interface and Algorithms for Authenticated Encryption" + * + * Definition of CCM*: + * IEEE 802.15.4 - IEEE Standard for Local and metropolitan area networks + * Integer representation is fixed most-significant-octet-first order and + * the representation of octets is most-significant-bit-first order. This is + * consistent with RFC 3610. */ /* * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved @@ -44,31 +59,38 @@ #define MBEDTLS_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to the function. */ #define MBEDTLS_ERR_CCM_AUTH_FAILED -0x000F /**< Authenticated decryption failed. */ -#define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011 /**< CCM hardware accelerator failed. */ -#if !defined(MBEDTLS_CCM_ALT) -// Regular implementation -// +/* MBEDTLS_ERR_CCM_HW_ACCEL_FAILED is deprecated and should not be used. */ +#define MBEDTLS_ERR_CCM_HW_ACCEL_FAILED -0x0011 /**< CCM hardware accelerator failed. */ #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_CCM_ALT) +// Regular implementation +// + /** * \brief The CCM context-type definition. The CCM context is passed * to the APIs called. */ -typedef struct { +typedef struct mbedtls_ccm_context +{ mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */ } mbedtls_ccm_context; +#else /* MBEDTLS_CCM_ALT */ +#include "ccm_alt.h" +#endif /* MBEDTLS_CCM_ALT */ + /** * \brief This function initializes the specified CCM context, * to make references valid, and prepare the context * for mbedtls_ccm_setkey() or mbedtls_ccm_free(). * - * \param ctx The CCM context to initialize. + * \param ctx The CCM context to initialize. This must not be \c NULL. */ void mbedtls_ccm_init( mbedtls_ccm_context *ctx ); @@ -76,12 +98,14 @@ void mbedtls_ccm_init( mbedtls_ccm_context *ctx ); * \brief This function initializes the CCM context set in the * \p ctx parameter and sets the encryption key. * - * \param ctx The CCM context to initialize. + * \param ctx The CCM context to initialize. This must be an initialized + * context. * \param cipher The 128-bit block cipher to use. - * \param key The encryption key. + * \param key The encryption key. This must not be \c NULL. * \param keybits The key size in bits. This must be acceptable by the cipher. * - * \return \c 0 on success, or a cipher-specific error code. + * \return \c 0 on success. + * \return A CCM or cipher-specific error code on failure. */ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx, mbedtls_cipher_id_t cipher, @@ -92,36 +116,96 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx, * \brief This function releases and clears the specified CCM context * and underlying cipher sub-context. * - * \param ctx The CCM context to clear. + * \param ctx The CCM context to clear. If this is \c NULL, the function + * has no effect. Otherwise, this must be initialized. */ void mbedtls_ccm_free( mbedtls_ccm_context *ctx ); /** * \brief This function encrypts a buffer using CCM. * - * \param ctx The CCM context to use for encryption. + * \note The tag is written to a separate buffer. To concatenate + * the \p tag with the \p output, as done in RFC-3610: + * Counter with CBC-MAC (CCM), use + * \p tag = \p output + \p length, and make sure that the + * output buffer is at least \p length + \p tag_len wide. + * + * \param ctx The CCM context to use for encryption. This must be + * initialized and bound to a key. * \param length The length of the input data in Bytes. - * \param iv Initialization vector (nonce). - * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13. - * \param add The additional data field. + * \param iv The initialization vector (nonce). This must be a readable + * buffer of at least \p iv_len Bytes. + * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, + * or 13. The length L of the message length field is + * 15 - \p iv_len. + * \param add The additional data field. If \p add_len is greater than + * zero, \p add must be a readable buffer of at least that + * length. * \param add_len The length of additional data in Bytes. - * Must be less than 2^16 - 2^8. - * \param input The buffer holding the input data. - * \param output The buffer holding the output data. - * Must be at least \p length Bytes wide. - * \param tag The buffer holding the tag. - * \param tag_len The length of the tag to generate in Bytes: + * This must be less than `2^16 - 2^8`. + * \param input The buffer holding the input data. If \p length is greater + * than zero, \p input must be a readable buffer of at least + * that length. + * \param output The buffer holding the output data. If \p length is greater + * than zero, \p output must be a writable buffer of at least + * that length. + * \param tag The buffer holding the authentication field. This must be a + * readable buffer of at least \p tag_len Bytes. + * \param tag_len The length of the authentication field to generate in Bytes: * 4, 6, 8, 10, 12, 14 or 16. * + * \return \c 0 on success. + * \return A CCM or cipher-specific error code on failure. + */ +int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, + const unsigned char *iv, size_t iv_len, + const unsigned char *add, size_t add_len, + const unsigned char *input, unsigned char *output, + unsigned char *tag, size_t tag_len ); + +/** + * \brief This function encrypts a buffer using CCM*. + * * \note The tag is written to a separate buffer. To concatenate * the \p tag with the \p output, as done in RFC-3610: * Counter with CBC-MAC (CCM), use * \p tag = \p output + \p length, and make sure that the * output buffer is at least \p length + \p tag_len wide. * + * \note When using this function in a variable tag length context, + * the tag length has to be encoded into the \p iv passed to + * this function. + * + * \param ctx The CCM context to use for encryption. This must be + * initialized and bound to a key. + * \param length The length of the input data in Bytes. + * \param iv The initialization vector (nonce). This must be a readable + * buffer of at least \p iv_len Bytes. + * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, + * or 13. The length L of the message length field is + * 15 - \p iv_len. + * \param add The additional data field. This must be a readable buffer of + * at least \p add_len Bytes. + * \param add_len The length of additional data in Bytes. + * This must be less than 2^16 - 2^8. + * \param input The buffer holding the input data. If \p length is greater + * than zero, \p input must be a readable buffer of at least + * that length. + * \param output The buffer holding the output data. If \p length is greater + * than zero, \p output must be a writable buffer of at least + * that length. + * \param tag The buffer holding the authentication field. This must be a + * readable buffer of at least \p tag_len Bytes. + * \param tag_len The length of the authentication field to generate in Bytes: + * 0, 4, 6, 8, 10, 12, 14 or 16. + * + * \warning Passing \c 0 as \p tag_len means that the message is no + * longer authenticated. + * * \return \c 0 on success. + * \return A CCM or cipher-specific error code on failure. */ -int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, +int mbedtls_ccm_star_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, const unsigned char *add, size_t add_len, const unsigned char *input, unsigned char *output, @@ -131,22 +215,32 @@ int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, * \brief This function performs a CCM authenticated decryption of a * buffer. * - * \param ctx The CCM context to use for decryption. + * \param ctx The CCM context to use for decryption. This must be + * initialized and bound to a key. * \param length The length of the input data in Bytes. - * \param iv Initialization vector. - * \param iv_len The length of the IV in Bytes: 7, 8, 9, 10, 11, 12, or 13. - * \param add The additional data field. + * \param iv The initialization vector (nonce). This must be a readable + * buffer of at least \p iv_len Bytes. + * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, + * or 13. The length L of the message length field is + * 15 - \p iv_len. + * \param add The additional data field. This must be a readable buffer + * of at least that \p add_len Bytes.. * \param add_len The length of additional data in Bytes. - * Must be less than 2^16 - 2^8. - * \param input The buffer holding the input data. - * \param output The buffer holding the output data. - * Must be at least \p length Bytes wide. - * \param tag The buffer holding the tag. - * \param tag_len The length of the tag in Bytes. + * This must be less than 2^16 - 2^8. + * \param input The buffer holding the input data. If \p length is greater + * than zero, \p input must be a readable buffer of at least + * that length. + * \param output The buffer holding the output data. If \p length is greater + * than zero, \p output must be a writable buffer of at least + * that length. + * \param tag The buffer holding the authentication field. This must be a + * readable buffer of at least \p tag_len Bytes. + * \param tag_len The length of the authentication field to generate in Bytes: * 4, 6, 8, 10, 12, 14 or 16. * - * \return 0 if successful and authenticated, or - * #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match. + * \return \c 0 on success. This indicates that the message is authentic. + * \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match. + * \return A cipher-specific error code on calculation failure. */ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, const unsigned char *iv, size_t iv_len, @@ -154,23 +248,57 @@ int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, const unsigned char *input, unsigned char *output, const unsigned char *tag, size_t tag_len ); -#ifdef __cplusplus -} -#endif - -#else /* MBEDTLS_CCM_ALT */ -#include "ccm_alt.h" -#endif /* MBEDTLS_CCM_ALT */ - -#ifdef __cplusplus -extern "C" { -#endif +/** + * \brief This function performs a CCM* authenticated decryption of a + * buffer. + * + * \note When using this function in a variable tag length context, + * the tag length has to be decoded from \p iv and passed to + * this function as \p tag_len. (\p tag needs to be adjusted + * accordingly.) + * + * \param ctx The CCM context to use for decryption. This must be + * initialized and bound to a key. + * \param length The length of the input data in Bytes. + * \param iv The initialization vector (nonce). This must be a readable + * buffer of at least \p iv_len Bytes. + * \param iv_len The length of the nonce in Bytes: 7, 8, 9, 10, 11, 12, + * or 13. The length L of the message length field is + * 15 - \p iv_len. + * \param add The additional data field. This must be a readable buffer of + * at least that \p add_len Bytes. + * \param add_len The length of additional data in Bytes. + * This must be less than 2^16 - 2^8. + * \param input The buffer holding the input data. If \p length is greater + * than zero, \p input must be a readable buffer of at least + * that length. + * \param output The buffer holding the output data. If \p length is greater + * than zero, \p output must be a writable buffer of at least + * that length. + * \param tag The buffer holding the authentication field. This must be a + * readable buffer of at least \p tag_len Bytes. + * \param tag_len The length of the authentication field in Bytes. + * 0, 4, 6, 8, 10, 12, 14 or 16. + * + * \warning Passing \c 0 as \p tag_len means that the message is nos + * longer authenticated. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match. + * \return A cipher-specific error code on calculation failure. + */ +int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, + const unsigned char *iv, size_t iv_len, + const unsigned char *add, size_t add_len, + const unsigned char *input, unsigned char *output, + const unsigned char *tag, size_t tag_len ); #if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) /** * \brief The CCM checkup routine. * - * \return \c 0 on success, or \c 1 on failure. + * \return \c 0 on success. + * \return \c 1 on failure. */ int mbedtls_ccm_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/certs.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/certs.h index b7c5708f85..179ebbbad2 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/certs.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/certs.h @@ -36,68 +36,214 @@ extern "C" { #endif +/* List of all PEM-encoded CA certificates, terminated by NULL; + * PEM encoded if MBEDTLS_PEM_PARSE_C is enabled, DER encoded + * otherwise. */ +extern const char * mbedtls_test_cas[]; +extern const size_t mbedtls_test_cas_len[]; + +/* List of all DER-encoded CA certificates, terminated by NULL */ +extern const unsigned char * mbedtls_test_cas_der[]; +extern const size_t mbedtls_test_cas_der_len[]; + #if defined(MBEDTLS_PEM_PARSE_C) /* Concatenation of all CA certificates in PEM format if available */ extern const char mbedtls_test_cas_pem[]; extern const size_t mbedtls_test_cas_pem_len; -#endif - -/* List of all CA certificates, terminated by NULL */ -extern const char * mbedtls_test_cas[]; -extern const size_t mbedtls_test_cas_len[]; +#endif /* MBEDTLS_PEM_PARSE_C */ /* - * Convenience for users who just want a certificate: - * RSA by default, or ECDSA if RSA is not available + * CA test certificates */ + +extern const char mbedtls_test_ca_crt_ec_pem[]; +extern const char mbedtls_test_ca_key_ec_pem[]; +extern const char mbedtls_test_ca_pwd_ec_pem[]; +extern const char mbedtls_test_ca_key_rsa_pem[]; +extern const char mbedtls_test_ca_pwd_rsa_pem[]; +extern const char mbedtls_test_ca_crt_rsa_sha1_pem[]; +extern const char mbedtls_test_ca_crt_rsa_sha256_pem[]; + +extern const unsigned char mbedtls_test_ca_crt_ec_der[]; +extern const unsigned char mbedtls_test_ca_key_ec_der[]; +extern const unsigned char mbedtls_test_ca_key_rsa_der[]; +extern const unsigned char mbedtls_test_ca_crt_rsa_sha1_der[]; +extern const unsigned char mbedtls_test_ca_crt_rsa_sha256_der[]; + +extern const size_t mbedtls_test_ca_crt_ec_pem_len; +extern const size_t mbedtls_test_ca_key_ec_pem_len; +extern const size_t mbedtls_test_ca_pwd_ec_pem_len; +extern const size_t mbedtls_test_ca_key_rsa_pem_len; +extern const size_t mbedtls_test_ca_pwd_rsa_pem_len; +extern const size_t mbedtls_test_ca_crt_rsa_sha1_pem_len; +extern const size_t mbedtls_test_ca_crt_rsa_sha256_pem_len; + +extern const size_t mbedtls_test_ca_crt_ec_der_len; +extern const size_t mbedtls_test_ca_key_ec_der_len; +extern const size_t mbedtls_test_ca_pwd_ec_der_len; +extern const size_t mbedtls_test_ca_key_rsa_der_len; +extern const size_t mbedtls_test_ca_pwd_rsa_der_len; +extern const size_t mbedtls_test_ca_crt_rsa_sha1_der_len; +extern const size_t mbedtls_test_ca_crt_rsa_sha256_der_len; + +/* Config-dependent dispatch between PEM and DER encoding + * (PEM if enabled, otherwise DER) */ + +extern const char mbedtls_test_ca_crt_ec[]; +extern const char mbedtls_test_ca_key_ec[]; +extern const char mbedtls_test_ca_pwd_ec[]; +extern const char mbedtls_test_ca_key_rsa[]; +extern const char mbedtls_test_ca_pwd_rsa[]; +extern const char mbedtls_test_ca_crt_rsa_sha1[]; +extern const char mbedtls_test_ca_crt_rsa_sha256[]; + +extern const size_t mbedtls_test_ca_crt_ec_len; +extern const size_t mbedtls_test_ca_key_ec_len; +extern const size_t mbedtls_test_ca_pwd_ec_len; +extern const size_t mbedtls_test_ca_key_rsa_len; +extern const size_t mbedtls_test_ca_pwd_rsa_len; +extern const size_t mbedtls_test_ca_crt_rsa_sha1_len; +extern const size_t mbedtls_test_ca_crt_rsa_sha256_len; + +/* Config-dependent dispatch between SHA-1 and SHA-256 + * (SHA-256 if enabled, otherwise SHA-1) */ + +extern const char mbedtls_test_ca_crt_rsa[]; +extern const size_t mbedtls_test_ca_crt_rsa_len; + +/* Config-dependent dispatch between EC and RSA + * (RSA if enabled, otherwise EC) */ + extern const char * mbedtls_test_ca_crt; -extern const size_t mbedtls_test_ca_crt_len; extern const char * mbedtls_test_ca_key; -extern const size_t mbedtls_test_ca_key_len; extern const char * mbedtls_test_ca_pwd; +extern const size_t mbedtls_test_ca_crt_len; +extern const size_t mbedtls_test_ca_key_len; extern const size_t mbedtls_test_ca_pwd_len; + +/* + * Server test certificates + */ + +extern const char mbedtls_test_srv_crt_ec_pem[]; +extern const char mbedtls_test_srv_key_ec_pem[]; +extern const char mbedtls_test_srv_pwd_ec_pem[]; +extern const char mbedtls_test_srv_key_rsa_pem[]; +extern const char mbedtls_test_srv_pwd_rsa_pem[]; +extern const char mbedtls_test_srv_crt_rsa_sha1_pem[]; +extern const char mbedtls_test_srv_crt_rsa_sha256_pem[]; + +extern const unsigned char mbedtls_test_srv_crt_ec_der[]; +extern const unsigned char mbedtls_test_srv_key_ec_der[]; +extern const unsigned char mbedtls_test_srv_key_rsa_der[]; +extern const unsigned char mbedtls_test_srv_crt_rsa_sha1_der[]; +extern const unsigned char mbedtls_test_srv_crt_rsa_sha256_der[]; + +extern const size_t mbedtls_test_srv_crt_ec_pem_len; +extern const size_t mbedtls_test_srv_key_ec_pem_len; +extern const size_t mbedtls_test_srv_pwd_ec_pem_len; +extern const size_t mbedtls_test_srv_key_rsa_pem_len; +extern const size_t mbedtls_test_srv_pwd_rsa_pem_len; +extern const size_t mbedtls_test_srv_crt_rsa_sha1_pem_len; +extern const size_t mbedtls_test_srv_crt_rsa_sha256_pem_len; + +extern const size_t mbedtls_test_srv_crt_ec_der_len; +extern const size_t mbedtls_test_srv_key_ec_der_len; +extern const size_t mbedtls_test_srv_pwd_ec_der_len; +extern const size_t mbedtls_test_srv_key_rsa_der_len; +extern const size_t mbedtls_test_srv_pwd_rsa_der_len; +extern const size_t mbedtls_test_srv_crt_rsa_sha1_der_len; +extern const size_t mbedtls_test_srv_crt_rsa_sha256_der_len; + +/* Config-dependent dispatch between PEM and DER encoding + * (PEM if enabled, otherwise DER) */ + +extern const char mbedtls_test_srv_crt_ec[]; +extern const char mbedtls_test_srv_key_ec[]; +extern const char mbedtls_test_srv_pwd_ec[]; +extern const char mbedtls_test_srv_key_rsa[]; +extern const char mbedtls_test_srv_pwd_rsa[]; +extern const char mbedtls_test_srv_crt_rsa_sha1[]; +extern const char mbedtls_test_srv_crt_rsa_sha256[]; + +extern const size_t mbedtls_test_srv_crt_ec_len; +extern const size_t mbedtls_test_srv_key_ec_len; +extern const size_t mbedtls_test_srv_pwd_ec_len; +extern const size_t mbedtls_test_srv_key_rsa_len; +extern const size_t mbedtls_test_srv_pwd_rsa_len; +extern const size_t mbedtls_test_srv_crt_rsa_sha1_len; +extern const size_t mbedtls_test_srv_crt_rsa_sha256_len; + +/* Config-dependent dispatch between SHA-1 and SHA-256 + * (SHA-256 if enabled, otherwise SHA-1) */ + +extern const char mbedtls_test_srv_crt_rsa[]; +extern const size_t mbedtls_test_srv_crt_rsa_len; + +/* Config-dependent dispatch between EC and RSA + * (RSA if enabled, otherwise EC) */ + extern const char * mbedtls_test_srv_crt; -extern const size_t mbedtls_test_srv_crt_len; extern const char * mbedtls_test_srv_key; +extern const char * mbedtls_test_srv_pwd; +extern const size_t mbedtls_test_srv_crt_len; extern const size_t mbedtls_test_srv_key_len; -extern const char * mbedtls_test_cli_crt; -extern const size_t mbedtls_test_cli_crt_len; -extern const char * mbedtls_test_cli_key; -extern const size_t mbedtls_test_cli_key_len; +extern const size_t mbedtls_test_srv_pwd_len; + +/* + * Client test certificates + */ + +extern const char mbedtls_test_cli_crt_ec_pem[]; +extern const char mbedtls_test_cli_key_ec_pem[]; +extern const char mbedtls_test_cli_pwd_ec_pem[]; +extern const char mbedtls_test_cli_key_rsa_pem[]; +extern const char mbedtls_test_cli_pwd_rsa_pem[]; +extern const char mbedtls_test_cli_crt_rsa_pem[]; + +extern const unsigned char mbedtls_test_cli_crt_ec_der[]; +extern const unsigned char mbedtls_test_cli_key_ec_der[]; +extern const unsigned char mbedtls_test_cli_key_rsa_der[]; +extern const unsigned char mbedtls_test_cli_crt_rsa_der[]; + +extern const size_t mbedtls_test_cli_crt_ec_pem_len; +extern const size_t mbedtls_test_cli_key_ec_pem_len; +extern const size_t mbedtls_test_cli_pwd_ec_pem_len; +extern const size_t mbedtls_test_cli_key_rsa_pem_len; +extern const size_t mbedtls_test_cli_pwd_rsa_pem_len; +extern const size_t mbedtls_test_cli_crt_rsa_pem_len; + +extern const size_t mbedtls_test_cli_crt_ec_der_len; +extern const size_t mbedtls_test_cli_key_ec_der_len; +extern const size_t mbedtls_test_cli_key_rsa_der_len; +extern const size_t mbedtls_test_cli_crt_rsa_der_len; + +/* Config-dependent dispatch between PEM and DER encoding + * (PEM if enabled, otherwise DER) */ + +extern const char mbedtls_test_cli_crt_ec[]; +extern const char mbedtls_test_cli_key_ec[]; +extern const char mbedtls_test_cli_pwd_ec[]; +extern const char mbedtls_test_cli_key_rsa[]; +extern const char mbedtls_test_cli_pwd_rsa[]; +extern const char mbedtls_test_cli_crt_rsa[]; -#if defined(MBEDTLS_ECDSA_C) -extern const char mbedtls_test_ca_crt_ec[]; -extern const size_t mbedtls_test_ca_crt_ec_len; -extern const char mbedtls_test_ca_key_ec[]; -extern const size_t mbedtls_test_ca_key_ec_len; -extern const char mbedtls_test_ca_pwd_ec[]; -extern const size_t mbedtls_test_ca_pwd_ec_len; -extern const char mbedtls_test_srv_crt_ec[]; -extern const size_t mbedtls_test_srv_crt_ec_len; -extern const char mbedtls_test_srv_key_ec[]; -extern const size_t mbedtls_test_srv_key_ec_len; -extern const char mbedtls_test_cli_crt_ec[]; extern const size_t mbedtls_test_cli_crt_ec_len; -extern const char mbedtls_test_cli_key_ec[]; extern const size_t mbedtls_test_cli_key_ec_len; -#endif - -#if defined(MBEDTLS_RSA_C) -extern const char mbedtls_test_ca_crt_rsa[]; -extern const size_t mbedtls_test_ca_crt_rsa_len; -extern const char mbedtls_test_ca_key_rsa[]; -extern const size_t mbedtls_test_ca_key_rsa_len; -extern const char mbedtls_test_ca_pwd_rsa[]; -extern const size_t mbedtls_test_ca_pwd_rsa_len; -extern const char mbedtls_test_srv_crt_rsa[]; -extern const size_t mbedtls_test_srv_crt_rsa_len; -extern const char mbedtls_test_srv_key_rsa[]; -extern const size_t mbedtls_test_srv_key_rsa_len; -extern const char mbedtls_test_cli_crt_rsa[]; -extern const size_t mbedtls_test_cli_crt_rsa_len; -extern const char mbedtls_test_cli_key_rsa[]; +extern const size_t mbedtls_test_cli_pwd_ec_len; extern const size_t mbedtls_test_cli_key_rsa_len; -#endif +extern const size_t mbedtls_test_cli_pwd_rsa_len; +extern const size_t mbedtls_test_cli_crt_rsa_len; + +/* Config-dependent dispatch between EC and RSA + * (RSA if enabled, otherwise EC) */ + +extern const char * mbedtls_test_cli_crt; +extern const char * mbedtls_test_cli_key; +extern const char * mbedtls_test_cli_pwd; +extern const size_t mbedtls_test_cli_crt_len; +extern const size_t mbedtls_test_cli_key_len; +extern const size_t mbedtls_test_cli_pwd_len; #ifdef __cplusplus } diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/chacha20.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/chacha20.h new file mode 100644 index 0000000000..2ae5e6e5f4 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/chacha20.h @@ -0,0 +1,226 @@ +/** + * \file chacha20.h + * + * \brief This file contains ChaCha20 definitions and functions. + * + * ChaCha20 is a stream cipher that can encrypt and decrypt + * information. ChaCha was created by Daniel Bernstein as a variant of + * its Salsa cipher https://cr.yp.to/chacha/chacha-20080128.pdf + * ChaCha20 is the variant with 20 rounds, that was also standardized + * in RFC 7539. + * + * \author Daniel King + */ + +/* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of Mbed TLS (https://tls.mbed.org) + */ + +#ifndef MBEDTLS_CHACHA20_H +#define MBEDTLS_CHACHA20_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include +#include + +#define MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA -0x0051 /**< Invalid input parameter(s). */ + +/* MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE is deprecated and should not be + * used. */ +#define MBEDTLS_ERR_CHACHA20_FEATURE_UNAVAILABLE -0x0053 /**< Feature not available. For example, s part of the API is not implemented. */ + +/* MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED is deprecated and should not be used. + */ +#define MBEDTLS_ERR_CHACHA20_HW_ACCEL_FAILED -0x0055 /**< Chacha20 hardware accelerator failed. */ + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(MBEDTLS_CHACHA20_ALT) + +typedef struct mbedtls_chacha20_context +{ + uint32_t state[16]; /*! The state (before round operations). */ + uint8_t keystream8[64]; /*! Leftover keystream bytes. */ + size_t keystream_bytes_used; /*! Number of keystream bytes already used. */ +} +mbedtls_chacha20_context; + +#else /* MBEDTLS_CHACHA20_ALT */ +#include "chacha20_alt.h" +#endif /* MBEDTLS_CHACHA20_ALT */ + +/** + * \brief This function initializes the specified ChaCha20 context. + * + * It must be the first API called before using + * the context. + * + * It is usually followed by calls to + * \c mbedtls_chacha20_setkey() and + * \c mbedtls_chacha20_starts(), then one or more calls to + * to \c mbedtls_chacha20_update(), and finally to + * \c mbedtls_chacha20_free(). + * + * \param ctx The ChaCha20 context to initialize. + * This must not be \c NULL. + */ +void mbedtls_chacha20_init( mbedtls_chacha20_context *ctx ); + +/** + * \brief This function releases and clears the specified + * ChaCha20 context. + * + * \param ctx The ChaCha20 context to clear. This may be \c NULL, + * in which case this function is a no-op. If it is not + * \c NULL, it must point to an initialized context. + * + */ +void mbedtls_chacha20_free( mbedtls_chacha20_context *ctx ); + +/** + * \brief This function sets the encryption/decryption key. + * + * \note After using this function, you must also call + * \c mbedtls_chacha20_starts() to set a nonce before you + * start encrypting/decrypting data with + * \c mbedtls_chacha_update(). + * + * \param ctx The ChaCha20 context to which the key should be bound. + * It must be initialized. + * \param key The encryption/decryption key. This must be \c 32 Bytes + * in length. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA if ctx or key is NULL. + */ +int mbedtls_chacha20_setkey( mbedtls_chacha20_context *ctx, + const unsigned char key[32] ); + +/** + * \brief This function sets the nonce and initial counter value. + * + * \note A ChaCha20 context can be re-used with the same key by + * calling this function to change the nonce. + * + * \warning You must never use the same nonce twice with the same key. + * This would void any confidentiality guarantees for the + * messages encrypted with the same nonce and key. + * + * \param ctx The ChaCha20 context to which the nonce should be bound. + * It must be initialized and bound to a key. + * \param nonce The nonce. This must be \c 12 Bytes in size. + * \param counter The initial counter value. This is usually \c 0. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA if ctx or nonce is + * NULL. + */ +int mbedtls_chacha20_starts( mbedtls_chacha20_context* ctx, + const unsigned char nonce[12], + uint32_t counter ); + +/** + * \brief This function encrypts or decrypts data. + * + * Since ChaCha20 is a stream cipher, the same operation is + * used for encrypting and decrypting data. + * + * \note The \p input and \p output pointers must either be equal or + * point to non-overlapping buffers. + * + * \note \c mbedtls_chacha20_setkey() and + * \c mbedtls_chacha20_starts() must be called at least once + * to setup the context before this function can be called. + * + * \note This function can be called multiple times in a row in + * order to encrypt of decrypt data piecewise with the same + * key and nonce. + * + * \param ctx The ChaCha20 context to use for encryption or decryption. + * It must be initialized and bound to a key and nonce. + * \param size The length of the input data in Bytes. + * \param input The buffer holding the input data. + * This pointer can be \c NULL if `size == 0`. + * \param output The buffer holding the output data. + * This must be able to hold \p size Bytes. + * This pointer can be \c NULL if `size == 0`. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx, + size_t size, + const unsigned char *input, + unsigned char *output ); + +/** + * \brief This function encrypts or decrypts data with ChaCha20 and + * the given key and nonce. + * + * Since ChaCha20 is a stream cipher, the same operation is + * used for encrypting and decrypting data. + * + * \warning You must never use the same (key, nonce) pair more than + * once. This would void any confidentiality guarantees for + * the messages encrypted with the same nonce and key. + * + * \note The \p input and \p output pointers must either be equal or + * point to non-overlapping buffers. + * + * \param key The encryption/decryption key. + * This must be \c 32 Bytes in length. + * \param nonce The nonce. This must be \c 12 Bytes in size. + * \param counter The initial counter value. This is usually \c 0. + * \param size The length of the input data in Bytes. + * \param input The buffer holding the input data. + * This pointer can be \c NULL if `size == 0`. + * \param output The buffer holding the output data. + * This must be able to hold \p size Bytes. + * This pointer can be \c NULL if `size == 0`. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_chacha20_crypt( const unsigned char key[32], + const unsigned char nonce[12], + uint32_t counter, + size_t size, + const unsigned char* input, + unsigned char* output ); + +#if defined(MBEDTLS_SELF_TEST) +/** + * \brief The ChaCha20 checkup routine. + * + * \return \c 0 on success. + * \return \c 1 on failure. + */ +int mbedtls_chacha20_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + +#ifdef __cplusplus +} +#endif + +#endif /* MBEDTLS_CHACHA20_H */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/chachapoly.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/chachapoly.h new file mode 100644 index 0000000000..49e615d278 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/chachapoly.h @@ -0,0 +1,358 @@ +/** + * \file chachapoly.h + * + * \brief This file contains the AEAD-ChaCha20-Poly1305 definitions and + * functions. + * + * ChaCha20-Poly1305 is an algorithm for Authenticated Encryption + * with Associated Data (AEAD) that can be used to encrypt and + * authenticate data. It is based on ChaCha20 and Poly1305 by Daniel + * Bernstein and was standardized in RFC 7539. + * + * \author Daniel King + */ + +/* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of Mbed TLS (https://tls.mbed.org) + */ + +#ifndef MBEDTLS_CHACHAPOLY_H +#define MBEDTLS_CHACHAPOLY_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +/* for shared error codes */ +#include "poly1305.h" + +#define MBEDTLS_ERR_CHACHAPOLY_BAD_STATE -0x0054 /**< The requested operation is not permitted in the current state. */ +#define MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED -0x0056 /**< Authenticated decryption failed: data was not authentic. */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum +{ + MBEDTLS_CHACHAPOLY_ENCRYPT, /**< The mode value for performing encryption. */ + MBEDTLS_CHACHAPOLY_DECRYPT /**< The mode value for performing decryption. */ +} +mbedtls_chachapoly_mode_t; + +#if !defined(MBEDTLS_CHACHAPOLY_ALT) + +#include "chacha20.h" + +typedef struct mbedtls_chachapoly_context +{ + mbedtls_chacha20_context chacha20_ctx; /**< The ChaCha20 context. */ + mbedtls_poly1305_context poly1305_ctx; /**< The Poly1305 context. */ + uint64_t aad_len; /**< The length (bytes) of the Additional Authenticated Data. */ + uint64_t ciphertext_len; /**< The length (bytes) of the ciphertext. */ + int state; /**< The current state of the context. */ + mbedtls_chachapoly_mode_t mode; /**< Cipher mode (encrypt or decrypt). */ +} +mbedtls_chachapoly_context; + +#else /* !MBEDTLS_CHACHAPOLY_ALT */ +#include "chachapoly_alt.h" +#endif /* !MBEDTLS_CHACHAPOLY_ALT */ + +/** + * \brief This function initializes the specified ChaCha20-Poly1305 context. + * + * It must be the first API called before using + * the context. It must be followed by a call to + * \c mbedtls_chachapoly_setkey() before any operation can be + * done, and to \c mbedtls_chachapoly_free() once all + * operations with that context have been finished. + * + * In order to encrypt or decrypt full messages at once, for + * each message you should make a single call to + * \c mbedtls_chachapoly_crypt_and_tag() or + * \c mbedtls_chachapoly_auth_decrypt(). + * + * In order to encrypt messages piecewise, for each + * message you should make a call to + * \c mbedtls_chachapoly_starts(), then 0 or more calls to + * \c mbedtls_chachapoly_update_aad(), then 0 or more calls to + * \c mbedtls_chachapoly_update(), then one call to + * \c mbedtls_chachapoly_finish(). + * + * \warning Decryption with the piecewise API is discouraged! Always + * use \c mbedtls_chachapoly_auth_decrypt() when possible! + * + * If however this is not possible because the data is too + * large to fit in memory, you need to: + * + * - call \c mbedtls_chachapoly_starts() and (if needed) + * \c mbedtls_chachapoly_update_aad() as above, + * - call \c mbedtls_chachapoly_update() multiple times and + * ensure its output (the plaintext) is NOT used in any other + * way than placing it in temporary storage at this point, + * - call \c mbedtls_chachapoly_finish() to compute the + * authentication tag and compared it in constant time to the + * tag received with the ciphertext. + * + * If the tags are not equal, you must immediately discard + * all previous outputs of \c mbedtls_chachapoly_update(), + * otherwise you can now safely use the plaintext. + * + * \param ctx The ChachaPoly context to initialize. Must not be \c NULL. + */ +void mbedtls_chachapoly_init( mbedtls_chachapoly_context *ctx ); + +/** + * \brief This function releases and clears the specified + * ChaCha20-Poly1305 context. + * + * \param ctx The ChachaPoly context to clear. This may be \c NULL, in which + * case this function is a no-op. + */ +void mbedtls_chachapoly_free( mbedtls_chachapoly_context *ctx ); + +/** + * \brief This function sets the ChaCha20-Poly1305 + * symmetric encryption key. + * + * \param ctx The ChaCha20-Poly1305 context to which the key should be + * bound. This must be initialized. + * \param key The \c 256 Bit (\c 32 Bytes) key. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_chachapoly_setkey( mbedtls_chachapoly_context *ctx, + const unsigned char key[32] ); + +/** + * \brief This function starts a ChaCha20-Poly1305 encryption or + * decryption operation. + * + * \warning You must never use the same nonce twice with the same key. + * This would void any confidentiality and authenticity + * guarantees for the messages encrypted with the same nonce + * and key. + * + * \note If the context is being used for AAD only (no data to + * encrypt or decrypt) then \p mode can be set to any value. + * + * \warning Decryption with the piecewise API is discouraged, see the + * warning on \c mbedtls_chachapoly_init(). + * + * \param ctx The ChaCha20-Poly1305 context. This must be initialized + * and bound to a key. + * \param nonce The nonce/IV to use for the message. + * This must be a redable buffer of length \c 12 Bytes. + * \param mode The operation to perform: #MBEDTLS_CHACHAPOLY_ENCRYPT or + * #MBEDTLS_CHACHAPOLY_DECRYPT (discouraged, see warning). + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_chachapoly_starts( mbedtls_chachapoly_context *ctx, + const unsigned char nonce[12], + mbedtls_chachapoly_mode_t mode ); + +/** + * \brief This function feeds additional data to be authenticated + * into an ongoing ChaCha20-Poly1305 operation. + * + * The Additional Authenticated Data (AAD), also called + * Associated Data (AD) is only authenticated but not + * encrypted nor included in the encrypted output. It is + * usually transmitted separately from the ciphertext or + * computed locally by each party. + * + * \note This function is called before data is encrypted/decrypted. + * I.e. call this function to process the AAD before calling + * \c mbedtls_chachapoly_update(). + * + * You may call this function multiple times to process + * an arbitrary amount of AAD. It is permitted to call + * this function 0 times, if no AAD is used. + * + * This function cannot be called any more if data has + * been processed by \c mbedtls_chachapoly_update(), + * or if the context has been finished. + * + * \warning Decryption with the piecewise API is discouraged, see the + * warning on \c mbedtls_chachapoly_init(). + * + * \param ctx The ChaCha20-Poly1305 context. This must be initialized + * and bound to a key. + * \param aad_len The length in Bytes of the AAD. The length has no + * restrictions. + * \param aad Buffer containing the AAD. + * This pointer can be \c NULL if `aad_len == 0`. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA + * if \p ctx or \p aad are NULL. + * \return #MBEDTLS_ERR_CHACHAPOLY_BAD_STATE + * if the operations has not been started or has been + * finished, or if the AAD has been finished. + */ +int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx, + const unsigned char *aad, + size_t aad_len ); + +/** + * \brief Thus function feeds data to be encrypted or decrypted + * into an on-going ChaCha20-Poly1305 + * operation. + * + * The direction (encryption or decryption) depends on the + * mode that was given when calling + * \c mbedtls_chachapoly_starts(). + * + * You may call this function multiple times to process + * an arbitrary amount of data. It is permitted to call + * this function 0 times, if no data is to be encrypted + * or decrypted. + * + * \warning Decryption with the piecewise API is discouraged, see the + * warning on \c mbedtls_chachapoly_init(). + * + * \param ctx The ChaCha20-Poly1305 context to use. This must be initialized. + * \param len The length (in bytes) of the data to encrypt or decrypt. + * \param input The buffer containing the data to encrypt or decrypt. + * This pointer can be \c NULL if `len == 0`. + * \param output The buffer to where the encrypted or decrypted data is + * written. This must be able to hold \p len bytes. + * This pointer can be \c NULL if `len == 0`. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CHACHAPOLY_BAD_STATE + * if the operation has not been started or has been + * finished. + * \return Another negative error code on other kinds of failure. + */ +int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx, + size_t len, + const unsigned char *input, + unsigned char *output ); + +/** + * \brief This function finished the ChaCha20-Poly1305 operation and + * generates the MAC (authentication tag). + * + * \param ctx The ChaCha20-Poly1305 context to use. This must be initialized. + * \param mac The buffer to where the 128-bit (16 bytes) MAC is written. + * + * \warning Decryption with the piecewise API is discouraged, see the + * warning on \c mbedtls_chachapoly_init(). + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CHACHAPOLY_BAD_STATE + * if the operation has not been started or has been + * finished. + * \return Another negative error code on other kinds of failure. + */ +int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx, + unsigned char mac[16] ); + +/** + * \brief This function performs a complete ChaCha20-Poly1305 + * authenticated encryption with the previously-set key. + * + * \note Before using this function, you must set the key with + * \c mbedtls_chachapoly_setkey(). + * + * \warning You must never use the same nonce twice with the same key. + * This would void any confidentiality and authenticity + * guarantees for the messages encrypted with the same nonce + * and key. + * + * \param ctx The ChaCha20-Poly1305 context to use (holds the key). + * This must be initialized. + * \param length The length (in bytes) of the data to encrypt or decrypt. + * \param nonce The 96-bit (12 bytes) nonce/IV to use. + * \param aad The buffer containing the additional authenticated + * data (AAD). This pointer can be \c NULL if `aad_len == 0`. + * \param aad_len The length (in bytes) of the AAD data to process. + * \param input The buffer containing the data to encrypt or decrypt. + * This pointer can be \c NULL if `ilen == 0`. + * \param output The buffer to where the encrypted or decrypted data + * is written. This pointer can be \c NULL if `ilen == 0`. + * \param tag The buffer to where the computed 128-bit (16 bytes) MAC + * is written. This must not be \c NULL. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_chachapoly_encrypt_and_tag( mbedtls_chachapoly_context *ctx, + size_t length, + const unsigned char nonce[12], + const unsigned char *aad, + size_t aad_len, + const unsigned char *input, + unsigned char *output, + unsigned char tag[16] ); + +/** + * \brief This function performs a complete ChaCha20-Poly1305 + * authenticated decryption with the previously-set key. + * + * \note Before using this function, you must set the key with + * \c mbedtls_chachapoly_setkey(). + * + * \param ctx The ChaCha20-Poly1305 context to use (holds the key). + * \param length The length (in Bytes) of the data to decrypt. + * \param nonce The \c 96 Bit (\c 12 bytes) nonce/IV to use. + * \param aad The buffer containing the additional authenticated data (AAD). + * This pointer can be \c NULL if `aad_len == 0`. + * \param aad_len The length (in bytes) of the AAD data to process. + * \param tag The buffer holding the authentication tag. + * This must be a readable buffer of length \c 16 Bytes. + * \param input The buffer containing the data to decrypt. + * This pointer can be \c NULL if `ilen == 0`. + * \param output The buffer to where the decrypted data is written. + * This pointer can be \c NULL if `ilen == 0`. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED + * if the data was not authentic. + * \return Another negative error code on other kinds of failure. + */ +int mbedtls_chachapoly_auth_decrypt( mbedtls_chachapoly_context *ctx, + size_t length, + const unsigned char nonce[12], + const unsigned char *aad, + size_t aad_len, + const unsigned char tag[16], + const unsigned char *input, + unsigned char *output ); + +#if defined(MBEDTLS_SELF_TEST) +/** + * \brief The ChaCha20-Poly1305 checkup routine. + * + * \return \c 0 on success. + * \return \c 1 on failure. + */ +int mbedtls_chachapoly_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + +#ifdef __cplusplus +} +#endif + +#endif /* MBEDTLS_CHACHAPOLY_H */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/check_config.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/check_config.h index fa7110fe92..b86e5807e0 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/check_config.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/check_config.h @@ -4,7 +4,7 @@ * \brief Consistency checks for configuration options */ /* - * Copyright (C) 2006-2016, ARM Limited, All Rights Reserved + * Copyright (C) 2006-2018, ARM Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -87,6 +87,11 @@ #error "MBEDTLS_CMAC_C defined, but not all prerequisites" #endif +#if defined(MBEDTLS_NIST_KW_C) && \ + ( !defined(MBEDTLS_AES_C) || !defined(MBEDTLS_CIPHER_C) ) +#error "MBEDTLS_NIST_KW_C defined, but not all prerequisites" +#endif + #if defined(MBEDTLS_ECDH_C) && !defined(MBEDTLS_ECP_C) #error "MBEDTLS_ECDH_C defined, but not all prerequisites" #endif @@ -103,6 +108,17 @@ #error "MBEDTLS_ECJPAKE_C defined, but not all prerequisites" #endif +#if defined(MBEDTLS_ECP_RESTARTABLE) && \ + ( defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT) || \ + defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT) || \ + defined(MBEDTLS_ECDSA_SIGN_ALT) || \ + defined(MBEDTLS_ECDSA_VERIFY_ALT) || \ + defined(MBEDTLS_ECDSA_GENKEY_ALT) || \ + defined(MBEDTLS_ECP_INTERNAL_ALT) || \ + defined(MBEDTLS_ECP_ALT) ) +#error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative ECP implementation" +#endif + #if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C) #error "MBEDTLS_ECDSA_DETERMINISTIC defined, but not all prerequisites" #endif @@ -195,6 +211,10 @@ #error "MBEDTLS_HAVEGE_C defined, but not all prerequisites" #endif +#if defined(MBEDTLS_HKDF_C) && !defined(MBEDTLS_MD_C) +#error "MBEDTLS_HKDF_C defined, but not all prerequisites" +#endif + #if defined(MBEDTLS_HMAC_DRBG_C) && !defined(MBEDTLS_MD_C) #error "MBEDTLS_HMAC_DRBG_C defined, but not all prerequisites" #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/cipher.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/cipher.h index 1c453a1d32..082a691741 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/cipher.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/cipher.h @@ -1,7 +1,9 @@ /** * \file cipher.h * - * \brief The generic cipher wrapper. + * \brief This file contains an abstraction interface for use with the cipher + * primitives provided by the library. It provides a common interface to all of + * the available cipher operations. * * \author Adriaan de Jong */ @@ -34,8 +36,9 @@ #endif #include +#include "platform_util.h" -#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C) +#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CCM_C) || defined(MBEDTLS_CHACHAPOLY_C) #define MBEDTLS_CIPHER_MODE_AEAD #endif @@ -43,7 +46,8 @@ #define MBEDTLS_CIPHER_MODE_WITH_PADDING #endif -#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER) +#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_NULL_CIPHER) || \ + defined(MBEDTLS_CHACHA20_C) #define MBEDTLS_CIPHER_MODE_STREAM #endif @@ -59,6 +63,8 @@ #define MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED -0x6280 /**< Decryption of block requires a full block. */ #define MBEDTLS_ERR_CIPHER_AUTH_FAILED -0x6300 /**< Authentication failed (for AEAD modes). */ #define MBEDTLS_ERR_CIPHER_INVALID_CONTEXT -0x6380 /**< The context is invalid. For example, because it was freed. */ + +/* MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED -0x6400 /**< Cipher hardware accelerator failed. */ #define MBEDTLS_CIPHER_VARIABLE_IV_LEN 0x01 /**< Cipher accepts IVs of variable length. */ @@ -69,93 +75,122 @@ extern "C" { #endif /** - * \brief An enumeration of supported ciphers. + * \brief Supported cipher types. * - * \warning ARC4 and DES are considered weak ciphers and their use - * constitutes a security risk. We recommend considering stronger + * \warning RC4 and DES are considered weak ciphers and their use + * constitutes a security risk. Arm recommends considering stronger * ciphers instead. */ typedef enum { - MBEDTLS_CIPHER_ID_NONE = 0, - MBEDTLS_CIPHER_ID_NULL, - MBEDTLS_CIPHER_ID_AES, - MBEDTLS_CIPHER_ID_DES, - MBEDTLS_CIPHER_ID_3DES, - MBEDTLS_CIPHER_ID_CAMELLIA, - MBEDTLS_CIPHER_ID_BLOWFISH, - MBEDTLS_CIPHER_ID_ARC4, + MBEDTLS_CIPHER_ID_NONE = 0, /**< Placeholder to mark the end of cipher ID lists. */ + MBEDTLS_CIPHER_ID_NULL, /**< The identity cipher, treated as a stream cipher. */ + MBEDTLS_CIPHER_ID_AES, /**< The AES cipher. */ + MBEDTLS_CIPHER_ID_DES, /**< The DES cipher. */ + MBEDTLS_CIPHER_ID_3DES, /**< The Triple DES cipher. */ + MBEDTLS_CIPHER_ID_CAMELLIA, /**< The Camellia cipher. */ + MBEDTLS_CIPHER_ID_BLOWFISH, /**< The Blowfish cipher. */ + MBEDTLS_CIPHER_ID_ARC4, /**< The RC4 cipher. */ + MBEDTLS_CIPHER_ID_ARIA, /**< The Aria cipher. */ + MBEDTLS_CIPHER_ID_CHACHA20, /**< The ChaCha20 cipher. */ } mbedtls_cipher_id_t; /** - * \brief An enumeration of supported (cipher, mode) pairs. + * \brief Supported {cipher type, cipher mode} pairs. * - * \warning ARC4 and DES are considered weak ciphers and their use - * constitutes a security risk. We recommend considering stronger + * \warning RC4 and DES are considered weak ciphers and their use + * constitutes a security risk. Arm recommends considering stronger * ciphers instead. */ typedef enum { - MBEDTLS_CIPHER_NONE = 0, - MBEDTLS_CIPHER_NULL, - MBEDTLS_CIPHER_AES_128_ECB, - MBEDTLS_CIPHER_AES_192_ECB, - MBEDTLS_CIPHER_AES_256_ECB, - MBEDTLS_CIPHER_AES_128_CBC, - MBEDTLS_CIPHER_AES_192_CBC, - MBEDTLS_CIPHER_AES_256_CBC, - MBEDTLS_CIPHER_AES_128_CFB128, - MBEDTLS_CIPHER_AES_192_CFB128, - MBEDTLS_CIPHER_AES_256_CFB128, - MBEDTLS_CIPHER_AES_128_CTR, - MBEDTLS_CIPHER_AES_192_CTR, - MBEDTLS_CIPHER_AES_256_CTR, - MBEDTLS_CIPHER_AES_128_GCM, - MBEDTLS_CIPHER_AES_192_GCM, - MBEDTLS_CIPHER_AES_256_GCM, - MBEDTLS_CIPHER_CAMELLIA_128_ECB, - MBEDTLS_CIPHER_CAMELLIA_192_ECB, - MBEDTLS_CIPHER_CAMELLIA_256_ECB, - MBEDTLS_CIPHER_CAMELLIA_128_CBC, - MBEDTLS_CIPHER_CAMELLIA_192_CBC, - MBEDTLS_CIPHER_CAMELLIA_256_CBC, - MBEDTLS_CIPHER_CAMELLIA_128_CFB128, - MBEDTLS_CIPHER_CAMELLIA_192_CFB128, - MBEDTLS_CIPHER_CAMELLIA_256_CFB128, - MBEDTLS_CIPHER_CAMELLIA_128_CTR, - MBEDTLS_CIPHER_CAMELLIA_192_CTR, - MBEDTLS_CIPHER_CAMELLIA_256_CTR, - MBEDTLS_CIPHER_CAMELLIA_128_GCM, - MBEDTLS_CIPHER_CAMELLIA_192_GCM, - MBEDTLS_CIPHER_CAMELLIA_256_GCM, - MBEDTLS_CIPHER_DES_ECB, - MBEDTLS_CIPHER_DES_CBC, - MBEDTLS_CIPHER_DES_EDE_ECB, - MBEDTLS_CIPHER_DES_EDE_CBC, - MBEDTLS_CIPHER_DES_EDE3_ECB, - MBEDTLS_CIPHER_DES_EDE3_CBC, - MBEDTLS_CIPHER_BLOWFISH_ECB, - MBEDTLS_CIPHER_BLOWFISH_CBC, - MBEDTLS_CIPHER_BLOWFISH_CFB64, - MBEDTLS_CIPHER_BLOWFISH_CTR, - MBEDTLS_CIPHER_ARC4_128, - MBEDTLS_CIPHER_AES_128_CCM, - MBEDTLS_CIPHER_AES_192_CCM, - MBEDTLS_CIPHER_AES_256_CCM, - MBEDTLS_CIPHER_CAMELLIA_128_CCM, - MBEDTLS_CIPHER_CAMELLIA_192_CCM, - MBEDTLS_CIPHER_CAMELLIA_256_CCM, + MBEDTLS_CIPHER_NONE = 0, /**< Placeholder to mark the end of cipher-pair lists. */ + MBEDTLS_CIPHER_NULL, /**< The identity stream cipher. */ + MBEDTLS_CIPHER_AES_128_ECB, /**< AES cipher with 128-bit ECB mode. */ + MBEDTLS_CIPHER_AES_192_ECB, /**< AES cipher with 192-bit ECB mode. */ + MBEDTLS_CIPHER_AES_256_ECB, /**< AES cipher with 256-bit ECB mode. */ + MBEDTLS_CIPHER_AES_128_CBC, /**< AES cipher with 128-bit CBC mode. */ + MBEDTLS_CIPHER_AES_192_CBC, /**< AES cipher with 192-bit CBC mode. */ + MBEDTLS_CIPHER_AES_256_CBC, /**< AES cipher with 256-bit CBC mode. */ + MBEDTLS_CIPHER_AES_128_CFB128, /**< AES cipher with 128-bit CFB128 mode. */ + MBEDTLS_CIPHER_AES_192_CFB128, /**< AES cipher with 192-bit CFB128 mode. */ + MBEDTLS_CIPHER_AES_256_CFB128, /**< AES cipher with 256-bit CFB128 mode. */ + MBEDTLS_CIPHER_AES_128_CTR, /**< AES cipher with 128-bit CTR mode. */ + MBEDTLS_CIPHER_AES_192_CTR, /**< AES cipher with 192-bit CTR mode. */ + MBEDTLS_CIPHER_AES_256_CTR, /**< AES cipher with 256-bit CTR mode. */ + MBEDTLS_CIPHER_AES_128_GCM, /**< AES cipher with 128-bit GCM mode. */ + MBEDTLS_CIPHER_AES_192_GCM, /**< AES cipher with 192-bit GCM mode. */ + MBEDTLS_CIPHER_AES_256_GCM, /**< AES cipher with 256-bit GCM mode. */ + MBEDTLS_CIPHER_CAMELLIA_128_ECB, /**< Camellia cipher with 128-bit ECB mode. */ + MBEDTLS_CIPHER_CAMELLIA_192_ECB, /**< Camellia cipher with 192-bit ECB mode. */ + MBEDTLS_CIPHER_CAMELLIA_256_ECB, /**< Camellia cipher with 256-bit ECB mode. */ + MBEDTLS_CIPHER_CAMELLIA_128_CBC, /**< Camellia cipher with 128-bit CBC mode. */ + MBEDTLS_CIPHER_CAMELLIA_192_CBC, /**< Camellia cipher with 192-bit CBC mode. */ + MBEDTLS_CIPHER_CAMELLIA_256_CBC, /**< Camellia cipher with 256-bit CBC mode. */ + MBEDTLS_CIPHER_CAMELLIA_128_CFB128, /**< Camellia cipher with 128-bit CFB128 mode. */ + MBEDTLS_CIPHER_CAMELLIA_192_CFB128, /**< Camellia cipher with 192-bit CFB128 mode. */ + MBEDTLS_CIPHER_CAMELLIA_256_CFB128, /**< Camellia cipher with 256-bit CFB128 mode. */ + MBEDTLS_CIPHER_CAMELLIA_128_CTR, /**< Camellia cipher with 128-bit CTR mode. */ + MBEDTLS_CIPHER_CAMELLIA_192_CTR, /**< Camellia cipher with 192-bit CTR mode. */ + MBEDTLS_CIPHER_CAMELLIA_256_CTR, /**< Camellia cipher with 256-bit CTR mode. */ + MBEDTLS_CIPHER_CAMELLIA_128_GCM, /**< Camellia cipher with 128-bit GCM mode. */ + MBEDTLS_CIPHER_CAMELLIA_192_GCM, /**< Camellia cipher with 192-bit GCM mode. */ + MBEDTLS_CIPHER_CAMELLIA_256_GCM, /**< Camellia cipher with 256-bit GCM mode. */ + MBEDTLS_CIPHER_DES_ECB, /**< DES cipher with ECB mode. */ + MBEDTLS_CIPHER_DES_CBC, /**< DES cipher with CBC mode. */ + MBEDTLS_CIPHER_DES_EDE_ECB, /**< DES cipher with EDE ECB mode. */ + MBEDTLS_CIPHER_DES_EDE_CBC, /**< DES cipher with EDE CBC mode. */ + MBEDTLS_CIPHER_DES_EDE3_ECB, /**< DES cipher with EDE3 ECB mode. */ + MBEDTLS_CIPHER_DES_EDE3_CBC, /**< DES cipher with EDE3 CBC mode. */ + MBEDTLS_CIPHER_BLOWFISH_ECB, /**< Blowfish cipher with ECB mode. */ + MBEDTLS_CIPHER_BLOWFISH_CBC, /**< Blowfish cipher with CBC mode. */ + MBEDTLS_CIPHER_BLOWFISH_CFB64, /**< Blowfish cipher with CFB64 mode. */ + MBEDTLS_CIPHER_BLOWFISH_CTR, /**< Blowfish cipher with CTR mode. */ + MBEDTLS_CIPHER_ARC4_128, /**< RC4 cipher with 128-bit mode. */ + MBEDTLS_CIPHER_AES_128_CCM, /**< AES cipher with 128-bit CCM mode. */ + MBEDTLS_CIPHER_AES_192_CCM, /**< AES cipher with 192-bit CCM mode. */ + MBEDTLS_CIPHER_AES_256_CCM, /**< AES cipher with 256-bit CCM mode. */ + MBEDTLS_CIPHER_CAMELLIA_128_CCM, /**< Camellia cipher with 128-bit CCM mode. */ + MBEDTLS_CIPHER_CAMELLIA_192_CCM, /**< Camellia cipher with 192-bit CCM mode. */ + MBEDTLS_CIPHER_CAMELLIA_256_CCM, /**< Camellia cipher with 256-bit CCM mode. */ + MBEDTLS_CIPHER_ARIA_128_ECB, /**< Aria cipher with 128-bit key and ECB mode. */ + MBEDTLS_CIPHER_ARIA_192_ECB, /**< Aria cipher with 192-bit key and ECB mode. */ + MBEDTLS_CIPHER_ARIA_256_ECB, /**< Aria cipher with 256-bit key and ECB mode. */ + MBEDTLS_CIPHER_ARIA_128_CBC, /**< Aria cipher with 128-bit key and CBC mode. */ + MBEDTLS_CIPHER_ARIA_192_CBC, /**< Aria cipher with 192-bit key and CBC mode. */ + MBEDTLS_CIPHER_ARIA_256_CBC, /**< Aria cipher with 256-bit key and CBC mode. */ + MBEDTLS_CIPHER_ARIA_128_CFB128, /**< Aria cipher with 128-bit key and CFB-128 mode. */ + MBEDTLS_CIPHER_ARIA_192_CFB128, /**< Aria cipher with 192-bit key and CFB-128 mode. */ + MBEDTLS_CIPHER_ARIA_256_CFB128, /**< Aria cipher with 256-bit key and CFB-128 mode. */ + MBEDTLS_CIPHER_ARIA_128_CTR, /**< Aria cipher with 128-bit key and CTR mode. */ + MBEDTLS_CIPHER_ARIA_192_CTR, /**< Aria cipher with 192-bit key and CTR mode. */ + MBEDTLS_CIPHER_ARIA_256_CTR, /**< Aria cipher with 256-bit key and CTR mode. */ + MBEDTLS_CIPHER_ARIA_128_GCM, /**< Aria cipher with 128-bit key and GCM mode. */ + MBEDTLS_CIPHER_ARIA_192_GCM, /**< Aria cipher with 192-bit key and GCM mode. */ + MBEDTLS_CIPHER_ARIA_256_GCM, /**< Aria cipher with 256-bit key and GCM mode. */ + MBEDTLS_CIPHER_ARIA_128_CCM, /**< Aria cipher with 128-bit key and CCM mode. */ + MBEDTLS_CIPHER_ARIA_192_CCM, /**< Aria cipher with 192-bit key and CCM mode. */ + MBEDTLS_CIPHER_ARIA_256_CCM, /**< Aria cipher with 256-bit key and CCM mode. */ + MBEDTLS_CIPHER_AES_128_OFB, /**< AES 128-bit cipher in OFB mode. */ + MBEDTLS_CIPHER_AES_192_OFB, /**< AES 192-bit cipher in OFB mode. */ + MBEDTLS_CIPHER_AES_256_OFB, /**< AES 256-bit cipher in OFB mode. */ + MBEDTLS_CIPHER_AES_128_XTS, /**< AES 128-bit cipher in XTS block mode. */ + MBEDTLS_CIPHER_AES_256_XTS, /**< AES 256-bit cipher in XTS block mode. */ + MBEDTLS_CIPHER_CHACHA20, /**< ChaCha20 stream cipher. */ + MBEDTLS_CIPHER_CHACHA20_POLY1305, /**< ChaCha20-Poly1305 AEAD cipher. */ } mbedtls_cipher_type_t; /** Supported cipher modes. */ typedef enum { - MBEDTLS_MODE_NONE = 0, - MBEDTLS_MODE_ECB, - MBEDTLS_MODE_CBC, - MBEDTLS_MODE_CFB, - MBEDTLS_MODE_OFB, /* Unused! */ - MBEDTLS_MODE_CTR, - MBEDTLS_MODE_GCM, - MBEDTLS_MODE_STREAM, - MBEDTLS_MODE_CCM, + MBEDTLS_MODE_NONE = 0, /**< None. */ + MBEDTLS_MODE_ECB, /**< The ECB cipher mode. */ + MBEDTLS_MODE_CBC, /**< The CBC cipher mode. */ + MBEDTLS_MODE_CFB, /**< The CFB cipher mode. */ + MBEDTLS_MODE_OFB, /**< The OFB cipher mode. */ + MBEDTLS_MODE_CTR, /**< The CTR cipher mode. */ + MBEDTLS_MODE_GCM, /**< The GCM cipher mode. */ + MBEDTLS_MODE_STREAM, /**< The stream cipher mode. */ + MBEDTLS_MODE_CCM, /**< The CCM cipher mode. */ + MBEDTLS_MODE_XTS, /**< The XTS cipher mode. */ + MBEDTLS_MODE_CHACHAPOLY, /**< The ChaCha-Poly cipher mode. */ } mbedtls_cipher_mode_t; /** Supported cipher padding types. */ @@ -163,8 +198,8 @@ typedef enum { MBEDTLS_PADDING_PKCS7 = 0, /**< PKCS7 padding (default). */ MBEDTLS_PADDING_ONE_AND_ZEROS, /**< ISO/IEC 7816-4 padding. */ MBEDTLS_PADDING_ZEROS_AND_LEN, /**< ANSI X.923 padding. */ - MBEDTLS_PADDING_ZEROS, /**< zero padding (not reversible). */ - MBEDTLS_PADDING_NONE, /**< never pad (full blocks only). */ + MBEDTLS_PADDING_ZEROS, /**< Zero padding (not reversible). */ + MBEDTLS_PADDING_NONE, /**< Never pad (full blocks only). */ } mbedtls_cipher_padding_t; /** Type of operation. */ @@ -204,7 +239,8 @@ typedef struct mbedtls_cmac_context_t mbedtls_cmac_context_t; * Cipher information. Allows calling cipher functions * in a generic way. */ -typedef struct { +typedef struct mbedtls_cipher_info_t +{ /** Full cipher identifier. For example, * MBEDTLS_CIPHER_AES_256_CBC. */ @@ -228,7 +264,10 @@ typedef struct { */ unsigned int iv_size; - /** Flags to set. For example, if the cipher supports variable IV sizes or variable key sizes. */ + /** Bitflag comprised of MBEDTLS_CIPHER_VARIABLE_IV_LEN and + * MBEDTLS_CIPHER_VARIABLE_KEY_LEN indicating whether the + * cipher supports variable IV or variable key sizes, respectively. + */ int flags; /** The block size, in Bytes. */ @@ -242,7 +281,8 @@ typedef struct { /** * Generic cipher context. */ -typedef struct { +typedef struct mbedtls_cipher_context_t +{ /** Information about the associated cipher. */ const mbedtls_cipher_info_t *cipher_info; @@ -268,7 +308,8 @@ typedef struct { /** Number of Bytes that have not been processed yet. */ size_t unprocessed_len; - /** Current IV or NONCE_COUNTER for CTR-mode. */ + /** Current IV or NONCE_COUNTER for CTR-mode, data unit (or sector) number + * for XTS-mode. */ unsigned char iv[MBEDTLS_MAX_IV_LENGTH]; /** IV size in Bytes, for ciphers with variable-length IVs. */ @@ -296,10 +337,12 @@ const int *mbedtls_cipher_list( void ); * \brief This function retrieves the cipher-information * structure associated with the given cipher name. * - * \param cipher_name Name of the cipher to search for. + * \param cipher_name Name of the cipher to search for. This must not be + * \c NULL. * * \return The cipher information structure associated with the - * given \p cipher_name, or NULL if not found. + * given \p cipher_name. + * \return \c NULL if the associated cipher information is not found. */ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher_name ); @@ -310,7 +353,8 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher * \param cipher_type Type of the cipher to search for. * * \return The cipher information structure associated with the - * given \p cipher_type, or NULL if not found. + * given \p cipher_type. + * \return \c NULL if the associated cipher information is not found. */ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher_type_t cipher_type ); @@ -325,7 +369,8 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher * \param mode The cipher mode. For example, #MBEDTLS_MODE_CBC. * * \return The cipher information structure associated with the - * given \p cipher_id, or NULL if not found. + * given \p cipher_id. + * \return \c NULL if the associated cipher information is not found. */ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_cipher_id_t cipher_id, int key_bitlen, @@ -333,6 +378,8 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_ciph /** * \brief This function initializes a \p cipher_context as NONE. + * + * \param ctx The context to be initialized. This must not be \c NULL. */ void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx ); @@ -340,6 +387,10 @@ void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx ); * \brief This function frees and clears the cipher-specific * context of \p ctx. Freeing \p ctx itself remains the * responsibility of the caller. + * + * \param ctx The context to be freed. If this is \c NULL, the + * function has no effect, otherwise this must point to an + * initialized context. */ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx ); @@ -349,31 +400,35 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx ); * structure with the appropriate values. It also clears * the structure. * - * \param ctx The context to initialize. May not be NULL. + * \param ctx The context to initialize. This must be initialized. * \param cipher_info The cipher to use. * - * \return \c 0 on success, - * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on parameter failure, - * #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the - * cipher-specific context failed. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. + * \return #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the + * cipher-specific context fails. * * \internal Currently, the function also clears the structure. * In future versions, the caller will be required to call * mbedtls_cipher_init() on the structure first. */ -int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info ); +int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, + const mbedtls_cipher_info_t *cipher_info ); /** * \brief This function returns the block size of the given cipher. * - * \param ctx The context of the cipher. Must be initialized. + * \param ctx The context of the cipher. This must be initialized. * - * \return The size of the blocks of the cipher, or zero if \p ctx - * has not been initialized. + * \return The block size of the underlying cipher. + * \return \c 0 if \p ctx has not been initialized. */ -static inline unsigned int mbedtls_cipher_get_block_size( const mbedtls_cipher_context_t *ctx ) +static inline unsigned int mbedtls_cipher_get_block_size( + const mbedtls_cipher_context_t *ctx ) { - if( NULL == ctx || NULL == ctx->cipher_info ) + MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 ); + if( ctx->cipher_info == NULL ) return 0; return ctx->cipher_info->block_size; @@ -383,14 +438,16 @@ static inline unsigned int mbedtls_cipher_get_block_size( const mbedtls_cipher_c * \brief This function returns the mode of operation for * the cipher. For example, MBEDTLS_MODE_CBC. * - * \param ctx The context of the cipher. Must be initialized. + * \param ctx The context of the cipher. This must be initialized. * - * \return The mode of operation, or #MBEDTLS_MODE_NONE if - * \p ctx has not been initialized. + * \return The mode of operation. + * \return #MBEDTLS_MODE_NONE if \p ctx has not been initialized. */ -static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode( const mbedtls_cipher_context_t *ctx ) +static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode( + const mbedtls_cipher_context_t *ctx ) { - if( NULL == ctx || NULL == ctx->cipher_info ) + MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, MBEDTLS_MODE_NONE ); + if( ctx->cipher_info == NULL ) return MBEDTLS_MODE_NONE; return ctx->cipher_info->mode; @@ -400,15 +457,17 @@ static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode( const mbedtl * \brief This function returns the size of the IV or nonce * of the cipher, in Bytes. * - * \param ctx The context of the cipher. Must be initialized. + * \param ctx The context of the cipher. This must be initialized. * - * \return
  • If no IV has been set: the recommended IV size. - * 0 for ciphers not using IV or nonce.
  • - *
  • If IV has already been set: the actual size.
+ * \return The recommended IV size if no IV has been set. + * \return \c 0 for ciphers not using an IV or a nonce. + * \return The actual size if an IV has been set. */ -static inline int mbedtls_cipher_get_iv_size( const mbedtls_cipher_context_t *ctx ) +static inline int mbedtls_cipher_get_iv_size( + const mbedtls_cipher_context_t *ctx ) { - if( NULL == ctx || NULL == ctx->cipher_info ) + MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 ); + if( ctx->cipher_info == NULL ) return 0; if( ctx->iv_size != 0 ) @@ -420,14 +479,17 @@ static inline int mbedtls_cipher_get_iv_size( const mbedtls_cipher_context_t *ct /** * \brief This function returns the type of the given cipher. * - * \param ctx The context of the cipher. Must be initialized. + * \param ctx The context of the cipher. This must be initialized. * - * \return The type of the cipher, or #MBEDTLS_CIPHER_NONE if - * \p ctx has not been initialized. + * \return The type of the cipher. + * \return #MBEDTLS_CIPHER_NONE if \p ctx has not been initialized. */ -static inline mbedtls_cipher_type_t mbedtls_cipher_get_type( const mbedtls_cipher_context_t *ctx ) +static inline mbedtls_cipher_type_t mbedtls_cipher_get_type( + const mbedtls_cipher_context_t *ctx ) { - if( NULL == ctx || NULL == ctx->cipher_info ) + MBEDTLS_INTERNAL_VALIDATE_RET( + ctx != NULL, MBEDTLS_CIPHER_NONE ); + if( ctx->cipher_info == NULL ) return MBEDTLS_CIPHER_NONE; return ctx->cipher_info->type; @@ -437,14 +499,16 @@ static inline mbedtls_cipher_type_t mbedtls_cipher_get_type( const mbedtls_ciphe * \brief This function returns the name of the given cipher * as a string. * - * \param ctx The context of the cipher. Must be initialized. + * \param ctx The context of the cipher. This must be initialized. * - * \return The name of the cipher, or NULL if \p ctx has not - * been not initialized. + * \return The name of the cipher. + * \return NULL if \p ctx has not been not initialized. */ -static inline const char *mbedtls_cipher_get_name( const mbedtls_cipher_context_t *ctx ) +static inline const char *mbedtls_cipher_get_name( + const mbedtls_cipher_context_t *ctx ) { - if( NULL == ctx || NULL == ctx->cipher_info ) + MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 ); + if( ctx->cipher_info == NULL ) return 0; return ctx->cipher_info->name; @@ -453,15 +517,18 @@ static inline const char *mbedtls_cipher_get_name( const mbedtls_cipher_context_ /** * \brief This function returns the key length of the cipher. * - * \param ctx The context of the cipher. Must be initialized. + * \param ctx The context of the cipher. This must be initialized. * - * \return The key length of the cipher in bits, or - * #MBEDTLS_KEY_LENGTH_NONE if ctx \p has not been + * \return The key length of the cipher in bits. + * \return #MBEDTLS_KEY_LENGTH_NONE if ctx \p has not been * initialized. */ -static inline int mbedtls_cipher_get_key_bitlen( const mbedtls_cipher_context_t *ctx ) +static inline int mbedtls_cipher_get_key_bitlen( + const mbedtls_cipher_context_t *ctx ) { - if( NULL == ctx || NULL == ctx->cipher_info ) + MBEDTLS_INTERNAL_VALIDATE_RET( + ctx != NULL, MBEDTLS_KEY_LENGTH_NONE ); + if( ctx->cipher_info == NULL ) return MBEDTLS_KEY_LENGTH_NONE; return (int) ctx->cipher_info->key_bitlen; @@ -470,15 +537,17 @@ static inline int mbedtls_cipher_get_key_bitlen( const mbedtls_cipher_context_t /** * \brief This function returns the operation of the given cipher. * - * \param ctx The context of the cipher. Must be initialized. + * \param ctx The context of the cipher. This must be initialized. * - * \return The type of operation: #MBEDTLS_ENCRYPT or - * #MBEDTLS_DECRYPT, or #MBEDTLS_OPERATION_NONE if \p ctx - * has not been initialized. + * \return The type of operation: #MBEDTLS_ENCRYPT or #MBEDTLS_DECRYPT. + * \return #MBEDTLS_OPERATION_NONE if \p ctx has not been initialized. */ -static inline mbedtls_operation_t mbedtls_cipher_get_operation( const mbedtls_cipher_context_t *ctx ) +static inline mbedtls_operation_t mbedtls_cipher_get_operation( + const mbedtls_cipher_context_t *ctx ) { - if( NULL == ctx || NULL == ctx->cipher_info ) + MBEDTLS_INTERNAL_VALIDATE_RET( + ctx != NULL, MBEDTLS_OPERATION_NONE ); + if( ctx->cipher_info == NULL ) return MBEDTLS_OPERATION_NONE; return ctx->operation; @@ -487,20 +556,23 @@ static inline mbedtls_operation_t mbedtls_cipher_get_operation( const mbedtls_ci /** * \brief This function sets the key to use with the given context. * - * \param ctx The generic cipher context. May not be NULL. Must have - * been initialized using mbedtls_cipher_info_from_type() - * or mbedtls_cipher_info_from_string(). - * \param key The key to use. - * \param key_bitlen The key length to use, in bits. + * \param ctx The generic cipher context. This must be initialized and + * bound to a cipher information structure. + * \param key The key to use. This must be a readable buffer of at + * least \p key_bitlen Bits. + * \param key_bitlen The key length to use, in Bits. * \param operation The operation that the key will be used for: * #MBEDTLS_ENCRYPT or #MBEDTLS_DECRYPT. * - * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if - * parameter verification fails, or a cipher-specific - * error code. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. + * \return A cipher-specific error code on failure. */ -int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, const unsigned char *key, - int key_bitlen, const mbedtls_operation_t operation ); +int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, + const unsigned char *key, + int key_bitlen, + const mbedtls_operation_t operation ); #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) /** @@ -509,59 +581,71 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, const unsigned char *k * * The default passing mode is PKCS7 padding. * - * \param ctx The generic cipher context. + * \param ctx The generic cipher context. This must be initialized and + * bound to a cipher information structure. * \param mode The padding mode. * - * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE - * if the selected padding mode is not supported, or - * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if the cipher mode + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE + * if the selected padding mode is not supported. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if the cipher mode * does not support padding. */ -int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, mbedtls_cipher_padding_t mode ); +int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, + mbedtls_cipher_padding_t mode ); #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */ /** * \brief This function sets the initialization vector (IV) * or nonce. * - * \param ctx The generic cipher context. - * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers. + * \note Some ciphers do not use IVs nor nonce. For these + * ciphers, this function has no effect. + * + * \param ctx The generic cipher context. This must be initialized and + * bound to a cipher information structure. + * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers. This + * must be a readable buffer of at least \p iv_len Bytes. * \param iv_len The IV length for ciphers with variable-size IV. * This parameter is discarded by ciphers with fixed-size IV. * - * \returns \c 0 on success, or #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA - * - * \note Some ciphers do not use IVs nor nonce. For these - * ciphers, this function has no effect. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. */ int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx, - const unsigned char *iv, size_t iv_len ); + const unsigned char *iv, + size_t iv_len ); /** * \brief This function resets the cipher state. * - * \param ctx The generic cipher context. + * \param ctx The generic cipher context. This must be initialized. * - * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA - * if parameter verification fails. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. */ int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx ); -#if defined(MBEDTLS_GCM_C) +#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) /** * \brief This function adds additional data for AEAD ciphers. - * Only supported with GCM. Must be called - * exactly once, after mbedtls_cipher_reset(). + * Currently supported with GCM and ChaCha20+Poly1305. + * This must be called exactly once, after + * mbedtls_cipher_reset(). * - * \param ctx The generic cipher context. - * \param ad The additional data to use. - * \param ad_len the Length of \p ad. + * \param ctx The generic cipher context. This must be initialized. + * \param ad The additional data to use. This must be a readable + * buffer of at least \p ad_len Bytes. + * \param ad_len the Length of \p ad Bytes. * - * \return \c 0 on success, or a specific error code on failure. + * \return \c 0 on success. + * \return A specific error code on failure. */ int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx, const unsigned char *ad, size_t ad_len ); -#endif /* MBEDTLS_GCM_C */ +#endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */ /** * \brief The generic cipher update function. It encrypts or @@ -573,25 +657,29 @@ int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx, * Exception: For MBEDTLS_MODE_ECB, expects a single block * in size. For example, 16 Bytes for AES. * - * \param ctx The generic cipher context. - * \param input The buffer holding the input data. + * \note If the underlying cipher is used in GCM mode, all calls + * to this function, except for the last one before + * mbedtls_cipher_finish(), must have \p ilen as a + * multiple of the block size of the cipher. + * + * \param ctx The generic cipher context. This must be initialized and + * bound to a key. + * \param input The buffer holding the input data. This must be a + * readable buffer of at least \p ilen Bytes. * \param ilen The length of the input data. - * \param output The buffer for the output data. Must be able to hold at - * least \p ilen + block_size. Must not be the same buffer - * as input. + * \param output The buffer for the output data. This must be able to + * hold at least `ilen + block_size`. This must not be the + * same buffer as \p input. * \param olen The length of the output data, to be updated with the - * actual number of Bytes written. + * actual number of Bytes written. This must not be + * \c NULL. * - * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if - * parameter verification fails, - * #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE on an - * unsupported mode for a cipher, or a cipher-specific - * error code. - * - * \note If the underlying cipher is GCM, all calls to this - * function, except the last one before - * mbedtls_cipher_finish(). Must have \p ilen as a - * multiple of the block_size. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. + * \return #MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE on an + * unsupported mode for a cipher. + * \return A cipher-specific error code on failure. */ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen ); @@ -602,78 +690,94 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i * contained in it is padded to the size of * the last block, and written to the \p output buffer. * - * \param ctx The generic cipher context. - * \param output The buffer to write data to. Needs block_size available. + * \param ctx The generic cipher context. This must be initialized and + * bound to a key. + * \param output The buffer to write data to. This needs to be a writable + * buffer of at least \p block_size Bytes. * \param olen The length of the data written to the \p output buffer. + * This may not be \c NULL. * - * \returns \c 0 on success, #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if - * parameter verification fails, - * #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED if decryption - * expected a full block but was not provided one, - * #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding - * while decrypting, or a cipher-specific error code - * on failure for any other reason. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. + * \return #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED on decryption + * expecting a full block but not receiving one. + * \return #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding + * while decrypting. + * \return A cipher-specific error code on failure. */ int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, unsigned char *output, size_t *olen ); -#if defined(MBEDTLS_GCM_C) +#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) /** * \brief This function writes a tag for AEAD ciphers. - * Only supported with GCM. - * Must be called after mbedtls_cipher_finish(). - * - * \param ctx The generic cipher context. - * \param tag The buffer to write the tag to. + * Currently supported with GCM and ChaCha20+Poly1305. + * This must be called after mbedtls_cipher_finish(). + * + * \param ctx The generic cipher context. This must be initialized, + * bound to a key, and have just completed a cipher + * operation through mbedtls_cipher_finish() the tag for + * which should be written. + * \param tag The buffer to write the tag to. This must be a writable + * buffer of at least \p tag_len Bytes. * \param tag_len The length of the tag to write. * - * \return \c 0 on success, or a specific error code on failure. + * \return \c 0 on success. + * \return A specific error code on failure. */ int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx, unsigned char *tag, size_t tag_len ); /** * \brief This function checks the tag for AEAD ciphers. - * Only supported with GCM. - * Must be called after mbedtls_cipher_finish(). + * Currently supported with GCM and ChaCha20+Poly1305. + * This must be called after mbedtls_cipher_finish(). * - * \param ctx The generic cipher context. - * \param tag The buffer holding the tag. + * \param ctx The generic cipher context. This must be initialized. + * \param tag The buffer holding the tag. This must be a readable + * buffer of at least \p tag_len Bytes. * \param tag_len The length of the tag to check. * - * \return \c 0 on success, or a specific error code on failure. + * \return \c 0 on success. + * \return A specific error code on failure. */ int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx, const unsigned char *tag, size_t tag_len ); -#endif /* MBEDTLS_GCM_C */ +#endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */ /** * \brief The generic all-in-one encryption/decryption function, * for all ciphers except AEAD constructs. * - * \param ctx The generic cipher context. + * \param ctx The generic cipher context. This must be initialized. * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers. + * This must be a readable buffer of at least \p iv_len + * Bytes. * \param iv_len The IV length for ciphers with variable-size IV. * This parameter is discarded by ciphers with fixed-size * IV. - * \param input The buffer holding the input data. - * \param ilen The length of the input data. - * \param output The buffer for the output data. Must be able to hold at - * least \p ilen + block_size. Must not be the same buffer - * as input. + * \param input The buffer holding the input data. This must be a + * readable buffer of at least \p ilen Bytes. + * \param ilen The length of the input data in Bytes. + * \param output The buffer for the output data. This must be able to + * hold at least `ilen + block_size`. This must not be the + * same buffer as \p input. * \param olen The length of the output data, to be updated with the - * actual number of Bytes written. + * actual number of Bytes written. This must not be + * \c NULL. * * \note Some ciphers do not use IVs nor nonce. For these * ciphers, use \p iv = NULL and \p iv_len = 0. * - * \returns \c 0 on success, or - * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, or - * #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED if decryption - * expected a full block but was not provided one, or - * #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding - * while decrypting, or a cipher-specific error code on - * failure for any other reason. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. + * \return #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED on decryption + * expecting a full block but not receiving one. + * \return #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding + * while decrypting. + * \return A cipher-specific error code on failure. */ int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, @@ -684,24 +788,32 @@ int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx, /** * \brief The generic autenticated encryption (AEAD) function. * - * \param ctx The generic cipher context. + * \param ctx The generic cipher context. This must be initialized and + * bound to a key. * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers. + * This must be a readable buffer of at least \p iv_len + * Bytes. * \param iv_len The IV length for ciphers with variable-size IV. * This parameter is discarded by ciphers with fixed-size IV. - * \param ad The additional data to authenticate. + * \param ad The additional data to authenticate. This must be a + * readable buffer of at least \p ad_len Bytes. * \param ad_len The length of \p ad. - * \param input The buffer holding the input data. + * \param input The buffer holding the input data. This must be a + * readable buffer of at least \p ilen Bytes. * \param ilen The length of the input data. - * \param output The buffer for the output data. - * Must be able to hold at least \p ilen. + * \param output The buffer for the output data. This must be able to + * hold at least \p ilen Bytes. * \param olen The length of the output data, to be updated with the - * actual number of Bytes written. - * \param tag The buffer for the authentication tag. + * actual number of Bytes written. This must not be + * \c NULL. + * \param tag The buffer for the authentication tag. This must be a + * writable buffer of at least \p tag_len Bytes. * \param tag_len The desired length of the authentication tag. * - * \returns \c 0 on success, or - * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, or - * a cipher-specific error code. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. + * \return A cipher-specific error code on failure. */ int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, @@ -713,29 +825,37 @@ int mbedtls_cipher_auth_encrypt( mbedtls_cipher_context_t *ctx, /** * \brief The generic autenticated decryption (AEAD) function. * - * \param ctx The generic cipher context. + * \note If the data is not authentic, then the output buffer + * is zeroed out to prevent the unauthentic plaintext being + * used, making this interface safer. + * + * \param ctx The generic cipher context. This must be initialized and + * and bound to a key. * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers. + * This must be a readable buffer of at least \p iv_len + * Bytes. * \param iv_len The IV length for ciphers with variable-size IV. * This parameter is discarded by ciphers with fixed-size IV. - * \param ad The additional data to be authenticated. + * \param ad The additional data to be authenticated. This must be a + * readable buffer of at least \p ad_len Bytes. * \param ad_len The length of \p ad. - * \param input The buffer holding the input data. + * \param input The buffer holding the input data. This must be a + * readable buffer of at least \p ilen Bytes. * \param ilen The length of the input data. * \param output The buffer for the output data. - * Must be able to hold at least \p ilen. + * This must be able to hold at least \p ilen Bytes. * \param olen The length of the output data, to be updated with the - * actual number of Bytes written. - * \param tag The buffer holding the authentication tag. + * actual number of Bytes written. This must not be + * \c NULL. + * \param tag The buffer holding the authentication tag. This must be + * a readable buffer of at least \p tag_len Bytes. * \param tag_len The length of the authentication tag. * - * \returns \c 0 on success, or - * #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, or - * #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic, - * or a cipher-specific error code on failure for any other reason. - * - * \note If the data is not authentic, then the output buffer - * is zeroed out to prevent the unauthentic plaintext being - * used, making this interface safer. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on + * parameter-verification failure. + * \return #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic. + * \return A cipher-specific error code on failure. */ int mbedtls_cipher_auth_decrypt( mbedtls_cipher_context_t *ctx, const unsigned char *iv, size_t iv_len, diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/cipher_internal.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/cipher_internal.h index 969ff9ccb8..c6def0bef7 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/cipher_internal.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/cipher_internal.h @@ -64,6 +64,14 @@ struct mbedtls_cipher_base_t unsigned char *output ); #endif +#if defined(MBEDTLS_CIPHER_MODE_OFB) + /** Encrypt using OFB (Full length) */ + int (*ofb_func)( void *ctx, size_t length, size_t *iv_off, + unsigned char *iv, + const unsigned char *input, + unsigned char *output ); +#endif + #if defined(MBEDTLS_CIPHER_MODE_CTR) /** Encrypt using CTR */ int (*ctr_func)( void *ctx, size_t length, size_t *nc_off, @@ -71,6 +79,13 @@ struct mbedtls_cipher_base_t const unsigned char *input, unsigned char *output ); #endif +#if defined(MBEDTLS_CIPHER_MODE_XTS) + /** Encrypt or decrypt using XTS. */ + int (*xts_func)( void *ctx, mbedtls_operation_t mode, size_t length, + const unsigned char data_unit[16], + const unsigned char *input, unsigned char *output ); +#endif + #if defined(MBEDTLS_CIPHER_MODE_STREAM) /** Encrypt using STREAM */ int (*stream_func)( void *ctx, size_t length, diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/cmac.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/cmac.h index adfe1c3e01..9d42b3f209 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/cmac.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/cmac.h @@ -1,8 +1,10 @@ /** * \file cmac.h * - * \brief The Cipher-based Message Authentication Code (CMAC) Mode for - * Authentication. + * \brief This file contains CMAC definitions and functions. + * + * The Cipher-based Message Authentication Code (CMAC) Mode for + * Authentication is defined in RFC-4493: The AES-CMAC Algorithm. */ /* * Copyright (C) 2015-2018, Arm Limited (or its affiliates), All Rights Reserved @@ -38,15 +40,16 @@ extern "C" { #endif +/* MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_CMAC_HW_ACCEL_FAILED -0x007A /**< CMAC hardware accelerator failed. */ #define MBEDTLS_AES_BLOCK_SIZE 16 #define MBEDTLS_DES3_BLOCK_SIZE 8 #if defined(MBEDTLS_AES_C) -#define MBEDTLS_CIPHER_BLKSIZE_MAX 16 /* The longest block used by CMAC is that of AES. */ +#define MBEDTLS_CIPHER_BLKSIZE_MAX 16 /**< The longest block used by CMAC is that of AES. */ #else -#define MBEDTLS_CIPHER_BLKSIZE_MAX 8 /* The longest block used by CMAC is that of 3DES. */ +#define MBEDTLS_CIPHER_BLKSIZE_MAX 8 /**< The longest block used by CMAC is that of 3DES. */ #endif #if !defined(MBEDTLS_CMAC_ALT) @@ -67,22 +70,25 @@ struct mbedtls_cmac_context_t size_t unprocessed_len; }; +#else /* !MBEDTLS_CMAC_ALT */ +#include "cmac_alt.h" +#endif /* !MBEDTLS_CMAC_ALT */ + /** * \brief This function sets the CMAC key, and prepares to authenticate * the input data. * Must be called with an initialized cipher context. * * \param ctx The cipher context used for the CMAC operation, initialized - * as one of the following types:
    - *
  • MBEDTLS_CIPHER_AES_128_ECB
  • - *
  • MBEDTLS_CIPHER_AES_192_ECB
  • - *
  • MBEDTLS_CIPHER_AES_256_ECB
  • - *
  • MBEDTLS_CIPHER_DES_EDE3_ECB
+ * as one of the following types: MBEDTLS_CIPHER_AES_128_ECB, + * MBEDTLS_CIPHER_AES_192_ECB, MBEDTLS_CIPHER_AES_256_ECB, + * or MBEDTLS_CIPHER_DES_EDE3_ECB. * \param key The CMAC key. * \param keybits The length of the CMAC key in bits. * Must be supported by the cipher. * - * \return \c 0 on success, or a cipher-specific error code. + * \return \c 0 on success. + * \return A cipher-specific error code on failure. */ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx, const unsigned char *key, size_t keybits ); @@ -99,8 +105,9 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx, * \param input The buffer holding the input data. * \param ilen The length of the input data. * - * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA - * if parameter verification fails. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA + * if parameter verification fails. */ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx, const unsigned char *input, size_t ilen ); @@ -116,7 +123,8 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx, * \param ctx The cipher context used for the CMAC operation. * \param output The output buffer for the CMAC checksum result. * - * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA * if parameter verification fails. */ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx, @@ -132,7 +140,8 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx, * * \param ctx The cipher context used for the CMAC operation. * - * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA * if parameter verification fails. */ int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx ); @@ -155,7 +164,8 @@ int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx ); * \param ilen The length of the input data. * \param output The buffer for the generic CMAC result. * - * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA * if parameter verification fails. */ int mbedtls_cipher_cmac( const mbedtls_cipher_info_t *cipher_info, @@ -186,23 +196,12 @@ int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_len, unsigned char output[16] ); #endif /* MBEDTLS_AES_C */ -#ifdef __cplusplus -} -#endif - -#else /* !MBEDTLS_CMAC_ALT */ -#include "cmac_alt.h" -#endif /* !MBEDTLS_CMAC_ALT */ - -#ifdef __cplusplus -extern "C" { -#endif - #if defined(MBEDTLS_SELF_TEST) && ( defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C) ) /** * \brief The CMAC checkup routine. * - * \return \c 0 on success, or \c 1 on failure. + * \return \c 0 on success. + * \return \c 1 on failure. */ int mbedtls_cmac_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST && ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/compat-1.3.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/compat-1.3.h index 94de845dd8..a58b47243d 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/compat-1.3.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/compat-1.3.h @@ -1384,7 +1384,8 @@ #define SSL_ANTI_REPLAY_ENABLED MBEDTLS_SSL_ANTI_REPLAY_ENABLED #define SSL_ARC4_DISABLED MBEDTLS_SSL_ARC4_DISABLED #define SSL_ARC4_ENABLED MBEDTLS_SSL_ARC4_ENABLED -#define SSL_BUFFER_LEN MBEDTLS_SSL_BUFFER_LEN +#define SSL_BUFFER_LEN ( ( ( MBEDTLS_SSL_IN_BUFFER_LEN ) < ( MBEDTLS_SSL_OUT_BUFFER_LEN ) ) \ + ? ( MBEDTLS_SSL_IN_BUFFER_LEN ) : ( MBEDTLS_SSL_OUT_BUFFER_LEN ) ) #define SSL_CACHE_DEFAULT_MAX_ENTRIES MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES #define SSL_CACHE_DEFAULT_TIMEOUT MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT #define SSL_CBC_RECORD_SPLITTING_DISABLED MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/config.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/config.h index f3039f937f..654f9725e4 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/config.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/config.h @@ -8,7 +8,7 @@ * memory footprint. */ /* - * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * Copyright (C) 2006-2018, ARM Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -48,10 +48,14 @@ * Requires support for asm() in compiler. * * Used in: + * library/aria.c * library/timing.c - * library/padlock.c * include/mbedtls/bn_mul.h * + * Required by: + * MBEDTLS_AESNI_C + * MBEDTLS_PADLOCK_C + * * Comment to disable the use of assembly code. */ #define MBEDTLS_HAVE_ASM @@ -84,6 +88,28 @@ */ //#define MBEDTLS_NO_UDBL_DIVISION +/** + * \def MBEDTLS_NO_64BIT_MULTIPLICATION + * + * The platform lacks support for 32x32 -> 64-bit multiplication. + * + * Used in: + * library/poly1305.c + * + * Some parts of the library may use multiplication of two unsigned 32-bit + * operands with a 64-bit result in order to speed up computations. On some + * platforms, this is not available in hardware and has to be implemented in + * software, usually in a library provided by the toolchain. + * + * Sometimes it is not desirable to have to link to that library. This option + * removes the dependency of that library on platforms that lack a hardware + * 64-bit multiplier by embedding a software implementation in Mbed TLS. + * + * Note that depending on the compiler, this may decrease performance compared + * to using the library function provided by the toolchain. + */ +//#define MBEDTLS_NO_64BIT_MULTIPLICATION + /** * \def MBEDTLS_HAVE_SSE2 * @@ -111,12 +137,21 @@ /** * \def MBEDTLS_HAVE_TIME_DATE * - * System has time.h and time(), gmtime() and the clock is correct. + * System has time.h, time(), and an implementation for + * mbedtls_platform_gmtime_r() (see below). * The time needs to be correct (not necesarily very accurate, but at least * the date should be correct). This is used to verify the validity period of * X.509 certificates. * * Comment if your system does not have a correct clock. + * + * \note mbedtls_platform_gmtime_r() is an abstraction in platform_util.h that + * behaves similarly to the gmtime_r() function from the C standard. Refer to + * the documentation for mbedtls_platform_gmtime_r() for more information. + * + * \note It is possible to configure an implementation for + * mbedtls_platform_gmtime_r() at compile-time by using the macro + * MBEDTLS_PLATFORM_GMTIME_R_ALT. */ #define MBEDTLS_HAVE_TIME_DATE @@ -221,6 +256,48 @@ */ //#define MBEDTLS_DEPRECATED_REMOVED +/** + * \def MBEDTLS_CHECK_PARAMS + * + * This configuration option controls whether the library validates more of + * the parameters passed to it. + * + * When this flag is not defined, the library only attempts to validate an + * input parameter if: (1) they may come from the outside world (such as the + * network, the filesystem, etc.) or (2) not validating them could result in + * internal memory errors such as overflowing a buffer controlled by the + * library. On the other hand, it doesn't attempt to validate parameters whose + * values are fully controlled by the application (such as pointers). + * + * When this flag is defined, the library additionally attempts to validate + * parameters that are fully controlled by the application, and should always + * be valid if the application code is fully correct and trusted. + * + * For example, when a function accepts as input a pointer to a buffer that may + * contain untrusted data, and its documentation mentions that this pointer + * must not be NULL: + * - the pointer is checked to be non-NULL only if this option is enabled + * - the content of the buffer is always validated + * + * When this flag is defined, if a library function receives a parameter that + * is invalid, it will: + * - invoke the macro MBEDTLS_PARAM_FAILED() which by default expands to a + * call to the function mbedtls_param_failed() + * - immediately return (with a specific error code unless the function + * returns void and can't communicate an error). + * + * When defining this flag, you also need to: + * - either provide a definition of the function mbedtls_param_failed() in + * your application (see platform_util.h for its prototype) as the library + * calls that function, but does not provide a default definition for it, + * - or provide a different definition of the macro MBEDTLS_PARAM_FAILED() + * below if the above mechanism is not flexible enough to suit your needs. + * See the documentation of this macro later in this file. + * + * Uncomment to enable validation of application-controlled parameters. + */ +//#define MBEDTLS_CHECK_PARAMS + /* \} name SECTION: System support */ /** @@ -271,23 +348,29 @@ */ //#define MBEDTLS_AES_ALT //#define MBEDTLS_ARC4_ALT +//#define MBEDTLS_ARIA_ALT //#define MBEDTLS_BLOWFISH_ALT //#define MBEDTLS_CAMELLIA_ALT //#define MBEDTLS_CCM_ALT +//#define MBEDTLS_CHACHA20_ALT +//#define MBEDTLS_CHACHAPOLY_ALT //#define MBEDTLS_CMAC_ALT //#define MBEDTLS_DES_ALT //#define MBEDTLS_DHM_ALT //#define MBEDTLS_ECJPAKE_ALT //#define MBEDTLS_GCM_ALT +//#define MBEDTLS_NIST_KW_ALT //#define MBEDTLS_MD2_ALT //#define MBEDTLS_MD4_ALT //#define MBEDTLS_MD5_ALT +//#define MBEDTLS_POLY1305_ALT //#define MBEDTLS_RIPEMD160_ALT //#define MBEDTLS_RSA_ALT //#define MBEDTLS_SHA1_ALT //#define MBEDTLS_SHA256_ALT //#define MBEDTLS_SHA512_ALT //#define MBEDTLS_XTEA_ALT + /* * When replacing the elliptic curve module, pleace consider, that it is * implemented with two .c files: @@ -373,11 +456,11 @@ * unsigned char mbedtls_internal_ecp_grp_capable( * const mbedtls_ecp_group *grp ) * int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp ) - * void mbedtls_internal_ecp_deinit( const mbedtls_ecp_group *grp ) + * void mbedtls_internal_ecp_free( const mbedtls_ecp_group *grp ) * The mbedtls_internal_ecp_grp_capable function should return 1 if the * replacement functions implement arithmetic for the given group and 0 * otherwise. - * The functions mbedtls_internal_ecp_init and mbedtls_internal_ecp_deinit are + * The functions mbedtls_internal_ecp_init and mbedtls_internal_ecp_free are * called before and after each point operation and provide an opportunity to * implement optimized set up and tear down instructions. * @@ -440,12 +523,45 @@ /** * \def MBEDTLS_AES_ROM_TABLES * - * Store the AES tables in ROM. + * Use precomputed AES tables stored in ROM. + * + * Uncomment this macro to use precomputed AES tables stored in ROM. + * Comment this macro to generate AES tables in RAM at runtime. + * + * Tradeoff: Using precomputed ROM tables reduces RAM usage by ~8kb + * (or ~2kb if \c MBEDTLS_AES_FEWER_TABLES is used) and reduces the + * initialization time before the first AES operation can be performed. + * It comes at the cost of additional ~8kb ROM use (resp. ~2kb if \c + * MBEDTLS_AES_FEWER_TABLES below is used), and potentially degraded + * performance if ROM access is slower than RAM access. + * + * This option is independent of \c MBEDTLS_AES_FEWER_TABLES. * - * Uncomment this macro to store the AES tables in ROM. */ //#define MBEDTLS_AES_ROM_TABLES +/** + * \def MBEDTLS_AES_FEWER_TABLES + * + * Use less ROM/RAM for AES tables. + * + * Uncommenting this macro omits 75% of the AES tables from + * ROM / RAM (depending on the value of \c MBEDTLS_AES_ROM_TABLES) + * by computing their values on the fly during operations + * (the tables are entry-wise rotations of one another). + * + * Tradeoff: Uncommenting this reduces the RAM / ROM footprint + * by ~6kb but at the cost of more arithmetic operations during + * runtime. Specifically, one has to compare 4 accesses within + * different tables to 4 accesses with additional arithmetic + * operations within the same table. The performance gain/loss + * depends on the system and memory details. + * + * This option is independent of \c MBEDTLS_AES_ROM_TABLES. + * + */ +//#define MBEDTLS_AES_FEWER_TABLES + /** * \def MBEDTLS_CAMELLIA_SMALL_MEMORY * @@ -476,6 +592,20 @@ */ #define MBEDTLS_CIPHER_MODE_CTR +/** + * \def MBEDTLS_CIPHER_MODE_OFB + * + * Enable Output Feedback mode (OFB) for symmetric ciphers. + */ +#define MBEDTLS_CIPHER_MODE_OFB + +/** + * \def MBEDTLS_CIPHER_MODE_XTS + * + * Enable Xor-encrypt-xor with ciphertext stealing mode (XTS) for AES. + */ +#define MBEDTLS_CIPHER_MODE_XTS + /** * \def MBEDTLS_CIPHER_NULL_CIPHER * @@ -596,6 +726,7 @@ #define MBEDTLS_ECP_DP_BP384R1_ENABLED #define MBEDTLS_ECP_DP_BP512R1_ENABLED #define MBEDTLS_ECP_DP_CURVE25519_ENABLED +#define MBEDTLS_ECP_DP_CURVE448_ENABLED /** * \def MBEDTLS_ECP_NIST_OPTIM @@ -608,6 +739,30 @@ */ #define MBEDTLS_ECP_NIST_OPTIM +/** + * \def MBEDTLS_ECP_RESTARTABLE + * + * Enable "non-blocking" ECC operations that can return early and be resumed. + * + * This allows various functions to pause by returning + * #MBEDTLS_ERR_ECP_IN_PROGRESS (or, for functions in the SSL module, + * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS) and then be called later again in + * order to further progress and eventually complete their operation. This is + * controlled through mbedtls_ecp_set_max_ops() which limits the maximum + * number of ECC operations a function may perform before pausing; see + * mbedtls_ecp_set_max_ops() for more information. + * + * This is useful in non-threaded environments if you want to avoid blocking + * for too long on ECC (and, hence, X.509 or SSL/TLS) operations. + * + * Uncomment this macro to enable restartable ECC computations. + * + * \note This option only works with the default software implementation of + * elliptic curve functionality. It is incompatible with + * MBEDTLS_ECP_ALT, MBEDTLS_ECDH_XXX_ALT and MBEDTLS_ECDSA_XXX_ALT. + */ +//#define MBEDTLS_ECP_RESTARTABLE + /** * \def MBEDTLS_ECDSA_DETERMINISTIC * @@ -1114,6 +1269,17 @@ */ #define MBEDTLS_SSL_ALL_ALERT_MESSAGES +/** + * \def MBEDTLS_SSL_ASYNC_PRIVATE + * + * Enable asynchronous external private key operations in SSL. This allows + * you to configure an SSL connection to call an external cryptographic + * module to perform private key operations instead of performing the + * operation inside the library. + * + */ +//#define MBEDTLS_SSL_ASYNC_PRIVATE + /** * \def MBEDTLS_SSL_DEBUG_ALL * @@ -1562,6 +1728,9 @@ * * \note Currently compression can't be used with DTLS. * + * \deprecated This feature is deprecated and will be removed + * in the next major revision of the library. + * * Used in: library/ssl_tls.c * library/ssl_cli.c * library/ssl_srv.c @@ -1600,7 +1769,7 @@ * Enable the AES block cipher. * * Module: library/aes.c - * Caller: library/ssl_tls.c + * Caller: library/cipher.c * library/pem.c * library/ctr_drbg.c * @@ -1675,7 +1844,7 @@ * Enable the ARCFOUR stream cipher. * * Module: library/arc4.c - * Caller: library/ssl_tls.c + * Caller: library/cipher.c * * This module enables the following ciphersuites (if other requisites are * enabled as well): @@ -1769,7 +1938,7 @@ * Enable the Camellia block cipher. * * Module: library/camellia.c - * Caller: library/ssl_tls.c + * Caller: library/cipher.c * * This module enables the following ciphersuites (if other requisites are * enabled as well): @@ -1818,6 +1987,58 @@ */ #define MBEDTLS_CAMELLIA_C +/** + * \def MBEDTLS_ARIA_C + * + * Enable the ARIA block cipher. + * + * Module: library/aria.c + * Caller: library/cipher.c + * + * This module enables the following ciphersuites (if other requisites are + * enabled as well): + * + * MBEDTLS_TLS_RSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_PSK_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_PSK_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384 + * MBEDTLS_TLS_PSK_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_PSK_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256 + * MBEDTLS_TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384 + * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256 + * MBEDTLS_TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384 + */ +//#define MBEDTLS_ARIA_C + /** * \def MBEDTLS_CCM_C * @@ -1844,6 +2065,26 @@ */ #define MBEDTLS_CERTS_C +/** + * \def MBEDTLS_CHACHA20_C + * + * Enable the ChaCha20 stream cipher. + * + * Module: library/chacha20.c + */ +#define MBEDTLS_CHACHA20_C + +/** + * \def MBEDTLS_CHACHAPOLY_C + * + * Enable the ChaCha20-Poly1305 AEAD algorithm. + * + * Module: library/chachapoly.c + * + * This module requires: MBEDTLS_CHACHA20_C, MBEDTLS_POLY1305_C + */ +#define MBEDTLS_CHACHAPOLY_C + /** * \def MBEDTLS_CIPHER_C * @@ -1872,14 +2113,16 @@ /** * \def MBEDTLS_CTR_DRBG_C * - * Enable the CTR_DRBG AES-256-based random generator. + * Enable the CTR_DRBG AES-based random generator. + * The CTR_DRBG generator uses AES-256 by default. + * To use AES-128 instead, enable MBEDTLS_CTR_DRBG_USE_128_BIT_KEY below. * * Module: library/ctr_drbg.c * Caller: * * Requires: MBEDTLS_AES_C * - * This module provides the CTR_DRBG AES-256 random number generator. + * This module provides the CTR_DRBG AES random number generator. */ #define MBEDTLS_CTR_DRBG_C @@ -1904,7 +2147,7 @@ * * Module: library/des.c * Caller: library/pem.c - * library/ssl_tls.c + * library/cipher.c * * This module enables the following ciphersuites (if other requisites are * enabled as well): @@ -2074,6 +2317,21 @@ */ //#define MBEDTLS_HAVEGE_C +/** + * \def MBEDTLS_HKDF_C + * + * Enable the HKDF algorithm (RFC 5869). + * + * Module: library/hkdf.c + * Caller: + * + * Requires: MBEDTLS_MD_C + * + * This module adds support for the Hashed Message Authentication Code + * (HMAC)-based key derivation function (HKDF). + */ +#define MBEDTLS_HKDF_C + /** * \def MBEDTLS_HMAC_DRBG_C * @@ -2088,6 +2346,19 @@ */ #define MBEDTLS_HMAC_DRBG_C +/** + * \def MBEDTLS_NIST_KW_C + * + * Enable the Key Wrapping mode for 128-bit block ciphers, + * as defined in NIST SP 800-38F. Only KW and KWP modes + * are supported. At the moment, only AES is approved by NIST. + * + * Module: library/nist_kw.c + * + * Requires: MBEDTLS_AES_C and MBEDTLS_CIPHER_C + */ +//#define MBEDTLS_NIST_KW_C + /** * \def MBEDTLS_MD_C * @@ -2371,6 +2642,16 @@ */ #define MBEDTLS_PLATFORM_C +/** + * \def MBEDTLS_POLY1305_C + * + * Enable the Poly1305 MAC algorithm. + * + * Module: library/poly1305.c + * Caller: library/chachapoly.c + */ +#define MBEDTLS_POLY1305_C + /** * \def MBEDTLS_RIPEMD160_C * @@ -2726,6 +3007,7 @@ //#define MBEDTLS_CTR_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */ //#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */ //#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */ +//#define MBEDTLS_CTR_DRBG_USE_128_BIT_KEY /**< Use 128-bit key for CTR_DRBG - may reduce security (see ctr_drbg.h) */ /* HMAC_DRBG options */ //#define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */ @@ -2776,12 +3058,134 @@ //#define MBEDTLS_PLATFORM_NV_SEED_READ_MACRO mbedtls_platform_std_nv_seed_read /**< Default nv_seed_read function to use, can be undefined */ //#define MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO mbedtls_platform_std_nv_seed_write /**< Default nv_seed_write function to use, can be undefined */ +/** + * \brief This macro is invoked by the library when an invalid parameter + * is detected that is only checked with MBEDTLS_CHECK_PARAMS + * (see the documentation of that option for context). + * + * When you leave this undefined here, a default definition is + * provided that invokes the function mbedtls_param_failed(), + * which is declared in platform_util.h for the benefit of the + * library, but that you need to define in your application. + * + * When you define this here, this replaces the default + * definition in platform_util.h (which no longer declares the + * function mbedtls_param_failed()) and it is your responsibility + * to make sure this macro expands to something suitable (in + * particular, that all the necessary declarations are visible + * from within the library - you can ensure that by providing + * them in this file next to the macro definition). + * + * Note that you may define this macro to expand to nothing, in + * which case you don't have to worry about declarations or + * definitions. However, you will then be notified about invalid + * parameters only in non-void functions, and void function will + * just silently return early on invalid parameters, which + * partially negates the benefits of enabling + * #MBEDTLS_CHECK_PARAMS in the first place, so is discouraged. + * + * \param cond The expression that should evaluate to true, but doesn't. + */ +//#define MBEDTLS_PARAM_FAILED( cond ) assert( cond ) + /* SSL Cache options */ //#define MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT 86400 /**< 1 day */ //#define MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES 50 /**< Maximum entries in cache */ /* SSL options */ -//#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 /**< Maxium fragment length in bytes, determines the size of each of the two internal I/O buffers */ + +/** \def MBEDTLS_SSL_MAX_CONTENT_LEN + * + * Maximum length (in bytes) of incoming and outgoing plaintext fragments. + * + * This determines the size of both the incoming and outgoing TLS I/O buffers + * in such a way that both are capable of holding the specified amount of + * plaintext data, regardless of the protection mechanism used. + * + * To configure incoming and outgoing I/O buffers separately, use + * #MBEDTLS_SSL_IN_CONTENT_LEN and #MBEDTLS_SSL_OUT_CONTENT_LEN, + * which overwrite the value set by this option. + * + * \note When using a value less than the default of 16KB on the client, it is + * recommended to use the Maximum Fragment Length (MFL) extension to + * inform the server about this limitation. On the server, there + * is no supported, standardized way of informing the client about + * restriction on the maximum size of incoming messages, and unless + * the limitation has been communicated by other means, it is recommended + * to only change the outgoing buffer size #MBEDTLS_SSL_OUT_CONTENT_LEN + * while keeping the default value of 16KB for the incoming buffer. + * + * Uncomment to set the maximum plaintext size of both + * incoming and outgoing I/O buffers. + */ +//#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 + +/** \def MBEDTLS_SSL_IN_CONTENT_LEN + * + * Maximum length (in bytes) of incoming plaintext fragments. + * + * This determines the size of the incoming TLS I/O buffer in such a way + * that it is capable of holding the specified amount of plaintext data, + * regardless of the protection mechanism used. + * + * If this option is undefined, it inherits its value from + * #MBEDTLS_SSL_MAX_CONTENT_LEN. + * + * \note When using a value less than the default of 16KB on the client, it is + * recommended to use the Maximum Fragment Length (MFL) extension to + * inform the server about this limitation. On the server, there + * is no supported, standardized way of informing the client about + * restriction on the maximum size of incoming messages, and unless + * the limitation has been communicated by other means, it is recommended + * to only change the outgoing buffer size #MBEDTLS_SSL_OUT_CONTENT_LEN + * while keeping the default value of 16KB for the incoming buffer. + * + * Uncomment to set the maximum plaintext size of the incoming I/O buffer + * independently of the outgoing I/O buffer. + */ +//#define MBEDTLS_SSL_IN_CONTENT_LEN 16384 + +/** \def MBEDTLS_SSL_OUT_CONTENT_LEN + * + * Maximum length (in bytes) of outgoing plaintext fragments. + * + * This determines the size of the outgoing TLS I/O buffer in such a way + * that it is capable of holding the specified amount of plaintext data, + * regardless of the protection mechanism used. + * + * If this option undefined, it inherits its value from + * #MBEDTLS_SSL_MAX_CONTENT_LEN. + * + * It is possible to save RAM by setting a smaller outward buffer, while keeping + * the default inward 16384 byte buffer to conform to the TLS specification. + * + * The minimum required outward buffer size is determined by the handshake + * protocol's usage. Handshaking will fail if the outward buffer is too small. + * The specific size requirement depends on the configured ciphers and any + * certificate data which is sent during the handshake. + * + * Uncomment to set the maximum plaintext size of the outgoing I/O buffer + * independently of the incoming I/O buffer. + */ +//#define MBEDTLS_SSL_OUT_CONTENT_LEN 16384 + +/** \def MBEDTLS_SSL_DTLS_MAX_BUFFERING + * + * Maximum number of heap-allocated bytes for the purpose of + * DTLS handshake message reassembly and future message buffering. + * + * This should be at least 9/8 * MBEDTLSSL_IN_CONTENT_LEN + * to account for a reassembled handshake message of maximum size, + * together with its reassembly bitmap. + * + * A value of 2 * MBEDTLS_SSL_IN_CONTENT_LEN (32768 by default) + * should be sufficient for all practical situations as it allows + * to reassembly a large handshake message (such as a certificate) + * while buffering multiple smaller handshake messages. + * + */ +//#define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768 + //#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */ //#define MBEDTLS_PSK_MAX_LEN 32 /**< Max size of TLS pre-shared keys, in bytes (default 256 bits) */ //#define MBEDTLS_SSL_COOKIE_TIMEOUT 60 /**< Default expiration delay of DTLS cookies, in seconds if HAVE_TIME, or in number of cookies issued */ @@ -2835,25 +3239,53 @@ */ #define MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_KEY_EXCHANGE -/* \} name SECTION: Customisation configuration options */ - -/* Target and application specific configurations */ -//#define YOTTA_CFG_MBEDTLS_TARGET_CONFIG_FILE "target_config.h" +/** + * Uncomment the macro to let mbed TLS use your alternate implementation of + * mbedtls_platform_zeroize(). This replaces the default implementation in + * platform_util.c. + * + * mbedtls_platform_zeroize() is a widely used function across the library to + * zero a block of memory. The implementation is expected to be secure in the + * sense that it has been written to prevent the compiler from removing calls + * to mbedtls_platform_zeroize() as part of redundant code elimination + * optimizations. However, it is difficult to guarantee that calls to + * mbedtls_platform_zeroize() will not be optimized by the compiler as older + * versions of the C language standards do not provide a secure implementation + * of memset(). Therefore, MBEDTLS_PLATFORM_ZEROIZE_ALT enables users to + * configure their own implementation of mbedtls_platform_zeroize(), for + * example by using directives specific to their compiler, features from newer + * C standards (e.g using memset_s() in C11) or calling a secure memset() from + * their system (e.g explicit_bzero() in BSD). + */ +//#define MBEDTLS_PLATFORM_ZEROIZE_ALT + +/** + * Uncomment the macro to let Mbed TLS use your alternate implementation of + * mbedtls_platform_gmtime_r(). This replaces the default implementation in + * platform_util.c. + * + * gmtime() is not a thread-safe function as defined in the C standard. The + * library will try to use safer implementations of this function, such as + * gmtime_r() when available. However, if Mbed TLS cannot identify the target + * system, the implementation of mbedtls_platform_gmtime_r() will default to + * using the standard gmtime(). In this case, calls from the library to + * gmtime() will be guarded by the global mutex mbedtls_threading_gmtime_mutex + * if MBEDTLS_THREADING_C is enabled. We recommend that calls from outside the + * library are also guarded with this mutex to avoid race conditions. However, + * if the macro MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, Mbed TLS will + * unconditionally use the implementation for mbedtls_platform_gmtime_r() + * supplied at compile time. + */ +//#define MBEDTLS_PLATFORM_GMTIME_R_ALT -#if defined(TARGET_LIKE_MBED) && defined(YOTTA_CFG_MBEDTLS_TARGET_CONFIG_FILE) -#include YOTTA_CFG_MBEDTLS_TARGET_CONFIG_FILE -#endif +/* \} name SECTION: Customisation configuration options */ -/* +/* Target and application specific configurations + * * Allow user to override any previous default. * - * Use two macro names for that, as: - * - with yotta the prefix YOTTA_CFG_ is forced - * - without yotta is looks weird to have a YOTTA prefix. */ -#if defined(YOTTA_CFG_MBEDTLS_USER_CONFIG_FILE) -#include YOTTA_CFG_MBEDTLS_USER_CONFIG_FILE -#elif defined(MBEDTLS_USER_CONFIG_FILE) +#if defined(MBEDTLS_USER_CONFIG_FILE) #include MBEDTLS_USER_CONFIG_FILE #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h index 5a32843152..cc3df7b113 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ctr_drbg.h @@ -1,10 +1,18 @@ /** * \file ctr_drbg.h * - * \brief CTR_DRBG is based on AES-256, as defined in NIST SP 800-90A: - * Recommendation for Random Number Generation Using Deterministic - * Random Bit Generators. + * \brief This file contains CTR_DRBG definitions and functions. * + * CTR_DRBG is a standardized way of building a PRNG from a block-cipher + * in counter mode operation, as defined in NIST SP 800-90A: + * Recommendation for Random Number Generation Using Deterministic Random + * Bit Generators. + * + * The Mbed TLS implementation of CTR_DRBG uses AES-256 (default) or AES-128 + * as the underlying block cipher. + * + * \warning Using 128-bit keys for CTR_DRBG limits the security of generated + * keys and operations that use random values generated to 128-bit security. */ /* * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved @@ -46,7 +54,13 @@ #define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A /**< Read or write error in file. */ #define MBEDTLS_CTR_DRBG_BLOCKSIZE 16 /**< The block size used by the cipher. */ -#define MBEDTLS_CTR_DRBG_KEYSIZE 32 /**< The key size used by the cipher. */ + +#if defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY) +#define MBEDTLS_CTR_DRBG_KEYSIZE 16 /**< The key size used by the cipher (compile-time choice: 128 bits). */ +#else +#define MBEDTLS_CTR_DRBG_KEYSIZE 32 /**< The key size used by the cipher (compile-time choice: 256 bits). */ +#endif + #define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 ) /**< The key size for the DRBG operation, in bits. */ #define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE ) /**< The seed length, calculated as (counter + AES key). */ @@ -109,7 +123,7 @@ extern "C" { /** * \brief The CTR_DRBG context structure. */ -typedef struct +typedef struct mbedtls_ctr_drbg_context { unsigned char counter[16]; /*!< The counter (V). */ int reseed_counter; /*!< The reseed counter. */ @@ -162,8 +176,8 @@ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx ); identifiers. Can be NULL. * \param len The length of the personalization data. * - * \return \c 0 on success, or - * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure. */ int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx, int (*f_entropy)(void *, unsigned char *, size_t), @@ -222,49 +236,30 @@ void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx, * \param additional Additional data to add to the state. Can be NULL. * \param len The length of the additional data. * - * \return \c 0 on success, or - * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on failure. */ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t len ); /** - * \brief This function updates the state of the CTR_DRBG context. - * - * \param ctx The CTR_DRBG context. - * \param additional The data to update the state with. - * \param add_len Length of \p additional in bytes. This must be at - * most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if - * \p add_len is more than - * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT. - * \return An error from the underlying AES cipher on failure. + * \brief This function updates the state of the CTR_DRBG context. + * + * \param ctx The CTR_DRBG context. + * \param additional The data to update the state with. + * \param add_len Length of \p additional in bytes. This must be at + * most #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG if + * \p add_len is more than + * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT. + * \return An error from the underlying AES cipher on failure. */ int mbedtls_ctr_drbg_update_ret( mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len ); -/** - * \brief This function updates the state of the CTR_DRBG context. - * - * \warning This function cannot report errors. You should use - * mbedtls_ctr_drbg_update_ret() instead. - * - * \note If \p add_len is greater than - * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT, only the first - * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT Bytes are used. - * The remaining Bytes are silently discarded. - * - * \param ctx The CTR_DRBG context. - * \param additional The data to update the state with. - * \param add_len Length of \p additional data. - */ -void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx, - const unsigned char *additional, - size_t add_len ); - /** * \brief This function updates a CTR_DRBG instance with additional * data and uses it to generate random data. @@ -278,8 +273,8 @@ void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx, * \param additional Additional data to update. Can be NULL. * \param add_len The length of the additional data. * - * \return \c 0 on success, or - * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure. */ int mbedtls_ctr_drbg_random_with_add( void *p_rng, @@ -296,13 +291,42 @@ int mbedtls_ctr_drbg_random_with_add( void *p_rng, * \param output The buffer to fill. * \param output_len The length of the buffer. * - * \return \c 0 on success, or - * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or * #MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG on failure. */ int mbedtls_ctr_drbg_random( void *p_rng, unsigned char *output, size_t output_len ); + +#if ! defined(MBEDTLS_DEPRECATED_REMOVED) +#if defined(MBEDTLS_DEPRECATED_WARNING) +#define MBEDTLS_DEPRECATED __attribute__((deprecated)) +#else +#define MBEDTLS_DEPRECATED +#endif +/** + * \brief This function updates the state of the CTR_DRBG context. + * + * \deprecated Superseded by mbedtls_ctr_drbg_update_ret() + * in 2.16.0. + * + * \note If \p add_len is greater than + * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT, only the first + * #MBEDTLS_CTR_DRBG_MAX_SEED_INPUT Bytes are used. + * The remaining Bytes are silently discarded. + * + * \param ctx The CTR_DRBG context. + * \param additional The data to update the state with. + * \param add_len Length of \p additional data. + */ +MBEDTLS_DEPRECATED void mbedtls_ctr_drbg_update( + mbedtls_ctr_drbg_context *ctx, + const unsigned char *additional, + size_t add_len ); +#undef MBEDTLS_DEPRECATED +#endif /* !MBEDTLS_DEPRECATED_REMOVED */ + #if defined(MBEDTLS_FS_IO) /** * \brief This function writes a seed file. @@ -310,9 +334,9 @@ int mbedtls_ctr_drbg_random( void *p_rng, * \param ctx The CTR_DRBG context. * \param path The name of the file. * - * \return \c 0 on success, - * #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, or - * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error. + * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED on * failure. */ int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path ); @@ -324,21 +348,26 @@ int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char * \param ctx The CTR_DRBG context. * \param path The name of the file. * - * \return \c 0 on success, - * #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error, - * #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or + * \return \c 0 on success. + * \return #MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR on file error. + * \return #MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED or * #MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG on failure. */ int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path ); #endif /* MBEDTLS_FS_IO */ +#if defined(MBEDTLS_SELF_TEST) + /** * \brief The CTR_DRBG checkup routine. * - * \return \c 0 on success, or \c 1 on failure. + * \return \c 0 on success. + * \return \c 1 on failure. */ int mbedtls_ctr_drbg_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + /* Internal functions (do not call directly) */ int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *, int (*)(void *, unsigned char *, size_t), void *, diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/debug.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/debug.h index ef8db67ff1..736444bb76 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/debug.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/debug.h @@ -65,6 +65,11 @@ mbedtls_debug_print_crt( ssl, level, __FILE__, __LINE__, text, crt ) #endif +#if defined(MBEDTLS_ECDH_C) +#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) \ + mbedtls_debug_printf_ecdh( ssl, level, __FILE__, __LINE__, ecdh, attr ) +#endif + #else /* MBEDTLS_DEBUG_C */ #define MBEDTLS_SSL_DEBUG_MSG( level, args ) do { } while( 0 ) @@ -73,6 +78,7 @@ #define MBEDTLS_SSL_DEBUG_MPI( level, text, X ) do { } while( 0 ) #define MBEDTLS_SSL_DEBUG_ECP( level, text, X ) do { } while( 0 ) #define MBEDTLS_SSL_DEBUG_CRT( level, text, crt ) do { } while( 0 ) +#define MBEDTLS_SSL_DEBUG_ECDH( level, ecdh, attr ) do { } while( 0 ) #endif /* MBEDTLS_DEBUG_C */ @@ -221,6 +227,36 @@ void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level, const char *text, const mbedtls_x509_crt *crt ); #endif +#if defined(MBEDTLS_ECDH_C) +typedef enum +{ + MBEDTLS_DEBUG_ECDH_Q, + MBEDTLS_DEBUG_ECDH_QP, + MBEDTLS_DEBUG_ECDH_Z, +} mbedtls_debug_ecdh_attr; + +/** + * \brief Print a field of the ECDH structure in the SSL context to the debug + * output. This function is always used through the + * MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file + * and line number parameters. + * + * \param ssl SSL context + * \param level error level of the debug message + * \param file file the error has occurred in + * \param line line number the error has occurred in + * \param ecdh the ECDH context + * \param attr the identifier of the attribute being output + * + * \attention This function is intended for INTERNAL usage within the + * library only. + */ +void mbedtls_debug_printf_ecdh( const mbedtls_ssl_context *ssl, int level, + const char *file, int line, + const mbedtls_ecdh_context *ecdh, + mbedtls_debug_ecdh_attr attr ); +#endif + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/des.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/des.h index 5a1a636522..54e6b7894b 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/des.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/des.h @@ -42,18 +42,20 @@ #define MBEDTLS_DES_DECRYPT 0 #define MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH -0x0032 /**< The data input has an invalid length. */ + +/* MBEDTLS_ERR_DES_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_DES_HW_ACCEL_FAILED -0x0033 /**< DES hardware accelerator failed. */ #define MBEDTLS_DES_KEY_SIZE 8 -#if !defined(MBEDTLS_DES_ALT) -// Regular implementation -// - #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_DES_ALT) +// Regular implementation +// + /** * \brief DES context structure * @@ -61,7 +63,7 @@ extern "C" { * security risk. We recommend considering stronger ciphers * instead. */ -typedef struct +typedef struct mbedtls_des_context { uint32_t sk[32]; /*!< DES subkeys */ } @@ -70,12 +72,16 @@ mbedtls_des_context; /** * \brief Triple-DES context structure */ -typedef struct +typedef struct mbedtls_des3_context { uint32_t sk[96]; /*!< 3DES subkeys */ } mbedtls_des3_context; +#else /* MBEDTLS_DES_ALT */ +#include "des_alt.h" +#endif /* MBEDTLS_DES_ALT */ + /** * \brief Initialize DES context * @@ -331,17 +337,8 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx, */ void mbedtls_des_setkey( uint32_t SK[32], const unsigned char key[MBEDTLS_DES_KEY_SIZE] ); -#ifdef __cplusplus -} -#endif - -#else /* MBEDTLS_DES_ALT */ -#include "des_alt.h" -#endif /* MBEDTLS_DES_ALT */ -#ifdef __cplusplus -extern "C" { -#endif +#if defined(MBEDTLS_SELF_TEST) /** * \brief Checkup routine @@ -350,6 +347,8 @@ extern "C" { */ int mbedtls_des_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/dhm.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/dhm.h index 00fafd8d16..2909f5fbc8 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/dhm.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/dhm.h @@ -1,7 +1,13 @@ /** * \file dhm.h * - * \brief Diffie-Hellman-Merkle key exchange. + * \brief This file contains Diffie-Hellman-Merkle (DHM) key exchange + * definitions and functions. + * + * Diffie-Hellman-Merkle (DHM) key exchange is defined in + * RFC-2631: Diffie-Hellman Key Agreement Method and + * Public-Key Cryptography Standards (PKCS) #3: Diffie + * Hellman Key Agreement Standard. * * RFC-3526: More Modular Exponential (MODP) Diffie-Hellman groups for * Internet Key Exchange (IKE) defines a number of standardized @@ -65,7 +71,6 @@ #include MBEDTLS_CONFIG_FILE #endif #include "bignum.h" -#if !defined(MBEDTLS_DHM_ALT) /* * DHM Error codes @@ -79,17 +84,22 @@ #define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380 /**< The ASN.1 data is not formatted correctly. */ #define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400 /**< Allocation of memory failed. */ #define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480 /**< Read or write of file failed. */ + +/* MBEDTLS_ERR_DHM_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_DHM_HW_ACCEL_FAILED -0x3500 /**< DHM hardware accelerator failed. */ + #define MBEDTLS_ERR_DHM_SET_GROUP_FAILED -0x3580 /**< Setting the modulus and generator failed. */ #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_DHM_ALT) + /** * \brief The DHM context structure. */ -typedef struct +typedef struct mbedtls_dhm_context { size_t len; /*!< The size of \p P in Bytes. */ mbedtls_mpi P; /*!< The prime modulus. */ @@ -105,6 +115,10 @@ typedef struct } mbedtls_dhm_context; +#else /* MBEDTLS_DHM_ALT */ +#include "dhm_alt.h" +#endif /* MBEDTLS_DHM_ALT */ + /** * \brief This function initializes the DHM context. * @@ -113,9 +127,15 @@ mbedtls_dhm_context; void mbedtls_dhm_init( mbedtls_dhm_context *ctx ); /** - * \brief This function parses the ServerKeyExchange parameters. + * \brief This function parses the DHM parameters in a + * TLS ServerKeyExchange handshake message + * (DHM modulus, generator, and public key). + * + * \note In a TLS handshake, this is the how the client + * sets up its DHM context from the server's public + * DHM key material. * - * \param ctx The DHM context. + * \param ctx The DHM context to use. This must be initialized. * \param p On input, *p must be the start of the input buffer. * On output, *p is updated to point to the end of the data * that has been read. On success, this is the first byte @@ -125,38 +145,44 @@ void mbedtls_dhm_init( mbedtls_dhm_context *ctx ); * failures. * \param end The end of the input buffer. * - * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code - * on failure. + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure. */ int mbedtls_dhm_read_params( mbedtls_dhm_context *ctx, - unsigned char **p, - const unsigned char *end ); + unsigned char **p, + const unsigned char *end ); /** - * \brief This function sets up and writes the ServerKeyExchange - * parameters. - * - * \param ctx The DHM context. - * \param x_size The private value size in Bytes. - * \param olen The number of characters written. - * \param output The destination buffer. - * \param f_rng The RNG function. - * \param p_rng The RNG parameter. - * - * \note The destination buffer must be large enough to hold - * the reduced binary presentation of the modulus, the generator - * and the public key, each wrapped with a 2-byte length field. - * It is the responsibility of the caller to ensure that enough - * space is available. Refer to \c mbedtls_mpi_size to computing - * the byte-size of an MPI. + * \brief This function generates a DHM key pair and exports its + * public part together with the DHM parameters in the format + * used in a TLS ServerKeyExchange handshake message. * - * \note This function assumes that \c ctx->P and \c ctx->G - * have already been properly set. For that, use + * \note This function assumes that the DHM parameters \c ctx->P + * and \c ctx->G have already been properly set. For that, use * mbedtls_dhm_set_group() below in conjunction with * mbedtls_mpi_read_binary() and mbedtls_mpi_read_string(). * - * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code - * on failure. + * \note In a TLS handshake, this is the how the server generates + * and exports its DHM key material. + * + * \param ctx The DHM context to use. This must be initialized + * and have the DHM parameters set. It may or may not + * already have imported the peer's public key. + * \param x_size The private key size in Bytes. + * \param olen The address at which to store the number of Bytes + * written on success. This must not be \c NULL. + * \param output The destination buffer. This must be a writable buffer of + * sufficient size to hold the reduced binary presentation of + * the modulus, the generator and the public key, each wrapped + * with a 2-byte length field. It is the responsibility of the + * caller to ensure that enough space is available. Refer to + * mbedtls_mpi_size() to computing the byte-size of an MPI. + * \param f_rng The RNG function. Must not be \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may be + * \c NULL if \p f_rng doesn't need a context parameter. + * + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure. */ int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size, unsigned char *output, size_t *olen, @@ -164,54 +190,66 @@ int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size, void *p_rng ); /** - * \brief Set prime modulus and generator + * \brief This function sets the prime modulus and generator. * - * \param ctx The DHM context. - * \param P The MPI holding DHM prime modulus. - * \param G The MPI holding DHM generator. + * \note This function can be used to set \c ctx->P, \c ctx->G + * in preparation for mbedtls_dhm_make_params(). * - * \note This function can be used to set P, G - * in preparation for \c mbedtls_dhm_make_params. + * \param ctx The DHM context to configure. This must be initialized. + * \param P The MPI holding the DHM prime modulus. This must be + * an initialized MPI. + * \param G The MPI holding the DHM generator. This must be an + * initialized MPI. * - * \return \c 0 if successful, or an \c MBEDTLS_ERR_DHM_XXX error code - * on failure. + * \return \c 0 if successful. + * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure. */ int mbedtls_dhm_set_group( mbedtls_dhm_context *ctx, const mbedtls_mpi *P, const mbedtls_mpi *G ); /** - * \brief This function imports the public value G^Y of the peer. + * \brief This function imports the raw public value of the peer. * - * \param ctx The DHM context. - * \param input The input buffer. - * \param ilen The size of the input buffer. + * \note In a TLS handshake, this is the how the server imports + * the Client's public DHM key. * - * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code - * on failure. + * \param ctx The DHM context to use. This must be initialized and have + * its DHM parameters set, e.g. via mbedtls_dhm_set_group(). + * It may or may not already have generated its own private key. + * \param input The input buffer containing the \c G^Y value of the peer. + * This must be a readable buffer of size \p ilen Bytes. + * \param ilen The size of the input buffer \p input in Bytes. + * + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure. */ int mbedtls_dhm_read_public( mbedtls_dhm_context *ctx, const unsigned char *input, size_t ilen ); /** - * \brief This function creates its own private value \c X and - * exports \c G^X. + * \brief This function creates a DHM key pair and exports + * the raw public key in big-endian format. * - * \param ctx The DHM context. - * \param x_size The private value size in Bytes. - * \param output The destination buffer. - * \param olen The length of the destination buffer. Must be at least - equal to ctx->len (the size of \c P). - * \param f_rng The RNG function. - * \param p_rng The RNG parameter. + * \note The destination buffer is always fully written + * so as to contain a big-endian representation of G^X mod P. + * If it is larger than \c ctx->len, it is padded accordingly + * with zero-bytes at the beginning. * - * \note The destination buffer will always be fully written - * so as to contain a big-endian presentation of G^X mod P. - * If it is larger than ctx->len, it will accordingly be - * padded with zero-bytes in the beginning. + * \param ctx The DHM context to use. This must be initialized and + * have the DHM parameters set. It may or may not already + * have imported the peer's public key. + * \param x_size The private key size in Bytes. + * \param output The destination buffer. This must be a writable buffer of + * size \p olen Bytes. + * \param olen The length of the destination buffer. This must be at least + * equal to `ctx->len` (the size of \c P). + * \param f_rng The RNG function. This must not be \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL + * if \p f_rng doesn't need a context argument. * - * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code - * on failure. + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure. */ int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size, unsigned char *output, size_t olen, @@ -219,25 +257,30 @@ int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size, void *p_rng ); /** - * \brief This function derives and exports the shared secret - * \c (G^Y)^X mod \c P. + * \brief This function derives and exports the shared secret + * \c (G^Y)^X mod \c P. * - * \param ctx The DHM context. - * \param output The destination buffer. - * \param output_size The size of the destination buffer. Must be at least - * the size of ctx->len. - * \param olen On exit, holds the actual number of Bytes written. - * \param f_rng The RNG function, for blinding purposes. - * \param p_rng The RNG parameter. + * \note If \p f_rng is not \c NULL, it is used to blind the input as + * a countermeasure against timing attacks. Blinding is used + * only if our private key \c X is re-used, and not used + * otherwise. We recommend always passing a non-NULL + * \p f_rng argument. * - * \return \c 0 on success, or an \c MBEDTLS_ERR_DHM_XXX error code - * on failure. + * \param ctx The DHM context to use. This must be initialized + * and have its own private key generated and the peer's + * public key imported. + * \param output The buffer to write the generated shared key to. This + * must be a writable buffer of size \p output_size Bytes. + * \param output_size The size of the destination buffer. This must be at + * least the size of \c ctx->len (the size of \c P). + * \param olen On exit, holds the actual number of Bytes written. + * \param f_rng The RNG function, for blinding purposes. This may + * b \c NULL if blinding isn't needed. + * \param p_rng The RNG context. This may be \c NULL if \p f_rng + * doesn't need a context argument. * - * \note If non-NULL, \p f_rng is used to blind the input as - * a countermeasure against timing attacks. Blinding is used - * only if our secret value \p X is re-used and omitted - * otherwise. Therefore, we recommend always passing a - * non-NULL \p f_rng argument. + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_DHM_XXX error code on failure. */ int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx, unsigned char *output, size_t output_size, size_t *olen, @@ -245,9 +288,12 @@ int mbedtls_dhm_calc_secret( mbedtls_dhm_context *ctx, void *p_rng ); /** - * \brief This function frees and clears the components of a DHM key. + * \brief This function frees and clears the components + * of a DHM context. * - * \param ctx The DHM context to free and clear. + * \param ctx The DHM context to free and clear. This may be \c NULL, + * in which case this function is a no-op. If it is not \c NULL, + * it must point to an initialized DHM context. */ void mbedtls_dhm_free( mbedtls_dhm_context *ctx ); @@ -256,16 +302,19 @@ void mbedtls_dhm_free( mbedtls_dhm_context *ctx ); /** * \brief This function parses DHM parameters in PEM or DER format. * - * \param dhm The DHM context to initialize. - * \param dhmin The input buffer. - * \param dhminlen The size of the buffer, including the terminating null - * Byte for PEM data. + * \param dhm The DHM context to import the DHM parameters into. + * This must be initialized. + * \param dhmin The input buffer. This must be a readable buffer of + * length \p dhminlen Bytes. + * \param dhminlen The size of the input buffer \p dhmin, including the + * terminating \c NULL Byte for PEM data. * - * \return \c 0 on success, or a specific DHM or PEM error code - * on failure. + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_DHM_XXX or \c MBEDTLS_ERR_PEM_XXX error + * code on failure. */ int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin, - size_t dhminlen ); + size_t dhminlen ); #if defined(MBEDTLS_FS_IO) /** \ingroup x509_module */ @@ -273,34 +322,29 @@ int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin, * \brief This function loads and parses DHM parameters from a file. * * \param dhm The DHM context to load the parameters to. + * This must be initialized. * \param path The filename to read the DHM parameters from. + * This must not be \c NULL. * - * \return \c 0 on success, or a specific DHM or PEM error code - * on failure. + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_DHM_XXX or \c MBEDTLS_ERR_PEM_XXX + * error code on failure. */ int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path ); #endif /* MBEDTLS_FS_IO */ #endif /* MBEDTLS_ASN1_PARSE_C */ -#ifdef __cplusplus -} -#endif - -#else /* MBEDTLS_DHM_ALT */ -#include "dhm_alt.h" -#endif /* MBEDTLS_DHM_ALT */ - -#ifdef __cplusplus -extern "C" { -#endif +#if defined(MBEDTLS_SELF_TEST) /** * \brief The DMH checkup routine. * - * \return \c 0 on success, or \c 1 on failure. + * \return \c 0 on success. + * \return \c 1 on failure. */ int mbedtls_dhm_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ #ifdef __cplusplus } #endif @@ -348,15 +392,6 @@ int mbedtls_dhm_self_test( int verbose ); #if !defined(MBEDTLS_DEPRECATED_REMOVED) -#if defined(MBEDTLS_DEPRECATED_WARNING) -#define MBEDTLS_DEPRECATED __attribute__((deprecated)) -MBEDTLS_DEPRECATED typedef char const * mbedtls_deprecated_constant_t; -#define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) \ - ( (mbedtls_deprecated_constant_t) ( VAL ) ) -#else -#define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) VAL -#endif /* ! MBEDTLS_DEPRECATED_WARNING */ - /** * \warning The origin of the primes in RFC 5114 is not documented and * their use therefore constitutes a security risk! diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdh.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdh.h index d16bad2d8e..4479a1d46f 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdh.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdh.h @@ -1,10 +1,11 @@ /** * \file ecdh.h * - * \brief The Elliptic Curve Diffie-Hellman (ECDH) protocol APIs. + * \brief This file contains ECDH definitions and functions. * - * ECDH is an anonymous key agreement protocol allowing two parties to - * establish a shared secret over an insecure channel. Each party must have an + * The Elliptic Curve Diffie-Hellman (ECDH) protocol is an anonymous + * key agreement protocol allowing two parties to establish a shared + * secret over an insecure channel. Each party must have an * elliptic-curve publicā€“private key pair. * * For more information, see NIST SP 800-56A Rev. 2: Recommendation for @@ -41,26 +42,74 @@ #include "ecp.h" +/* + * Use a backward compatible ECDH context. + * + * This flag is always enabled for now and future versions might add a + * configuration option that conditionally undefines this flag. + * The configuration option in question may have a different name. + * + * Features undefining this flag, must have a warning in their description in + * config.h stating that the feature breaks backward compatibility. + */ +#define MBEDTLS_ECDH_LEGACY_CONTEXT + #ifdef __cplusplus extern "C" { #endif /** - * Defines the source of the imported EC key: - *
  • Our key.
  • - *
  • The key of the peer.
+ * Defines the source of the imported EC key. */ typedef enum { - MBEDTLS_ECDH_OURS, - MBEDTLS_ECDH_THEIRS, + MBEDTLS_ECDH_OURS, /**< Our key. */ + MBEDTLS_ECDH_THEIRS, /**< The key of the peer. */ } mbedtls_ecdh_side; +#if !defined(MBEDTLS_ECDH_LEGACY_CONTEXT) +/** + * Defines the ECDH implementation used. + * + * Later versions of the library may add new variants, therefore users should + * not make any assumptions about them. + */ +typedef enum +{ + MBEDTLS_ECDH_VARIANT_NONE = 0, /*!< Implementation not defined. */ + MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,/*!< The default Mbed TLS implementation */ +} mbedtls_ecdh_variant; + +/** + * The context used by the default ECDH implementation. + * + * Later versions might change the structure of this context, therefore users + * should not make any assumptions about the structure of + * mbedtls_ecdh_context_mbed. + */ +typedef struct mbedtls_ecdh_context_mbed +{ + mbedtls_ecp_group grp; /*!< The elliptic curve used. */ + mbedtls_mpi d; /*!< The private key. */ + mbedtls_ecp_point Q; /*!< The public key. */ + mbedtls_ecp_point Qp; /*!< The value of the public key of the peer. */ + mbedtls_mpi z; /*!< The shared secret. */ +#if defined(MBEDTLS_ECP_RESTARTABLE) + mbedtls_ecp_restart_ctx rs; /*!< The restart context for EC computations. */ +#endif +} mbedtls_ecdh_context_mbed; +#endif + /** + * + * \warning Performing multiple operations concurrently on the same + * ECDSA context is not supported; objects of this type + * should not be shared between multiple threads. * \brief The ECDH context structure. */ -typedef struct +typedef struct mbedtls_ecdh_context { +#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) mbedtls_ecp_group grp; /*!< The elliptic curve used. */ mbedtls_mpi d; /*!< The private key. */ mbedtls_ecp_point Q; /*!< The public key. */ @@ -70,6 +119,29 @@ typedef struct mbedtls_ecp_point Vi; /*!< The blinding value. */ mbedtls_ecp_point Vf; /*!< The unblinding value. */ mbedtls_mpi _d; /*!< The previous \p d. */ +#if defined(MBEDTLS_ECP_RESTARTABLE) + int restart_enabled; /*!< The flag for restartable mode. */ + mbedtls_ecp_restart_ctx rs; /*!< The restart context for EC computations. */ +#endif /* MBEDTLS_ECP_RESTARTABLE */ +#else + uint8_t point_format; /*!< The format of point export in TLS messages + as defined in RFC 4492. */ + mbedtls_ecp_group_id grp_id;/*!< The elliptic curve used. */ + mbedtls_ecdh_variant var; /*!< The ECDH implementation/structure used. */ + union + { + mbedtls_ecdh_context_mbed mbed_ecdh; + } ctx; /*!< Implementation-specific context. The + context in use is specified by the \c var + field. */ +#if defined(MBEDTLS_ECP_RESTARTABLE) + uint8_t restart_enabled; /*!< The flag for restartable mode. Functions of + an alternative implementation not supporting + restartable mode must return + MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED error + if this flag is set. */ +#endif /* MBEDTLS_ECP_RESTARTABLE */ +#endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */ } mbedtls_ecdh_context; @@ -81,16 +153,22 @@ mbedtls_ecdh_context; * implemented during the ECDH key exchange. The second core * computation is performed by mbedtls_ecdh_compute_shared(). * - * \param grp The ECP group. + * \see ecp.h + * + * \param grp The ECP group to use. This must be initialized and have + * domain parameters loaded, for example through + * mbedtls_ecp_load() or mbedtls_ecp_tls_read_group(). * \param d The destination MPI (private key). + * This must be initialized. * \param Q The destination point (public key). - * \param f_rng The RNG function. - * \param p_rng The RNG parameter. + * This must be initialized. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may be + * \c NULL in case \p f_rng doesn't need a context argument. * - * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX or + * \return \c 0 on success. + * \return Another \c MBEDTLS_ERR_ECP_XXX or * \c MBEDTLS_MPI_XXX error code on failure. - * - * \see ecp.h */ int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q, int (*f_rng)(void *, unsigned char *, size_t), @@ -103,21 +181,32 @@ int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp * implemented during the ECDH key exchange. The first core * computation is performed by mbedtls_ecdh_gen_public(). * - * \param grp The ECP group. + * \see ecp.h + * + * \note If \p f_rng is not NULL, it is used to implement + * countermeasures against side-channel attacks. + * For more information, see mbedtls_ecp_mul(). + * + * \param grp The ECP group to use. This must be initialized and have + * domain parameters loaded, for example through + * mbedtls_ecp_load() or mbedtls_ecp_tls_read_group(). * \param z The destination MPI (shared secret). + * This must be initialized. * \param Q The public key from another party. + * This must be initialized. * \param d Our secret exponent (private key). - * \param f_rng The RNG function. - * \param p_rng The RNG parameter. - * - * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX or + * This must be initialized. + * \param f_rng The RNG function. This may be \c NULL if randomization + * of intermediate results during the ECP computations is + * not needed (discouraged). See the documentation of + * mbedtls_ecp_mul() for more. + * \param p_rng The RNG context to be passed to \p f_rng. This may be + * \c NULL if \p f_rng is \c NULL or doesn't need a + * context argument. + * + * \return \c 0 on success. + * \return Another \c MBEDTLS_ERR_ECP_XXX or * \c MBEDTLS_MPI_XXX error code on failure. - * - * \see ecp.h - * - * \note If \p f_rng is not NULL, it is used to implement - * countermeasures against potential elaborate timing - * attacks. For more information, see mbedtls_ecp_mul(). */ int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z, const mbedtls_ecp_point *Q, const mbedtls_mpi *d, @@ -127,39 +216,62 @@ int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z, /** * \brief This function initializes an ECDH context. * - * \param ctx The ECDH context to initialize. + * \param ctx The ECDH context to initialize. This must not be \c NULL. */ void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx ); /** - * \brief This function frees a context. + * \brief This function sets up the ECDH context with the information + * given. * - * \param ctx The context to free. - */ -void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx ); - -/** - * \brief This function generates a public key and a TLS - * ServerKeyExchange payload. + * This function should be called after mbedtls_ecdh_init() but + * before mbedtls_ecdh_make_params(). There is no need to call + * this function before mbedtls_ecdh_read_params(). * * This is the first function used by a TLS server for ECDHE * ciphersuites. * - * \param ctx The ECDH context. - * \param olen The number of characters written. - * \param buf The destination buffer. - * \param blen The length of the destination buffer. - * \param f_rng The RNG function. - * \param p_rng The RNG parameter. + * \param ctx The ECDH context to set up. This must be initialized. + * \param grp_id The group id of the group to set up the context for. * - * \note This function assumes that the ECP group (grp) of the - * \p ctx context has already been properly set, - * for example, using mbedtls_ecp_group_load(). + * \return \c 0 on success. + */ +int mbedtls_ecdh_setup( mbedtls_ecdh_context *ctx, + mbedtls_ecp_group_id grp_id ); + +/** + * \brief This function frees a context. * - * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code - * on failure. + * \param ctx The context to free. This may be \c NULL, in which + * case this function does nothing. If it is not \c NULL, + * it must point to an initialized ECDH context. + */ +void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx ); + +/** + * \brief This function generates an EC key pair and exports its + * in the format used in a TLS ServerKeyExchange handshake + * message. + * + * This is the second function used by a TLS server for ECDHE + * ciphersuites. (It is called after mbedtls_ecdh_setup().) * * \see ecp.h + * + * \param ctx The ECDH context to use. This must be initialized + * and bound to a group, for example via mbedtls_ecdh_setup(). + * \param olen The address at which to store the number of Bytes written. + * \param buf The destination buffer. This must be a writable buffer of + * length \p blen Bytes. + * \param blen The length of the destination buffer \p buf in Bytes. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may be + * \c NULL in case \p f_rng doesn't need a context argument. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of + * operations was reached: see \c mbedtls_ecp_set_max_ops(). + * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure. */ int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, @@ -167,23 +279,32 @@ int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen, void *p_rng ); /** - * \brief This function parses and processes a TLS ServerKeyExhange - * payload. + * \brief This function parses the ECDHE parameters in a + * TLS ServerKeyExchange handshake message. * - * This is the first function used by a TLS client for ECDHE - * ciphersuites. + * \note In a TLS handshake, this is the how the client + * sets up its ECDHE context from the server's public + * ECDHE key material. + * + * \see ecp.h * - * \param ctx The ECDH context. - * \param buf The pointer to the start of the input buffer. - * \param end The address for one Byte past the end of the buffer. + * \param ctx The ECDHE context to use. This must be initialized. + * \param buf On input, \c *buf must be the start of the input buffer. + * On output, \c *buf is updated to point to the end of the + * data that has been read. On success, this is the first byte + * past the end of the ServerKeyExchange parameters. + * On error, this is the point at which an error has been + * detected, which is usually not useful except to debug + * failures. + * \param end The end of the input buffer. * - * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code - * on failure. + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX error code on failure. * - * \see ecp.h */ int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx, - const unsigned char **buf, const unsigned char *end ); + const unsigned char **buf, + const unsigned char *end ); /** * \brief This function sets up an ECDH context from an EC key. @@ -192,38 +313,47 @@ int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx, * ServerKeyEchange for static ECDH, and imports ECDH * parameters from the EC key information of a certificate. * - * \param ctx The ECDH context to set up. - * \param key The EC key to use. - * \param side Defines the source of the key: - *
  • 1: Our key.
  • -
  • 0: The key of the peer.
+ * \see ecp.h * - * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code - * on failure. + * \param ctx The ECDH context to set up. This must be initialized. + * \param key The EC key to use. This must be initialized. + * \param side Defines the source of the key. Possible values are: + * - #MBEDTLS_ECDH_OURS: The key is ours. + * - #MBEDTLS_ECDH_THEIRS: The key is that of the peer. + * + * \return \c 0 on success. + * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure. * - * \see ecp.h */ -int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key, - mbedtls_ecdh_side side ); +int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, + const mbedtls_ecp_keypair *key, + mbedtls_ecdh_side side ); /** - * \brief This function generates a public key and a TLS - * ClientKeyExchange payload. + * \brief This function generates a public key and exports it + * as a TLS ClientKeyExchange payload. * * This is the second function used by a TLS client for ECDH(E) * ciphersuites. * - * \param ctx The ECDH context. - * \param olen The number of Bytes written. - * \param buf The destination buffer. - * \param blen The size of the destination buffer. - * \param f_rng The RNG function. - * \param p_rng The RNG parameter. - * - * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code - * on failure. - * * \see ecp.h + * + * \param ctx The ECDH context to use. This must be initialized + * and bound to a group, the latter usually by + * mbedtls_ecdh_read_params(). + * \param olen The address at which to store the number of Bytes written. + * This must not be \c NULL. + * \param buf The destination buffer. This must be a writable buffer + * of length \p blen Bytes. + * \param blen The size of the destination buffer \p buf in Bytes. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may be + * \c NULL in case \p f_rng doesn't need a context argument. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of + * operations was reached: see \c mbedtls_ecp_set_max_ops(). + * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure. */ int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, @@ -231,23 +361,26 @@ int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen, void *p_rng ); /** - * \brief This function parses and processes a TLS ClientKeyExchange - * payload. + * \brief This function parses and processes the ECDHE payload of a + * TLS ClientKeyExchange message. * - * This is the second function used by a TLS server for ECDH(E) - * ciphersuites. + * This is the third function used by a TLS server for ECDH(E) + * ciphersuites. (It is called after mbedtls_ecdh_setup() and + * mbedtls_ecdh_make_params().) * - * \param ctx The ECDH context. - * \param buf The start of the input buffer. - * \param blen The length of the input buffer. + * \see ecp.h * - * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code - * on failure. + * \param ctx The ECDH context to use. This must be initialized + * and bound to a group, for example via mbedtls_ecdh_setup(). + * \param buf The pointer to the ClientKeyExchange payload. This must + * be a readable buffer of length \p blen Bytes. + * \param blen The length of the input buffer \p buf in Bytes. * - * \see ecp.h + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX error code on failure. */ int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx, - const unsigned char *buf, size_t blen ); + const unsigned char *buf, size_t blen ); /** * \brief This function derives and exports the shared secret. @@ -255,27 +388,51 @@ int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx, * This is the last function used by both TLS client * and servers. * - * \param ctx The ECDH context. - * \param olen The number of Bytes written. - * \param buf The destination buffer. - * \param blen The length of the destination buffer. - * \param f_rng The RNG function. - * \param p_rng The RNG parameter. - * - * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX error code - * on failure. + * \note If \p f_rng is not NULL, it is used to implement + * countermeasures against side-channel attacks. + * For more information, see mbedtls_ecp_mul(). * * \see ecp.h - * - * \note If \p f_rng is not NULL, it is used to implement - * countermeasures against potential elaborate timing - * attacks. For more information, see mbedtls_ecp_mul(). + + * \param ctx The ECDH context to use. This must be initialized + * and have its own private key generated and the peer's + * public key imported. + * \param olen The address at which to store the total number of + * Bytes written on success. This must not be \c NULL. + * \param buf The buffer to write the generated shared key to. This + * must be a writable buffer of size \p blen Bytes. + * \param blen The length of the destination buffer \p buf in Bytes. + * \param f_rng The RNG function, for blinding purposes. This may + * b \c NULL if blinding isn't needed. + * \param p_rng The RNG context. This may be \c NULL if \p f_rng + * doesn't need a context argument. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of + * operations was reached: see \c mbedtls_ecp_set_max_ops(). + * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure. */ int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); +#if defined(MBEDTLS_ECP_RESTARTABLE) +/** + * \brief This function enables restartable EC computations for this + * context. (Default: disabled.) + * + * \see \c mbedtls_ecp_set_max_ops() + * + * \note It is not possible to safely disable restartable + * computations once enabled, except by free-ing the context, + * which cancels possible in-progress operations. + * + * \param ctx The ECDH context to use. This must be initialized. + */ +void mbedtls_ecdh_enable_restart( mbedtls_ecdh_context *ctx ); +#endif /* MBEDTLS_ECP_RESTARTABLE */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdsa.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdsa.h index cfd1370120..f8b28507c2 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdsa.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecdsa.h @@ -1,9 +1,10 @@ /** * \file ecdsa.h * - * \brief The Elliptic Curve Digital Signature Algorithm (ECDSA). + * \brief This file contains ECDSA definitions and functions. * - * ECDSA is defined in Standards for Efficient Cryptography Group (SECG): + * The Elliptic Curve Digital Signature Algorithm (ECDSA) is defined in + * Standards for Efficient Cryptography Group (SECG): * SEC1 Elliptic Curve Cryptography. * The use of ECDSA for TLS is defined in RFC-4492: Elliptic Curve * Cryptography (ECC) Cipher Suites for Transport Layer Security (TLS). @@ -60,29 +61,71 @@ /** The maximal size of an ECDSA signature in Bytes. */ #define MBEDTLS_ECDSA_MAX_LEN ( 3 + 2 * ( 3 + MBEDTLS_ECP_MAX_BYTES ) ) +#ifdef __cplusplus +extern "C" { +#endif + /** * \brief The ECDSA context structure. + * + * \warning Performing multiple operations concurrently on the same + * ECDSA context is not supported; objects of this type + * should not be shared between multiple threads. */ typedef mbedtls_ecp_keypair mbedtls_ecdsa_context; -#ifdef __cplusplus -extern "C" { +#if defined(MBEDTLS_ECP_RESTARTABLE) + +/** + * \brief Internal restart context for ecdsa_verify() + * + * \note Opaque struct, defined in ecdsa.c + */ +typedef struct mbedtls_ecdsa_restart_ver mbedtls_ecdsa_restart_ver_ctx; + +/** + * \brief Internal restart context for ecdsa_sign() + * + * \note Opaque struct, defined in ecdsa.c + */ +typedef struct mbedtls_ecdsa_restart_sig mbedtls_ecdsa_restart_sig_ctx; + +#if defined(MBEDTLS_ECDSA_DETERMINISTIC) +/** + * \brief Internal restart context for ecdsa_sign_det() + * + * \note Opaque struct, defined in ecdsa.c + */ +typedef struct mbedtls_ecdsa_restart_det mbedtls_ecdsa_restart_det_ctx; #endif +/** + * \brief General context for resuming ECDSA operations + */ +typedef struct +{ + mbedtls_ecp_restart_ctx ecp; /*!< base context for ECP restart and + shared administrative info */ + mbedtls_ecdsa_restart_ver_ctx *ver; /*!< ecdsa_verify() sub-context */ + mbedtls_ecdsa_restart_sig_ctx *sig; /*!< ecdsa_sign() sub-context */ +#if defined(MBEDTLS_ECDSA_DETERMINISTIC) + mbedtls_ecdsa_restart_det_ctx *det; /*!< ecdsa_sign_det() sub-context */ +#endif +} mbedtls_ecdsa_restart_ctx; + +#else /* MBEDTLS_ECP_RESTARTABLE */ + +/* Now we can declare functions that take a pointer to that */ +typedef void mbedtls_ecdsa_restart_ctx; + +#endif /* MBEDTLS_ECP_RESTARTABLE */ + /** * \brief This function computes the ECDSA signature of a * previously-hashed message. * - * \note The deterministic version is usually preferred. - * - * \param grp The ECP group. - * \param r The first output integer. - * \param s The second output integer. - * \param d The private signing key. - * \param buf The message hash. - * \param blen The length of \p buf. - * \param f_rng The RNG function. - * \param p_rng The RNG parameter. + * \note The deterministic version implemented in + * mbedtls_ecdsa_sign_det() is usually preferred. * * \note If the bitlength of the message hash is larger than the * bitlength of the group order, then the hash is truncated @@ -90,10 +133,28 @@ extern "C" { * (SECG): SEC1 Elliptic Curve Cryptography, section * 4.1.3, step 5. * - * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX - * or \c MBEDTLS_MPI_XXX error code on failure. - * * \see ecp.h + * + * \param grp The context for the elliptic curve to use. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param r The MPI context in which to store the first part + * the signature. This must be initialized. + * \param s The MPI context in which to store the second part + * the signature. This must be initialized. + * \param d The private signing key. This must be initialized. + * \param buf The content to be signed. This is usually the hash of + * the original data to be signed. This must be a readable + * buffer of length \p blen Bytes. It may be \c NULL if + * \p blen is zero. + * \param blen The length of \p buf in Bytes. + * \param f_rng The RNG function. This must not be \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may be + * \c NULL if \p f_rng doesn't need a context parameter. + * + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX + * or \c MBEDTLS_MPI_XXX error code on failure. */ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, const mbedtls_mpi *d, const unsigned char *buf, size_t blen, @@ -103,62 +164,80 @@ int mbedtls_ecdsa_sign( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, /** * \brief This function computes the ECDSA signature of a * previously-hashed message, deterministic version. + * * For more information, see RFC-6979: Deterministic * Usage of the Digital Signature Algorithm (DSA) and Elliptic * Curve Digital Signature Algorithm (ECDSA). * - * \param grp The ECP group. - * \param r The first output integer. - * \param s The second output integer. - * \param d The private signing key. - * \param buf The message hash. - * \param blen The length of \p buf. - * \param md_alg The MD algorithm used to hash the message. - * * \note If the bitlength of the message hash is larger than the * bitlength of the group order, then the hash is truncated as * defined in Standards for Efficient Cryptography Group * (SECG): SEC1 Elliptic Curve Cryptography, section * 4.1.3, step 5. * - * \return \c 0 on success, - * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX - * error code on failure. - * * \see ecp.h + * + * \param grp The context for the elliptic curve to use. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param r The MPI context in which to store the first part + * the signature. This must be initialized. + * \param s The MPI context in which to store the second part + * the signature. This must be initialized. + * \param d The private signing key. This must be initialized + * and setup, for example through mbedtls_ecp_gen_privkey(). + * \param buf The hashed content to be signed. This must be a readable + * buffer of length \p blen Bytes. It may be \c NULL if + * \p blen is zero. + * \param blen The length of \p buf in Bytes. + * \param md_alg The hash algorithm used to hash the original data. + * + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX + * error code on failure. */ -int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, mbedtls_mpi *s, - const mbedtls_mpi *d, const unsigned char *buf, size_t blen, - mbedtls_md_type_t md_alg ); +int mbedtls_ecdsa_sign_det( mbedtls_ecp_group *grp, mbedtls_mpi *r, + mbedtls_mpi *s, const mbedtls_mpi *d, + const unsigned char *buf, size_t blen, + mbedtls_md_type_t md_alg ); #endif /* MBEDTLS_ECDSA_DETERMINISTIC */ /** * \brief This function verifies the ECDSA signature of a * previously-hashed message. * - * \param grp The ECP group. - * \param buf The message hash. - * \param blen The length of \p buf. - * \param Q The public key to use for verification. - * \param r The first integer of the signature. - * \param s The second integer of the signature. - * * \note If the bitlength of the message hash is larger than the * bitlength of the group order, then the hash is truncated as * defined in Standards for Efficient Cryptography Group * (SECG): SEC1 Elliptic Curve Cryptography, section * 4.1.4, step 3. * - * \return \c 0 on success, - * #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid, - * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX - * error code on failure for any other reason. - * * \see ecp.h + * + * \param grp The ECP group to use. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param buf The hashed content that was signed. This must be a readable + * buffer of length \p blen Bytes. It may be \c NULL if + * \p blen is zero. + * \param blen The length of \p buf in Bytes. + * \param Q The public key to use for verification. This must be + * initialized and setup. + * \param r The first integer of the signature. + * This must be initialized. + * \param s The second integer of the signature. + * This must be initialized. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the signature + * is invalid. + * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX + * error code on failure for any other reason. */ int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp, - const unsigned char *buf, size_t blen, - const mbedtls_ecp_point *Q, const mbedtls_mpi *r, const mbedtls_mpi *s); + const unsigned char *buf, size_t blen, + const mbedtls_ecp_point *Q, const mbedtls_mpi *r, + const mbedtls_mpi *s); /** * \brief This function computes the ECDSA signature and writes it @@ -175,38 +254,92 @@ int mbedtls_ecdsa_verify( mbedtls_ecp_group *grp, * of the Digital Signature Algorithm (DSA) and Elliptic * Curve Digital Signature Algorithm (ECDSA)
. * - * \param ctx The ECDSA context. - * \param md_alg The message digest that was used to hash the message. - * \param hash The message hash. - * \param hlen The length of the hash. - * \param sig The buffer that holds the signature. - * \param slen The length of the signature written. - * \param f_rng The RNG function. - * \param p_rng The RNG parameter. - * - * \note The \p sig buffer must be at least twice as large as the - * size of the curve used, plus 9. For example, 73 Bytes if - * a 256-bit curve is used. A buffer length of - * #MBEDTLS_ECDSA_MAX_LEN is always safe. - * * \note If the bitlength of the message hash is larger than the * bitlength of the group order, then the hash is truncated as * defined in Standards for Efficient Cryptography Group * (SECG): SEC1 Elliptic Curve Cryptography, section * 4.1.3, step 5. * - * \return \c 0 on success, - * or an \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or - * \c MBEDTLS_ERR_ASN1_XXX error code on failure. - * * \see ecp.h + * + * \param ctx The ECDSA context to use. This must be initialized + * and have a group and private key bound to it, for example + * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair(). + * \param md_alg The message digest that was used to hash the message. + * \param hash The message hash to be signed. This must be a readable + * buffer of length \p blen Bytes. + * \param hlen The length of the hash \p hash in Bytes. + * \param sig The buffer to which to write the signature. This must be a + * writable buffer of length at least twice as large as the + * size of the curve used, plus 9. For example, 73 Bytes if + * a 256-bit curve is used. A buffer length of + * #MBEDTLS_ECDSA_MAX_LEN is always safe. + * \param slen The address at which to store the actual length of + * the signature written. Must not be \c NULL. + * \param f_rng The RNG function. This must not be \c NULL if + * #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise, + * it is unused and may be set to \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may be + * \c NULL if \p f_rng is \c NULL or doesn't use a context. + * + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or + * \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ -int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t md_alg, +int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, + mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hlen, unsigned char *sig, size_t *slen, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); +/** + * \brief This function computes the ECDSA signature and writes it + * to a buffer, in a restartable way. + * + * \see \c mbedtls_ecdsa_write_signature() + * + * \note This function is like \c mbedtls_ecdsa_write_signature() + * but it can return early and restart according to the limit + * set with \c mbedtls_ecp_set_max_ops() to reduce blocking. + * + * \param ctx The ECDSA context to use. This must be initialized + * and have a group and private key bound to it, for example + * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair(). + * \param md_alg The message digest that was used to hash the message. + * \param hash The message hash to be signed. This must be a readable + * buffer of length \p blen Bytes. + * \param hlen The length of the hash \p hash in Bytes. + * \param sig The buffer to which to write the signature. This must be a + * writable buffer of length at least twice as large as the + * size of the curve used, plus 9. For example, 73 Bytes if + * a 256-bit curve is used. A buffer length of + * #MBEDTLS_ECDSA_MAX_LEN is always safe. + * \param slen The address at which to store the actual length of + * the signature written. Must not be \c NULL. + * \param f_rng The RNG function. This must not be \c NULL if + * #MBEDTLS_ECDSA_DETERMINISTIC is unset. Otherwise, + * it is unused and may be set to \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may be + * \c NULL if \p f_rng is \c NULL or doesn't use a context. + * \param rs_ctx The restart context to use. This may be \c NULL to disable + * restarting. If it is not \c NULL, it must point to an + * initialized restart context. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of + * operations was reached: see \c mbedtls_ecp_set_max_ops(). + * \return Another \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or + * \c MBEDTLS_ERR_ASN1_XXX error code on failure. + */ +int mbedtls_ecdsa_write_signature_restartable( mbedtls_ecdsa_context *ctx, + mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hlen, + unsigned char *sig, size_t *slen, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + mbedtls_ecdsa_restart_ctx *rs_ctx ); + #if defined(MBEDTLS_ECDSA_DETERMINISTIC) #if ! defined(MBEDTLS_DEPRECATED_REMOVED) #if defined(MBEDTLS_DEPRECATED_WARNING) @@ -215,31 +348,17 @@ int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t #define MBEDTLS_DEPRECATED #endif /** - * \brief This function computes an ECDSA signature and writes it to a buffer, - * serialized as defined in RFC-4492: Elliptic Curve Cryptography - * (ECC) Cipher Suites for Transport Layer Security (TLS). + * \brief This function computes an ECDSA signature and writes + * it to a buffer, serialized as defined in RFC-4492: + * Elliptic Curve Cryptography (ECC) Cipher Suites for + * Transport Layer Security (TLS). * - * The deterministic version is defined in RFC-6979: - * Deterministic Usage of the Digital Signature Algorithm (DSA) and - * Elliptic Curve Digital Signature Algorithm (ECDSA). + * The deterministic version is defined in RFC-6979: + * Deterministic Usage of the Digital Signature Algorithm (DSA) + * and Elliptic Curve Digital Signature Algorithm (ECDSA). * * \warning It is not thread-safe to use the same context in * multiple threads. - - * - * \deprecated Superseded by mbedtls_ecdsa_write_signature() in 2.0.0 - * - * \param ctx The ECDSA context. - * \param hash The Message hash. - * \param hlen The length of the hash. - * \param sig The buffer that holds the signature. - * \param slen The length of the signature written. - * \param md_alg The MD algorithm used to hash the message. - * - * \note The \p sig buffer must be at least twice as large as the - * size of the curve used, plus 9. For example, 73 Bytes if a - * 256-bit curve is used. A buffer length of - * #MBEDTLS_ECDSA_MAX_LEN is always safe. * * \note If the bitlength of the message hash is larger than the * bitlength of the group order, then the hash is truncated as @@ -247,11 +366,29 @@ int mbedtls_ecdsa_write_signature( mbedtls_ecdsa_context *ctx, mbedtls_md_type_t * (SECG): SEC1 Elliptic Curve Cryptography, section * 4.1.3, step 5. * - * \return \c 0 on success, - * or an \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or - * \c MBEDTLS_ERR_ASN1_XXX error code on failure. - * * \see ecp.h + * + * \deprecated Superseded by mbedtls_ecdsa_write_signature() in + * Mbed TLS version 2.0 and later. + * + * \param ctx The ECDSA context to use. This must be initialized + * and have a group and private key bound to it, for example + * via mbedtls_ecdsa_genkey() or mbedtls_ecdsa_from_keypair(). + * \param hash The message hash to be signed. This must be a readable + * buffer of length \p blen Bytes. + * \param hlen The length of the hash \p hash in Bytes. + * \param sig The buffer to which to write the signature. This must be a + * writable buffer of length at least twice as large as the + * size of the curve used, plus 9. For example, 73 Bytes if + * a 256-bit curve is used. A buffer length of + * #MBEDTLS_ECDSA_MAX_LEN is always safe. + * \param slen The address at which to store the actual length of + * the signature written. Must not be \c NULL. + * \param md_alg The message digest that was used to hash the message. + * + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX, \c MBEDTLS_ERR_MPI_XXX or + * \c MBEDTLS_ERR_ASN1_XXX error code on failure. */ int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx, const unsigned char *hash, size_t hlen, @@ -264,75 +401,143 @@ int mbedtls_ecdsa_write_signature_det( mbedtls_ecdsa_context *ctx, /** * \brief This function reads and verifies an ECDSA signature. * - * \param ctx The ECDSA context. - * \param hash The message hash. - * \param hlen The size of the hash. - * \param sig The signature to read and verify. - * \param slen The size of \p sig. - * * \note If the bitlength of the message hash is larger than the * bitlength of the group order, then the hash is truncated as * defined in Standards for Efficient Cryptography Group * (SECG): SEC1 Elliptic Curve Cryptography, section * 4.1.4, step 3. * - * \return \c 0 on success, - * #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid, - * #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if there is a valid - * signature in sig but its length is less than \p siglen, - * or an \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX - * error code on failure for any other reason. - * * \see ecp.h + * + * \param ctx The ECDSA context to use. This must be initialized + * and have a group and public key bound to it. + * \param hash The message hash that was signed. This must be a readable + * buffer of length \p size Bytes. + * \param hlen The size of the hash \p hash. + * \param sig The signature to read and verify. This must be a readable + * buffer of length \p slen Bytes. + * \param slen The size of \p sig in Bytes. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid. + * \return #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if there is a valid + * signature in \p sig, but its length is less than \p siglen. + * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX + * error code on failure for any other reason. */ int mbedtls_ecdsa_read_signature( mbedtls_ecdsa_context *ctx, const unsigned char *hash, size_t hlen, const unsigned char *sig, size_t slen ); +/** + * \brief This function reads and verifies an ECDSA signature, + * in a restartable way. + * + * \see \c mbedtls_ecdsa_read_signature() + * + * \note This function is like \c mbedtls_ecdsa_read_signature() + * but it can return early and restart according to the limit + * set with \c mbedtls_ecp_set_max_ops() to reduce blocking. + * + * \param ctx The ECDSA context to use. This must be initialized + * and have a group and public key bound to it. + * \param hash The message hash that was signed. This must be a readable + * buffer of length \p size Bytes. + * \param hlen The size of the hash \p hash. + * \param sig The signature to read and verify. This must be a readable + * buffer of length \p slen Bytes. + * \param slen The size of \p sig in Bytes. + * \param rs_ctx The restart context to use. This may be \c NULL to disable + * restarting. If it is not \c NULL, it must point to an + * initialized restart context. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if signature is invalid. + * \return #MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH if there is a valid + * signature in \p sig, but its length is less than \p siglen. + * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of + * operations was reached: see \c mbedtls_ecp_set_max_ops(). + * \return Another \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_ERR_MPI_XXX + * error code on failure for any other reason. + */ +int mbedtls_ecdsa_read_signature_restartable( mbedtls_ecdsa_context *ctx, + const unsigned char *hash, size_t hlen, + const unsigned char *sig, size_t slen, + mbedtls_ecdsa_restart_ctx *rs_ctx ); + /** * \brief This function generates an ECDSA keypair on the given curve. * + * \see ecp.h + * * \param ctx The ECDSA context to store the keypair in. + * This must be initialized. * \param gid The elliptic curve to use. One of the various * \c MBEDTLS_ECP_DP_XXX macros depending on configuration. - * \param f_rng The RNG function. - * \param p_rng The RNG parameter. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may be + * \c NULL if \p f_rng doesn't need a context argument. * - * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX code on - * failure. - * - * \see ecp.h + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX code on failure. */ int mbedtls_ecdsa_genkey( mbedtls_ecdsa_context *ctx, mbedtls_ecp_group_id gid, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); /** - * \brief This function sets an ECDSA context from an EC key pair. + * \brief This function sets up an ECDSA context from an EC key pair. * - * \param ctx The ECDSA context to set. - * \param key The EC key to use. + * \see ecp.h * - * \return \c 0 on success, or an \c MBEDTLS_ERR_ECP_XXX code on - * failure. + * \param ctx The ECDSA context to setup. This must be initialized. + * \param key The EC key to use. This must be initialized and hold + * a private-public key pair or a public key. In the former + * case, the ECDSA context may be used for signature creation + * and verification after this call. In the latter case, it + * may be used for signature verification. * - * \see ecp.h + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX code on failure. */ -int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, const mbedtls_ecp_keypair *key ); +int mbedtls_ecdsa_from_keypair( mbedtls_ecdsa_context *ctx, + const mbedtls_ecp_keypair *key ); /** * \brief This function initializes an ECDSA context. * * \param ctx The ECDSA context to initialize. + * This must not be \c NULL. */ void mbedtls_ecdsa_init( mbedtls_ecdsa_context *ctx ); /** * \brief This function frees an ECDSA context. * - * \param ctx The ECDSA context to free. + * \param ctx The ECDSA context to free. This may be \c NULL, + * in which case this function does nothing. If it + * is not \c NULL, it must be initialized. */ void mbedtls_ecdsa_free( mbedtls_ecdsa_context *ctx ); +#if defined(MBEDTLS_ECP_RESTARTABLE) +/** + * \brief Initialize a restart context. + * + * \param ctx The restart context to initialize. + * This must not be \c NULL. + */ +void mbedtls_ecdsa_restart_init( mbedtls_ecdsa_restart_ctx *ctx ); + +/** + * \brief Free the components of a restart context. + * + * \param ctx The restart context to free. This may be \c NULL, + * in which case this function does nothing. If it + * is not \c NULL, it must be initialized. + */ +void mbedtls_ecdsa_restart_free( mbedtls_ecdsa_restart_ctx *ctx ); +#endif /* MBEDTLS_ECP_RESTARTABLE */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecjpake.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecjpake.h index 8d09bf2293..3d8d02ae64 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecjpake.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecjpake.h @@ -49,8 +49,6 @@ #include "ecp.h" #include "md.h" -#if !defined(MBEDTLS_ECJPAKE_ALT) - #ifdef __cplusplus extern "C" { #endif @@ -63,6 +61,7 @@ typedef enum { MBEDTLS_ECJPAKE_SERVER, /**< Server */ } mbedtls_ecjpake_role; +#if !defined(MBEDTLS_ECJPAKE_ALT) /** * EC J-PAKE context structure. * @@ -74,7 +73,7 @@ typedef enum { * convetion from the Thread v1.0 spec. Correspondance is indicated in the * description as a pair C: client name, S: server name */ -typedef struct +typedef struct mbedtls_ecjpake_context { const mbedtls_md_info_t *md_info; /**< Hash to use */ mbedtls_ecp_group grp; /**< Elliptic curve */ @@ -93,29 +92,38 @@ typedef struct mbedtls_mpi s; /**< Pre-shared secret (passphrase) */ } mbedtls_ecjpake_context; +#else /* MBEDTLS_ECJPAKE_ALT */ +#include "ecjpake_alt.h" +#endif /* MBEDTLS_ECJPAKE_ALT */ + /** - * \brief Initialize a context - * (just makes it ready for setup() or free()). + * \brief Initialize an ECJPAKE context. * - * \param ctx context to initialize + * \param ctx The ECJPAKE context to initialize. + * This must not be \c NULL. */ void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx ); /** - * \brief Set up a context for use + * \brief Set up an ECJPAKE context for use. * * \note Currently the only values for hash/curve allowed by the - * standard are MBEDTLS_MD_SHA256/MBEDTLS_ECP_DP_SECP256R1. + * standard are #MBEDTLS_MD_SHA256/#MBEDTLS_ECP_DP_SECP256R1. * - * \param ctx context to set up - * \param role Our role: client or server - * \param hash hash function to use (MBEDTLS_MD_XXX) - * \param curve elliptic curve identifier (MBEDTLS_ECP_DP_XXX) - * \param secret pre-shared secret (passphrase) - * \param len length of the shared secret + * \param ctx The ECJPAKE context to set up. This must be initialized. + * \param role The role of the caller. This must be either + * #MBEDTLS_ECJPAKE_CLIENT or #MBEDTLS_ECJPAKE_SERVER. + * \param hash The identifier of the hash function to use, + * for example #MBEDTLS_MD_SHA256. + * \param curve The identifier of the elliptic curve to use, + * for example #MBEDTLS_ECP_DP_SECP256R1. + * \param secret The pre-shared secret (passphrase). This must be + * a readable buffer of length \p len Bytes. It need + * only be valid for the duration of this call. + * \param len The length of the pre-shared secret \p secret. * - * \return 0 if successfull, - * a negative error code otherwise + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx, mbedtls_ecjpake_role role, @@ -125,29 +133,34 @@ int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx, size_t len ); /** - * \brief Check if a context is ready for use + * \brief Check if an ECJPAKE context is ready for use. * - * \param ctx Context to check + * \param ctx The ECJPAKE context to check. This must be + * initialized. * - * \return 0 if the context is ready for use, - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise + * \return \c 0 if the context is ready for use. + * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise. */ int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx ); /** * \brief Generate and write the first round message * (TLS: contents of the Client/ServerHello extension, - * excluding extension type and length bytes) + * excluding extension type and length bytes). * - * \param ctx Context to use - * \param buf Buffer to write the contents to - * \param len Buffer size - * \param olen Will be updated with the number of bytes written - * \param f_rng RNG function - * \param p_rng RNG parameter + * \param ctx The ECJPAKE context to use. This must be + * initialized and set up. + * \param buf The buffer to write the contents to. This must be a + * writable buffer of length \p len Bytes. + * \param len The length of \p buf in Bytes. + * \param olen The address at which to store the total number + * of Bytes written to \p buf. This must not be \c NULL. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG parameter to be passed to \p f_rng. This + * may be \c NULL if \p f_rng doesn't use a context. * - * \return 0 if successfull, - * a negative error code otherwise + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_ecjpake_write_round_one( mbedtls_ecjpake_context *ctx, unsigned char *buf, size_t len, size_t *olen, @@ -157,14 +170,16 @@ int mbedtls_ecjpake_write_round_one( mbedtls_ecjpake_context *ctx, /** * \brief Read and process the first round message * (TLS: contents of the Client/ServerHello extension, - * excluding extension type and length bytes) + * excluding extension type and length bytes). * - * \param ctx Context to use - * \param buf Pointer to extension contents - * \param len Extension length + * \param ctx The ECJPAKE context to use. This must be initialized + * and set up. + * \param buf The buffer holding the first round message. This must + * be a readable buffer of length \p len Bytes. + * \param len The length in Bytes of \p buf. * - * \return 0 if successfull, - * a negative error code otherwise + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_ecjpake_read_round_one( mbedtls_ecjpake_context *ctx, const unsigned char *buf, @@ -172,17 +187,21 @@ int mbedtls_ecjpake_read_round_one( mbedtls_ecjpake_context *ctx, /** * \brief Generate and write the second round message - * (TLS: contents of the Client/ServerKeyExchange) + * (TLS: contents of the Client/ServerKeyExchange). * - * \param ctx Context to use - * \param buf Buffer to write the contents to - * \param len Buffer size - * \param olen Will be updated with the number of bytes written - * \param f_rng RNG function - * \param p_rng RNG parameter + * \param ctx The ECJPAKE context to use. This must be initialized, + * set up, and already have performed round one. + * \param buf The buffer to write the round two contents to. + * This must be a writable buffer of length \p len Bytes. + * \param len The size of \p buf in Bytes. + * \param olen The address at which to store the total number of Bytes + * written to \p buf. This must not be \c NULL. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG parameter to be passed to \p f_rng. This + * may be \c NULL if \p f_rng doesn't use a context. * - * \return 0 if successfull, - * a negative error code otherwise + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_ecjpake_write_round_two( mbedtls_ecjpake_context *ctx, unsigned char *buf, size_t len, size_t *olen, @@ -191,14 +210,16 @@ int mbedtls_ecjpake_write_round_two( mbedtls_ecjpake_context *ctx, /** * \brief Read and process the second round message - * (TLS: contents of the Client/ServerKeyExchange) + * (TLS: contents of the Client/ServerKeyExchange). * - * \param ctx Context to use - * \param buf Pointer to the message - * \param len Message length + * \param ctx The ECJPAKE context to use. This must be initialized + * and set up and already have performed round one. + * \param buf The buffer holding the second round message. This must + * be a readable buffer of length \p len Bytes. + * \param len The length in Bytes of \p buf. * - * \return 0 if successfull, - * a negative error code otherwise + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_ecjpake_read_round_two( mbedtls_ecjpake_context *ctx, const unsigned char *buf, @@ -206,17 +227,21 @@ int mbedtls_ecjpake_read_round_two( mbedtls_ecjpake_context *ctx, /** * \brief Derive the shared secret - * (TLS: Pre-Master Secret) + * (TLS: Pre-Master Secret). * - * \param ctx Context to use - * \param buf Buffer to write the contents to - * \param len Buffer size - * \param olen Will be updated with the number of bytes written - * \param f_rng RNG function - * \param p_rng RNG parameter + * \param ctx The ECJPAKE context to use. This must be initialized, + * set up and have performed both round one and two. + * \param buf The buffer to write the derived secret to. This must + * be a writable buffer of length \p len Bytes. + * \param len The length of \p buf in Bytes. + * \param olen The address at which to store the total number of Bytes + * written to \p buf. This must not be \c NULL. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG parameter to be passed to \p f_rng. This + * may be \c NULL if \p f_rng doesn't use a context. * - * \return 0 if successfull, - * a negative error code otherwise + * \return \c 0 if successful. + * \return A negative error code on failure. */ int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx, unsigned char *buf, size_t len, size_t *olen, @@ -224,26 +249,17 @@ int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx, void *p_rng ); /** - * \brief Free a context's content + * \brief This clears an ECJPAKE context and frees any + * embedded data structure. * - * \param ctx context to free + * \param ctx The ECJPAKE context to free. This may be \c NULL, + * in which case this function does nothing. If it is not + * \c NULL, it must point to an initialized ECJPAKE context. */ void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx ); -#ifdef __cplusplus -} -#endif - -#else /* MBEDTLS_ECJPAKE_ALT */ -#include "ecjpake_alt.h" -#endif /* MBEDTLS_ECJPAKE_ALT */ - #if defined(MBEDTLS_SELF_TEST) -#ifdef __cplusplus -extern "C" { -#endif - /** * \brief Checkup routine * @@ -251,10 +267,11 @@ extern "C" { */ int mbedtls_ecjpake_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif -#endif /* MBEDTLS_SELF_TEST */ #endif /* ecjpake.h */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp.h index 6c43c00693..065a4cc0b9 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ecp.h @@ -1,10 +1,21 @@ /** * \file ecp.h * - * \brief Elliptic curves over GF(p) + * \brief This file provides an API for Elliptic Curves over GF(P) (ECP). + * + * The use of ECP in cryptography and TLS is defined in + * Standards for Efficient Cryptography Group (SECG): SEC1 + * Elliptic Curve Cryptography and + * RFC-4492: Elliptic Curve Cryptography (ECC) Cipher Suites + * for Transport Layer Security (TLS). + * + * RFC-2409: The Internet Key Exchange (IKE) defines ECP + * group types. + * */ + /* - * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -19,8 +30,9 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * This file is part of mbed TLS (https://tls.mbed.org) + * This file is part of Mbed TLS (https://tls.mbed.org) */ + #ifndef MBEDTLS_ECP_H #define MBEDTLS_ECP_H @@ -37,160 +49,165 @@ */ #define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80 /**< Bad input parameters to function. */ #define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 /**< The buffer is too small to write to. */ -#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 /**< Requested curve not available. */ +#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 /**< The requested feature is not available, for example, the requested curve is not supported. */ #define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00 /**< The signature is not valid. */ #define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80 /**< Memory allocation failed. */ -#define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 /**< Generation of random value, such as (ephemeral) key, failed. */ +#define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 /**< Generation of random value, such as ephemeral key, failed. */ #define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80 /**< Invalid private or public key. */ #define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 /**< The buffer contains a valid signature followed by more data. */ -#define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80 /**< ECP hardware accelerator failed. */ -#if !defined(MBEDTLS_ECP_ALT) -/* - * default mbed TLS elliptic curve arithmetic implementation - * - * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an - * alternative implementation for the whole module and it will replace this - * one.) - */ +/* MBEDTLS_ERR_ECP_HW_ACCEL_FAILED is deprecated and should not be used. */ +#define MBEDTLS_ERR_ECP_HW_ACCEL_FAILED -0x4B80 /**< The ECP hardware accelerator failed. */ + +#define MBEDTLS_ERR_ECP_IN_PROGRESS -0x4B00 /**< Operation in progress, call again with the same parameters to continue. */ #ifdef __cplusplus extern "C" { #endif /** - * Domain parameters (curve, subgroup and generator) identifiers. + * Domain-parameter identifiers: curve, subgroup, and generator. * - * Only curves over prime fields are supported. + * \note Only curves over prime fields are supported. * * \warning This library does not support validation of arbitrary domain - * parameters. Therefore, only well-known domain parameters from trusted + * parameters. Therefore, only standardized domain parameters from trusted * sources should be used. See mbedtls_ecp_group_load(). */ typedef enum { - MBEDTLS_ECP_DP_NONE = 0, - MBEDTLS_ECP_DP_SECP192R1, /*!< 192-bits NIST curve */ - MBEDTLS_ECP_DP_SECP224R1, /*!< 224-bits NIST curve */ - MBEDTLS_ECP_DP_SECP256R1, /*!< 256-bits NIST curve */ - MBEDTLS_ECP_DP_SECP384R1, /*!< 384-bits NIST curve */ - MBEDTLS_ECP_DP_SECP521R1, /*!< 521-bits NIST curve */ - MBEDTLS_ECP_DP_BP256R1, /*!< 256-bits Brainpool curve */ - MBEDTLS_ECP_DP_BP384R1, /*!< 384-bits Brainpool curve */ - MBEDTLS_ECP_DP_BP512R1, /*!< 512-bits Brainpool curve */ - MBEDTLS_ECP_DP_CURVE25519, /*!< Curve25519 */ - MBEDTLS_ECP_DP_SECP192K1, /*!< 192-bits "Koblitz" curve */ - MBEDTLS_ECP_DP_SECP224K1, /*!< 224-bits "Koblitz" curve */ - MBEDTLS_ECP_DP_SECP256K1, /*!< 256-bits "Koblitz" curve */ + MBEDTLS_ECP_DP_NONE = 0, /*!< Curve not defined. */ + MBEDTLS_ECP_DP_SECP192R1, /*!< Domain parameters for the 192-bit curve defined by FIPS 186-4 and SEC1. */ + MBEDTLS_ECP_DP_SECP224R1, /*!< Domain parameters for the 224-bit curve defined by FIPS 186-4 and SEC1. */ + MBEDTLS_ECP_DP_SECP256R1, /*!< Domain parameters for the 256-bit curve defined by FIPS 186-4 and SEC1. */ + MBEDTLS_ECP_DP_SECP384R1, /*!< Domain parameters for the 384-bit curve defined by FIPS 186-4 and SEC1. */ + MBEDTLS_ECP_DP_SECP521R1, /*!< Domain parameters for the 521-bit curve defined by FIPS 186-4 and SEC1. */ + MBEDTLS_ECP_DP_BP256R1, /*!< Domain parameters for 256-bit Brainpool curve. */ + MBEDTLS_ECP_DP_BP384R1, /*!< Domain parameters for 384-bit Brainpool curve. */ + MBEDTLS_ECP_DP_BP512R1, /*!< Domain parameters for 512-bit Brainpool curve. */ + MBEDTLS_ECP_DP_CURVE25519, /*!< Domain parameters for Curve25519. */ + MBEDTLS_ECP_DP_SECP192K1, /*!< Domain parameters for 192-bit "Koblitz" curve. */ + MBEDTLS_ECP_DP_SECP224K1, /*!< Domain parameters for 224-bit "Koblitz" curve. */ + MBEDTLS_ECP_DP_SECP256K1, /*!< Domain parameters for 256-bit "Koblitz" curve. */ + MBEDTLS_ECP_DP_CURVE448, /*!< Domain parameters for Curve448. */ } mbedtls_ecp_group_id; /** - * Number of supported curves (plus one for NONE). + * The number of supported curves, plus one for #MBEDTLS_ECP_DP_NONE. * - * (Montgomery curves excluded for now.) + * \note Montgomery curves are currently excluded. */ #define MBEDTLS_ECP_DP_MAX 12 /** - * Curve information for use by other modules + * Curve information, for use by other modules. */ -typedef struct +typedef struct mbedtls_ecp_curve_info { - mbedtls_ecp_group_id grp_id; /*!< Internal identifier */ - uint16_t tls_id; /*!< TLS NamedCurve identifier */ - uint16_t bit_size; /*!< Curve size in bits */ - const char *name; /*!< Human-friendly name */ + mbedtls_ecp_group_id grp_id; /*!< An internal identifier. */ + uint16_t tls_id; /*!< The TLS NamedCurve identifier. */ + uint16_t bit_size; /*!< The curve size in bits. */ + const char *name; /*!< A human-friendly name. */ } mbedtls_ecp_curve_info; /** - * \brief ECP point structure (jacobian coordinates) + * \brief The ECP point structure, in Jacobian coordinates. * * \note All functions expect and return points satisfying - * the following condition: Z == 0 or Z == 1. (Other - * values of Z are used by internal functions only.) - * The point is zero, or "at infinity", if Z == 0. - * Otherwise, X and Y are its standard (affine) coordinates. + * the following condition: Z == 0 or + * Z == 1. Other values of \p Z are + * used only by internal functions. + * The point is zero, or "at infinity", if Z == 0. + * Otherwise, \p X and \p Y are its standard (affine) + * coordinates. */ -typedef struct +typedef struct mbedtls_ecp_point { - mbedtls_mpi X; /*!< the point's X coordinate */ - mbedtls_mpi Y; /*!< the point's Y coordinate */ - mbedtls_mpi Z; /*!< the point's Z coordinate */ + mbedtls_mpi X; /*!< The X coordinate of the ECP point. */ + mbedtls_mpi Y; /*!< The Y coordinate of the ECP point. */ + mbedtls_mpi Z; /*!< The Z coordinate of the ECP point. */ } mbedtls_ecp_point; -/** - * \brief ECP group structure - * - * We consider two types of curves equations: - * 1. Short Weierstrass y^2 = x^3 + A x + B mod P (SEC1 + RFC 4492) - * 2. Montgomery, y^2 = x^3 + A x^2 + x mod P (Curve25519 + draft) - * In both cases, a generator G for a prime-order subgroup is fixed. In the - * short weierstrass, this subgroup is actually the whole curve, and its - * cardinal is denoted by N. - * - * In the case of Short Weierstrass curves, our code requires that N is an odd - * prime. (Use odd in mbedtls_ecp_mul() and prime in mbedtls_ecdsa_sign() for blinding.) - * - * In the case of Montgomery curves, we don't store A but (A + 2) / 4 which is - * the quantity actually used in the formulas. Also, nbits is not the size of N - * but the required size for private keys. +#if !defined(MBEDTLS_ECP_ALT) +/* + * default mbed TLS elliptic curve arithmetic implementation * - * If modp is NULL, reduction modulo P is done using a generic algorithm. - * Otherwise, it must point to a function that takes an mbedtls_mpi in the range - * 0..2^(2*pbits)-1 and transforms it in-place in an integer of little more - * than pbits, so that the integer may be efficiently brought in the 0..P-1 - * range by a few additions or substractions. It must return 0 on success and - * non-zero on failure. + * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an + * alternative implementation for the whole module and it will replace this + * one.) */ -typedef struct -{ - mbedtls_ecp_group_id id; /*!< internal group identifier */ - mbedtls_mpi P; /*!< prime modulus of the base field */ - mbedtls_mpi A; /*!< 1. A in the equation, or 2. (A + 2) / 4 */ - mbedtls_mpi B; /*!< 1. B in the equation, or 2. unused */ - mbedtls_ecp_point G; /*!< generator of the (sub)group used */ - mbedtls_mpi N; /*!< 1. the order of G, or 2. unused */ - size_t pbits; /*!< number of bits in P */ - size_t nbits; /*!< number of bits in 1. P, or 2. private keys */ - unsigned int h; /*!< internal: 1 if the constants are static */ - int (*modp)(mbedtls_mpi *); /*!< function for fast reduction mod P */ - int (*t_pre)(mbedtls_ecp_point *, void *); /*!< unused */ - int (*t_post)(mbedtls_ecp_point *, void *); /*!< unused */ - void *t_data; /*!< unused */ - mbedtls_ecp_point *T; /*!< pre-computed points for ecp_mul_comb() */ - size_t T_size; /*!< number for pre-computed points */ -} -mbedtls_ecp_group; /** - * \brief ECP key pair structure + * \brief The ECP group structure. + * + * We consider two types of curve equations: + *
  • Short Weierstrass: y^2 = x^3 + A x + B mod P + * (SEC1 + RFC-4492)
  • + *
  • Montgomery: y^2 = x^3 + A x^2 + x mod P (Curve25519, + * Curve448)
+ * In both cases, the generator (\p G) for a prime-order subgroup is fixed. + * + * For Short Weierstrass, this subgroup is the whole curve, and its + * cardinality is denoted by \p N. Our code requires that \p N is an + * odd prime as mbedtls_ecp_mul() requires an odd number, and + * mbedtls_ecdsa_sign() requires that it is prime for blinding purposes. + * + * For Montgomery curves, we do not store \p A, but (A + 2) / 4, + * which is the quantity used in the formulas. Additionally, \p nbits is + * not the size of \p N but the required size for private keys. + * + * If \p modp is NULL, reduction modulo \p P is done using a generic algorithm. + * Otherwise, \p modp must point to a function that takes an \p mbedtls_mpi in the + * range of 0..2^(2*pbits)-1, and transforms it in-place to an integer + * which is congruent mod \p P to the given MPI, and is close enough to \p pbits + * in size, so that it may be efficiently brought in the 0..P-1 range by a few + * additions or subtractions. Therefore, it is only an approximative modular + * reduction. It must return 0 on success and non-zero on failure. + * + * \note Alternative implementations must keep the group IDs distinct. If + * two group structures have the same ID, then they must be + * identical. * - * A generic key pair that could be used for ECDSA, fixed ECDH, etc. - * - * \note Members purposefully in the same order as struc mbedtls_ecdsa_context. */ -typedef struct +typedef struct mbedtls_ecp_group { - mbedtls_ecp_group grp; /*!< Elliptic curve and base point */ - mbedtls_mpi d; /*!< our secret value */ - mbedtls_ecp_point Q; /*!< our public value */ + mbedtls_ecp_group_id id; /*!< An internal group identifier. */ + mbedtls_mpi P; /*!< The prime modulus of the base field. */ + mbedtls_mpi A; /*!< For Short Weierstrass: \p A in the equation. For + Montgomery curves: (A + 2) / 4. */ + mbedtls_mpi B; /*!< For Short Weierstrass: \p B in the equation. + For Montgomery curves: unused. */ + mbedtls_ecp_point G; /*!< The generator of the subgroup used. */ + mbedtls_mpi N; /*!< The order of \p G. */ + size_t pbits; /*!< The number of bits in \p P.*/ + size_t nbits; /*!< For Short Weierstrass: The number of bits in \p P. + For Montgomery curves: the number of bits in the + private keys. */ + unsigned int h; /*!< \internal 1 if the constants are static. */ + int (*modp)(mbedtls_mpi *); /*!< The function for fast pseudo-reduction + mod \p P (see above).*/ + int (*t_pre)(mbedtls_ecp_point *, void *); /*!< Unused. */ + int (*t_post)(mbedtls_ecp_point *, void *); /*!< Unused. */ + void *t_data; /*!< Unused. */ + mbedtls_ecp_point *T; /*!< Pre-computed points for ecp_mul_comb(). */ + size_t T_size; /*!< The number of pre-computed points. */ } -mbedtls_ecp_keypair; +mbedtls_ecp_group; /** * \name SECTION: Module settings * * The configuration options you can set for this module are in this section. - * Either change them in config.h or define them on the compiler command line. + * Either change them in config.h, or define them using the compiler command line. * \{ */ #if !defined(MBEDTLS_ECP_MAX_BITS) /** - * Maximum size of the groups (that is, of N and P) + * The maximum size of the groups, that is, of \c N and \c P. */ -#define MBEDTLS_ECP_MAX_BITS 521 /**< Maximum bit size of groups */ +#define MBEDTLS_ECP_MAX_BITS 521 /**< The maximum size of groups, in bits. */ #endif #define MBEDTLS_ECP_MAX_BYTES ( ( MBEDTLS_ECP_MAX_BITS + 7 ) / 8 ) @@ -213,11 +230,10 @@ mbedtls_ecp_keypair; * 521 145 141 135 120 97 * 384 214 209 198 177 146 * 256 320 320 303 262 226 - * 224 475 475 453 398 342 * 192 640 640 633 587 476 */ -#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< Maximum window size used */ +#define MBEDTLS_ECP_WINDOW_SIZE 6 /**< The maximum window size used. */ #endif /* MBEDTLS_ECP_WINDOW_SIZE */ #if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM) @@ -232,33 +248,188 @@ mbedtls_ecp_keypair; * * Change this value to 0 to reduce peak memory usage. */ -#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up */ +#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up. */ #endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */ /* \} name SECTION: Module settings */ +#else /* MBEDTLS_ECP_ALT */ +#include "ecp_alt.h" +#endif /* MBEDTLS_ECP_ALT */ + +#if defined(MBEDTLS_ECP_RESTARTABLE) + +/** + * \brief Internal restart context for multiplication + * + * \note Opaque struct + */ +typedef struct mbedtls_ecp_restart_mul mbedtls_ecp_restart_mul_ctx; + +/** + * \brief Internal restart context for ecp_muladd() + * + * \note Opaque struct + */ +typedef struct mbedtls_ecp_restart_muladd mbedtls_ecp_restart_muladd_ctx; + +/** + * \brief General context for resuming ECC operations + */ +typedef struct +{ + unsigned ops_done; /*!< current ops count */ + unsigned depth; /*!< call depth (0 = top-level) */ + mbedtls_ecp_restart_mul_ctx *rsm; /*!< ecp_mul_comb() sub-context */ + mbedtls_ecp_restart_muladd_ctx *ma; /*!< ecp_muladd() sub-context */ +} mbedtls_ecp_restart_ctx; + +/* + * Operation counts for restartable functions + */ +#define MBEDTLS_ECP_OPS_CHK 3 /*!< basic ops count for ecp_check_pubkey() */ +#define MBEDTLS_ECP_OPS_DBL 8 /*!< basic ops count for ecp_double_jac() */ +#define MBEDTLS_ECP_OPS_ADD 11 /*!< basic ops count for see ecp_add_mixed() */ +#define MBEDTLS_ECP_OPS_INV 120 /*!< empirical equivalent for mpi_mod_inv() */ + +/** + * \brief Internal; for restartable functions in other modules. + * Check and update basic ops budget. + * + * \param grp Group structure + * \param rs_ctx Restart context + * \param ops Number of basic ops to do + * + * \return \c 0 if doing \p ops basic ops is still allowed, + * \return #MBEDTLS_ERR_ECP_IN_PROGRESS otherwise. + */ +int mbedtls_ecp_check_budget( const mbedtls_ecp_group *grp, + mbedtls_ecp_restart_ctx *rs_ctx, + unsigned ops ); + +/* Utility macro for checking and updating ops budget */ +#define MBEDTLS_ECP_BUDGET( ops ) \ + MBEDTLS_MPI_CHK( mbedtls_ecp_check_budget( grp, rs_ctx, \ + (unsigned) (ops) ) ); + +#else /* MBEDTLS_ECP_RESTARTABLE */ + +#define MBEDTLS_ECP_BUDGET( ops ) /* no-op; for compatibility */ + +/* We want to declare restartable versions of existing functions anyway */ +typedef void mbedtls_ecp_restart_ctx; + +#endif /* MBEDTLS_ECP_RESTARTABLE */ + +/** + * \brief The ECP key-pair structure. + * + * A generic key-pair that may be used for ECDSA and fixed ECDH, for example. + * + * \note Members are deliberately in the same order as in the + * ::mbedtls_ecdsa_context structure. + */ +typedef struct mbedtls_ecp_keypair +{ + mbedtls_ecp_group grp; /*!< Elliptic curve and base point */ + mbedtls_mpi d; /*!< our secret value */ + mbedtls_ecp_point Q; /*!< our public value */ +} +mbedtls_ecp_keypair; + /* * Point formats, from RFC 4492's enum ECPointFormat */ -#define MBEDTLS_ECP_PF_UNCOMPRESSED 0 /**< Uncompressed point format */ -#define MBEDTLS_ECP_PF_COMPRESSED 1 /**< Compressed point format */ +#define MBEDTLS_ECP_PF_UNCOMPRESSED 0 /**< Uncompressed point format. */ +#define MBEDTLS_ECP_PF_COMPRESSED 1 /**< Compressed point format. */ /* * Some other constants from RFC 4492 */ -#define MBEDTLS_ECP_TLS_NAMED_CURVE 3 /**< ECCurveType's named_curve */ +#define MBEDTLS_ECP_TLS_NAMED_CURVE 3 /**< The named_curve of ECCurveType. */ + +#if defined(MBEDTLS_ECP_RESTARTABLE) +/** + * \brief Set the maximum number of basic operations done in a row. + * + * If more operations are needed to complete a computation, + * #MBEDTLS_ERR_ECP_IN_PROGRESS will be returned by the + * function performing the computation. It is then the + * caller's responsibility to either call again with the same + * parameters until it returns 0 or an error code; or to free + * the restart context if the operation is to be aborted. + * + * It is strictly required that all input parameters and the + * restart context be the same on successive calls for the + * same operation, but output parameters need not be the + * same; they must not be used until the function finally + * returns 0. + * + * This only applies to functions whose documentation + * mentions they may return #MBEDTLS_ERR_ECP_IN_PROGRESS (or + * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS for functions in the + * SSL module). For functions that accept a "restart context" + * argument, passing NULL disables restart and makes the + * function equivalent to the function with the same name + * with \c _restartable removed. For functions in the ECDH + * module, restart is disabled unless the function accepts + * an "ECDH context" argument and + * mbedtls_ecdh_enable_restart() was previously called on + * that context. For function in the SSL module, restart is + * only enabled for specific sides and key exchanges + * (currently only for clients and ECDHE-ECDSA). + * + * \param max_ops Maximum number of basic operations done in a row. + * Default: 0 (unlimited). + * Lower (non-zero) values mean ECC functions will block for + * a lesser maximum amount of time. + * + * \note A "basic operation" is defined as a rough equivalent of a + * multiplication in GF(p) for the NIST P-256 curve. + * As an indication, with default settings, a scalar + * multiplication (full run of \c mbedtls_ecp_mul()) is: + * - about 3300 basic operations for P-256 + * - about 9400 basic operations for P-384 + * + * \note Very low values are not always respected: sometimes + * functions need to block for a minimum number of + * operations, and will do so even if max_ops is set to a + * lower value. That minimum depends on the curve size, and + * can be made lower by decreasing the value of + * \c MBEDTLS_ECP_WINDOW_SIZE. As an indication, here is the + * lowest effective value for various curves and values of + * that parameter (w for short): + * w=6 w=5 w=4 w=3 w=2 + * P-256 208 208 160 136 124 + * P-384 682 416 320 272 248 + * P-521 1364 832 640 544 496 + * + * \note This setting is currently ignored by Curve25519. + */ +void mbedtls_ecp_set_max_ops( unsigned max_ops ); /** - * \brief Get the list of supported curves in order of preferrence - * (full information) + * \brief Check if restart is enabled (max_ops != 0) * - * \return A statically allocated array, the last entry is 0. + * \return \c 0 if \c max_ops == 0 (restart disabled) + * \return \c 1 otherwise (restart enabled) + */ +int mbedtls_ecp_restart_is_enabled( void ); +#endif /* MBEDTLS_ECP_RESTARTABLE */ + +/** + * \brief This function retrieves the information defined in + * mbedtls_ecp_curve_info() for all supported curves in order + * of preference. + * + * \return A statically allocated array. The last entry is 0. */ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void ); /** - * \brief Get the list of supported curves in order of preferrence - * (grp_id only) + * \brief This function retrieves the list of internal group + * identifiers of all supported curves in the order of + * preference. * * \return A statically allocated array, * terminated with MBEDTLS_ECP_DP_NONE. @@ -266,416 +437,689 @@ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list( void ); const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list( void ); /** - * \brief Get curve information from an internal group identifier + * \brief This function retrieves curve information from an internal + * group identifier. * - * \param grp_id A MBEDTLS_ECP_DP_XXX value + * \param grp_id An \c MBEDTLS_ECP_DP_XXX value. * - * \return The associated curve information or NULL + * \return The associated curve information on success. + * \return NULL on failure. */ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id( mbedtls_ecp_group_id grp_id ); /** - * \brief Get curve information from a TLS NamedCurve value + * \brief This function retrieves curve information from a TLS + * NamedCurve value. * - * \param tls_id A MBEDTLS_ECP_DP_XXX value + * \param tls_id An \c MBEDTLS_ECP_DP_XXX value. * - * \return The associated curve information or NULL + * \return The associated curve information on success. + * \return NULL on failure. */ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id( uint16_t tls_id ); /** - * \brief Get curve information from a human-readable name + * \brief This function retrieves curve information from a + * human-readable name. * - * \param name The name + * \param name The human-readable name. * - * \return The associated curve information or NULL + * \return The associated curve information on success. + * \return NULL on failure. */ const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name( const char *name ); /** - * \brief Initialize a point (as zero) + * \brief This function initializes a point as zero. + * + * \param pt The point to initialize. */ void mbedtls_ecp_point_init( mbedtls_ecp_point *pt ); /** - * \brief Initialize a group (to something meaningless) + * \brief This function initializes an ECP group context + * without loading any domain parameters. + * + * \note After this function is called, domain parameters + * for various ECP groups can be loaded through the + * mbedtls_ecp_group_load() or mbedtls_ecp_tls_read_group() + * functions. */ void mbedtls_ecp_group_init( mbedtls_ecp_group *grp ); /** - * \brief Initialize a key pair (as an invalid one) + * \brief This function initializes a key pair as an invalid one. + * + * \param key The key pair to initialize. */ void mbedtls_ecp_keypair_init( mbedtls_ecp_keypair *key ); /** - * \brief Free the components of a point + * \brief This function frees the components of a point. + * + * \param pt The point to free. */ void mbedtls_ecp_point_free( mbedtls_ecp_point *pt ); /** - * \brief Free the components of an ECP group + * \brief This function frees the components of an ECP group. + * + * \param grp The group to free. This may be \c NULL, in which + * case this function returns immediately. If it is not + * \c NULL, it must point to an initialized ECP group. */ void mbedtls_ecp_group_free( mbedtls_ecp_group *grp ); /** - * \brief Free the components of a key pair + * \brief This function frees the components of a key pair. + * + * \param key The key pair to free. This may be \c NULL, in which + * case this function returns immediately. If it is not + * \c NULL, it must point to an initialized ECP key pair. */ void mbedtls_ecp_keypair_free( mbedtls_ecp_keypair *key ); +#if defined(MBEDTLS_ECP_RESTARTABLE) /** - * \brief Copy the contents of point Q into P + * \brief Initialize a restart context. * - * \param P Destination point - * \param Q Source point + * \param ctx The restart context to initialize. This must + * not be \c NULL. + */ +void mbedtls_ecp_restart_init( mbedtls_ecp_restart_ctx *ctx ); + +/** + * \brief Free the components of a restart context. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \param ctx The restart context to free. This may be \c NULL, in which + * case this function returns immediately. If it is not + * \c NULL, it must point to an initialized restart context. + */ +void mbedtls_ecp_restart_free( mbedtls_ecp_restart_ctx *ctx ); +#endif /* MBEDTLS_ECP_RESTARTABLE */ + +/** + * \brief This function copies the contents of point \p Q into + * point \p P. + * + * \param P The destination point. This must be initialized. + * \param Q The source point. This must be initialized. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. + * \return Another negative error code for other kinds of failure. */ int mbedtls_ecp_copy( mbedtls_ecp_point *P, const mbedtls_ecp_point *Q ); /** - * \brief Copy the contents of a group object + * \brief This function copies the contents of group \p src into + * group \p dst. * - * \param dst Destination group - * \param src Source group + * \param dst The destination group. This must be initialized. + * \param src The source group. This must be initialized. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. + * \return Another negative error code on other kinds of failure. */ -int mbedtls_ecp_group_copy( mbedtls_ecp_group *dst, const mbedtls_ecp_group *src ); +int mbedtls_ecp_group_copy( mbedtls_ecp_group *dst, + const mbedtls_ecp_group *src ); /** - * \brief Set a point to zero + * \brief This function sets a point to the point at infinity. * - * \param pt Destination point + * \param pt The point to set. This must be initialized. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. + * \return Another negative error code on other kinds of failure. */ int mbedtls_ecp_set_zero( mbedtls_ecp_point *pt ); /** - * \brief Tell if a point is zero + * \brief This function checks if a point is the point at infinity. * - * \param pt Point to test + * \param pt The point to test. This must be initialized. * - * \return 1 if point is zero, 0 otherwise + * \return \c 1 if the point is zero. + * \return \c 0 if the point is non-zero. + * \return A negative error code on failure. */ int mbedtls_ecp_is_zero( mbedtls_ecp_point *pt ); /** - * \brief Compare two points + * \brief This function compares two points. * - * \note This assumes the points are normalized. Otherwise, + * \note This assumes that the points are normalized. Otherwise, * they may compare as "not equal" even if they are. * - * \param P First point to compare - * \param Q Second point to compare + * \param P The first point to compare. This must be initialized. + * \param Q The second point to compare. This must be initialized. * - * \return 0 if the points are equal, - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise + * \return \c 0 if the points are equal. + * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the points are not equal. */ int mbedtls_ecp_point_cmp( const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q ); /** - * \brief Import a non-zero point from two ASCII strings + * \brief This function imports a non-zero point from two ASCII + * strings. * - * \param P Destination point - * \param radix Input numeric base - * \param x First affine coordinate as a null-terminated string - * \param y Second affine coordinate as a null-terminated string + * \param P The destination point. This must be initialized. + * \param radix The numeric base of the input. + * \param x The first affine coordinate, as a null-terminated string. + * \param y The second affine coordinate, as a null-terminated string. * - * \return 0 if successful, or a MBEDTLS_ERR_MPI_XXX error code + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_MPI_XXX error code on failure. */ int mbedtls_ecp_point_read_string( mbedtls_ecp_point *P, int radix, const char *x, const char *y ); /** - * \brief Export a point into unsigned binary data - * - * \param grp Group to which the point should belong - * \param P Point to export - * \param format Point format, should be a MBEDTLS_ECP_PF_XXX macro - * \param olen Length of the actual output - * \param buf Output buffer - * \param buflen Length of the output buffer - * - * \return 0 if successful, - * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA - * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL + * \brief This function exports a point into unsigned binary data. + * + * \param grp The group to which the point should belong. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param P The point to export. This must be initialized. + * \param format The point format. This must be either + * #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED. + * \param olen The address at which to store the length of + * the output in Bytes. This must not be \c NULL. + * \param buf The output buffer. This must be a writable buffer + * of length \p buflen Bytes. + * \param buflen The length of the output buffer \p buf in Bytes. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output buffer + * is too small to hold the point. + * \return Another negative error code on other kinds of failure. */ int mbedtls_ecp_point_write_binary( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *P, int format, size_t *olen, unsigned char *buf, size_t buflen ); /** - * \brief Import a point from unsigned binary data - * - * \param grp Group to which the point should belong - * \param P Point to import - * \param buf Input buffer - * \param ilen Actual length of input - * - * \return 0 if successful, - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed, - * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format + * \brief This function imports a point from unsigned binary data. + * + * \note This function does not check that the point actually + * belongs to the given group, see mbedtls_ecp_check_pubkey() + * for that. + * + * \param grp The group to which the point should belong. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param P The destination context to import the point to. + * This must be initialized. + * \param buf The input buffer. This must be a readable buffer + * of length \p ilen Bytes. + * \param ilen The length of the input buffer \p buf in Bytes. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the input is invalid. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. + * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format * is not implemented. - * - * \note This function does NOT check that the point actually - * belongs to the given group, see mbedtls_ecp_check_pubkey() for - * that. */ -int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P, - const unsigned char *buf, size_t ilen ); +int mbedtls_ecp_point_read_binary( const mbedtls_ecp_group *grp, + mbedtls_ecp_point *P, + const unsigned char *buf, size_t ilen ); /** - * \brief Import a point from a TLS ECPoint record - * - * \param grp ECP group used - * \param pt Destination point - * \param buf $(Start of input buffer) - * \param len Buffer length - * - * \note buf is updated to point right after the ECPoint on exit - * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_XXX if initialization failed - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid + * \brief This function imports a point from a TLS ECPoint record. + * + * \note On function return, \p *buf is updated to point immediately + * after the ECPoint record. + * + * \param grp The ECP group to use. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param pt The destination point. + * \param buf The address of the pointer to the start of the input buffer. + * \param len The length of the buffer. + * + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_MPI_XXX error code on initialization + * failure. + * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid. */ -int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt, - const unsigned char **buf, size_t len ); +int mbedtls_ecp_tls_read_point( const mbedtls_ecp_group *grp, + mbedtls_ecp_point *pt, + const unsigned char **buf, size_t len ); /** - * \brief Export a point as a TLS ECPoint record - * - * \param grp ECP group used - * \param pt Point to export - * \param format Export format - * \param olen length of data written - * \param buf Buffer to write to - * \param blen Buffer length - * - * \return 0 if successful, - * or MBEDTLS_ERR_ECP_BAD_INPUT_DATA - * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL + * \brief This function exports a point as a TLS ECPoint record + * defined in RFC 4492, Section 5.4. + * + * \param grp The ECP group to use. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param pt The point to be exported. This must be initialized. + * \param format The point format to use. This must be either + * #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED. + * \param olen The address at which to store the length in Bytes + * of the data written. + * \param buf The target buffer. This must be a writable buffer of + * length \p blen Bytes. + * \param blen The length of the target buffer \p buf in Bytes. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the input is invalid. + * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the target buffer + * is too small to hold the exported point. + * \return Another negative error code on other kinds of failure. */ -int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt, - int format, size_t *olen, - unsigned char *buf, size_t blen ); +int mbedtls_ecp_tls_write_point( const mbedtls_ecp_group *grp, + const mbedtls_ecp_point *pt, + int format, size_t *olen, + unsigned char *buf, size_t blen ); /** - * \brief Set a group using well-known domain parameters + * \brief This function sets up an ECP group context + * from a standardized set of domain parameters. * - * \param grp Destination group - * \param id Index in the list of well-known domain parameters + * \note The index should be a value of the NamedCurve enum, + * as defined in RFC-4492: Elliptic Curve Cryptography + * (ECC) Cipher Suites for Transport Layer Security (TLS), + * usually in the form of an \c MBEDTLS_ECP_DP_XXX macro. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_XXX if initialization failed - * MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE for unkownn groups + * \param grp The group context to setup. This must be initialized. + * \param id The identifier of the domain parameter set to load. * - * \note Index should be a value of RFC 4492's enum NamedCurve, - * usually in the form of a MBEDTLS_ECP_DP_XXX macro. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p id doesn't + * correspond to a known group. + * \return Another negative error code on other kinds of failure. */ int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id ); /** - * \brief Set a group from a TLS ECParameters record + * \brief This function sets up an ECP group context from a TLS + * ECParameters record as defined in RFC 4492, Section 5.4. * - * \param grp Destination group - * \param buf &(Start of input buffer) - * \param len Buffer length + * \note The read pointer \p buf is updated to point right after + * the ECParameters record on exit. * - * \note buf is updated to point right after ECParameters on exit + * \param grp The group context to setup. This must be initialized. + * \param buf The address of the pointer to the start of the input buffer. + * \param len The length of the input buffer \c *buf in Bytes. * - * \return 0 if successful, - * MBEDTLS_ERR_MPI_XXX if initialization failed - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid. + * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the group is not + * recognized. + * \return Another negative error code on other kinds of failure. */ -int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp, const unsigned char **buf, size_t len ); +int mbedtls_ecp_tls_read_group( mbedtls_ecp_group *grp, + const unsigned char **buf, size_t len ); /** - * \brief Write the TLS ECParameters record for a group - * - * \param grp ECP group used - * \param olen Number of bytes actually written - * \param buf Buffer to write to - * \param blen Buffer length - * - * \return 0 if successful, - * or MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL + * \brief This function extracts an elliptic curve group ID from a + * TLS ECParameters record as defined in RFC 4492, Section 5.4. + * + * \note The read pointer \p buf is updated to point right after + * the ECParameters record on exit. + * + * \param grp The address at which to store the group id. + * This must not be \c NULL. + * \param buf The address of the pointer to the start of the input buffer. + * \param len The length of the input buffer \c *buf in Bytes. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid. + * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the group is not + * recognized. + * \return Another negative error code on other kinds of failure. */ -int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, size_t *olen, - unsigned char *buf, size_t blen ); +int mbedtls_ecp_tls_read_group_id( mbedtls_ecp_group_id *grp, + const unsigned char **buf, + size_t len ); +/** + * \brief This function exports an elliptic curve as a TLS + * ECParameters record as defined in RFC 4492, Section 5.4. + * + * \param grp The ECP group to be exported. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param olen The address at which to store the number of Bytes written. + * This must not be \c NULL. + * \param buf The buffer to write to. This must be a writable buffer + * of length \p blen Bytes. + * \param blen The length of the output buffer \p buf in Bytes. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output + * buffer is too small to hold the exported group. + * \return Another negative error code on other kinds of failure. + */ +int mbedtls_ecp_tls_write_group( const mbedtls_ecp_group *grp, + size_t *olen, + unsigned char *buf, size_t blen ); /** - * \brief Multiplication by an integer: R = m * P - * (Not thread-safe to use same group in multiple threads) - * - * \note In order to prevent timing attacks, this function - * executes the exact same sequence of (base field) - * operations for any valid m. It avoids any if-branch or - * array index depending on the value of m. - * - * \note If f_rng is not NULL, it is used to randomize intermediate - * results in order to prevent potential timing attacks - * targeting these results. It is recommended to always - * provide a non-NULL f_rng (the overhead is negligible). - * - * \param grp ECP group - * \param R Destination point - * \param m Integer by which to multiply - * \param P Point to multiply - * \param f_rng RNG function (see notes) - * \param p_rng RNG parameter - * - * \return 0 if successful, - * MBEDTLS_ERR_ECP_INVALID_KEY if m is not a valid privkey - * or P is not a valid pubkey, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \brief This function performs a scalar multiplication of a point + * by an integer: \p R = \p m * \p P. + * + * It is not thread-safe to use same group in multiple threads. + * + * \note To prevent timing attacks, this function + * executes the exact same sequence of base-field + * operations for any valid \p m. It avoids any if-branch or + * array index depending on the value of \p m. + * + * \note If \p f_rng is not NULL, it is used to randomize + * intermediate results to prevent potential timing attacks + * targeting these results. We recommend always providing + * a non-NULL \p f_rng. The overhead is negligible. + * + * \param grp The ECP group to use. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param R The point in which to store the result of the calculation. + * This must be initialized. + * \param m The integer by which to multiply. This must be initialized. + * \param P The point to multiply. This must be initialized. + * \param f_rng The RNG function. This may be \c NULL if randomization + * of intermediate results isn't desired (discouraged). + * \param p_rng The RNG context to be passed to \p p_rng. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m is not a valid private + * key, or \p P is not a valid public key. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. + * \return Another negative error code on other kinds of failure. */ int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); /** - * \brief Multiplication and addition of two points by integers: - * R = m * P + n * Q - * (Not thread-safe to use same group in multiple threads) - * - * \note In contrast to mbedtls_ecp_mul(), this function does not guarantee - * a constant execution flow and timing. - * - * \param grp ECP group - * \param R Destination point - * \param m Integer by which to multiply P - * \param P Point to multiply by m - * \param n Integer by which to multiply Q - * \param Q Point to be multiplied by n - * - * \return 0 if successful, - * MBEDTLS_ERR_ECP_INVALID_KEY if m or n is not a valid privkey - * or P or Q is not a valid pubkey, - * MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed + * \brief This function performs multiplication of a point by + * an integer: \p R = \p m * \p P in a restartable way. + * + * \see mbedtls_ecp_mul() + * + * \note This function does the same as \c mbedtls_ecp_mul(), but + * it can return early and restart according to the limit set + * with \c mbedtls_ecp_set_max_ops() to reduce blocking. + * + * \param grp The ECP group to use. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param R The point in which to store the result of the calculation. + * This must be initialized. + * \param m The integer by which to multiply. This must be initialized. + * \param P The point to multiply. This must be initialized. + * \param f_rng The RNG function. This may be \c NULL if randomization + * of intermediate results isn't desired (discouraged). + * \param p_rng The RNG context to be passed to \p p_rng. + * \param rs_ctx The restart context (NULL disables restart). + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m is not a valid private + * key, or \p P is not a valid public key. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. + * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of + * operations was reached: see \c mbedtls_ecp_set_max_ops(). + * \return Another negative error code on other kinds of failure. + */ +int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, + const mbedtls_mpi *m, const mbedtls_ecp_point *P, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, + mbedtls_ecp_restart_ctx *rs_ctx ); + +/** + * \brief This function performs multiplication and addition of two + * points by integers: \p R = \p m * \p P + \p n * \p Q + * + * It is not thread-safe to use same group in multiple threads. + * + * \note In contrast to mbedtls_ecp_mul(), this function does not + * guarantee a constant execution flow and timing. + * + * \param grp The ECP group to use. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param R The point in which to store the result of the calculation. + * This must be initialized. + * \param m The integer by which to multiply \p P. + * This must be initialized. + * \param P The point to multiply by \p m. This must be initialized. + * \param n The integer by which to multiply \p Q. + * This must be initialized. + * \param Q The point to be multiplied by \p n. + * This must be initialized. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m or \p n are not + * valid private keys, or \p P or \p Q are not valid public + * keys. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. + * \return Another negative error code on other kinds of failure. */ int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, const mbedtls_mpi *m, const mbedtls_ecp_point *P, const mbedtls_mpi *n, const mbedtls_ecp_point *Q ); /** - * \brief Check that a point is a valid public key on this curve - * - * \param grp Curve/group the point should belong to - * \param pt Point to check - * - * \return 0 if point is a valid public key, - * MBEDTLS_ERR_ECP_INVALID_KEY otherwise. - * - * \note This function only checks the point is non-zero, has valid - * coordinates and lies on the curve, but not that it is - * indeed a multiple of G. This is additional check is more - * expensive, isn't required by standards, and shouldn't be - * necessary if the group used has a small cofactor. In - * particular, it is useless for the NIST groups which all - * have a cofactor of 1. - * - * \note Uses bare components rather than an mbedtls_ecp_keypair structure - * in order to ease use with other structures such as - * mbedtls_ecdh_context of mbedtls_ecdsa_context. + * \brief This function performs multiplication and addition of two + * points by integers: \p R = \p m * \p P + \p n * \p Q in a + * restartable way. + * + * \see \c mbedtls_ecp_muladd() + * + * \note This function works the same as \c mbedtls_ecp_muladd(), + * but it can return early and restart according to the limit + * set with \c mbedtls_ecp_set_max_ops() to reduce blocking. + * + * \param grp The ECP group to use. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param R The point in which to store the result of the calculation. + * This must be initialized. + * \param m The integer by which to multiply \p P. + * This must be initialized. + * \param P The point to multiply by \p m. This must be initialized. + * \param n The integer by which to multiply \p Q. + * This must be initialized. + * \param Q The point to be multiplied by \p n. + * This must be initialized. + * \param rs_ctx The restart context (NULL disables restart). + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m or \p n are not + * valid private keys, or \p P or \p Q are not valid public + * keys. + * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. + * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of + * operations was reached: see \c mbedtls_ecp_set_max_ops(). + * \return Another negative error code on other kinds of failure. */ -int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp, const mbedtls_ecp_point *pt ); +int mbedtls_ecp_muladd_restartable( + mbedtls_ecp_group *grp, mbedtls_ecp_point *R, + const mbedtls_mpi *m, const mbedtls_ecp_point *P, + const mbedtls_mpi *n, const mbedtls_ecp_point *Q, + mbedtls_ecp_restart_ctx *rs_ctx ); /** - * \brief Check that an mbedtls_mpi is a valid private key for this curve - * - * \param grp Group used - * \param d Integer to check - * - * \return 0 if point is a valid private key, - * MBEDTLS_ERR_ECP_INVALID_KEY otherwise. - * - * \note Uses bare components rather than an mbedtls_ecp_keypair structure - * in order to ease use with other structures such as - * mbedtls_ecdh_context of mbedtls_ecdsa_context. + * \brief This function checks that a point is a valid public key + * on this curve. + * + * It only checks that the point is non-zero, has + * valid coordinates and lies on the curve. It does not verify + * that it is indeed a multiple of \p G. This additional + * check is computationally more expensive, is not required + * by standards, and should not be necessary if the group + * used has a small cofactor. In particular, it is useless for + * the NIST groups which all have a cofactor of 1. + * + * \note This function uses bare components rather than an + * ::mbedtls_ecp_keypair structure, to ease use with other + * structures, such as ::mbedtls_ecdh_context or + * ::mbedtls_ecdsa_context. + * + * \param grp The ECP group the point should belong to. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param pt The point to check. This must be initialized. + * + * \return \c 0 if the point is a valid public key. + * \return #MBEDTLS_ERR_ECP_INVALID_KEY if the point is not + * a valid public key for the given curve. + * \return Another negative error code on other kinds of failure. */ -int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp, const mbedtls_mpi *d ); +int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp, + const mbedtls_ecp_point *pt ); /** - * \brief Generate a keypair with configurable base point - * - * \param grp ECP group - * \param G Chosen base point - * \param d Destination MPI (secret part) - * \param Q Destination point (public part) - * \param f_rng RNG function - * \param p_rng RNG parameter - * - * \return 0 if successful, - * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code - * - * \note Uses bare components rather than an mbedtls_ecp_keypair structure - * in order to ease use with other structures such as - * mbedtls_ecdh_context of mbedtls_ecdsa_context. + * \brief This function checks that an \p mbedtls_mpi is a + * valid private key for this curve. + * + * \note This function uses bare components rather than an + * ::mbedtls_ecp_keypair structure to ease use with other + * structures, such as ::mbedtls_ecdh_context or + * ::mbedtls_ecdsa_context. + * + * \param grp The ECP group the private key should belong to. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param d The integer to check. This must be initialized. + * + * \return \c 0 if the point is a valid private key. + * \return #MBEDTLS_ERR_ECP_INVALID_KEY if the point is not a valid + * private key for the given curve. + * \return Another negative error code on other kinds of failure. */ -int mbedtls_ecp_gen_keypair_base( mbedtls_ecp_group *grp, - const mbedtls_ecp_point *G, - mbedtls_mpi *d, mbedtls_ecp_point *Q, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng ); +int mbedtls_ecp_check_privkey( const mbedtls_ecp_group *grp, + const mbedtls_mpi *d ); /** - * \brief Generate a keypair - * - * \param grp ECP group - * \param d Destination MPI (secret part) - * \param Q Destination point (public part) - * \param f_rng RNG function - * \param p_rng RNG parameter - * - * \return 0 if successful, - * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code - * - * \note Uses bare components rather than an mbedtls_ecp_keypair structure - * in order to ease use with other structures such as - * mbedtls_ecdh_context of mbedtls_ecdsa_context. + * \brief This function generates a private key. + * + * \param grp The ECP group to generate a private key for. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param d The destination MPI (secret part). This must be initialized. + * \param f_rng The RNG function. This must not be \c NULL. + * \param p_rng The RNG parameter to be passed to \p f_rng. This may be + * \c NULL if \p f_rng doesn't need a context argument. + * + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code + * on failure. */ -int mbedtls_ecp_gen_keypair( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q, +int mbedtls_ecp_gen_privkey( const mbedtls_ecp_group *grp, + mbedtls_mpi *d, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); /** - * \brief Generate a keypair + * \brief This function generates a keypair with a configurable base + * point. + * + * \note This function uses bare components rather than an + * ::mbedtls_ecp_keypair structure to ease use with other + * structures, such as ::mbedtls_ecdh_context or + * ::mbedtls_ecdsa_context. + * + * \param grp The ECP group to generate a key pair for. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param G The base point to use. This must be initialized + * and belong to \p grp. It replaces the default base + * point \c grp->G used by mbedtls_ecp_gen_keypair(). + * \param d The destination MPI (secret part). + * This must be initialized. + * \param Q The destination point (public part). + * This must be initialized. + * \param f_rng The RNG function. This must not be \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may + * be \c NULL if \p f_rng doesn't need a context argument. + * + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code + * on failure. + */ +int mbedtls_ecp_gen_keypair_base( mbedtls_ecp_group *grp, + const mbedtls_ecp_point *G, + mbedtls_mpi *d, mbedtls_ecp_point *Q, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); + +/** + * \brief This function generates an ECP keypair. + * + * \note This function uses bare components rather than an + * ::mbedtls_ecp_keypair structure to ease use with other + * structures, such as ::mbedtls_ecdh_context or + * ::mbedtls_ecdsa_context. + * + * \param grp The ECP group to generate a key pair for. + * This must be initialized and have group parameters + * set, for example through mbedtls_ecp_group_load(). + * \param d The destination MPI (secret part). + * This must be initialized. + * \param Q The destination point (public part). + * This must be initialized. + * \param f_rng The RNG function. This must not be \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may + * be \c NULL if \p f_rng doesn't need a context argument. + * + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code + * on failure. + */ +int mbedtls_ecp_gen_keypair( mbedtls_ecp_group *grp, mbedtls_mpi *d, + mbedtls_ecp_point *Q, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); + +/** + * \brief This function generates an ECP key. * - * \param grp_id ECP group identifier - * \param key Destination keypair - * \param f_rng RNG function - * \param p_rng RNG parameter + * \param grp_id The ECP group identifier. + * \param key The destination key. This must be initialized. + * \param f_rng The RNG function to use. This must not be \c NULL. + * \param p_rng The RNG context to be passed to \p f_rng. This may + * be \c NULL if \p f_rng doesn't need a context argument. * - * \return 0 if successful, - * or a MBEDTLS_ERR_ECP_XXX or MBEDTLS_MPI_XXX error code + * \return \c 0 on success. + * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code + * on failure. */ int mbedtls_ecp_gen_key( mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); /** - * \brief Check a public-private key pair - * - * \param pub Keypair structure holding a public key - * \param prv Keypair structure holding a private (plus public) key - * - * \return 0 if successful (keys are valid and match), or - * MBEDTLS_ERR_ECP_BAD_INPUT_DATA, or - * a MBEDTLS_ERR_ECP_XXX or MBEDTLS_ERR_MPI_XXX code. + * \brief This function checks that the keypair objects + * \p pub and \p prv have the same group and the + * same public point, and that the private key in + * \p prv is consistent with the public key. + * + * \param pub The keypair structure holding the public key. This + * must be initialized. If it contains a private key, that + * part is ignored. + * \param prv The keypair structure holding the full keypair. + * This must be initialized. + * + * \return \c 0 on success, meaning that the keys are valid and match. + * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the keys are invalid or do not match. + * \return An \c MBEDTLS_ERR_ECP_XXX or an \c MBEDTLS_ERR_MPI_XXX + * error code on calculation failure. */ -int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv ); +int mbedtls_ecp_check_pub_priv( const mbedtls_ecp_keypair *pub, + const mbedtls_ecp_keypair *prv ); #if defined(MBEDTLS_SELF_TEST) /** - * \brief Checkup routine + * \brief The ECP checkup routine. * - * \return 0 if successful, or 1 if a test failed + * \return \c 0 on success. + * \return \c 1 on failure. */ int mbedtls_ecp_self_test( int verbose ); @@ -685,8 +1129,4 @@ int mbedtls_ecp_self_test( int verbose ); } #endif -#else /* MBEDTLS_ECP_ALT */ -#include "ecp_alt.h" -#endif /* MBEDTLS_ECP_ALT */ - #endif /* ecp.h */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/entropy.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/entropy.h index fcb4d02557..ca06dc3c58 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/entropy.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/entropy.h @@ -107,7 +107,7 @@ typedef int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, s /** * \brief Entropy source state */ -typedef struct +typedef struct mbedtls_entropy_source_state { mbedtls_entropy_f_source_ptr f_source; /**< The entropy source callback */ void * p_source; /**< The callback data pointer */ @@ -120,7 +120,7 @@ mbedtls_entropy_source_state; /** * \brief Entropy context structure */ -typedef struct +typedef struct mbedtls_entropy_context { int accumulator_started; #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR) @@ -166,7 +166,7 @@ void mbedtls_entropy_free( mbedtls_entropy_context *ctx ); * \param threshold Minimum required from source before entropy is released * ( with mbedtls_entropy_func() ) (in bytes) * \param strong MBEDTLS_ENTROPY_SOURCE_STRONG or - * MBEDTSL_ENTROPY_SOURCE_WEAK. + * MBEDTLS_ENTROPY_SOURCE_WEAK. * At least one strong source needs to be added. * Weaker sources (such as the cycle counter) can be used as * a complement. diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/error.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/error.h index ef22bc6842..bee0fe485a 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/error.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/error.h @@ -4,7 +4,7 @@ * \brief Error to string translation */ /* - * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved + * Copyright (C) 2006-2018, ARM Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -59,7 +59,7 @@ * GCM 3 0x0012-0x0014 0x0013-0x0013 * BLOWFISH 3 0x0016-0x0018 0x0017-0x0017 * THREADING 3 0x001A-0x001E - * AES 4 0x0020-0x0022 0x0023-0x0025 + * AES 5 0x0020-0x0022 0x0021-0x0025 * CAMELLIA 3 0x0024-0x0026 0x0027-0x0027 * XTEA 2 0x0028-0x0028 0x0029-0x0029 * BASE64 2 0x002A-0x002C @@ -68,7 +68,8 @@ * DES 2 0x0032-0x0032 0x0033-0x0033 * CTR_DBRG 4 0x0034-0x003A * ENTROPY 3 0x003C-0x0040 0x003D-0x003F - * NET 11 0x0042-0x0052 0x0043-0x0045 + * NET 13 0x0042-0x0052 0x0043-0x0049 + * ARIA 4 0x0058-0x005E * ASN1 7 0x0060-0x006C * CMAC 1 0x007A-0x007A * PBKDF2 1 0x007C-0x007C @@ -79,9 +80,13 @@ * MD4 1 0x002D-0x002D * MD5 1 0x002F-0x002F * RIPEMD160 1 0x0031-0x0031 - * SHA1 1 0x0035-0x0035 - * SHA256 1 0x0037-0x0037 - * SHA512 1 0x0039-0x0039 + * SHA1 1 0x0035-0x0035 0x0073-0x0073 + * SHA256 1 0x0037-0x0037 0x0074-0x0074 + * SHA512 1 0x0039-0x0039 0x0075-0x0075 + * CHACHA20 3 0x0051-0x0055 + * POLY1305 3 0x0057-0x005B + * CHACHAPOLY 2 0x0054-0x0056 + * PLATFORM 1 0x0070-0x0072 * * High-level module nr (3 bits - 0x0...-0x7...) * Name ID Nr of Errors @@ -92,11 +97,12 @@ * DHM 3 11 * PK 3 15 (Started from top) * RSA 4 11 - * ECP 4 9 (Started from top) + * ECP 4 10 (Started from top) * MD 5 5 + * HKDF 5 1 (Started from top) * CIPHER 6 8 - * SSL 6 17 (Started from top) - * SSL 7 31 + * SSL 6 23 (Started from top) + * SSL 7 32 * * Module dependent error code (5 bits 0x.00.-0x.F8.) */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/gcm.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/gcm.h index bd258aae54..fd130abd7c 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/gcm.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/gcm.h @@ -1,9 +1,11 @@ /** * \file gcm.h * - * \brief Galois/Counter Mode (GCM) for 128-bit block ciphers, as defined - * in D. McGrew, J. Viega, The Galois/Counter Mode of Operation - * (GCM), Natl. Inst. Stand. Technol. + * \brief This file contains GCM definitions and functions. + * + * The Galois/Counter Mode (GCM) for 128-bit block ciphers is defined + * in D. McGrew, J. Viega, The Galois/Counter Mode of Operation + * (GCM), Natl. Inst. Stand. Technol. * * For more information on GCM, see NIST SP 800-38D: Recommendation for * Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC. @@ -45,19 +47,23 @@ #define MBEDTLS_GCM_DECRYPT 0 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012 /**< Authenticated decryption failed. */ + +/* MBEDTLS_ERR_GCM_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013 /**< GCM hardware accelerator failed. */ -#define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014 /**< Bad input parameters to function. */ -#if !defined(MBEDTLS_GCM_ALT) +#define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014 /**< Bad input parameters to function. */ #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_GCM_ALT) + /** * \brief The GCM context structure. */ -typedef struct { +typedef struct mbedtls_gcm_context +{ mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */ uint64_t HL[16]; /*!< Precalculated HTable low. */ uint64_t HH[16]; /*!< Precalculated HTable high. */ @@ -72,6 +78,10 @@ typedef struct { } mbedtls_gcm_context; +#else /* !MBEDTLS_GCM_ALT */ +#include "gcm_alt.h" +#endif /* !MBEDTLS_GCM_ALT */ + /** * \brief This function initializes the specified GCM context, * to make references valid, and prepares the context @@ -81,7 +91,7 @@ mbedtls_gcm_context; * cipher, nor set the key. For this purpose, use * mbedtls_gcm_setkey(). * - * \param ctx The GCM context to initialize. + * \param ctx The GCM context to initialize. This must not be \c NULL. */ void mbedtls_gcm_init( mbedtls_gcm_context *ctx ); @@ -89,15 +99,17 @@ void mbedtls_gcm_init( mbedtls_gcm_context *ctx ); * \brief This function associates a GCM context with a * cipher algorithm and a key. * - * \param ctx The GCM context to initialize. + * \param ctx The GCM context. This must be initialized. * \param cipher The 128-bit block cipher to use. - * \param key The encryption key. + * \param key The encryption key. This must be a readable buffer of at + * least \p keybits bits. * \param keybits The key size in bits. Valid options are: *
  • 128 bits
  • *
  • 192 bits
  • *
  • 256 bits
* - * \return \c 0 on success, or a cipher specific error code. + * \return \c 0 on success. + * \return A cipher-specific error code on failure. */ int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, mbedtls_cipher_id_t cipher, @@ -107,17 +119,18 @@ int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, /** * \brief This function performs GCM encryption or decryption of a buffer. * - * \note For encryption, the output buffer can be the same as the input buffer. - * For decryption, the output buffer cannot be the same as input buffer. - * If the buffers overlap, the output buffer must trail at least 8 Bytes - * behind the input buffer. + * \note For encryption, the output buffer can be the same as the + * input buffer. For decryption, the output buffer cannot be + * the same as input buffer. If the buffers overlap, the output + * buffer must trail at least 8 Bytes behind the input buffer. * * \warning When this function performs a decryption, it outputs the * authentication tag and does not verify that the data is * authentic. You should use this function to perform encryption * only. For decryption, use mbedtls_gcm_auth_decrypt() instead. * - * \param ctx The GCM context to use for encryption or decryption. + * \param ctx The GCM context to use for encryption or decryption. This + * must be initialized. * \param mode The operation to perform: * - #MBEDTLS_GCM_ENCRYPT to perform authenticated encryption. * The ciphertext is written to \p output and the @@ -131,22 +144,28 @@ int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, * calling this function in decryption mode. * \param length The length of the input data, which is equal to the length * of the output data. - * \param iv The initialization vector. + * \param iv The initialization vector. This must be a readable buffer of + * at least \p iv_len Bytes. * \param iv_len The length of the IV. - * \param add The buffer holding the additional data. + * \param add The buffer holding the additional data. This must be of at + * least that size in Bytes. * \param add_len The length of the additional data. - * \param input The buffer holding the input data. Its size is \b length. - * \param output The buffer for holding the output data. It must have room - * for \b length bytes. + * \param input The buffer holding the input data. If \p length is greater + * than zero, this must be a readable buffer of at least that + * size in Bytes. + * \param output The buffer for holding the output data. If \p length is greater + * than zero, this must be a writable buffer of at least that + * size in Bytes. * \param tag_len The length of the tag to generate. - * \param tag The buffer for holding the tag. + * \param tag The buffer for holding the tag. This must be a readable + * buffer of at least \p tag_len Bytes. * * \return \c 0 if the encryption or decryption was performed * successfully. Note that in #MBEDTLS_GCM_DECRYPT mode, * this does not indicate that the data is authentic. - * \return #MBEDTLS_ERR_GCM_BAD_INPUT if the lengths are not valid. - * \return #MBEDTLS_ERR_GCM_HW_ACCEL_FAILED or a cipher-specific - * error code if the encryption or decryption failed. + * \return #MBEDTLS_ERR_GCM_BAD_INPUT if the lengths or pointers are + * not valid or a cipher-specific error code if the encryption + * or decryption failed. */ int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx, int mode, @@ -164,28 +183,34 @@ int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx, * \brief This function performs a GCM authenticated decryption of a * buffer. * - * \note For decryption, the output buffer cannot be the same as input buffer. - * If the buffers overlap, the output buffer must trail at least 8 Bytes - * behind the input buffer. + * \note For decryption, the output buffer cannot be the same as + * input buffer. If the buffers overlap, the output buffer + * must trail at least 8 Bytes behind the input buffer. * - * \param ctx The GCM context. + * \param ctx The GCM context. This must be initialized. * \param length The length of the ciphertext to decrypt, which is also * the length of the decrypted plaintext. - * \param iv The initialization vector. + * \param iv The initialization vector. This must be a readable buffer + * of at least \p iv_len Bytes. * \param iv_len The length of the IV. - * \param add The buffer holding the additional data. + * \param add The buffer holding the additional data. This must be of at + * least that size in Bytes. * \param add_len The length of the additional data. - * \param tag The buffer holding the tag to verify. + * \param tag The buffer holding the tag to verify. This must be a + * readable buffer of at least \p tag_len Bytes. * \param tag_len The length of the tag to verify. - * \param input The buffer holding the ciphertext. Its size is \b length. - * \param output The buffer for holding the decrypted plaintext. It must - * have room for \b length bytes. + * \param input The buffer holding the ciphertext. If \p length is greater + * than zero, this must be a readable buffer of at least that + * size. + * \param output The buffer for holding the decrypted plaintext. If \p length + * is greater than zero, this must be a writable buffer of at + * least that size. * * \return \c 0 if successful and authenticated. * \return #MBEDTLS_ERR_GCM_AUTH_FAILED if the tag does not match. - * \return #MBEDTLS_ERR_GCM_BAD_INPUT if the lengths are not valid. - * \return #MBEDTLS_ERR_GCM_HW_ACCEL_FAILED or a cipher-specific - * error code if the decryption failed. + * \return #MBEDTLS_ERR_GCM_BAD_INPUT if the lengths or pointers are + * not valid or a cipher-specific error code if the decryption + * failed. */ int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx, size_t length, @@ -202,15 +227,18 @@ int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx, * \brief This function starts a GCM encryption or decryption * operation. * - * \param ctx The GCM context. + * \param ctx The GCM context. This must be initialized. * \param mode The operation to perform: #MBEDTLS_GCM_ENCRYPT or * #MBEDTLS_GCM_DECRYPT. - * \param iv The initialization vector. + * \param iv The initialization vector. This must be a readable buffer of + * at least \p iv_len Bytes. * \param iv_len The length of the IV. - * \param add The buffer holding the additional data, or NULL if \p add_len is 0. - * \param add_len The length of the additional data. If 0, \p add is NULL. + * \param add The buffer holding the additional data, or \c NULL + * if \p add_len is \c 0. + * \param add_len The length of the additional data. If \c 0, + * \p add may be \c NULL. * - * \return \c 0 on success. + * \return \c 0 on success. */ int mbedtls_gcm_starts( mbedtls_gcm_context *ctx, int mode, @@ -227,16 +255,22 @@ int mbedtls_gcm_starts( mbedtls_gcm_context *ctx, * Bytes. Only the last call before calling * mbedtls_gcm_finish() can be less than 16 Bytes. * - * \note For decryption, the output buffer cannot be the same as input buffer. - * If the buffers overlap, the output buffer must trail at least 8 Bytes - * behind the input buffer. + * \note For decryption, the output buffer cannot be the same as + * input buffer. If the buffers overlap, the output buffer + * must trail at least 8 Bytes behind the input buffer. * - * \param ctx The GCM context. - * \param length The length of the input data. This must be a multiple of 16 except in the last call before mbedtls_gcm_finish(). - * \param input The buffer holding the input data. - * \param output The buffer for holding the output data. + * \param ctx The GCM context. This must be initialized. + * \param length The length of the input data. This must be a multiple of + * 16 except in the last call before mbedtls_gcm_finish(). + * \param input The buffer holding the input data. If \p length is greater + * than zero, this must be a readable buffer of at least that + * size in Bytes. + * \param output The buffer for holding the output data. If \p length is + * greater than zero, this must be a writable buffer of at + * least that size in Bytes. * - * \return \c 0 on success, or #MBEDTLS_ERR_GCM_BAD_INPUT on failure. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_GCM_BAD_INPUT on failure. */ int mbedtls_gcm_update( mbedtls_gcm_context *ctx, size_t length, @@ -250,11 +284,14 @@ int mbedtls_gcm_update( mbedtls_gcm_context *ctx, * It wraps up the GCM stream, and generates the * tag. The tag can have a maximum length of 16 Bytes. * - * \param ctx The GCM context. - * \param tag The buffer for holding the tag. - * \param tag_len The length of the tag to generate. Must be at least four. + * \param ctx The GCM context. This must be initialized. + * \param tag The buffer for holding the tag. This must be a readable + * buffer of at least \p tag_len Bytes. + * \param tag_len The length of the tag to generate. This must be at least + * four. * - * \return \c 0 on success, or #MBEDTLS_ERR_GCM_BAD_INPUT on failure. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_GCM_BAD_INPUT on failure. */ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx, unsigned char *tag, @@ -264,29 +301,23 @@ int mbedtls_gcm_finish( mbedtls_gcm_context *ctx, * \brief This function clears a GCM context and the underlying * cipher sub-context. * - * \param ctx The GCM context to clear. + * \param ctx The GCM context to clear. If this is \c NULL, the call has + * no effect. Otherwise, this must be initialized. */ void mbedtls_gcm_free( mbedtls_gcm_context *ctx ); -#ifdef __cplusplus -} -#endif - -#else /* !MBEDTLS_GCM_ALT */ -#include "gcm_alt.h" -#endif /* !MBEDTLS_GCM_ALT */ - -#ifdef __cplusplus -extern "C" { -#endif +#if defined(MBEDTLS_SELF_TEST) /** * \brief The GCM checkup routine. * - * \return \c 0 on success, or \c 1 on failure. + * \return \c 0 on success. + * \return \c 1 on failure. */ int mbedtls_gcm_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/havege.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/havege.h index e6bf6fae8e..4c1c86087a 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/havege.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/havege.h @@ -41,7 +41,7 @@ extern "C" { /** * \brief HAVEGE state structure */ -typedef struct +typedef struct mbedtls_havege_state { int PT1, PT2, offset[2]; int pool[MBEDTLS_HAVEGE_COLLECT_SIZE]; diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/hkdf.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/hkdf.h new file mode 100644 index 0000000000..40ee64eb03 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/hkdf.h @@ -0,0 +1,141 @@ +/** + * \file hkdf.h + * + * \brief This file contains the HKDF interface. + * + * The HMAC-based Extract-and-Expand Key Derivation Function (HKDF) is + * specified by RFC 5869. + */ +/* + * Copyright (C) 2016-2018, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of mbed TLS (https://tls.mbed.org) + */ +#ifndef MBEDTLS_HKDF_H +#define MBEDTLS_HKDF_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include "md.h" + +/** + * \name HKDF Error codes + * \{ + */ +#define MBEDTLS_ERR_HKDF_BAD_INPUT_DATA -0x5F80 /**< Bad input parameters to function. */ +/* \} name */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief This is the HMAC-based Extract-and-Expand Key Derivation Function + * (HKDF). + * + * \param md A hash function; md.size denotes the length of the hash + * function output in bytes. + * \param salt An optional salt value (a non-secret random value); + * if the salt is not provided, a string of all zeros of + * md.size length is used as the salt. + * \param salt_len The length in bytes of the optional \p salt. + * \param ikm The input keying material. + * \param ikm_len The length in bytes of \p ikm. + * \param info An optional context and application specific information + * string. This can be a zero-length string. + * \param info_len The length of \p info in bytes. + * \param okm The output keying material of \p okm_len bytes. + * \param okm_len The length of the output keying material in bytes. This + * must be less than or equal to 255 * md.size bytes. + * + * \return 0 on success. + * \return #MBEDTLS_ERR_HKDF_BAD_INPUT_DATA when the parameters are invalid. + * \return An MBEDTLS_ERR_MD_* error for errors returned from the underlying + * MD layer. + */ +int mbedtls_hkdf( const mbedtls_md_info_t *md, const unsigned char *salt, + size_t salt_len, const unsigned char *ikm, size_t ikm_len, + const unsigned char *info, size_t info_len, + unsigned char *okm, size_t okm_len ); + +/** + * \brief Take the input keying material \p ikm and extract from it a + * fixed-length pseudorandom key \p prk. + * + * \warning This function should only be used if the security of it has been + * studied and established in that particular context (eg. TLS 1.3 + * key schedule). For standard HKDF security guarantees use + * \c mbedtls_hkdf instead. + * + * \param md A hash function; md.size denotes the length of the + * hash function output in bytes. + * \param salt An optional salt value (a non-secret random value); + * if the salt is not provided, a string of all zeros + * of md.size length is used as the salt. + * \param salt_len The length in bytes of the optional \p salt. + * \param ikm The input keying material. + * \param ikm_len The length in bytes of \p ikm. + * \param[out] prk A pseudorandom key of at least md.size bytes. + * + * \return 0 on success. + * \return #MBEDTLS_ERR_HKDF_BAD_INPUT_DATA when the parameters are invalid. + * \return An MBEDTLS_ERR_MD_* error for errors returned from the underlying + * MD layer. + */ +int mbedtls_hkdf_extract( const mbedtls_md_info_t *md, + const unsigned char *salt, size_t salt_len, + const unsigned char *ikm, size_t ikm_len, + unsigned char *prk ); + +/** + * \brief Expand the supplied \p prk into several additional pseudorandom + * keys, which is the output of the HKDF. + * + * \warning This function should only be used if the security of it has been + * studied and established in that particular context (eg. TLS 1.3 + * key schedule). For standard HKDF security guarantees use + * \c mbedtls_hkdf instead. + * + * \param md A hash function; md.size denotes the length of the hash + * function output in bytes. + * \param prk A pseudorandom key of at least md.size bytes. \p prk is + * usually the output from the HKDF extract step. + * \param prk_len The length in bytes of \p prk. + * \param info An optional context and application specific information + * string. This can be a zero-length string. + * \param info_len The length of \p info in bytes. + * \param okm The output keying material of \p okm_len bytes. + * \param okm_len The length of the output keying material in bytes. This + * must be less than or equal to 255 * md.size bytes. + * + * \return 0 on success. + * \return #MBEDTLS_ERR_HKDF_BAD_INPUT_DATA when the parameters are invalid. + * \return An MBEDTLS_ERR_MD_* error for errors returned from the underlying + * MD layer. + */ +int mbedtls_hkdf_expand( const mbedtls_md_info_t *md, const unsigned char *prk, + size_t prk_len, const unsigned char *info, + size_t info_len, unsigned char *okm, size_t okm_len ); + +#ifdef __cplusplus +} +#endif + +#endif /* hkdf.h */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h index f58b1e31d8..7eae32bbd6 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/hmac_drbg.h @@ -80,7 +80,7 @@ extern "C" { /** * HMAC_DRBG context. */ -typedef struct +typedef struct mbedtls_hmac_drbg_context { /* Working state: the key K is not stored explicitely, * but is implied by the HMAC context */ @@ -210,23 +210,6 @@ void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx, int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t add_len ); -/** - * \brief HMAC_DRBG update state - * - * \warning This function cannot report errors. You should use - * mbedtls_hmac_drbg_update_ret() instead. - * - * \param ctx HMAC_DRBG context - * \param additional Additional data to update state with, or NULL - * \param add_len Length of additional data, or 0 - * - * \note Additional data is optional, pass NULL and 0 as second - * third argument if no additional data is being used. - */ -void mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx, - const unsigned char *additional, - size_t add_len ); - /** * \brief HMAC_DRBG reseeding (extracts data from entropy source) * @@ -283,6 +266,31 @@ int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len */ void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx ); +#if ! defined(MBEDTLS_DEPRECATED_REMOVED) +#if defined(MBEDTLS_DEPRECATED_WARNING) +#define MBEDTLS_DEPRECATED __attribute__((deprecated)) +#else +#define MBEDTLS_DEPRECATED +#endif +/** + * \brief HMAC_DRBG update state + * + * \deprecated Superseded by mbedtls_hmac_drbg_update_ret() + * in 2.16.0. + * + * \param ctx HMAC_DRBG context + * \param additional Additional data to update state with, or NULL + * \param add_len Length of additional data, or 0 + * + * \note Additional data is optional, pass NULL and 0 as second + * third argument if no additional data is being used. + */ +MBEDTLS_DEPRECATED void mbedtls_hmac_drbg_update( + mbedtls_hmac_drbg_context *ctx, + const unsigned char *additional, size_t add_len ); +#undef MBEDTLS_DEPRECATED +#endif /* !MBEDTLS_DEPRECATED_REMOVED */ + #if defined(MBEDTLS_FS_IO) /** * \brief Write a seed file diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/md.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/md.h index 06538c3827..8bcf766a6c 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/md.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/md.h @@ -1,7 +1,7 @@ /** * \file md.h * - * \brief The generic message-digest wrapper. + * \brief This file contains the generic message-digest wrapper. * * \author Adriaan de Jong */ @@ -39,6 +39,8 @@ #define MBEDTLS_ERR_MD_BAD_INPUT_DATA -0x5100 /**< Bad input parameters to function. */ #define MBEDTLS_ERR_MD_ALLOC_FAILED -0x5180 /**< Failed to allocate memory. */ #define MBEDTLS_ERR_MD_FILE_IO_ERROR -0x5200 /**< Opening or reading of file failed. */ + +/* MBEDTLS_ERR_MD_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_MD_HW_ACCEL_FAILED -0x5280 /**< MD hardware accelerator failed. */ #ifdef __cplusplus @@ -46,7 +48,7 @@ extern "C" { #endif /** - * \brief Enumeration of supported message digests + * \brief Supported message digests. * * \warning MD2, MD4, MD5 and SHA-1 are considered weak message digests and * their use constitutes a security risk. We recommend considering @@ -54,16 +56,16 @@ extern "C" { * */ typedef enum { - MBEDTLS_MD_NONE=0, - MBEDTLS_MD_MD2, - MBEDTLS_MD_MD4, - MBEDTLS_MD_MD5, - MBEDTLS_MD_SHA1, - MBEDTLS_MD_SHA224, - MBEDTLS_MD_SHA256, - MBEDTLS_MD_SHA384, - MBEDTLS_MD_SHA512, - MBEDTLS_MD_RIPEMD160, + MBEDTLS_MD_NONE=0, /**< None. */ + MBEDTLS_MD_MD2, /**< The MD2 message digest. */ + MBEDTLS_MD_MD4, /**< The MD4 message digest. */ + MBEDTLS_MD_MD5, /**< The MD5 message digest. */ + MBEDTLS_MD_SHA1, /**< The SHA-1 message digest. */ + MBEDTLS_MD_SHA224, /**< The SHA-224 message digest. */ + MBEDTLS_MD_SHA256, /**< The SHA-256 message digest. */ + MBEDTLS_MD_SHA384, /**< The SHA-384 message digest. */ + MBEDTLS_MD_SHA512, /**< The SHA-512 message digest. */ + MBEDTLS_MD_RIPEMD160, /**< The RIPEMD-160 message digest. */ } mbedtls_md_type_t; #if defined(MBEDTLS_SHA512_C) @@ -80,7 +82,8 @@ typedef struct mbedtls_md_info_t mbedtls_md_info_t; /** * The generic message-digest context. */ -typedef struct { +typedef struct mbedtls_md_context_t +{ /** Information about the associated message digest. */ const mbedtls_md_info_t *md_info; @@ -108,8 +111,8 @@ const int *mbedtls_md_list( void ); * * \param md_name The name of the digest to search for. * - * \return The message-digest information associated with \p md_name, - * or NULL if not found. + * \return The message-digest information associated with \p md_name. + * \return NULL if the associated message-digest information is not found. */ const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name ); @@ -119,8 +122,8 @@ const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name ); * * \param md_type The type of digest to search for. * - * \return The message-digest information associated with \p md_type, - * or NULL if not found. + * \return The message-digest information associated with \p md_type. + * \return NULL if the associated message-digest information is not found. */ const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type ); @@ -168,9 +171,10 @@ void mbedtls_md_free( mbedtls_md_context_t *ctx ); * \param md_info The information structure of the message-digest algorithm * to use. * - * \returns \c 0 on success, - * #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure, - * #MBEDTLS_ERR_MD_ALLOC_FAILED memory allocation failure. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification + * failure. + * \return #MBEDTLS_ERR_MD_ALLOC_FAILED on memory-allocation failure. */ int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info ) MBEDTLS_DEPRECATED; #undef MBEDTLS_DEPRECATED @@ -187,12 +191,13 @@ int mbedtls_md_init_ctx( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_ * \param ctx The context to set up. * \param md_info The information structure of the message-digest algorithm * to use. - * \param hmac
  • 0: HMAC is not used. Saves some memory.
  • - *
  • non-zero: HMAC is used with this context.
+ * \param hmac Defines if HMAC is used. 0: HMAC is not used (saves some memory), + * or non-zero: HMAC is used with this context. * - * \returns \c 0 on success, - * #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure, or - * #MBEDTLS_ERR_MD_ALLOC_FAILED on memory allocation failure. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification + * failure. + * \return #MBEDTLS_ERR_MD_ALLOC_FAILED on memory-allocation failure. */ int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac ); @@ -212,8 +217,8 @@ int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_inf * \param dst The destination context. * \param src The context to be cloned. * - * \return \c 0 on success, - * #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter failure. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification failure. */ int mbedtls_md_clone( mbedtls_md_context_t *dst, const mbedtls_md_context_t *src ); @@ -260,8 +265,9 @@ const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info ); * * \param ctx The generic message-digest context. * - * \returns \c 0 on success, #MBEDTLS_ERR_MD_BAD_INPUT_DATA if - * parameter verification fails. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification + * failure. */ int mbedtls_md_starts( mbedtls_md_context_t *ctx ); @@ -277,8 +283,9 @@ int mbedtls_md_starts( mbedtls_md_context_t *ctx ); * \param input The buffer holding the input data. * \param ilen The length of the input data. * - * \returns \c 0 on success, #MBEDTLS_ERR_MD_BAD_INPUT_DATA if - * parameter verification fails. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification + * failure. */ int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ); @@ -296,8 +303,9 @@ int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, si * \param ctx The generic message-digest context. * \param output The buffer for the generic message-digest checksum result. * - * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if - * parameter verification fails. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification + * failure. */ int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output ); @@ -315,8 +323,9 @@ int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output ); * \param ilen The length of the input data. * \param output The generic message-digest checksum result. * - * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if - * parameter verification fails. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification + * failure. */ int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, unsigned char *output ); @@ -334,9 +343,10 @@ int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, si * \param path The input file name. * \param output The generic message-digest checksum result. * - * \return \c 0 on success, - * #MBEDTLS_ERR_MD_FILE_IO_ERROR if file input failed, or - * #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info was NULL. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_FILE_IO_ERROR on an I/O error accessing + * the file pointed by \p path. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info was NULL. */ int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path, unsigned char *output ); @@ -356,8 +366,9 @@ int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path, * \param key The HMAC secret key. * \param keylen The length of the HMAC key in Bytes. * - * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if - * parameter verification fails. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification + * failure. */ int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen ); @@ -377,8 +388,9 @@ int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, * \param input The buffer holding the input data. * \param ilen The length of the input data. * - * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if - * parameter verification fails. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification + * failure. */ int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ); @@ -397,8 +409,9 @@ int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *inpu * context. * \param output The generic HMAC checksum result. * - * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if - * parameter verification fails. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification + * failure. */ int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output); @@ -413,8 +426,9 @@ int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output); * \param ctx The message digest context containing an embedded HMAC * context. * - * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if - * parameter verification fails. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification + * failure. */ int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ); @@ -436,8 +450,9 @@ int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ); * \param ilen The length of the input data. * \param output The generic HMAC result. * - * \returns \c 0 on success, or #MBEDTLS_ERR_MD_BAD_INPUT_DATA if - * parameter verification fails. + * \return \c 0 on success. + * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification + * failure. */ int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/md2.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/md2.h index 0fd8b5afcc..fe97cf08d4 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/md2.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/md2.h @@ -37,16 +37,17 @@ #include +/* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */ -#if !defined(MBEDTLS_MD2_ALT) -// Regular implementation -// - #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_MD2_ALT) +// Regular implementation +// + /** * \brief MD2 context structure * @@ -55,7 +56,7 @@ extern "C" { * stronger message digests instead. * */ -typedef struct +typedef struct mbedtls_md2_context { unsigned char cksum[16]; /*!< checksum of the data block */ unsigned char state[48]; /*!< intermediate digest state */ @@ -64,6 +65,10 @@ typedef struct } mbedtls_md2_context; +#else /* MBEDTLS_MD2_ALT */ +#include "md2_alt.h" +#endif /* MBEDTLS_MD2_ALT */ + /** * \brief Initialize MD2 context * @@ -235,18 +240,6 @@ MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx ); #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ -#ifdef __cplusplus -} -#endif - -#else /* MBEDTLS_MD2_ALT */ -#include "md2_alt.h" -#endif /* MBEDTLS_MD2_ALT */ - -#ifdef __cplusplus -extern "C" { -#endif - /** * \brief Output = MD2( input buffer ) * @@ -290,6 +283,8 @@ MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input, #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ +#if defined(MBEDTLS_SELF_TEST) + /** * \brief Checkup routine * @@ -302,6 +297,8 @@ MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input, */ int mbedtls_md2_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/md4.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/md4.h index 23fa95e46a..ce703c0ba4 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/md4.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/md4.h @@ -38,16 +38,17 @@ #include #include +/* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */ -#if !defined(MBEDTLS_MD4_ALT) -// Regular implementation -// - #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_MD4_ALT) +// Regular implementation +// + /** * \brief MD4 context structure * @@ -56,7 +57,7 @@ extern "C" { * stronger message digests instead. * */ -typedef struct +typedef struct mbedtls_md4_context { uint32_t total[2]; /*!< number of bytes processed */ uint32_t state[4]; /*!< intermediate digest state */ @@ -64,6 +65,10 @@ typedef struct } mbedtls_md4_context; +#else /* MBEDTLS_MD4_ALT */ +#include "md4_alt.h" +#endif /* MBEDTLS_MD4_ALT */ + /** * \brief Initialize MD4 context * @@ -238,18 +243,6 @@ MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx, #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ -#ifdef __cplusplus -} -#endif - -#else /* MBEDTLS_MD4_ALT */ -#include "md4_alt.h" -#endif /* MBEDTLS_MD4_ALT */ - -#ifdef __cplusplus -extern "C" { -#endif - /** * \brief Output = MD4( input buffer ) * @@ -295,6 +288,8 @@ MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input, #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ +#if defined(MBEDTLS_SELF_TEST) + /** * \brief Checkup routine * @@ -307,6 +302,8 @@ MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input, */ int mbedtls_md4_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/md5.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/md5.h index 06ea4c5d44..6eed6cc864 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/md5.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/md5.h @@ -37,16 +37,17 @@ #include #include +/* MBEDTLS_ERR_MD5_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED -0x002F /**< MD5 hardware accelerator failed */ -#if !defined(MBEDTLS_MD5_ALT) -// Regular implementation -// - #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_MD5_ALT) +// Regular implementation +// + /** * \brief MD5 context structure * @@ -55,7 +56,7 @@ extern "C" { * stronger message digests instead. * */ -typedef struct +typedef struct mbedtls_md5_context { uint32_t total[2]; /*!< number of bytes processed */ uint32_t state[4]; /*!< intermediate digest state */ @@ -63,6 +64,10 @@ typedef struct } mbedtls_md5_context; +#else /* MBEDTLS_MD5_ALT */ +#include "md5_alt.h" +#endif /* MBEDTLS_MD5_ALT */ + /** * \brief Initialize MD5 context * @@ -238,18 +243,6 @@ MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx, #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ -#ifdef __cplusplus -} -#endif - -#else /* MBEDTLS_MD5_ALT */ -#include "md5_alt.h" -#endif /* MBEDTLS_MD5_ALT */ - -#ifdef __cplusplus -extern "C" { -#endif - /** * \brief Output = MD5( input buffer ) * @@ -295,6 +288,8 @@ MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input, #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ +#if defined(MBEDTLS_SELF_TEST) + /** * \brief Checkup routine * @@ -307,6 +302,8 @@ MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input, */ int mbedtls_md5_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/net_sockets.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/net_sockets.h index 52bb8de7c7..4c7ef00fe6 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/net_sockets.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/net_sockets.h @@ -1,7 +1,23 @@ /** * \file net_sockets.h * - * \brief Network communication functions + * \brief Network sockets abstraction layer to integrate Mbed TLS into a + * BSD-style sockets API. + * + * The network sockets module provides an example integration of the + * Mbed TLS library into a BSD sockets implementation. The module is + * intended to be an example of how Mbed TLS can be integrated into a + * networking stack, as well as to be Mbed TLS's network integration + * for its supported platforms. + * + * The module is intended only to be used with the Mbed TLS library and + * is not intended to be used by third party application software + * directly. + * + * The supported platforms are as follows: + * * Microsoft Windows and Windows CE + * * POSIX/Unix platforms including Linux, OS X + * */ /* * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved @@ -46,12 +62,17 @@ #define MBEDTLS_ERR_NET_UNKNOWN_HOST -0x0052 /**< Failed to get an IP address for the given hostname. */ #define MBEDTLS_ERR_NET_BUFFER_TOO_SMALL -0x0043 /**< Buffer is too small to hold the data. */ #define MBEDTLS_ERR_NET_INVALID_CONTEXT -0x0045 /**< The context is invalid, eg because it was free()ed. */ +#define MBEDTLS_ERR_NET_POLL_FAILED -0x0047 /**< Polling the net context failed. */ +#define MBEDTLS_ERR_NET_BAD_INPUT_DATA -0x0049 /**< Input invalid. */ #define MBEDTLS_NET_LISTEN_BACKLOG 10 /**< The backlog that listen() should use. */ #define MBEDTLS_NET_PROTO_TCP 0 /**< The TCP transport protocol */ #define MBEDTLS_NET_PROTO_UDP 1 /**< The UDP transport protocol */ +#define MBEDTLS_NET_POLL_READ 1 /**< Used in \c mbedtls_net_poll to check for pending data */ +#define MBEDTLS_NET_POLL_WRITE 2 /**< Used in \c mbedtls_net_poll to check if write possible */ + #ifdef __cplusplus extern "C" { #endif @@ -63,7 +84,7 @@ extern "C" { * (eg two file descriptors for combined IPv4 + IPv6 support, or additional * structures for hand-made UDP demultiplexing). */ -typedef struct +typedef struct mbedtls_net_context { int fd; /**< The underlying file descriptor */ } @@ -133,6 +154,29 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx, mbedtls_net_context *client_ctx, void *client_ip, size_t buf_size, size_t *ip_len ); +/** + * \brief Check and wait for the context to be ready for read/write + * + * \param ctx Socket to check + * \param rw Bitflag composed of MBEDTLS_NET_POLL_READ and + * MBEDTLS_NET_POLL_WRITE specifying the events + * to wait for: + * - If MBEDTLS_NET_POLL_READ is set, the function + * will return as soon as the net context is available + * for reading. + * - If MBEDTLS_NET_POLL_WRITE is set, the function + * will return as soon as the net context is available + * for writing. + * \param timeout Maximal amount of time to wait before returning, + * in milliseconds. If \c timeout is zero, the + * function returns immediately. If \c timeout is + * -1u, the function blocks potentially indefinitely. + * + * \return Bitmask composed of MBEDTLS_NET_POLL_READ/WRITE + * on success or timeout, or a negative return code otherwise. + */ +int mbedtls_net_poll( mbedtls_net_context *ctx, uint32_t rw, uint32_t timeout ); + /** * \brief Set the socket blocking * diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/nist_kw.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/nist_kw.h new file mode 100644 index 0000000000..3b67b59cd2 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/nist_kw.h @@ -0,0 +1,184 @@ +/** + * \file nist_kw.h + * + * \brief This file provides an API for key wrapping (KW) and key wrapping with + * padding (KWP) as defined in NIST SP 800-38F. + * https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-38F.pdf + * + * Key wrapping specifies a deterministic authenticated-encryption mode + * of operation, according to NIST SP 800-38F: Recommendation for + * Block Cipher Modes of Operation: Methods for Key Wrapping. Its + * purpose is to protect cryptographic keys. + * + * Its equivalent is RFC 3394 for KW, and RFC 5649 for KWP. + * https://tools.ietf.org/html/rfc3394 + * https://tools.ietf.org/html/rfc5649 + * + */ +/* + * Copyright (C) 2018, Arm Limited (or its affiliates), All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of Mbed TLS (https://tls.mbed.org) + */ + +#ifndef MBEDTLS_NIST_KW_H +#define MBEDTLS_NIST_KW_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include "cipher.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum +{ + MBEDTLS_KW_MODE_KW = 0, + MBEDTLS_KW_MODE_KWP = 1 +} mbedtls_nist_kw_mode_t; + +#if !defined(MBEDTLS_NIST_KW_ALT) +// Regular implementation +// + +/** + * \brief The key wrapping context-type definition. The key wrapping context is passed + * to the APIs called. + * + * \note The definition of this type may change in future library versions. + * Don't make any assumptions on this context! + */ +typedef struct { + mbedtls_cipher_context_t cipher_ctx; /*!< The cipher context used. */ +} mbedtls_nist_kw_context; + +#else /* MBEDTLS_NIST_key wrapping_ALT */ +#include "nist_kw_alt.h" +#endif /* MBEDTLS_NIST_KW_ALT */ + +/** + * \brief This function initializes the specified key wrapping context + * to make references valid and prepare the context + * for mbedtls_nist_kw_setkey() or mbedtls_nist_kw_free(). + * + * \param ctx The key wrapping context to initialize. + * + */ +void mbedtls_nist_kw_init( mbedtls_nist_kw_context *ctx ); + +/** + * \brief This function initializes the key wrapping context set in the + * \p ctx parameter and sets the encryption key. + * + * \param ctx The key wrapping context. + * \param cipher The 128-bit block cipher to use. Only AES is supported. + * \param key The Key Encryption Key (KEK). + * \param keybits The KEK size in bits. This must be acceptable by the cipher. + * \param is_wrap Specify whether the operation within the context is wrapping or unwrapping + * + * \return \c 0 on success. + * \return \c MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA for any invalid input. + * \return \c MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE for 128-bit block ciphers + * which are not supported. + * \return cipher-specific error code on failure of the underlying cipher. + */ +int mbedtls_nist_kw_setkey( mbedtls_nist_kw_context *ctx, + mbedtls_cipher_id_t cipher, + const unsigned char *key, + unsigned int keybits, + const int is_wrap ); + +/** + * \brief This function releases and clears the specified key wrapping context + * and underlying cipher sub-context. + * + * \param ctx The key wrapping context to clear. + */ +void mbedtls_nist_kw_free( mbedtls_nist_kw_context *ctx ); + +/** + * \brief This function encrypts a buffer using key wrapping. + * + * \param ctx The key wrapping context to use for encryption. + * \param mode The key wrapping mode to use (MBEDTLS_KW_MODE_KW or MBEDTLS_KW_MODE_KWP) + * \param input The buffer holding the input data. + * \param in_len The length of the input data in Bytes. + * The input uses units of 8 Bytes called semiblocks. + *
  • For KW mode: a multiple of 8 bytes between 16 and 2^57-8 inclusive.
  • + *
  • For KWP mode: any length between 1 and 2^32-1 inclusive.
+ * \param[out] output The buffer holding the output data. + *
  • For KW mode: Must be at least 8 bytes larger than \p in_len.
  • + *
  • For KWP mode: Must be at least 8 bytes larger rounded up to a multiple of + * 8 bytes for KWP (15 bytes at most).
+ * \param[out] out_len The number of bytes written to the output buffer. \c 0 on failure. + * \param[in] out_size The capacity of the output buffer. + * + * \return \c 0 on success. + * \return \c MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA for invalid input length. + * \return cipher-specific error code on failure of the underlying cipher. + */ +int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx, mbedtls_nist_kw_mode_t mode, + const unsigned char *input, size_t in_len, + unsigned char *output, size_t* out_len, size_t out_size ); + +/** + * \brief This function decrypts a buffer using key wrapping. + * + * \param ctx The key wrapping context to use for decryption. + * \param mode The key wrapping mode to use (MBEDTLS_KW_MODE_KW or MBEDTLS_KW_MODE_KWP) + * \param input The buffer holding the input data. + * \param in_len The length of the input data in Bytes. + * The input uses units of 8 Bytes called semiblocks. + * The input must be a multiple of semiblocks. + *
  • For KW mode: a multiple of 8 bytes between 24 and 2^57 inclusive.
  • + *
  • For KWP mode: a multiple of 8 bytes between 16 and 2^32 inclusive.
+ * \param[out] output The buffer holding the output data. + * The output buffer's minimal length is 8 bytes shorter than \p in_len. + * \param[out] out_len The number of bytes written to the output buffer. \c 0 on failure. + * For KWP mode, the length could be up to 15 bytes shorter than \p in_len, + * depending on how much padding was added to the data. + * \param[in] out_size The capacity of the output buffer. + * + * \return \c 0 on success. + * \return \c MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA for invalid input length. + * \return \c MBEDTLS_ERR_CIPHER_AUTH_FAILED for verification failure of the ciphertext. + * \return cipher-specific error code on failure of the underlying cipher. + */ +int mbedtls_nist_kw_unwrap( mbedtls_nist_kw_context *ctx, mbedtls_nist_kw_mode_t mode, + const unsigned char *input, size_t in_len, + unsigned char *output, size_t* out_len, size_t out_size); + + +#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) +/** + * \brief The key wrapping checkup routine. + * + * \return \c 0 on success. + * \return \c 1 on failure. + */ +int mbedtls_nist_kw_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ + +#ifdef __cplusplus +} +#endif + +#endif /* MBEDTLS_NIST_KW_H */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/oid.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/oid.h index 408645ece7..6fbd018aaa 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/oid.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/oid.h @@ -97,6 +97,8 @@ /* ISO arc for standard certificate and CRL extensions */ #define MBEDTLS_OID_ID_CE MBEDTLS_OID_ISO_CCITT_DS "\x1D" /**< id-ce OBJECT IDENTIFIER ::= {joint-iso-ccitt(2) ds(5) 29} */ +#define MBEDTLS_OID_NIST_ALG MBEDTLS_OID_GOV "\x03\x04" /** { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithm(4) */ + /** * Private Internet Extensions * { iso(1) identified-organization(3) dod(6) internet(1) @@ -219,12 +221,12 @@ #define MBEDTLS_OID_DIGEST_ALG_MD4 MBEDTLS_OID_RSA_COMPANY "\x02\x04" /**< id-mbedtls_md4 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 4 } */ #define MBEDTLS_OID_DIGEST_ALG_MD5 MBEDTLS_OID_RSA_COMPANY "\x02\x05" /**< id-mbedtls_md5 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 5 } */ #define MBEDTLS_OID_DIGEST_ALG_SHA1 MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_SHA1 /**< id-mbedtls_sha1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 26 } */ -#define MBEDTLS_OID_DIGEST_ALG_SHA224 MBEDTLS_OID_GOV "\x03\x04\x02\x04" /**< id-sha224 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 4 } */ -#define MBEDTLS_OID_DIGEST_ALG_SHA256 MBEDTLS_OID_GOV "\x03\x04\x02\x01" /**< id-mbedtls_sha256 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 1 } */ +#define MBEDTLS_OID_DIGEST_ALG_SHA224 MBEDTLS_OID_NIST_ALG "\x02\x04" /**< id-sha224 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 4 } */ +#define MBEDTLS_OID_DIGEST_ALG_SHA256 MBEDTLS_OID_NIST_ALG "\x02\x01" /**< id-mbedtls_sha256 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 1 } */ -#define MBEDTLS_OID_DIGEST_ALG_SHA384 MBEDTLS_OID_GOV "\x03\x04\x02\x02" /**< id-sha384 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 2 } */ +#define MBEDTLS_OID_DIGEST_ALG_SHA384 MBEDTLS_OID_NIST_ALG "\x02\x02" /**< id-sha384 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 2 } */ -#define MBEDTLS_OID_DIGEST_ALG_SHA512 MBEDTLS_OID_GOV "\x03\x04\x02\x03" /**< id-mbedtls_sha512 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 3 } */ +#define MBEDTLS_OID_DIGEST_ALG_SHA512 MBEDTLS_OID_NIST_ALG "\x02\x03" /**< id-mbedtls_sha512 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 3 } */ #define MBEDTLS_OID_HMAC_SHA1 MBEDTLS_OID_RSA_COMPANY "\x02\x07" /**< id-hmacWithSHA1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 7 } */ @@ -241,7 +243,20 @@ */ #define MBEDTLS_OID_DES_CBC MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_ALG "\x07" /**< desCBC OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 7 } */ #define MBEDTLS_OID_DES_EDE3_CBC MBEDTLS_OID_RSA_COMPANY "\x03\x07" /**< des-ede3-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2) -- us(840) rsadsi(113549) encryptionAlgorithm(3) 7 } */ +#define MBEDTLS_OID_AES MBEDTLS_OID_NIST_ALG "\x01" /** aes OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithm(4) 1 } */ +/* + * Key Wrapping algorithms + */ +/* + * RFC 5649 + */ +#define MBEDTLS_OID_AES128_KW MBEDTLS_OID_AES "\x05" /** id-aes128-wrap OBJECT IDENTIFIER ::= { aes 5 } */ +#define MBEDTLS_OID_AES128_KWP MBEDTLS_OID_AES "\x08" /** id-aes128-wrap-pad OBJECT IDENTIFIER ::= { aes 8 } */ +#define MBEDTLS_OID_AES192_KW MBEDTLS_OID_AES "\x19" /** id-aes192-wrap OBJECT IDENTIFIER ::= { aes 25 } */ +#define MBEDTLS_OID_AES192_KWP MBEDTLS_OID_AES "\x1c" /** id-aes192-wrap-pad OBJECT IDENTIFIER ::= { aes 28 } */ +#define MBEDTLS_OID_AES256_KW MBEDTLS_OID_AES "\x2d" /** id-aes256-wrap OBJECT IDENTIFIER ::= { aes 45 } */ +#define MBEDTLS_OID_AES256_KWP MBEDTLS_OID_AES "\x30" /** id-aes256-wrap-pad OBJECT IDENTIFIER ::= { aes 48 } */ /* * PKCS#5 OIDs */ @@ -388,7 +403,8 @@ extern "C" { /** * \brief Base OID descriptor structure */ -typedef struct { +typedef struct mbedtls_oid_descriptor_t +{ const char *asn1; /*!< OID ASN.1 representation */ size_t asn1_len; /*!< length of asn1 */ const char *name; /*!< official name (e.g. from RFC) */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/padlock.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/padlock.h index 918e6195ad..721a5d4930 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/padlock.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/padlock.h @@ -3,6 +3,9 @@ * * \brief VIA PadLock ACE for HW encryption/decryption supported by some * processors + * + * \warning These functions are only for internal use by other library + * functions; you must not call them directly. */ /* * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved @@ -56,14 +59,17 @@ #define MBEDTLS_PADLOCK_PHE 0x0C00 #define MBEDTLS_PADLOCK_PMM 0x3000 -#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) x & ~15)) +#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15)) #ifdef __cplusplus extern "C" { #endif /** - * \brief PadLock detection routine + * \brief Internal PadLock detection routine + * + * \note This function is only for internal use by other library + * functions; you must not call it directly. * * \param feature The feature to detect * @@ -72,7 +78,10 @@ extern "C" { int mbedtls_padlock_has_support( int feature ); /** - * \brief PadLock AES-ECB block en(de)cryption + * \brief Internal PadLock AES-ECB block en(de)cryption + * + * \note This function is only for internal use by other library + * functions; you must not call it directly. * * \param ctx AES context * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT @@ -82,12 +91,15 @@ int mbedtls_padlock_has_support( int feature ); * \return 0 if success, 1 if operation failed */ int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx, - int mode, - const unsigned char input[16], - unsigned char output[16] ); + int mode, + const unsigned char input[16], + unsigned char output[16] ); /** - * \brief PadLock AES-CBC buffer en(de)cryption + * \brief Internal PadLock AES-CBC buffer en(de)cryption + * + * \note This function is only for internal use by other library + * functions; you must not call it directly. * * \param ctx AES context * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT @@ -99,11 +111,11 @@ int mbedtls_padlock_xcryptecb( mbedtls_aes_context *ctx, * \return 0 if success, 1 if operation failed */ int mbedtls_padlock_xcryptcbc( mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output ); + int mode, + size_t length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); #ifdef __cplusplus } diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/pem.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/pem.h index 81918503e9..a29e9ce300 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/pem.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/pem.h @@ -57,7 +57,7 @@ extern "C" { /** * \brief PEM context structure */ -typedef struct +typedef struct mbedtls_pem_context { unsigned char *buf; /*!< buffer for decoded data */ size_t buflen; /*!< length of the buffer */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/pk.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/pk.h index ee06b2fd20..91950f9407 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/pk.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/pk.h @@ -64,6 +64,8 @@ #define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00 /**< Elliptic curve is unsupported (only NIST curves are supported). */ #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980 /**< Unavailable feature, e.g. RSA disabled for RSA key. */ #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900 /**< The buffer contains a valid signature followed by more data. */ + +/* MBEDTLS_ERR_PK_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_PK_HW_ACCEL_FAILED -0x3880 /**< PK hardware accelerator failed. */ #ifdef __cplusplus @@ -87,7 +89,7 @@ typedef enum { * \brief Options for RSASSA-PSS signature verification. * See \c mbedtls_rsa_rsassa_pss_verify_ext() */ -typedef struct +typedef struct mbedtls_pk_rsassa_pss_options { mbedtls_md_type_t mgf1_hash_id; int expected_salt_len; @@ -107,7 +109,7 @@ typedef enum /** * \brief Item to send to the debug module */ -typedef struct +typedef struct mbedtls_pk_debug_item { mbedtls_pk_debug_type type; const char *name; @@ -125,12 +127,26 @@ typedef struct mbedtls_pk_info_t mbedtls_pk_info_t; /** * \brief Public key container */ -typedef struct +typedef struct mbedtls_pk_context { - const mbedtls_pk_info_t * pk_info; /**< Public key informations */ + const mbedtls_pk_info_t * pk_info; /**< Public key information */ void * pk_ctx; /**< Underlying public key context */ } mbedtls_pk_context; +#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) +/** + * \brief Context for resuming operations + */ +typedef struct +{ + const mbedtls_pk_info_t * pk_info; /**< Public key information */ + void * rs_ctx; /**< Underlying restart context */ +} mbedtls_pk_restart_ctx; +#else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ +/* Now we can declare functions that take a pointer to that */ +typedef void mbedtls_pk_restart_ctx; +#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ + #if defined(MBEDTLS_RSA_C) /** * Quick access to an RSA context inside a PK context. @@ -181,20 +197,45 @@ typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)( void *ctx ); const mbedtls_pk_info_t *mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type ); /** - * \brief Initialize a mbedtls_pk_context (as NONE) + * \brief Initialize a #mbedtls_pk_context (as NONE). + * + * \param ctx The context to initialize. + * This must not be \c NULL. */ void mbedtls_pk_init( mbedtls_pk_context *ctx ); /** - * \brief Free a mbedtls_pk_context + * \brief Free the components of a #mbedtls_pk_context. + * + * \param ctx The context to clear. It must have been initialized. + * If this is \c NULL, this function does nothing. */ void mbedtls_pk_free( mbedtls_pk_context *ctx ); +#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) +/** + * \brief Initialize a restart context + * + * \param ctx The context to initialize. + * This must not be \c NULL. + */ +void mbedtls_pk_restart_init( mbedtls_pk_restart_ctx *ctx ); + +/** + * \brief Free the components of a restart context + * + * \param ctx The context to clear. It must have been initialized. + * If this is \c NULL, this function does nothing. + */ +void mbedtls_pk_restart_free( mbedtls_pk_restart_ctx *ctx ); +#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ + /** * \brief Initialize a PK context with the information given * and allocates the type-specific PK subcontext. * - * \param ctx Context to initialize. Must be empty (type NONE). + * \param ctx Context to initialize. It must not have been set + * up yet (type #MBEDTLS_PK_NONE). * \param info Information to use * * \return 0 on success, @@ -210,7 +251,8 @@ int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info ); /** * \brief Initialize an RSA-alt context * - * \param ctx Context to initialize. Must be empty (type NONE). + * \param ctx Context to initialize. It must not have been set + * up yet (type #MBEDTLS_PK_NONE). * \param key RSA key pointer * \param decrypt_func Decryption function * \param sign_func Signing function @@ -230,7 +272,7 @@ int mbedtls_pk_setup_rsa_alt( mbedtls_pk_context *ctx, void * key, /** * \brief Get the size in bits of the underlying key * - * \param ctx Context to use + * \param ctx The context to query. It must have been initialized. * * \return Key size in bits, or 0 on error */ @@ -238,7 +280,8 @@ size_t mbedtls_pk_get_bitlen( const mbedtls_pk_context *ctx ); /** * \brief Get the length in bytes of the underlying key - * \param ctx Context to use + * + * \param ctx The context to query. It must have been initialized. * * \return Key length in bytes, or 0 on error */ @@ -250,18 +293,21 @@ static inline size_t mbedtls_pk_get_len( const mbedtls_pk_context *ctx ) /** * \brief Tell if a context can do the operation given by type * - * \param ctx Context to test - * \param type Target type + * \param ctx The context to query. It must have been initialized. + * \param type The desired type. * - * \return 0 if context can't do the operations, - * 1 otherwise. + * \return 1 if the context can do operations on the given type. + * \return 0 if the context cannot do the operations on the given + * type. This is always the case for a context that has + * been initialized but not set up, or that has been + * cleared with mbedtls_pk_free(). */ int mbedtls_pk_can_do( const mbedtls_pk_context *ctx, mbedtls_pk_type_t type ); /** * \brief Verify signature (including padding if relevant). * - * \param ctx PK context to use + * \param ctx The PK context to use. It must have been set up. * \param md_alg Hash algorithm used (see notes) * \param hash Hash of the message to sign * \param hash_len Hash length or 0 (see notes) @@ -286,13 +332,39 @@ int mbedtls_pk_verify( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, const unsigned char *hash, size_t hash_len, const unsigned char *sig, size_t sig_len ); +/** + * \brief Restartable version of \c mbedtls_pk_verify() + * + * \note Performs the same job as \c mbedtls_pk_verify(), but can + * return early and restart according to the limit set with + * \c mbedtls_ecp_set_max_ops() to reduce blocking for ECC + * operations. For RSA, same as \c mbedtls_pk_verify(). + * + * \param ctx The PK context to use. It must have been set up. + * \param md_alg Hash algorithm used (see notes) + * \param hash Hash of the message to sign + * \param hash_len Hash length or 0 (see notes) + * \param sig Signature to verify + * \param sig_len Signature length + * \param rs_ctx Restart context (NULL to disable restart) + * + * \return See \c mbedtls_pk_verify(), or + * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of + * operations was reached: see \c mbedtls_ecp_set_max_ops(). + */ +int mbedtls_pk_verify_restartable( mbedtls_pk_context *ctx, + mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len, + mbedtls_pk_restart_ctx *rs_ctx ); + /** * \brief Verify signature, with options. * (Includes verification of the padding depending on type.) * * \param type Signature type (inc. possible padding type) to verify * \param options Pointer to type-specific options, or NULL - * \param ctx PK context to use + * \param ctx The PK context to use. It must have been set up. * \param md_alg Hash algorithm used (see notes) * \param hash Hash of the message to sign * \param hash_len Hash length or 0 (see notes) @@ -323,7 +395,8 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options, /** * \brief Make signature, including padding if relevant. * - * \param ctx PK context to use - must hold a private key + * \param ctx The PK context to use. It must have been set up + * with a private key. * \param md_alg Hash algorithm used (see notes) * \param hash Hash of the message to sign * \param hash_len Hash length or 0 (see notes) @@ -349,10 +422,41 @@ int mbedtls_pk_sign( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, unsigned char *sig, size_t *sig_len, int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); +/** + * \brief Restartable version of \c mbedtls_pk_sign() + * + * \note Performs the same job as \c mbedtls_pk_sign(), but can + * return early and restart according to the limit set with + * \c mbedtls_ecp_set_max_ops() to reduce blocking for ECC + * operations. For RSA, same as \c mbedtls_pk_sign(). + * + * \param ctx The PK context to use. It must have been set up + * with a private key. + * \param md_alg Hash algorithm used (see notes) + * \param hash Hash of the message to sign + * \param hash_len Hash length or 0 (see notes) + * \param sig Place to write the signature + * \param sig_len Number of bytes written + * \param f_rng RNG function + * \param p_rng RNG parameter + * \param rs_ctx Restart context (NULL to disable restart) + * + * \return See \c mbedtls_pk_sign(), or + * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of + * operations was reached: see \c mbedtls_ecp_set_max_ops(). + */ +int mbedtls_pk_sign_restartable( mbedtls_pk_context *ctx, + mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, + mbedtls_pk_restart_ctx *rs_ctx ); + /** * \brief Decrypt message (including padding if relevant). * - * \param ctx PK context to use - must hold a private key + * \param ctx The PK context to use. It must have been set up + * with a private key. * \param input Input to decrypt * \param ilen Input size * \param output Decrypted output @@ -373,7 +477,7 @@ int mbedtls_pk_decrypt( mbedtls_pk_context *ctx, /** * \brief Encrypt message (including padding if relevant). * - * \param ctx PK context to use + * \param ctx The PK context to use. It must have been set up. * \param input Message to encrypt * \param ilen Message size * \param output Encrypted output @@ -404,7 +508,7 @@ int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, const mbedtls_pk_conte /** * \brief Export debug information * - * \param ctx Context to use + * \param ctx The PK context to use. It must have been initialized. * \param items Place to write debug items * * \return 0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA @@ -414,7 +518,7 @@ int mbedtls_pk_debug( const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *item /** * \brief Access the type name * - * \param ctx Context to use + * \param ctx The PK context to use. It must have been initialized. * * \return Type name on success, or "invalid PK" */ @@ -423,9 +527,10 @@ const char * mbedtls_pk_get_name( const mbedtls_pk_context *ctx ); /** * \brief Get the key type * - * \param ctx Context to use + * \param ctx The PK context to use. It must have been initialized. * - * \return Type on success, or MBEDTLS_PK_NONE + * \return Type on success. + * \return #MBEDTLS_PK_NONE for a context that has not been set up. */ mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx ); @@ -434,12 +539,22 @@ mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx ); /** * \brief Parse a private key in PEM or DER format * - * \param ctx key to be initialized - * \param key input buffer - * \param keylen size of the buffer - * (including the terminating null byte for PEM data) - * \param pwd password for decryption (optional) - * \param pwdlen size of the password + * \param ctx The PK context to fill. It must have been initialized + * but not set up. + * \param key Input buffer to parse. + * The buffer must contain the input exactly, with no + * extra trailing material. For PEM, the buffer must + * contain a null-terminated string. + * \param keylen Size of \b key in bytes. + * For PEM data, this includes the terminating null byte, + * so \p keylen must be equal to `strlen(key) + 1`. + * \param pwd Optional password for decryption. + * Pass \c NULL if expecting a non-encrypted key. + * Pass a string of \p pwdlen bytes if expecting an encrypted + * key; a non-encrypted key will also be accepted. + * The empty password is not supported. + * \param pwdlen Size of the password in bytes. + * Ignored if \p pwd is \c NULL. * * \note On entry, ctx must be empty, either freshly initialised * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a @@ -457,10 +572,15 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *ctx, /** * \brief Parse a public key in PEM or DER format * - * \param ctx key to be initialized - * \param key input buffer - * \param keylen size of the buffer - * (including the terminating null byte for PEM data) + * \param ctx The PK context to fill. It must have been initialized + * but not set up. + * \param key Input buffer to parse. + * The buffer must contain the input exactly, with no + * extra trailing material. For PEM, the buffer must + * contain a null-terminated string. + * \param keylen Size of \b key in bytes. + * For PEM data, this includes the terminating null byte, + * so \p keylen must be equal to `strlen(key) + 1`. * * \note On entry, ctx must be empty, either freshly initialised * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a @@ -478,9 +598,14 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx, /** * \brief Load and parse a private key * - * \param ctx key to be initialized + * \param ctx The PK context to fill. It must have been initialized + * but not set up. * \param path filename to read the private key from - * \param password password to decrypt the file (can be NULL) + * \param password Optional password to decrypt the file. + * Pass \c NULL if expecting a non-encrypted key. + * Pass a null-terminated string if expecting an encrypted + * key; a non-encrypted key will also be accepted. + * The empty password is not supported. * * \note On entry, ctx must be empty, either freshly initialised * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a @@ -497,7 +622,8 @@ int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx, /** * \brief Load and parse a public key * - * \param ctx key to be initialized + * \param ctx The PK context to fill. It must have been initialized + * but not set up. * \param path filename to read the public key from * * \note On entry, ctx must be empty, either freshly initialised @@ -520,7 +646,7 @@ int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path ) * return value to determine where you should start * using the buffer * - * \param ctx private to write away + * \param ctx PK context which must contain a valid private key. * \param buf buffer to write to * \param size size of the buffer * @@ -535,7 +661,7 @@ int mbedtls_pk_write_key_der( mbedtls_pk_context *ctx, unsigned char *buf, size_ * return value to determine where you should start * using the buffer * - * \param ctx public key to write away + * \param ctx PK context which must contain a valid public or private key. * \param buf buffer to write to * \param size size of the buffer * @@ -548,9 +674,10 @@ int mbedtls_pk_write_pubkey_der( mbedtls_pk_context *ctx, unsigned char *buf, si /** * \brief Write a public key to a PEM string * - * \param ctx public key to write away - * \param buf buffer to write to - * \param size size of the buffer + * \param ctx PK context which must contain a valid public or private key. + * \param buf Buffer to write to. The output includes a + * terminating null byte. + * \param size Size of the buffer in bytes. * * \return 0 if successful, or a specific error code */ @@ -559,9 +686,10 @@ int mbedtls_pk_write_pubkey_pem( mbedtls_pk_context *ctx, unsigned char *buf, si /** * \brief Write a private key to a PKCS#1 or SEC1 PEM string * - * \param ctx private to write away - * \param buf buffer to write to - * \param size size of the buffer + * \param ctx PK context which must contain a valid private key. + * \param buf Buffer to write to. The output includes a + * terminating null byte. + * \param size Size of the buffer in bytes. * * \return 0 if successful, or a specific error code */ @@ -580,7 +708,8 @@ int mbedtls_pk_write_key_pem( mbedtls_pk_context *ctx, unsigned char *buf, size_ * * \param p the position in the ASN.1 data * \param end end of the buffer - * \param pk the key to fill + * \param pk The PK context to fill. It must have been initialized + * but not set up. * * \return 0 if successful, or a specific PK error code */ @@ -595,7 +724,7 @@ int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end, * * \param p reference to current position pointer * \param start start of the buffer (for bounds-checking) - * \param key public key to write away + * \param key PK context which must contain a valid public or private key. * * \return the length written or a negative error code */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/pk_internal.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/pk_internal.h index 3dae0fc5b2..48b7a5f7bf 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/pk_internal.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/pk_internal.h @@ -59,6 +59,21 @@ struct mbedtls_pk_info_t int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); +#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) + /** Verify signature (restartable) */ + int (*verify_rs_func)( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len, + void *rs_ctx ); + + /** Make signature (restartable) */ + int (*sign_rs_func)( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, void *rs_ctx ); +#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ + /** Decrypt message */ int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen, size_t osize, @@ -80,6 +95,14 @@ struct mbedtls_pk_info_t /** Free the given context */ void (*ctx_free_func)( void *ctx ); +#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) + /** Allocate the restart context */ + void * (*rs_alloc_func)( void ); + + /** Free the restart context */ + void (*rs_free_func)( void *rs_ctx ); +#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ + /** Interface with the debug module */ void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items ); diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs11.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs11.h index bf65c55a79..02427ddc1e 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs11.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs11.h @@ -50,7 +50,8 @@ extern "C" { /** * Context for PKCS #11 private keys. */ -typedef struct { +typedef struct mbedtls_pkcs11_context +{ pkcs11h_certificate_t pkcs11h_cert; int len; } mbedtls_pkcs11_context; diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs5.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs5.h index f201250046..c92185f7a6 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs5.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/pkcs5.h @@ -91,6 +91,8 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p unsigned int iteration_count, uint32_t key_length, unsigned char *output ); +#if defined(MBEDTLS_SELF_TEST) + /** * \brief Checkup routine * @@ -98,6 +100,8 @@ int mbedtls_pkcs5_pbkdf2_hmac( mbedtls_md_context_t *ctx, const unsigned char *p */ int mbedtls_pkcs5_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/platform.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/platform.h index 7c2835b305..89fe8a7b19 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/platform.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/platform.h @@ -1,7 +1,16 @@ /** * \file platform.h * - * \brief The Mbed TLS platform abstraction layer. + * \brief This file contains the definitions and functions of the + * Mbed TLS platform abstraction layer. + * + * The platform abstraction layer removes the need for the library + * to directly link to standard C library functions or operating + * system services, making the library easier to port and embed. + * Application developers and users of the library can provide their own + * implementations of these functions, or implementations specific to + * their platform, which can be statically linked to the library or + * dynamically configured at runtime. */ /* * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved @@ -34,6 +43,9 @@ #include "platform_time.h" #endif +#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware accelerator failed */ +#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072 /**< The requested feature is not supported by the platform */ + #ifdef __cplusplus extern "C" { #endif @@ -102,7 +114,7 @@ extern "C" { /* \} name SECTION: Module settings */ /* - * The function pointers for calloc and free + * The function pointers for calloc and free. */ #if defined(MBEDTLS_PLATFORM_MEMORY) #if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \ @@ -112,11 +124,12 @@ extern "C" { #else /* For size_t */ #include -extern void * (*mbedtls_calloc)( size_t n, size_t size ); -extern void (*mbedtls_free)( void *ptr ); +extern void *mbedtls_calloc( size_t n, size_t size ); +extern void mbedtls_free( void *ptr ); /** - * \brief This function allows configuring custom memory-management functions. + * \brief This function dynamically sets the memory-management + * functions used by the library, during runtime. * * \param calloc_func The \c calloc function implementation. * \param free_func The \c free function implementation. @@ -140,7 +153,9 @@ int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ), extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... ); /** - * \brief This function allows configuring a custom \p fprintf function pointer. + * \brief This function dynamically configures the fprintf + * function that is called when the + * mbedtls_fprintf() function is invoked by the library. * * \param fprintf_func The \c fprintf function implementation. * @@ -163,8 +178,9 @@ int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char extern int (*mbedtls_printf)( const char *format, ... ); /** - * \brief This function allows configuring a custom \c printf function - * pointer. + * \brief This function dynamically configures the snprintf + * function that is called when the mbedtls_snprintf() + * function is invoked by the library. * * \param printf_func The \c printf function implementation. * @@ -197,12 +213,12 @@ int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... ); extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... ); /** - * \brief This function allows configuring a custom \c snprintf function - * pointer. + * \brief This function allows configuring a custom + * \c snprintf function pointer. * * \param snprintf_func The \c snprintf function implementation. * - * \return \c 0 on success. + * \return \c 0 on success. */ int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n, const char * format, ... ) ); @@ -221,12 +237,13 @@ int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n, extern void (*mbedtls_exit)( int status ); /** - * \brief This function allows configuring a custom \c exit function - * pointer. + * \brief This function dynamically configures the exit + * function that is called when the mbedtls_exit() + * function is invoked by the library. * * \param exit_func The \c exit function implementation. * - * \return \c 0 on success. + * \return \c 0 on success. */ int mbedtls_platform_set_exit( void (*exit_func)( int status ) ); #else @@ -301,8 +318,9 @@ int mbedtls_platform_set_nv_seed( * \note This structure may be used to assist platform-specific * setup or teardown operations. */ -typedef struct { - char dummy; /**< Placeholder member, as empty structs are not portable. */ +typedef struct mbedtls_platform_context +{ + char dummy; /**< A placeholder member, as empty structs are not portable. */ } mbedtls_platform_context; @@ -311,33 +329,34 @@ mbedtls_platform_context; #endif /* !MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT */ /** - * \brief This function performs any platform initialization operations. + * \brief This function performs any platform-specific initialization + * operations. * - * \param ctx The Mbed TLS context. + * \note This function should be called before any other library functions. * - * \return \c 0 on success. - * - * \note This function is intended to allow platform-specific initialization, - * and should be called before any other library functions. Its - * implementation is platform-specific, and unless + * Its implementation is platform-specific, and unless * platform-specific code is provided, it does nothing. * - * Its use and whether it is necessary to call it is dependent on the - * platform. + * \note The usage and necessity of this function is dependent on the platform. + * + * \param ctx The platform context. + * + * \return \c 0 on success. */ int mbedtls_platform_setup( mbedtls_platform_context *ctx ); /** * \brief This function performs any platform teardown operations. * - * \param ctx The Mbed TLS context. - * * \note This function should be called after every other Mbed TLS module * has been correctly freed using the appropriate free function. + * * Its implementation is platform-specific, and unless * platform-specific code is provided, it does nothing. * - * Its use and whether it is necessary to call it is dependent on the - * platform. + * \note The usage and necessity of this function is dependent on the platform. + * + * \param ctx The platform context. + * */ void mbedtls_platform_teardown( mbedtls_platform_context *ctx ); diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/platform_util.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/platform_util.h new file mode 100644 index 0000000000..dba6d45982 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/platform_util.h @@ -0,0 +1,185 @@ +/** + * \file platform_util.h + * + * \brief Common and shared functions used by multiple modules in the Mbed TLS + * library. + */ +/* + * Copyright (C) 2018, Arm Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of Mbed TLS (https://tls.mbed.org) + */ +#ifndef MBEDTLS_PLATFORM_UTIL_H +#define MBEDTLS_PLATFORM_UTIL_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include +#if defined(MBEDTLS_HAVE_TIME_DATE) +#include "platform_time.h" +#include +#endif /* MBEDTLS_HAVE_TIME_DATE */ + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(MBEDTLS_CHECK_PARAMS) + +#if defined(MBEDTLS_PARAM_FAILED) +/** An alternative definition of MBEDTLS_PARAM_FAILED has been set in config.h. + * + * This flag can be used to check whether it is safe to assume that + * MBEDTLS_PARAM_FAILED() will expand to a call to mbedtls_param_failed(). + */ +#define MBEDTLS_PARAM_FAILED_ALT +#else /* MBEDTLS_PARAM_FAILED */ +#define MBEDTLS_PARAM_FAILED( cond ) \ + mbedtls_param_failed( #cond, __FILE__, __LINE__ ) + +/** + * \brief User supplied callback function for parameter validation failure. + * See #MBEDTLS_CHECK_PARAMS for context. + * + * This function will be called unless an alternative treatement + * is defined through the #MBEDTLS_PARAM_FAILED macro. + * + * This function can return, and the operation will be aborted, or + * alternatively, through use of setjmp()/longjmp() can resume + * execution in the application code. + * + * \param failure_condition The assertion that didn't hold. + * \param file The file where the assertion failed. + * \param line The line in the file where the assertion failed. + */ +void mbedtls_param_failed( const char *failure_condition, + const char *file, + int line ); +#endif /* MBEDTLS_PARAM_FAILED */ + +/* Internal macro meant to be called only from within the library. */ +#define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) \ + do { \ + if( !(cond) ) \ + { \ + MBEDTLS_PARAM_FAILED( cond ); \ + return( ret ); \ + } \ + } while( 0 ) + +/* Internal macro meant to be called only from within the library. */ +#define MBEDTLS_INTERNAL_VALIDATE( cond ) \ + do { \ + if( !(cond) ) \ + { \ + MBEDTLS_PARAM_FAILED( cond ); \ + return; \ + } \ + } while( 0 ) + +#else /* MBEDTLS_CHECK_PARAMS */ + +/* Internal macros meant to be called only from within the library. */ +#define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) do { } while( 0 ) +#define MBEDTLS_INTERNAL_VALIDATE( cond ) do { } while( 0 ) + +#endif /* MBEDTLS_CHECK_PARAMS */ + +/* Internal helper macros for deprecating API constants. */ +#if !defined(MBEDTLS_DEPRECATED_REMOVED) +#if defined(MBEDTLS_DEPRECATED_WARNING) +/* Deliberately don't (yet) export MBEDTLS_DEPRECATED here + * to avoid conflict with other headers which define and use + * it, too. We might want to move all these definitions here at + * some point for uniformity. */ +#define MBEDTLS_DEPRECATED __attribute__((deprecated)) +MBEDTLS_DEPRECATED typedef char const * mbedtls_deprecated_string_constant_t; +#define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) \ + ( (mbedtls_deprecated_string_constant_t) ( VAL ) ) +MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t; +#define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) \ + ( (mbedtls_deprecated_numeric_constant_t) ( VAL ) ) +#undef MBEDTLS_DEPRECATED +#else /* MBEDTLS_DEPRECATED_WARNING */ +#define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) VAL +#define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) VAL +#endif /* MBEDTLS_DEPRECATED_WARNING */ +#endif /* MBEDTLS_DEPRECATED_REMOVED */ + +/** + * \brief Securely zeroize a buffer + * + * The function is meant to wipe the data contained in a buffer so + * that it can no longer be recovered even if the program memory + * is later compromised. Call this function on sensitive data + * stored on the stack before returning from a function, and on + * sensitive data stored on the heap before freeing the heap + * object. + * + * It is extremely difficult to guarantee that calls to + * mbedtls_platform_zeroize() are not removed by aggressive + * compiler optimizations in a portable way. For this reason, Mbed + * TLS provides the configuration option + * MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure + * mbedtls_platform_zeroize() to use a suitable implementation for + * their platform and needs + * + * \param buf Buffer to be zeroized + * \param len Length of the buffer in bytes + * + */ +void mbedtls_platform_zeroize( void *buf, size_t len ); + +#if defined(MBEDTLS_HAVE_TIME_DATE) +/** + * \brief Platform-specific implementation of gmtime_r() + * + * The function is a thread-safe abstraction that behaves + * similarly to the gmtime_r() function from Unix/POSIX. + * + * Mbed TLS will try to identify the underlying platform and + * make use of an appropriate underlying implementation (e.g. + * gmtime_r() for POSIX and gmtime_s() for Windows). If this is + * not possible, then gmtime() will be used. In this case, calls + * from the library to gmtime() will be guarded by the mutex + * mbedtls_threading_gmtime_mutex if MBEDTLS_THREADING_C is + * enabled. It is recommended that calls from outside the library + * are also guarded by this mutex. + * + * If MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, then Mbed TLS will + * unconditionally use the alternative implementation for + * mbedtls_platform_gmtime_r() supplied by the user at compile time. + * + * \param tt Pointer to an object containing time (in seconds) since the + * epoch to be converted + * \param tm_buf Pointer to an object where the results will be stored + * + * \return Pointer to an object of type struct tm on success, otherwise + * NULL + */ +struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt, + struct tm *tm_buf ); +#endif /* MBEDTLS_HAVE_TIME_DATE */ + +#ifdef __cplusplus +} +#endif + +#endif /* MBEDTLS_PLATFORM_UTIL_H */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/poly1305.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/poly1305.h new file mode 100644 index 0000000000..f0ec44c968 --- /dev/null +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/poly1305.h @@ -0,0 +1,192 @@ +/** + * \file poly1305.h + * + * \brief This file contains Poly1305 definitions and functions. + * + * Poly1305 is a one-time message authenticator that can be used to + * authenticate messages. Poly1305-AES was created by Daniel + * Bernstein https://cr.yp.to/mac/poly1305-20050329.pdf The generic + * Poly1305 algorithm (not tied to AES) was also standardized in RFC + * 7539. + * + * \author Daniel King + */ + +/* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This file is part of Mbed TLS (https://tls.mbed.org) + */ + +#ifndef MBEDTLS_POLY1305_H +#define MBEDTLS_POLY1305_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +#include +#include + +#define MBEDTLS_ERR_POLY1305_BAD_INPUT_DATA -0x0057 /**< Invalid input parameter(s). */ + +/* MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE is deprecated and should not be + * used. */ +#define MBEDTLS_ERR_POLY1305_FEATURE_UNAVAILABLE -0x0059 /**< Feature not available. For example, s part of the API is not implemented. */ + +/* MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED is deprecated and should not be used. + */ +#define MBEDTLS_ERR_POLY1305_HW_ACCEL_FAILED -0x005B /**< Poly1305 hardware accelerator failed. */ + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(MBEDTLS_POLY1305_ALT) + +typedef struct mbedtls_poly1305_context +{ + uint32_t r[4]; /** The value for 'r' (low 128 bits of the key). */ + uint32_t s[4]; /** The value for 's' (high 128 bits of the key). */ + uint32_t acc[5]; /** The accumulator number. */ + uint8_t queue[16]; /** The current partial block of data. */ + size_t queue_len; /** The number of bytes stored in 'queue'. */ +} +mbedtls_poly1305_context; + +#else /* MBEDTLS_POLY1305_ALT */ +#include "poly1305_alt.h" +#endif /* MBEDTLS_POLY1305_ALT */ + +/** + * \brief This function initializes the specified Poly1305 context. + * + * It must be the first API called before using + * the context. + * + * It is usually followed by a call to + * \c mbedtls_poly1305_starts(), then one or more calls to + * \c mbedtls_poly1305_update(), then one call to + * \c mbedtls_poly1305_finish(), then finally + * \c mbedtls_poly1305_free(). + * + * \param ctx The Poly1305 context to initialize. This must + * not be \c NULL. + */ +void mbedtls_poly1305_init( mbedtls_poly1305_context *ctx ); + +/** + * \brief This function releases and clears the specified + * Poly1305 context. + * + * \param ctx The Poly1305 context to clear. This may be \c NULL, in which + * case this function is a no-op. If it is not \c NULL, it must + * point to an initialized Poly1305 context. + */ +void mbedtls_poly1305_free( mbedtls_poly1305_context *ctx ); + +/** + * \brief This function sets the one-time authentication key. + * + * \warning The key must be unique and unpredictable for each + * invocation of Poly1305. + * + * \param ctx The Poly1305 context to which the key should be bound. + * This must be initialized. + * \param key The buffer containing the \c 32 Byte (\c 256 Bit) key. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_poly1305_starts( mbedtls_poly1305_context *ctx, + const unsigned char key[32] ); + +/** + * \brief This functions feeds an input buffer into an ongoing + * Poly1305 computation. + * + * It is called between \c mbedtls_cipher_poly1305_starts() and + * \c mbedtls_cipher_poly1305_finish(). + * It can be called repeatedly to process a stream of data. + * + * \param ctx The Poly1305 context to use for the Poly1305 operation. + * This must be initialized and bound to a key. + * \param ilen The length of the input data in Bytes. + * Any value is accepted. + * \param input The buffer holding the input data. + * This pointer can be \c NULL if `ilen == 0`. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx, + const unsigned char *input, + size_t ilen ); + +/** + * \brief This function generates the Poly1305 Message + * Authentication Code (MAC). + * + * \param ctx The Poly1305 context to use for the Poly1305 operation. + * This must be initialized and bound to a key. + * \param mac The buffer to where the MAC is written. This must + * be a writable buffer of length \c 16 Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx, + unsigned char mac[16] ); + +/** + * \brief This function calculates the Poly1305 MAC of the input + * buffer with the provided key. + * + * \warning The key must be unique and unpredictable for each + * invocation of Poly1305. + * + * \param key The buffer containing the \c 32 Byte (\c 256 Bit) key. + * \param ilen The length of the input data in Bytes. + * Any value is accepted. + * \param input The buffer holding the input data. + * This pointer can be \c NULL if `ilen == 0`. + * \param mac The buffer to where the MAC is written. This must be + * a writable buffer of length \c 16 Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_poly1305_mac( const unsigned char key[32], + const unsigned char *input, + size_t ilen, + unsigned char mac[16] ); + +#if defined(MBEDTLS_SELF_TEST) +/** + * \brief The Poly1305 checkup routine. + * + * \return \c 0 on success. + * \return \c 1 on failure. + */ +int mbedtls_poly1305_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + +#ifdef __cplusplus +} +#endif + +#endif /* MBEDTLS_POLY1305_H */ diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/ripemd160.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/ripemd160.h index 3a8b50a621..b42f6d2a95 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/ripemd160.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/ripemd160.h @@ -33,20 +33,22 @@ #include #include +/* MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED is deprecated and should not be used. + */ #define MBEDTLS_ERR_RIPEMD160_HW_ACCEL_FAILED -0x0031 /**< RIPEMD160 hardware accelerator failed */ -#if !defined(MBEDTLS_RIPEMD160_ALT) -// Regular implementation -// - #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_RIPEMD160_ALT) +// Regular implementation +// + /** * \brief RIPEMD-160 context structure */ -typedef struct +typedef struct mbedtls_ripemd160_context { uint32_t total[2]; /*!< number of bytes processed */ uint32_t state[5]; /*!< intermediate digest state */ @@ -54,6 +56,10 @@ typedef struct } mbedtls_ripemd160_context; +#else /* MBEDTLS_RIPEMD160_ALT */ +#include "ripemd160.h" +#endif /* MBEDTLS_RIPEMD160_ALT */ + /** * \brief Initialize RIPEMD-160 context * @@ -178,18 +184,6 @@ MBEDTLS_DEPRECATED void mbedtls_ripemd160_process( #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ -#ifdef __cplusplus -} -#endif - -#else /* MBEDTLS_RIPEMD160_ALT */ -#include "ripemd160_alt.h" -#endif /* MBEDTLS_RIPEMD160_ALT */ - -#ifdef __cplusplus -extern "C" { -#endif - /** * \brief Output = RIPEMD-160( input buffer ) * @@ -225,6 +219,8 @@ MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input, #undef MBEDTLS_DEPRECATED #endif /* !MBEDTLS_DEPRECATED_REMOVED */ +#if defined(MBEDTLS_SELF_TEST) + /** * \brief Checkup routine * @@ -232,6 +228,8 @@ MBEDTLS_DEPRECATED void mbedtls_ripemd160( const unsigned char *input, */ int mbedtls_ripemd160_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/mbedtls/mbedtls/include/mbedtls/rsa.h b/3rdparty/mbedtls/mbedtls/include/mbedtls/rsa.h index 5548f3c127..906c427332 100644 --- a/3rdparty/mbedtls/mbedtls/include/mbedtls/rsa.h +++ b/3rdparty/mbedtls/mbedtls/include/mbedtls/rsa.h @@ -1,11 +1,12 @@ /** * \file rsa.h * - * \brief The RSA public-key cryptosystem. + * \brief This file provides an API for the RSA public-key cryptosystem. * - * For more information, see Public-Key Cryptography Standards (PKCS) - * #1 v1.5: RSA Encryption and Public-Key Cryptography Standards - * (PKCS) #1 v2.1: RSA Cryptography Specifications. + * The RSA public-key cryptosystem is defined in Public-Key + * Cryptography Standards (PKCS) #1 v1.5: RSA Encryption + * and Public-Key Cryptography Standards (PKCS) #1 v2.1: + * RSA Cryptography Specifications. * */ /* @@ -54,7 +55,12 @@ #define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380 /**< The PKCS#1 verification failed. */ #define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400 /**< The output buffer for decryption is not large enough. */ #define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480 /**< The random generator failed to generate non-zeros. */ + +/* MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION is deprecated and should not be used. + */ #define MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION -0x4500 /**< The implementation does not offer the requested operation, for example, because of security violations or lack of functionality. */ + +/* MBEDTLS_ERR_RSA_HW_ACCEL_FAILED is deprecated and should not be used. */ #define MBEDTLS_ERR_RSA_HW_ACCEL_FAILED -0x4580 /**< RSA hardware accelerator failed. */ /* @@ -63,8 +69,8 @@ #define MBEDTLS_RSA_PUBLIC 0 /**< Request private key operation. */ #define MBEDTLS_RSA_PRIVATE 1 /**< Request public key operation. */ -#define MBEDTLS_RSA_PKCS_V15 0 /**< Use PKCS-1 v1.5 encoding. */ -#define MBEDTLS_RSA_PKCS_V21 1 /**< Use PKCS-1 v2.1 encoding. */ +#define MBEDTLS_RSA_PKCS_V15 0 /**< Use PKCS#1 v1.5 encoding. */ +#define MBEDTLS_RSA_PKCS_V21 1 /**< Use PKCS#1 v2.1 encoding. */ #define MBEDTLS_RSA_SIGN 1 /**< Identifier for RSA signature operations. */ #define MBEDTLS_RSA_CRYPT 2 /**< Identifier for RSA encryption and decryption operations. */ @@ -76,14 +82,14 @@ * eg for alternative (PKCS#11) RSA implemenations in the PK layers. */ -#if !defined(MBEDTLS_RSA_ALT) -// Regular implementation -// - #ifdef __cplusplus extern "C" { #endif +#if !defined(MBEDTLS_RSA_ALT) +// Regular implementation +// + /** * \brief The RSA context structure. * @@ -91,29 +97,29 @@ extern "C" { * is deprecated. All manipulation should instead be done through * the public interface functions. */ -typedef struct +typedef struct mbedtls_rsa_context { int ver; /*!< Always 0.*/ size_t len; /*!< The size of \p N in Bytes. */ - mbedtls_mpi N; /*!< The public modulus. */ - mbedtls_mpi E; /*!< The public exponent. */ + mbedtls_mpi N; /*!< The public modulus. */ + mbedtls_mpi E; /*!< The public exponent. */ - mbedtls_mpi D; /*!< The private exponent. */ - mbedtls_mpi P; /*!< The first prime factor. */ - mbedtls_mpi Q; /*!< The second prime factor. */ + mbedtls_mpi D; /*!< The private exponent. */ + mbedtls_mpi P; /*!< The first prime factor. */ + mbedtls_mpi Q; /*!< The second prime factor. */ - mbedtls_mpi DP; /*!< \p D % (P - 1) */ - mbedtls_mpi DQ; /*!< \p D % (Q - 1) */ - mbedtls_mpi QP; /*!< 1 / (Q % P) */ + mbedtls_mpi DP; /*!< D % (P - 1). */ + mbedtls_mpi DQ; /*!< D % (Q - 1). */ + mbedtls_mpi QP; /*!< 1 / (Q % P). */ - mbedtls_mpi RN; /*!< cached R^2 mod \p N */ + mbedtls_mpi RN; /*!< cached R^2 mod N. */ - mbedtls_mpi RP; /*!< cached R^2 mod \p P */ - mbedtls_mpi RQ; /*!< cached R^2 mod \p Q */ + mbedtls_mpi RP; /*!< cached R^2 mod P. */ + mbedtls_mpi RQ; /*!< cached R^2 mod Q. */ - mbedtls_mpi Vi; /*!< The cached blinding value. */ - mbedtls_mpi Vf; /*!< The cached un-blinding value. */ + mbedtls_mpi Vi; /*!< The cached blinding value. */ + mbedtls_mpi Vf; /*!< The cached un-blinding value. */ int padding; /*!< Selects padding mode: #MBEDTLS_RSA_PKCS_V15 for 1.5 padding and @@ -128,18 +134,16 @@ typedef struct } mbedtls_rsa_context; +#else /* MBEDTLS_RSA_ALT */ +#include "rsa_alt.h" +#endif /* MBEDTLS_RSA_ALT */ + /** * \brief This function initializes an RSA context. * * \note Set padding to #MBEDTLS_RSA_PKCS_V21 for the RSAES-OAEP * encryption scheme and the RSASSA-PSS signature scheme. * - * \param ctx The RSA context to initialize. - * \param padding Selects padding mode: #MBEDTLS_RSA_PKCS_V15 or - * #MBEDTLS_RSA_PKCS_V21. - * \param hash_id The hash identifier of #mbedtls_md_type_t type, if - * \p padding is #MBEDTLS_RSA_PKCS_V21. - * * \note The \p hash_id parameter is ignored when using * #MBEDTLS_RSA_PKCS_V15 padding. * @@ -153,22 +157,22 @@ mbedtls_rsa_context; * encryption. For PSS signatures, it is always used for * making signatures, but can be overriden for verifying them. * If set to #MBEDTLS_MD_NONE, it is always overriden. + * + * \param ctx The RSA context to initialize. This must not be \c NULL. + * \param padding The padding mode to use. This must be either + * #MBEDTLS_RSA_PKCS_V15 or #MBEDTLS_RSA_PKCS_V21. + * \param hash_id The hash identifier of ::mbedtls_md_type_t type, if + * \p padding is #MBEDTLS_RSA_PKCS_V21. It is unused + * otherwise. */ void mbedtls_rsa_init( mbedtls_rsa_context *ctx, int padding, - int hash_id); + int hash_id ); /** * \brief This function imports a set of core parameters into an * RSA context. * - * \param ctx The initialized RSA context to store the parameters in. - * \param N The RSA modulus, or NULL. - * \param P The first prime factor of \p N, or NULL. - * \param Q The second prime factor of \p N, or NULL. - * \param D The private exponent, or NULL. - * \param E The public exponent, or NULL. - * * \note This function can be called multiple times for successive * imports, if the parameters are not simultaneously present. * @@ -184,7 +188,15 @@ void mbedtls_rsa_init( mbedtls_rsa_context *ctx, * \note The imported parameters are copied and need not be preserved * for the lifetime of the RSA context being set up. * - * \return \c 0 on success, or a non-zero error code on failure. + * \param ctx The initialized RSA context to store the parameters in. + * \param N The RSA modulus. This may be \c NULL. + * \param P The first prime factor of \p N. This may be \c NULL. + * \param Q The second prime factor of \p N. This may be \c NULL. + * \param D The private exponent. This may be \c NULL. + * \param E The public exponent. This may be \c NULL. + * + * \return \c 0 on success. + * \return A non-zero error code on failure. */ int mbedtls_rsa_import( mbedtls_rsa_context *ctx, const mbedtls_mpi *N, @@ -195,18 +207,6 @@ int mbedtls_rsa_import( mbedtls_rsa_context *ctx, * \brief This function imports core RSA parameters, in raw big-endian * binary format, into an RSA context. * - * \param ctx The initialized RSA context to store the parameters in. - * \param N The RSA modulus, or NULL. - * \param N_len The Byte length of \p N, ignored if \p N == NULL. - * \param P The first prime factor of \p N, or NULL. - * \param P_len The Byte length of \p P, ignored if \p P == NULL. - * \param Q The second prime factor of \p N, or NULL. - * \param Q_len The Byte length of \p Q, ignored if \p Q == NULL. - * \param D The private exponent, or NULL. - * \param D_len The Byte length of \p D, ignored if \p D == NULL. - * \param E The public exponent, or NULL. - * \param E_len The Byte length of \p E, ignored if \p E == NULL. - * * \note This function can be called multiple times for successive * imports, if the parameters are not simultaneously present. * @@ -222,7 +222,20 @@ int mbedtls_rsa_import( mbedtls_rsa_context *ctx, * \note The imported parameters are copied and need not be preserved * for the lifetime of the RSA context being set up. * - * \return \c 0 on success, or a non-zero error code on failure. + * \param ctx The initialized RSA context to store the parameters in. + * \param N The RSA modulus. This may be \c NULL. + * \param N_len The Byte length of \p N; it is ignored if \p N == NULL. + * \param P The first prime factor of \p N. This may be \c NULL. + * \param P_len The Byte length of \p P; it ns ignored if \p P == NULL. + * \param Q The second prime factor of \p N. This may be \c NULL. + * \param Q_len The Byte length of \p Q; it is ignored if \p Q == NULL. + * \param D The private exponent. This may be \c NULL. + * \param D_len The Byte length of \p D; it is ignored if \p D == NULL. + * \param E The public exponent. This may be \c NULL. + * \param E_len The Byte length of \p E; it is ignored if \p E == NULL. + * + * \return \c 0 on success. + * \return A non-zero error code on failure. */ int mbedtls_rsa_import_raw( mbedtls_rsa_context *ctx, unsigned char const *N, size_t N_len, @@ -250,17 +263,18 @@ int mbedtls_rsa_import_raw( mbedtls_rsa_context *ctx, * the RSA context can be used for RSA operations without * the risk of failure or crash. * - * \param ctx The initialized RSA context holding imported parameters. - * - * \return \c 0 on success, or #MBEDTLS_ERR_RSA_BAD_INPUT_DATA if the - * attempted derivations failed. - * * \warning This function need not perform consistency checks * for the imported parameters. In particular, parameters that * are not needed by the implementation might be silently * discarded and left unchecked. To check the consistency * of the key material, see mbedtls_rsa_check_privkey(). * + * \param ctx The initialized RSA context holding imported parameters. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_RSA_BAD_INPUT_DATA if the attempted derivations + * failed. + * */ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx ); @@ -273,7 +287,7 @@ int mbedtls_rsa_complete( mbedtls_rsa_context *ctx ); * zero Bytes. * * Possible reasons for returning - * #MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION: