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

sim: Ensure the estimated TLV area size is always equal to the actual size #2215

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

taltenbach
Copy link
Contributor

@taltenbach taltenbach commented Feb 23, 2025

To generate largest possible and oversized images, the simulator needs to determine first the maximum size of an image. When signing the images using ECDSA, the actual size of the generated image was not exactly always the desired size. Indeed, in that case, the size of the TLV area estimated during the computation of the maximum image size might not be always equal to the actual TLV area size. This is because the ECDSA signatures are encoded as ASN.1 and the size of the ASN.1 representation can vary depending on the value of the two integers the signature is composed of.

This was not a big deal but was adding a bit of randomness in the simulation and was for example making difficult to generate reliably an oversized image, possibly leading to occasional false failures of the tests using oversized images.

To avoid the issue, a very simple workaround is implemented: when using ECDSA, each image is signed repeatedly until a signature with the maximum size is obtained. This is possible without modifying the image because ECDSA signing is not a deterministic process and gives a completely different signature at each try. On average, four attempts should be required to get the desired signature size.

ECDSA signatures are encoded as ASN.1 and the size of the ASN.1
representation can vary depending on the value of the two integers the
signature is composed of. This means that when ECDSA is used, the size
of the TLV area is not always equal to the size that was estimated by
the simulator when attempting to determine the maximum image size.
Indeed, the estimate gives the maximum possible size of the TLV area and
depending on its actual size, the generated images might be in fact a
bit smaller than expected.

This is not a big issue but adds a bit of randomness in the simulation
and make difficult to generate precisely oversized images when desired
for example.

This commit ensures an ECDSA signature with the largest possible size is
always used, making the size of the corresponding TLV entry constant in
the simulator.

Signed-off-by: Thomas Altenbach <[email protected]>
To generate oversized, the simulator needs to know the maximum image
size. To obtain such size, the size of the TLV area is estimated and
when using ECDSA, the actual size of the TLV area in the generated image
was not always equal to the estimated size. This required to add a bit
more data than what should be necessary when creating oversized images,
to ensure the generated images will actually be oversized in most cases.

Thanks to the previous commit, this is no more necessary and it is now
possible to reliably generate oversized images with the smallest size.

Signed-off-by: Thomas Altenbach <[email protected]>
For the overwrite-only upgrade strategy, the trailer size computed by
the simulator and used to determine the maximum image size was not
correct. This commit fixes the issue.

Having an underestimated trailer size was causing the
'oversized_secondary_slot' to fail since the previous commit, because
the oversized images are now generated to have the smallest possible
size.

Signed-off-by: Thomas Altenbach <[email protected]>
@taltenbach taltenbach requested a review from d3zd3z as a code owner February 23, 2025 23:36
@nordicjm nordicjm requested a review from utzig February 26, 2025 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant