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

fix minor bug in path_cnt checks #196

Merged
merged 1 commit into from
May 27, 2015
Merged

Conversation

NWilson
Copy link
Contributor

@NWilson NWilson commented May 13, 2015

What do you think, is this a bug or not? I don't think it's dangerous, you'd need to have two CAs in the trust_ca list with the same subject name, but I think it counts as unintended behaviour that should be fixed.

Noticed during code review.

Commit comment: If the top certificate occurs twice in trust_ca (for example) it would not be good for the second instance to be checked with check_path_cnt reduced twice!

If the top certificate occurs twice in trust_ca (for example) it would
not be good for the second instance to be checked with check_path_cnt
reduced twice!
@mpg
Copy link
Contributor

mpg commented May 27, 2015

Thanks for catching this. I agree with your analysis.

@mpg mpg merged commit bc07c3a into Mbed-TLS:development May 27, 2015
@NWilson NWilson deleted the path_cnt_bug branch November 16, 2015 10:02
hanno-becker pushed a commit that referenced this pull request Nov 16, 2018
gilles-peskine-arm pushed a commit to gilles-peskine-arm/mbedtls that referenced this pull request Sep 3, 2019
gilles-peskine-arm added a commit to gilles-peskine-arm/mbedtls that referenced this pull request Apr 16, 2021
Use bitwise or on the absolute values, rather than addition, to
combine a high-level error code with a low-level error code (or an
error code of either kind with 0). This gives the same result when
combining error codes of different levels, since those use disjoint
bit positions.

An advantage of using bitwise or is that it is more robust to
mistakes. For example, combining an error code with itself is now a
no-op. Combining two error codes from the same module is more likely
to result in an error code from that module. We detect such errors
dynamically in tests when MBEDTLS_TEST_HOOKS is enabled, but that
doesn't help for rare cases which are not covered by our tests.

Another advantage is that it guarantees that the result cannot be 0 if
either input is nonzero. This sometimes helps optimizers and static
analyzers.

A downside is that the generated code tends to be slightly larger. When
combining a high-level constant with a low-level value, which is a
common idiom, the typical cost with Arm Thumb seems to be 1 extra
instruction, e.g. dhm_read_bignum before:
    30:   4b04            ldr     r3, [pc, Mbed-TLS#16]   ; (44 <dhm_read_bignum+0x44>)
    32:   18c0            adds    r0, r0, r3
    44:   ffffcf00        .word   0xffffcf00
After:
    30:   23c4            movs    r3, Mbed-TLS#196        ; 0xc4
    32:   4240            negs    r0, r0
    34:   019b            lsls    r3, r3, Mbed-TLS#6
    36:   4318            orrs    r0, r3
    38:   4240            negs    r0, r0

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
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.

2 participants