Skip to content
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

[Crypto] Replace OpenSSL-specific flag with public API to check SHA256 digest initialization #36608

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

Alami-Amine
Copy link
Contributor

This is a follow_up to #36386 based on a post-merge comment.

  • an OpenSSL-specific mInitialized flag was added to HASH_SHA256 to check if digest computation was initialized, which isn't used for other Crypto Backends.

  • It also added platform-specific #ifdefs to the a platform-agnostic header.

  • Fix: replace by a Public API IsInitialized, with its implementation for OpenSSL/BoringSSL

Copy link

Review changes with  SemanticDiff

@Alami-Amine Alami-Amine changed the title [Crypto] Replace OpenSSL-specific initialization flag with a new public API to check SHA256 digest initialization [Crypto] Replace OpenSSL-specific flag with a new public API to check SHA256 digest initialization Nov 22, 2024
@Alami-Amine Alami-Amine marked this pull request as ready for review November 22, 2024 09:35
Copy link

github-actions bot commented Nov 22, 2024

PR #36608: Size comparison from 04e6a68 to c5ffbc1

Full report (25 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, nrfconnect, qpg, stm32, telink, tizen)
platform target config section 04e6a68 c5ffbc1 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1350314 1350314 0 0.0
RAM 104088 104088 0 0.0
bl702 lighting-app bl702+eth FLASH 649926 649926 0 0.0
RAM 25329 25329 0 0.0
bl702+wifi FLASH 827254 827254 0 0.0
RAM 14069 14069 0 0.0
bl706+mfd+rpc+littlefs FLASH 1055448 1055448 0 0.0
RAM 23917 23917 0 0.0
bl702l lighting-app bl702l+mfd+littlefs FLASH 977078 977078 0 0.0
RAM 16556 16556 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 838240 838240 0 0.0
RAM 123640 123640 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 824180 824180 0 0.0
RAM 125520 125520 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 770888 770888 0 0.0
RAM 113988 113988 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 755092 755092 0 0.0
RAM 114204 114204 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 629294 629294 0 0.0
RAM 205792 205792 0 0.0
lock CC3235SF_LAUNCHXL FLASH 667874 667874 0 0.0
RAM 205936 205936 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 916244 916244 0 0.0
RAM 143292 143292 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 888432 888432 0 0.0
RAM 141479 141479 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 850444 850444 0 0.0
RAM 142200 142200 0 0.0
qpg lighting-app qpg6105+debug FLASH 662520 662520 0 0.0
RAM 105384 105384 0 0.0
lock-app qpg6105+debug FLASH 620628 620628 0 0.0
RAM 99844 99844 0 0.0
stm32 light STM32WB5MM-DK FLASH 483332 483332 0 0.0
RAM 144848 144848 0 0.0
telink bridge-app tlsr9258a FLASH 681594 681594 0 0.0
RAM 91200 91200 0 0.0
contact-sensor-app tlsr9528a_retention FLASH 622030 622030 0 0.0
RAM 31432 31432 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 762886 762886 0 0.0
RAM 50208 50208 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 709164 709164 0 0.0
RAM 73460 73460 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 625872 625872 0 0.0
RAM 142132 142132 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 811780 811780 0 0.0
RAM 99676 99676 0 0.0
tizen all-clusters-app arm unknown 4972 4976 4 0.1
FLASH 1726800 1726872 72 0.0
RAM 90652 90636 -16 -0.0
chip-tool-ubsan arm unknown 10780 10784 4 0.0
FLASH 17946894 17946846 -48 -0.0
RAM 7830432 7830368 -64 -0.0

This is a follow_up to project-chip#36386 based on a post-merge comment,
- an OpenSSL-specific mInitialized flag was added to HASH_SHA256 to check if digest computation was initialised, which isn't used for other Crypto Backends
- Fix: replace by a Public API `IsInitialized`, with its implementation for OpenSSL/BoringSSL
Copy link

github-actions bot commented Nov 22, 2024

PR #36608: Size comparison from 04e6a68 to 49e008f

Full report (69 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
platform target config section 04e6a68 49e008f change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1350314 1350314 0 0.0
RAM 104088 104088 0 0.0
bl702 lighting-app bl702+eth FLASH 649926 649926 0 0.0
RAM 25329 25329 0 0.0
bl702+wifi FLASH 827254 827254 0 0.0
RAM 14069 14069 0 0.0
bl706+mfd+rpc+littlefs FLASH 1055448 1055448 0 0.0
RAM 23917 23917 0 0.0
bl702l lighting-app bl702l+mfd+littlefs FLASH 977078 977078 0 0.0
RAM 16556 16556 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 838240 838240 0 0.0
RAM 123640 123640 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 824180 824180 0 0.0
RAM 125520 125520 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 770888 770888 0 0.0
RAM 113988 113988 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 755092 755092 0 0.0
RAM 114204 114204 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 629294 629294 0 0.0
RAM 205792 205792 0 0.0
lock CC3235SF_LAUNCHXL FLASH 667874 667874 0 0.0
RAM 205936 205936 0 0.0
cyw30739 light CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 679857 679857 0 0.0
RAM 78692 78692 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 699709 699709 0 0.0
RAM 81332 81332 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 699709 699709 0 0.0
RAM 81332 81332 0 0.0
CYW930739M2EVB-02 unknown 2040 2040 0 0.0
FLASH 656637 656637 0 0.0
RAM 73760 73760 0 0.0
light-switch CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 616721 616721 0 0.0
RAM 71652 71652 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 636357 636357 0 0.0
RAM 74196 74196 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 636357 636357 0 0.0
RAM 74196 74196 0 0.0
lock CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 636185 636185 0 0.0
RAM 74700 74700 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 655901 655901 0 0.0
RAM 77244 77244 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 655901 655901 0 0.0
RAM 77244 77244 0 0.0
thermostat CYW30739B2-P5-EVK-01 unknown 2040 2040 0 0.0
FLASH 612677 612677 0 0.0
RAM 68780 68780 0 0.0
CYW30739B2-P5-EVK-02 unknown 2040 2040 0 0.0
FLASH 632529 632529 0 0.0
RAM 71420 71420 0 0.0
CYW30739B2-P5-EVK-03 unknown 2040 2040 0 0.0
FLASH 632529 632529 0 0.0
RAM 71420 71420 0 0.0
efr32 lock-app BRD4187C FLASH 927948 927948 0 0.0
RAM 160168 160168 0 0.0
BRD4338a FLASH 744312 744304 -8 -0.0
RAM 233296 233296 0 0.0
window-app BRD4187C FLASH 1019432 1019424 -8 -0.0
RAM 128268 128268 0 0.0
esp32 all-clusters-app c3devkit DRAM 95344 95344 0 0.0
FLASH 1541622 1541622 0 0.0
IRAM 82542 82542 0 0.0
m5stack DRAM 116256 116256 0 0.0
FLASH 1548702 1548702 0 0.0
IRAM 117039 117039 0 0.0
linux air-purifier-app debug unknown 4712 4720 8 0.2
FLASH 2706461 2706565 104 0.0
RAM 129704 129672 -32 -0.0
all-clusters-app debug unknown 5552 5560 8 0.1
FLASH 5997562 5997666 104 0.0
RAM 523432 523400 -32 -0.0
all-clusters-minimal-app debug unknown 5448 5456 8 0.1
FLASH 5335816 5335920 104 0.0
RAM 242488 242456 -32 -0.0
bridge-app debug unknown 5432 5440 8 0.1
FLASH 4675534 4675638 104 0.0
RAM 218432 218400 -32 -0.0
chip-tool debug unknown 5984 5992 8 0.1
FLASH 12834328 12834432 104 0.0
RAM 582194 582194 0 0.0
chip-tool-ipv6only arm64 unknown 21304 21304 0 0.0
FLASH 10969504 10969648 144 0.0
RAM 633144 633144 0 0.0
fabric-admin debug unknown 5808 5816 8 0.1
FLASH 11243271 11243375 104 0.0
RAM 582578 582578 0 0.0
fabric-bridge-app debug unknown 4688 4696 8 0.2
FLASH 4499792 4499896 104 0.0
RAM 205424 205392 -32 -0.0
fabric-sync debug unknown 4896 4904 8 0.2
FLASH 5596357 5596453 96 0.0
RAM 472424 472392 -32 -0.0
lighting-app debug+rpc+ui unknown 6096 6104 8 0.1
FLASH 5611473 5611585 112 0.0
RAM 228616 228584 -32 -0.0
lock-app debug unknown 5368 5376 8 0.1
FLASH 4724890 4724994 104 0.0
RAM 204632 204600 -32 -0.0
ota-provider-app debug unknown 4744 4752 8 0.2
FLASH 4350396 4350500 104 0.0
RAM 198304 198272 -32 -0.0
ota-requestor-app debug unknown 4680 4688 8 0.2
FLASH 4488830 4488934 104 0.0
RAM 202888 202856 -32 -0.0
shell debug unknown 4240 4248 8 0.2
FLASH 3020749 3020861 112 0.0
RAM 160336 160304 -32 -0.0
thermostat-no-ble arm64 unknown 9512 9512 0 0.0
FLASH 4096272 4096416 144 0.0
RAM 243008 242976 -32 -0.0
tv-app debug unknown 5664 5672 8 0.1
FLASH 5948085 5948181 96 0.0
RAM 595920 595888 -32 -0.0
tv-casting-app debug unknown 5232 5240 8 0.2
FLASH 11040269 11040365 96 0.0
RAM 691960 691960 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 916244 916244 0 0.0
RAM 143292 143292 0 0.0
nrf7002dk_nrf5340_cpuapp FLASH 888432 888432 0 0.0
RAM 141479 141479 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 FLASH 850444 850444 0 0.0
RAM 142200 142200 0 0.0
nxp contact k32w0+release FLASH 584344 584344 0 0.0
RAM 71056 71056 0 0.0
mcxw71+release FLASH 598872 598872 0 0.0
RAM 63152 63152 0 0.0
light k32w0+release FLASH 611284 611284 0 0.0
RAM 70448 70448 0 0.0
k32w1+release FLASH 685384 685384 0 0.0
RAM 48776 48776 0 0.0
lock mcxw71+release FLASH 748896 748896 0 0.0
RAM 67308 67308 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1644236 1644236 0 0.0
RAM 212072 212072 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1552212 1552212 0 0.0
RAM 208872 208872 0 0.0
light cy8ckit_062s2_43012 FLASH 1467252 1467252 0 0.0
RAM 200856 200856 0 0.0
lock cy8ckit_062s2_43012 FLASH 1465428 1465428 0 0.0
RAM 225216 225216 0 0.0
qpg lighting-app qpg6105+debug FLASH 662520 662520 0 0.0
RAM 105384 105384 0 0.0
lock-app qpg6105+debug FLASH 620628 620628 0 0.0
RAM 99844 99844 0 0.0
stm32 light STM32WB5MM-DK FLASH 483332 483332 0 0.0
RAM 144848 144848 0 0.0
telink bridge-app tlsr9258a FLASH 681594 681594 0 0.0
RAM 91200 91200 0 0.0
contact-sensor-app tlsr9528a_retention FLASH 622030 622030 0 0.0
RAM 31432 31432 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 762886 762886 0 0.0
RAM 50208 50208 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 709164 709164 0 0.0
RAM 73460 73460 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 625872 625872 0 0.0
RAM 142132 142132 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 811780 811780 0 0.0
RAM 99676 99676 0 0.0
tizen all-clusters-app arm unknown 4972 4976 4 0.1
FLASH 1726800 1726872 72 0.0
RAM 90652 90636 -16 -0.0
chip-tool-ubsan arm unknown 10780 10784 4 0.0
FLASH 17946894 17946846 -48 -0.0
RAM 7830432 7830368 -64 -0.0

@Alami-Amine Alami-Amine changed the title [Crypto] Replace OpenSSL-specific flag with a new public API to check SHA256 digest initialization [Crypto] Replace OpenSSL-specific flag with public API to check SHA256 digest initialization Nov 22, 2024
@mergify mergify bot merged commit 048227b into project-chip:master Nov 22, 2024
67 checks passed
*
* @return True if the context is correctly initialized; otherwise, false.
*/
bool IsInitialized();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need implementations for the non-OpenSSL/BoringSSL backends?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also: this looks like an API that API consumers should call before they do anything with the object.... but they very much don't do that, and if they tried it would not work with most of the backends. Why is this public API at all?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. The method used here should be used more widely whenever the context is used at all. I would expect this API to be private since it's only used internally and should never be false. The idea is to avoid double-free or leaks, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this was a mistake, the IsInitialized is only to be used internally by Hash_SHA256_stream within the OpenSSL backend. So I will make IsInitialized protected.

@bzbarsky-apple Should I add a stub for IsInitialized in other backends or only add a comment in the *.h that it is only implemented in OpenSSL?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's private/protected, it really does not matter; someone who tries to use it will know what they are doing and notice they need to implement it. So comment saying "implement this if your backend needs it" is fine.

shgutte pushed a commit to shgutte/connectedhomeip that referenced this pull request Nov 25, 2024
…hip#36608)

This is a follow_up to project-chip#36386 based on a post-merge comment,
- an OpenSSL-specific mInitialized flag was added to HASH_SHA256 to check if digest computation was initialised, which isn't used for other Crypto Backends
- Fix: replace by a Public API `IsInitialized`, with its implementation for OpenSSL/BoringSSL
yyzhong-g pushed a commit to yyzhong-g/connectedhomeip that referenced this pull request Dec 12, 2024
…hip#36608)

This is a follow_up to project-chip#36386 based on a post-merge comment,
- an OpenSSL-specific mInitialized flag was added to HASH_SHA256 to check if digest computation was initialised, which isn't used for other Crypto Backends
- Fix: replace by a Public API `IsInitialized`, with its implementation for OpenSSL/BoringSSL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants