id int64 1 36.7k | label int64 0 1 | bug_url stringlengths 91 134 | bug_function stringlengths 13 72.7k | functions stringlengths 17 79.2k |
|---|---|---|---|---|
34,301 | 0 | https://gitlab.com/libtiff/libtiff/blob/277644d8a4c2723aaa7049cacd6c852f9a539335/tools/tiffcrop.c/#L8571 | static int
rotateImage(uint16 rotation, struct image_data *image, uint32 *img_width,
uint32 *img_length, unsigned char **ibuff_ptr)
{
int shift_width;
uint32 bytes_per_pixel, bytes_per_sample;
uint32 row, rowsize, src_offset, dst_offset;
uint32 i, col, width, length;
uint32 colsize, buffsize, col_offset, pix_offset;
unsigned char *ibuff;
unsigned char *src;
unsigned char *dst;
uint16 spp, bps;
float res_temp;
unsigned char *rbuff = NULL;
width = *img_width;
length = *img_length;
spp = image->spp;
bps = image->bps;
rowsize = ((bps * spp * width) + 7) / 8;
colsize = ((bps * spp * length) + 7) / 8;
if ((colsize * width) > (rowsize * length))
buffsize = (colsize + 1) * width;
else
buffsize = (rowsize + 1) * length;
bytes_per_sample = (bps + 7) / 8;
bytes_per_pixel = ((bps * spp) + 7) / 8;
if (bytes_per_pixel < (bytes_per_sample + 1))
shift_width = bytes_per_pixel;
else
shift_width = bytes_per_sample + 1;
switch (rotation)
{
case 0:
case 360: return (0);
case 90:
case 180:
case 270: break;
default: TIFFError("rotateImage", "Invalid rotation angle %d", rotation);
return (-1);
}
if (!(rbuff = (unsigned char *)_TIFFmalloc(buffsize)))
{
TIFFError("rotateImage", "Unable to allocate rotation buffer of %1u bytes", buffsize);
return (-1);
}
_TIFFmemset(rbuff, '\0', buffsize);
ibuff = *ibuff_ptr;
switch (rotation)
{
case 180: if ((bps % 8) == 0)
{
src = ibuff;
pix_offset = (spp * bps) / 8;
for (row = 0; row < length; row++)
{
dst_offset = (length - row - 1) * rowsize;
for (col = 0; col < width; col++)
{
col_offset = (width - col - 1) * pix_offset;
dst = rbuff + dst_offset + col_offset;
for (i = 0; i < bytes_per_pixel; i++)
*dst++ = *src++;
}
}
}
else
{
for (row = 0; row < length; row++)
{
src_offset = row * rowsize;
dst_offset = (length - row - 1) * rowsize;
src = ibuff + src_offset;
dst = rbuff + dst_offset;
switch (shift_width)
{
case 1: if (bps == 1)
{
if (reverseSamples8bits(spp, bps, width, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
}
if (reverseSamples16bits(spp, bps, width, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
case 2: if (reverseSamples24bits(spp, bps, width, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
case 3:
case 4:
case 5: if (reverseSamples32bits(spp, bps, width, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
default: TIFFError("rotateImage","Unsupported bit depth %d", bps);
_TIFFfree(rbuff);
return (-1);
}
}
}
_TIFFfree(ibuff);
*(ibuff_ptr) = rbuff;
break;
case 90: if ((bps % 8) == 0)
{
for (col = 0; col < width; col++)
{
src_offset = ((length - 1) * rowsize) + (col * bytes_per_pixel);
dst_offset = col * colsize;
src = ibuff + src_offset;
dst = rbuff + dst_offset;
for (row = length; row > 0; row--)
{
for (i = 0; i < bytes_per_pixel; i++)
*dst++ = *(src + i);
src -= rowsize;
}
}
}
else
{
for (col = 0; col < width; col++)
{
src_offset = (length - 1) * rowsize;
dst_offset = col * colsize;
src = ibuff + src_offset;
dst = rbuff + dst_offset;
switch (shift_width)
{
case 1: if (bps == 1)
{
if (rotateContigSamples8bits(rotation, spp, bps, width,
length, col, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
}
if (rotateContigSamples16bits(rotation, spp, bps, width,
length, col, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
case 2: if (rotateContigSamples24bits(rotation, spp, bps, width,
length, col, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
case 3:
case 4:
case 5: if (rotateContigSamples32bits(rotation, spp, bps, width,
length, col, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
default: TIFFError("rotateImage","Unsupported bit depth %d", bps);
_TIFFfree(rbuff);
return (-1);
}
}
}
_TIFFfree(ibuff);
*(ibuff_ptr) = rbuff;
*img_width = length;
*img_length = width;
image->width = length;
image->length = width;
res_temp = image->xres;
image->xres = image->yres;
image->yres = res_temp;
break;
case 270: if ((bps % 8) == 0)
{
for (col = 0; col < width; col++)
{
src_offset = col * bytes_per_pixel;
dst_offset = (width - col - 1) * colsize;
src = ibuff + src_offset;
dst = rbuff + dst_offset;
for (row = length; row > 0; row--)
{
for (i = 0; i < bytes_per_pixel; i++)
*dst++ = *(src + i);
src += rowsize;
}
}
}
else
{
for (col = 0; col < width; col++)
{
src_offset = 0;
dst_offset = (width - col - 1) * colsize;
src = ibuff + src_offset;
dst = rbuff + dst_offset;
switch (shift_width)
{
case 1: if (bps == 1)
{
if (rotateContigSamples8bits(rotation, spp, bps, width,
length, col, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
}
if (rotateContigSamples16bits(rotation, spp, bps, width,
length, col, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
case 2: if (rotateContigSamples24bits(rotation, spp, bps, width,
length, col, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
case 3:
case 4:
case 5: if (rotateContigSamples32bits(rotation, spp, bps, width,
length, col, src, dst))
{
_TIFFfree(rbuff);
return (-1);
}
break;
default: TIFFError("rotateImage","Unsupported bit depth %d", bps);
_TIFFfree(rbuff);
return (-1);
}
}
}
_TIFFfree(ibuff);
*(ibuff_ptr) = rbuff;
*img_width = length;
*img_length = width;
image->width = length;
image->length = width;
res_temp = image->xres;
image->xres = image->yres;
image->yres = res_temp;
break;
default:
break;
}
return (0);
} | ['static int\nrotateImage(uint16 rotation, struct image_data *image, uint32 *img_width,\n uint32 *img_length, unsigned char **ibuff_ptr)\n {\n int shift_width;\n uint32 bytes_per_pixel, bytes_per_sample;\n uint32 row, rowsize, src_offset, dst_offset;\n uint32 i, col, width, length;\n uint32 colsize, buffsize, col_offset, pix_offset;\n unsigned char *ibuff;\n unsigned char *src;\n unsigned char *dst;\n uint16 spp, bps;\n float res_temp;\n unsigned char *rbuff = NULL;\n width = *img_width;\n length = *img_length;\n spp = image->spp;\n bps = image->bps;\n rowsize = ((bps * spp * width) + 7) / 8;\n colsize = ((bps * spp * length) + 7) / 8;\n if ((colsize * width) > (rowsize * length))\n buffsize = (colsize + 1) * width;\n else\n buffsize = (rowsize + 1) * length;\n bytes_per_sample = (bps + 7) / 8;\n bytes_per_pixel = ((bps * spp) + 7) / 8;\n if (bytes_per_pixel < (bytes_per_sample + 1))\n shift_width = bytes_per_pixel;\n else\n shift_width = bytes_per_sample + 1;\n switch (rotation)\n {\n case 0:\n case 360: return (0);\n case 90:\n case 180:\n case 270: break;\n default: TIFFError("rotateImage", "Invalid rotation angle %d", rotation);\n return (-1);\n }\n if (!(rbuff = (unsigned char *)_TIFFmalloc(buffsize)))\n {\n TIFFError("rotateImage", "Unable to allocate rotation buffer of %1u bytes", buffsize);\n return (-1);\n }\n _TIFFmemset(rbuff, \'\\0\', buffsize);\n ibuff = *ibuff_ptr;\n switch (rotation)\n {\n case 180: if ((bps % 8) == 0)\n {\n src = ibuff;\n pix_offset = (spp * bps) / 8;\n for (row = 0; row < length; row++)\n {\n\t\t dst_offset = (length - row - 1) * rowsize;\n for (col = 0; col < width; col++)\n {\n\t\t col_offset = (width - col - 1) * pix_offset;\n dst = rbuff + dst_offset + col_offset;\n\t\t for (i = 0; i < bytes_per_pixel; i++)\n\t\t *dst++ = *src++;\n }\n }\n }\n\t else\n {\n for (row = 0; row < length; row++)\n {\n\t\t src_offset = row * rowsize;\n\t\t dst_offset = (length - row - 1) * rowsize;\n\t\t src = ibuff + src_offset;\n dst = rbuff + dst_offset;\n switch (shift_width)\n {\n case 1: if (bps == 1)\n\t\t\t {\n if (reverseSamples8bits(spp, bps, width, src, dst))\n {\n\t\t _TIFFfree(rbuff);\n return (-1);\n }\n break;\n }\n if (reverseSamples16bits(spp, bps, width, src, dst))\n {\n\t\t _TIFFfree(rbuff);\n return (-1);\n }\n break;\n case 2: if (reverseSamples24bits(spp, bps, width, src, dst))\n {\n\t\t _TIFFfree(rbuff);\n return (-1);\n }\n break;\n case 3:\n case 4:\n case 5: if (reverseSamples32bits(spp, bps, width, src, dst))\n {\n\t\t _TIFFfree(rbuff);\n return (-1);\n }\n break;\n default: TIFFError("rotateImage","Unsupported bit depth %d", bps);\n\t\t _TIFFfree(rbuff);\n return (-1);\n }\n\t\t }\n\t\t}\n _TIFFfree(ibuff);\n *(ibuff_ptr) = rbuff;\n break;\n case 90: if ((bps % 8) == 0)\n {\n for (col = 0; col < width; col++)\n {\n\t\t src_offset = ((length - 1) * rowsize) + (col * bytes_per_pixel);\n dst_offset = col * colsize;\n\t\t src = ibuff + src_offset;\n\t\t dst = rbuff + dst_offset;\n for (row = length; row > 0; row--)\n {\n for (i = 0; i < bytes_per_pixel; i++)\n *dst++ = *(src + i);\n\t\t src -= rowsize;\n }\n\t\t }\n\t\t}\n else\n {\n for (col = 0; col < width; col++)\n {\n\t\t src_offset = (length - 1) * rowsize;\n dst_offset = col * colsize;\n\t\t src = ibuff + src_offset;\n\t\t dst = rbuff + dst_offset;\n switch (shift_width)\n {\n case 1: if (bps == 1)\n\t\t\t {\n if (rotateContigSamples8bits(rotation, spp, bps, width,\n\t\t\t\t \t length, col, src, dst))\n {\n\t\t _TIFFfree(rbuff);\n return (-1);\n }\n break;\n }\n if (rotateContigSamples16bits(rotation, spp, bps, width,\n\t\t\t\t \t length, col, src, dst))\n {\n\t _TIFFfree(rbuff);\n return (-1);\n\t\t }\n\t\t break;\n case 2: if (rotateContigSamples24bits(rotation, spp, bps, width,\n\t\t\t\t\t length, col, src, dst))\n {\n\t\t _TIFFfree(rbuff);\n return (-1);\n }\n break;\n case 3:\n case 4:\n case 5: if (rotateContigSamples32bits(rotation, spp, bps, width,\n\t\t\t\t\t length, col, src, dst))\n {\n\t\t _TIFFfree(rbuff);\n return (-1);\n }\n break;\n default: TIFFError("rotateImage","Unsupported bit depth %d", bps);\n\t\t _TIFFfree(rbuff);\n return (-1);\n\t\t }\n\t\t }\n\t\t}\n _TIFFfree(ibuff);\n *(ibuff_ptr) = rbuff;\n *img_width = length;\n *img_length = width;\n image->width = length;\n image->length = width;\n res_temp = image->xres;\n image->xres = image->yres;\n image->yres = res_temp;\n\t break;\n case 270: if ((bps % 8) == 0)\n {\n for (col = 0; col < width; col++)\n {\n\t\t src_offset = col * bytes_per_pixel;\n dst_offset = (width - col - 1) * colsize;\n\t\t src = ibuff + src_offset;\n\t\t dst = rbuff + dst_offset;\n for (row = length; row > 0; row--)\n {\n for (i = 0; i < bytes_per_pixel; i++)\n *dst++ = *(src + i);\n\t\t src += rowsize;\n }\n\t\t }\n\t\t}\n else\n {\n for (col = 0; col < width; col++)\n {\n\t\t src_offset = 0;\n dst_offset = (width - col - 1) * colsize;\n\t\t src = ibuff + src_offset;\n\t\t dst = rbuff + dst_offset;\n switch (shift_width)\n {\n case 1: if (bps == 1)\n\t\t\t {\n if (rotateContigSamples8bits(rotation, spp, bps, width,\n\t\t\t\t \t length, col, src, dst))\n {\n\t\t _TIFFfree(rbuff);\n return (-1);\n }\n break;\n }\n if (rotateContigSamples16bits(rotation, spp, bps, width,\n\t\t\t\t \t length, col, src, dst))\n {\n\t _TIFFfree(rbuff);\n return (-1);\n\t\t }\n\t\t break;\n case 2: if (rotateContigSamples24bits(rotation, spp, bps, width,\n\t\t\t\t\t length, col, src, dst))\n {\n\t\t _TIFFfree(rbuff);\n return (-1);\n }\n break;\n case 3:\n case 4:\n case 5: if (rotateContigSamples32bits(rotation, spp, bps, width,\n\t\t\t\t\t length, col, src, dst))\n {\n\t\t _TIFFfree(rbuff);\n return (-1);\n }\n break;\n default: TIFFError("rotateImage","Unsupported bit depth %d", bps);\n\t\t _TIFFfree(rbuff);\n return (-1);\n\t\t }\n\t\t }\n\t\t}\n _TIFFfree(ibuff);\n *(ibuff_ptr) = rbuff;\n *img_width = length;\n *img_length = width;\n image->width = length;\n image->length = width;\n res_temp = image->xres;\n image->xres = image->yres;\n image->yres = res_temp;\n break;\n default:\n break;\n }\n return (0);\n }', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n if (s == 0)\n return ((void *) NULL);\n\treturn (malloc((size_t) s));\n}', 'void\n_TIFFmemset(void* p, int v, tmsize_t c)\n{\n\tmemset(p, v, (size_t) c);\n}'] |
34,302 | 1 | https://github.com/openssl/openssl/blob/3da2e9c4ee45989a426ff513dc6c6250d1e460de/crypto/bn/bn_shift.c/#L165 | int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, j, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l, tmp;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_RSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
rb = n % BN_BITS2;
lb = BN_BITS2 - rb;
if (nw >= a->top || a->top == 0) {
BN_zero(r);
return 1;
}
i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;
if (r != a) {
if (bn_wexpand(r, i) == NULL)
return 0;
r->neg = a->neg;
} else {
if (n == 0)
return 1;
}
f = &(a->d[nw]);
t = r->d;
j = a->top - nw;
r->top = i;
if (rb == 0) {
for (i = j; i != 0; i--)
*(t++) = *(f++);
} else {
l = *(f++);
for (i = j - 1; i != 0; i--) {
tmp = (l >> rb) & BN_MASK2;
l = *(f++);
*(t++) = (tmp | (l << lb)) & BN_MASK2;
}
if ((l = (l >> rb) & BN_MASK2))
*(t) = l;
}
if (!r->top)
r->neg = 0;
bn_check_top(r);
return 1;
} | ['static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)\n{\n BIGNUM *r1, *m1, *vrfy, *r2, *m[RSA_MAX_PRIME_NUM - 2];\n int ret = 0, i, ex_primes = 0, smooth = 0;\n RSA_PRIME_INFO *pinfo;\n BN_CTX_start(ctx);\n r1 = BN_CTX_get(ctx);\n r2 = BN_CTX_get(ctx);\n m1 = BN_CTX_get(ctx);\n vrfy = BN_CTX_get(ctx);\n if (vrfy == NULL)\n goto err;\n if (rsa->version == RSA_ASN1_VERSION_MULTI\n && ((ex_primes = sk_RSA_PRIME_INFO_num(rsa->prime_infos)) <= 0\n || ex_primes > RSA_MAX_PRIME_NUM - 2))\n goto err;\n if (rsa->flags & RSA_FLAG_CACHE_PRIVATE) {\n BIGNUM *factor = BN_new();\n if (factor == NULL)\n goto err;\n if (!(BN_with_flags(factor, rsa->p, BN_FLG_CONSTTIME),\n BN_MONT_CTX_set_locked(&rsa->_method_mod_p, rsa->lock,\n factor, ctx))\n || !(BN_with_flags(factor, rsa->q, BN_FLG_CONSTTIME),\n BN_MONT_CTX_set_locked(&rsa->_method_mod_q, rsa->lock,\n factor, ctx))) {\n BN_free(factor);\n goto err;\n }\n for (i = 0; i < ex_primes; i++) {\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n BN_with_flags(factor, pinfo->r, BN_FLG_CONSTTIME);\n if (!BN_MONT_CTX_set_locked(&pinfo->m, rsa->lock, factor, ctx)) {\n BN_free(factor);\n goto err;\n }\n }\n BN_free(factor);\n smooth = (ex_primes == 0)\n && (rsa->meth->bn_mod_exp == BN_mod_exp_mont)\n && (BN_num_bits(rsa->q) == BN_num_bits(rsa->p));\n }\n if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,\n rsa->n, ctx))\n goto err;\n if (smooth) {\n if (\n !bn_from_mont_fixed_top(m1, I, rsa->_method_mod_q, ctx)\n || !bn_to_mont_fixed_top(m1, m1, rsa->_method_mod_q, ctx)\n || !BN_mod_exp_mont_consttime(m1, m1, rsa->dmq1, rsa->q, ctx,\n rsa->_method_mod_q)\n || !bn_from_mont_fixed_top(r1, I, rsa->_method_mod_p, ctx)\n || !bn_to_mont_fixed_top(r1, r1, rsa->_method_mod_p, ctx)\n || !BN_mod_exp_mont_consttime(r1, r1, rsa->dmp1, rsa->p, ctx,\n rsa->_method_mod_p)\n || !bn_mod_sub_fixed_top(r1, r1, m1, rsa->p)\n || !bn_to_mont_fixed_top(r1, r1, rsa->_method_mod_p, ctx)\n || !bn_mul_mont_fixed_top(r1, r1, rsa->iqmp, rsa->_method_mod_p,\n ctx)\n || !bn_mul_fixed_top(r0, r1, rsa->q, ctx)\n || !bn_mod_add_fixed_top(r0, r0, m1, rsa->n))\n goto err;\n goto tail;\n }\n {\n BIGNUM *c = BN_new();\n if (c == NULL)\n goto err;\n BN_with_flags(c, I, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, c, rsa->q, ctx)) {\n BN_free(c);\n goto err;\n }\n {\n BIGNUM *dmq1 = BN_new();\n if (dmq1 == NULL) {\n BN_free(c);\n goto err;\n }\n BN_with_flags(dmq1, rsa->dmq1, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(m1, r1, dmq1, rsa->q, ctx,\n rsa->_method_mod_q)) {\n BN_free(c);\n BN_free(dmq1);\n goto err;\n }\n BN_free(dmq1);\n }\n if (!BN_mod(r1, c, rsa->p, ctx)) {\n BN_free(c);\n goto err;\n }\n BN_free(c);\n }\n {\n BIGNUM *dmp1 = BN_new();\n if (dmp1 == NULL)\n goto err;\n BN_with_flags(dmp1, rsa->dmp1, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(r0, r1, dmp1, rsa->p, ctx,\n rsa->_method_mod_p)) {\n BN_free(dmp1);\n goto err;\n }\n BN_free(dmp1);\n }\n if (ex_primes > 0) {\n BIGNUM *di = BN_new(), *cc = BN_new();\n if (cc == NULL || di == NULL) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n for (i = 0; i < ex_primes; i++) {\n if ((m[i] = BN_CTX_get(ctx)) == NULL) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n BN_with_flags(cc, I, BN_FLG_CONSTTIME);\n BN_with_flags(di, pinfo->d, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, cc, pinfo->r, ctx)) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n if (!rsa->meth->bn_mod_exp(m[i], r1, di, pinfo->r, ctx, pinfo->m)) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n }\n BN_free(cc);\n BN_free(di);\n }\n if (!BN_sub(r0, r0, m1))\n goto err;\n if (BN_is_negative(r0))\n if (!BN_add(r0, r0, rsa->p))\n goto err;\n if (!BN_mul(r1, r0, rsa->iqmp, ctx))\n goto err;\n {\n BIGNUM *pr1 = BN_new();\n if (pr1 == NULL)\n goto err;\n BN_with_flags(pr1, r1, BN_FLG_CONSTTIME);\n if (!BN_mod(r0, pr1, rsa->p, ctx)) {\n BN_free(pr1);\n goto err;\n }\n BN_free(pr1);\n }\n if (BN_is_negative(r0))\n if (!BN_add(r0, r0, rsa->p))\n goto err;\n if (!BN_mul(r1, r0, rsa->q, ctx))\n goto err;\n if (!BN_add(r0, r1, m1))\n goto err;\n if (ex_primes > 0) {\n BIGNUM *pr2 = BN_new();\n if (pr2 == NULL)\n goto err;\n for (i = 0; i < ex_primes; i++) {\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n if (!BN_sub(r1, m[i], r0)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_mul(r2, r1, pinfo->t, ctx)) {\n BN_free(pr2);\n goto err;\n }\n BN_with_flags(pr2, r2, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, pr2, pinfo->r, ctx)) {\n BN_free(pr2);\n goto err;\n }\n if (BN_is_negative(r1))\n if (!BN_add(r1, r1, pinfo->r)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_mul(r1, r1, pinfo->pp, ctx)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_add(r0, r0, r1)) {\n BN_free(pr2);\n goto err;\n }\n }\n BN_free(pr2);\n }\n tail:\n if (rsa->e && rsa->n) {\n if (rsa->meth->bn_mod_exp == BN_mod_exp_mont) {\n if (!BN_mod_exp_mont(vrfy, r0, rsa->e, rsa->n, ctx,\n rsa->_method_mod_n))\n goto err;\n } else {\n bn_correct_top(r0);\n if (!rsa->meth->bn_mod_exp(vrfy, r0, rsa->e, rsa->n, ctx,\n rsa->_method_mod_n))\n goto err;\n }\n if (!BN_sub(vrfy, vrfy, I))\n goto err;\n if (BN_is_zero(vrfy)) {\n bn_correct_top(r0);\n ret = 1;\n goto err;\n }\n if (!BN_mod(vrfy, vrfy, rsa->n, ctx))\n goto err;\n if (BN_is_negative(vrfy))\n if (!BN_add(vrfy, vrfy, rsa->n))\n goto err;\n if (!BN_is_zero(vrfy)) {\n BIGNUM *d = BN_new();\n if (d == NULL)\n goto err;\n BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(r0, I, d, rsa->n, ctx,\n rsa->_method_mod_n)) {\n BN_free(d);\n goto err;\n }\n BN_free(d);\n }\n }\n bn_correct_top(r0);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.flags = BN_FLG_STATIC_DATA;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n l0 = bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1);\n q -= l0;\n for (l0 = 0 - l0, j = 0; j < div_n; j++)\n tmp->d[j] = sdiv->d[j] & l0;\n l0 = bn_add_words(wnum.d, wnum.d, tmp->d, div_n);\n (*wnump) += l0;\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'void BN_with_flags(BIGNUM *dest, const BIGNUM *b, int flags)\n{\n dest->d = b->d;\n dest->top = b->top;\n dest->dmax = b->dmax;\n dest->neg = b->neg;\n dest->flags = ((dest->flags & BN_FLG_MALLOCED)\n | (b->flags & ~BN_FLG_MALLOCED)\n | BN_FLG_STATIC_DATA | flags);\n}', 'int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, j, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l, tmp;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_RSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n rb = n % BN_BITS2;\n lb = BN_BITS2 - rb;\n if (nw >= a->top || a->top == 0) {\n BN_zero(r);\n return 1;\n }\n i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;\n if (r != a) {\n if (bn_wexpand(r, i) == NULL)\n return 0;\n r->neg = a->neg;\n } else {\n if (n == 0)\n return 1;\n }\n f = &(a->d[nw]);\n t = r->d;\n j = a->top - nw;\n r->top = i;\n if (rb == 0) {\n for (i = j; i != 0; i--)\n *(t++) = *(f++);\n } else {\n l = *(f++);\n for (i = j - 1; i != 0; i--) {\n tmp = (l >> rb) & BN_MASK2;\n l = *(f++);\n *(t++) = (tmp | (l << lb)) & BN_MASK2;\n }\n if ((l = (l >> rb) & BN_MASK2))\n *(t) = l;\n }\n if (!r->top)\n r->neg = 0;\n bn_check_top(r);\n return 1;\n}'] |
34,303 | 0 | https://github.com/libav/libav/blob/e5b0fc170f85b00f7dd0ac514918fb5c95253d39/libavcodec/bitstream.h/#L139 | static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
bc->bits >>= n;
#else
uint64_t ret = bc->bits >> (64 - n);
bc->bits <<= n;
#endif
bc->bits_left -= n;
return ret;
} | ['static int decode_channel_sound_unit(ATRAC3Context *q, BitstreamContext *bc,\n ChannelUnit *snd, float *output,\n int channel_num, int coding_mode)\n{\n int band, ret, num_subbands, last_tonal, num_bands;\n GainBlock *gain1 = &snd->gain_block[ snd->gc_blk_switch];\n GainBlock *gain2 = &snd->gain_block[1 - snd->gc_blk_switch];\n if (coding_mode == JOINT_STEREO && channel_num == 1) {\n if (bitstream_read(bc, 2) != 3) {\n av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\\n");\n return AVERROR_INVALIDDATA;\n }\n } else {\n if (bitstream_read(bc, 6) != 0x28) {\n av_log(NULL,AV_LOG_ERROR,"Sound Unit id != 0x28.\\n");\n return AVERROR_INVALIDDATA;\n }\n }\n snd->bands_coded = bitstream_read(bc, 2);\n ret = decode_gain_control(bc, gain2, snd->bands_coded);\n if (ret)\n return ret;\n snd->num_components = decode_tonal_components(bc, snd->components,\n snd->bands_coded);\n if (snd->num_components < 0)\n return snd->num_components;\n num_subbands = decode_spectrum(bc, snd->spectrum);\n last_tonal = add_tonal_components(snd->spectrum, snd->num_components,\n snd->components);\n num_bands = (subband_tab[num_subbands] - 1) >> 8;\n if (last_tonal >= 0)\n num_bands = FFMAX((last_tonal + 256) >> 8, num_bands);\n for (band = 0; band < 4; band++) {\n if (band <= num_bands)\n imlt(q, &snd->spectrum[band * 256], snd->imdct_buf, band & 1);\n else\n memset(snd->imdct_buf, 0, 512 * sizeof(*snd->imdct_buf));\n ff_atrac_gain_compensation(&q->gainc_ctx, snd->imdct_buf,\n &snd->prev_frame[band * 256],\n &gain1->g_block[band], &gain2->g_block[band],\n 256, &output[band * 256]);\n }\n snd->gc_blk_switch ^= 1;\n return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}'] |
34,304 | 0 | https://github.com/libav/libav/blob/a88ef93b4abbea9f18c8750113dc9e99931f2f8a/libavcodec/mpegaudiodec.c/#L605 | static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,
int *dither_state, OUT_INT *samples, int incr)
{
register const MPA_INT *w, *w2, *p;
int j;
OUT_INT *samples2;
#if CONFIG_FLOAT
float sum, sum2;
#else
int64_t sum, sum2;
#endif
memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));
samples2 = samples + 31 * incr;
w = window;
w2 = window + 31;
sum = *dither_state;
p = synth_buf + 16;
SUM8(MACS, sum, w, p);
p = synth_buf + 48;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
samples += incr;
w++;
for(j=1;j<16;j++) {
sum2 = 0;
p = synth_buf + 16 + j;
SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);
p = synth_buf + 48 - j;
SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);
*samples = round_sample(&sum);
samples += incr;
sum += sum2;
*samples2 = round_sample(&sum);
samples2 -= incr;
w++;
w2--;
}
p = synth_buf + 32;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
*dither_state= sum;
} | ['static int qdm2_decode_frame(AVCodecContext *avctx,\n void *data, int *data_size,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n QDM2Context *s = avctx->priv_data;\n int16_t *out = data;\n int i;\n if(!buf)\n return 0;\n if(buf_size < s->checksum_size)\n return -1;\n av_log(avctx, AV_LOG_DEBUG, "decode(%d): %p[%d] -> %p[%d]\\n",\n buf_size, buf, s->checksum_size, data, *data_size);\n for (i = 0; i < 16; i++) {\n if (qdm2_decode(s, buf, out) < 0)\n return -1;\n out += s->channels * s->frame_size;\n }\n *data_size = (uint8_t*)out - (uint8_t*)data;\n return s->checksum_size;\n}', 'static int qdm2_decode (QDM2Context *q, const uint8_t *in, int16_t *out)\n{\n int ch, i;\n const int frame_size = (q->frame_size * q->channels);\n q->compressed_data = in;\n q->compressed_size = q->checksum_size;\n memmove(q->output_buffer, &q->output_buffer[frame_size], frame_size * sizeof(float));\n memset(&q->output_buffer[frame_size], 0, frame_size * sizeof(float));\n if (q->sub_packet == 0) {\n q->has_errors = 0;\n av_log(NULL,AV_LOG_DEBUG,"Superblock follows\\n");\n qdm2_decode_super_block(q);\n }\n if (!q->has_errors) {\n if (q->sub_packet == 2)\n qdm2_decode_fft_packets(q);\n qdm2_fft_tone_synthesizer(q, q->sub_packet);\n }\n for (ch = 0; ch < q->channels; ch++) {\n qdm2_calculate_fft(q, ch, q->sub_packet);\n if (!q->has_errors && q->sub_packet_list_C[0].packet != NULL) {\n SAMPLES_NEEDED_2("has errors, and C list is not empty")\n return -1;\n }\n }\n if (!q->has_errors && q->do_synth_filter)\n qdm2_synthesis_filter(q, q->sub_packet);\n q->sub_packet = (q->sub_packet + 1) % 16;\n for (i = 0; i < frame_size; i++) {\n int value = (int)q->output_buffer[i];\n if (value > SOFTCLIP_THRESHOLD)\n value = (value > HARDCLIP_THRESHOLD) ? 32767 : softclip_table[ value - SOFTCLIP_THRESHOLD];\n else if (value < -SOFTCLIP_THRESHOLD)\n value = (value < -HARDCLIP_THRESHOLD) ? -32767 : -softclip_table[-value - SOFTCLIP_THRESHOLD];\n out[i] = value;\n }\n return 0;\n}', 'static void qdm2_synthesis_filter (QDM2Context *q, int index)\n{\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE];\n int i, k, ch, sb_used, sub_sampling, dither_state = 0;\n sb_used = QDM2_SB_USED(q->sub_sampling);\n for (ch = 0; ch < q->channels; ch++)\n for (i = 0; i < 8; i++)\n for (k=sb_used; k < SBLIMIT; k++)\n q->sb_samples[ch][(8 * index) + i][k] = 0;\n for (ch = 0; ch < q->nb_channels; ch++) {\n OUT_INT *samples_ptr = samples + ch;\n for (i = 0; i < 8; i++) {\n ff_mpa_synth_filter(q->synth_buf[ch], &(q->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, q->nb_channels,\n q->sb_samples[ch][(8 * index) + i]);\n samples_ptr += 32 * q->nb_channels;\n }\n }\n sub_sampling = (4 >> q->sub_sampling);\n for (ch = 0; ch < q->channels; ch++)\n for (i = 0; i < q->frame_size; i++)\n q->output_buffer[q->channels * i + ch] += (float)(samples[q->nb_channels * sub_sampling * i + ch] >> (sizeof(OUT_INT)*8-16));\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n int offset;\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n dct32(synth_buf, sb_samples);\n apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}', 'static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,\n int *dither_state, OUT_INT *samples, int incr)\n{\n register const MPA_INT *w, *w2, *p;\n int j;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n}'] |
34,305 | 0 | https://github.com/openssl/openssl/blob/aa8b03b415d20c0863f44c211486f881c6689383/crypto/bn/bn_ctx.c/#L353 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['static int RSA_eay_private_decrypt(int flen, const unsigned char *from,\n\t unsigned char *to, RSA *rsa, int padding)\n\t{\n\tBIGNUM *f, *ret, *br;\n\tint j,num=0,r= -1;\n\tunsigned char *p;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tint local_blinding = 0;\n\tBN_BLINDING *blinding = NULL;\n\tif((ctx = BN_CTX_new()) == NULL) goto err;\n\tBN_CTX_start(ctx);\n\tf = BN_CTX_get(ctx);\n\tbr = BN_CTX_get(ctx);\n\tret = BN_CTX_get(ctx);\n\tnum = BN_num_bytes(rsa->n);\n\tbuf = OPENSSL_malloc(num);\n\tif(!f || !ret || !buf)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tif (flen > num)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);\n\t\tgoto err;\n\t\t}\n\tif (BN_bin2bn(from,(int)flen,f) == NULL) goto err;\n\tif (BN_ucmp(f, rsa->n) >= 0)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n\t\tgoto err;\n\t\t}\n\tif (!(rsa->flags & RSA_FLAG_NO_BLINDING))\n\t\t{\n\t\tblinding = rsa_get_blinding(rsa, &br, &local_blinding, ctx);\n\t\tif (blinding == NULL)\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (blinding != NULL)\n\t\tif (!rsa_blinding_convert(blinding, local_blinding, f, br, ctx))\n\t\t\tgoto err;\n\tif ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||\n\t\t((rsa->p != NULL) &&\n\t\t(rsa->q != NULL) &&\n\t\t(rsa->dmp1 != NULL) &&\n\t\t(rsa->dmq1 != NULL) &&\n\t\t(rsa->iqmp != NULL)) )\n\t\t{\n\t\tif (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tBIGNUM local_d;\n\t\tBIGNUM *d = NULL;\n\t\tif (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME))\n\t\t\t{\n\t\t\td = &local_d;\n\t\t\tBN_with_flags(d, rsa->d, BN_FLG_EXP_CONSTTIME);\n\t\t\t}\n\t\telse\n\t\t\td = rsa->d;\n\t\tMONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);\n\t\tif (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx,\n\t\t\t\trsa->_method_mod_n))\n\t\t goto err;\n\t\t}\n\tif (blinding)\n\t\tif (!rsa_blinding_invert(blinding, local_blinding, ret, br, ctx))\n\t\t\tgoto err;\n\tp=buf;\n\tj=BN_bn2bin(ret,p);\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\tr=RSA_padding_check_PKCS1_type_2(to,num,buf,j,num);\n\t\tbreak;\n#ifndef OPENSSL_NO_SHA\n case RSA_PKCS1_OAEP_PADDING:\n\t r=RSA_padding_check_PKCS1_OAEP(to,num,buf,j,num,NULL,0);\n break;\n#endif\n \tcase RSA_SSLV23_PADDING:\n\t\tr=RSA_padding_check_SSLv23(to,num,buf,j,num);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\tr=RSA_padding_check_none(to,num,buf,j,num);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (r < 0)\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_PADDING_CHECK_FAILED);\nerr:\n\tif (ctx != NULL)\n\t\t{\n\t\tBN_CTX_end(ctx);\n\t\tBN_CTX_free(ctx);\n\t\t}\n\tif (buf != NULL)\n\t\t{\n\t\tOPENSSL_cleanse(buf,num);\n\t\tOPENSSL_free(buf);\n\t\t}\n\treturn(r);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,\n\t\t\t\t\tconst BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tif (*pmont)\n\t\treturn *pmont;\n\tCRYPTO_w_lock(lock);\n\tif (!*pmont)\n\t\t{\n\t\t*pmont = BN_MONT_CTX_new();\n\t\tif (*pmont && !BN_MONT_CTX_set(*pmont, mod, ctx))\n\t\t\t{\n\t\t\tBN_MONT_CTX_free(*pmont);\n\t\t\t*pmont = NULL;\n\t\t\t}\n\t\t}\n\tCRYPTO_w_unlock(lock);\n\treturn *pmont;\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *Ri,*R;\n\tBN_CTX_start(ctx);\n\tif((Ri = BN_CTX_get(ctx)) == NULL) goto err;\n\tR= &(mont->RR);\n\tif (!BN_copy(&(mont->N),mod)) goto err;\n\tmont->N.neg = 0;\n#ifdef MONT_WORD\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\ttmod.d=buf;\n\t\ttmod.dmax=2;\n\t\ttmod.neg=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,2*BN_BITS2))) goto err;\n\t\t\t\t\t\t\t\ttmod.top=0;\n\t\tif ((buf[0] = mod->d[0]))\t\t\ttmod.top=1;\n\t\tif ((buf[1] = mod->top>1 ? mod->d[1] : 0))\ttmod.top=2;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,2*BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_expand(Ri,(int)sizeof(BN_ULONG)*2) == NULL)\n\t\t\t\tgoto err;\n\t\t\tRi->neg=0;\n\t\t\tRi->d[0]=BN_MASK2;\n\t\t\tRi->d[1]=BN_MASK2;\n\t\t\tRi->top=2;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n#else\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,BN_BITS2))) goto err;\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.top = buf[0] != 0 ? 1 : 0;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_set_word(Ri,BN_MASK2)) goto err;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = 0;\n#endif\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(&mont->N);\n\t\tBN_zero(R);\n\t\tif (!BN_set_bit(R,mont->ri)) goto err;\n\t\tif ((BN_mod_inverse(Ri,R,&mont->N,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,mont->ri)) goto err;\n\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\tif (!BN_div(&(mont->Ni),NULL,Ri,&mont->N,ctx)) goto err;\n\t\t}\n#endif\n\tBN_zero(&(mont->RR));\n\tif (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;\n\tif (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tif (!BN_nnmod(B, B, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}'] |
34,306 | 0 | https://github.com/openssl/openssl/blob/9b340281873643d2b8a33047dc8bfa607f7e0c3c/crypto/lhash/lhash.c/#L191 | static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
OPENSSL_LH_DOALL_FUNC func,
OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)
{
int i;
OPENSSL_LH_NODE *a, *n;
if (lh == NULL)
return;
for (i = lh->num_nodes - 1; i >= 0; i--) {
a = lh->b[i];
while (a != NULL) {
n = a->next;
if (use_arg)
func_arg(a->data, arg);
else
func(a->data);
a = n;
}
}
} | ['static int test_tlsafile(SSL_CTX *ctx, const char *base_name,\n BIO *f, const char *path)\n{\n char *line;\n int testno = 0;\n int ret = 1;\n SSL *ssl;\n while (ret > 0 && (line = read_to_eol(f)) != NULL) {\n STACK_OF(X509) *chain;\n int ntlsa;\n int ncert;\n int noncheck;\n int want;\n int want_depth;\n int off;\n int i;\n int ok;\n int err;\n int mdpth;\n if (*line == \'\\0\' || *line == \'#\')\n continue;\n ++testno;\n if (sscanf(line, "%d %d %d %d %d%n",\n &ntlsa, &ncert, &noncheck, &want, &want_depth, &off) != 5\n || !allws(line + off)) {\n TEST_error("Malformed line for test %d", testno);\n return 0;\n }\n if (!TEST_ptr(ssl = SSL_new(ctx)))\n return 0;\n SSL_set_connect_state(ssl);\n if (SSL_dane_enable(ssl, base_name) <= 0) {\n SSL_free(ssl);\n return 0;\n }\n if (noncheck)\n SSL_dane_set_flags(ssl, DANE_FLAG_NO_DANE_EE_NAMECHECKS);\n for (i = 0; i < ntlsa; ++i) {\n if ((line = read_to_eol(f)) == NULL || !tlsa_import_rr(ssl, line)) {\n SSL_free(ssl);\n return 0;\n }\n }\n ERR_clear_error();\n if (!TEST_ptr(chain = load_chain(f, ncert))) {\n SSL_free(ssl);\n return 0;\n }\n ok = verify_chain(ssl, chain);\n sk_X509_pop_free(chain, X509_free);\n err = SSL_get_verify_result(ssl);\n SSL_set_verify_result(ssl, X509_V_OK);\n mdpth = SSL_get0_dane_authority(ssl, NULL, NULL);\n SSL_set_verify_result(ssl, err);\n SSL_free(ssl);\n if (!TEST_int_eq(err, want)) {\n if (want == X509_V_OK)\n TEST_info("Verification failure in test %d: %d=%s",\n testno, err, X509_verify_cert_error_string(err));\n else\n TEST_info("Unexpected error in test %d", testno);\n ret = 0;\n continue;\n }\n if (!TEST_false(want == 0 && ok == 0)) {\n TEST_info("Verification failure in test %d: ok=0", testno);\n ret = 0;\n continue;\n }\n if (!TEST_int_eq(mdpth, want_depth)) {\n TEST_info("In test test %d", testno);\n ret = 0;\n }\n }\n ERR_clear_error();\n return ret;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return NULL;\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return NULL;\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->references = 1;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL) {\n OPENSSL_free(s);\n s = NULL;\n goto err;\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->dane.flags = ctx->dane.flags;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->max_early_data = ctx->max_early_data;\n s->recv_max_early_data = ctx->recv_max_early_data;\n s->num_tickets = ctx->num_tickets;\n s->pha_enabled = ctx->pha_enabled;\n s->tls13_ciphersuites = sk_SSL_CIPHER_dup(ctx->tls13_ciphersuites);\n if (s->tls13_ciphersuites == NULL)\n goto err;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n s->msg_callback = ctx->msg_callback;\n s->msg_callback_arg = ctx->msg_callback_arg;\n s->verify_mode = ctx->verify_mode;\n s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n s->record_padding_cb = ctx->record_padding_cb;\n s->record_padding_arg = ctx->record_padding_arg;\n s->block_padding = ctx->block_padding;\n s->sid_ctx_length = ctx->sid_ctx_length;\n if (!ossl_assert(s->sid_ctx_length <= sizeof(s->sid_ctx)))\n goto err;\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->ext.max_fragment_len_mode = ctx->ext.max_fragment_len_mode;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->ext.debug_cb = 0;\n s->ext.debug_arg = NULL;\n s->ext.ticket_expected = 0;\n s->ext.status_type = ctx->ext.status_type;\n s->ext.status_expected = 0;\n s->ext.ocsp.ids = NULL;\n s->ext.ocsp.exts = NULL;\n s->ext.ocsp.resp = NULL;\n s->ext.ocsp.resp_len = 0;\n SSL_CTX_up_ref(ctx);\n s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n if (ctx->ext.ecpointformats) {\n s->ext.ecpointformats =\n OPENSSL_memdup(ctx->ext.ecpointformats,\n ctx->ext.ecpointformats_len);\n if (!s->ext.ecpointformats)\n goto err;\n s->ext.ecpointformats_len =\n ctx->ext.ecpointformats_len;\n }\n if (ctx->ext.supportedgroups) {\n s->ext.supportedgroups =\n OPENSSL_memdup(ctx->ext.supportedgroups,\n ctx->ext.supportedgroups_len\n * sizeof(*ctx->ext.supportedgroups));\n if (!s->ext.supportedgroups)\n goto err;\n s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n s->ext.npn = NULL;\n#endif\n if (s->ctx->ext.alpn) {\n s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n if (s->ext.alpn == NULL)\n goto err;\n memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n s->ext.alpn_len = s->ctx->ext.alpn_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n s->key_update = SSL_KEY_UPDATE_NONE;\n s->allow_early_data_cb = ctx->allow_early_data_cb;\n s->allow_early_data_cb_data = ctx->allow_early_data_cb_data;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->psk_find_session_cb = ctx->psk_find_session_cb;\n s->psk_use_session_cb = ctx->psk_use_session_cb;\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n RECORD_LAYER_release(&s->rlayer);\n ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n s->wbio = NULL;\n BIO_free_all(s->rbio);\n s->rbio = NULL;\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n sk_SSL_CIPHER_free(s->tls13_ciphersuites);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n SSL_SESSION_free(s->psksession);\n OPENSSL_free(s->psksession_id);\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->ext.hostname);\n SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->ext.ecpointformats);\n OPENSSL_free(s->ext.supportedgroups);\n#endif\n sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->ext.scts);\n#endif\n OPENSSL_free(s->ext.ocsp.resp);\n OPENSSL_free(s->ext.alpn);\n OPENSSL_free(s->ext.tls13_cookie);\n OPENSSL_free(s->clienthello);\n OPENSSL_free(s->pha_context);\n EVP_MD_CTX_free(s->pha_dgst);\n sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(s->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n int i;\n if (a == NULL)\n return;\n CRYPTO_DOWN_REF(&a->references, &i, a->lock);\n REF_PRINT_COUNT("SSL_CTX", a);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(a->param);\n dane_ctx_final(&a->dane);\n if (a->sessions != NULL)\n SSL_CTX_flush_sessions(a, 0);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n lh_SSL_SESSION_free(a->sessions);\n X509_STORE_free(a->cert_store);\n#ifndef OPENSSL_NO_CT\n CTLOG_STORE_free(a->ctlog_store);\n#endif\n sk_SSL_CIPHER_free(a->cipher_list);\n sk_SSL_CIPHER_free(a->cipher_list_by_id);\n sk_SSL_CIPHER_free(a->tls13_ciphersuites);\n ssl_cert_free(a->cert);\n sk_X509_NAME_pop_free(a->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(a->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(a->extra_certs, X509_free);\n a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(a->ext.ecpointformats);\n OPENSSL_free(a->ext.supportedgroups);\n#endif\n OPENSSL_free(a->ext.alpn);\n OPENSSL_secure_free(a->ext.secure);\n CRYPTO_THREAD_lock_free(a->lock);\n OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n unsigned long i;\n TIMEOUT_PARAM tp;\n tp.ctx = s;\n tp.cache = s->sessions;\n if (tp.cache == NULL)\n return;\n tp.time = t;\n CRYPTO_THREAD_write_lock(s->lock);\n i = lh_SSL_SESSION_get_down_load(s->sessions);\n lh_SSL_SESSION_set_down_load(s->sessions, 0);\n lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);\n lh_SSL_SESSION_set_down_load(s->sessions, i);\n CRYPTO_THREAD_unlock(s->lock);\n}', 'IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM)', 'void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)\n{\n doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);\n}', 'static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,\n OPENSSL_LH_DOALL_FUNC func,\n OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)\n{\n int i;\n OPENSSL_LH_NODE *a, *n;\n if (lh == NULL)\n return;\n for (i = lh->num_nodes - 1; i >= 0; i--) {\n a = lh->b[i];\n while (a != NULL) {\n n = a->next;\n if (use_arg)\n func_arg(a->data, arg);\n else\n func(a->data);\n a = n;\n }\n }\n}'] |
34,307 | 0 | https://github.com/libav/libav/blob/f924d52975ec5bbae41d26f79be2373a1b12046b/libavformat/srtp.c/#L151 | int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr)
{
uint8_t iv[16] = { 0 }, hmac[20];
int len = *lenptr;
int ext, seq_largest;
uint32_t ssrc, roc;
uint64_t index;
int rtcp;
if (len < s->hmac_size)
return AVERROR_INVALIDDATA;
rtcp = RTP_PT_IS_RTCP(buf[1]);
av_hmac_init(s->hmac, rtcp ? s->rtcp_auth : s->rtp_auth, sizeof(s->rtp_auth));
av_hmac_update(s->hmac, buf, len - s->hmac_size);
if (!rtcp) {
int seq = AV_RB16(buf + 2);
uint32_t v;
uint8_t rocbuf[4];
seq_largest = s->seq_initialized ? s->seq_largest : seq;
v = roc = s->roc;
if (seq_largest < 32768) {
if (seq - seq_largest > 32768)
v = roc - 1;
} else {
if (seq_largest - 32768 > seq)
v = roc + 1;
}
if (v == roc) {
seq_largest = FFMAX(seq_largest, seq);
} else if (v == roc + 1) {
seq_largest = seq;
roc = v;
}
index = seq + (((uint64_t)v) << 16);
AV_WB32(rocbuf, roc);
av_hmac_update(s->hmac, rocbuf, 4);
}
av_hmac_final(s->hmac, hmac, sizeof(hmac));
if (memcmp(hmac, buf + len - s->hmac_size, s->hmac_size)) {
av_log(NULL, AV_LOG_WARNING, "HMAC mismatch\n");
return AVERROR_INVALIDDATA;
}
len -= s->hmac_size;
*lenptr = len;
if (len < 12)
return AVERROR_INVALIDDATA;
if (rtcp) {
uint32_t srtcp_index = AV_RB32(buf + len - 4);
len -= 4;
*lenptr = len;
ssrc = AV_RB32(buf + 4);
index = srtcp_index & 0x7fffffff;
buf += 8;
len -= 8;
if (!(srtcp_index & 0x80000000))
return 0;
} else {
s->seq_initialized = 1;
s->seq_largest = seq_largest;
s->roc = roc;
ext = buf[0] & 0x10;
ssrc = AV_RB32(buf + 8);
buf += 12;
len -= 12;
if (ext) {
if (len < 4)
return AVERROR_INVALIDDATA;
ext = (AV_RB16(buf + 2) + 1) * 4;
if (len < ext)
return AVERROR_INVALIDDATA;
len -= ext;
buf += ext;
}
}
create_iv(iv, rtcp ? s->rtcp_salt : s->rtp_salt, index, ssrc);
av_aes_init(s->aes, rtcp ? s->rtcp_key : s->rtp_key, 128, 0);
encrypt_counter(s->aes, iv, buf, len);
return 0;
} | ['static int srtp_read(URLContext *h, uint8_t *buf, int size)\n{\n SRTPProtoContext *s = h->priv_data;\n int ret;\nstart:\n ret = ffurl_read(s->rtp_hd, buf, size);\n if (ret > 0 && s->srtp_in.aes) {\n if (ff_srtp_decrypt(&s->srtp_in, buf, &ret) < 0)\n goto start;\n }\n return ret;\n}', 'int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr)\n{\n uint8_t iv[16] = { 0 }, hmac[20];\n int len = *lenptr;\n int ext, seq_largest;\n uint32_t ssrc, roc;\n uint64_t index;\n int rtcp;\n if (len < s->hmac_size)\n return AVERROR_INVALIDDATA;\n rtcp = RTP_PT_IS_RTCP(buf[1]);\n av_hmac_init(s->hmac, rtcp ? s->rtcp_auth : s->rtp_auth, sizeof(s->rtp_auth));\n av_hmac_update(s->hmac, buf, len - s->hmac_size);\n if (!rtcp) {\n int seq = AV_RB16(buf + 2);\n uint32_t v;\n uint8_t rocbuf[4];\n seq_largest = s->seq_initialized ? s->seq_largest : seq;\n v = roc = s->roc;\n if (seq_largest < 32768) {\n if (seq - seq_largest > 32768)\n v = roc - 1;\n } else {\n if (seq_largest - 32768 > seq)\n v = roc + 1;\n }\n if (v == roc) {\n seq_largest = FFMAX(seq_largest, seq);\n } else if (v == roc + 1) {\n seq_largest = seq;\n roc = v;\n }\n index = seq + (((uint64_t)v) << 16);\n AV_WB32(rocbuf, roc);\n av_hmac_update(s->hmac, rocbuf, 4);\n }\n av_hmac_final(s->hmac, hmac, sizeof(hmac));\n if (memcmp(hmac, buf + len - s->hmac_size, s->hmac_size)) {\n av_log(NULL, AV_LOG_WARNING, "HMAC mismatch\\n");\n return AVERROR_INVALIDDATA;\n }\n len -= s->hmac_size;\n *lenptr = len;\n if (len < 12)\n return AVERROR_INVALIDDATA;\n if (rtcp) {\n uint32_t srtcp_index = AV_RB32(buf + len - 4);\n len -= 4;\n *lenptr = len;\n ssrc = AV_RB32(buf + 4);\n index = srtcp_index & 0x7fffffff;\n buf += 8;\n len -= 8;\n if (!(srtcp_index & 0x80000000))\n return 0;\n } else {\n s->seq_initialized = 1;\n s->seq_largest = seq_largest;\n s->roc = roc;\n ext = buf[0] & 0x10;\n ssrc = AV_RB32(buf + 8);\n buf += 12;\n len -= 12;\n if (ext) {\n if (len < 4)\n return AVERROR_INVALIDDATA;\n ext = (AV_RB16(buf + 2) + 1) * 4;\n if (len < ext)\n return AVERROR_INVALIDDATA;\n len -= ext;\n buf += ext;\n }\n }\n create_iv(iv, rtcp ? s->rtcp_salt : s->rtp_salt, index, ssrc);\n av_aes_init(s->aes, rtcp ? s->rtcp_key : s->rtp_key, 128, 0);\n encrypt_counter(s->aes, iv, buf, len);\n return 0;\n}'] |
34,308 | 0 | https://github.com/openssl/openssl/blob/ff281ee8369350d88e8b57af139614f5683e1e8c/test/handshake_helper.c/#L135 | static int select_server_ctx(SSL *s, void *arg, int ignore)
{
const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
HANDSHAKE_EX_DATA *ex_data =
(HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
if (servername == NULL) {
ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
return SSL_TLSEXT_ERR_NOACK;
}
if (strcmp(servername, "server2") == 0) {
SSL_CTX *new_ctx = (SSL_CTX*)arg;
SSL_set_SSL_CTX(s, new_ctx);
SSL_clear_options(s, 0xFFFFFFFFL);
SSL_set_options(s, SSL_CTX_get_options(new_ctx));
ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;
return SSL_TLSEXT_ERR_OK;
} else if (strcmp(servername, "server1") == 0) {
ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
return SSL_TLSEXT_ERR_OK;
} else if (ignore) {
ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
return SSL_TLSEXT_ERR_NOACK;
} else {
return SSL_TLSEXT_ERR_ALERT_FATAL;
}
} | ['static int select_server_ctx(SSL *s, void *arg, int ignore)\n{\n const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);\n HANDSHAKE_EX_DATA *ex_data =\n (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n if (servername == NULL) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_NOACK;\n }\n if (strcmp(servername, "server2") == 0) {\n SSL_CTX *new_ctx = (SSL_CTX*)arg;\n SSL_set_SSL_CTX(s, new_ctx);\n SSL_clear_options(s, 0xFFFFFFFFL);\n SSL_set_options(s, SSL_CTX_get_options(new_ctx));\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;\n return SSL_TLSEXT_ERR_OK;\n } else if (strcmp(servername, "server1") == 0) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_OK;\n } else if (ignore) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_NOACK;\n } else {\n return SSL_TLSEXT_ERR_ALERT_FATAL;\n }\n}', 'const char *SSL_get_servername(const SSL *s, const int type)\n{\n if (type != TLSEXT_NAMETYPE_host_name)\n return NULL;\n return s->session && !s->ext.hostname ?\n s->session->ext.hostname : s->ext.hostname;\n}', 'void *SSL_get_ex_data(const SSL *s, int idx)\n{\n return (CRYPTO_get_ex_data(&s->ex_data, idx));\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n return NULL;\n return sk_void_value(ad->sk, idx);\n}'] |
34,309 | 0 | https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L271 | static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
} | ['int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)\n{\n int i, n = 0, len, nid, first, use_bn;\n BIGNUM *bl;\n unsigned long l;\n const unsigned char *p;\n char tbuf[DECIMAL_SIZE(i) + DECIMAL_SIZE(l) + 2];\n if (buf && buf_len > 0)\n buf[0] = \'\\0\';\n if ((a == NULL) || (a->data == NULL))\n return (0);\n if (!no_name && (nid = OBJ_obj2nid(a)) != NID_undef) {\n const char *s;\n s = OBJ_nid2ln(nid);\n if (s == NULL)\n s = OBJ_nid2sn(nid);\n if (s) {\n if (buf)\n OPENSSL_strlcpy(buf, s, buf_len);\n n = strlen(s);\n return n;\n }\n }\n len = a->length;\n p = a->data;\n first = 1;\n bl = NULL;\n while (len > 0) {\n l = 0;\n use_bn = 0;\n for (;;) {\n unsigned char c = *p++;\n len--;\n if ((len == 0) && (c & 0x80))\n goto err;\n if (use_bn) {\n if (!BN_add_word(bl, c & 0x7f))\n goto err;\n } else\n l |= c & 0x7f;\n if (!(c & 0x80))\n break;\n if (!use_bn && (l > (ULONG_MAX >> 7L))) {\n if (bl == NULL && (bl = BN_new()) == NULL)\n goto err;\n if (!BN_set_word(bl, l))\n goto err;\n use_bn = 1;\n }\n if (use_bn) {\n if (!BN_lshift(bl, bl, 7))\n goto err;\n } else\n l <<= 7L;\n }\n if (first) {\n first = 0;\n if (l >= 80) {\n i = 2;\n if (use_bn) {\n if (!BN_sub_word(bl, 80))\n goto err;\n } else\n l -= 80;\n } else {\n i = (int)(l / 40);\n l -= (long)(i * 40);\n }\n if (buf && (buf_len > 1)) {\n *buf++ = i + \'0\';\n *buf = \'\\0\';\n buf_len--;\n }\n n++;\n }\n if (use_bn) {\n char *bndec;\n bndec = BN_bn2dec(bl);\n if (!bndec)\n goto err;\n i = strlen(bndec);\n if (buf) {\n if (buf_len > 1) {\n *buf++ = \'.\';\n *buf = \'\\0\';\n buf_len--;\n }\n OPENSSL_strlcpy(buf, bndec, buf_len);\n if (i > buf_len) {\n buf += buf_len;\n buf_len = 0;\n } else {\n buf += i;\n buf_len -= i;\n }\n }\n n++;\n n += i;\n OPENSSL_free(bndec);\n } else {\n BIO_snprintf(tbuf, sizeof tbuf, ".%lu", l);\n i = strlen(tbuf);\n if (buf && (buf_len > 0)) {\n OPENSSL_strlcpy(buf, tbuf, buf_len);\n if (i > buf_len) {\n buf += buf_len;\n buf_len = 0;\n } else {\n buf += i;\n buf_len -= i;\n }\n }\n n += i;\n l = 0;\n }\n }\n BN_free(bl);\n return n;\n err:\n BN_free(bl);\n return -1;\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'int BN_add_word(BIGNUM *a, BN_ULONG w)\n{\n BN_ULONG l;\n int i;\n bn_check_top(a);\n w &= BN_MASK2;\n if (!w)\n return 1;\n if (BN_is_zero(a))\n return BN_set_word(a, w);\n if (a->neg) {\n a->neg = 0;\n i = BN_sub_word(a, w);\n if (!BN_is_zero(a))\n a->neg = !(a->neg);\n return (i);\n }\n for (i = 0; w != 0 && i < a->top; i++) {\n a->d[i] = l = (a->d[i] + w) & BN_MASK2;\n w = (w > l) ? 1 : 0;\n }\n if (w && i == a->top) {\n if (bn_wexpand(a, a->top + 1) == NULL)\n return 0;\n a->top++;\n a->d[i] = w;\n }\n bn_check_top(a);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}'] |
34,310 | 0 | https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/ssl/record/ssl3_record.c/#L937 | int n_ssl3_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int send)
{
unsigned char *mac_sec, *seq;
const EVP_MD_CTX *hash;
unsigned char *p, rec_char;
size_t md_size;
int npad;
int t;
if (send) {
mac_sec = &(ssl->s3->write_mac_secret[0]);
seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);
hash = ssl->write_hash;
} else {
mac_sec = &(ssl->s3->read_mac_secret[0]);
seq = RECORD_LAYER_get_read_sequence(&ssl->rlayer);
hash = ssl->read_hash;
}
t = EVP_MD_CTX_size(hash);
if (t < 0)
return -1;
md_size = t;
npad = (48 / md_size) * md_size;
if (!send &&
EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&
ssl3_cbc_record_digest_supported(hash)) {
unsigned char header[75];
unsigned j = 0;
memcpy(header + j, mac_sec, md_size);
j += md_size;
memcpy(header + j, ssl3_pad_1, npad);
j += npad;
memcpy(header + j, seq, 8);
j += 8;
header[j++] = rec->type;
header[j++] = rec->length >> 8;
header[j++] = rec->length & 0xff;
if (ssl3_cbc_digest_record(hash,
md, &md_size,
header, rec->input,
rec->length + md_size, rec->orig_len,
mac_sec, md_size, 1) <= 0)
return -1;
} else {
unsigned int md_size_u;
EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
if (md_ctx == NULL)
return -1;
rec_char = rec->type;
p = md;
s2n(rec->length, p);
if (EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0
|| EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0
|| EVP_DigestUpdate(md_ctx, ssl3_pad_1, npad) <= 0
|| EVP_DigestUpdate(md_ctx, seq, 8) <= 0
|| EVP_DigestUpdate(md_ctx, &rec_char, 1) <= 0
|| EVP_DigestUpdate(md_ctx, md, 2) <= 0
|| EVP_DigestUpdate(md_ctx, rec->input, rec->length) <= 0
|| EVP_DigestFinal_ex(md_ctx, md, NULL) <= 0
|| EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0
|| EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0
|| EVP_DigestUpdate(md_ctx, ssl3_pad_2, npad) <= 0
|| EVP_DigestUpdate(md_ctx, md, md_size) <= 0
|| EVP_DigestFinal_ex(md_ctx, md, &md_size_u) <= 0) {
EVP_MD_CTX_reset(md_ctx);
return -1;
}
md_size = md_size_u;
EVP_MD_CTX_free(md_ctx);
}
ssl3_record_sequence_update(seq);
return (md_size);
} | ['int n_ssl3_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int send)\n{\n unsigned char *mac_sec, *seq;\n const EVP_MD_CTX *hash;\n unsigned char *p, rec_char;\n size_t md_size;\n int npad;\n int t;\n if (send) {\n mac_sec = &(ssl->s3->write_mac_secret[0]);\n seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);\n hash = ssl->write_hash;\n } else {\n mac_sec = &(ssl->s3->read_mac_secret[0]);\n seq = RECORD_LAYER_get_read_sequence(&ssl->rlayer);\n hash = ssl->read_hash;\n }\n t = EVP_MD_CTX_size(hash);\n if (t < 0)\n return -1;\n md_size = t;\n npad = (48 / md_size) * md_size;\n if (!send &&\n EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n ssl3_cbc_record_digest_supported(hash)) {\n unsigned char header[75];\n unsigned j = 0;\n memcpy(header + j, mac_sec, md_size);\n j += md_size;\n memcpy(header + j, ssl3_pad_1, npad);\n j += npad;\n memcpy(header + j, seq, 8);\n j += 8;\n header[j++] = rec->type;\n header[j++] = rec->length >> 8;\n header[j++] = rec->length & 0xff;\n if (ssl3_cbc_digest_record(hash,\n md, &md_size,\n header, rec->input,\n rec->length + md_size, rec->orig_len,\n mac_sec, md_size, 1) <= 0)\n return -1;\n } else {\n unsigned int md_size_u;\n EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();\n if (md_ctx == NULL)\n return -1;\n rec_char = rec->type;\n p = md;\n s2n(rec->length, p);\n if (EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0\n || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0\n || EVP_DigestUpdate(md_ctx, ssl3_pad_1, npad) <= 0\n || EVP_DigestUpdate(md_ctx, seq, 8) <= 0\n || EVP_DigestUpdate(md_ctx, &rec_char, 1) <= 0\n || EVP_DigestUpdate(md_ctx, md, 2) <= 0\n || EVP_DigestUpdate(md_ctx, rec->input, rec->length) <= 0\n || EVP_DigestFinal_ex(md_ctx, md, NULL) <= 0\n || EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0\n || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0\n || EVP_DigestUpdate(md_ctx, ssl3_pad_2, npad) <= 0\n || EVP_DigestUpdate(md_ctx, md, md_size) <= 0\n || EVP_DigestFinal_ex(md_ctx, md, &md_size_u) <= 0) {\n EVP_MD_CTX_reset(md_ctx);\n return -1;\n }\n md_size = md_size_u;\n EVP_MD_CTX_free(md_ctx);\n }\n ssl3_record_sequence_update(seq);\n return (md_size);\n}', 'const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx)\n{\n if (!ctx)\n return NULL;\n return ctx->digest;\n}', 'int EVP_MD_size(const EVP_MD *md)\n{\n if (!md) {\n EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);\n return -1;\n }\n return md->md_size;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)\n{\n unsigned char *tmp_buf;\n if ((in == NULL) || (in->digest == NULL)) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);\n return 0;\n }\n#ifndef OPENSSL_NO_ENGINE\n if (in->engine && !ENGINE_init(in->engine)) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);\n return 0;\n }\n#endif\n if (out->digest == in->digest) {\n tmp_buf = out->md_data;\n EVP_MD_CTX_set_flags(out, EVP_MD_CTX_FLAG_REUSE);\n } else\n tmp_buf = NULL;\n EVP_MD_CTX_reset(out);\n memcpy(out, in, sizeof(*out));\n out->md_data = NULL;\n out->pctx = NULL;\n if (in->md_data && out->digest->ctx_size) {\n if (tmp_buf)\n out->md_data = tmp_buf;\n else {\n out->md_data = OPENSSL_malloc(out->digest->ctx_size);\n if (out->md_data == NULL) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n }\n memcpy(out->md_data, in->md_data, out->digest->ctx_size);\n }\n out->update = in->update;\n if (in->pctx) {\n out->pctx = EVP_PKEY_CTX_dup(in->pctx);\n if (!out->pctx) {\n EVP_MD_CTX_reset(out);\n return 0;\n }\n }\n if (out->digest->copy)\n return out->digest->copy(out, in);\n return 1;\n}', 'int ENGINE_init(ENGINE *e)\n{\n int ret;\n if (e == NULL) {\n ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {\n ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n CRYPTO_THREAD_write_lock(global_engine_lock);\n ret = engine_unlocked_init(e);\n CRYPTO_THREAD_unlock(global_engine_lock);\n return ret;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}'] |
34,311 | 0 | https://github.com/libav/libav/blob/366ba2dee1f2b17825b42e2164d3b9879f0271b1/libavcodec/h264_mb.c/#L697 | static av_always_inline void hl_decode_mb_predict_luma(const H264Context *h,
H264SliceContext *sl,
int mb_type, int simple,
int transform_bypass,
int pixel_shift,
const int *block_offset,
int linesize,
uint8_t *dest_y, int p)
{
void (*idct_add)(uint8_t *dst, int16_t *block, int stride);
void (*idct_dc_add)(uint8_t *dst, int16_t *block, int stride);
int i;
int qscale = p == 0 ? sl->qscale : sl->chroma_qp[p - 1];
block_offset += 16 * p;
if (IS_INTRA4x4(mb_type)) {
if (IS_8x8DCT(mb_type)) {
if (transform_bypass) {
idct_dc_add =
idct_add = h->h264dsp.h264_add_pixels8_clear;
} else {
idct_dc_add = h->h264dsp.h264_idct8_dc_add;
idct_add = h->h264dsp.h264_idct8_add;
}
for (i = 0; i < 16; i += 4) {
uint8_t *const ptr = dest_y + block_offset[i];
const int dir = sl->intra4x4_pred_mode_cache[scan8[i]];
if (transform_bypass && h->ps.sps->profile_idc == 244 && dir <= 1) {
h->hpc.pred8x8l_add[dir](ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
} else {
const int nnz = sl->non_zero_count_cache[scan8[i + p * 16]];
h->hpc.pred8x8l[dir](ptr, (sl->topleft_samples_available << i) & 0x8000,
(sl->topright_samples_available << i) & 0x4000, linesize);
if (nnz) {
if (nnz == 1 && dctcoef_get(sl->mb, pixel_shift, i * 16 + p * 256))
idct_dc_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
else
idct_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
}
}
}
} else {
if (transform_bypass) {
idct_dc_add =
idct_add = h->h264dsp.h264_add_pixels4_clear;
} else {
idct_dc_add = h->h264dsp.h264_idct_dc_add;
idct_add = h->h264dsp.h264_idct_add;
}
for (i = 0; i < 16; i++) {
uint8_t *const ptr = dest_y + block_offset[i];
const int dir = sl->intra4x4_pred_mode_cache[scan8[i]];
if (transform_bypass && h->ps.sps->profile_idc == 244 && dir <= 1) {
h->hpc.pred4x4_add[dir](ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
} else {
uint8_t *topright;
int nnz, tr;
uint64_t tr_high;
if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) {
const int topright_avail = (sl->topright_samples_available << i) & 0x8000;
assert(sl->mb_y || linesize <= block_offset[i]);
if (!topright_avail) {
if (pixel_shift) {
tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;
topright = (uint8_t *)&tr_high;
} else {
tr = ptr[3 - linesize] * 0x01010101u;
topright = (uint8_t *)&tr;
}
} else
topright = ptr + (4 << pixel_shift) - linesize;
} else
topright = NULL;
h->hpc.pred4x4[dir](ptr, topright, linesize);
nnz = sl->non_zero_count_cache[scan8[i + p * 16]];
if (nnz) {
if (nnz == 1 && dctcoef_get(sl->mb, pixel_shift, i * 16 + p * 256))
idct_dc_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
else
idct_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
}
}
}
}
} else {
h->hpc.pred16x16[sl->intra16x16_pred_mode](dest_y, linesize);
if (sl->non_zero_count_cache[scan8[LUMA_DC_BLOCK_INDEX + p]]) {
if (!transform_bypass)
h->h264dsp.h264_luma_dc_dequant_idct(sl->mb + (p * 256 << pixel_shift),
sl->mb_luma_dc[p],
h->ps.pps->dequant4_coeff[p][qscale][0]);
else {
static const uint8_t dc_mapping[16] = {
0 * 16, 1 * 16, 4 * 16, 5 * 16,
2 * 16, 3 * 16, 6 * 16, 7 * 16,
8 * 16, 9 * 16, 12 * 16, 13 * 16,
10 * 16, 11 * 16, 14 * 16, 15 * 16
};
for (i = 0; i < 16; i++)
dctcoef_set(sl->mb + (p * 256 << pixel_shift),
pixel_shift, dc_mapping[i],
dctcoef_get(sl->mb_luma_dc[p],
pixel_shift, i));
}
}
}
} | ['static int h264_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame, AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n H264Context *h = avctx->priv_data;\n AVFrame *pict = data;\n int buf_index = 0;\n int ret;\n h->flags = avctx->flags;\n h->setup_finished = 0;\nout:\n if (buf_size == 0) {\n H264Picture *out;\n int i, out_idx;\n h->cur_pic_ptr = NULL;\n out = h->delayed_pic[0];\n out_idx = 0;\n for (i = 1;\n h->delayed_pic[i] &&\n !h->delayed_pic[i]->f->key_frame &&\n !h->delayed_pic[i]->mmco_reset;\n i++)\n if (h->delayed_pic[i]->poc < out->poc) {\n out = h->delayed_pic[i];\n out_idx = i;\n }\n for (i = out_idx; h->delayed_pic[i]; i++)\n h->delayed_pic[i] = h->delayed_pic[i + 1];\n if (out) {\n ret = output_frame(h, pict, out->f);\n if (ret < 0)\n return ret;\n *got_frame = 1;\n }\n return buf_index;\n }\n buf_index = decode_nal_units(h, buf, buf_size);\n if (buf_index < 0)\n return AVERROR_INVALIDDATA;\n if (!h->cur_pic_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {\n buf_size = 0;\n goto out;\n }\n if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) {\n if (avctx->skip_frame >= AVDISCARD_NONREF)\n return 0;\n av_log(avctx, AV_LOG_ERROR, "no frame!\\n");\n return AVERROR_INVALIDDATA;\n }\n if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) ||\n (h->mb_y >= h->mb_height && h->mb_height)) {\n if (avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)\n decode_postinit(h, 1);\n ff_h264_field_end(h, &h->slice_ctx[0], 0);\n *got_frame = 0;\n if (h->next_output_pic && ((avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) ||\n h->next_output_pic->recovered)) {\n if (!h->next_output_pic->recovered)\n h->next_output_pic->f->flags |= AV_FRAME_FLAG_CORRUPT;\n ret = output_frame(h, pict, h->next_output_pic->f);\n if (ret < 0)\n return ret;\n *got_frame = 1;\n }\n }\n assert(pict->buf[0] || !*got_frame);\n return get_consumed_bytes(buf_index, buf_size);\n}', 'static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)\n{\n AVCodecContext *const avctx = h->avctx;\n unsigned context_count = 0;\n int nals_needed = 0;\n int i, ret = 0;\n if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {\n h->current_slice = 0;\n if (!h->first_field)\n h->cur_pic_ptr = NULL;\n ff_h264_sei_uninit(&h->sei);\n }\n ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc,\n h->nal_length_size, avctx->codec_id);\n if (ret < 0) {\n av_log(avctx, AV_LOG_ERROR,\n "Error splitting the input into NAL units.\\n");\n return ret;\n }\n if (avctx->active_thread_type & FF_THREAD_FRAME)\n nals_needed = get_last_needed_nal(h);\n for (i = 0; i < h->pkt.nb_nals; i++) {\n H2645NAL *nal = &h->pkt.nals[i];\n H264SliceContext *sl = &h->slice_ctx[context_count];\n int err;\n if (avctx->skip_frame >= AVDISCARD_NONREF &&\n nal->ref_idc == 0 && nal->type != NAL_SEI)\n continue;\n h->nal_ref_idc = nal->ref_idc;\n h->nal_unit_type = nal->type;\n err = 0;\n switch (nal->type) {\n case NAL_IDR_SLICE:\n if (nal->type != NAL_IDR_SLICE) {\n av_log(h->avctx, AV_LOG_ERROR,\n "Invalid mix of idr and non-idr slices\\n");\n ret = -1;\n goto end;\n }\n idr(h);\n case NAL_SLICE:\n sl->gb = nal->gb;\n if ((err = ff_h264_decode_slice_header(h, sl)))\n break;\n if (h->sei.recovery_point.recovery_frame_cnt >= 0 && h->recovery_frame < 0) {\n h->recovery_frame = (h->poc.frame_num + h->sei.recovery_point.recovery_frame_cnt) &\n ((1 << h->ps.sps->log2_max_frame_num) - 1);\n }\n h->cur_pic_ptr->f->key_frame |=\n (nal->type == NAL_IDR_SLICE) || (h->sei.recovery_point.recovery_frame_cnt >= 0);\n if (nal->type == NAL_IDR_SLICE || h->recovery_frame == h->poc.frame_num) {\n h->recovery_frame = -1;\n h->cur_pic_ptr->recovered = 1;\n }\n if (nal->type == NAL_IDR_SLICE)\n h->frame_recovered |= FRAME_RECOVERED_IDR;\n h->cur_pic_ptr->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_IDR);\n if (h->current_slice == 1) {\n if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS))\n decode_postinit(h, i >= nals_needed);\n if (h->avctx->hwaccel &&\n (ret = h->avctx->hwaccel->start_frame(h->avctx, NULL, 0)) < 0)\n return ret;\n }\n if (sl->redundant_pic_count == 0 &&\n (avctx->skip_frame < AVDISCARD_NONREF || nal->ref_idc) &&\n (avctx->skip_frame < AVDISCARD_BIDIR ||\n sl->slice_type_nos != AV_PICTURE_TYPE_B) &&\n (avctx->skip_frame < AVDISCARD_NONKEY ||\n h->cur_pic_ptr->f->key_frame) &&\n avctx->skip_frame < AVDISCARD_ALL) {\n if (avctx->hwaccel) {\n ret = avctx->hwaccel->decode_slice(avctx, nal->raw_data, nal->raw_size);\n if (ret < 0)\n return ret;\n } else\n context_count++;\n }\n break;\n case NAL_DPA:\n case NAL_DPB:\n case NAL_DPC:\n avpriv_request_sample(avctx, "data partitioning");\n ret = AVERROR(ENOSYS);\n goto end;\n break;\n case NAL_SEI:\n ret = ff_h264_sei_decode(&h->sei, &nal->gb, &h->ps, avctx);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n break;\n case NAL_SPS:\n ret = ff_h264_decode_seq_parameter_set(&nal->gb, avctx, &h->ps);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n break;\n case NAL_PPS:\n ret = ff_h264_decode_picture_parameter_set(&nal->gb, avctx, &h->ps,\n nal->size_bits);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n break;\n case NAL_AUD:\n case NAL_END_SEQUENCE:\n case NAL_END_STREAM:\n case NAL_FILLER_DATA:\n case NAL_SPS_EXT:\n case NAL_AUXILIARY_SLICE:\n break;\n case NAL_FF_IGNORE:\n break;\n default:\n av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\\n",\n nal->type, nal->size_bits);\n }\n if (context_count == h->nb_slice_ctx) {\n ret = ff_h264_execute_decode_slices(h, context_count);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n context_count = 0;\n }\n if (err < 0) {\n av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\\n");\n sl->ref_count[0] = sl->ref_count[1] = sl->list_count = 0;\n }\n }\n if (context_count) {\n ret = ff_h264_execute_decode_slices(h, context_count);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n }\n ret = 0;\nend:\n if (h->cur_pic_ptr && !h->droppable) {\n ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n h->picture_structure == PICT_BOTTOM_FIELD);\n }\n return (ret < 0) ? ret : buf_size;\n}', 'int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,\n void *logctx, int is_nalff, int nal_length_size,\n enum AVCodecID codec_id)\n{\n int consumed, ret = 0;\n pkt->nb_nals = 0;\n while (length >= 4) {\n H2645NAL *nal;\n int extract_length = 0;\n int skip_trailing_zeros = 1;\n if (is_nalff) {\n int i;\n for (i = 0; i < nal_length_size; i++)\n extract_length = (extract_length << 8) | buf[i];\n buf += nal_length_size;\n length -= nal_length_size;\n if (extract_length > length) {\n av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit size.\\n");\n return AVERROR_INVALIDDATA;\n }\n } else {\n if (buf[2] == 0) {\n length--;\n buf++;\n continue;\n }\n if (buf[0] != 0 || buf[1] != 0 || buf[2] != 1)\n return AVERROR_INVALIDDATA;\n buf += 3;\n length -= 3;\n extract_length = length;\n }\n if (pkt->nals_allocated < pkt->nb_nals + 1) {\n int new_size = pkt->nals_allocated + 1;\n H2645NAL *tmp = av_realloc_array(pkt->nals, new_size, sizeof(*tmp));\n if (!tmp)\n return AVERROR(ENOMEM);\n pkt->nals = tmp;\n memset(pkt->nals + pkt->nals_allocated, 0,\n (new_size - pkt->nals_allocated) * sizeof(*tmp));\n pkt->nals_allocated = new_size;\n }\n nal = &pkt->nals[pkt->nb_nals++];\n consumed = ff_h2645_extract_rbsp(buf, extract_length, nal);\n if (consumed < 0)\n return consumed;\n if (consumed < length - 3 &&\n buf[consumed] == 0x00 && buf[consumed + 1] == 0x00 &&\n buf[consumed + 2] == 0x01 && buf[consumed + 3] == 0xE0)\n skip_trailing_zeros = 0;\n nal->size_bits = get_bit_length(nal, skip_trailing_zeros);\n ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);\n if (ret < 0)\n return ret;\n if (codec_id == AV_CODEC_ID_HEVC)\n ret = hevc_parse_nal_header(nal, logctx);\n else\n ret = h264_parse_nal_header(nal, logctx);\n if (ret <= 0) {\n if (ret < 0) {\n av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit %d, skipping.\\n",\n nal->type);\n }\n pkt->nb_nals--;\n }\n buf += consumed;\n length -= consumed;\n }\n return 0;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n bit_size = 0;\n buffer = NULL;\n ret = AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n return ret;\n}', 'int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count)\n{\n AVCodecContext *const avctx = h->avctx;\n H264SliceContext *sl;\n int i, j;\n if (h->avctx->hwaccel)\n return 0;\n if (context_count == 1) {\n int ret;\n h->slice_ctx[0].next_slice_idx = h->mb_width * h->mb_height;\n h->postpone_filter = 0;\n ret = decode_slice(avctx, &h->slice_ctx[0]);\n h->mb_y = h->slice_ctx[0].mb_y;\n return ret;\n } else {\n for (i = 0; i < context_count; i++) {\n int next_slice_idx = h->mb_width * h->mb_height;\n int slice_idx;\n sl = &h->slice_ctx[i];\n sl->er.error_count = 0;\n slice_idx = sl->mb_y * h->mb_width + sl->mb_x;\n for (j = 0; j < context_count; j++) {\n H264SliceContext *sl2 = &h->slice_ctx[j];\n int slice_idx2 = sl2->mb_y * h->mb_width + sl2->mb_x;\n if (i == j || slice_idx2 < slice_idx)\n continue;\n next_slice_idx = FFMIN(next_slice_idx, slice_idx2);\n }\n sl->next_slice_idx = next_slice_idx;\n }\n avctx->execute(avctx, decode_slice, h->slice_ctx,\n NULL, context_count, sizeof(h->slice_ctx[0]));\n sl = &h->slice_ctx[context_count - 1];\n h->mb_y = sl->mb_y;\n for (i = 1; i < context_count; i++)\n h->slice_ctx[0].er.error_count += h->slice_ctx[i].er.error_count;\n if (h->postpone_filter) {\n h->postpone_filter = 0;\n for (i = 0; i < context_count; i++) {\n int y_end, x_end;\n sl = &h->slice_ctx[i];\n y_end = FFMIN(sl->mb_y + 1, h->mb_height);\n x_end = (sl->mb_y >= h->mb_height) ? h->mb_width : sl->mb_x;\n for (j = sl->resync_mb_y; j < y_end; j += 1 + FIELD_OR_MBAFF_PICTURE(h)) {\n sl->mb_y = j;\n loop_filter(h, sl, j > sl->resync_mb_y ? 0 : sl->resync_mb_x,\n j == y_end - 1 ? x_end : h->mb_width);\n }\n }\n }\n }\n return 0;\n}', 'static int decode_slice(struct AVCodecContext *avctx, void *arg)\n{\n H264SliceContext *sl = arg;\n const H264Context *h = sl->h264;\n int lf_x_start = sl->mb_x;\n int orig_deblock = sl->deblocking_filter;\n int ret;\n sl->linesize = h->cur_pic_ptr->f->linesize[0];\n sl->uvlinesize = h->cur_pic_ptr->f->linesize[1];\n ret = alloc_scratch_buffers(sl, sl->linesize);\n if (ret < 0)\n return ret;\n sl->mb_skip_run = -1;\n if (h->postpone_filter)\n sl->deblocking_filter = 0;\n sl->is_complex = FRAME_MBAFF(h) || h->picture_structure != PICT_FRAME ||\n avctx->codec_id != AV_CODEC_ID_H264 ||\n (CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY));\n if (h->ps.pps->cabac) {\n align_get_bits(&sl->gb);\n ff_init_cabac_decoder(&sl->cabac,\n sl->gb.buffer + get_bits_count(&sl->gb) / 8,\n (get_bits_left(&sl->gb) + 7) / 8);\n ff_h264_init_cabac_states(h, sl);\n for (;;) {\n int ret, eos;\n if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) {\n av_log(h->avctx, AV_LOG_ERROR, "Slice overlaps with next at %d\\n",\n sl->next_slice_idx);\n return AVERROR_INVALIDDATA;\n }\n ret = ff_h264_decode_mb_cabac(h, sl);\n if (ret >= 0)\n ff_h264_hl_decode_mb(h, sl);\n if (ret >= 0 && FRAME_MBAFF(h)) {\n sl->mb_y++;\n ret = ff_h264_decode_mb_cabac(h, sl);\n if (ret >= 0)\n ff_h264_hl_decode_mb(h, sl);\n sl->mb_y--;\n }\n eos = get_cabac_terminate(&sl->cabac);\n if ((h->workaround_bugs & FF_BUG_TRUNCATED) &&\n sl->cabac.bytestream > sl->cabac.bytestream_end + 2) {\n er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1,\n sl->mb_y, ER_MB_END);\n if (sl->mb_x >= lf_x_start)\n loop_filter(h, sl, lf_x_start, sl->mb_x + 1);\n goto finish;\n }\n if (ret < 0 || sl->cabac.bytestream > sl->cabac.bytestream_end + 2) {\n av_log(h->avctx, AV_LOG_ERROR,\n "error while decoding MB %d %d, bytestream %td\\n",\n sl->mb_x, sl->mb_y,\n sl->cabac.bytestream_end - sl->cabac.bytestream);\n er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,\n sl->mb_y, ER_MB_ERROR);\n return AVERROR_INVALIDDATA;\n }\n if (++sl->mb_x >= h->mb_width) {\n loop_filter(h, sl, lf_x_start, sl->mb_x);\n sl->mb_x = lf_x_start = 0;\n decode_finish_row(h, sl);\n ++sl->mb_y;\n if (FIELD_OR_MBAFF_PICTURE(h)) {\n ++sl->mb_y;\n if (FRAME_MBAFF(h) && sl->mb_y < h->mb_height)\n predict_field_decoding_flag(h, sl);\n }\n }\n if (eos || sl->mb_y >= h->mb_height) {\n ff_tlog(h->avctx, "slice end %d %d\\n",\n get_bits_count(&sl->gb), sl->gb.size_in_bits);\n er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1,\n sl->mb_y, ER_MB_END);\n if (sl->mb_x > lf_x_start)\n loop_filter(h, sl, lf_x_start, sl->mb_x);\n goto finish;\n }\n }\n } else {\n for (;;) {\n int ret;\n if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) {\n av_log(h->avctx, AV_LOG_ERROR, "Slice overlaps with next at %d\\n",\n sl->next_slice_idx);\n return AVERROR_INVALIDDATA;\n }\n ret = ff_h264_decode_mb_cavlc(h, sl);\n if (ret >= 0)\n ff_h264_hl_decode_mb(h, sl);\n if (ret >= 0 && FRAME_MBAFF(h)) {\n sl->mb_y++;\n ret = ff_h264_decode_mb_cavlc(h, sl);\n if (ret >= 0)\n ff_h264_hl_decode_mb(h, sl);\n sl->mb_y--;\n }\n if (ret < 0) {\n av_log(h->avctx, AV_LOG_ERROR,\n "error while decoding MB %d %d\\n", sl->mb_x, sl->mb_y);\n er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,\n sl->mb_y, ER_MB_ERROR);\n return ret;\n }\n if (++sl->mb_x >= h->mb_width) {\n loop_filter(h, sl, lf_x_start, sl->mb_x);\n sl->mb_x = lf_x_start = 0;\n decode_finish_row(h, sl);\n ++sl->mb_y;\n if (FIELD_OR_MBAFF_PICTURE(h)) {\n ++sl->mb_y;\n if (FRAME_MBAFF(h) && sl->mb_y < h->mb_height)\n predict_field_decoding_flag(h, sl);\n }\n if (sl->mb_y >= h->mb_height) {\n ff_tlog(h->avctx, "slice end %d %d\\n",\n get_bits_count(&sl->gb), sl->gb.size_in_bits);\n if (get_bits_left(&sl->gb) == 0) {\n er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,\n sl->mb_x - 1, sl->mb_y, ER_MB_END);\n goto finish;\n } else {\n er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,\n sl->mb_x - 1, sl->mb_y, ER_MB_END);\n return AVERROR_INVALIDDATA;\n }\n }\n }\n if (get_bits_left(&sl->gb) <= 0 && sl->mb_skip_run <= 0) {\n ff_tlog(h->avctx, "slice end %d %d\\n",\n get_bits_count(&sl->gb), sl->gb.size_in_bits);\n if (get_bits_left(&sl->gb) == 0) {\n er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y,\n sl->mb_x - 1, sl->mb_y, ER_MB_END);\n if (sl->mb_x > lf_x_start)\n loop_filter(h, sl, lf_x_start, sl->mb_x);\n goto finish;\n } else {\n er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x,\n sl->mb_y, ER_MB_ERROR);\n return AVERROR_INVALIDDATA;\n }\n }\n }\n }\nfinish:\n sl->deblocking_filter = orig_deblock;\n return 0;\n}', 'int ff_h264_decode_mb_cabac(const H264Context *h, H264SliceContext *sl)\n{\n const SPS *sps = h->ps.sps;\n int mb_xy;\n int mb_type, partition_count, cbp = 0;\n int dct8x8_allowed= h->ps.pps->transform_8x8_mode;\n int decode_chroma = sps->chroma_format_idc == 1 || sps->chroma_format_idc == 2;\n const int pixel_shift = h->pixel_shift;\n mb_xy = sl->mb_xy = sl->mb_x + sl->mb_y*h->mb_stride;\n ff_tlog(h->avctx, "pic:%d mb:%d/%d\\n", h->frame_num, sl->mb_x, sl->mb_y);\n if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {\n int skip;\n if (FRAME_MBAFF(h) && (sl->mb_y & 1) == 1 && sl->prev_mb_skipped)\n skip = sl->next_mb_skipped;\n else\n skip = decode_cabac_mb_skip(h, sl, sl->mb_x, sl->mb_y );\n if( skip ) {\n if (FRAME_MBAFF(h) && (sl->mb_y & 1) == 0) {\n h->cur_pic.mb_type[mb_xy] = MB_TYPE_SKIP;\n sl->next_mb_skipped = decode_cabac_mb_skip(h, sl, sl->mb_x, sl->mb_y+1 );\n if(!sl->next_mb_skipped)\n sl->mb_mbaff = sl->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h, sl);\n }\n decode_mb_skip(h, sl);\n h->cbp_table[mb_xy] = 0;\n h->chroma_pred_mode_table[mb_xy] = 0;\n sl->last_qscale_diff = 0;\n return 0;\n }\n }\n if (FRAME_MBAFF(h)) {\n if ((sl->mb_y & 1) == 0)\n sl->mb_mbaff =\n sl->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h, sl);\n }\n sl->prev_mb_skipped = 0;\n fill_decode_neighbors(h, sl, -(MB_FIELD(sl)));\n if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {\n int ctx = 0;\n assert(sl->slice_type_nos == AV_PICTURE_TYPE_B);\n if (!IS_DIRECT(sl->left_type[LTOP] - 1))\n ctx++;\n if (!IS_DIRECT(sl->top_type - 1))\n ctx++;\n if( !get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+ctx] ) ){\n mb_type= 0;\n }else if( !get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+3] ) ) {\n mb_type= 1 + get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+5] );\n }else{\n int bits;\n bits = get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+4] ) << 3;\n bits+= get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+5] ) << 2;\n bits+= get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+5] ) << 1;\n bits+= get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+5] );\n if( bits < 8 ){\n mb_type= bits + 3;\n }else if( bits == 13 ){\n mb_type = decode_cabac_intra_mb_type(sl, 32, 0);\n goto decode_intra_mb;\n }else if( bits == 14 ){\n mb_type= 11;\n }else if( bits == 15 ){\n mb_type= 22;\n }else{\n bits= ( bits<<1 ) + get_cabac_noinline( &sl->cabac, &sl->cabac_state[27+5] );\n mb_type= bits - 4;\n }\n }\n partition_count = ff_h264_b_mb_type_info[mb_type].partition_count;\n mb_type = ff_h264_b_mb_type_info[mb_type].type;\n } else if (sl->slice_type_nos == AV_PICTURE_TYPE_P) {\n if( get_cabac_noinline( &sl->cabac, &sl->cabac_state[14] ) == 0 ) {\n if( get_cabac_noinline( &sl->cabac, &sl->cabac_state[15] ) == 0 ) {\n mb_type= 3 * get_cabac_noinline( &sl->cabac, &sl->cabac_state[16] );\n } else {\n mb_type= 2 - get_cabac_noinline( &sl->cabac, &sl->cabac_state[17] );\n }\n partition_count = ff_h264_p_mb_type_info[mb_type].partition_count;\n mb_type = ff_h264_p_mb_type_info[mb_type].type;\n } else {\n mb_type = decode_cabac_intra_mb_type(sl, 17, 0);\n goto decode_intra_mb;\n }\n } else {\n mb_type = decode_cabac_intra_mb_type(sl, 3, 1);\n if (sl->slice_type == AV_PICTURE_TYPE_SI && mb_type)\n mb_type--;\n assert(sl->slice_type_nos == AV_PICTURE_TYPE_I);\ndecode_intra_mb:\n partition_count = 0;\n cbp = ff_h264_i_mb_type_info[mb_type].cbp;\n sl->intra16x16_pred_mode = ff_h264_i_mb_type_info[mb_type].pred_mode;\n mb_type = ff_h264_i_mb_type_info[mb_type].type;\n }\n if (MB_FIELD(sl))\n mb_type |= MB_TYPE_INTERLACED;\n h->slice_table[mb_xy] = sl->slice_num;\n if(IS_INTRA_PCM(mb_type)) {\n const int mb_size = ff_h264_mb_sizes[sps->chroma_format_idc] *\n sps->bit_depth_luma >> 3;\n const uint8_t *ptr;\n ptr= sl->cabac.bytestream;\n if(sl->cabac.low&0x1) ptr--;\n if(CABAC_BITS==16){\n if(sl->cabac.low&0x1FF) ptr--;\n }\n if ((int) (sl->cabac.bytestream_end - ptr) < mb_size)\n return -1;\n sl->intra_pcm_ptr = ptr;\n ptr += mb_size;\n ff_init_cabac_decoder(&sl->cabac, ptr, sl->cabac.bytestream_end - ptr);\n h->cbp_table[mb_xy] = 0xf7ef;\n h->chroma_pred_mode_table[mb_xy] = 0;\n h->cur_pic.qscale_table[mb_xy] = 0;\n memset(h->non_zero_count[mb_xy], 16, 48);\n h->cur_pic.mb_type[mb_xy] = mb_type;\n sl->last_qscale_diff = 0;\n return 0;\n }\n fill_decode_caches(h, sl, mb_type);\n if( IS_INTRA( mb_type ) ) {\n int i, pred_mode;\n if( IS_INTRA4x4( mb_type ) ) {\n if (dct8x8_allowed && get_cabac_noinline(&sl->cabac, &sl->cabac_state[399 + sl->neighbor_transform_size])) {\n mb_type |= MB_TYPE_8x8DCT;\n for( i = 0; i < 16; i+=4 ) {\n int pred = pred_intra_mode(h, sl, i);\n int mode = decode_cabac_mb_intra4x4_pred_mode(sl, pred);\n fill_rectangle(&sl->intra4x4_pred_mode_cache[scan8[i]], 2, 2, 8, mode, 1);\n }\n } else {\n for( i = 0; i < 16; i++ ) {\n int pred = pred_intra_mode(h, sl, i);\n sl->intra4x4_pred_mode_cache[scan8[i]] = decode_cabac_mb_intra4x4_pred_mode(sl, pred);\n ff_dlog(h->avctx, "i4x4 pred=%d mode=%d\\n", pred,\n sl->intra4x4_pred_mode_cache[scan8[i]]);\n }\n }\n write_back_intra_pred_mode(h, sl);\n if (ff_h264_check_intra4x4_pred_mode(sl->intra4x4_pred_mode_cache, h->avctx,\n sl->top_samples_available, sl->left_samples_available) < 0 )\n return -1;\n } else {\n sl->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,\n sl->left_samples_available, sl->intra16x16_pred_mode, 0);\n if (sl->intra16x16_pred_mode < 0) return -1;\n }\n if(decode_chroma){\n h->chroma_pred_mode_table[mb_xy] =\n pred_mode = decode_cabac_mb_chroma_pre_mode(h, sl);\n pred_mode= ff_h264_check_intra_pred_mode(h->avctx, sl->top_samples_available,\n sl->left_samples_available, pred_mode, 1 );\n if( pred_mode < 0 ) return -1;\n sl->chroma_pred_mode = pred_mode;\n } else {\n sl->chroma_pred_mode = DC_128_PRED8x8;\n }\n } else if( partition_count == 4 ) {\n int i, j, sub_partition_count[4], list, ref[2][4];\n if (sl->slice_type_nos == AV_PICTURE_TYPE_B ) {\n for( i = 0; i < 4; i++ ) {\n sl->sub_mb_type[i] = decode_cabac_b_mb_sub_type(sl);\n sub_partition_count[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;\n sl->sub_mb_type[i] = ff_h264_b_sub_mb_type_info[sl->sub_mb_type[i]].type;\n }\n if (IS_DIRECT(sl->sub_mb_type[0] | sl->sub_mb_type[1] |\n sl->sub_mb_type[2] | sl->sub_mb_type[3])) {\n ff_h264_pred_direct_motion(h, sl, &mb_type);\n sl->ref_cache[0][scan8[4]] =\n sl->ref_cache[1][scan8[4]] =\n sl->ref_cache[0][scan8[12]] =\n sl->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n for( i = 0; i < 4; i++ )\n fill_rectangle(&sl->direct_cache[scan8[4*i]], 2, 2, 8, (sl->sub_mb_type[i] >> 1) & 0xFF, 1);\n }\n } else {\n for( i = 0; i < 4; i++ ) {\n sl->sub_mb_type[i] = decode_cabac_p_mb_sub_type(sl);\n sub_partition_count[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].partition_count;\n sl->sub_mb_type[i] = ff_h264_p_sub_mb_type_info[sl->sub_mb_type[i]].type;\n }\n }\n for( list = 0; list < sl->list_count; list++ ) {\n for( i = 0; i < 4; i++ ) {\n if(IS_DIRECT(sl->sub_mb_type[i])) continue;\n if(IS_DIR(sl->sub_mb_type[i], 0, list)){\n int rc = sl->ref_count[list] << MB_MBAFF(sl);\n if (rc > 1) {\n ref[list][i] = decode_cabac_mb_ref(sl, list, 4 * i);\n if (ref[list][i] >= (unsigned) rc) {\n av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref[list][i], rc);\n return -1;\n }\n }else\n ref[list][i] = 0;\n } else {\n ref[list][i] = -1;\n }\n sl->ref_cache[list][scan8[4 * i] + 1] =\n sl->ref_cache[list][scan8[4 * i] + 8] = sl->ref_cache[list][scan8[4 * i] + 9] = ref[list][i];\n }\n }\n if(dct8x8_allowed)\n dct8x8_allowed = get_dct8x8_allowed(h, sl);\n for (list = 0; list < sl->list_count; list++) {\n for(i=0; i<4; i++){\n sl->ref_cache[list][scan8[4 * i]] = sl->ref_cache[list][scan8[4 * i] + 1];\n if(IS_DIRECT(sl->sub_mb_type[i])){\n fill_rectangle(sl->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 2);\n continue;\n }\n if(IS_DIR(sl->sub_mb_type[i], 0, list) && !IS_DIRECT(sl->sub_mb_type[i])){\n const int sub_mb_type= sl->sub_mb_type[i];\n const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;\n for(j=0; j<sub_partition_count[i]; j++){\n int mpx, mpy;\n int mx, my;\n const int index= 4*i + block_width*j;\n int16_t (* mv_cache)[2] = &sl->mv_cache[list][ scan8[index] ];\n uint8_t (* mvd_cache)[2]= &sl->mvd_cache[list][ scan8[index] ];\n pred_motion(h, sl, index, block_width, list, sl->ref_cache[list][ scan8[index] ], &mx, &my);\n DECODE_CABAC_MB_MVD(sl, list, index)\n ff_tlog(h->avctx, "final mv:%d %d\\n", mx, my);\n if(IS_SUB_8X8(sub_mb_type)){\n mv_cache[ 1 ][0]=\n mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;\n mv_cache[ 1 ][1]=\n mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;\n mvd_cache[ 1 ][0]=\n mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mpx;\n mvd_cache[ 1 ][1]=\n mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mpy;\n }else if(IS_SUB_8X4(sub_mb_type)){\n mv_cache[ 1 ][0]= mx;\n mv_cache[ 1 ][1]= my;\n mvd_cache[ 1 ][0]= mpx;\n mvd_cache[ 1 ][1]= mpy;\n }else if(IS_SUB_4X8(sub_mb_type)){\n mv_cache[ 8 ][0]= mx;\n mv_cache[ 8 ][1]= my;\n mvd_cache[ 8 ][0]= mpx;\n mvd_cache[ 8 ][1]= mpy;\n }\n mv_cache[ 0 ][0]= mx;\n mv_cache[ 0 ][1]= my;\n mvd_cache[ 0 ][0]= mpx;\n mvd_cache[ 0 ][1]= mpy;\n }\n }else{\n fill_rectangle(sl->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4);\n fill_rectangle(sl->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2);\n }\n }\n }\n } else if( IS_DIRECT(mb_type) ) {\n ff_h264_pred_direct_motion(h, sl, &mb_type);\n fill_rectangle(sl->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 2);\n fill_rectangle(sl->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2);\n dct8x8_allowed &= sps->direct_8x8_inference_flag;\n } else {\n int list, i;\n if(IS_16X16(mb_type)){\n for (list = 0; list < sl->list_count; list++) {\n if(IS_DIR(mb_type, 0, list)){\n int ref, rc = sl->ref_count[list] << MB_MBAFF(sl);\n if (rc > 1) {\n ref= decode_cabac_mb_ref(sl, list, 0);\n if (ref >= (unsigned) rc) {\n av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, rc);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&sl->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1);\n }\n }\n for (list = 0; list < sl->list_count; list++) {\n if(IS_DIR(mb_type, 0, list)){\n int mx,my,mpx,mpy;\n pred_motion(h, sl, 0, 4, list, sl->ref_cache[list][ scan8[0] ], &mx, &my);\n DECODE_CABAC_MB_MVD(sl, list, 0)\n ff_tlog(h->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(sl->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2);\n fill_rectangle(sl->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);\n }\n }\n }\n else if(IS_16X8(mb_type)){\n for (list = 0; list < sl->list_count; list++) {\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int ref, rc = sl->ref_count[list] << MB_MBAFF(sl);\n if (rc > 1) {\n ref= decode_cabac_mb_ref(sl, list, 8 * i);\n if (ref >= (unsigned) rc) {\n av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, rc);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&sl->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1);\n }else\n fill_rectangle(&sl->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);\n }\n }\n for (list = 0; list < sl->list_count; list++) {\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int mx,my,mpx,mpy;\n pred_16x8_motion(h, sl, 8*i, list, sl->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n DECODE_CABAC_MB_MVD(sl, list, 8*i)\n ff_tlog(h->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(sl->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2);\n fill_rectangle(sl->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);\n }else{\n fill_rectangle(sl->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 2);\n fill_rectangle(sl->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);\n }\n }\n }\n }else{\n assert(IS_8X16(mb_type));\n for (list = 0; list < sl->list_count; list++) {\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int ref, rc = sl->ref_count[list] << MB_MBAFF(sl);\n if (rc > 1) {\n ref = decode_cabac_mb_ref(sl, list, 4 * i);\n if (ref >= (unsigned) rc) {\n av_log(h->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, rc);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&sl->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1);\n }else\n fill_rectangle(&sl->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);\n }\n }\n for (list = 0; list < sl->list_count; list++) {\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int mx,my,mpx,mpy;\n pred_8x16_motion(h, sl, i*4, list, sl->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n DECODE_CABAC_MB_MVD(sl, list, 4*i)\n ff_tlog(h->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(sl->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2);\n fill_rectangle(sl->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);\n }else{\n fill_rectangle(sl->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 2);\n fill_rectangle(sl->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);\n }\n }\n }\n }\n }\n if( IS_INTER( mb_type ) ) {\n h->chroma_pred_mode_table[mb_xy] = 0;\n write_back_motion(h, sl, mb_type);\n }\n if( !IS_INTRA16x16( mb_type ) ) {\n cbp = decode_cabac_mb_cbp_luma(sl);\n if(decode_chroma)\n cbp |= decode_cabac_mb_cbp_chroma(sl) << 4;\n }\n h->cbp_table[mb_xy] = sl->cbp = cbp;\n if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) {\n mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline(&sl->cabac, &sl->cabac_state[399 + sl->neighbor_transform_size]);\n }\n if (CHROMA444(h) && IS_8x8DCT(mb_type)){\n int i;\n uint8_t *nnz_cache = sl->non_zero_count_cache;\n for (i = 0; i < 2; i++){\n if (sl->left_type[LEFT(i)] && !IS_8x8DCT(sl->left_type[LEFT(i)])) {\n nnz_cache[3+8* 1 + 2*8*i]=\n nnz_cache[3+8* 2 + 2*8*i]=\n nnz_cache[3+8* 6 + 2*8*i]=\n nnz_cache[3+8* 7 + 2*8*i]=\n nnz_cache[3+8*11 + 2*8*i]=\n nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;\n }\n }\n if (sl->top_type && !IS_8x8DCT(sl->top_type)){\n uint32_t top_empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n AV_WN32A(&nnz_cache[4+8* 0], top_empty);\n AV_WN32A(&nnz_cache[4+8* 5], top_empty);\n AV_WN32A(&nnz_cache[4+8*10], top_empty);\n }\n }\n h->cur_pic.mb_type[mb_xy] = mb_type;\n if( cbp || IS_INTRA16x16( mb_type ) ) {\n const uint8_t *scan, *scan8x8;\n const uint32_t *qmul;\n if(IS_INTERLACED(mb_type)){\n scan8x8 = sl->qscale ? h->field_scan8x8 : h->field_scan8x8_q0;\n scan = sl->qscale ? h->field_scan : h->field_scan_q0;\n }else{\n scan8x8 = sl->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;\n scan = sl->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n }\n if(get_cabac_noinline( &sl->cabac, &sl->cabac_state[60 + (sl->last_qscale_diff != 0)])){\n int val = 1;\n int ctx= 2;\n const int max_qp = 51 + 6*(sps->bit_depth_luma-8);\n while( get_cabac_noinline( &sl->cabac, &sl->cabac_state[60 + ctx] ) ) {\n ctx= 3;\n val++;\n if(val > 2*max_qp){\n av_log(h->avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\\n", sl->mb_x, sl->mb_y);\n return -1;\n }\n }\n if( val&0x01 )\n val= (val + 1)>>1 ;\n else\n val= -((val + 1)>>1);\n sl->last_qscale_diff = val;\n sl->qscale += val;\n if (((unsigned)sl->qscale) > max_qp){\n if (sl->qscale < 0) sl->qscale += max_qp + 1;\n else sl->qscale -= max_qp + 1;\n }\n sl->chroma_qp[0] = get_chroma_qp(h, 0, sl->qscale);\n sl->chroma_qp[1] = get_chroma_qp(h, 1, sl->qscale);\n }else\n sl->last_qscale_diff=0;\n decode_cabac_luma_residual(h, sl, scan, scan8x8, pixel_shift, mb_type, cbp, 0);\n if (CHROMA444(h)) {\n decode_cabac_luma_residual(h, sl, scan, scan8x8, pixel_shift, mb_type, cbp, 1);\n decode_cabac_luma_residual(h, sl, scan, scan8x8, pixel_shift, mb_type, cbp, 2);\n } else if (CHROMA422(h)) {\n if( cbp&0x30 ){\n int c;\n for (c = 0; c < 2; c++)\n decode_cabac_residual_dc_422(h, sl, sl->mb + ((256 + 16*16*c) << pixel_shift), 3,\n CHROMA_DC_BLOCK_INDEX + c,\n ff_h264_chroma422_dc_scan, 8);\n }\n if( cbp&0x20 ) {\n int c, i, i8x8;\n for( c = 0; c < 2; c++ ) {\n int16_t *mb = sl->mb + (16*(16 + 16*c) << pixel_shift);\n qmul = h->ps.pps->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][sl->chroma_qp[c]];\n for (i8x8 = 0; i8x8 < 2; i8x8++) {\n for (i = 0; i < 4; i++) {\n const int index = 16 + 16 * c + 8*i8x8 + i;\n decode_cabac_residual_nondc(h, sl, mb, 4, index, scan + 1, qmul, 15);\n mb += 16<<pixel_shift;\n }\n }\n }\n } else {\n fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n }\n } else {\n if( cbp&0x30 ){\n int c;\n for (c = 0; c < 2; c++)\n decode_cabac_residual_dc(h, sl, sl->mb + ((256 + 16 * 16 * c) << pixel_shift),\n 3, CHROMA_DC_BLOCK_INDEX + c, ff_h264_chroma_dc_scan, 4);\n }\n if( cbp&0x20 ) {\n int c, i;\n for( c = 0; c < 2; c++ ) {\n qmul = h->ps.pps->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][sl->chroma_qp[c]];\n for( i = 0; i < 4; i++ ) {\n const int index = 16 + 16 * c + i;\n decode_cabac_residual_nondc(h, sl, sl->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15);\n }\n }\n } else {\n fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n }\n }\n } else {\n fill_rectangle(&sl->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);\n fill_rectangle(&sl->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&sl->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n sl->last_qscale_diff = 0;\n }\n h->cur_pic.qscale_table[mb_xy] = sl->qscale;\n write_back_non_zero_count(h, sl);\n return 0;\n}', 'void ff_h264_hl_decode_mb(const H264Context *h, H264SliceContext *sl)\n{\n const int mb_xy = sl->mb_xy;\n const int mb_type = h->cur_pic.mb_type[mb_xy];\n int is_complex = CONFIG_SMALL || sl->is_complex ||\n IS_INTRA_PCM(mb_type) || sl->qscale == 0;\n if (CHROMA444(h)) {\n if (is_complex || h->pixel_shift)\n hl_decode_mb_444_complex(h, sl);\n else\n hl_decode_mb_444_simple_8(h, sl);\n } else if (is_complex) {\n hl_decode_mb_complex(h, sl);\n } else if (h->pixel_shift) {\n hl_decode_mb_simple_16(h, sl);\n } else\n hl_decode_mb_simple_8(h, sl);\n}', 'static av_noinline void FUNC(hl_decode_mb_444)(const H264Context *h, H264SliceContext *sl)\n{\n const int mb_x = sl->mb_x;\n const int mb_y = sl->mb_y;\n const int mb_xy = sl->mb_xy;\n const int mb_type = h->cur_pic.mb_type[mb_xy];\n uint8_t *dest[3];\n int linesize;\n int i, j, p;\n const int *block_offset = &h->block_offset[0];\n const int transform_bypass = !SIMPLE && (sl->qscale == 0 && h->ps.sps->transform_bypass);\n const int plane_count = (SIMPLE || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) ? 3 : 1;\n for (p = 0; p < plane_count; p++) {\n dest[p] = h->cur_pic.f->data[p] +\n ((mb_x << PIXEL_SHIFT) + mb_y * sl->linesize) * 16;\n h->vdsp.prefetch(dest[p] + (sl->mb_x & 3) * 4 * sl->linesize + (64 << PIXEL_SHIFT),\n sl->linesize, 4);\n }\n h->list_counts[mb_xy] = sl->list_count;\n if (!SIMPLE && MB_FIELD(sl)) {\n linesize = sl->mb_linesize = sl->mb_uvlinesize = sl->linesize * 2;\n block_offset = &h->block_offset[48];\n if (mb_y & 1)\n for (p = 0; p < 3; p++)\n dest[p] -= sl->linesize * 15;\n if (FRAME_MBAFF(h)) {\n int list;\n for (list = 0; list < sl->list_count; list++) {\n if (!USES_LIST(mb_type, list))\n continue;\n if (IS_16X16(mb_type)) {\n int8_t *ref = &sl->ref_cache[list][scan8[0]];\n fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (sl->mb_y & 1), 1);\n } else {\n for (i = 0; i < 16; i += 4) {\n int ref = sl->ref_cache[list][scan8[i]];\n if (ref >= 0)\n fill_rectangle(&sl->ref_cache[list][scan8[i]], 2, 2,\n 8, (16 + ref) ^ (sl->mb_y & 1), 1);\n }\n }\n }\n }\n } else {\n linesize = sl->mb_linesize = sl->mb_uvlinesize = sl->linesize;\n }\n if (!SIMPLE && IS_INTRA_PCM(mb_type)) {\n if (PIXEL_SHIFT) {\n const int bit_depth = h->ps.sps->bit_depth_luma;\n GetBitContext gb;\n init_get_bits(&gb, sl->intra_pcm_ptr, 768 * bit_depth);\n for (p = 0; p < plane_count; p++)\n for (i = 0; i < 16; i++) {\n uint16_t *tmp = (uint16_t *)(dest[p] + i * linesize);\n for (j = 0; j < 16; j++)\n tmp[j] = get_bits(&gb, bit_depth);\n }\n } else {\n for (p = 0; p < plane_count; p++)\n for (i = 0; i < 16; i++)\n memcpy(dest[p] + i * linesize,\n sl->intra_pcm_ptr + p * 256 + i * 16, 16);\n }\n } else {\n if (IS_INTRA(mb_type)) {\n if (sl->deblocking_filter)\n xchg_mb_border(h, sl, dest[0], dest[1], dest[2], linesize,\n linesize, 1, 1, SIMPLE, PIXEL_SHIFT);\n for (p = 0; p < plane_count; p++)\n hl_decode_mb_predict_luma(h, sl, mb_type, SIMPLE,\n transform_bypass, PIXEL_SHIFT,\n block_offset, linesize, dest[p], p);\n if (sl->deblocking_filter)\n xchg_mb_border(h, sl, dest[0], dest[1], dest[2], linesize,\n linesize, 0, 1, SIMPLE, PIXEL_SHIFT);\n } else {\n FUNC(hl_motion_444)(h, sl, dest[0], dest[1], dest[2],\n h->h264qpel.put_h264_qpel_pixels_tab,\n h->h264chroma.put_h264_chroma_pixels_tab,\n h->h264qpel.avg_h264_qpel_pixels_tab,\n h->h264chroma.avg_h264_chroma_pixels_tab,\n h->h264dsp.weight_h264_pixels_tab,\n h->h264dsp.biweight_h264_pixels_tab);\n }\n for (p = 0; p < plane_count; p++)\n hl_decode_mb_idct_luma(h, sl, mb_type, SIMPLE, transform_bypass,\n PIXEL_SHIFT, block_offset, linesize,\n dest[p], p);\n }\n}', 'static av_always_inline void hl_decode_mb_predict_luma(const H264Context *h,\n H264SliceContext *sl,\n int mb_type, int simple,\n int transform_bypass,\n int pixel_shift,\n const int *block_offset,\n int linesize,\n uint8_t *dest_y, int p)\n{\n void (*idct_add)(uint8_t *dst, int16_t *block, int stride);\n void (*idct_dc_add)(uint8_t *dst, int16_t *block, int stride);\n int i;\n int qscale = p == 0 ? sl->qscale : sl->chroma_qp[p - 1];\n block_offset += 16 * p;\n if (IS_INTRA4x4(mb_type)) {\n if (IS_8x8DCT(mb_type)) {\n if (transform_bypass) {\n idct_dc_add =\n idct_add = h->h264dsp.h264_add_pixels8_clear;\n } else {\n idct_dc_add = h->h264dsp.h264_idct8_dc_add;\n idct_add = h->h264dsp.h264_idct8_add;\n }\n for (i = 0; i < 16; i += 4) {\n uint8_t *const ptr = dest_y + block_offset[i];\n const int dir = sl->intra4x4_pred_mode_cache[scan8[i]];\n if (transform_bypass && h->ps.sps->profile_idc == 244 && dir <= 1) {\n h->hpc.pred8x8l_add[dir](ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n } else {\n const int nnz = sl->non_zero_count_cache[scan8[i + p * 16]];\n h->hpc.pred8x8l[dir](ptr, (sl->topleft_samples_available << i) & 0x8000,\n (sl->topright_samples_available << i) & 0x4000, linesize);\n if (nnz) {\n if (nnz == 1 && dctcoef_get(sl->mb, pixel_shift, i * 16 + p * 256))\n idct_dc_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n else\n idct_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n }\n }\n }\n } else {\n if (transform_bypass) {\n idct_dc_add =\n idct_add = h->h264dsp.h264_add_pixels4_clear;\n } else {\n idct_dc_add = h->h264dsp.h264_idct_dc_add;\n idct_add = h->h264dsp.h264_idct_add;\n }\n for (i = 0; i < 16; i++) {\n uint8_t *const ptr = dest_y + block_offset[i];\n const int dir = sl->intra4x4_pred_mode_cache[scan8[i]];\n if (transform_bypass && h->ps.sps->profile_idc == 244 && dir <= 1) {\n h->hpc.pred4x4_add[dir](ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n } else {\n uint8_t *topright;\n int nnz, tr;\n uint64_t tr_high;\n if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) {\n const int topright_avail = (sl->topright_samples_available << i) & 0x8000;\n assert(sl->mb_y || linesize <= block_offset[i]);\n if (!topright_avail) {\n if (pixel_shift) {\n tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;\n topright = (uint8_t *)&tr_high;\n } else {\n tr = ptr[3 - linesize] * 0x01010101u;\n topright = (uint8_t *)&tr;\n }\n } else\n topright = ptr + (4 << pixel_shift) - linesize;\n } else\n topright = NULL;\n h->hpc.pred4x4[dir](ptr, topright, linesize);\n nnz = sl->non_zero_count_cache[scan8[i + p * 16]];\n if (nnz) {\n if (nnz == 1 && dctcoef_get(sl->mb, pixel_shift, i * 16 + p * 256))\n idct_dc_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n else\n idct_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n }\n }\n }\n }\n } else {\n h->hpc.pred16x16[sl->intra16x16_pred_mode](dest_y, linesize);\n if (sl->non_zero_count_cache[scan8[LUMA_DC_BLOCK_INDEX + p]]) {\n if (!transform_bypass)\n h->h264dsp.h264_luma_dc_dequant_idct(sl->mb + (p * 256 << pixel_shift),\n sl->mb_luma_dc[p],\n h->ps.pps->dequant4_coeff[p][qscale][0]);\n else {\n static const uint8_t dc_mapping[16] = {\n 0 * 16, 1 * 16, 4 * 16, 5 * 16,\n 2 * 16, 3 * 16, 6 * 16, 7 * 16,\n 8 * 16, 9 * 16, 12 * 16, 13 * 16,\n 10 * 16, 11 * 16, 14 * 16, 15 * 16\n };\n for (i = 0; i < 16; i++)\n dctcoef_set(sl->mb + (p * 256 << pixel_shift),\n pixel_shift, dc_mapping[i],\n dctcoef_get(sl->mb_luma_dc[p],\n pixel_shift, i));\n }\n }\n }\n}'] |
34,312 | 0 | https://github.com/libav/libav/blob/a20639017bfca0490bb1799575714f22bf470b4f/libavcodec/mpegaudiodec.c/#L891 | static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,
int *dither_state, OUT_INT *samples, int incr)
{
register const MPA_INT *w, *w2, *p;
int j;
OUT_INT *samples2;
#if CONFIG_FLOAT
float sum, sum2;
#elif FRAC_BITS <= 15
int sum, sum2;
#else
int64_t sum, sum2;
#endif
memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));
samples2 = samples + 31 * incr;
w = window;
w2 = window + 31;
sum = *dither_state;
p = synth_buf + 16;
SUM8(MACS, sum, w, p);
p = synth_buf + 48;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
samples += incr;
w++;
for(j=1;j<16;j++) {
sum2 = 0;
p = synth_buf + 16 + j;
SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);
p = synth_buf + 48 - j;
SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);
*samples = round_sample(&sum);
samples += incr;
sum += sum2;
*samples2 = round_sample(&sum);
samples2 -= incr;
w++;
w2--;
}
p = synth_buf + 32;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
*dither_state= sum;
} | ['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n int offset;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15 && !CONFIG_FLOAT\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}', 'static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,\n int *dither_state, OUT_INT *samples, int incr)\n{\n register const MPA_INT *w, *w2, *p;\n int j;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#elif FRAC_BITS <= 15\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n}'] |
34,313 | 0 | https://github.com/libav/libav/blob/688417399c69aadd4c287bdb0dec82ef8799011c/libavcodec/hevcdsp_template.c/#L904 | PUT_HEVC_QPEL_HV(2, 1) | ['QPEL(64)', 'PUT_HEVC_QPEL_HV(2, 1)'] |
34,314 | 0 | https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavcodec/mpegaudiodec.c/#L894 | void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
MPA_INT *window, int *dither_state,
OUT_INT *samples, int incr,
int32_t sb_samples[SBLIMIT])
{
int32_t tmp[32];
register MPA_INT *synth_buf;
register const MPA_INT *w, *w2, *p;
int j, offset, v;
OUT_INT *samples2;
#if FRAC_BITS <= 15
int sum, sum2;
#else
int64_t sum, sum2;
#endif
dct32(tmp, sb_samples);
offset = *synth_buf_offset;
synth_buf = synth_buf_ptr + offset;
for(j=0;j<32;j++) {
v = tmp[j];
#if FRAC_BITS <= 15
v = av_clip_int16(v);
#endif
synth_buf[j] = v;
}
memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));
samples2 = samples + 31 * incr;
w = window;
w2 = window + 31;
sum = *dither_state;
p = synth_buf + 16;
SUM8(MACS, sum, w, p);
p = synth_buf + 48;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
samples += incr;
w++;
for(j=1;j<16;j++) {
sum2 = 0;
p = synth_buf + 16 + j;
SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);
p = synth_buf + 48 - j;
SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);
*samples = round_sample(&sum);
samples += incr;
sum += sum2;
*samples2 = round_sample(&sum);
samples2 -= incr;
w++;
w2--;
}
p = synth_buf + 32;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
*dither_state= sum;
offset = (offset - 32) & 511;
*synth_buf_offset = offset;
} | ['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n mpa_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n int32_t sb_samples[SBLIMIT])\n{\n int32_t tmp[32];\n register MPA_INT *synth_buf;\n register const MPA_INT *w, *w2, *p;\n int j, offset, v;\n OUT_INT *samples2;\n#if FRAC_BITS <= 15\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n dct32(tmp, sb_samples);\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n for(j=0;j<32;j++) {\n v = tmp[j];\n#if FRAC_BITS <= 15\n v = av_clip_int16(v);\n#endif\n synth_buf[j] = v;\n }\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}'] |
34,315 | 0 | https://github.com/libav/libav/blob/2c8077621b6466da205ba26fd20a9c906bb71893/libavcodec/interplayvideo.c/#L836 | static int ipvideo_decode_block_opcode_0xA_16(IpvideoContext *s)
{
int x, y;
uint16_t P[4];
int flags = 0;
uint16_t *pixel_ptr = (uint16_t*)s->pixel_ptr;
CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 24);
if (!(AV_RL16(s->stream_ptr) & 0x8000)) {
CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 48);
for (y = 0; y < 16; y++) {
if (!(y & 3)) {
for (x = 0; x < 4; x++)
P[x] = bytestream_get_le16(&s->stream_ptr);
flags = bytestream_get_le32(&s->stream_ptr);
}
for (x = 0; x < 4; x++, flags >>= 2)
*pixel_ptr++ = P[flags & 0x03];
pixel_ptr += s->stride - 4;
if (y == 7) pixel_ptr -= 8 * s->stride - 4;
}
} else {
int vert = !(AV_RL16(s->stream_ptr + 16) & 0x8000);
uint64_t flags = 0;
for (y = 0; y < 16; y++) {
if (!(y & 7)) {
for (x = 0; x < 4; x++)
P[x] = bytestream_get_le16(&s->stream_ptr);
flags = bytestream_get_le64(&s->stream_ptr);
}
for (x = 0; x < 4; x++, flags >>= 2)
*pixel_ptr++ = P[flags & 0x03];
if (vert) {
pixel_ptr += s->stride - 4;
if (y == 7) pixel_ptr -= 8 * s->stride - 4;
} else if (y & 1) pixel_ptr += s->line_inc;
}
}
return 0;
} | ['static int ipvideo_decode_block_opcode_0xA_16(IpvideoContext *s)\n{\n int x, y;\n uint16_t P[4];\n int flags = 0;\n uint16_t *pixel_ptr = (uint16_t*)s->pixel_ptr;\n CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 24);\n if (!(AV_RL16(s->stream_ptr) & 0x8000)) {\n CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 48);\n for (y = 0; y < 16; y++) {\n if (!(y & 3)) {\n for (x = 0; x < 4; x++)\n P[x] = bytestream_get_le16(&s->stream_ptr);\n flags = bytestream_get_le32(&s->stream_ptr);\n }\n for (x = 0; x < 4; x++, flags >>= 2)\n *pixel_ptr++ = P[flags & 0x03];\n pixel_ptr += s->stride - 4;\n if (y == 7) pixel_ptr -= 8 * s->stride - 4;\n }\n } else {\n int vert = !(AV_RL16(s->stream_ptr + 16) & 0x8000);\n uint64_t flags = 0;\n for (y = 0; y < 16; y++) {\n if (!(y & 7)) {\n for (x = 0; x < 4; x++)\n P[x] = bytestream_get_le16(&s->stream_ptr);\n flags = bytestream_get_le64(&s->stream_ptr);\n }\n for (x = 0; x < 4; x++, flags >>= 2)\n *pixel_ptr++ = P[flags & 0x03];\n if (vert) {\n pixel_ptr += s->stride - 4;\n if (y == 7) pixel_ptr -= 8 * s->stride - 4;\n } else if (y & 1) pixel_ptr += s->line_inc;\n }\n }\n return 0;\n}'] |
34,316 | 0 | https://github.com/libav/libav/blob/47399ccdfd93d337c96c76fbf591f0e3637131ef/libavcodec/bitstream.h/#L236 | static inline void skip_remaining(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
bc->bits >>= n;
#else
bc->bits <<= n;
#endif
bc->bits_left -= n;
} | ['static int read_highpass_coeffs(CFHDContext *s, GetByteContext *gb,\n int16_t *coeff_data)\n{\n int i, ret;\n int highpass_height = s->plane[s->channel_num].band[s->level][s->subband_num].height;\n int highpass_width = s->plane[s->channel_num].band[s->level][s->subband_num].width;\n int highpass_a_width = s->plane[s->channel_num].band[s->level][s->subband_num].a_width;\n int highpass_a_height = s->plane[s->channel_num].band[s->level][s->subband_num].a_height;\n ptrdiff_t highpass_stride = s->plane[s->channel_num].band[s->level][s->subband_num].stride;\n int expected = highpass_height * highpass_stride;\n int a_expected = highpass_a_height * highpass_a_width;\n int count = 0;\n unsigned bytes;\n if (highpass_height > highpass_a_height ||\n highpass_width > highpass_a_width ||\n a_expected < expected) {\n av_log(s->avctx, AV_LOG_ERROR, "Too many highpass coefficients\\n");\n return AVERROR_INVALIDDATA;\n }\n av_log(s->avctx, AV_LOG_DEBUG,\n "Start subband coeffs plane %i level %i codebook %i expected %i\\n",\n s->channel_num, s->level, s->codebook, expected);\n if ((ret = bitstream_init8(&s->bc, gb->buffer,\n bytestream2_get_bytes_left(gb))) < 0)\n return ret;\n if (!s->codebook) {\n DECODE_SUBBAND_COEFFS(table_9_rl_vlc, level == 64)\n } else {\n DECODE_SUBBAND_COEFFS(table_18_rl_vlc, level == 255 && run == 2)\n }\n bytes = FFALIGN(AV_CEIL_RSHIFT(bitstream_tell(&s->bc), 3), 4);\n if (bytes > bytestream2_get_bytes_left(gb)) {\n av_log(s->avctx, AV_LOG_ERROR, "Bitstream overread error\\n");\n return AVERROR_INVALIDDATA;\n } else\n bytestream2_seek(gb, bytes, SEEK_CUR);\n av_log(s->avctx, AV_LOG_DEBUG, "End subband coeffs %i extra %i\\n",\n count, count - expected);\n s->codebook = 0;\n if (highpass_height & 1) {\n int16_t *last_line = &coeff_data[expected];\n memcpy(last_line, &last_line[-highpass_stride],\n highpass_stride * sizeof(*coeff_data));\n }\n return 0;\n}', 'static inline int bitstream_init8(BitstreamContext *bc, const uint8_t *buffer,\n unsigned byte_size)\n{\n if (byte_size > INT_MAX / 8)\n return AVERROR_INVALIDDATA;\n return bitstream_init(bc, buffer, byte_size * 8);\n}', 'static inline unsigned bitstream_peek(BitstreamContext *bc, unsigned n)\n{\n if (n > bc->bits_left)\n refill_32(bc);\n return show_val(bc, n);\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n < bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n bc->bits = 0;\n bc->bits_left = 0;\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}'] |
34,317 | 0 | https://github.com/openssl/openssl/blob/ac33c5a477568127ad99b1260a8978477de50e36/crypto/modes/gcm128.c/#L1483 | int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
const unsigned char *in, unsigned char *out,
size_t len, ctr128_f stream)
{
#if defined(OPENSSL_SMALL_FOOTPRINT)
return CRYPTO_gcm128_encrypt(ctx, in, out, len);
#else
const union {
long one;
char little;
} is_endian = { 1 };
unsigned int n, ctr;
size_t i;
u64 mlen = ctx->len.u[1];
void *key = ctx->key;
# ifdef GCM_FUNCREF_4BIT
void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult;
# ifdef GHASH
void (*gcm_ghash_p) (u64 Xi[2], const u128 Htable[16],
const u8 *inp, size_t len) = ctx->ghash;
# endif
# endif
mlen += len;
if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len))
return -1;
ctx->len.u[1] = mlen;
if (ctx->ares) {
GCM_MUL(ctx, Xi);
ctx->ares = 0;
}
if (is_endian.little)
# ifdef BSWAP4
ctr = BSWAP4(ctx->Yi.d[3]);
# else
ctr = GETU32(ctx->Yi.c + 12);
# endif
else
ctr = ctx->Yi.d[3];
n = ctx->mres;
if (n) {
while (n && len) {
ctx->Xi.c[n] ^= *(out++) = *(in++) ^ ctx->EKi.c[n];
--len;
n = (n + 1) % 16;
}
if (n == 0)
GCM_MUL(ctx, Xi);
else {
ctx->mres = n;
return 0;
}
}
# if defined(GHASH) && defined(GHASH_CHUNK)
while (len >= GHASH_CHUNK) {
(*stream) (in, out, GHASH_CHUNK / 16, key, ctx->Yi.c);
ctr += GHASH_CHUNK / 16;
if (is_endian.little)
# ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
# else
PUTU32(ctx->Yi.c + 12, ctr);
# endif
else
ctx->Yi.d[3] = ctr;
GHASH(ctx, out, GHASH_CHUNK);
out += GHASH_CHUNK;
in += GHASH_CHUNK;
len -= GHASH_CHUNK;
}
# endif
if ((i = (len & (size_t)-16))) {
size_t j = i / 16;
(*stream) (in, out, j, key, ctx->Yi.c);
ctr += (unsigned int)j;
if (is_endian.little)
# ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
# else
PUTU32(ctx->Yi.c + 12, ctr);
# endif
else
ctx->Yi.d[3] = ctr;
in += i;
len -= i;
# if defined(GHASH)
GHASH(ctx, out, i);
out += i;
# else
while (j--) {
for (i = 0; i < 16; ++i)
ctx->Xi.c[i] ^= out[i];
GCM_MUL(ctx, Xi);
out += 16;
}
# endif
}
if (len) {
(*ctx->block) (ctx->Yi.c, ctx->EKi.c, key);
++ctr;
if (is_endian.little)
# ifdef BSWAP4
ctx->Yi.d[3] = BSWAP4(ctr);
# else
PUTU32(ctx->Yi.c + 12, ctr);
# endif
else
ctx->Yi.d[3] = ctr;
while (len--) {
ctx->Xi.c[n] ^= out[n] = in[n] ^ ctx->EKi.c[n];
++n;
}
}
ctx->mres = n;
return 0;
#endif
} | ['static int aes_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,\n const unsigned char *in, size_t len)\n{\n EVP_AES_GCM_CTX *gctx = EVP_C_DATA(EVP_AES_GCM_CTX,ctx);\n int rv = -1;\n if (out != in\n || len < (EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN))\n return -1;\n if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CIPHER_CTX_encrypting(ctx) ?\n EVP_CTRL_GCM_IV_GEN : EVP_CTRL_GCM_SET_IV_INV,\n EVP_GCM_TLS_EXPLICIT_IV_LEN, out) <= 0)\n goto err;\n if (CRYPTO_gcm128_aad(&gctx->gcm, EVP_CIPHER_CTX_buf_noconst(ctx),\n gctx->tls_aad_len))\n goto err;\n in += EVP_GCM_TLS_EXPLICIT_IV_LEN;\n out += EVP_GCM_TLS_EXPLICIT_IV_LEN;\n len -= EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN;\n if (EVP_CIPHER_CTX_encrypting(ctx)) {\n if (gctx->ctr) {\n size_t bulk = 0;\n# if defined(AES_GCM_ASM)\n if (len >= 32 && AES_GCM_ASM(gctx)) {\n if (CRYPTO_gcm128_encrypt(&gctx->gcm, NULL, NULL, 0))\n return -1;\n bulk = AES_gcm_encrypt(in, out, len,\n gctx->gcm.key,\n gctx->gcm.Yi.c, gctx->gcm.Xi.u);\n gctx->gcm.len.u[1] += bulk;\n }\n# endif\n if (CRYPTO_gcm128_encrypt_ctr32(&gctx->gcm,\n in + bulk,\n out + bulk,\n len - bulk, gctx->ctr))\n goto err;\n } else {\n size_t bulk = 0;\n# if defined(AES_GCM_ASM2)\n if (len >= 32 && AES_GCM_ASM2(gctx)) {\n if (CRYPTO_gcm128_encrypt(&gctx->gcm, NULL, NULL, 0))\n return -1;\n bulk = AES_gcm_encrypt(in, out, len,\n gctx->gcm.key,\n gctx->gcm.Yi.c, gctx->gcm.Xi.u);\n gctx->gcm.len.u[1] += bulk;\n }\n# endif\n if (CRYPTO_gcm128_encrypt(&gctx->gcm,\n in + bulk, out + bulk, len - bulk))\n goto err;\n }\n out += len;\n CRYPTO_gcm128_tag(&gctx->gcm, out, EVP_GCM_TLS_TAG_LEN);\n rv = len + EVP_GCM_TLS_EXPLICIT_IV_LEN + EVP_GCM_TLS_TAG_LEN;\n } else {\n if (gctx->ctr) {\n size_t bulk = 0;\n# if defined(AES_GCM_ASM)\n if (len >= 16 && AES_GCM_ASM(gctx)) {\n if (CRYPTO_gcm128_decrypt(&gctx->gcm, NULL, NULL, 0))\n return -1;\n bulk = AES_gcm_decrypt(in, out, len,\n gctx->gcm.key,\n gctx->gcm.Yi.c, gctx->gcm.Xi.u);\n gctx->gcm.len.u[1] += bulk;\n }\n# endif\n if (CRYPTO_gcm128_decrypt_ctr32(&gctx->gcm,\n in + bulk,\n out + bulk,\n len - bulk, gctx->ctr))\n goto err;\n } else {\n size_t bulk = 0;\n# if defined(AES_GCM_ASM2)\n if (len >= 16 && AES_GCM_ASM2(gctx)) {\n if (CRYPTO_gcm128_decrypt(&gctx->gcm, NULL, NULL, 0))\n return -1;\n bulk = AES_gcm_decrypt(in, out, len,\n gctx->gcm.key,\n gctx->gcm.Yi.c, gctx->gcm.Xi.u);\n gctx->gcm.len.u[1] += bulk;\n }\n# endif\n if (CRYPTO_gcm128_decrypt(&gctx->gcm,\n in + bulk, out + bulk, len - bulk))\n goto err;\n }\n CRYPTO_gcm128_tag(&gctx->gcm, EVP_CIPHER_CTX_buf_noconst(ctx),\n EVP_GCM_TLS_TAG_LEN);\n if (CRYPTO_memcmp(EVP_CIPHER_CTX_buf_noconst(ctx), in + len,\n EVP_GCM_TLS_TAG_LEN)) {\n OPENSSL_cleanse(out, len);\n goto err;\n }\n rv = len;\n }\n err:\n gctx->iv_set = 0;\n gctx->tls_aad_len = -1;\n return rv;\n}', 'int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,\n const unsigned char *in, unsigned char *out,\n size_t len, ctr128_f stream)\n{\n#if defined(OPENSSL_SMALL_FOOTPRINT)\n return CRYPTO_gcm128_encrypt(ctx, in, out, len);\n#else\n const union {\n long one;\n char little;\n } is_endian = { 1 };\n unsigned int n, ctr;\n size_t i;\n u64 mlen = ctx->len.u[1];\n void *key = ctx->key;\n# ifdef GCM_FUNCREF_4BIT\n void (*gcm_gmult_p) (u64 Xi[2], const u128 Htable[16]) = ctx->gmult;\n# ifdef GHASH\n void (*gcm_ghash_p) (u64 Xi[2], const u128 Htable[16],\n const u8 *inp, size_t len) = ctx->ghash;\n# endif\n# endif\n mlen += len;\n if (mlen > ((U64(1) << 36) - 32) || (sizeof(len) == 8 && mlen < len))\n return -1;\n ctx->len.u[1] = mlen;\n if (ctx->ares) {\n GCM_MUL(ctx, Xi);\n ctx->ares = 0;\n }\n if (is_endian.little)\n# ifdef BSWAP4\n ctr = BSWAP4(ctx->Yi.d[3]);\n# else\n ctr = GETU32(ctx->Yi.c + 12);\n# endif\n else\n ctr = ctx->Yi.d[3];\n n = ctx->mres;\n if (n) {\n while (n && len) {\n ctx->Xi.c[n] ^= *(out++) = *(in++) ^ ctx->EKi.c[n];\n --len;\n n = (n + 1) % 16;\n }\n if (n == 0)\n GCM_MUL(ctx, Xi);\n else {\n ctx->mres = n;\n return 0;\n }\n }\n# if defined(GHASH) && defined(GHASH_CHUNK)\n while (len >= GHASH_CHUNK) {\n (*stream) (in, out, GHASH_CHUNK / 16, key, ctx->Yi.c);\n ctr += GHASH_CHUNK / 16;\n if (is_endian.little)\n# ifdef BSWAP4\n ctx->Yi.d[3] = BSWAP4(ctr);\n# else\n PUTU32(ctx->Yi.c + 12, ctr);\n# endif\n else\n ctx->Yi.d[3] = ctr;\n GHASH(ctx, out, GHASH_CHUNK);\n out += GHASH_CHUNK;\n in += GHASH_CHUNK;\n len -= GHASH_CHUNK;\n }\n# endif\n if ((i = (len & (size_t)-16))) {\n size_t j = i / 16;\n (*stream) (in, out, j, key, ctx->Yi.c);\n ctr += (unsigned int)j;\n if (is_endian.little)\n# ifdef BSWAP4\n ctx->Yi.d[3] = BSWAP4(ctr);\n# else\n PUTU32(ctx->Yi.c + 12, ctr);\n# endif\n else\n ctx->Yi.d[3] = ctr;\n in += i;\n len -= i;\n# if defined(GHASH)\n GHASH(ctx, out, i);\n out += i;\n# else\n while (j--) {\n for (i = 0; i < 16; ++i)\n ctx->Xi.c[i] ^= out[i];\n GCM_MUL(ctx, Xi);\n out += 16;\n }\n# endif\n }\n if (len) {\n (*ctx->block) (ctx->Yi.c, ctx->EKi.c, key);\n ++ctr;\n if (is_endian.little)\n# ifdef BSWAP4\n ctx->Yi.d[3] = BSWAP4(ctr);\n# else\n PUTU32(ctx->Yi.c + 12, ctr);\n# endif\n else\n ctx->Yi.d[3] = ctr;\n while (len--) {\n ctx->Xi.c[n] ^= out[n] = in[n] ^ ctx->EKi.c[n];\n ++n;\n }\n }\n ctx->mres = n;\n return 0;\n#endif\n}'] |
34,318 | 0 | https://github.com/libav/libav/blob/fa0912fe50e59df72b7bf81f8838d2c6d9780343/libswscale/swscale.c/#L3239 | SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
float lumaSharpen, float chromaSharpen,
float chromaHShift, float chromaVShift,
int verbose)
{
SwsFilter *filter= av_malloc(sizeof(SwsFilter));
if (lumaGBlur!=0.0){
filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0);
filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0);
}else{
filter->lumH= sws_getIdentityVec();
filter->lumV= sws_getIdentityVec();
}
if (chromaGBlur!=0.0){
filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0);
filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0);
}else{
filter->chrH= sws_getIdentityVec();
filter->chrV= sws_getIdentityVec();
}
if (chromaSharpen!=0.0){
SwsVector *id= sws_getIdentityVec();
sws_scaleVec(filter->chrH, -chromaSharpen);
sws_scaleVec(filter->chrV, -chromaSharpen);
sws_addVec(filter->chrH, id);
sws_addVec(filter->chrV, id);
sws_freeVec(id);
}
if (lumaSharpen!=0.0){
SwsVector *id= sws_getIdentityVec();
sws_scaleVec(filter->lumH, -lumaSharpen);
sws_scaleVec(filter->lumV, -lumaSharpen);
sws_addVec(filter->lumH, id);
sws_addVec(filter->lumV, id);
sws_freeVec(id);
}
if (chromaHShift != 0.0)
sws_shiftVec(filter->chrH, (int)(chromaHShift+0.5));
if (chromaVShift != 0.0)
sws_shiftVec(filter->chrV, (int)(chromaVShift+0.5));
sws_normalizeVec(filter->chrH, 1.0);
sws_normalizeVec(filter->chrV, 1.0);
sws_normalizeVec(filter->lumH, 1.0);
sws_normalizeVec(filter->lumV, 1.0);
if (verbose) sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG);
if (verbose) sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);
return filter;
} | ['SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,\n float lumaSharpen, float chromaSharpen,\n float chromaHShift, float chromaVShift,\n int verbose)\n{\n SwsFilter *filter= av_malloc(sizeof(SwsFilter));\n if (lumaGBlur!=0.0){\n filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0);\n filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0);\n }else{\n filter->lumH= sws_getIdentityVec();\n filter->lumV= sws_getIdentityVec();\n }\n if (chromaGBlur!=0.0){\n filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0);\n filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0);\n }else{\n filter->chrH= sws_getIdentityVec();\n filter->chrV= sws_getIdentityVec();\n }\n if (chromaSharpen!=0.0){\n SwsVector *id= sws_getIdentityVec();\n sws_scaleVec(filter->chrH, -chromaSharpen);\n sws_scaleVec(filter->chrV, -chromaSharpen);\n sws_addVec(filter->chrH, id);\n sws_addVec(filter->chrV, id);\n sws_freeVec(id);\n }\n if (lumaSharpen!=0.0){\n SwsVector *id= sws_getIdentityVec();\n sws_scaleVec(filter->lumH, -lumaSharpen);\n sws_scaleVec(filter->lumV, -lumaSharpen);\n sws_addVec(filter->lumH, id);\n sws_addVec(filter->lumV, id);\n sws_freeVec(id);\n }\n if (chromaHShift != 0.0)\n sws_shiftVec(filter->chrH, (int)(chromaHShift+0.5));\n if (chromaVShift != 0.0)\n sws_shiftVec(filter->chrV, (int)(chromaVShift+0.5));\n sws_normalizeVec(filter->chrH, 1.0);\n sws_normalizeVec(filter->chrV, 1.0);\n sws_normalizeVec(filter->lumH, 1.0);\n sws_normalizeVec(filter->lumV, 1.0);\n if (verbose) sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG);\n if (verbose) sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);\n return filter;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}'] |
34,319 | 0 | https://github.com/openssl/openssl/blob/3208ff58ca59d143b49dd2f1c05fbc33cf35e64f/crypto/lhash/lhash.c/#L365 | static void contract(LHASH *lh)
{
LHASH_NODE **n,*n1,*np;
np=lh->b[lh->p+lh->pmax-1];
lh->b[lh->p+lh->pmax-1]=NULL;
if (lh->p == 0)
{
n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
if (n == NULL)
{
lh->error++;
return;
}
lh->num_contract_reallocs++;
lh->num_alloc_nodes/=2;
lh->pmax/=2;
lh->p=lh->pmax-1;
lh->b=n;
}
else
lh->p--;
lh->num_nodes--;
lh->num_contracts++;
n1=lh->b[(int)lh->p];
if (n1 == NULL)
lh->b[(int)lh->p]=np;
else
{
while (n1->next != NULL)
n1=n1->next;
n1->next=np;
}
} | ['int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)\n\t{\n\tint ret=0;\n\tSSL_SESSION *s;\n\tCRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION);\n\tCRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\ts=(SSL_SESSION *)lh_insert(ctx->sessions,c);\n\tif (s != NULL && s != c)\n\t\t{\n\t\tSSL_SESSION_list_remove(ctx,s);\n\t\tSSL_SESSION_free(s);\n\t\ts = NULL;\n\t\t}\n\tif (s == NULL)\n\t\tSSL_SESSION_list_add(ctx,c);\n\tif (s != NULL)\n\t\t{\n\t\tSSL_SESSION_free(s);\n\t\tret=0;\n\t\t}\n\telse\n\t\t{\n\t\tret=1;\n\t\tif (SSL_CTX_sess_get_cache_size(ctx) > 0)\n\t\t\t{\n\t\t\twhile (SSL_CTX_sess_number(ctx) >\n\t\t\t\tSSL_CTX_sess_get_cache_size(ctx))\n\t\t\t\t{\n\t\t\t\tif (!remove_session_lock(ctx,\n\t\t\t\t\tctx->session_cache_tail, 0))\n\t\t\t\t\tbreak;\n\t\t\t\telse\n\t\t\t\t\tctx->stats.sess_cache_full++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tCRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\treturn(ret);\n\t}', 'void *lh_insert(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tconst void *ret;\n\tlh->error=0;\n\tif (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))\n\t\texpand(lh);\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tif ((nn=(LHASH_NODE *)OPENSSL_malloc(sizeof(LHASH_NODE))) == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn(NULL);\n\t\t\t}\n\t\tnn->data=data;\n\t\tnn->next=NULL;\n#ifndef OPENSSL_NO_HASH_COMP\n\t\tnn->hash=hash;\n#endif\n\t\t*rn=nn;\n\t\tret=NULL;\n\t\tlh->num_insert++;\n\t\tlh->num_items++;\n\t\t}\n\telse\n\t\t{\n\t\tret= (*rn)->data;\n\t\t(*rn)->data=data;\n\t\tlh->num_replace++;\n\t\t}\n\treturn((void *)ret);\n\t}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tif ((r = (SSL_SESSION *)lh_retrieve(ctx->sessions,c)) == c)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tconst void *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn((void *)ret);\n\t}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)OPENSSL_realloc(lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}'] |
34,320 | 0 | https://gitlab.com/libtiff/libtiff/blob/3adc33842b7533066daea2516741832edc44d5fd/libtiff/tif_read.c/#L948 | static int
TIFFStartTile(TIFF* tif, uint32 tile)
{
TIFFDirectory *td = &tif->tif_dir;
if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
if (!(*tif->tif_setupdecode)(tif))
return (0);
tif->tif_flags |= TIFF_CODERSETUP;
}
tif->tif_curtile = tile;
tif->tif_row =
(tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) *
td->td_tilelength;
tif->tif_col =
(tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) *
td->td_tilewidth;
tif->tif_flags &= ~TIFF_BUF4WRITE;
if (tif->tif_flags&TIFF_NOREADRAW)
{
tif->tif_rawcp = NULL;
tif->tif_rawcc = 0;
}
else
{
tif->tif_rawcp = tif->tif_rawdata;
tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];
}
return ((*tif->tif_predecode)(tif,
(uint16)(tile/td->td_stripsperimage)));
} | ['void TIFF_ProcessFullResBlock( TIFF *hTIFF, int nPlanarConfig,\n int bSubsampled,\n int nHorSubsampling, int nVerSubsampling,\n int nOverviews, int * panOvList,\n int nBitsPerPixel,\n int nSamples, TIFFOvrCache ** papoRawBIs,\n uint32 nSXOff, uint32 nSYOff,\n unsigned char *pabySrcTile,\n uint32 nBlockXSize, uint32 nBlockYSize,\n int nSampleFormat, const char * pszResampling )\n{\n int\t\tiOverview, iSample;\n for( iSample = 0; iSample < nSamples; iSample++ )\n {\n if( nPlanarConfig == PLANARCONFIG_SEPARATE || iSample == 0 )\n {\n if( TIFFIsTiled(hTIFF) )\n {\n TIFFReadEncodedTile( hTIFF,\n TIFFComputeTile(hTIFF, nSXOff, nSYOff,\n 0, (tsample_t)iSample ),\n pabySrcTile,\n TIFFTileSize(hTIFF));\n }\n else\n {\n TIFFReadEncodedStrip( hTIFF,\n TIFFComputeStrip(hTIFF, nSYOff,\n (tsample_t) iSample),\n pabySrcTile,\n TIFFStripSize(hTIFF) );\n }\n }\n for( iOverview = 0; iOverview < nOverviews; iOverview++ )\n {\n TIFFOvrCache *poRBI = papoRawBIs[iOverview];\n unsigned char *pabyOTile;\n uint32 nTXOff, nTYOff, nOXOff, nOYOff, nOMult;\n uint32 nOBlockXSize = poRBI->nBlockXSize;\n uint32 nOBlockYSize = poRBI->nBlockYSize;\n int nSkewBits, nSampleByteOffset;\n nOMult = panOvList[iOverview];\n nOXOff = (nSXOff/nOMult) / nOBlockXSize;\n nOYOff = (nSYOff/nOMult) / nOBlockYSize;\n if( bSubsampled )\n {\n pabyOTile = TIFFGetOvrBlock_Subsampled( poRBI, nOXOff, nOYOff );\n nTXOff = (nSXOff - nOXOff*nOMult*nOBlockXSize) / nOMult;\n nTYOff = (nSYOff - nOYOff*nOMult*nOBlockYSize) / nOMult;\n#ifdef DBMALLOC\n malloc_chain_check( 1 );\n#endif\n TIFF_DownSample_Subsampled( pabySrcTile, iSample,\n nBlockXSize, nBlockYSize,\n pabyOTile,\n poRBI->nBlockXSize, poRBI->nBlockYSize,\n nTXOff, nTYOff,\n nOMult, pszResampling,\n nHorSubsampling, nVerSubsampling );\n#ifdef DBMALLOC\n malloc_chain_check( 1 );\n#endif\n }\n else\n {\n pabyOTile = TIFFGetOvrBlock( poRBI, nOXOff, nOYOff, iSample );\n nTXOff = (nSXOff - nOXOff*nOMult*nOBlockXSize) / nOMult;\n nTYOff = (nSYOff - nOYOff*nOMult*nOBlockYSize) / nOMult;\n assert( (nBitsPerPixel % 8) == 0 );\n if( nPlanarConfig == PLANARCONFIG_SEPARATE )\n {\n nSkewBits = 0;\n nSampleByteOffset = 0;\n }\n else\n {\n nSkewBits = nBitsPerPixel * (nSamples-1);\n nSampleByteOffset = (nBitsPerPixel/8) * iSample;\n }\n#ifdef DBMALLOC\n malloc_chain_check( 1 );\n#endif\n TIFF_DownSample( pabySrcTile + nSampleByteOffset,\n nBlockXSize, nBlockYSize,\n nSkewBits, nBitsPerPixel, pabyOTile,\n poRBI->nBlockXSize, poRBI->nBlockYSize,\n nTXOff, nTYOff,\n nOMult, nSampleFormat, pszResampling );\n#ifdef DBMALLOC\n malloc_chain_check( 1 );\n#endif\n }\n }\n }\n}', 'tmsize_t\nTIFFTileSize(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFTileSize";\n\tuint64 m;\n\ttmsize_t n;\n\tm=TIFFTileSize64(tif);\n\tn=(tmsize_t)m;\n\tif ((uint64)n!=m)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\tn=0;\n\t}\n\treturn(n);\n}', 'uint64\nTIFFTileSize64(TIFF* tif)\n{\n\treturn (TIFFVTileSize64(tif, tif->tif_dir.td_tilelength));\n}', 'uint64\nTIFFVTileSize64(TIFF* tif, uint32 nrows)\n{\n\tstatic const char module[] = "TIFFVTileSize64";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif (td->td_tilelength == 0 || td->td_tilewidth == 0 ||\n\t td->td_tiledepth == 0)\n\t\treturn (0);\n\tif ((td->td_planarconfig==PLANARCONFIG_CONTIG)&&\n\t (td->td_photometric==PHOTOMETRIC_YCBCR)&&\n\t (td->td_samplesperpixel==3)&&\n\t (!isUpSampled(tif)))\n\t{\n\t\tuint16 ycbcrsubsampling[2];\n\t\tuint16 samplingblock_samples;\n\t\tuint32 samplingblocks_hor;\n\t\tuint32 samplingblocks_ver;\n\t\tuint64 samplingrow_samples;\n\t\tuint64 samplingrow_size;\n\t\tTIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0,\n\t\t ycbcrsubsampling+1);\n\t\tassert((ycbcrsubsampling[0]==1)||(ycbcrsubsampling[0]==2)||(ycbcrsubsampling[0]==4));\n\t\tassert((ycbcrsubsampling[1]==1)||(ycbcrsubsampling[1]==2)||(ycbcrsubsampling[1]==4));\n\t\tif (ycbcrsubsampling[0]*ycbcrsubsampling[1]==0)\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t\t "Invalid YCbCr subsampling");\n\t\t\treturn 0;\n\t\t}\n\t\tsamplingblock_samples=ycbcrsubsampling[0]*ycbcrsubsampling[1]+2;\n\t\tsamplingblocks_hor=TIFFhowmany_32(td->td_tilewidth,ycbcrsubsampling[0]);\n\t\tsamplingblocks_ver=TIFFhowmany_32(nrows,ycbcrsubsampling[1]);\n\t\tsamplingrow_samples=multiply_64(tif,samplingblocks_hor,samplingblock_samples,module);\n\t\tsamplingrow_size=TIFFhowmany8_64(multiply_64(tif,samplingrow_samples,td->td_bitspersample,module));\n\t\treturn(multiply_64(tif,samplingrow_size,samplingblocks_ver,module));\n\t}\n\telse\n\t\treturn(multiply_64(tif,nrows,TIFFTileRowSize64(tif),module));\n}', 'tmsize_t\nTIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)\n{\n\tstatic const char module[] = "TIFFReadEncodedTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\ttmsize_t tilesize = tif->tif_tilesize;\n\tif (!TIFFCheckRead(tif, 1))\n\t\treturn ((tmsize_t)(-1));\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "%lu: Tile out of range, max %lu",\n\t\t (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n\tif (size == (tmsize_t)(-1))\n\t\tsize = tilesize;\n\telse if (size > tilesize)\n\t\tsize = tilesize;\n\tif (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,\n\t (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) {\n\t\t(*tif->tif_postdecode)(tif, (uint8*) buf, size);\n\t\treturn (size);\n\t} else\n\t\treturn ((tmsize_t)(-1));\n}', 'int\nTIFFFillTile(TIFF* tif, uint32 tile)\n{\n\tstatic const char module[] = "TIFFFillTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags&TIFF_NOREADRAW)==0)\n\t{\n\t\tuint64 bytecount = td->td_stripbytecount[tile];\n\t\tif (bytecount <= 0) {\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%I64u: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned __int64) bytecount,\n\t\t\t\t (unsigned long) tile);\n#else\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%llu: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned long long) bytecount,\n\t\t\t\t (unsigned long) tile);\n#endif\n\t\t\treturn (0);\n\t\t}\n\t\tif (isMapped(tif) &&\n\t\t (isFillOrder(tif, td->td_fillorder)\n\t\t || (tif->tif_flags & TIFF_NOBITREV))) {\n\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)\n\t\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\ttif->tif_flags &= ~TIFF_MYBUFFER;\n\t\t\tif (bytecount > (uint64)tif->tif_size ||\n\t\t\t td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\ttif->tif_rawdatasize = (tmsize_t)bytecount;\n\t\t\ttif->tif_rawdata =\n\t\t\t\ttif->tif_base + (tmsize_t)td->td_stripoffset[tile];\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = (tmsize_t) bytecount;\n\t\t} else {\n\t\t\ttmsize_t bytecountm;\n\t\t\tbytecountm=(tmsize_t)bytecount;\n\t\t\tif ((uint64)bytecountm!=bytecount)\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif (bytecountm > tif->tif_rawdatasize) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) == 0) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Data buffer too small to hold tile %lu",\n\t\t\t\t\t (unsigned long) tile);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (TIFFReadRawTile1(tif, tile, tif->tif_rawdata,\n\t\t\t bytecountm, module) != bytecountm)\n\t\t\t\treturn (0);\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = bytecountm;\n\t\t\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t\t\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\t\t\tTIFFReverseBits(tif->tif_rawdata,\n tif->tif_rawdataloaded);\n\t\t}\n\t}\n\treturn (TIFFStartTile(tif, tile));\n}', 'static int\nTIFFStartTile(TIFF* tif, uint32 tile)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupdecode)(tif))\n\t\t\treturn (0);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_curtile = tile;\n\ttif->tif_row =\n\t (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) *\n\t\ttd->td_tilelength;\n\ttif->tif_col =\n\t (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) *\n\t\ttd->td_tilewidth;\n tif->tif_flags &= ~TIFF_BUF4WRITE;\n\tif (tif->tif_flags&TIFF_NOREADRAW)\n\t{\n\t\ttif->tif_rawcp = NULL;\n\t\ttif->tif_rawcc = 0;\n\t}\n\telse\n\t{\n\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\ttif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];\n\t}\n\treturn ((*tif->tif_predecode)(tif,\n\t\t\t(uint16)(tile/td->td_stripsperimage)));\n}'] |
34,321 | 0 | https://github.com/openssl/openssl/blob/09977dd095f3c655c99b9e1810a213f7eafa7364/crypto/bn/bn_lib.c/#L342 | static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *A, *a = NULL;
const BN_ULONG *B;
int i;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b,BN_FLG_SECURE))
a = A = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = A = OPENSSL_zalloc(words * sizeof(*a));
if (A == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
#if 1
B = b->d;
if (B != NULL) {
for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
BN_ULONG a0, a1, a2, a3;
a0 = B[0];
a1 = B[1];
a2 = B[2];
a3 = B[3];
A[0] = a0;
A[1] = a1;
A[2] = a2;
A[3] = a3;
}
switch (b->top & 3) {
case 3:
A[2] = B[2];
case 2:
A[1] = B[1];
case 1:
A[0] = B[0];
case 0:
;
}
}
#else
memset(A, 0, sizeof(*A) * words);
memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
return (a);
} | ['BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if(((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *A, *a = NULL;\n const BN_ULONG *B;\n int i;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b,BN_FLG_SECURE))\n a = A = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = A = OPENSSL_zalloc(words * sizeof(*a));\n if (A == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n#if 1\n B = b->d;\n if (B != NULL) {\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:\n ;\n }\n }\n#else\n memset(A, 0, sizeof(*A) * words);\n memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n return (a);\n}'] |
34,322 | 0 | https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L333 | BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
bn_check_top(b);
if (a == b)
return a;
if (bn_wexpand(a, b->top) == NULL)
return NULL;
if (b->top > 0)
memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
a->top = b->top;
a->neg = b->neg;
bn_check_top(a);
return a;
} | ['static int ecdh_cms_decrypt(CMS_RecipientInfo *ri)\n{\n EVP_PKEY_CTX *pctx;\n pctx = CMS_RecipientInfo_get0_pkey_ctx(ri);\n if (!pctx)\n return 0;\n if (!EVP_PKEY_CTX_get0_peerkey(pctx)) {\n X509_ALGOR *alg;\n ASN1_BIT_STRING *pubkey;\n if (!CMS_RecipientInfo_kari_get0_orig_id(ri, &alg, &pubkey,\n NULL, NULL, NULL))\n return 0;\n if (!alg || !pubkey)\n return 0;\n if (!ecdh_cms_set_peerkey(pctx, alg, pubkey)) {\n ECerr(EC_F_ECDH_CMS_DECRYPT, EC_R_PEER_KEY_ERROR);\n return 0;\n }\n }\n if (!ecdh_cms_set_shared_info(pctx, ri)) {\n ECerr(EC_F_ECDH_CMS_DECRYPT, EC_R_SHARED_INFO_ERROR);\n return 0;\n }\n return 1;\n}', 'static int ecdh_cms_set_peerkey(EVP_PKEY_CTX *pctx,\n X509_ALGOR *alg, ASN1_BIT_STRING *pubkey)\n{\n const ASN1_OBJECT *aoid;\n int atype;\n const void *aval;\n int rv = 0;\n EVP_PKEY *pkpeer = NULL;\n EC_KEY *ecpeer = NULL;\n const unsigned char *p;\n int plen;\n X509_ALGOR_get0(&aoid, &atype, &aval, alg);\n if (OBJ_obj2nid(aoid) != NID_X9_62_id_ecPublicKey)\n goto err;\n if (atype == V_ASN1_UNDEF || atype == V_ASN1_NULL) {\n const EC_GROUP *grp;\n EVP_PKEY *pk;\n pk = EVP_PKEY_CTX_get0_pkey(pctx);\n if (!pk)\n goto err;\n grp = EC_KEY_get0_group(pk->pkey.ec);\n ecpeer = EC_KEY_new();\n if (ecpeer == NULL)\n goto err;\n if (!EC_KEY_set_group(ecpeer, grp))\n goto err;\n } else {\n ecpeer = eckey_type2param(atype, aval);\n if (!ecpeer)\n goto err;\n }\n plen = ASN1_STRING_length(pubkey);\n p = ASN1_STRING_get0_data(pubkey);\n if (!p || !plen)\n goto err;\n if (!o2i_ECPublicKey(&ecpeer, &p, plen))\n goto err;\n pkpeer = EVP_PKEY_new();\n if (pkpeer == NULL)\n goto err;\n EVP_PKEY_set1_EC_KEY(pkpeer, ecpeer);\n if (EVP_PKEY_derive_set_peer(pctx, pkpeer) > 0)\n rv = 1;\n err:\n EC_KEY_free(ecpeer);\n EVP_PKEY_free(pkpeer);\n return rv;\n}', 'int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)\n{\n if (key->meth->set_group != NULL && key->meth->set_group(key, group) == 0)\n return 0;\n EC_GROUP_free(key->group);\n key->group = EC_GROUP_dup(group);\n return (key->group == NULL) ? 0 : 1;\n}', 'EC_GROUP *EC_GROUP_dup(const EC_GROUP *a)\n{\n EC_GROUP *t = NULL;\n int ok = 0;\n if (a == NULL)\n return NULL;\n if ((t = EC_GROUP_new(a->meth)) == NULL)\n return (NULL);\n if (!EC_GROUP_copy(t, a))\n goto err;\n ok = 1;\n err:\n if (!ok) {\n EC_GROUP_free(t);\n return NULL;\n }\n return t;\n}', 'int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)\n{\n if (dest->meth->group_copy == 0) {\n ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n if (dest->meth != src->meth) {\n ECerr(EC_F_EC_GROUP_COPY, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n if (dest == src)\n return 1;\n dest->pre_comp_type = src->pre_comp_type;\n switch (src->pre_comp_type) {\n case PCT_none:\n dest->pre_comp.ec = NULL;\n break;\n case PCT_nistz256:\n#ifdef ECP_NISTZ256_ASM\n dest->pre_comp.nistz256 = EC_nistz256_pre_comp_dup(src->pre_comp.nistz256);\n#endif\n break;\n#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128\n case PCT_nistp224:\n dest->pre_comp.nistp224 = EC_nistp224_pre_comp_dup(src->pre_comp.nistp224);\n break;\n case PCT_nistp256:\n dest->pre_comp.nistp256 = EC_nistp256_pre_comp_dup(src->pre_comp.nistp256);\n break;\n case PCT_nistp521:\n dest->pre_comp.nistp521 = EC_nistp521_pre_comp_dup(src->pre_comp.nistp521);\n break;\n#else\n case PCT_nistp224:\n case PCT_nistp256:\n case PCT_nistp521:\n break;\n#endif\n case PCT_ec:\n dest->pre_comp.ec = EC_ec_pre_comp_dup(src->pre_comp.ec);\n break;\n }\n if (src->mont_data != NULL) {\n if (dest->mont_data == NULL) {\n dest->mont_data = BN_MONT_CTX_new();\n if (dest->mont_data == NULL)\n return 0;\n }\n if (!BN_MONT_CTX_copy(dest->mont_data, src->mont_data))\n return 0;\n } else {\n BN_MONT_CTX_free(dest->mont_data);\n dest->mont_data = NULL;\n }\n if (src->generator != NULL) {\n if (dest->generator == NULL) {\n dest->generator = EC_POINT_new(dest);\n if (dest->generator == NULL)\n return 0;\n }\n if (!EC_POINT_copy(dest->generator, src->generator))\n return 0;\n } else {\n EC_POINT_clear_free(dest->generator);\n dest->generator = NULL;\n }\n if ((src->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0) {\n if (!BN_copy(dest->order, src->order))\n return 0;\n if (!BN_copy(dest->cofactor, src->cofactor))\n return 0;\n }\n dest->curve_name = src->curve_name;\n dest->asn1_flag = src->asn1_flag;\n dest->asn1_form = src->asn1_form;\n if (src->seed) {\n OPENSSL_free(dest->seed);\n dest->seed = OPENSSL_malloc(src->seed_len);\n if (dest->seed == NULL)\n return 0;\n if (!memcpy(dest->seed, src->seed, src->seed_len))\n return 0;\n dest->seed_len = src->seed_len;\n } else {\n OPENSSL_free(dest->seed);\n dest->seed = NULL;\n dest->seed_len = 0;\n }\n return dest->meth->group_copy(dest, src);\n}', 'BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)\n{\n if (to == from)\n return (to);\n if (!BN_copy(&(to->RR), &(from->RR)))\n return NULL;\n if (!BN_copy(&(to->N), &(from->N)))\n return NULL;\n if (!BN_copy(&(to->Ni), &(from->Ni)))\n return NULL;\n to->ri = from->ri;\n to->n0[0] = from->n0[0];\n to->n0[1] = from->n0[1];\n return (to);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}'] |
34,323 | 0 | https://github.com/openssl/openssl/blob/9dd4ac8cf17f2afd636e85ae0111d1df4104a475/ssl/ssl_lib.c/#L4350 | static int nss_keylog_int(const char *prefix,
SSL *ssl,
const uint8_t *parameter_1,
size_t parameter_1_len,
const uint8_t *parameter_2,
size_t parameter_2_len)
{
char *out = NULL;
char *cursor = NULL;
size_t out_len = 0;
size_t i;
size_t prefix_len;
if (ssl->ctx->keylog_callback == NULL) return 1;
prefix_len = strlen(prefix);
out_len = prefix_len + (2*parameter_1_len) + (2*parameter_2_len) + 3;
if ((out = cursor = OPENSSL_malloc(out_len)) == NULL) {
SSLerr(SSL_F_NSS_KEYLOG_INT, ERR_R_MALLOC_FAILURE);
return 0;
}
strcpy(cursor, prefix);
cursor += prefix_len;
*cursor++ = ' ';
for (i = 0; i < parameter_1_len; i++) {
sprintf(cursor, "%02x", parameter_1[i]);
cursor += 2;
}
*cursor++ = ' ';
for (i = 0; i < parameter_2_len; i++) {
sprintf(cursor, "%02x", parameter_2[i]);
cursor += 2;
}
*cursor = '\0';
ssl->ctx->keylog_callback(ssl, (const char *)out);
OPENSSL_free(out);
return 1;
} | ['static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt, int *al)\n{\n#ifndef OPENSSL_NO_RSA\n unsigned char *encdata = NULL;\n EVP_PKEY *pkey = NULL;\n EVP_PKEY_CTX *pctx = NULL;\n size_t enclen;\n unsigned char *pms = NULL;\n size_t pmslen = 0;\n if (s->session->peer == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pkey = X509_get0_pubkey(s->session->peer);\n if (EVP_PKEY_get0_RSA(pkey) == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pmslen = SSL_MAX_MASTER_KEY_LENGTH;\n pms = OPENSSL_malloc(pmslen);\n if (pms == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);\n *al = SSL_AD_INTERNAL_ERROR;\n return 0;\n }\n pms[0] = s->client_version >> 8;\n pms[1] = s->client_version & 0xff;\n if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {\n goto err;\n }\n if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n pctx = EVP_PKEY_CTX_new(pkey, NULL);\n if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0\n || EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_EVP_LIB);\n goto err;\n }\n if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)\n || EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, SSL_R_BAD_RSA_ENCRYPT);\n goto err;\n }\n EVP_PKEY_CTX_free(pctx);\n pctx = NULL;\n# ifdef PKCS1_CHECK\n if (s->options & SSL_OP_PKCS1_CHECK_1)\n (*p)[1]++;\n if (s->options & SSL_OP_PKCS1_CHECK_2)\n tmp_buf[0] = 0x70;\n# endif\n if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n s->s3->tmp.pms = pms;\n s->s3->tmp.pmslen = pmslen;\n if (!ssl_log_rsa_client_key_exchange(s, encdata, enclen, pms, pmslen))\n goto err;\n return 1;\n err:\n OPENSSL_clear_free(pms, pmslen);\n EVP_PKEY_CTX_free(pctx);\n return 0;\n#else\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n *al = SSL_AD_INTERNAL_ERROR;\n return 0;\n#endif\n}', 'int ssl_log_rsa_client_key_exchange(SSL *ssl,\n const uint8_t *encrypted_premaster,\n size_t encrypted_premaster_len,\n const uint8_t *premaster,\n size_t premaster_len)\n{\n if (encrypted_premaster_len < 8) {\n SSLerr(SSL_F_SSL_LOG_RSA_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n return nss_keylog_int("RSA",\n ssl,\n encrypted_premaster,\n 8,\n premaster,\n premaster_len);\n}', 'static int nss_keylog_int(const char *prefix,\n SSL *ssl,\n const uint8_t *parameter_1,\n size_t parameter_1_len,\n const uint8_t *parameter_2,\n size_t parameter_2_len)\n{\n char *out = NULL;\n char *cursor = NULL;\n size_t out_len = 0;\n size_t i;\n size_t prefix_len;\n if (ssl->ctx->keylog_callback == NULL) return 1;\n prefix_len = strlen(prefix);\n out_len = prefix_len + (2*parameter_1_len) + (2*parameter_2_len) + 3;\n if ((out = cursor = OPENSSL_malloc(out_len)) == NULL) {\n SSLerr(SSL_F_NSS_KEYLOG_INT, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n strcpy(cursor, prefix);\n cursor += prefix_len;\n *cursor++ = \' \';\n for (i = 0; i < parameter_1_len; i++) {\n sprintf(cursor, "%02x", parameter_1[i]);\n cursor += 2;\n }\n *cursor++ = \' \';\n for (i = 0; i < parameter_2_len; i++) {\n sprintf(cursor, "%02x", parameter_2[i]);\n cursor += 2;\n }\n *cursor = \'\\0\';\n ssl->ctx->keylog_callback(ssl, (const char *)out);\n OPENSSL_free(out);\n return 1;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}'] |
34,324 | 0 | https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavcodec/mpegaudiodec.c/#L906 | void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
MPA_INT *window, int *dither_state,
OUT_INT *samples, int incr,
int32_t sb_samples[SBLIMIT])
{
int32_t tmp[32];
register MPA_INT *synth_buf;
register const MPA_INT *w, *w2, *p;
int j, offset, v;
OUT_INT *samples2;
#if FRAC_BITS <= 15
int sum, sum2;
#else
int64_t sum, sum2;
#endif
dct32(tmp, sb_samples);
offset = *synth_buf_offset;
synth_buf = synth_buf_ptr + offset;
for(j=0;j<32;j++) {
v = tmp[j];
#if FRAC_BITS <= 15
v = av_clip_int16(v);
#endif
synth_buf[j] = v;
}
memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));
samples2 = samples + 31 * incr;
w = window;
w2 = window + 31;
sum = *dither_state;
p = synth_buf + 16;
SUM8(MACS, sum, w, p);
p = synth_buf + 48;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
samples += incr;
w++;
for(j=1;j<16;j++) {
sum2 = 0;
p = synth_buf + 16 + j;
SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);
p = synth_buf + 48 - j;
SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);
*samples = round_sample(&sum);
samples += incr;
sum += sum2;
*samples2 = round_sample(&sum);
samples2 -= incr;
w++;
w2--;
}
p = synth_buf + 32;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
*dither_state= sum;
offset = (offset - 32) & 511;
*synth_buf_offset = offset;
} | ['static int decode_frame_mp3on4(AVCodecContext * avctx,\n void *data, int *data_size,\n const uint8_t * buf, int buf_size)\n{\n MP3On4DecodeContext *s = avctx->priv_data;\n MPADecodeContext *m;\n int fsize, len = buf_size, out_size = 0;\n uint32_t header;\n OUT_INT *out_samples = data;\n OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS];\n OUT_INT *outptr, *bp;\n int fr, j, n;\n *data_size = 0;\n if (buf_size < HEADER_SIZE)\n return -1;\n outptr = s->frames == 1 ? out_samples : decoded_buf;\n avctx->bit_rate = 0;\n for (fr = 0; fr < s->frames; fr++) {\n fsize = AV_RB16(buf) >> 4;\n fsize = FFMIN3(fsize, len, MPA_MAX_CODED_FRAME_SIZE);\n m = s->mp3decctx[fr];\n assert (m != NULL);\n header = (AV_RB32(buf) & 0x000fffff) | s->syncword;\n if (ff_mpa_check_header(header) < 0)\n break;\n ff_mpegaudio_decode_header(m, header);\n out_size += mp_decode_frame(m, outptr, buf, fsize);\n buf += fsize;\n len -= fsize;\n if(s->frames > 1) {\n n = m->avctx->frame_size*m->nb_channels;\n bp = out_samples + s->coff[fr];\n if(m->nb_channels == 1) {\n for(j = 0; j < n; j++) {\n *bp = decoded_buf[j];\n bp += avctx->channels;\n }\n } else {\n for(j = 0; j < n; j++) {\n bp[0] = decoded_buf[j++];\n bp[1] = decoded_buf[j];\n bp += avctx->channels;\n }\n }\n }\n avctx->bit_rate += m->bit_rate;\n }\n avctx->sample_rate = s->mp3decctx[0]->sample_rate;\n *data_size = out_size;\n return buf_size;\n}', 'int ff_mpegaudio_decode_header(MPADecodeContext *s, uint32_t header)\n{\n int sample_rate, frame_size, mpeg25, padding;\n int sample_rate_index, bitrate_index;\n if (header & (1<<20)) {\n s->lsf = (header & (1<<19)) ? 0 : 1;\n mpeg25 = 0;\n } else {\n s->lsf = 1;\n mpeg25 = 1;\n }\n s->layer = 4 - ((header >> 17) & 3);\n sample_rate_index = (header >> 10) & 3;\n sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);\n sample_rate_index += 3 * (s->lsf + mpeg25);\n s->sample_rate_index = sample_rate_index;\n s->error_protection = ((header >> 16) & 1) ^ 1;\n s->sample_rate = sample_rate;\n bitrate_index = (header >> 12) & 0xf;\n padding = (header >> 9) & 1;\n s->mode = (header >> 6) & 3;\n s->mode_ext = (header >> 4) & 3;\n if (s->mode == MPA_MONO)\n s->nb_channels = 1;\n else\n s->nb_channels = 2;\n if (bitrate_index != 0) {\n frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];\n s->bit_rate = frame_size * 1000;\n switch(s->layer) {\n case 1:\n frame_size = (frame_size * 12000) / sample_rate;\n frame_size = (frame_size + padding) * 4;\n break;\n case 2:\n frame_size = (frame_size * 144000) / sample_rate;\n frame_size += padding;\n break;\n default:\n case 3:\n frame_size = (frame_size * 144000) / (sample_rate << s->lsf);\n frame_size += padding;\n break;\n }\n s->frame_size = frame_size;\n } else {\n return 1;\n }\n#if defined(DEBUG)\n dprintf(s->avctx, "layer%d, %d Hz, %d kbits/s, ",\n s->layer, s->sample_rate, s->bit_rate);\n if (s->nb_channels == 2) {\n if (s->layer == 3) {\n if (s->mode_ext & MODE_EXT_MS_STEREO)\n dprintf(s->avctx, "ms-");\n if (s->mode_ext & MODE_EXT_I_STEREO)\n dprintf(s->avctx, "i-");\n }\n dprintf(s->avctx, "stereo");\n } else {\n dprintf(s->avctx, "mono");\n }\n dprintf(s->avctx, "\\n");\n#endif\n return 0;\n}', 'static int mp_decode_frame(MPADecodeContext *s,\n OUT_INT *samples, const uint8_t *buf, int buf_size)\n{\n int i, nb_frames, ch;\n OUT_INT *samples_ptr;\n init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE)*8);\n if (s->error_protection)\n skip_bits(&s->gb, 16);\n dprintf(s->avctx, "frame %d:\\n", s->frame_count);\n switch(s->layer) {\n case 1:\n s->avctx->frame_size = 384;\n nb_frames = mp_decode_layer1(s);\n break;\n case 2:\n s->avctx->frame_size = 1152;\n nb_frames = mp_decode_layer2(s);\n break;\n case 3:\n s->avctx->frame_size = s->lsf ? 576 : 1152;\n default:\n nb_frames = mp_decode_layer3(s);\n s->last_buf_size=0;\n if(s->in_gb.buffer){\n align_get_bits(&s->gb);\n i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3;\n if(i >= 0 && i <= BACKSTEP_SIZE){\n memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i);\n s->last_buf_size=i;\n }else\n av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\\n", i);\n s->gb= s->in_gb;\n s->in_gb.buffer= NULL;\n }\n align_get_bits(&s->gb);\n assert((get_bits_count(&s->gb) & 7) == 0);\n i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3;\n if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){\n av_log(s->avctx, AV_LOG_WARNING, "invalid new backstep %d\\n", i);\n i= FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE);\n }\n assert(i <= buf_size - HEADER_SIZE && i>= 0);\n memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i);\n s->last_buf_size += i;\n break;\n }\n#if defined(DEBUG)\n for(i=0;i<nb_frames;i++) {\n for(ch=0;ch<s->nb_channels;ch++) {\n int j;\n dprintf(s->avctx, "%d-%d:", i, ch);\n for(j=0;j<SBLIMIT;j++)\n dprintf(s->avctx, " %0.6f", (double)s->sb_samples[ch][i][j] / FRAC_ONE);\n dprintf(s->avctx, "\\n");\n }\n }\n#endif\n for(ch=0;ch<s->nb_channels;ch++) {\n samples_ptr = samples + ch;\n for(i=0;i<nb_frames;i++) {\n ff_mpa_synth_filter(s->synth_buf[ch], &(s->synth_buf_offset[ch]),\n window, &s->dither_state,\n samples_ptr, s->nb_channels,\n s->sb_samples[ch][i]);\n samples_ptr += 32 * s->nb_channels;\n }\n }\n#ifdef DEBUG\n s->frame_count++;\n#endif\n return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n int32_t sb_samples[SBLIMIT])\n{\n int32_t tmp[32];\n register MPA_INT *synth_buf;\n register const MPA_INT *w, *w2, *p;\n int j, offset, v;\n OUT_INT *samples2;\n#if FRAC_BITS <= 15\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n dct32(tmp, sb_samples);\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n for(j=0;j<32;j++) {\n v = tmp[j];\n#if FRAC_BITS <= 15\n v = av_clip_int16(v);\n#endif\n synth_buf[j] = v;\n }\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}'] |
34,325 | 0 | https://github.com/openssl/openssl/blob/5ea564f154ebe8bda2a0e091a312e2058edf437f/crypto/bn/bn_lib.c/#L717 | int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)
{
int i;
BN_ULONG aa, bb;
aa = a[n - 1];
bb = b[n - 1];
if (aa != bb)
return ((aa > bb) ? 1 : -1);
for (i = n - 2; i >= 0; i--) {
aa = a[i];
bb = b[i];
if (aa != bb)
return ((aa > bb) ? 1 : -1);
}
return (0);
} | ['int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,\n BN_RECP_CTX *recp, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *a;\n const BIGNUM *ca;\n BN_CTX_start(ctx);\n if ((a = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (y != NULL) {\n if (x == y) {\n if (!BN_sqr(a, x, ctx))\n goto err;\n } else {\n if (!BN_mul(a, x, y, ctx))\n goto err;\n }\n ca = a;\n } else\n ca = x;\n ret = BN_div_recp(NULL, r, ca, recp, ctx);\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return (ret);\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,\n int dna, int dnb, BN_ULONG *t)\n{\n int n = n2 / 2, c1, c2;\n int tna = n + dna, tnb = n + dnb;\n unsigned int neg, zero;\n BN_ULONG ln, lo, *p;\n# ifdef BN_MUL_COMBA\n# if 0\n if (n2 == 4) {\n bn_mul_comba4(r, a, b);\n return;\n }\n# endif\n if (n2 == 8 && dna == 0 && dnb == 0) {\n bn_mul_comba8(r, a, b);\n return;\n }\n# endif\n if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(r, a, n2 + dna, b, n2 + dnb);\n if ((dna + dnb) < 0)\n memset(&r[2 * n2 + dna + dnb], 0,\n sizeof(BN_ULONG) * -(dna + dnb));\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n zero = neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n zero = 1;\n break;\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n zero = 1;\n break;\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n zero = 1;\n break;\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# ifdef BN_MUL_COMBA\n if (n == 4 && dna == 0 && dnb == 0) {\n if (!zero)\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n else\n memset(&t[n2], 0, sizeof(*t) * 8);\n bn_mul_comba4(r, a, b);\n bn_mul_comba4(&(r[n2]), &(a[n]), &(b[n]));\n } else if (n == 8 && dna == 0 && dnb == 0) {\n if (!zero)\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n else\n memset(&t[n2], 0, sizeof(*t) * 16);\n bn_mul_comba8(r, a, b);\n bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));\n } else\n# endif\n {\n p = &(t[n2 * 2]);\n if (!zero)\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n else\n memset(&t[n2], 0, sizeof(*t) * n2);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), n, dna, dnb, p);\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)\n{\n int n, i;\n n = cl - 1;\n if (dl < 0) {\n for (i = dl; i < 0; i++) {\n if (b[n - i] != 0)\n return -1;\n }\n }\n if (dl > 0) {\n for (i = dl; i > 0; i--) {\n if (a[n + i] != 0)\n return 1;\n }\n }\n return bn_cmp_words(a, b, cl);\n}', 'int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)\n{\n int i;\n BN_ULONG aa, bb;\n aa = a[n - 1];\n bb = b[n - 1];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n for (i = n - 2; i >= 0; i--) {\n aa = a[i];\n bb = b[i];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n }\n return (0);\n}'] |
34,326 | 0 | https://github.com/libav/libav/blob/7fa70598e83cca650717d02ac96bcf55e9f97c19/libavformat/electronicarts.c/#L447 | static int ea_read_packet(AVFormatContext *s,
AVPacket *pkt)
{
EaDemuxContext *ea = s->priv_data;
ByteIOContext *pb = s->pb;
int ret = 0;
int packet_read = 0;
unsigned int chunk_type, chunk_size;
int key = 0;
int av_uninit(num_samples);
while (!packet_read) {
chunk_type = get_le32(pb);
chunk_size = (ea->big_endian ? get_be32(pb) : get_le32(pb)) - 8;
switch (chunk_type) {
case ISNh_TAG:
url_fskip(pb, 32);
chunk_size -= 32;
case ISNd_TAG:
case SCDl_TAG:
case SNDC_TAG:
case SDEN_TAG:
if (!ea->audio_codec) {
url_fskip(pb, chunk_size);
break;
} else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR ||
ea->audio_codec == CODEC_ID_MP3) {
num_samples = get_le32(pb);
url_fskip(pb, 8);
chunk_size -= 12;
}
ret = av_get_packet(pb, pkt, chunk_size);
if (ret != chunk_size)
ret = AVERROR(EIO);
else {
pkt->stream_index = ea->audio_stream_index;
pkt->pts = 90000;
pkt->pts *= ea->audio_frame_counter;
pkt->pts /= ea->sample_rate;
switch (ea->audio_codec) {
case CODEC_ID_ADPCM_EA:
ea->audio_frame_counter += ((chunk_size - 12) * 2) /
ea->num_channels;
break;
case CODEC_ID_PCM_S16LE_PLANAR:
case CODEC_ID_MP3:
ea->audio_frame_counter += num_samples;
break;
default:
ea->audio_frame_counter += chunk_size /
(ea->bytes * ea->num_channels);
}
}
packet_read = 1;
break;
case 0:
case ISNe_TAG:
case SCEl_TAG:
case SEND_TAG:
case SEEN_TAG:
ret = AVERROR(EIO);
packet_read = 1;
break;
case MVIh_TAG:
case kVGT_TAG:
case pQGT_TAG:
case TGQs_TAG:
key = PKT_FLAG_KEY;
case MVIf_TAG:
case fVGT_TAG:
url_fseek(pb, -8, SEEK_CUR);
chunk_size += 8;
goto get_video_packet;
case mTCD_TAG:
url_fseek(pb, 8, SEEK_CUR);
chunk_size -= 8;
goto get_video_packet;
case MV0K_TAG:
case MPCh_TAG:
case pIQT_TAG:
key = PKT_FLAG_KEY;
case MV0F_TAG:
get_video_packet:
ret = av_get_packet(pb, pkt, chunk_size);
if (ret != chunk_size)
ret = AVERROR_IO;
else {
pkt->stream_index = ea->video_stream_index;
pkt->flags |= key;
}
packet_read = 1;
break;
default:
url_fseek(pb, chunk_size, SEEK_CUR);
break;
}
}
return ret;
} | ['static int ea_read_packet(AVFormatContext *s,\n AVPacket *pkt)\n{\n EaDemuxContext *ea = s->priv_data;\n ByteIOContext *pb = s->pb;\n int ret = 0;\n int packet_read = 0;\n unsigned int chunk_type, chunk_size;\n int key = 0;\n int av_uninit(num_samples);\n while (!packet_read) {\n chunk_type = get_le32(pb);\n chunk_size = (ea->big_endian ? get_be32(pb) : get_le32(pb)) - 8;\n switch (chunk_type) {\n case ISNh_TAG:\n url_fskip(pb, 32);\n chunk_size -= 32;\n case ISNd_TAG:\n case SCDl_TAG:\n case SNDC_TAG:\n case SDEN_TAG:\n if (!ea->audio_codec) {\n url_fskip(pb, chunk_size);\n break;\n } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR ||\n ea->audio_codec == CODEC_ID_MP3) {\n num_samples = get_le32(pb);\n url_fskip(pb, 8);\n chunk_size -= 12;\n }\n ret = av_get_packet(pb, pkt, chunk_size);\n if (ret != chunk_size)\n ret = AVERROR(EIO);\n else {\n pkt->stream_index = ea->audio_stream_index;\n pkt->pts = 90000;\n pkt->pts *= ea->audio_frame_counter;\n pkt->pts /= ea->sample_rate;\n switch (ea->audio_codec) {\n case CODEC_ID_ADPCM_EA:\n ea->audio_frame_counter += ((chunk_size - 12) * 2) /\n ea->num_channels;\n break;\n case CODEC_ID_PCM_S16LE_PLANAR:\n case CODEC_ID_MP3:\n ea->audio_frame_counter += num_samples;\n break;\n default:\n ea->audio_frame_counter += chunk_size /\n (ea->bytes * ea->num_channels);\n }\n }\n packet_read = 1;\n break;\n case 0:\n case ISNe_TAG:\n case SCEl_TAG:\n case SEND_TAG:\n case SEEN_TAG:\n ret = AVERROR(EIO);\n packet_read = 1;\n break;\n case MVIh_TAG:\n case kVGT_TAG:\n case pQGT_TAG:\n case TGQs_TAG:\n key = PKT_FLAG_KEY;\n case MVIf_TAG:\n case fVGT_TAG:\n url_fseek(pb, -8, SEEK_CUR);\n chunk_size += 8;\n goto get_video_packet;\n case mTCD_TAG:\n url_fseek(pb, 8, SEEK_CUR);\n chunk_size -= 8;\n goto get_video_packet;\n case MV0K_TAG:\n case MPCh_TAG:\n case pIQT_TAG:\n key = PKT_FLAG_KEY;\n case MV0F_TAG:\nget_video_packet:\n ret = av_get_packet(pb, pkt, chunk_size);\n if (ret != chunk_size)\n ret = AVERROR_IO;\n else {\n pkt->stream_index = ea->video_stream_index;\n pkt->flags |= key;\n }\n packet_read = 1;\n break;\n default:\n url_fseek(pb, chunk_size, SEEK_CUR);\n break;\n }\n }\n return ret;\n}'] |
34,327 | 0 | https://github.com/openssl/openssl/blob/a14715888bc4b5bd2b1da3f8ac7d4cabef8c9cb8/crypto/init.c/#L402 | int ossl_init_thread_start(uint64_t opts)
{
struct thread_local_inits_st *locals;
if (!OPENSSL_init_crypto(0, NULL))
return 0;
locals = ossl_init_get_thread_local(1);
if (locals == NULL)
return 0;
if (opts & OPENSSL_INIT_THREAD_ASYNC) {
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
"marking thread for async\n");
#endif
locals->async = 1;
}
if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
"marking thread for err_state\n");
#endif
locals->err_state = 1;
}
return 1;
} | ['int ossl_init_thread_start(uint64_t opts)\n{\n struct thread_local_inits_st *locals;\n if (!OPENSSL_init_crypto(0, NULL))\n return 0;\n locals = ossl_init_get_thread_local(1);\n if (locals == NULL)\n return 0;\n if (opts & OPENSSL_INIT_THREAD_ASYNC) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for async\\n");\n#endif\n locals->async = 1;\n }\n if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for err_state\\n");\n#endif\n locals->err_state = 1;\n }\n return 1;\n}', 'static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)\n{\n struct thread_local_inits_st *local =\n CRYPTO_THREAD_get_local(&threadstopkey);\n if (local == NULL && alloc) {\n local = OPENSSL_zalloc(sizeof(*local));\n if (local != NULL && !CRYPTO_THREAD_set_local(&threadstopkey, local)) {\n OPENSSL_free(local);\n return NULL;\n }\n }\n if (!alloc) {\n CRYPTO_THREAD_set_local(&threadstopkey, NULL);\n }\n return local;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)\n{\n if (pthread_setspecific(*key, val) != 0)\n return 0;\n return 1;\n}'] |
34,328 | 0 | https://github.com/libav/libav/blob/7fa70598e83cca650717d02ac96bcf55e9f97c19/libavcodec/msmpeg4.c/#L1612 | int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
int n, int coded, const uint8_t *scan_table)
{
int level, i, last, run, run_diff;
int av_uninit(dc_pred_dir);
RLTable *rl;
RL_VLC_ELEM *rl_vlc;
int qmul, qadd;
if (s->mb_intra) {
qmul=1;
qadd=0;
level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
if (level < 0){
av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
if(s->inter_intra_pred) level=0;
else return -1;
}
if (n < 4) {
rl = &rl_table[s->rl_table_index];
if(level > 256*s->y_dc_scale){
av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);
if(!s->inter_intra_pred) return -1;
}
} else {
rl = &rl_table[3 + s->rl_chroma_table_index];
if(level > 256*s->c_dc_scale){
av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);
if(!s->inter_intra_pred) return -1;
}
}
block[0] = level;
run_diff = s->msmpeg4_version >= 4;
i = 0;
if (!coded) {
goto not_coded;
}
if (s->ac_pred) {
if (dc_pred_dir == 0)
scan_table = s->intra_v_scantable.permutated;
else
scan_table = s->intra_h_scantable.permutated;
} else {
scan_table = s->intra_scantable.permutated;
}
rl_vlc= rl->rl_vlc[0];
} else {
qmul = s->qscale << 1;
qadd = (s->qscale - 1) | 1;
i = -1;
rl = &rl_table[3 + s->rl_table_index];
if(s->msmpeg4_version==2)
run_diff = 0;
else
run_diff = 1;
if (!coded) {
s->block_last_index[n] = i;
return 0;
}
if(!scan_table)
scan_table = s->inter_scantable.permutated;
rl_vlc= rl->rl_vlc[s->qscale];
}
{
OPEN_READER(re, &s->gb);
for(;;) {
UPDATE_CACHE(re, &s->gb);
GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
if (level==0) {
int cache;
cache= GET_CACHE(re, &s->gb);
if (s->msmpeg4_version==1 || (cache&0x80000000)==0) {
if (s->msmpeg4_version==1 || (cache&0x40000000)==0) {
if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2);
UPDATE_CACHE(re, &s->gb);
if(s->msmpeg4_version<=3){
last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);
level= SHOW_SBITS(re, &s->gb, 8); LAST_SKIP_CACHE(re, &s->gb, 8);
SKIP_COUNTER(re, &s->gb, 1+6+8);
}else{
int sign;
last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
if(!s->esc3_level_length){
int ll;
if(s->qscale<8){
ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);
if(ll==0){
if(SHOW_UBITS(re, &s->gb, 1)) av_log(s->avctx, AV_LOG_ERROR, "cool a new vlc code ,contact the ffmpeg developers and upload the file\n");
SKIP_BITS(re, &s->gb, 1);
ll=8;
}
}else{
ll=2;
while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){
ll++;
SKIP_BITS(re, &s->gb, 1);
}
if(ll<8) SKIP_BITS(re, &s->gb, 1);
}
s->esc3_level_length= ll;
s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
UPDATE_CACHE(re, &s->gb);
}
run= SHOW_UBITS(re, &s->gb, s->esc3_run_length);
SKIP_BITS(re, &s->gb, s->esc3_run_length);
sign= SHOW_UBITS(re, &s->gb, 1);
SKIP_BITS(re, &s->gb, 1);
level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);
SKIP_BITS(re, &s->gb, s->esc3_level_length);
if(sign) level= -level;
}
#if 0
{
const int abs_level= FFABS(level);
const int run1= run - rl->max_run[last][abs_level] - run_diff;
if(abs_level<=MAX_LEVEL && run<=MAX_RUN){
if(abs_level <= rl->max_level[last][run]){
av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
return DECODING_AC_LOST;
}
if(abs_level <= rl->max_level[last][run]*2){
av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
return DECODING_AC_LOST;
}
if(run1>=0 && abs_level <= rl->max_level[last][run1]){
av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
return DECODING_AC_LOST;
}
}
}
#endif
if (level>0) level= level * qmul + qadd;
else level= level * qmul - qadd;
#if 0
if(level>2048 || level<-2048){
av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc\n");
return DECODING_AC_LOST;
}
#endif
i+= run + 1;
if(last) i+=192;
#ifdef ERROR_DETAILS
if(run==66)
av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 level=%d\n", level);
else if((i>62 && i<192) || i>192+63)
av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC3 i=%d run=%d level=%d\n", i, run, level);
#endif
} else {
#if MIN_CACHE_BITS < 23
LAST_SKIP_BITS(re, &s->gb, 2);
UPDATE_CACHE(re, &s->gb);
#else
SKIP_BITS(re, &s->gb, 2);
#endif
GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
i+= run + rl->max_run[run>>7][level/qmul] + run_diff;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
LAST_SKIP_BITS(re, &s->gb, 1);
#ifdef ERROR_DETAILS
if(run==66)
av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 level=%d\n", level);
else if((i>62 && i<192) || i>192+63)
av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC2 i=%d run=%d level=%d\n", i, run, level);
#endif
}
} else {
#if MIN_CACHE_BITS < 22
LAST_SKIP_BITS(re, &s->gb, 1);
UPDATE_CACHE(re, &s->gb);
#else
SKIP_BITS(re, &s->gb, 1);
#endif
GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
i+= run;
level = level + rl->max_level[run>>7][(run-1)&63] * qmul;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
LAST_SKIP_BITS(re, &s->gb, 1);
#ifdef ERROR_DETAILS
if(run==66)
av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 level=%d\n", level);
else if((i>62 && i<192) || i>192+63)
av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC1 i=%d run=%d level=%d\n", i, run, level);
#endif
}
} else {
i+= run;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
LAST_SKIP_BITS(re, &s->gb, 1);
#ifdef ERROR_DETAILS
if(run==66)
av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code level=%d\n", level);
else if((i>62 && i<192) || i>192+63)
av_log(s->avctx, AV_LOG_ERROR, "run overflow i=%d run=%d level=%d\n", i, run, level);
#endif
}
if (i > 62){
i-= 192;
if(i&(~63)){
const int left= s->gb.size_in_bits - get_bits_count(&s->gb);
if(((i+192 == 64 && level/qmul==-1) || s->error_recognition<=1) && left>=0){
av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
break;
}else{
av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
}
block[scan_table[i]] = level;
break;
}
block[scan_table[i]] = level;
}
CLOSE_READER(re, &s->gb);
}
not_coded:
if (s->mb_intra) {
mpeg4_pred_ac(s, block, n, dc_pred_dir);
if (s->ac_pred) {
i = 63;
}
}
if(s->msmpeg4_version>=4 && i>0) i=63;
s->block_last_index[n] = i;
return 0;
} | ['int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,\n int n, int coded, const uint8_t *scan_table)\n{\n int level, i, last, run, run_diff;\n int av_uninit(dc_pred_dir);\n RLTable *rl;\n RL_VLC_ELEM *rl_vlc;\n int qmul, qadd;\n if (s->mb_intra) {\n qmul=1;\n qadd=0;\n level = msmpeg4_decode_dc(s, n, &dc_pred_dir);\n if (level < 0){\n av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\\n", n, s->qscale);\n if(s->inter_intra_pred) level=0;\n else return -1;\n }\n if (n < 4) {\n rl = &rl_table[s->rl_table_index];\n if(level > 256*s->y_dc_scale){\n av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\\n", s->qscale);\n if(!s->inter_intra_pred) return -1;\n }\n } else {\n rl = &rl_table[3 + s->rl_chroma_table_index];\n if(level > 256*s->c_dc_scale){\n av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\\n", s->qscale);\n if(!s->inter_intra_pred) return -1;\n }\n }\n block[0] = level;\n run_diff = s->msmpeg4_version >= 4;\n i = 0;\n if (!coded) {\n goto not_coded;\n }\n if (s->ac_pred) {\n if (dc_pred_dir == 0)\n scan_table = s->intra_v_scantable.permutated;\n else\n scan_table = s->intra_h_scantable.permutated;\n } else {\n scan_table = s->intra_scantable.permutated;\n }\n rl_vlc= rl->rl_vlc[0];\n } else {\n qmul = s->qscale << 1;\n qadd = (s->qscale - 1) | 1;\n i = -1;\n rl = &rl_table[3 + s->rl_table_index];\n if(s->msmpeg4_version==2)\n run_diff = 0;\n else\n run_diff = 1;\n if (!coded) {\n s->block_last_index[n] = i;\n return 0;\n }\n if(!scan_table)\n scan_table = s->inter_scantable.permutated;\n rl_vlc= rl->rl_vlc[s->qscale];\n }\n {\n OPEN_READER(re, &s->gb);\n for(;;) {\n UPDATE_CACHE(re, &s->gb);\n GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);\n if (level==0) {\n int cache;\n cache= GET_CACHE(re, &s->gb);\n if (s->msmpeg4_version==1 || (cache&0x80000000)==0) {\n if (s->msmpeg4_version==1 || (cache&0x40000000)==0) {\n if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2);\n UPDATE_CACHE(re, &s->gb);\n if(s->msmpeg4_version<=3){\n last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);\n run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);\n level= SHOW_SBITS(re, &s->gb, 8); LAST_SKIP_CACHE(re, &s->gb, 8);\n SKIP_COUNTER(re, &s->gb, 1+6+8);\n }else{\n int sign;\n last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);\n if(!s->esc3_level_length){\n int ll;\n if(s->qscale<8){\n ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);\n if(ll==0){\n if(SHOW_UBITS(re, &s->gb, 1)) av_log(s->avctx, AV_LOG_ERROR, "cool a new vlc code ,contact the ffmpeg developers and upload the file\\n");\n SKIP_BITS(re, &s->gb, 1);\n ll=8;\n }\n }else{\n ll=2;\n while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){\n ll++;\n SKIP_BITS(re, &s->gb, 1);\n }\n if(ll<8) SKIP_BITS(re, &s->gb, 1);\n }\n s->esc3_level_length= ll;\n s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);\n UPDATE_CACHE(re, &s->gb);\n }\n run= SHOW_UBITS(re, &s->gb, s->esc3_run_length);\n SKIP_BITS(re, &s->gb, s->esc3_run_length);\n sign= SHOW_UBITS(re, &s->gb, 1);\n SKIP_BITS(re, &s->gb, 1);\n level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);\n SKIP_BITS(re, &s->gb, s->esc3_level_length);\n if(sign) level= -level;\n }\n#if 0\n {\n const int abs_level= FFABS(level);\n const int run1= run - rl->max_run[last][abs_level] - run_diff;\n if(abs_level<=MAX_LEVEL && run<=MAX_RUN){\n if(abs_level <= rl->max_level[last][run]){\n av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\\n");\n return DECODING_AC_LOST;\n }\n if(abs_level <= rl->max_level[last][run]*2){\n av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\\n");\n return DECODING_AC_LOST;\n }\n if(run1>=0 && abs_level <= rl->max_level[last][run1]){\n av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\\n");\n return DECODING_AC_LOST;\n }\n }\n }\n#endif\n if (level>0) level= level * qmul + qadd;\n else level= level * qmul - qadd;\n#if 0\n if(level>2048 || level<-2048){\n av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc\\n");\n return DECODING_AC_LOST;\n }\n#endif\n i+= run + 1;\n if(last) i+=192;\n#ifdef ERROR_DETAILS\n if(run==66)\n av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 level=%d\\n", level);\n else if((i>62 && i<192) || i>192+63)\n av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC3 i=%d run=%d level=%d\\n", i, run, level);\n#endif\n } else {\n#if MIN_CACHE_BITS < 23\n LAST_SKIP_BITS(re, &s->gb, 2);\n UPDATE_CACHE(re, &s->gb);\n#else\n SKIP_BITS(re, &s->gb, 2);\n#endif\n GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);\n i+= run + rl->max_run[run>>7][level/qmul] + run_diff;\n level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);\n LAST_SKIP_BITS(re, &s->gb, 1);\n#ifdef ERROR_DETAILS\n if(run==66)\n av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 level=%d\\n", level);\n else if((i>62 && i<192) || i>192+63)\n av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC2 i=%d run=%d level=%d\\n", i, run, level);\n#endif\n }\n } else {\n#if MIN_CACHE_BITS < 22\n LAST_SKIP_BITS(re, &s->gb, 1);\n UPDATE_CACHE(re, &s->gb);\n#else\n SKIP_BITS(re, &s->gb, 1);\n#endif\n GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);\n i+= run;\n level = level + rl->max_level[run>>7][(run-1)&63] * qmul;\n level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);\n LAST_SKIP_BITS(re, &s->gb, 1);\n#ifdef ERROR_DETAILS\n if(run==66)\n av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 level=%d\\n", level);\n else if((i>62 && i<192) || i>192+63)\n av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC1 i=%d run=%d level=%d\\n", i, run, level);\n#endif\n }\n } else {\n i+= run;\n level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);\n LAST_SKIP_BITS(re, &s->gb, 1);\n#ifdef ERROR_DETAILS\n if(run==66)\n av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code level=%d\\n", level);\n else if((i>62 && i<192) || i>192+63)\n av_log(s->avctx, AV_LOG_ERROR, "run overflow i=%d run=%d level=%d\\n", i, run, level);\n#endif\n }\n if (i > 62){\n i-= 192;\n if(i&(~63)){\n const int left= s->gb.size_in_bits - get_bits_count(&s->gb);\n if(((i+192 == 64 && level/qmul==-1) || s->error_recognition<=1) && left>=0){\n av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\\n", s->mb_x, s->mb_y);\n break;\n }else{\n av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\\n", s->mb_x, s->mb_y);\n return -1;\n }\n }\n block[scan_table[i]] = level;\n break;\n }\n block[scan_table[i]] = level;\n }\n CLOSE_READER(re, &s->gb);\n }\n not_coded:\n if (s->mb_intra) {\n mpeg4_pred_ac(s, block, n, dc_pred_dir);\n if (s->ac_pred) {\n i = 63;\n }\n }\n if(s->msmpeg4_version>=4 && i>0) i=63;\n s->block_last_index[n] = i;\n return 0;\n}'] |
34,329 | 0 | https://github.com/libav/libav/blob/4d4d7cf9d539a053f531f662a972b23d335738eb/libavcodec/fmvc.c/#L152 | static int decode_type2(GetByteContext *gb, PutByteContext *pb)
{
unsigned repeat = 0, first = 1, opcode;
int i, len, pos;
while (bytestream2_get_bytes_left(gb) > 0) {
GetByteContext gbc;
while (bytestream2_get_bytes_left(gb) > 0) {
if (first) {
first = 0;
if (bytestream2_peek_byte(gb) > 17) {
len = bytestream2_get_byte(gb) - 17;
if (len < 4) {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
continue;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
if (opcode < 0x10) {
bytestream2_skip(gb, 1);
pos = - (opcode >> 2) - 4 * bytestream2_get_byte(gb) - 2049;
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
len = opcode & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
continue;
}
}
repeat = 0;
}
repeat = 1;
}
if (repeat) {
repeat = 0;
opcode = bytestream2_peek_byte(gb);
if (opcode < 0x10) {
bytestream2_skip(gb, 1);
if (!opcode) {
if (!bytestream2_peek_byte(gb)) {
do {
bytestream2_skip(gb, 1);
opcode += 255;
} while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);
}
opcode += bytestream2_get_byte(gb) + 15;
}
bytestream2_put_le32(pb, bytestream2_get_le32(gb));
for (i = opcode - 1; i > 0; --i)
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
opcode = bytestream2_peek_byte(gb);
if (opcode < 0x10) {
bytestream2_skip(gb, 1);
pos = - (opcode >> 2) - 4 * bytestream2_get_byte(gb) - 2049;
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
len = opcode & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
continue;
}
}
}
if (opcode >= 0x40) {
bytestream2_skip(gb, 1);
pos = - ((opcode >> 2) & 7) - 1 - 8 * bytestream2_get_byte(gb);
len = (opcode >> 5) - 1;
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
do {
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
--len;
} while (len);
len = opcode & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
continue;
} else if (opcode < 0x20) {
break;
}
len = opcode & 0x1F;
bytestream2_skip(gb, 1);
if (!len) {
if (!bytestream2_peek_byte(gb)) {
do {
bytestream2_skip(gb, 1);
len += 255;
} while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);
}
len += bytestream2_get_byte(gb) + 31;
}
i = bytestream2_get_le16(gb);
pos = - (i >> 2) - 1;
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);
if (len < 6 || bytestream2_tell_p(pb) - bytestream2_tell(&gbc) < 4) {
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
do {
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
--len;
} while (len);
} else {
bytestream2_put_le32(pb, bytestream2_get_le32(&gbc));
for (len = len - 2; len; --len)
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
}
len = i & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
}
bytestream2_skip(gb, 1);
if (opcode < 0x10) {
pos = -(opcode >> 2) - 1 - 4 * bytestream2_get_byte(gb);
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
len = opcode & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
continue;
}
len = opcode & 7;
if (!len) {
if (!bytestream2_peek_byte(gb)) {
do {
bytestream2_skip(gb, 1);
len += 255;
} while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);
}
len += bytestream2_get_byte(gb) + 7;
}
i = bytestream2_get_le16(gb);
pos = bytestream2_tell_p(pb) - 2048 * (opcode & 8);
pos = pos - (i >> 2);
if (pos == bytestream2_tell_p(pb))
break;
pos = pos - 0x4000;
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, pos, SEEK_SET);
if (len < 6 || bytestream2_tell_p(pb) - bytestream2_tell(&gbc) < 4) {
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
do {
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
--len;
} while (len);
} else {
bytestream2_put_le32(pb, bytestream2_get_le32(&gbc));
for (len = len - 2; len; --len)
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
}
len = i & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
}
return 0;
} | ['static int decode_type2(GetByteContext *gb, PutByteContext *pb)\n{\n unsigned repeat = 0, first = 1, opcode;\n int i, len, pos;\n while (bytestream2_get_bytes_left(gb) > 0) {\n GetByteContext gbc;\n while (bytestream2_get_bytes_left(gb) > 0) {\n if (first) {\n first = 0;\n if (bytestream2_peek_byte(gb) > 17) {\n len = bytestream2_get_byte(gb) - 17;\n if (len < 4) {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n continue;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n if (opcode < 0x10) {\n bytestream2_skip(gb, 1);\n pos = - (opcode >> 2) - 4 * bytestream2_get_byte(gb) - 2049;\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n len = opcode & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n continue;\n }\n }\n repeat = 0;\n }\n repeat = 1;\n }\n if (repeat) {\n repeat = 0;\n opcode = bytestream2_peek_byte(gb);\n if (opcode < 0x10) {\n bytestream2_skip(gb, 1);\n if (!opcode) {\n if (!bytestream2_peek_byte(gb)) {\n do {\n bytestream2_skip(gb, 1);\n opcode += 255;\n } while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);\n }\n opcode += bytestream2_get_byte(gb) + 15;\n }\n bytestream2_put_le32(pb, bytestream2_get_le32(gb));\n for (i = opcode - 1; i > 0; --i)\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n opcode = bytestream2_peek_byte(gb);\n if (opcode < 0x10) {\n bytestream2_skip(gb, 1);\n pos = - (opcode >> 2) - 4 * bytestream2_get_byte(gb) - 2049;\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n len = opcode & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n continue;\n }\n }\n }\n if (opcode >= 0x40) {\n bytestream2_skip(gb, 1);\n pos = - ((opcode >> 2) & 7) - 1 - 8 * bytestream2_get_byte(gb);\n len = (opcode >> 5) - 1;\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n --len;\n } while (len);\n len = opcode & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n continue;\n } else if (opcode < 0x20) {\n break;\n }\n len = opcode & 0x1F;\n bytestream2_skip(gb, 1);\n if (!len) {\n if (!bytestream2_peek_byte(gb)) {\n do {\n bytestream2_skip(gb, 1);\n len += 255;\n } while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);\n }\n len += bytestream2_get_byte(gb) + 31;\n }\n i = bytestream2_get_le16(gb);\n pos = - (i >> 2) - 1;\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);\n if (len < 6 || bytestream2_tell_p(pb) - bytestream2_tell(&gbc) < 4) {\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n --len;\n } while (len);\n } else {\n bytestream2_put_le32(pb, bytestream2_get_le32(&gbc));\n for (len = len - 2; len; --len)\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n }\n len = i & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n }\n bytestream2_skip(gb, 1);\n if (opcode < 0x10) {\n pos = -(opcode >> 2) - 1 - 4 * bytestream2_get_byte(gb);\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n len = opcode & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n continue;\n }\n len = opcode & 7;\n if (!len) {\n if (!bytestream2_peek_byte(gb)) {\n do {\n bytestream2_skip(gb, 1);\n len += 255;\n } while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);\n }\n len += bytestream2_get_byte(gb) + 7;\n }\n i = bytestream2_get_le16(gb);\n pos = bytestream2_tell_p(pb) - 2048 * (opcode & 8);\n pos = pos - (i >> 2);\n if (pos == bytestream2_tell_p(pb))\n break;\n pos = pos - 0x4000;\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, pos, SEEK_SET);\n if (len < 6 || bytestream2_tell_p(pb) - bytestream2_tell(&gbc) < 4) {\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n --len;\n } while (len);\n } else {\n bytestream2_put_le32(pb, bytestream2_get_le32(&gbc));\n for (len = len - 2; len; --len)\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n }\n len = i & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n }\n return 0;\n}', 'DEF(unsigned int, byte, 1, AV_RB8 , AV_WB8)'] |
34,330 | 0 | https://github.com/libav/libav/blob/77b0443544fd5f5c3f974b7a4fa4f2f18f7ba8df/ffmpeg.c/#L3694 | static void opt_vstats (void)
{
char filename[40];
time_t today2 = time(NULL);
struct tm *today = localtime(&today2);
snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
today->tm_sec);
opt_vstats_file(filename);
} | ['static void opt_vstats (void)\n{\n char filename[40];\n time_t today2 = time(NULL);\n struct tm *today = localtime(&today2);\n snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,\n today->tm_sec);\n opt_vstats_file(filename);\n}'] |
34,331 | 0 | https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/crypto/x509v3/v3_skey.c/#L149 | static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
X509V3_CTX *ctx, char *str)
{
ASN1_OCTET_STRING *oct;
ASN1_BIT_STRING *pk;
unsigned char pkey_dig[EVP_MAX_MD_SIZE];
unsigned int diglen;
if (strcmp(str, "hash"))
return s2i_ASN1_OCTET_STRING(method, ctx, str);
if ((oct = ASN1_OCTET_STRING_new()) == NULL) {
X509V3err(X509V3_F_S2I_SKEY_ID, ERR_R_MALLOC_FAILURE);
return NULL;
}
if (ctx && (ctx->flags == CTX_TEST))
return oct;
if (!ctx || (!ctx->subject_req && !ctx->subject_cert)) {
X509V3err(X509V3_F_S2I_SKEY_ID, X509V3_R_NO_PUBLIC_KEY);
goto err;
}
if (ctx->subject_req)
pk = ctx->subject_req->req_info.pubkey->public_key;
else
pk = ctx->subject_cert->cert_info.key->public_key;
if (!pk) {
X509V3err(X509V3_F_S2I_SKEY_ID, X509V3_R_NO_PUBLIC_KEY);
goto err;
}
if (!EVP_Digest
(pk->data, pk->length, pkey_dig, &diglen, EVP_sha1(), NULL))
goto err;
if (!ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {
X509V3err(X509V3_F_S2I_SKEY_ID, ERR_R_MALLOC_FAILURE);
goto err;
}
return oct;
err:
ASN1_OCTET_STRING_free(oct);
return NULL;
} | ['static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,\n X509V3_CTX *ctx, char *str)\n{\n ASN1_OCTET_STRING *oct;\n ASN1_BIT_STRING *pk;\n unsigned char pkey_dig[EVP_MAX_MD_SIZE];\n unsigned int diglen;\n if (strcmp(str, "hash"))\n return s2i_ASN1_OCTET_STRING(method, ctx, str);\n if ((oct = ASN1_OCTET_STRING_new()) == NULL) {\n X509V3err(X509V3_F_S2I_SKEY_ID, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n if (ctx && (ctx->flags == CTX_TEST))\n return oct;\n if (!ctx || (!ctx->subject_req && !ctx->subject_cert)) {\n X509V3err(X509V3_F_S2I_SKEY_ID, X509V3_R_NO_PUBLIC_KEY);\n goto err;\n }\n if (ctx->subject_req)\n pk = ctx->subject_req->req_info.pubkey->public_key;\n else\n pk = ctx->subject_cert->cert_info.key->public_key;\n if (!pk) {\n X509V3err(X509V3_F_S2I_SKEY_ID, X509V3_R_NO_PUBLIC_KEY);\n goto err;\n }\n if (!EVP_Digest\n (pk->data, pk->length, pkey_dig, &diglen, EVP_sha1(), NULL))\n goto err;\n if (!ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {\n X509V3err(X509V3_F_S2I_SKEY_ID, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n return oct;\n err:\n ASN1_OCTET_STRING_free(oct);\n return NULL;\n}', 'IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)', 'ASN1_STRING *ASN1_STRING_type_new(int type)\n{\n ASN1_STRING *ret;\n ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->type = type;\n return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'const EVP_MD *EVP_sha1(void)\n{\n return (&sha1_md);\n}', 'int EVP_Digest(const void *data, size_t count,\n unsigned char *md, unsigned int *size, const EVP_MD *type,\n ENGINE *impl)\n{\n EVP_MD_CTX *ctx = EVP_MD_CTX_new();\n int ret;\n if (ctx == NULL)\n return 0;\n EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT);\n ret = EVP_DigestInit_ex(ctx, type, impl)\n && EVP_DigestUpdate(ctx, data, count)\n && EVP_DigestFinal_ex(ctx, md, size);\n EVP_MD_CTX_free(ctx);\n return ret;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void ASN1_STRING_free(ASN1_STRING *a)\n{\n if (a == NULL)\n return;\n if (!(a->flags & ASN1_STRING_FLAG_NDEF))\n OPENSSL_free(a->data);\n if (!(a->flags & ASN1_STRING_FLAG_EMBED))\n OPENSSL_free(a);\n}'] |
34,332 | 1 | https://github.com/openssl/openssl/blob/b79aa47a0c8478bea62fc2bb55f99e0be172da3d/crypto/rand/rand_egd.c/#L148 | int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)
{
int ret = 0;
struct sockaddr_un addr;
int len, num, numbytes;
int fd = -1;
int success;
unsigned char egdbuf[2], tempbuf[255], *retrievebuf;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
if (strlen(path) >= sizeof(addr.sun_path))
return (-1);
strcpy(addr.sun_path,path);
len = offsetof(struct sockaddr_un, sun_path) + strlen(path);
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1) return (-1);
success = 0;
while (!success)
{
if (connect(fd, (struct sockaddr *)&addr, len) == 0)
success = 1;
else
{
switch (errno)
{
#ifdef EINTR
case EINTR:
#endif
#ifdef EAGAIN
case EAGAIN:
#endif
#ifdef EINPROGRESS
case EINPROGRESS:
#endif
#ifdef EALREADY
case EALREADY:
#endif
break;
#ifdef EISCONN
case EISCONN:
success = 1;
break;
#endif
default:
goto err;
}
}
}
while(bytes > 0)
{
egdbuf[0] = 1;
egdbuf[1] = bytes < 255 ? bytes : 255;
numbytes = 0;
while (numbytes != 2)
{
num = write(fd, egdbuf + numbytes, 2 - numbytes);
if (num >= 0)
numbytes += num;
else
{
switch (errno)
{
#ifdef EINTR
case EINTR:
#endif
#ifdef EAGAIN
case EAGAIN:
#endif
break;
default:
ret = -1;
goto err;
}
}
}
numbytes = 0;
while (numbytes != 1)
{
num = read(fd, egdbuf, 1);
if (num >= 0)
numbytes += num;
else
{
switch (errno)
{
#ifdef EINTR
case EINTR:
#endif
#ifdef EAGAIN
case EAGAIN:
#endif
break;
default:
ret = -1;
goto err;
}
}
}
if(egdbuf[0] == 0)
goto err;
if (buf)
retrievebuf = buf + ret;
else
retrievebuf = tempbuf;
numbytes = 0;
while (numbytes != egdbuf[0])
{
num = read(fd, retrievebuf + numbytes, egdbuf[0] - numbytes);
if (num >= 0)
numbytes += num;
else
{
switch (errno)
{
#ifdef EINTR
case EINTR:
#endif
#ifdef EAGAIN
case EAGAIN:
#endif
break;
default:
ret = -1;
goto err;
}
}
}
ret += egdbuf[0];
bytes -= egdbuf[0];
if (!buf)
RAND_seed(tempbuf, egdbuf[0]);
}
err:
if (fd != -1) close(fd);
return(ret);
} | ['int RAND_poll(void)\n{\n\tunsigned long l;\n\tpid_t curr_pid = getpid();\n#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)\n\tunsigned char tmpbuf[ENTROPY_NEEDED];\n\tint n = 0;\n#endif\n#ifdef DEVRANDOM\n\tstatic const char *randomfiles[] = { DEVRANDOM, NULL };\n\tconst char **randomfile = NULL;\n\tint fd;\n#endif\n#ifdef DEVRANDOM_EGD\n\tstatic const char *egdsockets[] = { DEVRANDOM_EGD, NULL };\n\tconst char **egdsocket = NULL;\n#endif\n#ifdef DEVRANDOM\n\tfor (randomfile = randomfiles; *randomfile && n < ENTROPY_NEEDED; randomfile++)\n\t\t{\n\t\tif ((fd = open(*randomfile, O_RDONLY|O_NONBLOCK\n#ifdef O_NOCTTY\n\t\t\t|O_NOCTTY\n#endif\n#ifdef O_NOFOLLOW\n\t\t\t|O_NOFOLLOW\n#endif\n\t\t\t)) >= 0)\n\t\t\t{\n\t\t\tstruct timeval t = { 0, 10*1000 };\n\t\t\tint r;\n\t\t\tfd_set fset;\n\t\t\tdo\n\t\t\t\t{\n\t\t\t\tFD_ZERO(&fset);\n\t\t\t\tFD_SET(fd, &fset);\n\t\t\t\tr = -1;\n\t\t\t\tif (select(fd+1,&fset,NULL,NULL,&t) < 0)\n\t\t\t\t\tt.tv_usec=0;\n\t\t\t\telse if (FD_ISSET(fd, &fset))\n\t\t\t\t\t{\n\t\t\t\t\tr=read(fd,(unsigned char *)tmpbuf+n,\n\t\t\t\t\t ENTROPY_NEEDED-n);\n\t\t\t\t\tif (r > 0)\n\t\t\t\t\t\tn += r;\n\t\t\t\t\t}\n\t\t\t\tif (t.tv_usec == 10*1000)\n\t\t\t\t\tt.tv_usec=0;\n\t\t\t\t}\n\t\t\twhile ((r > 0 || (errno == EINTR || errno == EAGAIN))\n\t\t\t\t&& t.tv_usec != 0 && n < ENTROPY_NEEDED);\n\t\t\tclose(fd);\n\t\t\t}\n\t\t}\n#endif\n#ifdef DEVRANDOM_EGD\n\tfor (egdsocket = egdsockets; *egdsocket && n < ENTROPY_NEEDED; egdsocket++)\n\t\t{\n\t\tint r;\n\t\tr = RAND_query_egd_bytes(*egdsocket, (unsigned char *)tmpbuf+n,\n\t\t\t\t\t ENTROPY_NEEDED-n);\n\t\tif (r > 0)\n\t\t\tn += r;\n\t\t}\n#endif\n#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)\n\tif (n > 0)\n\t\t{\n\t\tRAND_add(tmpbuf,sizeof tmpbuf,n);\n\t\tOPENSSL_cleanse(tmpbuf,n);\n\t\t}\n#endif\n\tl=curr_pid;\n\tRAND_add(&l,sizeof(l),0);\n\tl=getuid();\n\tRAND_add(&l,sizeof(l),0);\n\tl=time(NULL);\n\tRAND_add(&l,sizeof(l),0);\n#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)\n\treturn 1;\n#else\n\treturn 0;\n#endif\n}', 'int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)\n\t{\n\tint ret = 0;\n\tstruct sockaddr_un addr;\n\tint len, num, numbytes;\n\tint fd = -1;\n\tint success;\n\tunsigned char egdbuf[2], tempbuf[255], *retrievebuf;\n\tmemset(&addr, 0, sizeof(addr));\n\taddr.sun_family = AF_UNIX;\n\tif (strlen(path) >= sizeof(addr.sun_path))\n\t\treturn (-1);\n\tstrcpy(addr.sun_path,path);\n\tlen = offsetof(struct sockaddr_un, sun_path) + strlen(path);\n\tfd = socket(AF_UNIX, SOCK_STREAM, 0);\n\tif (fd == -1) return (-1);\n\tsuccess = 0;\n\twhile (!success)\n\t {\n\t if (connect(fd, (struct sockaddr *)&addr, len) == 0)\n\t success = 1;\n\t else\n\t\t{\n\t\tswitch (errno)\n\t\t {\n#ifdef EINTR\n\t\t case EINTR:\n#endif\n#ifdef EAGAIN\n\t\t case EAGAIN:\n#endif\n#ifdef EINPROGRESS\n\t\t case EINPROGRESS:\n#endif\n#ifdef EALREADY\n\t\t case EALREADY:\n#endif\n\t\t\tbreak;\n#ifdef EISCONN\n\t\t case EISCONN:\n\t\t\tsuccess = 1;\n\t\t\tbreak;\n#endif\n\t\t default:\n\t\t\tgoto err;\n\t\t }\n\t\t}\n\t }\n\twhile(bytes > 0)\n\t {\n\t egdbuf[0] = 1;\n\t egdbuf[1] = bytes < 255 ? bytes : 255;\n\t numbytes = 0;\n\t while (numbytes != 2)\n\t\t{\n\t num = write(fd, egdbuf + numbytes, 2 - numbytes);\n\t if (num >= 0)\n\t\t numbytes += num;\n\t \telse\n\t\t {\n\t\t switch (errno)\n\t\t \t{\n#ifdef EINTR\n\t\t \tcase EINTR:\n#endif\n#ifdef EAGAIN\n\t\t \tcase EAGAIN:\n#endif\n\t\t\t break;\n\t\t \tdefault:\n\t\t\t ret = -1;\n\t\t\t goto err;\n\t\t\t}\n\t\t }\n\t\t}\n\t numbytes = 0;\n\t while (numbytes != 1)\n\t\t{\n\t num = read(fd, egdbuf, 1);\n\t if (num >= 0)\n\t\t numbytes += num;\n\t \telse\n\t\t {\n\t\t switch (errno)\n\t\t \t{\n#ifdef EINTR\n\t\t \tcase EINTR:\n#endif\n#ifdef EAGAIN\n\t\t \tcase EAGAIN:\n#endif\n\t\t\t break;\n\t\t \tdefault:\n\t\t\t ret = -1;\n\t\t\t goto err;\n\t\t\t}\n\t\t }\n\t\t}\n\t if(egdbuf[0] == 0)\n\t\tgoto err;\n\t if (buf)\n\t\tretrievebuf = buf + ret;\n\t else\n\t\tretrievebuf = tempbuf;\n\t numbytes = 0;\n\t while (numbytes != egdbuf[0])\n\t\t{\n\t num = read(fd, retrievebuf + numbytes, egdbuf[0] - numbytes);\n\t if (num >= 0)\n\t\t numbytes += num;\n\t \telse\n\t\t {\n\t\t switch (errno)\n\t\t \t{\n#ifdef EINTR\n\t\t \tcase EINTR:\n#endif\n#ifdef EAGAIN\n\t\t \tcase EAGAIN:\n#endif\n\t\t\t break;\n\t\t \tdefault:\n\t\t\t ret = -1;\n\t\t\t goto err;\n\t\t\t}\n\t\t }\n\t\t}\n\t ret += egdbuf[0];\n\t bytes -= egdbuf[0];\n\t if (!buf)\n\t\tRAND_seed(tempbuf, egdbuf[0]);\n\t }\n err:\n\tif (fd != -1) close(fd);\n\treturn(ret);\n\t}'] |
34,333 | 0 | https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/md5/md5_dgst.c/#L133 | void MD5_Update(MD5_CTX *c, const void *_data, unsigned long len)
{
register const unsigned char *data=_data;
register ULONG *p;
int sw,sc;
ULONG l;
if (len == 0) return;
l=(c->Nl+(len<<3))&0xffffffffL;
if (l < c->Nl)
c->Nh++;
c->Nh+=(len>>29);
c->Nl=l;
if (c->num != 0)
{
p=c->data;
sw=c->num>>2;
sc=c->num&0x03;
if ((c->num+len) >= MD5_CBLOCK)
{
l= p[sw];
p_c2l(data,l,sc);
p[sw++]=l;
for (; sw<MD5_LBLOCK; sw++)
{
c2l(data,l);
p[sw]=l;
}
len-=(MD5_CBLOCK-c->num);
md5_block(c,p,64);
c->num=0;
}
else
{
int ew,ec;
c->num+=(int)len;
if ((sc+len) < 4)
{
l= p[sw];
p_c2l_p(data,l,sc,len);
p[sw]=l;
}
else
{
ew=(c->num>>2);
ec=(c->num&0x03);
l= p[sw];
p_c2l(data,l,sc);
p[sw++]=l;
for (; sw < ew; sw++)
{ c2l(data,l); p[sw]=l; }
if (ec)
{
c2l_p(data,l,ec);
p[sw]=l;
}
}
return;
}
}
#ifdef L_ENDIAN
if ((((unsigned long)data)%sizeof(ULONG)) == 0)
{
sw=(int)len/MD5_CBLOCK;
if (sw > 0)
{
sw*=MD5_CBLOCK;
md5_block(c,(ULONG *)data,sw);
data+=sw;
len-=sw;
}
}
#endif
p=c->data;
while (len >= MD5_CBLOCK)
{
#if defined(L_ENDIAN) || defined(B_ENDIAN)
if (p != (unsigned long *)data)
memcpy(p,data,MD5_CBLOCK);
data+=MD5_CBLOCK;
#ifdef B_ENDIAN
for (sw=(MD5_LBLOCK/4); sw; sw--)
{
Endian_Reverse32(p[0]);
Endian_Reverse32(p[1]);
Endian_Reverse32(p[2]);
Endian_Reverse32(p[3]);
p+=4;
}
#endif
#else
for (sw=(MD5_LBLOCK/4); sw; sw--)
{
c2l(data,l); *(p++)=l;
c2l(data,l); *(p++)=l;
c2l(data,l); *(p++)=l;
c2l(data,l); *(p++)=l;
}
#endif
p=c->data;
md5_block(c,p,64);
len-=MD5_CBLOCK;
}
sc=(int)len;
c->num=sc;
if (sc)
{
sw=sc>>2;
#ifdef L_ENDIAN
p[sw]=0;
memcpy(p,data,sc);
#else
sc&=0x03;
for ( ; sw; sw--)
{ c2l(data,l); *(p++)=l; }
c2l_p(data,l,sc);
*p=l;
#endif
}
} | ['int ssl3_change_cipher_state(SSL *s, int which)\n\t{\n\tunsigned char *p,*key_block,*mac_secret;\n\tunsigned char exp_key[EVP_MAX_KEY_LENGTH];\n\tunsigned char exp_iv[EVP_MAX_KEY_LENGTH];\n\tunsigned char *ms,*key,*iv,*er1,*er2;\n\tEVP_CIPHER_CTX *dd;\n\tconst EVP_CIPHER *c;\n\tCOMP_METHOD *comp;\n\tconst EVP_MD *m;\n\tMD5_CTX md;\n\tint exp,n,i,j,k,cl;\n\texp=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);\n\tc=s->s3->tmp.new_sym_enc;\n\tm=s->s3->tmp.new_hash;\n\tif (s->s3->tmp.new_compression == NULL)\n\t\tcomp=NULL;\n\telse\n\t\tcomp=s->s3->tmp.new_compression->method;\n\tkey_block=s->s3->tmp.key_block;\n\tif (which & SSL3_CC_READ)\n\t\t{\n\t\tif ((s->enc_read_ctx == NULL) &&\n\t\t\t((s->enc_read_ctx=(EVP_CIPHER_CTX *)\n\t\t\tMalloc(sizeof(EVP_CIPHER_CTX))) == NULL))\n\t\t\tgoto err;\n\t\tdd= s->enc_read_ctx;\n\t\ts->read_hash=m;\n\t\tif (s->expand != NULL)\n\t\t\t{\n\t\t\tCOMP_CTX_free(s->expand);\n\t\t\ts->expand=NULL;\n\t\t\t}\n\t\tif (comp != NULL)\n\t\t\t{\n\t\t\ts->expand=COMP_CTX_new(comp);\n\t\t\tif (s->expand == NULL)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_CHANGE_CIPHER_STATE,SSL_R_COMPRESSION_LIBRARY_ERROR);\n\t\t\t\tgoto err2;\n\t\t\t\t}\n\t\t\tif (s->s3->rrec.comp == NULL)\n\t\t\t\ts->s3->rrec.comp=(unsigned char *)\n\t\t\t\t\tMalloc(SSL3_RT_MAX_PLAIN_LENGTH);\n\t\t\tif (s->s3->rrec.comp == NULL)\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tmemset(&(s->s3->read_sequence[0]),0,8);\n\t\tmac_secret= &(s->s3->read_mac_secret[0]);\n\t\t}\n\telse\n\t\t{\n\t\tif ((s->enc_write_ctx == NULL) &&\n\t\t\t((s->enc_write_ctx=(EVP_CIPHER_CTX *)\n\t\t\tMalloc(sizeof(EVP_CIPHER_CTX))) == NULL))\n\t\t\tgoto err;\n\t\tdd= s->enc_write_ctx;\n\t\ts->write_hash=m;\n\t\tif (s->compress != NULL)\n\t\t\t{\n\t\t\tCOMP_CTX_free(s->compress);\n\t\t\ts->compress=NULL;\n\t\t\t}\n\t\tif (comp != NULL)\n\t\t\t{\n\t\t\ts->compress=COMP_CTX_new(comp);\n\t\t\tif (s->compress == NULL)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_CHANGE_CIPHER_STATE,SSL_R_COMPRESSION_LIBRARY_ERROR);\n\t\t\t\tgoto err2;\n\t\t\t\t}\n\t\t\t}\n\t\tmemset(&(s->s3->write_sequence[0]),0,8);\n\t\tmac_secret= &(s->s3->write_mac_secret[0]);\n\t\t}\n\tEVP_CIPHER_CTX_init(dd);\n\tp=s->s3->tmp.key_block;\n\ti=EVP_MD_size(m);\n\tcl=EVP_CIPHER_key_length(c);\n\tj=exp ? (cl < SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher) ?\n\t\t cl : SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher)) : cl;\n\tk=EVP_CIPHER_iv_length(c);\n\tif (\t(which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) ||\n\t\t(which == SSL3_CHANGE_CIPHER_SERVER_READ))\n\t\t{\n\t\tms= &(p[ 0]); n=i+i;\n\t\tkey= &(p[ n]); n+=j+j;\n\t\tiv= &(p[ n]); n+=k+k;\n\t\ter1= &(s->s3->client_random[0]);\n\t\ter2= &(s->s3->server_random[0]);\n\t\t}\n\telse\n\t\t{\n\t\tn=i;\n\t\tms= &(p[ n]); n+=i+j;\n\t\tkey= &(p[ n]); n+=j+k;\n\t\tiv= &(p[ n]); n+=k;\n\t\ter1= &(s->s3->server_random[0]);\n\t\ter2= &(s->s3->client_random[0]);\n\t\t}\n\tif (n > s->s3->tmp.key_block_length)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHANGE_CIPHER_STATE,SSL_R_INTERNAL_ERROR);\n\t\tgoto err2;\n\t\t}\n\tmemcpy(mac_secret,ms,i);\n\tif (exp)\n\t\t{\n\t\tMD5_Init(&md);\n\t\tMD5_Update(&md,key,j);\n\t\tMD5_Update(&md,er1,SSL3_RANDOM_SIZE);\n\t\tMD5_Update(&md,er2,SSL3_RANDOM_SIZE);\n\t\tMD5_Final(&(exp_key[0]),&md);\n\t\tkey= &(exp_key[0]);\n\t\tif (k > 0)\n\t\t\t{\n\t\t\tMD5_Init(&md);\n\t\t\tMD5_Update(&md,er1,SSL3_RANDOM_SIZE);\n\t\t\tMD5_Update(&md,er2,SSL3_RANDOM_SIZE);\n\t\t\tMD5_Final(&(exp_iv[0]),&md);\n\t\t\tiv= &(exp_iv[0]);\n\t\t\t}\n\t\t}\n\ts->session->key_arg_length=0;\n\tEVP_CipherInit(dd,c,key,iv,(which & SSL3_CC_WRITE));\n\tmemset(&(exp_key[0]),0,sizeof(exp_key));\n\tmemset(&(exp_iv[0]),0,sizeof(exp_iv));\n\treturn(1);\nerr:\n\tSSLerr(SSL_F_SSL3_CHANGE_CIPHER_STATE,ERR_R_MALLOC_FAILURE);\nerr2:\n\treturn(0);\n\t}', 'void MD5_Init(MD5_CTX *c)\n\t{\n\tc->A=INIT_DATA_A;\n\tc->B=INIT_DATA_B;\n\tc->C=INIT_DATA_C;\n\tc->D=INIT_DATA_D;\n\tc->Nl=0;\n\tc->Nh=0;\n\tc->num=0;\n\t}', 'void MD5_Update(MD5_CTX *c, const void *_data, unsigned long len)\n\t{\n\tregister const unsigned char *data=_data;\n\tregister ULONG *p;\n\tint sw,sc;\n\tULONG l;\n\tif (len == 0) return;\n\tl=(c->Nl+(len<<3))&0xffffffffL;\n\tif (l < c->Nl)\n\t\tc->Nh++;\n\tc->Nh+=(len>>29);\n\tc->Nl=l;\n\tif (c->num != 0)\n\t\t{\n\t\tp=c->data;\n\t\tsw=c->num>>2;\n\t\tsc=c->num&0x03;\n\t\tif ((c->num+len) >= MD5_CBLOCK)\n\t\t\t{\n\t\t\tl= p[sw];\n\t\t\tp_c2l(data,l,sc);\n\t\t\tp[sw++]=l;\n\t\t\tfor (; sw<MD5_LBLOCK; sw++)\n\t\t\t\t{\n\t\t\t\tc2l(data,l);\n\t\t\t\tp[sw]=l;\n\t\t\t\t}\n\t\t\tlen-=(MD5_CBLOCK-c->num);\n\t\t\tmd5_block(c,p,64);\n\t\t\tc->num=0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tint ew,ec;\n\t\t\tc->num+=(int)len;\n\t\t\tif ((sc+len) < 4)\n\t\t\t\t{\n\t\t\t\tl= p[sw];\n\t\t\t\tp_c2l_p(data,l,sc,len);\n\t\t\t\tp[sw]=l;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tew=(c->num>>2);\n\t\t\t\tec=(c->num&0x03);\n\t\t\t\tl= p[sw];\n\t\t\t\tp_c2l(data,l,sc);\n\t\t\t\tp[sw++]=l;\n\t\t\t\tfor (; sw < ew; sw++)\n\t\t\t\t\t{ c2l(data,l); p[sw]=l; }\n\t\t\t\tif (ec)\n\t\t\t\t\t{\n\t\t\t\t\tc2l_p(data,l,ec);\n\t\t\t\t\tp[sw]=l;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\treturn;\n\t\t\t}\n\t\t}\n#ifdef L_ENDIAN\n\tif ((((unsigned long)data)%sizeof(ULONG)) == 0)\n\t\t{\n\t\tsw=(int)len/MD5_CBLOCK;\n\t\tif (sw > 0)\n\t\t\t{\n\t\t\tsw*=MD5_CBLOCK;\n\t\t\tmd5_block(c,(ULONG *)data,sw);\n\t\t\tdata+=sw;\n\t\t\tlen-=sw;\n\t\t\t}\n\t\t}\n#endif\n\tp=c->data;\n\twhile (len >= MD5_CBLOCK)\n\t\t{\n#if defined(L_ENDIAN) || defined(B_ENDIAN)\n\t\tif (p != (unsigned long *)data)\n\t\t\tmemcpy(p,data,MD5_CBLOCK);\n\t\tdata+=MD5_CBLOCK;\n#ifdef B_ENDIAN\n\t\tfor (sw=(MD5_LBLOCK/4); sw; sw--)\n\t\t\t{\n\t\t\tEndian_Reverse32(p[0]);\n\t\t\tEndian_Reverse32(p[1]);\n\t\t\tEndian_Reverse32(p[2]);\n\t\t\tEndian_Reverse32(p[3]);\n\t\t\tp+=4;\n\t\t\t}\n#endif\n#else\n\t\tfor (sw=(MD5_LBLOCK/4); sw; sw--)\n\t\t\t{\n\t\t\tc2l(data,l); *(p++)=l;\n\t\t\tc2l(data,l); *(p++)=l;\n\t\t\tc2l(data,l); *(p++)=l;\n\t\t\tc2l(data,l); *(p++)=l;\n\t\t\t}\n#endif\n\t\tp=c->data;\n\t\tmd5_block(c,p,64);\n\t\tlen-=MD5_CBLOCK;\n\t\t}\n\tsc=(int)len;\n\tc->num=sc;\n\tif (sc)\n\t\t{\n\t\tsw=sc>>2;\n#ifdef L_ENDIAN\n\t\tp[sw]=0;\n\t\tmemcpy(p,data,sc);\n#else\n\t\tsc&=0x03;\n\t\tfor ( ; sw; sw--)\n\t\t\t{ c2l(data,l); *(p++)=l; }\n\t\tc2l_p(data,l,sc);\n\t\t*p=l;\n#endif\n\t\t}\n\t}'] |
34,334 | 0 | https://github.com/libav/libav/blob/cbfe5bee2e20df90c581937b2cb4b1535acbf726/ffmpeg.c/#L3167 | static void new_audio_stream(AVFormatContext *oc)
{
AVStream *st;
AVCodecContext *audio_enc;
int codec_id;
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
av_exit(1);
}
avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO);
bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters;
audio_bitstream_filters= NULL;
if(thread_count>1)
avcodec_thread_init(st->codec, thread_count);
audio_enc = st->codec;
audio_enc->codec_type = CODEC_TYPE_AUDIO;
if(audio_codec_tag)
audio_enc->codec_tag= audio_codec_tag;
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
avcodec_opts[CODEC_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
}
if (audio_stream_copy) {
st->stream_copy = 1;
audio_enc->channels = audio_channels;
} else {
AVCodec *codec;
set_context_opts(audio_enc, avcodec_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
if (audio_codec_name) {
codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1);
codec = avcodec_find_encoder_by_name(audio_codec_name);
output_codecs[nb_ocodecs] = codec;
} else {
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);
codec = avcodec_find_encoder(codec_id);
}
audio_enc->codec_id = codec_id;
if (audio_qscale > QSCALE_NONE) {
audio_enc->flags |= CODEC_FLAG_QSCALE;
audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;
}
audio_enc->thread_count = thread_count;
audio_enc->channels = audio_channels;
audio_enc->sample_fmt = audio_sample_fmt;
audio_enc->channel_layout = channel_layout;
if (avcodec_channel_layout_num_channels(channel_layout) != audio_channels)
audio_enc->channel_layout = 0;
if(codec && codec->sample_fmts){
const enum SampleFormat *p= codec->sample_fmts;
for(; *p!=-1; p++){
if(*p == audio_enc->sample_fmt)
break;
}
if(*p == -1)
audio_enc->sample_fmt = codec->sample_fmts[0];
}
}
nb_ocodecs++;
audio_enc->sample_rate = audio_sample_rate;
audio_enc->time_base= (AVRational){1, audio_sample_rate};
if (audio_language) {
av_metadata_set(&st->metadata, "language", audio_language);
av_free(audio_language);
audio_language = NULL;
}
audio_disable = 0;
av_freep(&audio_codec_name);
audio_stream_copy = 0;
} | ['static void new_audio_stream(AVFormatContext *oc)\n{\n AVStream *st;\n AVCodecContext *audio_enc;\n int codec_id;\n st = av_new_stream(oc, oc->nb_streams);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n av_exit(1);\n }\n avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO);\n bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters;\n audio_bitstream_filters= NULL;\n if(thread_count>1)\n avcodec_thread_init(st->codec, thread_count);\n audio_enc = st->codec;\n audio_enc->codec_type = CODEC_TYPE_AUDIO;\n if(audio_codec_tag)\n audio_enc->codec_tag= audio_codec_tag;\n if (oc->oformat->flags & AVFMT_GLOBALHEADER) {\n audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;\n avcodec_opts[CODEC_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER;\n }\n if (audio_stream_copy) {\n st->stream_copy = 1;\n audio_enc->channels = audio_channels;\n } else {\n AVCodec *codec;\n set_context_opts(audio_enc, avcodec_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);\n if (audio_codec_name) {\n codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1);\n codec = avcodec_find_encoder_by_name(audio_codec_name);\n output_codecs[nb_ocodecs] = codec;\n } else {\n codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);\n codec = avcodec_find_encoder(codec_id);\n }\n audio_enc->codec_id = codec_id;\n if (audio_qscale > QSCALE_NONE) {\n audio_enc->flags |= CODEC_FLAG_QSCALE;\n audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;\n }\n audio_enc->thread_count = thread_count;\n audio_enc->channels = audio_channels;\n audio_enc->sample_fmt = audio_sample_fmt;\n audio_enc->channel_layout = channel_layout;\n if (avcodec_channel_layout_num_channels(channel_layout) != audio_channels)\n audio_enc->channel_layout = 0;\n if(codec && codec->sample_fmts){\n const enum SampleFormat *p= codec->sample_fmts;\n for(; *p!=-1; p++){\n if(*p == audio_enc->sample_fmt)\n break;\n }\n if(*p == -1)\n audio_enc->sample_fmt = codec->sample_fmts[0];\n }\n }\n nb_ocodecs++;\n audio_enc->sample_rate = audio_sample_rate;\n audio_enc->time_base= (AVRational){1, audio_sample_rate};\n if (audio_language) {\n av_metadata_set(&st->metadata, "language", audio_language);\n av_free(audio_language);\n audio_language = NULL;\n }\n audio_disable = 0;\n av_freep(&audio_codec_name);\n audio_stream_copy = 0;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n if (s->nb_streams >= MAX_STREAMS)\n return NULL;\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n st->codec= avcodec_alloc_context();\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->id = id;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = 0;\n st->first_dts = AV_NOPTS_VALUE;\n av_set_pts_info(st, 33, 1, 90000);\n st->last_IP_pts = AV_NOPTS_VALUE;\n for(i=0; i<MAX_REORDER_DELAY+1; i++)\n st->pts_buffer[i]= AV_NOPTS_VALUE;\n st->reference_dts = AV_NOPTS_VALUE;\n st->sample_aspect_ratio = (AVRational){0,1};\n s->streams[s->nb_streams++] = st;\n return st;\n}'] |
34,335 | 0 | https://github.com/openssl/openssl/blob/a8140a42f5ee9e4e1423b5b6b319dc4657659f6f/crypto/bn/bn_lib.c/#L232 | static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
} | ['int RSA_check_key_ex(const RSA *key, BN_GENCB *cb)\n{\n#ifdef FIPS_MODE\n return rsa_sp800_56b_check_public(key)\n && rsa_sp800_56b_check_private(key)\n && rsa_sp800_56b_check_keypair(key, NULL, -1, RSA_bits(key));\n#else\n BIGNUM *i, *j, *k, *l, *m;\n BN_CTX *ctx;\n int ret = 1, ex_primes = 0, idx;\n RSA_PRIME_INFO *pinfo;\n if (key->p == NULL || key->q == NULL || key->n == NULL\n || key->e == NULL || key->d == NULL) {\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_VALUE_MISSING);\n return 0;\n }\n if (key->version == RSA_ASN1_VERSION_MULTI) {\n ex_primes = sk_RSA_PRIME_INFO_num(key->prime_infos);\n if (ex_primes <= 0\n || (ex_primes + 2) > rsa_multip_cap(BN_num_bits(key->n))) {\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_INVALID_MULTI_PRIME_KEY);\n return 0;\n }\n }\n i = BN_new();\n j = BN_new();\n k = BN_new();\n l = BN_new();\n m = BN_new();\n ctx = BN_CTX_new();\n if (i == NULL || j == NULL || k == NULL || l == NULL\n || m == NULL || ctx == NULL) {\n ret = -1;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (BN_is_one(key->e)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n }\n if (!BN_is_odd(key->e)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n }\n if (BN_is_prime_ex(key->p, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_P_NOT_PRIME);\n }\n if (BN_is_prime_ex(key->q, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_Q_NOT_PRIME);\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (BN_is_prime_ex(pinfo->r, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_R_NOT_PRIME);\n }\n }\n if (!BN_mul(i, key->p, key->q, ctx)) {\n ret = -1;\n goto err;\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (!BN_mul(i, i, pinfo->r, ctx)) {\n ret = -1;\n goto err;\n }\n }\n if (BN_cmp(i, key->n) != 0) {\n ret = 0;\n if (ex_primes)\n RSAerr(RSA_F_RSA_CHECK_KEY_EX,\n RSA_R_N_DOES_NOT_EQUAL_PRODUCT_OF_PRIMES);\n else\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_N_DOES_NOT_EQUAL_P_Q);\n }\n if (!BN_sub(i, key->p, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_sub(j, key->q, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mul(l, i, j, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_gcd(m, i, j, ctx)) {\n ret = -1;\n goto err;\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (!BN_sub(k, pinfo->r, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mul(l, l, k, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_gcd(m, m, k, ctx)) {\n ret = -1;\n goto err;\n }\n }\n if (!BN_div(k, NULL, l, m, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_mod_mul(i, key->d, key->e, k, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_is_one(i)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_D_E_NOT_CONGRUENT_TO_1);\n }\n if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) {\n if (!BN_sub(i, key->p, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, key->dmp1) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMP1_NOT_CONGRUENT_TO_D);\n }\n if (!BN_sub(i, key->q, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, key->dmq1) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMQ1_NOT_CONGRUENT_TO_D);\n }\n if (!BN_mod_inverse(i, key->q, key->p, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(i, key->iqmp) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_IQMP_NOT_INVERSE_OF_Q);\n }\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (!BN_sub(i, pinfo->r, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, pinfo->d) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_EXPONENT_NOT_CONGRUENT_TO_D);\n }\n if (!BN_mod_inverse(i, pinfo->pp, pinfo->r, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(i, pinfo->t) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_COEFFICIENT_NOT_INVERSE_OF_R);\n }\n }\n err:\n BN_free(i);\n BN_free(j);\n BN_free(k);\n BN_free(l);\n BN_free(m);\n BN_CTX_free(ctx);\n return ret;\n#endif\n}', 'int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n BN_GENCB *cb)\n{\n return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);\n}', 'int BN_is_prime_fasttest_ex(const BIGNUM *w, int checks, BN_CTX *ctx_passed,\n int do_trial_division, BN_GENCB *cb)\n{\n int i, status, ret = -1;\n BN_CTX *ctx = NULL;\n if (BN_cmp(w, BN_value_one()) <= 0)\n return 0;\n if (BN_is_odd(w)) {\n if (BN_is_word(w, 3))\n return 1;\n } else {\n return BN_is_word(w, 2);\n }\n if (do_trial_division) {\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG mod = BN_mod_word(w, primes[i]);\n if (mod == (BN_ULONG)-1)\n return -1;\n if (mod == 0)\n return BN_is_word(w, primes[i]);\n }\n if (!BN_GENCB_call(cb, 1, -1))\n return -1;\n }\n if (ctx_passed != NULL)\n ctx = ctx_passed;\n else if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n ret = bn_miller_rabin_is_prime(w, checks, ctx, cb, 0, &status);\n if (!ret)\n goto err;\n ret = (status == BN_PRIMETEST_PROBABLY_PRIME);\nerr:\n if (ctx_passed == NULL)\n BN_CTX_free(ctx);\n return ret;\n}', 'int bn_miller_rabin_is_prime(const BIGNUM *w, int iterations, BN_CTX *ctx,\n BN_GENCB *cb, int enhanced, int *status)\n{\n int i, j, a, ret = 0;\n BIGNUM *g, *w1, *w3, *x, *m, *z, *b;\n BN_MONT_CTX *mont = NULL;\n if (!BN_is_odd(w))\n return 0;\n BN_CTX_start(ctx);\n g = BN_CTX_get(ctx);\n w1 = BN_CTX_get(ctx);\n w3 = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n m = BN_CTX_get(ctx);\n z = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (!(b != NULL\n && BN_copy(w1, w)\n && BN_sub_word(w1, 1)\n && BN_copy(w3, w)\n && BN_sub_word(w3, 3)))\n goto err;\n if (BN_is_zero(w3) || BN_is_negative(w3))\n goto err;\n a = 1;\n while (!BN_is_bit_set(w1, a))\n a++;\n if (!BN_rshift(m, w1, a))\n goto err;\n mont = BN_MONT_CTX_new();\n if (mont == NULL || !BN_MONT_CTX_set(mont, w, ctx))\n goto err;\n if (iterations == BN_prime_checks)\n iterations = BN_prime_checks_for_size(BN_num_bits(w));\n for (i = 0; i < iterations; ++i) {\n if (!BN_priv_rand_range(b, w3) || !BN_add_word(b, 2))\n goto err;\n if (enhanced) {\n if (!BN_gcd(g, b, w, ctx))\n goto err;\n if (!BN_is_one(g)) {\n *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n ret = 1;\n goto err;\n }\n }\n if (!BN_mod_exp_mont(z, b, m, w, ctx, mont))\n goto err;\n if (BN_is_one(z) || BN_cmp(z, w1) == 0)\n goto outer_loop;\n for (j = 1; j < a ; ++j) {\n if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n goto err;\n if (BN_cmp(z, w1) == 0)\n goto outer_loop;\n if (BN_is_one(z))\n goto composite;\n }\n if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n goto err;\n if (BN_is_one(z))\n goto composite;\n if (!BN_copy(x, z))\n goto err;\ncomposite:\n if (enhanced) {\n if (!BN_sub_word(x, 1) || !BN_gcd(g, x, w, ctx))\n goto err;\n if (BN_is_one(g))\n *status = BN_PRIMETEST_COMPOSITE_NOT_POWER_OF_PRIME;\n else\n *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n } else {\n *status = BN_PRIMETEST_COMPOSITE;\n }\n ret = 1;\n goto err;\nouter_loop: ;\n if (!BN_GENCB_call(cb, 1, i))\n goto err;\n }\n *status = BN_PRIMETEST_PROBABLY_PRIME;\n ret = 1;\nerr:\n BN_clear(g);\n BN_clear(w1);\n BN_clear(w3);\n BN_clear(x);\n BN_clear(m);\n BN_clear(z);\n BN_clear(b);\n BN_CTX_end(ctx);\n BN_MONT_CTX_free(mont);\n return ret;\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (!bn_to_mont_fixed_top(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !bn_mul_mont_fixed_top(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n r->flags |= BN_FLG_FIXED_TOP;\n } else\n#endif\n if (!bn_to_mont_fixed_top(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (!bn_mul_mont_fixed_top(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = bn_mul_fixed_top(r, a, b, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}'] |
34,336 | 0 | https://github.com/libav/libav/blob/7c44d716e76cbd1c29369563a8b384addd5e7c03/libavformat/utils.c/#L2609 | void avformat_free_context(AVFormatContext *s)
{
int i;
AVStream *st;
av_opt_free(s);
if (s->iformat && s->iformat->priv_class && s->priv_data)
av_opt_free(s->priv_data);
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
if (st->parser) {
av_parser_close(st->parser);
av_free_packet(&st->cur_pkt);
}
av_dict_free(&st->metadata);
av_free(st->index_entries);
av_free(st->codec->extradata);
av_free(st->codec->subtitle_header);
av_free(st->codec);
av_free(st->priv_data);
av_free(st->info);
av_free(st);
}
for(i=s->nb_programs-1; i>=0; i--) {
av_dict_free(&s->programs[i]->metadata);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
av_freep(&s->programs);
av_freep(&s->priv_data);
while(s->nb_chapters--) {
av_dict_free(&s->chapters[s->nb_chapters]->metadata);
av_free(s->chapters[s->nb_chapters]);
}
av_freep(&s->chapters);
av_dict_free(&s->metadata);
av_freep(&s->streams);
av_free(s);
} | ['static int read_ffserver_streams(AVFormatContext *s, const char *filename)\n{\n int i, err;\n AVFormatContext *ic = NULL;\n int nopts = 0;\n err = avformat_open_input(&ic, filename, NULL, NULL);\n if (err < 0)\n return err;\n s->nb_streams = 0;\n s->streams = av_mallocz(sizeof(AVStream *) * ic->nb_streams);\n for(i=0;i<ic->nb_streams;i++) {\n AVStream *st;\n AVCodec *codec;\n s->nb_streams++;\n st = av_mallocz(sizeof(AVStream));\n memcpy(st, ic->streams[i], sizeof(AVStream));\n st->info = NULL;\n st->codec = avcodec_alloc_context();\n if (!st->codec) {\n print_error(filename, AVERROR(ENOMEM));\n ffmpeg_exit(1);\n }\n avcodec_copy_context(st->codec, ic->streams[i]->codec);\n s->streams[i] = st;\n codec = avcodec_find_encoder(st->codec->codec_id);\n if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {\n if (audio_stream_copy) {\n st->stream_copy = 1;\n } else\n choose_sample_fmt(st, codec);\n } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n if (video_stream_copy) {\n st->stream_copy = 1;\n } else\n choose_pixel_fmt(st, codec);\n }\n if(st->codec->flags & CODEC_FLAG_BITEXACT)\n nopts = 1;\n new_output_stream(s, nb_output_files);\n }\n if (!nopts)\n s->timestamp = av_gettime();\n av_close_input_file(ic);\n return 0;\n}', 'int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)\n{\n AVFormatContext *s = *ps;\n int ret = 0;\n AVFormatParameters ap = { 0 };\n AVDictionary *tmp = NULL;\n if (!s && !(s = avformat_alloc_context()))\n return AVERROR(ENOMEM);\n if (fmt)\n s->iformat = fmt;\n if (options)\n av_dict_copy(&tmp, *options, 0);\n if ((ret = av_opt_set_dict(s, &tmp)) < 0)\n goto fail;\n if ((ret = init_input(s, filename)) < 0)\n goto fail;\n if (s->iformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(filename)) {\n ret = AVERROR(EINVAL);\n goto fail;\n }\n }\n s->duration = s->start_time = AV_NOPTS_VALUE;\n av_strlcpy(s->filename, filename, sizeof(s->filename));\n if (s->iformat->priv_data_size > 0) {\n if (!(s->priv_data = av_mallocz(s->iformat->priv_data_size))) {\n ret = AVERROR(ENOMEM);\n goto fail;\n }\n if (s->iformat->priv_class) {\n *(const AVClass**)s->priv_data = s->iformat->priv_class;\n av_opt_set_defaults(s->priv_data);\n if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)\n goto fail;\n }\n }\n if (s->pb)\n ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);\n if (s->iformat->read_header)\n if ((ret = s->iformat->read_header(s, &ap)) < 0)\n goto fail;\n if (s->pb && !s->data_offset)\n s->data_offset = avio_tell(s->pb);\n s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;\n if (options) {\n av_dict_free(options);\n *options = tmp;\n }\n *ps = s;\n return 0;\nfail:\n av_dict_free(&tmp);\n if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO))\n avio_close(s->pb);\n avformat_free_context(s);\n *ps = NULL;\n return ret;\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n av_opt_free(s);\n if (s->iformat && s->iformat->priv_class && s->priv_data)\n av_opt_free(s->priv_data);\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n av_free_packet(&st->cur_pkt);\n }\n av_dict_free(&st->metadata);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec->subtitle_header);\n av_free(st->codec);\n av_free(st->priv_data);\n av_free(st->info);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n av_dict_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n av_dict_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_dict_free(&s->metadata);\n av_freep(&s->streams);\n av_free(s);\n}'] |
34,337 | 0 | https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/vc1.c/#L646 | static void vc1_mc_4mv_chroma(VC1Context *v)
{
MpegEncContext *s = &v->s;
DSPContext *dsp = &v->s.dsp;
uint8_t *srcU, *srcV;
int uvdxy, uvmx, uvmy, uvsrc_x, uvsrc_y;
int i, idx, tx = 0, ty = 0;
int mvx[4], mvy[4], intra[4];
static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
if(!v->s.last_picture.data[0])return;
if(s->flags & CODEC_FLAG_GRAY) return;
for(i = 0; i < 4; i++) {
mvx[i] = s->mv[0][i][0];
mvy[i] = s->mv[0][i][1];
intra[i] = v->mb_type[0][s->block_index[i]];
}
idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0];
if(!idx) {
tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);
ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);
} else if(count[idx] == 1) {
switch(idx) {
case 0x1:
tx = mid_pred(mvx[1], mvx[2], mvx[3]);
ty = mid_pred(mvy[1], mvy[2], mvy[3]);
break;
case 0x2:
tx = mid_pred(mvx[0], mvx[2], mvx[3]);
ty = mid_pred(mvy[0], mvy[2], mvy[3]);
break;
case 0x4:
tx = mid_pred(mvx[0], mvx[1], mvx[3]);
ty = mid_pred(mvy[0], mvy[1], mvy[3]);
break;
case 0x8:
tx = mid_pred(mvx[0], mvx[1], mvx[2]);
ty = mid_pred(mvy[0], mvy[1], mvy[2]);
break;
}
} else if(count[idx] == 2) {
int t1 = 0, t2 = 0;
for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;}
for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;}
tx = (mvx[t1] + mvx[t2]) / 2;
ty = (mvy[t1] + mvy[t2]) / 2;
} else {
s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
return;
}
s->current_picture.motion_val[1][s->block_index[0]][0] = tx;
s->current_picture.motion_val[1][s->block_index[0]][1] = ty;
uvmx = (tx + ((tx&3) == 3)) >> 1;
uvmy = (ty + ((ty&3) == 3)) >> 1;
if(v->fastuvmc) {
uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
}
uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
if(v->profile != PROFILE_ADVANCED){
uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
}else{
uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
}
srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
|| (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9
|| (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){
ff_emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1,
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
ff_emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1,
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
srcU = s->edge_emu_buffer;
srcV = s->edge_emu_buffer + 16;
if(v->rangeredfrm) {
int i, j;
uint8_t *src, *src2;
src = srcU; src2 = srcV;
for(j = 0; j < 9; j++) {
for(i = 0; i < 9; i++) {
src[i] = ((src[i] - 128) >> 1) + 128;
src2[i] = ((src2[i] - 128) >> 1) + 128;
}
src += s->uvlinesize;
src2 += s->uvlinesize;
}
}
if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
int i, j;
uint8_t *src, *src2;
src = srcU; src2 = srcV;
for(j = 0; j < 9; j++) {
for(i = 0; i < 9; i++) {
src[i] = v->lutuv[src[i]];
src2[i] = v->lutuv[src2[i]];
}
src += s->uvlinesize;
src2 += s->uvlinesize;
}
}
}
uvdxy = ((uvmy & 3) << 2) | (uvmx & 3);
uvmx = (uvmx&3)<<1;
uvmy = (uvmy&3)<<1;
if(!v->rnd){
dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
}else{
dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
}
} | ['static void vc1_mc_4mv_chroma(VC1Context *v)\n{\n MpegEncContext *s = &v->s;\n DSPContext *dsp = &v->s.dsp;\n uint8_t *srcU, *srcV;\n int uvdxy, uvmx, uvmy, uvsrc_x, uvsrc_y;\n int i, idx, tx = 0, ty = 0;\n int mvx[4], mvy[4], intra[4];\n static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};\n if(!v->s.last_picture.data[0])return;\n if(s->flags & CODEC_FLAG_GRAY) return;\n for(i = 0; i < 4; i++) {\n mvx[i] = s->mv[0][i][0];\n mvy[i] = s->mv[0][i][1];\n intra[i] = v->mb_type[0][s->block_index[i]];\n }\n idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0];\n if(!idx) {\n tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);\n ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);\n } else if(count[idx] == 1) {\n switch(idx) {\n case 0x1:\n tx = mid_pred(mvx[1], mvx[2], mvx[3]);\n ty = mid_pred(mvy[1], mvy[2], mvy[3]);\n break;\n case 0x2:\n tx = mid_pred(mvx[0], mvx[2], mvx[3]);\n ty = mid_pred(mvy[0], mvy[2], mvy[3]);\n break;\n case 0x4:\n tx = mid_pred(mvx[0], mvx[1], mvx[3]);\n ty = mid_pred(mvy[0], mvy[1], mvy[3]);\n break;\n case 0x8:\n tx = mid_pred(mvx[0], mvx[1], mvx[2]);\n ty = mid_pred(mvy[0], mvy[1], mvy[2]);\n break;\n }\n } else if(count[idx] == 2) {\n int t1 = 0, t2 = 0;\n for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;}\n for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;}\n tx = (mvx[t1] + mvx[t2]) / 2;\n ty = (mvy[t1] + mvy[t2]) / 2;\n } else {\n s->current_picture.motion_val[1][s->block_index[0]][0] = 0;\n s->current_picture.motion_val[1][s->block_index[0]][1] = 0;\n return;\n }\n s->current_picture.motion_val[1][s->block_index[0]][0] = tx;\n s->current_picture.motion_val[1][s->block_index[0]][1] = ty;\n uvmx = (tx + ((tx&3) == 3)) >> 1;\n uvmy = (ty + ((ty&3) == 3)) >> 1;\n if(v->fastuvmc) {\n uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));\n uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));\n }\n uvsrc_x = s->mb_x * 8 + (uvmx >> 2);\n uvsrc_y = s->mb_y * 8 + (uvmy >> 2);\n if(v->profile != PROFILE_ADVANCED){\n uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);\n uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);\n }else{\n uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);\n uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);\n }\n srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;\n srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;\n if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)\n || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9\n || (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){\n ff_emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1,\n uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);\n ff_emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1,\n uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);\n srcU = s->edge_emu_buffer;\n srcV = s->edge_emu_buffer + 16;\n if(v->rangeredfrm) {\n int i, j;\n uint8_t *src, *src2;\n src = srcU; src2 = srcV;\n for(j = 0; j < 9; j++) {\n for(i = 0; i < 9; i++) {\n src[i] = ((src[i] - 128) >> 1) + 128;\n src2[i] = ((src2[i] - 128) >> 1) + 128;\n }\n src += s->uvlinesize;\n src2 += s->uvlinesize;\n }\n }\n if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {\n int i, j;\n uint8_t *src, *src2;\n src = srcU; src2 = srcV;\n for(j = 0; j < 9; j++) {\n for(i = 0; i < 9; i++) {\n src[i] = v->lutuv[src[i]];\n src2[i] = v->lutuv[src2[i]];\n }\n src += s->uvlinesize;\n src2 += s->uvlinesize;\n }\n }\n }\n uvdxy = ((uvmy & 3) << 2) | (uvmx & 3);\n uvmx = (uvmx&3)<<1;\n uvmy = (uvmy&3)<<1;\n if(!v->rnd){\n dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);\n dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);\n }else{\n dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);\n dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);\n }\n}'] |
34,338 | 0 | https://gitlab.com/libtiff/libtiff/blob/163627448aa8d2893582f2546dd85706586e6243/libtiff/tif_swab.c/#L113 | void
TIFFSwabArrayOfLong(register uint32* lp, tmsize_t n)
{
register unsigned char *cp;
register unsigned char t;
assert(sizeof(uint32)==4);
while (n-- > 0) {
cp = (unsigned char *)lp;
t = cp[3]; cp[3] = cp[0]; cp[0] = t;
t = cp[2]; cp[2] = cp[1]; cp[1] = t;
lp++;
}
} | ['static int\nwriteCroppedImage(TIFF *in, TIFF *out, struct image_data *image,\n struct dump_opts *dump, uint32 width, uint32 length,\n unsigned char *crop_buff, int pagenum, int total_pages)\n {\n uint16 bps, spp;\n uint16 input_compression, input_photometric;\n uint16 input_planar;\n struct cpTag* p;\n input_compression = image->compression;\n input_photometric = image->photometric;\n spp = image->spp;\n bps = image->bps;\n TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);\n TIFFSetField(out, TIFFTAG_IMAGELENGTH, length);\n TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bps);\n TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, spp);\n#ifdef DEBUG2\n TIFFError("writeCroppedImage", "Input compression: %s",\n\t (input_compression == COMPRESSION_OJPEG) ? "Old Jpeg" :\n\t ((input_compression == COMPRESSION_JPEG) ? "New Jpeg" : "Non Jpeg"));\n#endif\n if (compression != (uint16)-1)\n TIFFSetField(out, TIFFTAG_COMPRESSION, compression);\n else\n {\n if (input_compression == COMPRESSION_OJPEG)\n {\n compression = COMPRESSION_JPEG;\n jpegcolormode = JPEGCOLORMODE_RAW;\n TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);\n }\n else\n CopyField(TIFFTAG_COMPRESSION, compression);\n }\n if (compression == COMPRESSION_JPEG)\n {\n if ((input_photometric == PHOTOMETRIC_PALETTE) ||\n (input_photometric == PHOTOMETRIC_MASK))\n {\n TIFFError ("writeCroppedImage",\n "JPEG compression cannot be used with %s image data",\n \t (input_photometric == PHOTOMETRIC_PALETTE) ?\n "palette" : "mask");\n return (-1);\n }\n if ((input_photometric == PHOTOMETRIC_RGB) &&\n\t(jpegcolormode == JPEGCOLORMODE_RGB))\n TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);\n else\n\tTIFFSetField(out, TIFFTAG_PHOTOMETRIC, input_photometric);\n }\n else\n {\n if (compression == COMPRESSION_SGILOG || compression == COMPRESSION_SGILOG24)\n {\n TIFFSetField(out, TIFFTAG_PHOTOMETRIC, spp == 1 ?\n\t\t\tPHOTOMETRIC_LOGL : PHOTOMETRIC_LOGLUV);\n }\n else\n {\n if (input_compression == COMPRESSION_SGILOG ||\n input_compression == COMPRESSION_SGILOG24)\n {\n TIFFSetField(out, TIFFTAG_PHOTOMETRIC, spp == 1 ?\n\t\t\t PHOTOMETRIC_LOGL : PHOTOMETRIC_LOGLUV);\n }\n else\n TIFFSetField(out, TIFFTAG_PHOTOMETRIC, image->photometric);\n }\n }\n if (((input_photometric == PHOTOMETRIC_LOGL) ||\n (input_photometric == PHOTOMETRIC_LOGLUV)) &&\n ((compression != COMPRESSION_SGILOG) &&\n (compression != COMPRESSION_SGILOG24)))\n {\n TIFFError("writeCroppedImage",\n "LogL and LogLuv source data require SGI_LOG or SGI_LOG24 compression");\n return (-1);\n }\n if (fillorder != 0)\n TIFFSetField(out, TIFFTAG_FILLORDER, fillorder);\n else\n CopyTag(TIFFTAG_FILLORDER, 1, TIFF_SHORT);\n TIFFSetField(out, TIFFTAG_ORIENTATION, image->orientation);\n if (outtiled == -1)\n outtiled = TIFFIsTiled(in);\n if (outtiled) {\n if (tilewidth == (uint32) 0)\n TIFFGetField(in, TIFFTAG_TILEWIDTH, &tilewidth);\n if (tilelength == (uint32) 0)\n TIFFGetField(in, TIFFTAG_TILELENGTH, &tilelength);\n if (tilewidth == 0 || tilelength == 0)\n TIFFDefaultTileSize(out, &tilewidth, &tilelength);\n TIFFSetField(out, TIFFTAG_TILEWIDTH, tilewidth);\n TIFFSetField(out, TIFFTAG_TILELENGTH, tilelength);\n } else {\n\tif (rowsperstrip == (uint32) 0)\n {\n\t if (!TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &rowsperstrip))\n\t rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip);\n if (compression != COMPRESSION_JPEG)\n {\n \t if (rowsperstrip > length)\n\t rowsperstrip = length;\n\t }\n\t }\n\telse\n if (rowsperstrip == (uint32) -1)\n\t rowsperstrip = length;\n\tTIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip);\n\t}\n TIFFGetFieldDefaulted(in, TIFFTAG_PLANARCONFIG, &input_planar);\n if (config != (uint16) -1)\n TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);\n else\n CopyField(TIFFTAG_PLANARCONFIG, config);\n if (spp <= 4)\n CopyTag(TIFFTAG_TRANSFERFUNCTION, 4, TIFF_SHORT);\n CopyTag(TIFFTAG_COLORMAP, 4, TIFF_SHORT);\n switch (compression) {\n case COMPRESSION_JPEG:\n if (((bps % 8) == 0) || ((bps % 12) == 0))\n\t {\n TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);\n\t TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);\n }\n else\n {\n\t TIFFError("writeCroppedImage",\n "JPEG compression requires 8 or 12 bits per sample");\n return (-1);\n }\n\t break;\n case COMPRESSION_LZW:\n case COMPRESSION_ADOBE_DEFLATE:\n case COMPRESSION_DEFLATE:\n\tif (predictor != (uint16)-1)\n TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);\n\telse\n\t CopyField(TIFFTAG_PREDICTOR, predictor);\n\tbreak;\n case COMPRESSION_CCITTFAX3:\n case COMPRESSION_CCITTFAX4:\n if (bps != 1)\n {\n\t TIFFError("writeCroppedImage",\n "Group 3/4 compression is not usable with bps > 1");\n return (-1);\n\t }\n\tif (compression == COMPRESSION_CCITTFAX3) {\n if (g3opts != (uint32) -1)\n\t TIFFSetField(out, TIFFTAG_GROUP3OPTIONS, g3opts);\n\t else\n\t CopyField(TIFFTAG_GROUP3OPTIONS, g3opts);\n\t} else\n\t CopyTag(TIFFTAG_GROUP4OPTIONS, 1, TIFF_LONG);\n\t CopyTag(TIFFTAG_BADFAXLINES, 1, TIFF_LONG);\n\t CopyTag(TIFFTAG_CLEANFAXDATA, 1, TIFF_LONG);\n\t CopyTag(TIFFTAG_CONSECUTIVEBADFAXLINES, 1, TIFF_LONG);\n\t CopyTag(TIFFTAG_FAXRECVPARAMS, 1, TIFF_LONG);\n\t CopyTag(TIFFTAG_FAXRECVTIME, 1, TIFF_LONG);\n\t CopyTag(TIFFTAG_FAXSUBADDRESS, 1, TIFF_ASCII);\n\t break;\n case COMPRESSION_NONE:\n break;\n default: break;\n }\n { uint32 len32;\n void** data;\n if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &len32, &data))\n TIFFSetField(out, TIFFTAG_ICCPROFILE, len32, data);\n }\n { uint16 ninks;\n const char* inknames;\n if (TIFFGetField(in, TIFFTAG_NUMBEROFINKS, &ninks)) {\n TIFFSetField(out, TIFFTAG_NUMBEROFINKS, ninks);\n if (TIFFGetField(in, TIFFTAG_INKNAMES, &inknames)) {\n\t int inknameslen = strlen(inknames) + 1;\n\t const char* cp = inknames;\n\t while (ninks > 1) {\n\t cp = strchr(cp, \'\\0\');\n\t if (cp) {\n\t cp++;\n\t inknameslen += (strlen(cp) + 1);\n\t }\n\t ninks--;\n }\n\t TIFFSetField(out, TIFFTAG_INKNAMES, inknameslen, inknames);\n }\n }\n }\n {\n unsigned short pg0, pg1;\n if (TIFFGetField(in, TIFFTAG_PAGENUMBER, &pg0, &pg1)) {\n TIFFSetField(out, TIFFTAG_PAGENUMBER, pagenum, total_pages);\n }\n }\n for (p = tags; p < &tags[NTAGS]; p++)\n\t\tCopyTag(p->tag, p->count, p->type);\n if (outtiled)\n {\n if (config == PLANARCONFIG_CONTIG)\n {\n if (writeBufferToContigTiles (out, crop_buff, length, width, spp, dump))\n TIFFError("","Unable to write contiguous tile data for page %d", pagenum);\n }\n else\n {\n if (writeBufferToSeparateTiles (out, crop_buff, length, width, spp, dump))\n TIFFError("","Unable to write separate tile data for page %d", pagenum);\n }\n }\n else\n {\n if (config == PLANARCONFIG_CONTIG)\n {\n if (writeBufferToContigStrips (out, crop_buff, length))\n TIFFError("","Unable to write contiguous strip data for page %d", pagenum);\n }\n else\n {\n if (writeBufferToSeparateStrips(out, crop_buff, length, width, spp, dump))\n TIFFError("","Unable to write separate strip data for page %d", pagenum);\n }\n }\n if (!TIFFWriteDirectory(out))\n {\n TIFFError("","Failed to write IFD for page number %d", pagenum);\n TIFFClose(out);\n return (-1);\n }\n return (0);\n }', 'static int writeBufferToContigStrips(TIFF* out, uint8* buf, uint32 imagelength)\n {\n uint32 row, nrows, rowsperstrip;\n tstrip_t strip = 0;\n tsize_t stripsize;\n TIFFGetFieldDefaulted(out, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);\n for (row = 0; row < imagelength; row += rowsperstrip)\n {\n nrows = (row + rowsperstrip > imagelength) ?\n\t imagelength - row : rowsperstrip;\n stripsize = TIFFVStripSize(out, nrows);\n if (TIFFWriteEncodedStrip(out, strip++, buf, stripsize) < 0)\n {\n TIFFError(TIFFFileName(out), "Error, can\'t write strip %u", strip - 1);\n return 1;\n }\n buf += stripsize;\n }\n return 0;\n }', 'int\nTIFFGetFieldDefaulted(TIFF* tif, uint32 tag, ...)\n{\n\tint ok;\n\tva_list ap;\n\tva_start(ap, tag);\n\tok = TIFFVGetFieldDefaulted(tif, tag, ap);\n\tva_end(ap);\n\treturn (ok);\n}', 'int\nTIFFVGetFieldDefaulted(TIFF* tif, uint32 tag, va_list ap)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif (TIFFVGetField(tif, tag, ap))\n\t\treturn (1);\n\tswitch (tag) {\n\tcase TIFFTAG_SUBFILETYPE:\n\t\t*va_arg(ap, uint32 *) = td->td_subfiletype;\n\t\treturn (1);\n\tcase TIFFTAG_BITSPERSAMPLE:\n\t\t*va_arg(ap, uint16 *) = td->td_bitspersample;\n\t\treturn (1);\n\tcase TIFFTAG_THRESHHOLDING:\n\t\t*va_arg(ap, uint16 *) = td->td_threshholding;\n\t\treturn (1);\n\tcase TIFFTAG_FILLORDER:\n\t\t*va_arg(ap, uint16 *) = td->td_fillorder;\n\t\treturn (1);\n\tcase TIFFTAG_ORIENTATION:\n\t\t*va_arg(ap, uint16 *) = td->td_orientation;\n\t\treturn (1);\n\tcase TIFFTAG_SAMPLESPERPIXEL:\n\t\t*va_arg(ap, uint16 *) = td->td_samplesperpixel;\n\t\treturn (1);\n\tcase TIFFTAG_ROWSPERSTRIP:\n\t\t*va_arg(ap, uint32 *) = td->td_rowsperstrip;\n\t\treturn (1);\n\tcase TIFFTAG_MINSAMPLEVALUE:\n\t\t*va_arg(ap, uint16 *) = td->td_minsamplevalue;\n\t\treturn (1);\n\tcase TIFFTAG_MAXSAMPLEVALUE:\n\t\t*va_arg(ap, uint16 *) = td->td_maxsamplevalue;\n\t\treturn (1);\n\tcase TIFFTAG_PLANARCONFIG:\n\t\t*va_arg(ap, uint16 *) = td->td_planarconfig;\n\t\treturn (1);\n\tcase TIFFTAG_RESOLUTIONUNIT:\n\t\t*va_arg(ap, uint16 *) = td->td_resolutionunit;\n\t\treturn (1);\n\tcase TIFFTAG_PREDICTOR:\n {\n\t\t\tTIFFPredictorState* sp = (TIFFPredictorState*) tif->tif_data;\n\t\t\t*va_arg(ap, uint16*) = (uint16) sp->predictor;\n\t\t\treturn 1;\n }\n\tcase TIFFTAG_DOTRANGE:\n\t\t*va_arg(ap, uint16 *) = 0;\n\t\t*va_arg(ap, uint16 *) = (1<<td->td_bitspersample)-1;\n\t\treturn (1);\n\tcase TIFFTAG_INKSET:\n\t\t*va_arg(ap, uint16 *) = INKSET_CMYK;\n\t\treturn 1;\n\tcase TIFFTAG_NUMBEROFINKS:\n\t\t*va_arg(ap, uint16 *) = 4;\n\t\treturn (1);\n\tcase TIFFTAG_EXTRASAMPLES:\n\t\t*va_arg(ap, uint16 *) = td->td_extrasamples;\n\t\t*va_arg(ap, uint16 **) = td->td_sampleinfo;\n\t\treturn (1);\n\tcase TIFFTAG_MATTEING:\n\t\t*va_arg(ap, uint16 *) =\n\t\t (td->td_extrasamples == 1 &&\n\t\t td->td_sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);\n\t\treturn (1);\n\tcase TIFFTAG_TILEDEPTH:\n\t\t*va_arg(ap, uint32 *) = td->td_tiledepth;\n\t\treturn (1);\n\tcase TIFFTAG_DATATYPE:\n\t\t*va_arg(ap, uint16 *) = td->td_sampleformat-1;\n\t\treturn (1);\n\tcase TIFFTAG_SAMPLEFORMAT:\n\t\t*va_arg(ap, uint16 *) = td->td_sampleformat;\n return(1);\n\tcase TIFFTAG_IMAGEDEPTH:\n\t\t*va_arg(ap, uint32 *) = td->td_imagedepth;\n\t\treturn (1);\n\tcase TIFFTAG_YCBCRCOEFFICIENTS:\n\t\t{\n\t\t\tstatic float ycbcrcoeffs[] = { 0.299f, 0.587f, 0.114f };\n\t\t\t*va_arg(ap, float **) = ycbcrcoeffs;\n\t\t\treturn 1;\n\t\t}\n\tcase TIFFTAG_YCBCRSUBSAMPLING:\n\t\t*va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[0];\n\t\t*va_arg(ap, uint16 *) = td->td_ycbcrsubsampling[1];\n\t\treturn (1);\n\tcase TIFFTAG_YCBCRPOSITIONING:\n\t\t*va_arg(ap, uint16 *) = td->td_ycbcrpositioning;\n\t\treturn (1);\n\tcase TIFFTAG_WHITEPOINT:\n\t\t{\n\t\t\tstatic float whitepoint[2];\n\t\t\twhitepoint[0] =\tD50_X0 / (D50_X0 + D50_Y0 + D50_Z0);\n\t\t\twhitepoint[1] =\tD50_Y0 / (D50_X0 + D50_Y0 + D50_Z0);\n\t\t\t*va_arg(ap, float **) = whitepoint;\n\t\t\treturn 1;\n\t\t}\n\tcase TIFFTAG_TRANSFERFUNCTION:\n\t\tif (!td->td_transferfunction[0] &&\n\t\t !TIFFDefaultTransferFunction(td)) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name, "No space for \\"TransferFunction\\" tag");\n\t\t\treturn (0);\n\t\t}\n\t\t*va_arg(ap, uint16 **) = td->td_transferfunction[0];\n\t\tif (td->td_samplesperpixel - td->td_extrasamples > 1) {\n\t\t\t*va_arg(ap, uint16 **) = td->td_transferfunction[1];\n\t\t\t*va_arg(ap, uint16 **) = td->td_transferfunction[2];\n\t\t}\n\t\treturn (1);\n\tcase TIFFTAG_REFERENCEBLACKWHITE:\n\t\tif (!td->td_refblackwhite && !TIFFDefaultRefBlackWhite(td))\n\t\t\treturn (0);\n\t\t*va_arg(ap, float **) = td->td_refblackwhite;\n\t\treturn (1);\n\t}\n\treturn 0;\n}', 'int\nTIFFWriteDirectory(TIFF* tif)\n{\n\treturn TIFFWriteDirectorySec(tif,TRUE,TRUE,NULL);\n}', 'static int\nTIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)\n{\n\tstatic const char module[] = "TIFFWriteDirectorySec";\n\tuint32 ndir;\n\tTIFFDirEntry* dir;\n\tuint32 dirsize;\n\tvoid* dirmem;\n\tuint32 m;\n\tif (tif->tif_mode == O_RDONLY)\n\t\treturn (1);\n _TIFFFillStriles( tif );\n\tif (imagedone)\n\t{\n\t\tif (tif->tif_flags & TIFF_POSTENCODE)\n\t\t{\n\t\t\ttif->tif_flags &= ~TIFF_POSTENCODE;\n\t\t\tif (!(*tif->tif_postencode)(tif))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t\t\t "Error post-encoding before directory write");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\t(*tif->tif_close)(tif);\n\t\tif (tif->tif_rawcc > 0\n\t\t && (tif->tif_flags & TIFF_BEENWRITING) != 0 )\n\t\t{\n\t\t if( !TIFFFlushData1(tif) )\n {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Error flushing data before directory write");\n\t\t\treturn (0);\n }\n\t\t}\n\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)\n\t\t{\n\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\ttif->tif_rawdata = NULL;\n\t\t\ttif->tif_rawcc = 0;\n\t\t\ttif->tif_rawdatasize = 0;\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = 0;\n\t\t}\n\t\ttif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP);\n\t}\n\tdir=NULL;\n\tdirmem=NULL;\n\tdirsize=0;\n\twhile (1)\n\t{\n\t\tndir=0;\n\t\tif (isimage)\n\t\t{\n\t\t\tif (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGEWIDTH,tif->tif_dir.td_imagewidth))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGELENGTH,tif->tif_dir.td_imagelength))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILEWIDTH,tif->tif_dir.td_tilewidth))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILELENGTH,tif->tif_dir.td_tilelength))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_RESOLUTION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XRESOLUTION,tif->tif_dir.td_xresolution))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YRESOLUTION,tif->tif_dir.td_yresolution))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_POSITION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XPOSITION,tif->tif_dir.td_xposition))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YPOSITION,tif->tif_dir.td_yposition))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SUBFILETYPE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_SUBFILETYPE,tif->tif_dir.td_subfiletype))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_BITSPERSAMPLE,tif->tif_dir.td_bitspersample))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_COMPRESSION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_COMPRESSION,tif->tif_dir.td_compression))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PHOTOMETRIC))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PHOTOMETRIC,tif->tif_dir.td_photometric))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_THRESHHOLDING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_THRESHHOLDING,tif->tif_dir.td_threshholding))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_FILLORDER))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_FILLORDER,tif->tif_dir.td_fillorder))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_ORIENTATION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_ORIENTATION,tif->tif_dir.td_orientation))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_SAMPLESPERPIXEL,tif->tif_dir.td_samplesperpixel))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_ROWSPERSTRIP,tif->tif_dir.td_rowsperstrip))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MINSAMPLEVALUE,tif->tif_dir.td_minsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MAXSAMPLEVALUE,tif->tif_dir.td_maxsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PLANARCONFIG))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PLANARCONFIG,tif->tif_dir.td_planarconfig))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_RESOLUTIONUNIT,tif->tif_dir.td_resolutionunit))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PAGENUMBER))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_PAGENUMBER,2,&tif->tif_dir.td_pagenumber[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_STRIPBYTECOUNTS))\n\t\t\t{\n\t\t\t\tif (!isTiled(tif))\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_STRIPOFFSETS))\n\t\t\t{\n\t\t\t\tif (!isTiled(tif))\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_COLORMAP))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagColormap(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_EXTRASAMPLES))\n\t\t\t{\n\t\t\t\tif (tif->tif_dir.td_extrasamples)\n\t\t\t\t{\n\t\t\t\t\tuint16 na;\n\t\t\t\t\tuint16* nb;\n\t\t\t\t\tTIFFGetFieldDefaulted(tif,TIFFTAG_EXTRASAMPLES,&na,&nb);\n\t\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_EXTRASAMPLES,na,nb))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_SAMPLEFORMAT,tif->tif_dir.td_sampleformat))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMINSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_sminsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMAXSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_smaxsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_IMAGEDEPTH))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_IMAGEDEPTH,tif->tif_dir.td_imagedepth))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TILEDEPTH))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_TILEDEPTH,tif->tif_dir.td_tiledepth))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_HALFTONEHINTS,2,&tif->tif_dir.td_halftonehints[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_YCBCRSUBSAMPLING,2,&tif->tif_dir.td_ycbcrsubsampling[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_YCBCRPOSITIONING,tif->tif_dir.td_ycbcrpositioning))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_REFBLACKWHITE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,TIFFTAG_REFERENCEBLACKWHITE,6,tif->tif_dir.td_refblackwhite))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagTransferfunction(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_INKNAMES))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,TIFFTAG_INKNAMES,tif->tif_dir.td_inknameslen,tif->tif_dir.td_inknames))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SUBIFD))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSubifd(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\t{\n\t\t\t\tuint32 n;\n\t\t\t\tfor (n=0; n<tif->tif_nfields; n++) {\n\t\t\t\t\tconst TIFFField* o;\n\t\t\t\t\to = tif->tif_fields[n];\n\t\t\t\t\tif ((o->field_bit>=FIELD_CODEC)&&(TIFFFieldSet(tif,o->field_bit)))\n\t\t\t\t\t{\n\t\t\t\t\t\tswitch (o->get_field_type)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcase TIFF_SETGET_ASCII:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 pa;\n\t\t\t\t\t\t\t\t\tchar* pb;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_ASCII);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==TIFF_VARIABLE);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&pb);\n\t\t\t\t\t\t\t\t\tpa=(uint32)(strlen(pb));\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,o->field_tag,pa,pb))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_UINT16:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint16 p;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_SHORT);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==1);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&p);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,o->field_tag,p))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_UINT32:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 p;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_LONG);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==1);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&p);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,o->field_tag,p))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_C32_UINT8:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 pa;\n\t\t\t\t\t\t\t\t\tvoid* pb;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_UNDEFINED);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==TIFF_VARIABLE2);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==1);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&pa,&pb);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,o->field_tag,pa,pb))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\tassert(0);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (m=0; m<(uint32)(tif->tif_dir.td_customValueCount); m++)\n\t\t{\n\t\t\tswitch (tif->tif_dir.td_customValues[m].info->field_type)\n\t\t\t{\n\t\t\t\tcase TIFF_ASCII:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_UNDEFINED:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_BYTE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagByteArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SBYTE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSbyteArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SHORT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SSHORT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSshortArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_LONG:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SLONG:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSlongArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_LONG8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLong8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SLONG8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSlong8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_RATIONAL:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SRATIONAL:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_FLOAT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagFloatArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_DOUBLE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagDoubleArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_IFD:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagIfdArray(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_IFD8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagIfdIfd8Array(tif,&ndir,dir,tif->tif_dir.td_customValues[m].info->field_tag,tif->tif_dir.td_customValues[m].count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert(0);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (dir!=NULL)\n\t\t\tbreak;\n\t\tdir=_TIFFmalloc(ndir*sizeof(TIFFDirEntry));\n\t\tif (dir==NULL)\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Out of memory");\n\t\t\tgoto bad;\n\t\t}\n\t\tif (isimage)\n\t\t{\n\t\t\tif ((tif->tif_diroff==0)&&(!TIFFLinkDirectory(tif)))\n\t\t\t\tgoto bad;\n\t\t}\n\t\telse\n\t\t\ttif->tif_diroff=(TIFFSeekFile(tif,0,SEEK_END)+1)&(~1);\n\t\tif (pdiroff!=NULL)\n\t\t\t*pdiroff=tif->tif_diroff;\n\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\tdirsize=2+ndir*12+4;\n\t\telse\n\t\t\tdirsize=8+ndir*20+8;\n\t\ttif->tif_dataoff=tif->tif_diroff+dirsize;\n\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\ttif->tif_dataoff=(uint32)tif->tif_dataoff;\n\t\tif ((tif->tif_dataoff<tif->tif_diroff)||(tif->tif_dataoff<(uint64)dirsize))\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Maximum TIFF file size exceeded");\n\t\t\tgoto bad;\n\t\t}\n\t\tif (tif->tif_dataoff&1)\n\t\t\ttif->tif_dataoff++;\n\t\tif (isimage)\n\t\t\ttif->tif_curdir++;\n\t}\n\tif (isimage)\n\t{\n\t\tif (TIFFFieldSet(tif,FIELD_SUBIFD)&&(tif->tif_subifdoff==0))\n\t\t{\n\t\t\tuint32 na;\n\t\t\tTIFFDirEntry* nb;\n\t\t\tfor (na=0, nb=dir; ; na++, nb++)\n\t\t\t{\n\t\t\t\tassert(na<ndir);\n\t\t\t\tif (nb->tdir_tag==TIFFTAG_SUBIFD)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\t\ttif->tif_subifdoff=tif->tif_diroff+2+na*12+8;\n\t\t\telse\n\t\t\t\ttif->tif_subifdoff=tif->tif_diroff+8+na*20+12;\n\t\t}\n\t}\n\tdirmem=_TIFFmalloc(dirsize);\n\tif (dirmem==NULL)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Out of memory");\n\t\tgoto bad;\n\t}\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t{\n\t\tuint8* n;\n\t\tuint32 nTmp;\n\t\tTIFFDirEntry* o;\n\t\tn=dirmem;\n\t\t*(uint16*)n=ndir;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabShort((uint16*)n);\n\t\tn+=2;\n\t\to=dir;\n\t\tfor (m=0; m<ndir; m++)\n\t\t{\n\t\t\t*(uint16*)n=o->tdir_tag;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t*(uint16*)n=o->tdir_type;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\tnTmp = (uint32)o->tdir_count;\n\t\t\t_TIFFmemcpy(n,&nTmp,4);\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabLong((uint32*)n);\n\t\t\tn+=4;\n\t\t\t_TIFFmemcpy(n,&o->tdir_offset,4);\n\t\t\tn+=4;\n\t\t\to++;\n\t\t}\n\t\tnTmp = (uint32)tif->tif_nextdiroff;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong(&nTmp);\n\t\t_TIFFmemcpy(n,&nTmp,4);\n\t}\n\telse\n\t{\n\t\tuint8* n;\n\t\tTIFFDirEntry* o;\n\t\tn=dirmem;\n\t\t*(uint64*)n=ndir;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong8((uint64*)n);\n\t\tn+=8;\n\t\to=dir;\n\t\tfor (m=0; m<ndir; m++)\n\t\t{\n\t\t\t*(uint16*)n=o->tdir_tag;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t*(uint16*)n=o->tdir_type;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t_TIFFmemcpy(n,&o->tdir_count,8);\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabLong8((uint64*)n);\n\t\t\tn+=8;\n\t\t\t_TIFFmemcpy(n,&o->tdir_offset,8);\n\t\t\tn+=8;\n\t\t\to++;\n\t\t}\n\t\t_TIFFmemcpy(n,&tif->tif_nextdiroff,8);\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong8((uint64*)n);\n\t}\n\t_TIFFfree(dir);\n\tdir=NULL;\n\tif (!SeekOK(tif,tif->tif_diroff))\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory");\n\t\tgoto bad;\n\t}\n\tif (!WriteOK(tif,dirmem,(tmsize_t)dirsize))\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory");\n\t\tgoto bad;\n\t}\n\t_TIFFfree(dirmem);\n\tif (imagedone)\n\t{\n\t\tTIFFFreeDirectory(tif);\n\t\ttif->tif_flags &= ~TIFF_DIRTYDIRECT;\n\t\ttif->tif_flags &= ~TIFF_DIRTYSTRIP;\n\t\t(*tif->tif_cleanup)(tif);\n\t\tTIFFCreateDirectory(tif);\n\t}\n\treturn(1);\nbad:\n\tif (dir!=NULL)\n\t\t_TIFFfree(dir);\n\tif (dirmem!=NULL)\n\t\t_TIFFfree(dirmem);\n\treturn(0);\n}', 'void\nTIFFClose(TIFF* tif)\n{\n\tTIFFCloseProc closeproc = tif->tif_closeproc;\n\tthandle_t fd = tif->tif_clientdata;\n\tTIFFCleanup(tif);\n\t(void) (*closeproc)(fd);\n}', 'void\nTIFFCleanup(TIFF* tif)\n{\n\tif (tif->tif_mode != O_RDONLY)\n\t\tTIFFFlush(tif);\n\t(*tif->tif_cleanup)(tif);\n\tTIFFFreeDirectory(tif);\n\tif (tif->tif_dirlist)\n\t\t_TIFFfree(tif->tif_dirlist);\n\twhile( tif->tif_clientinfo )\n\t{\n\t\tTIFFClientInfoLink *link = tif->tif_clientinfo;\n\t\ttif->tif_clientinfo = link->next;\n\t\t_TIFFfree( link->name );\n\t\t_TIFFfree( link );\n\t}\n\tif (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))\n\t\t_TIFFfree(tif->tif_rawdata);\n\tif (isMapped(tif))\n\t\tTIFFUnmapFileContents(tif, tif->tif_base, (toff_t)tif->tif_size);\n\tif (tif->tif_fields && tif->tif_nfields > 0) {\n\t\tuint32 i;\n\t\tfor (i = 0; i < tif->tif_nfields; i++) {\n\t\t\tTIFFField *fld = tif->tif_fields[i];\n\t\t\tif (fld->field_bit == FIELD_CUSTOM &&\n\t\t\t strncmp("Tag ", fld->field_name, 4) == 0) {\n\t\t\t\t_TIFFfree(fld->field_name);\n\t\t\t\t_TIFFfree(fld);\n\t\t\t}\n\t\t}\n\t\t_TIFFfree(tif->tif_fields);\n\t}\n if (tif->tif_nfieldscompat > 0) {\n uint32 i;\n for (i = 0; i < tif->tif_nfieldscompat; i++) {\n if (tif->tif_fieldscompat[i].allocated_size)\n _TIFFfree(tif->tif_fieldscompat[i].fields);\n }\n _TIFFfree(tif->tif_fieldscompat);\n }\n\t_TIFFfree(tif);\n}', 'int\nTIFFFlush(TIFF* tif)\n{\n if( tif->tif_mode == O_RDONLY )\n return 1;\n if (!TIFFFlushData(tif))\n return (0);\n if( (tif->tif_flags & TIFF_DIRTYSTRIP)\n && !(tif->tif_flags & TIFF_DIRTYDIRECT)\n && tif->tif_mode == O_RDWR )\n {\n uint64 *offsets=NULL, *sizes=NULL;\n if( TIFFIsTiled(tif) )\n {\n if( TIFFGetField( tif, TIFFTAG_TILEOFFSETS, &offsets )\n && TIFFGetField( tif, TIFFTAG_TILEBYTECOUNTS, &sizes )\n && _TIFFRewriteField( tif, TIFFTAG_TILEOFFSETS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, offsets )\n && _TIFFRewriteField( tif, TIFFTAG_TILEBYTECOUNTS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, sizes ) )\n {\n tif->tif_flags &= ~TIFF_DIRTYSTRIP;\n tif->tif_flags &= ~TIFF_BEENWRITING;\n return 1;\n }\n }\n else\n {\n if( TIFFGetField( tif, TIFFTAG_STRIPOFFSETS, &offsets )\n && TIFFGetField( tif, TIFFTAG_STRIPBYTECOUNTS, &sizes )\n && _TIFFRewriteField( tif, TIFFTAG_STRIPOFFSETS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, offsets )\n && _TIFFRewriteField( tif, TIFFTAG_STRIPBYTECOUNTS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, sizes ) )\n {\n tif->tif_flags &= ~TIFF_DIRTYSTRIP;\n tif->tif_flags &= ~TIFF_BEENWRITING;\n return 1;\n }\n }\n }\n if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP))\n && !TIFFRewriteDirectory(tif))\n return (0);\n return (1);\n}', 'int\nTIFFRewriteDirectory( TIFF *tif )\n{\n\tstatic const char module[] = "TIFFRewriteDirectory";\n\tif( tif->tif_diroff == 0 )\n\t\treturn TIFFWriteDirectory( tif );\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t{\n\t\tif (tif->tif_header.classic.tiff_diroff == tif->tif_diroff)\n\t\t{\n\t\t\ttif->tif_header.classic.tiff_diroff = 0;\n\t\t\ttif->tif_diroff = 0;\n\t\t\tTIFFSeekFile(tif,4,SEEK_SET);\n\t\t\tif (!WriteOK(tif, &(tif->tif_header.classic.tiff_diroff),4))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t\t "Error updating TIFF header");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tuint32 nextdir;\n\t\t\tnextdir = tif->tif_header.classic.tiff_diroff;\n\t\t\twhile(1) {\n\t\t\t\tuint16 dircount;\n\t\t\t\tuint32 nextnextdir;\n\t\t\t\tif (!SeekOK(tif, nextdir) ||\n\t\t\t\t !ReadOK(tif, &dircount, 2)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory count");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabShort(&dircount);\n\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t nextdir+2+dircount*12, SEEK_SET);\n\t\t\t\tif (!ReadOK(tif, &nextnextdir, 4)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory link");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong(&nextnextdir);\n\t\t\t\tif (nextnextdir==tif->tif_diroff)\n\t\t\t\t{\n\t\t\t\t\tuint32 m;\n\t\t\t\t\tm=0;\n\t\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t\t nextdir+2+dircount*12, SEEK_SET);\n\t\t\t\t\tif (!WriteOK(tif, &m, 4)) {\n\t\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t\t "Error writing directory link");\n\t\t\t\t\t\treturn (0);\n\t\t\t\t\t}\n\t\t\t\t\ttif->tif_diroff=0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tnextdir=nextnextdir;\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tif (tif->tif_header.big.tiff_diroff == tif->tif_diroff)\n\t\t{\n\t\t\ttif->tif_header.big.tiff_diroff = 0;\n\t\t\ttif->tif_diroff = 0;\n\t\t\tTIFFSeekFile(tif,8,SEEK_SET);\n\t\t\tif (!WriteOK(tif, &(tif->tif_header.big.tiff_diroff),8))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t\t "Error updating TIFF header");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tuint64 nextdir;\n\t\t\tnextdir = tif->tif_header.big.tiff_diroff;\n\t\t\twhile(1) {\n\t\t\t\tuint64 dircount64;\n\t\t\t\tuint16 dircount;\n\t\t\t\tuint64 nextnextdir;\n\t\t\t\tif (!SeekOK(tif, nextdir) ||\n\t\t\t\t !ReadOK(tif, &dircount64, 8)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory count");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong8(&dircount64);\n\t\t\t\tif (dircount64>0xFFFF)\n\t\t\t\t{\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Sanity check on tag count failed, likely corrupt TIFF");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tdircount=(uint16)dircount64;\n\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t nextdir+8+dircount*20, SEEK_SET);\n\t\t\t\tif (!ReadOK(tif, &nextnextdir, 8)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory link");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong8(&nextnextdir);\n\t\t\t\tif (nextnextdir==tif->tif_diroff)\n\t\t\t\t{\n\t\t\t\t\tuint64 m;\n\t\t\t\t\tm=0;\n\t\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t\t nextdir+8+dircount*20, SEEK_SET);\n\t\t\t\t\tif (!WriteOK(tif, &m, 8)) {\n\t\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t\t "Error writing directory link");\n\t\t\t\t\t\treturn (0);\n\t\t\t\t\t}\n\t\t\t\t\ttif->tif_diroff=0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tnextdir=nextnextdir;\n\t\t\t}\n\t\t}\n\t}\n\treturn TIFFWriteDirectory( tif );\n}', 'static int\nTIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value)\n{\n\tstatic const char module[] = "TIFFWriteDirectoryTagSampleformatArray";\n\tvoid* conv;\n\tuint32 i;\n\tint ok;\n\tconv = _TIFFmalloc(count*sizeof(double));\n\tif (conv == NULL)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata, module, "Out of memory");\n\t\treturn (0);\n\t}\n\tswitch (tif->tif_dir.td_sampleformat)\n\t{\n\t\tcase SAMPLEFORMAT_IEEEFP:\n\t\t\tif (tif->tif_dir.td_bitspersample<=32)\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((float*)conv)[i] = (float)value[i];\n\t\t\t\tok = TIFFWriteDirectoryTagFloatArray(tif,ndir,dir,tag,count,(float*)conv);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tok = TIFFWriteDirectoryTagDoubleArray(tif,ndir,dir,tag,count,value);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SAMPLEFORMAT_INT:\n\t\t\tif (tif->tif_dir.td_bitspersample<=8)\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((int8*)conv)[i] = (int8)value[i];\n\t\t\t\tok = TIFFWriteDirectoryTagSbyteArray(tif,ndir,dir,tag,count,(int8*)conv);\n\t\t\t}\n\t\t\telse if (tif->tif_dir.td_bitspersample<=16)\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((int16*)conv)[i] = (int16)value[i];\n\t\t\t\tok = TIFFWriteDirectoryTagSshortArray(tif,ndir,dir,tag,count,(int16*)conv);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((int32*)conv)[i] = (int32)value[i];\n\t\t\t\tok = TIFFWriteDirectoryTagSlongArray(tif,ndir,dir,tag,count,(int32*)conv);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SAMPLEFORMAT_UINT:\n\t\t\tif (tif->tif_dir.td_bitspersample<=8)\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((uint8*)conv)[i] = (uint8)value[i];\n\t\t\t\tok = TIFFWriteDirectoryTagByteArray(tif,ndir,dir,tag,count,(uint8*)conv);\n\t\t\t}\n\t\t\telse if (tif->tif_dir.td_bitspersample<=16)\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((uint16*)conv)[i] = (uint16)value[i];\n\t\t\t\tok = TIFFWriteDirectoryTagShortArray(tif,ndir,dir,tag,count,(uint16*)conv);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((uint32*)conv)[i] = (uint32)value[i];\n\t\t\t\tok = TIFFWriteDirectoryTagLongArray(tif,ndir,dir,tag,count,(uint32*)conv);\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tok = 0;\n\t}\n\t_TIFFfree(conv);\n\treturn (ok);\n}', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n if (s == 0)\n return ((void *) NULL);\n\treturn (malloc((size_t) s));\n}', 'static int\nTIFFWriteDirectoryTagSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value)\n{\n\tif (dir==NULL)\n\t{\n\t\t(*ndir)++;\n\t\treturn(1);\n\t}\n\treturn(TIFFWriteDirectoryTagCheckedSlongArray(tif,ndir,dir,tag,count,value));\n}', 'static int\nTIFFWriteDirectoryTagCheckedSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value)\n{\n\tassert(count<0x40000000);\n\tassert(sizeof(int32)==4);\n\tif (tif->tif_flags&TIFF_SWAB)\n\t\tTIFFSwabArrayOfLong((uint32*)value,count);\n\treturn(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SLONG,count,count*4,value));\n}', 'void\nTIFFSwabArrayOfLong(register uint32* lp, tmsize_t n)\n{\n\tregister unsigned char *cp;\n\tregister unsigned char t;\n\tassert(sizeof(uint32)==4);\n\twhile (n-- > 0) {\n\t\tcp = (unsigned char *)lp;\n\t\tt = cp[3]; cp[3] = cp[0]; cp[0] = t;\n\t\tt = cp[2]; cp[2] = cp[1]; cp[1] = t;\n\t\tlp++;\n\t}\n}'] |
34,339 | 0 | https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L536 | int BN_set_word(BIGNUM *a, BN_ULONG w)
{
bn_check_top(a);
if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
return (0);
a->neg = 0;
a->d[0] = w;
a->top = (w ? 1 : 0);
bn_check_top(a);
return (1);
} | ['int gost2001_keygen(EC_KEY *ec)\n{\n BIGNUM *order = BN_new(), *d = BN_new();\n const EC_GROUP *group = EC_KEY_get0_group(ec);\n if (!group || !EC_GROUP_get_order(group, order, NULL)) {\n GOSTerr(GOST_F_GOST2001_KEYGEN, ERR_R_INTERNAL_ERROR);\n BN_free(d);\n BN_free(order);\n return 0;\n }\n do {\n if (!BN_rand_range(d, order)) {\n GOSTerr(GOST_F_GOST2001_KEYGEN,\n GOST_R_RANDOM_NUMBER_GENERATOR_FAILED);\n BN_free(d);\n BN_free(order);\n return 0;\n }\n }\n while (BN_is_zero(d));\n if (!EC_KEY_set_private_key(ec, d)) {\n GOSTerr(GOST_F_GOST2001_KEYGEN, ERR_R_INTERNAL_ERROR);\n BN_free(d);\n BN_free(order);\n return 0;\n }\n BN_free(d);\n BN_free(order);\n return gost2001_compute_public(ec);\n}', 'int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)\n{\n if (!BN_copy(order, group->order))\n return 0;\n return !BN_is_zero(order);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n int i;\n BN_ULONG *A;\n const BN_ULONG *B;\n bn_check_top(b);\n if (a == b)\n return (a);\n if (bn_wexpand(a, b->top) == NULL)\n return (NULL);\n#if 1\n A = a->d;\n B = b->d;\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:;\n }\n#else\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n#endif\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return (a);\n}', 'int BN_rand_range(BIGNUM *r, const BIGNUM *range)\n{\n return bn_rand_range(0, r, range);\n}', 'static int bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range)\n{\n int (*bn_rand) (BIGNUM *, int, int, int) =\n pseudo ? BN_pseudo_rand : BN_rand;\n int n;\n int count = 100;\n if (range->neg || BN_is_zero(range)) {\n BNerr(BN_F_BN_RAND_RANGE, BN_R_INVALID_RANGE);\n return 0;\n }\n n = BN_num_bits(range);\n if (n == 1)\n BN_zero(r);\n else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) {\n do {\n if (!bn_rand(r, n + 1, -1, 0))\n return 0;\n if (BN_cmp(r, range) >= 0) {\n if (!BN_sub(r, r, range))\n return 0;\n if (BN_cmp(r, range) >= 0)\n if (!BN_sub(r, r, range))\n return 0;\n }\n if (!--count) {\n BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n return 0;\n }\n }\n while (BN_cmp(r, range) >= 0);\n } else {\n do {\n if (!bn_rand(r, n, -1, 0))\n return 0;\n if (!--count) {\n BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n return 0;\n }\n }\n while (BN_cmp(r, range) >= 0);\n }\n bn_check_top(r);\n return 1;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}'] |
34,340 | 0 | https://github.com/libav/libav/blob/af2faf2076b96ab85cc51d5e970574079373c396/libswscale/swscale.c/#L1062 | static void yuv2packedX_c(SwsContext *c, const int16_t *lumFilter,
const int16_t **lumSrc, int lumFilterSize,
const int16_t *chrFilter, const int16_t **chrUSrc,
const int16_t **chrVSrc, int chrFilterSize,
const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
{
int i;
YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGBX_C)
} | ['static void yuv2packedX_c(SwsContext *c, const int16_t *lumFilter,\n const int16_t **lumSrc, int lumFilterSize,\n const int16_t *chrFilter, const int16_t **chrUSrc,\n const int16_t **chrVSrc, int chrFilterSize,\n const int16_t **alpSrc, uint8_t *dest, int dstW, int y)\n{\n int i;\n YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGBX_C)\n}'] |
34,341 | 0 | https://github.com/libav/libav/blob/a1c1c7801918c46da5525cfddb99f3467c522b02/libavformat/rtsp.c/#L904 | static int
rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
{
RTSPState *rt = s->priv_data;
AVStream *st = NULL;
if (rtsp_st->stream_index >= 0)
st = s->streams[rtsp_st->stream_index];
if (!st)
s->ctx_flags |= AVFMTCTX_NOHEADER;
if (rt->transport == RTSP_TRANSPORT_RDT)
rtsp_st->tx_ctx = ff_rdt_parse_open(s, st->index,
rtsp_st->dynamic_protocol_context,
rtsp_st->dynamic_handler);
else
rtsp_st->tx_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle,
rtsp_st->sdp_payload_type,
&rtsp_st->rtp_payload_data);
if (!rtsp_st->tx_ctx) {
return AVERROR(ENOMEM);
} else if (rt->transport != RTSP_TRANSPORT_RDT) {
if(rtsp_st->dynamic_handler) {
rtp_parse_set_dynamic_protocol(rtsp_st->tx_ctx,
rtsp_st->dynamic_protocol_context,
rtsp_st->dynamic_handler);
}
}
return 0;
} | ['static int\nrtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)\n{\n RTSPState *rt = s->priv_data;\n AVStream *st = NULL;\n if (rtsp_st->stream_index >= 0)\n st = s->streams[rtsp_st->stream_index];\n if (!st)\n s->ctx_flags |= AVFMTCTX_NOHEADER;\n if (rt->transport == RTSP_TRANSPORT_RDT)\n rtsp_st->tx_ctx = ff_rdt_parse_open(s, st->index,\n rtsp_st->dynamic_protocol_context,\n rtsp_st->dynamic_handler);\n else\n rtsp_st->tx_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle,\n rtsp_st->sdp_payload_type,\n &rtsp_st->rtp_payload_data);\n if (!rtsp_st->tx_ctx) {\n return AVERROR(ENOMEM);\n } else if (rt->transport != RTSP_TRANSPORT_RDT) {\n if(rtsp_st->dynamic_handler) {\n rtp_parse_set_dynamic_protocol(rtsp_st->tx_ctx,\n rtsp_st->dynamic_protocol_context,\n rtsp_st->dynamic_handler);\n }\n }\n return 0;\n}'] |
34,342 | 0 | https://github.com/openssl/openssl/blob/55442b8a5b719f54578083fae0fcc814b599cd84/crypto/bn/bn_lib.c/#L295 | BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
bn_check_top(b);
if (a == b)
return a;
if (bn_wexpand(a, b->top) == NULL)
return NULL;
if (b->top > 0)
memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
a->top = b->top;
a->neg = b->neg;
bn_check_top(a);
return a;
} | ['static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)\n{\n BIGNUM *kinv = NULL;\n BIGNUM *m;\n BIGNUM *xr;\n BN_CTX *ctx = NULL;\n int reason = ERR_R_BN_LIB;\n DSA_SIG *ret = NULL;\n int rv = 0;\n m = BN_new();\n xr = BN_new();\n if (m == NULL || xr == NULL)\n goto err;\n if (!dsa->p || !dsa->q || !dsa->g) {\n reason = DSA_R_MISSING_PARAMETERS;\n goto err;\n }\n ret = DSA_SIG_new();\n if (ret == NULL)\n goto err;\n ret->r = BN_new();\n ret->s = BN_new();\n if (ret->r == NULL || ret->s == NULL)\n goto err;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n redo:\n if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen))\n goto err;\n if (dlen > BN_num_bytes(dsa->q))\n dlen = BN_num_bytes(dsa->q);\n if (BN_bin2bn(dgst, dlen, m) == NULL)\n goto err;\n if (!BN_mod_mul(xr, dsa->priv_key, ret->r, dsa->q, ctx))\n goto err;\n if (!BN_add(ret->s, xr, m))\n goto err;\n if (BN_cmp(ret->s, dsa->q) > 0)\n if (!BN_sub(ret->s, ret->s, dsa->q))\n goto err;\n if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->q, ctx))\n goto err;\n if (BN_is_zero(ret->r) || BN_is_zero(ret->s))\n goto redo;\n rv = 1;\n err:\n if (rv == 0) {\n DSAerr(DSA_F_DSA_DO_SIGN, reason);\n DSA_SIG_free(ret);\n ret = NULL;\n }\n BN_CTX_free(ctx);\n BN_clear_free(m);\n BN_clear_free(xr);\n BN_clear_free(kinv);\n return ret;\n}', 'static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,\n BIGNUM **kinvp, BIGNUM **rp,\n const unsigned char *dgst, int dlen)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *k, *kinv = NULL, *r = *rp;\n BIGNUM *l, *m;\n int ret = 0;\n int q_bits;\n if (!dsa->p || !dsa->q || !dsa->g) {\n DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS);\n return 0;\n }\n k = BN_new();\n l = BN_new();\n m = BN_new();\n if (k == NULL || l == NULL || m == NULL)\n goto err;\n if (ctx_in == NULL) {\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n } else\n ctx = ctx_in;\n q_bits = BN_num_bits(dsa->q);\n if (!BN_set_bit(k, q_bits)\n || !BN_set_bit(l, q_bits)\n || !BN_set_bit(m, q_bits))\n goto err;\n do {\n if (dgst != NULL) {\n if (!BN_generate_dsa_nonce(k, dsa->q, dsa->priv_key, dgst,\n dlen, ctx))\n goto err;\n } else if (!BN_priv_rand_range(k, dsa->q))\n goto err;\n } while (BN_is_zero(k));\n BN_set_flags(k, BN_FLG_CONSTTIME);\n if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n dsa->lock, dsa->p, ctx))\n goto err;\n }\n if (!BN_add(l, k, dsa->q)\n || !BN_add(m, l, dsa->q)\n || !BN_copy(k, BN_num_bits(l) > q_bits ? l : m))\n goto err;\n if ((dsa)->meth->bn_mod_exp != NULL) {\n if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx,\n dsa->method_mont_p))\n goto err;\n } else {\n if (!BN_mod_exp_mont(r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p))\n goto err;\n }\n if (!BN_mod(r, r, dsa->q, ctx))\n goto err;\n if ((kinv = BN_mod_inverse(NULL, k, dsa->q, ctx)) == NULL)\n goto err;\n BN_clear_free(*kinvp);\n *kinvp = kinv;\n kinv = NULL;\n ret = 1;\n err:\n if (!ret)\n DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n BN_clear_free(k);\n BN_clear_free(l);\n BN_clear_free(m);\n return ret;\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (BN_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n bn_correct_top(r);\n } else\n#endif\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}'] |
34,343 | 0 | https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/apps/speed.c/#L1608 | int MAIN(int argc, char **argv)
{
unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
unsigned char *buf = NULL, *buf2 = NULL;
int mret = 1;
long count = 0, save_count = 0;
int i, j, k;
# if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
long rsa_count;
# endif
# ifndef OPENSSL_NO_RSA
unsigned rsa_num;
# endif
unsigned char md[EVP_MAX_MD_SIZE];
# ifndef OPENSSL_NO_MD2
unsigned char md2[MD2_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_MDC2
unsigned char mdc2[MDC2_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_MD4
unsigned char md4[MD4_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_MD5
unsigned char md5[MD5_DIGEST_LENGTH];
unsigned char hmac[MD5_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_SHA
unsigned char sha[SHA_DIGEST_LENGTH];
# ifndef OPENSSL_NO_SHA256
unsigned char sha256[SHA256_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_SHA512
unsigned char sha512[SHA512_DIGEST_LENGTH];
# endif
# endif
# ifndef OPENSSL_NO_WHIRLPOOL
unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_RMD160
unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_RC4
RC4_KEY rc4_ks;
# endif
# ifndef OPENSSL_NO_RC5
RC5_32_KEY rc5_ks;
# endif
# ifndef OPENSSL_NO_RC2
RC2_KEY rc2_ks;
# endif
# ifndef OPENSSL_NO_IDEA
IDEA_KEY_SCHEDULE idea_ks;
# endif
# ifndef OPENSSL_NO_SEED
SEED_KEY_SCHEDULE seed_ks;
# endif
# ifndef OPENSSL_NO_BF
BF_KEY bf_ks;
# endif
# ifndef OPENSSL_NO_CAST
CAST_KEY cast_ks;
# endif
static const unsigned char key16[16] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
};
# ifndef OPENSSL_NO_AES
static const unsigned char key24[24] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
};
static const unsigned char key32[32] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
};
# endif
# ifndef OPENSSL_NO_CAMELLIA
static const unsigned char ckey24[24] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
};
static const unsigned char ckey32[32] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
};
# endif
# ifndef OPENSSL_NO_AES
# define MAX_BLOCK_SIZE 128
# else
# define MAX_BLOCK_SIZE 64
# endif
unsigned char DES_iv[8];
unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
# ifndef OPENSSL_NO_DES
static DES_cblock key =
{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
static DES_cblock key2 =
{ 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
static DES_cblock key3 =
{ 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
DES_key_schedule sch;
DES_key_schedule sch2;
DES_key_schedule sch3;
# endif
# ifndef OPENSSL_NO_AES
AES_KEY aes_ks1, aes_ks2, aes_ks3;
# endif
# ifndef OPENSSL_NO_CAMELLIA
CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
# endif
# define D_MD2 0
# define D_MDC2 1
# define D_MD4 2
# define D_MD5 3
# define D_HMAC 4
# define D_SHA1 5
# define D_RMD160 6
# define D_RC4 7
# define D_CBC_DES 8
# define D_EDE3_DES 9
# define D_CBC_IDEA 10
# define D_CBC_SEED 11
# define D_CBC_RC2 12
# define D_CBC_RC5 13
# define D_CBC_BF 14
# define D_CBC_CAST 15
# define D_CBC_128_AES 16
# define D_CBC_192_AES 17
# define D_CBC_256_AES 18
# define D_CBC_128_CML 19
# define D_CBC_192_CML 20
# define D_CBC_256_CML 21
# define D_EVP 22
# define D_SHA256 23
# define D_SHA512 24
# define D_WHIRLPOOL 25
# define D_IGE_128_AES 26
# define D_IGE_192_AES 27
# define D_IGE_256_AES 28
# define D_GHASH 29
double d = 0.0;
long c[ALGOR_NUM][SIZE_NUM];
# ifndef OPENSSL_SYS_WIN32
# endif
# define R_DSA_512 0
# define R_DSA_1024 1
# define R_DSA_2048 2
# define R_RSA_512 0
# define R_RSA_1024 1
# define R_RSA_2048 2
# define R_RSA_3072 3
# define R_RSA_4096 4
# define R_RSA_7680 5
# define R_RSA_15360 6
# define R_EC_P160 0
# define R_EC_P192 1
# define R_EC_P224 2
# define R_EC_P256 3
# define R_EC_P384 4
# define R_EC_P521 5
# define R_EC_K163 6
# define R_EC_K233 7
# define R_EC_K283 8
# define R_EC_K409 9
# define R_EC_K571 10
# define R_EC_B163 11
# define R_EC_B233 12
# define R_EC_B283 13
# define R_EC_B409 14
# define R_EC_B571 15
# ifndef OPENSSL_NO_RSA
RSA *rsa_key[RSA_NUM];
long rsa_c[RSA_NUM][2];
static unsigned int rsa_bits[RSA_NUM] = {
512, 1024, 2048, 3072, 4096, 7680, 15360
};
static unsigned char *rsa_data[RSA_NUM] = {
test512, test1024, test2048, test3072, test4096, test7680, test15360
};
static int rsa_data_length[RSA_NUM] = {
sizeof(test512), sizeof(test1024),
sizeof(test2048), sizeof(test3072),
sizeof(test4096), sizeof(test7680),
sizeof(test15360)
};
# endif
# ifndef OPENSSL_NO_DSA
DSA *dsa_key[DSA_NUM];
long dsa_c[DSA_NUM][2];
static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
# endif
# ifndef OPENSSL_NO_EC
static unsigned int test_curves[EC_NUM] = {
NID_secp160r1,
NID_X9_62_prime192v1,
NID_secp224r1,
NID_X9_62_prime256v1,
NID_secp384r1,
NID_secp521r1,
NID_sect163k1,
NID_sect233k1,
NID_sect283k1,
NID_sect409k1,
NID_sect571k1,
NID_sect163r2,
NID_sect233r1,
NID_sect283r1,
NID_sect409r1,
NID_sect571r1
};
static const char *test_curves_names[EC_NUM] = {
"secp160r1",
"nistp192",
"nistp224",
"nistp256",
"nistp384",
"nistp521",
"nistk163",
"nistk233",
"nistk283",
"nistk409",
"nistk571",
"nistb163",
"nistb233",
"nistb283",
"nistb409",
"nistb571"
};
static int test_curves_bits[EC_NUM] = {
160, 192, 224, 256, 384, 521,
163, 233, 283, 409, 571,
163, 233, 283, 409, 571
};
# endif
# ifndef OPENSSL_NO_ECDSA
unsigned char ecdsasig[256];
unsigned int ecdsasiglen;
EC_KEY *ecdsa[EC_NUM];
long ecdsa_c[EC_NUM][2];
# endif
# ifndef OPENSSL_NO_ECDH
EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
int secret_size_a, secret_size_b;
int ecdh_checks = 0;
int secret_idx = 0;
long ecdh_c[EC_NUM][2];
# endif
int rsa_doit[RSA_NUM];
int dsa_doit[DSA_NUM];
# ifndef OPENSSL_NO_ECDSA
int ecdsa_doit[EC_NUM];
# endif
# ifndef OPENSSL_NO_ECDH
int ecdh_doit[EC_NUM];
# endif
int doit[ALGOR_NUM];
int pr_header = 0;
const EVP_CIPHER *evp_cipher = NULL;
const EVP_MD *evp_md = NULL;
int decrypt = 0;
# ifndef NO_FORK
int multi = 0;
# endif
int multiblock = 0;
int misalign = MAX_MISALIGNMENT + 1;
# ifndef TIMES
usertime = -1;
# endif
apps_startup();
memset(results, 0, sizeof(results));
# ifndef OPENSSL_NO_DSA
memset(dsa_key, 0, sizeof(dsa_key));
# endif
# ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
ecdsa[i] = NULL;
# endif
# ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++) {
ecdh_a[i] = NULL;
ecdh_b[i] = NULL;
}
# endif
if (bio_err == NULL)
if ((bio_err = BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
# ifndef OPENSSL_NO_RSA
memset(rsa_key, 0, sizeof(rsa_key));
for (i = 0; i < RSA_NUM; i++)
rsa_key[i] = NULL;
# endif
if ((buf_malloc =
(unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
BIO_printf(bio_err, "out of memory\n");
goto end;
}
if ((buf2_malloc =
(unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
BIO_printf(bio_err, "out of memory\n");
goto end;
}
misalign = 0;
buf = buf_malloc;
buf2 = buf2_malloc;
memset(c, 0, sizeof(c));
memset(DES_iv, 0, sizeof(DES_iv));
memset(iv, 0, sizeof(iv));
for (i = 0; i < ALGOR_NUM; i++)
doit[i] = 0;
for (i = 0; i < RSA_NUM; i++)
rsa_doit[i] = 0;
for (i = 0; i < DSA_NUM; i++)
dsa_doit[i] = 0;
# ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
ecdsa_doit[i] = 0;
# endif
# ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++)
ecdh_doit[i] = 0;
# endif
j = 0;
argc--;
argv++;
while (argc) {
if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
usertime = 0;
j--;
} else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no EVP given\n");
goto end;
}
evp_cipher = EVP_get_cipherbyname(*argv);
if (!evp_cipher) {
evp_md = EVP_get_digestbyname(*argv);
}
if (!evp_cipher && !evp_md) {
BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
*argv);
goto end;
}
doit[D_EVP] = 1;
} else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
decrypt = 1;
j--;
}
# ifndef OPENSSL_NO_ENGINE
else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no engine given\n");
goto end;
}
setup_engine(bio_err, *argv, 0);
j--;
}
# endif
# ifndef NO_FORK
else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no multi count given\n");
goto end;
}
multi = atoi(argv[0]);
if (multi <= 0) {
BIO_printf(bio_err, "bad multi count\n");
goto end;
}
j--;
}
# endif
else if (argc > 0 && !strcmp(*argv, "-mr")) {
mr = 1;
j--;
} else if (argc > 0 && !strcmp(*argv, "-mb")) {
multiblock = 1;
j--;
} else if (argc > 0 && !strcmp(*argv, "-misalign")) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no misalignment given\n");
goto end;
}
misalign = atoi(argv[0]);
if (misalign < 0 || misalign > MAX_MISALIGNMENT) {
BIO_printf(bio_err,
"misalignment is outsize permitted range 0-%d\n",
MAX_MISALIGNMENT);
goto end;
}
buf = buf_malloc + misalign;
buf2 = buf2_malloc + misalign;
j--;
} else
# ifndef OPENSSL_NO_MD2
if (strcmp(*argv, "md2") == 0)
doit[D_MD2] = 1;
else
# endif
# ifndef OPENSSL_NO_MDC2
if (strcmp(*argv, "mdc2") == 0)
doit[D_MDC2] = 1;
else
# endif
# ifndef OPENSSL_NO_MD4
if (strcmp(*argv, "md4") == 0)
doit[D_MD4] = 1;
else
# endif
# ifndef OPENSSL_NO_MD5
if (strcmp(*argv, "md5") == 0)
doit[D_MD5] = 1;
else
# endif
# ifndef OPENSSL_NO_MD5
if (strcmp(*argv, "hmac") == 0)
doit[D_HMAC] = 1;
else
# endif
# ifndef OPENSSL_NO_SHA
if (strcmp(*argv, "sha1") == 0)
doit[D_SHA1] = 1;
else if (strcmp(*argv, "sha") == 0)
doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
else
# ifndef OPENSSL_NO_SHA256
if (strcmp(*argv, "sha256") == 0)
doit[D_SHA256] = 1;
else
# endif
# ifndef OPENSSL_NO_SHA512
if (strcmp(*argv, "sha512") == 0)
doit[D_SHA512] = 1;
else
# endif
# endif
# ifndef OPENSSL_NO_WHIRLPOOL
if (strcmp(*argv, "whirlpool") == 0)
doit[D_WHIRLPOOL] = 1;
else
# endif
# ifndef OPENSSL_NO_RMD160
if (strcmp(*argv, "ripemd") == 0)
doit[D_RMD160] = 1;
else if (strcmp(*argv, "rmd160") == 0)
doit[D_RMD160] = 1;
else if (strcmp(*argv, "ripemd160") == 0)
doit[D_RMD160] = 1;
else
# endif
# ifndef OPENSSL_NO_RC4
if (strcmp(*argv, "rc4") == 0)
doit[D_RC4] = 1;
else
# endif
# ifndef OPENSSL_NO_DES
if (strcmp(*argv, "des-cbc") == 0)
doit[D_CBC_DES] = 1;
else if (strcmp(*argv, "des-ede3") == 0)
doit[D_EDE3_DES] = 1;
else
# endif
# ifndef OPENSSL_NO_AES
if (strcmp(*argv, "aes-128-cbc") == 0)
doit[D_CBC_128_AES] = 1;
else if (strcmp(*argv, "aes-192-cbc") == 0)
doit[D_CBC_192_AES] = 1;
else if (strcmp(*argv, "aes-256-cbc") == 0)
doit[D_CBC_256_AES] = 1;
else if (strcmp(*argv, "aes-128-ige") == 0)
doit[D_IGE_128_AES] = 1;
else if (strcmp(*argv, "aes-192-ige") == 0)
doit[D_IGE_192_AES] = 1;
else if (strcmp(*argv, "aes-256-ige") == 0)
doit[D_IGE_256_AES] = 1;
else
# endif
# ifndef OPENSSL_NO_CAMELLIA
if (strcmp(*argv, "camellia-128-cbc") == 0)
doit[D_CBC_128_CML] = 1;
else if (strcmp(*argv, "camellia-192-cbc") == 0)
doit[D_CBC_192_CML] = 1;
else if (strcmp(*argv, "camellia-256-cbc") == 0)
doit[D_CBC_256_CML] = 1;
else
# endif
# ifndef OPENSSL_NO_RSA
# if 0
if (strcmp(*argv, "rsaref") == 0) {
RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
j--;
} else
# endif
# ifndef RSA_NULL
if (strcmp(*argv, "openssl") == 0) {
RSA_set_default_method(RSA_PKCS1_SSLeay());
j--;
} else
# endif
# endif
if (strcmp(*argv, "dsa512") == 0)
dsa_doit[R_DSA_512] = 2;
else if (strcmp(*argv, "dsa1024") == 0)
dsa_doit[R_DSA_1024] = 2;
else if (strcmp(*argv, "dsa2048") == 0)
dsa_doit[R_DSA_2048] = 2;
else if (strcmp(*argv, "rsa512") == 0)
rsa_doit[R_RSA_512] = 2;
else if (strcmp(*argv, "rsa1024") == 0)
rsa_doit[R_RSA_1024] = 2;
else if (strcmp(*argv, "rsa2048") == 0)
rsa_doit[R_RSA_2048] = 2;
else if (strcmp(*argv, "rsa3072") == 0)
rsa_doit[R_RSA_3072] = 2;
else if (strcmp(*argv, "rsa4096") == 0)
rsa_doit[R_RSA_4096] = 2;
else if (strcmp(*argv, "rsa7680") == 0)
rsa_doit[R_RSA_7680] = 2;
else if (strcmp(*argv, "rsa15360") == 0)
rsa_doit[R_RSA_15360] = 2;
else
# ifndef OPENSSL_NO_RC2
if (strcmp(*argv, "rc2-cbc") == 0)
doit[D_CBC_RC2] = 1;
else if (strcmp(*argv, "rc2") == 0)
doit[D_CBC_RC2] = 1;
else
# endif
# ifndef OPENSSL_NO_RC5
if (strcmp(*argv, "rc5-cbc") == 0)
doit[D_CBC_RC5] = 1;
else if (strcmp(*argv, "rc5") == 0)
doit[D_CBC_RC5] = 1;
else
# endif
# ifndef OPENSSL_NO_IDEA
if (strcmp(*argv, "idea-cbc") == 0)
doit[D_CBC_IDEA] = 1;
else if (strcmp(*argv, "idea") == 0)
doit[D_CBC_IDEA] = 1;
else
# endif
# ifndef OPENSSL_NO_SEED
if (strcmp(*argv, "seed-cbc") == 0)
doit[D_CBC_SEED] = 1;
else if (strcmp(*argv, "seed") == 0)
doit[D_CBC_SEED] = 1;
else
# endif
# ifndef OPENSSL_NO_BF
if (strcmp(*argv, "bf-cbc") == 0)
doit[D_CBC_BF] = 1;
else if (strcmp(*argv, "blowfish") == 0)
doit[D_CBC_BF] = 1;
else if (strcmp(*argv, "bf") == 0)
doit[D_CBC_BF] = 1;
else
# endif
# ifndef OPENSSL_NO_CAST
if (strcmp(*argv, "cast-cbc") == 0)
doit[D_CBC_CAST] = 1;
else if (strcmp(*argv, "cast") == 0)
doit[D_CBC_CAST] = 1;
else if (strcmp(*argv, "cast5") == 0)
doit[D_CBC_CAST] = 1;
else
# endif
# ifndef OPENSSL_NO_DES
if (strcmp(*argv, "des") == 0) {
doit[D_CBC_DES] = 1;
doit[D_EDE3_DES] = 1;
} else
# endif
# ifndef OPENSSL_NO_AES
if (strcmp(*argv, "aes") == 0) {
doit[D_CBC_128_AES] = 1;
doit[D_CBC_192_AES] = 1;
doit[D_CBC_256_AES] = 1;
} else if (strcmp(*argv, "ghash") == 0) {
doit[D_GHASH] = 1;
} else
# endif
# ifndef OPENSSL_NO_CAMELLIA
if (strcmp(*argv, "camellia") == 0) {
doit[D_CBC_128_CML] = 1;
doit[D_CBC_192_CML] = 1;
doit[D_CBC_256_CML] = 1;
} else
# endif
# ifndef OPENSSL_NO_RSA
if (strcmp(*argv, "rsa") == 0) {
rsa_doit[R_RSA_512] = 1;
rsa_doit[R_RSA_1024] = 1;
rsa_doit[R_RSA_2048] = 1;
rsa_doit[R_RSA_3072] = 1;
rsa_doit[R_RSA_4096] = 1;
rsa_doit[R_RSA_7680] = 1;
rsa_doit[R_RSA_15360] = 1;
} else
# endif
# ifndef OPENSSL_NO_DSA
if (strcmp(*argv, "dsa") == 0) {
dsa_doit[R_DSA_512] = 1;
dsa_doit[R_DSA_1024] = 1;
dsa_doit[R_DSA_2048] = 1;
} else
# endif
# ifndef OPENSSL_NO_ECDSA
if (strcmp(*argv, "ecdsap160") == 0)
ecdsa_doit[R_EC_P160] = 2;
else if (strcmp(*argv, "ecdsap192") == 0)
ecdsa_doit[R_EC_P192] = 2;
else if (strcmp(*argv, "ecdsap224") == 0)
ecdsa_doit[R_EC_P224] = 2;
else if (strcmp(*argv, "ecdsap256") == 0)
ecdsa_doit[R_EC_P256] = 2;
else if (strcmp(*argv, "ecdsap384") == 0)
ecdsa_doit[R_EC_P384] = 2;
else if (strcmp(*argv, "ecdsap521") == 0)
ecdsa_doit[R_EC_P521] = 2;
else if (strcmp(*argv, "ecdsak163") == 0)
ecdsa_doit[R_EC_K163] = 2;
else if (strcmp(*argv, "ecdsak233") == 0)
ecdsa_doit[R_EC_K233] = 2;
else if (strcmp(*argv, "ecdsak283") == 0)
ecdsa_doit[R_EC_K283] = 2;
else if (strcmp(*argv, "ecdsak409") == 0)
ecdsa_doit[R_EC_K409] = 2;
else if (strcmp(*argv, "ecdsak571") == 0)
ecdsa_doit[R_EC_K571] = 2;
else if (strcmp(*argv, "ecdsab163") == 0)
ecdsa_doit[R_EC_B163] = 2;
else if (strcmp(*argv, "ecdsab233") == 0)
ecdsa_doit[R_EC_B233] = 2;
else if (strcmp(*argv, "ecdsab283") == 0)
ecdsa_doit[R_EC_B283] = 2;
else if (strcmp(*argv, "ecdsab409") == 0)
ecdsa_doit[R_EC_B409] = 2;
else if (strcmp(*argv, "ecdsab571") == 0)
ecdsa_doit[R_EC_B571] = 2;
else if (strcmp(*argv, "ecdsa") == 0) {
for (i = 0; i < EC_NUM; i++)
ecdsa_doit[i] = 1;
} else
# endif
# ifndef OPENSSL_NO_ECDH
if (strcmp(*argv, "ecdhp160") == 0)
ecdh_doit[R_EC_P160] = 2;
else if (strcmp(*argv, "ecdhp192") == 0)
ecdh_doit[R_EC_P192] = 2;
else if (strcmp(*argv, "ecdhp224") == 0)
ecdh_doit[R_EC_P224] = 2;
else if (strcmp(*argv, "ecdhp256") == 0)
ecdh_doit[R_EC_P256] = 2;
else if (strcmp(*argv, "ecdhp384") == 0)
ecdh_doit[R_EC_P384] = 2;
else if (strcmp(*argv, "ecdhp521") == 0)
ecdh_doit[R_EC_P521] = 2;
else if (strcmp(*argv, "ecdhk163") == 0)
ecdh_doit[R_EC_K163] = 2;
else if (strcmp(*argv, "ecdhk233") == 0)
ecdh_doit[R_EC_K233] = 2;
else if (strcmp(*argv, "ecdhk283") == 0)
ecdh_doit[R_EC_K283] = 2;
else if (strcmp(*argv, "ecdhk409") == 0)
ecdh_doit[R_EC_K409] = 2;
else if (strcmp(*argv, "ecdhk571") == 0)
ecdh_doit[R_EC_K571] = 2;
else if (strcmp(*argv, "ecdhb163") == 0)
ecdh_doit[R_EC_B163] = 2;
else if (strcmp(*argv, "ecdhb233") == 0)
ecdh_doit[R_EC_B233] = 2;
else if (strcmp(*argv, "ecdhb283") == 0)
ecdh_doit[R_EC_B283] = 2;
else if (strcmp(*argv, "ecdhb409") == 0)
ecdh_doit[R_EC_B409] = 2;
else if (strcmp(*argv, "ecdhb571") == 0)
ecdh_doit[R_EC_B571] = 2;
else if (strcmp(*argv, "ecdh") == 0) {
for (i = 0; i < EC_NUM; i++)
ecdh_doit[i] = 1;
} else
# endif
{
BIO_printf(bio_err, "Error: bad option or value\n");
BIO_printf(bio_err, "\n");
BIO_printf(bio_err, "Available values:\n");
# ifndef OPENSSL_NO_MD2
BIO_printf(bio_err, "md2 ");
# endif
# ifndef OPENSSL_NO_MDC2
BIO_printf(bio_err, "mdc2 ");
# endif
# ifndef OPENSSL_NO_MD4
BIO_printf(bio_err, "md4 ");
# endif
# ifndef OPENSSL_NO_MD5
BIO_printf(bio_err, "md5 ");
# ifndef OPENSSL_NO_HMAC
BIO_printf(bio_err, "hmac ");
# endif
# endif
# ifndef OPENSSL_NO_SHA1
BIO_printf(bio_err, "sha1 ");
# endif
# ifndef OPENSSL_NO_SHA256
BIO_printf(bio_err, "sha256 ");
# endif
# ifndef OPENSSL_NO_SHA512
BIO_printf(bio_err, "sha512 ");
# endif
# ifndef OPENSSL_NO_WHIRLPOOL
BIO_printf(bio_err, "whirlpool");
# endif
# ifndef OPENSSL_NO_RMD160
BIO_printf(bio_err, "rmd160");
# endif
# if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
!defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
!defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \
!defined(OPENSSL_NO_WHIRLPOOL)
BIO_printf(bio_err, "\n");
# endif
# ifndef OPENSSL_NO_IDEA
BIO_printf(bio_err, "idea-cbc ");
# endif
# ifndef OPENSSL_NO_SEED
BIO_printf(bio_err, "seed-cbc ");
# endif
# ifndef OPENSSL_NO_RC2
BIO_printf(bio_err, "rc2-cbc ");
# endif
# ifndef OPENSSL_NO_RC5
BIO_printf(bio_err, "rc5-cbc ");
# endif
# ifndef OPENSSL_NO_BF
BIO_printf(bio_err, "bf-cbc");
# endif
# if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
!defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
BIO_printf(bio_err, "\n");
# endif
# ifndef OPENSSL_NO_DES
BIO_printf(bio_err, "des-cbc des-ede3 ");
# endif
# ifndef OPENSSL_NO_AES
BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
# endif
# ifndef OPENSSL_NO_CAMELLIA
BIO_printf(bio_err, "\n");
BIO_printf(bio_err,
"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
# endif
# ifndef OPENSSL_NO_RC4
BIO_printf(bio_err, "rc4");
# endif
BIO_printf(bio_err, "\n");
# ifndef OPENSSL_NO_RSA
BIO_printf(bio_err,
"rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
BIO_printf(bio_err, "rsa7680 rsa15360\n");
# endif
# ifndef OPENSSL_NO_DSA
BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
# endif
# ifndef OPENSSL_NO_ECDSA
BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
"ecdsap256 ecdsap384 ecdsap521\n");
BIO_printf(bio_err,
"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
BIO_printf(bio_err,
"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
BIO_printf(bio_err, "ecdsa\n");
# endif
# ifndef OPENSSL_NO_ECDH
BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
"ecdhp256 ecdhp384 ecdhp521\n");
BIO_printf(bio_err,
"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
BIO_printf(bio_err,
"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
BIO_printf(bio_err, "ecdh\n");
# endif
# ifndef OPENSSL_NO_IDEA
BIO_printf(bio_err, "idea ");
# endif
# ifndef OPENSSL_NO_SEED
BIO_printf(bio_err, "seed ");
# endif
# ifndef OPENSSL_NO_RC2
BIO_printf(bio_err, "rc2 ");
# endif
# ifndef OPENSSL_NO_DES
BIO_printf(bio_err, "des ");
# endif
# ifndef OPENSSL_NO_AES
BIO_printf(bio_err, "aes ");
# endif
# ifndef OPENSSL_NO_CAMELLIA
BIO_printf(bio_err, "camellia ");
# endif
# ifndef OPENSSL_NO_RSA
BIO_printf(bio_err, "rsa ");
# endif
# ifndef OPENSSL_NO_BF
BIO_printf(bio_err, "blowfish");
# endif
# if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
!defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
!defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
!defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
BIO_printf(bio_err, "\n");
# endif
BIO_printf(bio_err, "\n");
BIO_printf(bio_err, "Available options:\n");
# if defined(TIMES) || defined(USE_TOD)
BIO_printf(bio_err, "-elapsed "
"measure time in real time instead of CPU user time.\n");
# endif
# ifndef OPENSSL_NO_ENGINE
BIO_printf(bio_err,
"-engine e "
"use engine e, possibly a hardware device.\n");
# endif
BIO_printf(bio_err, "-evp e " "use EVP e.\n");
BIO_printf(bio_err,
"-decrypt "
"time decryption instead of encryption (only EVP).\n");
BIO_printf(bio_err,
"-mr "
"produce machine readable output.\n");
BIO_printf(bio_err,
"-mb "
"perform multi-block benchmark (for specific ciphers)\n");
BIO_printf(bio_err,
"-misalign n "
"perform benchmark with misaligned data\n");
# ifndef NO_FORK
BIO_printf(bio_err,
"-multi n " "run n benchmarks in parallel.\n");
# endif
goto end;
}
argc--;
argv++;
j++;
}
# ifndef NO_FORK
if (multi && do_multi(multi))
goto show_res;
# endif
if (j == 0) {
for (i = 0; i < ALGOR_NUM; i++) {
if (i != D_EVP)
doit[i] = 1;
}
for (i = 0; i < RSA_NUM; i++)
rsa_doit[i] = 1;
for (i = 0; i < DSA_NUM; i++)
dsa_doit[i] = 1;
# ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
ecdsa_doit[i] = 1;
# endif
# ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++)
ecdh_doit[i] = 1;
# endif
}
for (i = 0; i < ALGOR_NUM; i++)
if (doit[i])
pr_header++;
if (usertime == 0 && !mr)
BIO_printf(bio_err,
"You have chosen to measure elapsed time "
"instead of user CPU time.\n");
# ifndef OPENSSL_NO_RSA
for (i = 0; i < RSA_NUM; i++) {
const unsigned char *p;
p = rsa_data[i];
rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
if (rsa_key[i] == NULL) {
BIO_printf(bio_err, "internal error loading RSA key number %d\n",
i);
goto end;
}
# if 0
else {
BIO_printf(bio_err,
mr ? "+RK:%d:"
: "Loaded RSA key, %d bit modulus and e= 0x",
BN_num_bits(rsa_key[i]->n));
BN_print(bio_err, rsa_key[i]->e);
BIO_printf(bio_err, "\n");
}
# endif
}
# endif
# ifndef OPENSSL_NO_DSA
dsa_key[0] = get_dsa512();
dsa_key[1] = get_dsa1024();
dsa_key[2] = get_dsa2048();
# endif
# ifndef OPENSSL_NO_DES
DES_set_key_unchecked(&key, &sch);
DES_set_key_unchecked(&key2, &sch2);
DES_set_key_unchecked(&key3, &sch3);
# endif
# ifndef OPENSSL_NO_AES
AES_set_encrypt_key(key16, 128, &aes_ks1);
AES_set_encrypt_key(key24, 192, &aes_ks2);
AES_set_encrypt_key(key32, 256, &aes_ks3);
# endif
# ifndef OPENSSL_NO_CAMELLIA
Camellia_set_key(key16, 128, &camellia_ks1);
Camellia_set_key(ckey24, 192, &camellia_ks2);
Camellia_set_key(ckey32, 256, &camellia_ks3);
# endif
# ifndef OPENSSL_NO_IDEA
idea_set_encrypt_key(key16, &idea_ks);
# endif
# ifndef OPENSSL_NO_SEED
SEED_set_key(key16, &seed_ks);
# endif
# ifndef OPENSSL_NO_RC4
RC4_set_key(&rc4_ks, 16, key16);
# endif
# ifndef OPENSSL_NO_RC2
RC2_set_key(&rc2_ks, 16, key16, 128);
# endif
# ifndef OPENSSL_NO_RC5
RC5_32_set_key(&rc5_ks, 16, key16, 12);
# endif
# ifndef OPENSSL_NO_BF
BF_set_key(&bf_ks, 16, key16);
# endif
# ifndef OPENSSL_NO_CAST
CAST_set_key(&cast_ks, 16, key16);
# endif
# ifndef OPENSSL_NO_RSA
memset(rsa_c, 0, sizeof(rsa_c));
# endif
# ifndef SIGALRM
# ifndef OPENSSL_NO_DES
BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
count = 10;
do {
long it;
count *= 2;
Time_F(START);
for (it = count; it; it--)
DES_ecb_encrypt((DES_cblock *)buf,
(DES_cblock *)buf, &sch, DES_ENCRYPT);
d = Time_F(STOP);
} while (d < 3);
save_count = count;
c[D_MD2][0] = count / 10;
c[D_MDC2][0] = count / 10;
c[D_MD4][0] = count;
c[D_MD5][0] = count;
c[D_HMAC][0] = count;
c[D_SHA1][0] = count;
c[D_RMD160][0] = count;
c[D_RC4][0] = count * 5;
c[D_CBC_DES][0] = count;
c[D_EDE3_DES][0] = count / 3;
c[D_CBC_IDEA][0] = count;
c[D_CBC_SEED][0] = count;
c[D_CBC_RC2][0] = count;
c[D_CBC_RC5][0] = count;
c[D_CBC_BF][0] = count;
c[D_CBC_CAST][0] = count;
c[D_CBC_128_AES][0] = count;
c[D_CBC_192_AES][0] = count;
c[D_CBC_256_AES][0] = count;
c[D_CBC_128_CML][0] = count;
c[D_CBC_192_CML][0] = count;
c[D_CBC_256_CML][0] = count;
c[D_SHA256][0] = count;
c[D_SHA512][0] = count;
c[D_WHIRLPOOL][0] = count;
c[D_IGE_128_AES][0] = count;
c[D_IGE_192_AES][0] = count;
c[D_IGE_256_AES][0] = count;
c[D_GHASH][0] = count;
for (i = 1; i < SIZE_NUM; i++) {
long l0, l1;
l0 = (long)lengths[0];
l1 = (long)lengths[i];
c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
l0 = (long)lengths[i - 1];
c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
}
# ifndef OPENSSL_NO_RSA
rsa_c[R_RSA_512][0] = count / 2000;
rsa_c[R_RSA_512][1] = count / 400;
for (i = 1; i < RSA_NUM; i++) {
rsa_c[i][0] = rsa_c[i - 1][0] / 8;
rsa_c[i][1] = rsa_c[i - 1][1] / 4;
if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
rsa_doit[i] = 0;
else {
if (rsa_c[i][0] == 0) {
rsa_c[i][0] = 1;
rsa_c[i][1] = 20;
}
}
}
# endif
# ifndef OPENSSL_NO_DSA
dsa_c[R_DSA_512][0] = count / 1000;
dsa_c[R_DSA_512][1] = count / 1000 / 2;
for (i = 1; i < DSA_NUM; i++) {
dsa_c[i][0] = dsa_c[i - 1][0] / 4;
dsa_c[i][1] = dsa_c[i - 1][1] / 4;
if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
dsa_doit[i] = 0;
else {
if (dsa_c[i] == 0) {
dsa_c[i][0] = 1;
dsa_c[i][1] = 1;
}
}
}
# endif
# ifndef OPENSSL_NO_ECDSA
ecdsa_c[R_EC_P160][0] = count / 1000;
ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
for (i = R_EC_P192; i <= R_EC_P521; i++) {
ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i] = 0;
else {
if (ecdsa_c[i] == 0) {
ecdsa_c[i][0] = 1;
ecdsa_c[i][1] = 1;
}
}
}
ecdsa_c[R_EC_K163][0] = count / 1000;
ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
for (i = R_EC_K233; i <= R_EC_K571; i++) {
ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i] = 0;
else {
if (ecdsa_c[i] == 0) {
ecdsa_c[i][0] = 1;
ecdsa_c[i][1] = 1;
}
}
}
ecdsa_c[R_EC_B163][0] = count / 1000;
ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
for (i = R_EC_B233; i <= R_EC_B571; i++) {
ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i] = 0;
else {
if (ecdsa_c[i] == 0) {
ecdsa_c[i][0] = 1;
ecdsa_c[i][1] = 1;
}
}
}
# endif
# ifndef OPENSSL_NO_ECDH
ecdh_c[R_EC_P160][0] = count / 1000;
ecdh_c[R_EC_P160][1] = count / 1000;
for (i = R_EC_P192; i <= R_EC_P521; i++) {
ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i] = 0;
else {
if (ecdh_c[i] == 0) {
ecdh_c[i][0] = 1;
ecdh_c[i][1] = 1;
}
}
}
ecdh_c[R_EC_K163][0] = count / 1000;
ecdh_c[R_EC_K163][1] = count / 1000;
for (i = R_EC_K233; i <= R_EC_K571; i++) {
ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i] = 0;
else {
if (ecdh_c[i] == 0) {
ecdh_c[i][0] = 1;
ecdh_c[i][1] = 1;
}
}
}
ecdh_c[R_EC_B163][0] = count / 1000;
ecdh_c[R_EC_B163][1] = count / 1000;
for (i = R_EC_B233; i <= R_EC_B571; i++) {
ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i] = 0;
else {
if (ecdh_c[i] == 0) {
ecdh_c[i][0] = 1;
ecdh_c[i][1] = 1;
}
}
}
# endif
# define COND(d) (count < (d))
# define COUNT(d) (d)
# else
# error "You cannot disable DES on systems without SIGALRM."
# endif
# else
# define COND(c) (run && count<0x7fffffff)
# define COUNT(d) (count)
# ifndef _WIN32
signal(SIGALRM, sig_done);
# endif
# endif
# ifndef OPENSSL_NO_MD2
if (doit[D_MD2]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
EVP_md2(), NULL);
d = Time_F(STOP);
print_result(D_MD2, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_MDC2
if (doit[D_MDC2]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
EVP_mdc2(), NULL);
d = Time_F(STOP);
print_result(D_MDC2, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_MD4
if (doit[D_MD4]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
NULL, EVP_md4(), NULL);
d = Time_F(STOP);
print_result(D_MD4, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_MD5
if (doit[D_MD5]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
MD5(buf, lengths[j], md5);
d = Time_F(STOP);
print_result(D_MD5, j, count, d);
}
}
# endif
# if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
if (doit[D_HMAC]) {
HMAC_CTX hctx;
HMAC_CTX_init(&hctx);
HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
16, EVP_md5(), NULL);
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
HMAC_Update(&hctx, buf, lengths[j]);
HMAC_Final(&hctx, &(hmac[0]), NULL);
}
d = Time_F(STOP);
print_result(D_HMAC, j, count, d);
}
HMAC_CTX_cleanup(&hctx);
}
# endif
# ifndef OPENSSL_NO_SHA
if (doit[D_SHA1]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
# if 0
EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,
EVP_sha1(), NULL);
# else
SHA1(buf, lengths[j], sha);
# endif
d = Time_F(STOP);
print_result(D_SHA1, j, count, d);
}
}
# ifndef OPENSSL_NO_SHA256
if (doit[D_SHA256]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
SHA256(buf, lengths[j], sha256);
d = Time_F(STOP);
print_result(D_SHA256, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_SHA512
if (doit[D_SHA512]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
SHA512(buf, lengths[j], sha512);
d = Time_F(STOP);
print_result(D_SHA512, j, count, d);
}
}
# endif
# endif
# ifndef OPENSSL_NO_WHIRLPOOL
if (doit[D_WHIRLPOOL]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
WHIRLPOOL(buf, lengths[j], whirlpool);
d = Time_F(STOP);
print_result(D_WHIRLPOOL, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_RMD160
if (doit[D_RMD160]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
EVP_ripemd160(), NULL);
d = Time_F(STOP);
print_result(D_RMD160, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_RC4
if (doit[D_RC4]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
d = Time_F(STOP);
print_result(D_RC4, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_DES
if (doit[D_CBC_DES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
&DES_iv, DES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_DES, j, count, d);
}
}
if (doit[D_EDE3_DES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
DES_ede3_cbc_encrypt(buf, buf, lengths[j],
&sch, &sch2, &sch3,
&DES_iv, DES_ENCRYPT);
d = Time_F(STOP);
print_result(D_EDE3_DES, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_AES
if (doit[D_CBC_128_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
AES_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &aes_ks1,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_128_AES, j, count, d);
}
}
if (doit[D_CBC_192_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
AES_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &aes_ks2,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_192_AES, j, count, d);
}
}
if (doit[D_CBC_256_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
AES_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &aes_ks3,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_256_AES, j, count, d);
}
}
if (doit[D_IGE_128_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
AES_ige_encrypt(buf, buf2,
(unsigned long)lengths[j], &aes_ks1,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_IGE_128_AES, j, count, d);
}
}
if (doit[D_IGE_192_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
AES_ige_encrypt(buf, buf2,
(unsigned long)lengths[j], &aes_ks2,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_IGE_192_AES, j, count, d);
}
}
if (doit[D_IGE_256_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
AES_ige_encrypt(buf, buf2,
(unsigned long)lengths[j], &aes_ks3,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_IGE_256_AES, j, count, d);
}
}
if (doit[D_GHASH]) {
GCM128_CONTEXT *ctx =
CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
d = Time_F(STOP);
print_result(D_GHASH, j, count, d);
}
CRYPTO_gcm128_release(ctx);
}
# endif
# ifndef OPENSSL_NO_CAMELLIA
if (doit[D_CBC_128_CML]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
Camellia_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &camellia_ks1,
iv, CAMELLIA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_128_CML, j, count, d);
}
}
if (doit[D_CBC_192_CML]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
Camellia_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &camellia_ks2,
iv, CAMELLIA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_192_CML, j, count, d);
}
}
if (doit[D_CBC_256_CML]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
Camellia_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &camellia_ks3,
iv, CAMELLIA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_256_CML, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_IDEA
if (doit[D_CBC_IDEA]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
idea_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &idea_ks,
iv, IDEA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_IDEA, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_SEED
if (doit[D_CBC_SEED]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
SEED_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &seed_ks, iv, 1);
d = Time_F(STOP);
print_result(D_CBC_SEED, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_RC2
if (doit[D_CBC_RC2]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
RC2_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &rc2_ks,
iv, RC2_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_RC2, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_RC5
if (doit[D_CBC_RC5]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
RC5_32_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &rc5_ks,
iv, RC5_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_RC5, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_BF
if (doit[D_CBC_BF]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
BF_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &bf_ks,
iv, BF_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_BF, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_CAST
if (doit[D_CBC_CAST]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
CAST_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &cast_ks,
iv, CAST_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_CAST, j, count, d);
}
}
# endif
if (doit[D_EVP]) {
# ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
if (multiblock && evp_cipher) {
if (!
(EVP_CIPHER_flags(evp_cipher) &
EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
fprintf(stderr, "%s is not multi-block capable\n",
OBJ_nid2ln(evp_cipher->nid));
goto end;
}
multiblock_speed(evp_cipher);
mret = 0;
goto end;
}
# endif
for (j = 0; j < SIZE_NUM; j++) {
if (evp_cipher) {
EVP_CIPHER_CTX ctx;
int outl;
names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
print_message(names[D_EVP], save_count, lengths[j]);
EVP_CIPHER_CTX_init(&ctx);
if (decrypt)
EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
else
EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
EVP_CIPHER_CTX_set_padding(&ctx, 0);
Time_F(START);
if (decrypt)
for (count = 0, run = 1;
COND(save_count * 4 * lengths[0] / lengths[j]);
count++)
EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
else
for (count = 0, run = 1;
COND(save_count * 4 * lengths[0] / lengths[j]);
count++)
EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
if (decrypt)
EVP_DecryptFinal_ex(&ctx, buf, &outl);
else
EVP_EncryptFinal_ex(&ctx, buf, &outl);
d = Time_F(STOP);
EVP_CIPHER_CTX_cleanup(&ctx);
}
if (evp_md) {
names[D_EVP] = OBJ_nid2ln(evp_md->type);
print_message(names[D_EVP], save_count, lengths[j]);
Time_F(START);
for (count = 0, run = 1;
COND(save_count * 4 * lengths[0] / lengths[j]); count++)
EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
d = Time_F(STOP);
}
print_result(D_EVP, j, count, d);
}
}
# ifndef OPENSSL_SYS_WIN32
# endif
RAND_pseudo_bytes(buf, 36);
# ifndef OPENSSL_NO_RSA
for (j = 0; j < RSA_NUM; j++) {
int ret;
if (!rsa_doit[j])
continue;
ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err,
"RSA sign failure. No RSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
pkey_print_message("private", "rsa",
rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
&rsa_num, rsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err, "RSA sign failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R1:%ld:%d:%.2f\n"
: "%ld %d bit private RSA's in %.2fs\n",
count, rsa_bits[j], d);
rsa_results[j][0] = d / (double)count;
rsa_count = count;
}
# if 1
ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err,
"RSA verify failure. No RSA verify will be done.\n");
ERR_print_errors(bio_err);
rsa_doit[j] = 0;
} else {
pkey_print_message("public", "rsa",
rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
rsa_num, rsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err, "RSA verify failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R2:%ld:%d:%.2f\n"
: "%ld %d bit public RSA's in %.2fs\n",
count, rsa_bits[j], d);
rsa_results[j][1] = d / (double)count;
}
# endif
if (rsa_count <= 1) {
for (j++; j < RSA_NUM; j++)
rsa_doit[j] = 0;
}
}
# endif
RAND_pseudo_bytes(buf, 20);
# ifndef OPENSSL_NO_DSA
if (RAND_status() != 1) {
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j = 0; j < DSA_NUM; j++) {
unsigned int kk;
int ret;
if (!dsa_doit[j])
continue;
ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err,
"DSA sign failure. No DSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
pkey_print_message("sign", "dsa",
dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err, "DSA sign failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R3:%ld:%d:%.2f\n"
: "%ld %d bit DSA signs in %.2fs\n",
count, dsa_bits[j], d);
dsa_results[j][0] = d / (double)count;
rsa_count = count;
}
ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err,
"DSA verify failure. No DSA verify will be done.\n");
ERR_print_errors(bio_err);
dsa_doit[j] = 0;
} else {
pkey_print_message("verify", "dsa",
dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err, "DSA verify failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R4:%ld:%d:%.2f\n"
: "%ld %d bit DSA verify in %.2fs\n",
count, dsa_bits[j], d);
dsa_results[j][1] = d / (double)count;
}
if (rsa_count <= 1) {
for (j++; j < DSA_NUM; j++)
dsa_doit[j] = 0;
}
}
if (rnd_fake)
RAND_cleanup();
# endif
# ifndef OPENSSL_NO_ECDSA
if (RAND_status() != 1) {
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j = 0; j < EC_NUM; j++) {
int ret;
if (!ecdsa_doit[j])
continue;
ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
if (ecdsa[j] == NULL) {
BIO_printf(bio_err, "ECDSA failure.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
# if 1
EC_KEY_precompute_mult(ecdsa[j], NULL);
# endif
EC_KEY_generate_key(ecdsa[j]);
ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
if (ret == 0) {
BIO_printf(bio_err,
"ECDSA sign failure. No ECDSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
pkey_print_message("sign", "ecdsa",
ecdsa_c[j][0],
test_curves_bits[j], ECDSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
ret = ECDSA_sign(0, buf, 20,
ecdsasig, &ecdsasiglen, ecdsa[j]);
if (ret == 0) {
BIO_printf(bio_err, "ECDSA sign failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R5:%ld:%d:%.2f\n" :
"%ld %d bit ECDSA signs in %.2fs \n",
count, test_curves_bits[j], d);
ecdsa_results[j][0] = d / (double)count;
rsa_count = count;
}
ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
if (ret != 1) {
BIO_printf(bio_err,
"ECDSA verify failure. No ECDSA verify will be done.\n");
ERR_print_errors(bio_err);
ecdsa_doit[j] = 0;
} else {
pkey_print_message("verify", "ecdsa",
ecdsa_c[j][1],
test_curves_bits[j], ECDSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
ret =
ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
ecdsa[j]);
if (ret != 1) {
BIO_printf(bio_err, "ECDSA verify failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R6:%ld:%d:%.2f\n"
: "%ld %d bit ECDSA verify in %.2fs\n",
count, test_curves_bits[j], d);
ecdsa_results[j][1] = d / (double)count;
}
if (rsa_count <= 1) {
for (j++; j < EC_NUM; j++)
ecdsa_doit[j] = 0;
}
}
}
if (rnd_fake)
RAND_cleanup();
# endif
# ifndef OPENSSL_NO_ECDH
if (RAND_status() != 1) {
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j = 0; j < EC_NUM; j++) {
if (!ecdh_doit[j])
continue;
ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
BIO_printf(bio_err, "ECDH failure.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
if (!EC_KEY_generate_key(ecdh_a[j]) ||
!EC_KEY_generate_key(ecdh_b[j])) {
BIO_printf(bio_err, "ECDH key generation failure.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
int field_size, outlen;
void *(*kdf) (const void *in, size_t inlen, void *out,
size_t *xoutlen);
field_size =
EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
if (field_size <= 24 * 8) {
outlen = KDF1_SHA1_len;
kdf = KDF1_SHA1;
} else {
outlen = (field_size + 7) / 8;
kdf = NULL;
}
secret_size_a =
ECDH_compute_key(secret_a, outlen,
EC_KEY_get0_public_key(ecdh_b[j]),
ecdh_a[j], kdf);
secret_size_b =
ECDH_compute_key(secret_b, outlen,
EC_KEY_get0_public_key(ecdh_a[j]),
ecdh_b[j], kdf);
if (secret_size_a != secret_size_b)
ecdh_checks = 0;
else
ecdh_checks = 1;
for (secret_idx = 0; (secret_idx < secret_size_a)
&& (ecdh_checks == 1); secret_idx++) {
if (secret_a[secret_idx] != secret_b[secret_idx])
ecdh_checks = 0;
}
if (ecdh_checks == 0) {
BIO_printf(bio_err, "ECDH computations don't match.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
}
pkey_print_message("", "ecdh",
ecdh_c[j][0],
test_curves_bits[j], ECDH_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
ECDH_compute_key(secret_a, outlen,
EC_KEY_get0_public_key(ecdh_b[j]),
ecdh_a[j], kdf);
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R7:%ld:%d:%.2f\n" :
"%ld %d-bit ECDH ops in %.2fs\n", count,
test_curves_bits[j], d);
ecdh_results[j][0] = d / (double)count;
rsa_count = count;
}
}
if (rsa_count <= 1) {
for (j++; j < EC_NUM; j++)
ecdh_doit[j] = 0;
}
}
if (rnd_fake)
RAND_cleanup();
# endif
# ifndef NO_FORK
show_res:
# endif
if (!mr) {
fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
printf("options:");
printf("%s ", BN_options());
# ifndef OPENSSL_NO_MD2
printf("%s ", MD2_options());
# endif
# ifndef OPENSSL_NO_RC4
printf("%s ", RC4_options());
# endif
# ifndef OPENSSL_NO_DES
printf("%s ", DES_options());
# endif
# ifndef OPENSSL_NO_AES
printf("%s ", AES_options());
# endif
# ifndef OPENSSL_NO_IDEA
printf("%s ", idea_options());
# endif
# ifndef OPENSSL_NO_BF
printf("%s ", BF_options());
# endif
fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
}
if (pr_header) {
if (mr)
fprintf(stdout, "+H");
else {
fprintf(stdout,
"The 'numbers' are in 1000s of bytes per second processed.\n");
fprintf(stdout, "type ");
}
for (j = 0; j < SIZE_NUM; j++)
fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
fprintf(stdout, "\n");
}
for (k = 0; k < ALGOR_NUM; k++) {
if (!doit[k])
continue;
if (mr)
fprintf(stdout, "+F:%d:%s", k, names[k]);
else
fprintf(stdout, "%-13s", names[k]);
for (j = 0; j < SIZE_NUM; j++) {
if (results[k][j] > 10000 && !mr)
fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
else
fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
}
fprintf(stdout, "\n");
}
# ifndef OPENSSL_NO_RSA
j = 1;
for (k = 0; k < RSA_NUM; k++) {
if (!rsa_doit[k])
continue;
if (j && !mr) {
printf("%18ssign verify sign/s verify/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F2:%u:%u:%f:%f\n",
k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
else
fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
}
# endif
# ifndef OPENSSL_NO_DSA
j = 1;
for (k = 0; k < DSA_NUM; k++) {
if (!dsa_doit[k])
continue;
if (j && !mr) {
printf("%18ssign verify sign/s verify/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F3:%u:%u:%f:%f\n",
k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
else
fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
}
# endif
# ifndef OPENSSL_NO_ECDSA
j = 1;
for (k = 0; k < EC_NUM; k++) {
if (!ecdsa_doit[k])
continue;
if (j && !mr) {
printf("%30ssign verify sign/s verify/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F4:%u:%u:%f:%f\n",
k, test_curves_bits[k],
ecdsa_results[k][0], ecdsa_results[k][1]);
else
fprintf(stdout,
"%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
test_curves_bits[k],
test_curves_names[k],
ecdsa_results[k][0], ecdsa_results[k][1],
1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
}
# endif
# ifndef OPENSSL_NO_ECDH
j = 1;
for (k = 0; k < EC_NUM; k++) {
if (!ecdh_doit[k])
continue;
if (j && !mr) {
printf("%30sop op/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F5:%u:%u:%f:%f\n",
k, test_curves_bits[k],
ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
else
fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
test_curves_bits[k],
test_curves_names[k],
ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
}
# endif
mret = 0;
end:
ERR_print_errors(bio_err);
if (buf_malloc != NULL)
OPENSSL_free(buf_malloc);
if (buf2_malloc != NULL)
OPENSSL_free(buf2_malloc);
# ifndef OPENSSL_NO_RSA
for (i = 0; i < RSA_NUM; i++)
if (rsa_key[i] != NULL)
RSA_free(rsa_key[i]);
# endif
# ifndef OPENSSL_NO_DSA
for (i = 0; i < DSA_NUM; i++)
if (dsa_key[i] != NULL)
DSA_free(dsa_key[i]);
# endif
# ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
if (ecdsa[i] != NULL)
EC_KEY_free(ecdsa[i]);
# endif
# ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++) {
if (ecdh_a[i] != NULL)
EC_KEY_free(ecdh_a[i]);
if (ecdh_b[i] != NULL)
EC_KEY_free(ecdh_b[i]);
}
# endif
apps_shutdown();
OPENSSL_EXIT(mret);
} | ['int MAIN(int argc, char **argv)\n{\n unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;\n unsigned char *buf = NULL, *buf2 = NULL;\n int mret = 1;\n long count = 0, save_count = 0;\n int i, j, k;\n# if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)\n long rsa_count;\n# endif\n# ifndef OPENSSL_NO_RSA\n unsigned rsa_num;\n# endif\n unsigned char md[EVP_MAX_MD_SIZE];\n# ifndef OPENSSL_NO_MD2\n unsigned char md2[MD2_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_MDC2\n unsigned char mdc2[MDC2_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_MD4\n unsigned char md4[MD4_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_MD5\n unsigned char md5[MD5_DIGEST_LENGTH];\n unsigned char hmac[MD5_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_SHA\n unsigned char sha[SHA_DIGEST_LENGTH];\n# ifndef OPENSSL_NO_SHA256\n unsigned char sha256[SHA256_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_SHA512\n unsigned char sha512[SHA512_DIGEST_LENGTH];\n# endif\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_RMD160\n unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_RC4\n RC4_KEY rc4_ks;\n# endif\n# ifndef OPENSSL_NO_RC5\n RC5_32_KEY rc5_ks;\n# endif\n# ifndef OPENSSL_NO_RC2\n RC2_KEY rc2_ks;\n# endif\n# ifndef OPENSSL_NO_IDEA\n IDEA_KEY_SCHEDULE idea_ks;\n# endif\n# ifndef OPENSSL_NO_SEED\n SEED_KEY_SCHEDULE seed_ks;\n# endif\n# ifndef OPENSSL_NO_BF\n BF_KEY bf_ks;\n# endif\n# ifndef OPENSSL_NO_CAST\n CAST_KEY cast_ks;\n# endif\n static const unsigned char key16[16] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12\n };\n# ifndef OPENSSL_NO_AES\n static const unsigned char key24[24] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34\n };\n static const unsigned char key32[32] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,\n 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56\n };\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n static const unsigned char ckey24[24] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34\n };\n static const unsigned char ckey32[32] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,\n 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56\n };\n# endif\n# ifndef OPENSSL_NO_AES\n# define MAX_BLOCK_SIZE 128\n# else\n# define MAX_BLOCK_SIZE 64\n# endif\n unsigned char DES_iv[8];\n unsigned char iv[2 * MAX_BLOCK_SIZE / 8];\n# ifndef OPENSSL_NO_DES\n static DES_cblock key =\n { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };\n static DES_cblock key2 =\n { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };\n static DES_cblock key3 =\n { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };\n DES_key_schedule sch;\n DES_key_schedule sch2;\n DES_key_schedule sch3;\n# endif\n# ifndef OPENSSL_NO_AES\n AES_KEY aes_ks1, aes_ks2, aes_ks3;\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;\n# endif\n# define D_MD2 0\n# define D_MDC2 1\n# define D_MD4 2\n# define D_MD5 3\n# define D_HMAC 4\n# define D_SHA1 5\n# define D_RMD160 6\n# define D_RC4 7\n# define D_CBC_DES 8\n# define D_EDE3_DES 9\n# define D_CBC_IDEA 10\n# define D_CBC_SEED 11\n# define D_CBC_RC2 12\n# define D_CBC_RC5 13\n# define D_CBC_BF 14\n# define D_CBC_CAST 15\n# define D_CBC_128_AES 16\n# define D_CBC_192_AES 17\n# define D_CBC_256_AES 18\n# define D_CBC_128_CML 19\n# define D_CBC_192_CML 20\n# define D_CBC_256_CML 21\n# define D_EVP 22\n# define D_SHA256 23\n# define D_SHA512 24\n# define D_WHIRLPOOL 25\n# define D_IGE_128_AES 26\n# define D_IGE_192_AES 27\n# define D_IGE_256_AES 28\n# define D_GHASH 29\n double d = 0.0;\n long c[ALGOR_NUM][SIZE_NUM];\n# ifndef OPENSSL_SYS_WIN32\n# endif\n# define R_DSA_512 0\n# define R_DSA_1024 1\n# define R_DSA_2048 2\n# define R_RSA_512 0\n# define R_RSA_1024 1\n# define R_RSA_2048 2\n# define R_RSA_3072 3\n# define R_RSA_4096 4\n# define R_RSA_7680 5\n# define R_RSA_15360 6\n# define R_EC_P160 0\n# define R_EC_P192 1\n# define R_EC_P224 2\n# define R_EC_P256 3\n# define R_EC_P384 4\n# define R_EC_P521 5\n# define R_EC_K163 6\n# define R_EC_K233 7\n# define R_EC_K283 8\n# define R_EC_K409 9\n# define R_EC_K571 10\n# define R_EC_B163 11\n# define R_EC_B233 12\n# define R_EC_B283 13\n# define R_EC_B409 14\n# define R_EC_B571 15\n# ifndef OPENSSL_NO_RSA\n RSA *rsa_key[RSA_NUM];\n long rsa_c[RSA_NUM][2];\n static unsigned int rsa_bits[RSA_NUM] = {\n 512, 1024, 2048, 3072, 4096, 7680, 15360\n };\n static unsigned char *rsa_data[RSA_NUM] = {\n test512, test1024, test2048, test3072, test4096, test7680, test15360\n };\n static int rsa_data_length[RSA_NUM] = {\n sizeof(test512), sizeof(test1024),\n sizeof(test2048), sizeof(test3072),\n sizeof(test4096), sizeof(test7680),\n sizeof(test15360)\n };\n# endif\n# ifndef OPENSSL_NO_DSA\n DSA *dsa_key[DSA_NUM];\n long dsa_c[DSA_NUM][2];\n static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };\n# endif\n# ifndef OPENSSL_NO_EC\n static unsigned int test_curves[EC_NUM] = {\n NID_secp160r1,\n NID_X9_62_prime192v1,\n NID_secp224r1,\n NID_X9_62_prime256v1,\n NID_secp384r1,\n NID_secp521r1,\n NID_sect163k1,\n NID_sect233k1,\n NID_sect283k1,\n NID_sect409k1,\n NID_sect571k1,\n NID_sect163r2,\n NID_sect233r1,\n NID_sect283r1,\n NID_sect409r1,\n NID_sect571r1\n };\n static const char *test_curves_names[EC_NUM] = {\n "secp160r1",\n "nistp192",\n "nistp224",\n "nistp256",\n "nistp384",\n "nistp521",\n "nistk163",\n "nistk233",\n "nistk283",\n "nistk409",\n "nistk571",\n "nistb163",\n "nistb233",\n "nistb283",\n "nistb409",\n "nistb571"\n };\n static int test_curves_bits[EC_NUM] = {\n 160, 192, 224, 256, 384, 521,\n 163, 233, 283, 409, 571,\n 163, 233, 283, 409, 571\n };\n# endif\n# ifndef OPENSSL_NO_ECDSA\n unsigned char ecdsasig[256];\n unsigned int ecdsasiglen;\n EC_KEY *ecdsa[EC_NUM];\n long ecdsa_c[EC_NUM][2];\n# endif\n# ifndef OPENSSL_NO_ECDH\n EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];\n unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];\n int secret_size_a, secret_size_b;\n int ecdh_checks = 0;\n int secret_idx = 0;\n long ecdh_c[EC_NUM][2];\n# endif\n int rsa_doit[RSA_NUM];\n int dsa_doit[DSA_NUM];\n# ifndef OPENSSL_NO_ECDSA\n int ecdsa_doit[EC_NUM];\n# endif\n# ifndef OPENSSL_NO_ECDH\n int ecdh_doit[EC_NUM];\n# endif\n int doit[ALGOR_NUM];\n int pr_header = 0;\n const EVP_CIPHER *evp_cipher = NULL;\n const EVP_MD *evp_md = NULL;\n int decrypt = 0;\n# ifndef NO_FORK\n int multi = 0;\n# endif\n int multiblock = 0;\n int misalign = MAX_MISALIGNMENT + 1;\n# ifndef TIMES\n usertime = -1;\n# endif\n apps_startup();\n memset(results, 0, sizeof(results));\n# ifndef OPENSSL_NO_DSA\n memset(dsa_key, 0, sizeof(dsa_key));\n# endif\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa[i] = NULL;\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++) {\n ecdh_a[i] = NULL;\n ecdh_b[i] = NULL;\n }\n# endif\n if (bio_err == NULL)\n if ((bio_err = BIO_new(BIO_s_file())) != NULL)\n BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);\n if (!load_config(bio_err, NULL))\n goto end;\n# ifndef OPENSSL_NO_RSA\n memset(rsa_key, 0, sizeof(rsa_key));\n for (i = 0; i < RSA_NUM; i++)\n rsa_key[i] = NULL;\n# endif\n if ((buf_malloc =\n (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {\n BIO_printf(bio_err, "out of memory\\n");\n goto end;\n }\n if ((buf2_malloc =\n (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {\n BIO_printf(bio_err, "out of memory\\n");\n goto end;\n }\n misalign = 0;\n buf = buf_malloc;\n buf2 = buf2_malloc;\n memset(c, 0, sizeof(c));\n memset(DES_iv, 0, sizeof(DES_iv));\n memset(iv, 0, sizeof(iv));\n for (i = 0; i < ALGOR_NUM; i++)\n doit[i] = 0;\n for (i = 0; i < RSA_NUM; i++)\n rsa_doit[i] = 0;\n for (i = 0; i < DSA_NUM; i++)\n dsa_doit[i] = 0;\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 0;\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 0;\n# endif\n j = 0;\n argc--;\n argv++;\n while (argc) {\n if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {\n usertime = 0;\n j--;\n } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no EVP given\\n");\n goto end;\n }\n evp_cipher = EVP_get_cipherbyname(*argv);\n if (!evp_cipher) {\n evp_md = EVP_get_digestbyname(*argv);\n }\n if (!evp_cipher && !evp_md) {\n BIO_printf(bio_err, "%s is an unknown cipher or digest\\n",\n *argv);\n goto end;\n }\n doit[D_EVP] = 1;\n } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {\n decrypt = 1;\n j--;\n }\n# ifndef OPENSSL_NO_ENGINE\n else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no engine given\\n");\n goto end;\n }\n setup_engine(bio_err, *argv, 0);\n j--;\n }\n# endif\n# ifndef NO_FORK\n else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no multi count given\\n");\n goto end;\n }\n multi = atoi(argv[0]);\n if (multi <= 0) {\n BIO_printf(bio_err, "bad multi count\\n");\n goto end;\n }\n j--;\n }\n# endif\n else if (argc > 0 && !strcmp(*argv, "-mr")) {\n mr = 1;\n j--;\n } else if (argc > 0 && !strcmp(*argv, "-mb")) {\n multiblock = 1;\n j--;\n } else if (argc > 0 && !strcmp(*argv, "-misalign")) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no misalignment given\\n");\n goto end;\n }\n misalign = atoi(argv[0]);\n if (misalign < 0 || misalign > MAX_MISALIGNMENT) {\n BIO_printf(bio_err,\n "misalignment is outsize permitted range 0-%d\\n",\n MAX_MISALIGNMENT);\n goto end;\n }\n buf = buf_malloc + misalign;\n buf2 = buf2_malloc + misalign;\n j--;\n } else\n# ifndef OPENSSL_NO_MD2\n if (strcmp(*argv, "md2") == 0)\n doit[D_MD2] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MDC2\n if (strcmp(*argv, "mdc2") == 0)\n doit[D_MDC2] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MD4\n if (strcmp(*argv, "md4") == 0)\n doit[D_MD4] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MD5\n if (strcmp(*argv, "md5") == 0)\n doit[D_MD5] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MD5\n if (strcmp(*argv, "hmac") == 0)\n doit[D_HMAC] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_SHA\n if (strcmp(*argv, "sha1") == 0)\n doit[D_SHA1] = 1;\n else if (strcmp(*argv, "sha") == 0)\n doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;\n else\n# ifndef OPENSSL_NO_SHA256\n if (strcmp(*argv, "sha256") == 0)\n doit[D_SHA256] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_SHA512\n if (strcmp(*argv, "sha512") == 0)\n doit[D_SHA512] = 1;\n else\n# endif\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n if (strcmp(*argv, "whirlpool") == 0)\n doit[D_WHIRLPOOL] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RMD160\n if (strcmp(*argv, "ripemd") == 0)\n doit[D_RMD160] = 1;\n else if (strcmp(*argv, "rmd160") == 0)\n doit[D_RMD160] = 1;\n else if (strcmp(*argv, "ripemd160") == 0)\n doit[D_RMD160] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RC4\n if (strcmp(*argv, "rc4") == 0)\n doit[D_RC4] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_DES\n if (strcmp(*argv, "des-cbc") == 0)\n doit[D_CBC_DES] = 1;\n else if (strcmp(*argv, "des-ede3") == 0)\n doit[D_EDE3_DES] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_AES\n if (strcmp(*argv, "aes-128-cbc") == 0)\n doit[D_CBC_128_AES] = 1;\n else if (strcmp(*argv, "aes-192-cbc") == 0)\n doit[D_CBC_192_AES] = 1;\n else if (strcmp(*argv, "aes-256-cbc") == 0)\n doit[D_CBC_256_AES] = 1;\n else if (strcmp(*argv, "aes-128-ige") == 0)\n doit[D_IGE_128_AES] = 1;\n else if (strcmp(*argv, "aes-192-ige") == 0)\n doit[D_IGE_192_AES] = 1;\n else if (strcmp(*argv, "aes-256-ige") == 0)\n doit[D_IGE_256_AES] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n if (strcmp(*argv, "camellia-128-cbc") == 0)\n doit[D_CBC_128_CML] = 1;\n else if (strcmp(*argv, "camellia-192-cbc") == 0)\n doit[D_CBC_192_CML] = 1;\n else if (strcmp(*argv, "camellia-256-cbc") == 0)\n doit[D_CBC_256_CML] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RSA\n# if 0\n if (strcmp(*argv, "rsaref") == 0) {\n RSA_set_default_openssl_method(RSA_PKCS1_RSAref());\n j--;\n } else\n# endif\n# ifndef RSA_NULL\n if (strcmp(*argv, "openssl") == 0) {\n RSA_set_default_method(RSA_PKCS1_SSLeay());\n j--;\n } else\n# endif\n# endif\n if (strcmp(*argv, "dsa512") == 0)\n dsa_doit[R_DSA_512] = 2;\n else if (strcmp(*argv, "dsa1024") == 0)\n dsa_doit[R_DSA_1024] = 2;\n else if (strcmp(*argv, "dsa2048") == 0)\n dsa_doit[R_DSA_2048] = 2;\n else if (strcmp(*argv, "rsa512") == 0)\n rsa_doit[R_RSA_512] = 2;\n else if (strcmp(*argv, "rsa1024") == 0)\n rsa_doit[R_RSA_1024] = 2;\n else if (strcmp(*argv, "rsa2048") == 0)\n rsa_doit[R_RSA_2048] = 2;\n else if (strcmp(*argv, "rsa3072") == 0)\n rsa_doit[R_RSA_3072] = 2;\n else if (strcmp(*argv, "rsa4096") == 0)\n rsa_doit[R_RSA_4096] = 2;\n else if (strcmp(*argv, "rsa7680") == 0)\n rsa_doit[R_RSA_7680] = 2;\n else if (strcmp(*argv, "rsa15360") == 0)\n rsa_doit[R_RSA_15360] = 2;\n else\n# ifndef OPENSSL_NO_RC2\n if (strcmp(*argv, "rc2-cbc") == 0)\n doit[D_CBC_RC2] = 1;\n else if (strcmp(*argv, "rc2") == 0)\n doit[D_CBC_RC2] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RC5\n if (strcmp(*argv, "rc5-cbc") == 0)\n doit[D_CBC_RC5] = 1;\n else if (strcmp(*argv, "rc5") == 0)\n doit[D_CBC_RC5] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_IDEA\n if (strcmp(*argv, "idea-cbc") == 0)\n doit[D_CBC_IDEA] = 1;\n else if (strcmp(*argv, "idea") == 0)\n doit[D_CBC_IDEA] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_SEED\n if (strcmp(*argv, "seed-cbc") == 0)\n doit[D_CBC_SEED] = 1;\n else if (strcmp(*argv, "seed") == 0)\n doit[D_CBC_SEED] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_BF\n if (strcmp(*argv, "bf-cbc") == 0)\n doit[D_CBC_BF] = 1;\n else if (strcmp(*argv, "blowfish") == 0)\n doit[D_CBC_BF] = 1;\n else if (strcmp(*argv, "bf") == 0)\n doit[D_CBC_BF] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_CAST\n if (strcmp(*argv, "cast-cbc") == 0)\n doit[D_CBC_CAST] = 1;\n else if (strcmp(*argv, "cast") == 0)\n doit[D_CBC_CAST] = 1;\n else if (strcmp(*argv, "cast5") == 0)\n doit[D_CBC_CAST] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_DES\n if (strcmp(*argv, "des") == 0) {\n doit[D_CBC_DES] = 1;\n doit[D_EDE3_DES] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_AES\n if (strcmp(*argv, "aes") == 0) {\n doit[D_CBC_128_AES] = 1;\n doit[D_CBC_192_AES] = 1;\n doit[D_CBC_256_AES] = 1;\n } else if (strcmp(*argv, "ghash") == 0) {\n doit[D_GHASH] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n if (strcmp(*argv, "camellia") == 0) {\n doit[D_CBC_128_CML] = 1;\n doit[D_CBC_192_CML] = 1;\n doit[D_CBC_256_CML] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_RSA\n if (strcmp(*argv, "rsa") == 0) {\n rsa_doit[R_RSA_512] = 1;\n rsa_doit[R_RSA_1024] = 1;\n rsa_doit[R_RSA_2048] = 1;\n rsa_doit[R_RSA_3072] = 1;\n rsa_doit[R_RSA_4096] = 1;\n rsa_doit[R_RSA_7680] = 1;\n rsa_doit[R_RSA_15360] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_DSA\n if (strcmp(*argv, "dsa") == 0) {\n dsa_doit[R_DSA_512] = 1;\n dsa_doit[R_DSA_1024] = 1;\n dsa_doit[R_DSA_2048] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_ECDSA\n if (strcmp(*argv, "ecdsap160") == 0)\n ecdsa_doit[R_EC_P160] = 2;\n else if (strcmp(*argv, "ecdsap192") == 0)\n ecdsa_doit[R_EC_P192] = 2;\n else if (strcmp(*argv, "ecdsap224") == 0)\n ecdsa_doit[R_EC_P224] = 2;\n else if (strcmp(*argv, "ecdsap256") == 0)\n ecdsa_doit[R_EC_P256] = 2;\n else if (strcmp(*argv, "ecdsap384") == 0)\n ecdsa_doit[R_EC_P384] = 2;\n else if (strcmp(*argv, "ecdsap521") == 0)\n ecdsa_doit[R_EC_P521] = 2;\n else if (strcmp(*argv, "ecdsak163") == 0)\n ecdsa_doit[R_EC_K163] = 2;\n else if (strcmp(*argv, "ecdsak233") == 0)\n ecdsa_doit[R_EC_K233] = 2;\n else if (strcmp(*argv, "ecdsak283") == 0)\n ecdsa_doit[R_EC_K283] = 2;\n else if (strcmp(*argv, "ecdsak409") == 0)\n ecdsa_doit[R_EC_K409] = 2;\n else if (strcmp(*argv, "ecdsak571") == 0)\n ecdsa_doit[R_EC_K571] = 2;\n else if (strcmp(*argv, "ecdsab163") == 0)\n ecdsa_doit[R_EC_B163] = 2;\n else if (strcmp(*argv, "ecdsab233") == 0)\n ecdsa_doit[R_EC_B233] = 2;\n else if (strcmp(*argv, "ecdsab283") == 0)\n ecdsa_doit[R_EC_B283] = 2;\n else if (strcmp(*argv, "ecdsab409") == 0)\n ecdsa_doit[R_EC_B409] = 2;\n else if (strcmp(*argv, "ecdsab571") == 0)\n ecdsa_doit[R_EC_B571] = 2;\n else if (strcmp(*argv, "ecdsa") == 0) {\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_ECDH\n if (strcmp(*argv, "ecdhp160") == 0)\n ecdh_doit[R_EC_P160] = 2;\n else if (strcmp(*argv, "ecdhp192") == 0)\n ecdh_doit[R_EC_P192] = 2;\n else if (strcmp(*argv, "ecdhp224") == 0)\n ecdh_doit[R_EC_P224] = 2;\n else if (strcmp(*argv, "ecdhp256") == 0)\n ecdh_doit[R_EC_P256] = 2;\n else if (strcmp(*argv, "ecdhp384") == 0)\n ecdh_doit[R_EC_P384] = 2;\n else if (strcmp(*argv, "ecdhp521") == 0)\n ecdh_doit[R_EC_P521] = 2;\n else if (strcmp(*argv, "ecdhk163") == 0)\n ecdh_doit[R_EC_K163] = 2;\n else if (strcmp(*argv, "ecdhk233") == 0)\n ecdh_doit[R_EC_K233] = 2;\n else if (strcmp(*argv, "ecdhk283") == 0)\n ecdh_doit[R_EC_K283] = 2;\n else if (strcmp(*argv, "ecdhk409") == 0)\n ecdh_doit[R_EC_K409] = 2;\n else if (strcmp(*argv, "ecdhk571") == 0)\n ecdh_doit[R_EC_K571] = 2;\n else if (strcmp(*argv, "ecdhb163") == 0)\n ecdh_doit[R_EC_B163] = 2;\n else if (strcmp(*argv, "ecdhb233") == 0)\n ecdh_doit[R_EC_B233] = 2;\n else if (strcmp(*argv, "ecdhb283") == 0)\n ecdh_doit[R_EC_B283] = 2;\n else if (strcmp(*argv, "ecdhb409") == 0)\n ecdh_doit[R_EC_B409] = 2;\n else if (strcmp(*argv, "ecdhb571") == 0)\n ecdh_doit[R_EC_B571] = 2;\n else if (strcmp(*argv, "ecdh") == 0) {\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 1;\n } else\n# endif\n {\n BIO_printf(bio_err, "Error: bad option or value\\n");\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err, "Available values:\\n");\n# ifndef OPENSSL_NO_MD2\n BIO_printf(bio_err, "md2 ");\n# endif\n# ifndef OPENSSL_NO_MDC2\n BIO_printf(bio_err, "mdc2 ");\n# endif\n# ifndef OPENSSL_NO_MD4\n BIO_printf(bio_err, "md4 ");\n# endif\n# ifndef OPENSSL_NO_MD5\n BIO_printf(bio_err, "md5 ");\n# ifndef OPENSSL_NO_HMAC\n BIO_printf(bio_err, "hmac ");\n# endif\n# endif\n# ifndef OPENSSL_NO_SHA1\n BIO_printf(bio_err, "sha1 ");\n# endif\n# ifndef OPENSSL_NO_SHA256\n BIO_printf(bio_err, "sha256 ");\n# endif\n# ifndef OPENSSL_NO_SHA512\n BIO_printf(bio_err, "sha512 ");\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n BIO_printf(bio_err, "whirlpool");\n# endif\n# ifndef OPENSSL_NO_RMD160\n BIO_printf(bio_err, "rmd160");\n# endif\n# if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \\\n !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \\\n !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \\\n !defined(OPENSSL_NO_WHIRLPOOL)\n BIO_printf(bio_err, "\\n");\n# endif\n# ifndef OPENSSL_NO_IDEA\n BIO_printf(bio_err, "idea-cbc ");\n# endif\n# ifndef OPENSSL_NO_SEED\n BIO_printf(bio_err, "seed-cbc ");\n# endif\n# ifndef OPENSSL_NO_RC2\n BIO_printf(bio_err, "rc2-cbc ");\n# endif\n# ifndef OPENSSL_NO_RC5\n BIO_printf(bio_err, "rc5-cbc ");\n# endif\n# ifndef OPENSSL_NO_BF\n BIO_printf(bio_err, "bf-cbc");\n# endif\n# if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)\n BIO_printf(bio_err, "\\n");\n# endif\n# ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "des-cbc des-ede3 ");\n# endif\n# ifndef OPENSSL_NO_AES\n BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");\n BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err,\n "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");\n# endif\n# ifndef OPENSSL_NO_RC4\n BIO_printf(bio_err, "rc4");\n# endif\n BIO_printf(bio_err, "\\n");\n# ifndef OPENSSL_NO_RSA\n BIO_printf(bio_err,\n "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\\n");\n BIO_printf(bio_err, "rsa7680 rsa15360\\n");\n# endif\n# ifndef OPENSSL_NO_DSA\n BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\\n");\n# endif\n# ifndef OPENSSL_NO_ECDSA\n BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "\n "ecdsap256 ecdsap384 ecdsap521\\n");\n BIO_printf(bio_err,\n "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\\n");\n BIO_printf(bio_err,\n "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\\n");\n BIO_printf(bio_err, "ecdsa\\n");\n# endif\n# ifndef OPENSSL_NO_ECDH\n BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "\n "ecdhp256 ecdhp384 ecdhp521\\n");\n BIO_printf(bio_err,\n "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\\n");\n BIO_printf(bio_err,\n "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\\n");\n BIO_printf(bio_err, "ecdh\\n");\n# endif\n# ifndef OPENSSL_NO_IDEA\n BIO_printf(bio_err, "idea ");\n# endif\n# ifndef OPENSSL_NO_SEED\n BIO_printf(bio_err, "seed ");\n# endif\n# ifndef OPENSSL_NO_RC2\n BIO_printf(bio_err, "rc2 ");\n# endif\n# ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "des ");\n# endif\n# ifndef OPENSSL_NO_AES\n BIO_printf(bio_err, "aes ");\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n BIO_printf(bio_err, "camellia ");\n# endif\n# ifndef OPENSSL_NO_RSA\n BIO_printf(bio_err, "rsa ");\n# endif\n# ifndef OPENSSL_NO_BF\n BIO_printf(bio_err, "blowfish");\n# endif\n# if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \\\n !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \\\n !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \\\n !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)\n BIO_printf(bio_err, "\\n");\n# endif\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err, "Available options:\\n");\n# if defined(TIMES) || defined(USE_TOD)\n BIO_printf(bio_err, "-elapsed "\n "measure time in real time instead of CPU user time.\\n");\n# endif\n# ifndef OPENSSL_NO_ENGINE\n BIO_printf(bio_err,\n "-engine e "\n "use engine e, possibly a hardware device.\\n");\n# endif\n BIO_printf(bio_err, "-evp e " "use EVP e.\\n");\n BIO_printf(bio_err,\n "-decrypt "\n "time decryption instead of encryption (only EVP).\\n");\n BIO_printf(bio_err,\n "-mr "\n "produce machine readable output.\\n");\n BIO_printf(bio_err,\n "-mb "\n "perform multi-block benchmark (for specific ciphers)\\n");\n BIO_printf(bio_err,\n "-misalign n "\n "perform benchmark with misaligned data\\n");\n# ifndef NO_FORK\n BIO_printf(bio_err,\n "-multi n " "run n benchmarks in parallel.\\n");\n# endif\n goto end;\n }\n argc--;\n argv++;\n j++;\n }\n# ifndef NO_FORK\n if (multi && do_multi(multi))\n goto show_res;\n# endif\n if (j == 0) {\n for (i = 0; i < ALGOR_NUM; i++) {\n if (i != D_EVP)\n doit[i] = 1;\n }\n for (i = 0; i < RSA_NUM; i++)\n rsa_doit[i] = 1;\n for (i = 0; i < DSA_NUM; i++)\n dsa_doit[i] = 1;\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 1;\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 1;\n# endif\n }\n for (i = 0; i < ALGOR_NUM; i++)\n if (doit[i])\n pr_header++;\n if (usertime == 0 && !mr)\n BIO_printf(bio_err,\n "You have chosen to measure elapsed time "\n "instead of user CPU time.\\n");\n# ifndef OPENSSL_NO_RSA\n for (i = 0; i < RSA_NUM; i++) {\n const unsigned char *p;\n p = rsa_data[i];\n rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);\n if (rsa_key[i] == NULL) {\n BIO_printf(bio_err, "internal error loading RSA key number %d\\n",\n i);\n goto end;\n }\n# if 0\n else {\n BIO_printf(bio_err,\n mr ? "+RK:%d:"\n : "Loaded RSA key, %d bit modulus and e= 0x",\n BN_num_bits(rsa_key[i]->n));\n BN_print(bio_err, rsa_key[i]->e);\n BIO_printf(bio_err, "\\n");\n }\n# endif\n }\n# endif\n# ifndef OPENSSL_NO_DSA\n dsa_key[0] = get_dsa512();\n dsa_key[1] = get_dsa1024();\n dsa_key[2] = get_dsa2048();\n# endif\n# ifndef OPENSSL_NO_DES\n DES_set_key_unchecked(&key, &sch);\n DES_set_key_unchecked(&key2, &sch2);\n DES_set_key_unchecked(&key3, &sch3);\n# endif\n# ifndef OPENSSL_NO_AES\n AES_set_encrypt_key(key16, 128, &aes_ks1);\n AES_set_encrypt_key(key24, 192, &aes_ks2);\n AES_set_encrypt_key(key32, 256, &aes_ks3);\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n Camellia_set_key(key16, 128, &camellia_ks1);\n Camellia_set_key(ckey24, 192, &camellia_ks2);\n Camellia_set_key(ckey32, 256, &camellia_ks3);\n# endif\n# ifndef OPENSSL_NO_IDEA\n idea_set_encrypt_key(key16, &idea_ks);\n# endif\n# ifndef OPENSSL_NO_SEED\n SEED_set_key(key16, &seed_ks);\n# endif\n# ifndef OPENSSL_NO_RC4\n RC4_set_key(&rc4_ks, 16, key16);\n# endif\n# ifndef OPENSSL_NO_RC2\n RC2_set_key(&rc2_ks, 16, key16, 128);\n# endif\n# ifndef OPENSSL_NO_RC5\n RC5_32_set_key(&rc5_ks, 16, key16, 12);\n# endif\n# ifndef OPENSSL_NO_BF\n BF_set_key(&bf_ks, 16, key16);\n# endif\n# ifndef OPENSSL_NO_CAST\n CAST_set_key(&cast_ks, 16, key16);\n# endif\n# ifndef OPENSSL_NO_RSA\n memset(rsa_c, 0, sizeof(rsa_c));\n# endif\n# ifndef SIGALRM\n# ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "First we calculate the approximate speed ...\\n");\n count = 10;\n do {\n long it;\n count *= 2;\n Time_F(START);\n for (it = count; it; it--)\n DES_ecb_encrypt((DES_cblock *)buf,\n (DES_cblock *)buf, &sch, DES_ENCRYPT);\n d = Time_F(STOP);\n } while (d < 3);\n save_count = count;\n c[D_MD2][0] = count / 10;\n c[D_MDC2][0] = count / 10;\n c[D_MD4][0] = count;\n c[D_MD5][0] = count;\n c[D_HMAC][0] = count;\n c[D_SHA1][0] = count;\n c[D_RMD160][0] = count;\n c[D_RC4][0] = count * 5;\n c[D_CBC_DES][0] = count;\n c[D_EDE3_DES][0] = count / 3;\n c[D_CBC_IDEA][0] = count;\n c[D_CBC_SEED][0] = count;\n c[D_CBC_RC2][0] = count;\n c[D_CBC_RC5][0] = count;\n c[D_CBC_BF][0] = count;\n c[D_CBC_CAST][0] = count;\n c[D_CBC_128_AES][0] = count;\n c[D_CBC_192_AES][0] = count;\n c[D_CBC_256_AES][0] = count;\n c[D_CBC_128_CML][0] = count;\n c[D_CBC_192_CML][0] = count;\n c[D_CBC_256_CML][0] = count;\n c[D_SHA256][0] = count;\n c[D_SHA512][0] = count;\n c[D_WHIRLPOOL][0] = count;\n c[D_IGE_128_AES][0] = count;\n c[D_IGE_192_AES][0] = count;\n c[D_IGE_256_AES][0] = count;\n c[D_GHASH][0] = count;\n for (i = 1; i < SIZE_NUM; i++) {\n long l0, l1;\n l0 = (long)lengths[0];\n l1 = (long)lengths[i];\n c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;\n c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;\n c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;\n c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;\n c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;\n c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;\n c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;\n c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;\n c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;\n c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;\n l0 = (long)lengths[i - 1];\n c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;\n c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;\n c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;\n c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;\n c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;\n c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;\n c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;\n c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;\n c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;\n c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;\n c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;\n c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;\n c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;\n c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;\n c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;\n c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;\n c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;\n c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;\n }\n# ifndef OPENSSL_NO_RSA\n rsa_c[R_RSA_512][0] = count / 2000;\n rsa_c[R_RSA_512][1] = count / 400;\n for (i = 1; i < RSA_NUM; i++) {\n rsa_c[i][0] = rsa_c[i - 1][0] / 8;\n rsa_c[i][1] = rsa_c[i - 1][1] / 4;\n if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))\n rsa_doit[i] = 0;\n else {\n if (rsa_c[i][0] == 0) {\n rsa_c[i][0] = 1;\n rsa_c[i][1] = 20;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_DSA\n dsa_c[R_DSA_512][0] = count / 1000;\n dsa_c[R_DSA_512][1] = count / 1000 / 2;\n for (i = 1; i < DSA_NUM; i++) {\n dsa_c[i][0] = dsa_c[i - 1][0] / 4;\n dsa_c[i][1] = dsa_c[i - 1][1] / 4;\n if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))\n dsa_doit[i] = 0;\n else {\n if (dsa_c[i] == 0) {\n dsa_c[i][0] = 1;\n dsa_c[i][1] = 1;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_ECDSA\n ecdsa_c[R_EC_P160][0] = count / 1000;\n ecdsa_c[R_EC_P160][1] = count / 1000 / 2;\n for (i = R_EC_P192; i <= R_EC_P521; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n ecdsa_c[R_EC_K163][0] = count / 1000;\n ecdsa_c[R_EC_K163][1] = count / 1000 / 2;\n for (i = R_EC_K233; i <= R_EC_K571; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n ecdsa_c[R_EC_B163][0] = count / 1000;\n ecdsa_c[R_EC_B163][1] = count / 1000 / 2;\n for (i = R_EC_B233; i <= R_EC_B571; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_ECDH\n ecdh_c[R_EC_P160][0] = count / 1000;\n ecdh_c[R_EC_P160][1] = count / 1000;\n for (i = R_EC_P192; i <= R_EC_P521; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n ecdh_c[R_EC_K163][0] = count / 1000;\n ecdh_c[R_EC_K163][1] = count / 1000;\n for (i = R_EC_K233; i <= R_EC_K571; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n ecdh_c[R_EC_B163][0] = count / 1000;\n ecdh_c[R_EC_B163][1] = count / 1000;\n for (i = R_EC_B233; i <= R_EC_B571; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n# endif\n# define COND(d) (count < (d))\n# define COUNT(d) (d)\n# else\n# error "You cannot disable DES on systems without SIGALRM."\n# endif\n# else\n# define COND(c) (run && count<0x7fffffff)\n# define COUNT(d) (count)\n# ifndef _WIN32\n signal(SIGALRM, sig_done);\n# endif\n# endif\n# ifndef OPENSSL_NO_MD2\n if (doit[D_MD2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD2], c[D_MD2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD2][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,\n EVP_md2(), NULL);\n d = Time_F(STOP);\n print_result(D_MD2, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_MDC2\n if (doit[D_MDC2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,\n EVP_mdc2(), NULL);\n d = Time_F(STOP);\n print_result(D_MDC2, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_MD4\n if (doit[D_MD4]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD4], c[D_MD4][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD4][j]); count++)\n EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),\n NULL, EVP_md4(), NULL);\n d = Time_F(STOP);\n print_result(D_MD4, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_MD5\n if (doit[D_MD5]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD5], c[D_MD5][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD5][j]); count++)\n MD5(buf, lengths[j], md5);\n d = Time_F(STOP);\n print_result(D_MD5, j, count, d);\n }\n }\n# endif\n# if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)\n if (doit[D_HMAC]) {\n HMAC_CTX hctx;\n HMAC_CTX_init(&hctx);\n HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",\n 16, EVP_md5(), NULL);\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {\n HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);\n HMAC_Update(&hctx, buf, lengths[j]);\n HMAC_Final(&hctx, &(hmac[0]), NULL);\n }\n d = Time_F(STOP);\n print_result(D_HMAC, j, count, d);\n }\n HMAC_CTX_cleanup(&hctx);\n }\n# endif\n# ifndef OPENSSL_NO_SHA\n if (doit[D_SHA1]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)\n# if 0\n EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,\n EVP_sha1(), NULL);\n# else\n SHA1(buf, lengths[j], sha);\n# endif\n d = Time_F(STOP);\n print_result(D_SHA1, j, count, d);\n }\n }\n# ifndef OPENSSL_NO_SHA256\n if (doit[D_SHA256]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)\n SHA256(buf, lengths[j], sha256);\n d = Time_F(STOP);\n print_result(D_SHA256, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_SHA512\n if (doit[D_SHA512]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)\n SHA512(buf, lengths[j], sha512);\n d = Time_F(STOP);\n print_result(D_SHA512, j, count, d);\n }\n }\n# endif\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n if (doit[D_WHIRLPOOL]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)\n WHIRLPOOL(buf, lengths[j], whirlpool);\n d = Time_F(STOP);\n print_result(D_WHIRLPOOL, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RMD160\n if (doit[D_RMD160]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,\n EVP_ripemd160(), NULL);\n d = Time_F(STOP);\n print_result(D_RMD160, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RC4\n if (doit[D_RC4]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_RC4], c[D_RC4][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_RC4][j]); count++)\n RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);\n d = Time_F(STOP);\n print_result(D_RC4, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_DES\n if (doit[D_CBC_DES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)\n DES_ncbc_encrypt(buf, buf, lengths[j], &sch,\n &DES_iv, DES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_DES, j, count, d);\n }\n }\n if (doit[D_EDE3_DES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)\n DES_ede3_cbc_encrypt(buf, buf, lengths[j],\n &sch, &sch2, &sch3,\n &DES_iv, DES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_EDE3_DES, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_AES\n if (doit[D_CBC_128_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks1,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_128_AES, j, count, d);\n }\n }\n if (doit[D_CBC_192_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks2,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_192_AES, j, count, d);\n }\n }\n if (doit[D_CBC_256_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks3,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_256_AES, j, count, d);\n }\n }\n if (doit[D_IGE_128_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks1,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_128_AES, j, count, d);\n }\n }\n if (doit[D_IGE_192_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks2,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_192_AES, j, count, d);\n }\n }\n if (doit[D_IGE_256_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks3,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_256_AES, j, count, d);\n }\n }\n if (doit[D_GHASH]) {\n GCM128_CONTEXT *ctx =\n CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);\n CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)\n CRYPTO_gcm128_aad(ctx, buf, lengths[j]);\n d = Time_F(STOP);\n print_result(D_GHASH, j, count, d);\n }\n CRYPTO_gcm128_release(ctx);\n }\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n if (doit[D_CBC_128_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks1,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_128_CML, j, count, d);\n }\n }\n if (doit[D_CBC_192_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks2,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_192_CML, j, count, d);\n }\n }\n if (doit[D_CBC_256_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks3,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_256_CML, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_IDEA\n if (doit[D_CBC_IDEA]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)\n idea_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &idea_ks,\n iv, IDEA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_IDEA, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_SEED\n if (doit[D_CBC_SEED]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)\n SEED_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &seed_ks, iv, 1);\n d = Time_F(STOP);\n print_result(D_CBC_SEED, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RC2\n if (doit[D_CBC_RC2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)\n RC2_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &rc2_ks,\n iv, RC2_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_RC2, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RC5\n if (doit[D_CBC_RC5]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)\n RC5_32_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &rc5_ks,\n iv, RC5_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_RC5, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_BF\n if (doit[D_CBC_BF]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)\n BF_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &bf_ks,\n iv, BF_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_BF, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_CAST\n if (doit[D_CBC_CAST]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)\n CAST_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &cast_ks,\n iv, CAST_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_CAST, j, count, d);\n }\n }\n# endif\n if (doit[D_EVP]) {\n# ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK\n if (multiblock && evp_cipher) {\n if (!\n (EVP_CIPHER_flags(evp_cipher) &\n EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {\n fprintf(stderr, "%s is not multi-block capable\\n",\n OBJ_nid2ln(evp_cipher->nid));\n goto end;\n }\n multiblock_speed(evp_cipher);\n mret = 0;\n goto end;\n }\n# endif\n for (j = 0; j < SIZE_NUM; j++) {\n if (evp_cipher) {\n EVP_CIPHER_CTX ctx;\n int outl;\n names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);\n print_message(names[D_EVP], save_count, lengths[j]);\n EVP_CIPHER_CTX_init(&ctx);\n if (decrypt)\n EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);\n else\n EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);\n EVP_CIPHER_CTX_set_padding(&ctx, 0);\n Time_F(START);\n if (decrypt)\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]);\n count++)\n EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);\n else\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]);\n count++)\n EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);\n if (decrypt)\n EVP_DecryptFinal_ex(&ctx, buf, &outl);\n else\n EVP_EncryptFinal_ex(&ctx, buf, &outl);\n d = Time_F(STOP);\n EVP_CIPHER_CTX_cleanup(&ctx);\n }\n if (evp_md) {\n names[D_EVP] = OBJ_nid2ln(evp_md->type);\n print_message(names[D_EVP], save_count, lengths[j]);\n Time_F(START);\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]); count++)\n EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);\n d = Time_F(STOP);\n }\n print_result(D_EVP, j, count, d);\n }\n }\n# ifndef OPENSSL_SYS_WIN32\n# endif\n RAND_pseudo_bytes(buf, 36);\n# ifndef OPENSSL_NO_RSA\n for (j = 0; j < RSA_NUM; j++) {\n int ret;\n if (!rsa_doit[j])\n continue;\n ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "RSA sign failure. No RSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("private", "rsa",\n rsa_c[j][0], rsa_bits[j], RSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {\n ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,\n &rsa_num, rsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "RSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R1:%ld:%d:%.2f\\n"\n : "%ld %d bit private RSA\'s in %.2fs\\n",\n count, rsa_bits[j], d);\n rsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n# if 1\n ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err,\n "RSA verify failure. No RSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_doit[j] = 0;\n } else {\n pkey_print_message("public", "rsa",\n rsa_c[j][1], rsa_bits[j], RSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {\n ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,\n rsa_num, rsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err, "RSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R2:%ld:%d:%.2f\\n"\n : "%ld %d bit public RSA\'s in %.2fs\\n",\n count, rsa_bits[j], d);\n rsa_results[j][1] = d / (double)count;\n }\n# endif\n if (rsa_count <= 1) {\n for (j++; j < RSA_NUM; j++)\n rsa_doit[j] = 0;\n }\n }\n# endif\n RAND_pseudo_bytes(buf, 20);\n# ifndef OPENSSL_NO_DSA\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < DSA_NUM; j++) {\n unsigned int kk;\n int ret;\n if (!dsa_doit[j])\n continue;\n ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "DSA sign failure. No DSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("sign", "dsa",\n dsa_c[j][0], dsa_bits[j], DSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {\n ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "DSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R3:%ld:%d:%.2f\\n"\n : "%ld %d bit DSA signs in %.2fs\\n",\n count, dsa_bits[j], d);\n dsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err,\n "DSA verify failure. No DSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n dsa_doit[j] = 0;\n } else {\n pkey_print_message("verify", "dsa",\n dsa_c[j][1], dsa_bits[j], DSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {\n ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err, "DSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R4:%ld:%d:%.2f\\n"\n : "%ld %d bit DSA verify in %.2fs\\n",\n count, dsa_bits[j], d);\n dsa_results[j][1] = d / (double)count;\n }\n if (rsa_count <= 1) {\n for (j++; j < DSA_NUM; j++)\n dsa_doit[j] = 0;\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n# endif\n# ifndef OPENSSL_NO_ECDSA\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < EC_NUM; j++) {\n int ret;\n if (!ecdsa_doit[j])\n continue;\n ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n if (ecdsa[j] == NULL) {\n BIO_printf(bio_err, "ECDSA failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n# if 1\n EC_KEY_precompute_mult(ecdsa[j], NULL);\n# endif\n EC_KEY_generate_key(ecdsa[j]);\n ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "ECDSA sign failure. No ECDSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("sign", "ecdsa",\n ecdsa_c[j][0],\n test_curves_bits[j], ECDSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {\n ret = ECDSA_sign(0, buf, 20,\n ecdsasig, &ecdsasiglen, ecdsa[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "ECDSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R5:%ld:%d:%.2f\\n" :\n "%ld %d bit ECDSA signs in %.2fs \\n",\n count, test_curves_bits[j], d);\n ecdsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);\n if (ret != 1) {\n BIO_printf(bio_err,\n "ECDSA verify failure. No ECDSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n ecdsa_doit[j] = 0;\n } else {\n pkey_print_message("verify", "ecdsa",\n ecdsa_c[j][1],\n test_curves_bits[j], ECDSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {\n ret =\n ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,\n ecdsa[j]);\n if (ret != 1) {\n BIO_printf(bio_err, "ECDSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R6:%ld:%d:%.2f\\n"\n : "%ld %d bit ECDSA verify in %.2fs\\n",\n count, test_curves_bits[j], d);\n ecdsa_results[j][1] = d / (double)count;\n }\n if (rsa_count <= 1) {\n for (j++; j < EC_NUM; j++)\n ecdsa_doit[j] = 0;\n }\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n# endif\n# ifndef OPENSSL_NO_ECDH\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < EC_NUM; j++) {\n if (!ecdh_doit[j])\n continue;\n ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {\n BIO_printf(bio_err, "ECDH failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n if (!EC_KEY_generate_key(ecdh_a[j]) ||\n !EC_KEY_generate_key(ecdh_b[j])) {\n BIO_printf(bio_err, "ECDH key generation failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n int field_size, outlen;\n void *(*kdf) (const void *in, size_t inlen, void *out,\n size_t *xoutlen);\n field_size =\n EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));\n if (field_size <= 24 * 8) {\n outlen = KDF1_SHA1_len;\n kdf = KDF1_SHA1;\n } else {\n outlen = (field_size + 7) / 8;\n kdf = NULL;\n }\n secret_size_a =\n ECDH_compute_key(secret_a, outlen,\n EC_KEY_get0_public_key(ecdh_b[j]),\n ecdh_a[j], kdf);\n secret_size_b =\n ECDH_compute_key(secret_b, outlen,\n EC_KEY_get0_public_key(ecdh_a[j]),\n ecdh_b[j], kdf);\n if (secret_size_a != secret_size_b)\n ecdh_checks = 0;\n else\n ecdh_checks = 1;\n for (secret_idx = 0; (secret_idx < secret_size_a)\n && (ecdh_checks == 1); secret_idx++) {\n if (secret_a[secret_idx] != secret_b[secret_idx])\n ecdh_checks = 0;\n }\n if (ecdh_checks == 0) {\n BIO_printf(bio_err, "ECDH computations don\'t match.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n }\n pkey_print_message("", "ecdh",\n ecdh_c[j][0],\n test_curves_bits[j], ECDH_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {\n ECDH_compute_key(secret_a, outlen,\n EC_KEY_get0_public_key(ecdh_b[j]),\n ecdh_a[j], kdf);\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R7:%ld:%d:%.2f\\n" :\n "%ld %d-bit ECDH ops in %.2fs\\n", count,\n test_curves_bits[j], d);\n ecdh_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n }\n if (rsa_count <= 1) {\n for (j++; j < EC_NUM; j++)\n ecdh_doit[j] = 0;\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n# endif\n# ifndef NO_FORK\n show_res:\n# endif\n if (!mr) {\n fprintf(stdout, "%s\\n", SSLeay_version(SSLEAY_VERSION));\n fprintf(stdout, "%s\\n", SSLeay_version(SSLEAY_BUILT_ON));\n printf("options:");\n printf("%s ", BN_options());\n# ifndef OPENSSL_NO_MD2\n printf("%s ", MD2_options());\n# endif\n# ifndef OPENSSL_NO_RC4\n printf("%s ", RC4_options());\n# endif\n# ifndef OPENSSL_NO_DES\n printf("%s ", DES_options());\n# endif\n# ifndef OPENSSL_NO_AES\n printf("%s ", AES_options());\n# endif\n# ifndef OPENSSL_NO_IDEA\n printf("%s ", idea_options());\n# endif\n# ifndef OPENSSL_NO_BF\n printf("%s ", BF_options());\n# endif\n fprintf(stdout, "\\n%s\\n", SSLeay_version(SSLEAY_CFLAGS));\n }\n if (pr_header) {\n if (mr)\n fprintf(stdout, "+H");\n else {\n fprintf(stdout,\n "The \'numbers\' are in 1000s of bytes per second processed.\\n");\n fprintf(stdout, "type ");\n }\n for (j = 0; j < SIZE_NUM; j++)\n fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);\n fprintf(stdout, "\\n");\n }\n for (k = 0; k < ALGOR_NUM; k++) {\n if (!doit[k])\n continue;\n if (mr)\n fprintf(stdout, "+F:%d:%s", k, names[k]);\n else\n fprintf(stdout, "%-13s", names[k]);\n for (j = 0; j < SIZE_NUM; j++) {\n if (results[k][j] > 10000 && !mr)\n fprintf(stdout, " %11.2fk", results[k][j] / 1e3);\n else\n fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);\n }\n fprintf(stdout, "\\n");\n }\n# ifndef OPENSSL_NO_RSA\n j = 1;\n for (k = 0; k < RSA_NUM; k++) {\n if (!rsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%18ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F2:%u:%u:%f:%f\\n",\n k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);\n else\n fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n rsa_bits[k], rsa_results[k][0], rsa_results[k][1],\n 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);\n }\n# endif\n# ifndef OPENSSL_NO_DSA\n j = 1;\n for (k = 0; k < DSA_NUM; k++) {\n if (!dsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%18ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F3:%u:%u:%f:%f\\n",\n k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);\n else\n fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n dsa_bits[k], dsa_results[k][0], dsa_results[k][1],\n 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);\n }\n# endif\n# ifndef OPENSSL_NO_ECDSA\n j = 1;\n for (k = 0; k < EC_NUM; k++) {\n if (!ecdsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%30ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F4:%u:%u:%f:%f\\n",\n k, test_curves_bits[k],\n ecdsa_results[k][0], ecdsa_results[k][1]);\n else\n fprintf(stdout,\n "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\\n",\n test_curves_bits[k],\n test_curves_names[k],\n ecdsa_results[k][0], ecdsa_results[k][1],\n 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);\n }\n# endif\n# ifndef OPENSSL_NO_ECDH\n j = 1;\n for (k = 0; k < EC_NUM; k++) {\n if (!ecdh_doit[k])\n continue;\n if (j && !mr) {\n printf("%30sop op/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F5:%u:%u:%f:%f\\n",\n k, test_curves_bits[k],\n ecdh_results[k][0], 1.0 / ecdh_results[k][0]);\n else\n fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\\n",\n test_curves_bits[k],\n test_curves_names[k],\n ecdh_results[k][0], 1.0 / ecdh_results[k][0]);\n }\n# endif\n mret = 0;\n end:\n ERR_print_errors(bio_err);\n if (buf_malloc != NULL)\n OPENSSL_free(buf_malloc);\n if (buf2_malloc != NULL)\n OPENSSL_free(buf2_malloc);\n# ifndef OPENSSL_NO_RSA\n for (i = 0; i < RSA_NUM; i++)\n if (rsa_key[i] != NULL)\n RSA_free(rsa_key[i]);\n# endif\n# ifndef OPENSSL_NO_DSA\n for (i = 0; i < DSA_NUM; i++)\n if (dsa_key[i] != NULL)\n DSA_free(dsa_key[i]);\n# endif\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n if (ecdsa[i] != NULL)\n EC_KEY_free(ecdsa[i]);\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++) {\n if (ecdh_a[i] != NULL)\n EC_KEY_free(ecdh_a[i]);\n if (ecdh_b[i] != NULL)\n EC_KEY_free(ecdh_b[i]);\n }\n# endif\n apps_shutdown();\n OPENSSL_EXIT(mret);\n}'] |
34,344 | 1 | https://github.com/apache/httpd/blob/81af07c707b365c9a3fd7f98adc86d02e90275e1/server/protocol.c/#L453 | AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
apr_size_t *read, request_rec *r,
int flags, apr_bucket_brigade *bb)
{
apr_status_t rv;
apr_bucket *e;
apr_size_t bytes_handled = 0, current_alloc = 0;
char *pos, *last_char = *s;
int do_alloc = (*s == NULL), saw_eos = 0;
int fold = flags & AP_GETLINE_FOLD;
int crlf = flags & AP_GETLINE_CRLF;
if (!n) {
*read = 0;
return APR_BADARG;
}
if (last_char)
*last_char = '\0';
for (;;) {
apr_brigade_cleanup(bb);
rv = ap_get_brigade(r->proto_input_filters, bb, AP_MODE_GETLINE,
APR_BLOCK_READ, 0);
if (rv != APR_SUCCESS) {
goto cleanup;
}
if (APR_BRIGADE_EMPTY(bb)) {
rv = APR_EGENERAL;
goto cleanup;
}
for (e = APR_BRIGADE_FIRST(bb);
e != APR_BRIGADE_SENTINEL(bb);
e = APR_BUCKET_NEXT(e))
{
const char *str;
apr_size_t len;
if (APR_BUCKET_IS_EOS(e)) {
saw_eos = 1;
break;
}
rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ);
if (rv != APR_SUCCESS) {
goto cleanup;
}
if (len == 0) {
continue;
}
if (n < bytes_handled + len) {
rv = APR_ENOSPC;
goto cleanup;
}
if (do_alloc) {
if (!*s) {
current_alloc = len;
*s = apr_palloc(r->pool, current_alloc + 1);
}
else if (bytes_handled + len > current_alloc) {
apr_size_t new_size = current_alloc * 2;
char *new_buffer;
if (bytes_handled + len > new_size) {
new_size = (bytes_handled + len) * 2;
}
new_buffer = apr_palloc(r->pool, new_size + 1);
memcpy(new_buffer, *s, bytes_handled);
current_alloc = new_size;
*s = new_buffer;
}
}
pos = *s + bytes_handled;
memcpy(pos, str, len);
last_char = pos + len - 1;
bytes_handled += len;
}
if (last_char && (*last_char == APR_ASCII_LF)) {
break;
}
}
if (last_char > *s && last_char[-1] == APR_ASCII_CR) {
last_char--;
}
else if (crlf) {
rv = APR_EINVAL;
goto cleanup;
}
bytes_handled = last_char - *s;
if (fold && bytes_handled && !saw_eos) {
for (;;) {
const char *str;
apr_size_t len;
char c;
apr_brigade_cleanup(bb);
rv = ap_get_brigade(r->proto_input_filters, bb, AP_MODE_SPECULATIVE,
APR_BLOCK_READ, 1);
if (rv != APR_SUCCESS) {
goto cleanup;
}
if (APR_BRIGADE_EMPTY(bb)) {
break;
}
e = APR_BRIGADE_FIRST(bb);
if (APR_BUCKET_IS_EOS(e)) {
break;
}
rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ);
if (rv != APR_SUCCESS) {
apr_brigade_cleanup(bb);
goto cleanup;
}
c = *str;
if (c == APR_ASCII_BLANK || c == APR_ASCII_TAB) {
if (bytes_handled >= n) {
rv = APR_ENOSPC;
goto cleanup;
}
else {
apr_size_t next_size, next_len;
char *tmp;
if (do_alloc) {
tmp = NULL;
}
else {
tmp = last_char;
}
next_size = n - bytes_handled;
rv = ap_rgetline_core(&tmp, next_size,
&next_len, r, 0, bb);
if (rv != APR_SUCCESS) {
goto cleanup;
}
if (do_alloc && next_len > 0) {
char *new_buffer;
apr_size_t new_size = bytes_handled + next_len + 1;
new_buffer = apr_palloc(r->pool, new_size);
memcpy(new_buffer, *s, bytes_handled);
memcpy(new_buffer + bytes_handled, tmp, next_len);
*s = new_buffer;
}
last_char += next_len;
bytes_handled += next_len;
}
}
else {
break;
}
}
}
cleanup:
if (bytes_handled >= n) {
bytes_handled = n - 1;
}
if (*s) {
(*s)[bytes_handled] = '\0';
}
*read = bytes_handled;
if (rv != APR_SUCCESS) {
return rv;
}
if (strlen(*s) < bytes_handled) {
return APR_EINVAL;
}
return APR_SUCCESS;
} | ["AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,\n apr_size_t *read, request_rec *r,\n int flags, apr_bucket_brigade *bb)\n{\n apr_status_t rv;\n apr_bucket *e;\n apr_size_t bytes_handled = 0, current_alloc = 0;\n char *pos, *last_char = *s;\n int do_alloc = (*s == NULL), saw_eos = 0;\n int fold = flags & AP_GETLINE_FOLD;\n int crlf = flags & AP_GETLINE_CRLF;\n if (!n) {\n *read = 0;\n return APR_BADARG;\n }\n if (last_char)\n *last_char = '\\0';\n for (;;) {\n apr_brigade_cleanup(bb);\n rv = ap_get_brigade(r->proto_input_filters, bb, AP_MODE_GETLINE,\n APR_BLOCK_READ, 0);\n if (rv != APR_SUCCESS) {\n goto cleanup;\n }\n if (APR_BRIGADE_EMPTY(bb)) {\n rv = APR_EGENERAL;\n goto cleanup;\n }\n for (e = APR_BRIGADE_FIRST(bb);\n e != APR_BRIGADE_SENTINEL(bb);\n e = APR_BUCKET_NEXT(e))\n {\n const char *str;\n apr_size_t len;\n if (APR_BUCKET_IS_EOS(e)) {\n saw_eos = 1;\n break;\n }\n rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ);\n if (rv != APR_SUCCESS) {\n goto cleanup;\n }\n if (len == 0) {\n continue;\n }\n if (n < bytes_handled + len) {\n rv = APR_ENOSPC;\n goto cleanup;\n }\n if (do_alloc) {\n if (!*s) {\n current_alloc = len;\n *s = apr_palloc(r->pool, current_alloc + 1);\n }\n else if (bytes_handled + len > current_alloc) {\n apr_size_t new_size = current_alloc * 2;\n char *new_buffer;\n if (bytes_handled + len > new_size) {\n new_size = (bytes_handled + len) * 2;\n }\n new_buffer = apr_palloc(r->pool, new_size + 1);\n memcpy(new_buffer, *s, bytes_handled);\n current_alloc = new_size;\n *s = new_buffer;\n }\n }\n pos = *s + bytes_handled;\n memcpy(pos, str, len);\n last_char = pos + len - 1;\n bytes_handled += len;\n }\n if (last_char && (*last_char == APR_ASCII_LF)) {\n break;\n }\n }\n if (last_char > *s && last_char[-1] == APR_ASCII_CR) {\n last_char--;\n }\n else if (crlf) {\n rv = APR_EINVAL;\n goto cleanup;\n }\n bytes_handled = last_char - *s;\n if (fold && bytes_handled && !saw_eos) {\n for (;;) {\n const char *str;\n apr_size_t len;\n char c;\n apr_brigade_cleanup(bb);\n rv = ap_get_brigade(r->proto_input_filters, bb, AP_MODE_SPECULATIVE,\n APR_BLOCK_READ, 1);\n if (rv != APR_SUCCESS) {\n goto cleanup;\n }\n if (APR_BRIGADE_EMPTY(bb)) {\n break;\n }\n e = APR_BRIGADE_FIRST(bb);\n if (APR_BUCKET_IS_EOS(e)) {\n break;\n }\n rv = apr_bucket_read(e, &str, &len, APR_BLOCK_READ);\n if (rv != APR_SUCCESS) {\n apr_brigade_cleanup(bb);\n goto cleanup;\n }\n c = *str;\n if (c == APR_ASCII_BLANK || c == APR_ASCII_TAB) {\n if (bytes_handled >= n) {\n rv = APR_ENOSPC;\n goto cleanup;\n }\n else {\n apr_size_t next_size, next_len;\n char *tmp;\n if (do_alloc) {\n tmp = NULL;\n }\n else {\n tmp = last_char;\n }\n next_size = n - bytes_handled;\n rv = ap_rgetline_core(&tmp, next_size,\n &next_len, r, 0, bb);\n if (rv != APR_SUCCESS) {\n goto cleanup;\n }\n if (do_alloc && next_len > 0) {\n char *new_buffer;\n apr_size_t new_size = bytes_handled + next_len + 1;\n new_buffer = apr_palloc(r->pool, new_size);\n memcpy(new_buffer, *s, bytes_handled);\n memcpy(new_buffer + bytes_handled, tmp, next_len);\n *s = new_buffer;\n }\n last_char += next_len;\n bytes_handled += next_len;\n }\n }\n else {\n break;\n }\n }\n }\ncleanup:\n if (bytes_handled >= n) {\n bytes_handled = n - 1;\n }\n if (*s) {\n (*s)[bytes_handled] = '\\0';\n }\n *read = bytes_handled;\n if (rv != APR_SUCCESS) {\n return rv;\n }\n if (strlen(*s) < bytes_handled) {\n return APR_EINVAL;\n }\n return APR_SUCCESS;\n}"] |
34,345 | 0 | https://github.com/nginx/nginx/blob/3d791c46f5eddaa620be1f8a90b53b7c7aaa4cf3/src/core/ngx_inet.c/#L561 | static ngx_int_t
ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u)
{
#if (NGX_HAVE_UNIX_DOMAIN)
u_char *path, *uri, *last;
size_t len;
struct sockaddr_un *saun;
len = u->url.len;
path = u->url.data;
path += 5;
len -= 5;
if (u->uri_part) {
last = path + len;
uri = ngx_strlchr(path, last, ':');
if (uri) {
len = uri - path;
uri++;
u->uri.len = last - uri;
u->uri.data = uri;
}
}
if (len == 0) {
u->err = "no path in the unix domain socket";
return NGX_ERROR;
}
u->host.len = len++;
u->host.data = path;
if (len > sizeof(saun->sun_path)) {
u->err = "too long path in the unix domain socket";
return NGX_ERROR;
}
u->socklen = sizeof(struct sockaddr_un);
saun = (struct sockaddr_un *) &u->sockaddr;
saun->sun_family = AF_UNIX;
(void) ngx_cpystrn((u_char *) saun->sun_path, path, len);
u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t));
if (u->addrs == NULL) {
return NGX_ERROR;
}
saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un));
if (saun == NULL) {
return NGX_ERROR;
}
u->family = AF_UNIX;
u->naddrs = 1;
saun->sun_family = AF_UNIX;
(void) ngx_cpystrn((u_char *) saun->sun_path, path, len);
u->addrs[0].sockaddr = (struct sockaddr *) saun;
u->addrs[0].socklen = sizeof(struct sockaddr_un);
u->addrs[0].name.len = len + 4;
u->addrs[0].name.data = u->url.data;
return NGX_OK;
#else
u->err = "the unix domain sockets are not supported on this platform";
return NGX_ERROR;
#endif
} | ['static ngx_int_t\nngx_http_fastcgi_eval(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)\n{\n ngx_url_t url;\n ngx_http_upstream_t *u;\n ngx_memzero(&url, sizeof(ngx_url_t));\n if (ngx_http_script_run(r, &url.url, flcf->fastcgi_lengths->elts, 0,\n flcf->fastcgi_values->elts)\n == NULL)\n {\n return NGX_ERROR;\n }\n url.no_resolve = 1;\n if (ngx_parse_url(r->pool, &url) != NGX_OK) {\n if (url.err) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "%s in upstream \\"%V\\"", url.err, &url.url);\n }\n return NGX_ERROR;\n }\n u = r->upstream;\n u->resolved = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_resolved_t));\n if (u->resolved == NULL) {\n return NGX_ERROR;\n }\n if (url.addrs && url.addrs[0].sockaddr) {\n u->resolved->sockaddr = url.addrs[0].sockaddr;\n u->resolved->socklen = url.addrs[0].socklen;\n u->resolved->naddrs = 1;\n u->resolved->host = url.addrs[0].name;\n } else {\n u->resolved->host = url.host;\n }\n u->resolved->port = url.port;\n u->resolved->no_port = url.no_port;\n return NGX_OK;\n}', 'u_char *\nngx_http_script_run(ngx_http_request_t *r, ngx_str_t *value,\n void *code_lengths, size_t len, void *code_values)\n{\n ngx_uint_t i;\n ngx_http_script_code_pt code;\n ngx_http_script_len_code_pt lcode;\n ngx_http_script_engine_t e;\n ngx_http_core_main_conf_t *cmcf;\n cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);\n for (i = 0; i < cmcf->variables.nelts; i++) {\n if (r->variables[i].no_cacheable) {\n r->variables[i].valid = 0;\n r->variables[i].not_found = 0;\n }\n }\n ngx_memzero(&e, sizeof(ngx_http_script_engine_t));\n e.ip = code_lengths;\n e.request = r;\n e.flushed = 1;\n while (*(uintptr_t *) e.ip) {\n lcode = *(ngx_http_script_len_code_pt *) e.ip;\n len += lcode(&e);\n }\n value->len = len;\n value->data = ngx_pnalloc(r->pool, len);\n if (value->data == NULL) {\n return NULL;\n }\n e.ip = code_values;\n e.pos = value->data;\n while (*(uintptr_t *) e.ip) {\n code = *(ngx_http_script_code_pt *) e.ip;\n code((ngx_http_script_engine_t *) &e);\n }\n return e.pos;\n}', 'ngx_int_t\nngx_parse_url(ngx_pool_t *pool, ngx_url_t *u)\n{\n u_char *p;\n size_t len;\n p = u->url.data;\n len = u->url.len;\n if (len >= 5 && ngx_strncasecmp(p, (u_char *) "unix:", 5) == 0) {\n return ngx_parse_unix_domain_url(pool, u);\n }\n if (len && p[0] == \'[\') {\n return ngx_parse_inet6_url(pool, u);\n }\n return ngx_parse_inet_url(pool, u);\n}', 'static ngx_int_t\nngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u)\n{\n#if (NGX_HAVE_UNIX_DOMAIN)\n u_char *path, *uri, *last;\n size_t len;\n struct sockaddr_un *saun;\n len = u->url.len;\n path = u->url.data;\n path += 5;\n len -= 5;\n if (u->uri_part) {\n last = path + len;\n uri = ngx_strlchr(path, last, \':\');\n if (uri) {\n len = uri - path;\n uri++;\n u->uri.len = last - uri;\n u->uri.data = uri;\n }\n }\n if (len == 0) {\n u->err = "no path in the unix domain socket";\n return NGX_ERROR;\n }\n u->host.len = len++;\n u->host.data = path;\n if (len > sizeof(saun->sun_path)) {\n u->err = "too long path in the unix domain socket";\n return NGX_ERROR;\n }\n u->socklen = sizeof(struct sockaddr_un);\n saun = (struct sockaddr_un *) &u->sockaddr;\n saun->sun_family = AF_UNIX;\n (void) ngx_cpystrn((u_char *) saun->sun_path, path, len);\n u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t));\n if (u->addrs == NULL) {\n return NGX_ERROR;\n }\n saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un));\n if (saun == NULL) {\n return NGX_ERROR;\n }\n u->family = AF_UNIX;\n u->naddrs = 1;\n saun->sun_family = AF_UNIX;\n (void) ngx_cpystrn((u_char *) saun->sun_path, path, len);\n u->addrs[0].sockaddr = (struct sockaddr *) saun;\n u->addrs[0].socklen = sizeof(struct sockaddr_un);\n u->addrs[0].name.len = len + 4;\n u->addrs[0].name.data = u->url.data;\n return NGX_OK;\n#else\n u->err = "the unix domain sockets are not supported on this platform";\n return NGX_ERROR;\n#endif\n}'] |
34,346 | 0 | https://github.com/openssl/openssl/blob/5d1c09de1f2736e1d4b1877206d08455ec75f558/crypto/bn/bn_lib.c/#L232 | static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
} | ['int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n const int p[], BN_CTX *ctx)\n{\n int ret = 0, i, n;\n BIGNUM *u;\n bn_check_top(a);\n bn_check_top(b);\n if (BN_is_zero(b))\n return BN_one(r);\n if (BN_abs_is_word(b, 1))\n return (BN_copy(r, a) != NULL);\n BN_CTX_start(ctx);\n if ((u = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_GF2m_mod_arr(u, a, p))\n goto err;\n n = BN_num_bits(b) - 1;\n for (i = n - 1; i >= 0; i--) {\n if (!BN_GF2m_mod_sqr_arr(u, u, p, ctx))\n goto err;\n if (BN_is_bit_set(b, i)) {\n if (!BN_GF2m_mod_mul_arr(u, u, a, p, ctx))\n goto err;\n }\n }\n if (!BN_copy(r, u))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],\n BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *s;\n bn_check_top(a);\n BN_CTX_start(ctx);\n if ((s = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!bn_wexpand(s, 2 * a->top))\n goto err;\n for (i = a->top - 1; i >= 0; i--) {\n s->d[2 * i + 1] = SQR1(a->d[i]);\n s->d[2 * i] = SQR0(a->d[i]);\n }\n s->top = 2 * a->top;\n bn_correct_top(s);\n if (!BN_GF2m_mod_arr(r, s, p))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n const int p[], BN_CTX *ctx)\n{\n int zlen, i, j, k, ret = 0;\n BIGNUM *s;\n BN_ULONG x1, x0, y1, y0, zz[4];\n bn_check_top(a);\n bn_check_top(b);\n if (a == b) {\n return BN_GF2m_mod_sqr_arr(r, a, p, ctx);\n }\n BN_CTX_start(ctx);\n if ((s = BN_CTX_get(ctx)) == NULL)\n goto err;\n zlen = a->top + b->top + 4;\n if (!bn_wexpand(s, zlen))\n goto err;\n s->top = zlen;\n for (i = 0; i < zlen; i++)\n s->d[i] = 0;\n for (j = 0; j < b->top; j += 2) {\n y0 = b->d[j];\n y1 = ((j + 1) == b->top) ? 0 : b->d[j + 1];\n for (i = 0; i < a->top; i += 2) {\n x0 = a->d[i];\n x1 = ((i + 1) == a->top) ? 0 : a->d[i + 1];\n bn_GF2m_mul_2x2(zz, x1, x0, y1, y0);\n for (k = 0; k < 4; k++)\n s->d[i + j + k] ^= zz[k];\n }\n }\n bn_correct_top(s);\n if (BN_GF2m_mod_arr(r, s, p))\n ret = 1;\n bn_check_top(r);\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[])\n{\n int j, k;\n int n, dN, d0, d1;\n BN_ULONG zz, *z;\n bn_check_top(a);\n if (!p[0]) {\n BN_zero(r);\n return 1;\n }\n if (a != r) {\n if (!bn_wexpand(r, a->top))\n return 0;\n for (j = 0; j < a->top; j++) {\n r->d[j] = a->d[j];\n }\n r->top = a->top;\n }\n z = r->d;\n dN = p[0] / BN_BITS2;\n for (j = r->top - 1; j > dN;) {\n zz = z[j];\n if (z[j] == 0) {\n j--;\n continue;\n }\n z[j] = 0;\n for (k = 1; p[k] != 0; k++) {\n n = p[0] - p[k];\n d0 = n % BN_BITS2;\n d1 = BN_BITS2 - d0;\n n /= BN_BITS2;\n z[j - n] ^= (zz >> d0);\n if (d0)\n z[j - n - 1] ^= (zz << d1);\n }\n n = dN;\n d0 = p[0] % BN_BITS2;\n d1 = BN_BITS2 - d0;\n z[j - n] ^= (zz >> d0);\n if (d0)\n z[j - n - 1] ^= (zz << d1);\n }\n while (j == dN) {\n d0 = p[0] % BN_BITS2;\n zz = z[dN] >> d0;\n if (zz == 0)\n break;\n d1 = BN_BITS2 - d0;\n if (d0)\n z[dN] = (z[dN] << d1) >> d1;\n else\n z[dN] = 0;\n z[0] ^= zz;\n for (k = 1; p[k] != 0; k++) {\n BN_ULONG tmp_ulong;\n n = p[k] / BN_BITS2;\n d0 = p[k] % BN_BITS2;\n d1 = BN_BITS2 - d0;\n z[n] ^= (zz << d0);\n if (d0 && (tmp_ulong = zz >> d1))\n z[n + 1] ^= tmp_ulong;\n }\n }\n bn_correct_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}'] |
34,347 | 0 | https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_mul.c/#L647 | void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
{
BN_ULONG *rr;
if (na < nb) {
int itmp;
BN_ULONG *ltmp;
itmp = na;
na = nb;
nb = itmp;
ltmp = a;
a = b;
b = ltmp;
}
rr = &(r[na]);
if (nb <= 0) {
(void)bn_mul_words(r, a, na, 0);
return;
} else
rr[0] = bn_mul_words(r, a, na, b[0]);
for (;;) {
if (--nb <= 0)
return;
rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]);
if (--nb <= 0)
return;
rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]);
if (--nb <= 0)
return;
rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]);
if (--nb <= 0)
return;
rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);
rr += 4;
r += 4;
b += 4;
}
} | ['static int test_mod_exp_zero(void)\n{\n BIGNUM *a = NULL, *p = NULL, *m = NULL;\n BIGNUM *r = NULL;\n BN_ULONG one_word = 1;\n BN_CTX *ctx = BN_CTX_new();\n int ret = 1, failed = 0;\n if (!TEST_ptr(m = BN_new())\n || !TEST_ptr(a = BN_new())\n || !TEST_ptr(p = BN_new())\n || !TEST_ptr(r = BN_new()))\n goto err;\n BN_one(m);\n BN_one(a);\n BN_zero(p);\n if (!TEST_true(BN_rand(a, 1024, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY)))\n goto err;\n if (!TEST_true(BN_mod_exp(r, a, p, m, ctx)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_recp(r, a, p, m, ctx)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_recp", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_simple(r, a, p, m, ctx)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_simple", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_mont(r, a, p, m, ctx, NULL)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_mont", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_mont_consttime(r, a, p, m, ctx, NULL)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_mont_consttime", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_mont_word(r, one_word, p, m, ctx, NULL)))\n goto err;\n if (!TEST_BN_eq_zero(r)) {\n TEST_error("BN_mod_exp_mont_word failed: "\n "1 ** 0 mod 1 = r (should be 0)");\n BN_print_var(r);\n goto err;\n }\n ret = !failed;\n err:\n BN_free(r);\n BN_free(a);\n BN_free(p);\n BN_free(m);\n BN_CTX_free(ctx);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (BN_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n bn_correct_top(r);\n } else\n#endif\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_mod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n int num = mont->N.top;\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return 1;\n }\n }\n#endif\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)\n{\n BN_ULONG *rr;\n if (na < nb) {\n int itmp;\n BN_ULONG *ltmp;\n itmp = na;\n na = nb;\n nb = itmp;\n ltmp = a;\n a = b;\n b = ltmp;\n }\n rr = &(r[na]);\n if (nb <= 0) {\n (void)bn_mul_words(r, a, na, 0);\n return;\n } else\n rr[0] = bn_mul_words(r, a, na, b[0]);\n for (;;) {\n if (--nb <= 0)\n return;\n rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]);\n if (--nb <= 0)\n return;\n rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]);\n if (--nb <= 0)\n return;\n rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]);\n if (--nb <= 0)\n return;\n rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);\n rr += 4;\n r += 4;\n b += 4;\n }\n}'] |
34,348 | 0 | https://github.com/openssl/openssl/blob/02cba628daa7fea959c561531a8a984756bdf41c/ssl/s3_lib.c/#L2820 | int ssl3_new(SSL *s)
{
SSL3_STATE *s3;
if ((s3 = OPENSSL_zalloc(sizeof(*s3))) == NULL)
goto err;
s->s3 = s3;
#ifndef OPENSSL_NO_SRP
if (!SSL_SRP_CTX_init(s))
goto err;
#endif
s->method->ssl_clear(s);
return (1);
err:
return (0);
} | ['int ssl3_new(SSL *s)\n{\n SSL3_STATE *s3;\n if ((s3 = OPENSSL_zalloc(sizeof(*s3))) == NULL)\n goto err;\n s->s3 = s3;\n#ifndef OPENSSL_NO_SRP\n if (!SSL_SRP_CTX_init(s))\n goto err;\n#endif\n s->method->ssl_clear(s);\n return (1);\n err:\n return (0);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}'] |
34,349 | 0 | https://github.com/libav/libav/blob/9e12002f114d7e0b0ef69519518cdc0391e5e198/avconv.c/#L3817 | static void opt_output_file(void *optctx, const char *filename)
{
OptionsContext *o = optctx;
AVFormatContext *oc;
int i, err;
AVOutputFormat *file_oformat;
OutputStream *ost;
InputStream *ist;
if (!strcmp(filename, "-"))
filename = "pipe:";
oc = avformat_alloc_context();
if (!oc) {
print_error(filename, AVERROR(ENOMEM));
exit_program(1);
}
if (o->format) {
file_oformat = av_guess_format(o->format, NULL, NULL);
if (!file_oformat) {
av_log(NULL, AV_LOG_FATAL, "Requested output format '%s' is not a suitable output format\n", o->format);
exit_program(1);
}
} else {
file_oformat = av_guess_format(NULL, filename, NULL);
if (!file_oformat) {
av_log(NULL, AV_LOG_FATAL, "Unable to find a suitable output format for '%s'\n",
filename);
exit_program(1);
}
}
oc->oformat = file_oformat;
oc->interrupt_callback = int_cb;
av_strlcpy(oc->filename, filename, sizeof(oc->filename));
if (!o->nb_stream_maps) {
#define NEW_STREAM(type, index)\
if (index >= 0) {\
ost = new_ ## type ## _stream(o, oc);\
ost->source_index = index;\
ost->sync_ist = &input_streams[index];\
input_streams[index].discard = 0;\
}
if (!o->video_disable && oc->oformat->video_codec != CODEC_ID_NONE) {
int area = 0, idx = -1;
for (i = 0; i < nb_input_streams; i++) {
ist = &input_streams[i];
if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
ist->st->codec->width * ist->st->codec->height > area) {
area = ist->st->codec->width * ist->st->codec->height;
idx = i;
}
}
NEW_STREAM(video, idx);
}
if (!o->audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) {
int channels = 0, idx = -1;
for (i = 0; i < nb_input_streams; i++) {
ist = &input_streams[i];
if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
ist->st->codec->channels > channels) {
channels = ist->st->codec->channels;
idx = i;
}
}
NEW_STREAM(audio, idx);
}
if (!o->subtitle_disable && oc->oformat->subtitle_codec != CODEC_ID_NONE) {
for (i = 0; i < nb_input_streams; i++)
if (input_streams[i].st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
NEW_STREAM(subtitle, i);
break;
}
}
} else {
for (i = 0; i < o->nb_stream_maps; i++) {
StreamMap *map = &o->stream_maps[i];
if (map->disabled)
continue;
ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];
switch (ist->st->codec->codec_type) {
case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc); break;
case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break;
case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break;
case AVMEDIA_TYPE_DATA: ost = new_data_stream(o, oc); break;
case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc); break;
default:
av_log(NULL, AV_LOG_FATAL, "Cannot map stream #%d:%d - unsupported type.\n",
map->file_index, map->stream_index);
exit_program(1);
}
ost->source_index = input_files[map->file_index].ist_index + map->stream_index;
ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index +
map->sync_stream_index];
ist->discard = 0;
}
}
for (i = 0; i < o->nb_attachments; i++) {
AVIOContext *pb;
uint8_t *attachment;
const char *p;
int64_t len;
if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n",
o->attachments[i]);
exit_program(1);
}
if ((len = avio_size(pb)) <= 0) {
av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
o->attachments[i]);
exit_program(1);
}
if (!(attachment = av_malloc(len))) {
av_log(NULL, AV_LOG_FATAL, "Attachment %s too large to fit into memory.\n",
o->attachments[i]);
exit_program(1);
}
avio_read(pb, attachment, len);
ost = new_attachment_stream(o, oc);
ost->stream_copy = 0;
ost->source_index = -1;
ost->attachment_filename = o->attachments[i];
ost->st->codec->extradata = attachment;
ost->st->codec->extradata_size = len;
p = strrchr(o->attachments[i], '/');
av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
avio_close(pb);
}
output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1);
output_files[nb_output_files - 1].ctx = oc;
output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams;
output_files[nb_output_files - 1].recording_time = o->recording_time;
output_files[nb_output_files - 1].start_time = o->start_time;
output_files[nb_output_files - 1].limit_filesize = o->limit_filesize;
av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0);
if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
if (!av_filename_number_test(oc->filename)) {
print_error(oc->filename, AVERROR(EINVAL));
exit_program(1);
}
}
if (!(oc->oformat->flags & AVFMT_NOFILE)) {
assert_file_overwrite(filename);
if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
&oc->interrupt_callback,
&output_files[nb_output_files - 1].opts)) < 0) {
print_error(filename, err);
exit_program(1);
}
}
if (o->mux_preload) {
uint8_t buf[64];
snprintf(buf, sizeof(buf), "%d", (int)(o->mux_preload*AV_TIME_BASE));
av_dict_set(&output_files[nb_output_files - 1].opts, "preload", buf, 0);
}
oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
oc->flags |= AVFMT_FLAG_NONBLOCK;
for (i = 0; i < o->nb_metadata_map; i++) {
char *p;
int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
if (in_file_index < 0)
continue;
if (in_file_index >= nb_input_files) {
av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index);
exit_program(1);
}
copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, input_files[in_file_index].ctx, o);
}
if (o->chapters_input_file >= nb_input_files) {
if (o->chapters_input_file == INT_MAX) {
o->chapters_input_file = -1;
for (i = 0; i < nb_input_files; i++)
if (input_files[i].ctx->nb_chapters) {
o->chapters_input_file = i;
break;
}
} else {
av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
o->chapters_input_file);
exit_program(1);
}
}
if (o->chapters_input_file >= 0)
copy_chapters(&input_files[o->chapters_input_file], &output_files[nb_output_files - 1],
!o->metadata_chapters_manual);
if (!o->metadata_global_manual && nb_input_files)
av_dict_copy(&oc->metadata, input_files[0].ctx->metadata,
AV_DICT_DONT_OVERWRITE);
if (!o->metadata_streams_manual)
for (i = output_files[nb_output_files - 1].ost_index; i < nb_output_streams; i++) {
InputStream *ist;
if (output_streams[i].source_index < 0)
continue;
ist = &input_streams[output_streams[i].source_index];
av_dict_copy(&output_streams[i].st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
}
for (i = 0; i < o->nb_metadata; i++) {
AVDictionary **m;
char type, *val;
const char *stream_spec;
int index = 0, j, ret;
val = strchr(o->metadata[i].u.str, '=');
if (!val) {
av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
o->metadata[i].u.str);
exit_program(1);
}
*val++ = 0;
parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);
if (type == 's') {
for (j = 0; j < oc->nb_streams; j++) {
if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
} else if (ret < 0)
exit_program(1);
}
printf("ret %d, stream_spec %s\n", ret, stream_spec);
}
else {
switch (type) {
case 'g':
m = &oc->metadata;
break;
case 'c':
if (index < 0 || index >= oc->nb_chapters) {
av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
exit_program(1);
}
m = &oc->chapters[index]->metadata;
break;
default:
av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
exit_program(1);
}
av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
}
}
reset_options(o);
} | ['static void opt_output_file(void *optctx, const char *filename)\n{\n OptionsContext *o = optctx;\n AVFormatContext *oc;\n int i, err;\n AVOutputFormat *file_oformat;\n OutputStream *ost;\n InputStream *ist;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!oc) {\n print_error(filename, AVERROR(ENOMEM));\n exit_program(1);\n }\n if (o->format) {\n file_oformat = av_guess_format(o->format, NULL, NULL);\n if (!file_oformat) {\n av_log(NULL, AV_LOG_FATAL, "Requested output format \'%s\' is not a suitable output format\\n", o->format);\n exit_program(1);\n }\n } else {\n file_oformat = av_guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n av_log(NULL, AV_LOG_FATAL, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n exit_program(1);\n }\n }\n oc->oformat = file_oformat;\n oc->interrupt_callback = int_cb;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!o->nb_stream_maps) {\n#define NEW_STREAM(type, index)\\\n if (index >= 0) {\\\n ost = new_ ## type ## _stream(o, oc);\\\n ost->source_index = index;\\\n ost->sync_ist = &input_streams[index];\\\n input_streams[index].discard = 0;\\\n }\n if (!o->video_disable && oc->oformat->video_codec != CODEC_ID_NONE) {\n int area = 0, idx = -1;\n for (i = 0; i < nb_input_streams; i++) {\n ist = &input_streams[i];\n if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&\n ist->st->codec->width * ist->st->codec->height > area) {\n area = ist->st->codec->width * ist->st->codec->height;\n idx = i;\n }\n }\n NEW_STREAM(video, idx);\n }\n if (!o->audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) {\n int channels = 0, idx = -1;\n for (i = 0; i < nb_input_streams; i++) {\n ist = &input_streams[i];\n if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&\n ist->st->codec->channels > channels) {\n channels = ist->st->codec->channels;\n idx = i;\n }\n }\n NEW_STREAM(audio, idx);\n }\n if (!o->subtitle_disable && oc->oformat->subtitle_codec != CODEC_ID_NONE) {\n for (i = 0; i < nb_input_streams; i++)\n if (input_streams[i].st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {\n NEW_STREAM(subtitle, i);\n break;\n }\n }\n } else {\n for (i = 0; i < o->nb_stream_maps; i++) {\n StreamMap *map = &o->stream_maps[i];\n if (map->disabled)\n continue;\n ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];\n switch (ist->st->codec->codec_type) {\n case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc); break;\n case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break;\n case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break;\n case AVMEDIA_TYPE_DATA: ost = new_data_stream(o, oc); break;\n case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc); break;\n default:\n av_log(NULL, AV_LOG_FATAL, "Cannot map stream #%d:%d - unsupported type.\\n",\n map->file_index, map->stream_index);\n exit_program(1);\n }\n ost->source_index = input_files[map->file_index].ist_index + map->stream_index;\n ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index +\n map->sync_stream_index];\n ist->discard = 0;\n }\n }\n for (i = 0; i < o->nb_attachments; i++) {\n AVIOContext *pb;\n uint8_t *attachment;\n const char *p;\n int64_t len;\n if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {\n av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\\n",\n o->attachments[i]);\n exit_program(1);\n }\n if ((len = avio_size(pb)) <= 0) {\n av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\\n",\n o->attachments[i]);\n exit_program(1);\n }\n if (!(attachment = av_malloc(len))) {\n av_log(NULL, AV_LOG_FATAL, "Attachment %s too large to fit into memory.\\n",\n o->attachments[i]);\n exit_program(1);\n }\n avio_read(pb, attachment, len);\n ost = new_attachment_stream(o, oc);\n ost->stream_copy = 0;\n ost->source_index = -1;\n ost->attachment_filename = o->attachments[i];\n ost->st->codec->extradata = attachment;\n ost->st->codec->extradata_size = len;\n p = strrchr(o->attachments[i], \'/\');\n av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);\n avio_close(pb);\n }\n output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1);\n output_files[nb_output_files - 1].ctx = oc;\n output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams;\n output_files[nb_output_files - 1].recording_time = o->recording_time;\n output_files[nb_output_files - 1].start_time = o->start_time;\n output_files[nb_output_files - 1].limit_filesize = o->limit_filesize;\n av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0);\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR(EINVAL));\n exit_program(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n assert_file_overwrite(filename);\n if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,\n &oc->interrupt_callback,\n &output_files[nb_output_files - 1].opts)) < 0) {\n print_error(filename, err);\n exit_program(1);\n }\n }\n if (o->mux_preload) {\n uint8_t buf[64];\n snprintf(buf, sizeof(buf), "%d", (int)(o->mux_preload*AV_TIME_BASE));\n av_dict_set(&output_files[nb_output_files - 1].opts, "preload", buf, 0);\n }\n oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n for (i = 0; i < o->nb_metadata_map; i++) {\n char *p;\n int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);\n if (in_file_index < 0)\n continue;\n if (in_file_index >= nb_input_files) {\n av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\\n", in_file_index);\n exit_program(1);\n }\n copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, input_files[in_file_index].ctx, o);\n }\n if (o->chapters_input_file >= nb_input_files) {\n if (o->chapters_input_file == INT_MAX) {\n o->chapters_input_file = -1;\n for (i = 0; i < nb_input_files; i++)\n if (input_files[i].ctx->nb_chapters) {\n o->chapters_input_file = i;\n break;\n }\n } else {\n av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\\n",\n o->chapters_input_file);\n exit_program(1);\n }\n }\n if (o->chapters_input_file >= 0)\n copy_chapters(&input_files[o->chapters_input_file], &output_files[nb_output_files - 1],\n !o->metadata_chapters_manual);\n if (!o->metadata_global_manual && nb_input_files)\n av_dict_copy(&oc->metadata, input_files[0].ctx->metadata,\n AV_DICT_DONT_OVERWRITE);\n if (!o->metadata_streams_manual)\n for (i = output_files[nb_output_files - 1].ost_index; i < nb_output_streams; i++) {\n InputStream *ist;\n if (output_streams[i].source_index < 0)\n continue;\n ist = &input_streams[output_streams[i].source_index];\n av_dict_copy(&output_streams[i].st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);\n }\n for (i = 0; i < o->nb_metadata; i++) {\n AVDictionary **m;\n char type, *val;\n const char *stream_spec;\n int index = 0, j, ret;\n val = strchr(o->metadata[i].u.str, \'=\');\n if (!val) {\n av_log(NULL, AV_LOG_FATAL, "No \'=\' character in metadata string %s.\\n",\n o->metadata[i].u.str);\n exit_program(1);\n }\n *val++ = 0;\n parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);\n if (type == \'s\') {\n for (j = 0; j < oc->nb_streams; j++) {\n if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {\n av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);\n } else if (ret < 0)\n exit_program(1);\n }\n printf("ret %d, stream_spec %s\\n", ret, stream_spec);\n }\n else {\n switch (type) {\n case \'g\':\n m = &oc->metadata;\n break;\n case \'c\':\n if (index < 0 || index >= oc->nb_chapters) {\n av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\\n", index);\n exit_program(1);\n }\n m = &oc->chapters[index]->metadata;\n break;\n default:\n av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\\n", o->metadata[i].specifier);\n exit_program(1);\n }\n av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);\n }\n }\n reset_options(o);\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n AVFormatContext *ic;\n ic = av_malloc(sizeof(AVFormatContext));\n if (!ic) return ic;\n avformat_get_context_defaults(ic);\n return ic;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-32) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'void print_error(const char *filename, int err)\n{\n char errbuf[128];\n const char *errbuf_ptr = errbuf;\n if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)\n errbuf_ptr = strerror(AVUNERROR(err));\n av_log(NULL, AV_LOG_ERROR, "%s: %s\\n", filename, errbuf_ptr);\n}'] |
34,350 | 0 | https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/bn/bn_mul.c/#L728 | void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
{
BN_ULONG *rr;
#ifdef BN_COUNT
printf(" bn_mul_normal %d * %d\n",na,nb);
#endif
if (na < nb)
{
int itmp;
BN_ULONG *ltmp;
itmp=na; na=nb; nb=itmp;
ltmp=a; a=b; b=ltmp;
}
rr= &(r[na]);
rr[0]=bn_mul_words(r,a,na,b[0]);
for (;;)
{
if (--nb <= 0) return;
rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);
if (--nb <= 0) return;
rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);
if (--nb <= 0) return;
rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);
if (--nb <= 0) return;
rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);
rr+=4;
r+=4;
b+=4;
}
} | ['int DH_generate_key(DH *dh)\n\t{\n\tint ok=0;\n\tunsigned int i;\n\tBN_CTX ctx;\n\tBN_MONT_CTX *mont;\n\tBIGNUM *pub_key=NULL,*priv_key=NULL;\n\tBN_CTX_init(&ctx);\n\tif (dh->priv_key == NULL)\n\t\t{\n\t\ti=dh->length;\n\t\tif (i == 0)\n\t\t\t{\n\t\t\ti=BN_num_bits(dh->p)-1;\n\t\t\t}\n\t\tpriv_key=BN_new();\n\t\tif (priv_key == NULL) goto err;\n\t\tif (!BN_rand(priv_key,i,0,0)) goto err;\n\t\t}\n\telse\n\t\tpriv_key=dh->priv_key;\n\tif (dh->pub_key == NULL)\n\t\t{\n\t\tpub_key=BN_new();\n\t\tif (pub_key == NULL) goto err;\n\t\t}\n\telse\n\t\tpub_key=dh->pub_key;\n\tif ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))\n\t\t{\n\t\tif ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,\n\t\t\t\tdh->p,&ctx)) goto err;\n\t\t}\n\tmont=(BN_MONT_CTX *)dh->method_mont_p;\n\tif (!BN_mod_exp_mont(pub_key,dh->g,priv_key,dh->p,&ctx,mont)) goto err;\n\tdh->pub_key=pub_key;\n\tdh->priv_key=priv_key;\n\tok=1;\nerr:\n\tif (ok != 1)\n\t\tDHerr(DH_F_DH_GENERATE_KEY,ERR_R_BN_LIB);\n\tif ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);\n\tif ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);\n\tBN_CTX_free(&ctx);\n\treturn(ok);\n\t}', 'int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx,\n\t BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *d,*aa,*r;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\td= &(ctx->bn[ctx->tos++]);\n\tr= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n#if 1\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n#endif\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tBN_init(&val[0]);\n\tts=1;\n\tif (BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[0]),a,m,ctx);\n\t\taa= &(val[0]);\n\t\t}\n\telse\n\t\taa=a;\n\tif (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err;\n\tif (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err;\n\tif (bits <= 20)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&(val[i]));\n\t\tif (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tBN_from_montgomery(rr,r,mont,ctx);\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tctx->tos-=2;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\treturn(ret);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_MONT_CTX *mont,\n\t BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp,*tmp2;\n tmp= &(ctx->bn[ctx->tos]);\n tmp2= &(ctx->bn[ctx->tos]);\n\tctx->tos+=2;\n\tbn_check_top(tmp);\n\tbn_check_top(tmp2);\n\tif (a == b)\n\t\t{\n#if 0\n\t\tbn_wexpand(tmp,a->top*2);\n\t\tbn_wexpand(tmp2,a->top*4);\n\t\tbn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);\n\t\ttmp->top=a->top*2;\n\t\tif (tmp->d[tmp->top-1] == 0)\n\t\t\ttmp->top--;\n#else\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n\tctx->tos-=2;\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}', 'void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)\n\t{\n\tBN_ULONG *rr;\n#ifdef BN_COUNT\nprintf(" bn_mul_normal %d * %d\\n",na,nb);\n#endif\n\tif (na < nb)\n\t\t{\n\t\tint itmp;\n\t\tBN_ULONG *ltmp;\n\t\titmp=na; na=nb; nb=itmp;\n\t\tltmp=a; a=b; b=ltmp;\n\t\t}\n\trr= &(r[na]);\n\trr[0]=bn_mul_words(r,a,na,b[0]);\n\tfor (;;)\n\t\t{\n\t\tif (--nb <= 0) return;\n\t\trr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);\n\t\tif (--nb <= 0) return;\n\t\trr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);\n\t\tif (--nb <= 0) return;\n\t\trr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);\n\t\tif (--nb <= 0) return;\n\t\trr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);\n\t\trr+=4;\n\t\tr+=4;\n\t\tb+=4;\n\t\t}\n\t}'] |
34,351 | 0 | https://github.com/libav/libav/blob/f97cb4515626228620d7317191c4c32f14eb1a1b/libavcodec/error_resilience.c/#L701 | static void guess_mv(MpegEncContext *s)
{
uint8_t fixed[s->mb_stride * s->mb_height];
#define MV_FROZEN 3
#define MV_CHANGED 2
#define MV_UNCHANGED 1
const int mb_stride = s->mb_stride;
const int mb_width = s->mb_width;
const int mb_height = s->mb_height;
int i, depth, num_avail;
int mb_x, mb_y, mot_step, mot_stride;
set_mv_strides(s, &mot_step, &mot_stride);
num_avail = 0;
for (i = 0; i < s->mb_num; i++) {
const int mb_xy = s->mb_index2xy[i];
int f = 0;
int error = s->error_status_table[mb_xy];
if (IS_INTRA(s->current_picture.f.mb_type[mb_xy]))
f = MV_FROZEN;
if (!(error & ER_MV_ERROR))
f = MV_FROZEN;
fixed[mb_xy] = f;
if (f == MV_FROZEN)
num_avail++;
}
if ((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) ||
num_avail <= mb_width / 2) {
for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
const int mb_xy = mb_x + mb_y * s->mb_stride;
if (IS_INTRA(s->current_picture.f.mb_type[mb_xy]))
continue;
if (!(s->error_status_table[mb_xy] & ER_MV_ERROR))
continue;
s->mv_dir = s->last_picture.f.data[0] ? MV_DIR_FORWARD
: MV_DIR_BACKWARD;
s->mb_intra = 0;
s->mv_type = MV_TYPE_16X16;
s->mb_skipped = 0;
s->dsp.clear_blocks(s->block[0]);
s->mb_x = mb_x;
s->mb_y = mb_y;
s->mv[0][0][0] = 0;
s->mv[0][0][1] = 0;
decode_mb(s, 0);
}
}
return;
}
for (depth = 0; ; depth++) {
int changed, pass, none_left;
none_left = 1;
changed = 1;
for (pass = 0; (changed || pass < 2) && pass < 10; pass++) {
int mb_x, mb_y;
int score_sum = 0;
changed = 0;
for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
const int mb_xy = mb_x + mb_y * s->mb_stride;
int mv_predictor[8][2] = { { 0 } };
int ref[8] = { 0 };
int pred_count = 0;
int j;
int best_score = 256 * 256 * 256 * 64;
int best_pred = 0;
const int mot_index = (mb_x + mb_y * mot_stride) * mot_step;
int prev_x, prev_y, prev_ref;
if ((mb_x ^ mb_y ^ pass) & 1)
continue;
if (fixed[mb_xy] == MV_FROZEN)
continue;
assert(!IS_INTRA(s->current_picture.f.mb_type[mb_xy]));
assert(s->last_picture_ptr && s->last_picture_ptr->f.data[0]);
j = 0;
if (mb_x > 0 && fixed[mb_xy - 1] == MV_FROZEN)
j = 1;
if (mb_x + 1 < mb_width && fixed[mb_xy + 1] == MV_FROZEN)
j = 1;
if (mb_y > 0 && fixed[mb_xy - mb_stride] == MV_FROZEN)
j = 1;
if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_FROZEN)
j = 1;
if (j == 0)
continue;
j = 0;
if (mb_x > 0 && fixed[mb_xy - 1 ] == MV_CHANGED)
j = 1;
if (mb_x + 1 < mb_width && fixed[mb_xy + 1 ] == MV_CHANGED)
j = 1;
if (mb_y > 0 && fixed[mb_xy - mb_stride] == MV_CHANGED)
j = 1;
if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_CHANGED)
j = 1;
if (j == 0 && pass > 1)
continue;
none_left = 0;
if (mb_x > 0 && fixed[mb_xy - 1]) {
mv_predictor[pred_count][0] =
s->current_picture.f.motion_val[0][mot_index - mot_step][0];
mv_predictor[pred_count][1] =
s->current_picture.f.motion_val[0][mot_index - mot_step][1];
ref[pred_count] =
s->current_picture.f.ref_index[0][4 * (mb_xy - 1)];
pred_count++;
}
if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) {
mv_predictor[pred_count][0] =
s->current_picture.f.motion_val[0][mot_index + mot_step][0];
mv_predictor[pred_count][1] =
s->current_picture.f.motion_val[0][mot_index + mot_step][1];
ref[pred_count] =
s->current_picture.f.ref_index[0][4 * (mb_xy + 1)];
pred_count++;
}
if (mb_y > 0 && fixed[mb_xy - mb_stride]) {
mv_predictor[pred_count][0] =
s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][0];
mv_predictor[pred_count][1] =
s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][1];
ref[pred_count] =
s->current_picture.f.ref_index[0][4 * (mb_xy - s->mb_stride)];
pred_count++;
}
if (mb_y + 1<mb_height && fixed[mb_xy + mb_stride]) {
mv_predictor[pred_count][0] =
s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][0];
mv_predictor[pred_count][1] =
s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][1];
ref[pred_count] =
s->current_picture.f.ref_index[0][4 * (mb_xy + s->mb_stride)];
pred_count++;
}
if (pred_count == 0)
continue;
if (pred_count > 1) {
int sum_x = 0, sum_y = 0, sum_r = 0;
int max_x, max_y, min_x, min_y, max_r, min_r;
for (j = 0; j < pred_count; j++) {
sum_x += mv_predictor[j][0];
sum_y += mv_predictor[j][1];
sum_r += ref[j];
if (j && ref[j] != ref[j - 1])
goto skip_mean_and_median;
}
mv_predictor[pred_count][0] = sum_x / j;
mv_predictor[pred_count][1] = sum_y / j;
ref[pred_count] = sum_r / j;
if (pred_count >= 3) {
min_y = min_x = min_r = 99999;
max_y = max_x = max_r = -99999;
} else {
min_x = min_y = max_x = max_y = min_r = max_r = 0;
}
for (j = 0; j < pred_count; j++) {
max_x = FFMAX(max_x, mv_predictor[j][0]);
max_y = FFMAX(max_y, mv_predictor[j][1]);
max_r = FFMAX(max_r, ref[j]);
min_x = FFMIN(min_x, mv_predictor[j][0]);
min_y = FFMIN(min_y, mv_predictor[j][1]);
min_r = FFMIN(min_r, ref[j]);
}
mv_predictor[pred_count + 1][0] = sum_x - max_x - min_x;
mv_predictor[pred_count + 1][1] = sum_y - max_y - min_y;
ref[pred_count + 1] = sum_r - max_r - min_r;
if (pred_count == 4) {
mv_predictor[pred_count + 1][0] /= 2;
mv_predictor[pred_count + 1][1] /= 2;
ref[pred_count + 1] /= 2;
}
pred_count += 2;
}
skip_mean_and_median:
pred_count++;
if (!fixed[mb_xy]) {
if (s->avctx->codec_id == CODEC_ID_H264) {
} else {
ff_thread_await_progress((AVFrame *) s->last_picture_ptr,
mb_y, 0);
}
if (!s->last_picture.f.motion_val[0] ||
!s->last_picture.f.ref_index[0])
goto skip_last_mv;
prev_x = s->last_picture.f.motion_val[0][mot_index][0];
prev_y = s->last_picture.f.motion_val[0][mot_index][1];
prev_ref = s->last_picture.f.ref_index[0][4 * mb_xy];
} else {
prev_x = s->current_picture.f.motion_val[0][mot_index][0];
prev_y = s->current_picture.f.motion_val[0][mot_index][1];
prev_ref = s->current_picture.f.ref_index[0][4 * mb_xy];
}
mv_predictor[pred_count][0] = prev_x;
mv_predictor[pred_count][1] = prev_y;
ref[pred_count] = prev_ref;
pred_count++;
skip_last_mv:
s->mv_dir = MV_DIR_FORWARD;
s->mb_intra = 0;
s->mv_type = MV_TYPE_16X16;
s->mb_skipped = 0;
s->dsp.clear_blocks(s->block[0]);
s->mb_x = mb_x;
s->mb_y = mb_y;
for (j = 0; j < pred_count; j++) {
int score = 0;
uint8_t *src = s->current_picture.f.data[0] +
mb_x * 16 + mb_y * 16 * s->linesize;
s->current_picture.f.motion_val[0][mot_index][0] =
s->mv[0][0][0] = mv_predictor[j][0];
s->current_picture.f.motion_val[0][mot_index][1] =
s->mv[0][0][1] = mv_predictor[j][1];
if (ref[j] < 0)
continue;
decode_mb(s, ref[j]);
if (mb_x > 0 && fixed[mb_xy - 1]) {
int k;
for (k = 0; k < 16; k++)
score += FFABS(src[k * s->linesize - 1] -
src[k * s->linesize]);
}
if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) {
int k;
for (k = 0; k < 16; k++)
score += FFABS(src[k * s->linesize + 15] -
src[k * s->linesize + 16]);
}
if (mb_y > 0 && fixed[mb_xy - mb_stride]) {
int k;
for (k = 0; k < 16; k++)
score += FFABS(src[k - s->linesize] - src[k]);
}
if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride]) {
int k;
for (k = 0; k < 16; k++)
score += FFABS(src[k + s->linesize * 15] -
src[k + s->linesize * 16]);
}
if (score <= best_score) {
best_score = score;
best_pred = j;
}
}
score_sum += best_score;
s->mv[0][0][0] = mv_predictor[best_pred][0];
s->mv[0][0][1] = mv_predictor[best_pred][1];
for (i = 0; i < mot_step; i++)
for (j = 0; j < mot_step; j++) {
s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0];
s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1];
}
decode_mb(s, ref[best_pred]);
if (s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y) {
fixed[mb_xy] = MV_CHANGED;
changed++;
} else
fixed[mb_xy] = MV_UNCHANGED;
}
}
}
if (none_left)
return;
for (i = 0; i < s->mb_num; i++) {
int mb_xy = s->mb_index2xy[i];
if (fixed[mb_xy])
fixed[mb_xy] = MV_FROZEN;
}
}
} | ['static void guess_mv(MpegEncContext *s)\n{\n uint8_t fixed[s->mb_stride * s->mb_height];\n#define MV_FROZEN 3\n#define MV_CHANGED 2\n#define MV_UNCHANGED 1\n const int mb_stride = s->mb_stride;\n const int mb_width = s->mb_width;\n const int mb_height = s->mb_height;\n int i, depth, num_avail;\n int mb_x, mb_y, mot_step, mot_stride;\n set_mv_strides(s, &mot_step, &mot_stride);\n num_avail = 0;\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n int f = 0;\n int error = s->error_status_table[mb_xy];\n if (IS_INTRA(s->current_picture.f.mb_type[mb_xy]))\n f = MV_FROZEN;\n if (!(error & ER_MV_ERROR))\n f = MV_FROZEN;\n fixed[mb_xy] = f;\n if (f == MV_FROZEN)\n num_avail++;\n }\n if ((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) ||\n num_avail <= mb_width / 2) {\n for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n if (IS_INTRA(s->current_picture.f.mb_type[mb_xy]))\n continue;\n if (!(s->error_status_table[mb_xy] & ER_MV_ERROR))\n continue;\n s->mv_dir = s->last_picture.f.data[0] ? MV_DIR_FORWARD\n : MV_DIR_BACKWARD;\n s->mb_intra = 0;\n s->mv_type = MV_TYPE_16X16;\n s->mb_skipped = 0;\n s->dsp.clear_blocks(s->block[0]);\n s->mb_x = mb_x;\n s->mb_y = mb_y;\n s->mv[0][0][0] = 0;\n s->mv[0][0][1] = 0;\n decode_mb(s, 0);\n }\n }\n return;\n }\n for (depth = 0; ; depth++) {\n int changed, pass, none_left;\n none_left = 1;\n changed = 1;\n for (pass = 0; (changed || pass < 2) && pass < 10; pass++) {\n int mb_x, mb_y;\n int score_sum = 0;\n changed = 0;\n for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n int mv_predictor[8][2] = { { 0 } };\n int ref[8] = { 0 };\n int pred_count = 0;\n int j;\n int best_score = 256 * 256 * 256 * 64;\n int best_pred = 0;\n const int mot_index = (mb_x + mb_y * mot_stride) * mot_step;\n int prev_x, prev_y, prev_ref;\n if ((mb_x ^ mb_y ^ pass) & 1)\n continue;\n if (fixed[mb_xy] == MV_FROZEN)\n continue;\n assert(!IS_INTRA(s->current_picture.f.mb_type[mb_xy]));\n assert(s->last_picture_ptr && s->last_picture_ptr->f.data[0]);\n j = 0;\n if (mb_x > 0 && fixed[mb_xy - 1] == MV_FROZEN)\n j = 1;\n if (mb_x + 1 < mb_width && fixed[mb_xy + 1] == MV_FROZEN)\n j = 1;\n if (mb_y > 0 && fixed[mb_xy - mb_stride] == MV_FROZEN)\n j = 1;\n if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_FROZEN)\n j = 1;\n if (j == 0)\n continue;\n j = 0;\n if (mb_x > 0 && fixed[mb_xy - 1 ] == MV_CHANGED)\n j = 1;\n if (mb_x + 1 < mb_width && fixed[mb_xy + 1 ] == MV_CHANGED)\n j = 1;\n if (mb_y > 0 && fixed[mb_xy - mb_stride] == MV_CHANGED)\n j = 1;\n if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_CHANGED)\n j = 1;\n if (j == 0 && pass > 1)\n continue;\n none_left = 0;\n if (mb_x > 0 && fixed[mb_xy - 1]) {\n mv_predictor[pred_count][0] =\n s->current_picture.f.motion_val[0][mot_index - mot_step][0];\n mv_predictor[pred_count][1] =\n s->current_picture.f.motion_val[0][mot_index - mot_step][1];\n ref[pred_count] =\n s->current_picture.f.ref_index[0][4 * (mb_xy - 1)];\n pred_count++;\n }\n if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) {\n mv_predictor[pred_count][0] =\n s->current_picture.f.motion_val[0][mot_index + mot_step][0];\n mv_predictor[pred_count][1] =\n s->current_picture.f.motion_val[0][mot_index + mot_step][1];\n ref[pred_count] =\n s->current_picture.f.ref_index[0][4 * (mb_xy + 1)];\n pred_count++;\n }\n if (mb_y > 0 && fixed[mb_xy - mb_stride]) {\n mv_predictor[pred_count][0] =\n s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][0];\n mv_predictor[pred_count][1] =\n s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][1];\n ref[pred_count] =\n s->current_picture.f.ref_index[0][4 * (mb_xy - s->mb_stride)];\n pred_count++;\n }\n if (mb_y + 1<mb_height && fixed[mb_xy + mb_stride]) {\n mv_predictor[pred_count][0] =\n s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][0];\n mv_predictor[pred_count][1] =\n s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][1];\n ref[pred_count] =\n s->current_picture.f.ref_index[0][4 * (mb_xy + s->mb_stride)];\n pred_count++;\n }\n if (pred_count == 0)\n continue;\n if (pred_count > 1) {\n int sum_x = 0, sum_y = 0, sum_r = 0;\n int max_x, max_y, min_x, min_y, max_r, min_r;\n for (j = 0; j < pred_count; j++) {\n sum_x += mv_predictor[j][0];\n sum_y += mv_predictor[j][1];\n sum_r += ref[j];\n if (j && ref[j] != ref[j - 1])\n goto skip_mean_and_median;\n }\n mv_predictor[pred_count][0] = sum_x / j;\n mv_predictor[pred_count][1] = sum_y / j;\n ref[pred_count] = sum_r / j;\n if (pred_count >= 3) {\n min_y = min_x = min_r = 99999;\n max_y = max_x = max_r = -99999;\n } else {\n min_x = min_y = max_x = max_y = min_r = max_r = 0;\n }\n for (j = 0; j < pred_count; j++) {\n max_x = FFMAX(max_x, mv_predictor[j][0]);\n max_y = FFMAX(max_y, mv_predictor[j][1]);\n max_r = FFMAX(max_r, ref[j]);\n min_x = FFMIN(min_x, mv_predictor[j][0]);\n min_y = FFMIN(min_y, mv_predictor[j][1]);\n min_r = FFMIN(min_r, ref[j]);\n }\n mv_predictor[pred_count + 1][0] = sum_x - max_x - min_x;\n mv_predictor[pred_count + 1][1] = sum_y - max_y - min_y;\n ref[pred_count + 1] = sum_r - max_r - min_r;\n if (pred_count == 4) {\n mv_predictor[pred_count + 1][0] /= 2;\n mv_predictor[pred_count + 1][1] /= 2;\n ref[pred_count + 1] /= 2;\n }\n pred_count += 2;\n }\nskip_mean_and_median:\n pred_count++;\n if (!fixed[mb_xy]) {\n if (s->avctx->codec_id == CODEC_ID_H264) {\n } else {\n ff_thread_await_progress((AVFrame *) s->last_picture_ptr,\n mb_y, 0);\n }\n if (!s->last_picture.f.motion_val[0] ||\n !s->last_picture.f.ref_index[0])\n goto skip_last_mv;\n prev_x = s->last_picture.f.motion_val[0][mot_index][0];\n prev_y = s->last_picture.f.motion_val[0][mot_index][1];\n prev_ref = s->last_picture.f.ref_index[0][4 * mb_xy];\n } else {\n prev_x = s->current_picture.f.motion_val[0][mot_index][0];\n prev_y = s->current_picture.f.motion_val[0][mot_index][1];\n prev_ref = s->current_picture.f.ref_index[0][4 * mb_xy];\n }\n mv_predictor[pred_count][0] = prev_x;\n mv_predictor[pred_count][1] = prev_y;\n ref[pred_count] = prev_ref;\n pred_count++;\nskip_last_mv:\n s->mv_dir = MV_DIR_FORWARD;\n s->mb_intra = 0;\n s->mv_type = MV_TYPE_16X16;\n s->mb_skipped = 0;\n s->dsp.clear_blocks(s->block[0]);\n s->mb_x = mb_x;\n s->mb_y = mb_y;\n for (j = 0; j < pred_count; j++) {\n int score = 0;\n uint8_t *src = s->current_picture.f.data[0] +\n mb_x * 16 + mb_y * 16 * s->linesize;\n s->current_picture.f.motion_val[0][mot_index][0] =\n s->mv[0][0][0] = mv_predictor[j][0];\n s->current_picture.f.motion_val[0][mot_index][1] =\n s->mv[0][0][1] = mv_predictor[j][1];\n if (ref[j] < 0)\n continue;\n decode_mb(s, ref[j]);\n if (mb_x > 0 && fixed[mb_xy - 1]) {\n int k;\n for (k = 0; k < 16; k++)\n score += FFABS(src[k * s->linesize - 1] -\n src[k * s->linesize]);\n }\n if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) {\n int k;\n for (k = 0; k < 16; k++)\n score += FFABS(src[k * s->linesize + 15] -\n src[k * s->linesize + 16]);\n }\n if (mb_y > 0 && fixed[mb_xy - mb_stride]) {\n int k;\n for (k = 0; k < 16; k++)\n score += FFABS(src[k - s->linesize] - src[k]);\n }\n if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride]) {\n int k;\n for (k = 0; k < 16; k++)\n score += FFABS(src[k + s->linesize * 15] -\n src[k + s->linesize * 16]);\n }\n if (score <= best_score) {\n best_score = score;\n best_pred = j;\n }\n }\n score_sum += best_score;\n s->mv[0][0][0] = mv_predictor[best_pred][0];\n s->mv[0][0][1] = mv_predictor[best_pred][1];\n for (i = 0; i < mot_step; i++)\n for (j = 0; j < mot_step; j++) {\n s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0];\n s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1];\n }\n decode_mb(s, ref[best_pred]);\n if (s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y) {\n fixed[mb_xy] = MV_CHANGED;\n changed++;\n } else\n fixed[mb_xy] = MV_UNCHANGED;\n }\n }\n }\n if (none_left)\n return;\n for (i = 0; i < s->mb_num; i++) {\n int mb_xy = s->mb_index2xy[i];\n if (fixed[mb_xy])\n fixed[mb_xy] = MV_FROZEN;\n }\n }\n}'] |
34,352 | 0 | https://github.com/openssl/openssl/blob/c15e95a61dacfc326cf9cdf05935ae8c6c97bcf6/apps/apps.c/#L1926 | int bio_to_mem(unsigned char **out, int maxlen, BIO *in)
{
BIO *mem;
int len, ret;
unsigned char tbuf[1024];
mem = BIO_new(BIO_s_mem());
if (mem == NULL)
return -1;
for (;;) {
if ((maxlen != -1) && maxlen < 1024)
len = maxlen;
else
len = 1024;
len = BIO_read(in, tbuf, len);
if (len < 0) {
BIO_free(mem);
return -1;
}
if (len == 0)
break;
if (BIO_write(mem, tbuf, len) != len) {
BIO_free(mem);
return -1;
}
maxlen -= len;
if (maxlen == 0)
break;
}
ret = BIO_get_mem_data(mem, (char **)out);
BIO_set_flags(mem, BIO_FLAGS_MEM_RDONLY);
BIO_free(mem);
return ret;
} | ['int bio_to_mem(unsigned char **out, int maxlen, BIO *in)\n{\n BIO *mem;\n int len, ret;\n unsigned char tbuf[1024];\n mem = BIO_new(BIO_s_mem());\n if (mem == NULL)\n return -1;\n for (;;) {\n if ((maxlen != -1) && maxlen < 1024)\n len = maxlen;\n else\n len = 1024;\n len = BIO_read(in, tbuf, len);\n if (len < 0) {\n BIO_free(mem);\n return -1;\n }\n if (len == 0)\n break;\n if (BIO_write(mem, tbuf, len) != len) {\n BIO_free(mem);\n return -1;\n }\n maxlen -= len;\n if (maxlen == 0)\n break;\n }\n ret = BIO_get_mem_data(mem, (char **)out);\n BIO_set_flags(mem, BIO_FLAGS_MEM_RDONLY);\n BIO_free(mem);\n return ret;\n}', 'BIO_METHOD *BIO_s_mem(void)\n{\n return (&mem_method);\n}', 'BIO *BIO_new(BIO_METHOD *method)\n{\n BIO *ret = OPENSSL_malloc(sizeof(*ret));\n if (ret == NULL) {\n BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n if (!BIO_set(ret, method)) {\n OPENSSL_free(ret);\n ret = NULL;\n }\n return (ret);\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'int BIO_read(BIO *b, void *out, int outl)\n{\n int i;\n long (*cb) (BIO *, int, const char *, int, long, long);\n if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) {\n BIOerr(BIO_F_BIO_READ, BIO_R_UNSUPPORTED_METHOD);\n return (-2);\n }\n cb = b->callback;\n if ((cb != NULL) &&\n ((i = (int)cb(b, BIO_CB_READ, out, outl, 0L, 1L)) <= 0))\n return (i);\n if (!b->init) {\n BIOerr(BIO_F_BIO_READ, BIO_R_UNINITIALIZED);\n return (-2);\n }\n i = b->method->bread(b, out, outl);\n if (i > 0)\n b->num_read += (uint64_t)i;\n if (cb != NULL)\n i = (int)cb(b, BIO_CB_READ | BIO_CB_RETURN, out, outl, 0L, (long)i);\n return (i);\n}', 'int BIO_free(BIO *a)\n{\n int i;\n if (a == NULL)\n return (0);\n i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO);\n REF_PRINT_COUNT("BIO", a);\n if (i > 0)\n return (1);\n REF_ASSERT_ISNT(i < 0);\n if ((a->callback != NULL) &&\n ((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0))\n return (i);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data);\n if ((a->method != NULL) && (a->method->destroy != NULL))\n a->method->destroy(a);\n OPENSSL_free(a);\n return (1);\n}', 'int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,\n int line)\n{\n int ret = 0;\n if (add_lock_callback != NULL) {\n#ifdef LOCK_DEBUG\n int before = *pointer;\n#endif\n ret = add_lock_callback(pointer, amount, type, file, line);\n#ifdef LOCK_DEBUG\n {\n CRYPTO_THREADID id;\n CRYPTO_THREADID_current(&id);\n fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n CRYPTO_THREADID_hash(&id), before, amount, ret,\n CRYPTO_get_lock_name(type), file, line);\n }\n#endif\n } else {\n CRYPTO_lock(CRYPTO_LOCK | CRYPTO_WRITE, type, file, line);\n ret = *pointer + amount;\n#ifdef LOCK_DEBUG\n {\n CRYPTO_THREADID id;\n CRYPTO_THREADID_current(&id);\n fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n CRYPTO_THREADID_hash(&id),\n *pointer, amount, ret,\n CRYPTO_get_lock_name(type), file, line);\n }\n#endif\n *pointer = ret;\n CRYPTO_lock(CRYPTO_UNLOCK | CRYPTO_WRITE, type, file, line);\n }\n return (ret);\n}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n{\n#ifdef LOCK_DEBUG\n {\n CRYPTO_THREADID id;\n char *rw_text, *operation_text;\n if (mode & CRYPTO_LOCK)\n operation_text = "lock ";\n else if (mode & CRYPTO_UNLOCK)\n operation_text = "unlock";\n else\n operation_text = "ERROR ";\n if (mode & CRYPTO_READ)\n rw_text = "r";\n else if (mode & CRYPTO_WRITE)\n rw_text = "w";\n else\n rw_text = "ERROR";\n CRYPTO_THREADID_current(&id);\n fprintf(stderr, "lock:%08lx:(%s)%s %-18s %s:%d\\n",\n CRYPTO_THREADID_hash(&id), rw_text, operation_text,\n CRYPTO_get_lock_name(type), file, line);\n }\n#endif\n if (type < 0) {\n if (dynlock_lock_callback != NULL) {\n struct CRYPTO_dynlock_value *pointer\n = CRYPTO_get_dynlock_value(type);\n OPENSSL_assert(pointer != NULL);\n dynlock_lock_callback(mode, pointer, file, line);\n CRYPTO_destroy_dynlockid(type);\n }\n } else if (locking_callback != NULL)\n locking_callback(mode, type, file, line);\n}'] |
34,353 | 0 | https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L268 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (!bn_to_mont_fixed_top(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !bn_mul_mont_fixed_top(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n r->flags |= BN_FLG_FIXED_TOP;\n } else\n#endif\n if (!bn_to_mont_fixed_top(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (!bn_mul_mont_fixed_top(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int bn_to_mont_fixed_top(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return bn_mul_mont_fixed_top(r, a, &(mont->RR), mont, ctx);\n}', 'int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!bn_sqr_fixed_top(tmp, a, ctx))\n goto err;\n } else {\n if (!bn_mul_fixed_top(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!bn_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}'] |
34,354 | 0 | https://github.com/libav/libav/blob/63380b5e54f64abdde4a8b6bce0d60f1fa4a22a1/libavcodec/ac3.c/#L163 | int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
int start, int end, int fast_gain, int is_lfe,
int dba_mode, int dba_nsegs, uint8_t *dba_offsets,
uint8_t *dba_lengths, uint8_t *dba_values,
int16_t *mask)
{
int16_t excite[50];
int band;
int band_start, band_end, begin, end1;
int lowcomp, fastleak, slowleak;
band_start = bin_to_band_tab[start];
band_end = bin_to_band_tab[end-1] + 1;
if (band_start == 0) {
lowcomp = 0;
lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384);
excite[0] = band_psd[0] - fast_gain - lowcomp;
lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384);
excite[1] = band_psd[1] - fast_gain - lowcomp;
begin = 7;
for (band = 2; band < 7; band++) {
if (!(is_lfe && band == 6))
lowcomp = calc_lowcomp1(lowcomp, band_psd[band], band_psd[band+1], 384);
fastleak = band_psd[band] - fast_gain;
slowleak = band_psd[band] - s->slow_gain;
excite[band] = fastleak - lowcomp;
if (!(is_lfe && band == 6)) {
if (band_psd[band] <= band_psd[band+1]) {
begin = band + 1;
break;
}
}
}
end1 = FFMIN(band_end, 22);
for (band = begin; band < end1; band++) {
if (!(is_lfe && band == 6))
lowcomp = calc_lowcomp(lowcomp, band_psd[band], band_psd[band+1], band);
fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain);
slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain);
excite[band] = FFMAX(fastleak - lowcomp, slowleak);
}
begin = 22;
} else {
begin = band_start;
fastleak = (s->cpl_fast_leak << 8) + 768;
slowleak = (s->cpl_slow_leak << 8) + 768;
}
for (band = begin; band < band_end; band++) {
fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain);
slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain);
excite[band] = FFMAX(fastleak, slowleak);
}
for (band = band_start; band < band_end; band++) {
int tmp = s->db_per_bit - band_psd[band];
if (tmp > 0) {
excite[band] += tmp >> 2;
}
mask[band] = FFMAX(ff_ac3_hearing_threshold_tab[band >> s->sr_shift][s->sr_code], excite[band]);
}
if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {
int i, seg, delta;
if (dba_nsegs >= 8)
return -1;
band = 0;
for (seg = 0; seg < dba_nsegs; seg++) {
band += dba_offsets[seg];
if (band >= 50 || dba_lengths[seg] > 50-band)
return -1;
if (dba_values[seg] >= 4) {
delta = (dba_values[seg] - 3) << 7;
} else {
delta = (dba_values[seg] - 4) << 7;
}
for (i = 0; i < dba_lengths[seg]; i++) {
mask[band++] += delta;
}
}
}
return 0;
} | ['int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,\n int start, int end, int fast_gain, int is_lfe,\n int dba_mode, int dba_nsegs, uint8_t *dba_offsets,\n uint8_t *dba_lengths, uint8_t *dba_values,\n int16_t *mask)\n{\n int16_t excite[50];\n int band;\n int band_start, band_end, begin, end1;\n int lowcomp, fastleak, slowleak;\n band_start = bin_to_band_tab[start];\n band_end = bin_to_band_tab[end-1] + 1;\n if (band_start == 0) {\n lowcomp = 0;\n lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384);\n excite[0] = band_psd[0] - fast_gain - lowcomp;\n lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384);\n excite[1] = band_psd[1] - fast_gain - lowcomp;\n begin = 7;\n for (band = 2; band < 7; band++) {\n if (!(is_lfe && band == 6))\n lowcomp = calc_lowcomp1(lowcomp, band_psd[band], band_psd[band+1], 384);\n fastleak = band_psd[band] - fast_gain;\n slowleak = band_psd[band] - s->slow_gain;\n excite[band] = fastleak - lowcomp;\n if (!(is_lfe && band == 6)) {\n if (band_psd[band] <= band_psd[band+1]) {\n begin = band + 1;\n break;\n }\n }\n }\n end1 = FFMIN(band_end, 22);\n for (band = begin; band < end1; band++) {\n if (!(is_lfe && band == 6))\n lowcomp = calc_lowcomp(lowcomp, band_psd[band], band_psd[band+1], band);\n fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain);\n slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain);\n excite[band] = FFMAX(fastleak - lowcomp, slowleak);\n }\n begin = 22;\n } else {\n begin = band_start;\n fastleak = (s->cpl_fast_leak << 8) + 768;\n slowleak = (s->cpl_slow_leak << 8) + 768;\n }\n for (band = begin; band < band_end; band++) {\n fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain);\n slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain);\n excite[band] = FFMAX(fastleak, slowleak);\n }\n for (band = band_start; band < band_end; band++) {\n int tmp = s->db_per_bit - band_psd[band];\n if (tmp > 0) {\n excite[band] += tmp >> 2;\n }\n mask[band] = FFMAX(ff_ac3_hearing_threshold_tab[band >> s->sr_shift][s->sr_code], excite[band]);\n }\n if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {\n int i, seg, delta;\n if (dba_nsegs >= 8)\n return -1;\n band = 0;\n for (seg = 0; seg < dba_nsegs; seg++) {\n band += dba_offsets[seg];\n if (band >= 50 || dba_lengths[seg] > 50-band)\n return -1;\n if (dba_values[seg] >= 4) {\n delta = (dba_values[seg] - 3) << 7;\n } else {\n delta = (dba_values[seg] - 4) << 7;\n }\n for (i = 0; i < dba_lengths[seg]; i++) {\n mask[band++] += delta;\n }\n }\n }\n return 0;\n}'] |
34,355 | 0 | https://gitlab.com/libtiff/libtiff/blob/163627448aa8d2893582f2546dd85706586e6243/tools/tiffdump.c/#L664 | static void
PrintASCII(FILE* fd, uint32 cc, const unsigned char* cp)
{
for (; cc > 0; cc--, cp++) {
const char* tp;
if (isprint(*cp)) {
fputc(*cp, fd);
continue;
}
for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
if (*tp++ == *cp)
break;
if (*tp)
fprintf(fd, "\\%c", *tp);
else if (*cp)
fprintf(fd, "\\%03o", *cp);
else
fprintf(fd, "\\0");
}
} | ['static uint64\nReadDirectory(int fd, unsigned int ix, uint64 off)\n{\n\tuint16 dircount;\n\tuint32 direntrysize;\n\tvoid* dirmem = NULL;\n\tuint64 nextdiroff = 0;\n\tuint32 n;\n\tuint8* dp;\n\tif (off == 0)\n\t\tgoto done;\n#if defined(__WIN32__) && defined(_MSC_VER)\n\tif (_lseeki64(fd, (__int64)off, SEEK_SET) != (__int64)off) {\n#else\n\tif (lseek(fd, (off_t)off, SEEK_SET) != (off_t)off) {\n#endif\n\t\tFatal("Seek error accessing TIFF directory");\n\t\tgoto done;\n\t}\n\tif (!bigtiff) {\n\t\tif (read(fd, (char*) &dircount, sizeof (uint16)) != sizeof (uint16)) {\n\t\t\tReadError("directory count");\n\t\t\tgoto done;\n\t\t}\n\t\tif (swabflag)\n\t\t\tTIFFSwabShort(&dircount);\n\t\tdirentrysize = 12;\n\t} else {\n\t\tuint64 dircount64 = 0;\n\t\tif (read(fd, (char*) &dircount64, sizeof (uint64)) != sizeof (uint64)) {\n\t\t\tReadError("directory count");\n\t\t\tgoto done;\n\t\t}\n\t\tif (swabflag)\n\t\t\tTIFFSwabLong8(&dircount64);\n\t\tif (dircount64>0xFFFF) {\n\t\t\tError("Sanity check on directory count failed");\n\t\t\tgoto done;\n\t\t}\n\t\tdircount = (uint16)dircount64;\n\t\tdirentrysize = 20;\n\t}\n\tdirmem = _TIFFmalloc(dircount * direntrysize);\n\tif (dirmem == NULL) {\n\t\tFatal("No space for TIFF directory");\n\t\tgoto done;\n\t}\n\tn = read(fd, (char*) dirmem, dircount*direntrysize);\n\tif (n != dircount*direntrysize) {\n\t\tn /= direntrysize;\n\t\tError(\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t "Could only read %lu of %u entries in directory at offset %#I64x",\n\t\t (unsigned long)n, dircount, (unsigned __int64) off);\n#else\n\t "Could only read %lu of %u entries in directory at offset %#llx",\n\t\t (unsigned long)n, dircount, (unsigned long long) off);\n#endif\n\t\tdircount = n;\n\t\tnextdiroff = 0;\n\t} else {\n\t\tif (!bigtiff) {\n\t\t\tuint32 nextdiroff32;\n\t\t\tif (read(fd, (char*) &nextdiroff32, sizeof (uint32)) != sizeof (uint32))\n\t\t\t\tnextdiroff32 = 0;\n\t\t\tif (swabflag)\n\t\t\t\tTIFFSwabLong(&nextdiroff32);\n\t\t\tnextdiroff = nextdiroff32;\n\t\t} else {\n\t\t\tif (read(fd, (char*) &nextdiroff, sizeof (uint64)) != sizeof (uint64))\n\t\t\t\tnextdiroff = 0;\n\t\t\tif (swabflag)\n\t\t\t\tTIFFSwabLong8(&nextdiroff);\n\t\t}\n\t}\n#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))\n\tprintf("Directory %u: offset %I64u (%#I64x) next %I64u (%#I64x)\\n", ix,\n\t (unsigned __int64)off, (unsigned __int64)off,\n\t (unsigned __int64)nextdiroff, (unsigned __int64)nextdiroff);\n#else\n\tprintf("Directory %u: offset %llu (%#llx) next %llu (%#llx)\\n", ix,\n\t (unsigned long long)off, (unsigned long long)off,\n\t (unsigned long long)nextdiroff, (unsigned long long)nextdiroff);\n#endif\n\tfor (dp = (uint8*)dirmem, n = dircount; n > 0; n--) {\n\t\tuint16 tag;\n\t\tuint16 type;\n\t\tuint16 typewidth;\n\t\tuint64 count;\n\t\tuint64 datasize;\n\t\tint datafits;\n\t\tvoid* datamem;\n\t\tuint64 dataoffset;\n\t\tint datatruncated;\n\t\ttag = *(uint16*)dp;\n\t\tif (swabflag)\n\t\t\tTIFFSwabShort(&tag);\n\t\tdp += sizeof(uint16);\n\t\ttype = *(uint16*)dp;\n\t\tdp += sizeof(uint16);\n\t\tif (swabflag)\n\t\t\tTIFFSwabShort(&type);\n\t\tPrintTag(stdout, tag);\n\t\tputchar(\' \');\n\t\tPrintType(stdout, type);\n\t\tputchar(\' \');\n\t\tif (!bigtiff)\n\t\t{\n\t\t\tuint32 count32;\n\t\t\tcount32 = *(uint32*)dp;\n\t\t\tif (swabflag)\n\t\t\t\tTIFFSwabLong(&count32);\n\t\t\tdp += sizeof(uint32);\n\t\t\tcount = count32;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tcount = *(uint64*)dp;\n\t\t\tif (swabflag)\n\t\t\t\tTIFFSwabLong8(&count);\n\t\t\tdp += sizeof(uint64);\n\t\t}\n#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))\n\t\tprintf("%I64u<", (unsigned __int64)count);\n#else\n\t\tprintf("%llu<", (unsigned long long)count);\n#endif\n\t\tif (type >= NWIDTHS)\n\t\t\ttypewidth = 0;\n\t\telse\n\t\t\ttypewidth = datawidth[type];\n\t\tdatasize = count*typewidth;\n\t\tdatafits = 1;\n\t\tdatamem = dp;\n\t\tdataoffset = 0;\n\t\tdatatruncated = 0;\n\t\tif (!bigtiff)\n\t\t{\n\t\t\tif (datasize>4)\n\t\t\t{\n\t\t\t\tuint32 dataoffset32;\n\t\t\t\tdatafits = 0;\n\t\t\t\tdatamem = NULL;\n\t\t\t\tdataoffset32 = *(uint32*)dp;\n\t\t\t\tif (swabflag)\n\t\t\t\t\tTIFFSwabLong(&dataoffset32);\n\t\t\t\tdataoffset = dataoffset32;\n\t\t\t}\n\t\t\tdp += sizeof(uint32);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (datasize>8)\n\t\t\t{\n\t\t\t\tdatafits = 0;\n\t\t\t\tdatamem = NULL;\n\t\t\t\tdataoffset = *(uint64*)dp;\n\t\t\t\tif (swabflag)\n\t\t\t\t\tTIFFSwabLong8(&dataoffset);\n\t\t\t}\n\t\t\tdp += sizeof(uint64);\n\t\t}\n\t\tif (datasize>0x10000)\n\t\t{\n\t\t\tdatatruncated = 1;\n\t\t\tcount = 0x10000/typewidth;\n\t\t\tdatasize = count*typewidth;\n\t\t}\n\t\tif (count>maxitems)\n\t\t{\n\t\t\tdatatruncated = 1;\n\t\t\tcount = maxitems;\n\t\t\tdatasize = count*typewidth;\n\t\t}\n\t\tif (!datafits)\n\t\t{\n\t\t\tdatamem = _TIFFmalloc((uint32)datasize);\n\t\t\tif (datamem) {\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t\t\t\tif (_lseeki64(fd, (__int64)dataoffset, SEEK_SET)\n\t\t\t\t != (__int64)dataoffset)\n#else\n\t\t\t\tif (lseek(fd, (off_t)dataoffset, 0) !=\n\t\t\t\t (off_t)dataoffset)\n#endif\n\t\t\t\t{\n\t\t\t\t\tError(\n\t\t\t\t"Seek error accessing tag %u value", tag);\n\t\t\t\t\t_TIFFfree(datamem);\n\t\t\t\t\tdatamem = NULL;\n\t\t\t\t}\n\t\t\t\tif (read(fd, datamem, (size_t)datasize) != (TIFF_SSIZE_T)datasize)\n\t\t\t\t{\n\t\t\t\t\tError(\n\t\t\t\t"Read error accessing tag %u value", tag);\n\t\t\t\t\t_TIFFfree(datamem);\n\t\t\t\t\tdatamem = NULL;\n\t\t\t\t}\n\t\t\t} else\n\t\t\t\tError("No space for data for tag %u",tag);\n\t\t}\n\t\tif (datamem)\n\t\t{\n\t\t\tif (swabflag)\n\t\t\t{\n\t\t\t\tswitch (type)\n\t\t\t\t{\n\t\t\t\t\tcase TIFF_BYTE:\n\t\t\t\t\tcase TIFF_ASCII:\n\t\t\t\t\tcase TIFF_SBYTE:\n\t\t\t\t\tcase TIFF_UNDEFINED:\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase TIFF_SHORT:\n\t\t\t\t\tcase TIFF_SSHORT:\n\t\t\t\t\t\tTIFFSwabArrayOfShort((uint16*)datamem,(tmsize_t)count);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase TIFF_LONG:\n\t\t\t\t\tcase TIFF_SLONG:\n\t\t\t\t\tcase TIFF_FLOAT:\n\t\t\t\t\tcase TIFF_IFD:\n\t\t\t\t\t\tTIFFSwabArrayOfLong((uint32*)datamem,(tmsize_t)count);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase TIFF_RATIONAL:\n\t\t\t\t\tcase TIFF_SRATIONAL:\n\t\t\t\t\t\tTIFFSwabArrayOfLong((uint32*)datamem,(tmsize_t)count*2);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase TIFF_DOUBLE:\n\t\t\t\t\tcase TIFF_LONG8:\n\t\t\t\t\tcase TIFF_SLONG8:\n\t\t\t\t\tcase TIFF_IFD8:\n\t\t\t\t\t\tTIFFSwabArrayOfLong8((uint64*)datamem,(tmsize_t)count);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tPrintData(stdout,type,(uint32)count,datamem);\n\t\t\tif (datatruncated)\n\t\t\t\tprintf(" ...");\n\t\t\tif (!datafits)\n\t\t\t\t_TIFFfree(datamem);\n\t\t}\n\t\tprintf(">\\n");\n\t}\ndone:\n\tif (dirmem)\n\t\t_TIFFfree((char *)dirmem);\n\treturn (nextdiroff);\n}', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n if (s == 0)\n return ((void *) NULL);\n\treturn (malloc((size_t) s));\n}', 'static void\nPrintData(FILE* fd, uint16 type, uint32 count, unsigned char* data)\n{\n\tchar* sep = "";\n\tswitch (type) {\n\tcase TIFF_BYTE:\n\t\twhile (count-- > 0)\n\t\t\tfprintf(fd, bytefmt, sep, *data++), sep = " ";\n\t\tbreak;\n\tcase TIFF_SBYTE:\n\t\twhile (count-- > 0)\n\t\t\tfprintf(fd, sbytefmt, sep, *(char *)data++), sep = " ";\n\t\tbreak;\n\tcase TIFF_UNDEFINED:\n\t\twhile (count-- > 0)\n\t\t\tfprintf(fd, bytefmt, sep, *data++), sep = " ";\n\t\tbreak;\n\tcase TIFF_ASCII:\n\t\tPrintASCII(fd, count, data);\n\t\tbreak;\n\tcase TIFF_SHORT: {\n\t\tuint16 *wp = (uint16*)data;\n\t\twhile (count-- > 0)\n\t\t\tfprintf(fd, shortfmt, sep, *wp++), sep = " ";\n\t\tbreak;\n\t}\n\tcase TIFF_SSHORT: {\n\t\tint16 *wp = (int16*)data;\n\t\twhile (count-- > 0)\n\t\t\tfprintf(fd, sshortfmt, sep, *wp++), sep = " ";\n\t\tbreak;\n\t}\n\tcase TIFF_LONG: {\n\t\tuint32 *lp = (uint32*)data;\n\t\twhile (count-- > 0) {\n\t\t\tfprintf(fd, longfmt, sep, (unsigned long) *lp++);\n\t\t\tsep = " ";\n\t\t}\n\t\tbreak;\n\t}\n\tcase TIFF_SLONG: {\n\t\tint32 *lp = (int32*)data;\n\t\twhile (count-- > 0)\n\t\t\tfprintf(fd, slongfmt, sep, (long) *lp++), sep = " ";\n\t\tbreak;\n\t}\n\tcase TIFF_LONG8: {\n\t\tuint64 *llp = (uint64*)data;\n\t\twhile (count-- > 0) {\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t\t\tfprintf(fd, long8fmt, sep, (unsigned __int64) *llp++);\n#else\n\t\t\tfprintf(fd, long8fmt, sep, (unsigned long long) *llp++);\n#endif\n\t\t\tsep = " ";\n\t\t}\n\t\tbreak;\n\t}\n\tcase TIFF_SLONG8: {\n\t\tint64 *llp = (int64*)data;\n\t\twhile (count-- > 0)\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t\t\tfprintf(fd, slong8fmt, sep, (__int64) *llp++), sep = " ";\n#else\n\t\t\tfprintf(fd, slong8fmt, sep, (long long) *llp++), sep = " ";\n#endif\n\t\tbreak;\n\t}\n\tcase TIFF_RATIONAL: {\n\t\tuint32 *lp = (uint32*)data;\n\t\twhile (count-- > 0) {\n\t\t\tif (lp[1] == 0)\n\t\t\t\tfprintf(fd, "%sNan (%lu/%lu)", sep,\n\t\t\t\t (unsigned long) lp[0],\n\t\t\t\t (unsigned long) lp[1]);\n\t\t\telse\n\t\t\t\tfprintf(fd, rationalfmt, sep,\n\t\t\t\t (double)lp[0] / (double)lp[1]);\n\t\t\tsep = " ";\n\t\t\tlp += 2;\n\t\t}\n\t\tbreak;\n\t}\n\tcase TIFF_SRATIONAL: {\n\t\tint32 *lp = (int32*)data;\n\t\twhile (count-- > 0) {\n\t\t\tif (lp[1] == 0)\n\t\t\t\tfprintf(fd, "%sNan (%ld/%ld)", sep,\n\t\t\t\t (long) lp[0], (long) lp[1]);\n\t\t\telse\n\t\t\t\tfprintf(fd, srationalfmt, sep,\n\t\t\t\t (double)lp[0] / (double)lp[1]);\n\t\t\tsep = " ";\n\t\t\tlp += 2;\n\t\t}\n\t\tbreak;\n\t}\n\tcase TIFF_FLOAT: {\n\t\tfloat *fp = (float *)data;\n\t\twhile (count-- > 0)\n\t\t\tfprintf(fd, floatfmt, sep, *fp++), sep = " ";\n\t\tbreak;\n\t}\n\tcase TIFF_DOUBLE: {\n\t\tdouble *dp = (double *)data;\n\t\twhile (count-- > 0)\n\t\t\tfprintf(fd, doublefmt, sep, *dp++), sep = " ";\n\t\tbreak;\n\t}\n\tcase TIFF_IFD: {\n\t\tuint32 *lp = (uint32*)data;\n\t\twhile (count-- > 0) {\n\t\t\tfprintf(fd, ifdfmt, sep, (unsigned long) *lp++);\n\t\t\tsep = " ";\n\t\t}\n\t\tbreak;\n\t}\n\tcase TIFF_IFD8: {\n\t\tuint64 *llp = (uint64*)data;\n\t\twhile (count-- > 0) {\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t\t\tfprintf(fd, ifd8fmt, sep, (unsigned __int64) *llp++);\n#else\n\t\t\tfprintf(fd, ifd8fmt, sep, (unsigned long long) *llp++);\n#endif\n\t\t\tsep = " ";\n\t\t}\n\t\tbreak;\n\t}\n\t}\n}', 'static void\nPrintASCII(FILE* fd, uint32 cc, const unsigned char* cp)\n{\n\tfor (; cc > 0; cc--, cp++) {\n\t\tconst char* tp;\n\t\tif (isprint(*cp)) {\n\t\t\tfputc(*cp, fd);\n\t\t\tcontinue;\n\t\t}\n\t\tfor (tp = "\\tt\\bb\\rr\\nn\\vv"; *tp; tp++)\n\t\t\tif (*tp++ == *cp)\n\t\t\t\tbreak;\n\t\tif (*tp)\n\t\t\tfprintf(fd, "\\\\%c", *tp);\n\t\telse if (*cp)\n\t\t\tfprintf(fd, "\\\\%03o", *cp);\n\t\telse\n\t\t\tfprintf(fd, "\\\\0");\n\t}\n}'] |
34,356 | 0 | https://github.com/libav/libav/blob/c15fea7933b3801962851a37c3ef00ce968431c4/libavcodec/ansi.c/#L225 | static int execute_code(AVCodecContext * avctx, int c)
{
AnsiContext *s = avctx->priv_data;
int ret, i, width, height;
switch(c) {
case 'A':
s->y = FFMAX(s->y - (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), 0);
break;
case 'B':
s->y = FFMIN(s->y + (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), avctx->height - s->font_height);
break;
case 'C':
s->x = FFMIN(s->x + (s->nb_args > 0 ? s->args[0]*FONT_WIDTH : FONT_WIDTH), avctx->width - FONT_WIDTH);
break;
case 'D':
s->x = FFMAX(s->x - (s->nb_args > 0 ? s->args[0]*FONT_WIDTH : FONT_WIDTH), 0);
break;
case 'H':
case 'f':
s->y = s->nb_args > 0 ? av_clip((s->args[0] - 1)*s->font_height, 0, avctx->height - s->font_height) : 0;
s->x = s->nb_args > 1 ? av_clip((s->args[1] - 1)*FONT_WIDTH, 0, avctx->width - FONT_WIDTH) : 0;
break;
case 'h':
case 'l':
if (s->nb_args < 2)
s->args[0] = DEFAULT_SCREEN_MODE;
switch(s->args[0]) {
case 0: case 1: case 4: case 5: case 13: case 19:
s->font = ff_cga_font;
s->font_height = 8;
width = 40<<3;
height = 25<<3;
break;
case 2: case 3:
s->font = ff_vga16_font;
s->font_height = 16;
width = 80<<3;
height = 25<<4;
break;
case 6: case 14:
s->font = ff_cga_font;
s->font_height = 8;
width = 80<<3;
height = 25<<3;
break;
case 7:
break;
case 15: case 16:
s->font = ff_cga_font;
s->font_height = 8;
width = 80<<3;
height = 43<<3;
break;
case 17: case 18:
s->font = ff_cga_font;
s->font_height = 8;
width = 80<<3;
height = 60<<4;
break;
default:
av_log_ask_for_sample(avctx, "unsupported screen mode\n");
}
if (width != avctx->width || height != avctx->height) {
if (s->frame.data[0])
avctx->release_buffer(avctx, &s->frame);
avcodec_set_dimensions(avctx, width, height);
ret = ff_get_buffer(avctx, &s->frame);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
s->frame.pict_type = AV_PICTURE_TYPE_I;
s->frame.palette_has_changed = 1;
memcpy(s->frame.data[1], ff_cga_palette, 16 * 4);
erase_screen(avctx);
} else if (c == 'l') {
erase_screen(avctx);
}
break;
case 'J':
switch (s->args[0]) {
case 0:
erase_line(avctx, s->x, avctx->width - s->x);
if (s->y < avctx->height - s->font_height)
memset(s->frame.data[0] + (s->y + s->font_height)*s->frame.linesize[0],
DEFAULT_BG_COLOR, (avctx->height - s->y - s->font_height)*s->frame.linesize[0]);
break;
case 1:
erase_line(avctx, 0, s->x);
if (s->y > 0)
memset(s->frame.data[0], DEFAULT_BG_COLOR, s->y * s->frame.linesize[0]);
break;
case 2:
erase_screen(avctx);
}
break;
case 'K':
switch(s->args[0]) {
case 0:
erase_line(avctx, s->x, avctx->width - s->x);
break;
case 1:
erase_line(avctx, 0, s->x);
break;
case 2:
erase_line(avctx, 0, avctx->width);
}
break;
case 'm':
if (s->nb_args == 0) {
s->nb_args = 1;
s->args[0] = 0;
}
for (i = 0; i < FFMIN(s->nb_args, MAX_NB_ARGS); i++) {
int m = s->args[i];
if (m == 0) {
s->attributes = 0;
s->fg = DEFAULT_FG_COLOR;
s->bg = DEFAULT_BG_COLOR;
} else if (m == 1 || m == 2 || m == 4 || m == 5 || m == 7 || m == 8) {
s->attributes |= 1 << (m - 1);
} else if (m >= 30 && m <= 38) {
s->fg = ansi_to_cga[m - 30];
} else if (m == 39) {
s->fg = ansi_to_cga[DEFAULT_FG_COLOR];
} else if (m >= 40 && m <= 47) {
s->bg = ansi_to_cga[m - 40];
} else if (m == 49) {
s->fg = ansi_to_cga[DEFAULT_BG_COLOR];
} else {
av_log_ask_for_sample(avctx, "unsupported rendition parameter\n");
}
}
break;
case 'n':
case 'R':
break;
case 's':
s->sx = s->x;
s->sy = s->y;
break;
case 'u':
s->x = av_clip(s->sx, 0, avctx->width - FONT_WIDTH);
s->y = av_clip(s->sy, 0, avctx->height - s->font_height);
break;
default:
av_log_ask_for_sample(avctx, "unsupported escape code\n");
break;
}
return 0;
} | ['static int execute_code(AVCodecContext * avctx, int c)\n{\n AnsiContext *s = avctx->priv_data;\n int ret, i, width, height;\n switch(c) {\n case \'A\':\n s->y = FFMAX(s->y - (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), 0);\n break;\n case \'B\':\n s->y = FFMIN(s->y + (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), avctx->height - s->font_height);\n break;\n case \'C\':\n s->x = FFMIN(s->x + (s->nb_args > 0 ? s->args[0]*FONT_WIDTH : FONT_WIDTH), avctx->width - FONT_WIDTH);\n break;\n case \'D\':\n s->x = FFMAX(s->x - (s->nb_args > 0 ? s->args[0]*FONT_WIDTH : FONT_WIDTH), 0);\n break;\n case \'H\':\n case \'f\':\n s->y = s->nb_args > 0 ? av_clip((s->args[0] - 1)*s->font_height, 0, avctx->height - s->font_height) : 0;\n s->x = s->nb_args > 1 ? av_clip((s->args[1] - 1)*FONT_WIDTH, 0, avctx->width - FONT_WIDTH) : 0;\n break;\n case \'h\':\n case \'l\':\n if (s->nb_args < 2)\n s->args[0] = DEFAULT_SCREEN_MODE;\n switch(s->args[0]) {\n case 0: case 1: case 4: case 5: case 13: case 19:\n s->font = ff_cga_font;\n s->font_height = 8;\n width = 40<<3;\n height = 25<<3;\n break;\n case 2: case 3:\n s->font = ff_vga16_font;\n s->font_height = 16;\n width = 80<<3;\n height = 25<<4;\n break;\n case 6: case 14:\n s->font = ff_cga_font;\n s->font_height = 8;\n width = 80<<3;\n height = 25<<3;\n break;\n case 7:\n break;\n case 15: case 16:\n s->font = ff_cga_font;\n s->font_height = 8;\n width = 80<<3;\n height = 43<<3;\n break;\n case 17: case 18:\n s->font = ff_cga_font;\n s->font_height = 8;\n width = 80<<3;\n height = 60<<4;\n break;\n default:\n av_log_ask_for_sample(avctx, "unsupported screen mode\\n");\n }\n if (width != avctx->width || height != avctx->height) {\n if (s->frame.data[0])\n avctx->release_buffer(avctx, &s->frame);\n avcodec_set_dimensions(avctx, width, height);\n ret = ff_get_buffer(avctx, &s->frame);\n if (ret < 0) {\n av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return ret;\n }\n s->frame.pict_type = AV_PICTURE_TYPE_I;\n s->frame.palette_has_changed = 1;\n memcpy(s->frame.data[1], ff_cga_palette, 16 * 4);\n erase_screen(avctx);\n } else if (c == \'l\') {\n erase_screen(avctx);\n }\n break;\n case \'J\':\n switch (s->args[0]) {\n case 0:\n erase_line(avctx, s->x, avctx->width - s->x);\n if (s->y < avctx->height - s->font_height)\n memset(s->frame.data[0] + (s->y + s->font_height)*s->frame.linesize[0],\n DEFAULT_BG_COLOR, (avctx->height - s->y - s->font_height)*s->frame.linesize[0]);\n break;\n case 1:\n erase_line(avctx, 0, s->x);\n if (s->y > 0)\n memset(s->frame.data[0], DEFAULT_BG_COLOR, s->y * s->frame.linesize[0]);\n break;\n case 2:\n erase_screen(avctx);\n }\n break;\n case \'K\':\n switch(s->args[0]) {\n case 0:\n erase_line(avctx, s->x, avctx->width - s->x);\n break;\n case 1:\n erase_line(avctx, 0, s->x);\n break;\n case 2:\n erase_line(avctx, 0, avctx->width);\n }\n break;\n case \'m\':\n if (s->nb_args == 0) {\n s->nb_args = 1;\n s->args[0] = 0;\n }\n for (i = 0; i < FFMIN(s->nb_args, MAX_NB_ARGS); i++) {\n int m = s->args[i];\n if (m == 0) {\n s->attributes = 0;\n s->fg = DEFAULT_FG_COLOR;\n s->bg = DEFAULT_BG_COLOR;\n } else if (m == 1 || m == 2 || m == 4 || m == 5 || m == 7 || m == 8) {\n s->attributes |= 1 << (m - 1);\n } else if (m >= 30 && m <= 38) {\n s->fg = ansi_to_cga[m - 30];\n } else if (m == 39) {\n s->fg = ansi_to_cga[DEFAULT_FG_COLOR];\n } else if (m >= 40 && m <= 47) {\n s->bg = ansi_to_cga[m - 40];\n } else if (m == 49) {\n s->fg = ansi_to_cga[DEFAULT_BG_COLOR];\n } else {\n av_log_ask_for_sample(avctx, "unsupported rendition parameter\\n");\n }\n }\n break;\n case \'n\':\n case \'R\':\n break;\n case \'s\':\n s->sx = s->x;\n s->sy = s->y;\n break;\n case \'u\':\n s->x = av_clip(s->sx, 0, avctx->width - FONT_WIDTH);\n s->y = av_clip(s->sy, 0, avctx->height - s->font_height);\n break;\n default:\n av_log_ask_for_sample(avctx, "unsupported escape code\\n");\n break;\n }\n return 0;\n}'] |
34,357 | 0 | https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L268 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['int rsa_get_lcm(BN_CTX *ctx, const BIGNUM *p, const BIGNUM *q,\n BIGNUM *lcm, BIGNUM *gcd, BIGNUM *p1, BIGNUM *q1,\n BIGNUM *p1q1)\n{\n return BN_sub(p1, p, BN_value_one())\n && BN_sub(q1, q, BN_value_one())\n && BN_mul(p1q1, p1, q1, ctx)\n && BN_gcd(gcd, p1, q1, ctx)\n && BN_div(lcm, NULL, p1q1, gcd, ctx);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = bn_mul_fixed_top(r, a, b, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)\n{\n BIGNUM *a, *b, *t;\n int ret = 0;\n bn_check_top(in_a);\n bn_check_top(in_b);\n BN_CTX_start(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (b == NULL)\n goto err;\n if (BN_copy(a, in_a) == NULL)\n goto err;\n if (BN_copy(b, in_b) == NULL)\n goto err;\n a->neg = 0;\n b->neg = 0;\n if (BN_cmp(a, b) < 0) {\n t = a;\n a = b;\n b = t;\n }\n t = euclid(a, b);\n if (t == NULL)\n goto err;\n if (BN_copy(r, t) == NULL)\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n const BIGNUM *divisor, BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnum, *wnumtop;\n BN_ULONG d0, d1;\n int num_n, div_n;\n assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);\n bn_check_top(num);\n bn_check_top(divisor);\n bn_check_top(dv);\n bn_check_top(rm);\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n if (!BN_copy(sdiv, divisor))\n goto err;\n norm_shift = bn_left_align(sdiv);\n sdiv->neg = 0;\n if (!(bn_lshift_fixed_top(snum, num, norm_shift)))\n goto err;\n div_n = sdiv->top;\n num_n = snum->top;\n if (num_n <= div_n) {\n if (bn_wexpand(snum, div_n + 1) == NULL)\n goto err;\n memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));\n snum->top = num_n = div_n + 1;\n }\n loop = num_n - div_n;\n wnum = &(snum->d[loop]);\n wnumtop = &(snum->d[num_n - 1]);\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n if (!bn_wexpand(res, loop))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop;\n res->flags |= BN_FLG_FIXED_TOP;\n resp = &(res->d[loop]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n for (i = 0; i < loop; i++, wnumtop--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnumtop, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnumtop[0];\n n1 = wnumtop[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum--;\n l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);\n q -= l0;\n for (l0 = 0 - l0, j = 0; j < div_n; j++)\n tmp->d[j] = sdiv->d[j] & l0;\n l0 = bn_add_words(wnum, wnum, tmp->d, div_n);\n (*wnumtop) += l0;\n assert((*wnumtop) == 0);\n *--resp = q;\n }\n snum->neg = num->neg;\n snum->top = div_n;\n snum->flags |= BN_FLG_FIXED_TOP;\n if (rm != NULL)\n bn_rshift_fixed_top(rm, snum, norm_shift);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}'] |
34,358 | 0 | https://gitlab.com/libtiff/libtiff/blob/709e93ded0000128625a23838756a408ea30745d/libtiff/tif_read.c/#L945 | static int
TIFFStartTile(TIFF* tif, uint32 tile)
{
TIFFDirectory *td = &tif->tif_dir;
if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
if (!(*tif->tif_setupdecode)(tif))
return (0);
tif->tif_flags |= TIFF_CODERSETUP;
}
tif->tif_curtile = tile;
tif->tif_row =
(tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) *
td->td_tilelength;
tif->tif_col =
(tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) *
td->td_tilewidth;
tif->tif_flags &= ~TIFF_BUF4WRITE;
if (tif->tif_flags&TIFF_NOREADRAW)
{
tif->tif_rawcp = NULL;
tif->tif_rawcc = 0;
}
else
{
tif->tif_rawcp = tif->tif_rawdata;
tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];
}
return ((*tif->tif_predecode)(tif,
(uint16)(tile/td->td_stripsperimage)));
} | ['tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_t tile){\n\tuint16 edge=0;\n\ttsize_t written=0;\n\tunsigned char* buffer=NULL;\n\ttsize_t bufferoffset=0;\n\tunsigned char* samplebuffer=NULL;\n\ttsize_t samplebufferoffset=0;\n\ttsize_t read=0;\n\tuint16 i=0;\n\tttile_t tilecount=0;\n\ttsize_t tilesize=0;\n\tttile_t septilecount=0;\n\ttsize_t septilesize=0;\n#ifdef JPEG_SUPPORT\n\tunsigned char* jpt;\n\tfloat* xfloatp;\n\tuint32 xuint32=0;\n#endif\n\tedge |= t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tedge |= t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tif( (t2p->pdf_transcode == T2P_TRANSCODE_RAW) && ((edge == 0)\n#if defined(JPEG_SUPPORT) || defined(OJPEG_SUPPORT)\n\t\t|| (t2p->pdf_compression == T2P_COMPRESS_JPEG)\n#endif\n\t)\n\t){\n#ifdef CCITT_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_G4){\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tTIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\tif (t2p->tiff_fillorder==FILLORDER_LSB2MSB){\n\t\t\t\t\tTIFFReverseBits(buffer, t2p->tiff_datasize);\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(t2p->tiff_datasize);\n\t\t}\n#endif\n#ifdef ZIP_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_ZIP){\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tTIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\tif (t2p->tiff_fillorder==FILLORDER_LSB2MSB){\n\t\t\t\t\tTIFFReverseBits(buffer, t2p->tiff_datasize);\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(t2p->tiff_datasize);\n\t\t}\n#endif\n#ifdef OJPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_OJPEG){\n\t\t\tif(! t2p->pdf_ojpegdata){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"No support for OJPEG image %s with "\n "bad tables",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tbuffer=(unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\t_TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength);\n\t\t\tif(edge!=0){\n\t\t\t\tif(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){\n\t\t\t\t\tbuffer[7]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength >> 8) & 0xff;\n\t\t\t\t\tbuffer[8]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength ) & 0xff;\n\t\t\t\t}\n\t\t\t\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){\n\t\t\t\t\tbuffer[9]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth >> 8) & 0xff;\n\t\t\t\t\tbuffer[10]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth ) & 0xff;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbufferoffset=t2p->pdf_ojpegdatalength;\n\t\t\tbufferoffset+=TIFFReadRawTile(input,\n\t\t\t\t\ttile,\n\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),\n\t\t\t\t\t-1);\n\t\t\t((unsigned char*)buffer)[bufferoffset++]=0xff;\n\t\t\t((unsigned char*)buffer)[bufferoffset++]=0xd9;\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, bufferoffset);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(bufferoffset);\n\t\t}\n#endif\n#ifdef JPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_JPEG){\n\t\t\tunsigned char table_end[2];\n\t\t\tuint32 count = 0;\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\tt2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) {\n\t\t\t\tif (count > 0) {\n\t\t\t\t\t_TIFFmemcpy(buffer, jpt, count);\n\t\t\t\t\tbufferoffset += count - 2;\n\t\t\t\t\ttable_end[0] = buffer[bufferoffset-2];\n\t\t\t\t\ttable_end[1] = buffer[bufferoffset-1];\n\t\t\t\t}\n\t\t\t\tif (count > 0) {\n\t\t\t\t\txuint32 = bufferoffset;\n\t\t\t\t\tbufferoffset += TIFFReadRawTile(\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset-2]),\n\t\t\t\t\t\t-1);\n\t\t\t\t\t\tbuffer[xuint32-2]=table_end[0];\n\t\t\t\t\t\tbuffer[xuint32-1]=table_end[1];\n\t\t\t\t} else {\n\t\t\t\t\tbufferoffset += TIFFReadRawTile(\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),\n\t\t\t\t\t\t-1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, bufferoffset);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(bufferoffset);\n\t\t}\n#endif\n\t\t(void)0;\n\t}\n\tif(t2p->pdf_sample==T2P_SAMPLE_NOTHING){\n\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\tif(buffer==NULL){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"Can\'t allocate %lu bytes of memory for "\n "t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\tTIFFFileName(input));\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t\tread = TIFFReadEncodedTile(\n\t\t\tinput,\n\t\t\ttile,\n\t\t\t(tdata_t) &buffer[bufferoffset],\n\t\t\tt2p->tiff_datasize);\n\t\tif(read==-1){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\ttile,\n\t\t\t\tTIFFFileName(input));\n\t\t\t_TIFFfree(buffer);\n\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t} else {\n\t\tif(t2p->pdf_sample == T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG){\n\t\t\tseptilesize=TIFFTileSize(input);\n\t\t\tseptilecount=TIFFNumberOfTiles(input);\n\t\t\ttilesize=septilesize*t2p->tiff_samplesperpixel;\n\t\t\ttilecount=septilecount/t2p->tiff_samplesperpixel;\n\t\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tsamplebuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(samplebuffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tsamplebufferoffset=0;\n\t\t\tfor(i=0;i<t2p->tiff_samplesperpixel;i++){\n\t\t\t\tread =\n\t\t\t\t\tTIFFReadEncodedTile(input,\n\t\t\t\t\t\ttile + i*tilecount,\n\t\t\t\t\t\t(tdata_t) &(samplebuffer[samplebufferoffset]),\n\t\t\t\t\t\tseptilesize);\n\t\t\t\tif(read==-1){\n\t\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\t\t\ttile + i*tilecount,\n\t\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\t\t_TIFFfree(samplebuffer);\n\t\t\t\t\t\t_TIFFfree(buffer);\n\t\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t\tsamplebufferoffset+=read;\n\t\t\t}\n\t\t\tt2p_sample_planar_separate_to_contig(\n\t\t\t\tt2p,\n\t\t\t\t&(buffer[bufferoffset]),\n\t\t\t\tsamplebuffer,\n\t\t\t\tsamplebufferoffset);\n\t\t\tbufferoffset+=samplebufferoffset;\n\t\t\t_TIFFfree(samplebuffer);\n\t\t}\n\t\tif(buffer==NULL){\n\t\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tread = TIFFReadEncodedTile(\n\t\t\t\tinput,\n\t\t\t\ttile,\n\t\t\t\t(tdata_t) &buffer[bufferoffset],\n\t\t\t\tt2p->tiff_datasize);\n\t\t\tif(read==-1){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\t\ttile,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t_TIFFfree(buffer);\n\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_RGBA_TO_RGB){\n\t\t\tt2p->tiff_datasize=t2p_sample_rgba_to_rgb(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_RGBAA_TO_RGB){\n\t\t\tt2p->tiff_datasize=t2p_sample_rgbaa_to_rgb(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_YCBCR_TO_RGB){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"No support for YCbCr to RGB in tile for %s",\n\t\t\t\tTIFFFileName(input));\n\t\t\t_TIFFfree(buffer);\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED){\n\t\t\tt2p->tiff_datasize=t2p_sample_lab_signed_to_unsigned(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t}\n\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile) != 0){\n\t\tt2p_tile_collapse_left(\n\t\t\tbuffer,\n\t\t\tTIFFTileRowSize(input),\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t}\n\tt2p_disable(output);\n\tTIFFSetField(output, TIFFTAG_PHOTOMETRIC, t2p->tiff_photometric);\n\tTIFFSetField(output, TIFFTAG_BITSPERSAMPLE, t2p->tiff_bitspersample);\n\tTIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, t2p->tiff_samplesperpixel);\n\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile) == 0){\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGEWIDTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth);\n\t} else {\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGEWIDTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth);\n\t}\n\tif(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile) == 0){\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGELENGTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_ROWSPERSTRIP,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t} else {\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGELENGTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_ROWSPERSTRIP,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);\n\t}\n\tTIFFSetField(output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);\n\tTIFFSetField(output, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);\n\tswitch(t2p->pdf_compression){\n\tcase T2P_COMPRESS_NONE:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_NONE);\n\t\tbreak;\n#ifdef CCITT_SUPPORT\n\tcase T2P_COMPRESS_G4:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);\n\t\tbreak;\n#endif\n#ifdef JPEG_SUPPORT\n\tcase T2P_COMPRESS_JPEG:\n\t\tif (t2p->tiff_photometric==PHOTOMETRIC_YCBCR) {\n\t\t\tuint16 hor = 0, ver = 0;\n\t\t\tif (TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &hor, &ver)!=0) {\n\t\t\t\tif (hor != 0 && ver != 0) {\n\t\t\t\t\tTIFFSetField(output, TIFFTAG_YCBCRSUBSAMPLING, hor, ver);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_REFERENCEBLACKWHITE, &xfloatp)!=0){\n\t\t\t\tTIFFSetField(output, TIFFTAG_REFERENCEBLACKWHITE, xfloatp);\n\t\t\t}\n\t\t}\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);\n\t\tTIFFSetField(output, TIFFTAG_JPEGTABLESMODE, 0);\n\t\tif(t2p->pdf_colorspace & (T2P_CS_RGB | T2P_CS_LAB)){\n\t\t\tTIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);\n\t\t\tif(t2p->tiff_photometric != PHOTOMETRIC_YCBCR){\n\t\t\t\tTIFFSetField(output, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);\n\t\t\t} else {\n\t\t\t\tTIFFSetField(output, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RAW);\n\t\t\t}\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_GRAY){\n\t\t\t(void)0;\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_CMYK){\n\t\t\t(void)0;\n\t\t}\n\t\tif(t2p->pdf_defaultcompressionquality != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_JPEGQUALITY,\n\t\t\t\tt2p->pdf_defaultcompressionquality);\n\t\t}\n\t\tbreak;\n#endif\n#ifdef ZIP_SUPPORT\n\tcase T2P_COMPRESS_ZIP:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);\n\t\tif(t2p->pdf_defaultcompressionquality%100 != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_PREDICTOR,\n\t\t\t\tt2p->pdf_defaultcompressionquality % 100);\n\t\t}\n\t\tif(t2p->pdf_defaultcompressionquality/100 != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_ZIPQUALITY,\n\t\t\t\t(t2p->pdf_defaultcompressionquality / 100));\n\t\t}\n\t\tbreak;\n#endif\n\tdefault:\n\t\tbreak;\n\t}\n\tt2p_enable(output);\n\tt2p->outputwritten = 0;\n\tbufferoffset = TIFFWriteEncodedStrip(output, (tstrip_t) 0, buffer,\n\t\t\t\t\t TIFFStripSize(output));\n\tif (buffer != NULL) {\n\t\t_TIFFfree(buffer);\n\t\tbuffer = NULL;\n\t}\n\tif (bufferoffset == -1) {\n\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t "Error writing encoded tile to output PDF %s",\n\t\t\t TIFFFileName(output));\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn(0);\n\t}\n\twritten = t2p->outputwritten;\n\treturn(written);\n}', 'tmsize_t\nTIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)\n{\n\tstatic const char module[] = "TIFFReadEncodedTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\ttmsize_t tilesize = tif->tif_tilesize;\n\tif (!TIFFCheckRead(tif, 1))\n\t\treturn ((tmsize_t)(-1));\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "%lu: Tile out of range, max %lu",\n\t\t (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n\tif (size == (tmsize_t)(-1))\n\t\tsize = tilesize;\n\telse if (size > tilesize)\n\t\tsize = tilesize;\n\tif (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,\n\t (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) {\n\t\t(*tif->tif_postdecode)(tif, (uint8*) buf, size);\n\t\treturn (size);\n\t} else\n\t\treturn ((tmsize_t)(-1));\n}', 'int\nTIFFFillTile(TIFF* tif, uint32 tile)\n{\n\tstatic const char module[] = "TIFFFillTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags&TIFF_NOREADRAW)==0)\n\t{\n\t\tuint64 bytecount = td->td_stripbytecount[tile];\n\t\tif (bytecount <= 0) {\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%I64u: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned __int64) bytecount,\n\t\t\t\t (unsigned long) tile);\n#else\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%llu: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned long long) bytecount,\n\t\t\t\t (unsigned long) tile);\n#endif\n\t\t\treturn (0);\n\t\t}\n\t\tif (isMapped(tif) &&\n\t\t (isFillOrder(tif, td->td_fillorder)\n\t\t || (tif->tif_flags & TIFF_NOBITREV))) {\n\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)\n\t\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\ttif->tif_flags &= ~TIFF_MYBUFFER;\n\t\t\tif (bytecount > (uint64)tif->tif_size ||\n\t\t\t td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\ttif->tif_rawdatasize = (tmsize_t)bytecount;\n\t\t\ttif->tif_rawdata =\n\t\t\t\ttif->tif_base + (tmsize_t)td->td_stripoffset[tile];\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = (tmsize_t) bytecount;\n\t\t} else {\n\t\t\ttmsize_t bytecountm;\n\t\t\tbytecountm=(tmsize_t)bytecount;\n\t\t\tif ((uint64)bytecountm!=bytecount)\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif (bytecountm > tif->tif_rawdatasize) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) == 0) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Data buffer too small to hold tile %lu",\n\t\t\t\t\t (unsigned long) tile);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (TIFFReadRawTile1(tif, tile, tif->tif_rawdata,\n\t\t\t bytecountm, module) != bytecountm)\n\t\t\t\treturn (0);\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = bytecountm;\n\t\t\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t\t\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\t\t\tTIFFReverseBits(tif->tif_rawdata,\n tif->tif_rawdataloaded);\n\t\t}\n\t}\n\treturn (TIFFStartTile(tif, tile));\n}', 'static int\nTIFFStartTile(TIFF* tif, uint32 tile)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupdecode)(tif))\n\t\t\treturn (0);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_curtile = tile;\n\ttif->tif_row =\n\t (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) *\n\t\ttd->td_tilelength;\n\ttif->tif_col =\n\t (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) *\n\t\ttd->td_tilewidth;\n tif->tif_flags &= ~TIFF_BUF4WRITE;\n\tif (tif->tif_flags&TIFF_NOREADRAW)\n\t{\n\t\ttif->tif_rawcp = NULL;\n\t\ttif->tif_rawcc = 0;\n\t}\n\telse\n\t{\n\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\ttif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];\n\t}\n\treturn ((*tif->tif_predecode)(tif,\n\t\t\t(uint16)(tile/td->td_stripsperimage)));\n}'] |
34,359 | 0 | https://github.com/openssl/openssl/blob/877e8e970c3c94c43ce1db50fdbb8e9b0342b90e/crypto/bn/bn_asm.c/#L189 | BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)
{
BN_ULONG carry=0;
BN_ULONG bl,bh;
assert(num >= 0);
if (num <= 0) return((BN_ULONG)0);
bl=LBITS(w);
bh=HBITS(w);
#ifndef OPENSSL_SMALL_FOOTPRINT
while (num&~3)
{
mul(rp[0],ap[0],bl,bh,carry);
mul(rp[1],ap[1],bl,bh,carry);
mul(rp[2],ap[2],bl,bh,carry);
mul(rp[3],ap[3],bl,bh,carry);
ap+=4; rp+=4; num-=4;
}
#endif
while (num)
{
mul(rp[0],ap[0],bl,bh,carry);
ap++; rp++; num--;
}
return(carry);
} | ['BN_ULONG bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w)\n\t{\n\tBN_ULONG carry=0;\n\tBN_ULONG bl,bh;\n\tassert(num >= 0);\n\tif (num <= 0) return((BN_ULONG)0);\n\tbl=LBITS(w);\n\tbh=HBITS(w);\n#ifndef OPENSSL_SMALL_FOOTPRINT\n\twhile (num&~3)\n\t\t{\n\t\tmul(rp[0],ap[0],bl,bh,carry);\n\t\tmul(rp[1],ap[1],bl,bh,carry);\n\t\tmul(rp[2],ap[2],bl,bh,carry);\n\t\tmul(rp[3],ap[3],bl,bh,carry);\n\t\tap+=4; rp+=4; num-=4;\n\t\t}\n#endif\n\twhile (num)\n\t\t{\n\t\tmul(rp[0],ap[0],bl,bh,carry);\n\t\tap++; rp++; num--;\n\t\t}\n\treturn(carry);\n\t}'] |
34,360 | 0 | https://github.com/libav/libav/blob/e5b0fc170f85b00f7dd0ac514918fb5c95253d39/libavcodec/bitstream.h/#L237 | static inline void skip_remaining(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
bc->bits >>= n;
#else
bc->bits <<= n;
#endif
bc->bits_left -= n;
} | ['static int read_argb_line(CLLCContext *ctx, BitstreamContext *bc, int *top_left,\n VLC *vlc, uint8_t *outbuf)\n{\n uint8_t *dst;\n int pred[4];\n int code;\n int i;\n dst = outbuf;\n pred[0] = top_left[0];\n pred[1] = top_left[1];\n pred[2] = top_left[2];\n pred[3] = top_left[3];\n for (i = 0; i < ctx->avctx->width; i++) {\n code = bitstream_read_vlc(bc, vlc[0].table, 7, 2);\n pred[0] += code;\n dst[0] = pred[0];\n if (dst[0]) {\n code = bitstream_read_vlc(bc, vlc[1].table, 7, 2);\n pred[1] += code;\n dst[1] = pred[1];\n code = bitstream_read_vlc(bc, vlc[2].table, 7, 2);\n pred[2] += code;\n dst[2] = pred[2];\n code = bitstream_read_vlc(bc, vlc[3].table, 7, 2);\n pred[3] += code;\n dst[3] = pred[3];\n } else {\n dst[1] = 0;\n dst[2] = 0;\n dst[3] = 0;\n }\n dst += 4;\n }\n top_left[0] = outbuf[0];\n if (top_left[0]) {\n top_left[1] = outbuf[1];\n top_left[2] = outbuf[2];\n top_left[3] = outbuf[3];\n }\n return 0;\n}', 'static inline int bitstream_read_vlc(BitstreamContext *bc, VLC_TYPE (*table)[2],\n int bits, int max_depth)\n{\n int nb_bits;\n unsigned idx = bitstream_peek(bc, bits);\n int code = table[idx][0];\n int n = table[idx][1];\n if (max_depth > 1 && n < 0) {\n skip_remaining(bc, bits);\n code = set_idx(bc, code, &n, &nb_bits, table);\n if (max_depth > 2 && n < 0) {\n skip_remaining(bc, nb_bits);\n code = set_idx(bc, code, &n, &nb_bits, table);\n }\n }\n skip_remaining(bc, n);\n return code;\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}'] |
34,361 | 0 | https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L139 | static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
bc->bits >>= n;
#else
uint64_t ret = bc->bits >> (64 - n);
bc->bits <<= n;
#endif
bc->bits_left -= n;
return ret;
} | ['static int synth_superframe(AVCodecContext *ctx, AVFrame *frame,\n int *got_frame_ptr)\n{\n WMAVoiceContext *s = ctx->priv_data;\n BitstreamContext *bc = &s->bc, s_bc;\n int n, res, n_samples = 480;\n double lsps[MAX_FRAMES][MAX_LSPS];\n const double *mean_lsf = s->lsps == 16 ?\n wmavoice_mean_lsf16[s->lsp_def_mode] : wmavoice_mean_lsf10[s->lsp_def_mode];\n float excitation[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE + 12];\n float synth[MAX_LSPS + MAX_SFRAMESIZE];\n float *samples;\n memcpy(synth, s->synth_history,\n s->lsps * sizeof(*synth));\n memcpy(excitation, s->excitation_history,\n s->history_nsamples * sizeof(*excitation));\n if (s->sframe_cache_size > 0) {\n bc = &s_bc;\n bitstream_init(bc, s->sframe_cache, s->sframe_cache_size);\n s->sframe_cache_size = 0;\n }\n if ((res = check_bits_for_superframe(bc, s)) == 1) {\n *got_frame_ptr = 0;\n return 1;\n } else if (res < 0)\n return res;\n if (!bitstream_read_bit(bc)) {\n avpriv_request_sample(ctx, "WMAPro-in-WMAVoice");\n return AVERROR_PATCHWELCOME;\n }\n if (bitstream_read_bit(bc)) {\n if ((n_samples = bitstream_read(bc, 12)) > 480) {\n av_log(ctx, AV_LOG_ERROR,\n "Superframe encodes >480 samples (%d), not allowed\\n",\n n_samples);\n return AVERROR_INVALIDDATA;\n }\n }\n if (s->has_residual_lsps) {\n double prev_lsps[MAX_LSPS], a1[MAX_LSPS * 2], a2[MAX_LSPS * 2];\n for (n = 0; n < s->lsps; n++)\n prev_lsps[n] = s->prev_lsps[n] - mean_lsf[n];\n if (s->lsps == 10) {\n dequant_lsp10r(bc, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);\n } else\n dequant_lsp16r(bc, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);\n for (n = 0; n < s->lsps; n++) {\n lsps[0][n] = mean_lsf[n] + (a1[n] - a2[n * 2]);\n lsps[1][n] = mean_lsf[n] + (a1[s->lsps + n] - a2[n * 2 + 1]);\n lsps[2][n] += mean_lsf[n];\n }\n for (n = 0; n < 3; n++)\n stabilize_lsps(lsps[n], s->lsps);\n }\n frame->nb_samples = 480;\n if ((res = ff_get_buffer(ctx, frame, 0)) < 0) {\n av_log(ctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return res;\n }\n frame->nb_samples = n_samples;\n samples = (float *)frame->data[0];\n for (n = 0; n < 3; n++) {\n if (!s->has_residual_lsps) {\n int m;\n if (s->lsps == 10) {\n dequant_lsp10i(bc, lsps[n]);\n } else\n dequant_lsp16i(bc, lsps[n]);\n for (m = 0; m < s->lsps; m++)\n lsps[n][m] += mean_lsf[m];\n stabilize_lsps(lsps[n], s->lsps);\n }\n if ((res = synth_frame(ctx, bc, n,\n &samples[n * MAX_FRAMESIZE],\n lsps[n], n == 0 ? s->prev_lsps : lsps[n - 1],\n &excitation[s->history_nsamples + n * MAX_FRAMESIZE],\n &synth[s->lsps + n * MAX_FRAMESIZE]))) {\n *got_frame_ptr = 0;\n return res;\n }\n }\n if (bitstream_read_bit(bc)) {\n res = bitstream_read(bc, 4);\n bitstream_skip(bc, 10 * (res + 1));\n }\n *got_frame_ptr = 1;\n memcpy(s->prev_lsps, lsps[2],\n s->lsps * sizeof(*s->prev_lsps));\n memcpy(s->synth_history, &synth[MAX_SFRAMESIZE],\n s->lsps * sizeof(*synth));\n memcpy(s->excitation_history, &excitation[MAX_SFRAMESIZE],\n s->history_nsamples * sizeof(*excitation));\n if (s->do_apf)\n memmove(s->zero_exc_pf, &s->zero_exc_pf[MAX_SFRAMESIZE],\n s->history_nsamples * sizeof(*s->zero_exc_pf));\n return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}'] |
34,362 | 0 | https://github.com/openssl/openssl/blob/4fcdd66fff5fea0cfa1055c6680a76a4303f28a2/crypto/x509/x509_vfy.c/#L1784 | static int internal_verify(X509_STORE_CTX *ctx)
{
int ok=0,n;
X509 *xs,*xi;
EVP_PKEY *pkey=NULL;
int (*cb)(int xok,X509_STORE_CTX *xctx);
cb=ctx->verify_cb;
n=sk_X509_num(ctx->chain);
ctx->error_depth=n-1;
n--;
xi=sk_X509_value(ctx->chain,n);
if (ctx->check_issued(ctx, xi, xi))
xs=xi;
else
{
if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN && n == 0)
{
xs = xi;
goto check_cert;
}
if (n <= 0)
{
ctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
ctx->current_cert=xi;
ok=cb(0,ctx);
goto end;
}
else
{
n--;
ctx->error_depth=n;
xs=sk_X509_value(ctx->chain,n);
}
}
while (n >= 0)
{
ctx->error_depth=n;
if (!xs->valid && (xs != xi || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE)))
{
if ((pkey=X509_get_pubkey(xi)) == NULL)
{
ctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
ctx->current_cert=xi;
ok=(*cb)(0,ctx);
if (!ok) goto end;
}
else if (X509_verify(xs,pkey) <= 0)
{
ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;
ctx->current_cert=xs;
ok=(*cb)(0,ctx);
if (!ok)
{
EVP_PKEY_free(pkey);
goto end;
}
}
EVP_PKEY_free(pkey);
pkey=NULL;
}
xs->valid = 1;
check_cert:
ok = check_cert_time(ctx, xs);
if (!ok)
goto end;
ctx->current_issuer=xi;
ctx->current_cert=xs;
ok=(*cb)(1,ctx);
if (!ok) goto end;
n--;
if (n >= 0)
{
xi=xs;
xs=sk_X509_value(ctx->chain,n);
}
}
ok=1;
end:
return ok;
} | ['static int internal_verify(X509_STORE_CTX *ctx)\n\t{\n\tint ok=0,n;\n\tX509 *xs,*xi;\n\tEVP_PKEY *pkey=NULL;\n\tint (*cb)(int xok,X509_STORE_CTX *xctx);\n\tcb=ctx->verify_cb;\n\tn=sk_X509_num(ctx->chain);\n\tctx->error_depth=n-1;\n\tn--;\n\txi=sk_X509_value(ctx->chain,n);\n\tif (ctx->check_issued(ctx, xi, xi))\n\t\txs=xi;\n\telse\n\t\t{\n\t\tif (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN && n == 0)\n\t\t\t{\n\t\t\txs = xi;\n\t\t\tgoto check_cert;\n\t\t\t}\n\t\tif (n <= 0)\n\t\t\t{\n\t\t\tctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;\n\t\t\tctx->current_cert=xi;\n\t\t\tok=cb(0,ctx);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tn--;\n\t\t\tctx->error_depth=n;\n\t\t\txs=sk_X509_value(ctx->chain,n);\n\t\t\t}\n\t\t}\n\twhile (n >= 0)\n\t\t{\n\t\tctx->error_depth=n;\n\t\tif (!xs->valid && (xs != xi || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE)))\n\t\t\t{\n\t\t\tif ((pkey=X509_get_pubkey(xi)) == NULL)\n\t\t\t\t{\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;\n\t\t\t\tctx->current_cert=xi;\n\t\t\t\tok=(*cb)(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\telse if (X509_verify(xs,pkey) <= 0)\n\t\t\t\t{\n\t\t\t\tctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;\n\t\t\t\tctx->current_cert=xs;\n\t\t\t\tok=(*cb)(0,ctx);\n\t\t\t\tif (!ok)\n\t\t\t\t\t{\n\t\t\t\t\tEVP_PKEY_free(pkey);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tEVP_PKEY_free(pkey);\n\t\t\tpkey=NULL;\n\t\t\t}\n\t\txs->valid = 1;\n\t\tcheck_cert:\n\t\tok = check_cert_time(ctx, xs);\n\t\tif (!ok)\n\t\t\tgoto end;\n\t\tctx->current_issuer=xi;\n\t\tctx->current_cert=xs;\n\t\tok=(*cb)(1,ctx);\n\t\tif (!ok) goto end;\n\t\tn--;\n\t\tif (n >= 0)\n\t\t\t{\n\t\t\txi=xs;\n\t\t\txs=sk_X509_value(ctx->chain,n);\n\t\t\t}\n\t\t}\n\tok=1;\nend:\n\treturn ok;\n\t}', 'int sk_num(const _STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}', 'void *sk_value(const _STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}'] |
34,363 | 0 | https://github.com/openssl/openssl/blob/280eb33b5930efef9a3dfdeab5c3df46a9425243/crypto/x509/x509_vpm.c/#L91 | X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void)
{
X509_VERIFY_PARAM *param;
param = OPENSSL_malloc(sizeof(X509_VERIFY_PARAM));
memset(param, 0, sizeof(X509_VERIFY_PARAM));
x509_verify_param_zero(param);
return param;
} | ['X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void)\n\t{\n\tX509_VERIFY_PARAM *param;\n\tparam = OPENSSL_malloc(sizeof(X509_VERIFY_PARAM));\n\tmemset(param, 0, sizeof(X509_VERIFY_PARAM));\n\tx509_verify_param_zero(param);\n\treturn param;\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}'] |
34,364 | 0 | https://github.com/openssl/openssl/blob/e3713c365c2657236439fea00822a43aa396d112/crypto/init.c/#L402 | int ossl_init_thread_start(uint64_t opts)
{
struct thread_local_inits_st *locals;
if (!OPENSSL_init_crypto(0, NULL))
return 0;
locals = ossl_init_get_thread_local(1);
if (locals == NULL)
return 0;
if (opts & OPENSSL_INIT_THREAD_ASYNC) {
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
"marking thread for async\n");
#endif
locals->async = 1;
}
if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
"marking thread for err_state\n");
#endif
locals->err_state = 1;
}
return 1;
} | ['int ossl_init_thread_start(uint64_t opts)\n{\n struct thread_local_inits_st *locals;\n if (!OPENSSL_init_crypto(0, NULL))\n return 0;\n locals = ossl_init_get_thread_local(1);\n if (locals == NULL)\n return 0;\n if (opts & OPENSSL_INIT_THREAD_ASYNC) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for async\\n");\n#endif\n locals->async = 1;\n }\n if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for err_state\\n");\n#endif\n locals->err_state = 1;\n }\n return 1;\n}', 'static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)\n{\n struct thread_local_inits_st *local =\n CRYPTO_THREAD_get_local(&threadstopkey);\n if (local == NULL && alloc) {\n local = OPENSSL_zalloc(sizeof *local);\n if (local != NULL && !CRYPTO_THREAD_set_local(&threadstopkey, local)) {\n OPENSSL_free(local);\n return NULL;\n }\n }\n if (!alloc) {\n CRYPTO_THREAD_set_local(&threadstopkey, NULL);\n }\n return local;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)\n{\n if (pthread_setspecific(*key, val) != 0)\n return 0;\n return 1;\n}'] |
34,365 | 0 | https://github.com/libav/libav/blob/dc26318c2dd05893843147d8c5b169bd2f498c61/ffmpeg.c/#L3077 | static int opt_input_ts_scale(const char *opt, const char *arg)
{
unsigned int stream;
double scale;
char *p;
stream = strtol(arg, &p, 0);
if (*p)
p++;
scale= strtod(p, &p);
ts_scale = grow_array(ts_scale, sizeof(*ts_scale), &nb_ts_scale, stream + 1);
ts_scale[stream] = scale;
return 0;
} | ['static int opt_input_ts_scale(const char *opt, const char *arg)\n{\n unsigned int stream;\n double scale;\n char *p;\n stream = strtol(arg, &p, 0);\n if (*p)\n p++;\n scale= strtod(p, &p);\n ts_scale = grow_array(ts_scale, sizeof(*ts_scale), &nb_ts_scale, stream + 1);\n ts_scale[stream] = scale;\n return 0;\n}', 'void *grow_array(void *array, int elem_size, int *size, int new_size)\n{\n if (new_size >= INT_MAX / elem_size) {\n av_log(NULL, AV_LOG_ERROR, "Array too big.\\n");\n exit_program(1);\n }\n if (*size < new_size) {\n uint8_t *tmp = av_realloc(array, new_size*elem_size);\n if (!tmp) {\n av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\\n");\n exit_program(1);\n }\n memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);\n *size = new_size;\n return tmp;\n }\n return array;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if(!ptr) return av_malloc(size);\n diff= ((char*)ptr)[-1];\n return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#else\n return realloc(ptr, size);\n#endif\n}'] |
34,366 | 0 | https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/wmadec.c/#L641 | static int wma_decode_block(WMACodecContext *s)
{
int n, v, a, ch, code, bsize;
int coef_nb_bits, total_gain;
int nb_coefs[MAX_CHANNELS];
float mdct_norm;
#ifdef TRACE
tprintf(s->avctx, "***decode_block: %d:%d\n", s->frame_count - 1, s->block_num);
#endif
if (s->use_variable_block_len) {
n = av_log2(s->nb_block_sizes - 1) + 1;
if (s->reset_block_lengths) {
s->reset_block_lengths = 0;
v = get_bits(&s->gb, n);
if (v >= s->nb_block_sizes)
return -1;
s->prev_block_len_bits = s->frame_len_bits - v;
v = get_bits(&s->gb, n);
if (v >= s->nb_block_sizes)
return -1;
s->block_len_bits = s->frame_len_bits - v;
} else {
s->prev_block_len_bits = s->block_len_bits;
s->block_len_bits = s->next_block_len_bits;
}
v = get_bits(&s->gb, n);
if (v >= s->nb_block_sizes)
return -1;
s->next_block_len_bits = s->frame_len_bits - v;
} else {
s->next_block_len_bits = s->frame_len_bits;
s->prev_block_len_bits = s->frame_len_bits;
s->block_len_bits = s->frame_len_bits;
}
s->block_len = 1 << s->block_len_bits;
if ((s->block_pos + s->block_len) > s->frame_len)
return -1;
if (s->nb_channels == 2) {
s->ms_stereo = get_bits1(&s->gb);
}
v = 0;
for(ch = 0; ch < s->nb_channels; ch++) {
a = get_bits1(&s->gb);
s->channel_coded[ch] = a;
v |= a;
}
if (!v)
goto next;
bsize = s->frame_len_bits - s->block_len_bits;
total_gain = 1;
for(;;) {
a = get_bits(&s->gb, 7);
total_gain += a;
if (a != 127)
break;
}
coef_nb_bits= ff_wma_total_gain_to_bits(total_gain);
n = s->coefs_end[bsize] - s->coefs_start;
for(ch = 0; ch < s->nb_channels; ch++)
nb_coefs[ch] = n;
if (s->use_noise_coding) {
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
int i, n, a;
n = s->exponent_high_sizes[bsize];
for(i=0;i<n;i++) {
a = get_bits1(&s->gb);
s->high_band_coded[ch][i] = a;
if (a)
nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
}
}
}
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
int i, n, val, code;
n = s->exponent_high_sizes[bsize];
val = (int)0x80000000;
for(i=0;i<n;i++) {
if (s->high_band_coded[ch][i]) {
if (val == (int)0x80000000) {
val = get_bits(&s->gb, 7) - 19;
} else {
code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);
if (code < 0)
return -1;
val += code - 18;
}
s->high_band_values[ch][i] = val;
}
}
}
}
}
if ((s->block_len_bits == s->frame_len_bits) ||
get_bits1(&s->gb)) {
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
if (s->use_exp_vlc) {
if (decode_exp_vlc(s, ch) < 0)
return -1;
} else {
decode_exp_lsp(s, ch);
}
s->exponents_bsize[ch] = bsize;
}
}
}
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
VLC *coef_vlc;
int level, run, sign, tindex;
int16_t *ptr, *eptr;
const uint16_t *level_table, *run_table;
tindex = (ch == 1 && s->ms_stereo);
coef_vlc = &s->coef_vlc[tindex];
run_table = s->run_table[tindex];
level_table = s->level_table[tindex];
ptr = &s->coefs1[ch][0];
eptr = ptr + nb_coefs[ch];
memset(ptr, 0, s->block_len * sizeof(int16_t));
for(;;) {
code = get_vlc2(&s->gb, coef_vlc->table, VLCBITS, VLCMAX);
if (code < 0)
return -1;
if (code == 1) {
break;
} else if (code == 0) {
level = get_bits(&s->gb, coef_nb_bits);
run = get_bits(&s->gb, s->frame_len_bits);
} else {
run = run_table[code];
level = level_table[code];
}
sign = get_bits1(&s->gb);
if (!sign)
level = -level;
ptr += run;
if (ptr >= eptr)
{
av_log(NULL, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\n");
break;
}
*ptr++ = level;
if (ptr >= eptr)
break;
}
}
if (s->version == 1 && s->nb_channels >= 2) {
align_get_bits(&s->gb);
}
}
{
int n4 = s->block_len / 2;
mdct_norm = 1.0 / (float)n4;
if (s->version == 1) {
mdct_norm *= sqrt(n4);
}
}
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
int16_t *coefs1;
float *coefs, *exponents, mult, mult1, noise;
int i, j, n, n1, last_high_band, esize;
float exp_power[HIGH_BAND_MAX_SIZE];
coefs1 = s->coefs1[ch];
exponents = s->exponents[ch];
esize = s->exponents_bsize[ch];
mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];
mult *= mdct_norm;
coefs = s->coefs[ch];
if (s->use_noise_coding) {
mult1 = mult;
for(i = 0;i < s->coefs_start; i++) {
*coefs++ = s->noise_table[s->noise_index] *
exponents[i<<bsize>>esize] * mult1;
s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
}
n1 = s->exponent_high_sizes[bsize];
exponents = s->exponents[ch] +
(s->high_band_start[bsize]<<bsize);
last_high_band = 0;
for(j=0;j<n1;j++) {
n = s->exponent_high_bands[s->frame_len_bits -
s->block_len_bits][j];
if (s->high_band_coded[ch][j]) {
float e2, v;
e2 = 0;
for(i = 0;i < n; i++) {
v = exponents[i<<bsize>>esize];
e2 += v * v;
}
exp_power[j] = e2 / n;
last_high_band = j;
tprintf(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n);
}
exponents += n<<bsize;
}
exponents = s->exponents[ch] + (s->coefs_start<<bsize);
for(j=-1;j<n1;j++) {
if (j < 0) {
n = s->high_band_start[bsize] -
s->coefs_start;
} else {
n = s->exponent_high_bands[s->frame_len_bits -
s->block_len_bits][j];
}
if (j >= 0 && s->high_band_coded[ch][j]) {
mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05);
mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);
mult1 *= mdct_norm;
for(i = 0;i < n; i++) {
noise = s->noise_table[s->noise_index];
s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
*coefs++ = noise *
exponents[i<<bsize>>esize] * mult1;
}
exponents += n<<bsize;
} else {
for(i = 0;i < n; i++) {
noise = s->noise_table[s->noise_index];
s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
*coefs++ = ((*coefs1++) + noise) *
exponents[i<<bsize>>esize] * mult;
}
exponents += n<<bsize;
}
}
n = s->block_len - s->coefs_end[bsize];
mult1 = mult * exponents[((-1<<bsize))>>esize];
for(i = 0; i < n; i++) {
*coefs++ = s->noise_table[s->noise_index] * mult1;
s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
}
} else {
for(i = 0;i < s->coefs_start; i++)
*coefs++ = 0.0;
n = nb_coefs[ch];
for(i = 0;i < n; i++) {
*coefs++ = coefs1[i] * exponents[i<<bsize>>esize] * mult;
}
n = s->block_len - s->coefs_end[bsize];
for(i = 0;i < n; i++)
*coefs++ = 0.0;
}
}
}
#ifdef TRACE
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len);
dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);
}
}
#endif
if (s->ms_stereo && s->channel_coded[1]) {
float a, b;
int i;
if (!s->channel_coded[0]) {
tprintf(s->avctx, "rare ms-stereo case happened\n");
memset(s->coefs[0], 0, sizeof(float) * s->block_len);
s->channel_coded[0] = 1;
}
for(i = 0; i < s->block_len; i++) {
a = s->coefs[0][i];
b = s->coefs[1][i];
s->coefs[0][i] = a + b;
s->coefs[1][i] = a - b;
}
}
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
int n4, index, n;
n = s->block_len;
n4 = s->block_len / 2;
s->mdct_ctx[bsize].fft.imdct_calc(&s->mdct_ctx[bsize],
s->output, s->coefs[ch], s->mdct_tmp);
index = (s->frame_len / 2) + s->block_pos - n4;
wma_window(s, &s->frame_out[ch][index]);
if (s->ms_stereo && !s->channel_coded[1]) {
wma_window(s, &s->frame_out[1][index]);
}
}
}
next:
s->block_num++;
s->block_pos += s->block_len;
if (s->block_pos >= s->frame_len)
return 1;
else
return 0;
} | ['static int wma_decode_block(WMACodecContext *s)\n{\n int n, v, a, ch, code, bsize;\n int coef_nb_bits, total_gain;\n int nb_coefs[MAX_CHANNELS];\n float mdct_norm;\n#ifdef TRACE\n tprintf(s->avctx, "***decode_block: %d:%d\\n", s->frame_count - 1, s->block_num);\n#endif\n if (s->use_variable_block_len) {\n n = av_log2(s->nb_block_sizes - 1) + 1;\n if (s->reset_block_lengths) {\n s->reset_block_lengths = 0;\n v = get_bits(&s->gb, n);\n if (v >= s->nb_block_sizes)\n return -1;\n s->prev_block_len_bits = s->frame_len_bits - v;\n v = get_bits(&s->gb, n);\n if (v >= s->nb_block_sizes)\n return -1;\n s->block_len_bits = s->frame_len_bits - v;\n } else {\n s->prev_block_len_bits = s->block_len_bits;\n s->block_len_bits = s->next_block_len_bits;\n }\n v = get_bits(&s->gb, n);\n if (v >= s->nb_block_sizes)\n return -1;\n s->next_block_len_bits = s->frame_len_bits - v;\n } else {\n s->next_block_len_bits = s->frame_len_bits;\n s->prev_block_len_bits = s->frame_len_bits;\n s->block_len_bits = s->frame_len_bits;\n }\n s->block_len = 1 << s->block_len_bits;\n if ((s->block_pos + s->block_len) > s->frame_len)\n return -1;\n if (s->nb_channels == 2) {\n s->ms_stereo = get_bits1(&s->gb);\n }\n v = 0;\n for(ch = 0; ch < s->nb_channels; ch++) {\n a = get_bits1(&s->gb);\n s->channel_coded[ch] = a;\n v |= a;\n }\n if (!v)\n goto next;\n bsize = s->frame_len_bits - s->block_len_bits;\n total_gain = 1;\n for(;;) {\n a = get_bits(&s->gb, 7);\n total_gain += a;\n if (a != 127)\n break;\n }\n coef_nb_bits= ff_wma_total_gain_to_bits(total_gain);\n n = s->coefs_end[bsize] - s->coefs_start;\n for(ch = 0; ch < s->nb_channels; ch++)\n nb_coefs[ch] = n;\n if (s->use_noise_coding) {\n for(ch = 0; ch < s->nb_channels; ch++) {\n if (s->channel_coded[ch]) {\n int i, n, a;\n n = s->exponent_high_sizes[bsize];\n for(i=0;i<n;i++) {\n a = get_bits1(&s->gb);\n s->high_band_coded[ch][i] = a;\n if (a)\n nb_coefs[ch] -= s->exponent_high_bands[bsize][i];\n }\n }\n }\n for(ch = 0; ch < s->nb_channels; ch++) {\n if (s->channel_coded[ch]) {\n int i, n, val, code;\n n = s->exponent_high_sizes[bsize];\n val = (int)0x80000000;\n for(i=0;i<n;i++) {\n if (s->high_band_coded[ch][i]) {\n if (val == (int)0x80000000) {\n val = get_bits(&s->gb, 7) - 19;\n } else {\n code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);\n if (code < 0)\n return -1;\n val += code - 18;\n }\n s->high_band_values[ch][i] = val;\n }\n }\n }\n }\n }\n if ((s->block_len_bits == s->frame_len_bits) ||\n get_bits1(&s->gb)) {\n for(ch = 0; ch < s->nb_channels; ch++) {\n if (s->channel_coded[ch]) {\n if (s->use_exp_vlc) {\n if (decode_exp_vlc(s, ch) < 0)\n return -1;\n } else {\n decode_exp_lsp(s, ch);\n }\n s->exponents_bsize[ch] = bsize;\n }\n }\n }\n for(ch = 0; ch < s->nb_channels; ch++) {\n if (s->channel_coded[ch]) {\n VLC *coef_vlc;\n int level, run, sign, tindex;\n int16_t *ptr, *eptr;\n const uint16_t *level_table, *run_table;\n tindex = (ch == 1 && s->ms_stereo);\n coef_vlc = &s->coef_vlc[tindex];\n run_table = s->run_table[tindex];\n level_table = s->level_table[tindex];\n ptr = &s->coefs1[ch][0];\n eptr = ptr + nb_coefs[ch];\n memset(ptr, 0, s->block_len * sizeof(int16_t));\n for(;;) {\n code = get_vlc2(&s->gb, coef_vlc->table, VLCBITS, VLCMAX);\n if (code < 0)\n return -1;\n if (code == 1) {\n break;\n } else if (code == 0) {\n level = get_bits(&s->gb, coef_nb_bits);\n run = get_bits(&s->gb, s->frame_len_bits);\n } else {\n run = run_table[code];\n level = level_table[code];\n }\n sign = get_bits1(&s->gb);\n if (!sign)\n level = -level;\n ptr += run;\n if (ptr >= eptr)\n {\n av_log(NULL, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\\n");\n break;\n }\n *ptr++ = level;\n if (ptr >= eptr)\n break;\n }\n }\n if (s->version == 1 && s->nb_channels >= 2) {\n align_get_bits(&s->gb);\n }\n }\n {\n int n4 = s->block_len / 2;\n mdct_norm = 1.0 / (float)n4;\n if (s->version == 1) {\n mdct_norm *= sqrt(n4);\n }\n }\n for(ch = 0; ch < s->nb_channels; ch++) {\n if (s->channel_coded[ch]) {\n int16_t *coefs1;\n float *coefs, *exponents, mult, mult1, noise;\n int i, j, n, n1, last_high_band, esize;\n float exp_power[HIGH_BAND_MAX_SIZE];\n coefs1 = s->coefs1[ch];\n exponents = s->exponents[ch];\n esize = s->exponents_bsize[ch];\n mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];\n mult *= mdct_norm;\n coefs = s->coefs[ch];\n if (s->use_noise_coding) {\n mult1 = mult;\n for(i = 0;i < s->coefs_start; i++) {\n *coefs++ = s->noise_table[s->noise_index] *\n exponents[i<<bsize>>esize] * mult1;\n s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);\n }\n n1 = s->exponent_high_sizes[bsize];\n exponents = s->exponents[ch] +\n (s->high_band_start[bsize]<<bsize);\n last_high_band = 0;\n for(j=0;j<n1;j++) {\n n = s->exponent_high_bands[s->frame_len_bits -\n s->block_len_bits][j];\n if (s->high_band_coded[ch][j]) {\n float e2, v;\n e2 = 0;\n for(i = 0;i < n; i++) {\n v = exponents[i<<bsize>>esize];\n e2 += v * v;\n }\n exp_power[j] = e2 / n;\n last_high_band = j;\n tprintf(s->avctx, "%d: power=%f (%d)\\n", j, exp_power[j], n);\n }\n exponents += n<<bsize;\n }\n exponents = s->exponents[ch] + (s->coefs_start<<bsize);\n for(j=-1;j<n1;j++) {\n if (j < 0) {\n n = s->high_band_start[bsize] -\n s->coefs_start;\n } else {\n n = s->exponent_high_bands[s->frame_len_bits -\n s->block_len_bits][j];\n }\n if (j >= 0 && s->high_band_coded[ch][j]) {\n mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);\n mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05);\n mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);\n mult1 *= mdct_norm;\n for(i = 0;i < n; i++) {\n noise = s->noise_table[s->noise_index];\n s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);\n *coefs++ = noise *\n exponents[i<<bsize>>esize] * mult1;\n }\n exponents += n<<bsize;\n } else {\n for(i = 0;i < n; i++) {\n noise = s->noise_table[s->noise_index];\n s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);\n *coefs++ = ((*coefs1++) + noise) *\n exponents[i<<bsize>>esize] * mult;\n }\n exponents += n<<bsize;\n }\n }\n n = s->block_len - s->coefs_end[bsize];\n mult1 = mult * exponents[((-1<<bsize))>>esize];\n for(i = 0; i < n; i++) {\n *coefs++ = s->noise_table[s->noise_index] * mult1;\n s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);\n }\n } else {\n for(i = 0;i < s->coefs_start; i++)\n *coefs++ = 0.0;\n n = nb_coefs[ch];\n for(i = 0;i < n; i++) {\n *coefs++ = coefs1[i] * exponents[i<<bsize>>esize] * mult;\n }\n n = s->block_len - s->coefs_end[bsize];\n for(i = 0;i < n; i++)\n *coefs++ = 0.0;\n }\n }\n }\n#ifdef TRACE\n for(ch = 0; ch < s->nb_channels; ch++) {\n if (s->channel_coded[ch]) {\n dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len);\n dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);\n }\n }\n#endif\n if (s->ms_stereo && s->channel_coded[1]) {\n float a, b;\n int i;\n if (!s->channel_coded[0]) {\n tprintf(s->avctx, "rare ms-stereo case happened\\n");\n memset(s->coefs[0], 0, sizeof(float) * s->block_len);\n s->channel_coded[0] = 1;\n }\n for(i = 0; i < s->block_len; i++) {\n a = s->coefs[0][i];\n b = s->coefs[1][i];\n s->coefs[0][i] = a + b;\n s->coefs[1][i] = a - b;\n }\n }\n for(ch = 0; ch < s->nb_channels; ch++) {\n if (s->channel_coded[ch]) {\n int n4, index, n;\n n = s->block_len;\n n4 = s->block_len / 2;\n s->mdct_ctx[bsize].fft.imdct_calc(&s->mdct_ctx[bsize],\n s->output, s->coefs[ch], s->mdct_tmp);\n index = (s->frame_len / 2) + s->block_pos - n4;\n wma_window(s, &s->frame_out[ch][index]);\n if (s->ms_stereo && !s->channel_coded[1]) {\n wma_window(s, &s->frame_out[1][index]);\n }\n }\n }\n next:\n s->block_num++;\n s->block_pos += s->block_len;\n if (s->block_pos >= s->frame_len)\n return 1;\n else\n return 0;\n}'] |
34,367 | 0 | https://github.com/libav/libav/blob/fd7f59639c43f0ab6b83ad2c1ceccafc553d7845/libavcodec/flashsvenc.c/#L148 | static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf, int buf_size,
int block_width, int block_height, uint8_t *previous_frame, int* I_frame) {
PutBitContext pb;
int h_blocks, v_blocks, h_part, v_part, i, j;
int buf_pos, res;
int pred_blocks = 0;
init_put_bits(&pb, buf, buf_size*8);
put_bits(&pb, 4, (block_width/16)-1);
put_bits(&pb, 12, s->image_width);
put_bits(&pb, 4, (block_height/16)-1);
put_bits(&pb, 12, s->image_height);
flush_put_bits(&pb);
buf_pos=4;
h_blocks = s->image_width / block_width;
h_part = s->image_width % block_width;
v_blocks = s->image_height / block_height;
v_part = s->image_height % block_height;
for (j = 0; j < v_blocks + (v_part?1:0); j++)
{
int hp = j*block_height;
int hs = (j<v_blocks)?block_height:v_part;
for (i = 0; i < h_blocks + (h_part?1:0); i++)
{
int wp = i*block_width;
int ws = (i<h_blocks)?block_width:h_part;
int ret=Z_OK;
uint8_t *ptr;
ptr = buf+buf_pos;
res = copy_region_enc(p->data[0], s->tmpblock, s->image_height-(hp+hs+1), wp, hs, ws, p->linesize[0], previous_frame);
if (res || *I_frame) {
unsigned long zsize;
zsize = 3*block_width*block_height;
ret = compress2(ptr+2, &zsize, s->tmpblock, 3*ws*hs, 9);
if (ret != Z_OK)
av_log(s->avctx, AV_LOG_ERROR, "error while compressing block %dx%d\n", i, j);
bytestream_put_be16(&ptr,(unsigned int)zsize);
buf_pos += zsize+2;
} else {
pred_blocks++;
bytestream_put_be16(&ptr,0);
buf_pos += 2;
}
}
}
if (pred_blocks)
*I_frame = 0;
else
*I_frame = 1;
return buf_pos;
} | ['static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf, int buf_size,\n int block_width, int block_height, uint8_t *previous_frame, int* I_frame) {\n PutBitContext pb;\n int h_blocks, v_blocks, h_part, v_part, i, j;\n int buf_pos, res;\n int pred_blocks = 0;\n init_put_bits(&pb, buf, buf_size*8);\n put_bits(&pb, 4, (block_width/16)-1);\n put_bits(&pb, 12, s->image_width);\n put_bits(&pb, 4, (block_height/16)-1);\n put_bits(&pb, 12, s->image_height);\n flush_put_bits(&pb);\n buf_pos=4;\n h_blocks = s->image_width / block_width;\n h_part = s->image_width % block_width;\n v_blocks = s->image_height / block_height;\n v_part = s->image_height % block_height;\n for (j = 0; j < v_blocks + (v_part?1:0); j++)\n {\n int hp = j*block_height;\n int hs = (j<v_blocks)?block_height:v_part;\n for (i = 0; i < h_blocks + (h_part?1:0); i++)\n {\n int wp = i*block_width;\n int ws = (i<h_blocks)?block_width:h_part;\n int ret=Z_OK;\n uint8_t *ptr;\n ptr = buf+buf_pos;\n res = copy_region_enc(p->data[0], s->tmpblock, s->image_height-(hp+hs+1), wp, hs, ws, p->linesize[0], previous_frame);\n if (res || *I_frame) {\n unsigned long zsize;\n zsize = 3*block_width*block_height;\n ret = compress2(ptr+2, &zsize, s->tmpblock, 3*ws*hs, 9);\n if (ret != Z_OK)\n av_log(s->avctx, AV_LOG_ERROR, "error while compressing block %dx%d\\n", i, j);\n bytestream_put_be16(&ptr,(unsigned int)zsize);\n buf_pos += zsize+2;\n } else {\n pred_blocks++;\n bytestream_put_be16(&ptr,0);\n buf_pos += 2;\n }\n }\n }\n if (pred_blocks)\n *I_frame = 0;\n else\n *I_frame = 1;\n return buf_pos;\n}', 'static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)\n{\n if(buffer_size < 0) {\n buffer_size = 0;\n buffer = NULL;\n }\n s->buf = buffer;\n s->buf_end = s->buf + buffer_size;\n#ifdef ALT_BITSTREAM_WRITER\n s->index=0;\n ((uint32_t*)(s->buf))[0]=0;\n#else\n s->buf_ptr = s->buf;\n s->bit_left=32;\n s->bit_buf=0;\n#endif\n}', 'static inline void put_bits(PutBitContext *s, int n, unsigned int value)\n{\n unsigned int bit_buf;\n int bit_left;\n assert(n == 32 || value < (1U << n));\n bit_buf = s->bit_buf;\n bit_left = s->bit_left;\n#ifdef BITSTREAM_WRITER_LE\n bit_buf |= value << (32 - bit_left);\n if (n >= bit_left) {\n#ifndef HAVE_FAST_UNALIGNED\n if (3 & (intptr_t) s->buf_ptr) {\n s->buf_ptr[0] = bit_buf ;\n s->buf_ptr[1] = bit_buf >> 8;\n s->buf_ptr[2] = bit_buf >> 16;\n s->buf_ptr[3] = bit_buf >> 24;\n } else\n#endif\n *(uint32_t *)s->buf_ptr = le2me_32(bit_buf);\n s->buf_ptr+=4;\n bit_buf = (bit_left==32)?0:value >> bit_left;\n bit_left+=32;\n }\n bit_left-=n;\n#else\n if (n < bit_left) {\n bit_buf = (bit_buf<<n) | value;\n bit_left-=n;\n } else {\n bit_buf<<=bit_left;\n bit_buf |= value >> (n - bit_left);\n#ifndef HAVE_FAST_UNALIGNED\n if (3 & (intptr_t) s->buf_ptr) {\n s->buf_ptr[0] = bit_buf >> 24;\n s->buf_ptr[1] = bit_buf >> 16;\n s->buf_ptr[2] = bit_buf >> 8;\n s->buf_ptr[3] = bit_buf ;\n } else\n#endif\n *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);\n s->buf_ptr+=4;\n bit_left+=32 - n;\n bit_buf = value;\n }\n#endif\n s->bit_buf = bit_buf;\n s->bit_left = bit_left;\n}', 'static av_always_inline av_const uint32_t bswap_32(uint32_t x)\n{\n x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);\n x= (x>>16) | (x<<16);\n return x;\n}'] |
34,368 | 0 | https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L684 | int BN_set_bit(BIGNUM *a, int n)
{
int i, j, k;
if (n < 0)
return 0;
i = n / BN_BITS2;
j = n % BN_BITS2;
if (a->top <= i) {
if (bn_wexpand(a, i + 1) == NULL)
return (0);
for (k = a->top; k < i + 1; k++)
a->d[k] = 0;
a->top = i + 1;
}
a->d[i] |= (((BN_ULONG)1) << j);
bn_check_top(a);
return (1);
} | ['EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)\n{\n EC_KEY *ret = NULL;\n EC_PRIVATEKEY *priv_key = NULL;\n const unsigned char *p = *in;\n if ((priv_key = d2i_EC_PRIVATEKEY(NULL, &p, len)) == NULL) {\n ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);\n return NULL;\n }\n if (a == NULL || *a == NULL) {\n if ((ret = EC_KEY_new()) == NULL) {\n ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n } else\n ret = *a;\n if (priv_key->parameters) {\n EC_GROUP_clear_free(ret->group);\n ret->group = ec_asn1_pkparameters2group(priv_key->parameters);\n }\n if (ret->group == NULL) {\n ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);\n goto err;\n }\n ret->version = priv_key->version;\n if (priv_key->privateKey) {\n if (ret->priv_key == NULL)\n ret->priv_key = BN_secure_new();\n if (ret->priv_key == NULL) {\n ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n ret->priv_key = BN_bin2bn(ASN1_STRING_data(priv_key->privateKey),\n ASN1_STRING_length(priv_key->privateKey),\n ret->priv_key);\n if (ret->priv_key == NULL) {\n ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_BN_LIB);\n goto err;\n }\n } else {\n ECerr(EC_F_D2I_ECPRIVATEKEY, EC_R_MISSING_PRIVATE_KEY);\n goto err;\n }\n EC_POINT_clear_free(ret->pub_key);\n ret->pub_key = EC_POINT_new(ret->group);\n if (ret->pub_key == NULL) {\n ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);\n goto err;\n }\n if (priv_key->publicKey) {\n const unsigned char *pub_oct;\n int pub_oct_len;\n pub_oct = ASN1_STRING_data(priv_key->publicKey);\n pub_oct_len = ASN1_STRING_length(priv_key->publicKey);\n if (pub_oct_len <= 0) {\n ECerr(EC_F_D2I_ECPRIVATEKEY, EC_R_BUFFER_TOO_SMALL);\n goto err;\n }\n ret->conv_form = (point_conversion_form_t) (pub_oct[0] & ~0x01);\n if (!EC_POINT_oct2point(ret->group, ret->pub_key,\n pub_oct, (size_t)(pub_oct_len), NULL)) {\n ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);\n goto err;\n }\n } else {\n if (!EC_POINT_mul\n (ret->group, ret->pub_key, ret->priv_key, NULL, NULL, NULL)) {\n ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);\n goto err;\n }\n ret->enc_flag |= EC_PKEY_NO_PUBKEY;\n }\n if (a)\n *a = ret;\n EC_PRIVATEKEY_free(priv_key);\n *in = p;\n return (ret);\n err:\n if (a == NULL || *a != ret)\n EC_KEY_free(ret);\n EC_PRIVATEKEY_free(priv_key);\n return NULL;\n}', 'EC_GROUP *ec_asn1_pkparameters2group(const ECPKPARAMETERS *params)\n{\n EC_GROUP *ret = NULL;\n int tmp = 0;\n if (params == NULL) {\n ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, EC_R_MISSING_PARAMETERS);\n return NULL;\n }\n if (params->type == 0) {\n tmp = OBJ_obj2nid(params->value.named_curve);\n if ((ret = EC_GROUP_new_by_curve_name(tmp)) == NULL) {\n ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP,\n EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);\n return NULL;\n }\n EC_GROUP_set_asn1_flag(ret, OPENSSL_EC_NAMED_CURVE);\n } else if (params->type == 1) {\n ret = ec_asn1_parameters2group(params->value.parameters);\n if (!ret) {\n ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, ERR_R_EC_LIB);\n return NULL;\n }\n EC_GROUP_set_asn1_flag(ret, 0x0);\n } else if (params->type == 2) {\n return NULL;\n } else {\n ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, EC_R_ASN1_ERROR);\n return NULL;\n }\n return ret;\n}', 'static EC_GROUP *ec_asn1_parameters2group(const ECPARAMETERS *params)\n{\n int ok = 0, tmp;\n EC_GROUP *ret = NULL;\n BIGNUM *p = NULL, *a = NULL, *b = NULL;\n EC_POINT *point = NULL;\n long field_bits;\n if (!params->fieldID || !params->fieldID->fieldType ||\n !params->fieldID->p.ptr) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n if (!params->curve || !params->curve->a ||\n !params->curve->a->data || !params->curve->b ||\n !params->curve->b->data) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n a = BN_bin2bn(params->curve->a->data, params->curve->a->length, NULL);\n if (a == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_BN_LIB);\n goto err;\n }\n b = BN_bin2bn(params->curve->b->data, params->curve->b->length, NULL);\n if (b == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_BN_LIB);\n goto err;\n }\n tmp = OBJ_obj2nid(params->fieldID->fieldType);\n if (tmp == NID_X9_62_characteristic_two_field)\n#ifdef OPENSSL_NO_EC2M\n {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_GF2M_NOT_SUPPORTED);\n goto err;\n }\n#else\n {\n X9_62_CHARACTERISTIC_TWO *char_two;\n char_two = params->fieldID->p.char_two;\n field_bits = char_two->m;\n if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_FIELD_TOO_LARGE);\n goto err;\n }\n if ((p = BN_new()) == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n tmp = OBJ_obj2nid(char_two->type);\n if (tmp == NID_X9_62_tpBasis) {\n long tmp_long;\n if (!char_two->p.tpBasis) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n tmp_long = ASN1_INTEGER_get(char_two->p.tpBasis);\n if (!(char_two->m > tmp_long && tmp_long > 0)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP,\n EC_R_INVALID_TRINOMIAL_BASIS);\n goto err;\n }\n if (!BN_set_bit(p, (int)char_two->m))\n goto err;\n if (!BN_set_bit(p, (int)tmp_long))\n goto err;\n if (!BN_set_bit(p, 0))\n goto err;\n } else if (tmp == NID_X9_62_ppBasis) {\n X9_62_PENTANOMIAL *penta;\n penta = char_two->p.ppBasis;\n if (!penta) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n if (!\n (char_two->m > penta->k3 && penta->k3 > penta->k2\n && penta->k2 > penta->k1 && penta->k1 > 0)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP,\n EC_R_INVALID_PENTANOMIAL_BASIS);\n goto err;\n }\n if (!BN_set_bit(p, (int)char_two->m))\n goto err;\n if (!BN_set_bit(p, (int)penta->k1))\n goto err;\n if (!BN_set_bit(p, (int)penta->k2))\n goto err;\n if (!BN_set_bit(p, (int)penta->k3))\n goto err;\n if (!BN_set_bit(p, 0))\n goto err;\n } else if (tmp == NID_X9_62_onBasis) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_NOT_IMPLEMENTED);\n goto err;\n } else {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n ret = EC_GROUP_new_curve_GF2m(p, a, b, NULL);\n }\n#endif\n else if (tmp == NID_X9_62_prime_field) {\n if (!params->fieldID->p.prime) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n p = ASN1_INTEGER_to_BN(params->fieldID->p.prime, NULL);\n if (p == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);\n goto err;\n }\n if (BN_is_negative(p) || BN_is_zero(p)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_FIELD);\n goto err;\n }\n field_bits = BN_num_bits(p);\n if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_FIELD_TOO_LARGE);\n goto err;\n }\n ret = EC_GROUP_new_curve_GFp(p, a, b, NULL);\n } else {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_FIELD);\n goto err;\n }\n if (ret == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);\n goto err;\n }\n if (params->curve->seed != NULL) {\n OPENSSL_free(ret->seed);\n if ((ret->seed = OPENSSL_malloc(params->curve->seed->length)) == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n memcpy(ret->seed, params->curve->seed->data,\n params->curve->seed->length);\n ret->seed_len = params->curve->seed->length;\n }\n if (!params->order || !params->base || !params->base->data) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n if ((point = EC_POINT_new(ret)) == NULL)\n goto err;\n EC_GROUP_set_point_conversion_form(ret, (point_conversion_form_t)\n (params->base->data[0] & ~0x01));\n if (!EC_POINT_oct2point(ret, point, params->base->data,\n params->base->length, NULL)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);\n goto err;\n }\n if ((a = ASN1_INTEGER_to_BN(params->order, a)) == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);\n goto err;\n }\n if (BN_is_negative(a) || BN_is_zero(a)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_GROUP_ORDER);\n goto err;\n }\n if (BN_num_bits(a) > (int)field_bits + 1) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_GROUP_ORDER);\n goto err;\n }\n if (params->cofactor == NULL) {\n BN_free(b);\n b = NULL;\n } else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);\n goto err;\n }\n if (!EC_GROUP_set_generator(ret, point, a, b)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);\n goto err;\n }\n ok = 1;\n err:\n if (!ok) {\n EC_GROUP_clear_free(ret);\n ret = NULL;\n }\n BN_free(p);\n BN_free(a);\n BN_free(b);\n EC_POINT_free(point);\n return (ret);\n}', 'int BN_set_bit(BIGNUM *a, int n)\n{\n int i, j, k;\n if (n < 0)\n return 0;\n i = n / BN_BITS2;\n j = n % BN_BITS2;\n if (a->top <= i) {\n if (bn_wexpand(a, i + 1) == NULL)\n return (0);\n for (k = a->top; k < i + 1; k++)\n a->d[k] = 0;\n a->top = i + 1;\n }\n a->d[i] |= (((BN_ULONG)1) << j);\n bn_check_top(a);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}'] |
34,369 | 0 | https://github.com/libav/libav/blob/58ef4ecff834f47f5a4c2a6bd4385b1999a30930/libavcodec/h264.c/#L2979 | static int decode_slice_header(H264Context *h, H264Context *h0){
MpegEncContext * const s = &h->s;
MpegEncContext * const s0 = &h0->s;
unsigned int first_mb_in_slice;
unsigned int pps_id;
int num_ref_idx_active_override_flag;
unsigned int slice_type, tmp, i, j;
int default_ref_list_done = 0;
int last_pic_structure;
s->dropable= h->nal_ref_idc == 0;
if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc && !h->pixel_shift){
s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;
s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;
}else{
s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab;
s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab;
}
first_mb_in_slice= get_ue_golomb(&s->gb);
if(first_mb_in_slice == 0){
if(h0->current_slice && FIELD_PICTURE){
field_end(h, 1);
}
h0->current_slice = 0;
if (!s0->first_field)
s->current_picture_ptr= NULL;
}
slice_type= get_ue_golomb_31(&s->gb);
if(slice_type > 9){
av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y);
return -1;
}
if(slice_type > 4){
slice_type -= 5;
h->slice_type_fixed=1;
}else
h->slice_type_fixed=0;
slice_type= golomb_to_pict_type[ slice_type ];
if (slice_type == AV_PICTURE_TYPE_I
|| (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) {
default_ref_list_done = 1;
}
h->slice_type= slice_type;
h->slice_type_nos= slice_type & 3;
s->pict_type= h->slice_type;
pps_id= get_ue_golomb(&s->gb);
if(pps_id>=MAX_PPS_COUNT){
av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n");
return -1;
}
if(!h0->pps_buffers[pps_id]) {
av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\n", pps_id);
return -1;
}
h->pps= *h0->pps_buffers[pps_id];
if(!h0->sps_buffers[h->pps.sps_id]) {
av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\n", h->pps.sps_id);
return -1;
}
h->sps = *h0->sps_buffers[h->pps.sps_id];
s->avctx->profile = ff_h264_get_profile(&h->sps);
s->avctx->level = h->sps.level_idc;
s->avctx->refs = h->sps.ref_frame_count;
if(h == h0 && h->dequant_coeff_pps != pps_id){
h->dequant_coeff_pps = pps_id;
init_dequant_tables(h);
}
s->mb_width= h->sps.mb_width;
s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);
h->b_stride= s->mb_width*4;
s->width = 16*s->mb_width - (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<<CHROMA444)-1);
if(h->sps.frame_mbs_only_flag)
s->height= 16*s->mb_height - (2>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1);
else
s->height= 16*s->mb_height - (4>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1);
if (s->context_initialized
&& ( s->width != s->avctx->width || s->height != s->avctx->height
|| av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {
if(h != h0) {
av_log_missing_feature(s->avctx, "Width/height changing with threads is", 0);
return -1;
}
free_tables(h, 0);
flush_dpb(s->avctx);
MPV_common_end(s);
}
if (!s->context_initialized) {
if (h != h0) {
av_log(h->s.avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\n");
return -1;
}
avcodec_set_dimensions(s->avctx, s->width, s->height);
s->avctx->sample_aspect_ratio= h->sps.sar;
av_assert0(s->avctx->sample_aspect_ratio.den);
h->s.avctx->coded_width = 16*s->mb_width;
h->s.avctx->coded_height = 16*s->mb_height;
if(h->sps.video_signal_type_present_flag){
s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
if(h->sps.colour_description_present_flag){
s->avctx->color_primaries = h->sps.color_primaries;
s->avctx->color_trc = h->sps.color_trc;
s->avctx->colorspace = h->sps.colorspace;
}
}
if(h->sps.timing_info_present_flag){
int64_t den= h->sps.time_scale;
if(h->x264_build < 44U)
den *= 2;
av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,
h->sps.num_units_in_tick, den, 1<<30);
}
switch (h->sps.bit_depth_luma) {
case 9 :
s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P9 : PIX_FMT_YUV420P9;
break;
case 10 :
s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P10 : PIX_FMT_YUV420P10;
break;
default:
if (CHROMA444){
s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P;
}else{
s->avctx->pix_fmt = s->avctx->get_format(s->avctx,
s->avctx->codec->pix_fmts ?
s->avctx->codec->pix_fmts :
s->avctx->color_range == AVCOL_RANGE_JPEG ?
hwaccel_pixfmt_list_h264_jpeg_420 :
ff_hwaccel_pixfmt_list_420);
}
}
s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id, s->avctx->pix_fmt);
if (MPV_common_init(s) < 0) {
av_log(h->s.avctx, AV_LOG_ERROR, "MPV_common_init() failed.\n");
return -1;
}
s->first_field = 0;
h->prev_interlaced_frame = 1;
init_scan_tables(h);
ff_h264_alloc_tables(h);
if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_SLICE)) {
if (context_init(h) < 0) {
av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\n");
return -1;
}
} else {
for(i = 1; i < s->avctx->thread_count; i++) {
H264Context *c;
c = h->thread_context[i] = av_malloc(sizeof(H264Context));
memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));
memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext));
c->h264dsp = h->h264dsp;
c->sps = h->sps;
c->pps = h->pps;
c->pixel_shift = h->pixel_shift;
init_scan_tables(c);
clone_tables(c, h, i);
}
for(i = 0; i < s->avctx->thread_count; i++)
if (context_init(h->thread_context[i]) < 0) {
av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\n");
return -1;
}
}
}
h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num);
h->mb_mbaff = 0;
h->mb_aff_frame = 0;
last_pic_structure = s0->picture_structure;
if(h->sps.frame_mbs_only_flag){
s->picture_structure= PICT_FRAME;
}else{
if(get_bits1(&s->gb)) {
s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb);
} else {
s->picture_structure= PICT_FRAME;
h->mb_aff_frame = h->sps.mb_aff;
}
}
h->mb_field_decoding_flag= s->picture_structure != PICT_FRAME;
if(h0->current_slice == 0){
if(h->frame_num != h->prev_frame_num) {
int unwrap_prev_frame_num = h->prev_frame_num, max_frame_num = 1<<h->sps.log2_max_frame_num;
if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num;
if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) {
unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1;
if (unwrap_prev_frame_num < 0)
unwrap_prev_frame_num += max_frame_num;
h->prev_frame_num = unwrap_prev_frame_num;
}
}
while(h->frame_num != h->prev_frame_num &&
h->frame_num != (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num)){
Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;
av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num);
if (ff_h264_frame_start(h) < 0)
return -1;
h->prev_frame_num++;
h->prev_frame_num %= 1<<h->sps.log2_max_frame_num;
s->current_picture_ptr->frame_num= h->prev_frame_num;
ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 0);
ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 1);
ff_generate_sliding_window_mmcos(h);
ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
if (h->short_ref_count) {
if (prev) {
av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize,
(const uint8_t**)prev->f.data, prev->f.linesize,
s->avctx->pix_fmt, s->mb_width*16, s->mb_height*16);
h->short_ref[0]->poc = prev->poc+2;
}
h->short_ref[0]->frame_num = h->prev_frame_num;
}
}
if (s0->first_field) {
assert(s0->current_picture_ptr);
assert(s0->current_picture_ptr->f.data[0]);
assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF);
if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {
s0->current_picture_ptr = NULL;
s0->first_field = FIELD_PICTURE;
} else {
if (h->nal_ref_idc &&
s0->current_picture_ptr->f.reference &&
s0->current_picture_ptr->frame_num != h->frame_num) {
s0->first_field = 1;
s0->current_picture_ptr = NULL;
} else {
s0->first_field = 0;
}
}
} else {
assert(!s0->current_picture_ptr);
s0->first_field = FIELD_PICTURE;
}
if(!FIELD_PICTURE || s0->first_field) {
if (ff_h264_frame_start(h) < 0) {
s0->first_field = 0;
return -1;
}
} else {
ff_release_unused_pictures(s, 0);
}
}
if(h != h0)
clone_slice(h, h0);
s->current_picture_ptr->frame_num= h->frame_num;
assert(s->mb_num == s->mb_width * s->mb_height);
if(first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num ||
first_mb_in_slice >= s->mb_num){
av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
return -1;
}
s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;
s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE;
if (s->picture_structure == PICT_BOTTOM_FIELD)
s->resync_mb_y = s->mb_y = s->mb_y + 1;
assert(s->mb_y < s->mb_height);
if(s->picture_structure==PICT_FRAME){
h->curr_pic_num= h->frame_num;
h->max_pic_num= 1<< h->sps.log2_max_frame_num;
}else{
h->curr_pic_num= 2*h->frame_num + 1;
h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1);
}
if(h->nal_unit_type == NAL_IDR_SLICE){
get_ue_golomb(&s->gb);
}
if(h->sps.poc_type==0){
h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb);
if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){
h->delta_poc_bottom= get_se_golomb(&s->gb);
}
}
if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){
h->delta_poc[0]= get_se_golomb(&s->gb);
if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME)
h->delta_poc[1]= get_se_golomb(&s->gb);
}
init_poc(h);
if(h->pps.redundant_pic_cnt_present){
h->redundant_pic_count= get_ue_golomb(&s->gb);
}
h->ref_count[0]= h->pps.ref_count[0];
h->ref_count[1]= h->pps.ref_count[1];
if(h->slice_type_nos != AV_PICTURE_TYPE_I){
if(h->slice_type_nos == AV_PICTURE_TYPE_B){
h->direct_spatial_mv_pred= get_bits1(&s->gb);
}
num_ref_idx_active_override_flag= get_bits1(&s->gb);
if(num_ref_idx_active_override_flag){
h->ref_count[0]= get_ue_golomb(&s->gb) + 1;
if(h->slice_type_nos==AV_PICTURE_TYPE_B)
h->ref_count[1]= get_ue_golomb(&s->gb) + 1;
if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){
av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n");
h->ref_count[0]= h->ref_count[1]= 1;
return -1;
}
}
if(h->slice_type_nos == AV_PICTURE_TYPE_B)
h->list_count= 2;
else
h->list_count= 1;
}else
h->list_count= 0;
if(!default_ref_list_done){
ff_h264_fill_default_ref_list(h);
}
if(h->slice_type_nos!=AV_PICTURE_TYPE_I && ff_h264_decode_ref_pic_list_reordering(h) < 0)
return -1;
if(h->slice_type_nos!=AV_PICTURE_TYPE_I){
s->last_picture_ptr= &h->ref_list[0][0];
ff_copy_picture(&s->last_picture, s->last_picture_ptr);
}
if(h->slice_type_nos==AV_PICTURE_TYPE_B){
s->next_picture_ptr= &h->ref_list[1][0];
ff_copy_picture(&s->next_picture, s->next_picture_ptr);
}
if( (h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P )
|| (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== AV_PICTURE_TYPE_B ) )
pred_weight_table(h);
else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){
implicit_weight_table(h, -1);
}else {
h->use_weight = 0;
for (i = 0; i < 2; i++) {
h->luma_weight_flag[i] = 0;
h->chroma_weight_flag[i] = 0;
}
}
if(h->nal_ref_idc)
ff_h264_decode_ref_pic_marking(h0, &s->gb);
if(FRAME_MBAFF){
ff_h264_fill_mbaff_ref_list(h);
if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){
implicit_weight_table(h, 0);
implicit_weight_table(h, 1);
}
}
if(h->slice_type_nos==AV_PICTURE_TYPE_B && !h->direct_spatial_mv_pred)
ff_h264_direct_dist_scale_factor(h);
ff_h264_direct_ref_list_init(h);
if( h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac ){
tmp = get_ue_golomb_31(&s->gb);
if(tmp > 2){
av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n");
return -1;
}
h->cabac_init_idc= tmp;
}
h->last_qscale_diff = 0;
tmp = h->pps.init_qp + get_se_golomb(&s->gb);
if(tmp>51+6*(h->sps.bit_depth_luma-8)){
av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp);
return -1;
}
s->qscale= tmp;
h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);
h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);
if(h->slice_type == AV_PICTURE_TYPE_SP){
get_bits1(&s->gb);
}
if(h->slice_type==AV_PICTURE_TYPE_SP || h->slice_type == AV_PICTURE_TYPE_SI){
get_se_golomb(&s->gb);
}
h->deblocking_filter = 1;
h->slice_alpha_c0_offset = 52;
h->slice_beta_offset = 52;
if( h->pps.deblocking_filter_parameters_present ) {
tmp= get_ue_golomb_31(&s->gb);
if(tmp > 2){
av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp);
return -1;
}
h->deblocking_filter= tmp;
if(h->deblocking_filter < 2)
h->deblocking_filter^= 1;
if( h->deblocking_filter ) {
h->slice_alpha_c0_offset += get_se_golomb(&s->gb) << 1;
h->slice_beta_offset += get_se_golomb(&s->gb) << 1;
if( h->slice_alpha_c0_offset > 104U
|| h->slice_beta_offset > 104U){
av_log(s->avctx, AV_LOG_ERROR, "deblocking filter parameters %d %d out of range\n", h->slice_alpha_c0_offset, h->slice_beta_offset);
return -1;
}
}
}
if( s->avctx->skip_loop_filter >= AVDISCARD_ALL
||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type_nos != AV_PICTURE_TYPE_I)
||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type_nos == AV_PICTURE_TYPE_B)
||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0))
h->deblocking_filter= 0;
if(h->deblocking_filter == 1 && h0->max_contexts > 1) {
if(s->avctx->flags2 & CODEC_FLAG2_FAST) {
h->deblocking_filter = 2;
} else {
h0->max_contexts = 1;
if(!h0->single_decode_warning) {
av_log(s->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n");
h0->single_decode_warning = 1;
}
if (h != h0) {
av_log(h->s.avctx, AV_LOG_ERROR, "Deblocking switched inside frame.\n");
return 1;
}
}
}
h->qp_thresh = 15 + 52 - FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset)
- FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1])
+ 6 * (h->sps.bit_depth_luma - 8);
#if 0
if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5)
slice_group_change_cycle= get_bits(&s->gb, ?);
#endif
h0->last_slice_type = slice_type;
h->slice_num = ++h0->current_slice;
if(h->slice_num >= MAX_SLICES){
av_log(s->avctx, AV_LOG_ERROR, "Too many slices, increase MAX_SLICES and recompile\n");
}
for(j=0; j<2; j++){
int id_list[16];
int *ref2frm= h->ref2frm[h->slice_num&(MAX_SLICES-1)][j];
for(i=0; i<16; i++){
id_list[i]= 60;
if (h->ref_list[j][i].f.data[0]) {
int k;
uint8_t *base = h->ref_list[j][i].f.base[0];
for(k=0; k<h->short_ref_count; k++)
if (h->short_ref[k]->f.base[0] == base) {
id_list[i]= k;
break;
}
for(k=0; k<h->long_ref_count; k++)
if (h->long_ref[k] && h->long_ref[k]->f.base[0] == base) {
id_list[i]= h->short_ref_count + k;
break;
}
}
}
ref2frm[0]=
ref2frm[1]= -1;
for(i=0; i<16; i++)
ref2frm[i+2]= 4*id_list[i]
+ (h->ref_list[j][i].f.reference & 3);
ref2frm[18+0]=
ref2frm[18+1]= -1;
for(i=16; i<48; i++)
ref2frm[i+4]= 4*id_list[(i-16)>>1]
+ (h->ref_list[j][i].f.reference & 3);
}
h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE || (!h->sps.frame_mbs_only_flag && s->avctx->active_thread_type)) ? 0 : 16;
h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;
if(s->avctx->debug&FF_DEBUG_PICT_INFO){
av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
h->slice_num,
(s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"),
first_mb_in_slice,
av_get_picture_type_char(h->slice_type), h->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",
pps_id, h->frame_num,
s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1],
h->ref_count[0], h->ref_count[1],
s->qscale,
h->deblocking_filter, h->slice_alpha_c0_offset/2-26, h->slice_beta_offset/2-26,
h->use_weight,
h->use_weight==1 && h->use_weight_chroma ? "c" : "",
h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""
);
}
return 0;
} | ['static int decode_slice_header(H264Context *h, H264Context *h0){\n MpegEncContext * const s = &h->s;\n MpegEncContext * const s0 = &h0->s;\n unsigned int first_mb_in_slice;\n unsigned int pps_id;\n int num_ref_idx_active_override_flag;\n unsigned int slice_type, tmp, i, j;\n int default_ref_list_done = 0;\n int last_pic_structure;\n s->dropable= h->nal_ref_idc == 0;\n if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc && !h->pixel_shift){\n s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;\n s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;\n }else{\n s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab;\n s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab;\n }\n first_mb_in_slice= get_ue_golomb(&s->gb);\n if(first_mb_in_slice == 0){\n if(h0->current_slice && FIELD_PICTURE){\n field_end(h, 1);\n }\n h0->current_slice = 0;\n if (!s0->first_field)\n s->current_picture_ptr= NULL;\n }\n slice_type= get_ue_golomb_31(&s->gb);\n if(slice_type > 9){\n av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\\n", h->slice_type, s->mb_x, s->mb_y);\n return -1;\n }\n if(slice_type > 4){\n slice_type -= 5;\n h->slice_type_fixed=1;\n }else\n h->slice_type_fixed=0;\n slice_type= golomb_to_pict_type[ slice_type ];\n if (slice_type == AV_PICTURE_TYPE_I\n || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) {\n default_ref_list_done = 1;\n }\n h->slice_type= slice_type;\n h->slice_type_nos= slice_type & 3;\n s->pict_type= h->slice_type;\n pps_id= get_ue_golomb(&s->gb);\n if(pps_id>=MAX_PPS_COUNT){\n av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\\n");\n return -1;\n }\n if(!h0->pps_buffers[pps_id]) {\n av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\\n", pps_id);\n return -1;\n }\n h->pps= *h0->pps_buffers[pps_id];\n if(!h0->sps_buffers[h->pps.sps_id]) {\n av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\\n", h->pps.sps_id);\n return -1;\n }\n h->sps = *h0->sps_buffers[h->pps.sps_id];\n s->avctx->profile = ff_h264_get_profile(&h->sps);\n s->avctx->level = h->sps.level_idc;\n s->avctx->refs = h->sps.ref_frame_count;\n if(h == h0 && h->dequant_coeff_pps != pps_id){\n h->dequant_coeff_pps = pps_id;\n init_dequant_tables(h);\n }\n s->mb_width= h->sps.mb_width;\n s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);\n h->b_stride= s->mb_width*4;\n s->width = 16*s->mb_width - (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<<CHROMA444)-1);\n if(h->sps.frame_mbs_only_flag)\n s->height= 16*s->mb_height - (2>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1);\n else\n s->height= 16*s->mb_height - (4>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1);\n if (s->context_initialized\n && ( s->width != s->avctx->width || s->height != s->avctx->height\n || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {\n if(h != h0) {\n av_log_missing_feature(s->avctx, "Width/height changing with threads is", 0);\n return -1;\n }\n free_tables(h, 0);\n flush_dpb(s->avctx);\n MPV_common_end(s);\n }\n if (!s->context_initialized) {\n if (h != h0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\\n");\n return -1;\n }\n avcodec_set_dimensions(s->avctx, s->width, s->height);\n s->avctx->sample_aspect_ratio= h->sps.sar;\n av_assert0(s->avctx->sample_aspect_ratio.den);\n h->s.avctx->coded_width = 16*s->mb_width;\n h->s.avctx->coded_height = 16*s->mb_height;\n if(h->sps.video_signal_type_present_flag){\n s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;\n if(h->sps.colour_description_present_flag){\n s->avctx->color_primaries = h->sps.color_primaries;\n s->avctx->color_trc = h->sps.color_trc;\n s->avctx->colorspace = h->sps.colorspace;\n }\n }\n if(h->sps.timing_info_present_flag){\n int64_t den= h->sps.time_scale;\n if(h->x264_build < 44U)\n den *= 2;\n av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,\n h->sps.num_units_in_tick, den, 1<<30);\n }\n switch (h->sps.bit_depth_luma) {\n case 9 :\n s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P9 : PIX_FMT_YUV420P9;\n break;\n case 10 :\n s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P10 : PIX_FMT_YUV420P10;\n break;\n default:\n if (CHROMA444){\n s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P;\n }else{\n s->avctx->pix_fmt = s->avctx->get_format(s->avctx,\n s->avctx->codec->pix_fmts ?\n s->avctx->codec->pix_fmts :\n s->avctx->color_range == AVCOL_RANGE_JPEG ?\n hwaccel_pixfmt_list_h264_jpeg_420 :\n ff_hwaccel_pixfmt_list_420);\n }\n }\n s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id, s->avctx->pix_fmt);\n if (MPV_common_init(s) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "MPV_common_init() failed.\\n");\n return -1;\n }\n s->first_field = 0;\n h->prev_interlaced_frame = 1;\n init_scan_tables(h);\n ff_h264_alloc_tables(h);\n if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_SLICE)) {\n if (context_init(h) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\\n");\n return -1;\n }\n } else {\n for(i = 1; i < s->avctx->thread_count; i++) {\n H264Context *c;\n c = h->thread_context[i] = av_malloc(sizeof(H264Context));\n memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));\n memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext));\n c->h264dsp = h->h264dsp;\n c->sps = h->sps;\n c->pps = h->pps;\n c->pixel_shift = h->pixel_shift;\n init_scan_tables(c);\n clone_tables(c, h, i);\n }\n for(i = 0; i < s->avctx->thread_count; i++)\n if (context_init(h->thread_context[i]) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\\n");\n return -1;\n }\n }\n }\n h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num);\n h->mb_mbaff = 0;\n h->mb_aff_frame = 0;\n last_pic_structure = s0->picture_structure;\n if(h->sps.frame_mbs_only_flag){\n s->picture_structure= PICT_FRAME;\n }else{\n if(get_bits1(&s->gb)) {\n s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb);\n } else {\n s->picture_structure= PICT_FRAME;\n h->mb_aff_frame = h->sps.mb_aff;\n }\n }\n h->mb_field_decoding_flag= s->picture_structure != PICT_FRAME;\n if(h0->current_slice == 0){\n if(h->frame_num != h->prev_frame_num) {\n int unwrap_prev_frame_num = h->prev_frame_num, max_frame_num = 1<<h->sps.log2_max_frame_num;\n if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num;\n if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) {\n unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1;\n if (unwrap_prev_frame_num < 0)\n unwrap_prev_frame_num += max_frame_num;\n h->prev_frame_num = unwrap_prev_frame_num;\n }\n }\n while(h->frame_num != h->prev_frame_num &&\n h->frame_num != (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num)){\n Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;\n av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\\n", h->frame_num, h->prev_frame_num);\n if (ff_h264_frame_start(h) < 0)\n return -1;\n h->prev_frame_num++;\n h->prev_frame_num %= 1<<h->sps.log2_max_frame_num;\n s->current_picture_ptr->frame_num= h->prev_frame_num;\n ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 0);\n ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 1);\n ff_generate_sliding_window_mmcos(h);\n ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);\n if (h->short_ref_count) {\n if (prev) {\n av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize,\n (const uint8_t**)prev->f.data, prev->f.linesize,\n s->avctx->pix_fmt, s->mb_width*16, s->mb_height*16);\n h->short_ref[0]->poc = prev->poc+2;\n }\n h->short_ref[0]->frame_num = h->prev_frame_num;\n }\n }\n if (s0->first_field) {\n assert(s0->current_picture_ptr);\n assert(s0->current_picture_ptr->f.data[0]);\n assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF);\n if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {\n s0->current_picture_ptr = NULL;\n s0->first_field = FIELD_PICTURE;\n } else {\n if (h->nal_ref_idc &&\n s0->current_picture_ptr->f.reference &&\n s0->current_picture_ptr->frame_num != h->frame_num) {\n s0->first_field = 1;\n s0->current_picture_ptr = NULL;\n } else {\n s0->first_field = 0;\n }\n }\n } else {\n assert(!s0->current_picture_ptr);\n s0->first_field = FIELD_PICTURE;\n }\n if(!FIELD_PICTURE || s0->first_field) {\n if (ff_h264_frame_start(h) < 0) {\n s0->first_field = 0;\n return -1;\n }\n } else {\n ff_release_unused_pictures(s, 0);\n }\n }\n if(h != h0)\n clone_slice(h, h0);\n s->current_picture_ptr->frame_num= h->frame_num;\n assert(s->mb_num == s->mb_width * s->mb_height);\n if(first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num ||\n first_mb_in_slice >= s->mb_num){\n av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\\n");\n return -1;\n }\n s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;\n s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE;\n if (s->picture_structure == PICT_BOTTOM_FIELD)\n s->resync_mb_y = s->mb_y = s->mb_y + 1;\n assert(s->mb_y < s->mb_height);\n if(s->picture_structure==PICT_FRAME){\n h->curr_pic_num= h->frame_num;\n h->max_pic_num= 1<< h->sps.log2_max_frame_num;\n }else{\n h->curr_pic_num= 2*h->frame_num + 1;\n h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1);\n }\n if(h->nal_unit_type == NAL_IDR_SLICE){\n get_ue_golomb(&s->gb);\n }\n if(h->sps.poc_type==0){\n h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb);\n if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){\n h->delta_poc_bottom= get_se_golomb(&s->gb);\n }\n }\n if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){\n h->delta_poc[0]= get_se_golomb(&s->gb);\n if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME)\n h->delta_poc[1]= get_se_golomb(&s->gb);\n }\n init_poc(h);\n if(h->pps.redundant_pic_cnt_present){\n h->redundant_pic_count= get_ue_golomb(&s->gb);\n }\n h->ref_count[0]= h->pps.ref_count[0];\n h->ref_count[1]= h->pps.ref_count[1];\n if(h->slice_type_nos != AV_PICTURE_TYPE_I){\n if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n h->direct_spatial_mv_pred= get_bits1(&s->gb);\n }\n num_ref_idx_active_override_flag= get_bits1(&s->gb);\n if(num_ref_idx_active_override_flag){\n h->ref_count[0]= get_ue_golomb(&s->gb) + 1;\n if(h->slice_type_nos==AV_PICTURE_TYPE_B)\n h->ref_count[1]= get_ue_golomb(&s->gb) + 1;\n if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){\n av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\\n");\n h->ref_count[0]= h->ref_count[1]= 1;\n return -1;\n }\n }\n if(h->slice_type_nos == AV_PICTURE_TYPE_B)\n h->list_count= 2;\n else\n h->list_count= 1;\n }else\n h->list_count= 0;\n if(!default_ref_list_done){\n ff_h264_fill_default_ref_list(h);\n }\n if(h->slice_type_nos!=AV_PICTURE_TYPE_I && ff_h264_decode_ref_pic_list_reordering(h) < 0)\n return -1;\n if(h->slice_type_nos!=AV_PICTURE_TYPE_I){\n s->last_picture_ptr= &h->ref_list[0][0];\n ff_copy_picture(&s->last_picture, s->last_picture_ptr);\n }\n if(h->slice_type_nos==AV_PICTURE_TYPE_B){\n s->next_picture_ptr= &h->ref_list[1][0];\n ff_copy_picture(&s->next_picture, s->next_picture_ptr);\n }\n if( (h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P )\n || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== AV_PICTURE_TYPE_B ) )\n pred_weight_table(h);\n else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){\n implicit_weight_table(h, -1);\n }else {\n h->use_weight = 0;\n for (i = 0; i < 2; i++) {\n h->luma_weight_flag[i] = 0;\n h->chroma_weight_flag[i] = 0;\n }\n }\n if(h->nal_ref_idc)\n ff_h264_decode_ref_pic_marking(h0, &s->gb);\n if(FRAME_MBAFF){\n ff_h264_fill_mbaff_ref_list(h);\n if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){\n implicit_weight_table(h, 0);\n implicit_weight_table(h, 1);\n }\n }\n if(h->slice_type_nos==AV_PICTURE_TYPE_B && !h->direct_spatial_mv_pred)\n ff_h264_direct_dist_scale_factor(h);\n ff_h264_direct_ref_list_init(h);\n if( h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac ){\n tmp = get_ue_golomb_31(&s->gb);\n if(tmp > 2){\n av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\\n");\n return -1;\n }\n h->cabac_init_idc= tmp;\n }\n h->last_qscale_diff = 0;\n tmp = h->pps.init_qp + get_se_golomb(&s->gb);\n if(tmp>51+6*(h->sps.bit_depth_luma-8)){\n av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n return -1;\n }\n s->qscale= tmp;\n h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n if(h->slice_type == AV_PICTURE_TYPE_SP){\n get_bits1(&s->gb);\n }\n if(h->slice_type==AV_PICTURE_TYPE_SP || h->slice_type == AV_PICTURE_TYPE_SI){\n get_se_golomb(&s->gb);\n }\n h->deblocking_filter = 1;\n h->slice_alpha_c0_offset = 52;\n h->slice_beta_offset = 52;\n if( h->pps.deblocking_filter_parameters_present ) {\n tmp= get_ue_golomb_31(&s->gb);\n if(tmp > 2){\n av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\\n", tmp);\n return -1;\n }\n h->deblocking_filter= tmp;\n if(h->deblocking_filter < 2)\n h->deblocking_filter^= 1;\n if( h->deblocking_filter ) {\n h->slice_alpha_c0_offset += get_se_golomb(&s->gb) << 1;\n h->slice_beta_offset += get_se_golomb(&s->gb) << 1;\n if( h->slice_alpha_c0_offset > 104U\n || h->slice_beta_offset > 104U){\n av_log(s->avctx, AV_LOG_ERROR, "deblocking filter parameters %d %d out of range\\n", h->slice_alpha_c0_offset, h->slice_beta_offset);\n return -1;\n }\n }\n }\n if( s->avctx->skip_loop_filter >= AVDISCARD_ALL\n ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type_nos != AV_PICTURE_TYPE_I)\n ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type_nos == AV_PICTURE_TYPE_B)\n ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0))\n h->deblocking_filter= 0;\n if(h->deblocking_filter == 1 && h0->max_contexts > 1) {\n if(s->avctx->flags2 & CODEC_FLAG2_FAST) {\n h->deblocking_filter = 2;\n } else {\n h0->max_contexts = 1;\n if(!h0->single_decode_warning) {\n av_log(s->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\\n");\n h0->single_decode_warning = 1;\n }\n if (h != h0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "Deblocking switched inside frame.\\n");\n return 1;\n }\n }\n }\n h->qp_thresh = 15 + 52 - FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset)\n - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1])\n + 6 * (h->sps.bit_depth_luma - 8);\n#if 0\n if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5)\n slice_group_change_cycle= get_bits(&s->gb, ?);\n#endif\n h0->last_slice_type = slice_type;\n h->slice_num = ++h0->current_slice;\n if(h->slice_num >= MAX_SLICES){\n av_log(s->avctx, AV_LOG_ERROR, "Too many slices, increase MAX_SLICES and recompile\\n");\n }\n for(j=0; j<2; j++){\n int id_list[16];\n int *ref2frm= h->ref2frm[h->slice_num&(MAX_SLICES-1)][j];\n for(i=0; i<16; i++){\n id_list[i]= 60;\n if (h->ref_list[j][i].f.data[0]) {\n int k;\n uint8_t *base = h->ref_list[j][i].f.base[0];\n for(k=0; k<h->short_ref_count; k++)\n if (h->short_ref[k]->f.base[0] == base) {\n id_list[i]= k;\n break;\n }\n for(k=0; k<h->long_ref_count; k++)\n if (h->long_ref[k] && h->long_ref[k]->f.base[0] == base) {\n id_list[i]= h->short_ref_count + k;\n break;\n }\n }\n }\n ref2frm[0]=\n ref2frm[1]= -1;\n for(i=0; i<16; i++)\n ref2frm[i+2]= 4*id_list[i]\n + (h->ref_list[j][i].f.reference & 3);\n ref2frm[18+0]=\n ref2frm[18+1]= -1;\n for(i=16; i<48; i++)\n ref2frm[i+4]= 4*id_list[(i-16)>>1]\n + (h->ref_list[j][i].f.reference & 3);\n }\n h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE || (!h->sps.frame_mbs_only_flag && s->avctx->active_thread_type)) ? 0 : 16;\n h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;\n if(s->avctx->debug&FF_DEBUG_PICT_INFO){\n av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\\n",\n h->slice_num,\n (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"),\n first_mb_in_slice,\n av_get_picture_type_char(h->slice_type), h->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",\n pps_id, h->frame_num,\n s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1],\n h->ref_count[0], h->ref_count[1],\n s->qscale,\n h->deblocking_filter, h->slice_alpha_c0_offset/2-26, h->slice_beta_offset/2-26,\n h->use_weight,\n h->use_weight==1 && h->use_weight_chroma ? "c" : "",\n h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""\n );\n }\n return 0;\n}'] |
34,370 | 0 | https://github.com/libav/libav/blob/548a99742c2498575d0dbcd1aa030b9d51d28b18/libswscale/swscale.c/#L3067 | SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,
float lumaSharpen, float chromaSharpen,
float chromaHShift, float chromaVShift,
int verbose)
{
SwsFilter *filter= av_malloc(sizeof(SwsFilter));
if (lumaGBlur!=0.0){
filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0);
filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0);
}else{
filter->lumH= sws_getIdentityVec();
filter->lumV= sws_getIdentityVec();
}
if (chromaGBlur!=0.0){
filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0);
filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0);
}else{
filter->chrH= sws_getIdentityVec();
filter->chrV= sws_getIdentityVec();
}
if (chromaSharpen!=0.0){
SwsVector *id= sws_getIdentityVec();
sws_scaleVec(filter->chrH, -chromaSharpen);
sws_scaleVec(filter->chrV, -chromaSharpen);
sws_addVec(filter->chrH, id);
sws_addVec(filter->chrV, id);
sws_freeVec(id);
}
if (lumaSharpen!=0.0){
SwsVector *id= sws_getIdentityVec();
sws_scaleVec(filter->lumH, -lumaSharpen);
sws_scaleVec(filter->lumV, -lumaSharpen);
sws_addVec(filter->lumH, id);
sws_addVec(filter->lumV, id);
sws_freeVec(id);
}
if (chromaHShift != 0.0)
sws_shiftVec(filter->chrH, (int)(chromaHShift+0.5));
if (chromaVShift != 0.0)
sws_shiftVec(filter->chrV, (int)(chromaVShift+0.5));
sws_normalizeVec(filter->chrH, 1.0);
sws_normalizeVec(filter->chrV, 1.0);
sws_normalizeVec(filter->lumH, 1.0);
sws_normalizeVec(filter->lumV, 1.0);
if (verbose) sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG);
if (verbose) sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);
return filter;
} | ['SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur,\n float lumaSharpen, float chromaSharpen,\n float chromaHShift, float chromaVShift,\n int verbose)\n{\n SwsFilter *filter= av_malloc(sizeof(SwsFilter));\n if (lumaGBlur!=0.0){\n filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0);\n filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0);\n }else{\n filter->lumH= sws_getIdentityVec();\n filter->lumV= sws_getIdentityVec();\n }\n if (chromaGBlur!=0.0){\n filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0);\n filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0);\n }else{\n filter->chrH= sws_getIdentityVec();\n filter->chrV= sws_getIdentityVec();\n }\n if (chromaSharpen!=0.0){\n SwsVector *id= sws_getIdentityVec();\n sws_scaleVec(filter->chrH, -chromaSharpen);\n sws_scaleVec(filter->chrV, -chromaSharpen);\n sws_addVec(filter->chrH, id);\n sws_addVec(filter->chrV, id);\n sws_freeVec(id);\n }\n if (lumaSharpen!=0.0){\n SwsVector *id= sws_getIdentityVec();\n sws_scaleVec(filter->lumH, -lumaSharpen);\n sws_scaleVec(filter->lumV, -lumaSharpen);\n sws_addVec(filter->lumH, id);\n sws_addVec(filter->lumV, id);\n sws_freeVec(id);\n }\n if (chromaHShift != 0.0)\n sws_shiftVec(filter->chrH, (int)(chromaHShift+0.5));\n if (chromaVShift != 0.0)\n sws_shiftVec(filter->chrV, (int)(chromaVShift+0.5));\n sws_normalizeVec(filter->chrH, 1.0);\n sws_normalizeVec(filter->chrV, 1.0);\n sws_normalizeVec(filter->lumH, 1.0);\n sws_normalizeVec(filter->lumV, 1.0);\n if (verbose) sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG);\n if (verbose) sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG);\n return filter;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'SwsVector *sws_getIdentityVec(void){\n return sws_getConstVec(1.0, 1);\n}'] |
34,371 | 0 | https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/lhash/lhash.c/#L122 | void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
{
unsigned long hash;
OPENSSL_LH_NODE *nn, **rn;
void *ret;
lh->error = 0;
rn = getrn(lh, data, &hash);
if (*rn == NULL) {
lh->num_no_delete++;
return NULL;
} else {
nn = *rn;
*rn = nn->next;
ret = nn->data;
OPENSSL_free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
contract(lh);
return ret;
} | ['int dtls1_process_buffered_records(SSL *s)\n{\n pitem *item;\n SSL3_BUFFER *rb;\n SSL3_RECORD *rr;\n DTLS1_BITMAP *bitmap;\n unsigned int is_next_epoch;\n int replayok = 1;\n item = pqueue_peek(s->rlayer.d->unprocessed_rcds.q);\n if (item) {\n if (s->rlayer.d->unprocessed_rcds.epoch != s->rlayer.d->r_epoch)\n return 1;\n rr = RECORD_LAYER_get_rrec(&s->rlayer);\n rb = RECORD_LAYER_get_rbuf(&s->rlayer);\n if (SSL3_BUFFER_get_left(rb) > 0) {\n return 1;\n }\n while (pqueue_peek(s->rlayer.d->unprocessed_rcds.q)) {\n dtls1_get_unprocessed_record(s);\n bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);\n if (bitmap == NULL) {\n SSLerr(SSL_F_DTLS1_PROCESS_BUFFERED_RECORDS,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n#ifndef OPENSSL_NO_SCTP\n if (!BIO_dgram_is_sctp(SSL_get_rbio(s)))\n#endif\n {\n replayok = dtls1_record_replay_check(s, bitmap);\n }\n if (!replayok || !dtls1_process_record(s, bitmap)) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n continue;\n }\n if (dtls1_buffer_record(s, &(s->rlayer.d->processed_rcds),\n SSL3_RECORD_get_seq_num(s->rlayer.rrec)) < 0)\n return 0;\n }\n }\n s->rlayer.d->processed_rcds.epoch = s->rlayer.d->r_epoch;\n s->rlayer.d->unprocessed_rcds.epoch = s->rlayer.d->r_epoch + 1;\n return 1;\n}', 'int dtls1_process_record(SSL *s, DTLS1_BITMAP *bitmap)\n{\n int i, al;\n int enc_err;\n SSL_SESSION *sess;\n SSL3_RECORD *rr;\n int imac_size;\n size_t mac_size;\n unsigned char md[EVP_MAX_MD_SIZE];\n rr = RECORD_LAYER_get_rrec(&s->rlayer);\n sess = s->session;\n rr->input = &(RECORD_LAYER_get_packet(&s->rlayer)[DTLS1_RT_HEADER_LENGTH]);\n if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH) {\n al = SSL_AD_RECORD_OVERFLOW;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_ENCRYPTED_LENGTH_TOO_LONG);\n goto f_err;\n }\n rr->data = rr->input;\n rr->orig_len = rr->length;\n if (SSL_READ_ETM(s) && s->read_hash) {\n unsigned char *mac;\n mac_size = EVP_MD_CTX_size(s->read_hash);\n if (!ossl_assert(mac_size <= EVP_MAX_MD_SIZE)) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n if (rr->orig_len < mac_size) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_LENGTH_TOO_SHORT);\n goto f_err;\n }\n rr->length -= mac_size;\n mac = rr->data + rr->length;\n i = s->method->ssl3_enc->mac(s, rr, md, 0 );\n if (i == 0 || CRYPTO_memcmp(md, mac, (size_t)mac_size) != 0) {\n al = SSL_AD_BAD_RECORD_MAC;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD,\n SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC);\n goto f_err;\n }\n }\n enc_err = s->method->ssl3_enc->enc(s, rr, 1, 0);\n if (enc_err == 0) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto err;\n }\n#ifdef SSL_DEBUG\n printf("dec %ld\\n", rr->length);\n {\n size_t z;\n for (z = 0; z < rr->length; z++)\n printf("%02X%c", rr->data[z], ((z + 1) % 16) ? \' \' : \'\\n\');\n }\n printf("\\n");\n#endif\n if ((sess != NULL) && !SSL_READ_ETM(s) &&\n (s->enc_read_ctx != NULL) && (EVP_MD_CTX_md(s->read_hash) != NULL)) {\n unsigned char *mac = NULL;\n unsigned char mac_tmp[EVP_MAX_MD_SIZE];\n imac_size = EVP_MD_CTX_size(s->read_hash);\n if (imac_size < 0) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, ERR_LIB_EVP);\n goto f_err;\n }\n mac_size = (size_t)imac_size;\n if (!ossl_assert(mac_size <= EVP_MAX_MD_SIZE)) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n if (rr->orig_len < mac_size ||\n (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n rr->orig_len < mac_size + 1)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_LENGTH_TOO_SHORT);\n goto f_err;\n }\n if (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE) {\n mac = mac_tmp;\n if (!ssl3_cbc_copy_mac(mac_tmp, rr, mac_size)) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n rr->length -= mac_size;\n } else {\n rr->length -= mac_size;\n mac = &rr->data[rr->length];\n }\n i = s->method->ssl3_enc->mac(s, rr, md, 0 );\n if (i == 0 || mac == NULL\n || CRYPTO_memcmp(md, mac, mac_size) != 0)\n enc_err = -1;\n if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH + mac_size)\n enc_err = -1;\n }\n if (enc_err < 0) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto err;\n }\n if (s->expand != NULL) {\n if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH) {\n al = SSL_AD_RECORD_OVERFLOW;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD,\n SSL_R_COMPRESSED_LENGTH_TOO_LONG);\n goto f_err;\n }\n if (!ssl3_do_uncompress(s, rr)) {\n al = SSL_AD_DECOMPRESSION_FAILURE;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_BAD_DECOMPRESSION);\n goto f_err;\n }\n }\n if (rr->length > SSL3_RT_MAX_PLAIN_LENGTH) {\n al = SSL_AD_RECORD_OVERFLOW;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_DATA_LENGTH_TOO_LONG);\n goto f_err;\n }\n rr->off = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n dtls1_record_bitmap_update(s, bitmap);\n return 1;\n f_err:\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\n return 0;\n}', 'int ssl3_send_alert(SSL *s, int level, int desc)\n{\n if (SSL_TREAT_AS_TLS13(s))\n desc = tls13_alert_code(desc);\n else\n desc = s->method->ssl3_enc->alert_value(desc);\n if (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n desc = SSL_AD_HANDSHAKE_FAILURE;\n if (desc < 0)\n return -1;\n if ((level == SSL3_AL_FATAL) && (s->session != NULL))\n SSL_CTX_remove_session(s->session_ctx, s->session);\n s->s3->alert_dispatch = 1;\n s->s3->send_alert[0] = level;\n s->s3->send_alert[1] = desc;\n if (!RECORD_LAYER_write_pending(&s->rlayer)) {\n return s->method->ssl_dispatch_alert(s);\n }\n return -1;\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_THREAD_write_lock(ctx->lock);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, c);\n SSL_SESSION_list_remove(ctx, c);\n }\n c->not_resumable = 1;\n if (lck)\n CRYPTO_THREAD_unlock(ctx->lock);\n if (ret)\n SSL_SESSION_free(r);\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, c);\n } else\n ret = 0;\n return ret;\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n unsigned long hash;\n OPENSSL_LH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return NULL;\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return ret;\n}'] |
34,372 | 0 | https://github.com/nginx/nginx/blob/a0caa70c98fcda923970c9edcf8caad60cb8e40a/src/core/ngx_hash.c/#L736 | ngx_int_t
ngx_hash_add_key(ngx_hash_keys_arrays_t *ha, ngx_str_t *key, void *value,
ngx_uint_t flags)
{
size_t len;
u_char *p;
ngx_str_t *name;
ngx_uint_t i, k, n, skip, last;
ngx_array_t *keys, *hwc;
ngx_hash_key_t *hk;
last = key->len;
if (flags & NGX_HASH_WILDCARD_KEY) {
n = 0;
for (i = 0; i < key->len; i++) {
if (key->data[i] == '*') {
if (++n > 1) {
return NGX_DECLINED;
}
}
if (key->data[i] == '.' && key->data[i + 1] == '.') {
return NGX_DECLINED;
}
}
if (key->len > 1 && key->data[0] == '.') {
skip = 1;
goto wildcard;
}
if (key->len > 2) {
if (key->data[0] == '*' && key->data[1] == '.') {
skip = 2;
goto wildcard;
}
if (key->data[i - 2] == '.' && key->data[i - 1] == '*') {
skip = 0;
last -= 2;
goto wildcard;
}
}
if (n) {
return NGX_DECLINED;
}
}
k = 0;
for (i = 0; i < last; i++) {
if (!(flags & NGX_HASH_READONLY_KEY)) {
key->data[i] = ngx_tolower(key->data[i]);
}
k = ngx_hash(k, key->data[i]);
}
k %= ha->hsize;
name = ha->keys_hash[k].elts;
if (name) {
for (i = 0; i < ha->keys_hash[k].nelts; i++) {
if (last != name[i].len) {
continue;
}
if (ngx_strncmp(key->data, name[i].data, last) == 0) {
return NGX_BUSY;
}
}
} else {
if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4,
sizeof(ngx_str_t))
!= NGX_OK)
{
return NGX_ERROR;
}
}
name = ngx_array_push(&ha->keys_hash[k]);
if (name == NULL) {
return NGX_ERROR;
}
*name = *key;
hk = ngx_array_push(&ha->keys);
if (hk == NULL) {
return NGX_ERROR;
}
hk->key = *key;
hk->key_hash = ngx_hash_key(key->data, last);
hk->value = value;
return NGX_OK;
wildcard:
k = ngx_hash_strlow(&key->data[skip], &key->data[skip], last - skip);
k %= ha->hsize;
if (skip == 1) {
name = ha->keys_hash[k].elts;
if (name) {
len = last - skip;
for (i = 0; i < ha->keys_hash[k].nelts; i++) {
if (len != name[i].len) {
continue;
}
if (ngx_strncmp(&key->data[1], name[i].data, len) == 0) {
return NGX_BUSY;
}
}
} else {
if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4,
sizeof(ngx_str_t))
!= NGX_OK)
{
return NGX_ERROR;
}
}
name = ngx_array_push(&ha->keys_hash[k]);
if (name == NULL) {
return NGX_ERROR;
}
name->len = last - 1;
name->data = ngx_pnalloc(ha->temp_pool, name->len);
if (name->data == NULL) {
return NGX_ERROR;
}
ngx_memcpy(name->data, &key->data[1], name->len);
}
if (skip) {
p = ngx_pnalloc(ha->temp_pool, last);
if (p == NULL) {
return NGX_ERROR;
}
len = 0;
n = 0;
for (i = last - 1; i; i--) {
if (key->data[i] == '.') {
ngx_memcpy(&p[n], &key->data[i + 1], len);
n += len;
p[n++] = '.';
len = 0;
continue;
}
len++;
}
if (len) {
ngx_memcpy(&p[n], &key->data[1], len);
n += len;
}
p[n] = '\0';
hwc = &ha->dns_wc_head;
keys = &ha->dns_wc_head_hash[k];
} else {
last++;
p = ngx_pnalloc(ha->temp_pool, last);
if (p == NULL) {
return NGX_ERROR;
}
ngx_cpystrn(p, key->data, last);
hwc = &ha->dns_wc_tail;
keys = &ha->dns_wc_tail_hash[k];
}
name = keys->elts;
if (name) {
len = last - skip;
for (i = 0; i < keys->nelts; i++) {
if (len != name[i].len) {
continue;
}
if (ngx_strncmp(key->data + skip, name[i].data, len) == 0) {
return NGX_BUSY;
}
}
} else {
if (ngx_array_init(keys, ha->temp_pool, 4, sizeof(ngx_str_t)) != NGX_OK)
{
return NGX_ERROR;
}
}
name = ngx_array_push(keys);
if (name == NULL) {
return NGX_ERROR;
}
name->len = last - skip;
name->data = ngx_pnalloc(ha->temp_pool, name->len);
if (name->data == NULL) {
return NGX_ERROR;
}
ngx_memcpy(name->data, key->data + skip, name->len);
hk = ngx_array_push(hwc);
if (hk == NULL) {
return NGX_ERROR;
}
hk->key.len = last - 1;
hk->key.data = p;
hk->key_hash = 0;
hk->value = value;
return NGX_OK;
} | ['ngx_http_variable_t *\nngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags)\n{\n ngx_int_t rc;\n ngx_uint_t i;\n ngx_hash_key_t *key;\n ngx_http_variable_t *v;\n ngx_http_core_main_conf_t *cmcf;\n if (name->len == 0) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid variable name \\"$\\"");\n return NULL;\n }\n cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);\n key = cmcf->variables_keys->keys.elts;\n for (i = 0; i < cmcf->variables_keys->keys.nelts; i++) {\n if (name->len != key[i].key.len\n || ngx_strncasecmp(name->data, key[i].key.data, name->len) != 0)\n {\n continue;\n }\n v = key[i].value;\n if (!(v->flags & NGX_HTTP_VAR_CHANGEABLE)) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "the duplicate \\"%V\\" variable", name);\n return NULL;\n }\n return v;\n }\n v = ngx_palloc(cf->pool, sizeof(ngx_http_variable_t));\n if (v == NULL) {\n return NULL;\n }\n v->name.len = name->len;\n v->name.data = ngx_pnalloc(cf->pool, name->len);\n if (v->name.data == NULL) {\n return NULL;\n }\n ngx_strlow(v->name.data, name->data, name->len);\n v->set_handler = NULL;\n v->get_handler = NULL;\n v->data = 0;\n v->flags = flags;\n v->index = 0;\n rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, 0);\n if (rc == NGX_ERROR) {\n return NULL;\n }\n if (rc == NGX_BUSY) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "conflicting variable name \\"%V\\"", name);\n return NULL;\n }\n return v;\n}', "ngx_int_t\nngx_hash_add_key(ngx_hash_keys_arrays_t *ha, ngx_str_t *key, void *value,\n ngx_uint_t flags)\n{\n size_t len;\n u_char *p;\n ngx_str_t *name;\n ngx_uint_t i, k, n, skip, last;\n ngx_array_t *keys, *hwc;\n ngx_hash_key_t *hk;\n last = key->len;\n if (flags & NGX_HASH_WILDCARD_KEY) {\n n = 0;\n for (i = 0; i < key->len; i++) {\n if (key->data[i] == '*') {\n if (++n > 1) {\n return NGX_DECLINED;\n }\n }\n if (key->data[i] == '.' && key->data[i + 1] == '.') {\n return NGX_DECLINED;\n }\n }\n if (key->len > 1 && key->data[0] == '.') {\n skip = 1;\n goto wildcard;\n }\n if (key->len > 2) {\n if (key->data[0] == '*' && key->data[1] == '.') {\n skip = 2;\n goto wildcard;\n }\n if (key->data[i - 2] == '.' && key->data[i - 1] == '*') {\n skip = 0;\n last -= 2;\n goto wildcard;\n }\n }\n if (n) {\n return NGX_DECLINED;\n }\n }\n k = 0;\n for (i = 0; i < last; i++) {\n if (!(flags & NGX_HASH_READONLY_KEY)) {\n key->data[i] = ngx_tolower(key->data[i]);\n }\n k = ngx_hash(k, key->data[i]);\n }\n k %= ha->hsize;\n name = ha->keys_hash[k].elts;\n if (name) {\n for (i = 0; i < ha->keys_hash[k].nelts; i++) {\n if (last != name[i].len) {\n continue;\n }\n if (ngx_strncmp(key->data, name[i].data, last) == 0) {\n return NGX_BUSY;\n }\n }\n } else {\n if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4,\n sizeof(ngx_str_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n }\n name = ngx_array_push(&ha->keys_hash[k]);\n if (name == NULL) {\n return NGX_ERROR;\n }\n *name = *key;\n hk = ngx_array_push(&ha->keys);\n if (hk == NULL) {\n return NGX_ERROR;\n }\n hk->key = *key;\n hk->key_hash = ngx_hash_key(key->data, last);\n hk->value = value;\n return NGX_OK;\nwildcard:\n k = ngx_hash_strlow(&key->data[skip], &key->data[skip], last - skip);\n k %= ha->hsize;\n if (skip == 1) {\n name = ha->keys_hash[k].elts;\n if (name) {\n len = last - skip;\n for (i = 0; i < ha->keys_hash[k].nelts; i++) {\n if (len != name[i].len) {\n continue;\n }\n if (ngx_strncmp(&key->data[1], name[i].data, len) == 0) {\n return NGX_BUSY;\n }\n }\n } else {\n if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4,\n sizeof(ngx_str_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n }\n name = ngx_array_push(&ha->keys_hash[k]);\n if (name == NULL) {\n return NGX_ERROR;\n }\n name->len = last - 1;\n name->data = ngx_pnalloc(ha->temp_pool, name->len);\n if (name->data == NULL) {\n return NGX_ERROR;\n }\n ngx_memcpy(name->data, &key->data[1], name->len);\n }\n if (skip) {\n p = ngx_pnalloc(ha->temp_pool, last);\n if (p == NULL) {\n return NGX_ERROR;\n }\n len = 0;\n n = 0;\n for (i = last - 1; i; i--) {\n if (key->data[i] == '.') {\n ngx_memcpy(&p[n], &key->data[i + 1], len);\n n += len;\n p[n++] = '.';\n len = 0;\n continue;\n }\n len++;\n }\n if (len) {\n ngx_memcpy(&p[n], &key->data[1], len);\n n += len;\n }\n p[n] = '\\0';\n hwc = &ha->dns_wc_head;\n keys = &ha->dns_wc_head_hash[k];\n } else {\n last++;\n p = ngx_pnalloc(ha->temp_pool, last);\n if (p == NULL) {\n return NGX_ERROR;\n }\n ngx_cpystrn(p, key->data, last);\n hwc = &ha->dns_wc_tail;\n keys = &ha->dns_wc_tail_hash[k];\n }\n name = keys->elts;\n if (name) {\n len = last - skip;\n for (i = 0; i < keys->nelts; i++) {\n if (len != name[i].len) {\n continue;\n }\n if (ngx_strncmp(key->data + skip, name[i].data, len) == 0) {\n return NGX_BUSY;\n }\n }\n } else {\n if (ngx_array_init(keys, ha->temp_pool, 4, sizeof(ngx_str_t)) != NGX_OK)\n {\n return NGX_ERROR;\n }\n }\n name = ngx_array_push(keys);\n if (name == NULL) {\n return NGX_ERROR;\n }\n name->len = last - skip;\n name->data = ngx_pnalloc(ha->temp_pool, name->len);\n if (name->data == NULL) {\n return NGX_ERROR;\n }\n ngx_memcpy(name->data, key->data + skip, name->len);\n hk = ngx_array_push(hwc);\n if (hk == NULL) {\n return NGX_ERROR;\n }\n hk->key.len = last - 1;\n hk->key.data = p;\n hk->key_hash = 0;\n hk->value = value;\n return NGX_OK;\n}"] |
34,373 | 0 | https://github.com/libav/libav/blob/ed669c9becf9d03c25e78ee98c2e4de564b854fc/avconv.c/#L3110 | static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type)
{
OutputStream *ost;
AVStream *st = avformat_new_stream(oc, NULL);
int idx = oc->nb_streams - 1, ret = 0;
int64_t max_frames = INT64_MAX;
char *bsf = NULL, *next, *codec_tag = NULL;
AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;
double qscale = -1;
char *buf = NULL, *arg = NULL, *preset = NULL;
AVIOContext *s = NULL;
if (!st) {
av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
exit_program(1);
}
if (oc->nb_streams - 1 < o->nb_streamid_map)
st->id = o->streamid_map[oc->nb_streams - 1];
output_streams = grow_array(output_streams, sizeof(*output_streams), &nb_output_streams,
nb_output_streams + 1);
ost = &output_streams[nb_output_streams - 1];
ost->file_index = nb_output_files;
ost->index = idx;
ost->st = st;
st->codec->codec_type = type;
choose_encoder(o, oc, ost);
if (ost->enc) {
ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st);
}
avcodec_get_context_defaults3(st->codec, ost->enc);
st->codec->codec_type = type;
MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
do {
buf = get_line(s);
if (!buf[0] || buf[0] == '#') {
av_free(buf);
continue;
}
if (!(arg = strchr(buf, '='))) {
av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
exit_program(1);
}
*arg++ = 0;
av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE);
av_free(buf);
} while (!s->eof_reached);
avio_close(s);
}
if (ret) {
av_log(NULL, AV_LOG_FATAL,
"Preset %s specified for stream %d:%d, but could not be opened.\n",
preset, ost->file_index, ost->index);
exit_program(1);
}
MATCH_PER_STREAM_OPT(max_frames, i64, max_frames, oc, st);
ost->max_frames = max_frames;
MATCH_PER_STREAM_OPT(bitstream_filters, str, bsf, oc, st);
while (bsf) {
if (next = strchr(bsf, ','))
*next++ = 0;
if (!(bsfc = av_bitstream_filter_init(bsf))) {
av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf);
exit_program(1);
}
if (bsfc_prev)
bsfc_prev->next = bsfc;
else
ost->bitstream_filters = bsfc;
bsfc_prev = bsfc;
bsf = next;
}
MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
if (codec_tag) {
uint32_t tag = strtol(codec_tag, &next, 0);
if (*next)
tag = AV_RL32(codec_tag);
st->codec->codec_tag = tag;
}
MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
if (qscale >= 0 || same_quant) {
st->codec->flags |= CODEC_FLAG_QSCALE;
st->codec->global_quality = FF_QP2LAMBDA * qscale;
}
if (oc->oformat->flags & AVFMT_GLOBALHEADER)
st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
av_opt_get_int(sws_opts, "sws_flags", 0, &ost->sws_flags);
return ost;
} | ['static void opt_output_file(void *optctx, const char *filename)\n{\n OptionsContext *o = optctx;\n AVFormatContext *oc;\n int i, err;\n AVOutputFormat *file_oformat;\n OutputStream *ost;\n InputStream *ist;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!oc) {\n print_error(filename, AVERROR(ENOMEM));\n exit_program(1);\n }\n if (o->format) {\n file_oformat = av_guess_format(o->format, NULL, NULL);\n if (!file_oformat) {\n av_log(NULL, AV_LOG_FATAL, "Requested output format \'%s\' is not a suitable output format\\n", o->format);\n exit_program(1);\n }\n } else {\n file_oformat = av_guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n av_log(NULL, AV_LOG_FATAL, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n exit_program(1);\n }\n }\n oc->oformat = file_oformat;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!strcmp(file_oformat->name, "ffm") &&\n av_strstart(filename, "http:", NULL)) {\n int err = read_avserver_streams(o, oc, filename);\n if (err < 0) {\n print_error(filename, err);\n exit_program(1);\n }\n } else if (!o->nb_stream_maps) {\n#define NEW_STREAM(type, index)\\\n if (index >= 0) {\\\n ost = new_ ## type ## _stream(o, oc);\\\n ost->source_index = index;\\\n ost->sync_ist = &input_streams[index];\\\n input_streams[index].discard = 0;\\\n }\n if (!o->video_disable && oc->oformat->video_codec != CODEC_ID_NONE) {\n int area = 0, idx = -1;\n for (i = 0; i < nb_input_streams; i++) {\n ist = &input_streams[i];\n if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&\n ist->st->codec->width * ist->st->codec->height > area) {\n area = ist->st->codec->width * ist->st->codec->height;\n idx = i;\n }\n }\n NEW_STREAM(video, idx);\n }\n if (!o->audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) {\n int channels = 0, idx = -1;\n for (i = 0; i < nb_input_streams; i++) {\n ist = &input_streams[i];\n if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&\n ist->st->codec->channels > channels) {\n channels = ist->st->codec->channels;\n idx = i;\n }\n }\n NEW_STREAM(audio, idx);\n }\n if (!o->subtitle_disable && oc->oformat->subtitle_codec != CODEC_ID_NONE) {\n for (i = 0; i < nb_input_streams; i++)\n if (input_streams[i].st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {\n NEW_STREAM(subtitle, i);\n break;\n }\n }\n } else {\n for (i = 0; i < o->nb_stream_maps; i++) {\n StreamMap *map = &o->stream_maps[i];\n if (map->disabled)\n continue;\n ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index];\n switch (ist->st->codec->codec_type) {\n case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc); break;\n case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break;\n case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream(o, oc); break;\n case AVMEDIA_TYPE_DATA: ost = new_data_stream(o, oc); break;\n case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc); break;\n default:\n av_log(NULL, AV_LOG_FATAL, "Cannot map stream #%d.%d - unsupported type.\\n",\n map->file_index, map->stream_index);\n exit_program(1);\n }\n ost->source_index = input_files[map->file_index].ist_index + map->stream_index;\n ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index +\n map->sync_stream_index];\n ist->discard = 0;\n }\n }\n for (i = 0; i < o->nb_attachments; i++) {\n AVIOContext *pb;\n uint8_t *attachment;\n const char *p;\n int64_t len;\n if ((err = avio_open(&pb, o->attachments[i], AVIO_FLAG_READ)) < 0) {\n av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\\n",\n o->attachments[i]);\n exit_program(1);\n }\n if ((len = avio_size(pb)) <= 0) {\n av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\\n",\n o->attachments[i]);\n exit_program(1);\n }\n if (!(attachment = av_malloc(len))) {\n av_log(NULL, AV_LOG_FATAL, "Attachment %s too large to fit into memory.\\n",\n o->attachments[i]);\n exit_program(1);\n }\n avio_read(pb, attachment, len);\n ost = new_attachment_stream(o, oc);\n ost->stream_copy = 0;\n ost->source_index = -1;\n ost->attachment_filename = o->attachments[i];\n ost->st->codec->extradata = attachment;\n ost->st->codec->extradata_size = len;\n p = strrchr(o->attachments[i], \'/\');\n av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);\n avio_close(pb);\n }\n output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1);\n output_files[nb_output_files - 1].ctx = oc;\n output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams;\n output_files[nb_output_files - 1].recording_time = o->recording_time;\n output_files[nb_output_files - 1].start_time = o->start_time;\n output_files[nb_output_files - 1].limit_filesize = o->limit_filesize;\n av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0);\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR(EINVAL));\n exit_program(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n assert_file_overwrite(filename);\n if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {\n print_error(filename, err);\n exit_program(1);\n }\n }\n if (o->mux_preload) {\n uint8_t buf[64];\n snprintf(buf, sizeof(buf), "%d", (int)(o->mux_preload*AV_TIME_BASE));\n av_dict_set(&output_files[nb_output_files - 1].opts, "preload", buf, 0);\n }\n oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n if (o->chapters_input_file >= nb_input_files) {\n if (o->chapters_input_file == INT_MAX) {\n o->chapters_input_file = -1;\n for (i = 0; i < nb_input_files; i++)\n if (input_files[i].ctx->nb_chapters) {\n o->chapters_input_file = i;\n break;\n }\n } else {\n av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\\n",\n o->chapters_input_file);\n exit_program(1);\n }\n }\n if (o->chapters_input_file >= 0)\n copy_chapters(&input_files[o->chapters_input_file], &output_files[nb_output_files - 1],\n !o->metadata_chapters_manual);\n for (i = 0; i < o->nb_meta_data_maps; i++) {\n AVFormatContext *files[2];\n AVDictionary **meta[2];\n int j;\n#define METADATA_CHECK_INDEX(index, nb_elems, desc)\\\n if ((index) < 0 || (index) >= (nb_elems)) {\\\n av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps\\n",\\\n (desc), (index));\\\n exit_program(1);\\\n }\n int in_file_index = o->meta_data_maps[i][1].file;\n if (in_file_index < 0)\n continue;\n METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file")\n files[0] = oc;\n files[1] = input_files[in_file_index].ctx;\n for (j = 0; j < 2; j++) {\n MetadataMap *map = &o->meta_data_maps[i][j];\n switch (map->type) {\n case \'g\':\n meta[j] = &files[j]->metadata;\n break;\n case \'s\':\n METADATA_CHECK_INDEX(map->index, files[j]->nb_streams, "stream")\n meta[j] = &files[j]->streams[map->index]->metadata;\n break;\n case \'c\':\n METADATA_CHECK_INDEX(map->index, files[j]->nb_chapters, "chapter")\n meta[j] = &files[j]->chapters[map->index]->metadata;\n break;\n case \'p\':\n METADATA_CHECK_INDEX(map->index, files[j]->nb_programs, "program")\n meta[j] = &files[j]->programs[map->index]->metadata;\n break;\n }\n }\n av_dict_copy(meta[0], *meta[1], AV_DICT_DONT_OVERWRITE);\n }\n if (!o->metadata_global_manual && nb_input_files)\n av_dict_copy(&oc->metadata, input_files[0].ctx->metadata,\n AV_DICT_DONT_OVERWRITE);\n if (!o->metadata_streams_manual)\n for (i = output_files[nb_output_files - 1].ost_index; i < nb_output_streams; i++) {\n InputStream *ist;\n if (output_streams[i].source_index < 0)\n continue;\n ist = &input_streams[output_streams[i].source_index];\n av_dict_copy(&output_streams[i].st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);\n }\n for (i = 0; i < o->nb_metadata; i++) {\n AVDictionary **m;\n char type, *val;\n int index = 0;\n val = strchr(o->metadata[i].u.str, \'=\');\n if (!val) {\n av_log(NULL, AV_LOG_FATAL, "No \'=\' character in metadata string %s.\\n",\n o->metadata[i].u.str);\n exit_program(1);\n }\n *val++ = 0;\n parse_meta_type(o->metadata[i].specifier, &type, &index);\n switch (type) {\n case \'g\':\n m = &oc->metadata;\n break;\n case \'s\':\n if (index < 0 || index >= oc->nb_streams) {\n av_log(NULL, AV_LOG_FATAL, "Invalid stream index %d in metadata specifier.\\n", index);\n exit_program(1);\n }\n m = &oc->streams[index]->metadata;\n break;\n case \'c\':\n if (index < 0 || index >= oc->nb_chapters) {\n av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\\n", index);\n exit_program(1);\n }\n m = &oc->chapters[index]->metadata;\n break;\n default:\n av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\\n", o->metadata[i].specifier);\n exit_program(1);\n }\n av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);\n }\n reset_options(o);\n}', 'static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc)\n{\n AVStream *st;\n OutputStream *ost;\n AVCodecContext *video_enc;\n ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO);\n st = ost->st;\n video_enc = st->codec;\n if (!ost->stream_copy) {\n const char *p = NULL;\n char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL;\n char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL;\n char *intra_matrix = NULL, *inter_matrix = NULL, *filters = NULL;\n int i, force_fps = 0, top_field_first = -1;\n MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);\n if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {\n av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\\n", frame_rate);\n exit_program(1);\n }\n MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);\n if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {\n av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\\n", frame_size);\n exit_program(1);\n }\n MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);\n if (frame_aspect_ratio)\n ost->frame_aspect_ratio = parse_frame_aspect_ratio(frame_aspect_ratio);\n MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);\n if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == PIX_FMT_NONE) {\n av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\\n", frame_pix_fmt);\n exit_program(1);\n }\n st->sample_aspect_ratio = video_enc->sample_aspect_ratio;\n MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);\n if (intra_matrix) {\n if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {\n av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\\n");\n exit_program(1);\n }\n parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);\n }\n MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);\n if (inter_matrix) {\n if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {\n av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\\n");\n exit_program(1);\n }\n parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);\n }\n MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);\n for(i=0; p; i++){\n int start, end, q;\n int e=sscanf(p, "%d,%d,%d", &start, &end, &q);\n if(e!=3){\n av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\\n");\n exit_program(1);\n }\n video_enc->rc_override=\n av_realloc(video_enc->rc_override,\n sizeof(RcOverride)*(i+1));\n video_enc->rc_override[i].start_frame= start;\n video_enc->rc_override[i].end_frame = end;\n if(q>0){\n video_enc->rc_override[i].qscale= q;\n video_enc->rc_override[i].quality_factor= 1.0;\n }\n else{\n video_enc->rc_override[i].qscale= 0;\n video_enc->rc_override[i].quality_factor= -q/100.0;\n }\n p= strchr(p, \'/\');\n if(p) p++;\n }\n video_enc->rc_override_count=i;\n if (!video_enc->rc_initial_buffer_occupancy)\n video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;\n video_enc->intra_dc_precision= intra_dc_precision - 8;\n if (do_pass) {\n if (do_pass == 1) {\n video_enc->flags |= CODEC_FLAG_PASS1;\n } else {\n video_enc->flags |= CODEC_FLAG_PASS2;\n }\n }\n MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_key_frames, oc, st);\n if (forced_key_frames)\n parse_forced_key_frames(forced_key_frames, ost, video_enc);\n MATCH_PER_STREAM_OPT(force_fps, i, force_fps, oc, st);\n ost->force_fps = force_fps;\n MATCH_PER_STREAM_OPT(top_field_first, i, top_field_first, oc, st);\n ost->top_field_first = top_field_first;\n#if CONFIG_AVFILTER\n MATCH_PER_STREAM_OPT(filters, str, filters, oc, st);\n if (filters)\n ost->avfilter = av_strdup(filters);\n#endif\n }\n return ost;\n}', 'static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type)\n{\n OutputStream *ost;\n AVStream *st = avformat_new_stream(oc, NULL);\n int idx = oc->nb_streams - 1, ret = 0;\n int64_t max_frames = INT64_MAX;\n char *bsf = NULL, *next, *codec_tag = NULL;\n AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL;\n double qscale = -1;\n char *buf = NULL, *arg = NULL, *preset = NULL;\n AVIOContext *s = NULL;\n if (!st) {\n av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\\n");\n exit_program(1);\n }\n if (oc->nb_streams - 1 < o->nb_streamid_map)\n st->id = o->streamid_map[oc->nb_streams - 1];\n output_streams = grow_array(output_streams, sizeof(*output_streams), &nb_output_streams,\n nb_output_streams + 1);\n ost = &output_streams[nb_output_streams - 1];\n ost->file_index = nb_output_files;\n ost->index = idx;\n ost->st = st;\n st->codec->codec_type = type;\n choose_encoder(o, oc, ost);\n if (ost->enc) {\n ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st);\n }\n avcodec_get_context_defaults3(st->codec, ost->enc);\n st->codec->codec_type = type;\n MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);\n if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {\n do {\n buf = get_line(s);\n if (!buf[0] || buf[0] == \'#\') {\n av_free(buf);\n continue;\n }\n if (!(arg = strchr(buf, \'=\'))) {\n av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\\n");\n exit_program(1);\n }\n *arg++ = 0;\n av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE);\n av_free(buf);\n } while (!s->eof_reached);\n avio_close(s);\n }\n if (ret) {\n av_log(NULL, AV_LOG_FATAL,\n "Preset %s specified for stream %d:%d, but could not be opened.\\n",\n preset, ost->file_index, ost->index);\n exit_program(1);\n }\n MATCH_PER_STREAM_OPT(max_frames, i64, max_frames, oc, st);\n ost->max_frames = max_frames;\n MATCH_PER_STREAM_OPT(bitstream_filters, str, bsf, oc, st);\n while (bsf) {\n if (next = strchr(bsf, \',\'))\n *next++ = 0;\n if (!(bsfc = av_bitstream_filter_init(bsf))) {\n av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\\n", bsf);\n exit_program(1);\n }\n if (bsfc_prev)\n bsfc_prev->next = bsfc;\n else\n ost->bitstream_filters = bsfc;\n bsfc_prev = bsfc;\n bsf = next;\n }\n MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);\n if (codec_tag) {\n uint32_t tag = strtol(codec_tag, &next, 0);\n if (*next)\n tag = AV_RL32(codec_tag);\n st->codec->codec_tag = tag;\n }\n MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);\n if (qscale >= 0 || same_quant) {\n st->codec->flags |= CODEC_FLAG_QSCALE;\n st->codec->global_quality = FF_QP2LAMBDA * qscale;\n }\n if (oc->oformat->flags & AVFMT_GLOBALHEADER)\n st->codec->flags |= CODEC_FLAG_GLOBAL_HEADER;\n av_opt_get_int(sws_opts, "sws_flags", 0, &ost->sws_flags);\n return ost;\n}', 'AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c)\n{\n AVStream *st;\n int i;\n AVStream **streams;\n if (s->nb_streams >= INT_MAX/sizeof(*streams))\n return NULL;\n streams = av_realloc(s->streams, (s->nb_streams + 1) * sizeof(*streams));\n if (!streams)\n return NULL;\n s->streams = streams;\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n if (!(st->info = av_mallocz(sizeof(*st->info)))) {\n av_free(st);\n return NULL;\n }\n st->codec = avcodec_alloc_context3(c);\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = 0;\n st->first_dts = AV_NOPTS_VALUE;\n st->probe_packets = MAX_PROBE_PACKETS;\n av_set_pts_info(st, 33, 1, 90000);\n st->last_IP_pts = AV_NOPTS_VALUE;\n for(i=0; i<MAX_REORDER_DELAY+1; i++)\n st->pts_buffer[i]= AV_NOPTS_VALUE;\n st->reference_dts = AV_NOPTS_VALUE;\n st->sample_aspect_ratio = (AVRational){0,1};\n s->streams[s->nb_streams++] = st;\n return st;\n}'] |
34,374 | 0 | https://github.com/openssl/openssl/blob/ff64702b3d83d4c77756e0fd7b624e2165dbbdf0/crypto/packet.c/#L52 | int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
{
if (!ossl_assert(pkt->subs != NULL && len != 0))
return 0;
if (pkt->maxsize - pkt->written < len)
return 0;
if (pkt->buf != NULL && (pkt->buf->length - pkt->written < len)) {
size_t newlen;
size_t reflen;
reflen = (len > pkt->buf->length) ? len : pkt->buf->length;
if (reflen > SIZE_MAX / 2) {
newlen = SIZE_MAX;
} else {
newlen = reflen * 2;
if (newlen < DEFAULT_BUF_SIZE)
newlen = DEFAULT_BUF_SIZE;
}
if (BUF_MEM_grow(pkt->buf, newlen) == 0)
return 0;
}
if (allocbytes != NULL)
*allocbytes = WPACKET_get_curr(pkt);
return 1;
} | ['EXT_RETURN tls_construct_stoc_use_srtp(SSL *s, WPACKET *pkt,\n unsigned int context, X509 *x,\n size_t chainidx)\n{\n if (s->srtp_profile == NULL)\n return EXT_RETURN_NOT_SENT;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_use_srtp)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u16(pkt, 2)\n || !WPACKET_put_bytes_u16(pkt, s->srtp_profile->id)\n || !WPACKET_put_bytes_u8(pkt, 0)\n || !WPACKET_close(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_USE_SRTP,\n ERR_R_INTERNAL_ERROR);\n return EXT_RETURN_FAIL;\n }\n return EXT_RETURN_SENT;\n}', 'int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)\n{\n unsigned char *data;\n if (!ossl_assert(size <= sizeof(unsigned int))\n || !WPACKET_allocate_bytes(pkt, size, &data)\n || !put_value(data, val, size))\n return 0;\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n return 0;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!ossl_assert(pkt->subs != NULL && len != 0))\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->buf != NULL && (pkt->buf->length - pkt->written < len)) {\n size_t newlen;\n size_t reflen;\n reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n if (reflen > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = reflen * 2;\n if (newlen < DEFAULT_BUF_SIZE)\n newlen = DEFAULT_BUF_SIZE;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n if (allocbytes != NULL)\n *allocbytes = WPACKET_get_curr(pkt);\n return 1;\n}'] |
34,375 | 0 | https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_lib.c/#L260 | static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
} | ['int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,\n BIGNUM *Xp1, BIGNUM *Xp2,\n const BIGNUM *Xp,\n const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb)\n{\n int ret = 0;\n BN_CTX_start(ctx);\n if (Xp1 == NULL)\n Xp1 = BN_CTX_get(ctx);\n if (Xp2 == NULL)\n Xp2 = BN_CTX_get(ctx);\n if (Xp1 == NULL || Xp2 == NULL)\n goto error;\n if (!BN_priv_rand(Xp1, 101, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))\n goto error;\n if (!BN_priv_rand(Xp2, 101, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))\n goto error;\n if (!BN_X931_derive_prime_ex(p, p1, p2, Xp, Xp1, Xp2, e, ctx, cb))\n goto error;\n ret = 1;\n error:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(PRIVATE, rnd, bits, top, bottom);\n}', 'static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom)\n{\n unsigned char *buf = NULL;\n int b, ret = 0, bit, bytes, mask;\n if (bits == 0) {\n if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)\n goto toosmall;\n BN_zero(rnd);\n return 1;\n }\n if (bits < 0 || (bits == 1 && top > 0))\n goto toosmall;\n bytes = (bits + 7) / 8;\n bit = (bits - 1) % 8;\n mask = 0xff << (bit + 1);\n buf = OPENSSL_malloc(bytes);\n if (buf == NULL) {\n BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n b = flag == NORMAL ? RAND_bytes(buf, bytes) : RAND_priv_bytes(buf, bytes);\n if (b <= 0)\n goto err;\n if (flag == TESTING) {\n int i;\n unsigned char c;\n for (i = 0; i < bytes; i++) {\n if (RAND_bytes(&c, 1) <= 0)\n goto err;\n if (c >= 128 && i > 0)\n buf[i] = buf[i - 1];\n else if (c < 42)\n buf[i] = 0;\n else if (c < 84)\n buf[i] = 255;\n }\n }\n if (top >= 0) {\n if (top) {\n if (bit == 0) {\n buf[0] = 1;\n buf[1] |= 0x80;\n } else {\n buf[0] |= (3 << (bit - 1));\n }\n } else {\n buf[0] |= (1 << bit);\n }\n }\n buf[0] &= ~mask;\n if (bottom)\n buf[bytes - 1] |= 1;\n if (!BN_bin2bn(buf, bytes, rnd))\n goto err;\n ret = 1;\n err:\n OPENSSL_clear_free(buf, bytes);\n bn_check_top(rnd);\n return ret;\ntoosmall:\n BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n return 0;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}'] |
34,376 | 0 | https://github.com/openssl/openssl/blob/a26d8be9531862af09c69b9704d219f1768d3d0e/crypto/bio/b_print.c/#L425 | static int
_dopr(char **sbuffer,
char **buffer,
size_t *maxlen,
size_t *retlen, int *truncated, const char *format, va_list args)
{
char ch;
LLONG value;
LDOUBLE fvalue;
char *strvalue;
int min;
int max;
int state;
int flags;
int cflags;
size_t currlen;
state = DP_S_DEFAULT;
flags = currlen = cflags = min = 0;
max = -1;
ch = *format++;
while (state != DP_S_DONE) {
if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
state = DP_S_DONE;
switch (state) {
case DP_S_DEFAULT:
if (ch == '%')
state = DP_S_FLAGS;
else
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))
return 0;
ch = *format++;
break;
case DP_S_FLAGS:
switch (ch) {
case '-':
flags |= DP_F_MINUS;
ch = *format++;
break;
case '+':
flags |= DP_F_PLUS;
ch = *format++;
break;
case ' ':
flags |= DP_F_SPACE;
ch = *format++;
break;
case '#':
flags |= DP_F_NUM;
ch = *format++;
break;
case '0':
flags |= DP_F_ZERO;
ch = *format++;
break;
default:
state = DP_S_MIN;
break;
}
break;
case DP_S_MIN:
if (isdigit((unsigned char)ch)) {
min = 10 * min + char_to_int(ch);
ch = *format++;
} else if (ch == '*') {
min = va_arg(args, int);
ch = *format++;
state = DP_S_DOT;
} else
state = DP_S_DOT;
break;
case DP_S_DOT:
if (ch == '.') {
state = DP_S_MAX;
ch = *format++;
} else
state = DP_S_MOD;
break;
case DP_S_MAX:
if (isdigit((unsigned char)ch)) {
if (max < 0)
max = 0;
max = 10 * max + char_to_int(ch);
ch = *format++;
} else if (ch == '*') {
max = va_arg(args, int);
ch = *format++;
state = DP_S_MOD;
} else
state = DP_S_MOD;
break;
case DP_S_MOD:
switch (ch) {
case 'h':
cflags = DP_C_SHORT;
ch = *format++;
break;
case 'l':
if (*format == 'l') {
cflags = DP_C_LLONG;
format++;
} else
cflags = DP_C_LONG;
ch = *format++;
break;
case 'q':
cflags = DP_C_LLONG;
ch = *format++;
break;
case 'L':
cflags = DP_C_LDOUBLE;
ch = *format++;
break;
default:
break;
}
state = DP_S_CONV;
break;
case DP_S_CONV:
switch (ch) {
case 'd':
case 'i':
switch (cflags) {
case DP_C_SHORT:
value = (short int)va_arg(args, int);
break;
case DP_C_LONG:
value = va_arg(args, long int);
break;
case DP_C_LLONG:
value = va_arg(args, LLONG);
break;
default:
value = va_arg(args, int);
break;
}
if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, 10, min,
max, flags))
return 0;
break;
case 'X':
flags |= DP_F_UP;
case 'x':
case 'o':
case 'u':
flags |= DP_F_UNSIGNED;
switch (cflags) {
case DP_C_SHORT:
value = (unsigned short int)va_arg(args, unsigned int);
break;
case DP_C_LONG:
value = (LLONG) va_arg(args, unsigned long int);
break;
case DP_C_LLONG:
value = va_arg(args, unsigned LLONG);
break;
default:
value = (LLONG) va_arg(args, unsigned int);
break;
}
if (!fmtint(sbuffer, buffer, &currlen, maxlen, value,
ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
min, max, flags))
return 0;
break;
case 'f':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,
flags))
return 0;
break;
case 'E':
flags |= DP_F_UP;
case 'e':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
break;
case 'G':
flags |= DP_F_UP;
case 'g':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
break;
case 'c':
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen,
va_arg(args, int)))
return 0;
break;
case 's':
strvalue = va_arg(args, char *);
if (max < 0) {
if (buffer)
max = INT_MAX;
else
max = *maxlen;
}
if (!fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
flags, min, max))
return 0;
break;
case 'p':
value = (size_t)va_arg(args, void *);
if (!fmtint(sbuffer, buffer, &currlen, maxlen,
value, 16, min, max, flags | DP_F_NUM))
return 0;
break;
case 'n':
if (cflags == DP_C_SHORT) {
short int *num;
num = va_arg(args, short int *);
*num = currlen;
} else if (cflags == DP_C_LONG) {
long int *num;
num = va_arg(args, long int *);
*num = (long int)currlen;
} else if (cflags == DP_C_LLONG) {
LLONG *num;
num = va_arg(args, LLONG *);
*num = (LLONG) currlen;
} else {
int *num;
num = va_arg(args, int *);
*num = currlen;
}
break;
case '%':
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))
return 0;
break;
case 'w':
ch = *format++;
break;
default:
break;
}
ch = *format++;
state = DP_S_DEFAULT;
flags = cflags = min = 0;
max = -1;
break;
case DP_S_DONE:
break;
default:
break;
}
}
*truncated = (currlen > *maxlen - 1);
if (*truncated)
currlen = *maxlen - 1;
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0'))
return 0;
*retlen = currlen - 1;
return 1;
} | ['long BIO_debug_callback(BIO *bio, int cmd, const char *argp,\n int argi, long argl, long ret)\n{\n BIO *b;\n char buf[256];\n char *p;\n long r = 1;\n int len;\n size_t p_maxlen;\n if (BIO_CB_RETURN & cmd)\n r = ret;\n len = BIO_snprintf(buf,sizeof buf,"BIO[%p]: ",(void *)bio);\n p = buf + len;\n p_maxlen = sizeof(buf) - len;\n switch (cmd) {\n case BIO_CB_FREE:\n BIO_snprintf(p, p_maxlen, "Free - %s\\n", bio->method->name);\n break;\n case BIO_CB_READ:\n if (bio->method->type & BIO_TYPE_DESCRIPTOR)\n BIO_snprintf(p, p_maxlen, "read(%d,%lu) - %s fd=%d\\n",\n bio->num, (unsigned long)argi,\n bio->method->name, bio->num);\n else\n BIO_snprintf(p, p_maxlen, "read(%d,%lu) - %s\\n",\n bio->num, (unsigned long)argi, bio->method->name);\n break;\n case BIO_CB_WRITE:\n if (bio->method->type & BIO_TYPE_DESCRIPTOR)\n BIO_snprintf(p, p_maxlen, "write(%d,%lu) - %s fd=%d\\n",\n bio->num, (unsigned long)argi,\n bio->method->name, bio->num);\n else\n BIO_snprintf(p, p_maxlen, "write(%d,%lu) - %s\\n",\n bio->num, (unsigned long)argi, bio->method->name);\n break;\n case BIO_CB_PUTS:\n BIO_snprintf(p, p_maxlen, "puts() - %s\\n", bio->method->name);\n break;\n case BIO_CB_GETS:\n BIO_snprintf(p, p_maxlen, "gets(%lu) - %s\\n", (unsigned long)argi,\n bio->method->name);\n break;\n case BIO_CB_CTRL:\n BIO_snprintf(p, p_maxlen, "ctrl(%lu) - %s\\n", (unsigned long)argi,\n bio->method->name);\n break;\n case BIO_CB_RETURN | BIO_CB_READ:\n BIO_snprintf(p, p_maxlen, "read return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_WRITE:\n BIO_snprintf(p, p_maxlen, "write return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_GETS:\n BIO_snprintf(p, p_maxlen, "gets return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_PUTS:\n BIO_snprintf(p, p_maxlen, "puts return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_CTRL:\n BIO_snprintf(p, p_maxlen, "ctrl return %ld\\n", ret);\n break;\n default:\n BIO_snprintf(p, p_maxlen, "bio callback - unknown type (%d)\\n", cmd);\n break;\n }\n b = (BIO *)bio->cb_arg;\n if (b != NULL)\n BIO_write(b, buf, strlen(buf));\n#if !defined(OPENSSL_NO_STDIO)\n else\n fputs(buf, stderr);\n#endif\n return (r);\n}', 'int BIO_snprintf(char *buf, size_t n, const char *format, ...)\n{\n va_list args;\n int ret;\n va_start(args, format);\n ret = BIO_vsnprintf(buf, n, format, args);\n va_end(args);\n return (ret);\n}', 'int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)\n{\n size_t retlen;\n int truncated;\n if(!_dopr(&buf, NULL, &n, &retlen, &truncated, format, args))\n return -1;\n if (truncated)\n return -1;\n else\n return (retlen <= INT_MAX) ? (int)retlen : -1;\n}', "static int\n_dopr(char **sbuffer,\n char **buffer,\n size_t *maxlen,\n size_t *retlen, int *truncated, const char *format, va_list args)\n{\n char ch;\n LLONG value;\n LDOUBLE fvalue;\n char *strvalue;\n int min;\n int max;\n int state;\n int flags;\n int cflags;\n size_t currlen;\n state = DP_S_DEFAULT;\n flags = currlen = cflags = min = 0;\n max = -1;\n ch = *format++;\n while (state != DP_S_DONE) {\n if (ch == '\\0' || (buffer == NULL && currlen >= *maxlen))\n state = DP_S_DONE;\n switch (state) {\n case DP_S_DEFAULT:\n if (ch == '%')\n state = DP_S_FLAGS;\n else\n if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))\n return 0;\n ch = *format++;\n break;\n case DP_S_FLAGS:\n switch (ch) {\n case '-':\n flags |= DP_F_MINUS;\n ch = *format++;\n break;\n case '+':\n flags |= DP_F_PLUS;\n ch = *format++;\n break;\n case ' ':\n flags |= DP_F_SPACE;\n ch = *format++;\n break;\n case '#':\n flags |= DP_F_NUM;\n ch = *format++;\n break;\n case '0':\n flags |= DP_F_ZERO;\n ch = *format++;\n break;\n default:\n state = DP_S_MIN;\n break;\n }\n break;\n case DP_S_MIN:\n if (isdigit((unsigned char)ch)) {\n min = 10 * min + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n min = va_arg(args, int);\n ch = *format++;\n state = DP_S_DOT;\n } else\n state = DP_S_DOT;\n break;\n case DP_S_DOT:\n if (ch == '.') {\n state = DP_S_MAX;\n ch = *format++;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MAX:\n if (isdigit((unsigned char)ch)) {\n if (max < 0)\n max = 0;\n max = 10 * max + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n max = va_arg(args, int);\n ch = *format++;\n state = DP_S_MOD;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MOD:\n switch (ch) {\n case 'h':\n cflags = DP_C_SHORT;\n ch = *format++;\n break;\n case 'l':\n if (*format == 'l') {\n cflags = DP_C_LLONG;\n format++;\n } else\n cflags = DP_C_LONG;\n ch = *format++;\n break;\n case 'q':\n cflags = DP_C_LLONG;\n ch = *format++;\n break;\n case 'L':\n cflags = DP_C_LDOUBLE;\n ch = *format++;\n break;\n default:\n break;\n }\n state = DP_S_CONV;\n break;\n case DP_S_CONV:\n switch (ch) {\n case 'd':\n case 'i':\n switch (cflags) {\n case DP_C_SHORT:\n value = (short int)va_arg(args, int);\n break;\n case DP_C_LONG:\n value = va_arg(args, long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, LLONG);\n break;\n default:\n value = va_arg(args, int);\n break;\n }\n if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, 10, min,\n max, flags))\n return 0;\n break;\n case 'X':\n flags |= DP_F_UP;\n case 'x':\n case 'o':\n case 'u':\n flags |= DP_F_UNSIGNED;\n switch (cflags) {\n case DP_C_SHORT:\n value = (unsigned short int)va_arg(args, unsigned int);\n break;\n case DP_C_LONG:\n value = (LLONG) va_arg(args, unsigned long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, unsigned LLONG);\n break;\n default:\n value = (LLONG) va_arg(args, unsigned int);\n break;\n }\n if (!fmtint(sbuffer, buffer, &currlen, maxlen, value,\n ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),\n min, max, flags))\n return 0;\n break;\n case 'f':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,\n flags))\n return 0;\n break;\n case 'E':\n flags |= DP_F_UP;\n case 'e':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n break;\n case 'G':\n flags |= DP_F_UP;\n case 'g':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n break;\n case 'c':\n if(!doapr_outch(sbuffer, buffer, &currlen, maxlen,\n va_arg(args, int)))\n return 0;\n break;\n case 's':\n strvalue = va_arg(args, char *);\n if (max < 0) {\n if (buffer)\n max = INT_MAX;\n else\n max = *maxlen;\n }\n if (!fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,\n flags, min, max))\n return 0;\n break;\n case 'p':\n value = (size_t)va_arg(args, void *);\n if (!fmtint(sbuffer, buffer, &currlen, maxlen,\n value, 16, min, max, flags | DP_F_NUM))\n return 0;\n break;\n case 'n':\n if (cflags == DP_C_SHORT) {\n short int *num;\n num = va_arg(args, short int *);\n *num = currlen;\n } else if (cflags == DP_C_LONG) {\n long int *num;\n num = va_arg(args, long int *);\n *num = (long int)currlen;\n } else if (cflags == DP_C_LLONG) {\n LLONG *num;\n num = va_arg(args, LLONG *);\n *num = (LLONG) currlen;\n } else {\n int *num;\n num = va_arg(args, int *);\n *num = currlen;\n }\n break;\n case '%':\n if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))\n return 0;\n break;\n case 'w':\n ch = *format++;\n break;\n default:\n break;\n }\n ch = *format++;\n state = DP_S_DEFAULT;\n flags = cflags = min = 0;\n max = -1;\n break;\n case DP_S_DONE:\n break;\n default:\n break;\n }\n }\n *truncated = (currlen > *maxlen - 1);\n if (*truncated)\n currlen = *maxlen - 1;\n if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\\0'))\n return 0;\n *retlen = currlen - 1;\n return 1;\n}"] |
34,377 | 0 | https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L271 | static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
} | ['static void char2_field_tests(void)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *p, *a, *b;\n EC_GROUP *group;\n EC_GROUP *C2_K163 = NULL, *C2_K233 = NULL, *C2_K283 = NULL, *C2_K409 =\n NULL, *C2_K571 = NULL;\n EC_GROUP *C2_B163 = NULL, *C2_B233 = NULL, *C2_B283 = NULL, *C2_B409 =\n NULL, *C2_B571 = NULL;\n EC_POINT *P, *Q, *R;\n BIGNUM *x, *y, *z, *cof, *yplusone;\n unsigned char buf[100];\n size_t i, len;\n int k;\n ctx = BN_CTX_new();\n if (!ctx)\n ABORT;\n p = BN_new();\n a = BN_new();\n b = BN_new();\n if (p == NULL || a == NULL || b == NULL)\n ABORT;\n if (!BN_hex2bn(&p, "13"))\n ABORT;\n if (!BN_hex2bn(&a, "3"))\n ABORT;\n if (!BN_hex2bn(&b, "1"))\n ABORT;\n group = EC_GROUP_new(EC_GF2m_simple_method());\n if (!group)\n ABORT;\n if (!EC_GROUP_set_curve_GF2m(group, p, a, b, ctx))\n ABORT;\n {\n EC_GROUP *tmp;\n tmp = EC_GROUP_new(EC_GROUP_method_of(group));\n if (!tmp)\n ABORT;\n if (!EC_GROUP_copy(tmp, group))\n ABORT;\n EC_GROUP_free(group);\n group = tmp;\n }\n if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx))\n ABORT;\n fprintf(stdout,\n "Curve defined by Weierstrass equation\\n y^2 + x*y = x^3 + a*x^2 + b (mod 0x");\n BN_print_fp(stdout, p);\n fprintf(stdout, ")\\n a = 0x");\n BN_print_fp(stdout, a);\n fprintf(stdout, "\\n b = 0x");\n BN_print_fp(stdout, b);\n fprintf(stdout, "\\n(0x... means binary polynomial)\\n");\n P = EC_POINT_new(group);\n Q = EC_POINT_new(group);\n R = EC_POINT_new(group);\n if (!P || !Q || !R)\n ABORT;\n if (!EC_POINT_set_to_infinity(group, P))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, P))\n ABORT;\n buf[0] = 0;\n if (!EC_POINT_oct2point(group, Q, buf, 1, ctx))\n ABORT;\n if (!EC_POINT_add(group, P, P, Q, ctx))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, P))\n ABORT;\n x = BN_new();\n y = BN_new();\n z = BN_new();\n cof = BN_new();\n yplusone = BN_new();\n if (x == NULL || y == NULL || z == NULL || cof == NULL || yplusone == NULL)\n ABORT;\n if (!BN_hex2bn(&x, "6"))\n ABORT;\n# ifdef OPENSSL_EC_BIN_PT_COMP\n if (!EC_POINT_set_compressed_coordinates_GF2m(group, Q, x, 1, ctx))\n ABORT;\n# else\n if (!BN_hex2bn(&y, "8"))\n ABORT;\n if (!EC_POINT_set_affine_coordinates_GF2m(group, Q, x, y, ctx))\n ABORT;\n# endif\n if (EC_POINT_is_on_curve(group, Q, ctx) <= 0) {\n# ifdef OPENSSL_EC_BIN_PT_COMP\n if (!EC_POINT_get_affine_coordinates_GF2m(group, Q, x, y, ctx))\n ABORT;\n# endif\n fprintf(stderr, "Point is not on curve: x = 0x");\n BN_print_fp(stderr, x);\n fprintf(stderr, ", y = 0x");\n BN_print_fp(stderr, y);\n fprintf(stderr, "\\n");\n ABORT;\n }\n fprintf(stdout, "A cyclic subgroup:\\n");\n k = 100;\n do {\n if (k-- == 0)\n ABORT;\n if (EC_POINT_is_at_infinity(group, P))\n fprintf(stdout, " point at infinity\\n");\n else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group, P, x, y, ctx))\n ABORT;\n fprintf(stdout, " x = 0x");\n BN_print_fp(stdout, x);\n fprintf(stdout, ", y = 0x");\n BN_print_fp(stdout, y);\n fprintf(stdout, "\\n");\n }\n if (!EC_POINT_copy(R, P))\n ABORT;\n if (!EC_POINT_add(group, P, P, Q, ctx))\n ABORT;\n }\n while (!EC_POINT_is_at_infinity(group, P));\n if (!EC_POINT_add(group, P, Q, R, ctx))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, P))\n ABORT;\n# ifdef OPENSSL_EC_BIN_PT_COMP\n len =\n EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf,\n sizeof buf, ctx);\n if (len == 0)\n ABORT;\n if (!EC_POINT_oct2point(group, P, buf, len, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, P, Q, ctx))\n ABORT;\n fprintf(stdout, "Generator as octet string, compressed form:\\n ");\n for (i = 0; i < len; i++)\n fprintf(stdout, "%02X", buf[i]);\n# endif\n len =\n EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf,\n sizeof buf, ctx);\n if (len == 0)\n ABORT;\n if (!EC_POINT_oct2point(group, P, buf, len, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, P, Q, ctx))\n ABORT;\n fprintf(stdout, "\\nGenerator as octet string, uncompressed form:\\n ");\n for (i = 0; i < len; i++)\n fprintf(stdout, "%02X", buf[i]);\n# ifdef OPENSSL_EC_BIN_PT_COMP\n len =\n EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf,\n ctx);\n if (len == 0)\n ABORT;\n if (!EC_POINT_oct2point(group, P, buf, len, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, P, Q, ctx))\n ABORT;\n fprintf(stdout, "\\nGenerator as octet string, hybrid form:\\n ");\n for (i = 0; i < len; i++)\n fprintf(stdout, "%02X", buf[i]);\n# endif\n fprintf(stdout, "\\n");\n if (!EC_POINT_invert(group, P, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, P, R, ctx))\n ABORT;\n CHAR2_CURVE_TEST\n ("NIST curve K-163",\n "0800000000000000000000000000000000000000C9",\n "1",\n "1",\n "02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8",\n "0289070FB05D38FF58321F2E800536D538CCDAA3D9",\n 1, "04000000000000000000020108A2E0CC0D99F8A5EF", "2", 163, C2_K163);\n CHAR2_CURVE_TEST\n ("NIST curve B-163",\n "0800000000000000000000000000000000000000C9",\n "1",\n "020A601907B8C953CA1481EB10512F78744A3205FD",\n "03F0EBA16286A2D57EA0991168D4994637E8343E36",\n "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1",\n 1, "040000000000000000000292FE77E70C12A4234C33", "2", 163, C2_B163);\n CHAR2_CURVE_TEST\n ("NIST curve K-233",\n "020000000000000000000000000000000000000004000000000000000001",\n "0",\n "1",\n "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126",\n "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3",\n 0,\n "008000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF",\n "4", 233, C2_K233);\n CHAR2_CURVE_TEST\n ("NIST curve B-233",\n "020000000000000000000000000000000000000004000000000000000001",\n "000000000000000000000000000000000000000000000000000000000001",\n "0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD",\n "00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B",\n "01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052",\n 1,\n "01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7",\n "2", 233, C2_B233);\n CHAR2_CURVE_TEST\n ("NIST curve K-283",\n "0800000000000000000000000000000000000000000000000000000000000000000010A1",\n "0",\n "1",\n "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836",\n "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259",\n 0,\n "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61",\n "4", 283, C2_K283);\n CHAR2_CURVE_TEST\n ("NIST curve B-283",\n "0800000000000000000000000000000000000000000000000000000000000000000010A1",\n "000000000000000000000000000000000000000000000000000000000000000000000001",\n "027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5",\n "05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053",\n "03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4",\n 1,\n "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307",\n "2", 283, C2_B283);\n CHAR2_CURVE_TEST\n ("NIST curve K-409",\n "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001",\n "0",\n "1",\n "0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746",\n "01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B",\n 1,\n "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF",\n "4", 409, C2_K409);\n CHAR2_CURVE_TEST\n ("NIST curve B-409",\n "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001",\n "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",\n "0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F",\n "015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7",\n "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706",\n 1,\n "010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173",\n "2", 409, C2_B409);\n CHAR2_CURVE_TEST\n ("NIST curve K-571",\n "80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425",\n "0",\n "1",\n "026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972",\n "0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3",\n 0,\n "020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001",\n "4", 571, C2_K571);\n CHAR2_CURVE_TEST\n ("NIST curve B-571",\n "80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425",\n "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",\n "02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A",\n "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19",\n "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B",\n 1,\n "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47",\n "2", 571, C2_B571);\n if (!EC_POINT_copy(Q, P))\n ABORT;\n if (EC_POINT_is_at_infinity(group, Q))\n ABORT;\n if (!EC_POINT_dbl(group, P, P, ctx))\n ABORT;\n if (EC_POINT_is_on_curve(group, P, ctx) <= 0)\n ABORT;\n if (!EC_POINT_invert(group, Q, ctx))\n ABORT;\n if (!EC_POINT_add(group, R, P, Q, ctx))\n ABORT;\n if (!EC_POINT_add(group, R, R, Q, ctx))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, R))\n ABORT;\n {\n const EC_POINT *points[3];\n const BIGNUM *scalars[3];\n if (EC_POINT_is_at_infinity(group, Q))\n ABORT;\n points[0] = Q;\n points[1] = Q;\n points[2] = Q;\n if (!BN_add(y, z, BN_value_one()))\n ABORT;\n if (BN_is_odd(y))\n ABORT;\n if (!BN_rshift1(y, y))\n ABORT;\n scalars[0] = y;\n scalars[1] = y;\n fprintf(stdout, "combined multiplication ...");\n fflush(stdout);\n if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))\n ABORT;\n if (!EC_POINTs_mul(group, R, z, 2, points, scalars, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, P, R, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, R, Q, ctx))\n ABORT;\n fprintf(stdout, ".");\n fflush(stdout);\n if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0))\n ABORT;\n if (!BN_add(z, z, y))\n ABORT;\n BN_set_negative(z, 1);\n scalars[0] = y;\n scalars[1] = z;\n if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, P))\n ABORT;\n fprintf(stdout, ".");\n fflush(stdout);\n if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0))\n ABORT;\n if (!BN_add(z, x, y))\n ABORT;\n BN_set_negative(z, 1);\n scalars[0] = x;\n scalars[1] = y;\n scalars[2] = z;\n if (!EC_POINTs_mul(group, P, NULL, 3, points, scalars, ctx))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, P))\n ABORT;\n fprintf(stdout, " ok\\n\\n");\n }\n BN_CTX_free(ctx);\n BN_free(p);\n BN_free(a);\n BN_free(b);\n EC_GROUP_free(group);\n EC_POINT_free(P);\n EC_POINT_free(Q);\n EC_POINT_free(R);\n BN_free(x);\n BN_free(y);\n BN_free(z);\n BN_free(cof);\n BN_free(yplusone);\n EC_GROUP_free(C2_K163);\n EC_GROUP_free(C2_B163);\n EC_GROUP_free(C2_K233);\n EC_GROUP_free(C2_B233);\n EC_GROUP_free(C2_K283);\n EC_GROUP_free(C2_B283);\n EC_GROUP_free(C2_K409);\n EC_GROUP_free(C2_B409);\n EC_GROUP_free(C2_K571);\n EC_GROUP_free(C2_B571);\n}', "int BN_hex2bn(BIGNUM **bn, const char *a)\n{\n BIGNUM *ret = NULL;\n BN_ULONG l = 0;\n int neg = 0, h, m, i, j, k, c;\n int num;\n if ((a == NULL) || (*a == '\\0'))\n return (0);\n if (*a == '-') {\n neg = 1;\n a++;\n }\n for (i = 0; i <= (INT_MAX/4) && isxdigit((unsigned char)a[i]); i++)\n continue;\n if (i == 0 || i > INT_MAX/4)\n goto err;\n num = i + neg;\n if (bn == NULL)\n return (num);\n if (*bn == NULL) {\n if ((ret = BN_new()) == NULL)\n return (0);\n } else {\n ret = *bn;\n BN_zero(ret);\n }\n if (bn_expand(ret, i * 4) == NULL)\n goto err;\n j = i;\n m = 0;\n h = 0;\n while (j > 0) {\n m = ((BN_BYTES * 2) <= j) ? (BN_BYTES * 2) : j;\n l = 0;\n for (;;) {\n c = a[j - m];\n k = OPENSSL_hexchar2int(c);\n if (k < 0)\n k = 0;\n l = (l << 4) | k;\n if (--m <= 0) {\n ret->d[h++] = l;\n break;\n }\n }\n j -= (BN_BYTES * 2);\n }\n ret->top = h;\n bn_correct_top(ret);\n *bn = ret;\n bn_check_top(ret);\n if (ret->top != 0)\n ret->neg = neg;\n return (num);\n err:\n if (*bn == NULL)\n BN_free(ret);\n return (0);\n}", 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}'] |
34,378 | 0 | https://github.com/libav/libav/blob/60728e8bab8d2a5f6bbb4baa7d53142dbc6047ed/libavformat/utils.c/#L2629 | void avformat_free_context(AVFormatContext *s)
{
int i, j;
AVStream *st;
av_opt_free(s);
if (s->iformat && s->iformat->priv_class && s->priv_data)
av_opt_free(s->priv_data);
for (i = 0; i < s->nb_streams; i++) {
st = s->streams[i];
for (j = 0; j < st->nb_side_data; j++)
av_freep(&st->side_data[j].data);
av_freep(&st->side_data);
st->nb_side_data = 0;
if (st->parser) {
av_parser_close(st->parser);
}
if (st->attached_pic.data)
av_free_packet(&st->attached_pic);
av_dict_free(&st->metadata);
av_freep(&st->probe_data.buf);
av_free(st->index_entries);
av_free(st->codec->extradata);
av_free(st->codec->subtitle_header);
av_free(st->codec);
av_free(st->priv_data);
av_free(st->info);
av_free(st);
}
for (i = s->nb_programs - 1; i >= 0; i--) {
av_dict_free(&s->programs[i]->metadata);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
av_freep(&s->programs);
av_freep(&s->priv_data);
while (s->nb_chapters--) {
av_dict_free(&s->chapters[s->nb_chapters]->metadata);
av_free(s->chapters[s->nb_chapters]);
}
av_freep(&s->chapters);
av_dict_free(&s->metadata);
av_freep(&s->streams);
av_freep(&s->internal);
av_free(s);
} | ['static int hls_write_trailer(struct AVFormatContext *s)\n{\n HLSContext *hls = s->priv_data;\n AVFormatContext *oc = hls->avf;\n av_write_trailer(oc);\n avio_closep(&oc->pb);\n avformat_free_context(oc);\n av_free(hls->basename);\n append_entry(hls, hls->duration);\n hls_window(s, 1);\n free_entries(hls);\n avio_close(hls->pb);\n return 0;\n}', 'int avio_closep(AVIOContext **s)\n{\n int ret = avio_close(*s);\n *s = NULL;\n return ret;\n}', 'int avio_close(AVIOContext *s)\n{\n URLContext *h;\n if (!s)\n return 0;\n avio_flush(s);\n h = s->opaque;\n av_freep(&s->buffer);\n av_free(s);\n return ffurl_close(h);\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i, j;\n AVStream *st;\n av_opt_free(s);\n if (s->iformat && s->iformat->priv_class && s->priv_data)\n av_opt_free(s->priv_data);\n for (i = 0; i < s->nb_streams; i++) {\n st = s->streams[i];\n for (j = 0; j < st->nb_side_data; j++)\n av_freep(&st->side_data[j].data);\n av_freep(&st->side_data);\n st->nb_side_data = 0;\n if (st->parser) {\n av_parser_close(st->parser);\n }\n if (st->attached_pic.data)\n av_free_packet(&st->attached_pic);\n av_dict_free(&st->metadata);\n av_freep(&st->probe_data.buf);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec->subtitle_header);\n av_free(st->codec);\n av_free(st->priv_data);\n av_free(st->info);\n av_free(st);\n }\n for (i = s->nb_programs - 1; i >= 0; i--) {\n av_dict_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n av_freep(&s->priv_data);\n while (s->nb_chapters--) {\n av_dict_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_dict_free(&s->metadata);\n av_freep(&s->streams);\n av_freep(&s->internal);\n av_free(s);\n}'] |
34,379 | 0 | https://github.com/openssl/openssl/blob/9b67b4b3caf071f490b95128f5dd44d9ce52032d/crypto/buffer/buffer.c/#L141 | char *BUF_strdup(const char *str)
{
char *ret;
int n;
if (str == NULL) return(NULL);
n=strlen(str);
ret=Malloc(n+1);
if (ret == NULL)
{
BUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE);
return(NULL);
}
memcpy(ret,str,n+1);
return(ret);
} | ['int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,\n\t STACK_OF(CONF_VALUE) **extlist)\n{\n\tchar *strtmp;\n\tint ret;\n\tif(!aint) return 1;\n\tif(!(strtmp = i2s_ASN1_INTEGER(NULL, aint))) return 0;\n\tret = X509V3_add_value(name, strtmp, extlist);\n\tFree(strtmp);\n\treturn ret;\n}', 'char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, ASN1_INTEGER *a)\n{\n\tBIGNUM *bntmp = NULL;\n\tchar *strtmp = NULL;\n\tif(!a) return NULL;\n\tif(!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) ||\n\t !(strtmp = BN_bn2dec(bntmp)) )\n\t\tX509V3err(X509V3_F_I2S_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);\n\tBN_free(bntmp);\n\treturn strtmp;\n}', 'int X509V3_add_value(const char *name, const char *value,\n\t\t\t\t\t\tSTACK_OF(CONF_VALUE) **extlist)\n{\n\tCONF_VALUE *vtmp = NULL;\n\tchar *tname = NULL, *tvalue = NULL;\n\tif(name && !(tname = BUF_strdup(name))) goto err;\n\tif(value && !(tvalue = BUF_strdup(value))) goto err;;\n\tif(!(vtmp = (CONF_VALUE *)Malloc(sizeof(CONF_VALUE)))) goto err;\n\tif(!*extlist && !(*extlist = sk_CONF_VALUE_new(NULL))) goto err;\n\tvtmp->section = NULL;\n\tvtmp->name = tname;\n\tvtmp->value = tvalue;\n\tif(!sk_CONF_VALUE_push(*extlist, vtmp)) goto err;\n\treturn 1;\n\terr:\n\tX509V3err(X509V3_F_X509V3_ADD_VALUE,ERR_R_MALLOC_FAILURE);\n\tif(vtmp) Free(vtmp);\n\tif(tname) Free(tname);\n\tif(tvalue) Free(tvalue);\n\treturn 0;\n}', 'char *BUF_strdup(const char *str)\n\t{\n\tchar *ret;\n\tint n;\n\tif (str == NULL) return(NULL);\n\tn=strlen(str);\n\tret=Malloc(n+1);\n\tif (ret == NULL)\n\t\t{\n\t\tBUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tmemcpy(ret,str,n+1);\n\treturn(ret);\n\t}'] |
34,380 | 0 | https://github.com/openssl/openssl/blob/a5a95f8d65c2c616ebee13ae4b33eacde34bb2d3/apps/srp.c/#L63 | static void print_entry(CA_DB *db, int indx, int verbose, char *s)
{
if (indx >= 0 && verbose) {
int j;
char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);
BIO_printf(bio_err, "%s \"%s\"\n", s, pp[DB_srpid]);
for (j = 0; j < DB_NUMBER; j++) {
BIO_printf(bio_err, " %d = \"%s\"\n", j, pp[j]);
}
}
} | ['static void print_entry(CA_DB *db, int indx, int verbose, char *s)\n{\n if (indx >= 0 && verbose) {\n int j;\n char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);\n BIO_printf(bio_err, "%s \\"%s\\"\\n", s, pp[DB_srpid]);\n for (j = 0; j < DB_NUMBER; j++) {\n BIO_printf(bio_err, " %d = \\"%s\\"\\n", j, pp[j]);\n }\n }\n}', 'DEFINE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING)', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n if (st == NULL || i < 0 || i >= st->num)\n return NULL;\n return (void *)st->data[i];\n}'] |
34,381 | 0 | https://github.com/openssl/openssl/blob/e334d78b87517652cc34825aff7b6fc7be9a1e83/crypto/lhash/lhash.c/#L243 | char *lh_delete(LHASH *lh, char *data)
{
unsigned long hash;
LHASH_NODE *nn,**rn;
char *ret;
lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
{
lh->num_no_delete++;
return(NULL);
}
else
{
nn= *rn;
*rn=nn->next;
ret=nn->data;
Free((char *)nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
contract(lh);
return(ret);
} | ['static int ssl3_get_server_done(SSL *s)\n\t{\n\tint ok,ret=0;\n\tlong n;\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_CR_SRVR_DONE_A,\n\t\tSSL3_ST_CR_SRVR_DONE_B,\n\t\tSSL3_MT_SERVER_DONE,\n\t\t30,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\tif (n > 0)\n\t\t{\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_DONE,SSL_R_LENGTH_MISMATCH);\n\t\t}\n\tret=1;\n\treturn(ret);\n\t}', 'long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)\n\t{\n\tunsigned char *p;\n\tunsigned long l;\n\tlong n;\n\tint i,al;\n\tif (s->s3->tmp.reuse_message)\n\t\t{\n\t\ts->s3->tmp.reuse_message=0;\n\t\tif ((mt >= 0) && (s->s3->tmp.message_type != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t*ok=1;\n\t\treturn((int)s->s3->tmp.message_size);\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tif (s->state == st1)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],\n\t\t\t\t 4-s->init_num);\n\t\tif (i < (4-s->init_num))\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\tif ((mt >= 0) && (*p != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\ts->s3->tmp.message_type= *(p++);\n\t\tn2l3(p,l);\n\t\tif (l > (unsigned long)max)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (l && !BUF_MEM_grow(s->init_buf,(int)l))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ts->s3->tmp.message_size=l;\n\t\ts->state=stn;\n\t\ts->init_num=0;\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tn=s->s3->tmp.message_size;\n\tif (n > 0)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n);\n\t\tif (i != (int)n)\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\t}\n\t*ok=1;\n\treturn(n);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\t*ok=0;\n\treturn(-1);\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\tssl3_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,(char *)c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'char *lh_delete(LHASH *lh, char *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tchar *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tFree((char *)nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}'] |
34,382 | 0 | https://github.com/openssl/openssl/blob/ed371b8cbac0d0349667558c061c1ae380cf75eb/crypto/bn/bn_lib.c/#L232 | static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
} | ['static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n const BIGNUM *divisor, BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnum, *wnumtop;\n BN_ULONG d0, d1;\n int num_n, div_n;\n assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);\n bn_check_top(num);\n bn_check_top(divisor);\n bn_check_top(dv);\n bn_check_top(rm);\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n if (!BN_copy(sdiv, divisor))\n goto err;\n norm_shift = bn_left_align(sdiv);\n sdiv->neg = 0;\n if (!(bn_lshift_fixed_top(snum, num, norm_shift)))\n goto err;\n div_n = sdiv->top;\n num_n = snum->top;\n if (num_n <= div_n) {\n if (bn_wexpand(snum, div_n + 1) == NULL)\n goto err;\n memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));\n snum->top = num_n = div_n + 1;\n }\n loop = num_n - div_n;\n wnum = &(snum->d[loop]);\n wnumtop = &(snum->d[num_n - 1]);\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n if (!bn_wexpand(res, loop))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop;\n res->flags |= BN_FLG_FIXED_TOP;\n resp = &(res->d[loop]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n for (i = 0; i < loop; i++, wnumtop--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnumtop, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnumtop[0];\n n1 = wnumtop[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum--;\n l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);\n q -= l0;\n for (l0 = 0 - l0, j = 0; j < div_n; j++)\n tmp->d[j] = sdiv->d[j] & l0;\n l0 = bn_add_words(wnum, wnum, tmp->d, div_n);\n (*wnumtop) += l0;\n assert((*wnumtop) == 0);\n *--resp = q;\n }\n snum->neg = num->neg;\n snum->top = div_n;\n snum->flags |= BN_FLG_FIXED_TOP;\n if (rm != NULL)\n bn_rshift_fixed_top(rm, snum, norm_shift);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'int bn_rshift_fixed_top(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, top, nw;\n unsigned int lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l, m, mask;\n bn_check_top(r);\n bn_check_top(a);\n assert(n >= 0);\n nw = n / BN_BITS2;\n if (nw >= a->top) {\n BN_zero(r);\n return 1;\n }\n rb = (unsigned int)n % BN_BITS2;\n lb = BN_BITS2 - rb;\n lb %= BN_BITS2;\n mask = (BN_ULONG)0 - lb;\n mask |= mask >> 8;\n top = a->top - nw;\n if (r != a && bn_wexpand(r, top) == NULL)\n return 0;\n t = &(r->d[0]);\n f = &(a->d[nw]);\n l = f[0];\n for (i = 0; i < top - 1; i++) {\n m = f[i + 1];\n t[i] = (l >> rb) | ((m << lb) & mask);\n l = m;\n }\n t[i] = l >> rb;\n r->neg = a->neg;\n r->top = top;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}'] |
34,383 | 0 | https://github.com/openssl/openssl/blob/b98ebe0fa5d23fa230f5d9c45c27fbc111bd3129/apps/pkcs12.c/#L872 | int print_attribs (BIO *out, STACK_OF(X509_ATTRIBUTE) *attrlst, char *name)
{
X509_ATTRIBUTE *attr;
ASN1_TYPE *av;
char *value;
int i, attr_nid;
if(!attrlst) {
BIO_printf(out, "%s: <No Attributes>\n", name);
return 1;
}
if(!sk_X509_ATTRIBUTE_num(attrlst)) {
BIO_printf(out, "%s: <Empty Attributes>\n", name);
return 1;
}
BIO_printf(out, "%s\n", name);
for(i = 0; i < sk_X509_ATTRIBUTE_num(attrlst); i++) {
attr = sk_X509_ATTRIBUTE_value(attrlst, i);
attr_nid = OBJ_obj2nid(attr->object);
BIO_printf(out, " ");
if(attr_nid == NID_undef) {
i2a_ASN1_OBJECT (out, attr->object);
BIO_printf(out, ": ");
} else BIO_printf(out, "%s: ", OBJ_nid2ln(attr_nid));
if(sk_ASN1_TYPE_num(attr->value.set)) {
av = sk_ASN1_TYPE_value(attr->value.set, 0);
switch(av->type) {
case V_ASN1_BMPSTRING:
value = uni2asc(av->value.bmpstring->data,
av->value.bmpstring->length);
BIO_printf(out, "%s\n", value);
OPENSSL_free(value);
break;
case V_ASN1_OCTET_STRING:
hex_prin(out, av->value.bit_string->data,
av->value.bit_string->length);
BIO_printf(out, "\n");
break;
case V_ASN1_BIT_STRING:
hex_prin(out, av->value.octet_string->data,
av->value.octet_string->length);
BIO_printf(out, "\n");
break;
default:
BIO_printf(out, "<Unsupported tag %d>\n", av->type);
break;
}
} else BIO_printf(out, "<No Values>\n");
}
return 1;
} | ['int print_attribs (BIO *out, STACK_OF(X509_ATTRIBUTE) *attrlst, char *name)\n{\n\tX509_ATTRIBUTE *attr;\n\tASN1_TYPE *av;\n\tchar *value;\n\tint i, attr_nid;\n\tif(!attrlst) {\n\t\tBIO_printf(out, "%s: <No Attributes>\\n", name);\n\t\treturn 1;\n\t}\n\tif(!sk_X509_ATTRIBUTE_num(attrlst)) {\n\t\tBIO_printf(out, "%s: <Empty Attributes>\\n", name);\n\t\treturn 1;\n\t}\n\tBIO_printf(out, "%s\\n", name);\n\tfor(i = 0; i < sk_X509_ATTRIBUTE_num(attrlst); i++) {\n\t\tattr = sk_X509_ATTRIBUTE_value(attrlst, i);\n\t\tattr_nid = OBJ_obj2nid(attr->object);\n\t\tBIO_printf(out, " ");\n\t\tif(attr_nid == NID_undef) {\n\t\t\ti2a_ASN1_OBJECT (out, attr->object);\n\t\t\tBIO_printf(out, ": ");\n\t\t} else BIO_printf(out, "%s: ", OBJ_nid2ln(attr_nid));\n\t\tif(sk_ASN1_TYPE_num(attr->value.set)) {\n\t\t\tav = sk_ASN1_TYPE_value(attr->value.set, 0);\n\t\t\tswitch(av->type) {\n\t\t\t\tcase V_ASN1_BMPSTRING:\n \t\t\tvalue = uni2asc(av->value.bmpstring->data,\n \t av->value.bmpstring->length);\n\t\t\t\tBIO_printf(out, "%s\\n", value);\n\t\t\t\tOPENSSL_free(value);\n\t\t\t\tbreak;\n\t\t\t\tcase V_ASN1_OCTET_STRING:\n\t\t\t\thex_prin(out, av->value.bit_string->data,\n\t\t\t\t\tav->value.bit_string->length);\n\t\t\t\tBIO_printf(out, "\\n");\n\t\t\t\tbreak;\n\t\t\t\tcase V_ASN1_BIT_STRING:\n\t\t\t\thex_prin(out, av->value.octet_string->data,\n\t\t\t\t\tav->value.octet_string->length);\n\t\t\t\tBIO_printf(out, "\\n");\n\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tBIO_printf(out, "<Unsupported tag %d>\\n", av->type);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} else BIO_printf(out, "<No Values>\\n");\n\t}\n\treturn 1;\n}', 'int sk_num(const STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}', 'char *sk_value(const STACK *st, int i)\n{\n\tif(st == NULL) return NULL;\n\treturn st->data[i];\n}', 'int OBJ_obj2nid(ASN1_OBJECT *a)\n\t{\n\tASN1_OBJECT **op;\n\tADDED_OBJ ad,*adp;\n\tif (a == NULL)\n\t\treturn(NID_undef);\n\tif (a->nid != 0)\n\t\treturn(a->nid);\n\tif (added != NULL)\n\t\t{\n\t\tad.type=ADDED_DATA;\n\t\tad.obj=a;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,&ad);\n\t\tif (adp != NULL) return (adp->obj->nid);\n\t\t}\n\top=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,\n\t\tsizeof(ASN1_OBJECT *),obj_cmp);\n\tif (op == NULL)\n\t\treturn(NID_undef);\n\treturn((*op)->nid);\n\t}', 'int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)\n\t{\n\tchar buf[80];\n\tint i;\n\tif ((a == NULL) || (a->data == NULL))\n\t\treturn(BIO_write(bp,"NULL",4));\n\ti=i2t_ASN1_OBJECT(buf,80,a);\n\tif (i > 80) i=80;\n\tBIO_write(bp,buf,i);\n\treturn(i);\n\t}', 'int BIO_write(BIO *b, const void *in, int inl)\n\t{\n\tint i;\n\tlong (*cb)();\n\tif (b == NULL)\n\t\treturn(0);\n\tcb=b->callback;\n\tif ((b->method == NULL) || (b->method->bwrite == NULL))\n\t\t{\n\t\tBIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD);\n\t\treturn(-2);\n\t\t}\n\tif ((cb != NULL) &&\n\t\t((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0))\n\t\t\treturn(i);\n\tif (!b->init)\n\t\t{\n\t\tBIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED);\n\t\treturn(-2);\n\t\t}\n\ti=b->method->bwrite(b,in,inl);\n\tif (i > 0) b->num_write+=(unsigned long)i;\n\tif (b->references <= 0) abort();\n\tif (cb != NULL)\n\t\ti=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,\n\t\t\t0L,(long)i);\n\treturn(i);\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}'] |
34,384 | 0 | https://github.com/openssl/openssl/blob/d858c87653257185ead1c5baf3d84cd7276dd912/crypto/x509/x509_vfy.c/#L1108 | static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl,
X509 **pissuer, int *pcrl_score)
{
X509 *crl_issuer = NULL;
X509_NAME *cnm = X509_CRL_get_issuer(crl);
int cidx = ctx->error_depth;
int i;
if (cidx != sk_X509_num(ctx->chain) - 1)
cidx++;
crl_issuer = sk_X509_value(ctx->chain, cidx);
if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {
if (*pcrl_score & CRL_SCORE_ISSUER_NAME) {
*pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_ISSUER_CERT;
*pissuer = crl_issuer;
return;
}
}
for (cidx++; cidx < sk_X509_num(ctx->chain); cidx++) {
crl_issuer = sk_X509_value(ctx->chain, cidx);
if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm))
continue;
if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {
*pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_SAME_PATH;
*pissuer = crl_issuer;
return;
}
}
if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT))
return;
for (i = 0; i < sk_X509_num(ctx->untrusted); i++) {
crl_issuer = sk_X509_value(ctx->untrusted, i);
if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm))
continue;
if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {
*pissuer = crl_issuer;
*pcrl_score |= CRL_SCORE_AKID;
return;
}
}
} | ['static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl,\n X509 **pissuer, int *pcrl_score)\n{\n X509 *crl_issuer = NULL;\n X509_NAME *cnm = X509_CRL_get_issuer(crl);\n int cidx = ctx->error_depth;\n int i;\n if (cidx != sk_X509_num(ctx->chain) - 1)\n cidx++;\n crl_issuer = sk_X509_value(ctx->chain, cidx);\n if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {\n if (*pcrl_score & CRL_SCORE_ISSUER_NAME) {\n *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_ISSUER_CERT;\n *pissuer = crl_issuer;\n return;\n }\n }\n for (cidx++; cidx < sk_X509_num(ctx->chain); cidx++) {\n crl_issuer = sk_X509_value(ctx->chain, cidx);\n if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm))\n continue;\n if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {\n *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_SAME_PATH;\n *pissuer = crl_issuer;\n return;\n }\n }\n if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT))\n return;\n for (i = 0; i < sk_X509_num(ctx->untrusted); i++) {\n crl_issuer = sk_X509_value(ctx->untrusted, i);\n if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm))\n continue;\n if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {\n *pissuer = crl_issuer;\n *pcrl_score |= CRL_SCORE_AKID;\n return;\n }\n }\n}', 'X509_NAME *X509_CRL_get_issuer(X509_CRL *crl)\n{\n return crl->crl.issuer;\n}', 'DEFINE_STACK_OF(X509)', 'int sk_num(const _STACK *st)\n{\n if (st == NULL)\n return -1;\n return st->num;\n}', 'void *sk_value(const _STACK *st, int i)\n{\n if (!st || (i < 0) || (i >= st->num))\n return NULL;\n return st->data[i];\n}', 'int X509_check_akid(X509 *issuer, AUTHORITY_KEYID *akid)\n{\n if (!akid)\n return X509_V_OK;\n if (akid->keyid && issuer->skid &&\n ASN1_OCTET_STRING_cmp(akid->keyid, issuer->skid))\n return X509_V_ERR_AKID_SKID_MISMATCH;\n if (akid->serial &&\n ASN1_INTEGER_cmp(X509_get_serialNumber(issuer), akid->serial))\n return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;\n if (akid->issuer) {\n GENERAL_NAMES *gens;\n GENERAL_NAME *gen;\n X509_NAME *nm = NULL;\n int i;\n gens = akid->issuer;\n for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) {\n gen = sk_GENERAL_NAME_value(gens, i);\n if (gen->type == GEN_DIRNAME) {\n nm = gen->d.dirn;\n break;\n }\n }\n if (nm && X509_NAME_cmp(nm, X509_get_issuer_name(issuer)))\n return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;\n }\n return X509_V_OK;\n}', 'X509_NAME *X509_get_subject_name(X509 *a)\n{\n return (a->cert_info.subject);\n}'] |
34,385 | 0 | https://github.com/openssl/openssl/blob/a7cef52f9b961dcb1e5d0c3b75185a12a88ad2db/crypto/bn/bn_lib.c/#L365 | int BN_set_word(BIGNUM *a, BN_ULONG w)
{
bn_check_top(a);
if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
return 0;
a->neg = 0;
a->d[0] = w;
a->top = (w ? 1 : 0);
a->flags &= ~BN_FLG_FIXED_TOP;
bn_check_top(a);
return 1;
} | ['static int x9_62_tests(int n)\n{\n int nid, md_nid, ret = 0;\n const char *r_in = NULL, *s_in = NULL, *tbs = NULL;\n unsigned char *pbuf = NULL, *qbuf = NULL, *message = NULL;\n unsigned char digest[EVP_MAX_MD_SIZE];\n unsigned int dgst_len = 0;\n long q_len, msg_len = 0;\n size_t p_len;\n EVP_MD_CTX *mctx = NULL;\n EC_KEY *key = NULL;\n ECDSA_SIG *signature = NULL;\n BIGNUM *r = NULL, *s = NULL;\n BIGNUM *kinv = NULL, *rp = NULL;\n const BIGNUM *sig_r = NULL, *sig_s = NULL;\n nid = ecdsa_cavs_kats[n].nid;\n md_nid = ecdsa_cavs_kats[n].md_nid;\n r_in = ecdsa_cavs_kats[n].r;\n s_in = ecdsa_cavs_kats[n].s;\n tbs = ecdsa_cavs_kats[n].msg;\n numbers[0] = ecdsa_cavs_kats[n].d;\n numbers[1] = ecdsa_cavs_kats[n].k;\n TEST_info("ECDSA KATs for curve %s", OBJ_nid2sn(nid));\n if (!TEST_ptr(mctx = EVP_MD_CTX_new())\n || !TEST_ptr(message = OPENSSL_hexstr2buf(tbs, &msg_len))\n || !TEST_true(EVP_DigestInit_ex(mctx, EVP_get_digestbynid(md_nid), NULL))\n || !TEST_true(EVP_DigestUpdate(mctx, message, msg_len))\n || !TEST_true(EVP_DigestFinal_ex(mctx, digest, &dgst_len))\n || !TEST_ptr(key = EC_KEY_new_by_curve_name(nid))\n || !TEST_ptr(r = BN_new())\n || !TEST_ptr(s = BN_new())\n || !TEST_true(BN_hex2bn(&r, r_in))\n || !TEST_true(BN_hex2bn(&s, s_in))\n || !TEST_true(change_rand()))\n goto err;\n use_fake = 1;\n if (!TEST_true(EC_KEY_generate_key(key))\n || !TEST_true(p_len = EC_KEY_key2buf(key, POINT_CONVERSION_UNCOMPRESSED,\n &pbuf, NULL))\n || !TEST_ptr(qbuf = OPENSSL_hexstr2buf(ecdsa_cavs_kats[n].Q, &q_len))\n || !TEST_int_eq(q_len, p_len)\n || !TEST_mem_eq(qbuf, q_len, pbuf, p_len))\n goto err;\n use_fake = 1;\n if (!TEST_true(ECDSA_sign_setup(key, NULL, &kinv, &rp))\n || !TEST_ptr(signature = ECDSA_do_sign_ex(digest, dgst_len,\n kinv, rp, key))\n || !TEST_int_eq(ECDSA_do_verify(digest, dgst_len, signature, key), 1))\n goto err;\n ECDSA_SIG_get0(signature, &sig_r, &sig_s);\n if (!TEST_BN_eq(sig_r, r)\n || !TEST_BN_eq(sig_s, s))\n goto err;\n ret = 1;\n err:\n if (!TEST_true(restore_rand()))\n ret = 0;\n OPENSSL_free(message);\n OPENSSL_free(pbuf);\n OPENSSL_free(qbuf);\n EC_KEY_free(key);\n ECDSA_SIG_free(signature);\n BN_free(r);\n BN_free(s);\n EVP_MD_CTX_free(mctx);\n BN_clear_free(kinv);\n BN_clear_free(rp);\n return ret;\n}', 'EC_KEY *EC_KEY_new_by_curve_name(int nid)\n{\n EC_KEY *ret = EC_KEY_new();\n if (ret == NULL)\n return NULL;\n ret->group = EC_GROUP_new_by_curve_name(nid);\n if (ret->group == NULL) {\n EC_KEY_free(ret);\n return NULL;\n }\n if (ret->meth->set_group != NULL\n && ret->meth->set_group(ret, ret->group) == 0) {\n EC_KEY_free(ret);\n return NULL;\n }\n return ret;\n}', 'EC_KEY *EC_KEY_new(void)\n{\n return EC_KEY_new_method(NULL);\n}', 'EC_KEY *EC_KEY_new_method(ENGINE *engine)\n{\n EC_KEY *ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL) {\n ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n ret->references = 1;\n ret->lock = CRYPTO_THREAD_lock_new();\n if (ret->lock == NULL) {\n ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(ret);\n return NULL;\n }\n ret->meth = EC_KEY_get_default_method();\n#ifndef OPENSSL_NO_ENGINE\n if (engine != NULL) {\n if (!ENGINE_init(engine)) {\n ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB);\n goto err;\n }\n ret->engine = engine;\n } else\n ret->engine = ENGINE_get_default_EC();\n if (ret->engine != NULL) {\n ret->meth = ENGINE_get_EC(ret->engine);\n if (ret->meth == NULL) {\n ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB);\n goto err;\n }\n }\n#endif\n ret->version = 1;\n ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) {\n goto err;\n }\n if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {\n ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_INIT_FAIL);\n goto err;\n }\n return ret;\n err:\n EC_KEY_free(ret);\n return NULL;\n}', 'void EC_KEY_free(EC_KEY *r)\n{\n int i;\n if (r == NULL)\n return;\n CRYPTO_DOWN_REF(&r->references, &i, r->lock);\n REF_PRINT_COUNT("EC_KEY", r);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n if (r->meth != NULL && r->meth->finish != NULL)\n r->meth->finish(r);\n#ifndef OPENSSL_NO_ENGINE\n ENGINE_finish(r->engine);\n#endif\n if (r->group && r->group->meth->keyfinish)\n r->group->meth->keyfinish(r);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, r, &r->ex_data);\n CRYPTO_THREAD_lock_free(r->lock);\n EC_GROUP_free(r->group);\n EC_POINT_free(r->pub_key);\n BN_clear_free(r->priv_key);\n OPENSSL_clear_free((void *)r, sizeof(EC_KEY));\n}', "int BN_hex2bn(BIGNUM **bn, const char *a)\n{\n BIGNUM *ret = NULL;\n BN_ULONG l = 0;\n int neg = 0, h, m, i, j, k, c;\n int num;\n if (a == NULL || *a == '\\0')\n return 0;\n if (*a == '-') {\n neg = 1;\n a++;\n }\n for (i = 0; i <= INT_MAX / 4 && ossl_isxdigit(a[i]); i++)\n continue;\n if (i == 0 || i > INT_MAX / 4)\n goto err;\n num = i + neg;\n if (bn == NULL)\n return num;\n if (*bn == NULL) {\n if ((ret = BN_new()) == NULL)\n return 0;\n } else {\n ret = *bn;\n BN_zero(ret);\n }\n if (bn_expand(ret, i * 4) == NULL)\n goto err;\n j = i;\n m = 0;\n h = 0;\n while (j > 0) {\n m = (BN_BYTES * 2 <= j) ? BN_BYTES * 2 : j;\n l = 0;\n for (;;) {\n c = a[j - m];\n k = OPENSSL_hexchar2int(c);\n if (k < 0)\n k = 0;\n l = (l << 4) | k;\n if (--m <= 0) {\n ret->d[h++] = l;\n break;\n }\n }\n j -= BN_BYTES * 2;\n }\n ret->top = h;\n bn_correct_top(ret);\n *bn = ret;\n bn_check_top(ret);\n if (ret->top != 0)\n ret->neg = neg;\n return num;\n err:\n if (*bn == NULL)\n BN_free(ret);\n return 0;\n}", 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}'] |
34,386 | 0 | https://github.com/libav/libav/blob/80bdf7e0b7975956c42f17589cb21a5531f179ef/libavcodec/vc1dec.c/#L1582 | static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, int mv1, int r_x, int r_y, uint8_t* is_intra, int pred_flag, int dir)
{
MpegEncContext *s = &v->s;
int xy, wrap, off = 0;
int16_t *A, *B, *C;
int px, py;
int sum;
int mixedmv_pic, num_samefield = 0, num_oppfield = 0;
int opposit, f;
int16_t samefield_pred[2], oppfield_pred[2];
int16_t samefield_predA[2], oppfield_predA[2];
int16_t samefield_predB[2], oppfield_predB[2];
int16_t samefield_predC[2], oppfield_predC[2];
int16_t *predA, *predC;
int a_valid, b_valid, c_valid;
int hybridmv_thresh, y_bias = 0;
if (v->mv_mode == MV_PMODE_MIXED_MV ||
((v->mv_mode == MV_PMODE_INTENSITY_COMP) && (v->mv_mode2 == MV_PMODE_MIXED_MV))) mixedmv_pic = 1;
else mixedmv_pic = 0;
dmv_x <<= 1 - s->quarter_sample;
dmv_y <<= 1 - s->quarter_sample;
wrap = s->b8_stride;
xy = s->block_index[n];
if(s->mb_intra){
s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy + v->blocks_off][0] = 0;
s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy + v->blocks_off][1] = 0;
s->current_picture.f.motion_val[1][xy + v->blocks_off][0] = 0;
s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = 0;
if(mv1) {
s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][0] = 0;
s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][1] = 0;
s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][0] = 0;
s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][1] = 0;
s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][0] = 0;
s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][1] = 0;
v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;
s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][0] = 0;
s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][1] = 0;
s->current_picture.f.motion_val[1][xy + wrap][0] = 0;
s->current_picture.f.motion_val[1][xy + wrap + v->blocks_off][1] = 0;
s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][0] = 0;
s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][1] = 0;
}
return;
}
C = s->current_picture.f.motion_val[dir][xy - 1 + v->blocks_off];
A = s->current_picture.f.motion_val[dir][xy - wrap + v->blocks_off];
if(mv1) {
if (v->field_mode && mixedmv_pic)
off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;
else
off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;
} else {
switch (n) {
case 0:
off = (s->mb_x > 0) ? -1 : 1;
break;
case 1:
off = (s->mb_x == (s->mb_width - 1)) ? -1 : 1;
break;
case 2:
off = 1;
break;
case 3:
off = -1;
}
}
B = s->current_picture.f.motion_val[dir][xy - wrap + off + v->blocks_off];
a_valid = !s->first_slice_line || (n==2 || n==3);
b_valid = a_valid && (s->mb_width > 1);
c_valid = s->mb_x || (n==1 || n==3);
if (v->field_mode) {
a_valid = a_valid && !is_intra[xy - wrap];
b_valid = b_valid && !is_intra[xy - wrap + off];
c_valid = c_valid && !is_intra[xy - 1];
}
if (a_valid) {
f = v->mv_f[dir][xy - wrap + v->blocks_off];
num_oppfield += f;
num_samefield += 1 - f;
if (f) {
oppfield_predA[0] = A[0];
oppfield_predA[1] = A[1];
samefield_predA[0] = scaleforsame(v, 0, A[0], 0, dir);
samefield_predA[1] = scaleforsame(v, n, A[1], 1, dir);
} else {
samefield_predA[0] = A[0];
samefield_predA[1] = A[1];
if (v->numref)
oppfield_predA[0] = scaleforopp(v, A[0], 0, dir);
if (v->numref)
oppfield_predA[1] = scaleforopp(v, A[1], 1, dir);
}
} else {
samefield_predA[0] = samefield_predA[1] = 0;
oppfield_predA[0] = oppfield_predA[1] = 0;
}
if (c_valid) {
f = v->mv_f[dir][xy - 1 + v->blocks_off];
num_oppfield += f;
num_samefield += 1 - f;
if (f) {
oppfield_predC[0] = C[0];
oppfield_predC[1] = C[1];
samefield_predC[0] = scaleforsame(v, 0, C[0], 0, dir);
samefield_predC[1] = scaleforsame(v, n, C[1], 1, dir);
} else {
samefield_predC[0] = C[0];
samefield_predC[1] = C[1];
if (v->numref)
oppfield_predC[0] = scaleforopp(v, C[0], 0, dir);
if (v->numref)
oppfield_predC[1] = scaleforopp(v, C[1], 1, dir);
}
} else {
samefield_predC[0] = samefield_predC[1] = 0;
oppfield_predC[0] = oppfield_predC[1] = 0;
}
if (b_valid) {
f = v->mv_f[dir][xy - wrap + off + v->blocks_off];
num_oppfield += f;
num_samefield += 1 - f;
if (f) {
oppfield_predB[0] = B[0];
oppfield_predB[1] = B[1];
samefield_predB[0] = scaleforsame(v, 0, B[0], 0, dir);
samefield_predB[1] = scaleforsame(v, n, B[1], 1, dir);
} else {
samefield_predB[0] = B[0];
samefield_predB[1] = B[1];
if (v->numref)
oppfield_predB[0] = scaleforopp(v, B[0], 0, dir);
if (v->numref)
oppfield_predB[1] = scaleforopp(v, B[1], 1, dir);
}
} else {
samefield_predB[0] = samefield_predB[1] = 0;
oppfield_predB[0] = oppfield_predB[1] = 0;
}
if (a_valid) {
samefield_pred[0] = samefield_predA[0];
samefield_pred[1] = samefield_predA[1];
oppfield_pred[0] = oppfield_predA[0];
oppfield_pred[1] = oppfield_predA[1];
} else if (c_valid) {
samefield_pred[0] = samefield_predC[0];
samefield_pred[1] = samefield_predC[1];
oppfield_pred[0] = oppfield_predC[0];
oppfield_pred[1] = oppfield_predC[1];
} else if (b_valid) {
samefield_pred[0] = samefield_predB[0];
samefield_pred[1] = samefield_predB[1];
oppfield_pred[0] = oppfield_predB[0];
oppfield_pred[1] = oppfield_predB[1];
} else {
samefield_pred[0] = samefield_pred[1] = 0;
oppfield_pred[0] = oppfield_pred[1] = 0;
}
if (num_samefield + num_oppfield > 1) {
samefield_pred[0] = mid_pred(samefield_predA[0], samefield_predB[0], samefield_predC[0]);
samefield_pred[1] = mid_pred(samefield_predA[1], samefield_predB[1], samefield_predC[1]);
if (v->numref)
oppfield_pred[0] = mid_pred(oppfield_predA[0], oppfield_predB[0], oppfield_predC[0]);
if (v->numref)
oppfield_pred[1] = mid_pred(oppfield_predA[1], oppfield_predB[1], oppfield_predC[1]);
}
if (v->field_mode) {
if (num_samefield <= num_oppfield)
opposit = 1 - pred_flag;
else
opposit = pred_flag;
} else
opposit = 0;
if (opposit) {
px = oppfield_pred[0];
py = oppfield_pred[1];
predA = oppfield_predA;
predC = oppfield_predC;
v->mv_f[dir][xy + v->blocks_off] = f = 1;
v->ref_field_type[dir] = !v->cur_field_type;
} else {
px = samefield_pred[0];
py = samefield_pred[1];
predA = samefield_predA;
predC = samefield_predC;
v->mv_f[dir][xy + v->blocks_off] = f = 0;
v->ref_field_type[dir] = v->cur_field_type;
}
if (!v->field_mode) {
int qx, qy, X, Y;
qx = (s->mb_x << 6) + ((n==1 || n==3) ? 32 : 0);
qy = (s->mb_y << 6) + ((n==2 || n==3) ? 32 : 0);
X = (s->mb_width << 6) - 4;
Y = (s->mb_height << 6) - 4;
if(mv1) {
if(qx + px < -60) px = -60 - qx;
if(qy + py < -60) py = -60 - qy;
} else {
if(qx + px < -28) px = -28 - qx;
if(qy + py < -28) py = -28 - qy;
}
if(qx + px > X) px = X - qx;
if(qy + py > Y) py = Y - qy;
}
if (!v->field_mode || s->pict_type != AV_PICTURE_TYPE_B) {
if (v->field_mode && !s->quarter_sample)
hybridmv_thresh = 16;
else
hybridmv_thresh = 32;
if (a_valid && c_valid) {
if (is_intra[xy - wrap])
sum = FFABS(px) + FFABS(py);
else
sum = FFABS(px - predA[0]) + FFABS(py - predA[1]);
if (sum > hybridmv_thresh) {
if (get_bits1(&s->gb)) {
px = predA[0];
py = predA[1];
} else {
px = predC[0];
py = predC[1];
}
} else {
if (is_intra[xy - 1])
sum = FFABS(px) + FFABS(py);
else
sum = FFABS(px - predC[0]) + FFABS(py - predC[1]);
if (sum > hybridmv_thresh) {
if(get_bits1(&s->gb)) {
px = predA[0];
py = predA[1];
} else {
px = predC[0];
py = predC[1];
}
}
}
}
}
if (v->field_mode && !s->quarter_sample) {
r_x <<= 1;
r_y <<= 1;
}
if (v->field_mode && v->numref)
r_y >>= 1;
if (v->field_mode && v->cur_field_type && v->ref_field_type[dir] == 0)
y_bias = 1;
s->mv[dir][n][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
s->mv[dir][n][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1] = ((py + dmv_y + r_y - y_bias) & ((r_y << 1) - 1)) - r_y + y_bias;
if(mv1) {
s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];
s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];
s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];
s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];
s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];
s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];
v->mv_f[dir][xy + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];
v->mv_f[dir][xy + wrap + v->blocks_off] = v->mv_f[dir][xy + wrap + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];
}
} | ['static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, int mv1, int r_x, int r_y, uint8_t* is_intra, int pred_flag, int dir)\n{\n MpegEncContext *s = &v->s;\n int xy, wrap, off = 0;\n int16_t *A, *B, *C;\n int px, py;\n int sum;\n int mixedmv_pic, num_samefield = 0, num_oppfield = 0;\n int opposit, f;\n int16_t samefield_pred[2], oppfield_pred[2];\n int16_t samefield_predA[2], oppfield_predA[2];\n int16_t samefield_predB[2], oppfield_predB[2];\n int16_t samefield_predC[2], oppfield_predC[2];\n int16_t *predA, *predC;\n int a_valid, b_valid, c_valid;\n int hybridmv_thresh, y_bias = 0;\n if (v->mv_mode == MV_PMODE_MIXED_MV ||\n ((v->mv_mode == MV_PMODE_INTENSITY_COMP) && (v->mv_mode2 == MV_PMODE_MIXED_MV))) mixedmv_pic = 1;\n else mixedmv_pic = 0;\n dmv_x <<= 1 - s->quarter_sample;\n dmv_y <<= 1 - s->quarter_sample;\n wrap = s->b8_stride;\n xy = s->block_index[n];\n if(s->mb_intra){\n s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy + v->blocks_off][0] = 0;\n s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy + v->blocks_off][1] = 0;\n s->current_picture.f.motion_val[1][xy + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = 0;\n if(mv1) {\n s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][1] = 0;\n s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][1] = 0;\n s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][1] = 0;\n v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;\n s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][1] = 0;\n s->current_picture.f.motion_val[1][xy + wrap][0] = 0;\n s->current_picture.f.motion_val[1][xy + wrap + v->blocks_off][1] = 0;\n s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][1] = 0;\n }\n return;\n }\n C = s->current_picture.f.motion_val[dir][xy - 1 + v->blocks_off];\n A = s->current_picture.f.motion_val[dir][xy - wrap + v->blocks_off];\n if(mv1) {\n if (v->field_mode && mixedmv_pic)\n off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;\n else\n off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;\n } else {\n switch (n) {\n case 0:\n off = (s->mb_x > 0) ? -1 : 1;\n break;\n case 1:\n off = (s->mb_x == (s->mb_width - 1)) ? -1 : 1;\n break;\n case 2:\n off = 1;\n break;\n case 3:\n off = -1;\n }\n }\n B = s->current_picture.f.motion_val[dir][xy - wrap + off + v->blocks_off];\n a_valid = !s->first_slice_line || (n==2 || n==3);\n b_valid = a_valid && (s->mb_width > 1);\n c_valid = s->mb_x || (n==1 || n==3);\n if (v->field_mode) {\n a_valid = a_valid && !is_intra[xy - wrap];\n b_valid = b_valid && !is_intra[xy - wrap + off];\n c_valid = c_valid && !is_intra[xy - 1];\n }\n if (a_valid) {\n f = v->mv_f[dir][xy - wrap + v->blocks_off];\n num_oppfield += f;\n num_samefield += 1 - f;\n if (f) {\n oppfield_predA[0] = A[0];\n oppfield_predA[1] = A[1];\n samefield_predA[0] = scaleforsame(v, 0, A[0], 0, dir);\n samefield_predA[1] = scaleforsame(v, n, A[1], 1, dir);\n } else {\n samefield_predA[0] = A[0];\n samefield_predA[1] = A[1];\n if (v->numref)\n oppfield_predA[0] = scaleforopp(v, A[0], 0, dir);\n if (v->numref)\n oppfield_predA[1] = scaleforopp(v, A[1], 1, dir);\n }\n } else {\n samefield_predA[0] = samefield_predA[1] = 0;\n oppfield_predA[0] = oppfield_predA[1] = 0;\n }\n if (c_valid) {\n f = v->mv_f[dir][xy - 1 + v->blocks_off];\n num_oppfield += f;\n num_samefield += 1 - f;\n if (f) {\n oppfield_predC[0] = C[0];\n oppfield_predC[1] = C[1];\n samefield_predC[0] = scaleforsame(v, 0, C[0], 0, dir);\n samefield_predC[1] = scaleforsame(v, n, C[1], 1, dir);\n } else {\n samefield_predC[0] = C[0];\n samefield_predC[1] = C[1];\n if (v->numref)\n oppfield_predC[0] = scaleforopp(v, C[0], 0, dir);\n if (v->numref)\n oppfield_predC[1] = scaleforopp(v, C[1], 1, dir);\n }\n } else {\n samefield_predC[0] = samefield_predC[1] = 0;\n oppfield_predC[0] = oppfield_predC[1] = 0;\n }\n if (b_valid) {\n f = v->mv_f[dir][xy - wrap + off + v->blocks_off];\n num_oppfield += f;\n num_samefield += 1 - f;\n if (f) {\n oppfield_predB[0] = B[0];\n oppfield_predB[1] = B[1];\n samefield_predB[0] = scaleforsame(v, 0, B[0], 0, dir);\n samefield_predB[1] = scaleforsame(v, n, B[1], 1, dir);\n } else {\n samefield_predB[0] = B[0];\n samefield_predB[1] = B[1];\n if (v->numref)\n oppfield_predB[0] = scaleforopp(v, B[0], 0, dir);\n if (v->numref)\n oppfield_predB[1] = scaleforopp(v, B[1], 1, dir);\n }\n } else {\n samefield_predB[0] = samefield_predB[1] = 0;\n oppfield_predB[0] = oppfield_predB[1] = 0;\n }\n if (a_valid) {\n samefield_pred[0] = samefield_predA[0];\n samefield_pred[1] = samefield_predA[1];\n oppfield_pred[0] = oppfield_predA[0];\n oppfield_pred[1] = oppfield_predA[1];\n } else if (c_valid) {\n samefield_pred[0] = samefield_predC[0];\n samefield_pred[1] = samefield_predC[1];\n oppfield_pred[0] = oppfield_predC[0];\n oppfield_pred[1] = oppfield_predC[1];\n } else if (b_valid) {\n samefield_pred[0] = samefield_predB[0];\n samefield_pred[1] = samefield_predB[1];\n oppfield_pred[0] = oppfield_predB[0];\n oppfield_pred[1] = oppfield_predB[1];\n } else {\n samefield_pred[0] = samefield_pred[1] = 0;\n oppfield_pred[0] = oppfield_pred[1] = 0;\n }\n if (num_samefield + num_oppfield > 1) {\n samefield_pred[0] = mid_pred(samefield_predA[0], samefield_predB[0], samefield_predC[0]);\n samefield_pred[1] = mid_pred(samefield_predA[1], samefield_predB[1], samefield_predC[1]);\n if (v->numref)\n oppfield_pred[0] = mid_pred(oppfield_predA[0], oppfield_predB[0], oppfield_predC[0]);\n if (v->numref)\n oppfield_pred[1] = mid_pred(oppfield_predA[1], oppfield_predB[1], oppfield_predC[1]);\n }\n if (v->field_mode) {\n if (num_samefield <= num_oppfield)\n opposit = 1 - pred_flag;\n else\n opposit = pred_flag;\n } else\n opposit = 0;\n if (opposit) {\n px = oppfield_pred[0];\n py = oppfield_pred[1];\n predA = oppfield_predA;\n predC = oppfield_predC;\n v->mv_f[dir][xy + v->blocks_off] = f = 1;\n v->ref_field_type[dir] = !v->cur_field_type;\n } else {\n px = samefield_pred[0];\n py = samefield_pred[1];\n predA = samefield_predA;\n predC = samefield_predC;\n v->mv_f[dir][xy + v->blocks_off] = f = 0;\n v->ref_field_type[dir] = v->cur_field_type;\n }\n if (!v->field_mode) {\n int qx, qy, X, Y;\n qx = (s->mb_x << 6) + ((n==1 || n==3) ? 32 : 0);\n qy = (s->mb_y << 6) + ((n==2 || n==3) ? 32 : 0);\n X = (s->mb_width << 6) - 4;\n Y = (s->mb_height << 6) - 4;\n if(mv1) {\n if(qx + px < -60) px = -60 - qx;\n if(qy + py < -60) py = -60 - qy;\n } else {\n if(qx + px < -28) px = -28 - qx;\n if(qy + py < -28) py = -28 - qy;\n }\n if(qx + px > X) px = X - qx;\n if(qy + py > Y) py = Y - qy;\n }\n if (!v->field_mode || s->pict_type != AV_PICTURE_TYPE_B) {\n if (v->field_mode && !s->quarter_sample)\n hybridmv_thresh = 16;\n else\n hybridmv_thresh = 32;\n if (a_valid && c_valid) {\n if (is_intra[xy - wrap])\n sum = FFABS(px) + FFABS(py);\n else\n sum = FFABS(px - predA[0]) + FFABS(py - predA[1]);\n if (sum > hybridmv_thresh) {\n if (get_bits1(&s->gb)) {\n px = predA[0];\n py = predA[1];\n } else {\n px = predC[0];\n py = predC[1];\n }\n } else {\n if (is_intra[xy - 1])\n sum = FFABS(px) + FFABS(py);\n else\n sum = FFABS(px - predC[0]) + FFABS(py - predC[1]);\n if (sum > hybridmv_thresh) {\n if(get_bits1(&s->gb)) {\n px = predA[0];\n py = predA[1];\n } else {\n px = predC[0];\n py = predC[1];\n }\n }\n }\n }\n }\n if (v->field_mode && !s->quarter_sample) {\n r_x <<= 1;\n r_y <<= 1;\n }\n if (v->field_mode && v->numref)\n r_y >>= 1;\n if (v->field_mode && v->cur_field_type && v->ref_field_type[dir] == 0)\n y_bias = 1;\n s->mv[dir][n][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;\n s->mv[dir][n][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1] = ((py + dmv_y + r_y - y_bias) & ((r_y << 1) - 1)) - r_y + y_bias;\n if(mv1) {\n s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];\n s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];\n s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];\n s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];\n s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];\n s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];\n v->mv_f[dir][xy + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];\n v->mv_f[dir][xy + wrap + v->blocks_off] = v->mv_f[dir][xy + wrap + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];\n }\n}'] |
34,387 | 0 | https://github.com/libav/libav/blob/0940580adb5e6bde8782841b3104fd0783e541f0/libavformat/oggdec.c/#L65 | static int ogg_save(AVFormatContext *s)
{
struct ogg *ogg = s->priv_data;
struct ogg_state *ost =
av_malloc(sizeof(*ost) + (ogg->nstreams - 1) * sizeof(*ogg->streams));
int i;
ost->pos = avio_tell(s->pb);
ost->curidx = ogg->curidx;
ost->next = ogg->state;
ost->nstreams = ogg->nstreams;
memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams));
for (i = 0; i < ogg->nstreams; i++) {
struct ogg_stream *os = ogg->streams + i;
os->buf = av_mallocz(os->bufsize + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(os->buf, ost->streams[i].buf, os->bufpos);
}
ogg->state = ost;
return 0;
} | ['static int ogg_save(AVFormatContext *s)\n{\n struct ogg *ogg = s->priv_data;\n struct ogg_state *ost =\n av_malloc(sizeof(*ost) + (ogg->nstreams - 1) * sizeof(*ogg->streams));\n int i;\n ost->pos = avio_tell(s->pb);\n ost->curidx = ogg->curidx;\n ost->next = ogg->state;\n ost->nstreams = ogg->nstreams;\n memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams));\n for (i = 0; i < ogg->nstreams; i++) {\n struct ogg_stream *os = ogg->streams + i;\n os->buf = av_mallocz(os->bufsize + FF_INPUT_BUFFER_PADDING_SIZE);\n memcpy(os->buf, ost->streams[i].buf, os->bufpos);\n }\n ogg->state = ost;\n return 0;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if (size > (INT_MAX - 32) || !size)\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size + 32);\n if (!ptr)\n return ptr;\n diff = ((-(long)ptr - 1) & 31) + 1;\n ptr = (char *)ptr + diff;\n ((char *)ptr)[-1] = diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr, 32, size))\n ptr = NULL;\n#elif HAVE_ALIGNED_MALLOC\n ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n ptr = memalign(32, size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'static av_always_inline int64_t avio_tell(AVIOContext *s)\n{\n return avio_seek(s, 0, SEEK_CUR);\n}'] |
34,388 | 0 | https://gitlab.com/libtiff/libtiff/blob/771a4ea0a98c7a218c9f3add9a05e08d29625758/libtiff/tif_dirread.c/#L4227 | static int
EstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)
{
static const char module[] = "EstimateStripByteCounts";
TIFFDirEntry *dp;
TIFFDirectory *td = &tif->tif_dir;
uint32 strip;
if (td->td_stripbytecount)
_TIFFfree(td->td_stripbytecount);
td->td_stripbytecount = (uint64*)
_TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64),
"for \"StripByteCounts\" array");
if( td->td_stripbytecount == NULL )
return -1;
if (td->td_compression != COMPRESSION_NONE) {
uint64 space;
uint64 filesize;
uint16 n;
filesize = TIFFGetFileSize(tif);
if (!(tif->tif_flags&TIFF_BIGTIFF))
space=sizeof(TIFFHeaderClassic)+2+dircount*12+4;
else
space=sizeof(TIFFHeaderBig)+8+dircount*20+8;
for (dp = dir, n = dircount; n > 0; n--, dp++)
{
uint32 typewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type);
uint64 datasize;
typewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type);
if (typewidth == 0) {
TIFFErrorExt(tif->tif_clientdata, module,
"Cannot determine size of unknown tag type %d",
dp->tdir_type);
return -1;
}
datasize=(uint64)typewidth*dp->tdir_count;
if (!(tif->tif_flags&TIFF_BIGTIFF))
{
if (datasize<=4)
datasize=0;
}
else
{
if (datasize<=8)
datasize=0;
}
space+=datasize;
}
space = filesize - space;
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
space /= td->td_samplesperpixel;
for (strip = 0; strip < td->td_nstrips; strip++)
td->td_stripbytecount[strip] = space;
strip--;
if (td->td_stripoffset[strip]+td->td_stripbytecount[strip] > filesize)
td->td_stripbytecount[strip] = filesize - td->td_stripoffset[strip];
} else if (isTiled(tif)) {
uint64 bytespertile = TIFFTileSize64(tif);
for (strip = 0; strip < td->td_nstrips; strip++)
td->td_stripbytecount[strip] = bytespertile;
} else {
uint64 rowbytes = TIFFScanlineSize64(tif);
uint32 rowsperstrip = td->td_imagelength/td->td_stripsperimage;
for (strip = 0; strip < td->td_nstrips; strip++)
td->td_stripbytecount[strip] = rowbytes * rowsperstrip;
}
TIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);
if (!TIFFFieldSet(tif, FIELD_ROWSPERSTRIP))
td->td_rowsperstrip = td->td_imagelength;
return 1;
} | ['static void TIFFWriteOvrRow( TIFFOvrCache * psCache )\n{\n int\t\tnRet, iTileX, iTileY = psCache->nBlockOffset;\n unsigned char *pabyData;\n toff_t\tnBaseDirOffset;\n uint32 RowsInStrip;\n if( TIFFIsByteSwapped(psCache->hTIFF) )\n {\n if( psCache->nBitsPerPixel == 16 )\n TIFFSwabArrayOfShort( (uint16 *) psCache->pabyRow1Blocks,\n (psCache->nBytesPerBlock * psCache->nSamples) / 2 );\n else if( psCache->nBitsPerPixel == 32 )\n TIFFSwabArrayOfLong( (uint32 *) psCache->pabyRow1Blocks,\n (psCache->nBytesPerBlock * psCache->nSamples) / 4 );\n else if( psCache->nBitsPerPixel == 64 )\n TIFFSwabArrayOfDouble( (double *) psCache->pabyRow1Blocks,\n (psCache->nBytesPerBlock * psCache->nSamples) / 8 );\n }\n nBaseDirOffset = TIFFCurrentDirOffset( psCache->hTIFF );\n nRet = TIFFSetSubDirectory( psCache->hTIFF, psCache->nDirOffset );\n assert( nRet == 1 );\n\tfor( iTileX = 0; iTileX < psCache->nBlocksPerRow; iTileX++ )\n\t{\n\t\tint nTileID;\n\t\tif (psCache->nPlanarConfig == PLANARCONFIG_SEPARATE)\n\t\t{\n\t\t\tint iSample;\n\t\t\tfor( iSample = 0; iSample < psCache->nSamples; iSample++ )\n\t\t\t{\n\t\t\t\tpabyData = TIFFGetOvrBlock( psCache, iTileX, iTileY, iSample );\n\t\t\t\tif( psCache->bTiled )\n\t\t\t\t{\n\t\t\t\t\tnTileID = TIFFComputeTile( psCache->hTIFF,\n\t\t\t\t\t iTileX * psCache->nBlockXSize,\n\t\t\t\t\t iTileY * psCache->nBlockYSize,\n\t\t\t\t\t 0, (tsample_t) iSample );\n\t\t\t\t\tTIFFWriteEncodedTile( psCache->hTIFF, nTileID,\n\t\t\t\t\t pabyData,\n\t\t\t\t\t TIFFTileSize(psCache->hTIFF) );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tnTileID = TIFFComputeStrip( psCache->hTIFF,\n\t\t\t\t\t iTileY * psCache->nBlockYSize,\n\t\t\t\t\t (tsample_t) iSample );\n\t\t\t\t\tRowsInStrip=psCache->nBlockYSize;\n\t\t\t\t\tif ((iTileY+1)*psCache->nBlockYSize>psCache->nYSize)\n\t\t\t\t\t\tRowsInStrip=psCache->nYSize-iTileY*psCache->nBlockYSize;\n\t\t\t\t\tTIFFWriteEncodedStrip( psCache->hTIFF, nTileID,\n\t\t\t\t\t pabyData,\n\t\t\t\t\t TIFFVStripSize(psCache->hTIFF,RowsInStrip) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpabyData = TIFFGetOvrBlock( psCache, iTileX, iTileY, 0 );\n\t\t\tif( psCache->bTiled )\n\t\t\t{\n\t\t\t\tnTileID = TIFFComputeTile( psCache->hTIFF,\n\t\t\t\t iTileX * psCache->nBlockXSize,\n\t\t\t\t iTileY * psCache->nBlockYSize,\n\t\t\t\t 0, 0 );\n\t\t\t\tTIFFWriteEncodedTile( psCache->hTIFF, nTileID,\n\t\t\t\t pabyData,\n\t\t\t\t TIFFTileSize(psCache->hTIFF) );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tnTileID = TIFFComputeStrip( psCache->hTIFF,\n\t\t\t\t iTileY * psCache->nBlockYSize,\n\t\t\t\t 0 );\n\t\t\t\tRowsInStrip=psCache->nBlockYSize;\n\t\t\t\tif ((iTileY+1)*psCache->nBlockYSize>psCache->nYSize)\n\t\t\t\t\tRowsInStrip=psCache->nYSize-iTileY*psCache->nBlockYSize;\n\t\t\t\tTIFFWriteEncodedStrip( psCache->hTIFF, nTileID,\n\t\t\t\t pabyData,\n\t\t\t\t TIFFVStripSize(psCache->hTIFF,RowsInStrip) );\n\t\t\t}\n\t\t}\n\t}\n pabyData = psCache->pabyRow1Blocks;\n psCache->pabyRow1Blocks = psCache->pabyRow2Blocks;\n psCache->pabyRow2Blocks = pabyData;\n _TIFFmemset( pabyData, 0, psCache->nBytesPerRow );\n psCache->nBlockOffset++;\n TIFFFlush( psCache->hTIFF );\n TIFFSetSubDirectory( psCache->hTIFF, nBaseDirOffset );\n}', 'tmsize_t\nTIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)\n{\n\tstatic const char module[] = "TIFFWriteEncodedStrip";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint16 sample;\n\tif (!WRITECHECKSTRIPS(tif, module))\n\t\treturn ((tmsize_t) -1);\n\tif (strip >= td->td_nstrips) {\n\t\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Can not grow image by strips when using separate planes");\n\t\t\treturn ((tmsize_t) -1);\n\t\t}\n\t\tif (!TIFFGrowStrips(tif, 1, module))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttd->td_stripsperimage =\n\t\t TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip);\n\t}\n\tif (!BUFFERCHECK(tif))\n\t\treturn ((tmsize_t) -1);\n tif->tif_flags |= TIFF_BUF4WRITE;\n\ttif->tif_curstrip = strip;\n\ttif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupencode)(tif))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_rawcc = 0;\n\ttif->tif_rawcp = tif->tif_rawdata;\n\tif( td->td_stripbytecount[strip] > 0 )\n {\n tif->tif_curoff = 0;\n }\n\ttif->tif_flags &= ~TIFF_POSTENCODE;\n\tsample = (uint16)(strip / td->td_stripsperimage);\n\tif (!(*tif->tif_preencode)(tif, sample))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_postdecode( tif, (uint8*) data, cc );\n\tif (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample))\n\t\treturn (0);\n\tif (!(*tif->tif_postencode)(tif))\n\t\treturn ((tmsize_t) -1);\n\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\tTIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);\n\tif (tif->tif_rawcc > 0 &&\n\t !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_rawcc = 0;\n\ttif->tif_rawcp = tif->tif_rawdata;\n\treturn (cc);\n}', 'int\nTIFFFlush(TIFF* tif)\n{\n if( tif->tif_mode == O_RDONLY )\n return 1;\n if (!TIFFFlushData(tif))\n return (0);\n if( (tif->tif_flags & TIFF_DIRTYSTRIP)\n && !(tif->tif_flags & TIFF_DIRTYDIRECT)\n && tif->tif_mode == O_RDWR )\n {\n uint64 *offsets=NULL, *sizes=NULL;\n if( TIFFIsTiled(tif) )\n {\n if( TIFFGetField( tif, TIFFTAG_TILEOFFSETS, &offsets )\n && TIFFGetField( tif, TIFFTAG_TILEBYTECOUNTS, &sizes )\n && _TIFFRewriteField( tif, TIFFTAG_TILEOFFSETS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, offsets )\n && _TIFFRewriteField( tif, TIFFTAG_TILEBYTECOUNTS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, sizes ) )\n {\n tif->tif_flags &= ~TIFF_DIRTYSTRIP;\n tif->tif_flags &= ~TIFF_BEENWRITING;\n return 1;\n }\n }\n else\n {\n if( TIFFGetField( tif, TIFFTAG_STRIPOFFSETS, &offsets )\n && TIFFGetField( tif, TIFFTAG_STRIPBYTECOUNTS, &sizes )\n && _TIFFRewriteField( tif, TIFFTAG_STRIPOFFSETS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, offsets )\n && _TIFFRewriteField( tif, TIFFTAG_STRIPBYTECOUNTS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, sizes ) )\n {\n tif->tif_flags &= ~TIFF_DIRTYSTRIP;\n tif->tif_flags &= ~TIFF_BEENWRITING;\n return 1;\n }\n }\n }\n if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP))\n && !TIFFWriteDirectory(tif))\n return (0);\n return (1);\n}', 'int\nTIFFSetSubDirectory(TIFF* tif, uint64 diroff)\n{\n\ttif->tif_nextdiroff = diroff;\n\ttif->tif_dirnumber = 0;\n\treturn (TIFFReadDirectory(tif));\n}', 'int\nTIFFReadDirectory(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFReadDirectory";\n\tTIFFDirEntry* dir;\n\tuint16 dircount;\n\tTIFFDirEntry* dp;\n\tuint16 di;\n\tconst TIFFField* fip;\n\tuint32 fii;\n toff_t nextdiroff;\n\ttif->tif_diroff=tif->tif_nextdiroff;\n\tif (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff))\n\t\treturn 0;\n\t(*tif->tif_cleanup)(tif);\n\ttif->tif_curdir++;\n nextdiroff = tif->tif_nextdiroff;\n\tdircount=TIFFFetchDirectory(tif,nextdiroff,&dir,&tif->tif_nextdiroff);\n\tif (!dircount)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t "Failed to read directory at offset " TIFF_UINT64_FORMAT,nextdiroff);\n\t\treturn 0;\n\t}\n\tTIFFReadDirectoryCheckOrder(tif,dir,dircount);\n\ttif->tif_flags &= ~TIFF_BEENWRITING;\n\ttif->tif_flags &= ~TIFF_BUF4WRITE;\n\tTIFFFreeDirectory(tif);\n\tTIFFDefaultDirectory(tif);\n\tTIFFSetField(tif,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);\n\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_SAMPLESPERPIXEL);\n\tif (dp)\n\t{\n\t\tif (!TIFFFetchNormalTag(tif,dp,0))\n\t\t\tgoto bad;\n\t\tdp->tdir_tag=IGNORE;\n\t}\n\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_COMPRESSION);\n\tif (dp)\n\t{\n\t\tuint16 value;\n\t\tenum TIFFReadDirEntryErr err;\n\t\terr=TIFFReadDirEntryShort(tif,dp,&value);\n\t\tif (err==TIFFReadDirEntryErrCount)\n\t\t\terr=TIFFReadDirEntryPersampleShort(tif,dp,&value);\n\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t{\n\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,"Compression",0);\n\t\t\tgoto bad;\n\t\t}\n\t\tif (!TIFFSetField(tif,TIFFTAG_COMPRESSION,value))\n\t\t\tgoto bad;\n\t\tdp->tdir_tag=IGNORE;\n\t}\n\telse\n\t{\n\t\tif (!TIFFSetField(tif,TIFFTAG_COMPRESSION,COMPRESSION_NONE))\n\t\t\tgoto bad;\n\t}\n\tfor (di=0, dp=dir; di<dircount; di++, dp++)\n\t{\n\t\tif (dp->tdir_tag!=IGNORE)\n\t\t{\n\t\t\tTIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii);\n\t\t\tif (fii==(uint32)(-1))\n\t\t\t{\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t\t "Unknown field with tag %d (0x%x) encountered",\n\t\t\t\t dp->tdir_tag,dp->tdir_tag);\n\t\t\t\tif (!_TIFFMergeFields(tif,\n\t\t\t\t\t_TIFFCreateAnonField(tif,\n\t\t\t\t\t\tdp->tdir_tag,\n\t\t\t\t\t\t(TIFFDataType) dp->tdir_type),\n\t\t\t\t\t1)) {\n\t\t\t\t\tTIFFWarningExt(tif->tif_clientdata,\n\t\t\t\t\t module,\n\t\t\t\t\t "Registering anonymous field with tag %d (0x%x) failed",\n\t\t\t\t\t dp->tdir_tag,\n\t\t\t\t\t dp->tdir_tag);\n\t\t\t\t\tdp->tdir_tag=IGNORE;\n\t\t\t\t} else {\n\t\t\t\t\tTIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii);\n\t\t\t\t\tassert(fii!=(uint32)(-1));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (dp->tdir_tag!=IGNORE)\n\t\t{\n\t\t\tfip=tif->tif_fields[fii];\n\t\t\tif (fip->field_bit==FIELD_IGNORE)\n\t\t\t\tdp->tdir_tag=IGNORE;\n\t\t\telse\n\t\t\t{\n\t\t\t\tswitch (dp->tdir_tag)\n\t\t\t\t{\n\t\t\t\t\tcase TIFFTAG_STRIPOFFSETS:\n\t\t\t\t\tcase TIFFTAG_STRIPBYTECOUNTS:\n\t\t\t\t\tcase TIFFTAG_TILEOFFSETS:\n\t\t\t\t\tcase TIFFTAG_TILEBYTECOUNTS:\n\t\t\t\t\t\tTIFFSetFieldBit(tif,fip->field_bit);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase TIFFTAG_IMAGEWIDTH:\n\t\t\t\t\tcase TIFFTAG_IMAGELENGTH:\n\t\t\t\t\tcase TIFFTAG_IMAGEDEPTH:\n\t\t\t\t\tcase TIFFTAG_TILELENGTH:\n\t\t\t\t\tcase TIFFTAG_TILEWIDTH:\n\t\t\t\t\tcase TIFFTAG_TILEDEPTH:\n\t\t\t\t\tcase TIFFTAG_PLANARCONFIG:\n\t\t\t\t\tcase TIFFTAG_ROWSPERSTRIP:\n\t\t\t\t\tcase TIFFTAG_EXTRASAMPLES:\n\t\t\t\t\t\tif (!TIFFFetchNormalTag(tif,dp,0))\n\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\tdp->tdir_tag=IGNORE;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif ((tif->tif_dir.td_compression==COMPRESSION_OJPEG)&&\n\t (tif->tif_dir.td_planarconfig==PLANARCONFIG_SEPARATE))\n\t{\n\t\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_STRIPOFFSETS);\n\t\tif ((dp!=0)&&(dp->tdir_count==1))\n\t\t{\n\t\t\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,\n\t\t\t TIFFTAG_STRIPBYTECOUNTS);\n\t\t\tif ((dp!=0)&&(dp->tdir_count==1))\n\t\t\t{\n\t\t\t\ttif->tif_dir.td_planarconfig=PLANARCONFIG_CONTIG;\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t "Planarconfig tag value assumed incorrect, "\n\t\t\t\t "assuming data is contig instead of chunky");\n\t\t\t}\n\t\t}\n\t}\n\tif (!TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS))\n\t{\n\t\tMissingRequired(tif,"ImageLength");\n\t\tgoto bad;\n\t}\n\tif (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) {\n\t\ttif->tif_dir.td_nstrips = TIFFNumberOfStrips(tif);\n\t\ttif->tif_dir.td_tilewidth = tif->tif_dir.td_imagewidth;\n\t\ttif->tif_dir.td_tilelength = tif->tif_dir.td_rowsperstrip;\n\t\ttif->tif_dir.td_tiledepth = tif->tif_dir.td_imagedepth;\n\t\ttif->tif_flags &= ~TIFF_ISTILED;\n\t} else {\n\t\ttif->tif_dir.td_nstrips = TIFFNumberOfTiles(tif);\n\t\ttif->tif_flags |= TIFF_ISTILED;\n\t}\n\tif (!tif->tif_dir.td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "Cannot handle zero number of %s",\n\t\t isTiled(tif) ? "tiles" : "strips");\n\t\tgoto bad;\n\t}\n\ttif->tif_dir.td_stripsperimage = tif->tif_dir.td_nstrips;\n\tif (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\ttif->tif_dir.td_stripsperimage /= tif->tif_dir.td_samplesperpixel;\n\tif (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) {\n\t\tif ((tif->tif_dir.td_compression==COMPRESSION_OJPEG) &&\n\t\t (isTiled(tif)==0) &&\n\t\t (tif->tif_dir.td_nstrips==1)) {\n\t\t\tTIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);\n\t\t} else {\n\t\t\tMissingRequired(tif,\n\t\t\t\tisTiled(tif) ? "TileOffsets" : "StripOffsets");\n\t\t\tgoto bad;\n\t\t}\n\t}\n\tfor (di=0, dp=dir; di<dircount; di++, dp++)\n\t{\n\t\tswitch (dp->tdir_tag)\n\t\t{\n\t\t\tcase IGNORE:\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_MINSAMPLEVALUE:\n\t\t\tcase TIFFTAG_MAXSAMPLEVALUE:\n\t\t\tcase TIFFTAG_BITSPERSAMPLE:\n\t\t\tcase TIFFTAG_DATATYPE:\n\t\t\tcase TIFFTAG_SAMPLEFORMAT:\n\t\t\t\t{\n\t\t\t\t\tuint16 value;\n\t\t\t\t\tenum TIFFReadDirEntryErr err;\n\t\t\t\t\terr=TIFFReadDirEntryShort(tif,dp,&value);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrCount)\n\t\t\t\t\t\terr=TIFFReadDirEntryPersampleShort(tif,dp,&value);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,TIFFFieldWithTag(tif,dp->tdir_tag)->field_name,0);\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t}\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_SMINSAMPLEVALUE:\n\t\t\tcase TIFFTAG_SMAXSAMPLEVALUE:\n\t\t\t\t{\n\t\t\t\t\tdouble value;\n\t\t\t\t\tenum TIFFReadDirEntryErr err;\n\t\t\t\t\terr=TIFFReadDirEntryPersampleDouble(tif,dp,&value);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,TIFFFieldWithTag(tif,dp->tdir_tag)->field_name,0);\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t}\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_STRIPOFFSETS:\n\t\t\tcase TIFFTAG_TILEOFFSETS:\n\t\t\t\tif (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripoffset))\n\t\t\t\t\tgoto bad;\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_STRIPBYTECOUNTS:\n\t\t\tcase TIFFTAG_TILEBYTECOUNTS:\n\t\t\t\tif (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripbytecount))\n\t\t\t\t\tgoto bad;\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_COLORMAP:\n\t\t\tcase TIFFTAG_TRANSFERFUNCTION:\n\t\t\t\t{\n\t\t\t\t\tenum TIFFReadDirEntryErr err;\n\t\t\t\t\tuint32 countpersample;\n\t\t\t\t\tuint32 countrequired;\n\t\t\t\t\tuint32 incrementpersample;\n\t\t\t\t\tuint16* value;\n\t\t\t\t\tcountpersample=(1L<<tif->tif_dir.td_bitspersample);\n\t\t\t\t\tif ((dp->tdir_tag==TIFFTAG_TRANSFERFUNCTION)&&(dp->tdir_count==(uint64)countpersample))\n\t\t\t\t\t{\n\t\t\t\t\t\tcountrequired=countpersample;\n\t\t\t\t\t\tincrementpersample=0;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tcountrequired=3*countpersample;\n\t\t\t\t\t\tincrementpersample=countpersample;\n\t\t\t\t\t}\n\t\t\t\t\tif (dp->tdir_count!=(uint64)countrequired)\n\t\t\t\t\t\terr=TIFFReadDirEntryErrCount;\n\t\t\t\t\telse\n\t\t\t\t\t\terr=TIFFReadDirEntryShortArray(tif,dp,&value);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,TIFFFieldWithTag(tif,dp->tdir_tag)->field_name,1);\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tTIFFSetField(tif,dp->tdir_tag,value,value+incrementpersample,value+2*incrementpersample);\n\t\t\t\t\t\t_TIFFfree(value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_OSUBFILETYPE:\n\t\t\t\t{\n\t\t\t\t\tuint16 valueo;\n\t\t\t\t\tuint32 value;\n\t\t\t\t\tif (TIFFReadDirEntryShort(tif,dp,&valueo)==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tswitch (valueo)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcase OFILETYPE_REDUCEDIMAGE: value=FILETYPE_REDUCEDIMAGE; break;\n\t\t\t\t\t\t\tcase OFILETYPE_PAGE: value=FILETYPE_PAGE; break;\n\t\t\t\t\t\t\tdefault: value=0; break;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (value!=0)\n\t\t\t\t\t\t\tTIFFSetField(tif,TIFFTAG_SUBFILETYPE,value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t(void) TIFFFetchNormalTag(tif, dp, TRUE);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tif (tif->tif_dir.td_compression==COMPRESSION_OJPEG)\n\t{\n\t\tif (!TIFFFieldSet(tif,FIELD_PHOTOMETRIC))\n\t\t{\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t "Photometric tag is missing, assuming data is YCbCr");\n\t\t\tif (!TIFFSetField(tif,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_YCBCR))\n\t\t\t\tgoto bad;\n\t\t}\n\t\telse if (tif->tif_dir.td_photometric==PHOTOMETRIC_RGB)\n\t\t{\n\t\t\ttif->tif_dir.td_photometric=PHOTOMETRIC_YCBCR;\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t "Photometric tag value assumed incorrect, "\n\t\t\t "assuming data is YCbCr instead of RGB");\n\t\t}\n\t\tif (!TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))\n\t\t{\n\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t "BitsPerSample tag is missing, assuming 8 bits per sample");\n\t\t\tif (!TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE,8))\n\t\t\t\tgoto bad;\n\t\t}\n\t\tif (!TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))\n\t\t{\n\t\t\tif ((tif->tif_dir.td_photometric==PHOTOMETRIC_RGB)\n\t\t\t || (tif->tif_dir.td_photometric==PHOTOMETRIC_YCBCR))\n\t\t\t{\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t "SamplesPerPixel tag is missing, "\n\t\t\t\t "assuming correct SamplesPerPixel value is 3");\n\t\t\t\tif (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,3))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\telse if ((tif->tif_dir.td_photometric==PHOTOMETRIC_MINISWHITE)\n\t\t\t\t || (tif->tif_dir.td_photometric==PHOTOMETRIC_MINISBLACK))\n\t\t\t{\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t "SamplesPerPixel tag is missing, "\n\t\t\t\t "assuming correct SamplesPerPixel value is 1");\n\t\t\t\tif (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,1))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t}\n\t}\n\tif (tif->tif_dir.td_photometric == PHOTOMETRIC_PALETTE &&\n\t !TIFFFieldSet(tif, FIELD_COLORMAP)) {\n\t\tMissingRequired(tif, "Colormap");\n\t\tgoto bad;\n\t}\n\tif (tif->tif_dir.td_compression!=COMPRESSION_OJPEG)\n\t{\n\t\tif (!TIFFFieldSet(tif, FIELD_STRIPBYTECOUNTS)) {\n\t\t\tif ((tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG &&\n\t\t\t tif->tif_dir.td_nstrips > 1) ||\n\t\t\t (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE &&\n\t\t\t tif->tif_dir.td_nstrips != (uint32)tif->tif_dir.td_samplesperpixel)) {\n\t\t\t MissingRequired(tif, "StripByteCounts");\n\t\t\t goto bad;\n\t\t\t}\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t\t"TIFF directory is missing required "\n\t\t\t\t"\\"%s\\" field, calculating from imagelength",\n\t\t\t\tTIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);\n\t\t\tif (EstimateStripByteCounts(tif, dir, dircount) < 0)\n\t\t\t goto bad;\n\t\t#define\tBYTECOUNTLOOKSBAD \\\n\t\t ( (tif->tif_dir.td_stripbytecount[0] == 0 && tif->tif_dir.td_stripoffset[0] != 0) || \\\n\t\t (tif->tif_dir.td_compression == COMPRESSION_NONE && \\\n\t\t tif->tif_dir.td_stripbytecount[0] > TIFFGetFileSize(tif) - tif->tif_dir.td_stripoffset[0]) || \\\n\t\t (tif->tif_mode == O_RDONLY && \\\n\t\t tif->tif_dir.td_compression == COMPRESSION_NONE && \\\n\t\t tif->tif_dir.td_stripbytecount[0] < TIFFScanlineSize64(tif) * tif->tif_dir.td_imagelength) )\n\t\t} else if (tif->tif_dir.td_nstrips == 1\n\t\t\t && tif->tif_dir.td_stripoffset[0] != 0\n\t\t\t && BYTECOUNTLOOKSBAD) {\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t "Bogus \\"%s\\" field, ignoring and calculating from imagelength",\n\t\t\t TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);\n\t\t\tif(EstimateStripByteCounts(tif, dir, dircount) < 0)\n\t\t\t goto bad;\n\t\t} else if (tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG\n\t\t\t && tif->tif_dir.td_nstrips > 2\n\t\t\t && tif->tif_dir.td_compression == COMPRESSION_NONE\n\t\t\t && tif->tif_dir.td_stripbytecount[0] != tif->tif_dir.td_stripbytecount[1]\n\t\t\t && tif->tif_dir.td_stripbytecount[0] != 0\n\t\t\t && tif->tif_dir.td_stripbytecount[1] != 0 ) {\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t "Wrong \\"%s\\" field, ignoring and calculating from imagelength",\n\t\t\t TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);\n\t\t\tif (EstimateStripByteCounts(tif, dir, dircount) < 0)\n\t\t\t goto bad;\n\t\t}\n\t}\n\tif (dir)\n\t{\n\t\t_TIFFfree(dir);\n\t\tdir=NULL;\n\t}\n\tif (!TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE))\n\t{\n\t\tif (tif->tif_dir.td_bitspersample>=16)\n\t\t\ttif->tif_dir.td_maxsamplevalue=0xFFFF;\n\t\telse\n\t\t\ttif->tif_dir.td_maxsamplevalue = (uint16)((1L<<tif->tif_dir.td_bitspersample)-1);\n\t}\n\tif (tif->tif_dir.td_nstrips > 1) {\n\t\tuint32 strip;\n\t\ttif->tif_dir.td_stripbytecountsorted = 1;\n\t\tfor (strip = 1; strip < tif->tif_dir.td_nstrips; strip++) {\n\t\t\tif (tif->tif_dir.td_stripoffset[strip - 1] >\n\t\t\t tif->tif_dir.td_stripoffset[strip]) {\n\t\t\t\ttif->tif_dir.td_stripbytecountsorted = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t(*tif->tif_fixuptags)(tif);\n\tif ((tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG)&&\n\t (tif->tif_dir.td_nstrips==1)&&\n\t (tif->tif_dir.td_compression==COMPRESSION_NONE)&&\n\t ((tif->tif_flags&(TIFF_STRIPCHOP|TIFF_ISTILED))==TIFF_STRIPCHOP))\n\t\tChopUpSingleUncompressedStrip(tif);\n\ttif->tif_flags &= ~TIFF_DIRTYDIRECT;\n\ttif->tif_flags &= ~TIFF_DIRTYSTRIP;\n\ttif->tif_row = (uint32) -1;\n\ttif->tif_curstrip = (uint32) -1;\n\ttif->tif_col = (uint32) -1;\n\ttif->tif_curtile = (uint32) -1;\n\ttif->tif_tilesize = (tmsize_t) -1;\n\ttif->tif_scanlinesize = TIFFScanlineSize(tif);\n\tif (!tif->tif_scanlinesize) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "Cannot handle zero scanline size");\n\t\treturn (0);\n\t}\n\tif (isTiled(tif)) {\n\t\ttif->tif_tilesize = TIFFTileSize(tif);\n\t\tif (!tif->tif_tilesize) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Cannot handle zero tile size");\n\t\t\treturn (0);\n\t\t}\n\t} else {\n\t\tif (!TIFFStripSize(tif)) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Cannot handle zero strip size");\n\t\t\treturn (0);\n\t\t}\n\t}\n\treturn (1);\nbad:\n\tif (dir)\n\t\t_TIFFfree(dir);\n\treturn (0);\n}', 'int\nTIFFDefaultDirectory(TIFF* tif)\n{\n\tregister TIFFDirectory* td = &tif->tif_dir;\n\tconst TIFFFieldArray* tiffFieldArray;\n\ttiffFieldArray = _TIFFGetFields();\n\t_TIFFSetupFields(tif, tiffFieldArray);\n\t_TIFFmemset(td, 0, sizeof (*td));\n\ttd->td_fillorder = FILLORDER_MSB2LSB;\n\ttd->td_bitspersample = 1;\n\ttd->td_threshholding = THRESHHOLD_BILEVEL;\n\ttd->td_orientation = ORIENTATION_TOPLEFT;\n\ttd->td_samplesperpixel = 1;\n\ttd->td_rowsperstrip = (uint32) -1;\n\ttd->td_tilewidth = 0;\n\ttd->td_tilelength = 0;\n\ttd->td_tiledepth = 1;\n\ttd->td_stripbytecountsorted = 1;\n\ttd->td_resolutionunit = RESUNIT_INCH;\n\ttd->td_sampleformat = SAMPLEFORMAT_UINT;\n\ttd->td_imagedepth = 1;\n\ttd->td_ycbcrsubsampling[0] = 2;\n\ttd->td_ycbcrsubsampling[1] = 2;\n\ttd->td_ycbcrpositioning = YCBCRPOSITION_CENTERED;\n\ttif->tif_postdecode = _TIFFNoPostDecode;\n\ttif->tif_foundfield = NULL;\n\ttif->tif_tagmethods.vsetfield = _TIFFVSetField;\n\ttif->tif_tagmethods.vgetfield = _TIFFVGetField;\n\ttif->tif_tagmethods.printdir = NULL;\n\tif (_TIFFextender)\n\t\t(*_TIFFextender)(tif);\n\t(void) TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);\n\ttif->tif_flags &= ~TIFF_DIRTYDIRECT;\n\ttif->tif_flags &= ~TIFF_ISTILED;\n\treturn (1);\n}', 'static int\nEstimateStripByteCounts(TIFF* tif, TIFFDirEntry* dir, uint16 dircount)\n{\n\tstatic const char module[] = "EstimateStripByteCounts";\n\tTIFFDirEntry *dp;\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 strip;\n\tif (td->td_stripbytecount)\n\t\t_TIFFfree(td->td_stripbytecount);\n\ttd->td_stripbytecount = (uint64*)\n\t _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64),\n\t\t"for \\"StripByteCounts\\" array");\n if( td->td_stripbytecount == NULL )\n return -1;\n\tif (td->td_compression != COMPRESSION_NONE) {\n\t\tuint64 space;\n\t\tuint64 filesize;\n\t\tuint16 n;\n\t\tfilesize = TIFFGetFileSize(tif);\n\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\tspace=sizeof(TIFFHeaderClassic)+2+dircount*12+4;\n\t\telse\n\t\t\tspace=sizeof(TIFFHeaderBig)+8+dircount*20+8;\n\t\tfor (dp = dir, n = dircount; n > 0; n--, dp++)\n\t\t{\n\t\t\tuint32 typewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type);\n\t\t\tuint64 datasize;\n\t\t\ttypewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type);\n\t\t\tif (typewidth == 0) {\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t "Cannot determine size of unknown tag type %d",\n\t\t\t\t dp->tdir_type);\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tdatasize=(uint64)typewidth*dp->tdir_count;\n\t\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\t{\n\t\t\t\tif (datasize<=4)\n\t\t\t\t\tdatasize=0;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tif (datasize<=8)\n\t\t\t\t\tdatasize=0;\n\t\t\t}\n\t\t\tspace+=datasize;\n\t\t}\n\t\tspace = filesize - space;\n\t\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\t\tspace /= td->td_samplesperpixel;\n\t\tfor (strip = 0; strip < td->td_nstrips; strip++)\n\t\t\ttd->td_stripbytecount[strip] = space;\n\t\tstrip--;\n\t\tif (td->td_stripoffset[strip]+td->td_stripbytecount[strip] > filesize)\n\t\t\ttd->td_stripbytecount[strip] = filesize - td->td_stripoffset[strip];\n\t} else if (isTiled(tif)) {\n\t\tuint64 bytespertile = TIFFTileSize64(tif);\n\t\tfor (strip = 0; strip < td->td_nstrips; strip++)\n\t\t td->td_stripbytecount[strip] = bytespertile;\n\t} else {\n\t\tuint64 rowbytes = TIFFScanlineSize64(tif);\n\t\tuint32 rowsperstrip = td->td_imagelength/td->td_stripsperimage;\n\t\tfor (strip = 0; strip < td->td_nstrips; strip++)\n\t\t\ttd->td_stripbytecount[strip] = rowbytes * rowsperstrip;\n\t}\n\tTIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);\n\tif (!TIFFFieldSet(tif, FIELD_ROWSPERSTRIP))\n\t\ttd->td_rowsperstrip = td->td_imagelength;\n\treturn 1;\n}'] |
34,389 | 0 | https://github.com/libav/libav/blob/3b2fbe67bd63b00331db2a9b213f6d420418a312/libavcodec/opus_celt.c/#L759 | static void celt_decode_allocation(CeltContext *s, OpusRangeCoder *rc)
{
int cap[CELT_MAX_BANDS];
int boost[CELT_MAX_BANDS];
int threshold[CELT_MAX_BANDS];
int bits1[CELT_MAX_BANDS];
int bits2[CELT_MAX_BANDS];
int trim_offset[CELT_MAX_BANDS];
int skip_startband = s->startband;
int dynalloc = 6;
int alloctrim = 5;
int extrabits = 0;
int skip_bit = 0;
int intensitystereo_bit = 0;
int dualstereo_bit = 0;
int remaining, bandbits;
int low, high, total, done;
int totalbits;
int consumed;
int i, j;
consumed = opus_rc_tell(rc);
s->spread = CELT_SPREAD_NORMAL;
if (consumed + 4 <= s->framebits)
s->spread = opus_rc_getsymbol(rc, celt_model_spread);
for (i = 0; i < CELT_MAX_BANDS; i++) {
cap[i] = (celt_static_caps[s->duration][s->coded_channels - 1][i] + 64)
* celt_freq_range[i] << (s->coded_channels - 1) << s->duration >> 2;
}
totalbits = s->framebits << 3;
consumed = opus_rc_tell_frac(rc);
for (i = s->startband; i < s->endband; i++) {
int quanta, band_dynalloc;
boost[i] = 0;
quanta = celt_freq_range[i] << (s->coded_channels - 1) << s->duration;
quanta = FFMIN(quanta << 3, FFMAX(6 << 3, quanta));
band_dynalloc = dynalloc;
while (consumed + (band_dynalloc<<3) < totalbits && boost[i] < cap[i]) {
int add = opus_rc_p2model(rc, band_dynalloc);
consumed = opus_rc_tell_frac(rc);
if (!add)
break;
boost[i] += quanta;
totalbits -= quanta;
band_dynalloc = 1;
}
if (boost[i])
dynalloc = FFMAX(2, dynalloc - 1);
}
if (consumed + (6 << 3) <= totalbits)
alloctrim = opus_rc_getsymbol(rc, celt_model_alloc_trim);
totalbits = (s->framebits << 3) - opus_rc_tell_frac(rc) - 1;
s->anticollapse_bit = 0;
if (s->blocks > 1 && s->duration >= 2 &&
totalbits >= ((s->duration + 2) << 3))
s->anticollapse_bit = 1 << 3;
totalbits -= s->anticollapse_bit;
if (totalbits >= 1 << 3)
skip_bit = 1 << 3;
totalbits -= skip_bit;
if (s->coded_channels == 2) {
intensitystereo_bit = celt_log2_frac[s->endband - s->startband];
if (intensitystereo_bit <= totalbits) {
totalbits -= intensitystereo_bit;
if (totalbits >= 1 << 3) {
dualstereo_bit = 1 << 3;
totalbits -= 1 << 3;
}
} else
intensitystereo_bit = 0;
}
for (i = s->startband; i < s->endband; i++) {
int trim = alloctrim - 5 - s->duration;
int band = celt_freq_range[i] * (s->endband - i - 1);
int duration = s->duration + 3;
int scale = duration + s->coded_channels - 1;
threshold[i] = FFMAX(3 * celt_freq_range[i] << duration >> 4,
s->coded_channels << 3);
trim_offset[i] = trim * (band << scale) >> 6;
if (celt_freq_range[i] << s->duration == 1)
trim_offset[i] -= s->coded_channels << 3;
}
low = 1;
high = CELT_VECTORS - 1;
while (low <= high) {
int center = (low + high) >> 1;
done = total = 0;
for (i = s->endband - 1; i >= s->startband; i--) {
bandbits = celt_freq_range[i] * celt_static_alloc[center][i]
<< (s->coded_channels - 1) << s->duration >> 2;
if (bandbits)
bandbits = FFMAX(0, bandbits + trim_offset[i]);
bandbits += boost[i];
if (bandbits >= threshold[i] || done) {
done = 1;
total += FFMIN(bandbits, cap[i]);
} else if (bandbits >= s->coded_channels << 3)
total += s->coded_channels << 3;
}
if (total > totalbits)
high = center - 1;
else
low = center + 1;
}
high = low--;
for (i = s->startband; i < s->endband; i++) {
bits1[i] = celt_freq_range[i] * celt_static_alloc[low][i]
<< (s->coded_channels - 1) << s->duration >> 2;
bits2[i] = high >= CELT_VECTORS ? cap[i] :
celt_freq_range[i] * celt_static_alloc[high][i]
<< (s->coded_channels - 1) << s->duration >> 2;
if (bits1[i])
bits1[i] = FFMAX(0, bits1[i] + trim_offset[i]);
if (bits2[i])
bits2[i] = FFMAX(0, bits2[i] + trim_offset[i]);
if (low)
bits1[i] += boost[i];
bits2[i] += boost[i];
if (boost[i])
skip_startband = i;
bits2[i] = FFMAX(0, bits2[i] - bits1[i]);
}
low = 0;
high = 1 << CELT_ALLOC_STEPS;
for (i = 0; i < CELT_ALLOC_STEPS; i++) {
int center = (low + high) >> 1;
done = total = 0;
for (j = s->endband - 1; j >= s->startband; j--) {
bandbits = bits1[j] + (center * bits2[j] >> CELT_ALLOC_STEPS);
if (bandbits >= threshold[j] || done) {
done = 1;
total += FFMIN(bandbits, cap[j]);
} else if (bandbits >= s->coded_channels << 3)
total += s->coded_channels << 3;
}
if (total > totalbits)
high = center;
else
low = center;
}
done = total = 0;
for (i = s->endband - 1; i >= s->startband; i--) {
bandbits = bits1[i] + (low * bits2[i] >> CELT_ALLOC_STEPS);
if (bandbits >= threshold[i] || done)
done = 1;
else
bandbits = (bandbits >= s->coded_channels << 3) ?
s->coded_channels << 3 : 0;
bandbits = FFMIN(bandbits, cap[i]);
s->pulses[i] = bandbits;
total += bandbits;
}
for (s->codedbands = s->endband; ; s->codedbands--) {
int allocation;
j = s->codedbands - 1;
if (j == skip_startband) {
totalbits += skip_bit;
break;
}
remaining = totalbits - total;
bandbits = remaining / (celt_freq_bands[j+1] - celt_freq_bands[s->startband]);
remaining -= bandbits * (celt_freq_bands[j+1] - celt_freq_bands[s->startband]);
allocation = s->pulses[j] + bandbits * celt_freq_range[j]
+ FFMAX(0, remaining - (celt_freq_bands[j] - celt_freq_bands[s->startband]));
if (allocation >= FFMAX(threshold[j], (s->coded_channels + 1) <<3 )) {
if (opus_rc_p2model(rc, 1))
break;
total += 1 << 3;
allocation -= 1 << 3;
}
total -= s->pulses[j];
if (intensitystereo_bit) {
total -= intensitystereo_bit;
intensitystereo_bit = celt_log2_frac[j - s->startband];
total += intensitystereo_bit;
}
total += s->pulses[j] = (allocation >= s->coded_channels << 3) ?
s->coded_channels << 3 : 0;
}
s->intensitystereo = 0;
s->dualstereo = 0;
if (intensitystereo_bit)
s->intensitystereo = s->startband +
opus_rc_unimodel(rc, s->codedbands + 1 - s->startband);
if (s->intensitystereo <= s->startband)
totalbits += dualstereo_bit;
else if (dualstereo_bit)
s->dualstereo = opus_rc_p2model(rc, 1);
remaining = totalbits - total;
bandbits = remaining / (celt_freq_bands[s->codedbands] - celt_freq_bands[s->startband]);
remaining -= bandbits * (celt_freq_bands[s->codedbands] - celt_freq_bands[s->startband]);
for (i = s->startband; i < s->codedbands; i++) {
int bits = FFMIN(remaining, celt_freq_range[i]);
s->pulses[i] += bits + bandbits * celt_freq_range[i];
remaining -= bits;
}
for (i = s->startband; i < s->codedbands; i++) {
int N = celt_freq_range[i] << s->duration;
int prev_extra = extrabits;
s->pulses[i] += extrabits;
if (N > 1) {
int dof;
int temp;
int offset;
int fine_bits, max_bits;
extrabits = FFMAX(0, s->pulses[i] - cap[i]);
s->pulses[i] -= extrabits;
dof = N * s->coded_channels
+ (s->coded_channels == 2 && N > 2 && !s->dualstereo && i < s->intensitystereo);
temp = dof * (celt_log_freq_range[i] + (s->duration<<3));
offset = (temp >> 1) - dof * CELT_FINE_OFFSET;
if (N == 2)
offset += dof<<1;
if (s->pulses[i] + offset < 2 * (dof << 3))
offset += temp >> 2;
else if (s->pulses[i] + offset < 3 * (dof << 3))
offset += temp >> 3;
fine_bits = (s->pulses[i] + offset + (dof << 2)) / (dof << 3);
max_bits = FFMIN((s->pulses[i]>>3) >> (s->coded_channels - 1),
CELT_MAX_FINE_BITS);
max_bits = FFMAX(max_bits, 0);
s->fine_bits[i] = av_clip(fine_bits, 0, max_bits);
s->fine_priority[i] = (s->fine_bits[i] * (dof<<3) >= s->pulses[i] + offset);
s->pulses[i] -= s->fine_bits[i] << (s->coded_channels - 1) << 3;
} else {
extrabits = FFMAX(0, s->pulses[i] - (s->coded_channels << 3));
s->pulses[i] -= extrabits;
s->fine_bits[i] = 0;
s->fine_priority[i] = 1;
}
if (extrabits > 0) {
int fineextra = FFMIN(extrabits >> (s->coded_channels + 2),
CELT_MAX_FINE_BITS - s->fine_bits[i]);
s->fine_bits[i] += fineextra;
fineextra <<= s->coded_channels + 2;
s->fine_priority[i] = (fineextra >= extrabits - prev_extra);
extrabits -= fineextra;
}
}
s->remaining = extrabits;
for (; i < s->endband; i++) {
s->fine_bits[i] = s->pulses[i] >> (s->coded_channels - 1) >> 3;
s->pulses[i] = 0;
s->fine_priority[i] = s->fine_bits[i] < 1;
}
} | ['static void celt_decode_allocation(CeltContext *s, OpusRangeCoder *rc)\n{\n int cap[CELT_MAX_BANDS];\n int boost[CELT_MAX_BANDS];\n int threshold[CELT_MAX_BANDS];\n int bits1[CELT_MAX_BANDS];\n int bits2[CELT_MAX_BANDS];\n int trim_offset[CELT_MAX_BANDS];\n int skip_startband = s->startband;\n int dynalloc = 6;\n int alloctrim = 5;\n int extrabits = 0;\n int skip_bit = 0;\n int intensitystereo_bit = 0;\n int dualstereo_bit = 0;\n int remaining, bandbits;\n int low, high, total, done;\n int totalbits;\n int consumed;\n int i, j;\n consumed = opus_rc_tell(rc);\n s->spread = CELT_SPREAD_NORMAL;\n if (consumed + 4 <= s->framebits)\n s->spread = opus_rc_getsymbol(rc, celt_model_spread);\n for (i = 0; i < CELT_MAX_BANDS; i++) {\n cap[i] = (celt_static_caps[s->duration][s->coded_channels - 1][i] + 64)\n * celt_freq_range[i] << (s->coded_channels - 1) << s->duration >> 2;\n }\n totalbits = s->framebits << 3;\n consumed = opus_rc_tell_frac(rc);\n for (i = s->startband; i < s->endband; i++) {\n int quanta, band_dynalloc;\n boost[i] = 0;\n quanta = celt_freq_range[i] << (s->coded_channels - 1) << s->duration;\n quanta = FFMIN(quanta << 3, FFMAX(6 << 3, quanta));\n band_dynalloc = dynalloc;\n while (consumed + (band_dynalloc<<3) < totalbits && boost[i] < cap[i]) {\n int add = opus_rc_p2model(rc, band_dynalloc);\n consumed = opus_rc_tell_frac(rc);\n if (!add)\n break;\n boost[i] += quanta;\n totalbits -= quanta;\n band_dynalloc = 1;\n }\n if (boost[i])\n dynalloc = FFMAX(2, dynalloc - 1);\n }\n if (consumed + (6 << 3) <= totalbits)\n alloctrim = opus_rc_getsymbol(rc, celt_model_alloc_trim);\n totalbits = (s->framebits << 3) - opus_rc_tell_frac(rc) - 1;\n s->anticollapse_bit = 0;\n if (s->blocks > 1 && s->duration >= 2 &&\n totalbits >= ((s->duration + 2) << 3))\n s->anticollapse_bit = 1 << 3;\n totalbits -= s->anticollapse_bit;\n if (totalbits >= 1 << 3)\n skip_bit = 1 << 3;\n totalbits -= skip_bit;\n if (s->coded_channels == 2) {\n intensitystereo_bit = celt_log2_frac[s->endband - s->startband];\n if (intensitystereo_bit <= totalbits) {\n totalbits -= intensitystereo_bit;\n if (totalbits >= 1 << 3) {\n dualstereo_bit = 1 << 3;\n totalbits -= 1 << 3;\n }\n } else\n intensitystereo_bit = 0;\n }\n for (i = s->startband; i < s->endband; i++) {\n int trim = alloctrim - 5 - s->duration;\n int band = celt_freq_range[i] * (s->endband - i - 1);\n int duration = s->duration + 3;\n int scale = duration + s->coded_channels - 1;\n threshold[i] = FFMAX(3 * celt_freq_range[i] << duration >> 4,\n s->coded_channels << 3);\n trim_offset[i] = trim * (band << scale) >> 6;\n if (celt_freq_range[i] << s->duration == 1)\n trim_offset[i] -= s->coded_channels << 3;\n }\n low = 1;\n high = CELT_VECTORS - 1;\n while (low <= high) {\n int center = (low + high) >> 1;\n done = total = 0;\n for (i = s->endband - 1; i >= s->startband; i--) {\n bandbits = celt_freq_range[i] * celt_static_alloc[center][i]\n << (s->coded_channels - 1) << s->duration >> 2;\n if (bandbits)\n bandbits = FFMAX(0, bandbits + trim_offset[i]);\n bandbits += boost[i];\n if (bandbits >= threshold[i] || done) {\n done = 1;\n total += FFMIN(bandbits, cap[i]);\n } else if (bandbits >= s->coded_channels << 3)\n total += s->coded_channels << 3;\n }\n if (total > totalbits)\n high = center - 1;\n else\n low = center + 1;\n }\n high = low--;\n for (i = s->startband; i < s->endband; i++) {\n bits1[i] = celt_freq_range[i] * celt_static_alloc[low][i]\n << (s->coded_channels - 1) << s->duration >> 2;\n bits2[i] = high >= CELT_VECTORS ? cap[i] :\n celt_freq_range[i] * celt_static_alloc[high][i]\n << (s->coded_channels - 1) << s->duration >> 2;\n if (bits1[i])\n bits1[i] = FFMAX(0, bits1[i] + trim_offset[i]);\n if (bits2[i])\n bits2[i] = FFMAX(0, bits2[i] + trim_offset[i]);\n if (low)\n bits1[i] += boost[i];\n bits2[i] += boost[i];\n if (boost[i])\n skip_startband = i;\n bits2[i] = FFMAX(0, bits2[i] - bits1[i]);\n }\n low = 0;\n high = 1 << CELT_ALLOC_STEPS;\n for (i = 0; i < CELT_ALLOC_STEPS; i++) {\n int center = (low + high) >> 1;\n done = total = 0;\n for (j = s->endband - 1; j >= s->startband; j--) {\n bandbits = bits1[j] + (center * bits2[j] >> CELT_ALLOC_STEPS);\n if (bandbits >= threshold[j] || done) {\n done = 1;\n total += FFMIN(bandbits, cap[j]);\n } else if (bandbits >= s->coded_channels << 3)\n total += s->coded_channels << 3;\n }\n if (total > totalbits)\n high = center;\n else\n low = center;\n }\n done = total = 0;\n for (i = s->endband - 1; i >= s->startband; i--) {\n bandbits = bits1[i] + (low * bits2[i] >> CELT_ALLOC_STEPS);\n if (bandbits >= threshold[i] || done)\n done = 1;\n else\n bandbits = (bandbits >= s->coded_channels << 3) ?\n s->coded_channels << 3 : 0;\n bandbits = FFMIN(bandbits, cap[i]);\n s->pulses[i] = bandbits;\n total += bandbits;\n }\n for (s->codedbands = s->endband; ; s->codedbands--) {\n int allocation;\n j = s->codedbands - 1;\n if (j == skip_startband) {\n totalbits += skip_bit;\n break;\n }\n remaining = totalbits - total;\n bandbits = remaining / (celt_freq_bands[j+1] - celt_freq_bands[s->startband]);\n remaining -= bandbits * (celt_freq_bands[j+1] - celt_freq_bands[s->startband]);\n allocation = s->pulses[j] + bandbits * celt_freq_range[j]\n + FFMAX(0, remaining - (celt_freq_bands[j] - celt_freq_bands[s->startband]));\n if (allocation >= FFMAX(threshold[j], (s->coded_channels + 1) <<3 )) {\n if (opus_rc_p2model(rc, 1))\n break;\n total += 1 << 3;\n allocation -= 1 << 3;\n }\n total -= s->pulses[j];\n if (intensitystereo_bit) {\n total -= intensitystereo_bit;\n intensitystereo_bit = celt_log2_frac[j - s->startband];\n total += intensitystereo_bit;\n }\n total += s->pulses[j] = (allocation >= s->coded_channels << 3) ?\n s->coded_channels << 3 : 0;\n }\n s->intensitystereo = 0;\n s->dualstereo = 0;\n if (intensitystereo_bit)\n s->intensitystereo = s->startband +\n opus_rc_unimodel(rc, s->codedbands + 1 - s->startband);\n if (s->intensitystereo <= s->startband)\n totalbits += dualstereo_bit;\n else if (dualstereo_bit)\n s->dualstereo = opus_rc_p2model(rc, 1);\n remaining = totalbits - total;\n bandbits = remaining / (celt_freq_bands[s->codedbands] - celt_freq_bands[s->startband]);\n remaining -= bandbits * (celt_freq_bands[s->codedbands] - celt_freq_bands[s->startband]);\n for (i = s->startband; i < s->codedbands; i++) {\n int bits = FFMIN(remaining, celt_freq_range[i]);\n s->pulses[i] += bits + bandbits * celt_freq_range[i];\n remaining -= bits;\n }\n for (i = s->startband; i < s->codedbands; i++) {\n int N = celt_freq_range[i] << s->duration;\n int prev_extra = extrabits;\n s->pulses[i] += extrabits;\n if (N > 1) {\n int dof;\n int temp;\n int offset;\n int fine_bits, max_bits;\n extrabits = FFMAX(0, s->pulses[i] - cap[i]);\n s->pulses[i] -= extrabits;\n dof = N * s->coded_channels\n + (s->coded_channels == 2 && N > 2 && !s->dualstereo && i < s->intensitystereo);\n temp = dof * (celt_log_freq_range[i] + (s->duration<<3));\n offset = (temp >> 1) - dof * CELT_FINE_OFFSET;\n if (N == 2)\n offset += dof<<1;\n if (s->pulses[i] + offset < 2 * (dof << 3))\n offset += temp >> 2;\n else if (s->pulses[i] + offset < 3 * (dof << 3))\n offset += temp >> 3;\n fine_bits = (s->pulses[i] + offset + (dof << 2)) / (dof << 3);\n max_bits = FFMIN((s->pulses[i]>>3) >> (s->coded_channels - 1),\n CELT_MAX_FINE_BITS);\n max_bits = FFMAX(max_bits, 0);\n s->fine_bits[i] = av_clip(fine_bits, 0, max_bits);\n s->fine_priority[i] = (s->fine_bits[i] * (dof<<3) >= s->pulses[i] + offset);\n s->pulses[i] -= s->fine_bits[i] << (s->coded_channels - 1) << 3;\n } else {\n extrabits = FFMAX(0, s->pulses[i] - (s->coded_channels << 3));\n s->pulses[i] -= extrabits;\n s->fine_bits[i] = 0;\n s->fine_priority[i] = 1;\n }\n if (extrabits > 0) {\n int fineextra = FFMIN(extrabits >> (s->coded_channels + 2),\n CELT_MAX_FINE_BITS - s->fine_bits[i]);\n s->fine_bits[i] += fineextra;\n fineextra <<= s->coded_channels + 2;\n s->fine_priority[i] = (fineextra >= extrabits - prev_extra);\n extrabits -= fineextra;\n }\n }\n s->remaining = extrabits;\n for (; i < s->endband; i++) {\n s->fine_bits[i] = s->pulses[i] >> (s->coded_channels - 1) >> 3;\n s->pulses[i] = 0;\n s->fine_priority[i] = s->fine_bits[i] < 1;\n }\n}'] |
34,390 | 0 | https://github.com/openssl/openssl/blob/313fce7b61ecaf5879cf84b256bdd0964134836e/crypto/bn/bn_ctx.c/#L353 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,\n\tBN_RECP_CTX *recp, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tBIGNUM *a;\n\tconst BIGNUM *ca;\n\tBN_CTX_start(ctx);\n\tif ((a = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (y != NULL)\n\t\t{\n\t\tif (x == y)\n\t\t\t{ if (!BN_sqr(a,x,ctx)) goto err; }\n\t\telse\n\t\t\t{ if (!BN_mul(a,x,y,ctx)) goto err; }\n\t\tca = a;\n\t\t}\n\telse\n\t\tca=x;\n\tret = BN_div_recp(NULL,r,ca,recp,ctx);\nerr:\n\tBN_CTX_end(ctx);\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,\n\tBN_RECP_CTX *recp, BN_CTX *ctx)\n\t{\n\tint i,j,ret=0;\n\tBIGNUM *a,*b,*d,*r;\n\tBN_CTX_start(ctx);\n\ta=BN_CTX_get(ctx);\n\tb=BN_CTX_get(ctx);\n\tif (dv != NULL)\n\t\td=dv;\n\telse\n\t\td=BN_CTX_get(ctx);\n\tif (rem != NULL)\n\t\tr=rem;\n\telse\n\t\tr=BN_CTX_get(ctx);\n\tif (a == NULL || b == NULL || d == NULL || r == NULL) goto err;\n\tif (BN_ucmp(m,&(recp->N)) < 0)\n\t\t{\n\t\tBN_zero(d);\n\t\tif (!BN_copy(r,m)) return 0;\n\t\tBN_CTX_end(ctx);\n\t\treturn(1);\n\t\t}\n\ti=BN_num_bits(m);\n\tj=recp->num_bits<<1;\n\tif (j>i) i=j;\n\tif (i != recp->shift)\n\t\trecp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),\n\t\t\ti,ctx);\n\tif (recp->shift == -1) goto err;\n\tif (!BN_rshift(a,m,recp->num_bits)) goto err;\n\tif (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;\n\tif (!BN_rshift(d,b,i-recp->num_bits)) goto err;\n\td->neg=0;\n\tif (!BN_mul(b,&(recp->N),d,ctx)) goto err;\n\tif (!BN_usub(r,m,b)) goto err;\n\tr->neg=0;\n#if 1\n\tj=0;\n\twhile (BN_ucmp(r,&(recp->N)) >= 0)\n\t\t{\n\t\tif (j++ > 2)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_DIV_RECP,BN_R_BAD_RECIPROCAL);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!BN_usub(r,r,&(recp->N))) goto err;\n\t\tif (!BN_add_word(d,1)) goto err;\n\t\t}\n#endif\n\tr->neg=BN_is_zero(r)?0:m->neg;\n\td->neg=m->neg^recp->N.neg;\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\tbn_check_top(dv);\n\tbn_check_top(rem);\n\treturn(ret);\n\t}', 'int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx)\n\t{\n\tint ret= -1;\n\tBIGNUM *t;\n\tBN_CTX_start(ctx);\n\tif((t = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (!BN_set_bit(t,len)) goto err;\n\tif (!BN_div(r,NULL,t,m,ctx)) goto err;\n\tret=len;\nerr:\n\tbn_check_top(r);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}'] |
34,391 | 0 | https://github.com/libav/libav/blob/89b35a139e838deeb32ec20d8d034c81014401d0/libavcodec/extract_extradata_bsf.c/#L47 | static int val_in_array(const int *arr, int len, int val)
{
int i;
for (i = 0; i < len; i++)
if (arr[i] == val)
return 1;
return 0;
} | ['static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,\n uint8_t **data, int *size)\n{\n static const int extradata_nal_types_hevc[] = {\n HEVC_NAL_VPS, HEVC_NAL_SPS, HEVC_NAL_PPS,\n };\n static const int extradata_nal_types_h264[] = {\n H264_NAL_SPS, H264_NAL_PPS,\n };\n ExtractExtradataContext *s = ctx->priv_data;\n H2645Packet h2645_pkt = { 0 };\n int extradata_size = 0;\n const int *extradata_nal_types;\n int nb_extradata_nal_types;\n int i, ret = 0;\n if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {\n extradata_nal_types = extradata_nal_types_hevc;\n nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_hevc);\n } else {\n extradata_nal_types = extradata_nal_types_h264;\n nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_h264);\n }\n ret = ff_h2645_packet_split(&h2645_pkt, pkt->data, pkt->size,\n ctx, 0, 0, ctx->par_in->codec_id);\n if (ret < 0)\n return ret;\n for (i = 0; i < h2645_pkt.nb_nals; i++) {\n H2645NAL *nal = &h2645_pkt.nals[i];\n if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type))\n extradata_size += nal->raw_size + 3;\n }\n if (extradata_size) {\n AVBufferRef *filtered_buf;\n uint8_t *extradata, *filtered_data;\n if (s->remove) {\n filtered_buf = av_buffer_alloc(pkt->size + AV_INPUT_BUFFER_PADDING_SIZE);\n if (!filtered_buf)\n goto fail;\n filtered_data = filtered_buf->data;\n }\n extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);\n if (!extradata) {\n av_buffer_unref(&filtered_buf);\n goto fail;\n }\n *data = extradata;\n *size = extradata_size;\n for (i = 0; i < h2645_pkt.nb_nals; i++) {\n H2645NAL *nal = &h2645_pkt.nals[i];\n if (val_in_array(extradata_nal_types, nb_extradata_nal_types,\n nal->type)) {\n AV_WB24(extradata, 1);\n memcpy(extradata + 3, nal->raw_data, nal->raw_size);\n extradata += 3 + nal->raw_size;\n } else if (s->remove) {\n AV_WB24(filtered_data, 1);\n memcpy(filtered_data + 3, nal->raw_data, nal->raw_size);\n filtered_data += 3 + nal->raw_size;\n }\n }\n if (s->remove) {\n av_buffer_unref(&pkt->buf);\n pkt->buf = filtered_buf;\n pkt->data = filtered_buf->data;\n pkt->size = filtered_data - filtered_buf->data;\n }\n }\nfail:\n ff_h2645_packet_uninit(&h2645_pkt);\n return ret;\n}', 'static int val_in_array(const int *arr, int len, int val)\n{\n int i;\n for (i = 0; i < len; i++)\n if (arr[i] == val)\n return 1;\n return 0;\n}'] |
34,392 | 0 | https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/bn/bn_lib.c/#L759 | int bn_cmp_words(BN_ULONG *a, BN_ULONG *b, int n)
{
int i;
BN_ULONG aa,bb;
aa=a[n-1];
bb=b[n-1];
if (aa != bb) return((aa > bb)?1:-1);
for (i=n-2; i>=0; i--)
{
aa=a[i];
bb=b[i];
if (aa != bb) return((aa > bb)?1:-1);
}
return(0);
} | ['int test_mod_exp(BIO *bp, BN_CTX *ctx)\n\t{\n\tBIGNUM *a,*b,*c,*d,*e;\n\tint i;\n\ta=BN_new();\n\tb=BN_new();\n\tc=BN_new();\n\td=BN_new();\n\te=BN_new();\n\tBN_rand(c,30,0,1);\n\tfor (i=0; i<6; i++)\n\t\t{\n\t\tBN_rand(a,20+i*5,0,0);\n\t\tBN_rand(b,2+i,0,0);\n\t\tif (!BN_mod_exp(d,a,b,c,ctx))\n\t\t\treturn(00);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,a);\n\t\t\t\tBIO_puts(bp," ^ ");\n\t\t\t\tBN_print(bp,b);\n\t\t\t\tBIO_puts(bp," % ");\n\t\t\t\tBN_print(bp,c);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,d);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\t}\n\tBN_free(a);\n\tBN_free(b);\n\tBN_free(c);\n\tBN_free(d);\n\tBN_free(e);\n\treturn(1);\n\t}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n\t{\n\tunsigned char *buf=NULL;\n\tint ret=0,bit,bytes,mask;\n\ttime_t tim;\n\tbytes=(bits+7)/8;\n\tbit=(bits-1)%8;\n\tmask=0xff<<bit;\n\tbuf=(unsigned char *)Malloc(bytes);\n\tif (buf == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\ttime(&tim);\n\tRAND_seed(&tim,sizeof(tim));\n\tRAND_bytes(buf,(int)bytes);\n\tif (top)\n\t\t{\n\t\tif (bit == 0)\n\t\t\t{\n\t\t\tbuf[0]=1;\n\t\t\tbuf[1]|=0x80;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbuf[0]|=(3<<(bit-1));\n\t\t\tbuf[0]&= ~(mask<<1);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tbuf[0]|=(1<<bit);\n\t\tbuf[0]&= ~(mask<<1);\n\t\t}\n\tif (bottom)\n\t\tbuf[bytes-1]|=1;\n\tif (!BN_bin2bn(buf,bytes,rnd)) goto err;\n\tret=1;\nerr:\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bytes);\n\t\tFree(buf);\n\t\t}\n\treturn(ret);\n\t}', 'int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{ ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL); }\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx,\n\t BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *d,*aa,*r;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\td= &(ctx->bn[ctx->tos++]);\n\tr= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n#if 1\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n#endif\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tBN_init(&val[0]);\n\tts=1;\n\tif (BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[0]),a,m,ctx);\n\t\taa= &(val[0]);\n\t\t}\n\telse\n\t\taa=a;\n\tif (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err;\n\tif (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err;\n\tif (bits <= 20)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&(val[i]));\n\t\tif (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tBN_from_montgomery(rr,r,mont,ctx);\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tctx->tos-=2;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\treturn(ret);\n\t}', 'int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)\n\t{\n#if 0\n\tint i,nm,nd;\n\tBIGNUM *dv;\n\tif (BN_ucmp(m,d) < 0)\n\t\treturn((BN_copy(rem,m) == NULL)?0:1);\n\tdv= &(ctx->bn[ctx->tos]);\n\tif (!BN_copy(rem,m)) return(0);\n\tnm=BN_num_bits(rem);\n\tnd=BN_num_bits(d);\n\tif (!BN_lshift(dv,d,nm-nd)) return(0);\n\tfor (i=nm-nd; i>=0; i--)\n\t\t{\n\t\tif (BN_cmp(rem,dv) >= 0)\n\t\t\t{\n\t\t\tif (!BN_sub(rem,rem,dv)) return(0);\n\t\t\t}\n\t\tif (!BN_rshift1(dv,dv)) return(0);\n\t\t}\n\treturn(1);\n#else\n\treturn(BN_div(NULL,rem,m,d,ctx));\n#endif\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, BIGNUM *num, BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,j,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\ttmp= &(ctx->bn[ctx->tos]);\n\ttmp->neg=0;\n\tsnum= &(ctx->bn[ctx->tos+1]);\n\tsdiv= &(ctx->bn[ctx->tos+2]);\n\tif (dv == NULL)\n\t\tres= &(ctx->bn[ctx->tos+3]);\n\telse\tres=dv;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tBN_lshift(sdiv,divisor,norm_shift);\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tBN_lshift(snum,num,norm_shift);\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\tBN_init(&wnum);\n\twnum.d=\t &(snum->d[loop]);\n\twnum.top= div_n;\n\twnum.max= snum->max+1;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tif (!BN_usub(&wnum,&wnum,sdiv)) goto err;\n\t\t*resp=1;\n\t\tres->d[res->top-1]=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tresp--;\n\tfor (i=0; i<loop-1; i++)\n\t\t{\n\t\tBN_ULONG q,n0,n1;\n\t\tBN_ULONG l0;\n\t\twnum.d--; wnum.top++;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\tq=bn_div_words(n0,n1,d0);\n\t\t{\n#ifdef BN_LLONG\n\t\tBN_ULLONG t1,t2,rem;\n\t\tt1=((BN_ULLONG)n0<<BN_BITS2)|n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\trem=t1-(BN_ULLONG)q*d0;\n\t\t\tif ((rem>>BN_BITS2) ||\n\t\t\t\t(t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\t}\n#else\n\t\tBN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;\n\t\tt1h=n0;\n\t\tt1l=n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\tt3t=LBITS(d0); t3h=HBITS(d0);\n\t\t\tmul64(t3t,t3h,ql,qh);\n\t\t\tt3l=(t1l-t3t)&BN_MASK2;\n\t\t\tif (t3l > t1l) t3h++;\n\t\t\tt3h=(t1h-t3h)&BN_MASK2;\n\t\t\tif (t3h) break;\n\t\t\tif (t2h < t3l) break;\n\t\t\tif ((t2h == t3l) && (t2l <= wnump[-2])) break;\n\t\t\tq--;\n\t\t\t}\n#endif\n\t\t}\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\tfor (j=div_n+1; j>0; j--)\n\t\t\tif (tmp->d[j-1]) break;\n\t\ttmp->top=j;\n\t\tj=wnum.top;\n\t\tBN_sub(&wnum,&wnum,tmp);\n\t\tsnum->top=snum->top+wnum.top-j;\n\t\tif (wnum.neg)\n\t\t\t{\n\t\t\tq--;\n\t\t\tj=wnum.top;\n\t\t\tBN_add(&wnum,&wnum,sdiv);\n\t\t\tsnum->top+=wnum.top-j;\n\t\t\t}\n\t\t*(resp--)=q;\n\t\twnump--;\n\t\t}\n\tif (rm != NULL)\n\t\t{\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\trm->neg=num->neg;\n\t\t}\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_MONT_CTX *mont,\n\t BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp,*tmp2;\n tmp= &(ctx->bn[ctx->tos]);\n tmp2= &(ctx->bn[ctx->tos]);\n\tctx->tos+=2;\n\tbn_check_top(tmp);\n\tbn_check_top(tmp2);\n\tif (a == b)\n\t\t{\n#if 0\n\t\tbn_wexpand(tmp,a->top*2);\n\t\tbn_wexpand(tmp2,a->top*4);\n\t\tbn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);\n\t\ttmp->top=a->top*2;\n\t\tif (tmp->d[tmp->top-1] == 0)\n\t\t\ttmp->top--;\n#else\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n\tctx->tos-=2;\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,\n\t int n, BN_ULONG *t)\n\t{\n\tint i,j,n2=n*2;\n\tunsigned int c1;\n\tBN_ULONG ln,lo,*p;\n#ifdef BN_COUNT\nprintf(" bn_mul_part_recursive %d * %d\\n",tn+n,tn+n);\n#endif\n\tif (n < 8)\n\t\t{\n\t\ti=tn+n;\n\t\tbn_mul_normal(r,a,i,b,i);\n\t\treturn;\n\t\t}\n\tbn_sub_words(t, a, &(a[n]),n);\n\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n if (n == 8)\n\t\t{\n\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\tmemset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));\n\t\t}\n\telse\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);\n\t\tbn_mul_recursive(r,a,b,n,p);\n\t\ti=n/2;\n\t\tj=tn-i;\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p);\n\t\t\tmemset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));\n\t\t\t}\n\t\telse if (j > 0)\n\t\t\t\t{\n\t\t\t\tbn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\t\tj,i,p);\n\t\t\t\tmemset(&(r[n2+tn*2]),0,\n\t\t\t\t\tsizeof(BN_ULONG)*(n2-tn*2));\n\t\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tmemset(&(r[n2]),0,sizeof(BN_ULONG)*n2);\n\t\t\tif (tn < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t\t\t{\n\t\t\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tfor (;;)\n\t\t\t\t\t{\n\t\t\t\t\ti/=2;\n\t\t\t\t\tif (i < tn)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_part_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ttn-i,i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (i == tn)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ti,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,\n\t BN_ULONG *t)\n\t{\n\tint n=n2/2,c1,c2;\n\tunsigned int neg,zero;\n\tBN_ULONG ln,lo,*p;\n#ifdef BN_COUNT\nprintf(" bn_mul_recursive %d * %d\\n",n2,n2);\n#endif\n#ifdef BN_MUL_COMBA\n if (n2 == 8)\n\t\t{\n\t\tbn_mul_comba8(r,a,b);\n\t\treturn;\n\t\t}\n#endif\n\tif (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t{\n\t\tbn_mul_normal(r,a,n2,b,n2);\n\t\treturn;\n\t\t}\n\tc1=bn_cmp_words(a,&(a[n]),n);\n\tc2=bn_cmp_words(&(b[n]),b,n);\n\tzero=neg=0;\n\tswitch (c1*3+c2)\n\t\t{\n\tcase -4:\n\t\tbn_sub_words(t, &(a[n]),a, n);\n\t\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n\t\tbreak;\n\tcase -3:\n\t\tzero=1;\n\t\tbreak;\n\tcase -2:\n\t\tbn_sub_words(t, &(a[n]),a, n);\n\t\tbn_sub_words(&(t[n]),&(b[n]),b, n);\n\t\tneg=1;\n\t\tbreak;\n\tcase -1:\n\tcase 0:\n\tcase 1:\n\t\tzero=1;\n\t\tbreak;\n\tcase 2:\n\t\tbn_sub_words(t, a, &(a[n]),n);\n\t\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n\t\tneg=1;\n\t\tbreak;\n\tcase 3:\n\t\tzero=1;\n\t\tbreak;\n\tcase 4:\n\t\tbn_sub_words(t, a, &(a[n]),n);\n\t\tbn_sub_words(&(t[n]),&(b[n]),b, n);\n\t\tbreak;\n\t\t}\n#ifdef BN_MUL_COMBA\n\tif (n == 4)\n\t\t{\n\t\tif (!zero)\n\t\t\tbn_mul_comba4(&(t[n2]),t,&(t[n]));\n\t\telse\n\t\t\tmemset(&(t[n2]),0,8*sizeof(BN_ULONG));\n\t\tbn_mul_comba4(r,a,b);\n\t\tbn_mul_comba4(&(r[n2]),&(a[n]),&(b[n]));\n\t\t}\n\telse if (n == 8)\n\t\t{\n\t\tif (!zero)\n\t\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\telse\n\t\t\tmemset(&(t[n2]),0,16*sizeof(BN_ULONG));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_comba8(&(r[n2]),&(a[n]),&(b[n]));\n\t\t}\n\telse\n#endif\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tif (!zero)\n\t\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);\n\t\telse\n\t\t\tmemset(&(t[n2]),0,n2*sizeof(BN_ULONG));\n\t\tbn_mul_recursive(r,a,b,n,p);\n\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p);\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tif (neg)\n\t\t{\n\t\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\t\t}\n\telse\n\t\t{\n\t\tc1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));\n\t\t}\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < (BN_ULONG)c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'int bn_cmp_words(BN_ULONG *a, BN_ULONG *b, int n)\n\t{\n\tint i;\n\tBN_ULONG aa,bb;\n\taa=a[n-1];\n\tbb=b[n-1];\n\tif (aa != bb) return((aa > bb)?1:-1);\n\tfor (i=n-2; i>=0; i--)\n\t\t{\n\t\taa=a[i];\n\t\tbb=b[i];\n\t\tif (aa != bb) return((aa > bb)?1:-1);\n\t\t}\n\treturn(0);\n\t}'] |
34,393 | 0 | https://github.com/openssl/openssl/blob/9b340281873643d2b8a33047dc8bfa607f7e0c3c/crypto/lhash/lhash.c/#L191 | static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
OPENSSL_LH_DOALL_FUNC func,
OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)
{
int i;
OPENSSL_LH_NODE *a, *n;
if (lh == NULL)
return;
for (i = lh->num_nodes - 1; i >= 0; i--) {
a = lh->b[i];
while (a != NULL) {
n = a->next;
if (use_arg)
func_arg(a->data, arg);
else
func(a->data);
a = n;
}
}
} | ['static int test_dtls_unprocessed(int testidx)\n{\n SSL_CTX *sctx = NULL, *cctx = NULL;\n SSL *serverssl1 = NULL, *clientssl1 = NULL;\n BIO *c_to_s_fbio, *c_to_s_mempacket;\n int testresult = 0;\n timer_cb_count = 0;\n if (!TEST_true(create_ssl_ctx_pair(DTLS_server_method(),\n DTLS_client_method(),\n DTLS1_VERSION, DTLS_MAX_VERSION,\n &sctx, &cctx, cert, privkey)))\n return 0;\n if (!TEST_true(SSL_CTX_set_cipher_list(cctx, "AES128-SHA")))\n goto end;\n c_to_s_fbio = BIO_new(bio_f_tls_dump_filter());\n if (!TEST_ptr(c_to_s_fbio))\n goto end;\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1,\n NULL, c_to_s_fbio)))\n goto end;\n DTLS_set_timer_cb(clientssl1, timer_cb);\n if (testidx == 1)\n certstatus[RECORD_SEQUENCE] = 0xff;\n c_to_s_mempacket = SSL_get_wbio(clientssl1);\n c_to_s_mempacket = BIO_next(c_to_s_mempacket);\n mempacket_test_inject(c_to_s_mempacket, (char *)certstatus,\n sizeof(certstatus), 1, INJECT_PACKET_IGNORE_REC_SEQ);\n if (!TEST_true(create_ssl_connection(serverssl1, clientssl1,\n SSL_ERROR_NONE)))\n goto end;\n if (timer_cb_count == 0) {\n printf("timer_callback was not called.\\n");\n goto end;\n }\n testresult = 1;\n end:\n SSL_free(serverssl1);\n SSL_free(clientssl1);\n SSL_CTX_free(sctx);\n SSL_CTX_free(cctx);\n return testresult;\n}', 'int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,\n SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)\n{\n SSL *serverssl = NULL, *clientssl = NULL;\n BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;\n if (*sssl != NULL)\n serverssl = *sssl;\n else if (!TEST_ptr(serverssl = SSL_new(serverctx)))\n goto error;\n if (*cssl != NULL)\n clientssl = *cssl;\n else if (!TEST_ptr(clientssl = SSL_new(clientctx)))\n goto error;\n if (SSL_is_dtls(clientssl)) {\n if (!TEST_ptr(s_to_c_bio = BIO_new(bio_s_mempacket_test()))\n || !TEST_ptr(c_to_s_bio = BIO_new(bio_s_mempacket_test())))\n goto error;\n } else {\n if (!TEST_ptr(s_to_c_bio = BIO_new(BIO_s_mem()))\n || !TEST_ptr(c_to_s_bio = BIO_new(BIO_s_mem())))\n goto error;\n }\n if (s_to_c_fbio != NULL\n && !TEST_ptr(s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio)))\n goto error;\n if (c_to_s_fbio != NULL\n && !TEST_ptr(c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio)))\n goto error;\n BIO_set_mem_eof_return(s_to_c_bio, -1);\n BIO_set_mem_eof_return(c_to_s_bio, -1);\n SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);\n BIO_up_ref(s_to_c_bio);\n BIO_up_ref(c_to_s_bio);\n SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);\n *sssl = serverssl;\n *cssl = clientssl;\n return 1;\n error:\n SSL_free(serverssl);\n SSL_free(clientssl);\n BIO_free(s_to_c_bio);\n BIO_free(c_to_s_bio);\n BIO_free(s_to_c_fbio);\n BIO_free(c_to_s_fbio);\n return 0;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return NULL;\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return NULL;\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->references = 1;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL) {\n OPENSSL_free(s);\n s = NULL;\n goto err;\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->dane.flags = ctx->dane.flags;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->max_early_data = ctx->max_early_data;\n s->recv_max_early_data = ctx->recv_max_early_data;\n s->num_tickets = ctx->num_tickets;\n s->pha_enabled = ctx->pha_enabled;\n s->tls13_ciphersuites = sk_SSL_CIPHER_dup(ctx->tls13_ciphersuites);\n if (s->tls13_ciphersuites == NULL)\n goto err;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n s->msg_callback = ctx->msg_callback;\n s->msg_callback_arg = ctx->msg_callback_arg;\n s->verify_mode = ctx->verify_mode;\n s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n s->record_padding_cb = ctx->record_padding_cb;\n s->record_padding_arg = ctx->record_padding_arg;\n s->block_padding = ctx->block_padding;\n s->sid_ctx_length = ctx->sid_ctx_length;\n if (!ossl_assert(s->sid_ctx_length <= sizeof(s->sid_ctx)))\n goto err;\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->ext.max_fragment_len_mode = ctx->ext.max_fragment_len_mode;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->ext.debug_cb = 0;\n s->ext.debug_arg = NULL;\n s->ext.ticket_expected = 0;\n s->ext.status_type = ctx->ext.status_type;\n s->ext.status_expected = 0;\n s->ext.ocsp.ids = NULL;\n s->ext.ocsp.exts = NULL;\n s->ext.ocsp.resp = NULL;\n s->ext.ocsp.resp_len = 0;\n SSL_CTX_up_ref(ctx);\n s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n if (ctx->ext.ecpointformats) {\n s->ext.ecpointformats =\n OPENSSL_memdup(ctx->ext.ecpointformats,\n ctx->ext.ecpointformats_len);\n if (!s->ext.ecpointformats)\n goto err;\n s->ext.ecpointformats_len =\n ctx->ext.ecpointformats_len;\n }\n if (ctx->ext.supportedgroups) {\n s->ext.supportedgroups =\n OPENSSL_memdup(ctx->ext.supportedgroups,\n ctx->ext.supportedgroups_len\n * sizeof(*ctx->ext.supportedgroups));\n if (!s->ext.supportedgroups)\n goto err;\n s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n s->ext.npn = NULL;\n#endif\n if (s->ctx->ext.alpn) {\n s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n if (s->ext.alpn == NULL)\n goto err;\n memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n s->ext.alpn_len = s->ctx->ext.alpn_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n s->key_update = SSL_KEY_UPDATE_NONE;\n s->allow_early_data_cb = ctx->allow_early_data_cb;\n s->allow_early_data_cb_data = ctx->allow_early_data_cb_data;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->psk_find_session_cb = ctx->psk_find_session_cb;\n s->psk_use_session_cb = ctx->psk_use_session_cb;\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n RECORD_LAYER_release(&s->rlayer);\n ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n s->wbio = NULL;\n BIO_free_all(s->rbio);\n s->rbio = NULL;\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n sk_SSL_CIPHER_free(s->tls13_ciphersuites);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n SSL_SESSION_free(s->psksession);\n OPENSSL_free(s->psksession_id);\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->ext.hostname);\n SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->ext.ecpointformats);\n OPENSSL_free(s->ext.supportedgroups);\n#endif\n sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->ext.scts);\n#endif\n OPENSSL_free(s->ext.ocsp.resp);\n OPENSSL_free(s->ext.alpn);\n OPENSSL_free(s->ext.tls13_cookie);\n OPENSSL_free(s->clienthello);\n OPENSSL_free(s->pha_context);\n EVP_MD_CTX_free(s->pha_dgst);\n sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(s->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n int i;\n if (a == NULL)\n return;\n CRYPTO_DOWN_REF(&a->references, &i, a->lock);\n REF_PRINT_COUNT("SSL_CTX", a);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(a->param);\n dane_ctx_final(&a->dane);\n if (a->sessions != NULL)\n SSL_CTX_flush_sessions(a, 0);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n lh_SSL_SESSION_free(a->sessions);\n X509_STORE_free(a->cert_store);\n#ifndef OPENSSL_NO_CT\n CTLOG_STORE_free(a->ctlog_store);\n#endif\n sk_SSL_CIPHER_free(a->cipher_list);\n sk_SSL_CIPHER_free(a->cipher_list_by_id);\n sk_SSL_CIPHER_free(a->tls13_ciphersuites);\n ssl_cert_free(a->cert);\n sk_X509_NAME_pop_free(a->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(a->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(a->extra_certs, X509_free);\n a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(a->ext.ecpointformats);\n OPENSSL_free(a->ext.supportedgroups);\n#endif\n OPENSSL_free(a->ext.alpn);\n OPENSSL_secure_free(a->ext.secure);\n CRYPTO_THREAD_lock_free(a->lock);\n OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n unsigned long i;\n TIMEOUT_PARAM tp;\n tp.ctx = s;\n tp.cache = s->sessions;\n if (tp.cache == NULL)\n return;\n tp.time = t;\n CRYPTO_THREAD_write_lock(s->lock);\n i = lh_SSL_SESSION_get_down_load(s->sessions);\n lh_SSL_SESSION_set_down_load(s->sessions, 0);\n lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);\n lh_SSL_SESSION_set_down_load(s->sessions, i);\n CRYPTO_THREAD_unlock(s->lock);\n}', 'IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM)', 'void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)\n{\n doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);\n}', 'static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,\n OPENSSL_LH_DOALL_FUNC func,\n OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)\n{\n int i;\n OPENSSL_LH_NODE *a, *n;\n if (lh == NULL)\n return;\n for (i = lh->num_nodes - 1; i >= 0; i--) {\n a = lh->b[i];\n while (a != NULL) {\n n = a->next;\n if (use_arg)\n func_arg(a->data, arg);\n else\n func(a->data);\n a = n;\n }\n }\n}'] |
34,394 | 0 | https://github.com/libav/libav/blob/04f691cd4fb7d226e54df886a21ba201cb5019f4/libswscale/utils.c/#L209 | int sws_isSupportedInput(enum AVPixelFormat pix_fmt)
{
return (unsigned)pix_fmt < AV_PIX_FMT_NB ?
format_entries[pix_fmt].is_supported_in : 0;
} | ['static int query_formats(AVFilterContext *ctx)\n{\n AVFilterFormats *formats;\n enum AVPixelFormat pix_fmt;\n int ret;\n if (ctx->inputs[0]) {\n const AVPixFmtDescriptor *desc = NULL;\n formats = NULL;\n while ((desc = av_pix_fmt_desc_next(desc))) {\n pix_fmt = av_pix_fmt_desc_get_id(desc);\n if ((sws_isSupportedInput(pix_fmt) ||\n sws_isSupportedEndiannessConversion(pix_fmt))\n && (ret = ff_add_format(&formats, pix_fmt)) < 0) {\n ff_formats_unref(&formats);\n return ret;\n }\n }\n ff_formats_ref(formats, &ctx->inputs[0]->out_formats);\n }\n if (ctx->outputs[0]) {\n const AVPixFmtDescriptor *desc = NULL;\n formats = NULL;\n while ((desc = av_pix_fmt_desc_next(desc))) {\n pix_fmt = av_pix_fmt_desc_get_id(desc);\n if ((sws_isSupportedOutput(pix_fmt) ||\n sws_isSupportedEndiannessConversion(pix_fmt))\n && (ret = ff_add_format(&formats, pix_fmt)) < 0) {\n ff_formats_unref(&formats);\n return ret;\n }\n }\n ff_formats_ref(formats, &ctx->outputs[0]->in_formats);\n }\n return 0;\n}', 'enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)\n{\n if (desc < av_pix_fmt_descriptors ||\n desc >= av_pix_fmt_descriptors + FF_ARRAY_ELEMS(av_pix_fmt_descriptors))\n return AV_PIX_FMT_NONE;\n return desc - av_pix_fmt_descriptors;\n}', 'int sws_isSupportedInput(enum AVPixelFormat pix_fmt)\n{\n return (unsigned)pix_fmt < AV_PIX_FMT_NB ?\n format_entries[pix_fmt].is_supported_in : 0;\n}'] |
34,395 | 0 | https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_lib.c/#L260 | static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
} | ['BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)\n{\n#ifndef BN_LLONG\n BN_ULONG ret = 0;\n#else\n BN_ULLONG ret = 0;\n#endif\n int i;\n if (w == 0)\n return (BN_ULONG)-1;\n#ifndef BN_LLONG\n if (w > ((BN_ULONG)1 << BN_BITS4)) {\n BIGNUM *tmp = BN_dup(a);\n if (tmp == NULL)\n return (BN_ULONG)-1;\n ret = BN_div_word(tmp, w);\n BN_free(tmp);\n return ret;\n }\n#endif\n bn_check_top(a);\n w &= BN_MASK2;\n for (i = a->top - 1; i >= 0; i--) {\n#ifndef BN_LLONG\n ret = ((ret << BN_BITS4) | ((a->d[i] >> BN_BITS4) & BN_MASK2l)) % w;\n ret = ((ret << BN_BITS4) | (a->d[i] & BN_MASK2l)) % w;\n#else\n ret = (BN_ULLONG) (((ret << (BN_ULLONG) BN_BITS2) | a->d[i]) %\n (BN_ULLONG) w);\n#endif\n }\n return (BN_ULONG)ret;\n}', 'BIGNUM *BN_dup(const BIGNUM *a)\n{\n BIGNUM *t;\n if (a == NULL)\n return NULL;\n bn_check_top(a);\n t = BN_get_flags(a, BN_FLG_SECURE) ? BN_secure_new() : BN_new();\n if (t == NULL)\n return NULL;\n if (!BN_copy(t, a)) {\n BN_free(t);\n return NULL;\n }\n bn_check_top(t);\n return t;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(a, BN_FLG_CONSTTIME);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)\n{\n BN_ULONG ret = 0;\n int i, j;\n bn_check_top(a);\n w &= BN_MASK2;\n if (!w)\n return (BN_ULONG)-1;\n if (a->top == 0)\n return 0;\n j = BN_BITS2 - BN_num_bits_word(w);\n w <<= j;\n if (!BN_lshift(a, a, j))\n return (BN_ULONG)-1;\n for (i = a->top - 1; i >= 0; i--) {\n BN_ULONG l, d;\n l = a->d[i];\n d = bn_div_words(ret, l, w);\n ret = (l - ((d * w) & BN_MASK2)) & BN_MASK2;\n a->d[i] = d;\n }\n if ((a->top > 0) && (a->d[a->top - 1] == 0))\n a->top--;\n ret >>= j;\n if (!a->top)\n a->neg = 0;\n bn_check_top(a);\n return ret;\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return 0;\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}'] |
34,396 | 0 | https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/bn/bn_lib.c/#L377 | BIGNUM *bn_expand2(BIGNUM *b, int words)
{
BN_ULONG *A,*B,*a;
int i,j;
bn_check_top(b);
if (words > b->max)
{
bn_check_top(b);
if (BN_get_flags(b,BN_FLG_STATIC_DATA))
{
BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return(NULL);
}
a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));
if (A == NULL)
{
BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);
return(NULL);
}
memset(A,0x5c,sizeof(BN_ULONG)*(words+1));
#if 1
B=b->d;
if (B != NULL)
{
for (i=b->top&(~7); i>0; i-=8)
{
A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];
A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];
A+=8;
B+=8;
}
switch (b->top&7)
{
case 7:
A[6]=B[6];
case 6:
A[5]=B[5];
case 5:
A[4]=B[4];
case 4:
A[3]=B[3];
case 3:
A[2]=B[2];
case 2:
A[1]=B[1];
case 1:
A[0]=B[0];
case 0:
;
}
Free(b->d);
}
b->d=a;
b->max=words;
B= &(b->d[b->top]);
j=(b->max - b->top) & ~7;
for (i=0; i<j; i+=8)
{
B[0]=0; B[1]=0; B[2]=0; B[3]=0;
B[4]=0; B[5]=0; B[6]=0; B[7]=0;
B+=8;
}
j=(b->max - b->top) & 7;
for (i=0; i<j; i++)
{
B[0]=0;
B++;
}
#else
memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
#endif
}
return(b);
} | ['int test_rshift(BIO *bp)\n\t{\n\tBIGNUM *a,*b,*c;\n\tint i;\n\ta=BN_new();\n\tb=BN_new();\n\tc=BN_new();\n\tBN_one(c);\n\tBN_rand(a,200,0,0);\n\ta->neg=rand_neg();\n\tfor (i=0; i<70; i++)\n\t\t{\n\t\tBN_rshift(b,a,i+1);\n\t\tBN_add(c,c,c);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,a);\n\t\t\t\tBIO_puts(bp," / ");\n\t\t\t\tBN_print(bp,c);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,b);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\t}\n\tBN_free(a);\n\tBN_free(b);\n\tBN_free(c);\n\treturn(1);\n\t}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n\t{\n\tint i,n;\n\tif (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);\n\tn=sizeof(BN_ULONG)/BN_BYTES;\n\ta->neg=0;\n\ta->top=0;\n\ta->d[0]=(BN_ULONG)w&BN_MASK2;\n\tif (a->d[0] != 0) a->top=1;\n\tfor (i=1; i<n; i++)\n\t\t{\n#ifndef SIXTY_FOUR_BIT\n\t\tw>>=BN_BITS4;\n\t\tw>>=BN_BITS4;\n#endif\n\t\ta->d[i]=(BN_ULONG)w&BN_MASK2;\n\t\tif (a->d[i] != 0) a->top=i+1;\n\t\t}\n\treturn(1);\n\t}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n\t{\n\tunsigned char *buf=NULL;\n\tint ret=0,bit,bytes,mask;\n\ttime_t tim;\n\tbytes=(bits+7)/8;\n\tbit=(bits-1)%8;\n\tmask=0xff<<bit;\n\tbuf=(unsigned char *)Malloc(bytes);\n\tif (buf == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\ttime(&tim);\n\tRAND_seed(&tim,sizeof(tim));\n\tRAND_bytes(buf,(int)bytes);\n\tif (top)\n\t\t{\n\t\tif (bit == 0)\n\t\t\t{\n\t\t\tbuf[0]=1;\n\t\t\tbuf[1]|=0x80;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbuf[0]|=(3<<(bit-1));\n\t\t\tbuf[0]&= ~(mask<<1);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tbuf[0]|=(1<<bit);\n\t\tbuf[0]&= ~(mask<<1);\n\t\t}\n\tif (bottom)\n\t\tbuf[bytes-1]|=1;\n\tif (!BN_bin2bn(buf,bytes,rnd)) goto err;\n\tret=1;\nerr:\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bytes);\n\t\tFree(buf);\n\t\t}\n\treturn(ret);\n\t}', 'int BN_rshift(BIGNUM *r, BIGNUM *a, int n)\n\t{\n\tint i,j,nw,lb,rb;\n\tBN_ULONG *t,*f;\n\tBN_ULONG l,tmp;\n\tnw=n/BN_BITS2;\n\trb=n%BN_BITS2;\n\tlb=BN_BITS2-rb;\n\tif (nw > a->top)\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\tif (r != a)\n\t\t{\n\t\tr->neg=a->neg;\n\t\tif (bn_wexpand(r,a->top-nw+1) == NULL) return(0);\n\t\t}\n\tf= &(a->d[nw]);\n\tt=r->d;\n\tj=a->top-nw;\n\tr->top=j;\n\tif (rb == 0)\n\t\t{\n\t\tfor (i=j+1; i > 0; i--)\n\t\t\t*(t++)= *(f++);\n\t\t}\n\telse\n\t\t{\n\t\tl= *(f++);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\ttmp =(l>>rb)&BN_MASK2;\n\t\t\tl= *(f++);\n\t\t\t*(t++) =(tmp|(l<<lb))&BN_MASK2;\n\t\t\t}\n\t\t*(t++) =(l>>rb)&BN_MASK2;\n\t\t}\n\t*t=0;\n\tbn_fix_top(r);\n\treturn(1);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*B,*a;\n\tint i,j;\n\tbn_check_top(b);\n\tif (words > b->max)\n\t\t{\n\t\tbn_check_top(b);\n\t\tif (BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\ta=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));\n\t\tif (A == NULL)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(NULL);\n\t\t\t}\nmemset(A,0x5c,sizeof(BN_ULONG)*(words+1));\n#if 1\n\t\tB=b->d;\n\t\tif (B != NULL)\n\t\t\t{\n\t\t\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t\t\t{\n\t\t\t\tA[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];\n\t\t\t\tA[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];\n\t\t\t\tA+=8;\n\t\t\t\tB+=8;\n\t\t\t\t}\n\t\t\tswitch (b->top&7)\n\t\t\t\t{\n\t\t\tcase 7:\n\t\t\t\tA[6]=B[6];\n\t\t\tcase 6:\n\t\t\t\tA[5]=B[5];\n\t\t\tcase 5:\n\t\t\t\tA[4]=B[4];\n\t\t\tcase 4:\n\t\t\t\tA[3]=B[3];\n\t\t\tcase 3:\n\t\t\t\tA[2]=B[2];\n\t\t\tcase 2:\n\t\t\t\tA[1]=B[1];\n\t\t\tcase 1:\n\t\t\t\tA[0]=B[0];\n\t\t\tcase 0:\n\t\t\t\t;\n\t\t\t\t}\n\t\t\tFree(b->d);\n\t\t\t}\n\t\tb->d=a;\n\t\tb->max=words;\n\t\tB= &(b->d[b->top]);\n\t\tj=(b->max - b->top) & ~7;\n\t\tfor (i=0; i<j; i+=8)\n\t\t\t{\n\t\t\tB[0]=0; B[1]=0; B[2]=0; B[3]=0;\n\t\t\tB[4]=0; B[5]=0; B[6]=0; B[7]=0;\n\t\t\tB+=8;\n\t\t\t}\n\t\tj=(b->max - b->top) & 7;\n\t\tfor (i=0; i<j; i++)\n\t\t\t{\n\t\t\tB[0]=0;\n\t\t\tB++;\n\t\t\t}\n#else\n\t\t\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\t\t}\n\treturn(b);\n\t}'] |
34,397 | 1 | https://github.com/openssl/openssl/blob/96826bfc84c63207b720543443626029946a0fc7/crypto/bn/bntest.c/#L1931 | int test_rshift(BIO *bp,BN_CTX *ctx)
{
BIGNUM *a,*b,*c,*d,*e;
int i;
a=BN_new();
b=BN_new();
c=BN_new();
d=BN_new();
e=BN_new();
BN_one(c);
BN_bntest_rand(a,200,0,0);
a->neg=rand_neg();
for (i=0; i<num0; i++)
{
BN_rshift(b,a,i+1);
BN_add(c,c,c);
if (bp != NULL)
{
if (!results)
{
BN_print(bp,a);
BIO_puts(bp," / ");
BN_print(bp,c);
BIO_puts(bp," - ");
}
BN_print(bp,b);
BIO_puts(bp,"\n");
}
BN_div(d,e,a,c,ctx);
BN_sub(d,d,b);
if(!BN_is_zero(d))
{
fprintf(stderr,"Right shift test failed!\n");
return 0;
}
}
BN_free(a);
BN_free(b);
BN_free(c);
BN_free(d);
BN_free(e);
return(1);
} | ['int test_rshift(BIO *bp,BN_CTX *ctx)\n\t{\n\tBIGNUM *a,*b,*c,*d,*e;\n\tint i;\n\ta=BN_new();\n\tb=BN_new();\n\tc=BN_new();\n\td=BN_new();\n\te=BN_new();\n\tBN_one(c);\n\tBN_bntest_rand(a,200,0,0);\n\ta->neg=rand_neg();\n\tfor (i=0; i<num0; i++)\n\t\t{\n\t\tBN_rshift(b,a,i+1);\n\t\tBN_add(c,c,c);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,a);\n\t\t\t\tBIO_puts(bp," / ");\n\t\t\t\tBN_print(bp,c);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,b);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\tBN_div(d,e,a,c,ctx);\n\t\tBN_sub(d,d,b);\n\t\tif(!BN_is_zero(d))\n\t\t {\n\t\t fprintf(stderr,"Right shift test failed!\\n");\n\t\t return 0;\n\t\t }\n\t\t}\n\tBN_free(a);\n\tBN_free(b);\n\tBN_free(c);\n\tBN_free(d);\n\tBN_free(e);\n\treturn(1);\n\t}', 'BIGNUM *BN_new(void)\n\t{\n\tBIGNUM *ret;\n\tif ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->flags=BN_FLG_MALLOCED;\n\tret->top=0;\n\tret->neg=0;\n\tret->dmax=0;\n\tret->d=NULL;\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n\t{\n\tbn_check_top(a);\n\tif (bn_expand(a,(int)sizeof(BN_ULONG)*8) == NULL) return(0);\n\ta->neg = 0;\n\ta->d[0] = w;\n\ta->top = (w ? 1 : 0);\n\tbn_check_top(a);\n\treturn(1);\n\t}'] |
34,398 | 0 | https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/bn/bn_lib.c/#L620 | int BN_bn2bin(BIGNUM *a, unsigned char *to)
{
int n,i;
BN_ULONG l;
n=i=BN_num_bytes(a);
while (i-- > 0)
{
l=a->d[i/BN_BYTES];
*(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;
}
return(n);
} | ['int DHparams_print(BIO *bp, DH *x)\n\t{\n\tunsigned char *m=NULL;\n\tint reason=ERR_R_BUF_LIB,i,ret=0;\n\ti=BN_num_bytes(x->p);\n\tm=(unsigned char *)Malloc((unsigned int)i+10);\n\tif (m == NULL)\n\t\t{\n\t\treason=ERR_R_MALLOC_FAILURE;\n\t\tgoto err;\n\t\t}\n\tif (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\\n",\n\t\tBN_num_bits(x->p)) <= 0)\n\t\tgoto err;\n\tif (!print(bp,"prime:",x->p,m,4)) goto err;\n\tif (!print(bp,"generator:",x->g,m,4)) goto err;\n\tif (x->length != 0)\n\t\t{\n\t\tif (BIO_printf(bp," recomented-private-length: %d bits\\n",\n\t\t\t(int)x->length) <= 0) goto err;\n\t\t}\n\tret=1;\n\tif (0)\n\t\t{\nerr:\n\t\tDHerr(DH_F_DHPARAMS_PRINT,reason);\n\t\t}\n\tif (m != NULL) Free((char *)m);\n\treturn(ret);\n\t}', 'int BN_num_bits(BIGNUM *a)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tbn_check_top(a);\n\tif (a->top == 0) return(0);\n\tl=a->d[a->top-1];\n\ti=(a->top-1)*BN_BITS2;\n\tif (l == 0)\n\t\t{\n#if !defined(NO_STDIO) && !defined(WIN16)\n\t\tfprintf(stderr,"BAD TOP VALUE\\n");\n#endif\n\t\tabort();\n\t\t}\n\treturn(i+BN_num_bits_word(l));\n\t}', 'static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,\n\t int off)\n\t{\n\tint n,i;\n\tchar str[128];\n\tconst char *neg;\n\tif (num == NULL) return(1);\n\tneg=(num->neg)?"-":"";\n\tif (off)\n\t\t{\n\t\tif (off > 128) off=128;\n\t\tmemset(str,\' \',off);\n\t\tif (BIO_write(bp,str,off) <= 0) return(0);\n\t\t}\n\tif (BN_num_bytes(num) <= BN_BYTES)\n\t\t{\n\t\tif (BIO_printf(bp,"%s %s%lu (%s0x%lx)\\n",number,neg,\n\t\t\t(unsigned long)num->d[0],neg,(unsigned long)num->d[0])\n\t\t\t<= 0) return(0);\n\t\t}\n\telse\n\t\t{\n\t\tbuf[0]=0;\n\t\tif (BIO_printf(bp,"%s%s",number,\n\t\t\t(neg[0] == \'-\')?" (Negative)":"") <= 0)\n\t\t\treturn(0);\n\t\tn=BN_bn2bin(num,&buf[1]);\n\t\tif (buf[1] & 0x80)\n\t\t\tn++;\n\t\telse\tbuf++;\n\t\tfor (i=0; i<n; i++)\n\t\t\t{\n\t\t\tif ((i%15) == 0)\n\t\t\t\t{\n\t\t\t\tstr[0]=\'\\n\';\n\t\t\t\tmemset(&(str[1]),\' \',off+4);\n\t\t\t\tif (BIO_write(bp,str,off+1+4) <= 0) return(0);\n\t\t\t\t}\n\t\t\tif (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":")\n\t\t\t\t<= 0) return(0);\n\t\t\t}\n\t\tif (BIO_write(bp,"\\n",1) <= 0) return(0);\n\t\t}\n\treturn(1);\n\t}', 'int BN_bn2bin(BIGNUM *a, unsigned char *to)\n\t{\n\tint n,i;\n\tBN_ULONG l;\n\tn=i=BN_num_bytes(a);\n\twhile (i-- > 0)\n\t\t{\n\t\tl=a->d[i/BN_BYTES];\n\t\t*(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;\n\t\t}\n\treturn(n);\n\t}'] |
34,399 | 0 | https://github.com/openssl/openssl/blob/38d1b3cc0271008b8bd130a2c4b442775b028a08/crypto/bn/bn_shift.c/#L113 | int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return (0);
r->neg = a->neg;
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return (1);
} | ['int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}'] |
34,400 | 0 | https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/ssl/t1_enc.c/#L786 | int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
const char *label, size_t llen,
const unsigned char *context,
size_t contextlen, int use_context)
{
unsigned char *buff;
unsigned char *val = NULL;
size_t vallen = 0, currentvalpos;
int rv;
buff = OPENSSL_malloc(olen);
if (buff == NULL)
goto err2;
vallen = llen + SSL3_RANDOM_SIZE * 2;
if (use_context) {
vallen += 2 + contextlen;
}
val = OPENSSL_malloc(vallen);
if (val == NULL)
goto err2;
currentvalpos = 0;
memcpy(val + currentvalpos, (unsigned char *)label, llen);
currentvalpos += llen;
memcpy(val + currentvalpos, s->s3->client_random, SSL3_RANDOM_SIZE);
currentvalpos += SSL3_RANDOM_SIZE;
memcpy(val + currentvalpos, s->s3->server_random, SSL3_RANDOM_SIZE);
currentvalpos += SSL3_RANDOM_SIZE;
if (use_context) {
val[currentvalpos] = (contextlen >> 8) & 0xff;
currentvalpos++;
val[currentvalpos] = contextlen & 0xff;
currentvalpos++;
if ((contextlen > 0) || (context != NULL)) {
memcpy(val + currentvalpos, context, contextlen);
}
}
if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,
TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0)
goto err1;
if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,
TLS_MD_SERVER_FINISH_CONST_SIZE) == 0)
goto err1;
if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,
TLS_MD_MASTER_SECRET_CONST_SIZE) == 0)
goto err1;
if (memcmp(val, TLS_MD_EXTENDED_MASTER_SECRET_CONST,
TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE) == 0)
goto err1;
if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,
TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0)
goto err1;
rv = tls1_PRF(s,
val, vallen,
NULL, 0,
NULL, 0,
NULL, 0,
NULL, 0,
s->session->master_key, s->session->master_key_length,
out, buff, olen);
goto ret;
err1:
SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL,
SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);
rv = 0;
goto ret;
err2:
SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, ERR_R_MALLOC_FAILURE);
rv = 0;
ret:
CRYPTO_clear_free(val, vallen);
CRYPTO_clear_free(buff, olen);
return (rv);
} | ['int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,\n const char *label, size_t llen,\n const unsigned char *context,\n size_t contextlen, int use_context)\n{\n unsigned char *buff;\n unsigned char *val = NULL;\n size_t vallen = 0, currentvalpos;\n int rv;\n buff = OPENSSL_malloc(olen);\n if (buff == NULL)\n goto err2;\n vallen = llen + SSL3_RANDOM_SIZE * 2;\n if (use_context) {\n vallen += 2 + contextlen;\n }\n val = OPENSSL_malloc(vallen);\n if (val == NULL)\n goto err2;\n currentvalpos = 0;\n memcpy(val + currentvalpos, (unsigned char *)label, llen);\n currentvalpos += llen;\n memcpy(val + currentvalpos, s->s3->client_random, SSL3_RANDOM_SIZE);\n currentvalpos += SSL3_RANDOM_SIZE;\n memcpy(val + currentvalpos, s->s3->server_random, SSL3_RANDOM_SIZE);\n currentvalpos += SSL3_RANDOM_SIZE;\n if (use_context) {\n val[currentvalpos] = (contextlen >> 8) & 0xff;\n currentvalpos++;\n val[currentvalpos] = contextlen & 0xff;\n currentvalpos++;\n if ((contextlen > 0) || (context != NULL)) {\n memcpy(val + currentvalpos, context, contextlen);\n }\n }\n if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,\n TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0)\n goto err1;\n if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,\n TLS_MD_SERVER_FINISH_CONST_SIZE) == 0)\n goto err1;\n if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,\n TLS_MD_MASTER_SECRET_CONST_SIZE) == 0)\n goto err1;\n if (memcmp(val, TLS_MD_EXTENDED_MASTER_SECRET_CONST,\n TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE) == 0)\n goto err1;\n if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,\n TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0)\n goto err1;\n rv = tls1_PRF(s,\n val, vallen,\n NULL, 0,\n NULL, 0,\n NULL, 0,\n NULL, 0,\n s->session->master_key, s->session->master_key_length,\n out, buff, olen);\n goto ret;\n err1:\n SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL,\n SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);\n rv = 0;\n goto ret;\n err2:\n SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, ERR_R_MALLOC_FAILURE);\n rv = 0;\n ret:\n CRYPTO_clear_free(val, vallen);\n CRYPTO_clear_free(buff, olen);\n return (rv);\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.