Prevent timing attack in key handlers