Perform a length check before CRYPTO_memcmp to avoid out-of-bounds reads

CRYPTO_memcmp doesn't perform any bounds checking, therefore we have to do this before calling CRYPTO_memcmp.