-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapt SHA256 dependency in generate_pkcs7_tests.py #46
Closed
ronald-cron-arm
wants to merge
2
commits into
Mbed-TLS:main
from
ronald-cron-arm:adapt-generate-pkcs7-tests
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
import sys | ||
from typing import Iterable, List, Optional | ||
|
||
from . import build_tree | ||
from . import psa_information | ||
from . import typing_util | ||
|
||
def hex_string(data: bytes) -> str: | ||
|
@@ -89,3 +91,33 @@ def write_data_file(filename: str, | |
tc.write(out) | ||
out.write('\n# End of automatically generated file.\n') | ||
os.replace(tempfile, filename) | ||
|
||
def hash_dependency_symbol(psa_hash_alg: str) -> str: | ||
"""Get the dependency symbol for an hash algorithm when the algorithm | ||
support is needed by legacy or USE_PSA_CRYPTO domain code. | ||
|
||
The function should be used only for dependencies of legacy or | ||
USE_PSA_CRYPTO domain code. Otherwise, just use the PSA_WANT_ prefixed | ||
symbols. For more information about the legacy and USE_PSA_CRYPTO domain, | ||
as well as MBEDTLS_MD_CAN_ prefixed symbols, see transition-guards.md. | ||
|
||
psa_hash_alg PSA macro of an hash algorithm (e.g. PSA_ALG_SHA_256) | ||
|
||
If invoked in the context of Mbed TLS 4.x or TF-PSA-Crypto, the function | ||
just returns the PSA_WANT_ prefixed symbol that corresponds to | ||
psa_hash_alg. | ||
|
||
If invoked in the context of Mbed TLS 3.6, the function returns the | ||
MBEDTLS_MD_CAN_ prefixed symbol that corresponds to psa_hash_alg. | ||
|
||
""" | ||
if not psa_hash_alg.startswith('PSA_ALG_') or \ | ||
psa_hash_alg[8:] not in ['MD5', 'RIPEMD160', 'SHA_1', 'SHA_224', | ||
'SHA_256', 'SHA_384', 'SHA_512', 'SHA3_224', | ||
'SHA3_256', 'SHA3_384', 'SHA3_512']: | ||
raise ValueError('Unable to determine dependency symbol for ' + psa_hash_alg) | ||
|
||
if build_tree.is_mbedtls_3_6(): | ||
return "MBEDTLS_MD_CAN_" + psa_hash_alg[8:].replace("_", "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite correct: for SHA3 we want to keep the underscore. I think using a dict would be easier and more readable. |
||
else: | ||
return psa_information.psa_want_symbol(psa_hash_alg) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function name should include something like
compat36
. Also, the description should lead with the fact that it's about 3.6 compatibility: for us it's obvious due the context of the PR, but otherwise "legacy or USE_PSA_CRYPTO domain" in the first sentence will make little sense to future readers as those only exist in 3.6.