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
33,501
0
https://github.com/openssl/openssl/blob/49cd47eaababc8c57871b929080fc1357e2ad7b8/crypto/rsa/rsa_oaep.c/#L279
int PKCS1_MGF1(unsigned char *mask, long len, const unsigned char *seed, long seedlen, const EVP_MD *dgst) { long i, outlen = 0; unsigned char cnt[4]; EVP_MD_CTX *c = EVP_MD_CTX_new(); unsigned char md[EVP_MAX_MD_SIZE]; int mdlen; int rv = -1; if (c == NULL) goto err; mdlen = EVP_MD_size(dgst); if (mdlen < 0) goto err; for (i = 0; outlen < len; i++) { cnt[0] = (unsigned char)((i >> 24) & 255); cnt[1] = (unsigned char)((i >> 16) & 255); cnt[2] = (unsigned char)((i >> 8)) & 255; cnt[3] = (unsigned char)(i & 255); if (!EVP_DigestInit_ex(c, dgst, NULL) || !EVP_DigestUpdate(c, seed, seedlen) || !EVP_DigestUpdate(c, cnt, 4)) goto err; if (outlen + mdlen <= len) { if (!EVP_DigestFinal_ex(c, mask + outlen, NULL)) goto err; outlen += mdlen; } else { if (!EVP_DigestFinal_ex(c, md, NULL)) goto err; memcpy(mask + outlen, md, len - outlen); outlen = len; } } rv = 0; err: EVP_MD_CTX_free(c); return rv; }
['int PKCS1_MGF1(unsigned char *mask, long len,\n const unsigned char *seed, long seedlen, const EVP_MD *dgst)\n{\n long i, outlen = 0;\n unsigned char cnt[4];\n EVP_MD_CTX *c = EVP_MD_CTX_new();\n unsigned char md[EVP_MAX_MD_SIZE];\n int mdlen;\n int rv = -1;\n if (c == NULL)\n goto err;\n mdlen = EVP_MD_size(dgst);\n if (mdlen < 0)\n goto err;\n for (i = 0; outlen < len; i++) {\n cnt[0] = (unsigned char)((i >> 24) & 255);\n cnt[1] = (unsigned char)((i >> 16) & 255);\n cnt[2] = (unsigned char)((i >> 8)) & 255;\n cnt[3] = (unsigned char)(i & 255);\n if (!EVP_DigestInit_ex(c, dgst, NULL)\n || !EVP_DigestUpdate(c, seed, seedlen)\n || !EVP_DigestUpdate(c, cnt, 4))\n goto err;\n if (outlen + mdlen <= len) {\n if (!EVP_DigestFinal_ex(c, mask + outlen, NULL))\n goto err;\n outlen += mdlen;\n } else {\n if (!EVP_DigestFinal_ex(c, md, NULL))\n goto err;\n memcpy(mask + outlen, md, len - outlen);\n outlen = len;\n }\n }\n rv = 0;\n err:\n EVP_MD_CTX_free(c);\n return rv;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n 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 EVP_MD_size(const EVP_MD *md)\n{\n if (!md) {\n EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);\n return -1;\n }\n return md->md_size;\n}', 'int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)\n{\n return ctx->update(ctx, data, count);\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
33,502
0
https://github.com/libav/libav/blob/f653095bdd5f6c25960f75b81b138dd78f73ca37/libavcodec/mpegaudiodec.c/#L1098
static void imdct36(int *out, int *buf, int *in, int *win) { int i, j, t0, t1, t2, t3, s0, s1, s2, s3; int tmp[18], *tmp1, *in1; for(i=17;i>=1;i--) in[i] += in[i-1]; for(i=17;i>=3;i-=2) in[i] += in[i-2]; for(j=0;j<2;j++) { tmp1 = tmp + j; in1 = in + j; #if 0 int64_t t0, t1, t2, t3; t2 = in1[2*4] + in1[2*8] - in1[2*2]; t3 = (in1[2*0] + (int64_t)(in1[2*6]>>1))<<32; t1 = in1[2*0] - in1[2*6]; tmp1[ 6] = t1 - (t2>>1); tmp1[16] = t1 + t2; t0 = MUL64(2*(in1[2*2] + in1[2*4]), C2); t1 = MUL64( in1[2*4] - in1[2*8] , -2*C8); t2 = MUL64(2*(in1[2*2] + in1[2*8]), -C4); tmp1[10] = (t3 - t0 - t2) >> 32; tmp1[ 2] = (t3 + t0 + t1) >> 32; tmp1[14] = (t3 + t2 - t1) >> 32; tmp1[ 4] = MULH(2*(in1[2*5] + in1[2*7] - in1[2*1]), -C3); t2 = MUL64(2*(in1[2*1] + in1[2*5]), C1); t3 = MUL64( in1[2*5] - in1[2*7] , -2*C7); t0 = MUL64(2*in1[2*3], C3); t1 = MUL64(2*(in1[2*1] + in1[2*7]), -C5); tmp1[ 0] = (t2 + t3 + t0) >> 32; tmp1[12] = (t2 + t1 - t0) >> 32; tmp1[ 8] = (t3 - t1 - t0) >> 32; #else t2 = in1[2*4] + in1[2*8] - in1[2*2]; t3 = in1[2*0] + (in1[2*6]>>1); t1 = in1[2*0] - in1[2*6]; tmp1[ 6] = t1 - (t2>>1); tmp1[16] = t1 + t2; t0 = MULH(2*(in1[2*2] + in1[2*4]), C2); t1 = MULH( in1[2*4] - in1[2*8] , -2*C8); t2 = MULH(2*(in1[2*2] + in1[2*8]), -C4); tmp1[10] = t3 - t0 - t2; tmp1[ 2] = t3 + t0 + t1; tmp1[14] = t3 + t2 - t1; tmp1[ 4] = MULH(2*(in1[2*5] + in1[2*7] - in1[2*1]), -C3); t2 = MULH(2*(in1[2*1] + in1[2*5]), C1); t3 = MULH( in1[2*5] - in1[2*7] , -2*C7); t0 = MULH(2*in1[2*3], C3); t1 = MULH(2*(in1[2*1] + in1[2*7]), -C5); tmp1[ 0] = t2 + t3 + t0; tmp1[12] = t2 + t1 - t0; tmp1[ 8] = t3 - t1 - t0; #endif } i = 0; for(j=0;j<4;j++) { t0 = tmp[i]; t1 = tmp[i + 2]; s0 = t1 + t0; s2 = t1 - t0; t2 = tmp[i + 1]; t3 = tmp[i + 3]; s1 = MULH(2*(t3 + t2), icos36h[j]); s3 = MULL(t3 - t2, icos36[8 - j], FRAC_BITS); t0 = s0 + s1; t1 = s0 - s1; out[(9 + j)*SBLIMIT] = MULH(t1, win[9 + j]) + buf[9 + j]; out[(8 - j)*SBLIMIT] = MULH(t1, win[8 - j]) + buf[8 - j]; buf[9 + j] = MULH(t0, win[18 + 9 + j]); buf[8 - j] = MULH(t0, win[18 + 8 - j]); t0 = s2 + s3; t1 = s2 - s3; out[(9 + 8 - j)*SBLIMIT] = MULH(t1, win[9 + 8 - j]) + buf[9 + 8 - j]; out[( j)*SBLIMIT] = MULH(t1, win[ j]) + buf[ j]; buf[9 + 8 - j] = MULH(t0, win[18 + 9 + 8 - j]); buf[ + j] = MULH(t0, win[18 + j]); i += 4; } s0 = tmp[16]; s1 = MULH(2*tmp[17], icos36h[4]); t0 = s0 + s1; t1 = s0 - s1; out[(9 + 4)*SBLIMIT] = MULH(t1, win[9 + 4]) + buf[9 + 4]; out[(8 - 4)*SBLIMIT] = MULH(t1, win[8 - 4]) + buf[8 - 4]; buf[9 + 4] = MULH(t0, win[18 + 9 + 4]); buf[8 - 4] = MULH(t0, win[18 + 8 - 4]); }
['static void imdct36(int *out, int *buf, int *in, int *win)\n{\n int i, j, t0, t1, t2, t3, s0, s1, s2, s3;\n int tmp[18], *tmp1, *in1;\n for(i=17;i>=1;i--)\n in[i] += in[i-1];\n for(i=17;i>=3;i-=2)\n in[i] += in[i-2];\n for(j=0;j<2;j++) {\n tmp1 = tmp + j;\n in1 = in + j;\n#if 0\n int64_t t0, t1, t2, t3;\n t2 = in1[2*4] + in1[2*8] - in1[2*2];\n t3 = (in1[2*0] + (int64_t)(in1[2*6]>>1))<<32;\n t1 = in1[2*0] - in1[2*6];\n tmp1[ 6] = t1 - (t2>>1);\n tmp1[16] = t1 + t2;\n t0 = MUL64(2*(in1[2*2] + in1[2*4]), C2);\n t1 = MUL64( in1[2*4] - in1[2*8] , -2*C8);\n t2 = MUL64(2*(in1[2*2] + in1[2*8]), -C4);\n tmp1[10] = (t3 - t0 - t2) >> 32;\n tmp1[ 2] = (t3 + t0 + t1) >> 32;\n tmp1[14] = (t3 + t2 - t1) >> 32;\n tmp1[ 4] = MULH(2*(in1[2*5] + in1[2*7] - in1[2*1]), -C3);\n t2 = MUL64(2*(in1[2*1] + in1[2*5]), C1);\n t3 = MUL64( in1[2*5] - in1[2*7] , -2*C7);\n t0 = MUL64(2*in1[2*3], C3);\n t1 = MUL64(2*(in1[2*1] + in1[2*7]), -C5);\n tmp1[ 0] = (t2 + t3 + t0) >> 32;\n tmp1[12] = (t2 + t1 - t0) >> 32;\n tmp1[ 8] = (t3 - t1 - t0) >> 32;\n#else\n t2 = in1[2*4] + in1[2*8] - in1[2*2];\n t3 = in1[2*0] + (in1[2*6]>>1);\n t1 = in1[2*0] - in1[2*6];\n tmp1[ 6] = t1 - (t2>>1);\n tmp1[16] = t1 + t2;\n t0 = MULH(2*(in1[2*2] + in1[2*4]), C2);\n t1 = MULH( in1[2*4] - in1[2*8] , -2*C8);\n t2 = MULH(2*(in1[2*2] + in1[2*8]), -C4);\n tmp1[10] = t3 - t0 - t2;\n tmp1[ 2] = t3 + t0 + t1;\n tmp1[14] = t3 + t2 - t1;\n tmp1[ 4] = MULH(2*(in1[2*5] + in1[2*7] - in1[2*1]), -C3);\n t2 = MULH(2*(in1[2*1] + in1[2*5]), C1);\n t3 = MULH( in1[2*5] - in1[2*7] , -2*C7);\n t0 = MULH(2*in1[2*3], C3);\n t1 = MULH(2*(in1[2*1] + in1[2*7]), -C5);\n tmp1[ 0] = t2 + t3 + t0;\n tmp1[12] = t2 + t1 - t0;\n tmp1[ 8] = t3 - t1 - t0;\n#endif\n }\n i = 0;\n for(j=0;j<4;j++) {\n t0 = tmp[i];\n t1 = tmp[i + 2];\n s0 = t1 + t0;\n s2 = t1 - t0;\n t2 = tmp[i + 1];\n t3 = tmp[i + 3];\n s1 = MULH(2*(t3 + t2), icos36h[j]);\n s3 = MULL(t3 - t2, icos36[8 - j], FRAC_BITS);\n t0 = s0 + s1;\n t1 = s0 - s1;\n out[(9 + j)*SBLIMIT] = MULH(t1, win[9 + j]) + buf[9 + j];\n out[(8 - j)*SBLIMIT] = MULH(t1, win[8 - j]) + buf[8 - j];\n buf[9 + j] = MULH(t0, win[18 + 9 + j]);\n buf[8 - j] = MULH(t0, win[18 + 8 - j]);\n t0 = s2 + s3;\n t1 = s2 - s3;\n out[(9 + 8 - j)*SBLIMIT] = MULH(t1, win[9 + 8 - j]) + buf[9 + 8 - j];\n out[( j)*SBLIMIT] = MULH(t1, win[ j]) + buf[ j];\n buf[9 + 8 - j] = MULH(t0, win[18 + 9 + 8 - j]);\n buf[ + j] = MULH(t0, win[18 + j]);\n i += 4;\n }\n s0 = tmp[16];\n s1 = MULH(2*tmp[17], icos36h[4]);\n t0 = s0 + s1;\n t1 = s0 - s1;\n out[(9 + 4)*SBLIMIT] = MULH(t1, win[9 + 4]) + buf[9 + 4];\n out[(8 - 4)*SBLIMIT] = MULH(t1, win[8 - 4]) + buf[8 - 4];\n buf[9 + 4] = MULH(t0, win[18 + 9 + 4]);\n buf[8 - 4] = MULH(t0, win[18 + 8 - 4]);\n}']
33,503
0
https://github.com/openssl/openssl/blob/5d1c09de1f2736e1d4b1877206d08455ec75f558/crypto/bn/bn_lib.c/#L232
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return NULL; } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return NULL; } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(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 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}', '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 r->flags |= BN_FLG_FIXED_TOP;\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->flags |= BN_FLG_FIXED_TOP;\n ret->neg = r->neg;\n rp = ret->d;\n ap = &(r->d[nl]);\n carry -= bn_sub_words(rp, ap, np, nl);\n for (i = 0; i < nl; i++) {\n rp[i] = (carry & ap[i]) | (~carry & rp[i]);\n ap[i] = 0;\n }\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
33,504
0
https://github.com/openssl/openssl/blob/0350ef69add8758dd180e73cbc7c1961bf64e503/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['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 != NULL && ret != in) {\n BN_clear_free(ret);\n }\n ret = NULL;\n }\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n 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}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_mod_exp_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 *d, *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 BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return -1;\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_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else\n ret = BN_one(rr);\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 d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (d == NULL || r == NULL || 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) && (mont != NULL))\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *Ri, *R;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n BN_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', '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 (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 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 local_A, local_B;\n BIGNUM *pA, *pB;\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 pB = &local_B;\n BN_with_flags(pB, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, pB, A, ctx))\n goto err;\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n pA = &local_A;\n BN_with_flags(pA, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, pA, B, ctx))\n goto err;\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}', '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}']
33,505
0
https://github.com/libav/libav/blob/bb770c5b522bdd81b65ea4391579e5ebdd62a047/libavcodec/wmavoice.c/#L534
static void dequant_lsp16r(GetBitContext *gb, double *i_lsps, const double *old, double *a1, double *a2, int q_mode) { static const uint16_t vec_sizes[3] = { 128, 128, 128 }; static const double mul_lsf[3] = { 1.2232979501e-3, 1.4062241527e-3, 1.6114744851e-3 }; static const double base_lsf[3] = { M_PI * -5.5830e-2, M_PI * -5.2908e-2, M_PI * -5.4776e-2 }; const float (*ipol_tab)[2][16] = q_mode ? wmavoice_lsp16_intercoeff_b : wmavoice_lsp16_intercoeff_a; uint16_t interpol, v[3]; int n; dequant_lsp16i(gb, i_lsps); interpol = get_bits(gb, 5); v[0] = get_bits(gb, 7); v[1] = get_bits(gb, 7); v[2] = get_bits(gb, 7); for (n = 0; n < 16; n++) { double delta = old[n] - i_lsps[n]; a1[n] = ipol_tab[interpol][0][n] * delta + i_lsps[n]; a1[16 + n] = ipol_tab[interpol][1][n] * delta + i_lsps[n]; } dequant_lsps( a2, 10, v, vec_sizes, 1, wmavoice_dq_lsp16r1, mul_lsf, base_lsf); dequant_lsps(&a2[10], 10, &v[1], &vec_sizes[1], 1, wmavoice_dq_lsp16r2, &mul_lsf[1], &base_lsf[1]); dequant_lsps(&a2[20], 12, &v[2], &vec_sizes[2], 1, wmavoice_dq_lsp16r3, &mul_lsf[2], &base_lsf[2]); }
['static int synth_superframe(AVCodecContext *ctx,\n float *samples, int *data_size)\n{\n WMAVoiceContext *s = ctx->priv_data;\n GetBitContext *gb = &s->gb, s_gb;\n int n, res, n_samples = 480;\n double lsps[MAX_FRAMES][MAX_LSPS];\n const double *mean_lsf = s->lsps == 16 ?\n wmavoice_mean_lsf16[s->lsp_def_mode] : wmavoice_mean_lsf10[s->lsp_def_mode];\n float excitation[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE + 12];\n float synth[MAX_LSPS + MAX_SFRAMESIZE];\n memcpy(synth, s->synth_history,\n s->lsps * sizeof(*synth));\n memcpy(excitation, s->excitation_history,\n s->history_nsamples * sizeof(*excitation));\n if (s->sframe_cache_size > 0) {\n gb = &s_gb;\n init_get_bits(gb, s->sframe_cache, s->sframe_cache_size);\n s->sframe_cache_size = 0;\n }\n if ((res = check_bits_for_superframe(gb, s)) == 1) return 1;\n if (!get_bits1(gb)) {\n av_log_missing_feature(ctx, "WMAPro-in-WMAVoice support", 1);\n return -1;\n }\n if (get_bits1(gb)) {\n if ((n_samples = get_bits(gb, 12)) > 480) {\n av_log(ctx, AV_LOG_ERROR,\n "Superframe encodes >480 samples (%d), not allowed\\n",\n n_samples);\n return -1;\n }\n }\n if (s->has_residual_lsps) {\n double prev_lsps[MAX_LSPS], a1[MAX_LSPS * 2], a2[MAX_LSPS * 2];\n for (n = 0; n < s->lsps; n++)\n prev_lsps[n] = s->prev_lsps[n] - mean_lsf[n];\n if (s->lsps == 10) {\n dequant_lsp10r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);\n } else\n dequant_lsp16r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);\n for (n = 0; n < s->lsps; n++) {\n lsps[0][n] = mean_lsf[n] + (a1[n] - a2[n * 2]);\n lsps[1][n] = mean_lsf[n] + (a1[s->lsps + n] - a2[n * 2 + 1]);\n lsps[2][n] += mean_lsf[n];\n }\n for (n = 0; n < 3; n++)\n stabilize_lsps(lsps[n], s->lsps);\n }\n for (n = 0; n < 3; n++) {\n if (!s->has_residual_lsps) {\n int m;\n if (s->lsps == 10) {\n dequant_lsp10i(gb, lsps[n]);\n } else\n dequant_lsp16i(gb, lsps[n]);\n for (m = 0; m < s->lsps; m++)\n lsps[n][m] += mean_lsf[m];\n stabilize_lsps(lsps[n], s->lsps);\n }\n if ((res = synth_frame(ctx, gb,\n &samples[n * MAX_FRAMESIZE],\n lsps[n], n == 0 ? s->prev_lsps : lsps[n - 1],\n &excitation[s->history_nsamples + n * MAX_FRAMESIZE],\n &synth[s->lsps + n * MAX_FRAMESIZE])))\n return res;\n }\n if (get_bits1(gb)) {\n res = get_bits(gb, 4);\n skip_bits(gb, 10 * (res + 1));\n }\n *data_size = n_samples * sizeof(float);\n memcpy(s->prev_lsps, lsps[2],\n s->lsps * sizeof(*s->prev_lsps));\n memcpy(s->synth_history, &synth[MAX_SFRAMESIZE],\n s->lsps * sizeof(*synth));\n memcpy(s->excitation_history, &excitation[MAX_SFRAMESIZE],\n s->history_nsamples * sizeof(*excitation));\n return 0;\n}', 'static void dequant_lsp16r(GetBitContext *gb,\n double *i_lsps, const double *old,\n double *a1, double *a2, int q_mode)\n{\n static const uint16_t vec_sizes[3] = { 128, 128, 128 };\n static const double mul_lsf[3] = {\n 1.2232979501e-3, 1.4062241527e-3, 1.6114744851e-3\n };\n static const double base_lsf[3] = {\n M_PI * -5.5830e-2, M_PI * -5.2908e-2, M_PI * -5.4776e-2\n };\n const float (*ipol_tab)[2][16] = q_mode ?\n wmavoice_lsp16_intercoeff_b : wmavoice_lsp16_intercoeff_a;\n uint16_t interpol, v[3];\n int n;\n dequant_lsp16i(gb, i_lsps);\n interpol = get_bits(gb, 5);\n v[0] = get_bits(gb, 7);\n v[1] = get_bits(gb, 7);\n v[2] = get_bits(gb, 7);\n for (n = 0; n < 16; n++) {\n double delta = old[n] - i_lsps[n];\n a1[n] = ipol_tab[interpol][0][n] * delta + i_lsps[n];\n a1[16 + n] = ipol_tab[interpol][1][n] * delta + i_lsps[n];\n }\n dequant_lsps( a2, 10, v, vec_sizes, 1,\n wmavoice_dq_lsp16r1, mul_lsf, base_lsf);\n dequant_lsps(&a2[10], 10, &v[1], &vec_sizes[1], 1,\n wmavoice_dq_lsp16r2, &mul_lsf[1], &base_lsf[1]);\n dequant_lsps(&a2[20], 12, &v[2], &vec_sizes[2], 1,\n wmavoice_dq_lsp16r3, &mul_lsf[2], &base_lsf[2]);\n}']
33,506
0
https://github.com/openssl/openssl/blob/09977dd095f3c655c99b9e1810a213f7eafa7364/crypto/bn/bn_sqr.c/#L167
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp) { int i, j, max; const BN_ULONG *ap; BN_ULONG *rp; max = n * 2; ap = a; rp = r; rp[0] = rp[max - 1] = 0; rp++; j = n; if (--j > 0) { ap++; rp[j] = bn_mul_words(rp, ap, j, ap[-1]); rp += 2; } for (i = n - 2; i > 0; i--) { j--; ap++; rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]); rp += 2; } bn_add_words(r, r, r, max); bn_sqr_words(tmp, a, n); bn_add_words(r, r, tmp, max); }
['int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,\n EC_POINT *point,\n const BIGNUM *x_, int y_bit,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *tmp1, *tmp2, *x, *y;\n int ret = 0;\n ERR_clear_error();\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n y_bit = (y_bit != 0);\n BN_CTX_start(ctx);\n tmp1 = BN_CTX_get(ctx);\n tmp2 = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto err;\n if (!BN_nnmod(x, x_, group->field, ctx))\n goto err;\n if (group->meth->field_decode == 0) {\n if (!group->meth->field_sqr(group, tmp2, x_, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx))\n goto err;\n } else {\n if (!BN_mod_sqr(tmp2, x_, group->field, ctx))\n goto err;\n if (!BN_mod_mul(tmp1, tmp2, x_, group->field, ctx))\n goto err;\n }\n if (group->a_is_minus3) {\n if (!BN_mod_lshift1_quick(tmp2, x, group->field))\n goto err;\n if (!BN_mod_add_quick(tmp2, tmp2, x, group->field))\n goto err;\n if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->a, ctx))\n goto err;\n if (!BN_mod_mul(tmp2, tmp2, x, group->field, ctx))\n goto err;\n } else {\n if (!group->meth->field_mul(group, tmp2, group->a, x, ctx))\n goto err;\n }\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n }\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->b, ctx))\n goto err;\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (!BN_mod_add_quick(tmp1, tmp1, group->b, group->field))\n goto err;\n }\n if (!BN_mod_sqrt(y, tmp1, group->field, ctx)) {\n unsigned long err = ERR_peek_last_error();\n if (ERR_GET_LIB(err) == ERR_LIB_BN\n && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {\n ERR_clear_error();\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n } else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_BN_LIB);\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n if (BN_is_zero(y)) {\n int kron;\n kron = BN_kronecker(x, group->field, ctx);\n if (kron == -2)\n goto err;\n if (kron == 1)\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSION_BIT);\n else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n goto err;\n }\n if (!BN_usub(y, group->field, y))\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, 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_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_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}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
33,507
0
https://github.com/openssl/openssl/blob/4dfc8f1f0b3ff85adfdca3a37be5df7928092f07/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,bits,ret=0,idx,window,wvalue;\n\tint top;\n \tBIGNUM *r;\n\tconst BIGNUM *aa;\n\tBN_MONT_CTX *mont=NULL;\n\tint numPowers;\n\tunsigned char *powerbufFree=NULL;\n\tint powerbufLen = 0;\n\tunsigned char *powerbuf=NULL;\n\tBIGNUM *computeTemp=NULL, *am=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\ttop = m->top;\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\tr = BN_CTX_get(ctx);\n\tif (r == NULL) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\twindow = BN_window_bits_for_ctime_exponent_size(bits);\n\tnumPowers = 1 << window;\n\tpowerbufLen = sizeof(m->d[0])*top*numPowers;\n\tif ((powerbufFree=(unsigned char*)OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL)\n\t\tgoto err;\n\tpowerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n\tmemset(powerbuf, 0, powerbufLen);\n \tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(r, top, powerbuf, 0, numPowers)) goto err;\n\tcomputeTemp = BN_CTX_get(ctx);\n\tam = BN_CTX_get(ctx);\n\tif (computeTemp==NULL || am==NULL) goto err;\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(am,a,m,ctx))\n\t\t\tgoto err;\n\t\taa= am;\n\t\t}\n\telse\n\t\taa=a;\n\tif (!BN_to_montgomery(am,aa,mont,ctx)) goto err;\n\tif (!BN_copy(computeTemp, am)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(am, top, powerbuf, 1, numPowers)) goto err;\n\tif (window > 1)\n\t\t{\n\t\tfor (i=2; i<numPowers; i++)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(computeTemp,am,computeTemp,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(computeTemp, top, powerbuf, i, numPowers)) goto err;\n\t\t\t}\n\t\t}\n \tbits = ((bits+window-1)/window)*window;\n \tidx=bits-1;\n \twhile (idx >= 0)\n \t\t{\n \t\twvalue=0;\n \t\tfor (i=0; i<window; i++,idx--)\n \t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\tgoto err;\n\t\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,idx);\n \t\t\t}\n\t\tif (!MOD_EXP_CTIME_COPY_FROM_PREBUF(computeTemp, top, powerbuf, wvalue, numPowers)) goto err;\n \t\tif (!BN_mod_mul_montgomery(r,r,computeTemp,mont,ctx)) goto err;\n \t\t}\n\tif (!BN_from_montgomery(rr,r,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tif (powerbuf!=NULL)\n\t\t{\n\t\tOPENSSL_cleanse(powerbuf,powerbufLen);\n\t\tOPENSSL_free(powerbufFree);\n\t\t}\n \tif (am!=NULL) BN_clear(am);\n \tif (computeTemp!=NULL) BN_clear(computeTemp);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n\t\t\t BN_MONT_CTX *mont, BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp;\n\tint ret=0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n\tint num = mont->N.top;\n\tif (num>1 && a->top==num && b->top==num)\n\t\t{\n\t\tif (bn_wexpand(r,num) == NULL) return(0);\n\t\tif (bn_mul_mont(r->d,a->d,b->d,mont->N.d,mont->n0,num))\n\t\t\t{\n\t\t\tr->neg = a->neg^b->neg;\n\t\t\tr->top = num;\n\t\t\tbn_correct_top(r);\n\t\t\treturn(1);\n\t\t\t}\n\t\t}\n#endif\n\tBN_CTX_start(ctx);\n\ttmp = BN_CTX_get(ctx);\n\tif (tmp == NULL) goto err;\n\tbn_check_top(tmp);\n\tif (a == b)\n\t\t{\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n#ifdef MONT_WORD\n\tif (!BN_from_montgomery_word(r,tmp,mont)) goto err;\n#else\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n#endif\n\tbn_check_top(r);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n\t{\n\tint max,al;\n\tint ret = 0;\n\tBIGNUM *tmp,*rr;\n#ifdef BN_COUNT\n\tfprintf(stderr,"BN_sqr %d * %d\\n",a->top,a->top);\n#endif\n\tbn_check_top(a);\n\tal=a->top;\n\tif (al <= 0)\n\t\t{\n\t\tr->top=0;\n\t\treturn 1;\n\t\t}\n\tBN_CTX_start(ctx);\n\trr=(a != r) ? r : BN_CTX_get(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tif (!rr || !tmp) goto err;\n\tmax = 2 * al;\n\tif (bn_wexpand(rr,max) == NULL) goto err;\n\tif (al == 4)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[8];\n\t\tbn_sqr_normal(rr->d,a->d,4,t);\n#else\n\t\tbn_sqr_comba4(rr->d,a->d);\n#endif\n\t\t}\n\telse if (al == 8)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[16];\n\t\tbn_sqr_normal(rr->d,a->d,8,t);\n#else\n\t\tbn_sqr_comba8(rr->d,a->d);\n#endif\n\t\t}\n\telse\n\t\t{\n#if defined(BN_RECURSION)\n\t\tif (al < BN_SQR_RECURSIVE_SIZE_NORMAL)\n\t\t\t{\n\t\t\tBN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];\n\t\t\tbn_sqr_normal(rr->d,a->d,al,t);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tint j,k;\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,k*2) == NULL) goto err;\n\t\t\t\tbn_sqr_recursive(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,max) == NULL) goto err;\n\t\t\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\t}\n#else\n\t\tif (bn_wexpand(tmp,max) == NULL) goto err;\n\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n#endif\n\t\t}\n\trr->neg=0;\n\tif(a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n\t\trr->top = max - 1;\n\telse\n\t\trr->top = max;\n\tif (rr != r) BN_copy(r,rr);\n\tret = 1;\n err:\n\tbn_check_top(rr);\n\tbn_check_top(tmp);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', '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}']
33,508
0
https://github.com/libav/libav/blob/deb23777f2efe6f822841c420864637b62940838/libavformat/rtsp.c/#L1971
static int sdp_read_header(AVFormatContext *s) { RTSPState *rt = s->priv_data; RTSPStream *rtsp_st; int size, i, err; char *content; char url[1024]; if (!ff_network_init()) return AVERROR(EIO); if (s->max_delay < 0) s->max_delay = DEFAULT_REORDERING_DELAY; content = av_malloc(SDP_MAX_SIZE); size = avio_read(s->pb, content, SDP_MAX_SIZE - 1); if (size <= 0) { av_free(content); return AVERROR_INVALIDDATA; } content[size] ='\0'; err = ff_sdp_parse(s, content); av_free(content); if (err) goto fail; for (i = 0; i < rt->nb_rtsp_streams; i++) { char namebuf[50]; rtsp_st = rt->rtsp_streams[i]; getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip), namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST); ff_url_join(url, sizeof(url), "rtp", NULL, namebuf, rtsp_st->sdp_port, "?localport=%d&ttl=%d&connect=%d", rtsp_st->sdp_port, rtsp_st->sdp_ttl, rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0); if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, &s->interrupt_callback, NULL) < 0) { err = AVERROR_INVALIDDATA; goto fail; } if ((err = ff_rtsp_open_transport_ctx(s, rtsp_st))) goto fail; } return 0; fail: ff_rtsp_close_streams(s); ff_network_close(); return err; }
['static int sdp_read_header(AVFormatContext *s)\n{\n RTSPState *rt = s->priv_data;\n RTSPStream *rtsp_st;\n int size, i, err;\n char *content;\n char url[1024];\n if (!ff_network_init())\n return AVERROR(EIO);\n if (s->max_delay < 0)\n s->max_delay = DEFAULT_REORDERING_DELAY;\n content = av_malloc(SDP_MAX_SIZE);\n size = avio_read(s->pb, content, SDP_MAX_SIZE - 1);\n if (size <= 0) {\n av_free(content);\n return AVERROR_INVALIDDATA;\n }\n content[size] =\'\\0\';\n err = ff_sdp_parse(s, content);\n av_free(content);\n if (err) goto fail;\n for (i = 0; i < rt->nb_rtsp_streams; i++) {\n char namebuf[50];\n rtsp_st = rt->rtsp_streams[i];\n getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip),\n namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);\n ff_url_join(url, sizeof(url), "rtp", NULL,\n namebuf, rtsp_st->sdp_port,\n "?localport=%d&ttl=%d&connect=%d", rtsp_st->sdp_port,\n rtsp_st->sdp_ttl,\n rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0);\n if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,\n &s->interrupt_callback, NULL) < 0) {\n err = AVERROR_INVALIDDATA;\n goto fail;\n }\n if ((err = ff_rtsp_open_transport_ctx(s, rtsp_st)))\n goto fail;\n }\n return 0;\nfail:\n ff_rtsp_close_streams(s);\n ff_network_close();\n return err;\n}', 'int ff_network_init(void)\n{\n#if HAVE_WINSOCK2_H\n WSADATA wsaData;\n#endif\n if (!ff_network_inited_globally)\n av_log(NULL, AV_LOG_WARNING, "Using network protocols without global "\n "network initialization. Please use "\n "avformat_network_init(), this will "\n "become mandatory later.\\n");\n#if HAVE_WINSOCK2_H\n if (WSAStartup(MAKEWORD(1,1), &wsaData))\n return 0;\n#endif\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}']
33,509
0
https://github.com/libav/libav/blob/98137a1a5b1a4438ab4d84e63a957dc83c7dacaf/libavcodec/vp8.c/#L1038
static inline void vp8_mc(VP8Context *s, int luma, uint8_t *dst, uint8_t *src, const VP56mv *mv, int x_off, int y_off, int block_w, int block_h, int width, int height, int linesize, vp8_mc_func mc_func[3][3]) { if (AV_RN32A(mv)) { static const uint8_t idx[8] = { 0, 1, 2, 1, 2, 1, 2, 1 }; int mx = (mv->x << luma)&7, mx_idx = idx[mx]; int my = (mv->y << luma)&7, my_idx = idx[my]; x_off += mv->x >> (3 - luma); y_off += mv->y >> (3 - luma); src += y_off * linesize + x_off; if (x_off < 2 || x_off >= width - block_w - 3 || y_off < 2 || y_off >= height - block_h - 3) { ff_emulated_edge_mc(s->edge_emu_buffer, src - 2 * linesize - 2, linesize, block_w + 5, block_h + 5, x_off - 2, y_off - 2, width, height); src = s->edge_emu_buffer + 2 + linesize * 2; } mc_func[my_idx][mx_idx](dst, linesize, src, linesize, block_h, mx, my); } else mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0); }
['static void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,\n int mb_x, int mb_y)\n{\n int x_off = mb_x << 4, y_off = mb_y << 4;\n int width = 16*s->mb_width, height = 16*s->mb_height;\n prefetch_motion(s, mb, mb_x, mb_y, x_off, y_off, VP56_FRAME_PREVIOUS);\n if (mb->mode < VP8_MVMODE_SPLIT) {\n vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,\n 0, 0, 16, 16, width, height, &mb->mv);\n } else switch (mb->partitioning) {\n case VP8_SPLITMVMODE_4x4: {\n int x, y;\n VP56mv uvmv;\n for (y = 0; y < 4; y++) {\n for (x = 0; x < 4; x++) {\n vp8_mc(s, 1, dst[0] + 4*y*s->linesize + x*4,\n s->framep[mb->ref_frame]->data[0], &mb->bmv[4*y + x],\n 4*x + x_off, 4*y + y_off, 4, 4,\n width, height, s->linesize,\n s->put_pixels_tab[2]);\n }\n }\n x_off >>= 1; y_off >>= 1; width >>= 1; height >>= 1;\n for (y = 0; y < 2; y++) {\n for (x = 0; x < 2; x++) {\n uvmv.x = mb->bmv[ 2*y * 4 + 2*x ].x +\n mb->bmv[ 2*y * 4 + 2*x+1].x +\n mb->bmv[(2*y+1) * 4 + 2*x ].x +\n mb->bmv[(2*y+1) * 4 + 2*x+1].x;\n uvmv.y = mb->bmv[ 2*y * 4 + 2*x ].y +\n mb->bmv[ 2*y * 4 + 2*x+1].y +\n mb->bmv[(2*y+1) * 4 + 2*x ].y +\n mb->bmv[(2*y+1) * 4 + 2*x+1].y;\n uvmv.x = (uvmv.x + 2 + (uvmv.x >> (INT_BIT-1))) >> 2;\n uvmv.y = (uvmv.y + 2 + (uvmv.y >> (INT_BIT-1))) >> 2;\n if (s->profile == 3) {\n uvmv.x &= ~7;\n uvmv.y &= ~7;\n }\n vp8_mc(s, 0, dst[1] + 4*y*s->uvlinesize + x*4,\n s->framep[mb->ref_frame]->data[1], &uvmv,\n 4*x + x_off, 4*y + y_off, 4, 4,\n width, height, s->uvlinesize,\n s->put_pixels_tab[2]);\n vp8_mc(s, 0, dst[2] + 4*y*s->uvlinesize + x*4,\n s->framep[mb->ref_frame]->data[2], &uvmv,\n 4*x + x_off, 4*y + y_off, 4, 4,\n width, height, s->uvlinesize,\n s->put_pixels_tab[2]);\n }\n }\n break;\n }\n case VP8_SPLITMVMODE_16x8:\n vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,\n 0, 0, 16, 8, width, height, &mb->bmv[0]);\n vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,\n 0, 8, 16, 8, width, height, &mb->bmv[1]);\n break;\n case VP8_SPLITMVMODE_8x16:\n vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,\n 0, 0, 8, 16, width, height, &mb->bmv[0]);\n vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,\n 8, 0, 8, 16, width, height, &mb->bmv[1]);\n break;\n case VP8_SPLITMVMODE_8x8:\n vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,\n 0, 0, 8, 8, width, height, &mb->bmv[0]);\n vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,\n 8, 0, 8, 8, width, height, &mb->bmv[1]);\n vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,\n 0, 8, 8, 8, width, height, &mb->bmv[2]);\n vp8_mc_part(s, dst, s->framep[mb->ref_frame], x_off, y_off,\n 8, 8, 8, 8, width, height, &mb->bmv[3]);\n break;\n }\n prefetch_motion(s, mb, mb_x, mb_y, x_off, y_off, VP56_FRAME_GOLDEN);\n}', 'static inline void vp8_mc(VP8Context *s, int luma,\n uint8_t *dst, uint8_t *src, const VP56mv *mv,\n int x_off, int y_off, int block_w, int block_h,\n int width, int height, int linesize,\n vp8_mc_func mc_func[3][3])\n{\n if (AV_RN32A(mv)) {\n static const uint8_t idx[8] = { 0, 1, 2, 1, 2, 1, 2, 1 };\n int mx = (mv->x << luma)&7, mx_idx = idx[mx];\n int my = (mv->y << luma)&7, my_idx = idx[my];\n x_off += mv->x >> (3 - luma);\n y_off += mv->y >> (3 - luma);\n src += y_off * linesize + x_off;\n if (x_off < 2 || x_off >= width - block_w - 3 ||\n y_off < 2 || y_off >= height - block_h - 3) {\n ff_emulated_edge_mc(s->edge_emu_buffer, src - 2 * linesize - 2, linesize,\n block_w + 5, block_h + 5,\n x_off - 2, y_off - 2, width, height);\n src = s->edge_emu_buffer + 2 + linesize * 2;\n }\n mc_func[my_idx][mx_idx](dst, linesize, src, linesize, block_h, mx, my);\n } else\n mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0);\n}']
33,510
0
https://github.com/libav/libav/blob/bb8c6ac840afa69dd37860fdf85da9f4cf1e0ae4/libavcodec/g722enc.c/#L142
static inline void filter_samples(G722Context *c, const int16_t *samples, int *xlow, int *xhigh) { int xout[2]; c->prev_samples[c->prev_samples_pos++] = samples[0]; c->prev_samples[c->prev_samples_pos++] = samples[1]; c->dsp.apply_qmf(c->prev_samples + c->prev_samples_pos - 24, xout); *xlow = xout[0] + xout[1] >> 14; *xhigh = xout[0] - xout[1] >> 14; if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) { memmove(c->prev_samples, c->prev_samples + c->prev_samples_pos - 22, 22 * sizeof(c->prev_samples[0])); c->prev_samples_pos = 22; } }
['static void g722_encode_no_trellis(G722Context *c,\n uint8_t *dst, int nb_samples,\n const int16_t *samples)\n{\n int i;\n for (i = 0; i < nb_samples; i += 2)\n encode_byte(c, dst++, &samples[i]);\n}', 'static av_always_inline void encode_byte(G722Context *c, uint8_t *dst,\n const int16_t *samples)\n{\n int xlow, xhigh, ilow, ihigh;\n filter_samples(c, samples, &xlow, &xhigh);\n ihigh = encode_high(&c->band[1], xhigh);\n ilow = encode_low (&c->band[0], xlow);\n ff_g722_update_high_predictor(&c->band[1], c->band[1].scale_factor *\n ff_g722_high_inv_quant[ihigh] >> 10, ihigh);\n ff_g722_update_low_predictor(&c->band[0], ilow >> 2);\n *dst = ihigh << 6 | ilow;\n}', 'static inline void filter_samples(G722Context *c, const int16_t *samples,\n int *xlow, int *xhigh)\n{\n int xout[2];\n c->prev_samples[c->prev_samples_pos++] = samples[0];\n c->prev_samples[c->prev_samples_pos++] = samples[1];\n c->dsp.apply_qmf(c->prev_samples + c->prev_samples_pos - 24, xout);\n *xlow = xout[0] + xout[1] >> 14;\n *xhigh = xout[0] - xout[1] >> 14;\n if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) {\n memmove(c->prev_samples,\n c->prev_samples + c->prev_samples_pos - 22,\n 22 * sizeof(c->prev_samples[0]));\n c->prev_samples_pos = 22;\n }\n}']
33,511
0
https://github.com/libav/libav/blob/896a5bff64264f4d01ed98eacc97a67260c1e17e/libavformat/rtsp.c/#L2163
static int sdp_read_header(AVFormatContext *s) { RTSPState *rt = s->priv_data; RTSPStream *rtsp_st; int size, i, err; char *content; char url[1024]; if (!ff_network_init()) return AVERROR(EIO); if (s->max_delay < 0) s->max_delay = DEFAULT_REORDERING_DELAY; if (rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO) rt->lower_transport = RTSP_LOWER_TRANSPORT_CUSTOM; content = av_malloc(SDP_MAX_SIZE); size = avio_read(s->pb, content, SDP_MAX_SIZE - 1); if (size <= 0) { av_free(content); return AVERROR_INVALIDDATA; } content[size] ='\0'; err = ff_sdp_parse(s, content); av_free(content); if (err) goto fail; for (i = 0; i < rt->nb_rtsp_streams; i++) { char namebuf[50]; rtsp_st = rt->rtsp_streams[i]; if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) { getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip), namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST); ff_url_join(url, sizeof(url), "rtp", NULL, namebuf, rtsp_st->sdp_port, "?localport=%d&ttl=%d&connect=%d&write_to_source=%d", rtsp_st->sdp_port, rtsp_st->sdp_ttl, rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0, rt->rtsp_flags & RTSP_FLAG_RTCP_TO_SOURCE ? 1 : 0); append_source_addrs(url, sizeof(url), "sources", rtsp_st->nb_include_source_addrs, rtsp_st->include_source_addrs); append_source_addrs(url, sizeof(url), "block", rtsp_st->nb_exclude_source_addrs, rtsp_st->exclude_source_addrs); if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, &s->interrupt_callback, NULL) < 0) { err = AVERROR_INVALIDDATA; goto fail; } } if ((err = ff_rtsp_open_transport_ctx(s, rtsp_st))) goto fail; } return 0; fail: ff_rtsp_close_streams(s); ff_network_close(); return err; }
['static int sdp_read_header(AVFormatContext *s)\n{\n RTSPState *rt = s->priv_data;\n RTSPStream *rtsp_st;\n int size, i, err;\n char *content;\n char url[1024];\n if (!ff_network_init())\n return AVERROR(EIO);\n if (s->max_delay < 0)\n s->max_delay = DEFAULT_REORDERING_DELAY;\n if (rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)\n rt->lower_transport = RTSP_LOWER_TRANSPORT_CUSTOM;\n content = av_malloc(SDP_MAX_SIZE);\n size = avio_read(s->pb, content, SDP_MAX_SIZE - 1);\n if (size <= 0) {\n av_free(content);\n return AVERROR_INVALIDDATA;\n }\n content[size] =\'\\0\';\n err = ff_sdp_parse(s, content);\n av_free(content);\n if (err) goto fail;\n for (i = 0; i < rt->nb_rtsp_streams; i++) {\n char namebuf[50];\n rtsp_st = rt->rtsp_streams[i];\n if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) {\n getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip),\n namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);\n ff_url_join(url, sizeof(url), "rtp", NULL,\n namebuf, rtsp_st->sdp_port,\n "?localport=%d&ttl=%d&connect=%d&write_to_source=%d",\n rtsp_st->sdp_port, rtsp_st->sdp_ttl,\n rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0,\n rt->rtsp_flags & RTSP_FLAG_RTCP_TO_SOURCE ? 1 : 0);\n append_source_addrs(url, sizeof(url), "sources",\n rtsp_st->nb_include_source_addrs,\n rtsp_st->include_source_addrs);\n append_source_addrs(url, sizeof(url), "block",\n rtsp_st->nb_exclude_source_addrs,\n rtsp_st->exclude_source_addrs);\n if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,\n &s->interrupt_callback, NULL) < 0) {\n err = AVERROR_INVALIDDATA;\n goto fail;\n }\n }\n if ((err = ff_rtsp_open_transport_ctx(s, rtsp_st)))\n goto fail;\n }\n return 0;\nfail:\n ff_rtsp_close_streams(s);\n ff_network_close();\n return err;\n}', 'int ff_network_init(void)\n{\n#if HAVE_WINSOCK2_H\n WSADATA wsaData;\n#endif\n if (!ff_network_inited_globally)\n av_log(NULL, AV_LOG_WARNING, "Using network protocols without global "\n "network initialization. Please use "\n "avformat_network_init(), this will "\n "become mandatory later.\\n");\n#if HAVE_WINSOCK2_H\n if (WSAStartup(MAKEWORD(1,1), &wsaData))\n return 0;\n#endif\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}']
33,512
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_lib.c/#L260
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return NULL; } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return NULL; } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
["ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, const char *value)\n{\n BIGNUM *bn = NULL;\n ASN1_INTEGER *aint;\n int isneg, ishex;\n int ret;\n if (value == NULL) {\n X509V3err(X509V3_F_S2I_ASN1_INTEGER, X509V3_R_INVALID_NULL_VALUE);\n return NULL;\n }\n bn = BN_new();\n if (bn == NULL) {\n X509V3err(X509V3_F_S2I_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n if (value[0] == '-') {\n value++;\n isneg = 1;\n } else\n isneg = 0;\n if (value[0] == '0' && ((value[1] == 'x') || (value[1] == 'X'))) {\n value += 2;\n ishex = 1;\n } else\n ishex = 0;\n if (ishex)\n ret = BN_hex2bn(&bn, value);\n else\n ret = BN_dec2bn(&bn, value);\n if (!ret || value[ret]) {\n BN_free(bn);\n X509V3err(X509V3_F_S2I_ASN1_INTEGER, X509V3_R_BN_DEC2BN_ERROR);\n return NULL;\n }\n if (isneg && BN_is_zero(bn))\n isneg = 0;\n aint = BN_to_ASN1_INTEGER(bn, NULL);\n BN_free(bn);\n if (!aint) {\n X509V3err(X509V3_F_S2I_ASN1_INTEGER,\n X509V3_R_BN_TO_ASN1_INTEGER_ERROR);\n return NULL;\n }\n if (isneg)\n aint->type |= V_ASN1_NEG;\n return aint;\n}", "int BN_dec2bn(BIGNUM **bn, const char *a)\n{\n BIGNUM *ret = NULL;\n BN_ULONG l = 0;\n int neg = 0, i, j;\n int num;\n if (a == NULL || *a == '\\0')\n return 0;\n if (*a == '-') {\n neg = 1;\n a++;\n }\n for (i = 0; i <= INT_MAX / 4 && ossl_isdigit(a[i]); i++)\n continue;\n if (i == 0 || i > INT_MAX / 4)\n goto err;\n num = i + neg;\n if (bn == NULL)\n return num;\n if (*bn == NULL) {\n if ((ret = BN_new()) == NULL)\n return 0;\n } else {\n ret = *bn;\n BN_zero(ret);\n }\n if (bn_expand(ret, i * 4) == NULL)\n goto err;\n j = BN_DEC_NUM - i % BN_DEC_NUM;\n if (j == BN_DEC_NUM)\n j = 0;\n l = 0;\n while (--i >= 0) {\n l *= 10;\n l += *a - '0';\n a++;\n if (++j == BN_DEC_NUM) {\n if (!BN_mul_word(ret, BN_DEC_CONV)\n || !BN_add_word(ret, l))\n goto err;\n l = 0;\n j = 0;\n }\n }\n bn_correct_top(ret);\n *bn = ret;\n bn_check_top(ret);\n if (ret->top != 0)\n ret->neg = neg;\n return num;\n err:\n if (*bn == NULL)\n BN_free(ret);\n return 0;\n}", 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n 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}']
33,513
0
https://github.com/libav/libav/blob/cb668476ab1343d27e03edc0b32f57ca7a187471/libavcodec/h264.c/#L348
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((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1); ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) , pic_height-1), 0); }else if(FIELD_PICTURE && !ref_field_picture){ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field , pic_height-1), 0); }else if(FIELD_PICTURE){ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field); }else{ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0); } } } } }
['static int decode_frame(AVCodecContext *avctx,\n void *data, int *data_size,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n H264Context *h = avctx->priv_data;\n MpegEncContext *s = &h->s;\n AVFrame *pict = data;\n int buf_index;\n s->flags= avctx->flags;\n s->flags2= avctx->flags2;\n out:\n if (buf_size == 0) {\n Picture *out;\n int i, out_idx;\n s->current_picture_ptr = NULL;\n out = h->delayed_pic[0];\n out_idx = 0;\n for (i = 1; h->delayed_pic[i] && !h->delayed_pic[i]->f.key_frame && !h->delayed_pic[i]->mmco_reset; i++)\n if(h->delayed_pic[i]->poc < out->poc){\n out = h->delayed_pic[i];\n out_idx = i;\n }\n for(i=out_idx; h->delayed_pic[i]; i++)\n h->delayed_pic[i] = h->delayed_pic[i+1];\n if(out){\n *data_size = sizeof(AVFrame);\n *pict= *(AVFrame*)out;\n }\n return 0;\n }\n buf_index=decode_nal_units(h, buf, buf_size);\n if(buf_index < 0)\n return -1;\n if (!s->current_picture_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {\n buf_size = 0;\n goto out;\n }\n if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){\n if (avctx->skip_frame >= AVDISCARD_NONREF)\n return 0;\n av_log(avctx, AV_LOG_ERROR, "no frame!\\n");\n return -1;\n }\n if(!(s->flags2 & CODEC_FLAG2_CHUNKS) || (s->mb_y >= s->mb_height && s->mb_height)){\n if(s->flags2 & CODEC_FLAG2_CHUNKS) decode_postinit(h, 1);\n field_end(h, 0);\n if (!h->next_output_pic) {\n *data_size = 0;\n } else {\n *data_size = sizeof(AVFrame);\n *pict = *(AVFrame*)h->next_output_pic;\n }\n }\n assert(pict->data[0] || !*data_size);\n ff_print_debug_info(s, pict);\n return get_consumed_bytes(s, buf_index, buf_size);\n}', 'static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){\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 = (HAVE_THREADS && (s->avctx->active_thread_type&FF_THREAD_SLICE)) ? avctx->thread_count : 1;\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) 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, "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 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1)\n break;\n }\n if(buf_index+3 >= buf_size) break;\n buf_index+=3;\n if(buf_index >= next_avc) continue;\n }\n hx = h->thread_context[context_count];\n ptr= ff_h264_decode_nal(hx, buf + buf_index, &dst_length, &consumed, next_avc - buf_index);\n if (ptr==NULL || dst_length < 0){\n return -1;\n }\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 && 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 }\n bit_length= !dst_length ? 0 : (8*dst_length - 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, "NAL %d at %d/%d length %d\\n", hx->nal_unit_type, buf_index, buf_size, dst_length);\n }\n if (h->is_avc && (nalsize != consumed) && nalsize){\n av_log(h->s.avctx, AV_LOG_DEBUG, "AVC: Consumed only %d bytes instead of %d\\n", consumed, nalsize);\n }\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;\n again:\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, "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 }\n if (s->avctx->hwaccel && s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0)\n return -1;\n if(CONFIG_H264_VDPAU_DECODER && 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 || hx->nal_ref_idc)\n && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=AV_PICTURE_TYPE_B)\n && (avctx->skip_frame < AVDISCARD_NONKEY || 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, &buf[buf_index - consumed], consumed) < 0)\n return -1;\n }else\n if(CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){\n static const uint8_t start_code[] = {0x00, 0x00, 0x01};\n ff_vdpau_add_data_chunk(s, start_code, sizeof(start_code));\n ff_vdpau_add_data_chunk(s, &buf[buf_index - consumed], 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 && hx->intra_gb_ptr && hx->s.data_partitioning\n && s->context_initialized\n && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)\n && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=AV_PICTURE_TYPE_B)\n && (avctx->skip_frame < AVDISCARD_NONKEY || 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 ff_h264_decode_seq_parameter_set(h);\n if (s->flags& CODEC_FLAG_LOW_DELAY ||\n (h->sps.bitstream_restriction_flag && !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 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->pixel_shift = h->sps.bit_depth_luma > 8;\n ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma);\n ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma);\n s->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16;\n dsputil_init(&s->dsp, s->avctx);\n } else {\n av_log(avctx, AV_LOG_DEBUG, "Unsupported bit depth: %d\\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", 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 field_end(H264Context *h, int in_setup){\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((AVFrame*)s->current_picture_ptr, (16*s->mb_height >> FIELD_PICTURE) - 1,\n s->picture_structure==PICT_BOTTOM_FIELD);\n if (CONFIG_H264_VDPAU_DECODER && 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, "hardware accelerator failed to decode picture\\n");\n }\n if (CONFIG_H264_VDPAU_DECODER && 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 MPV_frame_end(s);\n h->current_slice=0;\n return err;\n}', 'void ff_er_frame_end(MpegEncContext *s){\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->error_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*(s->avctx->skip_top + s->avctx->skip_bottom)) return;\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&AC_END)\n end_ok=0;\n if((error&MV_END) || (error&DC_END) || (error&AC_ERROR))\n end_ok=1;\n if(!end_ok)\n s->error_status_table[mb_xy]|= AC_ERROR;\n if(error&VP_START)\n end_ok=0;\n }\n }\n if(s->error_recognition>=4){\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|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)\n && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)\n && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){\n end_ok=0;\n }\n if(!end_ok)\n s->error_status_table[mb_xy]|= DC_ERROR|AC_ERROR|MV_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& (DC_ERROR|AC_ERROR|MV_ERROR);\n else{\n error|= old_error& (DC_ERROR|AC_ERROR|MV_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&(AC_ERROR|DC_ERROR|MV_ERROR))\n error|= AC_ERROR|DC_ERROR|MV_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&DC_ERROR) dc_error ++;\n if(error&AC_ERROR) ac_error ++;\n if(error&MV_ERROR) mv_error ++;\n }\n av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\\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&DC_ERROR) && (error&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 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 error= s->error_status_table[mb_xy];\n if(IS_INTRA(mb_type)) continue;\n if(error&MV_ERROR) continue;\n if(!(error&AC_ERROR)) 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 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 error= s->error_status_table[mb_xy];\n if(IS_INTRA(mb_type)) continue;\n if(!(error&MV_ERROR)) continue;\n if(!(error&AC_ERROR)) continue;\n s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD;\n if(!s->last_picture.f.data[0]) s->mv_dir &= ~MV_DIR_FORWARD;\n if(!s->next_picture.f.data[0]) 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((AVFrame *) s->next_picture_ptr,\n 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) 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 + (y + (n>>1)*8)*s->linesize];\n }\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)) continue;\n if(!(error&AC_ERROR)) 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, s->mb_height*2, s->linesize , 1);\n h_block_filter(s, s->current_picture.f.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);\n h_block_filter(s, s->current_picture.f.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);\n v_block_filter(s, s->current_picture.f.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);\n v_block_filter(s, s->current_picture.f.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);\n v_block_filter(s, s->current_picture.f.data[2], s->mb_width , 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 && (error&(DC_ERROR|MV_ERROR|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 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]) 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&DC_ERROR) && (error&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 || !h->ref_list[0][0].f.data[0])\n return 1;\n }\n if(undamaged_count < 5) return 0;\n if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration && 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&DC_ERROR) && (error&MV_ERROR))\n continue;\n j++;\n if((j%skip_amount) != 0) continue;\n if(s->pict_type==AV_PICTURE_TYPE_I){\n uint8_t *mb_ptr = s->current_picture.f.data[0] + mb_x*16 + mb_y*16*s->linesize;\n uint8_t *last_mb_ptr= s->last_picture.f.data [0] + mb_x*16 + mb_y*16*s->linesize;\n if (s->avctx->codec_id == CODEC_ID_H264) {\n } else {\n ff_thread_await_progress((AVFrame *) s->last_picture_ptr,\n mb_y, 0);\n }\n is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr , s->linesize, 16);\n is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, 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 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], 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, 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 MPV_decode_mb(s, s->block);\n }\n}', 'void ff_h264_hl_decode_mb(H264Context *h){\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 hl_decode_mb_444_internal(h, 0, h->pixel_shift);\n}', 'static av_always_inline void hl_decode_mb_444_internal(H264Context *h, int simple, int pixel_shift){\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 {\n dest[p] = s->current_picture.f.data[p] + ((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), 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, 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 }\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 }\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, 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, transform_bypass, pixel_shift, block_offset, linesize, dest[p], p);\n if(h->deblocking_filter)\n xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, 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, 1);\n }\n for (p = 0; p < plane_count; p++)\n hl_decode_mb_idct_luma(h, mb_type, 1, simple, transform_bypass, pixel_shift, block_offset, linesize, dest[p], p);\n }\n if(h->cbp || IS_INTRA(mb_type))\n {\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, uint8_t *dest_cb, uint8_t *dest_cr,\n qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),\n qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg),\n h264_weight_func *weight_op, h264_biweight_func *weight_avg,\n int pixel_shift, int chroma444){\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_PTHREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))\n await_references(h);\n prefetch_motion(h, 0, pixel_shift, chroma444);\n if(IS_16X16(mb_type)){\n mc_part(h, 0, 1, 8, 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, chroma444);\n }else if(IS_16X8(mb_type)){\n mc_part(h, 0, 0, 4, 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[1], &weight_avg[1],\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, 8, 0, 4, 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[1], &weight_avg[1],\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n pixel_shift, chroma444);\n }else if(IS_8X16(mb_type)){\n mc_part(h, 0, 0, 8, 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[2], &weight_avg[2],\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, 4, 0, 8, 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[2], &weight_avg[2],\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n pixel_shift, chroma444);\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, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n &weight_op[3], &weight_avg[3],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n }else if(IS_SUB_8X4(sub_mb_type)){\n mc_part(h, n , 0, 2, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n &weight_op[4], &weight_avg[4],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, n+2, 0, 2, 4 << pixel_shift, 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[4], &weight_avg[4],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n }else if(IS_SUB_4X8(sub_mb_type)){\n mc_part(h, n , 0, 4, 4*h->mb_linesize, 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[5], &weight_avg[5],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, n+1, 0, 4, 4*h->mb_linesize, 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[5], &weight_avg[5],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\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, 2, 0, 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[6], &weight_avg[6],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n }\n }\n }\n }\n prefetch_motion(h, 1, pixel_shift, chroma444);\n}', 'static void await_references(H264Context *h){\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), IS_DIR(sub_mb_type, 0, 1), 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), IS_DIR(sub_mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, n+2, 4, y_offset+4,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), 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), IS_DIR(sub_mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, n+1, 8, y_offset,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), 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), IS_DIR(sub_mb_type, 0, 1), 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((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1);\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) , pic_height-1), 0);\n }else if(FIELD_PICTURE && !ref_field_picture){\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field , pic_height-1), 0);\n }else if(FIELD_PICTURE){\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field);\n }else{\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0);\n }\n }\n }\n }\n}']
33,514
0
https://github.com/openssl/openssl/blob/4882171df5ba7cb8735b685478a008df25eef47a/crypto/bn/bn_print.c/#L197
int BN_hex2bn(BIGNUM **bn, const char *a) { BIGNUM *ret=NULL; BN_ULONG l=0; int neg=0,h,m,i,j,k,c; int num; if ((a == NULL) || (*a == '\0')) return(0); if (*a == '-') { neg=1; a++; } for (i=0; isxdigit((unsigned char) a[i]); i++) ; num=i+neg; if (bn == NULL) return(num); if (*bn == NULL) { if ((ret=BN_new()) == NULL) return(0); } else { ret= *bn; BN_zero(ret); } if (bn_expand(ret,i*4) == NULL) goto err; j=i; m=0; h=0; while (j > 0) { m=((BN_BYTES*2) <= j)?(BN_BYTES*2):j; l=0; for (;;) { c=a[j-m]; if ((c >= '0') && (c <= '9')) k=c-'0'; else if ((c >= 'a') && (c <= 'f')) k=c-'a'+10; else if ((c >= 'A') && (c <= 'F')) k=c-'A'+10; else k=0; l=(l<<4)|k; if (--m <= 0) { ret->d[h++]=l; break; } } j-=(BN_BYTES*2); } ret->top=h; bn_fix_top(ret); ret->neg=neg; *bn=ret; return(num); err: if (*bn == NULL) BN_free(ret); return(0); }
['EC_GROUP *EC_GROUP_new_by_name(int name)\n\t{\n\tEC_GROUP *ret = NULL;\n\tswitch (name)\n\t\t{\n\tcase EC_GROUP_NO_CURVE:\n\t\treturn NULL;\n\tcase EC_GROUP_NIST_PRIME_224:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_NIST_PRIME_224);\n\t\tbreak;\n\tcase EC_GROUP_NIST_PRIME_384:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_NIST_PRIME_384);\n\t\tbreak;\n\tcase EC_GROUP_NIST_PRIME_521:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_NIST_PRIME_521);\n\t\tbreak;\n\tcase EC_GROUP_NIST_PRIME_192:\n\tcase EC_GROUP_X9_62_PRIME_192V1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_NIST_PRIME_192);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_PRIME_192V2:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_X9_62_PRIME_192V2);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_PRIME_192V3:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_X9_62_PRIME_192V3);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_PRIME_239V1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_X9_62_PRIME_239V1);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_PRIME_239V2:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_X9_62_PRIME_239V2);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_PRIME_239V3:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_X9_62_PRIME_239V3);\n\t\tbreak;\n\tcase EC_GROUP_NIST_PRIME_256:\n\tcase EC_GROUP_X9_62_PRIME_256V1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_X9_62_PRIME_256V1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_112R1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_112R1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_112R2:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_112R2);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_128R1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_128R1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_128R2:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_128R2);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_160K1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_160K1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_160R1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_160R1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_160R2:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_160R2);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_192K1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_192K1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_224K1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_224K1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_256K1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_256K1);\n\t\tbreak;\n\t\t}\n\tif (ret == NULL)\n\t\t{\n\t\tECerr(EC_F_EC_GROUP_NEW_BY_NAME, EC_R_UNKNOWN_GROUP);\n\t\treturn NULL;\n\t\t}\n\tEC_GROUP_set_nid(ret, name);\n\treturn ret;\n\t}', 'static EC_GROUP *ec_group_new_GFp_from_hex(const char *prime_in,\n\t const char *a_in, const char *b_in,\n\t const char *x_in, const int y_bit, const char *order_in, const BN_ULONG cofac_in)\n\t{\n\tEC_GROUP *group=NULL;\n\tEC_POINT *P=NULL;\n\tBN_CTX\t *ctx=NULL;\n\tBIGNUM \t *prime=NULL,*a=NULL,*b=NULL,*x=NULL,*order=NULL;\n\tint\t ok=0;\n\tif ((ctx = BN_CTX_new()) == NULL) goto bn_err;\n\tif ((prime = BN_new()) == NULL || (a = BN_new()) == NULL || (b = BN_new()) == NULL ||\n\t\t(x = BN_new()) == NULL || (order = BN_new()) == NULL) goto bn_err;\n\tif (!BN_hex2bn(&prime, prime_in)) goto bn_err;\n\tif (!BN_hex2bn(&a, a_in)) goto bn_err;\n\tif (!BN_hex2bn(&b, b_in)) goto bn_err;\n\tif ((group = EC_GROUP_new_curve_GFp(prime, a, b, ctx)) == NULL) goto err;\n\tif ((P = EC_POINT_new(group)) == NULL) goto err;\n\tif (!BN_hex2bn(&x, x_in)) goto bn_err;\n\tif (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, y_bit, ctx)) goto err;\n\tif (!BN_hex2bn(&order, order_in)) goto bn_err;\n\tif (!BN_set_word(x, cofac_in)) goto bn_err;\n\tif (!EC_GROUP_set_generator(group, P, order, x)) goto err;\n\tok=1;\nbn_err:\n\tif (!ok)\n\t\tECerr(EC_F_EC_GROUP_NEW_GFP_FROM_HEX, ERR_R_BN_LIB);\nerr:\n\tif (!ok)\n\t\t{\n\t\tEC_GROUP_free(group);\n\t\tgroup = NULL;\n\t\t}\n\tif (P) \t EC_POINT_free(P);\n\tif (ctx) BN_CTX_free(ctx);\n\tif (prime) BN_free(prime);\n\tif (a) BN_free(a);\n\tif (b) BN_free(b);\n\tif (order) BN_free(order);\n\tif (x) BN_free(x);\n\treturn(group);\n\t}', "int BN_hex2bn(BIGNUM **bn, const char *a)\n\t{\n\tBIGNUM *ret=NULL;\n\tBN_ULONG l=0;\n\tint neg=0,h,m,i,j,k,c;\n\tint num;\n\tif ((a == NULL) || (*a == '\\0')) return(0);\n\tif (*a == '-') { neg=1; a++; }\n\tfor (i=0; isxdigit((unsigned char) a[i]); i++)\n\t\t;\n\tnum=i+neg;\n\tif (bn == NULL) return(num);\n\tif (*bn == NULL)\n\t\t{\n\t\tif ((ret=BN_new()) == NULL) return(0);\n\t\t}\n\telse\n\t\t{\n\t\tret= *bn;\n\t\tBN_zero(ret);\n\t\t}\n\tif (bn_expand(ret,i*4) == NULL) goto err;\n\tj=i;\n\tm=0;\n\th=0;\n\twhile (j > 0)\n\t\t{\n\t\tm=((BN_BYTES*2) <= j)?(BN_BYTES*2):j;\n\t\tl=0;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tc=a[j-m];\n\t\t\tif ((c >= '0') && (c <= '9')) k=c-'0';\n\t\t\telse if ((c >= 'a') && (c <= 'f')) k=c-'a'+10;\n\t\t\telse if ((c >= 'A') && (c <= 'F')) k=c-'A'+10;\n\t\t\telse k=0;\n\t\t\tl=(l<<4)|k;\n\t\t\tif (--m <= 0)\n\t\t\t\t{\n\t\t\t\tret->d[h++]=l;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tj-=(BN_BYTES*2);\n\t\t}\n\tret->top=h;\n\tbn_fix_top(ret);\n\tret->neg=neg;\n\t*bn=ret;\n\treturn(num);\nerr:\n\tif (*bn == NULL) BN_free(ret);\n\treturn(0);\n\t}"]
33,515
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_lib.c/#L260
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return NULL; } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return NULL; } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n 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_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', '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_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 (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', '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}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(a, BN_FLG_CONSTTIME);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', '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}']
33,516
0
https://github.com/openssl/openssl/blob/0bde1089f895718db2fe2637fda4a0c2ed6df904/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; 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 ssl3_get_client_hello(SSL *s)\n\t{\n\tint i,j,ok,al,ret= -1;\n\tlong n;\n\tunsigned long id;\n\tunsigned char *p,*d,*q;\n\tSSL_CIPHER *c;\n\tSSL_COMP *comp=NULL;\n\tSTACK_OF(SSL_CIPHER) *ciphers=NULL;\n\tif (s->state == SSL3_ST_SR_CLNT_HELLO_A)\n\t\t{\n\t\ts->first_packet=1;\n\t\ts->state=SSL3_ST_SR_CLNT_HELLO_B;\n\t\t}\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_SR_CLNT_HELLO_B,\n\t\tSSL3_ST_SR_CLNT_HELLO_C,\n\t\tSSL3_MT_CLIENT_HELLO,\n\t\tSSL3_RT_MAX_PLAIN_LENGTH,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\td=p=(unsigned char *)s->init_buf->data;\n\ts->client_version=(((int)p[0])<<8)|(int)p[1];\n\tp+=2;\n\tmemcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE);\n\tp+=SSL3_RANDOM_SIZE;\n\tj= *(p++);\n\ts->hit=0;\n\tif (j == 0)\n\t\t{\n\t\tif (!ssl_get_new_session(s,1))\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\t{\n\t\ti=ssl_get_prev_session(s,p,j);\n\t\tif (i == 1)\n\t\t\t{\n\t\t\ts->hit=1;\n\t\t\t}\n\t\telse if (i == -1)\n\t\t\tgoto err;\n\t\telse\n\t\t\t{\n\t\t\tif (!ssl_get_new_session(s,1))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tp+=j;\n\tn2s(p,i);\n\tif ((i == 0) && (j != 0))\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED);\n\t\tgoto f_err;\n\t\t}\n\tif ((i+p) > (d+n))\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);\n\t\tgoto f_err;\n\t\t}\n\tif ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers))\n\t\t== NULL))\n\t\t{\n\t\tgoto err;\n\t\t}\n\tp+=i;\n\tif ((s->hit) && (i > 0))\n\t\t{\n\t\tj=0;\n\t\tid=s->session->cipher->id;\n#ifdef CIPHER_DEBUG\n\t\tprintf("client sent %d ciphers\\n",sk_num(ciphers));\n#endif\n\t\tfor (i=0; i<sk_SSL_CIPHER_num(ciphers); i++)\n\t\t\t{\n\t\t\tc=sk_SSL_CIPHER_value(ciphers,i);\n#ifdef CIPHER_DEBUG\n\t\t\tprintf("client [%2d of %2d]:%s\\n",\n\t\t\t\ti,sk_num(ciphers),SSL_CIPHER_get_name(c));\n#endif\n\t\t\tif (c->id == id)\n\t\t\t\t{\n\t\t\t\tj=1;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tif ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1))\n\t\t\t\t{\n\t\t\t\ts->session->cipher=sk_SSL_CIPHER_value(ciphers,\n\t\t\t\t\t\t\t\t 0);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\ti= *(p++);\n\tq=p;\n\tfor (j=0; j<i; j++)\n\t\t{\n\t\tif (p[j] == 0) break;\n\t\t}\n\tp+=i;\n\tif (j >= i)\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED);\n\t\tgoto f_err;\n\t\t}\n\ts->s3->tmp.new_compression=NULL;\n\tif (s->ctx->comp_methods != NULL)\n\t\t{\n\t\tint m,nn,o,v,done=0;\n\t\tnn=sk_SSL_COMP_num(s->ctx->comp_methods);\n\t\tfor (m=0; m<nn; m++)\n\t\t\t{\n\t\t\tcomp=sk_SSL_COMP_value(s->ctx->comp_methods,m);\n\t\t\tv=comp->id;\n\t\t\tfor (o=0; o<i; o++)\n\t\t\t\t{\n\t\t\t\tif (v == q[o])\n\t\t\t\t\t{\n\t\t\t\t\tdone=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tif (done) break;\n\t\t\t}\n\t\tif (done)\n\t\t\ts->s3->tmp.new_compression=comp;\n\t\telse\n\t\t\tcomp=NULL;\n\t\t}\n\tif (s->version == SSL3_VERSION)\n\t\t{\n\t\tif (p > (d+n))\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\tif (!s->hit)\n\t\t{\n\t\ts->session->compress_meth=(comp == NULL)?0:comp->id;\n\t\tif (s->session->ciphers != NULL)\n\t\t\tsk_SSL_CIPHER_free(s->session->ciphers);\n\t\ts->session->ciphers=ciphers;\n\t\tif (ciphers == NULL)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tciphers=NULL;\n\t\tc=ssl3_choose_cipher(s,s->session->ciphers,\n\t\t\t\t ssl_get_ciphers_by_id(s));\n\t\tif (c == NULL)\n\t\t\t{\n\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\ts->s3->tmp.new_cipher=c;\n\t\t}\n\telse\n\t\t{\n#ifdef REUSE_CIPHER_BUG\n\t\tSTACK_OF(SSL_CIPHER) *sk;\n\t\tSSL_CIPHER *nc=NULL;\n\t\tSSL_CIPHER *ec=NULL;\n\t\tif (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)\n\t\t\t{\n\t\t\tsk=s->session->ciphers;\n\t\t\tfor (i=0; i<sk_SSL_CIPHER_num(sk); i++)\n\t\t\t\t{\n\t\t\t\tc=sk_SSL_CIPHER_value(sk,i);\n\t\t\t\tif (c->algorithms & SSL_eNULL)\n\t\t\t\t\tnc=c;\n\t\t\t\tif (SSL_C_IS_EXPORT(c))\n\t\t\t\t\tec=c;\n\t\t\t\t}\n\t\t\tif (nc != NULL)\n\t\t\t\ts->s3->tmp.new_cipher=nc;\n\t\t\telse if (ec != NULL)\n\t\t\t\ts->s3->tmp.new_cipher=ec;\n\t\t\telse\n\t\t\t\ts->s3->tmp.new_cipher=s->session->cipher;\n\t\t\t}\n\t\telse\n#endif\n\t\ts->s3->tmp.new_cipher=s->session->cipher;\n\t\t}\n\tret=1;\n\tif (0)\n\t\t{\nf_err:\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\t\t}\nerr:\n\tif (ciphers != NULL) sk_SSL_CIPHER_free(ciphers);\n\treturn(ret);\n\t}', 'long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)\n\t{\n\tunsigned char *p;\n\tunsigned long l;\n\tlong n;\n\tint i,al;\n\tif (s->s3->tmp.reuse_message)\n\t\t{\n\t\ts->s3->tmp.reuse_message=0;\n\t\tif ((mt >= 0) && (s->s3->tmp.message_type != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t*ok=1;\n\t\treturn((int)s->s3->tmp.message_size);\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tif (s->state == st1)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],\n\t\t\t\t 4-s->init_num);\n\t\tif (i < (4-s->init_num))\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\tif ((mt >= 0) && (*p != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) &&\n\t\t\t\t\t(st1 == SSL3_ST_SR_CERT_A) &&\n\t\t\t\t\t(stn == SSL3_ST_SR_CERT_B))\n\t\t\t{\n\t\t\tssl3_init_finished_mac(s);\n\t\t\tssl3_finish_mac(s, p + s->init_num, i);\n\t\t\t}\n\t\ts->s3->tmp.message_type= *(p++);\n\t\tn2l3(p,l);\n\t\tif (l > (unsigned long)max)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (l && !BUF_MEM_grow(s->init_buf,(int)l))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ts->s3->tmp.message_size=l;\n\t\ts->state=stn;\n\t\ts->init_num=0;\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tn=s->s3->tmp.message_size;\n\tif (n > 0)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n);\n\t\tif (i != (int)n)\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\t}\n\t*ok=1;\n\treturn(n);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\t*ok=0;\n\treturn(-1);\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\tssl3_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,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\tFree(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}']
33,517
0
https://github.com/openssl/openssl/blob/37b8f1e21c56996644afa38816f575b05eb483ae/crypto/x509v3/v3_purp.c/#L93
int X509_check_purpose(X509 *x, int id, int ca) { int idx; const X509_PURPOSE *pt; if (!(x->ex_flags & EXFLAG_SET)) { CRYPTO_THREAD_write_lock(x->lock); x509v3_cache_extensions(x); CRYPTO_THREAD_unlock(x->lock); } if (id == -1) return 1; idx = X509_PURPOSE_get_by_id(id); if (idx == -1) return -1; pt = X509_PURPOSE_get0(idx); return pt->check_purpose(pt, x, ca); }
['int X509_check_purpose(X509 *x, int id, int ca)\n{\n int idx;\n const X509_PURPOSE *pt;\n if (!(x->ex_flags & EXFLAG_SET)) {\n CRYPTO_THREAD_write_lock(x->lock);\n x509v3_cache_extensions(x);\n CRYPTO_THREAD_unlock(x->lock);\n }\n if (id == -1)\n return 1;\n idx = X509_PURPOSE_get_by_id(id);\n if (idx == -1)\n return -1;\n pt = X509_PURPOSE_get0(idx);\n return pt->check_purpose(pt, x, ca);\n}', 'int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)\n{\n if (pthread_rwlock_wrlock(lock) != 0)\n return 0;\n return 1;\n}', 'int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)\n{\n if (pthread_rwlock_unlock(lock) != 0)\n return 0;\n return 1;\n}', 'int X509_PURPOSE_get_by_id(int purpose)\n{\n X509_PURPOSE tmp;\n int idx;\n if ((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))\n return purpose - X509_PURPOSE_MIN;\n tmp.purpose = purpose;\n if (!xptable)\n return -1;\n idx = sk_X509_PURPOSE_find(xptable, &tmp);\n if (idx == -1)\n return -1;\n return idx + X509_PURPOSE_COUNT;\n}', 'DEFINE_STACK_OF(X509_PURPOSE)', 'int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)\n{\n return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);\n}', 'static int internal_find(OPENSSL_STACK *st, const void *data,\n int ret_val_options)\n{\n const void *r;\n int i;\n if (st == NULL)\n return -1;\n if (st->comp == NULL) {\n for (i = 0; i < st->num; i++)\n if (st->data[i] == data)\n return (i);\n return (-1);\n }\n OPENSSL_sk_sort(st);\n if (data == NULL)\n return (-1);\n r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp,\n ret_val_options);\n if (r == NULL)\n return (-1);\n return (int)((const char **)r - st->data);\n}', 'X509_PURPOSE *X509_PURPOSE_get0(int idx)\n{\n if (idx < 0)\n return NULL;\n if (idx < (int)X509_PURPOSE_COUNT)\n return xstandard + idx;\n return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);\n}']
33,518
0
https://github.com/openssl/openssl/blob/c43fa566ea3918ec3b468d214fd9eb80d79e0d0d/providers/common/ciphers/aes.c/#L286
IMPLEMENT_new_ctx(ecb, ECB, 256)
['IMPLEMENT_new_ctx(ecb, ECB, 256)', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
33,519
0
https://github.com/libav/libav/blob/6cecd63005b29a1dc3a5104e6ac85fd112705122/libswscale/yuv2rgb.c/#L701
int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation) { const int isRgb = c->dstFormat==PIX_FMT_RGB32 || c->dstFormat==PIX_FMT_RGB32_1 || c->dstFormat==PIX_FMT_BGR24 || c->dstFormat==PIX_FMT_RGB565 || c->dstFormat==PIX_FMT_RGB555 || c->dstFormat==PIX_FMT_RGB8 || c->dstFormat==PIX_FMT_RGB4 || c->dstFormat==PIX_FMT_RGB4_BYTE || c->dstFormat==PIX_FMT_MONOBLACK; const int bpp = fmt_depth(c->dstFormat); uint8_t *y_table; uint16_t *y_table16; uint32_t *y_table32; int i, base, rbase, gbase, bbase, abase, needAlpha; const int yoffs = fullRange ? 384 : 326; int64_t crv = inv_table[0]; int64_t cbu = inv_table[1]; int64_t cgu = -inv_table[2]; int64_t cgv = -inv_table[3]; int64_t cy = 1<<16; int64_t oy = 0; int64_t yb = 0; if (!fullRange) { cy = (cy*255) / 219; oy = 16<<16; } else { crv = (crv*224) / 255; cbu = (cbu*224) / 255; cgu = (cgu*224) / 255; cgv = (cgv*224) / 255; } cy = (cy *contrast ) >> 16; crv = (crv*contrast * saturation) >> 32; cbu = (cbu*contrast * saturation) >> 32; cgu = (cgu*contrast * saturation) >> 32; cgv = (cgv*contrast * saturation) >> 32; oy -= 256*brightness; crv = ((crv << 16) + 0x8000) / cy; cbu = ((cbu << 16) + 0x8000) / cy; cgu = ((cgu << 16) + 0x8000) / cy; cgv = ((cgv << 16) + 0x8000) / cy; av_free(c->yuvTable); switch (bpp) { case 1: c->yuvTable = av_malloc(1024); y_table = c->yuvTable; yb = -(384<<16) - oy; for (i = 0; i < 1024-110; i++) { y_table[i+110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7; yb += cy; } fill_table(c->table_gU, 1, cgu, y_table + yoffs); fill_gv_table(c->table_gV, 1, cgv); break; case 4: case 4|128: rbase = isRgb ? 3 : 0; gbase = 1; bbase = isRgb ? 0 : 3; c->yuvTable = av_malloc(1024*3); y_table = c->yuvTable; yb = -(384<<16) - oy; for (i = 0; i < 1024-110; i++) { int yval = av_clip_uint8((yb + 0x8000) >> 16); y_table[i+110 ] = (yval >> 7) << rbase; y_table[i+ 37+1024] = ((yval + 43) / 85) << gbase; y_table[i+110+2048] = (yval >> 7) << bbase; yb += cy; } fill_table(c->table_rV, 1, crv, y_table + yoffs); fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024); fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048); fill_gv_table(c->table_gV, 1, cgv); break; case 8: rbase = isRgb ? 5 : 0; gbase = isRgb ? 2 : 3; bbase = isRgb ? 0 : 6; c->yuvTable = av_malloc(1024*3); y_table = c->yuvTable; yb = -(384<<16) - oy; for (i = 0; i < 1024-38; i++) { int yval = av_clip_uint8((yb + 0x8000) >> 16); y_table[i+16 ] = ((yval + 18) / 36) << rbase; y_table[i+16+1024] = ((yval + 18) / 36) << gbase; y_table[i+37+2048] = ((yval + 43) / 85) << bbase; yb += cy; } fill_table(c->table_rV, 1, crv, y_table + yoffs); fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024); fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048); fill_gv_table(c->table_gV, 1, cgv); break; case 15: case 16: rbase = isRgb ? bpp - 5 : 0; gbase = 5; bbase = isRgb ? 0 : (bpp - 5); c->yuvTable = av_malloc(1024*3*2); y_table16 = c->yuvTable; yb = -(384<<16) - oy; for (i = 0; i < 1024; i++) { uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); y_table16[i ] = (yval >> 3) << rbase; y_table16[i+1024] = (yval >> (18 - bpp)) << gbase; y_table16[i+2048] = (yval >> 3) << bbase; yb += cy; } fill_table(c->table_rV, 2, crv, y_table16 + yoffs); fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024); fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048); fill_gv_table(c->table_gV, 2, cgv); break; case 24: c->yuvTable = av_malloc(1024); y_table = c->yuvTable; yb = -(384<<16) - oy; for (i = 0; i < 1024; i++) { y_table[i] = av_clip_uint8((yb + 0x8000) >> 16); yb += cy; } fill_table(c->table_rV, 1, crv, y_table + yoffs); fill_table(c->table_gU, 1, cgu, y_table + yoffs); fill_table(c->table_bU, 1, cbu, y_table + yoffs); fill_gv_table(c->table_gV, 1, cgv); break; case 32: base = (c->dstFormat == PIX_FMT_RGB32_1 || c->dstFormat == PIX_FMT_BGR32_1) ? 8 : 0; rbase = base + (isRgb ? 16 : 0); gbase = base + 8; bbase = base + (isRgb ? 0 : 16); needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat); if (!needAlpha) abase = (base + 24) & 31; c->yuvTable = av_malloc(1024*3*4); y_table32 = c->yuvTable; yb = -(384<<16) - oy; for (i = 0; i < 1024; i++) { uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); y_table32[i ] = (yval << rbase) + (needAlpha ? 0 : (255 << abase)); y_table32[i+1024] = yval << gbase; y_table32[i+2048] = yval << bbase; yb += cy; } fill_table(c->table_rV, 4, crv, y_table32 + yoffs); fill_table(c->table_gU, 4, cgu, y_table32 + yoffs + 1024); fill_table(c->table_bU, 4, cbu, y_table32 + yoffs + 2048); fill_gv_table(c->table_gV, 4, cgv); break; default: c->yuvTable = NULL; av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp); return -1; } return 0; }
['int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange,\n int brightness, int contrast, int saturation)\n{\n const int isRgb = c->dstFormat==PIX_FMT_RGB32\n || c->dstFormat==PIX_FMT_RGB32_1\n || c->dstFormat==PIX_FMT_BGR24\n || c->dstFormat==PIX_FMT_RGB565\n || c->dstFormat==PIX_FMT_RGB555\n || c->dstFormat==PIX_FMT_RGB8\n || c->dstFormat==PIX_FMT_RGB4\n || c->dstFormat==PIX_FMT_RGB4_BYTE\n || c->dstFormat==PIX_FMT_MONOBLACK;\n const int bpp = fmt_depth(c->dstFormat);\n uint8_t *y_table;\n uint16_t *y_table16;\n uint32_t *y_table32;\n int i, base, rbase, gbase, bbase, abase, needAlpha;\n const int yoffs = fullRange ? 384 : 326;\n int64_t crv = inv_table[0];\n int64_t cbu = inv_table[1];\n int64_t cgu = -inv_table[2];\n int64_t cgv = -inv_table[3];\n int64_t cy = 1<<16;\n int64_t oy = 0;\n int64_t yb = 0;\n if (!fullRange) {\n cy = (cy*255) / 219;\n oy = 16<<16;\n } else {\n crv = (crv*224) / 255;\n cbu = (cbu*224) / 255;\n cgu = (cgu*224) / 255;\n cgv = (cgv*224) / 255;\n }\n cy = (cy *contrast ) >> 16;\n crv = (crv*contrast * saturation) >> 32;\n cbu = (cbu*contrast * saturation) >> 32;\n cgu = (cgu*contrast * saturation) >> 32;\n cgv = (cgv*contrast * saturation) >> 32;\n oy -= 256*brightness;\n crv = ((crv << 16) + 0x8000) / cy;\n cbu = ((cbu << 16) + 0x8000) / cy;\n cgu = ((cgu << 16) + 0x8000) / cy;\n cgv = ((cgv << 16) + 0x8000) / cy;\n av_free(c->yuvTable);\n switch (bpp) {\n case 1:\n c->yuvTable = av_malloc(1024);\n y_table = c->yuvTable;\n yb = -(384<<16) - oy;\n for (i = 0; i < 1024-110; i++) {\n y_table[i+110] = av_clip_uint8((yb + 0x8000) >> 16) >> 7;\n yb += cy;\n }\n fill_table(c->table_gU, 1, cgu, y_table + yoffs);\n fill_gv_table(c->table_gV, 1, cgv);\n break;\n case 4:\n case 4|128:\n rbase = isRgb ? 3 : 0;\n gbase = 1;\n bbase = isRgb ? 0 : 3;\n c->yuvTable = av_malloc(1024*3);\n y_table = c->yuvTable;\n yb = -(384<<16) - oy;\n for (i = 0; i < 1024-110; i++) {\n int yval = av_clip_uint8((yb + 0x8000) >> 16);\n y_table[i+110 ] = (yval >> 7) << rbase;\n y_table[i+ 37+1024] = ((yval + 43) / 85) << gbase;\n y_table[i+110+2048] = (yval >> 7) << bbase;\n yb += cy;\n }\n fill_table(c->table_rV, 1, crv, y_table + yoffs);\n fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024);\n fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048);\n fill_gv_table(c->table_gV, 1, cgv);\n break;\n case 8:\n rbase = isRgb ? 5 : 0;\n gbase = isRgb ? 2 : 3;\n bbase = isRgb ? 0 : 6;\n c->yuvTable = av_malloc(1024*3);\n y_table = c->yuvTable;\n yb = -(384<<16) - oy;\n for (i = 0; i < 1024-38; i++) {\n int yval = av_clip_uint8((yb + 0x8000) >> 16);\n y_table[i+16 ] = ((yval + 18) / 36) << rbase;\n y_table[i+16+1024] = ((yval + 18) / 36) << gbase;\n y_table[i+37+2048] = ((yval + 43) / 85) << bbase;\n yb += cy;\n }\n fill_table(c->table_rV, 1, crv, y_table + yoffs);\n fill_table(c->table_gU, 1, cgu, y_table + yoffs + 1024);\n fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048);\n fill_gv_table(c->table_gV, 1, cgv);\n break;\n case 15:\n case 16:\n rbase = isRgb ? bpp - 5 : 0;\n gbase = 5;\n bbase = isRgb ? 0 : (bpp - 5);\n c->yuvTable = av_malloc(1024*3*2);\n y_table16 = c->yuvTable;\n yb = -(384<<16) - oy;\n for (i = 0; i < 1024; i++) {\n uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);\n y_table16[i ] = (yval >> 3) << rbase;\n y_table16[i+1024] = (yval >> (18 - bpp)) << gbase;\n y_table16[i+2048] = (yval >> 3) << bbase;\n yb += cy;\n }\n fill_table(c->table_rV, 2, crv, y_table16 + yoffs);\n fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024);\n fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048);\n fill_gv_table(c->table_gV, 2, cgv);\n break;\n case 24:\n c->yuvTable = av_malloc(1024);\n y_table = c->yuvTable;\n yb = -(384<<16) - oy;\n for (i = 0; i < 1024; i++) {\n y_table[i] = av_clip_uint8((yb + 0x8000) >> 16);\n yb += cy;\n }\n fill_table(c->table_rV, 1, crv, y_table + yoffs);\n fill_table(c->table_gU, 1, cgu, y_table + yoffs);\n fill_table(c->table_bU, 1, cbu, y_table + yoffs);\n fill_gv_table(c->table_gV, 1, cgv);\n break;\n case 32:\n base = (c->dstFormat == PIX_FMT_RGB32_1 || c->dstFormat == PIX_FMT_BGR32_1) ? 8 : 0;\n rbase = base + (isRgb ? 16 : 0);\n gbase = base + 8;\n bbase = base + (isRgb ? 0 : 16);\n needAlpha = CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat);\n if (!needAlpha)\n abase = (base + 24) & 31;\n c->yuvTable = av_malloc(1024*3*4);\n y_table32 = c->yuvTable;\n yb = -(384<<16) - oy;\n for (i = 0; i < 1024; i++) {\n uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16);\n y_table32[i ] = (yval << rbase) + (needAlpha ? 0 : (255 << abase));\n y_table32[i+1024] = yval << gbase;\n y_table32[i+2048] = yval << bbase;\n yb += cy;\n }\n fill_table(c->table_rV, 4, crv, y_table32 + yoffs);\n fill_table(c->table_gU, 4, cgu, y_table32 + yoffs + 1024);\n fill_table(c->table_bU, 4, cbu, y_table32 + yoffs + 2048);\n fill_gv_table(c->table_gV, 4, cgv);\n break;\n default:\n c->yuvTable = NULL;\n av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\\n", bpp);\n return -1;\n }\n return 0;\n}']
33,520
0
https://github.com/libav/libav/blob/fc8b1075e1f74ab14798e8698bd818eb1a14b938/ffmpeg.c/#L3373
static void new_subtitle_stream(AVFormatContext *oc) { AVStream *st; AVCodecContext *subtitle_enc; st = av_new_stream(oc, oc->nb_streams); if (!st) { fprintf(stderr, "Could not alloc stream\n"); av_exit(1); } avcodec_get_context_defaults2(st->codec, AVMEDIA_TYPE_SUBTITLE); bitstream_filters[nb_output_files][oc->nb_streams - 1]= subtitle_bitstream_filters; subtitle_bitstream_filters= NULL; subtitle_enc = st->codec; subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE; if(subtitle_codec_tag) subtitle_enc->codec_tag= subtitle_codec_tag; if (subtitle_stream_copy) { st->stream_copy = 1; } else { set_context_opts(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM); subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 1); output_codecs[nb_ocodecs] = avcodec_find_encoder_by_name(subtitle_codec_name); } nb_ocodecs++; if (subtitle_language) { av_metadata_set(&st->metadata, "language", subtitle_language); av_freep(&subtitle_language); } subtitle_disable = 0; av_freep(&subtitle_codec_name); subtitle_stream_copy = 0; }
['static void new_subtitle_stream(AVFormatContext *oc)\n{\n AVStream *st;\n AVCodecContext *subtitle_enc;\n st = av_new_stream(oc, oc->nb_streams);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n av_exit(1);\n }\n avcodec_get_context_defaults2(st->codec, AVMEDIA_TYPE_SUBTITLE);\n bitstream_filters[nb_output_files][oc->nb_streams - 1]= subtitle_bitstream_filters;\n subtitle_bitstream_filters= NULL;\n subtitle_enc = st->codec;\n subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;\n if(subtitle_codec_tag)\n subtitle_enc->codec_tag= subtitle_codec_tag;\n if (subtitle_stream_copy) {\n st->stream_copy = 1;\n } else {\n set_context_opts(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM);\n subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 1);\n output_codecs[nb_ocodecs] = avcodec_find_encoder_by_name(subtitle_codec_name);\n }\n nb_ocodecs++;\n if (subtitle_language) {\n av_metadata_set(&st->metadata, "language", subtitle_language);\n av_freep(&subtitle_language);\n }\n subtitle_disable = 0;\n av_freep(&subtitle_codec_name);\n subtitle_stream_copy = 0;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n if (s->nb_streams >= MAX_STREAMS)\n return NULL;\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n st->codec= avcodec_alloc_context();\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->id = id;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = 0;\n st->first_dts = AV_NOPTS_VALUE;\n 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}']
33,521
0
https://github.com/openssl/openssl/blob/54d00677f305375eee65a0c9edb5f0980c5f020f/crypto/bn/bn_lib.c/#L704
int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n) { int i; BN_ULONG aa, bb; aa = a[n - 1]; bb = b[n - 1]; if (aa != bb) return ((aa > bb) ? 1 : -1); for (i = n - 2; i >= 0; i--) { aa = a[i]; bb = b[i]; if (aa != bb) return ((aa > bb) ? 1 : -1); } return 0; }
['int BN_mod_mul(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}', '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 ret->flags &= (~BN_FLG_CONSTTIME);\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 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}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = bn_mul_fixed_top(r, a, b, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,\n int dna, int dnb, BN_ULONG *t)\n{\n int n = n2 / 2, c1, c2;\n int tna = n + dna, tnb = n + dnb;\n unsigned int neg, zero;\n BN_ULONG ln, lo, *p;\n# ifdef BN_MUL_COMBA\n# if 0\n if (n2 == 4) {\n bn_mul_comba4(r, a, b);\n return;\n }\n# endif\n if (n2 == 8 && dna == 0 && dnb == 0) {\n bn_mul_comba8(r, a, b);\n return;\n }\n# endif\n if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(r, a, n2 + dna, b, n2 + dnb);\n if ((dna + dnb) < 0)\n memset(&r[2 * n2 + dna + dnb], 0,\n sizeof(BN_ULONG) * -(dna + dnb));\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n zero = neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n zero = 1;\n break;\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n zero = 1;\n break;\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n zero = 1;\n break;\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# ifdef BN_MUL_COMBA\n if (n == 4 && dna == 0 && dnb == 0) {\n if (!zero)\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n else\n memset(&t[n2], 0, sizeof(*t) * 8);\n bn_mul_comba4(r, a, b);\n bn_mul_comba4(&(r[n2]), &(a[n]), &(b[n]));\n } else if (n == 8 && dna == 0 && dnb == 0) {\n if (!zero)\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n else\n memset(&t[n2], 0, sizeof(*t) * 16);\n bn_mul_comba8(r, a, b);\n bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));\n } else\n# endif\n {\n p = &(t[n2 * 2]);\n if (!zero)\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n else\n memset(&t[n2], 0, sizeof(*t) * n2);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), n, dna, dnb, p);\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)\n{\n int n, i;\n n = cl - 1;\n if (dl < 0) {\n for (i = dl; i < 0; i++) {\n if (b[n - i] != 0)\n return -1;\n }\n }\n if (dl > 0) {\n for (i = dl; i > 0; i--) {\n if (a[n + i] != 0)\n return 1;\n }\n }\n return bn_cmp_words(a, b, cl);\n}', 'int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)\n{\n int i;\n BN_ULONG aa, bb;\n aa = a[n - 1];\n bb = b[n - 1];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n for (i = n - 2; i >= 0; i--) {\n aa = a[i];\n bb = b[i];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n }\n return 0;\n}']
33,522
0
https://github.com/openssl/openssl/blob/40a706286febe0279336c96374c607daaa1b1d49/crypto/lhash/lhash.c/#L240
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); }
['int ssl3_connect(SSL *s)\n\t{\n\tBUF_MEM *buf=NULL;\n\tunsigned long Time=(unsigned long)time(NULL);\n\tlong num1;\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\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\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\t\ts->state=SSL_ST_CONNECT;\n\t\t\ts->ctx->stats.sess_connect_renegotiate++;\n\t\tcase SSL_ST_BEFORE:\n\t\tcase SSL_ST_CONNECT:\n\t\tcase SSL_ST_BEFORE|SSL_ST_CONNECT:\n\t\tcase SSL_ST_OK|SSL_ST_CONNECT:\n\t\t\ts->server=0;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);\n\t\t\tif ((s->version & 0xff00 ) != 0x0300)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_CONNECT, ERR_R_INTERNAL_ERROR);\n\t\t\t\tret = -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\ts->type=SSL_ST_CONNECT;\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\tbuf=NULL;\n\t\t\t\t}\n\t\t\tif (!ssl3_setup_buffers(s)) { ret= -1; goto end; }\n\t\t\tif (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }\n\t\t\tssl3_init_finished_mac(s);\n\t\t\ts->state=SSL3_ST_CW_CLNT_HELLO_A;\n\t\t\ts->ctx->stats.sess_connect++;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CLNT_HELLO_A:\n\t\tcase SSL3_ST_CW_CLNT_HELLO_B:\n\t\t\ts->shutdown=0;\n\t\t\tret=ssl3_client_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_SRVR_HELLO_A;\n\t\t\ts->init_num=0;\n\t\t\tif (s->bbio != s->wbio)\n\t\t\t\ts->wbio=BIO_push(s->bbio,s->wbio);\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_SRVR_HELLO_A:\n\t\tcase SSL3_ST_CR_SRVR_HELLO_B:\n\t\t\tret=ssl3_get_server_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL3_ST_CR_FINISHED_A;\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_CR_CERT_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_CERT_A:\n\t\tcase SSL3_ST_CR_CERT_B:\n#ifndef OPENSSL_NO_TLSEXT\n\t\t\tret=ssl3_check_finished(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (ret == 2)\n\t\t\t\t{\n\t\t\t\ts->hit = 1;\n\t\t\t\tif (s->tlsext_ticket_expected)\n\t\t\t\t\ts->state=SSL3_ST_CR_SESSION_TICKET_A;\n\t\t\t\telse\n\t\t\t\t\ts->state=SSL3_ST_CR_FINISHED_A;\n\t\t\t\ts->init_num=0;\n\t\t\t\tbreak;\n\t\t\t\t}\n#endif\n\t\t\tif (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&\n\t\t\t !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))\n\t\t\t\t{\n\t\t\t\tret=ssl3_get_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_CR_CERT_STATUS_A;\n\t\t\t\telse\n\t\t\t\t\ts->state=SSL3_ST_CR_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_CR_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_CR_KEY_EXCH_A;\n#endif\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_KEY_EXCH_A:\n\t\tcase SSL3_ST_CR_KEY_EXCH_B:\n\t\t\tret=ssl3_get_key_exchange(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_CERT_REQ_A;\n\t\t\ts->init_num=0;\n\t\t\tif (!ssl3_check_cert_and_algorithm(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\tbreak;\n\t\tcase SSL3_ST_CR_CERT_REQ_A:\n\t\tcase SSL3_ST_CR_CERT_REQ_B:\n\t\t\tret=ssl3_get_certificate_request(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_SRVR_DONE_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_SRVR_DONE_A:\n\t\tcase SSL3_ST_CR_SRVR_DONE_B:\n\t\t\tret=ssl3_get_server_done(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->s3->tmp.cert_req)\n\t\t\t\ts->state=SSL3_ST_CW_CERT_A;\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_CW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CERT_A:\n\t\tcase SSL3_ST_CW_CERT_B:\n\t\tcase SSL3_ST_CW_CERT_C:\n\t\tcase SSL3_ST_CW_CERT_D:\n\t\t\tret=ssl3_send_client_certificate(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_KEY_EXCH_A:\n\t\tcase SSL3_ST_CW_KEY_EXCH_B:\n\t\t\tret=ssl3_send_client_key_exchange(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->s3->tmp.cert_req == 1)\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_CW_CERT_VRFY_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\t\ts->s3->change_cipher_spec=0;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CERT_VRFY_A:\n\t\tcase SSL3_ST_CW_CERT_VRFY_B:\n\t\t\tret=ssl3_send_client_verify(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\ts->init_num=0;\n\t\t\ts->s3->change_cipher_spec=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CHANGE_A:\n\t\tcase SSL3_ST_CW_CHANGE_B:\n\t\t\tret=ssl3_send_change_cipher_spec(s,\n\t\t\t\tSSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\ts->session->cipher=s->s3->tmp.new_cipher;\n#ifdef OPENSSL_NO_COMP\n\t\t\ts->session->compress_meth=0;\n#else\n\t\t\tif (s->s3->tmp.new_compression == NULL)\n\t\t\t\ts->session->compress_meth=0;\n\t\t\telse\n\t\t\t\ts->session->compress_meth=\n\t\t\t\t\ts->s3->tmp.new_compression->id;\n#endif\n\t\t\tif (!s->method->ssl3_enc->setup_key_block(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\tif (!s->method->ssl3_enc->change_cipher_state(s,\n\t\t\t\tSSL3_CHANGE_CIPHER_CLIENT_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\tbreak;\n\t\tcase SSL3_ST_CW_FINISHED_A:\n\t\tcase SSL3_ST_CW_FINISHED_B:\n\t\t\tret=ssl3_send_finished(s,\n\t\t\t\tSSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,\n\t\t\t\ts->method->ssl3_enc->client_finished_label,\n\t\t\t\ts->method->ssl3_enc->client_finished_label_len);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_FLUSH;\n\t\t\ts->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;\n\t\t\tif (s->hit)\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.next_state=SSL_ST_OK;\n\t\t\t\tif (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)\n\t\t\t\t\t{\n\t\t\t\t\ts->state=SSL_ST_OK;\n\t\t\t\t\ts->s3->flags|=SSL3_FLAGS_POP_BUFFER;\n\t\t\t\t\ts->s3->delay_buf_pop_ret=0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n#ifndef OPENSSL_NO_TLSEXT\n\t\t\t\tif (s->tlsext_ticket_expected)\n\t\t\t\t\ts->s3->tmp.next_state=SSL3_ST_CR_SESSION_TICKET_A;\n\t\t\t\telse\n#endif\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n#ifndef OPENSSL_NO_TLSEXT\n\t\tcase SSL3_ST_CR_SESSION_TICKET_A:\n\t\tcase SSL3_ST_CR_SESSION_TICKET_B:\n\t\t\tret=ssl3_get_new_session_ticket(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\tbreak;\n\t\tcase SSL3_ST_CR_CERT_STATUS_A:\n\t\tcase SSL3_ST_CR_CERT_STATUS_B:\n\t\t\tret=ssl3_get_cert_status(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\tbreak;\n#endif\n\t\tcase SSL3_ST_CR_FINISHED_A:\n\t\tcase SSL3_ST_CR_FINISHED_B:\n\t\t\tret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,\n\t\t\t\tSSL3_ST_CR_FINISHED_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\telse\n\t\t\t\ts->state=SSL_ST_OK;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_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 SSL_ST_OK:\n\t\t\tssl3_cleanup_key_block(s);\n\t\t\tif (s->init_buf != NULL)\n\t\t\t\t{\n\t\t\t\tBUF_MEM_free(s->init_buf);\n\t\t\t\ts->init_buf=NULL;\n\t\t\t\t}\n\t\t\tif (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))\n\t\t\t\tssl_free_wbio_buffer(s);\n\t\t\ts->init_num=0;\n\t\t\ts->new_session=0;\n\t\t\tssl_update_cache(s,SSL_SESS_CACHE_CLIENT);\n\t\t\tif (s->hit) s->ctx->stats.sess_hit++;\n\t\t\tret=1;\n\t\t\ts->handshake_func=ssl3_connect;\n\t\t\ts->ctx->stats.sess_connect_good++;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);\n\t\t\tgoto end;\n\t\tdefault:\n\t\t\tSSLerr(SSL_F_SSL3_CONNECT,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_CONNECT_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 (buf != NULL)\n\t\tBUF_MEM_free(buf);\n\tif (cb != NULL)\n\t\tcb(s,SSL_CB_CONNECT_EXIT,ret);\n\treturn(ret);\n\t}', 'int ssl3_get_certificate_request(SSL *s)\n\t{\n\tint ok,ret=0;\n\tunsigned long n,nc,l;\n\tunsigned int llen,ctype_num,i;\n\tX509_NAME *xn=NULL;\n\tconst unsigned char *p,*q;\n\tunsigned char *d;\n\tSTACK_OF(X509_NAME) *ca_sk=NULL;\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_CR_CERT_REQ_A,\n\t\tSSL3_ST_CR_CERT_REQ_B,\n\t\t-1,\n\t\ts->max_cert_list,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\ts->s3->tmp.cert_req=0;\n\tif (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE)\n\t\t{\n\t\ts->s3->tmp.reuse_message=1;\n\t\treturn(1);\n\t\t}\n\tif (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST)\n\t\t{\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);\n\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (s->version > SSL3_VERSION)\n\t\t{\n\t\tif (s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL)\n\t\t\t{\n\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tp=d=(unsigned char *)s->init_msg;\n\tif ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tctype_num= *(p++);\n\tif (ctype_num > SSL3_CT_NUMBER)\n\t\tctype_num=SSL3_CT_NUMBER;\n\tfor (i=0; i<ctype_num; i++)\n\t\ts->s3->tmp.ctype[i]= p[i];\n\tp+=ctype_num;\n\tn2s(p,llen);\n#if 0\n{\nFILE *out;\nout=fopen("/tmp/vsign.der","w");\nfwrite(p,1,llen,out);\nfclose(out);\n}\n#endif\n\tif ((llen+ctype_num+2+1) != n)\n\t\t{\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH);\n\t\tgoto err;\n\t\t}\n\tfor (nc=0; nc<llen; )\n\t\t{\n\t\tn2s(p,l);\n\t\tif ((l+nc+2) > llen)\n\t\t\t{\n\t\t\tif ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG))\n\t\t\t\tgoto cont;\n\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG);\n\t\t\tgoto err;\n\t\t\t}\n\t\tq=p;\n\t\tif ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL)\n\t\t\t{\n\t\t\tif (s->options & SSL_OP_NETSCAPE_CA_DN_BUG)\n\t\t\t\tgoto cont;\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\tif (q != (p+l))\n\t\t\t{\n\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!sk_X509_NAME_push(ca_sk,xn))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=l;\n\t\tnc+=l+2;\n\t\t}\n\tif (0)\n\t\t{\ncont:\n\t\tERR_clear_error();\n\t\t}\n\ts->s3->tmp.cert_req=1;\n\ts->s3->tmp.ctype_num=ctype_num;\n\tif (s->s3->tmp.ca_names != NULL)\n\t\tsk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);\n\ts->s3->tmp.ca_names=ca_sk;\n\tca_sk=NULL;\n\tret=1;\nerr:\n\tif (ca_sk != NULL) sk_X509_NAME_pop_free(ca_sk,X509_NAME_free);\n\treturn(ret);\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n\t\tdesc = SSL_AD_HANDSHAKE_FAILURE;\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\ts->method->ssl_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tif ((r = lh_SSL_SESSION_retrieve(ctx->sessions,c)) == c)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tr=lh_SSL_SESSION_delete(ctx->sessions,c);\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(_LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\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}']
33,523
0
https://github.com/libav/libav/blob/deb23777f2efe6f822841c420864637b62940838/avconv_opt.c/#L1657
static int opt_vstats(const char *opt, const char *arg) { char filename[40]; time_t today2 = time(NULL); struct tm *today = localtime(&today2); snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min, today->tm_sec); return opt_vstats_file(opt, filename); }
['static int opt_vstats(const char *opt, const char *arg)\n{\n char filename[40];\n time_t today2 = time(NULL);\n struct tm *today = localtime(&today2);\n snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,\n today->tm_sec);\n return opt_vstats_file(opt, filename);\n}']
33,524
0
https://github.com/openssl/openssl/blob/408bf2f0c4867b599faa3dd013d2b869fdad77dc/engines/e_4758_cca.c/#L747
static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len, unsigned char *sigret, unsigned int *siglen, const RSA *rsa) { long returnCode; long reasonCode; long exitDataLength = 0; unsigned char exitData[8]; long ruleArrayLength = 1; unsigned char ruleArray[8] = "PKCS-1.1"; long outputLength=256; long outputBitLength; long keyTokenLength; unsigned char *hashBuffer = NULL; unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx); long length = SSL_SIG_LEN; long keyLength ; X509_SIG sig; ASN1_TYPE parameter; X509_ALGOR algorithm; ASN1_OCTET_STRING digest; keyTokenLength = *(long*)keyToken; keyToken+=sizeof(long); if (type == NID_md5 || type == NID_sha1) { sig.algor = &algorithm; algorithm.algorithm = OBJ_nid2obj(type); if (!algorithm.algorithm) { CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, CCA4758_R_UNKNOWN_ALGORITHM_TYPE); return 0; } if (!algorithm.algorithm->length) { CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD); return 0; } parameter.type = V_ASN1_NULL; parameter.value.ptr = NULL; algorithm.parameter = &parameter; sig.digest = &digest; sig.digest->data = (unsigned char*)m; sig.digest->length = m_len; length = i2d_X509_SIG(&sig, NULL); } keyLength = RSA_size(rsa); if (length - RSA_PKCS1_PADDING > keyLength) { CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); return 0; } switch (type) { case NID_md5_sha1 : if (m_len != SSL_SIG_LEN) { CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN, CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL); return 0; } hashBuffer = (unsigned char*)m; length = m_len; break; case NID_md5 : { unsigned char *ptr; ptr = hashBuffer = OPENSSL_malloc( (unsigned int)keyLength+1); if (!hashBuffer) { CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, ERR_R_MALLOC_FAILURE); return 0; } i2d_X509_SIG(&sig, &ptr); } break; case NID_sha1 : { unsigned char *ptr; ptr = hashBuffer = OPENSSL_malloc( (unsigned int)keyLength+1); if (!hashBuffer) { CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY, ERR_R_MALLOC_FAILURE); return 0; } i2d_X509_SIG(&sig, &ptr); } break; default: return 0; } digitalSignatureGenerate(&returnCode, &reasonCode, &exitDataLength, exitData, &ruleArrayLength, ruleArray, &keyTokenLength, keyToken, &length, hashBuffer, &outputLength, &outputBitLength, sigret); if (type == NID_sha1 || type == NID_md5) { memset(hashBuffer, 0, keyLength+1); OPENSSL_free(hashBuffer); } *siglen = outputLength; return ((returnCode || reasonCode) ? 0 : 1); }
['static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,\n\t\tunsigned char *sigret, unsigned int *siglen, const RSA *rsa)\n\t{\n\tlong returnCode;\n\tlong reasonCode;\n\tlong exitDataLength = 0;\n\tunsigned char exitData[8];\n\tlong ruleArrayLength = 1;\n\tunsigned char ruleArray[8] = "PKCS-1.1";\n\tlong outputLength=256;\n\tlong outputBitLength;\n\tlong keyTokenLength;\n\tunsigned char *hashBuffer = NULL;\n\tunsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);\n\tlong length = SSL_SIG_LEN;\n\tlong keyLength ;\n\tX509_SIG sig;\n\tASN1_TYPE parameter;\n\tX509_ALGOR algorithm;\n\tASN1_OCTET_STRING digest;\n\tkeyTokenLength = *(long*)keyToken;\n\tkeyToken+=sizeof(long);\n\tif (type == NID_md5 || type == NID_sha1)\n\t\t{\n\t\tsig.algor = &algorithm;\n\t\talgorithm.algorithm = OBJ_nid2obj(type);\n\t\tif (!algorithm.algorithm)\n\t\t\t{\n\t\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,\n\t\t\t\tCCA4758_R_UNKNOWN_ALGORITHM_TYPE);\n\t\t\treturn 0;\n\t\t\t}\n\t\tif (!algorithm.algorithm->length)\n\t\t\t{\n\t\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,\n\t\t\t\tCCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);\n\t\t\treturn 0;\n\t\t\t}\n\t\tparameter.type = V_ASN1_NULL;\n\t\tparameter.value.ptr = NULL;\n\t\talgorithm.parameter = &parameter;\n\t\tsig.digest = &digest;\n\t\tsig.digest->data = (unsigned char*)m;\n\t\tsig.digest->length = m_len;\n\t\tlength = i2d_X509_SIG(&sig, NULL);\n\t\t}\n\tkeyLength = RSA_size(rsa);\n\tif (length - RSA_PKCS1_PADDING > keyLength)\n\t\t{\n\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,\n\t\t\tCCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);\n\t\treturn 0;\n\t\t}\n\tswitch (type)\n\t\t{\n\t\tcase NID_md5_sha1 :\n\t\t\tif (m_len != SSL_SIG_LEN)\n\t\t\t\t{\n\t\t\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,\n\t\t\t\tCCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\thashBuffer = (unsigned char*)m;\n\t\t\tlength = m_len;\n\t\t\tbreak;\n\t\tcase NID_md5 :\n\t\t\t{\n\t\t\tunsigned char *ptr;\n\t\t\tptr = hashBuffer = OPENSSL_malloc(\n\t\t\t\t\t(unsigned int)keyLength+1);\n\t\t\tif (!hashBuffer)\n\t\t\t\t{\n\t\t\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,\n\t\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\ti2d_X509_SIG(&sig, &ptr);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase NID_sha1 :\n\t\t\t{\n\t\t\tunsigned char *ptr;\n\t\t\tptr = hashBuffer = OPENSSL_malloc(\n\t\t\t\t\t(unsigned int)keyLength+1);\n\t\t\tif (!hashBuffer)\n\t\t\t\t{\n\t\t\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,\n\t\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\ti2d_X509_SIG(&sig, &ptr);\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\treturn 0;\n\t\t}\n\tdigitalSignatureGenerate(&returnCode, &reasonCode, &exitDataLength,\n\t\texitData, &ruleArrayLength, ruleArray, &keyTokenLength,\n\t\tkeyToken, &length, hashBuffer, &outputLength, &outputBitLength,\n\t\tsigret);\n\tif (type == NID_sha1 || type == NID_md5)\n\t\t{\n\t\tmemset(hashBuffer, 0, keyLength+1);\n\t\tOPENSSL_free(hashBuffer);\n\t\t}\n\t*siglen = outputLength;\n\treturn ((returnCode || reasonCode) ? 0 : 1);\n\t}', 'void *RSA_get_ex_data(const RSA *r, int idx)\n\t{\n\treturn(CRYPTO_get_ex_data(&r->ex_data,idx));\n\t}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n\t{\n\tif (ad->sk == NULL)\n\t\treturn(0);\n\telse if (idx >= sk_num(ad->sk))\n\t\treturn(0);\n\telse\n\t\treturn(sk_value(ad->sk,idx));\n\t}', 'int sk_num(const STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}']
33,525
0
https://github.com/libav/libav/blob/22b16e6a5db14f6b10525fab69e1c0b58cfa899b/libavcodec/mpegvideo_enc.c/#L952
static int estimate_best_b_count(MpegEncContext *s){ AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id); AVCodecContext *c= avcodec_alloc_context(); AVFrame input[FF_MAX_B_FRAMES+2]; const int scale= s->avctx->brd_scale; int i, j, out_size, p_lambda, b_lambda, lambda2; int outbuf_size= s->width * s->height; uint8_t *outbuf= av_malloc(outbuf_size); int64_t best_rd= INT64_MAX; int best_b_count= -1; assert(scale>=0 && scale <=3); p_lambda= s->last_lambda_for[FF_P_TYPE]; b_lambda= s->last_lambda_for[FF_B_TYPE]; if(!b_lambda) b_lambda= p_lambda; lambda2= (b_lambda*b_lambda + (1<<FF_LAMBDA_SHIFT)/2 ) >> FF_LAMBDA_SHIFT; c->width = s->width >> scale; c->height= s->height>> scale; c->flags= CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | CODEC_FLAG_INPUT_PRESERVED ; c->flags|= s->avctx->flags & CODEC_FLAG_QPEL; c->mb_decision= s->avctx->mb_decision; c->me_cmp= s->avctx->me_cmp; c->mb_cmp= s->avctx->mb_cmp; c->me_sub_cmp= s->avctx->me_sub_cmp; c->pix_fmt = PIX_FMT_YUV420P; c->time_base= s->avctx->time_base; c->max_b_frames= s->max_b_frames; if (avcodec_open(c, codec) < 0) return -1; for(i=0; i<s->max_b_frames+2; i++){ int ysize= c->width*c->height; int csize= (c->width/2)*(c->height/2); Picture pre_input, *pre_input_ptr= i ? s->input_picture[i-1] : s->next_picture_ptr; avcodec_get_frame_defaults(&input[i]); input[i].data[0]= av_malloc(ysize + 2*csize); input[i].data[1]= input[i].data[0] + ysize; input[i].data[2]= input[i].data[1] + csize; input[i].linesize[0]= c->width; input[i].linesize[1]= input[i].linesize[2]= c->width/2; if(pre_input_ptr && (!i || s->input_picture[i-1])) { pre_input= *pre_input_ptr; if(pre_input.type != FF_BUFFER_TYPE_SHARED && i) { pre_input.data[0]+=INPLACE_OFFSET; pre_input.data[1]+=INPLACE_OFFSET; pre_input.data[2]+=INPLACE_OFFSET; } s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], pre_input.data[0], pre_input.linesize[0], c->width, c->height); s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], pre_input.data[1], pre_input.linesize[1], c->width>>1, c->height>>1); s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], pre_input.data[2], pre_input.linesize[2], c->width>>1, c->height>>1); } } for(j=0; j<s->max_b_frames+1; j++){ int64_t rd=0; if(!s->input_picture[j]) break; c->error[0]= c->error[1]= c->error[2]= 0; input[0].pict_type= FF_I_TYPE; input[0].quality= 1 * FF_QP2LAMBDA; out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[0]); for(i=0; i<s->max_b_frames+1; i++){ int is_p= i % (j+1) == j || i==s->max_b_frames; input[i+1].pict_type= is_p ? FF_P_TYPE : FF_B_TYPE; input[i+1].quality= is_p ? p_lambda : b_lambda; out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[i+1]); rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); } while(out_size){ out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL); rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); } rd += c->error[0] + c->error[1] + c->error[2]; if(rd < best_rd){ best_rd= rd; best_b_count= j; } } av_freep(&outbuf); avcodec_close(c); av_freep(&c); for(i=0; i<s->max_b_frames+2; i++){ av_freep(&input[i].data[0]); } return best_b_count; }
['static int estimate_best_b_count(MpegEncContext *s){\n AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id);\n AVCodecContext *c= avcodec_alloc_context();\n AVFrame input[FF_MAX_B_FRAMES+2];\n const int scale= s->avctx->brd_scale;\n int i, j, out_size, p_lambda, b_lambda, lambda2;\n int outbuf_size= s->width * s->height;\n uint8_t *outbuf= av_malloc(outbuf_size);\n int64_t best_rd= INT64_MAX;\n int best_b_count= -1;\n assert(scale>=0 && scale <=3);\n p_lambda= s->last_lambda_for[FF_P_TYPE];\n b_lambda= s->last_lambda_for[FF_B_TYPE];\n if(!b_lambda) b_lambda= p_lambda;\n lambda2= (b_lambda*b_lambda + (1<<FF_LAMBDA_SHIFT)/2 ) >> FF_LAMBDA_SHIFT;\n c->width = s->width >> scale;\n c->height= s->height>> scale;\n c->flags= CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | CODEC_FLAG_INPUT_PRESERVED ;\n c->flags|= s->avctx->flags & CODEC_FLAG_QPEL;\n c->mb_decision= s->avctx->mb_decision;\n c->me_cmp= s->avctx->me_cmp;\n c->mb_cmp= s->avctx->mb_cmp;\n c->me_sub_cmp= s->avctx->me_sub_cmp;\n c->pix_fmt = PIX_FMT_YUV420P;\n c->time_base= s->avctx->time_base;\n c->max_b_frames= s->max_b_frames;\n if (avcodec_open(c, codec) < 0)\n return -1;\n for(i=0; i<s->max_b_frames+2; i++){\n int ysize= c->width*c->height;\n int csize= (c->width/2)*(c->height/2);\n Picture pre_input, *pre_input_ptr= i ? s->input_picture[i-1] : s->next_picture_ptr;\n avcodec_get_frame_defaults(&input[i]);\n input[i].data[0]= av_malloc(ysize + 2*csize);\n input[i].data[1]= input[i].data[0] + ysize;\n input[i].data[2]= input[i].data[1] + csize;\n input[i].linesize[0]= c->width;\n input[i].linesize[1]=\n input[i].linesize[2]= c->width/2;\n if(pre_input_ptr && (!i || s->input_picture[i-1])) {\n pre_input= *pre_input_ptr;\n if(pre_input.type != FF_BUFFER_TYPE_SHARED && i) {\n pre_input.data[0]+=INPLACE_OFFSET;\n pre_input.data[1]+=INPLACE_OFFSET;\n pre_input.data[2]+=INPLACE_OFFSET;\n }\n s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], pre_input.data[0], pre_input.linesize[0], c->width, c->height);\n s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], pre_input.data[1], pre_input.linesize[1], c->width>>1, c->height>>1);\n s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], pre_input.data[2], pre_input.linesize[2], c->width>>1, c->height>>1);\n }\n }\n for(j=0; j<s->max_b_frames+1; j++){\n int64_t rd=0;\n if(!s->input_picture[j])\n break;\n c->error[0]= c->error[1]= c->error[2]= 0;\n input[0].pict_type= FF_I_TYPE;\n input[0].quality= 1 * FF_QP2LAMBDA;\n out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[0]);\n for(i=0; i<s->max_b_frames+1; i++){\n int is_p= i % (j+1) == j || i==s->max_b_frames;\n input[i+1].pict_type= is_p ? FF_P_TYPE : FF_B_TYPE;\n input[i+1].quality= is_p ? p_lambda : b_lambda;\n out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[i+1]);\n rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);\n }\n while(out_size){\n out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);\n rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);\n }\n rd += c->error[0] + c->error[1] + c->error[2];\n if(rd < best_rd){\n best_rd= rd;\n best_b_count= j;\n }\n }\n av_freep(&outbuf);\n avcodec_close(c);\n av_freep(&c);\n for(i=0; i<s->max_b_frames+2; i++){\n av_freep(&input[i].data[0]);\n }\n return best_b_count;\n}', 'AVCodecContext *avcodec_alloc_context(void){\n return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN);\n}', 'AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){\n AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));\n if(avctx==NULL) return NULL;\n avcodec_get_context_defaults2(avctx, codec_type);\n return avctx;\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}']
33,526
0
https://github.com/openssl/openssl/blob/f3ff481f318b10a223d6157bde9645e1797487c5/ssl/packet.c/#L25
int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes) { assert(pkt->subs != NULL && len != 0); if (pkt->subs == NULL || len == 0) return 0; if (pkt->maxsize - pkt->written < len) return 0; if (pkt->buf->length - pkt->written < len) { size_t newlen; if (pkt->buf->length > SIZE_MAX / 2) { newlen = SIZE_MAX; } else { newlen = (pkt->buf->length == 0) ? DEFAULT_BUF_SIZE : pkt->buf->length * 2; } if (BUF_MEM_grow(pkt->buf, newlen) == 0) return 0; } *allocbytes = (unsigned char *)pkt->buf->data + pkt->curr; pkt->written += len; pkt->curr += len; return 1; }
['int ssl_add_clienthello_tlsext(SSL *s, WPACKET *pkt, int *al)\n{\n#ifndef OPENSSL_NO_EC\n int using_ecc = 0;\n if (s->version >= TLS1_VERSION || SSL_IS_DTLS(s)) {\n int i;\n unsigned long alg_k, alg_a;\n STACK_OF(SSL_CIPHER) *cipher_stack = SSL_get_ciphers(s);\n for (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++) {\n const SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i);\n alg_k = c->algorithm_mkey;\n alg_a = c->algorithm_auth;\n if ((alg_k & (SSL_kECDHE | SSL_kECDHEPSK))\n || (alg_a & SSL_aECDSA)) {\n using_ecc = 1;\n break;\n }\n }\n }\n#endif\n if (s->renegotiate) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_renegotiate)\n || !WPACKET_sub_memcpy_u16(pkt, s->s3->previous_client_finished,\n s->s3->previous_client_finished_len)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (s->client_version == SSL3_VERSION)\n goto done;\n if (s->tlsext_hostname != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_server_name)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, TLSEXT_NAMETYPE_host_name)\n || !WPACKET_sub_memcpy_u16(pkt, s->tlsext_hostname,\n strlen(s->tlsext_hostname))\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#ifndef OPENSSL_NO_SRP\n if (s->srp_ctx.login != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_srp)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u8(pkt)\n || !WPACKET_set_flags(pkt, WPACKET_FLAGS_NON_ZERO_LENGTH)\n || !WPACKET_memcpy(pkt, s->srp_ctx.login,\n strlen(s->srp_ctx.login))\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_EC\n if (using_ecc) {\n const unsigned char *pcurves, *pformats;\n size_t num_curves, num_formats;\n size_t i;\n tls1_get_formatlist(s, &pformats, &num_formats);\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_sub_memcpy_u8(pkt, pformats, num_formats)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pcurves = s->tlsext_ellipticcurvelist;\n if (!tls1_get_curvelist(s, 0, &pcurves, &num_curves)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_elliptic_curves)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n for (i = 0; i < num_curves; i++, pcurves += 2) {\n if (tls_curve_allowed(s, pcurves, SSL_SECOP_CURVE_SUPPORTED)) {\n if (!WPACKET_put_bytes_u8(pkt, pcurves[0])\n || !WPACKET_put_bytes_u8(pkt, pcurves[1])) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (tls_use_ticket(s)) {\n int ticklen;\n if (!s->new_session && s->session && s->session->tlsext_tick)\n ticklen = s->session->tlsext_ticklen;\n else if (s->session && s->tlsext_session_ticket &&\n s->tlsext_session_ticket->data) {\n ticklen = s->tlsext_session_ticket->length;\n s->session->tlsext_tick = OPENSSL_malloc(ticklen);\n if (s->session->tlsext_tick == NULL) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n memcpy(s->session->tlsext_tick,\n s->tlsext_session_ticket->data, ticklen);\n s->session->tlsext_ticklen = ticklen;\n } else\n ticklen = 0;\n if (ticklen == 0 && s->tlsext_session_ticket &&\n s->tlsext_session_ticket->data == NULL)\n goto skip_ext;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_session_ticket)\n || !WPACKET_sub_memcpy_u16(pkt, s->session->tlsext_tick,\n ticklen)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n skip_ext:\n if (SSL_CLIENT_USE_SIGALGS(s)) {\n size_t salglen;\n const unsigned char *salg;\n salglen = tls12_get_psigalgs(s, &salg);\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signature_algorithms)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !tls12_copy_sigalgs(s, pkt, salg, salglen)\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#ifndef OPENSSL_NO_OCSP\n if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp) {\n int i;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_status_request)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, TLSEXT_STATUSTYPE_ocsp)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) {\n unsigned char *idbytes;\n int idlen;\n OCSP_RESPID *id;\n id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i);\n idlen = i2d_OCSP_RESPID(id, NULL);\n if (idlen <= 0\n || !WPACKET_sub_allocate_bytes_u16(pkt, idlen, &idbytes)\n || i2d_OCSP_RESPID(id, &idbytes) != idlen) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (s->tlsext_ocsp_exts) {\n unsigned char *extbytes;\n int extlen = i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, NULL);\n if (extlen < 0) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_allocate_bytes(pkt, extlen, &extbytes)\n || i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &extbytes)\n != extlen) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_HEARTBEATS\n if (SSL_IS_DTLS(s)) {\n unsigned int mode;\n if (s->tlsext_heartbeat & SSL_DTLSEXT_HB_DONT_RECV_REQUESTS)\n mode = SSL_DTLSEXT_HB_DONT_SEND_REQUESTS;\n else\n mode = SSL_DTLSEXT_HB_ENABLED;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_heartbeat)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, mode)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n if (s->ctx->next_proto_select_cb && !s->s3->tmp.finish_md_len) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_next_proto_neg)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (s->alpn_client_proto_list && !s->s3->tmp.finish_md_len) {\n if (!WPACKET_put_bytes_u16(pkt,\n TLSEXT_TYPE_application_layer_protocol_negotiation)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_sub_memcpy_u16(pkt, s->alpn_client_proto_list,\n s->alpn_client_proto_list_len)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n s->s3->alpn_sent = 1;\n }\n#ifndef OPENSSL_NO_SRTP\n if (SSL_IS_DTLS(s) && SSL_get_srtp_profiles(s)) {\n STACK_OF(SRTP_PROTECTION_PROFILE) *clnt = 0;\n SRTP_PROTECTION_PROFILE *prof;\n int i, ct;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_use_srtp)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n ct = sk_SRTP_PROTECTION_PROFILE_num(clnt);\n for (i = 0; i < ct; i++) {\n prof = sk_SRTP_PROTECTION_PROFILE_value(clnt, i);\n if (prof == NULL || !WPACKET_put_bytes_u16(pkt, prof->id)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n custom_ext_init(&s->cert->cli_ext);\n if (!custom_ext_add(s, 0, pkt, al)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_encrypt_then_mac)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n#ifndef OPENSSL_NO_CT\n if (s->ct_validation_callback != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signed_certificate_timestamp)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_extended_master_secret)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (s->options & SSL_OP_TLSEXT_PADDING) {\n unsigned char *padbytes;\n size_t hlen;\n if (!WPACKET_get_total_written(pkt, &hlen)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (hlen > 0xff && hlen < 0x200) {\n hlen = 0x200 - hlen;\n if (hlen >= 4)\n hlen -= 4;\n else\n hlen = 0;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_padding)\n || !WPACKET_sub_allocate_bytes_u16(pkt, hlen, &padbytes)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n memset(padbytes, 0, hlen);\n }\n }\n done:\n return 1;\n}', 'int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)\n{\n unsigned char *data;\n assert(size <= sizeof(unsigned int));\n if (size > sizeof(unsigned int)\n || !WPACKET_allocate_bytes(pkt, size, &data)\n || !put_value(data, val, size))\n return 0;\n return 1;\n}', 'int WPACKET_sub_memcpy__(WPACKET *pkt, const void *src, size_t len,\n size_t lenbytes)\n{\n if (!WPACKET_start_sub_packet_len__(pkt, lenbytes)\n || !WPACKET_memcpy(pkt, src, len)\n || !WPACKET_close(pkt))\n return 0;\n return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n assert(pkt->subs != NULL);\n if (pkt->subs == NULL)\n return 0;\n sub = OPENSSL_zalloc(sizeof(*sub));\n if (sub == NULL)\n return 0;\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n sub->packet_len = lenchars - (unsigned char *)pkt->buf->data;\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n assert(pkt->subs != NULL && len != 0);\n if (pkt->subs == NULL || len == 0)\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->buf->length - pkt->written < len) {\n size_t newlen;\n if (pkt->buf->length > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = (pkt->buf->length == 0) ? DEFAULT_BUF_SIZE\n : pkt->buf->length * 2;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n *allocbytes = (unsigned char *)pkt->buf->data + pkt->curr;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}']
33,527
0
https://github.com/openssl/openssl/blob/0cb957a6846dde0bee52f69c538aae5e7062ac73/apps/x509.c/#L1214
static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, const EVP_MD *digest, LHASH *conf, char *section) { EVP_PKEY *pktmp; pktmp = X509_get_pubkey(x); EVP_PKEY_copy_parameters(pktmp,pkey); EVP_PKEY_save_parameters(pktmp,1); EVP_PKEY_free(pktmp); if (!X509_set_issuer_name(x,X509_get_subject_name(x))) goto err; if (X509_gmtime_adj(X509_get_notBefore(x),0) == NULL) goto err; if (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL) goto err; if (!X509_set_pubkey(x,pkey)) goto err; if(clrext) { while(X509_get_ext_count(x) > 0) X509_delete_ext(x, 0); } if(conf) { X509V3_CTX ctx; X509_set_version(x,2); X509V3_set_ctx(&ctx, x, x, NULL, NULL, 0); X509V3_set_conf_lhash(&ctx, conf); if(!X509V3_EXT_add_conf(conf, &ctx, section, x)) goto err; } if (!X509_sign(x,pkey,digest)) goto err; return(1); err: ERR_print_errors(bio_err); return(0); }
['static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, const EVP_MD *digest,\n\t\t\t\t\t\tLHASH *conf, char *section)\n\t{\n\tEVP_PKEY *pktmp;\n\tpktmp = X509_get_pubkey(x);\n\tEVP_PKEY_copy_parameters(pktmp,pkey);\n\tEVP_PKEY_save_parameters(pktmp,1);\n\tEVP_PKEY_free(pktmp);\n\tif (!X509_set_issuer_name(x,X509_get_subject_name(x))) goto err;\n\tif (X509_gmtime_adj(X509_get_notBefore(x),0) == NULL) goto err;\n\tif (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL)\n\t\tgoto err;\n\tif (!X509_set_pubkey(x,pkey)) goto err;\n\tif(clrext) {\n\t\twhile(X509_get_ext_count(x) > 0) X509_delete_ext(x, 0);\n\t}\n\tif(conf) {\n\t\tX509V3_CTX ctx;\n\t\tX509_set_version(x,2);\n X509V3_set_ctx(&ctx, x, x, NULL, NULL, 0);\n X509V3_set_conf_lhash(&ctx, conf);\n if(!X509V3_EXT_add_conf(conf, &ctx, section, x)) goto err;\n\t}\n\tif (!X509_sign(x,pkey,digest)) goto err;\n\treturn(1);\nerr:\n\tERR_print_errors(bio_err);\n\treturn(0);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)\n\t{\n#ifndef NO_DSA\n\tif (pkey->type == EVP_PKEY_DSA)\n\t\t{\n\t\tint ret=pkey->save_parameters=mode;\n\t\tif (mode >= 0)\n\t\t\tpkey->save_parameters=mode;\n\t\treturn(ret);\n\t\t}\n#endif\n\treturn(0);\n\t}']
33,528
0
https://github.com/libav/libav/blob/67ce33162aa93bee1a5f9e8d6f00060329fa67da/libavcodec/lclenc.c/#L174
static av_cold int encode_init(AVCodecContext *avctx) { LclEncContext *c = avctx->priv_data; int zret; #ifndef CONFIG_ZLIB av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); return 1; #else c->avctx= avctx; assert(avctx->width && avctx->height); avctx->extradata= av_mallocz(8); avctx->coded_frame= &c->pic; c->compression = 6; c->flags = 0; switch(avctx->pix_fmt){ case PIX_FMT_BGR24: c->imgtype = IMGTYPE_RGB24; c->decomp_size = avctx->width * avctx->height * 3; avctx->bits_per_coded_sample= 24; break; default: av_log(avctx, AV_LOG_ERROR, "Input pixel format %s not supported\n", avcodec_get_pix_fmt_name(avctx->pix_fmt)); return -1; } ((uint8_t*)avctx->extradata)[0]= 4; ((uint8_t*)avctx->extradata)[1]= 0; ((uint8_t*)avctx->extradata)[2]= 0; ((uint8_t*)avctx->extradata)[3]= 0; ((uint8_t*)avctx->extradata)[4]= c->imgtype; ((uint8_t*)avctx->extradata)[5]= c->compression; ((uint8_t*)avctx->extradata)[6]= c->flags; ((uint8_t*)avctx->extradata)[7]= CODEC_ZLIB; c->avctx->extradata_size= 8; c->zstream.zalloc = Z_NULL; c->zstream.zfree = Z_NULL; c->zstream.opaque = Z_NULL; zret = deflateInit(&(c->zstream), c->compression); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Deflate init error: %d\n", zret); return 1; } c->max_comp_size = c->decomp_size + ((c->decomp_size + 7) >> 3) + ((c->decomp_size + 63) >> 6) + 11; if ((c->comp_buf = av_malloc(c->max_comp_size)) == NULL) { av_log(avctx, AV_LOG_ERROR, "Can't allocate compression buffer.\n"); return 1; } return 0; #endif }
['static av_cold int encode_init(AVCodecContext *avctx)\n{\n LclEncContext *c = avctx->priv_data;\n int zret;\n#ifndef CONFIG_ZLIB\n av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\\n");\n return 1;\n#else\n c->avctx= avctx;\n assert(avctx->width && avctx->height);\n avctx->extradata= av_mallocz(8);\n avctx->coded_frame= &c->pic;\n c->compression = 6;\n c->flags = 0;\n switch(avctx->pix_fmt){\n case PIX_FMT_BGR24:\n c->imgtype = IMGTYPE_RGB24;\n c->decomp_size = avctx->width * avctx->height * 3;\n avctx->bits_per_coded_sample= 24;\n break;\n default:\n av_log(avctx, AV_LOG_ERROR, "Input pixel format %s not supported\\n", avcodec_get_pix_fmt_name(avctx->pix_fmt));\n return -1;\n }\n ((uint8_t*)avctx->extradata)[0]= 4;\n ((uint8_t*)avctx->extradata)[1]= 0;\n ((uint8_t*)avctx->extradata)[2]= 0;\n ((uint8_t*)avctx->extradata)[3]= 0;\n ((uint8_t*)avctx->extradata)[4]= c->imgtype;\n ((uint8_t*)avctx->extradata)[5]= c->compression;\n ((uint8_t*)avctx->extradata)[6]= c->flags;\n ((uint8_t*)avctx->extradata)[7]= CODEC_ZLIB;\n c->avctx->extradata_size= 8;\n c->zstream.zalloc = Z_NULL;\n c->zstream.zfree = Z_NULL;\n c->zstream.opaque = Z_NULL;\n zret = deflateInit(&(c->zstream), c->compression);\n if (zret != Z_OK) {\n av_log(avctx, AV_LOG_ERROR, "Deflate init error: %d\\n", zret);\n return 1;\n }\n c->max_comp_size = c->decomp_size + ((c->decomp_size + 7) >> 3) +\n ((c->decomp_size + 63) >> 6) + 11;\n if ((c->comp_buf = av_malloc(c->max_comp_size)) == NULL) {\n av_log(avctx, AV_LOG_ERROR, "Can\'t allocate compression buffer.\\n");\n return 1;\n }\n return 0;\n#endif\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}']
33,529
0
https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L340
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while (num--) { bn_check_top(p->current->vals + offset); if (offset == 0) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['int rsa_check_crt_components(const RSA *rsa, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *r = NULL, *p1 = NULL, *q1 = NULL;\n if (rsa->dmp1 == NULL || rsa->dmq1 == NULL || rsa->iqmp == NULL) {\n if (rsa->dmp1 != NULL || rsa->dmq1 != NULL || rsa->iqmp != NULL)\n return 0;\n return 1;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n p1 = BN_CTX_get(ctx);\n q1 = BN_CTX_get(ctx);\n ret = (q1 != NULL)\n && (BN_copy(p1, rsa->p) != NULL)\n && BN_sub_word(p1, 1)\n && (BN_copy(q1, rsa->q) != NULL)\n && BN_sub_word(q1, 1)\n && (BN_cmp(rsa->dmp1, BN_value_one()) > 0)\n && (BN_cmp(rsa->dmp1, p1) < 0)\n && (BN_cmp(rsa->dmq1, BN_value_one()) > 0)\n && (BN_cmp(rsa->dmq1, q1) < 0)\n && (BN_cmp(rsa->iqmp, BN_value_one()) > 0)\n && (BN_cmp(rsa->iqmp, rsa->p) < 0)\n && BN_mod_mul(r, rsa->dmp1, rsa->e, p1, ctx)\n && BN_is_one(r)\n && BN_mod_mul(r, rsa->dmq1, rsa->e, q1, ctx)\n && BN_is_one(r)\n && BN_mod_mul(r, rsa->iqmp, rsa->q, rsa->p, ctx)\n && BN_is_one(r);\n BN_clear(p1);\n BN_clear(q1);\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG("ENTER BN_CTX_get()", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG("LEAVE BN_CTX_get()", ctx);\n return ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = bn_mul_fixed_top(r, a, b, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (offset == 0) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
33,530
0
https://github.com/libav/libav/blob/f73467192558cadff476c98c73767ec04e7212c3/libavutil/avstring.c/#L88
size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) { int len = strlen(dst); va_list vl; va_start(vl, fmt); len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl); va_end(vl); return len; }
['static int make_setup_request(AVFormatContext *s, const char *host, int port,\n int lower_transport, const char *real_challenge)\n{\n RTSPState *rt = s->priv_data;\n int rtx, j, i, err, interleave = 0;\n RTSPStream *rtsp_st;\n RTSPMessageHeader reply1, *reply = &reply1;\n char cmd[2048];\n const char *trans_pref;\n if (rt->transport == RTSP_TRANSPORT_RDT)\n trans_pref = "x-pn-tng";\n else\n trans_pref = "RTP/AVP";\n rt->timeout = 60;\n for (j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) {\n char transport[2048];\n if (lower_transport == RTSP_LOWER_TRANSPORT_UDP &&\n rt->server_type == RTSP_SERVER_WMS) {\n if (i == 0) {\n for (rtx = 0; rtx < rt->nb_rtsp_streams; rtx++) {\n int len = strlen(rt->rtsp_streams[rtx]->control_url);\n if (len >= 4 &&\n !strcmp(rt->rtsp_streams[rtx]->control_url + len - 4,\n "/rtx"))\n break;\n }\n if (rtx == rt->nb_rtsp_streams)\n return -1;\n rtsp_st = rt->rtsp_streams[rtx];\n } else\n rtsp_st = rt->rtsp_streams[i > rtx ? i : i - 1];\n } else\n rtsp_st = rt->rtsp_streams[i];\n if (lower_transport == RTSP_LOWER_TRANSPORT_UDP) {\n char buf[256];\n if (rt->server_type == RTSP_SERVER_WMS && i > 1) {\n port = reply->transports[0].client_port_min;\n goto have_port;\n }\n if (RTSP_RTP_PORT_MIN != 0) {\n while (j <= RTSP_RTP_PORT_MAX) {\n ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1,\n "?localport=%d", j);\n j += 2;\n if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0)\n goto rtp_opened;\n }\n }\n#if 0\n if (url_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) {\n err = AVERROR_INVALIDDATA;\n goto fail;\n }\n#else\n av_log(s, AV_LOG_ERROR, "Unable to open an input RTP port\\n");\n err = AVERROR(EIO);\n goto fail;\n#endif\n rtp_opened:\n port = rtp_get_local_rtp_port(rtsp_st->rtp_handle);\n have_port:\n snprintf(transport, sizeof(transport) - 1,\n "%s/UDP;", trans_pref);\n if (rt->server_type != RTSP_SERVER_REAL)\n av_strlcat(transport, "unicast;", sizeof(transport));\n av_strlcatf(transport, sizeof(transport),\n "client_port=%d", port);\n if (rt->transport == RTSP_TRANSPORT_RTP &&\n !(rt->server_type == RTSP_SERVER_WMS && i > 0))\n av_strlcatf(transport, sizeof(transport), "-%d", port + 1);\n }\n else if (lower_transport == RTSP_LOWER_TRANSPORT_TCP) {\n if (rt->server_type == RTSP_SERVER_WMS &&\n s->streams[rtsp_st->stream_index]->codec->codec_type ==\n AVMEDIA_TYPE_DATA)\n continue;\n snprintf(transport, sizeof(transport) - 1,\n "%s/TCP;", trans_pref);\n if (rt->server_type == RTSP_SERVER_WMS)\n av_strlcat(transport, "unicast;", sizeof(transport));\n av_strlcatf(transport, sizeof(transport),\n "interleaved=%d-%d",\n interleave, interleave + 1);\n interleave += 2;\n }\n else if (lower_transport == RTSP_LOWER_TRANSPORT_UDP_MULTICAST) {\n snprintf(transport, sizeof(transport) - 1,\n "%s/UDP;multicast", trans_pref);\n }\n if (s->oformat) {\n av_strlcat(transport, ";mode=receive", sizeof(transport));\n } else if (rt->server_type == RTSP_SERVER_REAL ||\n rt->server_type == RTSP_SERVER_WMS)\n av_strlcat(transport, ";mode=play", sizeof(transport));\n snprintf(cmd, sizeof(cmd),\n "Transport: %s\\r\\n",\n transport);\n if (i == 0 && rt->server_type == RTSP_SERVER_REAL && CONFIG_RTPDEC) {\n char real_res[41], real_csum[9];\n ff_rdt_calc_response_and_checksum(real_res, real_csum,\n real_challenge);\n av_strlcatf(cmd, sizeof(cmd),\n "If-Match: %s\\r\\n"\n "RealChallenge2: %s, sd=%s\\r\\n",\n rt->session_id, real_res, real_csum);\n }\n ff_rtsp_send_cmd(s, "SETUP", rtsp_st->control_url, cmd, reply, NULL);\n if (reply->status_code == 461 && i == 0) {\n err = 1;\n goto fail;\n } else if (reply->status_code != RTSP_STATUS_OK ||\n reply->nb_transports != 1) {\n err = AVERROR_INVALIDDATA;\n goto fail;\n }\n if (i > 0) {\n if (reply->transports[0].lower_transport != rt->lower_transport ||\n reply->transports[0].transport != rt->transport) {\n err = AVERROR_INVALIDDATA;\n goto fail;\n }\n } else {\n rt->lower_transport = reply->transports[0].lower_transport;\n rt->transport = reply->transports[0].transport;\n }\n if (reply->transports[0].lower_transport != lower_transport) {\n av_log(s, AV_LOG_ERROR, "Nonmatching transport in server reply\\n");\n err = AVERROR_INVALIDDATA;\n goto fail;\n }\n switch(reply->transports[0].lower_transport) {\n case RTSP_LOWER_TRANSPORT_TCP:\n rtsp_st->interleaved_min = reply->transports[0].interleaved_min;\n rtsp_st->interleaved_max = reply->transports[0].interleaved_max;\n break;\n case RTSP_LOWER_TRANSPORT_UDP: {\n char url[1024], options[30] = "";\n if (rt->filter_source)\n av_strlcpy(options, "?connect=1", sizeof(options));\n if (reply->transports[0].source[0]) {\n ff_url_join(url, sizeof(url), "rtp", NULL,\n reply->transports[0].source,\n reply->transports[0].server_port_min, options);\n } else {\n ff_url_join(url, sizeof(url), "rtp", NULL, host,\n reply->transports[0].server_port_min, options);\n }\n if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) &&\n rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) {\n err = AVERROR_INVALIDDATA;\n goto fail;\n }\n if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && s->iformat &&\n CONFIG_RTPDEC)\n rtp_send_punch_packets(rtsp_st->rtp_handle);\n break;\n }\n case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: {\n char url[1024], namebuf[50];\n struct sockaddr_storage addr;\n int port, ttl;\n if (reply->transports[0].destination.ss_family) {\n addr = reply->transports[0].destination;\n port = reply->transports[0].port_min;\n ttl = reply->transports[0].ttl;\n } else {\n addr = rtsp_st->sdp_ip;\n port = rtsp_st->sdp_port;\n ttl = rtsp_st->sdp_ttl;\n }\n getnameinfo((struct sockaddr*) &addr, sizeof(addr),\n namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);\n ff_url_join(url, sizeof(url), "rtp", NULL, namebuf,\n port, "?ttl=%d", ttl);\n if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) {\n err = AVERROR_INVALIDDATA;\n goto fail;\n }\n break;\n }\n }\n if ((err = rtsp_open_transport_ctx(s, rtsp_st)))\n goto fail;\n }\n if (reply->timeout > 0)\n rt->timeout = reply->timeout;\n if (rt->server_type == RTSP_SERVER_REAL)\n rt->need_subscription = 1;\n return 0;\nfail:\n for (i = 0; i < rt->nb_rtsp_streams; i++) {\n if (rt->rtsp_streams[i]->rtp_handle) {\n url_close(rt->rtsp_streams[i]->rtp_handle);\n rt->rtsp_streams[i]->rtp_handle = NULL;\n }\n }\n return err;\n}', 'size_t av_strlcat(char *dst, const char *src, size_t size)\n{\n size_t len = strlen(dst);\n if (size <= len + 1)\n return len + strlen(src);\n return len + av_strlcpy(dst + len, src, size - len);\n}', 'size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...)\n{\n int len = strlen(dst);\n va_list vl;\n va_start(vl, fmt);\n len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl);\n va_end(vl);\n return len;\n}']
33,531
0
https://github.com/libav/libav/blob/e4e30256f87f177decf59b59e923d05ef64147df/avconv.c/#L4271
static int opt_vstats(const char *opt, const char *arg) { char filename[40]; time_t today2 = time(NULL); struct tm *today = localtime(&today2); snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min, today->tm_sec); return opt_vstats_file(opt, filename); }
['static int opt_vstats(const char *opt, const char *arg)\n{\n char filename[40];\n time_t today2 = time(NULL);\n struct tm *today = localtime(&today2);\n snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,\n today->tm_sec);\n return opt_vstats_file(opt, filename);\n}']
33,532
0
https://github.com/libav/libav/blob/7fa70598e83cca650717d02ac96bcf55e9f97c19/libavcodec/wavpack.c/#L213
static void update_error_limit(WavpackContext *ctx) { int i, br[2], sl[2]; for(i = 0; i <= ctx->stereo_in; i++){ ctx->ch[i].bitrate_acc += ctx->ch[i].bitrate_delta; br[i] = ctx->ch[i].bitrate_acc >> 16; sl[i] = LEVEL_DECAY(ctx->ch[i].slow_level); } if(ctx->stereo_in && ctx->hybrid_bitrate){ int balance = (sl[1] - sl[0] + br[1] + 1) >> 1; if(balance > br[0]){ br[1] = br[0] << 1; br[0] = 0; }else if(-balance > br[0]){ br[0] <<= 1; br[1] = 0; }else{ br[1] = br[0] + balance; br[0] = br[0] - balance; } } for(i = 0; i <= ctx->stereo_in; i++){ if(ctx->hybrid_bitrate){ if(sl[i] - br[i] > -0x100) ctx->ch[i].error_limit = wp_exp2(sl[i] - br[i] + 0x100); else ctx->ch[i].error_limit = 0; }else{ ctx->ch[i].error_limit = wp_exp2(br[i]); } } }
['static void update_error_limit(WavpackContext *ctx)\n{\n int i, br[2], sl[2];\n for(i = 0; i <= ctx->stereo_in; i++){\n ctx->ch[i].bitrate_acc += ctx->ch[i].bitrate_delta;\n br[i] = ctx->ch[i].bitrate_acc >> 16;\n sl[i] = LEVEL_DECAY(ctx->ch[i].slow_level);\n }\n if(ctx->stereo_in && ctx->hybrid_bitrate){\n int balance = (sl[1] - sl[0] + br[1] + 1) >> 1;\n if(balance > br[0]){\n br[1] = br[0] << 1;\n br[0] = 0;\n }else if(-balance > br[0]){\n br[0] <<= 1;\n br[1] = 0;\n }else{\n br[1] = br[0] + balance;\n br[0] = br[0] - balance;\n }\n }\n for(i = 0; i <= ctx->stereo_in; i++){\n if(ctx->hybrid_bitrate){\n if(sl[i] - br[i] > -0x100)\n ctx->ch[i].error_limit = wp_exp2(sl[i] - br[i] + 0x100);\n else\n ctx->ch[i].error_limit = 0;\n }else{\n ctx->ch[i].error_limit = wp_exp2(br[i]);\n }\n }\n}']
33,533
0
https://github.com/openssl/openssl/blob/98e665493818493e9a2bb4fce30127aca052f47a/crypto/lhash/lhash.c/#L278
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; 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; } } }
['int MAIN(int argc, char **argv)\n\t{\n\tENGINE *e = NULL;\n\tchar **args;\n\tchar *host = NULL, *port = NULL, *path = "/";\n\tchar *reqin = NULL, *respin = NULL;\n\tchar *reqout = NULL, *respout = NULL;\n\tchar *signfile = NULL, *keyfile = NULL;\n\tchar *rsignfile = NULL, *rkeyfile = NULL;\n\tchar *outfile = NULL;\n\tint add_nonce = 1, noverify = 0, use_ssl = -1;\n\tOCSP_REQUEST *req = NULL;\n\tOCSP_RESPONSE *resp = NULL;\n\tOCSP_BASICRESP *bs = NULL;\n\tX509 *issuer = NULL, *cert = NULL;\n\tX509 *signer = NULL, *rsigner = NULL;\n\tEVP_PKEY *key = NULL, *rkey = NULL;\n\tBIO *acbio = NULL, *cbio = NULL;\n\tBIO *derbio = NULL;\n\tBIO *out = NULL;\n\tint req_text = 0, resp_text = 0;\n\tlong nsec = MAX_VALIDITY_PERIOD, maxage = -1;\n\tchar *CAfile = NULL, *CApath = NULL;\n\tX509_STORE *store = NULL;\n\tSSL_CTX *ctx = NULL;\n\tSTACK_OF(X509) *sign_other = NULL, *verify_other = NULL, *rother = NULL;\n\tchar *sign_certfile = NULL, *verify_certfile = NULL, *rcertfile = NULL;\n\tunsigned long sign_flags = 0, verify_flags = 0, rflags = 0;\n\tint ret = 1;\n\tint accept_count = -1;\n\tint badarg = 0;\n\tint i;\n\tSTACK *reqnames = NULL;\n\tSTACK_OF(OCSP_CERTID) *ids = NULL;\n\tX509 *rca_cert = NULL;\n\tchar *ridx_filename = NULL;\n\tchar *rca_filename = NULL;\n\tTXT_DB *rdb = NULL;\n\tint nmin = 0, ndays = -1;\n\tif (bio_err == NULL) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);\n\tSSL_load_error_strings();\n\targs = argv + 1;\n\treqnames = sk_new_null();\n\tids = sk_OCSP_CERTID_new_null();\n\twhile (!badarg && *args && *args[0] == \'-\')\n\t\t{\n\t\tif (!strcmp(*args, "-out"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\toutfile = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-url"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tif (!OCSP_parse_url(*args, &host, &port, &path, &use_ssl))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err, "Error parsing URL\\n");\n\t\t\t\t\tbadarg = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-host"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\thost = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-port"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tport = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-noverify"))\n\t\t\tnoverify = 1;\n\t\telse if (!strcmp(*args, "-nonce"))\n\t\t\tadd_nonce = 2;\n\t\telse if (!strcmp(*args, "-no_nonce"))\n\t\t\tadd_nonce = 0;\n\t\telse if (!strcmp(*args, "-resp_no_certs"))\n\t\t\trflags |= OCSP_NOCERTS;\n\t\telse if (!strcmp(*args, "-resp_key_id"))\n\t\t\trflags |= OCSP_RESPID_KEY;\n\t\telse if (!strcmp(*args, "-no_certs"))\n\t\t\tsign_flags |= OCSP_NOCERTS;\n\t\telse if (!strcmp(*args, "-no_signature_verify"))\n\t\t\tverify_flags |= OCSP_NOSIGS;\n\t\telse if (!strcmp(*args, "-no_cert_verify"))\n\t\t\tverify_flags |= OCSP_NOVERIFY;\n\t\telse if (!strcmp(*args, "-no_chain"))\n\t\t\tverify_flags |= OCSP_NOCHAIN;\n\t\telse if (!strcmp(*args, "-no_cert_checks"))\n\t\t\tverify_flags |= OCSP_NOCHECKS;\n\t\telse if (!strcmp(*args, "-no_explicit"))\n\t\t\tverify_flags |= OCSP_NOEXPLICIT;\n\t\telse if (!strcmp(*args, "-trust_other"))\n\t\t\tverify_flags |= OCSP_TRUSTOTHER;\n\t\telse if (!strcmp(*args, "-no_intern"))\n\t\t\tverify_flags |= OCSP_NOINTERN;\n\t\telse if (!strcmp(*args, "-text"))\n\t\t\t{\n\t\t\treq_text = 1;\n\t\t\tresp_text = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-req_text"))\n\t\t\treq_text = 1;\n\t\telse if (!strcmp(*args, "-resp_text"))\n\t\t\tresp_text = 1;\n\t\telse if (!strcmp(*args, "-reqin"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\treqin = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-respin"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\trespin = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-signer"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tsignfile = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp (*args, "-VAfile"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tverify_certfile = *args;\n\t\t\t\tverify_flags |= OCSP_TRUSTOTHER;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-sign_other"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tsign_certfile = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-verify_other"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tverify_certfile = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp (*args, "-CAfile"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tCAfile = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp (*args, "-CApath"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tCApath = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp (*args, "-validity_period"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tnsec = atol(*args);\n\t\t\t\tif (nsec < 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"Illegal validity period %s\\n",\n\t\t\t\t\t\t*args);\n\t\t\t\t\tbadarg = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp (*args, "-status_age"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tmaxage = atol(*args);\n\t\t\t\tif (maxage < 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"Illegal validity age %s\\n",\n\t\t\t\t\t\t*args);\n\t\t\t\t\tbadarg = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\t else if (!strcmp(*args, "-signkey"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tkeyfile = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-reqout"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\treqout = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-respout"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\trespout = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\t else if (!strcmp(*args, "-path"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tpath = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-issuer"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tX509_free(issuer);\n\t\t\t\tissuer = load_cert(bio_err, *args, FORMAT_PEM,\n\t\t\t\t\tNULL, e, "issuer certificate");\n\t\t\t\tif(!issuer) goto end;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp (*args, "-cert"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tX509_free(cert);\n\t\t\t\tcert = load_cert(bio_err, *args, FORMAT_PEM,\n\t\t\t\t\tNULL, e, "certificate");\n\t\t\t\tif(!cert) goto end;\n\t\t\t\tif(!add_ocsp_cert(&req, cert, issuer, ids))\n\t\t\t\t\tgoto end;\n\t\t\t\tif(!sk_push(reqnames, *args))\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-serial"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tif(!add_ocsp_serial(&req, *args, issuer, ids))\n\t\t\t\t\tgoto end;\n\t\t\t\tif(!sk_push(reqnames, *args))\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-index"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tridx_filename = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-CA"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\trca_filename = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp (*args, "-nmin"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tnmin = atol(*args);\n\t\t\t\tif (nmin < 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"Illegal update period %s\\n",\n\t\t\t\t\t\t*args);\n\t\t\t\t\tbadarg = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (ndays == -1)\n\t\t\t\t\tndays = 0;\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp (*args, "-nrequest"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\taccept_count = atol(*args);\n\t\t\t\tif (accept_count < 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"Illegal accept count %s\\n",\n\t\t\t\t\t\t*args);\n\t\t\t\t\tbadarg = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp (*args, "-ndays"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\tndays = atol(*args);\n\t\t\t\tif (ndays < 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"Illegal update period %s\\n",\n\t\t\t\t\t\t*args);\n\t\t\t\t\tbadarg = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-rsigner"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\trsignfile = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-rkey"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\trkeyfile = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*args, "-rother"))\n\t\t\t{\n\t\t\tif (args[1])\n\t\t\t\t{\n\t\t\t\targs++;\n\t\t\t\trcertfile = *args;\n\t\t\t\t}\n\t\t\telse badarg = 1;\n\t\t\t}\n\t\telse badarg = 1;\n\t\targs++;\n\t\t}\n\tif (!req && !reqin && !respin && !(port && ridx_filename)) badarg = 1;\n\tif (badarg)\n\t\t{\n\t\tBIO_printf (bio_err, "OCSP utility\\n");\n\t\tBIO_printf (bio_err, "Usage ocsp [options]\\n");\n\t\tBIO_printf (bio_err, "where options are\\n");\n\t\tBIO_printf (bio_err, "-out file output filename\\n");\n\t\tBIO_printf (bio_err, "-issuer file issuer certificate\\n");\n\t\tBIO_printf (bio_err, "-cert file certificate to check\\n");\n\t\tBIO_printf (bio_err, "-serial n serial number to check\\n");\n\t\tBIO_printf (bio_err, "-signer file certificate to sign OCSP request with\\n");\n\t\tBIO_printf (bio_err, "-signkey file private key to sign OCSP request with\\n");\n\t\tBIO_printf (bio_err, "-sign_certs file additional certificates to include in signed request\\n");\n\t\tBIO_printf (bio_err, "-no_certs don\'t include any certificates in signed request\\n");\n\t\tBIO_printf (bio_err, "-req_text print text form of request\\n");\n\t\tBIO_printf (bio_err, "-resp_text print text form of response\\n");\n\t\tBIO_printf (bio_err, "-text print text form of request and response\\n");\n\t\tBIO_printf (bio_err, "-reqout file write DER encoded OCSP request to \\"file\\"\\n");\n\t\tBIO_printf (bio_err, "-respout file write DER encoded OCSP reponse to \\"file\\"\\n");\n\t\tBIO_printf (bio_err, "-reqin file read DER encoded OCSP request from \\"file\\"\\n");\n\t\tBIO_printf (bio_err, "-respin file read DER encoded OCSP reponse from \\"file\\"\\n");\n\t\tBIO_printf (bio_err, "-nonce add OCSP nonce to request\\n");\n\t\tBIO_printf (bio_err, "-no_nonce don\'t add OCSP nonce to request\\n");\n\t\tBIO_printf (bio_err, "-url URL OCSP responder URL\\n");\n\t\tBIO_printf (bio_err, "-host host:n send OCSP request to host on port n\\n");\n\t\tBIO_printf (bio_err, "-path path to use in OCSP request\\n");\n\t\tBIO_printf (bio_err, "-CApath dir trusted certificates directory\\n");\n\t\tBIO_printf (bio_err, "-CAfile file trusted certificates file\\n");\n\t\tBIO_printf (bio_err, "-VAfile file validator certificates file\\n");\n\t\tBIO_printf (bio_err, "-validity_period n maximum validity discrepancy in seconds\\n");\n\t\tBIO_printf (bio_err, "-status_age n maximum status age in seconds\\n");\n\t\tBIO_printf (bio_err, "-noverify don\'t verify response at all\\n");\n\t\tBIO_printf (bio_err, "-verify_certs file additional certificates to search for signer\\n");\n\t\tBIO_printf (bio_err, "-trust_other don\'t verify additional certificates\\n");\n\t\tBIO_printf (bio_err, "-no_intern don\'t search certificates contained in response for signer\\n");\n\t\tBIO_printf (bio_err, "-no_sig_verify don\'t check signature on response\\n");\n\t\tBIO_printf (bio_err, "-no_cert_verify don\'t check signing certificate\\n");\n\t\tBIO_printf (bio_err, "-no_chain don\'t chain verify response\\n");\n\t\tBIO_printf (bio_err, "-no_cert_checks don\'t do additional checks on signing certificate\\n");\n\t\tBIO_printf (bio_err, "-port num\t\t port to run responder on\\n");\n\t\tBIO_printf (bio_err, "-index file\t certificate status index file\\n");\n\t\tBIO_printf (bio_err, "-CA file\t\t CA certificate\\n");\n\t\tBIO_printf (bio_err, "-rsigner file\t responder certificate to sign requests with\\n");\n\t\tBIO_printf (bio_err, "-rkey file\t responder key to sign requests with\\n");\n\t\tBIO_printf (bio_err, "-rother file\t other certificates to include in response\\n");\n\t\tBIO_printf (bio_err, "-resp_no_certs don\'t include any certificates in response\\n");\n\t\tBIO_printf (bio_err, "-nmin n\t \t number of minutes before next update\\n");\n\t\tBIO_printf (bio_err, "-ndays n\t \t number of days before next update\\n");\n\t\tBIO_printf (bio_err, "-resp_key_id identify reponse by signing certificate key ID\\n");\n\t\tBIO_printf (bio_err, "-nrequest n number of requests to accept (default unlimited)\\n");\n\t\tgoto end;\n\t\t}\n\tif(outfile) out = BIO_new_file(outfile, "w");\n\telse out = BIO_new_fp(stdout, BIO_NOCLOSE);\n\tif(!out)\n\t\t{\n\t\tBIO_printf(bio_err, "Error opening output file\\n");\n\t\tgoto end;\n\t\t}\n\tif (!req && (add_nonce != 2)) add_nonce = 0;\n\tif (!req && reqin)\n\t\t{\n\t\tderbio = BIO_new_file(reqin, "rb");\n\t\tif (!derbio)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error Opening OCSP request file\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\treq = d2i_OCSP_REQUEST_bio(derbio, NULL);\n\t\tBIO_free(derbio);\n\t\tif(!req)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error reading OCSP request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (!req && port)\n\t\t{\n\t\tacbio = init_responder(port);\n\t\tif (!acbio)\n\t\t\tgoto end;\n\t\t}\n\tif (rsignfile && !rdb)\n\t\t{\n\t\tif (!rkeyfile) rkeyfile = rsignfile;\n\t\trsigner = load_cert(bio_err, rsignfile, FORMAT_PEM,\n\t\t\tNULL, e, "responder certificate");\n\t\tif (!rsigner)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error loading responder certificate\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\trca_cert = load_cert(bio_err, rca_filename, FORMAT_PEM,\n\t\t\tNULL, e, "CA certificate");\n\t\tif (rcertfile)\n\t\t\t{\n\t\t\trother = load_certs(bio_err, sign_certfile, FORMAT_PEM,\n\t\t\t\tNULL, e, "responder other certificates");\n\t\t\tif (!sign_other) goto end;\n\t\t\t}\n\t\trkey = load_key(bio_err, rkeyfile, FORMAT_PEM, NULL, NULL,\n\t\t\t"responder private key");\n\t\tif (!rkey)\n\t\t\tgoto end;\n\t\t}\n\tif(acbio)\n\t\tBIO_printf(bio_err, "Waiting for OCSP client connections...\\n");\n\tredo_accept:\n\tif (acbio)\n\t\t{\n\t\tif (!do_responder(&req, &cbio, acbio, port))\n\t\t\tgoto end;\n\t\tif (!req)\n\t\t\t{\n\t\t\tresp = OCSP_response_create(OCSP_RESPONSE_STATUS_MALFORMEDREQUEST, NULL);\n\t\t\tsend_ocsp_response(cbio, resp);\n\t\t\tgoto done_resp;\n\t\t\t}\n\t\t}\n\tif (!req && (signfile || reqout || host || add_nonce || ridx_filename))\n\t\t{\n\t\tBIO_printf(bio_err, "Need an OCSP request for this operation!\\n");\n\t\tgoto end;\n\t\t}\n\tif (req && add_nonce) OCSP_request_add1_nonce(req, NULL, -1);\n\tif (signfile)\n\t\t{\n\t\tif (!keyfile) keyfile = signfile;\n\t\tsigner = load_cert(bio_err, signfile, FORMAT_PEM,\n\t\t\tNULL, e, "signer certificate");\n\t\tif (!signer)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error loading signer certificate\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (sign_certfile)\n\t\t\t{\n\t\t\tsign_other = load_certs(bio_err, sign_certfile, FORMAT_PEM,\n\t\t\t\tNULL, e, "signer certificates");\n\t\t\tif (!sign_other) goto end;\n\t\t\t}\n\t\tkey = load_key(bio_err, keyfile, FORMAT_PEM, NULL, NULL,\n\t\t\t"signer private key");\n\t\tif (!key)\n\t\t\tgoto end;\n\t\tif (!OCSP_request_sign(req, signer, key, EVP_sha1(), sign_other, sign_flags))\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error signing OCSP request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (req_text && req) OCSP_REQUEST_print(out, req, 0);\n\tif (ridx_filename && (!rkey || !rsigner || !rca_cert))\n\t\t{\n\t\tBIO_printf(bio_err, "Need a responder certificate, key and CA for this operation!\\n");\n\t\tgoto end;\n\t\t}\n\tif (ridx_filename && !rdb)\n\t\t{\n\t\tBIO *db_bio = NULL;\n\t\tdb_bio = BIO_new_file(ridx_filename, "r");\n\t\tif (!db_bio)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error opening index file %s\\n", ridx_filename);\n\t\t\tgoto end;\n\t\t\t}\n\t\trdb = TXT_DB_read(db_bio, DB_NUMBER);\n\t\tBIO_free(db_bio);\n\t\tif (!rdb)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error reading index file %s\\n", ridx_filename);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!make_serial_index(rdb))\n\t\t\tgoto end;\n\t\t}\n\tif (rdb)\n\t\t{\n\t\ti = make_ocsp_response(&resp, req, rdb, rca_cert, rsigner, rkey, rother, rflags, nmin, ndays);\n\t\tif (cbio)\n\t\t\tsend_ocsp_response(cbio, resp);\n\t\t}\n\telse if (host)\n\t\t{\n\t\tcbio = BIO_new_connect(host);\n\t\tif (!cbio)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error creating connect BIO\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (port) BIO_set_conn_port(cbio, port);\n\t\tif (use_ssl == 1)\n\t\t\t{\n\t\t\tBIO *sbio;\n\t\t\tctx = SSL_CTX_new(SSLv23_client_method());\n\t\t\tSSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY);\n\t\t\tsbio = BIO_new_ssl(ctx, 1);\n\t\t\tcbio = BIO_push(sbio, cbio);\n\t\t\t}\n\t\tif (BIO_do_connect(cbio) <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error connecting BIO\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tresp = OCSP_sendreq_bio(cbio, path, req);\n\t\tBIO_free_all(cbio);\n\t\tcbio = NULL;\n\t\tif (!resp)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error querying OCSP responsder\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\telse if (respin)\n\t\t{\n\t\tderbio = BIO_new_file(respin, "rb");\n\t\tif (!derbio)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error Opening OCSP response file\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tresp = d2i_OCSP_RESPONSE_bio(derbio, NULL);\n\t\tBIO_free(derbio);\n\t\tif(!resp)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error reading OCSP response\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tret = 0;\n\t\tgoto end;\n\t\t}\n\tdone_resp:\n\tif (respout)\n\t\t{\n\t\tderbio = BIO_new_file(respout, "wb");\n\t\tif(!derbio)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error opening file %s\\n", respout);\n\t\t\tgoto end;\n\t\t\t}\n\t\ti2d_OCSP_RESPONSE_bio(derbio, resp);\n\t\tBIO_free(derbio);\n\t\t}\n\ti = OCSP_response_status(resp);\n\tif (i != OCSP_RESPONSE_STATUS_SUCCESSFUL)\n\t\t{\n\t\tBIO_printf(out, "Responder Error: %s (%ld)\\n",\n\t\t\t\tOCSP_response_status_str(i), i);\n\t\tret = 0;\n\t\tgoto end;\n\t\t}\n\tif (resp_text) OCSP_RESPONSE_print(out, resp, 0);\n\tif (cbio)\n\t\t{\n\t\tif (accept_count > 0)\n\t\t\taccept_count--;\n\t\tif (accept_count)\n\t\t\t{\n\t\t\tBIO_free_all(cbio);\n\t\t\tcbio = NULL;\n\t\t\tOCSP_REQUEST_free(req);\n\t\t\treq = NULL;\n\t\t\tOCSP_RESPONSE_free(resp);\n\t\t\tresp = NULL;\n\t\t\tgoto redo_accept;\n\t\t\t}\n\t\tgoto end;\n\t\t}\n\tif (!store)\n\t\tstore = setup_verify(bio_err, CAfile, CApath);\n\tif (verify_certfile)\n\t\t{\n\t\tverify_other = load_certs(bio_err, verify_certfile, FORMAT_PEM,\n\t\t\tNULL, e, "validator certificate");\n\t\tif (!verify_other) goto end;\n\t\t}\n\tbs = OCSP_response_get1_basic(resp);\n\tif (!bs)\n\t\t{\n\t\tBIO_printf(bio_err, "Error parsing response\\n");\n\t\tgoto end;\n\t\t}\n\tif (!noverify)\n\t\t{\n\t\tif (req && ((i = OCSP_check_nonce(req, bs)) <= 0))\n\t\t\t{\n\t\t\tif (i == -1)\n\t\t\t\tBIO_printf(bio_err, "WARNING: no nonce in response\\n");\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err, "Nonce Verify error\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\ti = OCSP_basic_verify(bs, verify_other, store, verify_flags);\n if (i < 0) i = OCSP_basic_verify(bs, NULL, store, 0);\n\t\tif(i <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Response Verify Failure\\n", i);\n\t\t\tERR_print_errors(bio_err);\n\t\t\t}\n\t\telse\n\t\t\tBIO_printf(bio_err, "Response verify OK\\n");\n\t\t}\n\tif (!print_ocsp_summary(out, bs, req, reqnames, ids, nsec, maxage))\n\t\tgoto end;\n\tret = 0;\nend:\n\tERR_print_errors(bio_err);\n\tX509_free(signer);\n\tX509_STORE_free(store);\n\tEVP_PKEY_free(key);\n\tEVP_PKEY_free(rkey);\n\tX509_free(issuer);\n\tX509_free(cert);\n\tX509_free(rsigner);\n\tX509_free(rca_cert);\n\tTXT_DB_free(rdb);\n\tBIO_free_all(cbio);\n\tBIO_free_all(acbio);\n\tBIO_free(out);\n\tOCSP_REQUEST_free(req);\n\tOCSP_RESPONSE_free(resp);\n\tOCSP_BASICRESP_free(bs);\n\tsk_free(reqnames);\n\tsk_OCSP_CERTID_free(ids);\n\tsk_X509_pop_free(sign_other, X509_free);\n\tsk_X509_pop_free(verify_other, X509_free);\n\tif (use_ssl != -1)\n\t\t{\n\t\tOPENSSL_free(host);\n\t\tOPENSSL_free(port);\n\t\tOPENSSL_free(path);\n\t\tSSL_CTX_free(ctx);\n\t\t}\n\tEXIT(ret);\n}', 'SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)\n\t{\n\tSSL_CTX *ret=NULL;\n\tif (meth == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);\n\t\treturn(NULL);\n\t\t}\n\tif (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);\n\t\tgoto err;\n\t\t}\n\tret=(SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));\n\tif (ret == NULL)\n\t\tgoto err;\n\tmemset(ret,0,sizeof(SSL_CTX));\n\tret->method=meth;\n\tret->cert_store=NULL;\n\tret->session_cache_mode=SSL_SESS_CACHE_SERVER;\n\tret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;\n\tret->session_cache_head=NULL;\n\tret->session_cache_tail=NULL;\n\tret->session_timeout=meth->get_timeout();\n\tret->new_session_cb=0;\n\tret->remove_session_cb=0;\n\tret->get_session_cb=0;\n\tret->generate_session_id=0;\n\tmemset((char *)&ret->stats,0,sizeof(ret->stats));\n\tret->references=1;\n\tret->quiet_shutdown=0;\n\tret->info_callback=0;\n\tret->app_verify_callback=0;\n\tret->app_verify_arg=NULL;\n\tret->max_cert_list=SSL_MAX_CERT_LIST_DEFAULT;\n\tret->read_ahead=0;\n\tret->msg_callback=0;\n\tret->msg_callback_arg=NULL;\n\tret->verify_mode=SSL_VERIFY_NONE;\n\tret->verify_depth=-1;\n\tret->sid_ctx_length=0;\n\tret->default_verify_callback=NULL;\n\tif ((ret->cert=ssl_cert_new()) == NULL)\n\t\tgoto err;\n\tret->default_passwd_callback=0;\n\tret->default_passwd_callback_userdata=NULL;\n\tret->client_cert_cb=0;\n\tret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash),\n\t\t\tLHASH_COMP_FN(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(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data);\n\tret->extra_certs=NULL;\n\tret->comp_methods=SSL_COMP_get_compression_methods();\n\treturn(ret);\nerr:\n\tSSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);\nerr2:\n\tif (ret != NULL) SSL_CTX_free(ret);\n\treturn(NULL);\n\t}', 'LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)\n\t{\n\tLHASH *ret;\n\tint i;\n\tif ((ret=(LHASH *)OPENSSL_malloc(sizeof(LHASH))) == NULL)\n\t\tgoto err0;\n\tif ((ret->b=(LHASH_NODE **)OPENSSL_malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)\n\t\tgoto err1;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->b[i]=NULL;\n\tret->comp=((c == NULL)?(LHASH_COMP_FN_TYPE)strcmp:c);\n\tret->hash=((h == NULL)?(LHASH_HASH_FN_TYPE)lh_strhash:h);\n\tret->num_nodes=MIN_NODES/2;\n\tret->num_alloc_nodes=MIN_NODES;\n\tret->p=0;\n\tret->pmax=MIN_NODES/2;\n\tret->up_load=UP_LOAD;\n\tret->down_load=DOWN_LOAD;\n\tret->num_items=0;\n\tret->num_expands=0;\n\tret->num_expand_reallocs=0;\n\tret->num_contracts=0;\n\tret->num_contract_reallocs=0;\n\tret->num_hash_calls=0;\n\tret->num_comp_calls=0;\n\tret->num_insert=0;\n\tret->num_replace=0;\n\tret->num_delete=0;\n\tret->num_no_delete=0;\n\tret->num_retrieve=0;\n\tret->num_retrieve_miss=0;\n\tret->num_hash_comps=0;\n\tret->error=0;\n\treturn(ret);\nerr1:\n\tOPENSSL_free(ret);\nerr0:\n\treturn(NULL);\n\t}', 'BIO *BIO_new_ssl(SSL_CTX *ctx, int client)\n\t{\n\tBIO *ret;\n\tSSL *ssl;\n\tif ((ret=BIO_new(BIO_f_ssl())) == NULL)\n\t\treturn(NULL);\n\tif ((ssl=SSL_new(ctx)) == NULL)\n\t\t{\n\t\tBIO_free(ret);\n\t\treturn(NULL);\n\t\t}\n\tif (client)\n\t\tSSL_set_connect_state(ssl);\n\telse\n\t\tSSL_set_accept_state(ssl);\n\tBIO_set_ssl(ret,ssl,BIO_CLOSE);\n\treturn(ret);\n\t}', 'void TXT_DB_free(TXT_DB *db)\n\t{\n\tint i,n;\n\tchar **p,*max;\n\tif(db == NULL)\n\t return;\n\tif (db->index != NULL)\n\t\t{\n\t\tfor (i=db->num_fields-1; i>=0; i--)\n\t\t\tif (db->index[i] != NULL) lh_free(db->index[i]);\n\t\tOPENSSL_free(db->index);\n\t\t}\n\tif (db->qual != NULL)\n\t\tOPENSSL_free(db->qual);\n\tif (db->data != NULL)\n\t\t{\n\t\tfor (i=sk_num(db->data)-1; i>=0; i--)\n\t\t\t{\n\t\t\tp=(char **)sk_value(db->data,i);\n\t\t\tmax=p[db->num_fields];\n\t\t\tif (max == NULL)\n\t\t\t\t{\n\t\t\t\tfor (n=0; n<db->num_fields; n++)\n\t\t\t\t\tif (p[n] != NULL) OPENSSL_free(p[n]);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tfor (n=0; n<db->num_fields; n++)\n\t\t\t\t\t{\n\t\t\t\t\tif (((p[n] < (char *)p) || (p[n] > max))\n\t\t\t\t\t\t&& (p[n] != NULL))\n\t\t\t\t\t\tOPENSSL_free(p[n]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tOPENSSL_free(sk_value(db->data,i));\n\t\t\t}\n\t\tsk_free(db->data);\n\t\t}\n\tOPENSSL_free(db);\n\t}', 'void SSL_CTX_free(SSL_CTX *a)\n\t{\n\tint i;\n\tif (a == NULL) return;\n\ti=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);\n#ifdef REF_PRINT\n\tREF_PRINT("SSL_CTX",a);\n#endif\n\tif (i > 0) return;\n#ifdef REF_CHECK\n\tif (i < 0)\n\t\t{\n\t\tfprintf(stderr,"SSL_CTX_free, bad reference count\\n");\n\t\tabort();\n\t\t}\n#endif\n\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n\tif (a->sessions != NULL)\n\t\t{\n\t\tSSL_CTX_flush_sessions(a,0);\n\t\tlh_free(a->sessions);\n\t\t}\n\tif (a->cert_store != NULL)\n\t\tX509_STORE_free(a->cert_store);\n\tif (a->cipher_list != NULL)\n\t\tsk_SSL_CIPHER_free(a->cipher_list);\n\tif (a->cipher_list_by_id != NULL)\n\t\tsk_SSL_CIPHER_free(a->cipher_list_by_id);\n\tif (a->cert != NULL)\n\t\tssl_cert_free(a->cert);\n\tif (a->client_CA != NULL)\n\t\tsk_X509_NAME_pop_free(a->client_CA,X509_NAME_free);\n\tif (a->extra_certs != NULL)\n\t\tsk_X509_pop_free(a->extra_certs,X509_free);\n#if 0\n\tif (a->comp_methods != NULL)\n\t\tsk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);\n#else\n\ta->comp_methods = NULL;\n#endif\n\tOPENSSL_free(a);\n\t}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n\t{\n\tunsigned long i;\n\tTIMEOUT_PARAM tp;\n\ttp.ctx=s;\n\ttp.cache=s->sessions;\n\tif (tp.cache == NULL) return;\n\ttp.time=t;\n\tCRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\ti=tp.cache->down_load;\n\ttp.cache->down_load=0;\n\tlh_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout), &tp);\n\ttp.cache->down_load=i;\n\tCRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t}', 'void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)\n\t{\n\tdoall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);\n\t}', 'static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,\n\t\t\t LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)\n\t{\n\tint i;\n\tLHASH_NODE *a,*n;\n\tfor (i=lh->num_nodes-1; i>=0; i--)\n\t\t{\n\t\ta=lh->b[i];\n\t\twhile (a != NULL)\n\t\t\t{\n\t\t\tn=a->next;\n\t\t\tif(use_arg)\n\t\t\t\tfunc_arg(a->data,arg);\n\t\t\telse\n\t\t\t\tfunc(a->data);\n\t\t\ta=n;\n\t\t\t}\n\t\t}\n\t}']
33,534
0
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/crypto/bn/bn_ctx.c/#L401
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while (num--) { bn_check_top(p->current->vals + offset); if (offset == 0) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['int 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}', '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 void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (offset == 0) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
33,535
0
https://github.com/libav/libav/blob/67ce33162aa93bee1a5f9e8d6f00060329fa67da/libavcodec/vp3.c/#L2151
static int vp3_decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { Vp3DecodeContext *s = avctx->priv_data; GetBitContext gb; static int counter = 0; int i; init_get_bits(&gb, buf, buf_size * 8); if (s->theora && get_bits1(&gb)) { av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n"); return -1; } s->keyframe = !get_bits1(&gb); if (!s->theora) skip_bits(&gb, 1); s->last_quality_index = s->quality_index; s->nqis=0; do{ s->qis[s->nqis++]= get_bits(&gb, 6); } while(s->theora >= 0x030200 && s->nqis<3 && get_bits1(&gb)); s->quality_index= s->qis[0]; if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n", s->keyframe?"key":"", counter, s->quality_index); counter++; if (s->quality_index != s->last_quality_index) { init_dequantizer(s); init_loop_filter(s); } if (s->keyframe) { if (!s->theora) { skip_bits(&gb, 4); skip_bits(&gb, 4); if (s->version) { s->version = get_bits(&gb, 5); if (counter == 1) av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\n", s->version); } } if (s->version || s->theora) { if (get_bits1(&gb)) av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n"); skip_bits(&gb, 2); } if (s->last_frame.data[0] == s->golden_frame.data[0]) { if (s->golden_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); s->last_frame= s->golden_frame; } else { if (s->golden_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); if (s->last_frame.data[0]) avctx->release_buffer(avctx, &s->last_frame); } s->golden_frame.reference = 3; if(avctx->get_buffer(avctx, &s->golden_frame) < 0) { av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } s->current_frame= s->golden_frame; if (!s->pixel_addresses_initialized) { if (!s->flipped_image) vp3_calculate_pixel_addresses(s); else theora_calculate_pixel_addresses(s); s->pixel_addresses_initialized = 1; } } else { s->current_frame.reference = 3; if (!s->pixel_addresses_initialized) { av_log(s->avctx, AV_LOG_ERROR, "vp3: first frame not a keyframe\n"); return -1; } if(avctx->get_buffer(avctx, &s->current_frame) < 0) { av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); return -1; } } s->current_frame.qscale_table= s->qscale_table; s->current_frame.qstride= 0; init_frame(s, &gb); #if KEYFRAMES_ONLY if (!s->keyframe) { memcpy(s->current_frame.data[0], s->golden_frame.data[0], s->current_frame.linesize[0] * s->height); memcpy(s->current_frame.data[1], s->golden_frame.data[1], s->current_frame.linesize[1] * s->height / 2); memcpy(s->current_frame.data[2], s->golden_frame.data[2], s->current_frame.linesize[2] * s->height / 2); } else { #endif if (unpack_superblocks(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n"); return -1; } if (unpack_modes(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n"); return -1; } if (unpack_vectors(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n"); return -1; } if (unpack_dct_coeffs(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n"); return -1; } reverse_dc_prediction(s, 0, s->fragment_width, s->fragment_height); if ((avctx->flags & CODEC_FLAG_GRAY) == 0) { reverse_dc_prediction(s, s->fragment_start[1], s->fragment_width / 2, s->fragment_height / 2); reverse_dc_prediction(s, s->fragment_start[2], s->fragment_width / 2, s->fragment_height / 2); } for (i = 0; i < s->macroblock_height; i++) render_slice(s, i); apply_loop_filter(s); #if KEYFRAMES_ONLY } #endif *data_size=sizeof(AVFrame); *(AVFrame*)data= s->current_frame; if ((s->last_frame.data[0]) && (s->last_frame.data[0] != s->golden_frame.data[0])) avctx->release_buffer(avctx, &s->last_frame); s->last_frame= s->current_frame; s->current_frame.data[0]= NULL; return buf_size; }
['static int vp3_decode_frame(AVCodecContext *avctx,\n void *data, int *data_size,\n const uint8_t *buf, int buf_size)\n{\n Vp3DecodeContext *s = avctx->priv_data;\n GetBitContext gb;\n static int counter = 0;\n int i;\n init_get_bits(&gb, buf, buf_size * 8);\n if (s->theora && get_bits1(&gb))\n {\n av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\\n");\n return -1;\n }\n s->keyframe = !get_bits1(&gb);\n if (!s->theora)\n skip_bits(&gb, 1);\n s->last_quality_index = s->quality_index;\n s->nqis=0;\n do{\n s->qis[s->nqis++]= get_bits(&gb, 6);\n } while(s->theora >= 0x030200 && s->nqis<3 && get_bits1(&gb));\n s->quality_index= s->qis[0];\n if (s->avctx->debug & FF_DEBUG_PICT_INFO)\n av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\\n",\n s->keyframe?"key":"", counter, s->quality_index);\n counter++;\n if (s->quality_index != s->last_quality_index) {\n init_dequantizer(s);\n init_loop_filter(s);\n }\n if (s->keyframe) {\n if (!s->theora)\n {\n skip_bits(&gb, 4);\n skip_bits(&gb, 4);\n if (s->version)\n {\n s->version = get_bits(&gb, 5);\n if (counter == 1)\n av_log(s->avctx, AV_LOG_DEBUG, "VP version: %d\\n", s->version);\n }\n }\n if (s->version || s->theora)\n {\n if (get_bits1(&gb))\n av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\\n");\n skip_bits(&gb, 2);\n }\n if (s->last_frame.data[0] == s->golden_frame.data[0]) {\n if (s->golden_frame.data[0])\n avctx->release_buffer(avctx, &s->golden_frame);\n s->last_frame= s->golden_frame;\n } else {\n if (s->golden_frame.data[0])\n avctx->release_buffer(avctx, &s->golden_frame);\n if (s->last_frame.data[0])\n avctx->release_buffer(avctx, &s->last_frame);\n }\n s->golden_frame.reference = 3;\n if(avctx->get_buffer(avctx, &s->golden_frame) < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\\n");\n return -1;\n }\n s->current_frame= s->golden_frame;\n if (!s->pixel_addresses_initialized)\n {\n if (!s->flipped_image)\n vp3_calculate_pixel_addresses(s);\n else\n theora_calculate_pixel_addresses(s);\n s->pixel_addresses_initialized = 1;\n }\n } else {\n s->current_frame.reference = 3;\n if (!s->pixel_addresses_initialized) {\n av_log(s->avctx, AV_LOG_ERROR, "vp3: first frame not a keyframe\\n");\n return -1;\n }\n if(avctx->get_buffer(avctx, &s->current_frame) < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\\n");\n return -1;\n }\n }\n s->current_frame.qscale_table= s->qscale_table;\n s->current_frame.qstride= 0;\n init_frame(s, &gb);\n#if KEYFRAMES_ONLY\nif (!s->keyframe) {\n memcpy(s->current_frame.data[0], s->golden_frame.data[0],\n s->current_frame.linesize[0] * s->height);\n memcpy(s->current_frame.data[1], s->golden_frame.data[1],\n s->current_frame.linesize[1] * s->height / 2);\n memcpy(s->current_frame.data[2], s->golden_frame.data[2],\n s->current_frame.linesize[2] * s->height / 2);\n} else {\n#endif\n if (unpack_superblocks(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\\n");\n return -1;\n }\n if (unpack_modes(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\\n");\n return -1;\n }\n if (unpack_vectors(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\\n");\n return -1;\n }\n if (unpack_dct_coeffs(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\\n");\n return -1;\n }\n reverse_dc_prediction(s, 0, s->fragment_width, s->fragment_height);\n if ((avctx->flags & CODEC_FLAG_GRAY) == 0) {\n reverse_dc_prediction(s, s->fragment_start[1],\n s->fragment_width / 2, s->fragment_height / 2);\n reverse_dc_prediction(s, s->fragment_start[2],\n s->fragment_width / 2, s->fragment_height / 2);\n }\n for (i = 0; i < s->macroblock_height; i++)\n render_slice(s, i);\n apply_loop_filter(s);\n#if KEYFRAMES_ONLY\n}\n#endif\n *data_size=sizeof(AVFrame);\n *(AVFrame*)data= s->current_frame;\n if ((s->last_frame.data[0]) &&\n (s->last_frame.data[0] != s->golden_frame.data[0]))\n avctx->release_buffer(avctx, &s->last_frame);\n s->last_frame= s->current_frame;\n s->current_frame.data[0]= NULL;\n return buf_size;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size= (bit_size+7)>>3;\n if(buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer= buffer;\n s->size_in_bits= bit_size;\n s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index=0;\n#elif defined LIBMPEG2_BITSTREAM_READER\n s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n s->bit_count = 16 + 8*((intptr_t)buffer&1);\n skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n s->bit_count = 32 + 8*((intptr_t)buffer&3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n int index= s->index;\n uint8_t result= s->buffer[ index>>3 ];\n#ifdef ALT_BITSTREAM_READER_LE\n result>>= (index&0x07);\n result&= 1;\n#else\n result<<= (index&0x07);\n result>>= 8 - 1;\n#endif\n index++;\n s->index= index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}']
33,536
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/asn1/asn1_lib.c/#L107
int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass, long omax) { int i,ret; long l; unsigned char *p= *pp; int tag,xclass,inf; long max=omax; if (!max) goto err; ret=(*p&V_ASN1_CONSTRUCTED); xclass=(*p&V_ASN1_PRIVATE); i= *p&V_ASN1_PRIMATIVE_TAG; if (i == V_ASN1_PRIMATIVE_TAG) { p++; if (--max == 0) goto err; l=0; while (*p&0x80) { l<<=7L; l|= *(p++)&0x7f; if (--max == 0) goto err; } l<<=7L; l|= *(p++)&0x7f; tag=(int)l; } else { tag=i; p++; if (--max == 0) goto err; } *ptag=tag; *pclass=xclass; if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; #if 0 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n", (int)p,*plength,omax,(int)*pp,(int)(p+ *plength), (int)(omax+ *pp)); #endif #if 0 if ((p+ *plength) > (omax+ *pp)) { ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); ret|=0x80; } #endif *pp=p; return(ret|inf); err: ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); return(0x80); }
['static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey)\n\t{\n\tint i,ok=0,bad=0;\n\ti=ssl_cert_type(NULL,pkey);\n\tif (i < 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_SET_PKEY,SSL_R_UNKNOWN_CERTIFICATE_TYPE);\n\t\treturn(0);\n\t\t}\n\tif (c->pkeys[i].x509 != NULL)\n\t\t{\n\t\tEVP_PKEY *pktmp;\n\t\tpktmp =\tX509_get_pubkey(c->pkeys[i].x509);\n\t\tEVP_PKEY_copy_parameters(pktmp,pkey);\n\t\tEVP_PKEY_free(pktmp);\n\t\tERR_clear_error();\n#ifndef NO_RSA\n\t\tif ((pkey->type == EVP_PKEY_RSA) &&\n\t\t\t(RSA_flags(pkey->pkey.rsa) &\n\t\t\t RSA_METHOD_FLAG_NO_CHECK))\n\t\t\t ok=1;\n\t\telse\n#endif\n\t\t\tif (!X509_check_private_key(c->pkeys[i].x509,pkey))\n\t\t\t{\n\t\t\tif ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA))\n\t\t\t\t{\n\t\t\t\ti=(i == SSL_PKEY_DH_RSA)?\n\t\t\t\t\tSSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA;\n\t\t\t\tif (c->pkeys[i].x509 == NULL)\n\t\t\t\t\tok=1;\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!X509_check_private_key(\n\t\t\t\t\t\tc->pkeys[i].x509,pkey))\n\t\t\t\t\t\tbad=1;\n\t\t\t\t\telse\n\t\t\t\t\t\tok=1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tbad=1;\n\t\t\t}\n\t\telse\n\t\t\tok=1;\n\t\t}\n\telse\n\t\tok=1;\n\tif (bad)\n\t\t{\n\t\tX509_free(c->pkeys[i].x509);\n\t\tc->pkeys[i].x509=NULL;\n\t\treturn(0);\n\t\t}\n\tif (c->pkeys[i].privatekey != NULL)\n\t\tEVP_PKEY_free(c->pkeys[i].privatekey);\n\tCRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);\n\tc->pkeys[i].privatekey=pkey;\n\tc->key= &(c->pkeys[i]);\n\tc->valid=0;\n\treturn(1);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tlong j;\n\tint type;\n\tunsigned char *p;\n#ifndef NO_DSA\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t {\n\t CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);\n\t return(key->pkey);\n\t }\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tp=key->public_key->data;\n j=key->public_key->length;\n if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);\n\t\tgoto err;\n\t\t}\n\tret->save_parameters=0;\n#ifndef NO_DSA\n\ta=key->algor;\n\tif (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter->type == V_ASN1_SEQUENCE)\n\t\t\t{\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tp=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n\tkey->pkey=ret;\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);\n\treturn(ret);\nerr:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)\n\t{\n\tint i=ERR_R_NESTED_ASN1_ERROR;\n\tASN1_INTEGER *bs=NULL;\n\tM_ASN1_D2I_vars(a,DSA *,DSA_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn;\n\tASN1_BIT_STRING_free(bs);\n\tM_ASN1_D2I_Finish_2(a);\nerr_bn:\n\ti=ERR_R_BN_LIB;\nerr:\n\tASN1err(ASN1_F_D2I_DSAPARAMS,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);\n\tif (bs != NULL) ASN1_BIT_STRING_free(bs);\n\treturn(NULL);\n\t}', 'ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,\n\t long length)\n\t{\n\tASN1_INTEGER *ret=NULL;\n\tunsigned char *p,*to,*s;\n\tlong len;\n\tint inf,tag,xclass;\n\tint i;\n\tif ((a == NULL) || ((*a) == NULL))\n\t\t{\n\t\tif ((ret=ASN1_INTEGER_new()) == NULL) return(NULL);\n\t\tret->type=V_ASN1_INTEGER;\n\t\t}\n\telse\n\t\tret=(*a);\n\tp= *pp;\n\tinf=ASN1_get_object(&p,&len,&tag,&xclass,length);\n\tif (inf & 0x80)\n\t\t{\n\t\ti=ASN1_R_BAD_OBJECT_HEADER;\n\t\tgoto err;\n\t\t}\n\tif (tag != V_ASN1_INTEGER)\n\t\t{\n\t\ti=ASN1_R_EXPECTING_AN_INTEGER;\n\t\tgoto err;\n\t\t}\n\ts=(unsigned char *)Malloc((int)len+1);\n\tif (s == NULL)\n\t\t{\n\t\ti=ERR_R_MALLOC_FAILURE;\n\t\tgoto err;\n\t\t}\n\tto=s;\n\tif (*p & 0x80)\n\t\t{\n\t\tret->type=V_ASN1_NEG_INTEGER;\n\t\tif (*p == 0xff)\n\t\t\t{\n\t\t\tp++;\n\t\t\tlen--;\n\t\t\t}\n\t\tfor (i=(int)len; i>0; i--)\n\t\t\t*(to++)= (*(p++)^0xFF)+1;\n\t\t}\n\telse\n\t\t{\n\t\tret->type=V_ASN1_INTEGER;\n\t\tif ((*p == 0) && (len != 1))\n\t\t\t{\n\t\t\tp++;\n\t\t\tlen--;\n\t\t\t}\n\t\tmemcpy(s,p,(int)len);\n\t\tp+=len;\n\t\t}\n\tif (ret->data != NULL) Free((char *)ret->data);\n\tret->data=s;\n\tret->length=(int)len;\n\tif (a != NULL) (*a)=ret;\n\t*pp=p;\n\treturn(ret);\nerr:\n\tASN1err(ASN1_F_D2I_ASN1_INTEGER,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret)))\n\t\tASN1_INTEGER_free(ret);\n\treturn(NULL);\n\t}', 'int X509_check_private_key(X509 *x, EVP_PKEY *k)\n\t{\n\tEVP_PKEY *xk=NULL;\n\tint ok=0;\n\txk=X509_get_pubkey(x);\n\tif (xk->type != k->type)\n\t {\n\t SSLerr(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);\n\t goto err;\n\t }\n\tswitch (k->type)\n\t\t{\n#ifndef NO_RSA\n\tcase EVP_PKEY_RSA:\n\t\tif (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0\n\t\t || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0)\n\t\t {\n\t\t SSLerr(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);\n\t\t goto err;\n\t\t }\n\t\tbreak;\n#endif\n#ifndef NO_DSA\n\tcase EVP_PKEY_DSA:\n\t\tif (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)\n\t\t {\n\t\t SSLerr(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);\n\t\t goto err;\n\t\t }\n\t\tbreak;\n#endif\n#ifndef NO_DH\n\tcase EVP_PKEY_DH:\n\t SSLerr(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);\n\t\tgoto err;\n#endif\n\tdefault:\n\t SSLerr(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);\n\t\tgoto err;\n\t\t}\n\tok=1;\nerr:\n\tEVP_PKEY_free(xk);\n\treturn(ok);\n\t}', 'int asn1_GetSequence(ASN1_CTX *c, long *length)\n\t{\n\tunsigned char *q;\n\tq=c->p;\n\tc->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),\n\t\t*length);\n\tif (c->inf & 0x80)\n\t\t{\n\t\tc->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;\n\t\treturn(0);\n\t\t}\n\tif (c->tag != V_ASN1_SEQUENCE)\n\t\t{\n\t\tc->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;\n\t\treturn(0);\n\t\t}\n\t(*length)-=(c->p-q);\n\tif (c->max && (*length < 0))\n\t\t{\n\t\tc->error=ERR_R_ASN1_LENGTH_MISMATCH;\n\t\treturn(0);\n\t\t}\n\tif (c->inf == (1|V_ASN1_CONSTRUCTED))\n\t\tc->slen= *length+ *(c->pp)-c->p;\n\tc->eos=0;\n\treturn(1);\n\t}', 'int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,\n\t long omax)\n\t{\n\tint i,ret;\n\tlong l;\n\tunsigned char *p= *pp;\n\tint tag,xclass,inf;\n\tlong max=omax;\n\tif (!max) goto err;\n\tret=(*p&V_ASN1_CONSTRUCTED);\n\txclass=(*p&V_ASN1_PRIVATE);\n\ti= *p&V_ASN1_PRIMATIVE_TAG;\n\tif (i == V_ASN1_PRIMATIVE_TAG)\n\t\t{\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\tl=0;\n\t\twhile (*p&0x80)\n\t\t\t{\n\t\t\tl<<=7L;\n\t\t\tl|= *(p++)&0x7f;\n\t\t\tif (--max == 0) goto err;\n\t\t\t}\n\t\tl<<=7L;\n\t\tl|= *(p++)&0x7f;\n\t\ttag=(int)l;\n\t\t}\n\telse\n\t\t{\n\t\ttag=i;\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\t}\n\t*ptag=tag;\n\t*pclass=xclass;\n\tif (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;\n#if 0\n\tfprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\\n",\n\t\t(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),\n\t\t(int)(omax+ *pp));\n#endif\n#if 0\n\tif ((p+ *plength) > (omax+ *pp))\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);\n\t\tret|=0x80;\n\t\t}\n#endif\n\t*pp=p;\n\treturn(ret|inf);\nerr:\n\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);\n\treturn(0x80);\n\t}']
33,537
0
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/crypto/bio/b_print.c/#L418
static void _dopr(char **sbuffer, char **buffer, size_t *maxlen, size_t *retlen, int *truncated, const char *format, va_list args) { char ch; LLONG value; LDOUBLE fvalue; char *strvalue; int min; int max; int state; int flags; int cflags; size_t currlen; state = DP_S_DEFAULT; flags = currlen = cflags = min = 0; max = -1; ch = *format++; while (state != DP_S_DONE) { if (ch == '\0' || (buffer == NULL && currlen >= *maxlen)) state = DP_S_DONE; switch (state) { case DP_S_DEFAULT: if (ch == '%') state = DP_S_FLAGS; else doapr_outch(sbuffer, buffer, &currlen, maxlen, ch); ch = *format++; break; case DP_S_FLAGS: switch (ch) { case '-': flags |= DP_F_MINUS; ch = *format++; break; case '+': flags |= DP_F_PLUS; ch = *format++; break; case ' ': flags |= DP_F_SPACE; ch = *format++; break; case '#': flags |= DP_F_NUM; ch = *format++; break; case '0': flags |= DP_F_ZERO; ch = *format++; break; default: state = DP_S_MIN; break; } break; case DP_S_MIN: if (isdigit((unsigned char)ch)) { min = 10 * min + char_to_int(ch); ch = *format++; } else if (ch == '*') { min = va_arg(args, int); ch = *format++; state = DP_S_DOT; } else state = DP_S_DOT; break; case DP_S_DOT: if (ch == '.') { state = DP_S_MAX; ch = *format++; } else state = DP_S_MOD; break; case DP_S_MAX: if (isdigit((unsigned char)ch)) { if (max < 0) max = 0; max = 10 * max + char_to_int(ch); ch = *format++; } else if (ch == '*') { max = va_arg(args, int); ch = *format++; state = DP_S_MOD; } else state = DP_S_MOD; break; case DP_S_MOD: switch (ch) { case 'h': cflags = DP_C_SHORT; ch = *format++; break; case 'l': if (*format == 'l') { cflags = DP_C_LLONG; format++; } else cflags = DP_C_LONG; ch = *format++; break; case 'q': cflags = DP_C_LLONG; ch = *format++; break; case 'L': cflags = DP_C_LDOUBLE; ch = *format++; break; default: break; } state = DP_S_CONV; break; case DP_S_CONV: switch (ch) { case 'd': case 'i': switch (cflags) { case DP_C_SHORT: value = (short int)va_arg(args, int); break; case DP_C_LONG: value = va_arg(args, long int); break; case DP_C_LLONG: value = va_arg(args, LLONG); break; default: value = va_arg(args, int); break; } fmtint(sbuffer, buffer, &currlen, maxlen, value, 10, min, max, flags); break; case 'X': flags |= DP_F_UP; case 'x': case 'o': case 'u': flags |= DP_F_UNSIGNED; switch (cflags) { case DP_C_SHORT: value = (unsigned short int)va_arg(args, unsigned int); break; case DP_C_LONG: value = (LLONG) va_arg(args, unsigned long int); break; case DP_C_LLONG: value = va_arg(args, unsigned LLONG); break; default: value = (LLONG) va_arg(args, unsigned int); break; } fmtint(sbuffer, buffer, &currlen, maxlen, value, ch == 'o' ? 8 : (ch == 'u' ? 10 : 16), min, max, flags); break; case 'f': if (cflags == DP_C_LDOUBLE) fvalue = va_arg(args, LDOUBLE); else fvalue = va_arg(args, double); fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max, flags); break; case 'E': flags |= DP_F_UP; case 'e': if (cflags == DP_C_LDOUBLE) fvalue = va_arg(args, LDOUBLE); else fvalue = va_arg(args, double); break; case 'G': flags |= DP_F_UP; case 'g': if (cflags == DP_C_LDOUBLE) fvalue = va_arg(args, LDOUBLE); else fvalue = va_arg(args, double); break; case 'c': doapr_outch(sbuffer, buffer, &currlen, maxlen, va_arg(args, int)); break; case 's': strvalue = va_arg(args, char *); if (max < 0) { if (buffer) max = INT_MAX; else max = *maxlen; } fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue, flags, min, max); break; case 'p': value = (long)va_arg(args, void *); fmtint(sbuffer, buffer, &currlen, maxlen, value, 16, min, max, flags | DP_F_NUM); break; case 'n': if (cflags == DP_C_SHORT) { short int *num; num = va_arg(args, short int *); *num = currlen; } else if (cflags == DP_C_LONG) { long int *num; num = va_arg(args, long int *); *num = (long int)currlen; } else if (cflags == DP_C_LLONG) { LLONG *num; num = va_arg(args, LLONG *); *num = (LLONG) currlen; } else { int *num; num = va_arg(args, int *); *num = currlen; } break; case '%': doapr_outch(sbuffer, buffer, &currlen, maxlen, ch); break; case 'w': ch = *format++; break; default: break; } ch = *format++; state = DP_S_DEFAULT; flags = cflags = min = 0; max = -1; break; case DP_S_DONE: break; default: break; } } *truncated = (currlen > *maxlen - 1); if (*truncated) currlen = *maxlen - 1; doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0'); *retlen = currlen - 1; return; }
["char *BN_bn2dec(const BIGNUM *a)\n{\n int i = 0, num, ok = 0;\n char *buf = NULL;\n char *p;\n BIGNUM *t = NULL;\n BN_ULONG *bn_data = NULL, *lp;\n i = BN_num_bits(a) * 3;\n num = (i / 10 + i / 1000 + 1) + 1;\n bn_data = OPENSSL_malloc((num / BN_DEC_NUM + 1) * sizeof(BN_ULONG));\n buf = OPENSSL_malloc(num + 3);\n if ((buf == NULL) || (bn_data == NULL)) {\n BNerr(BN_F_BN_BN2DEC, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if ((t = BN_dup(a)) == NULL)\n goto err;\n#define BUF_REMAIN (num+3 - (size_t)(p - buf))\n p = buf;\n lp = bn_data;\n if (BN_is_zero(t)) {\n *(p++) = '0';\n *(p++) = '\\0';\n } else {\n if (BN_is_negative(t))\n *p++ = '-';\n i = 0;\n while (!BN_is_zero(t)) {\n *lp = BN_div_word(t, BN_DEC_CONV);\n lp++;\n }\n lp--;\n BIO_snprintf(p, BUF_REMAIN, BN_DEC_FMT1, *lp);\n while (*p)\n p++;\n while (lp != bn_data) {\n lp--;\n BIO_snprintf(p, BUF_REMAIN, BN_DEC_FMT2, *lp);\n while (*p)\n p++;\n }\n }\n ok = 1;\n err:\n OPENSSL_free(bn_data);\n BN_free(t);\n if (ok)\n return buf;\n OPENSSL_free(buf);\n return NULL;\n}", 'void *CRYPTO_malloc(int num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n if (allow_customize)\n allow_customize = 0;\n if (malloc_debug_func != NULL) {\n if (allow_customize_debug)\n allow_customize_debug = 0;\n malloc_debug_func(NULL, num, file, line, 0);\n }\n ret = malloc_ex_func(num, file, line);\n#ifdef LEVITTE_DEBUG_MEM\n fprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n if (malloc_debug_func != NULL)\n malloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'int BIO_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 _dopr(&buf, NULL, &n, &retlen, &truncated, format, args);\n if (truncated)\n return -1;\n else\n return (retlen <= INT_MAX) ? (int)retlen : -1;\n}', "static void\n_dopr(char **sbuffer,\n char **buffer,\n size_t *maxlen,\n size_t *retlen, int *truncated, const char *format, va_list args)\n{\n char ch;\n LLONG value;\n LDOUBLE fvalue;\n char *strvalue;\n int min;\n int max;\n int state;\n int flags;\n int cflags;\n size_t currlen;\n state = DP_S_DEFAULT;\n flags = currlen = cflags = min = 0;\n max = -1;\n ch = *format++;\n while (state != DP_S_DONE) {\n if (ch == '\\0' || (buffer == NULL && currlen >= *maxlen))\n state = DP_S_DONE;\n switch (state) {\n case DP_S_DEFAULT:\n if (ch == '%')\n state = DP_S_FLAGS;\n else\n doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);\n ch = *format++;\n break;\n case DP_S_FLAGS:\n switch (ch) {\n case '-':\n flags |= DP_F_MINUS;\n ch = *format++;\n break;\n case '+':\n flags |= DP_F_PLUS;\n ch = *format++;\n break;\n case ' ':\n flags |= DP_F_SPACE;\n ch = *format++;\n break;\n case '#':\n flags |= DP_F_NUM;\n ch = *format++;\n break;\n case '0':\n flags |= DP_F_ZERO;\n ch = *format++;\n break;\n default:\n state = DP_S_MIN;\n break;\n }\n break;\n case DP_S_MIN:\n if (isdigit((unsigned char)ch)) {\n min = 10 * min + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n min = va_arg(args, int);\n ch = *format++;\n state = DP_S_DOT;\n } else\n state = DP_S_DOT;\n break;\n case DP_S_DOT:\n if (ch == '.') {\n state = DP_S_MAX;\n ch = *format++;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MAX:\n if (isdigit((unsigned char)ch)) {\n if (max < 0)\n max = 0;\n max = 10 * max + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n max = va_arg(args, int);\n ch = *format++;\n state = DP_S_MOD;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MOD:\n switch (ch) {\n case 'h':\n cflags = DP_C_SHORT;\n ch = *format++;\n break;\n case 'l':\n if (*format == 'l') {\n cflags = DP_C_LLONG;\n format++;\n } else\n cflags = DP_C_LONG;\n ch = *format++;\n break;\n case 'q':\n cflags = DP_C_LLONG;\n ch = *format++;\n break;\n case 'L':\n cflags = DP_C_LDOUBLE;\n ch = *format++;\n break;\n default:\n break;\n }\n state = DP_S_CONV;\n break;\n case DP_S_CONV:\n switch (ch) {\n case 'd':\n case 'i':\n switch (cflags) {\n case DP_C_SHORT:\n value = (short int)va_arg(args, int);\n break;\n case DP_C_LONG:\n value = va_arg(args, long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, LLONG);\n break;\n default:\n value = va_arg(args, int);\n break;\n }\n fmtint(sbuffer, buffer, &currlen, maxlen,\n value, 10, min, max, flags);\n break;\n case 'X':\n flags |= DP_F_UP;\n case 'x':\n case 'o':\n case 'u':\n flags |= DP_F_UNSIGNED;\n switch (cflags) {\n case DP_C_SHORT:\n value = (unsigned short int)va_arg(args, unsigned int);\n break;\n case DP_C_LONG:\n value = (LLONG) va_arg(args, unsigned long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, unsigned LLONG);\n break;\n default:\n value = (LLONG) va_arg(args, unsigned int);\n break;\n }\n fmtint(sbuffer, buffer, &currlen, maxlen, value,\n ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),\n min, max, flags);\n break;\n case 'f':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n fmtfp(sbuffer, buffer, &currlen, maxlen,\n fvalue, min, max, flags);\n break;\n case 'E':\n flags |= DP_F_UP;\n case 'e':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n break;\n case 'G':\n flags |= DP_F_UP;\n case 'g':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n break;\n case 'c':\n doapr_outch(sbuffer, buffer, &currlen, maxlen,\n va_arg(args, int));\n break;\n case 's':\n strvalue = va_arg(args, char *);\n if (max < 0) {\n if (buffer)\n max = INT_MAX;\n else\n max = *maxlen;\n }\n fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,\n flags, min, max);\n break;\n case 'p':\n value = (long)va_arg(args, void *);\n fmtint(sbuffer, buffer, &currlen, maxlen,\n value, 16, min, max, flags | DP_F_NUM);\n break;\n case 'n':\n if (cflags == DP_C_SHORT) {\n short int *num;\n num = va_arg(args, short int *);\n *num = currlen;\n } else if (cflags == DP_C_LONG) {\n long int *num;\n num = va_arg(args, long int *);\n *num = (long int)currlen;\n } else if (cflags == DP_C_LLONG) {\n LLONG *num;\n num = va_arg(args, LLONG *);\n *num = (LLONG) currlen;\n } else {\n int *num;\n num = va_arg(args, int *);\n *num = currlen;\n }\n break;\n case '%':\n doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);\n break;\n case 'w':\n ch = *format++;\n break;\n default:\n break;\n }\n ch = *format++;\n state = DP_S_DEFAULT;\n flags = cflags = min = 0;\n max = -1;\n break;\n case DP_S_DONE:\n break;\n default:\n break;\n }\n }\n *truncated = (currlen > *maxlen - 1);\n if (*truncated)\n currlen = *maxlen - 1;\n doapr_outch(sbuffer, buffer, &currlen, maxlen, '\\0');\n *retlen = currlen - 1;\n return;\n}"]
33,538
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/vc1.c/#L674
static void vc1_mc_4mv_chroma(VC1Context *v) { MpegEncContext *s = &v->s; DSPContext *dsp = &v->s.dsp; uint8_t *srcU, *srcV; int uvdxy, uvmx, uvmy, uvsrc_x, uvsrc_y; int i, idx, tx = 0, ty = 0; int mvx[4], mvy[4], intra[4]; static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4}; if(!v->s.last_picture.data[0])return; if(s->flags & CODEC_FLAG_GRAY) return; for(i = 0; i < 4; i++) { mvx[i] = s->mv[0][i][0]; mvy[i] = s->mv[0][i][1]; intra[i] = v->mb_type[0][s->block_index[i]]; } idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0]; if(!idx) { tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]); ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]); } else if(count[idx] == 1) { switch(idx) { case 0x1: tx = mid_pred(mvx[1], mvx[2], mvx[3]); ty = mid_pred(mvy[1], mvy[2], mvy[3]); break; case 0x2: tx = mid_pred(mvx[0], mvx[2], mvx[3]); ty = mid_pred(mvy[0], mvy[2], mvy[3]); break; case 0x4: tx = mid_pred(mvx[0], mvx[1], mvx[3]); ty = mid_pred(mvy[0], mvy[1], mvy[3]); break; case 0x8: tx = mid_pred(mvx[0], mvx[1], mvx[2]); ty = mid_pred(mvy[0], mvy[1], mvy[2]); break; } } else if(count[idx] == 2) { int t1 = 0, t2 = 0; for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;} for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;} tx = (mvx[t1] + mvx[t2]) / 2; ty = (mvy[t1] + mvy[t2]) / 2; } else { s->current_picture.motion_val[1][s->block_index[0]][0] = 0; s->current_picture.motion_val[1][s->block_index[0]][1] = 0; return; } s->current_picture.motion_val[1][s->block_index[0]][0] = tx; s->current_picture.motion_val[1][s->block_index[0]][1] = ty; uvmx = (tx + ((tx&3) == 3)) >> 1; uvmy = (ty + ((ty&3) == 3)) >> 1; if(v->fastuvmc) { uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1)); uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1)); } uvsrc_x = s->mb_x * 8 + (uvmx >> 2); uvsrc_y = s->mb_y * 8 + (uvmy >> 2); if(v->profile != PROFILE_ADVANCED){ uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8); uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8); }else{ uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1); uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1); } srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x; srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x; if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP) || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9 || (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){ ff_emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1, uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); ff_emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1, uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); srcU = s->edge_emu_buffer; srcV = s->edge_emu_buffer + 16; if(v->rangeredfrm) { int i, j; uint8_t *src, *src2; src = srcU; src2 = srcV; for(j = 0; j < 9; j++) { for(i = 0; i < 9; i++) { src[i] = ((src[i] - 128) >> 1) + 128; src2[i] = ((src2[i] - 128) >> 1) + 128; } src += s->uvlinesize; src2 += s->uvlinesize; } } if(v->mv_mode == MV_PMODE_INTENSITY_COMP) { int i, j; uint8_t *src, *src2; src = srcU; src2 = srcV; for(j = 0; j < 9; j++) { for(i = 0; i < 9; i++) { src[i] = v->lutuv[src[i]]; src2[i] = v->lutuv[src2[i]]; } src += s->uvlinesize; src2 += s->uvlinesize; } } } uvdxy = ((uvmy & 3) << 2) | (uvmx & 3); uvmx = (uvmx&3)<<1; uvmy = (uvmy&3)<<1; if(!v->rnd){ dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy); dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy); }else{ dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy); dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy); } }
['static void vc1_mc_4mv_chroma(VC1Context *v)\n{\n MpegEncContext *s = &v->s;\n DSPContext *dsp = &v->s.dsp;\n uint8_t *srcU, *srcV;\n int uvdxy, uvmx, uvmy, uvsrc_x, uvsrc_y;\n int i, idx, tx = 0, ty = 0;\n int mvx[4], mvy[4], intra[4];\n static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};\n if(!v->s.last_picture.data[0])return;\n if(s->flags & CODEC_FLAG_GRAY) return;\n for(i = 0; i < 4; i++) {\n mvx[i] = s->mv[0][i][0];\n mvy[i] = s->mv[0][i][1];\n intra[i] = v->mb_type[0][s->block_index[i]];\n }\n idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0];\n if(!idx) {\n tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);\n ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);\n } else if(count[idx] == 1) {\n switch(idx) {\n case 0x1:\n tx = mid_pred(mvx[1], mvx[2], mvx[3]);\n ty = mid_pred(mvy[1], mvy[2], mvy[3]);\n break;\n case 0x2:\n tx = mid_pred(mvx[0], mvx[2], mvx[3]);\n ty = mid_pred(mvy[0], mvy[2], mvy[3]);\n break;\n case 0x4:\n tx = mid_pred(mvx[0], mvx[1], mvx[3]);\n ty = mid_pred(mvy[0], mvy[1], mvy[3]);\n break;\n case 0x8:\n tx = mid_pred(mvx[0], mvx[1], mvx[2]);\n ty = mid_pred(mvy[0], mvy[1], mvy[2]);\n break;\n }\n } else if(count[idx] == 2) {\n int t1 = 0, t2 = 0;\n for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;}\n for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;}\n tx = (mvx[t1] + mvx[t2]) / 2;\n ty = (mvy[t1] + mvy[t2]) / 2;\n } else {\n s->current_picture.motion_val[1][s->block_index[0]][0] = 0;\n s->current_picture.motion_val[1][s->block_index[0]][1] = 0;\n return;\n }\n s->current_picture.motion_val[1][s->block_index[0]][0] = tx;\n s->current_picture.motion_val[1][s->block_index[0]][1] = ty;\n uvmx = (tx + ((tx&3) == 3)) >> 1;\n uvmy = (ty + ((ty&3) == 3)) >> 1;\n if(v->fastuvmc) {\n uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));\n uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));\n }\n uvsrc_x = s->mb_x * 8 + (uvmx >> 2);\n uvsrc_y = s->mb_y * 8 + (uvmy >> 2);\n if(v->profile != PROFILE_ADVANCED){\n uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);\n uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);\n }else{\n uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);\n uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);\n }\n srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;\n srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;\n if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)\n || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9\n || (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){\n ff_emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1,\n uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);\n ff_emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1,\n uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);\n srcU = s->edge_emu_buffer;\n srcV = s->edge_emu_buffer + 16;\n if(v->rangeredfrm) {\n int i, j;\n uint8_t *src, *src2;\n src = srcU; src2 = srcV;\n for(j = 0; j < 9; j++) {\n for(i = 0; i < 9; i++) {\n src[i] = ((src[i] - 128) >> 1) + 128;\n src2[i] = ((src2[i] - 128) >> 1) + 128;\n }\n src += s->uvlinesize;\n src2 += s->uvlinesize;\n }\n }\n if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {\n int i, j;\n uint8_t *src, *src2;\n src = srcU; src2 = srcV;\n for(j = 0; j < 9; j++) {\n for(i = 0; i < 9; i++) {\n src[i] = v->lutuv[src[i]];\n src2[i] = v->lutuv[src2[i]];\n }\n src += s->uvlinesize;\n src2 += s->uvlinesize;\n }\n }\n }\n uvdxy = ((uvmy & 3) << 2) | (uvmx & 3);\n uvmx = (uvmx&3)<<1;\n uvmy = (uvmy&3)<<1;\n if(!v->rnd){\n dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);\n dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);\n }else{\n dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);\n dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);\n }\n}']
33,539
0
https://github.com/nginx/nginx/blob/1c906828aee64d8ac7eb4df57f9134e27e709a3d/src/core/ngx_string.c/#L938
ngx_int_t ngx_atoi(u_char *line, size_t n) { ngx_int_t value, cutoff, cutlim; if (n == 0) { return NGX_ERROR; } cutoff = NGX_MAX_INT_T_VALUE / 10; cutlim = NGX_MAX_INT_T_VALUE % 10; for (value = 0; n--; line++) { if (*line < '0' || *line > '9') { return NGX_ERROR; } if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) { return NGX_ERROR; } value = value * 10 + (*line - '0'); } return value; }
['static char *\nngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n ngx_http_uwsgi_loc_conf_t *uwcf = conf;\n size_t add;\n ngx_url_t u;\n ngx_str_t *value, *url;\n ngx_uint_t n;\n ngx_http_core_loc_conf_t *clcf;\n ngx_http_script_compile_t sc;\n if (uwcf->upstream.upstream || uwcf->uwsgi_lengths) {\n return "is duplicate";\n }\n clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);\n clcf->handler = ngx_http_uwsgi_handler;\n value = cf->args->elts;\n url = &value[1];\n n = ngx_http_script_variables_count(url);\n if (n) {\n ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));\n sc.cf = cf;\n sc.source = url;\n sc.lengths = &uwcf->uwsgi_lengths;\n sc.values = &uwcf->uwsgi_values;\n sc.variables = n;\n sc.complete_lengths = 1;\n sc.complete_values = 1;\n if (ngx_http_script_compile(&sc) != NGX_OK) {\n return NGX_CONF_ERROR;\n }\n#if (NGX_HTTP_SSL)\n uwcf->ssl = 1;\n#endif\n return NGX_CONF_OK;\n }\n if (ngx_strncasecmp(url->data, (u_char *) "uwsgi://", 8) == 0) {\n add = 8;\n } else if (ngx_strncasecmp(url->data, (u_char *) "suwsgi://", 9) == 0) {\n#if (NGX_HTTP_SSL)\n add = 9;\n uwcf->ssl = 1;\n#else\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "suwsgi protocol requires SSL support");\n return NGX_CONF_ERROR;\n#endif\n } else {\n add = 0;\n }\n ngx_memzero(&u, sizeof(ngx_url_t));\n u.url.len = url->len - add;\n u.url.data = url->data + add;\n u.no_resolve = 1;\n uwcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);\n if (uwcf->upstream.upstream == NULL) {\n return NGX_CONF_ERROR;\n }\n if (clcf->name.len && clcf->name.data[clcf->name.len - 1] == \'/\') {\n clcf->auto_redirect = 1;\n }\n return NGX_CONF_OK;\n}', 'ngx_http_upstream_srv_conf_t *\nngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)\n{\n ngx_uint_t i;\n ngx_http_upstream_server_t *us;\n ngx_http_upstream_srv_conf_t *uscf, **uscfp;\n ngx_http_upstream_main_conf_t *umcf;\n if (!(flags & NGX_HTTP_UPSTREAM_CREATE)) {\n if (ngx_parse_url(cf->pool, u) != NGX_OK) {\n if (u->err) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "%s in upstream \\"%V\\"", u->err, &u->url);\n }\n return NULL;\n }\n }\n umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module);\n uscfp = umcf->upstreams.elts;\n for (i = 0; i < umcf->upstreams.nelts; i++) {\n if (uscfp[i]->host.len != u->host.len\n || ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len)\n != 0)\n {\n continue;\n }\n if ((flags & NGX_HTTP_UPSTREAM_CREATE)\n && (uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE))\n {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "duplicate upstream \\"%V\\"", &u->host);\n return NULL;\n }\n if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && !u->no_port) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "upstream \\"%V\\" may not have port %d",\n &u->host, u->port);\n return NULL;\n }\n if ((flags & NGX_HTTP_UPSTREAM_CREATE) && !uscfp[i]->no_port) {\n ngx_log_error(NGX_LOG_EMERG, cf->log, 0,\n "upstream \\"%V\\" may not have port %d in %s:%ui",\n &u->host, uscfp[i]->port,\n uscfp[i]->file_name, uscfp[i]->line);\n return NULL;\n }\n if (uscfp[i]->port && u->port\n && uscfp[i]->port != u->port)\n {\n continue;\n }\n if (flags & NGX_HTTP_UPSTREAM_CREATE) {\n uscfp[i]->flags = flags;\n uscfp[i]->port = 0;\n }\n return uscfp[i];\n }\n uscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_srv_conf_t));\n if (uscf == NULL) {\n return NULL;\n }\n uscf->flags = flags;\n uscf->host = u->host;\n uscf->file_name = cf->conf_file->file.name.data;\n uscf->line = cf->conf_file->line;\n uscf->port = u->port;\n uscf->no_port = u->no_port;\n if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) {\n uscf->servers = ngx_array_create(cf->pool, 1,\n sizeof(ngx_http_upstream_server_t));\n if (uscf->servers == NULL) {\n return NULL;\n }\n us = ngx_array_push(uscf->servers);\n if (us == NULL) {\n return NULL;\n }\n ngx_memzero(us, sizeof(ngx_http_upstream_server_t));\n us->addrs = u->addrs;\n us->naddrs = 1;\n }\n uscfp = ngx_array_push(&umcf->upstreams);\n if (uscfp == NULL) {\n return NULL;\n }\n *uscfp = uscf;\n return uscf;\n}', 'ngx_int_t\nngx_parse_url(ngx_pool_t *pool, ngx_url_t *u)\n{\n u_char *p;\n size_t len;\n p = u->url.data;\n len = u->url.len;\n if (len >= 5 && ngx_strncasecmp(p, (u_char *) "unix:", 5) == 0) {\n return ngx_parse_unix_domain_url(pool, u);\n }\n if (len && p[0] == \'[\') {\n return ngx_parse_inet6_url(pool, u);\n }\n return ngx_parse_inet_url(pool, u);\n}', 'static ngx_int_t\nngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u)\n{\n u_char *host, *port, *last, *uri, *args, *dash;\n size_t len;\n ngx_int_t n;\n struct sockaddr_in *sin;\n u->socklen = sizeof(struct sockaddr_in);\n sin = (struct sockaddr_in *) &u->sockaddr;\n sin->sin_family = AF_INET;\n u->family = AF_INET;\n host = u->url.data;\n last = host + u->url.len;\n port = ngx_strlchr(host, last, \':\');\n uri = ngx_strlchr(host, last, \'/\');\n args = ngx_strlchr(host, last, \'?\');\n if (args) {\n if (uri == NULL || args < uri) {\n uri = args;\n }\n }\n if (uri) {\n if (u->listen || !u->uri_part) {\n u->err = "invalid host";\n return NGX_ERROR;\n }\n u->uri.len = last - uri;\n u->uri.data = uri;\n last = uri;\n if (uri < port) {\n port = NULL;\n }\n }\n if (port) {\n port++;\n len = last - port;\n if (u->listen) {\n dash = ngx_strlchr(port, last, \'-\');\n if (dash) {\n dash++;\n n = ngx_atoi(dash, last - dash);\n if (n < 1 || n > 65535) {\n u->err = "invalid port";\n return NGX_ERROR;\n }\n u->last_port = (in_port_t) n;\n len = dash - port - 1;\n }\n }\n n = ngx_atoi(port, len);\n if (n < 1 || n > 65535) {\n u->err = "invalid port";\n return NGX_ERROR;\n }\n if (u->last_port && n > u->last_port) {\n u->err = "invalid port range";\n return NGX_ERROR;\n }\n u->port = (in_port_t) n;\n sin->sin_port = htons((in_port_t) n);\n u->port_text.len = last - port;\n u->port_text.data = port;\n last = port - 1;\n } else {\n if (uri == NULL) {\n if (u->listen) {\n len = last - host;\n dash = ngx_strlchr(host, last, \'-\');\n if (dash) {\n dash++;\n n = ngx_atoi(dash, last - dash);\n if (n == NGX_ERROR) {\n goto no_port;\n }\n if (n < 1 || n > 65535) {\n u->err = "invalid port";\n } else {\n u->last_port = (in_port_t) n;\n }\n len = dash - host - 1;\n }\n n = ngx_atoi(host, len);\n if (n != NGX_ERROR) {\n if (u->err) {\n return NGX_ERROR;\n }\n if (n < 1 || n > 65535) {\n u->err = "invalid port";\n return NGX_ERROR;\n }\n if (u->last_port && n > u->last_port) {\n u->err = "invalid port range";\n return NGX_ERROR;\n }\n u->port = (in_port_t) n;\n sin->sin_port = htons((in_port_t) n);\n sin->sin_addr.s_addr = INADDR_ANY;\n u->port_text.len = last - host;\n u->port_text.data = host;\n u->wildcard = 1;\n return ngx_inet_add_addr(pool, u, &u->sockaddr.sockaddr,\n u->socklen, 1);\n }\n }\n }\nno_port:\n u->err = NULL;\n u->no_port = 1;\n u->port = u->default_port;\n sin->sin_port = htons(u->default_port);\n u->last_port = 0;\n }\n len = last - host;\n if (len == 0) {\n u->err = "no host";\n return NGX_ERROR;\n }\n u->host.len = len;\n u->host.data = host;\n if (u->listen && len == 1 && *host == \'*\') {\n sin->sin_addr.s_addr = INADDR_ANY;\n u->wildcard = 1;\n return ngx_inet_add_addr(pool, u, &u->sockaddr.sockaddr, u->socklen, 1);\n }\n sin->sin_addr.s_addr = ngx_inet_addr(host, len);\n if (sin->sin_addr.s_addr != INADDR_NONE) {\n if (sin->sin_addr.s_addr == INADDR_ANY) {\n u->wildcard = 1;\n }\n return ngx_inet_add_addr(pool, u, &u->sockaddr.sockaddr, u->socklen, 1);\n }\n if (u->no_resolve) {\n return NGX_OK;\n }\n if (ngx_inet_resolve_host(pool, u) != NGX_OK) {\n return NGX_ERROR;\n }\n u->family = u->addrs[0].sockaddr->sa_family;\n u->socklen = u->addrs[0].socklen;\n ngx_memcpy(&u->sockaddr, u->addrs[0].sockaddr, u->addrs[0].socklen);\n u->wildcard = ngx_inet_wildcard(&u->sockaddr.sockaddr);\n return NGX_OK;\n}', 'static ngx_inline u_char *\nngx_strlchr(u_char *p, u_char *last, u_char c)\n{\n while (p < last) {\n if (*p == c) {\n return p;\n }\n p++;\n }\n return NULL;\n}', "ngx_int_t\nngx_atoi(u_char *line, size_t n)\n{\n ngx_int_t value, cutoff, cutlim;\n if (n == 0) {\n return NGX_ERROR;\n }\n cutoff = NGX_MAX_INT_T_VALUE / 10;\n cutlim = NGX_MAX_INT_T_VALUE % 10;\n for (value = 0; n--; line++) {\n if (*line < '0' || *line > '9') {\n return NGX_ERROR;\n }\n if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) {\n return NGX_ERROR;\n }\n value = value * 10 + (*line - '0');\n }\n return value;\n}"]
33,540
0
https://github.com/libav/libav/blob/1c3e117e0bd73ffc5a3abeb35b521fd048988f06/ffmpeg.c/#L3110
static enum CodecID find_codec_or_die(const char *name, int type, int encoder, int strict) { const char *codec_string = encoder ? "encoder" : "decoder"; AVCodec *codec; if(!name) return CODEC_ID_NONE; codec = encoder ? avcodec_find_encoder_by_name(name) : avcodec_find_decoder_by_name(name); if(!codec) { fprintf(stderr, "Unknown %s '%s'\n", codec_string, name); ffmpeg_exit(1); } if(codec->type != type) { fprintf(stderr, "Invalid %s type '%s'\n", codec_string, name); ffmpeg_exit(1); } if(codec->capabilities & CODEC_CAP_EXPERIMENTAL && strict > FF_COMPLIANCE_EXPERIMENTAL) { fprintf(stderr, "%s '%s' is experimental and might produce bad " "results.\nAdd '-strict experimental' if you want to use it.\n", codec_string, codec->name); codec = encoder ? avcodec_find_encoder(codec->id) : avcodec_find_decoder(codec->id); if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL)) fprintf(stderr, "Or use the non experimental %s '%s'.\n", codec_string, codec->name); ffmpeg_exit(1); } return codec->id; }
['static enum CodecID find_codec_or_die(const char *name, int type, int encoder, int strict)\n{\n const char *codec_string = encoder ? "encoder" : "decoder";\n AVCodec *codec;\n if(!name)\n return CODEC_ID_NONE;\n codec = encoder ?\n avcodec_find_encoder_by_name(name) :\n avcodec_find_decoder_by_name(name);\n if(!codec) {\n fprintf(stderr, "Unknown %s \'%s\'\\n", codec_string, name);\n ffmpeg_exit(1);\n }\n if(codec->type != type) {\n fprintf(stderr, "Invalid %s type \'%s\'\\n", codec_string, name);\n ffmpeg_exit(1);\n }\n if(codec->capabilities & CODEC_CAP_EXPERIMENTAL &&\n strict > FF_COMPLIANCE_EXPERIMENTAL) {\n fprintf(stderr, "%s \'%s\' is experimental and might produce bad "\n "results.\\nAdd \'-strict experimental\' if you want to use it.\\n",\n codec_string, codec->name);\n codec = encoder ?\n avcodec_find_encoder(codec->id) :\n avcodec_find_decoder(codec->id);\n if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL))\n fprintf(stderr, "Or use the non experimental %s \'%s\'.\\n",\n codec_string, codec->name);\n ffmpeg_exit(1);\n }\n return codec->id;\n}']
33,541
0
https://github.com/libav/libav/blob/fcc0224e4fbd44ae268903185b0cf83560b13555/ffmpeg.c/#L3589
static void new_data_stream(AVFormatContext *oc, int file_idx) { AVStream *st; AVOutputStream *ost; AVCodec *codec=NULL; AVCodecContext *data_enc; st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0); if (!st) { fprintf(stderr, "Could not alloc stream\n"); ffmpeg_exit(1); } ost = new_output_stream(oc, file_idx); data_enc = st->codec; output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1); if (!data_stream_copy) { fprintf(stderr, "Data stream encoding not supported yet (only streamcopy)\n"); ffmpeg_exit(1); } avcodec_get_context_defaults3(st->codec, codec); data_enc->codec_type = AVMEDIA_TYPE_DATA; if (data_codec_tag) data_enc->codec_tag= data_codec_tag; if (oc->oformat->flags & AVFMT_GLOBALHEADER) { data_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; avcodec_opts[AVMEDIA_TYPE_DATA]->flags |= CODEC_FLAG_GLOBAL_HEADER; } if (data_stream_copy) { st->stream_copy = 1; } data_disable = 0; av_freep(&data_codec_name); data_stream_copy = 0; }
['static void new_data_stream(AVFormatContext *oc, int file_idx)\n{\n AVStream *st;\n AVOutputStream *ost;\n AVCodec *codec=NULL;\n AVCodecContext *data_enc;\n st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n ffmpeg_exit(1);\n }\n ost = new_output_stream(oc, file_idx);\n data_enc = st->codec;\n output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);\n if (!data_stream_copy) {\n fprintf(stderr, "Data stream encoding not supported yet (only streamcopy)\\n");\n ffmpeg_exit(1);\n }\n avcodec_get_context_defaults3(st->codec, codec);\n data_enc->codec_type = AVMEDIA_TYPE_DATA;\n if (data_codec_tag)\n data_enc->codec_tag= data_codec_tag;\n if (oc->oformat->flags & AVFMT_GLOBALHEADER) {\n data_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;\n avcodec_opts[AVMEDIA_TYPE_DATA]->flags |= CODEC_FLAG_GLOBAL_HEADER;\n }\n if (data_stream_copy) {\n st->stream_copy = 1;\n }\n data_disable = 0;\n av_freep(&data_codec_name);\n data_stream_copy = 0;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n AVStream **streams;\n if (s->nb_streams >= INT_MAX/sizeof(*streams))\n return NULL;\n streams = av_realloc(s->streams, (s->nb_streams + 1) * sizeof(*streams));\n if (!streams)\n return NULL;\n s->streams = streams;\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n if (!(st->info = av_mallocz(sizeof(*st->info)))) {\n av_free(st);\n return NULL;\n }\n st->codec= avcodec_alloc_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}']
33,542
0
https://github.com/openssl/openssl/blob/74a62e9629b2d07360a62571ff3028c83b69b0d9/crypto/lhash/lhash.c/#L209
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); }
['void CRYPTO_dbg_free(void *addr, int before_p)\n{\n MEM m, *mp;\n switch (before_p) {\n case 0:\n if (addr == NULL)\n break;\n if (is_MemCheck_on() && (mh != NULL)) {\n MemCheck_off();\n m.addr = addr;\n mp = lh_MEM_delete(mh, &m);\n if (mp != NULL) {\n app_info_free(mp->app_info);\n OPENSSL_free(mp);\n }\n MemCheck_on();\n }\n break;\n case 1:\n break;\n }\n}', '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}']
33,543
0
https://github.com/libav/libav/blob/704721bc9cb47c58ce3dff8ef64ce3fb85283069/libavcodec/g722enc.c/#L213
static int g722_encode_trellis(AVCodecContext *avctx, uint8_t *dst, int buf_size, void *data) { G722Context *c = avctx->priv_data; const int16_t *samples = data; int i, j, k; int frontier = 1 << avctx->trellis; struct TrellisNode **nodes[2]; struct TrellisNode **nodes_next[2]; int pathn[2] = {0, 0}, froze = -1; struct TrellisPath *p[2]; for (i = 0; i < 2; i++) { nodes[i] = c->nodep_buf[i]; nodes_next[i] = c->nodep_buf[i] + frontier; memset(c->nodep_buf[i], 0, 2 * frontier * sizeof(*c->nodep_buf)); nodes[i][0] = c->node_buf[i] + frontier; nodes[i][0]->ssd = 0; nodes[i][0]->path = 0; nodes[i][0]->state = c->band[i]; } for (i = 0; i < buf_size >> 1; i++) { int xlow, xhigh; struct TrellisNode *next[2]; int heap_pos[2] = {0, 0}; for (j = 0; j < 2; j++) { next[j] = c->node_buf[j] + frontier*(i & 1); memset(nodes_next[j], 0, frontier * sizeof(**nodes_next)); } filter_samples(c, &samples[2*i], &xlow, &xhigh); for (j = 0; j < frontier && nodes[0][j]; j++) { int range = j < frontier/2 ? 4 : 0; struct TrellisNode *cur_node = nodes[0][j]; int ilow = encode_low(&cur_node->state, xlow); for (k = ilow - range; k <= ilow + range && k <= 63; k += 4) { int decoded, dec_diff, pos; uint32_t ssd; struct TrellisNode* node; if (k < 0) continue; decoded = av_clip((cur_node->state.scale_factor * ff_g722_low_inv_quant6[k] >> 10) + cur_node->state.s_predictor, -16384, 16383); dec_diff = xlow - decoded; #define STORE_NODE(index, UPDATE, VALUE)\ ssd = cur_node->ssd + dec_diff*dec_diff;\ \ if (ssd < cur_node->ssd)\ continue;\ if (heap_pos[index] < frontier) {\ pos = heap_pos[index]++;\ assert(pathn[index] < FREEZE_INTERVAL * frontier);\ node = nodes_next[index][pos] = next[index]++;\ node->path = pathn[index]++;\ } else {\ \ pos = (frontier>>1) + (heap_pos[index] & ((frontier>>1) - 1));\ if (ssd >= nodes_next[index][pos]->ssd)\ continue;\ heap_pos[index]++;\ node = nodes_next[index][pos];\ }\ node->ssd = ssd;\ node->state = cur_node->state;\ UPDATE;\ c->paths[index][node->path].value = VALUE;\ c->paths[index][node->path].prev = cur_node->path;\ \ while (pos > 0) {\ int parent = (pos - 1) >> 1;\ if (nodes_next[index][parent]->ssd <= ssd)\ break;\ FFSWAP(struct TrellisNode*, nodes_next[index][parent],\ nodes_next[index][pos]);\ pos = parent;\ } STORE_NODE(0, ff_g722_update_low_predictor(&node->state, k >> 2), k); } } for (j = 0; j < frontier && nodes[1][j]; j++) { int ihigh; struct TrellisNode *cur_node = nodes[1][j]; for (ihigh = 0; ihigh < 4; ihigh++) { int dhigh, decoded, dec_diff, pos; uint32_t ssd; struct TrellisNode* node; dhigh = cur_node->state.scale_factor * ff_g722_high_inv_quant[ihigh] >> 10; decoded = av_clip(dhigh + cur_node->state.s_predictor, -16384, 16383); dec_diff = xhigh - decoded; STORE_NODE(1, ff_g722_update_high_predictor(&node->state, dhigh, ihigh), ihigh); } } for (j = 0; j < 2; j++) { FFSWAP(struct TrellisNode**, nodes[j], nodes_next[j]); if (nodes[j][0]->ssd > (1 << 16)) { for (k = 1; k < frontier && nodes[j][k]; k++) nodes[j][k]->ssd -= nodes[j][0]->ssd; nodes[j][0]->ssd = 0; } } if (i == froze + FREEZE_INTERVAL) { p[0] = &c->paths[0][nodes[0][0]->path]; p[1] = &c->paths[1][nodes[1][0]->path]; for (j = i; j > froze; j--) { dst[j] = p[1]->value << 6 | p[0]->value; p[0] = &c->paths[0][p[0]->prev]; p[1] = &c->paths[1][p[1]->prev]; } froze = i; pathn[0] = pathn[1] = 0; memset(nodes[0] + 1, 0, (frontier - 1)*sizeof(**nodes)); memset(nodes[1] + 1, 0, (frontier - 1)*sizeof(**nodes)); } } p[0] = &c->paths[0][nodes[0][0]->path]; p[1] = &c->paths[1][nodes[1][0]->path]; for (j = i; j > froze; j--) { dst[j] = p[1]->value << 6 | p[0]->value; p[0] = &c->paths[0][p[0]->prev]; p[1] = &c->paths[1][p[1]->prev]; } c->band[0] = nodes[0][0]->state; c->band[1] = nodes[1][0]->state; return i; }
['static int g722_encode_trellis(AVCodecContext *avctx,\n uint8_t *dst, int buf_size, void *data)\n{\n G722Context *c = avctx->priv_data;\n const int16_t *samples = data;\n int i, j, k;\n int frontier = 1 << avctx->trellis;\n struct TrellisNode **nodes[2];\n struct TrellisNode **nodes_next[2];\n int pathn[2] = {0, 0}, froze = -1;\n struct TrellisPath *p[2];\n for (i = 0; i < 2; i++) {\n nodes[i] = c->nodep_buf[i];\n nodes_next[i] = c->nodep_buf[i] + frontier;\n memset(c->nodep_buf[i], 0, 2 * frontier * sizeof(*c->nodep_buf));\n nodes[i][0] = c->node_buf[i] + frontier;\n nodes[i][0]->ssd = 0;\n nodes[i][0]->path = 0;\n nodes[i][0]->state = c->band[i];\n }\n for (i = 0; i < buf_size >> 1; i++) {\n int xlow, xhigh;\n struct TrellisNode *next[2];\n int heap_pos[2] = {0, 0};\n for (j = 0; j < 2; j++) {\n next[j] = c->node_buf[j] + frontier*(i & 1);\n memset(nodes_next[j], 0, frontier * sizeof(**nodes_next));\n }\n filter_samples(c, &samples[2*i], &xlow, &xhigh);\n for (j = 0; j < frontier && nodes[0][j]; j++) {\n int range = j < frontier/2 ? 4 : 0;\n struct TrellisNode *cur_node = nodes[0][j];\n int ilow = encode_low(&cur_node->state, xlow);\n for (k = ilow - range; k <= ilow + range && k <= 63; k += 4) {\n int decoded, dec_diff, pos;\n uint32_t ssd;\n struct TrellisNode* node;\n if (k < 0)\n continue;\n decoded = av_clip((cur_node->state.scale_factor *\n ff_g722_low_inv_quant6[k] >> 10)\n + cur_node->state.s_predictor, -16384, 16383);\n dec_diff = xlow - decoded;\n#define STORE_NODE(index, UPDATE, VALUE)\\\n ssd = cur_node->ssd + dec_diff*dec_diff;\\\n \\\n if (ssd < cur_node->ssd)\\\n continue;\\\n if (heap_pos[index] < frontier) {\\\n pos = heap_pos[index]++;\\\n assert(pathn[index] < FREEZE_INTERVAL * frontier);\\\n node = nodes_next[index][pos] = next[index]++;\\\n node->path = pathn[index]++;\\\n } else {\\\n \\\n pos = (frontier>>1) + (heap_pos[index] & ((frontier>>1) - 1));\\\n if (ssd >= nodes_next[index][pos]->ssd)\\\n continue;\\\n heap_pos[index]++;\\\n node = nodes_next[index][pos];\\\n }\\\n node->ssd = ssd;\\\n node->state = cur_node->state;\\\n UPDATE;\\\n c->paths[index][node->path].value = VALUE;\\\n c->paths[index][node->path].prev = cur_node->path;\\\n \\\n while (pos > 0) {\\\n int parent = (pos - 1) >> 1;\\\n if (nodes_next[index][parent]->ssd <= ssd)\\\n break;\\\n FFSWAP(struct TrellisNode*, nodes_next[index][parent],\\\n nodes_next[index][pos]);\\\n pos = parent;\\\n }\n STORE_NODE(0, ff_g722_update_low_predictor(&node->state, k >> 2), k);\n }\n }\n for (j = 0; j < frontier && nodes[1][j]; j++) {\n int ihigh;\n struct TrellisNode *cur_node = nodes[1][j];\n for (ihigh = 0; ihigh < 4; ihigh++) {\n int dhigh, decoded, dec_diff, pos;\n uint32_t ssd;\n struct TrellisNode* node;\n dhigh = cur_node->state.scale_factor *\n ff_g722_high_inv_quant[ihigh] >> 10;\n decoded = av_clip(dhigh + cur_node->state.s_predictor,\n -16384, 16383);\n dec_diff = xhigh - decoded;\n STORE_NODE(1, ff_g722_update_high_predictor(&node->state, dhigh, ihigh), ihigh);\n }\n }\n for (j = 0; j < 2; j++) {\n FFSWAP(struct TrellisNode**, nodes[j], nodes_next[j]);\n if (nodes[j][0]->ssd > (1 << 16)) {\n for (k = 1; k < frontier && nodes[j][k]; k++)\n nodes[j][k]->ssd -= nodes[j][0]->ssd;\n nodes[j][0]->ssd = 0;\n }\n }\n if (i == froze + FREEZE_INTERVAL) {\n p[0] = &c->paths[0][nodes[0][0]->path];\n p[1] = &c->paths[1][nodes[1][0]->path];\n for (j = i; j > froze; j--) {\n dst[j] = p[1]->value << 6 | p[0]->value;\n p[0] = &c->paths[0][p[0]->prev];\n p[1] = &c->paths[1][p[1]->prev];\n }\n froze = i;\n pathn[0] = pathn[1] = 0;\n memset(nodes[0] + 1, 0, (frontier - 1)*sizeof(**nodes));\n memset(nodes[1] + 1, 0, (frontier - 1)*sizeof(**nodes));\n }\n }\n p[0] = &c->paths[0][nodes[0][0]->path];\n p[1] = &c->paths[1][nodes[1][0]->path];\n for (j = i; j > froze; j--) {\n dst[j] = p[1]->value << 6 | p[0]->value;\n p[0] = &c->paths[0][p[0]->prev];\n p[1] = &c->paths[1][p[1]->prev];\n }\n c->band[0] = nodes[0][0]->state;\n c->band[1] = nodes[1][0]->state;\n return i;\n}']
33,544
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/asn1/asn1_lib.c/#L107
int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass, long omax) { int i,ret; long l; unsigned char *p= *pp; int tag,xclass,inf; long max=omax; if (!max) goto err; ret=(*p&V_ASN1_CONSTRUCTED); xclass=(*p&V_ASN1_PRIVATE); i= *p&V_ASN1_PRIMATIVE_TAG; if (i == V_ASN1_PRIMATIVE_TAG) { p++; if (--max == 0) goto err; l=0; while (*p&0x80) { l<<=7L; l|= *(p++)&0x7f; if (--max == 0) goto err; } l<<=7L; l|= *(p++)&0x7f; tag=(int)l; } else { tag=i; p++; if (--max == 0) goto err; } *ptag=tag; *pclass=xclass; if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; #if 0 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n", (int)p,*plength,omax,(int)*pp,(int)(p+ *plength), (int)(omax+ *pp)); #endif #if 0 if ((p+ *plength) > (omax+ *pp)) { ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); ret|=0x80; } #endif *pp=p; return(ret|inf); err: ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); return(0x80); }
['int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK *chain)\n\t{\n\tEVP_PKEY *ktmp=NULL,*ktmp2;\n\tint i,j;\n\tif ((pkey != NULL) && !EVP_PKEY_missing_parameters(pkey)) return(1);\n\tfor (i=0; i<sk_num(chain); i++)\n\t\t{\n\t\tktmp=X509_get_pubkey((X509 *)sk_value(chain,i));\n\t\tif (ktmp == NULL)\n\t\t\t{\n\t\t\tX509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY);\n\t\t\treturn(0);\n\t\t\t}\n\t\tif (!EVP_PKEY_missing_parameters(ktmp))\n\t\t\tbreak;\n\t\telse\n\t\t\t{\n\t\t\tEVP_PKEY_free(ktmp);\n\t\t\tktmp=NULL;\n\t\t\t}\n\t\t}\n\tif (ktmp == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN);\n\t\treturn(0);\n\t\t}\n\tfor (j=i-1; j >= 0; j--)\n\t\t{\n\t\tktmp2=X509_get_pubkey((X509 *)sk_value(chain,j));\n\t\tEVP_PKEY_copy_parameters(ktmp2,ktmp);\n\t\tEVP_PKEY_free(ktmp2);\n\t\t}\n\tif (pkey != NULL) EVP_PKEY_copy_parameters(pkey,ktmp);\n\tEVP_PKEY_free(ktmp);\n\treturn(1);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tlong j;\n\tint type;\n\tunsigned char *p;\n#ifndef NO_DSA\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t {\n\t CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);\n\t return(key->pkey);\n\t }\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tp=key->public_key->data;\n j=key->public_key->length;\n if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);\n\t\tgoto err;\n\t\t}\n\tret->save_parameters=0;\n#ifndef NO_DSA\n\ta=key->algor;\n\tif (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter->type == V_ASN1_SEQUENCE)\n\t\t\t{\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tp=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n\tkey->pkey=ret;\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);\n\treturn(ret);\nerr:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)\n\t{\n\tint i=ERR_R_NESTED_ASN1_ERROR;\n\tASN1_INTEGER *bs=NULL;\n\tM_ASN1_D2I_vars(a,DSA *,DSA_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn;\n\tASN1_BIT_STRING_free(bs);\n\tM_ASN1_D2I_Finish_2(a);\nerr_bn:\n\ti=ERR_R_BN_LIB;\nerr:\n\tASN1err(ASN1_F_D2I_DSAPARAMS,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);\n\tif (bs != NULL) ASN1_BIT_STRING_free(bs);\n\treturn(NULL);\n\t}', 'ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,\n\t long length)\n\t{\n\tASN1_INTEGER *ret=NULL;\n\tunsigned char *p,*to,*s;\n\tlong len;\n\tint inf,tag,xclass;\n\tint i;\n\tif ((a == NULL) || ((*a) == NULL))\n\t\t{\n\t\tif ((ret=ASN1_INTEGER_new()) == NULL) return(NULL);\n\t\tret->type=V_ASN1_INTEGER;\n\t\t}\n\telse\n\t\tret=(*a);\n\tp= *pp;\n\tinf=ASN1_get_object(&p,&len,&tag,&xclass,length);\n\tif (inf & 0x80)\n\t\t{\n\t\ti=ASN1_R_BAD_OBJECT_HEADER;\n\t\tgoto err;\n\t\t}\n\tif (tag != V_ASN1_INTEGER)\n\t\t{\n\t\ti=ASN1_R_EXPECTING_AN_INTEGER;\n\t\tgoto err;\n\t\t}\n\ts=(unsigned char *)Malloc((int)len+1);\n\tif (s == NULL)\n\t\t{\n\t\ti=ERR_R_MALLOC_FAILURE;\n\t\tgoto err;\n\t\t}\n\tto=s;\n\tif (*p & 0x80)\n\t\t{\n\t\tret->type=V_ASN1_NEG_INTEGER;\n\t\tif (*p == 0xff)\n\t\t\t{\n\t\t\tp++;\n\t\t\tlen--;\n\t\t\t}\n\t\tfor (i=(int)len; i>0; i--)\n\t\t\t*(to++)= (*(p++)^0xFF)+1;\n\t\t}\n\telse\n\t\t{\n\t\tret->type=V_ASN1_INTEGER;\n\t\tif ((*p == 0) && (len != 1))\n\t\t\t{\n\t\t\tp++;\n\t\t\tlen--;\n\t\t\t}\n\t\tmemcpy(s,p,(int)len);\n\t\tp+=len;\n\t\t}\n\tif (ret->data != NULL) Free((char *)ret->data);\n\tret->data=s;\n\tret->length=(int)len;\n\tif (a != NULL) (*a)=ret;\n\t*pp=p;\n\treturn(ret);\nerr:\n\tASN1err(ASN1_F_D2I_ASN1_INTEGER,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret)))\n\t\tASN1_INTEGER_free(ret);\n\treturn(NULL);\n\t}', 'int asn1_GetSequence(ASN1_CTX *c, long *length)\n\t{\n\tunsigned char *q;\n\tq=c->p;\n\tc->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),\n\t\t*length);\n\tif (c->inf & 0x80)\n\t\t{\n\t\tc->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;\n\t\treturn(0);\n\t\t}\n\tif (c->tag != V_ASN1_SEQUENCE)\n\t\t{\n\t\tc->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;\n\t\treturn(0);\n\t\t}\n\t(*length)-=(c->p-q);\n\tif (c->max && (*length < 0))\n\t\t{\n\t\tc->error=ERR_R_ASN1_LENGTH_MISMATCH;\n\t\treturn(0);\n\t\t}\n\tif (c->inf == (1|V_ASN1_CONSTRUCTED))\n\t\tc->slen= *length+ *(c->pp)-c->p;\n\tc->eos=0;\n\treturn(1);\n\t}', 'int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,\n\t long omax)\n\t{\n\tint i,ret;\n\tlong l;\n\tunsigned char *p= *pp;\n\tint tag,xclass,inf;\n\tlong max=omax;\n\tif (!max) goto err;\n\tret=(*p&V_ASN1_CONSTRUCTED);\n\txclass=(*p&V_ASN1_PRIVATE);\n\ti= *p&V_ASN1_PRIMATIVE_TAG;\n\tif (i == V_ASN1_PRIMATIVE_TAG)\n\t\t{\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\tl=0;\n\t\twhile (*p&0x80)\n\t\t\t{\n\t\t\tl<<=7L;\n\t\t\tl|= *(p++)&0x7f;\n\t\t\tif (--max == 0) goto err;\n\t\t\t}\n\t\tl<<=7L;\n\t\tl|= *(p++)&0x7f;\n\t\ttag=(int)l;\n\t\t}\n\telse\n\t\t{\n\t\ttag=i;\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\t}\n\t*ptag=tag;\n\t*pclass=xclass;\n\tif (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;\n#if 0\n\tfprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\\n",\n\t\t(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),\n\t\t(int)(omax+ *pp));\n#endif\n#if 0\n\tif ((p+ *plength) > (omax+ *pp))\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);\n\t\tret|=0x80;\n\t\t}\n#endif\n\t*pp=p;\n\treturn(ret|inf);\nerr:\n\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);\n\treturn(0x80);\n\t}']
33,545
0
https://github.com/openssl/openssl/blob/b879882a4b260067bc963807cb6b15b3c75902e8/crypto/pem/pvkfmt.c/#L686
static int derive_pvk_key(unsigned char *key, const unsigned char *salt, unsigned int saltlen, const unsigned char *pass, int passlen) { EVP_MD_CTX *mctx = EVP_MD_CTX_new(); int rv = 1; if (mctx == NULL || !EVP_DigestInit_ex(mctx, EVP_sha1(), NULL) || !EVP_DigestUpdate(mctx, salt, saltlen) || !EVP_DigestUpdate(mctx, pass, passlen) || !EVP_DigestFinal_ex(mctx, key, NULL)) rv = 0; EVP_MD_CTX_free(mctx); return rv; }
['static int derive_pvk_key(unsigned char *key,\n const unsigned char *salt, unsigned int saltlen,\n const unsigned char *pass, int passlen)\n{\n EVP_MD_CTX *mctx = EVP_MD_CTX_new();\n int rv = 1;\n if (mctx == NULL\n || !EVP_DigestInit_ex(mctx, EVP_sha1(), NULL)\n || !EVP_DigestUpdate(mctx, salt, saltlen)\n || !EVP_DigestUpdate(mctx, pass, passlen)\n || !EVP_DigestFinal_ex(mctx, key, NULL))\n rv = 0;\n EVP_MD_CTX_free(mctx);\n return rv;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'const EVP_MD *EVP_sha1(void)\n{\n return (&sha1_md);\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 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}']
33,546
0
https://github.com/openssl/openssl/blob/fff684168c7923aa85e6b4381d71d933396e32b0/crypto/rsa/rsa_sp800_56b_gen.c/#L127
int rsa_fips186_4_gen_prob_primes(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *Xpout, const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2, BIGNUM *q1, BIGNUM *q2, BIGNUM *Xqout, const BIGNUM *Xq, const BIGNUM *Xq1, const BIGNUM *Xq2, int nbits, const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb) { int ret = 0, ok; BIGNUM *Xpo = NULL, *Xqo = NULL, *tmp = NULL; if (nbits < RSA_FIPS1864_MIN_KEYGEN_KEYSIZE) { RSAerr(RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES, RSA_R_INVALID_KEY_LENGTH); return 0; } if (!rsa_check_public_exponent(e)) { RSAerr(RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES, RSA_R_PUB_EXPONENT_OUT_OF_RANGE); goto err; } BN_CTX_start(ctx); tmp = BN_CTX_get(ctx); Xpo = (Xpout != NULL) ? Xpout : BN_CTX_get(ctx); Xqo = (Xqout != NULL) ? Xqout : BN_CTX_get(ctx); if (tmp == NULL || Xpo == NULL || Xqo == NULL) goto err; if (rsa->p == NULL) rsa->p = BN_secure_new(); if (rsa->q == NULL) rsa->q = BN_secure_new(); if (rsa->p == NULL || rsa->q == NULL) goto err; if (!bn_rsa_fips186_4_gen_prob_primes(rsa->p, Xpo, p1, p2, Xp, Xp1, Xp2, nbits, e, ctx, cb)) goto err; for(;;) { if (!bn_rsa_fips186_4_gen_prob_primes(rsa->q, Xqo, q1, q2, Xq, Xq1, Xq2, nbits, e, ctx, cb)) goto err; ok = rsa_check_pminusq_diff(tmp, Xpo, Xqo, nbits); if (ok < 0) goto err; if (ok == 0) continue; ok = rsa_check_pminusq_diff(tmp, rsa->p, rsa->q, nbits); if (ok < 0) goto err; if (ok == 0) continue; break; } ret = 1; err: if (Xpo != Xpout) BN_clear(Xpo); if (Xqo != Xqout) BN_clear(Xqo); BN_clear(tmp); BN_CTX_end(ctx); return ret; }
['int rsa_fips186_4_gen_prob_primes(RSA *rsa, BIGNUM *p1, BIGNUM *p2,\n BIGNUM *Xpout, const BIGNUM *Xp,\n const BIGNUM *Xp1, const BIGNUM *Xp2,\n BIGNUM *q1, BIGNUM *q2, BIGNUM *Xqout,\n const BIGNUM *Xq, const BIGNUM *Xq1,\n const BIGNUM *Xq2, int nbits,\n const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb)\n{\n int ret = 0, ok;\n BIGNUM *Xpo = NULL, *Xqo = NULL, *tmp = NULL;\n if (nbits < RSA_FIPS1864_MIN_KEYGEN_KEYSIZE) {\n RSAerr(RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES, RSA_R_INVALID_KEY_LENGTH);\n return 0;\n }\n if (!rsa_check_public_exponent(e)) {\n RSAerr(RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES,\n RSA_R_PUB_EXPONENT_OUT_OF_RANGE);\n goto err;\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n Xpo = (Xpout != NULL) ? Xpout : BN_CTX_get(ctx);\n Xqo = (Xqout != NULL) ? Xqout : BN_CTX_get(ctx);\n if (tmp == NULL || Xpo == NULL || Xqo == NULL)\n goto err;\n if (rsa->p == NULL)\n rsa->p = BN_secure_new();\n if (rsa->q == NULL)\n rsa->q = BN_secure_new();\n if (rsa->p == NULL || rsa->q == NULL)\n goto err;\n if (!bn_rsa_fips186_4_gen_prob_primes(rsa->p, Xpo, p1, p2, Xp, Xp1, Xp2,\n nbits, e, ctx, cb))\n goto err;\n for(;;) {\n if (!bn_rsa_fips186_4_gen_prob_primes(rsa->q, Xqo, q1, q2, Xq, Xq1,\n Xq2, nbits, e, ctx, cb))\n goto err;\n ok = rsa_check_pminusq_diff(tmp, Xpo, Xqo, nbits);\n if (ok < 0)\n goto err;\n if (ok == 0)\n continue;\n ok = rsa_check_pminusq_diff(tmp, rsa->p, rsa->q, nbits);\n if (ok < 0)\n goto err;\n if (ok == 0)\n continue;\n break;\n }\n ret = 1;\nerr:\n if (Xpo != Xpout)\n BN_clear(Xpo);\n if (Xqo != Xqout)\n BN_clear(Xqo);\n BN_clear(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'int rsa_check_public_exponent(const BIGNUM *e)\n{\n int bitlen = BN_num_bits(e);\n return (BN_is_odd(e) && bitlen > 16 && bitlen < 257);\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n int i = a->top - 1;\n bn_check_top(a);\n if (BN_is_zero(a))\n return 0;\n return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'int BN_num_bits_word(BN_ULONG l)\n{\n BN_ULONG x, mask;\n int bits = (l != 0);\n#if BN_BITS2 > 32\n x = l >> 32;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 32 & mask;\n l ^= (x ^ l) & mask;\n#endif\n x = l >> 16;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 16 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 8;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 8 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 4;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 4 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 2;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 2 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 1;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 1 & mask;\n return bits;\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n return (a->top > 0) && (a->d[0] & 1);\n}', 'void BN_clear(BIGNUM *a)\n{\n bn_check_top(a);\n if (a->d != NULL)\n OPENSSL_cleanse(a->d, sizeof(*a->d) * a->dmax);\n a->neg = 0;\n a->top = 0;\n a->flags &= ~BN_FLG_FIXED_TOP;\n}']
33,547
0
https://github.com/libav/libav/blob/548a99742c2498575d0dbcd1aa030b9d51d28b18/libavcodec/msrledec.c/#L138
static int msrle_decode_8_16_24_32(AVCodecContext *avctx, AVPicture *pic, int depth, const uint8_t *data, int srcsize) { uint8_t *output, *output_end; const uint8_t* src = data; int p1, p2, line=avctx->height - 1, pos=0, i; uint16_t av_uninit(pix16); uint32_t av_uninit(pix32); output = pic->data[0] + (avctx->height - 1) * pic->linesize[0]; output_end = pic->data[0] + (avctx->height) * pic->linesize[0]; while(src < data + srcsize) { p1 = *src++; if(p1 == 0) { p2 = *src++; if(p2 == 0) { output = pic->data[0] + (--line) * pic->linesize[0]; if (line < 0){ av_log(avctx, AV_LOG_ERROR, "Next line is beyond picture bounds\n"); return -1; } pos = 0; continue; } else if(p2 == 1) { return 0; } else if(p2 == 2) { p1 = *src++; p2 = *src++; line -= p2; if (line < 0){ av_log(avctx, AV_LOG_ERROR, "Skip beyond picture bounds\n"); return -1; } pos += p1; output = pic->data[0] + line * pic->linesize[0] + pos * (depth >> 3); continue; } if (output + p2 * (depth >> 3) > output_end) { src += p2 * (depth >> 3); continue; } if ((depth == 8) || (depth == 24)) { for(i = 0; i < p2 * (depth >> 3); i++) { *output++ = *src++; } if(depth == 8 && (p2 & 1)) { src++; } } else if (depth == 16) { for(i = 0; i < p2; i++) { pix16 = AV_RL16(src); src += 2; *(uint16_t*)output = pix16; output += 2; } } else if (depth == 32) { for(i = 0; i < p2; i++) { pix32 = AV_RL32(src); src += 4; *(uint32_t*)output = pix32; output += 4; } } pos += p2; } else { uint8_t pix[3]; switch(depth){ case 8: pix[0] = *src++; break; case 16: pix16 = AV_RL16(src); src += 2; break; case 24: pix[0] = *src++; pix[1] = *src++; pix[2] = *src++; break; case 32: pix32 = AV_RL32(src); src += 4; break; } if (output + p1 * (depth >> 3) > output_end) continue; for(i = 0; i < p1; i++) { switch(depth){ case 8: *output++ = pix[0]; break; case 16: *(uint16_t*)output = pix16; output += 2; break; case 24: *output++ = pix[0]; *output++ = pix[1]; *output++ = pix[2]; break; case 32: *(uint32_t*)output = pix32; output += 4; break; } } pos += p1; } } av_log(avctx, AV_LOG_WARNING, "MS RLE warning: no end-of-picture code\n"); return 0; }
['static int msrle_decode_8_16_24_32(AVCodecContext *avctx, AVPicture *pic, int depth,\n const uint8_t *data, int srcsize)\n{\n uint8_t *output, *output_end;\n const uint8_t* src = data;\n int p1, p2, line=avctx->height - 1, pos=0, i;\n uint16_t av_uninit(pix16);\n uint32_t av_uninit(pix32);\n output = pic->data[0] + (avctx->height - 1) * pic->linesize[0];\n output_end = pic->data[0] + (avctx->height) * pic->linesize[0];\n while(src < data + srcsize) {\n p1 = *src++;\n if(p1 == 0) {\n p2 = *src++;\n if(p2 == 0) {\n output = pic->data[0] + (--line) * pic->linesize[0];\n if (line < 0){\n av_log(avctx, AV_LOG_ERROR, "Next line is beyond picture bounds\\n");\n return -1;\n }\n pos = 0;\n continue;\n } else if(p2 == 1) {\n return 0;\n } else if(p2 == 2) {\n p1 = *src++;\n p2 = *src++;\n line -= p2;\n if (line < 0){\n av_log(avctx, AV_LOG_ERROR, "Skip beyond picture bounds\\n");\n return -1;\n }\n pos += p1;\n output = pic->data[0] + line * pic->linesize[0] + pos * (depth >> 3);\n continue;\n }\n if (output + p2 * (depth >> 3) > output_end) {\n src += p2 * (depth >> 3);\n continue;\n }\n if ((depth == 8) || (depth == 24)) {\n for(i = 0; i < p2 * (depth >> 3); i++) {\n *output++ = *src++;\n }\n if(depth == 8 && (p2 & 1)) {\n src++;\n }\n } else if (depth == 16) {\n for(i = 0; i < p2; i++) {\n pix16 = AV_RL16(src);\n src += 2;\n *(uint16_t*)output = pix16;\n output += 2;\n }\n } else if (depth == 32) {\n for(i = 0; i < p2; i++) {\n pix32 = AV_RL32(src);\n src += 4;\n *(uint32_t*)output = pix32;\n output += 4;\n }\n }\n pos += p2;\n } else {\n uint8_t pix[3];\n switch(depth){\n case 8: pix[0] = *src++;\n break;\n case 16: pix16 = AV_RL16(src);\n src += 2;\n break;\n case 24: pix[0] = *src++;\n pix[1] = *src++;\n pix[2] = *src++;\n break;\n case 32: pix32 = AV_RL32(src);\n src += 4;\n break;\n }\n if (output + p1 * (depth >> 3) > output_end)\n continue;\n for(i = 0; i < p1; i++) {\n switch(depth){\n case 8: *output++ = pix[0];\n break;\n case 16: *(uint16_t*)output = pix16;\n output += 2;\n break;\n case 24: *output++ = pix[0];\n *output++ = pix[1];\n *output++ = pix[2];\n break;\n case 32: *(uint32_t*)output = pix32;\n output += 4;\n break;\n }\n }\n pos += p1;\n }\n }\n av_log(avctx, AV_LOG_WARNING, "MS RLE warning: no end-of-picture code\\n");\n return 0;\n}']
33,548
0
https://github.com/openssl/openssl/blob/ea32151f7b9353f8906188d007c6893704ac17bb/ssl/record/rec_layer_s3.c/#L902
int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, unsigned int len) { int i; SSL3_BUFFER *wb = s->rlayer.wbuf; unsigned int currbuf = 0; if ((s->rlayer.wpend_tot > (int)len) || ((s->rlayer.wpend_buf != buf) && !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER)) || (s->rlayer.wpend_type != type)) { SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BAD_WRITE_RETRY); return (-1); } for (;;) { if (SSL3_BUFFER_get_left(&wb[currbuf]) == 0 && currbuf < s->rlayer.numwpipes - 1) { currbuf++; continue; } clear_sys_error(); if (s->wbio != NULL) { s->rwstate = SSL_WRITING; i = BIO_write(s->wbio, (char *)&(SSL3_BUFFER_get_buf(&wb[currbuf])[ SSL3_BUFFER_get_offset(&wb[currbuf])]), (unsigned int)SSL3_BUFFER_get_left(&wb[currbuf])); } else { SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BIO_NOT_SET); i = -1; } if (i == SSL3_BUFFER_get_left(&wb[currbuf])) { SSL3_BUFFER_set_left(&wb[currbuf], 0); SSL3_BUFFER_add_offset(&wb[currbuf], i); if (currbuf + 1 < s->rlayer.numwpipes) continue; s->rwstate = SSL_NOTHING; return (s->rlayer.wpend_ret); } else if (i <= 0) { if (SSL_IS_DTLS(s)) { SSL3_BUFFER_set_left(&wb[currbuf], 0); } return (i); } SSL3_BUFFER_add_offset(&wb[currbuf], i); SSL3_BUFFER_add_left(&wb[currbuf], -i); } }
['int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,\n int len, int peek)\n{\n int al, i, j, ret;\n unsigned int n;\n SSL3_RECORD *rr;\n void (*cb) (const SSL *ssl, int type2, int val) = NULL;\n if (!SSL3_BUFFER_is_initialised(&s->rlayer.rbuf)) {\n if (!ssl3_setup_buffers(s))\n return (-1);\n }\n if ((type && (type != SSL3_RT_APPLICATION_DATA) &&\n (type != SSL3_RT_HANDSHAKE)) ||\n (peek && (type != SSL3_RT_APPLICATION_DATA))) {\n SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);\n return -1;\n }\n if ((ret = have_handshake_fragment(s, type, buf, len)))\n return ret;\n#ifndef OPENSSL_NO_SCTP\n if ((!ossl_statem_get_in_handshake(s) && SSL_in_init(s)) ||\n (BIO_dgram_is_sctp(SSL_get_rbio(s))\n && ossl_statem_in_sctp_read_sock(s)\n && s->s3->in_read_app_data != 2))\n#else\n if (!ossl_statem_get_in_handshake(s) && SSL_in_init(s))\n#endif\n {\n i = s->handshake_func(s);\n if (i < 0)\n return (i);\n if (i == 0) {\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_SSL_HANDSHAKE_FAILURE);\n return (-1);\n }\n }\n start:\n s->rwstate = SSL_NOTHING;\n rr = s->rlayer.rrec;\n if (SSL_is_init_finished(s) && SSL3_RECORD_get_length(rr) == 0) {\n pitem *item;\n item = pqueue_pop(s->rlayer.d->buffered_app_data.q);\n if (item) {\n#ifndef OPENSSL_NO_SCTP\n if (BIO_dgram_is_sctp(SSL_get_rbio(s))) {\n DTLS1_RECORD_DATA *rdata = (DTLS1_RECORD_DATA *)item->data;\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SCTP_SET_RCVINFO,\n sizeof(rdata->recordinfo), &rdata->recordinfo);\n }\n#endif\n dtls1_copy_record(s, item);\n OPENSSL_free(item->data);\n pitem_free(item);\n }\n }\n if (dtls1_handle_timeout(s) > 0)\n goto start;\n if ((SSL3_RECORD_get_length(rr) == 0)\n || (s->rlayer.rstate == SSL_ST_READ_BODY)) {\n ret = dtls1_get_record(s);\n if (ret <= 0) {\n ret = dtls1_read_failed(s, ret);\n if (ret <= 0)\n return (ret);\n else\n goto start;\n }\n }\n if (s->s3->change_cipher_spec\n && (SSL3_RECORD_get_type(rr) != SSL3_RT_HANDSHAKE)) {\n if (dtls1_buffer_record(s, &(s->rlayer.d->buffered_app_data),\n SSL3_RECORD_get_seq_num(rr)) < 0) {\n SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);\n return -1;\n }\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n if (s->shutdown & SSL_RECEIVED_SHUTDOWN) {\n SSL3_RECORD_set_length(rr, 0);\n s->rwstate = SSL_NOTHING;\n return (0);\n }\n if (type == SSL3_RECORD_get_type(rr)\n || (SSL3_RECORD_get_type(rr) == SSL3_RT_CHANGE_CIPHER_SPEC\n && type == SSL3_RT_HANDSHAKE && recvd_type != NULL)) {\n if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) &&\n (s->enc_read_ctx == NULL)) {\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_APP_DATA_IN_HANDSHAKE);\n goto f_err;\n }\n if (recvd_type != NULL)\n *recvd_type = SSL3_RECORD_get_type(rr);\n if (len <= 0)\n return (len);\n if ((unsigned int)len > SSL3_RECORD_get_length(rr))\n n = SSL3_RECORD_get_length(rr);\n else\n n = (unsigned int)len;\n memcpy(buf, &(SSL3_RECORD_get_data(rr)[SSL3_RECORD_get_off(rr)]), n);\n if (!peek) {\n SSL3_RECORD_add_length(rr, -n);\n SSL3_RECORD_add_off(rr, n);\n if (SSL3_RECORD_get_length(rr) == 0) {\n s->rlayer.rstate = SSL_ST_READ_HEADER;\n SSL3_RECORD_set_off(rr, 0);\n }\n }\n#ifndef OPENSSL_NO_SCTP\n if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&\n SSL3_RECORD_get_type(rr) == SSL3_RT_APPLICATION_DATA &&\n ossl_statem_in_sctp_read_sock(s)) {\n s->rwstate = SSL_READING;\n BIO_clear_retry_flags(SSL_get_rbio(s));\n BIO_set_retry_read(SSL_get_rbio(s));\n }\n if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&\n s->d1->shutdown_received\n && !BIO_dgram_sctp_msg_waiting(SSL_get_rbio(s))) {\n s->shutdown |= SSL_RECEIVED_SHUTDOWN;\n return (0);\n }\n#endif\n return (n);\n }\n {\n unsigned int k, dest_maxlen = 0;\n unsigned char *dest = NULL;\n unsigned int *dest_len = NULL;\n if (SSL3_RECORD_get_type(rr) == SSL3_RT_HANDSHAKE) {\n dest_maxlen = sizeof s->rlayer.d->handshake_fragment;\n dest = s->rlayer.d->handshake_fragment;\n dest_len = &s->rlayer.d->handshake_fragment_len;\n } else if (SSL3_RECORD_get_type(rr) == SSL3_RT_ALERT) {\n dest_maxlen = sizeof(s->rlayer.d->alert_fragment);\n dest = s->rlayer.d->alert_fragment;\n dest_len = &s->rlayer.d->alert_fragment_len;\n }\n#ifndef OPENSSL_NO_HEARTBEATS\n else if (SSL3_RECORD_get_type(rr) == DTLS1_RT_HEARTBEAT) {\n if (dtls1_process_heartbeat(s, SSL3_RECORD_get_data(rr),\n SSL3_RECORD_get_length(rr)) < 0) {\n return -1;\n }\n SSL3_RECORD_set_length(rr, 0);\n s->rwstate = SSL_READING;\n BIO_clear_retry_flags(SSL_get_rbio(s));\n BIO_set_retry_read(SSL_get_rbio(s));\n return (-1);\n }\n#endif\n else if (SSL3_RECORD_get_type(rr) != SSL3_RT_CHANGE_CIPHER_SPEC) {\n if (SSL3_RECORD_get_type(rr) == SSL3_RT_APPLICATION_DATA) {\n BIO *bio;\n s->s3->in_read_app_data = 2;\n bio = SSL_get_rbio(s);\n s->rwstate = SSL_READING;\n BIO_clear_retry_flags(bio);\n BIO_set_retry_read(bio);\n return (-1);\n }\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNEXPECTED_RECORD);\n goto f_err;\n }\n if (dest_maxlen > 0) {\n if (SSL3_RECORD_get_length(rr) < dest_maxlen) {\n#ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE\n FIX ME\n#endif\n s->rlayer.rstate = SSL_ST_READ_HEADER;\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n for (k = 0; k < dest_maxlen; k++) {\n dest[k] = SSL3_RECORD_get_data(rr)[SSL3_RECORD_get_off(rr)];\n SSL3_RECORD_add_off(rr, 1);\n SSL3_RECORD_add_length(rr, -1);\n }\n *dest_len = dest_maxlen;\n }\n }\n if ((!s->server) &&\n (s->rlayer.d->handshake_fragment_len >= DTLS1_HM_HEADER_LENGTH) &&\n (s->rlayer.d->handshake_fragment[0] == SSL3_MT_HELLO_REQUEST) &&\n (s->session != NULL) && (s->session->cipher != NULL)) {\n s->rlayer.d->handshake_fragment_len = 0;\n if ((s->rlayer.d->handshake_fragment[1] != 0) ||\n (s->rlayer.d->handshake_fragment[2] != 0) ||\n (s->rlayer.d->handshake_fragment[3] != 0)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_BAD_HELLO_REQUEST);\n goto f_err;\n }\n if (s->msg_callback)\n s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,\n s->rlayer.d->handshake_fragment, 4, s,\n s->msg_callback_arg);\n if (SSL_is_init_finished(s) &&\n !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) &&\n !s->s3->renegotiate) {\n s->d1->handshake_read_seq++;\n s->new_session = 1;\n ssl3_renegotiate(s);\n if (ssl3_renegotiate_check(s)) {\n i = s->handshake_func(s);\n if (i < 0)\n return (i);\n if (i == 0) {\n SSLerr(SSL_F_DTLS1_READ_BYTES,\n SSL_R_SSL_HANDSHAKE_FAILURE);\n return (-1);\n }\n if (!(s->mode & SSL_MODE_AUTO_RETRY)) {\n if (SSL3_BUFFER_get_left(&s->rlayer.rbuf) == 0) {\n BIO *bio;\n s->rwstate = SSL_READING;\n bio = SSL_get_rbio(s);\n BIO_clear_retry_flags(bio);\n BIO_set_retry_read(bio);\n return (-1);\n }\n }\n }\n }\n goto start;\n }\n if (s->rlayer.d->alert_fragment_len >= DTLS1_AL_HEADER_LENGTH) {\n int alert_level = s->rlayer.d->alert_fragment[0];\n int alert_descr = s->rlayer.d->alert_fragment[1];\n s->rlayer.d->alert_fragment_len = 0;\n if (s->msg_callback)\n s->msg_callback(0, s->version, SSL3_RT_ALERT,\n s->rlayer.d->alert_fragment, 2, s,\n s->msg_callback_arg);\n if (s->info_callback != NULL)\n cb = s->info_callback;\n else if (s->ctx->info_callback != NULL)\n cb = s->ctx->info_callback;\n if (cb != NULL) {\n j = (alert_level << 8) | alert_descr;\n cb(s, SSL_CB_READ_ALERT, j);\n }\n if (alert_level == SSL3_AL_WARNING) {\n s->s3->warn_alert = alert_descr;\n if (alert_descr == SSL_AD_CLOSE_NOTIFY) {\n#ifndef OPENSSL_NO_SCTP\n if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&\n BIO_dgram_sctp_msg_waiting(SSL_get_rbio(s))) {\n s->d1->shutdown_received = 1;\n s->rwstate = SSL_READING;\n BIO_clear_retry_flags(SSL_get_rbio(s));\n BIO_set_retry_read(SSL_get_rbio(s));\n return -1;\n }\n#endif\n s->shutdown |= SSL_RECEIVED_SHUTDOWN;\n return (0);\n }\n#if 0\n if (alert_descr == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE) {\n unsigned short seq;\n unsigned int frag_off;\n unsigned char *p = &(s->rlayer.d->alert_fragment[2]);\n n2s(p, seq);\n n2l3(p, frag_off);\n dtls1_retransmit_message(s,\n dtls1_get_queue_priority\n (frag->msg_header.seq, 0), frag_off,\n &found);\n if (!found && SSL_in_init(s)) {\n ssl3_send_alert(s, SSL3_AL_WARNING,\n DTLS1_AD_MISSING_HANDSHAKE_MESSAGE);\n }\n }\n#endif\n } else if (alert_level == SSL3_AL_FATAL) {\n char tmp[16];\n s->rwstate = SSL_NOTHING;\n s->s3->fatal_alert = alert_descr;\n SSLerr(SSL_F_DTLS1_READ_BYTES,\n SSL_AD_REASON_OFFSET + alert_descr);\n BIO_snprintf(tmp, sizeof tmp, "%d", alert_descr);\n ERR_add_error_data(2, "SSL alert number ", tmp);\n s->shutdown |= SSL_RECEIVED_SHUTDOWN;\n SSL_CTX_remove_session(s->ctx, s->session);\n return (0);\n } else {\n al = SSL_AD_ILLEGAL_PARAMETER;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNKNOWN_ALERT_TYPE);\n goto f_err;\n }\n goto start;\n }\n if (s->shutdown & SSL_SENT_SHUTDOWN) {\n s->rwstate = SSL_NOTHING;\n SSL3_RECORD_set_length(rr, 0);\n return (0);\n }\n if (SSL3_RECORD_get_type(rr) == SSL3_RT_CHANGE_CIPHER_SPEC) {\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n if ((s->rlayer.d->handshake_fragment_len >= DTLS1_HM_HEADER_LENGTH) &&\n !ossl_statem_get_in_handshake(s)) {\n struct hm_header_st msg_hdr;\n dtls1_get_message_header(rr->data, &msg_hdr);\n if (SSL3_RECORD_get_epoch(rr) != s->rlayer.d->r_epoch) {\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n if (msg_hdr.type == SSL3_MT_FINISHED) {\n if (dtls1_check_timeout_num(s) < 0)\n return -1;\n dtls1_retransmit_buffered_messages(s);\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n if (SSL_is_init_finished(s) &&\n !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)) {\n ossl_statem_set_in_init(s, 1);\n s->renegotiate = 1;\n s->new_session = 1;\n }\n i = s->handshake_func(s);\n if (i < 0)\n return (i);\n if (i == 0) {\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_SSL_HANDSHAKE_FAILURE);\n return (-1);\n }\n if (!(s->mode & SSL_MODE_AUTO_RETRY)) {\n if (SSL3_BUFFER_get_left(&s->rlayer.rbuf) == 0) {\n BIO *bio;\n s->rwstate = SSL_READING;\n bio = SSL_get_rbio(s);\n BIO_clear_retry_flags(bio);\n BIO_set_retry_read(bio);\n return (-1);\n }\n }\n goto start;\n }\n switch (SSL3_RECORD_get_type(rr)) {\n default:\n if (s->version == TLS1_VERSION) {\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNEXPECTED_RECORD);\n goto f_err;\n case SSL3_RT_CHANGE_CIPHER_SPEC:\n case SSL3_RT_ALERT:\n case SSL3_RT_HANDSHAKE:\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);\n goto f_err;\n case SSL3_RT_APPLICATION_DATA:\n if (s->s3->in_read_app_data &&\n (s->s3->total_renegotiations != 0) &&\n ossl_statem_app_data_allowed(s)) {\n s->s3->in_read_app_data = 2;\n return (-1);\n } else {\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNEXPECTED_RECORD);\n goto f_err;\n }\n }\n f_err:\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n return (-1);\n}', 'int dtls1_handle_timeout(SSL *s)\n{\n if (!dtls1_is_timer_expired(s)) {\n return 0;\n }\n dtls1_double_timeout(s);\n if (dtls1_check_timeout_num(s) < 0)\n return -1;\n s->d1->timeout.read_timeouts++;\n if (s->d1->timeout.read_timeouts > DTLS1_TMO_READ_COUNT) {\n s->d1->timeout.read_timeouts = 1;\n }\n#ifndef OPENSSL_NO_HEARTBEATS\n if (s->tlsext_hb_pending) {\n s->tlsext_hb_pending = 0;\n return dtls1_heartbeat(s);\n }\n#endif\n dtls1_start_timer(s);\n return dtls1_retransmit_buffered_messages(s);\n}', 'int dtls1_get_record(SSL *s)\n{\n int ssl_major, ssl_minor;\n int i, n;\n SSL3_RECORD *rr;\n unsigned char *p = NULL;\n unsigned short version;\n DTLS1_BITMAP *bitmap;\n unsigned int is_next_epoch;\n rr = RECORD_LAYER_get_rrec(&s->rlayer);\n if (dtls1_process_buffered_records(s) < 0)\n return -1;\n if (dtls1_get_processed_record(s))\n return 1;\n again:\n if ((RECORD_LAYER_get_rstate(&s->rlayer) != SSL_ST_READ_BODY) ||\n (RECORD_LAYER_get_packet_length(&s->rlayer) < DTLS1_RT_HEADER_LENGTH)) {\n n = ssl3_read_n(s, DTLS1_RT_HEADER_LENGTH,\n SSL3_BUFFER_get_len(&s->rlayer.rbuf), 0, 1);\n if (n <= 0)\n return (n);\n if (RECORD_LAYER_get_packet_length(&s->rlayer) != DTLS1_RT_HEADER_LENGTH) {\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_BODY);\n p = RECORD_LAYER_get_packet(&s->rlayer);\n if (s->msg_callback)\n s->msg_callback(0, 0, SSL3_RT_HEADER, p, DTLS1_RT_HEADER_LENGTH,\n s, s->msg_callback_arg);\n rr->type = *(p++);\n ssl_major = *(p++);\n ssl_minor = *(p++);\n version = (ssl_major << 8) | ssl_minor;\n n2s(p, rr->epoch);\n memcpy(&(RECORD_LAYER_get_read_sequence(&s->rlayer)[2]), p, 6);\n p += 6;\n n2s(p, rr->length);\n if (!s->first_packet) {\n if (version != s->version) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n }\n if ((version & 0xff00) != (s->version & 0xff00)) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n }\n if (rr->length >\n RECORD_LAYER_get_packet_length(&s->rlayer) - DTLS1_RT_HEADER_LENGTH) {\n i = rr->length;\n n = ssl3_read_n(s, i, i, 1, 1);\n if (n != i) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n }\n RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_HEADER);\n bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);\n if (bitmap == NULL) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n#ifndef OPENSSL_NO_SCTP\n if (!BIO_dgram_is_sctp(SSL_get_rbio(s))) {\n#endif\n if (!dtls1_record_replay_check(s, bitmap)) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n#ifndef OPENSSL_NO_SCTP\n }\n#endif\n if (rr->length == 0)\n goto again;\n if (is_next_epoch) {\n if ((SSL_in_init(s) || ossl_statem_get_in_handshake(s))) {\n if (dtls1_buffer_record\n (s, &(DTLS_RECORD_LAYER_get_unprocessed_rcds(&s->rlayer)),\n rr->seq_num) < 0)\n return -1;\n dtls1_record_bitmap_update(s, bitmap);\n }\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n if (!dtls1_process_record(s)) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n dtls1_record_bitmap_update(s, bitmap);\n return (1);\n}', 'int dtls1_process_buffered_records(SSL *s)\n{\n pitem *item;\n item = pqueue_peek(s->rlayer.d->unprocessed_rcds.q);\n if (item) {\n if (s->rlayer.d->unprocessed_rcds.epoch != s->rlayer.d->r_epoch)\n return (1);\n while (pqueue_peek(s->rlayer.d->unprocessed_rcds.q)) {\n dtls1_get_unprocessed_record(s);\n if (!dtls1_process_record(s))\n return (0);\n if (dtls1_buffer_record(s, &(s->rlayer.d->processed_rcds),\n SSL3_RECORD_get_seq_num(s->rlayer.rrec)) < 0)\n return -1;\n }\n }\n s->rlayer.d->processed_rcds.epoch = s->rlayer.d->r_epoch;\n s->rlayer.d->unprocessed_rcds.epoch = s->rlayer.d->r_epoch + 1;\n return (1);\n}', 'int dtls1_read_failed(SSL *s, int code)\n{\n if (code > 0) {\n fprintf(stderr, "dtls1_read_failed(); invalid state reached\\n");\n return 1;\n }\n if (!dtls1_is_timer_expired(s)) {\n return code;\n }\n#ifndef OPENSSL_NO_HEARTBEATS\n if (!SSL_in_init(s) && !s->tlsext_hb_pending)\n#else\n if (!SSL_in_init(s))\n#endif\n {\n BIO_set_flags(SSL_get_rbio(s), BIO_FLAGS_READ);\n return code;\n }\n return dtls1_handle_timeout(s);\n}', 'int dtls1_retransmit_buffered_messages(SSL *s)\n{\n pqueue *sent = s->d1->sent_messages;\n piterator iter;\n pitem *item;\n hm_fragment *frag;\n int found = 0;\n iter = pqueue_iterator(sent);\n for (item = pqueue_next(&iter); item != NULL; item = pqueue_next(&iter)) {\n frag = (hm_fragment *)item->data;\n if (dtls1_retransmit_message(s, (unsigned short)\n dtls1_get_queue_priority\n (frag->msg_header.seq,\n frag->msg_header.is_ccs),\n &found) <= 0 && found) {\n fprintf(stderr, "dtls1_retransmit_message() failed\\n");\n return -1;\n }\n }\n return 1;\n}', 'int\ndtls1_retransmit_message(SSL *s, unsigned short seq, int *found)\n{\n int ret;\n pitem *item;\n hm_fragment *frag;\n unsigned long header_length;\n unsigned char seq64be[8];\n struct dtls1_retransmit_state saved_state;\n memset(seq64be, 0, sizeof(seq64be));\n seq64be[6] = (unsigned char)(seq >> 8);\n seq64be[7] = (unsigned char)seq;\n item = pqueue_find(s->d1->sent_messages, seq64be);\n if (item == NULL) {\n fprintf(stderr, "retransmit: message %d non-existant\\n", seq);\n *found = 0;\n return 0;\n }\n *found = 1;\n frag = (hm_fragment *)item->data;\n if (frag->msg_header.is_ccs)\n header_length = DTLS1_CCS_HEADER_LENGTH;\n else\n header_length = DTLS1_HM_HEADER_LENGTH;\n memcpy(s->init_buf->data, frag->fragment,\n frag->msg_header.msg_len + header_length);\n s->init_num = frag->msg_header.msg_len + header_length;\n dtls1_set_message_header_int(s, frag->msg_header.type,\n frag->msg_header.msg_len,\n frag->msg_header.seq, 0,\n frag->msg_header.frag_len);\n saved_state.enc_write_ctx = s->enc_write_ctx;\n saved_state.write_hash = s->write_hash;\n saved_state.compress = s->compress;\n saved_state.session = s->session;\n saved_state.epoch = DTLS_RECORD_LAYER_get_w_epoch(&s->rlayer);\n s->d1->retransmitting = 1;\n s->enc_write_ctx = frag->msg_header.saved_retransmit_state.enc_write_ctx;\n s->write_hash = frag->msg_header.saved_retransmit_state.write_hash;\n s->compress = frag->msg_header.saved_retransmit_state.compress;\n s->session = frag->msg_header.saved_retransmit_state.session;\n DTLS_RECORD_LAYER_set_saved_w_epoch(&s->rlayer,\n frag->msg_header.saved_retransmit_state.epoch);\n ret = dtls1_do_write(s, frag->msg_header.is_ccs ?\n SSL3_RT_CHANGE_CIPHER_SPEC : SSL3_RT_HANDSHAKE);\n s->enc_write_ctx = saved_state.enc_write_ctx;\n s->write_hash = saved_state.write_hash;\n s->compress = saved_state.compress;\n s->session = saved_state.session;\n DTLS_RECORD_LAYER_set_saved_w_epoch(&s->rlayer, saved_state.epoch);\n s->d1->retransmitting = 0;\n (void)BIO_flush(SSL_get_wbio(s));\n return ret;\n}', 'int dtls1_do_write(SSL *s, int type)\n{\n int ret;\n unsigned int curr_mtu;\n int retry = 1;\n unsigned int len, frag_off, mac_size, blocksize, used_len;\n if (!dtls1_query_mtu(s))\n return -1;\n if (s->d1->mtu < dtls1_min_mtu(s))\n return -1;\n if (s->init_off == 0 && type == SSL3_RT_HANDSHAKE)\n OPENSSL_assert(s->init_num ==\n (int)s->d1->w_msg_hdr.msg_len +\n DTLS1_HM_HEADER_LENGTH);\n if (s->write_hash) {\n if (s->enc_write_ctx\n && (EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(s->enc_write_ctx)) &\n EVP_CIPH_FLAG_AEAD_CIPHER) != 0)\n mac_size = 0;\n else\n mac_size = EVP_MD_CTX_size(s->write_hash);\n } else\n mac_size = 0;\n if (s->enc_write_ctx &&\n (EVP_CIPHER_CTX_mode(s->enc_write_ctx) == EVP_CIPH_CBC_MODE))\n blocksize = 2 * EVP_CIPHER_CTX_block_size(s->enc_write_ctx);\n else\n blocksize = 0;\n frag_off = 0;\n s->rwstate = SSL_NOTHING;\n while (s->init_num > 0) {\n if (type == SSL3_RT_HANDSHAKE && s->init_off != 0) {\n if (frag_off > 0) {\n if (s->init_off <= DTLS1_HM_HEADER_LENGTH) {\n return -1;\n }\n s->init_off -= DTLS1_HM_HEADER_LENGTH;\n s->init_num += DTLS1_HM_HEADER_LENGTH;\n } else {\n frag_off = s->d1->w_msg_hdr.frag_off;\n }\n }\n used_len = BIO_wpending(SSL_get_wbio(s)) + DTLS1_RT_HEADER_LENGTH\n + mac_size + blocksize;\n if (s->d1->mtu > used_len)\n curr_mtu = s->d1->mtu - used_len;\n else\n curr_mtu = 0;\n if (curr_mtu <= DTLS1_HM_HEADER_LENGTH) {\n ret = BIO_flush(SSL_get_wbio(s));\n if (ret <= 0) {\n s->rwstate = SSL_WRITING;\n return ret;\n }\n used_len = DTLS1_RT_HEADER_LENGTH + mac_size + blocksize;\n if (s->d1->mtu > used_len + DTLS1_HM_HEADER_LENGTH) {\n curr_mtu = s->d1->mtu - used_len;\n } else {\n return -1;\n }\n }\n if (((unsigned int)s->init_num) > curr_mtu)\n len = curr_mtu;\n else\n len = s->init_num;\n if (len > INT_MAX)\n len = INT_MAX;\n if (type == SSL3_RT_HANDSHAKE) {\n if (len < DTLS1_HM_HEADER_LENGTH) {\n return -1;\n }\n dtls1_fix_message_header(s, frag_off,\n len - DTLS1_HM_HEADER_LENGTH);\n dtls1_write_message_header(s,\n (unsigned char *)&s->init_buf->\n data[s->init_off]);\n }\n ret = dtls1_write_bytes(s, type, &s->init_buf->data[s->init_off],\n len);\n if (ret < 0) {\n if (retry && BIO_ctrl(SSL_get_wbio(s),\n BIO_CTRL_DGRAM_MTU_EXCEEDED, 0, NULL) > 0) {\n if (!(SSL_get_options(s) & SSL_OP_NO_QUERY_MTU)) {\n if (!dtls1_query_mtu(s))\n return -1;\n retry = 0;\n } else\n return -1;\n } else {\n return (-1);\n }\n } else {\n OPENSSL_assert(len == (unsigned int)ret);\n if (type == SSL3_RT_HANDSHAKE && !s->d1->retransmitting) {\n unsigned char *p =\n (unsigned char *)&s->init_buf->data[s->init_off];\n const struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr;\n int xlen;\n if (frag_off == 0 && s->version != DTLS1_BAD_VER) {\n *p++ = msg_hdr->type;\n l2n3(msg_hdr->msg_len, p);\n s2n(msg_hdr->seq, p);\n l2n3(0, p);\n l2n3(msg_hdr->msg_len, p);\n p -= DTLS1_HM_HEADER_LENGTH;\n xlen = ret;\n } else {\n p += DTLS1_HM_HEADER_LENGTH;\n xlen = ret - DTLS1_HM_HEADER_LENGTH;\n }\n ssl3_finish_mac(s, p, xlen);\n }\n if (ret == s->init_num) {\n if (s->msg_callback)\n s->msg_callback(1, s->version, type, s->init_buf->data,\n (size_t)(s->init_off + s->init_num), s,\n s->msg_callback_arg);\n s->init_off = 0;\n s->init_num = 0;\n return (1);\n }\n s->init_off += ret;\n s->init_num -= ret;\n ret -= DTLS1_HM_HEADER_LENGTH;\n frag_off += ret;\n dtls1_fix_message_header(s, frag_off, 0);\n }\n }\n return (0);\n}', 'int dtls1_write_bytes(SSL *s, int type, const void *buf, int len)\n{\n int i;\n OPENSSL_assert(len <= SSL3_RT_MAX_PLAIN_LENGTH);\n s->rwstate = SSL_NOTHING;\n i = do_dtls1_write(s, type, buf, len, 0);\n return i;\n}', 'int do_dtls1_write(SSL *s, int type, const unsigned char *buf,\n unsigned int len, int create_empty_fragment)\n{\n unsigned char *p, *pseq;\n int i, mac_size, clear = 0;\n int prefix_len = 0;\n int eivlen;\n SSL3_RECORD wr;\n SSL3_BUFFER *wb;\n SSL_SESSION *sess;\n wb = &s->rlayer.wbuf[0];\n if (SSL3_BUFFER_get_left(wb) != 0) {\n OPENSSL_assert(0);\n return (ssl3_write_pending(s, type, buf, len));\n }\n if (s->s3->alert_dispatch) {\n i = s->method->ssl_dispatch_alert(s);\n if (i <= 0)\n return (i);\n }\n if (len == 0 && !create_empty_fragment)\n return 0;\n sess = s->session;\n if ((sess == NULL) ||\n (s->enc_write_ctx == NULL) || (EVP_MD_CTX_md(s->write_hash) == NULL))\n clear = 1;\n if (clear)\n mac_size = 0;\n else {\n mac_size = EVP_MD_CTX_size(s->write_hash);\n if (mac_size < 0)\n goto err;\n }\n p = SSL3_BUFFER_get_buf(wb) + prefix_len;\n *(p++) = type & 0xff;\n SSL3_RECORD_set_type(&wr, type);\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 pseq = p;\n p += 10;\n if (s->enc_write_ctx) {\n int mode = EVP_CIPHER_CTX_mode(s->enc_write_ctx);\n if (mode == EVP_CIPH_CBC_MODE) {\n eivlen = EVP_CIPHER_CTX_iv_length(s->enc_write_ctx);\n if (eivlen <= 1)\n eivlen = 0;\n }\n else if (mode == EVP_CIPH_GCM_MODE)\n eivlen = EVP_GCM_TLS_EXPLICIT_IV_LEN;\n else if (mode == EVP_CIPH_CCM_MODE)\n eivlen = EVP_CCM_TLS_EXPLICIT_IV_LEN;\n else\n eivlen = 0;\n } else\n eivlen = 0;\n SSL3_RECORD_set_data(&wr, p + eivlen);\n SSL3_RECORD_set_length(&wr, (int)len);\n SSL3_RECORD_set_input(&wr, (unsigned char *)buf);\n if (s->compress != NULL) {\n if (!ssl3_do_compress(s, &wr)) {\n SSLerr(SSL_F_DO_DTLS1_WRITE, SSL_R_COMPRESSION_FAILURE);\n goto err;\n }\n } else {\n memcpy(SSL3_RECORD_get_data(&wr), SSL3_RECORD_get_input(&wr),\n SSL3_RECORD_get_length(&wr));\n SSL3_RECORD_reset_input(&wr);\n }\n if (mac_size != 0) {\n if (s->method->ssl3_enc->mac(s, &wr,\n &(p[SSL3_RECORD_get_length(&wr) + eivlen]), 1) < 0)\n goto err;\n SSL3_RECORD_add_length(&wr, mac_size);\n }\n SSL3_RECORD_set_data(&wr, p);\n SSL3_RECORD_reset_input(&wr);\n if (eivlen)\n SSL3_RECORD_add_length(&wr, eivlen);\n if (s->method->ssl3_enc->enc(s, &wr, 1, 1) < 1)\n goto err;\n s2n(s->rlayer.d->w_epoch, pseq);\n memcpy(pseq, &(s->rlayer.write_sequence[2]), 6);\n pseq += 6;\n s2n(SSL3_RECORD_get_length(&wr), pseq);\n if (s->msg_callback)\n s->msg_callback(1, 0, SSL3_RT_HEADER, pseq - DTLS1_RT_HEADER_LENGTH,\n DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);\n SSL3_RECORD_set_type(&wr, type);\n SSL3_RECORD_add_length(&wr, DTLS1_RT_HEADER_LENGTH);\n ssl3_record_sequence_update(&(s->rlayer.write_sequence[0]));\n if (create_empty_fragment) {\n return wr.length;\n }\n SSL3_BUFFER_set_left(wb, prefix_len + SSL3_RECORD_get_length(&wr));\n SSL3_BUFFER_set_offset(wb, 0);\n s->rlayer.wpend_tot = len;\n s->rlayer.wpend_buf = buf;\n s->rlayer.wpend_type = type;\n s->rlayer.wpend_ret = len;\n return ssl3_write_pending(s, type, buf, len);\n err:\n return -1;\n}', 'int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,\n unsigned int len)\n{\n int i;\n SSL3_BUFFER *wb = s->rlayer.wbuf;\n unsigned int currbuf = 0;\n if ((s->rlayer.wpend_tot > (int)len)\n || ((s->rlayer.wpend_buf != buf) &&\n !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER))\n || (s->rlayer.wpend_type != type)) {\n SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BAD_WRITE_RETRY);\n return (-1);\n }\n for (;;) {\n if (SSL3_BUFFER_get_left(&wb[currbuf]) == 0\n && currbuf < s->rlayer.numwpipes - 1) {\n currbuf++;\n continue;\n }\n clear_sys_error();\n if (s->wbio != NULL) {\n s->rwstate = SSL_WRITING;\n i = BIO_write(s->wbio,\n (char *)&(SSL3_BUFFER_get_buf(&wb[currbuf])[\n SSL3_BUFFER_get_offset(&wb[currbuf])]),\n (unsigned int)SSL3_BUFFER_get_left(&wb[currbuf]));\n } else {\n SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BIO_NOT_SET);\n i = -1;\n }\n if (i == SSL3_BUFFER_get_left(&wb[currbuf])) {\n SSL3_BUFFER_set_left(&wb[currbuf], 0);\n SSL3_BUFFER_add_offset(&wb[currbuf], i);\n if (currbuf + 1 < s->rlayer.numwpipes)\n continue;\n s->rwstate = SSL_NOTHING;\n return (s->rlayer.wpend_ret);\n } else if (i <= 0) {\n if (SSL_IS_DTLS(s)) {\n SSL3_BUFFER_set_left(&wb[currbuf], 0);\n }\n return (i);\n }\n SSL3_BUFFER_add_offset(&wb[currbuf], i);\n SSL3_BUFFER_add_left(&wb[currbuf], -i);\n }\n}']
33,549
0
https://github.com/openssl/openssl/blob/d16765919d78a576425272adc0c3fb0b493b1198/crypto/lhash/lhash.c/#L281
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 SSL *doConnection(SSL *scon)\n\t{\n\tBIO *conn;\n\tSSL *serverCon;\n\tint width, i;\n\tfd_set readfds;\n\tif ((conn=BIO_new(BIO_s_connect())) == NULL)\n\t\treturn(NULL);\n\tBIO_set_conn_hostname(conn,host);\n\tif (scon == NULL)\n\t\tserverCon=SSL_new(tm_ctx);\n\telse\n\t\t{\n\t\tserverCon=scon;\n\t\tSSL_set_connect_state(serverCon);\n\t\t}\n\tSSL_set_bio(serverCon,conn,conn);\n#if 0\n\tif( scon != NULL )\n\t\tSSL_set_session(serverCon,SSL_get_session(scon));\n#endif\n\tfor(;;) {\n\t\ti=SSL_connect(serverCon);\n\t\tif (BIO_sock_should_retry(i))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"DELAY\\n");\n\t\t\ti=SSL_get_fd(serverCon);\n\t\t\twidth=i+1;\n\t\t\tFD_ZERO(&readfds);\n\t\t\topenssl_fdset(i,&readfds);\n\t\t\tselect(width,(void *)&readfds,NULL,NULL,NULL);\n\t\t\tcontinue;\n\t\t\t}\n\t\tbreak;\n\t\t}\n\tif(i <= 0)\n\t\t{\n\t\tBIO_printf(bio_err,"ERROR\\n");\n\t\tif (verify_error != X509_V_OK)\n\t\t\tBIO_printf(bio_err,"verify error:%s\\n",\n\t\t\t\tX509_verify_cert_error_string(verify_error));\n\t\telse\n\t\t\tERR_print_errors(bio_err);\n\t\tif (scon == NULL)\n\t\t\tSSL_free(serverCon);\n\t\treturn NULL;\n\t\t}\n\treturn serverCon;\n\t}', 'SSL *SSL_new(SSL_CTX *ctx)\n\t{\n\tSSL *s;\n\tif (ctx == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);\n\t\treturn(NULL);\n\t\t}\n\tif (ctx->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n\t\treturn(NULL);\n\t\t}\n\ts=(SSL *)OPENSSL_malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\n#ifndef\tOPENSSL_NO_KRB5\n\ts->kssl_ctx = kssl_ctx_new();\n#endif\n\ts->options=ctx->options;\n\ts->mode=ctx->mode;\n\ts->max_cert_list=ctx->max_cert_list;\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->read_ahead=ctx->read_ahead;\n\ts->msg_callback=ctx->msg_callback;\n\ts->msg_callback_arg=ctx->msg_callback_arg;\n\ts->verify_mode=ctx->verify_mode;\n\ts->not_resumable_session_cb=ctx->not_resumable_session_cb;\n#if 0\n\ts->verify_depth=ctx->verify_depth;\n#endif\n\ts->sid_ctx_length=ctx->sid_ctx_length;\n\tOPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);\n\tmemcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));\n\ts->verify_callback=ctx->default_verify_callback;\n\ts->generate_session_id=ctx->generate_session_id;\n\ts->param = X509_VERIFY_PARAM_new();\n\tif (!s->param)\n\t\tgoto err;\n\tX509_VERIFY_PARAM_inherit(s->param, ctx->param);\n#if 0\n\ts->purpose = ctx->purpose;\n\ts->trust = ctx->trust;\n#endif\n\ts->quiet_shutdown=ctx->quiet_shutdown;\n\ts->max_send_fragment = ctx->max_send_fragment;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->ctx=ctx;\n#ifndef OPENSSL_NO_TLSEXT\n\ts->tlsext_debug_cb = 0;\n\ts->tlsext_debug_arg = NULL;\n\ts->tlsext_ticket_expected = 0;\n\ts->tlsext_status_type = -1;\n\ts->tlsext_status_expected = 0;\n\ts->tlsext_ocsp_ids = NULL;\n\ts->tlsext_ocsp_exts = NULL;\n\ts->tlsext_ocsp_resp = NULL;\n\ts->tlsext_ocsp_resplen = -1;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->initial_ctx=ctx;\n# ifndef OPENSSL_NO_NEXTPROTONEG\n\ts->next_proto_negotiated = NULL;\n# endif\n#endif\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->references=1;\n\ts->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;\n\tSSL_clear(s);\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n#ifndef OPENSSL_NO_PSK\n\ts->psk_client_callback=ctx->psk_client_callback;\n\ts->psk_server_callback=ctx->psk_server_callback;\n#endif\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}', 'void SSL_free(SSL *s)\n\t{\n\tint i;\n\tif(s == NULL)\n\t return;\n\ti=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL);\n#ifdef REF_PRINT\n\tREF_PRINT("SSL",s);\n#endif\n\tif (i > 0) return;\n#ifdef REF_CHECK\n\tif (i < 0)\n\t\t{\n\t\tfprintf(stderr,"SSL_free, bad reference count\\n");\n\t\tabort();\n\t\t}\n#endif\n\tif (s->param)\n\t\tX509_VERIFY_PARAM_free(s->param);\n\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n\tif (s->bbio != NULL)\n\t\t{\n\t\tif (s->bbio == s->wbio)\n\t\t\t{\n\t\t\ts->wbio=BIO_pop(s->wbio);\n\t\t\t}\n\t\tBIO_free(s->bbio);\n\t\ts->bbio=NULL;\n\t\t}\n\tif (s->rbio != NULL)\n\t\tBIO_free_all(s->rbio);\n\tif ((s->wbio != NULL) && (s->wbio != s->rbio))\n\t\tBIO_free_all(s->wbio);\n\tif (s->init_buf != NULL) BUF_MEM_free(s->init_buf);\n\tif (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list);\n\tif (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id);\n\tif (s->session != NULL)\n\t\t{\n\t\tssl_clear_bad_session(s);\n\t\tSSL_SESSION_free(s->session);\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\tssl_clear_hash_ctx(&s->read_hash);\n\tssl_clear_hash_ctx(&s->write_hash);\n\tif (s->cert != NULL) ssl_cert_free(s->cert);\n#ifndef OPENSSL_NO_TLSEXT\n\tif (s->tlsext_hostname)\n\t\tOPENSSL_free(s->tlsext_hostname);\n\tif (s->initial_ctx) SSL_CTX_free(s->initial_ctx);\n#ifndef OPENSSL_NO_EC\n\tif (s->tlsext_ecpointformatlist) OPENSSL_free(s->tlsext_ecpointformatlist);\n\tif (s->tlsext_ellipticcurvelist) OPENSSL_free(s->tlsext_ellipticcurvelist);\n#endif\n\tif (s->tlsext_opaque_prf_input) OPENSSL_free(s->tlsext_opaque_prf_input);\n\tif (s->tlsext_ocsp_exts)\n\t\tsk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts,\n\t\t\t\t\t\tX509_EXTENSION_free);\n\tif (s->tlsext_ocsp_ids)\n\t\tsk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);\n\tif (s->tlsext_ocsp_resp)\n\t\tOPENSSL_free(s->tlsext_ocsp_resp);\n#endif\n\tif (s->client_CA != NULL)\n\t\tsk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);\n\tif (s->method != NULL) s->method->ssl_free(s);\n\tif (s->ctx) SSL_CTX_free(s->ctx);\n#ifndef\tOPENSSL_NO_KRB5\n\tif (s->kssl_ctx != NULL)\n\t\tkssl_ctx_free(s->kssl_ctx);\n#endif\n#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)\n\tif (s->next_proto_negotiated)\n\t\tOPENSSL_free(s->next_proto_negotiated);\n#endif\n\tOPENSSL_free(s);\n\t}', 'void SSL_CTX_free(SSL_CTX *a)\n\t{\n\tint i;\n\tif (a == NULL) return;\n\ti=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);\n#ifdef REF_PRINT\n\tREF_PRINT("SSL_CTX",a);\n#endif\n\tif (i > 0) return;\n#ifdef REF_CHECK\n\tif (i < 0)\n\t\t{\n\t\tfprintf(stderr,"SSL_CTX_free, bad reference count\\n");\n\t\tabort();\n\t\t}\n#endif\n\tif (a->param)\n\t\tX509_VERIFY_PARAM_free(a->param);\n\tif (a->sessions != NULL)\n\t\tSSL_CTX_flush_sessions(a,0);\n\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n\tif (a->sessions != NULL)\n\t\tlh_SSL_SESSION_free(a->sessions);\n\tif (a->cert_store != NULL)\n\t\tX509_STORE_free(a->cert_store);\n\tif (a->cipher_list != NULL)\n\t\tsk_SSL_CIPHER_free(a->cipher_list);\n\tif (a->cipher_list_by_id != NULL)\n\t\tsk_SSL_CIPHER_free(a->cipher_list_by_id);\n\tif (a->cert != NULL)\n\t\tssl_cert_free(a->cert);\n\tif (a->client_CA != NULL)\n\t\tsk_X509_NAME_pop_free(a->client_CA,X509_NAME_free);\n\tif (a->extra_certs != NULL)\n\t\tsk_X509_pop_free(a->extra_certs,X509_free);\n#if 0\n\tif (a->comp_methods != NULL)\n\t\tsk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);\n#else\n\ta->comp_methods = NULL;\n#endif\n#ifndef OPENSSL_NO_PSK\n\tif (a->psk_identity_hint)\n\t\tOPENSSL_free(a->psk_identity_hint);\n#endif\n#ifndef OPENSSL_NO_SRP\n\tSSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n\tif (a->client_cert_engine)\n\t\tENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_BUF_FREELISTS\n\tif (a->wbuf_freelist)\n\t\tssl_buf_freelist_free(a->wbuf_freelist);\n\tif (a->rbuf_freelist)\n\t\tssl_buf_freelist_free(a->rbuf_freelist);\n#endif\n\tOPENSSL_free(a);\n\t}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n\t{\n\tunsigned long i;\n\tTIMEOUT_PARAM tp;\n\ttp.ctx=s;\n\ttp.cache=s->sessions;\n\tif (tp.cache == NULL) return;\n\ttp.time=t;\n\tCRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\ti=CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load;\n\tCHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load=0;\n\tlh_SSL_SESSION_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout),\n\t\t\t\t TIMEOUT_PARAM, &tp);\n\tCHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load=i;\n\tCRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t}', 'void lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)\n\t{\n\tdoall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);\n\t}', 'static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,\n\t\t\t LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)\n\t{\n\tint i;\n\tLHASH_NODE *a,*n;\n\tif (lh == NULL)\n\t\treturn;\n\tfor (i=lh->num_nodes-1; i>=0; i--)\n\t\t{\n\t\ta=lh->b[i];\n\t\twhile (a != NULL)\n\t\t\t{\n\t\t\tn=a->next;\n\t\t\tif(use_arg)\n\t\t\t\tfunc_arg(a->data,arg);\n\t\t\telse\n\t\t\t\tfunc(a->data);\n\t\t\ta=n;\n\t\t\t}\n\t\t}\n\t}']
33,550
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavformat/mpeg.c/#L311
static int mpegps_read_pes_header(AVFormatContext *s, int64_t *ppos, int *pstart_code, int64_t *ppts, int64_t *pdts) { MpegDemuxContext *m = s->priv_data; int len, size, startcode, c, flags, header_len; int pes_ext, ext2_len, id_ext, skip; int64_t pts, dts; int64_t last_sync= url_ftell(s->pb); error_redo: url_fseek(s->pb, last_sync, SEEK_SET); redo: m->header_state = 0xff; size = MAX_SYNC_SIZE; startcode = find_next_start_code(s->pb, &size, &m->header_state); last_sync = url_ftell(s->pb); if (startcode < 0) return AVERROR(EIO); if (startcode == PACK_START_CODE) goto redo; if (startcode == SYSTEM_HEADER_START_CODE) goto redo; if (startcode == PADDING_STREAM) { url_fskip(s->pb, get_be16(s->pb)); goto redo; } if (startcode == PRIVATE_STREAM_2) { len = get_be16(s->pb); if (!m->sofdec) { while (len-- >= 6) { if (get_byte(s->pb) == 'S') { uint8_t buf[5]; get_buffer(s->pb, buf, sizeof(buf)); m->sofdec = !memcmp(buf, "ofdec", 5); len -= sizeof(buf); break; } } m->sofdec -= !m->sofdec; } url_fskip(s->pb, len); goto redo; } if (startcode == PROGRAM_STREAM_MAP) { mpegps_psm_parse(m, s->pb); goto redo; } if (!((startcode >= 0x1c0 && startcode <= 0x1df) || (startcode >= 0x1e0 && startcode <= 0x1ef) || (startcode == 0x1bd) || (startcode == 0x1fd))) goto redo; if (ppos) { *ppos = url_ftell(s->pb) - 4; } len = get_be16(s->pb); pts = dts = AV_NOPTS_VALUE; for(;;) { if (len < 1) goto error_redo; c = get_byte(s->pb); len--; if (c != 0xff) break; } if ((c & 0xc0) == 0x40) { get_byte(s->pb); c = get_byte(s->pb); len -= 2; } if ((c & 0xe0) == 0x20) { dts = pts = get_pts(s->pb, c); len -= 4; if (c & 0x10){ dts = get_pts(s->pb, -1); len -= 5; } } else if ((c & 0xc0) == 0x80) { #if 0 if ((c & 0x30) != 0) { goto redo; } #endif flags = get_byte(s->pb); header_len = get_byte(s->pb); len -= 2; if (header_len > len) goto error_redo; len -= header_len; if (flags & 0x80) { dts = pts = get_pts(s->pb, -1); header_len -= 5; if (flags & 0x40) { dts = get_pts(s->pb, -1); header_len -= 5; } } if (flags & 0x3f && header_len == 0){ flags &= 0xC0; av_log(s, AV_LOG_WARNING, "Further flags set but no bytes left\n"); } if (flags & 0x01) { pes_ext = get_byte(s->pb); header_len--; if (pes_ext & 0x40) { goto error_redo; } skip = (pes_ext >> 4) & 0xb; skip += skip & 0x9; url_fskip(s->pb, skip); header_len -= skip; if (pes_ext & 0x01) { ext2_len = get_byte(s->pb); header_len--; if ((ext2_len & 0x7f) > 0) { id_ext = get_byte(s->pb); if ((id_ext & 0x80) == 0) startcode = ((startcode & 0xff) << 8) | id_ext; header_len--; } } } if(header_len < 0) goto error_redo; url_fskip(s->pb, header_len); } else if( c!= 0xf ) goto redo; if (startcode == PRIVATE_STREAM_1 && !m->psm_es_type[startcode & 0xff]) { startcode = get_byte(s->pb); len--; if (startcode >= 0x80 && startcode <= 0xcf) { get_byte(s->pb); get_byte(s->pb); get_byte(s->pb); len -= 3; if (startcode >= 0xb0 && startcode <= 0xbf) { get_byte(s->pb); len--; } } } if(len<0) goto error_redo; if(dts != AV_NOPTS_VALUE && ppos){ int i; for(i=0; i<s->nb_streams; i++){ if(startcode == s->streams[i]->id && !url_is_streamed(s->pb) ) { ff_reduce_index(s, i); av_add_index_entry(s->streams[i], *ppos, dts, 0, 0, AVINDEX_KEYFRAME ); } } } *pstart_code = startcode; *ppts = pts; *pdts = dts; return len; }
['static int mpegps_read_pes_header(AVFormatContext *s,\n int64_t *ppos, int *pstart_code,\n int64_t *ppts, int64_t *pdts)\n{\n MpegDemuxContext *m = s->priv_data;\n int len, size, startcode, c, flags, header_len;\n int pes_ext, ext2_len, id_ext, skip;\n int64_t pts, dts;\n int64_t last_sync= url_ftell(s->pb);\n error_redo:\n url_fseek(s->pb, last_sync, SEEK_SET);\n redo:\n m->header_state = 0xff;\n size = MAX_SYNC_SIZE;\n startcode = find_next_start_code(s->pb, &size, &m->header_state);\n last_sync = url_ftell(s->pb);\n if (startcode < 0)\n return AVERROR(EIO);\n if (startcode == PACK_START_CODE)\n goto redo;\n if (startcode == SYSTEM_HEADER_START_CODE)\n goto redo;\n if (startcode == PADDING_STREAM) {\n url_fskip(s->pb, get_be16(s->pb));\n goto redo;\n }\n if (startcode == PRIVATE_STREAM_2) {\n len = get_be16(s->pb);\n if (!m->sofdec) {\n while (len-- >= 6) {\n if (get_byte(s->pb) == \'S\') {\n uint8_t buf[5];\n get_buffer(s->pb, buf, sizeof(buf));\n m->sofdec = !memcmp(buf, "ofdec", 5);\n len -= sizeof(buf);\n break;\n }\n }\n m->sofdec -= !m->sofdec;\n }\n url_fskip(s->pb, len);\n goto redo;\n }\n if (startcode == PROGRAM_STREAM_MAP) {\n mpegps_psm_parse(m, s->pb);\n goto redo;\n }\n if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||\n (startcode >= 0x1e0 && startcode <= 0x1ef) ||\n (startcode == 0x1bd) || (startcode == 0x1fd)))\n goto redo;\n if (ppos) {\n *ppos = url_ftell(s->pb) - 4;\n }\n len = get_be16(s->pb);\n pts =\n dts = AV_NOPTS_VALUE;\n for(;;) {\n if (len < 1)\n goto error_redo;\n c = get_byte(s->pb);\n len--;\n if (c != 0xff)\n break;\n }\n if ((c & 0xc0) == 0x40) {\n get_byte(s->pb);\n c = get_byte(s->pb);\n len -= 2;\n }\n if ((c & 0xe0) == 0x20) {\n dts = pts = get_pts(s->pb, c);\n len -= 4;\n if (c & 0x10){\n dts = get_pts(s->pb, -1);\n len -= 5;\n }\n } else if ((c & 0xc0) == 0x80) {\n#if 0\n if ((c & 0x30) != 0) {\n goto redo;\n }\n#endif\n flags = get_byte(s->pb);\n header_len = get_byte(s->pb);\n len -= 2;\n if (header_len > len)\n goto error_redo;\n len -= header_len;\n if (flags & 0x80) {\n dts = pts = get_pts(s->pb, -1);\n header_len -= 5;\n if (flags & 0x40) {\n dts = get_pts(s->pb, -1);\n header_len -= 5;\n }\n }\n if (flags & 0x3f && header_len == 0){\n flags &= 0xC0;\n av_log(s, AV_LOG_WARNING, "Further flags set but no bytes left\\n");\n }\n if (flags & 0x01) {\n pes_ext = get_byte(s->pb);\n header_len--;\n if (pes_ext & 0x40) {\n goto error_redo;\n }\n skip = (pes_ext >> 4) & 0xb;\n skip += skip & 0x9;\n url_fskip(s->pb, skip);\n header_len -= skip;\n if (pes_ext & 0x01) {\n ext2_len = get_byte(s->pb);\n header_len--;\n if ((ext2_len & 0x7f) > 0) {\n id_ext = get_byte(s->pb);\n if ((id_ext & 0x80) == 0)\n startcode = ((startcode & 0xff) << 8) | id_ext;\n header_len--;\n }\n }\n }\n if(header_len < 0)\n goto error_redo;\n url_fskip(s->pb, header_len);\n }\n else if( c!= 0xf )\n goto redo;\n if (startcode == PRIVATE_STREAM_1 && !m->psm_es_type[startcode & 0xff]) {\n startcode = get_byte(s->pb);\n len--;\n if (startcode >= 0x80 && startcode <= 0xcf) {\n get_byte(s->pb);\n get_byte(s->pb);\n get_byte(s->pb);\n len -= 3;\n if (startcode >= 0xb0 && startcode <= 0xbf) {\n get_byte(s->pb);\n len--;\n }\n }\n }\n if(len<0)\n goto error_redo;\n if(dts != AV_NOPTS_VALUE && ppos){\n int i;\n for(i=0; i<s->nb_streams; i++){\n if(startcode == s->streams[i]->id &&\n !url_is_streamed(s->pb) ) {\n ff_reduce_index(s, i);\n av_add_index_entry(s->streams[i], *ppos, dts, 0, 0, AVINDEX_KEYFRAME );\n }\n }\n }\n *pstart_code = startcode;\n *ppts = pts;\n *pdts = dts;\n return len;\n}']
33,551
0
https://github.com/libav/libav/blob/4be368b504c6f4a03051448728fc62cd0ed506b2/libavcodec/utils.c/#L1574
size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag) { int i, len, ret = 0; #define TAG_PRINT(x) \ (((x) >= '0' && (x) <= '9') || \ ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \ ((x) == '.' || (x) == ' ')) for (i = 0; i < 4; i++) { len = snprintf(buf, buf_size, TAG_PRINT(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF); buf += len; buf_size = buf_size > len ? buf_size - len : 0; ret += len; codec_tag >>= 8; } return ret; }
['void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)\n{\n const char *codec_name;\n const char *profile = NULL;\n const AVCodec *p;\n char buf1[32];\n int bitrate;\n AVRational display_aspect_ratio;\n if (enc->codec)\n p = enc->codec;\n else if (encode)\n p = avcodec_find_encoder(enc->codec_id);\n else\n p = avcodec_find_decoder(enc->codec_id);\n if (p) {\n codec_name = p->name;\n profile = av_get_profile_name(p, enc->profile);\n } else if (enc->codec_id == AV_CODEC_ID_MPEG2TS) {\n codec_name = "mpeg2ts";\n } else if (enc->codec_name[0] != \'\\0\') {\n codec_name = enc->codec_name;\n } else {\n char tag_buf[32];\n av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);\n snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);\n codec_name = buf1;\n }\n switch (enc->codec_type) {\n case AVMEDIA_TYPE_VIDEO:\n snprintf(buf, buf_size,\n "Video: %s%s",\n codec_name, enc->mb_decision ? " (hq)" : "");\n if (profile)\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n " (%s)", profile);\n if (enc->pix_fmt != AV_PIX_FMT_NONE) {\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n ", %s",\n av_get_pix_fmt_name(enc->pix_fmt));\n }\n if (enc->width) {\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n ", %dx%d",\n enc->width, enc->height);\n if (enc->sample_aspect_ratio.num) {\n av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,\n enc->width * enc->sample_aspect_ratio.num,\n enc->height * enc->sample_aspect_ratio.den,\n 1024 * 1024);\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n " [PAR %d:%d DAR %d:%d]",\n enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,\n display_aspect_ratio.num, display_aspect_ratio.den);\n }\n if (av_log_get_level() >= AV_LOG_DEBUG) {\n int g = av_gcd(enc->time_base.num, enc->time_base.den);\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n ", %d/%d",\n enc->time_base.num / g, enc->time_base.den / g);\n }\n }\n if (encode) {\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n ", q=%d-%d", enc->qmin, enc->qmax);\n }\n break;\n case AVMEDIA_TYPE_AUDIO:\n snprintf(buf, buf_size,\n "Audio: %s",\n codec_name);\n if (profile)\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n " (%s)", profile);\n if (enc->sample_rate) {\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n ", %d Hz", enc->sample_rate);\n }\n av_strlcat(buf, ", ", buf_size);\n av_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);\n if (enc->sample_fmt != AV_SAMPLE_FMT_NONE) {\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n ", %s", av_get_sample_fmt_name(enc->sample_fmt));\n }\n break;\n case AVMEDIA_TYPE_DATA:\n snprintf(buf, buf_size, "Data: %s", codec_name);\n break;\n case AVMEDIA_TYPE_SUBTITLE:\n snprintf(buf, buf_size, "Subtitle: %s", codec_name);\n break;\n case AVMEDIA_TYPE_ATTACHMENT:\n snprintf(buf, buf_size, "Attachment: %s", codec_name);\n break;\n default:\n snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);\n return;\n }\n if (encode) {\n if (enc->flags & CODEC_FLAG_PASS1)\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n ", pass 1");\n if (enc->flags & CODEC_FLAG_PASS2)\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n ", pass 2");\n }\n bitrate = get_bit_rate(enc);\n if (bitrate != 0) {\n snprintf(buf + strlen(buf), buf_size - strlen(buf),\n ", %d kb/s", bitrate / 1000);\n }\n}', 'size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)\n{\n int i, len, ret = 0;\n#define TAG_PRINT(x) \\\n (((x) >= \'0\' && (x) <= \'9\') || \\\n ((x) >= \'a\' && (x) <= \'z\') || ((x) >= \'A\' && (x) <= \'Z\') || \\\n ((x) == \'.\' || (x) == \' \'))\n for (i = 0; i < 4; i++) {\n len = snprintf(buf, buf_size,\n TAG_PRINT(codec_tag & 0xFF) ? "%c" : "[%d]", codec_tag & 0xFF);\n buf += len;\n buf_size = buf_size > len ? buf_size - len : 0;\n ret += len;\n codec_tag >>= 8;\n }\n return ret;\n}']
33,552
0
https://github.com/libav/libav/blob/d9c6eece21dfecb510e33738092f7a43fc7d36f8/libavformat/cutils.c/#L41
void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem) { int nb, nb_alloc; intptr_t *tab; nb = *nb_ptr; tab = *tab_ptr; if ((nb & (nb - 1)) == 0) { if (nb == 0) nb_alloc = 1; else nb_alloc = nb * 2; tab = av_realloc(tab, nb_alloc * sizeof(intptr_t)); *tab_ptr = tab; } tab[nb++] = elem; *nb_ptr = nb; }
['void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem)\n{\n int nb, nb_alloc;\n intptr_t *tab;\n nb = *nb_ptr;\n tab = *tab_ptr;\n if ((nb & (nb - 1)) == 0) {\n if (nb == 0)\n nb_alloc = 1;\n else\n nb_alloc = nb * 2;\n tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));\n *tab_ptr = tab;\n }\n tab[nb++] = elem;\n *nb_ptr = nb;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if(!ptr) return av_malloc(size);\n diff= ((char*)ptr)[-1];\n return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#else\n return realloc(ptr, size);\n#endif\n}']
33,553
0
https://github.com/libav/libav/blob/cb2c4de3a16c083973921587b6e8c79af59c9626/libavcodec/vc1dec.c/#L1620
static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, int mv1, int r_x, int r_y, uint8_t* is_intra, int pred_flag, int dir) { MpegEncContext *s = &v->s; int xy, wrap, off = 0; int16_t *A, *B, *C; int px, py; int sum; int mixedmv_pic, num_samefield = 0, num_oppfield = 0; int opposit, f; int16_t samefield_pred[2], oppfield_pred[2]; int16_t samefield_predA[2], oppfield_predA[2]; int16_t samefield_predB[2], oppfield_predB[2]; int16_t samefield_predC[2], oppfield_predC[2]; int16_t *predA, *predC; int a_valid, b_valid, c_valid; int hybridmv_thresh, y_bias = 0; if (v->mv_mode == MV_PMODE_MIXED_MV || ((v->mv_mode == MV_PMODE_INTENSITY_COMP) && (v->mv_mode2 == MV_PMODE_MIXED_MV))) mixedmv_pic = 1; else mixedmv_pic = 0; dmv_x <<= 1 - s->quarter_sample; dmv_y <<= 1 - s->quarter_sample; wrap = s->b8_stride; xy = s->block_index[n]; if (s->mb_intra) { s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy + v->blocks_off][0] = 0; s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy + v->blocks_off][1] = 0; s->current_picture.f.motion_val[1][xy + v->blocks_off][0] = 0; s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = 0; if (mv1) { s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][0] = 0; s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][1] = 0; s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][0] = 0; s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][1] = 0; s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][0] = 0; s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][1] = 0; v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0; s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][0] = 0; s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][1] = 0; s->current_picture.f.motion_val[1][xy + wrap][0] = 0; s->current_picture.f.motion_val[1][xy + wrap + v->blocks_off][1] = 0; s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][0] = 0; s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][1] = 0; } return; } C = s->current_picture.f.motion_val[dir][xy - 1 + v->blocks_off]; A = s->current_picture.f.motion_val[dir][xy - wrap + v->blocks_off]; if (mv1) { if (v->field_mode && mixedmv_pic) off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2; else off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2; } else { switch (n) { case 0: off = (s->mb_x > 0) ? -1 : 1; break; case 1: off = (s->mb_x == (s->mb_width - 1)) ? -1 : 1; break; case 2: off = 1; break; case 3: off = -1; } } B = s->current_picture.f.motion_val[dir][xy - wrap + off + v->blocks_off]; a_valid = !s->first_slice_line || (n == 2 || n == 3); b_valid = a_valid && (s->mb_width > 1); c_valid = s->mb_x || (n == 1 || n == 3); if (v->field_mode) { a_valid = a_valid && !is_intra[xy - wrap]; b_valid = b_valid && !is_intra[xy - wrap + off]; c_valid = c_valid && !is_intra[xy - 1]; } if (a_valid) { f = v->mv_f[dir][xy - wrap + v->blocks_off]; num_oppfield += f; num_samefield += 1 - f; if (f) { oppfield_predA[0] = A[0]; oppfield_predA[1] = A[1]; samefield_predA[0] = scaleforsame(v, 0, A[0], 0, dir); samefield_predA[1] = scaleforsame(v, n, A[1], 1, dir); } else { samefield_predA[0] = A[0]; samefield_predA[1] = A[1]; if (v->numref) oppfield_predA[0] = scaleforopp(v, A[0], 0, dir); if (v->numref) oppfield_predA[1] = scaleforopp(v, A[1], 1, dir); } } else { samefield_predA[0] = samefield_predA[1] = 0; oppfield_predA[0] = oppfield_predA[1] = 0; } if (c_valid) { f = v->mv_f[dir][xy - 1 + v->blocks_off]; num_oppfield += f; num_samefield += 1 - f; if (f) { oppfield_predC[0] = C[0]; oppfield_predC[1] = C[1]; samefield_predC[0] = scaleforsame(v, 0, C[0], 0, dir); samefield_predC[1] = scaleforsame(v, n, C[1], 1, dir); } else { samefield_predC[0] = C[0]; samefield_predC[1] = C[1]; if (v->numref) oppfield_predC[0] = scaleforopp(v, C[0], 0, dir); if (v->numref) oppfield_predC[1] = scaleforopp(v, C[1], 1, dir); } } else { samefield_predC[0] = samefield_predC[1] = 0; oppfield_predC[0] = oppfield_predC[1] = 0; } if (b_valid) { f = v->mv_f[dir][xy - wrap + off + v->blocks_off]; num_oppfield += f; num_samefield += 1 - f; if (f) { oppfield_predB[0] = B[0]; oppfield_predB[1] = B[1]; samefield_predB[0] = scaleforsame(v, 0, B[0], 0, dir); samefield_predB[1] = scaleforsame(v, n, B[1], 1, dir); } else { samefield_predB[0] = B[0]; samefield_predB[1] = B[1]; if (v->numref) oppfield_predB[0] = scaleforopp(v, B[0], 0, dir); if (v->numref) oppfield_predB[1] = scaleforopp(v, B[1], 1, dir); } } else { samefield_predB[0] = samefield_predB[1] = 0; oppfield_predB[0] = oppfield_predB[1] = 0; } if (a_valid) { samefield_pred[0] = samefield_predA[0]; samefield_pred[1] = samefield_predA[1]; oppfield_pred[0] = oppfield_predA[0]; oppfield_pred[1] = oppfield_predA[1]; } else if (c_valid) { samefield_pred[0] = samefield_predC[0]; samefield_pred[1] = samefield_predC[1]; oppfield_pred[0] = oppfield_predC[0]; oppfield_pred[1] = oppfield_predC[1]; } else if (b_valid) { samefield_pred[0] = samefield_predB[0]; samefield_pred[1] = samefield_predB[1]; oppfield_pred[0] = oppfield_predB[0]; oppfield_pred[1] = oppfield_predB[1]; } else { samefield_pred[0] = samefield_pred[1] = 0; oppfield_pred[0] = oppfield_pred[1] = 0; } if (num_samefield + num_oppfield > 1) { samefield_pred[0] = mid_pred(samefield_predA[0], samefield_predB[0], samefield_predC[0]); samefield_pred[1] = mid_pred(samefield_predA[1], samefield_predB[1], samefield_predC[1]); if (v->numref) oppfield_pred[0] = mid_pred(oppfield_predA[0], oppfield_predB[0], oppfield_predC[0]); if (v->numref) oppfield_pred[1] = mid_pred(oppfield_predA[1], oppfield_predB[1], oppfield_predC[1]); } if (v->field_mode) { if (num_samefield <= num_oppfield) opposit = 1 - pred_flag; else opposit = pred_flag; } else opposit = 0; if (opposit) { px = oppfield_pred[0]; py = oppfield_pred[1]; predA = oppfield_predA; predC = oppfield_predC; v->mv_f[dir][xy + v->blocks_off] = f = 1; v->ref_field_type[dir] = !v->cur_field_type; } else { px = samefield_pred[0]; py = samefield_pred[1]; predA = samefield_predA; predC = samefield_predC; v->mv_f[dir][xy + v->blocks_off] = f = 0; v->ref_field_type[dir] = v->cur_field_type; } if (!v->field_mode) { int qx, qy, X, Y; qx = (s->mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0); qy = (s->mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0); X = (s->mb_width << 6) - 4; Y = (s->mb_height << 6) - 4; if (mv1) { if (qx + px < -60) px = -60 - qx; if (qy + py < -60) py = -60 - qy; } else { if (qx + px < -28) px = -28 - qx; if (qy + py < -28) py = -28 - qy; } if (qx + px > X) px = X - qx; if (qy + py > Y) py = Y - qy; } if (!v->field_mode || s->pict_type != AV_PICTURE_TYPE_B) { if (v->field_mode && !s->quarter_sample) hybridmv_thresh = 16; else hybridmv_thresh = 32; if (a_valid && c_valid) { if (is_intra[xy - wrap]) sum = FFABS(px) + FFABS(py); else sum = FFABS(px - predA[0]) + FFABS(py - predA[1]); if (sum > hybridmv_thresh) { if (get_bits1(&s->gb)) { px = predA[0]; py = predA[1]; } else { px = predC[0]; py = predC[1]; } } else { if (is_intra[xy - 1]) sum = FFABS(px) + FFABS(py); else sum = FFABS(px - predC[0]) + FFABS(py - predC[1]); if (sum > hybridmv_thresh) { if (get_bits1(&s->gb)) { px = predA[0]; py = predA[1]; } else { px = predC[0]; py = predC[1]; } } } } } if (v->field_mode && !s->quarter_sample) { r_x <<= 1; r_y <<= 1; } if (v->field_mode && v->numref) r_y >>= 1; if (v->field_mode && v->cur_field_type && v->ref_field_type[dir] == 0) y_bias = 1; s->mv[dir][n][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x; s->mv[dir][n][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1] = ((py + dmv_y + r_y - y_bias) & ((r_y << 1) - 1)) - r_y + y_bias; if (mv1) { s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0]; s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1]; s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0]; s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1]; s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0]; s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1]; v->mv_f[dir][xy + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off]; v->mv_f[dir][xy + wrap + v->blocks_off] = v->mv_f[dir][xy + wrap + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off]; } }
['static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y,\n int mv1, int r_x, int r_y, uint8_t* is_intra,\n int pred_flag, int dir)\n{\n MpegEncContext *s = &v->s;\n int xy, wrap, off = 0;\n int16_t *A, *B, *C;\n int px, py;\n int sum;\n int mixedmv_pic, num_samefield = 0, num_oppfield = 0;\n int opposit, f;\n int16_t samefield_pred[2], oppfield_pred[2];\n int16_t samefield_predA[2], oppfield_predA[2];\n int16_t samefield_predB[2], oppfield_predB[2];\n int16_t samefield_predC[2], oppfield_predC[2];\n int16_t *predA, *predC;\n int a_valid, b_valid, c_valid;\n int hybridmv_thresh, y_bias = 0;\n if (v->mv_mode == MV_PMODE_MIXED_MV ||\n ((v->mv_mode == MV_PMODE_INTENSITY_COMP) && (v->mv_mode2 == MV_PMODE_MIXED_MV)))\n mixedmv_pic = 1;\n else\n mixedmv_pic = 0;\n dmv_x <<= 1 - s->quarter_sample;\n dmv_y <<= 1 - s->quarter_sample;\n wrap = s->b8_stride;\n xy = s->block_index[n];\n if (s->mb_intra) {\n s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy + v->blocks_off][0] = 0;\n s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy + v->blocks_off][1] = 0;\n s->current_picture.f.motion_val[1][xy + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = 0;\n if (mv1) {\n s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][1] = 0;\n s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][1] = 0;\n s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][1] = 0;\n v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0;\n s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][1] = 0;\n s->current_picture.f.motion_val[1][xy + wrap][0] = 0;\n s->current_picture.f.motion_val[1][xy + wrap + v->blocks_off][1] = 0;\n s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][0] = 0;\n s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][1] = 0;\n }\n return;\n }\n C = s->current_picture.f.motion_val[dir][xy - 1 + v->blocks_off];\n A = s->current_picture.f.motion_val[dir][xy - wrap + v->blocks_off];\n if (mv1) {\n if (v->field_mode && mixedmv_pic)\n off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2;\n else\n off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2;\n } else {\n switch (n) {\n case 0:\n off = (s->mb_x > 0) ? -1 : 1;\n break;\n case 1:\n off = (s->mb_x == (s->mb_width - 1)) ? -1 : 1;\n break;\n case 2:\n off = 1;\n break;\n case 3:\n off = -1;\n }\n }\n B = s->current_picture.f.motion_val[dir][xy - wrap + off + v->blocks_off];\n a_valid = !s->first_slice_line || (n == 2 || n == 3);\n b_valid = a_valid && (s->mb_width > 1);\n c_valid = s->mb_x || (n == 1 || n == 3);\n if (v->field_mode) {\n a_valid = a_valid && !is_intra[xy - wrap];\n b_valid = b_valid && !is_intra[xy - wrap + off];\n c_valid = c_valid && !is_intra[xy - 1];\n }\n if (a_valid) {\n f = v->mv_f[dir][xy - wrap + v->blocks_off];\n num_oppfield += f;\n num_samefield += 1 - f;\n if (f) {\n oppfield_predA[0] = A[0];\n oppfield_predA[1] = A[1];\n samefield_predA[0] = scaleforsame(v, 0, A[0], 0, dir);\n samefield_predA[1] = scaleforsame(v, n, A[1], 1, dir);\n } else {\n samefield_predA[0] = A[0];\n samefield_predA[1] = A[1];\n if (v->numref)\n oppfield_predA[0] = scaleforopp(v, A[0], 0, dir);\n if (v->numref)\n oppfield_predA[1] = scaleforopp(v, A[1], 1, dir);\n }\n } else {\n samefield_predA[0] = samefield_predA[1] = 0;\n oppfield_predA[0] = oppfield_predA[1] = 0;\n }\n if (c_valid) {\n f = v->mv_f[dir][xy - 1 + v->blocks_off];\n num_oppfield += f;\n num_samefield += 1 - f;\n if (f) {\n oppfield_predC[0] = C[0];\n oppfield_predC[1] = C[1];\n samefield_predC[0] = scaleforsame(v, 0, C[0], 0, dir);\n samefield_predC[1] = scaleforsame(v, n, C[1], 1, dir);\n } else {\n samefield_predC[0] = C[0];\n samefield_predC[1] = C[1];\n if (v->numref)\n oppfield_predC[0] = scaleforopp(v, C[0], 0, dir);\n if (v->numref)\n oppfield_predC[1] = scaleforopp(v, C[1], 1, dir);\n }\n } else {\n samefield_predC[0] = samefield_predC[1] = 0;\n oppfield_predC[0] = oppfield_predC[1] = 0;\n }\n if (b_valid) {\n f = v->mv_f[dir][xy - wrap + off + v->blocks_off];\n num_oppfield += f;\n num_samefield += 1 - f;\n if (f) {\n oppfield_predB[0] = B[0];\n oppfield_predB[1] = B[1];\n samefield_predB[0] = scaleforsame(v, 0, B[0], 0, dir);\n samefield_predB[1] = scaleforsame(v, n, B[1], 1, dir);\n } else {\n samefield_predB[0] = B[0];\n samefield_predB[1] = B[1];\n if (v->numref)\n oppfield_predB[0] = scaleforopp(v, B[0], 0, dir);\n if (v->numref)\n oppfield_predB[1] = scaleforopp(v, B[1], 1, dir);\n }\n } else {\n samefield_predB[0] = samefield_predB[1] = 0;\n oppfield_predB[0] = oppfield_predB[1] = 0;\n }\n if (a_valid) {\n samefield_pred[0] = samefield_predA[0];\n samefield_pred[1] = samefield_predA[1];\n oppfield_pred[0] = oppfield_predA[0];\n oppfield_pred[1] = oppfield_predA[1];\n } else if (c_valid) {\n samefield_pred[0] = samefield_predC[0];\n samefield_pred[1] = samefield_predC[1];\n oppfield_pred[0] = oppfield_predC[0];\n oppfield_pred[1] = oppfield_predC[1];\n } else if (b_valid) {\n samefield_pred[0] = samefield_predB[0];\n samefield_pred[1] = samefield_predB[1];\n oppfield_pred[0] = oppfield_predB[0];\n oppfield_pred[1] = oppfield_predB[1];\n } else {\n samefield_pred[0] = samefield_pred[1] = 0;\n oppfield_pred[0] = oppfield_pred[1] = 0;\n }\n if (num_samefield + num_oppfield > 1) {\n samefield_pred[0] = mid_pred(samefield_predA[0], samefield_predB[0], samefield_predC[0]);\n samefield_pred[1] = mid_pred(samefield_predA[1], samefield_predB[1], samefield_predC[1]);\n if (v->numref)\n oppfield_pred[0] = mid_pred(oppfield_predA[0], oppfield_predB[0], oppfield_predC[0]);\n if (v->numref)\n oppfield_pred[1] = mid_pred(oppfield_predA[1], oppfield_predB[1], oppfield_predC[1]);\n }\n if (v->field_mode) {\n if (num_samefield <= num_oppfield)\n opposit = 1 - pred_flag;\n else\n opposit = pred_flag;\n } else\n opposit = 0;\n if (opposit) {\n px = oppfield_pred[0];\n py = oppfield_pred[1];\n predA = oppfield_predA;\n predC = oppfield_predC;\n v->mv_f[dir][xy + v->blocks_off] = f = 1;\n v->ref_field_type[dir] = !v->cur_field_type;\n } else {\n px = samefield_pred[0];\n py = samefield_pred[1];\n predA = samefield_predA;\n predC = samefield_predC;\n v->mv_f[dir][xy + v->blocks_off] = f = 0;\n v->ref_field_type[dir] = v->cur_field_type;\n }\n if (!v->field_mode) {\n int qx, qy, X, Y;\n qx = (s->mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0);\n qy = (s->mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0);\n X = (s->mb_width << 6) - 4;\n Y = (s->mb_height << 6) - 4;\n if (mv1) {\n if (qx + px < -60) px = -60 - qx;\n if (qy + py < -60) py = -60 - qy;\n } else {\n if (qx + px < -28) px = -28 - qx;\n if (qy + py < -28) py = -28 - qy;\n }\n if (qx + px > X) px = X - qx;\n if (qy + py > Y) py = Y - qy;\n }\n if (!v->field_mode || s->pict_type != AV_PICTURE_TYPE_B) {\n if (v->field_mode && !s->quarter_sample)\n hybridmv_thresh = 16;\n else\n hybridmv_thresh = 32;\n if (a_valid && c_valid) {\n if (is_intra[xy - wrap])\n sum = FFABS(px) + FFABS(py);\n else\n sum = FFABS(px - predA[0]) + FFABS(py - predA[1]);\n if (sum > hybridmv_thresh) {\n if (get_bits1(&s->gb)) {\n px = predA[0];\n py = predA[1];\n } else {\n px = predC[0];\n py = predC[1];\n }\n } else {\n if (is_intra[xy - 1])\n sum = FFABS(px) + FFABS(py);\n else\n sum = FFABS(px - predC[0]) + FFABS(py - predC[1]);\n if (sum > hybridmv_thresh) {\n if (get_bits1(&s->gb)) {\n px = predA[0];\n py = predA[1];\n } else {\n px = predC[0];\n py = predC[1];\n }\n }\n }\n }\n }\n if (v->field_mode && !s->quarter_sample) {\n r_x <<= 1;\n r_y <<= 1;\n }\n if (v->field_mode && v->numref)\n r_y >>= 1;\n if (v->field_mode && v->cur_field_type && v->ref_field_type[dir] == 0)\n y_bias = 1;\n s->mv[dir][n][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;\n s->mv[dir][n][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1] = ((py + dmv_y + r_y - y_bias) & ((r_y << 1) - 1)) - r_y + y_bias;\n if (mv1) {\n s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];\n s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];\n s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];\n s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];\n s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0];\n s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1];\n v->mv_f[dir][xy + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];\n v->mv_f[dir][xy + wrap + v->blocks_off] = v->mv_f[dir][xy + wrap + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off];\n }\n}']
33,554
0
https://github.com/openssl/openssl/blob/16bce0e08b16b28a1953795bde3f913957b08ef2/ssl/packet.c/#L49
int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes) { assert(pkt->subs != NULL && len != 0); if (pkt->subs == NULL || len == 0) return 0; if (pkt->maxsize - pkt->written < len) return 0; if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) { size_t newlen; size_t reflen; reflen = (len > pkt->buf->length) ? len : pkt->buf->length; if (reflen > SIZE_MAX / 2) { newlen = SIZE_MAX; } else { newlen = reflen * 2; if (newlen < DEFAULT_BUF_SIZE) newlen = DEFAULT_BUF_SIZE; } if (BUF_MEM_grow(pkt->buf, newlen) == 0) return 0; } *allocbytes = GETBUF(pkt) + pkt->curr; return 1; }
['int ssl_add_clienthello_tlsext(SSL *s, WPACKET *pkt, int *al)\n{\n#ifndef OPENSSL_NO_EC\n int using_ecc = 0;\n if (s->version >= TLS1_VERSION || SSL_IS_DTLS(s)) {\n int i;\n unsigned long alg_k, alg_a;\n STACK_OF(SSL_CIPHER) *cipher_stack = SSL_get_ciphers(s);\n for (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++) {\n const SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i);\n alg_k = c->algorithm_mkey;\n alg_a = c->algorithm_auth;\n if ((alg_k & (SSL_kECDHE | SSL_kECDHEPSK))\n || (alg_a & SSL_aECDSA)) {\n using_ecc = 1;\n break;\n }\n }\n }\n#endif\n if (s->renegotiate) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_renegotiate)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_sub_memcpy_u8(pkt, s->s3->previous_client_finished,\n s->s3->previous_client_finished_len)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (s->client_version == SSL3_VERSION)\n goto done;\n if (s->tlsext_hostname != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_server_name)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, TLSEXT_NAMETYPE_host_name)\n || !WPACKET_sub_memcpy_u16(pkt, s->tlsext_hostname,\n strlen(s->tlsext_hostname))\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#ifndef OPENSSL_NO_SRP\n if (s->srp_ctx.login != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_srp)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u8(pkt)\n || !WPACKET_set_flags(pkt, WPACKET_FLAGS_NON_ZERO_LENGTH)\n || !WPACKET_memcpy(pkt, s->srp_ctx.login,\n strlen(s->srp_ctx.login))\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_EC\n if (using_ecc) {\n const unsigned char *pcurves, *pformats;\n size_t num_curves, num_formats;\n size_t i;\n tls1_get_formatlist(s, &pformats, &num_formats);\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_sub_memcpy_u8(pkt, pformats, num_formats)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pcurves = s->tlsext_ellipticcurvelist;\n if (!tls1_get_curvelist(s, 0, &pcurves, &num_curves)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_elliptic_curves)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n for (i = 0; i < num_curves; i++, pcurves += 2) {\n if (tls_curve_allowed(s, pcurves, SSL_SECOP_CURVE_SUPPORTED)) {\n if (!WPACKET_put_bytes_u8(pkt, pcurves[0])\n || !WPACKET_put_bytes_u8(pkt, pcurves[1])) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (tls_use_ticket(s)) {\n size_t ticklen;\n if (!s->new_session && s->session && s->session->tlsext_tick)\n ticklen = s->session->tlsext_ticklen;\n else if (s->session && s->tlsext_session_ticket &&\n s->tlsext_session_ticket->data) {\n ticklen = s->tlsext_session_ticket->length;\n s->session->tlsext_tick = OPENSSL_malloc(ticklen);\n if (s->session->tlsext_tick == NULL) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n memcpy(s->session->tlsext_tick,\n s->tlsext_session_ticket->data, ticklen);\n s->session->tlsext_ticklen = ticklen;\n } else\n ticklen = 0;\n if (ticklen == 0 && s->tlsext_session_ticket &&\n s->tlsext_session_ticket->data == NULL)\n goto skip_ext;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_session_ticket)\n || !WPACKET_sub_memcpy_u16(pkt, s->session->tlsext_tick,\n ticklen)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n skip_ext:\n if (SSL_CLIENT_USE_SIGALGS(s)) {\n size_t salglen;\n const unsigned char *salg;\n salglen = tls12_get_psigalgs(s, &salg);\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signature_algorithms)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !tls12_copy_sigalgs(s, pkt, salg, salglen)\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#ifndef OPENSSL_NO_OCSP\n if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp) {\n int i;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_status_request)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, TLSEXT_STATUSTYPE_ocsp)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) {\n unsigned char *idbytes;\n int idlen;\n OCSP_RESPID *id;\n id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i);\n idlen = i2d_OCSP_RESPID(id, NULL);\n if (idlen <= 0\n || !WPACKET_sub_allocate_bytes_u16(pkt, idlen, &idbytes)\n || i2d_OCSP_RESPID(id, &idbytes) != idlen) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (s->tlsext_ocsp_exts) {\n unsigned char *extbytes;\n int extlen = i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, NULL);\n if (extlen < 0) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_allocate_bytes(pkt, extlen, &extbytes)\n || i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &extbytes)\n != extlen) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_HEARTBEATS\n if (SSL_IS_DTLS(s)) {\n unsigned int mode;\n if (s->tlsext_heartbeat & SSL_DTLSEXT_HB_DONT_RECV_REQUESTS)\n mode = SSL_DTLSEXT_HB_DONT_SEND_REQUESTS;\n else\n mode = SSL_DTLSEXT_HB_ENABLED;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_heartbeat)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, mode)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n if (s->ctx->next_proto_select_cb && !s->s3->tmp.finish_md_len) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_next_proto_neg)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (s->alpn_client_proto_list && !s->s3->tmp.finish_md_len) {\n if (!WPACKET_put_bytes_u16(pkt,\n TLSEXT_TYPE_application_layer_protocol_negotiation)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_sub_memcpy_u16(pkt, s->alpn_client_proto_list,\n s->alpn_client_proto_list_len)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n s->s3->alpn_sent = 1;\n }\n#ifndef OPENSSL_NO_SRTP\n if (SSL_IS_DTLS(s) && SSL_get_srtp_profiles(s)) {\n STACK_OF(SRTP_PROTECTION_PROFILE) *clnt = SSL_get_srtp_profiles(s);\n SRTP_PROTECTION_PROFILE *prof;\n int i, ct;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_use_srtp)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n ct = sk_SRTP_PROTECTION_PROFILE_num(clnt);\n for (i = 0; i < ct; i++) {\n prof = sk_SRTP_PROTECTION_PROFILE_value(clnt, i);\n if (prof == NULL || !WPACKET_put_bytes_u16(pkt, prof->id)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt)\n || !WPACKET_put_bytes_u8(pkt, 0)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n custom_ext_init(&s->cert->cli_ext);\n if (!custom_ext_add(s, 0, pkt, al)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!(s->options & SSL_OP_NO_ENCRYPT_THEN_MAC)) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_encrypt_then_mac)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#ifndef OPENSSL_NO_CT\n if (s->ct_validation_callback != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signed_certificate_timestamp)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_extended_master_secret)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!SSL_IS_DTLS(s) && s->version >= TLS1_3_VERSION) {\n int min_version, max_version, reason, currv;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_supported_versions)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u8(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n reason = ssl_get_client_min_max_version(s, &min_version, &max_version);\n if (reason != 0) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, reason);\n return 0;\n }\n for (currv = max_version; currv >= min_version; currv--) {\n if (currv == TLS1_3_VERSION) {\n if (!WPACKET_put_bytes_u16(pkt, TLS1_3_VERSION_DRAFT)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n } else if (!WPACKET_put_bytes_u16(pkt, currv)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (s->options & SSL_OP_TLSEXT_PADDING) {\n unsigned char *padbytes;\n size_t hlen;\n if (!WPACKET_get_total_written(pkt, &hlen)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (hlen > 0xff && hlen < 0x200) {\n hlen = 0x200 - hlen;\n if (hlen >= 4)\n hlen -= 4;\n else\n hlen = 0;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_padding)\n || !WPACKET_sub_allocate_bytes_u16(pkt, hlen, &padbytes)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n memset(padbytes, 0, hlen);\n }\n }\n done:\n return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n assert(pkt->subs != NULL);\n if (pkt->subs == NULL)\n return 0;\n sub = OPENSSL_zalloc(sizeof(*sub));\n if (sub == NULL)\n return 0;\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n sub->packet_len = lenchars - GETBUF(pkt);\n return 1;\n}', 'int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)\n{\n unsigned char *dest;\n if (len == 0)\n return 1;\n if (!WPACKET_allocate_bytes(pkt, len, &dest))\n return 0;\n memcpy(dest, src, len);\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n return 0;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n assert(pkt->subs != NULL && len != 0);\n if (pkt->subs == NULL || len == 0)\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {\n size_t newlen;\n size_t reflen;\n reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n if (reflen > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = reflen * 2;\n if (newlen < DEFAULT_BUF_SIZE)\n newlen = DEFAULT_BUF_SIZE;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n *allocbytes = GETBUF(pkt) + pkt->curr;\n return 1;\n}']
33,555
0
https://github.com/nginx/nginx/blob/1c906828aee64d8ac7eb4df57f9134e27e709a3d/src/core/ngx_string.c/#L938
ngx_int_t ngx_atoi(u_char *line, size_t n) { ngx_int_t value, cutoff, cutlim; if (n == 0) { return NGX_ERROR; } cutoff = NGX_MAX_INT_T_VALUE / 10; cutlim = NGX_MAX_INT_T_VALUE % 10; for (value = 0; n--; line++) { if (*line < '0' || *line > '9') { return NGX_ERROR; } if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) { return NGX_ERROR; } value = value * 10 + (*line - '0'); } return value; }
['ngx_resolver_t *\nngx_resolver_create(ngx_conf_t *cf, ngx_str_t *names, ngx_uint_t n)\n{\n ngx_str_t s;\n ngx_url_t u;\n ngx_uint_t i, j;\n ngx_resolver_t *r;\n ngx_pool_cleanup_t *cln;\n ngx_resolver_connection_t *rec;\n r = ngx_pcalloc(cf->pool, sizeof(ngx_resolver_t));\n if (r == NULL) {\n return NULL;\n }\n r->event = ngx_pcalloc(cf->pool, sizeof(ngx_event_t));\n if (r->event == NULL) {\n return NULL;\n }\n cln = ngx_pool_cleanup_add(cf->pool, 0);\n if (cln == NULL) {\n return NULL;\n }\n cln->handler = ngx_resolver_cleanup;\n cln->data = r;\n ngx_rbtree_init(&r->name_rbtree, &r->name_sentinel,\n ngx_resolver_rbtree_insert_value);\n ngx_rbtree_init(&r->srv_rbtree, &r->srv_sentinel,\n ngx_resolver_rbtree_insert_value);\n ngx_rbtree_init(&r->addr_rbtree, &r->addr_sentinel,\n ngx_rbtree_insert_value);\n ngx_queue_init(&r->name_resend_queue);\n ngx_queue_init(&r->srv_resend_queue);\n ngx_queue_init(&r->addr_resend_queue);\n ngx_queue_init(&r->name_expire_queue);\n ngx_queue_init(&r->srv_expire_queue);\n ngx_queue_init(&r->addr_expire_queue);\n#if (NGX_HAVE_INET6)\n r->ipv6 = 1;\n ngx_rbtree_init(&r->addr6_rbtree, &r->addr6_sentinel,\n ngx_resolver_rbtree_insert_addr6_value);\n ngx_queue_init(&r->addr6_resend_queue);\n ngx_queue_init(&r->addr6_expire_queue);\n#endif\n r->event->handler = ngx_resolver_resend_handler;\n r->event->data = r;\n r->event->log = &cf->cycle->new_log;\n r->event->cancelable = 1;\n r->ident = -1;\n r->resend_timeout = 5;\n r->tcp_timeout = 5;\n r->expire = 30;\n r->valid = 0;\n r->log = &cf->cycle->new_log;\n r->log_level = NGX_LOG_ERR;\n if (n) {\n if (ngx_array_init(&r->connections, cf->pool, n,\n sizeof(ngx_resolver_connection_t))\n != NGX_OK)\n {\n return NULL;\n }\n }\n for (i = 0; i < n; i++) {\n if (ngx_strncmp(names[i].data, "valid=", 6) == 0) {\n s.len = names[i].len - 6;\n s.data = names[i].data + 6;\n r->valid = ngx_parse_time(&s, 1);\n if (r->valid == (time_t) NGX_ERROR) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid parameter: %V", &names[i]);\n return NULL;\n }\n continue;\n }\n#if (NGX_HAVE_INET6)\n if (ngx_strncmp(names[i].data, "ipv6=", 5) == 0) {\n if (ngx_strcmp(&names[i].data[5], "on") == 0) {\n r->ipv6 = 1;\n } else if (ngx_strcmp(&names[i].data[5], "off") == 0) {\n r->ipv6 = 0;\n } else {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid parameter: %V", &names[i]);\n return NULL;\n }\n continue;\n }\n#endif\n ngx_memzero(&u, sizeof(ngx_url_t));\n u.url = names[i];\n u.default_port = 53;\n if (ngx_parse_url(cf->pool, &u) != NGX_OK) {\n if (u.err) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "%s in resolver \\"%V\\"",\n u.err, &u.url);\n }\n return NULL;\n }\n rec = ngx_array_push_n(&r->connections, u.naddrs);\n if (rec == NULL) {\n return NULL;\n }\n ngx_memzero(rec, u.naddrs * sizeof(ngx_resolver_connection_t));\n for (j = 0; j < u.naddrs; j++) {\n rec[j].sockaddr = u.addrs[j].sockaddr;\n rec[j].socklen = u.addrs[j].socklen;\n rec[j].server = u.addrs[j].name;\n rec[j].resolver = r;\n }\n }\n if (n && r->connections.nelts == 0) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "no name servers defined");\n return NULL;\n }\n return r;\n}', 'ngx_int_t\nngx_parse_url(ngx_pool_t *pool, ngx_url_t *u)\n{\n u_char *p;\n size_t len;\n p = u->url.data;\n len = u->url.len;\n if (len >= 5 && ngx_strncasecmp(p, (u_char *) "unix:", 5) == 0) {\n return ngx_parse_unix_domain_url(pool, u);\n }\n if (len && p[0] == \'[\') {\n return ngx_parse_inet6_url(pool, u);\n }\n return ngx_parse_inet_url(pool, u);\n}', 'static ngx_int_t\nngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u)\n{\n u_char *host, *port, *last, *uri, *args, *dash;\n size_t len;\n ngx_int_t n;\n struct sockaddr_in *sin;\n u->socklen = sizeof(struct sockaddr_in);\n sin = (struct sockaddr_in *) &u->sockaddr;\n sin->sin_family = AF_INET;\n u->family = AF_INET;\n host = u->url.data;\n last = host + u->url.len;\n port = ngx_strlchr(host, last, \':\');\n uri = ngx_strlchr(host, last, \'/\');\n args = ngx_strlchr(host, last, \'?\');\n if (args) {\n if (uri == NULL || args < uri) {\n uri = args;\n }\n }\n if (uri) {\n if (u->listen || !u->uri_part) {\n u->err = "invalid host";\n return NGX_ERROR;\n }\n u->uri.len = last - uri;\n u->uri.data = uri;\n last = uri;\n if (uri < port) {\n port = NULL;\n }\n }\n if (port) {\n port++;\n len = last - port;\n if (u->listen) {\n dash = ngx_strlchr(port, last, \'-\');\n if (dash) {\n dash++;\n n = ngx_atoi(dash, last - dash);\n if (n < 1 || n > 65535) {\n u->err = "invalid port";\n return NGX_ERROR;\n }\n u->last_port = (in_port_t) n;\n len = dash - port - 1;\n }\n }\n n = ngx_atoi(port, len);\n if (n < 1 || n > 65535) {\n u->err = "invalid port";\n return NGX_ERROR;\n }\n if (u->last_port && n > u->last_port) {\n u->err = "invalid port range";\n return NGX_ERROR;\n }\n u->port = (in_port_t) n;\n sin->sin_port = htons((in_port_t) n);\n u->port_text.len = last - port;\n u->port_text.data = port;\n last = port - 1;\n } else {\n if (uri == NULL) {\n if (u->listen) {\n len = last - host;\n dash = ngx_strlchr(host, last, \'-\');\n if (dash) {\n dash++;\n n = ngx_atoi(dash, last - dash);\n if (n == NGX_ERROR) {\n goto no_port;\n }\n if (n < 1 || n > 65535) {\n u->err = "invalid port";\n } else {\n u->last_port = (in_port_t) n;\n }\n len = dash - host - 1;\n }\n n = ngx_atoi(host, len);\n if (n != NGX_ERROR) {\n if (u->err) {\n return NGX_ERROR;\n }\n if (n < 1 || n > 65535) {\n u->err = "invalid port";\n return NGX_ERROR;\n }\n if (u->last_port && n > u->last_port) {\n u->err = "invalid port range";\n return NGX_ERROR;\n }\n u->port = (in_port_t) n;\n sin->sin_port = htons((in_port_t) n);\n sin->sin_addr.s_addr = INADDR_ANY;\n u->port_text.len = last - host;\n u->port_text.data = host;\n u->wildcard = 1;\n return ngx_inet_add_addr(pool, u, &u->sockaddr.sockaddr,\n u->socklen, 1);\n }\n }\n }\nno_port:\n u->err = NULL;\n u->no_port = 1;\n u->port = u->default_port;\n sin->sin_port = htons(u->default_port);\n u->last_port = 0;\n }\n len = last - host;\n if (len == 0) {\n u->err = "no host";\n return NGX_ERROR;\n }\n u->host.len = len;\n u->host.data = host;\n if (u->listen && len == 1 && *host == \'*\') {\n sin->sin_addr.s_addr = INADDR_ANY;\n u->wildcard = 1;\n return ngx_inet_add_addr(pool, u, &u->sockaddr.sockaddr, u->socklen, 1);\n }\n sin->sin_addr.s_addr = ngx_inet_addr(host, len);\n if (sin->sin_addr.s_addr != INADDR_NONE) {\n if (sin->sin_addr.s_addr == INADDR_ANY) {\n u->wildcard = 1;\n }\n return ngx_inet_add_addr(pool, u, &u->sockaddr.sockaddr, u->socklen, 1);\n }\n if (u->no_resolve) {\n return NGX_OK;\n }\n if (ngx_inet_resolve_host(pool, u) != NGX_OK) {\n return NGX_ERROR;\n }\n u->family = u->addrs[0].sockaddr->sa_family;\n u->socklen = u->addrs[0].socklen;\n ngx_memcpy(&u->sockaddr, u->addrs[0].sockaddr, u->addrs[0].socklen);\n u->wildcard = ngx_inet_wildcard(&u->sockaddr.sockaddr);\n return NGX_OK;\n}', 'static ngx_inline u_char *\nngx_strlchr(u_char *p, u_char *last, u_char c)\n{\n while (p < last) {\n if (*p == c) {\n return p;\n }\n p++;\n }\n return NULL;\n}', "ngx_int_t\nngx_atoi(u_char *line, size_t n)\n{\n ngx_int_t value, cutoff, cutlim;\n if (n == 0) {\n return NGX_ERROR;\n }\n cutoff = NGX_MAX_INT_T_VALUE / 10;\n cutlim = NGX_MAX_INT_T_VALUE % 10;\n for (value = 0; n--; line++) {\n if (*line < '0' || *line > '9') {\n return NGX_ERROR;\n }\n if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) {\n return NGX_ERROR;\n }\n value = value * 10 + (*line - '0');\n }\n return value;\n}"]
33,556
0
https://github.com/openssl/openssl/blob/18e1e302452e6dea4500b6f981cee7e151294dea/crypto/bn/bn_ctx.c/#L268
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int test_badmod(void)\n{\n BIGNUM *a = NULL, *b = NULL, *zero = NULL;\n BN_MONT_CTX *mont = NULL;\n int st = 0;\n if (!TEST_ptr(a = BN_new())\n || !TEST_ptr(b = BN_new())\n || !TEST_ptr(zero = BN_new())\n || !TEST_ptr(mont = BN_MONT_CTX_new()))\n goto err;\n BN_zero(zero);\n if (!TEST_false(BN_div(a, b, BN_value_one(), zero, ctx)))\n goto err;\n ERR_clear_error();\n if (!TEST_false(BN_mod_mul(a, BN_value_one(), BN_value_one(), zero, ctx)))\n goto err;\n ERR_clear_error();\n if (!TEST_false(BN_mod_exp(a, BN_value_one(), BN_value_one(), zero, ctx)))\n goto err;\n ERR_clear_error();\n if (!TEST_false(BN_mod_exp_mont(a, BN_value_one(), BN_value_one(),\n zero, ctx, NULL)))\n goto err;\n ERR_clear_error();\n if (!TEST_false(BN_mod_exp_mont_consttime(a, BN_value_one(), BN_value_one(),\n zero, ctx, NULL)))\n goto err;\n ERR_clear_error();\n if (!TEST_false(BN_MONT_CTX_set(mont, zero, ctx)))\n goto err;\n ERR_clear_error();\n if (!TEST_true(BN_set_word(b, 16)))\n goto err;\n if (!TEST_false(BN_MONT_CTX_set(mont, b, ctx)))\n goto err;\n ERR_clear_error();\n if (!TEST_false(BN_mod_exp_mont(a, BN_value_one(), BN_value_one(),\n b, ctx, NULL)))\n goto err;\n ERR_clear_error();\n if (!TEST_false(BN_mod_exp_mont_consttime(a, BN_value_one(), BN_value_one(),\n b, ctx, NULL)))\n goto err;\n ERR_clear_error();\n st = 1;\n err:\n BN_free(a);\n BN_free(b);\n BN_free(zero);\n BN_MONT_CTX_free(mont);\n return st;\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_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_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG("ENTER BN_CTX_get()", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG("LEAVE BN_CTX_get()", ctx);\n return ret;\n}', '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}']
33,557
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/x509v3/v3_sxnet.c/#L334
ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone) { ASN1_INTEGER *izone = NULL; ASN1_OCTET_STRING *oct; if(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) { X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE); ASN1_INTEGER_free(izone); return NULL; } oct = SXNET_get_id_INTEGER(sx, izone); ASN1_INTEGER_free(oct); return oct; }
['ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)\n{\n\tASN1_INTEGER *izone = NULL;\n\tASN1_OCTET_STRING *oct;\n\tif(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {\n\t\tX509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE);\n\t\tASN1_INTEGER_free(izone);\n\t\treturn NULL;\n\t}\n\toct = SXNET_get_id_INTEGER(sx, izone);\n\tASN1_INTEGER_free(oct);\n\treturn oct;\n}', 'ASN1_STRING *ASN1_STRING_type_new(int type)\n\t{\n\tASN1_STRING *ret;\n\tret=(ASN1_STRING *)Malloc(sizeof(ASN1_STRING));\n\tif (ret == NULL)\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->length=0;\n\tret->type=type;\n\tret->data=NULL;\n\tret->flags=0;\n\treturn(ret);\n\t}', 'ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone)\n{\n\tSXNETID *id;\n\tint i;\n\tfor(i = 0; i < sk_SXNETID_num(sx->ids); i++) {\n\t\tid = sk_SXNETID_value(sx->ids, i);\n\t\tif(!ASN1_INTEGER_cmp(id->zone, zone)) return id->user;\n\t}\n\treturn NULL;\n}', 'IMPLEMENT_STACK_OF(SXNETID)']
33,558
1
https://github.com/libav/libav/blob/63e8d9760f23a4edf81e9ae58c4f6d3baa6ff4dd/libavcodec/mpegaudiodec.c/#L683
static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window, int *dither_state, OUT_INT *samples, int incr) { register const MPA_INT *w, *w2, *p; int j; OUT_INT *samples2; #if CONFIG_FLOAT float sum, sum2; #elif FRAC_BITS <= 15 int sum, sum2; #else int64_t sum, sum2; #endif memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf)); samples2 = samples + 31 * incr; w = window; w2 = window + 31; sum = *dither_state; p = synth_buf + 16; SUM8(MACS, sum, w, p); p = synth_buf + 48; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); samples += incr; w++; for(j=1;j<16;j++) { sum2 = 0; p = synth_buf + 16 + j; SUM8P2(sum, MACS, sum2, MLSS, w, w2, p); p = synth_buf + 48 - j; SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p); *samples = round_sample(&sum); samples += incr; sum += sum2; *samples2 = round_sample(&sum); samples2 -= incr; w++; w2--; } p = synth_buf + 32; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); *dither_state= sum; }
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n int offset;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n 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 apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,\n int *dither_state, OUT_INT *samples, int incr)\n{\n register const MPA_INT *w, *w2, *p;\n int j;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#elif FRAC_BITS <= 15\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n}']
33,559
0
https://github.com/libav/libav/blob/42181740a3972e17d0097d28fabc9a1a60322d47/libavcodec/vp9block.c/#L1249
static int inter_recon(AVCodecContext *avctx) { static const uint8_t bwlog_tab[2][N_BS_SIZES] = { { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 }, { 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4 }, }; VP9Context *s = avctx->priv_data; VP9Block *const b = &s->b; int row = b->row, col = b->col; AVFrame *ref1 = s->refs[s->refidx[b->ref[0]]]; AVFrame *ref2 = b->comp ? s->refs[s->refidx[b->ref[1]]] : NULL; int w = avctx->width, h = avctx->height; ptrdiff_t ls_y = b->y_stride, ls_uv = b->uv_stride; if (!ref1->data[0] || (b->comp && !ref2->data[0])) return AVERROR_INVALIDDATA; if (b->bs > BS_8x8) { if (b->bs == BS_8x4) { mc_luma_dir(s, s->dsp.mc[3][b->filter][0], b->dst[0], ls_y, ref1->data[0], ref1->linesize[0], row << 3, col << 3, &b->mv[0][0], 8, 4, w, h); mc_luma_dir(s, s->dsp.mc[3][b->filter][0], b->dst[0] + 4 * ls_y, ls_y, ref1->data[0], ref1->linesize[0], (row << 3) + 4, col << 3, &b->mv[2][0], 8, 4, w, h); if (b->comp) { mc_luma_dir(s, s->dsp.mc[3][b->filter][1], b->dst[0], ls_y, ref2->data[0], ref2->linesize[0], row << 3, col << 3, &b->mv[0][1], 8, 4, w, h); mc_luma_dir(s, s->dsp.mc[3][b->filter][1], b->dst[0] + 4 * ls_y, ls_y, ref2->data[0], ref2->linesize[0], (row << 3) + 4, col << 3, &b->mv[2][1], 8, 4, w, h); } } else if (b->bs == BS_4x8) { mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0], ls_y, ref1->data[0], ref1->linesize[0], row << 3, col << 3, &b->mv[0][0], 4, 8, w, h); mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4, ls_y, ref1->data[0], ref1->linesize[0], row << 3, (col << 3) + 4, &b->mv[1][0], 4, 8, w, h); if (b->comp) { mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0], ls_y, ref2->data[0], ref2->linesize[0], row << 3, col << 3, &b->mv[0][1], 4, 8, w, h); mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4, ls_y, ref2->data[0], ref2->linesize[0], row << 3, (col << 3) + 4, &b->mv[1][1], 4, 8, w, h); } } else { av_assert2(b->bs == BS_4x4); mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0], ls_y, ref1->data[0], ref1->linesize[0], row << 3, col << 3, &b->mv[0][0], 4, 4, w, h); mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4, ls_y, ref1->data[0], ref1->linesize[0], row << 3, (col << 3) + 4, &b->mv[1][0], 4, 4, w, h); mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4 * ls_y, ls_y, ref1->data[0], ref1->linesize[0], (row << 3) + 4, col << 3, &b->mv[2][0], 4, 4, w, h); mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4 * ls_y + 4, ls_y, ref1->data[0], ref1->linesize[0], (row << 3) + 4, (col << 3) + 4, &b->mv[3][0], 4, 4, w, h); if (b->comp) { mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0], ls_y, ref2->data[0], ref2->linesize[0], row << 3, col << 3, &b->mv[0][1], 4, 4, w, h); mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4, ls_y, ref2->data[0], ref2->linesize[0], row << 3, (col << 3) + 4, &b->mv[1][1], 4, 4, w, h); mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4 * ls_y, ls_y, ref2->data[0], ref2->linesize[0], (row << 3) + 4, col << 3, &b->mv[2][1], 4, 4, w, h); mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4 * ls_y + 4, ls_y, ref2->data[0], ref2->linesize[0], (row << 3) + 4, (col << 3) + 4, &b->mv[3][1], 4, 4, w, h); } } } else { int bwl = bwlog_tab[0][b->bs]; int bw = bwh_tab[0][b->bs][0] * 4; int bh = bwh_tab[0][b->bs][1] * 4; mc_luma_dir(s, s->dsp.mc[bwl][b->filter][0], b->dst[0], ls_y, ref1->data[0], ref1->linesize[0], row << 3, col << 3, &b->mv[0][0], bw, bh, w, h); if (b->comp) mc_luma_dir(s, s->dsp.mc[bwl][b->filter][1], b->dst[0], ls_y, ref2->data[0], ref2->linesize[0], row << 3, col << 3, &b->mv[0][1], bw, bh, w, h); } { int bwl = bwlog_tab[1][b->bs]; int bw = bwh_tab[1][b->bs][0] * 4, bh = bwh_tab[1][b->bs][1] * 4; VP56mv mvuv; w = (w + 1) >> 1; h = (h + 1) >> 1; if (b->bs > BS_8x8) { mvuv.x = ROUNDED_DIV(b->mv[0][0].x + b->mv[1][0].x + b->mv[2][0].x + b->mv[3][0].x, 4); mvuv.y = ROUNDED_DIV(b->mv[0][0].y + b->mv[1][0].y + b->mv[2][0].y + b->mv[3][0].y, 4); } else { mvuv = b->mv[0][0]; } mc_chroma_dir(s, s->dsp.mc[bwl][b->filter][0], b->dst[1], b->dst[2], ls_uv, ref1->data[1], ref1->linesize[1], ref1->data[2], ref1->linesize[2], row << 2, col << 2, &mvuv, bw, bh, w, h); if (b->comp) { if (b->bs > BS_8x8) { mvuv.x = ROUNDED_DIV(b->mv[0][1].x + b->mv[1][1].x + b->mv[2][1].x + b->mv[3][1].x, 4); mvuv.y = ROUNDED_DIV(b->mv[0][1].y + b->mv[1][1].y + b->mv[2][1].y + b->mv[3][1].y, 4); } else { mvuv = b->mv[0][1]; } mc_chroma_dir(s, s->dsp.mc[bwl][b->filter][1], b->dst[1], b->dst[2], ls_uv, ref2->data[1], ref2->linesize[1], ref2->data[2], ref2->linesize[2], row << 2, col << 2, &mvuv, bw, bh, w, h); } } if (!b->skip) { int w4 = bwh_tab[1][b->bs][0] << 1, step1d = 1 << b->tx, n; int h4 = bwh_tab[1][b->bs][1] << 1, x, y, step = 1 << (b->tx * 2); int end_x = FFMIN(2 * (s->cols - col), w4); int end_y = FFMIN(2 * (s->rows - row), h4); int tx = 4 * s->lossless + b->tx, uvtx = b->uvtx + 4 * s->lossless; int uvstep1d = 1 << b->uvtx, p; uint8_t *dst = b->dst[0]; for (n = 0, y = 0; y < end_y; y += step1d) { uint8_t *ptr = dst; for (x = 0; x < end_x; x += step1d, ptr += 4 * step1d, n += step) { int eob = b->tx > TX_8X8 ? AV_RN16A(&s->eob[n]) : s->eob[n]; if (eob) s->dsp.itxfm_add[tx][DCT_DCT](ptr, b->y_stride, s->block + 16 * n, eob); } dst += 4 * b->y_stride * step1d; } h4 >>= 1; w4 >>= 1; end_x >>= 1; end_y >>= 1; step = 1 << (b->uvtx * 2); for (p = 0; p < 2; p++) { dst = b->dst[p + 1]; for (n = 0, y = 0; y < end_y; y += uvstep1d) { uint8_t *ptr = dst; for (x = 0; x < end_x; x += uvstep1d, ptr += 4 * uvstep1d, n += step) { int eob = b->uvtx > TX_8X8 ? AV_RN16A(&s->uveob[p][n]) : s->uveob[p][n]; if (eob) s->dsp.itxfm_add[uvtx][DCT_DCT](ptr, b->uv_stride, s->uvblock[p] + 16 * n, eob); } dst += 4 * uvstep1d * b->uv_stride; } } } return 0; }
['static int inter_recon(AVCodecContext *avctx)\n{\n static const uint8_t bwlog_tab[2][N_BS_SIZES] = {\n { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 },\n { 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4 },\n };\n VP9Context *s = avctx->priv_data;\n VP9Block *const b = &s->b;\n int row = b->row, col = b->col;\n AVFrame *ref1 = s->refs[s->refidx[b->ref[0]]];\n AVFrame *ref2 = b->comp ? s->refs[s->refidx[b->ref[1]]] : NULL;\n int w = avctx->width, h = avctx->height;\n ptrdiff_t ls_y = b->y_stride, ls_uv = b->uv_stride;\n if (!ref1->data[0] || (b->comp && !ref2->data[0]))\n return AVERROR_INVALIDDATA;\n if (b->bs > BS_8x8) {\n if (b->bs == BS_8x4) {\n mc_luma_dir(s, s->dsp.mc[3][b->filter][0], b->dst[0], ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, col << 3, &b->mv[0][0], 8, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[3][b->filter][0],\n b->dst[0] + 4 * ls_y, ls_y,\n ref1->data[0], ref1->linesize[0],\n (row << 3) + 4, col << 3, &b->mv[2][0], 8, 4, w, h);\n if (b->comp) {\n mc_luma_dir(s, s->dsp.mc[3][b->filter][1], b->dst[0], ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, col << 3, &b->mv[0][1], 8, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[3][b->filter][1],\n b->dst[0] + 4 * ls_y, ls_y,\n ref2->data[0], ref2->linesize[0],\n (row << 3) + 4, col << 3, &b->mv[2][1], 8, 4, w, h);\n }\n } else if (b->bs == BS_4x8) {\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0], ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, col << 3, &b->mv[0][0], 4, 8, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4, ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, (col << 3) + 4, &b->mv[1][0], 4, 8, w, h);\n if (b->comp) {\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0], ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, col << 3, &b->mv[0][1], 4, 8, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4, ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, (col << 3) + 4, &b->mv[1][1], 4, 8, w, h);\n }\n } else {\n av_assert2(b->bs == BS_4x4);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0], ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, col << 3, &b->mv[0][0], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4, ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, (col << 3) + 4, &b->mv[1][0], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0],\n b->dst[0] + 4 * ls_y, ls_y,\n ref1->data[0], ref1->linesize[0],\n (row << 3) + 4, col << 3, &b->mv[2][0], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0],\n b->dst[0] + 4 * ls_y + 4, ls_y,\n ref1->data[0], ref1->linesize[0],\n (row << 3) + 4, (col << 3) + 4, &b->mv[3][0], 4, 4, w, h);\n if (b->comp) {\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0], ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, col << 3, &b->mv[0][1], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4, ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, (col << 3) + 4, &b->mv[1][1], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1],\n b->dst[0] + 4 * ls_y, ls_y,\n ref2->data[0], ref2->linesize[0],\n (row << 3) + 4, col << 3, &b->mv[2][1], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1],\n b->dst[0] + 4 * ls_y + 4, ls_y,\n ref2->data[0], ref2->linesize[0],\n (row << 3) + 4, (col << 3) + 4, &b->mv[3][1], 4, 4, w, h);\n }\n }\n } else {\n int bwl = bwlog_tab[0][b->bs];\n int bw = bwh_tab[0][b->bs][0] * 4;\n int bh = bwh_tab[0][b->bs][1] * 4;\n mc_luma_dir(s, s->dsp.mc[bwl][b->filter][0], b->dst[0], ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, col << 3, &b->mv[0][0], bw, bh, w, h);\n if (b->comp)\n mc_luma_dir(s, s->dsp.mc[bwl][b->filter][1], b->dst[0], ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, col << 3, &b->mv[0][1], bw, bh, w, h);\n }\n {\n int bwl = bwlog_tab[1][b->bs];\n int bw = bwh_tab[1][b->bs][0] * 4, bh = bwh_tab[1][b->bs][1] * 4;\n VP56mv mvuv;\n w = (w + 1) >> 1;\n h = (h + 1) >> 1;\n if (b->bs > BS_8x8) {\n mvuv.x = ROUNDED_DIV(b->mv[0][0].x + b->mv[1][0].x +\n b->mv[2][0].x + b->mv[3][0].x, 4);\n mvuv.y = ROUNDED_DIV(b->mv[0][0].y + b->mv[1][0].y +\n b->mv[2][0].y + b->mv[3][0].y, 4);\n } else {\n mvuv = b->mv[0][0];\n }\n mc_chroma_dir(s, s->dsp.mc[bwl][b->filter][0],\n b->dst[1], b->dst[2], ls_uv,\n ref1->data[1], ref1->linesize[1],\n ref1->data[2], ref1->linesize[2],\n row << 2, col << 2, &mvuv, bw, bh, w, h);\n if (b->comp) {\n if (b->bs > BS_8x8) {\n mvuv.x = ROUNDED_DIV(b->mv[0][1].x + b->mv[1][1].x +\n b->mv[2][1].x + b->mv[3][1].x, 4);\n mvuv.y = ROUNDED_DIV(b->mv[0][1].y + b->mv[1][1].y +\n b->mv[2][1].y + b->mv[3][1].y, 4);\n } else {\n mvuv = b->mv[0][1];\n }\n mc_chroma_dir(s, s->dsp.mc[bwl][b->filter][1],\n b->dst[1], b->dst[2], ls_uv,\n ref2->data[1], ref2->linesize[1],\n ref2->data[2], ref2->linesize[2],\n row << 2, col << 2, &mvuv, bw, bh, w, h);\n }\n }\n if (!b->skip) {\n int w4 = bwh_tab[1][b->bs][0] << 1, step1d = 1 << b->tx, n;\n int h4 = bwh_tab[1][b->bs][1] << 1, x, y, step = 1 << (b->tx * 2);\n int end_x = FFMIN(2 * (s->cols - col), w4);\n int end_y = FFMIN(2 * (s->rows - row), h4);\n int tx = 4 * s->lossless + b->tx, uvtx = b->uvtx + 4 * s->lossless;\n int uvstep1d = 1 << b->uvtx, p;\n uint8_t *dst = b->dst[0];\n for (n = 0, y = 0; y < end_y; y += step1d) {\n uint8_t *ptr = dst;\n for (x = 0; x < end_x; x += step1d, ptr += 4 * step1d, n += step) {\n int eob = b->tx > TX_8X8 ? AV_RN16A(&s->eob[n]) : s->eob[n];\n if (eob)\n s->dsp.itxfm_add[tx][DCT_DCT](ptr, b->y_stride,\n s->block + 16 * n, eob);\n }\n dst += 4 * b->y_stride * step1d;\n }\n h4 >>= 1;\n w4 >>= 1;\n end_x >>= 1;\n end_y >>= 1;\n step = 1 << (b->uvtx * 2);\n for (p = 0; p < 2; p++) {\n dst = b->dst[p + 1];\n for (n = 0, y = 0; y < end_y; y += uvstep1d) {\n uint8_t *ptr = dst;\n for (x = 0; x < end_x; x += uvstep1d, ptr += 4 * uvstep1d, n += step) {\n int eob = b->uvtx > TX_8X8 ? AV_RN16A(&s->uveob[p][n])\n : s->uveob[p][n];\n if (eob)\n s->dsp.itxfm_add[uvtx][DCT_DCT](ptr, b->uv_stride,\n s->uvblock[p] + 16 * n, eob);\n }\n dst += 4 * uvstep1d * b->uv_stride;\n }\n }\n }\n return 0;\n}']
33,560
0
https://github.com/libav/libav/blob/60a42ef44cc02a8b6a0f0b92ab92c6f9a4ddc838/libavcodec/smacker.c/#L318
static int decode_header_trees(SmackVContext *smk) { GetBitContext gb; int mmap_size, mclr_size, full_size, type_size; mmap_size = AV_RL32(smk->avctx->extradata); mclr_size = AV_RL32(smk->avctx->extradata + 4); full_size = AV_RL32(smk->avctx->extradata + 8); type_size = AV_RL32(smk->avctx->extradata + 12); init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8); if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\n"); smk->mmap_tbl = av_malloc(sizeof(int) * 2); smk->mmap_tbl[0] = 0; smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1; } else { if (smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size)) return -1; } if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n"); smk->mclr_tbl = av_malloc(sizeof(int) * 2); smk->mclr_tbl[0] = 0; smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1; } else { if (smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size)) return -1; } if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n"); smk->full_tbl = av_malloc(sizeof(int) * 2); smk->full_tbl[0] = 0; smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1; } else { if (smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size)) return -1; } if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n"); smk->type_tbl = av_malloc(sizeof(int) * 2); smk->type_tbl[0] = 0; smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1; } else { if (smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size)) return -1; } return 0; }
['static int decode_header_trees(SmackVContext *smk) {\n GetBitContext gb;\n int mmap_size, mclr_size, full_size, type_size;\n mmap_size = AV_RL32(smk->avctx->extradata);\n mclr_size = AV_RL32(smk->avctx->extradata + 4);\n full_size = AV_RL32(smk->avctx->extradata + 8);\n type_size = AV_RL32(smk->avctx->extradata + 12);\n init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8);\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\\n");\n smk->mmap_tbl = av_malloc(sizeof(int) * 2);\n smk->mmap_tbl[0] = 0;\n smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size))\n return -1;\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\\n");\n smk->mclr_tbl = av_malloc(sizeof(int) * 2);\n smk->mclr_tbl[0] = 0;\n smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size))\n return -1;\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\\n");\n smk->full_tbl = av_malloc(sizeof(int) * 2);\n smk->full_tbl[0] = 0;\n smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size))\n return -1;\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\\n");\n smk->type_tbl = av_malloc(sizeof(int) * 2);\n smk->type_tbl[0] = 0;\n smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size))\n return -1;\n }\n return 0;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size <= 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n ret = AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n return ret;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\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}']
33,561
0
https://github.com/libav/libav/blob/e5b019725f53b79159931d3a7317107cbbfd0860/libavcodec/dxv.c/#L129
static int dxv_decompress_dxt1(AVCodecContext *avctx) { DXVContext *ctx = avctx->priv_data; GetByteContext *gbc = &ctx->gbc; uint32_t value, prev, op; int idx = 0, state = 0; int pos = 2; AV_WL32(ctx->tex_data, bytestream2_get_le32(gbc)); AV_WL32(ctx->tex_data + 4, bytestream2_get_le32(gbc)); while (pos + 2 <= ctx->tex_size / 4) { CHECKPOINT(2); if (op) { prev = AV_RL32(ctx->tex_data + 4 * (pos - idx)); AV_WL32(ctx->tex_data + 4 * pos, prev); pos++; prev = AV_RL32(ctx->tex_data + 4 * (pos - idx)); AV_WL32(ctx->tex_data + 4 * pos, prev); pos++; } else { CHECKPOINT(2); if (op) prev = AV_RL32(ctx->tex_data + 4 * (pos - idx)); else prev = bytestream2_get_le32(gbc); AV_WL32(ctx->tex_data + 4 * pos, prev); pos++; CHECKPOINT(2); if (op) prev = AV_RL32(ctx->tex_data + 4 * (pos - idx)); else prev = bytestream2_get_le32(gbc); AV_WL32(ctx->tex_data + 4 * pos, prev); pos++; } } return 0; }
['static int dxv_decompress_dxt1(AVCodecContext *avctx)\n{\n DXVContext *ctx = avctx->priv_data;\n GetByteContext *gbc = &ctx->gbc;\n uint32_t value, prev, op;\n int idx = 0, state = 0;\n int pos = 2;\n AV_WL32(ctx->tex_data, bytestream2_get_le32(gbc));\n AV_WL32(ctx->tex_data + 4, bytestream2_get_le32(gbc));\n while (pos + 2 <= ctx->tex_size / 4) {\n CHECKPOINT(2);\n if (op) {\n prev = AV_RL32(ctx->tex_data + 4 * (pos - idx));\n AV_WL32(ctx->tex_data + 4 * pos, prev);\n pos++;\n prev = AV_RL32(ctx->tex_data + 4 * (pos - idx));\n AV_WL32(ctx->tex_data + 4 * pos, prev);\n pos++;\n } else {\n CHECKPOINT(2);\n if (op)\n prev = AV_RL32(ctx->tex_data + 4 * (pos - idx));\n else\n prev = bytestream2_get_le32(gbc);\n AV_WL32(ctx->tex_data + 4 * pos, prev);\n pos++;\n CHECKPOINT(2);\n if (op)\n prev = AV_RL32(ctx->tex_data + 4 * (pos - idx));\n else\n prev = bytestream2_get_le32(gbc);\n AV_WL32(ctx->tex_data + 4 * pos, prev);\n pos++;\n }\n }\n return 0;\n}']
33,562
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)]; }
['static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,\n BIGNUM **kinvp, BIGNUM **rp,\n const unsigned char *dgst, int dlen)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *k, *kinv = NULL, *r = *rp;\n BIGNUM *l;\n int ret = 0;\n int q_bits, q_words;\n if (!dsa->p || !dsa->q || !dsa->g) {\n DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS);\n return 0;\n }\n k = BN_new();\n l = BN_new();\n if (k == NULL || l == NULL)\n goto err;\n if (ctx_in == NULL) {\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n } else\n ctx = ctx_in;\n q_bits = BN_num_bits(dsa->q);\n q_words = bn_get_top(dsa->q);\n if (!bn_wexpand(k, q_words + 2)\n || !bn_wexpand(l, q_words + 2))\n goto err;\n do {\n if (dgst != NULL) {\n if (!BN_generate_dsa_nonce(k, dsa->q, dsa->priv_key, dgst,\n dlen, ctx))\n goto err;\n } else if (!BN_priv_rand_range(k, dsa->q))\n goto err;\n } while (BN_is_zero(k));\n BN_set_flags(k, BN_FLG_CONSTTIME);\n BN_set_flags(l, BN_FLG_CONSTTIME);\n if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n dsa->lock, dsa->p, ctx))\n goto err;\n }\n if (!BN_add(l, k, dsa->q)\n || !BN_add(k, l, dsa->q))\n goto err;\n BN_consttime_swap(BN_is_bit_set(l, q_bits), k, l, q_words + 2);\n if ((dsa)->meth->bn_mod_exp != NULL) {\n if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx,\n dsa->method_mont_p))\n goto err;\n } else {\n if (!BN_mod_exp_mont(r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p))\n goto err;\n }\n if (!BN_mod(r, r, dsa->q, ctx))\n goto err;\n if ((kinv = dsa_mod_inverse_fermat(k, dsa->q, ctx)) == NULL)\n goto err;\n BN_clear_free(*kinvp);\n *kinvp = kinv;\n kinv = NULL;\n ret = 1;\n err:\n if (!ret)\n DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n BN_clear_free(k);\n BN_clear_free(l);\n return ret;\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}', '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}']
33,563
0
https://github.com/libav/libav/blob/baf35bb4bc4fe7a2a4113c50989d11dd9ef81e76/libavcodec/faanidct.c/#L58
static inline void p8idct(int16_t data[64], FLOAT temp[64], uint8_t *dest, int stride, int x, int y, int type){ int i; FLOAT av_unused tmp0; FLOAT s04, d04, s17, d17, s26, d26, s53, d53; FLOAT os07, os16, os25, os34; FLOAT od07, od16, od25, od34; for(i=0; i<y*8; i+=y){ s17= temp[1*x + i] + temp[7*x + i]; d17= temp[1*x + i] - temp[7*x + i]; s53= temp[5*x + i] + temp[3*x + i]; d53= temp[5*x + i] - temp[3*x + i]; od07= s17 + s53; od25= (s17 - s53)*(2*A4); #if 0 tmp0= (d17 + d53)*(2*A2); od34= d17*( 2*B6) - tmp0; od16= d53*(-2*B2) + tmp0; #else od34= d17*(2*(B6-A2)) - d53*(2*A2); od16= d53*(2*(A2-B2)) + d17*(2*A2); #endif od16 -= od07; od25 -= od16; od34 += od25; s26 = temp[2*x + i] + temp[6*x + i]; d26 = temp[2*x + i] - temp[6*x + i]; d26*= 2*A4; d26-= s26; s04= temp[0*x + i] + temp[4*x + i]; d04= temp[0*x + i] - temp[4*x + i]; os07= s04 + s26; os34= s04 - s26; os16= d04 + d26; os25= d04 - d26; if(type==0){ temp[0*x + i]= os07 + od07; temp[7*x + i]= os07 - od07; temp[1*x + i]= os16 + od16; temp[6*x + i]= os16 - od16; temp[2*x + i]= os25 + od25; temp[5*x + i]= os25 - od25; temp[3*x + i]= os34 - od34; temp[4*x + i]= os34 + od34; }else if(type==1){ data[0*x + i]= lrintf(os07 + od07); data[7*x + i]= lrintf(os07 - od07); data[1*x + i]= lrintf(os16 + od16); data[6*x + i]= lrintf(os16 - od16); data[2*x + i]= lrintf(os25 + od25); data[5*x + i]= lrintf(os25 - od25); data[3*x + i]= lrintf(os34 - od34); data[4*x + i]= lrintf(os34 + od34); }else if(type==2){ dest[0*stride + i]= av_clip_uint8(((int)dest[0*stride + i]) + lrintf(os07 + od07)); dest[7*stride + i]= av_clip_uint8(((int)dest[7*stride + i]) + lrintf(os07 - od07)); dest[1*stride + i]= av_clip_uint8(((int)dest[1*stride + i]) + lrintf(os16 + od16)); dest[6*stride + i]= av_clip_uint8(((int)dest[6*stride + i]) + lrintf(os16 - od16)); dest[2*stride + i]= av_clip_uint8(((int)dest[2*stride + i]) + lrintf(os25 + od25)); dest[5*stride + i]= av_clip_uint8(((int)dest[5*stride + i]) + lrintf(os25 - od25)); dest[3*stride + i]= av_clip_uint8(((int)dest[3*stride + i]) + lrintf(os34 - od34)); dest[4*stride + i]= av_clip_uint8(((int)dest[4*stride + i]) + lrintf(os34 + od34)); }else{ dest[0*stride + i]= av_clip_uint8(lrintf(os07 + od07)); dest[7*stride + i]= av_clip_uint8(lrintf(os07 - od07)); dest[1*stride + i]= av_clip_uint8(lrintf(os16 + od16)); dest[6*stride + i]= av_clip_uint8(lrintf(os16 - od16)); dest[2*stride + i]= av_clip_uint8(lrintf(os25 + od25)); dest[5*stride + i]= av_clip_uint8(lrintf(os25 - od25)); dest[3*stride + i]= av_clip_uint8(lrintf(os34 - od34)); dest[4*stride + i]= av_clip_uint8(lrintf(os34 + od34)); } } }
['void ff_faanidct(int16_t block[64]){\n FLOAT temp[64];\n int i;\n emms_c();\n for(i=0; i<64; i++)\n temp[i] = block[i] * prescale[i];\n p8idct(block, temp, NULL, 0, 1, 8, 0);\n p8idct(block, temp, NULL, 0, 8, 1, 1);\n}', 'static inline void p8idct(int16_t data[64], FLOAT temp[64], uint8_t *dest, int stride, int x, int y, int type){\n int i;\n FLOAT av_unused tmp0;\n FLOAT s04, d04, s17, d17, s26, d26, s53, d53;\n FLOAT os07, os16, os25, os34;\n FLOAT od07, od16, od25, od34;\n for(i=0; i<y*8; i+=y){\n s17= temp[1*x + i] + temp[7*x + i];\n d17= temp[1*x + i] - temp[7*x + i];\n s53= temp[5*x + i] + temp[3*x + i];\n d53= temp[5*x + i] - temp[3*x + i];\n od07= s17 + s53;\n od25= (s17 - s53)*(2*A4);\n#if 0\n tmp0= (d17 + d53)*(2*A2);\n od34= d17*( 2*B6) - tmp0;\n od16= d53*(-2*B2) + tmp0;\n#else\n od34= d17*(2*(B6-A2)) - d53*(2*A2);\n od16= d53*(2*(A2-B2)) + d17*(2*A2);\n#endif\n od16 -= od07;\n od25 -= od16;\n od34 += od25;\n s26 = temp[2*x + i] + temp[6*x + i];\n d26 = temp[2*x + i] - temp[6*x + i];\n d26*= 2*A4;\n d26-= s26;\n s04= temp[0*x + i] + temp[4*x + i];\n d04= temp[0*x + i] - temp[4*x + i];\n os07= s04 + s26;\n os34= s04 - s26;\n os16= d04 + d26;\n os25= d04 - d26;\n if(type==0){\n temp[0*x + i]= os07 + od07;\n temp[7*x + i]= os07 - od07;\n temp[1*x + i]= os16 + od16;\n temp[6*x + i]= os16 - od16;\n temp[2*x + i]= os25 + od25;\n temp[5*x + i]= os25 - od25;\n temp[3*x + i]= os34 - od34;\n temp[4*x + i]= os34 + od34;\n }else if(type==1){\n data[0*x + i]= lrintf(os07 + od07);\n data[7*x + i]= lrintf(os07 - od07);\n data[1*x + i]= lrintf(os16 + od16);\n data[6*x + i]= lrintf(os16 - od16);\n data[2*x + i]= lrintf(os25 + od25);\n data[5*x + i]= lrintf(os25 - od25);\n data[3*x + i]= lrintf(os34 - od34);\n data[4*x + i]= lrintf(os34 + od34);\n }else if(type==2){\n dest[0*stride + i]= av_clip_uint8(((int)dest[0*stride + i]) + lrintf(os07 + od07));\n dest[7*stride + i]= av_clip_uint8(((int)dest[7*stride + i]) + lrintf(os07 - od07));\n dest[1*stride + i]= av_clip_uint8(((int)dest[1*stride + i]) + lrintf(os16 + od16));\n dest[6*stride + i]= av_clip_uint8(((int)dest[6*stride + i]) + lrintf(os16 - od16));\n dest[2*stride + i]= av_clip_uint8(((int)dest[2*stride + i]) + lrintf(os25 + od25));\n dest[5*stride + i]= av_clip_uint8(((int)dest[5*stride + i]) + lrintf(os25 - od25));\n dest[3*stride + i]= av_clip_uint8(((int)dest[3*stride + i]) + lrintf(os34 - od34));\n dest[4*stride + i]= av_clip_uint8(((int)dest[4*stride + i]) + lrintf(os34 + od34));\n }else{\n dest[0*stride + i]= av_clip_uint8(lrintf(os07 + od07));\n dest[7*stride + i]= av_clip_uint8(lrintf(os07 - od07));\n dest[1*stride + i]= av_clip_uint8(lrintf(os16 + od16));\n dest[6*stride + i]= av_clip_uint8(lrintf(os16 - od16));\n dest[2*stride + i]= av_clip_uint8(lrintf(os25 + od25));\n dest[5*stride + i]= av_clip_uint8(lrintf(os25 - od25));\n dest[3*stride + i]= av_clip_uint8(lrintf(os34 - od34));\n dest[4*stride + i]= av_clip_uint8(lrintf(os34 + od34));\n }\n }\n}']
33,564
0
https://github.com/libav/libav/blob/39bec05ed42e505d17877b0c23f16322f9b5883b/libavcodec/h264_mvpred.h/#L672
static void fill_decode_caches(H264Context *h, int mb_type) { int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; int topleft_type, top_type, topright_type, left_type[LEFT_MBS]; const uint8_t *left_block = h->left_block; int i; uint8_t *nnz; uint8_t *nnz_cache; topleft_xy = h->topleft_mb_xy; top_xy = h->top_mb_xy; topright_xy = h->topright_mb_xy; left_xy[LTOP] = h->left_mb_xy[LTOP]; left_xy[LBOT] = h->left_mb_xy[LBOT]; topleft_type = h->topleft_type; top_type = h->top_type; topright_type = h->topright_type; left_type[LTOP] = h->left_type[LTOP]; left_type[LBOT] = h->left_type[LBOT]; if (!IS_SKIP(mb_type)) { if (IS_INTRA(mb_type)) { int type_mask = h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1; h->topleft_samples_available = h->top_samples_available = h->left_samples_available = 0xFFFF; h->topright_samples_available = 0xEEEA; if (!(top_type & type_mask)) { h->topleft_samples_available = 0xB3FF; h->top_samples_available = 0x33FF; h->topright_samples_available = 0x26EA; } if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) { if (IS_INTERLACED(mb_type)) { if (!(left_type[LTOP] & type_mask)) { h->topleft_samples_available &= 0xDFFF; h->left_samples_available &= 0x5FFF; } if (!(left_type[LBOT] & type_mask)) { h->topleft_samples_available &= 0xFF5F; h->left_samples_available &= 0xFF5F; } } else { int left_typei = h->cur_pic.f.mb_type[left_xy[LTOP] + h->mb_stride]; assert(left_xy[LTOP] == left_xy[LBOT]); if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) { h->topleft_samples_available &= 0xDF5F; h->left_samples_available &= 0x5F5F; } } } else { if (!(left_type[LTOP] & type_mask)) { h->topleft_samples_available &= 0xDF5F; h->left_samples_available &= 0x5F5F; } } if (!(topleft_type & type_mask)) h->topleft_samples_available &= 0x7FFF; if (!(topright_type & type_mask)) h->topright_samples_available &= 0xFBFF; if (IS_INTRA4x4(mb_type)) { if (IS_INTRA4x4(top_type)) { AV_COPY32(h->intra4x4_pred_mode_cache + 4 + 8 * 0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]); } else { h->intra4x4_pred_mode_cache[4 + 8 * 0] = h->intra4x4_pred_mode_cache[5 + 8 * 0] = h->intra4x4_pred_mode_cache[6 + 8 * 0] = h->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask); } for (i = 0; i < 2; i++) { if (IS_INTRA4x4(left_type[LEFT(i)])) { int8_t *mode = h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]]; h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]]; h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]]; } else { h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask); } } } } nnz_cache = h->non_zero_count_cache; if (top_type) { nnz = h->non_zero_count[top_xy]; AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]); if (!h->chroma_y_shift) { AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]); AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]); } else { AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]); AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]); } } else { uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040; AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty); AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty); AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty); } for (i = 0; i < 2; i++) { if (left_type[LEFT(i)]) { nnz = h->non_zero_count[left_xy[LEFT(i)]]; nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]]; nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]]; if (CHROMA444) { nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4]; nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4]; nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4]; nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4]; } else if (CHROMA422) { nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4]; nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4]; nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4]; nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4]; } else { nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]]; nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]]; } } else { nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz_cache[3 + 8 * 12 + 2 * 8 * i] = CABAC && !IS_INTRA(mb_type) ? 0 : 64; } } if (CABAC) { if (top_type) h->top_cbp = h->cbp_table[top_xy]; else h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; if (left_type[LTOP]) { h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) | ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) | (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2); } else { h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; } } } if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)) { int list; int b_stride = h->b_stride; for (list = 0; list < h->list_count; list++) { int8_t *ref_cache = &h->ref_cache[list][scan8[0]]; int8_t *ref = h->cur_pic.f.ref_index[list]; int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]]; int16_t(*mv)[2] = h->cur_pic.f.motion_val[list]; if (!USES_LIST(mb_type, list)) continue; assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); if (USES_LIST(top_type, list)) { const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride; AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]); ref_cache[0 - 1 * 8] = ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2]; ref_cache[2 - 1 * 8] = ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3]; } else { AV_ZERO128(mv_cache[0 - 1 * 8]); AV_WN32A(&ref_cache[0 - 1 * 8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u); } if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) { for (i = 0; i < 2; i++) { int cache_idx = -1 + i * 2 * 8; if (USES_LIST(left_type[LEFT(i)], list)) { const int b_xy = h->mb2b_xy[left_xy[LEFT(i)]] + 3; const int b8_xy = 4 * left_xy[LEFT(i)] + 1; AV_COPY32(mv_cache[cache_idx], mv[b_xy + b_stride * left_block[0 + i * 2]]); AV_COPY32(mv_cache[cache_idx + 8], mv[b_xy + b_stride * left_block[1 + i * 2]]); ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)]; ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)]; } else { AV_ZERO32(mv_cache[cache_idx]); AV_ZERO32(mv_cache[cache_idx + 8]); ref_cache[cache_idx] = ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } } else { if (USES_LIST(left_type[LTOP], list)) { const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3; const int b8_xy = 4 * left_xy[LTOP] + 1; AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]); ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)]; } else { AV_ZERO32(mv_cache[-1]); ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if (USES_LIST(topright_type, list)) { const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride; AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]); ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2]; } else { AV_ZERO32(mv_cache[4 - 1 * 8]); ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } if (ref_cache[4 - 1 * 8] < 0) { if (USES_LIST(topleft_type, list)) { const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2 * b_stride); const int b8_xy = 4 * topleft_xy + 1 + (h->topleft_partition & 2); AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]); ref_cache[-1 - 1 * 8] = ref[b8_xy]; } else { AV_ZERO32(mv_cache[-1 - 1 * 8]); ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF) continue; if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) { uint8_t(*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]]; uint8_t(*mvd)[2] = h->mvd_table[list]; ref_cache[2 + 8 * 0] = ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE; AV_ZERO32(mv_cache[2 + 8 * 0]); AV_ZERO32(mv_cache[2 + 8 * 2]); if (CABAC) { if (USES_LIST(top_type, list)) { const int b_xy = h->mb2br_xy[top_xy]; AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]); } else { AV_ZERO64(mvd_cache[0 - 1 * 8]); } if (USES_LIST(left_type[LTOP], list)) { const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6; AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]); AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]); } else { AV_ZERO16(mvd_cache[-1 + 0 * 8]); AV_ZERO16(mvd_cache[-1 + 1 * 8]); } if (USES_LIST(left_type[LBOT], list)) { const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6; AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]); AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]); } else { AV_ZERO16(mvd_cache[-1 + 2 * 8]); AV_ZERO16(mvd_cache[-1 + 3 * 8]); } AV_ZERO16(mvd_cache[2 + 8 * 0]); AV_ZERO16(mvd_cache[2 + 8 * 2]); if (h->slice_type_nos == AV_PICTURE_TYPE_B) { uint8_t *direct_cache = &h->direct_cache[scan8[0]]; uint8_t *direct_table = h->direct_table; fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1); if (IS_DIRECT(top_type)) { AV_WN32A(&direct_cache[-1 * 8], 0x01010101u * (MB_TYPE_DIRECT2 >> 1)); } else if (IS_8X8(top_type)) { int b8_xy = 4 * top_xy; direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2]; direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3]; } else { AV_WN32A(&direct_cache[-1 * 8], 0x01010101 * (MB_TYPE_16x16 >> 1)); } if (IS_DIRECT(left_type[LTOP])) direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1; else if (IS_8X8(left_type[LTOP])) direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)]; else direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1; if (IS_DIRECT(left_type[LBOT])) direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1; else if (IS_8X8(left_type[LBOT])) direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)]; else direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1; } } } #define MAP_MVS \ MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \ MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \ MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \ MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \ MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \ MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT]) if (FRAME_MBAFF) { if (MB_FIELD) { #define MAP_F2F(idx, mb_type) \ if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \ h->ref_cache[list][idx] <<= 1; \ h->mv_cache[list][idx][1] /= 2; \ h->mvd_cache[list][idx][1] >>= 1; \ } MAP_MVS } else { #undef MAP_F2F #define MAP_F2F(idx, mb_type) \ if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \ h->ref_cache[list][idx] >>= 1; \ h->mv_cache[list][idx][1] <<= 1; \ h->mvd_cache[list][idx][1] <<= 1; \ } MAP_MVS #undef MAP_F2F } } } } h->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]); }
['static void fill_decode_caches(H264Context *h, int mb_type)\n{\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n int topleft_type, top_type, topright_type, left_type[LEFT_MBS];\n const uint8_t *left_block = h->left_block;\n int i;\n uint8_t *nnz;\n uint8_t *nnz_cache;\n topleft_xy = h->topleft_mb_xy;\n top_xy = h->top_mb_xy;\n topright_xy = h->topright_mb_xy;\n left_xy[LTOP] = h->left_mb_xy[LTOP];\n left_xy[LBOT] = h->left_mb_xy[LBOT];\n topleft_type = h->topleft_type;\n top_type = h->top_type;\n topright_type = h->topright_type;\n left_type[LTOP] = h->left_type[LTOP];\n left_type[LBOT] = h->left_type[LBOT];\n if (!IS_SKIP(mb_type)) {\n if (IS_INTRA(mb_type)) {\n int type_mask = h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available =\n h->top_samples_available =\n h->left_samples_available = 0xFFFF;\n h->topright_samples_available = 0xEEEA;\n if (!(top_type & type_mask)) {\n h->topleft_samples_available = 0xB3FF;\n h->top_samples_available = 0x33FF;\n h->topright_samples_available = 0x26EA;\n }\n if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {\n if (IS_INTERLACED(mb_type)) {\n if (!(left_type[LTOP] & type_mask)) {\n h->topleft_samples_available &= 0xDFFF;\n h->left_samples_available &= 0x5FFF;\n }\n if (!(left_type[LBOT] & type_mask)) {\n h->topleft_samples_available &= 0xFF5F;\n h->left_samples_available &= 0xFF5F;\n }\n } else {\n int left_typei = h->cur_pic.f.mb_type[left_xy[LTOP] + h->mb_stride];\n assert(left_xy[LTOP] == left_xy[LBOT]);\n if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {\n h->topleft_samples_available &= 0xDF5F;\n h->left_samples_available &= 0x5F5F;\n }\n }\n } else {\n if (!(left_type[LTOP] & type_mask)) {\n h->topleft_samples_available &= 0xDF5F;\n h->left_samples_available &= 0x5F5F;\n }\n }\n if (!(topleft_type & type_mask))\n h->topleft_samples_available &= 0x7FFF;\n if (!(topright_type & type_mask))\n h->topright_samples_available &= 0xFBFF;\n if (IS_INTRA4x4(mb_type)) {\n if (IS_INTRA4x4(top_type)) {\n AV_COPY32(h->intra4x4_pred_mode_cache + 4 + 8 * 0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);\n } else {\n h->intra4x4_pred_mode_cache[4 + 8 * 0] =\n h->intra4x4_pred_mode_cache[5 + 8 * 0] =\n h->intra4x4_pred_mode_cache[6 + 8 * 0] =\n h->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);\n }\n for (i = 0; i < 2; i++) {\n if (IS_INTRA4x4(left_type[LEFT(i)])) {\n int8_t *mode = h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];\n h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];\n h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];\n } else {\n h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =\n h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);\n }\n }\n }\n }\n nnz_cache = h->non_zero_count_cache;\n if (top_type) {\n nnz = h->non_zero_count[top_xy];\n AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);\n if (!h->chroma_y_shift) {\n AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]);\n AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);\n } else {\n AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]);\n AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);\n }\n } else {\n uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty);\n AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty);\n AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);\n }\n for (i = 0; i < 2; i++) {\n if (left_type[LEFT(i)]) {\n nnz = h->non_zero_count[left_xy[LEFT(i)]];\n nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];\n nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];\n if (CHROMA444) {\n nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];\n nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];\n nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];\n nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];\n } else if (CHROMA422) {\n nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];\n nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];\n nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];\n nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];\n } else {\n nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];\n nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];\n }\n } else {\n nnz_cache[3 + 8 * 1 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 2 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 6 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 7 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 11 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 12 + 2 * 8 * i] = CABAC && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if (CABAC) {\n if (top_type)\n h->top_cbp = h->cbp_table[top_xy];\n else\n h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n if (left_type[LTOP]) {\n h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) |\n ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |\n (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);\n } else {\n h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n }\n }\n if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)) {\n int list;\n int b_stride = h->b_stride;\n for (list = 0; list < h->list_count; list++) {\n int8_t *ref_cache = &h->ref_cache[list][scan8[0]];\n int8_t *ref = h->cur_pic.f.ref_index[list];\n int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]];\n int16_t(*mv)[2] = h->cur_pic.f.motion_val[list];\n if (!USES_LIST(mb_type, list))\n continue;\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n if (USES_LIST(top_type, list)) {\n const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;\n AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);\n ref_cache[0 - 1 * 8] =\n ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];\n ref_cache[2 - 1 * 8] =\n ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];\n } else {\n AV_ZERO128(mv_cache[0 - 1 * 8]);\n AV_WN32A(&ref_cache[0 - 1 * 8],\n ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);\n }\n if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {\n for (i = 0; i < 2; i++) {\n int cache_idx = -1 + i * 2 * 8;\n if (USES_LIST(left_type[LEFT(i)], list)) {\n const int b_xy = h->mb2b_xy[left_xy[LEFT(i)]] + 3;\n const int b8_xy = 4 * left_xy[LEFT(i)] + 1;\n AV_COPY32(mv_cache[cache_idx],\n mv[b_xy + b_stride * left_block[0 + i * 2]]);\n AV_COPY32(mv_cache[cache_idx + 8],\n mv[b_xy + b_stride * left_block[1 + i * 2]]);\n ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)];\n ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];\n } else {\n AV_ZERO32(mv_cache[cache_idx]);\n AV_ZERO32(mv_cache[cache_idx + 8]);\n ref_cache[cache_idx] =\n ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n } else {\n if (USES_LIST(left_type[LTOP], list)) {\n const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3;\n const int b8_xy = 4 * left_xy[LTOP] + 1;\n AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);\n ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];\n } else {\n AV_ZERO32(mv_cache[-1]);\n ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n if (USES_LIST(topright_type, list)) {\n const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;\n AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);\n ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];\n } else {\n AV_ZERO32(mv_cache[4 - 1 * 8]);\n ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n if (ref_cache[4 - 1 * 8] < 0) {\n if (USES_LIST(topleft_type, list)) {\n const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride +\n (h->topleft_partition & 2 * b_stride);\n const int b8_xy = 4 * topleft_xy + 1 + (h->topleft_partition & 2);\n AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);\n ref_cache[-1 - 1 * 8] = ref[b8_xy];\n } else {\n AV_ZERO32(mv_cache[-1 - 1 * 8]);\n ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF)\n continue;\n if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) {\n uint8_t(*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];\n uint8_t(*mvd)[2] = h->mvd_table[list];\n ref_cache[2 + 8 * 0] =\n ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE;\n AV_ZERO32(mv_cache[2 + 8 * 0]);\n AV_ZERO32(mv_cache[2 + 8 * 2]);\n if (CABAC) {\n if (USES_LIST(top_type, list)) {\n const int b_xy = h->mb2br_xy[top_xy];\n AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);\n } else {\n AV_ZERO64(mvd_cache[0 - 1 * 8]);\n }\n if (USES_LIST(left_type[LTOP], list)) {\n const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;\n AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);\n AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);\n } else {\n AV_ZERO16(mvd_cache[-1 + 0 * 8]);\n AV_ZERO16(mvd_cache[-1 + 1 * 8]);\n }\n if (USES_LIST(left_type[LBOT], list)) {\n const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;\n AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);\n AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);\n } else {\n AV_ZERO16(mvd_cache[-1 + 2 * 8]);\n AV_ZERO16(mvd_cache[-1 + 3 * 8]);\n }\n AV_ZERO16(mvd_cache[2 + 8 * 0]);\n AV_ZERO16(mvd_cache[2 + 8 * 2]);\n if (h->slice_type_nos == AV_PICTURE_TYPE_B) {\n uint8_t *direct_cache = &h->direct_cache[scan8[0]];\n uint8_t *direct_table = h->direct_table;\n fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);\n if (IS_DIRECT(top_type)) {\n AV_WN32A(&direct_cache[-1 * 8],\n 0x01010101u * (MB_TYPE_DIRECT2 >> 1));\n } else if (IS_8X8(top_type)) {\n int b8_xy = 4 * top_xy;\n direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];\n direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];\n } else {\n AV_WN32A(&direct_cache[-1 * 8],\n 0x01010101 * (MB_TYPE_16x16 >> 1));\n }\n if (IS_DIRECT(left_type[LTOP]))\n direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;\n else if (IS_8X8(left_type[LTOP]))\n direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];\n else\n direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;\n if (IS_DIRECT(left_type[LBOT]))\n direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;\n else if (IS_8X8(left_type[LBOT]))\n direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];\n else\n direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;\n }\n }\n }\n#define MAP_MVS \\\n MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \\\n MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \\\n MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \\\n MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \\\n MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \\\n MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])\n if (FRAME_MBAFF) {\n if (MB_FIELD) {\n#define MAP_F2F(idx, mb_type) \\\n if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \\\n h->ref_cache[list][idx] <<= 1; \\\n h->mv_cache[list][idx][1] /= 2; \\\n h->mvd_cache[list][idx][1] >>= 1; \\\n }\n MAP_MVS\n } else {\n#undef MAP_F2F\n#define MAP_F2F(idx, mb_type) \\\n if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \\\n h->ref_cache[list][idx] >>= 1; \\\n h->mv_cache[list][idx][1] <<= 1; \\\n h->mvd_cache[list][idx][1] <<= 1; \\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n h->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);\n}']
33,565
0
https://github.com/openssl/openssl/blob/05ec6a25f80ac8edfb7d7cb764d2dd68156a6965/crypto/x509/x509_obj.c/#L56
char *X509_NAME_oneline(X509_NAME *a, char *buf, int len) { X509_NAME_ENTRY *ne; int i; int n, lold, l, l1, l2, num, j, type; const char *s; char *p; unsigned char *q; BUF_MEM *b = NULL; static const char hex[17] = "0123456789ABCDEF"; int gs_doit[4]; char tmp_buf[80]; #ifdef CHARSET_EBCDIC unsigned char ebcdic_buf[1024]; #endif if (buf == NULL) { if ((b = BUF_MEM_new()) == NULL) goto err; if (!BUF_MEM_grow(b, 200)) goto err; b->data[0] = '\0'; len = 200; } else if (len == 0) { return NULL; } if (a == NULL) { if (b) { buf = b->data; OPENSSL_free(b); } strncpy(buf, "NO X509_NAME", len); buf[len - 1] = '\0'; return buf; } len--; l = 0; for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { ne = sk_X509_NAME_ENTRY_value(a->entries, i); n = OBJ_obj2nid(ne->object); if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) { i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object); s = tmp_buf; } l1 = strlen(s); type = ne->value->type; num = ne->value->length; if (num > NAME_ONELINE_MAX) { X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG); goto end; } q = ne->value->data; #ifdef CHARSET_EBCDIC if (type == V_ASN1_GENERALSTRING || type == V_ASN1_VISIBLESTRING || type == V_ASN1_PRINTABLESTRING || type == V_ASN1_TELETEXSTRING || type == V_ASN1_IA5STRING) { if (num > (int)sizeof(ebcdic_buf)) num = sizeof(ebcdic_buf); ascii2ebcdic(ebcdic_buf, q, num); q = ebcdic_buf; } #endif if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) { gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0; for (j = 0; j < num; j++) if (q[j] != 0) gs_doit[j & 3] = 1; if (gs_doit[0] | gs_doit[1] | gs_doit[2]) gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1; else { gs_doit[0] = gs_doit[1] = gs_doit[2] = 0; gs_doit[3] = 1; } } else gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1; for (l2 = j = 0; j < num; j++) { if (!gs_doit[j & 3]) continue; l2++; #ifndef CHARSET_EBCDIC if ((q[j] < ' ') || (q[j] > '~')) l2 += 3; #else if ((os_toascii[q[j]] < os_toascii[' ']) || (os_toascii[q[j]] > os_toascii['~'])) l2 += 3; #endif } lold = l; l += 1 + l1 + 1 + l2; if (l > NAME_ONELINE_MAX) { X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG); goto end; } if (b != NULL) { if (!BUF_MEM_grow(b, l + 1)) goto err; p = &(b->data[lold]); } else if (l > len) { break; } else p = &(buf[lold]); *(p++) = '/'; memcpy(p, s, (unsigned int)l1); p += l1; *(p++) = '='; #ifndef CHARSET_EBCDIC q = ne->value->data; #endif for (j = 0; j < num; j++) { if (!gs_doit[j & 3]) continue; #ifndef CHARSET_EBCDIC n = q[j]; if ((n < ' ') || (n > '~')) { *(p++) = '\\'; *(p++) = 'x'; *(p++) = hex[(n >> 4) & 0x0f]; *(p++) = hex[n & 0x0f]; } else *(p++) = n; #else n = os_toascii[q[j]]; if ((n < os_toascii[' ']) || (n > os_toascii['~'])) { *(p++) = '\\'; *(p++) = 'x'; *(p++) = hex[(n >> 4) & 0x0f]; *(p++) = hex[n & 0x0f]; } else *(p++) = q[j]; #endif } *p = '\0'; } if (b != NULL) { p = b->data; OPENSSL_free(b); } else p = buf; if (i == 0) *p = '\0'; return (p); err: X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE); end: BUF_MEM_free(b); return (NULL); }
['static int verify_callback(int ok, X509_STORE_CTX *ctx)\n{\n char *s, buf[256];\n s = X509_NAME_oneline(X509_get_subject_name(X509_STORE_CTX_get_current_cert(ctx)),\n buf, sizeof buf);\n if (s != NULL) {\n if (ok)\n printf("depth=%d %s\\n", X509_STORE_CTX_get_error_depth(ctx), buf);\n else {\n fprintf(stderr, "depth=%d error=%d %s\\n",\n X509_STORE_CTX_get_error_depth(ctx),\n X509_STORE_CTX_get_error(ctx), buf);\n }\n }\n if (ok == 0) {\n int i = X509_STORE_CTX_get_error(ctx);\n switch (i) {\n default:\n fprintf(stderr, "Error string: %s\\n",\n X509_verify_cert_error_string(i));\n break;\n case X509_V_ERR_CERT_NOT_YET_VALID:\n case X509_V_ERR_CERT_HAS_EXPIRED:\n case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:\n ok = 1;\n break;\n }\n }\n return (ok);\n}', 'char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)\n{\n X509_NAME_ENTRY *ne;\n int i;\n int n, lold, l, l1, l2, num, j, type;\n const char *s;\n char *p;\n unsigned char *q;\n BUF_MEM *b = NULL;\n static const char hex[17] = "0123456789ABCDEF";\n int gs_doit[4];\n char tmp_buf[80];\n#ifdef CHARSET_EBCDIC\n unsigned char ebcdic_buf[1024];\n#endif\n if (buf == NULL) {\n if ((b = BUF_MEM_new()) == NULL)\n goto err;\n if (!BUF_MEM_grow(b, 200))\n goto err;\n b->data[0] = \'\\0\';\n len = 200;\n } else if (len == 0) {\n return NULL;\n }\n if (a == NULL) {\n if (b) {\n buf = b->data;\n OPENSSL_free(b);\n }\n strncpy(buf, "NO X509_NAME", len);\n buf[len - 1] = \'\\0\';\n return buf;\n }\n len--;\n l = 0;\n for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {\n ne = sk_X509_NAME_ENTRY_value(a->entries, i);\n n = OBJ_obj2nid(ne->object);\n if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {\n i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);\n s = tmp_buf;\n }\n l1 = strlen(s);\n type = ne->value->type;\n num = ne->value->length;\n if (num > NAME_ONELINE_MAX) {\n X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);\n goto end;\n }\n q = ne->value->data;\n#ifdef CHARSET_EBCDIC\n if (type == V_ASN1_GENERALSTRING ||\n type == V_ASN1_VISIBLESTRING ||\n type == V_ASN1_PRINTABLESTRING ||\n type == V_ASN1_TELETEXSTRING ||\n type == V_ASN1_IA5STRING) {\n if (num > (int)sizeof(ebcdic_buf))\n num = sizeof(ebcdic_buf);\n ascii2ebcdic(ebcdic_buf, q, num);\n q = ebcdic_buf;\n }\n#endif\n if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;\n for (j = 0; j < num; j++)\n if (q[j] != 0)\n gs_doit[j & 3] = 1;\n if (gs_doit[0] | gs_doit[1] | gs_doit[2])\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n else {\n gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;\n gs_doit[3] = 1;\n }\n } else\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n for (l2 = j = 0; j < num; j++) {\n if (!gs_doit[j & 3])\n continue;\n l2++;\n#ifndef CHARSET_EBCDIC\n if ((q[j] < \' \') || (q[j] > \'~\'))\n l2 += 3;\n#else\n if ((os_toascii[q[j]] < os_toascii[\' \']) ||\n (os_toascii[q[j]] > os_toascii[\'~\']))\n l2 += 3;\n#endif\n }\n lold = l;\n l += 1 + l1 + 1 + l2;\n if (l > NAME_ONELINE_MAX) {\n X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);\n goto end;\n }\n if (b != NULL) {\n if (!BUF_MEM_grow(b, l + 1))\n goto err;\n p = &(b->data[lold]);\n } else if (l > len) {\n break;\n } else\n p = &(buf[lold]);\n *(p++) = \'/\';\n memcpy(p, s, (unsigned int)l1);\n p += l1;\n *(p++) = \'=\';\n#ifndef CHARSET_EBCDIC\n q = ne->value->data;\n#endif\n for (j = 0; j < num; j++) {\n if (!gs_doit[j & 3])\n continue;\n#ifndef CHARSET_EBCDIC\n n = q[j];\n if ((n < \' \') || (n > \'~\')) {\n *(p++) = \'\\\\\';\n *(p++) = \'x\';\n *(p++) = hex[(n >> 4) & 0x0f];\n *(p++) = hex[n & 0x0f];\n } else\n *(p++) = n;\n#else\n n = os_toascii[q[j]];\n if ((n < os_toascii[\' \']) || (n > os_toascii[\'~\'])) {\n *(p++) = \'\\\\\';\n *(p++) = \'x\';\n *(p++) = hex[(n >> 4) & 0x0f];\n *(p++) = hex[n & 0x0f];\n } else\n *(p++) = q[j];\n#endif\n }\n *p = \'\\0\';\n }\n if (b != NULL) {\n p = b->data;\n OPENSSL_free(b);\n } else\n p = buf;\n if (i == 0)\n *p = \'\\0\';\n return (p);\n err:\n X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);\n end:\n BUF_MEM_free(b);\n return (NULL);\n}']
33,566
0
https://github.com/libav/libav/blob/5228bcd8705523cee43e351e1a113e12aefcf837/libavcodec/h264pred.c/#L350
static void pred4x4_vertical_left_vp8_c(uint8_t *src, const uint8_t *topright, int stride){ LOAD_TOP_EDGE LOAD_TOP_RIGHT_EDGE src[0+0*stride]=(t0 + t1 + 1)>>1; src[1+0*stride]= src[0+2*stride]=(t1 + t2 + 1)>>1; src[2+0*stride]= src[1+2*stride]=(t2 + t3 + 1)>>1; src[3+0*stride]= src[2+2*stride]=(t3 + t4 + 1)>>1; src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; src[1+1*stride]= src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2; src[2+1*stride]= src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2; src[3+1*stride]= src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2; src[3+2*stride]=(t4 + 2*t5 + t6 + 2)>>2; src[3+3*stride]=(t5 + 2*t6 + t7 + 2)>>2; }
['static void pred4x4_vertical_left_vp8_c(uint8_t *src, const uint8_t *topright, int stride){\n LOAD_TOP_EDGE\n LOAD_TOP_RIGHT_EDGE\n src[0+0*stride]=(t0 + t1 + 1)>>1;\n src[1+0*stride]=\n src[0+2*stride]=(t1 + t2 + 1)>>1;\n src[2+0*stride]=\n src[1+2*stride]=(t2 + t3 + 1)>>1;\n src[3+0*stride]=\n src[2+2*stride]=(t3 + t4 + 1)>>1;\n src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;\n src[1+1*stride]=\n src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2;\n src[2+1*stride]=\n src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2;\n src[3+1*stride]=\n src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2;\n src[3+2*stride]=(t4 + 2*t5 + t6 + 2)>>2;\n src[3+3*stride]=(t5 + 2*t6 + t7 + 2)>>2;\n}']
33,567
0
https://github.com/openssl/openssl/blob/4b8515baa6edef1a771f9e4e3fbc0395b4a629e8/crypto/bn/bn_ctx.c/#L273
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num,\n EC_POINT *points[], BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *tmp, *tmp_Z;\n BIGNUM **prod_Z = NULL;\n size_t i;\n int ret = 0;\n if (num == 0)\n return 1;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n tmp_Z = BN_CTX_get(ctx);\n if (tmp_Z == NULL)\n goto err;\n prod_Z = OPENSSL_malloc(num * sizeof prod_Z[0]);\n if (prod_Z == NULL)\n goto err;\n for (i = 0; i < num; i++) {\n prod_Z[i] = BN_new();\n if (prod_Z[i] == NULL)\n goto err;\n }\n if (!BN_is_zero(points[0]->Z)) {\n if (!BN_copy(prod_Z[0], points[0]->Z))\n goto err;\n } else {\n if (group->meth->field_set_to_one != 0) {\n if (!group->meth->field_set_to_one(group, prod_Z[0], ctx))\n goto err;\n } else {\n if (!BN_one(prod_Z[0]))\n goto err;\n }\n }\n for (i = 1; i < num; i++) {\n if (!BN_is_zero(points[i]->Z)) {\n if (!group->\n meth->field_mul(group, prod_Z[i], prod_Z[i - 1], points[i]->Z,\n ctx))\n goto err;\n } else {\n if (!BN_copy(prod_Z[i], prod_Z[i - 1]))\n goto err;\n }\n }\n if (!BN_mod_inverse(tmp, prod_Z[num - 1], group->field, ctx)) {\n ECerr(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE, ERR_R_BN_LIB);\n goto err;\n }\n if (group->meth->field_encode != 0) {\n if (!group->meth->field_encode(group, tmp, tmp, ctx))\n goto err;\n if (!group->meth->field_encode(group, tmp, tmp, ctx))\n goto err;\n }\n for (i = num - 1; i > 0; --i) {\n if (!BN_is_zero(points[i]->Z)) {\n if (!group->\n meth->field_mul(group, tmp_Z, prod_Z[i - 1], tmp, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp, tmp, points[i]->Z, ctx))\n goto err;\n if (!BN_copy(points[i]->Z, tmp_Z))\n goto err;\n }\n }\n if (!BN_is_zero(points[0]->Z)) {\n if (!BN_copy(points[0]->Z, tmp))\n goto err;\n }\n for (i = 0; i < num; i++) {\n EC_POINT *p = points[i];\n if (!BN_is_zero(p->Z)) {\n if (!group->meth->field_sqr(group, tmp, p->Z, ctx))\n goto err;\n if (!group->meth->field_mul(group, p->X, p->X, tmp, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp, tmp, p->Z, ctx))\n goto err;\n if (!group->meth->field_mul(group, p->Y, p->Y, tmp, ctx))\n goto err;\n if (group->meth->field_set_to_one != 0) {\n if (!group->meth->field_set_to_one(group, p->Z, ctx))\n goto err;\n } else {\n if (!BN_one(p->Z))\n goto err;\n }\n p->Z_is_one = 1;\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n if (prod_Z != NULL) {\n for (i = 0; i < num; i++) {\n if (prod_Z[i] == NULL)\n break;\n BN_clear_free(prod_Z[i]);\n }\n OPENSSL_free(prod_Z);\n }\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}', '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 (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', '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 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}', '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}']
33,568
0
https://github.com/apache/httpd/blob/4a9b30db53505084c56786bed58d1870052adfc7/modules/dav/main/util.c/#L1023
static dav_error * dav_validate_resource_state(apr_pool_t *p, const dav_resource *resource, dav_lockdb *lockdb, const dav_if_header *if_header, int flags, dav_buffer *pbuf, request_rec *r) { dav_error *err; const char *uri; const char *etag; const dav_hooks_locks *locks_hooks = (lockdb ? lockdb->hooks : NULL); const dav_if_header *ifhdr_scan; dav_if_state_list *state_list; dav_lock *lock_list; dav_lock *lock; int num_matched; int num_that_apply; int seen_locktoken; apr_size_t uri_len; const char *reason = NULL; if (lockdb == NULL) { lock_list = NULL; } else { if ((err = dav_lock_query(lockdb, resource, &lock_list)) != NULL) { return dav_push_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, "The locks could not be queried for " "verification against a possible \"If:\" " "header.", err); } } if (flags & DAV_LOCKSCOPE_EXCLUSIVE) { if (lock_list != NULL) { return dav_new_error(p, HTTP_LOCKED, 0, 0, "Existing lock(s) on the requested resource " "prevent an exclusive lock."); } seen_locktoken = 1; } else if (flags & DAV_LOCKSCOPE_SHARED) { for (lock = lock_list; lock != NULL; lock = lock->next) { if (lock->scope == DAV_LOCKSCOPE_EXCLUSIVE) { return dav_new_error(p, HTTP_LOCKED, 0, 0, "The requested resource is already " "locked exclusively."); } } seen_locktoken = 1; } else { seen_locktoken = (lock_list == NULL); } if (if_header == NULL) { if (seen_locktoken) return NULL; return dav_new_error(p, HTTP_LOCKED, 0, 0, "This resource is locked and an \"If:\" header " "was not supplied to allow access to the " "resource."); } if (lock_list == NULL && if_header->dummy_header) { if (flags & DAV_VALIDATE_IS_PARENT) return NULL; return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0, "The locktoken specified in the \"Lock-Token:\" " "header is invalid because this resource has no " "outstanding locks."); } uri = resource->uri; uri_len = strlen(uri); if (uri[uri_len - 1] == '/') { dav_set_bufsize(p, pbuf, uri_len); memcpy(pbuf->buf, uri, uri_len); pbuf->buf[--uri_len] = '\0'; uri = pbuf->buf; } etag = (*resource->hooks->getetag)(resource); num_that_apply = 0; for (ifhdr_scan = if_header; ifhdr_scan != NULL; ifhdr_scan = ifhdr_scan->next) { if (ifhdr_scan->uri != NULL && (uri_len != ifhdr_scan->uri_len || memcmp(uri, ifhdr_scan->uri, uri_len) != 0)) { continue; } ++num_that_apply; for (state_list = ifhdr_scan->state; state_list != NULL; state_list = state_list->next) { switch(state_list->type) { case dav_if_etag: { const char *given_etag, *current_etag; int mismatch; if (state_list->etag[0] == 'W' && state_list->etag[1] == '/') { given_etag = state_list->etag + 2; } else { given_etag = state_list->etag; } if (etag[0] == 'W' && etag[1] == '/') { current_etag = etag + 2; } else { current_etag = etag; } mismatch = strcmp(given_etag, current_etag); if (state_list->condition == DAV_IF_COND_NORMAL && mismatch) { reason = "an entity-tag was specified, but the resource's " "actual ETag does not match."; goto state_list_failed; } else if (state_list->condition == DAV_IF_COND_NOT && !mismatch) { reason = "an entity-tag was specified using the \"Not\" form, " "but the resource's actual ETag matches the provided " "entity-tag."; goto state_list_failed; } break; } case dav_if_opaquelock: if (lockdb == NULL) { if (state_list->condition == DAV_IF_COND_NOT) { continue; } reason = "a State-token was supplied, but a lock database " "is not available for to provide the required lock."; goto state_list_failed; } num_matched = 0; for (lock = lock_list; lock != NULL; lock = lock->next) { if ((*locks_hooks->compare_locktoken)(state_list->locktoken, lock->locktoken)) { continue; } seen_locktoken = 1; if (state_list->condition == DAV_IF_COND_NOT) { reason = "a State-token was supplied, which used a " "\"Not\" condition. The State-token was found " "in the locks on this resource"; goto state_list_failed; } if (lock->auth_user && (!r->user || strcmp(lock->auth_user, r->user))) { const char *errmsg; errmsg = apr_pstrcat(p, "User \"", r->user, "\" submitted a locktoken created " "by user \"", lock->auth_user, "\".", NULL); return dav_new_error(p, HTTP_FORBIDDEN, 0, 0, errmsg); } num_matched = 1; break; } if (num_matched == 0 && state_list->condition == DAV_IF_COND_NORMAL) { reason = "a State-token was supplied, but it was not found " "in the locks on this resource."; goto state_list_failed; } break; case dav_if_unknown: if (state_list->condition == DAV_IF_COND_NORMAL) { reason = "an unknown state token was supplied"; goto state_list_failed; } break; } } if (seen_locktoken) { return NULL; } break; state_list_failed: ; } if (ifhdr_scan == NULL) { if (num_that_apply == 0) { if (seen_locktoken) return NULL; if (dav_find_submitted_locktoken(if_header, lock_list, locks_hooks)) { return NULL; } return dav_new_error(p, HTTP_LOCKED, 0 , 0, "This resource is locked and the \"If:\" " "header did not specify one of the " "locktokens for this resource's lock(s)."); } if (if_header->dummy_header) { return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0, "The locktoken specified in the " "\"Lock-Token:\" header did not specify one " "of this resource's locktoken(s)."); } if (reason == NULL) { return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, 0, "The preconditions specified by the \"If:\" " "header did not match this resource."); } return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, 0, apr_psprintf(p, "The precondition(s) specified by " "the \"If:\" header did not match " "this resource. At least one " "failure is because: %s", reason)); } if (dav_find_submitted_locktoken(if_header, lock_list, locks_hooks)) { return NULL; } if (if_header->dummy_header) { return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0, "The locktoken specified in the " "\"Lock-Token:\" header did not specify one " "of this resource's locktoken(s)."); } return dav_new_error(p, HTTP_LOCKED, 1 , 0, "This resource is locked and the \"If:\" header " "did not specify one of the " "locktokens for this resource's lock(s)."); }
['static int dav_method_copymove(request_rec *r, int is_move)\n{\n dav_resource *resource;\n dav_resource *resnew;\n dav_auto_version_info src_av_info = { 0 };\n dav_auto_version_info dst_av_info = { 0 };\n const char *body;\n const char *dest;\n dav_error *err;\n dav_error *err2;\n dav_error *err3;\n dav_response *multi_response;\n dav_lookup_result lookup;\n int is_dir;\n int overwrite;\n int depth;\n int result;\n dav_lockdb *lockdb;\n int replace_dest;\n int resnew_state;\n err = dav_get_resource(r, !is_move ,\n 0 , &resource);\n if (err != NULL)\n return dav_handle_err(r, err, NULL);\n if (!resource->exists) {\n return HTTP_NOT_FOUND;\n }\n if (resource->type != DAV_RESOURCE_TYPE_REGULAR) {\n body = apr_psprintf(r->pool,\n "Cannot COPY/MOVE resource %s.",\n ap_escape_html(r->pool, r->uri));\n return dav_error_response(r, HTTP_METHOD_NOT_ALLOWED, body);\n }\n dest = apr_table_get(r->headers_in, "Destination");\n if (dest == NULL) {\n const char *nscp_host = apr_table_get(r->headers_in, "Host");\n const char *nscp_path = apr_table_get(r->headers_in, "New-uri");\n if (nscp_host != NULL && nscp_path != NULL)\n dest = apr_psprintf(r->pool, "http://%s%s", nscp_host, nscp_path);\n }\n if (dest == NULL) {\n ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00591)\n "The request is missing a Destination header.");\n return HTTP_BAD_REQUEST;\n }\n lookup = dav_lookup_uri(dest, r, 1 );\n if (lookup.rnew == NULL) {\n if (lookup.err.status == HTTP_BAD_REQUEST) {\n ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00592)\n "%s", lookup.err.desc);\n return HTTP_BAD_REQUEST;\n }\n return dav_error_response(r, lookup.err.status, lookup.err.desc);\n }\n if (lookup.rnew->status != HTTP_OK) {\n const char *auth = apr_table_get(lookup.rnew->err_headers_out,\n "WWW-Authenticate");\n if (lookup.rnew->status == HTTP_UNAUTHORIZED && auth != NULL) {\n apr_table_setn(r->err_headers_out, "WWW-Authenticate",\n apr_pstrdup(r->pool, auth));\n }\n return dav_error_response(r, lookup.rnew->status,\n "Destination URI had an error.");\n }\n err = dav_get_resource(lookup.rnew, 0 ,\n 0 , &resnew);\n if (err != NULL)\n return dav_handle_err(r, err, NULL);\n if (resource->hooks != resnew->hooks) {\n return dav_error_response(r, HTTP_BAD_GATEWAY,\n "Destination URI is handled by a "\n "different repository than the source URI. "\n "MOVE or COPY between repositories is "\n "not possible.");\n }\n if ((overwrite = dav_get_overwrite(r)) < 0) {\n return HTTP_BAD_REQUEST;\n }\n if (resnew->exists && !overwrite) {\n return dav_error_response(r, HTTP_PRECONDITION_FAILED,\n "Destination is not empty and "\n "Overwrite is not \\"T\\"");\n }\n if ((*resource->hooks->is_same_resource)(resource, resnew)) {\n return dav_error_response(r, HTTP_FORBIDDEN,\n "Source and Destination URIs are the same.");\n }\n is_dir = resource->collection;\n if ((depth = dav_get_depth(r, DAV_INFINITY)) < 0) {\n return HTTP_BAD_REQUEST;\n }\n if (depth == 1) {\n ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00593)\n "Depth must be \\"0\\" or \\"infinity\\" for COPY or MOVE.");\n return HTTP_BAD_REQUEST;\n }\n if (is_move && is_dir && depth != DAV_INFINITY) {\n ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00594)\n "Depth must be \\"infinity\\" when moving a collection.");\n return HTTP_BAD_REQUEST;\n }\n if ((err = dav_validate_request(r, resource, depth, NULL,\n &multi_response,\n (is_move ? DAV_VALIDATE_PARENT\n : DAV_VALIDATE_RESOURCE)\n | DAV_VALIDATE_USE_424,\n NULL)) != NULL) {\n err = dav_push_error(r->pool, err->status, 0,\n apr_psprintf(r->pool,\n "Could not %s %s due to a failed "\n "precondition on the source "\n "(e.g. locks).",\n is_move ? "MOVE" : "COPY",\n ap_escape_html(r->pool, r->uri)),\n err);\n return dav_handle_err(r, err, multi_response);\n }\n if ((err = dav_validate_request(lookup.rnew, resnew, DAV_INFINITY, NULL,\n &multi_response,\n DAV_VALIDATE_PARENT\n | DAV_VALIDATE_USE_424, NULL)) != NULL) {\n err = dav_push_error(r->pool, err->status, 0,\n apr_psprintf(r->pool,\n "Could not MOVE/COPY %s due to a "\n "failed precondition on the "\n "destination (e.g. locks).",\n ap_escape_html(r->pool, r->uri)),\n err);\n return dav_handle_err(r, err, multi_response);\n }\n if (is_dir\n && depth == DAV_INFINITY\n && (*resource->hooks->is_parent_resource)(resource, resnew)) {\n return dav_error_response(r, HTTP_FORBIDDEN,\n "Source collection contains the "\n "Destination.");\n }\n if (is_dir\n && (*resnew->hooks->is_parent_resource)(resnew, resource)) {\n return dav_error_response(r, HTTP_FORBIDDEN,\n "Destination collection contains the Source "\n "and Overwrite has been specified.");\n }\n if ((result = ap_discard_request_body(r)) != OK) {\n return result;\n }\n if ((err = dav_open_lockdb(r, 0, &lockdb)) != NULL) {\n return dav_handle_err(r, err, NULL);\n }\n if (is_move && lockdb != NULL) {\n (void)dav_unlock(r, resource, NULL);\n }\n if (is_move) {\n if ((err = dav_auto_checkout(r, resource, 1 ,\n &src_av_info)) != NULL) {\n if (lockdb != NULL)\n (*lockdb->hooks->close_lockdb)(lockdb);\n return dav_handle_err(r, err, NULL);\n }\n }\n resnew_state = dav_get_resource_state(lookup.rnew, resnew);\n if (!resnew->exists)\n replace_dest = 0;\n else if (is_move || !resource->versioned)\n replace_dest = 1;\n else if (resource->type != resnew->type)\n replace_dest = 1;\n else if ((resource->collection == 0) != (resnew->collection == 0))\n replace_dest = 1;\n else\n replace_dest = 0;\n if (!resnew->exists || replace_dest) {\n if ((err = dav_auto_checkout(r, resnew, 1 ,\n &dst_av_info)) != NULL) {\n if (is_move) {\n (void)dav_auto_checkin(r, NULL, 1 ,\n 0 , &src_av_info);\n }\n if (lockdb != NULL)\n (*lockdb->hooks->close_lockdb)(lockdb);\n return dav_handle_err(r, err, NULL);\n }\n }\n if (src_av_info.parent_resource != NULL\n && dst_av_info.parent_resource != NULL\n && (*src_av_info.parent_resource->hooks->is_same_resource)\n (src_av_info.parent_resource, dst_av_info.parent_resource)) {\n dst_av_info.parent_resource = src_av_info.parent_resource;\n }\n if (replace_dest)\n err = (*resnew->hooks->remove_resource)(resnew, &multi_response);\n if (err == NULL) {\n if (is_move)\n err = (*resource->hooks->move_resource)(resource, resnew,\n &multi_response);\n else\n err = (*resource->hooks->copy_resource)(resource, resnew, depth,\n &multi_response);\n }\n err2 = dav_auto_checkin(r, NULL, err != NULL ,\n 0 , &dst_av_info);\n if (is_move) {\n err3 = dav_auto_checkin(r, NULL, err != NULL ,\n 0 , &src_av_info);\n }\n else\n err3 = NULL;\n if (err != NULL) {\n if (lockdb != NULL)\n (*lockdb->hooks->close_lockdb)(lockdb);\n err = dav_push_error(r->pool, err->status, 0,\n apr_psprintf(r->pool,\n "Could not MOVE/COPY %s.",\n ap_escape_html(r->pool, r->uri)),\n err);\n return dav_handle_err(r, err, multi_response);\n }\n if (err2 != NULL) {\n err = dav_push_error(r->pool, err2->status, 0,\n "The MOVE/COPY was successful, but there was a "\n "problem automatically checking in the "\n "source parent collection.",\n err2);\n dav_log_err(r, err, APLOG_WARNING);\n }\n if (err3 != NULL) {\n err = dav_push_error(r->pool, err3->status, 0,\n "The MOVE/COPY was successful, but there was a "\n "problem automatically checking in the "\n "destination or its parent collection.",\n err3);\n dav_log_err(r, err, APLOG_WARNING);\n }\n if (lockdb != NULL) {\n err = dav_notify_created(r, lockdb, resnew, resnew_state, depth);\n (*lockdb->hooks->close_lockdb)(lockdb);\n if (err != NULL) {\n err = dav_push_error(r->pool, err->status, 0,\n "The MOVE/COPY was successful, but there "\n "was a problem updating the lock "\n "information.",\n err);\n return dav_handle_err(r, err, NULL);\n }\n }\n return dav_created(r, lookup.rnew->uri, "Destination",\n resnew_state == DAV_RESOURCE_EXISTS);\n}', 'DAV_DECLARE(int) dav_get_depth(request_rec *r, int def_depth)\n{\n const char *depth = apr_table_get(r->headers_in, "Depth");\n if (depth == NULL) {\n return def_depth;\n }\n if (strcasecmp(depth, "infinity") == 0) {\n return DAV_INFINITY;\n }\n else if (strcmp(depth, "0") == 0) {\n return 0;\n }\n else if (strcmp(depth, "1") == 0) {\n return 1;\n }\n ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00580)\n "An invalid Depth header was specified.");\n return -1;\n}', 'DAV_DECLARE(dav_error *) dav_validate_request(request_rec *r,\n dav_resource *resource,\n int depth,\n dav_locktoken *locktoken,\n dav_response **response,\n int flags,\n dav_lockdb *lockdb)\n{\n dav_error *err;\n int result;\n dav_if_header *if_header;\n int lock_db_opened_locally = 0;\n const dav_hooks_locks *locks_hooks = DAV_GET_HOOKS_LOCKS(r);\n const dav_hooks_repository *repos_hooks = resource->hooks;\n dav_buffer work_buf = { 0 };\n dav_response *new_response;\n int resource_state;\n const char *etag;\n int set_etag = 0;\n#if DAV_DEBUG\n if (depth && response == NULL) {\n return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, 0,\n "DESIGN ERROR: dav_validate_request called "\n "with depth>0, but no response ptr.");\n }\n#endif\n if (response != NULL)\n *response = NULL;\n etag = apr_table_get(r->headers_out, "ETag");\n if (!etag) {\n etag = (*resource->hooks->getetag)(resource);\n if (etag && *etag) {\n apr_table_set(r->headers_out, "ETag", etag);\n set_etag = 1;\n }\n }\n resource_state = dav_get_resource_state(r, resource);\n result = dav_meets_conditions(r, resource_state);\n if (set_etag) {\n apr_table_unset(r->headers_out, "ETag");\n }\n if (result != OK) {\n return dav_new_error(r->pool, result, 0, 0, NULL);\n }\n if ((err = dav_process_if_header(r, &if_header)) != NULL) {\n return err;\n }\n if (locktoken != NULL) {\n dav_if_header *ifhdr_new;\n ifhdr_new = apr_pcalloc(r->pool, sizeof(*ifhdr_new));\n ifhdr_new->uri = resource->uri;\n ifhdr_new->uri_len = strlen(resource->uri);\n ifhdr_new->dummy_header = 1;\n ifhdr_new->state = apr_pcalloc(r->pool, sizeof(*ifhdr_new->state));\n ifhdr_new->state->type = dav_if_opaquelock;\n ifhdr_new->state->condition = DAV_IF_COND_NORMAL;\n ifhdr_new->state->locktoken = locktoken;\n ifhdr_new->next = if_header;\n if_header = ifhdr_new;\n }\n if (lockdb == NULL) {\n if (locks_hooks != NULL) {\n if ((err = (*locks_hooks->open_lockdb)(r, 0, 0, &lockdb)) != NULL) {\n return err;\n }\n lock_db_opened_locally = 1;\n }\n }\n if (resource->exists && depth > 0) {\n dav_walker_ctx ctx = { { 0 } };\n dav_response *multi_status;\n ctx.w.walk_type = DAV_WALKTYPE_NORMAL;\n ctx.w.func = dav_validate_walker;\n ctx.w.walk_ctx = &ctx;\n ctx.w.pool = r->pool;\n ctx.w.root = resource;\n ctx.if_header = if_header;\n ctx.r = r;\n ctx.flags = flags;\n if (lockdb != NULL) {\n ctx.w.lockdb = lockdb;\n ctx.w.walk_type |= DAV_WALKTYPE_LOCKNULL;\n }\n err = (*repos_hooks->walk)(&ctx.w, DAV_INFINITY, &multi_status);\n if (err == NULL) {\n *response = multi_status;\n }\n }\n else {\n err = dav_validate_resource_state(r->pool, resource, lockdb,\n if_header, flags, &work_buf, r);\n }\n if (err == NULL && (flags & DAV_VALIDATE_PARENT)) {\n dav_resource *parent_resource;\n err = (*repos_hooks->get_parent_resource)(resource, &parent_resource);\n if (err == NULL && parent_resource == NULL) {\n err = dav_new_error(r->pool, HTTP_FORBIDDEN, 0, 0,\n "Cannot access parent of repository root.");\n }\n else if (err == NULL) {\n err = dav_validate_resource_state(r->pool, parent_resource, lockdb,\n if_header,\n flags | DAV_VALIDATE_IS_PARENT,\n &work_buf, r);\n if (err != NULL) {\n new_response = apr_pcalloc(r->pool, sizeof(*new_response));\n new_response->href = parent_resource->uri;\n new_response->status = err->status;\n new_response->desc =\n "A validation error has occurred on the parent resource, "\n "preventing the operation on the resource specified by "\n "the Request-URI.";\n if (err->desc != NULL) {\n new_response->desc = apr_pstrcat(r->pool,\n new_response->desc,\n " The error was: ",\n err->desc, NULL);\n }\n new_response->next = *response;\n *response = new_response;\n err = NULL;\n }\n }\n }\n if (lock_db_opened_locally)\n (*locks_hooks->close_lockdb)(lockdb);\n if (err == NULL && response != NULL && *response != NULL) {\n apr_text *propstat = NULL;\n if ((flags & DAV_VALIDATE_USE_424) != 0) {\n return dav_new_error(r->pool, HTTP_FAILED_DEPENDENCY, 0, 0,\n "An error occurred on another resource, "\n "preventing the requested operation on "\n "this resource.");\n }\n if ((flags & DAV_VALIDATE_ADD_LD) != 0) {\n propstat = apr_pcalloc(r->pool, sizeof(*propstat));\n propstat->text =\n "<D:propstat>" DEBUG_CR\n "<D:prop><D:lockdiscovery/></D:prop>" DEBUG_CR\n "<D:status>HTTP/1.1 424 Failed Dependency</D:status>" DEBUG_CR\n "</D:propstat>" DEBUG_CR;\n }\n new_response = apr_pcalloc(r->pool, sizeof(*new_response));\n new_response->href = resource->uri;\n new_response->status = HTTP_FAILED_DEPENDENCY;\n new_response->propresult.propstats = propstat;\n new_response->desc =\n "An error occurred on another resource, preventing the "\n "requested operation on this resource.";\n new_response->next = *response;\n *response = new_response;\n return dav_new_error(r->pool, HTTP_MULTI_STATUS, 0, 0,\n "Error(s) occurred on resources during the "\n "validation process.");\n }\n return err;\n}', 'static dav_error * dav_validate_resource_state(apr_pool_t *p,\n const dav_resource *resource,\n dav_lockdb *lockdb,\n const dav_if_header *if_header,\n int flags,\n dav_buffer *pbuf,\n request_rec *r)\n{\n dav_error *err;\n const char *uri;\n const char *etag;\n const dav_hooks_locks *locks_hooks = (lockdb ? lockdb->hooks : NULL);\n const dav_if_header *ifhdr_scan;\n dav_if_state_list *state_list;\n dav_lock *lock_list;\n dav_lock *lock;\n int num_matched;\n int num_that_apply;\n int seen_locktoken;\n apr_size_t uri_len;\n const char *reason = NULL;\n if (lockdb == NULL) {\n lock_list = NULL;\n }\n else {\n if ((err = dav_lock_query(lockdb, resource, &lock_list)) != NULL) {\n return dav_push_error(p,\n HTTP_INTERNAL_SERVER_ERROR, 0,\n "The locks could not be queried for "\n "verification against a possible \\"If:\\" "\n "header.",\n err);\n }\n }\n if (flags & DAV_LOCKSCOPE_EXCLUSIVE) {\n if (lock_list != NULL) {\n return dav_new_error(p, HTTP_LOCKED, 0, 0,\n "Existing lock(s) on the requested resource "\n "prevent an exclusive lock.");\n }\n seen_locktoken = 1;\n }\n else if (flags & DAV_LOCKSCOPE_SHARED) {\n for (lock = lock_list; lock != NULL; lock = lock->next) {\n if (lock->scope == DAV_LOCKSCOPE_EXCLUSIVE) {\n return dav_new_error(p, HTTP_LOCKED, 0, 0,\n "The requested resource is already "\n "locked exclusively.");\n }\n }\n seen_locktoken = 1;\n }\n else {\n seen_locktoken = (lock_list == NULL);\n }\n if (if_header == NULL) {\n if (seen_locktoken)\n return NULL;\n return dav_new_error(p, HTTP_LOCKED, 0, 0,\n "This resource is locked and an \\"If:\\" header "\n "was not supplied to allow access to the "\n "resource.");\n }\n if (lock_list == NULL && if_header->dummy_header) {\n if (flags & DAV_VALIDATE_IS_PARENT)\n return NULL;\n return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0,\n "The locktoken specified in the \\"Lock-Token:\\" "\n "header is invalid because this resource has no "\n "outstanding locks.");\n }\n uri = resource->uri;\n uri_len = strlen(uri);\n if (uri[uri_len - 1] == \'/\') {\n dav_set_bufsize(p, pbuf, uri_len);\n memcpy(pbuf->buf, uri, uri_len);\n pbuf->buf[--uri_len] = \'\\0\';\n uri = pbuf->buf;\n }\n etag = (*resource->hooks->getetag)(resource);\n num_that_apply = 0;\n for (ifhdr_scan = if_header;\n ifhdr_scan != NULL;\n ifhdr_scan = ifhdr_scan->next) {\n if (ifhdr_scan->uri != NULL\n && (uri_len != ifhdr_scan->uri_len\n || memcmp(uri, ifhdr_scan->uri, uri_len) != 0)) {\n continue;\n }\n ++num_that_apply;\n for (state_list = ifhdr_scan->state;\n state_list != NULL;\n state_list = state_list->next) {\n switch(state_list->type) {\n case dav_if_etag:\n {\n const char *given_etag, *current_etag;\n int mismatch;\n if (state_list->etag[0] == \'W\' &&\n state_list->etag[1] == \'/\') {\n given_etag = state_list->etag + 2;\n }\n else {\n given_etag = state_list->etag;\n }\n if (etag[0] == \'W\' &&\n etag[1] == \'/\') {\n current_etag = etag + 2;\n }\n else {\n current_etag = etag;\n }\n mismatch = strcmp(given_etag, current_etag);\n if (state_list->condition == DAV_IF_COND_NORMAL && mismatch) {\n reason =\n "an entity-tag was specified, but the resource\'s "\n "actual ETag does not match.";\n goto state_list_failed;\n }\n else if (state_list->condition == DAV_IF_COND_NOT\n && !mismatch) {\n reason =\n "an entity-tag was specified using the \\"Not\\" form, "\n "but the resource\'s actual ETag matches the provided "\n "entity-tag.";\n goto state_list_failed;\n }\n break;\n }\n case dav_if_opaquelock:\n if (lockdb == NULL) {\n if (state_list->condition == DAV_IF_COND_NOT) {\n continue;\n }\n reason =\n "a State-token was supplied, but a lock database "\n "is not available for to provide the required lock.";\n goto state_list_failed;\n }\n num_matched = 0;\n for (lock = lock_list; lock != NULL; lock = lock->next) {\n if ((*locks_hooks->compare_locktoken)(state_list->locktoken, lock->locktoken)) {\n continue;\n }\n seen_locktoken = 1;\n if (state_list->condition == DAV_IF_COND_NOT) {\n reason =\n "a State-token was supplied, which used a "\n "\\"Not\\" condition. The State-token was found "\n "in the locks on this resource";\n goto state_list_failed;\n }\n if (lock->auth_user &&\n (!r->user ||\n strcmp(lock->auth_user, r->user))) {\n const char *errmsg;\n errmsg = apr_pstrcat(p, "User \\"",\n r->user,\n "\\" submitted a locktoken created "\n "by user \\"",\n lock->auth_user, "\\".", NULL);\n return dav_new_error(p, HTTP_FORBIDDEN, 0, 0, errmsg);\n }\n num_matched = 1;\n break;\n }\n if (num_matched == 0\n && state_list->condition == DAV_IF_COND_NORMAL) {\n reason =\n "a State-token was supplied, but it was not found "\n "in the locks on this resource.";\n goto state_list_failed;\n }\n break;\n case dav_if_unknown:\n if (state_list->condition == DAV_IF_COND_NORMAL) {\n reason =\n "an unknown state token was supplied";\n goto state_list_failed;\n }\n break;\n }\n }\n if (seen_locktoken) {\n return NULL;\n }\n break;\n state_list_failed:\n ;\n }\n if (ifhdr_scan == NULL) {\n if (num_that_apply == 0) {\n if (seen_locktoken)\n return NULL;\n if (dav_find_submitted_locktoken(if_header, lock_list,\n locks_hooks)) {\n return NULL;\n }\n return dav_new_error(p, HTTP_LOCKED, 0 , 0,\n "This resource is locked and the \\"If:\\" "\n "header did not specify one of the "\n "locktokens for this resource\'s lock(s).");\n }\n if (if_header->dummy_header) {\n return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0,\n "The locktoken specified in the "\n "\\"Lock-Token:\\" header did not specify one "\n "of this resource\'s locktoken(s).");\n }\n if (reason == NULL) {\n return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, 0,\n "The preconditions specified by the \\"If:\\" "\n "header did not match this resource.");\n }\n return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, 0,\n apr_psprintf(p,\n "The precondition(s) specified by "\n "the \\"If:\\" header did not match "\n "this resource. At least one "\n "failure is because: %s", reason));\n }\n if (dav_find_submitted_locktoken(if_header, lock_list, locks_hooks)) {\n return NULL;\n }\n if (if_header->dummy_header) {\n return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0,\n "The locktoken specified in the "\n "\\"Lock-Token:\\" header did not specify one "\n "of this resource\'s locktoken(s).");\n }\n return dav_new_error(p, HTTP_LOCKED, 1 , 0,\n "This resource is locked and the \\"If:\\" header "\n "did not specify one of the "\n "locktokens for this resource\'s lock(s).");\n}']
33,569
0
https://github.com/libav/libav/blob/a56fba502e9087c204b7d6cdc8e12d623f77d66d/libavcodec/flicvideo.c/#L537
static int flic_decode_frame_15_16BPP(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { FlicDecodeContext *s = avctx->priv_data; GetByteContext g2; int pixel_ptr; unsigned char palette_idx1; unsigned int frame_size; int num_chunks; unsigned int chunk_size; int chunk_type; int i, j; int lines; int compressed_lines; signed short line_packets; int y_ptr; int byte_run; int pixel_skip; int pixel_countdown; unsigned char *pixels; int pixel; unsigned int pixel_limit; bytestream2_init(&g2, buf, buf_size); s->frame.reference = 1; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; if (avctx->reget_buffer(avctx, &s->frame) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return -1; } pixels = s->frame.data[0]; pixel_limit = s->avctx->height * s->frame.linesize[0]; frame_size = bytestream2_get_le32(&g2); bytestream2_skip(&g2, 2); num_chunks = bytestream2_get_le16(&g2); bytestream2_skip(&g2, 8); frame_size -= 16; while ((frame_size > 0) && (num_chunks > 0)) { chunk_size = bytestream2_get_le32(&g2); chunk_type = bytestream2_get_le16(&g2); switch (chunk_type) { case FLI_256_COLOR: case FLI_COLOR: bytestream2_skip(&g2, chunk_size - 6); break; case FLI_DELTA: case FLI_DTA_LC: y_ptr = 0; compressed_lines = bytestream2_get_le16(&g2); while (compressed_lines > 0) { line_packets = bytestream2_get_le16(&g2); if (line_packets < 0) { line_packets = -line_packets; y_ptr += line_packets * s->frame.linesize[0]; } else { compressed_lines--; pixel_ptr = y_ptr; CHECK_PIXEL_PTR(0); pixel_countdown = s->avctx->width; for (i = 0; i < line_packets; i++) { pixel_skip = bytestream2_get_byte(&g2); pixel_ptr += (pixel_skip*2); pixel_countdown -= pixel_skip; byte_run = sign_extend(bytestream2_get_byte(&g2), 8); if (byte_run < 0) { byte_run = -byte_run; pixel = bytestream2_get_le16(&g2); CHECK_PIXEL_PTR(2 * byte_run); for (j = 0; j < byte_run; j++, pixel_countdown -= 2) { *((signed short*)(&pixels[pixel_ptr])) = pixel; pixel_ptr += 2; } } else { CHECK_PIXEL_PTR(2 * byte_run); for (j = 0; j < byte_run; j++, pixel_countdown--) { *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2); pixel_ptr += 2; } } } y_ptr += s->frame.linesize[0]; } } break; case FLI_LC: av_log(avctx, AV_LOG_ERROR, "Unexpected FLI_LC chunk in non-paletised FLC\n"); bytestream2_skip(&g2, chunk_size - 6); break; case FLI_BLACK: memset(pixels, 0x0000, s->frame.linesize[0] * s->avctx->height); break; case FLI_BRUN: y_ptr = 0; for (lines = 0; lines < s->avctx->height; lines++) { pixel_ptr = y_ptr; bytestream2_skip(&g2, 1); pixel_countdown = (s->avctx->width * 2); while (pixel_countdown > 0) { byte_run = sign_extend(bytestream2_get_byte(&g2), 8); if (byte_run > 0) { palette_idx1 = bytestream2_get_byte(&g2); CHECK_PIXEL_PTR(byte_run); for (j = 0; j < byte_run; j++) { pixels[pixel_ptr++] = palette_idx1; pixel_countdown--; if (pixel_countdown < 0) av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) (linea%d)\n", pixel_countdown, lines); } } else { byte_run = -byte_run; CHECK_PIXEL_PTR(byte_run); for (j = 0; j < byte_run; j++) { palette_idx1 = bytestream2_get_byte(&g2); pixels[pixel_ptr++] = palette_idx1; pixel_countdown--; if (pixel_countdown < 0) av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n", pixel_countdown, lines); } } } #if HAVE_BIGENDIAN pixel_ptr = y_ptr; pixel_countdown = s->avctx->width; while (pixel_countdown > 0) { *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[pixel_ptr]); pixel_ptr += 2; } #endif y_ptr += s->frame.linesize[0]; } break; case FLI_DTA_BRUN: y_ptr = 0; for (lines = 0; lines < s->avctx->height; lines++) { pixel_ptr = y_ptr; bytestream2_skip(&g2, 1); pixel_countdown = s->avctx->width; while (pixel_countdown > 0) { byte_run = sign_extend(bytestream2_get_byte(&g2), 8); if (byte_run > 0) { pixel = bytestream2_get_le16(&g2); CHECK_PIXEL_PTR(2 * byte_run); for (j = 0; j < byte_run; j++) { *((signed short*)(&pixels[pixel_ptr])) = pixel; pixel_ptr += 2; pixel_countdown--; if (pixel_countdown < 0) av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n", pixel_countdown); } } else { byte_run = -byte_run; CHECK_PIXEL_PTR(2 * byte_run); for (j = 0; j < byte_run; j++) { *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2); pixel_ptr += 2; pixel_countdown--; if (pixel_countdown < 0) av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n", pixel_countdown); } } } y_ptr += s->frame.linesize[0]; } break; case FLI_COPY: case FLI_DTA_COPY: if (chunk_size - 6 > (unsigned int)(s->avctx->width * s->avctx->height)*2) { av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \ "bigger than image, skipping chunk\n", chunk_size - 6); bytestream2_skip(&g2, chunk_size - 6); } else { for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height; y_ptr += s->frame.linesize[0]) { pixel_countdown = s->avctx->width; pixel_ptr = 0; while (pixel_countdown > 0) { *((signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2); pixel_ptr += 2; pixel_countdown--; } } } break; case FLI_MINI: bytestream2_skip(&g2, chunk_size - 6); break; default: av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type); break; } frame_size -= chunk_size; num_chunks--; } if ((bytestream2_get_bytes_left(&g2) != 0) && (bytestream2_get_bytes_left(&g2) != 1)) av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \ "and final chunk ptr = %d\n", buf_size, bytestream2_tell(&g2)); *data_size=sizeof(AVFrame); *(AVFrame*)data = s->frame; return buf_size; }
['static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,\n void *data, int *data_size,\n const uint8_t *buf, int buf_size)\n{\n FlicDecodeContext *s = avctx->priv_data;\n GetByteContext g2;\n int pixel_ptr;\n unsigned char palette_idx1;\n unsigned int frame_size;\n int num_chunks;\n unsigned int chunk_size;\n int chunk_type;\n int i, j;\n int lines;\n int compressed_lines;\n signed short line_packets;\n int y_ptr;\n int byte_run;\n int pixel_skip;\n int pixel_countdown;\n unsigned char *pixels;\n int pixel;\n unsigned int pixel_limit;\n bytestream2_init(&g2, buf, buf_size);\n s->frame.reference = 1;\n s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;\n if (avctx->reget_buffer(avctx, &s->frame) < 0) {\n av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\\n");\n return -1;\n }\n pixels = s->frame.data[0];\n pixel_limit = s->avctx->height * s->frame.linesize[0];\n frame_size = bytestream2_get_le32(&g2);\n bytestream2_skip(&g2, 2);\n num_chunks = bytestream2_get_le16(&g2);\n bytestream2_skip(&g2, 8);\n frame_size -= 16;\n while ((frame_size > 0) && (num_chunks > 0)) {\n chunk_size = bytestream2_get_le32(&g2);\n chunk_type = bytestream2_get_le16(&g2);\n switch (chunk_type) {\n case FLI_256_COLOR:\n case FLI_COLOR:\n bytestream2_skip(&g2, chunk_size - 6);\n break;\n case FLI_DELTA:\n case FLI_DTA_LC:\n y_ptr = 0;\n compressed_lines = bytestream2_get_le16(&g2);\n while (compressed_lines > 0) {\n line_packets = bytestream2_get_le16(&g2);\n if (line_packets < 0) {\n line_packets = -line_packets;\n y_ptr += line_packets * s->frame.linesize[0];\n } else {\n compressed_lines--;\n pixel_ptr = y_ptr;\n CHECK_PIXEL_PTR(0);\n pixel_countdown = s->avctx->width;\n for (i = 0; i < line_packets; i++) {\n pixel_skip = bytestream2_get_byte(&g2);\n pixel_ptr += (pixel_skip*2);\n pixel_countdown -= pixel_skip;\n byte_run = sign_extend(bytestream2_get_byte(&g2), 8);\n if (byte_run < 0) {\n byte_run = -byte_run;\n pixel = bytestream2_get_le16(&g2);\n CHECK_PIXEL_PTR(2 * byte_run);\n for (j = 0; j < byte_run; j++, pixel_countdown -= 2) {\n *((signed short*)(&pixels[pixel_ptr])) = pixel;\n pixel_ptr += 2;\n }\n } else {\n CHECK_PIXEL_PTR(2 * byte_run);\n for (j = 0; j < byte_run; j++, pixel_countdown--) {\n *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);\n pixel_ptr += 2;\n }\n }\n }\n y_ptr += s->frame.linesize[0];\n }\n }\n break;\n case FLI_LC:\n av_log(avctx, AV_LOG_ERROR, "Unexpected FLI_LC chunk in non-paletised FLC\\n");\n bytestream2_skip(&g2, chunk_size - 6);\n break;\n case FLI_BLACK:\n memset(pixels, 0x0000,\n s->frame.linesize[0] * s->avctx->height);\n break;\n case FLI_BRUN:\n y_ptr = 0;\n for (lines = 0; lines < s->avctx->height; lines++) {\n pixel_ptr = y_ptr;\n bytestream2_skip(&g2, 1);\n pixel_countdown = (s->avctx->width * 2);\n while (pixel_countdown > 0) {\n byte_run = sign_extend(bytestream2_get_byte(&g2), 8);\n if (byte_run > 0) {\n palette_idx1 = bytestream2_get_byte(&g2);\n CHECK_PIXEL_PTR(byte_run);\n for (j = 0; j < byte_run; j++) {\n pixels[pixel_ptr++] = palette_idx1;\n pixel_countdown--;\n if (pixel_countdown < 0)\n av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) (linea%d)\\n",\n pixel_countdown, lines);\n }\n } else {\n byte_run = -byte_run;\n CHECK_PIXEL_PTR(byte_run);\n for (j = 0; j < byte_run; j++) {\n palette_idx1 = bytestream2_get_byte(&g2);\n pixels[pixel_ptr++] = palette_idx1;\n pixel_countdown--;\n if (pixel_countdown < 0)\n av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\\n",\n pixel_countdown, lines);\n }\n }\n }\n#if HAVE_BIGENDIAN\n pixel_ptr = y_ptr;\n pixel_countdown = s->avctx->width;\n while (pixel_countdown > 0) {\n *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[pixel_ptr]);\n pixel_ptr += 2;\n }\n#endif\n y_ptr += s->frame.linesize[0];\n }\n break;\n case FLI_DTA_BRUN:\n y_ptr = 0;\n for (lines = 0; lines < s->avctx->height; lines++) {\n pixel_ptr = y_ptr;\n bytestream2_skip(&g2, 1);\n pixel_countdown = s->avctx->width;\n while (pixel_countdown > 0) {\n byte_run = sign_extend(bytestream2_get_byte(&g2), 8);\n if (byte_run > 0) {\n pixel = bytestream2_get_le16(&g2);\n CHECK_PIXEL_PTR(2 * byte_run);\n for (j = 0; j < byte_run; j++) {\n *((signed short*)(&pixels[pixel_ptr])) = pixel;\n pixel_ptr += 2;\n pixel_countdown--;\n if (pixel_countdown < 0)\n av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\\n",\n pixel_countdown);\n }\n } else {\n byte_run = -byte_run;\n CHECK_PIXEL_PTR(2 * byte_run);\n for (j = 0; j < byte_run; j++) {\n *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2);\n pixel_ptr += 2;\n pixel_countdown--;\n if (pixel_countdown < 0)\n av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\\n",\n pixel_countdown);\n }\n }\n }\n y_ptr += s->frame.linesize[0];\n }\n break;\n case FLI_COPY:\n case FLI_DTA_COPY:\n if (chunk_size - 6 > (unsigned int)(s->avctx->width * s->avctx->height)*2) {\n av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \\\n "bigger than image, skipping chunk\\n", chunk_size - 6);\n bytestream2_skip(&g2, chunk_size - 6);\n } else {\n for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height;\n y_ptr += s->frame.linesize[0]) {\n pixel_countdown = s->avctx->width;\n pixel_ptr = 0;\n while (pixel_countdown > 0) {\n *((signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2);\n pixel_ptr += 2;\n pixel_countdown--;\n }\n }\n }\n break;\n case FLI_MINI:\n bytestream2_skip(&g2, chunk_size - 6);\n break;\n default:\n av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\\n", chunk_type);\n break;\n }\n frame_size -= chunk_size;\n num_chunks--;\n }\n if ((bytestream2_get_bytes_left(&g2) != 0) && (bytestream2_get_bytes_left(&g2) != 1))\n av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \\\n "and final chunk ptr = %d\\n", buf_size, bytestream2_tell(&g2));\n *data_size=sizeof(AVFrame);\n *(AVFrame*)data = s->frame;\n return buf_size;\n}', 'DEF(unsigned int, le32, 4, AV_RL32, AV_WL32)']
33,570
0
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_lib.c/#L709
int BN_cmp(const BIGNUM *a, const BIGNUM *b) { int i; int gt,lt; BN_ULONG t1,t2; if ((a == NULL) || (b == NULL)) { if (a != NULL) return(-1); else if (b != NULL) return(1); else return(0); } bn_check_top(a); bn_check_top(b); if (a->neg != b->neg) { if (a->neg) return(-1); else return(1); } if (a->neg == 0) { gt=1; lt= -1; } else { gt= -1; lt=1; } if (a->top > b->top) return(gt); if (a->top < b->top) return(lt); for (i=a->top-1; i>=0; i--) { t1=a->d[i]; t2=b->d[i]; if (t1 > t2) return(gt); if (t1 < t2) return(lt); } return(0); }
['int RSA_check_key(const RSA *key)\n\t{\n\tBIGNUM *i, *j, *k, *l, *m;\n\tBN_CTX *ctx;\n\tint r;\n\tint ret=1;\n\ti = BN_new();\n\tj = BN_new();\n\tk = BN_new();\n\tl = BN_new();\n\tm = BN_new();\n\tctx = BN_CTX_new();\n\tif (i == NULL || j == NULL || k == NULL || l == NULL ||\n\t\tm == NULL || ctx == NULL)\n\t\t{\n\t\tret = -1;\n\t\tRSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tr = BN_is_prime_ex(key->p, BN_prime_checks, NULL, NULL);\n\tif (r != 1)\n\t\t{\n\t\tret = r;\n\t\tif (r != 0)\n\t\t\tgoto err;\n\t\tRSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME);\n\t\t}\n\tr = BN_is_prime_ex(key->q, BN_prime_checks, NULL, NULL);\n\tif (r != 1)\n\t\t{\n\t\tret = r;\n\t\tif (r != 0)\n\t\t\tgoto err;\n\t\tRSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME);\n\t\t}\n\tr = BN_mul(i, key->p, key->q, ctx);\n\tif (!r) { ret = -1; goto err; }\n\tif (BN_cmp(i, key->n) != 0)\n\t\t{\n\t\tret = 0;\n\t\tRSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q);\n\t\t}\n\tr = BN_sub(i, key->p, BN_value_one());\n\tif (!r) { ret = -1; goto err; }\n\tr = BN_sub(j, key->q, BN_value_one());\n\tif (!r) { ret = -1; goto err; }\n\tr = BN_mul(l, i, j, ctx);\n\tif (!r) { ret = -1; goto err; }\n\tr = BN_gcd(m, i, j, ctx);\n\tif (!r) { ret = -1; goto err; }\n\tr = BN_div(k, NULL, l, m, ctx);\n\tif (!r) { ret = -1; goto err; }\n\tr = BN_mod_mul(i, key->d, key->e, k, ctx);\n\tif (!r) { ret = -1; goto err; }\n\tif (!BN_is_one(i))\n\t\t{\n\t\tret = 0;\n\t\tRSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1);\n\t\t}\n\tif (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL)\n\t\t{\n\t\tr = BN_sub(i, key->p, BN_value_one());\n\t\tif (!r) { ret = -1; goto err; }\n\t\tr = BN_mod(j, key->d, i, ctx);\n\t\tif (!r) { ret = -1; goto err; }\n\t\tif (BN_cmp(j, key->dmp1) != 0)\n\t\t\t{\n\t\t\tret = 0;\n\t\t\tRSAerr(RSA_F_RSA_CHECK_KEY,\n\t\t\t\tRSA_R_DMP1_NOT_CONGRUENT_TO_D);\n\t\t\t}\n\t\tr = BN_sub(i, key->q, BN_value_one());\n\t\tif (!r) { ret = -1; goto err; }\n\t\tr = BN_mod(j, key->d, i, ctx);\n\t\tif (!r) { ret = -1; goto err; }\n\t\tif (BN_cmp(j, key->dmq1) != 0)\n\t\t\t{\n\t\t\tret = 0;\n\t\t\tRSAerr(RSA_F_RSA_CHECK_KEY,\n\t\t\t\tRSA_R_DMQ1_NOT_CONGRUENT_TO_D);\n\t\t\t}\n\t\tif(!BN_mod_inverse(i, key->q, key->p, ctx))\n\t\t\t{\n\t\t\tret = -1;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (BN_cmp(i, key->iqmp) != 0)\n\t\t\t{\n\t\t\tret = 0;\n\t\t\tRSAerr(RSA_F_RSA_CHECK_KEY,\n\t\t\t\tRSA_R_IQMP_NOT_INVERSE_OF_Q);\n\t\t\t}\n\t\t}\n err:\n\tif (i != NULL) BN_free(i);\n\tif (j != NULL) BN_free(j);\n\tif (k != NULL) BN_free(k);\n\tif (l != NULL) BN_free(l);\n\tif (m != NULL) BN_free(m);\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\treturn (ret);\n\t}', 'int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n\t{\n\tsize_t max;\n\tint add=0,neg=0;\n\tconst BIGNUM *tmp;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tif (a->neg)\n\t\t{\n\t\tif (b->neg)\n\t\t\t{ tmp=a; a=b; b=tmp; }\n\t\telse\n\t\t\t{ add=1; neg=1; }\n\t\t}\n\telse\n\t\t{\n\t\tif (b->neg) { add=1; neg=0; }\n\t\t}\n\tif (add)\n\t\t{\n\t\tif (!BN_uadd(r,a,b)) return(0);\n\t\tr->neg=neg;\n\t\treturn(1);\n\t\t}\n\tmax=(a->top > b->top)?a->top:b->top;\n\tif (bn_wexpand(r,max) == NULL) return(0);\n\tif (BN_ucmp(a,b) < 0)\n\t\t{\n\t\tif (!BN_usub(r,b,a)) return(0);\n\t\tr->neg=1;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_usub(r,a,b)) return(0);\n\t\tr->neg=0;\n\t\t}\n\tbn_check_top(r);\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;\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}', 'int BN_cmp(const BIGNUM *a, const BIGNUM *b)\n\t{\n\tint i;\n\tint gt,lt;\n\tBN_ULONG t1,t2;\n\tif ((a == NULL) || (b == NULL))\n\t\t{\n\t\tif (a != NULL)\n\t\t\treturn(-1);\n\t\telse if (b != NULL)\n\t\t\treturn(1);\n\t\telse\n\t\t\treturn(0);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tif (a->neg != b->neg)\n\t\t{\n\t\tif (a->neg)\n\t\t\treturn(-1);\n\t\telse\treturn(1);\n\t\t}\n\tif (a->neg == 0)\n\t\t{ gt=1; lt= -1; }\n\telse\t{ gt= -1; lt=1; }\n\tif (a->top > b->top) return(gt);\n\tif (a->top < b->top) return(lt);\n\tfor (i=a->top-1; i>=0; i--)\n\t\t{\n\t\tt1=a->d[i];\n\t\tt2=b->d[i];\n\t\tif (t1 > t2) return(gt);\n\t\tif (t1 < t2) return(lt);\n\t\t}\n\treturn(0);\n\t}']
33,571
0
https://github.com/openssl/openssl/blob/a14715888bc4b5bd2b1da3f8ac7d4cabef8c9cb8/crypto/ec/ec_mult.c/#L245
int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) { BN_CTX *new_ctx = NULL; const EC_POINT *generator = NULL; EC_POINT *tmp = NULL; size_t totalnum; size_t blocksize = 0, numblocks = 0; size_t pre_points_per_block = 0; size_t i, j; int k; int r_is_inverted = 0; int r_is_at_infinity = 1; size_t *wsize = NULL; signed char **wNAF = NULL; size_t *wNAF_len = NULL; size_t max_len = 0; size_t num_val; EC_POINT **val = NULL; EC_POINT **v; EC_POINT ***val_sub = NULL; const EC_PRE_COMP *pre_comp = NULL; int num_scalar = 0; int ret = 0; if (group->meth != r->meth) { ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS); return 0; } if ((scalar == NULL) && (num == 0)) { return EC_POINT_set_to_infinity(group, r); } for (i = 0; i < num; i++) { if (group->meth != points[i]->meth) { ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS); return 0; } } if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) goto err; } if (scalar != NULL) { generator = EC_GROUP_get0_generator(group); if (generator == NULL) { ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR); goto err; } pre_comp = group->pre_comp.ec; if (pre_comp && pre_comp->numblocks && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) == 0)) { blocksize = pre_comp->blocksize; numblocks = (BN_num_bits(scalar) / blocksize) + 1; if (numblocks > pre_comp->numblocks) numblocks = pre_comp->numblocks; pre_points_per_block = (size_t)1 << (pre_comp->w - 1); if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } } else { pre_comp = NULL; numblocks = 1; num_scalar = 1; } } totalnum = num + numblocks; wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0])); wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0])); wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0])); val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0])); if (wNAF != NULL) wNAF[0] = NULL; if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; } num_val = 0; for (i = 0; i < num + num_scalar; i++) { size_t bits; bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar); wsize[i] = EC_window_bits_for_scalar_size(bits); num_val += (size_t)1 << (wsize[i] - 1); wNAF[i + 1] = NULL; wNAF[i] = bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i]); if (wNAF[i] == NULL) goto err; if (wNAF_len[i] > max_len) max_len = wNAF_len[i]; } if (numblocks) { if (pre_comp == NULL) { if (num_scalar != 1) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } } else { signed char *tmp_wNAF = NULL; size_t tmp_len = 0; if (num_scalar != 0) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } wsize[num] = pre_comp->w; tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len); if (!tmp_wNAF) goto err; if (tmp_len <= max_len) { numblocks = 1; totalnum = num + 1; wNAF[num] = tmp_wNAF; wNAF[num + 1] = NULL; wNAF_len[num] = tmp_len; val_sub[num] = pre_comp->points; } else { signed char *pp; EC_POINT **tmp_points; if (tmp_len < numblocks * blocksize) { numblocks = (tmp_len + blocksize - 1) / blocksize; if (numblocks > pre_comp->numblocks) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } totalnum = num + numblocks; } pp = tmp_wNAF; tmp_points = pre_comp->points; for (i = num; i < totalnum; i++) { if (i < totalnum - 1) { wNAF_len[i] = blocksize; if (tmp_len < blocksize) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } tmp_len -= blocksize; } else wNAF_len[i] = tmp_len; wNAF[i + 1] = NULL; wNAF[i] = OPENSSL_malloc(wNAF_len[i]); if (wNAF[i] == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); OPENSSL_free(tmp_wNAF); goto err; } memcpy(wNAF[i], pp, wNAF_len[i]); if (wNAF_len[i] > max_len) max_len = wNAF_len[i]; if (*tmp_points == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); OPENSSL_free(tmp_wNAF); goto err; } val_sub[i] = tmp_points; tmp_points += pre_points_per_block; pp += blocksize; } OPENSSL_free(tmp_wNAF); } } } val = OPENSSL_malloc((num_val + 1) * sizeof(val[0])); if (val == NULL) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); goto err; } val[num_val] = NULL; v = val; for (i = 0; i < num + num_scalar; i++) { val_sub[i] = v; for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) { *v = EC_POINT_new(group); if (*v == NULL) goto err; v++; } } if (!(v == val + num_val)) { ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); goto err; } if ((tmp = EC_POINT_new(group)) == NULL) goto err; for (i = 0; i < num + num_scalar; i++) { if (i < num) { if (!EC_POINT_copy(val_sub[i][0], points[i])) goto err; } else { if (!EC_POINT_copy(val_sub[i][0], generator)) goto err; } if (wsize[i] > 1) { if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err; for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) { if (!EC_POINT_add (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err; } } } if (!EC_POINTs_make_affine(group, num_val, val, ctx)) goto err; r_is_at_infinity = 1; for (k = max_len - 1; k >= 0; k--) { if (!r_is_at_infinity) { if (!EC_POINT_dbl(group, r, r, ctx)) goto err; } for (i = 0; i < totalnum; i++) { if (wNAF_len[i] > (size_t)k) { int digit = wNAF[i][k]; int is_neg; if (digit) { is_neg = digit < 0; if (is_neg) digit = -digit; if (is_neg != r_is_inverted) { if (!r_is_at_infinity) { if (!EC_POINT_invert(group, r, ctx)) goto err; } r_is_inverted = !r_is_inverted; } if (r_is_at_infinity) { if (!EC_POINT_copy(r, val_sub[i][digit >> 1])) goto err; r_is_at_infinity = 0; } else { if (!EC_POINT_add (group, r, r, val_sub[i][digit >> 1], ctx)) goto err; } } } } } if (r_is_at_infinity) { if (!EC_POINT_set_to_infinity(group, r)) goto err; } else { if (r_is_inverted) if (!EC_POINT_invert(group, r, ctx)) goto err; } ret = 1; err: BN_CTX_free(new_ctx); EC_POINT_free(tmp); OPENSSL_free(wsize); OPENSSL_free(wNAF_len); if (wNAF != NULL) { signed char **w; for (w = wNAF; *w != NULL; w++) OPENSSL_free(*w); OPENSSL_free(wNAF); } if (val != NULL) { for (v = val; *v != NULL; v++) EC_POINT_clear_free(*v); OPENSSL_free(val); } OPENSSL_free(val_sub); return ret; }
['int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,\n const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)\n{\n const EC_POINT *points[1];\n const BIGNUM *scalars[1];\n points[0] = point;\n scalars[0] = p_scalar;\n return EC_POINTs_mul(group, r, g_scalar,\n (point != NULL\n && p_scalar != NULL), points, scalars, ctx);\n}', 'int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[],\n const BIGNUM *scalars[], BN_CTX *ctx)\n{\n if (group->meth->mul == 0)\n return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n return group->meth->mul(group, r, scalar, num, points, scalars, ctx);\n}', 'int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[], const BIGNUM *scalars[],\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n const EC_POINT *generator = NULL;\n EC_POINT *tmp = NULL;\n size_t totalnum;\n size_t blocksize = 0, numblocks = 0;\n size_t pre_points_per_block = 0;\n size_t i, j;\n int k;\n int r_is_inverted = 0;\n int r_is_at_infinity = 1;\n size_t *wsize = NULL;\n signed char **wNAF = NULL;\n size_t *wNAF_len = NULL;\n size_t max_len = 0;\n size_t num_val;\n EC_POINT **val = NULL;\n EC_POINT **v;\n EC_POINT ***val_sub = NULL;\n const EC_PRE_COMP *pre_comp = NULL;\n int num_scalar = 0;\n int ret = 0;\n if (group->meth != r->meth) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n if ((scalar == NULL) && (num == 0)) {\n return EC_POINT_set_to_infinity(group, r);\n }\n for (i = 0; i < num; i++) {\n if (group->meth != points[i]->meth) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n }\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n }\n if (scalar != NULL) {\n generator = EC_GROUP_get0_generator(group);\n if (generator == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);\n goto err;\n }\n pre_comp = group->pre_comp.ec;\n if (pre_comp && pre_comp->numblocks\n && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) ==\n 0)) {\n blocksize = pre_comp->blocksize;\n numblocks = (BN_num_bits(scalar) / blocksize) + 1;\n if (numblocks > pre_comp->numblocks)\n numblocks = pre_comp->numblocks;\n pre_points_per_block = (size_t)1 << (pre_comp->w - 1);\n if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n pre_comp = NULL;\n numblocks = 1;\n num_scalar = 1;\n }\n }\n totalnum = num + numblocks;\n wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0]));\n wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0]));\n wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0]));\n val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0]));\n if (wNAF != NULL)\n wNAF[0] = NULL;\n if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n num_val = 0;\n for (i = 0; i < num + num_scalar; i++) {\n size_t bits;\n bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);\n wsize[i] = EC_window_bits_for_scalar_size(bits);\n num_val += (size_t)1 << (wsize[i] - 1);\n wNAF[i + 1] = NULL;\n wNAF[i] =\n bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i],\n &wNAF_len[i]);\n if (wNAF[i] == NULL)\n goto err;\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n }\n if (numblocks) {\n if (pre_comp == NULL) {\n if (num_scalar != 1) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n signed char *tmp_wNAF = NULL;\n size_t tmp_len = 0;\n if (num_scalar != 0) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n wsize[num] = pre_comp->w;\n tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len);\n if (!tmp_wNAF)\n goto err;\n if (tmp_len <= max_len) {\n numblocks = 1;\n totalnum = num + 1;\n wNAF[num] = tmp_wNAF;\n wNAF[num + 1] = NULL;\n wNAF_len[num] = tmp_len;\n val_sub[num] = pre_comp->points;\n } else {\n signed char *pp;\n EC_POINT **tmp_points;\n if (tmp_len < numblocks * blocksize) {\n numblocks = (tmp_len + blocksize - 1) / blocksize;\n if (numblocks > pre_comp->numblocks) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n totalnum = num + numblocks;\n }\n pp = tmp_wNAF;\n tmp_points = pre_comp->points;\n for (i = num; i < totalnum; i++) {\n if (i < totalnum - 1) {\n wNAF_len[i] = blocksize;\n if (tmp_len < blocksize) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n tmp_len -= blocksize;\n } else\n wNAF_len[i] = tmp_len;\n wNAF[i + 1] = NULL;\n wNAF[i] = OPENSSL_malloc(wNAF_len[i]);\n if (wNAF[i] == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n memcpy(wNAF[i], pp, wNAF_len[i]);\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n if (*tmp_points == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n val_sub[i] = tmp_points;\n tmp_points += pre_points_per_block;\n pp += blocksize;\n }\n OPENSSL_free(tmp_wNAF);\n }\n }\n }\n val = OPENSSL_malloc((num_val + 1) * sizeof(val[0]));\n if (val == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n val[num_val] = NULL;\n v = val;\n for (i = 0; i < num + num_scalar; i++) {\n val_sub[i] = v;\n for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n *v = EC_POINT_new(group);\n if (*v == NULL)\n goto err;\n v++;\n }\n }\n if (!(v == val + num_val)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if ((tmp = EC_POINT_new(group)) == NULL)\n goto err;\n for (i = 0; i < num + num_scalar; i++) {\n if (i < num) {\n if (!EC_POINT_copy(val_sub[i][0], points[i]))\n goto err;\n } else {\n if (!EC_POINT_copy(val_sub[i][0], generator))\n goto err;\n }\n if (wsize[i] > 1) {\n if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx))\n goto err;\n for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n if (!EC_POINT_add\n (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx))\n goto err;\n }\n }\n }\n if (!EC_POINTs_make_affine(group, num_val, val, ctx))\n goto err;\n r_is_at_infinity = 1;\n for (k = max_len - 1; k >= 0; k--) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_dbl(group, r, r, ctx))\n goto err;\n }\n for (i = 0; i < totalnum; i++) {\n if (wNAF_len[i] > (size_t)k) {\n int digit = wNAF[i][k];\n int is_neg;\n if (digit) {\n is_neg = digit < 0;\n if (is_neg)\n digit = -digit;\n if (is_neg != r_is_inverted) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n r_is_inverted = !r_is_inverted;\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_copy(r, val_sub[i][digit >> 1]))\n goto err;\n r_is_at_infinity = 0;\n } else {\n if (!EC_POINT_add\n (group, r, r, val_sub[i][digit >> 1], ctx))\n goto err;\n }\n }\n }\n }\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n } else {\n if (r_is_inverted)\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n ret = 1;\n err:\n BN_CTX_free(new_ctx);\n EC_POINT_free(tmp);\n OPENSSL_free(wsize);\n OPENSSL_free(wNAF_len);\n if (wNAF != NULL) {\n signed char **w;\n for (w = wNAF; *w != NULL; w++)\n OPENSSL_free(*w);\n OPENSSL_free(wNAF);\n }\n if (val != NULL) {\n for (v = val; *v != NULL; v++)\n EC_POINT_clear_free(*v);\n OPENSSL_free(val);\n }\n OPENSSL_free(val_sub);\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}']
33,572
0
https://github.com/openssl/openssl/blob/09977dd095f3c655c99b9e1810a213f7eafa7364/crypto/bn/bn_gf2m.c/#L442
int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[]) { int j, k; int n, dN, d0, d1; BN_ULONG zz, *z; bn_check_top(a); if (!p[0]) { BN_zero(r); return 1; } if (a != r) { if (!bn_wexpand(r, a->top)) return 0; for (j = 0; j < a->top; j++) { r->d[j] = a->d[j]; } r->top = a->top; } z = r->d; dN = p[0] / BN_BITS2; for (j = r->top - 1; j > dN;) { zz = z[j]; if (z[j] == 0) { j--; continue; } z[j] = 0; for (k = 1; p[k] != 0; k++) { n = p[0] - p[k]; d0 = n % BN_BITS2; d1 = BN_BITS2 - d0; n /= BN_BITS2; z[j - n] ^= (zz >> d0); if (d0) z[j - n - 1] ^= (zz << d1); } n = dN; d0 = p[0] % BN_BITS2; d1 = BN_BITS2 - d0; z[j - n] ^= (zz >> d0); if (d0) z[j - n - 1] ^= (zz << d1); } while (j == dN) { d0 = p[0] % BN_BITS2; zz = z[dN] >> d0; if (zz == 0) break; d1 = BN_BITS2 - d0; if (d0) z[dN] = (z[dN] << d1) >> d1; else z[dN] = 0; z[0] ^= zz; for (k = 1; p[k] != 0; k++) { BN_ULONG tmp_ulong; n = p[k] / BN_BITS2; d0 = p[k] % BN_BITS2; d1 = BN_BITS2 - d0; z[n] ^= (zz << d0); if (d0 && (tmp_ulong = zz >> d1)) z[n + 1] ^= tmp_ulong; } } bn_correct_top(r); return 1; }
['int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *group,\n BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *b;\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_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT,\n ERR_R_MALLOC_FAILURE);\n goto err;\n }\n }\n BN_CTX_start(ctx);\n b = BN_CTX_get(ctx);\n if (b == NULL)\n goto err;\n if (!BN_GF2m_mod_arr(b, group->b, group->poly))\n goto err;\n if (BN_is_zero(b))\n goto err;\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_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[])\n{\n int j, k;\n int n, dN, d0, d1;\n BN_ULONG zz, *z;\n bn_check_top(a);\n if (!p[0]) {\n BN_zero(r);\n return 1;\n }\n if (a != r) {\n if (!bn_wexpand(r, a->top))\n return 0;\n for (j = 0; j < a->top; j++) {\n r->d[j] = a->d[j];\n }\n r->top = a->top;\n }\n z = r->d;\n dN = p[0] / BN_BITS2;\n for (j = r->top - 1; j > dN;) {\n zz = z[j];\n if (z[j] == 0) {\n j--;\n continue;\n }\n z[j] = 0;\n for (k = 1; p[k] != 0; k++) {\n n = p[0] - p[k];\n d0 = n % BN_BITS2;\n d1 = BN_BITS2 - d0;\n n /= BN_BITS2;\n z[j - n] ^= (zz >> d0);\n if (d0)\n z[j - n - 1] ^= (zz << d1);\n }\n n = dN;\n d0 = p[0] % BN_BITS2;\n d1 = BN_BITS2 - d0;\n z[j - n] ^= (zz >> d0);\n if (d0)\n z[j - n - 1] ^= (zz << d1);\n }\n while (j == dN) {\n d0 = p[0] % BN_BITS2;\n zz = z[dN] >> d0;\n if (zz == 0)\n break;\n d1 = BN_BITS2 - d0;\n if (d0)\n z[dN] = (z[dN] << d1) >> d1;\n else\n z[dN] = 0;\n z[0] ^= zz;\n for (k = 1; p[k] != 0; k++) {\n BN_ULONG tmp_ulong;\n n = p[k] / BN_BITS2;\n d0 = p[k] % BN_BITS2;\n d1 = BN_BITS2 - d0;\n z[n] ^= (zz << d0);\n if (d0 && (tmp_ulong = zz >> d1))\n z[n + 1] ^= tmp_ulong;\n }\n }\n bn_correct_top(r);\n return 1;\n}']
33,573
0
https://github.com/nginx/nginx/blob/70f7141074896fb1ff3e5fc08407ea0f64f2076b/src/core/ngx_sha1.c/#L194
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}']
33,574
0
https://github.com/openssl/openssl/blob/f305ecdac0b7048e7ef38a7196f4393fa7ceff38/crypto/bn/bn_ctx.c/#L300
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int ec_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)\n{\n const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec),\n *group_b = EC_KEY_get0_group(b->pkey.ec);\n if (group_a == NULL || group_b == NULL)\n return -2;\n if (EC_GROUP_cmp(group_a, group_b, NULL))\n return 0;\n else\n return 1;\n}', 'int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx)\n{\n int r = 0;\n BIGNUM *a1, *a2, *a3, *b1, *b2, *b3;\n#ifndef FIPS_MODE\n BN_CTX *ctx_new = NULL;\n if (ctx == NULL)\n ctx_new = ctx = BN_CTX_new();\n#endif\n if (ctx == NULL)\n return -1;\n if (EC_METHOD_get_field_type(EC_GROUP_method_of(a)) !=\n EC_METHOD_get_field_type(EC_GROUP_method_of(b)))\n return 1;\n if (EC_GROUP_get_curve_name(a) && EC_GROUP_get_curve_name(b) &&\n EC_GROUP_get_curve_name(a) != EC_GROUP_get_curve_name(b))\n return 1;\n if (a->meth->flags & EC_FLAGS_CUSTOM_CURVE)\n return 0;\n BN_CTX_start(ctx);\n a1 = BN_CTX_get(ctx);\n a2 = BN_CTX_get(ctx);\n a3 = BN_CTX_get(ctx);\n b1 = BN_CTX_get(ctx);\n b2 = BN_CTX_get(ctx);\n b3 = BN_CTX_get(ctx);\n if (b3 == NULL) {\n BN_CTX_end(ctx);\n#ifndef FIPS_MODE\n BN_CTX_free(ctx_new);\n#endif\n return -1;\n }\n if (!a->meth->group_get_curve(a, a1, a2, a3, ctx) ||\n !b->meth->group_get_curve(b, b1, b2, b3, ctx))\n r = 1;\n if (r || BN_cmp(a1, b1) != 0 || BN_cmp(a2, b2) != 0 || BN_cmp(a3, b3) != 0)\n r = 1;\n if (r || EC_POINT_cmp(a, EC_GROUP_get0_generator(a),\n EC_GROUP_get0_generator(b), ctx) != 0)\n r = 1;\n if (!r) {\n const BIGNUM *ao, *bo, *ac, *bc;\n ao = EC_GROUP_get0_order(a);\n bo = EC_GROUP_get0_order(b);\n if (ao == NULL || bo == NULL) {\n r = -1;\n goto end;\n }\n if (BN_cmp(ao, bo) != 0) {\n r = 1;\n goto end;\n }\n ac = EC_GROUP_get0_cofactor(a);\n bc = EC_GROUP_get0_cofactor(b);\n if (!BN_is_zero(ac) && !BN_is_zero(bc) && BN_cmp(ac, bc) != 0)\n r = 1;\n }\nend:\n BN_CTX_end(ctx);\n#ifndef FIPS_MODE\n BN_CTX_free(ctx_new);\n#endif\n return r;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n 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}']
33,575
0
https://github.com/openssl/openssl/blob/4a8ab10dd205b0f8527f993e608ebe1b032768eb/crypto/ui/ui_lib.c/#L247
int UI_dup_verify_string(UI *ui, const char *prompt, int flags, char *result_buf, int minsize, int maxsize, const char *test_buf) { char *prompt_copy = NULL; if (prompt != NULL) { prompt_copy = OPENSSL_strdup(prompt); if (prompt_copy == NULL) { UIerr(UI_F_UI_DUP_VERIFY_STRING, ERR_R_MALLOC_FAILURE); return -1; } } return general_allocate_string(ui, prompt_copy, 1, UIT_VERIFY, flags, result_buf, minsize, maxsize, test_buf); }
['int UI_dup_verify_string(UI *ui, const char *prompt, int flags,\n char *result_buf, int minsize, int maxsize,\n const char *test_buf)\n{\n char *prompt_copy = NULL;\n if (prompt != NULL) {\n prompt_copy = OPENSSL_strdup(prompt);\n if (prompt_copy == NULL) {\n UIerr(UI_F_UI_DUP_VERIFY_STRING, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n }\n return general_allocate_string(ui, prompt_copy, 1,\n UIT_VERIFY, flags, result_buf, minsize,\n maxsize, test_buf);\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 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}', 'static int general_allocate_string(UI *ui, const char *prompt,\n int prompt_freeable,\n enum UI_string_types type, int input_flags,\n char *result_buf, int minsize, int maxsize,\n const char *test_buf)\n{\n int ret = -1;\n UI_STRING *s = general_allocate_prompt(ui, prompt, prompt_freeable,\n type, input_flags, result_buf);\n if (s != NULL) {\n if (allocate_string_stack(ui) >= 0) {\n s->_.string_data.result_minsize = minsize;\n s->_.string_data.result_maxsize = maxsize;\n s->_.string_data.test_buf = test_buf;\n ret = sk_UI_STRING_push(ui->strings, s);\n if (ret <= 0) {\n ret--;\n free_string(s);\n }\n } else\n free_string(s);\n }\n return ret;\n}']
33,576
0
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/apps/speed.c/#L2321
int MAIN(int argc, char **argv) { unsigned char *buf_malloc = NULL, *buf2_malloc = NULL; unsigned char *buf = NULL, *buf2 = NULL; int mret = 1; long count = 0, save_count = 0; int i, j, k; # if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) long rsa_count; # endif # ifndef OPENSSL_NO_RSA unsigned rsa_num; # endif unsigned char md[EVP_MAX_MD_SIZE]; # ifndef OPENSSL_NO_MD2 unsigned char md2[MD2_DIGEST_LENGTH]; # endif # ifndef OPENSSL_NO_MDC2 unsigned char mdc2[MDC2_DIGEST_LENGTH]; # endif # ifndef OPENSSL_NO_MD4 unsigned char md4[MD4_DIGEST_LENGTH]; # endif # ifndef OPENSSL_NO_MD5 unsigned char md5[MD5_DIGEST_LENGTH]; unsigned char hmac[MD5_DIGEST_LENGTH]; # endif # ifndef OPENSSL_NO_SHA unsigned char sha[SHA_DIGEST_LENGTH]; # ifndef OPENSSL_NO_SHA256 unsigned char sha256[SHA256_DIGEST_LENGTH]; # endif # ifndef OPENSSL_NO_SHA512 unsigned char sha512[SHA512_DIGEST_LENGTH]; # endif # endif # ifndef OPENSSL_NO_WHIRLPOOL unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH]; # endif # ifndef OPENSSL_NO_RMD160 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH]; # endif # ifndef OPENSSL_NO_RC4 RC4_KEY rc4_ks; # endif # ifndef OPENSSL_NO_RC5 RC5_32_KEY rc5_ks; # endif # ifndef OPENSSL_NO_RC2 RC2_KEY rc2_ks; # endif # ifndef OPENSSL_NO_IDEA IDEA_KEY_SCHEDULE idea_ks; # endif # ifndef OPENSSL_NO_SEED SEED_KEY_SCHEDULE seed_ks; # endif # ifndef OPENSSL_NO_BF BF_KEY bf_ks; # endif # ifndef OPENSSL_NO_CAST CAST_KEY cast_ks; # endif static const unsigned char key16[16] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 }; # ifndef OPENSSL_NO_AES static const unsigned char key24[24] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 }; static const unsigned char key32[32] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56 }; # endif # ifndef OPENSSL_NO_CAMELLIA static const unsigned char ckey24[24] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 }; static const unsigned char ckey32[32] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56 }; # endif # ifndef OPENSSL_NO_AES # define MAX_BLOCK_SIZE 128 # else # define MAX_BLOCK_SIZE 64 # endif unsigned char DES_iv[8]; unsigned char iv[2 * MAX_BLOCK_SIZE / 8]; # ifndef OPENSSL_NO_DES static DES_cblock key = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 }; static DES_cblock key2 = { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 }; static DES_cblock key3 = { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 }; DES_key_schedule sch; DES_key_schedule sch2; DES_key_schedule sch3; # endif # ifndef OPENSSL_NO_AES AES_KEY aes_ks1, aes_ks2, aes_ks3; # endif # ifndef OPENSSL_NO_CAMELLIA CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3; # endif # define D_MD2 0 # define D_MDC2 1 # define D_MD4 2 # define D_MD5 3 # define D_HMAC 4 # define D_SHA1 5 # define D_RMD160 6 # define D_RC4 7 # define D_CBC_DES 8 # define D_EDE3_DES 9 # define D_CBC_IDEA 10 # define D_CBC_SEED 11 # define D_CBC_RC2 12 # define D_CBC_RC5 13 # define D_CBC_BF 14 # define D_CBC_CAST 15 # define D_CBC_128_AES 16 # define D_CBC_192_AES 17 # define D_CBC_256_AES 18 # define D_CBC_128_CML 19 # define D_CBC_192_CML 20 # define D_CBC_256_CML 21 # define D_EVP 22 # define D_SHA256 23 # define D_SHA512 24 # define D_WHIRLPOOL 25 # define D_IGE_128_AES 26 # define D_IGE_192_AES 27 # define D_IGE_256_AES 28 # define D_GHASH 29 double d = 0.0; long c[ALGOR_NUM][SIZE_NUM]; # ifndef OPENSSL_SYS_WIN32 # endif # define R_DSA_512 0 # define R_DSA_1024 1 # define R_DSA_2048 2 # define R_RSA_512 0 # define R_RSA_1024 1 # define R_RSA_2048 2 # define R_RSA_3072 3 # define R_RSA_4096 4 # define R_RSA_7680 5 # define R_RSA_15360 6 # define R_EC_P160 0 # define R_EC_P192 1 # define R_EC_P224 2 # define R_EC_P256 3 # define R_EC_P384 4 # define R_EC_P521 5 # define R_EC_K163 6 # define R_EC_K233 7 # define R_EC_K283 8 # define R_EC_K409 9 # define R_EC_K571 10 # define R_EC_B163 11 # define R_EC_B233 12 # define R_EC_B283 13 # define R_EC_B409 14 # define R_EC_B571 15 # ifndef OPENSSL_NO_RSA RSA *rsa_key[RSA_NUM]; long rsa_c[RSA_NUM][2]; static unsigned int rsa_bits[RSA_NUM] = { 512, 1024, 2048, 3072, 4096, 7680, 15360 }; static unsigned char *rsa_data[RSA_NUM] = { test512, test1024, test2048, test3072, test4096, test7680, test15360 }; static int rsa_data_length[RSA_NUM] = { sizeof(test512), sizeof(test1024), sizeof(test2048), sizeof(test3072), sizeof(test4096), sizeof(test7680), sizeof(test15360) }; # endif # ifndef OPENSSL_NO_DSA DSA *dsa_key[DSA_NUM]; long dsa_c[DSA_NUM][2]; static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 }; # endif # ifndef OPENSSL_NO_EC static unsigned int test_curves[EC_NUM] = { NID_secp160r1, NID_X9_62_prime192v1, NID_secp224r1, NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1, NID_sect163k1, NID_sect233k1, NID_sect283k1, NID_sect409k1, NID_sect571k1, NID_sect163r2, NID_sect233r1, NID_sect283r1, NID_sect409r1, NID_sect571r1 }; static const char *test_curves_names[EC_NUM] = { "secp160r1", "nistp192", "nistp224", "nistp256", "nistp384", "nistp521", "nistk163", "nistk233", "nistk283", "nistk409", "nistk571", "nistb163", "nistb233", "nistb283", "nistb409", "nistb571" }; static int test_curves_bits[EC_NUM] = { 160, 192, 224, 256, 384, 521, 163, 233, 283, 409, 571, 163, 233, 283, 409, 571 }; # endif # ifndef OPENSSL_NO_ECDSA unsigned char ecdsasig[256]; unsigned int ecdsasiglen; EC_KEY *ecdsa[EC_NUM]; long ecdsa_c[EC_NUM][2]; # endif # ifndef OPENSSL_NO_ECDH EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM]; unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE]; int secret_size_a, secret_size_b; int ecdh_checks = 0; int secret_idx = 0; long ecdh_c[EC_NUM][2]; # endif int rsa_doit[RSA_NUM]; int dsa_doit[DSA_NUM]; # ifndef OPENSSL_NO_ECDSA int ecdsa_doit[EC_NUM]; # endif # ifndef OPENSSL_NO_ECDH int ecdh_doit[EC_NUM]; # endif int doit[ALGOR_NUM]; int pr_header = 0; const EVP_CIPHER *evp_cipher = NULL; const EVP_MD *evp_md = NULL; int decrypt = 0; # ifndef NO_FORK int multi = 0; # endif int multiblock = 0; int misalign = MAX_MISALIGNMENT + 1; # ifndef TIMES usertime = -1; # endif apps_startup(); memset(results, 0, sizeof(results)); # ifndef OPENSSL_NO_DSA memset(dsa_key, 0, sizeof(dsa_key)); # endif # ifndef OPENSSL_NO_ECDSA for (i = 0; i < EC_NUM; i++) ecdsa[i] = NULL; # endif # ifndef OPENSSL_NO_ECDH for (i = 0; i < EC_NUM; i++) { ecdh_a[i] = NULL; ecdh_b[i] = NULL; } # endif if (bio_err == NULL) if ((bio_err = BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto end; # ifndef OPENSSL_NO_RSA memset(rsa_key, 0, sizeof(rsa_key)); for (i = 0; i < RSA_NUM; i++) rsa_key[i] = NULL; # endif if ((buf_malloc = (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) { BIO_printf(bio_err, "out of memory\n"); goto end; } if ((buf2_malloc = (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) { BIO_printf(bio_err, "out of memory\n"); goto end; } misalign = 0; buf = buf_malloc; buf2 = buf2_malloc; memset(c, 0, sizeof(c)); memset(DES_iv, 0, sizeof(DES_iv)); memset(iv, 0, sizeof(iv)); for (i = 0; i < ALGOR_NUM; i++) doit[i] = 0; for (i = 0; i < RSA_NUM; i++) rsa_doit[i] = 0; for (i = 0; i < DSA_NUM; i++) dsa_doit[i] = 0; # ifndef OPENSSL_NO_ECDSA for (i = 0; i < EC_NUM; i++) ecdsa_doit[i] = 0; # endif # ifndef OPENSSL_NO_ECDH for (i = 0; i < EC_NUM; i++) ecdh_doit[i] = 0; # endif j = 0; argc--; argv++; while (argc) { if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) { usertime = 0; j--; } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) { argc--; argv++; if (argc == 0) { BIO_printf(bio_err, "no EVP given\n"); goto end; } evp_cipher = EVP_get_cipherbyname(*argv); if (!evp_cipher) { evp_md = EVP_get_digestbyname(*argv); } if (!evp_cipher && !evp_md) { BIO_printf(bio_err, "%s is an unknown cipher or digest\n", *argv); goto end; } doit[D_EVP] = 1; } else if (argc > 0 && !strcmp(*argv, "-decrypt")) { decrypt = 1; j--; } # ifndef OPENSSL_NO_ENGINE else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) { argc--; argv++; if (argc == 0) { BIO_printf(bio_err, "no engine given\n"); goto end; } setup_engine(bio_err, *argv, 0); j--; } # endif # ifndef NO_FORK else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) { argc--; argv++; if (argc == 0) { BIO_printf(bio_err, "no multi count given\n"); goto end; } multi = atoi(argv[0]); if (multi <= 0) { BIO_printf(bio_err, "bad multi count\n"); goto end; } j--; } # endif else if (argc > 0 && !strcmp(*argv, "-mr")) { mr = 1; j--; } else if (argc > 0 && !strcmp(*argv, "-mb")) { multiblock = 1; j--; } else if (argc > 0 && !strcmp(*argv, "-misalign")) { argc--; argv++; if (argc == 0) { BIO_printf(bio_err, "no misalignment given\n"); goto end; } misalign = atoi(argv[0]); if (misalign < 0 || misalign > MAX_MISALIGNMENT) { BIO_printf(bio_err, "misalignment is outsize permitted range 0-%d\n", MAX_MISALIGNMENT); goto end; } buf = buf_malloc + misalign; buf2 = buf2_malloc + misalign; j--; } else # ifndef OPENSSL_NO_MD2 if (strcmp(*argv, "md2") == 0) doit[D_MD2] = 1; else # endif # ifndef OPENSSL_NO_MDC2 if (strcmp(*argv, "mdc2") == 0) doit[D_MDC2] = 1; else # endif # ifndef OPENSSL_NO_MD4 if (strcmp(*argv, "md4") == 0) doit[D_MD4] = 1; else # endif # ifndef OPENSSL_NO_MD5 if (strcmp(*argv, "md5") == 0) doit[D_MD5] = 1; else # endif # ifndef OPENSSL_NO_MD5 if (strcmp(*argv, "hmac") == 0) doit[D_HMAC] = 1; else # endif # ifndef OPENSSL_NO_SHA if (strcmp(*argv, "sha1") == 0) doit[D_SHA1] = 1; else if (strcmp(*argv, "sha") == 0) doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1; else # ifndef OPENSSL_NO_SHA256 if (strcmp(*argv, "sha256") == 0) doit[D_SHA256] = 1; else # endif # ifndef OPENSSL_NO_SHA512 if (strcmp(*argv, "sha512") == 0) doit[D_SHA512] = 1; else # endif # endif # ifndef OPENSSL_NO_WHIRLPOOL if (strcmp(*argv, "whirlpool") == 0) doit[D_WHIRLPOOL] = 1; else # endif # ifndef OPENSSL_NO_RMD160 if (strcmp(*argv, "ripemd") == 0) doit[D_RMD160] = 1; else if (strcmp(*argv, "rmd160") == 0) doit[D_RMD160] = 1; else if (strcmp(*argv, "ripemd160") == 0) doit[D_RMD160] = 1; else # endif # ifndef OPENSSL_NO_RC4 if (strcmp(*argv, "rc4") == 0) doit[D_RC4] = 1; else # endif # ifndef OPENSSL_NO_DES if (strcmp(*argv, "des-cbc") == 0) doit[D_CBC_DES] = 1; else if (strcmp(*argv, "des-ede3") == 0) doit[D_EDE3_DES] = 1; else # endif # ifndef OPENSSL_NO_AES if (strcmp(*argv, "aes-128-cbc") == 0) doit[D_CBC_128_AES] = 1; else if (strcmp(*argv, "aes-192-cbc") == 0) doit[D_CBC_192_AES] = 1; else if (strcmp(*argv, "aes-256-cbc") == 0) doit[D_CBC_256_AES] = 1; else if (strcmp(*argv, "aes-128-ige") == 0) doit[D_IGE_128_AES] = 1; else if (strcmp(*argv, "aes-192-ige") == 0) doit[D_IGE_192_AES] = 1; else if (strcmp(*argv, "aes-256-ige") == 0) doit[D_IGE_256_AES] = 1; else # endif # ifndef OPENSSL_NO_CAMELLIA if (strcmp(*argv, "camellia-128-cbc") == 0) doit[D_CBC_128_CML] = 1; else if (strcmp(*argv, "camellia-192-cbc") == 0) doit[D_CBC_192_CML] = 1; else if (strcmp(*argv, "camellia-256-cbc") == 0) doit[D_CBC_256_CML] = 1; else # endif # ifndef OPENSSL_NO_RSA # if 0 if (strcmp(*argv, "rsaref") == 0) { RSA_set_default_openssl_method(RSA_PKCS1_RSAref()); j--; } else # endif # ifndef RSA_NULL if (strcmp(*argv, "openssl") == 0) { RSA_set_default_method(RSA_PKCS1_SSLeay()); j--; } else # endif # endif if (strcmp(*argv, "dsa512") == 0) dsa_doit[R_DSA_512] = 2; else if (strcmp(*argv, "dsa1024") == 0) dsa_doit[R_DSA_1024] = 2; else if (strcmp(*argv, "dsa2048") == 0) dsa_doit[R_DSA_2048] = 2; else if (strcmp(*argv, "rsa512") == 0) rsa_doit[R_RSA_512] = 2; else if (strcmp(*argv, "rsa1024") == 0) rsa_doit[R_RSA_1024] = 2; else if (strcmp(*argv, "rsa2048") == 0) rsa_doit[R_RSA_2048] = 2; else if (strcmp(*argv, "rsa3072") == 0) rsa_doit[R_RSA_3072] = 2; else if (strcmp(*argv, "rsa4096") == 0) rsa_doit[R_RSA_4096] = 2; else if (strcmp(*argv, "rsa7680") == 0) rsa_doit[R_RSA_7680] = 2; else if (strcmp(*argv, "rsa15360") == 0) rsa_doit[R_RSA_15360] = 2; else # ifndef OPENSSL_NO_RC2 if (strcmp(*argv, "rc2-cbc") == 0) doit[D_CBC_RC2] = 1; else if (strcmp(*argv, "rc2") == 0) doit[D_CBC_RC2] = 1; else # endif # ifndef OPENSSL_NO_RC5 if (strcmp(*argv, "rc5-cbc") == 0) doit[D_CBC_RC5] = 1; else if (strcmp(*argv, "rc5") == 0) doit[D_CBC_RC5] = 1; else # endif # ifndef OPENSSL_NO_IDEA if (strcmp(*argv, "idea-cbc") == 0) doit[D_CBC_IDEA] = 1; else if (strcmp(*argv, "idea") == 0) doit[D_CBC_IDEA] = 1; else # endif # ifndef OPENSSL_NO_SEED if (strcmp(*argv, "seed-cbc") == 0) doit[D_CBC_SEED] = 1; else if (strcmp(*argv, "seed") == 0) doit[D_CBC_SEED] = 1; else # endif # ifndef OPENSSL_NO_BF if (strcmp(*argv, "bf-cbc") == 0) doit[D_CBC_BF] = 1; else if (strcmp(*argv, "blowfish") == 0) doit[D_CBC_BF] = 1; else if (strcmp(*argv, "bf") == 0) doit[D_CBC_BF] = 1; else # endif # ifndef OPENSSL_NO_CAST if (strcmp(*argv, "cast-cbc") == 0) doit[D_CBC_CAST] = 1; else if (strcmp(*argv, "cast") == 0) doit[D_CBC_CAST] = 1; else if (strcmp(*argv, "cast5") == 0) doit[D_CBC_CAST] = 1; else # endif # ifndef OPENSSL_NO_DES if (strcmp(*argv, "des") == 0) { doit[D_CBC_DES] = 1; doit[D_EDE3_DES] = 1; } else # endif # ifndef OPENSSL_NO_AES if (strcmp(*argv, "aes") == 0) { doit[D_CBC_128_AES] = 1; doit[D_CBC_192_AES] = 1; doit[D_CBC_256_AES] = 1; } else if (strcmp(*argv, "ghash") == 0) { doit[D_GHASH] = 1; } else # endif # ifndef OPENSSL_NO_CAMELLIA if (strcmp(*argv, "camellia") == 0) { doit[D_CBC_128_CML] = 1; doit[D_CBC_192_CML] = 1; doit[D_CBC_256_CML] = 1; } else # endif # ifndef OPENSSL_NO_RSA if (strcmp(*argv, "rsa") == 0) { rsa_doit[R_RSA_512] = 1; rsa_doit[R_RSA_1024] = 1; rsa_doit[R_RSA_2048] = 1; rsa_doit[R_RSA_3072] = 1; rsa_doit[R_RSA_4096] = 1; rsa_doit[R_RSA_7680] = 1; rsa_doit[R_RSA_15360] = 1; } else # endif # ifndef OPENSSL_NO_DSA if (strcmp(*argv, "dsa") == 0) { dsa_doit[R_DSA_512] = 1; dsa_doit[R_DSA_1024] = 1; dsa_doit[R_DSA_2048] = 1; } else # endif # ifndef OPENSSL_NO_ECDSA if (strcmp(*argv, "ecdsap160") == 0) ecdsa_doit[R_EC_P160] = 2; else if (strcmp(*argv, "ecdsap192") == 0) ecdsa_doit[R_EC_P192] = 2; else if (strcmp(*argv, "ecdsap224") == 0) ecdsa_doit[R_EC_P224] = 2; else if (strcmp(*argv, "ecdsap256") == 0) ecdsa_doit[R_EC_P256] = 2; else if (strcmp(*argv, "ecdsap384") == 0) ecdsa_doit[R_EC_P384] = 2; else if (strcmp(*argv, "ecdsap521") == 0) ecdsa_doit[R_EC_P521] = 2; else if (strcmp(*argv, "ecdsak163") == 0) ecdsa_doit[R_EC_K163] = 2; else if (strcmp(*argv, "ecdsak233") == 0) ecdsa_doit[R_EC_K233] = 2; else if (strcmp(*argv, "ecdsak283") == 0) ecdsa_doit[R_EC_K283] = 2; else if (strcmp(*argv, "ecdsak409") == 0) ecdsa_doit[R_EC_K409] = 2; else if (strcmp(*argv, "ecdsak571") == 0) ecdsa_doit[R_EC_K571] = 2; else if (strcmp(*argv, "ecdsab163") == 0) ecdsa_doit[R_EC_B163] = 2; else if (strcmp(*argv, "ecdsab233") == 0) ecdsa_doit[R_EC_B233] = 2; else if (strcmp(*argv, "ecdsab283") == 0) ecdsa_doit[R_EC_B283] = 2; else if (strcmp(*argv, "ecdsab409") == 0) ecdsa_doit[R_EC_B409] = 2; else if (strcmp(*argv, "ecdsab571") == 0) ecdsa_doit[R_EC_B571] = 2; else if (strcmp(*argv, "ecdsa") == 0) { for (i = 0; i < EC_NUM; i++) ecdsa_doit[i] = 1; } else # endif # ifndef OPENSSL_NO_ECDH if (strcmp(*argv, "ecdhp160") == 0) ecdh_doit[R_EC_P160] = 2; else if (strcmp(*argv, "ecdhp192") == 0) ecdh_doit[R_EC_P192] = 2; else if (strcmp(*argv, "ecdhp224") == 0) ecdh_doit[R_EC_P224] = 2; else if (strcmp(*argv, "ecdhp256") == 0) ecdh_doit[R_EC_P256] = 2; else if (strcmp(*argv, "ecdhp384") == 0) ecdh_doit[R_EC_P384] = 2; else if (strcmp(*argv, "ecdhp521") == 0) ecdh_doit[R_EC_P521] = 2; else if (strcmp(*argv, "ecdhk163") == 0) ecdh_doit[R_EC_K163] = 2; else if (strcmp(*argv, "ecdhk233") == 0) ecdh_doit[R_EC_K233] = 2; else if (strcmp(*argv, "ecdhk283") == 0) ecdh_doit[R_EC_K283] = 2; else if (strcmp(*argv, "ecdhk409") == 0) ecdh_doit[R_EC_K409] = 2; else if (strcmp(*argv, "ecdhk571") == 0) ecdh_doit[R_EC_K571] = 2; else if (strcmp(*argv, "ecdhb163") == 0) ecdh_doit[R_EC_B163] = 2; else if (strcmp(*argv, "ecdhb233") == 0) ecdh_doit[R_EC_B233] = 2; else if (strcmp(*argv, "ecdhb283") == 0) ecdh_doit[R_EC_B283] = 2; else if (strcmp(*argv, "ecdhb409") == 0) ecdh_doit[R_EC_B409] = 2; else if (strcmp(*argv, "ecdhb571") == 0) ecdh_doit[R_EC_B571] = 2; else if (strcmp(*argv, "ecdh") == 0) { for (i = 0; i < EC_NUM; i++) ecdh_doit[i] = 1; } else # endif { BIO_printf(bio_err, "Error: bad option or value\n"); BIO_printf(bio_err, "\n"); BIO_printf(bio_err, "Available values:\n"); # ifndef OPENSSL_NO_MD2 BIO_printf(bio_err, "md2 "); # endif # ifndef OPENSSL_NO_MDC2 BIO_printf(bio_err, "mdc2 "); # endif # ifndef OPENSSL_NO_MD4 BIO_printf(bio_err, "md4 "); # endif # ifndef OPENSSL_NO_MD5 BIO_printf(bio_err, "md5 "); # ifndef OPENSSL_NO_HMAC BIO_printf(bio_err, "hmac "); # endif # endif # ifndef OPENSSL_NO_SHA1 BIO_printf(bio_err, "sha1 "); # endif # ifndef OPENSSL_NO_SHA256 BIO_printf(bio_err, "sha256 "); # endif # ifndef OPENSSL_NO_SHA512 BIO_printf(bio_err, "sha512 "); # endif # ifndef OPENSSL_NO_WHIRLPOOL BIO_printf(bio_err, "whirlpool"); # endif # ifndef OPENSSL_NO_RMD160 BIO_printf(bio_err, "rmd160"); # endif # if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \ !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \ !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \ !defined(OPENSSL_NO_WHIRLPOOL) BIO_printf(bio_err, "\n"); # endif # ifndef OPENSSL_NO_IDEA BIO_printf(bio_err, "idea-cbc "); # endif # ifndef OPENSSL_NO_SEED BIO_printf(bio_err, "seed-cbc "); # endif # ifndef OPENSSL_NO_RC2 BIO_printf(bio_err, "rc2-cbc "); # endif # ifndef OPENSSL_NO_RC5 BIO_printf(bio_err, "rc5-cbc "); # endif # ifndef OPENSSL_NO_BF BIO_printf(bio_err, "bf-cbc"); # endif # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \ !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5) BIO_printf(bio_err, "\n"); # endif # ifndef OPENSSL_NO_DES BIO_printf(bio_err, "des-cbc des-ede3 "); # endif # ifndef OPENSSL_NO_AES BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc "); BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige "); # endif # ifndef OPENSSL_NO_CAMELLIA BIO_printf(bio_err, "\n"); BIO_printf(bio_err, "camellia-128-cbc camellia-192-cbc camellia-256-cbc "); # endif # ifndef OPENSSL_NO_RC4 BIO_printf(bio_err, "rc4"); # endif BIO_printf(bio_err, "\n"); # ifndef OPENSSL_NO_RSA BIO_printf(bio_err, "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n"); BIO_printf(bio_err, "rsa7680 rsa15360\n"); # endif # ifndef OPENSSL_NO_DSA BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n"); # endif # ifndef OPENSSL_NO_ECDSA BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 " "ecdsap256 ecdsap384 ecdsap521\n"); BIO_printf(bio_err, "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n"); BIO_printf(bio_err, "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n"); BIO_printf(bio_err, "ecdsa\n"); # endif # ifndef OPENSSL_NO_ECDH BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 " "ecdhp256 ecdhp384 ecdhp521\n"); BIO_printf(bio_err, "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n"); BIO_printf(bio_err, "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n"); BIO_printf(bio_err, "ecdh\n"); # endif # ifndef OPENSSL_NO_IDEA BIO_printf(bio_err, "idea "); # endif # ifndef OPENSSL_NO_SEED BIO_printf(bio_err, "seed "); # endif # ifndef OPENSSL_NO_RC2 BIO_printf(bio_err, "rc2 "); # endif # ifndef OPENSSL_NO_DES BIO_printf(bio_err, "des "); # endif # ifndef OPENSSL_NO_AES BIO_printf(bio_err, "aes "); # endif # ifndef OPENSSL_NO_CAMELLIA BIO_printf(bio_err, "camellia "); # endif # ifndef OPENSSL_NO_RSA BIO_printf(bio_err, "rsa "); # endif # ifndef OPENSSL_NO_BF BIO_printf(bio_err, "blowfish"); # endif # if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \ !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \ !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \ !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA) BIO_printf(bio_err, "\n"); # endif BIO_printf(bio_err, "\n"); BIO_printf(bio_err, "Available options:\n"); # if defined(TIMES) || defined(USE_TOD) BIO_printf(bio_err, "-elapsed " "measure time in real time instead of CPU user time.\n"); # endif # ifndef OPENSSL_NO_ENGINE BIO_printf(bio_err, "-engine e " "use engine e, possibly a hardware device.\n"); # endif BIO_printf(bio_err, "-evp e " "use EVP e.\n"); BIO_printf(bio_err, "-decrypt " "time decryption instead of encryption (only EVP).\n"); BIO_printf(bio_err, "-mr " "produce machine readable output.\n"); BIO_printf(bio_err, "-mb " "perform multi-block benchmark (for specific ciphers)\n"); BIO_printf(bio_err, "-misalign n " "perform benchmark with misaligned data\n"); # ifndef NO_FORK BIO_printf(bio_err, "-multi n " "run n benchmarks in parallel.\n"); # endif goto end; } argc--; argv++; j++; } # ifndef NO_FORK if (multi && do_multi(multi)) goto show_res; # endif if (j == 0) { for (i = 0; i < ALGOR_NUM; i++) { if (i != D_EVP) doit[i] = 1; } for (i = 0; i < RSA_NUM; i++) rsa_doit[i] = 1; for (i = 0; i < DSA_NUM; i++) dsa_doit[i] = 1; # ifndef OPENSSL_NO_ECDSA for (i = 0; i < EC_NUM; i++) ecdsa_doit[i] = 1; # endif # ifndef OPENSSL_NO_ECDH for (i = 0; i < EC_NUM; i++) ecdh_doit[i] = 1; # endif } for (i = 0; i < ALGOR_NUM; i++) if (doit[i]) pr_header++; if (usertime == 0 && !mr) BIO_printf(bio_err, "You have chosen to measure elapsed time " "instead of user CPU time.\n"); # ifndef OPENSSL_NO_RSA for (i = 0; i < RSA_NUM; i++) { const unsigned char *p; p = rsa_data[i]; rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]); if (rsa_key[i] == NULL) { BIO_printf(bio_err, "internal error loading RSA key number %d\n", i); goto end; } # if 0 else { BIO_printf(bio_err, mr ? "+RK:%d:" : "Loaded RSA key, %d bit modulus and e= 0x", BN_num_bits(rsa_key[i]->n)); BN_print(bio_err, rsa_key[i]->e); BIO_printf(bio_err, "\n"); } # endif } # endif # ifndef OPENSSL_NO_DSA dsa_key[0] = get_dsa512(); dsa_key[1] = get_dsa1024(); dsa_key[2] = get_dsa2048(); # endif # ifndef OPENSSL_NO_DES DES_set_key_unchecked(&key, &sch); DES_set_key_unchecked(&key2, &sch2); DES_set_key_unchecked(&key3, &sch3); # endif # ifndef OPENSSL_NO_AES AES_set_encrypt_key(key16, 128, &aes_ks1); AES_set_encrypt_key(key24, 192, &aes_ks2); AES_set_encrypt_key(key32, 256, &aes_ks3); # endif # ifndef OPENSSL_NO_CAMELLIA Camellia_set_key(key16, 128, &camellia_ks1); Camellia_set_key(ckey24, 192, &camellia_ks2); Camellia_set_key(ckey32, 256, &camellia_ks3); # endif # ifndef OPENSSL_NO_IDEA idea_set_encrypt_key(key16, &idea_ks); # endif # ifndef OPENSSL_NO_SEED SEED_set_key(key16, &seed_ks); # endif # ifndef OPENSSL_NO_RC4 RC4_set_key(&rc4_ks, 16, key16); # endif # ifndef OPENSSL_NO_RC2 RC2_set_key(&rc2_ks, 16, key16, 128); # endif # ifndef OPENSSL_NO_RC5 RC5_32_set_key(&rc5_ks, 16, key16, 12); # endif # ifndef OPENSSL_NO_BF BF_set_key(&bf_ks, 16, key16); # endif # ifndef OPENSSL_NO_CAST CAST_set_key(&cast_ks, 16, key16); # endif # ifndef OPENSSL_NO_RSA memset(rsa_c, 0, sizeof(rsa_c)); # endif # ifndef SIGALRM # ifndef OPENSSL_NO_DES BIO_printf(bio_err, "First we calculate the approximate speed ...\n"); count = 10; do { long it; count *= 2; Time_F(START); for (it = count; it; it--) DES_ecb_encrypt((DES_cblock *)buf, (DES_cblock *)buf, &sch, DES_ENCRYPT); d = Time_F(STOP); } while (d < 3); save_count = count; c[D_MD2][0] = count / 10; c[D_MDC2][0] = count / 10; c[D_MD4][0] = count; c[D_MD5][0] = count; c[D_HMAC][0] = count; c[D_SHA1][0] = count; c[D_RMD160][0] = count; c[D_RC4][0] = count * 5; c[D_CBC_DES][0] = count; c[D_EDE3_DES][0] = count / 3; c[D_CBC_IDEA][0] = count; c[D_CBC_SEED][0] = count; c[D_CBC_RC2][0] = count; c[D_CBC_RC5][0] = count; c[D_CBC_BF][0] = count; c[D_CBC_CAST][0] = count; c[D_CBC_128_AES][0] = count; c[D_CBC_192_AES][0] = count; c[D_CBC_256_AES][0] = count; c[D_CBC_128_CML][0] = count; c[D_CBC_192_CML][0] = count; c[D_CBC_256_CML][0] = count; c[D_SHA256][0] = count; c[D_SHA512][0] = count; c[D_WHIRLPOOL][0] = count; c[D_IGE_128_AES][0] = count; c[D_IGE_192_AES][0] = count; c[D_IGE_256_AES][0] = count; c[D_GHASH][0] = count; for (i = 1; i < SIZE_NUM; i++) { long l0, l1; l0 = (long)lengths[0]; l1 = (long)lengths[i]; c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1; c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1; c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1; c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1; c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1; c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1; c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1; c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1; c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1; c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1; l0 = (long)lengths[i - 1]; c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1; c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1; c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1; c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1; c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1; c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1; c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1; c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1; c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1; c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1; c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1; c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1; c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1; c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1; c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1; c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1; c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1; c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1; } # ifndef OPENSSL_NO_RSA rsa_c[R_RSA_512][0] = count / 2000; rsa_c[R_RSA_512][1] = count / 400; for (i = 1; i < RSA_NUM; i++) { rsa_c[i][0] = rsa_c[i - 1][0] / 8; rsa_c[i][1] = rsa_c[i - 1][1] / 4; if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0)) rsa_doit[i] = 0; else { if (rsa_c[i][0] == 0) { rsa_c[i][0] = 1; rsa_c[i][1] = 20; } } } # endif # ifndef OPENSSL_NO_DSA dsa_c[R_DSA_512][0] = count / 1000; dsa_c[R_DSA_512][1] = count / 1000 / 2; for (i = 1; i < DSA_NUM; i++) { dsa_c[i][0] = dsa_c[i - 1][0] / 4; dsa_c[i][1] = dsa_c[i - 1][1] / 4; if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0)) dsa_doit[i] = 0; else { if (dsa_c[i] == 0) { dsa_c[i][0] = 1; dsa_c[i][1] = 1; } } } # endif # ifndef OPENSSL_NO_ECDSA ecdsa_c[R_EC_P160][0] = count / 1000; ecdsa_c[R_EC_P160][1] = count / 1000 / 2; for (i = R_EC_P192; i <= R_EC_P521; i++) { ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2; ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2; if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0)) ecdsa_doit[i] = 0; else { if (ecdsa_c[i] == 0) { ecdsa_c[i][0] = 1; ecdsa_c[i][1] = 1; } } } ecdsa_c[R_EC_K163][0] = count / 1000; ecdsa_c[R_EC_K163][1] = count / 1000 / 2; for (i = R_EC_K233; i <= R_EC_K571; i++) { ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2; ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2; if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0)) ecdsa_doit[i] = 0; else { if (ecdsa_c[i] == 0) { ecdsa_c[i][0] = 1; ecdsa_c[i][1] = 1; } } } ecdsa_c[R_EC_B163][0] = count / 1000; ecdsa_c[R_EC_B163][1] = count / 1000 / 2; for (i = R_EC_B233; i <= R_EC_B571; i++) { ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2; ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2; if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0)) ecdsa_doit[i] = 0; else { if (ecdsa_c[i] == 0) { ecdsa_c[i][0] = 1; ecdsa_c[i][1] = 1; } } } # endif # ifndef OPENSSL_NO_ECDH ecdh_c[R_EC_P160][0] = count / 1000; ecdh_c[R_EC_P160][1] = count / 1000; for (i = R_EC_P192; i <= R_EC_P521; i++) { ecdh_c[i][0] = ecdh_c[i - 1][0] / 2; ecdh_c[i][1] = ecdh_c[i - 1][1] / 2; if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0)) ecdh_doit[i] = 0; else { if (ecdh_c[i] == 0) { ecdh_c[i][0] = 1; ecdh_c[i][1] = 1; } } } ecdh_c[R_EC_K163][0] = count / 1000; ecdh_c[R_EC_K163][1] = count / 1000; for (i = R_EC_K233; i <= R_EC_K571; i++) { ecdh_c[i][0] = ecdh_c[i - 1][0] / 2; ecdh_c[i][1] = ecdh_c[i - 1][1] / 2; if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0)) ecdh_doit[i] = 0; else { if (ecdh_c[i] == 0) { ecdh_c[i][0] = 1; ecdh_c[i][1] = 1; } } } ecdh_c[R_EC_B163][0] = count / 1000; ecdh_c[R_EC_B163][1] = count / 1000; for (i = R_EC_B233; i <= R_EC_B571; i++) { ecdh_c[i][0] = ecdh_c[i - 1][0] / 2; ecdh_c[i][1] = ecdh_c[i - 1][1] / 2; if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0)) ecdh_doit[i] = 0; else { if (ecdh_c[i] == 0) { ecdh_c[i][0] = 1; ecdh_c[i][1] = 1; } } } # endif # define COND(d) (count < (d)) # define COUNT(d) (d) # else # error "You cannot disable DES on systems without SIGALRM." # endif # else # define COND(c) (run && count<0x7fffffff) # define COUNT(d) (count) # ifndef _WIN32 signal(SIGALRM, sig_done); # endif # endif # ifndef OPENSSL_NO_MD2 if (doit[D_MD2]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_MD2], c[D_MD2][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_MD2][j]); count++) EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL, EVP_md2(), NULL); d = Time_F(STOP); print_result(D_MD2, j, count, d); } } # endif # ifndef OPENSSL_NO_MDC2 if (doit[D_MDC2]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_MDC2][j]); count++) EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL, EVP_mdc2(), NULL); d = Time_F(STOP); print_result(D_MDC2, j, count, d); } } # endif # ifndef OPENSSL_NO_MD4 if (doit[D_MD4]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_MD4], c[D_MD4][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_MD4][j]); count++) EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]), NULL, EVP_md4(), NULL); d = Time_F(STOP); print_result(D_MD4, j, count, d); } } # endif # ifndef OPENSSL_NO_MD5 if (doit[D_MD5]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_MD5], c[D_MD5][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_MD5][j]); count++) MD5(buf, lengths[j], md5); d = Time_F(STOP); print_result(D_MD5, j, count, d); } } # endif # if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC) if (doit[D_HMAC]) { HMAC_CTX hctx; HMAC_CTX_init(&hctx); HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...", 16, EVP_md5(), NULL); for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) { HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL); HMAC_Update(&hctx, buf, lengths[j]); HMAC_Final(&hctx, &(hmac[0]), NULL); } d = Time_F(STOP); print_result(D_HMAC, j, count, d); } HMAC_CTX_cleanup(&hctx); } # endif # ifndef OPENSSL_NO_SHA if (doit[D_SHA1]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_SHA1][j]); count++) # if 0 EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL, EVP_sha1(), NULL); # else SHA1(buf, lengths[j], sha); # endif d = Time_F(STOP); print_result(D_SHA1, j, count, d); } } # ifndef OPENSSL_NO_SHA256 if (doit[D_SHA256]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_SHA256][j]); count++) SHA256(buf, lengths[j], sha256); d = Time_F(STOP); print_result(D_SHA256, j, count, d); } } # endif # ifndef OPENSSL_NO_SHA512 if (doit[D_SHA512]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_SHA512][j]); count++) SHA512(buf, lengths[j], sha512); d = Time_F(STOP); print_result(D_SHA512, j, count, d); } } # endif # endif # ifndef OPENSSL_NO_WHIRLPOOL if (doit[D_WHIRLPOOL]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++) WHIRLPOOL(buf, lengths[j], whirlpool); d = Time_F(STOP); print_result(D_WHIRLPOOL, j, count, d); } } # endif # ifndef OPENSSL_NO_RMD160 if (doit[D_RMD160]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_RMD160][j]); count++) EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL, EVP_ripemd160(), NULL); d = Time_F(STOP); print_result(D_RMD160, j, count, d); } } # endif # ifndef OPENSSL_NO_RC4 if (doit[D_RC4]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_RC4], c[D_RC4][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_RC4][j]); count++) RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf); d = Time_F(STOP); print_result(D_RC4, j, count, d); } } # endif # ifndef OPENSSL_NO_DES if (doit[D_CBC_DES]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++) DES_ncbc_encrypt(buf, buf, lengths[j], &sch, &DES_iv, DES_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_DES, j, count, d); } } if (doit[D_EDE3_DES]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++) DES_ede3_cbc_encrypt(buf, buf, lengths[j], &sch, &sch2, &sch3, &DES_iv, DES_ENCRYPT); d = Time_F(STOP); print_result(D_EDE3_DES, j, count, d); } } # endif # ifndef OPENSSL_NO_AES if (doit[D_CBC_128_AES]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++) AES_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &aes_ks1, iv, AES_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_128_AES, j, count, d); } } if (doit[D_CBC_192_AES]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++) AES_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &aes_ks2, iv, AES_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_192_AES, j, count, d); } } if (doit[D_CBC_256_AES]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++) AES_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &aes_ks3, iv, AES_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_256_AES, j, count, d); } } if (doit[D_IGE_128_AES]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++) AES_ige_encrypt(buf, buf2, (unsigned long)lengths[j], &aes_ks1, iv, AES_ENCRYPT); d = Time_F(STOP); print_result(D_IGE_128_AES, j, count, d); } } if (doit[D_IGE_192_AES]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++) AES_ige_encrypt(buf, buf2, (unsigned long)lengths[j], &aes_ks2, iv, AES_ENCRYPT); d = Time_F(STOP); print_result(D_IGE_192_AES, j, count, d); } } if (doit[D_IGE_256_AES]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++) AES_ige_encrypt(buf, buf2, (unsigned long)lengths[j], &aes_ks3, iv, AES_ENCRYPT); d = Time_F(STOP); print_result(D_IGE_256_AES, j, count, d); } } if (doit[D_GHASH]) { GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt); CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12); for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_GHASH][j]); count++) CRYPTO_gcm128_aad(ctx, buf, lengths[j]); d = Time_F(STOP); print_result(D_GHASH, j, count, d); } CRYPTO_gcm128_release(ctx); } # endif # ifndef OPENSSL_NO_CAMELLIA if (doit[D_CBC_128_CML]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++) Camellia_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &camellia_ks1, iv, CAMELLIA_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_128_CML, j, count, d); } } if (doit[D_CBC_192_CML]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++) Camellia_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &camellia_ks2, iv, CAMELLIA_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_192_CML, j, count, d); } } if (doit[D_CBC_256_CML]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++) Camellia_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &camellia_ks3, iv, CAMELLIA_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_256_CML, j, count, d); } } # endif # ifndef OPENSSL_NO_IDEA if (doit[D_CBC_IDEA]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++) idea_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &idea_ks, iv, IDEA_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_IDEA, j, count, d); } } # endif # ifndef OPENSSL_NO_SEED if (doit[D_CBC_SEED]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++) SEED_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &seed_ks, iv, 1); d = Time_F(STOP); print_result(D_CBC_SEED, j, count, d); } } # endif # ifndef OPENSSL_NO_RC2 if (doit[D_CBC_RC2]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++) RC2_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &rc2_ks, iv, RC2_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_RC2, j, count, d); } } # endif # ifndef OPENSSL_NO_RC5 if (doit[D_CBC_RC5]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++) RC5_32_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &rc5_ks, iv, RC5_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_RC5, j, count, d); } } # endif # ifndef OPENSSL_NO_BF if (doit[D_CBC_BF]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++) BF_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &bf_ks, iv, BF_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_BF, j, count, d); } } # endif # ifndef OPENSSL_NO_CAST if (doit[D_CBC_CAST]) { for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++) CAST_cbc_encrypt(buf, buf, (unsigned long)lengths[j], &cast_ks, iv, CAST_ENCRYPT); d = Time_F(STOP); print_result(D_CBC_CAST, j, count, d); } } # endif if (doit[D_EVP]) { # ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK if (multiblock && evp_cipher) { if (! (EVP_CIPHER_flags(evp_cipher) & EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) { fprintf(stderr, "%s is not multi-block capable\n", OBJ_nid2ln(evp_cipher->nid)); goto end; } multiblock_speed(evp_cipher); mret = 0; goto end; } # endif for (j = 0; j < SIZE_NUM; j++) { if (evp_cipher) { EVP_CIPHER_CTX ctx; int outl; names[D_EVP] = OBJ_nid2ln(evp_cipher->nid); print_message(names[D_EVP], save_count, lengths[j]); EVP_CIPHER_CTX_init(&ctx); if (decrypt) EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv); else EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv); EVP_CIPHER_CTX_set_padding(&ctx, 0); Time_F(START); if (decrypt) for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++) EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]); else for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++) EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]); if (decrypt) EVP_DecryptFinal_ex(&ctx, buf, &outl); else EVP_EncryptFinal_ex(&ctx, buf, &outl); d = Time_F(STOP); EVP_CIPHER_CTX_cleanup(&ctx); } if (evp_md) { names[D_EVP] = OBJ_nid2ln(evp_md->type); print_message(names[D_EVP], save_count, lengths[j]); Time_F(START); for (count = 0, run = 1; COND(save_count * 4 * lengths[0] / lengths[j]); count++) EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL); d = Time_F(STOP); } print_result(D_EVP, j, count, d); } } # ifndef OPENSSL_SYS_WIN32 # endif RAND_pseudo_bytes(buf, 36); # ifndef OPENSSL_NO_RSA for (j = 0; j < RSA_NUM; j++) { int ret; if (!rsa_doit[j]) continue; ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]); if (ret == 0) { BIO_printf(bio_err, "RSA sign failure. No RSA sign will be done.\n"); ERR_print_errors(bio_err); rsa_count = 1; } else { pkey_print_message("private", "rsa", rsa_c[j][0], rsa_bits[j], RSA_SECONDS); Time_F(START); for (count = 0, run = 1; COND(rsa_c[j][0]); count++) { ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]); if (ret == 0) { BIO_printf(bio_err, "RSA sign failure\n"); ERR_print_errors(bio_err); count = 1; break; } } d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R1:%ld:%d:%.2f\n" : "%ld %d bit private RSA's in %.2fs\n", count, rsa_bits[j], d); rsa_results[j][0] = d / (double)count; rsa_count = count; } # if 1 ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]); if (ret <= 0) { BIO_printf(bio_err, "RSA verify failure. No RSA verify will be done.\n"); ERR_print_errors(bio_err); rsa_doit[j] = 0; } else { pkey_print_message("public", "rsa", rsa_c[j][1], rsa_bits[j], RSA_SECONDS); Time_F(START); for (count = 0, run = 1; COND(rsa_c[j][1]); count++) { ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]); if (ret <= 0) { BIO_printf(bio_err, "RSA verify failure\n"); ERR_print_errors(bio_err); count = 1; break; } } d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R2:%ld:%d:%.2f\n" : "%ld %d bit public RSA's in %.2fs\n", count, rsa_bits[j], d); rsa_results[j][1] = d / (double)count; } # endif if (rsa_count <= 1) { for (j++; j < RSA_NUM; j++) rsa_doit[j] = 0; } } # endif RAND_pseudo_bytes(buf, 20); # ifndef OPENSSL_NO_DSA if (RAND_status() != 1) { RAND_seed(rnd_seed, sizeof rnd_seed); rnd_fake = 1; } for (j = 0; j < DSA_NUM; j++) { unsigned int kk; int ret; if (!dsa_doit[j]) continue; ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]); if (ret == 0) { BIO_printf(bio_err, "DSA sign failure. No DSA sign will be done.\n"); ERR_print_errors(bio_err); rsa_count = 1; } else { pkey_print_message("sign", "dsa", dsa_c[j][0], dsa_bits[j], DSA_SECONDS); Time_F(START); for (count = 0, run = 1; COND(dsa_c[j][0]); count++) { ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]); if (ret == 0) { BIO_printf(bio_err, "DSA sign failure\n"); ERR_print_errors(bio_err); count = 1; break; } } d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R3:%ld:%d:%.2f\n" : "%ld %d bit DSA signs in %.2fs\n", count, dsa_bits[j], d); dsa_results[j][0] = d / (double)count; rsa_count = count; } ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]); if (ret <= 0) { BIO_printf(bio_err, "DSA verify failure. No DSA verify will be done.\n"); ERR_print_errors(bio_err); dsa_doit[j] = 0; } else { pkey_print_message("verify", "dsa", dsa_c[j][1], dsa_bits[j], DSA_SECONDS); Time_F(START); for (count = 0, run = 1; COND(dsa_c[j][1]); count++) { ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]); if (ret <= 0) { BIO_printf(bio_err, "DSA verify failure\n"); ERR_print_errors(bio_err); count = 1; break; } } d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R4:%ld:%d:%.2f\n" : "%ld %d bit DSA verify in %.2fs\n", count, dsa_bits[j], d); dsa_results[j][1] = d / (double)count; } if (rsa_count <= 1) { for (j++; j < DSA_NUM; j++) dsa_doit[j] = 0; } } if (rnd_fake) RAND_cleanup(); # endif # ifndef OPENSSL_NO_ECDSA if (RAND_status() != 1) { RAND_seed(rnd_seed, sizeof rnd_seed); rnd_fake = 1; } for (j = 0; j < EC_NUM; j++) { int ret; if (!ecdsa_doit[j]) continue; ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]); if (ecdsa[j] == NULL) { BIO_printf(bio_err, "ECDSA failure.\n"); ERR_print_errors(bio_err); rsa_count = 1; } else { # if 1 EC_KEY_precompute_mult(ecdsa[j], NULL); # endif EC_KEY_generate_key(ecdsa[j]); ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]); if (ret == 0) { BIO_printf(bio_err, "ECDSA sign failure. No ECDSA sign will be done.\n"); ERR_print_errors(bio_err); rsa_count = 1; } else { pkey_print_message("sign", "ecdsa", ecdsa_c[j][0], test_curves_bits[j], ECDSA_SECONDS); Time_F(START); for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) { ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]); if (ret == 0) { BIO_printf(bio_err, "ECDSA sign failure\n"); ERR_print_errors(bio_err); count = 1; break; } } d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" : "%ld %d bit ECDSA signs in %.2fs \n", count, test_curves_bits[j], d); ecdsa_results[j][0] = d / (double)count; rsa_count = count; } ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]); if (ret != 1) { BIO_printf(bio_err, "ECDSA verify failure. No ECDSA verify will be done.\n"); ERR_print_errors(bio_err); ecdsa_doit[j] = 0; } else { pkey_print_message("verify", "ecdsa", ecdsa_c[j][1], test_curves_bits[j], ECDSA_SECONDS); Time_F(START); for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) { ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]); if (ret != 1) { BIO_printf(bio_err, "ECDSA verify failure\n"); ERR_print_errors(bio_err); count = 1; break; } } d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R6:%ld:%d:%.2f\n" : "%ld %d bit ECDSA verify in %.2fs\n", count, test_curves_bits[j], d); ecdsa_results[j][1] = d / (double)count; } if (rsa_count <= 1) { for (j++; j < EC_NUM; j++) ecdsa_doit[j] = 0; } } } if (rnd_fake) RAND_cleanup(); # endif # ifndef OPENSSL_NO_ECDH if (RAND_status() != 1) { RAND_seed(rnd_seed, sizeof rnd_seed); rnd_fake = 1; } for (j = 0; j < EC_NUM; j++) { if (!ecdh_doit[j]) continue; ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]); ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]); if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) { BIO_printf(bio_err, "ECDH failure.\n"); ERR_print_errors(bio_err); rsa_count = 1; } else { if (!EC_KEY_generate_key(ecdh_a[j]) || !EC_KEY_generate_key(ecdh_b[j])) { BIO_printf(bio_err, "ECDH key generation failure.\n"); ERR_print_errors(bio_err); rsa_count = 1; } else { int field_size, outlen; void *(*kdf) (const void *in, size_t inlen, void *out, size_t *xoutlen); field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j])); if (field_size <= 24 * 8) { outlen = KDF1_SHA1_len; kdf = KDF1_SHA1; } else { outlen = (field_size + 7) / 8; kdf = NULL; } secret_size_a = ECDH_compute_key(secret_a, outlen, EC_KEY_get0_public_key(ecdh_b[j]), ecdh_a[j], kdf); secret_size_b = ECDH_compute_key(secret_b, outlen, EC_KEY_get0_public_key(ecdh_a[j]), ecdh_b[j], kdf); if (secret_size_a != secret_size_b) ecdh_checks = 0; else ecdh_checks = 1; for (secret_idx = 0; (secret_idx < secret_size_a) && (ecdh_checks == 1); secret_idx++) { if (secret_a[secret_idx] != secret_b[secret_idx]) ecdh_checks = 0; } if (ecdh_checks == 0) { BIO_printf(bio_err, "ECDH computations don't match.\n"); ERR_print_errors(bio_err); rsa_count = 1; } pkey_print_message("", "ecdh", ecdh_c[j][0], test_curves_bits[j], ECDH_SECONDS); Time_F(START); for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) { ECDH_compute_key(secret_a, outlen, EC_KEY_get0_public_key(ecdh_b[j]), ecdh_a[j], kdf); } d = Time_F(STOP); BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" : "%ld %d-bit ECDH ops in %.2fs\n", count, test_curves_bits[j], d); ecdh_results[j][0] = d / (double)count; rsa_count = count; } } if (rsa_count <= 1) { for (j++; j < EC_NUM; j++) ecdh_doit[j] = 0; } } if (rnd_fake) RAND_cleanup(); # endif # ifndef NO_FORK show_res: # endif if (!mr) { fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION)); fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON)); printf("options:"); printf("%s ", BN_options()); # ifndef OPENSSL_NO_MD2 printf("%s ", MD2_options()); # endif # ifndef OPENSSL_NO_RC4 printf("%s ", RC4_options()); # endif # ifndef OPENSSL_NO_DES printf("%s ", DES_options()); # endif # ifndef OPENSSL_NO_AES printf("%s ", AES_options()); # endif # ifndef OPENSSL_NO_IDEA printf("%s ", idea_options()); # endif # ifndef OPENSSL_NO_BF printf("%s ", BF_options()); # endif fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS)); } if (pr_header) { if (mr) fprintf(stdout, "+H"); else { fprintf(stdout, "The 'numbers' are in 1000s of bytes per second processed.\n"); fprintf(stdout, "type "); } for (j = 0; j < SIZE_NUM; j++) fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]); fprintf(stdout, "\n"); } for (k = 0; k < ALGOR_NUM; k++) { if (!doit[k]) continue; if (mr) fprintf(stdout, "+F:%d:%s", k, names[k]); else fprintf(stdout, "%-13s", names[k]); for (j = 0; j < SIZE_NUM; j++) { if (results[k][j] > 10000 && !mr) fprintf(stdout, " %11.2fk", results[k][j] / 1e3); else fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]); } fprintf(stdout, "\n"); } # ifndef OPENSSL_NO_RSA j = 1; for (k = 0; k < RSA_NUM; k++) { if (!rsa_doit[k]) continue; if (j && !mr) { printf("%18ssign verify sign/s verify/s\n", " "); j = 0; } if (mr) fprintf(stdout, "+F2:%u:%u:%f:%f\n", k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]); else fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", rsa_bits[k], rsa_results[k][0], rsa_results[k][1], 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]); } # endif # ifndef OPENSSL_NO_DSA j = 1; for (k = 0; k < DSA_NUM; k++) { if (!dsa_doit[k]) continue; if (j && !mr) { printf("%18ssign verify sign/s verify/s\n", " "); j = 0; } if (mr) fprintf(stdout, "+F3:%u:%u:%f:%f\n", k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]); else fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", dsa_bits[k], dsa_results[k][0], dsa_results[k][1], 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]); } # endif # ifndef OPENSSL_NO_ECDSA j = 1; for (k = 0; k < EC_NUM; k++) { if (!ecdsa_doit[k]) continue; if (j && !mr) { printf("%30ssign verify sign/s verify/s\n", " "); j = 0; } if (mr) fprintf(stdout, "+F4:%u:%u:%f:%f\n", k, test_curves_bits[k], ecdsa_results[k][0], ecdsa_results[k][1]); else fprintf(stdout, "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n", test_curves_bits[k], test_curves_names[k], ecdsa_results[k][0], ecdsa_results[k][1], 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]); } # endif # ifndef OPENSSL_NO_ECDH j = 1; for (k = 0; k < EC_NUM; k++) { if (!ecdh_doit[k]) continue; if (j && !mr) { printf("%30sop op/s\n", " "); j = 0; } if (mr) fprintf(stdout, "+F5:%u:%u:%f:%f\n", k, test_curves_bits[k], ecdh_results[k][0], 1.0 / ecdh_results[k][0]); else fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n", test_curves_bits[k], test_curves_names[k], ecdh_results[k][0], 1.0 / ecdh_results[k][0]); } # endif mret = 0; end: ERR_print_errors(bio_err); if (buf_malloc != NULL) OPENSSL_free(buf_malloc); if (buf2_malloc != NULL) OPENSSL_free(buf2_malloc); # ifndef OPENSSL_NO_RSA for (i = 0; i < RSA_NUM; i++) if (rsa_key[i] != NULL) RSA_free(rsa_key[i]); # endif # ifndef OPENSSL_NO_DSA for (i = 0; i < DSA_NUM; i++) if (dsa_key[i] != NULL) DSA_free(dsa_key[i]); # endif # ifndef OPENSSL_NO_ECDSA for (i = 0; i < EC_NUM; i++) if (ecdsa[i] != NULL) EC_KEY_free(ecdsa[i]); # endif # ifndef OPENSSL_NO_ECDH for (i = 0; i < EC_NUM; i++) { if (ecdh_a[i] != NULL) EC_KEY_free(ecdh_a[i]); if (ecdh_b[i] != NULL) EC_KEY_free(ecdh_b[i]); } # endif apps_shutdown(); OPENSSL_EXIT(mret); }
['int MAIN(int argc, char **argv)\n{\n unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;\n unsigned char *buf = NULL, *buf2 = NULL;\n int mret = 1;\n long count = 0, save_count = 0;\n int i, j, k;\n# if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)\n long rsa_count;\n# endif\n# ifndef OPENSSL_NO_RSA\n unsigned rsa_num;\n# endif\n unsigned char md[EVP_MAX_MD_SIZE];\n# ifndef OPENSSL_NO_MD2\n unsigned char md2[MD2_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_MDC2\n unsigned char mdc2[MDC2_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_MD4\n unsigned char md4[MD4_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_MD5\n unsigned char md5[MD5_DIGEST_LENGTH];\n unsigned char hmac[MD5_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_SHA\n unsigned char sha[SHA_DIGEST_LENGTH];\n# ifndef OPENSSL_NO_SHA256\n unsigned char sha256[SHA256_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_SHA512\n unsigned char sha512[SHA512_DIGEST_LENGTH];\n# endif\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_RMD160\n unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_RC4\n RC4_KEY rc4_ks;\n# endif\n# ifndef OPENSSL_NO_RC5\n RC5_32_KEY rc5_ks;\n# endif\n# ifndef OPENSSL_NO_RC2\n RC2_KEY rc2_ks;\n# endif\n# ifndef OPENSSL_NO_IDEA\n IDEA_KEY_SCHEDULE idea_ks;\n# endif\n# ifndef OPENSSL_NO_SEED\n SEED_KEY_SCHEDULE seed_ks;\n# endif\n# ifndef OPENSSL_NO_BF\n BF_KEY bf_ks;\n# endif\n# ifndef OPENSSL_NO_CAST\n CAST_KEY cast_ks;\n# endif\n static const unsigned char key16[16] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12\n };\n# ifndef OPENSSL_NO_AES\n static const unsigned char key24[24] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34\n };\n static const unsigned char key32[32] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,\n 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56\n };\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n static const unsigned char ckey24[24] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34\n };\n static const unsigned char ckey32[32] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,\n 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56\n };\n# endif\n# ifndef OPENSSL_NO_AES\n# define MAX_BLOCK_SIZE 128\n# else\n# define MAX_BLOCK_SIZE 64\n# endif\n unsigned char DES_iv[8];\n unsigned char iv[2 * MAX_BLOCK_SIZE / 8];\n# ifndef OPENSSL_NO_DES\n static DES_cblock key =\n { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };\n static DES_cblock key2 =\n { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };\n static DES_cblock key3 =\n { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };\n DES_key_schedule sch;\n DES_key_schedule sch2;\n DES_key_schedule sch3;\n# endif\n# ifndef OPENSSL_NO_AES\n AES_KEY aes_ks1, aes_ks2, aes_ks3;\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;\n# endif\n# define D_MD2 0\n# define D_MDC2 1\n# define D_MD4 2\n# define D_MD5 3\n# define D_HMAC 4\n# define D_SHA1 5\n# define D_RMD160 6\n# define D_RC4 7\n# define D_CBC_DES 8\n# define D_EDE3_DES 9\n# define D_CBC_IDEA 10\n# define D_CBC_SEED 11\n# define D_CBC_RC2 12\n# define D_CBC_RC5 13\n# define D_CBC_BF 14\n# define D_CBC_CAST 15\n# define D_CBC_128_AES 16\n# define D_CBC_192_AES 17\n# define D_CBC_256_AES 18\n# define D_CBC_128_CML 19\n# define D_CBC_192_CML 20\n# define D_CBC_256_CML 21\n# define D_EVP 22\n# define D_SHA256 23\n# define D_SHA512 24\n# define D_WHIRLPOOL 25\n# define D_IGE_128_AES 26\n# define D_IGE_192_AES 27\n# define D_IGE_256_AES 28\n# define D_GHASH 29\n double d = 0.0;\n long c[ALGOR_NUM][SIZE_NUM];\n# ifndef OPENSSL_SYS_WIN32\n# endif\n# define R_DSA_512 0\n# define R_DSA_1024 1\n# define R_DSA_2048 2\n# define R_RSA_512 0\n# define R_RSA_1024 1\n# define R_RSA_2048 2\n# define R_RSA_3072 3\n# define R_RSA_4096 4\n# define R_RSA_7680 5\n# define R_RSA_15360 6\n# define R_EC_P160 0\n# define R_EC_P192 1\n# define R_EC_P224 2\n# define R_EC_P256 3\n# define R_EC_P384 4\n# define R_EC_P521 5\n# define R_EC_K163 6\n# define R_EC_K233 7\n# define R_EC_K283 8\n# define R_EC_K409 9\n# define R_EC_K571 10\n# define R_EC_B163 11\n# define R_EC_B233 12\n# define R_EC_B283 13\n# define R_EC_B409 14\n# define R_EC_B571 15\n# ifndef OPENSSL_NO_RSA\n RSA *rsa_key[RSA_NUM];\n long rsa_c[RSA_NUM][2];\n static unsigned int rsa_bits[RSA_NUM] = {\n 512, 1024, 2048, 3072, 4096, 7680, 15360\n };\n static unsigned char *rsa_data[RSA_NUM] = {\n test512, test1024, test2048, test3072, test4096, test7680, test15360\n };\n static int rsa_data_length[RSA_NUM] = {\n sizeof(test512), sizeof(test1024),\n sizeof(test2048), sizeof(test3072),\n sizeof(test4096), sizeof(test7680),\n sizeof(test15360)\n };\n# endif\n# ifndef OPENSSL_NO_DSA\n DSA *dsa_key[DSA_NUM];\n long dsa_c[DSA_NUM][2];\n static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };\n# endif\n# ifndef OPENSSL_NO_EC\n static unsigned int test_curves[EC_NUM] = {\n NID_secp160r1,\n NID_X9_62_prime192v1,\n NID_secp224r1,\n NID_X9_62_prime256v1,\n NID_secp384r1,\n NID_secp521r1,\n NID_sect163k1,\n NID_sect233k1,\n NID_sect283k1,\n NID_sect409k1,\n NID_sect571k1,\n NID_sect163r2,\n NID_sect233r1,\n NID_sect283r1,\n NID_sect409r1,\n NID_sect571r1\n };\n static const char *test_curves_names[EC_NUM] = {\n "secp160r1",\n "nistp192",\n "nistp224",\n "nistp256",\n "nistp384",\n "nistp521",\n "nistk163",\n "nistk233",\n "nistk283",\n "nistk409",\n "nistk571",\n "nistb163",\n "nistb233",\n "nistb283",\n "nistb409",\n "nistb571"\n };\n static int test_curves_bits[EC_NUM] = {\n 160, 192, 224, 256, 384, 521,\n 163, 233, 283, 409, 571,\n 163, 233, 283, 409, 571\n };\n# endif\n# ifndef OPENSSL_NO_ECDSA\n unsigned char ecdsasig[256];\n unsigned int ecdsasiglen;\n EC_KEY *ecdsa[EC_NUM];\n long ecdsa_c[EC_NUM][2];\n# endif\n# ifndef OPENSSL_NO_ECDH\n EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];\n unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];\n int secret_size_a, secret_size_b;\n int ecdh_checks = 0;\n int secret_idx = 0;\n long ecdh_c[EC_NUM][2];\n# endif\n int rsa_doit[RSA_NUM];\n int dsa_doit[DSA_NUM];\n# ifndef OPENSSL_NO_ECDSA\n int ecdsa_doit[EC_NUM];\n# endif\n# ifndef OPENSSL_NO_ECDH\n int ecdh_doit[EC_NUM];\n# endif\n int doit[ALGOR_NUM];\n int pr_header = 0;\n const EVP_CIPHER *evp_cipher = NULL;\n const EVP_MD *evp_md = NULL;\n int decrypt = 0;\n# ifndef NO_FORK\n int multi = 0;\n# endif\n int multiblock = 0;\n int misalign = MAX_MISALIGNMENT + 1;\n# ifndef TIMES\n usertime = -1;\n# endif\n apps_startup();\n memset(results, 0, sizeof(results));\n# ifndef OPENSSL_NO_DSA\n memset(dsa_key, 0, sizeof(dsa_key));\n# endif\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa[i] = NULL;\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++) {\n ecdh_a[i] = NULL;\n ecdh_b[i] = NULL;\n }\n# endif\n if (bio_err == NULL)\n if ((bio_err = BIO_new(BIO_s_file())) != NULL)\n BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);\n if (!load_config(bio_err, NULL))\n goto end;\n# ifndef OPENSSL_NO_RSA\n memset(rsa_key, 0, sizeof(rsa_key));\n for (i = 0; i < RSA_NUM; i++)\n rsa_key[i] = NULL;\n# endif\n if ((buf_malloc =\n (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {\n BIO_printf(bio_err, "out of memory\\n");\n goto end;\n }\n if ((buf2_malloc =\n (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {\n BIO_printf(bio_err, "out of memory\\n");\n goto end;\n }\n misalign = 0;\n buf = buf_malloc;\n buf2 = buf2_malloc;\n memset(c, 0, sizeof(c));\n memset(DES_iv, 0, sizeof(DES_iv));\n memset(iv, 0, sizeof(iv));\n for (i = 0; i < ALGOR_NUM; i++)\n doit[i] = 0;\n for (i = 0; i < RSA_NUM; i++)\n rsa_doit[i] = 0;\n for (i = 0; i < DSA_NUM; i++)\n dsa_doit[i] = 0;\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 0;\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 0;\n# endif\n j = 0;\n argc--;\n argv++;\n while (argc) {\n if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {\n usertime = 0;\n j--;\n } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no EVP given\\n");\n goto end;\n }\n evp_cipher = EVP_get_cipherbyname(*argv);\n if (!evp_cipher) {\n evp_md = EVP_get_digestbyname(*argv);\n }\n if (!evp_cipher && !evp_md) {\n BIO_printf(bio_err, "%s is an unknown cipher or digest\\n",\n *argv);\n goto end;\n }\n doit[D_EVP] = 1;\n } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {\n decrypt = 1;\n j--;\n }\n# ifndef OPENSSL_NO_ENGINE\n else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no engine given\\n");\n goto end;\n }\n setup_engine(bio_err, *argv, 0);\n j--;\n }\n# endif\n# ifndef NO_FORK\n else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no multi count given\\n");\n goto end;\n }\n multi = atoi(argv[0]);\n if (multi <= 0) {\n BIO_printf(bio_err, "bad multi count\\n");\n goto end;\n }\n j--;\n }\n# endif\n else if (argc > 0 && !strcmp(*argv, "-mr")) {\n mr = 1;\n j--;\n } else if (argc > 0 && !strcmp(*argv, "-mb")) {\n multiblock = 1;\n j--;\n } else if (argc > 0 && !strcmp(*argv, "-misalign")) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no misalignment given\\n");\n goto end;\n }\n misalign = atoi(argv[0]);\n if (misalign < 0 || misalign > MAX_MISALIGNMENT) {\n BIO_printf(bio_err,\n "misalignment is outsize permitted range 0-%d\\n",\n MAX_MISALIGNMENT);\n goto end;\n }\n buf = buf_malloc + misalign;\n buf2 = buf2_malloc + misalign;\n j--;\n } else\n# ifndef OPENSSL_NO_MD2\n if (strcmp(*argv, "md2") == 0)\n doit[D_MD2] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MDC2\n if (strcmp(*argv, "mdc2") == 0)\n doit[D_MDC2] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MD4\n if (strcmp(*argv, "md4") == 0)\n doit[D_MD4] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MD5\n if (strcmp(*argv, "md5") == 0)\n doit[D_MD5] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MD5\n if (strcmp(*argv, "hmac") == 0)\n doit[D_HMAC] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_SHA\n if (strcmp(*argv, "sha1") == 0)\n doit[D_SHA1] = 1;\n else if (strcmp(*argv, "sha") == 0)\n doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;\n else\n# ifndef OPENSSL_NO_SHA256\n if (strcmp(*argv, "sha256") == 0)\n doit[D_SHA256] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_SHA512\n if (strcmp(*argv, "sha512") == 0)\n doit[D_SHA512] = 1;\n else\n# endif\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n if (strcmp(*argv, "whirlpool") == 0)\n doit[D_WHIRLPOOL] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RMD160\n if (strcmp(*argv, "ripemd") == 0)\n doit[D_RMD160] = 1;\n else if (strcmp(*argv, "rmd160") == 0)\n doit[D_RMD160] = 1;\n else if (strcmp(*argv, "ripemd160") == 0)\n doit[D_RMD160] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RC4\n if (strcmp(*argv, "rc4") == 0)\n doit[D_RC4] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_DES\n if (strcmp(*argv, "des-cbc") == 0)\n doit[D_CBC_DES] = 1;\n else if (strcmp(*argv, "des-ede3") == 0)\n doit[D_EDE3_DES] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_AES\n if (strcmp(*argv, "aes-128-cbc") == 0)\n doit[D_CBC_128_AES] = 1;\n else if (strcmp(*argv, "aes-192-cbc") == 0)\n doit[D_CBC_192_AES] = 1;\n else if (strcmp(*argv, "aes-256-cbc") == 0)\n doit[D_CBC_256_AES] = 1;\n else if (strcmp(*argv, "aes-128-ige") == 0)\n doit[D_IGE_128_AES] = 1;\n else if (strcmp(*argv, "aes-192-ige") == 0)\n doit[D_IGE_192_AES] = 1;\n else if (strcmp(*argv, "aes-256-ige") == 0)\n doit[D_IGE_256_AES] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n if (strcmp(*argv, "camellia-128-cbc") == 0)\n doit[D_CBC_128_CML] = 1;\n else if (strcmp(*argv, "camellia-192-cbc") == 0)\n doit[D_CBC_192_CML] = 1;\n else if (strcmp(*argv, "camellia-256-cbc") == 0)\n doit[D_CBC_256_CML] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RSA\n# if 0\n if (strcmp(*argv, "rsaref") == 0) {\n RSA_set_default_openssl_method(RSA_PKCS1_RSAref());\n j--;\n } else\n# endif\n# ifndef RSA_NULL\n if (strcmp(*argv, "openssl") == 0) {\n RSA_set_default_method(RSA_PKCS1_SSLeay());\n j--;\n } else\n# endif\n# endif\n if (strcmp(*argv, "dsa512") == 0)\n dsa_doit[R_DSA_512] = 2;\n else if (strcmp(*argv, "dsa1024") == 0)\n dsa_doit[R_DSA_1024] = 2;\n else if (strcmp(*argv, "dsa2048") == 0)\n dsa_doit[R_DSA_2048] = 2;\n else if (strcmp(*argv, "rsa512") == 0)\n rsa_doit[R_RSA_512] = 2;\n else if (strcmp(*argv, "rsa1024") == 0)\n rsa_doit[R_RSA_1024] = 2;\n else if (strcmp(*argv, "rsa2048") == 0)\n rsa_doit[R_RSA_2048] = 2;\n else if (strcmp(*argv, "rsa3072") == 0)\n rsa_doit[R_RSA_3072] = 2;\n else if (strcmp(*argv, "rsa4096") == 0)\n rsa_doit[R_RSA_4096] = 2;\n else if (strcmp(*argv, "rsa7680") == 0)\n rsa_doit[R_RSA_7680] = 2;\n else if (strcmp(*argv, "rsa15360") == 0)\n rsa_doit[R_RSA_15360] = 2;\n else\n# ifndef OPENSSL_NO_RC2\n if (strcmp(*argv, "rc2-cbc") == 0)\n doit[D_CBC_RC2] = 1;\n else if (strcmp(*argv, "rc2") == 0)\n doit[D_CBC_RC2] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RC5\n if (strcmp(*argv, "rc5-cbc") == 0)\n doit[D_CBC_RC5] = 1;\n else if (strcmp(*argv, "rc5") == 0)\n doit[D_CBC_RC5] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_IDEA\n if (strcmp(*argv, "idea-cbc") == 0)\n doit[D_CBC_IDEA] = 1;\n else if (strcmp(*argv, "idea") == 0)\n doit[D_CBC_IDEA] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_SEED\n if (strcmp(*argv, "seed-cbc") == 0)\n doit[D_CBC_SEED] = 1;\n else if (strcmp(*argv, "seed") == 0)\n doit[D_CBC_SEED] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_BF\n if (strcmp(*argv, "bf-cbc") == 0)\n doit[D_CBC_BF] = 1;\n else if (strcmp(*argv, "blowfish") == 0)\n doit[D_CBC_BF] = 1;\n else if (strcmp(*argv, "bf") == 0)\n doit[D_CBC_BF] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_CAST\n if (strcmp(*argv, "cast-cbc") == 0)\n doit[D_CBC_CAST] = 1;\n else if (strcmp(*argv, "cast") == 0)\n doit[D_CBC_CAST] = 1;\n else if (strcmp(*argv, "cast5") == 0)\n doit[D_CBC_CAST] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_DES\n if (strcmp(*argv, "des") == 0) {\n doit[D_CBC_DES] = 1;\n doit[D_EDE3_DES] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_AES\n if (strcmp(*argv, "aes") == 0) {\n doit[D_CBC_128_AES] = 1;\n doit[D_CBC_192_AES] = 1;\n doit[D_CBC_256_AES] = 1;\n } else if (strcmp(*argv, "ghash") == 0) {\n doit[D_GHASH] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n if (strcmp(*argv, "camellia") == 0) {\n doit[D_CBC_128_CML] = 1;\n doit[D_CBC_192_CML] = 1;\n doit[D_CBC_256_CML] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_RSA\n if (strcmp(*argv, "rsa") == 0) {\n rsa_doit[R_RSA_512] = 1;\n rsa_doit[R_RSA_1024] = 1;\n rsa_doit[R_RSA_2048] = 1;\n rsa_doit[R_RSA_3072] = 1;\n rsa_doit[R_RSA_4096] = 1;\n rsa_doit[R_RSA_7680] = 1;\n rsa_doit[R_RSA_15360] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_DSA\n if (strcmp(*argv, "dsa") == 0) {\n dsa_doit[R_DSA_512] = 1;\n dsa_doit[R_DSA_1024] = 1;\n dsa_doit[R_DSA_2048] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_ECDSA\n if (strcmp(*argv, "ecdsap160") == 0)\n ecdsa_doit[R_EC_P160] = 2;\n else if (strcmp(*argv, "ecdsap192") == 0)\n ecdsa_doit[R_EC_P192] = 2;\n else if (strcmp(*argv, "ecdsap224") == 0)\n ecdsa_doit[R_EC_P224] = 2;\n else if (strcmp(*argv, "ecdsap256") == 0)\n ecdsa_doit[R_EC_P256] = 2;\n else if (strcmp(*argv, "ecdsap384") == 0)\n ecdsa_doit[R_EC_P384] = 2;\n else if (strcmp(*argv, "ecdsap521") == 0)\n ecdsa_doit[R_EC_P521] = 2;\n else if (strcmp(*argv, "ecdsak163") == 0)\n ecdsa_doit[R_EC_K163] = 2;\n else if (strcmp(*argv, "ecdsak233") == 0)\n ecdsa_doit[R_EC_K233] = 2;\n else if (strcmp(*argv, "ecdsak283") == 0)\n ecdsa_doit[R_EC_K283] = 2;\n else if (strcmp(*argv, "ecdsak409") == 0)\n ecdsa_doit[R_EC_K409] = 2;\n else if (strcmp(*argv, "ecdsak571") == 0)\n ecdsa_doit[R_EC_K571] = 2;\n else if (strcmp(*argv, "ecdsab163") == 0)\n ecdsa_doit[R_EC_B163] = 2;\n else if (strcmp(*argv, "ecdsab233") == 0)\n ecdsa_doit[R_EC_B233] = 2;\n else if (strcmp(*argv, "ecdsab283") == 0)\n ecdsa_doit[R_EC_B283] = 2;\n else if (strcmp(*argv, "ecdsab409") == 0)\n ecdsa_doit[R_EC_B409] = 2;\n else if (strcmp(*argv, "ecdsab571") == 0)\n ecdsa_doit[R_EC_B571] = 2;\n else if (strcmp(*argv, "ecdsa") == 0) {\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_ECDH\n if (strcmp(*argv, "ecdhp160") == 0)\n ecdh_doit[R_EC_P160] = 2;\n else if (strcmp(*argv, "ecdhp192") == 0)\n ecdh_doit[R_EC_P192] = 2;\n else if (strcmp(*argv, "ecdhp224") == 0)\n ecdh_doit[R_EC_P224] = 2;\n else if (strcmp(*argv, "ecdhp256") == 0)\n ecdh_doit[R_EC_P256] = 2;\n else if (strcmp(*argv, "ecdhp384") == 0)\n ecdh_doit[R_EC_P384] = 2;\n else if (strcmp(*argv, "ecdhp521") == 0)\n ecdh_doit[R_EC_P521] = 2;\n else if (strcmp(*argv, "ecdhk163") == 0)\n ecdh_doit[R_EC_K163] = 2;\n else if (strcmp(*argv, "ecdhk233") == 0)\n ecdh_doit[R_EC_K233] = 2;\n else if (strcmp(*argv, "ecdhk283") == 0)\n ecdh_doit[R_EC_K283] = 2;\n else if (strcmp(*argv, "ecdhk409") == 0)\n ecdh_doit[R_EC_K409] = 2;\n else if (strcmp(*argv, "ecdhk571") == 0)\n ecdh_doit[R_EC_K571] = 2;\n else if (strcmp(*argv, "ecdhb163") == 0)\n ecdh_doit[R_EC_B163] = 2;\n else if (strcmp(*argv, "ecdhb233") == 0)\n ecdh_doit[R_EC_B233] = 2;\n else if (strcmp(*argv, "ecdhb283") == 0)\n ecdh_doit[R_EC_B283] = 2;\n else if (strcmp(*argv, "ecdhb409") == 0)\n ecdh_doit[R_EC_B409] = 2;\n else if (strcmp(*argv, "ecdhb571") == 0)\n ecdh_doit[R_EC_B571] = 2;\n else if (strcmp(*argv, "ecdh") == 0) {\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 1;\n } else\n# endif\n {\n BIO_printf(bio_err, "Error: bad option or value\\n");\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err, "Available values:\\n");\n# ifndef OPENSSL_NO_MD2\n BIO_printf(bio_err, "md2 ");\n# endif\n# ifndef OPENSSL_NO_MDC2\n BIO_printf(bio_err, "mdc2 ");\n# endif\n# ifndef OPENSSL_NO_MD4\n BIO_printf(bio_err, "md4 ");\n# endif\n# ifndef OPENSSL_NO_MD5\n BIO_printf(bio_err, "md5 ");\n# ifndef OPENSSL_NO_HMAC\n BIO_printf(bio_err, "hmac ");\n# endif\n# endif\n# ifndef OPENSSL_NO_SHA1\n BIO_printf(bio_err, "sha1 ");\n# endif\n# ifndef OPENSSL_NO_SHA256\n BIO_printf(bio_err, "sha256 ");\n# endif\n# ifndef OPENSSL_NO_SHA512\n BIO_printf(bio_err, "sha512 ");\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n BIO_printf(bio_err, "whirlpool");\n# endif\n# ifndef OPENSSL_NO_RMD160\n BIO_printf(bio_err, "rmd160");\n# endif\n# if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \\\n !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \\\n !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \\\n !defined(OPENSSL_NO_WHIRLPOOL)\n BIO_printf(bio_err, "\\n");\n# endif\n# ifndef OPENSSL_NO_IDEA\n BIO_printf(bio_err, "idea-cbc ");\n# endif\n# ifndef OPENSSL_NO_SEED\n BIO_printf(bio_err, "seed-cbc ");\n# endif\n# ifndef OPENSSL_NO_RC2\n BIO_printf(bio_err, "rc2-cbc ");\n# endif\n# ifndef OPENSSL_NO_RC5\n BIO_printf(bio_err, "rc5-cbc ");\n# endif\n# ifndef OPENSSL_NO_BF\n BIO_printf(bio_err, "bf-cbc");\n# endif\n# if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)\n BIO_printf(bio_err, "\\n");\n# endif\n# ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "des-cbc des-ede3 ");\n# endif\n# ifndef OPENSSL_NO_AES\n BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");\n BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err,\n "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");\n# endif\n# ifndef OPENSSL_NO_RC4\n BIO_printf(bio_err, "rc4");\n# endif\n BIO_printf(bio_err, "\\n");\n# ifndef OPENSSL_NO_RSA\n BIO_printf(bio_err,\n "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\\n");\n BIO_printf(bio_err, "rsa7680 rsa15360\\n");\n# endif\n# ifndef OPENSSL_NO_DSA\n BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\\n");\n# endif\n# ifndef OPENSSL_NO_ECDSA\n BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "\n "ecdsap256 ecdsap384 ecdsap521\\n");\n BIO_printf(bio_err,\n "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\\n");\n BIO_printf(bio_err,\n "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\\n");\n BIO_printf(bio_err, "ecdsa\\n");\n# endif\n# ifndef OPENSSL_NO_ECDH\n BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "\n "ecdhp256 ecdhp384 ecdhp521\\n");\n BIO_printf(bio_err,\n "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\\n");\n BIO_printf(bio_err,\n "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\\n");\n BIO_printf(bio_err, "ecdh\\n");\n# endif\n# ifndef OPENSSL_NO_IDEA\n BIO_printf(bio_err, "idea ");\n# endif\n# ifndef OPENSSL_NO_SEED\n BIO_printf(bio_err, "seed ");\n# endif\n# ifndef OPENSSL_NO_RC2\n BIO_printf(bio_err, "rc2 ");\n# endif\n# ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "des ");\n# endif\n# ifndef OPENSSL_NO_AES\n BIO_printf(bio_err, "aes ");\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n BIO_printf(bio_err, "camellia ");\n# endif\n# ifndef OPENSSL_NO_RSA\n BIO_printf(bio_err, "rsa ");\n# endif\n# ifndef OPENSSL_NO_BF\n BIO_printf(bio_err, "blowfish");\n# endif\n# if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \\\n !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \\\n !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \\\n !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)\n BIO_printf(bio_err, "\\n");\n# endif\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err, "Available options:\\n");\n# if defined(TIMES) || defined(USE_TOD)\n BIO_printf(bio_err, "-elapsed "\n "measure time in real time instead of CPU user time.\\n");\n# endif\n# ifndef OPENSSL_NO_ENGINE\n BIO_printf(bio_err,\n "-engine e "\n "use engine e, possibly a hardware device.\\n");\n# endif\n BIO_printf(bio_err, "-evp e " "use EVP e.\\n");\n BIO_printf(bio_err,\n "-decrypt "\n "time decryption instead of encryption (only EVP).\\n");\n BIO_printf(bio_err,\n "-mr "\n "produce machine readable output.\\n");\n BIO_printf(bio_err,\n "-mb "\n "perform multi-block benchmark (for specific ciphers)\\n");\n BIO_printf(bio_err,\n "-misalign n "\n "perform benchmark with misaligned data\\n");\n# ifndef NO_FORK\n BIO_printf(bio_err,\n "-multi n " "run n benchmarks in parallel.\\n");\n# endif\n goto end;\n }\n argc--;\n argv++;\n j++;\n }\n# ifndef NO_FORK\n if (multi && do_multi(multi))\n goto show_res;\n# endif\n if (j == 0) {\n for (i = 0; i < ALGOR_NUM; i++) {\n if (i != D_EVP)\n doit[i] = 1;\n }\n for (i = 0; i < RSA_NUM; i++)\n rsa_doit[i] = 1;\n for (i = 0; i < DSA_NUM; i++)\n dsa_doit[i] = 1;\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 1;\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 1;\n# endif\n }\n for (i = 0; i < ALGOR_NUM; i++)\n if (doit[i])\n pr_header++;\n if (usertime == 0 && !mr)\n BIO_printf(bio_err,\n "You have chosen to measure elapsed time "\n "instead of user CPU time.\\n");\n# ifndef OPENSSL_NO_RSA\n for (i = 0; i < RSA_NUM; i++) {\n const unsigned char *p;\n p = rsa_data[i];\n rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);\n if (rsa_key[i] == NULL) {\n BIO_printf(bio_err, "internal error loading RSA key number %d\\n",\n i);\n goto end;\n }\n# if 0\n else {\n BIO_printf(bio_err,\n mr ? "+RK:%d:"\n : "Loaded RSA key, %d bit modulus and e= 0x",\n BN_num_bits(rsa_key[i]->n));\n BN_print(bio_err, rsa_key[i]->e);\n BIO_printf(bio_err, "\\n");\n }\n# endif\n }\n# endif\n# ifndef OPENSSL_NO_DSA\n dsa_key[0] = get_dsa512();\n dsa_key[1] = get_dsa1024();\n dsa_key[2] = get_dsa2048();\n# endif\n# ifndef OPENSSL_NO_DES\n DES_set_key_unchecked(&key, &sch);\n DES_set_key_unchecked(&key2, &sch2);\n DES_set_key_unchecked(&key3, &sch3);\n# endif\n# ifndef OPENSSL_NO_AES\n AES_set_encrypt_key(key16, 128, &aes_ks1);\n AES_set_encrypt_key(key24, 192, &aes_ks2);\n AES_set_encrypt_key(key32, 256, &aes_ks3);\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n Camellia_set_key(key16, 128, &camellia_ks1);\n Camellia_set_key(ckey24, 192, &camellia_ks2);\n Camellia_set_key(ckey32, 256, &camellia_ks3);\n# endif\n# ifndef OPENSSL_NO_IDEA\n idea_set_encrypt_key(key16, &idea_ks);\n# endif\n# ifndef OPENSSL_NO_SEED\n SEED_set_key(key16, &seed_ks);\n# endif\n# ifndef OPENSSL_NO_RC4\n RC4_set_key(&rc4_ks, 16, key16);\n# endif\n# ifndef OPENSSL_NO_RC2\n RC2_set_key(&rc2_ks, 16, key16, 128);\n# endif\n# ifndef OPENSSL_NO_RC5\n RC5_32_set_key(&rc5_ks, 16, key16, 12);\n# endif\n# ifndef OPENSSL_NO_BF\n BF_set_key(&bf_ks, 16, key16);\n# endif\n# ifndef OPENSSL_NO_CAST\n CAST_set_key(&cast_ks, 16, key16);\n# endif\n# ifndef OPENSSL_NO_RSA\n memset(rsa_c, 0, sizeof(rsa_c));\n# endif\n# ifndef SIGALRM\n# ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "First we calculate the approximate speed ...\\n");\n count = 10;\n do {\n long it;\n count *= 2;\n Time_F(START);\n for (it = count; it; it--)\n DES_ecb_encrypt((DES_cblock *)buf,\n (DES_cblock *)buf, &sch, DES_ENCRYPT);\n d = Time_F(STOP);\n } while (d < 3);\n save_count = count;\n c[D_MD2][0] = count / 10;\n c[D_MDC2][0] = count / 10;\n c[D_MD4][0] = count;\n c[D_MD5][0] = count;\n c[D_HMAC][0] = count;\n c[D_SHA1][0] = count;\n c[D_RMD160][0] = count;\n c[D_RC4][0] = count * 5;\n c[D_CBC_DES][0] = count;\n c[D_EDE3_DES][0] = count / 3;\n c[D_CBC_IDEA][0] = count;\n c[D_CBC_SEED][0] = count;\n c[D_CBC_RC2][0] = count;\n c[D_CBC_RC5][0] = count;\n c[D_CBC_BF][0] = count;\n c[D_CBC_CAST][0] = count;\n c[D_CBC_128_AES][0] = count;\n c[D_CBC_192_AES][0] = count;\n c[D_CBC_256_AES][0] = count;\n c[D_CBC_128_CML][0] = count;\n c[D_CBC_192_CML][0] = count;\n c[D_CBC_256_CML][0] = count;\n c[D_SHA256][0] = count;\n c[D_SHA512][0] = count;\n c[D_WHIRLPOOL][0] = count;\n c[D_IGE_128_AES][0] = count;\n c[D_IGE_192_AES][0] = count;\n c[D_IGE_256_AES][0] = count;\n c[D_GHASH][0] = count;\n for (i = 1; i < SIZE_NUM; i++) {\n long l0, l1;\n l0 = (long)lengths[0];\n l1 = (long)lengths[i];\n c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;\n c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;\n c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;\n c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;\n c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;\n c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;\n c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;\n c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;\n c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;\n c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;\n l0 = (long)lengths[i - 1];\n c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;\n c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;\n c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;\n c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;\n c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;\n c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;\n c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;\n c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;\n c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;\n c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;\n c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;\n c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;\n c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;\n c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;\n c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;\n c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;\n c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;\n c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;\n }\n# ifndef OPENSSL_NO_RSA\n rsa_c[R_RSA_512][0] = count / 2000;\n rsa_c[R_RSA_512][1] = count / 400;\n for (i = 1; i < RSA_NUM; i++) {\n rsa_c[i][0] = rsa_c[i - 1][0] / 8;\n rsa_c[i][1] = rsa_c[i - 1][1] / 4;\n if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))\n rsa_doit[i] = 0;\n else {\n if (rsa_c[i][0] == 0) {\n rsa_c[i][0] = 1;\n rsa_c[i][1] = 20;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_DSA\n dsa_c[R_DSA_512][0] = count / 1000;\n dsa_c[R_DSA_512][1] = count / 1000 / 2;\n for (i = 1; i < DSA_NUM; i++) {\n dsa_c[i][0] = dsa_c[i - 1][0] / 4;\n dsa_c[i][1] = dsa_c[i - 1][1] / 4;\n if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))\n dsa_doit[i] = 0;\n else {\n if (dsa_c[i] == 0) {\n dsa_c[i][0] = 1;\n dsa_c[i][1] = 1;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_ECDSA\n ecdsa_c[R_EC_P160][0] = count / 1000;\n ecdsa_c[R_EC_P160][1] = count / 1000 / 2;\n for (i = R_EC_P192; i <= R_EC_P521; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n ecdsa_c[R_EC_K163][0] = count / 1000;\n ecdsa_c[R_EC_K163][1] = count / 1000 / 2;\n for (i = R_EC_K233; i <= R_EC_K571; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n ecdsa_c[R_EC_B163][0] = count / 1000;\n ecdsa_c[R_EC_B163][1] = count / 1000 / 2;\n for (i = R_EC_B233; i <= R_EC_B571; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_ECDH\n ecdh_c[R_EC_P160][0] = count / 1000;\n ecdh_c[R_EC_P160][1] = count / 1000;\n for (i = R_EC_P192; i <= R_EC_P521; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n ecdh_c[R_EC_K163][0] = count / 1000;\n ecdh_c[R_EC_K163][1] = count / 1000;\n for (i = R_EC_K233; i <= R_EC_K571; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n ecdh_c[R_EC_B163][0] = count / 1000;\n ecdh_c[R_EC_B163][1] = count / 1000;\n for (i = R_EC_B233; i <= R_EC_B571; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n# endif\n# define COND(d) (count < (d))\n# define COUNT(d) (d)\n# else\n# error "You cannot disable DES on systems without SIGALRM."\n# endif\n# else\n# define COND(c) (run && count<0x7fffffff)\n# define COUNT(d) (count)\n# ifndef _WIN32\n signal(SIGALRM, sig_done);\n# endif\n# endif\n# ifndef OPENSSL_NO_MD2\n if (doit[D_MD2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD2], c[D_MD2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD2][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,\n EVP_md2(), NULL);\n d = Time_F(STOP);\n print_result(D_MD2, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_MDC2\n if (doit[D_MDC2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,\n EVP_mdc2(), NULL);\n d = Time_F(STOP);\n print_result(D_MDC2, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_MD4\n if (doit[D_MD4]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD4], c[D_MD4][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD4][j]); count++)\n EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),\n NULL, EVP_md4(), NULL);\n d = Time_F(STOP);\n print_result(D_MD4, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_MD5\n if (doit[D_MD5]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD5], c[D_MD5][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD5][j]); count++)\n MD5(buf, lengths[j], md5);\n d = Time_F(STOP);\n print_result(D_MD5, j, count, d);\n }\n }\n# endif\n# if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)\n if (doit[D_HMAC]) {\n HMAC_CTX hctx;\n HMAC_CTX_init(&hctx);\n HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",\n 16, EVP_md5(), NULL);\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {\n HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);\n HMAC_Update(&hctx, buf, lengths[j]);\n HMAC_Final(&hctx, &(hmac[0]), NULL);\n }\n d = Time_F(STOP);\n print_result(D_HMAC, j, count, d);\n }\n HMAC_CTX_cleanup(&hctx);\n }\n# endif\n# ifndef OPENSSL_NO_SHA\n if (doit[D_SHA1]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)\n# if 0\n EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,\n EVP_sha1(), NULL);\n# else\n SHA1(buf, lengths[j], sha);\n# endif\n d = Time_F(STOP);\n print_result(D_SHA1, j, count, d);\n }\n }\n# ifndef OPENSSL_NO_SHA256\n if (doit[D_SHA256]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)\n SHA256(buf, lengths[j], sha256);\n d = Time_F(STOP);\n print_result(D_SHA256, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_SHA512\n if (doit[D_SHA512]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)\n SHA512(buf, lengths[j], sha512);\n d = Time_F(STOP);\n print_result(D_SHA512, j, count, d);\n }\n }\n# endif\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n if (doit[D_WHIRLPOOL]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)\n WHIRLPOOL(buf, lengths[j], whirlpool);\n d = Time_F(STOP);\n print_result(D_WHIRLPOOL, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RMD160\n if (doit[D_RMD160]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,\n EVP_ripemd160(), NULL);\n d = Time_F(STOP);\n print_result(D_RMD160, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RC4\n if (doit[D_RC4]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_RC4], c[D_RC4][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_RC4][j]); count++)\n RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);\n d = Time_F(STOP);\n print_result(D_RC4, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_DES\n if (doit[D_CBC_DES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)\n DES_ncbc_encrypt(buf, buf, lengths[j], &sch,\n &DES_iv, DES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_DES, j, count, d);\n }\n }\n if (doit[D_EDE3_DES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)\n DES_ede3_cbc_encrypt(buf, buf, lengths[j],\n &sch, &sch2, &sch3,\n &DES_iv, DES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_EDE3_DES, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_AES\n if (doit[D_CBC_128_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks1,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_128_AES, j, count, d);\n }\n }\n if (doit[D_CBC_192_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks2,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_192_AES, j, count, d);\n }\n }\n if (doit[D_CBC_256_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks3,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_256_AES, j, count, d);\n }\n }\n if (doit[D_IGE_128_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks1,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_128_AES, j, count, d);\n }\n }\n if (doit[D_IGE_192_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks2,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_192_AES, j, count, d);\n }\n }\n if (doit[D_IGE_256_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks3,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_256_AES, j, count, d);\n }\n }\n if (doit[D_GHASH]) {\n GCM128_CONTEXT *ctx =\n CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);\n CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)\n CRYPTO_gcm128_aad(ctx, buf, lengths[j]);\n d = Time_F(STOP);\n print_result(D_GHASH, j, count, d);\n }\n CRYPTO_gcm128_release(ctx);\n }\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n if (doit[D_CBC_128_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks1,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_128_CML, j, count, d);\n }\n }\n if (doit[D_CBC_192_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks2,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_192_CML, j, count, d);\n }\n }\n if (doit[D_CBC_256_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks3,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_256_CML, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_IDEA\n if (doit[D_CBC_IDEA]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)\n idea_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &idea_ks,\n iv, IDEA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_IDEA, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_SEED\n if (doit[D_CBC_SEED]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)\n SEED_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &seed_ks, iv, 1);\n d = Time_F(STOP);\n print_result(D_CBC_SEED, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RC2\n if (doit[D_CBC_RC2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)\n RC2_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &rc2_ks,\n iv, RC2_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_RC2, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RC5\n if (doit[D_CBC_RC5]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)\n RC5_32_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &rc5_ks,\n iv, RC5_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_RC5, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_BF\n if (doit[D_CBC_BF]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)\n BF_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &bf_ks,\n iv, BF_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_BF, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_CAST\n if (doit[D_CBC_CAST]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)\n CAST_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &cast_ks,\n iv, CAST_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_CAST, j, count, d);\n }\n }\n# endif\n if (doit[D_EVP]) {\n# ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK\n if (multiblock && evp_cipher) {\n if (!\n (EVP_CIPHER_flags(evp_cipher) &\n EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {\n fprintf(stderr, "%s is not multi-block capable\\n",\n OBJ_nid2ln(evp_cipher->nid));\n goto end;\n }\n multiblock_speed(evp_cipher);\n mret = 0;\n goto end;\n }\n# endif\n for (j = 0; j < SIZE_NUM; j++) {\n if (evp_cipher) {\n EVP_CIPHER_CTX ctx;\n int outl;\n names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);\n print_message(names[D_EVP], save_count, lengths[j]);\n EVP_CIPHER_CTX_init(&ctx);\n if (decrypt)\n EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);\n else\n EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);\n EVP_CIPHER_CTX_set_padding(&ctx, 0);\n Time_F(START);\n if (decrypt)\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]);\n count++)\n EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);\n else\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]);\n count++)\n EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);\n if (decrypt)\n EVP_DecryptFinal_ex(&ctx, buf, &outl);\n else\n EVP_EncryptFinal_ex(&ctx, buf, &outl);\n d = Time_F(STOP);\n EVP_CIPHER_CTX_cleanup(&ctx);\n }\n if (evp_md) {\n names[D_EVP] = OBJ_nid2ln(evp_md->type);\n print_message(names[D_EVP], save_count, lengths[j]);\n Time_F(START);\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]); count++)\n EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);\n d = Time_F(STOP);\n }\n print_result(D_EVP, j, count, d);\n }\n }\n# ifndef OPENSSL_SYS_WIN32\n# endif\n RAND_pseudo_bytes(buf, 36);\n# ifndef OPENSSL_NO_RSA\n for (j = 0; j < RSA_NUM; j++) {\n int ret;\n if (!rsa_doit[j])\n continue;\n ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "RSA sign failure. No RSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("private", "rsa",\n rsa_c[j][0], rsa_bits[j], RSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {\n ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,\n &rsa_num, rsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "RSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R1:%ld:%d:%.2f\\n"\n : "%ld %d bit private RSA\'s in %.2fs\\n",\n count, rsa_bits[j], d);\n rsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n# if 1\n ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err,\n "RSA verify failure. No RSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_doit[j] = 0;\n } else {\n pkey_print_message("public", "rsa",\n rsa_c[j][1], rsa_bits[j], RSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {\n ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,\n rsa_num, rsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err, "RSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R2:%ld:%d:%.2f\\n"\n : "%ld %d bit public RSA\'s in %.2fs\\n",\n count, rsa_bits[j], d);\n rsa_results[j][1] = d / (double)count;\n }\n# endif\n if (rsa_count <= 1) {\n for (j++; j < RSA_NUM; j++)\n rsa_doit[j] = 0;\n }\n }\n# endif\n RAND_pseudo_bytes(buf, 20);\n# ifndef OPENSSL_NO_DSA\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < DSA_NUM; j++) {\n unsigned int kk;\n int ret;\n if (!dsa_doit[j])\n continue;\n ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "DSA sign failure. No DSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("sign", "dsa",\n dsa_c[j][0], dsa_bits[j], DSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {\n ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "DSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R3:%ld:%d:%.2f\\n"\n : "%ld %d bit DSA signs in %.2fs\\n",\n count, dsa_bits[j], d);\n dsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err,\n "DSA verify failure. No DSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n dsa_doit[j] = 0;\n } else {\n pkey_print_message("verify", "dsa",\n dsa_c[j][1], dsa_bits[j], DSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {\n ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err, "DSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R4:%ld:%d:%.2f\\n"\n : "%ld %d bit DSA verify in %.2fs\\n",\n count, dsa_bits[j], d);\n dsa_results[j][1] = d / (double)count;\n }\n if (rsa_count <= 1) {\n for (j++; j < DSA_NUM; j++)\n dsa_doit[j] = 0;\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n# endif\n# ifndef OPENSSL_NO_ECDSA\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < EC_NUM; j++) {\n int ret;\n if (!ecdsa_doit[j])\n continue;\n ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n if (ecdsa[j] == NULL) {\n BIO_printf(bio_err, "ECDSA failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n# if 1\n EC_KEY_precompute_mult(ecdsa[j], NULL);\n# endif\n EC_KEY_generate_key(ecdsa[j]);\n ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "ECDSA sign failure. No ECDSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("sign", "ecdsa",\n ecdsa_c[j][0],\n test_curves_bits[j], ECDSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {\n ret = ECDSA_sign(0, buf, 20,\n ecdsasig, &ecdsasiglen, ecdsa[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "ECDSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R5:%ld:%d:%.2f\\n" :\n "%ld %d bit ECDSA signs in %.2fs \\n",\n count, test_curves_bits[j], d);\n ecdsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);\n if (ret != 1) {\n BIO_printf(bio_err,\n "ECDSA verify failure. No ECDSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n ecdsa_doit[j] = 0;\n } else {\n pkey_print_message("verify", "ecdsa",\n ecdsa_c[j][1],\n test_curves_bits[j], ECDSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {\n ret =\n ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,\n ecdsa[j]);\n if (ret != 1) {\n BIO_printf(bio_err, "ECDSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R6:%ld:%d:%.2f\\n"\n : "%ld %d bit ECDSA verify in %.2fs\\n",\n count, test_curves_bits[j], d);\n ecdsa_results[j][1] = d / (double)count;\n }\n if (rsa_count <= 1) {\n for (j++; j < EC_NUM; j++)\n ecdsa_doit[j] = 0;\n }\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n# endif\n# ifndef OPENSSL_NO_ECDH\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < EC_NUM; j++) {\n if (!ecdh_doit[j])\n continue;\n ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {\n BIO_printf(bio_err, "ECDH failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n if (!EC_KEY_generate_key(ecdh_a[j]) ||\n !EC_KEY_generate_key(ecdh_b[j])) {\n BIO_printf(bio_err, "ECDH key generation failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n int field_size, outlen;\n void *(*kdf) (const void *in, size_t inlen, void *out,\n size_t *xoutlen);\n field_size =\n EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));\n if (field_size <= 24 * 8) {\n outlen = KDF1_SHA1_len;\n kdf = KDF1_SHA1;\n } else {\n outlen = (field_size + 7) / 8;\n kdf = NULL;\n }\n secret_size_a =\n ECDH_compute_key(secret_a, outlen,\n EC_KEY_get0_public_key(ecdh_b[j]),\n ecdh_a[j], kdf);\n secret_size_b =\n ECDH_compute_key(secret_b, outlen,\n EC_KEY_get0_public_key(ecdh_a[j]),\n ecdh_b[j], kdf);\n if (secret_size_a != secret_size_b)\n ecdh_checks = 0;\n else\n ecdh_checks = 1;\n for (secret_idx = 0; (secret_idx < secret_size_a)\n && (ecdh_checks == 1); secret_idx++) {\n if (secret_a[secret_idx] != secret_b[secret_idx])\n ecdh_checks = 0;\n }\n if (ecdh_checks == 0) {\n BIO_printf(bio_err, "ECDH computations don\'t match.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n }\n pkey_print_message("", "ecdh",\n ecdh_c[j][0],\n test_curves_bits[j], ECDH_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {\n ECDH_compute_key(secret_a, outlen,\n EC_KEY_get0_public_key(ecdh_b[j]),\n ecdh_a[j], kdf);\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R7:%ld:%d:%.2f\\n" :\n "%ld %d-bit ECDH ops in %.2fs\\n", count,\n test_curves_bits[j], d);\n ecdh_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n }\n if (rsa_count <= 1) {\n for (j++; j < EC_NUM; j++)\n ecdh_doit[j] = 0;\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n# endif\n# ifndef NO_FORK\n show_res:\n# endif\n if (!mr) {\n fprintf(stdout, "%s\\n", SSLeay_version(SSLEAY_VERSION));\n fprintf(stdout, "%s\\n", SSLeay_version(SSLEAY_BUILT_ON));\n printf("options:");\n printf("%s ", BN_options());\n# ifndef OPENSSL_NO_MD2\n printf("%s ", MD2_options());\n# endif\n# ifndef OPENSSL_NO_RC4\n printf("%s ", RC4_options());\n# endif\n# ifndef OPENSSL_NO_DES\n printf("%s ", DES_options());\n# endif\n# ifndef OPENSSL_NO_AES\n printf("%s ", AES_options());\n# endif\n# ifndef OPENSSL_NO_IDEA\n printf("%s ", idea_options());\n# endif\n# ifndef OPENSSL_NO_BF\n printf("%s ", BF_options());\n# endif\n fprintf(stdout, "\\n%s\\n", SSLeay_version(SSLEAY_CFLAGS));\n }\n if (pr_header) {\n if (mr)\n fprintf(stdout, "+H");\n else {\n fprintf(stdout,\n "The \'numbers\' are in 1000s of bytes per second processed.\\n");\n fprintf(stdout, "type ");\n }\n for (j = 0; j < SIZE_NUM; j++)\n fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);\n fprintf(stdout, "\\n");\n }\n for (k = 0; k < ALGOR_NUM; k++) {\n if (!doit[k])\n continue;\n if (mr)\n fprintf(stdout, "+F:%d:%s", k, names[k]);\n else\n fprintf(stdout, "%-13s", names[k]);\n for (j = 0; j < SIZE_NUM; j++) {\n if (results[k][j] > 10000 && !mr)\n fprintf(stdout, " %11.2fk", results[k][j] / 1e3);\n else\n fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);\n }\n fprintf(stdout, "\\n");\n }\n# ifndef OPENSSL_NO_RSA\n j = 1;\n for (k = 0; k < RSA_NUM; k++) {\n if (!rsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%18ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F2:%u:%u:%f:%f\\n",\n k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);\n else\n fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n rsa_bits[k], rsa_results[k][0], rsa_results[k][1],\n 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);\n }\n# endif\n# ifndef OPENSSL_NO_DSA\n j = 1;\n for (k = 0; k < DSA_NUM; k++) {\n if (!dsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%18ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F3:%u:%u:%f:%f\\n",\n k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);\n else\n fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n dsa_bits[k], dsa_results[k][0], dsa_results[k][1],\n 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);\n }\n# endif\n# ifndef OPENSSL_NO_ECDSA\n j = 1;\n for (k = 0; k < EC_NUM; k++) {\n if (!ecdsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%30ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F4:%u:%u:%f:%f\\n",\n k, test_curves_bits[k],\n ecdsa_results[k][0], ecdsa_results[k][1]);\n else\n fprintf(stdout,\n "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\\n",\n test_curves_bits[k],\n test_curves_names[k],\n ecdsa_results[k][0], ecdsa_results[k][1],\n 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);\n }\n# endif\n# ifndef OPENSSL_NO_ECDH\n j = 1;\n for (k = 0; k < EC_NUM; k++) {\n if (!ecdh_doit[k])\n continue;\n if (j && !mr) {\n printf("%30sop op/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F5:%u:%u:%f:%f\\n",\n k, test_curves_bits[k],\n ecdh_results[k][0], 1.0 / ecdh_results[k][0]);\n else\n fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\\n",\n test_curves_bits[k],\n test_curves_names[k],\n ecdh_results[k][0], 1.0 / ecdh_results[k][0]);\n }\n# endif\n mret = 0;\n end:\n ERR_print_errors(bio_err);\n if (buf_malloc != NULL)\n OPENSSL_free(buf_malloc);\n if (buf2_malloc != NULL)\n OPENSSL_free(buf2_malloc);\n# ifndef OPENSSL_NO_RSA\n for (i = 0; i < RSA_NUM; i++)\n if (rsa_key[i] != NULL)\n RSA_free(rsa_key[i]);\n# endif\n# ifndef OPENSSL_NO_DSA\n for (i = 0; i < DSA_NUM; i++)\n if (dsa_key[i] != NULL)\n DSA_free(dsa_key[i]);\n# endif\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n if (ecdsa[i] != NULL)\n EC_KEY_free(ecdsa[i]);\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++) {\n if (ecdh_a[i] != NULL)\n EC_KEY_free(ecdh_a[i]);\n if (ecdh_b[i] != NULL)\n EC_KEY_free(ecdh_b[i]);\n }\n# endif\n apps_shutdown();\n OPENSSL_EXIT(mret);\n}']
33,577
0
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/evp/evp_enc.c/#L329
int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, size_t inl) { size_t i; size_t bl; size_t j; if (inl <= 0) { *outl = 0; return inl == 0; } if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0) { if(ctx->cipher->do_cipher(ctx,out,in,inl)) { *outl=inl; return 1; } else { *outl=0; return 0; } } i=ctx->buf_len; bl=ctx->cipher->block_size; OPENSSL_assert(bl <= (int)sizeof(ctx->buf)); if (i != 0) { if (i+inl < bl) { memcpy(&(ctx->buf[i]),in,inl); ctx->buf_len+=inl; *outl=0; return 1; } else { j=bl-i; memcpy(&(ctx->buf[i]),in,j); if(!ctx->cipher->do_cipher(ctx,out,ctx->buf,bl)) return 0; inl-=j; in+=j; out+=bl; *outl=bl; } } else *outl = 0; i=inl&(bl-1); inl-=i; if (inl > 0) { if(!ctx->cipher->do_cipher(ctx,out,in,inl)) return 0; *outl+=inl; } if (i != 0) memcpy(ctx->buf,&(in[inl]),i); ctx->buf_len=i; return 1; }
['unsigned char * PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,\n\t\t\t\t int passlen, unsigned char *in, int inlen,\n\t\t\t\t unsigned char **data, size_t *datalen,\n\t\t\t\t int en_de)\n{\n\tunsigned char *out;\n\tint outlen, i;\n\tEVP_CIPHER_CTX ctx;\n\tEVP_CIPHER_CTX_init(&ctx);\n if (!EVP_PBE_CipherInit(algor->algorithm, pass, passlen,\n\t\t\t\t\t algor->parameter, &ctx, en_de)) {\n\t\tPKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR);\n\t\treturn NULL;\n\t}\n\tif(!(out = OPENSSL_malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx)))) {\n\t\tPKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t}\n\tEVP_CipherUpdate(&ctx, out, &i, in, inlen);\n\toutlen = i;\n\tif(!EVP_CipherFinal_ex(&ctx, out + i, &i)) {\n\t\tOPENSSL_free(out);\n\t\tout = NULL;\n\t\tPKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_CIPHERFINAL_ERROR);\n\t\tgoto err;\n\t}\n\toutlen += i;\n\tif (datalen) *datalen = outlen;\n\tif (data) *data = out;\n\terr:\n\tEVP_CIPHER_CTX_cleanup(&ctx);\n\treturn out;\n}', 'int EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n\t\t const unsigned char *in, size_t inl)\n\t{\n\tif (ctx->encrypt)\n\t\treturn EVP_EncryptUpdate(ctx,out,outl,in,inl);\n\telse\treturn EVP_DecryptUpdate(ctx,out,outl,in,inl);\n\t}', 'int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n\t\t const unsigned char *in, size_t inl)\n\t{\n\tsize_t i;\n\tsize_t bl;\n\tsize_t j;\n\tif (inl <= 0)\n\t\t{\n\t\t*outl = 0;\n\t\treturn inl == 0;\n\t\t}\n\tif(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0)\n\t\t{\n\t\tif(ctx->cipher->do_cipher(ctx,out,in,inl))\n\t\t\t{\n\t\t\t*outl=inl;\n\t\t\treturn 1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\t*outl=0;\n\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\ti=ctx->buf_len;\n\tbl=ctx->cipher->block_size;\n\tOPENSSL_assert(bl <= (int)sizeof(ctx->buf));\n\tif (i != 0)\n\t\t{\n\t\tif (i+inl < bl)\n\t\t\t{\n\t\t\tmemcpy(&(ctx->buf[i]),in,inl);\n\t\t\tctx->buf_len+=inl;\n\t\t\t*outl=0;\n\t\t\treturn 1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tj=bl-i;\n\t\t\tmemcpy(&(ctx->buf[i]),in,j);\n\t\t\tif(!ctx->cipher->do_cipher(ctx,out,ctx->buf,bl)) return 0;\n\t\t\tinl-=j;\n\t\t\tin+=j;\n\t\t\tout+=bl;\n\t\t\t*outl=bl;\n\t\t\t}\n\t\t}\n\telse\n\t\t*outl = 0;\n\ti=inl&(bl-1);\n\tinl-=i;\n\tif (inl > 0)\n\t\t{\n\t\tif(!ctx->cipher->do_cipher(ctx,out,in,inl)) return 0;\n\t\t*outl+=inl;\n\t\t}\n\tif (i != 0)\n\t\tmemcpy(ctx->buf,&(in[inl]),i);\n\tctx->buf_len=i;\n\treturn 1;\n\t}']
33,578
0
https://github.com/openssl/openssl/blob/b79aa47a0c8478bea62fc2bb55f99e0be172da3d/crypto/bn/bn_add.c/#L230
int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) { int max,min,dif; register BN_ULONG t1,t2,*ap,*bp,*rp; int i,carry; #if defined(IRIX_CC_BUG) && !defined(LINT) int dummy; #endif bn_check_top(a); bn_check_top(b); max = a->top; min = b->top; dif = max - min; if (dif < 0) { BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3); return(0); } if (bn_wexpand(r,max) == NULL) return(0); ap=a->d; bp=b->d; rp=r->d; #if 1 carry=0; for (i = min; i != 0; i--) { t1= *(ap++); t2= *(bp++); if (carry) { carry=(t1 <= t2); t1=(t1-t2-1)&BN_MASK2; } else { carry=(t1 < t2); t1=(t1-t2)&BN_MASK2; } #if defined(IRIX_CC_BUG) && !defined(LINT) dummy=t1; #endif *(rp++)=t1&BN_MASK2; } #else carry=bn_sub_words(rp,ap,bp,min); ap+=min; bp+=min; rp+=min; #endif if (carry) { if (!dif) return 0; while (dif) { dif--; t1 = *(ap++); t2 = (t1-1)&BN_MASK2; *(rp++) = t2; if (t1) break; } } #if 0 memcpy(rp,ap,sizeof(*rp)*(max-i)); #else if (rp != ap) { for (;;) { if (!dif--) break; rp[0]=ap[0]; if (!dif--) break; rp[1]=ap[1]; if (!dif--) break; rp[2]=ap[2]; if (!dif--) break; rp[3]=ap[3]; rp+=4; ap+=4; } } #endif r->top=max; r->neg=0; bn_correct_top(r); return(1); }
['BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tif (!BN_nnmod(B, B, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tif (ret)\n\t\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n\t{\n\tint max,min,dif;\n\tBN_ULONG *ap,*bp,*rp,carry,t1,t2;\n\tconst BIGNUM *tmp;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tif (a->top < b->top)\n\t\t{ tmp=a; a=b; b=tmp; }\n\tmax = a->top;\n\tmin = b->top;\n\tdif = max - min;\n\tif (bn_wexpand(r,max+1) == NULL)\n\t\treturn 0;\n\tr->top=max;\n\tap=a->d;\n\tbp=b->d;\n\trp=r->d;\n\tcarry=bn_add_words(rp,ap,bp,min);\n\trp+=min;\n\tap+=min;\n\tbp+=min;\n\tif (carry)\n\t\t{\n\t\twhile (dif)\n\t\t\t{\n\t\t\tdif--;\n\t\t\tt1 = *(ap++);\n\t\t\tt2 = (t1+1) & BN_MASK2;\n\t\t\t*(rp++) = t2;\n\t\t\tif (t2)\n\t\t\t\t{\n\t\t\t\tcarry=0;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (carry)\n\t\t\t{\n\t\t\t*rp = 1;\n\t\t\tr->top++;\n\t\t\t}\n\t\t}\n\tif (dif && rp != ap)\n\t\twhile (dif--)\n\t\t\t*(rp++) = *(ap++);\n\tr->neg = 0;\n\tbn_check_top(r);\n\treturn 1;\n\t}', 'int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n\t{\n\tint max,min,dif;\n\tregister BN_ULONG t1,t2,*ap,*bp,*rp;\n\tint i,carry;\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\tint dummy;\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tmax = a->top;\n\tmin = b->top;\n\tdif = max - min;\n\tif (dif < 0)\n\t\t{\n\t\tBNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);\n\t\treturn(0);\n\t\t}\n\tif (bn_wexpand(r,max) == NULL) return(0);\n\tap=a->d;\n\tbp=b->d;\n\trp=r->d;\n#if 1\n\tcarry=0;\n\tfor (i = min; i != 0; i--)\n\t\t{\n\t\tt1= *(ap++);\n\t\tt2= *(bp++);\n\t\tif (carry)\n\t\t\t{\n\t\t\tcarry=(t1 <= t2);\n\t\t\tt1=(t1-t2-1)&BN_MASK2;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tcarry=(t1 < t2);\n\t\t\tt1=(t1-t2)&BN_MASK2;\n\t\t\t}\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\t\tdummy=t1;\n#endif\n\t\t*(rp++)=t1&BN_MASK2;\n\t\t}\n#else\n\tcarry=bn_sub_words(rp,ap,bp,min);\n\tap+=min;\n\tbp+=min;\n\trp+=min;\n#endif\n\tif (carry)\n\t\t{\n\t\tif (!dif)\n\t\t\treturn 0;\n\t\twhile (dif)\n\t\t\t{\n\t\t\tdif--;\n\t\t\tt1 = *(ap++);\n\t\t\tt2 = (t1-1)&BN_MASK2;\n\t\t\t*(rp++) = t2;\n\t\t\tif (t1)\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n#if 0\n\tmemcpy(rp,ap,sizeof(*rp)*(max-i));\n#else\n\tif (rp != ap)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tif (!dif--) break;\n\t\t\trp[0]=ap[0];\n\t\t\tif (!dif--) break;\n\t\t\trp[1]=ap[1];\n\t\t\tif (!dif--) break;\n\t\t\trp[2]=ap[2];\n\t\t\tif (!dif--) break;\n\t\t\trp[3]=ap[3];\n\t\t\trp+=4;\n\t\t\tap+=4;\n\t\t\t}\n\t\t}\n#endif\n\tr->top=max;\n\tr->neg=0;\n\tbn_correct_top(r);\n\treturn(1);\n\t}']
33,579
0
https://github.com/openssl/openssl/blob/0bde1089f895718db2fe2637fda4a0c2ed6df904/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 **)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 long ssl_ctrl(BIO *b, int cmd, long num, char *ptr)\n\t{\n\tSSL **sslp,*ssl;\n\tBIO_SSL *bs;\n\tBIO *dbio,*bio;\n\tlong ret=1;\n\tbs=(BIO_SSL *)b->ptr;\n\tssl=bs->ssl;\n\tif ((ssl == NULL) && (cmd != BIO_C_SET_SSL))\n\t\treturn(0);\n\tswitch (cmd)\n\t\t{\n\tcase BIO_CTRL_RESET:\n\t\tSSL_shutdown(ssl);\n\t\tif (ssl->handshake_func == ssl->method->ssl_connect)\n\t\t\tSSL_set_connect_state(ssl);\n\t\telse if (ssl->handshake_func == ssl->method->ssl_accept)\n\t\t\tSSL_set_accept_state(ssl);\n\t\tSSL_clear(ssl);\n\t\tif (b->next_bio != NULL)\n\t\t\tret=BIO_ctrl(b->next_bio,cmd,num,ptr);\n\t\telse if (ssl->rbio != NULL)\n\t\t\tret=BIO_ctrl(ssl->rbio,cmd,num,ptr);\n\t\telse\n\t\t\tret=1;\n\t\tbreak;\n\tcase BIO_CTRL_INFO:\n\t\tret=0;\n\t\tbreak;\n\tcase BIO_C_SSL_MODE:\n\t\tif (num)\n\t\t\tSSL_set_connect_state(ssl);\n\t\telse\n\t\t\tSSL_set_accept_state(ssl);\n\t\tbreak;\n\tcase BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT:\n\t\tret=bs->renegotiate_timeout;\n\t\tif (num < 60) num=5;\n\t\tbs->renegotiate_timeout=(unsigned long)num;\n\t\tbs->last_time=(unsigned long)time(NULL);\n\t\tbreak;\n\tcase BIO_C_SET_SSL_RENEGOTIATE_BYTES:\n\t\tret=bs->renegotiate_count;\n\t\tif ((long)num >=512)\n\t\t\tbs->renegotiate_count=(unsigned long)num;\n\t\tbreak;\n\tcase BIO_C_GET_SSL_NUM_RENEGOTIATES:\n\t\tret=bs->num_renegotiates;\n\t\tbreak;\n\tcase BIO_C_SET_SSL:\n\t\tif (ssl != NULL)\n\t\t\tssl_free(b);\n\t\tb->shutdown=(int)num;\n\t\tssl=(SSL *)ptr;\n\t\t((BIO_SSL *)b->ptr)->ssl=ssl;\n\t\tbio=SSL_get_rbio(ssl);\n\t\tif (bio != NULL)\n\t\t\t{\n\t\t\tif (b->next_bio != NULL)\n\t\t\t\tBIO_push(bio,b->next_bio);\n\t\t\tb->next_bio=bio;\n\t\t\tCRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO);\n\t\t\t}\n\t\tb->init=1;\n\t\tbreak;\n\tcase BIO_C_GET_SSL:\n\t\tif (ptr != NULL)\n\t\t\t{\n\t\t\tsslp=(SSL **)ptr;\n\t\t\t*sslp=ssl;\n\t\t\t}\n\t\telse\n\t\t\tret=0;\n\t\tbreak;\n\tcase BIO_CTRL_GET_CLOSE:\n\t\tret=b->shutdown;\n\t\tbreak;\n\tcase BIO_CTRL_SET_CLOSE:\n\t\tb->shutdown=(int)num;\n\t\tbreak;\n\tcase BIO_CTRL_WPENDING:\n\t\tret=BIO_ctrl(ssl->wbio,cmd,num,ptr);\n\t\tbreak;\n\tcase BIO_CTRL_PENDING:\n\t\tret=SSL_pending(ssl);\n\t\tif (ret == 0)\n\t\t\tret=BIO_pending(ssl->rbio);\n\t\tbreak;\n\tcase BIO_CTRL_FLUSH:\n\t\tBIO_clear_retry_flags(b);\n\t\tret=BIO_ctrl(ssl->wbio,cmd,num,ptr);\n\t\tBIO_copy_next_retry(b);\n\t\tbreak;\n\tcase BIO_CTRL_PUSH:\n\t\tif ((b->next_bio != NULL) && (b->next_bio != ssl->rbio))\n\t\t\t{\n\t\t\tSSL_set_bio(ssl,b->next_bio,b->next_bio);\n\t\t\tCRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO);\n\t\t\t}\n\t\tbreak;\n\tcase BIO_CTRL_POP:\n\t\tif (ssl->rbio != ssl->wbio)\n\t\t\t{\n\t\t\tBIO_free_all(ssl->wbio);\n\t\t\t}\n\t\tssl->wbio=NULL;\n\t\tssl->rbio=NULL;\n\t\tbreak;\n\tcase BIO_C_DO_STATE_MACHINE:\n\t\tBIO_clear_retry_flags(b);\n\t\tb->retry_reason=0;\n\t\tret=(int)SSL_do_handshake(ssl);\n\t\tswitch (SSL_get_error(ssl,(int)ret))\n\t\t\t{\n\t\tcase SSL_ERROR_WANT_READ:\n\t\t\tBIO_set_flags(b,\n\t\t\t\tBIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY);\n\t\t\tbreak;\n\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\tBIO_set_flags(b,\n\t\t\t\tBIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY);\n\t\t\tbreak;\n\t\tcase SSL_ERROR_WANT_CONNECT:\n\t\t\tBIO_set_flags(b,\n\t\t\t\tBIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY);\n\t\t\tb->retry_reason=b->next_bio->retry_reason;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t\t\t}\n\t\tbreak;\n\tcase BIO_CTRL_DUP:\n\t\tdbio=(BIO *)ptr;\n\t\tif (((BIO_SSL *)dbio->ptr)->ssl != NULL)\n\t\t\tSSL_free(((BIO_SSL *)dbio->ptr)->ssl);\n\t\t((BIO_SSL *)dbio->ptr)->ssl=SSL_dup(ssl);\n\t\t((BIO_SSL *)dbio->ptr)->renegotiate_count=\n\t\t\t((BIO_SSL *)b->ptr)->renegotiate_count;\n\t\t((BIO_SSL *)dbio->ptr)->byte_count=\n\t\t\t((BIO_SSL *)b->ptr)->byte_count;\n\t\t((BIO_SSL *)dbio->ptr)->renegotiate_timeout=\n\t\t\t((BIO_SSL *)b->ptr)->renegotiate_timeout;\n\t\t((BIO_SSL *)dbio->ptr)->last_time=\n\t\t\t((BIO_SSL *)b->ptr)->last_time;\n\t\tret=(((BIO_SSL *)dbio->ptr)->ssl != NULL);\n\t\tbreak;\n\tcase BIO_C_GET_FD:\n\t\tret=BIO_ctrl(ssl->rbio,cmd,num,ptr);\n\t\tbreak;\n\tcase BIO_CTRL_SET_CALLBACK:\n\t\t{\n\t\tunion void_fn_to_char_u tmp_cb;\n\t\ttmp_cb.char_p = ptr;\n\t\tSSL_set_info_callback(ssl,tmp_cb.fn_p);\n\t\t}\n\t\tbreak;\n\tcase BIO_CTRL_GET_CALLBACK:\n\t\t{\n\t\tvoid (**fptr)();\n\t\tfptr=(void (**)())ptr;\n\t\t*fptr=SSL_get_info_callback(ssl);\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tret=BIO_ctrl(ssl->rbio,cmd,num,ptr);\n\t\tbreak;\n\t\t}\n\treturn(ret);\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,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\tFree(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)Realloc(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}']
33,580
0
https://github.com/openssl/openssl/blob/d00b1d62d62036dc21c78658a28da4a6279e6fe2/crypto/bn/bn_ctx.c/#L354
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,\n\tconst BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx)\n\t{\n\tBN_CTX *new_ctx = NULL;\n\tint ret = 0;\n\tif (ctx == NULL)\n\t\t{\n\t\tctx = new_ctx = BN_CTX_new();\n\t\tif (ctx == NULL)\n\t\t\treturn 0;\n\t\t}\n\tif (x != NULL)\n\t\t{\n\t\tif (!BN_nnmod(point->X, x, group->field, ctx)) goto err;\n\t\tif (group->meth->field_encode)\n\t\t\t{\n\t\t\tif (!group->meth->field_encode(group, point->X, point->X, ctx)) goto err;\n\t\t\t}\n\t\t}\n\tif (y != NULL)\n\t\t{\n\t\tif (!BN_nnmod(point->Y, y, group->field, ctx)) goto err;\n\t\tif (group->meth->field_encode)\n\t\t\t{\n\t\t\tif (!group->meth->field_encode(group, point->Y, point->Y, ctx)) goto err;\n\t\t\t}\n\t\t}\n\tif (z != NULL)\n\t\t{\n\t\tint Z_is_one;\n\t\tif (!BN_nnmod(point->Z, z, group->field, ctx)) goto err;\n\t\tZ_is_one = BN_is_one(point->Z);\n\t\tif (group->meth->field_encode)\n\t\t\t{\n\t\t\tif (Z_is_one && (group->meth->field_set_to_one != 0))\n\t\t\t\t{\n\t\t\t\tif (!group->meth->field_set_to_one(group, point->Z, ctx)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!group->meth->field_encode(group, point->Z, point->Z, ctx)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\tpoint->Z_is_one = Z_is_one;\n\t\t}\n\tret = 1;\n err:\n\tif (new_ctx != NULL)\n\t\tBN_CTX_free(new_ctx);\n\treturn ret;\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tint no_branch=0;\n\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\tno_branch=1;\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (!no_branch && BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n\t\tgoto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (no_branch)\n\t\t{\n\t\tif (snum->top <= sdiv->top+1)\n\t\t\t{\n\t\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\t\tsnum->top = sdiv->top + 2;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\t\tsnum->d[snum->top] = 0;\n\t\t\tsnum->top ++;\n\t\t\t}\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-no_branch;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (!no_branch)\n\t\t{\n\t\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t\t{\n\t\t\tbn_clear_top2max(&wnum);\n\t\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t\t*resp=1;\n\t\t\t}\n\t\telse\n\t\t\tres->top--;\n\t\t}\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tif (no_branch)\tbn_correct_top(res);\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_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}']
33,581
0
https://github.com/nginx/nginx/blob/70f7141074896fb1ff3e5fc08407ea0f64f2076b/src/core/ngx_string.c/#L922
ngx_int_t ngx_atoi(u_char *line, size_t n) { ngx_int_t value, cutoff, cutlim; if (n == 0) { return NGX_ERROR; } cutoff = NGX_MAX_INT_T_VALUE / 10; cutlim = NGX_MAX_INT_T_VALUE % 10; for (value = 0; n--; line++) { if (*line < '0' || *line > '9') { return NGX_ERROR; } if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) { return NGX_ERROR; } value = value * 10 + (*line - '0'); } return value; }
['static ngx_int_t\nngx_http_upstream_set_local(ngx_http_request_t *r, ngx_http_upstream_t *u,\n ngx_http_upstream_local_t *local)\n{\n ngx_int_t rc;\n ngx_str_t val;\n ngx_addr_t *addr;\n if (local == NULL) {\n u->peer.local = NULL;\n return NGX_OK;\n }\n#if (NGX_HAVE_TRANSPARENT_PROXY)\n u->peer.transparent = local->transparent;\n#endif\n if (local->value == NULL) {\n u->peer.local = local->addr;\n return NGX_OK;\n }\n if (ngx_http_complex_value(r, local->value, &val) != NGX_OK) {\n return NGX_ERROR;\n }\n if (val.len == 0) {\n return NGX_OK;\n }\n addr = ngx_palloc(r->pool, sizeof(ngx_addr_t));\n if (addr == NULL) {\n return NGX_ERROR;\n }\n rc = ngx_parse_addr_port(r->pool, addr, val.data, val.len);\n if (rc == NGX_ERROR) {\n return NGX_ERROR;\n }\n if (rc != NGX_OK) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "invalid local address \\"%V\\"", &val);\n return NGX_OK;\n }\n addr->name = val;\n u->peer.local = addr;\n return NGX_OK;\n}', "ngx_int_t\nngx_parse_addr_port(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text,\n size_t len)\n{\n u_char *p, *last;\n size_t plen;\n ngx_int_t rc, port;\n rc = ngx_parse_addr(pool, addr, text, len);\n if (rc != NGX_DECLINED) {\n return rc;\n }\n last = text + len;\n#if (NGX_HAVE_INET6)\n if (len && text[0] == '[') {\n p = ngx_strlchr(text, last, ']');\n if (p == NULL || p == last - 1 || *++p != ':') {\n return NGX_DECLINED;\n }\n text++;\n len -= 2;\n } else\n#endif\n {\n p = ngx_strlchr(text, last, ':');\n if (p == NULL) {\n return NGX_DECLINED;\n }\n }\n p++;\n plen = last - p;\n port = ngx_atoi(p, plen);\n if (port < 1 || port > 65535) {\n return NGX_DECLINED;\n }\n len -= plen + 1;\n rc = ngx_parse_addr(pool, addr, text, len);\n if (rc != NGX_OK) {\n return rc;\n }\n ngx_inet_set_port(addr->sockaddr, (in_port_t) port);\n return NGX_OK;\n}", 'static ngx_inline u_char *\nngx_strlchr(u_char *p, u_char *last, u_char c)\n{\n while (p < last) {\n if (*p == c) {\n return p;\n }\n p++;\n }\n return NULL;\n}', "ngx_int_t\nngx_atoi(u_char *line, size_t n)\n{\n ngx_int_t value, cutoff, cutlim;\n if (n == 0) {\n return NGX_ERROR;\n }\n cutoff = NGX_MAX_INT_T_VALUE / 10;\n cutlim = NGX_MAX_INT_T_VALUE % 10;\n for (value = 0; n--; line++) {\n if (*line < '0' || *line > '9') {\n return NGX_ERROR;\n }\n if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) {\n return NGX_ERROR;\n }\n value = value * 10 + (*line - '0');\n }\n return value;\n}"]
33,582
0
https://github.com/libav/libav/blob/47399ccdfd93d337c96c76fbf591f0e3637131ef/libavcodec/bitstream.h/#L236
static inline void skip_remaining(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE bc->bits >>= n; #else bc->bits <<= n; #endif bc->bits_left -= n; }
['static av_always_inline void decode_line(FFV1Context *s, int w,\n int16_t *sample[2],\n int plane_index, int bits)\n{\n PlaneContext *const p = &s->plane[plane_index];\n RangeCoder *const c = &s->c;\n int x;\n int run_count = 0;\n int run_mode = 0;\n int run_index = s->run_index;\n for (x = 0; x < w; x++) {\n int diff, context, sign;\n context = get_context(p, sample[1] + x, sample[0] + x, sample[1] + x);\n if (context < 0) {\n context = -context;\n sign = 1;\n } else\n sign = 0;\n av_assert2(context < p->context_count);\n if (s->ac != AC_GOLOMB_RICE) {\n diff = get_symbol_inline(c, p->state[context], 1);\n } else {\n if (context == 0 && run_mode == 0)\n run_mode = 1;\n if (run_mode) {\n if (run_count == 0 && run_mode == 1) {\n if (bitstream_read_bit(&s->bc)) {\n run_count = 1 << ff_log2_run[run_index];\n if (x + run_count <= w)\n run_index++;\n } else {\n if (ff_log2_run[run_index])\n run_count = bitstream_read(&s->bc, ff_log2_run[run_index]);\n else\n run_count = 0;\n if (run_index)\n run_index--;\n run_mode = 2;\n }\n }\n run_count--;\n if (run_count < 0) {\n run_mode = 0;\n run_count = 0;\n diff = get_vlc_symbol(&s->bc, &p->vlc_state[context],\n bits);\n if (diff >= 0)\n diff++;\n } else\n diff = 0;\n } else\n diff = get_vlc_symbol(&s->bc, &p->vlc_state[context], bits);\n ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\\n",\n run_count, run_index, run_mode, x, bitstream_tell(&s->bc));\n }\n if (sign)\n diff = -diff;\n sample[1][x] = (predict(sample[1] + x, sample[0] + x) + diff) &\n ((1 << bits) - 1);\n }\n s->run_index = run_index;\n}', 'static inline int get_vlc_symbol(BitstreamContext *bc, VlcState *const state,\n int bits)\n{\n int k, i, v, ret;\n i = state->count;\n k = 0;\n while (i < state->error_sum) {\n k++;\n i += i;\n }\n assert(k <= 8);\n v = get_sr_golomb(bc, k, 12, bits);\n ff_dlog(NULL, "v:%d bias:%d error:%d drift:%d count:%d k:%d",\n v, state->bias, state->error_sum, state->drift, state->count, k);\n v ^= ((2 * state->drift + state->count) >> 31);\n ret = fold(v + state->bias, bits);\n update_vlc_state(state, v);\n return ret;\n}', 'static inline int get_sr_golomb(BitstreamContext *bc, int k, int limit,\n int esc_len)\n{\n int v = get_ur_golomb(bc, k, limit, esc_len);\n v++;\n if (v & 1)\n return v >> 1;\n else\n return -(v >> 1);\n}', 'static inline int get_ur_golomb(BitstreamContext *bc, int k, int limit,\n int esc_len)\n{\n unsigned int buf;\n int log;\n buf = bitstream_peek(bc, 32);\n log = av_log2(buf);\n if (log > 31 - limit) {\n buf >>= log - k;\n buf += (30 - log) << k;\n bitstream_skip(bc, 32 + k - log);\n return buf;\n } else {\n bitstream_skip(bc, limit);\n buf = bitstream_read(bc, esc_len);\n return buf + limit - 1;\n }\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n < bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n bc->bits = 0;\n bc->bits_left = 0;\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
33,583
0
https://github.com/libav/libav/blob/a1e98f198e9db4e5ddfc2f777014179d3d7bc4d2/libavcodec/mpc8.c/#L363
static int mpc8_decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; MPCContext *c = avctx->priv_data; GetBitContext gb2, *gb = &gb2; int i, j, k, ch, cnt, res, t; Band *bands = c->bands; int off; int maxband, keyframe; int last[2]; c->frame.nb_samples = MPC_FRAME_SIZE; if ((res = avctx->get_buffer(avctx, &c->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return res; } keyframe = c->cur_frame == 0; if(keyframe){ memset(c->Q, 0, sizeof(c->Q)); c->last_bits_used = 0; } init_get_bits(gb, buf, buf_size * 8); skip_bits(gb, c->last_bits_used & 7); if(keyframe) maxband = mpc8_get_mod_golomb(gb, c->maxbands + 1); else{ maxband = c->last_max_band + get_vlc2(gb, band_vlc.table, MPC8_BANDS_BITS, 2); if(maxband > 32) maxband -= 33; } if(maxband > c->maxbands) return AVERROR_INVALIDDATA; c->last_max_band = maxband; if(maxband){ last[0] = last[1] = 0; for(i = maxband - 1; i >= 0; i--){ for(ch = 0; ch < 2; ch++){ last[ch] = get_vlc2(gb, res_vlc[last[ch] > 2].table, MPC8_RES_BITS, 2) + last[ch]; if(last[ch] > 15) last[ch] -= 17; bands[i].res[ch] = last[ch]; } } if(c->MSS){ int mask; cnt = 0; for(i = 0; i < maxband; i++) if(bands[i].res[0] || bands[i].res[1]) cnt++; t = mpc8_get_mod_golomb(gb, cnt); mask = mpc8_get_mask(gb, cnt, t); for(i = maxband - 1; i >= 0; i--) if(bands[i].res[0] || bands[i].res[1]){ bands[i].msf = mask & 1; mask >>= 1; } } } for(i = maxband; i < c->maxbands; i++) bands[i].res[0] = bands[i].res[1] = 0; if(keyframe){ for(i = 0; i < 32; i++) c->oldDSCF[0][i] = c->oldDSCF[1][i] = 1; } for(i = 0; i < maxband; i++){ if(bands[i].res[0] || bands[i].res[1]){ cnt = !!bands[i].res[0] + !!bands[i].res[1] - 1; if(cnt >= 0){ t = get_vlc2(gb, scfi_vlc[cnt].table, scfi_vlc[cnt].bits, 1); if(bands[i].res[0]) bands[i].scfi[0] = t >> (2 * cnt); if(bands[i].res[1]) bands[i].scfi[1] = t & 3; } } } for(i = 0; i < maxband; i++){ for(ch = 0; ch < 2; ch++){ if(!bands[i].res[ch]) continue; if(c->oldDSCF[ch][i]){ bands[i].scf_idx[ch][0] = get_bits(gb, 7) - 6; c->oldDSCF[ch][i] = 0; }else{ t = get_vlc2(gb, dscf_vlc[1].table, MPC8_DSCF1_BITS, 2); if(t == 64) t += get_bits(gb, 6); bands[i].scf_idx[ch][0] = ((bands[i].scf_idx[ch][2] + t - 25) & 0x7F) - 6; } for(j = 0; j < 2; j++){ if((bands[i].scfi[ch] << j) & 2) bands[i].scf_idx[ch][j + 1] = bands[i].scf_idx[ch][j]; else{ t = get_vlc2(gb, dscf_vlc[0].table, MPC8_DSCF0_BITS, 2); if(t == 31) t = 64 + get_bits(gb, 6); bands[i].scf_idx[ch][j + 1] = ((bands[i].scf_idx[ch][j] + t - 25) & 0x7F) - 6; } } } } for(i = 0, off = 0; i < maxband; i++, off += SAMPLES_PER_BAND){ for(ch = 0; ch < 2; ch++){ res = bands[i].res[ch]; switch(res){ case -1: for(j = 0; j < SAMPLES_PER_BAND; j++) c->Q[ch][off + j] = (av_lfg_get(&c->rnd) & 0x3FC) - 510; break; case 0: break; case 1: for(j = 0; j < SAMPLES_PER_BAND; j += SAMPLES_PER_BAND / 2){ cnt = get_vlc2(gb, q1_vlc.table, MPC8_Q1_BITS, 2); t = mpc8_get_mask(gb, 18, cnt); for(k = 0; k < SAMPLES_PER_BAND / 2; k++, t <<= 1) c->Q[ch][off + j + k] = (t & 0x20000) ? (get_bits1(gb) << 1) - 1 : 0; } break; case 2: cnt = 6; for(j = 0; j < SAMPLES_PER_BAND; j += 3){ t = get_vlc2(gb, q2_vlc[cnt > 3].table, MPC8_Q2_BITS, 2); c->Q[ch][off + j + 0] = mpc8_idx50[t]; c->Q[ch][off + j + 1] = mpc8_idx51[t]; c->Q[ch][off + j + 2] = mpc8_idx52[t]; cnt = (cnt >> 1) + mpc8_huffq2[t]; } break; case 3: case 4: for(j = 0; j < SAMPLES_PER_BAND; j += 2){ t = get_vlc2(gb, q3_vlc[res - 3].table, MPC8_Q3_BITS, 2) + q3_offsets[res - 3]; c->Q[ch][off + j + 1] = t >> 4; c->Q[ch][off + j + 0] = (t & 8) ? (t & 0xF) - 16 : (t & 0xF); } break; case 5: case 6: case 7: case 8: cnt = 2 * mpc8_thres[res]; for(j = 0; j < SAMPLES_PER_BAND; j++){ t = get_vlc2(gb, quant_vlc[res - 5][cnt > mpc8_thres[res]].table, quant_vlc[res - 5][cnt > mpc8_thres[res]].bits, 2) + quant_offsets[res - 5]; c->Q[ch][off + j] = t; cnt = (cnt >> 1) + FFABS(c->Q[ch][off + j]); } break; default: for(j = 0; j < SAMPLES_PER_BAND; j++){ c->Q[ch][off + j] = get_vlc2(gb, q9up_vlc.table, MPC8_Q9UP_BITS, 2); if(res != 9){ c->Q[ch][off + j] <<= res - 9; c->Q[ch][off + j] |= get_bits(gb, res - 9); } c->Q[ch][off + j] -= (1 << (res - 2)) - 1; } } } } ff_mpc_dequantize_and_synth(c, maxband, c->frame.data[0], avctx->channels); c->cur_frame++; c->last_bits_used = get_bits_count(gb); if(c->cur_frame >= c->frames) c->cur_frame = 0; *got_frame_ptr = 1; *(AVFrame *)data = c->frame; return c->cur_frame ? c->last_bits_used >> 3 : buf_size; }
['static int mpc8_decode_frame(AVCodecContext * avctx, void *data,\n int *got_frame_ptr, AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n MPCContext *c = avctx->priv_data;\n GetBitContext gb2, *gb = &gb2;\n int i, j, k, ch, cnt, res, t;\n Band *bands = c->bands;\n int off;\n int maxband, keyframe;\n int last[2];\n c->frame.nb_samples = MPC_FRAME_SIZE;\n if ((res = avctx->get_buffer(avctx, &c->frame)) < 0) {\n av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return res;\n }\n keyframe = c->cur_frame == 0;\n if(keyframe){\n memset(c->Q, 0, sizeof(c->Q));\n c->last_bits_used = 0;\n }\n init_get_bits(gb, buf, buf_size * 8);\n skip_bits(gb, c->last_bits_used & 7);\n if(keyframe)\n maxband = mpc8_get_mod_golomb(gb, c->maxbands + 1);\n else{\n maxband = c->last_max_band + get_vlc2(gb, band_vlc.table, MPC8_BANDS_BITS, 2);\n if(maxband > 32) maxband -= 33;\n }\n if(maxband > c->maxbands)\n return AVERROR_INVALIDDATA;\n c->last_max_band = maxband;\n if(maxband){\n last[0] = last[1] = 0;\n for(i = maxband - 1; i >= 0; i--){\n for(ch = 0; ch < 2; ch++){\n last[ch] = get_vlc2(gb, res_vlc[last[ch] > 2].table, MPC8_RES_BITS, 2) + last[ch];\n if(last[ch] > 15) last[ch] -= 17;\n bands[i].res[ch] = last[ch];\n }\n }\n if(c->MSS){\n int mask;\n cnt = 0;\n for(i = 0; i < maxband; i++)\n if(bands[i].res[0] || bands[i].res[1])\n cnt++;\n t = mpc8_get_mod_golomb(gb, cnt);\n mask = mpc8_get_mask(gb, cnt, t);\n for(i = maxband - 1; i >= 0; i--)\n if(bands[i].res[0] || bands[i].res[1]){\n bands[i].msf = mask & 1;\n mask >>= 1;\n }\n }\n }\n for(i = maxband; i < c->maxbands; i++)\n bands[i].res[0] = bands[i].res[1] = 0;\n if(keyframe){\n for(i = 0; i < 32; i++)\n c->oldDSCF[0][i] = c->oldDSCF[1][i] = 1;\n }\n for(i = 0; i < maxband; i++){\n if(bands[i].res[0] || bands[i].res[1]){\n cnt = !!bands[i].res[0] + !!bands[i].res[1] - 1;\n if(cnt >= 0){\n t = get_vlc2(gb, scfi_vlc[cnt].table, scfi_vlc[cnt].bits, 1);\n if(bands[i].res[0]) bands[i].scfi[0] = t >> (2 * cnt);\n if(bands[i].res[1]) bands[i].scfi[1] = t & 3;\n }\n }\n }\n for(i = 0; i < maxband; i++){\n for(ch = 0; ch < 2; ch++){\n if(!bands[i].res[ch]) continue;\n if(c->oldDSCF[ch][i]){\n bands[i].scf_idx[ch][0] = get_bits(gb, 7) - 6;\n c->oldDSCF[ch][i] = 0;\n }else{\n t = get_vlc2(gb, dscf_vlc[1].table, MPC8_DSCF1_BITS, 2);\n if(t == 64)\n t += get_bits(gb, 6);\n bands[i].scf_idx[ch][0] = ((bands[i].scf_idx[ch][2] + t - 25) & 0x7F) - 6;\n }\n for(j = 0; j < 2; j++){\n if((bands[i].scfi[ch] << j) & 2)\n bands[i].scf_idx[ch][j + 1] = bands[i].scf_idx[ch][j];\n else{\n t = get_vlc2(gb, dscf_vlc[0].table, MPC8_DSCF0_BITS, 2);\n if(t == 31)\n t = 64 + get_bits(gb, 6);\n bands[i].scf_idx[ch][j + 1] = ((bands[i].scf_idx[ch][j] + t - 25) & 0x7F) - 6;\n }\n }\n }\n }\n for(i = 0, off = 0; i < maxband; i++, off += SAMPLES_PER_BAND){\n for(ch = 0; ch < 2; ch++){\n res = bands[i].res[ch];\n switch(res){\n case -1:\n for(j = 0; j < SAMPLES_PER_BAND; j++)\n c->Q[ch][off + j] = (av_lfg_get(&c->rnd) & 0x3FC) - 510;\n break;\n case 0:\n break;\n case 1:\n for(j = 0; j < SAMPLES_PER_BAND; j += SAMPLES_PER_BAND / 2){\n cnt = get_vlc2(gb, q1_vlc.table, MPC8_Q1_BITS, 2);\n t = mpc8_get_mask(gb, 18, cnt);\n for(k = 0; k < SAMPLES_PER_BAND / 2; k++, t <<= 1)\n c->Q[ch][off + j + k] = (t & 0x20000) ? (get_bits1(gb) << 1) - 1 : 0;\n }\n break;\n case 2:\n cnt = 6;\n for(j = 0; j < SAMPLES_PER_BAND; j += 3){\n t = get_vlc2(gb, q2_vlc[cnt > 3].table, MPC8_Q2_BITS, 2);\n c->Q[ch][off + j + 0] = mpc8_idx50[t];\n c->Q[ch][off + j + 1] = mpc8_idx51[t];\n c->Q[ch][off + j + 2] = mpc8_idx52[t];\n cnt = (cnt >> 1) + mpc8_huffq2[t];\n }\n break;\n case 3:\n case 4:\n for(j = 0; j < SAMPLES_PER_BAND; j += 2){\n t = get_vlc2(gb, q3_vlc[res - 3].table, MPC8_Q3_BITS, 2) + q3_offsets[res - 3];\n c->Q[ch][off + j + 1] = t >> 4;\n c->Q[ch][off + j + 0] = (t & 8) ? (t & 0xF) - 16 : (t & 0xF);\n }\n break;\n case 5:\n case 6:\n case 7:\n case 8:\n cnt = 2 * mpc8_thres[res];\n for(j = 0; j < SAMPLES_PER_BAND; j++){\n t = get_vlc2(gb, quant_vlc[res - 5][cnt > mpc8_thres[res]].table, quant_vlc[res - 5][cnt > mpc8_thres[res]].bits, 2) + quant_offsets[res - 5];\n c->Q[ch][off + j] = t;\n cnt = (cnt >> 1) + FFABS(c->Q[ch][off + j]);\n }\n break;\n default:\n for(j = 0; j < SAMPLES_PER_BAND; j++){\n c->Q[ch][off + j] = get_vlc2(gb, q9up_vlc.table, MPC8_Q9UP_BITS, 2);\n if(res != 9){\n c->Q[ch][off + j] <<= res - 9;\n c->Q[ch][off + j] |= get_bits(gb, res - 9);\n }\n c->Q[ch][off + j] -= (1 << (res - 2)) - 1;\n }\n }\n }\n }\n ff_mpc_dequantize_and_synth(c, maxband, c->frame.data[0], avctx->channels);\n c->cur_frame++;\n c->last_bits_used = get_bits_count(gb);\n if(c->cur_frame >= c->frames)\n c->cur_frame = 0;\n *got_frame_ptr = 1;\n *(AVFrame *)data = c->frame;\n return c->cur_frame ? c->last_bits_used >> 3 : buf_size;\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\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}']
33,584
0
https://github.com/openssl/openssl/blob/f3ff481f318b10a223d6157bde9645e1797487c5/ssl/packet.c/#L25
int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes) { assert(pkt->subs != NULL && len != 0); if (pkt->subs == NULL || len == 0) return 0; if (pkt->maxsize - pkt->written < len) return 0; if (pkt->buf->length - pkt->written < len) { size_t newlen; if (pkt->buf->length > SIZE_MAX / 2) { newlen = SIZE_MAX; } else { newlen = (pkt->buf->length == 0) ? DEFAULT_BUF_SIZE : pkt->buf->length * 2; } if (BUF_MEM_grow(pkt->buf, newlen) == 0) return 0; } *allocbytes = (unsigned char *)pkt->buf->data + pkt->curr; pkt->written += len; pkt->curr += len; return 1; }
['int ssl_add_clienthello_tlsext(SSL *s, WPACKET *pkt, int *al)\n{\n#ifndef OPENSSL_NO_EC\n int using_ecc = 0;\n if (s->version >= TLS1_VERSION || SSL_IS_DTLS(s)) {\n int i;\n unsigned long alg_k, alg_a;\n STACK_OF(SSL_CIPHER) *cipher_stack = SSL_get_ciphers(s);\n for (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++) {\n const SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i);\n alg_k = c->algorithm_mkey;\n alg_a = c->algorithm_auth;\n if ((alg_k & (SSL_kECDHE | SSL_kECDHEPSK))\n || (alg_a & SSL_aECDSA)) {\n using_ecc = 1;\n break;\n }\n }\n }\n#endif\n if (s->renegotiate) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_renegotiate)\n || !WPACKET_sub_memcpy_u16(pkt, s->s3->previous_client_finished,\n s->s3->previous_client_finished_len)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (s->client_version == SSL3_VERSION)\n goto done;\n if (s->tlsext_hostname != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_server_name)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, TLSEXT_NAMETYPE_host_name)\n || !WPACKET_sub_memcpy_u16(pkt, s->tlsext_hostname,\n strlen(s->tlsext_hostname))\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#ifndef OPENSSL_NO_SRP\n if (s->srp_ctx.login != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_srp)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u8(pkt)\n || !WPACKET_set_flags(pkt, WPACKET_FLAGS_NON_ZERO_LENGTH)\n || !WPACKET_memcpy(pkt, s->srp_ctx.login,\n strlen(s->srp_ctx.login))\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_EC\n if (using_ecc) {\n const unsigned char *pcurves, *pformats;\n size_t num_curves, num_formats;\n size_t i;\n tls1_get_formatlist(s, &pformats, &num_formats);\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_sub_memcpy_u8(pkt, pformats, num_formats)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pcurves = s->tlsext_ellipticcurvelist;\n if (!tls1_get_curvelist(s, 0, &pcurves, &num_curves)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_elliptic_curves)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n for (i = 0; i < num_curves; i++, pcurves += 2) {\n if (tls_curve_allowed(s, pcurves, SSL_SECOP_CURVE_SUPPORTED)) {\n if (!WPACKET_put_bytes_u8(pkt, pcurves[0])\n || !WPACKET_put_bytes_u8(pkt, pcurves[1])) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (tls_use_ticket(s)) {\n int ticklen;\n if (!s->new_session && s->session && s->session->tlsext_tick)\n ticklen = s->session->tlsext_ticklen;\n else if (s->session && s->tlsext_session_ticket &&\n s->tlsext_session_ticket->data) {\n ticklen = s->tlsext_session_ticket->length;\n s->session->tlsext_tick = OPENSSL_malloc(ticklen);\n if (s->session->tlsext_tick == NULL) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n memcpy(s->session->tlsext_tick,\n s->tlsext_session_ticket->data, ticklen);\n s->session->tlsext_ticklen = ticklen;\n } else\n ticklen = 0;\n if (ticklen == 0 && s->tlsext_session_ticket &&\n s->tlsext_session_ticket->data == NULL)\n goto skip_ext;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_session_ticket)\n || !WPACKET_sub_memcpy_u16(pkt, s->session->tlsext_tick,\n ticklen)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n skip_ext:\n if (SSL_CLIENT_USE_SIGALGS(s)) {\n size_t salglen;\n const unsigned char *salg;\n salglen = tls12_get_psigalgs(s, &salg);\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signature_algorithms)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !tls12_copy_sigalgs(s, pkt, salg, salglen)\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#ifndef OPENSSL_NO_OCSP\n if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp) {\n int i;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_status_request)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, TLSEXT_STATUSTYPE_ocsp)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) {\n unsigned char *idbytes;\n int idlen;\n OCSP_RESPID *id;\n id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i);\n idlen = i2d_OCSP_RESPID(id, NULL);\n if (idlen <= 0\n || !WPACKET_sub_allocate_bytes_u16(pkt, idlen, &idbytes)\n || i2d_OCSP_RESPID(id, &idbytes) != idlen) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (s->tlsext_ocsp_exts) {\n unsigned char *extbytes;\n int extlen = i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, NULL);\n if (extlen < 0) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_allocate_bytes(pkt, extlen, &extbytes)\n || i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &extbytes)\n != extlen) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_HEARTBEATS\n if (SSL_IS_DTLS(s)) {\n unsigned int mode;\n if (s->tlsext_heartbeat & SSL_DTLSEXT_HB_DONT_RECV_REQUESTS)\n mode = SSL_DTLSEXT_HB_DONT_SEND_REQUESTS;\n else\n mode = SSL_DTLSEXT_HB_ENABLED;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_heartbeat)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, mode)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n if (s->ctx->next_proto_select_cb && !s->s3->tmp.finish_md_len) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_next_proto_neg)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (s->alpn_client_proto_list && !s->s3->tmp.finish_md_len) {\n if (!WPACKET_put_bytes_u16(pkt,\n TLSEXT_TYPE_application_layer_protocol_negotiation)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_sub_memcpy_u16(pkt, s->alpn_client_proto_list,\n s->alpn_client_proto_list_len)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n s->s3->alpn_sent = 1;\n }\n#ifndef OPENSSL_NO_SRTP\n if (SSL_IS_DTLS(s) && SSL_get_srtp_profiles(s)) {\n STACK_OF(SRTP_PROTECTION_PROFILE) *clnt = 0;\n SRTP_PROTECTION_PROFILE *prof;\n int i, ct;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_use_srtp)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n ct = sk_SRTP_PROTECTION_PROFILE_num(clnt);\n for (i = 0; i < ct; i++) {\n prof = sk_SRTP_PROTECTION_PROFILE_value(clnt, i);\n if (prof == NULL || !WPACKET_put_bytes_u16(pkt, prof->id)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n custom_ext_init(&s->cert->cli_ext);\n if (!custom_ext_add(s, 0, pkt, al)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_encrypt_then_mac)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n#ifndef OPENSSL_NO_CT\n if (s->ct_validation_callback != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signed_certificate_timestamp)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_extended_master_secret)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (s->options & SSL_OP_TLSEXT_PADDING) {\n unsigned char *padbytes;\n size_t hlen;\n if (!WPACKET_get_total_written(pkt, &hlen)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (hlen > 0xff && hlen < 0x200) {\n hlen = 0x200 - hlen;\n if (hlen >= 4)\n hlen -= 4;\n else\n hlen = 0;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_padding)\n || !WPACKET_sub_allocate_bytes_u16(pkt, hlen, &padbytes)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n memset(padbytes, 0, hlen);\n }\n }\n done:\n return 1;\n}', 'int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)\n{\n unsigned char *data;\n assert(size <= sizeof(unsigned int));\n if (size > sizeof(unsigned int)\n || !WPACKET_allocate_bytes(pkt, size, &data)\n || !put_value(data, val, size))\n return 0;\n return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n assert(pkt->subs != NULL);\n if (pkt->subs == NULL)\n return 0;\n sub = OPENSSL_zalloc(sizeof(*sub));\n if (sub == NULL)\n return 0;\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n sub->packet_len = lenchars - (unsigned char *)pkt->buf->data;\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n assert(pkt->subs != NULL && len != 0);\n if (pkt->subs == NULL || len == 0)\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->buf->length - pkt->written < len) {\n size_t newlen;\n if (pkt->buf->length > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = (pkt->buf->length == 0) ? DEFAULT_BUF_SIZE\n : pkt->buf->length * 2;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n *allocbytes = (unsigned char *)pkt->buf->data + pkt->curr;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}']
33,585
0
https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/crypto/ts/ts_rsp_sign.c/#L876
static int ESS_add_signing_cert(PKCS7_SIGNER_INFO *si, ESS_SIGNING_CERT *sc) { ASN1_STRING *seq = NULL; unsigned char *p, *pp = NULL; int len; len = i2d_ESS_SIGNING_CERT(sc, NULL); if ((pp = OPENSSL_malloc(len)) == NULL) { TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE); goto err; } p = pp; i2d_ESS_SIGNING_CERT(sc, &p); if ((seq = ASN1_STRING_new()) == NULL || !ASN1_STRING_set(seq, pp, len)) { TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE); goto err; } OPENSSL_free(pp); pp = NULL; return PKCS7_add_signed_attribute(si, NID_id_smime_aa_signingCertificate, V_ASN1_SEQUENCE, seq); err: ASN1_STRING_free(seq); OPENSSL_free(pp); return 0; }
['static int ESS_add_signing_cert(PKCS7_SIGNER_INFO *si, ESS_SIGNING_CERT *sc)\n{\n ASN1_STRING *seq = NULL;\n unsigned char *p, *pp = NULL;\n int len;\n len = i2d_ESS_SIGNING_CERT(sc, NULL);\n if ((pp = OPENSSL_malloc(len)) == NULL) {\n TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n p = pp;\n i2d_ESS_SIGNING_CERT(sc, &p);\n if ((seq = ASN1_STRING_new()) == NULL || !ASN1_STRING_set(seq, pp, len)) {\n TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n OPENSSL_free(pp);\n pp = NULL;\n return PKCS7_add_signed_attribute(si,\n NID_id_smime_aa_signingCertificate,\n V_ASN1_SEQUENCE, seq);\n err:\n ASN1_STRING_free(seq);\n OPENSSL_free(pp);\n return 0;\n}', 'IMPLEMENT_ASN1_FUNCTIONS_const(ESS_SIGNING_CERT)', '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}', '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}', 'ASN1_STRING *ASN1_STRING_new(void)\n{\n return (ASN1_STRING_type_new(V_ASN1_OCTET_STRING));\n}', 'ASN1_STRING *ASN1_STRING_type_new(int type)\n{\n ASN1_STRING *ret;\n ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->type = type;\n return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', "int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)\n{\n unsigned char *c;\n const char *data = _data;\n if (len < 0) {\n if (data == NULL)\n return (0);\n else\n len = strlen(data);\n }\n if ((str->length < len) || (str->data == NULL)) {\n c = str->data;\n str->data = OPENSSL_realloc(c, len + 1);\n if (str->data == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);\n str->data = c;\n return (0);\n }\n }\n str->length = len;\n if (data != NULL) {\n memcpy(str->data, data, len);\n str->data[len] = '\\0';\n }\n return (1);\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#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}', 'void CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_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}', 'int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,\n void *value)\n{\n return (add_attribute(&(p7si->auth_attr), nid, atrtype, value));\n}', 'static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,\n void *value)\n{\n X509_ATTRIBUTE *attr = NULL;\n if (*sk == NULL) {\n if ((*sk = sk_X509_ATTRIBUTE_new_null()) == NULL)\n return 0;\n new_attrib:\n if ((attr = X509_ATTRIBUTE_create(nid, atrtype, value)) == NULL)\n return 0;\n if (!sk_X509_ATTRIBUTE_push(*sk, attr)) {\n X509_ATTRIBUTE_free(attr);\n return 0;\n }\n } else {\n int i;\n for (i = 0; i < sk_X509_ATTRIBUTE_num(*sk); i++) {\n attr = sk_X509_ATTRIBUTE_value(*sk, i);\n if (OBJ_obj2nid(X509_ATTRIBUTE_get0_object(attr)) == nid) {\n X509_ATTRIBUTE_free(attr);\n attr = X509_ATTRIBUTE_create(nid, atrtype, value);\n if (attr == NULL)\n return 0;\n if (!sk_X509_ATTRIBUTE_set(*sk, i, attr)) {\n X509_ATTRIBUTE_free(attr);\n return 0;\n }\n goto end;\n }\n }\n goto new_attrib;\n }\n end:\n return (1);\n}', '_STACK *sk_new_null(void)\n{\n return sk_new((int (*)(const void *, const void *))0);\n}', '_STACK *sk_new(int (*c) (const void *, const void *))\n{\n _STACK *ret;\n if ((ret = OPENSSL_zalloc(sizeof(_STACK))) == NULL)\n goto err;\n if ((ret->data = OPENSSL_zalloc(sizeof(*ret->data) * MIN_NODES)) == NULL)\n goto err;\n ret->comp = c;\n ret->num_alloc = MIN_NODES;\n return (ret);\n err:\n OPENSSL_free(ret);\n return (NULL);\n}']
33,586
0
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_lib.c/#L231
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return NULL; } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return NULL; } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
["int BN_hex2bn(BIGNUM **bn, const char *a)\n{\n BIGNUM *ret = NULL;\n BN_ULONG l = 0;\n int neg = 0, h, m, i, j, k, c;\n int num;\n if (a == NULL || *a == '\\0')\n return 0;\n if (*a == '-') {\n neg = 1;\n a++;\n }\n for (i = 0; i <= INT_MAX / 4 && ossl_isxdigit(a[i]); i++)\n continue;\n if (i == 0 || i > INT_MAX / 4)\n goto err;\n num = i + neg;\n if (bn == NULL)\n return num;\n if (*bn == NULL) {\n if ((ret = BN_new()) == NULL)\n return 0;\n } else {\n ret = *bn;\n BN_zero(ret);\n }\n if (bn_expand(ret, i * 4) == NULL)\n goto err;\n j = i;\n m = 0;\n h = 0;\n while (j > 0) {\n m = (BN_BYTES * 2 <= j) ? BN_BYTES * 2 : j;\n l = 0;\n for (;;) {\n c = a[j - m];\n k = OPENSSL_hexchar2int(c);\n if (k < 0)\n k = 0;\n l = (l << 4) | k;\n if (--m <= 0) {\n ret->d[h++] = l;\n break;\n }\n }\n j -= BN_BYTES * 2;\n }\n ret->top = h;\n bn_correct_top(ret);\n *bn = ret;\n bn_check_top(ret);\n if (ret->top != 0)\n ret->neg = neg;\n return num;\n err:\n if (*bn == NULL)\n BN_free(ret);\n return 0;\n}", '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}']
33,587
0
https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/lhash/lhash.c/#L122
void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data) { unsigned long hash; OPENSSL_LH_NODE *nn, **rn; void *ret; lh->error = 0; rn = getrn(lh, data, &hash); if (*rn == NULL) { lh->num_no_delete++; return NULL; } else { nn = *rn; *rn = nn->next; ret = nn->data; OPENSSL_free(nn); lh->num_delete++; } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))) contract(lh); return ret; }
['static int server_setup_sni(void)\n{\n SSL_CTX *ctx;\n SSL *con = NULL;\n BIO *rbio;\n BIO *wbio;\n int ret = 0;\n ctx = SSL_CTX_new(TLS_server_method());\n if (!TEST_ptr(ctx))\n goto end;\n con = SSL_new(ctx);\n if (!TEST_ptr(con))\n goto end;\n rbio = BIO_new(BIO_s_mem());\n wbio = BIO_new(BIO_s_mem());\n if (!TEST_ptr(rbio)|| !TEST_ptr(wbio)) {\n BIO_free(rbio);\n BIO_free(wbio);\n goto end;\n }\n SSL_set_bio(con, rbio, wbio);\n SSL_set_tlsext_host_name(con, host);\n if (!TEST_int_le(SSL_accept(con), 0))\n goto end;\n if (!TEST_ptr_null(SSL_get_servername(con, TLSEXT_NAMETYPE_host_name)))\n goto end;\n ret = 1;\nend:\n SSL_free(con);\n SSL_CTX_free(ctx);\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 goto err;\n if (RAND_get_rand_method() == RAND_OpenSSL()) {\n s->drbg = RAND_DRBG_new(NID_aes_128_ctr, RAND_DRBG_FLAG_CTR_USE_DF,\n RAND_DRBG_get0_global());\n if (s->drbg == NULL\n || RAND_DRBG_instantiate(s->drbg, NULL, 0) == 0) {\n CRYPTO_THREAD_lock_free(s->lock);\n goto err;\n }\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 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->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 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 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 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 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 RAND_DRBG_free(s->drbg);\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}']
33,588
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_ctx.c/#L328
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const int p[],\n BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *u;\n bn_check_top(a);\n if (!p[0]) {\n BN_zero(r);\n return 1;\n }\n BN_CTX_start(ctx);\n if ((u = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_set_bit(u, p[0] - 1))\n goto err;\n ret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx);\n bn_check_top(r);\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', '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}']
33,589
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_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 a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (dv != NULL)\n d = dv;\n else\n d = BN_CTX_get(ctx);\n if (rem != NULL)\n r = rem;\n else\n r = BN_CTX_get(ctx);\n if (a == NULL || b == NULL || d == NULL || r == 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}', '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}', '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}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
33,590
0
https://github.com/openssl/openssl/blob/69588edbaa424beb71c6a9b1be416588232cb78c/crypto/sha/sha512.c/#L212
int SHA512_Update(SHA512_CTX *c, const void *_data, size_t len) { SHA_LONG64 l; unsigned char *p = c->u.p; const unsigned char *data = (const unsigned char *)_data; if (len == 0) return 1; l = (c->Nl + (((SHA_LONG64) len) << 3)) & U64(0xffffffffffffffff); if (l < c->Nl) c->Nh++; if (sizeof(len) >= 8) c->Nh += (((SHA_LONG64) len) >> 61); c->Nl = l; if (c->num != 0) { size_t n = sizeof(c->u) - c->num; if (len < n) { memcpy(p + c->num, data, len), c->num += (unsigned int)len; return 1; } else { memcpy(p + c->num, data, n), c->num = 0; len -= n, data += n; sha512_block_data_order(c, p, 1); } } if (len >= sizeof(c->u)) { #ifndef SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA if ((size_t)data % sizeof(c->u.d[0]) != 0) while (len >= sizeof(c->u)) memcpy(p, data, sizeof(c->u)), sha512_block_data_order(c, p, 1), len -= sizeof(c->u), data += sizeof(c->u); else #endif sha512_block_data_order(c, data, len / sizeof(c->u)), data += len, len %= sizeof(c->u), data -= len; } if (len != 0) memcpy(p, data, len), c->num = (int)len; return 1; }
['static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)\n{\n BIGNUM *kinv = NULL;\n BIGNUM *m;\n BIGNUM *xr;\n BN_CTX *ctx = NULL;\n int reason = ERR_R_BN_LIB;\n DSA_SIG *ret = NULL;\n int rv = 0;\n m = BN_new();\n xr = BN_new();\n if (m == NULL || xr == NULL)\n goto err;\n if (!dsa->p || !dsa->q || !dsa->g) {\n reason = DSA_R_MISSING_PARAMETERS;\n goto err;\n }\n ret = DSA_SIG_new();\n if (ret == NULL)\n goto err;\n ret->r = BN_new();\n ret->s = BN_new();\n if (ret->r == NULL || ret->s == NULL)\n goto err;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n redo:\n if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen))\n goto err;\n if (dlen > BN_num_bytes(dsa->q))\n dlen = BN_num_bytes(dsa->q);\n if (BN_bin2bn(dgst, dlen, m) == NULL)\n goto err;\n if (!BN_mod_mul(xr, dsa->priv_key, ret->r, dsa->q, ctx))\n goto err;\n if (!BN_add(ret->s, xr, m))\n goto err;\n if (BN_cmp(ret->s, dsa->q) > 0)\n if (!BN_sub(ret->s, ret->s, dsa->q))\n goto err;\n if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->q, ctx))\n goto err;\n if (BN_is_zero(ret->r) || BN_is_zero(ret->s))\n goto redo;\n rv = 1;\n err:\n if (rv == 0) {\n DSAerr(DSA_F_DSA_DO_SIGN, reason);\n DSA_SIG_free(ret);\n ret = NULL;\n }\n BN_CTX_free(ctx);\n BN_clear_free(m);\n BN_clear_free(xr);\n BN_clear_free(kinv);\n return ret;\n}', 'static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,\n BIGNUM **kinvp, BIGNUM **rp,\n const unsigned char *dgst, int dlen)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *k, *kinv = NULL, *r = *rp;\n int ret = 0;\n if (!dsa->p || !dsa->q || !dsa->g) {\n DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS);\n return 0;\n }\n k = BN_new();\n if (k == NULL)\n goto err;\n if (ctx_in == NULL) {\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n } else\n ctx = ctx_in;\n do {\n if (dgst != NULL) {\n if (!BN_generate_dsa_nonce(k, dsa->q, dsa->priv_key, dgst,\n dlen, ctx))\n goto err;\n } else if (!BN_rand_range(k, dsa->q))\n goto err;\n } while (BN_is_zero(k));\n BN_set_flags(k, BN_FLG_CONSTTIME);\n if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n dsa->lock, dsa->p, ctx))\n goto err;\n }\n if (!BN_add(k, k, dsa->q))\n goto err;\n if (BN_num_bits(k) <= BN_num_bits(dsa->q)) {\n if (!BN_add(k, k, dsa->q))\n goto err;\n }\n if ((dsa)->meth->bn_mod_exp != NULL) {\n if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx,\n dsa->method_mont_p))\n goto err;\n } else {\n if (!BN_mod_exp_mont(r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p))\n goto err;\n }\n if (!BN_mod(r, r, dsa->q, ctx))\n goto err;\n if ((kinv = BN_mod_inverse(NULL, k, dsa->q, ctx)) == NULL)\n goto err;\n BN_clear_free(*kinvp);\n *kinvp = kinv;\n kinv = NULL;\n ret = 1;\n err:\n if (!ret)\n DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n BN_clear_free(k);\n return ret;\n}', 'int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range,\n const BIGNUM *priv, const unsigned char *message,\n size_t message_len, BN_CTX *ctx)\n{\n SHA512_CTX sha;\n unsigned char random_bytes[64];\n unsigned char digest[SHA512_DIGEST_LENGTH];\n unsigned done, todo;\n const unsigned num_k_bytes = BN_num_bytes(range) + 8;\n unsigned char private_bytes[96];\n unsigned char *k_bytes;\n int ret = 0;\n k_bytes = OPENSSL_malloc(num_k_bytes);\n if (k_bytes == NULL)\n goto err;\n todo = sizeof(priv->d[0]) * priv->top;\n if (todo > sizeof(private_bytes)) {\n BNerr(BN_F_BN_GENERATE_DSA_NONCE, BN_R_PRIVATE_KEY_TOO_LARGE);\n goto err;\n }\n memcpy(private_bytes, priv->d, todo);\n memset(private_bytes + todo, 0, sizeof(private_bytes) - todo);\n for (done = 0; done < num_k_bytes;) {\n if (RAND_bytes(random_bytes, sizeof(random_bytes)) != 1)\n goto err;\n SHA512_Init(&sha);\n SHA512_Update(&sha, &done, sizeof(done));\n SHA512_Update(&sha, private_bytes, sizeof(private_bytes));\n SHA512_Update(&sha, message, message_len);\n SHA512_Update(&sha, random_bytes, sizeof(random_bytes));\n SHA512_Final(digest, &sha);\n todo = num_k_bytes - done;\n if (todo > SHA512_DIGEST_LENGTH)\n todo = SHA512_DIGEST_LENGTH;\n memcpy(k_bytes + done, digest, todo);\n done += todo;\n }\n if (!BN_bin2bn(k_bytes, num_k_bytes, out))\n goto err;\n if (BN_mod(out, out, range, ctx) != 1)\n goto err;\n ret = 1;\n err:\n OPENSSL_free(k_bytes);\n return ret;\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}']
33,591
0
https://github.com/openssl/openssl/blob/ec04e866343d40a1e3e8e5db79557e279a2dd0d8/crypto/bn/bn_recp.c/#L115
int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, BN_RECP_CTX *recp, BN_CTX *ctx) { int ret = 0; BIGNUM *a; const BIGNUM *ca; BN_CTX_start(ctx); if ((a = BN_CTX_get(ctx)) == NULL) goto err; if (y != NULL) { if (x == y) { if (!BN_sqr(a, x, ctx)) goto err; } else { if (!BN_mul(a, x, y, ctx)) goto err; } ca = a; } else ca = x; ret = BN_div_recp(NULL, r, ca, recp, ctx); err: BN_CTX_end(ctx); bn_check_top(r); return (ret); }
['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}', '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}', 'static int BN_STACK_push(BN_STACK *st, unsigned int idx)\n{\n if (st->depth == st->size) {\n unsigned int newsize =\n st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES;\n unsigned int *newitems = OPENSSL_malloc(sizeof(*newitems) * newsize);\n if (newitems == NULL)\n return 0;\n if (st->depth)\n memcpy(newitems, st->indexes, sizeof(*newitems) * st->depth);\n OPENSSL_free(st->indexes);\n st->indexes = newitems;\n st->size = newsize;\n }\n st->indexes[(st->depth)++] = idx;\n return 1;\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 CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_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}', '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}']
33,592
0
https://github.com/openssl/openssl/blob/6446e0c3c8286428374ec738ffdc859802bd3c92/apps/apps.c/#L1368
char *make_config_name() { const char *t=X509_get_default_cert_area(); size_t len; char *p; len=strlen(t)+strlen(OPENSSL_CONF)+2; p=OPENSSL_malloc(len); BUF_strlcpy(p,t,len); #ifndef OPENSSL_SYS_VMS BUF_strlcat(p,"/",len); #endif BUF_strlcat(p,OPENSSL_CONF,len); return p; }
['char *make_config_name()\n\t{\n\tconst char *t=X509_get_default_cert_area();\n\tsize_t len;\n\tchar *p;\n\tlen=strlen(t)+strlen(OPENSSL_CONF)+2;\n\tp=OPENSSL_malloc(len);\n\tBUF_strlcpy(p,t,len);\n#ifndef OPENSSL_SYS_VMS\n\tBUF_strlcat(p,"/",len);\n#endif\n\tBUF_strlcat(p,OPENSSL_CONF,len);\n\treturn p;\n\t}', 'const char *X509_get_default_cert_area(void)\n\t{ return(X509_CERT_AREA); }', '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}', 'size_t BUF_strlcat(char *dst, const char *src, size_t size)\n\t{\n\tsize_t l = 0;\n\tfor(; size > 0 && *dst; size--, dst++)\n\t\tl++;\n\treturn l + BUF_strlcpy(dst, src, size);\n\t}']
33,593
0
https://github.com/libav/libav/blob/d0540fd02171a6233d2016b199d013299debf7e3/libavcodec/svq3.c/#L1039
static int svq3_decode_slice_header(AVCodecContext *avctx) { SVQ3Context *s = avctx->priv_data; const int mb_xy = s->mb_xy; int i, header; unsigned slice_id; header = get_bits(&s->gb, 8); if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) { av_log(avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header); return -1; } else { int slice_bits, slice_bytes, slice_length; int length = header >> 5 & 3; slice_length = show_bits(&s->gb, 8 * length); slice_bits = slice_length * 8; slice_bytes = slice_length + length - 1; if (slice_bytes > get_bits_left(&s->gb)) { av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\n"); return -1; } skip_bits(&s->gb, 8); av_fast_malloc(&s->slice_buf, &s->slice_size, slice_bytes + AV_INPUT_BUFFER_PADDING_SIZE); if (!s->slice_buf) return AVERROR(ENOMEM); memcpy(s->slice_buf, s->gb.buffer + s->gb.index / 8, slice_bytes); init_get_bits(&s->gb_slice, s->slice_buf, slice_bits); if (s->watermark_key) { uint32_t header = AV_RL32(&s->gb_slice.buffer[1]); AV_WL32(&s->gb_slice.buffer[1], header ^ s->watermark_key); } if (length > 0) { memcpy(s->slice_buf, &s->slice_buf[slice_length], length - 1); } skip_bits_long(&s->gb, slice_bytes * 8); } if ((slice_id = svq3_get_ue_golomb(&s->gb_slice)) >= 3) { av_log(s->avctx, AV_LOG_ERROR, "illegal slice type %u \n", slice_id); return -1; } s->pict_type = ff_h264_golomb_to_pict_type[slice_id]; if ((header & 0x9F) == 2) { i = (s->mb_num < 64) ? 6 : (1 + av_log2(s->mb_num - 1)); get_bits(&s->gb_slice, i); } else { skip_bits1(&s->gb_slice); } s->slice_num = get_bits(&s->gb_slice, 8); s->qscale = get_bits(&s->gb_slice, 5); s->adaptive_quant = get_bits1(&s->gb_slice); skip_bits1(&s->gb_slice); if (s->unknown_flag) skip_bits1(&s->gb_slice); skip_bits1(&s->gb_slice); skip_bits(&s->gb_slice, 2); while (get_bits1(&s->gb_slice)) skip_bits(&s->gb_slice, 8); if (s->mb_x > 0) { memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - 1] + 3, -1, 4 * sizeof(int8_t)); memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_x], -1, 8 * sizeof(int8_t) * s->mb_x); } if (s->mb_y > 0) { memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_stride], -1, 8 * sizeof(int8_t) * (s->mb_width - s->mb_x)); if (s->mb_x > 0) s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] = -1; } return 0; }
['static int svq3_decode_slice_header(AVCodecContext *avctx)\n{\n SVQ3Context *s = avctx->priv_data;\n const int mb_xy = s->mb_xy;\n int i, header;\n unsigned slice_id;\n header = get_bits(&s->gb, 8);\n if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {\n av_log(avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\\n", header);\n return -1;\n } else {\n int slice_bits, slice_bytes, slice_length;\n int length = header >> 5 & 3;\n slice_length = show_bits(&s->gb, 8 * length);\n slice_bits = slice_length * 8;\n slice_bytes = slice_length + length - 1;\n if (slice_bytes > get_bits_left(&s->gb)) {\n av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\\n");\n return -1;\n }\n skip_bits(&s->gb, 8);\n av_fast_malloc(&s->slice_buf, &s->slice_size, slice_bytes + AV_INPUT_BUFFER_PADDING_SIZE);\n if (!s->slice_buf)\n return AVERROR(ENOMEM);\n memcpy(s->slice_buf, s->gb.buffer + s->gb.index / 8, slice_bytes);\n init_get_bits(&s->gb_slice, s->slice_buf, slice_bits);\n if (s->watermark_key) {\n uint32_t header = AV_RL32(&s->gb_slice.buffer[1]);\n AV_WL32(&s->gb_slice.buffer[1], header ^ s->watermark_key);\n }\n if (length > 0) {\n memcpy(s->slice_buf, &s->slice_buf[slice_length], length - 1);\n }\n skip_bits_long(&s->gb, slice_bytes * 8);\n }\n if ((slice_id = svq3_get_ue_golomb(&s->gb_slice)) >= 3) {\n av_log(s->avctx, AV_LOG_ERROR, "illegal slice type %u \\n", slice_id);\n return -1;\n }\n s->pict_type = ff_h264_golomb_to_pict_type[slice_id];\n if ((header & 0x9F) == 2) {\n i = (s->mb_num < 64) ? 6 : (1 + av_log2(s->mb_num - 1));\n get_bits(&s->gb_slice, i);\n } else {\n skip_bits1(&s->gb_slice);\n }\n s->slice_num = get_bits(&s->gb_slice, 8);\n s->qscale = get_bits(&s->gb_slice, 5);\n s->adaptive_quant = get_bits1(&s->gb_slice);\n skip_bits1(&s->gb_slice);\n if (s->unknown_flag)\n skip_bits1(&s->gb_slice);\n skip_bits1(&s->gb_slice);\n skip_bits(&s->gb_slice, 2);\n while (get_bits1(&s->gb_slice))\n skip_bits(&s->gb_slice, 8);\n if (s->mb_x > 0) {\n memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - 1] + 3,\n -1, 4 * sizeof(int8_t));\n memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_x],\n -1, 8 * sizeof(int8_t) * s->mb_x);\n }\n if (s->mb_y > 0) {\n memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_stride],\n -1, 8 * sizeof(int8_t) * (s->mb_width - s->mb_x));\n if (s->mb_x > 0)\n s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] = -1;\n }\n return 0;\n}', 'static inline int get_bits_left(GetBitContext *gb)\n{\n return gb->size_in_bits - get_bits_count(gb);\n}', 'static inline int get_bits_count(const GetBitContext *s)\n{\n return s->index;\n}', 'void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)\n{\n void **p = ptr;\n if (min_size < *size)\n return;\n min_size = FFMAX(17 * min_size / 16 + 32, min_size);\n av_free(*p);\n *p = av_malloc(min_size);\n if (!*p)\n min_size = 0;\n *size = min_size;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n bit_size = 0;\n buffer = NULL;\n ret = AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n return ret;\n}']
33,594
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_ctx.c/#L328
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)\n{\n int ret = 1;\n bn_check_top(n);\n if ((b->A == NULL) || (b->Ai == NULL)) {\n BNerr(BN_F_BN_BLINDING_CONVERT_EX, BN_R_NOT_INITIALIZED);\n return (0);\n }\n if (b->counter == -1)\n b->counter = 0;\n else if (!BN_BLINDING_update(b, ctx))\n return (0);\n if (r != NULL) {\n if (!BN_copy(r, b->Ai))\n ret = 0;\n }\n if (!BN_mod_mul(n, n, b->A, b->mod, ctx))\n ret = 0;\n return ret;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'void BN_CTX_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_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}', '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}']
33,595
0
https://github.com/libav/libav/blob/fd12dd959305aa80bd2e434cc087f3cabd013242/libavutil/avstring.c/#L88
size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) { int len = strlen(dst); va_list vl; va_start(vl, fmt); len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl); va_end(vl); return len; }
['void ff_rtsp_send_cmd_with_content_async(AVFormatContext *s,\n const char *method, const char *url,\n const char *headers,\n const unsigned char *send_content,\n int send_content_length)\n{\n RTSPState *rt = s->priv_data;\n char buf[4096];\n rt->seq++;\n snprintf(buf, sizeof(buf), "%s %s RTSP/1.0\\r\\n", method, url);\n if (headers)\n av_strlcat(buf, headers, sizeof(buf));\n av_strlcatf(buf, sizeof(buf), "CSeq: %d\\r\\n", rt->seq);\n if (rt->session_id[0] != \'\\0\' && (!headers ||\n !strstr(headers, "\\nIf-Match:"))) {\n av_strlcatf(buf, sizeof(buf), "Session: %s\\r\\n", rt->session_id);\n }\n if (rt->auth[0]) {\n char *str = ff_http_auth_create_response(&rt->auth_state,\n rt->auth, url, method);\n if (str)\n av_strlcat(buf, str, sizeof(buf));\n av_free(str);\n }\n if (send_content_length > 0 && send_content)\n av_strlcatf(buf, sizeof(buf), "Content-Length: %d\\r\\n", send_content_length);\n av_strlcat(buf, "\\r\\n", sizeof(buf));\n dprintf(s, "Sending:\\n%s--\\n", buf);\n url_write(rt->rtsp_hd, buf, strlen(buf));\n if (send_content_length > 0 && send_content)\n url_write(rt->rtsp_hd, send_content, send_content_length);\n rt->last_cmd_time = av_gettime();\n}', 'size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...)\n{\n int len = strlen(dst);\n va_list vl;\n va_start(vl, fmt);\n len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl);\n va_end(vl);\n return len;\n}']
33,596
0
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/idea/i_skey.c/#L128
void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk) { int r; register IDEA_INT *fp, *tp, t; tp = &(dk->data[0][0]); fp = &(ek->data[8][0]); for (r = 0; r < 9; r++) { *(tp++) = inverse(fp[0]); *(tp++) = ((int)(0x10000L - fp[2]) & 0xffff); *(tp++) = ((int)(0x10000L - fp[1]) & 0xffff); *(tp++) = inverse(fp[3]); if (r == 8) break; fp -= 6; *(tp++) = fp[4]; *(tp++) = fp[5]; } tp = &(dk->data[0][0]); t = tp[1]; tp[1] = tp[2]; tp[2] = t; t = tp[49]; tp[49] = tp[50]; tp[50] = t; }
['void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk)\n{\n int r;\n register IDEA_INT *fp, *tp, t;\n tp = &(dk->data[0][0]);\n fp = &(ek->data[8][0]);\n for (r = 0; r < 9; r++) {\n *(tp++) = inverse(fp[0]);\n *(tp++) = ((int)(0x10000L - fp[2]) & 0xffff);\n *(tp++) = ((int)(0x10000L - fp[1]) & 0xffff);\n *(tp++) = inverse(fp[3]);\n if (r == 8)\n break;\n fp -= 6;\n *(tp++) = fp[4];\n *(tp++) = fp[5];\n }\n tp = &(dk->data[0][0]);\n t = tp[1];\n tp[1] = tp[2];\n tp[2] = t;\n t = tp[49];\n tp[49] = tp[50];\n tp[50] = t;\n}']
33,597
0
https://github.com/libav/libav/blob/44594cc7980a4651aba8ac40c59192c283634748/ffmpeg.c/#L3965
static void opt_vstats (void) { char filename[40]; time_t today2 = time(NULL); struct tm *today = localtime(&today2); snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min, today->tm_sec); opt_vstats_file(filename); }
['static void opt_vstats (void)\n{\n char filename[40];\n time_t today2 = time(NULL);\n struct tm *today = localtime(&today2);\n snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,\n today->tm_sec);\n opt_vstats_file(filename);\n}']
33,598
0
https://github.com/openssl/openssl/blob/3cdd1e94b1d71f2ce3002738f9506da91fe2af45/test/evp_test.c/#L1556
static int encode_test_init(struct evp_test *t, const char *encoding) { struct encode_data *edata = OPENSSL_zalloc(sizeof(*edata)); if (strcmp(encoding, "canonical") == 0) { edata->encoding = BASE64_CANONICAL_ENCODING; } else if (strcmp(encoding, "valid") == 0) { edata->encoding = BASE64_VALID_ENCODING; } else if (strcmp(encoding, "invalid") == 0) { edata->encoding = BASE64_INVALID_ENCODING; t->expected_err = BUF_strdup("DECODE_ERROR"); if (t->expected_err == NULL) return 0; } else { fprintf(stderr, "Bad encoding: %s. Should be one of " "{canonical, valid, invalid}\n", encoding); return 0; } t->data = edata; return 1; }
['static int encode_test_init(struct evp_test *t, const char *encoding)\n{\n struct encode_data *edata = OPENSSL_zalloc(sizeof(*edata));\n if (strcmp(encoding, "canonical") == 0) {\n edata->encoding = BASE64_CANONICAL_ENCODING;\n } else if (strcmp(encoding, "valid") == 0) {\n edata->encoding = BASE64_VALID_ENCODING;\n } else if (strcmp(encoding, "invalid") == 0) {\n edata->encoding = BASE64_INVALID_ENCODING;\n t->expected_err = BUF_strdup("DECODE_ERROR");\n if (t->expected_err == NULL)\n return 0;\n } else {\n fprintf(stderr, "Bad encoding: %s. Should be one of "\n "{canonical, valid, invalid}\\n", encoding);\n return 0;\n }\n t->data = edata;\n return 1;\n}', 'void *CRYPTO_zalloc(int 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(int num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n if (allow_customize)\n allow_customize = 0;\n if (malloc_debug_func != NULL) {\n if (allow_customize_debug)\n allow_customize_debug = 0;\n malloc_debug_func(NULL, num, file, line, 0);\n }\n ret = malloc_ex_func(num, file, line);\n#ifdef LEVITTE_DEBUG_MEM\n fprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n if (malloc_debug_func != NULL)\n malloc_debug_func(ret, num, file, line, 1);\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}']
33,599
0
https://github.com/libav/libav/blob/ecf79c4d3e8baaf2f303278ef81db6f8407656bc/libavfilter/video.c/#L158
AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h) { AVFilterBufferRef *ret = NULL; av_unused char buf[16]; FF_DPRINTF_START(NULL, get_video_buffer); ff_dlog_link(NULL, link, 0); av_dlog(NULL, " perms:%s w:%d h:%d\n", ff_get_ref_perms_string(buf, sizeof(buf), perms), w, h); if (link->dstpad->get_video_buffer) ret = link->dstpad->get_video_buffer(link, perms, w, h); if (!ret) ret = ff_default_get_video_buffer(link, perms, w, h); if (ret) ret->type = AVMEDIA_TYPE_VIDEO; FF_DPRINTF_START(NULL, get_video_buffer); ff_dlog_link(NULL, link, 0); av_dlog(NULL, " returning "); ff_dlog_ref(NULL, ret, 1); return ret; }
['AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)\n{\n AVFilterBufferRef *ret = NULL;\n av_unused char buf[16];\n FF_DPRINTF_START(NULL, get_video_buffer); ff_dlog_link(NULL, link, 0);\n av_dlog(NULL, " perms:%s w:%d h:%d\\n", ff_get_ref_perms_string(buf, sizeof(buf), perms), w, h);\n if (link->dstpad->get_video_buffer)\n ret = link->dstpad->get_video_buffer(link, perms, w, h);\n if (!ret)\n ret = ff_default_get_video_buffer(link, perms, w, h);\n if (ret)\n ret->type = AVMEDIA_TYPE_VIDEO;\n FF_DPRINTF_START(NULL, get_video_buffer); ff_dlog_link(NULL, link, 0); av_dlog(NULL, " returning "); ff_dlog_ref(NULL, ret, 1);\n return ret;\n}', 'void ff_dlog_link(void *ctx, AVFilterLink *link, int end)\n{\n if (link->type == AVMEDIA_TYPE_VIDEO) {\n av_dlog(ctx,\n "link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s",\n link, link->w, link->h,\n av_pix_fmt_descriptors[link->format].name,\n link->src ? link->src->filter->name : "",\n link->dst ? link->dst->filter->name : "",\n end ? "\\n" : "");\n } else {\n char buf[128];\n av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);\n av_dlog(ctx,\n "link[%p r:%"PRId64" cl:%s fmt:%-16s %-16s->%-16s]%s",\n link, link->sample_rate, buf,\n av_get_sample_fmt_name(link->format),\n link->src ? link->src->filter->name : "",\n link->dst ? link->dst->filter->name : "",\n end ? "\\n" : "");\n }\n}', 'AVFilterBufferRef *ff_default_get_video_buffer(AVFilterLink *link, int perms, int w, int h)\n{\n int linesize[4];\n uint8_t *data[4];\n AVFilterBufferRef *picref = NULL;\n if (av_image_alloc(data, linesize, w, h, link->format, 16) < 0)\n return NULL;\n picref = avfilter_get_video_buffer_ref_from_arrays(data, linesize,\n perms, w, h, link->format);\n if (!picref) {\n av_free(data[0]);\n return NULL;\n }\n return picref;\n}', 'static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end)\n{\n av_unused char buf[16];\n av_dlog(ctx,\n "ref[%p buf:%p refcount:%d perms:%s data:%p linesize[%d, %d, %d, %d] pts:%"PRId64" pos:%"PRId64,\n ref, ref->buf, ref->buf->refcount, ff_get_ref_perms_string(buf, sizeof(buf), ref->perms), ref->data[0],\n ref->linesize[0], ref->linesize[1], ref->linesize[2], ref->linesize[3],\n ref->pts, ref->pos);\n if (ref->video) {\n av_dlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c",\n ref->video->pixel_aspect.num, ref->video->pixel_aspect.den,\n ref->video->w, ref->video->h,\n !ref->video->interlaced ? \'P\' :\n ref->video->top_field_first ? \'T\' : \'B\',\n ref->video->key_frame,\n av_get_picture_type_char(ref->video->pict_type));\n }\n if (ref->audio) {\n av_dlog(ctx, " cl:%"PRId64"d n:%d r:%d p:%d",\n ref->audio->channel_layout,\n ref->audio->nb_samples,\n ref->audio->sample_rate,\n ref->audio->planar);\n }\n av_dlog(ctx, "]%s", end ? "\\n" : "");\n}']
33,600
0
https://github.com/openssl/openssl/blob/b879882a4b260067bc963807cb6b15b3c75902e8/crypto/init.c/#L380
int ossl_init_thread_start(uint64_t opts) { struct thread_local_inits_st *locals = ossl_init_get_thread_local(1); if (locals == NULL) return 0; if (opts & OPENSSL_INIT_THREAD_ASYNC) { #ifdef OPENSSL_INIT_DEBUG fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: " "marking thread for async\n"); #endif locals->async = 1; } if (opts & OPENSSL_INIT_THREAD_ERR_STATE) { #ifdef OPENSSL_INIT_DEBUG fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: " "marking thread for err_state\n"); #endif locals->err_state = 1; } return 1; }
['int ossl_init_thread_start(uint64_t opts)\n{\n struct thread_local_inits_st *locals = ossl_init_get_thread_local(1);\n if (locals == NULL)\n return 0;\n if (opts & OPENSSL_INIT_THREAD_ASYNC) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for async\\n");\n#endif\n locals->async = 1;\n }\n if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for err_state\\n");\n#endif\n locals->err_state = 1;\n }\n return 1;\n}', 'static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)\n{\n struct thread_local_inits_st *local =\n CRYPTO_THREAD_get_local(&threadstopkey);\n if (local == NULL && alloc) {\n local = OPENSSL_zalloc(sizeof *local);\n CRYPTO_THREAD_set_local(&threadstopkey, local);\n }\n if (!alloc) {\n CRYPTO_THREAD_set_local(&threadstopkey, NULL);\n }\n return local;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)\n{\n if (pthread_setspecific(*key, val) != 0)\n return 0;\n return 1;\n}']