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
2,501
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 int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,\n const BIGNUM *a1_odd, int k, BN_CTX *ctx,\n BN_MONT_CTX *mont)\n{\n if (!BN_mod_exp_mont(w, w, a1_odd, a, ctx, mont))\n return -1;\n if (BN_is_one(w))\n return 0;\n if (BN_cmp(w, a1) == 0)\n return 0;\n while (--k) {\n if (!BN_mod_mul(w, w, w, a, ctx))\n return -1;\n if (BN_is_one(w))\n return 1;\n if (BN_cmp(w, a1) == 0)\n return 0;\n }\n bn_check_top(w);\n return 1;\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_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n bn_correct_top(r);\n } else\n#endif\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_is_one(const BIGNUM *a)\n{\n return BN_abs_is_word(a, 1) && !a->neg;\n}', 'int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)\n{\n return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));\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_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_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_rshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, j, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l, tmp;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_RSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n rb = n % BN_BITS2;\n lb = BN_BITS2 - rb;\n if (nw >= a->top || a->top == 0) {\n BN_zero(r);\n return 1;\n }\n i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;\n if (r != a) {\n if (bn_wexpand(r, i) == NULL)\n return 0;\n r->neg = a->neg;\n } else {\n if (n == 0)\n return 1;\n }\n f = &(a->d[nw]);\n t = r->d;\n j = a->top - nw;\n r->top = i;\n if (rb == 0) {\n for (i = j; i != 0; i--)\n *(t++) = *(f++);\n } else {\n l = *(f++);\n for (i = j - 1; i != 0; i--) {\n tmp = (l >> rb) & BN_MASK2;\n l = *(f++);\n *(t++) = (tmp | (l << lb)) & BN_MASK2;\n }\n if ((l = (l >> rb) & BN_MASK2))\n *(t) = l;\n }\n if (!r->top)\n r->neg = 0;\n bn_check_top(r);\n return 1;\n}', '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#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}']
2,502
0
https://github.com/libav/libav/blob/cc20fbcd39c7b60602edae4f7deb092ecfd3c975/libavcodec/vp9block.c/#L782
static int decode_block_coeffs(VP56RangeCoder *c, int16_t *coef, int n_coeffs, enum TxfmMode tx, unsigned (*cnt)[6][3], unsigned (*eob)[6][2], uint8_t(*p)[6][11], int nnz, const int16_t *scan, const int16_t(*nb)[2], const int16_t *band_counts, const int16_t *qmul) { int i = 0, band = 0, band_left = band_counts[band]; uint8_t *tp = p[0][nnz]; uint8_t cache[1024]; do { int val, rc; val = vp56_rac_get_prob_branchy(c, tp[0]); eob[band][nnz][val]++; if (!val) break; skip_eob: if (!vp56_rac_get_prob_branchy(c, tp[1])) { cnt[band][nnz][0]++; if (!--band_left) band_left = band_counts[++band]; cache[scan[i]] = 0; nnz = (1 + cache[nb[i][0]] + cache[nb[i][1]]) >> 1; tp = p[band][nnz]; if (++i == n_coeffs) break; goto skip_eob; } rc = scan[i]; if (!vp56_rac_get_prob_branchy(c, tp[2])) { cnt[band][nnz][1]++; val = 1; cache[rc] = 1; } else { if (!tp[3]) memcpy(&tp[3], ff_vp9_model_pareto8[tp[2]], 8); cnt[band][nnz][2]++; if (!vp56_rac_get_prob_branchy(c, tp[3])) { if (!vp56_rac_get_prob_branchy(c, tp[4])) { cache[rc] = val = 2; } else { val = 3 + vp56_rac_get_prob(c, tp[5]); cache[rc] = 3; } } else if (!vp56_rac_get_prob_branchy(c, tp[6])) { cache[rc] = 4; if (!vp56_rac_get_prob_branchy(c, tp[7])) { val = vp56_rac_get_prob(c, 159) + 5; } else { val = (vp56_rac_get_prob(c, 165) << 1) + 7; val += vp56_rac_get_prob(c, 145); } } else { cache[rc] = 5; if (!vp56_rac_get_prob_branchy(c, tp[8])) { if (!vp56_rac_get_prob_branchy(c, tp[9])) { val = (vp56_rac_get_prob(c, 173) << 2) + 11; val += (vp56_rac_get_prob(c, 148) << 1); val += vp56_rac_get_prob(c, 140); } else { val = (vp56_rac_get_prob(c, 176) << 3) + 19; val += (vp56_rac_get_prob(c, 155) << 2); val += (vp56_rac_get_prob(c, 140) << 1); val += vp56_rac_get_prob(c, 135); } } else if (!vp56_rac_get_prob_branchy(c, tp[10])) { val = (vp56_rac_get_prob(c, 180) << 4) + 35; val += (vp56_rac_get_prob(c, 157) << 3); val += (vp56_rac_get_prob(c, 141) << 2); val += (vp56_rac_get_prob(c, 134) << 1); val += vp56_rac_get_prob(c, 130); } else { val = (vp56_rac_get_prob(c, 254) << 13) + 67; val += (vp56_rac_get_prob(c, 254) << 12); val += (vp56_rac_get_prob(c, 254) << 11); val += (vp56_rac_get_prob(c, 252) << 10); val += (vp56_rac_get_prob(c, 249) << 9); val += (vp56_rac_get_prob(c, 243) << 8); val += (vp56_rac_get_prob(c, 230) << 7); val += (vp56_rac_get_prob(c, 196) << 6); val += (vp56_rac_get_prob(c, 177) << 5); val += (vp56_rac_get_prob(c, 153) << 4); val += (vp56_rac_get_prob(c, 140) << 3); val += (vp56_rac_get_prob(c, 133) << 2); val += (vp56_rac_get_prob(c, 130) << 1); val += vp56_rac_get_prob(c, 129); } } } if (!--band_left) band_left = band_counts[++band]; if (tx == TX_32X32) coef[rc] = ((vp8_rac_get(c) ? -val : val) * qmul[!!i]) / 2; else coef[rc] = (vp8_rac_get(c) ? -val : val) * qmul[!!i]; nnz = (1 + cache[nb[i][0]] + cache[nb[i][1]]) >> 1; tp = p[band][nnz]; } while (++i < n_coeffs); return i; }
['static int decode_block_coeffs(VP56RangeCoder *c, int16_t *coef, int n_coeffs,\n enum TxfmMode tx, unsigned (*cnt)[6][3],\n unsigned (*eob)[6][2], uint8_t(*p)[6][11],\n int nnz, const int16_t *scan,\n const int16_t(*nb)[2],\n const int16_t *band_counts, const int16_t *qmul)\n{\n int i = 0, band = 0, band_left = band_counts[band];\n uint8_t *tp = p[0][nnz];\n uint8_t cache[1024];\n do {\n int val, rc;\n val = vp56_rac_get_prob_branchy(c, tp[0]);\n eob[band][nnz][val]++;\n if (!val)\n break;\nskip_eob:\n if (!vp56_rac_get_prob_branchy(c, tp[1])) {\n cnt[band][nnz][0]++;\n if (!--band_left)\n band_left = band_counts[++band];\n cache[scan[i]] = 0;\n nnz = (1 + cache[nb[i][0]] + cache[nb[i][1]]) >> 1;\n tp = p[band][nnz];\n if (++i == n_coeffs)\n break;\n goto skip_eob;\n }\n rc = scan[i];\n if (!vp56_rac_get_prob_branchy(c, tp[2])) {\n cnt[band][nnz][1]++;\n val = 1;\n cache[rc] = 1;\n } else {\n if (!tp[3])\n memcpy(&tp[3], ff_vp9_model_pareto8[tp[2]], 8);\n cnt[band][nnz][2]++;\n if (!vp56_rac_get_prob_branchy(c, tp[3])) {\n if (!vp56_rac_get_prob_branchy(c, tp[4])) {\n cache[rc] = val = 2;\n } else {\n val = 3 + vp56_rac_get_prob(c, tp[5]);\n cache[rc] = 3;\n }\n } else if (!vp56_rac_get_prob_branchy(c, tp[6])) {\n cache[rc] = 4;\n if (!vp56_rac_get_prob_branchy(c, tp[7])) {\n val = vp56_rac_get_prob(c, 159) + 5;\n } else {\n val = (vp56_rac_get_prob(c, 165) << 1) + 7;\n val += vp56_rac_get_prob(c, 145);\n }\n } else {\n cache[rc] = 5;\n if (!vp56_rac_get_prob_branchy(c, tp[8])) {\n if (!vp56_rac_get_prob_branchy(c, tp[9])) {\n val = (vp56_rac_get_prob(c, 173) << 2) + 11;\n val += (vp56_rac_get_prob(c, 148) << 1);\n val += vp56_rac_get_prob(c, 140);\n } else {\n val = (vp56_rac_get_prob(c, 176) << 3) + 19;\n val += (vp56_rac_get_prob(c, 155) << 2);\n val += (vp56_rac_get_prob(c, 140) << 1);\n val += vp56_rac_get_prob(c, 135);\n }\n } else if (!vp56_rac_get_prob_branchy(c, tp[10])) {\n val = (vp56_rac_get_prob(c, 180) << 4) + 35;\n val += (vp56_rac_get_prob(c, 157) << 3);\n val += (vp56_rac_get_prob(c, 141) << 2);\n val += (vp56_rac_get_prob(c, 134) << 1);\n val += vp56_rac_get_prob(c, 130);\n } else {\n val = (vp56_rac_get_prob(c, 254) << 13) + 67;\n val += (vp56_rac_get_prob(c, 254) << 12);\n val += (vp56_rac_get_prob(c, 254) << 11);\n val += (vp56_rac_get_prob(c, 252) << 10);\n val += (vp56_rac_get_prob(c, 249) << 9);\n val += (vp56_rac_get_prob(c, 243) << 8);\n val += (vp56_rac_get_prob(c, 230) << 7);\n val += (vp56_rac_get_prob(c, 196) << 6);\n val += (vp56_rac_get_prob(c, 177) << 5);\n val += (vp56_rac_get_prob(c, 153) << 4);\n val += (vp56_rac_get_prob(c, 140) << 3);\n val += (vp56_rac_get_prob(c, 133) << 2);\n val += (vp56_rac_get_prob(c, 130) << 1);\n val += vp56_rac_get_prob(c, 129);\n }\n }\n }\n if (!--band_left)\n band_left = band_counts[++band];\n if (tx == TX_32X32)\n coef[rc] = ((vp8_rac_get(c) ? -val : val) * qmul[!!i]) / 2;\n else\n coef[rc] = (vp8_rac_get(c) ? -val : val) * qmul[!!i];\n nnz = (1 + cache[nb[i][0]] + cache[nb[i][1]]) >> 1;\n tp = p[band][nnz];\n } while (++i < n_coeffs);\n return i;\n}']
2,503
0
https://github.com/openssl/openssl/blob/ea32151f7b9353f8906188d007c6893704ac17bb/crypto/dso/dso_lib.c/#L157
DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags) { DSO *ret; int allocated = 0; if (dso == NULL) { ret = DSO_new_method(meth); if (ret == NULL) { DSOerr(DSO_F_DSO_LOAD, ERR_R_MALLOC_FAILURE); goto err; } allocated = 1; if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) { DSOerr(DSO_F_DSO_LOAD, DSO_R_CTRL_FAILED); goto err; } } else ret = dso; if (ret->filename != NULL) { DSOerr(DSO_F_DSO_LOAD, DSO_R_DSO_ALREADY_LOADED); goto err; } if (filename != NULL) if (!DSO_set_filename(ret, filename)) { DSOerr(DSO_F_DSO_LOAD, DSO_R_SET_FILENAME_FAILED); goto err; } filename = ret->filename; if (filename == NULL) { DSOerr(DSO_F_DSO_LOAD, DSO_R_NO_FILENAME); goto err; } if (ret->meth->dso_load == NULL) { DSOerr(DSO_F_DSO_LOAD, DSO_R_UNSUPPORTED); goto err; } if (!ret->meth->dso_load(ret)) { DSOerr(DSO_F_DSO_LOAD, DSO_R_LOAD_FAILED); goto err; } return (ret); err: if (allocated) DSO_free(ret); return (NULL); }
['DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)\n{\n DSO *ret;\n int allocated = 0;\n if (dso == NULL) {\n ret = DSO_new_method(meth);\n if (ret == NULL) {\n DSOerr(DSO_F_DSO_LOAD, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n allocated = 1;\n if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_CTRL_FAILED);\n goto err;\n }\n } else\n ret = dso;\n if (ret->filename != NULL) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_DSO_ALREADY_LOADED);\n goto err;\n }\n if (filename != NULL)\n if (!DSO_set_filename(ret, filename)) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_SET_FILENAME_FAILED);\n goto err;\n }\n filename = ret->filename;\n if (filename == NULL) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_NO_FILENAME);\n goto err;\n }\n if (ret->meth->dso_load == NULL) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_UNSUPPORTED);\n goto err;\n }\n if (!ret->meth->dso_load(ret)) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_LOAD_FAILED);\n goto err;\n }\n return (ret);\n err:\n if (allocated)\n DSO_free(ret);\n return (NULL);\n}', 'long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)\n{\n if (dso == NULL) {\n DSOerr(DSO_F_DSO_CTRL, ERR_R_PASSED_NULL_PARAMETER);\n return (-1);\n }\n switch (cmd) {\n case DSO_CTRL_GET_FLAGS:\n return dso->flags;\n case DSO_CTRL_SET_FLAGS:\n dso->flags = (int)larg;\n return (0);\n case DSO_CTRL_OR_FLAGS:\n dso->flags |= (int)larg;\n return (0);\n default:\n break;\n }\n if ((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) {\n DSOerr(DSO_F_DSO_CTRL, DSO_R_UNSUPPORTED);\n return (-1);\n }\n return (dso->meth->dso_ctrl(dso, cmd, larg, parg));\n}', 'int DSO_set_filename(DSO *dso, const char *filename)\n{\n char *copied;\n if ((dso == NULL) || (filename == NULL)) {\n DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_PASSED_NULL_PARAMETER);\n return (0);\n }\n if (dso->loaded_filename) {\n DSOerr(DSO_F_DSO_SET_FILENAME, DSO_R_DSO_ALREADY_LOADED);\n return (0);\n }\n copied = OPENSSL_strdup(filename);\n if (copied == NULL) {\n DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_MALLOC_FAILURE);\n return (0);\n }\n OPENSSL_free(dso->filename);\n dso->filename = copied;\n return (1);\n}', 'char *CRYPTO_strdup(const char *str, const char* file, int line)\n{\n char *ret;\n size_t size;\n if (str == NULL)\n return NULL;\n size = strlen(str) + 1;\n ret = CRYPTO_malloc(size, file, line);\n if (ret != NULL)\n memcpy(ret, str, size);\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 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}']
2,504
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}']
2,505
0
https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L271
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['int BN_from_montgomery(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 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 (t1 == NULL || 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}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)\n{\n BIGNUM *n;\n BN_ULONG *ap, *np, *rp, n0, v, carry;\n int nl, max, i;\n n = &(mont->N);\n nl = n->top;\n if (nl == 0) {\n ret->top = 0;\n return (1);\n }\n max = (2 * nl);\n if (bn_wexpand(r, max) == NULL)\n return (0);\n r->neg ^= n->neg;\n np = n->d;\n rp = r->d;\n i = max - r->top;\n if (i)\n memset(&rp[r->top], 0, sizeof(*rp) * i);\n r->top = max;\n n0 = mont->n0[0];\n for (carry = 0, i = 0; i < nl; i++, rp++) {\n v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);\n v = (v + carry + rp[nl]) & BN_MASK2;\n carry |= (v != rp[nl]);\n carry &= (v <= rp[nl]);\n rp[nl] = v;\n }\n if (bn_wexpand(ret, nl) == NULL)\n return (0);\n ret->top = nl;\n ret->neg = r->neg;\n rp = ret->d;\n ap = &(r->d[nl]);\n# define BRANCH_FREE 1\n# if BRANCH_FREE\n {\n BN_ULONG *nrp;\n size_t m;\n v = bn_sub_words(rp, ap, np, nl) - carry;\n m = (0 - (size_t)v);\n nrp =\n (BN_ULONG *)(((PTR_SIZE_INT) rp & ~m) | ((PTR_SIZE_INT) ap & m));\n for (i = 0, nl -= 4; i < nl; i += 4) {\n BN_ULONG t1, t2, t3, t4;\n t1 = nrp[i + 0];\n t2 = nrp[i + 1];\n t3 = nrp[i + 2];\n ap[i + 0] = 0;\n t4 = nrp[i + 3];\n ap[i + 1] = 0;\n rp[i + 0] = t1;\n ap[i + 2] = 0;\n rp[i + 1] = t2;\n ap[i + 3] = 0;\n rp[i + 2] = t3;\n rp[i + 3] = t4;\n }\n for (nl += 4; i < nl; i++)\n rp[i] = nrp[i], ap[i] = 0;\n }\n# else\n if (bn_sub_words(rp, ap, np, nl) - carry)\n memcpy(rp, ap, nl * sizeof(BN_ULONG));\n# endif\n bn_correct_top(r);\n bn_correct_top(ret);\n bn_check_top(ret);\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}']
2,506
0
https://github.com/libav/libav/blob/3b2fbe67bd63b00331db2a9b213f6d420418a312/libavcodec/opus_silk.c/#L891
static inline int silk_is_lpc_stable(const int16_t lpc[16], int order) { int k, j, DC_resp = 0; int32_t lpc32[2][16]; int totalinvgain = 1 << 30; int32_t *row = lpc32[0], *prevrow; for (k = 0; k < order; k++) { DC_resp += lpc[k]; row[k] = lpc[k] * 4096; } if (DC_resp >= 4096) return 0; for (k = order - 1; 1; k--) { int rc; int gaindiv; int gain; int fbits; int error; if (FFABS(row[k]) > 16773022) return 0; rc = -(row[k] * 128); gaindiv = (1 << 30) - MULH(rc, rc); totalinvgain = MULH(totalinvgain, gaindiv) << 2; if (k == 0) return (totalinvgain >= 107374); fbits = opus_ilog(gaindiv); gain = ((1 << 29) - 1) / (gaindiv >> (fbits + 1 - 16)); error = (1 << 29) - MULL(gaindiv << (15 + 16 - fbits), gain, 16); gain = ((gain << 16) + (error * gain >> 13)); prevrow = row; row = lpc32[k & 1]; for (j = 0; j < k; j++) { int x = prevrow[j] - ROUND_MULL(prevrow[k - j - 1], rc, 31); row[j] = ROUND_MULL(x, gain, fbits); } } }
['static inline void silk_decode_lpc(SilkContext *s, SilkFrame *frame,\n OpusRangeCoder *rc,\n float lpc_leadin[16], float lpc[16],\n int *lpc_order, int *has_lpc_leadin, int voiced)\n{\n int i;\n int order;\n int8_t lsf_i1, lsf_i2[16];\n int16_t lsf_res[16];\n int16_t nlsf[16];\n *lpc_order = order = s->wb ? 16 : 10;\n lsf_i1 = opus_rc_getsymbol(rc, silk_model_lsf_s1[s->wb][voiced]);\n for (i = 0; i < order; i++) {\n int index = s->wb ? silk_lsf_s2_model_sel_wb [lsf_i1][i] :\n silk_lsf_s2_model_sel_nbmb[lsf_i1][i];\n lsf_i2[i] = opus_rc_getsymbol(rc, silk_model_lsf_s2[index]) - 4;\n if (lsf_i2[i] == -4)\n lsf_i2[i] -= opus_rc_getsymbol(rc, silk_model_lsf_s2_ext);\n else if (lsf_i2[i] == 4)\n lsf_i2[i] += opus_rc_getsymbol(rc, silk_model_lsf_s2_ext);\n }\n for (i = order - 1; i >= 0; i--) {\n int qstep = s->wb ? 9830 : 11796;\n lsf_res[i] = lsf_i2[i] * 1024;\n if (lsf_i2[i] < 0) lsf_res[i] += 102;\n else if (lsf_i2[i] > 0) lsf_res[i] -= 102;\n lsf_res[i] = (lsf_res[i] * qstep) >> 16;\n if (i + 1 < order) {\n int weight = s->wb ? silk_lsf_pred_weights_wb [silk_lsf_weight_sel_wb [lsf_i1][i]][i] :\n silk_lsf_pred_weights_nbmb[silk_lsf_weight_sel_nbmb[lsf_i1][i]][i];\n lsf_res[i] += (lsf_res[i+1] * weight) >> 8;\n }\n }\n for (i = 0; i < order; i++) {\n const uint8_t * codebook = s->wb ? silk_lsf_codebook_wb [lsf_i1] :\n silk_lsf_codebook_nbmb[lsf_i1];\n int cur, prev, next, weight_sq, weight, ipart, fpart, y, value;\n cur = codebook[i];\n prev = i ? codebook[i - 1] : 0;\n next = i + 1 < order ? codebook[i + 1] : 256;\n weight_sq = (1024 / (cur - prev) + 1024 / (next - cur)) << 16;\n ipart = opus_ilog(weight_sq);\n fpart = (weight_sq >> (ipart-8)) & 127;\n y = ((ipart & 1) ? 32768 : 46214) >> ((32 - ipart)>>1);\n weight = y + ((213 * fpart * y) >> 16);\n value = cur * 128 + (lsf_res[i] * 16384) / weight;\n nlsf[i] = av_clip(value, 0, 32767);\n }\n silk_stabilize_lsf(nlsf, order, s->wb ? silk_lsf_min_spacing_wb :\n silk_lsf_min_spacing_nbmb);\n *has_lpc_leadin = 0;\n if (s->subframes == 4) {\n int offset = opus_rc_getsymbol(rc, silk_model_lsf_interpolation_offset);\n if (offset != 4 && frame->coded) {\n *has_lpc_leadin = 1;\n if (offset != 0) {\n int16_t nlsf_leadin[16];\n for (i = 0; i < order; i++)\n nlsf_leadin[i] = frame->nlsf[i] +\n ((nlsf[i] - frame->nlsf[i]) * offset >> 2);\n silk_lsf2lpc(nlsf_leadin, lpc_leadin, order);\n } else\n memcpy(lpc_leadin, frame->lpc, 16 * sizeof(float));\n } else\n offset = 4;\n s->nlsf_interp_factor = offset;\n silk_lsf2lpc(nlsf, lpc, order);\n } else {\n s->nlsf_interp_factor = 4;\n silk_lsf2lpc(nlsf, lpc, order);\n }\n memcpy(frame->nlsf, nlsf, order * sizeof(nlsf[0]));\n memcpy(frame->lpc, lpc, order * sizeof(lpc[0]));\n}', 'static void silk_lsf2lpc(const int16_t nlsf[16], float lpcf[16], int order)\n{\n int i, k;\n int32_t lsp[16];\n int32_t p[9], q[9];\n int32_t lpc32[16];\n int16_t lpc[16];\n for (k = 0; k < order; k++) {\n int index = nlsf[k] >> 8;\n int offset = nlsf[k] & 255;\n int k2 = (order == 10) ? silk_lsf_ordering_nbmb[k] : silk_lsf_ordering_wb[k];\n lsp[k2] = silk_cosine[index] * 256;\n lsp[k2] += (silk_cosine[index + 1] - silk_cosine[index]) * offset;\n lsp[k2] = (lsp[k2] + 4) >> 3;\n }\n silk_lsp2poly(lsp , p, order >> 1);\n silk_lsp2poly(lsp + 1, q, order >> 1);\n for (k = 0; k < order>>1; k++) {\n lpc32[k] = -p[k + 1] - p[k] - q[k + 1] + q[k];\n lpc32[order-k-1] = -p[k + 1] - p[k] + q[k + 1] - q[k];\n }\n for (i = 0; i < 10; i++) {\n int j;\n unsigned int maxabs = 0;\n for (j = 0, k = 0; j < order; j++) {\n unsigned int x = FFABS(lpc32[k]);\n if (x > maxabs) {\n maxabs = x;\n k = j;\n }\n }\n maxabs = (maxabs + 16) >> 5;\n if (maxabs > 32767) {\n unsigned int chirp, chirp_base;\n maxabs = FFMIN(maxabs, 163838);\n chirp_base = chirp = 65470 - ((maxabs - 32767) << 14) / ((maxabs * (k+1)) >> 2);\n for (k = 0; k < order; k++) {\n lpc32[k] = ROUND_MULL(lpc32[k], chirp, 16);\n chirp = (chirp_base * chirp + 32768) >> 16;\n }\n } else break;\n }\n if (i == 10) {\n for (k = 0; k < order; k++) {\n int x = (lpc32[k] + 16) >> 5;\n lpc[k] = av_clip_int16(x);\n lpc32[k] = lpc[k] << 5;\n }\n } else {\n for (k = 0; k < order; k++)\n lpc[k] = (lpc32[k] + 16) >> 5;\n }\n for (i = 1; i <= 16 && !silk_is_lpc_stable(lpc, order); i++) {\n unsigned int chirp, chirp_base;\n chirp_base = chirp = 65536 - (1 << i);\n for (k = 0; k < order; k++) {\n lpc32[k] = ROUND_MULL(lpc32[k], chirp, 16);\n lpc[k] = (lpc32[k] + 16) >> 5;\n chirp = (chirp_base * chirp + 32768) >> 16;\n }\n }\n for (i = 0; i < order; i++)\n lpcf[i] = lpc[i] / 4096.0f;\n}', 'static inline int silk_is_lpc_stable(const int16_t lpc[16], int order)\n{\n int k, j, DC_resp = 0;\n int32_t lpc32[2][16];\n int totalinvgain = 1 << 30;\n int32_t *row = lpc32[0], *prevrow;\n for (k = 0; k < order; k++) {\n DC_resp += lpc[k];\n row[k] = lpc[k] * 4096;\n }\n if (DC_resp >= 4096)\n return 0;\n for (k = order - 1; 1; k--) {\n int rc;\n int gaindiv;\n int gain;\n int fbits;\n int error;\n if (FFABS(row[k]) > 16773022)\n return 0;\n rc = -(row[k] * 128);\n gaindiv = (1 << 30) - MULH(rc, rc);\n totalinvgain = MULH(totalinvgain, gaindiv) << 2;\n if (k == 0)\n return (totalinvgain >= 107374);\n fbits = opus_ilog(gaindiv);\n gain = ((1 << 29) - 1) / (gaindiv >> (fbits + 1 - 16));\n error = (1 << 29) - MULL(gaindiv << (15 + 16 - fbits), gain, 16);\n gain = ((gain << 16) + (error * gain >> 13));\n prevrow = row;\n row = lpc32[k & 1];\n for (j = 0; j < k; j++) {\n int x = prevrow[j] - ROUND_MULL(prevrow[k - j - 1], rc, 31);\n row[j] = ROUND_MULL(x, gain, fbits);\n }\n }\n}']
2,507
0
https://github.com/openssl/openssl/blob/93f1c13619c5b41f2dcfdbf6ae666f867922a87a/crypto/lhash/lhash.c/#L271
static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg) { int i; LHASH_NODE *a, *n; if (lh == NULL) return; for (i = lh->num_nodes - 1; i >= 0; i--) { a = lh->b[i]; while (a != NULL) { n = a->next; if (use_arg) func_arg(a->data, arg); else func(a->data); a = n; } } }
['static int sv_body(char *hostname, int s, int stype, unsigned char *context)\n{\n char *buf = NULL;\n fd_set readfds;\n int ret = 1, width;\n int k, i;\n unsigned long l;\n SSL *con = NULL;\n BIO *sbio;\n#ifndef OPENSSL_NO_KRB5\n KSSL_CTX *kctx;\n#endif\n struct timeval timeout;\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)\n struct timeval tv;\n#else\n struct timeval *timeoutp;\n#endif\n if ((buf = OPENSSL_malloc(bufsize)) == NULL) {\n BIO_printf(bio_err, "out of memory\\n");\n goto err;\n }\n#ifdef FIONBIO\n if (s_nbio) {\n unsigned long sl = 1;\n if (!s_quiet)\n BIO_printf(bio_err, "turning on non blocking io\\n");\n if (BIO_socket_ioctl(s, FIONBIO, &sl) < 0)\n ERR_print_errors(bio_err);\n }\n#endif\n if (con == NULL) {\n con = SSL_new(ctx);\n#ifndef OPENSSL_NO_TLSEXT\n if (s_tlsextdebug) {\n SSL_set_tlsext_debug_callback(con, tlsext_cb);\n SSL_set_tlsext_debug_arg(con, bio_s_out);\n }\n if (s_tlsextstatus) {\n SSL_CTX_set_tlsext_status_cb(ctx, cert_status_cb);\n tlscstatp.err = bio_err;\n SSL_CTX_set_tlsext_status_arg(ctx, &tlscstatp);\n }\n#endif\n#ifndef OPENSSL_NO_KRB5\n if ((kctx = kssl_ctx_new()) != NULL) {\n SSL_set0_kssl_ctx(con, kctx);\n kssl_ctx_setstring(kctx, KSSL_SERVICE, KRB5SVC);\n kssl_ctx_setstring(kctx, KSSL_KEYTAB, KRB5KEYTAB);\n }\n#endif\n if (context && !SSL_set_session_id_context(con, context,\n strlen((char *)context))) {\n BIO_printf(bio_err, "Error setting session id context\\n");\n ret = -1;\n goto err;\n }\n }\n if(!SSL_clear(con)) {\n BIO_printf(bio_err, "Error clearing SSL connection\\n");\n ret = -1;\n goto err;\n }\n if (stype == SOCK_DGRAM) {\n sbio = BIO_new_dgram(s, BIO_NOCLOSE);\n if (enable_timeouts) {\n timeout.tv_sec = 0;\n timeout.tv_usec = DGRAM_RCV_TIMEOUT;\n BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);\n timeout.tv_sec = 0;\n timeout.tv_usec = DGRAM_SND_TIMEOUT;\n BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);\n }\n if (socket_mtu) {\n if (socket_mtu < DTLS_get_link_min_mtu(con)) {\n BIO_printf(bio_err, "MTU too small. Must be at least %ld\\n",\n DTLS_get_link_min_mtu(con));\n ret = -1;\n BIO_free(sbio);\n goto err;\n }\n SSL_set_options(con, SSL_OP_NO_QUERY_MTU);\n if (!DTLS_set_link_mtu(con, socket_mtu)) {\n BIO_printf(bio_err, "Failed to set MTU\\n");\n ret = -1;\n BIO_free(sbio);\n goto err;\n }\n } else\n BIO_ctrl(sbio, BIO_CTRL_DGRAM_MTU_DISCOVER, 0, NULL);\n SSL_set_options(con, SSL_OP_COOKIE_EXCHANGE);\n } else\n sbio = BIO_new_socket(s, BIO_NOCLOSE);\n if (s_nbio_test) {\n BIO *test;\n test = BIO_new(BIO_f_nbio_test());\n sbio = BIO_push(test, sbio);\n }\n#ifndef OPENSSL_NO_JPAKE\n if (jpake_secret)\n jpake_server_auth(bio_s_out, sbio, jpake_secret);\n#endif\n SSL_set_bio(con, sbio, sbio);\n SSL_set_accept_state(con);\n if (s_debug) {\n SSL_set_debug(con, 1);\n BIO_set_callback(SSL_get_rbio(con), bio_dump_callback);\n BIO_set_callback_arg(SSL_get_rbio(con), (char *)bio_s_out);\n }\n if (s_msg) {\n#ifndef OPENSSL_NO_SSL_TRACE\n if (s_msg == 2)\n SSL_set_msg_callback(con, SSL_trace);\n else\n#endif\n SSL_set_msg_callback(con, msg_cb);\n SSL_set_msg_callback_arg(con, bio_s_msg ? bio_s_msg : bio_s_out);\n }\n#ifndef OPENSSL_NO_TLSEXT\n if (s_tlsextdebug) {\n SSL_set_tlsext_debug_callback(con, tlsext_cb);\n SSL_set_tlsext_debug_arg(con, bio_s_out);\n }\n#endif\n width = s + 1;\n for (;;) {\n int read_from_terminal;\n int read_from_sslcon;\n read_from_terminal = 0;\n read_from_sslcon = SSL_pending(con);\n if (!read_from_sslcon) {\n FD_ZERO(&readfds);\n#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE)\n openssl_fdset(fileno(stdin), &readfds);\n#endif\n openssl_fdset(s, &readfds);\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)\n tv.tv_sec = 1;\n tv.tv_usec = 0;\n i = select(width, (void *)&readfds, NULL, NULL, &tv);\n if ((i < 0) || (!i && !_kbhit()))\n continue;\n if (_kbhit())\n read_from_terminal = 1;\n#else\n if ((SSL_version(con) == DTLS1_VERSION) &&\n DTLSv1_get_timeout(con, &timeout))\n timeoutp = &timeout;\n else\n timeoutp = NULL;\n i = select(width, (void *)&readfds, NULL, NULL, timeoutp);\n if ((SSL_version(con) == DTLS1_VERSION)\n && DTLSv1_handle_timeout(con) > 0) {\n BIO_printf(bio_err, "TIMEOUT occurred\\n");\n }\n if (i <= 0)\n continue;\n if (FD_ISSET(fileno(stdin), &readfds))\n read_from_terminal = 1;\n#endif\n if (FD_ISSET(s, &readfds))\n read_from_sslcon = 1;\n }\n if (read_from_terminal) {\n if (s_crlf) {\n int j, lf_num;\n i = raw_read_stdin(buf, bufsize / 2);\n lf_num = 0;\n for (j = 0; j < i; j++)\n if (buf[j] == \'\\n\')\n lf_num++;\n for (j = i - 1; j >= 0; j--) {\n buf[j + lf_num] = buf[j];\n if (buf[j] == \'\\n\') {\n lf_num--;\n i++;\n buf[j + lf_num] = \'\\r\';\n }\n }\n assert(lf_num == 0);\n } else\n i = raw_read_stdin(buf, bufsize);\n if (!s_quiet && !s_brief) {\n if ((i <= 0) || (buf[0] == \'Q\')) {\n BIO_printf(bio_s_out, "DONE\\n");\n SHUTDOWN(s);\n close_accept_socket();\n ret = -11;\n goto err;\n }\n if ((i <= 0) || (buf[0] == \'q\')) {\n BIO_printf(bio_s_out, "DONE\\n");\n if (SSL_version(con) != DTLS1_VERSION)\n SHUTDOWN(s);\n goto err;\n }\n#ifndef OPENSSL_NO_HEARTBEATS\n if ((buf[0] == \'B\') && ((buf[1] == \'\\n\') || (buf[1] == \'\\r\'))) {\n BIO_printf(bio_err, "HEARTBEATING\\n");\n SSL_heartbeat(con);\n i = 0;\n continue;\n }\n#endif\n if ((buf[0] == \'r\') && ((buf[1] == \'\\n\') || (buf[1] == \'\\r\'))) {\n SSL_renegotiate(con);\n i = SSL_do_handshake(con);\n printf("SSL_do_handshake -> %d\\n", i);\n i = 0;\n continue;\n }\n if ((buf[0] == \'R\') && ((buf[1] == \'\\n\') || (buf[1] == \'\\r\'))) {\n SSL_set_verify(con,\n SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE,\n NULL);\n SSL_renegotiate(con);\n i = SSL_do_handshake(con);\n printf("SSL_do_handshake -> %d\\n", i);\n i = 0;\n continue;\n }\n if (buf[0] == \'P\') {\n static const char *str = "Lets print some clear text\\n";\n BIO_write(SSL_get_wbio(con), str, strlen(str));\n }\n if (buf[0] == \'S\') {\n print_stats(bio_s_out, SSL_get_SSL_CTX(con));\n }\n }\n#ifdef CHARSET_EBCDIC\n ebcdic2ascii(buf, buf, i);\n#endif\n l = k = 0;\n for (;;) {\n#ifdef RENEG\n {\n static count = 0;\n if (++count == 100) {\n count = 0;\n SSL_renegotiate(con);\n }\n }\n#endif\n k = SSL_write(con, &(buf[l]), (unsigned int)i);\n#ifndef OPENSSL_NO_SRP\n while (SSL_get_error(con, k) == SSL_ERROR_WANT_X509_LOOKUP) {\n BIO_printf(bio_s_out, "LOOKUP renego during write\\n");\n srp_callback_parm.user =\n SRP_VBASE_get_by_user(srp_callback_parm.vb,\n srp_callback_parm.login);\n if (srp_callback_parm.user)\n BIO_printf(bio_s_out, "LOOKUP done %s\\n",\n srp_callback_parm.user->info);\n else\n BIO_printf(bio_s_out, "LOOKUP not successful\\n");\n k = SSL_write(con, &(buf[l]), (unsigned int)i);\n }\n#endif\n switch (SSL_get_error(con, k)) {\n case SSL_ERROR_NONE:\n break;\n case SSL_ERROR_WANT_WRITE:\n case SSL_ERROR_WANT_READ:\n case SSL_ERROR_WANT_X509_LOOKUP:\n BIO_printf(bio_s_out, "Write BLOCK\\n");\n break;\n case SSL_ERROR_SYSCALL:\n case SSL_ERROR_SSL:\n BIO_printf(bio_s_out, "ERROR\\n");\n ERR_print_errors(bio_err);\n ret = 1;\n goto err;\n case SSL_ERROR_ZERO_RETURN:\n BIO_printf(bio_s_out, "DONE\\n");\n ret = 1;\n goto err;\n }\n l += k;\n i -= k;\n if (i <= 0)\n break;\n }\n }\n if (read_from_sslcon) {\n if (!SSL_is_init_finished(con)) {\n i = init_ssl_connection(con);\n if (i < 0) {\n ret = 0;\n goto err;\n } else if (i == 0) {\n ret = 1;\n goto err;\n }\n } else {\n again:\n i = SSL_read(con, (char *)buf, bufsize);\n#ifndef OPENSSL_NO_SRP\n while (SSL_get_error(con, i) == SSL_ERROR_WANT_X509_LOOKUP) {\n BIO_printf(bio_s_out, "LOOKUP renego during read\\n");\n srp_callback_parm.user =\n SRP_VBASE_get_by_user(srp_callback_parm.vb,\n srp_callback_parm.login);\n if (srp_callback_parm.user)\n BIO_printf(bio_s_out, "LOOKUP done %s\\n",\n srp_callback_parm.user->info);\n else\n BIO_printf(bio_s_out, "LOOKUP not successful\\n");\n i = SSL_read(con, (char *)buf, bufsize);\n }\n#endif\n switch (SSL_get_error(con, i)) {\n case SSL_ERROR_NONE:\n#ifdef CHARSET_EBCDIC\n ascii2ebcdic(buf, buf, i);\n#endif\n raw_write_stdout(buf, (unsigned int)i);\n if (SSL_pending(con))\n goto again;\n break;\n case SSL_ERROR_WANT_WRITE:\n case SSL_ERROR_WANT_READ:\n BIO_printf(bio_s_out, "Read BLOCK\\n");\n break;\n case SSL_ERROR_SYSCALL:\n case SSL_ERROR_SSL:\n BIO_printf(bio_s_out, "ERROR\\n");\n ERR_print_errors(bio_err);\n ret = 1;\n goto err;\n case SSL_ERROR_ZERO_RETURN:\n BIO_printf(bio_s_out, "DONE\\n");\n ret = 1;\n goto err;\n }\n }\n }\n }\n err:\n if (con != NULL) {\n BIO_printf(bio_s_out, "shutting down SSL\\n");\n SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);\n SSL_free(con);\n }\n BIO_printf(bio_s_out, "CONNECTION CLOSED\\n");\n if (buf != NULL) {\n OPENSSL_cleanse(buf, bufsize);\n OPENSSL_free(buf);\n }\n if (ret >= 0)\n BIO_printf(bio_s_out, "ACCEPT\\n");\n return (ret);\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return (NULL);\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return (NULL);\n }\n s = (SSL *)OPENSSL_malloc(sizeof(SSL));\n if (s == NULL)\n goto err;\n memset(s, 0, sizeof(SSL));\n#ifndef OPENSSL_NO_KRB5\n s->kssl_ctx = kssl_ctx_new();\n#endif\n s->options = ctx->options;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n s->read_ahead = 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->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)\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 CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);\n s->ctx = ctx;\n#ifndef OPENSSL_NO_TLSEXT\n s->tlsext_debug_cb = 0;\n s->tlsext_debug_arg = NULL;\n s->tlsext_ticket_expected = 0;\n s->tlsext_status_type = -1;\n s->tlsext_status_expected = 0;\n s->tlsext_ocsp_ids = NULL;\n s->tlsext_ocsp_exts = NULL;\n s->tlsext_ocsp_resp = NULL;\n s->tlsext_ocsp_resplen = -1;\n CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);\n s->initial_ctx = ctx;\n# ifndef OPENSSL_NO_EC\n if (ctx->tlsext_ecpointformatlist) {\n s->tlsext_ecpointformatlist =\n BUF_memdup(ctx->tlsext_ecpointformatlist,\n ctx->tlsext_ecpointformatlist_length);\n if (!s->tlsext_ecpointformatlist)\n goto err;\n s->tlsext_ecpointformatlist_length =\n ctx->tlsext_ecpointformatlist_length;\n }\n if (ctx->tlsext_ellipticcurvelist) {\n s->tlsext_ellipticcurvelist =\n BUF_memdup(ctx->tlsext_ellipticcurvelist,\n ctx->tlsext_ellipticcurvelist_length);\n if (!s->tlsext_ellipticcurvelist)\n goto err;\n s->tlsext_ellipticcurvelist_length =\n ctx->tlsext_ellipticcurvelist_length;\n }\n# endif\n# ifndef OPENSSL_NO_NEXTPROTONEG\n s->next_proto_negotiated = NULL;\n# endif\n if (s->ctx->alpn_client_proto_list) {\n s->alpn_client_proto_list =\n OPENSSL_malloc(s->ctx->alpn_client_proto_list_len);\n if (s->alpn_client_proto_list == NULL)\n goto err;\n memcpy(s->alpn_client_proto_list, s->ctx->alpn_client_proto_list,\n s->ctx->alpn_client_proto_list_len);\n s->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len;\n }\n#endif\n s->verify_result = X509_V_OK;\n s->method = ctx->method;\n if (!s->method->ssl_new(s))\n goto err;\n s->references = 1;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if(!SSL_clear(s))\n goto err;\n CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\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 return (s);\n err:\n if (s != NULL)\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 i = CRYPTO_add(&s->references, -1, CRYPTO_LOCK_SSL);\n#ifdef REF_PRINT\n REF_PRINT("SSL", s);\n#endif\n if (i > 0)\n return;\n#ifdef REF_CHECK\n if (i < 0) {\n fprintf(stderr, "SSL_free, bad reference count\\n");\n abort();\n }\n#endif\n if (s->param)\n X509_VERIFY_PARAM_free(s->param);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n if (s->bbio != NULL) {\n if (s->bbio == s->wbio) {\n s->wbio = BIO_pop(s->wbio);\n }\n BIO_free(s->bbio);\n s->bbio = NULL;\n }\n if (s->rbio != NULL)\n BIO_free_all(s->rbio);\n if ((s->wbio != NULL) && (s->wbio != s->rbio))\n BIO_free_all(s->wbio);\n if (s->init_buf != NULL)\n BUF_MEM_free(s->init_buf);\n if (s->cipher_list != NULL)\n sk_SSL_CIPHER_free(s->cipher_list);\n if (s->cipher_list_by_id != NULL)\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 ssl_clear_cipher_ctx(s);\n ssl_clear_hash_ctx(&s->read_hash);\n ssl_clear_hash_ctx(&s->write_hash);\n if (s->cert != NULL)\n ssl_cert_free(s->cert);\n#ifndef OPENSSL_NO_TLSEXT\n if (s->tlsext_hostname)\n OPENSSL_free(s->tlsext_hostname);\n if (s->initial_ctx)\n SSL_CTX_free(s->initial_ctx);\n# ifndef OPENSSL_NO_EC\n if (s->tlsext_ecpointformatlist)\n OPENSSL_free(s->tlsext_ecpointformatlist);\n if (s->tlsext_ellipticcurvelist)\n OPENSSL_free(s->tlsext_ellipticcurvelist);\n# endif\n if (s->tlsext_ocsp_exts)\n sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts, X509_EXTENSION_free);\n if (s->tlsext_ocsp_ids)\n sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);\n if (s->tlsext_ocsp_resp)\n OPENSSL_free(s->tlsext_ocsp_resp);\n if (s->alpn_client_proto_list)\n OPENSSL_free(s->alpn_client_proto_list);\n#endif\n if (s->client_CA != NULL)\n sk_X509_NAME_pop_free(s->client_CA, X509_NAME_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n if (s->ctx)\n SSL_CTX_free(s->ctx);\n#ifndef OPENSSL_NO_KRB5\n if (s->kssl_ctx != NULL)\n kssl_ctx_free(s->kssl_ctx);\n#endif\n#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)\n if (s->next_proto_negotiated)\n OPENSSL_free(s->next_proto_negotiated);\n#endif\n#ifndef OPENSSL_NO_SRTP\n if (s->srtp_profiles)\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n OPENSSL_free(s);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n int i;\n if (a == NULL)\n return;\n i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_SSL_CTX);\n#ifdef REF_PRINT\n REF_PRINT("SSL_CTX", a);\n#endif\n if (i > 0)\n return;\n#ifdef REF_CHECK\n if (i < 0) {\n fprintf(stderr, "SSL_CTX_free, bad reference count\\n");\n abort();\n }\n#endif\n if (a->param)\n X509_VERIFY_PARAM_free(a->param);\n if (a->sessions != NULL)\n SSL_CTX_flush_sessions(a, 0);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n if (a->sessions != NULL)\n lh_SSL_SESSION_free(a->sessions);\n if (a->cert_store != NULL)\n X509_STORE_free(a->cert_store);\n if (a->cipher_list != NULL)\n sk_SSL_CIPHER_free(a->cipher_list);\n if (a->cipher_list_by_id != NULL)\n sk_SSL_CIPHER_free(a->cipher_list_by_id);\n if (a->cert != NULL)\n ssl_cert_free(a->cert);\n if (a->client_CA != NULL)\n sk_X509_NAME_pop_free(a->client_CA, X509_NAME_free);\n if (a->extra_certs != NULL)\n sk_X509_pop_free(a->extra_certs, X509_free);\n a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n if (a->srtp_profiles)\n sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_PSK\n if (a->psk_identity_hint)\n OPENSSL_free(a->psk_identity_hint);\n#endif\n#ifndef OPENSSL_NO_SRP\n SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n if (a->client_cert_engine)\n ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n# ifndef OPENSSL_NO_EC\n if (a->tlsext_ecpointformatlist)\n OPENSSL_free(a->tlsext_ecpointformatlist);\n if (a->tlsext_ellipticcurvelist)\n OPENSSL_free(a->tlsext_ellipticcurvelist);\n# endif\n if (a->alpn_client_proto_list != NULL)\n OPENSSL_free(a->alpn_client_proto_list);\n#endif\n OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n unsigned long i;\n TIMEOUT_PARAM tp;\n tp.ctx = s;\n tp.cache = s->sessions;\n if (tp.cache == NULL)\n return;\n tp.time = t;\n CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n i = CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load;\n CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load = 0;\n lh_SSL_SESSION_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout),\n TIMEOUT_PARAM, &tp);\n CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load = i;\n CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n}', 'void lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)\n{\n doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);\n}', 'static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,\n LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)\n{\n int i;\n LHASH_NODE *a, *n;\n if (lh == NULL)\n return;\n for (i = lh->num_nodes - 1; i >= 0; i--) {\n a = lh->b[i];\n while (a != NULL) {\n n = a->next;\n if (use_arg)\n func_arg(a->data, arg);\n else\n func(a->data);\n a = n;\n }\n }\n}']
2,508
0
https://github.com/openssl/openssl/blob/313fce7b61ecaf5879cf84b256bdd0964134836e/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int gost2001_do_verify(const unsigned char *dgst,int dgst_len,\n\tDSA_SIG *sig, EC_KEY *ec)\n\t{\n\tBN_CTX *ctx=BN_CTX_new();\n\tconst EC_GROUP *group = EC_KEY_get0_group(ec);\n\tBIGNUM *order;\n\tBIGNUM *md = NULL,*e=NULL,*R=NULL,*v=NULL,*z1=NULL,*z2=NULL;\n\tBIGNUM *X=NULL,*tmp=NULL;\n\tEC_POINT *C = NULL;\n\tconst EC_POINT *pub_key=NULL;\n\tint ok=0;\n\tBN_CTX_start(ctx);\n\torder = BN_CTX_get(ctx);\n\te = BN_CTX_get(ctx);\n\tz1 = BN_CTX_get(ctx);\n\tz2 = BN_CTX_get(ctx);\n\ttmp = BN_CTX_get(ctx);\n\tX= BN_CTX_get(ctx);\n\tR=BN_CTX_get(ctx);\n\tv=BN_CTX_get(ctx);\n\tEC_GROUP_get_order(group,order,ctx);\n\tpub_key = EC_KEY_get0_public_key(ec);\n\tif (BN_is_zero(sig->s) || BN_is_zero(sig->r) ||\n\t\t(BN_cmp(sig->s,order)>=1) || (BN_cmp(sig->r,order)>=1))\n\t\t{\n\t\tGOSTerr(GOST_F_GOST_DO_VERIFY,GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);\n\t\tgoto err;\n\t\t}\n\tmd = hashsum2bn(dgst);\n\tBN_mod(e,md,order,ctx);\n#ifdef DEBUG_SIGN\n\tfprintf(stderr,"digest as bignum: ");\n\tBN_print_fp(stderr,md);\n\tfprintf(stderr,"\\ndigest mod q: ");\n\tBN_print_fp(stderr,e);\n#endif\n\tif (BN_is_zero(e)) BN_one(e);\n\tv=BN_mod_inverse(v,e,order,ctx);\n\tBN_mod_mul(z1,sig->s,v,order,ctx);\n\tBN_sub(tmp,order,sig->r);\n\tBN_mod_mul(z2,tmp,v,order,ctx);\n#ifdef DEBUG_SIGN\n\tfprintf(stderr,"\\nInverted digest value: ");\n\tBN_print_fp(stderr,v);\n\tfprintf(stderr,"\\nz1: ");\n\tBN_print_fp(stderr,z1);\n\tfprintf(stderr,"\\nz2: ");\n\tBN_print_fp(stderr,z2);\n#endif\n\tC = EC_POINT_new(group);\n\tif (!EC_POINT_mul(group,C,z1,pub_key,z2,ctx))\n\t\t{\n\t\tGOSTerr(GOST_F_GOST2001_DO_VERIFY,ERR_R_EC_LIB);\n\t\tgoto err;\n\t\t}\n\tif (!EC_POINT_get_affine_coordinates_GFp(group,C,X,NULL,ctx))\n\t\t{\n\t\tGOSTerr(GOST_F_GOST2001_DO_VERIFY,ERR_R_EC_LIB);\n\t\tgoto err;\n\t\t}\n\tBN_mod(R,X,order,ctx);\n#ifdef DEBUG_SIGN\n\tfprintf(stderr,"\\nX=");\n\tBN_print_fp(stderr,X);\n\tfprintf(stderr,"\\nX mod q=");\n\tBN_print_fp(stderr,R);\n\tfprintf(stderr,"\\n");\n#endif\n\tif (BN_cmp(R,sig->r)!=0)\n\t\t{\n\t\tGOSTerr(GOST_F_GOST2001_DO_VERIFY,GOST_R_SIGNATURE_MISMATCH);\n\t\t}\n\telse\n\t\t{\n\t\tok = 1;\n\t\t}\n\terr:\n\tEC_POINT_free(C);\n\tBN_CTX_end(ctx);\n\tBN_CTX_free(ctx);\n\tBN_free(md);\n\treturn ok;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
2,509
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/mem.c/#L245
void CRYPTO_free(void *str) { #ifdef CRYPTO_MDEBUG if (call_malloc_debug) { CRYPTO_mem_debug_free(str, 0); free(str); CRYPTO_mem_debug_free(str, 1); } else { free(str); } #else free(str); #endif }
["static int int_x509_param_set_hosts(X509_VERIFY_PARAM *vpm, int mode,\n const char *name, size_t namelen)\n{\n char *copy;\n if (namelen == 0)\n namelen = name ? strlen(name) : 0;\n else if (name && memchr(name, '\\0', namelen > 1 ? namelen - 1 : namelen))\n return 0;\n if (name && name[namelen - 1] == '\\0')\n --namelen;\n if (mode == SET_HOST) {\n sk_OPENSSL_STRING_pop_free(vpm->hosts, str_free);\n vpm->hosts = NULL;\n }\n if (name == NULL || namelen == 0)\n return 1;\n copy = OPENSSL_strndup(name, namelen);\n if (copy == NULL)\n return 0;\n if (vpm->hosts == NULL &&\n (vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {\n OPENSSL_free(copy);\n return 0;\n }\n if (!sk_OPENSSL_STRING_push(vpm->hosts, copy)) {\n OPENSSL_free(copy);\n if (sk_OPENSSL_STRING_num(vpm->hosts) == 0) {\n sk_OPENSSL_STRING_free(vpm->hosts);\n vpm->hosts = NULL;\n }\n return 0;\n }\n return 1;\n}", 'DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)', 'int sk_push(_STACK *st, void *data)\n{\n return (sk_insert(st, data, st->num));\n}', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n char **s;\n if (st == NULL)\n return 0;\n if (st->num_alloc <= st->num + 1) {\n s = OPENSSL_realloc((char *)st->data,\n (unsigned int)sizeof(char *) * st->num_alloc * 2);\n if (s == NULL)\n return (0);\n st->data = s;\n st->num_alloc *= 2;\n }\n if ((loc >= (int)st->num) || (loc < 0))\n st->data[st->num] = data;\n else {\n memmove(&(st->data[loc + 1]),\n &(st->data[loc]), sizeof(char *) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return (st->num);\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str);\n return NULL;\n }\n allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)file;\n (void)line;\n#endif\n return realloc(str, num);\n}', 'void CRYPTO_free(void *str)\n{\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0);\n free(str);\n CRYPTO_mem_debug_free(str, 1);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
2,510
0
https://github.com/openssl/openssl/blob/fbb7b33b28e3026c7443339c1f300ef725e2ff50/ssl/statem/statem_clnt.c/#L2774
static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt, int *al) { #ifndef OPENSSL_NO_RSA unsigned char *encdata = NULL; EVP_PKEY *pkey = NULL; EVP_PKEY_CTX *pctx = NULL; size_t enclen; unsigned char *pms = NULL; size_t pmslen = 0; if (s->session->peer == NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR); return 0; } pkey = X509_get0_pubkey(s->session->peer); if (EVP_PKEY_get0_RSA(pkey) == NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR); return 0; } pmslen = SSL_MAX_MASTER_KEY_LENGTH; pms = OPENSSL_malloc(pmslen); if (pms == NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE); *al = SSL_AD_INTERNAL_ERROR; return 0; } pms[0] = s->client_version >> 8; pms[1] = s->client_version & 0xff; if (ssl_randbytes(s, pms + 2, (int)(pmslen - 2)) <= 0) { goto err; } if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) { SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR); goto err; } pctx = EVP_PKEY_CTX_new(pkey, NULL); if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0 || EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) { SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_EVP_LIB); goto err; } if (!WPACKET_allocate_bytes(pkt, enclen, &encdata) || EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) { SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, SSL_R_BAD_RSA_ENCRYPT); goto err; } EVP_PKEY_CTX_free(pctx); pctx = NULL; if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) { SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR); goto err; } if (!ssl_log_rsa_client_key_exchange(s, encdata, enclen, pms, pmslen)) goto err; s->s3->tmp.pms = pms; s->s3->tmp.pmslen = pmslen; return 1; err: OPENSSL_clear_free(pms, pmslen); EVP_PKEY_CTX_free(pctx); return 0; #else SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR); *al = SSL_AD_INTERNAL_ERROR; return 0; #endif }
['static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt, int *al)\n{\n#ifndef OPENSSL_NO_RSA\n unsigned char *encdata = NULL;\n EVP_PKEY *pkey = NULL;\n EVP_PKEY_CTX *pctx = NULL;\n size_t enclen;\n unsigned char *pms = NULL;\n size_t pmslen = 0;\n if (s->session->peer == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pkey = X509_get0_pubkey(s->session->peer);\n if (EVP_PKEY_get0_RSA(pkey) == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pmslen = SSL_MAX_MASTER_KEY_LENGTH;\n pms = OPENSSL_malloc(pmslen);\n if (pms == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);\n *al = SSL_AD_INTERNAL_ERROR;\n return 0;\n }\n pms[0] = s->client_version >> 8;\n pms[1] = s->client_version & 0xff;\n if (ssl_randbytes(s, pms + 2, (int)(pmslen - 2)) <= 0) {\n goto err;\n }\n if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n pctx = EVP_PKEY_CTX_new(pkey, NULL);\n if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0\n || EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_EVP_LIB);\n goto err;\n }\n if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)\n || EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, SSL_R_BAD_RSA_ENCRYPT);\n goto err;\n }\n EVP_PKEY_CTX_free(pctx);\n pctx = NULL;\n if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!ssl_log_rsa_client_key_exchange(s, encdata, enclen, pms, pmslen))\n goto err;\n s->s3->tmp.pms = pms;\n s->s3->tmp.pmslen = pmslen;\n return 1;\n err:\n OPENSSL_clear_free(pms, pmslen);\n EVP_PKEY_CTX_free(pctx);\n return 0;\n#else\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n *al = SSL_AD_INTERNAL_ERROR;\n return 0;\n#endif\n}', 'EVP_PKEY *X509_get0_pubkey(const X509 *x)\n{\n if (x == NULL)\n return NULL;\n return X509_PUBKEY_get0(x->cert_info.key);\n}', 'EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)\n{\n EVP_PKEY *ret = NULL;\n if (key == NULL || key->public_key == NULL)\n return NULL;\n if (key->pkey != NULL)\n return key->pkey;\n x509_pubkey_decode(&ret, key);\n if (ret != NULL) {\n X509err(X509_F_X509_PUBKEY_GET0, ERR_R_INTERNAL_ERROR);\n EVP_PKEY_free(ret);\n }\n return NULL;\n}', 'static int x509_pubkey_decode(EVP_PKEY **ppkey, X509_PUBKEY *key)\n {\n EVP_PKEY *pkey = EVP_PKEY_new();\n if (pkey == NULL) {\n X509err(X509_F_X509_PUBKEY_DECODE, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n if (!EVP_PKEY_set_type(pkey, OBJ_obj2nid(key->algor->algorithm))) {\n X509err(X509_F_X509_PUBKEY_DECODE, X509_R_UNSUPPORTED_ALGORITHM);\n goto error;\n }\n if (pkey->ameth->pub_decode) {\n if (!pkey->ameth->pub_decode(pkey, key)) {\n X509err(X509_F_X509_PUBKEY_DECODE, X509_R_PUBLIC_KEY_DECODE_ERROR);\n goto error;\n }\n } else {\n X509err(X509_F_X509_PUBKEY_DECODE, X509_R_METHOD_NOT_SUPPORTED);\n goto error;\n }\n *ppkey = pkey;\n return 1;\n error:\n EVP_PKEY_free(pkey);\n return 0;\n}', 'RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)\n{\n if (pkey->type != EVP_PKEY_RSA) {\n EVPerr(EVP_F_EVP_PKEY_GET0_RSA, EVP_R_EXPECTING_AN_RSA_KEY);\n return NULL;\n }\n return pkey->pkey.rsa;\n}']
2,511
0
https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/test/handshake_helper.c/#L112
static int select_server_ctx(SSL *s, void *arg, int ignore) { const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name); HANDSHAKE_EX_DATA *ex_data = (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx)); if (servername == NULL) { ex_data->servername = SSL_TEST_SERVERNAME_SERVER1; return SSL_TLSEXT_ERR_NOACK; } if (strcmp(servername, "server2") == 0) { SSL_CTX *new_ctx = (SSL_CTX*)arg; SSL_set_SSL_CTX(s, new_ctx); SSL_clear_options(s, 0xFFFFFFFFL); SSL_set_options(s, SSL_CTX_get_options(new_ctx)); ex_data->servername = SSL_TEST_SERVERNAME_SERVER2; return SSL_TLSEXT_ERR_OK; } else if (strcmp(servername, "server1") == 0) { ex_data->servername = SSL_TEST_SERVERNAME_SERVER1; return SSL_TLSEXT_ERR_OK; } else if (ignore) { ex_data->servername = SSL_TEST_SERVERNAME_SERVER1; return SSL_TLSEXT_ERR_NOACK; } else { return SSL_TLSEXT_ERR_ALERT_FATAL; } }
['static int select_server_ctx(SSL *s, void *arg, int ignore)\n{\n const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);\n HANDSHAKE_EX_DATA *ex_data =\n (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n if (servername == NULL) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_NOACK;\n }\n if (strcmp(servername, "server2") == 0) {\n SSL_CTX *new_ctx = (SSL_CTX*)arg;\n SSL_set_SSL_CTX(s, new_ctx);\n SSL_clear_options(s, 0xFFFFFFFFL);\n SSL_set_options(s, SSL_CTX_get_options(new_ctx));\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;\n return SSL_TLSEXT_ERR_OK;\n } else if (strcmp(servername, "server1") == 0) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_OK;\n } else if (ignore) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_NOACK;\n } else {\n return SSL_TLSEXT_ERR_ALERT_FATAL;\n }\n}', 'const char *SSL_get_servername(const SSL *s, const int type)\n{\n if (type != TLSEXT_NAMETYPE_host_name)\n return NULL;\n return s->session && !s->tlsext_hostname ?\n s->session->tlsext_hostname : s->tlsext_hostname;\n}', 'void *SSL_get_ex_data(const SSL *s, int idx)\n{\n return (CRYPTO_get_ex_data(&s->ex_data, idx));\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n return NULL;\n return sk_void_value(ad->sk, idx);\n}', 'SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx)\n{\n CERT *new_cert;\n if (ssl->ctx == ctx)\n return ssl->ctx;\n if (ctx == NULL)\n ctx = ssl->initial_ctx;\n new_cert = ssl_cert_dup(ctx->cert);\n if (new_cert == NULL) {\n return NULL;\n }\n ssl_cert_free(ssl->cert);\n ssl->cert = new_cert;\n OPENSSL_assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx));\n if ((ssl->ctx != NULL) &&\n (ssl->sid_ctx_length == ssl->ctx->sid_ctx_length) &&\n (memcmp(ssl->sid_ctx, ssl->ctx->sid_ctx, ssl->sid_ctx_length) == 0)) {\n ssl->sid_ctx_length = ctx->sid_ctx_length;\n memcpy(&ssl->sid_ctx, &ctx->sid_ctx, sizeof(ssl->sid_ctx));\n }\n SSL_CTX_up_ref(ctx);\n SSL_CTX_free(ssl->ctx);\n ssl->ctx = ctx;\n return ssl->ctx;\n}', 'unsigned long SSL_clear_options(SSL *s, unsigned long op)\n{\n return s->options &= ~op;\n}', 'unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)\n{\n return ctx->options;\n}', 'unsigned long SSL_set_options(SSL *s, unsigned long op)\n{\n return s->options |= op;\n}']
2,512
0
https://github.com/libav/libav/blob/41874d0a5df35732367f0c675eac914c23d65aee/libavcodec/ra144enc.c/#L204
static int adaptive_cb_search(const int16_t *adapt_cb, float *work, const float *coefs, float *data) { int i, best_vect; float score, gain, best_score, best_gain; float exc[BLOCKSIZE]; gain = best_score = 0; for (i = BLOCKSIZE / 2; i <= BUFFERSIZE; i++) { create_adapt_vect(exc, adapt_cb, i); get_match_score(work, coefs, exc, NULL, NULL, data, &score, &gain); if (score > best_score) { best_score = score; best_vect = i; best_gain = gain; } } if (!best_score) return 0; create_adapt_vect(exc, adapt_cb, best_vect); ff_celp_lp_synthesis_filterf(work, coefs, exc, BLOCKSIZE, LPC_ORDER); for (i = 0; i < BLOCKSIZE; i++) data[i] -= best_gain * work[i]; return (best_vect - BLOCKSIZE / 2 + 1); }
['static int adaptive_cb_search(const int16_t *adapt_cb, float *work,\n const float *coefs, float *data)\n{\n int i, best_vect;\n float score, gain, best_score, best_gain;\n float exc[BLOCKSIZE];\n gain = best_score = 0;\n for (i = BLOCKSIZE / 2; i <= BUFFERSIZE; i++) {\n create_adapt_vect(exc, adapt_cb, i);\n get_match_score(work, coefs, exc, NULL, NULL, data, &score, &gain);\n if (score > best_score) {\n best_score = score;\n best_vect = i;\n best_gain = gain;\n }\n }\n if (!best_score)\n return 0;\n create_adapt_vect(exc, adapt_cb, best_vect);\n ff_celp_lp_synthesis_filterf(work, coefs, exc, BLOCKSIZE, LPC_ORDER);\n for (i = 0; i < BLOCKSIZE; i++)\n data[i] -= best_gain * work[i];\n return (best_vect - BLOCKSIZE / 2 + 1);\n}']
2,513
0
https://github.com/openssl/openssl/blob/4b8515baa6edef1a771f9e4e3fbc0395b4a629e8/crypto/bn/bn_lib.c/#L271
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['static int dh_builtin_genparams(DH *ret, int prime_len, int generator,\n BN_GENCB *cb)\n{\n BIGNUM *t1, *t2;\n int g, ok = -1;\n BN_CTX *ctx = NULL;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\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 (!ret->p && ((ret->p = BN_new()) == NULL))\n goto err;\n if (!ret->g && ((ret->g = BN_new()) == NULL))\n goto err;\n if (generator <= 1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);\n goto err;\n }\n if (generator == DH_GENERATOR_2) {\n if (!BN_set_word(t1, 24))\n goto err;\n if (!BN_set_word(t2, 11))\n goto err;\n g = 2;\n } else if (generator == DH_GENERATOR_5) {\n if (!BN_set_word(t1, 10))\n goto err;\n if (!BN_set_word(t2, 3))\n goto err;\n g = 5;\n } else {\n if (!BN_set_word(t1, 2))\n goto err;\n if (!BN_set_word(t2, 1))\n goto err;\n g = generator;\n }\n if (!BN_generate_prime_ex(ret->p, prime_len, 1, t1, t2, cb))\n goto err;\n if (!BN_GENCB_call(cb, 3, 0))\n goto err;\n if (!BN_set_word(ret->g, g))\n goto err;\n ok = 1;\n err:\n if (ok == -1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, ERR_R_BN_LIB);\n ok = 0;\n }\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return ok;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = 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}']
2,514
0
https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/ssl/s3_cbc.c/#L407
int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx, unsigned char *md_out, size_t *md_out_size, const unsigned char header[13], const unsigned char *data, size_t data_plus_mac_size, size_t data_plus_mac_plus_padding_size, const unsigned char *mac_secret, unsigned mac_secret_length, char is_sslv3) { union { double align; unsigned char c[sizeof(LARGEST_DIGEST_CTX)]; } md_state; void (*md_final_raw) (void *ctx, unsigned char *md_out); void (*md_transform) (void *ctx, const unsigned char *block); unsigned md_size, md_block_size = 64; unsigned sslv3_pad_length = 40, header_length, variance_blocks, len, max_mac_bytes, num_blocks, num_starting_blocks, k, mac_end_offset, c, index_a, index_b; unsigned int bits; unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES]; unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE]; unsigned char first_block[MAX_HASH_BLOCK_SIZE]; unsigned char mac_out[EVP_MAX_MD_SIZE]; unsigned i, j, md_out_size_u; EVP_MD_CTX *md_ctx = NULL; unsigned md_length_size = 8; char length_is_big_endian = 1; int ret; OPENSSL_assert(data_plus_mac_plus_padding_size < 1024 * 1024); switch (EVP_MD_CTX_type(ctx)) { case NID_md5: if (MD5_Init((MD5_CTX *)md_state.c) <= 0) return 0; md_final_raw = tls1_md5_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))MD5_Transform; md_size = 16; sslv3_pad_length = 48; length_is_big_endian = 0; break; case NID_sha1: if (SHA1_Init((SHA_CTX *)md_state.c) <= 0) return 0; md_final_raw = tls1_sha1_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))SHA1_Transform; md_size = 20; break; case NID_sha224: if (SHA224_Init((SHA256_CTX *)md_state.c) <= 0) return 0; md_final_raw = tls1_sha256_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))SHA256_Transform; md_size = 224 / 8; break; case NID_sha256: if (SHA256_Init((SHA256_CTX *)md_state.c) <= 0) return 0; md_final_raw = tls1_sha256_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))SHA256_Transform; md_size = 32; break; case NID_sha384: if (SHA384_Init((SHA512_CTX *)md_state.c) <= 0) return 0; md_final_raw = tls1_sha512_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))SHA512_Transform; md_size = 384 / 8; md_block_size = 128; md_length_size = 16; break; case NID_sha512: if (SHA512_Init((SHA512_CTX *)md_state.c) <= 0) return 0; md_final_raw = tls1_sha512_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))SHA512_Transform; md_size = 64; md_block_size = 128; md_length_size = 16; break; default: OPENSSL_assert(0); if (md_out_size) *md_out_size = 0; return 0; } OPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES); OPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE); OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE); header_length = 13; if (is_sslv3) { header_length = mac_secret_length + sslv3_pad_length + 8 + 1 + 2 ; } variance_blocks = is_sslv3 ? 2 : 6; len = data_plus_mac_plus_padding_size + header_length; max_mac_bytes = len - md_size - 1; num_blocks = (max_mac_bytes + 1 + md_length_size + md_block_size - 1) / md_block_size; num_starting_blocks = 0; k = 0; mac_end_offset = data_plus_mac_size + header_length - md_size; c = mac_end_offset % md_block_size; index_a = mac_end_offset / md_block_size; index_b = (mac_end_offset + md_length_size) / md_block_size; if (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0)) { num_starting_blocks = num_blocks - variance_blocks; k = md_block_size * num_starting_blocks; } bits = 8 * mac_end_offset; if (!is_sslv3) { bits += 8 * md_block_size; memset(hmac_pad, 0, md_block_size); OPENSSL_assert(mac_secret_length <= sizeof(hmac_pad)); memcpy(hmac_pad, mac_secret, mac_secret_length); for (i = 0; i < md_block_size; i++) hmac_pad[i] ^= 0x36; md_transform(md_state.c, hmac_pad); } if (length_is_big_endian) { memset(length_bytes, 0, md_length_size - 4); length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24); length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16); length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8); length_bytes[md_length_size - 1] = (unsigned char)bits; } else { memset(length_bytes, 0, md_length_size); length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24); length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16); length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8); length_bytes[md_length_size - 8] = (unsigned char)bits; } if (k > 0) { if (is_sslv3) { unsigned overhang; if (header_length <= md_block_size) { return 0; } overhang = header_length - md_block_size; md_transform(md_state.c, header); memcpy(first_block, header + md_block_size, overhang); memcpy(first_block + overhang, data, md_block_size - overhang); md_transform(md_state.c, first_block); for (i = 1; i < k / md_block_size - 1; i++) md_transform(md_state.c, data + md_block_size * i - overhang); } else { memcpy(first_block, header, 13); memcpy(first_block + 13, data, md_block_size - 13); md_transform(md_state.c, first_block); for (i = 1; i < k / md_block_size; i++) md_transform(md_state.c, data + md_block_size * i - 13); } } memset(mac_out, 0, sizeof(mac_out)); for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks; i++) { unsigned char block[MAX_HASH_BLOCK_SIZE]; unsigned char is_block_a = constant_time_eq_8(i, index_a); unsigned char is_block_b = constant_time_eq_8(i, index_b); for (j = 0; j < md_block_size; j++) { unsigned char b = 0, is_past_c, is_past_cp1; if (k < header_length) b = header[k]; else if (k < data_plus_mac_plus_padding_size + header_length) b = data[k - header_length]; k++; is_past_c = is_block_a & constant_time_ge_8(j, c); is_past_cp1 = is_block_a & constant_time_ge_8(j, c + 1); b = constant_time_select_8(is_past_c, 0x80, b); b = b & ~is_past_cp1; b &= ~is_block_b | is_block_a; if (j >= md_block_size - md_length_size) { b = constant_time_select_8(is_block_b, length_bytes[j - (md_block_size - md_length_size)], b); } block[j] = b; } md_transform(md_state.c, block); md_final_raw(md_state.c, block); for (j = 0; j < md_size; j++) mac_out[j] |= block[j] & is_block_b; } md_ctx = EVP_MD_CTX_new(); if (md_ctx == NULL) goto err; if (EVP_DigestInit_ex(md_ctx, EVP_MD_CTX_md(ctx), NULL ) <= 0) goto err; if (is_sslv3) { memset(hmac_pad, 0x5c, sslv3_pad_length); if (EVP_DigestUpdate(md_ctx, mac_secret, mac_secret_length) <= 0 || EVP_DigestUpdate(md_ctx, hmac_pad, sslv3_pad_length) <= 0 || EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0) goto err; } else { for (i = 0; i < md_block_size; i++) hmac_pad[i] ^= 0x6a; if (EVP_DigestUpdate(md_ctx, hmac_pad, md_block_size) <= 0 || EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0) goto err; } ret = EVP_DigestFinal(md_ctx, md_out, &md_out_size_u); if (ret && md_out_size) *md_out_size = md_out_size_u; EVP_MD_CTX_free(md_ctx); return 1; err: EVP_MD_CTX_free(md_ctx); return 0; }
['int tls1_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int send)\n{\n unsigned char *seq;\n EVP_MD_CTX *hash;\n size_t md_size;\n int i;\n EVP_MD_CTX *hmac = NULL, *mac_ctx;\n unsigned char header[13];\n int stream_mac = (send ? (ssl->mac_flags & SSL_MAC_FLAG_WRITE_MAC_STREAM)\n : (ssl->mac_flags & SSL_MAC_FLAG_READ_MAC_STREAM));\n int t;\n if (send) {\n seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);\n hash = ssl->write_hash;\n } else {\n seq = RECORD_LAYER_get_read_sequence(&ssl->rlayer);\n hash = ssl->read_hash;\n }\n t = EVP_MD_CTX_size(hash);\n OPENSSL_assert(t >= 0);\n md_size = t;\n if (stream_mac) {\n mac_ctx = hash;\n } else {\n hmac = EVP_MD_CTX_new();\n if (hmac == NULL || !EVP_MD_CTX_copy(hmac, hash))\n return -1;\n mac_ctx = hmac;\n }\n if (SSL_IS_DTLS(ssl)) {\n unsigned char dtlsseq[8], *p = dtlsseq;\n s2n(send ? DTLS_RECORD_LAYER_get_w_epoch(&ssl->rlayer) :\n DTLS_RECORD_LAYER_get_r_epoch(&ssl->rlayer), p);\n memcpy(p, &seq[2], 6);\n memcpy(header, dtlsseq, 8);\n } else\n memcpy(header, seq, 8);\n header[8] = rec->type;\n header[9] = (unsigned char)(ssl->version >> 8);\n header[10] = (unsigned char)(ssl->version);\n header[11] = (rec->length) >> 8;\n header[12] = (rec->length) & 0xff;\n if (!send && !SSL_USE_ETM(ssl) &&\n EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n ssl3_cbc_record_digest_supported(mac_ctx)) {\n if (ssl3_cbc_digest_record(mac_ctx,\n md, &md_size,\n header, rec->input,\n rec->length + md_size, rec->orig_len,\n ssl->s3->read_mac_secret,\n ssl->s3->read_mac_secret_size, 0) <= 0) {\n EVP_MD_CTX_free(hmac);\n return -1;\n }\n } else {\n if (EVP_DigestSignUpdate(mac_ctx, header, sizeof(header)) <= 0\n || EVP_DigestSignUpdate(mac_ctx, rec->input, rec->length) <= 0\n || EVP_DigestSignFinal(mac_ctx, md, &md_size) <= 0) {\n EVP_MD_CTX_free(hmac);\n return -1;\n }\n if (!send && !SSL_USE_ETM(ssl) && FIPS_mode())\n if (!tls_fips_digest_extra(ssl->enc_read_ctx,\n mac_ctx, rec->input,\n rec->length, rec->orig_len)) {\n EVP_MD_CTX_free(hmac);\n return -1;\n }\n }\n EVP_MD_CTX_free(hmac);\n#ifdef SSL_DEBUG\n fprintf(stderr, "seq=");\n {\n int z;\n for (z = 0; z < 8; z++)\n fprintf(stderr, "%02X ", seq[z]);\n fprintf(stderr, "\\n");\n }\n fprintf(stderr, "rec=");\n {\n unsigned int z;\n for (z = 0; z < rec->length; z++)\n fprintf(stderr, "%02X ", rec->data[z]);\n fprintf(stderr, "\\n");\n }\n#endif\n if (!SSL_IS_DTLS(ssl)) {\n for (i = 7; i >= 0; i--) {\n ++seq[i];\n if (seq[i] != 0)\n break;\n }\n }\n#ifdef SSL_DEBUG\n {\n unsigned int z;\n for (z = 0; z < md_size; z++)\n fprintf(stderr, "%02X ", md[z]);\n fprintf(stderr, "\\n");\n }\n#endif\n return (md_size);\n}', 'int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx,\n unsigned char *md_out,\n size_t *md_out_size,\n const unsigned char header[13],\n const unsigned char *data,\n size_t data_plus_mac_size,\n size_t data_plus_mac_plus_padding_size,\n const unsigned char *mac_secret,\n unsigned mac_secret_length, char is_sslv3)\n{\n union {\n double align;\n unsigned char c[sizeof(LARGEST_DIGEST_CTX)];\n } md_state;\n void (*md_final_raw) (void *ctx, unsigned char *md_out);\n void (*md_transform) (void *ctx, const unsigned char *block);\n unsigned md_size, md_block_size = 64;\n unsigned sslv3_pad_length = 40, header_length, variance_blocks,\n len, max_mac_bytes, num_blocks,\n num_starting_blocks, k, mac_end_offset, c, index_a, index_b;\n unsigned int bits;\n unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];\n unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];\n unsigned char first_block[MAX_HASH_BLOCK_SIZE];\n unsigned char mac_out[EVP_MAX_MD_SIZE];\n unsigned i, j, md_out_size_u;\n EVP_MD_CTX *md_ctx = NULL;\n unsigned md_length_size = 8;\n char length_is_big_endian = 1;\n int ret;\n OPENSSL_assert(data_plus_mac_plus_padding_size < 1024 * 1024);\n switch (EVP_MD_CTX_type(ctx)) {\n case NID_md5:\n if (MD5_Init((MD5_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_md5_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))MD5_Transform;\n md_size = 16;\n sslv3_pad_length = 48;\n length_is_big_endian = 0;\n break;\n case NID_sha1:\n if (SHA1_Init((SHA_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha1_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA1_Transform;\n md_size = 20;\n break;\n case NID_sha224:\n if (SHA224_Init((SHA256_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha256_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;\n md_size = 224 / 8;\n break;\n case NID_sha256:\n if (SHA256_Init((SHA256_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha256_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;\n md_size = 32;\n break;\n case NID_sha384:\n if (SHA384_Init((SHA512_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha512_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;\n md_size = 384 / 8;\n md_block_size = 128;\n md_length_size = 16;\n break;\n case NID_sha512:\n if (SHA512_Init((SHA512_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha512_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;\n md_size = 64;\n md_block_size = 128;\n md_length_size = 16;\n break;\n default:\n OPENSSL_assert(0);\n if (md_out_size)\n *md_out_size = 0;\n return 0;\n }\n OPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES);\n OPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE);\n OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);\n header_length = 13;\n if (is_sslv3) {\n header_length = mac_secret_length + sslv3_pad_length + 8 +\n 1 +\n 2 ;\n }\n variance_blocks = is_sslv3 ? 2 : 6;\n len = data_plus_mac_plus_padding_size + header_length;\n max_mac_bytes = len - md_size - 1;\n num_blocks =\n (max_mac_bytes + 1 + md_length_size + md_block_size -\n 1) / md_block_size;\n num_starting_blocks = 0;\n k = 0;\n mac_end_offset = data_plus_mac_size + header_length - md_size;\n c = mac_end_offset % md_block_size;\n index_a = mac_end_offset / md_block_size;\n index_b = (mac_end_offset + md_length_size) / md_block_size;\n if (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0)) {\n num_starting_blocks = num_blocks - variance_blocks;\n k = md_block_size * num_starting_blocks;\n }\n bits = 8 * mac_end_offset;\n if (!is_sslv3) {\n bits += 8 * md_block_size;\n memset(hmac_pad, 0, md_block_size);\n OPENSSL_assert(mac_secret_length <= sizeof(hmac_pad));\n memcpy(hmac_pad, mac_secret, mac_secret_length);\n for (i = 0; i < md_block_size; i++)\n hmac_pad[i] ^= 0x36;\n md_transform(md_state.c, hmac_pad);\n }\n if (length_is_big_endian) {\n memset(length_bytes, 0, md_length_size - 4);\n length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24);\n length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16);\n length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8);\n length_bytes[md_length_size - 1] = (unsigned char)bits;\n } else {\n memset(length_bytes, 0, md_length_size);\n length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24);\n length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16);\n length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8);\n length_bytes[md_length_size - 8] = (unsigned char)bits;\n }\n if (k > 0) {\n if (is_sslv3) {\n unsigned overhang;\n if (header_length <= md_block_size) {\n return 0;\n }\n overhang = header_length - md_block_size;\n md_transform(md_state.c, header);\n memcpy(first_block, header + md_block_size, overhang);\n memcpy(first_block + overhang, data, md_block_size - overhang);\n md_transform(md_state.c, first_block);\n for (i = 1; i < k / md_block_size - 1; i++)\n md_transform(md_state.c, data + md_block_size * i - overhang);\n } else {\n memcpy(first_block, header, 13);\n memcpy(first_block + 13, data, md_block_size - 13);\n md_transform(md_state.c, first_block);\n for (i = 1; i < k / md_block_size; i++)\n md_transform(md_state.c, data + md_block_size * i - 13);\n }\n }\n memset(mac_out, 0, sizeof(mac_out));\n for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks;\n i++) {\n unsigned char block[MAX_HASH_BLOCK_SIZE];\n unsigned char is_block_a = constant_time_eq_8(i, index_a);\n unsigned char is_block_b = constant_time_eq_8(i, index_b);\n for (j = 0; j < md_block_size; j++) {\n unsigned char b = 0, is_past_c, is_past_cp1;\n if (k < header_length)\n b = header[k];\n else if (k < data_plus_mac_plus_padding_size + header_length)\n b = data[k - header_length];\n k++;\n is_past_c = is_block_a & constant_time_ge_8(j, c);\n is_past_cp1 = is_block_a & constant_time_ge_8(j, c + 1);\n b = constant_time_select_8(is_past_c, 0x80, b);\n b = b & ~is_past_cp1;\n b &= ~is_block_b | is_block_a;\n if (j >= md_block_size - md_length_size) {\n b = constant_time_select_8(is_block_b,\n length_bytes[j -\n (md_block_size -\n md_length_size)], b);\n }\n block[j] = b;\n }\n md_transform(md_state.c, block);\n md_final_raw(md_state.c, block);\n for (j = 0; j < md_size; j++)\n mac_out[j] |= block[j] & is_block_b;\n }\n md_ctx = EVP_MD_CTX_new();\n if (md_ctx == NULL)\n goto err;\n if (EVP_DigestInit_ex(md_ctx, EVP_MD_CTX_md(ctx), NULL ) <= 0)\n goto err;\n if (is_sslv3) {\n memset(hmac_pad, 0x5c, sslv3_pad_length);\n if (EVP_DigestUpdate(md_ctx, mac_secret, mac_secret_length) <= 0\n || EVP_DigestUpdate(md_ctx, hmac_pad, sslv3_pad_length) <= 0\n || EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0)\n goto err;\n } else {\n for (i = 0; i < md_block_size; i++)\n hmac_pad[i] ^= 0x6a;\n if (EVP_DigestUpdate(md_ctx, hmac_pad, md_block_size) <= 0\n || EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0)\n goto err;\n }\n ret = EVP_DigestFinal(md_ctx, md_out, &md_out_size_u);\n if (ret && md_out_size)\n *md_out_size = md_out_size_u;\n EVP_MD_CTX_free(md_ctx);\n return 1;\n err:\n EVP_MD_CTX_free(md_ctx);\n return 0;\n}']
2,515
0
https://github.com/openssl/openssl/blob/97d5809c2b70fdd240990b940c564bcbd77a19c6/crypto/constant_time_locl.h/#L137
static inline unsigned int constant_time_lt(unsigned int a, unsigned int b) { return constant_time_msb(a^((a^b)|((a-b)^b))); }
['int tls1_cbc_remove_padding(const SSL* s,\n\t\t\t SSL3_RECORD *rec,\n\t\t\t unsigned block_size,\n\t\t\t unsigned mac_size)\n\t{\n\tunsigned padding_length, good, to_check, i;\n\tconst unsigned overhead = 1 + mac_size;\n\tif (SSL_USE_EXPLICIT_IV(s))\n\t\t{\n\t\tif (overhead + block_size > rec->length)\n\t\t\treturn 0;\n\t\trec->data += block_size;\n\t\trec->input += block_size;\n\t\trec->length -= block_size;\n\t\trec->orig_len -= block_size;\n\t\t}\n\telse if (overhead > rec->length)\n\t\treturn 0;\n\tpadding_length = rec->data[rec->length-1];\n\tif ( (s->options&SSL_OP_TLS_BLOCK_PADDING_BUG) && !s->expand)\n\t\t{\n\t\tif ((memcmp(s->s3->read_sequence, "\\0\\0\\0\\0\\0\\0\\0\\0",8) == 0) &&\n\t\t !(padding_length & 1))\n\t\t\t{\n\t\t\ts->s3->flags|=TLS1_FLAGS_TLS_PADDING_BUG;\n\t\t\t}\n\t\tif ((s->s3->flags & TLS1_FLAGS_TLS_PADDING_BUG) &&\n\t\t padding_length > 0)\n\t\t\t{\n\t\t\tpadding_length--;\n\t\t\t}\n\t\t}\n\tif (EVP_CIPHER_flags(s->enc_read_ctx->cipher)&EVP_CIPH_FLAG_AEAD_CIPHER)\n\t\t{\n\t\trec->length -= padding_length + 1;\n\t\treturn 1;\n\t\t}\n\tgood = constant_time_ge(rec->length, overhead+padding_length);\n\tto_check = 255;\n\tif (to_check > rec->length-1)\n\t\tto_check = rec->length-1;\n\tfor (i = 0; i < to_check; i++)\n\t\t{\n\t\tunsigned char mask = constant_time_ge_8(padding_length, i);\n\t\tunsigned char b = rec->data[rec->length-1-i];\n\t\tgood &= ~(mask&(padding_length ^ b));\n\t\t}\n\tgood = constant_time_eq(0xff, good & 0xff);\n\trec->length -= good & (padding_length+1);\n\treturn constant_time_select_int(good, 1, -1);\n\t}', 'static inline unsigned char constant_time_ge_8(unsigned int a, unsigned int b)\n\t{\n\treturn (unsigned char)(constant_time_ge(a, b));\n\t}', 'static inline unsigned int constant_time_ge(unsigned int a, unsigned int b)\n\t{\n\treturn ~constant_time_lt(a, b);\n\t}', 'static inline unsigned int constant_time_lt(unsigned int a, unsigned int b)\n\t{\n\treturn constant_time_msb(a^((a^b)|((a-b)^b)));\n\t}']
2,516
0
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static void jpake_send_step2(BIO *bconn, JPAKE_CTX *ctx)\n\t{\n\tJPAKE_STEP2 s2;\n\tJPAKE_STEP2_init(&s2);\n\tJPAKE_STEP2_generate(&s2, ctx);\n\tjpake_send_part(bconn, &s2);\n\t(void)BIO_flush(bconn);\n\tJPAKE_STEP2_release(&s2);\n\t}', 'int JPAKE_STEP2_generate(JPAKE_STEP2 *send, JPAKE_CTX *ctx)\n {\n BIGNUM *t1 = BN_new();\n BIGNUM *t2 = BN_new();\n BN_mod_exp(t1, ctx->p.g, ctx->xa, ctx->p.p, ctx->ctx);\n BN_mod_mul(t2, t1, ctx->p.gxc, ctx->p.p, ctx->ctx);\n BN_mod_mul(t1, t2, ctx->p.gxd, ctx->p.p, ctx->ctx);\n BN_mod_mul(t2, ctx->xb, ctx->secret, ctx->p.q, ctx->ctx);\n generate_step_part(send, t2, t1, ctx);\n BN_free(t1);\n BN_free(t2);\n return 1;\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;\n\tsize_t loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tsize_t 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\tsize_t 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+1U)) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,div_n+1U)) 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}']
2,517
0
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/crypto/pkcs12/p12_key.c/#L158
int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int id, int iter, int n, unsigned char *out, const EVP_MD *md_type) { unsigned char *B, *D, *I, *p, *Ai; int Slen, Plen, Ilen, Ijlen; int i, j, u, v; int ret = 0; BIGNUM *Ij, *Bpl1; EVP_MD_CTX ctx; #ifdef DEBUG_KEYGEN unsigned char *tmpout = out; int tmpn = n; #endif EVP_MD_CTX_init(&ctx); #ifdef DEBUG_KEYGEN fprintf(stderr, "KEYGEN DEBUG\n"); fprintf(stderr, "ID %d, ITER %d\n", id, iter); fprintf(stderr, "Password (length %d):\n", passlen); h__dump(pass, passlen); fprintf(stderr, "Salt (length %d):\n", saltlen); h__dump(salt, saltlen); #endif v = EVP_MD_block_size(md_type); u = EVP_MD_size(md_type); if (u < 0) return 0; D = OPENSSL_malloc(v); Ai = OPENSSL_malloc(u); B = OPENSSL_malloc(v + 1); Slen = v * ((saltlen + v - 1) / v); if (passlen) Plen = v * ((passlen + v - 1) / v); else Plen = 0; Ilen = Slen + Plen; I = OPENSSL_malloc(Ilen); Ij = BN_new(); Bpl1 = BN_new(); if (!D || !Ai || !B || !I || !Ij || !Bpl1) goto err; for (i = 0; i < v; i++) D[i] = id; p = I; for (i = 0; i < Slen; i++) *p++ = salt[i % saltlen]; for (i = 0; i < Plen; i++) *p++ = pass[i % passlen]; for (;;) { if (!EVP_DigestInit_ex(&ctx, md_type, NULL) || !EVP_DigestUpdate(&ctx, D, v) || !EVP_DigestUpdate(&ctx, I, Ilen) || !EVP_DigestFinal_ex(&ctx, Ai, NULL)) goto err; for (j = 1; j < iter; j++) { if (!EVP_DigestInit_ex(&ctx, md_type, NULL) || !EVP_DigestUpdate(&ctx, Ai, u) || !EVP_DigestFinal_ex(&ctx, Ai, NULL)) goto err; } memcpy(out, Ai, min(n, u)); if (u >= n) { #ifdef DEBUG_KEYGEN fprintf(stderr, "Output KEY (length %d)\n", tmpn); h__dump(tmpout, tmpn); #endif ret = 1; goto end; } n -= u; out += u; for (j = 0; j < v; j++) B[j] = Ai[j % u]; if (!BN_bin2bn(B, v, Bpl1)) goto err; if (!BN_add_word(Bpl1, 1)) goto err; for (j = 0; j < Ilen; j += v) { if (!BN_bin2bn(I + j, v, Ij)) goto err; if (!BN_add(Ij, Ij, Bpl1)) goto err; if (!BN_bn2bin(Ij, B)) goto err; Ijlen = BN_num_bytes(Ij); if (Ijlen > v) { if (!BN_bn2bin(Ij, B)) goto err; memcpy(I + j, B + 1, v); #ifndef PKCS12_BROKEN_KEYGEN } else if (Ijlen < v) { memset(I + j, 0, v - Ijlen); if (!BN_bn2bin(Ij, I + j + v - Ijlen)) goto err; #endif } else if (!BN_bn2bin(Ij, I + j)) goto err; } } err: PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI, ERR_R_MALLOC_FAILURE); end: OPENSSL_free(Ai); OPENSSL_free(B); OPENSSL_free(D); OPENSSL_free(I); BN_free(Ij); BN_free(Bpl1); EVP_MD_CTX_cleanup(&ctx); return ret; }
['int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,\n unsigned char *mac, unsigned int *maclen)\n{\n const EVP_MD *md_type;\n HMAC_CTX hmac;\n unsigned char key[EVP_MAX_MD_SIZE], *salt;\n int saltlen, iter;\n int md_size;\n if (!PKCS7_type_is_data(p12->authsafes)) {\n PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_CONTENT_TYPE_NOT_DATA);\n return 0;\n }\n salt = p12->mac->salt->data;\n saltlen = p12->mac->salt->length;\n if (!p12->mac->iter)\n iter = 1;\n else\n iter = ASN1_INTEGER_get(p12->mac->iter);\n if ((md_type = EVP_get_digestbyobj(p12->mac->dinfo->algor->algorithm))\n == NULL) {\n PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);\n return 0;\n }\n md_size = EVP_MD_size(md_type);\n if (md_size < 0)\n return 0;\n if (!PKCS12_key_gen(pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter,\n md_size, key, md_type)) {\n PKCS12err(PKCS12_F_PKCS12_GEN_MAC, PKCS12_R_KEY_GEN_ERROR);\n return 0;\n }\n HMAC_CTX_init(&hmac);\n if (!HMAC_Init_ex(&hmac, key, md_size, md_type, NULL)\n || !HMAC_Update(&hmac, p12->authsafes->d.data->data,\n p12->authsafes->d.data->length)\n || !HMAC_Final(&hmac, mac, maclen)) {\n HMAC_CTX_cleanup(&hmac);\n return 0;\n }\n HMAC_CTX_cleanup(&hmac);\n return 1;\n}', 'int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,\n int saltlen, int id, int iter, int n,\n unsigned char *out, const EVP_MD *md_type)\n{\n int ret;\n unsigned char *unipass;\n int uniplen;\n if (!pass) {\n unipass = NULL;\n uniplen = 0;\n } else if (!OPENSSL_asc2uni(pass, passlen, &unipass, &uniplen)) {\n PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen,\n id, iter, n, out, md_type);\n if (ret <= 0)\n return 0;\n OPENSSL_clear_free(unipass, uniplen);\n return ret;\n}', 'int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,\n int saltlen, int id, int iter, int n,\n unsigned char *out, const EVP_MD *md_type)\n{\n unsigned char *B, *D, *I, *p, *Ai;\n int Slen, Plen, Ilen, Ijlen;\n int i, j, u, v;\n int ret = 0;\n BIGNUM *Ij, *Bpl1;\n EVP_MD_CTX ctx;\n#ifdef DEBUG_KEYGEN\n unsigned char *tmpout = out;\n int tmpn = n;\n#endif\n EVP_MD_CTX_init(&ctx);\n#ifdef DEBUG_KEYGEN\n fprintf(stderr, "KEYGEN DEBUG\\n");\n fprintf(stderr, "ID %d, ITER %d\\n", id, iter);\n fprintf(stderr, "Password (length %d):\\n", passlen);\n h__dump(pass, passlen);\n fprintf(stderr, "Salt (length %d):\\n", saltlen);\n h__dump(salt, saltlen);\n#endif\n v = EVP_MD_block_size(md_type);\n u = EVP_MD_size(md_type);\n if (u < 0)\n return 0;\n D = OPENSSL_malloc(v);\n Ai = OPENSSL_malloc(u);\n B = OPENSSL_malloc(v + 1);\n Slen = v * ((saltlen + v - 1) / v);\n if (passlen)\n Plen = v * ((passlen + v - 1) / v);\n else\n Plen = 0;\n Ilen = Slen + Plen;\n I = OPENSSL_malloc(Ilen);\n Ij = BN_new();\n Bpl1 = BN_new();\n if (!D || !Ai || !B || !I || !Ij || !Bpl1)\n goto err;\n for (i = 0; i < v; i++)\n D[i] = id;\n p = I;\n for (i = 0; i < Slen; i++)\n *p++ = salt[i % saltlen];\n for (i = 0; i < Plen; i++)\n *p++ = pass[i % passlen];\n for (;;) {\n if (!EVP_DigestInit_ex(&ctx, md_type, NULL)\n || !EVP_DigestUpdate(&ctx, D, v)\n || !EVP_DigestUpdate(&ctx, I, Ilen)\n || !EVP_DigestFinal_ex(&ctx, Ai, NULL))\n goto err;\n for (j = 1; j < iter; j++) {\n if (!EVP_DigestInit_ex(&ctx, md_type, NULL)\n || !EVP_DigestUpdate(&ctx, Ai, u)\n || !EVP_DigestFinal_ex(&ctx, Ai, NULL))\n goto err;\n }\n memcpy(out, Ai, min(n, u));\n if (u >= n) {\n#ifdef DEBUG_KEYGEN\n fprintf(stderr, "Output KEY (length %d)\\n", tmpn);\n h__dump(tmpout, tmpn);\n#endif\n ret = 1;\n goto end;\n }\n n -= u;\n out += u;\n for (j = 0; j < v; j++)\n B[j] = Ai[j % u];\n if (!BN_bin2bn(B, v, Bpl1))\n goto err;\n if (!BN_add_word(Bpl1, 1))\n goto err;\n for (j = 0; j < Ilen; j += v) {\n if (!BN_bin2bn(I + j, v, Ij))\n goto err;\n if (!BN_add(Ij, Ij, Bpl1))\n goto err;\n if (!BN_bn2bin(Ij, B))\n goto err;\n Ijlen = BN_num_bytes(Ij);\n if (Ijlen > v) {\n if (!BN_bn2bin(Ij, B))\n goto err;\n memcpy(I + j, B + 1, v);\n#ifndef PKCS12_BROKEN_KEYGEN\n } else if (Ijlen < v) {\n memset(I + j, 0, v - Ijlen);\n if (!BN_bn2bin(Ij, I + j + v - Ijlen))\n goto err;\n#endif\n } else if (!BN_bn2bin(Ij, I + j))\n goto err;\n }\n }\n err:\n PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI, ERR_R_MALLOC_FAILURE);\n end:\n OPENSSL_free(Ai);\n OPENSSL_free(B);\n OPENSSL_free(D);\n OPENSSL_free(I);\n BN_free(Ij);\n BN_free(Bpl1);\n EVP_MD_CTX_cleanup(&ctx);\n return ret;\n}']
2,518
0
https://github.com/libav/libav/blob/9ee3334840c0d8564ca73dbfd6cd5a01bcdca79b/libavfilter/buffer.c/#L78
void avfilter_unref_buffer(AVFilterBufferRef *ref) { if (!ref) return; if (!(--ref->buf->refcount)) ref->buf->free(ref->buf); if (ref->extended_data != ref->data) av_freep(&ref->extended_data); av_free(ref->video); av_free(ref->audio); av_free(ref); }
['static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)\n{\n AVFilterContext *ctx = inlink->dst;\n ResampleContext *s = ctx->priv;\n AVFilterLink *outlink = ctx->outputs[0];\n if (s->avr) {\n AVFilterBufferRef *buf_out;\n int delay, nb_samples, ret;\n delay = avresample_get_delay(s->avr);\n nb_samples = av_rescale_rnd(buf->audio->nb_samples + delay,\n outlink->sample_rate, inlink->sample_rate,\n AV_ROUND_UP);\n buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples);\n ret = avresample_convert(s->avr, (void**)buf_out->extended_data,\n buf_out->linesize[0], nb_samples,\n (void**)buf->extended_data, buf->linesize[0],\n buf->audio->nb_samples);\n av_assert0(!avresample_available(s->avr));\n if (s->next_pts == AV_NOPTS_VALUE) {\n if (buf->pts == AV_NOPTS_VALUE) {\n av_log(ctx, AV_LOG_WARNING, "First timestamp is missing, "\n "assuming 0.\\n");\n s->next_pts = 0;\n } else\n s->next_pts = av_rescale_q(buf->pts, inlink->time_base,\n outlink->time_base);\n }\n if (ret > 0) {\n buf_out->audio->nb_samples = ret;\n if (buf->pts != AV_NOPTS_VALUE) {\n buf_out->pts = av_rescale_q(buf->pts, inlink->time_base,\n outlink->time_base) -\n av_rescale(delay, outlink->sample_rate,\n inlink->sample_rate);\n } else\n buf_out->pts = s->next_pts;\n s->next_pts = buf_out->pts + buf_out->audio->nb_samples;\n ff_filter_samples(outlink, buf_out);\n }\n avfilter_unref_buffer(buf);\n } else\n ff_filter_samples(outlink, buf);\n}', 'void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)\n{\n void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);\n AVFilterPad *dst = link->dstpad;\n AVFilterBufferRef *buf_out;\n FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1);\n if (!(filter_samples = dst->filter_samples))\n filter_samples = ff_default_filter_samples;\n if ((dst->min_perms & samplesref->perms) != dst->min_perms ||\n dst->rej_perms & samplesref->perms) {\n av_log(link->dst, AV_LOG_DEBUG,\n "Copying audio data in avfilter (have perms %x, need %x, reject %x)\\n",\n samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms);\n buf_out = ff_default_get_audio_buffer(link, dst->min_perms,\n samplesref->audio->nb_samples);\n buf_out->pts = samplesref->pts;\n buf_out->audio->sample_rate = samplesref->audio->sample_rate;\n av_samples_copy(buf_out->extended_data, samplesref->extended_data,\n 0, 0, samplesref->audio->nb_samples,\n av_get_channel_layout_nb_channels(link->channel_layout),\n link->format);\n avfilter_unref_buffer(samplesref);\n } else\n buf_out = samplesref;\n filter_samples(link, buf_out);\n}', 'void avfilter_unref_buffer(AVFilterBufferRef *ref)\n{\n if (!ref)\n return;\n if (!(--ref->buf->refcount))\n ref->buf->free(ref->buf);\n if (ref->extended_data != ref->data)\n av_freep(&ref->extended_data);\n av_free(ref->video);\n av_free(ref->audio);\n av_free(ref);\n}']
2,519
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 ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,\n const EC_POINT *b, BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *x0, *y0, *x1, *y1, *x2, *y2, *s, *t;\n int ret = 0;\n if (EC_POINT_is_at_infinity(group, a)) {\n if (!EC_POINT_copy(r, b))\n return 0;\n return 1;\n }\n if (EC_POINT_is_at_infinity(group, b)) {\n if (!EC_POINT_copy(r, a))\n return 0;\n return 1;\n }\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 x0 = BN_CTX_get(ctx);\n y0 = BN_CTX_get(ctx);\n x1 = BN_CTX_get(ctx);\n y1 = BN_CTX_get(ctx);\n x2 = BN_CTX_get(ctx);\n y2 = BN_CTX_get(ctx);\n s = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (a->Z_is_one) {\n if (!BN_copy(x0, a->X))\n goto err;\n if (!BN_copy(y0, a->Y))\n goto err;\n } else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group, a, x0, y0, ctx))\n goto err;\n }\n if (b->Z_is_one) {\n if (!BN_copy(x1, b->X))\n goto err;\n if (!BN_copy(y1, b->Y))\n goto err;\n } else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group, b, x1, y1, ctx))\n goto err;\n }\n if (BN_GF2m_cmp(x0, x1)) {\n if (!BN_GF2m_add(t, x0, x1))\n goto err;\n if (!BN_GF2m_add(s, y0, y1))\n goto err;\n if (!group->meth->field_div(group, s, s, t, ctx))\n goto err;\n if (!group->meth->field_sqr(group, x2, s, ctx))\n goto err;\n if (!BN_GF2m_add(x2, x2, group->a))\n goto err;\n if (!BN_GF2m_add(x2, x2, s))\n goto err;\n if (!BN_GF2m_add(x2, x2, t))\n goto err;\n } else {\n if (BN_GF2m_cmp(y0, y1) || BN_is_zero(x1)) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n ret = 1;\n goto err;\n }\n if (!group->meth->field_div(group, s, y1, x1, ctx))\n goto err;\n if (!BN_GF2m_add(s, s, x1))\n goto err;\n if (!group->meth->field_sqr(group, x2, s, ctx))\n goto err;\n if (!BN_GF2m_add(x2, x2, s))\n goto err;\n if (!BN_GF2m_add(x2, x2, group->a))\n goto err;\n }\n if (!BN_GF2m_add(y2, x1, x2))\n goto err;\n if (!group->meth->field_mul(group, y2, y2, s, ctx))\n goto err;\n if (!BN_GF2m_add(y2, y2, x2))\n goto err;\n if (!BN_GF2m_add(y2, y2, y1))\n goto err;\n if (!EC_POINT_set_affine_coordinates_GF2m(group, r, x2, y2, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\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}']
2,520
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_mul.c/#L647
void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb) { BN_ULONG *rr; if (na < nb) { int itmp; BN_ULONG *ltmp; itmp = na; na = nb; nb = itmp; ltmp = a; a = b; b = ltmp; } rr = &(r[na]); if (nb <= 0) { (void)bn_mul_words(r, a, na, 0); return; } else rr[0] = bn_mul_words(r, a, na, b[0]); for (;;) { if (--nb <= 0) return; rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]); if (--nb <= 0) return; rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]); if (--nb <= 0) return; rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]); if (--nb <= 0) return; rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]); rr += 4; r += 4; b += 4; } }
['int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *a, *b, *order, *tmp_1, *tmp_2;\n const BIGNUM *p = group->field;\n BN_CTX *new_ctx = NULL;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL) {\n ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT,\n ERR_R_MALLOC_FAILURE);\n goto err;\n }\n }\n BN_CTX_start(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n tmp_1 = BN_CTX_get(ctx);\n tmp_2 = BN_CTX_get(ctx);\n order = BN_CTX_get(ctx);\n if (order == NULL)\n goto err;\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, a, group->a, ctx))\n goto err;\n if (!group->meth->field_decode(group, b, group->b, ctx))\n goto err;\n } else {\n if (!BN_copy(a, group->a))\n goto err;\n if (!BN_copy(b, group->b))\n goto err;\n }\n if (BN_is_zero(a)) {\n if (BN_is_zero(b))\n goto err;\n } else if (!BN_is_zero(b)) {\n if (!BN_mod_sqr(tmp_1, a, p, ctx))\n goto err;\n if (!BN_mod_mul(tmp_2, tmp_1, a, p, ctx))\n goto err;\n if (!BN_lshift(tmp_1, tmp_2, 2))\n goto err;\n if (!BN_mod_sqr(tmp_2, b, p, ctx))\n goto err;\n if (!BN_mul_word(tmp_2, 27))\n goto err;\n if (!BN_mod_add(a, tmp_1, tmp_2, p, ctx))\n goto err;\n if (BN_is_zero(a))\n goto err;\n }\n ret = 1;\n err:\n if (ctx != NULL)\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}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_mod_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#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)\n{\n BN_ULONG *rr;\n if (na < nb) {\n int itmp;\n BN_ULONG *ltmp;\n itmp = na;\n na = nb;\n nb = itmp;\n ltmp = a;\n a = b;\n b = ltmp;\n }\n rr = &(r[na]);\n if (nb <= 0) {\n (void)bn_mul_words(r, a, na, 0);\n return;\n } else\n rr[0] = bn_mul_words(r, a, na, b[0]);\n for (;;) {\n if (--nb <= 0)\n return;\n rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]);\n if (--nb <= 0)\n return;\n rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]);\n if (--nb <= 0)\n return;\n rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]);\n if (--nb <= 0)\n return;\n rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);\n rr += 4;\n r += 4;\n b += 4;\n }\n}']
2,521
0
https://github.com/libav/libav/blob/490a022d86ef1c506a79744c5a95368af356fc69/libavformat/rtpdec_mpeg4.c/#L187
static int aac_parse_packet(AVFormatContext *ctx, PayloadContext *data, AVStream *st, AVPacket *pkt, uint32_t *timestamp, const uint8_t *buf, int len, int flags) { if (rtp_parse_mp4_au(data, buf)) return -1; buf += data->au_headers_length_bytes + 2; len -= data->au_headers_length_bytes + 2; av_new_packet(pkt, data->au_headers[0].size); memcpy(pkt->data, buf, data->au_headers[0].size); pkt->stream_index = st->index; return 0; }
['static int aac_parse_packet(AVFormatContext *ctx,\n PayloadContext *data,\n AVStream *st,\n AVPacket *pkt,\n uint32_t *timestamp,\n const uint8_t *buf, int len, int flags)\n{\n if (rtp_parse_mp4_au(data, buf))\n return -1;\n buf += data->au_headers_length_bytes + 2;\n len -= data->au_headers_length_bytes + 2;\n av_new_packet(pkt, data->au_headers[0].size);\n memcpy(pkt->data, buf, data->au_headers[0].size);\n pkt->stream_index = st->index;\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(size_t 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 pkt->side_data = NULL;\n pkt->side_data_elems = 0;\n}']
2,522
0
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_lib.c/#L250
int BN_num_bits(const BIGNUM *a) { int i = a->top - 1; bn_check_top(a); if (BN_is_zero(a)) return 0; return ((i*BN_BITS2) + BN_num_bits_word(a->d[i])); }
['int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,\n\t\t\tunsigned char *buf, int off)\n\t{\n\tint n,i;\n\tconst char *neg;\n\tif (num == NULL) return(1);\n\tneg = (BN_is_negative(num))?"-":"";\n\tif(!BIO_indent(bp,off,128))\n\t\treturn 0;\n\tif (BN_is_zero(num))\n\t\t{\n\t\tif (BIO_printf(bp, "%s 0\\n", number) <= 0)\n\t\t\treturn 0;\n\t\treturn 1;\n\t\t}\n\tif (BN_num_bytes(num) <= BN_BYTES)\n\t\t{\n\t\tif (BIO_printf(bp,"%s %s%lu (%s0x%lx)\\n",number,neg,\n\t\t\t(unsigned long)num->d[0],neg,(unsigned long)num->d[0])\n\t\t\t<= 0) return(0);\n\t\t}\n\telse\n\t\t{\n\t\tbuf[0]=0;\n\t\tif (BIO_printf(bp,"%s%s",number,\n\t\t\t(neg[0] == \'-\')?" (Negative)":"") <= 0)\n\t\t\treturn(0);\n\t\tn=BN_bn2bin(num,&buf[1]);\n\t\tif (buf[1] & 0x80)\n\t\t\tn++;\n\t\telse\tbuf++;\n\t\tfor (i=0; i<n; i++)\n\t\t\t{\n\t\t\tif ((i%15) == 0)\n\t\t\t\t{\n\t\t\t\tif(BIO_puts(bp,"\\n") <= 0\n\t\t\t\t || !BIO_indent(bp,off+4,128))\n\t\t\t\t return 0;\n\t\t\t\t}\n\t\t\tif (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":")\n\t\t\t\t<= 0) return(0);\n\t\t\t}\n\t\tif (BIO_write(bp,"\\n",1) <= 0) return(0);\n\t\t}\n\treturn(1);\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}', 'int BN_bn2bin(const BIGNUM *a, unsigned char *to)\n\t{\n\tint n,i;\n\tBN_ULONG l;\n\tbn_check_top(a);\n\tn=i=BN_num_bytes(a);\n\twhile (i--)\n\t\t{\n\t\tl=a->d[i/BN_BYTES];\n\t\t*(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;\n\t\t}\n\treturn(n);\n\t}']
2,523
0
https://github.com/openssl/openssl/blob/4b8515baa6edef1a771f9e4e3fbc0395b4a629e8/crypto/bn/bn_lib.c/#L401
int BN_set_word(BIGNUM *a, BN_ULONG w) { bn_check_top(a); if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL) return (0); a->neg = 0; a->d[0] = w; a->top = (w ? 1 : 0); bn_check_top(a); return (1); }
['static int dh_builtin_genparams(DH *ret, int prime_len, int generator,\n BN_GENCB *cb)\n{\n BIGNUM *t1, *t2;\n int g, ok = -1;\n BN_CTX *ctx = NULL;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\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 (!ret->p && ((ret->p = BN_new()) == NULL))\n goto err;\n if (!ret->g && ((ret->g = BN_new()) == NULL))\n goto err;\n if (generator <= 1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);\n goto err;\n }\n if (generator == DH_GENERATOR_2) {\n if (!BN_set_word(t1, 24))\n goto err;\n if (!BN_set_word(t2, 11))\n goto err;\n g = 2;\n } else if (generator == DH_GENERATOR_5) {\n if (!BN_set_word(t1, 10))\n goto err;\n if (!BN_set_word(t2, 3))\n goto err;\n g = 5;\n } else {\n if (!BN_set_word(t1, 2))\n goto err;\n if (!BN_set_word(t2, 1))\n goto err;\n g = generator;\n }\n if (!BN_generate_prime_ex(ret->p, prime_len, 1, t1, t2, cb))\n goto err;\n if (!BN_GENCB_call(cb, 3, 0))\n goto err;\n if (!BN_set_word(ret->g, g))\n goto err;\n ok = 1;\n err:\n if (ok == -1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, ERR_R_BN_LIB);\n ok = 0;\n }\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return ok;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}']
2,524
0
https://github.com/libav/libav/blob/e5b019725f53b79159931d3a7317107cbbfd0860/libavformat/m4vdec.c/#L35
static int mpeg4video_probe(AVProbeData *probe_packet) { uint32_t temp_buffer = -1; int VO = 0, VOL = 0, VOP = 0, VISO = 0, res = 0; int i; for (i = 0; i < probe_packet->buf_size; i++) { temp_buffer = (temp_buffer << 8) + probe_packet->buf[i]; if (temp_buffer & 0xfffffe00) continue; if (temp_buffer < 2) continue; if (temp_buffer == VOP_START_CODE) VOP++; else if (temp_buffer == VISUAL_OBJECT_START_CODE) VISO++; else if (temp_buffer >= 0x100 && temp_buffer < 0x120) VO++; else if (temp_buffer >= 0x120 && temp_buffer < 0x130) VOL++; else if (!(0x1AF < temp_buffer && temp_buffer < 0x1B7) && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++; } if (VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res == 0) return AVPROBE_SCORE_EXTENSION; return 0; }
['static int mpeg4video_probe(AVProbeData *probe_packet)\n{\n uint32_t temp_buffer = -1;\n int VO = 0, VOL = 0, VOP = 0, VISO = 0, res = 0;\n int i;\n for (i = 0; i < probe_packet->buf_size; i++) {\n temp_buffer = (temp_buffer << 8) + probe_packet->buf[i];\n if (temp_buffer & 0xfffffe00)\n continue;\n if (temp_buffer < 2)\n continue;\n if (temp_buffer == VOP_START_CODE)\n VOP++;\n else if (temp_buffer == VISUAL_OBJECT_START_CODE)\n VISO++;\n else if (temp_buffer >= 0x100 && temp_buffer < 0x120)\n VO++;\n else if (temp_buffer >= 0x120 && temp_buffer < 0x130)\n VOL++;\n else if (!(0x1AF < temp_buffer && temp_buffer < 0x1B7) &&\n !(0x1B9 < temp_buffer && temp_buffer < 0x1C4))\n res++;\n }\n if (VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res == 0)\n return AVPROBE_SCORE_EXTENSION;\n return 0;\n}']
2,525
0
https://github.com/openssl/openssl/blob/2864df8f9d3264e19b49a246e272fb513f4c1be3/crypto/bn/bn_ctx.c/#L270
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("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', '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 if (ctx == NULL)\n return;\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
2,526
0
https://github.com/nginx/nginx/blob/70f7141074896fb1ff3e5fc08407ea0f64f2076b/src/core/ngx_sha1.c/#L229
static const u_char * ngx_sha1_body(ngx_sha1_t *ctx, const u_char *data, size_t size) { uint32_t a, b, c, d, e, temp; uint32_t saved_a, saved_b, saved_c, saved_d, saved_e; uint32_t words[80]; ngx_uint_t i; const u_char *p; p = data; a = ctx->a; b = ctx->b; c = ctx->c; d = ctx->d; e = ctx->e; do { saved_a = a; saved_b = b; saved_c = c; saved_d = d; saved_e = e; for (i = 0; i < 16; i++) { words[i] = GET(i); } for (i = 16; i < 80; i++) { words[i] = ROTATE(1, words[i - 3] ^ words[i - 8] ^ words[i - 14] ^ words[i - 16]); } STEP(F1, a, b, c, d, e, words[0], 0x5a827999); STEP(F1, a, b, c, d, e, words[1], 0x5a827999); STEP(F1, a, b, c, d, e, words[2], 0x5a827999); STEP(F1, a, b, c, d, e, words[3], 0x5a827999); STEP(F1, a, b, c, d, e, words[4], 0x5a827999); STEP(F1, a, b, c, d, e, words[5], 0x5a827999); STEP(F1, a, b, c, d, e, words[6], 0x5a827999); STEP(F1, a, b, c, d, e, words[7], 0x5a827999); STEP(F1, a, b, c, d, e, words[8], 0x5a827999); STEP(F1, a, b, c, d, e, words[9], 0x5a827999); STEP(F1, a, b, c, d, e, words[10], 0x5a827999); STEP(F1, a, b, c, d, e, words[11], 0x5a827999); STEP(F1, a, b, c, d, e, words[12], 0x5a827999); STEP(F1, a, b, c, d, e, words[13], 0x5a827999); STEP(F1, a, b, c, d, e, words[14], 0x5a827999); STEP(F1, a, b, c, d, e, words[15], 0x5a827999); STEP(F1, a, b, c, d, e, words[16], 0x5a827999); STEP(F1, a, b, c, d, e, words[17], 0x5a827999); STEP(F1, a, b, c, d, e, words[18], 0x5a827999); STEP(F1, a, b, c, d, e, words[19], 0x5a827999); STEP(F2, a, b, c, d, e, words[20], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[21], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[22], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[23], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[24], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[25], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[26], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[27], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[28], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[29], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[30], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[31], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[32], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[33], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[34], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[35], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[36], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[37], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[38], 0x6ed9eba1); STEP(F2, a, b, c, d, e, words[39], 0x6ed9eba1); STEP(F3, a, b, c, d, e, words[40], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[41], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[42], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[43], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[44], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[45], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[46], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[47], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[48], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[49], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[50], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[51], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[52], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[53], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[54], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[55], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[56], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[57], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[58], 0x8f1bbcdc); STEP(F3, a, b, c, d, e, words[59], 0x8f1bbcdc); STEP(F2, a, b, c, d, e, words[60], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[61], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[62], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[63], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[64], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[65], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[66], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[67], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[68], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[69], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[70], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[71], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[72], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[73], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[74], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[75], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[76], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[77], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[78], 0xca62c1d6); STEP(F2, a, b, c, d, e, words[79], 0xca62c1d6); a += saved_a; b += saved_b; c += saved_c; d += saved_d; e += saved_e; p += 64; } while (size -= 64); ctx->a = a; ctx->b = b; ctx->c = c; ctx->d = d; ctx->e = e; return p; }
['static const u_char *\nngx_sha1_body(ngx_sha1_t *ctx, const u_char *data, size_t size)\n{\n uint32_t a, b, c, d, e, temp;\n uint32_t saved_a, saved_b, saved_c, saved_d, saved_e;\n uint32_t words[80];\n ngx_uint_t i;\n const u_char *p;\n p = data;\n a = ctx->a;\n b = ctx->b;\n c = ctx->c;\n d = ctx->d;\n e = ctx->e;\n do {\n saved_a = a;\n saved_b = b;\n saved_c = c;\n saved_d = d;\n saved_e = e;\n for (i = 0; i < 16; i++) {\n words[i] = GET(i);\n }\n for (i = 16; i < 80; i++) {\n words[i] = ROTATE(1, words[i - 3] ^ words[i - 8] ^ words[i - 14]\n ^ words[i - 16]);\n }\n STEP(F1, a, b, c, d, e, words[0], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[1], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[2], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[3], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[4], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[5], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[6], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[7], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[8], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[9], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[10], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[11], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[12], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[13], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[14], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[15], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[16], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[17], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[18], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[19], 0x5a827999);\n STEP(F2, a, b, c, d, e, words[20], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[21], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[22], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[23], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[24], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[25], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[26], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[27], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[28], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[29], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[30], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[31], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[32], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[33], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[34], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[35], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[36], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[37], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[38], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[39], 0x6ed9eba1);\n STEP(F3, a, b, c, d, e, words[40], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[41], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[42], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[43], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[44], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[45], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[46], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[47], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[48], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[49], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[50], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[51], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[52], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[53], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[54], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[55], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[56], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[57], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[58], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[59], 0x8f1bbcdc);\n STEP(F2, a, b, c, d, e, words[60], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[61], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[62], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[63], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[64], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[65], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[66], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[67], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[68], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[69], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[70], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[71], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[72], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[73], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[74], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[75], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[76], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[77], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[78], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[79], 0xca62c1d6);\n a += saved_a;\n b += saved_b;\n c += saved_c;\n d += saved_d;\n e += saved_e;\n p += 64;\n } while (size -= 64);\n ctx->a = a;\n ctx->b = b;\n ctx->c = c;\n ctx->d = d;\n ctx->e = e;\n return p;\n}']
2,527
0
https://github.com/libav/libav/blob/555000c7d5c1e13043a948ebc48d2939b0ba6536/libavformat/utils.c/#L2638
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); } if (st->attached_pic.data) av_free_packet(&st->attached_pic); 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 av_cold void uninit(AVFilterContext *ctx)\n{\n MovieContext *movie = ctx->priv;\n av_free(movie->file_name);\n av_free(movie->format_name);\n if (movie->codec_ctx)\n avcodec_close(movie->codec_ctx);\n if (movie->format_ctx)\n avformat_close_input(&movie->format_ctx);\n av_frame_free(&movie->frame);\n}', 'int avcodec_close(AVCodecContext *avctx)\n{\n if (ff_lockmgr_cb) {\n if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))\n return -1;\n }\n entangled_thread_counter++;\n if (entangled_thread_counter != 1) {\n av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\\n");\n entangled_thread_counter--;\n return -1;\n }\n if (avcodec_is_open(avctx)) {\n FramePool *pool = avctx->internal->pool;\n int i;\n if (HAVE_THREADS && avctx->thread_opaque)\n ff_thread_free(avctx);\n if (avctx->codec && avctx->codec->close)\n avctx->codec->close(avctx);\n avctx->coded_frame = NULL;\n if (!avctx->refcounted_frames)\n av_frame_unref(&avctx->internal->to_free);\n for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)\n av_buffer_pool_uninit(&pool->pools[i]);\n av_freep(&avctx->internal->pool);\n av_freep(&avctx->internal);\n }\n if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)\n av_opt_free(avctx->priv_data);\n av_opt_free(avctx);\n av_freep(&avctx->priv_data);\n if (av_codec_is_encoder(avctx->codec))\n av_freep(&avctx->extradata);\n avctx->codec = NULL;\n avctx->active_thread_type = 0;\n entangled_thread_counter--;\n if (ff_lockmgr_cb) {\n (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);\n }\n return 0;\n}', 'void av_frame_unref(AVFrame *frame)\n{\n int i;\n for (i = 0; i < frame->nb_side_data; i++) {\n av_freep(&frame->side_data[i]->data);\n av_dict_free(&frame->side_data[i]->metadata);\n av_freep(&frame->side_data[i]);\n }\n av_freep(&frame->side_data);\n for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)\n av_buffer_unref(&frame->buf[i]);\n for (i = 0; i < frame->nb_extended_buf; i++)\n av_buffer_unref(&frame->extended_buf[i]);\n av_freep(&frame->extended_buf);\n get_frame_defaults(frame);\n}', 'static void get_frame_defaults(AVFrame *frame)\n{\n if (frame->extended_data != frame->data)\n av_freep(&frame->extended_data);\n memset(frame, 0, sizeof(*frame));\n frame->pts = AV_NOPTS_VALUE;\n frame->key_frame = 1;\n frame->sample_aspect_ratio = (AVRational){ 0, 1 };\n frame->format = -1;\n frame->extended_data = frame->data;\n}', 'void avformat_close_input(AVFormatContext **ps)\n{\n AVFormatContext *s = *ps;\n AVIOContext *pb = s->pb;\n if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) ||\n (s->flags & AVFMT_FLAG_CUSTOM_IO))\n pb = NULL;\n flush_packet_queue(s);\n if (s->iformat) {\n if (s->iformat->read_close)\n s->iformat->read_close(s);\n }\n avformat_free_context(s);\n *ps = NULL;\n avio_close(pb);\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 }\n if (st->attached_pic.data)\n av_free_packet(&st->attached_pic);\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}']
2,528
0
https://github.com/openssl/openssl/blob/40a706286febe0279336c96374c607daaa1b1d49/crypto/lhash/lhash.c/#L370
static void contract(_LHASH *lh) { LHASH_NODE **n,*n1,*np; np=lh->b[lh->p+lh->pmax-1]; lh->b[lh->p+lh->pmax-1]=NULL; if (lh->p == 0) { n=(LHASH_NODE **)OPENSSL_realloc(lh->b, (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); if (n == NULL) { lh->error++; return; } lh->num_contract_reallocs++; lh->num_alloc_nodes/=2; lh->pmax/=2; lh->p=lh->pmax-1; lh->b=n; } else lh->p--; lh->num_nodes--; lh->num_contracts++; n1=lh->b[(int)lh->p]; if (n1 == NULL) lh->b[(int)lh->p]=np; else { while (n1->next != NULL) n1=n1->next; n1->next=np; } }
['static ERR_STRING_DATA *int_err_del_item(ERR_STRING_DATA *d)\n\t{\n\tERR_STRING_DATA *p;\n\tLHASH_OF(ERR_STRING_DATA) *hash;\n\terr_fns_check();\n\thash = ERRFN(err_get)(0);\n\tif (!hash)\n\t\treturn NULL;\n\tCRYPTO_w_lock(CRYPTO_LOCK_ERR);\n\tp = lh_ERR_STRING_DATA_delete(hash, d);\n\tCRYPTO_w_unlock(CRYPTO_LOCK_ERR);\n\treturn p;\n\t}', 'void *lh_delete(_LHASH *lh, const 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}', 'static void contract(_LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)OPENSSL_realloc(lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}']
2,529
0
https://github.com/openssl/openssl/blob/8580f8015fa2f56da854ece033f9d1894bcc3ede/crypto/buffer/buffer.c/#L135
int BUF_MEM_grow_clean(BUF_MEM *str, size_t len) { char *ret; size_t n; if (str->length >= len) { memset(&str->data[len],0,str->length-len); str->length=len; return(len); } if (str->max >= len) { memset(&str->data[str->length],0,len-str->length); str->length=len; return(len); } n=(len+3)/3*4; if (str->data == NULL) ret=OPENSSL_malloc(n); else ret=OPENSSL_realloc_clean(str->data,str->max,n); if (ret == NULL) { BUFerr(BUF_F_BUF_MEM_GROW_CLEAN,ERR_R_MALLOC_FAILURE); len=0; } else { str->data=ret; str->max=n; memset(&str->data[str->length],0,len-str->length); str->length=len; } return(len); }
['int dtls1_accept(SSL *s)\n\t{\n\tBUF_MEM *buf;\n\tunsigned long Time=(unsigned long)time(NULL);\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\n\tlong num1;\n\tunsigned long alg_k;\n\tint ret= -1;\n\tint new_state,state,skip=0;\n\tRAND_add(&Time,sizeof(Time),0);\n\tERR_clear_error();\n\tclear_sys_error();\n\tif (s->info_callback != NULL)\n\t\tcb=s->info_callback;\n\telse if (s->ctx->info_callback != NULL)\n\t\tcb=s->ctx->info_callback;\n\ts->in_handshake++;\n\tif (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);\n\tif (s->cert == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_DTLS1_ACCEPT,SSL_R_NO_CERTIFICATE_SET);\n\t\treturn(-1);\n\t\t}\n\tfor (;;)\n\t\t{\n\t\tstate=s->state;\n\t\tswitch (s->state)\n\t\t\t{\n\t\tcase SSL_ST_RENEGOTIATE:\n\t\t\ts->new_session=1;\n\t\tcase SSL_ST_BEFORE:\n\t\tcase SSL_ST_ACCEPT:\n\t\tcase SSL_ST_BEFORE|SSL_ST_ACCEPT:\n\t\tcase SSL_ST_OK|SSL_ST_ACCEPT:\n\t\t\ts->server=1;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);\n\t\t\tif ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_DTLS1_ACCEPT, ERR_R_INTERNAL_ERROR);\n\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\ts->type=SSL_ST_ACCEPT;\n\t\t\tif (s->init_buf == NULL)\n\t\t\t\t{\n\t\t\t\tif ((buf=BUF_MEM_new()) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\ts->init_buf=buf;\n\t\t\t\t}\n\t\t\tif (!ssl3_setup_buffers(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tif (s->state != SSL_ST_RENEGOTIATE)\n\t\t\t\t{\n\t\t\t\tif (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; }\n\t\t\t\tssl3_init_finished_mac(s);\n\t\t\t\ts->state=SSL3_ST_SR_CLNT_HELLO_A;\n\t\t\t\ts->ctx->stats.sess_accept++;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->ctx->stats.sess_accept_renegotiate++;\n\t\t\t\ts->state=SSL3_ST_SW_HELLO_REQ_A;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_HELLO_REQ_A:\n\t\tcase SSL3_ST_SW_HELLO_REQ_B:\n\t\t\ts->shutdown=0;\n\t\t\tdtls1_start_timer(s);\n\t\t\tret=dtls1_send_hello_request(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\ts->init_num=0;\n\t\t\tssl3_init_finished_mac(s);\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_HELLO_REQ_C:\n\t\t\ts->state=SSL_ST_OK;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CLNT_HELLO_A:\n\t\tcase SSL3_ST_SR_CLNT_HELLO_B:\n\t\tcase SSL3_ST_SR_CLNT_HELLO_C:\n\t\t\ts->shutdown=0;\n\t\t\tret=ssl3_get_client_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tdtls1_stop_timer(s);\n\t\t\ts->new_session = 2;\n\t\t\tif (ret == 1 && (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE))\n\t\t\t\ts->state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A;\n\t\t\telse\n\t\t\t\ts->state = SSL3_ST_SW_SRVR_HELLO_A;\n\t\t\ts->init_num=0;\n\t\t\tif (s->d1->listen && s->state == SSL3_ST_SW_SRVR_HELLO_A)\n\t\t\t\t{\n\t\t\t\tret = 2;\n\t\t\t\ts->d1->listen = 0;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:\n\t\tcase DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:\n\t\t\tdtls1_start_timer(s);\n\t\t\tret = dtls1_send_hello_verify_request(s);\n\t\t\tif ( ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_CLNT_HELLO_A;\n\t\t\tif (s->version != DTLS1_BAD_VER)\n\t\t\t\tssl3_init_finished_mac(s);\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_SRVR_HELLO_A:\n\t\tcase SSL3_ST_SW_SRVR_HELLO_B:\n\t\t\tdtls1_start_timer(s);\n\t\t\tret=dtls1_send_server_hello(s);\n\t\t\tif (ret <= 0) goto end;\n#ifndef OPENSSL_NO_TLSEXT\n\t\t\tif (s->hit)\n\t\t\t\t{\n\t\t\t\tif (s->tlsext_ticket_expected)\n\t\t\t\t\ts->state=SSL3_ST_SW_SESSION_TICKET_A;\n\t\t\t\telse\n\t\t\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n\t\t\t\t}\n#else\n\t\t\tif (s->hit)\n\t\t\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n#endif\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_SW_CERT_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CERT_A:\n\t\tcase SSL3_ST_SW_CERT_B:\n\t\t\tif (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL)\n\t\t\t\t&& !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))\n\t\t\t\t{\n\t\t\t\tdtls1_start_timer(s);\n\t\t\t\tret=dtls1_send_server_certificate(s);\n\t\t\t\tif (ret <= 0) goto end;\n#ifndef OPENSSL_NO_TLSEXT\n\t\t\t\tif (s->tlsext_status_expected)\n\t\t\t\t\ts->state=SSL3_ST_SW_CERT_STATUS_A;\n\t\t\t\telse\n\t\t\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tskip = 1;\n\t\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n\t\t\t\t}\n#else\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tskip=1;\n\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n#endif\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_KEY_EXCH_A:\n\t\tcase SSL3_ST_SW_KEY_EXCH_B:\n\t\t\talg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n\t\t\tif ((s->options & SSL_OP_EPHEMERAL_RSA)\n#ifndef OPENSSL_NO_KRB5\n\t\t\t\t&& !(alg_k & SSL_kKRB5)\n#endif\n\t\t\t\t)\n\t\t\t\ts->s3->tmp.use_rsa_tmp=1;\n\t\t\telse\n\t\t\t\ts->s3->tmp.use_rsa_tmp=0;\n\t\t\tif (s->s3->tmp.use_rsa_tmp\n#ifndef OPENSSL_NO_PSK\n\t\t\t || ((alg_k & SSL_kPSK) && s->ctx->psk_identity_hint)\n#endif\n\t\t\t || (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd))\n\t\t\t || (alg_k & SSL_kEECDH)\n\t\t\t || ((alg_k & SSL_kRSA)\n\t\t\t\t&& (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL\n\t\t\t\t || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)\n\t\t\t\t\t&& EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)\n\t\t\t\t\t)\n\t\t\t\t )\n\t\t\t\t)\n\t\t\t )\n\t\t\t\t{\n\t\t\t\tdtls1_start_timer(s);\n\t\t\t\tret=dtls1_send_server_key_exchange(s);\n\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tskip=1;\n\t\t\ts->state=SSL3_ST_SW_CERT_REQ_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CERT_REQ_A:\n\t\tcase SSL3_ST_SW_CERT_REQ_B:\n\t\t\tif (\n\t\t\t\t!(s->verify_mode & SSL_VERIFY_PEER) ||\n\t\t\t\t((s->session->peer != NULL) &&\n\t\t\t\t (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||\n\t\t\t\t((s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&\n\t\t\t\t !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) ||\n\t\t\t\t(s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5)\n\t\t\t\t|| (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))\n\t\t\t\t{\n\t\t\t\tskip=1;\n\t\t\t\ts->s3->tmp.cert_request=0;\n\t\t\t\ts->state=SSL3_ST_SW_SRVR_DONE_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.cert_request=1;\n\t\t\t\tdtls1_start_timer(s);\n\t\t\t\tret=dtls1_send_certificate_request(s);\n\t\t\t\tif (ret <= 0) goto end;\n#ifndef NETSCAPE_HANG_BUG\n\t\t\t\ts->state=SSL3_ST_SW_SRVR_DONE_A;\n#else\n\t\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_CERT_A;\n#endif\n\t\t\t\ts->init_num=0;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_SRVR_DONE_A:\n\t\tcase SSL3_ST_SW_SRVR_DONE_B:\n\t\t\tdtls1_start_timer(s);\n\t\t\tret=dtls1_send_server_done(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_CERT_A;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_FLUSH:\n\t\t\tnum1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);\n\t\t\tif (num1 > 0)\n\t\t\t\t{\n\t\t\t\ts->rwstate=SSL_WRITING;\n\t\t\t\tnum1=BIO_flush(s->wbio);\n\t\t\t\tif (num1 <= 0) { ret= -1; goto end; }\n\t\t\t\ts->rwstate=SSL_NOTHING;\n\t\t\t\t}\n\t\t\ts->state=s->s3->tmp.next_state;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CERT_A:\n\t\tcase SSL3_ST_SR_CERT_B:\n\t\t\tret = ssl3_check_client_hello(s);\n\t\t\tif (ret <= 0)\n\t\t\t\tgoto end;\n\t\t\tdtls1_stop_timer(s);\n\t\t\tif (ret == 2)\n\t\t\t\ts->state = SSL3_ST_SR_CLNT_HELLO_C;\n\t\t\telse {\n\t\t\t\tret=ssl3_get_client_certificate(s);\n\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\tdtls1_stop_timer(s);\n\t\t\t\ts->init_num=0;\n\t\t\t\ts->state=SSL3_ST_SR_KEY_EXCH_A;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_KEY_EXCH_A:\n\t\tcase SSL3_ST_SR_KEY_EXCH_B:\n\t\t\tret=ssl3_get_client_key_exchange(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tdtls1_stop_timer(s);\n\t\t\ts->state=SSL3_ST_SR_CERT_VRFY_A;\n\t\t\ts->init_num=0;\n\t\t\tif (ret == 2)\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_SR_FINISHED_A;\n\t\t\t\ts->init_num = 0;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_SR_CERT_VRFY_A;\n\t\t\t\ts->init_num=0;\n\t\t\t\ts->method->ssl3_enc->cert_verify_mac(s,\n\t\t\t\t\tNID_md5,\n\t\t\t\t\t&(s->s3->tmp.cert_verify_md[0]));\n\t\t\t\ts->method->ssl3_enc->cert_verify_mac(s,\n\t\t\t\t\tNID_sha1,\n\t\t\t\t\t&(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]));\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CERT_VRFY_A:\n\t\tcase SSL3_ST_SR_CERT_VRFY_B:\n\t\t\ts->d1->change_cipher_spec_ok = 1;\n\t\t\tret=ssl3_get_cert_verify(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tdtls1_stop_timer(s);\n\t\t\ts->state=SSL3_ST_SR_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_FINISHED_A:\n\t\tcase SSL3_ST_SR_FINISHED_B:\n\t\t\ts->d1->change_cipher_spec_ok = 1;\n\t\t\tret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,\n\t\t\t\tSSL3_ST_SR_FINISHED_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tdtls1_stop_timer(s);\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL_ST_OK;\n#ifndef OPENSSL_NO_TLSEXT\n\t\t\telse if (s->tlsext_ticket_expected)\n\t\t\t\ts->state=SSL3_ST_SW_SESSION_TICKET_A;\n#endif\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n#ifndef OPENSSL_NO_TLSEXT\n\t\tcase SSL3_ST_SW_SESSION_TICKET_A:\n\t\tcase SSL3_ST_SW_SESSION_TICKET_B:\n\t\t\tret=dtls1_send_newsession_ticket(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CERT_STATUS_A:\n\t\tcase SSL3_ST_SW_CERT_STATUS_B:\n\t\t\tret=ssl3_send_cert_status(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n#endif\n\t\tcase SSL3_ST_SW_CHANGE_A:\n\t\tcase SSL3_ST_SW_CHANGE_B:\n\t\t\ts->session->cipher=s->s3->tmp.new_cipher;\n\t\t\tif (!s->method->ssl3_enc->setup_key_block(s))\n\t\t\t\t{ ret= -1; goto end; }\n\t\t\tret=dtls1_send_change_cipher_spec(s,\n\t\t\t\tSSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\tif (!s->method->ssl3_enc->change_cipher_state(s,\n\t\t\t\tSSL3_CHANGE_CIPHER_SERVER_WRITE))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tdtls1_reset_seq_numbers(s, SSL3_CC_WRITE);\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_FINISHED_A:\n\t\tcase SSL3_ST_SW_FINISHED_B:\n\t\t\tret=dtls1_send_finished(s,\n\t\t\t\tSSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B,\n\t\t\t\ts->method->ssl3_enc->server_finished_label,\n\t\t\t\ts->method->ssl3_enc->server_finished_label_len);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\tif (s->hit)\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;\n\t\t\telse\n\t\t\t\ts->s3->tmp.next_state=SSL_ST_OK;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL_ST_OK:\n\t\t\tssl3_cleanup_key_block(s);\n#if 0\n\t\t\tBUF_MEM_free(s->init_buf);\n\t\t\ts->init_buf=NULL;\n#endif\n\t\t\tssl_free_wbio_buffer(s);\n\t\t\ts->init_num=0;\n\t\t\tif (s->new_session == 2)\n\t\t\t\t{\n\t\t\t\ts->new_session=0;\n\t\t\t\tssl_update_cache(s,SSL_SESS_CACHE_SERVER);\n\t\t\t\ts->ctx->stats.sess_accept_good++;\n\t\t\t\ts->handshake_func=dtls1_accept;\n\t\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);\n\t\t\t\t}\n\t\t\tret = 1;\n\t\t\ts->d1->handshake_read_seq = 0;\n\t\t\ts->d1->handshake_write_seq = 0;\n\t\t\ts->d1->next_handshake_write_seq = 0;\n\t\t\tgoto end;\n\t\tdefault:\n\t\t\tSSLerr(SSL_F_DTLS1_ACCEPT,SSL_R_UNKNOWN_STATE);\n\t\t\tret= -1;\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!s->s3->tmp.reuse_message && !skip)\n\t\t\t{\n\t\t\tif (s->debug)\n\t\t\t\t{\n\t\t\t\tif ((ret=BIO_flush(s->wbio)) <= 0)\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif ((cb != NULL) && (s->state != state))\n\t\t\t\t{\n\t\t\t\tnew_state=s->state;\n\t\t\t\ts->state=state;\n\t\t\t\tcb(s,SSL_CB_ACCEPT_LOOP,1);\n\t\t\t\ts->state=new_state;\n\t\t\t\t}\n\t\t\t}\n\t\tskip=0;\n\t\t}\nend:\n\ts->in_handshake--;\n\tif (cb != NULL)\n\t\tcb(s,SSL_CB_ACCEPT_EXIT,ret);\n\treturn(ret);\n\t}', 'int dtls1_send_server_certificate(SSL *s)\n\t{\n\tunsigned long l;\n\tX509 *x;\n\tif (s->state == SSL3_ST_SW_CERT_A)\n\t\t{\n\t\tx=ssl_get_server_send_cert(s);\n\t\tif (x == NULL)\n\t\t\t{\n\t\t\tif ((s->s3->tmp.new_cipher->algorithm_mkey != SSL_kKRB5) ||\n\t\t\t (s->s3->tmp.new_cipher->algorithm_auth != SSL_aKRB5))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_DTLS1_SEND_SERVER_CERTIFICATE,ERR_R_INTERNAL_ERROR);\n\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\tl=dtls1_output_cert_chain(s,x);\n\t\ts->state=SSL3_ST_SW_CERT_B;\n\t\ts->init_num=(int)l;\n\t\ts->init_off=0;\n\t\tdtls1_buffer_message(s, 0);\n\t\t}\n\treturn(dtls1_do_write(s,SSL3_RT_HANDSHAKE));\n\t}', 'unsigned long dtls1_output_cert_chain(SSL *s, X509 *x)\n\t{\n\tunsigned char *p;\n\tint i;\n\tunsigned long l= 3 + DTLS1_HM_HEADER_LENGTH;\n\tBUF_MEM *buf;\n\tbuf=s->init_buf;\n\tif (!BUF_MEM_grow_clean(buf,10))\n\t\t{\n\t\tSSLerr(SSL_F_DTLS1_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);\n\t\treturn(0);\n\t\t}\n\tif (x != NULL)\n\t\t{\n\t\tX509_STORE_CTX xs_ctx;\n\t\tif (!X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,x,NULL))\n \t\t\t{\n \t\t\tSSLerr(SSL_F_DTLS1_OUTPUT_CERT_CHAIN,ERR_R_X509_LIB);\n \t\t\treturn(0);\n \t\t\t}\n\t\tX509_verify_cert(&xs_ctx);\n\t\tfor (i=0; i < sk_X509_num(xs_ctx.chain); i++)\n \t\t\t{\n\t\t\tx = sk_X509_value(xs_ctx.chain, i);\n\t\t\tif (!dtls1_add_cert_to_buf(buf, &l, x))\n \t\t\t\t{\n\t\t\t\tX509_STORE_CTX_cleanup(&xs_ctx);\n\t\t\t\treturn 0;\n \t\t\t\t}\n \t\t\t}\n \t\tX509_STORE_CTX_cleanup(&xs_ctx);\n \t\t}\n\tfor (i=0; i<sk_X509_num(s->ctx->extra_certs); i++)\n\t\t{\n\t\tx=sk_X509_value(s->ctx->extra_certs,i);\n\t\tif (!dtls1_add_cert_to_buf(buf, &l, x))\n\t\t\treturn 0;\n\t\t}\n\tl-= (3 + DTLS1_HM_HEADER_LENGTH);\n\tp=(unsigned char *)&(buf->data[DTLS1_HM_HEADER_LENGTH]);\n\tl2n3(l,p);\n\tl+=3;\n\tp=(unsigned char *)&(buf->data[0]);\n\tp = dtls1_set_message_header(s, p, SSL3_MT_CERTIFICATE, l, 0, l);\n\tl+=DTLS1_HM_HEADER_LENGTH;\n\treturn(l);\n\t}', 'int BUF_MEM_grow_clean(BUF_MEM *str, size_t len)\n\t{\n\tchar *ret;\n\tsize_t n;\n\tif (str->length >= len)\n\t\t{\n\t\tmemset(&str->data[len],0,str->length-len);\n\t\tstr->length=len;\n\t\treturn(len);\n\t\t}\n\tif (str->max >= len)\n\t\t{\n\t\tmemset(&str->data[str->length],0,len-str->length);\n\t\tstr->length=len;\n\t\treturn(len);\n\t\t}\n\tn=(len+3)/3*4;\n\tif (str->data == NULL)\n\t\tret=OPENSSL_malloc(n);\n\telse\n\t\tret=OPENSSL_realloc_clean(str->data,str->max,n);\n\tif (ret == NULL)\n\t\t{\n\t\tBUFerr(BUF_F_BUF_MEM_GROW_CLEAN,ERR_R_MALLOC_FAILURE);\n\t\tlen=0;\n\t\t}\n\telse\n\t\t{\n\t\tstr->data=ret;\n\t\tstr->max=n;\n\t\tmemset(&str->data[str->length],0,len-str->length);\n\t\tstr->length=len;\n\t\t}\n\treturn(len);\n\t}']
2,530
0
https://github.com/openssl/openssl/blob/05ec6a25f80ac8edfb7d7cb764d2dd68156a6965/test/handshake_helper.c/#L74
static int select_server_ctx(SSL *s, void *arg, int ignore) { const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name); HANDSHAKE_EX_DATA *ex_data = (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx)); if (servername == NULL) { ex_data->servername = SSL_TEST_SERVERNAME_SERVER1; return SSL_TLSEXT_ERR_NOACK; } if (strcmp(servername, "server2") == 0) { SSL_CTX *new_ctx = (SSL_CTX*)arg; SSL_set_SSL_CTX(s, new_ctx); SSL_clear_options(s, 0xFFFFFFFFL); SSL_set_options(s, SSL_CTX_get_options(new_ctx)); ex_data->servername = SSL_TEST_SERVERNAME_SERVER2; return SSL_TLSEXT_ERR_OK; } else if (strcmp(servername, "server1") == 0) { ex_data->servername = SSL_TEST_SERVERNAME_SERVER1; return SSL_TLSEXT_ERR_OK; } else if (ignore) { ex_data->servername = SSL_TEST_SERVERNAME_SERVER1; return SSL_TLSEXT_ERR_NOACK; } else { return SSL_TLSEXT_ERR_ALERT_FATAL; } }
['static int select_server_ctx(SSL *s, void *arg, int ignore)\n{\n const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);\n HANDSHAKE_EX_DATA *ex_data =\n (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n if (servername == NULL) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_NOACK;\n }\n if (strcmp(servername, "server2") == 0) {\n SSL_CTX *new_ctx = (SSL_CTX*)arg;\n SSL_set_SSL_CTX(s, new_ctx);\n SSL_clear_options(s, 0xFFFFFFFFL);\n SSL_set_options(s, SSL_CTX_get_options(new_ctx));\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;\n return SSL_TLSEXT_ERR_OK;\n } else if (strcmp(servername, "server1") == 0) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_OK;\n } else if (ignore) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_NOACK;\n } else {\n return SSL_TLSEXT_ERR_ALERT_FATAL;\n }\n}', 'const char *SSL_get_servername(const SSL *s, const int type)\n{\n if (type != TLSEXT_NAMETYPE_host_name)\n return NULL;\n return s->session && !s->tlsext_hostname ?\n s->session->tlsext_hostname : s->tlsext_hostname;\n}', 'void *SSL_get_ex_data(const SSL *s, int idx)\n{\n return (CRYPTO_get_ex_data(&s->ex_data, idx));\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n return NULL;\n return sk_void_value(ad->sk, idx);\n}', 'SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx)\n{\n CERT *new_cert;\n if (ssl->ctx == ctx)\n return ssl->ctx;\n if (ctx == NULL)\n ctx = ssl->initial_ctx;\n new_cert = ssl_cert_dup(ctx->cert);\n if (new_cert == NULL) {\n return NULL;\n }\n ssl_cert_free(ssl->cert);\n ssl->cert = new_cert;\n OPENSSL_assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx));\n if ((ssl->ctx != NULL) &&\n (ssl->sid_ctx_length == ssl->ctx->sid_ctx_length) &&\n (memcmp(ssl->sid_ctx, ssl->ctx->sid_ctx, ssl->sid_ctx_length) == 0)) {\n ssl->sid_ctx_length = ctx->sid_ctx_length;\n memcpy(&ssl->sid_ctx, &ctx->sid_ctx, sizeof(ssl->sid_ctx));\n }\n SSL_CTX_up_ref(ctx);\n SSL_CTX_free(ssl->ctx);\n ssl->ctx = ctx;\n return ssl->ctx;\n}', 'unsigned long SSL_clear_options(SSL *s, unsigned long op)\n{\n return s->options &= ~op;\n}', 'unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)\n{\n return ctx->options;\n}', 'unsigned long SSL_set_options(SSL *s, unsigned long op)\n{\n return s->options |= op;\n}']
2,531
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); }
['static EC_GROUP *ec_asn1_parameters2group(const ECPARAMETERS *params)\n{\n int ok = 0, tmp;\n EC_GROUP *ret = NULL;\n BIGNUM *p = NULL, *a = NULL, *b = NULL;\n EC_POINT *point = NULL;\n long field_bits;\n if (!params->fieldID || !params->fieldID->fieldType ||\n !params->fieldID->p.ptr) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n if (!params->curve || !params->curve->a ||\n !params->curve->a->data || !params->curve->b ||\n !params->curve->b->data) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n a = BN_bin2bn(params->curve->a->data, params->curve->a->length, NULL);\n if (a == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_BN_LIB);\n goto err;\n }\n b = BN_bin2bn(params->curve->b->data, params->curve->b->length, NULL);\n if (b == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_BN_LIB);\n goto err;\n }\n tmp = OBJ_obj2nid(params->fieldID->fieldType);\n if (tmp == NID_X9_62_characteristic_two_field)\n#ifdef OPENSSL_NO_EC2M\n {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_GF2M_NOT_SUPPORTED);\n goto err;\n }\n#else\n {\n X9_62_CHARACTERISTIC_TWO *char_two;\n char_two = params->fieldID->p.char_two;\n field_bits = char_two->m;\n if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_FIELD_TOO_LARGE);\n goto err;\n }\n if ((p = BN_new()) == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n tmp = OBJ_obj2nid(char_two->type);\n if (tmp == NID_X9_62_tpBasis) {\n long tmp_long;\n if (!char_two->p.tpBasis) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n tmp_long = ASN1_INTEGER_get(char_two->p.tpBasis);\n if (!(char_two->m > tmp_long && tmp_long > 0)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP,\n EC_R_INVALID_TRINOMIAL_BASIS);\n goto err;\n }\n if (!BN_set_bit(p, (int)char_two->m))\n goto err;\n if (!BN_set_bit(p, (int)tmp_long))\n goto err;\n if (!BN_set_bit(p, 0))\n goto err;\n } else if (tmp == NID_X9_62_ppBasis) {\n X9_62_PENTANOMIAL *penta;\n penta = char_two->p.ppBasis;\n if (!penta) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n if (!\n (char_two->m > penta->k3 && penta->k3 > penta->k2\n && penta->k2 > penta->k1 && penta->k1 > 0)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP,\n EC_R_INVALID_PENTANOMIAL_BASIS);\n goto err;\n }\n if (!BN_set_bit(p, (int)char_two->m))\n goto err;\n if (!BN_set_bit(p, (int)penta->k1))\n goto err;\n if (!BN_set_bit(p, (int)penta->k2))\n goto err;\n if (!BN_set_bit(p, (int)penta->k3))\n goto err;\n if (!BN_set_bit(p, 0))\n goto err;\n } else if (tmp == NID_X9_62_onBasis) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_NOT_IMPLEMENTED);\n goto err;\n } else {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n ret = EC_GROUP_new_curve_GF2m(p, a, b, NULL);\n }\n#endif\n else if (tmp == NID_X9_62_prime_field) {\n if (!params->fieldID->p.prime) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n p = ASN1_INTEGER_to_BN(params->fieldID->p.prime, NULL);\n if (p == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);\n goto err;\n }\n if (BN_is_negative(p) || BN_is_zero(p)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_FIELD);\n goto err;\n }\n field_bits = BN_num_bits(p);\n if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_FIELD_TOO_LARGE);\n goto err;\n }\n ret = EC_GROUP_new_curve_GFp(p, a, b, NULL);\n } else {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_FIELD);\n goto err;\n }\n if (ret == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);\n goto err;\n }\n if (params->curve->seed != NULL) {\n OPENSSL_free(ret->seed);\n if ((ret->seed = OPENSSL_malloc(params->curve->seed->length)) == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n memcpy(ret->seed, params->curve->seed->data,\n params->curve->seed->length);\n ret->seed_len = params->curve->seed->length;\n }\n if (!params->order || !params->base || !params->base->data) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);\n goto err;\n }\n if ((point = EC_POINT_new(ret)) == NULL)\n goto err;\n EC_GROUP_set_point_conversion_form(ret, (point_conversion_form_t)\n (params->base->data[0] & ~0x01));\n if (!EC_POINT_oct2point(ret, point, params->base->data,\n params->base->length, NULL)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);\n goto err;\n }\n if ((a = ASN1_INTEGER_to_BN(params->order, a)) == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);\n goto err;\n }\n if (BN_is_negative(a) || BN_is_zero(a)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_GROUP_ORDER);\n goto err;\n }\n if (BN_num_bits(a) > (int)field_bits + 1) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_GROUP_ORDER);\n goto err;\n }\n if (params->cofactor == NULL) {\n BN_free(b);\n b = NULL;\n } else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);\n goto err;\n }\n if (!EC_GROUP_set_generator(ret, point, a, b)) {\n ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);\n goto err;\n }\n ok = 1;\n err:\n if (!ok) {\n EC_GROUP_clear_free(ret);\n ret = NULL;\n }\n BN_free(p);\n BN_free(a);\n BN_free(b);\n EC_POINT_free(point);\n return (ret);\n}', '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}', 'int BN_set_bit(BIGNUM *a, int n)\n{\n int i, j, k;\n if (n < 0)\n return 0;\n i = n / BN_BITS2;\n j = n % BN_BITS2;\n if (a->top <= i) {\n if (bn_wexpand(a, i + 1) == NULL)\n return (0);\n for (k = a->top; k < i + 1; k++)\n a->d[k] = 0;\n a->top = i + 1;\n }\n a->d[i] |= (((BN_ULONG)1) << j);\n bn_check_top(a);\n return (1);\n}', 'BIGNUM *bn_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}']
2,532
0
https://github.com/libav/libav/blob/e5d403720ec4914169f55913a5a5555d908500b6/libavcodec/h264.c/#L407
static void await_references(H264Context *h) { MpegEncContext *const s = &h->s; const int mb_xy = h->mb_xy; const int mb_type = s->current_picture.f.mb_type[mb_xy]; int refs[2][48]; int nrefs[2] = { 0 }; int ref, list; memset(refs, -1, sizeof(refs)); if (IS_16X16(mb_type)) { get_lowest_part_y(h, refs, 0, 16, 0, IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); } else if (IS_16X8(mb_type)) { get_lowest_part_y(h, refs, 0, 8, 0, IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, 8, 8, 8, IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs); } else if (IS_8X16(mb_type)) { get_lowest_part_y(h, refs, 0, 16, 0, IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, 4, 16, 0, IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs); } else { int i; assert(IS_8X8(mb_type)); for (i = 0; i < 4; i++) { const int sub_mb_type = h->sub_mb_type[i]; const int n = 4 * i; int y_offset = (i & 2) << 2; if (IS_SUB_8X8(sub_mb_type)) { get_lowest_part_y(h, refs, n, 8, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); } else if (IS_SUB_8X4(sub_mb_type)) { get_lowest_part_y(h, refs, n, 4, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, n + 2, 4, y_offset + 4, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); } else if (IS_SUB_4X8(sub_mb_type)) { get_lowest_part_y(h, refs, n, 8, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, n + 1, 8, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); } else { int j; assert(IS_SUB_4X4(sub_mb_type)); for (j = 0; j < 4; j++) { int sub_y_offset = y_offset + 2 * (j & 2); get_lowest_part_y(h, refs, n + j, 4, sub_y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); } } } } for (list = h->list_count - 1; list >= 0; list--) for (ref = 0; ref < 48 && nrefs[list]; ref++) { int row = refs[list][ref]; if (row >= 0) { Picture *ref_pic = &h->ref_list[list][ref]; int ref_field = ref_pic->f.reference - 1; int ref_field_picture = ref_pic->field_picture; int pic_height = 16 * s->mb_height >> ref_field_picture; row <<= MB_MBAFF; nrefs[list]--; if (!FIELD_PICTURE && ref_field_picture) { ff_thread_await_progress(&ref_pic->f, FFMIN((row >> 1) - !(row & 1), pic_height - 1), 1); ff_thread_await_progress(&ref_pic->f, FFMIN((row >> 1), pic_height - 1), 0); } else if (FIELD_PICTURE && !ref_field_picture) { ff_thread_await_progress(&ref_pic->f, FFMIN(row * 2 + ref_field, pic_height - 1), 0); } else if (FIELD_PICTURE) { ff_thread_await_progress(&ref_pic->f, FFMIN(row, pic_height - 1), ref_field); } else { ff_thread_await_progress(&ref_pic->f, FFMIN(row, pic_height - 1), 0); } } } }
['static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)\n{\n MpegEncContext *const s = &h->s;\n AVCodecContext *const avctx = s->avctx;\n H264Context *hx;\n int buf_index;\n int context_count;\n int next_avc;\n int pass = !(avctx->active_thread_type & FF_THREAD_FRAME);\n int nals_needed = 0;\n int nal_index;\n h->max_contexts = s->slice_context_count;\n if (!(s->flags2 & CODEC_FLAG2_CHUNKS)) {\n h->current_slice = 0;\n if (!s->first_field)\n s->current_picture_ptr = NULL;\n ff_h264_reset_sei(h);\n }\n for (; pass <= 1; pass++) {\n buf_index = 0;\n context_count = 0;\n next_avc = h->is_avc ? 0 : buf_size;\n nal_index = 0;\n for (;;) {\n int consumed;\n int dst_length;\n int bit_length;\n const uint8_t *ptr;\n int i, nalsize = 0;\n int err;\n if (buf_index >= next_avc) {\n if (buf_index >= buf_size - h->nal_length_size)\n break;\n nalsize = 0;\n for (i = 0; i < h->nal_length_size; i++)\n nalsize = (nalsize << 8) | buf[buf_index++];\n if (nalsize <= 0 || nalsize > buf_size - buf_index) {\n av_log(h->s.avctx, AV_LOG_ERROR,\n "AVC: nal size %d\\n", nalsize);\n break;\n }\n next_avc = buf_index + nalsize;\n } else {\n for (; buf_index + 3 < next_avc; buf_index++)\n if (buf[buf_index] == 0 &&\n buf[buf_index + 1] == 0 &&\n buf[buf_index + 2] == 1)\n break;\n if (buf_index + 3 >= buf_size)\n break;\n buf_index += 3;\n if (buf_index >= next_avc)\n continue;\n }\n hx = h->thread_context[context_count];\n ptr = ff_h264_decode_nal(hx, buf + buf_index, &dst_length,\n &consumed, next_avc - buf_index);\n if (ptr == NULL || dst_length < 0)\n return -1;\n i = buf_index + consumed;\n if ((s->workaround_bugs & FF_BUG_AUTODETECT) && i + 3 < next_avc &&\n buf[i] == 0x00 && buf[i + 1] == 0x00 &&\n buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)\n s->workaround_bugs |= FF_BUG_TRUNCATED;\n if (!(s->workaround_bugs & FF_BUG_TRUNCATED))\n while (ptr[dst_length - 1] == 0 && dst_length > 0)\n dst_length--;\n bit_length = !dst_length ? 0\n : (8 * dst_length -\n ff_h264_decode_rbsp_trailing(h, ptr + dst_length - 1));\n if (s->avctx->debug & FF_DEBUG_STARTCODE)\n av_log(h->s.avctx, AV_LOG_DEBUG,\n "NAL %d at %d/%d length %d\\n",\n hx->nal_unit_type, buf_index, buf_size, dst_length);\n if (h->is_avc && (nalsize != consumed) && nalsize)\n av_log(h->s.avctx, AV_LOG_DEBUG,\n "AVC: Consumed only %d bytes instead of %d\\n",\n consumed, nalsize);\n buf_index += consumed;\n nal_index++;\n if (pass == 0) {\n switch (hx->nal_unit_type) {\n case NAL_SPS:\n case NAL_PPS:\n nals_needed = nal_index;\n break;\n case NAL_IDR_SLICE:\n case NAL_SLICE:\n init_get_bits(&hx->s.gb, ptr, bit_length);\n if (!get_ue_golomb(&hx->s.gb))\n nals_needed = nal_index;\n }\n continue;\n }\n if (avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0)\n continue;\nagain:\n err = 0;\n switch (hx->nal_unit_type) {\n case NAL_IDR_SLICE:\n if (h->nal_unit_type != NAL_IDR_SLICE) {\n av_log(h->s.avctx, AV_LOG_ERROR,\n "Invalid mix of idr and non-idr slices");\n return -1;\n }\n idr(h);\n case NAL_SLICE:\n init_get_bits(&hx->s.gb, ptr, bit_length);\n hx->intra_gb_ptr =\n hx->inter_gb_ptr = &hx->s.gb;\n hx->s.data_partitioning = 0;\n if ((err = decode_slice_header(hx, h)))\n break;\n s->current_picture_ptr->f.key_frame |=\n (hx->nal_unit_type == NAL_IDR_SLICE) ||\n (h->sei_recovery_frame_cnt >= 0);\n if (h->current_slice == 1) {\n if (!(s->flags2 & CODEC_FLAG2_CHUNKS))\n decode_postinit(h, nal_index >= nals_needed);\n if (s->avctx->hwaccel &&\n s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0)\n return -1;\n if (CONFIG_H264_VDPAU_DECODER &&\n s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)\n ff_vdpau_h264_picture_start(s);\n }\n if (hx->redundant_pic_count == 0 &&\n (avctx->skip_frame < AVDISCARD_NONREF ||\n hx->nal_ref_idc) &&\n (avctx->skip_frame < AVDISCARD_BIDIR ||\n hx->slice_type_nos != AV_PICTURE_TYPE_B) &&\n (avctx->skip_frame < AVDISCARD_NONKEY ||\n hx->slice_type_nos == AV_PICTURE_TYPE_I) &&\n avctx->skip_frame < AVDISCARD_ALL) {\n if (avctx->hwaccel) {\n if (avctx->hwaccel->decode_slice(avctx,\n &buf[buf_index - consumed],\n consumed) < 0)\n return -1;\n } else if (CONFIG_H264_VDPAU_DECODER &&\n s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) {\n static const uint8_t start_code[] = {\n 0x00, 0x00, 0x01 };\n ff_vdpau_add_data_chunk(s, start_code,\n sizeof(start_code));\n ff_vdpau_add_data_chunk(s, &buf[buf_index - consumed],\n consumed);\n } else\n context_count++;\n }\n break;\n case NAL_DPA:\n init_get_bits(&hx->s.gb, ptr, bit_length);\n hx->intra_gb_ptr =\n hx->inter_gb_ptr = NULL;\n if ((err = decode_slice_header(hx, h)) < 0)\n break;\n hx->s.data_partitioning = 1;\n break;\n case NAL_DPB:\n init_get_bits(&hx->intra_gb, ptr, bit_length);\n hx->intra_gb_ptr = &hx->intra_gb;\n break;\n case NAL_DPC:\n init_get_bits(&hx->inter_gb, ptr, bit_length);\n hx->inter_gb_ptr = &hx->inter_gb;\n if (hx->redundant_pic_count == 0 &&\n hx->intra_gb_ptr &&\n hx->s.data_partitioning &&\n s->context_initialized &&\n (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) &&\n (avctx->skip_frame < AVDISCARD_BIDIR ||\n hx->slice_type_nos != AV_PICTURE_TYPE_B) &&\n (avctx->skip_frame < AVDISCARD_NONKEY ||\n hx->slice_type_nos == AV_PICTURE_TYPE_I) &&\n avctx->skip_frame < AVDISCARD_ALL)\n context_count++;\n break;\n case NAL_SEI:\n init_get_bits(&s->gb, ptr, bit_length);\n ff_h264_decode_sei(h);\n break;\n case NAL_SPS:\n init_get_bits(&s->gb, ptr, bit_length);\n if (ff_h264_decode_seq_parameter_set(h) < 0 &&\n h->is_avc && (nalsize != consumed) && nalsize) {\n av_log(h->s.avctx, AV_LOG_DEBUG,\n "SPS decoding failure, try parsing the coomplete NAL\\n");\n init_get_bits(&s->gb, buf + buf_index + 1 - consumed,\n 8 * (nalsize - 1));\n ff_h264_decode_seq_parameter_set(h);\n }\n if (s->flags & CODEC_FLAG_LOW_DELAY ||\n (h->sps.bitstream_restriction_flag &&\n !h->sps.num_reorder_frames))\n s->low_delay = 1;\n if (avctx->has_b_frames < 2)\n avctx->has_b_frames = !s->low_delay;\n if (avctx->bits_per_raw_sample != h->sps.bit_depth_luma ||\n h->cur_chroma_format_idc != h->sps.chroma_format_idc) {\n if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10) {\n avctx->bits_per_raw_sample = h->sps.bit_depth_luma;\n h->cur_chroma_format_idc = h->sps.chroma_format_idc;\n h->pixel_shift = h->sps.bit_depth_luma > 8;\n ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma,\n h->sps.chroma_format_idc);\n ff_h264_pred_init(&h->hpc, s->codec_id,\n h->sps.bit_depth_luma,\n h->sps.chroma_format_idc);\n s->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16;\n ff_dsputil_init(&s->dsp, s->avctx);\n } else {\n av_log(avctx, AV_LOG_ERROR,\n "Unsupported bit depth: %d\\n",\n h->sps.bit_depth_luma);\n return -1;\n }\n }\n break;\n case NAL_PPS:\n init_get_bits(&s->gb, ptr, bit_length);\n ff_h264_decode_picture_parameter_set(h, bit_length);\n break;\n case NAL_AUD:\n case NAL_END_SEQUENCE:\n case NAL_END_STREAM:\n case NAL_FILLER_DATA:\n case NAL_SPS_EXT:\n case NAL_AUXILIARY_SLICE:\n break;\n default:\n av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\\n",\n hx->nal_unit_type, bit_length);\n }\n if (context_count == h->max_contexts) {\n execute_decode_slices(h, context_count);\n context_count = 0;\n }\n if (err < 0)\n av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\\n");\n else if (err == 1) {\n h->nal_unit_type = hx->nal_unit_type;\n h->nal_ref_idc = hx->nal_ref_idc;\n hx = h;\n goto again;\n }\n }\n }\n if (context_count)\n execute_decode_slices(h, context_count);\n return buf_index;\n}', 'static int decode_slice_header(H264Context *h, H264Context *h0)\n{\n MpegEncContext *const s = &h->s;\n MpegEncContext *const s0 = &h0->s;\n unsigned int first_mb_in_slice;\n unsigned int pps_id;\n int num_ref_idx_active_override_flag;\n unsigned int slice_type, tmp, i, j;\n int default_ref_list_done = 0;\n int last_pic_structure;\n s->dropable = h->nal_ref_idc == 0;\n if ((s->avctx->flags2 & CODEC_FLAG2_FAST) &&\n !h->nal_ref_idc && !h->pixel_shift) {\n s->me.qpel_put = s->dsp.put_2tap_qpel_pixels_tab;\n s->me.qpel_avg = s->dsp.avg_2tap_qpel_pixels_tab;\n } else {\n s->me.qpel_put = s->dsp.put_h264_qpel_pixels_tab;\n s->me.qpel_avg = s->dsp.avg_h264_qpel_pixels_tab;\n }\n first_mb_in_slice = get_ue_golomb(&s->gb);\n if (first_mb_in_slice == 0) {\n if (h0->current_slice && FIELD_PICTURE) {\n field_end(h, 1);\n }\n h0->current_slice = 0;\n if (!s0->first_field)\n s->current_picture_ptr = NULL;\n }\n slice_type = get_ue_golomb_31(&s->gb);\n if (slice_type > 9) {\n av_log(h->s.avctx, AV_LOG_ERROR,\n "slice type too large (%d) at %d %d\\n",\n h->slice_type, s->mb_x, s->mb_y);\n return -1;\n }\n if (slice_type > 4) {\n slice_type -= 5;\n h->slice_type_fixed = 1;\n } else\n h->slice_type_fixed = 0;\n slice_type = golomb_to_pict_type[slice_type];\n if (slice_type == AV_PICTURE_TYPE_I ||\n (h0->current_slice != 0 && slice_type == h0->last_slice_type)) {\n default_ref_list_done = 1;\n }\n h->slice_type = slice_type;\n h->slice_type_nos = slice_type & 3;\n s->pict_type = h->slice_type;\n pps_id = get_ue_golomb(&s->gb);\n if (pps_id >= MAX_PPS_COUNT) {\n av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\\n");\n return -1;\n }\n if (!h0->pps_buffers[pps_id]) {\n av_log(h->s.avctx, AV_LOG_ERROR,\n "non-existing PPS %u referenced\\n",\n pps_id);\n return -1;\n }\n h->pps = *h0->pps_buffers[pps_id];\n if (!h0->sps_buffers[h->pps.sps_id]) {\n av_log(h->s.avctx, AV_LOG_ERROR,\n "non-existing SPS %u referenced\\n",\n h->pps.sps_id);\n return -1;\n }\n h->sps = *h0->sps_buffers[h->pps.sps_id];\n s->avctx->profile = ff_h264_get_profile(&h->sps);\n s->avctx->level = h->sps.level_idc;\n s->avctx->refs = h->sps.ref_frame_count;\n s->mb_width = h->sps.mb_width;\n s->mb_height = h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);\n h->b_stride = s->mb_width * 4;\n s->chroma_y_shift = h->sps.chroma_format_idc <= 1;\n s->width = 16 * s->mb_width - (2 >> CHROMA444) * FFMIN(h->sps.crop_right, (8 << CHROMA444) - 1);\n if (h->sps.frame_mbs_only_flag)\n s->height = 16 * s->mb_height - (1 << s->chroma_y_shift) * FFMIN(h->sps.crop_bottom, (16 >> s->chroma_y_shift) - 1);\n else\n s->height = 16 * s->mb_height - (2 << s->chroma_y_shift) * FFMIN(h->sps.crop_bottom, (16 >> s->chroma_y_shift) - 1);\n if (s->context_initialized &&\n (s->width != s->avctx->width || s->height != s->avctx->height ||\n av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {\n if (h != h0) {\n av_log_missing_feature(s->avctx,\n "Width/height changing with threads is", 0);\n return -1;\n }\n free_tables(h, 0);\n flush_dpb(s->avctx);\n ff_MPV_common_end(s);\n }\n if (!s->context_initialized) {\n if (h != h0) {\n av_log(h->s.avctx, AV_LOG_ERROR,\n "Cannot (re-)initialize context during parallel decoding.\\n");\n return -1;\n }\n avcodec_set_dimensions(s->avctx, s->width, s->height);\n s->avctx->sample_aspect_ratio = h->sps.sar;\n av_assert0(s->avctx->sample_aspect_ratio.den);\n if (h->sps.video_signal_type_present_flag) {\n s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG\n : AVCOL_RANGE_MPEG;\n if (h->sps.colour_description_present_flag) {\n s->avctx->color_primaries = h->sps.color_primaries;\n s->avctx->color_trc = h->sps.color_trc;\n s->avctx->colorspace = h->sps.colorspace;\n }\n }\n if (h->sps.timing_info_present_flag) {\n int64_t den = h->sps.time_scale;\n if (h->x264_build < 44U)\n den *= 2;\n av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,\n h->sps.num_units_in_tick, den, 1 << 30);\n }\n switch (h->sps.bit_depth_luma) {\n case 9:\n if (CHROMA444) {\n if (s->avctx->colorspace == AVCOL_SPC_RGB) {\n s->avctx->pix_fmt = PIX_FMT_GBRP9;\n } else\n s->avctx->pix_fmt = PIX_FMT_YUV444P9;\n } else if (CHROMA422)\n s->avctx->pix_fmt = PIX_FMT_YUV422P9;\n else\n s->avctx->pix_fmt = PIX_FMT_YUV420P9;\n break;\n case 10:\n if (CHROMA444) {\n if (s->avctx->colorspace == AVCOL_SPC_RGB) {\n s->avctx->pix_fmt = PIX_FMT_GBRP10;\n } else\n s->avctx->pix_fmt = PIX_FMT_YUV444P10;\n } else if (CHROMA422)\n s->avctx->pix_fmt = PIX_FMT_YUV422P10;\n else\n s->avctx->pix_fmt = PIX_FMT_YUV420P10;\n break;\n case 8:\n if (CHROMA444) {\n if (s->avctx->colorspace == AVCOL_SPC_RGB) {\n s->avctx->pix_fmt = PIX_FMT_GBRP;\n } else\n s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P\n : PIX_FMT_YUV444P;\n } else if (CHROMA422) {\n s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ422P\n : PIX_FMT_YUV422P;\n } else {\n s->avctx->pix_fmt = s->avctx->get_format(s->avctx,\n s->avctx->codec->pix_fmts ?\n s->avctx->codec->pix_fmts :\n s->avctx->color_range == AVCOL_RANGE_JPEG ?\n hwaccel_pixfmt_list_h264_jpeg_420 :\n ff_hwaccel_pixfmt_list_420);\n }\n break;\n default:\n av_log(s->avctx, AV_LOG_ERROR,\n "Unsupported bit depth: %d\\n", h->sps.bit_depth_luma);\n return AVERROR_INVALIDDATA;\n }\n s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id,\n s->avctx->pix_fmt);\n if (ff_MPV_common_init(s) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "ff_MPV_common_init() failed.\\n");\n return -1;\n }\n s->first_field = 0;\n h->prev_interlaced_frame = 1;\n init_scan_tables(h);\n if (ff_h264_alloc_tables(h) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR,\n "Could not allocate memory for h264\\n");\n return AVERROR(ENOMEM);\n }\n if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_SLICE)) {\n if (context_init(h) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\\n");\n return -1;\n }\n } else {\n for (i = 1; i < s->slice_context_count; i++) {\n H264Context *c;\n c = h->thread_context[i] = av_malloc(sizeof(H264Context));\n memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));\n memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext));\n c->h264dsp = h->h264dsp;\n c->sps = h->sps;\n c->pps = h->pps;\n c->pixel_shift = h->pixel_shift;\n init_scan_tables(c);\n clone_tables(c, h, i);\n }\n for (i = 0; i < s->slice_context_count; i++)\n if (context_init(h->thread_context[i]) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR,\n "context_init() failed.\\n");\n return -1;\n }\n }\n }\n if (h == h0 && h->dequant_coeff_pps != pps_id) {\n h->dequant_coeff_pps = pps_id;\n init_dequant_tables(h);\n }\n h->frame_num = get_bits(&s->gb, h->sps.log2_max_frame_num);\n h->mb_mbaff = 0;\n h->mb_aff_frame = 0;\n last_pic_structure = s0->picture_structure;\n if (h->sps.frame_mbs_only_flag) {\n s->picture_structure = PICT_FRAME;\n } else {\n if (get_bits1(&s->gb)) {\n s->picture_structure = PICT_TOP_FIELD + get_bits1(&s->gb);\n } else {\n s->picture_structure = PICT_FRAME;\n h->mb_aff_frame = h->sps.mb_aff;\n }\n }\n h->mb_field_decoding_flag = s->picture_structure != PICT_FRAME;\n if (h0->current_slice == 0) {\n if (h->frame_num != h->prev_frame_num) {\n int unwrap_prev_frame_num = h->prev_frame_num;\n int max_frame_num = 1 << h->sps.log2_max_frame_num;\n if (unwrap_prev_frame_num > h->frame_num)\n unwrap_prev_frame_num -= max_frame_num;\n if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) {\n unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1;\n if (unwrap_prev_frame_num < 0)\n unwrap_prev_frame_num += max_frame_num;\n h->prev_frame_num = unwrap_prev_frame_num;\n }\n }\n while (h->frame_num != h->prev_frame_num &&\n h->frame_num != (h->prev_frame_num + 1) % (1 << h->sps.log2_max_frame_num)) {\n Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;\n av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\\n",\n h->frame_num, h->prev_frame_num);\n if (ff_h264_frame_start(h) < 0)\n return -1;\n h->prev_frame_num++;\n h->prev_frame_num %= 1 << h->sps.log2_max_frame_num;\n s->current_picture_ptr->frame_num = h->prev_frame_num;\n ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0);\n ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 1);\n ff_generate_sliding_window_mmcos(h);\n if (ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index) < 0 &&\n (s->avctx->err_recognition & AV_EF_EXPLODE))\n return AVERROR_INVALIDDATA;\n if (h->short_ref_count) {\n if (prev) {\n av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize,\n (const uint8_t **)prev->f.data, prev->f.linesize,\n s->avctx->pix_fmt, s->mb_width * 16, s->mb_height * 16);\n h->short_ref[0]->poc = prev->poc + 2;\n }\n h->short_ref[0]->frame_num = h->prev_frame_num;\n }\n }\n if (s0->first_field) {\n assert(s0->current_picture_ptr);\n assert(s0->current_picture_ptr->f.data[0]);\n assert(s0->current_picture_ptr->f.reference != DELAYED_PIC_REF);\n if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {\n s0->current_picture_ptr = NULL;\n s0->first_field = FIELD_PICTURE;\n } else {\n if (h->nal_ref_idc &&\n s0->current_picture_ptr->f.reference &&\n s0->current_picture_ptr->frame_num != h->frame_num) {\n s0->first_field = 1;\n s0->current_picture_ptr = NULL;\n } else {\n s0->first_field = 0;\n }\n }\n } else {\n assert(!s0->current_picture_ptr);\n s0->first_field = FIELD_PICTURE;\n }\n if (!FIELD_PICTURE || s0->first_field) {\n if (ff_h264_frame_start(h) < 0) {\n s0->first_field = 0;\n return -1;\n }\n } else {\n ff_release_unused_pictures(s, 0);\n }\n }\n if (h != h0)\n clone_slice(h, h0);\n s->current_picture_ptr->frame_num = h->frame_num;\n assert(s->mb_num == s->mb_width * s->mb_height);\n if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num ||\n first_mb_in_slice >= s->mb_num) {\n av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\\n");\n return -1;\n }\n s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;\n s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE;\n if (s->picture_structure == PICT_BOTTOM_FIELD)\n s->resync_mb_y = s->mb_y = s->mb_y + 1;\n assert(s->mb_y < s->mb_height);\n if (s->picture_structure == PICT_FRAME) {\n h->curr_pic_num = h->frame_num;\n h->max_pic_num = 1 << h->sps.log2_max_frame_num;\n } else {\n h->curr_pic_num = 2 * h->frame_num + 1;\n h->max_pic_num = 1 << (h->sps.log2_max_frame_num + 1);\n }\n if (h->nal_unit_type == NAL_IDR_SLICE)\n get_ue_golomb(&s->gb);\n if (h->sps.poc_type == 0) {\n h->poc_lsb = get_bits(&s->gb, h->sps.log2_max_poc_lsb);\n if (h->pps.pic_order_present == 1 && s->picture_structure == PICT_FRAME)\n h->delta_poc_bottom = get_se_golomb(&s->gb);\n }\n if (h->sps.poc_type == 1 && !h->sps.delta_pic_order_always_zero_flag) {\n h->delta_poc[0] = get_se_golomb(&s->gb);\n if (h->pps.pic_order_present == 1 && s->picture_structure == PICT_FRAME)\n h->delta_poc[1] = get_se_golomb(&s->gb);\n }\n init_poc(h);\n if (h->pps.redundant_pic_cnt_present)\n h->redundant_pic_count = get_ue_golomb(&s->gb);\n h->ref_count[0] = h->pps.ref_count[0];\n h->ref_count[1] = h->pps.ref_count[1];\n if (h->slice_type_nos != AV_PICTURE_TYPE_I) {\n int max_refs = s->picture_structure == PICT_FRAME ? 16 : 32;\n if (h->slice_type_nos == AV_PICTURE_TYPE_B)\n h->direct_spatial_mv_pred = get_bits1(&s->gb);\n num_ref_idx_active_override_flag = get_bits1(&s->gb);\n if (num_ref_idx_active_override_flag) {\n h->ref_count[0] = get_ue_golomb(&s->gb) + 1;\n if (h->slice_type_nos == AV_PICTURE_TYPE_B)\n h->ref_count[1] = get_ue_golomb(&s->gb) + 1;\n }\n if (h->ref_count[0] > max_refs || h->ref_count[1] > max_refs) {\n av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\\n");\n h->ref_count[0] = h->ref_count[1] = 1;\n return AVERROR_INVALIDDATA;\n }\n if (h->slice_type_nos == AV_PICTURE_TYPE_B)\n h->list_count = 2;\n else\n h->list_count = 1;\n } else\n h->list_count = 0;\n if (!default_ref_list_done)\n ff_h264_fill_default_ref_list(h);\n if (h->slice_type_nos != AV_PICTURE_TYPE_I &&\n ff_h264_decode_ref_pic_list_reordering(h) < 0) {\n h->ref_count[1] = h->ref_count[0] = 0;\n return -1;\n }\n if (h->slice_type_nos != AV_PICTURE_TYPE_I) {\n s->last_picture_ptr = &h->ref_list[0][0];\n ff_copy_picture(&s->last_picture, s->last_picture_ptr);\n }\n if (h->slice_type_nos == AV_PICTURE_TYPE_B) {\n s->next_picture_ptr = &h->ref_list[1][0];\n ff_copy_picture(&s->next_picture, s->next_picture_ptr);\n }\n if ((h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P) ||\n (h->pps.weighted_bipred_idc == 1 &&\n h->slice_type_nos == AV_PICTURE_TYPE_B))\n pred_weight_table(h);\n else if (h->pps.weighted_bipred_idc == 2 &&\n h->slice_type_nos == AV_PICTURE_TYPE_B) {\n implicit_weight_table(h, -1);\n } else {\n h->use_weight = 0;\n for (i = 0; i < 2; i++) {\n h->luma_weight_flag[i] = 0;\n h->chroma_weight_flag[i] = 0;\n }\n }\n if (h->nal_ref_idc && ff_h264_decode_ref_pic_marking(h0, &s->gb) < 0 &&\n (s->avctx->err_recognition & AV_EF_EXPLODE))\n return AVERROR_INVALIDDATA;\n if (FRAME_MBAFF) {\n ff_h264_fill_mbaff_ref_list(h);\n if (h->pps.weighted_bipred_idc == 2 && h->slice_type_nos == AV_PICTURE_TYPE_B) {\n implicit_weight_table(h, 0);\n implicit_weight_table(h, 1);\n }\n }\n if (h->slice_type_nos == AV_PICTURE_TYPE_B && !h->direct_spatial_mv_pred)\n ff_h264_direct_dist_scale_factor(h);\n ff_h264_direct_ref_list_init(h);\n if (h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac) {\n tmp = get_ue_golomb_31(&s->gb);\n if (tmp > 2) {\n av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\\n");\n return -1;\n }\n h->cabac_init_idc = tmp;\n }\n h->last_qscale_diff = 0;\n tmp = h->pps.init_qp + get_se_golomb(&s->gb);\n if (tmp > 51 + 6 * (h->sps.bit_depth_luma - 8)) {\n av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n return -1;\n }\n s->qscale = tmp;\n h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n if (h->slice_type == AV_PICTURE_TYPE_SP)\n get_bits1(&s->gb);\n if (h->slice_type == AV_PICTURE_TYPE_SP ||\n h->slice_type == AV_PICTURE_TYPE_SI)\n get_se_golomb(&s->gb);\n h->deblocking_filter = 1;\n h->slice_alpha_c0_offset = 52;\n h->slice_beta_offset = 52;\n if (h->pps.deblocking_filter_parameters_present) {\n tmp = get_ue_golomb_31(&s->gb);\n if (tmp > 2) {\n av_log(s->avctx, AV_LOG_ERROR,\n "deblocking_filter_idc %u out of range\\n", tmp);\n return -1;\n }\n h->deblocking_filter = tmp;\n if (h->deblocking_filter < 2)\n h->deblocking_filter ^= 1;\n if (h->deblocking_filter) {\n h->slice_alpha_c0_offset += get_se_golomb(&s->gb) << 1;\n h->slice_beta_offset += get_se_golomb(&s->gb) << 1;\n if (h->slice_alpha_c0_offset > 104U ||\n h->slice_beta_offset > 104U) {\n av_log(s->avctx, AV_LOG_ERROR,\n "deblocking filter parameters %d %d out of range\\n",\n h->slice_alpha_c0_offset, h->slice_beta_offset);\n return -1;\n }\n }\n }\n if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||\n (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&\n h->slice_type_nos != AV_PICTURE_TYPE_I) ||\n (s->avctx->skip_loop_filter >= AVDISCARD_BIDIR &&\n h->slice_type_nos == AV_PICTURE_TYPE_B) ||\n (s->avctx->skip_loop_filter >= AVDISCARD_NONREF &&\n h->nal_ref_idc == 0))\n h->deblocking_filter = 0;\n if (h->deblocking_filter == 1 && h0->max_contexts > 1) {\n if (s->avctx->flags2 & CODEC_FLAG2_FAST) {\n h->deblocking_filter = 2;\n } else {\n h0->max_contexts = 1;\n if (!h0->single_decode_warning) {\n av_log(s->avctx, AV_LOG_INFO,\n "Cannot parallelize deblocking type 1, decoding such frames in sequential order\\n");\n h0->single_decode_warning = 1;\n }\n if (h != h0) {\n av_log(h->s.avctx, AV_LOG_ERROR,\n "Deblocking switched inside frame.\\n");\n return 1;\n }\n }\n }\n h->qp_thresh = 15 + 52 -\n FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset) -\n FFMAX3(0,\n h->pps.chroma_qp_index_offset[0],\n h->pps.chroma_qp_index_offset[1]) +\n 6 * (h->sps.bit_depth_luma - 8);\n h0->last_slice_type = slice_type;\n h->slice_num = ++h0->current_slice;\n if (h->slice_num >= MAX_SLICES) {\n av_log(s->avctx, AV_LOG_ERROR,\n "Too many slices, increase MAX_SLICES and recompile\\n");\n }\n for (j = 0; j < 2; j++) {\n int id_list[16];\n int *ref2frm = h->ref2frm[h->slice_num & (MAX_SLICES - 1)][j];\n for (i = 0; i < 16; i++) {\n id_list[i] = 60;\n if (h->ref_list[j][i].f.data[0]) {\n int k;\n uint8_t *base = h->ref_list[j][i].f.base[0];\n for (k = 0; k < h->short_ref_count; k++)\n if (h->short_ref[k]->f.base[0] == base) {\n id_list[i] = k;\n break;\n }\n for (k = 0; k < h->long_ref_count; k++)\n if (h->long_ref[k] && h->long_ref[k]->f.base[0] == base) {\n id_list[i] = h->short_ref_count + k;\n break;\n }\n }\n }\n ref2frm[0] =\n ref2frm[1] = -1;\n for (i = 0; i < 16; i++)\n ref2frm[i + 2] = 4 * id_list[i] +\n (h->ref_list[j][i].f.reference & 3);\n ref2frm[18 + 0] =\n ref2frm[18 + 1] = -1;\n for (i = 16; i < 48; i++)\n ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] +\n (h->ref_list[j][i].f.reference & 3);\n }\n h->emu_edge_width = (s->flags & CODEC_FLAG_EMU_EDGE ||\n (!h->sps.frame_mbs_only_flag &&\n s->avctx->active_thread_type))\n ? 0 : 16;\n h->emu_edge_height = (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;\n if (s->avctx->debug & FF_DEBUG_PICT_INFO) {\n av_log(h->s.avctx, AV_LOG_DEBUG,\n "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\\n",\n h->slice_num,\n (s->picture_structure == PICT_FRAME ? "F" : s->picture_structure == PICT_TOP_FIELD ? "T" : "B"),\n first_mb_in_slice,\n av_get_picture_type_char(h->slice_type),\n h->slice_type_fixed ? " fix" : "",\n h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",\n pps_id, h->frame_num,\n s->current_picture_ptr->field_poc[0],\n s->current_picture_ptr->field_poc[1],\n h->ref_count[0], h->ref_count[1],\n s->qscale,\n h->deblocking_filter,\n h->slice_alpha_c0_offset / 2 - 26, h->slice_beta_offset / 2 - 26,\n h->use_weight,\n h->use_weight == 1 && h->use_weight_chroma ? "c" : "",\n h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");\n }\n return 0;\n}', 'static int field_end(H264Context *h, int in_setup)\n{\n MpegEncContext *const s = &h->s;\n AVCodecContext *const avctx = s->avctx;\n int err = 0;\n s->mb_y = 0;\n if (!in_setup && !s->dropable)\n ff_thread_report_progress(&s->current_picture_ptr->f,\n (16 * s->mb_height >> FIELD_PICTURE) - 1,\n s->picture_structure == PICT_BOTTOM_FIELD);\n if (CONFIG_H264_VDPAU_DECODER &&\n s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)\n ff_vdpau_h264_set_reference_frames(s);\n if (in_setup || !(avctx->active_thread_type & FF_THREAD_FRAME)) {\n if (!s->dropable) {\n err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);\n h->prev_poc_msb = h->poc_msb;\n h->prev_poc_lsb = h->poc_lsb;\n }\n h->prev_frame_num_offset = h->frame_num_offset;\n h->prev_frame_num = h->frame_num;\n h->outputed_poc = h->next_outputed_poc;\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_H264_VDPAU_DECODER &&\n s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)\n ff_vdpau_h264_picture_complete(s);\n if (!FIELD_PICTURE)\n ff_er_frame_end(s);\n ff_MPV_frame_end(s);\n h->current_slice = 0;\n return err;\n}', 'void ff_er_frame_end(MpegEncContext *s)\n{\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 int size = s->b8_stride * 2 * s->mb_height;\n Picture *pic = s->current_picture_ptr;\n if (!s->err_recognition || s->error_count == 0 || s->avctx->lowres ||\n s->avctx->hwaccel ||\n s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU ||\n s->picture_structure != PICT_FRAME ||\n s->error_count == 3 * s->mb_width *\n (s->avctx->skip_top + s->avctx->skip_bottom)) {\n return;\n };\n if (s->current_picture.f.motion_val[0] == NULL) {\n av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\\n");\n for (i = 0; i < 2; i++) {\n pic->f.ref_index[i] = av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t));\n pic->motion_val_base[i] = av_mallocz((size + 4) * 2 * sizeof(uint16_t));\n pic->f.motion_val[i] = pic->motion_val_base[i] + 4;\n }\n pic->f.motion_subsample_log2 = 3;\n s->current_picture = *s->current_picture_ptr;\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->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[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->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n else\n s->current_picture.f.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0;\n }\n if (!s->last_picture.f.data[0] && !s->next_picture.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->current_picture.f.mb_type[mb_xy]))\n s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n }\n for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n s->mb_x = 0;\n s->mb_y = mb_y;\n ff_init_block_index(s);\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->current_picture.f.mb_type[mb_xy];\n int dir = !s->last_picture.f.data[0];\n ff_update_block_index(s);\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 s->mv_dir = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD;\n s->mb_intra = 0;\n s->mb_skipped = 0;\n if (IS_8X8(mb_type)) {\n int mb_index = mb_x * 2 + mb_y * 2 * s->b8_stride;\n int j;\n s->mv_type = MV_TYPE_8X8;\n for (j = 0; j < 4; j++) {\n s->mv[0][j][0] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][0];\n s->mv[0][j][1] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][1];\n }\n } else {\n s->mv_type = MV_TYPE_16X16;\n s->mv[0][0][0] = s->current_picture.f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][0];\n s->mv[0][0][1] = s->current_picture.f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][1];\n }\n s->dsp.clear_blocks(s->block[0]);\n s->mb_x = mb_x;\n s->mb_y = mb_y;\n decode_mb(s, 0 );\n }\n }\n if (s->pict_type == AV_PICTURE_TYPE_B) {\n for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n s->mb_x = 0;\n s->mb_y = mb_y;\n ff_init_block_index(s);\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->current_picture.f.mb_type[mb_xy];\n ff_update_block_index(s);\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 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;\n if (!s->last_picture.f.data[0])\n s->mv_dir &= ~MV_DIR_FORWARD;\n if (!s->next_picture.f.data[0])\n s->mv_dir &= ~MV_DIR_BACKWARD;\n s->mb_intra = 0;\n s->mv_type = MV_TYPE_16X16;\n s->mb_skipped = 0;\n if (s->pp_time) {\n int time_pp = s->pp_time;\n int time_pb = s->pb_time;\n if (s->avctx->codec_id == CODEC_ID_H264) {\n } else {\n ff_thread_await_progress(&s->next_picture_ptr->f, mb_y, 0);\n }\n s->mv[0][0][0] = s->next_picture.f.motion_val[0][xy][0] * time_pb / time_pp;\n s->mv[0][0][1] = s->next_picture.f.motion_val[0][xy][1] * time_pb / time_pp;\n s->mv[1][0][0] = s->next_picture.f.motion_val[0][xy][0] * (time_pb - time_pp) / time_pp;\n s->mv[1][0][1] = s->next_picture.f.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->dsp.clear_blocks(s->block[0]);\n s->mb_x = mb_x;\n s->mb_y = mb_y;\n decode_mb(s, 0);\n }\n }\n } else\n guess_mv(s);\n if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)\n goto ec_clean;\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->current_picture.f.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->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize;\n dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize;\n dest_cr = s->current_picture.f.data[2] + mb_x * 8 + mb_y * 8 * s->uvlinesize;\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) * s->linesize];\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 * s->uvlinesize];\n dcv += dest_cr[x + y * s->uvlinesize];\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->current_picture.f.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->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize;\n dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize;\n dest_cr = s->current_picture.f.data[2] + mb_x * 8 + mb_y * 8 * s->uvlinesize;\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->current_picture.f.data[0], s->mb_width * 2,\n s->mb_height * 2, s->linesize, 1);\n h_block_filter(s, s->current_picture.f.data[1], s->mb_width,\n s->mb_height , s->uvlinesize, 0);\n h_block_filter(s, s->current_picture.f.data[2], s->mb_width,\n s->mb_height , s->uvlinesize, 0);\n v_block_filter(s, s->current_picture.f.data[0], s->mb_width * 2,\n s->mb_height * 2, s->linesize, 1);\n v_block_filter(s, s->current_picture.f.data[1], s->mb_width,\n s->mb_height , s->uvlinesize, 0);\n v_block_filter(s, s->current_picture.f.data[2], s->mb_width,\n s->mb_height , s->uvlinesize, 0);\n }\nec_clean:\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->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 s->mbintra_table[mb_xy] = 1;\n }\n}', 'static int is_intra_more_likely(MpegEncContext *s)\n{\n int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;\n if (!s->last_picture_ptr || !s->last_picture_ptr->f.data[0])\n return 1;\n undamaged_count = 0;\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n const int error = s->error_status_table[mb_xy];\n if (!((error & ER_DC_ERROR) && (error & ER_MV_ERROR)))\n undamaged_count++;\n }\n if (s->codec_id == CODEC_ID_H264) {\n H264Context *h = (void*) s;\n if (h->list_count <= 0 || h->ref_count[0] <= 0 ||\n !h->ref_list[0][0].f.data[0])\n return 1;\n }\n if (undamaged_count < 5)\n return 0;\n if (CONFIG_MPEG_XVMC_DECODER &&\n s->avctx->xvmc_acceleration &&\n s->pict_type == AV_PICTURE_TYPE_I)\n return 1;\n skip_amount = FFMAX(undamaged_count / 50, 1);\n is_intra_likely = 0;\n j = 0;\n for (mb_y = 0; mb_y < s->mb_height - 1; mb_y++) {\n for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n int error;\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n error = s->error_status_table[mb_xy];\n if ((error & ER_DC_ERROR) && (error & ER_MV_ERROR))\n continue;\n j++;\n if ((j % skip_amount) != 0)\n continue;\n if (s->pict_type == AV_PICTURE_TYPE_I) {\n uint8_t *mb_ptr = s->current_picture.f.data[0] +\n mb_x * 16 + mb_y * 16 * s->linesize;\n uint8_t *last_mb_ptr = s->last_picture.f.data[0] +\n mb_x * 16 + mb_y * 16 * s->linesize;\n if (s->avctx->codec_id == CODEC_ID_H264) {\n } else {\n ff_thread_await_progress(&s->last_picture_ptr->f,\n mb_y, 0);\n }\n is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr,\n s->linesize, 16);\n is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr,\n last_mb_ptr + s->linesize * 16,\n s->linesize, 16);\n } else {\n if (IS_INTRA(s->current_picture.f.mb_type[mb_xy]))\n is_intra_likely++;\n else\n is_intra_likely--;\n }\n }\n }\n return is_intra_likely > 0;\n}', 'static void decode_mb(MpegEncContext *s, int ref)\n{\n s->dest[0] = s->current_picture.f.data[0] + (s->mb_y * 16 * s->linesize) + s->mb_x * 16;\n s->dest[1] = s->current_picture.f.data[1] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);\n s->dest[2] = s->current_picture.f.data[2] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);\n if (CONFIG_H264_DECODER && s->codec_id == CODEC_ID_H264) {\n H264Context *h = (void*)s;\n h->mb_xy = s->mb_x + s->mb_y * s->mb_stride;\n memset(h->non_zero_count_cache, 0, sizeof(h->non_zero_count_cache));\n assert(ref >= 0);\n if (ref >= h->ref_count[0])\n ref = 0;\n fill_rectangle(&s->current_picture.f.ref_index[0][4 * h->mb_xy],\n 2, 2, 2, ref, 1);\n fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);\n fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8,\n pack16to32(s->mv[0][0][0], s->mv[0][0][1]), 4);\n assert(!FRAME_MBAFF);\n ff_h264_hl_decode_mb(h);\n } else {\n assert(ref == 0);\n ff_MPV_decode_mb(s, s->block);\n }\n}', 'void ff_h264_hl_decode_mb(H264Context *h)\n{\n MpegEncContext *const s = &h->s;\n const int mb_xy = h->mb_xy;\n const int mb_type = s->current_picture.f.mb_type[mb_xy];\n int is_complex = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0;\n if (CHROMA444) {\n if (is_complex || h->pixel_shift)\n hl_decode_mb_444_complex(h);\n else\n hl_decode_mb_444_simple(h);\n } else if (is_complex) {\n hl_decode_mb_complex(h);\n } else if (h->pixel_shift) {\n hl_decode_mb_simple_16(h);\n } else\n hl_decode_mb_simple_8(h);\n}', 'static void av_noinline hl_decode_mb_444_complex(H264Context *h)\n{\n hl_decode_mb_444_internal(h, 0, h->pixel_shift);\n}', 'static av_always_inline void hl_decode_mb_444_internal(H264Context *h,\n int simple,\n int pixel_shift)\n{\n MpegEncContext *const s = &h->s;\n const int mb_x = s->mb_x;\n const int mb_y = s->mb_y;\n const int mb_xy = h->mb_xy;\n const int mb_type = s->current_picture.f.mb_type[mb_xy];\n uint8_t *dest[3];\n int linesize;\n int i, j, p;\n int *block_offset = &h->block_offset[0];\n const int transform_bypass = !simple && (s->qscale == 0 && h->sps.transform_bypass);\n const int plane_count = (simple || !CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) ? 3 : 1;\n for (p = 0; p < plane_count; p++) {\n dest[p] = s->current_picture.f.data[p] +\n ((mb_x << pixel_shift) + mb_y * s->linesize) * 16;\n s->dsp.prefetch(dest[p] + (s->mb_x & 3) * 4 * s->linesize + (64 << pixel_shift),\n s->linesize, 4);\n }\n h->list_counts[mb_xy] = h->list_count;\n if (!simple && MB_FIELD) {\n linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize * 2;\n block_offset = &h->block_offset[48];\n if (mb_y & 1)\n for (p = 0; p < 3; p++)\n dest[p] -= s->linesize * 15;\n if (FRAME_MBAFF) {\n int list;\n for (list = 0; list < h->list_count; list++) {\n if (!USES_LIST(mb_type, list))\n continue;\n if (IS_16X16(mb_type)) {\n int8_t *ref = &h->ref_cache[list][scan8[0]];\n fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (s->mb_y & 1), 1);\n } else {\n for (i = 0; i < 16; i += 4) {\n int ref = h->ref_cache[list][scan8[i]];\n if (ref >= 0)\n fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2,\n 8, (16 + ref) ^ (s->mb_y & 1), 1);\n }\n }\n }\n }\n } else {\n linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize;\n }\n if (!simple && IS_INTRA_PCM(mb_type)) {\n if (pixel_shift) {\n const int bit_depth = h->sps.bit_depth_luma;\n GetBitContext gb;\n init_get_bits(&gb, (uint8_t *)h->mb, 768 * bit_depth);\n for (p = 0; p < plane_count; p++)\n for (i = 0; i < 16; i++) {\n uint16_t *tmp = (uint16_t *)(dest[p] + i * linesize);\n for (j = 0; j < 16; j++)\n tmp[j] = get_bits(&gb, bit_depth);\n }\n } else {\n for (p = 0; p < plane_count; p++)\n for (i = 0; i < 16; i++)\n memcpy(dest[p] + i * linesize, h->mb + p * 128 + i * 8, 16);\n }\n } else {\n if (IS_INTRA(mb_type)) {\n if (h->deblocking_filter)\n xchg_mb_border(h, dest[0], dest[1], dest[2], linesize,\n linesize, 1, 1, simple, pixel_shift);\n for (p = 0; p < plane_count; p++)\n hl_decode_mb_predict_luma(h, mb_type, 1, simple,\n transform_bypass, pixel_shift,\n block_offset, linesize, dest[p], p);\n if (h->deblocking_filter)\n xchg_mb_border(h, dest[0], dest[1], dest[2], linesize,\n linesize, 0, 1, simple, pixel_shift);\n } else {\n hl_motion(h, dest[0], dest[1], dest[2],\n s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,\n s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,\n h->h264dsp.weight_h264_pixels_tab,\n h->h264dsp.biweight_h264_pixels_tab, pixel_shift, 3);\n }\n for (p = 0; p < plane_count; p++)\n hl_decode_mb_idct_luma(h, mb_type, 1, simple, transform_bypass,\n pixel_shift, block_offset, linesize,\n dest[p], p);\n }\n if (h->cbp || IS_INTRA(mb_type)) {\n s->dsp.clear_blocks(h->mb);\n s->dsp.clear_blocks(h->mb + (24 * 16 << pixel_shift));\n }\n}', 'static av_always_inline void hl_motion(H264Context *h, uint8_t *dest_y,\n uint8_t *dest_cb, uint8_t *dest_cr,\n qpel_mc_func(*qpix_put)[16],\n h264_chroma_mc_func(*chroma_put),\n qpel_mc_func(*qpix_avg)[16],\n h264_chroma_mc_func(*chroma_avg),\n h264_weight_func *weight_op,\n h264_biweight_func *weight_avg,\n int pixel_shift, int chroma_idc)\n{\n MpegEncContext *const s = &h->s;\n const int mb_xy = h->mb_xy;\n const int mb_type = s->current_picture.f.mb_type[mb_xy];\n assert(IS_INTER(mb_type));\n if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))\n await_references(h);\n prefetch_motion(h, 0, pixel_shift, chroma_idc);\n if (IS_16X16(mb_type)) {\n mc_part(h, 0, 1, 16, 0, dest_y, dest_cb, dest_cr, 0, 0,\n qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],\n weight_op, weight_avg,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n pixel_shift, chroma_idc);\n } else if (IS_16X8(mb_type)) {\n mc_part(h, 0, 0, 8, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 0,\n qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n weight_op, weight_avg,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n pixel_shift, chroma_idc);\n mc_part(h, 8, 0, 8, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 4,\n qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n weight_op, weight_avg,\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n pixel_shift, chroma_idc);\n } else if (IS_8X16(mb_type)) {\n mc_part(h, 0, 0, 16, 8 * h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,\n qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n &weight_op[1], &weight_avg[1],\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n pixel_shift, chroma_idc);\n mc_part(h, 4, 0, 16, 8 * h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,\n qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n &weight_op[1], &weight_avg[1],\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n pixel_shift, chroma_idc);\n } else {\n int i;\n assert(IS_8X8(mb_type));\n for (i = 0; i < 4; i++) {\n const int sub_mb_type = h->sub_mb_type[i];\n const int n = 4 * i;\n int x_offset = (i & 1) << 2;\n int y_offset = (i & 2) << 1;\n if (IS_SUB_8X8(sub_mb_type)) {\n mc_part(h, n, 1, 8, 0, dest_y, dest_cb, dest_cr,\n x_offset, y_offset,\n qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n &weight_op[1], &weight_avg[1],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma_idc);\n } else if (IS_SUB_8X4(sub_mb_type)) {\n mc_part(h, n, 0, 4, 4 << pixel_shift, dest_y, dest_cb, dest_cr,\n x_offset, y_offset,\n qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n &weight_op[1], &weight_avg[1],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma_idc);\n mc_part(h, n + 2, 0, 4, 4 << pixel_shift,\n dest_y, dest_cb, dest_cr, x_offset, y_offset + 2,\n qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n &weight_op[1], &weight_avg[1],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma_idc);\n } else if (IS_SUB_4X8(sub_mb_type)) {\n mc_part(h, n, 0, 8, 4 * h->mb_linesize,\n dest_y, dest_cb, dest_cr, x_offset, y_offset,\n qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n &weight_op[2], &weight_avg[2],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma_idc);\n mc_part(h, n + 1, 0, 8, 4 * h->mb_linesize,\n dest_y, dest_cb, dest_cr, x_offset + 2, y_offset,\n qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n &weight_op[2], &weight_avg[2],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma_idc);\n } else {\n int j;\n assert(IS_SUB_4X4(sub_mb_type));\n for (j = 0; j < 4; j++) {\n int sub_x_offset = x_offset + 2 * (j & 1);\n int sub_y_offset = y_offset + (j & 2);\n mc_part(h, n + j, 1, 4, 0,\n dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,\n qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n &weight_op[2], &weight_avg[2],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma_idc);\n }\n }\n }\n }\n prefetch_motion(h, 1, pixel_shift, chroma_idc);\n}', 'static void await_references(H264Context *h)\n{\n MpegEncContext *const s = &h->s;\n const int mb_xy = h->mb_xy;\n const int mb_type = s->current_picture.f.mb_type[mb_xy];\n int refs[2][48];\n int nrefs[2] = { 0 };\n int ref, list;\n memset(refs, -1, sizeof(refs));\n if (IS_16X16(mb_type)) {\n get_lowest_part_y(h, refs, 0, 16, 0,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n } else if (IS_16X8(mb_type)) {\n get_lowest_part_y(h, refs, 0, 8, 0,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, 8, 8, 8,\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n } else if (IS_8X16(mb_type)) {\n get_lowest_part_y(h, refs, 0, 16, 0,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, 4, 16, 0,\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n } else {\n int i;\n assert(IS_8X8(mb_type));\n for (i = 0; i < 4; i++) {\n const int sub_mb_type = h->sub_mb_type[i];\n const int n = 4 * i;\n int y_offset = (i & 2) << 2;\n if (IS_SUB_8X8(sub_mb_type)) {\n get_lowest_part_y(h, refs, n, 8, y_offset,\n IS_DIR(sub_mb_type, 0, 0),\n IS_DIR(sub_mb_type, 0, 1),\n nrefs);\n } else if (IS_SUB_8X4(sub_mb_type)) {\n get_lowest_part_y(h, refs, n, 4, y_offset,\n IS_DIR(sub_mb_type, 0, 0),\n IS_DIR(sub_mb_type, 0, 1),\n nrefs);\n get_lowest_part_y(h, refs, n + 2, 4, y_offset + 4,\n IS_DIR(sub_mb_type, 0, 0),\n IS_DIR(sub_mb_type, 0, 1),\n nrefs);\n } else if (IS_SUB_4X8(sub_mb_type)) {\n get_lowest_part_y(h, refs, n, 8, y_offset,\n IS_DIR(sub_mb_type, 0, 0),\n IS_DIR(sub_mb_type, 0, 1),\n nrefs);\n get_lowest_part_y(h, refs, n + 1, 8, y_offset,\n IS_DIR(sub_mb_type, 0, 0),\n IS_DIR(sub_mb_type, 0, 1),\n nrefs);\n } else {\n int j;\n assert(IS_SUB_4X4(sub_mb_type));\n for (j = 0; j < 4; j++) {\n int sub_y_offset = y_offset + 2 * (j & 2);\n get_lowest_part_y(h, refs, n + j, 4, sub_y_offset,\n IS_DIR(sub_mb_type, 0, 0),\n IS_DIR(sub_mb_type, 0, 1),\n nrefs);\n }\n }\n }\n }\n for (list = h->list_count - 1; list >= 0; list--)\n for (ref = 0; ref < 48 && nrefs[list]; ref++) {\n int row = refs[list][ref];\n if (row >= 0) {\n Picture *ref_pic = &h->ref_list[list][ref];\n int ref_field = ref_pic->f.reference - 1;\n int ref_field_picture = ref_pic->field_picture;\n int pic_height = 16 * s->mb_height >> ref_field_picture;\n row <<= MB_MBAFF;\n nrefs[list]--;\n if (!FIELD_PICTURE && ref_field_picture) {\n ff_thread_await_progress(&ref_pic->f,\n FFMIN((row >> 1) - !(row & 1),\n pic_height - 1),\n 1);\n ff_thread_await_progress(&ref_pic->f,\n FFMIN((row >> 1), pic_height - 1),\n 0);\n } else if (FIELD_PICTURE && !ref_field_picture) {\n ff_thread_await_progress(&ref_pic->f,\n FFMIN(row * 2 + ref_field,\n pic_height - 1),\n 0);\n } else if (FIELD_PICTURE) {\n ff_thread_await_progress(&ref_pic->f,\n FFMIN(row, pic_height - 1),\n ref_field);\n } else {\n ff_thread_await_progress(&ref_pic->f,\n FFMIN(row, pic_height - 1),\n 0);\n }\n }\n }\n}']
2,533
1
https://github.com/openssl/openssl/blob/29eb7d9ce0488690cca532d0ecb4075b5ca59209/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 X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)\n\t{\n\tint ret=0;\n\tBIO *in=NULL;\n\tint i,count=0;\n\tX509 *x=NULL;\n\tif (file == NULL) return(1);\n\tin=BIO_new(BIO_s_file_internal());\n\tif ((in == NULL) || (BIO_read_filename(in,file) <= 0))\n\t\t{\n\t\tX509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_SYS_LIB);\n\t\tgoto err;\n\t\t}\n\tif (type == X509_FILETYPE_PEM)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tx=PEM_read_bio_X509_AUX(in,NULL,NULL,NULL);\n\t\t\tif (x == NULL)\n\t\t\t\t{\n\t\t\t\tif ((ERR_GET_REASON(ERR_peek_error()) ==\n\t\t\t\t\tPEM_R_NO_START_LINE) && (count > 0))\n\t\t\t\t\t{\n\t\t\t\t\tERR_clear_error();\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tX509err(X509_F_X509_LOAD_CERT_FILE,\n\t\t\t\t\t\tERR_R_PEM_LIB);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\ti=X509_STORE_add_cert(ctx->store_ctx,x);\n\t\t\tif (!i) goto err;\n\t\t\tcount++;\n\t\t\tX509_free(x);\n\t\t\tx=NULL;\n\t\t\t}\n\t\tret=count;\n\t\t}\n\telse if (type == X509_FILETYPE_ASN1)\n\t\t{\n\t\tx=d2i_X509_bio(in,NULL);\n\t\tif (x == NULL)\n\t\t\t{\n\t\t\tX509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_ASN1_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ti=X509_STORE_add_cert(ctx->store_ctx,x);\n\t\tif (!i) goto err;\n\t\tret=i;\n\t\t}\n\telse\n\t\t{\n\t\tX509err(X509_F_X509_LOAD_CERT_FILE,X509_R_BAD_X509_FILETYPE);\n\t\tgoto err;\n\t\t}\nerr:\n\tif (x != NULL) X509_free(x);\n\tif (in != NULL) BIO_free(in);\n\treturn(ret);\n\t}', 'int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)\n\t{\n\tX509_OBJECT *obj,*r;\n\tint ret=1;\n\tif (x == NULL) return(0);\n\tobj=(X509_OBJECT *)OPENSSL_malloc(sizeof(X509_OBJECT));\n\tif (obj == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE);\n\t\treturn(0);\n\t\t}\n\tobj->type=X509_LU_X509;\n\tobj->data.x509=x;\n\tCRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);\n\tX509_OBJECT_up_ref_count(obj);\n\tr=(X509_OBJECT *)lh_insert(ctx->certs,obj);\n\tif (r != NULL)\n\t\t{\n\t\tlh_delete(ctx->certs,obj);\n\t\tX509_OBJECT_free_contents(obj);\n\t\tOPENSSL_free(obj);\n\t\tlh_insert(ctx->certs,r);\n\t\tX509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE);\n\t\tret=0;\n\t\t}\n\tCRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);\n\treturn(ret);\n\t}', 'void *lh_insert(LHASH *lh, void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\tif (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))\n\t\texpand(lh);\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tif ((nn=(LHASH_NODE *)OPENSSL_malloc(sizeof(LHASH_NODE))) == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn(NULL);\n\t\t\t}\n\t\tnn->data=data;\n\t\tnn->next=NULL;\n#ifndef NO_HASH_COMP\n\t\tnn->hash=hash;\n#endif\n\t\t*rn=nn;\n\t\tret=NULL;\n\t\tlh->num_insert++;\n\t\tlh->num_items++;\n\t\t}\n\telse\n\t\t{\n\t\tret= (*rn)->data;\n\t\t(*rn)->data=data;\n\t\tlh->num_replace++;\n\t\t}\n\treturn(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}']
2,534
0
https://github.com/libav/libav/blob/e5b0fc170f85b00f7dd0ac514918fb5c95253d39/libavcodec/bitstream.h/#L139
static inline uint64_t get_val(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1); bc->bits >>= n; #else uint64_t ret = bc->bits >> (64 - n); bc->bits <<= n; #endif bc->bits_left -= n; return ret; }
['static int decode_block(BinkAudioContext *s, float **out, int use_dct)\n{\n int ch, i, j, k;\n float q, quant[25];\n int width, coeff;\n BitstreamContext *bc = &s->bc;\n if (use_dct)\n bitstream_skip(bc, 2);\n for (ch = 0; ch < s->channels; ch++) {\n FFTSample *coeffs = out[ch];\n if (s->version_b) {\n if (bitstream_bits_left(bc) < 64)\n return AVERROR_INVALIDDATA;\n coeffs[0] = av_int2float(bitstream_read(bc, 32)) * s->root;\n coeffs[1] = av_int2float(bitstream_read(bc, 32)) * s->root;\n } else {\n if (bitstream_bits_left(bc) < 58)\n return AVERROR_INVALIDDATA;\n coeffs[0] = get_float(bc) * s->root;\n coeffs[1] = get_float(bc) * s->root;\n }\n if (bitstream_bits_left(bc) < s->num_bands * 8)\n return AVERROR_INVALIDDATA;\n for (i = 0; i < s->num_bands; i++) {\n int value = bitstream_read(bc, 8);\n quant[i] = quant_table[FFMIN(value, 95)];\n }\n k = 0;\n q = quant[0];\n i = 2;\n while (i < s->frame_len) {\n if (s->version_b) {\n j = i + 16;\n } else {\n int v = bitstream_read_bit(bc);\n if (v) {\n v = bitstream_read(bc, 4);\n j = i + rle_length_tab[v] * 8;\n } else {\n j = i + 8;\n }\n }\n j = FFMIN(j, s->frame_len);\n width = bitstream_read(bc, 4);\n if (width == 0) {\n memset(coeffs + i, 0, (j - i) * sizeof(*coeffs));\n i = j;\n while (s->bands[k] < i)\n q = quant[k++];\n } else {\n while (i < j) {\n if (s->bands[k] == i)\n q = quant[k++];\n coeff = bitstream_read(bc, width);\n if (coeff) {\n int v;\n v = bitstream_read_bit(bc);\n if (v)\n coeffs[i] = -q * coeff;\n else\n coeffs[i] = q * coeff;\n } else {\n coeffs[i] = 0.0f;\n }\n i++;\n }\n }\n }\n if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) {\n coeffs[0] /= 0.5;\n s->trans.dct.dct_calc(&s->trans.dct, coeffs);\n }\n else if (CONFIG_BINKAUDIO_RDFT_DECODER)\n s->trans.rdft.rdft_calc(&s->trans.rdft, coeffs);\n }\n for (ch = 0; ch < s->channels; ch++) {\n int j;\n int count = s->overlap_len * s->channels;\n if (!s->first) {\n j = ch;\n for (i = 0; i < s->overlap_len; i++, j += s->channels)\n out[ch][i] = (s->previous[ch][i] * (count - j) +\n out[ch][i] * j) / count;\n }\n memcpy(s->previous[ch], &out[ch][s->frame_len - s->overlap_len],\n s->overlap_len * sizeof(*s->previous[ch]));\n }\n s->first = 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 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}']
2,535
0
https://github.com/openssl/openssl/blob/9b340281873643d2b8a33047dc8bfa607f7e0c3c/crypto/lhash/lhash.c/#L191
static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg, OPENSSL_LH_DOALL_FUNC func, OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg) { int i; OPENSSL_LH_NODE *a, *n; if (lh == NULL) return; for (i = lh->num_nodes - 1; i >= 0; i--) { a = lh->b[i]; while (a != NULL) { n = a->next; if (use_arg) func_arg(a->data, arg); else func(a->data); a = n; } } }
['static int test_dtls_drop_records(int idx)\n{\n SSL_CTX *sctx = NULL, *cctx = NULL;\n SSL *serverssl = NULL, *clientssl = NULL;\n BIO *c_to_s_fbio, *mempackbio;\n int testresult = 0;\n int epoch = 0;\n SSL_SESSION *sess = NULL;\n int cli_to_srv_epoch0, cli_to_srv_epoch1, srv_to_cli_epoch0;\n if (!TEST_true(create_ssl_ctx_pair(DTLS_server_method(),\n DTLS_client_method(),\n DTLS1_VERSION, DTLS_MAX_VERSION,\n &sctx, &cctx, cert, privkey)))\n return 0;\n if (idx >= TOTAL_FULL_HAND_RECORDS) {\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,\n NULL, NULL))\n || !TEST_true(create_ssl_connection(serverssl, clientssl,\n SSL_ERROR_NONE))\n || !TEST_ptr(sess = SSL_get1_session(clientssl)))\n goto end;\n SSL_shutdown(clientssl);\n SSL_shutdown(serverssl);\n SSL_free(serverssl);\n SSL_free(clientssl);\n serverssl = clientssl = NULL;\n cli_to_srv_epoch0 = CLI_TO_SRV_RESUME_EPOCH_0_RECS;\n cli_to_srv_epoch1 = CLI_TO_SRV_RESUME_EPOCH_1_RECS;\n srv_to_cli_epoch0 = SRV_TO_CLI_RESUME_EPOCH_0_RECS;\n idx -= TOTAL_FULL_HAND_RECORDS;\n } else {\n cli_to_srv_epoch0 = CLI_TO_SRV_EPOCH_0_RECS;\n cli_to_srv_epoch1 = CLI_TO_SRV_EPOCH_1_RECS;\n srv_to_cli_epoch0 = SRV_TO_CLI_EPOCH_0_RECS;\n }\n c_to_s_fbio = BIO_new(bio_f_tls_dump_filter());\n if (!TEST_ptr(c_to_s_fbio))\n goto end;\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,\n NULL, c_to_s_fbio)))\n goto end;\n if (sess != NULL) {\n if (!TEST_true(SSL_set_session(clientssl, sess)))\n goto end;\n }\n DTLS_set_timer_cb(clientssl, timer_cb);\n DTLS_set_timer_cb(serverssl, timer_cb);\n if (idx >= cli_to_srv_epoch0 + cli_to_srv_epoch1) {\n mempackbio = SSL_get_wbio(serverssl);\n idx -= cli_to_srv_epoch0 + cli_to_srv_epoch1;\n if (idx >= srv_to_cli_epoch0) {\n epoch = 1;\n idx -= srv_to_cli_epoch0;\n }\n } else {\n mempackbio = SSL_get_wbio(clientssl);\n if (idx >= cli_to_srv_epoch0) {\n epoch = 1;\n idx -= cli_to_srv_epoch0;\n }\n mempackbio = BIO_next(mempackbio);\n }\n BIO_ctrl(mempackbio, MEMPACKET_CTRL_SET_DROP_EPOCH, epoch, NULL);\n BIO_ctrl(mempackbio, MEMPACKET_CTRL_SET_DROP_REC, idx, NULL);\n if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)))\n goto end;\n if (sess != NULL && !TEST_true(SSL_session_reused(clientssl)))\n goto end;\n if (!TEST_int_eq((int)BIO_ctrl(mempackbio, MEMPACKET_CTRL_GET_DROP_REC, 0,\n NULL), -1))\n goto end;\n testresult = 1;\n end:\n SSL_SESSION_free(sess);\n SSL_free(serverssl);\n SSL_free(clientssl);\n SSL_CTX_free(sctx);\n SSL_CTX_free(cctx);\n return testresult;\n}', 'int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,\n SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)\n{\n SSL *serverssl = NULL, *clientssl = NULL;\n BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;\n if (*sssl != NULL)\n serverssl = *sssl;\n else if (!TEST_ptr(serverssl = SSL_new(serverctx)))\n goto error;\n if (*cssl != NULL)\n clientssl = *cssl;\n else if (!TEST_ptr(clientssl = SSL_new(clientctx)))\n goto error;\n if (SSL_is_dtls(clientssl)) {\n if (!TEST_ptr(s_to_c_bio = BIO_new(bio_s_mempacket_test()))\n || !TEST_ptr(c_to_s_bio = BIO_new(bio_s_mempacket_test())))\n goto error;\n } else {\n if (!TEST_ptr(s_to_c_bio = BIO_new(BIO_s_mem()))\n || !TEST_ptr(c_to_s_bio = BIO_new(BIO_s_mem())))\n goto error;\n }\n if (s_to_c_fbio != NULL\n && !TEST_ptr(s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio)))\n goto error;\n if (c_to_s_fbio != NULL\n && !TEST_ptr(c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio)))\n goto error;\n BIO_set_mem_eof_return(s_to_c_bio, -1);\n BIO_set_mem_eof_return(c_to_s_bio, -1);\n SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);\n BIO_up_ref(s_to_c_bio);\n BIO_up_ref(c_to_s_bio);\n SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);\n *sssl = serverssl;\n *cssl = clientssl;\n return 1;\n error:\n SSL_free(serverssl);\n SSL_free(clientssl);\n BIO_free(s_to_c_bio);\n BIO_free(c_to_s_bio);\n BIO_free(s_to_c_fbio);\n BIO_free(c_to_s_fbio);\n return 0;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return NULL;\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return NULL;\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->references = 1;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL) {\n OPENSSL_free(s);\n s = NULL;\n goto err;\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->dane.flags = ctx->dane.flags;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->max_early_data = ctx->max_early_data;\n s->recv_max_early_data = ctx->recv_max_early_data;\n s->num_tickets = ctx->num_tickets;\n s->pha_enabled = ctx->pha_enabled;\n s->tls13_ciphersuites = sk_SSL_CIPHER_dup(ctx->tls13_ciphersuites);\n if (s->tls13_ciphersuites == NULL)\n goto err;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n s->msg_callback = ctx->msg_callback;\n s->msg_callback_arg = ctx->msg_callback_arg;\n s->verify_mode = ctx->verify_mode;\n s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n s->record_padding_cb = ctx->record_padding_cb;\n s->record_padding_arg = ctx->record_padding_arg;\n s->block_padding = ctx->block_padding;\n s->sid_ctx_length = ctx->sid_ctx_length;\n if (!ossl_assert(s->sid_ctx_length <= sizeof(s->sid_ctx)))\n goto err;\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->ext.max_fragment_len_mode = ctx->ext.max_fragment_len_mode;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->ext.debug_cb = 0;\n s->ext.debug_arg = NULL;\n s->ext.ticket_expected = 0;\n s->ext.status_type = ctx->ext.status_type;\n s->ext.status_expected = 0;\n s->ext.ocsp.ids = NULL;\n s->ext.ocsp.exts = NULL;\n s->ext.ocsp.resp = NULL;\n s->ext.ocsp.resp_len = 0;\n SSL_CTX_up_ref(ctx);\n s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n if (ctx->ext.ecpointformats) {\n s->ext.ecpointformats =\n OPENSSL_memdup(ctx->ext.ecpointformats,\n ctx->ext.ecpointformats_len);\n if (!s->ext.ecpointformats)\n goto err;\n s->ext.ecpointformats_len =\n ctx->ext.ecpointformats_len;\n }\n if (ctx->ext.supportedgroups) {\n s->ext.supportedgroups =\n OPENSSL_memdup(ctx->ext.supportedgroups,\n ctx->ext.supportedgroups_len\n * sizeof(*ctx->ext.supportedgroups));\n if (!s->ext.supportedgroups)\n goto err;\n s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n s->ext.npn = NULL;\n#endif\n if (s->ctx->ext.alpn) {\n s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n if (s->ext.alpn == NULL)\n goto err;\n memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n s->ext.alpn_len = s->ctx->ext.alpn_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n s->key_update = SSL_KEY_UPDATE_NONE;\n s->allow_early_data_cb = ctx->allow_early_data_cb;\n s->allow_early_data_cb_data = ctx->allow_early_data_cb_data;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->psk_find_session_cb = ctx->psk_find_session_cb;\n s->psk_use_session_cb = ctx->psk_use_session_cb;\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n RECORD_LAYER_release(&s->rlayer);\n ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n s->wbio = NULL;\n BIO_free_all(s->rbio);\n s->rbio = NULL;\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n sk_SSL_CIPHER_free(s->tls13_ciphersuites);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n SSL_SESSION_free(s->psksession);\n OPENSSL_free(s->psksession_id);\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->ext.hostname);\n SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->ext.ecpointformats);\n OPENSSL_free(s->ext.supportedgroups);\n#endif\n sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->ext.scts);\n#endif\n OPENSSL_free(s->ext.ocsp.resp);\n OPENSSL_free(s->ext.alpn);\n OPENSSL_free(s->ext.tls13_cookie);\n OPENSSL_free(s->clienthello);\n OPENSSL_free(s->pha_context);\n EVP_MD_CTX_free(s->pha_dgst);\n sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(s->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n int i;\n if (a == NULL)\n return;\n CRYPTO_DOWN_REF(&a->references, &i, a->lock);\n REF_PRINT_COUNT("SSL_CTX", a);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(a->param);\n dane_ctx_final(&a->dane);\n if (a->sessions != NULL)\n SSL_CTX_flush_sessions(a, 0);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n lh_SSL_SESSION_free(a->sessions);\n X509_STORE_free(a->cert_store);\n#ifndef OPENSSL_NO_CT\n CTLOG_STORE_free(a->ctlog_store);\n#endif\n sk_SSL_CIPHER_free(a->cipher_list);\n sk_SSL_CIPHER_free(a->cipher_list_by_id);\n sk_SSL_CIPHER_free(a->tls13_ciphersuites);\n ssl_cert_free(a->cert);\n sk_X509_NAME_pop_free(a->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(a->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(a->extra_certs, X509_free);\n a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(a->ext.ecpointformats);\n OPENSSL_free(a->ext.supportedgroups);\n#endif\n OPENSSL_free(a->ext.alpn);\n OPENSSL_secure_free(a->ext.secure);\n CRYPTO_THREAD_lock_free(a->lock);\n OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n unsigned long i;\n TIMEOUT_PARAM tp;\n tp.ctx = s;\n tp.cache = s->sessions;\n if (tp.cache == NULL)\n return;\n tp.time = t;\n CRYPTO_THREAD_write_lock(s->lock);\n i = lh_SSL_SESSION_get_down_load(s->sessions);\n lh_SSL_SESSION_set_down_load(s->sessions, 0);\n lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);\n lh_SSL_SESSION_set_down_load(s->sessions, i);\n CRYPTO_THREAD_unlock(s->lock);\n}', 'IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM)', 'void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)\n{\n doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);\n}', 'static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,\n OPENSSL_LH_DOALL_FUNC func,\n OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)\n{\n int i;\n OPENSSL_LH_NODE *a, *n;\n if (lh == NULL)\n return;\n for (i = lh->num_nodes - 1; i >= 0; i--) {\n a = lh->b[i];\n while (a != NULL) {\n n = a->next;\n if (use_arg)\n func_arg(a->data, arg);\n else\n func(a->data);\n a = n;\n }\n }\n}']
2,536
0
https://github.com/libav/libav/blob/67ce33162aa93bee1a5f9e8d6f00060329fa67da/libavcodec/alacenc.c/#L391
static av_cold int alac_encode_init(AVCodecContext *avctx) { AlacEncodeContext *s = avctx->priv_data; uint8_t *alac_extradata = av_mallocz(ALAC_EXTRADATA_SIZE+1); avctx->frame_size = DEFAULT_FRAME_SIZE; avctx->bits_per_coded_sample = DEFAULT_SAMPLE_SIZE; if(avctx->sample_fmt != SAMPLE_FMT_S16) { av_log(avctx, AV_LOG_ERROR, "only pcm_s16 input samples are supported\n"); return -1; } if(avctx->compression_level == FF_COMPRESSION_DEFAULT) s->compression_level = 1; else s->compression_level = av_clip(avctx->compression_level, 0, 1); s->rc.history_mult = 40; s->rc.initial_history = 10; s->rc.k_modifier = 14; s->rc.rice_modifier = 4; s->max_coded_frame_size = (ALAC_FRAME_HEADER_SIZE + ALAC_FRAME_FOOTER_SIZE + avctx->frame_size*avctx->channels*avctx->bits_per_coded_sample)>>3; s->write_sample_size = avctx->bits_per_coded_sample + avctx->channels - 1; AV_WB32(alac_extradata, ALAC_EXTRADATA_SIZE); AV_WB32(alac_extradata+4, MKBETAG('a','l','a','c')); AV_WB32(alac_extradata+12, avctx->frame_size); AV_WB8 (alac_extradata+17, avctx->bits_per_coded_sample); AV_WB8 (alac_extradata+21, avctx->channels); AV_WB32(alac_extradata+24, s->max_coded_frame_size); AV_WB32(alac_extradata+28, avctx->sample_rate*avctx->channels*avctx->bits_per_coded_sample); AV_WB32(alac_extradata+32, avctx->sample_rate); if(s->compression_level > 0) { AV_WB8(alac_extradata+18, s->rc.history_mult); AV_WB8(alac_extradata+19, s->rc.initial_history); AV_WB8(alac_extradata+20, s->rc.k_modifier); } s->min_prediction_order = DEFAULT_MIN_PRED_ORDER; if(avctx->min_prediction_order >= 0) { if(avctx->min_prediction_order < MIN_LPC_ORDER || avctx->min_prediction_order > ALAC_MAX_LPC_ORDER) { av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", avctx->min_prediction_order); return -1; } s->min_prediction_order = avctx->min_prediction_order; } s->max_prediction_order = DEFAULT_MAX_PRED_ORDER; if(avctx->max_prediction_order >= 0) { if(avctx->max_prediction_order < MIN_LPC_ORDER || avctx->max_prediction_order > ALAC_MAX_LPC_ORDER) { av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", avctx->max_prediction_order); return -1; } s->max_prediction_order = avctx->max_prediction_order; } if(s->max_prediction_order < s->min_prediction_order) { av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n", s->min_prediction_order, s->max_prediction_order); return -1; } avctx->extradata = alac_extradata; avctx->extradata_size = ALAC_EXTRADATA_SIZE; avctx->coded_frame = avcodec_alloc_frame(); avctx->coded_frame->key_frame = 1; s->avctx = avctx; dsputil_init(&s->dspctx, avctx); return 0; }
['static av_cold int alac_encode_init(AVCodecContext *avctx)\n{\n AlacEncodeContext *s = avctx->priv_data;\n uint8_t *alac_extradata = av_mallocz(ALAC_EXTRADATA_SIZE+1);\n avctx->frame_size = DEFAULT_FRAME_SIZE;\n avctx->bits_per_coded_sample = DEFAULT_SAMPLE_SIZE;\n if(avctx->sample_fmt != SAMPLE_FMT_S16) {\n av_log(avctx, AV_LOG_ERROR, "only pcm_s16 input samples are supported\\n");\n return -1;\n }\n if(avctx->compression_level == FF_COMPRESSION_DEFAULT)\n s->compression_level = 1;\n else\n s->compression_level = av_clip(avctx->compression_level, 0, 1);\n s->rc.history_mult = 40;\n s->rc.initial_history = 10;\n s->rc.k_modifier = 14;\n s->rc.rice_modifier = 4;\n s->max_coded_frame_size = (ALAC_FRAME_HEADER_SIZE + ALAC_FRAME_FOOTER_SIZE +\n avctx->frame_size*avctx->channels*avctx->bits_per_coded_sample)>>3;\n s->write_sample_size = avctx->bits_per_coded_sample + avctx->channels - 1;\n AV_WB32(alac_extradata, ALAC_EXTRADATA_SIZE);\n AV_WB32(alac_extradata+4, MKBETAG(\'a\',\'l\',\'a\',\'c\'));\n AV_WB32(alac_extradata+12, avctx->frame_size);\n AV_WB8 (alac_extradata+17, avctx->bits_per_coded_sample);\n AV_WB8 (alac_extradata+21, avctx->channels);\n AV_WB32(alac_extradata+24, s->max_coded_frame_size);\n AV_WB32(alac_extradata+28, avctx->sample_rate*avctx->channels*avctx->bits_per_coded_sample);\n AV_WB32(alac_extradata+32, avctx->sample_rate);\n if(s->compression_level > 0) {\n AV_WB8(alac_extradata+18, s->rc.history_mult);\n AV_WB8(alac_extradata+19, s->rc.initial_history);\n AV_WB8(alac_extradata+20, s->rc.k_modifier);\n }\n s->min_prediction_order = DEFAULT_MIN_PRED_ORDER;\n if(avctx->min_prediction_order >= 0) {\n if(avctx->min_prediction_order < MIN_LPC_ORDER ||\n avctx->min_prediction_order > ALAC_MAX_LPC_ORDER) {\n av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\\n", avctx->min_prediction_order);\n return -1;\n }\n s->min_prediction_order = avctx->min_prediction_order;\n }\n s->max_prediction_order = DEFAULT_MAX_PRED_ORDER;\n if(avctx->max_prediction_order >= 0) {\n if(avctx->max_prediction_order < MIN_LPC_ORDER ||\n avctx->max_prediction_order > ALAC_MAX_LPC_ORDER) {\n av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\\n", avctx->max_prediction_order);\n return -1;\n }\n s->max_prediction_order = avctx->max_prediction_order;\n }\n if(s->max_prediction_order < s->min_prediction_order) {\n av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\\n",\n s->min_prediction_order, s->max_prediction_order);\n return -1;\n }\n avctx->extradata = alac_extradata;\n avctx->extradata_size = ALAC_EXTRADATA_SIZE;\n avctx->coded_frame = avcodec_alloc_frame();\n avctx->coded_frame->key_frame = 1;\n s->avctx = avctx;\n dsputil_init(&s->dspctx, avctx);\n return 0;\n}', 'void *av_mallocz(unsigned int size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr;\n#ifdef CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#ifdef 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 defined (HAVE_MEMALIGN)\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'static inline av_const int av_clip(int a, int amin, int amax)\n{\n if (a < amin) return amin;\n else if (a > amax) return amax;\n else return a;\n}']
2,537
0
https://github.com/libav/libav/blob/cb2c4de3a16c083973921587b6e8c79af59c9626/libavcodec/vc1dec.c/#L3720
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.f.motion_val[1][s->block_index[0]][0] = 0; s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0; } s->current_picture.f.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.f.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->dsp.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.f.mb_type[mb_pos] = MB_TYPE_SKIP; s->current_picture.f.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); 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.f.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->dsp.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.f.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); } vc1_mc_4mv_chroma(v, 0); s->current_picture.f.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.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 }\n s->current_picture.f.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.f.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->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : 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.f.mb_type[mb_pos] = MB_TYPE_SKIP;\n s->current_picture.f.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);\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.f.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->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off,\n (i & 4) ? s->uvlinesize : 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.f.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);\n }\n vc1_mc_4mv_chroma(v, 0);\n s->current_picture.f.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}']
2,538
0
https://github.com/openssl/openssl/blob/84c15db551ce1d167b901a3bde2b21880b084384/crypto/bn/bn_mul.c/#L648
int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) { int top,al,bl; BIGNUM *rr; #ifdef BN_RECURSION BIGNUM *t; int i,j,k; #endif #ifdef BN_COUNT printf("BN_mul %d * %d\n",a->top,b->top); #endif bn_check_top(a); bn_check_top(b); bn_check_top(r); al=a->top; bl=b->top; r->neg=a->neg^b->neg; if ((al == 0) || (bl == 0)) { BN_zero(r); return(1); } top=al+bl; if ((r == a) || (r == b)) rr= &(ctx->bn[ctx->tos+1]); else rr=r; #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) if (al == bl) { # ifdef BN_MUL_COMBA if (al == 8) { if (bn_wexpand(rr,16) == NULL) return(0); r->top=16; bn_mul_comba8(rr->d,a->d,b->d); goto end; } else # endif #ifdef BN_RECURSION if (al < BN_MULL_SIZE_NORMAL) #endif { if (bn_wexpand(rr,top) == NULL) return(0); rr->top=top; bn_mul_normal(rr->d,a->d,al,b->d,bl); goto end; } # ifdef BN_RECURSION goto symetric; # endif } #endif #ifdef BN_RECURSION else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL)) { if (bn_wexpand(rr,top) == NULL) return(0); rr->top=top; bn_mul_normal(rr->d,a->d,al,b->d,bl); goto end; } else { i=(al-bl); if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA)) { bn_wexpand(b,al); b->d[bl]=0; bl++; goto symetric; } else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA)) { bn_wexpand(a,bl); a->d[al]=0; al++; goto symetric; } } #endif if (bn_wexpand(rr,top) == NULL) return(0); rr->top=top; bn_mul_normal(rr->d,a->d,al,b->d,bl); #ifdef BN_RECURSION if (0) { symetric: j=BN_num_bits_word((BN_ULONG)al); j=1<<(j-1); k=j+j; t= &(ctx->bn[ctx->tos]); if (al == j) { bn_wexpand(t,k*2); bn_wexpand(rr,k*2); bn_mul_recursive(rr->d,a->d,b->d,al,t->d); } else { bn_wexpand(a,k); bn_wexpand(b,k); bn_wexpand(t,k*4); bn_wexpand(rr,k*4); for (i=a->top; i<k; i++) a->d[i]=0; for (i=b->top; i<k; i++) b->d[i]=0; bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d); } rr->top=top; } #endif #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) end: #endif bn_fix_top(rr); if (r != rr) BN_copy(r,rr); return(1); }
['int test_div_recp(BIO *bp, BN_CTX *ctx)\n\t{\n\tBIGNUM a,b,c,d,e;\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_init(&e);\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\tBN_mul(&e,&d,&b,ctx);\n\t\tBN_add(&d,&e,&c);\n\t\tBN_sub(&d,&d,&a);\n\t\tif(!BN_is_zero(&d))\n\t\t {\n\t\t BIO_puts(bp,"Reciprocal division test failed!\\n");\n\t\t return 0;\n\t\t }\n\t\t}\n\tBN_free(&a);\n\tBN_free(&b);\n\tBN_free(&c);\n\tBN_free(&d);\n\tBN_free(&e);\n\tBN_RECP_CTX_free(&recp);\n\treturn(1);\n\t}', 'int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tBN_copy(&(recp->N),d);\n\tBN_zero(&(recp->Nr));\n\trecp->num_bits=BN_num_bits(d);\n\trecp->shift=0;\n\treturn(1);\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}', '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_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}']
2,539
0
https://github.com/openssl/openssl/blob/980afccf98a9ab6df7a26161b5a39538c30a2292/crypto/rc5/rc5_skey.c/#L87
void RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data, int rounds) { RC5_32_INT L[64],l,ll,A,B,*S,k; int i,j,m,c,t,ii,jj; if ( (rounds != RC5_16_ROUNDS) && (rounds != RC5_12_ROUNDS) && (rounds != RC5_8_ROUNDS)) rounds=RC5_16_ROUNDS; key->rounds=rounds; S= &(key->data[0]); j=0; for (i=0; i<=(len-8); i+=8) { c2l(data,l); L[j++]=l; c2l(data,l); L[j++]=l; } ii=len-i; if (ii) { k=len&0x07; c2ln(data,l,ll,k); L[j+0]=l; L[j+1]=ll; } c=(len+3)/4; t=(rounds+1)*2; S[0]=RC5_32_P; for (i=1; i<t; i++) S[i]=(S[i-1]+RC5_32_Q)&RC5_32_MASK; j=(t>c)?t:c; j*=3; ii=jj=0; A=B=0; for (i=0; i<j; i++) { k=(S[ii]+A+B)&RC5_32_MASK; A=S[ii]=ROTATE_l32(k,3); m=(int)(A+B); k=(L[jj]+A+B)&RC5_32_MASK; B=L[jj]=ROTATE_l32(k,m); if (++ii >= t) ii=0; if (++jj >= c) jj=0; } }
['int MAIN(int argc, char **argv)\n\t{\n\tENGINE *e;\n\tunsigned char *buf=NULL,*buf2=NULL;\n\tint mret=1;\n\tlong count=0,save_count=0;\n\tint i,j,k;\n#ifndef OPENSSL_NO_RSA\n\tunsigned rsa_num;\n\tlong rsa_count;\n#endif\n\tunsigned char md[EVP_MAX_MD_SIZE];\n#ifndef OPENSSL_NO_MD2\n\tunsigned char md2[MD2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MDC2\n\tunsigned char mdc2[MDC2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD4\n\tunsigned char md4[MD4_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD5\n\tunsigned char md5[MD5_DIGEST_LENGTH];\n\tunsigned char hmac[MD5_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_SHA\n\tunsigned char sha[SHA_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\tunsigned char rmd160[RIPEMD160_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_RC4\n\tRC4_KEY rc4_ks;\n#endif\n#ifndef OPENSSL_NO_RC5\n\tRC5_32_KEY rc5_ks;\n#endif\n#ifndef OPENSSL_NO_RC2\n\tRC2_KEY rc2_ks;\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tIDEA_KEY_SCHEDULE idea_ks;\n#endif\n#ifndef OPENSSL_NO_BF\n\tBF_KEY bf_ks;\n#endif\n#ifndef OPENSSL_NO_CAST\n\tCAST_KEY cast_ks;\n#endif\n\tstatic const unsigned char key16[16]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};\n\tstatic const unsigned char key24[24]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};\n\tstatic const unsigned char key32[32]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,\n\t\t 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};\n#ifndef OPENSSL_NO_AES\n#define MAX_BLOCK_SIZE 128\n#else\n#define MAX_BLOCK_SIZE 64\n#endif\n\tunsigned char DES_iv[8];\n\tunsigned char iv[MAX_BLOCK_SIZE/8];\n#ifndef OPENSSL_NO_DES\n\tDES_cblock *buf_as_des_cblock = NULL;\n\tstatic des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};\n\tstatic des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};\n\tstatic des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};\n\tDES_key_schedule sch;\n\tDES_key_schedule sch2;\n\tDES_key_schedule sch3;\n#endif\n#ifndef OPENSSL_NO_AES\n\tAES_KEY aes_ks1, aes_ks2, aes_ks3;\n#endif\n#define\tD_MD2\t\t0\n#define\tD_MDC2\t\t1\n#define\tD_MD4\t\t2\n#define\tD_MD5\t\t3\n#define\tD_HMAC\t\t4\n#define\tD_SHA1\t\t5\n#define D_RMD160\t6\n#define\tD_RC4\t\t7\n#define\tD_CBC_DES\t8\n#define\tD_EDE3_DES\t9\n#define\tD_CBC_IDEA\t10\n#define\tD_CBC_RC2\t11\n#define\tD_CBC_RC5\t12\n#define\tD_CBC_BF\t13\n#define\tD_CBC_CAST\t14\n#define D_CBC_128_AES\t15\n#define D_CBC_192_AES\t16\n#define D_CBC_256_AES\t17\n#define D_EVP\t\t18\n\tdouble d=0.0;\n\tlong c[ALGOR_NUM][SIZE_NUM];\n#define\tR_DSA_512\t0\n#define\tR_DSA_1024\t1\n#define\tR_DSA_2048\t2\n#define\tR_RSA_512\t0\n#define\tR_RSA_1024\t1\n#define\tR_RSA_2048\t2\n#define\tR_RSA_4096\t3\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa_key[RSA_NUM];\n\tlong rsa_c[RSA_NUM][2];\n\tstatic unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};\n\tstatic unsigned char *rsa_data[RSA_NUM]=\n\t\t{test512,test1024,test2048,test4096};\n\tstatic int rsa_data_length[RSA_NUM]={\n\t\tsizeof(test512),sizeof(test1024),\n\t\tsizeof(test2048),sizeof(test4096)};\n#endif\n#ifndef OPENSSL_NO_DSA\n\tDSA *dsa_key[DSA_NUM];\n\tlong dsa_c[DSA_NUM][2];\n\tstatic unsigned int dsa_bits[DSA_NUM]={512,1024,2048};\n#endif\n\tint rsa_doit[RSA_NUM];\n\tint dsa_doit[DSA_NUM];\n\tint doit[ALGOR_NUM];\n\tint pr_header=0;\n\tconst EVP_CIPHER *evp_cipher=NULL;\n\tconst EVP_MD *evp_md=NULL;\n\tint decrypt=0;\n#ifdef HAVE_FORK\n\tint multi=0;\n#endif\n#ifndef TIMES\n\tusertime=-1;\n#endif\n\tapps_startup();\n\tmemset(results, 0, sizeof(results));\n#ifndef OPENSSL_NO_DSA\n\tmemset(dsa_key,0,sizeof(dsa_key));\n#endif\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n#ifndef OPENSSL_NO_RSA\n\tmemset(rsa_key,0,sizeof(rsa_key));\n\tfor (i=0; i<RSA_NUM; i++)\n\t\trsa_key[i]=NULL;\n#endif\n\tif ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n#ifndef OPENSSL_NO_DES\n\tbuf_as_des_cblock = (des_cblock *)buf;\n#endif\n\tif ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n\tmemset(c,0,sizeof(c));\n\tmemset(DES_iv,0,sizeof(DES_iv));\n\tmemset(iv,0,sizeof(iv));\n\tfor (i=0; i<ALGOR_NUM; i++)\n\t\tdoit[i]=0;\n\tfor (i=0; i<RSA_NUM; i++)\n\t\trsa_doit[i]=0;\n\tfor (i=0; i<DSA_NUM; i++)\n\t\tdsa_doit[i]=0;\n\tj=0;\n\targc--;\n\targv++;\n\twhile (argc)\n\t\t{\n\t\tif\t((argc > 0) && (strcmp(*argv,"-elapsed") == 0))\n\t\t\t{\n\t\t\tusertime = 0;\n\t\t\tj--;\n\t\t\t}\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-evp") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no EVP given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tevp_cipher=EVP_get_cipherbyname(*argv);\n\t\t\tif(!evp_cipher)\n\t\t\t\t{\n\t\t\t\tevp_md=EVP_get_digestbyname(*argv);\n\t\t\t\t}\n\t\t\tif(!evp_cipher && !evp_md)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"%s is an unknown cipher or digest\\n",*argv);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tdoit[D_EVP]=1;\n\t\t\t}\n\t\telse if (argc > 0 && !strcmp(*argv,"-decrypt"))\n\t\t\t{\n\t\t\tdecrypt=1;\n\t\t\tj--;\n\t\t\t}\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-engine") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no engine given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n e = setup_engine(bio_err, *argv, 0);\n\t\t\tj--;\n\t\t\t}\n#ifdef HAVE_FORK\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-multi") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no multi count given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tmulti=atoi(argv[0]);\n\t\t\tif(multi <= 0)\n\t\t\t {\n\t\t\t\tBIO_printf(bio_err,"bad multi count\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tj--;\n\t\t\t}\n#endif\n\t\telse if (argc > 0 && !strcmp(*argv,"-mr"))\n\t\t\t{\n\t\t\tmr=1;\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#ifndef OPENSSL_NO_MD2\n\t\tif\t(strcmp(*argv,"md2") == 0) doit[D_MD2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MDC2\n\t\t\tif (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD4\n\t\t\tif (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tif (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tif (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_SHA\n\t\t\tif (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\t\t\tif (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\t\tif (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tif (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;\n\t\telse\tif (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tif (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;\n\t\telse\tif (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;\n\t\telse\tif (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RSA\n#if 0\n\t\t\tif (strcmp(*argv,"rsaref") == 0)\n\t\t\t{\n\t\t\tRSA_set_default_openssl_method(RSA_PKCS1_RSAref());\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#endif\n#ifndef RSA_NULL\n\t\t\tif (strcmp(*argv,"openssl") == 0)\n\t\t\t{\n\t\t\tRSA_set_default_method(RSA_PKCS1_SSLeay());\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#endif\n#endif\n\t\t if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;\n\t\telse if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;\n\t\telse if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;\n\t\telse if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;\n\t\telse if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;\n\t\telse if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;\n\t\telse if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;\n\t\telse\n#ifndef OPENSSL_NO_RC2\n\t\t if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;\n\t\telse if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RC5\n\t\t if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;\n\t\telse if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;\n\t\telse if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;\n\t\telse if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;\n\t\telse if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_CAST\n\t\t if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;\n\t\telse if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;\n\t\telse if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tif (strcmp(*argv,"des") == 0)\n\t\t\t{\n\t\t\tdoit[D_CBC_DES]=1;\n\t\t\tdoit[D_EDE3_DES]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tif (strcmp(*argv,"aes") == 0)\n\t\t\t{\n\t\t\tdoit[D_CBC_128_AES]=1;\n\t\t\tdoit[D_CBC_192_AES]=1;\n\t\t\tdoit[D_CBC_256_AES]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RSA\n\t\t\tif (strcmp(*argv,"rsa") == 0)\n\t\t\t{\n\t\t\trsa_doit[R_RSA_512]=1;\n\t\t\trsa_doit[R_RSA_1024]=1;\n\t\t\trsa_doit[R_RSA_2048]=1;\n\t\t\trsa_doit[R_RSA_4096]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DSA\n\t\t\tif (strcmp(*argv,"dsa") == 0)\n\t\t\t{\n\t\t\tdsa_doit[R_DSA_512]=1;\n\t\t\tdsa_doit[R_DSA_1024]=1;\n\t\t\t}\n\t\telse\n#endif\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Error: bad option or value\\n");\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\tBIO_printf(bio_err,"Available values:\\n");\n#ifndef OPENSSL_NO_MD2\n\t\t\tBIO_printf(bio_err,"md2 ");\n#endif\n#ifndef OPENSSL_NO_MDC2\n\t\t\tBIO_printf(bio_err,"mdc2 ");\n#endif\n#ifndef OPENSSL_NO_MD4\n\t\t\tBIO_printf(bio_err,"md4 ");\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tBIO_printf(bio_err,"md5 ");\n#ifndef OPENSSL_NO_HMAC\n\t\t\tBIO_printf(bio_err,"hmac ");\n#endif\n#endif\n#ifndef OPENSSL_NO_SHA1\n\t\t\tBIO_printf(bio_err,"sha1 ");\n#endif\n#ifndef OPENSSL_NO_RIPEMD160\n\t\t\tBIO_printf(bio_err,"rmd160");\n#endif\n#if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \\\n !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \\\n !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t\tBIO_printf(bio_err,"idea-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC2\n\t\t\tBIO_printf(bio_err,"rc2-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC5\n\t\t\tBIO_printf(bio_err,"rc5-cbc ");\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t\tBIO_printf(bio_err,"bf-cbc");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tBIO_printf(bio_err,"des-cbc des-ede3 ");\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tBIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\t\tBIO_printf(bio_err,"rc4");\n#endif\n\t\t\tBIO_printf(bio_err,"\\n");\n#ifndef OPENSSL_NO_RSA\n\t\t\tBIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\\n");\n#endif\n#ifndef OPENSSL_NO_DSA\n\t\t\tBIO_printf(bio_err,"dsa512 dsa1024 dsa2048\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t\tBIO_printf(bio_err,"idea ");\n#endif\n#ifndef OPENSSL_NO_RC2\n\t\t\tBIO_printf(bio_err,"rc2 ");\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tBIO_printf(bio_err,"des ");\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tBIO_printf(bio_err,"aes ");\n#endif\n#ifndef OPENSSL_NO_RSA\n\t\t\tBIO_printf(bio_err,"rsa ");\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t\tBIO_printf(bio_err,"blowfish");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_AES)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\tBIO_printf(bio_err,"Available options:\\n");\n#ifdef TIMES\n\t\t\tBIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\\n");\n#endif\n\t\t\tBIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\\n");\n\t\t\tBIO_printf(bio_err,"-evp e use EVP e.\\n");\n\t\t\tBIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\\n");\n\t\t\tBIO_printf(bio_err,"-mr produce machine readable output.\\n");\n#ifdef HAVE_FORK\n\t\t\tBIO_printf(bio_err,"-multi n run n benchmarks in parallel.\\n");\n#endif\n\t\t\tgoto end;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\tj++;\n\t\t}\n#ifdef HAVE_FORK\n\tif(multi && do_multi(multi))\n\t\tgoto show_res;\n#endif\n\tif (j == 0)\n\t\t{\n\t\tfor (i=0; i<ALGOR_NUM; i++)\n\t\t\t{\n\t\t\tif (i != D_EVP)\n\t\t\t\tdoit[i]=1;\n\t\t\t}\n\t\tfor (i=0; i<RSA_NUM; i++)\n\t\t\trsa_doit[i]=1;\n\t\tfor (i=0; i<DSA_NUM; i++)\n\t\t\tdsa_doit[i]=1;\n\t\t}\n\tfor (i=0; i<ALGOR_NUM; i++)\n\t\tif (doit[i]) pr_header++;\n\tif (usertime == 0 && !mr)\n\t\tBIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\\n");\n\tif (usertime <= 0 && !mr)\n\t\t{\n\t\tBIO_printf(bio_err,"To get the most accurate results, try to run this\\n");\n\t\tBIO_printf(bio_err,"program when this computer is idle.\\n");\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\tfor (i=0; i<RSA_NUM; i++)\n\t\t{\n\t\tconst unsigned char *p;\n\t\tp=rsa_data[i];\n\t\trsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);\n\t\tif (rsa_key[i] == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"internal error loading RSA key number %d\\n",i);\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,mr ? "+RK:%d:"\n\t\t\t\t : "Loaded RSA key, %d bit modulus and e= 0x",\n\t\t\t\t BN_num_bits(rsa_key[i]->n));\n\t\t\tBN_print(bio_err,rsa_key[i]->e);\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\t}\n#endif\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tdsa_key[0]=get_dsa512();\n\tdsa_key[1]=get_dsa1024();\n\tdsa_key[2]=get_dsa2048();\n#endif\n#ifndef OPENSSL_NO_DES\n\tDES_set_key_unchecked(&key,&sch);\n\tDES_set_key_unchecked(&key2,&sch2);\n\tDES_set_key_unchecked(&key3,&sch3);\n#endif\n#ifndef OPENSSL_NO_AES\n\tAES_set_encrypt_key(key16,128,&aes_ks1);\n\tAES_set_encrypt_key(key24,192,&aes_ks2);\n\tAES_set_encrypt_key(key32,256,&aes_ks3);\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tidea_set_encrypt_key(key16,&idea_ks);\n#endif\n#ifndef OPENSSL_NO_RC4\n\tRC4_set_key(&rc4_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_RC2\n\tRC2_set_key(&rc2_ks,16,key16,128);\n#endif\n#ifndef OPENSSL_NO_RC5\n\tRC5_32_set_key(&rc5_ks,16,key16,12);\n#endif\n#ifndef OPENSSL_NO_BF\n\tBF_set_key(&bf_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_CAST\n\tCAST_set_key(&cast_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_RSA\n\tmemset(rsa_c,0,sizeof(rsa_c));\n#endif\n#ifndef SIGALRM\n#ifndef OPENSSL_NO_DES\n\tBIO_printf(bio_err,"First we calculate the approximate speed ...\\n");\n\tcount=10;\n\tdo\t{\n\t\tlong i;\n\t\tcount*=2;\n\t\tTime_F(START);\n\t\tfor (i=count; i; i--)\n\t\t\tDES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,\n\t\t\t\t&sch,DES_ENCRYPT);\n\t\td=Time_F(STOP);\n\t\t} while (d <3);\n\tsave_count=count;\n\tc[D_MD2][0]=count/10;\n\tc[D_MDC2][0]=count/10;\n\tc[D_MD4][0]=count;\n\tc[D_MD5][0]=count;\n\tc[D_HMAC][0]=count;\n\tc[D_SHA1][0]=count;\n\tc[D_RMD160][0]=count;\n\tc[D_RC4][0]=count*5;\n\tc[D_CBC_DES][0]=count;\n\tc[D_EDE3_DES][0]=count/3;\n\tc[D_CBC_IDEA][0]=count;\n\tc[D_CBC_RC2][0]=count;\n\tc[D_CBC_RC5][0]=count;\n\tc[D_CBC_BF][0]=count;\n\tc[D_CBC_CAST][0]=count;\n\tfor (i=1; i<SIZE_NUM; i++)\n\t\t{\n\t\tc[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];\n\t\tc[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];\n\t\tc[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];\n\t\tc[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];\n\t\t}\n\tfor (i=1; i<SIZE_NUM; i++)\n\t\t{\n\t\tlong l0,l1;\n\t\tl0=(long)lengths[i-1];\n\t\tl1=(long)lengths[i];\n\t\tc[D_RC4][i]=c[D_RC4][i-1]*l0/l1;\n\t\tc[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;\n\t\tc[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;\n\t\tc[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;\n\t\tc[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;\n\t\tc[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;\n\t\tc[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;\n\t\tc[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\trsa_c[R_RSA_512][0]=count/2000;\n\trsa_c[R_RSA_512][1]=count/400;\n\tfor (i=1; i<RSA_NUM; i++)\n\t\t{\n\t\trsa_c[i][0]=rsa_c[i-1][0]/8;\n\t\trsa_c[i][1]=rsa_c[i-1][1]/4;\n\t\tif ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))\n\t\t\trsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (rsa_c[i][0] == 0)\n\t\t\t\t{\n\t\t\t\trsa_c[i][0]=1;\n\t\t\t\trsa_c[i][1]=20;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tdsa_c[R_DSA_512][0]=count/1000;\n\tdsa_c[R_DSA_512][1]=count/1000/2;\n\tfor (i=1; i<DSA_NUM; i++)\n\t\t{\n\t\tdsa_c[i][0]=dsa_c[i-1][0]/4;\n\t\tdsa_c[i][1]=dsa_c[i-1][1]/4;\n\t\tif ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))\n\t\t\tdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (dsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tdsa_c[i][0]=1;\n\t\t\t\tdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#define COND(d)\t(count < (d))\n#define COUNT(d) (d)\n#else\n# error "You cannot disable DES on systems without SIGALRM."\n#endif\n#else\n#define COND(c)\t(run)\n#define COUNT(d) (count)\n\tsignal(SIGALRM,sig_done);\n#endif\n#ifndef OPENSSL_NO_MD2\n\tif (doit[D_MD2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD2],c[D_MD2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD2][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MDC2\n\tif (doit[D_MDC2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MDC2][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MDC2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MD4\n\tif (doit[D_MD4])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD4],c[D_MD4][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD4][j]); count++)\n\t\t\t\tEVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD4,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MD5\n\tif (doit[D_MD5])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD5],c[D_MD5][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD5][j]); count++)\n\t\t\t\tEVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD5,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)\n\tif (doit[D_HMAC])\n\t\t{\n\t\tHMAC_CTX hctx;\n\t\tHMAC_CTX_init(&hctx);\n\t\tHMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",\n\t\t\t16,EVP_md5());\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_HMAC][j]); count++)\n\t\t\t\t{\n\t\t\t\tHMAC_Init_ex(&hctx,NULL,0,NULL);\n HMAC_Update(&hctx,buf,lengths[j]);\n HMAC_Final(&hctx,&(hmac[0]),NULL);\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_HMAC,j,count,d);\n\t\t\t}\n\t\tHMAC_CTX_cleanup(&hctx);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_SHA\n\tif (doit[D_SHA1])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_SHA1][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_SHA1,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\tif (doit[D_RMD160])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_RMD160][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_RMD160,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC4\n\tif (doit[D_RC4])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_RC4],c[D_RC4][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_RC4][j]); count++)\n\t\t\t\tRC4(&rc4_ks,(unsigned int)lengths[j],\n\t\t\t\t\tbuf,buf);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_RC4,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DES\n\tif (doit[D_CBC_DES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_DES][j]); count++)\n\t\t\t\tDES_ncbc_encrypt(buf,buf,lengths[j],&sch,\n\t\t\t\t\t\t &DES_iv,DES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_DES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_EDE3_DES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)\n\t\t\t\tDES_ede3_cbc_encrypt(buf,buf,lengths[j],\n\t\t\t\t\t\t &sch,&sch2,&sch3,\n\t\t\t\t\t\t &DES_iv,DES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_EDE3_DES,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_AES\n\tif (doit[D_CBC_128_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks1,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_128_AES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_192_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks2,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_192_AES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_256_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks3,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_256_AES,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tif (doit[D_CBC_IDEA])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)\n\t\t\t\tidea_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&idea_ks,\n\t\t\t\t\tiv,IDEA_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_IDEA,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC2\n\tif (doit[D_CBC_RC2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)\n\t\t\t\tRC2_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&rc2_ks,\n\t\t\t\t\tiv,RC2_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_RC2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC5\n\tif (doit[D_CBC_RC5])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)\n\t\t\t\tRC5_32_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&rc5_ks,\n\t\t\t\t\tiv,RC5_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_RC5,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_BF\n\tif (doit[D_CBC_BF])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_BF][j]); count++)\n\t\t\t\tBF_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&bf_ks,\n\t\t\t\t\tiv,BF_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_BF,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_CAST\n\tif (doit[D_CBC_CAST])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)\n\t\t\t\tCAST_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&cast_ks,\n\t\t\t\t\tiv,CAST_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_CAST,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n\tif (doit[D_EVP])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tif (evp_cipher)\n\t\t\t\t{\n\t\t\t\tEVP_CIPHER_CTX ctx;\n\t\t\t\tint outl;\n\t\t\t\tnames[D_EVP]=OBJ_nid2ln(evp_cipher->nid);\n\t\t\t\tprint_message(names[D_EVP],save_count,\n\t\t\t\t\tlengths[j]);\n\t\t\t\tEVP_CIPHER_CTX_init(&ctx);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tEVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);\n\t\t\t\telse\n\t\t\t\t\tEVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);\n\t\t\t\tTime_F(START);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\t\tEVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);\n\t\t\t\telse\n\t\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\t\tEVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tEVP_DecryptFinal_ex(&ctx,buf,&outl);\n\t\t\t\telse\n\t\t\t\t\tEVP_EncryptFinal_ex(&ctx,buf,&outl);\n\t\t\t\td=Time_F(STOP);\n\t\t\t\t}\n\t\t\tif (evp_md)\n\t\t\t\t{\n\t\t\t\tnames[D_EVP]=OBJ_nid2ln(evp_md->type);\n\t\t\t\tprint_message(names[D_EVP],save_count,\n\t\t\t\t\tlengths[j]);\n\t\t\t\tTime_F(START);\n\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\tEVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);\n\t\t\t\td=Time_F(STOP);\n\t\t\t\t}\n\t\t\tprint_result(D_EVP,j,count,d);\n\t\t\t}\n\t\t}\n\tRAND_pseudo_bytes(buf,36);\n#ifndef OPENSSL_NO_RSA\n\tfor (j=0; j<RSA_NUM; j++)\n\t\t{\n\t\tint ret;\n\t\tif (!rsa_doit[j]) continue;\n\t\tret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);\n\t\tif (ret == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("private","rsa",\n\t\t\t\trsa_c[j][0],rsa_bits[j],\n\t\t\t\tRSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(rsa_c[j][0]); count++)\n\t\t\t\t{\n\t\t\t\tret=RSA_sign(NID_md5_sha1, buf,36, buf2,\n\t\t\t\t\t&rsa_num, rsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"RSA sign failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit private RSA\'s in %.2fs\\n",\n\t\t\t\t count,rsa_bits[j],d);\n\t\t\trsa_results[j][0]=d/(double)count;\n\t\t\trsa_count=count;\n\t\t\t}\n#if 1\n\t\tret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);\n\t\tif (ret <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_doit[j] = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("public","rsa",\n\t\t\t\trsa_c[j][1],rsa_bits[j],\n\t\t\t\tRSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(rsa_c[j][1]); count++)\n\t\t\t\t{\n\t\t\t\tret=RSA_verify(NID_md5_sha1, buf,36, buf2,\n\t\t\t\t\trsa_num, rsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"RSA verify failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit public RSA\'s in %.2fs\\n",\n\t\t\t\t count,rsa_bits[j],d);\n\t\t\trsa_results[j][1]=d/(double)count;\n\t\t\t}\n#endif\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<RSA_NUM; j++)\n\t\t\t\trsa_doit[j]=0;\n\t\t\t}\n\t\t}\n#endif\n\tRAND_pseudo_bytes(buf,20);\n#ifndef OPENSSL_NO_DSA\n\tif (RAND_status() != 1)\n\t\t{\n\t\tRAND_seed(rnd_seed, sizeof rnd_seed);\n\t\trnd_fake = 1;\n\t\t}\n\tfor (j=0; j<DSA_NUM; j++)\n\t\t{\n\t\tunsigned int kk;\n\t\tint ret;\n\t\tif (!dsa_doit[j]) continue;\n\t\tret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t&kk,dsa_key[j]);\n\t\tif (ret == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("sign","dsa",\n\t\t\t\tdsa_c[j][0],dsa_bits[j],\n\t\t\t\tDSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(dsa_c[j][0]); count++)\n\t\t\t\t{\n\t\t\t\tret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t\t\t&kk,dsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"DSA sign failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit DSA signs in %.2fs\\n",\n\t\t\t\t count,dsa_bits[j],d);\n\t\t\tdsa_results[j][0]=d/(double)count;\n\t\t\trsa_count=count;\n\t\t\t}\n\t\tret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\tkk,dsa_key[j]);\n\t\tif (ret <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tdsa_doit[j] = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("verify","dsa",\n\t\t\t\tdsa_c[j][1],dsa_bits[j],\n\t\t\t\tDSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(dsa_c[j][1]); count++)\n\t\t\t\t{\n\t\t\t\tret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t\t\tkk,dsa_key[j]);\n\t\t\t\tif (ret <= 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"DSA verify failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit DSA verify in %.2fs\\n",\n\t\t\t\t count,dsa_bits[j],d);\n\t\t\tdsa_results[j][1]=d/(double)count;\n\t\t\t}\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<DSA_NUM; j++)\n\t\t\t\tdsa_doit[j]=0;\n\t\t\t}\n\t\t}\n\tif (rnd_fake) RAND_cleanup();\n#endif\n#ifdef HAVE_FORK\nshow_res:\n#endif\n\tif(!mr)\n\t\t{\n\t\tfprintf(stdout,"%s\\n",SSLeay_version(SSLEAY_VERSION));\n fprintf(stdout,"%s\\n",SSLeay_version(SSLEAY_BUILT_ON));\n\t\tprintf("options:");\n\t\tprintf("%s ",BN_options());\n#ifndef OPENSSL_NO_MD2\n\t\tprintf("%s ",MD2_options());\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\tprintf("%s ",RC4_options());\n#endif\n#ifndef OPENSSL_NO_DES\n\t\tprintf("%s ",des_options());\n#endif\n#ifndef OPENSSL_NO_AES\n\t\tprintf("%s ",AES_options());\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\tprintf("%s ",idea_options());\n#endif\n#ifndef OPENSSL_NO_BF\n\t\tprintf("%s ",BF_options());\n#endif\n\t\tfprintf(stdout,"\\n%s\\n",SSLeay_version(SSLEAY_CFLAGS));\n\t\tprintf("available timing options: ");\n#ifdef TIMES\n\t\tprintf("TIMES ");\n#endif\n#ifdef TIMEB\n\t\tprintf("TIMEB ");\n#endif\n#ifdef USE_TOD\n\t\tprintf("USE_TOD ");\n#endif\n#ifdef HZ\n#define as_string(s) (#s)\n\t\tprintf("HZ=%g", HZ);\n# ifdef _SC_CLK_TCK\n\t\tprintf(" [sysconf value]");\n# endif\n#endif\n\t\tprintf("\\n");\n\t\tprintf("timing function used: %s%s%s%s%s%s%s\\n",\n\t\t (ftime_used ? "ftime" : ""),\n\t\t (ftime_used + times_used > 1 ? "," : ""),\n\t\t (times_used ? "times" : ""),\n\t\t (ftime_used + times_used + gettimeofday_used > 1 ? "," : ""),\n\t\t (gettimeofday_used ? "gettimeofday" : ""),\n\t\t (ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""),\n\t\t (getrusage_used ? "getrusage" : ""));\n\t\t}\n\tif (pr_header)\n\t\t{\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+H");\n\t\telse\n\t\t\t{\n\t\t\tfprintf(stdout,"The \'numbers\' are in 1000s of bytes per second processed.\\n");\n\t\t\tfprintf(stdout,"type ");\n\t\t\t}\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\tfprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);\n\t\tfprintf(stdout,"\\n");\n\t\t}\n\tfor (k=0; k<ALGOR_NUM; k++)\n\t\t{\n\t\tif (!doit[k]) continue;\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F:%d:%s",k,names[k]);\n\t\telse\n\t\t\tfprintf(stdout,"%-13s",names[k]);\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tif (results[k][j] > 10000 && !mr)\n\t\t\t\tfprintf(stdout," %11.2fk",results[k][j]/1e3);\n\t\t\telse\n\t\t\t\tfprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);\n\t\t\t}\n\t\tfprintf(stdout,"\\n");\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\tj=1;\n\tfor (k=0; k<RSA_NUM; k++)\n\t\t{\n\t\tif (!rsa_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%18ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F2:%u:%u:%f:%f\\n",\n\t\t\t\tk,rsa_bits[k],rsa_results[k][0],\n\t\t\t\trsa_results[k][1]);\n\t\telse\n\t\t\tfprintf(stdout,"rsa %4u bits %8.4fs %8.4fs %8.1f %8.1f\\n",\n\t\t\t\trsa_bits[k],rsa_results[k][0],rsa_results[k][1],\n\t\t\t\t1.0/rsa_results[k][0],1.0/rsa_results[k][1]);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tj=1;\n\tfor (k=0; k<DSA_NUM; k++)\n\t\t{\n\t\tif (!dsa_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%18ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F3:%u:%u:%f:%f\\n",\n\t\t\t\tk,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);\n\t\telse\n\t\t\tfprintf(stdout,"dsa %4u bits %8.4fs %8.4fs %8.1f %8.1f\\n",\n\t\t\t\tdsa_bits[k],dsa_results[k][0],dsa_results[k][1],\n\t\t\t\t1.0/dsa_results[k][0],1.0/dsa_results[k][1]);\n\t\t}\n#endif\n\tmret=0;\nend:\n\tERR_print_errors(bio_err);\n\tif (buf != NULL) OPENSSL_free(buf);\n\tif (buf2 != NULL) OPENSSL_free(buf2);\n#ifndef OPENSSL_NO_RSA\n\tfor (i=0; i<RSA_NUM; i++)\n\t\tif (rsa_key[i] != NULL)\n\t\t\tRSA_free(rsa_key[i]);\n#endif\n#ifndef OPENSSL_NO_DSA\n\tfor (i=0; i<DSA_NUM; i++)\n\t\tif (dsa_key[i] != NULL)\n\t\t\tDSA_free(dsa_key[i]);\n#endif\n\tapps_shutdown();\n\tEXIT(mret);\n\t}', 'void RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,\n\t\t int rounds)\n\t{\n\tRC5_32_INT L[64],l,ll,A,B,*S,k;\n\tint i,j,m,c,t,ii,jj;\n\tif (\t(rounds != RC5_16_ROUNDS) &&\n\t\t(rounds != RC5_12_ROUNDS) &&\n\t\t(rounds != RC5_8_ROUNDS))\n\t\trounds=RC5_16_ROUNDS;\n\tkey->rounds=rounds;\n\tS= &(key->data[0]);\n\tj=0;\n\tfor (i=0; i<=(len-8); i+=8)\n\t\t{\n\t\tc2l(data,l);\n\t\tL[j++]=l;\n\t\tc2l(data,l);\n\t\tL[j++]=l;\n\t\t}\n\tii=len-i;\n\tif (ii)\n\t\t{\n\t\tk=len&0x07;\n\t\tc2ln(data,l,ll,k);\n\t\tL[j+0]=l;\n\t\tL[j+1]=ll;\n\t\t}\n\tc=(len+3)/4;\n\tt=(rounds+1)*2;\n\tS[0]=RC5_32_P;\n\tfor (i=1; i<t; i++)\n\t\tS[i]=(S[i-1]+RC5_32_Q)&RC5_32_MASK;\n\tj=(t>c)?t:c;\n\tj*=3;\n\tii=jj=0;\n\tA=B=0;\n\tfor (i=0; i<j; i++)\n\t\t{\n\t\tk=(S[ii]+A+B)&RC5_32_MASK;\n\t\tA=S[ii]=ROTATE_l32(k,3);\n\t\tm=(int)(A+B);\n\t\tk=(L[jj]+A+B)&RC5_32_MASK;\n\t\tB=L[jj]=ROTATE_l32(k,m);\n\t\tif (++ii >= t) ii=0;\n\t\tif (++jj >= c) jj=0;\n\t\t}\n\t}']
2,540
0
https://github.com/openssl/openssl/blob/02cba628daa7fea959c561531a8a984756bdf41c/crypto/bn/bn_shift.c/#L112
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) { int i, nw, lb, rb; BN_ULONG *t, *f; BN_ULONG l; bn_check_top(r); bn_check_top(a); if (n < 0) { BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT); return 0; } nw = n / BN_BITS2; if (bn_wexpand(r, a->top + nw + 1) == NULL) return (0); r->neg = a->neg; lb = n % BN_BITS2; rb = BN_BITS2 - lb; f = a->d; t = r->d; t[a->top + nw] = 0; if (lb == 0) for (i = a->top - 1; i >= 0; i--) t[nw + i] = f[i]; else for (i = a->top - 1; i >= 0; i--) { l = f[i]; t[nw + i + 1] |= (l >> rb) & BN_MASK2; t[nw + i] = (l << lb) & BN_MASK2; } memset(t, 0, sizeof(*t) * nw); r->top = a->top + nw + 1; bn_correct_top(r); bn_check_top(r); return (1); }
['int rsa_main(int argc, char **argv)\n{\n ENGINE *e = NULL;\n BIO *out = NULL;\n RSA *rsa = NULL;\n const EVP_CIPHER *enc = NULL;\n char *infile = NULL, *outfile = NULL, *prog;\n char *passin = NULL, *passout = NULL, *passinarg = NULL, *passoutarg = NULL;\n int i, private = 0;\n int informat = FORMAT_PEM, outformat = FORMAT_PEM, text = 0, check = 0;\n int noout = 0, modulus = 0, pubin = 0, pubout = 0, ret = 1;\n# if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4)\n int pvk_encr = 2;\n# endif\n OPTION_CHOICE o;\n prog = opt_init(argc, argv, rsa_options);\n while ((o = opt_next()) != OPT_EOF) {\n switch (o) {\n case OPT_EOF:\n case OPT_ERR:\n opthelp:\n BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n goto end;\n case OPT_HELP:\n opt_help(rsa_options);\n ret = 0;\n goto end;\n case OPT_INFORM:\n if (!opt_format(opt_arg(), OPT_FMT_ANY, &informat))\n goto opthelp;\n break;\n case OPT_IN:\n infile = opt_arg();\n break;\n case OPT_OUTFORM:\n if (!opt_format(opt_arg(), OPT_FMT_ANY, &outformat))\n goto opthelp;\n break;\n case OPT_OUT:\n outfile = opt_arg();\n break;\n case OPT_PASSIN:\n passinarg = opt_arg();\n break;\n case OPT_PASSOUT:\n passoutarg = opt_arg();\n break;\n case OPT_ENGINE:\n e = setup_engine(opt_arg(), 0);\n break;\n case OPT_PUBIN:\n pubin = 1;\n break;\n case OPT_PUBOUT:\n pubout = 1;\n break;\n case OPT_RSAPUBKEY_IN:\n pubin = 2;\n break;\n case OPT_RSAPUBKEY_OUT:\n pubout = 2;\n break;\n case OPT_PVK_STRONG:\n case OPT_PVK_WEAK:\n case OPT_PVK_NONE:\n# if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4)\n pvk_encr = (o - OPT_PVK_NONE);\n# endif\n break;\n case OPT_NOOUT:\n noout = 1;\n break;\n case OPT_TEXT:\n text = 1;\n break;\n case OPT_MODULUS:\n modulus = 1;\n break;\n case OPT_CHECK:\n check = 1;\n break;\n case OPT_CIPHER:\n if (!opt_cipher(opt_unknown(), &enc))\n goto opthelp;\n break;\n }\n }\n argc = opt_num_rest();\n if (argc != 0)\n goto opthelp;\n private = (text && !pubin) || (!pubout && !noout) ? 1 : 0;\n if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {\n BIO_printf(bio_err, "Error getting passwords\\n");\n goto end;\n }\n if (check && pubin) {\n BIO_printf(bio_err, "Only private keys can be checked\\n");\n goto end;\n }\n {\n EVP_PKEY *pkey;\n if (pubin) {\n int tmpformat = -1;\n if (pubin == 2) {\n if (informat == FORMAT_PEM)\n tmpformat = FORMAT_PEMRSA;\n else if (informat == FORMAT_ASN1)\n tmpformat = FORMAT_ASN1RSA;\n } else\n tmpformat = informat;\n pkey = load_pubkey(infile, tmpformat, 1, passin, e, "Public Key");\n } else\n pkey = load_key(infile, informat, 1, passin, e, "Private Key");\n if (pkey != NULL)\n rsa = EVP_PKEY_get1_RSA(pkey);\n EVP_PKEY_free(pkey);\n }\n if (rsa == NULL) {\n ERR_print_errors(bio_err);\n goto end;\n }\n out = bio_open_owner(outfile, outformat, private);\n if (out == NULL)\n goto end;\n if (text) {\n assert(pubin || private);\n if (!RSA_print(out, rsa, 0)) {\n perror(outfile);\n ERR_print_errors(bio_err);\n goto end;\n }\n }\n if (modulus) {\n const BIGNUM *n;\n RSA_get0_key(rsa, &n, NULL, NULL);\n BIO_printf(out, "Modulus=");\n BN_print(out, n);\n BIO_printf(out, "\\n");\n }\n if (check) {\n int r = RSA_check_key(rsa);\n if (r == 1)\n BIO_printf(out, "RSA key ok\\n");\n else if (r == 0) {\n unsigned long err;\n while ((err = ERR_peek_error()) != 0 &&\n ERR_GET_LIB(err) == ERR_LIB_RSA &&\n ERR_GET_FUNC(err) == RSA_F_RSA_CHECK_KEY &&\n ERR_GET_REASON(err) != ERR_R_MALLOC_FAILURE) {\n BIO_printf(out, "RSA key error: %s\\n",\n ERR_reason_error_string(err));\n ERR_get_error();\n }\n } else if (r == -1) {\n ERR_print_errors(bio_err);\n goto end;\n }\n }\n if (noout) {\n ret = 0;\n goto end;\n }\n BIO_printf(bio_err, "writing RSA key\\n");\n if (outformat == FORMAT_ASN1) {\n if (pubout || pubin) {\n if (pubout == 2)\n i = i2d_RSAPublicKey_bio(out, rsa);\n else\n i = i2d_RSA_PUBKEY_bio(out, rsa);\n } else {\n assert(private);\n i = i2d_RSAPrivateKey_bio(out, rsa);\n }\n }\n else if (outformat == FORMAT_PEM) {\n if (pubout || pubin) {\n if (pubout == 2)\n i = PEM_write_bio_RSAPublicKey(out, rsa);\n else\n i = PEM_write_bio_RSA_PUBKEY(out, rsa);\n } else {\n assert(private);\n i = PEM_write_bio_RSAPrivateKey(out, rsa,\n enc, NULL, 0, NULL, passout);\n }\n# ifndef OPENSSL_NO_DSA\n } else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) {\n EVP_PKEY *pk;\n pk = EVP_PKEY_new();\n EVP_PKEY_set1_RSA(pk, rsa);\n if (outformat == FORMAT_PVK) {\n if (pubin) {\n BIO_printf(bio_err, "PVK form impossible with public key input\\n");\n EVP_PKEY_free(pk);\n goto end;\n }\n assert(private);\n# ifdef OPENSSL_NO_RC4\n BIO_printf(bio_err, "PVK format not supported\\n");\n EVP_PKEY_free(pk);\n goto end;\n# else\n i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);\n# endif\n } else if (pubin || pubout) {\n i = i2b_PublicKey_bio(out, pk);\n } else {\n assert(private);\n i = i2b_PrivateKey_bio(out, pk);\n }\n EVP_PKEY_free(pk);\n# endif\n } else {\n BIO_printf(bio_err, "bad output format specified for outfile\\n");\n goto end;\n }\n if (i <= 0) {\n BIO_printf(bio_err, "unable to write key\\n");\n ERR_print_errors(bio_err);\n } else\n ret = 0;\n end:\n release_engine(e);\n BIO_free_all(out);\n RSA_free(rsa);\n OPENSSL_free(passin);\n OPENSSL_free(passout);\n return (ret);\n}', 'int BN_print(BIO *bp, const BIGNUM *a)\n{\n int i, j, v, z = 0;\n int ret = 0;\n if ((a->neg) && (BIO_write(bp, "-", 1) != 1))\n goto end;\n if (BN_is_zero(a) && (BIO_write(bp, "0", 1) != 1))\n goto end;\n for (i = a->top - 1; i >= 0; i--) {\n for (j = BN_BITS2 - 4; j >= 0; j -= 4) {\n v = ((int)(a->d[i] >> (long)j)) & 0x0f;\n if (z || (v != 0)) {\n if (BIO_write(bp, &(Hex[v]), 1) != 1)\n goto end;\n z = 1;\n }\n }\n }\n ret = 1;\n end:\n return (ret);\n}', 'int RSA_check_key(const RSA *key)\n{\n return RSA_check_key_ex(key, NULL);\n}', 'int RSA_check_key_ex(const RSA *key, BN_GENCB *cb)\n{\n BIGNUM *i, *j, *k, *l, *m;\n BN_CTX *ctx;\n int ret = 1;\n if (key->p == NULL || key->q == NULL || key->n == NULL\n || key->e == NULL || key->d == NULL) {\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_VALUE_MISSING);\n return 0;\n }\n i = BN_new();\n j = BN_new();\n k = BN_new();\n l = BN_new();\n m = BN_new();\n ctx = BN_CTX_new();\n if (i == NULL || j == NULL || k == NULL || l == NULL\n || m == NULL || ctx == NULL) {\n ret = -1;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (BN_is_one(key->e)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n }\n if (!BN_is_odd(key->e)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n }\n if (BN_is_prime_ex(key->p, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_P_NOT_PRIME);\n }\n if (BN_is_prime_ex(key->q, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_Q_NOT_PRIME);\n }\n if (!BN_mul(i, key->p, key->q, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(i, key->n) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_N_DOES_NOT_EQUAL_P_Q);\n }\n if (!BN_sub(i, key->p, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_sub(j, key->q, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mul(l, i, j, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_gcd(m, i, j, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_div(k, NULL, l, m, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_mod_mul(i, key->d, key->e, k, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_is_one(i)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_D_E_NOT_CONGRUENT_TO_1);\n }\n if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) {\n if (!BN_sub(i, key->p, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, key->dmp1) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMP1_NOT_CONGRUENT_TO_D);\n }\n if (!BN_sub(i, key->q, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, key->dmq1) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMQ1_NOT_CONGRUENT_TO_D);\n }\n if (!BN_mod_inverse(i, key->q, key->p, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(i, key->iqmp) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_IQMP_NOT_INVERSE_OF_Q);\n }\n }\n err:\n BN_free(i);\n BN_free(j);\n BN_free(k);\n BN_free(l);\n BN_free(m);\n BN_CTX_free(ctx);\n return ret;\n}', '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 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_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
2,541
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 decode_exp_vlc(WMACodecContext *s, int ch)\n{\n int last_exp, n, code;\n const uint16_t *ptr;\n float v, max_scale;\n uint32_t *q, *q_end, iv;\n const float *ptab = pow_tab + 60;\n const uint32_t *iptab = (const uint32_t *) ptab;\n ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];\n q = (uint32_t *) s->exponents[ch];\n q_end = q + s->block_len;\n max_scale = 0;\n if (s->version == 1) {\n last_exp = bitstream_read(&s->bc, 5) + 10;\n v = ptab[last_exp];\n iv = iptab[last_exp];\n max_scale = v;\n n = *ptr++;\n switch (n & 3) do {\n case 0: *q++ = iv;\n case 3: *q++ = iv;\n case 2: *q++ = iv;\n case 1: *q++ = iv;\n } while ((n -= 4) > 0);\n } else\n last_exp = 36;\n while (q < q_end) {\n code = bitstream_read_vlc(&s->bc, s->exp_vlc.table, EXPVLCBITS, EXPMAX);\n if (code < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "Exponent vlc invalid\\n");\n return -1;\n }\n last_exp += code - 60;\n if ((unsigned) last_exp + 60 >= FF_ARRAY_ELEMS(pow_tab)) {\n av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\\n",\n last_exp);\n return -1;\n }\n v = ptab[last_exp];\n iv = iptab[last_exp];\n if (v > max_scale)\n max_scale = v;\n n = *ptr++;\n switch (n & 3) do {\n case 0: *q++ = iv;\n case 3: *q++ = iv;\n case 2: *q++ = iv;\n case 1: *q++ = iv;\n } while ((n -= 4) > 0);\n }\n s->max_exponent[ch] = max_scale;\n return 0;\n}', 'static inline int bitstream_read_vlc(BitstreamContext *bc, VLC_TYPE (*table)[2],\n int bits, int max_depth)\n{\n int nb_bits;\n unsigned idx = bitstream_peek(bc, bits);\n int code = table[idx][0];\n int n = table[idx][1];\n if (max_depth > 1 && n < 0) {\n skip_remaining(bc, bits);\n code = set_idx(bc, code, &n, &nb_bits, table);\n if (max_depth > 2 && n < 0) {\n skip_remaining(bc, nb_bits);\n code = set_idx(bc, code, &n, &nb_bits, table);\n }\n }\n skip_remaining(bc, n);\n return code;\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
2,542
0
https://github.com/openssl/openssl/blob/5e5d53d341fd9a9b9cc0a58eb3690832ca7a511f/crypto/des/set_key.c/#L420
void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule) { static const int shifts2[16] = { 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0 }; register DES_LONG c, d, t, s, t2; register const unsigned char *in; register DES_LONG *k; register int i; #ifdef OPENBSD_DEV_CRYPTO memcpy(schedule->key, key, sizeof schedule->key); schedule->session = NULL; #endif k = &schedule->ks->deslong[0]; in = &(*key)[0]; c2l(in, c); c2l(in, d); PERM_OP(d, c, t, 4, 0x0f0f0f0fL); HPERM_OP(c, t, -2, 0xcccc0000L); HPERM_OP(d, t, -2, 0xcccc0000L); PERM_OP(d, c, t, 1, 0x55555555L); PERM_OP(c, d, t, 8, 0x00ff00ffL); PERM_OP(d, c, t, 1, 0x55555555L); d = (((d & 0x000000ffL) << 16L) | (d & 0x0000ff00L) | ((d & 0x00ff0000L) >> 16L) | ((c & 0xf0000000L) >> 4L)); c &= 0x0fffffffL; for (i = 0; i < ITERATIONS; i++) { if (shifts2[i]) { c = ((c >> 2L) | (c << 26L)); d = ((d >> 2L) | (d << 26L)); } else { c = ((c >> 1L) | (c << 27L)); d = ((d >> 1L) | (d << 27L)); } c &= 0x0fffffffL; d &= 0x0fffffffL; s = des_skb[0][(c) & 0x3f] | des_skb[1][((c >> 6L) & 0x03) | ((c >> 7L) & 0x3c)] | des_skb[2][((c >> 13L) & 0x0f) | ((c >> 14L) & 0x30)] | des_skb[3][((c >> 20L) & 0x01) | ((c >> 21L) & 0x06) | ((c >> 22L) & 0x38)]; t = des_skb[4][(d) & 0x3f] | des_skb[5][((d >> 7L) & 0x03) | ((d >> 8L) & 0x3c)] | des_skb[6][(d >> 15L) & 0x3f] | des_skb[7][((d >> 21L) & 0x0f) | ((d >> 22L) & 0x30)]; t2 = ((t << 16L) | (s & 0x0000ffffL)) & 0xffffffffL; *(k++) = ROTATE(t2, 30) & 0xffffffffL; t2 = ((s >> 16L) | (t & 0xffff0000L)); *(k++) = ROTATE(t2, 26) & 0xffffffffL; } }
['void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule)\n{\n static const int shifts2[16] =\n { 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0 };\n register DES_LONG c, d, t, s, t2;\n register const unsigned char *in;\n register DES_LONG *k;\n register int i;\n#ifdef OPENBSD_DEV_CRYPTO\n memcpy(schedule->key, key, sizeof schedule->key);\n schedule->session = NULL;\n#endif\n k = &schedule->ks->deslong[0];\n in = &(*key)[0];\n c2l(in, c);\n c2l(in, d);\n PERM_OP(d, c, t, 4, 0x0f0f0f0fL);\n HPERM_OP(c, t, -2, 0xcccc0000L);\n HPERM_OP(d, t, -2, 0xcccc0000L);\n PERM_OP(d, c, t, 1, 0x55555555L);\n PERM_OP(c, d, t, 8, 0x00ff00ffL);\n PERM_OP(d, c, t, 1, 0x55555555L);\n d = (((d & 0x000000ffL) << 16L) | (d & 0x0000ff00L) |\n ((d & 0x00ff0000L) >> 16L) | ((c & 0xf0000000L) >> 4L));\n c &= 0x0fffffffL;\n for (i = 0; i < ITERATIONS; i++) {\n if (shifts2[i]) {\n c = ((c >> 2L) | (c << 26L));\n d = ((d >> 2L) | (d << 26L));\n } else {\n c = ((c >> 1L) | (c << 27L));\n d = ((d >> 1L) | (d << 27L));\n }\n c &= 0x0fffffffL;\n d &= 0x0fffffffL;\n s = des_skb[0][(c) & 0x3f] |\n des_skb[1][((c >> 6L) & 0x03) | ((c >> 7L) & 0x3c)] |\n des_skb[2][((c >> 13L) & 0x0f) | ((c >> 14L) & 0x30)] |\n des_skb[3][((c >> 20L) & 0x01) | ((c >> 21L) & 0x06) |\n ((c >> 22L) & 0x38)];\n t = des_skb[4][(d) & 0x3f] |\n des_skb[5][((d >> 7L) & 0x03) | ((d >> 8L) & 0x3c)] |\n des_skb[6][(d >> 15L) & 0x3f] |\n des_skb[7][((d >> 21L) & 0x0f) | ((d >> 22L) & 0x30)];\n t2 = ((t << 16L) | (s & 0x0000ffffL)) & 0xffffffffL;\n *(k++) = ROTATE(t2, 30) & 0xffffffffL;\n t2 = ((s >> 16L) | (t & 0xffff0000L));\n *(k++) = ROTATE(t2, 26) & 0xffffffffL;\n }\n}']
2,543
0
https://github.com/libav/libav/blob/62a1ef9f26c654a3e988aa465c4ac1d776c4c356/avtools/avconv_hw.c/#L299
int hw_device_setup_for_decode(InputStream *ist) { enum AVHWDeviceType type; HWDevice *dev; const char *type_name; int err; if (ist->hwaccel_device) { dev = hw_device_get_by_name(ist->hwaccel_device); if (!dev) { char *tmp; size_t len; type = hw_device_match_type_by_hwaccel(ist->hwaccel_id); if (type == AV_HWDEVICE_TYPE_NONE) { return 0; } type_name = av_hwdevice_get_type_name(type); len = strlen(type_name) + 1 + strlen(ist->hwaccel_device) + 1; tmp = av_malloc(len); if (!tmp) return AVERROR(ENOMEM); snprintf(tmp, len, "%s:%s", type_name, ist->hwaccel_device); err = hw_device_init_from_string(tmp, &dev); av_free(tmp); if (err < 0) return err; } } else { if (ist->hwaccel_id != HWACCEL_NONE) type = hw_device_match_type_by_hwaccel(ist->hwaccel_id); else type = hw_device_match_type_in_name(ist->dec->name); if (type != AV_HWDEVICE_TYPE_NONE) { dev = hw_device_get_by_type(type); } else { return 0; } } if (!dev) { av_log(ist->dec_ctx, AV_LOG_WARNING, "No device available " "for decoder (device type %s for codec %s).\n", av_hwdevice_get_type_name(type), ist->dec->name); return 0; } ist->dec_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref); if (!ist->dec_ctx->hw_device_ctx) return AVERROR(ENOMEM); return 0; }
['int hw_device_setup_for_decode(InputStream *ist)\n{\n enum AVHWDeviceType type;\n HWDevice *dev;\n const char *type_name;\n int err;\n if (ist->hwaccel_device) {\n dev = hw_device_get_by_name(ist->hwaccel_device);\n if (!dev) {\n char *tmp;\n size_t len;\n type = hw_device_match_type_by_hwaccel(ist->hwaccel_id);\n if (type == AV_HWDEVICE_TYPE_NONE) {\n return 0;\n }\n type_name = av_hwdevice_get_type_name(type);\n len = strlen(type_name) + 1 +\n strlen(ist->hwaccel_device) + 1;\n tmp = av_malloc(len);\n if (!tmp)\n return AVERROR(ENOMEM);\n snprintf(tmp, len, "%s:%s", type_name, ist->hwaccel_device);\n err = hw_device_init_from_string(tmp, &dev);\n av_free(tmp);\n if (err < 0)\n return err;\n }\n } else {\n if (ist->hwaccel_id != HWACCEL_NONE)\n type = hw_device_match_type_by_hwaccel(ist->hwaccel_id);\n else\n type = hw_device_match_type_in_name(ist->dec->name);\n if (type != AV_HWDEVICE_TYPE_NONE) {\n dev = hw_device_get_by_type(type);\n } else {\n return 0;\n }\n }\n if (!dev) {\n av_log(ist->dec_ctx, AV_LOG_WARNING, "No device available "\n "for decoder (device type %s for codec %s).\\n",\n av_hwdevice_get_type_name(type), ist->dec->name);\n return 0;\n }\n ist->dec_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);\n if (!ist->dec_ctx->hw_device_ctx)\n return AVERROR(ENOMEM);\n return 0;\n}']
2,544
0
https://gitlab.com/libtiff/libtiff/blob/771a4ea0a98c7a218c9f3add9a05e08d29625758/libtiff/tif_read.c/#L748
static int TIFFStartTile(TIFF* tif, uint32 tile) { TIFFDirectory *td = &tif->tif_dir; if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { if (!(*tif->tif_setupdecode)(tif)) return (0); tif->tif_flags |= TIFF_CODERSETUP; } tif->tif_curtile = tile; tif->tif_row = (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) * td->td_tilelength; tif->tif_col = (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) * td->td_tilewidth; tif->tif_flags &= ~TIFF_BUF4WRITE; if (tif->tif_flags&TIFF_NOREADRAW) { tif->tif_rawcp = NULL; tif->tif_rawcc = 0; } else { tif->tif_rawcp = tif->tif_rawdata; tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile]; } return ((*tif->tif_predecode)(tif, (uint16)(tile/td->td_stripsperimage))); }
['void\nTIFFReadContigTileData(TIFF* tif)\n{\n\tunsigned char *buf;\n\ttsize_t rowsize = TIFFTileRowSize(tif);\n\tbuf = (unsigned char *)_TIFFmalloc(TIFFTileSize(tif));\n\tif (buf) {\n\t\tuint32 tw, th, w, h;\n\t\tuint32 row, col;\n\t\tTIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);\n\t\tTIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);\n\t\tTIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw);\n\t\tTIFFGetField(tif, TIFFTAG_TILELENGTH, &th);\n\t\tfor (row = 0; row < h; row += th) {\n\t\t\tfor (col = 0; col < w; col += tw) {\n\t\t\t\tif (TIFFReadTile(tif, buf, col, row, 0, 0) < 0) {\n\t\t\t\t\tif (stoponerr)\n\t\t\t\t\t\tbreak;\n\t\t\t\t} else if (showdata)\n\t\t\t\t\tShowTile(row, col, (tsample_t) -1, buf, th, rowsize);\n\t\t\t}\n\t\t}\n\t\t_TIFFfree(buf);\n\t}\n}', 'tmsize_t\nTIFFTileRowSize(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFTileRowSize";\n\tuint64 m;\n\ttmsize_t n;\n\tm=TIFFTileRowSize64(tif);\n\tn=(tmsize_t)m;\n\tif ((uint64)n!=m)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\tn=0;\n\t}\n\treturn(n);\n}', 'uint64\nTIFFTileRowSize64(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint64 rowsize;\n\tif (td->td_tilelength == 0 || td->td_tilewidth == 0)\n\t\treturn (0);\n\trowsize = multiply_64(tif, td->td_bitspersample, td->td_tilewidth,\n\t "TIFFTileRowSize");\n\tif (td->td_planarconfig == PLANARCONFIG_CONTIG)\n\t\trowsize = multiply_64(tif, rowsize, td->td_samplesperpixel,\n\t\t "TIFFTileRowSize");\n\treturn (TIFFhowmany8_64(rowsize));\n}', 'tmsize_t\nTIFFTileSize(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFTileSize";\n\tuint64 m;\n\ttmsize_t n;\n\tm=TIFFTileSize64(tif);\n\tn=(tmsize_t)m;\n\tif ((uint64)n!=m)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\tn=0;\n\t}\n\treturn(n);\n}', 'uint64\nTIFFTileSize64(TIFF* tif)\n{\n\treturn (TIFFVTileSize64(tif, tif->tif_dir.td_tilelength));\n}', 'uint64\nTIFFVTileSize64(TIFF* tif, uint32 nrows)\n{\n\tstatic const char module[] = "TIFFVTileSize64";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif (td->td_tilelength == 0 || td->td_tilewidth == 0 ||\n\t td->td_tiledepth == 0)\n\t\treturn (0);\n\tif ((td->td_planarconfig==PLANARCONFIG_CONTIG)&&\n\t (td->td_photometric==PHOTOMETRIC_YCBCR)&&\n\t (td->td_samplesperpixel==3)&&\n\t (!isUpSampled(tif)))\n\t{\n\t\tuint16 ycbcrsubsampling[2];\n\t\tuint16 samplingblock_samples;\n\t\tuint32 samplingblocks_hor;\n\t\tuint32 samplingblocks_ver;\n\t\tuint64 samplingrow_samples;\n\t\tuint64 samplingrow_size;\n\t\tTIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0,\n\t\t ycbcrsubsampling+1);\n\t\tassert((ycbcrsubsampling[0]==1)||(ycbcrsubsampling[0]==2)||(ycbcrsubsampling[0]==4));\n\t\tassert((ycbcrsubsampling[1]==1)||(ycbcrsubsampling[1]==2)||(ycbcrsubsampling[1]==4));\n\t\tif (ycbcrsubsampling[0]*ycbcrsubsampling[1]==0)\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t\t "Invalid YCbCr subsampling");\n\t\t\treturn 0;\n\t\t}\n\t\tsamplingblock_samples=ycbcrsubsampling[0]*ycbcrsubsampling[1]+2;\n\t\tsamplingblocks_hor=TIFFhowmany_32(td->td_tilewidth,ycbcrsubsampling[0]);\n\t\tsamplingblocks_ver=TIFFhowmany_32(nrows,ycbcrsubsampling[1]);\n\t\tsamplingrow_samples=multiply_64(tif,samplingblocks_hor,samplingblock_samples,module);\n\t\tsamplingrow_size=TIFFhowmany8_64(multiply_64(tif,samplingrow_samples,td->td_bitspersample,module));\n\t\treturn(multiply_64(tif,samplingrow_size,samplingblocks_ver,module));\n\t}\n\telse\n\t\treturn(multiply_64(tif,nrows,TIFFTileRowSize64(tif),module));\n}', 'tmsize_t\nTIFFReadTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tif (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s))\n\t\treturn ((tmsize_t)(-1));\n\treturn (TIFFReadEncodedTile(tif,\n\t TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1)));\n}', 'tmsize_t\nTIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)\n{\n\tstatic const char module[] = "TIFFReadEncodedTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\ttmsize_t tilesize = tif->tif_tilesize;\n\tif (!TIFFCheckRead(tif, 1))\n\t\treturn ((tmsize_t)(-1));\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "%lu: Tile out of range, max %lu",\n\t\t (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n\tif (size == (tmsize_t)(-1))\n\t\tsize = tilesize;\n\telse if (size > tilesize)\n\t\tsize = tilesize;\n\tif (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,\n\t (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) {\n\t\t(*tif->tif_postdecode)(tif, (uint8*) buf, size);\n\t\treturn (size);\n\t} else\n\t\treturn ((tmsize_t)(-1));\n}', 'int\nTIFFFillTile(TIFF* tif, uint32 tile)\n{\n\tstatic const char module[] = "TIFFFillTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags&TIFF_NOREADRAW)==0)\n\t{\n\t\tuint64 bytecount = td->td_stripbytecount[tile];\n\t\tif (bytecount <= 0) {\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%I64u: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned __int64) bytecount,\n\t\t\t\t (unsigned long) tile);\n#else\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%llu: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned long long) bytecount,\n\t\t\t\t (unsigned long) tile);\n#endif\n\t\t\treturn (0);\n\t\t}\n\t\tif (isMapped(tif) &&\n\t\t (isFillOrder(tif, td->td_fillorder)\n\t\t || (tif->tif_flags & TIFF_NOBITREV))) {\n\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)\n\t\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\ttif->tif_flags &= ~TIFF_MYBUFFER;\n\t\t\tif (bytecount > (uint64)tif->tif_size ||\n\t\t\t td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\ttif->tif_rawdatasize = (tmsize_t)bytecount;\n\t\t\ttif->tif_rawdata =\n\t\t\t\ttif->tif_base + (tmsize_t)td->td_stripoffset[tile];\n\t\t} else {\n\t\t\ttmsize_t bytecountm;\n\t\t\tbytecountm=(tmsize_t)bytecount;\n\t\t\tif ((uint64)bytecountm!=bytecount)\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif (bytecountm > tif->tif_rawdatasize) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) == 0) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Data buffer too small to hold tile %lu",\n\t\t\t\t\t (unsigned long) tile);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (TIFFReadRawTile1(tif, tile, tif->tif_rawdata,\n\t\t\t bytecountm, module) != bytecountm)\n\t\t\t\treturn (0);\n\t\t\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t\t\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\t\t\tTIFFReverseBits(tif->tif_rawdata, bytecountm);\n\t\t}\n\t}\n\treturn (TIFFStartTile(tif, tile));\n}', 'static int\nTIFFStartTile(TIFF* tif, uint32 tile)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupdecode)(tif))\n\t\t\treturn (0);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_curtile = tile;\n\ttif->tif_row =\n\t (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) *\n\t\ttd->td_tilelength;\n\ttif->tif_col =\n\t (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) *\n\t\ttd->td_tilewidth;\n tif->tif_flags &= ~TIFF_BUF4WRITE;\n\tif (tif->tif_flags&TIFF_NOREADRAW)\n\t{\n\t\ttif->tif_rawcp = NULL;\n\t\ttif->tif_rawcc = 0;\n\t}\n\telse\n\t{\n\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\ttif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];\n\t}\n\treturn ((*tif->tif_predecode)(tif,\n\t\t\t(uint16)(tile/td->td_stripsperimage)));\n}']
2,545
0
https://github.com/libav/libav/blob/fe533ffdcffadb3e55f07d0caf316bc6bfe82049/libavcodec/png_parser.c/#L86
static int png_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { PNGParseContext *ppc = s->priv_data; int next = END_NOT_FOUND; int i = 0; *poutbuf_size = 0; if (buf_size == 0) return 0; if (!ppc->pc.frame_start_found) { uint64_t state64 = ppc->pc.state64; for (; i < buf_size; i++) { state64 = (state64 << 8) | buf[i]; if (state64 == PNG_SIGNATURE || state64 == MNG_SIGNATURE) { i++; ppc->pc.frame_start_found = 1; break; } } ppc->pc.state64 = state64; } else if (ppc->remaining_size) { i = FFMIN(ppc->remaining_size, buf_size); ppc->remaining_size -= i; if (ppc->remaining_size) goto flush; if (ppc->chunk_pos == -1) { next = i; goto flush; } } for (; ppc->pc.frame_start_found && i < buf_size; i++) { ppc->pc.state = (ppc->pc.state << 8) | buf[i]; if (ppc->chunk_pos == 3) { ppc->chunk_length = ppc->pc.state; if (ppc->chunk_length > 0x7fffffff) { ppc->chunk_pos = ppc->pc.frame_start_found = 0; goto flush; } ppc->chunk_length += 4; } else if (ppc->chunk_pos == 7) { if (ppc->chunk_length >= buf_size - i) ppc->remaining_size = ppc->chunk_length - buf_size + i + 1; if (ppc->pc.state == MKBETAG('I', 'E', 'N', 'D')) { if (ppc->remaining_size) ppc->chunk_pos = -1; else next = ppc->chunk_length + i + 1; break; } else { ppc->chunk_pos = 0; if (ppc->remaining_size) break; else i += ppc->chunk_length; continue; } } ppc->chunk_pos++; } flush: if (ff_combine_frame(&ppc->pc, next, &buf, &buf_size) < 0) return buf_size; ppc->chunk_pos = ppc->pc.frame_start_found = 0; *poutbuf = buf; *poutbuf_size = buf_size; return next; }
["static int png_parse(AVCodecParserContext *s, AVCodecContext *avctx,\n const uint8_t **poutbuf, int *poutbuf_size,\n const uint8_t *buf, int buf_size)\n{\n PNGParseContext *ppc = s->priv_data;\n int next = END_NOT_FOUND;\n int i = 0;\n *poutbuf_size = 0;\n if (buf_size == 0)\n return 0;\n if (!ppc->pc.frame_start_found) {\n uint64_t state64 = ppc->pc.state64;\n for (; i < buf_size; i++) {\n state64 = (state64 << 8) | buf[i];\n if (state64 == PNG_SIGNATURE ||\n state64 == MNG_SIGNATURE) {\n i++;\n ppc->pc.frame_start_found = 1;\n break;\n }\n }\n ppc->pc.state64 = state64;\n } else if (ppc->remaining_size) {\n i = FFMIN(ppc->remaining_size, buf_size);\n ppc->remaining_size -= i;\n if (ppc->remaining_size)\n goto flush;\n if (ppc->chunk_pos == -1) {\n next = i;\n goto flush;\n }\n }\n for (; ppc->pc.frame_start_found && i < buf_size; i++) {\n ppc->pc.state = (ppc->pc.state << 8) | buf[i];\n if (ppc->chunk_pos == 3) {\n ppc->chunk_length = ppc->pc.state;\n if (ppc->chunk_length > 0x7fffffff) {\n ppc->chunk_pos = ppc->pc.frame_start_found = 0;\n goto flush;\n }\n ppc->chunk_length += 4;\n } else if (ppc->chunk_pos == 7) {\n if (ppc->chunk_length >= buf_size - i)\n ppc->remaining_size = ppc->chunk_length - buf_size + i + 1;\n if (ppc->pc.state == MKBETAG('I', 'E', 'N', 'D')) {\n if (ppc->remaining_size)\n ppc->chunk_pos = -1;\n else\n next = ppc->chunk_length + i + 1;\n break;\n } else {\n ppc->chunk_pos = 0;\n if (ppc->remaining_size)\n break;\n else\n i += ppc->chunk_length;\n continue;\n }\n }\n ppc->chunk_pos++;\n }\nflush:\n if (ff_combine_frame(&ppc->pc, next, &buf, &buf_size) < 0)\n return buf_size;\n ppc->chunk_pos = ppc->pc.frame_start_found = 0;\n *poutbuf = buf;\n *poutbuf_size = buf_size;\n return next;\n}"]
2,546
0
https://github.com/openssl/openssl/blob/f09877c12c830d16f38064dace415679e867fc0f/test/curve448_internal_test.c/#L638
static int test_ed448(void) { uint8_t outsig[114]; EVP_MD_CTX *hashctx = EVP_MD_CTX_new(); if (!TEST_ptr(hashctx) || !TEST_true(ED448_sign(outsig, NULL, 0, pubkey1, privkey1, NULL, 0)) || !TEST_int_eq(memcmp(sig1, outsig, sizeof(sig1)), 0) || !TEST_true(ED448_sign(outsig, msg2, sizeof(msg2), pubkey2, privkey2, NULL, 0)) || !TEST_int_eq(memcmp(sig2, outsig, sizeof(sig2)), 0) || !TEST_true(ED448_sign(outsig, msg3, sizeof(msg3), pubkey3, privkey3, context3, sizeof(context3))) || !TEST_int_eq(memcmp(sig3, outsig, sizeof(sig3)), 0) || !TEST_true(ED448_sign(outsig, msg4, sizeof(msg4), pubkey4, privkey4, NULL, 0)) || !TEST_int_eq(memcmp(sig4, outsig, sizeof(sig4)), 0) || !TEST_true(ED448_sign(outsig, msg5, sizeof(msg5), pubkey5, privkey5, NULL, 0)) || !TEST_int_eq(memcmp(sig5, outsig, sizeof(sig5)), 0) || !TEST_true(ED448_sign(outsig, msg6, sizeof(msg6), pubkey6, privkey6, NULL, 0)) || !TEST_int_eq(memcmp(sig6, outsig, sizeof(sig6)), 0) || !TEST_true(ED448_sign(outsig, msg7, sizeof(msg7), pubkey7, privkey7, NULL, 0)) || !TEST_int_eq(memcmp(sig7, outsig, sizeof(sig7)), 0) || !TEST_true(ED448_sign(outsig, msg8, sizeof(msg8), pubkey8, privkey8, NULL, 0)) || !TEST_int_eq(memcmp(sig8, outsig, sizeof(sig8)), 0) || !TEST_true(ED448_sign(outsig, msg9, sizeof(msg9), pubkey9, privkey9, NULL, 0)) || !TEST_int_eq(memcmp(sig9, outsig, sizeof(sig9)), 0) || !TEST_true(ED448ph_sign(outsig, dohash(hashctx, phmsg1, sizeof(phmsg1)), phpubkey1, phprivkey1, NULL, 0)) || !TEST_int_eq(memcmp(phsig1, outsig, sizeof(phsig1)), 0) || !TEST_true(ED448ph_sign(outsig, dohash(hashctx, phmsg2, sizeof(phmsg2)), phpubkey2, phprivkey2, phcontext2, sizeof(phcontext2))) || !TEST_int_eq(memcmp(phsig2, outsig, sizeof(phsig2)), 0)) { EVP_MD_CTX_free(hashctx); return 0; } EVP_MD_CTX_free(hashctx); return 1; }
['static int test_ed448(void)\n{\n uint8_t outsig[114];\n EVP_MD_CTX *hashctx = EVP_MD_CTX_new();\n if (!TEST_ptr(hashctx)\n || !TEST_true(ED448_sign(outsig, NULL, 0, pubkey1, privkey1, NULL,\n 0))\n || !TEST_int_eq(memcmp(sig1, outsig, sizeof(sig1)), 0)\n || !TEST_true(ED448_sign(outsig, msg2, sizeof(msg2), pubkey2,\n privkey2, NULL, 0))\n || !TEST_int_eq(memcmp(sig2, outsig, sizeof(sig2)), 0)\n || !TEST_true(ED448_sign(outsig, msg3, sizeof(msg3), pubkey3,\n privkey3, context3, sizeof(context3)))\n || !TEST_int_eq(memcmp(sig3, outsig, sizeof(sig3)), 0)\n || !TEST_true(ED448_sign(outsig, msg4, sizeof(msg4), pubkey4,\n privkey4, NULL, 0))\n || !TEST_int_eq(memcmp(sig4, outsig, sizeof(sig4)), 0)\n || !TEST_true(ED448_sign(outsig, msg5, sizeof(msg5), pubkey5,\n privkey5, NULL, 0))\n || !TEST_int_eq(memcmp(sig5, outsig, sizeof(sig5)), 0)\n || !TEST_true(ED448_sign(outsig, msg6, sizeof(msg6), pubkey6,\n privkey6, NULL, 0))\n || !TEST_int_eq(memcmp(sig6, outsig, sizeof(sig6)), 0)\n || !TEST_true(ED448_sign(outsig, msg7, sizeof(msg7), pubkey7,\n privkey7, NULL, 0))\n || !TEST_int_eq(memcmp(sig7, outsig, sizeof(sig7)), 0)\n || !TEST_true(ED448_sign(outsig, msg8, sizeof(msg8), pubkey8,\n privkey8, NULL, 0))\n || !TEST_int_eq(memcmp(sig8, outsig, sizeof(sig8)), 0)\n || !TEST_true(ED448_sign(outsig, msg9, sizeof(msg9), pubkey9,\n privkey9, NULL, 0))\n || !TEST_int_eq(memcmp(sig9, outsig, sizeof(sig9)), 0)\n || !TEST_true(ED448ph_sign(outsig, dohash(hashctx, phmsg1,\n sizeof(phmsg1)), phpubkey1, phprivkey1,\n NULL, 0))\n || !TEST_int_eq(memcmp(phsig1, outsig, sizeof(phsig1)), 0)\n || !TEST_true(ED448ph_sign(outsig, dohash(hashctx, phmsg2,\n sizeof(phmsg2)), phpubkey2, phprivkey2,\n phcontext2, sizeof(phcontext2)))\n || !TEST_int_eq(memcmp(phsig2, outsig, sizeof(phsig2)), 0)) {\n EVP_MD_CTX_free(hashctx);\n return 0;\n }\n EVP_MD_CTX_free(hashctx);\n return 1;\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 if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int test_ptr(const char *file, int line, const char *s, const void *p)\n{\n if (p != NULL)\n return 1;\n test_fail_message(NULL, file, line, "ptr", s, "NULL", "!=", "%p", p);\n return 0;\n}', 'int ED448_sign(uint8_t *out_sig, const uint8_t *message, size_t message_len,\n const uint8_t public_key[57], const uint8_t private_key[57],\n const uint8_t *context, size_t context_len)\n{\n return c448_ed448_sign(out_sig, private_key, public_key, message,\n message_len, 0, context, context_len)\n == C448_SUCCESS;\n}', 'c448_error_t c448_ed448_sign(\n uint8_t signature[EDDSA_448_SIGNATURE_BYTES],\n const uint8_t privkey[EDDSA_448_PRIVATE_BYTES],\n const uint8_t pubkey[EDDSA_448_PUBLIC_BYTES],\n const uint8_t *message, size_t message_len,\n uint8_t prehashed, const uint8_t *context,\n size_t context_len)\n{\n curve448_scalar_t secret_scalar;\n EVP_MD_CTX *hashctx = EVP_MD_CTX_new();\n c448_error_t ret = C448_FAILURE;\n curve448_scalar_t nonce_scalar;\n uint8_t nonce_point[EDDSA_448_PUBLIC_BYTES] = { 0 };\n unsigned int c;\n curve448_scalar_t challenge_scalar;\n if (hashctx == NULL)\n return C448_FAILURE;\n {\n uint8_t expanded[EDDSA_448_PRIVATE_BYTES * 2];\n if (!oneshot_hash(expanded, sizeof(expanded), privkey,\n EDDSA_448_PRIVATE_BYTES))\n goto err;\n clamp(expanded);\n curve448_scalar_decode_long(secret_scalar, expanded,\n EDDSA_448_PRIVATE_BYTES);\n if (!hash_init_with_dom(hashctx, prehashed, 0, context, context_len)\n || !EVP_DigestUpdate(hashctx,\n expanded + EDDSA_448_PRIVATE_BYTES,\n EDDSA_448_PRIVATE_BYTES)\n || !EVP_DigestUpdate(hashctx, message, message_len)) {\n OPENSSL_cleanse(expanded, sizeof(expanded));\n goto err;\n }\n OPENSSL_cleanse(expanded, sizeof(expanded));\n }\n {\n uint8_t nonce[2 * EDDSA_448_PRIVATE_BYTES];\n if (!EVP_DigestFinalXOF(hashctx, nonce, sizeof(nonce)))\n goto err;\n curve448_scalar_decode_long(nonce_scalar, nonce, sizeof(nonce));\n OPENSSL_cleanse(nonce, sizeof(nonce));\n }\n {\n curve448_scalar_t nonce_scalar_2;\n curve448_point_t p;\n curve448_scalar_halve(nonce_scalar_2, nonce_scalar);\n for (c = 2; c < C448_EDDSA_ENCODE_RATIO; c <<= 1)\n curve448_scalar_halve(nonce_scalar_2, nonce_scalar_2);\n curve448_precomputed_scalarmul(p, curve448_precomputed_base,\n nonce_scalar_2);\n curve448_point_mul_by_ratio_and_encode_like_eddsa(nonce_point, p);\n curve448_point_destroy(p);\n curve448_scalar_destroy(nonce_scalar_2);\n }\n {\n uint8_t challenge[2 * EDDSA_448_PRIVATE_BYTES];\n if (!hash_init_with_dom(hashctx, prehashed, 0, context, context_len)\n || !EVP_DigestUpdate(hashctx, nonce_point, sizeof(nonce_point))\n || !EVP_DigestUpdate(hashctx, pubkey, EDDSA_448_PUBLIC_BYTES)\n || !EVP_DigestUpdate(hashctx, message, message_len)\n || !EVP_DigestFinalXOF(hashctx, challenge, sizeof(challenge)))\n goto err;\n curve448_scalar_decode_long(challenge_scalar, challenge,\n sizeof(challenge));\n OPENSSL_cleanse(challenge, sizeof(challenge));\n }\n curve448_scalar_mul(challenge_scalar, challenge_scalar, secret_scalar);\n curve448_scalar_add(challenge_scalar, challenge_scalar, nonce_scalar);\n OPENSSL_cleanse(signature, EDDSA_448_SIGNATURE_BYTES);\n memcpy(signature, nonce_point, sizeof(nonce_point));\n curve448_scalar_encode(&signature[EDDSA_448_PUBLIC_BYTES],\n challenge_scalar);\n curve448_scalar_destroy(secret_scalar);\n curve448_scalar_destroy(nonce_scalar);\n curve448_scalar_destroy(challenge_scalar);\n ret = C448_SUCCESS;\n err:\n EVP_MD_CTX_free(hashctx);\n return ret;\n}', 'static c448_error_t oneshot_hash(uint8_t *out, size_t outlen,\n const uint8_t *in, size_t inlen)\n{\n EVP_MD_CTX *hashctx = EVP_MD_CTX_new();\n if (hashctx == NULL)\n return C448_FAILURE;\n if (!EVP_DigestInit_ex(hashctx, EVP_shake256(), NULL)\n || !EVP_DigestUpdate(hashctx, in, inlen)\n || !EVP_DigestFinalXOF(hashctx, out, outlen)) {\n EVP_MD_CTX_free(hashctx);\n return C448_FAILURE;\n }\n EVP_MD_CTX_free(hashctx);\n return C448_SUCCESS;\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}', 'int test_true(const char *file, int line, const char *s, int b)\n{\n if (b)\n return 1;\n test_fail_message(NULL, file, line, "bool", s, "true", "==", "false");\n return 0;\n}']
2,547
0
https://github.com/openssl/openssl/blob/09977dd095f3c655c99b9e1810a213f7eafa7364/crypto/bn/bn_lib.c/#L342
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *A, *a = NULL; const BN_ULONG *B; int i; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b,BN_FLG_SECURE)) a = A = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = A = OPENSSL_zalloc(words * sizeof(*a)); if (A == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } #if 1 B = b->d; if (B != NULL) { for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) { BN_ULONG a0, a1, a2, a3; a0 = B[0]; a1 = B[1]; a2 = B[2]; a3 = B[3]; A[0] = a0; A[1] = a1; A[2] = a2; A[3] = a3; } switch (b->top & 3) { case 3: A[2] = B[2]; case 2: A[1] = B[1]; case 1: A[0] = B[0]; case 0: ; } } #else memset(A, 0, sizeof(*A) * words); memcpy(A, b->d, sizeof(b->d[0]) * b->top); #endif return (a); }
['BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n BIGNUM *ret = in;\n int err = 1;\n int r;\n BIGNUM *A, *b, *q, *t, *x, *y;\n int e, i, j;\n if (!BN_is_odd(p) || BN_abs_is_word(p, 1)) {\n if (BN_abs_is_word(p, 2)) {\n if (ret == NULL)\n ret = BN_new();\n if (ret == NULL)\n goto end;\n if (!BN_set_word(ret, BN_is_bit_set(a, 0))) {\n if (ret != in)\n BN_free(ret);\n return NULL;\n }\n bn_check_top(ret);\n return ret;\n }\n BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n return (NULL);\n }\n if (BN_is_zero(a) || BN_is_one(a)) {\n if (ret == NULL)\n ret = BN_new();\n if (ret == NULL)\n goto end;\n if (!BN_set_word(ret, BN_is_one(a))) {\n if (ret != in)\n BN_free(ret);\n return NULL;\n }\n bn_check_top(ret);\n return ret;\n }\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n q = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto end;\n if (ret == NULL)\n ret = BN_new();\n if (ret == NULL)\n goto end;\n if (!BN_nnmod(A, a, p, ctx))\n goto end;\n e = 1;\n while (!BN_is_bit_set(p, e))\n e++;\n if (e == 1) {\n if (!BN_rshift(q, p, 2))\n goto end;\n q->neg = 0;\n if (!BN_add_word(q, 1))\n goto end;\n if (!BN_mod_exp(ret, A, q, p, ctx))\n goto end;\n err = 0;\n goto vrfy;\n }\n if (e == 2) {\n if (!BN_mod_lshift1_quick(t, A, p))\n goto end;\n if (!BN_rshift(q, p, 3))\n goto end;\n q->neg = 0;\n if (!BN_mod_exp(b, t, q, p, ctx))\n goto end;\n if (!BN_mod_sqr(y, b, p, ctx))\n goto end;\n if (!BN_mod_mul(t, t, y, p, ctx))\n goto end;\n if (!BN_sub_word(t, 1))\n goto end;\n if (!BN_mod_mul(x, A, b, p, ctx))\n goto end;\n if (!BN_mod_mul(x, x, t, p, ctx))\n goto end;\n if (!BN_copy(ret, x))\n goto end;\n err = 0;\n goto vrfy;\n }\n if (!BN_copy(q, p))\n goto end;\n q->neg = 0;\n i = 2;\n do {\n if (i < 22) {\n if (!BN_set_word(y, i))\n goto end;\n } else {\n if (!BN_pseudo_rand(y, BN_num_bits(p), 0, 0))\n goto end;\n if (BN_ucmp(y, p) >= 0) {\n if (!(p->neg ? BN_add : BN_sub) (y, y, p))\n goto end;\n }\n if (BN_is_zero(y))\n if (!BN_set_word(y, i))\n goto end;\n }\n r = BN_kronecker(y, q, ctx);\n if (r < -1)\n goto end;\n if (r == 0) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n goto end;\n }\n }\n while (r == 1 && ++i < 82);\n if (r != -1) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_TOO_MANY_ITERATIONS);\n goto end;\n }\n if (!BN_rshift(q, q, e))\n goto end;\n if (!BN_mod_exp(y, y, q, p, ctx))\n goto end;\n if (BN_is_one(y)) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n goto end;\n }\n if (!BN_rshift1(t, q))\n goto end;\n if (BN_is_zero(t)) {\n if (!BN_nnmod(t, A, p, ctx))\n goto end;\n if (BN_is_zero(t)) {\n BN_zero(ret);\n err = 0;\n goto end;\n } else if (!BN_one(x))\n goto end;\n } else {\n if (!BN_mod_exp(x, A, t, p, ctx))\n goto end;\n if (BN_is_zero(x)) {\n BN_zero(ret);\n err = 0;\n goto end;\n }\n }\n if (!BN_mod_sqr(b, x, p, ctx))\n goto end;\n if (!BN_mod_mul(b, b, A, p, ctx))\n goto end;\n if (!BN_mod_mul(x, x, A, p, ctx))\n goto end;\n while (1) {\n if (BN_is_one(b)) {\n if (!BN_copy(ret, x))\n goto end;\n err = 0;\n goto vrfy;\n }\n i = 1;\n if (!BN_mod_sqr(t, b, p, ctx))\n goto end;\n while (!BN_is_one(t)) {\n i++;\n if (i == e) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);\n goto end;\n }\n if (!BN_mod_mul(t, t, t, p, ctx))\n goto end;\n }\n if (!BN_copy(t, y))\n goto end;\n for (j = e - i - 1; j > 0; j--) {\n if (!BN_mod_sqr(t, t, p, ctx))\n goto end;\n }\n if (!BN_mod_mul(y, t, t, p, ctx))\n goto end;\n if (!BN_mod_mul(x, x, t, p, ctx))\n goto end;\n if (!BN_mod_mul(b, b, y, p, ctx))\n goto end;\n e = i;\n }\n vrfy:\n if (!err) {\n if (!BN_mod_sqr(x, ret, p, ctx))\n err = 1;\n if (!err && 0 != BN_cmp(x, A)) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);\n err = 1;\n }\n }\n end:\n if (err) {\n if (ret != in)\n BN_clear_free(ret);\n ret = NULL;\n }\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if(((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, j, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l, tmp;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_RSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n rb = n % BN_BITS2;\n lb = BN_BITS2 - rb;\n if (nw >= a->top || a->top == 0) {\n BN_zero(r);\n return (1);\n }\n i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;\n if (r != a) {\n r->neg = a->neg;\n if (bn_wexpand(r, i) == NULL)\n return (0);\n } else {\n if (n == 0)\n return 1;\n }\n f = &(a->d[nw]);\n t = r->d;\n j = a->top - nw;\n r->top = i;\n if (rb == 0) {\n for (i = j; i != 0; i--)\n *(t++) = *(f++);\n } else {\n l = *(f++);\n for (i = j - 1; i != 0; i--) {\n tmp = (l >> rb) & BN_MASK2;\n l = *(f++);\n *(t++) = (tmp | (l << lb)) & BN_MASK2;\n }\n if ((l = (l >> rb) & BN_MASK2))\n *(t) = l;\n }\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *A, *a = NULL;\n const BN_ULONG *B;\n int i;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b,BN_FLG_SECURE))\n a = A = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = A = OPENSSL_zalloc(words * sizeof(*a));\n if (A == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n#if 1\n B = b->d;\n if (B != NULL) {\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:\n ;\n }\n }\n#else\n memset(A, 0, sizeof(*A) * words);\n memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n return (a);\n}']
2,548
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavformat/mpegtsenc.c/#L600
static void mpegts_write_pes(AVFormatContext *s, AVStream *st, const uint8_t *payload, int payload_size, int64_t pts, int64_t dts) { MpegTSWriteStream *ts_st = st->priv_data; uint8_t buf[TS_PACKET_SIZE]; uint8_t *q; int val, is_start, len, header_len, write_pcr, private_code, flags; int afc_len, stuffing_len; int64_t pcr = -1; is_start = 1; while (payload_size > 0) { retransmit_si_info(s); write_pcr = 0; if (ts_st->pid == ts_st->service->pcr_pid) { ts_st->service->pcr_packet_count++; if (ts_st->service->pcr_packet_count >= ts_st->service->pcr_packet_freq) { ts_st->service->pcr_packet_count = 0; write_pcr = 1; pcr = pts; } } q = buf; *q++ = 0x47; val = (ts_st->pid >> 8); if (is_start) val |= 0x40; *q++ = val; *q++ = ts_st->pid; *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0); ts_st->cc = (ts_st->cc + 1) & 0xf; if (write_pcr) { *q++ = 7; *q++ = 0x10; *q++ = pcr >> 25; *q++ = pcr >> 17; *q++ = pcr >> 9; *q++ = pcr >> 1; *q++ = (pcr & 1) << 7; *q++ = 0; } if (is_start) { *q++ = 0x00; *q++ = 0x00; *q++ = 0x01; private_code = 0; if (st->codec->codec_type == CODEC_TYPE_VIDEO) { *q++ = 0xe0; } else if (st->codec->codec_type == CODEC_TYPE_AUDIO && (st->codec->codec_id == CODEC_ID_MP2 || st->codec->codec_id == CODEC_ID_MP3)) { *q++ = 0xc0; } else { *q++ = 0xbd; if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) { private_code = 0x20; } } header_len = 0; flags = 0; if (pts != AV_NOPTS_VALUE) { header_len += 5; flags |= 0x80; } if (dts != AV_NOPTS_VALUE) { header_len += 5; flags |= 0x40; } len = payload_size + header_len + 3; if (private_code != 0) len++; *q++ = len >> 8; *q++ = len; val = 0x80; if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) val |= 0x04; *q++ = val; *q++ = flags; *q++ = header_len; if (pts != AV_NOPTS_VALUE) { write_pts(q, flags >> 6, pts); q += 5; } if (dts != AV_NOPTS_VALUE) { write_pts(q, 1, dts); q += 5; } if (private_code != 0) *q++ = private_code; is_start = 0; } header_len = q - buf; len = TS_PACKET_SIZE - header_len; if (len > payload_size) len = payload_size; stuffing_len = TS_PACKET_SIZE - header_len - len; if (stuffing_len > 0) { if (buf[3] & 0x20) { afc_len = buf[4] + 1; memmove(buf + 4 + afc_len + stuffing_len, buf + 4 + afc_len, header_len - (4 + afc_len)); buf[4] += stuffing_len; memset(buf + 4 + afc_len, 0xff, stuffing_len); } else { memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4); buf[3] |= 0x20; buf[4] = stuffing_len - 1; if (stuffing_len >= 2) { buf[5] = 0x00; memset(buf + 6, 0xff, stuffing_len - 2); } } } memcpy(buf + TS_PACKET_SIZE - len, payload, len); payload += len; payload_size -= len; put_buffer(s->pb, buf, TS_PACKET_SIZE); } put_flush_packet(s->pb); }
['static void mpegts_write_pes(AVFormatContext *s, AVStream *st,\n const uint8_t *payload, int payload_size,\n int64_t pts, int64_t dts)\n{\n MpegTSWriteStream *ts_st = st->priv_data;\n uint8_t buf[TS_PACKET_SIZE];\n uint8_t *q;\n int val, is_start, len, header_len, write_pcr, private_code, flags;\n int afc_len, stuffing_len;\n int64_t pcr = -1;\n is_start = 1;\n while (payload_size > 0) {\n retransmit_si_info(s);\n write_pcr = 0;\n if (ts_st->pid == ts_st->service->pcr_pid) {\n ts_st->service->pcr_packet_count++;\n if (ts_st->service->pcr_packet_count >=\n ts_st->service->pcr_packet_freq) {\n ts_st->service->pcr_packet_count = 0;\n write_pcr = 1;\n pcr = pts;\n }\n }\n q = buf;\n *q++ = 0x47;\n val = (ts_st->pid >> 8);\n if (is_start)\n val |= 0x40;\n *q++ = val;\n *q++ = ts_st->pid;\n *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0);\n ts_st->cc = (ts_st->cc + 1) & 0xf;\n if (write_pcr) {\n *q++ = 7;\n *q++ = 0x10;\n *q++ = pcr >> 25;\n *q++ = pcr >> 17;\n *q++ = pcr >> 9;\n *q++ = pcr >> 1;\n *q++ = (pcr & 1) << 7;\n *q++ = 0;\n }\n if (is_start) {\n *q++ = 0x00;\n *q++ = 0x00;\n *q++ = 0x01;\n private_code = 0;\n if (st->codec->codec_type == CODEC_TYPE_VIDEO) {\n *q++ = 0xe0;\n } else if (st->codec->codec_type == CODEC_TYPE_AUDIO &&\n (st->codec->codec_id == CODEC_ID_MP2 ||\n st->codec->codec_id == CODEC_ID_MP3)) {\n *q++ = 0xc0;\n } else {\n *q++ = 0xbd;\n if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) {\n private_code = 0x20;\n }\n }\n header_len = 0;\n flags = 0;\n if (pts != AV_NOPTS_VALUE) {\n header_len += 5;\n flags |= 0x80;\n }\n if (dts != AV_NOPTS_VALUE) {\n header_len += 5;\n flags |= 0x40;\n }\n len = payload_size + header_len + 3;\n if (private_code != 0)\n len++;\n *q++ = len >> 8;\n *q++ = len;\n val = 0x80;\n if (st->codec->codec_type == CODEC_TYPE_SUBTITLE)\n val |= 0x04;\n *q++ = val;\n *q++ = flags;\n *q++ = header_len;\n if (pts != AV_NOPTS_VALUE) {\n write_pts(q, flags >> 6, pts);\n q += 5;\n }\n if (dts != AV_NOPTS_VALUE) {\n write_pts(q, 1, dts);\n q += 5;\n }\n if (private_code != 0)\n *q++ = private_code;\n is_start = 0;\n }\n header_len = q - buf;\n len = TS_PACKET_SIZE - header_len;\n if (len > payload_size)\n len = payload_size;\n stuffing_len = TS_PACKET_SIZE - header_len - len;\n if (stuffing_len > 0) {\n if (buf[3] & 0x20) {\n afc_len = buf[4] + 1;\n memmove(buf + 4 + afc_len + stuffing_len,\n buf + 4 + afc_len,\n header_len - (4 + afc_len));\n buf[4] += stuffing_len;\n memset(buf + 4 + afc_len, 0xff, stuffing_len);\n } else {\n memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4);\n buf[3] |= 0x20;\n buf[4] = stuffing_len - 1;\n if (stuffing_len >= 2) {\n buf[5] = 0x00;\n memset(buf + 6, 0xff, stuffing_len - 2);\n }\n }\n }\n memcpy(buf + TS_PACKET_SIZE - len, payload, len);\n payload += len;\n payload_size -= len;\n put_buffer(s->pb, buf, TS_PACKET_SIZE);\n }\n put_flush_packet(s->pb);\n}']
2,549
1
https://github.com/libav/libav/blob/63e8d9760f23a4edf81e9ae58c4f6d3baa6ff4dd/libavcodec/dct32.c/#L240
static void dct32(INTFLOAT *out, const INTFLOAT *tab) { INTFLOAT tmp0, tmp1; INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 , val8 , val9 , val10, val11, val12, val13, val14, val15, val16, val17, val18, val19, val20, val21, val22, val23, val24, val25, val26, val27, val28, val29, val30, val31; BF0( 0, 31, COS0_0 , 1); BF0(15, 16, COS0_15, 5); BF( 0, 15, COS1_0 , 1); BF(16, 31,-COS1_0 , 1); BF0( 7, 24, COS0_7 , 1); BF0( 8, 23, COS0_8 , 1); BF( 7, 8, COS1_7 , 4); BF(23, 24,-COS1_7 , 4); BF( 0, 7, COS2_0 , 1); BF( 8, 15,-COS2_0 , 1); BF(16, 23, COS2_0 , 1); BF(24, 31,-COS2_0 , 1); BF0( 3, 28, COS0_3 , 1); BF0(12, 19, COS0_12, 2); BF( 3, 12, COS1_3 , 1); BF(19, 28,-COS1_3 , 1); BF0( 4, 27, COS0_4 , 1); BF0(11, 20, COS0_11, 2); BF( 4, 11, COS1_4 , 1); BF(20, 27,-COS1_4 , 1); BF( 3, 4, COS2_3 , 3); BF(11, 12,-COS2_3 , 3); BF(19, 20, COS2_3 , 3); BF(27, 28,-COS2_3 , 3); BF( 0, 3, COS3_0 , 1); BF( 4, 7,-COS3_0 , 1); BF( 8, 11, COS3_0 , 1); BF(12, 15,-COS3_0 , 1); BF(16, 19, COS3_0 , 1); BF(20, 23,-COS3_0 , 1); BF(24, 27, COS3_0 , 1); BF(28, 31,-COS3_0 , 1); BF0( 1, 30, COS0_1 , 1); BF0(14, 17, COS0_14, 3); BF( 1, 14, COS1_1 , 1); BF(17, 30,-COS1_1 , 1); BF0( 6, 25, COS0_6 , 1); BF0( 9, 22, COS0_9 , 1); BF( 6, 9, COS1_6 , 2); BF(22, 25,-COS1_6 , 2); BF( 1, 6, COS2_1 , 1); BF( 9, 14,-COS2_1 , 1); BF(17, 22, COS2_1 , 1); BF(25, 30,-COS2_1 , 1); BF0( 2, 29, COS0_2 , 1); BF0(13, 18, COS0_13, 3); BF( 2, 13, COS1_2 , 1); BF(18, 29,-COS1_2 , 1); BF0( 5, 26, COS0_5 , 1); BF0(10, 21, COS0_10, 1); BF( 5, 10, COS1_5 , 2); BF(21, 26,-COS1_5 , 2); BF( 2, 5, COS2_2 , 1); BF(10, 13,-COS2_2 , 1); BF(18, 21, COS2_2 , 1); BF(26, 29,-COS2_2 , 1); BF( 1, 2, COS3_1 , 2); BF( 5, 6,-COS3_1 , 2); BF( 9, 10, COS3_1 , 2); BF(13, 14,-COS3_1 , 2); BF(17, 18, COS3_1 , 2); BF(21, 22,-COS3_1 , 2); BF(25, 26, COS3_1 , 2); BF(29, 30,-COS3_1 , 2); BF1( 0, 1, 2, 3); BF2( 4, 5, 6, 7); BF1( 8, 9, 10, 11); BF2(12, 13, 14, 15); BF1(16, 17, 18, 19); BF2(20, 21, 22, 23); BF1(24, 25, 26, 27); BF2(28, 29, 30, 31); ADD( 8, 12); ADD(12, 10); ADD(10, 14); ADD(14, 9); ADD( 9, 13); ADD(13, 11); ADD(11, 15); out[ 0] = val0; out[16] = val1; out[ 8] = val2; out[24] = val3; out[ 4] = val4; out[20] = val5; out[12] = val6; out[28] = val7; out[ 2] = val8; out[18] = val9; out[10] = val10; out[26] = val11; out[ 6] = val12; out[22] = val13; out[14] = val14; out[30] = val15; ADD(24, 28); ADD(28, 26); ADD(26, 30); ADD(30, 25); ADD(25, 29); ADD(29, 27); ADD(27, 31); out[ 1] = val16 + val24; out[17] = val17 + val25; out[ 9] = val18 + val26; out[25] = val19 + val27; out[ 5] = val20 + val28; out[21] = val21 + val29; out[13] = val22 + val30; out[29] = val23 + val31; out[ 3] = val24 + val20; out[19] = val25 + val21; out[11] = val26 + val22; out[27] = val27 + val23; out[ 7] = val28 + val18; out[23] = val29 + val19; out[15] = val30 + val17; out[31] = val31; }
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n int offset;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n int j;\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 apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}', 'static void dct32(INTFLOAT *out, const INTFLOAT *tab)\n{\n INTFLOAT tmp0, tmp1;\n INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 ,\n val8 , val9 , val10, val11, val12, val13, val14, val15,\n val16, val17, val18, val19, val20, val21, val22, val23,\n val24, val25, val26, val27, val28, val29, val30, val31;\n BF0( 0, 31, COS0_0 , 1);\n BF0(15, 16, COS0_15, 5);\n BF( 0, 15, COS1_0 , 1);\n BF(16, 31,-COS1_0 , 1);\n BF0( 7, 24, COS0_7 , 1);\n BF0( 8, 23, COS0_8 , 1);\n BF( 7, 8, COS1_7 , 4);\n BF(23, 24,-COS1_7 , 4);\n BF( 0, 7, COS2_0 , 1);\n BF( 8, 15,-COS2_0 , 1);\n BF(16, 23, COS2_0 , 1);\n BF(24, 31,-COS2_0 , 1);\n BF0( 3, 28, COS0_3 , 1);\n BF0(12, 19, COS0_12, 2);\n BF( 3, 12, COS1_3 , 1);\n BF(19, 28,-COS1_3 , 1);\n BF0( 4, 27, COS0_4 , 1);\n BF0(11, 20, COS0_11, 2);\n BF( 4, 11, COS1_4 , 1);\n BF(20, 27,-COS1_4 , 1);\n BF( 3, 4, COS2_3 , 3);\n BF(11, 12,-COS2_3 , 3);\n BF(19, 20, COS2_3 , 3);\n BF(27, 28,-COS2_3 , 3);\n BF( 0, 3, COS3_0 , 1);\n BF( 4, 7,-COS3_0 , 1);\n BF( 8, 11, COS3_0 , 1);\n BF(12, 15,-COS3_0 , 1);\n BF(16, 19, COS3_0 , 1);\n BF(20, 23,-COS3_0 , 1);\n BF(24, 27, COS3_0 , 1);\n BF(28, 31,-COS3_0 , 1);\n BF0( 1, 30, COS0_1 , 1);\n BF0(14, 17, COS0_14, 3);\n BF( 1, 14, COS1_1 , 1);\n BF(17, 30,-COS1_1 , 1);\n BF0( 6, 25, COS0_6 , 1);\n BF0( 9, 22, COS0_9 , 1);\n BF( 6, 9, COS1_6 , 2);\n BF(22, 25,-COS1_6 , 2);\n BF( 1, 6, COS2_1 , 1);\n BF( 9, 14,-COS2_1 , 1);\n BF(17, 22, COS2_1 , 1);\n BF(25, 30,-COS2_1 , 1);\n BF0( 2, 29, COS0_2 , 1);\n BF0(13, 18, COS0_13, 3);\n BF( 2, 13, COS1_2 , 1);\n BF(18, 29,-COS1_2 , 1);\n BF0( 5, 26, COS0_5 , 1);\n BF0(10, 21, COS0_10, 1);\n BF( 5, 10, COS1_5 , 2);\n BF(21, 26,-COS1_5 , 2);\n BF( 2, 5, COS2_2 , 1);\n BF(10, 13,-COS2_2 , 1);\n BF(18, 21, COS2_2 , 1);\n BF(26, 29,-COS2_2 , 1);\n BF( 1, 2, COS3_1 , 2);\n BF( 5, 6,-COS3_1 , 2);\n BF( 9, 10, COS3_1 , 2);\n BF(13, 14,-COS3_1 , 2);\n BF(17, 18, COS3_1 , 2);\n BF(21, 22,-COS3_1 , 2);\n BF(25, 26, COS3_1 , 2);\n BF(29, 30,-COS3_1 , 2);\n BF1( 0, 1, 2, 3);\n BF2( 4, 5, 6, 7);\n BF1( 8, 9, 10, 11);\n BF2(12, 13, 14, 15);\n BF1(16, 17, 18, 19);\n BF2(20, 21, 22, 23);\n BF1(24, 25, 26, 27);\n BF2(28, 29, 30, 31);\n ADD( 8, 12);\n ADD(12, 10);\n ADD(10, 14);\n ADD(14, 9);\n ADD( 9, 13);\n ADD(13, 11);\n ADD(11, 15);\n out[ 0] = val0;\n out[16] = val1;\n out[ 8] = val2;\n out[24] = val3;\n out[ 4] = val4;\n out[20] = val5;\n out[12] = val6;\n out[28] = val7;\n out[ 2] = val8;\n out[18] = val9;\n out[10] = val10;\n out[26] = val11;\n out[ 6] = val12;\n out[22] = val13;\n out[14] = val14;\n out[30] = val15;\n ADD(24, 28);\n ADD(28, 26);\n ADD(26, 30);\n ADD(30, 25);\n ADD(25, 29);\n ADD(29, 27);\n ADD(27, 31);\n out[ 1] = val16 + val24;\n out[17] = val17 + val25;\n out[ 9] = val18 + val26;\n out[25] = val19 + val27;\n out[ 5] = val20 + val28;\n out[21] = val21 + val29;\n out[13] = val22 + val30;\n out[29] = val23 + val31;\n out[ 3] = val24 + val20;\n out[19] = val25 + val21;\n out[11] = val26 + val22;\n out[27] = val27 + val23;\n out[ 7] = val28 + val18;\n out[23] = val29 + val19;\n out[15] = val30 + val17;\n out[31] = val31;\n}']
2,550
0
https://github.com/openssl/openssl/blob/fa9bb6201e1d16ba8ccab938833d140ef81a7f73/crypto/lhash/lhash.c/#L313
static void expand(_LHASH *lh) { LHASH_NODE **n, **n1, **n2, *np; unsigned int p, i, j; unsigned long hash, nni; lh->num_nodes++; lh->num_expands++; p = (int)lh->p++; n1 = &(lh->b[p]); n2 = &(lh->b[p + (int)lh->pmax]); *n2 = NULL; nni = lh->num_alloc_nodes; for (np = *n1; np != NULL;) { hash = np->hash; if ((hash % nni) != p) { *n1 = (*n1)->next; np->next = *n2; *n2 = np; } else n1 = &((*n1)->next); np = *n1; } if ((lh->p) >= lh->pmax) { j = (int)lh->num_alloc_nodes * 2; n = OPENSSL_realloc(lh->b, (int)(sizeof(LHASH_NODE *) * j)); if (n == NULL) { lh->error++; lh->p = 0; return; } for (i = (int)lh->num_alloc_nodes; i < j; i++) n[i] = NULL; lh->pmax = lh->num_alloc_nodes; lh->num_alloc_nodes = j; lh->num_expand_reallocs++; lh->p = 0; lh->b = n; } }
['static ERR_STATE *int_thread_set_item(ERR_STATE *d)\n{\n ERR_STATE *p = NULL;\n LHASH_OF(ERR_STATE) *hash;\n CRYPTO_w_lock(CRYPTO_LOCK_ERR);\n hash = int_thread_get(1, 0);\n if (hash)\n p = lh_ERR_STATE_insert(hash, d);\n CRYPTO_w_unlock(CRYPTO_LOCK_ERR);\n int_thread_release(&hash);\n return p;\n}', 'static LHASH_OF(ERR_STATE) *int_thread_get(int create, int lockit)\n{\n LHASH_OF(ERR_STATE) *ret = NULL;\n if (lockit)\n CRYPTO_w_lock(CRYPTO_LOCK_ERR);\n if (!int_thread_hash && create) {\n int_thread_hash = lh_ERR_STATE_new(err_state_hash, err_state_cmp);\n }\n if (int_thread_hash != NULL) {\n refcount.references++;\n ret = int_thread_hash;\n }\n if (lockit)\n CRYPTO_w_unlock(CRYPTO_LOCK_ERR);\n return ret;\n}', 'DEFINE_LHASH_OF(ERR_STATE)', '_LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)\n{\n _LHASH *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)\n goto err0;\n if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL)\n goto err1;\n ret->comp = ((c == NULL) ? (LHASH_COMP_FN_TYPE)strcmp : c);\n ret->hash = ((h == NULL) ? (LHASH_HASH_FN_TYPE)lh_strhash : h);\n ret->num_nodes = MIN_NODES / 2;\n ret->num_alloc_nodes = MIN_NODES;\n ret->pmax = MIN_NODES / 2;\n ret->up_load = UP_LOAD;\n ret->down_load = DOWN_LOAD;\n return (ret);\n err1:\n OPENSSL_free(ret);\n err0:\n return (NULL);\n}', 'void *lh_insert(_LHASH *lh, void *data)\n{\n unsigned long hash;\n LHASH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n if (lh->up_load <= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))\n expand(lh);\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n if ((nn = OPENSSL_malloc(sizeof(*nn))) == NULL) {\n lh->error++;\n return (NULL);\n }\n nn->data = data;\n nn->next = NULL;\n nn->hash = hash;\n *rn = nn;\n ret = NULL;\n lh->num_insert++;\n lh->num_items++;\n } else {\n ret = (*rn)->data;\n (*rn)->data = data;\n lh->num_replace++;\n }\n return (ret);\n}', 'static void expand(_LHASH *lh)\n{\n LHASH_NODE **n, **n1, **n2, *np;\n unsigned int p, i, j;\n unsigned long hash, nni;\n lh->num_nodes++;\n lh->num_expands++;\n p = (int)lh->p++;\n n1 = &(lh->b[p]);\n n2 = &(lh->b[p + (int)lh->pmax]);\n *n2 = NULL;\n nni = lh->num_alloc_nodes;\n for (np = *n1; np != NULL;) {\n hash = np->hash;\n if ((hash % nni) != p) {\n *n1 = (*n1)->next;\n np->next = *n2;\n *n2 = np;\n } else\n n1 = &((*n1)->next);\n np = *n1;\n }\n if ((lh->p) >= lh->pmax) {\n j = (int)lh->num_alloc_nodes * 2;\n n = OPENSSL_realloc(lh->b, (int)(sizeof(LHASH_NODE *) * j));\n if (n == NULL) {\n lh->error++;\n lh->p = 0;\n return;\n }\n for (i = (int)lh->num_alloc_nodes; i < j; i++)\n n[i] = NULL;\n lh->pmax = lh->num_alloc_nodes;\n lh->num_alloc_nodes = j;\n lh->num_expand_reallocs++;\n lh->p = 0;\n lh->b = n;\n }\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (realloc_impl != NULL && realloc_impl != &CRYPTO_realloc)\n return realloc_impl(str, num, file, line);\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str, file, line);\n return NULL;\n }\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)file;\n (void)line;\n#endif\n return realloc(str, num);\n}']
2,551
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/asn1/asn1_lib.c/#L240
int ASN1_object_size(int constructed, int length, int tag) { int ret = 1; if (length < 0) return -1; if (tag >= 31) { while (tag > 0) { tag >>= 7; ret++; } } if (constructed == 2) { ret += 3; } else { ret++; if (length > 127) { int tmplen = length; while (tmplen > 0) { tmplen >>= 8; ret++; } } } if (ret >= INT_MAX - length) return -1; return ret + length; }
['int DSA_size(const DSA *r)\n{\n int ret, i;\n ASN1_INTEGER bs;\n unsigned char buf[4];\n i = BN_num_bits(r->q);\n bs.length = (i + 7) / 8;\n bs.data = buf;\n bs.type = V_ASN1_INTEGER;\n buf[0] = 0xff;\n i = i2d_ASN1_INTEGER(&bs, NULL);\n i += i;\n ret = ASN1_object_size(1, i, V_ASN1_SEQUENCE);\n return ret;\n}', 'IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)', 'int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)\n{\n return asn1_item_flags_i2d(val, out, it, 0);\n}', 'static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,\n const ASN1_ITEM *it, int flags)\n{\n if (out && !*out) {\n unsigned char *p, *buf;\n int len;\n len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);\n if (len <= 0)\n return len;\n buf = OPENSSL_malloc(len);\n if (buf == NULL)\n return -1;\n p = buf;\n ASN1_item_ex_i2d(&val, &p, it, -1, flags);\n *out = buf;\n return len;\n }\n return ASN1_item_ex_i2d(&val, out, it, -1, flags);\n}', 'int ASN1_object_size(int constructed, int length, int tag)\n{\n int ret = 1;\n if (length < 0)\n return -1;\n if (tag >= 31) {\n while (tag > 0) {\n tag >>= 7;\n ret++;\n }\n }\n if (constructed == 2) {\n ret += 3;\n } else {\n ret++;\n if (length > 127) {\n int tmplen = length;\n while (tmplen > 0) {\n tmplen >>= 8;\n ret++;\n }\n }\n }\n if (ret >= INT_MAX - length)\n return -1;\n return ret + length;\n}']
2,552
0
https://github.com/openssl/openssl/blob/5f97f508e450af9d53e3a01b59b13e9e7b540720/crypto/lhash/lhash.c/#L356
static void contract(LHASH *lh) { LHASH_NODE **n,*n1,*np; np=lh->b[lh->p+lh->pmax-1]; lh->b[lh->p+lh->pmax-1]=NULL; if (lh->p == 0) { n=(LHASH_NODE **)OPENSSL_realloc(lh->b, (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); if (n == NULL) { lh->error++; return; } lh->num_contract_reallocs++; lh->num_alloc_nodes/=2; lh->pmax/=2; lh->p=lh->pmax-1; lh->b=n; } else lh->p--; lh->num_nodes--; lh->num_contracts++; n1=lh->b[(int)lh->p]; if (n1 == NULL) lh->b[(int)lh->p]=np; else { while (n1->next != NULL) n1=n1->next; n1->next=np; } }
['static int sv_body(char *hostname, int s, unsigned char *context)\n\t{\n\tchar *buf=NULL;\n\tfd_set readfds;\n\tint ret=1,width;\n\tint k,i;\n\tunsigned long l;\n\tSSL *con=NULL;\n\tBIO *sbio;\n#ifdef WINDOWS\n\tstruct timeval tv;\n#endif\n\tif ((buf=OPENSSL_malloc(bufsize)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto err;\n\t\t}\n#ifdef FIONBIO\n\tif (s_nbio)\n\t\t{\n\t\tunsigned long sl=1;\n\t\tif (!s_quiet)\n\t\t\tBIO_printf(bio_err,"turning on non blocking io\\n");\n\t\tif (BIO_socket_ioctl(s,FIONBIO,&sl) < 0)\n\t\t\tERR_print_errors(bio_err);\n\t\t}\n#endif\n\tif (con == NULL) {\n\t\tcon=SSL_new(ctx);\n\t\tif(context)\n\t\t SSL_set_session_id_context(con, context,\n\t\t\t\t\t\t strlen((char *)context));\n\t}\n\tSSL_clear(con);\n\tsbio=BIO_new_socket(s,BIO_NOCLOSE);\n\tif (s_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\tSSL_set_bio(con,sbio,sbio);\n\tSSL_set_accept_state(con);\n\tif (s_debug)\n\t\t{\n\t\tcon->debug=1;\n\t\tBIO_set_callback(SSL_get_rbio(con),bio_dump_cb);\n\t\tBIO_set_callback_arg(SSL_get_rbio(con),bio_s_out);\n\t\t}\n\twidth=s+1;\n\tfor (;;)\n\t\t{\n\t\tint read_from_terminal;\n\t\tint read_from_sslcon;\n\t\tread_from_terminal = 0;\n\t\tread_from_sslcon = SSL_pending(con);\n\t\tif (!read_from_sslcon)\n\t\t\t{\n\t\t\tFD_ZERO(&readfds);\n#ifndef WINDOWS\n\t\t\tFD_SET(fileno(stdin),&readfds);\n#endif\n\t\t\tFD_SET(s,&readfds);\n#ifdef WINDOWS\n\t\t\ttv.tv_sec = 1;\n\t\t\ttv.tv_usec = 0;\n\t\t\ti=select(width,(void *)&readfds,NULL,NULL,&tv);\n\t\t\tif((i < 0) || (!i && !_kbhit() ) )continue;\n\t\t\tif(_kbhit())\n\t\t\t\tread_from_terminal = 1;\n#else\n\t\t\ti=select(width,(void *)&readfds,NULL,NULL,NULL);\n\t\t\tif (i <= 0) continue;\n\t\t\tif (FD_ISSET(fileno(stdin),&readfds))\n\t\t\t\tread_from_terminal = 1;\n#endif\n\t\t\tif (FD_ISSET(s,&readfds))\n\t\t\t\tread_from_sslcon = 1;\n\t\t\t}\n\t\tif (read_from_terminal)\n\t\t\t{\n\t\t\tif (s_crlf)\n\t\t\t\t{\n\t\t\t\tint j, lf_num;\n\t\t\t\ti=read(fileno(stdin), buf, bufsize/2);\n\t\t\t\tlf_num = 0;\n\t\t\t\tfor (j = 0; j < i; j++)\n\t\t\t\t\tif (buf[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\tbuf[j+lf_num] = buf[j];\n\t\t\t\t\tif (buf[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\tbuf[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),buf,bufsize);\n\t\t\tif (!s_quiet)\n\t\t\t\t{\n\t\t\t\tif ((i <= 0) || (buf[0] == \'Q\'))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tSHUTDOWN(s);\n\t\t\t\t\tclose_accept_socket();\n\t\t\t\t\tret= -11;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tif ((i <= 0) || (buf[0] == \'q\'))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tSHUTDOWN(s);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tif ((buf[0] == \'r\') &&\n\t\t\t\t\t((buf[1] == \'\\n\') || (buf[1] == \'\\r\')))\n\t\t\t\t\t{\n\t\t\t\t\tSSL_renegotiate(con);\n\t\t\t\t\ti=SSL_do_handshake(con);\n\t\t\t\t\tprintf("SSL_do_handshake -> %d\\n",i);\n\t\t\t\t\ti=0;\n\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\tif ((buf[0] == \'R\') &&\n\t\t\t\t\t((buf[1] == \'\\n\') || (buf[1] == \'\\r\')))\n\t\t\t\t\t{\n\t\t\t\t\tSSL_set_verify(con,\n\t\t\t\t\t\tSSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,NULL);\n\t\t\t\t\tSSL_renegotiate(con);\n\t\t\t\t\ti=SSL_do_handshake(con);\n\t\t\t\t\tprintf("SSL_do_handshake -> %d\\n",i);\n\t\t\t\t\ti=0;\n\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\tif (buf[0] == \'P\')\n\t\t\t\t\t{\n\t\t\t\t\tstatic char *str="Lets print some clear text\\n";\n\t\t\t\t\tBIO_write(SSL_get_wbio(con),str,strlen(str));\n\t\t\t\t\t}\n\t\t\t\tif (buf[0] == \'S\')\n\t\t\t\t\t{\n\t\t\t\t\tprint_stats(bio_s_out,SSL_get_SSL_CTX(con));\n\t\t\t\t\t}\n\t\t\t\t}\n#ifdef CHARSET_EBCDIC\n\t\t\tebcdic2ascii(buf,buf,i);\n#endif\n\t\t\tl=k=0;\n\t\t\tfor (;;)\n\t\t\t\t{\n#ifdef RENEG\n{ static count=0; if (++count == 100) { count=0; SSL_renegotiate(con); } }\n#endif\n\t\t\t\tk=SSL_write(con,&(buf[l]),(unsigned int)i);\n\t\t\t\tswitch (SSL_get_error(con,k))\n\t\t\t\t\t{\n\t\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\t\tBIO_printf(bio_s_out,"Write BLOCK\\n");\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\t\tBIO_printf(bio_s_out,"ERROR\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tl+=k;\n\t\t\t\ti-=k;\n\t\t\t\tif (i <= 0) break;\n\t\t\t\t}\n\t\t\t}\n\t\tif (read_from_sslcon)\n\t\t\t{\n\t\t\tif (!SSL_is_init_finished(con))\n\t\t\t\t{\n\t\t\t\ti=init_ssl_connection(con);\n\t\t\t\tif (i < 0)\n\t\t\t\t\t{\n\t\t\t\t\tret=0;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\telse if (i == 0)\n\t\t\t\t\t{\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\nagain:\n\t\t\t\ti=SSL_read(con,(char *)buf,bufsize);\n\t\t\t\tswitch (SSL_get_error(con,i))\n\t\t\t\t\t{\n\t\t\t\tcase SSL_ERROR_NONE:\n#ifdef CHARSET_EBCDIC\n\t\t\t\t\tascii2ebcdic(buf,buf,i);\n#endif\n\t\t\t\t\twrite(fileno(stdout),buf,\n\t\t\t\t\t\t(unsigned int)i);\n\t\t\t\t\tif (SSL_pending(con)) goto again;\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\t\tBIO_printf(bio_s_out,"Read BLOCK\\n");\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\t\tBIO_printf(bio_s_out,"ERROR\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\nerr:\n\tBIO_printf(bio_s_out,"shutting down SSL\\n");\n#if 1\n\tSSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);\n#else\n\tSSL_shutdown(con);\n#endif\n\tif (con != NULL) SSL_free(con);\n\tBIO_printf(bio_s_out,"CONNECTION CLOSED\\n");\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bufsize);\n\t\tOPENSSL_free(buf);\n\t\t}\n\tif (ret >= 0)\n\t\tBIO_printf(bio_s_out,"ACCEPT\\n");\n\treturn(ret);\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\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}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)OPENSSL_realloc(lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}']
2,553
0
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_ctx.c/#L276
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n if (m->top == 1)\n a %= m->d[0];\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 if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == 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 r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_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_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n 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 bn_correct_top(r);\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(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_sqr(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 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(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}']
2,554
0
https://github.com/openssl/openssl/blob/a68d8c7b77a3d46d591b89cfd0ecd2a2242e4613/ssl/ssl_ciph.c/#L490
DEFINE_RUN_ONCE_STATIC(do_load_builtin_compressions) { SSL_COMP *comp = NULL; COMP_METHOD *method = COMP_zlib(); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); ssl_comp_methods = sk_SSL_COMP_new(sk_comp_cmp); if (COMP_get_type(method) != NID_undef && ssl_comp_methods != NULL) { comp = OPENSSL_malloc(sizeof(*comp)); if (comp != NULL) { comp->method = method; comp->id = SSL_COMP_ZLIB_IDX; comp->name = COMP_get_name(method); sk_SSL_COMP_push(ssl_comp_methods, comp); sk_SSL_COMP_sort(ssl_comp_methods); } } CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); return 1; }
['DEFINE_RUN_ONCE_STATIC(do_load_builtin_compressions)', 'DEFINE_RUN_ONCE_STATIC(do_load_builtin_compressions)\n{\n SSL_COMP *comp = NULL;\n COMP_METHOD *method = COMP_zlib();\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n ssl_comp_methods = sk_SSL_COMP_new(sk_comp_cmp);\n if (COMP_get_type(method) != NID_undef && ssl_comp_methods != NULL) {\n comp = OPENSSL_malloc(sizeof(*comp));\n if (comp != NULL) {\n comp->method = method;\n comp->id = SSL_COMP_ZLIB_IDX;\n comp->name = COMP_get_name(method);\n sk_SSL_COMP_push(ssl_comp_methods, comp);\n sk_SSL_COMP_sort(ssl_comp_methods);\n }\n }\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n return 1;\n}', 'COMP_METHOD *COMP_zlib(void)\n{\n COMP_METHOD *meth = &zlib_method_nozlib;\n#ifdef ZLIB_SHARED\n# ifndef LIBZ\n# if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)\n# define LIBZ "ZLIB1"\n# elif defined(OPENSSL_SYS_VMS)\n# define LIBZ "LIBZ"\n# else\n# define LIBZ "z"\n# endif\n# endif\n if (!zlib_loaded) {\n zlib_dso = DSO_load(NULL, LIBZ, NULL, 0);\n if (zlib_dso != NULL) {\n p_compress = (compress_ft) DSO_bind_func(zlib_dso, "compress");\n p_inflateEnd\n = (inflateEnd_ft) DSO_bind_func(zlib_dso, "inflateEnd");\n p_inflate = (inflate_ft) DSO_bind_func(zlib_dso, "inflate");\n p_inflateInit_\n = (inflateInit__ft) DSO_bind_func(zlib_dso, "inflateInit_");\n p_deflateEnd\n = (deflateEnd_ft) DSO_bind_func(zlib_dso, "deflateEnd");\n p_deflate = (deflate_ft) DSO_bind_func(zlib_dso, "deflate");\n p_deflateInit_\n = (deflateInit__ft) DSO_bind_func(zlib_dso, "deflateInit_");\n p_zError = (zError__ft) DSO_bind_func(zlib_dso, "zError");\n if (p_compress && p_inflateEnd && p_inflate\n && p_inflateInit_ && p_deflateEnd\n && p_deflate && p_deflateInit_ && p_zError)\n zlib_loaded++;\n if (!OPENSSL_init_crypto(OPENSSL_INIT_ZLIB, NULL)) {\n comp_zlib_cleanup_int();\n return meth;\n }\n if (zlib_loaded)\n meth = &zlib_stateful_method;\n }\n }\n#endif\n#if defined(ZLIB)\n meth = &zlib_stateful_method;\n#endif\n return (meth);\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}', 'int COMP_get_type(const COMP_METHOD *meth)\n{\n return meth->type;\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}', 'const char *COMP_get_name(const COMP_METHOD *meth)\n{\n return meth->name;\n}', 'int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)\n{\n return (OPENSSL_sk_insert(st, data, st->num));\n}']
2,555
1
https://github.com/openssl/openssl/blob/e4cf866322a4549c55153f9f135f9dadf4d3fc31/crypto/buffer/buf_str.c/#L98
char *BUF_strndup(const char *str, size_t siz) { char *ret; if (str == NULL) return NULL; siz = BUF_strnlen(str, siz); if (siz >= INT_MAX) return NULL; ret = OPENSSL_malloc(siz + 1); if (ret == NULL) { BUFerr(BUF_F_BUF_STRNDUP, ERR_R_MALLOC_FAILURE); return NULL; } memcpy(ret, str, siz); ret[siz] = '\0'; return (ret); }
['int setup_ui_method(void)\n{\n ui_method = UI_create_method("OpenSSL application user interface");\n UI_method_set_opener(ui_method, ui_open);\n UI_method_set_reader(ui_method, ui_read);\n UI_method_set_writer(ui_method, ui_write);\n UI_method_set_closer(ui_method, ui_close);\n return 0;\n}', 'UI_METHOD *UI_create_method(char *name)\n{\n UI_METHOD *ui_method = OPENSSL_zalloc(sizeof(*ui_method));\n if (ui_method != NULL)\n ui_method->name = BUF_strdup(name);\n return ui_method;\n}', 'char *BUF_strdup(const char *str)\n{\n if (str == NULL)\n return NULL;\n return BUF_strndup(str, strlen(str));\n}', "char *BUF_strndup(const char *str, size_t siz)\n{\n char *ret;\n if (str == NULL)\n return NULL;\n siz = BUF_strnlen(str, siz);\n if (siz >= INT_MAX)\n return NULL;\n ret = OPENSSL_malloc(siz + 1);\n if (ret == NULL) {\n BUFerr(BUF_F_BUF_STRNDUP, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n memcpy(ret, str, siz);\n ret[siz] = '\\0';\n return (ret);\n}", "size_t BUF_strnlen(const char *str, size_t maxlen)\n{\n const char *p;\n for (p = str; maxlen-- != 0 && *p != '\\0'; ++p) ;\n return p - str;\n}"]
2,556
0
https://github.com/libav/libav/blob/f5a2c9816e0b58edf2a87297be8d648631fc3432/libavcodec/dv.c/#L505
static inline void dv_decode_video_segment(DVVideoContext *s, const uint8_t *buf_ptr1, const uint16_t *mb_pos_ptr) { int quant, dc, dct_mode, class1, j; int mb_index, mb_x, mb_y, v, last_index; int y_stride, linesize; DCTELEM *block, *block1; int c_offset; uint8_t *y_ptr; const uint8_t *buf_ptr; PutBitContext pb, vs_pb; GetBitContext gb; BlockInfo mb_data[5 * DV_MAX_BPM], *mb, *mb1; DECLARE_ALIGNED_16(DCTELEM, sblock[5*DV_MAX_BPM][64]); DECLARE_ALIGNED_8(uint8_t, mb_bit_buffer[80 + 4]); DECLARE_ALIGNED_8(uint8_t, vs_bit_buffer[5 * 80 + 4]); const int log2_blocksize= 3-s->avctx->lowres; int is_field_mode[5]; assert((((int)mb_bit_buffer)&7)==0); assert((((int)vs_bit_buffer)&7)==0); memset(sblock, 0, sizeof(sblock)); buf_ptr = buf_ptr1; block1 = &sblock[0][0]; mb1 = mb_data; init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80); for(mb_index = 0; mb_index < 5; mb_index++, mb1 += s->sys->bpm, block1 += s->sys->bpm * 64) { quant = buf_ptr[3] & 0x0f; buf_ptr += 4; init_put_bits(&pb, mb_bit_buffer, 80); mb = mb1; block = block1; is_field_mode[mb_index] = 0; for(j = 0;j < s->sys->bpm; j++) { last_index = s->sys->block_sizes[j]; init_get_bits(&gb, buf_ptr, last_index); dc = get_sbits(&gb, 9); dct_mode = get_bits1(&gb); class1 = get_bits(&gb, 2); if (DV_PROFILE_IS_HD(s->sys)) { mb->idct_put = s->idct_put[0]; mb->scan_table = s->dv_zigzag[0]; mb->factor_table = s->dv100_idct_factor[((s->sys->height == 720)<<1)|(j >= 4)][class1][quant]; is_field_mode[mb_index] |= !j && dct_mode; } else { mb->idct_put = s->idct_put[dct_mode && log2_blocksize==3]; mb->scan_table = s->dv_zigzag[dct_mode]; mb->factor_table = s->dv_idct_factor[class1 == 3][dct_mode] [quant + dv_quant_offset[class1]]; } dc = dc << 2; dc += 1024; block[0] = dc; buf_ptr += last_index >> 3; mb->pos = 0; mb->partial_bit_count = 0; #ifdef VLC_DEBUG printf("MB block: %d, %d ", mb_index, j); #endif dv_decode_ac(&gb, mb, block); if (mb->pos >= 64) bit_copy(&pb, &gb); block += 64; mb++; } #ifdef VLC_DEBUG printf("***pass 2 size=%d MB#=%d\n", put_bits_count(&pb), mb_index); #endif block = block1; mb = mb1; init_get_bits(&gb, mb_bit_buffer, put_bits_count(&pb)); flush_put_bits(&pb); for(j = 0;j < s->sys->bpm; j++, block += 64, mb++) { if (mb->pos < 64 && get_bits_left(&gb) > 0) { dv_decode_ac(&gb, mb, block); if (mb->pos < 64) break; } } if (j >= s->sys->bpm) bit_copy(&vs_pb, &gb); } #ifdef VLC_DEBUG printf("***pass 3 size=%d\n", put_bits_count(&vs_pb)); #endif block = &sblock[0][0]; mb = mb_data; init_get_bits(&gb, vs_bit_buffer, put_bits_count(&vs_pb)); flush_put_bits(&vs_pb); for(mb_index = 0; mb_index < 5; mb_index++) { for(j = 0;j < s->sys->bpm; j++) { if (mb->pos < 64) { #ifdef VLC_DEBUG printf("start %d:%d\n", mb_index, j); #endif dv_decode_ac(&gb, mb, block); } if (mb->pos >= 64 && mb->pos < 127) av_log(NULL, AV_LOG_ERROR, "AC EOB marker is absent pos=%d\n", mb->pos); block += 64; mb++; } } block = &sblock[0][0]; mb = mb_data; for(mb_index = 0; mb_index < 5; mb_index++) { v = *mb_pos_ptr++; mb_x = v & 0xff; mb_y = v >> 8; if (s->sys->height == 720 && !(s->buf[1]&0x0C)) { mb_y -= (mb_y>17)?18:-72; } if ((s->sys->pix_fmt == PIX_FMT_YUV420P) || (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) || (s->sys->height >= 720 && mb_y != 134)) { y_stride = (s->picture.linesize[0]<<((!is_field_mode[mb_index])*log2_blocksize)); } else { y_stride = (2<<log2_blocksize); } y_ptr = s->picture.data[0] + ((mb_y * s->picture.linesize[0] + mb_x)<<log2_blocksize); linesize = s->picture.linesize[0]<<is_field_mode[mb_index]; mb[0] .idct_put(y_ptr , linesize, block + 0*64); if (s->sys->video_stype == 4) { mb[2].idct_put(y_ptr + (1<<log2_blocksize) , linesize, block + 2*64); } else { mb[1].idct_put(y_ptr + (1<<log2_blocksize) , linesize, block + 1*64); mb[2].idct_put(y_ptr + y_stride, linesize, block + 2*64); mb[3].idct_put(y_ptr + (1<<log2_blocksize) + y_stride, linesize, block + 3*64); } mb += 4; block += 4*64; c_offset = (((mb_y>>(s->sys->pix_fmt == PIX_FMT_YUV420P)) * s->picture.linesize[1] + (mb_x>>((s->sys->pix_fmt == PIX_FMT_YUV411P)?2:1)))<<log2_blocksize); for(j=2; j; j--) { uint8_t *c_ptr = s->picture.data[j] + c_offset; if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) { uint64_t aligned_pixels[64/8]; uint8_t *pixels = (uint8_t*)aligned_pixels; uint8_t *c_ptr1, *ptr1; int x, y; mb->idct_put(pixels, 8, block); for(y = 0; y < (1<<log2_blocksize); y++, c_ptr += s->picture.linesize[j], pixels += 8) { ptr1= pixels + (1<<(log2_blocksize-1)); c_ptr1 = c_ptr + (s->picture.linesize[j]<<log2_blocksize); for(x=0; x < (1<<(log2_blocksize-1)); x++) { c_ptr[x]= pixels[x]; c_ptr1[x]= ptr1[x]; } } block += 64; mb++; } else { y_stride = (mb_y == 134) ? (1<<log2_blocksize) : s->picture.linesize[j]<<((!is_field_mode[mb_index])*log2_blocksize); linesize = s->picture.linesize[j]<<is_field_mode[mb_index]; (mb++)-> idct_put(c_ptr , linesize, block); block+=64; if (s->sys->bpm == 8) { (mb++)->idct_put(c_ptr + y_stride, linesize, block); block+=64; } } } } }
['static inline void dv_decode_video_segment(DVVideoContext *s,\n const uint8_t *buf_ptr1,\n const uint16_t *mb_pos_ptr)\n{\n int quant, dc, dct_mode, class1, j;\n int mb_index, mb_x, mb_y, v, last_index;\n int y_stride, linesize;\n DCTELEM *block, *block1;\n int c_offset;\n uint8_t *y_ptr;\n const uint8_t *buf_ptr;\n PutBitContext pb, vs_pb;\n GetBitContext gb;\n BlockInfo mb_data[5 * DV_MAX_BPM], *mb, *mb1;\n DECLARE_ALIGNED_16(DCTELEM, sblock[5*DV_MAX_BPM][64]);\n DECLARE_ALIGNED_8(uint8_t, mb_bit_buffer[80 + 4]);\n DECLARE_ALIGNED_8(uint8_t, vs_bit_buffer[5 * 80 + 4]);\n const int log2_blocksize= 3-s->avctx->lowres;\n int is_field_mode[5];\n assert((((int)mb_bit_buffer)&7)==0);\n assert((((int)vs_bit_buffer)&7)==0);\n memset(sblock, 0, sizeof(sblock));\n buf_ptr = buf_ptr1;\n block1 = &sblock[0][0];\n mb1 = mb_data;\n init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80);\n for(mb_index = 0; mb_index < 5; mb_index++, mb1 += s->sys->bpm, block1 += s->sys->bpm * 64) {\n quant = buf_ptr[3] & 0x0f;\n buf_ptr += 4;\n init_put_bits(&pb, mb_bit_buffer, 80);\n mb = mb1;\n block = block1;\n is_field_mode[mb_index] = 0;\n for(j = 0;j < s->sys->bpm; j++) {\n last_index = s->sys->block_sizes[j];\n init_get_bits(&gb, buf_ptr, last_index);\n dc = get_sbits(&gb, 9);\n dct_mode = get_bits1(&gb);\n class1 = get_bits(&gb, 2);\n if (DV_PROFILE_IS_HD(s->sys)) {\n mb->idct_put = s->idct_put[0];\n mb->scan_table = s->dv_zigzag[0];\n mb->factor_table = s->dv100_idct_factor[((s->sys->height == 720)<<1)|(j >= 4)][class1][quant];\n is_field_mode[mb_index] |= !j && dct_mode;\n } else {\n mb->idct_put = s->idct_put[dct_mode && log2_blocksize==3];\n mb->scan_table = s->dv_zigzag[dct_mode];\n mb->factor_table = s->dv_idct_factor[class1 == 3][dct_mode]\n [quant + dv_quant_offset[class1]];\n }\n dc = dc << 2;\n dc += 1024;\n block[0] = dc;\n buf_ptr += last_index >> 3;\n mb->pos = 0;\n mb->partial_bit_count = 0;\n#ifdef VLC_DEBUG\n printf("MB block: %d, %d ", mb_index, j);\n#endif\n dv_decode_ac(&gb, mb, block);\n if (mb->pos >= 64)\n bit_copy(&pb, &gb);\n block += 64;\n mb++;\n }\n#ifdef VLC_DEBUG\n printf("***pass 2 size=%d MB#=%d\\n", put_bits_count(&pb), mb_index);\n#endif\n block = block1;\n mb = mb1;\n init_get_bits(&gb, mb_bit_buffer, put_bits_count(&pb));\n flush_put_bits(&pb);\n for(j = 0;j < s->sys->bpm; j++, block += 64, mb++) {\n if (mb->pos < 64 && get_bits_left(&gb) > 0) {\n dv_decode_ac(&gb, mb, block);\n if (mb->pos < 64)\n break;\n }\n }\n if (j >= s->sys->bpm)\n bit_copy(&vs_pb, &gb);\n }\n#ifdef VLC_DEBUG\n printf("***pass 3 size=%d\\n", put_bits_count(&vs_pb));\n#endif\n block = &sblock[0][0];\n mb = mb_data;\n init_get_bits(&gb, vs_bit_buffer, put_bits_count(&vs_pb));\n flush_put_bits(&vs_pb);\n for(mb_index = 0; mb_index < 5; mb_index++) {\n for(j = 0;j < s->sys->bpm; j++) {\n if (mb->pos < 64) {\n#ifdef VLC_DEBUG\n printf("start %d:%d\\n", mb_index, j);\n#endif\n dv_decode_ac(&gb, mb, block);\n }\n if (mb->pos >= 64 && mb->pos < 127)\n av_log(NULL, AV_LOG_ERROR, "AC EOB marker is absent pos=%d\\n", mb->pos);\n block += 64;\n mb++;\n }\n }\n block = &sblock[0][0];\n mb = mb_data;\n for(mb_index = 0; mb_index < 5; mb_index++) {\n v = *mb_pos_ptr++;\n mb_x = v & 0xff;\n mb_y = v >> 8;\n if (s->sys->height == 720 && !(s->buf[1]&0x0C)) {\n mb_y -= (mb_y>17)?18:-72;\n }\n if ((s->sys->pix_fmt == PIX_FMT_YUV420P) ||\n (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) ||\n (s->sys->height >= 720 && mb_y != 134)) {\n y_stride = (s->picture.linesize[0]<<((!is_field_mode[mb_index])*log2_blocksize));\n } else {\n y_stride = (2<<log2_blocksize);\n }\n y_ptr = s->picture.data[0] + ((mb_y * s->picture.linesize[0] + mb_x)<<log2_blocksize);\n linesize = s->picture.linesize[0]<<is_field_mode[mb_index];\n mb[0] .idct_put(y_ptr , linesize, block + 0*64);\n if (s->sys->video_stype == 4) {\n mb[2].idct_put(y_ptr + (1<<log2_blocksize) , linesize, block + 2*64);\n } else {\n mb[1].idct_put(y_ptr + (1<<log2_blocksize) , linesize, block + 1*64);\n mb[2].idct_put(y_ptr + y_stride, linesize, block + 2*64);\n mb[3].idct_put(y_ptr + (1<<log2_blocksize) + y_stride, linesize, block + 3*64);\n }\n mb += 4;\n block += 4*64;\n c_offset = (((mb_y>>(s->sys->pix_fmt == PIX_FMT_YUV420P)) * s->picture.linesize[1] +\n (mb_x>>((s->sys->pix_fmt == PIX_FMT_YUV411P)?2:1)))<<log2_blocksize);\n for(j=2; j; j--) {\n uint8_t *c_ptr = s->picture.data[j] + c_offset;\n if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) {\n uint64_t aligned_pixels[64/8];\n uint8_t *pixels = (uint8_t*)aligned_pixels;\n uint8_t *c_ptr1, *ptr1;\n int x, y;\n mb->idct_put(pixels, 8, block);\n for(y = 0; y < (1<<log2_blocksize); y++, c_ptr += s->picture.linesize[j], pixels += 8) {\n ptr1= pixels + (1<<(log2_blocksize-1));\n c_ptr1 = c_ptr + (s->picture.linesize[j]<<log2_blocksize);\n for(x=0; x < (1<<(log2_blocksize-1)); x++) {\n c_ptr[x]= pixels[x];\n c_ptr1[x]= ptr1[x];\n }\n }\n block += 64; mb++;\n } else {\n y_stride = (mb_y == 134) ? (1<<log2_blocksize) :\n s->picture.linesize[j]<<((!is_field_mode[mb_index])*log2_blocksize);\n linesize = s->picture.linesize[j]<<is_field_mode[mb_index];\n (mb++)-> idct_put(c_ptr , linesize, block); block+=64;\n if (s->sys->bpm == 8) {\n (mb++)->idct_put(c_ptr + y_stride, linesize, block); block+=64;\n }\n }\n }\n }\n}']
2,557
0
https://github.com/openssl/openssl/blob/de3955f66225e42bfae710c50b51c98aa4616ac1/ssl/ssl_ciph.c/#L473
DEFINE_RUN_ONCE_STATIC(do_load_builtin_compressions) { SSL_COMP *comp = NULL; COMP_METHOD *method = COMP_zlib(); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); ssl_comp_methods = sk_SSL_COMP_new(sk_comp_cmp); if (COMP_get_type(method) != NID_undef && ssl_comp_methods != NULL) { comp = OPENSSL_malloc(sizeof(*comp)); if (comp != NULL) { comp->method = method; comp->id = SSL_COMP_ZLIB_IDX; comp->name = COMP_get_name(method); sk_SSL_COMP_push(ssl_comp_methods, comp); sk_SSL_COMP_sort(ssl_comp_methods); } } CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); return 1; }
['DEFINE_RUN_ONCE_STATIC(do_load_builtin_compressions)', 'DEFINE_RUN_ONCE_STATIC(do_load_builtin_compressions)\n{\n SSL_COMP *comp = NULL;\n COMP_METHOD *method = COMP_zlib();\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n ssl_comp_methods = sk_SSL_COMP_new(sk_comp_cmp);\n if (COMP_get_type(method) != NID_undef && ssl_comp_methods != NULL) {\n comp = OPENSSL_malloc(sizeof(*comp));\n if (comp != NULL) {\n comp->method = method;\n comp->id = SSL_COMP_ZLIB_IDX;\n comp->name = COMP_get_name(method);\n sk_SSL_COMP_push(ssl_comp_methods, comp);\n sk_SSL_COMP_sort(ssl_comp_methods);\n }\n }\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n return 1;\n}', 'COMP_METHOD *COMP_zlib(void)\n{\n COMP_METHOD *meth = &zlib_method_nozlib;\n#ifdef ZLIB_SHARED\n# ifndef LIBZ\n# if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)\n# define LIBZ "ZLIB1"\n# elif defined(OPENSSL_SYS_VMS)\n# define LIBZ "LIBZ"\n# else\n# define LIBZ "z"\n# endif\n# endif\n if (!zlib_loaded) {\n zlib_dso = DSO_load(NULL, LIBZ, NULL, 0);\n if (zlib_dso != NULL) {\n p_compress = (compress_ft) DSO_bind_func(zlib_dso, "compress");\n p_inflateEnd\n = (inflateEnd_ft) DSO_bind_func(zlib_dso, "inflateEnd");\n p_inflate = (inflate_ft) DSO_bind_func(zlib_dso, "inflate");\n p_inflateInit_\n = (inflateInit__ft) DSO_bind_func(zlib_dso, "inflateInit_");\n p_deflateEnd\n = (deflateEnd_ft) DSO_bind_func(zlib_dso, "deflateEnd");\n p_deflate = (deflate_ft) DSO_bind_func(zlib_dso, "deflate");\n p_deflateInit_\n = (deflateInit__ft) DSO_bind_func(zlib_dso, "deflateInit_");\n p_zError = (zError__ft) DSO_bind_func(zlib_dso, "zError");\n if (p_compress && p_inflateEnd && p_inflate\n && p_inflateInit_ && p_deflateEnd\n && p_deflate && p_deflateInit_ && p_zError)\n zlib_loaded++;\n if (!OPENSSL_init_crypto(OPENSSL_INIT_ZLIB, NULL)) {\n comp_zlib_cleanup_int();\n return meth;\n }\n if (zlib_loaded)\n meth = &zlib_stateful_method;\n }\n }\n#endif\n#if defined(ZLIB)\n meth = &zlib_stateful_method;\n#endif\n return meth;\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(memdbg_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(memdbg_lock);\n CRYPTO_THREAD_write_lock(long_memdbg_lock);\n CRYPTO_THREAD_write_lock(memdbg_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_memdbg_lock);\n }\n }\n }\n break;\n }\n CRYPTO_THREAD_unlock(memdbg_lock);\n return ret;\n#endif\n}', 'OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c)\n{\n return OPENSSL_sk_new_reserve(c, 0);\n}', 'int COMP_get_type(const COMP_METHOD *meth)\n{\n return meth->type;\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}', 'const char *COMP_get_name(const COMP_METHOD *meth)\n{\n return meth->name;\n}', 'int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)\n{\n if (st == NULL)\n return -1;\n return OPENSSL_sk_insert(st, data, st->num);\n}', 'int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc)\n{\n if (st == NULL || st->num == max_nodes)\n return 0;\n if (!sk_reserve(st, 1, 0))\n return 0;\n if ((loc >= st->num) || (loc < 0)) {\n st->data[st->num] = data;\n } else {\n memmove(&st->data[loc + 1], &st->data[loc],\n sizeof(st->data[0]) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return st->num;\n}']
2,558
0
https://github.com/libav/libav/blob/640d5f1c801061844394813c78ea449e5826f6e5/libavformat/mpegts.c/#L694
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size) { GetBitContext gb; int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0; int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0; int dts_flag = -1, cts_flag = -1; int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE; init_get_bits(&gb, buf, buf_size*8); if (sl->use_au_start) au_start_flag = get_bits1(&gb); if (sl->use_au_end) au_end_flag = get_bits1(&gb); if (!sl->use_au_start && !sl->use_au_end) au_start_flag = au_end_flag = 1; if (sl->ocr_len > 0) ocr_flag = get_bits1(&gb); if (sl->use_idle) idle_flag = get_bits1(&gb); if (sl->use_padding) padding_flag = get_bits1(&gb); if (padding_flag) padding_bits = get_bits(&gb, 3); if (!idle_flag && (!padding_flag || padding_bits != 0)) { if (sl->packet_seq_num_len) skip_bits_long(&gb, sl->packet_seq_num_len); if (sl->degr_prior_len) if (get_bits1(&gb)) skip_bits(&gb, sl->degr_prior_len); if (ocr_flag) skip_bits_long(&gb, sl->ocr_len); if (au_start_flag) { if (sl->use_rand_acc_pt) get_bits1(&gb); if (sl->au_seq_num_len > 0) skip_bits_long(&gb, sl->au_seq_num_len); if (sl->use_timestamps) { dts_flag = get_bits1(&gb); cts_flag = get_bits1(&gb); } } if (sl->inst_bitrate_len) inst_bitrate_flag = get_bits1(&gb); if (dts_flag == 1) dts = get_bits64(&gb, sl->timestamp_len); if (cts_flag == 1) cts = get_bits64(&gb, sl->timestamp_len); if (sl->au_len > 0) skip_bits_long(&gb, sl->au_len); if (inst_bitrate_flag) skip_bits_long(&gb, sl->inst_bitrate_len); } if (dts != AV_NOPTS_VALUE) pes->dts = dts; if (cts != AV_NOPTS_VALUE) pes->pts = cts; av_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res); return (get_bits_count(&gb) + 7) >> 3; }
['static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)\n{\n GetBitContext gb;\n int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;\n int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;\n int dts_flag = -1, cts_flag = -1;\n int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE;\n init_get_bits(&gb, buf, buf_size*8);\n if (sl->use_au_start)\n au_start_flag = get_bits1(&gb);\n if (sl->use_au_end)\n au_end_flag = get_bits1(&gb);\n if (!sl->use_au_start && !sl->use_au_end)\n au_start_flag = au_end_flag = 1;\n if (sl->ocr_len > 0)\n ocr_flag = get_bits1(&gb);\n if (sl->use_idle)\n idle_flag = get_bits1(&gb);\n if (sl->use_padding)\n padding_flag = get_bits1(&gb);\n if (padding_flag)\n padding_bits = get_bits(&gb, 3);\n if (!idle_flag && (!padding_flag || padding_bits != 0)) {\n if (sl->packet_seq_num_len)\n skip_bits_long(&gb, sl->packet_seq_num_len);\n if (sl->degr_prior_len)\n if (get_bits1(&gb))\n skip_bits(&gb, sl->degr_prior_len);\n if (ocr_flag)\n skip_bits_long(&gb, sl->ocr_len);\n if (au_start_flag) {\n if (sl->use_rand_acc_pt)\n get_bits1(&gb);\n if (sl->au_seq_num_len > 0)\n skip_bits_long(&gb, sl->au_seq_num_len);\n if (sl->use_timestamps) {\n dts_flag = get_bits1(&gb);\n cts_flag = get_bits1(&gb);\n }\n }\n if (sl->inst_bitrate_len)\n inst_bitrate_flag = get_bits1(&gb);\n if (dts_flag == 1)\n dts = get_bits64(&gb, sl->timestamp_len);\n if (cts_flag == 1)\n cts = get_bits64(&gb, sl->timestamp_len);\n if (sl->au_len > 0)\n skip_bits_long(&gb, sl->au_len);\n if (inst_bitrate_flag)\n skip_bits_long(&gb, sl->inst_bitrate_len);\n }\n if (dts != AV_NOPTS_VALUE)\n pes->dts = dts;\n if (cts != AV_NOPTS_VALUE)\n pes->pts = cts;\n av_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res);\n return (get_bits_count(&gb) + 7) >> 3;\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}']
2,559
0
https://github.com/openssl/openssl/blob/3fd5ece39b59d938d0cc84b8e5148d19044d15cf/test/ssltest_old.c/#L761
static void print_key_details(BIO *out, EVP_PKEY *key) { int keyid = EVP_PKEY_id(key); #ifndef OPENSSL_NO_EC if (keyid == EVP_PKEY_EC) { EC_KEY *ec = EVP_PKEY_get1_EC_KEY(key); int nid; const char *cname; nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec)); EC_KEY_free(ec); cname = EC_curve_nid2nist(nid); if (!cname) cname = OBJ_nid2sn(nid); BIO_printf(out, "%d bits EC (%s)", EVP_PKEY_bits(key), cname); } else #endif { const char *algname; switch (keyid) { case EVP_PKEY_RSA: algname = "RSA"; break; case EVP_PKEY_DSA: algname = "DSA"; break; case EVP_PKEY_DH: algname = "DH"; break; default: algname = OBJ_nid2sn(keyid); break; } BIO_printf(out, "%d bits %s", EVP_PKEY_bits(key), algname); } }
['static void print_key_details(BIO *out, EVP_PKEY *key)\n{\n int keyid = EVP_PKEY_id(key);\n#ifndef OPENSSL_NO_EC\n if (keyid == EVP_PKEY_EC) {\n EC_KEY *ec = EVP_PKEY_get1_EC_KEY(key);\n int nid;\n const char *cname;\n nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));\n EC_KEY_free(ec);\n cname = EC_curve_nid2nist(nid);\n if (!cname)\n cname = OBJ_nid2sn(nid);\n BIO_printf(out, "%d bits EC (%s)", EVP_PKEY_bits(key), cname);\n } else\n#endif\n {\n const char *algname;\n switch (keyid) {\n case EVP_PKEY_RSA:\n algname = "RSA";\n break;\n case EVP_PKEY_DSA:\n algname = "DSA";\n break;\n case EVP_PKEY_DH:\n algname = "DH";\n break;\n default:\n algname = OBJ_nid2sn(keyid);\n break;\n }\n BIO_printf(out, "%d bits %s", EVP_PKEY_bits(key), algname);\n }\n}', 'int EVP_PKEY_id(const EVP_PKEY *pkey)\n{\n return pkey->type;\n}', 'EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)\n{\n EC_KEY *ret = EVP_PKEY_get0_EC_KEY(pkey);\n if (ret != NULL)\n EC_KEY_up_ref(ret);\n return ret;\n}', 'EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)\n{\n if (pkey->type != EVP_PKEY_EC) {\n EVPerr(EVP_F_EVP_PKEY_GET0_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);\n return NULL;\n }\n return pkey->pkey.ec;\n}', 'const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)\n{\n return key->group;\n}']
2,560
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavformat/rmdec.c/#L788
static int64_t rm_read_dts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit) { RMContext *rm = s->priv_data; int64_t pos, dts; int stream_index2, flags, len, h; pos = *ppos; if(rm->old_format) return AV_NOPTS_VALUE; url_fseek(s->pb, pos, SEEK_SET); rm->remaining_len=0; for(;;){ int seq=1; AVStream *st; len=sync(s, &dts, &flags, &stream_index2, &pos); if(len<0) return AV_NOPTS_VALUE; st = s->streams[stream_index2]; if (st->codec->codec_type == CODEC_TYPE_VIDEO) { h= get_byte(s->pb); len--; if(!(h & 0x40)){ seq = get_byte(s->pb); len--; } } if((flags&2) && (seq&0x7F) == 1){ av_add_index_entry(st, pos, dts, 0, 0, AVINDEX_KEYFRAME); if(stream_index2 == stream_index) break; } url_fskip(s->pb, len); } *ppos = pos; return dts; }
['static int64_t rm_read_dts(AVFormatContext *s, int stream_index,\n int64_t *ppos, int64_t pos_limit)\n{\n RMContext *rm = s->priv_data;\n int64_t pos, dts;\n int stream_index2, flags, len, h;\n pos = *ppos;\n if(rm->old_format)\n return AV_NOPTS_VALUE;\n url_fseek(s->pb, pos, SEEK_SET);\n rm->remaining_len=0;\n for(;;){\n int seq=1;\n AVStream *st;\n len=sync(s, &dts, &flags, &stream_index2, &pos);\n if(len<0)\n return AV_NOPTS_VALUE;\n st = s->streams[stream_index2];\n if (st->codec->codec_type == CODEC_TYPE_VIDEO) {\n h= get_byte(s->pb); len--;\n if(!(h & 0x40)){\n seq = get_byte(s->pb); len--;\n }\n }\n if((flags&2) && (seq&0x7F) == 1){\n av_add_index_entry(st, pos, dts, 0, 0, AVINDEX_KEYFRAME);\n if(stream_index2 == stream_index)\n break;\n }\n url_fskip(s->pb, len);\n }\n *ppos = pos;\n return dts;\n}']
2,561
0
https://github.com/openssl/openssl/blob/d858c87653257185ead1c5baf3d84cd7276dd912/apps/pkeyutl.c/#L305
int pkeyutl_main(int argc, char **argv) { BIO *in = NULL, *out = NULL; ENGINE *e = NULL; EVP_PKEY_CTX *ctx = NULL; char *infile = NULL, *outfile = NULL, *sigfile = NULL, *passinarg = NULL; char hexdump = 0, asn1parse = 0, rev = 0, *prog; unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL; OPTION_CHOICE o; int buf_inlen = 0, siglen = -1, keyform = FORMAT_PEM, peerform = FORMAT_PEM; int keysize = -1, pkey_op = EVP_PKEY_OP_SIGN, key_type = KEY_PRIVKEY; int ret = 1, rv = -1; size_t buf_outlen; const char *inkey = NULL; const char *peerkey = NULL; STACK_OF(OPENSSL_STRING) *pkeyopts = NULL; prog = opt_init(argc, argv, pkeyutl_options); while ((o = opt_next()) != OPT_EOF) { switch (o) { case OPT_EOF: case OPT_ERR: opthelp: BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); goto end; case OPT_HELP: opt_help(pkeyutl_options); ret = 0; goto end; case OPT_IN: infile = opt_arg(); break; case OPT_OUT: outfile = opt_arg(); break; case OPT_SIGFILE: sigfile = opt_arg(); break; case OPT_INKEY: inkey = opt_arg(); break; case OPT_PEERKEY: peerkey = opt_arg(); break; case OPT_PASSIN: passinarg = opt_arg(); break; case OPT_PEERFORM: if (!opt_format(opt_arg(), OPT_FMT_PDE, &peerform)) goto opthelp; break; case OPT_KEYFORM: if (!opt_format(opt_arg(), OPT_FMT_PDE, &keyform)) goto opthelp; break; case OPT_ENGINE: e = setup_engine(opt_arg(), 0); break; case OPT_PUBIN: key_type = KEY_PUBKEY; break; case OPT_CERTIN: key_type = KEY_CERT; break; case OPT_ASN1PARSE: asn1parse = 1; break; case OPT_HEXDUMP: hexdump = 1; break; case OPT_SIGN: pkey_op = EVP_PKEY_OP_SIGN; break; case OPT_VERIFY: pkey_op = EVP_PKEY_OP_VERIFY; break; case OPT_VERIFYRECOVER: pkey_op = EVP_PKEY_OP_VERIFYRECOVER; break; case OPT_ENCRYPT: pkey_op = EVP_PKEY_OP_ENCRYPT; break; case OPT_DECRYPT: pkey_op = EVP_PKEY_OP_DECRYPT; break; case OPT_DERIVE: pkey_op = EVP_PKEY_OP_DERIVE; break; case OPT_REV: rev = 1; break; case OPT_PKEYOPT: if ((pkeyopts == NULL && (pkeyopts = sk_OPENSSL_STRING_new_null()) == NULL) || sk_OPENSSL_STRING_push(pkeyopts, *++argv) == 0) { BIO_puts(bio_err, "out of memory\n"); goto end; } break; } } argc = opt_num_rest(); argv = opt_rest(); if (inkey == NULL || (peerkey != NULL && pkey_op != EVP_PKEY_OP_DERIVE)) goto opthelp; ctx = init_ctx(&keysize, inkey, keyform, key_type, passinarg, pkey_op, e); if (ctx == NULL) { BIO_printf(bio_err, "%s: Error initializing context\n", prog); ERR_print_errors(bio_err); goto end; } if (peerkey != NULL && !setup_peer(ctx, peerform, peerkey, e)) { BIO_printf(bio_err, "%s: Error setting up peer key\n", prog); ERR_print_errors(bio_err); goto end; } if (pkeyopts != NULL) { int num = sk_OPENSSL_STRING_num(pkeyopts); int i; for (i = 0; i < num; ++i) { const char *opt = sk_OPENSSL_STRING_value(pkeyopts, i); if (pkey_ctrl_string(ctx, opt) <= 0) { BIO_printf(bio_err, "%s: Can't set parameter:\n", prog); ERR_print_errors(bio_err); goto end; } } } if (sigfile && (pkey_op != EVP_PKEY_OP_VERIFY)) { BIO_printf(bio_err, "%s: Signature file specified for non verify\n", prog); goto end; } if (!sigfile && (pkey_op == EVP_PKEY_OP_VERIFY)) { BIO_printf(bio_err, "%s: No signature file specified for verify\n", prog); goto end; } app_RAND_load_file(NULL, 0); if (pkey_op != EVP_PKEY_OP_DERIVE) { in = bio_open_default(infile, 'r', FORMAT_BINARY); if (in == NULL) goto end; } out = bio_open_default(outfile, 'w', FORMAT_BINARY); if (out == NULL) goto end; if (sigfile) { BIO *sigbio = BIO_new_file(sigfile, "rb"); if (!sigbio) { BIO_printf(bio_err, "Can't open signature file %s\n", sigfile); goto end; } siglen = bio_to_mem(&sig, keysize * 10, sigbio); BIO_free(sigbio); if (siglen < 0) { BIO_printf(bio_err, "Error reading signature data\n"); goto end; } } if (in) { buf_inlen = bio_to_mem(&buf_in, keysize * 10, in); if (buf_inlen < 0) { BIO_printf(bio_err, "Error reading input Data\n"); exit(1); } if (rev) { size_t i; unsigned char ctmp; size_t l = (size_t)buf_inlen; for (i = 0; i < l / 2; i++) { ctmp = buf_in[i]; buf_in[i] = buf_in[l - 1 - i]; buf_in[l - 1 - i] = ctmp; } } } if (pkey_op == EVP_PKEY_OP_VERIFY) { rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen, buf_in, (size_t)buf_inlen); if (rv == 1) { BIO_puts(out, "Signature Verified Successfully\n"); ret = 0; } else BIO_puts(out, "Signature Verification Failure\n"); goto end; } rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen, buf_in, (size_t)buf_inlen); if (rv > 0 && buf_outlen != 0) { buf_out = app_malloc(buf_outlen, "buffer output"); rv = do_keyop(ctx, pkey_op, buf_out, (size_t *)&buf_outlen, buf_in, (size_t)buf_inlen); } if (rv < 0) { ERR_print_errors(bio_err); goto end; } ret = 0; if (asn1parse) { if (!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1)) ERR_print_errors(bio_err); } else if (hexdump) BIO_dump(out, (char *)buf_out, buf_outlen); else BIO_write(out, buf_out, buf_outlen); end: EVP_PKEY_CTX_free(ctx); BIO_free(in); BIO_free_all(out); OPENSSL_free(buf_in); OPENSSL_free(buf_out); OPENSSL_free(sig); sk_OPENSSL_STRING_free(pkeyopts); return ret; }
['int pkeyutl_main(int argc, char **argv)\n{\n BIO *in = NULL, *out = NULL;\n ENGINE *e = NULL;\n EVP_PKEY_CTX *ctx = NULL;\n char *infile = NULL, *outfile = NULL, *sigfile = NULL, *passinarg = NULL;\n char hexdump = 0, asn1parse = 0, rev = 0, *prog;\n unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL;\n OPTION_CHOICE o;\n int buf_inlen = 0, siglen = -1, keyform = FORMAT_PEM, peerform =\n FORMAT_PEM;\n int keysize = -1, pkey_op = EVP_PKEY_OP_SIGN, key_type = KEY_PRIVKEY;\n int ret = 1, rv = -1;\n size_t buf_outlen;\n const char *inkey = NULL;\n const char *peerkey = NULL;\n STACK_OF(OPENSSL_STRING) *pkeyopts = NULL;\n prog = opt_init(argc, argv, pkeyutl_options);\n while ((o = opt_next()) != OPT_EOF) {\n switch (o) {\n case OPT_EOF:\n case OPT_ERR:\n opthelp:\n BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n goto end;\n case OPT_HELP:\n opt_help(pkeyutl_options);\n ret = 0;\n goto end;\n case OPT_IN:\n infile = opt_arg();\n break;\n case OPT_OUT:\n outfile = opt_arg();\n break;\n case OPT_SIGFILE:\n sigfile = opt_arg();\n break;\n case OPT_INKEY:\n inkey = opt_arg();\n break;\n case OPT_PEERKEY:\n peerkey = opt_arg();\n break;\n case OPT_PASSIN:\n passinarg = opt_arg();\n break;\n case OPT_PEERFORM:\n if (!opt_format(opt_arg(), OPT_FMT_PDE, &peerform))\n goto opthelp;\n break;\n case OPT_KEYFORM:\n if (!opt_format(opt_arg(), OPT_FMT_PDE, &keyform))\n goto opthelp;\n break;\n case OPT_ENGINE:\n e = setup_engine(opt_arg(), 0);\n break;\n case OPT_PUBIN:\n key_type = KEY_PUBKEY;\n break;\n case OPT_CERTIN:\n key_type = KEY_CERT;\n break;\n case OPT_ASN1PARSE:\n asn1parse = 1;\n break;\n case OPT_HEXDUMP:\n hexdump = 1;\n break;\n case OPT_SIGN:\n pkey_op = EVP_PKEY_OP_SIGN;\n break;\n case OPT_VERIFY:\n pkey_op = EVP_PKEY_OP_VERIFY;\n break;\n case OPT_VERIFYRECOVER:\n pkey_op = EVP_PKEY_OP_VERIFYRECOVER;\n break;\n case OPT_ENCRYPT:\n pkey_op = EVP_PKEY_OP_ENCRYPT;\n break;\n case OPT_DECRYPT:\n pkey_op = EVP_PKEY_OP_DECRYPT;\n break;\n case OPT_DERIVE:\n pkey_op = EVP_PKEY_OP_DERIVE;\n break;\n case OPT_REV:\n rev = 1;\n break;\n case OPT_PKEYOPT:\n if ((pkeyopts == NULL &&\n (pkeyopts = sk_OPENSSL_STRING_new_null()) == NULL) ||\n sk_OPENSSL_STRING_push(pkeyopts, *++argv) == 0) {\n BIO_puts(bio_err, "out of memory\\n");\n goto end;\n }\n break;\n }\n }\n argc = opt_num_rest();\n argv = opt_rest();\n if (inkey == NULL ||\n (peerkey != NULL && pkey_op != EVP_PKEY_OP_DERIVE))\n goto opthelp;\n ctx = init_ctx(&keysize, inkey, keyform, key_type,\n passinarg, pkey_op, e);\n if (ctx == NULL) {\n BIO_printf(bio_err, "%s: Error initializing context\\n", prog);\n ERR_print_errors(bio_err);\n goto end;\n }\n if (peerkey != NULL && !setup_peer(ctx, peerform, peerkey, e)) {\n BIO_printf(bio_err, "%s: Error setting up peer key\\n", prog);\n ERR_print_errors(bio_err);\n goto end;\n }\n if (pkeyopts != NULL) {\n int num = sk_OPENSSL_STRING_num(pkeyopts);\n int i;\n for (i = 0; i < num; ++i) {\n const char *opt = sk_OPENSSL_STRING_value(pkeyopts, i);\n if (pkey_ctrl_string(ctx, opt) <= 0) {\n BIO_printf(bio_err, "%s: Can\'t set parameter:\\n", prog);\n ERR_print_errors(bio_err);\n goto end;\n }\n }\n }\n if (sigfile && (pkey_op != EVP_PKEY_OP_VERIFY)) {\n BIO_printf(bio_err,\n "%s: Signature file specified for non verify\\n", prog);\n goto end;\n }\n if (!sigfile && (pkey_op == EVP_PKEY_OP_VERIFY)) {\n BIO_printf(bio_err,\n "%s: No signature file specified for verify\\n", prog);\n goto end;\n }\n app_RAND_load_file(NULL, 0);\n if (pkey_op != EVP_PKEY_OP_DERIVE) {\n in = bio_open_default(infile, \'r\', FORMAT_BINARY);\n if (in == NULL)\n goto end;\n }\n out = bio_open_default(outfile, \'w\', FORMAT_BINARY);\n if (out == NULL)\n goto end;\n if (sigfile) {\n BIO *sigbio = BIO_new_file(sigfile, "rb");\n if (!sigbio) {\n BIO_printf(bio_err, "Can\'t open signature file %s\\n", sigfile);\n goto end;\n }\n siglen = bio_to_mem(&sig, keysize * 10, sigbio);\n BIO_free(sigbio);\n if (siglen < 0) {\n BIO_printf(bio_err, "Error reading signature data\\n");\n goto end;\n }\n }\n if (in) {\n buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);\n if (buf_inlen < 0) {\n BIO_printf(bio_err, "Error reading input Data\\n");\n exit(1);\n }\n if (rev) {\n size_t i;\n unsigned char ctmp;\n size_t l = (size_t)buf_inlen;\n for (i = 0; i < l / 2; i++) {\n ctmp = buf_in[i];\n buf_in[i] = buf_in[l - 1 - i];\n buf_in[l - 1 - i] = ctmp;\n }\n }\n }\n if (pkey_op == EVP_PKEY_OP_VERIFY) {\n rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen,\n buf_in, (size_t)buf_inlen);\n if (rv == 1) {\n BIO_puts(out, "Signature Verified Successfully\\n");\n ret = 0;\n } else\n BIO_puts(out, "Signature Verification Failure\\n");\n goto end;\n }\n rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen,\n buf_in, (size_t)buf_inlen);\n if (rv > 0 && buf_outlen != 0) {\n buf_out = app_malloc(buf_outlen, "buffer output");\n rv = do_keyop(ctx, pkey_op,\n buf_out, (size_t *)&buf_outlen,\n buf_in, (size_t)buf_inlen);\n }\n if (rv < 0) {\n ERR_print_errors(bio_err);\n goto end;\n }\n ret = 0;\n if (asn1parse) {\n if (!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1))\n ERR_print_errors(bio_err);\n } else if (hexdump)\n BIO_dump(out, (char *)buf_out, buf_outlen);\n else\n BIO_write(out, buf_out, buf_outlen);\n end:\n EVP_PKEY_CTX_free(ctx);\n BIO_free(in);\n BIO_free_all(out);\n OPENSSL_free(buf_in);\n OPENSSL_free(buf_out);\n OPENSSL_free(sig);\n sk_OPENSSL_STRING_free(pkeyopts);\n return ret;\n}', 'int bio_to_mem(unsigned char **out, int maxlen, BIO *in)\n{\n BIO *mem;\n int len, ret;\n unsigned char tbuf[1024];\n mem = BIO_new(BIO_s_mem());\n if (mem == NULL)\n return -1;\n for (;;) {\n if ((maxlen != -1) && maxlen < 1024)\n len = maxlen;\n else\n len = 1024;\n len = BIO_read(in, tbuf, len);\n if (len < 0) {\n BIO_free(mem);\n return -1;\n }\n if (len == 0)\n break;\n if (BIO_write(mem, tbuf, len) != len) {\n BIO_free(mem);\n return -1;\n }\n maxlen -= len;\n if (maxlen == 0)\n break;\n }\n ret = BIO_get_mem_data(mem, (char **)out);\n BIO_set_flags(mem, BIO_FLAGS_MEM_RDONLY);\n BIO_free(mem);\n return ret;\n}']
2,562
0
https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/bn/bn_lib.c/#L271
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['int DH_check(const DH *dh, int *ret)\n{\n int ok = 0, r;\n BN_CTX *ctx = NULL;\n BN_ULONG l;\n BIGNUM *t1 = NULL, *t2 = NULL;\n *ret = 0;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\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 (dh->q) {\n if (BN_cmp(dh->g, BN_value_one()) <= 0)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n else if (BN_cmp(dh->g, dh->p) >= 0)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n else {\n if (!BN_mod_exp(t1, dh->g, dh->q, dh->p, ctx))\n goto err;\n if (!BN_is_one(t1))\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n }\n r = BN_is_prime_ex(dh->q, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_Q_NOT_PRIME;\n if (!BN_div(t1, t2, dh->p, dh->q, ctx))\n goto err;\n if (!BN_is_one(t2))\n *ret |= DH_CHECK_INVALID_Q_VALUE;\n if (dh->j && BN_cmp(dh->j, t1))\n *ret |= DH_CHECK_INVALID_J_VALUE;\n } else if (BN_is_word(dh->g, DH_GENERATOR_2)) {\n l = BN_mod_word(dh->p, 24);\n if (l == (BN_ULONG)-1)\n goto err;\n if (l != 11)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n } else if (BN_is_word(dh->g, DH_GENERATOR_5)) {\n l = BN_mod_word(dh->p, 10);\n if (l == (BN_ULONG)-1)\n goto err;\n if ((l != 3) && (l != 7))\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n } else\n *ret |= DH_UNABLE_TO_CHECK_GENERATOR;\n r = BN_is_prime_ex(dh->p, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_P_NOT_PRIME;\n else if (!dh->q) {\n if (!BN_rshift1(t1, dh->p))\n goto err;\n r = BN_is_prime_ex(t1, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_P_NOT_SAFE_PRIME;\n }\n ok = 1;\n err:\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return (ok);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', '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_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
2,563
0
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/crypto/mem_dbg.c/#L650
static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l) { char buf[1024]; char *bufp = buf; APP_INFO *amip; int ami_cnt; struct tm *lcl = NULL; CRYPTO_THREADID ti; #define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf)) if (m->addr == (char *)l->bio) { l->seen = 1; return; } if (options & V_CRYPTO_MDEBUG_TIME) { lcl = localtime(&m->time); BIO_snprintf(bufp, BUF_REMAIN, "[%02d:%02d:%02d] ", lcl->tm_hour, lcl->tm_min, lcl->tm_sec); bufp += strlen(bufp); } BIO_snprintf(bufp, BUF_REMAIN, "%5lu file=%s, line=%d, ", m->order, m->file, m->line); bufp += strlen(bufp); if (options & V_CRYPTO_MDEBUG_THREAD) { BIO_snprintf(bufp, BUF_REMAIN, "thread=%lu, ", CRYPTO_THREADID_hash(&m->threadid)); bufp += strlen(bufp); } BIO_snprintf(bufp, BUF_REMAIN, "number=%d, address=%08lX\n", m->num, (unsigned long)m->addr); bufp += strlen(bufp); BIO_puts(l->bio, buf); l->chunks++; l->bytes += m->num; amip = m->app_info; ami_cnt = 0; if (!amip) return; CRYPTO_THREADID_cpy(&ti, &amip->threadid); do { int buf_len; int info_len; ami_cnt++; memset(buf, '>', ami_cnt); BIO_snprintf(buf + ami_cnt, sizeof buf - ami_cnt, " thread=%lu, file=%s, line=%d, info=\"", CRYPTO_THREADID_hash(&amip->threadid), amip->file, amip->line); buf_len = strlen(buf); info_len = strlen(amip->info); if (128 - buf_len - 3 < info_len) { memcpy(buf + buf_len, amip->info, 128 - buf_len - 3); buf_len = 128 - 3; } else { BUF_strlcpy(buf + buf_len, amip->info, sizeof buf - buf_len); buf_len = strlen(buf); } BIO_snprintf(buf + buf_len, sizeof buf - buf_len, "\"\n"); BIO_puts(l->bio, buf); amip = amip->next; } while (amip && !CRYPTO_THREADID_cmp(&amip->threadid, &ti)); #ifdef LEVITTE_DEBUG_MEM if (amip) { fprintf(stderr, "Thread switch detected in backtrace!!!!\n"); abort(); } #endif }
['static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l)\n{\n char buf[1024];\n char *bufp = buf;\n APP_INFO *amip;\n int ami_cnt;\n struct tm *lcl = NULL;\n CRYPTO_THREADID ti;\n#define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf))\n if (m->addr == (char *)l->bio) {\n l->seen = 1;\n return;\n }\n if (options & V_CRYPTO_MDEBUG_TIME) {\n lcl = localtime(&m->time);\n BIO_snprintf(bufp, BUF_REMAIN, "[%02d:%02d:%02d] ",\n lcl->tm_hour, lcl->tm_min, lcl->tm_sec);\n bufp += strlen(bufp);\n }\n BIO_snprintf(bufp, BUF_REMAIN, "%5lu file=%s, line=%d, ",\n m->order, m->file, m->line);\n bufp += strlen(bufp);\n if (options & V_CRYPTO_MDEBUG_THREAD) {\n BIO_snprintf(bufp, BUF_REMAIN, "thread=%lu, ",\n CRYPTO_THREADID_hash(&m->threadid));\n bufp += strlen(bufp);\n }\n BIO_snprintf(bufp, BUF_REMAIN, "number=%d, address=%08lX\\n",\n m->num, (unsigned long)m->addr);\n bufp += strlen(bufp);\n BIO_puts(l->bio, buf);\n l->chunks++;\n l->bytes += m->num;\n amip = m->app_info;\n ami_cnt = 0;\n if (!amip)\n return;\n CRYPTO_THREADID_cpy(&ti, &amip->threadid);\n do {\n int buf_len;\n int info_len;\n ami_cnt++;\n memset(buf, \'>\', ami_cnt);\n BIO_snprintf(buf + ami_cnt, sizeof buf - ami_cnt,\n " thread=%lu, file=%s, line=%d, info=\\"",\n CRYPTO_THREADID_hash(&amip->threadid), amip->file,\n amip->line);\n buf_len = strlen(buf);\n info_len = strlen(amip->info);\n if (128 - buf_len - 3 < info_len) {\n memcpy(buf + buf_len, amip->info, 128 - buf_len - 3);\n buf_len = 128 - 3;\n } else {\n BUF_strlcpy(buf + buf_len, amip->info, sizeof buf - buf_len);\n buf_len = strlen(buf);\n }\n BIO_snprintf(buf + buf_len, sizeof buf - buf_len, "\\"\\n");\n BIO_puts(l->bio, buf);\n amip = amip->next;\n }\n while (amip && !CRYPTO_THREADID_cmp(&amip->threadid, &ti));\n#ifdef LEVITTE_DEBUG_MEM\n if (amip) {\n fprintf(stderr, "Thread switch detected in backtrace!!!!\\n");\n abort();\n }\n#endif\n}']
2,564
0
https://github.com/openssl/openssl/blob/c15e95a61dacfc326cf9cdf05935ae8c6c97bcf6/crypto/lhash/lhash.c/#L208
void *lh_delete(_LHASH *lh, const 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); }
['static int state_machine(SSL *s, int server)\n{\n BUF_MEM *buf = NULL;\n unsigned long Time = (unsigned long)time(NULL);\n void (*cb) (const SSL *ssl, int type, int val) = NULL;\n OSSL_STATEM *st = &s->statem;\n int ret = -1;\n int ssret;\n if (st->state == MSG_FLOW_ERROR) {\n return -1;\n }\n RAND_add(&Time, sizeof(Time), 0);\n ERR_clear_error();\n clear_sys_error();\n cb = get_callback(s);\n st->in_handshake++;\n if (!SSL_in_init(s) || SSL_in_before(s)) {\n if (!SSL_clear(s))\n return -1;\n }\n#ifndef OPENSSL_NO_SCTP\n if (SSL_IS_DTLS(s)) {\n BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE,\n st->in_handshake, NULL);\n }\n#endif\n#ifndef OPENSSL_NO_HEARTBEATS\n if (s->tlsext_hb_pending) {\n if (SSL_IS_DTLS(s))\n dtls1_stop_timer(s);\n s->tlsext_hb_pending = 0;\n s->tlsext_hb_seq++;\n }\n#endif\n if (st->state == MSG_FLOW_RENEGOTIATE) {\n s->renegotiate = 1;\n if (!server)\n s->ctx->stats.sess_connect_renegotiate++;\n }\n if (st->state == MSG_FLOW_UNINITED || st->state == MSG_FLOW_RENEGOTIATE) {\n if (st->state == MSG_FLOW_UNINITED) {\n st->hand_state = TLS_ST_BEFORE;\n }\n s->server = server;\n if (cb != NULL)\n cb(s, SSL_CB_HANDSHAKE_START, 1);\n if (SSL_IS_DTLS(s)) {\n if ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00) &&\n (server\n || (s->version & 0xff00) != (DTLS1_BAD_VER & 0xff00))) {\n SSLerr(SSL_F_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n goto end;\n }\n } else {\n if ((s->version >> 8) != SSL3_VERSION_MAJOR) {\n SSLerr(SSL_F_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n goto end;\n }\n }\n if (!ssl_security(s, SSL_SECOP_VERSION, 0, s->version, NULL)) {\n SSLerr(SSL_F_STATE_MACHINE, SSL_R_VERSION_TOO_LOW);\n goto end;\n }\n if (s->init_buf == NULL) {\n if ((buf = BUF_MEM_new()) == NULL) {\n goto end;\n }\n if (!BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {\n goto end;\n }\n s->init_buf = buf;\n buf = NULL;\n }\n if (!ssl3_setup_buffers(s)) {\n goto end;\n }\n s->init_num = 0;\n s->s3->change_cipher_spec = 0;\n if (!server || st->state != MSG_FLOW_RENEGOTIATE) {\n#ifndef OPENSSL_NO_SCTP\n if (!SSL_IS_DTLS(s) || !BIO_dgram_is_sctp(SSL_get_wbio(s)))\n#endif\n if (!ssl_init_wbio_buffer(s, server ? 1 : 0)) {\n goto end;\n }\n ssl3_init_finished_mac(s);\n }\n if (server) {\n if (st->state != MSG_FLOW_RENEGOTIATE) {\n s->ctx->stats.sess_accept++;\n } else if (!s->s3->send_connection_binding &&\n !(s->options &\n SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)) {\n SSLerr(SSL_F_STATE_MACHINE,\n SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);\n ossl_statem_set_error(s);\n goto end;\n } else {\n s->ctx->stats.sess_accept_renegotiate++;\n }\n } else {\n s->ctx->stats.sess_connect++;\n memset(s->s3->client_random, 0, sizeof(s->s3->client_random));\n s->hit = 0;\n s->s3->tmp.cert_request = 0;\n if (SSL_IS_DTLS(s)) {\n st->use_timer = 1;\n }\n }\n st->state = MSG_FLOW_WRITING;\n init_write_state_machine(s);\n st->read_state_first_init = 1;\n }\n while(st->state != MSG_FLOW_FINISHED) {\n if(st->state == MSG_FLOW_READING) {\n ssret = read_state_machine(s);\n if (ssret == SUB_STATE_FINISHED) {\n st->state = MSG_FLOW_WRITING;\n init_write_state_machine(s);\n } else {\n goto end;\n }\n } else if (st->state == MSG_FLOW_WRITING) {\n ssret = write_state_machine(s);\n if (ssret == SUB_STATE_FINISHED) {\n st->state = MSG_FLOW_READING;\n init_read_state_machine(s);\n } else if (ssret == SUB_STATE_END_HANDSHAKE) {\n st->state = MSG_FLOW_FINISHED;\n } else {\n goto end;\n }\n } else {\n ossl_statem_set_error(s);\n goto end;\n }\n }\n st->state = MSG_FLOW_UNINITED;\n ret = 1;\n end:\n st->in_handshake--;\n#ifndef OPENSSL_NO_SCTP\n if (SSL_IS_DTLS(s)) {\n BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE,\n st->in_handshake, NULL);\n }\n#endif\n BUF_MEM_free(buf);\n if (cb != NULL) {\n if (server)\n cb(s, SSL_CB_ACCEPT_EXIT, ret);\n else\n cb(s, SSL_CB_CONNECT_EXIT, ret);\n }\n return ret;\n}', 'int ssl3_send_alert(SSL *s, int level, int desc)\n{\n desc = s->method->ssl3_enc->alert_value(desc);\n if (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n desc = SSL_AD_HANDSHAKE_FAILURE;\n if (desc < 0)\n return -1;\n if ((level == SSL3_AL_FATAL) && (s->session != NULL))\n SSL_CTX_remove_session(s->ctx, s->session);\n s->s3->alert_dispatch = 1;\n s->s3->send_alert[0] = level;\n s->s3->send_alert[1] = desc;\n if (!RECORD_LAYER_write_pending(&s->rlayer)) {\n return s->method->ssl_dispatch_alert(s);\n }\n return -1;\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\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 if (lck)\n CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n if (ret) {\n r->not_resumable = 1;\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, r);\n SSL_SESSION_free(r);\n }\n } else\n ret = 0;\n return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *lh_delete(_LHASH *lh, const void *data)\n{\n unsigned long hash;\n LHASH_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}']
2,565
0
https://github.com/libav/libav/blob/a20639017bfca0490bb1799575714f22bf470b4f/libavcodec/ps.c/#L1041
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}']
2,566
0
https://github.com/openssl/openssl/blob/1f9d203dac62f7426f6ff1fbc819e3de8b6f1171/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 test_tlsafile(SSL_CTX *ctx, const char *base_name,\n BIO *f, const char *path)\n{\n char *line;\n int testno = 0;\n int ret = 1;\n SSL *ssl;\n while (ret > 0 && (line = read_to_eol(f)) != NULL) {\n STACK_OF(X509) *chain;\n int ntlsa;\n int ncert;\n int noncheck;\n int want;\n int want_depth;\n int off;\n int i;\n int ok;\n int err;\n int mdpth;\n if (*line == \'\\0\' || *line == \'#\')\n continue;\n ++testno;\n if (sscanf(line, "%d %d %d %d %d%n",\n &ntlsa, &ncert, &noncheck, &want, &want_depth, &off) != 5\n || !allws(line + off)) {\n TEST_error("Malformed line for test %d", testno);\n return 0;\n }\n if (!TEST_ptr(ssl = SSL_new(ctx)))\n return 0;\n SSL_set_connect_state(ssl);\n if (SSL_dane_enable(ssl, base_name) <= 0) {\n SSL_free(ssl);\n return 0;\n }\n if (noncheck)\n SSL_dane_set_flags(ssl, DANE_FLAG_NO_DANE_EE_NAMECHECKS);\n for (i = 0; i < ntlsa; ++i) {\n if ((line = read_to_eol(f)) == NULL || !tlsa_import_rr(ssl, line)) {\n SSL_free(ssl);\n return 0;\n }\n }\n ERR_clear_error();\n if (!TEST_ptr(chain = load_chain(f, ncert))) {\n SSL_free(ssl);\n return 0;\n }\n ok = verify_chain(ssl, chain);\n sk_X509_pop_free(chain, X509_free);\n err = SSL_get_verify_result(ssl);\n SSL_set_verify_result(ssl, X509_V_OK);\n mdpth = SSL_get0_dane_authority(ssl, NULL, NULL);\n SSL_set_verify_result(ssl, err);\n SSL_free(ssl);\n if (!TEST_int_eq(err, want)) {\n if (want == X509_V_OK)\n TEST_info("Verification failure in test %d: %d=%s",\n testno, err, X509_verify_cert_error_string(err));\n else\n TEST_info("Unexpected error in test %d", testno);\n ret = 0;\n continue;\n }\n if (!TEST_false(want == 0 && ok == 0)) {\n TEST_info("Verification failure in test %d: ok=0", testno);\n ret = 0;\n continue;\n }\n if (!TEST_int_eq(mdpth, want_depth)) {\n TEST_info("In test test %d", testno);\n ret = 0;\n }\n }\n ERR_clear_error();\n return ret;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return (NULL);\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return (NULL);\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->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}']
2,567
0
https://github.com/openssl/openssl/blob/3216f9605c19e835900645ad97064b02f27f77be/test/testutil/tests.c/#L792
int test_BN_abs_eq_word(const char *file, int line, const char *bns, const char *ws, const BIGNUM *a, BN_ULONG w) { BIGNUM *bw, *aa; if (a != NULL && BN_abs_is_word(a, w)) return 1; bw = BN_new(); aa = BN_dup(a); BN_set_negative(aa, 0); BN_set_word(bw, w); test_fail_bignum_message(NULL, file, line, "BIGNUM", bns, ws, "abs==", aa, bw); BN_free(bw); BN_free(aa); return 0; }
['int test_BN_abs_eq_word(const char *file, int line, const char *bns,\n const char *ws, const BIGNUM *a, BN_ULONG w)\n{\n BIGNUM *bw, *aa;\n if (a != NULL && BN_abs_is_word(a, w))\n return 1;\n bw = BN_new();\n aa = BN_dup(a);\n BN_set_negative(aa, 0);\n BN_set_word(bw, w);\n test_fail_bignum_message(NULL, file, line, "BIGNUM", bns, ws, "abs==",\n aa, bw);\n BN_free(bw);\n BN_free(aa);\n return 0;\n}', 'int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)\n{\n return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));\n}', 'BIGNUM *BN_dup(const BIGNUM *a)\n{\n BIGNUM *t;\n if (a == NULL)\n return NULL;\n bn_check_top(a);\n t = BN_get_flags(a, BN_FLG_SECURE) ? BN_secure_new() : BN_new();\n if (t == NULL)\n return NULL;\n if (!BN_copy(t, a)) {\n BN_free(t);\n return NULL;\n }\n bn_check_top(t);\n return t;\n}', 'int BN_get_flags(const BIGNUM *b, int n)\n{\n return b->flags & n;\n}', 'void BN_set_negative(BIGNUM *a, int b)\n{\n if (b && !BN_is_zero(a))\n a->neg = 1;\n else\n a->neg = 0;\n}']
2,568
0
https://github.com/openssl/openssl/blob/9f5a87fd665cb597fa1c1f4eef882d2d2f833e61/ssl/ssl_lib.c/#L4485
EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash, const EVP_MD *md) { ssl_clear_hash_ctx(hash); *hash = EVP_MD_CTX_new(); if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) { EVP_MD_CTX_free(*hash); *hash = NULL; return NULL; } return *hash; }
['EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash, const EVP_MD *md)\n{\n ssl_clear_hash_ctx(hash);\n *hash = EVP_MD_CTX_new();\n if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {\n EVP_MD_CTX_free(*hash);\n *hash = NULL;\n return NULL;\n }\n return *hash;\n}', 'void ssl_clear_hash_ctx(EVP_MD_CTX **hash)\n{\n EVP_MD_CTX_free(*hash);\n *hash = NULL;\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}', '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 if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
2,569
0
https://github.com/openssl/openssl/blob/84c15db551ce1d167b901a3bde2b21880b084384/crypto/bn/bn_lib.c/#L588
int BN_set_word(BIGNUM *a, BN_ULONG w) { int i,n; if (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0); n=sizeof(BN_ULONG)/BN_BYTES; a->neg=0; a->top=0; a->d[0]=(BN_ULONG)w&BN_MASK2; if (a->d[0] != 0) a->top=1; for (i=1; i<n; i++) { #ifndef SIXTY_FOUR_BIT w>>=BN_BITS4; w>>=BN_BITS4; #else w=0; #endif a->d[i]=(BN_ULONG)w&BN_MASK2; if (a->d[i] != 0) a->top=i+1; } return(1); }
['int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tBIGNUM Ri,*R;\n\tBN_init(&Ri);\n\tR= &(mont->RR);\n\tBN_copy(&(mont->N),mod);\n#ifdef BN_RECURSION_MONT\n\tif (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD)\n#endif\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tmont->use_word=1;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,BN_BITS2);\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.d=buf;\n\t\ttmod.top=1;\n\t\ttmod.max=mod->max;\n\t\ttmod.neg=mod->neg;\n\t\tif ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,BN_BITS2);\n\t\tif (!BN_is_zero(&Ri))\n\t\t\t{\n#if 1\n\t\t\tBN_sub_word(&Ri,1);\n#else\n\t\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBN_set_word(&Ri,BN_MASK2);\n\t\t\t}\n\t\tBN_div(&Ri,NULL,&Ri,&tmod,ctx);\n\t\tmont->n0=Ri.d[0];\n\t\tBN_free(&Ri);\n\t\t}\n#ifdef BN_RECURSION_MONT\n\telse\n\t\t{\n\t\tmont->use_word=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if 1\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,mont->ri);\n#else\n\t\tBN_lshift(R,BN_value_one(),mont->ri);\n#endif\n\t\tif ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,mont->ri);\n#if 1\n\t\tBN_sub_word(&Ri,1);\n#else\n\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\tBN_div(&(mont->Ni),NULL,&Ri,mod,ctx);\n\t\tBN_free(&Ri);\n\t\t}\n#endif\n#if 1\n\tBN_zero(&(mont->RR));\n\tBN_set_bit(&(mont->RR),mont->ri*2);\n#else\n\tBN_lshift(mont->RR,BN_value_one(),mont->ri*2);\n#endif\n\tBN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);\n\treturn(1);\nerr:\n\treturn(0);\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_lshift(BIGNUM *r, const BIGNUM *a, int n)\n\t{\n\tint i,nw,lb,rb;\n\tBN_ULONG *t,*f;\n\tBN_ULONG l;\n\tr->neg=a->neg;\n\tif (bn_wexpand(r,a->top+(n/BN_BITS2)+1) == NULL) return(0);\n\tnw=n/BN_BITS2;\n\tlb=n%BN_BITS2;\n\trb=BN_BITS2-lb;\n\tf=a->d;\n\tt=r->d;\n\tt[a->top+nw]=0;\n\tif (lb == 0)\n\t\tfor (i=a->top-1; i>=0; i--)\n\t\t\tt[nw+i]=f[i];\n\telse\n\t\tfor (i=a->top-1; i>=0; i--)\n\t\t\t{\n\t\t\tl=f[i];\n\t\t\tt[nw+i+1]|=(l>>rb)&BN_MASK2;\n\t\t\tt[nw+i]=(l<<lb)&BN_MASK2;\n\t\t\t}\n\tmemset(t,0,nw*sizeof(t[0]));\n\tr->top=a->top+nw+1;\n\tbn_fix_top(r);\n\treturn(1);\n\t}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n\t{\n\tint i,n;\n\tif (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);\n\tn=sizeof(BN_ULONG)/BN_BYTES;\n\ta->neg=0;\n\ta->top=0;\n\ta->d[0]=(BN_ULONG)w&BN_MASK2;\n\tif (a->d[0] != 0) a->top=1;\n\tfor (i=1; i<n; i++)\n\t\t{\n#ifndef SIXTY_FOUR_BIT\n\t\tw>>=BN_BITS4;\n\t\tw>>=BN_BITS4;\n#else\n\t\tw=0;\n#endif\n\t\ta->d[i]=(BN_ULONG)w&BN_MASK2;\n\t\tif (a->d[i] != 0) a->top=i+1;\n\t\t}\n\treturn(1);\n\t}']
2,570
0
https://github.com/libav/libav/blob/9b75ae05cf1554238bb103b3c3304dcba0bbc6cf/libavcodec/mjpegdec.c/#L865
static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, int Al, const uint8_t *mb_bitmask, const AVFrame *reference) { int i, mb_x, mb_y; uint8_t *data[MAX_COMPONENTS]; const uint8_t *reference_data[MAX_COMPONENTS]; int linesize[MAX_COMPONENTS]; GetBitContext mb_bitmask_gb; if (mb_bitmask) init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width * s->mb_height); if (s->flipped && s->avctx->flags & CODEC_FLAG_EMU_EDGE) { av_log(s->avctx, AV_LOG_ERROR, "Can not flip image with CODEC_FLAG_EMU_EDGE set!\n"); s->flipped = 0; } for (i = 0; i < nb_components; i++) { int c = s->comp_index[i]; data[c] = s->picture_ptr->data[c]; reference_data[c] = reference ? reference->data[c] : NULL; linesize[c] = s->linesize[c]; s->coefs_finished[c] |= 1; if (s->flipped) { int offset = (linesize[c] * (s->v_scount[i] * (8 * s->mb_height - ((s->height / s->v_max) & 7)) - 1)); data[c] += offset; reference_data[c] += offset; linesize[c] *= -1; } } for (mb_y = 0; mb_y < s->mb_height; mb_y++) { for (mb_x = 0; mb_x < s->mb_width; mb_x++) { const int copy_mb = mb_bitmask && !get_bits1(&mb_bitmask_gb); if (s->restart_interval && !s->restart_count) s->restart_count = s->restart_interval; if (get_bits_left(&s->gb) < 0) { av_log(s->avctx, AV_LOG_ERROR, "overread %d\n", -get_bits_left(&s->gb)); return -1; } for (i = 0; i < nb_components; i++) { uint8_t *ptr; int n, h, v, x, y, c, j; int block_offset; n = s->nb_blocks[i]; c = s->comp_index[i]; h = s->h_scount[i]; v = s->v_scount[i]; x = 0; y = 0; for (j = 0; j < n; j++) { block_offset = ((linesize[c] * (v * mb_y + y) * 8) + (h * mb_x + x) * 8); if (s->interlaced && s->bottom_field) block_offset += linesize[c] >> 1; ptr = data[c] + block_offset; if (!s->progressive) { if (copy_mb) copy_block8(ptr, reference_data[c] + block_offset, linesize[c], linesize[c], 8); else { s->dsp.clear_block(s->block); if (decode_block(s, s->block, i, s->dc_index[i], s->ac_index[i], s->quant_matrixes[s->quant_index[c]]) < 0) { av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x); return -1; } s->dsp.idct_put(ptr, linesize[c], s->block); } } else { int block_idx = s->block_stride[c] * (v * mb_y + y) + (h * mb_x + x); DCTELEM *block = s->blocks[c][block_idx]; if (Ah) block[0] += get_bits1(&s->gb) * s->quant_matrixes[s->quant_index[c]][0] << Al; else if (decode_dc_progressive(s, block, i, s->dc_index[i], s->quant_matrixes[s->quant_index[c]], Al) < 0) { av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x); return -1; } } if (++x == h) { x = 0; y++; } } } if (s->restart_interval) { s->restart_count--; i = 8 + ((-get_bits_count(&s->gb)) & 7); if (show_bits(&s->gb, i) == (1 << i) - 1) { int pos = get_bits_count(&s->gb); align_get_bits(&s->gb); while (get_bits_left(&s->gb) >= 8 && show_bits(&s->gb, 8) == 0xFF) skip_bits(&s->gb, 8); if ((get_bits(&s->gb, 8) & 0xF8) == 0xD0) { for (i = 0; i < nb_components; i++) s->last_dc[i] = 1024; } else skip_bits_long(&s->gb, pos - get_bits_count(&s->gb)); } } } } return 0; }
['static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah,\n int Al, const uint8_t *mb_bitmask,\n const AVFrame *reference)\n{\n int i, mb_x, mb_y;\n uint8_t *data[MAX_COMPONENTS];\n const uint8_t *reference_data[MAX_COMPONENTS];\n int linesize[MAX_COMPONENTS];\n GetBitContext mb_bitmask_gb;\n if (mb_bitmask)\n init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width * s->mb_height);\n if (s->flipped && s->avctx->flags & CODEC_FLAG_EMU_EDGE) {\n av_log(s->avctx, AV_LOG_ERROR,\n "Can not flip image with CODEC_FLAG_EMU_EDGE set!\\n");\n s->flipped = 0;\n }\n for (i = 0; i < nb_components; i++) {\n int c = s->comp_index[i];\n data[c] = s->picture_ptr->data[c];\n reference_data[c] = reference ? reference->data[c] : NULL;\n linesize[c] = s->linesize[c];\n s->coefs_finished[c] |= 1;\n if (s->flipped) {\n int offset = (linesize[c] * (s->v_scount[i] *\n (8 * s->mb_height - ((s->height / s->v_max) & 7)) - 1));\n data[c] += offset;\n reference_data[c] += offset;\n linesize[c] *= -1;\n }\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 copy_mb = mb_bitmask && !get_bits1(&mb_bitmask_gb);\n if (s->restart_interval && !s->restart_count)\n s->restart_count = s->restart_interval;\n if (get_bits_left(&s->gb) < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "overread %d\\n",\n -get_bits_left(&s->gb));\n return -1;\n }\n for (i = 0; i < nb_components; i++) {\n uint8_t *ptr;\n int n, h, v, x, y, c, j;\n int block_offset;\n n = s->nb_blocks[i];\n c = s->comp_index[i];\n h = s->h_scount[i];\n v = s->v_scount[i];\n x = 0;\n y = 0;\n for (j = 0; j < n; j++) {\n block_offset = ((linesize[c] * (v * mb_y + y) * 8) +\n (h * mb_x + x) * 8);\n if (s->interlaced && s->bottom_field)\n block_offset += linesize[c] >> 1;\n ptr = data[c] + block_offset;\n if (!s->progressive) {\n if (copy_mb)\n copy_block8(ptr, reference_data[c] + block_offset,\n linesize[c], linesize[c], 8);\n else {\n s->dsp.clear_block(s->block);\n if (decode_block(s, s->block, i,\n s->dc_index[i], s->ac_index[i],\n s->quant_matrixes[s->quant_index[c]]) < 0) {\n av_log(s->avctx, AV_LOG_ERROR,\n "error y=%d x=%d\\n", mb_y, mb_x);\n return -1;\n }\n s->dsp.idct_put(ptr, linesize[c], s->block);\n }\n } else {\n int block_idx = s->block_stride[c] * (v * mb_y + y) +\n (h * mb_x + x);\n DCTELEM *block = s->blocks[c][block_idx];\n if (Ah)\n block[0] += get_bits1(&s->gb) *\n s->quant_matrixes[s->quant_index[c]][0] << Al;\n else if (decode_dc_progressive(s, block, i, s->dc_index[i],\n s->quant_matrixes[s->quant_index[c]],\n Al) < 0) {\n av_log(s->avctx, AV_LOG_ERROR,\n "error y=%d x=%d\\n", mb_y, mb_x);\n return -1;\n }\n }\n if (++x == h) {\n x = 0;\n y++;\n }\n }\n }\n if (s->restart_interval) {\n s->restart_count--;\n i = 8 + ((-get_bits_count(&s->gb)) & 7);\n if (show_bits(&s->gb, i) == (1 << i) - 1) {\n int pos = get_bits_count(&s->gb);\n align_get_bits(&s->gb);\n while (get_bits_left(&s->gb) >= 8 && show_bits(&s->gb, 8) == 0xFF)\n skip_bits(&s->gb, 8);\n if ((get_bits(&s->gb, 8) & 0xF8) == 0xD0) {\n for (i = 0; i < nb_components; i++)\n s->last_dc[i] = 1024;\n } else\n skip_bits_long(&s->gb, pos - get_bits_count(&s->gb));\n }\n }\n }\n }\n return 0;\n}']
2,571
0
https://github.com/openssl/openssl/blob/ddc6a5c8f5900959bdbdfee79e1625a3f7808acd/crypto/rand/drbg_rand.c/#L283
int ctr_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen, const unsigned char *adin, size_t adinlen) { RAND_DRBG_CTR *ctr = &drbg->ctr; if (adin != NULL && adinlen != 0) { ctr_update(drbg, adin, adinlen, NULL, 0, NULL, 0); if (drbg->flags & RAND_DRBG_FLAG_CTR_USE_DF) { adin = NULL; adinlen = 1; } } else { adinlen = 0; } for ( ; ; ) { inc_128(ctr); if (outlen < 16) { AES_encrypt(ctr->V, ctr->K, &ctr->ks); memcpy(out, ctr->K, outlen); break; } AES_encrypt(ctr->V, out, &ctr->ks); out += 16; outlen -= 16; if (outlen == 0) break; } ctr_update(drbg, adin, adinlen, NULL, 0, NULL, 0); return 1; }
['int SSL_srp_server_param_with_username(SSL *s, int *ad)\n{\n unsigned char b[SSL_MAX_MASTER_KEY_LENGTH];\n int al;\n *ad = SSL_AD_UNKNOWN_PSK_IDENTITY;\n if ((s->srp_ctx.TLS_ext_srp_username_callback != NULL) &&\n ((al =\n s->srp_ctx.TLS_ext_srp_username_callback(s, ad,\n s->srp_ctx.SRP_cb_arg)) !=\n SSL_ERROR_NONE))\n return al;\n *ad = SSL_AD_INTERNAL_ERROR;\n if ((s->srp_ctx.N == NULL) ||\n (s->srp_ctx.g == NULL) ||\n (s->srp_ctx.s == NULL) || (s->srp_ctx.v == NULL))\n return SSL3_AL_FATAL;\n if (ssl_randbytes(s, b, sizeof(b)) <= 0)\n return SSL3_AL_FATAL;\n s->srp_ctx.b = BN_bin2bn(b, sizeof(b), NULL);\n OPENSSL_cleanse(b, sizeof(b));\n return ((s->srp_ctx.B =\n SRP_Calc_B(s->srp_ctx.b, s->srp_ctx.N, s->srp_ctx.g,\n s->srp_ctx.v)) !=\n NULL) ? SSL_ERROR_NONE : SSL3_AL_FATAL;\n}', 'int ssl_randbytes(SSL *s, unsigned char *rnd, size_t size)\n{\n if (s->drbg != NULL)\n return RAND_DRBG_generate(s->drbg, rnd, size, 0, NULL, 0);\n return RAND_bytes(rnd, (int)size);\n}', 'int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,\n int prediction_resistance,\n const unsigned char *adin, size_t adinlen)\n{\n if (drbg->state == DRBG_ERROR) {\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_IN_ERROR_STATE);\n return 0;\n }\n if (drbg->state == DRBG_UNINITIALISED) {\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_NOT_INSTANTIATED);\n return 0;\n }\n if (outlen > drbg->max_request) {\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_REQUEST_TOO_LARGE_FOR_DRBG);\n return 0;\n }\n if (adinlen > drbg->max_adin) {\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_ADDITIONAL_INPUT_TOO_LONG);\n return 0;\n }\n if (drbg->reseed_counter >= drbg->reseed_interval)\n drbg->state = DRBG_RESEED;\n if (drbg->state == DRBG_RESEED || prediction_resistance) {\n if (!RAND_DRBG_reseed(drbg, adin, adinlen)) {\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_RESEED_ERROR);\n return 0;\n }\n adin = NULL;\n adinlen = 0;\n }\n if (!ctr_generate(drbg, out, outlen, adin, adinlen)) {\n drbg->state = DRBG_ERROR;\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_GENERATE_ERROR);\n return 0;\n }\n if (drbg->reseed_counter >= drbg->reseed_interval)\n drbg->state = DRBG_RESEED;\n else\n drbg->reseed_counter++;\n return 1;\n}', 'int ctr_generate(RAND_DRBG *drbg,\n unsigned char *out, size_t outlen,\n const unsigned char *adin, size_t adinlen)\n{\n RAND_DRBG_CTR *ctr = &drbg->ctr;\n if (adin != NULL && adinlen != 0) {\n ctr_update(drbg, adin, adinlen, NULL, 0, NULL, 0);\n if (drbg->flags & RAND_DRBG_FLAG_CTR_USE_DF) {\n adin = NULL;\n adinlen = 1;\n }\n } else {\n adinlen = 0;\n }\n for ( ; ; ) {\n inc_128(ctr);\n if (outlen < 16) {\n AES_encrypt(ctr->V, ctr->K, &ctr->ks);\n memcpy(out, ctr->K, outlen);\n break;\n }\n AES_encrypt(ctr->V, out, &ctr->ks);\n out += 16;\n outlen -= 16;\n if (outlen == 0)\n break;\n }\n ctr_update(drbg, adin, adinlen, NULL, 0, NULL, 0);\n return 1;\n}']
2,572
0
https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/test/bntest.c/#L1733
int test_kron(BIO *bp, BN_CTX *ctx) { BN_GENCB cb; BIGNUM *a, *b, *r, *t; int i; int legendre, kronecker; int ret = 0; a = BN_new(); b = BN_new(); r = BN_new(); t = BN_new(); if (a == NULL || b == NULL || r == NULL || t == NULL) goto err; BN_GENCB_set(&cb, genprime_cb, NULL); if (!BN_generate_prime_ex(b, 512, 0, NULL, NULL, &cb)) goto err; b->neg = rand_neg(); putc('\n', stderr); for (i = 0; i < num0; i++) { if (!BN_bntest_rand(a, 512, 0, 0)) goto err; a->neg = rand_neg(); if (!BN_copy(t, b)) goto err; t->neg = 0; if (!BN_sub_word(t, 1)) goto err; if (!BN_rshift1(t, t)) goto err; b->neg = 0; if (!BN_mod_exp_recp(r, a, t, b, ctx)) goto err; b->neg = 1; if (BN_is_word(r, 1)) legendre = 1; else if (BN_is_zero(r)) legendre = 0; else { if (!BN_add_word(r, 1)) goto err; if (0 != BN_ucmp(r, b)) { fprintf(stderr, "Legendre symbol computation failed\n"); goto err; } legendre = -1; } kronecker = BN_kronecker(a, b, ctx); if (kronecker < -1) goto err; if (a->neg && b->neg) kronecker = -kronecker; if (legendre != kronecker) { fprintf(stderr, "legendre != kronecker; a = "); BN_print_fp(stderr, a); fprintf(stderr, ", b = "); BN_print_fp(stderr, b); fprintf(stderr, "\n"); goto err; } putc('.', stderr); fflush(stderr); } putc('\n', stderr); fflush(stderr); ret = 1; err: BN_free(a); BN_free(b); BN_free(r); BN_free(t); return ret; }
['int test_kron(BIO *bp, BN_CTX *ctx)\n{\n BN_GENCB cb;\n BIGNUM *a, *b, *r, *t;\n int i;\n int legendre, kronecker;\n int ret = 0;\n a = BN_new();\n b = BN_new();\n r = BN_new();\n t = BN_new();\n if (a == NULL || b == NULL || r == NULL || t == NULL)\n goto err;\n BN_GENCB_set(&cb, genprime_cb, NULL);\n if (!BN_generate_prime_ex(b, 512, 0, NULL, NULL, &cb))\n goto err;\n b->neg = rand_neg();\n putc(\'\\n\', stderr);\n for (i = 0; i < num0; i++) {\n if (!BN_bntest_rand(a, 512, 0, 0))\n goto err;\n a->neg = rand_neg();\n if (!BN_copy(t, b))\n goto err;\n t->neg = 0;\n if (!BN_sub_word(t, 1))\n goto err;\n if (!BN_rshift1(t, t))\n goto err;\n b->neg = 0;\n if (!BN_mod_exp_recp(r, a, t, b, ctx))\n goto err;\n b->neg = 1;\n if (BN_is_word(r, 1))\n legendre = 1;\n else if (BN_is_zero(r))\n legendre = 0;\n else {\n if (!BN_add_word(r, 1))\n goto err;\n if (0 != BN_ucmp(r, b)) {\n fprintf(stderr, "Legendre symbol computation failed\\n");\n goto err;\n }\n legendre = -1;\n }\n kronecker = BN_kronecker(a, b, ctx);\n if (kronecker < -1)\n goto err;\n if (a->neg && b->neg)\n kronecker = -kronecker;\n if (legendre != kronecker) {\n fprintf(stderr, "legendre != kronecker; a = ");\n BN_print_fp(stderr, a);\n fprintf(stderr, ", b = ");\n BN_print_fp(stderr, b);\n fprintf(stderr, "\\n");\n goto err;\n }\n putc(\'.\', stderr);\n fflush(stderr);\n }\n putc(\'\\n\', stderr);\n fflush(stderr);\n ret = 1;\n err:\n BN_free(a);\n BN_free(b);\n BN_free(r);\n BN_free(t);\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}', 'void BN_GENCB_set(BN_GENCB *gencb, int (*callback) (int, int, BN_GENCB *),\n void *cb_arg)\n{\n BN_GENCB *tmp_gencb = gencb;\n tmp_gencb->ver = 2;\n tmp_gencb->arg = cb_arg;\n tmp_gencb->cb.cb_2 = callback;\n}', 'void BN_free(BIGNUM *a)\n{\n if (a == NULL)\n return;\n bn_check_top(a);\n if (!BN_get_flags(a, BN_FLG_STATIC_DATA))\n bn_free_d(a);\n if (a->flags & BN_FLG_MALLOCED)\n OPENSSL_free(a);\n else {\n#if OPENSSL_API_COMPAT < 0x00908000L\n a->flags |= BN_FLG_FREE;\n#endif\n a->d = NULL;\n }\n}', 'int BN_get_flags(const BIGNUM *b, int n)\n{\n return b->flags & n;\n}']
2,573
0
https://github.com/openssl/openssl/blob/0ca6d7c6b1e73d17ca67b7ffd8435bde43bf50af/ssl/ssl_cert.c/#L717
int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, const char *dir) { DIR *d; struct dirent *dstruct; int ret = 0; CRYPTO_w_lock(CRYPTO_LOCK_READDIR); d = opendir(dir); if(!d) { SYSerr(SYS_F_OPENDIR, get_last_sys_error()); ERR_add_error_data(3, "opendir('", dir, "')"); SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB); goto err; } while((dstruct=readdir(d))) { char buf[1024]; if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf) { SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG); goto err; } sprintf(buf,"%s/%s",dir,dstruct->d_name); if(!SSL_add_file_cert_subjects_to_stack(stack,buf)) goto err; } ret = 1; err: CRYPTO_w_unlock(CRYPTO_LOCK_READDIR); return ret; }
['int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,\n\t\t\t\t const char *dir)\n {\n DIR *d;\n struct dirent *dstruct;\n int ret = 0;\n CRYPTO_w_lock(CRYPTO_LOCK_READDIR);\n d = opendir(dir);\n if(!d)\n\t{\n\tSYSerr(SYS_F_OPENDIR, get_last_sys_error());\n\tERR_add_error_data(3, "opendir(\'", dir, "\')");\n\tSSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);\n\tgoto err;\n\t}\n while((dstruct=readdir(d)))\n\t{\n\tchar buf[1024];\n\tif(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)\n\t {\n\t SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);\n\t goto err;\n\t }\n\tsprintf(buf,"%s/%s",dir,dstruct->d_name);\n\tif(!SSL_add_file_cert_subjects_to_stack(stack,buf))\n\t goto err;\n\t}\n ret = 1;\nerr:\n CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);\n return ret;\n }', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n\t{\n#ifdef LOCK_DEBUG\n\t\t{\n\t\tchar *rw_text,*operation_text;\n\t\tif (mode & CRYPTO_LOCK)\n\t\t\toperation_text="lock ";\n\t\telse if (mode & CRYPTO_UNLOCK)\n\t\t\toperation_text="unlock";\n\t\telse\n\t\t\toperation_text="ERROR ";\n\t\tif (mode & CRYPTO_READ)\n\t\t\trw_text="r";\n\t\telse if (mode & CRYPTO_WRITE)\n\t\t\trw_text="w";\n\t\telse\n\t\t\trw_text="ERROR";\n\t\tfprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\\n",\n\t\t\tCRYPTO_thread_id(), rw_text, operation_text,\n\t\t\tCRYPTO_get_lock_name(type), file, line);\n\t\t}\n#endif\n\tif (locking_callback != NULL)\n\t\tlocking_callback(mode,type,file,line);\n\t}']
2,574
0
https://github.com/openssl/openssl/blob/2864df8f9d3264e19b49a246e272fb513f4c1be3/crypto/bn/bn_ctx.c/#L270
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,\n const BIGNUM *v)\n{\n BIGNUM *kv = NULL, *gb = NULL;\n BIGNUM *B = NULL, *k = NULL;\n BN_CTX *bn_ctx;\n if (b == NULL || N == NULL || g == NULL || v == NULL ||\n (bn_ctx = BN_CTX_new()) == NULL)\n return NULL;\n if ((kv = BN_new()) == NULL ||\n (gb = BN_new()) == NULL || (B = BN_new()) == NULL)\n goto err;\n if (!BN_mod_exp(gb, g, b, N, bn_ctx)\n || (k = srp_Calc_k(N, g)) == NULL\n || !BN_mod_mul(kv, v, k, N, bn_ctx)\n || !BN_mod_add(B, gb, kv, N, bn_ctx)) {\n BN_free(B);\n B = NULL;\n }\n err:\n BN_CTX_free(bn_ctx);\n BN_clear_free(kv);\n BN_clear_free(gb);\n BN_free(k);\n return B;\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_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 || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, 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_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 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}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int BN_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_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,\n BN_RECP_CTX *recp, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *a;\n const BIGNUM *ca;\n BN_CTX_start(ctx);\n if ((a = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (y != NULL) {\n if (x == y) {\n if (!BN_sqr(a, x, ctx))\n goto err;\n } else {\n if (!BN_mul(a, x, y, ctx))\n goto err;\n }\n ca = a;\n } else\n ca = x;\n ret = BN_div_recp(NULL, r, ca, recp, ctx);\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return ret;\n}', 'int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,\n BN_RECP_CTX *recp, BN_CTX *ctx)\n{\n int i, j, ret = 0;\n BIGNUM *a, *b, *d, *r;\n BN_CTX_start(ctx);\n d = (dv != NULL) ? dv : BN_CTX_get(ctx);\n r = (rem != NULL) ? rem : BN_CTX_get(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (b == NULL)\n goto err;\n if (BN_ucmp(m, &(recp->N)) < 0) {\n BN_zero(d);\n if (!BN_copy(r, m)) {\n BN_CTX_end(ctx);\n return 0;\n }\n BN_CTX_end(ctx);\n return 1;\n }\n i = BN_num_bits(m);\n j = recp->num_bits << 1;\n if (j > i)\n i = j;\n if (i != recp->shift)\n recp->shift = BN_reciprocal(&(recp->Nr), &(recp->N), i, ctx);\n if (recp->shift == -1)\n goto err;\n if (!BN_rshift(a, m, recp->num_bits))\n goto err;\n if (!BN_mul(b, a, &(recp->Nr), ctx))\n goto err;\n if (!BN_rshift(d, b, i - recp->num_bits))\n goto err;\n d->neg = 0;\n if (!BN_mul(b, &(recp->N), d, ctx))\n goto err;\n if (!BN_usub(r, m, b))\n goto err;\n r->neg = 0;\n j = 0;\n while (BN_ucmp(r, &(recp->N)) >= 0) {\n if (j++ > 2) {\n BNerr(BN_F_BN_DIV_RECP, BN_R_BAD_RECIPROCAL);\n goto err;\n }\n if (!BN_usub(r, r, &(recp->N)))\n goto err;\n if (!BN_add_word(d, 1))\n goto err;\n }\n r->neg = BN_is_zero(r) ? 0 : m->neg;\n d->neg = m->neg ^ recp->N.neg;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(dv);\n bn_check_top(rem);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
2,575
0
https://github.com/libav/libav/blob/d10102d23c9467d4eb84f58e0cd12be284b982f6/libavformat/mxfenc.c/#L1232
static int mxf_write_partition(AVFormatContext *s, int bodysid, int indexsid, const uint8_t *key, int write_metadata) { MXFContext *mxf = s->priv_data; AVIOContext *pb = s->pb; int64_t header_byte_count_offset; unsigned index_byte_count = 0; uint64_t partition_offset = avio_tell(pb); int err; if (!mxf->edit_unit_byte_count && mxf->edit_units_count) index_byte_count = 85 + 12+(s->nb_streams+1)*6 + 12+mxf->edit_units_count*(11+mxf->slice_count*4); else if (mxf->edit_unit_byte_count && indexsid) index_byte_count = 80; if (index_byte_count) { index_byte_count += 16 + klv_ber_length(index_byte_count); index_byte_count += klv_fill_size(index_byte_count); } if (!memcmp(key, body_partition_key, 16)) { if ((err = av_reallocp_array(&mxf->body_partition_offset, mxf->body_partitions_count + 1, sizeof(*mxf->body_partition_offset))) < 0) { mxf->body_partitions_count = 0; return err; } mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset; } avio_write(pb, key, 16); klv_encode_ber_length(pb, 88 + 16LL * mxf->essence_container_count); avio_wb16(pb, 1); avio_wb16(pb, 2); avio_wb32(pb, KAG_SIZE); avio_wb64(pb, partition_offset); if (!memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1) avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]); else if (!memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count) avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]); else avio_wb64(pb, 0); avio_wb64(pb, mxf->footer_partition_offset); header_byte_count_offset = avio_tell(pb); avio_wb64(pb, 0); avio_wb64(pb, index_byte_count); avio_wb32(pb, index_byte_count ? indexsid : 0); if (bodysid && mxf->edit_units_count && mxf->body_partitions_count) { avio_wb64(pb, mxf->body_offset); } else avio_wb64(pb, 0); avio_wb32(pb, bodysid); avio_write(pb, op1a_ul, 16); mxf_write_essence_container_refs(s); if (write_metadata) { int64_t pos, start; unsigned header_byte_count; mxf_write_klv_fill(s); start = avio_tell(s->pb); mxf_write_primer_pack(s); mxf_write_header_metadata_sets(s); pos = avio_tell(s->pb); header_byte_count = pos - start + klv_fill_size(pos); avio_seek(pb, header_byte_count_offset, SEEK_SET); avio_wb64(pb, header_byte_count); avio_seek(pb, pos, SEEK_SET); } avio_flush(pb); return 0; }
['static int mxf_write_footer(AVFormatContext *s)\n{\n MXFContext *mxf = s->priv_data;\n AVIOContext *pb = s->pb;\n int err;\n mxf->duration = mxf->last_indexed_edit_unit + mxf->edit_units_count;\n mxf_write_klv_fill(s);\n mxf->footer_partition_offset = avio_tell(pb);\n if (mxf->edit_unit_byte_count) {\n if ((err = mxf_write_partition(s, 0, 0, footer_partition_key, 0)) < 0)\n return err;\n } else {\n if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 0)) < 0)\n return err;\n mxf_write_klv_fill(s);\n mxf_write_index_table_segment(s);\n }\n mxf_write_klv_fill(s);\n mxf_write_random_index_pack(s);\n if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {\n avio_seek(pb, 0, SEEK_SET);\n if (mxf->edit_unit_byte_count) {\n if ((err = mxf_write_partition(s, 1, 2, header_closed_partition_key, 1)) < 0)\n return err;\n mxf_write_klv_fill(s);\n mxf_write_index_table_segment(s);\n } else {\n if ((err = mxf_write_partition(s, 0, 0, header_closed_partition_key, 1)) < 0)\n return err;\n }\n }\n ff_audio_interleave_close(s);\n av_freep(&mxf->index_entries);\n av_freep(&mxf->body_partition_offset);\n av_freep(&mxf->timecode_track->priv_data);\n av_freep(&mxf->timecode_track);\n mxf_free(s);\n return 0;\n}', 'static int mxf_write_partition(AVFormatContext *s, int bodysid,\n int indexsid,\n const uint8_t *key, int write_metadata)\n{\n MXFContext *mxf = s->priv_data;\n AVIOContext *pb = s->pb;\n int64_t header_byte_count_offset;\n unsigned index_byte_count = 0;\n uint64_t partition_offset = avio_tell(pb);\n int err;\n if (!mxf->edit_unit_byte_count && mxf->edit_units_count)\n index_byte_count = 85 + 12+(s->nb_streams+1)*6 +\n 12+mxf->edit_units_count*(11+mxf->slice_count*4);\n else if (mxf->edit_unit_byte_count && indexsid)\n index_byte_count = 80;\n if (index_byte_count) {\n index_byte_count += 16 + klv_ber_length(index_byte_count);\n index_byte_count += klv_fill_size(index_byte_count);\n }\n if (!memcmp(key, body_partition_key, 16)) {\n if ((err = av_reallocp_array(&mxf->body_partition_offset, mxf->body_partitions_count + 1,\n sizeof(*mxf->body_partition_offset))) < 0) {\n mxf->body_partitions_count = 0;\n return err;\n }\n mxf->body_partition_offset[mxf->body_partitions_count++] = partition_offset;\n }\n avio_write(pb, key, 16);\n klv_encode_ber_length(pb, 88 + 16LL * mxf->essence_container_count);\n avio_wb16(pb, 1);\n avio_wb16(pb, 2);\n avio_wb32(pb, KAG_SIZE);\n avio_wb64(pb, partition_offset);\n if (!memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1)\n avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]);\n else if (!memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count)\n avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]);\n else\n avio_wb64(pb, 0);\n avio_wb64(pb, mxf->footer_partition_offset);\n header_byte_count_offset = avio_tell(pb);\n avio_wb64(pb, 0);\n avio_wb64(pb, index_byte_count);\n avio_wb32(pb, index_byte_count ? indexsid : 0);\n if (bodysid && mxf->edit_units_count && mxf->body_partitions_count) {\n avio_wb64(pb, mxf->body_offset);\n } else\n avio_wb64(pb, 0);\n avio_wb32(pb, bodysid);\n avio_write(pb, op1a_ul, 16);\n mxf_write_essence_container_refs(s);\n if (write_metadata) {\n int64_t pos, start;\n unsigned header_byte_count;\n mxf_write_klv_fill(s);\n start = avio_tell(s->pb);\n mxf_write_primer_pack(s);\n mxf_write_header_metadata_sets(s);\n pos = avio_tell(s->pb);\n header_byte_count = pos - start + klv_fill_size(pos);\n avio_seek(pb, header_byte_count_offset, SEEK_SET);\n avio_wb64(pb, header_byte_count);\n avio_seek(pb, pos, SEEK_SET);\n }\n avio_flush(pb);\n return 0;\n}', 'static void mxf_write_random_index_pack(AVFormatContext *s)\n{\n MXFContext *mxf = s->priv_data;\n AVIOContext *pb = s->pb;\n uint64_t pos = avio_tell(pb);\n int i;\n avio_write(pb, random_index_pack_key, 16);\n klv_encode_ber_length(pb, 28 + 12LL*mxf->body_partitions_count);\n if (mxf->edit_unit_byte_count)\n avio_wb32(pb, 1);\n else\n avio_wb32(pb, 0);\n avio_wb64(pb, 0);\n for (i = 0; i < mxf->body_partitions_count; i++) {\n avio_wb32(pb, 1);\n avio_wb64(pb, mxf->body_partition_offset[i]);\n }\n avio_wb32(pb, 0);\n avio_wb64(pb, mxf->footer_partition_offset);\n avio_wb32(pb, avio_tell(pb) - pos + 4);\n}']
2,576
0
https://github.com/libav/libav/blob/a893655bdaa726a82424367b6456d195be12ebbc/libavcodec/svq3.c/#L163
void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp) { const int qmul = svq3_dequant_coeff[qp]; #define stride 16 int i; int temp[16]; static const uint8_t x_offset[4] = { 0, 1 * stride, 4 * stride, 5 * stride }; for (i = 0; i < 4; i++) { const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]); const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]); const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3]; const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3]; temp[4 * i + 0] = z0 + z3; temp[4 * i + 1] = z1 + z2; temp[4 * i + 2] = z1 - z2; temp[4 * i + 3] = z0 - z3; } for (i = 0; i < 4; i++) { const int offset = x_offset[i]; const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]); const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]); const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i]; const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i]; output[stride * 0 + offset] = (z0 + z3) * qmul + 0x80000 >> 20; output[stride * 2 + offset] = (z1 + z2) * qmul + 0x80000 >> 20; output[stride * 8 + offset] = (z1 - z2) * qmul + 0x80000 >> 20; output[stride * 10 + offset] = (z0 - z3) * qmul + 0x80000 >> 20; } }
['void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp)\n{\n const int qmul = svq3_dequant_coeff[qp];\n#define stride 16\n int i;\n int temp[16];\n static const uint8_t x_offset[4] = { 0, 1 * stride, 4 * stride, 5 * stride };\n for (i = 0; i < 4; i++) {\n const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);\n const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);\n const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];\n const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];\n temp[4 * i + 0] = z0 + z3;\n temp[4 * i + 1] = z1 + z2;\n temp[4 * i + 2] = z1 - z2;\n temp[4 * i + 3] = z0 - z3;\n }\n for (i = 0; i < 4; i++) {\n const int offset = x_offset[i];\n const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);\n const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);\n const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];\n const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];\n output[stride * 0 + offset] = (z0 + z3) * qmul + 0x80000 >> 20;\n output[stride * 2 + offset] = (z1 + z2) * qmul + 0x80000 >> 20;\n output[stride * 8 + offset] = (z1 - z2) * qmul + 0x80000 >> 20;\n output[stride * 10 + offset] = (z0 - z3) * qmul + 0x80000 >> 20;\n }\n}']
2,577
0
https://github.com/openssl/openssl/blob/a87228031f8a4e274c2f859a2589dcef2eb7cc58/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx)\n\t{\n\tint ret= -1;\n\tBIGNUM *t;\n\tBN_CTX_start(ctx);\n\tif((t = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (!BN_set_bit(t,len)) goto err;\n\tif (!BN_div(r,NULL,t,m,ctx)) goto err;\n\tret=len;\nerr:\n\tbn_check_top(r);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', '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_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\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}']
2,578
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L368
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}']
2,579
0
https://github.com/openssl/openssl/blob/b2aea0e3d9a15e30ebce8b6da213df4a3f346155/test/handshake_helper.c/#L200
static int client_hello_select_server_ctx(SSL *s, void *arg, int ignore) { const char *servername; const unsigned char *p; size_t len, remaining; HANDSHAKE_EX_DATA *ex_data = (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx)); if (!SSL_client_hello_get0_ext(s, TLSEXT_TYPE_server_name, &p, &remaining) || remaining <= 2) return 0; len = (*(p++) << 8); len += *(p++); if (len + 2 != remaining) return 0; remaining = len; if (remaining == 0 || *p++ != TLSEXT_NAMETYPE_host_name) return 0; remaining--; if (remaining <= 2) return 0; len = (*(p++) << 8); len += *(p++); if (len + 2 > remaining) return 0; remaining = len; servername = (const char *)p; if (len == strlen("server2") && strncmp(servername, "server2", len) == 0) { SSL_CTX *new_ctx = arg; SSL_set_SSL_CTX(s, new_ctx); SSL_clear_options(s, 0xFFFFFFFFL); SSL_set_options(s, SSL_CTX_get_options(new_ctx)); ex_data->servername = SSL_TEST_SERVERNAME_SERVER2; return 1; } else if (len == strlen("server1") && strncmp(servername, "server1", len) == 0) { ex_data->servername = SSL_TEST_SERVERNAME_SERVER1; return 1; } else if (ignore) { ex_data->servername = SSL_TEST_SERVERNAME_SERVER1; return 1; } return 0; }
['static int client_hello_select_server_ctx(SSL *s, void *arg, int ignore)\n{\n const char *servername;\n const unsigned char *p;\n size_t len, remaining;\n HANDSHAKE_EX_DATA *ex_data =\n (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n if (!SSL_client_hello_get0_ext(s, TLSEXT_TYPE_server_name, &p,\n &remaining) ||\n remaining <= 2)\n return 0;\n len = (*(p++) << 8);\n len += *(p++);\n if (len + 2 != remaining)\n return 0;\n remaining = len;\n if (remaining == 0 || *p++ != TLSEXT_NAMETYPE_host_name)\n return 0;\n remaining--;\n if (remaining <= 2)\n return 0;\n len = (*(p++) << 8);\n len += *(p++);\n if (len + 2 > remaining)\n return 0;\n remaining = len;\n servername = (const char *)p;\n if (len == strlen("server2") && strncmp(servername, "server2", len) == 0) {\n SSL_CTX *new_ctx = arg;\n SSL_set_SSL_CTX(s, new_ctx);\n SSL_clear_options(s, 0xFFFFFFFFL);\n SSL_set_options(s, SSL_CTX_get_options(new_ctx));\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;\n return 1;\n } else if (len == strlen("server1") &&\n strncmp(servername, "server1", len) == 0) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return 1;\n } else if (ignore) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return 1;\n }\n return 0;\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}', 'SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx)\n{\n CERT *new_cert;\n if (ssl->ctx == ctx)\n return ssl->ctx;\n if (ctx == NULL)\n ctx = ssl->session_ctx;\n new_cert = ssl_cert_dup(ctx->cert);\n if (new_cert == NULL) {\n return NULL;\n }\n if (!custom_exts_copy_flags(&new_cert->custext, &ssl->cert->custext)) {\n ssl_cert_free(new_cert);\n return NULL;\n }\n ssl_cert_free(ssl->cert);\n ssl->cert = new_cert;\n if (!ossl_assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx)))\n return NULL;\n if ((ssl->ctx != NULL) &&\n (ssl->sid_ctx_length == ssl->ctx->sid_ctx_length) &&\n (memcmp(ssl->sid_ctx, ssl->ctx->sid_ctx, ssl->sid_ctx_length) == 0)) {\n ssl->sid_ctx_length = ctx->sid_ctx_length;\n memcpy(&ssl->sid_ctx, &ctx->sid_ctx, sizeof(ssl->sid_ctx));\n }\n SSL_CTX_up_ref(ctx);\n SSL_CTX_free(ssl->ctx);\n ssl->ctx = ctx;\n return ssl->ctx;\n}', 'void ssl_cert_free(CERT *c)\n{\n int i;\n if (c == NULL)\n return;\n CRYPTO_DOWN_REF(&c->references, &i, c->lock);\n REF_PRINT_COUNT("CERT", c);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n#ifndef OPENSSL_NO_DH\n EVP_PKEY_free(c->dh_tmp);\n#endif\n ssl_cert_clear_certs(c);\n OPENSSL_free(c->conf_sigalgs);\n OPENSSL_free(c->client_sigalgs);\n OPENSSL_free(c->shared_sigalgs);\n OPENSSL_free(c->ctype);\n X509_STORE_free(c->verify_store);\n X509_STORE_free(c->chain_store);\n custom_exts_free(&c->custext);\n#ifndef OPENSSL_NO_PSK\n OPENSSL_free(c->psk_identity_hint);\n#endif\n CRYPTO_THREAD_lock_free(c->lock);\n OPENSSL_free(c);\n}', 'int SSL_CTX_up_ref(SSL_CTX *ctx)\n{\n int i;\n if (CRYPTO_UP_REF(&ctx->references, &i, ctx->lock) <= 0)\n return 0;\n REF_PRINT_COUNT("SSL_CTX", ctx);\n REF_ASSERT_ISNT(i < 2);\n return ((i > 1) ? 1 : 0);\n}', 'static inline int CRYPTO_UP_REF(_Atomic int *val, int *ret, void *lock)\n{\n *ret = atomic_fetch_add_explicit(val, 1, memory_order_relaxed) + 1;\n return 1;\n}', 'unsigned long SSL_clear_options(SSL *s, unsigned long op)\n{\n return s->options &= ~op;\n}', 'unsigned long SSL_CTX_get_options(const SSL_CTX *ctx)\n{\n return ctx->options;\n}', 'unsigned long SSL_set_options(SSL *s, unsigned long op)\n{\n return s->options |= op;\n}']
2,580
0
https://github.com/libav/libav/blob/e5b0fc170f85b00f7dd0ac514918fb5c95253d39/libavcodec/bitstream.h/#L139
static inline uint64_t get_val(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1); bc->bits >>= n; #else uint64_t ret = bc->bits >> (64 - n); bc->bits <<= n; #endif bc->bits_left -= n; return ret; }
['static int decode_gainc_npoints(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx,\n int ch_num, int coded_subbands)\n{\n int i, delta, delta_bits, min_val;\n Atrac3pChanParams *chan = &ctx->channels[ch_num];\n Atrac3pChanParams *ref_chan = &ctx->channels[0];\n switch (bitstream_read(bc, 2)) {\n case 0:\n for (i = 0; i < coded_subbands; i++)\n chan->gain_data[i].num_points = bitstream_read(bc, 3);\n break;\n case 1:\n for (i = 0; i < coded_subbands; i++)\n chan->gain_data[i].num_points =\n bitstream_read_vlc(bc, gain_vlc_tabs[0].table,\n gain_vlc_tabs[0].bits, 1);\n break;\n case 2:\n if (ch_num) {\n for (i = 0; i < coded_subbands; i++) {\n delta = bitstream_read_vlc(bc, gain_vlc_tabs[1].table,\n gain_vlc_tabs[1].bits, 1);\n chan->gain_data[i].num_points =\n (ref_chan->gain_data[i].num_points + delta) & 7;\n }\n } else {\n chan->gain_data[0].num_points =\n bitstream_read_vlc(bc, gain_vlc_tabs[0].table,\n gain_vlc_tabs[0].bits, 1);\n for (i = 1; i < coded_subbands; i++) {\n delta = bitstream_read_vlc(bc, gain_vlc_tabs[1].table,\n gain_vlc_tabs[1].bits, 1);\n chan->gain_data[i].num_points =\n (chan->gain_data[i - 1].num_points + delta) & 7;\n }\n }\n break;\n case 3:\n if (ch_num) {\n for (i = 0; i < coded_subbands; i++)\n chan->gain_data[i].num_points =\n ref_chan->gain_data[i].num_points;\n } else {\n delta_bits = bitstream_read(bc, 2);\n min_val = bitstream_read(bc, 3);\n for (i = 0; i < coded_subbands; i++) {\n chan->gain_data[i].num_points = min_val + bitstream_read(bc, delta_bits);\n if (chan->gain_data[i].num_points > 7)\n return AVERROR_INVALIDDATA;\n }\n }\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}']
2,581
0
https://github.com/libav/libav/blob/f40f329e9219a8dd7e585345a8ea294fa66562b9/ffmpeg.c/#L3639
static void opt_output_file(const char *filename) { AVFormatContext *oc; int err, use_video, use_audio, use_subtitle; int input_has_video, input_has_audio, input_has_subtitle; AVFormatParameters params, *ap = &params; AVOutputFormat *file_oformat; if (!strcmp(filename, "-")) filename = "pipe:"; oc = avformat_alloc_context(); if (!oc) { print_error(filename, AVERROR(ENOMEM)); av_exit(1); } if (last_asked_format) { file_oformat = av_guess_format(last_asked_format, NULL, NULL); if (!file_oformat) { fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format); av_exit(1); } last_asked_format = NULL; } else { file_oformat = av_guess_format(NULL, filename, NULL); if (!file_oformat) { fprintf(stderr, "Unable to find a suitable output format for '%s'\n", filename); av_exit(1); } } oc->oformat = file_oformat; av_strlcpy(oc->filename, filename, sizeof(oc->filename)); if (!strcmp(file_oformat->name, "ffm") && av_strstart(filename, "http:", NULL)) { int err = read_ffserver_streams(oc, filename); if (err < 0) { print_error(filename, err); av_exit(1); } } else { use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name; use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name; use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name; if (nb_input_files > 0) { check_audio_video_sub_inputs(&input_has_video, &input_has_audio, &input_has_subtitle); if (!input_has_video) use_video = 0; if (!input_has_audio) use_audio = 0; if (!input_has_subtitle) use_subtitle = 0; } if (audio_disable) { use_audio = 0; } if (video_disable) { use_video = 0; } if (subtitle_disable) { use_subtitle = 0; } if (use_video) { new_video_stream(oc); } if (use_audio) { new_audio_stream(oc); } if (use_subtitle) { new_subtitle_stream(oc); } oc->timestamp = rec_timestamp; for(; metadata_count>0; metadata_count--){ av_metadata_set2(&oc->metadata, metadata[metadata_count-1].key, metadata[metadata_count-1].value, 0); } av_metadata_conv(oc, oc->oformat->metadata_conv, NULL); } output_files[nb_output_files++] = oc; if (oc->oformat->flags & AVFMT_NEEDNUMBER) { if (!av_filename_number_test(oc->filename)) { print_error(oc->filename, AVERROR_NUMEXPECTED); av_exit(1); } } if (!(oc->oformat->flags & AVFMT_NOFILE)) { if (!file_overwrite && (strchr(filename, ':') == NULL || filename[1] == ':' || av_strstart(filename, "file:", NULL))) { if (url_exist(filename)) { if (!using_stdin) { fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); fflush(stderr); if (!read_yesno()) { fprintf(stderr, "Not overwriting - exiting\n"); av_exit(1); } } else { fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); av_exit(1); } } } if ((err = url_fopen(&oc->pb, filename, URL_WRONLY)) < 0) { print_error(filename, err); av_exit(1); } } memset(ap, 0, sizeof(*ap)); if (av_set_parameters(oc, ap) < 0) { fprintf(stderr, "%s: Invalid encoding parameters\n", oc->filename); av_exit(1); } oc->preload= (int)(mux_preload*AV_TIME_BASE); oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE); oc->loop_output = loop_output; oc->flags |= AVFMT_FLAG_NONBLOCK; set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM); }
['static void opt_output_file(const char *filename)\n{\n AVFormatContext *oc;\n int err, use_video, use_audio, use_subtitle;\n int input_has_video, input_has_audio, input_has_subtitle;\n AVFormatParameters params, *ap = &params;\n AVOutputFormat *file_oformat;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!oc) {\n print_error(filename, AVERROR(ENOMEM));\n av_exit(1);\n }\n if (last_asked_format) {\n file_oformat = av_guess_format(last_asked_format, NULL, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Requested output format \'%s\' is not a suitable output format\\n", last_asked_format);\n av_exit(1);\n }\n last_asked_format = NULL;\n } else {\n file_oformat = av_guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n av_exit(1);\n }\n }\n oc->oformat = file_oformat;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!strcmp(file_oformat->name, "ffm") &&\n av_strstart(filename, "http:", NULL)) {\n int err = read_ffserver_streams(oc, filename);\n if (err < 0) {\n print_error(filename, err);\n av_exit(1);\n }\n } else {\n use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;\n use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;\n use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;\n if (nb_input_files > 0) {\n check_audio_video_sub_inputs(&input_has_video, &input_has_audio,\n &input_has_subtitle);\n if (!input_has_video)\n use_video = 0;\n if (!input_has_audio)\n use_audio = 0;\n if (!input_has_subtitle)\n use_subtitle = 0;\n }\n if (audio_disable) {\n use_audio = 0;\n }\n if (video_disable) {\n use_video = 0;\n }\n if (subtitle_disable) {\n use_subtitle = 0;\n }\n if (use_video) {\n new_video_stream(oc);\n }\n if (use_audio) {\n new_audio_stream(oc);\n }\n if (use_subtitle) {\n new_subtitle_stream(oc);\n }\n oc->timestamp = rec_timestamp;\n for(; metadata_count>0; metadata_count--){\n av_metadata_set2(&oc->metadata, metadata[metadata_count-1].key,\n metadata[metadata_count-1].value, 0);\n }\n av_metadata_conv(oc, oc->oformat->metadata_conv, NULL);\n }\n output_files[nb_output_files++] = oc;\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR_NUMEXPECTED);\n av_exit(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n if (!file_overwrite &&\n (strchr(filename, \':\') == NULL ||\n filename[1] == \':\' ||\n av_strstart(filename, "file:", NULL))) {\n if (url_exist(filename)) {\n if (!using_stdin) {\n fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n fflush(stderr);\n if (!read_yesno()) {\n fprintf(stderr, "Not overwriting - exiting\\n");\n av_exit(1);\n }\n }\n else {\n fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n av_exit(1);\n }\n }\n }\n if ((err = url_fopen(&oc->pb, filename, URL_WRONLY)) < 0) {\n print_error(filename, err);\n av_exit(1);\n }\n }\n memset(ap, 0, sizeof(*ap));\n if (av_set_parameters(oc, ap) < 0) {\n fprintf(stderr, "%s: Invalid encoding parameters\\n",\n oc->filename);\n av_exit(1);\n }\n oc->preload= (int)(mux_preload*AV_TIME_BASE);\n oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n oc->loop_output = loop_output;\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n AVFormatContext *ic;\n ic = av_malloc(sizeof(AVFormatContext));\n if (!ic) return ic;\n avformat_get_context_defaults(ic);\n ic->av_class = &av_format_context_class;\n return ic;\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 print_error(const char *filename, int err)\n{\n char errbuf[128];\n const char *errbuf_ptr = errbuf;\n if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)\n errbuf_ptr = strerror(AVUNERROR(err));\n fprintf(stderr, "%s: %s\\n", filename, errbuf_ptr);\n}', 'int av_strerror(int errnum, char *errbuf, size_t errbuf_size)\n{\n int ret = 0;\n const char *errstr = NULL;\n switch (errnum) {\n case AVERROR_EOF: errstr = "End of file"; break;\n case AVERROR_INVALIDDATA: errstr = "Invalid data found when processing input"; break;\n case AVERROR_NUMEXPECTED: errstr = "Number syntax expected in filename"; break;\n case AVERROR_PATCHWELCOME: errstr = "Not yet implemented in FFmpeg, patches welcome"; break;\n }\n if (errstr) {\n av_strlcpy(errbuf, errstr, errbuf_size);\n } else {\n#if HAVE_STRERROR_R\n ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size);\n#else\n ret = -1;\n#endif\n if (ret < 0)\n snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);\n }\n return ret;\n}']
2,582
0
https://github.com/openssl/openssl/blob/f10725a6e19f0d72df5789e38601918539e64082/apps/speed.c/#L2560
static int do_multi(int multi) { int n; int fd[2]; int *fds; static char sep[]=":"; fds=malloc(multi*sizeof *fds); for(n=0 ; n < multi ; ++n) { pipe(fd); if(fork()) { close(fd[1]); fds[n]=fd[0]; } else { close(fd[0]); close(1); dup(fd[1]); close(fd[1]); mr=1; usertime=0; return 0; } printf("Forked child %d\n",n); } for(n=0 ; n < multi ; ++n) { FILE *f; char buf[1024]; char *p; f=fdopen(fds[n],"r"); while(fgets(buf,sizeof buf,f)) { p=strchr(buf,'\n'); if(p) *p='\0'; if(buf[0] != '+') { fprintf(stderr,"Don't understand line '%s' from child %d\n", buf,n); continue; } printf("Got: %s from %d\n",buf,n); if(!strncmp(buf,"+F:",3)) { int alg; int j; p=buf+3; alg=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); for(j=0 ; j < SIZE_NUM ; ++j) results[alg][j]+=atof(sstrsep(&p,sep)); } else if(!strncmp(buf,"+F2:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); else rsa_results[k][0]=d; d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); else rsa_results[k][1]=d; } else if(!strncmp(buf,"+F2:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); else rsa_results[k][0]=d; d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); else rsa_results[k][1]=d; } else if(!strncmp(buf,"+F3:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d); else dsa_results[k][0]=d; d=atof(sstrsep(&p,sep)); if(n) dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d); else dsa_results[k][1]=d; } #ifndef OPENSSL_NO_ECDSA else if(!strncmp(buf,"+F4:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d); else ecdsa_results[k][0]=d; d=atof(sstrsep(&p,sep)); if(n) ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d); else ecdsa_results[k][1]=d; } #endif #ifndef OPENSSL_NO_ECDH else if(!strncmp(buf,"+F5:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d); else ecdh_results[k][0]=d; } #endif else if(!strncmp(buf,"+H:",3)) { } else fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n); } } return 1; }
['static int do_multi(int multi)\n\t{\n\tint n;\n\tint fd[2];\n\tint *fds;\n\tstatic char sep[]=":";\n\tfds=malloc(multi*sizeof *fds);\n\tfor(n=0 ; n < multi ; ++n)\n\t\t{\n\t\tpipe(fd);\n\t\tif(fork())\n\t\t\t{\n\t\t\tclose(fd[1]);\n\t\t\tfds[n]=fd[0];\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tclose(fd[0]);\n\t\t\tclose(1);\n\t\t\tdup(fd[1]);\n\t\t\tclose(fd[1]);\n\t\t\tmr=1;\n\t\t\tusertime=0;\n\t\t\treturn 0;\n\t\t\t}\n\t\tprintf("Forked child %d\\n",n);\n\t\t}\n\tfor(n=0 ; n < multi ; ++n)\n\t\t{\n\t\tFILE *f;\n\t\tchar buf[1024];\n\t\tchar *p;\n\t\tf=fdopen(fds[n],"r");\n\t\twhile(fgets(buf,sizeof buf,f))\n\t\t\t{\n\t\t\tp=strchr(buf,\'\\n\');\n\t\t\tif(p)\n\t\t\t\t*p=\'\\0\';\n\t\t\tif(buf[0] != \'+\')\n\t\t\t\t{\n\t\t\t\tfprintf(stderr,"Don\'t understand line \'%s\' from child %d\\n",\n\t\t\t\t\t\tbuf,n);\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\tprintf("Got: %s from %d\\n",buf,n);\n\t\t\tif(!strncmp(buf,"+F:",3))\n\t\t\t\t{\n\t\t\t\tint alg;\n\t\t\t\tint j;\n\t\t\t\tp=buf+3;\n\t\t\t\talg=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\tfor(j=0 ; j < SIZE_NUM ; ++j)\n\t\t\t\t\tresults[alg][j]+=atof(sstrsep(&p,sep));\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F2:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][1]=d;\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F2:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][1]=d;\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F3:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tdsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tdsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tdsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\tdsa_results[k][1]=d;\n\t\t\t\t}\n#ifndef OPENSSL_NO_ECDSA\n\t\t\telse if(!strncmp(buf,"+F4:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdsa_results[k][1]=d;\n\t\t\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\t\telse if(!strncmp(buf,"+F5:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdh_results[k][0]=d;\n\t\t\t\t}\n#endif\n\t\t\telse if(!strncmp(buf,"+H:",3))\n\t\t\t\t{\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tfprintf(stderr,"Unknown type \'%s\' from child %d\\n",buf,n);\n\t\t\t}\n\t\t}\n\treturn 1;\n\t}']
2,583
0
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/des/des_enc.c/#L240
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}']
2,584
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bio/b_dump.c/#L58
int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u), void *u, const char *s, int len, int indent) { int ret = 0; char buf[288 + 1]; int i, j, rows, trc, n; unsigned char ch; int dump_width; trc = 0; #ifdef TRUNCATE for (; (len > 0) && ((s[len - 1] == ' ') || (s[len - 1] == '\0')); len--) trc++; #endif if (indent < 0) indent = 0; else if (indent > 128) indent = 128; dump_width = DUMP_WIDTH_LESS_INDENT(indent); rows = len / dump_width; if ((rows * dump_width) < len) rows++; for (i = 0; i < rows; i++) { n = BIO_snprintf(buf, sizeof(buf), "%*s%04x - ", indent, "", i * dump_width); for (j = 0; j < dump_width; j++) { if (SPACE(buf, n, 3)) { if (((i * dump_width) + j) >= len) { strcpy(buf + n, " "); } else { ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff; BIO_snprintf(buf + n, 4, "%02x%c", ch, j == 7 ? '-' : ' '); } n += 3; } } if (SPACE(buf, n, 2)) { strcpy(buf + n, " "); n += 2; } for (j = 0; j < dump_width; j++) { if (((i * dump_width) + j) >= len) break; if (SPACE(buf, n, 1)) { ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff; #ifndef CHARSET_EBCDIC buf[n++] = ((ch >= ' ') && (ch <= '~')) ? ch : '.'; #else buf[n++] = ((ch >= os_toascii[' ']) && (ch <= os_toascii['~'])) ? os_toebcdic[ch] : '.'; #endif buf[n] = '\0'; } } if (SPACE(buf, n, 1)) { buf[n++] = '\n'; buf[n] = '\0'; } ret += cb((void *)buf, n, u); } #ifdef TRUNCATE if (trc > 0) { n = BIO_snprintf(buf, sizeof(buf), "%*s%04x - <SPACES/NULS>\n", indent, "", len + trc); ret += cb((void *)buf, n, u); } #endif return ret; }
['int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u),\n void *u, const char *s, int len, int indent)\n{\n int ret = 0;\n char buf[288 + 1];\n int i, j, rows, trc, n;\n unsigned char ch;\n int dump_width;\n trc = 0;\n#ifdef TRUNCATE\n for (; (len > 0) && ((s[len - 1] == \' \') || (s[len - 1] == \'\\0\')); len--)\n trc++;\n#endif\n if (indent < 0)\n indent = 0;\n else if (indent > 128)\n indent = 128;\n dump_width = DUMP_WIDTH_LESS_INDENT(indent);\n rows = len / dump_width;\n if ((rows * dump_width) < len)\n rows++;\n for (i = 0; i < rows; i++) {\n n = BIO_snprintf(buf, sizeof(buf), "%*s%04x - ", indent, "",\n i * dump_width);\n for (j = 0; j < dump_width; j++) {\n if (SPACE(buf, n, 3)) {\n if (((i * dump_width) + j) >= len) {\n strcpy(buf + n, " ");\n } else {\n ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;\n BIO_snprintf(buf + n, 4, "%02x%c", ch,\n j == 7 ? \'-\' : \' \');\n }\n n += 3;\n }\n }\n if (SPACE(buf, n, 2)) {\n strcpy(buf + n, " ");\n n += 2;\n }\n for (j = 0; j < dump_width; j++) {\n if (((i * dump_width) + j) >= len)\n break;\n if (SPACE(buf, n, 1)) {\n ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;\n#ifndef CHARSET_EBCDIC\n buf[n++] = ((ch >= \' \') && (ch <= \'~\')) ? ch : \'.\';\n#else\n buf[n++] = ((ch >= os_toascii[\' \']) && (ch <= os_toascii[\'~\']))\n ? os_toebcdic[ch]\n : \'.\';\n#endif\n buf[n] = \'\\0\';\n }\n }\n if (SPACE(buf, n, 1)) {\n buf[n++] = \'\\n\';\n buf[n] = \'\\0\';\n }\n ret += cb((void *)buf, n, u);\n }\n#ifdef TRUNCATE\n if (trc > 0) {\n n = BIO_snprintf(buf, sizeof(buf), "%*s%04x - <SPACES/NULS>\\n",\n indent, "", len + trc);\n ret += cb((void *)buf, n, u);\n }\n#endif\n return ret;\n}', 'int BIO_snprintf(char *buf, size_t n, const char *format, ...)\n{\n va_list args;\n int ret;\n va_start(args, format);\n ret = BIO_vsnprintf(buf, n, format, args);\n va_end(args);\n return ret;\n}', 'int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)\n{\n size_t retlen;\n int truncated;\n if(!_dopr(&buf, NULL, &n, &retlen, &truncated, format, args))\n return -1;\n if (truncated)\n return -1;\n else\n return (retlen <= INT_MAX) ? (int)retlen : -1;\n}']
2,585
0
https://github.com/openssl/openssl/blob/350a404cb8b4524bab6b039e03b61b9db9fa8821/apps/ts.c/#L1083
static X509_STORE *create_cert_store(char *ca_path, char *ca_file) { X509_STORE *cert_ctx = NULL; X509_LOOKUP *lookup = NULL; int i; cert_ctx = X509_STORE_new(); X509_STORE_set_verify_cb_func(cert_ctx, verify_cb); if (ca_path) { lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_hash_dir()); if (lookup == NULL) { BIO_printf(bio_err, "memory allocation failure\n"); goto err; } i = X509_LOOKUP_add_dir(lookup, ca_path, X509_FILETYPE_PEM); if (!i) { BIO_printf(bio_err, "Error loading directory %s\n", ca_path); goto err; } } if (ca_file) { lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file()); if (lookup == NULL) { BIO_printf(bio_err, "memory allocation failure\n"); goto err; } i = X509_LOOKUP_load_file(lookup, ca_file, X509_FILETYPE_PEM); if (!i) { BIO_printf(bio_err, "Error loading file %s\n", ca_file); goto err; } } return cert_ctx; err: X509_STORE_free(cert_ctx); return NULL; }
['static X509_STORE *create_cert_store(char *ca_path, char *ca_file)\n\t{\n\tX509_STORE *cert_ctx = NULL;\n\tX509_LOOKUP *lookup = NULL;\n\tint i;\n\tcert_ctx = X509_STORE_new();\n\tX509_STORE_set_verify_cb_func(cert_ctx, verify_cb);\n\tif (ca_path)\n\t\t{\n\t\tlookup = X509_STORE_add_lookup(cert_ctx,\n\t\t\t\t\t X509_LOOKUP_hash_dir());\n\t\tif (lookup == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "memory allocation failure\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\ti = X509_LOOKUP_add_dir(lookup, ca_path, X509_FILETYPE_PEM);\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error loading directory %s\\n",\n\t\t\t\t ca_path);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (ca_file)\n\t\t{\n\t\tlookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file());\n\t\tif (lookup == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "memory allocation failure\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\ti = X509_LOOKUP_load_file(lookup, ca_file, X509_FILETYPE_PEM);\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error loading file %s\\n", ca_file);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\treturn cert_ctx;\n err:\n\tX509_STORE_free(cert_ctx);\n\treturn NULL;\n\t}', 'X509_STORE *X509_STORE_new(void)\n\t{\n\tX509_STORE *ret;\n\tif ((ret=(X509_STORE *)OPENSSL_malloc(sizeof(X509_STORE))) == NULL)\n\t\treturn NULL;\n\tret->objs = sk_X509_OBJECT_new(x509_object_cmp);\n\tret->cache=1;\n\tret->get_cert_methods=sk_X509_LOOKUP_new_null();\n\tret->verify=0;\n\tret->verify_cb=0;\n\tif ((ret->param = X509_VERIFY_PARAM_new()) == NULL)\n\t\treturn NULL;\n\tret->get_issuer = 0;\n\tret->check_issued = 0;\n\tret->check_revocation = 0;\n\tret->get_crl = 0;\n\tret->check_crl = 0;\n\tret->cert_crl = 0;\n\tret->cleanup = 0;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data);\n\tret->references=1;\n\treturn ret;\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}']
2,586
0
https://github.com/libav/libav/blob/b5c1c16247ab7d166c84eaf4564e49a1535fdaaf/libavformat/oggparsespeex.c/#L78
static int speex_header(AVFormatContext *s, int idx) { struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; struct speex_params *spxp = os->private; AVStream *st = s->streams[idx]; uint8_t *p = os->buf + os->pstart; if (!spxp) { spxp = av_mallocz(sizeof(*spxp)); os->private = spxp; } if (spxp->seq > 1) return 0; if (spxp->seq == 0) { int frames_per_packet; st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = AV_CODEC_ID_SPEEX; st->codec->sample_rate = AV_RL32(p + 36); st->codec->channels = AV_RL32(p + 48); if (st->codec->channels < 1 || st->codec->channels > 2) { av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\n"); return AVERROR_INVALIDDATA; } st->codec->channel_layout = st->codec->channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; spxp->packet_size = AV_RL32(p + 56); frames_per_packet = AV_RL32(p + 64); if (frames_per_packet) spxp->packet_size *= frames_per_packet; st->codec->extradata_size = os->psize; st->codec->extradata = av_malloc(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); memcpy(st->codec->extradata, p, st->codec->extradata_size); avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); } else ff_vorbis_stream_comment(s, st, p, os->psize); spxp->seq++; return 1; }
['static int speex_header(AVFormatContext *s, int idx) {\n struct ogg *ogg = s->priv_data;\n struct ogg_stream *os = ogg->streams + idx;\n struct speex_params *spxp = os->private;\n AVStream *st = s->streams[idx];\n uint8_t *p = os->buf + os->pstart;\n if (!spxp) {\n spxp = av_mallocz(sizeof(*spxp));\n os->private = spxp;\n }\n if (spxp->seq > 1)\n return 0;\n if (spxp->seq == 0) {\n int frames_per_packet;\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n st->codec->codec_id = AV_CODEC_ID_SPEEX;\n st->codec->sample_rate = AV_RL32(p + 36);\n st->codec->channels = AV_RL32(p + 48);\n if (st->codec->channels < 1 || st->codec->channels > 2) {\n av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\\n");\n return AVERROR_INVALIDDATA;\n }\n st->codec->channel_layout = st->codec->channels == 1 ? AV_CH_LAYOUT_MONO :\n AV_CH_LAYOUT_STEREO;\n spxp->packet_size = AV_RL32(p + 56);\n frames_per_packet = AV_RL32(p + 64);\n if (frames_per_packet)\n spxp->packet_size *= frames_per_packet;\n st->codec->extradata_size = os->psize;\n st->codec->extradata = av_malloc(st->codec->extradata_size\n + AV_INPUT_BUFFER_PADDING_SIZE);\n memcpy(st->codec->extradata, p, st->codec->extradata_size);\n avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);\n } else\n ff_vorbis_stream_comment(s, st, p, os->psize);\n spxp->seq++;\n return 1;\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}']
2,587
0
https://github.com/libav/libav/blob/cb4cb7b0ea12b791dde587b1acd504dbb4ec8f41/libavcodec/hqx.c/#L185
static void hqx_idct_put(uint16_t *dst, ptrdiff_t stride, int16_t *block, const uint8_t *quant) { int i, j; hqx_idct(block, quant); for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { int v = av_clip(block[j + i * 8] + 0x800, 0, 0x1000); dst[j] = (v << 4) | (v >> 8); } dst += stride >> 1; } }
['static int hqx_decode_422(HQXContext *ctx, AVFrame *pic,\n GetBitContext *gb, int x, int y)\n{\n const int *quants;\n int flag;\n int last_dc;\n int i, ret;\n if (ctx->interlaced)\n flag = get_bits1(gb);\n else\n flag = 0;\n quants = hqx_quants[get_bits(gb, 4)];\n for (i = 0; i < 8; i++) {\n int vlc_index = ctx->dcb - 9;\n if (i == 0 || i == 4 || i == 6)\n last_dc = 0;\n ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,\n ctx->dcb, ctx->block[i], &last_dc);\n if (ret < 0)\n return ret;\n }\n put_blocks(pic, 0, x, y, flag, ctx->block[0], ctx->block[2], hqx_quant_luma);\n put_blocks(pic, 0, x + 8, y, flag, ctx->block[1], ctx->block[3], hqx_quant_luma);\n put_blocks(pic, 2, x >> 1, y, flag, ctx->block[4], ctx->block[5], hqx_quant_chroma);\n put_blocks(pic, 1, x >> 1, y, flag, ctx->block[6], ctx->block[7], hqx_quant_chroma);\n return 0;\n}', 'static inline void put_blocks(AVFrame *pic, int plane,\n int x, int y, int ilace,\n int16_t *block0, int16_t *block1,\n const uint8_t *quant)\n{\n int fields = ilace ? 2 : 1;\n int lsize = pic->linesize[plane];\n uint8_t *p = pic->data[plane] + x * 2;\n hqx_idct_put((uint16_t *)(p + y * lsize), lsize * fields, block0, quant);\n hqx_idct_put((uint16_t *)(p + (y + (ilace ? 1 : 8)) * lsize),\n lsize * fields, block1, quant);\n}', 'static void hqx_idct_put(uint16_t *dst, ptrdiff_t stride,\n int16_t *block, const uint8_t *quant)\n{\n int i, j;\n hqx_idct(block, quant);\n for (i = 0; i < 8; i++) {\n for (j = 0; j < 8; j++) {\n int v = av_clip(block[j + i * 8] + 0x800, 0, 0x1000);\n dst[j] = (v << 4) | (v >> 8);\n }\n dst += stride >> 1;\n }\n}']
2,588
0
https://github.com/openssl/openssl/blob/c3be39f2e47ec6c538ef1060d35dbee5c286ea4f/crypto/mem.c/#L312
void CRYPTO_free(void *str, const char *file, int line) { INCREMENT(free_count); if (free_impl != NULL && free_impl != &CRYPTO_free) { free_impl(str, file, line); return; } #if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE) if (call_malloc_debug) { CRYPTO_mem_debug_free(str, 0, file, line); free(str); CRYPTO_mem_debug_free(str, 1, file, line); } else { free(str); } #else free(str); #endif }
['OPENSSL_STACK *OPENSSL_sk_new_reserve(OPENSSL_sk_compfunc c, int n)\n{\n OPENSSL_STACK *st = OPENSSL_zalloc(sizeof(OPENSSL_STACK));\n if (st == NULL)\n return NULL;\n st->comp = c;\n if (n <= 0)\n return st;\n if (!sk_reserve(st, n, 1)) {\n OPENSSL_sk_free(st);\n return NULL;\n }\n return st;\n}', 'static int sk_reserve(OPENSSL_STACK *st, int n, int exact)\n{\n const void **tmpdata;\n int num_alloc;\n if (n > max_nodes - st->num)\n return 0;\n num_alloc = st->num + n;\n if (num_alloc < min_nodes)\n num_alloc = min_nodes;\n if (st->data == NULL) {\n if ((st->data = OPENSSL_zalloc(sizeof(void *) * num_alloc)) == NULL) {\n CRYPTOerr(CRYPTO_F_SK_RESERVE, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n st->num_alloc = num_alloc;\n return 1;\n }\n if (!exact) {\n if (num_alloc <= st->num_alloc)\n return 1;\n num_alloc = compute_growth(num_alloc, st->num_alloc);\n if (num_alloc == 0)\n return 0;\n } else if (num_alloc == st->num_alloc) {\n return 1;\n }\n tmpdata = OPENSSL_realloc((void *)st->data, sizeof(void *) * num_alloc);\n if (tmpdata == NULL)\n return 0;\n st->data = tmpdata;\n st->num_alloc = num_alloc;\n return 1;\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n INCREMENT(realloc_count);\n if (realloc_impl != NULL && realloc_impl != &CRYPTO_realloc)\n return realloc_impl(str, num, file, line);\n FAILTEST();\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str, file, line);\n return NULL;\n }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)(file); (void)(line);\n#endif\n return realloc(str, num);\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#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\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 OPENSSL_sk_free(OPENSSL_STACK *st)\n{\n if (st == NULL)\n return;\n OPENSSL_free(st->data);\n OPENSSL_free(st);\n}']
2,589
0
https://github.com/openssl/openssl/blob/0350ef69add8758dd180e73cbc7c1961bf64e503/apps/speed.c/#L2620
static int do_multi(int multi) { int n; int fd[2]; int *fds; static char sep[] = ":"; fds = malloc(multi * sizeof *fds); for (n = 0; n < multi; ++n) { if (pipe(fd) == -1) { fprintf(stderr, "pipe failure\n"); exit(1); } fflush(stdout); fflush(stderr); if (fork()) { close(fd[1]); fds[n] = fd[0]; } else { close(fd[0]); close(1); if (dup(fd[1]) == -1) { fprintf(stderr, "dup failed\n"); exit(1); } close(fd[1]); mr = 1; usertime = 0; free(fds); return 0; } printf("Forked child %d\n", n); } for (n = 0; n < multi; ++n) { FILE *f; char buf[1024]; char *p; f = fdopen(fds[n], "r"); while (fgets(buf, sizeof buf, f)) { p = strchr(buf, '\n'); if (p) *p = '\0'; if (buf[0] != '+') { fprintf(stderr, "Don't understand line '%s' from child %d\n", buf, n); continue; } printf("Got: %s from %d\n", buf, n); if (!strncmp(buf, "+F:", 3)) { int alg; int j; p = buf + 3; alg = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); for (j = 0; j < SIZE_NUM; ++j) results[alg][j] += atof(sstrsep(&p, sep)); } else if (!strncmp(buf, "+F2:", 4)) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); if (n) rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d); else rsa_results[k][0] = d; d = atof(sstrsep(&p, sep)); if (n) rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d); else rsa_results[k][1] = d; } else if (!strncmp(buf, "+F2:", 4)) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); if (n) rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d); else rsa_results[k][0] = d; d = atof(sstrsep(&p, sep)); if (n) rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d); else rsa_results[k][1] = d; } # ifndef OPENSSL_NO_DSA else if (!strncmp(buf, "+F3:", 4)) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); if (n) dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d); else dsa_results[k][0] = d; d = atof(sstrsep(&p, sep)); if (n) dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d); else dsa_results[k][1] = d; } # endif # ifndef OPENSSL_NO_ECDSA else if (!strncmp(buf, "+F4:", 4)) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); if (n) ecdsa_results[k][0] = 1 / (1 / ecdsa_results[k][0] + 1 / d); else ecdsa_results[k][0] = d; d = atof(sstrsep(&p, sep)); if (n) ecdsa_results[k][1] = 1 / (1 / ecdsa_results[k][1] + 1 / d); else ecdsa_results[k][1] = d; } # endif # ifndef OPENSSL_NO_ECDH else if (!strncmp(buf, "+F5:", 4)) { int k; double d; p = buf + 4; k = atoi(sstrsep(&p, sep)); sstrsep(&p, sep); d = atof(sstrsep(&p, sep)); if (n) ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d); else ecdh_results[k][0] = d; } # endif else if (!strncmp(buf, "+H:", 3)) { } else fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n); } fclose(f); } free(fds); return 1; }
['static int do_multi(int multi)\n{\n int n;\n int fd[2];\n int *fds;\n static char sep[] = ":";\n fds = malloc(multi * sizeof *fds);\n for (n = 0; n < multi; ++n) {\n if (pipe(fd) == -1) {\n fprintf(stderr, "pipe failure\\n");\n exit(1);\n }\n fflush(stdout);\n fflush(stderr);\n if (fork()) {\n close(fd[1]);\n fds[n] = fd[0];\n } else {\n close(fd[0]);\n close(1);\n if (dup(fd[1]) == -1) {\n fprintf(stderr, "dup failed\\n");\n exit(1);\n }\n close(fd[1]);\n mr = 1;\n usertime = 0;\n free(fds);\n return 0;\n }\n printf("Forked child %d\\n", n);\n }\n for (n = 0; n < multi; ++n) {\n FILE *f;\n char buf[1024];\n char *p;\n f = fdopen(fds[n], "r");\n while (fgets(buf, sizeof buf, f)) {\n p = strchr(buf, \'\\n\');\n if (p)\n *p = \'\\0\';\n if (buf[0] != \'+\') {\n fprintf(stderr, "Don\'t understand line \'%s\' from child %d\\n",\n buf, n);\n continue;\n }\n printf("Got: %s from %d\\n", buf, n);\n if (!strncmp(buf, "+F:", 3)) {\n int alg;\n int j;\n p = buf + 3;\n alg = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n for (j = 0; j < SIZE_NUM; ++j)\n results[alg][j] += atof(sstrsep(&p, sep));\n } else if (!strncmp(buf, "+F2:", 4)) {\n int k;\n double d;\n p = buf + 4;\n k = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n d = atof(sstrsep(&p, sep));\n if (n)\n rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);\n else\n rsa_results[k][0] = d;\n d = atof(sstrsep(&p, sep));\n if (n)\n rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);\n else\n rsa_results[k][1] = d;\n } else if (!strncmp(buf, "+F2:", 4)) {\n int k;\n double d;\n p = buf + 4;\n k = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n d = atof(sstrsep(&p, sep));\n if (n)\n rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);\n else\n rsa_results[k][0] = d;\n d = atof(sstrsep(&p, sep));\n if (n)\n rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);\n else\n rsa_results[k][1] = d;\n }\n# ifndef OPENSSL_NO_DSA\n else if (!strncmp(buf, "+F3:", 4)) {\n int k;\n double d;\n p = buf + 4;\n k = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n d = atof(sstrsep(&p, sep));\n if (n)\n dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);\n else\n dsa_results[k][0] = d;\n d = atof(sstrsep(&p, sep));\n if (n)\n dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);\n else\n dsa_results[k][1] = d;\n }\n# endif\n# ifndef OPENSSL_NO_ECDSA\n else if (!strncmp(buf, "+F4:", 4)) {\n int k;\n double d;\n p = buf + 4;\n k = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n d = atof(sstrsep(&p, sep));\n if (n)\n ecdsa_results[k][0] =\n 1 / (1 / ecdsa_results[k][0] + 1 / d);\n else\n ecdsa_results[k][0] = d;\n d = atof(sstrsep(&p, sep));\n if (n)\n ecdsa_results[k][1] =\n 1 / (1 / ecdsa_results[k][1] + 1 / d);\n else\n ecdsa_results[k][1] = d;\n }\n# endif\n# ifndef OPENSSL_NO_ECDH\n else if (!strncmp(buf, "+F5:", 4)) {\n int k;\n double d;\n p = buf + 4;\n k = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n d = atof(sstrsep(&p, sep));\n if (n)\n ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);\n else\n ecdh_results[k][0] = d;\n }\n# endif\n else if (!strncmp(buf, "+H:", 3)) {\n } else\n fprintf(stderr, "Unknown type \'%s\' from child %d\\n", buf, n);\n }\n fclose(f);\n }\n free(fds);\n return 1;\n}']
2,590
0
https://github.com/openssl/openssl/blob/eaeb1870d4ef887a89f0bcec6b5ee1ec7fafa00f/crypto/bn/bn_asm.c/#L163
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); }
['BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int strong, BIGNUM *add,\n\t BIGNUM *rem, void (*callback)(int,int,void *), void *cb_arg)\n\t{\n\tBIGNUM *rnd=NULL;\n\tBIGNUM t;\n\tint i,j,c1=0;\n\tBN_CTX *ctx;\n\tctx=BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tif (ret == NULL)\n\t\t{\n\t\tif ((rnd=BN_new()) == NULL) goto err;\n\t\t}\n\telse\n\t\trnd=ret;\n\tBN_init(&t);\nloop:\n\tif (add == NULL)\n\t\t{\n\t\tif (!probable_prime(rnd,bits)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (strong)\n\t\t\t{\n\t\t\tif (!probable_prime_dh_strong(rnd,bits,add,rem,ctx))\n\t\t\t\t goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!probable_prime_dh(rnd,bits,add,rem,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (callback != NULL) callback(0,c1++,cb_arg);\n\tif (!strong)\n\t\t{\n\t\ti=BN_is_prime(rnd,BN_prime_checks,callback,ctx,cb_arg);\n\t\tif (i == -1) goto err;\n\t\tif (i == 0) goto loop;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_rshift1(&t,rnd)) goto err;\n\t\tfor (i=0; i<BN_prime_checks; i++)\n\t\t\t{\n\t\t\tj=BN_is_prime(rnd,1,callback,ctx,cb_arg);\n\t\t\tif (j == -1) goto err;\n\t\t\tif (j == 0) goto loop;\n\t\t\tj=BN_is_prime(&t,1,callback,ctx,cb_arg);\n\t\t\tif (j == -1) goto err;\n\t\t\tif (j == 0) goto loop;\n\t\t\tif (callback != NULL) callback(2,c1-1,cb_arg);\n\t\t\t}\n\t\t}\n\tret=rnd;\nerr:\n\tif ((ret == NULL) && (rnd != NULL)) BN_free(rnd);\n\tBN_free(&t);\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\treturn(ret);\n\t}', 'static int probable_prime_dh_strong(BIGNUM *p, int bits, BIGNUM *padd,\n\t BIGNUM *rem, BN_CTX *ctx)\n\t{\n\tint i,ret=0;\n\tBIGNUM *t1,*qadd=NULL,*q=NULL;\n\tbits--;\n\tt1= &(ctx->bn[ctx->tos++]);\n\tq= &(ctx->bn[ctx->tos++]);\n\tqadd= &(ctx->bn[ctx->tos++]);\n\tif (!BN_rshift1(qadd,padd)) goto err;\n\tif (!BN_rand(q,bits,0,1)) goto err;\n\tif (!BN_mod(t1,q,qadd,ctx)) goto err;\n\tif (!BN_sub(q,q,t1)) goto err;\n\tif (rem == NULL)\n\t\t{ if (!BN_add_word(q,1)) goto err; }\n\telse\n\t\t{\n\t\tif (!BN_rshift1(t1,rem)) goto err;\n\t\tif (!BN_add(q,q,t1)) goto err;\n\t\t}\n\tif (!BN_lshift1(p,q)) goto err;\n\tif (!BN_add_word(p,1)) goto err;\n\tloop: for (i=1; i<NUMPRIMES; i++)\n\t\t{\n\t\tif (\t(BN_mod_word(p,(BN_ULONG)primes[i]) == 0) ||\n\t\t\t(BN_mod_word(q,(BN_ULONG)primes[i]) == 0))\n\t\t\t{\n\t\t\tif (!BN_add(p,p,padd)) goto err;\n\t\t\tif (!BN_add(q,q,qadd)) goto err;\n\t\t\tgoto loop;\n\t\t\t}\n\t\t}\n\tret=1;\nerr:\n\tctx->tos-=3;\n\treturn(ret);\n\t}', 'int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,void *),\n\t BN_CTX *ctx_passed, void *cb_arg)\n\t{\n\tint i,j,c2=0,ret= -1;\n\tBIGNUM *check;\n\tBN_CTX *ctx=NULL,*ctx2=NULL;\n\tBN_MONT_CTX *mont=NULL;\n\tif (!BN_is_odd(a))\n\t\treturn(0);\n\tif (ctx_passed != NULL)\n\t\tctx=ctx_passed;\n\telse\n\t\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tif ((ctx2=BN_CTX_new()) == NULL) goto err;\n\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\tcheck= &(ctx->bn[ctx->tos++]);\n\tif (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;\n\tfor (i=0; i<checks; i++)\n\t\t{\n\t\tif (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;\n\t\tj=witness(check,a,ctx,ctx2,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 (callback != NULL) callback(1,c2++,cb_arg);\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tif ((ctx_passed == NULL) && (ctx != NULL))\n\t\tBN_CTX_free(ctx);\n\tif (ctx2 != NULL)\n\t\tBN_CTX_free(ctx2);\n\tif (mont != NULL) BN_MONT_CTX_free(mont);\n\treturn(ret);\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tBIGNUM Ri,*R;\n\tBN_init(&Ri);\n\tR= &(mont->RR);\n\tBN_copy(&(mont->N),mod);\n#ifdef BN_RECURSION_MONT\n\tif (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD)\n#endif\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tmont->use_word=1;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,BN_BITS2);\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.d=buf;\n\t\ttmod.top=1;\n\t\ttmod.max=mod->max;\n\t\ttmod.neg=mod->neg;\n\t\tif ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,BN_BITS2);\n\t\tif (!BN_is_zero(&Ri))\n\t\t\t{\n#if 1\n\t\t\tBN_sub_word(&Ri,1);\n#else\n\t\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBN_set_word(&Ri,BN_MASK2);\n\t\t\t}\n\t\tBN_div(&Ri,NULL,&Ri,&tmod,ctx);\n\t\tmont->n0=Ri.d[0];\n\t\tBN_free(&Ri);\n\t\t}\n#ifdef BN_RECURSION_MONT\n\telse\n\t\t{\n\t\tmont->use_word=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if 1\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,mont->ri);\n#else\n\t\tBN_lshift(R,BN_value_one(),mont->ri);\n#endif\n\t\tif ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,mont->ri);\n#if 1\n\t\tBN_sub_word(&Ri,1);\n#else\n\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\tBN_div(&(mont->Ni),NULL,&Ri,mod,ctx);\n\t\tBN_free(&Ri);\n\t\t}\n#endif\n#if 1\n\tBN_zero(&(mont->RR));\n\tBN_set_bit(&(mont->RR),mont->ri*2);\n#else\n\tBN_lshift(mont->RR,BN_value_one(),mont->ri*2);\n#endif\n\tBN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, 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}', 'static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx, BN_CTX *ctx2,\n\t BN_MONT_CTX *mont)\n\t{\n\tint k,i,ret= -1,good;\n\tBIGNUM *d,*dd,*tmp,*d1,*d2,*n1;\n\tBIGNUM *mont_one,*mont_n1,*mont_a;\n\td1= &(ctx->bn[ctx->tos]);\n\td2= &(ctx->bn[ctx->tos+1]);\n\tn1= &(ctx->bn[ctx->tos+2]);\n\tctx->tos+=3;\n\tmont_one= &(ctx2->bn[ctx2->tos]);\n\tmont_n1= &(ctx2->bn[ctx2->tos+1]);\n\tmont_a= &(ctx2->bn[ctx2->tos+2]);\n\tctx2->tos+=3;\n\td=d1;\n\tdd=d2;\n\tif (!BN_one(d)) goto err;\n\tif (!BN_sub(n1,n,d)) goto err;\n\tk=BN_num_bits(n1);\n\tif (!BN_to_montgomery(mont_one,BN_value_one(),mont,ctx2)) goto err;\n\tif (!BN_to_montgomery(mont_n1,n1,mont,ctx2)) goto err;\n\tif (!BN_to_montgomery(mont_a,a,mont,ctx2)) goto err;\n\tBN_copy(d,mont_one);\n\tfor (i=k-1; i>=0; i--)\n\t\t{\n\t\tif (\t(BN_cmp(d,mont_one) != 0) &&\n\t\t\t(BN_cmp(d,mont_n1) != 0))\n\t\t\tgood=1;\n\t\telse\n\t\t\tgood=0;\n\t\tBN_mod_mul_montgomery(dd,d,d,mont,ctx2);\n\t\tif (good && (BN_cmp(dd,mont_one) == 0))\n\t\t\t{\n\t\t\tret=1;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (BN_is_bit_set(n1,i))\n\t\t\t{\n\t\t\tBN_mod_mul_montgomery(d,dd,mont_a,mont,ctx2);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ttmp=d;\n\t\t\td=dd;\n\t\t\tdd=tmp;\n\t\t\t}\n\t\t}\n\tif (BN_cmp(d,mont_one) == 0)\n\t\ti=0;\n\telse\ti=1;\n\tret=i;\nerr:\n\tctx->tos-=3;\n\tctx2->tos-=3;\n\treturn(ret);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_MONT_CTX *mont,\n\t BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp,*tmp2;\n tmp= &(ctx->bn[ctx->tos]);\n tmp2= &(ctx->bn[ctx->tos]);\n\tctx->tos+=2;\n\tbn_check_top(tmp);\n\tbn_check_top(tmp2);\n\tif (a == b)\n\t\t{\n#if 0\n\t\tbn_wexpand(tmp,a->top*2);\n\t\tbn_wexpand(tmp2,a->top*4);\n\t\tbn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);\n\t\ttmp->top=a->top*2;\n\t\tif (tmp->d[tmp->top-1] == 0)\n\t\t\ttmp->top--;\n#else\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n\tctx->tos-=2;\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,\n\t BN_CTX *ctx)\n\t{\n#ifdef BN_RECURSION_MONT\n\tif (mont->use_word)\n#endif\n\t\t{\n\t\tBIGNUM *n,*r;\n\t\tBN_ULONG *ap,*np,*rp,n0,v,*nrp;\n\t\tint al,nl,max,i,x,ri;\n\t\tint retn=0;\n\t\tr= &(ctx->bn[ctx->tos]);\n\t\tif (!BN_copy(r,a)) goto err1;\n\t\tn= &(mont->N);\n\t\tap=a->d;\n\t\tal=ri=mont->ri/BN_BITS2;\n\t\tnl=n->top;\n\t\tif ((al == 0) || (nl == 0)) { r->top=0; return(1); }\n\t\tmax=(nl+al+1);\n\t\tif (bn_wexpand(r,max) == NULL) goto err1;\n\t\tif (bn_wexpand(ret,max) == NULL) goto err1;\n\t\tr->neg=a->neg^n->neg;\n\t\tnp=n->d;\n\t\trp=r->d;\n\t\tnrp= &(r->d[nl]);\n#if 1\n\t\tfor (i=r->top; i<max; i++)\n\t\t\tr->d[i]=0;\n#else\n\t\tmemset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG));\n#endif\n\t\tr->top=max;\n\t\tn0=mont->n0;\n#ifdef BN_COUNT\nprintf("word BN_from_montgomery %d * %d\\n",nl,nl);\n#endif\n\t\tfor (i=0; i<nl; i++)\n\t\t\t{\n\t\t\tv=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);\n\t\t\tnrp++;\n\t\t\trp++;\n\t\t\tif (((nrp[-1]+=v)&BN_MASK2) >= v)\n\t\t\t\tcontinue;\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (((++nrp[0])&BN_MASK2) != 0) continue;\n\t\t\t\tif (((++nrp[1])&BN_MASK2) != 0) continue;\n\t\t\t\tfor (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;\n\t\t\t\t}\n\t\t\t}\n\t\tbn_fix_top(r);\n#if 0\n\t\tBN_rshift(ret,r,mont->ri);\n#else\n\t\tx=ri;\n\t\trp=ret->d;\n\t\tap= &(r->d[x]);\n\t\tif (r->top < x)\n\t\t\tal=0;\n\t\telse\n\t\t\tal=r->top-x;\n\t\tret->top=al;\n\t\tal-=4;\n\t\tfor (i=0; i<al; i+=4)\n\t\t\t{\n\t\t\tBN_ULONG t1,t2,t3,t4;\n\t\t\tt1=ap[i+0];\n\t\t\tt2=ap[i+1];\n\t\t\tt3=ap[i+2];\n\t\t\tt4=ap[i+3];\n\t\t\trp[i+0]=t1;\n\t\t\trp[i+1]=t2;\n\t\t\trp[i+2]=t3;\n\t\t\trp[i+3]=t4;\n\t\t\t}\n\t\tal+=4;\n\t\tfor (; i<al; i++)\n\t\t\trp[i]=ap[i];\n#endif\n\t\tif (BN_ucmp(ret, &(mont->N)) >= 0)\n\t\t\t{\n\t\t\tBN_usub(ret,ret,&(mont->N));\n\t\t\t}\n\t\tretn=1;\nerr1:\n\t\treturn(retn);\n\t\t}\n#ifdef BN_RECURSION_MONT\n\telse\n\t\t{\n\t\tBIGNUM *t1,*t2,*t3;\n\t\tint j,i;\n#ifdef BN_COUNT\nprintf("number BN_from_montgomery\\n");\n#endif\n\t\tt1= &(ctx->bn[ctx->tos]);\n\t\tt2= &(ctx->bn[ctx->tos+1]);\n\t\tt3= &(ctx->bn[ctx->tos+2]);\n\t\ti=mont->Ni.top;\n\t\tbn_wexpand(ret,i);\n\t\tbn_wexpand(t1,i*4);\n\t\tbn_wexpand(t2,i*2);\n\t\tbn_mul_low_recursive(t2->d,a->d,mont->Ni.d,i,t1->d);\n\t\tBN_zero(t3);\n\t\tBN_set_bit(t3,mont->N.top*BN_BITS2);\n\t\tbn_sub_words(t3->d,t3->d,a->d,i);\n\t\tbn_mul_high(ret->d,t2->d,mont->N.d,t3->d,i,t1->d);\n\t\tif (a->top > i)\n\t\t\t{\n\t\t\tj=(int)(bn_add_words(ret->d,ret->d,&(a->d[i]),i));\n\t\t\tif (j)\n\t\t\t\tbn_sub_words(ret->d,ret->d,mont->N.d,i);\n\t\t\t}\n\t\tret->top=i;\n\t\tbn_fix_top(ret);\n\t\tif (a->d[0])\n\t\t\tBN_add_word(ret,1);\n\t\telse\n\t\t\t{\n\t\t\tfor (i=1; i<mont->N.top-1; i++)\n\t\t\t\t{\n\t\t\t\tif (a->d[i])\n\t\t\t\t\t{\n\t\t\t\t\tBN_add_word(ret,1);\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tif (BN_ucmp(ret,&(mont->N)) >= 0)\n\t\t\tBN_usub(ret,ret,&(mont->N));\n\t\treturn(1);\n\t\t}\n#endif\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}']
2,591
0
https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/ssl/packet_locl.h/#L36
static ossl_inline void packet_forward(PACKET *pkt, size_t len) { pkt->curr += len; pkt->remaining -= len; }
['int DTLSv1_listen(SSL *s, BIO_ADDR *client)\n{\n int next, n, ret = 0, clearpkt = 0;\n unsigned char cookie[DTLS1_COOKIE_LENGTH];\n unsigned char seq[SEQ_NUM_SIZE];\n const unsigned char *data;\n unsigned char *p, *buf;\n unsigned long reclen, fragoff, fraglen, msglen;\n unsigned int rectype, versmajor, msgseq, msgtype, clientvers, cookielen;\n BIO *rbio, *wbio;\n BUF_MEM *bufm;\n BIO_ADDR *tmpclient = NULL;\n PACKET pkt, msgpkt, msgpayload, session, cookiepkt;\n if (!SSL_clear(s))\n return -1;\n ERR_clear_error();\n rbio = SSL_get_rbio(s);\n wbio = SSL_get_wbio(s);\n if (!rbio || !wbio) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_BIO_NOT_SET);\n return -1;\n }\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 1, NULL);\n if ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNSUPPORTED_SSL_VERSION);\n return -1;\n }\n if (s->init_buf == NULL) {\n if ((bufm = BUF_MEM_new()) == NULL) {\n SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n if (!BUF_MEM_grow(bufm, SSL3_RT_MAX_PLAIN_LENGTH)) {\n BUF_MEM_free(bufm);\n SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n s->init_buf = bufm;\n }\n buf = (unsigned char *)s->init_buf->data;\n do {\n clear_sys_error();\n n = BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n if (n <= 0) {\n if (BIO_should_retry(rbio)) {\n goto end;\n }\n return -1;\n }\n clearpkt = 1;\n if (!PACKET_buf_init(&pkt, buf, n)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_INTERNAL_ERROR);\n return -1;\n }\n if (n < DTLS1_RT_HEADER_LENGTH) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_RECORD_TOO_SMALL);\n goto end;\n }\n if (s->msg_callback)\n s->msg_callback(0, 0, SSL3_RT_HEADER, buf,\n DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);\n if (!PACKET_get_1(&pkt, &rectype)\n || !PACKET_get_1(&pkt, &versmajor)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (rectype != SSL3_RT_HANDSHAKE) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n goto end;\n }\n if (versmajor != DTLS1_VERSION_MAJOR) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_BAD_PROTOCOL_VERSION_NUMBER);\n goto end;\n }\n if (!PACKET_forward(&pkt, 1)\n || !PACKET_copy_bytes(&pkt, seq, SEQ_NUM_SIZE)\n || !PACKET_get_length_prefixed_2(&pkt, &msgpkt)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (seq[0] != 0 || seq[1] != 0) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n goto end;\n }\n data = PACKET_data(&msgpkt);\n if (!PACKET_get_1(&msgpkt, &msgtype)\n || !PACKET_get_net_3(&msgpkt, &msglen)\n || !PACKET_get_net_2(&msgpkt, &msgseq)\n || !PACKET_get_net_3(&msgpkt, &fragoff)\n || !PACKET_get_net_3(&msgpkt, &fraglen)\n || !PACKET_get_sub_packet(&msgpkt, &msgpayload, fraglen)\n || PACKET_remaining(&msgpkt) != 0) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (msgtype != SSL3_MT_CLIENT_HELLO) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n goto end;\n }\n if (msgseq > 2) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_INVALID_SEQUENCE_NUMBER);\n goto end;\n }\n if (fragoff != 0 || fraglen > msglen) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_FRAGMENTED_CLIENT_HELLO);\n goto end;\n }\n if (s->msg_callback)\n s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, data,\n fraglen + DTLS1_HM_HEADER_LENGTH, s,\n s->msg_callback_arg);\n if (!PACKET_get_net_2(&msgpayload, &clientvers)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (DTLS_VERSION_LT(clientvers, (unsigned int)s->method->version) &&\n s->method->version != DTLS_ANY_VERSION) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_WRONG_VERSION_NUMBER);\n goto end;\n }\n if (!PACKET_forward(&msgpayload, SSL3_RANDOM_SIZE)\n || !PACKET_get_length_prefixed_1(&msgpayload, &session)\n || !PACKET_get_length_prefixed_1(&msgpayload, &cookiepkt)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (PACKET_remaining(&cookiepkt) == 0) {\n next = LISTEN_SEND_VERIFY_REQUEST;\n } else {\n if (s->ctx->app_verify_cookie_cb == NULL) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_NO_VERIFY_COOKIE_CALLBACK);\n return -1;\n }\n if (s->ctx->app_verify_cookie_cb(s, PACKET_data(&cookiepkt),\n PACKET_remaining(&cookiepkt)) ==\n 0) {\n next = LISTEN_SEND_VERIFY_REQUEST;\n } else {\n next = LISTEN_SUCCESS;\n }\n }\n if (next == LISTEN_SEND_VERIFY_REQUEST) {\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 0, NULL);\n BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 1, NULL);\n if (s->ctx->app_gen_cookie_cb == NULL ||\n s->ctx->app_gen_cookie_cb(s, cookie, &cookielen) == 0 ||\n cookielen > 255) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_COOKIE_GEN_CALLBACK_FAILURE);\n return -1;\n }\n p = &buf[DTLS1_RT_HEADER_LENGTH];\n msglen = dtls_raw_hello_verify_request(p + DTLS1_HM_HEADER_LENGTH,\n cookie, cookielen);\n *p++ = DTLS1_MT_HELLO_VERIFY_REQUEST;\n l2n3(msglen, p);\n s2n(0, p);\n l2n3(0, p);\n l2n3(msglen, p);\n reclen = msglen + DTLS1_HM_HEADER_LENGTH;\n p = buf;\n *(p++) = SSL3_RT_HANDSHAKE;\n if (s->method->version == DTLS_ANY_VERSION) {\n *(p++) = DTLS1_VERSION >> 8;\n *(p++) = DTLS1_VERSION & 0xff;\n } else {\n *(p++) = s->version >> 8;\n *(p++) = s->version & 0xff;\n }\n memcpy(p, seq, SEQ_NUM_SIZE);\n p += SEQ_NUM_SIZE;\n s2n(reclen, p);\n reclen += DTLS1_RT_HEADER_LENGTH;\n if (s->msg_callback)\n s->msg_callback(1, 0, SSL3_RT_HEADER, buf,\n DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);\n if ((tmpclient = BIO_ADDR_new()) == NULL) {\n SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_MALLOC_FAILURE);\n goto end;\n }\n if (BIO_dgram_get_peer(rbio, tmpclient) > 0) {\n (void)BIO_dgram_set_peer(wbio, tmpclient);\n }\n BIO_ADDR_free(tmpclient);\n tmpclient = NULL;\n if (BIO_write(wbio, buf, reclen) < (int)reclen) {\n if (BIO_should_retry(wbio)) {\n goto end;\n }\n return -1;\n }\n if (BIO_flush(wbio) <= 0) {\n if (BIO_should_retry(wbio)) {\n goto end;\n }\n return -1;\n }\n }\n } while (next != LISTEN_SUCCESS);\n s->d1->handshake_read_seq = 1;\n s->d1->handshake_write_seq = 1;\n s->d1->next_handshake_write_seq = 1;\n DTLS_RECORD_LAYER_set_write_sequence(&s->rlayer, seq);\n SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);\n ossl_statem_set_hello_verify_done(s);\n if (BIO_dgram_get_peer(rbio, client) <= 0)\n BIO_ADDR_clear(client);\n ret = 1;\n clearpkt = 0;\n end:\n BIO_ADDR_free(tmpclient);\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 0, NULL);\n if (clearpkt) {\n BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n }\n return ret;\n}', 'static ossl_inline void packet_forward(PACKET *pkt, size_t len)\n{\n pkt->curr += len;\n pkt->remaining -= len;\n}']
2,592
0
https://github.com/openssl/openssl/blob/6c2c3e9ba9146ef8c9b1fd2b660357b657706969/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); }
['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#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_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=Malloc(BUFSIZZ)) == NULL) ||\n\t\t((sbuf=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\tc_quiet=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\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\tSSLeay_add_ssl_algorithms();\n\tSSL_load_error_strings();\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 seting 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 *)SSL_new(ctx);\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\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() || !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())\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_quiet) && ((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_quiet) && (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); Free(cbuf); }\n\tif (sbuf != NULL) { memset(sbuf,0,BUFSIZZ); 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 *)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(SSL_SESSION_hash,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(unsigned long (*h)(), int (*c)())\n\t{\n\tLHASH *ret;\n\tint i;\n\tif ((ret=(LHASH *)Malloc(sizeof(LHASH))) == NULL)\n\t\tgoto err0;\n\tif ((ret->b=(LHASH_NODE **)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)?(int (*)())strcmp:c);\n\tret->hash=((h == NULL)?(unsigned long (*)())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\tFree((char *)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 *)Malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\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\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\tFree(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#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\ts->read_ahead=s->ctx->read_ahead;\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,(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}']
2,593
0
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)\n{\n if (!BN_sqr(r, a, ctx))\n return 0;\n return BN_mod(r, r, m, ctx);\n}', 'int BN_sqr(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 || !tmp)\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 if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (rr != r)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\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 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}', '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}']
2,594
0
https://github.com/openssl/openssl/blob/3da2e9c4ee45989a426ff513dc6c6250d1e460de/crypto/sha/sha512.c/#L148
int SHA512_Final(unsigned char *md, SHA512_CTX *c) { unsigned char *p = (unsigned char *)c->u.p; size_t n = c->num; p[n] = 0x80; n++; if (n > (sizeof(c->u) - 16)) { memset(p + n, 0, sizeof(c->u) - n); n = 0; sha512_block_data_order(c, p, 1); } memset(p + n, 0, sizeof(c->u) - 16 - n); #ifdef B_ENDIAN c->u.d[SHA_LBLOCK - 2] = c->Nh; c->u.d[SHA_LBLOCK - 1] = c->Nl; #else p[sizeof(c->u) - 1] = (unsigned char)(c->Nl); p[sizeof(c->u) - 2] = (unsigned char)(c->Nl >> 8); p[sizeof(c->u) - 3] = (unsigned char)(c->Nl >> 16); p[sizeof(c->u) - 4] = (unsigned char)(c->Nl >> 24); p[sizeof(c->u) - 5] = (unsigned char)(c->Nl >> 32); p[sizeof(c->u) - 6] = (unsigned char)(c->Nl >> 40); p[sizeof(c->u) - 7] = (unsigned char)(c->Nl >> 48); p[sizeof(c->u) - 8] = (unsigned char)(c->Nl >> 56); p[sizeof(c->u) - 9] = (unsigned char)(c->Nh); p[sizeof(c->u) - 10] = (unsigned char)(c->Nh >> 8); p[sizeof(c->u) - 11] = (unsigned char)(c->Nh >> 16); p[sizeof(c->u) - 12] = (unsigned char)(c->Nh >> 24); p[sizeof(c->u) - 13] = (unsigned char)(c->Nh >> 32); p[sizeof(c->u) - 14] = (unsigned char)(c->Nh >> 40); p[sizeof(c->u) - 15] = (unsigned char)(c->Nh >> 48); p[sizeof(c->u) - 16] = (unsigned char)(c->Nh >> 56); #endif sha512_block_data_order(c, p, 1); if (md == 0) return 0; switch (c->md_len) { case SHA224_DIGEST_LENGTH: for (n = 0; n < SHA224_DIGEST_LENGTH / 8; n++) { SHA_LONG64 t = c->h[n]; *(md++) = (unsigned char)(t >> 56); *(md++) = (unsigned char)(t >> 48); *(md++) = (unsigned char)(t >> 40); *(md++) = (unsigned char)(t >> 32); *(md++) = (unsigned char)(t >> 24); *(md++) = (unsigned char)(t >> 16); *(md++) = (unsigned char)(t >> 8); *(md++) = (unsigned char)(t); } { SHA_LONG64 t = c->h[SHA224_DIGEST_LENGTH / 8]; *(md++) = (unsigned char)(t >> 56); *(md++) = (unsigned char)(t >> 48); *(md++) = (unsigned char)(t >> 40); *(md++) = (unsigned char)(t >> 32); } break; case SHA256_DIGEST_LENGTH: for (n = 0; n < SHA256_DIGEST_LENGTH / 8; n++) { SHA_LONG64 t = c->h[n]; *(md++) = (unsigned char)(t >> 56); *(md++) = (unsigned char)(t >> 48); *(md++) = (unsigned char)(t >> 40); *(md++) = (unsigned char)(t >> 32); *(md++) = (unsigned char)(t >> 24); *(md++) = (unsigned char)(t >> 16); *(md++) = (unsigned char)(t >> 8); *(md++) = (unsigned char)(t); } break; case SHA384_DIGEST_LENGTH: for (n = 0; n < SHA384_DIGEST_LENGTH / 8; n++) { SHA_LONG64 t = c->h[n]; *(md++) = (unsigned char)(t >> 56); *(md++) = (unsigned char)(t >> 48); *(md++) = (unsigned char)(t >> 40); *(md++) = (unsigned char)(t >> 32); *(md++) = (unsigned char)(t >> 24); *(md++) = (unsigned char)(t >> 16); *(md++) = (unsigned char)(t >> 8); *(md++) = (unsigned char)(t); } break; case SHA512_DIGEST_LENGTH: for (n = 0; n < SHA512_DIGEST_LENGTH / 8; n++) { SHA_LONG64 t = c->h[n]; *(md++) = (unsigned char)(t >> 56); *(md++) = (unsigned char)(t >> 48); *(md++) = (unsigned char)(t >> 40); *(md++) = (unsigned char)(t >> 32); *(md++) = (unsigned char)(t >> 24); *(md++) = (unsigned char)(t >> 16); *(md++) = (unsigned char)(t >> 8); *(md++) = (unsigned char)(t); } break; default: return 0; } return 1; }
['int ED25519_verify(const uint8_t *message, size_t message_len,\n const uint8_t signature[64], const uint8_t public_key[32]) {\n int i;\n ge_p3 A;\n const uint8_t *r, *s;\n SHA512_CTX hash_ctx;\n ge_p2 R;\n uint8_t rcheck[32];\n uint8_t h[SHA512_DIGEST_LENGTH];\n const uint8_t l_low[16] = {\n 0xED, 0xD3, 0xF5, 0x5C, 0x1A, 0x63, 0x12, 0x58, 0xD6, 0x9C, 0xF7, 0xA2,\n 0xDE, 0xF9, 0xDE, 0x14\n };\n r = signature;\n s = signature + 32;\n if (s[31] > 0x10)\n return 0;\n if (s[31] == 0x10) {\n if (memcmp(s + 16, allzeroes, sizeof(allzeroes)) != 0)\n return 0;\n for (i = 15; i >= 0; i--) {\n if (s[i] < l_low[i])\n break;\n if (s[i] > l_low[i])\n return 0;\n }\n if (i < 0)\n return 0;\n }\n if (ge_frombytes_vartime(&A, public_key) != 0) {\n return 0;\n }\n fe_neg(A.X, A.X);\n fe_neg(A.T, A.T);\n SHA512_Init(&hash_ctx);\n SHA512_Update(&hash_ctx, r, 32);\n SHA512_Update(&hash_ctx, public_key, 32);\n SHA512_Update(&hash_ctx, message, message_len);\n SHA512_Final(h, &hash_ctx);\n x25519_sc_reduce(h);\n ge_double_scalarmult_vartime(&R, h, &A, s);\n ge_tobytes(rcheck, &R);\n return CRYPTO_memcmp(rcheck, r, sizeof(rcheck)) == 0;\n}', 'int SHA512_Init(SHA512_CTX *c)\n{\n c->h[0] = U64(0x6a09e667f3bcc908);\n c->h[1] = U64(0xbb67ae8584caa73b);\n c->h[2] = U64(0x3c6ef372fe94f82b);\n c->h[3] = U64(0xa54ff53a5f1d36f1);\n c->h[4] = U64(0x510e527fade682d1);\n c->h[5] = U64(0x9b05688c2b3e6c1f);\n c->h[6] = U64(0x1f83d9abfb41bd6b);\n c->h[7] = U64(0x5be0cd19137e2179);\n c->Nl = 0;\n c->Nh = 0;\n c->num = 0;\n c->md_len = SHA512_DIGEST_LENGTH;\n return 1;\n}', 'int SHA512_Update(SHA512_CTX *c, const void *_data, size_t len)\n{\n SHA_LONG64 l;\n unsigned char *p = c->u.p;\n const unsigned char *data = (const unsigned char *)_data;\n if (len == 0)\n return 1;\n l = (c->Nl + (((SHA_LONG64) len) << 3)) & U64(0xffffffffffffffff);\n if (l < c->Nl)\n c->Nh++;\n if (sizeof(len) >= 8)\n c->Nh += (((SHA_LONG64) len) >> 61);\n c->Nl = l;\n if (c->num != 0) {\n size_t n = sizeof(c->u) - c->num;\n if (len < n) {\n memcpy(p + c->num, data, len), c->num += (unsigned int)len;\n return 1;\n } else {\n memcpy(p + c->num, data, n), c->num = 0;\n len -= n, data += n;\n sha512_block_data_order(c, p, 1);\n }\n }\n if (len >= sizeof(c->u)) {\n#ifndef SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA\n if ((size_t)data % sizeof(c->u.d[0]) != 0)\n while (len >= sizeof(c->u))\n memcpy(p, data, sizeof(c->u)),\n sha512_block_data_order(c, p, 1),\n len -= sizeof(c->u), data += sizeof(c->u);\n else\n#endif\n sha512_block_data_order(c, data, len / sizeof(c->u)),\n data += len, len %= sizeof(c->u), data -= len;\n }\n if (len != 0)\n memcpy(p, data, len), c->num = (int)len;\n return 1;\n}', 'int SHA512_Final(unsigned char *md, SHA512_CTX *c)\n{\n unsigned char *p = (unsigned char *)c->u.p;\n size_t n = c->num;\n p[n] = 0x80;\n n++;\n if (n > (sizeof(c->u) - 16)) {\n memset(p + n, 0, sizeof(c->u) - n);\n n = 0;\n sha512_block_data_order(c, p, 1);\n }\n memset(p + n, 0, sizeof(c->u) - 16 - n);\n#ifdef B_ENDIAN\n c->u.d[SHA_LBLOCK - 2] = c->Nh;\n c->u.d[SHA_LBLOCK - 1] = c->Nl;\n#else\n p[sizeof(c->u) - 1] = (unsigned char)(c->Nl);\n p[sizeof(c->u) - 2] = (unsigned char)(c->Nl >> 8);\n p[sizeof(c->u) - 3] = (unsigned char)(c->Nl >> 16);\n p[sizeof(c->u) - 4] = (unsigned char)(c->Nl >> 24);\n p[sizeof(c->u) - 5] = (unsigned char)(c->Nl >> 32);\n p[sizeof(c->u) - 6] = (unsigned char)(c->Nl >> 40);\n p[sizeof(c->u) - 7] = (unsigned char)(c->Nl >> 48);\n p[sizeof(c->u) - 8] = (unsigned char)(c->Nl >> 56);\n p[sizeof(c->u) - 9] = (unsigned char)(c->Nh);\n p[sizeof(c->u) - 10] = (unsigned char)(c->Nh >> 8);\n p[sizeof(c->u) - 11] = (unsigned char)(c->Nh >> 16);\n p[sizeof(c->u) - 12] = (unsigned char)(c->Nh >> 24);\n p[sizeof(c->u) - 13] = (unsigned char)(c->Nh >> 32);\n p[sizeof(c->u) - 14] = (unsigned char)(c->Nh >> 40);\n p[sizeof(c->u) - 15] = (unsigned char)(c->Nh >> 48);\n p[sizeof(c->u) - 16] = (unsigned char)(c->Nh >> 56);\n#endif\n sha512_block_data_order(c, p, 1);\n if (md == 0)\n return 0;\n switch (c->md_len) {\n case SHA224_DIGEST_LENGTH:\n for (n = 0; n < SHA224_DIGEST_LENGTH / 8; n++) {\n SHA_LONG64 t = c->h[n];\n *(md++) = (unsigned char)(t >> 56);\n *(md++) = (unsigned char)(t >> 48);\n *(md++) = (unsigned char)(t >> 40);\n *(md++) = (unsigned char)(t >> 32);\n *(md++) = (unsigned char)(t >> 24);\n *(md++) = (unsigned char)(t >> 16);\n *(md++) = (unsigned char)(t >> 8);\n *(md++) = (unsigned char)(t);\n }\n {\n SHA_LONG64 t = c->h[SHA224_DIGEST_LENGTH / 8];\n *(md++) = (unsigned char)(t >> 56);\n *(md++) = (unsigned char)(t >> 48);\n *(md++) = (unsigned char)(t >> 40);\n *(md++) = (unsigned char)(t >> 32);\n }\n break;\n case SHA256_DIGEST_LENGTH:\n for (n = 0; n < SHA256_DIGEST_LENGTH / 8; n++) {\n SHA_LONG64 t = c->h[n];\n *(md++) = (unsigned char)(t >> 56);\n *(md++) = (unsigned char)(t >> 48);\n *(md++) = (unsigned char)(t >> 40);\n *(md++) = (unsigned char)(t >> 32);\n *(md++) = (unsigned char)(t >> 24);\n *(md++) = (unsigned char)(t >> 16);\n *(md++) = (unsigned char)(t >> 8);\n *(md++) = (unsigned char)(t);\n }\n break;\n case SHA384_DIGEST_LENGTH:\n for (n = 0; n < SHA384_DIGEST_LENGTH / 8; n++) {\n SHA_LONG64 t = c->h[n];\n *(md++) = (unsigned char)(t >> 56);\n *(md++) = (unsigned char)(t >> 48);\n *(md++) = (unsigned char)(t >> 40);\n *(md++) = (unsigned char)(t >> 32);\n *(md++) = (unsigned char)(t >> 24);\n *(md++) = (unsigned char)(t >> 16);\n *(md++) = (unsigned char)(t >> 8);\n *(md++) = (unsigned char)(t);\n }\n break;\n case SHA512_DIGEST_LENGTH:\n for (n = 0; n < SHA512_DIGEST_LENGTH / 8; n++) {\n SHA_LONG64 t = c->h[n];\n *(md++) = (unsigned char)(t >> 56);\n *(md++) = (unsigned char)(t >> 48);\n *(md++) = (unsigned char)(t >> 40);\n *(md++) = (unsigned char)(t >> 32);\n *(md++) = (unsigned char)(t >> 24);\n *(md++) = (unsigned char)(t >> 16);\n *(md++) = (unsigned char)(t >> 8);\n *(md++) = (unsigned char)(t);\n }\n break;\n default:\n return 0;\n }\n return 1;\n}']
2,595
0
https://github.com/libav/libav/blob/60392480181f24ebf3ab48d8ac3614705de90152/libavutil/buffer.c/#L161
int av_buffer_realloc(AVBufferRef **pbuf, int size) { AVBufferRef *buf = *pbuf; uint8_t *tmp; if (!buf) { uint8_t *data = av_realloc(NULL, size); if (!data) return AVERROR(ENOMEM); buf = av_buffer_create(data, size, av_buffer_default_free, NULL, 0); if (!buf) { av_freep(&data); return AVERROR(ENOMEM); } buf->buffer->flags |= BUFFER_FLAG_REALLOCATABLE; *pbuf = buf; return 0; } else if (buf->size == size) return 0; if (!(buf->buffer->flags & BUFFER_FLAG_REALLOCATABLE) || !av_buffer_is_writable(buf)) { AVBufferRef *new = NULL; av_buffer_realloc(&new, size); if (!new) return AVERROR(ENOMEM); memcpy(new->data, buf->data, FFMIN(size, buf->size)); av_buffer_unref(pbuf); *pbuf = new; return 0; } tmp = av_realloc(buf->buffer->data, size); if (!tmp) return AVERROR(ENOMEM); buf->buffer->data = buf->data = tmp; buf->buffer->size = buf->size = size; return 0; }
['int av_buffer_realloc(AVBufferRef **pbuf, int size)\n{\n AVBufferRef *buf = *pbuf;\n uint8_t *tmp;\n if (!buf) {\n uint8_t *data = av_realloc(NULL, size);\n if (!data)\n return AVERROR(ENOMEM);\n buf = av_buffer_create(data, size, av_buffer_default_free, NULL, 0);\n if (!buf) {\n av_freep(&data);\n return AVERROR(ENOMEM);\n }\n buf->buffer->flags |= BUFFER_FLAG_REALLOCATABLE;\n *pbuf = buf;\n return 0;\n } else if (buf->size == size)\n return 0;\n if (!(buf->buffer->flags & BUFFER_FLAG_REALLOCATABLE) ||\n !av_buffer_is_writable(buf)) {\n AVBufferRef *new = NULL;\n av_buffer_realloc(&new, size);\n if (!new)\n return AVERROR(ENOMEM);\n memcpy(new->data, buf->data, FFMIN(size, buf->size));\n av_buffer_unref(pbuf);\n *pbuf = new;\n return 0;\n }\n tmp = av_realloc(buf->buffer->data, size);\n if (!tmp)\n return AVERROR(ENOMEM);\n buf->buffer->data = buf->data = tmp;\n buf->buffer->size = buf->size = size;\n return 0;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if (size > (INT_MAX - 16))\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if (!ptr)\n return av_malloc(size);\n diff = ((char *)ptr)[-1];\n return (char *)realloc((char *)ptr - diff, size + diff) + diff;\n#elif HAVE_ALIGNED_MALLOC\n return _aligned_realloc(ptr, size, 32);\n#else\n return realloc(ptr, size);\n#endif\n}']
2,596
0
https://github.com/openssl/openssl/blob/d9c989fe3f137580ee627c91e01245e78b0b41ff/test/crltest.c/#L277
static int verify(X509 *leaf, X509 *root, STACK_OF(X509_CRL) *crls, unsigned long flags) { X509_STORE_CTX *ctx = X509_STORE_CTX_new(); X509_STORE *store = X509_STORE_new(); X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new(); STACK_OF(X509) *roots = sk_X509_new_null(); int status = X509_V_ERR_UNSPECIFIED; if (!TEST_ptr(ctx) || !TEST_ptr(store) || !TEST_ptr(param) || !TEST_ptr(roots)) goto err; X509_up_ref(root); if (!TEST_true(sk_X509_push(roots, root)) || !TEST_true(X509_STORE_CTX_init(ctx, store, leaf, NULL))) goto err; X509_STORE_CTX_set0_trusted_stack(ctx, roots); X509_STORE_CTX_set0_crls(ctx, crls); X509_VERIFY_PARAM_set_time(param, PARAM_TIME); if (!TEST_long_eq(X509_VERIFY_PARAM_get_time(param), PARAM_TIME)) goto err; X509_VERIFY_PARAM_set_depth(param, 16); if (flags) X509_VERIFY_PARAM_set_flags(param, flags); X509_STORE_CTX_set0_param(ctx, param); ERR_clear_error(); status = X509_verify_cert(ctx) == 1 ? X509_V_OK : X509_STORE_CTX_get_error(ctx); err: sk_X509_pop_free(roots, X509_free); sk_X509_CRL_pop_free(crls, X509_CRL_free); X509_STORE_CTX_free(ctx); X509_STORE_free(store); return status; }
['static int verify(X509 *leaf, X509 *root, STACK_OF(X509_CRL) *crls,\n unsigned long flags)\n{\n X509_STORE_CTX *ctx = X509_STORE_CTX_new();\n X509_STORE *store = X509_STORE_new();\n X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new();\n STACK_OF(X509) *roots = sk_X509_new_null();\n int status = X509_V_ERR_UNSPECIFIED;\n if (!TEST_ptr(ctx)\n || !TEST_ptr(store)\n || !TEST_ptr(param)\n || !TEST_ptr(roots))\n goto err;\n X509_up_ref(root);\n if (!TEST_true(sk_X509_push(roots, root))\n || !TEST_true(X509_STORE_CTX_init(ctx, store, leaf, NULL)))\n goto err;\n X509_STORE_CTX_set0_trusted_stack(ctx, roots);\n X509_STORE_CTX_set0_crls(ctx, crls);\n X509_VERIFY_PARAM_set_time(param, PARAM_TIME);\n if (!TEST_long_eq(X509_VERIFY_PARAM_get_time(param), PARAM_TIME))\n goto err;\n X509_VERIFY_PARAM_set_depth(param, 16);\n if (flags)\n X509_VERIFY_PARAM_set_flags(param, flags);\n X509_STORE_CTX_set0_param(ctx, param);\n ERR_clear_error();\n status = X509_verify_cert(ctx) == 1 ? X509_V_OK\n : X509_STORE_CTX_get_error(ctx);\nerr:\n sk_X509_pop_free(roots, X509_free);\n sk_X509_CRL_pop_free(crls, X509_CRL_free);\n X509_STORE_CTX_free(ctx);\n X509_STORE_free(store);\n return status;\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 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}', 'DEFINE_STACK_OF(X509)', 'OPENSSL_STACK *OPENSSL_sk_new_null(void)\n{\n return OPENSSL_sk_new_reserve(NULL, 0);\n}', 'int test_ptr(const char *file, int line, const char *s, const void *p)\n{\n if (p != NULL)\n return 1;\n test_fail_message(NULL, file, line, "ptr", s, "NULL", "!=", "%p", p);\n return 0;\n}', 'DEFINE_STACK_OF(X509_CRL)', '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 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}']
2,597
0
https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L268
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int ec_GFp_simple_field_inv(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,\n BN_CTX *ctx)\n{\n BIGNUM *e = NULL;\n BN_CTX *new_ctx = NULL;\n int ret = 0;\n if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL)\n return 0;\n BN_CTX_start(ctx);\n if ((e = BN_CTX_get(ctx)) == NULL)\n goto err;\n do {\n if (!BN_priv_rand_range(e, group->field))\n goto err;\n } while (BN_is_zero(e));\n if (!group->meth->field_mul(group, r, a, e, ctx))\n goto err;\n if (!BN_mod_inverse(r, r, group->field, ctx)) {\n ECerr(EC_F_EC_GFP_SIMPLE_FIELD_INV, EC_R_CANNOT_INVERT);\n goto err;\n }\n if (!group->meth->field_mul(group, r, r, e, ctx))\n goto err;\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("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', '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("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
2,598
0
https://github.com/libav/libav/blob/33147993689223956d735e691dca45588a10c28f/ffmpeg.c/#L3080
static void new_video_stream(AVFormatContext *oc) { AVStream *st; AVCodecContext *video_enc; enum CodecID codec_id; st = av_new_stream(oc, oc->nb_streams); if (!st) { fprintf(stderr, "Could not alloc stream\n"); av_exit(1); } avcodec_get_context_defaults2(st->codec, CODEC_TYPE_VIDEO); bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters; video_bitstream_filters= NULL; avcodec_thread_init(st->codec, thread_count); video_enc = st->codec; if(video_codec_tag) video_enc->codec_tag= video_codec_tag; if( (video_global_header&1) || (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))){ video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; avcodec_opts[CODEC_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER; } if(video_global_header&2){ video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER; avcodec_opts[CODEC_TYPE_VIDEO]->flags2|= CODEC_FLAG2_LOCAL_HEADER; } if (video_stream_copy) { st->stream_copy = 1; video_enc->codec_type = CODEC_TYPE_VIDEO; video_enc->sample_aspect_ratio = st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255); } else { const char *p; int i; AVCodec *codec; AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1}; if (video_codec_name) { codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 1); codec = avcodec_find_encoder_by_name(video_codec_name); output_codecs[nb_ocodecs] = codec; } else { codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO); codec = avcodec_find_encoder(codec_id); } video_enc->codec_id = codec_id; set_context_opts(video_enc, avcodec_opts[CODEC_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM); if (codec && codec->supported_framerates && !force_fps) fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)]; video_enc->time_base.den = fps.num; video_enc->time_base.num = fps.den; video_enc->width = frame_width + frame_padright + frame_padleft; video_enc->height = frame_height + frame_padtop + frame_padbottom; video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255); video_enc->pix_fmt = frame_pix_fmt; st->sample_aspect_ratio = video_enc->sample_aspect_ratio; if(codec && codec->pix_fmts){ const enum PixelFormat *p= codec->pix_fmts; for(; *p!=-1; p++){ if(*p == video_enc->pix_fmt) break; } if(*p == -1) video_enc->pix_fmt = codec->pix_fmts[0]; } if (intra_only) video_enc->gop_size = 0; if (video_qscale || same_quality) { video_enc->flags |= CODEC_FLAG_QSCALE; video_enc->global_quality= st->quality = FF_QP2LAMBDA * video_qscale; } if(intra_matrix) video_enc->intra_matrix = intra_matrix; if(inter_matrix) video_enc->inter_matrix = inter_matrix; p= video_rc_override_string; for(i=0; p; i++){ int start, end, q; int e=sscanf(p, "%d,%d,%d", &start, &end, &q); if(e!=3){ fprintf(stderr, "error parsing rc_override\n"); av_exit(1); } video_enc->rc_override= av_realloc(video_enc->rc_override, sizeof(RcOverride)*(i+1)); video_enc->rc_override[i].start_frame= start; video_enc->rc_override[i].end_frame = end; if(q>0){ video_enc->rc_override[i].qscale= q; video_enc->rc_override[i].quality_factor= 1.0; } else{ video_enc->rc_override[i].qscale= 0; video_enc->rc_override[i].quality_factor= -q/100.0; } p= strchr(p, '/'); if(p) p++; } video_enc->rc_override_count=i; if (!video_enc->rc_initial_buffer_occupancy) video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4; video_enc->me_threshold= me_threshold; video_enc->intra_dc_precision= intra_dc_precision - 8; if (do_psnr) video_enc->flags|= CODEC_FLAG_PSNR; if (do_pass) { if (do_pass == 1) { video_enc->flags |= CODEC_FLAG_PASS1; } else { video_enc->flags |= CODEC_FLAG_PASS2; } } } nb_ocodecs++; if (video_language) { av_metadata_set(&st->metadata, "language", video_language); av_freep(&video_language); } video_disable = 0; av_freep(&video_codec_name); video_stream_copy = 0; }
['static void new_video_stream(AVFormatContext *oc)\n{\n AVStream *st;\n AVCodecContext *video_enc;\n enum CodecID codec_id;\n st = av_new_stream(oc, oc->nb_streams);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n av_exit(1);\n }\n avcodec_get_context_defaults2(st->codec, CODEC_TYPE_VIDEO);\n bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters;\n video_bitstream_filters= NULL;\n avcodec_thread_init(st->codec, thread_count);\n video_enc = st->codec;\n if(video_codec_tag)\n video_enc->codec_tag= video_codec_tag;\n if( (video_global_header&1)\n || (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))){\n video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;\n avcodec_opts[CODEC_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;\n }\n if(video_global_header&2){\n video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER;\n avcodec_opts[CODEC_TYPE_VIDEO]->flags2|= CODEC_FLAG2_LOCAL_HEADER;\n }\n if (video_stream_copy) {\n st->stream_copy = 1;\n video_enc->codec_type = CODEC_TYPE_VIDEO;\n video_enc->sample_aspect_ratio =\n st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);\n } else {\n const char *p;\n int i;\n AVCodec *codec;\n AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};\n if (video_codec_name) {\n codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 1);\n codec = avcodec_find_encoder_by_name(video_codec_name);\n output_codecs[nb_ocodecs] = codec;\n } else {\n codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);\n codec = avcodec_find_encoder(codec_id);\n }\n video_enc->codec_id = codec_id;\n set_context_opts(video_enc, avcodec_opts[CODEC_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);\n if (codec && codec->supported_framerates && !force_fps)\n fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)];\n video_enc->time_base.den = fps.num;\n video_enc->time_base.num = fps.den;\n video_enc->width = frame_width + frame_padright + frame_padleft;\n video_enc->height = frame_height + frame_padtop + frame_padbottom;\n video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255);\n video_enc->pix_fmt = frame_pix_fmt;\n st->sample_aspect_ratio = video_enc->sample_aspect_ratio;\n if(codec && codec->pix_fmts){\n const enum PixelFormat *p= codec->pix_fmts;\n for(; *p!=-1; p++){\n if(*p == video_enc->pix_fmt)\n break;\n }\n if(*p == -1)\n video_enc->pix_fmt = codec->pix_fmts[0];\n }\n if (intra_only)\n video_enc->gop_size = 0;\n if (video_qscale || same_quality) {\n video_enc->flags |= CODEC_FLAG_QSCALE;\n video_enc->global_quality=\n st->quality = FF_QP2LAMBDA * video_qscale;\n }\n if(intra_matrix)\n video_enc->intra_matrix = intra_matrix;\n if(inter_matrix)\n video_enc->inter_matrix = inter_matrix;\n p= video_rc_override_string;\n for(i=0; p; i++){\n int start, end, q;\n int e=sscanf(p, "%d,%d,%d", &start, &end, &q);\n if(e!=3){\n fprintf(stderr, "error parsing rc_override\\n");\n av_exit(1);\n }\n video_enc->rc_override=\n av_realloc(video_enc->rc_override,\n sizeof(RcOverride)*(i+1));\n video_enc->rc_override[i].start_frame= start;\n video_enc->rc_override[i].end_frame = end;\n if(q>0){\n video_enc->rc_override[i].qscale= q;\n video_enc->rc_override[i].quality_factor= 1.0;\n }\n else{\n video_enc->rc_override[i].qscale= 0;\n video_enc->rc_override[i].quality_factor= -q/100.0;\n }\n p= strchr(p, \'/\');\n if(p) p++;\n }\n video_enc->rc_override_count=i;\n if (!video_enc->rc_initial_buffer_occupancy)\n video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;\n video_enc->me_threshold= me_threshold;\n video_enc->intra_dc_precision= intra_dc_precision - 8;\n if (do_psnr)\n video_enc->flags|= CODEC_FLAG_PSNR;\n if (do_pass) {\n if (do_pass == 1) {\n video_enc->flags |= CODEC_FLAG_PASS1;\n } else {\n video_enc->flags |= CODEC_FLAG_PASS2;\n }\n }\n }\n nb_ocodecs++;\n if (video_language) {\n av_metadata_set(&st->metadata, "language", video_language);\n av_freep(&video_language);\n }\n video_disable = 0;\n av_freep(&video_codec_name);\n video_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 st->probe_packets = MAX_PROBE_PACKETS;\n av_set_pts_info(st, 33, 1, 90000);\n st->last_IP_pts = AV_NOPTS_VALUE;\n for(i=0; i<MAX_REORDER_DELAY+1; i++)\n st->pts_buffer[i]= AV_NOPTS_VALUE;\n st->reference_dts = AV_NOPTS_VALUE;\n st->sample_aspect_ratio = (AVRational){0,1};\n s->streams[s->nb_streams++] = st;\n return st;\n}']
2,599
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 test_rshift(BIO *bp,BN_CTX *ctx)\n\t{\n\tBIGNUM *a,*b,*c,*d,*e;\n\tint i;\n\ta=BN_new();\n\tb=BN_new();\n\tc=BN_new();\n\td=BN_new();\n\te=BN_new();\n\tBN_one(c);\n\tBN_bntest_rand(a,200,0,0);\n\ta->neg=rand_neg();\n\tfor (i=0; i<num0; i++)\n\t\t{\n\t\tBN_rshift(b,a,i+1);\n\t\tBN_add(c,c,c);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,a);\n\t\t\t\tBIO_puts(bp," / ");\n\t\t\t\tBN_print(bp,c);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,b);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\tBN_div(d,e,a,c,ctx);\n\t\tBN_sub(d,d,b);\n\t\tif(!BN_is_zero(d))\n\t\t {\n\t\t fprintf(stderr,"Right shift test failed!\\n");\n\t\t return 0;\n\t\t }\n\t\t}\n\tBN_free(a);\n\tBN_free(b);\n\tBN_free(c);\n\tBN_free(d);\n\tBN_free(e);\n\treturn(1);\n\t}', '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_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}', '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}']
2,600
0
https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L271
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['int ec_GF2m_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point,\n BN_CTX *ctx)\n{\n int ret = -1;\n BN_CTX *new_ctx = NULL;\n BIGNUM *lh, *y2;\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 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 if (!point->Z_is_one)\n return -1;\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 y2 = BN_CTX_get(ctx);\n lh = BN_CTX_get(ctx);\n if (lh == NULL)\n goto err;\n if (!BN_GF2m_add(lh, point->X, group->a))\n goto err;\n if (!field_mul(group, lh, lh, point->X, ctx))\n goto err;\n if (!BN_GF2m_add(lh, lh, point->Y))\n goto err;\n if (!field_mul(group, lh, lh, point->X, ctx))\n goto err;\n if (!BN_GF2m_add(lh, lh, group->b))\n goto err;\n if (!field_sqr(group, y2, point->Y, ctx))\n goto err;\n if (!BN_GF2m_add(lh, lh, y2))\n goto err;\n ret = BN_is_zero(lh);\n err:\n if (ctx)\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_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int i;\n const BIGNUM *at, *bt;\n bn_check_top(a);\n bn_check_top(b);\n if (a->top < b->top) {\n at = b;\n bt = a;\n } else {\n at = a;\n bt = b;\n }\n if (bn_wexpand(r, at->top) == NULL)\n return 0;\n for (i = 0; i < bt->top; i++) {\n r->d[i] = at->d[i] ^ bt->d[i];\n }\n for (; i < at->top; i++) {\n r->d[i] = at->d[i];\n }\n r->top = at->top;\n bn_correct_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n 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}']