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
36,501
0
https://github.com/libav/libav/blob/47399ccdfd93d337c96c76fbf591f0e3637131ef/libavcodec/bitstream.h/#L245
static inline void bitstream_skip(BitstreamContext *bc, unsigned n) { if (n < bc->bits_left) skip_remaining(bc, n); else { n -= bc->bits_left; bc->bits = 0; bc->bits_left = 0; if (n >= 64) { unsigned skip = n / 8; n -= skip * 8; bc->ptr += skip; } refill_64(bc); if (n) skip_remaining(bc, n); } }
['static void read_const_block_data(ALSDecContext *ctx, ALSBlockData *bd)\n{\n ALSSpecificConfig *sconf = &ctx->sconf;\n AVCodecContext *avctx = ctx->avctx;\n BitstreamContext *bc = &ctx->bc;\n *bd->raw_samples = 0;\n *bd->const_block = bitstream_read_bit(bc);\n bd->js_blocks = bitstream_read_bit(bc);\n bitstream_skip(bc, 5);\n if (*bd->const_block) {\n unsigned int const_val_bits = sconf->floating ? 24 : avctx->bits_per_raw_sample;\n *bd->raw_samples = bitstream_read_signed(bc, const_val_bits);\n }\n *bd->const_block = 1;\n}', 'static inline unsigned bitstream_read_bit(BitstreamContext *bc)\n{\n if (!bc->bits_left)\n refill_64(bc);\n return get_val(bc, 1);\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}', '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}']
36,502
0
https://github.com/openssl/openssl/blob/c313e32a8b9514868f3fae09a8af025df76a4a8d/ssl/ssl_ciph.c/#L1686
int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm) { SSL_COMP *comp; if (cm == NULL || cm->type == NID_undef) return 1; if (id < 193 || id > 255) { SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE); return 0; } MemCheck_off(); comp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP)); comp->id=id; comp->method=cm; load_builtin_compressions(); if (ssl_comp_methods && !sk_SSL_COMP_find(ssl_comp_methods,comp)) { OPENSSL_free(comp); MemCheck_on(); SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,SSL_R_DUPLICATE_COMPRESSION_ID); return(1); } else if ((ssl_comp_methods == NULL) || !sk_SSL_COMP_push(ssl_comp_methods,comp)) { OPENSSL_free(comp); MemCheck_on(); SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE); return(1); } else { MemCheck_on(); return(0); } }
['int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)\n\t{\n\tSSL_COMP *comp;\n if (cm == NULL || cm->type == NID_undef)\n return 1;\n\tif (id < 193 || id > 255)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE);\n\t\treturn 0;\n\t\t}\n\tMemCheck_off();\n\tcomp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP));\n\tcomp->id=id;\n\tcomp->method=cm;\n\tload_builtin_compressions();\n\tif (ssl_comp_methods\n\t\t&& !sk_SSL_COMP_find(ssl_comp_methods,comp))\n\t\t{\n\t\tOPENSSL_free(comp);\n\t\tMemCheck_on();\n\t\tSSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,SSL_R_DUPLICATE_COMPRESSION_ID);\n\t\treturn(1);\n\t\t}\n\telse if ((ssl_comp_methods == NULL)\n\t\t|| !sk_SSL_COMP_push(ssl_comp_methods,comp))\n\t\t{\n\t\tOPENSSL_free(comp);\n\t\tMemCheck_on();\n\t\tSSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE);\n\t\treturn(1);\n\t\t}\n\telse\n\t\t{\n\t\tMemCheck_on();\n\t\treturn(0);\n\t\t}\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}']
36,503
1
https://github.com/openssl/openssl/blob/b3618f44a7b8504bfb0a64e8a33e6b8e56d4d516/crypto/bn/bn_shift.c/#L110
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; } r->neg = a->neg; nw = n / BN_BITS2; if (bn_wexpand(r, a->top + nw + 1) == NULL) return (0); 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 test_mul(BIO *bp)\n{\n BIGNUM *a, *b, *c, *d, *e;\n int i;\n BN_CTX *ctx;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n EXIT(1);\n a = BN_new();\n b = BN_new();\n c = BN_new();\n d = BN_new();\n e = BN_new();\n for (i = 0; i < num0 + num1; i++) {\n if (i <= num1) {\n BN_bntest_rand(a, 100, 0, 0);\n BN_bntest_rand(b, 100, 0, 0);\n } else\n BN_bntest_rand(b, i - num1, 0, 0);\n a->neg = rand_neg();\n b->neg = rand_neg();\n BN_mul(c, a, b, ctx);\n if (bp != NULL) {\n if (!results) {\n BN_print(bp, a);\n BIO_puts(bp, " * ");\n BN_print(bp, b);\n BIO_puts(bp, " - ");\n }\n BN_print(bp, c);\n BIO_puts(bp, "\\n");\n }\n BN_div(d, e, c, a, ctx);\n BN_sub(d, d, b);\n if (!BN_is_zero(d) || !BN_is_zero(e)) {\n fprintf(stderr, "Multiplication test failed!\\n");\n return 0;\n }\n }\n BN_free(a);\n BN_free(b);\n BN_free(c);\n BN_free(d);\n BN_free(e);\n BN_CTX_free(ctx);\n return (1);\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 rr->neg = a->neg ^ b->neg;\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 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}', '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 tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == 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 res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\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}', '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 r->neg = a->neg;\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\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}']
36,504
0
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/bn/bn_ctx.c/#L437
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while (num--) { bn_check_top(p->current->vals + offset); if (!offset) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)\n{\n int ret = 0;\n if ((b->A == NULL) || (b->Ai == NULL)) {\n BNerr(BN_F_BN_BLINDING_UPDATE, BN_R_NOT_INITIALIZED);\n goto err;\n }\n if (b->counter == -1)\n b->counter = 0;\n if (++b->counter == BN_BLINDING_COUNTER && b->e != NULL &&\n !(b->flags & BN_BLINDING_NO_RECREATE)) {\n if (!BN_BLINDING_create_param(b, NULL, NULL, ctx, NULL, NULL))\n goto err;\n } else if (!(b->flags & BN_BLINDING_NO_UPDATE)) {\n if (!BN_mod_mul(b->A, b->A, b->A, b->mod, ctx))\n goto err;\n if (!BN_mod_mul(b->Ai, b->Ai, b->Ai, b->mod, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (b->counter == BN_BLINDING_COUNTER)\n b->counter = 0;\n return (ret);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("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_EXIT(ctx);\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)) == 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_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 rr->neg = a->neg ^ b->neg;\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 bn_correct_top(rr);\n if (r != rr)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (!offset) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
36,505
0
https://github.com/openssl/openssl/blob/aa8b03b415d20c0863f44c211486f881c6689383/crypto/bn/bn_ctx.c/#L440
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while(num--) { bn_check_top(p->current->vals + offset); if(!offset) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n\t\tint do_trial_division, BN_GENCB *cb)\n\t{\n\tint i, j, ret = -1;\n\tint k;\n\tBN_CTX *ctx = NULL;\n\tBIGNUM *A1, *A1_odd, *check;\n\tBN_MONT_CTX *mont = NULL;\n\tconst BIGNUM *A = NULL;\n\tif (BN_cmp(a, BN_value_one()) <= 0)\n\t\treturn 0;\n\tif (checks == BN_prime_checks)\n\t\tchecks = BN_prime_checks_for_size(BN_num_bits(a));\n\tif (!BN_is_odd(a))\n\t\treturn 0;\n\tif (do_trial_division)\n\t\t{\n\t\tfor (i = 1; i < NUMPRIMES; i++)\n\t\t\tif (BN_mod_word(a, primes[i]) == 0)\n\t\t\t\treturn 0;\n\t\tif(!BN_GENCB_call(cb, 1, -1))\n\t\t\tgoto err;\n\t\t}\n\tif (ctx_passed != NULL)\n\t\tctx = ctx_passed;\n\telse\n\t\tif ((ctx=BN_CTX_new()) == NULL)\n\t\t\tgoto err;\n\tBN_CTX_start(ctx);\n\tif (a->neg)\n\t\t{\n\t\tBIGNUM *t;\n\t\tif ((t = BN_CTX_get(ctx)) == NULL) goto err;\n\t\tBN_copy(t, a);\n\t\tt->neg = 0;\n\t\tA = t;\n\t\t}\n\telse\n\t\tA = a;\n\tA1 = BN_CTX_get(ctx);\n\tA1_odd = BN_CTX_get(ctx);\n\tcheck = BN_CTX_get(ctx);\n\tif (check == NULL) goto err;\n\tif (!BN_copy(A1, A))\n\t\tgoto err;\n\tif (!BN_sub_word(A1, 1))\n\t\tgoto err;\n\tif (BN_is_zero(A1))\n\t\t{\n\t\tret = 0;\n\t\tgoto err;\n\t\t}\n\tk = 1;\n\twhile (!BN_is_bit_set(A1, k))\n\t\tk++;\n\tif (!BN_rshift(A1_odd, A1, k))\n\t\tgoto err;\n\tmont = BN_MONT_CTX_new();\n\tif (mont == NULL)\n\t\tgoto err;\n\tif (!BN_MONT_CTX_set(mont, A, ctx))\n\t\tgoto err;\n\tfor (i = 0; i < checks; i++)\n\t\t{\n\t\tif (!BN_pseudo_rand_range(check, A1))\n\t\t\tgoto err;\n\t\tif (!BN_add_word(check, 1))\n\t\t\tgoto err;\n\t\tj = witness(check, A, A1, A1_odd, k, ctx, mont);\n\t\tif (j == -1) goto err;\n\t\tif (j)\n\t\t\t{\n\t\t\tret=0;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif(!BN_GENCB_call(cb, 1, i))\n\t\t\tgoto err;\n\t\t}\n\tret=1;\nerr:\n\tif (ctx != NULL)\n\t\t{\n\t\tBN_CTX_end(ctx);\n\t\tif (ctx_passed == NULL)\n\t\t\tBN_CTX_free(ctx);\n\t\t}\n\tif (mont != NULL)\n\t\tBN_MONT_CTX_free(mont);\n\treturn(ret);\n\t}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n\t{\n\tBIGNUM *ret;\n\tCTXDBG_ENTRY("BN_CTX_get", ctx);\n\tif(ctx->err_stack || ctx->too_many) return NULL;\n\tif((ret = BN_POOL_get(&ctx->pool)) == NULL)\n\t\t{\n\t\tctx->too_many = 1;\n\t\tBNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\treturn NULL;\n\t\t}\n\tBN_zero(ret);\n\tctx->used++;\n\tCTXDBG_RET(ctx, ret);\n\treturn ret;\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 void BN_POOL_release(BN_POOL *p, unsigned int num)\n\t{\n\tunsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n\tp->used -= num;\n\twhile(num--)\n\t\t{\n\t\tbn_check_top(p->current->vals + offset);\n\t\tif(!offset)\n\t\t\t{\n\t\t\toffset = BN_CTX_POOL_SIZE - 1;\n\t\t\tp->current = p->current->prev;\n\t\t\t}\n\t\telse\n\t\t\toffset--;\n\t\t}\n\t}']
36,506
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavutil/rc4.c/#L36
void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen) { int i, j; uint8_t x, y; uint8_t state[256]; for (i = 0; i < 256; i++) state[i] = i; y = 0; for (j = 0, i = 0; i < 256; i++, j++) { if (j == keylen) j = 0; y += state[i] + key[j]; FFSWAP(uint8_t, state[i], state[y]); } x = 1; y = state[1]; while (datalen-- > 0) { uint8_t sum = state[x] + state[y]; FFSWAP(uint8_t, state[x], state[y]); *data++ ^= state[sum]; x++; y += state[x]; } }
['void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen) {\n int i, j;\n uint8_t x, y;\n uint8_t state[256];\n for (i = 0; i < 256; i++)\n state[i] = i;\n y = 0;\n for (j = 0, i = 0; i < 256; i++, j++) {\n if (j == keylen) j = 0;\n y += state[i] + key[j];\n FFSWAP(uint8_t, state[i], state[y]);\n }\n x = 1; y = state[1];\n while (datalen-- > 0) {\n uint8_t sum = state[x] + state[y];\n FFSWAP(uint8_t, state[x], state[y]);\n *data++ ^= state[sum];\n x++;\n y += state[x];\n }\n}']
36,507
0
https://github.com/libav/libav/blob/fd7b11d027da7cc350d867d22d4c6bbe6022d8df/libavformat/nutdec.c/#L760
static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){ AVFormatContext *s= nut->avf; ByteIOContext *bc = s->pb; int size, stream_id, discard; int64_t pts, last_IP_pts; StreamContext *stc; uint8_t header_idx; size= decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code); if(size < 0) return -1; stc= &nut->stream[stream_id]; if (stc->last_flags & FLAG_KEY) stc->skip_until_key_frame=0; discard= s->streams[ stream_id ]->discard; last_IP_pts= s->streams[ stream_id ]->last_IP_pts; if( (discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY)) ||(discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts) || discard >= AVDISCARD_ALL || stc->skip_until_key_frame){ url_fskip(bc, size); return 1; } av_new_packet(pkt, size + nut->header_len[header_idx]); memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]); pkt->pos= url_ftell(bc); get_buffer(bc, pkt->data + nut->header_len[header_idx], size); pkt->stream_index = stream_id; if (stc->last_flags & FLAG_KEY) pkt->flags |= AV_PKT_FLAG_KEY; pkt->pts = pts; return 0; }
['static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){\n AVFormatContext *s= nut->avf;\n ByteIOContext *bc = s->pb;\n int size, stream_id, discard;\n int64_t pts, last_IP_pts;\n StreamContext *stc;\n uint8_t header_idx;\n size= decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code);\n if(size < 0)\n return -1;\n stc= &nut->stream[stream_id];\n if (stc->last_flags & FLAG_KEY)\n stc->skip_until_key_frame=0;\n discard= s->streams[ stream_id ]->discard;\n last_IP_pts= s->streams[ stream_id ]->last_IP_pts;\n if( (discard >= AVDISCARD_NONKEY && !(stc->last_flags & FLAG_KEY))\n ||(discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts)\n || discard >= AVDISCARD_ALL\n || stc->skip_until_key_frame){\n url_fskip(bc, size);\n return 1;\n }\n av_new_packet(pkt, size + nut->header_len[header_idx]);\n memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]);\n pkt->pos= url_ftell(bc);\n get_buffer(bc, pkt->data + nut->header_len[header_idx], size);\n pkt->stream_index = stream_id;\n if (stc->last_flags & FLAG_KEY)\n pkt->flags |= AV_PKT_FLAG_KEY;\n pkt->pts = pts;\n return 0;\n}', 'int av_new_packet(AVPacket *pkt, int size)\n{\n uint8_t *data= NULL;\n if((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)\n data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n if (data){\n memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n }else\n size=0;\n av_init_packet(pkt);\n pkt->data = data;\n pkt->size = size;\n pkt->destruct = av_destruct_packet;\n if(!data)\n return AVERROR(ENOMEM);\n return 0;\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}', 'void av_init_packet(AVPacket *pkt)\n{\n pkt->pts = AV_NOPTS_VALUE;\n pkt->dts = AV_NOPTS_VALUE;\n pkt->pos = -1;\n pkt->duration = 0;\n pkt->convergence_duration = 0;\n pkt->flags = 0;\n pkt->stream_index = 0;\n pkt->destruct= NULL;\n}']
36,508
0
https://github.com/openssl/openssl/blob/9639515871c73722de3fff04d3c50d54aa6b1477/crypto/bn/bn_lib.c/#L447
BIGNUM *bn_expand2(BIGNUM *b, int words) { BN_ULONG *A,*a; const BN_ULONG *B; int i; 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); } #if 1 B=b->d; if (B != NULL) { #if 0 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: ; } #else 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: ; } #endif Free(b->d); } b->d=a; b->max=words; A= &(b->d[b->top]); for (i=(b->max - b->top)>>3; i>0; i--,A+=8) { A[0]=0; A[1]=0; A[2]=0; A[3]=0; A[4]=0; A[5]=0; A[6]=0; A[7]=0; } for (i=(b->max - b->top)&7; i>0; i--,A++) A[0]=0; #else memset(A,0,sizeof(BN_ULONG)*(words+1)); memcpy(A,b->d,sizeof(b->d[0])*b->top); b->d=a; b->max=words; #endif } return(b); }
['RSA *RSA_generate_key(int bits, unsigned long e_value,\n\t void (*callback)(int,int,void *), void *cb_arg)\n\t{\n\tRSA *rsa=NULL;\n\tBIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp;\n\tint bitsp,bitsq,ok= -1,n=0,i;\n\tBN_CTX *ctx=NULL,*ctx2=NULL;\n\tctx=BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tctx2=BN_CTX_new();\n\tif (ctx2 == NULL) goto err;\n\tr0= &(ctx->bn[0]);\n\tr1= &(ctx->bn[1]);\n\tr2= &(ctx->bn[2]);\n\tr3= &(ctx->bn[3]);\n\tctx->tos+=4;\n\tbitsp=(bits+1)/2;\n\tbitsq=bits-bitsp;\n\trsa=RSA_new();\n\tif (rsa == NULL) goto err;\n\trsa->e=BN_new();\n\tif (rsa->e == NULL) goto err;\n#if 1\n\tfor (i=0; i<sizeof(unsigned long)*8; i++)\n\t\t{\n\t\tif (e_value & (1<<i))\n\t\t\tBN_set_bit(rsa->e,i);\n\t\t}\n#else\n\tif (!BN_set_word(rsa->e,e_value)) goto err;\n#endif\n\tfor (;;)\n\t\t{\n\t\trsa->p=BN_generate_prime(NULL,bitsp,0,NULL,NULL,callback,cb_arg);\n\t\tif (rsa->p == NULL) goto err;\n\t\tif (!BN_sub(r2,rsa->p,BN_value_one())) goto err;\n\t\tif (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;\n\t\tif (BN_is_one(r1)) break;\n\t\tif (callback != NULL) callback(2,n++,cb_arg);\n\t\tBN_free(rsa->p);\n\t\t}\n\tif (callback != NULL) callback(3,0,cb_arg);\n\tfor (;;)\n\t\t{\n\t\trsa->q=BN_generate_prime(NULL,bitsq,0,NULL,NULL,callback,cb_arg);\n\t\tif (rsa->q == NULL) goto err;\n\t\tif (!BN_sub(r2,rsa->q,BN_value_one())) goto err;\n\t\tif (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;\n\t\tif (BN_is_one(r1) && (BN_cmp(rsa->p,rsa->q) != 0))\n\t\t\tbreak;\n\t\tif (callback != NULL) callback(2,n++,cb_arg);\n\t\tBN_free(rsa->q);\n\t\t}\n\tif (callback != NULL) callback(3,1,cb_arg);\n\tif (BN_cmp(rsa->p,rsa->q) < 0)\n\t\t{\n\t\ttmp=rsa->p;\n\t\trsa->p=rsa->q;\n\t\trsa->q=tmp;\n\t\t}\n\trsa->n=BN_new();\n\tif (rsa->n == NULL) goto err;\n\tif (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) goto err;\n\tif (!BN_sub(r1,rsa->p,BN_value_one())) goto err;\n\tif (!BN_sub(r2,rsa->q,BN_value_one())) goto err;\n\tif (!BN_mul(r0,r1,r2,ctx)) goto err;\n\trsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2);\n\tif (rsa->d == NULL) goto err;\n\trsa->dmp1=BN_new();\n\tif (rsa->dmp1 == NULL) goto err;\n\tif (!BN_mod(rsa->dmp1,rsa->d,r1,ctx)) goto err;\n\trsa->dmq1=BN_new();\n\tif (rsa->dmq1 == NULL) goto err;\n\tif (!BN_mod(rsa->dmq1,rsa->d,r2,ctx)) goto err;\n\trsa->iqmp=BN_mod_inverse(NULL,rsa->q,rsa->p,ctx2);\n\tif (rsa->iqmp == NULL) goto err;\n\tok=1;\nerr:\n\tif (ok == -1)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN);\n\t\tok=0;\n\t\t}\n\tBN_CTX_free(ctx);\n\tBN_CTX_free(ctx2);\n\tif (!ok)\n\t\t{\n\t\tif (rsa != NULL) RSA_free(rsa);\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\treturn(rsa);\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\trr->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}', 'BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*R;\n\tBIGNUM *T,*ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tA= &(ctx->bn[ctx->tos]);\n\tB= &(ctx->bn[ctx->tos+1]);\n\tX= &(ctx->bn[ctx->tos+2]);\n\tD= &(ctx->bn[ctx->tos+3]);\n\tM= &(ctx->bn[ctx->tos+4]);\n\tY= &(ctx->bn[ctx->tos+5]);\n\tctx->tos+=6;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_zero(X);\n\tBN_one(Y);\n\tif (BN_copy(A,a) == NULL) goto err;\n\tif (BN_copy(B,n) == NULL) goto err;\n\tsign=1;\n\twhile (!BN_is_zero(B))\n\t\t{\n\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\tT=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (!BN_mul(T,D,X,ctx)) goto err;\n\t\tif (!BN_add(T,T,Y)) goto err;\n\t\tM=Y;\n\t\tY=X;\n\t\tX=T;\n\t\tsign= -sign;\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{ if (!BN_mod(R,Y,n,ctx)) goto err; }\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\tctx->tos-=6;\n\treturn(ret);\n\t}', 'int BN_mod(BIGNUM *rem, const BIGNUM *m, const 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, const BIGNUM *num, const 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,l0;\n#ifdef BN_DIV3W\n\t\tq=bn_div_3_words(wnump,d0,d1);\n#else\n#if !defined(NO_ASM) && !defined(PEDANTIC)\n# if defined(__GNUC__) && __GNUC__>=2\n# if defined(__i386)\n# define bn_div_words(n0,n1,d0)\t\t\\\n\t({ asm volatile (\t\t\t\\\n\t\t"divl\t%4"\t\t\t\\\n\t\t: "=a"(q), "=d"(rem)\t\t\\\n\t\t: "a"(n1), "d"(n0), "g"(d0)\t\\\n\t\t: "cc");\t\t\t\\\n\t q;\t\t\t\t\t\\\n\t})\n# define REMINDER_IS_ALREADY_CALCULATED\n# endif\n# endif\n#endif\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#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0;\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#endif\n\t\t{\n#ifdef BN_LLONG\n\t\tBN_ULLONG t2;\n#ifndef REMINDER_IS_ALREADY_CALCULATED\n\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\tt2=(BN_ULLONG)d1*q;\n\t\tfor (;;)\n\t\t\t{\n if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\trem += d0;\n\t\t\tif (rem < d0) break;\n\t\t\tt2 -= d1;\n\t\t\t}\n#else\n\t\tBN_ULONG t2l,t2h,ql,qh;\n#ifndef REMINDER_IS_ALREADY_CALCULATED\n\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\tql =LBITS(q); qh =HBITS(q);\n\t\tmul64(t2l,t2h,ql,qh);\n\t\tfor (;;)\n\t\t\t{\n\t\t\tif ((t2h < rem) ||\n\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\trem += d0;\n\t\t\tif (rem < d0) break;\n\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t}\n#endif\n\t\t}\n#endif\n\t\twnum.d--; wnum.top++;\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}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A;\n\tconst BN_ULONG *B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t{\n\t\tBN_ULONG a0,a1,a2,a3;\n\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t}\n\tswitch (b->top&3)\n\t\t{\n\t\tcase 3: A[2]=B[2];\n\t\tcase 2: A[1]=B[1];\n\t\tcase 1: A[0]=B[0];\n\t\tcase 0: ;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\tif ((a->top == 0) && (a->d != NULL))\n\t\ta->d[0]=0;\n\ta->neg=b->neg;\n\treturn(a);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*a;\n\tconst BN_ULONG *B;\n\tint i;\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}\n#if 1\n\t\tB=b->d;\n\t\tif (B != NULL)\n\t\t\t{\n#if 0\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#else\n\t\t\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t\t\t{\n\t\t\t\tBN_ULONG a0,a1,a2,a3;\n\t\t\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\t\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t\t\t}\n\t\t\tswitch (b->top&3)\n\t\t\t\t{\n\t\t\t\tcase 3:\tA[2]=B[2];\n\t\t\t\tcase 2:\tA[1]=B[1];\n\t\t\t\tcase 1:\tA[0]=B[0];\n\t\t\t\tcase 0:\t;\n\t\t\t\t}\n#endif\n\t\t\tFree(b->d);\n\t\t\t}\n\t\tb->d=a;\n\t\tb->max=words;\n\t\tA= &(b->d[b->top]);\n\t\tfor (i=(b->max - b->top)>>3; i>0; i--,A+=8)\n\t\t\t{\n\t\t\tA[0]=0; A[1]=0; A[2]=0; A[3]=0;\n\t\t\tA[4]=0; A[5]=0; A[6]=0; A[7]=0;\n\t\t\t}\n\t\tfor (i=(b->max - b->top)&7; i>0; i--,A++)\n\t\t\tA[0]=0;\n#else\n\t\t\tmemset(A,0,sizeof(BN_ULONG)*(words+1));\n\t\t\tmemcpy(A,b->d,sizeof(b->d[0])*b->top);\n\t\t\tb->d=a;\n\t\t\tb->max=words;\n#endif\n\t\t}\n\treturn(b);\n\t}']
36,509
0
https://github.com/openssl/openssl/blob/d8028b202bfe337200a0cc89b80983ea1838cb30/crypto/lhash/lhash.c/#L123
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); }
['static int setup_cipher_list()\n{\n SSL_CTX *ctx = NULL;\n SSL *ssl = NULL;\n static STACK_OF(SSL_CIPHER) *sk_ciphers = NULL;\n int i, numciphers;\n ctx = SSL_CTX_new(TLS_server_method());\n TEST_check(ctx != NULL);\n ssl = SSL_new(ctx);\n TEST_check(ssl != NULL);\n sk_ciphers = SSL_get1_supported_ciphers(ssl);\n TEST_check(sk_ciphers != NULL);\n cipher_list = OPENSSL_malloc(sk_SSL_CIPHER_num(sk_ciphers) *\n sizeof(cipher_list[0]));\n TEST_check(cipher_list != NULL);\n for (numciphers = 0, i = 0; i < sk_SSL_CIPHER_num(sk_ciphers); i++) {\n const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(sk_ciphers, i);\n if (SSL_CIPHER_get_auth_nid(cipher) == NID_auth_rsa)\n cipher_list[numciphers++] = SSL_CIPHER_get_name(cipher);\n }\n TEST_check(numciphers != 0);\n sk_SSL_CIPHER_free(sk_ciphers);\n SSL_free(ssl);\n SSL_CTX_free(ctx);\n return numciphers;\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->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL) {\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(s);\n return NULL;\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->references = 1;\n s->max_early_data = ctx->max_early_data;\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 OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);\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->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 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 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->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 ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n BIO_free_all(s->rbio);\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 if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\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 sk_X509_NAME_pop_free(s->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 RECORD_LAYER_release(&s->rlayer);\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}', 'int ssl_clear_bad_session(SSL *s)\n{\n if ((s->session != NULL) &&\n !(s->shutdown & SSL_SENT_SHUTDOWN) &&\n !(SSL_in_init(s) || SSL_in_before(s))) {\n SSL_CTX_remove_session(s->session_ctx, s->session);\n return (1);\n } else\n return (0);\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}']
36,510
0
https://github.com/libav/libav/blob/c41b9842ceac42bedfd74a7ba2d02add82f818a9/libavcodec/rv40.c/#L512
static void rv40_loop_filter(RV34DecContext *r, int row) { MpegEncContext *s = &r->s; int mb_pos, mb_x; int i, j, k; uint8_t *Y, *C; int alpha, beta, betaY, betaC; int q; int mbtype[4]; int mb_strong[4]; int clip[4]; int cbp[4]; int uvcbp[4][2]; int mvmasks[4]; mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int mbtype = s->current_picture_ptr->f.mb_type[mb_pos]; if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype)) r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF; if(IS_INTRA(mbtype)) r->cbp_chroma[mb_pos] = 0xFF; } mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int y_h_deblock, y_v_deblock; int c_v_deblock[2], c_h_deblock[2]; int clip_left; int avail[4]; int y_to_deblock, c_to_deblock[2]; q = s->current_picture_ptr->f.qscale_table[mb_pos]; alpha = rv40_alpha_tab[q]; beta = rv40_beta_tab [q]; betaY = betaC = beta * 3; if(s->width * s->height <= 176*144) betaY += beta; avail[0] = 1; avail[1] = row; avail[2] = mb_x; avail[3] = row < s->mb_height - 1; for(i = 0; i < 4; i++){ if(avail[i]){ int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride; mvmasks[i] = r->deblock_coefs[pos]; mbtype [i] = s->current_picture_ptr->f.mb_type[pos]; cbp [i] = r->cbp_luma[pos]; uvcbp[i][0] = r->cbp_chroma[pos] & 0xF; uvcbp[i][1] = r->cbp_chroma[pos] >> 4; }else{ mvmasks[i] = 0; mbtype [i] = mbtype[0]; cbp [i] = 0; uvcbp[i][0] = uvcbp[i][1] = 0; } mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]); clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q]; } y_to_deblock = mvmasks[POS_CUR] | (mvmasks[POS_BOTTOM] << 16); y_h_deblock = y_to_deblock | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW) | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12); y_v_deblock = y_to_deblock | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL) | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3); if(!mb_x) y_v_deblock &= ~MASK_Y_LEFT_COL; if(!row) y_h_deblock &= ~MASK_Y_TOP_ROW; if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])) y_h_deblock &= ~(MASK_Y_TOP_ROW << 16); for(i = 0; i < 2; i++){ c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i]; c_v_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL) | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1); c_h_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2) | (uvcbp[POS_CUR][i] << 2); if(!mb_x) c_v_deblock[i] &= ~MASK_C_LEFT_COL; if(!row) c_h_deblock[i] &= ~MASK_C_TOP_ROW; if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]) c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4); } for(j = 0; j < 16; j += 4){ Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize; for(i = 0; i < 4; i++, Y += 4){ int ij = i + j; int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0; int dither = j ? ij : i*4; if(y_h_deblock & (MASK_BOTTOM << ij)){ rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize, s->linesize, dither, y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0, clip_cur, alpha, beta, betaY, 0, 0, 0); } if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; else clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 0, 1); } if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither, clip_cur, mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0, alpha, beta, betaY, 0, 1, 0); } if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 1, 1); } } } for(k = 0; k < 2; k++){ for(j = 0; j < 2; j++){ C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize; for(i = 0; i < 2; i++, C += 4){ int ij = i + j*2; int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0; if(c_h_deblock[k] & (MASK_CUR << (ij+2))){ int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0; rv40_adaptive_loop_filter(&r->rdsp, C+4*s->uvlinesize, s->uvlinesize, i*8, clip_bot, clip_cur, alpha, beta, betaC, 1, 0, 0); } if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; else clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 0, 1); } if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0; rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, i*8, clip_cur, clip_top, alpha, beta, betaC, 1, 1, 0); } if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 1, 1); } } } } } }
['static void rv40_loop_filter(RV34DecContext *r, int row)\n{\n MpegEncContext *s = &r->s;\n int mb_pos, mb_x;\n int i, j, k;\n uint8_t *Y, *C;\n int alpha, beta, betaY, betaC;\n int q;\n int mbtype[4];\n int mb_strong[4];\n int clip[4];\n int cbp[4];\n int uvcbp[4][2];\n int mvmasks[4];\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int mbtype = s->current_picture_ptr->f.mb_type[mb_pos];\n if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))\n r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF;\n if(IS_INTRA(mbtype))\n r->cbp_chroma[mb_pos] = 0xFF;\n }\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int y_h_deblock, y_v_deblock;\n int c_v_deblock[2], c_h_deblock[2];\n int clip_left;\n int avail[4];\n int y_to_deblock, c_to_deblock[2];\n q = s->current_picture_ptr->f.qscale_table[mb_pos];\n alpha = rv40_alpha_tab[q];\n beta = rv40_beta_tab [q];\n betaY = betaC = beta * 3;\n if(s->width * s->height <= 176*144)\n betaY += beta;\n avail[0] = 1;\n avail[1] = row;\n avail[2] = mb_x;\n avail[3] = row < s->mb_height - 1;\n for(i = 0; i < 4; i++){\n if(avail[i]){\n int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;\n mvmasks[i] = r->deblock_coefs[pos];\n mbtype [i] = s->current_picture_ptr->f.mb_type[pos];\n cbp [i] = r->cbp_luma[pos];\n uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;\n uvcbp[i][1] = r->cbp_chroma[pos] >> 4;\n }else{\n mvmasks[i] = 0;\n mbtype [i] = mbtype[0];\n cbp [i] = 0;\n uvcbp[i][0] = uvcbp[i][1] = 0;\n }\n mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);\n clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];\n }\n y_to_deblock = mvmasks[POS_CUR]\n | (mvmasks[POS_BOTTOM] << 16);\n y_h_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)\n | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);\n y_v_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)\n | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);\n if(!mb_x)\n y_v_deblock &= ~MASK_Y_LEFT_COL;\n if(!row)\n y_h_deblock &= ~MASK_Y_TOP_ROW;\n if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]))\n y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);\n for(i = 0; i < 2; i++){\n c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];\n c_v_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)\n | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);\n c_h_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)\n | (uvcbp[POS_CUR][i] << 2);\n if(!mb_x)\n c_v_deblock[i] &= ~MASK_C_LEFT_COL;\n if(!row)\n c_h_deblock[i] &= ~MASK_C_TOP_ROW;\n if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])\n c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);\n }\n for(j = 0; j < 16; j += 4){\n Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;\n for(i = 0; i < 4; i++, Y += 4){\n int ij = i + j;\n int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n int dither = j ? ij : i*4;\n if(y_h_deblock & (MASK_BOTTOM << ij)){\n rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize,\n s->linesize, dither,\n y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,\n clip_cur, alpha, beta, betaY,\n 0, 0, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n else\n clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 0, 1);\n }\n if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0,\n alpha, beta, betaY, 0, 1, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 1, 1);\n }\n }\n }\n for(k = 0; k < 2; k++){\n for(j = 0; j < 2; j++){\n C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;\n for(i = 0; i < 2; i++, C += 4){\n int ij = i + j*2;\n int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n if(c_h_deblock[k] & (MASK_CUR << (ij+2))){\n int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C+4*s->uvlinesize, s->uvlinesize, i*8,\n clip_bot,\n clip_cur,\n alpha, beta, betaC, 1, 0, 0);\n }\n if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n else\n clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 0, 1);\n }\n if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, i*8,\n clip_cur,\n clip_top,\n alpha, beta, betaC, 1, 1, 0);\n }\n if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 1, 1);\n }\n }\n }\n }\n }\n}']
36,511
0
https://gitlab.com/libtiff/libtiff/blob/43b0c984f0a2c81565b05b6590bf9de7df612477/libtiff/tif_tile.c/#L78
int TIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s) { TIFFDirectory *td = &tif->tif_dir; if (x >= td->td_imagewidth) { TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%lu: Col out of range, max %lu", (unsigned long) x, (unsigned long) (td->td_imagewidth - 1)); return (0); } if (y >= td->td_imagelength) { TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%lu: Row out of range, max %lu", (unsigned long) y, (unsigned long) (td->td_imagelength - 1)); return (0); } if (z >= td->td_imagedepth) { TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%lu: Depth out of range, max %lu", (unsigned long) z, (unsigned long) (td->td_imagedepth - 1)); return (0); } if (td->td_planarconfig == PLANARCONFIG_SEPARATE && s >= td->td_samplesperpixel) { TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%lu: Sample out of range, max %lu", (unsigned long) s, (unsigned long) (td->td_samplesperpixel - 1)); return (0); } return (1); }
['static int\nwriteSelections(TIFF *in, TIFF **out, struct crop_mask *crop,\n struct image_data *image, struct dump_opts *dump,\n struct buffinfo seg_buffs[], char *mp, char *filename,\n unsigned int *page, unsigned int total_pages)\n {\n int i, page_count;\n int autoindex = 0;\n unsigned char *crop_buff = NULL;\n switch (crop->exp_mode)\n {\n case ONE_FILE_COMPOSITE:\n autoindex = 0;\n crop_buff = seg_buffs[0].buffer;\n if (update_output_file (out, mp, autoindex, filename, page))\n return (1);\n page_count = total_pages;\n if (writeCroppedImage(in, *out, image, dump,\n crop->combined_width,\n crop->combined_length,\n crop_buff, *page, total_pages))\n {\n TIFFError("writeRegions", "Unable to write new image");\n return (-1);\n }\n\t break;\n case ONE_FILE_SEPARATED:\n autoindex = 0;\n if (update_output_file (out, mp, autoindex, filename, page))\n return (1);\n page_count = crop->selections * total_pages;\n for (i = 0; i < crop->selections; i++)\n {\n crop_buff = seg_buffs[i].buffer;\n if (writeCroppedImage(in, *out, image, dump,\n crop->regionlist[i].width,\n crop->regionlist[i].length,\n crop_buff, *page, page_count))\n {\n TIFFError("writeRegions", "Unable to write new image");\n return (-1);\n }\n\t }\n break;\n case FILE_PER_IMAGE_COMPOSITE:\n autoindex = 1;\n if (update_output_file (out, mp, autoindex, filename, page))\n return (1);\n crop_buff = seg_buffs[0].buffer;\n if (writeCroppedImage(in, *out, image, dump,\n crop->combined_width,\n crop->combined_length,\n crop_buff, *page, total_pages))\n {\n TIFFError("writeRegions", "Unable to write new image");\n return (-1);\n }\n break;\n case FILE_PER_IMAGE_SEPARATED:\n autoindex = 1;\n page_count = crop->selections;\n if (update_output_file (out, mp, autoindex, filename, page))\n return (1);\n for (i = 0; i < crop->selections; i++)\n {\n crop_buff = seg_buffs[i].buffer;\n if (writeCroppedImage(in, *out, image, dump,\n crop->regionlist[i].width,\n crop->regionlist[i].length,\n crop_buff, *page, page_count))\n {\n TIFFError("writeRegions", "Unable to write new image");\n return (-1);\n }\n }\n break;\n case FILE_PER_SELECTION:\n autoindex = 1;\n\t page_count = 1;\n for (i = 0; i < crop->selections; i++)\n {\n if (update_output_file (out, mp, autoindex, filename, page))\n return (1);\n crop_buff = seg_buffs[i].buffer;\n if (writeCroppedImage(in, *out, image, dump,\n crop->regionlist[i].width,\n crop->regionlist[i].length,\n crop_buff, *page, page_count))\n {\n TIFFError("writeRegions", "Unable to write new image");\n return (-1);\n }\n }\n\t break;\n default: return (1);\n }\n return (0);\n }', 'static int\nupdate_output_file (TIFF **tiffout, char *mode, int autoindex,\n char *outname, unsigned int *page)\n {\n static int findex = 0;\n size_t basename_len;\n char *sep;\n char export_ext[16];\n char exportname[PATH_MAX];\n if (autoindex && (*tiffout != NULL))\n {\n TIFFClose (*tiffout);\n *tiffout = NULL;\n }\n memcpy (export_ext, ".tiff", 6);\n memset (exportname, \'\\0\', sizeof(exportname));\n #define FILENUM_MAX_LENGTH (1+6+1+4+1)\n strncpy (exportname, outname, sizeof(exportname) - FILENUM_MAX_LENGTH);\n if (*tiffout == NULL)\n {\n if (autoindex)\n {\n findex++;\n if ((sep = strstr(exportname, ".tif")) || (sep = strstr(exportname, ".TIF")))\n {\n strncpy (export_ext, sep, 5);\n *sep = \'\\0\';\n }\n else\n memcpy (export_ext, ".tiff", 5);\n export_ext[5] = \'\\0\';\n basename_len = strlen(exportname);\n if (findex > MAX_EXPORT_PAGES)\n {\n TIFFError("update_output_file", "Maximum of %d pages per file exceeded", MAX_EXPORT_PAGES);\n return 1;\n }\n snprintf(exportname + basename_len, sizeof(exportname) - basename_len, "-%03d%.5s", findex, export_ext);\n }\n exportname[sizeof(exportname) - 1] = \'\\0\';\n *tiffout = TIFFOpen(exportname, mode);\n if (*tiffout == NULL)\n {\n TIFFError("update_output_file", "Unable to open output file %s", exportname);\n return 1;\n }\n *page = 0;\n return 0;\n }\n else\n (*page)++;\n return 0;\n }', '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 }\n CopyTag(TIFFTAG_BADFAXLINES, 1, TIFF_LONG);\n CopyTag(TIFFTAG_CLEANFAXDATA, 1, TIFF_LONG);\n CopyTag(TIFFTAG_CONSECUTIVEBADFAXLINES, 1, TIFF_LONG);\n CopyTag(TIFFTAG_FAXRECVPARAMS, 1, TIFF_LONG);\n CopyTag(TIFFTAG_FAXRECVTIME, 1, TIFF_LONG);\n CopyTag(TIFFTAG_FAXSUBADDRESS, 1, TIFF_ASCII);\n 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 return (-1);\n }\n return (0);\n }', 'static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength,\n\t\t\t\t uint32 imagewidth, tsample_t spp,\n struct dump_opts* dump)\n {\n uint16 bps;\n uint32 tl, tw;\n uint32 row, col, nrow, ncol;\n uint32 src_rowsize, col_offset;\n uint32 tile_rowsize = TIFFTileRowSize(out);\n uint8* bufp = (uint8*) buf;\n tsize_t tile_buffsize = 0;\n tsize_t tilesize = TIFFTileSize(out);\n unsigned char *tilebuf = NULL;\n if( !TIFFGetField(out, TIFFTAG_TILELENGTH, &tl) ||\n !TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw) ||\n !TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps) )\n return 1;\n if (tilesize == 0 || tile_rowsize == 0 || tl == 0 || tw == 0)\n {\n TIFFError("writeBufferToContigTiles", "Tile size, tile row size, tile width, or tile length is zero");\n exit(-1);\n }\n tile_buffsize = tilesize;\n if (tilesize < (tsize_t)(tl * tile_rowsize))\n {\n#ifdef DEBUG2\n TIFFError("writeBufferToContigTiles",\n\t "Tilesize %lu is too small, using alternate calculation %u",\n tilesize, tl * tile_rowsize);\n#endif\n tile_buffsize = tl * tile_rowsize;\n if (tl != tile_buffsize / tile_rowsize)\n {\n\tTIFFError("writeBufferToContigTiles", "Integer overflow when calculating buffer size");\n\texit(-1);\n }\n }\n if( imagewidth == 0 ||\n (uint32)bps * (uint32)spp > TIFF_UINT32_MAX / imagewidth ||\n bps * spp * imagewidth > TIFF_UINT32_MAX - 7U )\n {\n TIFFError(TIFFFileName(out),\n "Error, uint32 overflow when computing (imagewidth * bps * spp) + 7");\n return 1;\n }\n src_rowsize = ((imagewidth * spp * bps) + 7U) / 8;\n tilebuf = _TIFFmalloc(tile_buffsize);\n if (tilebuf == 0)\n return 1;\n for (row = 0; row < imagelength; row += tl)\n {\n nrow = (row + tl > imagelength) ? imagelength - row : tl;\n for (col = 0; col < imagewidth; col += tw)\n {\n if (col + tw > imagewidth)\n\tncol = imagewidth - col;\n else\n ncol = tw;\n col_offset = (((col * bps * spp) + 7) / 8);\n bufp = buf + (row * src_rowsize) + col_offset;\n if (extractContigSamplesToTileBuffer(tilebuf, bufp, nrow, ncol, imagewidth,\n\t\t\t\t\t tw, 0, spp, spp, bps, dump) > 0)\n {\n\tTIFFError("writeBufferToContigTiles",\n "Unable to extract data to tile for row %lu, col %lu",\n (unsigned long) row, (unsigned long)col);\n\t_TIFFfree(tilebuf);\n\treturn 1;\n }\n if (TIFFWriteTile(out, tilebuf, col, row, 0, 0) < 0)\n {\n\tTIFFError("writeBufferToContigTiles",\n\t "Cannot write tile at %lu %lu",\n\t (unsigned long) col, (unsigned long) row);\n\t _TIFFfree(tilebuf);\n\treturn 1;\n\t}\n }\n }\n _TIFFfree(tilebuf);\n return 0;\n }', 'tmsize_t\nTIFFWriteTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tif (!TIFFCheckTile(tif, x, y, z, s))\n\t\treturn ((tmsize_t)(-1));\n\treturn (TIFFWriteEncodedTile(tif,\n\t TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1)));\n}', 'int\nTIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif (x >= td->td_imagewidth) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Col out of range, max %lu",\n\t\t\t (unsigned long) x,\n\t\t\t (unsigned long) (td->td_imagewidth - 1));\n\t\treturn (0);\n\t}\n\tif (y >= td->td_imagelength) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Row out of range, max %lu",\n\t\t\t (unsigned long) y,\n\t\t\t (unsigned long) (td->td_imagelength - 1));\n\t\treturn (0);\n\t}\n\tif (z >= td->td_imagedepth) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Depth out of range, max %lu",\n\t\t\t (unsigned long) z,\n\t\t\t (unsigned long) (td->td_imagedepth - 1));\n\t\treturn (0);\n\t}\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE &&\n\t s >= td->td_samplesperpixel) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Sample out of range, max %lu",\n\t\t\t (unsigned long) s,\n\t\t\t (unsigned long) (td->td_samplesperpixel - 1));\n\t\treturn (0);\n\t}\n\treturn (1);\n}']
36,512
0
https://github.com/nginx/nginx/blob/ba290091cf2c369ae36c6c3845f770f85f1172e6/src/core/ngx_parse.c/#L21
ssize_t ngx_parse_size(ngx_str_t *line) { u_char unit; size_t len; ssize_t size; ngx_int_t scale; len = line->len; unit = line->data[len - 1]; switch (unit) { case 'K': case 'k': len--; scale = 1024; break; case 'M': case 'm': len--; scale = 1024 * 1024; break; default: scale = 1; } size = ngx_atosz(line->data, len); if (size == NGX_ERROR) { return NGX_ERROR; } size *= scale; return size; }
['static char *\nngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n u_char *p;\n ssize_t size;\n ngx_str_t *value, name, s;\n ngx_uint_t i;\n ngx_shm_zone_t *shm_zone;\n ngx_http_limit_conn_ctx_t *ctx;\n value = cf->args->elts;\n ctx = NULL;\n size = 0;\n name.len = 0;\n for (i = 1; i < cf->args->nelts; i++) {\n if (ngx_strncmp(value[i].data, "zone=", 5) == 0) {\n name.data = value[i].data + 5;\n p = (u_char *) ngx_strchr(name.data, \':\');\n if (p == NULL) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid zone size \\"%V\\"", &value[i]);\n return NGX_CONF_ERROR;\n }\n name.len = p - name.data;\n s.data = p + 1;\n s.len = value[i].data + value[i].len - s.data;\n size = ngx_parse_size(&s);\n if (size == NGX_ERROR) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid zone size \\"%V\\"", &value[i]);\n return NGX_CONF_ERROR;\n }\n if (size < (ssize_t) (8 * ngx_pagesize)) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "zone \\"%V\\" is too small", &value[i]);\n return NGX_CONF_ERROR;\n }\n continue;\n }\n if (value[i].len > 1 && value[i].data[0] == \'$\') {\n value[i].len--;\n value[i].data++;\n ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_conn_ctx_t));\n if (ctx == NULL) {\n return NGX_CONF_ERROR;\n }\n ctx->index = ngx_http_get_variable_index(cf, &value[i]);\n if (ctx->index == NGX_ERROR) {\n return NGX_CONF_ERROR;\n }\n ctx->var = value[i];\n continue;\n }\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid parameter \\"%V\\"", &value[i]);\n return NGX_CONF_ERROR;\n }\n if (name.len == 0) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "\\"%V\\" must have \\"zone\\" parameter",\n &cmd->name);\n return NGX_CONF_ERROR;\n }\n if (ctx == NULL) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "no variable is defined for %V \\"%V\\"",\n &cmd->name, &name);\n return NGX_CONF_ERROR;\n }\n shm_zone = ngx_shared_memory_add(cf, &name, size,\n &ngx_http_limit_conn_module);\n if (shm_zone == NULL) {\n return NGX_CONF_ERROR;\n }\n if (shm_zone->data) {\n ctx = shm_zone->data;\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "%V \\"%V\\" is already bound to variable \\"%V\\"",\n &cmd->name, &name, &ctx->var);\n return NGX_CONF_ERROR;\n }\n shm_zone->init = ngx_http_limit_conn_init_zone;\n shm_zone->data = ctx;\n return NGX_CONF_OK;\n}', "ssize_t\nngx_parse_size(ngx_str_t *line)\n{\n u_char unit;\n size_t len;\n ssize_t size;\n ngx_int_t scale;\n len = line->len;\n unit = line->data[len - 1];\n switch (unit) {\n case 'K':\n case 'k':\n len--;\n scale = 1024;\n break;\n case 'M':\n case 'm':\n len--;\n scale = 1024 * 1024;\n break;\n default:\n scale = 1;\n }\n size = ngx_atosz(line->data, len);\n if (size == NGX_ERROR) {\n return NGX_ERROR;\n }\n size *= scale;\n return size;\n}"]
36,513
0
https://github.com/libav/libav/blob/a893655bdaa726a82424367b6456d195be12ebbc/libavcodec/proresenc.c/#L475
static inline int estimate_vlc(unsigned codebook, int val) { unsigned int rice_order, exp_order, switch_bits, switch_val; int exponent; switch_bits = (codebook & 3) + 1; rice_order = codebook >> 5; exp_order = (codebook >> 2) & 7; switch_val = switch_bits << rice_order; if (val >= switch_val) { val -= switch_val - (1 << exp_order); exponent = av_log2(val); return exponent * 2 - exp_order + switch_bits + 1; } else { return (val >> rice_order) + rice_order + 1; } }
['static int estimate_dcs(int *error, DCTELEM *blocks, int blocks_per_slice,\n int scale)\n{\n int i;\n int codebook = 3, code, dc, prev_dc, delta, sign, new_sign;\n int bits;\n prev_dc = (blocks[0] - 0x4000) / scale;\n bits = estimate_vlc(FIRST_DC_CB, MAKE_CODE(prev_dc));\n sign = 0;\n codebook = 3;\n blocks += 64;\n *error += FFABS(blocks[0] - 0x4000) % scale;\n for (i = 1; i < blocks_per_slice; i++, blocks += 64) {\n dc = (blocks[0] - 0x4000) / scale;\n *error += FFABS(blocks[0] - 0x4000) % scale;\n delta = dc - prev_dc;\n new_sign = GET_SIGN(delta);\n delta = (delta ^ sign) - sign;\n code = MAKE_CODE(delta);\n bits += estimate_vlc(ff_prores_dc_codebook[codebook], code);\n codebook = (code + (code & 1)) >> 1;\n codebook = FFMIN(codebook, 3);\n sign = new_sign;\n prev_dc = dc;\n }\n return bits;\n}', 'static inline int estimate_vlc(unsigned codebook, int val)\n{\n unsigned int rice_order, exp_order, switch_bits, switch_val;\n int exponent;\n switch_bits = (codebook & 3) + 1;\n rice_order = codebook >> 5;\n exp_order = (codebook >> 2) & 7;\n switch_val = switch_bits << rice_order;\n if (val >= switch_val) {\n val -= switch_val - (1 << exp_order);\n exponent = av_log2(val);\n return exponent * 2 - exp_order + switch_bits + 1;\n } else {\n return (val >> rice_order) + rice_order + 1;\n }\n}', 'static av_always_inline av_const int ff_log2_c(unsigned int v)\n{\n int n = 0;\n if (v & 0xffff0000) {\n v >>= 16;\n n += 16;\n }\n if (v & 0xff00) {\n v >>= 8;\n n += 8;\n }\n n += ff_log2_tab[v];\n return n;\n}']
36,514
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/rsaref/rsaref.c/#L163
static int RSAref_bn2bin(BIGNUM *from, unsigned char *to, int max) { int i; i=BN_num_bytes(from); if (i > max) { RSAREFerr(RSAREF_F_RSAREF_BN2BIN,RSAREF_R_LEN); return(0); } memset(to,0,(unsigned int)max); if (!BN_bn2bin(from,&(to[max-i]))) return(0); return(1); }
['static int RSAref_Private_eay2ref(RSA *from, RSArefPrivateKey *to)\n\t{\n\tto->bits=BN_num_bits(from->n);\n\tif (!RSAref_bn2bin(from->n,to->m,RSAref_MAX_LEN)) return(0);\n\tif (!RSAref_bn2bin(from->e,to->e,RSAref_MAX_LEN)) return(0);\n\tif (!RSAref_bn2bin(from->d,to->d,RSAref_MAX_LEN)) return(0);\n\tif (!RSAref_bn2bin(from->p,to->prime[0],RSAref_MAX_PLEN)) return(0);\n\tif (!RSAref_bn2bin(from->q,to->prime[1],RSAref_MAX_PLEN)) return(0);\n\tif (!RSAref_bn2bin(from->dmp1,to->pexp[0],RSAref_MAX_PLEN)) return(0);\n\tif (!RSAref_bn2bin(from->dmq1,to->pexp[1],RSAref_MAX_PLEN)) return(0);\n\tif (!RSAref_bn2bin(from->iqmp,to->coef,RSAref_MAX_PLEN)) return(0);\n\treturn(1);\n\t}', 'static int RSAref_bn2bin(BIGNUM *from, unsigned char *to, int max)\n\t{\n\tint i;\n\ti=BN_num_bytes(from);\n\tif (i > max)\n\t\t{\n\t\tRSAREFerr(RSAREF_F_RSAREF_BN2BIN,RSAREF_R_LEN);\n\t\treturn(0);\n\t\t}\n\tmemset(to,0,(unsigned int)max);\n\tif (!BN_bn2bin(from,&(to[max-i])))\n\t\treturn(0);\n\treturn(1);\n\t}']
36,515
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 DSA_do_verify(unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa)\n\t{\n\tBN_CTX *ctx;\n\tBIGNUM u1,u2,t1;\n\tBN_MONT_CTX *mont=NULL;\n\tint ret = -1;\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tBN_init(&u1);\n\tBN_init(&u2);\n\tBN_init(&t1);\n\tif ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;\n\tif (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;\n\tif (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;\n\tif (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;\n\tif ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))\n\t\t{\n\t\tif ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,\n\t\t\t\tdsa->p,ctx)) goto err;\n\t\t}\n\tmont=(BN_MONT_CTX *)dsa->method_mont_p;\n#if 0\n\t{\n\tBIGNUM t2;\n\tBN_init(&t2);\n\tif (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;\n\tif (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;\n\tif (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;\n\tBN_free(&t2);\n\t}\n\tif (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;\n#else\n\t{\n\tif (!BN_mod_exp2_mont(&t1,dsa->g,&u1,dsa->pub_key,&u2,dsa->p,ctx,mont))\n\t\tgoto err;\n\tif (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;\n\t}\n#endif\n\tret=(BN_ucmp(&u1, sig->r) == 0);\n\terr:\n\tif (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tBN_free(&u1);\n\tBN_free(&u2);\n\tBN_free(&t1);\n\treturn(ret);\n\t}', 'int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint r=0;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(m);\n\tt= &(ctx->bn[ctx->tos++]);\n\tif (a == b)\n\t\t{ if (!BN_sqr(t,a,ctx)) goto err; }\n\telse\n\t\t{ if (!BN_mul(t,a,b,ctx)) goto err; }\n\tif (!BN_mod(ret,t,m,ctx)) goto err;\n\tr=1;\nerr:\n\tctx->tos--;\n\treturn(r);\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}']
36,516
0
https://github.com/libav/libav/blob/baf35bb4bc4fe7a2a4113c50989d11dd9ef81e76/libavcodec/vc1dec.c/#L4399
static void vc1_decode_i_blocks(VC1Context *v) { int k, j; MpegEncContext *s = &v->s; int cbp, val; uint8_t *coded_val; int mb_pos; switch (v->y_ac_table_index) { case 0: v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA; break; case 1: v->codingset = CS_HIGH_MOT_INTRA; break; case 2: v->codingset = CS_MID_RATE_INTRA; break; } switch (v->c_ac_table_index) { case 0: v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER; break; case 1: v->codingset2 = CS_HIGH_MOT_INTER; break; case 2: v->codingset2 = CS_MID_RATE_INTER; break; } s->y_dc_scale = s->y_dc_scale_table[v->pq]; s->c_dc_scale = s->c_dc_scale_table[v->pq]; s->mb_x = s->mb_y = 0; s->mb_intra = 1; s->first_slice_line = 1; for (s->mb_y = 0; s->mb_y < s->end_mb_y; s->mb_y++) { s->mb_x = 0; ff_init_block_index(s); for (; s->mb_x < v->end_mb_x; s->mb_x++) { uint8_t *dst[6]; ff_update_block_index(s); dst[0] = s->dest[0]; dst[1] = dst[0] + 8; dst[2] = s->dest[0] + s->linesize * 8; dst[3] = dst[2] + 8; dst[4] = s->dest[1]; dst[5] = s->dest[2]; s->dsp.clear_blocks(s->block[0]); mb_pos = s->mb_x + s->mb_y * s->mb_width; s->current_picture.f.mb_type[mb_pos] = MB_TYPE_INTRA; s->current_picture.f.qscale_table[mb_pos] = v->pq; s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0; s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0; cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); v->s.ac_pred = get_bits1(&v->s.gb); for (k = 0; k < 6; k++) { val = ((cbp >> (5 - k)) & 1); if (k < 4) { int pred = vc1_coded_block_pred(&v->s, k, &coded_val); val = val ^ pred; *coded_val = val; } cbp |= val << (5 - k); vc1_decode_i_block(v, s->block[k], k, val, (k < 4) ? v->codingset : v->codingset2); if (k > 3 && (s->flags & CODEC_FLAG_GRAY)) continue; v->vc1dsp.vc1_inv_trans_8x8(s->block[k]); if (v->pq >= 9 && v->overlap) { if (v->rangeredfrm) for (j = 0; j < 64; j++) s->block[k][j] <<= 1; s->dsp.put_signed_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize); } else { if (v->rangeredfrm) for (j = 0; j < 64; j++) s->block[k][j] = (s->block[k][j] - 64) << 1; s->dsp.put_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize); } } if (v->pq >= 9 && v->overlap) { if (s->mb_x) { v->vc1dsp.vc1_h_overlap(s->dest[0], s->linesize); v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize); if (!(s->flags & CODEC_FLAG_GRAY)) { v->vc1dsp.vc1_h_overlap(s->dest[1], s->uvlinesize); v->vc1dsp.vc1_h_overlap(s->dest[2], s->uvlinesize); } } v->vc1dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize); v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize); if (!s->first_slice_line) { v->vc1dsp.vc1_v_overlap(s->dest[0], s->linesize); v->vc1dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize); if (!(s->flags & CODEC_FLAG_GRAY)) { v->vc1dsp.vc1_v_overlap(s->dest[1], s->uvlinesize); v->vc1dsp.vc1_v_overlap(s->dest[2], s->uvlinesize); } } v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize); v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize); } if (v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq); if (get_bits_count(&s->gb) > v->bits) { ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, ER_MB_ERROR); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits); return; } } if (!v->s.loop_filter) ff_draw_horiz_band(s, s->mb_y * 16, 16); else if (s->mb_y) ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16); s->first_slice_line = 0; } if (v->s.loop_filter) ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16); ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, ER_MB_END); }
['static void vc1_decode_i_blocks(VC1Context *v)\n{\n int k, j;\n MpegEncContext *s = &v->s;\n int cbp, val;\n uint8_t *coded_val;\n int mb_pos;\n switch (v->y_ac_table_index) {\n case 0:\n v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA;\n break;\n case 1:\n v->codingset = CS_HIGH_MOT_INTRA;\n break;\n case 2:\n v->codingset = CS_MID_RATE_INTRA;\n break;\n }\n switch (v->c_ac_table_index) {\n case 0:\n v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER;\n break;\n case 1:\n v->codingset2 = CS_HIGH_MOT_INTER;\n break;\n case 2:\n v->codingset2 = CS_MID_RATE_INTER;\n break;\n }\n s->y_dc_scale = s->y_dc_scale_table[v->pq];\n s->c_dc_scale = s->c_dc_scale_table[v->pq];\n s->mb_x = s->mb_y = 0;\n s->mb_intra = 1;\n s->first_slice_line = 1;\n for (s->mb_y = 0; s->mb_y < s->end_mb_y; s->mb_y++) {\n s->mb_x = 0;\n ff_init_block_index(s);\n for (; s->mb_x < v->end_mb_x; s->mb_x++) {\n uint8_t *dst[6];\n ff_update_block_index(s);\n dst[0] = s->dest[0];\n dst[1] = dst[0] + 8;\n dst[2] = s->dest[0] + s->linesize * 8;\n dst[3] = dst[2] + 8;\n dst[4] = s->dest[1];\n dst[5] = s->dest[2];\n s->dsp.clear_blocks(s->block[0]);\n mb_pos = s->mb_x + s->mb_y * s->mb_width;\n s->current_picture.f.mb_type[mb_pos] = MB_TYPE_INTRA;\n s->current_picture.f.qscale_table[mb_pos] = v->pq;\n s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0;\n s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0;\n cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);\n v->s.ac_pred = get_bits1(&v->s.gb);\n for (k = 0; k < 6; k++) {\n val = ((cbp >> (5 - k)) & 1);\n if (k < 4) {\n int pred = vc1_coded_block_pred(&v->s, k, &coded_val);\n val = val ^ pred;\n *coded_val = val;\n }\n cbp |= val << (5 - k);\n vc1_decode_i_block(v, s->block[k], k, val, (k < 4) ? v->codingset : v->codingset2);\n if (k > 3 && (s->flags & CODEC_FLAG_GRAY))\n continue;\n v->vc1dsp.vc1_inv_trans_8x8(s->block[k]);\n if (v->pq >= 9 && v->overlap) {\n if (v->rangeredfrm)\n for (j = 0; j < 64; j++)\n s->block[k][j] <<= 1;\n s->dsp.put_signed_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize);\n } else {\n if (v->rangeredfrm)\n for (j = 0; j < 64; j++)\n s->block[k][j] = (s->block[k][j] - 64) << 1;\n s->dsp.put_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize);\n }\n }\n if (v->pq >= 9 && v->overlap) {\n if (s->mb_x) {\n v->vc1dsp.vc1_h_overlap(s->dest[0], s->linesize);\n v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize);\n if (!(s->flags & CODEC_FLAG_GRAY)) {\n v->vc1dsp.vc1_h_overlap(s->dest[1], s->uvlinesize);\n v->vc1dsp.vc1_h_overlap(s->dest[2], s->uvlinesize);\n }\n }\n v->vc1dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize);\n v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);\n if (!s->first_slice_line) {\n v->vc1dsp.vc1_v_overlap(s->dest[0], s->linesize);\n v->vc1dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize);\n if (!(s->flags & CODEC_FLAG_GRAY)) {\n v->vc1dsp.vc1_v_overlap(s->dest[1], s->uvlinesize);\n v->vc1dsp.vc1_v_overlap(s->dest[2], s->uvlinesize);\n }\n }\n v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize);\n v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize);\n }\n if (v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq);\n if (get_bits_count(&s->gb) > v->bits) {\n ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, ER_MB_ERROR);\n av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\\n",\n get_bits_count(&s->gb), v->bits);\n return;\n }\n }\n if (!v->s.loop_filter)\n ff_draw_horiz_band(s, s->mb_y * 16, 16);\n else if (s->mb_y)\n ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16);\n s->first_slice_line = 0;\n }\n if (v->s.loop_filter)\n ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16);\n ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, ER_MB_END);\n}', 'static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,\n int coded, int codingset)\n{\n GetBitContext *gb = &v->s.gb;\n MpegEncContext *s = &v->s;\n int dc_pred_dir = 0;\n int i;\n int16_t *dc_val;\n int16_t *ac_val, *ac_val2;\n int dcdiff;\n if (n < 4) {\n dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);\n } else {\n dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);\n }\n if (dcdiff < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\\n");\n return -1;\n }\n if (dcdiff) {\n if (dcdiff == 119 ) {\n if (v->pq == 1) dcdiff = get_bits(gb, 10);\n else if (v->pq == 2) dcdiff = get_bits(gb, 9);\n else dcdiff = get_bits(gb, 8);\n } else {\n if (v->pq == 1)\n dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3;\n else if (v->pq == 2)\n dcdiff = (dcdiff << 1) + get_bits1(gb) - 1;\n }\n if (get_bits1(gb))\n dcdiff = -dcdiff;\n }\n dcdiff += vc1_i_pred_dc(&v->s, v->overlap, v->pq, n, &dc_val, &dc_pred_dir);\n *dc_val = dcdiff;\n if (n < 4) {\n block[0] = dcdiff * s->y_dc_scale;\n } else {\n block[0] = dcdiff * s->c_dc_scale;\n }\n if (!coded) {\n goto not_coded;\n }\n i = 1;\n {\n int last = 0, skip, value;\n const uint8_t *zz_table;\n int scale;\n int k;\n scale = v->pq * 2 + v->halfpq;\n if (v->s.ac_pred) {\n if (!dc_pred_dir)\n zz_table = v->zz_8x8[2];\n else\n zz_table = v->zz_8x8[3];\n } else\n zz_table = v->zz_8x8[1];\n ac_val = s->ac_val[0][0] + s->block_index[n] * 16;\n ac_val2 = ac_val;\n if (dc_pred_dir)\n ac_val -= 16;\n else\n ac_val -= 16 * s->block_wrap[n];\n while (!last) {\n vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);\n i += skip;\n if (i > 63)\n break;\n block[zz_table[i++]] = value;\n }\n if (s->ac_pred) {\n if (dc_pred_dir) {\n for (k = 1; k < 8; k++)\n block[k << v->left_blk_sh] += ac_val[k];\n } else {\n for (k = 1; k < 8; k++)\n block[k << v->top_blk_sh] += ac_val[k + 8];\n }\n }\n for (k = 1; k < 8; k++) {\n ac_val2[k] = block[k << v->left_blk_sh];\n ac_val2[k + 8] = block[k << v->top_blk_sh];\n }\n for (k = 1; k < 64; k++)\n if (block[k]) {\n block[k] *= scale;\n if (!v->pquantizer)\n block[k] += (block[k] < 0) ? -v->pq : v->pq;\n }\n if (s->ac_pred) i = 63;\n }\nnot_coded:\n if (!coded) {\n int k, scale;\n ac_val = s->ac_val[0][0] + s->block_index[n] * 16;\n ac_val2 = ac_val;\n i = 0;\n scale = v->pq * 2 + v->halfpq;\n memset(ac_val2, 0, 16 * 2);\n if (dc_pred_dir) {\n ac_val -= 16;\n if (s->ac_pred)\n memcpy(ac_val2, ac_val, 8 * 2);\n } else {\n ac_val -= 16 * s->block_wrap[n];\n if (s->ac_pred)\n memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);\n }\n if (s->ac_pred) {\n if (dc_pred_dir) {\n for (k = 1; k < 8; k++) {\n block[k << v->left_blk_sh] = ac_val[k] * scale;\n if (!v->pquantizer && block[k << v->left_blk_sh])\n block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -v->pq : v->pq;\n }\n } else {\n for (k = 1; k < 8; k++) {\n block[k << v->top_blk_sh] = ac_val[k + 8] * scale;\n if (!v->pquantizer && block[k << v->top_blk_sh])\n block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -v->pq : v->pq;\n }\n }\n i = 63;\n }\n }\n s->block_last_index[n] = i;\n return 0;\n}']
36,517
0
https://gitlab.com/libtiff/libtiff/blob/01bac25a5a9fa0bc41b90a83eca3026e351d818d/tools/tiffdump.c/#L765
static void PrintData(FILE* fd, uint16 type, uint32 count, unsigned char* data) { char* sep = ""; switch (type) { case TIFF_BYTE: while (count-- > 0) fprintf(fd, bytefmt, sep, *data++), sep = " "; break; case TIFF_SBYTE: while (count-- > 0) fprintf(fd, sbytefmt, sep, *(char *)data++), sep = " "; break; case TIFF_UNDEFINED: while (count-- > 0) fprintf(fd, bytefmt, sep, *data++), sep = " "; break; case TIFF_ASCII: PrintASCII(fd, count, data); break; case TIFF_SHORT: { uint16 *wp = (uint16*)data; while (count-- > 0) fprintf(fd, shortfmt, sep, *wp++), sep = " "; break; } case TIFF_SSHORT: { int16 *wp = (int16*)data; while (count-- > 0) fprintf(fd, sshortfmt, sep, *wp++), sep = " "; break; } case TIFF_LONG: { uint32 *lp = (uint32*)data; while (count-- > 0) { fprintf(fd, longfmt, sep, (unsigned long) *lp++); sep = " "; } break; } case TIFF_SLONG: { int32 *lp = (int32*)data; while (count-- > 0) fprintf(fd, slongfmt, sep, (long) *lp++), sep = " "; break; } case TIFF_LONG8: { uint64 *llp = (uint64*)data; while (count-- > 0) { uint64 val; memcpy(&val, llp, sizeof(uint64)); llp ++; fprintf(fd, long8fmt, sep, val); sep = " "; } break; } case TIFF_SLONG8: { int64 *llp = (int64*)data; while (count-- > 0) { int64 val; memcpy(&val, llp, sizeof(int64)); llp ++; fprintf(fd, slong8fmt, sep, val); sep = " "; } break; } case TIFF_RATIONAL: { uint32 *lp = (uint32*)data; while (count-- > 0) { if (lp[1] == 0) fprintf(fd, "%sNan (%lu/%lu)", sep, (unsigned long) lp[0], (unsigned long) lp[1]); else fprintf(fd, rationalfmt, sep, (double)lp[0] / (double)lp[1]); sep = " "; lp += 2; } break; } case TIFF_SRATIONAL: { int32 *lp = (int32*)data; while (count-- > 0) { if (lp[1] == 0) fprintf(fd, "%sNan (%ld/%ld)", sep, (long) lp[0], (long) lp[1]); else fprintf(fd, srationalfmt, sep, (double)lp[0] / (double)lp[1]); sep = " "; lp += 2; } break; } case TIFF_FLOAT: { float *fp = (float *)data; while (count-- > 0) fprintf(fd, floatfmt, sep, *fp++), sep = " "; break; } case TIFF_DOUBLE: { double *dp = (double *)data; while (count-- > 0) fprintf(fd, doublefmt, sep, *dp++), sep = " "; break; } case TIFF_IFD: { uint32 *lp = (uint32*)data; while (count-- > 0) { fprintf(fd, ifdfmt, sep, (unsigned long) *lp++); sep = " "; } break; } case TIFF_IFD8: { uint64 *llp = (uint64*)data; while (count-- > 0) { #if defined(__WIN32__) && defined(_MSC_VER) fprintf(fd, ifd8fmt, sep, (unsigned __int64) *llp++); #else fprintf(fd, ifd8fmt, sep, (unsigned long long) *llp++); #endif sep = " "; } break; } } }
['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\tif (_TIFF_lseek_f(fd, (_TIFF_off_t)off, SEEK_SET) != (_TIFF_off_t)off) {\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(TIFFSafeMultiply(tmsize_t,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 int datasizeoverflow;\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\tmemcpy(&count, dp, sizeof(uint64));\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 datasizeoverflow = (typewidth > 0 && datasize / typewidth != count);\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 (datasizeoverflow || 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 (datasizeoverflow || 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 (datasizeoverflow || 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\t\t\t\tif (_TIFF_lseek_f(fd, (_TIFF_off_t)dataoffset, 0) !=\n\t\t\t\t (_TIFF_off_t)dataoffset)\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\telse if (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 {\n _TIFFfree(datamem);\n datamem = NULL;\n }\n\t\t}\n\t\tprintf(">\\n");\n\t}\ndone:\n\tif (dirmem)\n\t\t_TIFFfree((char *)dirmem);\n\treturn (nextdiroff);\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 uint64 val;\n memcpy(&val, llp, sizeof(uint64));\n llp ++;\n\t\t\tfprintf(fd, long8fmt, sep, val);\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 int64 val;\n memcpy(&val, llp, sizeof(int64));\n llp ++;\n fprintf(fd, slong8fmt, sep, val);\n sep = " ";\n }\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}']
36,518
1
https://github.com/nginx/nginx/blob/7e52432a0518ab5abe35478aacdac4ddda05c5e5/src/http/ngx_http_core_module.c/#L1802
void ngx_http_set_exten(ngx_http_request_t *r) { ngx_int_t i; ngx_str_null(&r->exten); for (i = r->uri.len - 1; i > 1; i--) { if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') { r->exten.len = r->uri.len - i - 1; r->exten.data = &r->uri.data[i + 1]; return; } else if (r->uri.data[i] == '/') { return; } } return; }
['ngx_int_t\nngx_http_process_request_uri(ngx_http_request_t *r)\n{\n ngx_http_core_srv_conf_t *cscf;\n if (r->args_start) {\n r->uri.len = r->args_start - 1 - r->uri_start;\n } else {\n r->uri.len = r->uri_end - r->uri_start;\n }\n if (r->complex_uri || r->quoted_uri) {\n r->uri.data = ngx_pnalloc(r->pool, r->uri.len + 1);\n if (r->uri.data == NULL) {\n ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_ERROR;\n }\n cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n if (ngx_http_parse_complex_uri(r, cscf->merge_slashes) != NGX_OK) {\n ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,\n "client sent invalid request");\n ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);\n return NGX_ERROR;\n }\n } else {\n r->uri.data = r->uri_start;\n }\n r->unparsed_uri.len = r->uri_end - r->uri_start;\n r->unparsed_uri.data = r->uri_start;\n r->valid_unparsed_uri = r->space_in_uri ? 0 : 1;\n if (r->uri_ext) {\n if (r->args_start) {\n r->exten.len = r->args_start - 1 - r->uri_ext;\n } else {\n r->exten.len = r->uri_end - r->uri_ext;\n }\n r->exten.data = r->uri_ext;\n }\n if (r->args_start && r->uri_end > r->args_start) {\n r->args.len = r->uri_end - r->args_start;\n r->args.data = r->args_start;\n }\n#if (NGX_WIN32)\n {\n u_char *p, *last;\n p = r->uri.data;\n last = r->uri.data + r->uri.len;\n while (p < last) {\n if (*p++ == \':\') {\n if (p < last && *p == \'$\') {\n ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,\n "client sent unsafe win32 URI");\n ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);\n return NGX_ERROR;\n }\n }\n }\n p = r->uri.data + r->uri.len - 1;\n while (p > r->uri.data) {\n if (*p == \' \') {\n p--;\n continue;\n }\n if (*p == \'.\') {\n p--;\n continue;\n }\n break;\n }\n if (p != r->uri.data + r->uri.len - 1) {\n r->uri.len = p + 1 - r->uri.data;\n ngx_http_set_exten(r);\n }\n }\n#endif\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http uri: \\"%V\\"", &r->uri);\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http args: \\"%V\\"", &r->args);\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http exten: \\"%V\\"", &r->exten);\n return NGX_OK;\n}', 'void\nngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)\n{\n ngx_connection_t *c;\n ngx_http_request_t *pr;\n ngx_http_core_loc_conf_t *clcf;\n c = r->connection;\n ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize request: %d, \\"%V?%V\\" a:%d, c:%d",\n rc, &r->uri, &r->args, r == c->data, r->main->count);\n if (rc == NGX_DONE) {\n ngx_http_finalize_connection(r);\n return;\n }\n if (rc == NGX_OK && r->filter_finalize) {\n c->error = 1;\n }\n if (rc == NGX_DECLINED) {\n r->content_handler = NULL;\n r->write_event_handler = ngx_http_core_run_phases;\n ngx_http_core_run_phases(r);\n return;\n }\n if (r != r->main && r->post_subrequest) {\n rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);\n }\n if (rc == NGX_ERROR\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n || c->error)\n {\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (r->main->blocked) {\n r->write_event_handler = ngx_http_request_finalizer;\n }\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE\n || rc == NGX_HTTP_CREATED\n || rc == NGX_HTTP_NO_CONTENT)\n {\n if (rc == NGX_HTTP_CLOSE) {\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (r == r->main) {\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n ngx_del_timer(c->write);\n }\n }\n c->read->handler = ngx_http_request_handler;\n c->write->handler = ngx_http_request_handler;\n ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));\n return;\n }\n if (r != r->main) {\n if (r->buffered || r->postponed) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n pr = r->parent;\n if (r == c->data) {\n r->main->count--;\n r->main->subrequests++;\n if (!r->logged) {\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->log_subrequest) {\n ngx_http_log_request(r);\n }\n r->logged = 1;\n } else {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "subrequest: \\"%V?%V\\" logged again",\n &r->uri, &r->args);\n }\n r->done = 1;\n if (pr->postponed && pr->postponed->request == r) {\n pr->postponed = pr->postponed->next;\n }\n c->data = pr;\n } else {\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n r->write_event_handler = ngx_http_request_finalizer;\n if (r->waited) {\n r->done = 1;\n }\n }\n if (ngx_http_post_request(pr, NULL) != NGX_OK) {\n r->main->count++;\n ngx_http_terminate_request(r, 0);\n return;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http wake parent request: \\"%V?%V\\"",\n &pr->uri, &pr->args);\n return;\n }\n if (r->buffered || c->buffered || r->postponed || r->blocked) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n if (r != c->data) {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n return;\n }\n r->done = 1;\n r->write_event_handler = ngx_http_request_empty_handler;\n if (!r->post_action) {\n r->request_complete = 1;\n }\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n c->write->delayed = 0;\n ngx_del_timer(c->write);\n }\n if (c->read->eof) {\n ngx_http_close_request(r, 0);\n return;\n }\n ngx_http_finalize_connection(r);\n}', 'ngx_int_t\nngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)\n{\n ngx_uint_t i, err;\n ngx_http_err_page_t *err_page;\n ngx_http_core_loc_conf_t *clcf;\n ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http special response: %i, \\"%V?%V\\"",\n error, &r->uri, &r->args);\n r->err_status = error;\n if (r->keepalive) {\n switch (error) {\n case NGX_HTTP_BAD_REQUEST:\n case NGX_HTTP_REQUEST_ENTITY_TOO_LARGE:\n case NGX_HTTP_REQUEST_URI_TOO_LARGE:\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n case NGX_HTTP_INTERNAL_SERVER_ERROR:\n case NGX_HTTP_NOT_IMPLEMENTED:\n r->keepalive = 0;\n }\n }\n if (r->lingering_close) {\n switch (error) {\n case NGX_HTTP_BAD_REQUEST:\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n r->lingering_close = 0;\n }\n }\n r->headers_out.content_type.len = 0;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (!r->error_page && clcf->error_pages && r->uri_changes != 0) {\n if (clcf->recursive_error_pages == 0) {\n r->error_page = 1;\n }\n err_page = clcf->error_pages->elts;\n for (i = 0; i < clcf->error_pages->nelts; i++) {\n if (err_page[i].status == error) {\n return ngx_http_send_error_page(r, &err_page[i]);\n }\n }\n }\n r->expect_tested = 1;\n if (ngx_http_discard_request_body(r) != NGX_OK) {\n r->keepalive = 0;\n }\n if (clcf->msie_refresh\n && r->headers_in.msie\n && (error == NGX_HTTP_MOVED_PERMANENTLY\n || error == NGX_HTTP_MOVED_TEMPORARILY))\n {\n return ngx_http_send_refresh(r);\n }\n if (error == NGX_HTTP_CREATED) {\n err = 0;\n } else if (error == NGX_HTTP_NO_CONTENT) {\n err = 0;\n } else if (error >= NGX_HTTP_MOVED_PERMANENTLY\n && error < NGX_HTTP_LAST_3XX)\n {\n err = error - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_OFF_3XX;\n } else if (error >= NGX_HTTP_BAD_REQUEST\n && error < NGX_HTTP_LAST_4XX)\n {\n err = error - NGX_HTTP_BAD_REQUEST + NGX_HTTP_OFF_4XX;\n } else if (error >= NGX_HTTP_NGINX_CODES\n && error < NGX_HTTP_LAST_5XX)\n {\n err = error - NGX_HTTP_NGINX_CODES + NGX_HTTP_OFF_5XX;\n switch (error) {\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n case NGX_HTTP_REQUEST_HEADER_TOO_LARGE:\n r->err_status = NGX_HTTP_BAD_REQUEST;\n break;\n }\n } else {\n err = 0;\n }\n return ngx_http_send_special_response(r, clcf, err);\n}', 'static ngx_int_t\nngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)\n{\n ngx_int_t overwrite;\n ngx_str_t uri, args;\n ngx_table_elt_t *location;\n ngx_http_core_loc_conf_t *clcf;\n overwrite = err_page->overwrite;\n if (overwrite && overwrite != NGX_HTTP_OK) {\n r->expect_tested = 1;\n }\n if (overwrite >= 0) {\n r->err_status = overwrite;\n }\n if (ngx_http_complex_value(r, &err_page->value, &uri) != NGX_OK) {\n return NGX_ERROR;\n }\n if (uri.data[0] == \'/\') {\n if (err_page->value.lengths) {\n ngx_http_split_args(r, &uri, &args);\n } else {\n args = err_page->args;\n }\n if (r->method != NGX_HTTP_HEAD) {\n r->method = NGX_HTTP_GET;\n r->method_name = ngx_http_get_name;\n }\n return ngx_http_internal_redirect(r, &uri, &args);\n }\n if (uri.data[0] == \'@\') {\n return ngx_http_named_location(r, &uri);\n }\n location = ngx_list_push(&r->headers_out.headers);\n if (location == NULL) {\n return NGX_ERROR;\n }\n if (overwrite != NGX_HTTP_MOVED_PERMANENTLY\n && overwrite != NGX_HTTP_MOVED_TEMPORARILY\n && overwrite != NGX_HTTP_SEE_OTHER\n && overwrite != NGX_HTTP_TEMPORARY_REDIRECT)\n {\n r->err_status = NGX_HTTP_MOVED_TEMPORARILY;\n }\n location->hash = 1;\n ngx_str_set(&location->key, "Location");\n location->value = uri;\n ngx_http_clear_location(r);\n r->headers_out.location = location;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->msie_refresh && r->headers_in.msie) {\n return ngx_http_send_refresh(r);\n }\n return ngx_http_send_special_response(r, clcf, r->err_status\n - NGX_HTTP_MOVED_PERMANENTLY\n + NGX_HTTP_OFF_3XX);\n}', 'ngx_int_t\nngx_http_internal_redirect(ngx_http_request_t *r,\n ngx_str_t *uri, ngx_str_t *args)\n{\n ngx_http_core_srv_conf_t *cscf;\n r->uri_changes--;\n if (r->uri_changes == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "rewrite or internal redirection cycle "\n "while internally redirecting to \\"%V\\"", uri);\n r->main->count++;\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n r->uri = *uri;\n if (args) {\n r->args = *args;\n } else {\n ngx_str_null(&r->args);\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "internal redirect: \\"%V?%V\\"", uri, &r->args);\n ngx_http_set_exten(r);\n ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);\n cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n r->loc_conf = cscf->ctx->loc_conf;\n ngx_http_update_location_config(r);\n#if (NGX_HTTP_CACHE)\n r->cache = NULL;\n#endif\n r->internal = 1;\n r->valid_unparsed_uri = 0;\n r->add_uri_to_alias = 0;\n r->main->count++;\n ngx_http_handler(r);\n return NGX_DONE;\n}', "void\nngx_http_set_exten(ngx_http_request_t *r)\n{\n ngx_int_t i;\n ngx_str_null(&r->exten);\n for (i = r->uri.len - 1; i > 1; i--) {\n if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {\n r->exten.len = r->uri.len - i - 1;\n r->exten.data = &r->uri.data[i + 1];\n return;\n } else if (r->uri.data[i] == '/') {\n return;\n }\n }\n return;\n}"]
36,519
0
https://github.com/apache/httpd/blob/b659ff3a97ee5aff34cef0c5cfefab1ce9149eea/modules/proxy/mod_proxy_uwsgi.c/#L119
static int uwsgi_send(proxy_conn_rec * conn, const char *buf, apr_size_t length, request_rec *r) { apr_status_t rv; apr_size_t written; while (length > 0) { written = length; if ((rv = apr_socket_send(conn->sock, buf, &written)) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(10098) "sending data to %s:%u failed", conn->hostname, conn->port); return HTTP_SERVICE_UNAVAILABLE; } conn->worker->s->transferred += written; buf += written; length -= written; } return OK; }
['static int uwsgi_send_body(request_rec *r, proxy_conn_rec * conn)\n{\n if (ap_should_client_block(r)) {\n char *buf = apr_palloc(r->pool, AP_IOBUFSIZE);\n int status;\n long readlen;\n readlen = ap_get_client_block(r, buf, AP_IOBUFSIZE);\n while (readlen > 0) {\n status = uwsgi_send(conn, buf, (apr_size_t)readlen, r);\n if (status != OK) {\n return HTTP_SERVICE_UNAVAILABLE;\n }\n readlen = ap_get_client_block(r, buf, AP_IOBUFSIZE);\n }\n if (readlen == -1) {\n ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10099)\n "receiving request body failed");\n return HTTP_INTERNAL_SERVER_ERROR;\n }\n }\n return OK;\n}', 'AP_DECLARE(long) ap_get_client_block(request_rec *r, char *buffer,\n apr_size_t bufsiz)\n{\n apr_status_t rv;\n apr_bucket_brigade *bb;\n if (r->remaining < 0 || (!r->read_chunked && r->remaining == 0)) {\n return 0;\n }\n bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);\n if (bb == NULL) {\n r->connection->keepalive = AP_CONN_CLOSE;\n return -1;\n }\n rv = ap_get_brigade(r->input_filters, bb, AP_MODE_READBYTES,\n APR_BLOCK_READ, bufsiz);\n if (rv == AP_FILTER_ERROR) {\n apr_brigade_destroy(bb);\n return -1;\n }\n if (rv != APR_SUCCESS) {\n apr_bucket *e;\n apr_brigade_cleanup(bb);\n e = ap_bucket_error_create(\n ap_map_http_request_error(rv, HTTP_BAD_REQUEST), NULL, r->pool,\n r->connection->bucket_alloc);\n APR_BRIGADE_INSERT_TAIL(bb, e);\n e = apr_bucket_eos_create(r->connection->bucket_alloc);\n APR_BRIGADE_INSERT_TAIL(bb, e);\n rv = ap_pass_brigade(r->output_filters, bb);\n if (APR_SUCCESS != rv) {\n ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, APLOGNO(02484)\n "Error while writing error response");\n }\n r->connection->keepalive = AP_CONN_CLOSE;\n apr_brigade_destroy(bb);\n return -1;\n }\n AP_DEBUG_ASSERT(!APR_BRIGADE_EMPTY(bb));\n if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(bb))) {\n if (r->read_chunked) {\n r->remaining = -1;\n }\n else {\n r->remaining = 0;\n }\n }\n rv = apr_brigade_flatten(bb, buffer, &bufsiz);\n if (rv != APR_SUCCESS) {\n apr_brigade_destroy(bb);\n return -1;\n }\n r->read_length += bufsiz;\n apr_brigade_destroy(bb);\n return bufsiz;\n}', 'static int uwsgi_send(proxy_conn_rec * conn, const char *buf,\n apr_size_t length, request_rec *r)\n{\n apr_status_t rv;\n apr_size_t written;\n while (length > 0) {\n written = length;\n if ((rv = apr_socket_send(conn->sock, buf, &written)) != APR_SUCCESS) {\n ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(10098)\n "sending data to %s:%u failed",\n conn->hostname, conn->port);\n return HTTP_SERVICE_UNAVAILABLE;\n }\n conn->worker->s->transferred += written;\n buf += written;\n length -= written;\n }\n return OK;\n}']
36,520
0
https://github.com/openssl/openssl/blob/6bf24568bc1e263348efd0394b30cc7492992127/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, &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_CONSTTIME))\n\t\t\t{\n\t\t\td = &local_d;\n\t\t\tBN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n\t\t\t}\n\t\telse\n\t\t\td = rsa->d;\n\t\tif (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n\t\t\tif (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))\n\t\t\t\tgoto 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\tint got_write_lock = 0;\n\tBN_MONT_CTX *ret;\n\tCRYPTO_r_lock(lock);\n\tif (!*pmont)\n\t\t{\n\t\tCRYPTO_r_unlock(lock);\n\t\tCRYPTO_w_lock(lock);\n\t\tgot_write_lock = 1;\n\t\tif (!*pmont)\n\t\t\t{\n\t\t\tret = BN_MONT_CTX_new();\n\t\t\tif (ret && !BN_MONT_CTX_set(ret, mod, ctx))\n\t\t\t\tBN_MONT_CTX_free(ret);\n\t\t\telse\n\t\t\t\t*pmont = ret;\n\t\t\t}\n\t\t}\n\tret = *pmont;\n\tif (got_write_lock)\n\t\tCRYPTO_w_unlock(lock);\n\telse\n\t\tCRYPTO_r_unlock(lock);\n\treturn ret;\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\tBN_init(&tmod);\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\tif ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_mod_inverse_no_branch(in, a, n, ctx);\n\t\t}\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}', 'static BIGNUM *BN_mod_inverse_no_branch(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 local_A, local_B;\n\tBIGNUM *pA, *pB;\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\tpB = &local_B;\n\t\tBN_with_flags(pB, B, BN_FLG_CONSTTIME);\n\t\tif (!BN_nnmod(B, pB, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\twhile (!BN_is_zero(B))\n\t\t{\n\t\tBIGNUM *tmp;\n\t\tpA = &local_A;\n\t\tBN_with_flags(pA, A, BN_FLG_CONSTTIME);\n\t\tif (!BN_div(D,M,pA,B,ctx)) goto err;\n\t\ttmp=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\tM=Y;\n\t\tY=X;\n\t\tX=tmp;\n\t\tsign = -sign;\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_NO_BRANCH,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\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\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(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;\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\t{\n\t\t\tBN_ULONG ql, qh;\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\t}\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}', 'static 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(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV_NO_BRANCH,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;\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\t{\n\t\t\tBN_ULONG ql, qh;\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\t}\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_correct_top(res);\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}']
36,521
0
https://github.com/nginx/nginx/blob/e4ecddfdb0d2ffc872658e36028971ad9a873726/src/core/ngx_string.c/#L244
u_char * ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args) { u_char *p, zero, *last; int d; float f, scale; size_t len, slen; int64_t i64; uint64_t ui64; ngx_msec_t ms; ngx_uint_t width, sign, hex, max_width, frac_width, i; ngx_str_t *v; ngx_variable_value_t *vv; if (max == 0) { return buf; } last = buf + max; while (*fmt && buf < last) { if (*fmt == '%') { i64 = 0; ui64 = 0; zero = (u_char) ((*++fmt == '0') ? '0' : ' '); width = 0; sign = 1; hex = 0; max_width = 0; frac_width = 0; slen = (size_t) -1; while (*fmt >= '0' && *fmt <= '9') { width = width * 10 + *fmt++ - '0'; } for ( ;; ) { switch (*fmt) { case 'u': sign = 0; fmt++; continue; case 'm': max_width = 1; fmt++; continue; case 'X': hex = 2; sign = 0; fmt++; continue; case 'x': hex = 1; sign = 0; fmt++; continue; case '.': fmt++; while (*fmt >= '0' && *fmt <= '9') { frac_width = frac_width * 10 + *fmt++ - '0'; } break; case '*': slen = va_arg(args, size_t); fmt++; continue; default: break; } break; } switch (*fmt) { case 'V': v = va_arg(args, ngx_str_t *); len = v->len; len = (buf + len < last) ? len : (size_t) (last - buf); buf = ngx_cpymem(buf, v->data, len); fmt++; continue; case 'v': vv = va_arg(args, ngx_variable_value_t *); len = vv->len; len = (buf + len < last) ? len : (size_t) (last - buf); buf = ngx_cpymem(buf, vv->data, len); fmt++; continue; case 's': p = va_arg(args, u_char *); if (slen == (size_t) -1) { while (*p && buf < last) { *buf++ = *p++; } } else { len = (buf + slen < last) ? slen : (size_t) (last - buf); buf = ngx_cpymem(buf, p, len); } fmt++; continue; case 'O': i64 = (int64_t) va_arg(args, off_t); sign = 1; break; case 'P': i64 = (int64_t) va_arg(args, ngx_pid_t); sign = 1; break; case 'T': i64 = (int64_t) va_arg(args, time_t); sign = 1; break; case 'M': ms = (ngx_msec_t) va_arg(args, ngx_msec_t); if ((ngx_msec_int_t) ms == -1) { sign = 1; i64 = -1; } else { sign = 0; ui64 = (uint64_t) ms; } break; case 'z': if (sign) { i64 = (int64_t) va_arg(args, ssize_t); } else { ui64 = (uint64_t) va_arg(args, size_t); } break; case 'i': if (sign) { i64 = (int64_t) va_arg(args, ngx_int_t); } else { ui64 = (uint64_t) va_arg(args, ngx_uint_t); } if (max_width) { width = NGX_INT_T_LEN; } break; case 'd': if (sign) { i64 = (int64_t) va_arg(args, int); } else { ui64 = (uint64_t) va_arg(args, u_int); } break; case 'l': if (sign) { i64 = (int64_t) va_arg(args, long); } else { ui64 = (uint64_t) va_arg(args, u_long); } break; case 'D': if (sign) { i64 = (int64_t) va_arg(args, int32_t); } else { ui64 = (uint64_t) va_arg(args, uint32_t); } break; case 'L': if (sign) { i64 = va_arg(args, int64_t); } else { ui64 = va_arg(args, uint64_t); } break; case 'A': if (sign) { i64 = (int64_t) va_arg(args, ngx_atomic_int_t); } else { ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t); } if (max_width) { width = NGX_ATOMIC_T_LEN; } break; case 'f': f = (float) va_arg(args, double); if (f < 0) { *buf++ = '-'; f = -f; } ui64 = (int64_t) f; buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width); if (frac_width) { if (buf < last) { *buf++ = '.'; } scale = 1.0; for (i = 0; i < frac_width; i++) { scale *= 10.0; } ui64 = (uint64_t) ((f - (int64_t) ui64) * scale); buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width); } fmt++; continue; #if !(NGX_WIN32) case 'r': i64 = (int64_t) va_arg(args, rlim_t); sign = 1; break; #endif case 'p': ui64 = (uintptr_t) va_arg(args, void *); hex = 2; sign = 0; zero = '0'; width = NGX_PTR_SIZE * 2; break; case 'c': d = va_arg(args, int); *buf++ = (u_char) (d & 0xff); fmt++; continue; case 'Z': *buf++ = '\0'; fmt++; continue; case 'N': #if (NGX_WIN32) *buf++ = CR; #endif *buf++ = LF; fmt++; continue; case '%': *buf++ = '%'; fmt++; continue; default: *buf++ = *fmt++; continue; } if (sign) { if (i64 < 0) { *buf++ = '-'; ui64 = (uint64_t) -i64; } else { ui64 = (uint64_t) i64; } } buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width); fmt++; } else { *buf++ = *fmt++; } } return buf; }
['static ngx_int_t\nngx_http_range_test_overlapped(ngx_http_request_t *r,\n ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in)\n{\n off_t start, last;\n ngx_buf_t *buf;\n ngx_uint_t i;\n ngx_http_range_t *range;\n if (ctx->offset) {\n goto overlapped;\n }\n buf = in->buf;\n if (!buf->last_buf) {\n if (buf->in_file) {\n start = buf->file_pos + ctx->offset;\n last = buf->file_last + ctx->offset;\n } else {\n start = buf->pos - buf->start + ctx->offset;\n last = buf->last - buf->start + ctx->offset;\n }\n range = ctx->ranges.elts;\n for (i = 0; i < ctx->ranges.nelts; i++) {\n if (start > range[i].start || last < range[i].end) {\n goto overlapped;\n }\n }\n }\n ctx->offset = ngx_buf_size(buf);\n return NGX_OK;\noverlapped:\n ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,\n "range in overlapped buffers");\n return NGX_ERROR;\n}', 'void\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, ...)\n#else\nvoid\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, va_list args)\n#endif\n{\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_list args;\n#endif\n u_char errstr[NGX_MAX_ERROR_STR], *p, *last;\n if (log->file->fd == NGX_INVALID_FILE) {\n return;\n }\n last = errstr + NGX_MAX_ERROR_STR;\n ngx_memcpy(errstr, ngx_cached_err_log_time.data,\n ngx_cached_err_log_time.len);\n p = errstr + ngx_cached_err_log_time.len;\n p = ngx_snprintf(p, last - p, " [%s] ", err_levels[level]);\n p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ",\n ngx_log_pid, ngx_log_tid);\n if (log->connection) {\n p = ngx_snprintf(p, last - p, "*%uA ", log->connection);\n }\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_start(args, fmt);\n p = ngx_vsnprintf(p, last - p, fmt, args);\n va_end(args);\n#else\n p = ngx_vsnprintf(p, last - p, fmt, args);\n#endif\n if (err) {\n if (p > last - 50) {\n p = last - 50;\n *p++ = \'.\';\n *p++ = \'.\';\n *p++ = \'.\';\n }\n#if (NGX_WIN32)\n p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)\n ? " (%d: " : " (%Xd: ", err);\n#else\n p = ngx_snprintf(p, last - p, " (%d: ", err);\n#endif\n p = ngx_strerror_r(err, p, last - p);\n if (p < last) {\n *p++ = \')\';\n }\n }\n if (level != NGX_LOG_DEBUG && log->handler) {\n p = log->handler(log, p, last - p);\n }\n if (p > last - NGX_LINEFEED_SIZE) {\n p = last - NGX_LINEFEED_SIZE;\n }\n ngx_linefeed(p);\n (void) ngx_write_fd(log->file->fd, errstr, p - errstr);\n}', 'u_char * ngx_cdecl\nngx_snprintf(u_char *buf, size_t max, const char *fmt, ...)\n{\n u_char *p;\n va_list args;\n va_start(args, fmt);\n p = ngx_vsnprintf(buf, max, fmt, args);\n va_end(args);\n return p;\n}', "u_char *\nngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)\n{\n u_char *p, zero, *last;\n int d;\n float f, scale;\n size_t len, slen;\n int64_t i64;\n uint64_t ui64;\n ngx_msec_t ms;\n ngx_uint_t width, sign, hex, max_width, frac_width, i;\n ngx_str_t *v;\n ngx_variable_value_t *vv;\n if (max == 0) {\n return buf;\n }\n last = buf + max;\n while (*fmt && buf < last) {\n if (*fmt == '%') {\n i64 = 0;\n ui64 = 0;\n zero = (u_char) ((*++fmt == '0') ? '0' : ' ');\n width = 0;\n sign = 1;\n hex = 0;\n max_width = 0;\n frac_width = 0;\n slen = (size_t) -1;\n while (*fmt >= '0' && *fmt <= '9') {\n width = width * 10 + *fmt++ - '0';\n }\n for ( ;; ) {\n switch (*fmt) {\n case 'u':\n sign = 0;\n fmt++;\n continue;\n case 'm':\n max_width = 1;\n fmt++;\n continue;\n case 'X':\n hex = 2;\n sign = 0;\n fmt++;\n continue;\n case 'x':\n hex = 1;\n sign = 0;\n fmt++;\n continue;\n case '.':\n fmt++;\n while (*fmt >= '0' && *fmt <= '9') {\n frac_width = frac_width * 10 + *fmt++ - '0';\n }\n break;\n case '*':\n slen = va_arg(args, size_t);\n fmt++;\n continue;\n default:\n break;\n }\n break;\n }\n switch (*fmt) {\n case 'V':\n v = va_arg(args, ngx_str_t *);\n len = v->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, v->data, len);\n fmt++;\n continue;\n case 'v':\n vv = va_arg(args, ngx_variable_value_t *);\n len = vv->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, vv->data, len);\n fmt++;\n continue;\n case 's':\n p = va_arg(args, u_char *);\n if (slen == (size_t) -1) {\n while (*p && buf < last) {\n *buf++ = *p++;\n }\n } else {\n len = (buf + slen < last) ? slen : (size_t) (last - buf);\n buf = ngx_cpymem(buf, p, len);\n }\n fmt++;\n continue;\n case 'O':\n i64 = (int64_t) va_arg(args, off_t);\n sign = 1;\n break;\n case 'P':\n i64 = (int64_t) va_arg(args, ngx_pid_t);\n sign = 1;\n break;\n case 'T':\n i64 = (int64_t) va_arg(args, time_t);\n sign = 1;\n break;\n case 'M':\n ms = (ngx_msec_t) va_arg(args, ngx_msec_t);\n if ((ngx_msec_int_t) ms == -1) {\n sign = 1;\n i64 = -1;\n } else {\n sign = 0;\n ui64 = (uint64_t) ms;\n }\n break;\n case 'z':\n if (sign) {\n i64 = (int64_t) va_arg(args, ssize_t);\n } else {\n ui64 = (uint64_t) va_arg(args, size_t);\n }\n break;\n case 'i':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_uint_t);\n }\n if (max_width) {\n width = NGX_INT_T_LEN;\n }\n break;\n case 'd':\n if (sign) {\n i64 = (int64_t) va_arg(args, int);\n } else {\n ui64 = (uint64_t) va_arg(args, u_int);\n }\n break;\n case 'l':\n if (sign) {\n i64 = (int64_t) va_arg(args, long);\n } else {\n ui64 = (uint64_t) va_arg(args, u_long);\n }\n break;\n case 'D':\n if (sign) {\n i64 = (int64_t) va_arg(args, int32_t);\n } else {\n ui64 = (uint64_t) va_arg(args, uint32_t);\n }\n break;\n case 'L':\n if (sign) {\n i64 = va_arg(args, int64_t);\n } else {\n ui64 = va_arg(args, uint64_t);\n }\n break;\n case 'A':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_atomic_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);\n }\n if (max_width) {\n width = NGX_ATOMIC_T_LEN;\n }\n break;\n case 'f':\n f = (float) va_arg(args, double);\n if (f < 0) {\n *buf++ = '-';\n f = -f;\n }\n ui64 = (int64_t) f;\n buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);\n if (frac_width) {\n if (buf < last) {\n *buf++ = '.';\n }\n scale = 1.0;\n for (i = 0; i < frac_width; i++) {\n scale *= 10.0;\n }\n ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);\n buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);\n }\n fmt++;\n continue;\n#if !(NGX_WIN32)\n case 'r':\n i64 = (int64_t) va_arg(args, rlim_t);\n sign = 1;\n break;\n#endif\n case 'p':\n ui64 = (uintptr_t) va_arg(args, void *);\n hex = 2;\n sign = 0;\n zero = '0';\n width = NGX_PTR_SIZE * 2;\n break;\n case 'c':\n d = va_arg(args, int);\n *buf++ = (u_char) (d & 0xff);\n fmt++;\n continue;\n case 'Z':\n *buf++ = '\\0';\n fmt++;\n continue;\n case 'N':\n#if (NGX_WIN32)\n *buf++ = CR;\n#endif\n *buf++ = LF;\n fmt++;\n continue;\n case '%':\n *buf++ = '%';\n fmt++;\n continue;\n default:\n *buf++ = *fmt++;\n continue;\n }\n if (sign) {\n if (i64 < 0) {\n *buf++ = '-';\n ui64 = (uint64_t) -i64;\n } else {\n ui64 = (uint64_t) i64;\n }\n }\n buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);\n fmt++;\n } else {\n *buf++ = *fmt++;\n }\n }\n return buf;\n}"]
36,522
0
https://github.com/libav/libav/blob/39bec05ed42e505d17877b0c23f16322f9b5883b/libavcodec/h264_mvpred.h/#L566
static void fill_decode_caches(H264Context *h, int mb_type) { int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; int topleft_type, top_type, topright_type, left_type[LEFT_MBS]; const uint8_t *left_block = h->left_block; int i; uint8_t *nnz; uint8_t *nnz_cache; topleft_xy = h->topleft_mb_xy; top_xy = h->top_mb_xy; topright_xy = h->topright_mb_xy; left_xy[LTOP] = h->left_mb_xy[LTOP]; left_xy[LBOT] = h->left_mb_xy[LBOT]; topleft_type = h->topleft_type; top_type = h->top_type; topright_type = h->topright_type; left_type[LTOP] = h->left_type[LTOP]; left_type[LBOT] = h->left_type[LBOT]; if (!IS_SKIP(mb_type)) { if (IS_INTRA(mb_type)) { int type_mask = h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1; h->topleft_samples_available = h->top_samples_available = h->left_samples_available = 0xFFFF; h->topright_samples_available = 0xEEEA; if (!(top_type & type_mask)) { h->topleft_samples_available = 0xB3FF; h->top_samples_available = 0x33FF; h->topright_samples_available = 0x26EA; } if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) { if (IS_INTERLACED(mb_type)) { if (!(left_type[LTOP] & type_mask)) { h->topleft_samples_available &= 0xDFFF; h->left_samples_available &= 0x5FFF; } if (!(left_type[LBOT] & type_mask)) { h->topleft_samples_available &= 0xFF5F; h->left_samples_available &= 0xFF5F; } } else { int left_typei = h->cur_pic.f.mb_type[left_xy[LTOP] + h->mb_stride]; assert(left_xy[LTOP] == left_xy[LBOT]); if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) { h->topleft_samples_available &= 0xDF5F; h->left_samples_available &= 0x5F5F; } } } else { if (!(left_type[LTOP] & type_mask)) { h->topleft_samples_available &= 0xDF5F; h->left_samples_available &= 0x5F5F; } } if (!(topleft_type & type_mask)) h->topleft_samples_available &= 0x7FFF; if (!(topright_type & type_mask)) h->topright_samples_available &= 0xFBFF; if (IS_INTRA4x4(mb_type)) { if (IS_INTRA4x4(top_type)) { AV_COPY32(h->intra4x4_pred_mode_cache + 4 + 8 * 0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]); } else { h->intra4x4_pred_mode_cache[4 + 8 * 0] = h->intra4x4_pred_mode_cache[5 + 8 * 0] = h->intra4x4_pred_mode_cache[6 + 8 * 0] = h->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask); } for (i = 0; i < 2; i++) { if (IS_INTRA4x4(left_type[LEFT(i)])) { int8_t *mode = h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]]; h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]]; h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]]; } else { h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask); } } } } nnz_cache = h->non_zero_count_cache; if (top_type) { nnz = h->non_zero_count[top_xy]; AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]); if (!h->chroma_y_shift) { AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]); AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]); } else { AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]); AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]); } } else { uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040; AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty); AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty); AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty); } for (i = 0; i < 2; i++) { if (left_type[LEFT(i)]) { nnz = h->non_zero_count[left_xy[LEFT(i)]]; nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]]; nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]]; if (CHROMA444) { nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4]; nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4]; nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4]; nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4]; } else if (CHROMA422) { nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4]; nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4]; nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4]; nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4]; } else { nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]]; nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]]; } } else { nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz_cache[3 + 8 * 12 + 2 * 8 * i] = CABAC && !IS_INTRA(mb_type) ? 0 : 64; } } if (CABAC) { if (top_type) h->top_cbp = h->cbp_table[top_xy]; else h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; if (left_type[LTOP]) { h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) | ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) | (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2); } else { h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; } } } if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)) { int list; int b_stride = h->b_stride; for (list = 0; list < h->list_count; list++) { int8_t *ref_cache = &h->ref_cache[list][scan8[0]]; int8_t *ref = h->cur_pic.f.ref_index[list]; int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]]; int16_t(*mv)[2] = h->cur_pic.f.motion_val[list]; if (!USES_LIST(mb_type, list)) continue; assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); if (USES_LIST(top_type, list)) { const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride; AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]); ref_cache[0 - 1 * 8] = ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2]; ref_cache[2 - 1 * 8] = ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3]; } else { AV_ZERO128(mv_cache[0 - 1 * 8]); AV_WN32A(&ref_cache[0 - 1 * 8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u); } if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) { for (i = 0; i < 2; i++) { int cache_idx = -1 + i * 2 * 8; if (USES_LIST(left_type[LEFT(i)], list)) { const int b_xy = h->mb2b_xy[left_xy[LEFT(i)]] + 3; const int b8_xy = 4 * left_xy[LEFT(i)] + 1; AV_COPY32(mv_cache[cache_idx], mv[b_xy + b_stride * left_block[0 + i * 2]]); AV_COPY32(mv_cache[cache_idx + 8], mv[b_xy + b_stride * left_block[1 + i * 2]]); ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)]; ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)]; } else { AV_ZERO32(mv_cache[cache_idx]); AV_ZERO32(mv_cache[cache_idx + 8]); ref_cache[cache_idx] = ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } } else { if (USES_LIST(left_type[LTOP], list)) { const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3; const int b8_xy = 4 * left_xy[LTOP] + 1; AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]); ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)]; } else { AV_ZERO32(mv_cache[-1]); ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if (USES_LIST(topright_type, list)) { const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride; AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]); ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2]; } else { AV_ZERO32(mv_cache[4 - 1 * 8]); ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } if (ref_cache[4 - 1 * 8] < 0) { if (USES_LIST(topleft_type, list)) { const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2 * b_stride); const int b8_xy = 4 * topleft_xy + 1 + (h->topleft_partition & 2); AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]); ref_cache[-1 - 1 * 8] = ref[b8_xy]; } else { AV_ZERO32(mv_cache[-1 - 1 * 8]); ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF) continue; if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) { uint8_t(*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]]; uint8_t(*mvd)[2] = h->mvd_table[list]; ref_cache[2 + 8 * 0] = ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE; AV_ZERO32(mv_cache[2 + 8 * 0]); AV_ZERO32(mv_cache[2 + 8 * 2]); if (CABAC) { if (USES_LIST(top_type, list)) { const int b_xy = h->mb2br_xy[top_xy]; AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]); } else { AV_ZERO64(mvd_cache[0 - 1 * 8]); } if (USES_LIST(left_type[LTOP], list)) { const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6; AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]); AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]); } else { AV_ZERO16(mvd_cache[-1 + 0 * 8]); AV_ZERO16(mvd_cache[-1 + 1 * 8]); } if (USES_LIST(left_type[LBOT], list)) { const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6; AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]); AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]); } else { AV_ZERO16(mvd_cache[-1 + 2 * 8]); AV_ZERO16(mvd_cache[-1 + 3 * 8]); } AV_ZERO16(mvd_cache[2 + 8 * 0]); AV_ZERO16(mvd_cache[2 + 8 * 2]); if (h->slice_type_nos == AV_PICTURE_TYPE_B) { uint8_t *direct_cache = &h->direct_cache[scan8[0]]; uint8_t *direct_table = h->direct_table; fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1); if (IS_DIRECT(top_type)) { AV_WN32A(&direct_cache[-1 * 8], 0x01010101u * (MB_TYPE_DIRECT2 >> 1)); } else if (IS_8X8(top_type)) { int b8_xy = 4 * top_xy; direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2]; direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3]; } else { AV_WN32A(&direct_cache[-1 * 8], 0x01010101 * (MB_TYPE_16x16 >> 1)); } if (IS_DIRECT(left_type[LTOP])) direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1; else if (IS_8X8(left_type[LTOP])) direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)]; else direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1; if (IS_DIRECT(left_type[LBOT])) direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1; else if (IS_8X8(left_type[LBOT])) direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)]; else direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1; } } } #define MAP_MVS \ MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \ MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \ MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \ MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \ MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \ MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT]) if (FRAME_MBAFF) { if (MB_FIELD) { #define MAP_F2F(idx, mb_type) \ if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \ h->ref_cache[list][idx] <<= 1; \ h->mv_cache[list][idx][1] /= 2; \ h->mvd_cache[list][idx][1] >>= 1; \ } MAP_MVS } else { #undef MAP_F2F #define MAP_F2F(idx, mb_type) \ if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \ h->ref_cache[list][idx] >>= 1; \ h->mv_cache[list][idx][1] <<= 1; \ h->mvd_cache[list][idx][1] <<= 1; \ } MAP_MVS #undef MAP_F2F } } } } h->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]); }
['int ff_h264_decode_mb_cavlc(H264Context *h){\n int mb_xy;\n int partition_count;\n unsigned int mb_type, cbp;\n int dct8x8_allowed= h->pps.transform_8x8_mode;\n int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2;\n const int pixel_shift = h->pixel_shift;\n mb_xy = h->mb_xy = h->mb_x + h->mb_y*h->mb_stride;\n tprintf(h->avctx, "pic:%d mb:%d/%d\\n", h->frame_num, h->mb_x, h->mb_y);\n cbp = 0;\n if(h->slice_type_nos != AV_PICTURE_TYPE_I){\n if(h->mb_skip_run==-1)\n h->mb_skip_run= get_ue_golomb(&h->gb);\n if (h->mb_skip_run--) {\n if(FRAME_MBAFF && (h->mb_y&1) == 0){\n if(h->mb_skip_run==0)\n h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&h->gb);\n }\n decode_mb_skip(h);\n return 0;\n }\n }\n if(FRAME_MBAFF){\n if( (h->mb_y&1) == 0 )\n h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&h->gb);\n }\n h->prev_mb_skipped= 0;\n mb_type= get_ue_golomb(&h->gb);\n if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n if(mb_type < 23){\n partition_count= b_mb_type_info[mb_type].partition_count;\n mb_type= b_mb_type_info[mb_type].type;\n }else{\n mb_type -= 23;\n goto decode_intra_mb;\n }\n }else if(h->slice_type_nos == AV_PICTURE_TYPE_P){\n if(mb_type < 5){\n partition_count= p_mb_type_info[mb_type].partition_count;\n mb_type= p_mb_type_info[mb_type].type;\n }else{\n mb_type -= 5;\n goto decode_intra_mb;\n }\n }else{\n assert(h->slice_type_nos == AV_PICTURE_TYPE_I);\n if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type)\n mb_type--;\ndecode_intra_mb:\n if(mb_type > 25){\n av_log(h->avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\\n", mb_type, av_get_picture_type_char(h->slice_type), h->mb_x, h->mb_y);\n return -1;\n }\n partition_count=0;\n cbp= i_mb_type_info[mb_type].cbp;\n h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;\n mb_type= i_mb_type_info[mb_type].type;\n }\n if(MB_FIELD)\n mb_type |= MB_TYPE_INTERLACED;\n h->slice_table[ mb_xy ]= h->slice_num;\n if(IS_INTRA_PCM(mb_type)){\n unsigned int x;\n const int mb_size = ff_h264_mb_sizes[h->sps.chroma_format_idc] *\n h->sps.bit_depth_luma >> 3;\n align_get_bits(&h->gb);\n for(x=0; x < mb_size; x++){\n ((uint8_t*)h->mb)[x]= get_bits(&h->gb, 8);\n }\n h->cur_pic.f.qscale_table[mb_xy] = 0;\n memset(h->non_zero_count[mb_xy], 16, 48);\n h->cur_pic.f.mb_type[mb_xy] = mb_type;\n return 0;\n }\n fill_decode_neighbors(h, mb_type);\n fill_decode_caches(h, mb_type);\n if(IS_INTRA(mb_type)){\n int pred_mode;\n if(IS_INTRA4x4(mb_type)){\n int i;\n int di = 1;\n if(dct8x8_allowed && get_bits1(&h->gb)){\n mb_type |= MB_TYPE_8x8DCT;\n di = 4;\n }\n for(i=0; i<16; i+=di){\n int mode= pred_intra_mode(h, i);\n if(!get_bits1(&h->gb)){\n const int rem_mode= get_bits(&h->gb, 3);\n mode = rem_mode + (rem_mode >= mode);\n }\n if(di==4)\n fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );\n else\n h->intra4x4_pred_mode_cache[ scan8[i] ] = mode;\n }\n write_back_intra_pred_mode(h);\n if( ff_h264_check_intra4x4_pred_mode(h) < 0)\n return -1;\n }else{\n h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode(h, h->intra16x16_pred_mode, 0);\n if(h->intra16x16_pred_mode < 0)\n return -1;\n }\n if(decode_chroma){\n pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&h->gb), 1);\n if(pred_mode < 0)\n return -1;\n h->chroma_pred_mode= pred_mode;\n } else {\n h->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(h->slice_type_nos == AV_PICTURE_TYPE_B){\n for(i=0; i<4; i++){\n h->sub_mb_type[i]= get_ue_golomb_31(&h->gb);\n if(h->sub_mb_type[i] >=13){\n av_log(h->avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\\n", h->sub_mb_type[i], h->mb_x, h->mb_y);\n return -1;\n }\n sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n if( IS_DIRECT(h->sub_mb_type[0]|h->sub_mb_type[1]|h->sub_mb_type[2]|h->sub_mb_type[3])) {\n ff_h264_pred_direct_motion(h, &mb_type);\n h->ref_cache[0][scan8[4]] =\n h->ref_cache[1][scan8[4]] =\n h->ref_cache[0][scan8[12]] =\n h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n }\n }else{\n assert(h->slice_type_nos == AV_PICTURE_TYPE_P);\n for(i=0; i<4; i++){\n h->sub_mb_type[i]= get_ue_golomb_31(&h->gb);\n if(h->sub_mb_type[i] >=4){\n av_log(h->avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\\n", h->sub_mb_type[i], h->mb_x, h->mb_y);\n return -1;\n }\n sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n }\n for(list=0; list<h->list_count; list++){\n int ref_count = IS_REF0(mb_type) ? 1 : h->ref_count[list] << MB_MBAFF;\n for(i=0; i<4; i++){\n if(IS_DIRECT(h->sub_mb_type[i])) continue;\n if(IS_DIR(h->sub_mb_type[i], 0, list)){\n unsigned int tmp;\n if(ref_count == 1){\n tmp= 0;\n }else if(ref_count == 2){\n tmp= get_bits1(&h->gb)^1;\n }else{\n tmp= get_ue_golomb_31(&h->gb);\n if(tmp>=ref_count){\n av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\\n", tmp);\n return -1;\n }\n }\n ref[list][i]= tmp;\n }else{\n ref[list][i] = -1;\n }\n }\n }\n if(dct8x8_allowed)\n dct8x8_allowed = get_dct8x8_allowed(h);\n for(list=0; list<h->list_count; list++){\n for(i=0; i<4; i++){\n if(IS_DIRECT(h->sub_mb_type[i])) {\n h->ref_cache[list][ scan8[4*i] ] = h->ref_cache[list][ scan8[4*i]+1 ];\n continue;\n }\n h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]=\n h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];\n if(IS_DIR(h->sub_mb_type[i], 0, list)){\n const int sub_mb_type= h->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 mx, my;\n const int index= 4*i + block_width*j;\n int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];\n pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);\n mx += get_se_golomb(&h->gb);\n my += get_se_golomb(&h->gb);\n tprintf(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 }else if(IS_SUB_8X4(sub_mb_type)){\n mv_cache[ 1 ][0]= mx;\n mv_cache[ 1 ][1]= my;\n }else if(IS_SUB_4X8(sub_mb_type)){\n mv_cache[ 8 ][0]= mx;\n mv_cache[ 8 ][1]= my;\n }\n mv_cache[ 0 ][0]= mx;\n mv_cache[ 0 ][1]= my;\n }\n }else{\n uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0];\n p[0] = p[1]=\n p[8] = p[9]= 0;\n }\n }\n }\n }else if(IS_DIRECT(mb_type)){\n ff_h264_pred_direct_motion(h, &mb_type);\n dct8x8_allowed &= h->sps.direct_8x8_inference_flag;\n }else{\n int list, mx, my, i;\n if(IS_16X16(mb_type)){\n for(list=0; list<h->list_count; list++){\n unsigned int val;\n if(IS_DIR(mb_type, 0, list)){\n int rc = h->ref_count[list] << MB_MBAFF;\n if (rc == 1) {\n val= 0;\n } else if (rc == 2) {\n val= get_bits1(&h->gb)^1;\n }else{\n val= get_ue_golomb_31(&h->gb);\n if (val >= rc) {\n av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n return -1;\n }\n }\n fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n if(IS_DIR(mb_type, 0, list)){\n pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);\n mx += get_se_golomb(&h->gb);\n my += get_se_golomb(&h->gb);\n tprintf(h->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->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<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n int rc = h->ref_count[list] << MB_MBAFF;\n if (rc == 1) {\n val= 0;\n } else if (rc == 2) {\n val= get_bits1(&h->gb)^1;\n }else{\n val= get_ue_golomb_31(&h->gb);\n if (val >= rc) {\n av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n return -1;\n }\n }\n }else\n val= LIST_NOT_USED&0xFF;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n mx += get_se_golomb(&h->gb);\n my += get_se_golomb(&h->gb);\n tprintf(h->avctx, "final mv:%d %d\\n", mx, my);\n val= pack16to32(mx,my);\n }else\n val=0;\n fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4);\n }\n }\n }else{\n assert(IS_8X16(mb_type));\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n int rc = h->ref_count[list] << MB_MBAFF;\n if (rc == 1) {\n val= 0;\n } else if (rc == 2) {\n val= get_bits1(&h->gb)^1;\n }else{\n val= get_ue_golomb_31(&h->gb);\n if (val >= rc) {\n av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n return -1;\n }\n }\n }else\n val= LIST_NOT_USED&0xFF;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n mx += get_se_golomb(&h->gb);\n my += get_se_golomb(&h->gb);\n tprintf(h->avctx, "final mv:%d %d\\n", mx, my);\n val= pack16to32(mx,my);\n }else\n val=0;\n fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4);\n }\n }\n }\n }\n if(IS_INTER(mb_type))\n write_back_motion(h, mb_type);\n if(!IS_INTRA16x16(mb_type)){\n cbp= get_ue_golomb(&h->gb);\n if(decode_chroma){\n if(cbp > 47){\n av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\\n", cbp, h->mb_x, h->mb_y);\n return -1;\n }\n if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp];\n else cbp= golomb_to_inter_cbp [cbp];\n }else{\n if(cbp > 15){\n av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\\n", cbp, h->mb_x, h->mb_y);\n return -1;\n }\n if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp];\n else cbp= golomb_to_inter_cbp_gray[cbp];\n }\n }\n if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){\n mb_type |= MB_TYPE_8x8DCT*get_bits1(&h->gb);\n }\n h->cbp=\n h->cbp_table[mb_xy]= cbp;\n h->cur_pic.f.mb_type[mb_xy] = mb_type;\n if(cbp || IS_INTRA16x16(mb_type)){\n int i4x4, i8x8, chroma_idx;\n int dquant;\n int ret;\n GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr;\n const uint8_t *scan, *scan8x8;\n const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);\n if(IS_INTERLACED(mb_type)){\n scan8x8= h->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;\n scan= h->qscale ? h->field_scan : h->field_scan_q0;\n }else{\n scan8x8= h->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0;\n scan= h->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n }\n dquant= get_se_golomb(&h->gb);\n h->qscale += dquant;\n if(((unsigned)h->qscale) > max_qp){\n if(h->qscale<0) h->qscale+= max_qp+1;\n else h->qscale-= max_qp+1;\n if(((unsigned)h->qscale) > max_qp){\n av_log(h->avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\\n", dquant, h->mb_x, h->mb_y);\n return -1;\n }\n }\n h->chroma_qp[0]= get_chroma_qp(h, 0, h->qscale);\n h->chroma_qp[1]= get_chroma_qp(h, 1, h->qscale);\n if( (ret = decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ){\n return -1;\n }\n h->cbp_table[mb_xy] |= ret << 12;\n if(CHROMA444){\n if( decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 1) < 0 ){\n return -1;\n }\n if( decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 2) < 0 ){\n return -1;\n }\n } else if (CHROMA422) {\n if(cbp&0x30){\n for(chroma_idx=0; chroma_idx<2; chroma_idx++)\n if (decode_residual(h, gb, h->mb + ((256 + 16*16*chroma_idx) << pixel_shift),\n CHROMA_DC_BLOCK_INDEX+chroma_idx, chroma422_dc_scan,\n NULL, 8) < 0) {\n return -1;\n }\n }\n if(cbp&0x20){\n for(chroma_idx=0; chroma_idx<2; chroma_idx++){\n const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]];\n int16_t *mb = h->mb + (16*(16 + 16*chroma_idx) << pixel_shift);\n for (i8x8 = 0; i8x8 < 2; i8x8++) {\n for (i4x4 = 0; i4x4 < 4; i4x4++) {\n const int index = 16 + 16*chroma_idx + 8*i8x8 + i4x4;\n if (decode_residual(h, gb, mb, index, scan + 1, qmul, 15) < 0)\n return -1;\n mb += 16 << pixel_shift;\n }\n }\n }\n }else{\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n }\n } else {\n if(cbp&0x30){\n for(chroma_idx=0; chroma_idx<2; chroma_idx++)\n if( decode_residual(h, gb, h->mb + ((256 + 16*16*chroma_idx) << pixel_shift), CHROMA_DC_BLOCK_INDEX+chroma_idx, chroma_dc_scan, NULL, 4) < 0){\n return -1;\n }\n }\n if(cbp&0x20){\n for(chroma_idx=0; chroma_idx<2; chroma_idx++){\n const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]];\n for(i4x4=0; i4x4<4; i4x4++){\n const int index= 16 + 16*chroma_idx + i4x4;\n if( decode_residual(h, gb, h->mb + (16*index << pixel_shift), index, scan + 1, qmul, 15) < 0){\n return -1;\n }\n }\n }\n }else{\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n }\n }\n }else{\n fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n }\n h->cur_pic.f.qscale_table[mb_xy] = h->qscale;\n write_back_non_zero_count(h);\n return 0;\n}', 'static void fill_decode_neighbors(H264Context *h, int mb_type)\n{\n const int mb_xy = h->mb_xy;\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n static const uint8_t left_block_options[4][32] = {\n { 0, 1, 2, 3, 7, 10, 8, 11, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 5 * 4, 1 + 9 * 4 },\n { 2, 2, 3, 3, 8, 11, 8, 11, 3 + 2 * 4, 3 + 2 * 4, 3 + 3 * 4, 3 + 3 * 4, 1 + 5 * 4, 1 + 9 * 4, 1 + 5 * 4, 1 + 9 * 4 },\n { 0, 0, 1, 1, 7, 10, 7, 10, 3 + 0 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 1 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 },\n { 0, 2, 0, 2, 7, 10, 7, 10, 3 + 0 * 4, 3 + 2 * 4, 3 + 0 * 4, 3 + 2 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 }\n };\n h->topleft_partition = -1;\n top_xy = mb_xy - (h->mb_stride << MB_FIELD);\n topleft_xy = top_xy - 1;\n topright_xy = top_xy + 1;\n left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;\n h->left_block = left_block_options[0];\n if (FRAME_MBAFF) {\n const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.f.mb_type[mb_xy - 1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if (h->mb_y & 1) {\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1;\n if (curr_mb_field_flag) {\n left_xy[LBOT] += h->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n topleft_xy += h->mb_stride;\n h->topleft_partition = 0;\n h->left_block = left_block_options[1];\n }\n }\n } else {\n if (curr_mb_field_flag) {\n topleft_xy += h->mb_stride & (((h->cur_pic.f.mb_type[top_xy - 1] >> 7) & 1) - 1);\n topright_xy += h->mb_stride & (((h->cur_pic.f.mb_type[top_xy + 1] >> 7) & 1) - 1);\n top_xy += h->mb_stride & (((h->cur_pic.f.mb_type[top_xy] >> 7) & 1) - 1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n if (curr_mb_field_flag) {\n left_xy[LBOT] += h->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n h->left_block = left_block_options[2];\n }\n }\n }\n }\n h->topleft_mb_xy = topleft_xy;\n h->top_mb_xy = top_xy;\n h->topright_mb_xy = topright_xy;\n h->left_mb_xy[LTOP] = left_xy[LTOP];\n h->left_mb_xy[LBOT] = left_xy[LBOT];\n h->topleft_type = h->cur_pic.f.mb_type[topleft_xy];\n h->top_type = h->cur_pic.f.mb_type[top_xy];\n h->topright_type = h->cur_pic.f.mb_type[topright_xy];\n h->left_type[LTOP] = h->cur_pic.f.mb_type[left_xy[LTOP]];\n h->left_type[LBOT] = h->cur_pic.f.mb_type[left_xy[LBOT]];\n if (FMO) {\n if (h->slice_table[topleft_xy] != h->slice_num)\n h->topleft_type = 0;\n if (h->slice_table[top_xy] != h->slice_num)\n h->top_type = 0;\n if (h->slice_table[left_xy[LTOP]] != h->slice_num)\n h->left_type[LTOP] = h->left_type[LBOT] = 0;\n } else {\n if (h->slice_table[topleft_xy] != h->slice_num) {\n h->topleft_type = 0;\n if (h->slice_table[top_xy] != h->slice_num)\n h->top_type = 0;\n if (h->slice_table[left_xy[LTOP]] != h->slice_num)\n h->left_type[LTOP] = h->left_type[LBOT] = 0;\n }\n }\n if (h->slice_table[topright_xy] != h->slice_num)\n h->topright_type = 0;\n}', 'static void fill_decode_caches(H264Context *h, int mb_type)\n{\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n int topleft_type, top_type, topright_type, left_type[LEFT_MBS];\n const uint8_t *left_block = h->left_block;\n int i;\n uint8_t *nnz;\n uint8_t *nnz_cache;\n topleft_xy = h->topleft_mb_xy;\n top_xy = h->top_mb_xy;\n topright_xy = h->topright_mb_xy;\n left_xy[LTOP] = h->left_mb_xy[LTOP];\n left_xy[LBOT] = h->left_mb_xy[LBOT];\n topleft_type = h->topleft_type;\n top_type = h->top_type;\n topright_type = h->topright_type;\n left_type[LTOP] = h->left_type[LTOP];\n left_type[LBOT] = h->left_type[LBOT];\n if (!IS_SKIP(mb_type)) {\n if (IS_INTRA(mb_type)) {\n int type_mask = h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available =\n h->top_samples_available =\n h->left_samples_available = 0xFFFF;\n h->topright_samples_available = 0xEEEA;\n if (!(top_type & type_mask)) {\n h->topleft_samples_available = 0xB3FF;\n h->top_samples_available = 0x33FF;\n h->topright_samples_available = 0x26EA;\n }\n if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {\n if (IS_INTERLACED(mb_type)) {\n if (!(left_type[LTOP] & type_mask)) {\n h->topleft_samples_available &= 0xDFFF;\n h->left_samples_available &= 0x5FFF;\n }\n if (!(left_type[LBOT] & type_mask)) {\n h->topleft_samples_available &= 0xFF5F;\n h->left_samples_available &= 0xFF5F;\n }\n } else {\n int left_typei = h->cur_pic.f.mb_type[left_xy[LTOP] + h->mb_stride];\n assert(left_xy[LTOP] == left_xy[LBOT]);\n if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {\n h->topleft_samples_available &= 0xDF5F;\n h->left_samples_available &= 0x5F5F;\n }\n }\n } else {\n if (!(left_type[LTOP] & type_mask)) {\n h->topleft_samples_available &= 0xDF5F;\n h->left_samples_available &= 0x5F5F;\n }\n }\n if (!(topleft_type & type_mask))\n h->topleft_samples_available &= 0x7FFF;\n if (!(topright_type & type_mask))\n h->topright_samples_available &= 0xFBFF;\n if (IS_INTRA4x4(mb_type)) {\n if (IS_INTRA4x4(top_type)) {\n AV_COPY32(h->intra4x4_pred_mode_cache + 4 + 8 * 0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);\n } else {\n h->intra4x4_pred_mode_cache[4 + 8 * 0] =\n h->intra4x4_pred_mode_cache[5 + 8 * 0] =\n h->intra4x4_pred_mode_cache[6 + 8 * 0] =\n h->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);\n }\n for (i = 0; i < 2; i++) {\n if (IS_INTRA4x4(left_type[LEFT(i)])) {\n int8_t *mode = h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];\n h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];\n h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];\n } else {\n h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =\n h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);\n }\n }\n }\n }\n nnz_cache = h->non_zero_count_cache;\n if (top_type) {\n nnz = h->non_zero_count[top_xy];\n AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);\n if (!h->chroma_y_shift) {\n AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]);\n AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);\n } else {\n AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]);\n AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);\n }\n } else {\n uint32_t top_empty = CABAC && !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 for (i = 0; i < 2; i++) {\n if (left_type[LEFT(i)]) {\n nnz = h->non_zero_count[left_xy[LEFT(i)]];\n nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];\n nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];\n if (CHROMA444) {\n nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];\n nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];\n nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];\n nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];\n } else if (CHROMA422) {\n nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];\n nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];\n nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];\n nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];\n } else {\n nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];\n nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];\n }\n } else {\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] = CABAC && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if (CABAC) {\n if (top_type)\n h->top_cbp = h->cbp_table[top_xy];\n else\n h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n if (left_type[LTOP]) {\n h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) |\n ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |\n (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);\n } else {\n h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n }\n }\n if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)) {\n int list;\n int b_stride = h->b_stride;\n for (list = 0; list < h->list_count; list++) {\n int8_t *ref_cache = &h->ref_cache[list][scan8[0]];\n int8_t *ref = h->cur_pic.f.ref_index[list];\n int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]];\n int16_t(*mv)[2] = h->cur_pic.f.motion_val[list];\n if (!USES_LIST(mb_type, list))\n continue;\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n if (USES_LIST(top_type, list)) {\n const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;\n AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);\n ref_cache[0 - 1 * 8] =\n ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];\n ref_cache[2 - 1 * 8] =\n ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];\n } else {\n AV_ZERO128(mv_cache[0 - 1 * 8]);\n AV_WN32A(&ref_cache[0 - 1 * 8],\n ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);\n }\n if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {\n for (i = 0; i < 2; i++) {\n int cache_idx = -1 + i * 2 * 8;\n if (USES_LIST(left_type[LEFT(i)], list)) {\n const int b_xy = h->mb2b_xy[left_xy[LEFT(i)]] + 3;\n const int b8_xy = 4 * left_xy[LEFT(i)] + 1;\n AV_COPY32(mv_cache[cache_idx],\n mv[b_xy + b_stride * left_block[0 + i * 2]]);\n AV_COPY32(mv_cache[cache_idx + 8],\n mv[b_xy + b_stride * left_block[1 + i * 2]]);\n ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)];\n ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];\n } else {\n AV_ZERO32(mv_cache[cache_idx]);\n AV_ZERO32(mv_cache[cache_idx + 8]);\n ref_cache[cache_idx] =\n ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n } else {\n if (USES_LIST(left_type[LTOP], list)) {\n const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3;\n const int b8_xy = 4 * left_xy[LTOP] + 1;\n AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);\n ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];\n } else {\n AV_ZERO32(mv_cache[-1]);\n ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n if (USES_LIST(topright_type, list)) {\n const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;\n AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);\n ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];\n } else {\n AV_ZERO32(mv_cache[4 - 1 * 8]);\n ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n if (ref_cache[4 - 1 * 8] < 0) {\n if (USES_LIST(topleft_type, list)) {\n const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride +\n (h->topleft_partition & 2 * b_stride);\n const int b8_xy = 4 * topleft_xy + 1 + (h->topleft_partition & 2);\n AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);\n ref_cache[-1 - 1 * 8] = ref[b8_xy];\n } else {\n AV_ZERO32(mv_cache[-1 - 1 * 8]);\n ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF)\n continue;\n if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) {\n uint8_t(*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];\n uint8_t(*mvd)[2] = h->mvd_table[list];\n ref_cache[2 + 8 * 0] =\n ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE;\n AV_ZERO32(mv_cache[2 + 8 * 0]);\n AV_ZERO32(mv_cache[2 + 8 * 2]);\n if (CABAC) {\n if (USES_LIST(top_type, list)) {\n const int b_xy = h->mb2br_xy[top_xy];\n AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);\n } else {\n AV_ZERO64(mvd_cache[0 - 1 * 8]);\n }\n if (USES_LIST(left_type[LTOP], list)) {\n const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;\n AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);\n AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);\n } else {\n AV_ZERO16(mvd_cache[-1 + 0 * 8]);\n AV_ZERO16(mvd_cache[-1 + 1 * 8]);\n }\n if (USES_LIST(left_type[LBOT], list)) {\n const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;\n AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);\n AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);\n } else {\n AV_ZERO16(mvd_cache[-1 + 2 * 8]);\n AV_ZERO16(mvd_cache[-1 + 3 * 8]);\n }\n AV_ZERO16(mvd_cache[2 + 8 * 0]);\n AV_ZERO16(mvd_cache[2 + 8 * 2]);\n if (h->slice_type_nos == AV_PICTURE_TYPE_B) {\n uint8_t *direct_cache = &h->direct_cache[scan8[0]];\n uint8_t *direct_table = h->direct_table;\n fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);\n if (IS_DIRECT(top_type)) {\n AV_WN32A(&direct_cache[-1 * 8],\n 0x01010101u * (MB_TYPE_DIRECT2 >> 1));\n } else if (IS_8X8(top_type)) {\n int b8_xy = 4 * top_xy;\n direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];\n direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];\n } else {\n AV_WN32A(&direct_cache[-1 * 8],\n 0x01010101 * (MB_TYPE_16x16 >> 1));\n }\n if (IS_DIRECT(left_type[LTOP]))\n direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;\n else if (IS_8X8(left_type[LTOP]))\n direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];\n else\n direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;\n if (IS_DIRECT(left_type[LBOT]))\n direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;\n else if (IS_8X8(left_type[LBOT]))\n direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];\n else\n direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;\n }\n }\n }\n#define MAP_MVS \\\n MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \\\n MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \\\n MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \\\n MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \\\n MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \\\n MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])\n if (FRAME_MBAFF) {\n if (MB_FIELD) {\n#define MAP_F2F(idx, mb_type) \\\n if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \\\n h->ref_cache[list][idx] <<= 1; \\\n h->mv_cache[list][idx][1] /= 2; \\\n h->mvd_cache[list][idx][1] >>= 1; \\\n }\n MAP_MVS\n } else {\n#undef MAP_F2F\n#define MAP_F2F(idx, mb_type) \\\n if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \\\n h->ref_cache[list][idx] >>= 1; \\\n h->mv_cache[list][idx][1] <<= 1; \\\n h->mvd_cache[list][idx][1] <<= 1; \\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n h->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);\n}']
36,523
0
https://github.com/openssl/openssl/blob/1f9d203dac62f7426f6ff1fbc819e3de8b6f1171/ssl/ssl_lib.c/#L253
static int dane_mtype_set(struct dane_ctx_st *dctx, const EVP_MD *md, uint8_t mtype, uint8_t ord) { int i; if (mtype == DANETLS_MATCHING_FULL && md != NULL) { SSLerr(SSL_F_DANE_MTYPE_SET, SSL_R_DANE_CANNOT_OVERRIDE_MTYPE_FULL); return 0; } if (mtype > dctx->mdmax) { const EVP_MD **mdevp; uint8_t *mdord; int n = ((int)mtype) + 1; mdevp = OPENSSL_realloc(dctx->mdevp, n * sizeof(*mdevp)); if (mdevp == NULL) { SSLerr(SSL_F_DANE_MTYPE_SET, ERR_R_MALLOC_FAILURE); return -1; } dctx->mdevp = mdevp; mdord = OPENSSL_realloc(dctx->mdord, n * sizeof(*mdord)); if (mdord == NULL) { SSLerr(SSL_F_DANE_MTYPE_SET, ERR_R_MALLOC_FAILURE); return -1; } dctx->mdord = mdord; for (i = dctx->mdmax + 1; i < mtype; ++i) { mdevp[i] = NULL; mdord[i] = 0; } dctx->mdmax = mtype; } dctx->mdevp[mtype] = md; dctx->mdord[mtype] = (md == NULL) ? 0 : ord; return 1; }
['static int run_tlsatest()\n{\n SSL_CTX *ctx = NULL;\n BIO *f = NULL;\n int ret = 0;\n if (!TEST_ptr(f = BIO_new_file(tlsafile, "r"))\n || !TEST_ptr(ctx = SSL_CTX_new(TLS_client_method()))\n || !TEST_int_gt(SSL_CTX_dane_enable(ctx), 0)\n || !TEST_true(SSL_CTX_load_verify_locations(ctx, CAfile, NULL))\n || !TEST_int_gt(SSL_CTX_dane_mtype_set(ctx, EVP_sha512(), 2, 1),\n 0)\n || !TEST_int_gt(SSL_CTX_dane_mtype_set(ctx, EVP_sha256(), 1, 2),\n 0)\n || !TEST_int_gt(test_tlsafile(ctx, basedomain, f, tlsafile), 0))\n goto end;\n ret = 1;\nend:\n BIO_free(f);\n SSL_CTX_free(ctx);\n return ret;\n}', 'int SSL_CTX_dane_enable(SSL_CTX *ctx)\n{\n return dane_ctx_enable(&ctx->dane);\n}', 'static int dane_ctx_enable(struct dane_ctx_st *dctx)\n{\n const EVP_MD **mdevp;\n uint8_t *mdord;\n uint8_t mdmax = DANETLS_MATCHING_LAST;\n int n = ((int)mdmax) + 1;\n size_t i;\n if (dctx->mdevp != NULL)\n return 1;\n mdevp = OPENSSL_zalloc(n * sizeof(*mdevp));\n mdord = OPENSSL_zalloc(n * sizeof(*mdord));\n if (mdord == NULL || mdevp == NULL) {\n OPENSSL_free(mdord);\n OPENSSL_free(mdevp);\n SSLerr(SSL_F_DANE_CTX_ENABLE, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n for (i = 0; i < OSSL_NELEM(dane_mds); ++i) {\n const EVP_MD *md;\n if (dane_mds[i].nid == NID_undef ||\n (md = EVP_get_digestbynid(dane_mds[i].nid)) == NULL)\n continue;\n mdevp[dane_mds[i].mtype] = md;\n mdord[dane_mds[i].mtype] = dane_mds[i].ord;\n }\n dctx->mdevp = mdevp;\n dctx->mdord = mdord;\n dctx->mdmax = mdmax;\n return 1;\n}', 'int SSL_CTX_dane_mtype_set(SSL_CTX *ctx, const EVP_MD *md, uint8_t mtype,\n uint8_t ord)\n{\n return dane_mtype_set(&ctx->dane, md, mtype, ord);\n}', 'static int dane_mtype_set(struct dane_ctx_st *dctx,\n const EVP_MD *md, uint8_t mtype, uint8_t ord)\n{\n int i;\n if (mtype == DANETLS_MATCHING_FULL && md != NULL) {\n SSLerr(SSL_F_DANE_MTYPE_SET, SSL_R_DANE_CANNOT_OVERRIDE_MTYPE_FULL);\n return 0;\n }\n if (mtype > dctx->mdmax) {\n const EVP_MD **mdevp;\n uint8_t *mdord;\n int n = ((int)mtype) + 1;\n mdevp = OPENSSL_realloc(dctx->mdevp, n * sizeof(*mdevp));\n if (mdevp == NULL) {\n SSLerr(SSL_F_DANE_MTYPE_SET, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n dctx->mdevp = mdevp;\n mdord = OPENSSL_realloc(dctx->mdord, n * sizeof(*mdord));\n if (mdord == NULL) {\n SSLerr(SSL_F_DANE_MTYPE_SET, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n dctx->mdord = mdord;\n for (i = dctx->mdmax + 1; i < mtype; ++i) {\n mdevp[i] = NULL;\n mdord[i] = 0;\n }\n dctx->mdmax = mtype;\n }\n dctx->mdevp[mtype] = md;\n dctx->mdord[mtype] = (md == NULL) ? 0 : ord;\n return 1;\n}']
36,524
0
https://github.com/libav/libav/blob/750f5034cf4d0dbe54aed917972f9c3f7a2cebbd/libavcodec/wmaprodec.c/#L1011
static void wmapro_window(WMAProDecodeCtx *s) { int i; for (i = 0; i < s->channels_for_cur_subframe; i++) { int c = s->channel_indexes_for_cur_subframe[i]; float* window; int winlen = s->channel[c].prev_block_len; float* start = s->channel[c].coeffs - (winlen >> 1); if (s->subframe_len < winlen) { start += (winlen - s->subframe_len) >> 1; winlen = s->subframe_len; } window = s->windows[av_log2(winlen) - BLOCK_MIN_BITS]; winlen >>= 1; s->dsp.vector_fmul_window(start, start, start + winlen, window, 0, winlen); s->channel[c].prev_block_len = s->subframe_len; } }
['static void wmapro_window(WMAProDecodeCtx *s)\n{\n int i;\n for (i = 0; i < s->channels_for_cur_subframe; i++) {\n int c = s->channel_indexes_for_cur_subframe[i];\n float* window;\n int winlen = s->channel[c].prev_block_len;\n float* start = s->channel[c].coeffs - (winlen >> 1);\n if (s->subframe_len < winlen) {\n start += (winlen - s->subframe_len) >> 1;\n winlen = s->subframe_len;\n }\n window = s->windows[av_log2(winlen) - BLOCK_MIN_BITS];\n winlen >>= 1;\n s->dsp.vector_fmul_window(start, start, start + winlen,\n window, 0, winlen);\n s->channel[c].prev_block_len = s->subframe_len;\n }\n}', 'static inline av_const int av_log2(unsigned int v)\n{\n int n = 0;\n if (v & 0xffff0000) {\n v >>= 16;\n n += 16;\n }\n if (v & 0xff00) {\n v >>= 8;\n n += 8;\n }\n n += ff_log2_tab[v];\n return n;\n}']
36,525
0
https://github.com/openssl/openssl/blob/e24bdcde5a80a7edeb1e0dbbcf45c3353a974974/crypto/initthread.c/#L233
int ossl_init_thread_start(void *arg, OSSL_thread_stop_handler_fn handfn) { THREAD_EVENT_HANDLER **hands; THREAD_EVENT_HANDLER *hand; #ifdef FIPS_MODE OPENSSL_CTX *ctx = arg; CRYPTO_THREAD_LOCAL *local = openssl_ctx_get_data(ctx, OPENSSL_CTX_THREAD_EVENT_HANDLER_INDEX, &thread_event_ossl_ctx_method); #else CRYPTO_THREAD_LOCAL *local = &destructor_key.value; #endif hands = init_get_thread_local(local, 1, 0); if (hands == NULL) return 0; #ifdef FIPS_MODE if (*hands == NULL) { if (!c_thread_start(FIPS_get_provider(ctx), ossl_ctx_thread_stop)) return 0; } #endif hand = OPENSSL_malloc(sizeof(*hand)); if (hand == NULL) return 0; hand->handfn = handfn; hand->arg = arg; hand->next = *hands; *hands = hand; return 1; }
['int ossl_init_thread_start(void *arg, OSSL_thread_stop_handler_fn handfn)\n{\n THREAD_EVENT_HANDLER **hands;\n THREAD_EVENT_HANDLER *hand;\n#ifdef FIPS_MODE\n OPENSSL_CTX *ctx = arg;\n CRYPTO_THREAD_LOCAL *local\n = openssl_ctx_get_data(ctx, OPENSSL_CTX_THREAD_EVENT_HANDLER_INDEX,\n &thread_event_ossl_ctx_method);\n#else\n CRYPTO_THREAD_LOCAL *local = &destructor_key.value;\n#endif\n hands = init_get_thread_local(local, 1, 0);\n if (hands == NULL)\n return 0;\n#ifdef FIPS_MODE\n if (*hands == NULL) {\n if (!c_thread_start(FIPS_get_provider(ctx), ossl_ctx_thread_stop))\n return 0;\n }\n#endif\n hand = OPENSSL_malloc(sizeof(*hand));\n if (hand == NULL)\n return 0;\n hand->handfn = handfn;\n hand->arg = arg;\n hand->next = *hands;\n *hands = hand;\n return 1;\n}', 'void *openssl_ctx_get_data(OPENSSL_CTX *ctx, int index,\n const OPENSSL_CTX_METHOD *meth)\n{\n void *data = NULL;\n ctx = openssl_ctx_get_concrete(ctx);\n if (ctx == NULL)\n return NULL;\n CRYPTO_THREAD_read_lock(ctx->lock);\n if (ctx->dyn_indexes[index] == -1\n && !openssl_ctx_init_index(ctx, index, meth)) {\n CRYPTO_THREAD_unlock(ctx->lock);\n return NULL;\n }\n if (CRYPTO_alloc_ex_data(CRYPTO_EX_INDEX_OPENSSL_CTX, NULL,\n &ctx->data, ctx->dyn_indexes[index]))\n data = CRYPTO_get_ex_data(&ctx->data, ctx->dyn_indexes[index]);\n CRYPTO_THREAD_unlock(ctx->lock);\n return data;\n}', 'OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx)\n{\n#ifndef FIPS_MODE\n if (ctx == NULL) {\n if (!RUN_ONCE(&default_context_init, do_default_context_init))\n return 0;\n return default_context;\n }\n#endif\n return ctx;\n}', 'static THREAD_EVENT_HANDLER **\ninit_get_thread_local(CRYPTO_THREAD_LOCAL *local, int alloc, int keep)\n{\n THREAD_EVENT_HANDLER **hands = CRYPTO_THREAD_get_local(local);\n if (alloc) {\n if (hands == NULL\n && (hands = OPENSSL_zalloc(sizeof(*hands))) != NULL\n && !CRYPTO_THREAD_set_local(local, hands)) {\n OPENSSL_free(hands);\n return NULL;\n }\n } else if (!keep) {\n CRYPTO_THREAD_set_local(local, NULL);\n }\n return hands;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}']
36,526
0
https://github.com/libav/libav/blob/f40f329e9219a8dd7e585345a8ea294fa66562b9/libavcodec/mpegaudiodec.c/#L896
void RENAME(ff_mpa_synth_filter)(MPA_INT *synth_buf_ptr, int *synth_buf_offset, MPA_INT *window, int *dither_state, OUT_INT *samples, int incr, INTFLOAT sb_samples[SBLIMIT]) { register MPA_INT *synth_buf; register const MPA_INT *w, *w2, *p; int j, offset; OUT_INT *samples2; #if CONFIG_FLOAT float sum, sum2; #elif FRAC_BITS <= 15 int32_t tmp[32]; int sum, sum2; #else int64_t sum, sum2; #endif offset = *synth_buf_offset; synth_buf = synth_buf_ptr + offset; #if FRAC_BITS <= 15 && !CONFIG_FLOAT dct32(tmp, sb_samples); for(j=0;j<32;j++) { synth_buf[j] = av_clip_int16(tmp[j]); } #else dct32(synth_buf, sb_samples); #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; 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 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 RENAME(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 register const MPA_INT *w, *w2, *p;\n int j, offset;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#elif FRAC_BITS <= 15\n int32_t tmp[32];\n int sum, sum2;\n#else\n int64_t sum, sum2;\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 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 offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}']
36,527
0
https://github.com/openssl/openssl/blob/d8028b202bfe337200a0cc89b80983ea1838cb30/ssl/packet.c/#L49
int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes) { assert(pkt->subs != NULL && len != 0); if (pkt->subs == NULL || len == 0) return 0; if (pkt->maxsize - pkt->written < len) return 0; if (pkt->staticbuf == 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_ctos_cookie(SSL *s, WPACKET *pkt, unsigned int context,\n X509 *x, size_t chainidx, int *al)\n{\n EXT_RETURN ret = EXT_RETURN_FAIL;\n if (s->ext.tls13_cookie_len == 0)\n return EXT_RETURN_NOT_SENT;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_cookie)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_sub_memcpy_u16(pkt, s->ext.tls13_cookie,\n s->ext.tls13_cookie_len)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CTOS_COOKIE, ERR_R_INTERNAL_ERROR);\n goto end;\n }\n ret = EXT_RETURN_SENT;\n end:\n OPENSSL_free(s->ext.tls13_cookie);\n s->ext.tls13_cookie = NULL;\n s->ext.tls13_cookie_len = 0;\n return ret;\n}', 'int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)\n{\n unsigned char *data;\n assert(size <= sizeof(unsigned int));\n if (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_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n assert(pkt->subs != NULL);\n if (pkt->subs == NULL)\n return 0;\n sub = OPENSSL_zalloc(sizeof(*sub));\n if (sub == NULL)\n return 0;\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n sub->packet_len = lenchars - GETBUF(pkt);\n return 1;\n}', 'int WPACKET_sub_memcpy__(WPACKET *pkt, const void *src, size_t len,\n size_t lenbytes)\n{\n if (!WPACKET_start_sub_packet_len__(pkt, lenbytes)\n || !WPACKET_memcpy(pkt, src, len)\n || !WPACKET_close(pkt))\n return 0;\n return 1;\n}', 'int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)\n{\n unsigned char *dest;\n if (len == 0)\n return 1;\n if (!WPACKET_allocate_bytes(pkt, len, &dest))\n return 0;\n memcpy(dest, src, len);\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 assert(pkt->subs != NULL && len != 0);\n if (pkt->subs == NULL || len == 0)\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->staticbuf == 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}']
36,528
0
https://gitlab.com/libtiff/libtiff/blob/709e93ded0000128625a23838756a408ea30745d/libtiff/tif_swab.c/#L296
void TIFFReverseBits(uint8* cp, tmsize_t n) { for (; n > 8; n -= 8) { cp[0] = TIFFBitRevTable[cp[0]]; cp[1] = TIFFBitRevTable[cp[1]]; cp[2] = TIFFBitRevTable[cp[2]]; cp[3] = TIFFBitRevTable[cp[3]]; cp[4] = TIFFBitRevTable[cp[4]]; cp[5] = TIFFBitRevTable[cp[5]]; cp[6] = TIFFBitRevTable[cp[6]]; cp[7] = TIFFBitRevTable[cp[7]]; cp += 8; } while (n-- > 0) *cp = TIFFBitRevTable[*cp], cp++; }
['DECLAREcpFunc(cpSeparate2SeparateByRow)\n{\n\ttsize_t scanlinesize = TIFFScanlineSize(in);\n\ttdata_t buf;\n\tuint32 row;\n\ttsample_t s;\n\t(void) imagewidth;\n\tbuf = _TIFFmalloc(scanlinesize);\n\tif (!buf)\n\t\treturn 0;\n\t_TIFFmemset(buf, 0, scanlinesize);\n\tfor (s = 0; s < spp; s++) {\n\t\tfor (row = 0; row < imagelength; row++) {\n\t\t\tif (TIFFReadScanline(in, buf, row, s) < 0 && !ignore) {\n\t\t\t\tTIFFError(TIFFFileName(in),\n\t\t\t\t "Error, can\'t read scanline %lu",\n\t\t\t\t (unsigned long) row);\n\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFWriteScanline(out, buf, row, s) < 0) {\n\t\t\t\tTIFFError(TIFFFileName(out),\n\t\t\t\t "Error, can\'t write scanline %lu",\n\t\t\t\t (unsigned long) row);\n\t\t\t\tgoto bad;\n\t\t\t}\n\t\t}\n\t}\n\t_TIFFfree(buf);\n\treturn 1;\nbad:\n\t_TIFFfree(buf);\n\treturn 0;\n}', 'int\nTIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample)\n{\n\tstatic const char module[] = "TIFFWriteScanline";\n\tregister TIFFDirectory *td;\n\tint status, imagegrew = 0;\n\tuint32 strip;\n\tif (!WRITECHECKSTRIPS(tif, module))\n\t\treturn (-1);\n\tif (!BUFFERCHECK(tif))\n\t\treturn (-1);\n tif->tif_flags |= TIFF_BUF4WRITE;\n\ttd = &tif->tif_dir;\n\tif (row >= td->td_imagelength) {\n\t\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Can not change \\"ImageLength\\" when using separate planes");\n\t\t\treturn (-1);\n\t\t}\n\t\ttd->td_imagelength = row+1;\n\t\timagegrew = 1;\n\t}\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE) {\n\t\tif (sample >= td->td_samplesperpixel) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "%lu: Sample out of range, max %lu",\n\t\t\t (unsigned long) sample, (unsigned long) td->td_samplesperpixel);\n\t\t\treturn (-1);\n\t\t}\n\t\tstrip = sample*td->td_stripsperimage + row/td->td_rowsperstrip;\n\t} else\n\t\tstrip = row / td->td_rowsperstrip;\n\tif (strip >= td->td_nstrips && !TIFFGrowStrips(tif, 1, module))\n\t\treturn (-1);\n\tif (strip != tif->tif_curstrip) {\n\t\tif (!TIFFFlushData(tif))\n\t\t\treturn (-1);\n\t\ttif->tif_curstrip = strip;\n\t\tif (strip >= td->td_stripsperimage && imagegrew)\n\t\t\ttd->td_stripsperimage =\n\t\t\t TIFFhowmany_32(td->td_imagelength,td->td_rowsperstrip);\n\t\ttif->tif_row =\n\t\t (strip % td->td_stripsperimage) * td->td_rowsperstrip;\n\t\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\t\tif (!(*tif->tif_setupencode)(tif))\n\t\t\t\treturn (-1);\n\t\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t\t}\n\t\ttif->tif_rawcc = 0;\n\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\tif( td->td_stripbytecount[strip] > 0 )\n\t\t{\n\t\t\ttd->td_stripbytecount[strip] = 0;\n\t\t\ttif->tif_curoff = 0;\n\t\t}\n\t\tif (!(*tif->tif_preencode)(tif, sample))\n\t\t\treturn (-1);\n\t\ttif->tif_flags |= TIFF_POSTENCODE;\n\t}\n\tif (row != tif->tif_row) {\n\t\tif (row < tif->tif_row) {\n\t\t\ttif->tif_row = (strip % td->td_stripsperimage) *\n\t\t\t td->td_rowsperstrip;\n\t\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\t}\n\t\tif (!(*tif->tif_seek)(tif, row - tif->tif_row))\n\t\t\treturn (-1);\n\t\ttif->tif_row = row;\n\t}\n\ttif->tif_postdecode( tif, (uint8*) buf, tif->tif_scanlinesize );\n\tstatus = (*tif->tif_encoderow)(tif, (uint8*) buf,\n\t tif->tif_scanlinesize, sample);\n\ttif->tif_row = row + 1;\n\treturn (status);\n}', 'int\nTIFFFlushData(TIFF* tif)\n{\n\tif ((tif->tif_flags & TIFF_BEENWRITING) == 0)\n\t\treturn (1);\n\tif (tif->tif_flags & TIFF_POSTENCODE) {\n\t\ttif->tif_flags &= ~TIFF_POSTENCODE;\n\t\tif (!(*tif->tif_postencode)(tif))\n\t\t\treturn (0);\n\t}\n\treturn (TIFFFlushData1(tif));\n}', 'int\nTIFFFlushData1(TIFF* tif)\n{\n\tif (tif->tif_rawcc > 0 && tif->tif_flags & TIFF_BUF4WRITE ) {\n\t\tif (!isFillOrder(tif, tif->tif_dir.td_fillorder) &&\n\t\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\t\tTIFFReverseBits((uint8*)tif->tif_rawdata,\n\t\t\t tif->tif_rawcc);\n\t\tif (!TIFFAppendToStrip(tif,\n\t\t isTiled(tif) ? tif->tif_curtile : tif->tif_curstrip,\n\t\t tif->tif_rawdata, tif->tif_rawcc))\n\t\t\treturn (0);\n\t\ttif->tif_rawcc = 0;\n\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t}\n\treturn (1);\n}', 'void\nTIFFReverseBits(uint8* cp, tmsize_t n)\n{\n\tfor (; n > 8; n -= 8) {\n\t\tcp[0] = TIFFBitRevTable[cp[0]];\n\t\tcp[1] = TIFFBitRevTable[cp[1]];\n\t\tcp[2] = TIFFBitRevTable[cp[2]];\n\t\tcp[3] = TIFFBitRevTable[cp[3]];\n\t\tcp[4] = TIFFBitRevTable[cp[4]];\n\t\tcp[5] = TIFFBitRevTable[cp[5]];\n\t\tcp[6] = TIFFBitRevTable[cp[6]];\n\t\tcp[7] = TIFFBitRevTable[cp[7]];\n\t\tcp += 8;\n\t}\n\twhile (n-- > 0)\n\t\t*cp = TIFFBitRevTable[*cp], cp++;\n}']
36,529
0
https://github.com/openssl/openssl/blob/b50e1bd3c3f0b8331b616a10bbc1fc20ea866d07/crypto/err/err.c/#L720
ERR_STATE *ERR_get_state(void) { static ERR_STATE fallback; ERR_STATE *ret=NULL,tmp,*tmpp; int thread_state_exists; int i; unsigned long pid; pid=(unsigned long)CRYPTO_thread_id(); CRYPTO_r_lock(CRYPTO_LOCK_ERR); if (thread_hash != NULL) { tmp.pid=pid; ret=(ERR_STATE *)lh_retrieve(thread_hash,&tmp); } CRYPTO_r_unlock(CRYPTO_LOCK_ERR); if (ret == NULL) { ret=(ERR_STATE *)Malloc(sizeof(ERR_STATE)); if (ret == NULL) return(&fallback); ret->pid=pid; ret->top=0; ret->bottom=0; for (i=0; i<ERR_NUM_ERRORS; i++) { ret->err_data[i]=NULL; ret->err_data_flags[i]=0; } CRYPTO_w_lock(CRYPTO_LOCK_ERR); if (thread_hash == NULL) thread_hash = lh_new(pid_hash, pid_cmp); if (thread_hash == NULL) thread_state_exists = 0; else { tmpp=(ERR_STATE *)lh_insert(thread_hash,ret); thread_state_exists = 1; } CRYPTO_w_unlock(CRYPTO_LOCK_ERR); if (!thread_state_exists) { ERR_STATE_free(ret); return(&fallback); } if (tmpp != NULL) { ERR_STATE_free(tmpp); } } return(ret); }
['ERR_STATE *ERR_get_state(void)\n\t{\n\tstatic ERR_STATE fallback;\n\tERR_STATE *ret=NULL,tmp,*tmpp;\n\tint thread_state_exists;\n\tint i;\n\tunsigned long pid;\n\tpid=(unsigned long)CRYPTO_thread_id();\n\tCRYPTO_r_lock(CRYPTO_LOCK_ERR);\n\tif (thread_hash != NULL)\n\t\t{\n\t\ttmp.pid=pid;\n\t\tret=(ERR_STATE *)lh_retrieve(thread_hash,&tmp);\n\t\t}\n\tCRYPTO_r_unlock(CRYPTO_LOCK_ERR);\n\tif (ret == NULL)\n\t\t{\n\t\tret=(ERR_STATE *)Malloc(sizeof(ERR_STATE));\n\t\tif (ret == NULL) return(&fallback);\n\t\tret->pid=pid;\n\t\tret->top=0;\n\t\tret->bottom=0;\n\t\tfor (i=0; i<ERR_NUM_ERRORS; i++)\n\t\t\t{\n\t\t\tret->err_data[i]=NULL;\n\t\t\tret->err_data_flags[i]=0;\n\t\t\t}\n\t\tCRYPTO_w_lock(CRYPTO_LOCK_ERR);\n\t\tif (thread_hash == NULL)\n\t\t\tthread_hash = lh_new(pid_hash, pid_cmp);\n\t\tif (thread_hash == NULL)\n\t\t\tthread_state_exists = 0;\n\t\telse\n\t\t\t{\n\t\t\ttmpp=(ERR_STATE *)lh_insert(thread_hash,ret);\n\t\t\tthread_state_exists = 1;\n\t\t\t}\n\t\tCRYPTO_w_unlock(CRYPTO_LOCK_ERR);\n\t\tif (!thread_state_exists)\n\t\t\t{\n\t\t\tERR_STATE_free(ret);\n\t\t\treturn(&fallback);\n\t\t\t}\n\t\tif (tmpp != NULL)\n\t\t\t{\n\t\t\tERR_STATE_free(tmpp);\n\t\t\t}\n\t\t}\n\treturn(ret);\n\t}']
36,530
0
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_lib.c/#L231
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_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}', '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->neg = b->neg;\n a->top = b->top;\n a->flags |= b->flags & BN_FLG_FIXED_TOP;\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}', '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}']
36,531
0
https://github.com/libav/libav/blob/3ee2c60cc296eee3f63d7b5fee9b4332eeeac9fa/libavutil/imgutils.c/#L283
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); if (!desc || desc->flags & AV_PIX_FMT_FLAG_HWACCEL) return; if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) { av_image_copy_plane(dst_data[0], dst_linesizes[0], src_data[0], src_linesizes[0], width, height); memcpy(dst_data[1], src_data[1], 4*256); } else { int i, planes_nb = 0; for (i = 0; i < desc->nb_components; i++) planes_nb = FFMAX(planes_nb, desc->comp[i].plane + 1); for (i = 0; i < planes_nb; i++) { int h = height; int bwidth = av_image_get_linesize(pix_fmt, width, i); if (i == 1 || i == 2) { h= -((-height)>>desc->log2_chroma_h); } av_image_copy_plane(dst_data[i], dst_linesizes[i], src_data[i], src_linesizes[i], bwidth, h); } } }
['static void copy_frame(AVFrame *f, const uint8_t *src, int width, int height)\n{\n uint8_t *src_data[4];\n int src_linesize[4];\n av_image_fill_arrays(src_data, src_linesize, src,\n f->format, width, height, 1);\n av_image_copy(f->data, f->linesize, src_data, src_linesize,\n f->format, width, height);\n}', 'void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4],\n const uint8_t *src_data[4], const int src_linesizes[4],\n enum AVPixelFormat pix_fmt, int width, int height)\n{\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);\n if (!desc || desc->flags & AV_PIX_FMT_FLAG_HWACCEL)\n return;\n if (desc->flags & AV_PIX_FMT_FLAG_PAL ||\n desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {\n av_image_copy_plane(dst_data[0], dst_linesizes[0],\n src_data[0], src_linesizes[0],\n width, height);\n memcpy(dst_data[1], src_data[1], 4*256);\n } else {\n int i, planes_nb = 0;\n for (i = 0; i < desc->nb_components; i++)\n planes_nb = FFMAX(planes_nb, desc->comp[i].plane + 1);\n for (i = 0; i < planes_nb; i++) {\n int h = height;\n int bwidth = av_image_get_linesize(pix_fmt, width, i);\n if (i == 1 || i == 2) {\n h= -((-height)>>desc->log2_chroma_h);\n }\n av_image_copy_plane(dst_data[i], dst_linesizes[i],\n src_data[i], src_linesizes[i],\n bwidth, h);\n }\n }\n}']
36,532
0
https://github.com/openssl/openssl/blob/52a1bab2d9891810618569e6c744375b768fce8c/crypto/lhash/lhash.c/#L240
void *lh_delete(LHASH *lh, void *data) { unsigned long hash; LHASH_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 MAIN(int argc, char **argv)\n\t{\n\tint off=0;\n\tSSL *con=NULL,*con2=NULL;\n\tint s,k,width,state=0;\n\tchar *cbuf=NULL,*sbuf=NULL;\n\tint cbuf_len,cbuf_off;\n\tint sbuf_len,sbuf_off;\n\tfd_set readfds,writefds;\n\tshort port=PORT;\n\tint full_log=1;\n\tchar *host=SSL_HOST_NAME;\n\tchar *cert_file=NULL,*key_file=NULL;\n\tchar *CApath=NULL,*CAfile=NULL,*cipher=NULL;\n\tint reconnect=0,badop=0,verify=SSL_VERIFY_NONE,bugs=0;\n\tint crlf=0;\n\tint write_tty,read_tty,write_ssl,read_ssl,tty_on,ssl_pending;\n\tSSL_CTX *ctx=NULL;\n\tint ret=1,in_init=1,i,nbio_test=0;\n\tint prexit = 0;\n\tSSL_METHOD *meth=NULL;\n\tBIO *sbio;\n\tchar *engine_id=NULL;\n\tENGINE *e=NULL;\n#ifdef WINDOWS\n\tstruct timeval tv;\n#endif\n#if !defined(NO_SSL2) && !defined(NO_SSL3)\n\tmeth=SSLv23_client_method();\n#elif !defined(NO_SSL3)\n\tmeth=SSLv3_client_method();\n#elif !defined(NO_SSL2)\n\tmeth=SSLv2_client_method();\n#endif\n\tapps_startup();\n\tc_Pause=0;\n\tc_quiet=0;\n\tc_ign_eof=0;\n\tc_debug=0;\n\tc_showcerts=0;\n\tif (bio_err == NULL)\n\t\tbio_err=BIO_new_fp(stderr,BIO_NOCLOSE);\n\tif (\t((cbuf=OPENSSL_malloc(BUFSIZZ)) == NULL) ||\n\t\t((sbuf=OPENSSL_malloc(BUFSIZZ)) == NULL))\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n\tverify_depth=0;\n\tverify_error=X509_V_OK;\n#ifdef FIONBIO\n\tc_nbio=0;\n#endif\n\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif\t(strcmp(*argv,"-host") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\thost= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-port") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tport=atoi(*(++argv));\n\t\t\tif (port == 0) goto bad;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-connect") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tif (!extract_host_port(*(++argv),&host,NULL,&port))\n\t\t\t\tgoto bad;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-verify") == 0)\n\t\t\t{\n\t\t\tverify=SSL_VERIFY_PEER;\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tverify_depth=atoi(*(++argv));\n\t\t\tBIO_printf(bio_err,"verify depth is %d\\n",verify_depth);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-cert") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcert_file= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-prexit") == 0)\n\t\t\tprexit=1;\n\t\telse if\t(strcmp(*argv,"-crlf") == 0)\n\t\t\tcrlf=1;\n\t\telse if\t(strcmp(*argv,"-quiet") == 0)\n\t\t\t{\n\t\t\tc_quiet=1;\n\t\t\tc_ign_eof=1;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-ign_eof") == 0)\n\t\t\tc_ign_eof=1;\n\t\telse if\t(strcmp(*argv,"-pause") == 0)\n\t\t\tc_Pause=1;\n\t\telse if\t(strcmp(*argv,"-debug") == 0)\n\t\t\tc_debug=1;\n\t\telse if\t(strcmp(*argv,"-showcerts") == 0)\n\t\t\tc_showcerts=1;\n\t\telse if\t(strcmp(*argv,"-nbio_test") == 0)\n\t\t\tnbio_test=1;\n\t\telse if\t(strcmp(*argv,"-state") == 0)\n\t\t\tstate=1;\n#ifndef NO_SSL2\n\t\telse if\t(strcmp(*argv,"-ssl2") == 0)\n\t\t\tmeth=SSLv2_client_method();\n#endif\n#ifndef NO_SSL3\n\t\telse if\t(strcmp(*argv,"-ssl3") == 0)\n\t\t\tmeth=SSLv3_client_method();\n#endif\n#ifndef NO_TLS1\n\t\telse if\t(strcmp(*argv,"-tls1") == 0)\n\t\t\tmeth=TLSv1_client_method();\n#endif\n\t\telse if (strcmp(*argv,"-bugs") == 0)\n\t\t\tbugs=1;\n\t\telse if\t(strcmp(*argv,"-key") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkey_file= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-reconnect") == 0)\n\t\t\t{\n\t\t\treconnect=5;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-CApath") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCApath= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-CAfile") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-no_tls1") == 0)\n\t\t\toff|=SSL_OP_NO_TLSv1;\n\t\telse if (strcmp(*argv,"-no_ssl3") == 0)\n\t\t\toff|=SSL_OP_NO_SSLv3;\n\t\telse if (strcmp(*argv,"-no_ssl2") == 0)\n\t\t\toff|=SSL_OP_NO_SSLv2;\n\t\telse if\t(strcmp(*argv,"-cipher") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcipher= *(++argv);\n\t\t\t}\n#ifdef FIONBIO\n\t\telse if (strcmp(*argv,"-nbio") == 0)\n\t\t\t{ c_nbio=1; }\n#endif\n\t\telse if\t(strcmp(*argv,"-engine") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tengine_id = *(++argv);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unknown option %s\\n",*argv);\n\t\t\tbadop=1;\n\t\t\tbreak;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (badop)\n\t\t{\nbad:\n\t\tsc_usage();\n\t\tgoto end;\n\t\t}\n\tapp_RAND_load_file(NULL, bio_err, 0);\n\tif (bio_c_out == NULL)\n\t\t{\n\t\tif (c_quiet)\n\t\t\t{\n\t\t\tbio_c_out=BIO_new(BIO_s_null());\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bio_c_out == NULL)\n\t\t\t\tbio_c_out=BIO_new_fp(stdout,BIO_NOCLOSE);\n\t\t\t}\n\t\t}\n\tOpenSSL_add_ssl_algorithms();\n\tSSL_load_error_strings();\n\tif (engine_id != NULL)\n\t\t{\n\t\tif((e = ENGINE_by_id(engine_id)) == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"invalid engine\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (c_debug)\n\t\t\t{\n\t\t\tENGINE_ctrl(e, ENGINE_CTRL_SET_LOGSTREAM,\n\t\t\t\t0, bio_err, 0);\n\t\t\t}\n\t\tif(!ENGINE_set_default(e, ENGINE_METHOD_ALL))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"can\'t use that engine\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tBIO_printf(bio_err,"engine \\"%s\\" set.\\n", engine_id);\n\t\tENGINE_free(e);\n\t\t}\n\tctx=SSL_CTX_new(meth);\n\tif (ctx == NULL)\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (bugs)\n\t\tSSL_CTX_set_options(ctx,SSL_OP_ALL|off);\n\telse\n\t\tSSL_CTX_set_options(ctx,off);\n\tif (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback);\n\tif (cipher != NULL)\n\t\tif(!SSL_CTX_set_cipher_list(ctx,cipher)) {\n\t\tBIO_printf(bio_err,"error setting cipher list\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n#if 0\n\telse\n\t\tSSL_CTX_set_cipher_list(ctx,getenv("SSL_CIPHER"));\n#endif\n\tSSL_CTX_set_verify(ctx,verify,verify_callback);\n\tif (!set_cert_stuff(ctx,cert_file,key_file))\n\t\tgoto end;\n\tif ((!SSL_CTX_load_verify_locations(ctx,CAfile,CApath)) ||\n\t\t(!SSL_CTX_set_default_verify_paths(ctx)))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\t}\n\tcon=SSL_new(ctx);\n#ifndef NO_KRB5\n\tif (con && (con->kssl_ctx = kssl_ctx_new()) != NULL)\n {\n kssl_ctx_setstring(con->kssl_ctx, KSSL_SERVER, host);\n\t\t}\n#endif\nre_start:\n\tif (init_client(&s,host,port) == 0)\n\t\t{\n\t\tBIO_printf(bio_err,"connect:errno=%d\\n",get_last_socket_error());\n\t\tSHUTDOWN(s);\n\t\tgoto end;\n\t\t}\n\tBIO_printf(bio_c_out,"CONNECTED(%08X)\\n",s);\n#ifdef FIONBIO\n\tif (c_nbio)\n\t\t{\n\t\tunsigned long l=1;\n\t\tBIO_printf(bio_c_out,"turning on non blocking io\\n");\n\t\tif (BIO_socket_ioctl(s,FIONBIO,&l) < 0)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n\tif (c_Pause & 0x01) con->debug=1;\n\tsbio=BIO_new_socket(s,BIO_NOCLOSE);\n\tif (nbio_test)\n\t\t{\n\t\tBIO *test;\n\t\ttest=BIO_new(BIO_f_nbio_test());\n\t\tsbio=BIO_push(test,sbio);\n\t\t}\n\tif (c_debug)\n\t\t{\n\t\tcon->debug=1;\n\t\tBIO_set_callback(sbio,bio_dump_cb);\n\t\tBIO_set_callback_arg(sbio,bio_c_out);\n\t\t}\n\tSSL_set_bio(con,sbio,sbio);\n\tSSL_set_connect_state(con);\n\twidth=SSL_get_fd(con)+1;\n\tread_tty=1;\n\twrite_tty=0;\n\ttty_on=0;\n\tread_ssl=1;\n\twrite_ssl=1;\n\tcbuf_len=0;\n\tcbuf_off=0;\n\tsbuf_len=0;\n\tsbuf_off=0;\n\tfor (;;)\n\t\t{\n\t\tFD_ZERO(&readfds);\n\t\tFD_ZERO(&writefds);\n\t\tif (SSL_in_init(con) && !SSL_total_renegotiations(con))\n\t\t\t{\n\t\t\tin_init=1;\n\t\t\ttty_on=0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ttty_on=1;\n\t\t\tif (in_init)\n\t\t\t\t{\n\t\t\t\tin_init=0;\n\t\t\t\tprint_stuff(bio_c_out,con,full_log);\n\t\t\t\tif (full_log > 0) full_log--;\n\t\t\t\tif (reconnect)\n\t\t\t\t\t{\n\t\t\t\t\treconnect--;\n\t\t\t\t\tBIO_printf(bio_c_out,"drop connection and then reconnect\\n");\n\t\t\t\t\tSSL_shutdown(con);\n\t\t\t\t\tSSL_set_connect_state(con);\n\t\t\t\t\tSHUTDOWN(SSL_get_fd(con));\n\t\t\t\t\tgoto re_start;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tssl_pending = read_ssl && SSL_pending(con);\n\t\tif (!ssl_pending)\n\t\t\t{\n#ifndef WINDOWS\n\t\t\tif (tty_on)\n\t\t\t\t{\n\t\t\t\tif (read_tty) FD_SET(fileno(stdin),&readfds);\n\t\t\t\tif (write_tty) FD_SET(fileno(stdout),&writefds);\n\t\t\t\t}\n\t\t\tif (read_ssl)\n\t\t\t\tFD_SET(SSL_get_fd(con),&readfds);\n\t\t\tif (write_ssl)\n\t\t\t\tFD_SET(SSL_get_fd(con),&writefds);\n#else\n\t\t\tif(!tty_on || !write_tty) {\n\t\t\t\tif (read_ssl)\n\t\t\t\t\tFD_SET(SSL_get_fd(con),&readfds);\n\t\t\t\tif (write_ssl)\n\t\t\t\t\tFD_SET(SSL_get_fd(con),&writefds);\n\t\t\t}\n#endif\n#ifdef WINDOWS\n\t\t\ti=0;\n\t\t\tif(!write_tty) {\n\t\t\t\tif(read_tty) {\n\t\t\t\t\ttv.tv_sec = 1;\n\t\t\t\t\ttv.tv_usec = 0;\n\t\t\t\t\ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t\t\t NULL,&tv);\n\t\t\t\t\tif(!i && (!((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0))) || !read_tty) ) continue;\n\t\t\t\t} else \ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t\t NULL,NULL);\n\t\t\t}\n#else\n\t\t\ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t NULL,NULL);\n#endif\n\t\t\tif ( i < 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"bad select %d\\n",\n\t\t\t\tget_last_socket_error());\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\t}\n\t\tif (!ssl_pending && FD_ISSET(SSL_get_fd(con),&writefds))\n\t\t\t{\n\t\t\tk=SSL_write(con,&(cbuf[cbuf_off]),\n\t\t\t\t(unsigned int)cbuf_len);\n\t\t\tswitch (SSL_get_error(con,k))\n\t\t\t\t{\n\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\tcbuf_off+=k;\n\t\t\t\tcbuf_len-=k;\n\t\t\t\tif (k <= 0) goto end;\n\t\t\t\tif (cbuf_len <= 0)\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=1;\n\t\t\t\t\twrite_ssl=0;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=0;\n\t\t\t\t\twrite_ssl=1;\n\t\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tBIO_printf(bio_c_out,"write W BLOCK\\n");\n\t\t\t\twrite_ssl=1;\n\t\t\t\tread_tty=0;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tBIO_printf(bio_c_out,"write R BLOCK\\n");\n\t\t\t\twrite_tty=0;\n\t\t\t\tread_ssl=1;\n\t\t\t\twrite_ssl=0;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\tBIO_printf(bio_c_out,"write X BLOCK\\n");\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\tif (cbuf_len != 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_c_out,"shutdown\\n");\n\t\t\t\t\tgoto shut;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=1;\n\t\t\t\t\twrite_ssl=0;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tif ((k != 0) || (cbuf_len != 0))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"write:errno=%d\\n",\n\t\t\t\t\t\tget_last_socket_error());\n\t\t\t\t\tgoto shut;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=1;\n\t\t\t\t\twrite_ssl=0;\n\t\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\t}\n#ifdef WINDOWS\n\t\telse if (!ssl_pending && write_tty)\n#else\n\t\telse if (!ssl_pending && FD_ISSET(fileno(stdout),&writefds))\n#endif\n\t\t\t{\n#ifdef CHARSET_EBCDIC\n\t\t\tascii2ebcdic(&(sbuf[sbuf_off]),&(sbuf[sbuf_off]),sbuf_len);\n#endif\n\t\t\ti=write(fileno(stdout),&(sbuf[sbuf_off]),sbuf_len);\n\t\t\tif (i <= 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_c_out,"DONE\\n");\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\tsbuf_len-=i;;\n\t\t\tsbuf_off+=i;\n\t\t\tif (sbuf_len <= 0)\n\t\t\t\t{\n\t\t\t\tread_ssl=1;\n\t\t\t\twrite_tty=0;\n\t\t\t\t}\n\t\t\t}\n\t\telse if (ssl_pending || FD_ISSET(SSL_get_fd(con),&readfds))\n\t\t\t{\n#ifdef RENEG\n{ static int iiii; if (++iiii == 52) { SSL_renegotiate(con); iiii=0; } }\n#endif\n#if 1\n\t\t\tk=SSL_read(con,sbuf,1024 );\n#else\n\t\t\tk=SSL_read(con,sbuf,16);\n{ char zbuf[10240];\nprintf("read=%d pending=%d peek=%d\\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240));\n}\n#endif\n\t\t\tswitch (SSL_get_error(con,k))\n\t\t\t\t{\n\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\tif (k <= 0)\n\t\t\t\t\tgoto end;\n\t\t\t\tsbuf_off=0;\n\t\t\t\tsbuf_len=k;\n\t\t\t\tread_ssl=0;\n\t\t\t\twrite_tty=1;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tBIO_printf(bio_c_out,"read W BLOCK\\n");\n\t\t\t\twrite_ssl=1;\n\t\t\t\tread_tty=0;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tBIO_printf(bio_c_out,"read R BLOCK\\n");\n\t\t\t\twrite_tty=0;\n\t\t\t\tread_ssl=1;\n\t\t\t\tif ((read_tty == 0) && (write_ssl == 0))\n\t\t\t\t\twrite_ssl=1;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\tBIO_printf(bio_c_out,"read X BLOCK\\n");\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tBIO_printf(bio_err,"read:errno=%d\\n",get_last_socket_error());\n\t\t\t\tgoto shut;\n\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\tBIO_printf(bio_c_out,"closed\\n");\n\t\t\t\tgoto shut;\n\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\t}\n#ifdef WINDOWS\n\t\telse if ((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0)))\n#else\n\t\telse if (FD_ISSET(fileno(stdin),&readfds))\n#endif\n\t\t\t{\n\t\t\tif (crlf)\n\t\t\t\t{\n\t\t\t\tint j, lf_num;\n\t\t\t\ti=read(fileno(stdin),cbuf,BUFSIZZ/2);\n\t\t\t\tlf_num = 0;\n\t\t\t\tfor (j = 0; j < i; j++)\n\t\t\t\t\tif (cbuf[j] == \'\\n\')\n\t\t\t\t\t\tlf_num++;\n\t\t\t\tfor (j = i-1; j >= 0; j--)\n\t\t\t\t\t{\n\t\t\t\t\tcbuf[j+lf_num] = cbuf[j];\n\t\t\t\t\tif (cbuf[j] == \'\\n\')\n\t\t\t\t\t\t{\n\t\t\t\t\t\tlf_num--;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\tcbuf[j+lf_num] = \'\\r\';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tassert(lf_num == 0);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\ti=read(fileno(stdin),cbuf,BUFSIZZ);\n\t\t\tif ((!c_ign_eof) && ((i <= 0) || (cbuf[0] == \'Q\')))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"DONE\\n");\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\tif ((!c_ign_eof) && (cbuf[0] == \'R\'))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"RENEGOTIATING\\n");\n\t\t\t\tSSL_renegotiate(con);\n\t\t\t\tcbuf_len=0;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tcbuf_len=i;\n\t\t\t\tcbuf_off=0;\n#ifdef CHARSET_EBCDIC\n\t\t\t\tebcdic2ascii(cbuf, cbuf, i);\n#endif\n\t\t\t\t}\n\t\t\twrite_ssl=1;\n\t\t\tread_tty=0;\n\t\t\t}\n\t\t}\nshut:\n\tSSL_shutdown(con);\n\tSHUTDOWN(SSL_get_fd(con));\n\tret=0;\nend:\n\tif(prexit) print_stuff(bio_c_out,con,1);\n\tif (con != NULL) SSL_free(con);\n\tif (con2 != NULL) SSL_free(con2);\n\tif (ctx != NULL) SSL_CTX_free(ctx);\n\tif (cbuf != NULL) { memset(cbuf,0,BUFSIZZ); OPENSSL_free(cbuf); }\n\tif (sbuf != NULL) { memset(sbuf,0,BUFSIZZ); OPENSSL_free(sbuf); }\n\tif (bio_c_out != NULL)\n\t\t{\n\t\tBIO_free(bio_c_out);\n\t\tbio_c_out=NULL;\n\t\t}\n\tEXIT(ret);\n\t}', 'SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)\n\t{\n\tSSL_CTX *ret=NULL;\n\tif (meth == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);\n\t\treturn(NULL);\n\t\t}\n\tif (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);\n\t\tgoto err;\n\t\t}\n\tret=(SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));\n\tif (ret == NULL)\n\t\tgoto err;\n\tmemset(ret,0,sizeof(SSL_CTX));\n\tret->method=meth;\n\tret->cert_store=NULL;\n\tret->session_cache_mode=SSL_SESS_CACHE_SERVER;\n\tret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;\n\tret->session_cache_head=NULL;\n\tret->session_cache_tail=NULL;\n\tret->session_timeout=meth->get_timeout();\n\tret->new_session_cb=NULL;\n\tret->remove_session_cb=NULL;\n\tret->get_session_cb=NULL;\n\tmemset((char *)&ret->stats,0,sizeof(ret->stats));\n\tret->references=1;\n\tret->quiet_shutdown=0;\n\tret->info_callback=NULL;\n\tret->app_verify_callback=NULL;\n\tret->app_verify_arg=NULL;\n\tret->read_ahead=0;\n\tret->verify_mode=SSL_VERIFY_NONE;\n\tret->verify_depth=-1;\n\tret->default_verify_callback=NULL;\n\tif ((ret->cert=ssl_cert_new()) == NULL)\n\t\tgoto err;\n\tret->default_passwd_callback=NULL;\n\tret->default_passwd_callback_userdata=NULL;\n\tret->client_cert_cb=NULL;\n\tret->sessions=lh_new((LHASH_HASH_FN_TYPE)SSL_SESSION_hash,\n\t\t\t(LHASH_COMP_FN_TYPE)SSL_SESSION_cmp);\n\tif (ret->sessions == NULL) goto err;\n\tret->cert_store=X509_STORE_new();\n\tif (ret->cert_store == NULL) goto err;\n\tssl_create_cipher_list(ret->method,\n\t\t&ret->cipher_list,&ret->cipher_list_by_id,\n\t\tSSL_DEFAULT_CIPHER_LIST);\n\tif (ret->cipher_list == NULL\n\t || sk_SSL_CIPHER_num(ret->cipher_list) <= 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->client_CA=sk_X509_NAME_new_null()) == NULL)\n\t\tgoto err;\n\tCRYPTO_new_ex_data(ssl_ctx_meth,(char *)ret,&ret->ex_data);\n\tret->extra_certs=NULL;\n\tret->comp_methods=SSL_COMP_get_compression_methods();\n\treturn(ret);\nerr:\n\tSSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);\nerr2:\n\tif (ret != NULL) SSL_CTX_free(ret);\n\treturn(NULL);\n\t}', 'LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)\n\t{\n\tLHASH *ret;\n\tint i;\n\tif ((ret=(LHASH *)OPENSSL_malloc(sizeof(LHASH))) == NULL)\n\t\tgoto err0;\n\tif ((ret->b=(LHASH_NODE **)OPENSSL_malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)\n\t\tgoto err1;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->b[i]=NULL;\n\tret->comp=((c == NULL)?(LHASH_COMP_FN_TYPE)strcmp:c);\n\tret->hash=((h == NULL)?(LHASH_HASH_FN_TYPE)lh_strhash:h);\n\tret->num_nodes=MIN_NODES/2;\n\tret->num_alloc_nodes=MIN_NODES;\n\tret->p=0;\n\tret->pmax=MIN_NODES/2;\n\tret->up_load=UP_LOAD;\n\tret->down_load=DOWN_LOAD;\n\tret->num_items=0;\n\tret->num_expands=0;\n\tret->num_expand_reallocs=0;\n\tret->num_contracts=0;\n\tret->num_contract_reallocs=0;\n\tret->num_hash_calls=0;\n\tret->num_comp_calls=0;\n\tret->num_insert=0;\n\tret->num_replace=0;\n\tret->num_delete=0;\n\tret->num_no_delete=0;\n\tret->num_retrieve=0;\n\tret->num_retrieve_miss=0;\n\tret->num_hash_comps=0;\n\tret->error=0;\n\treturn(ret);\nerr1:\n\tOPENSSL_free(ret);\nerr0:\n\treturn(NULL);\n\t}', 'SSL *SSL_new(SSL_CTX *ctx)\n\t{\n\tSSL *s;\n\tif (ctx == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);\n\t\treturn(NULL);\n\t\t}\n\tif (ctx->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n\t\treturn(NULL);\n\t\t}\n\ts=(SSL *)OPENSSL_malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\n#ifndef\tNO_KRB5\n\ts->kssl_ctx = kssl_ctx_new();\n#endif\n\tif (ctx->cert != NULL)\n\t\t{\n\t\ts->cert = ssl_cert_dup(ctx->cert);\n\t\tif (s->cert == NULL)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\ts->cert=NULL;\n\ts->sid_ctx_length=ctx->sid_ctx_length;\n\tmemcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));\n\ts->verify_mode=ctx->verify_mode;\n\ts->verify_depth=ctx->verify_depth;\n\ts->verify_callback=ctx->default_verify_callback;\n\ts->purpose = ctx->purpose;\n\ts->trust = ctx->trust;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->ctx=ctx;\n\ts->verify_result=X509_V_OK;\n\ts->method=ctx->method;\n\tif (!s->method->ssl_new(s))\n\t\tgoto err;\n\ts->quiet_shutdown=ctx->quiet_shutdown;\n\ts->references=1;\n\ts->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;\n\ts->options=ctx->options;\n\ts->mode=ctx->mode;\n\ts->read_ahead=ctx->read_ahead;\n\tSSL_clear(s);\n\tCRYPTO_new_ex_data(ssl_meth,s,&s->ex_data);\n\treturn(s);\nerr:\n\tif (s != NULL)\n\t\t{\n\t\tif (s->cert != NULL)\n\t\t\tssl_cert_free(s->cert);\n\t\tif (s->ctx != NULL)\n\t\t\tSSL_CTX_free(s->ctx);\n\t\tOPENSSL_free(s);\n\t\t}\n\tSSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);\n\treturn(NULL);\n\t}', 'int SSL_clear(SSL *s)\n\t{\n\tint state;\n\tif (s->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);\n\t\treturn(0);\n\t\t}\n\ts->error=0;\n\ts->hit=0;\n\ts->shutdown=0;\n#if 0\n\tif (s->new_session) return(1);\n#else\n\tif (s->new_session)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,SSL_R_INTERNAL_ERROR);\n\t\treturn 0;\n\t\t}\n#endif\n\tstate=s->state;\n\ts->type=0;\n\ts->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);\n\ts->version=s->method->version;\n\ts->client_version=s->version;\n\ts->rwstate=SSL_NOTHING;\n\ts->rstate=SSL_ST_READ_HEADER;\n#if 0\n\ts->read_ahead=s->ctx->read_ahead;\n#endif\n\tif (s->init_buf != NULL)\n\t\t{\n\t\tBUF_MEM_free(s->init_buf);\n\t\ts->init_buf=NULL;\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\tif (ssl_clear_bad_session(s))\n\t\t{\n\t\tSSL_SESSION_free(s->session);\n\t\ts->session=NULL;\n\t\t}\n\ts->first_packet=0;\n#if 1\n\tif ((s->session == NULL) && (s->method != s->ctx->method))\n\t\t{\n\t\ts->method->ssl_free(s);\n\t\ts->method=s->ctx->method;\n\t\tif (!s->method->ssl_new(s))\n\t\t\treturn(0);\n\t\t}\n\telse\n#endif\n\t\ts->method->ssl_clear(s);\n\treturn(1);\n\t}', 'int ssl_clear_bad_session(SSL *s)\n\t{\n\tif (\t(s->session != NULL) &&\n\t\t!(s->shutdown & SSL_SENT_SHUTDOWN) &&\n\t\t!(SSL_in_init(s) || SSL_in_before(s)))\n\t\t{\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\t\treturn(1);\n\t\t}\n\telse\n\t\treturn(0);\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,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}', 'void *lh_delete(LHASH *lh, void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *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(ret);\n\t}']
36,533
0
https://github.com/nginx/nginx/blob/e4ecddfdb0d2ffc872658e36028971ad9a873726/src/core/ngx_string.c/#L244
u_char * ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args) { u_char *p, zero, *last; int d; float f, scale; size_t len, slen; int64_t i64; uint64_t ui64; ngx_msec_t ms; ngx_uint_t width, sign, hex, max_width, frac_width, i; ngx_str_t *v; ngx_variable_value_t *vv; if (max == 0) { return buf; } last = buf + max; while (*fmt && buf < last) { if (*fmt == '%') { i64 = 0; ui64 = 0; zero = (u_char) ((*++fmt == '0') ? '0' : ' '); width = 0; sign = 1; hex = 0; max_width = 0; frac_width = 0; slen = (size_t) -1; while (*fmt >= '0' && *fmt <= '9') { width = width * 10 + *fmt++ - '0'; } for ( ;; ) { switch (*fmt) { case 'u': sign = 0; fmt++; continue; case 'm': max_width = 1; fmt++; continue; case 'X': hex = 2; sign = 0; fmt++; continue; case 'x': hex = 1; sign = 0; fmt++; continue; case '.': fmt++; while (*fmt >= '0' && *fmt <= '9') { frac_width = frac_width * 10 + *fmt++ - '0'; } break; case '*': slen = va_arg(args, size_t); fmt++; continue; default: break; } break; } switch (*fmt) { case 'V': v = va_arg(args, ngx_str_t *); len = v->len; len = (buf + len < last) ? len : (size_t) (last - buf); buf = ngx_cpymem(buf, v->data, len); fmt++; continue; case 'v': vv = va_arg(args, ngx_variable_value_t *); len = vv->len; len = (buf + len < last) ? len : (size_t) (last - buf); buf = ngx_cpymem(buf, vv->data, len); fmt++; continue; case 's': p = va_arg(args, u_char *); if (slen == (size_t) -1) { while (*p && buf < last) { *buf++ = *p++; } } else { len = (buf + slen < last) ? slen : (size_t) (last - buf); buf = ngx_cpymem(buf, p, len); } fmt++; continue; case 'O': i64 = (int64_t) va_arg(args, off_t); sign = 1; break; case 'P': i64 = (int64_t) va_arg(args, ngx_pid_t); sign = 1; break; case 'T': i64 = (int64_t) va_arg(args, time_t); sign = 1; break; case 'M': ms = (ngx_msec_t) va_arg(args, ngx_msec_t); if ((ngx_msec_int_t) ms == -1) { sign = 1; i64 = -1; } else { sign = 0; ui64 = (uint64_t) ms; } break; case 'z': if (sign) { i64 = (int64_t) va_arg(args, ssize_t); } else { ui64 = (uint64_t) va_arg(args, size_t); } break; case 'i': if (sign) { i64 = (int64_t) va_arg(args, ngx_int_t); } else { ui64 = (uint64_t) va_arg(args, ngx_uint_t); } if (max_width) { width = NGX_INT_T_LEN; } break; case 'd': if (sign) { i64 = (int64_t) va_arg(args, int); } else { ui64 = (uint64_t) va_arg(args, u_int); } break; case 'l': if (sign) { i64 = (int64_t) va_arg(args, long); } else { ui64 = (uint64_t) va_arg(args, u_long); } break; case 'D': if (sign) { i64 = (int64_t) va_arg(args, int32_t); } else { ui64 = (uint64_t) va_arg(args, uint32_t); } break; case 'L': if (sign) { i64 = va_arg(args, int64_t); } else { ui64 = va_arg(args, uint64_t); } break; case 'A': if (sign) { i64 = (int64_t) va_arg(args, ngx_atomic_int_t); } else { ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t); } if (max_width) { width = NGX_ATOMIC_T_LEN; } break; case 'f': f = (float) va_arg(args, double); if (f < 0) { *buf++ = '-'; f = -f; } ui64 = (int64_t) f; buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width); if (frac_width) { if (buf < last) { *buf++ = '.'; } scale = 1.0; for (i = 0; i < frac_width; i++) { scale *= 10.0; } ui64 = (uint64_t) ((f - (int64_t) ui64) * scale); buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width); } fmt++; continue; #if !(NGX_WIN32) case 'r': i64 = (int64_t) va_arg(args, rlim_t); sign = 1; break; #endif case 'p': ui64 = (uintptr_t) va_arg(args, void *); hex = 2; sign = 0; zero = '0'; width = NGX_PTR_SIZE * 2; break; case 'c': d = va_arg(args, int); *buf++ = (u_char) (d & 0xff); fmt++; continue; case 'Z': *buf++ = '\0'; fmt++; continue; case 'N': #if (NGX_WIN32) *buf++ = CR; #endif *buf++ = LF; fmt++; continue; case '%': *buf++ = '%'; fmt++; continue; default: *buf++ = *fmt++; continue; } if (sign) { if (i64 < 0) { *buf++ = '-'; ui64 = (uint64_t) -i64; } else { ui64 = (uint64_t) i64; } } buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width); fmt++; } else { *buf++ = *fmt++; } } return buf; }
['static ngx_int_t\nngx_epoll_del_connection(ngx_connection_t *c, ngx_uint_t flags)\n{\n int op;\n struct epoll_event ee;\n if (flags & NGX_CLOSE_EVENT) {\n c->read->active = 0;\n c->write->active = 0;\n return NGX_OK;\n }\n ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,\n "epoll del connection: fd:%d", c->fd);\n op = EPOLL_CTL_DEL;\n ee.events = 0;\n ee.data.ptr = NULL;\n if (epoll_ctl(ep, op, c->fd, &ee) == -1) {\n ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,\n "epoll_ctl(%d, %d) failed", op, c->fd);\n return NGX_ERROR;\n }\n c->read->active = 0;\n c->write->active = 0;\n return NGX_OK;\n}', 'void\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, ...)\n#else\nvoid\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, va_list args)\n#endif\n{\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_list args;\n#endif\n u_char errstr[NGX_MAX_ERROR_STR], *p, *last;\n if (log->file->fd == NGX_INVALID_FILE) {\n return;\n }\n last = errstr + NGX_MAX_ERROR_STR;\n ngx_memcpy(errstr, ngx_cached_err_log_time.data,\n ngx_cached_err_log_time.len);\n p = errstr + ngx_cached_err_log_time.len;\n p = ngx_snprintf(p, last - p, " [%s] ", err_levels[level]);\n p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ",\n ngx_log_pid, ngx_log_tid);\n if (log->connection) {\n p = ngx_snprintf(p, last - p, "*%uA ", log->connection);\n }\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_start(args, fmt);\n p = ngx_vsnprintf(p, last - p, fmt, args);\n va_end(args);\n#else\n p = ngx_vsnprintf(p, last - p, fmt, args);\n#endif\n if (err) {\n if (p > last - 50) {\n p = last - 50;\n *p++ = \'.\';\n *p++ = \'.\';\n *p++ = \'.\';\n }\n#if (NGX_WIN32)\n p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)\n ? " (%d: " : " (%Xd: ", err);\n#else\n p = ngx_snprintf(p, last - p, " (%d: ", err);\n#endif\n p = ngx_strerror_r(err, p, last - p);\n if (p < last) {\n *p++ = \')\';\n }\n }\n if (level != NGX_LOG_DEBUG && log->handler) {\n p = log->handler(log, p, last - p);\n }\n if (p > last - NGX_LINEFEED_SIZE) {\n p = last - NGX_LINEFEED_SIZE;\n }\n ngx_linefeed(p);\n (void) ngx_write_fd(log->file->fd, errstr, p - errstr);\n}', 'u_char * ngx_cdecl\nngx_snprintf(u_char *buf, size_t max, const char *fmt, ...)\n{\n u_char *p;\n va_list args;\n va_start(args, fmt);\n p = ngx_vsnprintf(buf, max, fmt, args);\n va_end(args);\n return p;\n}', "u_char *\nngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)\n{\n u_char *p, zero, *last;\n int d;\n float f, scale;\n size_t len, slen;\n int64_t i64;\n uint64_t ui64;\n ngx_msec_t ms;\n ngx_uint_t width, sign, hex, max_width, frac_width, i;\n ngx_str_t *v;\n ngx_variable_value_t *vv;\n if (max == 0) {\n return buf;\n }\n last = buf + max;\n while (*fmt && buf < last) {\n if (*fmt == '%') {\n i64 = 0;\n ui64 = 0;\n zero = (u_char) ((*++fmt == '0') ? '0' : ' ');\n width = 0;\n sign = 1;\n hex = 0;\n max_width = 0;\n frac_width = 0;\n slen = (size_t) -1;\n while (*fmt >= '0' && *fmt <= '9') {\n width = width * 10 + *fmt++ - '0';\n }\n for ( ;; ) {\n switch (*fmt) {\n case 'u':\n sign = 0;\n fmt++;\n continue;\n case 'm':\n max_width = 1;\n fmt++;\n continue;\n case 'X':\n hex = 2;\n sign = 0;\n fmt++;\n continue;\n case 'x':\n hex = 1;\n sign = 0;\n fmt++;\n continue;\n case '.':\n fmt++;\n while (*fmt >= '0' && *fmt <= '9') {\n frac_width = frac_width * 10 + *fmt++ - '0';\n }\n break;\n case '*':\n slen = va_arg(args, size_t);\n fmt++;\n continue;\n default:\n break;\n }\n break;\n }\n switch (*fmt) {\n case 'V':\n v = va_arg(args, ngx_str_t *);\n len = v->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, v->data, len);\n fmt++;\n continue;\n case 'v':\n vv = va_arg(args, ngx_variable_value_t *);\n len = vv->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, vv->data, len);\n fmt++;\n continue;\n case 's':\n p = va_arg(args, u_char *);\n if (slen == (size_t) -1) {\n while (*p && buf < last) {\n *buf++ = *p++;\n }\n } else {\n len = (buf + slen < last) ? slen : (size_t) (last - buf);\n buf = ngx_cpymem(buf, p, len);\n }\n fmt++;\n continue;\n case 'O':\n i64 = (int64_t) va_arg(args, off_t);\n sign = 1;\n break;\n case 'P':\n i64 = (int64_t) va_arg(args, ngx_pid_t);\n sign = 1;\n break;\n case 'T':\n i64 = (int64_t) va_arg(args, time_t);\n sign = 1;\n break;\n case 'M':\n ms = (ngx_msec_t) va_arg(args, ngx_msec_t);\n if ((ngx_msec_int_t) ms == -1) {\n sign = 1;\n i64 = -1;\n } else {\n sign = 0;\n ui64 = (uint64_t) ms;\n }\n break;\n case 'z':\n if (sign) {\n i64 = (int64_t) va_arg(args, ssize_t);\n } else {\n ui64 = (uint64_t) va_arg(args, size_t);\n }\n break;\n case 'i':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_uint_t);\n }\n if (max_width) {\n width = NGX_INT_T_LEN;\n }\n break;\n case 'd':\n if (sign) {\n i64 = (int64_t) va_arg(args, int);\n } else {\n ui64 = (uint64_t) va_arg(args, u_int);\n }\n break;\n case 'l':\n if (sign) {\n i64 = (int64_t) va_arg(args, long);\n } else {\n ui64 = (uint64_t) va_arg(args, u_long);\n }\n break;\n case 'D':\n if (sign) {\n i64 = (int64_t) va_arg(args, int32_t);\n } else {\n ui64 = (uint64_t) va_arg(args, uint32_t);\n }\n break;\n case 'L':\n if (sign) {\n i64 = va_arg(args, int64_t);\n } else {\n ui64 = va_arg(args, uint64_t);\n }\n break;\n case 'A':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_atomic_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);\n }\n if (max_width) {\n width = NGX_ATOMIC_T_LEN;\n }\n break;\n case 'f':\n f = (float) va_arg(args, double);\n if (f < 0) {\n *buf++ = '-';\n f = -f;\n }\n ui64 = (int64_t) f;\n buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);\n if (frac_width) {\n if (buf < last) {\n *buf++ = '.';\n }\n scale = 1.0;\n for (i = 0; i < frac_width; i++) {\n scale *= 10.0;\n }\n ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);\n buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);\n }\n fmt++;\n continue;\n#if !(NGX_WIN32)\n case 'r':\n i64 = (int64_t) va_arg(args, rlim_t);\n sign = 1;\n break;\n#endif\n case 'p':\n ui64 = (uintptr_t) va_arg(args, void *);\n hex = 2;\n sign = 0;\n zero = '0';\n width = NGX_PTR_SIZE * 2;\n break;\n case 'c':\n d = va_arg(args, int);\n *buf++ = (u_char) (d & 0xff);\n fmt++;\n continue;\n case 'Z':\n *buf++ = '\\0';\n fmt++;\n continue;\n case 'N':\n#if (NGX_WIN32)\n *buf++ = CR;\n#endif\n *buf++ = LF;\n fmt++;\n continue;\n case '%':\n *buf++ = '%';\n fmt++;\n continue;\n default:\n *buf++ = *fmt++;\n continue;\n }\n if (sign) {\n if (i64 < 0) {\n *buf++ = '-';\n ui64 = (uint64_t) -i64;\n } else {\n ui64 = (uint64_t) i64;\n }\n }\n buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);\n fmt++;\n } else {\n *buf++ = *fmt++;\n }\n }\n return buf;\n}"]
36,534
0
https://github.com/openssl/openssl/blob/ed371b8cbac0d0349667558c061c1ae380cf75eb/crypto/bn/bn_ctx.c/#L276
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int sm2_sig_verify(const EC_KEY *key, const ECDSA_SIG *sig,\n const BIGNUM *e)\n{\n int ret = 0;\n const EC_GROUP *group = EC_KEY_get0_group(key);\n const BIGNUM *order = EC_GROUP_get0_order(group);\n BN_CTX *ctx = NULL;\n EC_POINT *pt = NULL;\n BIGNUM *t = NULL;\n BIGNUM *x1 = NULL;\n const BIGNUM *r = NULL;\n const BIGNUM *s = NULL;\n ctx = BN_CTX_new();\n pt = EC_POINT_new(group);\n if (ctx == NULL || pt == NULL) {\n SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_MALLOC_FAILURE);\n goto done;\n }\n BN_CTX_start(ctx);\n t = BN_CTX_get(ctx);\n x1 = BN_CTX_get(ctx);\n if (x1 == NULL) {\n SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_MALLOC_FAILURE);\n goto done;\n }\n ECDSA_SIG_get0(sig, &r, &s);\n if (BN_cmp(r, BN_value_one()) < 0\n || BN_cmp(s, BN_value_one()) < 0\n || BN_cmp(order, r) <= 0\n || BN_cmp(order, s) <= 0) {\n SM2err(SM2_F_SM2_SIG_VERIFY, SM2_R_BAD_SIGNATURE);\n goto done;\n }\n if (!BN_mod_add(t, r, s, order, ctx)) {\n SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_BN_LIB);\n goto done;\n }\n if (BN_is_zero(t)) {\n SM2err(SM2_F_SM2_SIG_VERIFY, SM2_R_BAD_SIGNATURE);\n goto done;\n }\n if (!EC_POINT_mul(group, pt, s, EC_KEY_get0_public_key(key), t, ctx)\n || !EC_POINT_get_affine_coordinates(group, pt, x1, NULL, ctx)) {\n SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_EC_LIB);\n goto done;\n }\n if (!BN_mod_add(t, e, x1, order, ctx)) {\n SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_BN_LIB);\n goto done;\n }\n if (BN_cmp(r, t) == 0)\n ret = 1;\n done:\n EC_POINT_free(pt);\n BN_CTX_free(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("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_EXIT(ctx);\n}', 'int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n if (!BN_add(r, a, b))\n return 0;\n return BN_nnmod(r, r, m, ctx);\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}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("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_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
36,535
0
https://github.com/libav/libav/blob/a1c1c7801918c46da5525cfddb99f3467c522b02/libavcodec/rv40.c/#L603
static void rv40_loop_filter(RV34DecContext *r, int row) { MpegEncContext *s = &r->s; int mb_pos, mb_x; int i, j, k; uint8_t *Y, *C; int alpha, beta, betaY, betaC; int q; int mbtype[4]; int mb_strong[4]; int clip[4]; int cbp[4]; int uvcbp[4][2]; int mvmasks[4]; mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int mbtype = s->current_picture_ptr->mb_type[mb_pos]; if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype)) r->cbp_luma [mb_pos] = 0xFFFF; if(IS_INTRA(mbtype)) r->cbp_chroma[mb_pos] = 0xFF; } mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int y_h_deblock, y_v_deblock; int c_v_deblock[2], c_h_deblock[2]; int clip_left; int avail[4]; int y_to_deblock, c_to_deblock[2]; q = s->current_picture_ptr->qscale_table[mb_pos]; alpha = rv40_alpha_tab[q]; beta = rv40_beta_tab [q]; betaY = betaC = beta * 3; if(s->width * s->height <= 176*144) betaY += beta; avail[0] = 1; avail[1] = row; avail[2] = mb_x; avail[3] = row < s->mb_height - 1; for(i = 0; i < 4; i++){ if(avail[i]){ int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride; mvmasks[i] = r->deblock_coefs[pos]; mbtype [i] = s->current_picture_ptr->mb_type[pos]; cbp [i] = r->cbp_luma[pos]; uvcbp[i][0] = r->cbp_chroma[pos] & 0xF; uvcbp[i][1] = r->cbp_chroma[pos] >> 4; }else{ mvmasks[i] = 0; mbtype [i] = mbtype[0]; cbp [i] = 0; uvcbp[i][0] = uvcbp[i][1] = 0; } mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]); clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q]; } y_to_deblock = cbp[POS_CUR] | (cbp[POS_BOTTOM] << 16) | mvmasks[POS_CUR] | (mvmasks[POS_BOTTOM] << 16); y_h_deblock = y_to_deblock | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW) | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12); y_v_deblock = y_to_deblock | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL) | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3); if(!mb_x) y_v_deblock &= ~MASK_Y_LEFT_COL; if(!row) y_h_deblock &= ~MASK_Y_TOP_ROW; if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])) y_h_deblock &= ~(MASK_Y_TOP_ROW << 16); for(i = 0; i < 2; i++){ c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i]; c_v_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL) | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1); c_h_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2) | (uvcbp[POS_CUR][i] << 2); if(!mb_x) c_v_deblock[i] &= ~MASK_C_LEFT_COL; if(!row) c_h_deblock[i] &= ~MASK_C_TOP_ROW; if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]) c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4); } for(j = 0; j < 16; j += 4){ Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize; for(i = 0; i < 4; i++, Y += 4){ int ij = i + j; int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0; int dither = j ? ij : i*4; if(y_h_deblock & (MASK_BOTTOM << ij)){ rv40_h_loop_filter(Y+4*s->linesize, s->linesize, dither, y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0, clip_cur, alpha, beta, betaY, 0, 0); } if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; else clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; rv40_v_loop_filter(Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 0); } if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ rv40_h_loop_filter(Y, s->linesize, dither, clip_cur, (cbp[POS_TOP] | mvmasks[POS_TOP]) & (MASK_TOP << i) ? clip[POS_TOP] : 0, alpha, beta, betaY, 0, 1); } if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; rv40_v_loop_filter(Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 1); } } } for(k = 0; k < 2; k++){ for(j = 0; j < 2; j++){ C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize; for(i = 0; i < 2; i++, C += 4){ int ij = i + j*2; int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0; if(c_h_deblock[k] & (MASK_CUR << (ij+2))){ int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0; rv40_h_loop_filter(C+4*s->uvlinesize, s->uvlinesize, i*8, clip_bot, clip_cur, alpha, beta, betaC, 1, 0); } if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; else clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; rv40_v_loop_filter(C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 0); } if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0; rv40_h_loop_filter(C, s->uvlinesize, i*8, clip_cur, clip_top, alpha, beta, betaC, 1, 1); } if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; rv40_v_loop_filter(C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 1); } } } } } }
['static void rv40_loop_filter(RV34DecContext *r, int row)\n{\n MpegEncContext *s = &r->s;\n int mb_pos, mb_x;\n int i, j, k;\n uint8_t *Y, *C;\n int alpha, beta, betaY, betaC;\n int q;\n int mbtype[4];\n int mb_strong[4];\n int clip[4];\n int cbp[4];\n int uvcbp[4][2];\n int mvmasks[4];\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int mbtype = s->current_picture_ptr->mb_type[mb_pos];\n if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))\n r->cbp_luma [mb_pos] = 0xFFFF;\n if(IS_INTRA(mbtype))\n r->cbp_chroma[mb_pos] = 0xFF;\n }\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int y_h_deblock, y_v_deblock;\n int c_v_deblock[2], c_h_deblock[2];\n int clip_left;\n int avail[4];\n int y_to_deblock, c_to_deblock[2];\n q = s->current_picture_ptr->qscale_table[mb_pos];\n alpha = rv40_alpha_tab[q];\n beta = rv40_beta_tab [q];\n betaY = betaC = beta * 3;\n if(s->width * s->height <= 176*144)\n betaY += beta;\n avail[0] = 1;\n avail[1] = row;\n avail[2] = mb_x;\n avail[3] = row < s->mb_height - 1;\n for(i = 0; i < 4; i++){\n if(avail[i]){\n int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;\n mvmasks[i] = r->deblock_coefs[pos];\n mbtype [i] = s->current_picture_ptr->mb_type[pos];\n cbp [i] = r->cbp_luma[pos];\n uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;\n uvcbp[i][1] = r->cbp_chroma[pos] >> 4;\n }else{\n mvmasks[i] = 0;\n mbtype [i] = mbtype[0];\n cbp [i] = 0;\n uvcbp[i][0] = uvcbp[i][1] = 0;\n }\n mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);\n clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];\n }\n y_to_deblock = cbp[POS_CUR]\n | (cbp[POS_BOTTOM] << 16)\n | mvmasks[POS_CUR]\n | (mvmasks[POS_BOTTOM] << 16);\n y_h_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)\n | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);\n y_v_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)\n | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);\n if(!mb_x)\n y_v_deblock &= ~MASK_Y_LEFT_COL;\n if(!row)\n y_h_deblock &= ~MASK_Y_TOP_ROW;\n if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]))\n y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);\n for(i = 0; i < 2; i++){\n c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];\n c_v_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)\n | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);\n c_h_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)\n | (uvcbp[POS_CUR][i] << 2);\n if(!mb_x)\n c_v_deblock[i] &= ~MASK_C_LEFT_COL;\n if(!row)\n c_h_deblock[i] &= ~MASK_C_TOP_ROW;\n if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])\n c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);\n }\n for(j = 0; j < 16; j += 4){\n Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize;\n for(i = 0; i < 4; i++, Y += 4){\n int ij = i + j;\n int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n int dither = j ? ij : i*4;\n if(y_h_deblock & (MASK_BOTTOM << ij)){\n rv40_h_loop_filter(Y+4*s->linesize, s->linesize, dither,\n y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,\n clip_cur,\n alpha, beta, betaY, 0, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n else\n clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_v_loop_filter(Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 0);\n }\n if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n rv40_h_loop_filter(Y, s->linesize, dither,\n clip_cur,\n (cbp[POS_TOP] | mvmasks[POS_TOP]) & (MASK_TOP << i) ? clip[POS_TOP] : 0,\n alpha, beta, betaY, 0, 1);\n }\n if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n rv40_v_loop_filter(Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 1);\n }\n }\n }\n for(k = 0; k < 2; k++){\n for(j = 0; j < 2; j++){\n C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;\n for(i = 0; i < 2; i++, C += 4){\n int ij = i + j*2;\n int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n if(c_h_deblock[k] & (MASK_CUR << (ij+2))){\n int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;\n rv40_h_loop_filter(C+4*s->uvlinesize, s->uvlinesize, i*8,\n clip_bot,\n clip_cur,\n alpha, beta, betaC, 1, 0);\n }\n if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n else\n clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_v_loop_filter(C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 0);\n }\n if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;\n rv40_h_loop_filter(C, s->uvlinesize, i*8,\n clip_cur,\n clip_top,\n alpha, beta, betaC, 1, 1);\n }\n if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n rv40_v_loop_filter(C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 1);\n }\n }\n }\n }\n }\n}']
36,536
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 open_input_stream(HTTPContext *c, const char *info)\n{\n char buf[128];\n char input_filename[1024];\n AVFormatContext *s = NULL;\n int buf_size, i, ret;\n int64_t stream_pos;\n if (c->stream->feed) {\n strcpy(input_filename, c->stream->feed->feed_filename);\n buf_size = FFM_PACKET_SIZE;\n if (av_find_info_tag(buf, sizeof(buf), "date", info)) {\n if ((ret = av_parse_time(&stream_pos, buf, 0)) < 0)\n return ret;\n } else if (av_find_info_tag(buf, sizeof(buf), "buffer", info)) {\n int prebuffer = strtol(buf, 0, 10);\n stream_pos = av_gettime() - prebuffer * (int64_t)1000000;\n } else\n stream_pos = av_gettime() - c->stream->prebuffer * (int64_t)1000;\n } else {\n strcpy(input_filename, c->stream->feed_filename);\n buf_size = 0;\n if (av_find_info_tag(buf, sizeof(buf), "date", info)) {\n if ((ret = av_parse_time(&stream_pos, buf, 1)) < 0)\n return ret;\n } else\n stream_pos = 0;\n }\n if (input_filename[0] == \'\\0\')\n return -1;\n if ((ret = avformat_open_input(&s, input_filename, c->stream->ifmt, &c->stream->in_opts)) < 0) {\n http_log("could not open %s: %d\\n", input_filename, ret);\n return -1;\n }\n s->flags |= AVFMT_FLAG_GENPTS;\n c->fmt_in = s;\n if (strcmp(s->iformat->name, "ffm") && av_find_stream_info(c->fmt_in) < 0) {\n http_log("Could not find stream info \'%s\'\\n", input_filename);\n av_close_input_file(s);\n return -1;\n }\n for(i=0;i<s->nb_streams;i++)\n open_parser(s, i);\n c->pts_stream_index = 0;\n for(i=0;i<c->stream->nb_streams;i++) {\n if (c->pts_stream_index == 0 &&\n c->stream->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n c->pts_stream_index = i;\n }\n }\n if (c->fmt_in->iformat->read_seek)\n av_seek_frame(c->fmt_in, -1, stream_pos, 0);\n c->start_time = cur_time;\n c->first_pts = AV_NOPTS_VALUE;\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}']
36,537
0
https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/bn/bn_add.c/#L227
int BN_usub(BIGNUM *r, BIGNUM *a, BIGNUM *b) { int max,min; register BN_ULONG t1,t2,*ap,*bp,*rp; int i,carry; #if defined(IRIX_CC_BUG) && !defined(LINT) int dummy; #endif bn_check_top(a); bn_check_top(b); if (a->top < b->top) { BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3); return(0); } max=a->top; min=b->top; if (bn_wexpand(r,max) == NULL) return(0); ap=a->d; bp=b->d; rp=r->d; #if 1 carry=0; for (i=0; i<min; i++) { t1= *(ap++); t2= *(bp++); if (carry) { carry=(t1 <= t2); t1=(t1-t2-1)&BN_MASK2; } else { carry=(t1 < t2); t1=(t1-t2)&BN_MASK2; } #if defined(IRIX_CC_BUG) && !defined(LINT) dummy=t1; #endif *(rp++)=t1&BN_MASK2; } #else carry=bn_sub_words(rp,ap,bp,min); ap+=min; bp+=min; rp+=min; i=min; #endif if (carry) { while (i < max) { i++; t1= *(ap++); t2=(t1-1)&BN_MASK2; *(rp++)=t2; if (t1 > t2) break; } } #if 0 memcpy(rp,ap,sizeof(*rp)*(max-i)); #else if (rp != ap) { for (;;) { if (i++ >= max) break; rp[0]=ap[0]; if (i++ >= max) break; rp[1]=ap[1]; if (i++ >= max) break; rp[2]=ap[2]; if (i++ >= max) break; rp[3]=ap[3]; rp+=4; ap+=4; } } #endif r->top=max; bn_fix_top(r); return(1); }
['int test_div_recp(BIO *bp, BN_CTX *ctx)\n\t{\n\tBIGNUM a,b,c,d;\n\tBN_RECP_CTX recp;\n\tint i;\n\tint j;\n\tBN_RECP_CTX_init(&recp);\n\tBN_init(&a);\n\tBN_init(&b);\n\tBN_init(&c);\n\tBN_init(&d);\n\tBN_rand(&a,400,0,0);\n\tfor (i=0; i<100; i++)\n\t\t{\n\t\tBN_rand(&b,50+i,0,0);\n\t\ta.neg=rand_neg();\n\t\tb.neg=rand_neg();\n\t\tBN_RECP_CTX_set(&recp,&b,ctx);\n\t\tif (bp == NULL)\n\t\t\tfor (j=0; j<100; j++)\n\t\t\t\tBN_div_recp(&d,&c,&a,&recp,ctx);\n\t\tBN_div_recp(&d,&c,&a,&recp,ctx);\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\t}\n\t\t\tBN_print(bp,&d);\n\t\t\tBIO_puts(bp,"\\n");\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\t}\n\t\t\tBN_print(bp,&c);\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_RECP_CTX_free(&recp);\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_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,\n\t BN_CTX *ctx)\n\t{\n\tint i,j,tos,ret=0,ex;\n\tBIGNUM *a,*b,*d,*r;\n\ttos=ctx->tos;\n\ta= &(ctx->bn[ctx->tos++]);\n\tb= &(ctx->bn[ctx->tos++]);\n\tif (dv != NULL)\n\t\td=dv;\n\telse\n\t\td= &(ctx->bn[ctx->tos++]);\n\tif (rem != NULL)\n\t\tr=rem;\n\telse\n\t\tr= &(ctx->bn[ctx->tos++]);\n\tif (BN_ucmp(m,&(recp->N)) < 0)\n\t\t{\n\t\tBN_zero(d);\n\t\tBN_copy(r,m);\n\t\tctx->tos=tos;\n\t\treturn(1);\n\t\t}\n\ti=BN_num_bits(m);\n\tj=recp->num_bits*2;\n\tif (j > i)\n\t\t{\n\t\ti=j;\n\t\tex=0;\n\t\t}\n\telse\n\t\t{\n\t\tex=(i-j)/2;\n\t\t}\n\tj=i/2;\n\tif (i != recp->shift)\n\t\trecp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),\n\t\t\ti,ctx);\n\tif (!BN_rshift(a,m,j-ex)) goto err;\n\tif (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;\n\tif (!BN_rshift(d,b,j+ex)) 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\tj=0;\n#if 1\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_MOD_MUL_RECIPROCAL,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\tctx->tos=tos;\n\treturn(ret);\n\t}', 'int BN_ucmp(BIGNUM *a, BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG t1,t2,*ap,*bp;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\ti=a->top-b->top;\n\tif (i != 0) return(i);\n\tap=a->d;\n\tbp=b->d;\n\tfor (i=a->top-1; i>=0; i--)\n\t\t{\n\t\tt1= ap[i];\n\t\tt2= bp[i];\n\t\tif (t1 != t2)\n\t\t\treturn(t1 > t2?1:-1);\n\t\t}\n\treturn(0);\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}', 'int BN_usub(BIGNUM *r, BIGNUM *a, BIGNUM *b)\n\t{\n\tint max,min;\n\tregister BN_ULONG t1,t2,*ap,*bp,*rp;\n\tint i,carry;\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\tint dummy;\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tif (a->top < b->top)\n\t\t{\n\t\tBNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);\n\t\treturn(0);\n\t\t}\n\tmax=a->top;\n\tmin=b->top;\n\tif (bn_wexpand(r,max) == NULL) return(0);\n\tap=a->d;\n\tbp=b->d;\n\trp=r->d;\n#if 1\n\tcarry=0;\n\tfor (i=0; i<min; i++)\n\t\t{\n\t\tt1= *(ap++);\n\t\tt2= *(bp++);\n\t\tif (carry)\n\t\t\t{\n\t\t\tcarry=(t1 <= t2);\n\t\t\tt1=(t1-t2-1)&BN_MASK2;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tcarry=(t1 < t2);\n\t\t\tt1=(t1-t2)&BN_MASK2;\n\t\t\t}\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\t\tdummy=t1;\n#endif\n\t\t*(rp++)=t1&BN_MASK2;\n\t\t}\n#else\n\tcarry=bn_sub_words(rp,ap,bp,min);\n\tap+=min;\n\tbp+=min;\n\trp+=min;\n\ti=min;\n#endif\n\tif (carry)\n\t\t{\n\t\twhile (i < max)\n\t\t\t{\n\t\t\ti++;\n\t\t\tt1= *(ap++);\n\t\t\tt2=(t1-1)&BN_MASK2;\n\t\t\t*(rp++)=t2;\n\t\t\tif (t1 > t2) break;\n\t\t\t}\n\t\t}\n#if 0\n\tmemcpy(rp,ap,sizeof(*rp)*(max-i));\n#else\n\tif (rp != ap)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tif (i++ >= max) break;\n\t\t\trp[0]=ap[0];\n\t\t\tif (i++ >= max) break;\n\t\t\trp[1]=ap[1];\n\t\t\tif (i++ >= max) break;\n\t\t\trp[2]=ap[2];\n\t\t\tif (i++ >= max) break;\n\t\t\trp[3]=ap[3];\n\t\t\trp+=4;\n\t\t\tap+=4;\n\t\t\t}\n\t\t}\n#endif\n\tr->top=max;\n\tbn_fix_top(r);\n\treturn(1);\n\t}']
36,538
0
https://github.com/openssl/openssl/blob/ed371b8cbac0d0349667558c061c1ae380cf75eb/crypto/bn/bn_ctx.c/#L276
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int rsa_ossl_public_encrypt(int flen, const unsigned char *from,\n unsigned char *to, RSA *rsa, int padding)\n{\n BIGNUM *f, *ret;\n int i, num = 0, r = -1;\n unsigned char *buf = NULL;\n BN_CTX *ctx = NULL;\n if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);\n return -1;\n }\n if (BN_ucmp(rsa->n, rsa->e) <= 0) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);\n return -1;\n }\n if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS) {\n if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);\n return -1;\n }\n }\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n f = BN_CTX_get(ctx);\n ret = BN_CTX_get(ctx);\n num = BN_num_bytes(rsa->n);\n buf = OPENSSL_malloc(num);\n if (ret == NULL || buf == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n switch (padding) {\n case RSA_PKCS1_PADDING:\n i = RSA_padding_add_PKCS1_type_2(buf, num, from, flen);\n break;\n case RSA_PKCS1_OAEP_PADDING:\n i = RSA_padding_add_PKCS1_OAEP(buf, num, from, flen, NULL, 0);\n break;\n case RSA_SSLV23_PADDING:\n i = RSA_padding_add_SSLv23(buf, num, from, flen);\n break;\n case RSA_NO_PADDING:\n i = RSA_padding_add_none(buf, num, from, flen);\n break;\n default:\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE);\n goto err;\n }\n if (i <= 0)\n goto err;\n if (BN_bin2bn(buf, num, f) == NULL)\n goto err;\n if (BN_ucmp(f, rsa->n) >= 0) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT,\n RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n goto err;\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 (!rsa->meth->bn_mod_exp(ret, f, rsa->e, rsa->n, ctx,\n rsa->_method_mod_n))\n goto err;\n r = BN_bn2binpad(ret, to, num);\n err:\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n OPENSSL_clear_free(buf, num);\n return r;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("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_EXIT(ctx);\n}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock,\n const BIGNUM *mod, BN_CTX *ctx)\n{\n BN_MONT_CTX *ret;\n CRYPTO_THREAD_read_lock(lock);\n ret = *pmont;\n CRYPTO_THREAD_unlock(lock);\n if (ret)\n return ret;\n ret = BN_MONT_CTX_new();\n if (ret == NULL)\n return NULL;\n if (!BN_MONT_CTX_set(ret, mod, ctx)) {\n BN_MONT_CTX_free(ret);\n return NULL;\n }\n CRYPTO_THREAD_write_lock(lock);\n if (*pmont) {\n BN_MONT_CTX_free(ret);\n ret = *pmont;\n } else\n *pmont = ret;\n CRYPTO_THREAD_unlock(lock);\n return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int i, 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 if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\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 if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\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_is_one(&tmod))\n BN_zero(Ri);\n else 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_is_one(&tmod))\n BN_zero(Ri);\n else 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 for (i = mont->RR.top, ret = mont->N.top; i < ret; i++)\n mont->RR.d[i] = 0;\n mont->RR.top = ret;\n mont->RR.flags |= BN_FLG_FIXED_TOP;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', '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 (BN_abs_is_word(n, 1) || BN_is_zero(n)) {\n if (pnoinv != NULL)\n *pnoinv = 1;\n return NULL;\n }\n if (pnoinv != NULL)\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}', '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}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("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_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
36,539
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 ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,\n BN_CTX *ctx)\n{\n int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *,\n const BIGNUM *, BN_CTX *);\n int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);\n const BIGNUM *p;\n BN_CTX *new_ctx = NULL;\n BIGNUM *rh, *tmp, *Z4, *Z6;\n int ret = -1;\n if (EC_POINT_is_at_infinity(group, point))\n return 1;\n field_mul = group->meth->field_mul;\n field_sqr = group->meth->field_sqr;\n p = group->field;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return -1;\n }\n BN_CTX_start(ctx);\n rh = BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n Z4 = BN_CTX_get(ctx);\n Z6 = BN_CTX_get(ctx);\n if (Z6 == NULL)\n goto err;\n if (!field_sqr(group, rh, point->X, ctx))\n goto err;\n if (!point->Z_is_one) {\n if (!field_sqr(group, tmp, point->Z, ctx))\n goto err;\n if (!field_sqr(group, Z4, tmp, ctx))\n goto err;\n if (!field_mul(group, Z6, Z4, tmp, ctx))\n goto err;\n if (group->a_is_minus3) {\n if (!BN_mod_lshift1_quick(tmp, Z4, p))\n goto err;\n if (!BN_mod_add_quick(tmp, tmp, Z4, p))\n goto err;\n if (!BN_mod_sub_quick(rh, rh, tmp, p))\n goto err;\n if (!field_mul(group, rh, rh, point->X, ctx))\n goto err;\n } else {\n if (!field_mul(group, tmp, Z4, group->a, ctx))\n goto err;\n if (!BN_mod_add_quick(rh, rh, tmp, p))\n goto err;\n if (!field_mul(group, rh, rh, point->X, ctx))\n goto err;\n }\n if (!field_mul(group, tmp, group->b, Z6, ctx))\n goto err;\n if (!BN_mod_add_quick(rh, rh, tmp, p))\n goto err;\n } else {\n if (!BN_mod_add_quick(rh, rh, group->a, p))\n goto err;\n if (!field_mul(group, rh, rh, point->X, ctx))\n goto err;\n if (!BN_mod_add_quick(rh, rh, group->b, p))\n goto err;\n }\n if (!field_sqr(group, tmp, point->Y, ctx))\n goto err;\n ret = (0 == BN_ucmp(tmp, rh));\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\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}', 'int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m)\n{\n if (!BN_lshift1(r, a))\n return 0;\n bn_check_top(r);\n if (BN_cmp(r, m) >= 0)\n return BN_sub(r, r, m);\n return 1;\n}', 'int BN_lshift1(BIGNUM *r, const BIGNUM *a)\n{\n register BN_ULONG *ap, *rp, t, c;\n int i;\n bn_check_top(r);\n bn_check_top(a);\n if (r != a) {\n r->neg = a->neg;\n if (bn_wexpand(r, a->top + 1) == NULL)\n return 0;\n r->top = a->top;\n } else {\n if (bn_wexpand(r, a->top + 1) == NULL)\n return 0;\n }\n ap = a->d;\n rp = r->d;\n c = 0;\n for (i = 0; i < a->top; i++) {\n t = *(ap++);\n *(rp++) = ((t << 1) | c) & BN_MASK2;\n c = (t & BN_TBIT) ? 1 : 0;\n }\n if (c) {\n *rp = 1;\n r->top++;\n }\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}']
36,540
0
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_lib.c/#L231
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 DH *get_dh512(void)\n{\n static unsigned char dh512_p[] = {\n 0xCB, 0xC8, 0xE1, 0x86, 0xD0, 0x1F, 0x94, 0x17, 0xA6, 0x99, 0xF0,\n 0xC6,\n 0x1F, 0x0D, 0xAC, 0xB6, 0x25, 0x3E, 0x06, 0x39, 0xCA, 0x72, 0x04,\n 0xB0,\n 0x6E, 0xDA, 0xC0, 0x61, 0xE6, 0x7A, 0x77, 0x25, 0xE8, 0x3B, 0xB9,\n 0x5F,\n 0x9A, 0xB6, 0xB5, 0xFE, 0x99, 0x0B, 0xA1, 0x93, 0x4E, 0x35, 0x33,\n 0xB8,\n 0xE1, 0xF1, 0x13, 0x4F, 0x59, 0x1A, 0xD2, 0x57, 0xC0, 0x26, 0x21,\n 0x33,\n 0x02, 0xC5, 0xAE, 0x23,\n };\n static unsigned char dh512_g[] = {\n 0x02,\n };\n DH *dh;\n BIGNUM *p, *g;\n if ((dh = DH_new()) == NULL)\n return NULL;\n p = BN_bin2bn(dh512_p, sizeof(dh512_p), NULL);\n g = BN_bin2bn(dh512_g, sizeof(dh512_g), NULL);\n if ((p == NULL) || (g == NULL) || !DH_set0_pqg(dh, p, NULL, g)) {\n DH_free(dh);\n BN_free(p);\n BN_free(g);\n return NULL;\n }\n return dh;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return NULL;\n bn_check_top(ret);\n for ( ; len > 0 && *s == 0; s++, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return ret;\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n l = (l << 8L) | *(s++);\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\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}']
36,541
0
https://github.com/openssl/openssl/blob/3a66e306e45215b2dac68f66eb6b1012a94f17e5/crypto/evp/evp_pbe.c/#L126
int EVP_PBE_alg_add (int nid, EVP_CIPHER *cipher, EVP_MD *md, EVP_PBE_KEYGEN *keygen) { EVP_PBE_CTL *pbe_tmp; if (!pbe_algs) pbe_algs = sk_new (pbe_cmp); if (!(pbe_tmp = (EVP_PBE_CTL*) Malloc (sizeof(EVP_PBE_CTL)))) { EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE); return 0; } pbe_tmp->pbe_nid = nid; pbe_tmp->cipher = cipher; pbe_tmp->md = md; pbe_tmp->keygen = keygen; sk_push (pbe_algs, (char *)pbe_tmp); return 1; }
['int EVP_PBE_alg_add (int nid, EVP_CIPHER *cipher, EVP_MD *md,\n\t EVP_PBE_KEYGEN *keygen)\n{\n\tEVP_PBE_CTL *pbe_tmp;\n\tif (!pbe_algs) pbe_algs = sk_new (pbe_cmp);\n\tif (!(pbe_tmp = (EVP_PBE_CTL*) Malloc (sizeof(EVP_PBE_CTL)))) {\n\t\tEVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);\n\t\treturn 0;\n\t}\n\tpbe_tmp->pbe_nid = nid;\n\tpbe_tmp->cipher = cipher;\n\tpbe_tmp->md = md;\n\tpbe_tmp->keygen = keygen;\n\tsk_push (pbe_algs, (char *)pbe_tmp);\n\treturn 1;\n}', 'STACK *sk_new(int (*c)())\n\t{\n\tSTACK *ret;\n\tint i;\n\tif ((ret=(STACK *)Malloc(sizeof(STACK))) == NULL)\n\t\tgoto err0;\n\tif ((ret->data=(char **)Malloc(sizeof(char *)*MIN_NODES)) == NULL)\n\t\tgoto err1;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->data[i]=NULL;\n\tret->comp=c;\n\tret->num_alloc=MIN_NODES;\n\tret->num=0;\n\tret->sorted=0;\n\treturn(ret);\nerr1:\n\tFree((char *)ret);\nerr0:\n\treturn(NULL);\n\t}', 'int sk_push(STACK *st, char *data)\n\t{\n\treturn(sk_insert(st,data,st->num));\n\t}']
36,542
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_mul.c/#L1072
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; } }
['int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d;\n BIGNUM *val[TABLE_SIZE];\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_SIMPLE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return -1;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (!d || !val[0])\n goto err;\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul(d, val[0], val[0], m, 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(val[i], val[i - 1], d, m, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul(r, r, r, m, ctx))\n goto err;\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(r, r, r, m, ctx))\n goto err;\n }\n if (!BN_mod_mul(r, r, val[wvalue >> 1], m, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\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}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\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 rr->neg = a->neg ^ b->neg;\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 bn_correct_top(rr);\n if (r != rr)\n BN_copy(r, rr);\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}']
36,543
0
https://github.com/libav/libav/blob/a893655bdaa726a82424367b6456d195be12ebbc/libavcodec/indeo3.c/#L192
static av_cold int allocate_frame_buffers(Indeo3DecodeContext *ctx, AVCodecContext *avctx) { int p, luma_width, luma_height, chroma_width, chroma_height; int luma_pitch, chroma_pitch, luma_size, chroma_size; luma_width = ctx->width; luma_height = ctx->height; if (luma_width < 16 || luma_width > 640 || luma_height < 16 || luma_height > 480 || luma_width & 3 || luma_height & 3) { av_log(avctx, AV_LOG_ERROR, "Invalid picture dimensions: %d x %d!\n", luma_width, luma_height); return AVERROR_INVALIDDATA; } chroma_width = FFALIGN(luma_width >> 2, 4); chroma_height = FFALIGN(luma_height >> 2, 4); luma_pitch = FFALIGN(luma_width, 16); chroma_pitch = FFALIGN(chroma_width, 16); luma_size = luma_pitch * (luma_height + 1); chroma_size = chroma_pitch * (chroma_height + 1); for (p = 0; p < 3; p++) { ctx->planes[p].pitch = !p ? luma_pitch : chroma_pitch; ctx->planes[p].width = !p ? luma_width : chroma_width; ctx->planes[p].height = !p ? luma_height : chroma_height; ctx->planes[p].buffers[0] = av_malloc(!p ? luma_size : chroma_size); ctx->planes[p].buffers[1] = av_malloc(!p ? luma_size : chroma_size); memset(ctx->planes[p].buffers[0], 0x40, ctx->planes[p].pitch); memset(ctx->planes[p].buffers[1], 0x40, ctx->planes[p].pitch); ctx->planes[p].pixels[0] = ctx->planes[p].buffers[0] + ctx->planes[p].pitch; ctx->planes[p].pixels[1] = ctx->planes[p].buffers[1] + ctx->planes[p].pitch; memset(ctx->planes[p].pixels[0], 0, ctx->planes[p].pitch * ctx->planes[p].height); memset(ctx->planes[p].pixels[1], 0, ctx->planes[p].pitch * ctx->planes[p].height); } return 0; }
['static av_cold int allocate_frame_buffers(Indeo3DecodeContext *ctx,\n AVCodecContext *avctx)\n{\n int p, luma_width, luma_height, chroma_width, chroma_height;\n int luma_pitch, chroma_pitch, luma_size, chroma_size;\n luma_width = ctx->width;\n luma_height = ctx->height;\n if (luma_width < 16 || luma_width > 640 ||\n luma_height < 16 || luma_height > 480 ||\n luma_width & 3 || luma_height & 3) {\n av_log(avctx, AV_LOG_ERROR, "Invalid picture dimensions: %d x %d!\\n",\n luma_width, luma_height);\n return AVERROR_INVALIDDATA;\n }\n chroma_width = FFALIGN(luma_width >> 2, 4);\n chroma_height = FFALIGN(luma_height >> 2, 4);\n luma_pitch = FFALIGN(luma_width, 16);\n chroma_pitch = FFALIGN(chroma_width, 16);\n luma_size = luma_pitch * (luma_height + 1);\n chroma_size = chroma_pitch * (chroma_height + 1);\n for (p = 0; p < 3; p++) {\n ctx->planes[p].pitch = !p ? luma_pitch : chroma_pitch;\n ctx->planes[p].width = !p ? luma_width : chroma_width;\n ctx->planes[p].height = !p ? luma_height : chroma_height;\n ctx->planes[p].buffers[0] = av_malloc(!p ? luma_size : chroma_size);\n ctx->planes[p].buffers[1] = av_malloc(!p ? luma_size : chroma_size);\n memset(ctx->planes[p].buffers[0], 0x40, ctx->planes[p].pitch);\n memset(ctx->planes[p].buffers[1], 0x40, ctx->planes[p].pitch);\n ctx->planes[p].pixels[0] = ctx->planes[p].buffers[0] + ctx->planes[p].pitch;\n ctx->planes[p].pixels[1] = ctx->planes[p].buffers[1] + ctx->planes[p].pitch;\n memset(ctx->planes[p].pixels[0], 0, ctx->planes[p].pitch * ctx->planes[p].height);\n memset(ctx->planes[p].pixels[1], 0, ctx->planes[p].pitch * ctx->planes[p].height);\n }\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}']
36,544
0
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/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 h261_resync(H261Context *h)\n{\n MpegEncContext *const s = &h->s;\n int left, ret;\n if (h->gob_start_code_skipped) {\n ret = h261_decode_gob_header(h);\n if (ret >= 0)\n return 0;\n } else {\n if (bitstream_peek(&s->bc, 15) == 0) {\n ret = h261_decode_gob_header(h);\n if (ret >= 0)\n return 0;\n }\n s->bc = s->last_resync_bc;\n bitstream_align(&s->bc);\n left = bitstream_bits_left(&s->bc);\n for (; left > 15 + 1 + 4 + 5; left -= 8) {\n if (bitstream_peek(&s->bc, 15) == 0) {\n BitstreamContext bak = s->bc;\n ret = h261_decode_gob_header(h);\n if (ret >= 0)\n return 0;\n s->bc = bak;\n }\n bitstream_skip(&s->bc, 8);\n }\n }\n return -1;\n}', 'static int h261_decode_gob_header(H261Context *h)\n{\n unsigned int val;\n MpegEncContext *const s = &h->s;\n if (!h->gob_start_code_skipped) {\n val = bitstream_peek(&s->bc, 15);\n if (val)\n return -1;\n bitstream_skip(&s->bc, 16);\n }\n h->gob_start_code_skipped = 0;\n h->gob_number = bitstream_read(&s->bc, 4);\n s->qscale = bitstream_read(&s->bc, 5);\n if (s->mb_height == 18) {\n if ((h->gob_number <= 0) || (h->gob_number > 12))\n return -1;\n } else {\n if ((h->gob_number != 1) && (h->gob_number != 3) &&\n (h->gob_number != 5))\n return -1;\n }\n while (bitstream_read_bit(&s->bc) != 0)\n bitstream_skip(&s->bc, 8);\n if (s->qscale == 0) {\n av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\\n");\n if (s->avctx->err_recognition & AV_EF_BITSTREAM)\n return -1;\n }\n h->current_mba = 0;\n h->mba_diff = 0;\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 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 skip_remaining(bc, bc->bits_left);\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}']
36,545
0
https://github.com/openssl/openssl/blob/a4cefc86c820d3894ca960857ba4e7cf8e2014b0/test/handshake_helper.c/#L89
static void info_cb(const SSL *s, int where, int ret) { if (where & SSL_CB_ALERT) { HANDSHAKE_EX_DATA *ex_data = (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx)); if (where & SSL_CB_WRITE) { ex_data->alert_sent = ret; if (strcmp(SSL_alert_type_string(ret), "F") == 0 || strcmp(SSL_alert_desc_string(ret), "CN") == 0) ex_data->num_fatal_alerts_sent++; } else { ex_data->alert_received = ret; } } }
['static void info_cb(const SSL *s, int where, int ret)\n{\n if (where & SSL_CB_ALERT) {\n HANDSHAKE_EX_DATA *ex_data =\n (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n if (where & SSL_CB_WRITE) {\n ex_data->alert_sent = ret;\n if (strcmp(SSL_alert_type_string(ret), "F") == 0\n || strcmp(SSL_alert_desc_string(ret), "CN") == 0)\n ex_data->num_fatal_alerts_sent++;\n } else {\n ex_data->alert_received = ret;\n }\n }\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}']
36,546
0
https://github.com/openssl/openssl/blob/47bbaa5b607f592009ed40f5678fde21c10a873c/crypto/bn/bn_ctx.c/#L328
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *x, *y;\n int ret = 0;\n if (point->Z_is_one || EC_POINT_is_at_infinity(group, point))\n return 1;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n BN_CTX_start(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto err;\n if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx))\n goto err;\n if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))\n goto err;\n if (!point->Z_is_one) {\n ECerr(EC_F_EC_GFP_SIMPLE_MAKE_AFFINE, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("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_EXIT(ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("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_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
36,547
0
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/des/des_enc.c/#L144
void des_encrypt(DES_LONG *data, des_key_schedule ks, int enc) { register DES_LONG l,r,t,u; #ifdef DES_PTR register const unsigned char *des_SP=(const unsigned char *)des_SPtrans; #endif #ifndef DES_UNROLL register int i; #endif register DES_LONG *s; r=data[0]; l=data[1]; IP(r,l); r=ROTATE(r,29)&0xffffffffL; l=ROTATE(l,29)&0xffffffffL; s=(DES_LONG *)ks; if (enc) { #ifdef DES_UNROLL D_ENCRYPT(l,r, 0); D_ENCRYPT(r,l, 2); D_ENCRYPT(l,r, 4); D_ENCRYPT(r,l, 6); D_ENCRYPT(l,r, 8); D_ENCRYPT(r,l,10); D_ENCRYPT(l,r,12); D_ENCRYPT(r,l,14); D_ENCRYPT(l,r,16); D_ENCRYPT(r,l,18); D_ENCRYPT(l,r,20); D_ENCRYPT(r,l,22); D_ENCRYPT(l,r,24); D_ENCRYPT(r,l,26); D_ENCRYPT(l,r,28); D_ENCRYPT(r,l,30); #else for (i=0; i<32; i+=8) { D_ENCRYPT(l,r,i+0); D_ENCRYPT(r,l,i+2); D_ENCRYPT(l,r,i+4); D_ENCRYPT(r,l,i+6); } #endif } else { #ifdef DES_UNROLL D_ENCRYPT(l,r,30); D_ENCRYPT(r,l,28); D_ENCRYPT(l,r,26); D_ENCRYPT(r,l,24); D_ENCRYPT(l,r,22); D_ENCRYPT(r,l,20); D_ENCRYPT(l,r,18); D_ENCRYPT(r,l,16); D_ENCRYPT(l,r,14); D_ENCRYPT(r,l,12); D_ENCRYPT(l,r,10); D_ENCRYPT(r,l, 8); D_ENCRYPT(l,r, 6); D_ENCRYPT(r,l, 4); D_ENCRYPT(l,r, 2); D_ENCRYPT(r,l, 0); #else for (i=30; i>0; i-=8) { D_ENCRYPT(l,r,i-0); D_ENCRYPT(r,l,i-2); D_ENCRYPT(l,r,i-4); D_ENCRYPT(r,l,i-6); } #endif } l=ROTATE(l,3)&0xffffffffL; r=ROTATE(r,3)&0xffffffffL; FP(r,l); data[0]=l; data[1]=r; l=r=t=u=0; }
['void des_string_to_key(const char *str, des_cblock *key)\n\t{\n\tdes_key_schedule ks;\n\tint i,length;\n\tregister unsigned char j;\n\tmemset(key,0,8);\n\tlength=strlen(str);\n#ifdef OLD_STR_TO_KEY\n\tfor (i=0; i<length; i++)\n\t\t(*key)[i%8]^=(str[i]<<1);\n#else\n\tfor (i=0; i<length; i++)\n\t\t{\n\t\tj=str[i];\n\t\tif ((i%16) < 8)\n\t\t\t(*key)[i%8]^=(j<<1);\n\t\telse\n\t\t\t{\n\t\t\tj=((j<<4)&0xf0)|((j>>4)&0x0f);\n\t\t\tj=((j<<2)&0xcc)|((j>>2)&0x33);\n\t\t\tj=((j<<1)&0xaa)|((j>>1)&0x55);\n\t\t\t(*key)[7-(i%8)]^=j;\n\t\t\t}\n\t\t}\n#endif\n\tdes_set_odd_parity(key);\n\ti=des_check_key;\n\tdes_check_key=0;\n\tdes_set_key(key,ks);\n\tdes_check_key=i;\n\tdes_cbc_cksum((unsigned char*)str,key,length,ks,key);\n\tmemset(ks,0,sizeof(ks));\n\tdes_set_odd_parity(key);\n\t}', 'DES_LONG des_cbc_cksum(const unsigned char *in, des_cblock *output,\n\t\tlong length,\n\t\tdes_key_schedule schedule, const_des_cblock *ivec)\n\t{\n\tregister DES_LONG tout0,tout1,tin0,tin1;\n\tregister long l=length;\n\tDES_LONG tin[2];\n\tunsigned char *out = &(*output)[0];\n\tconst unsigned char *iv = &(*ivec)[0];\n\tc2l(iv,tout0);\n\tc2l(iv,tout1);\n\tfor (; l>0; l-=8)\n\t\t{\n\t\tif (l >= 8)\n\t\t\t{\n\t\t\tc2l(in,tin0);\n\t\t\tc2l(in,tin1);\n\t\t\t}\n\t\telse\n\t\t\tc2ln(in,tin0,tin1,l);\n\t\ttin0^=tout0; tin[0]=tin0;\n\t\ttin1^=tout1; tin[1]=tin1;\n\t\tdes_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);\n\t\ttout0=tin[0];\n\t\ttout1=tin[1];\n\t\t}\n\tif (out != NULL)\n\t\t{\n\t\tl2c(tout0,out);\n\t\tl2c(tout1,out);\n\t\t}\n\ttout0=tin0=tin1=tin[0]=tin[1]=0;\n\treturn(tout1);\n\t}', 'void des_encrypt(DES_LONG *data, des_key_schedule ks, int enc)\n\t{\n\tregister DES_LONG l,r,t,u;\n#ifdef DES_PTR\n\tregister const unsigned char *des_SP=(const unsigned char *)des_SPtrans;\n#endif\n#ifndef DES_UNROLL\n\tregister int i;\n#endif\n\tregister DES_LONG *s;\n\tr=data[0];\n\tl=data[1];\n\tIP(r,l);\n\tr=ROTATE(r,29)&0xffffffffL;\n\tl=ROTATE(l,29)&0xffffffffL;\n\ts=(DES_LONG *)ks;\n\tif (enc)\n\t\t{\n#ifdef DES_UNROLL\n\t\tD_ENCRYPT(l,r, 0);\n\t\tD_ENCRYPT(r,l, 2);\n\t\tD_ENCRYPT(l,r, 4);\n\t\tD_ENCRYPT(r,l, 6);\n\t\tD_ENCRYPT(l,r, 8);\n\t\tD_ENCRYPT(r,l,10);\n\t\tD_ENCRYPT(l,r,12);\n\t\tD_ENCRYPT(r,l,14);\n\t\tD_ENCRYPT(l,r,16);\n\t\tD_ENCRYPT(r,l,18);\n\t\tD_ENCRYPT(l,r,20);\n\t\tD_ENCRYPT(r,l,22);\n\t\tD_ENCRYPT(l,r,24);\n\t\tD_ENCRYPT(r,l,26);\n\t\tD_ENCRYPT(l,r,28);\n\t\tD_ENCRYPT(r,l,30);\n#else\n\t\tfor (i=0; i<32; i+=8)\n\t\t\t{\n\t\t\tD_ENCRYPT(l,r,i+0);\n\t\t\tD_ENCRYPT(r,l,i+2);\n\t\t\tD_ENCRYPT(l,r,i+4);\n\t\t\tD_ENCRYPT(r,l,i+6);\n\t\t\t}\n#endif\n\t\t}\n\telse\n\t\t{\n#ifdef DES_UNROLL\n\t\tD_ENCRYPT(l,r,30);\n\t\tD_ENCRYPT(r,l,28);\n\t\tD_ENCRYPT(l,r,26);\n\t\tD_ENCRYPT(r,l,24);\n\t\tD_ENCRYPT(l,r,22);\n\t\tD_ENCRYPT(r,l,20);\n\t\tD_ENCRYPT(l,r,18);\n\t\tD_ENCRYPT(r,l,16);\n\t\tD_ENCRYPT(l,r,14);\n\t\tD_ENCRYPT(r,l,12);\n\t\tD_ENCRYPT(l,r,10);\n\t\tD_ENCRYPT(r,l, 8);\n\t\tD_ENCRYPT(l,r, 6);\n\t\tD_ENCRYPT(r,l, 4);\n\t\tD_ENCRYPT(l,r, 2);\n\t\tD_ENCRYPT(r,l, 0);\n#else\n\t\tfor (i=30; i>0; i-=8)\n\t\t\t{\n\t\t\tD_ENCRYPT(l,r,i-0);\n\t\t\tD_ENCRYPT(r,l,i-2);\n\t\t\tD_ENCRYPT(l,r,i-4);\n\t\t\tD_ENCRYPT(r,l,i-6);\n\t\t\t}\n#endif\n\t\t}\n\tl=ROTATE(l,3)&0xffffffffL;\n\tr=ROTATE(r,3)&0xffffffffL;\n\tFP(r,l);\n\tdata[0]=l;\n\tdata[1]=r;\n\tl=r=t=u=0;\n\t}']
36,548
0
https://github.com/libav/libav/blob/df84d7d9bdf6b8e6896c711880f130b72738c828/libavcodec/mpegaudiodec.c/#L911
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]) { register MPA_INT *synth_buf; register const MPA_INT *w, *w2, *p; int j, offset; OUT_INT *samples2; #if FRAC_BITS <= 15 int32_t tmp[32]; int sum, sum2; #else int64_t sum, sum2; #endif offset = *synth_buf_offset; synth_buf = synth_buf_ptr + offset; #if FRAC_BITS <= 15 dct32(tmp, sb_samples); for(j=0;j<32;j++) { synth_buf[j] = av_clip_int16(tmp[j]); } #else dct32(synth_buf, sb_samples); #endif 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 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 int32_t sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n register const MPA_INT *w, *w2, *p;\n int j, offset;\n OUT_INT *samples2;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15\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 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}']
36,549
0
https://github.com/libav/libav/blob/d6e49096c0c3c10ffb176761b0da150c93bedbf6/libavformat/utils.c/#L2612
void avformat_free_context(AVFormatContext *s) { int i; if (!s) return; 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++) free_stream(&s->streams[i]); 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 void mov_free(AVFormatContext *s)\n{\n MOVMuxContext *mov = s->priv_data;\n int i;\n if (mov->chapter_track)\n avcodec_parameters_free(&mov->tracks[mov->chapter_track].par);\n for (i = 0; i < mov->nb_streams; i++) {\n if (mov->tracks[i].tag == MKTAG('r','t','p',' '))\n ff_mov_close_hinting(&mov->tracks[i]);\n av_freep(&mov->tracks[i].cluster);\n av_freep(&mov->tracks[i].frag_info);\n if (mov->tracks[i].vos_len)\n av_free(mov->tracks[i].vos_data);\n }\n av_freep(&mov->tracks);\n}", 'void avcodec_parameters_free(AVCodecParameters **ppar)\n{\n AVCodecParameters *par = *ppar;\n if (!par)\n return;\n codec_parameters_reset(par);\n av_freep(ppar);\n}', 'void ff_mov_close_hinting(MOVTrack *track)\n{\n AVFormatContext *rtp_ctx = track->rtp_ctx;\n avcodec_parameters_free(&track->par);\n sample_queue_free(&track->sample_queue);\n if (!rtp_ctx)\n return;\n if (rtp_ctx->pb) {\n av_write_trailer(rtp_ctx);\n ffio_free_dyn_buf(&rtp_ctx->pb);\n }\n avformat_free_context(rtp_ctx);\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i;\n if (!s)\n return;\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 free_stream(&s->streams[i]);\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}']
36,550
0
https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_ctx.c/#L276
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['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}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("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_EXIT(ctx);\n}', 'int bn_from_mont_fixed_top(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n int retn = 0;\n#ifdef MONT_WORD\n BIGNUM *t;\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) && BN_copy(t, a)) {\n retn = bn_from_montgomery_word(ret, t, mont);\n }\n BN_CTX_end(ctx);\n#else\n BIGNUM *t1, *t2;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n t2 = BN_CTX_get(ctx);\n if (t2 == NULL)\n goto err;\n if (!BN_copy(t1, a))\n goto err;\n BN_mask_bits(t1, mont->ri);\n if (!BN_mul(t2, t1, &mont->Ni, ctx))\n goto err;\n BN_mask_bits(t2, mont->ri);\n if (!BN_mul(t1, t2, &mont->N, ctx))\n goto err;\n if (!BN_add(t2, a, t1))\n goto err;\n if (!BN_rshift(ret, t2, mont->ri))\n goto err;\n if (BN_ucmp(ret, &(mont->N)) >= 0) {\n if (!BN_usub(ret, ret, &(mont->N)))\n goto err;\n }\n retn = 1;\n bn_check_top(ret);\n err:\n BN_CTX_end(ctx);\n#endif\n return retn;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("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_EXIT(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_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, wmask, window0;\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 = p->top * BN_BITS2;\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 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 (!a->neg) {\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 }\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_mont_fixed_top(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(&am, a, m, ctx))\n goto err;\n if (!bn_to_mont_fixed_top(&am, &am, mont, ctx))\n goto err;\n } else if (!bn_to_mont_fixed_top(&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 window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits > 0) {\n if (bits < stride)\n stride = bits;\n bits -= stride;\n wvalue = bn_get_bits(p, bits);\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 window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7) {\n while (bits > 0) {\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 bn_get_bits5(p->d, bits -= 5));\n }\n } else {\n while (bits > 0) {\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\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_mul_mont_fixed_top(&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_mul_mont_fixed_top(&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 window0 = (bits - 1) % window + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n wmask = (1 << window) - 1;\n while (bits > 0) {\n for (i = 0; i < window; i++)\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n bits -= window;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!bn_mul_mont_fixed_top(&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_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}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
36,551
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L357
static void pred4x4_horizontal_up_rv40_c(uint8_t *src, uint8_t *topright, int stride){ LOAD_LEFT_EDGE LOAD_DOWN_LEFT_EDGE LOAD_TOP_EDGE LOAD_TOP_RIGHT_EDGE src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3; src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3; src[2+0*stride]= src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3; src[3+0*stride]= src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3; src[2+1*stride]= src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3; src[3+1*stride]= src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3; src[3+2*stride]= src[1+3*stride]=(l3 + 2*l4 + l5 + 2)>>2; src[0+3*stride]= src[2+2*stride]=(t6 + t7 + l3 + l4 + 2)>>2; src[2+3*stride]=(l4 + l5 + 1)>>1; src[3+3*stride]=(l4 + 2*l5 + l6 + 2)>>2; }
['static void pred4x4_horizontal_up_rv40_c(uint8_t *src, uint8_t *topright, int stride){\n LOAD_LEFT_EDGE\n LOAD_DOWN_LEFT_EDGE\n LOAD_TOP_EDGE\n LOAD_TOP_RIGHT_EDGE\n src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3;\n src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3;\n src[2+0*stride]=\n src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3;\n src[3+0*stride]=\n src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3;\n src[2+1*stride]=\n src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3;\n src[3+1*stride]=\n src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3;\n src[3+2*stride]=\n src[1+3*stride]=(l3 + 2*l4 + l5 + 2)>>2;\n src[0+3*stride]=\n src[2+2*stride]=(t6 + t7 + l3 + l4 + 2)>>2;\n src[2+3*stride]=(l4 + l5 + 1)>>1;\n src[3+3*stride]=(l4 + 2*l5 + l6 + 2)>>2;\n}']
36,552
0
https://github.com/openssl/openssl/blob/18e1e302452e6dea4500b6f981cee7e151294dea/crypto/bn/bn_ctx.c/#L340
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while (num--) { bn_check_top(p->current->vals + offset); if (offset == 0) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x,\n const BIGNUM *p, BN_CTX *ctx)\n{\n BIGNUM *xinv = NULL;\n int ret = 0;\n bn_check_top(y);\n bn_check_top(x);\n bn_check_top(p);\n BN_CTX_start(ctx);\n xinv = BN_CTX_get(ctx);\n if (xinv == NULL)\n goto err;\n if (!BN_GF2m_mod_inv(xinv, x, p, ctx))\n goto err;\n if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx))\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_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n BIGNUM *b = NULL;\n int ret = 0;\n BN_CTX_start(ctx);\n if ((b = BN_CTX_get(ctx)) == NULL)\n goto err;\n do {\n if (!BN_priv_rand(b, BN_num_bits(p) - 1,\n BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY))\n goto err;\n } while (BN_is_zero(b));\n if (!BN_GF2m_mod_mul(r, a, b, p, ctx))\n goto err;\n if (!BN_GF2m_mod_inv_vartime(r, r, p, ctx))\n goto err;\n if (!BN_GF2m_mod_mul(r, r, b, p, ctx))\n goto err;\n ret = 1;\n err:\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}', 'int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n const BIGNUM *p, BN_CTX *ctx)\n{\n int ret = 0;\n const int max = BN_num_bits(p) + 1;\n int *arr = NULL;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(p);\n if ((arr = OPENSSL_malloc(sizeof(*arr) * max)) == NULL)\n goto err;\n ret = BN_GF2m_poly2arr(p, arr, max);\n if (!ret || ret > max) {\n BNerr(BN_F_BN_GF2M_MOD_MUL, BN_R_INVALID_LENGTH);\n goto err;\n }\n ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);\n bn_check_top(r);\n err:\n OPENSSL_free(arr);\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_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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG("ENTER 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 ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG("LEAVE BN_CTX_get()", ctx);\n return ret;\n}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (offset == 0) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
36,553
0
https://github.com/openssl/openssl/blob/84c15db551ce1d167b901a3bde2b21880b084384/crypto/bn/bn_asm.c/#L161
BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) { BN_ULONG c=0; BN_ULONG bl,bh; bn_check_num(num); if (num <= 0) return((BN_ULONG)0); bl=LBITS(w); bh=HBITS(w); for (;;) { mul_add(rp[0],ap[0],bl,bh,c); if (--num == 0) break; mul_add(rp[1],ap[1],bl,bh,c); if (--num == 0) break; mul_add(rp[2],ap[2],bl,bh,c); if (--num == 0) break; mul_add(rp[3],ap[3],bl,bh,c); if (--num == 0) break; ap+=4; rp+=4; } return(c); }
['int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *aa;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_RECP_CTX recp;\n\taa= &(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\tBN_RECP_CTX_init(&recp);\n\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_mod(&(val[0]),a,m,ctx)) goto err;\n\tif (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))\n\t\tgoto err;\n\tif (bits <= 17)\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_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,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\tif (!BN_one(r)) 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\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\tgoto err;\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_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,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\tret=1;\nerr:\n\tctx->tos--;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\tBN_RECP_CTX_free(&recp);\n\treturn(ret);\n\t}', 'int BN_mod(BIGNUM *rem, const BIGNUM *m, const 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, const BIGNUM *num, const 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_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_RECP_CTX *recp,\n\t BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tBIGNUM *a;\n\ta= &(ctx->bn[ctx->tos++]);\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\t}\n\telse\n\t\ta=x;\n\tBN_div_recp(NULL,r,a,recp,ctx);\n\tret=1;\nerr:\n\tctx->tos--;\n\treturn(ret);\n\t}', 'int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx)\n\t{\n\tint max,al;\n\tBIGNUM *tmp,*rr;\n#ifdef BN_COUNT\nprintf("BN_sqr %d * %d\\n",a->top,a->top);\n#endif\n\tbn_check_top(a);\n\ttmp= &(ctx->bn[ctx->tos]);\n\trr=(a != r)?r: (&ctx->bn[ctx->tos+1]);\n\tal=a->top;\n\tif (al <= 0)\n\t\t{\n\t\tr->top=0;\n\t\treturn(1);\n\t\t}\n\tmax=(al+al);\n\tif (bn_wexpand(rr,max+1) == NULL) return(0);\n\tr->neg=0;\n\tif (al == 4)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[8];\n\t\tbn_sqr_normal(rr->d,a->d,4,t);\n#else\n\t\tbn_sqr_comba4(rr->d,a->d);\n#endif\n\t\t}\n\telse if (al == 8)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[16];\n\t\tbn_sqr_normal(rr->d,a->d,8,t);\n#else\n\t\tbn_sqr_comba8(rr->d,a->d);\n#endif\n\t\t}\n\telse\n\t\t{\n#if defined(BN_RECURSION)\n\t\tif (al < BN_SQR_RECURSIVE_SIZE_NORMAL)\n\t\t\t{\n\t\t\tBN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];\n\t\t\tbn_sqr_normal(rr->d,a->d,al,t);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tint j,k;\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(a,k*2) == NULL) return(0);\n\t\t\t\tif (bn_wexpand(tmp,k*2) == NULL) return(0);\n\t\t\t\tbn_sqr_recursive(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,max) == NULL) return(0);\n\t\t\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\t}\n#else\n\t\tif (bn_wexpand(tmp,max) == NULL) return(0);\n\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n#endif\n\t\t}\n\trr->top=max;\n\tif ((max > 0) && (rr->d[max-1] == 0)) rr->top--;\n\tif (rr != r) BN_copy(r,rr);\n\treturn(1);\n\t}', 'void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp)\n\t{\n\tint i,j,max;\n\tBN_ULONG *ap,*rp;\n\tmax=n*2;\n\tap=a;\n\trp=r;\n\trp[0]=rp[max-1]=0;\n\trp++;\n\tj=n;\n\tif (--j > 0)\n\t\t{\n\t\tap++;\n\t\trp[j]=bn_mul_words(rp,ap,j,ap[-1]);\n\t\trp+=2;\n\t\t}\n\tfor (i=n-2; i>0; i--)\n\t\t{\n\t\tj--;\n\t\tap++;\n\t\trp[j]=bn_mul_add_words(rp,ap,j,ap[-1]);\n\t\trp+=2;\n\t\t}\n\tbn_add_words(r,r,r,max);\n\tbn_sqr_words(tmp,a,n);\n\tbn_add_words(r,r,tmp,max);\n\t}', 'BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)\n\t{\n\tBN_ULONG c=0;\n\tBN_ULONG bl,bh;\n\tbn_check_num(num);\n\tif (num <= 0) return((BN_ULONG)0);\n\tbl=LBITS(w);\n\tbh=HBITS(w);\n\tfor (;;)\n\t\t{\n\t\tmul_add(rp[0],ap[0],bl,bh,c);\n\t\tif (--num == 0) break;\n\t\tmul_add(rp[1],ap[1],bl,bh,c);\n\t\tif (--num == 0) break;\n\t\tmul_add(rp[2],ap[2],bl,bh,c);\n\t\tif (--num == 0) break;\n\t\tmul_add(rp[3],ap[3],bl,bh,c);\n\t\tif (--num == 0) break;\n\t\tap+=4;\n\t\trp+=4;\n\t\t}\n\treturn(c);\n\t}']
36,554
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L352
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_malloc(words * sizeof(*a)); else a = A = OPENSSL_malloc(words * sizeof(*a)); if (A == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } #ifdef PURIFY memset(a, 0, sizeof(*a) * words); #endif #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); }
['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, b, bits1, bits2, ret =\n 0, wpos1, wpos2, window1, window2, wvalue1, wvalue2;\n int r_is_one = 1;\n BIGNUM *d, *r;\n const BIGNUM *a_mod_m;\n BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n bn_check_top(a1);\n bn_check_top(p1);\n bn_check_top(a2);\n bn_check_top(p2);\n bn_check_top(m);\n if (!(m->d[0] & 1)) {\n BNerr(BN_F_BN_MOD_EXP2_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n bits1 = BN_num_bits(p1);\n bits2 = BN_num_bits(p2);\n if ((bits1 == 0) && (bits2 == 0)) {\n ret = BN_one(rr);\n return ret;\n }\n bits = (bits1 > bits2) ? bits1 : bits2;\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val1[0] = BN_CTX_get(ctx);\n val2[0] = BN_CTX_get(ctx);\n if (!d || !r || !val1[0] || !val2[0])\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 window1 = BN_window_bits_for_exponent_size(bits1);\n window2 = BN_window_bits_for_exponent_size(bits2);\n if (a1->neg || BN_ucmp(a1, m) >= 0) {\n if (!BN_mod(val1[0], a1, m, ctx))\n goto err;\n a_mod_m = val1[0];\n } else\n a_mod_m = a1;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx))\n goto err;\n if (window1 > 1) {\n if (!BN_mod_mul_montgomery(d, val1[0], val1[0], mont, ctx))\n goto err;\n j = 1 << (window1 - 1);\n for (i = 1; i < j; i++) {\n if (((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val1[i], val1[i - 1], d, mont, ctx))\n goto err;\n }\n }\n if (a2->neg || BN_ucmp(a2, m) >= 0) {\n if (!BN_mod(val2[0], a2, m, ctx))\n goto err;\n a_mod_m = val2[0];\n } else\n a_mod_m = a2;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val2[0], a_mod_m, mont, ctx))\n goto err;\n if (window2 > 1) {\n if (!BN_mod_mul_montgomery(d, val2[0], val2[0], mont, ctx))\n goto err;\n j = 1 << (window2 - 1);\n for (i = 1; i < j; i++) {\n if (((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val2[i], val2[i - 1], d, mont, ctx))\n goto err;\n }\n }\n r_is_one = 1;\n wvalue1 = 0;\n wvalue2 = 0;\n wpos1 = 0;\n wpos2 = 0;\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (b = bits - 1; b >= 0; b--) {\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!wvalue1)\n if (BN_is_bit_set(p1, b)) {\n i = b - window1 + 1;\n while (!BN_is_bit_set(p1, i))\n i++;\n wpos1 = i;\n wvalue1 = 1;\n for (i = b - 1; i >= wpos1; i--) {\n wvalue1 <<= 1;\n if (BN_is_bit_set(p1, i))\n wvalue1++;\n }\n }\n if (!wvalue2)\n if (BN_is_bit_set(p2, b)) {\n i = b - window2 + 1;\n while (!BN_is_bit_set(p2, i))\n i++;\n wpos2 = i;\n wvalue2 = 1;\n for (i = b - 1; i >= wpos2; i--) {\n wvalue2 <<= 1;\n if (BN_is_bit_set(p2, i))\n wvalue2++;\n }\n }\n if (wvalue1 && b == wpos1) {\n if (!BN_mod_mul_montgomery(r, r, val1[wvalue1 >> 1], mont, ctx))\n goto err;\n wvalue1 = 0;\n r_is_one = 0;\n }\n if (wvalue2 && b == wpos2) {\n if (!BN_mod_mul_montgomery(r, r, val2[wvalue2 >> 1], mont, ctx))\n goto err;\n wvalue2 = 0;\n r_is_one = 0;\n }\n }\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}', '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}', '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 tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == 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 res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\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 if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--, resp--) {\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# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\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# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\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 = 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 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}', '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, *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_malloc(words * sizeof(*a));\n else\n a = A = OPENSSL_malloc(words * sizeof(*a));\n if (A == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n#ifdef PURIFY\n memset(a, 0, sizeof(*a) * words);\n#endif\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}']
36,555
0
https://github.com/libav/libav/blob/0ca0924c10d9617a5793964bf79655424ef32b68/libavcodec/vp3.c/#L806
static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) { int j, k, sb_x, sb_y; int coding_mode; int motion_x[4]; int motion_y[4]; int last_motion_x = 0; int last_motion_y = 0; int prior_last_motion_x = 0; int prior_last_motion_y = 0; int current_macroblock; int current_fragment; int frag; if (s->keyframe) return 0; coding_mode = get_bits1(gb); for (sb_y = 0; sb_y < s->y_superblock_height; sb_y++) { for (sb_x = 0; sb_x < s->y_superblock_width; sb_x++) { if (get_bits_left(gb) <= 0) return -1; for (j = 0; j < 4; j++) { int mb_x = 2 * sb_x + (j >> 1); int mb_y = 2 * sb_y + (((j >> 1) + j) & 1); current_macroblock = mb_y * s->macroblock_width + mb_x; if (mb_x >= s->macroblock_width || mb_y >= s->macroblock_height || s->macroblock_coding[current_macroblock] == MODE_COPY) continue; switch (s->macroblock_coding[current_macroblock]) { case MODE_INTER_PLUS_MV: case MODE_GOLDEN_MV: if (coding_mode == 0) { motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; } else { motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)]; motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)]; } if (s->macroblock_coding[current_macroblock] == MODE_INTER_PLUS_MV) { prior_last_motion_x = last_motion_x; prior_last_motion_y = last_motion_y; last_motion_x = motion_x[0]; last_motion_y = motion_y[0]; } break; case MODE_INTER_FOURMV: prior_last_motion_x = last_motion_x; prior_last_motion_y = last_motion_y; for (k = 0; k < 4; k++) { current_fragment = BLOCK_Y * s->fragment_width[0] + BLOCK_X; if (s->all_fragments[current_fragment].coding_method != MODE_COPY) { if (coding_mode == 0) { motion_x[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; motion_y[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; } else { motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)]; motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)]; } last_motion_x = motion_x[k]; last_motion_y = motion_y[k]; } else { motion_x[k] = 0; motion_y[k] = 0; } } break; case MODE_INTER_LAST_MV: motion_x[0] = last_motion_x; motion_y[0] = last_motion_y; break; case MODE_INTER_PRIOR_LAST: motion_x[0] = prior_last_motion_x; motion_y[0] = prior_last_motion_y; prior_last_motion_x = last_motion_x; prior_last_motion_y = last_motion_y; last_motion_x = motion_x[0]; last_motion_y = motion_y[0]; break; default: motion_x[0] = 0; motion_y[0] = 0; break; } for (k = 0; k < 4; k++) { current_fragment = BLOCK_Y * s->fragment_width[0] + BLOCK_X; if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { s->motion_val[0][current_fragment][0] = motion_x[k]; s->motion_val[0][current_fragment][1] = motion_y[k]; } else { s->motion_val[0][current_fragment][0] = motion_x[0]; s->motion_val[0][current_fragment][1] = motion_y[0]; } } if (s->chroma_y_shift) { if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { motion_x[0] = RSHIFT(motion_x[0] + motion_x[1] + motion_x[2] + motion_x[3], 2); motion_y[0] = RSHIFT(motion_y[0] + motion_y[1] + motion_y[2] + motion_y[3], 2); } motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1); motion_y[0] = (motion_y[0] >> 1) | (motion_y[0] & 1); frag = mb_y * s->fragment_width[1] + mb_x; s->motion_val[1][frag][0] = motion_x[0]; s->motion_val[1][frag][1] = motion_y[0]; } else if (s->chroma_x_shift) { if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { motion_x[0] = RSHIFT(motion_x[0] + motion_x[1], 1); motion_y[0] = RSHIFT(motion_y[0] + motion_y[1], 1); motion_x[1] = RSHIFT(motion_x[2] + motion_x[3], 1); motion_y[1] = RSHIFT(motion_y[2] + motion_y[3], 1); } else { motion_x[1] = motion_x[0]; motion_y[1] = motion_y[0]; } motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1); motion_x[1] = (motion_x[1] >> 1) | (motion_x[1] & 1); frag = 2 * mb_y * s->fragment_width[1] + mb_x; for (k = 0; k < 2; k++) { s->motion_val[1][frag][0] = motion_x[k]; s->motion_val[1][frag][1] = motion_y[k]; frag += s->fragment_width[1]; } } else { for (k = 0; k < 4; k++) { frag = BLOCK_Y * s->fragment_width[1] + BLOCK_X; if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { s->motion_val[1][frag][0] = motion_x[k]; s->motion_val[1][frag][1] = motion_y[k]; } else { s->motion_val[1][frag][0] = motion_x[0]; s->motion_val[1][frag][1] = motion_y[0]; } } } } } } return 0; }
['static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)\n{\n int j, k, sb_x, sb_y;\n int coding_mode;\n int motion_x[4];\n int motion_y[4];\n int last_motion_x = 0;\n int last_motion_y = 0;\n int prior_last_motion_x = 0;\n int prior_last_motion_y = 0;\n int current_macroblock;\n int current_fragment;\n int frag;\n if (s->keyframe)\n return 0;\n coding_mode = get_bits1(gb);\n for (sb_y = 0; sb_y < s->y_superblock_height; sb_y++) {\n for (sb_x = 0; sb_x < s->y_superblock_width; sb_x++) {\n if (get_bits_left(gb) <= 0)\n return -1;\n for (j = 0; j < 4; j++) {\n int mb_x = 2 * sb_x + (j >> 1);\n int mb_y = 2 * sb_y + (((j >> 1) + j) & 1);\n current_macroblock = mb_y * s->macroblock_width + mb_x;\n if (mb_x >= s->macroblock_width ||\n mb_y >= s->macroblock_height ||\n s->macroblock_coding[current_macroblock] == MODE_COPY)\n continue;\n switch (s->macroblock_coding[current_macroblock]) {\n case MODE_INTER_PLUS_MV:\n case MODE_GOLDEN_MV:\n if (coding_mode == 0) {\n motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];\n motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];\n } else {\n motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)];\n motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)];\n }\n if (s->macroblock_coding[current_macroblock] == MODE_INTER_PLUS_MV) {\n prior_last_motion_x = last_motion_x;\n prior_last_motion_y = last_motion_y;\n last_motion_x = motion_x[0];\n last_motion_y = motion_y[0];\n }\n break;\n case MODE_INTER_FOURMV:\n prior_last_motion_x = last_motion_x;\n prior_last_motion_y = last_motion_y;\n for (k = 0; k < 4; k++) {\n current_fragment = BLOCK_Y * s->fragment_width[0] + BLOCK_X;\n if (s->all_fragments[current_fragment].coding_method != MODE_COPY) {\n if (coding_mode == 0) {\n motion_x[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];\n motion_y[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];\n } else {\n motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)];\n motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)];\n }\n last_motion_x = motion_x[k];\n last_motion_y = motion_y[k];\n } else {\n motion_x[k] = 0;\n motion_y[k] = 0;\n }\n }\n break;\n case MODE_INTER_LAST_MV:\n motion_x[0] = last_motion_x;\n motion_y[0] = last_motion_y;\n break;\n case MODE_INTER_PRIOR_LAST:\n motion_x[0] = prior_last_motion_x;\n motion_y[0] = prior_last_motion_y;\n prior_last_motion_x = last_motion_x;\n prior_last_motion_y = last_motion_y;\n last_motion_x = motion_x[0];\n last_motion_y = motion_y[0];\n break;\n default:\n motion_x[0] = 0;\n motion_y[0] = 0;\n break;\n }\n for (k = 0; k < 4; k++) {\n current_fragment =\n BLOCK_Y * s->fragment_width[0] + BLOCK_X;\n if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {\n s->motion_val[0][current_fragment][0] = motion_x[k];\n s->motion_val[0][current_fragment][1] = motion_y[k];\n } else {\n s->motion_val[0][current_fragment][0] = motion_x[0];\n s->motion_val[0][current_fragment][1] = motion_y[0];\n }\n }\n if (s->chroma_y_shift) {\n if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {\n motion_x[0] = RSHIFT(motion_x[0] + motion_x[1] +\n motion_x[2] + motion_x[3], 2);\n motion_y[0] = RSHIFT(motion_y[0] + motion_y[1] +\n motion_y[2] + motion_y[3], 2);\n }\n motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);\n motion_y[0] = (motion_y[0] >> 1) | (motion_y[0] & 1);\n frag = mb_y * s->fragment_width[1] + mb_x;\n s->motion_val[1][frag][0] = motion_x[0];\n s->motion_val[1][frag][1] = motion_y[0];\n } else if (s->chroma_x_shift) {\n if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {\n motion_x[0] = RSHIFT(motion_x[0] + motion_x[1], 1);\n motion_y[0] = RSHIFT(motion_y[0] + motion_y[1], 1);\n motion_x[1] = RSHIFT(motion_x[2] + motion_x[3], 1);\n motion_y[1] = RSHIFT(motion_y[2] + motion_y[3], 1);\n } else {\n motion_x[1] = motion_x[0];\n motion_y[1] = motion_y[0];\n }\n motion_x[0] = (motion_x[0] >> 1) | (motion_x[0] & 1);\n motion_x[1] = (motion_x[1] >> 1) | (motion_x[1] & 1);\n frag = 2 * mb_y * s->fragment_width[1] + mb_x;\n for (k = 0; k < 2; k++) {\n s->motion_val[1][frag][0] = motion_x[k];\n s->motion_val[1][frag][1] = motion_y[k];\n frag += s->fragment_width[1];\n }\n } else {\n for (k = 0; k < 4; k++) {\n frag = BLOCK_Y * s->fragment_width[1] + BLOCK_X;\n if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {\n s->motion_val[1][frag][0] = motion_x[k];\n s->motion_val[1][frag][1] = motion_y[k];\n } else {\n s->motion_val[1][frag][0] = motion_x[0];\n s->motion_val[1][frag][1] = motion_y[0];\n }\n }\n }\n }\n }\n }\n return 0;\n}']
36,556
0
https://github.com/openssl/openssl/blob/d43c4497ce1611373c3a3e5b433dfde4907d1a69/crypto/x509/x509_vfy.c/#L500
static int check_chain_extensions(X509_STORE_CTX *ctx) { #ifdef OPENSSL_NO_CHAIN_VERIFY return 1; #else int i, ok=0, must_be_ca, plen = 0; X509 *x; int (*cb)(int xok,X509_STORE_CTX *xctx); int proxy_path_length = 0; int purpose; int allow_proxy_certs; cb=ctx->verify_cb; must_be_ca = -1; if (ctx->parent) { allow_proxy_certs = 0; purpose = X509_PURPOSE_CRL_SIGN; } else { allow_proxy_certs = !!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS); if (getenv("OPENSSL_ALLOW_PROXY_CERTS")) allow_proxy_certs = 1; purpose = ctx->param->purpose; } for (i = 0; i < ctx->last_untrusted; i++) { int ret; x = sk_X509_value(ctx->chain, i); if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL) && (x->ex_flags & EXFLAG_CRITICAL)) { ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION; ctx->error_depth = i; ctx->current_cert = x; ok=cb(0,ctx); if (!ok) goto end; } if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY)) { ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED; ctx->error_depth = i; ctx->current_cert = x; ok=cb(0,ctx); if (!ok) goto end; } ret = X509_check_ca(x); switch(must_be_ca) { case -1: if ((ctx->param->flags & X509_V_FLAG_X509_STRICT) && (ret != 1) && (ret != 0)) { ret = 0; ctx->error = X509_V_ERR_INVALID_CA; } else ret = 1; break; case 0: if (ret != 0) { ret = 0; ctx->error = X509_V_ERR_INVALID_NON_CA; } else ret = 1; break; default: if ((ret == 0) || ((ctx->param->flags & X509_V_FLAG_X509_STRICT) && (ret != 1))) { ret = 0; ctx->error = X509_V_ERR_INVALID_CA; } else ret = 1; break; } if (ret == 0) { ctx->error_depth = i; ctx->current_cert = x; ok=cb(0,ctx); if (!ok) goto end; } if (ctx->param->purpose > 0) { ret = X509_check_purpose(x, purpose, must_be_ca > 0); if ((ret == 0) || ((ctx->param->flags & X509_V_FLAG_X509_STRICT) && (ret != 1))) { ctx->error = X509_V_ERR_INVALID_PURPOSE; ctx->error_depth = i; ctx->current_cert = x; ok=cb(0,ctx); if (!ok) goto end; } } if ((i > 1) && !(x->ex_flags & EXFLAG_SI) && (x->ex_pathlen != -1) && (plen > (x->ex_pathlen + proxy_path_length + 1))) { ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED; ctx->error_depth = i; ctx->current_cert = x; ok=cb(0,ctx); if (!ok) goto end; } if (!(x->ex_flags & EXFLAG_SI)) plen++; if (x->ex_flags & EXFLAG_PROXY) { if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen) { ctx->error = X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED; ctx->error_depth = i; ctx->current_cert = x; ok=cb(0,ctx); if (!ok) goto end; } proxy_path_length++; must_be_ca = 0; } else must_be_ca = 1; } ok = 1; end: return ok; #endif }
['static int check_chain_extensions(X509_STORE_CTX *ctx)\n{\n#ifdef OPENSSL_NO_CHAIN_VERIFY\n\treturn 1;\n#else\n\tint i, ok=0, must_be_ca, plen = 0;\n\tX509 *x;\n\tint (*cb)(int xok,X509_STORE_CTX *xctx);\n\tint proxy_path_length = 0;\n\tint purpose;\n\tint allow_proxy_certs;\n\tcb=ctx->verify_cb;\n\tmust_be_ca = -1;\n\tif (ctx->parent)\n\t\t{\n\t\tallow_proxy_certs = 0;\n\t\tpurpose = X509_PURPOSE_CRL_SIGN;\n\t\t}\n\telse\n\t\t{\n\t\tallow_proxy_certs =\n\t\t\t!!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);\n\t\tif (getenv("OPENSSL_ALLOW_PROXY_CERTS"))\n\t\t\tallow_proxy_certs = 1;\n\t\tpurpose = ctx->param->purpose;\n\t\t}\n\tfor (i = 0; i < ctx->last_untrusted; i++)\n\t\t{\n\t\tint ret;\n\t\tx = sk_X509_value(ctx->chain, i);\n\t\tif (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)\n\t\t\t&& (x->ex_flags & EXFLAG_CRITICAL))\n\t\t\t{\n\t\t\tctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tif (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY))\n\t\t\t{\n\t\t\tctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tret = X509_check_ca(x);\n\t\tswitch(must_be_ca)\n\t\t\t{\n\t\tcase -1:\n\t\t\tif ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n\t\t\t\t&& (ret != 1) && (ret != 0))\n\t\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tctx->error = X509_V_ERR_INVALID_CA;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tret = 1;\n\t\t\tbreak;\n\t\tcase 0:\n\t\t\tif (ret != 0)\n\t\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tctx->error = X509_V_ERR_INVALID_NON_CA;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tret = 1;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tif ((ret == 0)\n\t\t\t\t|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n\t\t\t\t\t&& (ret != 1)))\n\t\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tctx->error = X509_V_ERR_INVALID_CA;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tret = 1;\n\t\t\tbreak;\n\t\t\t}\n\t\tif (ret == 0)\n\t\t\t{\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tif (ctx->param->purpose > 0)\n\t\t\t{\n\t\t\tret = X509_check_purpose(x, purpose, must_be_ca > 0);\n\t\t\tif ((ret == 0)\n\t\t\t\t|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n\t\t\t\t\t&& (ret != 1)))\n\t\t\t\t{\n\t\t\t\tctx->error = X509_V_ERR_INVALID_PURPOSE;\n\t\t\t\tctx->error_depth = i;\n\t\t\t\tctx->current_cert = x;\n\t\t\t\tok=cb(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\t}\n\t\tif ((i > 1) && !(x->ex_flags & EXFLAG_SI)\n\t\t\t && (x->ex_pathlen != -1)\n\t\t\t && (plen > (x->ex_pathlen + proxy_path_length + 1)))\n\t\t\t{\n\t\t\tctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tif (!(x->ex_flags & EXFLAG_SI))\n\t\t\tplen++;\n\t\tif (x->ex_flags & EXFLAG_PROXY)\n\t\t\t{\n\t\t\tif (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen)\n\t\t\t\t{\n\t\t\t\tctx->error =\n\t\t\t\t\tX509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;\n\t\t\t\tctx->error_depth = i;\n\t\t\t\tctx->current_cert = x;\n\t\t\t\tok=cb(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\tproxy_path_length++;\n\t\t\tmust_be_ca = 0;\n\t\t\t}\n\t\telse\n\t\t\tmust_be_ca = 1;\n\t\t}\n\tok = 1;\n end:\n\treturn ok;\n#endif\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}']
36,557
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 unpack_bitstream(G723_1_Context *p, const uint8_t *buf,\n int buf_size)\n{\n BitstreamContext bc;\n int ad_cb_len;\n int temp, info_bits, i;\n bitstream_init8(&bc, buf, buf_size);\n info_bits = bitstream_read(&bc, 2);\n if (info_bits == 3) {\n p->cur_frame_type = UNTRANSMITTED_FRAME;\n return 0;\n }\n p->lsp_index[2] = bitstream_read(&bc, 8);\n p->lsp_index[1] = bitstream_read(&bc, 8);\n p->lsp_index[0] = bitstream_read(&bc, 8);\n if (info_bits == 2) {\n p->cur_frame_type = SID_FRAME;\n p->subframe[0].amp_index = bitstream_read(&bc, 6);\n return 0;\n }\n p->cur_rate = info_bits ? RATE_5300 : RATE_6300;\n p->cur_frame_type = ACTIVE_FRAME;\n p->pitch_lag[0] = bitstream_read(&bc, 7);\n if (p->pitch_lag[0] > 123)\n return -1;\n p->pitch_lag[0] += PITCH_MIN;\n p->subframe[1].ad_cb_lag = bitstream_read(&bc, 2);\n p->pitch_lag[1] = bitstream_read(&bc, 7);\n if (p->pitch_lag[1] > 123)\n return -1;\n p->pitch_lag[1] += PITCH_MIN;\n p->subframe[3].ad_cb_lag = bitstream_read(&bc, 2);\n p->subframe[0].ad_cb_lag = 1;\n p->subframe[2].ad_cb_lag = 1;\n for (i = 0; i < SUBFRAMES; i++) {\n temp = bitstream_read(&bc, 12);\n ad_cb_len = 170;\n p->subframe[i].dirac_train = 0;\n if (p->cur_rate == RATE_6300 && p->pitch_lag[i >> 1] < SUBFRAME_LEN - 2) {\n p->subframe[i].dirac_train = temp >> 11;\n temp &= 0x7FF;\n ad_cb_len = 85;\n }\n p->subframe[i].ad_cb_gain = FASTDIV(temp, GAIN_LEVELS);\n if (p->subframe[i].ad_cb_gain < ad_cb_len) {\n p->subframe[i].amp_index = temp - p->subframe[i].ad_cb_gain *\n GAIN_LEVELS;\n } else {\n return -1;\n }\n }\n p->subframe[0].grid_index = bitstream_read(&bc, 1);\n p->subframe[1].grid_index = bitstream_read(&bc, 1);\n p->subframe[2].grid_index = bitstream_read(&bc, 1);\n p->subframe[3].grid_index = bitstream_read(&bc, 1);\n if (p->cur_rate == RATE_6300) {\n bitstream_skip(&bc, 1);\n temp = bitstream_read(&bc, 13);\n p->subframe[0].pulse_pos = temp / 810;\n temp -= p->subframe[0].pulse_pos * 810;\n p->subframe[1].pulse_pos = FASTDIV(temp, 90);\n temp -= p->subframe[1].pulse_pos * 90;\n p->subframe[2].pulse_pos = FASTDIV(temp, 9);\n p->subframe[3].pulse_pos = temp - p->subframe[2].pulse_pos * 9;\n p->subframe[0].pulse_pos = (p->subframe[0].pulse_pos << 16) +\n bitstream_read(&bc, 16);\n p->subframe[1].pulse_pos = (p->subframe[1].pulse_pos << 14) +\n bitstream_read(&bc, 14);\n p->subframe[2].pulse_pos = (p->subframe[2].pulse_pos << 16) +\n bitstream_read(&bc, 16);\n p->subframe[3].pulse_pos = (p->subframe[3].pulse_pos << 14) +\n bitstream_read(&bc, 14);\n p->subframe[0].pulse_sign = bitstream_read(&bc, 6);\n p->subframe[1].pulse_sign = bitstream_read(&bc, 5);\n p->subframe[2].pulse_sign = bitstream_read(&bc, 6);\n p->subframe[3].pulse_sign = bitstream_read(&bc, 5);\n } else {\n p->subframe[0].pulse_pos = bitstream_read(&bc, 12);\n p->subframe[1].pulse_pos = bitstream_read(&bc, 12);\n p->subframe[2].pulse_pos = bitstream_read(&bc, 12);\n p->subframe[3].pulse_pos = bitstream_read(&bc, 12);\n p->subframe[0].pulse_sign = bitstream_read(&bc, 4);\n p->subframe[1].pulse_sign = bitstream_read(&bc, 4);\n p->subframe[2].pulse_sign = bitstream_read(&bc, 4);\n p->subframe[3].pulse_sign = bitstream_read(&bc, 4);\n }\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 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}']
36,558
0
https://github.com/openssl/openssl/blob/55525742f4c2bf416013fc3a75ec642775d97f80/crypto/bn/bn_ctx.c/#L440
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while(num--) { bn_check_top(p->current->vals + offset); if(!offset) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['static BIGNUM *rsa_get_public_exp(const BIGNUM *d, const BIGNUM *p,\n\tconst BIGNUM *q, BN_CTX *ctx)\n{\n\tBIGNUM *ret = NULL, *r0, *r1, *r2;\n\tif (d == NULL || p == NULL || q == NULL)\n\t\treturn NULL;\n\tBN_CTX_start(ctx);\n\tr0 = BN_CTX_get(ctx);\n\tr1 = BN_CTX_get(ctx);\n\tr2 = BN_CTX_get(ctx);\n\tif (r2 == NULL)\n\t\tgoto err;\n\tif (!BN_sub(r1, p, BN_value_one())) goto err;\n\tif (!BN_sub(r2, q, BN_value_one())) goto err;\n\tif (!BN_mul(r0, r1, r2, ctx)) goto err;\n\tret = BN_mod_inverse(NULL, d, r0, ctx);\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tint top,al,bl;\n\tBIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tint i;\n#endif\n#ifdef BN_RECURSION\n\tBIGNUM *t=NULL;\n\tint j=0,k;\n#endif\n#ifdef BN_COUNT\n\tfprintf(stderr,"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\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\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == b))\n\t\t{\n\t\tif ((rr = BN_CTX_get(ctx)) == NULL) goto err;\n\t\t}\n\telse\n\t\trr = r;\n\trr->neg=a->neg^b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\ti = al-bl;\n#endif\n#ifdef BN_MUL_COMBA\n\tif (i == 0)\n\t\t{\n# if 0\n\t\tif (al == 4)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,8) == NULL) goto err;\n\t\t\trr->top=8;\n\t\t\tbn_mul_comba4(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n# endif\n\t\tif (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) goto err;\n\t\t\trr->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\t}\n#endif\n#ifdef BN_RECURSION\n\tif ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (i >= -1 && i <= 1)\n\t\t\t{\n\t\t\tint sav_j =0;\n\t\t\tif (i >= 0)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)al);\n\t\t\t\t}\n\t\t\tif (i == -1)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)bl);\n\t\t\t\t}\n\t\t\tsav_j = j;\n\t\t\tj = 1<<(j-1);\n\t\t\tassert(j <= al || j <= bl);\n\t\t\tk = j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al > j || bl > j)\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*4);\n\t\t\t\tbn_wexpand(rr,k*4);\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*2);\n\t\t\t\tbn_wexpand(rr,k*2);\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)b;\n\t\t\tif (bn_wexpand(tmp_bn,al) == NULL) goto err;\n\t\t\ttmp_bn->d[bl]=0;\n\t\t\tbl++;\n\t\t\ti--;\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\tBIGNUM *tmp_bn = (BIGNUM *)a;\n\t\t\tif (bn_wexpand(tmp_bn,bl) == NULL) goto err;\n\t\t\ttmp_bn->d[al]=0;\n\t\t\tal++;\n\t\t\ti++;\n\t\t\t}\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#endif\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) goto err;\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_correct_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\tret=1;\nerr:\n\tbn_check_top(r);\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\tif ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_mod_inverse_no_branch(in, a, n, ctx);\n\t\t}\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}', 'static BIGNUM *BN_mod_inverse_no_branch(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 local_A, local_B;\n\tBIGNUM *pA, *pB;\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\tpB = &local_B;\n\t\tBN_with_flags(pB, B, BN_FLG_CONSTTIME);\n\t\tif (!BN_nnmod(B, pB, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\twhile (!BN_is_zero(B))\n\t\t{\n\t\tBIGNUM *tmp;\n\t\tpA = &local_A;\n\t\tBN_with_flags(pA, A, BN_FLG_CONSTTIME);\n\t\tif (!BN_div(D,M,pA,B,ctx)) goto err;\n\t\ttmp=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\tM=Y;\n\t\tY=X;\n\t\tX=tmp;\n\t\tsign = -sign;\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_NO_BRANCH,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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n\t{\n\tBIGNUM *ret;\n\tCTXDBG_ENTRY("BN_CTX_get", ctx);\n\tif(ctx->err_stack || ctx->too_many) return NULL;\n\tif((ret = BN_POOL_get(&ctx->pool)) == NULL)\n\t\t{\n\t\tctx->too_many = 1;\n\t\tBNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\treturn NULL;\n\t\t}\n\tBN_zero(ret);\n\tctx->used++;\n\tCTXDBG_RET(ctx, 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\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}', 'static 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_NO_BRANCH,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_correct_top(res);\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 void BN_POOL_release(BN_POOL *p, unsigned int num)\n\t{\n\tunsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n\tp->used -= num;\n\twhile(num--)\n\t\t{\n\t\tbn_check_top(p->current->vals + offset);\n\t\tif(!offset)\n\t\t\t{\n\t\t\toffset = BN_CTX_POOL_SIZE - 1;\n\t\t\tp->current = p->current->prev;\n\t\t\t}\n\t\telse\n\t\t\toffset--;\n\t\t}\n\t}']
36,559
0
https://github.com/libav/libav/blob/7684a36113fa12c88ba80b5498f05849a6b58632/libavcodec/utils.c/#L458
static int video_get_buffer(AVCodecContext *s, AVFrame *pic) { FramePool *pool = s->internal->pool; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pic->format); int pixel_size = desc->comp[0].step_minus1 + 1; int h_chroma_shift, v_chroma_shift; int i; if (pic->data[0] != NULL) { av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n"); return -1; } memset(pic->data, 0, sizeof(pic->data)); pic->extended_data = pic->data; av_pix_fmt_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); for (i = 0; i < 4 && pool->pools[i]; i++) { const int h_shift = i == 0 ? 0 : h_chroma_shift; const int v_shift = i == 0 ? 0 : v_chroma_shift; pic->linesize[i] = pool->linesize[i]; pic->buf[i] = av_buffer_pool_get(pool->pools[i]); if (!pic->buf[i]) goto fail; if ((s->flags & CODEC_FLAG_EMU_EDGE) || !pool->pools[2]) pic->data[i] = pic->buf[i]->data; else { pic->data[i] = pic->buf[i]->data + FFALIGN((pic->linesize[i] * EDGE_WIDTH >> v_shift) + (pixel_size * EDGE_WIDTH >> h_shift), pool->stride_align[i]); } } for (; i < AV_NUM_DATA_POINTERS; i++) { pic->data[i] = NULL; pic->linesize[i] = 0; } if (pic->data[1] && !pic->data[2]) avpriv_set_systematic_pal2((uint32_t *)pic->data[1], s->pix_fmt); if (s->debug & FF_DEBUG_BUFFERS) av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p\n", pic); return 0; fail: av_frame_unref(pic); return AVERROR(ENOMEM); }
['static int video_get_buffer(AVCodecContext *s, AVFrame *pic)\n{\n FramePool *pool = s->internal->pool;\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pic->format);\n int pixel_size = desc->comp[0].step_minus1 + 1;\n int h_chroma_shift, v_chroma_shift;\n int i;\n if (pic->data[0] != NULL) {\n av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\\n");\n return -1;\n }\n memset(pic->data, 0, sizeof(pic->data));\n pic->extended_data = pic->data;\n av_pix_fmt_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);\n for (i = 0; i < 4 && pool->pools[i]; i++) {\n const int h_shift = i == 0 ? 0 : h_chroma_shift;\n const int v_shift = i == 0 ? 0 : v_chroma_shift;\n pic->linesize[i] = pool->linesize[i];\n pic->buf[i] = av_buffer_pool_get(pool->pools[i]);\n if (!pic->buf[i])\n goto fail;\n if ((s->flags & CODEC_FLAG_EMU_EDGE) || !pool->pools[2])\n pic->data[i] = pic->buf[i]->data;\n else {\n pic->data[i] = pic->buf[i]->data +\n FFALIGN((pic->linesize[i] * EDGE_WIDTH >> v_shift) +\n (pixel_size * EDGE_WIDTH >> h_shift), pool->stride_align[i]);\n }\n }\n for (; i < AV_NUM_DATA_POINTERS; i++) {\n pic->data[i] = NULL;\n pic->linesize[i] = 0;\n }\n if (pic->data[1] && !pic->data[2])\n avpriv_set_systematic_pal2((uint32_t *)pic->data[1], s->pix_fmt);\n if (s->debug & FF_DEBUG_BUFFERS)\n av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p\\n", pic);\n return 0;\nfail:\n av_frame_unref(pic);\n return AVERROR(ENOMEM);\n}', 'const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)\n{\n if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)\n return NULL;\n return &av_pix_fmt_descriptors[pix_fmt];\n}']
36,560
0
https://github.com/libav/libav/blob/99ccd2ba10eac2b282c272ad9e75f082123c765a/libavcodec/wmv2enc.c/#L48
static int encode_ext_header(Wmv2Context *w){ MpegEncContext * const s= &w->s; PutBitContext pb; int code; init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size); put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047)); put_bits(&pb, 1, w->mspel_bit=1); put_bits(&pb, 1, s->loop_filter); put_bits(&pb, 1, w->abt_flag=1); put_bits(&pb, 1, w->j_type_bit=1); put_bits(&pb, 1, w->top_left_mv_flag=0); put_bits(&pb, 1, w->per_mb_rl_bit=1); put_bits(&pb, 3, code=1); flush_put_bits(&pb); s->slice_height = s->mb_height / code; return 0; }
['static int encode_ext_header(Wmv2Context *w){\n MpegEncContext * const s= &w->s;\n PutBitContext pb;\n int code;\n init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size);\n put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num);\n put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047));\n put_bits(&pb, 1, w->mspel_bit=1);\n put_bits(&pb, 1, s->loop_filter);\n put_bits(&pb, 1, w->abt_flag=1);\n put_bits(&pb, 1, w->j_type_bit=1);\n put_bits(&pb, 1, w->top_left_mv_flag=0);\n put_bits(&pb, 1, w->per_mb_rl_bit=1);\n put_bits(&pb, 3, code=1);\n flush_put_bits(&pb);\n s->slice_height = s->mb_height / code;\n return 0;\n}', 'static inline void init_put_bits(PutBitContext *s, uint8_t *buffer,\n int buffer_size)\n{\n if (buffer_size < 0) {\n buffer_size = 0;\n buffer = NULL;\n }\n s->size_in_bits = 8 * buffer_size;\n s->buf = buffer;\n s->buf_end = s->buf + buffer_size;\n s->buf_ptr = s->buf;\n s->bit_left = 32;\n s->bit_buf = 0;\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 <= 31 && 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 AV_WL32(s->buf_ptr, 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 AV_WB32(s->buf_ptr, 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 inline void flush_put_bits(PutBitContext *s)\n{\n#ifndef BITSTREAM_WRITER_LE\n if (s->bit_left < 32)\n s->bit_buf <<= s->bit_left;\n#endif\n while (s->bit_left < 32) {\n#ifdef BITSTREAM_WRITER_LE\n *s->buf_ptr++ = s->bit_buf;\n s->bit_buf >>= 8;\n#else\n *s->buf_ptr++ = s->bit_buf >> 24;\n s->bit_buf <<= 8;\n#endif\n s->bit_left += 8;\n }\n s->bit_left = 32;\n s->bit_buf = 0;\n}']
36,561
0
https://github.com/openssl/openssl/blob/80aa9cc985251463a3ad65b0a4d64bf93c70b175/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static void jpake_receive_step1(JPAKE_CTX *ctx, BIO *bconn)\n\t{\n\tJPAKE_STEP1 s1;\n\tJPAKE_STEP1_init(&s1);\n\tjpake_receive_part(&s1.p1, bconn);\n\tjpake_receive_part(&s1.p2, bconn);\n\tif(!JPAKE_STEP1_process(ctx, &s1))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\texit(1);\n\t\t}\n\tJPAKE_STEP1_release(&s1);\n\t}', 'int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received)\n {\n if(!verify_zkp(&received->p1, ctx->p.g, ctx))\n\t{\n\tJPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_VERIFY_X3_FAILED);\n\treturn 0;\n\t}\n if(!verify_zkp(&received->p2, ctx->p.g, ctx))\n\t{\n\tJPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_VERIFY_X4_FAILED);\n\treturn 0;\n\t}\n if(BN_is_one(received->p2.gx))\n\t{\n\tJPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_G_TO_THE_X4_IS_ONE);\n\treturn 0;\n\t}\n BN_copy(ctx->p.gxc, received->p1.gx);\n BN_copy(ctx->p.gxd, received->p2.gx);\n return 1;\n }', 'static int verify_zkp(const JPAKE_STEP_PART *p, const BIGNUM *zkpg,\n\t\t JPAKE_CTX *ctx)\n {\n BIGNUM *h = BN_new();\n BIGNUM *t1 = BN_new();\n BIGNUM *t2 = BN_new();\n BIGNUM *t3 = BN_new();\n int ret = 0;\n zkp_hash(h, zkpg, p, ctx->p.peer_name);\n BN_mod_exp(t1, zkpg, p->zkpx.b, ctx->p.p, ctx->ctx);\n BN_mod_exp(t2, p->gx, h, ctx->p.p, ctx->ctx);\n BN_mod_mul(t3, t1, t2, ctx->p.p, ctx->ctx);\n if(BN_cmp(t3, p->zkpx.gr) == 0)\n\tret = 1;\n else\n\tJPAKEerr(JPAKE_F_VERIFY_ZKP, JPAKE_R_ZKP_VERIFY_FAILED);\n BN_free(t3);\n BN_free(t2);\n BN_free(t1);\n BN_free(h);\n return ret;\n }', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n\t BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{\n# ifdef MONT_EXP_WORD\n\t\tif (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0))\n\t\t\t{\n\t\t\tBN_ULONG A = a->d[0];\n\t\t\tret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);\n\t\t\t}\n\t\telse\n# endif\n\t\t\tret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);\n\t\t}\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\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1;\n\tBIGNUM *aa;\n\tBIGNUM *val[TABLE_SIZE];\n\tBN_RECP_CTX recp;\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_RECP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\treturn -1;\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(r);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\taa = BN_CTX_get(ctx);\n\tval[0] = BN_CTX_get(ctx);\n\tif(!aa || !val[0]) goto err;\n\tBN_RECP_CTX_init(&recp);\n\tif (m->neg)\n\t\t{\n\t\tif (!BN_copy(aa, m)) goto err;\n\t\taa->neg = 0;\n\t\tif (BN_RECP_CTX_set(&recp,aa,ctx) <= 0) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\t\t}\n\tif (!BN_nnmod(val[0],a,m,ctx)) goto err;\n\tif (BN_is_zero(val[0]))\n\t\t{\n\t\tBN_zero(r);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_reciprocal(aa,val[0],val[0],&recp,ctx))\n\t\t\tgoto err;\n\t\tj=1<<(window-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_reciprocal(val[i],val[i-1],\n\t\t\t\t\t\taa,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_one(r)) 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\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\tgoto err;\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_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_reciprocal(r,r,val[wvalue>>1],&recp,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\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\tBN_RECP_CTX_free(&recp);\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_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\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\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(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;\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\t{\n\t\t\tBN_ULONG ql, qh;\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\t}\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}', 'static 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(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV_NO_BRANCH,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;\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\t{\n\t\t\tBN_ULONG ql, qh;\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\t}\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_correct_top(res);\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}']
36,562
0
https://github.com/libav/libav/blob/e6e7bfc11e93fe3499c576fa9466cb2e913b5965/libavcodec/h264_loopfilter.c/#L206
static av_always_inline void filter_mb_edgeh(uint8_t *pix, int stride, const int16_t bS[4], unsigned int qp, int a, int b, H264Context *h, int intra) { const unsigned int index_a = qp + a; const int alpha = alpha_table[index_a]; const int beta = beta_table[qp + b]; if (alpha ==0 || beta == 0) return; if( bS[0] < 4 || !intra ) { int8_t tc[4]; tc[0] = tc0_table[index_a][bS[0]]; tc[1] = tc0_table[index_a][bS[1]]; tc[2] = tc0_table[index_a][bS[2]]; tc[3] = tc0_table[index_a][bS[3]]; h->h264dsp.h264_v_loop_filter_luma(pix, stride, alpha, beta, tc); } else { h->h264dsp.h264_v_loop_filter_luma_intra(pix, stride, alpha, beta); } }
['static av_always_inline void h264_filter_mb_fast_internal(H264Context *h,\n int mb_x, int mb_y,\n uint8_t *img_y,\n uint8_t *img_cb,\n uint8_t *img_cr,\n unsigned int linesize,\n unsigned int uvlinesize,\n int pixel_shift)\n{\n MpegEncContext * const s = &h->s;\n int chroma = !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY));\n int chroma444 = CHROMA444;\n int chroma422 = CHROMA422;\n int mb_xy = h->mb_xy;\n int left_type= h->left_type[LTOP];\n int top_type= h->top_type;\n int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);\n int a = h->slice_alpha_c0_offset - qp_bd_offset;\n int b = h->slice_beta_offset - qp_bd_offset;\n int mb_type = s->current_picture.f.mb_type[mb_xy];\n int qp = s->current_picture.f.qscale_table[mb_xy];\n int qp0 = s->current_picture.f.qscale_table[mb_xy - 1];\n int qp1 = s->current_picture.f.qscale_table[h->top_mb_xy];\n int qpc = get_chroma_qp( h, 0, qp );\n int qpc0 = get_chroma_qp( h, 0, qp0 );\n int qpc1 = get_chroma_qp( h, 0, qp1 );\n qp0 = (qp + qp0 + 1) >> 1;\n qp1 = (qp + qp1 + 1) >> 1;\n qpc0 = (qpc + qpc0 + 1) >> 1;\n qpc1 = (qpc + qpc1 + 1) >> 1;\n if( IS_INTRA(mb_type) ) {\n static const int16_t bS4[4] = {4,4,4,4};\n static const int16_t bS3[4] = {3,3,3,3};\n const int16_t *bSH = FIELD_PICTURE ? bS3 : bS4;\n if(left_type)\n filter_mb_edgev( &img_y[4*0<<pixel_shift], linesize, bS4, qp0, a, b, h, 1);\n if( IS_8x8DCT(mb_type) ) {\n filter_mb_edgev( &img_y[4*2<<pixel_shift], linesize, bS3, qp, a, b, h, 0);\n if(top_type){\n filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, a, b, h, 1);\n }\n filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, a, b, h, 0);\n } else {\n filter_mb_edgev( &img_y[4*1<<pixel_shift], linesize, bS3, qp, a, b, h, 0);\n filter_mb_edgev( &img_y[4*2<<pixel_shift], linesize, bS3, qp, a, b, h, 0);\n filter_mb_edgev( &img_y[4*3<<pixel_shift], linesize, bS3, qp, a, b, h, 0);\n if(top_type){\n filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, a, b, h, 1);\n }\n filter_mb_edgeh( &img_y[4*1*linesize], linesize, bS3, qp, a, b, h, 0);\n filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, a, b, h, 0);\n filter_mb_edgeh( &img_y[4*3*linesize], linesize, bS3, qp, a, b, h, 0);\n }\n if(chroma){\n if(chroma444){\n if(left_type){\n filter_mb_edgev( &img_cb[4*0<<pixel_shift], linesize, bS4, qpc0, a, b, h, 1);\n filter_mb_edgev( &img_cr[4*0<<pixel_shift], linesize, bS4, qpc0, a, b, h, 1);\n }\n if( IS_8x8DCT(mb_type) ) {\n filter_mb_edgev( &img_cb[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cr[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n if(top_type){\n filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1 );\n filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1 );\n }\n filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);\n } else {\n filter_mb_edgev( &img_cb[4*1<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cr[4*1<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cb[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cr[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cb[4*3<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cr[4*3<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n if(top_type){\n filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1);\n filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1);\n }\n filter_mb_edgeh( &img_cb[4*1*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cr[4*1*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cb[4*3*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cr[4*3*linesize], linesize, bS3, qpc, a, b, h, 0);\n }\n }else if(chroma422){\n if(left_type){\n filter_mb_edgecv(&img_cb[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);\n filter_mb_edgecv(&img_cr[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);\n }\n filter_mb_edgecv(&img_cb[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgecv(&img_cr[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);\n if(top_type){\n filter_mb_edgech(&img_cb[4*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);\n filter_mb_edgech(&img_cr[4*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);\n }\n filter_mb_edgech(&img_cb[4*1*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech(&img_cr[4*1*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech(&img_cb[4*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech(&img_cr[4*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech(&img_cb[4*3*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech(&img_cr[4*3*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n }else{\n if(left_type){\n filter_mb_edgecv( &img_cb[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);\n filter_mb_edgecv( &img_cr[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);\n }\n filter_mb_edgecv( &img_cb[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgecv( &img_cr[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);\n if(top_type){\n filter_mb_edgech( &img_cb[2*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);\n filter_mb_edgech( &img_cr[2*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);\n }\n filter_mb_edgech( &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech( &img_cr[2*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n }\n }\n return;\n } else {\n LOCAL_ALIGNED_8(int16_t, bS, [2], [4][4]);\n int edges;\n if( IS_8x8DCT(mb_type) && (h->cbp&7) == 7 && !chroma444 ) {\n edges = 4;\n AV_WN64A(bS[0][0], 0x0002000200020002ULL);\n AV_WN64A(bS[0][2], 0x0002000200020002ULL);\n AV_WN64A(bS[1][0], 0x0002000200020002ULL);\n AV_WN64A(bS[1][2], 0x0002000200020002ULL);\n } else {\n int mask_edge1 = (3*(((5*mb_type)>>5)&1)) | (mb_type>>4);\n int mask_edge0 = 3*((mask_edge1>>1) & ((5*left_type)>>5)&1);\n int step = 1+(mb_type>>24);\n edges = 4 - 3*((mb_type>>3) & !(h->cbp & 15));\n h->h264dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache,\n h->list_count==2, edges, step, mask_edge0, mask_edge1, FIELD_PICTURE);\n }\n if( IS_INTRA(left_type) )\n AV_WN64A(bS[0][0], 0x0004000400040004ULL);\n if( IS_INTRA(top_type) )\n AV_WN64A(bS[1][0], FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL);\n#define FILTER(hv,dir,edge,intra)\\\n if(AV_RN64A(bS[dir][edge])) { \\\n filter_mb_edge##hv( &img_y[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qp : qp##dir, a, b, h, intra );\\\n if(chroma){\\\n if(chroma444){\\\n filter_mb_edge##hv( &img_cb[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\\\n filter_mb_edge##hv( &img_cr[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\\\n } else if(!(edge&1)) {\\\n filter_mb_edgec##hv( &img_cb[2*edge*(dir?uvlinesize:1<<pixel_shift)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\\\n filter_mb_edgec##hv( &img_cr[2*edge*(dir?uvlinesize:1<<pixel_shift)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\\\n }\\\n }\\\n }\n if(left_type)\n FILTER(v,0,0,1);\n if( edges == 1 ) {\n if(top_type)\n FILTER(h,1,0,1);\n } else if( IS_8x8DCT(mb_type) ) {\n FILTER(v,0,2,0);\n if(top_type)\n FILTER(h,1,0,1);\n FILTER(h,1,2,0);\n } else {\n FILTER(v,0,1,0);\n FILTER(v,0,2,0);\n FILTER(v,0,3,0);\n if(top_type)\n FILTER(h,1,0,1);\n FILTER(h,1,1,0);\n FILTER(h,1,2,0);\n FILTER(h,1,3,0);\n }\n#undef FILTER\n }\n}', 'static av_always_inline void filter_mb_edgeh(uint8_t *pix, int stride,\n const int16_t bS[4],\n unsigned int qp, int a, int b,\n H264Context *h, int intra)\n{\n const unsigned int index_a = qp + a;\n const int alpha = alpha_table[index_a];\n const int beta = beta_table[qp + b];\n if (alpha ==0 || beta == 0) return;\n if( bS[0] < 4 || !intra ) {\n int8_t tc[4];\n tc[0] = tc0_table[index_a][bS[0]];\n tc[1] = tc0_table[index_a][bS[1]];\n tc[2] = tc0_table[index_a][bS[2]];\n tc[3] = tc0_table[index_a][bS[3]];\n h->h264dsp.h264_v_loop_filter_luma(pix, stride, alpha, beta, tc);\n } else {\n h->h264dsp.h264_v_loop_filter_luma_intra(pix, stride, alpha, beta);\n }\n}']
36,563
1
https://github.com/openssl/openssl/blob/9b10986d7742a5105ac8c5f4eba8b103caf57ae9/crypto/bn/bn_sqr.c/#L124
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp) { int i, j, max; const BN_ULONG *ap; BN_ULONG *rp; max = n * 2; ap = a; rp = r; rp[0] = rp[max - 1] = 0; rp++; j = n; if (--j > 0) { ap++; rp[j] = bn_mul_words(rp, ap, j, ap[-1]); rp += 2; } for (i = n - 2; i > 0; i--) { j--; ap++; rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]); rp += 2; } bn_add_words(r, r, r, max); bn_sqr_words(tmp, a, n); bn_add_words(r, r, tmp, max); }
['static EVP_PKEY *b2i_dss(const unsigned char **in,\n unsigned int bitlen, int ispub)\n{\n const unsigned char *p = *in;\n EVP_PKEY *ret = NULL;\n DSA *dsa = NULL;\n BN_CTX *ctx = NULL;\n unsigned int nbyte;\n BIGNUM *pbn = NULL, *qbn = NULL, *gbn = NULL, *priv_key = NULL;\n BIGNUM *pub_key = NULL;\n nbyte = (bitlen + 7) >> 3;\n dsa = DSA_new();\n ret = EVP_PKEY_new();\n if (dsa == NULL || ret == NULL)\n goto memerr;\n if (!read_lebn(&p, nbyte, &pbn))\n goto memerr;\n if (!read_lebn(&p, 20, &qbn))\n goto memerr;\n if (!read_lebn(&p, nbyte, &gbn))\n goto memerr;\n if (ispub) {\n if (!read_lebn(&p, nbyte, &pub_key))\n goto memerr;\n } else {\n if (!read_lebn(&p, 20, &priv_key))\n goto memerr;\n pub_key = BN_new();\n if (pub_key == NULL)\n goto memerr;\n if ((ctx = BN_CTX_new()) == NULL)\n goto memerr;\n if (!BN_mod_exp(pub_key, gbn, priv_key, pbn, ctx))\n goto memerr;\n BN_CTX_free(ctx);\n ctx = NULL;\n }\n if (!DSA_set0_pqg(dsa, pbn, qbn, gbn))\n goto memerr;\n pbn = qbn = gbn = NULL;\n if (!DSA_set0_key(dsa, pub_key, priv_key))\n goto memerr;\n pub_key = priv_key = NULL;\n if (!EVP_PKEY_set1_DSA(ret, dsa))\n goto memerr;\n DSA_free(dsa);\n *in = p;\n return ret;\n memerr:\n PEMerr(PEM_F_B2I_DSS, ERR_R_MALLOC_FAILURE);\n DSA_free(dsa);\n BN_free(pbn);\n BN_free(qbn);\n BN_free(gbn);\n BN_free(pub_key);\n BN_free(priv_key);\n EVP_PKEY_free(ret);\n BN_CTX_free(ctx);\n return NULL;\n}', 'static int read_lebn(const unsigned char **in, unsigned int nbyte, BIGNUM **r)\n{\n *r = BN_lebin2bn(*in, nbyte, NULL);\n if (*r == NULL)\n return 0;\n *in += nbyte;\n return 1;\n}', 'BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return NULL;\n bn_check_top(ret);\n s += len;\n for ( ; len > 0 && s[-1] == 0; s--, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return ret;\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n s--;\n l = (l << 8L) | *s;\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\n return ret;\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_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_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, wmask, window0;\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 = p->top * BN_BITS2;\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 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 (!a->neg) {\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 }\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_mont_fixed_top(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(&am, a, m, ctx))\n goto err;\n if (!bn_to_mont_fixed_top(&am, &am, mont, ctx))\n goto err;\n } else if (!bn_to_mont_fixed_top(&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 window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits > 0) {\n if (bits < stride)\n stride = bits;\n bits -= stride;\n wvalue = bn_get_bits(p, bits);\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 window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7) {\n while (bits > 0) {\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 bn_get_bits5(p->d, bits -= 5));\n }\n } else {\n while (bits > 0) {\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\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_mul_mont_fixed_top(&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_mul_mont_fixed_top(&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 window0 = (bits - 1) % window + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n wmask = (1 << window) - 1;\n while (bits > 0) {\n for (i = 0; i < window; i++)\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n bits -= window;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!bn_mul_mont_fixed_top(&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_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_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
36,564
0
https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/test/bntest.c/#L1246
int test_gf2m_add(BIO *bp) { BIGNUM *a, *b, *c; int i, ret = 0; a = BN_new(); b = BN_new(); c = BN_new(); for (i = 0; i < num0; i++) { BN_rand(a, 512, 0, 0); BN_copy(b, BN_value_one()); a->neg = rand_neg(); b->neg = rand_neg(); BN_GF2m_add(c, a, b); if ((BN_is_odd(a) && BN_is_odd(c)) || (!BN_is_odd(a) && !BN_is_odd(c))) { fprintf(stderr, "GF(2^m) addition test (a) failed!\n"); goto err; } BN_GF2m_add(c, c, c); if (!BN_is_zero(c)) { fprintf(stderr, "GF(2^m) addition test (b) failed!\n"); goto err; } } ret = 1; err: BN_free(a); BN_free(b); BN_free(c); return ret; }
['int test_gf2m_add(BIO *bp)\n{\n BIGNUM *a, *b, *c;\n int i, ret = 0;\n a = BN_new();\n b = BN_new();\n c = BN_new();\n for (i = 0; i < num0; i++) {\n BN_rand(a, 512, 0, 0);\n BN_copy(b, BN_value_one());\n a->neg = rand_neg();\n b->neg = rand_neg();\n BN_GF2m_add(c, a, b);\n if ((BN_is_odd(a) && BN_is_odd(c))\n || (!BN_is_odd(a) && !BN_is_odd(c))) {\n fprintf(stderr, "GF(2^m) addition test (a) failed!\\n");\n goto err;\n }\n BN_GF2m_add(c, c, c);\n if (!BN_is_zero(c)) {\n fprintf(stderr, "GF(2^m) addition test (b) failed!\\n");\n goto err;\n }\n }\n ret = 1;\n err:\n BN_free(a);\n BN_free(b);\n BN_free(c);\n return ret;\n}', 'BIGNUM *BN_new(void)\n{\n BIGNUM *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->flags = BN_FLG_MALLOCED;\n bn_check_top(ret);\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}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(0, rnd, bits, top, bottom);\n}', 'static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)\n{\n unsigned char *buf = NULL;\n int ret = 0, bit, bytes, mask;\n time_t tim;\n if (bits < 0 || (bits == 1 && top > 0)) {\n BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n return 0;\n }\n if (bits == 0) {\n BN_zero(rnd);\n return 1;\n }\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 time(&tim);\n RAND_add(&tim, sizeof(tim), 0.0);\n if (pseudorand) {\n if (RAND_bytes(buf, bytes) <= 0)\n goto err;\n } else {\n if (RAND_bytes(buf, bytes) <= 0)\n goto err;\n }\n if (pseudorand == 2) {\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);\n}', 'void CRYPTO_clear_free(void *str, size_t num)\n{\n if (str == NULL)\n return;\n if (num)\n OPENSSL_cleanse(str, num);\n CRYPTO_free(str);\n}', 'const BIGNUM *BN_value_one(void)\n{\n static const BN_ULONG data_one = 1L;\n static const BIGNUM const_one =\n { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };\n return (&const_one);\n}', 'int rand_neg(void)\n{\n static unsigned int neg = 0;\n static int sign[8] = { 0, 0, 0, 1, 1, 0, 1, 1 };\n return (sign[(neg++) % 8]);\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n return (a->top > 0) && (a->d[0] & 1);\n}']
36,565
0
https://github.com/openssl/openssl/blob/e3713c365c2657236439fea00822a43aa396d112/ssl/record/ssl3_record.c/#L1172
int n_ssl3_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int sending) { unsigned char *mac_sec, *seq; const EVP_MD_CTX *hash; unsigned char *p, rec_char; size_t md_size; size_t npad; int t; if (sending) { 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 0; md_size = t; npad = (48 / md_size) * md_size; if (!sending && EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE && ssl3_cbc_record_digest_supported(hash)) { unsigned char header[75]; size_t 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++] = (unsigned char)(rec->length >> 8); header[j++] = (unsigned char)(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 0; } else { unsigned int md_size_u; EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); if (md_ctx == NULL) return 0; 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 0; } EVP_MD_CTX_free(md_ctx); } ssl3_record_sequence_update(seq); return 1; }
['int n_ssl3_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int sending)\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 size_t npad;\n int t;\n if (sending) {\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 0;\n md_size = t;\n npad = (48 / md_size) * md_size;\n if (!sending &&\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 size_t 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++] = (unsigned char)(rec->length >> 8);\n header[j++] = (unsigned char)(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 0;\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 0;\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 0;\n }\n EVP_MD_CTX_free(md_ctx);\n }\n ssl3_record_sequence_update(seq);\n return 1;\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 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 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}']
36,566
0
https://github.com/libav/libav/blob/67ce33162aa93bee1a5f9e8d6f00060329fa67da/libavcodec/vp3.c/#L2157
static int vp3_decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { Vp3DecodeContext *s = avctx->priv_data; GetBitContext gb; static int counter = 0; int i; init_get_bits(&gb, buf, buf_size * 8); if (s->theora && get_bits1(&gb)) { av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n"); return -1; } s->keyframe = !get_bits1(&gb); if (!s->theora) skip_bits(&gb, 1); s->last_quality_index = s->quality_index; s->nqis=0; do{ s->qis[s->nqis++]= get_bits(&gb, 6); } while(s->theora >= 0x030200 && s->nqis<3 && get_bits1(&gb)); s->quality_index= s->qis[0]; if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n", s->keyframe?"key":"", counter, s->quality_index); counter++; if (s->quality_index != s->last_quality_index) { init_dequantizer(s); init_loop_filter(s); } if (s->keyframe) { if (!s->theora) { skip_bits(&gb, 4); skip_bits(&gb, 4); if (s->version) { s->version = get_bits(&gb, 5); if (counter == 1) av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version); } } if (s->version || s->theora) { if (get_bits1(&gb)) av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n"); skip_bits(&gb, 2); } if (s->last_frame.data[0] == s->golden_frame.data[0]) { if (s->golden_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); s->last_frame= s->golden_frame; } else { if (s->golden_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); if (s->last_frame.data[0]) avctx->release_buffer(avctx, &s->last_frame); } s->golden_frame.reference = 3; if(avctx->get_buffer(avctx, &s->golden_frame) < 0) { av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } s->current_frame= s->golden_frame; if (!s->pixel_addresses_initialized) { if (!s->flipped_image) vp3_calculate_pixel_addresses(s); else theora_calculate_pixel_addresses(s); s->pixel_addresses_initialized = 1; } } else { s->current_frame.reference = 3; if (!s->pixel_addresses_initialized) { av_log(s->avctx, AV_LOG_ERROR, "vp3: first frame not a keyframe\n"); return -1; } if(avctx->get_buffer(avctx, &s->current_frame) < 0) { av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } } s->current_frame.qscale_table= s->qscale_table; s->current_frame.qstride= 0; init_frame(s, &gb); #if KEYFRAMES_ONLY if (!s->keyframe) { memcpy(s->current_frame.data[0], s->golden_frame.data[0], s->current_frame.linesize[0] * s->height); memcpy(s->current_frame.data[1], s->golden_frame.data[1], s->current_frame.linesize[1] * s->height / 2); memcpy(s->current_frame.data[2], s->golden_frame.data[2], s->current_frame.linesize[2] * s->height / 2); } else { #endif if (unpack_superblocks(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n"); return -1; } if (unpack_modes(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n"); return -1; } if (unpack_vectors(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n"); return -1; } if (unpack_dct_coeffs(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n"); return -1; } reverse_dc_prediction(s, 0, s->fragment_width, s->fragment_height); if ((avctx->flags & CODEC_FLAG_GRAY) == 0) { reverse_dc_prediction(s, s->fragment_start[1], s->fragment_width / 2, s->fragment_height / 2); reverse_dc_prediction(s, s->fragment_start[2], s->fragment_width / 2, s->fragment_height / 2); } for (i = 0; i < s->macroblock_height; i++) render_slice(s, i); apply_loop_filter(s); #if KEYFRAMES_ONLY } #endif *data_size=sizeof(AVFrame); *(AVFrame*)data= s->current_frame; if ((s->last_frame.data[0]) && (s->last_frame.data[0] != s->golden_frame.data[0])) avctx->release_buffer(avctx, &s->last_frame); s->last_frame= s->current_frame; s->current_frame.data[0]= NULL; return buf_size; }
['static int vp3_decode_frame(AVCodecContext *avctx,\n void *data, int *data_size,\n const uint8_t *buf, int buf_size)\n{\n Vp3DecodeContext *s = avctx->priv_data;\n GetBitContext gb;\n static int counter = 0;\n int i;\n init_get_bits(&gb, buf, buf_size * 8);\n if (s->theora && get_bits1(&gb))\n {\n av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\\n");\n return -1;\n }\n s->keyframe = !get_bits1(&gb);\n if (!s->theora)\n skip_bits(&gb, 1);\n s->last_quality_index = s->quality_index;\n s->nqis=0;\n do{\n s->qis[s->nqis++]= get_bits(&gb, 6);\n } while(s->theora >= 0x030200 && s->nqis<3 && get_bits1(&gb));\n s->quality_index= s->qis[0];\n if (s->avctx->debug & FF_DEBUG_PICT_INFO)\n av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\\n",\n s->keyframe?"key":"", counter, s->quality_index);\n counter++;\n if (s->quality_index != s->last_quality_index) {\n init_dequantizer(s);\n init_loop_filter(s);\n }\n if (s->keyframe) {\n if (!s->theora)\n {\n skip_bits(&gb, 4);\n skip_bits(&gb, 4);\n if (s->version)\n {\n s->version = get_bits(&gb, 5);\n if (counter == 1)\n av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\\n", s->version);\n }\n }\n if (s->version || s->theora)\n {\n if (get_bits1(&gb))\n av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\\n");\n skip_bits(&gb, 2);\n }\n if (s->last_frame.data[0] == s->golden_frame.data[0]) {\n if (s->golden_frame.data[0])\n avctx->release_buffer(avctx, &s->golden_frame);\n s->last_frame= s->golden_frame;\n } else {\n if (s->golden_frame.data[0])\n avctx->release_buffer(avctx, &s->golden_frame);\n if (s->last_frame.data[0])\n avctx->release_buffer(avctx, &s->last_frame);\n }\n s->golden_frame.reference = 3;\n if(avctx->get_buffer(avctx, &s->golden_frame) < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\\n");\n return -1;\n }\n s->current_frame= s->golden_frame;\n if (!s->pixel_addresses_initialized)\n {\n if (!s->flipped_image)\n vp3_calculate_pixel_addresses(s);\n else\n theora_calculate_pixel_addresses(s);\n s->pixel_addresses_initialized = 1;\n }\n } else {\n s->current_frame.reference = 3;\n if (!s->pixel_addresses_initialized) {\n av_log(s->avctx, AV_LOG_ERROR, "vp3: first frame not a keyframe\\n");\n return -1;\n }\n if(avctx->get_buffer(avctx, &s->current_frame) < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\\n");\n return -1;\n }\n }\n s->current_frame.qscale_table= s->qscale_table;\n s->current_frame.qstride= 0;\n init_frame(s, &gb);\n#if KEYFRAMES_ONLY\nif (!s->keyframe) {\n memcpy(s->current_frame.data[0], s->golden_frame.data[0],\n s->current_frame.linesize[0] * s->height);\n memcpy(s->current_frame.data[1], s->golden_frame.data[1],\n s->current_frame.linesize[1] * s->height / 2);\n memcpy(s->current_frame.data[2], s->golden_frame.data[2],\n s->current_frame.linesize[2] * s->height / 2);\n} else {\n#endif\n if (unpack_superblocks(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\\n");\n return -1;\n }\n if (unpack_modes(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\\n");\n return -1;\n }\n if (unpack_vectors(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\\n");\n return -1;\n }\n if (unpack_dct_coeffs(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\\n");\n return -1;\n }\n reverse_dc_prediction(s, 0, s->fragment_width, s->fragment_height);\n if ((avctx->flags & CODEC_FLAG_GRAY) == 0) {\n reverse_dc_prediction(s, s->fragment_start[1],\n s->fragment_width / 2, s->fragment_height / 2);\n reverse_dc_prediction(s, s->fragment_start[2],\n s->fragment_width / 2, s->fragment_height / 2);\n }\n for (i = 0; i < s->macroblock_height; i++)\n render_slice(s, i);\n apply_loop_filter(s);\n#if KEYFRAMES_ONLY\n}\n#endif\n *data_size=sizeof(AVFrame);\n *(AVFrame*)data= s->current_frame;\n if ((s->last_frame.data[0]) &&\n (s->last_frame.data[0] != s->golden_frame.data[0]))\n avctx->release_buffer(avctx, &s->last_frame);\n s->last_frame= s->current_frame;\n s->current_frame.data[0]= NULL;\n return buf_size;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size= (bit_size+7)>>3;\n if(buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer= buffer;\n s->size_in_bits= bit_size;\n s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index=0;\n#elif defined LIBMPEG2_BITSTREAM_READER\n s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n s->bit_count = 16 + 8*((intptr_t)buffer&1);\n skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n s->bit_count = 32 + 8*((intptr_t)buffer&3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n int index= s->index;\n uint8_t result= s->buffer[ index>>3 ];\n#ifdef ALT_BITSTREAM_READER_LE\n result>>= (index&0x07);\n result&= 1;\n#else\n result<<= (index&0x07);\n result>>= 8 - 1;\n#endif\n index++;\n s->index= index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}']
36,567
0
https://github.com/openssl/openssl/blob/f61c5ca6ca183bf0a51651857e3efb02a98889ad/ssl/statem/statem_clnt.c/#L2912
int tls_construct_client_verify(SSL *s, WPACKET *pkt) { EVP_PKEY *pkey; const EVP_MD *md = s->s3->tmp.md[s->cert->key - s->cert->pkeys]; EVP_MD_CTX *mctx = NULL; unsigned u = 0; long hdatalen = 0; void *hdata; unsigned char *sig = NULL; mctx = EVP_MD_CTX_new(); if (mctx == NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE); goto err; } pkey = s->cert->key->privatekey; hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata); if (hdatalen <= 0) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR); goto err; } if (SSL_USE_SIGALGS(s)&& !tls12_get_sigandhash(pkt, pkey, md)) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR); goto err; } #ifdef SSL_DEBUG fprintf(stderr, "Using client alg %s\n", EVP_MD_name(md)); #endif sig = OPENSSL_malloc(EVP_PKEY_size(pkey)); if (sig == NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE); goto err; } if (!EVP_SignInit_ex(mctx, md, NULL) || !EVP_SignUpdate(mctx, hdata, hdatalen) || (s->version == SSL3_VERSION && !EVP_MD_CTX_ctrl(mctx, EVP_CTRL_SSL3_MASTER_SECRET, (int)s->session->master_key_length, s->session->master_key)) || !EVP_SignFinal(mctx, sig, &u, pkey)) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_EVP_LIB); goto err; } #ifndef OPENSSL_NO_GOST { int pktype = EVP_PKEY_id(pkey); if (pktype == NID_id_GostR3410_2001 || pktype == NID_id_GostR3410_2012_256 || pktype == NID_id_GostR3410_2012_512) BUF_reverse(sig, NULL, u); } #endif if (!WPACKET_sub_memcpy_u16(pkt, sig, u)) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR); goto err; } if (!ssl3_digest_cached_records(s, 0)) goto err; OPENSSL_free(sig); EVP_MD_CTX_free(mctx); return 1; err: OPENSSL_free(sig); EVP_MD_CTX_free(mctx); ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); return 0; }
['int tls_construct_client_verify(SSL *s, WPACKET *pkt)\n{\n EVP_PKEY *pkey;\n const EVP_MD *md = s->s3->tmp.md[s->cert->key - s->cert->pkeys];\n EVP_MD_CTX *mctx = NULL;\n unsigned u = 0;\n long hdatalen = 0;\n void *hdata;\n unsigned char *sig = NULL;\n mctx = EVP_MD_CTX_new();\n if (mctx == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n pkey = s->cert->key->privatekey;\n hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);\n if (hdatalen <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (SSL_USE_SIGALGS(s)&& !tls12_get_sigandhash(pkt, pkey, md)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n#ifdef SSL_DEBUG\n fprintf(stderr, "Using client alg %s\\n", EVP_MD_name(md));\n#endif\n sig = OPENSSL_malloc(EVP_PKEY_size(pkey));\n if (sig == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!EVP_SignInit_ex(mctx, md, NULL)\n || !EVP_SignUpdate(mctx, hdata, hdatalen)\n || (s->version == SSL3_VERSION\n && !EVP_MD_CTX_ctrl(mctx, EVP_CTRL_SSL3_MASTER_SECRET,\n (int)s->session->master_key_length,\n s->session->master_key))\n || !EVP_SignFinal(mctx, sig, &u, pkey)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_EVP_LIB);\n goto err;\n }\n#ifndef OPENSSL_NO_GOST\n {\n int pktype = EVP_PKEY_id(pkey);\n if (pktype == NID_id_GostR3410_2001\n || pktype == NID_id_GostR3410_2012_256\n || pktype == NID_id_GostR3410_2012_512)\n BUF_reverse(sig, NULL, u);\n }\n#endif\n if (!WPACKET_sub_memcpy_u16(pkt, sig, u)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!ssl3_digest_cached_records(s, 0))\n goto err;\n OPENSSL_free(sig);\n EVP_MD_CTX_free(mctx);\n return 1;\n err:\n OPENSSL_free(sig);\n EVP_MD_CTX_free(mctx);\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);\n return 0;\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}', 'long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)\n{\n long ret;\n if (b == NULL)\n return 0;\n if ((b->method == NULL) || (b->method->ctrl == NULL)) {\n BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);\n return -2;\n }\n if (b->callback != NULL || b->callback_ex != NULL) {\n ret = bio_call_callback(b, BIO_CB_CTRL, parg, 0, cmd, larg, 1L, NULL);\n if (ret <= 0)\n return ret;\n }\n ret = b->method->ctrl(b, cmd, larg, parg);\n if (b->callback != NULL || b->callback_ex != NULL)\n ret = bio_call_callback(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, 0, cmd,\n larg, ret, NULL);\n return ret;\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx);\n OPENSSL_free(ctx);\n}']
36,568
0
https://github.com/openssl/openssl/blob/acc00492130d53d2d6a25bbe5409240aeba98420/crypto/ts/ts_rsp_verify.c/#L195
static int ts_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted, X509 *signer, STACK_OF(X509) **chain) { X509_STORE_CTX *cert_ctx = NULL; int i; int ret = 0; *chain = NULL; cert_ctx = X509_STORE_CTX_new(); if (cert_ctx == NULL) { TSerr(TS_F_TS_VERIFY_CERT, ERR_R_MALLOC_FAILURE); goto err; } if (!X509_STORE_CTX_init(cert_ctx, store, signer, untrusted)) goto end; X509_STORE_CTX_set_purpose(cert_ctx, X509_PURPOSE_TIMESTAMP_SIGN); i = X509_verify_cert(cert_ctx); if (i <= 0) { int j = X509_STORE_CTX_get_error(cert_ctx); TSerr(TS_F_TS_VERIFY_CERT, TS_R_CERTIFICATE_VERIFY_ERROR); ERR_add_error_data(2, "Verify error:", X509_verify_cert_error_string(j)); goto err; } *chain = X509_STORE_CTX_get1_chain(cert_ctx); ret = 1; goto end; err: ret = 0; end: X509_STORE_CTX_free(cert_ctx); return ret; }
['static int ts_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted,\n X509 *signer, STACK_OF(X509) **chain)\n{\n X509_STORE_CTX *cert_ctx = NULL;\n int i;\n int ret = 0;\n *chain = NULL;\n cert_ctx = X509_STORE_CTX_new();\n if (cert_ctx == NULL) {\n TSerr(TS_F_TS_VERIFY_CERT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!X509_STORE_CTX_init(cert_ctx, store, signer, untrusted))\n goto end;\n X509_STORE_CTX_set_purpose(cert_ctx, X509_PURPOSE_TIMESTAMP_SIGN);\n i = X509_verify_cert(cert_ctx);\n if (i <= 0) {\n int j = X509_STORE_CTX_get_error(cert_ctx);\n TSerr(TS_F_TS_VERIFY_CERT, TS_R_CERTIFICATE_VERIFY_ERROR);\n ERR_add_error_data(2, "Verify error:",\n X509_verify_cert_error_string(j));\n goto err;\n }\n *chain = X509_STORE_CTX_get1_chain(cert_ctx);\n ret = 1;\n goto end;\nerr:\n ret = 0;\nend:\n X509_STORE_CTX_free(cert_ctx);\n return ret;\n}', 'X509_STORE_CTX *X509_STORE_CTX_new(void)\n{\n X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));\n if (ctx == NULL) {\n X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n return 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}', 'void X509_STORE_CTX_free(X509_STORE_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n X509_STORE_CTX_cleanup(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
36,569
0
https://github.com/openssl/openssl/blob/9f9442918aeaed5dc2442d81ab8d29fe3e1fb906/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); if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0) BN_set_flags(a, BN_FLG_CONSTTIME); a->top = b->top; a->neg = b->neg; bn_check_top(a); return a; }
['static int srp_Verify_N_and_g(const BIGNUM *N, const BIGNUM *g)\n{\n BN_CTX *bn_ctx = BN_CTX_new();\n BIGNUM *p = BN_new();\n BIGNUM *r = BN_new();\n int ret =\n g != NULL && N != NULL && bn_ctx != NULL && BN_is_odd(N) &&\n BN_is_prime_ex(N, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&\n p != NULL && BN_rshift1(p, N) &&\n BN_is_prime_ex(p, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&\n r != NULL &&\n BN_mod_exp(r, g, p, N, bn_ctx) &&\n BN_add_word(r, 1) && BN_cmp(r, N) == 0;\n BN_free(r);\n BN_free(p);\n BN_CTX_free(bn_ctx);\n return ret;\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n return (a->top > 0) && (a->d[0] & 1);\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 *a, int checks, BN_CTX *ctx_passed,\n int do_trial_division, BN_GENCB *cb)\n{\n int i, j, ret = -1;\n int k;\n BN_CTX *ctx = NULL;\n BIGNUM *A1, *A1_odd, *check;\n BN_MONT_CTX *mont = NULL;\n if (BN_cmp(a, BN_value_one()) <= 0)\n return 0;\n if (checks == BN_prime_checks)\n checks = BN_prime_checks_for_size(BN_num_bits(a));\n if (!BN_is_odd(a))\n return BN_is_word(a, 2);\n if (do_trial_division) {\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG mod = BN_mod_word(a, primes[i]);\n if (mod == (BN_ULONG)-1)\n goto err;\n if (mod == 0)\n return BN_is_word(a, primes[i]);\n }\n if (!BN_GENCB_call(cb, 1, -1))\n goto err;\n }\n if (ctx_passed != NULL)\n ctx = ctx_passed;\n else if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n A1 = BN_CTX_get(ctx);\n A1_odd = BN_CTX_get(ctx);\n check = BN_CTX_get(ctx);\n if (check == NULL)\n goto err;\n if (!BN_copy(A1, a))\n goto err;\n if (!BN_sub_word(A1, 1))\n goto err;\n if (BN_is_zero(A1)) {\n ret = 0;\n goto err;\n }\n k = 1;\n while (!BN_is_bit_set(A1, k))\n k++;\n if (!BN_rshift(A1_odd, A1, k))\n goto err;\n mont = BN_MONT_CTX_new();\n if (mont == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, a, ctx))\n goto err;\n for (i = 0; i < checks; i++) {\n if (!BN_priv_rand_range(check, A1))\n goto err;\n if (!BN_add_word(check, 1))\n goto err;\n j = witness(check, a, A1, A1_odd, k, ctx, mont);\n if (j == -1)\n goto err;\n if (j) {\n ret = 0;\n goto err;\n }\n if (!BN_GENCB_call(cb, 1, i))\n goto err;\n }\n ret = 1;\n err:\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n if (ctx_passed == NULL)\n BN_CTX_free(ctx);\n }\n BN_MONT_CTX_free(mont);\n return (ret);\n}', 'int BN_cmp(const BIGNUM *a, const BIGNUM *b)\n{\n int i;\n int gt, lt;\n BN_ULONG t1, t2;\n if ((a == NULL) || (b == NULL)) {\n if (a != NULL)\n return (-1);\n else if (b != NULL)\n return (1);\n else\n return (0);\n }\n bn_check_top(a);\n bn_check_top(b);\n if (a->neg != b->neg) {\n if (a->neg)\n return (-1);\n else\n return (1);\n }\n if (a->neg == 0) {\n gt = 1;\n lt = -1;\n } else {\n gt = -1;\n lt = 1;\n }\n if (a->top > b->top)\n return (gt);\n if (a->top < b->top)\n return (lt);\n for (i = a->top - 1; i >= 0; i--) {\n t1 = a->d[i];\n t2 = b->d[i];\n if (t1 > t2)\n return (gt);\n if (t1 < t2)\n return (lt);\n }\n return (0);\n}', 'int BN_rshift1(BIGNUM *r, const BIGNUM *a)\n{\n BN_ULONG *ap, *rp, t, c;\n int i, j;\n bn_check_top(r);\n bn_check_top(a);\n if (BN_is_zero(a)) {\n BN_zero(r);\n return (1);\n }\n i = a->top;\n ap = a->d;\n j = i - (ap[i - 1] == 1);\n if (a != r) {\n if (bn_wexpand(r, j) == NULL)\n return (0);\n r->neg = a->neg;\n }\n rp = r->d;\n t = ap[--i];\n c = (t & 1) ? BN_TBIT : 0;\n if (t >>= 1)\n rp[i] = t;\n while (i > 0) {\n t = ap[--i];\n rp[i] = ((t >> 1) & BN_MASK2) | c;\n c = (t & 1) ? BN_TBIT : 0;\n }\n r->top = j;\n if (!r->top)\n r->neg = 0;\n bn_check_top(r);\n return (1);\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\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_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_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\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(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, 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_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\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_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return (ret);\n}', 'int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!BN_copy(&(recp->N), d))\n return 0;\n BN_zero(&(recp->Nr));\n recp->num_bits = BN_num_bits(d);\n recp->shift = 0;\n return (1);\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}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
36,570
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 decode_subframe(WMAProDecodeCtx *s)\n{\n int offset = s->samples_per_frame;\n int subframe_len = s->samples_per_frame;\n int i;\n int total_samples = s->samples_per_frame * s->avctx->channels;\n int transmit_coeffs = 0;\n int cur_subwoofer_cutoff;\n s->subframe_offset = bitstream_tell(&s->bc);\n for (i = 0; i < s->avctx->channels; i++) {\n s->channel[i].grouped = 0;\n if (offset > s->channel[i].decoded_samples) {\n offset = s->channel[i].decoded_samples;\n subframe_len =\n s->channel[i].subframe_len[s->channel[i].cur_subframe];\n }\n }\n ff_dlog(s->avctx,\n "processing subframe with offset %i len %i\\n", offset, subframe_len);\n s->channels_for_cur_subframe = 0;\n for (i = 0; i < s->avctx->channels; i++) {\n const int cur_subframe = s->channel[i].cur_subframe;\n total_samples -= s->channel[i].decoded_samples;\n if (offset == s->channel[i].decoded_samples &&\n subframe_len == s->channel[i].subframe_len[cur_subframe]) {\n total_samples -= s->channel[i].subframe_len[cur_subframe];\n s->channel[i].decoded_samples +=\n s->channel[i].subframe_len[cur_subframe];\n s->channel_indexes_for_cur_subframe[s->channels_for_cur_subframe] = i;\n ++s->channels_for_cur_subframe;\n }\n }\n if (!total_samples)\n s->parsed_all_subframes = 1;\n ff_dlog(s->avctx, "subframe is part of %i channels\\n",\n s->channels_for_cur_subframe);\n s->table_idx = av_log2(s->samples_per_frame/subframe_len);\n s->num_bands = s->num_sfb[s->table_idx];\n s->cur_sfb_offsets = s->sfb_offsets[s->table_idx];\n cur_subwoofer_cutoff = s->subwoofer_cutoffs[s->table_idx];\n offset += s->samples_per_frame >> 1;\n for (i = 0; i < s->channels_for_cur_subframe; i++) {\n int c = s->channel_indexes_for_cur_subframe[i];\n s->channel[c].coeffs = &s->channel[c].out[offset];\n }\n s->subframe_len = subframe_len;\n s->esc_len = av_log2(s->subframe_len - 1) + 1;\n if (bitstream_read_bit(&s->bc)) {\n int num_fill_bits;\n if (!(num_fill_bits = bitstream_read(&s->bc, 2))) {\n int len = bitstream_read(&s->bc, 4);\n num_fill_bits = bitstream_read(&s->bc, len) + 1;\n }\n if (num_fill_bits >= 0) {\n if (bitstream_tell(&s->bc) + num_fill_bits > s->num_saved_bits) {\n av_log(s->avctx, AV_LOG_ERROR, "invalid number of fill bits\\n");\n return AVERROR_INVALIDDATA;\n }\n bitstream_skip(&s->bc, num_fill_bits);\n }\n }\n if (bitstream_read_bit(&s->bc)) {\n avpriv_request_sample(s->avctx, "Reserved bit");\n return AVERROR_PATCHWELCOME;\n }\n if (decode_channel_transform(s) < 0)\n return AVERROR_INVALIDDATA;\n for (i = 0; i < s->channels_for_cur_subframe; i++) {\n int c = s->channel_indexes_for_cur_subframe[i];\n if ((s->channel[c].transmit_coefs = bitstream_read_bit(&s->bc)))\n transmit_coeffs = 1;\n }\n if (transmit_coeffs) {\n int step;\n int quant_step = 90 * s->bits_per_sample >> 4;\n if ((s->transmit_num_vec_coeffs = bitstream_read_bit(&s->bc))) {\n int num_bits = av_log2((s->subframe_len + 3)/4) + 1;\n for (i = 0; i < s->channels_for_cur_subframe; i++) {\n int c = s->channel_indexes_for_cur_subframe[i];\n int num_vec_coeffs = bitstream_read(&s->bc, num_bits) << 2;\n if (num_vec_coeffs + offset > FF_ARRAY_ELEMS(s->channel[c].out)) {\n av_log(s->avctx, AV_LOG_ERROR, "num_vec_coeffs %d is too large\\n", num_vec_coeffs);\n return AVERROR_INVALIDDATA;\n }\n s->channel[c].num_vec_coeffs = num_vec_coeffs;\n }\n } else {\n for (i = 0; i < s->channels_for_cur_subframe; i++) {\n int c = s->channel_indexes_for_cur_subframe[i];\n s->channel[c].num_vec_coeffs = s->subframe_len;\n }\n }\n step = bitstream_read_signed(&s->bc, 6);\n quant_step += step;\n if (step == -32 || step == 31) {\n const int sign = (step == 31) - 1;\n int quant = 0;\n while (bitstream_tell(&s->bc) + 5 < s->num_saved_bits &&\n (step = bitstream_read(&s->bc, 5)) == 31) {\n quant += 31;\n }\n quant_step += ((quant + step) ^ sign) - sign;\n }\n if (quant_step < 0) {\n av_log(s->avctx, AV_LOG_DEBUG, "negative quant step\\n");\n }\n if (s->channels_for_cur_subframe == 1) {\n s->channel[s->channel_indexes_for_cur_subframe[0]].quant_step = quant_step;\n } else {\n int modifier_len = bitstream_read(&s->bc, 3);\n for (i = 0; i < s->channels_for_cur_subframe; i++) {\n int c = s->channel_indexes_for_cur_subframe[i];\n s->channel[c].quant_step = quant_step;\n if (bitstream_read_bit(&s->bc)) {\n if (modifier_len) {\n s->channel[c].quant_step += bitstream_read(&s->bc, modifier_len) + 1;\n } else\n ++s->channel[c].quant_step;\n }\n }\n }\n if (decode_scale_factors(s) < 0)\n return AVERROR_INVALIDDATA;\n }\n ff_dlog(s->avctx, "BITSTREAM: subframe header length was %i\\n",\n bitstream_tell(&s->bc) - s->subframe_offset);\n for (i = 0; i < s->channels_for_cur_subframe; i++) {\n int c = s->channel_indexes_for_cur_subframe[i];\n if (s->channel[c].transmit_coefs &&\n bitstream_tell(&s->bc) < s->num_saved_bits) {\n decode_coeffs(s, c);\n } else\n memset(s->channel[c].coeffs, 0,\n sizeof(*s->channel[c].coeffs) * subframe_len);\n }\n ff_dlog(s->avctx, "BITSTREAM: subframe length was %i\\n",\n bitstream_tell(&s->bc) - s->subframe_offset);\n if (transmit_coeffs) {\n FFTContext *mdct = &s->mdct_ctx[av_log2(subframe_len) - WMAPRO_BLOCK_MIN_BITS];\n inverse_channel_transform(s);\n for (i = 0; i < s->channels_for_cur_subframe; i++) {\n int c = s->channel_indexes_for_cur_subframe[i];\n const int* sf = s->channel[c].scale_factors;\n int b;\n if (c == s->lfe_channel)\n memset(&s->tmp[cur_subwoofer_cutoff], 0, sizeof(*s->tmp) *\n (subframe_len - cur_subwoofer_cutoff));\n for (b = 0; b < s->num_bands; b++) {\n const int end = FFMIN(s->cur_sfb_offsets[b+1], s->subframe_len);\n const int exp = s->channel[c].quant_step -\n (s->channel[c].max_scale_factor - *sf++) *\n s->channel[c].scale_factor_step;\n const float quant = pow(10.0, exp / 20.0);\n int start = s->cur_sfb_offsets[b];\n s->fdsp.vector_fmul_scalar(s->tmp + start,\n s->channel[c].coeffs + start,\n quant, end - start);\n }\n mdct->imdct_half(mdct, s->channel[c].coeffs, s->tmp);\n }\n }\n wmapro_window(s);\n for (i = 0; i < s->channels_for_cur_subframe; i++) {\n int c = s->channel_indexes_for_cur_subframe[i];\n if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) {\n av_log(s->avctx, AV_LOG_ERROR, "broken subframe\\n");\n return AVERROR_INVALIDDATA;\n }\n ++s->channel[c].cur_subframe;\n }\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}']
36,571
0
https://github.com/openssl/openssl/blob/f1e793cc974094da7da52c6958ad7b972b4a446d/test/exdatatest.c/#L64
static MYOBJ *MYOBJ_new() { static int count = 0; MYOBJ *obj = OPENSSL_malloc(sizeof(*obj)); obj->id = ++count; obj->st = CRYPTO_new_ex_data(CRYPTO_EX_INDEX_APP, obj, &obj->ex_data); return obj; }
['static MYOBJ *MYOBJ_new()\n{\n static int count = 0;\n MYOBJ *obj = OPENSSL_malloc(sizeof(*obj));\n obj->id = ++count;\n obj->st = CRYPTO_new_ex_data(CRYPTO_EX_INDEX_APP, obj, &obj->ex_data);\n return obj;\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}']
36,572
0
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/bn/bn_asm.c/#L212
void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n) { bn_check_num(n); if (n <= 0) return; for (;;) { sqr64(r[0],r[1],a[0]); if (--n == 0) break; sqr64(r[2],r[3],a[1]); if (--n == 0) break; sqr64(r[4],r[5],a[2]); if (--n == 0) break; sqr64(r[6],r[7],a[3]); if (--n == 0) break; a+=4; r+=8; } }
['int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,\n\t BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue,ts=0;\n\tint start=1;\n\tBIGNUM *d;\n\tBIGNUM val[TABLE_SIZE];\n\td= &(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\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_mod(&(val[0]),a,m,ctx)) goto err;\n\tif (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))\n\t\tgoto err;\n\tif (bits <= 17)\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(&(val[i]),&(val[i-1]),d,m,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\tif (!BN_one(r)) 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\tif (!BN_mod_mul(r,r,r,m,ctx))\n\t\t\t\tgoto err;\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(r,r,r,m,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,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\tret=1;\nerr:\n\tctx->tos--;\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(BIGNUM *ret, BIGNUM *a, BIGNUM *b, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint r=0;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(m);\n\tt= &(ctx->bn[ctx->tos++]);\n\tif (a == b)\n\t\t{ if (!BN_sqr(t,a,ctx)) goto err; }\n\telse\n\t\t{ if (!BN_mul(t,a,b,ctx)) goto err; }\n\tif (!BN_mod(ret,t,m,ctx)) goto err;\n\tr=1;\nerr:\n\tctx->tos--;\n\treturn(r);\n\t}', 'int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx)\n\t{\n\tint max,al;\n\tBIGNUM *tmp,*rr;\n#ifdef BN_COUNT\nprintf("BN_sqr %d * %d\\n",a->top,a->top);\n#endif\n\tbn_check_top(a);\n\ttmp= &(ctx->bn[ctx->tos]);\n\trr=(a != r)?r: (&ctx->bn[ctx->tos+1]);\n\tal=a->top;\n\tif (al <= 0)\n\t\t{\n\t\tr->top=0;\n\t\treturn(1);\n\t\t}\n\tmax=(al+al);\n\tif (bn_wexpand(rr,max+1) == NULL) return(0);\n\tr->neg=0;\n\tif (al == 4)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[8];\n\t\tbn_sqr_normal(rr->d,a->d,4,t);\n#else\n\t\tbn_sqr_comba4(rr->d,a->d);\n#endif\n\t\t}\n\telse if (al == 8)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[16];\n\t\tbn_sqr_normal(rr->d,a->d,8,t);\n#else\n\t\tbn_sqr_comba8(rr->d,a->d);\n#endif\n\t\t}\n\telse\n\t\t{\n#if defined(BN_RECURSION)\n\t\tif (al < BN_SQR_RECURSIVE_SIZE_NORMAL)\n\t\t\t{\n\t\t\tBN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];\n\t\t\tbn_sqr_normal(rr->d,a->d,al,t);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tint j,k;\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(a,k*2) == NULL) return(0);\n\t\t\t\tif (bn_wexpand(tmp,k*2) == NULL) return(0);\n\t\t\t\tbn_sqr_recursive(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,max) == NULL) return(0);\n\t\t\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\t}\n#else\n\t\tif (bn_wexpand(tmp,max) == NULL) return(0);\n\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n#endif\n\t\t}\n\trr->top=max;\n\tif ((max > 0) && (rr->d[max-1] == 0)) rr->top--;\n\tif (rr != r) BN_copy(r,rr);\n\treturn(1);\n\t}', 'void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp)\n\t{\n\tint i,j,max;\n\tBN_ULONG *ap,*rp;\n\tmax=n*2;\n\tap=a;\n\trp=r;\n\trp[0]=rp[max-1]=0;\n\trp++;\n\tj=n;\n\tif (--j > 0)\n\t\t{\n\t\tap++;\n\t\trp[j]=bn_mul_words(rp,ap,j,ap[-1]);\n\t\trp+=2;\n\t\t}\n\tfor (i=n-2; i>0; i--)\n\t\t{\n\t\tj--;\n\t\tap++;\n\t\trp[j]=bn_mul_add_words(rp,ap,j,ap[-1]);\n\t\trp+=2;\n\t\t}\n\tbn_add_words(r,r,r,max);\n\tbn_sqr_words(tmp,a,n);\n\tbn_add_words(r,r,tmp,max);\n\t}', 'void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)\n {\n\tbn_check_num(n);\n\tif (n <= 0) return;\n\tfor (;;)\n\t\t{\n\t\tsqr64(r[0],r[1],a[0]);\n\t\tif (--n == 0) break;\n\t\tsqr64(r[2],r[3],a[1]);\n\t\tif (--n == 0) break;\n\t\tsqr64(r[4],r[5],a[2]);\n\t\tif (--n == 0) break;\n\t\tsqr64(r[6],r[7],a[3]);\n\t\tif (--n == 0) break;\n\t\ta+=4;\n\t\tr+=8;\n\t\t}\n\t}']
36,573
0
https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_ctx.c/#L276
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d;\n BIGNUM *val[TABLE_SIZE];\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 BNerr(BN_F_BN_MOD_EXP_SIMPLE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\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(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul(d, val[0], val[0], m, 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(val[i], val[i - 1], d, m, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul(r, r, r, m, ctx))\n goto err;\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(r, r, r, m, ctx))\n goto err;\n }\n if (!BN_mod_mul(r, r, val[wvalue >> 1], m, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\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_ENTRY("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_EXIT(ctx);\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.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) && !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}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int ret = bn_sqr_fixed_top(r, a, ctx);\n bn_correct_top(r);\n bn_check_top(r);\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_ENTRY("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_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
36,574
0
https://github.com/openssl/openssl/blob/80aa9cc985251463a3ad65b0a4d64bf93c70b175/apps/apps.c/#L390
int chopup_args(ARGS *arg, char *buf, int *argc, char **argv[]) { int num,len,i; char *p; *argc=0; *argv=NULL; len=strlen(buf); i=0; if (arg->count == 0) { arg->count=20; arg->data=(char **)OPENSSL_malloc(sizeof(char *)*arg->count); } for (i=0; i<arg->count; i++) arg->data[i]=NULL; num=0; p=buf; for (;;) { if (!*p) break; while (*p && ((*p == ' ') || (*p == '\t') || (*p == '\n'))) p++; if (!*p) break; if (num >= arg->count) { char **tmp_p; int tlen = arg->count + 20; tmp_p = (char **)OPENSSL_realloc(arg->data, sizeof(char *)*tlen); if (tmp_p == NULL) return 0; arg->data = tmp_p; arg->count = tlen; for (i = num; i < arg->count; i++) arg->data[i] = NULL; } arg->data[num++]=p; if ((*p == '\'') || (*p == '\"')) { i= *(p++); arg->data[num-1]++; while (*p && (*p != i)) p++; *p='\0'; } else { while (*p && ((*p != ' ') && (*p != '\t') && (*p != '\n'))) p++; if (*p == '\0') p--; else *p='\0'; } p++; } *argc=num; *argv=arg->data; return(1); }
['int chopup_args(ARGS *arg, char *buf, int *argc, char **argv[])\n\t{\n\tint num,len,i;\n\tchar *p;\n\t*argc=0;\n\t*argv=NULL;\n\tlen=strlen(buf);\n\ti=0;\n\tif (arg->count == 0)\n\t\t{\n\t\targ->count=20;\n\t\targ->data=(char **)OPENSSL_malloc(sizeof(char *)*arg->count);\n\t\t}\n\tfor (i=0; i<arg->count; i++)\n\t\targ->data[i]=NULL;\n\tnum=0;\n\tp=buf;\n\tfor (;;)\n\t\t{\n\t\tif (!*p) break;\n\t\twhile (*p && ((*p == \' \') || (*p == \'\\t\') || (*p == \'\\n\')))\n\t\t\tp++;\n\t\tif (!*p) break;\n\t\tif (num >= arg->count)\n\t\t\t{\n\t\t\tchar **tmp_p;\n\t\t\tint tlen = arg->count + 20;\n\t\t\ttmp_p = (char **)OPENSSL_realloc(arg->data,\n\t\t\t\tsizeof(char *)*tlen);\n\t\t\tif (tmp_p == NULL)\n\t\t\t\treturn 0;\n\t\t\targ->data = tmp_p;\n\t\t\targ->count = tlen;\n\t\t\tfor (i = num; i < arg->count; i++)\n\t\t\t\targ->data[i] = NULL;\n\t\t\t}\n\t\targ->data[num++]=p;\n\t\tif ((*p == \'\\\'\') || (*p == \'\\"\'))\n\t\t\t{\n\t\t\ti= *(p++);\n\t\t\targ->data[num-1]++;\n\t\t\twhile (*p && (*p != i))\n\t\t\t\tp++;\n\t\t\t*p=\'\\0\';\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\twhile (*p && ((*p != \' \') &&\n\t\t\t\t(*p != \'\\t\') && (*p != \'\\n\')))\n\t\t\t\tp++;\n\t\t\tif (*p == \'\\0\')\n\t\t\t\tp--;\n\t\t\telse\n\t\t\t\t*p=\'\\0\';\n\t\t\t}\n\t\tp++;\n\t\t}\n\t*argc=num;\n\t*argv=arg->data;\n\treturn(1);\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}']
36,575
0
https://github.com/openssl/openssl/blob/11af1a2758baefab1157755c508d7b7490155bab/ssl/ssltest.c/#L1111
static DH *get_dh512(void) { DH *dh=NULL; if ((dh=DH_new()) == NULL) return(NULL); dh->p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL); dh->g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL); if ((dh->p == NULL) || (dh->g == NULL)) return(NULL); return(dh); }
['static DH *get_dh512(void)\n\t{\n\tDH *dh=NULL;\n\tif ((dh=DH_new()) == NULL) return(NULL);\n\tdh->p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL);\n\tdh->g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL);\n\tif ((dh->p == NULL) || (dh->g == NULL))\n\t\treturn(NULL);\n\treturn(dh);\n\t}', 'DH *DH_new(void)\n\t{\n\tDH *ret;\n\tret=(DH *)Malloc(sizeof(DH));\n\tif (ret == NULL)\n\t\t{\n\t\tDHerr(DH_F_DH_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->pad=0;\n\tret->version=0;\n\tret->p=NULL;\n\tret->g=NULL;\n\tret->length=0;\n\tret->pub_key=NULL;\n\tret->priv_key=NULL;\n\tret->flags=DH_FLAG_CACHE_MONT_P;\n\tret->method_mont_p=NULL;\n\treturn(ret);\n\t}']
36,576
0
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/des/des_enc.c/#L239
void des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc) { register DES_LONG l,r,t,u; #ifdef DES_PTR register const unsigned char *des_SP=(const unsigned char *)des_SPtrans; #endif #ifndef DES_UNROLL register int i; #endif register DES_LONG *s; r=data[0]; l=data[1]; r=ROTATE(r,29)&0xffffffffL; l=ROTATE(l,29)&0xffffffffL; s=(DES_LONG *)ks; if (enc) { #ifdef DES_UNROLL D_ENCRYPT(l,r, 0); D_ENCRYPT(r,l, 2); D_ENCRYPT(l,r, 4); D_ENCRYPT(r,l, 6); D_ENCRYPT(l,r, 8); D_ENCRYPT(r,l,10); D_ENCRYPT(l,r,12); D_ENCRYPT(r,l,14); D_ENCRYPT(l,r,16); D_ENCRYPT(r,l,18); D_ENCRYPT(l,r,20); D_ENCRYPT(r,l,22); D_ENCRYPT(l,r,24); D_ENCRYPT(r,l,26); D_ENCRYPT(l,r,28); D_ENCRYPT(r,l,30); #else for (i=0; i<32; i+=8) { D_ENCRYPT(l,r,i+0); D_ENCRYPT(r,l,i+2); D_ENCRYPT(l,r,i+4); D_ENCRYPT(r,l,i+6); } #endif } else { #ifdef DES_UNROLL D_ENCRYPT(l,r,30); D_ENCRYPT(r,l,28); D_ENCRYPT(l,r,26); D_ENCRYPT(r,l,24); D_ENCRYPT(l,r,22); D_ENCRYPT(r,l,20); D_ENCRYPT(l,r,18); D_ENCRYPT(r,l,16); D_ENCRYPT(l,r,14); D_ENCRYPT(r,l,12); D_ENCRYPT(l,r,10); D_ENCRYPT(r,l, 8); D_ENCRYPT(l,r, 6); D_ENCRYPT(r,l, 4); D_ENCRYPT(l,r, 2); D_ENCRYPT(r,l, 0); #else for (i=30; i>0; i-=8) { D_ENCRYPT(l,r,i-0); D_ENCRYPT(r,l,i-2); D_ENCRYPT(l,r,i-4); D_ENCRYPT(r,l,i-6); } #endif } data[0]=ROTATE(l,3)&0xffffffffL; data[1]=ROTATE(r,3)&0xffffffffL; l=r=t=u=0; }
['static int ede_cfb64_test(unsigned char *cfb_cipher)\n\t{\n\tdes_key_schedule ks;\n\tint err=0,i,n;\n\tdes_key_sched(&cfb_key,ks);\n\tmemcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));\n\tn=0;\n\tdes_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n,\n\t\t\t DES_ENCRYPT);\n\tdes_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),\n\t\t\t sizeof(plain)-12,ks,ks,ks,\n\t\t\t &cfb_tmp,&n,DES_ENCRYPT);\n\tif (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)\n\t\t{\n\t\terr=1;\n\t\tprintf("ede_cfb_encrypt encrypt error\\n");\n\t\tfor (i=0; i<24; i+=8)\n\t\t\tprintf("%s\\n",pt(&(cfb_buf1[i])));\n\t\t}\n\tmemcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));\n\tn=0;\n\tdes_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,\n\t\t\t &cfb_tmp,&n,DES_DECRYPT);\n\tdes_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),\n\t\t\t sizeof(plain)-17,ks,ks,ks,\n\t\t\t &cfb_tmp,&n,DES_DECRYPT);\n\tif (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)\n\t\t{\n\t\terr=1;\n\t\tprintf("ede_cfb_encrypt decrypt error\\n");\n\t\tfor (i=0; i<24; i+=8)\n\t\t\tprintf("%s\\n",pt(&(cfb_buf2[i])));\n\t\t}\n\treturn(err);\n\t}', 'void des_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,\n\t long length, des_key_schedule ks1, des_key_schedule ks2,\n\t des_key_schedule ks3, des_cblock *ivec, int *num, int enc)\n\t{\n\tregister DES_LONG v0,v1;\n\tregister long l=length;\n\tregister int n= *num;\n\tDES_LONG ti[2];\n\tunsigned char *iv,c,cc;\n\tiv=&(*ivec)[0];\n\tif (enc)\n\t\t{\n\t\twhile (l--)\n\t\t\t{\n\t\t\tif (n == 0)\n\t\t\t\t{\n\t\t\t\tc2l(iv,v0);\n\t\t\t\tc2l(iv,v1);\n\t\t\t\tti[0]=v0;\n\t\t\t\tti[1]=v1;\n\t\t\t\tdes_encrypt3(ti,ks1,ks2,ks3);\n\t\t\t\tv0=ti[0];\n\t\t\t\tv1=ti[1];\n\t\t\t\tiv = &(*ivec)[0];\n\t\t\t\tl2c(v0,iv);\n\t\t\t\tl2c(v1,iv);\n\t\t\t\tiv = &(*ivec)[0];\n\t\t\t\t}\n\t\t\tc= *(in++)^iv[n];\n\t\t\t*(out++)=c;\n\t\t\tiv[n]=c;\n\t\t\tn=(n+1)&0x07;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (l--)\n\t\t\t{\n\t\t\tif (n == 0)\n\t\t\t\t{\n\t\t\t\tc2l(iv,v0);\n\t\t\t\tc2l(iv,v1);\n\t\t\t\tti[0]=v0;\n\t\t\t\tti[1]=v1;\n\t\t\t\tdes_encrypt3(ti,ks1,ks2,ks3);\n\t\t\t\tv0=ti[0];\n\t\t\t\tv1=ti[1];\n\t\t\t\tiv = &(*ivec)[0];\n\t\t\t\tl2c(v0,iv);\n\t\t\t\tl2c(v1,iv);\n\t\t\t\tiv = &(*ivec)[0];\n\t\t\t\t}\n\t\t\tcc= *(in++);\n\t\t\tc=iv[n];\n\t\t\tiv[n]=cc;\n\t\t\t*(out++)=c^cc;\n\t\t\tn=(n+1)&0x07;\n\t\t\t}\n\t\t}\n\tv0=v1=ti[0]=ti[1]=c=cc=0;\n\t*num=n;\n\t}', 'void des_encrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,\n\t des_key_schedule ks3)\n\t{\n\tregister DES_LONG l,r;\n\tl=data[0];\n\tr=data[1];\n\tIP(l,r);\n\tdata[0]=l;\n\tdata[1]=r;\n\tdes_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT);\n\tdes_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT);\n\tdes_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT);\n\tl=data[0];\n\tr=data[1];\n\tFP(r,l);\n\tdata[0]=l;\n\tdata[1]=r;\n\t}', 'void des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc)\n\t{\n\tregister DES_LONG l,r,t,u;\n#ifdef DES_PTR\n\tregister const unsigned char *des_SP=(const unsigned char *)des_SPtrans;\n#endif\n#ifndef DES_UNROLL\n\tregister int i;\n#endif\n\tregister DES_LONG *s;\n\tr=data[0];\n\tl=data[1];\n\tr=ROTATE(r,29)&0xffffffffL;\n\tl=ROTATE(l,29)&0xffffffffL;\n\ts=(DES_LONG *)ks;\n\tif (enc)\n\t\t{\n#ifdef DES_UNROLL\n\t\tD_ENCRYPT(l,r, 0);\n\t\tD_ENCRYPT(r,l, 2);\n\t\tD_ENCRYPT(l,r, 4);\n\t\tD_ENCRYPT(r,l, 6);\n\t\tD_ENCRYPT(l,r, 8);\n\t\tD_ENCRYPT(r,l,10);\n\t\tD_ENCRYPT(l,r,12);\n\t\tD_ENCRYPT(r,l,14);\n\t\tD_ENCRYPT(l,r,16);\n\t\tD_ENCRYPT(r,l,18);\n\t\tD_ENCRYPT(l,r,20);\n\t\tD_ENCRYPT(r,l,22);\n\t\tD_ENCRYPT(l,r,24);\n\t\tD_ENCRYPT(r,l,26);\n\t\tD_ENCRYPT(l,r,28);\n\t\tD_ENCRYPT(r,l,30);\n#else\n\t\tfor (i=0; i<32; i+=8)\n\t\t\t{\n\t\t\tD_ENCRYPT(l,r,i+0);\n\t\t\tD_ENCRYPT(r,l,i+2);\n\t\t\tD_ENCRYPT(l,r,i+4);\n\t\t\tD_ENCRYPT(r,l,i+6);\n\t\t\t}\n#endif\n\t\t}\n\telse\n\t\t{\n#ifdef DES_UNROLL\n\t\tD_ENCRYPT(l,r,30);\n\t\tD_ENCRYPT(r,l,28);\n\t\tD_ENCRYPT(l,r,26);\n\t\tD_ENCRYPT(r,l,24);\n\t\tD_ENCRYPT(l,r,22);\n\t\tD_ENCRYPT(r,l,20);\n\t\tD_ENCRYPT(l,r,18);\n\t\tD_ENCRYPT(r,l,16);\n\t\tD_ENCRYPT(l,r,14);\n\t\tD_ENCRYPT(r,l,12);\n\t\tD_ENCRYPT(l,r,10);\n\t\tD_ENCRYPT(r,l, 8);\n\t\tD_ENCRYPT(l,r, 6);\n\t\tD_ENCRYPT(r,l, 4);\n\t\tD_ENCRYPT(l,r, 2);\n\t\tD_ENCRYPT(r,l, 0);\n#else\n\t\tfor (i=30; i>0; i-=8)\n\t\t\t{\n\t\t\tD_ENCRYPT(l,r,i-0);\n\t\t\tD_ENCRYPT(r,l,i-2);\n\t\t\tD_ENCRYPT(l,r,i-4);\n\t\t\tD_ENCRYPT(r,l,i-6);\n\t\t\t}\n#endif\n\t\t}\n\tdata[0]=ROTATE(l,3)&0xffffffffL;\n\tdata[1]=ROTATE(r,3)&0xffffffffL;\n\tl=r=t=u=0;\n\t}']
36,577
0
https://github.com/libav/libav/blob/391ecc961ced2bde7aecb3053ac35191f838fae8/libavcodec/vc1dec.c/#L3613
static int vc1_decode_p_mb(VC1Context *v) { MpegEncContext *s = &v->s; GetBitContext *gb = &s->gb; int i, j; int mb_pos = s->mb_x + s->mb_y * s->mb_stride; int cbp; int mqdiff, mquant; int ttmb = v->ttfrm; int mb_has_coeffs = 1; int dmv_x, dmv_y; int index, index1; int val, sign; int first_block = 1; int dst_idx, off; int skipped, fourmv; int block_cbp = 0, pat, block_tt = 0, block_intra = 0; mquant = v->pq; if (v->mv_type_is_raw) fourmv = get_bits1(gb); else fourmv = v->mv_type_mb_plane[mb_pos]; if (v->skip_is_raw) skipped = get_bits1(gb); else skipped = v->s.mbskip_table[mb_pos]; if (!fourmv) { if (!skipped) { GET_MVDATA(dmv_x, dmv_y); if (s->mb_intra) { s->current_picture.motion_val[1][s->block_index[0]][0] = 0; s->current_picture.motion_val[1][s->block_index[0]][1] = 0; } s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16; vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0); if (s->mb_intra && !mb_has_coeffs) { GET_MQUANT(); s->ac_pred = get_bits1(gb); cbp = 0; } else if (mb_has_coeffs) { if (s->mb_intra) s->ac_pred = get_bits1(gb); cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); GET_MQUANT(); } else { mquant = v->pq; cbp = 0; } s->current_picture.qscale_table[mb_pos] = mquant; if (!v->ttmbf && !s->mb_intra && mb_has_coeffs) ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); if (!s->mb_intra) vc1_mc_1mv(v, 0); dst_idx = 0; for (i = 0; i < 6; i++) { s->dc_val[0][s->block_index[i]] = 0; dst_idx += i >> 2; val = ((cbp >> (5 - i)) & 1); off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); v->mb_type[0][s->block_index[i]] = s->mb_intra; if (s->mb_intra) { v->a_avail = v->c_avail = 0; if (i == 2 || i == 3 || !s->first_slice_line) v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]]; if (i == 1 || i == 3 || s->mb_x) v->c_avail = v->mb_type[0][s->block_index[i] - 1]; vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i & 4) ? v->codingset2 : v->codingset); if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); if (v->rangeredfrm) for (j = 0; j < 64; j++) s->block[i][j] <<= 1; s->idsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); if (v->pq >= 9 && v->overlap) { if (v->c_avail) v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); if (v->a_avail) v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); } block_cbp |= 0xF << (i << 2); block_intra |= 1 << i; } else if (val) { pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize, (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt); block_cbp |= pat << (i << 2); if (!v->ttmbf && ttmb < 8) ttmb = -1; first_block = 0; } } } else { s->mb_intra = 0; for (i = 0; i < 6; i++) { v->mb_type[0][s->block_index[i]] = 0; s->dc_val[0][s->block_index[i]] = 0; } s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP; s->current_picture.qscale_table[mb_pos] = 0; vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0); vc1_mc_1mv(v, 0); } } else { if (!skipped ) { int intra_count = 0, coded_inter = 0; int is_intra[6], is_coded[6]; cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); for (i = 0; i < 6; i++) { val = ((cbp >> (5 - i)) & 1); s->dc_val[0][s->block_index[i]] = 0; s->mb_intra = 0; if (i < 4) { dmv_x = dmv_y = 0; s->mb_intra = 0; mb_has_coeffs = 0; if (val) { GET_MVDATA(dmv_x, dmv_y); } vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0); if (!s->mb_intra) vc1_mc_4mv_luma(v, i, 0, 0); intra_count += s->mb_intra; is_intra[i] = s->mb_intra; is_coded[i] = mb_has_coeffs; } if (i & 4) { is_intra[i] = (intra_count >= 3); is_coded[i] = val; } if (i == 4) vc1_mc_4mv_chroma(v, 0); v->mb_type[0][s->block_index[i]] = is_intra[i]; if (!coded_inter) coded_inter = !is_intra[i] & is_coded[i]; } dst_idx = 0; if (!intra_count && !coded_inter) goto end; GET_MQUANT(); s->current_picture.qscale_table[mb_pos] = mquant; { int intrapred = 0; for (i = 0; i < 6; i++) if (is_intra[i]) { if (((!s->first_slice_line || (i == 2 || i == 3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]]) || ((s->mb_x || (i == 1 || i == 3)) && v->mb_type[0][s->block_index[i] - 1])) { intrapred = 1; break; } } if (intrapred) s->ac_pred = get_bits1(gb); else s->ac_pred = 0; } if (!v->ttmbf && coded_inter) ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); for (i = 0; i < 6; i++) { dst_idx += i >> 2; off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); s->mb_intra = is_intra[i]; if (is_intra[i]) { v->a_avail = v->c_avail = 0; if (i == 2 || i == 3 || !s->first_slice_line) v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]]; if (i == 1 || i == 3 || s->mb_x) v->c_avail = v->mb_type[0][s->block_index[i] - 1]; vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant, (i & 4) ? v->codingset2 : v->codingset); if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); if (v->rangeredfrm) for (j = 0; j < 64; j++) s->block[i][j] <<= 1; s->idsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize); if (v->pq >= 9 && v->overlap) { if (v->c_avail) v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); if (v->a_avail) v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); } block_cbp |= 0xF << (i << 2); block_intra |= 1 << i; } else if (is_coded[i]) { pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize, (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt); block_cbp |= pat << (i << 2); if (!v->ttmbf && ttmb < 8) ttmb = -1; first_block = 0; } } } else { s->mb_intra = 0; s->current_picture.qscale_table[mb_pos] = 0; for (i = 0; i < 6; i++) { v->mb_type[0][s->block_index[i]] = 0; s->dc_val[0][s->block_index[i]] = 0; } for (i = 0; i < 4; i++) { vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0); vc1_mc_4mv_luma(v, i, 0, 0); } vc1_mc_4mv_chroma(v, 0); s->current_picture.qscale_table[mb_pos] = 0; } } end: v->cbp[s->mb_x] = block_cbp; v->ttblk[s->mb_x] = block_tt; v->is_intra[s->mb_x] = block_intra; return 0; }
['static int vc1_decode_p_mb(VC1Context *v)\n{\n MpegEncContext *s = &v->s;\n GetBitContext *gb = &s->gb;\n int i, j;\n int mb_pos = s->mb_x + s->mb_y * s->mb_stride;\n int cbp;\n int mqdiff, mquant;\n int ttmb = v->ttfrm;\n int mb_has_coeffs = 1;\n int dmv_x, dmv_y;\n int index, index1;\n int val, sign;\n int first_block = 1;\n int dst_idx, off;\n int skipped, fourmv;\n int block_cbp = 0, pat, block_tt = 0, block_intra = 0;\n mquant = v->pq;\n if (v->mv_type_is_raw)\n fourmv = get_bits1(gb);\n else\n fourmv = v->mv_type_mb_plane[mb_pos];\n if (v->skip_is_raw)\n skipped = get_bits1(gb);\n else\n skipped = v->s.mbskip_table[mb_pos];\n if (!fourmv) {\n if (!skipped) {\n GET_MVDATA(dmv_x, dmv_y);\n if (s->mb_intra) {\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 }\n s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;\n vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);\n if (s->mb_intra && !mb_has_coeffs) {\n GET_MQUANT();\n s->ac_pred = get_bits1(gb);\n cbp = 0;\n } else if (mb_has_coeffs) {\n if (s->mb_intra)\n s->ac_pred = get_bits1(gb);\n cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);\n GET_MQUANT();\n } else {\n mquant = v->pq;\n cbp = 0;\n }\n s->current_picture.qscale_table[mb_pos] = mquant;\n if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)\n ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table,\n VC1_TTMB_VLC_BITS, 2);\n if (!s->mb_intra) vc1_mc_1mv(v, 0);\n dst_idx = 0;\n for (i = 0; i < 6; i++) {\n s->dc_val[0][s->block_index[i]] = 0;\n dst_idx += i >> 2;\n val = ((cbp >> (5 - i)) & 1);\n off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);\n v->mb_type[0][s->block_index[i]] = s->mb_intra;\n if (s->mb_intra) {\n v->a_avail = v->c_avail = 0;\n if (i == 2 || i == 3 || !s->first_slice_line)\n v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];\n if (i == 1 || i == 3 || s->mb_x)\n v->c_avail = v->mb_type[0][s->block_index[i] - 1];\n vc1_decode_intra_block(v, s->block[i], i, val, mquant,\n (i & 4) ? v->codingset2 : v->codingset);\n if ((i>3) && (s->flags & CODEC_FLAG_GRAY))\n continue;\n v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);\n if (v->rangeredfrm)\n for (j = 0; j < 64; j++)\n s->block[i][j] <<= 1;\n s->idsp.put_signed_pixels_clamped(s->block[i],\n s->dest[dst_idx] + off,\n i & 4 ? s->uvlinesize\n : s->linesize);\n if (v->pq >= 9 && v->overlap) {\n if (v->c_avail)\n v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);\n if (v->a_avail)\n v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);\n }\n block_cbp |= 0xF << (i << 2);\n block_intra |= 1 << i;\n } else if (val) {\n pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block,\n s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize,\n (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt);\n block_cbp |= pat << (i << 2);\n if (!v->ttmbf && ttmb < 8)\n ttmb = -1;\n first_block = 0;\n }\n }\n } else {\n s->mb_intra = 0;\n for (i = 0; i < 6; i++) {\n v->mb_type[0][s->block_index[i]] = 0;\n s->dc_val[0][s->block_index[i]] = 0;\n }\n s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;\n s->current_picture.qscale_table[mb_pos] = 0;\n vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);\n vc1_mc_1mv(v, 0);\n }\n } else {\n if (!skipped ) {\n int intra_count = 0, coded_inter = 0;\n int is_intra[6], is_coded[6];\n cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);\n for (i = 0; i < 6; i++) {\n val = ((cbp >> (5 - i)) & 1);\n s->dc_val[0][s->block_index[i]] = 0;\n s->mb_intra = 0;\n if (i < 4) {\n dmv_x = dmv_y = 0;\n s->mb_intra = 0;\n mb_has_coeffs = 0;\n if (val) {\n GET_MVDATA(dmv_x, dmv_y);\n }\n vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);\n if (!s->mb_intra)\n vc1_mc_4mv_luma(v, i, 0, 0);\n intra_count += s->mb_intra;\n is_intra[i] = s->mb_intra;\n is_coded[i] = mb_has_coeffs;\n }\n if (i & 4) {\n is_intra[i] = (intra_count >= 3);\n is_coded[i] = val;\n }\n if (i == 4)\n vc1_mc_4mv_chroma(v, 0);\n v->mb_type[0][s->block_index[i]] = is_intra[i];\n if (!coded_inter)\n coded_inter = !is_intra[i] & is_coded[i];\n }\n dst_idx = 0;\n if (!intra_count && !coded_inter)\n goto end;\n GET_MQUANT();\n s->current_picture.qscale_table[mb_pos] = mquant;\n {\n int intrapred = 0;\n for (i = 0; i < 6; i++)\n if (is_intra[i]) {\n if (((!s->first_slice_line || (i == 2 || i == 3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])\n || ((s->mb_x || (i == 1 || i == 3)) && v->mb_type[0][s->block_index[i] - 1])) {\n intrapred = 1;\n break;\n }\n }\n if (intrapred)\n s->ac_pred = get_bits1(gb);\n else\n s->ac_pred = 0;\n }\n if (!v->ttmbf && coded_inter)\n ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);\n for (i = 0; i < 6; i++) {\n dst_idx += i >> 2;\n off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);\n s->mb_intra = is_intra[i];\n if (is_intra[i]) {\n v->a_avail = v->c_avail = 0;\n if (i == 2 || i == 3 || !s->first_slice_line)\n v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];\n if (i == 1 || i == 3 || s->mb_x)\n v->c_avail = v->mb_type[0][s->block_index[i] - 1];\n vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant,\n (i & 4) ? v->codingset2 : v->codingset);\n if ((i>3) && (s->flags & CODEC_FLAG_GRAY))\n continue;\n v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);\n if (v->rangeredfrm)\n for (j = 0; j < 64; j++)\n s->block[i][j] <<= 1;\n s->idsp.put_signed_pixels_clamped(s->block[i],\n s->dest[dst_idx] + off,\n (i & 4) ? s->uvlinesize\n : s->linesize);\n if (v->pq >= 9 && v->overlap) {\n if (v->c_avail)\n v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);\n if (v->a_avail)\n v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);\n }\n block_cbp |= 0xF << (i << 2);\n block_intra |= 1 << i;\n } else if (is_coded[i]) {\n pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,\n first_block, s->dest[dst_idx] + off,\n (i & 4) ? s->uvlinesize : s->linesize,\n (i & 4) && (s->flags & CODEC_FLAG_GRAY),\n &block_tt);\n block_cbp |= pat << (i << 2);\n if (!v->ttmbf && ttmb < 8)\n ttmb = -1;\n first_block = 0;\n }\n }\n } else {\n s->mb_intra = 0;\n s->current_picture.qscale_table[mb_pos] = 0;\n for (i = 0; i < 6; i++) {\n v->mb_type[0][s->block_index[i]] = 0;\n s->dc_val[0][s->block_index[i]] = 0;\n }\n for (i = 0; i < 4; i++) {\n vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);\n vc1_mc_4mv_luma(v, i, 0, 0);\n }\n vc1_mc_4mv_chroma(v, 0);\n s->current_picture.qscale_table[mb_pos] = 0;\n }\n }\nend:\n v->cbp[s->mb_x] = block_cbp;\n v->ttblk[s->mb_x] = block_tt;\n v->is_intra[s->mb_x] = block_intra;\n return 0;\n}', 'static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,\n int coded, int mquant, int codingset)\n{\n GetBitContext *gb = &v->s.gb;\n MpegEncContext *s = &v->s;\n int dc_pred_dir = 0;\n int i;\n int16_t *dc_val;\n int16_t *ac_val, *ac_val2;\n int dcdiff;\n int mb_pos = s->mb_x + s->mb_y * s->mb_stride;\n int a_avail = v->a_avail, c_avail = v->c_avail;\n int use_pred = s->ac_pred;\n int scale;\n int q1, q2 = 0;\n s->bdsp.clear_block(block);\n mquant = (mquant < 1) ? 0 : ((mquant > 31) ? 31 : mquant);\n s->y_dc_scale = s->y_dc_scale_table[mquant];\n s->c_dc_scale = s->c_dc_scale_table[mquant];\n if (n < 4) {\n dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);\n } else {\n dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);\n }\n if (dcdiff < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\\n");\n return -1;\n }\n if (dcdiff) {\n if (dcdiff == 119 ) {\n if (mquant == 1) dcdiff = get_bits(gb, 10);\n else if (mquant == 2) dcdiff = get_bits(gb, 9);\n else dcdiff = get_bits(gb, 8);\n } else {\n if (mquant == 1)\n dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3;\n else if (mquant == 2)\n dcdiff = (dcdiff << 1) + get_bits1(gb) - 1;\n }\n if (get_bits1(gb))\n dcdiff = -dcdiff;\n }\n dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, a_avail, c_avail, &dc_val, &dc_pred_dir);\n *dc_val = dcdiff;\n if (n < 4) {\n block[0] = dcdiff * s->y_dc_scale;\n } else {\n block[0] = dcdiff * s->c_dc_scale;\n }\n i = 1;\n if (!a_avail) dc_pred_dir = 1;\n if (!c_avail) dc_pred_dir = 0;\n if (!a_avail && !c_avail) use_pred = 0;\n ac_val = s->ac_val[0][0] + s->block_index[n] * 16;\n ac_val2 = ac_val;\n scale = mquant * 2 + v->halfpq;\n if (dc_pred_dir)\n ac_val -= 16;\n else\n ac_val -= 16 * s->block_wrap[n];\n q1 = s->current_picture.qscale_table[mb_pos];\n if (dc_pred_dir && c_avail && mb_pos)\n q2 = s->current_picture.qscale_table[mb_pos - 1];\n if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride)\n q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride];\n if ( dc_pred_dir && n == 1)\n q2 = q1;\n if (!dc_pred_dir && n == 2)\n q2 = q1;\n if (n == 3) q2 = q1;\n if (coded) {\n int last = 0, skip, value;\n int k;\n while (!last) {\n vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);\n i += skip;\n if (i > 63)\n break;\n if (v->fcm == PROGRESSIVE)\n block[v->zz_8x8[0][i++]] = value;\n else {\n if (use_pred && (v->fcm == ILACE_FRAME)) {\n if (!dc_pred_dir)\n block[v->zz_8x8[2][i++]] = value;\n else\n block[v->zz_8x8[3][i++]] = value;\n } else {\n block[v->zzi_8x8[i++]] = value;\n }\n }\n }\n if (use_pred) {\n if (q2 && q1 != q2) {\n q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;\n q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;\n if (q1 < 1)\n return AVERROR_INVALIDDATA;\n if (dc_pred_dir) {\n for (k = 1; k < 8; k++)\n block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;\n } else {\n for (k = 1; k < 8; k++)\n block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;\n }\n } else {\n if (dc_pred_dir) {\n for (k = 1; k < 8; k++)\n block[k << v->left_blk_sh] += ac_val[k];\n } else {\n for (k = 1; k < 8; k++)\n block[k << v->top_blk_sh] += ac_val[k + 8];\n }\n }\n }\n for (k = 1; k < 8; k++) {\n ac_val2[k ] = block[k << v->left_blk_sh];\n ac_val2[k + 8] = block[k << v->top_blk_sh];\n }\n for (k = 1; k < 64; k++)\n if (block[k]) {\n block[k] *= scale;\n if (!v->pquantizer)\n block[k] += (block[k] < 0) ? -mquant : mquant;\n }\n if (use_pred) i = 63;\n } else {\n int k;\n memset(ac_val2, 0, 16 * 2);\n if (dc_pred_dir) {\n if (use_pred) {\n memcpy(ac_val2, ac_val, 8 * 2);\n if (q2 && q1 != q2) {\n q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;\n q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;\n if (q1 < 1)\n return AVERROR_INVALIDDATA;\n for (k = 1; k < 8; k++)\n ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;\n }\n }\n } else {\n if (use_pred) {\n memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);\n if (q2 && q1 != q2) {\n q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1;\n q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1;\n if (q1 < 1)\n return AVERROR_INVALIDDATA;\n for (k = 1; k < 8; k++)\n ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18;\n }\n }\n }\n if (use_pred) {\n if (dc_pred_dir) {\n for (k = 1; k < 8; k++) {\n block[k << v->left_blk_sh] = ac_val2[k] * scale;\n if (!v->pquantizer && block[k << v->left_blk_sh])\n block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant;\n }\n } else {\n for (k = 1; k < 8; k++) {\n block[k << v->top_blk_sh] = ac_val2[k + 8] * scale;\n if (!v->pquantizer && block[k << v->top_blk_sh])\n block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant;\n }\n }\n i = 63;\n }\n }\n s->block_last_index[n] = i;\n return 0;\n}']
36,578
0
https://github.com/openssl/openssl/blob/51a3b763c31afcf294af73d32f7451c9dee7cd76/ssl/statem/statem_srvr.c/#L2175
MSG_PROCESS_RETURN tls_process_client_key_exchange(SSL *s, PACKET *pkt) { int al; unsigned long alg_k; #ifndef OPENSSL_NO_RSA RSA *rsa = NULL; #endif #if !defined(OPENSSL_NO_EC) || !defined(OPENSSL_NO_DH) EVP_PKEY *ckey = NULL; #endif PACKET enc_premaster; unsigned char *rsa_decrypt = NULL; alg_k = s->s3->tmp.new_cipher->algorithm_mkey; #ifndef OPENSSL_NO_PSK if (alg_k & SSL_PSK) { unsigned char psk[PSK_MAX_PSK_LEN]; size_t psklen; PACKET psk_identity; if (!PACKET_get_length_prefixed_2(pkt, &psk_identity)) { al = SSL_AD_DECODE_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH); goto f_err; } if (PACKET_remaining(&psk_identity) > PSK_MAX_IDENTITY_LEN) { al = SSL_AD_DECODE_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_DATA_LENGTH_TOO_LONG); goto f_err; } if (s->psk_server_callback == NULL) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_PSK_NO_SERVER_CB); goto f_err; } if (!PACKET_strndup(&psk_identity, &s->session->psk_identity)) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); al = SSL_AD_INTERNAL_ERROR; goto f_err; } psklen = s->psk_server_callback(s, s->session->psk_identity, psk, sizeof(psk)); if (psklen > PSK_MAX_PSK_LEN) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto f_err; } else if (psklen == 0) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_PSK_IDENTITY_NOT_FOUND); al = SSL_AD_UNKNOWN_PSK_IDENTITY; goto f_err; } OPENSSL_free(s->s3->tmp.psk); s->s3->tmp.psk = OPENSSL_memdup(psk, psklen); OPENSSL_cleanse(psk, psklen); if (s->s3->tmp.psk == NULL) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE); goto f_err; } s->s3->tmp.psklen = psklen; } if (alg_k & SSL_kPSK) { if (PACKET_remaining(pkt) != 0) { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH); goto f_err; } if (!ssl_generate_master_secret(s, NULL, 0, 0)) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto f_err; } } else #endif #ifndef OPENSSL_NO_RSA if (alg_k & (SSL_kRSA | SSL_kRSAPSK)) { unsigned char rand_premaster_secret[SSL_MAX_MASTER_KEY_LENGTH]; int decrypt_len; unsigned char decrypt_good, version_good; size_t j, padding_len; rsa = EVP_PKEY_get0_RSA(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey); if (rsa == NULL) { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_MISSING_RSA_CERTIFICATE); goto f_err; } if (s->version == SSL3_VERSION || s->version == DTLS1_BAD_VER) { enc_premaster = *pkt; } else { if (!PACKET_get_length_prefixed_2(pkt, &enc_premaster) || PACKET_remaining(pkt) != 0) { al = SSL_AD_DECODE_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH); goto f_err; } } if (RSA_size(rsa) < SSL_MAX_MASTER_KEY_LENGTH) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, RSA_R_KEY_SIZE_TOO_SMALL); goto f_err; } rsa_decrypt = OPENSSL_malloc(RSA_size(rsa)); if (rsa_decrypt == NULL) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE); goto f_err; } if (RAND_bytes(rand_premaster_secret, sizeof(rand_premaster_secret)) <= 0) { goto err; } decrypt_len = RSA_private_decrypt(PACKET_remaining(&enc_premaster), PACKET_data(&enc_premaster), rsa_decrypt, rsa, RSA_NO_PADDING); if (decrypt_len < 0) { goto err; } if (decrypt_len < 11 + SSL_MAX_MASTER_KEY_LENGTH) { al = SSL_AD_DECRYPT_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_DECRYPTION_FAILED); goto f_err; } padding_len = decrypt_len - SSL_MAX_MASTER_KEY_LENGTH; decrypt_good = constant_time_eq_int_8(rsa_decrypt[0], 0) & constant_time_eq_int_8(rsa_decrypt[1], 2); for (j = 2; j < padding_len - 1; j++) { decrypt_good &= ~constant_time_is_zero_8(rsa_decrypt[j]); } decrypt_good &= constant_time_is_zero_8(rsa_decrypt[padding_len - 1]); version_good = constant_time_eq_8(rsa_decrypt[padding_len], (unsigned)(s->client_version >> 8)); version_good &= constant_time_eq_8(rsa_decrypt[padding_len + 1], (unsigned)(s->client_version & 0xff)); if (s->options & SSL_OP_TLS_ROLLBACK_BUG) { unsigned char workaround_good; workaround_good = constant_time_eq_8(rsa_decrypt[padding_len], (unsigned)(s->version >> 8)); workaround_good &= constant_time_eq_8(rsa_decrypt[padding_len + 1], (unsigned)(s->version & 0xff)); version_good |= workaround_good; } decrypt_good &= version_good; for (j = 0; j < sizeof(rand_premaster_secret); j++) { rsa_decrypt[padding_len + j] = constant_time_select_8(decrypt_good, rsa_decrypt[padding_len + j], rand_premaster_secret[j]); } if (!ssl_generate_master_secret(s, rsa_decrypt + padding_len, sizeof(rand_premaster_secret), 0)) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto f_err; } OPENSSL_free(rsa_decrypt); rsa_decrypt = NULL; } else #endif #ifndef OPENSSL_NO_DH if (alg_k & (SSL_kDHE | SSL_kDHEPSK)) { EVP_PKEY *skey = NULL; DH *cdh; unsigned int i; BIGNUM *pub_key; const unsigned char *data; if (!PACKET_get_net_2(pkt, &i)) { if (alg_k & (SSL_kDHE | SSL_kDHEPSK)) { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG); goto f_err; } i = 0; } if (PACKET_remaining(pkt) != i) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG); goto err; } skey = s->s3->tmp.pkey; if (skey == NULL) { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_MISSING_TMP_DH_KEY); goto f_err; } if (PACKET_remaining(pkt) == 0L) { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_MISSING_TMP_DH_KEY); goto f_err; } if (!PACKET_get_bytes(pkt, &data, i)) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto f_err; } ckey = EVP_PKEY_new(); if (ckey == NULL || EVP_PKEY_copy_parameters(ckey, skey) == 0) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_BN_LIB); goto err; } cdh = EVP_PKEY_get0_DH(ckey); pub_key = BN_bin2bn(data, i, NULL); if (pub_key == NULL || !DH_set0_key(cdh, pub_key, NULL)) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); if (pub_key != NULL) BN_free(pub_key); goto err; } if (ssl_derive(s, skey, ckey) == 0) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto f_err; } EVP_PKEY_free(ckey); ckey = NULL; EVP_PKEY_free(s->s3->tmp.pkey); s->s3->tmp.pkey = NULL; } else #endif #ifndef OPENSSL_NO_EC if (alg_k & (SSL_kECDHE | SSL_kECDHEPSK)) { EVP_PKEY *skey = s->s3->tmp.pkey; if (PACKET_remaining(pkt) == 0L) { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_MISSING_TMP_ECDH_KEY); goto f_err; } else { unsigned int i; const unsigned char *data; if (!PACKET_get_1(pkt, &i)) { al = SSL_AD_DECODE_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH); goto f_err; } if (!PACKET_get_bytes(pkt, &data, i) || PACKET_remaining(pkt) != 0) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_EC_LIB); goto err; } ckey = EVP_PKEY_new(); if (ckey == NULL || EVP_PKEY_copy_parameters(ckey, skey) <= 0) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_EVP_LIB); goto err; } if (EC_KEY_oct2key(EVP_PKEY_get0_EC_KEY(ckey), data, i, NULL) == 0) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_EC_LIB); goto err; } } if (ssl_derive(s, skey, ckey) == 0) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto f_err; } EVP_PKEY_free(ckey); ckey = NULL; EVP_PKEY_free(s->s3->tmp.pkey); s->s3->tmp.pkey = NULL; return MSG_PROCESS_CONTINUE_PROCESSING; } else #endif #ifndef OPENSSL_NO_SRP if (alg_k & SSL_kSRP) { unsigned int i; const unsigned char *data; if (!PACKET_get_net_2(pkt, &i) || !PACKET_get_bytes(pkt, &data, i)) { al = SSL_AD_DECODE_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_BAD_SRP_A_LENGTH); goto f_err; } if ((s->srp_ctx.A = BN_bin2bn(data, i, NULL)) == NULL) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_BN_LIB); goto err; } if (BN_ucmp(s->srp_ctx.A, s->srp_ctx.N) >= 0 || BN_is_zero(s->srp_ctx.A)) { al = SSL_AD_ILLEGAL_PARAMETER; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_BAD_SRP_PARAMETERS); goto f_err; } OPENSSL_free(s->session->srp_username); s->session->srp_username = OPENSSL_strdup(s->srp_ctx.login); if (s->session->srp_username == NULL) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE); goto err; } if (!srp_generate_server_master_secret(s)) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto err; } } else #endif #ifndef OPENSSL_NO_GOST if (alg_k & SSL_kGOST) { EVP_PKEY_CTX *pkey_ctx; EVP_PKEY *client_pub_pkey = NULL, *pk = NULL; unsigned char premaster_secret[32]; const unsigned char *start; size_t outlen = 32, inlen; unsigned long alg_a; int Ttag, Tclass; long Tlen; long sess_key_len; const unsigned char *data; alg_a = s->s3->tmp.new_cipher->algorithm_auth; if (alg_a & SSL_aGOST12) { pk = s->cert->pkeys[SSL_PKEY_GOST12_512].privatekey; if (pk == NULL) { pk = s->cert->pkeys[SSL_PKEY_GOST12_256].privatekey; } if (pk == NULL) { pk = s->cert->pkeys[SSL_PKEY_GOST01].privatekey; } } else if (alg_a & SSL_aGOST01) { pk = s->cert->pkeys[SSL_PKEY_GOST01].privatekey; } pkey_ctx = EVP_PKEY_CTX_new(pk, NULL); if (pkey_ctx == NULL) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE); goto f_err; } if (EVP_PKEY_decrypt_init(pkey_ctx) <= 0) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto f_err; } client_pub_pkey = X509_get0_pubkey(s->session->peer); if (client_pub_pkey) { if (EVP_PKEY_derive_set_peer(pkey_ctx, client_pub_pkey) <= 0) ERR_clear_error(); } sess_key_len = PACKET_remaining(pkt); if (!PACKET_get_bytes(pkt, &data, sess_key_len)) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto gerr; } if (ASN1_get_object ((const unsigned char **)&data, &Tlen, &Ttag, &Tclass, sess_key_len) != V_ASN1_CONSTRUCTED || Ttag != V_ASN1_SEQUENCE || Tclass != V_ASN1_UNIVERSAL) { al = SSL_AD_DECODE_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_DECRYPTION_FAILED); goto gerr; } start = data; inlen = Tlen; if (EVP_PKEY_decrypt (pkey_ctx, premaster_secret, &outlen, start, inlen) <= 0) { al = SSL_AD_DECODE_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_DECRYPTION_FAILED); goto gerr; } if (!ssl_generate_master_secret(s, premaster_secret, sizeof(premaster_secret), 0)) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto gerr; } if (EVP_PKEY_CTX_ctrl (pkey_ctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 2, NULL) > 0) s->statem.no_cert_verify = 1; EVP_PKEY_CTX_free(pkey_ctx); return MSG_PROCESS_CONTINUE_PROCESSING; gerr: EVP_PKEY_CTX_free(pkey_ctx); goto f_err; } else #endif { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_UNKNOWN_CIPHER_TYPE); goto f_err; } return MSG_PROCESS_CONTINUE_PROCESSING; f_err: ssl3_send_alert(s, SSL3_AL_FATAL, al); #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_SRP) err: #endif #if !defined(OPENSSL_NO_EC) || !defined(OPENSSL_NO_DH) EVP_PKEY_free(ckey); #endif OPENSSL_free(rsa_decrypt); #ifndef OPENSSL_NO_PSK OPENSSL_clear_free(s->s3->tmp.psk, s->s3->tmp.psklen); s->s3->tmp.psk = NULL; #endif ossl_statem_set_error(s); return MSG_PROCESS_ERROR; }
['MSG_PROCESS_RETURN tls_process_client_key_exchange(SSL *s, PACKET *pkt)\n{\n int al;\n unsigned long alg_k;\n#ifndef OPENSSL_NO_RSA\n RSA *rsa = NULL;\n#endif\n#if !defined(OPENSSL_NO_EC) || !defined(OPENSSL_NO_DH)\n EVP_PKEY *ckey = NULL;\n#endif\n PACKET enc_premaster;\n unsigned char *rsa_decrypt = NULL;\n alg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n#ifndef OPENSSL_NO_PSK\n if (alg_k & SSL_PSK) {\n unsigned char psk[PSK_MAX_PSK_LEN];\n size_t psklen;\n PACKET psk_identity;\n if (!PACKET_get_length_prefixed_2(pkt, &psk_identity)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH);\n goto f_err;\n }\n if (PACKET_remaining(&psk_identity) > PSK_MAX_IDENTITY_LEN) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_DATA_LENGTH_TOO_LONG);\n goto f_err;\n }\n if (s->psk_server_callback == NULL) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_PSK_NO_SERVER_CB);\n goto f_err;\n }\n if (!PACKET_strndup(&psk_identity, &s->session->psk_identity)) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n al = SSL_AD_INTERNAL_ERROR;\n goto f_err;\n }\n psklen = s->psk_server_callback(s, s->session->psk_identity,\n psk, sizeof(psk));\n if (psklen > PSK_MAX_PSK_LEN) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n goto f_err;\n } else if (psklen == 0) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_PSK_IDENTITY_NOT_FOUND);\n al = SSL_AD_UNKNOWN_PSK_IDENTITY;\n goto f_err;\n }\n OPENSSL_free(s->s3->tmp.psk);\n s->s3->tmp.psk = OPENSSL_memdup(psk, psklen);\n OPENSSL_cleanse(psk, psklen);\n if (s->s3->tmp.psk == NULL) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n goto f_err;\n }\n s->s3->tmp.psklen = psklen;\n }\n if (alg_k & SSL_kPSK) {\n if (PACKET_remaining(pkt) != 0) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH);\n goto f_err;\n }\n if (!ssl_generate_master_secret(s, NULL, 0, 0)) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n } else\n#endif\n#ifndef OPENSSL_NO_RSA\n if (alg_k & (SSL_kRSA | SSL_kRSAPSK)) {\n unsigned char rand_premaster_secret[SSL_MAX_MASTER_KEY_LENGTH];\n int decrypt_len;\n unsigned char decrypt_good, version_good;\n size_t j, padding_len;\n rsa = EVP_PKEY_get0_RSA(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey);\n if (rsa == NULL) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_MISSING_RSA_CERTIFICATE);\n goto f_err;\n }\n if (s->version == SSL3_VERSION || s->version == DTLS1_BAD_VER) {\n enc_premaster = *pkt;\n } else {\n if (!PACKET_get_length_prefixed_2(pkt, &enc_premaster)\n || PACKET_remaining(pkt) != 0) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_LENGTH_MISMATCH);\n goto f_err;\n }\n }\n if (RSA_size(rsa) < SSL_MAX_MASTER_KEY_LENGTH) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n RSA_R_KEY_SIZE_TOO_SMALL);\n goto f_err;\n }\n rsa_decrypt = OPENSSL_malloc(RSA_size(rsa));\n if (rsa_decrypt == NULL) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n goto f_err;\n }\n if (RAND_bytes(rand_premaster_secret,\n sizeof(rand_premaster_secret)) <= 0) {\n goto err;\n }\n decrypt_len = RSA_private_decrypt(PACKET_remaining(&enc_premaster),\n PACKET_data(&enc_premaster),\n rsa_decrypt, rsa, RSA_NO_PADDING);\n if (decrypt_len < 0) {\n goto err;\n }\n if (decrypt_len < 11 + SSL_MAX_MASTER_KEY_LENGTH) {\n al = SSL_AD_DECRYPT_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_DECRYPTION_FAILED);\n goto f_err;\n }\n padding_len = decrypt_len - SSL_MAX_MASTER_KEY_LENGTH;\n decrypt_good = constant_time_eq_int_8(rsa_decrypt[0], 0) &\n constant_time_eq_int_8(rsa_decrypt[1], 2);\n for (j = 2; j < padding_len - 1; j++) {\n decrypt_good &= ~constant_time_is_zero_8(rsa_decrypt[j]);\n }\n decrypt_good &= constant_time_is_zero_8(rsa_decrypt[padding_len - 1]);\n version_good =\n constant_time_eq_8(rsa_decrypt[padding_len],\n (unsigned)(s->client_version >> 8));\n version_good &=\n constant_time_eq_8(rsa_decrypt[padding_len + 1],\n (unsigned)(s->client_version & 0xff));\n if (s->options & SSL_OP_TLS_ROLLBACK_BUG) {\n unsigned char workaround_good;\n workaround_good = constant_time_eq_8(rsa_decrypt[padding_len],\n (unsigned)(s->version >> 8));\n workaround_good &=\n constant_time_eq_8(rsa_decrypt[padding_len + 1],\n (unsigned)(s->version & 0xff));\n version_good |= workaround_good;\n }\n decrypt_good &= version_good;\n for (j = 0; j < sizeof(rand_premaster_secret); j++) {\n rsa_decrypt[padding_len + j] =\n constant_time_select_8(decrypt_good,\n rsa_decrypt[padding_len + j],\n rand_premaster_secret[j]);\n }\n if (!ssl_generate_master_secret(s, rsa_decrypt + padding_len,\n sizeof(rand_premaster_secret), 0)) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n OPENSSL_free(rsa_decrypt);\n rsa_decrypt = NULL;\n } else\n#endif\n#ifndef OPENSSL_NO_DH\n if (alg_k & (SSL_kDHE | SSL_kDHEPSK)) {\n EVP_PKEY *skey = NULL;\n DH *cdh;\n unsigned int i;\n BIGNUM *pub_key;\n const unsigned char *data;\n if (!PACKET_get_net_2(pkt, &i)) {\n if (alg_k & (SSL_kDHE | SSL_kDHEPSK)) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);\n goto f_err;\n }\n i = 0;\n }\n if (PACKET_remaining(pkt) != i) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);\n goto err;\n }\n skey = s->s3->tmp.pkey;\n if (skey == NULL) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_MISSING_TMP_DH_KEY);\n goto f_err;\n }\n if (PACKET_remaining(pkt) == 0L) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_MISSING_TMP_DH_KEY);\n goto f_err;\n }\n if (!PACKET_get_bytes(pkt, &data, i)) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n ckey = EVP_PKEY_new();\n if (ckey == NULL || EVP_PKEY_copy_parameters(ckey, skey) == 0) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_BN_LIB);\n goto err;\n }\n cdh = EVP_PKEY_get0_DH(ckey);\n pub_key = BN_bin2bn(data, i, NULL);\n if (pub_key == NULL || !DH_set0_key(cdh, pub_key, NULL)) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n if (pub_key != NULL)\n BN_free(pub_key);\n goto err;\n }\n if (ssl_derive(s, skey, ckey) == 0) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n EVP_PKEY_free(ckey);\n ckey = NULL;\n EVP_PKEY_free(s->s3->tmp.pkey);\n s->s3->tmp.pkey = NULL;\n } else\n#endif\n#ifndef OPENSSL_NO_EC\n if (alg_k & (SSL_kECDHE | SSL_kECDHEPSK)) {\n EVP_PKEY *skey = s->s3->tmp.pkey;\n if (PACKET_remaining(pkt) == 0L) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_MISSING_TMP_ECDH_KEY);\n goto f_err;\n } else {\n unsigned int i;\n const unsigned char *data;\n if (!PACKET_get_1(pkt, &i)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_LENGTH_MISMATCH);\n goto f_err;\n }\n if (!PACKET_get_bytes(pkt, &data, i)\n || PACKET_remaining(pkt) != 0) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_EC_LIB);\n goto err;\n }\n ckey = EVP_PKEY_new();\n if (ckey == NULL || EVP_PKEY_copy_parameters(ckey, skey) <= 0) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_EVP_LIB);\n goto err;\n }\n if (EC_KEY_oct2key(EVP_PKEY_get0_EC_KEY(ckey), data, i,\n NULL) == 0) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_EC_LIB);\n goto err;\n }\n }\n if (ssl_derive(s, skey, ckey) == 0) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n EVP_PKEY_free(ckey);\n ckey = NULL;\n EVP_PKEY_free(s->s3->tmp.pkey);\n s->s3->tmp.pkey = NULL;\n return MSG_PROCESS_CONTINUE_PROCESSING;\n } else\n#endif\n#ifndef OPENSSL_NO_SRP\n if (alg_k & SSL_kSRP) {\n unsigned int i;\n const unsigned char *data;\n if (!PACKET_get_net_2(pkt, &i)\n || !PACKET_get_bytes(pkt, &data, i)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_BAD_SRP_A_LENGTH);\n goto f_err;\n }\n if ((s->srp_ctx.A = BN_bin2bn(data, i, NULL)) == NULL) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_BN_LIB);\n goto err;\n }\n if (BN_ucmp(s->srp_ctx.A, s->srp_ctx.N) >= 0\n || BN_is_zero(s->srp_ctx.A)) {\n al = SSL_AD_ILLEGAL_PARAMETER;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_BAD_SRP_PARAMETERS);\n goto f_err;\n }\n OPENSSL_free(s->session->srp_username);\n s->session->srp_username = OPENSSL_strdup(s->srp_ctx.login);\n if (s->session->srp_username == NULL) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!srp_generate_server_master_secret(s)) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else\n#endif\n#ifndef OPENSSL_NO_GOST\n if (alg_k & SSL_kGOST) {\n EVP_PKEY_CTX *pkey_ctx;\n EVP_PKEY *client_pub_pkey = NULL, *pk = NULL;\n unsigned char premaster_secret[32];\n const unsigned char *start;\n size_t outlen = 32, inlen;\n unsigned long alg_a;\n int Ttag, Tclass;\n long Tlen;\n long sess_key_len;\n const unsigned char *data;\n alg_a = s->s3->tmp.new_cipher->algorithm_auth;\n if (alg_a & SSL_aGOST12) {\n pk = s->cert->pkeys[SSL_PKEY_GOST12_512].privatekey;\n if (pk == NULL) {\n pk = s->cert->pkeys[SSL_PKEY_GOST12_256].privatekey;\n }\n if (pk == NULL) {\n pk = s->cert->pkeys[SSL_PKEY_GOST01].privatekey;\n }\n } else if (alg_a & SSL_aGOST01) {\n pk = s->cert->pkeys[SSL_PKEY_GOST01].privatekey;\n }\n pkey_ctx = EVP_PKEY_CTX_new(pk, NULL);\n if (pkey_ctx == NULL) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n goto f_err;\n }\n if (EVP_PKEY_decrypt_init(pkey_ctx) <= 0) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n client_pub_pkey = X509_get0_pubkey(s->session->peer);\n if (client_pub_pkey) {\n if (EVP_PKEY_derive_set_peer(pkey_ctx, client_pub_pkey) <= 0)\n ERR_clear_error();\n }\n sess_key_len = PACKET_remaining(pkt);\n if (!PACKET_get_bytes(pkt, &data, sess_key_len)) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n goto gerr;\n }\n if (ASN1_get_object ((const unsigned char **)&data, &Tlen, &Ttag,\n &Tclass, sess_key_len) != V_ASN1_CONSTRUCTED\n || Ttag != V_ASN1_SEQUENCE\n || Tclass != V_ASN1_UNIVERSAL) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_DECRYPTION_FAILED);\n goto gerr;\n }\n start = data;\n inlen = Tlen;\n if (EVP_PKEY_decrypt\n (pkey_ctx, premaster_secret, &outlen, start, inlen) <= 0) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE,\n SSL_R_DECRYPTION_FAILED);\n goto gerr;\n }\n if (!ssl_generate_master_secret(s, premaster_secret,\n sizeof(premaster_secret), 0)) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n goto gerr;\n }\n if (EVP_PKEY_CTX_ctrl\n (pkey_ctx, -1, -1, EVP_PKEY_CTRL_PEER_KEY, 2, NULL) > 0)\n s->statem.no_cert_verify = 1;\n EVP_PKEY_CTX_free(pkey_ctx);\n return MSG_PROCESS_CONTINUE_PROCESSING;\n gerr:\n EVP_PKEY_CTX_free(pkey_ctx);\n goto f_err;\n } else\n#endif\n {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, SSL_R_UNKNOWN_CIPHER_TYPE);\n goto f_err;\n }\n return MSG_PROCESS_CONTINUE_PROCESSING;\n f_err:\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_SRP)\n err:\n#endif\n#if !defined(OPENSSL_NO_EC) || !defined(OPENSSL_NO_DH)\n EVP_PKEY_free(ckey);\n#endif\n OPENSSL_free(rsa_decrypt);\n#ifndef OPENSSL_NO_PSK\n OPENSSL_clear_free(s->s3->tmp.psk, s->s3->tmp.psklen);\n s->s3->tmp.psk = NULL;\n#endif\n ossl_statem_set_error(s);\n return MSG_PROCESS_ERROR;\n}', 'int RSA_size(const RSA *r)\n{\n return (BN_num_bytes(r->n));\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n int i = a->top - 1;\n bn_check_top(a);\n if (BN_is_zero(a))\n return 0;\n return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\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}']
36,579
0
https://github.com/libav/libav/blob/0a3028b9b0c531b6c61076be22b88fa64c27332c/libavcodec/ac3enc.c/#L1090
static int bit_alloc(AC3EncodeContext *s, int snr_offset) { int blk, ch; int mantissa_bits; int mant_cnt[5]; snr_offset = (snr_offset - 240) << 2; reset_block_bap(s); mantissa_bits = 0; for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { AC3Block *block = &s->blocks[blk]; mant_cnt[0] = mant_cnt[3] = 0; mant_cnt[1] = mant_cnt[2] = 2; mant_cnt[4] = 1; for (ch = 0; ch < s->channels; ch++) { if (block->exp_strategy[ch] == EXP_REUSE) { memcpy(block->bap[ch], s->blocks[blk-1].bap[ch], AC3_MAX_COEFS); } else { ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0, s->nb_coefs[ch], snr_offset, s->bit_alloc.floor, ff_ac3_bap_tab, block->bap[ch]); } mantissa_bits += compute_mantissa_size(mant_cnt, block->bap[ch], s->nb_coefs[ch]); } mantissa_bits += compute_mantissa_size_final(mant_cnt); } return mantissa_bits; }
['static int bit_alloc(AC3EncodeContext *s, int snr_offset)\n{\n int blk, ch;\n int mantissa_bits;\n int mant_cnt[5];\n snr_offset = (snr_offset - 240) << 2;\n reset_block_bap(s);\n mantissa_bits = 0;\n for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {\n AC3Block *block = &s->blocks[blk];\n mant_cnt[0] = mant_cnt[3] = 0;\n mant_cnt[1] = mant_cnt[2] = 2;\n mant_cnt[4] = 1;\n for (ch = 0; ch < s->channels; ch++) {\n if (block->exp_strategy[ch] == EXP_REUSE) {\n memcpy(block->bap[ch], s->blocks[blk-1].bap[ch], AC3_MAX_COEFS);\n } else {\n ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0,\n s->nb_coefs[ch], snr_offset,\n s->bit_alloc.floor, ff_ac3_bap_tab,\n block->bap[ch]);\n }\n mantissa_bits += compute_mantissa_size(mant_cnt, block->bap[ch], s->nb_coefs[ch]);\n }\n mantissa_bits += compute_mantissa_size_final(mant_cnt);\n }\n return mantissa_bits;\n}']
36,580
0
https://github.com/openssl/openssl/blob/6c2c3e9ba9146ef8c9b1fd2b660357b657706969/crypto/lhash/lhash.c/#L359
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 **)Realloc((char *)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; } }
['static int ssl3_get_client_certificate(SSL *s)\n\t{\n\tint i,ok,al,ret= -1;\n\tX509 *x=NULL;\n\tunsigned long l,nc,llen,n;\n\tunsigned char *p,*d,*q;\n\tSTACK_OF(X509) *sk=NULL;\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_SR_CERT_A,\n\t\tSSL3_ST_SR_CERT_B,\n\t\t-1,\n#if defined(MSDOS) && !defined(WIN32)\n\t\t1024*30,\n#else\n\t\t1024*100,\n#endif\n\t\t&ok);\n\tif (!ok) return((int)n);\n\tif\t(s->s3->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE)\n\t\t{\n\t\tif (\t(s->verify_mode & SSL_VERIFY_PEER) &&\n\t\t\t(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);\n\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif ((s->version > SSL3_VERSION) && s->s3->tmp.cert_request)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST);\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tgoto f_err;\n\t\t\t}\n\t\ts->s3->tmp.reuse_message=1;\n\t\treturn(1);\n\t\t}\n\tif (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)\n\t\t{\n\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_WRONG_MESSAGE_TYPE);\n\t\tgoto f_err;\n\t\t}\n\td=p=(unsigned char *)s->init_buf->data;\n\tif ((sk=sk_X509_new_null()) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tn2l3(p,llen);\n\tif (llen+3 != n)\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_LENGTH_MISMATCH);\n\t\tgoto f_err;\n\t\t}\n\tfor (nc=0; nc<llen; )\n\t\t{\n\t\tn2l3(p,l);\n\t\tif ((l+nc+3) > llen)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tq=p;\n\t\tx=d2i_X509(NULL,&p,l);\n\t\tif (x == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_ASN1_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (p != (q+l))\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!sk_X509_push(sk,x))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tx=NULL;\n\t\tnc+=l+3;\n\t\t}\n\tif (sk_X509_num(sk) <= 0)\n\t\t{\n\t\tif (s->version == SSL3_VERSION)\n\t\t\t{\n\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATES_RETURNED);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\telse if ((s->verify_mode & SSL_VERIFY_PEER) &&\n\t\t\t (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);\n\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\ti=ssl_verify_cert_chain(s,sk);\n\t\tif (!i)\n\t\t\t{\n\t\t\tal=ssl_verify_alarm_type(s->verify_result);\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE,SSL_R_NO_CERTIFICATE_RETURNED);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\tif (s->session->peer != NULL)\n\t\tX509_free(s->session->peer);\n\ts->session->peer=sk_X509_shift(sk);\n\ts->session->verify_result = s->verify_result;\n\tif (s->session->sess_cert == NULL)\n\t\t{\n\t\ts->session->sess_cert = ssl_sess_cert_new();\n\t\tif (s->session->sess_cert == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE, ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (s->session->sess_cert->cert_chain != NULL)\n\t\tsk_X509_pop_free(s->session->sess_cert->cert_chain, X509_free);\n\ts->session->sess_cert->cert_chain=sk;\n\tsk=NULL;\n\tret=1;\n\tif (0)\n\t\t{\nf_err:\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\t\t}\nerr:\n\tif (x != NULL) X509_free(x);\n\tif (sk != NULL) sk_X509_pop_free(sk,X509_free);\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\tif((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) &&\n\t\t\t\t\t(st1 == SSL3_ST_SR_CERT_A) &&\n\t\t\t\t\t(stn == SSL3_ST_SR_CERT_B))\n\t\t\t{\n\t\t\tssl3_init_finished_mac(s);\n\t\t\tssl3_finish_mac(s, p + s->init_num, i);\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}', '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 **)Realloc((char *)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}']
36,581
0
https://github.com/libav/libav/blob/a20639017bfca0490bb1799575714f22bf470b4f/libavcodec/ps.c/#L1042
static void stereo_processing(PSContext *ps, float (*l)[32][2], float (*r)[32][2], int is34) { int e, b, k, n; float (*H11)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H11; float (*H12)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H12; float (*H21)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H21; float (*H22)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H22; int8_t *opd_hist = ps->opd_hist; int8_t *ipd_hist = ps->ipd_hist; int8_t iid_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t icc_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t ipd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t opd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t (*iid_mapped)[PS_MAX_NR_IIDICC] = iid_mapped_buf; int8_t (*icc_mapped)[PS_MAX_NR_IIDICC] = icc_mapped_buf; int8_t (*ipd_mapped)[PS_MAX_NR_IIDICC] = ipd_mapped_buf; int8_t (*opd_mapped)[PS_MAX_NR_IIDICC] = opd_mapped_buf; const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20; const float (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB; for (b = 0; b < PS_MAX_NR_IIDICC; b++) { H11[0][0][b] = H11[0][ps->num_env_old][b]; H12[0][0][b] = H12[0][ps->num_env_old][b]; H21[0][0][b] = H21[0][ps->num_env_old][b]; H22[0][0][b] = H22[0][ps->num_env_old][b]; H11[1][0][b] = H11[1][ps->num_env_old][b]; H12[1][0][b] = H12[1][ps->num_env_old][b]; H21[1][0][b] = H21[1][ps->num_env_old][b]; H22[1][0][b] = H22[1][ps->num_env_old][b]; } if (is34) { remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1); remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1); if (ps->enable_ipdopd) { remap34(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0); remap34(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0); } if (!ps->is34bands_old) { map_val_20_to_34(H11[0][0]); map_val_20_to_34(H11[1][0]); map_val_20_to_34(H12[0][0]); map_val_20_to_34(H12[1][0]); map_val_20_to_34(H21[0][0]); map_val_20_to_34(H21[1][0]); map_val_20_to_34(H22[0][0]); map_val_20_to_34(H22[1][0]); ipdopd_reset(ipd_hist, opd_hist); } } else { remap20(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1); remap20(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1); if (ps->enable_ipdopd) { remap20(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0); remap20(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0); } if (ps->is34bands_old) { map_val_34_to_20(H11[0][0]); map_val_34_to_20(H11[1][0]); map_val_34_to_20(H12[0][0]); map_val_34_to_20(H12[1][0]); map_val_34_to_20(H21[0][0]); map_val_34_to_20(H21[1][0]); map_val_34_to_20(H22[0][0]); map_val_34_to_20(H22[1][0]); ipdopd_reset(ipd_hist, opd_hist); } } for (e = 0; e < ps->num_env; e++) { for (b = 0; b < NR_PAR_BANDS[is34]; b++) { float h11, h12, h21, h22; h11 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][0]; h12 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][1]; h21 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][2]; h22 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][3]; if (!PS_BASELINE && ps->enable_ipdopd && b < ps->nr_ipdopd_par) { float h11i, h12i, h21i, h22i; float ipd_adj_re, ipd_adj_im; int opd_idx = opd_hist[b] * 8 + opd_mapped[e][b]; int ipd_idx = ipd_hist[b] * 8 + ipd_mapped[e][b]; float opd_re = pd_re_smooth[opd_idx]; float opd_im = pd_im_smooth[opd_idx]; float ipd_re = pd_re_smooth[ipd_idx]; float ipd_im = pd_im_smooth[ipd_idx]; opd_hist[b] = opd_idx & 0x3F; ipd_hist[b] = ipd_idx & 0x3F; ipd_adj_re = opd_re*ipd_re + opd_im*ipd_im; ipd_adj_im = opd_im*ipd_re - opd_re*ipd_im; h11i = h11 * opd_im; h11 = h11 * opd_re; h12i = h12 * ipd_adj_im; h12 = h12 * ipd_adj_re; h21i = h21 * opd_im; h21 = h21 * opd_re; h22i = h22 * ipd_adj_im; h22 = h22 * ipd_adj_re; H11[1][e+1][b] = h11i; H12[1][e+1][b] = h12i; H21[1][e+1][b] = h21i; H22[1][e+1][b] = h22i; } H11[0][e+1][b] = h11; H12[0][e+1][b] = h12; H21[0][e+1][b] = h21; H22[0][e+1][b] = h22; } for (k = 0; k < NR_BANDS[is34]; k++) { float h11r, h12r, h21r, h22r; float h11i, h12i, h21i, h22i; float h11r_step, h12r_step, h21r_step, h22r_step; float h11i_step, h12i_step, h21i_step, h22i_step; int start = ps->border_position[e]; int stop = ps->border_position[e+1]; float width = 1.f / (stop - start); b = k_to_i[k]; h11r = H11[0][e][b]; h12r = H12[0][e][b]; h21r = H21[0][e][b]; h22r = H22[0][e][b]; if (!PS_BASELINE && ps->enable_ipdopd) { if ((is34 && k <= 13 && k >= 9) || (!is34 && k <= 1)) { h11i = -H11[1][e][b]; h12i = -H12[1][e][b]; h21i = -H21[1][e][b]; h22i = -H22[1][e][b]; } else { h11i = H11[1][e][b]; h12i = H12[1][e][b]; h21i = H21[1][e][b]; h22i = H22[1][e][b]; } } h11r_step = (H11[0][e+1][b] - h11r) * width; h12r_step = (H12[0][e+1][b] - h12r) * width; h21r_step = (H21[0][e+1][b] - h21r) * width; h22r_step = (H22[0][e+1][b] - h22r) * width; if (!PS_BASELINE && ps->enable_ipdopd) { h11i_step = (H11[1][e+1][b] - h11i) * width; h12i_step = (H12[1][e+1][b] - h12i) * width; h21i_step = (H21[1][e+1][b] - h21i) * width; h22i_step = (H22[1][e+1][b] - h22i) * width; } for (n = start + 1; n <= stop; n++) { float l_re = l[k][n][0]; float l_im = l[k][n][1]; float r_re = r[k][n][0]; float r_im = r[k][n][1]; h11r += h11r_step; h12r += h12r_step; h21r += h21r_step; h22r += h22r_step; if (!PS_BASELINE && ps->enable_ipdopd) { h11i += h11i_step; h12i += h12i_step; h21i += h21i_step; h22i += h22i_step; l[k][n][0] = h11r*l_re + h21r*r_re - h11i*l_im - h21i*r_im; l[k][n][1] = h11r*l_im + h21r*r_im + h11i*l_re + h21i*r_re; r[k][n][0] = h12r*l_re + h22r*r_re - h12i*l_im - h22i*r_im; r[k][n][1] = h12r*l_im + h22r*r_im + h12i*l_re + h22i*r_re; } else { l[k][n][0] = h11r*l_re + h21r*r_re; l[k][n][1] = h11r*l_im + h21r*r_im; r[k][n][0] = h12r*l_re + h22r*r_re; r[k][n][1] = h12r*l_im + h22r*r_im; } } } } }
['static void stereo_processing(PSContext *ps, float (*l)[32][2], float (*r)[32][2], int is34)\n{\n int e, b, k, n;\n float (*H11)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H11;\n float (*H12)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H12;\n float (*H21)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H21;\n float (*H22)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H22;\n int8_t *opd_hist = ps->opd_hist;\n int8_t *ipd_hist = ps->ipd_hist;\n int8_t iid_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];\n int8_t icc_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];\n int8_t ipd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];\n int8_t opd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];\n int8_t (*iid_mapped)[PS_MAX_NR_IIDICC] = iid_mapped_buf;\n int8_t (*icc_mapped)[PS_MAX_NR_IIDICC] = icc_mapped_buf;\n int8_t (*ipd_mapped)[PS_MAX_NR_IIDICC] = ipd_mapped_buf;\n int8_t (*opd_mapped)[PS_MAX_NR_IIDICC] = opd_mapped_buf;\n const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20;\n const float (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB;\n for (b = 0; b < PS_MAX_NR_IIDICC; b++) {\n H11[0][0][b] = H11[0][ps->num_env_old][b];\n H12[0][0][b] = H12[0][ps->num_env_old][b];\n H21[0][0][b] = H21[0][ps->num_env_old][b];\n H22[0][0][b] = H22[0][ps->num_env_old][b];\n H11[1][0][b] = H11[1][ps->num_env_old][b];\n H12[1][0][b] = H12[1][ps->num_env_old][b];\n H21[1][0][b] = H21[1][ps->num_env_old][b];\n H22[1][0][b] = H22[1][ps->num_env_old][b];\n }\n if (is34) {\n remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1);\n remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1);\n if (ps->enable_ipdopd) {\n remap34(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0);\n remap34(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0);\n }\n if (!ps->is34bands_old) {\n map_val_20_to_34(H11[0][0]);\n map_val_20_to_34(H11[1][0]);\n map_val_20_to_34(H12[0][0]);\n map_val_20_to_34(H12[1][0]);\n map_val_20_to_34(H21[0][0]);\n map_val_20_to_34(H21[1][0]);\n map_val_20_to_34(H22[0][0]);\n map_val_20_to_34(H22[1][0]);\n ipdopd_reset(ipd_hist, opd_hist);\n }\n } else {\n remap20(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1);\n remap20(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1);\n if (ps->enable_ipdopd) {\n remap20(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0);\n remap20(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0);\n }\n if (ps->is34bands_old) {\n map_val_34_to_20(H11[0][0]);\n map_val_34_to_20(H11[1][0]);\n map_val_34_to_20(H12[0][0]);\n map_val_34_to_20(H12[1][0]);\n map_val_34_to_20(H21[0][0]);\n map_val_34_to_20(H21[1][0]);\n map_val_34_to_20(H22[0][0]);\n map_val_34_to_20(H22[1][0]);\n ipdopd_reset(ipd_hist, opd_hist);\n }\n }\n for (e = 0; e < ps->num_env; e++) {\n for (b = 0; b < NR_PAR_BANDS[is34]; b++) {\n float h11, h12, h21, h22;\n h11 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][0];\n h12 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][1];\n h21 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][2];\n h22 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][3];\n if (!PS_BASELINE && ps->enable_ipdopd && b < ps->nr_ipdopd_par) {\n float h11i, h12i, h21i, h22i;\n float ipd_adj_re, ipd_adj_im;\n int opd_idx = opd_hist[b] * 8 + opd_mapped[e][b];\n int ipd_idx = ipd_hist[b] * 8 + ipd_mapped[e][b];\n float opd_re = pd_re_smooth[opd_idx];\n float opd_im = pd_im_smooth[opd_idx];\n float ipd_re = pd_re_smooth[ipd_idx];\n float ipd_im = pd_im_smooth[ipd_idx];\n opd_hist[b] = opd_idx & 0x3F;\n ipd_hist[b] = ipd_idx & 0x3F;\n ipd_adj_re = opd_re*ipd_re + opd_im*ipd_im;\n ipd_adj_im = opd_im*ipd_re - opd_re*ipd_im;\n h11i = h11 * opd_im;\n h11 = h11 * opd_re;\n h12i = h12 * ipd_adj_im;\n h12 = h12 * ipd_adj_re;\n h21i = h21 * opd_im;\n h21 = h21 * opd_re;\n h22i = h22 * ipd_adj_im;\n h22 = h22 * ipd_adj_re;\n H11[1][e+1][b] = h11i;\n H12[1][e+1][b] = h12i;\n H21[1][e+1][b] = h21i;\n H22[1][e+1][b] = h22i;\n }\n H11[0][e+1][b] = h11;\n H12[0][e+1][b] = h12;\n H21[0][e+1][b] = h21;\n H22[0][e+1][b] = h22;\n }\n for (k = 0; k < NR_BANDS[is34]; k++) {\n float h11r, h12r, h21r, h22r;\n float h11i, h12i, h21i, h22i;\n float h11r_step, h12r_step, h21r_step, h22r_step;\n float h11i_step, h12i_step, h21i_step, h22i_step;\n int start = ps->border_position[e];\n int stop = ps->border_position[e+1];\n float width = 1.f / (stop - start);\n b = k_to_i[k];\n h11r = H11[0][e][b];\n h12r = H12[0][e][b];\n h21r = H21[0][e][b];\n h22r = H22[0][e][b];\n if (!PS_BASELINE && ps->enable_ipdopd) {\n if ((is34 && k <= 13 && k >= 9) || (!is34 && k <= 1)) {\n h11i = -H11[1][e][b];\n h12i = -H12[1][e][b];\n h21i = -H21[1][e][b];\n h22i = -H22[1][e][b];\n } else {\n h11i = H11[1][e][b];\n h12i = H12[1][e][b];\n h21i = H21[1][e][b];\n h22i = H22[1][e][b];\n }\n }\n h11r_step = (H11[0][e+1][b] - h11r) * width;\n h12r_step = (H12[0][e+1][b] - h12r) * width;\n h21r_step = (H21[0][e+1][b] - h21r) * width;\n h22r_step = (H22[0][e+1][b] - h22r) * width;\n if (!PS_BASELINE && ps->enable_ipdopd) {\n h11i_step = (H11[1][e+1][b] - h11i) * width;\n h12i_step = (H12[1][e+1][b] - h12i) * width;\n h21i_step = (H21[1][e+1][b] - h21i) * width;\n h22i_step = (H22[1][e+1][b] - h22i) * width;\n }\n for (n = start + 1; n <= stop; n++) {\n float l_re = l[k][n][0];\n float l_im = l[k][n][1];\n float r_re = r[k][n][0];\n float r_im = r[k][n][1];\n h11r += h11r_step;\n h12r += h12r_step;\n h21r += h21r_step;\n h22r += h22r_step;\n if (!PS_BASELINE && ps->enable_ipdopd) {\n h11i += h11i_step;\n h12i += h12i_step;\n h21i += h21i_step;\n h22i += h22i_step;\n l[k][n][0] = h11r*l_re + h21r*r_re - h11i*l_im - h21i*r_im;\n l[k][n][1] = h11r*l_im + h21r*r_im + h11i*l_re + h21i*r_re;\n r[k][n][0] = h12r*l_re + h22r*r_re - h12i*l_im - h22i*r_im;\n r[k][n][1] = h12r*l_im + h22r*r_im + h12i*l_re + h22i*r_re;\n } else {\n l[k][n][0] = h11r*l_re + h21r*r_re;\n l[k][n][1] = h11r*l_im + h21r*r_im;\n r[k][n][0] = h12r*l_re + h22r*r_re;\n r[k][n][1] = h12r*l_im + h22r*r_im;\n }\n }\n }\n }\n}']
36,582
0
https://github.com/openssl/openssl/blob/04485c5bc0dc7f49940e6d91b27cdcc7b83a8ab5/crypto/bn/bn_ctx.c/#L355
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n\tBN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint ret=0;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(m);\n\tBN_CTX_start(ctx);\n\tif ((t = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (a == b)\n\t\t{ if (!BN_sqr(t,a,ctx)) goto err; }\n\telse\n\t\t{ if (!BN_mul(t,a,b,ctx)) goto err; }\n\tif (!BN_nnmod(r,t,m,ctx)) goto err;\n\tbn_check_top(r);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\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_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n\t{\n\tint max,al;\n\tint ret = 0;\n\tBIGNUM *tmp,*rr;\n#ifdef BN_COUNT\n\tfprintf(stderr,"BN_sqr %d * %d\\n",a->top,a->top);\n#endif\n\tbn_check_top(a);\n\tal=a->top;\n\tif (al <= 0)\n\t\t{\n\t\tr->top=0;\n\t\treturn 1;\n\t\t}\n\tBN_CTX_start(ctx);\n\trr=(a != r) ? r : BN_CTX_get(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tif (!rr || !tmp) goto err;\n\tmax = 2 * al;\n\tif (bn_wexpand(rr,max) == NULL) goto err;\n\tif (al == 4)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[8];\n\t\tbn_sqr_normal(rr->d,a->d,4,t);\n#else\n\t\tbn_sqr_comba4(rr->d,a->d);\n#endif\n\t\t}\n\telse if (al == 8)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[16];\n\t\tbn_sqr_normal(rr->d,a->d,8,t);\n#else\n\t\tbn_sqr_comba8(rr->d,a->d);\n#endif\n\t\t}\n\telse\n\t\t{\n#if defined(BN_RECURSION)\n\t\tif (al < BN_SQR_RECURSIVE_SIZE_NORMAL)\n\t\t\t{\n\t\t\tBN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];\n\t\t\tbn_sqr_normal(rr->d,a->d,al,t);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tint j,k;\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,k*2) == NULL) goto err;\n\t\t\t\tbn_sqr_recursive(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,max) == NULL) goto err;\n\t\t\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\t}\n#else\n\t\tif (bn_wexpand(tmp,max) == NULL) goto err;\n\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n#endif\n\t\t}\n\trr->neg=0;\n\tif(a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n\t\trr->top = max - 1;\n\telse\n\t\trr->top = max;\n\tif (rr != r) BN_copy(r,rr);\n\tret = 1;\n err:\n\tbn_check_top(rr);\n\tbn_check_top(tmp);\n\tBN_CTX_end(ctx);\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\tint no_branch=0;\n\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\tno_branch=1;\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\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 (!no_branch && 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 || tmp == NULL || snum == NULL)\n\t\tgoto 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 (no_branch)\n\t\t{\n\t\tif (snum->top <= sdiv->top+1)\n\t\t\t{\n\t\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\t\tsnum->top = sdiv->top + 2;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\t\tsnum->d[snum->top] = 0;\n\t\t\tsnum->top ++;\n\t\t\t}\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-no_branch;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (!no_branch)\n\t\t{\n\t\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t\t{\n\t\t\tbn_clear_top2max(&wnum);\n\t\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t\t*resp=1;\n\t\t\t}\n\t\telse\n\t\t\tres->top--;\n\t\t}\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;\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\t{\n\t\t\tBN_ULONG ql, qh;\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\t}\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\tif (no_branch)\tbn_correct_top(res);\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}']
36,583
0
https://github.com/libav/libav/blob/a72cad0a6c05aa74940101e937cb3dc602d7d67b/libavcodec/vmdav.c/#L96
static void lz_unpack(const unsigned char *src, int src_len, unsigned char *dest, int dest_len) { const unsigned char *s; unsigned int s_len; unsigned char *d; unsigned char *d_end; unsigned char queue[QUEUE_SIZE]; unsigned int qpos; unsigned int dataleft; unsigned int chainofs; unsigned int chainlen; unsigned int speclen; unsigned char tag; unsigned int i, j; s = src; s_len = src_len; d = dest; d_end = d + dest_len; dataleft = AV_RL32(s); s += 4; s_len -= 4; memset(queue, 0x20, QUEUE_SIZE); if (s_len < 4) return; if (AV_RL32(s) == 0x56781234) { s += 4; s_len -= 4; qpos = 0x111; speclen = 0xF + 3; } else { qpos = 0xFEE; speclen = 100; } while (dataleft > 0 && s_len > 0) { tag = *s++; s_len--; if ((tag == 0xFF) && (dataleft > 8)) { if (d + 8 > d_end || s_len < 8) return; for (i = 0; i < 8; i++) { queue[qpos++] = *d++ = *s++; qpos &= QUEUE_MASK; } s_len -= 8; dataleft -= 8; } else { for (i = 0; i < 8; i++) { if (dataleft == 0) break; if (tag & 0x01) { if (d + 1 > d_end || s_len < 1) return; queue[qpos++] = *d++ = *s++; qpos &= QUEUE_MASK; dataleft--; s_len--; } else { if (s_len < 2) return; chainofs = *s++; chainofs |= ((*s & 0xF0) << 4); chainlen = (*s++ & 0x0F) + 3; s_len -= 2; if (chainlen == speclen) { if (s_len < 1) return; chainlen = *s++ + 0xF + 3; s_len--; } if (d + chainlen > d_end) return; for (j = 0; j < chainlen; j++) { *d = queue[chainofs++ & QUEUE_MASK]; queue[qpos++] = *d++; qpos &= QUEUE_MASK; } dataleft -= chainlen; } tag >>= 1; } } } }
['static void vmd_decode(VmdVideoContext *s)\n{\n int i;\n unsigned int *palette32;\n unsigned char r, g, b;\n const unsigned char *p = s->buf + 16;\n const unsigned char *pb;\n unsigned int pb_size;\n unsigned char meth;\n unsigned char *dp;\n unsigned char *pp;\n unsigned char len;\n int ofs;\n int frame_x, frame_y;\n int frame_width, frame_height;\n frame_x = AV_RL16(&s->buf[6]);\n frame_y = AV_RL16(&s->buf[8]);\n frame_width = AV_RL16(&s->buf[10]) - frame_x + 1;\n frame_height = AV_RL16(&s->buf[12]) - frame_y + 1;\n if (frame_x < 0 || frame_width < 0 ||\n frame_x >= s->avctx->width ||\n frame_width > s->avctx->width ||\n frame_x + frame_width > s->avctx->width)\n return;\n if (frame_y < 0 || frame_height < 0 ||\n frame_y >= s->avctx->height ||\n frame_height > s->avctx->height ||\n frame_y + frame_height > s->avctx->height)\n return;\n if ((frame_width == s->avctx->width && frame_height == s->avctx->height) &&\n (frame_x || frame_y)) {\n s->x_off = frame_x;\n s->y_off = frame_y;\n }\n frame_x -= s->x_off;\n frame_y -= s->y_off;\n if (s->prev_frame.data[0] &&\n (frame_x || frame_y || (frame_width != s->avctx->width) ||\n (frame_height != s->avctx->height))) {\n memcpy(s->frame.data[0], s->prev_frame.data[0],\n s->avctx->height * s->frame.linesize[0]);\n }\n if (s->buf[15] & 0x02) {\n p += 2;\n palette32 = (unsigned int *)s->palette;\n for (i = 0; i < PALETTE_COUNT; i++) {\n r = *p++ * 4;\n g = *p++ * 4;\n b = *p++ * 4;\n palette32[i] = (r << 16) | (g << 8) | (b);\n }\n s->size -= (256 * 3 + 2);\n }\n if (s->size > 0) {\n pb = p;\n pb_size = s->buf + s->size - pb;\n if (pb_size < 1)\n return;\n meth = *pb++; pb_size--;\n if (meth & 0x80) {\n lz_unpack(pb, pb_size,\n s->unpack_buffer, s->unpack_buffer_size);\n meth &= 0x7F;\n pb = s->unpack_buffer;\n pb_size = s->unpack_buffer_size;\n }\n dp = &s->frame.data[0][frame_y * s->frame.linesize[0] + frame_x];\n pp = &s->prev_frame.data[0][frame_y * s->prev_frame.linesize[0] + frame_x];\n switch (meth) {\n case 1:\n for (i = 0; i < frame_height; i++) {\n ofs = 0;\n do {\n if (pb_size < 1)\n return;\n len = *pb++;\n pb_size--;\n if (len & 0x80) {\n len = (len & 0x7F) + 1;\n if (ofs + len > frame_width || pb_size < len)\n return;\n memcpy(&dp[ofs], pb, len);\n pb += len;\n pb_size -= len;\n ofs += len;\n } else {\n if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])\n return;\n memcpy(&dp[ofs], &pp[ofs], len + 1);\n ofs += len + 1;\n }\n } while (ofs < frame_width);\n if (ofs > frame_width) {\n av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\\n",\n ofs, frame_width);\n break;\n }\n dp += s->frame.linesize[0];\n pp += s->prev_frame.linesize[0];\n }\n break;\n case 2:\n for (i = 0; i < frame_height; i++) {\n if (pb_size < frame_width)\n return;\n memcpy(dp, pb, frame_width);\n pb += frame_width;\n pb_size -= frame_width;\n dp += s->frame.linesize[0];\n pp += s->prev_frame.linesize[0];\n }\n break;\n case 3:\n for (i = 0; i < frame_height; i++) {\n ofs = 0;\n do {\n if (pb_size < 1)\n return;\n len = *pb++;\n pb_size--;\n if (len & 0x80) {\n len = (len & 0x7F) + 1;\n if (pb_size < 1)\n return;\n if (*pb++ == 0xFF)\n len = rle_unpack(pb, &dp[ofs], len, pb_size, frame_width - ofs);\n else {\n if (pb_size < len)\n return;\n memcpy(&dp[ofs], pb, len);\n }\n pb += len;\n pb_size -= 1 + len;\n ofs += len;\n } else {\n if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])\n return;\n memcpy(&dp[ofs], &pp[ofs], len + 1);\n ofs += len + 1;\n }\n } while (ofs < frame_width);\n if (ofs > frame_width) {\n av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\\n",\n ofs, frame_width);\n }\n dp += s->frame.linesize[0];\n pp += s->prev_frame.linesize[0];\n }\n break;\n }\n }\n}', 'static void lz_unpack(const unsigned char *src, int src_len,\n unsigned char *dest, int dest_len)\n{\n const unsigned char *s;\n unsigned int s_len;\n unsigned char *d;\n unsigned char *d_end;\n unsigned char queue[QUEUE_SIZE];\n unsigned int qpos;\n unsigned int dataleft;\n unsigned int chainofs;\n unsigned int chainlen;\n unsigned int speclen;\n unsigned char tag;\n unsigned int i, j;\n s = src;\n s_len = src_len;\n d = dest;\n d_end = d + dest_len;\n dataleft = AV_RL32(s);\n s += 4; s_len -= 4;\n memset(queue, 0x20, QUEUE_SIZE);\n if (s_len < 4)\n return;\n if (AV_RL32(s) == 0x56781234) {\n s += 4; s_len -= 4;\n qpos = 0x111;\n speclen = 0xF + 3;\n } else {\n qpos = 0xFEE;\n speclen = 100;\n }\n while (dataleft > 0 && s_len > 0) {\n tag = *s++; s_len--;\n if ((tag == 0xFF) && (dataleft > 8)) {\n if (d + 8 > d_end || s_len < 8)\n return;\n for (i = 0; i < 8; i++) {\n queue[qpos++] = *d++ = *s++;\n qpos &= QUEUE_MASK;\n }\n s_len -= 8;\n dataleft -= 8;\n } else {\n for (i = 0; i < 8; i++) {\n if (dataleft == 0)\n break;\n if (tag & 0x01) {\n if (d + 1 > d_end || s_len < 1)\n return;\n queue[qpos++] = *d++ = *s++;\n qpos &= QUEUE_MASK;\n dataleft--;\n s_len--;\n } else {\n if (s_len < 2)\n return;\n chainofs = *s++;\n chainofs |= ((*s & 0xF0) << 4);\n chainlen = (*s++ & 0x0F) + 3;\n s_len -= 2;\n if (chainlen == speclen) {\n if (s_len < 1)\n return;\n chainlen = *s++ + 0xF + 3;\n s_len--;\n }\n if (d + chainlen > d_end)\n return;\n for (j = 0; j < chainlen; j++) {\n *d = queue[chainofs++ & QUEUE_MASK];\n queue[qpos++] = *d++;\n qpos &= QUEUE_MASK;\n }\n dataleft -= chainlen;\n }\n tag >>= 1;\n }\n }\n }\n}']
36,584
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; }
['static int char2_field_tests(void)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *p = NULL, *a = NULL, *b = NULL;\n EC_GROUP *group = NULL, *tmp = NULL;\n EC_POINT *P = NULL, *Q = NULL, *R = NULL;\n BIGNUM *x = NULL, *y = NULL, *z = NULL, *cof = NULL, *yplusone = NULL;\n unsigned char buf[100];\n size_t len;\n int k, r = 0;\n if (!TEST_ptr(ctx = BN_CTX_new())\n || !TEST_ptr(p = BN_new())\n || !TEST_ptr(a = BN_new())\n || !TEST_ptr(b = BN_new())\n || !TEST_true(BN_hex2bn(&p, "13"))\n || !TEST_true(BN_hex2bn(&a, "3"))\n || !TEST_true(BN_hex2bn(&b, "1")))\n goto err;\n group = EC_GROUP_new(EC_GF2m_simple_method());\n if (!TEST_ptr(group)\n || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n || !TEST_ptr(tmp = EC_GROUP_new(EC_GROUP_method_of(group)))\n || !TEST_true(EC_GROUP_copy(tmp, group)))\n goto err;\n EC_GROUP_free(group);\n group = tmp;\n tmp = NULL;\n if (!TEST_true(EC_GROUP_get_curve(group, p, a, b, ctx)))\n goto err;\n TEST_info("Curve defined by Weierstrass equation");\n TEST_note(" y^2 + x*y = x^3 + a*x^2 + b (mod p)");\n test_output_bignum("a", a);\n test_output_bignum("b", b);\n test_output_bignum("p", p);\n if (!TEST_ptr(P = EC_POINT_new(group))\n || !TEST_ptr(Q = EC_POINT_new(group))\n || !TEST_ptr(R = EC_POINT_new(group))\n || !TEST_true(EC_POINT_set_to_infinity(group, P))\n || !TEST_true(EC_POINT_is_at_infinity(group, P)))\n goto err;\n buf[0] = 0;\n if (!TEST_true(EC_POINT_oct2point(group, Q, buf, 1, ctx))\n || !TEST_true(EC_POINT_add(group, P, P, Q, ctx))\n || !TEST_true(EC_POINT_is_at_infinity(group, P))\n || !TEST_ptr(x = BN_new())\n || !TEST_ptr(y = BN_new())\n || !TEST_ptr(z = BN_new())\n || !TEST_ptr(cof = BN_new())\n || !TEST_ptr(yplusone = BN_new())\n || !TEST_true(BN_hex2bn(&x, "6"))\n# ifdef OPENSSL_EC_BIN_PT_COMP\n || !TEST_true(EC_POINT_set_compressed_coordinates(group, Q, x, 1, ctx))\n# else\n || !TEST_true(BN_hex2bn(&y, "8"))\n || !TEST_true(EC_POINT_set_affine_coordinates(group, Q, x, y, ctx))\n# endif\n )\n goto err;\n if (!TEST_int_gt(EC_POINT_is_on_curve(group, Q, ctx), 0)) {\n# ifdef OPENSSL_EC_BIN_PT_COMP\n if (!TEST_true(EC_POINT_get_affine_coordinates(group, Q, x, y, ctx)))\n goto err;\n# endif\n TEST_info("Point is not on curve");\n test_output_bignum("x", x);\n test_output_bignum("y", y);\n goto err;\n }\n TEST_note("A cyclic subgroup:");\n k = 100;\n do {\n if (!TEST_int_ne(k--, 0))\n goto err;\n if (EC_POINT_is_at_infinity(group, P))\n TEST_note(" point at infinity");\n else {\n if (!TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y,\n ctx)))\n goto err;\n test_output_bignum("x", x);\n test_output_bignum("y", y);\n }\n if (!TEST_true(EC_POINT_copy(R, P))\n || !TEST_true(EC_POINT_add(group, P, P, Q, ctx)))\n goto err;\n }\n while (!EC_POINT_is_at_infinity(group, P));\n if (!TEST_true(EC_POINT_add(group, P, Q, R, ctx))\n || !TEST_true(EC_POINT_is_at_infinity(group, P)))\n goto err;\n# ifdef OPENSSL_EC_BIN_PT_COMP\n len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED,\n buf, sizeof(buf), ctx);\n if (!TEST_size_t_ne(len, 0)\n || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))\n || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))\n goto err;\n test_output_memory("Generator as octet string, compressed form:",\n buf, len);\n# endif\n len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED,\n buf, sizeof(buf), ctx);\n if (!TEST_size_t_ne(len, 0)\n || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))\n || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))\n goto err;\n test_output_memory("Generator as octet string, uncompressed form:",\n buf, len);\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 (!TEST_size_t_ne(len, 0)\n || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))\n || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))\n goto err;\n test_output_memory("Generator as octet string, hybrid form:",\n buf, len);\n# endif\n if (!TEST_true(EC_POINT_invert(group, P, ctx))\n || !TEST_int_eq(0, EC_POINT_cmp(group, P, R, ctx)))\n goto err;\n TEST_note("\\n");\n r = 1;\nerr:\n BN_CTX_free(ctx);\n BN_free(p);\n BN_free(a);\n BN_free(b);\n EC_GROUP_free(group);\n EC_GROUP_free(tmp);\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 return r;\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}', '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#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\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}']
36,585
0
https://github.com/openssl/openssl/blob/fbb7b33b28e3026c7443339c1f300ef725e2ff50/crypto/objects/o_names.c/#L130
int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *), int (*cmp_func) (const char *, const char *), void (*free_func) (const char *, int, const char *)) { int ret = 0, i, push; NAME_FUNCS *name_funcs; if (!OBJ_NAME_init()) return 0; CRYPTO_THREAD_write_lock(obj_lock); if (name_funcs_stack == NULL) { CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); name_funcs_stack = sk_NAME_FUNCS_new_null(); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); } if (name_funcs_stack == NULL) { goto out; } ret = names_type_num; names_type_num++; for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) { CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); name_funcs = OPENSSL_zalloc(sizeof(*name_funcs)); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); if (name_funcs == NULL) { OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE); ret = 0; goto out; } name_funcs->hash_func = OPENSSL_LH_strhash; name_funcs->cmp_func = obj_strcmp; CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); push = sk_NAME_FUNCS_push(name_funcs_stack, name_funcs); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); if (!push) { OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE); OPENSSL_free(name_funcs); ret = 0; goto out; } } name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret); if (hash_func != NULL) name_funcs->hash_func = hash_func; if (cmp_func != NULL) name_funcs->cmp_func = cmp_func; if (free_func != NULL) name_funcs->free_func = free_func; out: CRYPTO_THREAD_unlock(obj_lock); return ret; }
['int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),\n int (*cmp_func) (const char *, const char *),\n void (*free_func) (const char *, int, const char *))\n{\n int ret = 0, i, push;\n NAME_FUNCS *name_funcs;\n if (!OBJ_NAME_init())\n return 0;\n CRYPTO_THREAD_write_lock(obj_lock);\n if (name_funcs_stack == NULL) {\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n name_funcs_stack = sk_NAME_FUNCS_new_null();\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n }\n if (name_funcs_stack == NULL) {\n goto out;\n }\n ret = names_type_num;\n names_type_num++;\n for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) {\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n name_funcs = OPENSSL_zalloc(sizeof(*name_funcs));\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n if (name_funcs == NULL) {\n OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);\n ret = 0;\n goto out;\n }\n name_funcs->hash_func = OPENSSL_LH_strhash;\n name_funcs->cmp_func = obj_strcmp;\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n push = sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n if (!push) {\n OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(name_funcs);\n ret = 0;\n goto out;\n }\n }\n name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);\n if (hash_func != NULL)\n name_funcs->hash_func = hash_func;\n if (cmp_func != NULL)\n name_funcs->cmp_func = cmp_func;\n if (free_func != NULL)\n name_funcs->free_func = free_func;\nout:\n CRYPTO_THREAD_unlock(obj_lock);\n return ret;\n}', 'int OBJ_NAME_init(void)\n{\n return RUN_ONCE(&init, o_names_init);\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}', 'int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n if (pthread_rwlock_wrlock(lock) != 0)\n return 0;\n# else\n if (pthread_mutex_lock(lock) != 0)\n return 0;\n# endif\n return 1;\n}', 'int CRYPTO_mem_ctrl(int mode)\n{\n#ifdef OPENSSL_NO_CRYPTO_MDEBUG\n return mode - mode;\n#else\n int ret = mh_mode;\n if (!RUN_ONCE(&memdbg_init, do_memdbg_init))\n return -1;\n CRYPTO_THREAD_write_lock(malloc_lock);\n switch (mode) {\n default:\n break;\n case CRYPTO_MEM_CHECK_ON:\n mh_mode = CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE;\n num_disable = 0;\n break;\n case CRYPTO_MEM_CHECK_OFF:\n mh_mode = 0;\n num_disable = 0;\n break;\n case CRYPTO_MEM_CHECK_DISABLE:\n if (mh_mode & CRYPTO_MEM_CHECK_ON) {\n CRYPTO_THREAD_ID cur = CRYPTO_THREAD_get_current_id();\n if (!num_disable\n || !CRYPTO_THREAD_compare_id(disabling_threadid, cur)) {\n CRYPTO_THREAD_unlock(malloc_lock);\n CRYPTO_THREAD_write_lock(long_malloc_lock);\n CRYPTO_THREAD_write_lock(malloc_lock);\n mh_mode &= ~CRYPTO_MEM_CHECK_ENABLE;\n disabling_threadid = cur;\n }\n num_disable++;\n }\n break;\n case CRYPTO_MEM_CHECK_ENABLE:\n if (mh_mode & CRYPTO_MEM_CHECK_ON) {\n if (num_disable) {\n num_disable--;\n if (num_disable == 0) {\n mh_mode |= CRYPTO_MEM_CHECK_ENABLE;\n CRYPTO_THREAD_unlock(long_malloc_lock);\n }\n }\n }\n break;\n }\n CRYPTO_THREAD_unlock(malloc_lock);\n return ret;\n#endif\n}', 'OPENSSL_STACK *OPENSSL_sk_new_null(void)\n{\n return OPENSSL_zalloc(sizeof(OPENSSL_STACK));\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 (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int OPENSSL_sk_num(const OPENSSL_STACK *st)\n{\n return st == NULL ? -1 : st->num;\n}', '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}']
36,586
0
https://gitlab.com/libtiff/libtiff/blob/709e93ded0000128625a23838756a408ea30745d/libtiff/tif_tile.c/#L133
uint32 TIFFNumberOfTiles(TIFF* tif) { TIFFDirectory *td = &tif->tif_dir; uint32 dx = td->td_tilewidth; uint32 dy = td->td_tilelength; uint32 dz = td->td_tiledepth; uint32 ntiles; if (dx == (uint32) -1) dx = td->td_imagewidth; if (dy == (uint32) -1) dy = td->td_imagelength; if (dz == (uint32) -1) dz = td->td_imagedepth; ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 : _TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx), TIFFhowmany_32(td->td_imagelength, dy), "TIFFNumberOfTiles"), TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles"); if (td->td_planarconfig == PLANARCONFIG_SEPARATE) ntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel, "TIFFNumberOfTiles"); return (ntiles); }
['void t2p_read_tiff_init(T2P* t2p, TIFF* input){\n\ttdir_t directorycount=0;\n\ttdir_t i=0;\n\tuint16 pagen=0;\n\tuint16 paged=0;\n\tuint16 xuint16=0;\n\tdirectorycount=TIFFNumberOfDirectories(input);\n\tt2p->tiff_pages = (T2P_PAGE*) _TIFFmalloc(directorycount * sizeof(T2P_PAGE));\n\tif(t2p->tiff_pages==NULL){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"Can\'t allocate %lu bytes of memory for tiff_pages array, %s",\n\t\t\t(unsigned long) directorycount * sizeof(T2P_PAGE),\n\t\t\tTIFFFileName(input));\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\t_TIFFmemset( t2p->tiff_pages, 0x00, directorycount * sizeof(T2P_PAGE));\n\tt2p->tiff_tiles = (T2P_TILES*) _TIFFmalloc(directorycount * sizeof(T2P_TILES));\n\tif(t2p->tiff_tiles==NULL){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"Can\'t allocate %lu bytes of memory for tiff_tiles array, %s",\n\t\t\t(unsigned long) directorycount * sizeof(T2P_TILES),\n\t\t\tTIFFFileName(input));\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\t_TIFFmemset( t2p->tiff_tiles, 0x00, directorycount * sizeof(T2P_TILES));\n\tfor(i=0;i<directorycount;i++){\n\t\tuint32 subfiletype = 0;\n\t\tif(!TIFFSetDirectory(input, i)){\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"Can\'t set directory %u of input file %s",\n\t\t\t\ti,\n\t\t\t\tTIFFFileName(input));\n\t\t\treturn;\n\t\t}\n\t\tif(TIFFGetField(input, TIFFTAG_PAGENUMBER, &pagen, &paged)){\n\t\t\tif((pagen>paged) && (paged != 0)){\n\t\t\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_number =\n\t\t\t\t\tpaged;\n\t\t\t} else {\n\t\t\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_number =\n\t\t\t\t\tpagen;\n\t\t\t}\n\t\t\tgoto ispage2;\n\t\t}\n\t\tif(TIFFGetField(input, TIFFTAG_SUBFILETYPE, &subfiletype)){\n\t\t\tif ( ((subfiletype & FILETYPE_PAGE) != 0)\n || (subfiletype == 0)){\n\t\t\t\tgoto ispage;\n\t\t\t} else {\n\t\t\t\tgoto isnotpage;\n\t\t\t}\n\t\t}\n\t\tif(TIFFGetField(input, TIFFTAG_OSUBFILETYPE, &subfiletype)){\n\t\t\tif ((subfiletype == OFILETYPE_IMAGE)\n\t\t\t\t|| (subfiletype == OFILETYPE_PAGE)\n\t\t\t\t|| (subfiletype == 0) ){\n\t\t\t\tgoto ispage;\n\t\t\t} else {\n\t\t\t\tgoto isnotpage;\n\t\t\t}\n\t\t}\n\t\tispage:\n\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_number=t2p->tiff_pagecount;\n\t\tispage2:\n\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_directory=i;\n\t\tif(TIFFIsTiled(input)){\n\t\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_tilecount =\n\t\t\t\tTIFFNumberOfTiles(input);\n\t\t}\n\t\tt2p->tiff_pagecount++;\n\t\tisnotpage:\n\t\t(void)0;\n\t}\n\tqsort((void*) t2p->tiff_pages, t2p->tiff_pagecount,\n sizeof(T2P_PAGE), t2p_cmp_t2p_page);\n\tfor(i=0;i<t2p->tiff_pagecount;i++){\n\t\tt2p->pdf_xrefcount += 5;\n\t\tTIFFSetDirectory(input, t2p->tiff_pages[i].page_directory );\n\t\tif((TIFFGetField(input, TIFFTAG_PHOTOMETRIC, &xuint16)\n && (xuint16==PHOTOMETRIC_PALETTE))\n\t\t || TIFFGetField(input, TIFFTAG_INDEXED, &xuint16)) {\n\t\t\tt2p->tiff_pages[i].page_extra++;\n\t\t\tt2p->pdf_xrefcount++;\n\t\t}\n#ifdef ZIP_SUPPORT\n\t\tif (TIFFGetField(input, TIFFTAG_COMPRESSION, &xuint16)) {\n if( (xuint16== COMPRESSION_DEFLATE ||\n xuint16== COMPRESSION_ADOBE_DEFLATE) &&\n ((t2p->tiff_pages[i].page_tilecount != 0)\n || TIFFNumberOfStrips(input)==1) &&\n (t2p->pdf_nopassthrough==0)\t){\n if(t2p->pdf_minorversion<2){t2p->pdf_minorversion=2;}\n }\n }\n#endif\n\t\tif (TIFFGetField(input, TIFFTAG_TRANSFERFUNCTION,\n &(t2p->tiff_transferfunction[0]),\n &(t2p->tiff_transferfunction[1]),\n &(t2p->tiff_transferfunction[2]))) {\n\t\t\tif(t2p->tiff_transferfunction[1] !=\n\t\t\t t2p->tiff_transferfunction[0]) {\n\t\t\t\tt2p->tiff_transferfunctioncount = 3;\n\t\t\t\tt2p->tiff_pages[i].page_extra += 4;\n\t\t\t\tt2p->pdf_xrefcount += 4;\n\t\t\t} else {\n\t\t\t\tt2p->tiff_transferfunctioncount = 1;\n\t\t\t\tt2p->tiff_pages[i].page_extra += 2;\n\t\t\t\tt2p->pdf_xrefcount += 2;\n\t\t\t}\n\t\t\tif(t2p->pdf_minorversion < 2)\n\t\t\t\tt2p->pdf_minorversion = 2;\n } else {\n\t\t\tt2p->tiff_transferfunctioncount=0;\n\t\t}\n\t\tif( TIFFGetField(\n\t\t\tinput,\n\t\t\tTIFFTAG_ICCPROFILE,\n\t\t\t&(t2p->tiff_iccprofilelength),\n\t\t\t&(t2p->tiff_iccprofile)) != 0){\n\t\t\tt2p->tiff_pages[i].page_extra++;\n\t\t\tt2p->pdf_xrefcount++;\n\t\t\tif(t2p->pdf_minorversion<3){t2p->pdf_minorversion=3;}\n\t\t}\n\t\tt2p->tiff_tiles[i].tiles_tilecount=\n\t\t\tt2p->tiff_pages[i].page_tilecount;\n\t\tif( (TIFFGetField(input, TIFFTAG_PLANARCONFIG, &xuint16) != 0)\n\t\t\t&& (xuint16 == PLANARCONFIG_SEPARATE ) ){\n\t\t\t\tTIFFGetField(input, TIFFTAG_SAMPLESPERPIXEL, &xuint16);\n\t\t\t\tt2p->tiff_tiles[i].tiles_tilecount/= xuint16;\n\t\t}\n\t\tif( t2p->tiff_tiles[i].tiles_tilecount > 0){\n\t\t\tt2p->pdf_xrefcount +=\n\t\t\t\t(t2p->tiff_tiles[i].tiles_tilecount -1)*2;\n\t\t\tTIFFGetField(input,\n\t\t\t\tTIFFTAG_TILEWIDTH,\n\t\t\t\t&( t2p->tiff_tiles[i].tiles_tilewidth) );\n\t\t\tTIFFGetField(input,\n\t\t\t\tTIFFTAG_TILELENGTH,\n\t\t\t\t&( t2p->tiff_tiles[i].tiles_tilelength) );\n\t\t\tt2p->tiff_tiles[i].tiles_tiles =\n\t\t\t(T2P_TILE*) _TIFFmalloc(\n\t\t\t\tt2p->tiff_tiles[i].tiles_tilecount\n\t\t\t\t* sizeof(T2P_TILE) );\n\t\t\tif( t2p->tiff_tiles[i].tiles_tiles == NULL){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory for t2p_read_tiff_init, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_tiles[i].tiles_tilecount * sizeof(T2P_TILE),\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\treturn;\n}', 'int\nTIFFSetDirectory(TIFF* tif, uint16 dirn)\n{\n\tuint64 nextdir;\n\tuint16 n;\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\tnextdir = tif->tif_header.classic.tiff_diroff;\n\telse\n\t\tnextdir = tif->tif_header.big.tiff_diroff;\n\tfor (n = dirn; n > 0 && nextdir != 0; n--)\n\t\tif (!TIFFAdvanceDirectory(tif, &nextdir, NULL))\n\t\t\treturn (0);\n\ttif->tif_nextdiroff = nextdir;\n\ttif->tif_curdir = (dirn - n) - 1;\n\ttif->tif_dirnumber = 0;\n\treturn (TIFFReadDirectory(tif));\n}', 'uint32\nTIFFNumberOfTiles(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 dx = td->td_tilewidth;\n\tuint32 dy = td->td_tilelength;\n\tuint32 dz = td->td_tiledepth;\n\tuint32 ntiles;\n\tif (dx == (uint32) -1)\n\t\tdx = td->td_imagewidth;\n\tif (dy == (uint32) -1)\n\t\tdy = td->td_imagelength;\n\tif (dz == (uint32) -1)\n\t\tdz = td->td_imagedepth;\n\tntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :\n\t _TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx),\n\t TIFFhowmany_32(td->td_imagelength, dy),\n\t "TIFFNumberOfTiles"),\n\t TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\tntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel,\n\t\t "TIFFNumberOfTiles");\n\treturn (ntiles);\n}']
36,587
0
https://github.com/openssl/openssl/blob/404fb7149effa40d04625272424a28ff25c0e673/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); }
['void CRYPTO_dbg_realloc(void *addr1, void *addr2, int num,\n\tconst char *file, int line, int before_p)\n\t{\n\tMEM m,*mp;\n#ifdef LEVITTE_DEBUG\n\tfprintf(stderr, "LEVITTE_DEBUG: --> CRYPTO_dbg_malloc(addr1 = %p, addr2 = %p, num = %d, file = \\"%s\\", line = %d, before_p = %d)\\n",\n\t\taddr1, addr2, num, file, line, before_p);\n#endif\n\tswitch(before_p)\n\t\t{\n\tcase 0:\n\t\tbreak;\n\tcase 1:\n\t\tif (addr2 == NULL)\n\t\t\tbreak;\n\t\tif (addr1 == NULL)\n\t\t\t{\n\t\t\tCRYPTO_dbg_malloc(addr2, num, file, line, 128 | before_p);\n\t\t\tbreak;\n\t\t\t}\n\t\tif (is_MemCheck_on())\n\t\t\t{\n\t\t\tMemCheck_off();\n\t\t\tm.addr=addr1;\n\t\t\tmp=(MEM *)lh_delete(mh,(char *)&m);\n\t\t\tif (mp != NULL)\n\t\t\t\t{\n#ifdef LEVITTE_DEBUG\n\t\t\t\tfprintf(stderr, "LEVITTE_DEBUG: [%5d] * 0x%p (%d) -> 0x%p (%d)\\n",\n\t\t\t\t\tmp->order,\n\t\t\t\t\tmp->addr, mp->num,\n\t\t\t\t\taddr2, num);\n#endif\n\t\t\t\tmp->addr=addr2;\n\t\t\t\tmp->num=num;\n\t\t\t\tlh_insert(mh,(char *)mp);\n\t\t\t\t}\n\t\t\tMemCheck_on();\n\t\t\t}\n\t\tbreak;\n\t\t}\n\treturn;\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}']
36,588
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/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 **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, STACK **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_new(NULL))) goto err;\n\tvtmp->section = NULL;\n\tvtmp->name = tname;\n\tvtmp->value = tvalue;\n\tif(!sk_push(*extlist, (char *)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}']
36,589
0
https://github.com/libav/libav/blob/6cecd63005b29a1dc3a5104e6ac85fd112705122/ffmpeg.c/#L3254
static void new_subtitle_stream(AVFormatContext *oc) { AVStream *st; AVCodecContext *subtitle_enc; 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_SUBTITLE); bitstream_filters[nb_output_files][oc->nb_streams - 1]= subtitle_bitstream_filters; subtitle_bitstream_filters= NULL; subtitle_enc = st->codec; subtitle_enc->codec_type = CODEC_TYPE_SUBTITLE; if(subtitle_codec_tag) subtitle_enc->codec_tag= subtitle_codec_tag; if (subtitle_stream_copy) { st->stream_copy = 1; } else { set_context_opts(avcodec_opts[CODEC_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM); subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 1); output_codecs[nb_ocodecs] = avcodec_find_encoder_by_name(subtitle_codec_name); } nb_ocodecs++; if (subtitle_language) { av_metadata_set(&st->metadata, "language", subtitle_language); av_free(subtitle_language); subtitle_language = NULL; } subtitle_disable = 0; av_freep(&subtitle_codec_name); subtitle_stream_copy = 0; }
['static void new_subtitle_stream(AVFormatContext *oc)\n{\n AVStream *st;\n AVCodecContext *subtitle_enc;\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_SUBTITLE);\n bitstream_filters[nb_output_files][oc->nb_streams - 1]= subtitle_bitstream_filters;\n subtitle_bitstream_filters= NULL;\n subtitle_enc = st->codec;\n subtitle_enc->codec_type = CODEC_TYPE_SUBTITLE;\n if(subtitle_codec_tag)\n subtitle_enc->codec_tag= subtitle_codec_tag;\n if (subtitle_stream_copy) {\n st->stream_copy = 1;\n } else {\n set_context_opts(avcodec_opts[CODEC_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM);\n subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 1);\n output_codecs[nb_ocodecs] = avcodec_find_encoder_by_name(subtitle_codec_name);\n }\n nb_ocodecs++;\n if (subtitle_language) {\n av_metadata_set(&st->metadata, "language", subtitle_language);\n av_free(subtitle_language);\n subtitle_language = NULL;\n }\n subtitle_disable = 0;\n av_freep(&subtitle_codec_name);\n subtitle_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}']
36,590
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/test/danetest.c/#L127
static int verify_chain(SSL *ssl, STACK_OF(X509) *chain) { int ret; X509_STORE_CTX *store_ctx; SSL_CTX *ssl_ctx = SSL_get_SSL_CTX(ssl); X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx); int store_ctx_idx = SSL_get_ex_data_X509_STORE_CTX_idx(); X509 *cert = sk_X509_value(chain, 0); if ((store_ctx = X509_STORE_CTX_new()) == NULL) return -1; if (!X509_STORE_CTX_init(store_ctx, store, cert, chain)) return 0; X509_STORE_CTX_set_ex_data(store_ctx, store_ctx_idx, ssl); X509_STORE_CTX_set_default(store_ctx, SSL_is_server(ssl) ? "ssl_client" : "ssl_server"); X509_VERIFY_PARAM_set1(X509_STORE_CTX_get0_param(store_ctx), SSL_get0_param(ssl)); store_ctx_dane_init(store_ctx, ssl); if (SSL_get_verify_callback(ssl)) X509_STORE_CTX_set_verify_cb(store_ctx, SSL_get_verify_callback(ssl)); ret = X509_verify_cert(store_ctx); SSL_set_verify_result(ssl, X509_STORE_CTX_get_error(store_ctx)); X509_STORE_CTX_cleanup(store_ctx); X509_STORE_CTX_free(store_ctx); return (ret); }
['static int verify_chain(SSL *ssl, STACK_OF(X509) *chain)\n{\n int ret;\n X509_STORE_CTX *store_ctx;\n SSL_CTX *ssl_ctx = SSL_get_SSL_CTX(ssl);\n X509_STORE *store = SSL_CTX_get_cert_store(ssl_ctx);\n int store_ctx_idx = SSL_get_ex_data_X509_STORE_CTX_idx();\n X509 *cert = sk_X509_value(chain, 0);\n if ((store_ctx = X509_STORE_CTX_new()) == NULL)\n return -1;\n if (!X509_STORE_CTX_init(store_ctx, store, cert, chain))\n\treturn 0;\n X509_STORE_CTX_set_ex_data(store_ctx, store_ctx_idx, ssl);\n X509_STORE_CTX_set_default(store_ctx,\n SSL_is_server(ssl) ? "ssl_client" : "ssl_server");\n X509_VERIFY_PARAM_set1(X509_STORE_CTX_get0_param(store_ctx),\n SSL_get0_param(ssl));\n store_ctx_dane_init(store_ctx, ssl);\n if (SSL_get_verify_callback(ssl))\n\tX509_STORE_CTX_set_verify_cb(store_ctx, SSL_get_verify_callback(ssl));\n ret = X509_verify_cert(store_ctx);\n SSL_set_verify_result(ssl, X509_STORE_CTX_get_error(store_ctx));\n X509_STORE_CTX_cleanup(store_ctx);\n X509_STORE_CTX_free(store_ctx);\n return (ret);\n}', 'SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl)\n{\n return (ssl->ctx);\n}', 'X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx)\n{\n return (ctx->cert_store);\n}', 'DEFINE_STACK_OF(X509)', '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}', 'X509_STORE_CTX *X509_STORE_CTX_new(void)\n{\n X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));\n if (ctx == NULL) {\n X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n return 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 (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}']
36,591
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/pem/pvkfmt.c/#L656
static int derive_pvk_key(unsigned char *key, const unsigned char *salt, unsigned int saltlen, const unsigned char *pass, int passlen) { EVP_MD_CTX *mctx = EVP_MD_CTX_new(); int rv = 1; if (mctx == NULL || !EVP_DigestInit_ex(mctx, EVP_sha1(), NULL) || !EVP_DigestUpdate(mctx, salt, saltlen) || !EVP_DigestUpdate(mctx, pass, passlen) || !EVP_DigestFinal_ex(mctx, key, NULL)) rv = 0; EVP_MD_CTX_free(mctx); return rv; }
['static int derive_pvk_key(unsigned char *key,\n const unsigned char *salt, unsigned int saltlen,\n const unsigned char *pass, int passlen)\n{\n EVP_MD_CTX *mctx = EVP_MD_CTX_new();\n int rv = 1;\n if (mctx == NULL\n || !EVP_DigestInit_ex(mctx, EVP_sha1(), NULL)\n || !EVP_DigestUpdate(mctx, salt, saltlen)\n || !EVP_DigestUpdate(mctx, pass, passlen)\n || !EVP_DigestFinal_ex(mctx, key, NULL))\n rv = 0;\n EVP_MD_CTX_free(mctx);\n return rv;\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 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}', 'const EVP_MD *EVP_sha1(void)\n{\n return &sha1_md;\n}', 'int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)\n{\n return ctx->update(ctx, data, count);\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
36,592
0
https://github.com/openssl/openssl/blob/a09474dd2df89d5719b58bf6b3110344ea046ab9/ssl/ssltest.c/#L463
static int verify_alpn(SSL *client, SSL *server) { const unsigned char *client_proto, *server_proto; unsigned int client_proto_len = 0, server_proto_len = 0; SSL_get0_alpn_selected(client, &client_proto, &client_proto_len); SSL_get0_alpn_selected(server, &server_proto, &server_proto_len); if (alpn_selected != NULL) { OPENSSL_free(alpn_selected); alpn_selected = NULL; } if (client_proto_len != server_proto_len || memcmp(client_proto, server_proto, client_proto_len) != 0) { BIO_printf(bio_stdout, "ALPN selected protocols differ!\n"); goto err; } if (client_proto_len > 0 && alpn_expected == NULL) { BIO_printf(bio_stdout, "ALPN unexpectedly negotiated\n"); goto err; } if (alpn_expected != NULL && (client_proto_len != strlen(alpn_expected) || memcmp(client_proto, alpn_expected, client_proto_len) != 0)) { BIO_printf(bio_stdout, "ALPN selected protocols not equal to expected protocol: %s\n", alpn_expected); goto err; } return 0; err: BIO_printf(bio_stdout, "ALPN results: client: '"); BIO_write(bio_stdout, client_proto, client_proto_len); BIO_printf(bio_stdout, "', server: '"); BIO_write(bio_stdout, server_proto, server_proto_len); BIO_printf(bio_stdout, "'\n"); BIO_printf(bio_stdout, "ALPN configured: client: '%s', server: '%s'\n", alpn_client, alpn_server); return -1; }
['static int verify_alpn(SSL *client, SSL *server)\n\t{\n\tconst unsigned char *client_proto, *server_proto;\n\tunsigned int client_proto_len = 0, server_proto_len = 0;\n\tSSL_get0_alpn_selected(client, &client_proto, &client_proto_len);\n\tSSL_get0_alpn_selected(server, &server_proto, &server_proto_len);\n\tif (alpn_selected != NULL)\n\t\t{\n\t\tOPENSSL_free(alpn_selected);\n\t\talpn_selected = NULL;\n\t\t}\n\tif (client_proto_len != server_proto_len ||\n\t memcmp(client_proto, server_proto, client_proto_len) != 0)\n\t\t{\n\t\tBIO_printf(bio_stdout, "ALPN selected protocols differ!\\n");\n\t\tgoto err;\n\t\t}\n\tif (client_proto_len > 0 && alpn_expected == NULL)\n\t\t{\n\t\tBIO_printf(bio_stdout, "ALPN unexpectedly negotiated\\n");\n\t\tgoto err;\n\t\t}\n\tif (alpn_expected != NULL &&\n\t (client_proto_len != strlen(alpn_expected) ||\n\t memcmp(client_proto, alpn_expected, client_proto_len) != 0))\n\t\t{\n\t\tBIO_printf(bio_stdout, "ALPN selected protocols not equal to expected protocol: %s\\n", alpn_expected);\n\t\tgoto err;\n\t\t}\n\treturn 0;\nerr:\n\tBIO_printf(bio_stdout, "ALPN results: client: \'");\n\tBIO_write(bio_stdout, client_proto, client_proto_len);\n\tBIO_printf(bio_stdout, "\', server: \'");\n\tBIO_write(bio_stdout, server_proto, server_proto_len);\n\tBIO_printf(bio_stdout, "\'\\n");\n\tBIO_printf(bio_stdout, "ALPN configured: client: \'%s\', server: \'%s\'\\n", alpn_client, alpn_server);\n\treturn -1;\n\t}', 'void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,\n\t\t\t unsigned *len)\n\t{\n\t*data = NULL;\n\tif (ssl->s3)\n\t\t*data = ssl->s3->alpn_selected;\n\tif (*data == NULL)\n\t\t*len = 0;\n\telse\n\t\t*len = ssl->s3->alpn_selected_len;\n\t}', 'void CRYPTO_free(void *str)\n\t{\n\tif (free_debug_func != NULL)\n\t\tfree_debug_func(str, 0);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: < 0x%p\\n", str);\n#endif\n\tfree_func(str);\n\tif (free_debug_func != NULL)\n\t\tfree_debug_func(NULL, 1);\n\t}']
36,593
0
https://github.com/libav/libav/blob/fc322d6a70189da24dbd445c710bb214eb031ce7/libavcodec/error_resilience.c/#L581
static void guess_mv(ERContext *s) { uint8_t *fixed = s->er_temp_buffer; #define MV_FROZEN 3 #define MV_CHANGED 2 #define MV_UNCHANGED 1 const ptrdiff_t 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; ptrdiff_t 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->cur_pic.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; int mv_dir = (s->last_pic.f && s->last_pic.f->data[0]) ? MV_DIR_FORWARD : MV_DIR_BACKWARD; if (IS_INTRA(s->cur_pic.mb_type[mb_xy])) continue; if (!(s->error_status_table[mb_xy] & ER_MV_ERROR)) continue; s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; s->decode_mb(s->opaque, 0, mv_dir, MV_TYPE_16X16, &s->mv, mb_x, mb_y, 0, 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 = 0, prev_y = 0, prev_ref = 0; if ((mb_x ^ mb_y ^ pass) & 1) continue; if (fixed[mb_xy] == MV_FROZEN) continue; 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->cur_pic.motion_val[0][mot_index - mot_step][0]; mv_predictor[pred_count][1] = s->cur_pic.motion_val[0][mot_index - mot_step][1]; ref[pred_count] = s->cur_pic.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->cur_pic.motion_val[0][mot_index + mot_step][0]; mv_predictor[pred_count][1] = s->cur_pic.motion_val[0][mot_index + mot_step][1]; ref[pred_count] = s->cur_pic.ref_index[0][4 * (mb_xy + 1)]; pred_count++; } if (mb_y > 0 && fixed[mb_xy - mb_stride]) { mv_predictor[pred_count][0] = s->cur_pic.motion_val[0][mot_index - mot_stride * mot_step][0]; mv_predictor[pred_count][1] = s->cur_pic.motion_val[0][mot_index - mot_stride * mot_step][1]; ref[pred_count] = s->cur_pic.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->cur_pic.motion_val[0][mot_index + mot_stride * mot_step][0]; mv_predictor[pred_count][1] = s->cur_pic.motion_val[0][mot_index + mot_stride * mot_step][1]; ref[pred_count] = s->cur_pic.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 == AV_CODEC_ID_H264) { } else { ff_thread_await_progress(s->last_pic.tf, mb_y, 0); } if (!s->last_pic.motion_val[0] || !s->last_pic.ref_index[0]) goto skip_last_mv; prev_x = s->last_pic.motion_val[0][mot_index][0]; prev_y = s->last_pic.motion_val[0][mot_index][1]; prev_ref = s->last_pic.ref_index[0][4 * mb_xy]; } else { prev_x = s->cur_pic.motion_val[0][mot_index][0]; prev_y = s->cur_pic.motion_val[0][mot_index][1]; prev_ref = s->cur_pic.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: for (j = 0; j < pred_count; j++) { int *linesize = s->cur_pic.f->linesize; int score = 0; uint8_t *src = s->cur_pic.f->data[0] + mb_x * 16 + mb_y * 16 * linesize[0]; s->cur_pic.motion_val[0][mot_index][0] = s->mv[0][0][0] = mv_predictor[j][0]; s->cur_pic.motion_val[0][mot_index][1] = s->mv[0][0][1] = mv_predictor[j][1]; if (ref[j] < 0) continue; s->decode_mb(s->opaque, ref[j], MV_DIR_FORWARD, MV_TYPE_16X16, &s->mv, mb_x, mb_y, 0, 0); if (mb_x > 0 && fixed[mb_xy - 1]) { int k; for (k = 0; k < 16; k++) score += FFABS(src[k * linesize[0] - 1] - src[k * linesize[0]]); } if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) { int k; for (k = 0; k < 16; k++) score += FFABS(src[k * linesize[0] + 15] - src[k * linesize[0] + 16]); } if (mb_y > 0 && fixed[mb_xy - mb_stride]) { int k; for (k = 0; k < 16; k++) score += FFABS(src[k - linesize[0]] - 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 + linesize[0] * 15] - src[k + linesize[0] * 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->cur_pic.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0]; s->cur_pic.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1]; } s->decode_mb(s->opaque, ref[best_pred], MV_DIR_FORWARD, MV_TYPE_16X16, &s->mv, mb_x, mb_y, 0, 0); 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 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 const uint8_t *new_extradata;\n int new_extradata_size;\n h->flags = avctx->flags;\n h->setup_finished = 0;\n h->nb_slice_ctx_queued = 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 new_extradata_size = 0;\n new_extradata = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,\n &new_extradata_size);\n if (new_extradata_size > 0 && new_extradata) {\n ret = ff_h264_decode_extradata(new_extradata, new_extradata_size,\n &h->ps, &h->is_avc, &h->nal_length_size,\n avctx->err_recognition, avctx);\n if (ret < 0)\n return ret;\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 == H264_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 (h->field_started)\n ff_h264_field_end(h, &h->slice_ctx[0], 0);\n *got_frame = 0;\n if (h->output_frame->buf[0]) {\n ret = output_frame(h, pict, h->output_frame) ;\n av_frame_unref(h->output_frame);\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 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 if (h->is_avc && !(avctx->err_recognition & AV_EF_EXPLODE)) {\n int err = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, 0, 0,\n avctx->codec_id);\n if (err >= 0) {\n av_log(avctx, AV_LOG_WARNING,\n "The stream seems to contain AVCC extradata with Annex B "\n "formatted data, which is invalid.");\n h->is_avc = 0;\n ret = 0;\n }\n }\n if (ret < 0)\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 int max_slice_ctx, err;\n if (avctx->skip_frame >= AVDISCARD_NONREF &&\n nal->ref_idc == 0 && nal->type != H264_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 H264_NAL_IDR_SLICE:\n idr(h);\n case H264_NAL_SLICE:\n if ((err = ff_h264_queue_decode_slice(h, nal)))\n break;\n if (avctx->active_thread_type & FF_THREAD_FRAME &&\n i >= nals_needed && !h->setup_finished && h->cur_pic_ptr) {\n ff_thread_finish_setup(avctx);\n h->setup_finished = 1;\n }\n max_slice_ctx = avctx->hwaccel ? 1 : h->nb_slice_ctx;\n if (h->nb_slice_ctx_queued == max_slice_ctx) {\n if (avctx->hwaccel) {\n ret = avctx->hwaccel->decode_slice(avctx, nal->raw_data, nal->raw_size);\n h->nb_slice_ctx_queued = 0;\n } else\n ret = ff_h264_execute_decode_slices(h);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n }\n break;\n case H264_NAL_DPA:\n case H264_NAL_DPB:\n case H264_NAL_DPC:\n avpriv_request_sample(avctx, "data partitioning");\n ret = AVERROR(ENOSYS);\n goto end;\n break;\n case H264_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 H264_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 H264_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 H264_NAL_AUD:\n case H264_NAL_END_SEQUENCE:\n case H264_NAL_END_STREAM:\n case H264_NAL_FILLER_DATA:\n case H264_NAL_SPS_EXT:\n case H264_NAL_AUXILIARY_SLICE:\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 (err < 0) {\n av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\\n");\n }\n }\n ret = ff_h264_execute_decode_slices(h);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\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 const uint8_t *next_avc = buf + (is_nalff ? 0 : length);\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 (buf == next_avc) {\n int i;\n for (i = 0; i < nal_length_size; i++)\n extract_length = (extract_length << 8) | buf[i];\n if (extract_length > length) {\n av_log(logctx, AV_LOG_ERROR,\n "Invalid NAL unit size (%d > %d).\\n",\n extract_length, length);\n return AVERROR_INVALIDDATA;\n }\n buf += nal_length_size;\n length -= nal_length_size;\n next_avc = buf + extract_length;\n } else {\n int buf_index = find_next_start_code(buf, next_avc);\n buf += buf_index;\n length -= buf_index;\n if (buf == next_avc)\n continue;\n if (length > 0) {\n extract_length = length;\n } else if (pkt->nb_nals == 0) {\n av_log(logctx, AV_LOG_ERROR, "No NAL unit found\\n");\n return AVERROR_INVALIDDATA;\n } else {\n break;\n }\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_field_end(H264Context *h, H264SliceContext *sl, int in_setup)\n{\n AVCodecContext *const avctx = h->avctx;\n int err = 0;\n h->mb_y = 0;\n if (!in_setup && !h->droppable)\n ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n h->picture_structure == PICT_BOTTOM_FIELD);\n if (in_setup || !(avctx->active_thread_type & FF_THREAD_FRAME)) {\n if (!h->droppable) {\n err = ff_h264_execute_ref_pic_marking(h);\n h->poc.prev_poc_msb = h->poc.poc_msb;\n h->poc.prev_poc_lsb = h->poc.poc_lsb;\n }\n h->poc.prev_frame_num_offset = h->poc.frame_num_offset;\n h->poc.prev_frame_num = h->poc.frame_num;\n }\n if (avctx->hwaccel) {\n if (avctx->hwaccel->end_frame(avctx) < 0)\n av_log(avctx, AV_LOG_ERROR,\n "hardware accelerator failed to decode picture\\n");\n }\n#if CONFIG_ERROR_RESILIENCE\n if (!FIELD_PICTURE(h) && h->enable_er) {\n h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr);\n h264_set_erpic(&sl->er.last_pic,\n sl->ref_count[0] ? sl->ref_list[0][0].parent : NULL);\n h264_set_erpic(&sl->er.next_pic,\n sl->ref_count[1] ? sl->ref_list[1][0].parent : NULL);\n ff_er_frame_end(&sl->er);\n }\n#endif\n emms_c();\n h->current_slice = 0;\n h->field_started = 0;\n return err;\n}', 'void ff_er_frame_end(ERContext *s)\n{\n int *linesize = s->cur_pic.f->linesize;\n int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;\n int distance;\n int threshold_part[4] = { 100, 100, 100 };\n int threshold = 50;\n int is_intra_likely;\n if (!s->avctx->error_concealment || s->error_count == 0 ||\n s->avctx->hwaccel ||\n !s->cur_pic.f ||\n s->cur_pic.field_picture ||\n s->error_count == 3 * s->mb_width *\n (s->avctx->skip_top + s->avctx->skip_bottom)) {\n return;\n };\n if (!s->cur_pic.motion_val[0] || !s->cur_pic.ref_index[0]) {\n av_log(s->avctx, AV_LOG_ERROR, "MVs not available, ER not possible.\\n");\n return;\n }\n if (s->avctx->debug & FF_DEBUG_ER) {\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 int status = s->error_status_table[mb_x + mb_y * s->mb_stride];\n av_log(s->avctx, AV_LOG_DEBUG, "%2X ", status);\n }\n av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n }\n }\n for (error_type = 1; error_type <= 3; error_type++) {\n int end_ok = 0;\n for (i = s->mb_num - 1; i >= 0; i--) {\n const int mb_xy = s->mb_index2xy[i];\n int error = s->error_status_table[mb_xy];\n if (error & (1 << error_type))\n end_ok = 1;\n if (error & (8 << error_type))\n end_ok = 1;\n if (!end_ok)\n s->error_status_table[mb_xy] |= 1 << error_type;\n if (error & VP_START)\n end_ok = 0;\n }\n }\n if (s->partitioned_frame) {\n int end_ok = 0;\n for (i = s->mb_num - 1; i >= 0; i--) {\n const int mb_xy = s->mb_index2xy[i];\n int error = s->error_status_table[mb_xy];\n if (error & ER_AC_END)\n end_ok = 0;\n if ((error & ER_MV_END) ||\n (error & ER_DC_END) ||\n (error & ER_AC_ERROR))\n end_ok = 1;\n if (!end_ok)\n s->error_status_table[mb_xy]|= ER_AC_ERROR;\n if (error & VP_START)\n end_ok = 0;\n }\n }\n if (s->avctx->err_recognition & AV_EF_EXPLODE) {\n int end_ok = 1;\n for (i = s->mb_num - 2; i >= s->mb_width + 100; i--) {\n const int mb_xy = s->mb_index2xy[i];\n int error1 = s->error_status_table[mb_xy];\n int error2 = s->error_status_table[s->mb_index2xy[i + 1]];\n if (error1 & VP_START)\n end_ok = 1;\n if (error2 == (VP_START | ER_MB_ERROR | ER_MB_END) &&\n error1 != (VP_START | ER_MB_ERROR | ER_MB_END) &&\n ((error1 & ER_AC_END) || (error1 & ER_DC_END) ||\n (error1 & ER_MV_END))) {\n end_ok = 0;\n }\n if (!end_ok)\n s->error_status_table[mb_xy] |= ER_MB_ERROR;\n }\n }\n distance = 9999999;\n for (error_type = 1; error_type <= 3; error_type++) {\n for (i = s->mb_num - 1; i >= 0; i--) {\n const int mb_xy = s->mb_index2xy[i];\n int error = s->error_status_table[mb_xy];\n if (s->mbskip_table && !s->mbskip_table[mb_xy])\n distance++;\n if (error & (1 << error_type))\n distance = 0;\n if (s->partitioned_frame) {\n if (distance < threshold_part[error_type - 1])\n s->error_status_table[mb_xy] |= 1 << error_type;\n } else {\n if (distance < threshold)\n s->error_status_table[mb_xy] |= 1 << error_type;\n }\n if (error & VP_START)\n distance = 9999999;\n }\n }\n error = 0;\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n int old_error = s->error_status_table[mb_xy];\n if (old_error & VP_START) {\n error = old_error & ER_MB_ERROR;\n } else {\n error |= old_error & ER_MB_ERROR;\n s->error_status_table[mb_xy] |= error;\n }\n }\n if (!s->partitioned_frame) {\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n error = s->error_status_table[mb_xy];\n if (error & ER_MB_ERROR)\n error |= ER_MB_ERROR;\n s->error_status_table[mb_xy] = error;\n }\n }\n dc_error = ac_error = mv_error = 0;\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n error = s->error_status_table[mb_xy];\n if (error & ER_DC_ERROR)\n dc_error++;\n if (error & ER_AC_ERROR)\n ac_error++;\n if (error & ER_MV_ERROR)\n mv_error++;\n }\n av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\\n",\n dc_error, ac_error, mv_error);\n is_intra_likely = is_intra_more_likely(s);\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n error = s->error_status_table[mb_xy];\n if (!((error & ER_DC_ERROR) && (error & ER_MV_ERROR)))\n continue;\n if (is_intra_likely)\n s->cur_pic.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n else\n s->cur_pic.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0;\n }\n if (!(s->last_pic.f && s->last_pic.f->data[0]) &&\n !(s->next_pic.f && s->next_pic.f->data[0]))\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n if (!IS_INTRA(s->cur_pic.mb_type[mb_xy]))\n s->cur_pic.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n }\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 const int mb_type = s->cur_pic.mb_type[mb_xy];\n const int dir = !(s->last_pic.f && s->last_pic.f->data[0]);\n const int mv_dir = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD;\n int mv_type;\n error = s->error_status_table[mb_xy];\n if (IS_INTRA(mb_type))\n continue;\n if (error & ER_MV_ERROR)\n continue;\n if (!(error & ER_AC_ERROR))\n continue;\n if (IS_8X8(mb_type)) {\n int mb_index = mb_x * 2 + mb_y * 2 * s->b8_stride;\n int j;\n mv_type = MV_TYPE_8X8;\n for (j = 0; j < 4; j++) {\n s->mv[0][j][0] = s->cur_pic.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][0];\n s->mv[0][j][1] = s->cur_pic.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][1];\n }\n } else {\n mv_type = MV_TYPE_16X16;\n s->mv[0][0][0] = s->cur_pic.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][0];\n s->mv[0][0][1] = s->cur_pic.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][1];\n }\n s->decode_mb(s->opaque, 0 ,\n mv_dir, mv_type, &s->mv, mb_x, mb_y, 0, 0);\n }\n }\n if (s->cur_pic.f->pict_type == AV_PICTURE_TYPE_B) {\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 int xy = mb_x * 2 + mb_y * 2 * s->b8_stride;\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n const int mb_type = s->cur_pic.mb_type[mb_xy];\n int mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;\n error = s->error_status_table[mb_xy];\n if (IS_INTRA(mb_type))\n continue;\n if (!(error & ER_MV_ERROR))\n continue;\n if (!(error & ER_AC_ERROR))\n continue;\n if (!(s->last_pic.f && s->last_pic.f->data[0]))\n mv_dir &= ~MV_DIR_FORWARD;\n if (!(s->next_pic.f && s->next_pic.f->data[0]))\n mv_dir &= ~MV_DIR_BACKWARD;\n if (s->pp_time) {\n int time_pp = s->pp_time;\n int time_pb = s->pb_time;\n ff_thread_await_progress(s->next_pic.tf, mb_y, 0);\n s->mv[0][0][0] = s->next_pic.motion_val[0][xy][0] * time_pb / time_pp;\n s->mv[0][0][1] = s->next_pic.motion_val[0][xy][1] * time_pb / time_pp;\n s->mv[1][0][0] = s->next_pic.motion_val[0][xy][0] * (time_pb - time_pp) / time_pp;\n s->mv[1][0][1] = s->next_pic.motion_val[0][xy][1] * (time_pb - time_pp) / time_pp;\n } else {\n s->mv[0][0][0] = 0;\n s->mv[0][0][1] = 0;\n s->mv[1][0][0] = 0;\n s->mv[1][0][1] = 0;\n }\n s->decode_mb(s->opaque, 0, mv_dir, MV_TYPE_16X16, &s->mv,\n mb_x, mb_y, 0, 0);\n }\n }\n } else\n guess_mv(s);\n#if FF_API_XVMC\nFF_DISABLE_DEPRECATION_WARNINGS\n if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)\n goto ec_clean;\nFF_ENABLE_DEPRECATION_WARNINGS\n#endif\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 int dc, dcu, dcv, y, n;\n int16_t *dc_ptr;\n uint8_t *dest_y, *dest_cb, *dest_cr;\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n const int mb_type = s->cur_pic.mb_type[mb_xy];\n error = s->error_status_table[mb_xy];\n if (IS_INTRA(mb_type) && s->partitioned_frame)\n continue;\n dest_y = s->cur_pic.f->data[0] + mb_x * 16 + mb_y * 16 * linesize[0];\n dest_cb = s->cur_pic.f->data[1] + mb_x * 8 + mb_y * 8 * linesize[1];\n dest_cr = s->cur_pic.f->data[2] + mb_x * 8 + mb_y * 8 * linesize[2];\n dc_ptr = &s->dc_val[0][mb_x * 2 + mb_y * 2 * s->b8_stride];\n for (n = 0; n < 4; n++) {\n dc = 0;\n for (y = 0; y < 8; y++) {\n int x;\n for (x = 0; x < 8; x++)\n dc += dest_y[x + (n & 1) * 8 +\n (y + (n >> 1) * 8) * linesize[0]];\n }\n dc_ptr[(n & 1) + (n >> 1) * s->b8_stride] = (dc + 4) >> 3;\n }\n dcu = dcv = 0;\n for (y = 0; y < 8; y++) {\n int x;\n for (x = 0; x < 8; x++) {\n dcu += dest_cb[x + y * linesize[1]];\n dcv += dest_cr[x + y * linesize[2]];\n }\n }\n s->dc_val[1][mb_x + mb_y * s->mb_stride] = (dcu + 4) >> 3;\n s->dc_val[2][mb_x + mb_y * s->mb_stride] = (dcv + 4) >> 3;\n }\n }\n guess_dc(s, s->dc_val[0], s->mb_width * 2, s->mb_height * 2, s->b8_stride, 1);\n guess_dc(s, s->dc_val[1], s->mb_width, s->mb_height, s->mb_stride, 0);\n guess_dc(s, s->dc_val[2], s->mb_width, s->mb_height, s->mb_stride, 0);\n filter181(s->dc_val[0], s->mb_width * 2, s->mb_height * 2, s->b8_stride);\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 uint8_t *dest_y, *dest_cb, *dest_cr;\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n const int mb_type = s->cur_pic.mb_type[mb_xy];\n error = s->error_status_table[mb_xy];\n if (IS_INTER(mb_type))\n continue;\n if (!(error & ER_AC_ERROR))\n continue;\n dest_y = s->cur_pic.f->data[0] + mb_x * 16 + mb_y * 16 * linesize[0];\n dest_cb = s->cur_pic.f->data[1] + mb_x * 8 + mb_y * 8 * linesize[1];\n dest_cr = s->cur_pic.f->data[2] + mb_x * 8 + mb_y * 8 * linesize[2];\n put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);\n }\n }\n if (s->avctx->error_concealment & FF_EC_DEBLOCK) {\n h_block_filter(s, s->cur_pic.f->data[0], s->mb_width * 2,\n s->mb_height * 2, linesize[0], 1);\n h_block_filter(s, s->cur_pic.f->data[1], s->mb_width,\n s->mb_height, linesize[1], 0);\n h_block_filter(s, s->cur_pic.f->data[2], s->mb_width,\n s->mb_height, linesize[2], 0);\n v_block_filter(s, s->cur_pic.f->data[0], s->mb_width * 2,\n s->mb_height * 2, linesize[0], 1);\n v_block_filter(s, s->cur_pic.f->data[1], s->mb_width,\n s->mb_height, linesize[1], 0);\n v_block_filter(s, s->cur_pic.f->data[2], s->mb_width,\n s->mb_height, linesize[2], 0);\n }\n#if FF_API_XVMC\nec_clean:\n#endif\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n int error = s->error_status_table[mb_xy];\n if (s->mbskip_table && s->cur_pic.f->pict_type != AV_PICTURE_TYPE_B &&\n (error & (ER_DC_ERROR | ER_MV_ERROR | ER_AC_ERROR))) {\n s->mbskip_table[mb_xy] = 0;\n }\n if (s->mbintra_table)\n s->mbintra_table[mb_xy] = 1;\n }\n memset(&s->cur_pic, 0, sizeof(ERPicture));\n memset(&s->last_pic, 0, sizeof(ERPicture));\n memset(&s->next_pic, 0, sizeof(ERPicture));\n}', 'static void guess_mv(ERContext *s)\n{\n uint8_t *fixed = s->er_temp_buffer;\n#define MV_FROZEN 3\n#define MV_CHANGED 2\n#define MV_UNCHANGED 1\n const ptrdiff_t 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;\n ptrdiff_t 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->cur_pic.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 int mv_dir = (s->last_pic.f && s->last_pic.f->data[0]) ? MV_DIR_FORWARD : MV_DIR_BACKWARD;\n if (IS_INTRA(s->cur_pic.mb_type[mb_xy]))\n continue;\n if (!(s->error_status_table[mb_xy] & ER_MV_ERROR))\n continue;\n s->mv[0][0][0] = 0;\n s->mv[0][0][1] = 0;\n s->decode_mb(s->opaque, 0, mv_dir, MV_TYPE_16X16, &s->mv,\n mb_x, mb_y, 0, 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 = 0, prev_y = 0, prev_ref = 0;\n if ((mb_x ^ mb_y ^ pass) & 1)\n continue;\n if (fixed[mb_xy] == MV_FROZEN)\n continue;\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->cur_pic.motion_val[0][mot_index - mot_step][0];\n mv_predictor[pred_count][1] =\n s->cur_pic.motion_val[0][mot_index - mot_step][1];\n ref[pred_count] =\n s->cur_pic.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->cur_pic.motion_val[0][mot_index + mot_step][0];\n mv_predictor[pred_count][1] =\n s->cur_pic.motion_val[0][mot_index + mot_step][1];\n ref[pred_count] =\n s->cur_pic.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->cur_pic.motion_val[0][mot_index - mot_stride * mot_step][0];\n mv_predictor[pred_count][1] =\n s->cur_pic.motion_val[0][mot_index - mot_stride * mot_step][1];\n ref[pred_count] =\n s->cur_pic.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->cur_pic.motion_val[0][mot_index + mot_stride * mot_step][0];\n mv_predictor[pred_count][1] =\n s->cur_pic.motion_val[0][mot_index + mot_stride * mot_step][1];\n ref[pred_count] =\n s->cur_pic.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 == AV_CODEC_ID_H264) {\n } else {\n ff_thread_await_progress(s->last_pic.tf,\n mb_y, 0);\n }\n if (!s->last_pic.motion_val[0] ||\n !s->last_pic.ref_index[0])\n goto skip_last_mv;\n prev_x = s->last_pic.motion_val[0][mot_index][0];\n prev_y = s->last_pic.motion_val[0][mot_index][1];\n prev_ref = s->last_pic.ref_index[0][4 * mb_xy];\n } else {\n prev_x = s->cur_pic.motion_val[0][mot_index][0];\n prev_y = s->cur_pic.motion_val[0][mot_index][1];\n prev_ref = s->cur_pic.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 for (j = 0; j < pred_count; j++) {\n int *linesize = s->cur_pic.f->linesize;\n int score = 0;\n uint8_t *src = s->cur_pic.f->data[0] +\n mb_x * 16 + mb_y * 16 * linesize[0];\n s->cur_pic.motion_val[0][mot_index][0] =\n s->mv[0][0][0] = mv_predictor[j][0];\n s->cur_pic.motion_val[0][mot_index][1] =\n s->mv[0][0][1] = mv_predictor[j][1];\n if (ref[j] < 0)\n continue;\n s->decode_mb(s->opaque, ref[j], MV_DIR_FORWARD,\n MV_TYPE_16X16, &s->mv, mb_x, mb_y, 0, 0);\n if (mb_x > 0 && fixed[mb_xy - 1]) {\n int k;\n for (k = 0; k < 16; k++)\n score += FFABS(src[k * linesize[0] - 1] -\n src[k * linesize[0]]);\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 * linesize[0] + 15] -\n src[k * linesize[0] + 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 - linesize[0]] - 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 + linesize[0] * 15] -\n src[k + linesize[0] * 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->cur_pic.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0];\n s->cur_pic.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1];\n }\n s->decode_mb(s->opaque, ref[best_pred], MV_DIR_FORWARD,\n MV_TYPE_16X16, &s->mv, mb_x, mb_y, 0, 0);\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}']
36,594
0
https://github.com/libav/libav/blob/77b0443544fd5f5c3f974b7a4fa4f2f18f7ba8df/libavformat/dv.c/#L121
static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4], const DVprofile *sys) { int size, chan, i, j, d, of, smpls, freq, quant, half_ch; uint16_t lc, rc; const uint8_t* as_pack; uint8_t *pcm, ipcm; as_pack = dv_extract_pack(frame, dv_audio_source); if (!as_pack) return 0; smpls = as_pack[1] & 0x3f; freq = (as_pack[4] >> 3) & 0x07; quant = as_pack[4] & 0x07; if (quant > 1) return -1; size = (sys->audio_min_samples[freq] + smpls) * 4; half_ch = sys->difseg_size/2; ipcm = (sys->height == 720 && ((frame[1]>>2)&0x3) == 0)?2:0; pcm = ppcm[ipcm++]; for (chan = 0; chan < sys->n_difchan; chan++) { for (i = 0; i < sys->difseg_size; i++) { frame += 6 * 80; if (quant == 1 && i == half_ch) { pcm = ppcm[ipcm++]; if (!pcm) break; } for (j = 0; j < 9; j++) { for (d = 8; d < 80; d += 2) { if (quant == 0) { of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride; if (of*2 >= size) continue; pcm[of*2] = frame[d+1]; pcm[of*2+1] = frame[d]; if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00) pcm[of*2+1] = 0; } else { lc = ((uint16_t)frame[d] << 4) | ((uint16_t)frame[d+2] >> 4); rc = ((uint16_t)frame[d+1] << 4) | ((uint16_t)frame[d+2] & 0x0f); lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc)); rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc)); of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride; if (of*2 >= size) continue; pcm[of*2] = lc & 0xff; pcm[of*2+1] = lc >> 8; of = sys->audio_shuffle[i%half_ch+half_ch][j] + (d - 8)/3 * sys->audio_stride; pcm[of*2] = rc & 0xff; pcm[of*2+1] = rc >> 8; ++d; } } frame += 16 * 80; } } pcm = ppcm[ipcm++]; if (!pcm) break; } return size; }
['static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt)\n{\n struct dv1394_data *dv = context->priv_data;\n int size;\n size = dv_get_packet(dv->dv_demux, pkt);\n if (size > 0)\n return size;\n if (!dv->avail) {\n struct dv1394_status s;\n struct pollfd p;\n if (dv->done) {\n if (ioctl(dv->fd, DV1394_RECEIVE_FRAMES, dv->done) < 0) {\n av_log(context, AV_LOG_ERROR, "DV1394: Ring buffer overflow. Reseting ..\\n");\n dv1394_reset(dv);\n dv1394_start(dv);\n }\n dv->done = 0;\n }\nrestart_poll:\n p.fd = dv->fd;\n p.events = POLLIN | POLLERR | POLLHUP;\n if (poll(&p, 1, -1) < 0) {\n if (errno == EAGAIN || errno == EINTR)\n goto restart_poll;\n av_log(context, AV_LOG_ERROR, "Poll failed: %s\\n", strerror(errno));\n return AVERROR(EIO);\n }\n if (ioctl(dv->fd, DV1394_GET_STATUS, &s) < 0) {\n av_log(context, AV_LOG_ERROR, "Failed to get status: %s\\n", strerror(errno));\n return AVERROR(EIO);\n }\n#ifdef DV1394_DEBUG\n av_log(context, AV_LOG_DEBUG, "DV1394: status\\n"\n "\\tactive_frame\\t%d\\n"\n "\\tfirst_clear_frame\\t%d\\n"\n "\\tn_clear_frames\\t%d\\n"\n "\\tdropped_frames\\t%d\\n",\n s.active_frame, s.first_clear_frame,\n s.n_clear_frames, s.dropped_frames);\n#endif\n dv->avail = s.n_clear_frames;\n dv->index = s.first_clear_frame;\n dv->done = 0;\n if (s.dropped_frames) {\n av_log(context, AV_LOG_ERROR, "DV1394: Frame drop detected (%d). Reseting ..\\n",\n s.dropped_frames);\n dv1394_reset(dv);\n dv1394_start(dv);\n }\n }\n#ifdef DV1394_DEBUG\n av_log(context, AV_LOG_DEBUG, "index %d, avail %d, done %d\\n", dv->index, dv->avail,\n dv->done);\n#endif\n size = dv_produce_packet(dv->dv_demux, pkt,\n dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE),\n DV1394_PAL_FRAME_SIZE);\n dv->index = (dv->index + 1) % DV1394_RING_FRAMES;\n dv->done++; dv->avail--;\n return size;\n}', 'int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,\n uint8_t* buf, int buf_size)\n{\n int size, i;\n uint8_t *ppcm[4] = {0};\n if (buf_size < DV_PROFILE_BYTES ||\n !(c->sys = dv_frame_profile(buf)) ||\n buf_size < c->sys->frame_size) {\n return -1;\n }\n size = dv_extract_audio_info(c, buf);\n for (i=0; i<c->ach; i++) {\n c->audio_pkt[i].size = size;\n c->audio_pkt[i].pts = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate;\n ppcm[i] = c->audio_buf[i];\n }\n dv_extract_audio(buf, ppcm, c->sys);\n c->abytes += size;\n if (c->sys->height == 720) {\n if (((buf[1]>>2)&0x3))\n c->audio_pkt[2].size = c->audio_pkt[3].size = 0;\n else\n c->audio_pkt[0].size = c->audio_pkt[1].size = 0;\n }\n size = dv_extract_video_info(c, buf);\n av_init_packet(pkt);\n pkt->data = buf;\n pkt->size = size;\n pkt->flags |= PKT_FLAG_KEY;\n pkt->stream_index = c->vst->id;\n pkt->pts = c->frames;\n c->frames++;\n return size;\n}', 'static inline const DVprofile* dv_frame_profile(const uint8_t* frame)\n{\n int i;\n int dsf = (frame[3] & 0x80) >> 7;\n int stype = frame[80*5 + 48 + 3] & 0x1f;\n if (dsf == 1 && stype == 0 && frame[5] & 0x07) {\n return &dv_profiles[2];\n }\n for (i=0; i<sizeof(dv_profiles)/sizeof(DVprofile); i++)\n if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)\n return &dv_profiles[i];\n return NULL;\n}', 'static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)\n{\n const uint8_t* as_pack;\n int freq, stype, smpls, quant, i, ach;\n as_pack = dv_extract_pack(frame, dv_audio_source);\n if (!as_pack || !c->sys) {\n c->ach = 0;\n return 0;\n }\n smpls = as_pack[1] & 0x3f;\n freq = (as_pack[4] >> 3) & 0x07;\n stype = (as_pack[3] & 0x1f);\n quant = as_pack[4] & 0x07;\n if (stype == 3) {\n ach = 4;\n } else\n ach = (stype == 2 || (quant && (freq == 2))) ? 2 : 1;\n for (i=0; i<ach; i++) {\n if (!c->ast[i]) {\n c->ast[i] = av_new_stream(c->fctx, 0);\n if (!c->ast[i])\n break;\n av_set_pts_info(c->ast[i], 64, 1, 30000);\n c->ast[i]->codec->codec_type = CODEC_TYPE_AUDIO;\n c->ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;\n av_init_packet(&c->audio_pkt[i]);\n c->audio_pkt[i].size = 0;\n c->audio_pkt[i].data = c->audio_buf[i];\n c->audio_pkt[i].stream_index = c->ast[i]->index;\n c->audio_pkt[i].flags |= PKT_FLAG_KEY;\n }\n c->ast[i]->codec->sample_rate = dv_audio_frequency[freq];\n c->ast[i]->codec->channels = 2;\n c->ast[i]->codec->bit_rate = 2 * dv_audio_frequency[freq] * 16;\n c->ast[i]->start_time = 0;\n }\n c->ach = i;\n return (c->sys->audio_min_samples[freq] + smpls) * 4; ;\n}', 'static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)\n{\n int offs;\n switch (t) {\n case dv_audio_source:\n offs = (80*6 + 80*16*3 + 3);\n break;\n case dv_audio_control:\n offs = (80*6 + 80*16*4 + 3);\n break;\n case dv_video_control:\n offs = (80*5 + 48 + 5);\n break;\n default:\n return NULL;\n }\n return frame[offs] == t ? &frame[offs] : NULL;\n}', 'static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],\n const DVprofile *sys)\n{\n int size, chan, i, j, d, of, smpls, freq, quant, half_ch;\n uint16_t lc, rc;\n const uint8_t* as_pack;\n uint8_t *pcm, ipcm;\n as_pack = dv_extract_pack(frame, dv_audio_source);\n if (!as_pack)\n return 0;\n smpls = as_pack[1] & 0x3f;\n freq = (as_pack[4] >> 3) & 0x07;\n quant = as_pack[4] & 0x07;\n if (quant > 1)\n return -1;\n size = (sys->audio_min_samples[freq] + smpls) * 4;\n half_ch = sys->difseg_size/2;\n ipcm = (sys->height == 720 && ((frame[1]>>2)&0x3) == 0)?2:0;\n pcm = ppcm[ipcm++];\n for (chan = 0; chan < sys->n_difchan; chan++) {\n for (i = 0; i < sys->difseg_size; i++) {\n frame += 6 * 80;\n if (quant == 1 && i == half_ch) {\n pcm = ppcm[ipcm++];\n if (!pcm)\n break;\n }\n for (j = 0; j < 9; j++) {\n for (d = 8; d < 80; d += 2) {\n if (quant == 0) {\n of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride;\n if (of*2 >= size)\n continue;\n pcm[of*2] = frame[d+1];\n pcm[of*2+1] = frame[d];\n if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)\n pcm[of*2+1] = 0;\n } else {\n lc = ((uint16_t)frame[d] << 4) |\n ((uint16_t)frame[d+2] >> 4);\n rc = ((uint16_t)frame[d+1] << 4) |\n ((uint16_t)frame[d+2] & 0x0f);\n lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));\n rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));\n of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride;\n if (of*2 >= size)\n continue;\n pcm[of*2] = lc & 0xff;\n pcm[of*2+1] = lc >> 8;\n of = sys->audio_shuffle[i%half_ch+half_ch][j] +\n (d - 8)/3 * sys->audio_stride;\n pcm[of*2] = rc & 0xff;\n pcm[of*2+1] = rc >> 8;\n ++d;\n }\n }\n frame += 16 * 80;\n }\n }\n pcm = ppcm[ipcm++];\n if (!pcm)\n break;\n }\n return size;\n}']
36,595
0
https://github.com/openssl/openssl/blob/8580f8015fa2f56da854ece033f9d1894bcc3ede/crypto/bn/bn_asm.c/#L405
BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n) { BN_ULONG t1,t2; int c=0; assert(n >= 0); if (n <= 0) return((BN_ULONG)0); #ifndef OPENSSL_SMALL_FOOTPRINT while (n&~3) { t1=a[0]; t2=b[0]; r[0]=(t1-t2-c)&BN_MASK2; if (t1 != t2) c=(t1 < t2); t1=a[1]; t2=b[1]; r[1]=(t1-t2-c)&BN_MASK2; if (t1 != t2) c=(t1 < t2); t1=a[2]; t2=b[2]; r[2]=(t1-t2-c)&BN_MASK2; if (t1 != t2) c=(t1 < t2); t1=a[3]; t2=b[3]; r[3]=(t1-t2-c)&BN_MASK2; if (t1 != t2) c=(t1 < t2); a+=4; b+=4; r+=4; n-=4; } #endif while (n) { t1=a[0]; t2=b[0]; r[0]=(t1-t2-c)&BN_MASK2; if (t1 != t2) c=(t1 < t2); a++; b++; r++; n--; } return(c); }
['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n\tconst BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n\tBN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,b,bits1,bits2,ret=0,wpos1,wpos2,window1,window2,wvalue1,wvalue2;\n\tint r_is_one=1;\n\tBIGNUM *d,*r;\n\tconst BIGNUM *a_mod_m;\n\tBIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a1);\n\tbn_check_top(p1);\n\tbn_check_top(a2);\n\tbn_check_top(p2);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP2_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits1=BN_num_bits(p1);\n\tbits2=BN_num_bits(p2);\n\tif ((bits1 == 0) && (bits2 == 0))\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tbits=(bits1 > bits2)?bits1:bits2;\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tval1[0] = BN_CTX_get(ctx);\n\tval2[0] = BN_CTX_get(ctx);\n\tif(!d || !r || !val1[0] || !val2[0]) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\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\twindow1 = BN_window_bits_for_exponent_size(bits1);\n\twindow2 = BN_window_bits_for_exponent_size(bits2);\n\tif (a1->neg || BN_ucmp(a1,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(val1[0],a1,m,ctx))\n\t\t\tgoto err;\n\t\ta_mod_m = val1[0];\n\t\t}\n\telse\n\t\ta_mod_m = a1;\n\tif (BN_is_zero(a_mod_m))\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(val1[0],a_mod_m,mont,ctx)) goto err;\n\tif (window1 > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,val1[0],val1[0],mont,ctx)) goto err;\n\t\tj=1<<(window1-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_montgomery(val1[i],val1[i-1],\n\t\t\t\t\t\td,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (a2->neg || BN_ucmp(a2,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(val2[0],a2,m,ctx))\n\t\t\tgoto err;\n\t\ta_mod_m = val2[0];\n\t\t}\n\telse\n\t\ta_mod_m = a2;\n\tif (BN_is_zero(a_mod_m))\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(val2[0],a_mod_m,mont,ctx)) goto err;\n\tif (window2 > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,val2[0],val2[0],mont,ctx)) goto err;\n\t\tj=1<<(window2-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_montgomery(val2[i],val2[i-1],\n\t\t\t\t\t\td,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tr_is_one=1;\n\twvalue1=0;\n\twvalue2=0;\n\twpos1=0;\n\twpos2=0;\n\tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (b=bits-1; b>=0; b--)\n\t\t{\n\t\tif (!r_is_one)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tif (!wvalue1)\n\t\t\tif (BN_is_bit_set(p1, b))\n\t\t\t\t{\n\t\t\t\ti = b-window1+1;\n\t\t\t\twhile (!BN_is_bit_set(p1, i))\n\t\t\t\t\ti++;\n\t\t\t\twpos1 = i;\n\t\t\t\twvalue1 = 1;\n\t\t\t\tfor (i = b-1; i >= wpos1; i--)\n\t\t\t\t\t{\n\t\t\t\t\twvalue1 <<= 1;\n\t\t\t\t\tif (BN_is_bit_set(p1, i))\n\t\t\t\t\t\twvalue1++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\tif (!wvalue2)\n\t\t\tif (BN_is_bit_set(p2, b))\n\t\t\t\t{\n\t\t\t\ti = b-window2+1;\n\t\t\t\twhile (!BN_is_bit_set(p2, i))\n\t\t\t\t\ti++;\n\t\t\t\twpos2 = i;\n\t\t\t\twvalue2 = 1;\n\t\t\t\tfor (i = b-1; i >= wpos2; i--)\n\t\t\t\t\t{\n\t\t\t\t\twvalue2 <<= 1;\n\t\t\t\t\tif (BN_is_bit_set(p2, i))\n\t\t\t\t\t\twvalue2++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\tif (wvalue1 && b == wpos1)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,val1[wvalue1>>1],mont,ctx))\n\t\t\t\tgoto err;\n\t\t\twvalue1 = 0;\n\t\t\tr_is_one = 0;\n\t\t\t}\n\t\tif (wvalue2 && b == wpos2)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,val2[wvalue2>>1],mont,ctx))\n\t\t\t\tgoto err;\n\t\t\twvalue2 = 0;\n\t\t\tr_is_one = 0;\n\t\t\t}\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\tBN_CTX_end(ctx);\n\tbn_check_top(rr);\n\treturn(ret);\n\t}', 'const BIGNUM *BN_value_one(void)\n\t{\n\tstatic const BN_ULONG data_one=1L;\n\tstatic const BIGNUM const_one={(BN_ULONG *)&data_one,1,1,0,BN_FLG_STATIC_DATA};\n\treturn(&const_one);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n\t\t\t BN_MONT_CTX *mont, BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp;\n\tint ret=0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n\tint num = mont->N.top;\n\tif (num>1 && a->top==num && b->top==num)\n\t\t{\n\t\tif (bn_wexpand(r,num) == NULL) return(0);\n\t\tif (bn_mul_mont(r->d,a->d,b->d,mont->N.d,mont->n0,num))\n\t\t\t{\n\t\t\tr->neg = a->neg^b->neg;\n\t\t\tr->top = num;\n\t\t\tbn_correct_top(r);\n\t\t\treturn(1);\n\t\t\t}\n\t\t}\n#endif\n\tBN_CTX_start(ctx);\n\ttmp = BN_CTX_get(ctx);\n\tif (tmp == NULL) goto err;\n\tbn_check_top(tmp);\n\tif (a == b)\n\t\t{\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n#ifdef MONT_WORD\n\tif (!BN_from_montgomery_word(r,tmp,mont)) goto err;\n#else\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n#endif\n\tbn_check_top(r);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tint top,al,bl;\n\tBIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tint i;\n#endif\n#ifdef BN_RECURSION\n\tBIGNUM *t=NULL;\n\tint j=0,k;\n#endif\n#ifdef BN_COUNT\n\tfprintf(stderr,"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\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\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == b))\n\t\t{\n\t\tif ((rr = BN_CTX_get(ctx)) == NULL) goto err;\n\t\t}\n\telse\n\t\trr = r;\n\trr->neg=a->neg^b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\ti = al-bl;\n#endif\n#ifdef BN_MUL_COMBA\n\tif (i == 0)\n\t\t{\n# if 0\n\t\tif (al == 4)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,8) == NULL) goto err;\n\t\t\trr->top=8;\n\t\t\tbn_mul_comba4(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n# endif\n\t\tif (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) goto err;\n\t\t\trr->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\t}\n#endif\n#ifdef BN_RECURSION\n\tif ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (i >= -1 && i <= 1)\n\t\t\t{\n\t\t\tint sav_j =0;\n\t\t\tif (i >= 0)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)al);\n\t\t\t\t}\n\t\t\tif (i == -1)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)bl);\n\t\t\t\t}\n\t\t\tsav_j = j;\n\t\t\tj = 1<<(j-1);\n\t\t\tassert(j <= al || j <= bl);\n\t\t\tk = j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (t == NULL)\n\t\t\t\tgoto err;\n\t\t\tif (al > j || bl > j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)b;\n\t\t\tif (bn_wexpand(tmp_bn,al) == NULL) goto err;\n\t\t\ttmp_bn->d[bl]=0;\n\t\t\tbl++;\n\t\t\ti--;\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\tBIGNUM *tmp_bn = (BIGNUM *)a;\n\t\t\tif (bn_wexpand(tmp_bn,bl) == NULL) goto err;\n\t\t\ttmp_bn->d[al]=0;\n\t\t\tal++;\n\t\t\ti++;\n\t\t\t}\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#endif\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) goto err;\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_correct_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\tret=1;\nerr:\n\tbn_check_top(r);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n\t int tna, int tnb, BN_ULONG *t)\n\t{\n\tint i,j,n2=n*2;\n\tint c1,c2,neg,zero;\n\tBN_ULONG ln,lo,*p;\n# ifdef BN_COUNT\n\tfprintf(stderr," bn_mul_part_recursive (%d%+d) * (%d%+d)\\n",\n\t\tn, tna, n, tnb);\n# endif\n\tif (n < 8)\n\t\t{\n\t\tbn_mul_normal(r,a,n+tna,b,n+tnb);\n\t\treturn;\n\t\t}\n\tc1=bn_cmp_part_words(a,&(a[n]),tna,n-tna);\n\tc2=bn_cmp_part_words(&(b[n]),b,tnb,tnb-n);\n\tzero=neg=0;\n\tswitch (c1*3+c2)\n\t\t{\n\tcase -4:\n\t\tbn_sub_part_words(t, &(a[n]),a, tna,tna-n);\n\t\tbn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb);\n\t\tbreak;\n\tcase -3:\n\t\tzero=1;\n\tcase -2:\n\t\tbn_sub_part_words(t, &(a[n]),a, tna,tna-n);\n\t\tbn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n);\n\t\tneg=1;\n\t\tbreak;\n\tcase -1:\n\tcase 0:\n\tcase 1:\n\t\tzero=1;\n\tcase 2:\n\t\tbn_sub_part_words(t, a, &(a[n]),tna,n-tna);\n\t\tbn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb);\n\t\tneg=1;\n\t\tbreak;\n\tcase 3:\n\t\tzero=1;\n\tcase 4:\n\t\tbn_sub_part_words(t, a, &(a[n]),tna,n-tna);\n\t\tbn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n);\n\t\tbreak;\n\t\t}\n# if 0\n\tif (n == 4)\n\t\t{\n\t\tbn_mul_comba4(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba4(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# endif\n\tif (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]),tna,&(b[n]),tnb);\n\t\tmemset(&(r[n2+tna+tnb]),0,sizeof(BN_ULONG)*(n2-tna-tnb));\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,0,0,p);\n\t\tbn_mul_recursive(r,a,b,n,0,0,p);\n\t\ti=n/2;\n\t\tif (tna > tnb)\n\t\t\tj = tna - i;\n\t\telse\n\t\t\tj = tnb - i;\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\ti,tna-i,tnb-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\ti,tna-i,tnb-i,p);\n\t\t\t\tmemset(&(r[n2+tna+tnb]),0,\n\t\t\t\t\tsizeof(BN_ULONG)*(n2-tna-tnb));\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 (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n\t\t\t\t&& tnb < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t\t\t{\n\t\t\t\tbn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb);\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 < tna || i < tnb)\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\ti,tna-i,tnb-i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (i == tna || i == tnb)\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,tna-i,tnb-i,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\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_part_words(const BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tint n,i;\n\tn = cl-1;\n\tif (dl < 0)\n\t\t{\n\t\tfor (i=dl; i<0; i++)\n\t\t\t{\n\t\t\tif (b[n-i] != 0)\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\tif (dl > 0)\n\t\t{\n\t\tfor (i=dl; i>0; i--)\n\t\t\t{\n\t\t\tif (a[n+i] != 0)\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\treturn bn_cmp_words(a,b,cl);\n\t}', 'BN_ULONG bn_sub_part_words(BN_ULONG *r,\n\tconst BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tBN_ULONG c, t;\n\tassert(cl >= 0);\n\tc = bn_sub_words(r, a, b, cl);\n\tif (dl == 0)\n\t\treturn c;\n\tr += cl;\n\ta += cl;\n\tb += cl;\n\tif (dl < 0)\n\t\t{\n#ifdef BN_COUNT\n\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl < 0, c = %d)\\n", cl, dl, c);\n#endif\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt = b[0];\n\t\t\tr[0] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[1];\n\t\t\tr[1] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[2];\n\t\t\tr[2] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[3];\n\t\t\tr[3] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tb += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tint save_dl = dl;\n#ifdef BN_COUNT\n\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c = %d)\\n", cl, dl, c);\n#endif\n\t\twhile(c)\n\t\t\t{\n\t\t\tt = a[0];\n\t\t\tr[0] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[1];\n\t\t\tr[1] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[2];\n\t\t\tr[2] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[3];\n\t\t\tr[3] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tsave_dl = dl;\n\t\t\ta += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n#ifdef BN_COUNT\n\t\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c == 0)\\n", cl, dl);\n#endif\n\t\t\tif (save_dl > dl)\n\t\t\t\t{\n\t\t\t\tswitch (save_dl - dl)\n\t\t\t\t\t{\n\t\t\t\tcase 1:\n\t\t\t\t\tr[1] = a[1];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 2:\n\t\t\t\t\tr[2] = a[2];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 3:\n\t\t\t\t\tr[3] = a[3];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\t\t}\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n#ifdef BN_COUNT\n\t\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, copy)\\n", cl, dl);\n#endif\n\t\t\tfor(;;)\n\t\t\t\t{\n\t\t\t\tr[0] = a[0];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[1] = a[1];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[2] = a[2];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[3] = a[3];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\treturn c;\n\t}', 'BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)\n {\n\tBN_ULONG t1,t2;\n\tint c=0;\n\tassert(n >= 0);\n\tif (n <= 0) return((BN_ULONG)0);\n#ifndef OPENSSL_SMALL_FOOTPRINT\n\twhile (n&~3)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[1]; t2=b[1];\n\t\tr[1]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[2]; t2=b[2];\n\t\tr[2]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[3]; t2=b[3];\n\t\tr[3]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\ta+=4; b+=4; r+=4; n-=4;\n\t\t}\n#endif\n\twhile (n)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\ta++; b++; r++; n--;\n\t\t}\n\treturn(c);\n\t}']
36,596
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/ec/ec_kmeth.c/#L130
EC_KEY *EC_KEY_new_method(ENGINE *engine) { EC_KEY *ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) { ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_MALLOC_FAILURE); return (NULL); } ret->meth = EC_KEY_get_default_method(); #ifndef OPENSSL_NO_ENGINE if (engine != NULL) { if (!ENGINE_init(engine)) { ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB); OPENSSL_free(ret); return NULL; } ret->engine = engine; } else ret->engine = ENGINE_get_default_EC(); if (ret->engine != NULL) { ret->meth = ENGINE_get_EC(ret->engine); if (ret->meth == NULL) { ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB); ENGINE_finish(ret->engine); OPENSSL_free(ret); return NULL; } } #endif ret->version = 1; ret->conv_form = POINT_CONVERSION_UNCOMPRESSED; ret->references = 1; if (ret->meth->init != NULL && ret->meth->init(ret) == 0) { EC_KEY_free(ret); return NULL; } return ret; }
['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->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 OPENSSL_free(ret);\n return NULL;\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 ENGINE_finish(ret->engine);\n OPENSSL_free(ret);\n return NULL;\n }\n }\n#endif\n ret->version = 1;\n ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;\n ret->references = 1;\n if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {\n EC_KEY_free(ret);\n return NULL;\n }\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#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}', 'const EC_KEY_METHOD *EC_KEY_get_default_method(void)\n{\n return default_ec_key_meth;\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 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);\n ret = engine_unlocked_init(e);\n CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);\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}', 'int engine_unlocked_init(ENGINE *e)\n{\n int to_return = 1;\n if ((e->funct_ref == 0) && e->init)\n to_return = e->init(e);\n if (to_return) {\n e->struct_ref++;\n e->funct_ref++;\n engine_ref_debug(e, 0, 1)\n engine_ref_debug(e, 1, 1)\n }\n return to_return;\n}', 'const EC_KEY_METHOD *ENGINE_get_EC(const ENGINE *e)\n{\n return e->ec_meth;\n}']
36,597
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/des/des_enc.c/#L144
void des_encrypt(DES_LONG *data, des_key_schedule ks, int enc) { register DES_LONG l,r,t,u; #ifdef DES_PTR register const unsigned char *des_SP=(const unsigned char *)des_SPtrans; #endif #ifndef DES_UNROLL register int i; #endif register DES_LONG *s; r=data[0]; l=data[1]; IP(r,l); r=ROTATE(r,29)&0xffffffffL; l=ROTATE(l,29)&0xffffffffL; s=(DES_LONG *)ks; if (enc) { #ifdef DES_UNROLL D_ENCRYPT(l,r, 0); D_ENCRYPT(r,l, 2); D_ENCRYPT(l,r, 4); D_ENCRYPT(r,l, 6); D_ENCRYPT(l,r, 8); D_ENCRYPT(r,l,10); D_ENCRYPT(l,r,12); D_ENCRYPT(r,l,14); D_ENCRYPT(l,r,16); D_ENCRYPT(r,l,18); D_ENCRYPT(l,r,20); D_ENCRYPT(r,l,22); D_ENCRYPT(l,r,24); D_ENCRYPT(r,l,26); D_ENCRYPT(l,r,28); D_ENCRYPT(r,l,30); #else for (i=0; i<32; i+=8) { D_ENCRYPT(l,r,i+0); D_ENCRYPT(r,l,i+2); D_ENCRYPT(l,r,i+4); D_ENCRYPT(r,l,i+6); } #endif } else { #ifdef DES_UNROLL D_ENCRYPT(l,r,30); D_ENCRYPT(r,l,28); D_ENCRYPT(l,r,26); D_ENCRYPT(r,l,24); D_ENCRYPT(l,r,22); D_ENCRYPT(r,l,20); D_ENCRYPT(l,r,18); D_ENCRYPT(r,l,16); D_ENCRYPT(l,r,14); D_ENCRYPT(r,l,12); D_ENCRYPT(l,r,10); D_ENCRYPT(r,l, 8); D_ENCRYPT(l,r, 6); D_ENCRYPT(r,l, 4); D_ENCRYPT(l,r, 2); D_ENCRYPT(r,l, 0); #else for (i=30; i>0; i-=8) { D_ENCRYPT(l,r,i-0); D_ENCRYPT(r,l,i-2); D_ENCRYPT(l,r,i-4); D_ENCRYPT(r,l,i-6); } #endif } l=ROTATE(l,3)&0xffffffffL; r=ROTATE(r,3)&0xffffffffL; FP(r,l); data[0]=l; data[1]=r; l=r=t=u=0; }
['int _des_crypt(char *buf, int len, struct desparams *desp)\n\t{\n\tdes_key_schedule ks;\n\tint enc;\n\tdes_set_key(desp->des_key,ks);\n\tenc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;\n\tif (desp->des_mode == CBC)\n\t\tdes_ecb_encrypt(desp->UDES.UDES_buf,desp->UDES.UDES_buf,ks,\n\t\t\t\tenc);\n\telse\n\t\t{\n\t\tdes_ncbc_encrypt(desp->UDES.UDES_buf,desp->UDES.UDES_buf,\n\t\t\t\tlen,ks,desp->des_ivec,enc);\n#ifdef undef\n\t\ta=(char *)&(desp->UDES.UDES_buf[len-8]);\n\t\tb=(char *)&(desp->des_ivec[0]);\n\t\t*(a++)= *(b++); *(a++)= *(b++);\n\t\t*(a++)= *(b++); *(a++)= *(b++);\n\t\t*(a++)= *(b++); *(a++)= *(b++);\n\t\t*(a++)= *(b++); *(a++)= *(b++);\n#endif\n\t\t}\n\treturn(1);\n\t}', 'void des_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,\n\t des_key_schedule schedule, des_cblock ivec, int enc)\n\t{\n\tregister DES_LONG tin0,tin1;\n\tregister DES_LONG tout0,tout1,xor0,xor1;\n\tregister long l=length;\n\tDES_LONG tin[2];\n\tunsigned char *iv;\n\tiv=ivec;\n\tif (enc)\n\t\t{\n\t\tc2l(iv,tout0);\n\t\tc2l(iv,tout1);\n\t\tfor (l-=8; l>=0; l-=8)\n\t\t\t{\n\t\t\tc2l(in,tin0);\n\t\t\tc2l(in,tin1);\n\t\t\ttin0^=tout0; tin[0]=tin0;\n\t\t\ttin1^=tout1; tin[1]=tin1;\n\t\t\tdes_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);\n\t\t\ttout0=tin[0]; l2c(tout0,out);\n\t\t\ttout1=tin[1]; l2c(tout1,out);\n\t\t\t}\n\t\tif (l != -8)\n\t\t\t{\n\t\t\tc2ln(in,tin0,tin1,l+8);\n\t\t\ttin0^=tout0; tin[0]=tin0;\n\t\t\ttin1^=tout1; tin[1]=tin1;\n\t\t\tdes_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);\n\t\t\ttout0=tin[0]; l2c(tout0,out);\n\t\t\ttout1=tin[1]; l2c(tout1,out);\n\t\t\t}\n\t\tiv=ivec;\n\t\tl2c(tout0,iv);\n\t\tl2c(tout1,iv);\n\t\t}\n\telse\n\t\t{\n\t\tc2l(iv,xor0);\n\t\tc2l(iv,xor1);\n\t\tfor (l-=8; l>=0; l-=8)\n\t\t\t{\n\t\t\tc2l(in,tin0); tin[0]=tin0;\n\t\t\tc2l(in,tin1); tin[1]=tin1;\n\t\t\tdes_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);\n\t\t\ttout0=tin[0]^xor0;\n\t\t\ttout1=tin[1]^xor1;\n\t\t\tl2c(tout0,out);\n\t\t\tl2c(tout1,out);\n\t\t\txor0=tin0;\n\t\t\txor1=tin1;\n\t\t\t}\n\t\tif (l != -8)\n\t\t\t{\n\t\t\tc2l(in,tin0); tin[0]=tin0;\n\t\t\tc2l(in,tin1); tin[1]=tin1;\n\t\t\tdes_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);\n\t\t\ttout0=tin[0]^xor0;\n\t\t\ttout1=tin[1]^xor1;\n\t\t\tl2cn(tout0,tout1,out,l+8);\n\t\t\txor0=tin0;\n\t\t\txor1=tin1;\n\t\t\t}\n\t\tiv=ivec;\n\t\tl2c(xor0,iv);\n\t\tl2c(xor1,iv);\n\t\t}\n\ttin0=tin1=tout0=tout1=xor0=xor1=0;\n\ttin[0]=tin[1]=0;\n\t}', 'void des_encrypt(DES_LONG *data, des_key_schedule ks, int enc)\n\t{\n\tregister DES_LONG l,r,t,u;\n#ifdef DES_PTR\n\tregister const unsigned char *des_SP=(const unsigned char *)des_SPtrans;\n#endif\n#ifndef DES_UNROLL\n\tregister int i;\n#endif\n\tregister DES_LONG *s;\n\tr=data[0];\n\tl=data[1];\n\tIP(r,l);\n\tr=ROTATE(r,29)&0xffffffffL;\n\tl=ROTATE(l,29)&0xffffffffL;\n\ts=(DES_LONG *)ks;\n\tif (enc)\n\t\t{\n#ifdef DES_UNROLL\n\t\tD_ENCRYPT(l,r, 0);\n\t\tD_ENCRYPT(r,l, 2);\n\t\tD_ENCRYPT(l,r, 4);\n\t\tD_ENCRYPT(r,l, 6);\n\t\tD_ENCRYPT(l,r, 8);\n\t\tD_ENCRYPT(r,l,10);\n\t\tD_ENCRYPT(l,r,12);\n\t\tD_ENCRYPT(r,l,14);\n\t\tD_ENCRYPT(l,r,16);\n\t\tD_ENCRYPT(r,l,18);\n\t\tD_ENCRYPT(l,r,20);\n\t\tD_ENCRYPT(r,l,22);\n\t\tD_ENCRYPT(l,r,24);\n\t\tD_ENCRYPT(r,l,26);\n\t\tD_ENCRYPT(l,r,28);\n\t\tD_ENCRYPT(r,l,30);\n#else\n\t\tfor (i=0; i<32; i+=8)\n\t\t\t{\n\t\t\tD_ENCRYPT(l,r,i+0);\n\t\t\tD_ENCRYPT(r,l,i+2);\n\t\t\tD_ENCRYPT(l,r,i+4);\n\t\t\tD_ENCRYPT(r,l,i+6);\n\t\t\t}\n#endif\n\t\t}\n\telse\n\t\t{\n#ifdef DES_UNROLL\n\t\tD_ENCRYPT(l,r,30);\n\t\tD_ENCRYPT(r,l,28);\n\t\tD_ENCRYPT(l,r,26);\n\t\tD_ENCRYPT(r,l,24);\n\t\tD_ENCRYPT(l,r,22);\n\t\tD_ENCRYPT(r,l,20);\n\t\tD_ENCRYPT(l,r,18);\n\t\tD_ENCRYPT(r,l,16);\n\t\tD_ENCRYPT(l,r,14);\n\t\tD_ENCRYPT(r,l,12);\n\t\tD_ENCRYPT(l,r,10);\n\t\tD_ENCRYPT(r,l, 8);\n\t\tD_ENCRYPT(l,r, 6);\n\t\tD_ENCRYPT(r,l, 4);\n\t\tD_ENCRYPT(l,r, 2);\n\t\tD_ENCRYPT(r,l, 0);\n#else\n\t\tfor (i=30; i>0; i-=8)\n\t\t\t{\n\t\t\tD_ENCRYPT(l,r,i-0);\n\t\t\tD_ENCRYPT(r,l,i-2);\n\t\t\tD_ENCRYPT(l,r,i-4);\n\t\t\tD_ENCRYPT(r,l,i-6);\n\t\t\t}\n#endif\n\t\t}\n\tl=ROTATE(l,3)&0xffffffffL;\n\tr=ROTATE(r,3)&0xffffffffL;\n\tFP(r,l);\n\tdata[0]=l;\n\tdata[1]=r;\n\tl=r=t=u=0;\n\t}']
36,598
0
https://github.com/libav/libav/blob/dc86ca1ab54c04f15214e6fc023d6dfc627aee34/libavcodec/smacker.c/#L320
static int decode_header_trees(SmackVContext *smk) { GetBitContext gb; int mmap_size, mclr_size, full_size, type_size; mmap_size = AV_RL32(smk->avctx->extradata); mclr_size = AV_RL32(smk->avctx->extradata + 4); full_size = AV_RL32(smk->avctx->extradata + 8); type_size = AV_RL32(smk->avctx->extradata + 12); init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8); if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\n"); smk->mmap_tbl = av_malloc(sizeof(int) * 2); smk->mmap_tbl[0] = 0; smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1; } else { if (smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size)) return -1; } if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n"); smk->mclr_tbl = av_malloc(sizeof(int) * 2); smk->mclr_tbl[0] = 0; smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1; } else { if (smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size)) return -1; } if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n"); smk->full_tbl = av_malloc(sizeof(int) * 2); smk->full_tbl[0] = 0; smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1; } else { if (smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size)) return -1; } if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n"); smk->type_tbl = av_malloc(sizeof(int) * 2); smk->type_tbl[0] = 0; smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1; } else { if (smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size)) return -1; } return 0; }
['static int decode_header_trees(SmackVContext *smk) {\n GetBitContext gb;\n int mmap_size, mclr_size, full_size, type_size;\n mmap_size = AV_RL32(smk->avctx->extradata);\n mclr_size = AV_RL32(smk->avctx->extradata + 4);\n full_size = AV_RL32(smk->avctx->extradata + 8);\n type_size = AV_RL32(smk->avctx->extradata + 12);\n init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8);\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\\n");\n smk->mmap_tbl = av_malloc(sizeof(int) * 2);\n smk->mmap_tbl[0] = 0;\n smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size))\n return -1;\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\\n");\n smk->mclr_tbl = av_malloc(sizeof(int) * 2);\n smk->mclr_tbl[0] = 0;\n smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size))\n return -1;\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\\n");\n smk->full_tbl = av_malloc(sizeof(int) * 2);\n smk->full_tbl[0] = 0;\n smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size))\n return -1;\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\\n");\n smk->type_tbl = av_malloc(sizeof(int) * 2);\n smk->type_tbl[0] = 0;\n smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size))\n return -1;\n }\n return 0;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size = (bit_size+7)>>3;\n if (buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n s->buffer_end = buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index = 0;\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer & ~3);\n s->bit_count = 32 + 8*((intptr_t)buffer & 3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef ALT_BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n index++;\n s->index = index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\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}']
36,599
0
https://github.com/openssl/openssl/blob/74df8c4ce3c7ccb4e2809a44791756356f704b66/crypto/rand/rand_lib.c/#L145
int RAND_bytes(unsigned char *buf, int num) { const RAND_METHOD *meth = RAND_get_rand_method(); if (meth->bytes != NULL) return meth->bytes(buf, num); RANDerr(RAND_F_RAND_BYTES, RAND_R_FUNC_NOT_IMPLEMENTED); return -1; }
['int RAND_bytes(unsigned char *buf, int num)\n{\n const RAND_METHOD *meth = RAND_get_rand_method();\n if (meth->bytes != NULL)\n return meth->bytes(buf, num);\n RANDerr(RAND_F_RAND_BYTES, RAND_R_FUNC_NOT_IMPLEMENTED);\n return -1;\n}', 'const RAND_METHOD *RAND_get_rand_method(void)\n{\n const RAND_METHOD *tmp_meth = NULL;\n if (!RUN_ONCE(&rand_init, do_rand_init))\n return NULL;\n CRYPTO_THREAD_write_lock(rand_meth_lock);\n if (default_RAND_meth == NULL) {\n#ifndef OPENSSL_NO_ENGINE\n ENGINE *e;\n if ((e = ENGINE_get_default_RAND()) != NULL\n && (tmp_meth = ENGINE_get_RAND(e)) != NULL) {\n funct_ref = e;\n default_RAND_meth = tmp_meth;\n } else {\n ENGINE_finish(e);\n default_RAND_meth = &openssl_rand_meth;\n }\n#else\n default_RAND_meth = &openssl_rand_meth;\n#endif\n }\n tmp_meth = default_RAND_meth;\n CRYPTO_THREAD_unlock(rand_meth_lock);\n return tmp_meth;\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}']
36,600
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/error_resilience.c/#L419
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; 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.mb_type[mb_xy])) f=MV_FROZEN; if(!(error&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.mb_type[mb_xy])) continue; if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue; 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; s->mv[0][0][0]= 0; s->mv[0][0][1]= 0; decode_mb(s); } } 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 pred_count=0; int j; int best_score=256*256*256*64; int best_pred=0; const int mot_stride= s->b8_stride; const int mot_index= mb_x*2 + mb_y*2*mot_stride; int prev_x= s->current_picture.motion_val[0][mot_index][0]; int prev_y= s->current_picture.motion_val[0][mot_index][1]; if((mb_x^mb_y^pass)&1) continue; if(fixed[mb_xy]==MV_FROZEN) continue; assert(!IS_INTRA(s->current_picture.mb_type[mb_xy])); assert(s->last_picture_ptr && s->last_picture_ptr->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.motion_val[0][mot_index - 2][0]; mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - 2][1]; pred_count++; } if(mb_x+1<mb_width && fixed[mb_xy+1]){ mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + 2][0]; mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][1]; pred_count++; } if(mb_y>0 && fixed[mb_xy-mb_stride]){ mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*2][0]; mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*2][1]; pred_count++; } if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){ mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*2][0]; mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1]; pred_count++; } if(pred_count==0) continue; if(pred_count>1){ int sum_x=0, sum_y=0; int max_x, max_y, min_x, min_y; for(j=0; j<pred_count; j++){ sum_x+= mv_predictor[j][0]; sum_y+= mv_predictor[j][1]; } mv_predictor[pred_count][0] = sum_x/j; mv_predictor[pred_count][1] = sum_y/j; if(pred_count>=3){ min_y= min_x= 99999; max_y= max_x=-99999; }else{ min_x=min_y=max_x=max_y=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]); min_x= FFMIN(min_x, mv_predictor[j][0]); min_y= FFMIN(min_y, mv_predictor[j][1]); } mv_predictor[pred_count+1][0] = sum_x - max_x - min_x; mv_predictor[pred_count+1][1] = sum_y - max_y - min_y; if(pred_count==4){ mv_predictor[pred_count+1][0] /= 2; mv_predictor[pred_count+1][1] /= 2; } pred_count+=2; } pred_count++; mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0]; mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1]; pred_count++; 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.data[0] + mb_x*16 + mb_y*16*s->linesize; s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0]; s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1]; decode_mb(s); 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->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0]; s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1]; decode_mb(s); 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 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;\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.mb_type[mb_xy])) f=MV_FROZEN;\n if(!(error&MV_ERROR)) 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)) || 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.mb_type[mb_xy])) continue;\n if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue;\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 s->mv[0][0][0]= 0;\n s->mv[0][0][1]= 0;\n decode_mb(s);\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;\nint 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 pred_count=0;\n int j;\n int best_score=256*256*256*64;\n int best_pred=0;\n const int mot_stride= s->b8_stride;\n const int mot_index= mb_x*2 + mb_y*2*mot_stride;\n int prev_x= s->current_picture.motion_val[0][mot_index][0];\n int prev_y= s->current_picture.motion_val[0][mot_index][1];\n if((mb_x^mb_y^pass)&1) continue;\n if(fixed[mb_xy]==MV_FROZEN) continue;\n assert(!IS_INTRA(s->current_picture.mb_type[mb_xy]));\n assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);\n j=0;\n if(mb_x>0 && fixed[mb_xy-1 ]==MV_FROZEN) j=1;\n if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_FROZEN) j=1;\n if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_FROZEN) j=1;\n if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_FROZEN) j=1;\n if(j==0) continue;\n j=0;\n if(mb_x>0 && fixed[mb_xy-1 ]==MV_CHANGED) j=1;\n if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_CHANGED) j=1;\n if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_CHANGED) j=1;\n if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_CHANGED) j=1;\n if(j==0 && pass>1) continue;\n none_left=0;\n if(mb_x>0 && fixed[mb_xy-1]){\n mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - 2][0];\n mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - 2][1];\n pred_count++;\n }\n if(mb_x+1<mb_width && fixed[mb_xy+1]){\n mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + 2][0];\n mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][1];\n pred_count++;\n }\n if(mb_y>0 && fixed[mb_xy-mb_stride]){\n mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*2][0];\n mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*2][1];\n pred_count++;\n }\n if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){\n mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*2][0];\n mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1];\n pred_count++;\n }\n if(pred_count==0) continue;\n if(pred_count>1){\n int sum_x=0, sum_y=0;\n int max_x, max_y, min_x, min_y;\n for(j=0; j<pred_count; j++){\n sum_x+= mv_predictor[j][0];\n sum_y+= mv_predictor[j][1];\n }\n mv_predictor[pred_count][0] = sum_x/j;\n mv_predictor[pred_count][1] = sum_y/j;\n if(pred_count>=3){\n min_y= min_x= 99999;\n max_y= max_x=-99999;\n }else{\n min_x=min_y=max_x=max_y=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 min_x= FFMIN(min_x, mv_predictor[j][0]);\n min_y= FFMIN(min_y, mv_predictor[j][1]);\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 if(pred_count==4){\n mv_predictor[pred_count+1][0] /= 2;\n mv_predictor[pred_count+1][1] /= 2;\n }\n pred_count+=2;\n }\n pred_count++;\n mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0];\n mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1];\n pred_count++;\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.data[0] + mb_x*16 + mb_y*16*s->linesize;\n s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];\n s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1];\n decode_mb(s);\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 ]-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]-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]-src[k+s->linesize*16]);\n }\n if(score <= best_score){\n best_score= score;\n best_pred= j;\n }\n }\nscore_sum+= best_score;\n s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0];\n s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1];\n decode_mb(s);\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}']