size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv,
		unsigned char *out,
		const unsigned char *in, size_t inlen, block128_f block)
	{
	size_t n = inlen / 8 - 1;
	size_t padded_len;
	size_t padding_len;
	size_t ptext_len;
	unsigned char aiv[8];
	static unsigned char zeros[8] = {0x0};
	size_t ret;
	if ((inlen & 0x7) != 0 || inlen < 16 || inlen >= CRYPTO128_WRAP_MAX)
		return 0;
	memmove(out, in, inlen);
	if (inlen == 16)
		{
		block(out, out, key);
		memcpy(aiv, out, 8);
		memmove(out, out + 8, 8);
		padded_len = 8;
		}
		else
		{
		padded_len = inlen - 8;
		ret = crypto_128_unwrap_raw(key, aiv, out, out, inlen, block);
		if (padded_len != ret)
			{
			OPENSSL_cleanse(out, inlen);
			return 0;
			}
		}
	if ((!icv && CRYPTO_memcmp(aiv, default_aiv, 4))
		|| (icv && CRYPTO_memcmp(aiv, icv, 4)))
		{
		OPENSSL_cleanse(out, inlen);
		return 0;
		}
	ptext_len = (aiv[4] << 24) | (aiv[5] << 16) | (aiv[6] << 8) | aiv[7];
	if (8*(n-1) >= ptext_len || ptext_len > 8*n)
		{
		OPENSSL_cleanse(out, inlen);
		return 0;
		}
	padding_len = padded_len - ptext_len;
	if (CRYPTO_memcmp(out + ptext_len, zeros, padding_len) != 0)
		{
		OPENSSL_cleanse(out, inlen);
		return 0;
		}
	return ptext_len;
	}
['size_t CRYPTO_128_unwrap_pad(void *key, const unsigned char *icv,\n\t\tunsigned char *out,\n\t\tconst unsigned char *in, size_t inlen, block128_f block)\n\t{\n\tsize_t n = inlen / 8 - 1;\n\tsize_t padded_len;\n\tsize_t padding_len;\n\tsize_t ptext_len;\n\tunsigned char aiv[8];\n\tstatic unsigned char zeros[8] = {0x0};\n\tsize_t ret;\n\tif ((inlen & 0x7) != 0 || inlen < 16 || inlen >= CRYPTO128_WRAP_MAX)\n\t\treturn 0;\n\tmemmove(out, in, inlen);\n\tif (inlen == 16)\n\t\t{\n\t\tblock(out, out, key);\n\t\tmemcpy(aiv, out, 8);\n\t\tmemmove(out, out + 8, 8);\n\t\tpadded_len = 8;\n\t\t}\n\t\telse\n\t\t{\n\t\tpadded_len = inlen - 8;\n\t\tret = crypto_128_unwrap_raw(key, aiv, out, out, inlen, block);\n\t\tif (padded_len != ret)\n\t\t\t{\n\t\t\tOPENSSL_cleanse(out, inlen);\n\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\tif ((!icv && CRYPTO_memcmp(aiv, default_aiv, 4))\n\t\t|| (icv && CRYPTO_memcmp(aiv, icv, 4)))\n\t\t{\n\t\tOPENSSL_cleanse(out, inlen);\n\t\treturn 0;\n\t\t}\n\tptext_len = (aiv[4] << 24) | (aiv[5] << 16) | (aiv[6] << 8) | aiv[7];\n\tif (8*(n-1) >= ptext_len || ptext_len > 8*n)\n\t\t{\n\t\tOPENSSL_cleanse(out, inlen);\n\t\treturn 0;\n\t\t}\n\tpadding_len = padded_len - ptext_len;\n\tif (CRYPTO_memcmp(out + ptext_len, zeros, padding_len) != 0)\n\t\t{\n\t\tOPENSSL_cleanse(out, inlen);\n\t\treturn 0;\n\t\t}\n\treturn ptext_len;\n\t}']