round outlen down if invalid, add self-tests