mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Avoid implementation defined behaviour
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
@ -130,7 +130,14 @@ int mbedtls_ct_memcmp(const void *a,
|
|||||||
* This would have significant security implications, so protect against it. */
|
* This would have significant security implications, so protect against it. */
|
||||||
#error "mbedtls_ct_memcmp() requires minimum 32-bit ints"
|
#error "mbedtls_ct_memcmp() requires minimum 32-bit ints"
|
||||||
#else
|
#else
|
||||||
return (int) diff;
|
/* The bit-twiddling ensures that when we cast uint32_t to int, we are casting
|
||||||
|
* a value that is in the range 0..INT_MAX - a value larger than this would
|
||||||
|
* result in implementation defined behaviour.
|
||||||
|
*
|
||||||
|
* This ensures that the value returned by the function is non-zero iff
|
||||||
|
* diff is non-zero.
|
||||||
|
*/
|
||||||
|
return (int) ((diff & 0xffff) | (diff >> 16));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user