id
int64 1
36.7k
| label
int64 0
1
| bug_url
stringlengths 91
134
| bug_function
stringlengths 13
72.7k
| functions
stringlengths 17
79.2k
|
|---|---|---|---|---|
2,701
| 0
|
https://github.com/openssl/openssl/blob/a68d8c7b77a3d46d591b89cfd0ecd2a2242e4613/test/bntest.c/#L320
|
static int test_modexp_mont5()
{
BIGNUM *a, *p, *m, *d, *e, *b, *n, *c;
BN_MONT_CTX *mont;
a = BN_new();
p = BN_new();
m = BN_new();
d = BN_new();
e = BN_new();
b = BN_new();
n = BN_new();
c = BN_new();
mont = BN_MONT_CTX_new();
BN_bntest_rand(m, 1024, 0, 1);
BN_bntest_rand(a, 1024, 0, 0);
BN_zero(p);
if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
return 0;
if (!BN_is_one(d)) {
printf("Modular exponentiation test failed!\n");
return 0;
}
BN_hex2bn(&a,
"7878787878787878787878787878787878787878787878787878787878787878"
"7878787878787878787878787878787878787878787878787878787878787878"
"7878787878787878787878787878787878787878787878787878787878787878"
"7878787878787878787878787878787878787878787878787878787878787878");
BN_hex2bn(&b,
"095D72C08C097BA488C5E439C655A192EAFB6380073D8C2664668EDDB4060744"
"E16E57FB4EDB9AE10A0CEFCDC28A894F689A128379DB279D48A2E20849D68593"
"9B7803BCF46CEBF5C533FB0DD35B080593DE5472E3FE5DB951B8BFF9B4CB8F03"
"9CC638A5EE8CDD703719F8000E6A9F63BEED5F2FCD52FF293EA05A251BB4AB81");
BN_hex2bn(&n,
"D78AF684E71DB0C39CFF4E64FB9DB567132CB9C50CC98009FEB820B26F2DED9B"
"91B9B5E2B83AE0AE4EB4E0523CA726BFBE969B89FD754F674CE99118C3F2D1C5"
"D81FDC7C54E02B60262B241D53C040E99E45826ECA37A804668E690E1AFC1CA4"
"2C9A15D84D4954425F0B7642FC0BD9D7B24E2618D2DCC9B729D944BADACFDDAF");
BN_MONT_CTX_set(mont, n, ctx);
BN_mod_mul_montgomery(c, a, b, mont, ctx);
BN_mod_mul_montgomery(d, b, a, mont, ctx);
if (BN_cmp(c, d)) {
fprintf(stderr, "Montgomery multiplication test failed:"
" a*b != b*a.\n");
return 0;
}
BN_bntest_rand(p, 1024, 0, 0);
BN_zero(a);
if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
return 0;
if (!BN_is_zero(d)) {
fprintf(stderr, "Modular exponentiation test failed!\n");
return 0;
}
BN_one(a);
BN_MONT_CTX_set(mont, m, ctx);
if (!BN_from_montgomery(e, a, mont, ctx))
return 0;
if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL))
return 0;
if (!BN_mod_exp_simple(a, e, p, m, ctx))
return 0;
if (BN_cmp(a, d) != 0) {
printf("Modular exponentiation test failed!\n");
return 0;
}
BN_bntest_rand(e, 1024, 0, 0);
if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL))
return 0;
if (!BN_mod_exp_simple(a, e, p, m, ctx))
return 0;
if (BN_cmp(a, d) != 0) {
printf("Modular exponentiation test failed!\n");
return 0;
}
BN_MONT_CTX_free(mont);
BN_free(a);
BN_free(p);
BN_free(m);
BN_free(d);
BN_free(e);
BN_free(b);
BN_free(n);
BN_free(c);
return 1;
}
|
['static int test_modexp_mont5()\n{\n BIGNUM *a, *p, *m, *d, *e, *b, *n, *c;\n BN_MONT_CTX *mont;\n a = BN_new();\n p = BN_new();\n m = BN_new();\n d = BN_new();\n e = BN_new();\n b = BN_new();\n n = BN_new();\n c = BN_new();\n mont = BN_MONT_CTX_new();\n BN_bntest_rand(m, 1024, 0, 1);\n BN_bntest_rand(a, 1024, 0, 0);\n BN_zero(p);\n if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))\n return 0;\n if (!BN_is_one(d)) {\n printf("Modular exponentiation test failed!\\n");\n return 0;\n }\n BN_hex2bn(&a,\n "7878787878787878787878787878787878787878787878787878787878787878"\n "7878787878787878787878787878787878787878787878787878787878787878"\n "7878787878787878787878787878787878787878787878787878787878787878"\n "7878787878787878787878787878787878787878787878787878787878787878");\n BN_hex2bn(&b,\n "095D72C08C097BA488C5E439C655A192EAFB6380073D8C2664668EDDB4060744"\n "E16E57FB4EDB9AE10A0CEFCDC28A894F689A128379DB279D48A2E20849D68593"\n "9B7803BCF46CEBF5C533FB0DD35B080593DE5472E3FE5DB951B8BFF9B4CB8F03"\n "9CC638A5EE8CDD703719F8000E6A9F63BEED5F2FCD52FF293EA05A251BB4AB81");\n BN_hex2bn(&n,\n "D78AF684E71DB0C39CFF4E64FB9DB567132CB9C50CC98009FEB820B26F2DED9B"\n "91B9B5E2B83AE0AE4EB4E0523CA726BFBE969B89FD754F674CE99118C3F2D1C5"\n "D81FDC7C54E02B60262B241D53C040E99E45826ECA37A804668E690E1AFC1CA4"\n "2C9A15D84D4954425F0B7642FC0BD9D7B24E2618D2DCC9B729D944BADACFDDAF");\n BN_MONT_CTX_set(mont, n, ctx);\n BN_mod_mul_montgomery(c, a, b, mont, ctx);\n BN_mod_mul_montgomery(d, b, a, mont, ctx);\n if (BN_cmp(c, d)) {\n fprintf(stderr, "Montgomery multiplication test failed:"\n " a*b != b*a.\\n");\n return 0;\n }\n BN_bntest_rand(p, 1024, 0, 0);\n BN_zero(a);\n if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))\n return 0;\n if (!BN_is_zero(d)) {\n fprintf(stderr, "Modular exponentiation test failed!\\n");\n return 0;\n }\n BN_one(a);\n BN_MONT_CTX_set(mont, m, ctx);\n if (!BN_from_montgomery(e, a, mont, ctx))\n return 0;\n if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL))\n return 0;\n if (!BN_mod_exp_simple(a, e, p, m, ctx))\n return 0;\n if (BN_cmp(a, d) != 0) {\n printf("Modular exponentiation test failed!\\n");\n return 0;\n }\n BN_bntest_rand(e, 1024, 0, 0);\n if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL))\n return 0;\n if (!BN_mod_exp_simple(a, e, p, m, ctx))\n return 0;\n if (BN_cmp(a, d) != 0) {\n printf("Modular exponentiation test failed!\\n");\n return 0;\n }\n BN_MONT_CTX_free(mont);\n BN_free(a);\n BN_free(p);\n BN_free(m);\n BN_free(d);\n BN_free(e);\n BN_free(b);\n BN_free(n);\n BN_free(c);\n return 1;\n}', 'BN_MONT_CTX *BN_MONT_CTX_new(void)\n{\n BN_MONT_CTX *ret;\n if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)\n return (NULL);\n BN_MONT_CTX_init(ret);\n ret->flags = BN_FLG_MALLOCED;\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}', 'void BN_MONT_CTX_init(BN_MONT_CTX *ctx)\n{\n ctx->ri = 0;\n bn_init(&(ctx->RR));\n bn_init(&(ctx->N));\n bn_init(&(ctx->Ni));\n ctx->n0[0] = ctx->n0[1] = 0;\n ctx->flags = 0;\n}', 'int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(2, rnd, bits, top, bottom);\n}', 'int BN_is_one(const BIGNUM *a)\n{\n return BN_abs_is_word(a, 1) && !a->neg;\n}', 'int BN_abs_is_word(const BIGNUM *a, const BN_ULONG w)\n{\n return ((a->top == 1) && (a->d[0] == w)) || ((w == 0) && (a->top == 0));\n}']
|
2,702
| 0
|
https://github.com/libav/libav/blob/15201e256035a3e8f9d3d7b96fc327467e1a8ead/libavcodec/vc1_parser.c/#L205
|
static int vc1_parse(AVCodecParserContext *s,
AVCodecContext *avctx,
const uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size)
{
VC1ParseContext *vpc = s->priv_data;
int pic_found = vpc->pc.frame_start_found;
uint8_t *unesc_buffer = vpc->unesc_buffer;
size_t unesc_index = vpc->unesc_index;
VC1ParseSearchState search_state = vpc->search_state;
int next = END_NOT_FOUND;
int i = vpc->bytes_to_skip;
if (pic_found && buf_size == 0) {
memset(unesc_buffer + unesc_index, 0, UNESCAPED_THRESHOLD - unesc_index);
vc1_extract_header(s, avctx, unesc_buffer, unesc_index);
next = 0;
}
while (i < buf_size) {
int start_code_found = 0;
uint8_t b;
while (i < buf_size && unesc_index < UNESCAPED_THRESHOLD) {
b = buf[i++];
unesc_buffer[unesc_index++] = b;
if (search_state <= ONE_ZERO)
search_state = b ? NO_MATCH : search_state + 1;
else if (search_state == TWO_ZEROS) {
if (b == 1)
search_state = ONE;
else if (b > 1) {
if (b == 3)
unesc_index--;
search_state = NO_MATCH;
}
}
else {
search_state = NO_MATCH;
start_code_found = 1;
break;
}
}
if ((s->flags & PARSER_FLAG_COMPLETE_FRAMES) &&
unesc_index >= UNESCAPED_THRESHOLD &&
vpc->prev_start_code == (VC1_CODE_FRAME & 0xFF))
{
vc1_extract_header(s, avctx, unesc_buffer, unesc_index);
break;
}
if (unesc_index >= UNESCAPED_THRESHOLD && !start_code_found) {
while (i < buf_size) {
if (search_state == NO_MATCH) {
i += vpc->v.vc1dsp.startcode_find_candidate(buf + i, buf_size - i);
if (i < buf_size) {
search_state = ONE_ZERO;
}
i++;
} else {
b = buf[i++];
if (search_state == ONE_ZERO)
search_state = b ? NO_MATCH : TWO_ZEROS;
else if (search_state == TWO_ZEROS) {
if (b >= 1)
search_state = b == 1 ? ONE : NO_MATCH;
}
else {
search_state = NO_MATCH;
start_code_found = 1;
break;
}
}
}
}
if (start_code_found) {
vc1_extract_header(s, avctx, unesc_buffer, unesc_index);
vpc->prev_start_code = b;
unesc_index = 0;
if (!(s->flags & PARSER_FLAG_COMPLETE_FRAMES)) {
if (!pic_found && (b == (VC1_CODE_FRAME & 0xFF) || b == (VC1_CODE_FIELD & 0xFF))) {
pic_found = 1;
}
else if (pic_found && b != (VC1_CODE_FIELD & 0xFF) && b != (VC1_CODE_SLICE & 0xFF)) {
next = i - 4;
pic_found = b == (VC1_CODE_FRAME & 0xFF);
break;
}
}
}
}
vpc->pc.frame_start_found = pic_found;
vpc->unesc_index = unesc_index;
vpc->search_state = search_state;
if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
next = buf_size;
} else {
if (ff_combine_frame(&vpc->pc, next, &buf, &buf_size) < 0) {
vpc->bytes_to_skip = 0;
*poutbuf = NULL;
*poutbuf_size = 0;
return buf_size;
}
}
vpc->bytes_to_skip = 4;
if (next < 0)
vpc->bytes_to_skip += next;
*poutbuf = buf;
*poutbuf_size = buf_size;
return next;
}
|
['static int vc1_parse(AVCodecParserContext *s,\n AVCodecContext *avctx,\n const uint8_t **poutbuf, int *poutbuf_size,\n const uint8_t *buf, int buf_size)\n{\n VC1ParseContext *vpc = s->priv_data;\n int pic_found = vpc->pc.frame_start_found;\n uint8_t *unesc_buffer = vpc->unesc_buffer;\n size_t unesc_index = vpc->unesc_index;\n VC1ParseSearchState search_state = vpc->search_state;\n int next = END_NOT_FOUND;\n int i = vpc->bytes_to_skip;\n if (pic_found && buf_size == 0) {\n memset(unesc_buffer + unesc_index, 0, UNESCAPED_THRESHOLD - unesc_index);\n vc1_extract_header(s, avctx, unesc_buffer, unesc_index);\n next = 0;\n }\n while (i < buf_size) {\n int start_code_found = 0;\n uint8_t b;\n while (i < buf_size && unesc_index < UNESCAPED_THRESHOLD) {\n b = buf[i++];\n unesc_buffer[unesc_index++] = b;\n if (search_state <= ONE_ZERO)\n search_state = b ? NO_MATCH : search_state + 1;\n else if (search_state == TWO_ZEROS) {\n if (b == 1)\n search_state = ONE;\n else if (b > 1) {\n if (b == 3)\n unesc_index--;\n search_state = NO_MATCH;\n }\n }\n else {\n search_state = NO_MATCH;\n start_code_found = 1;\n break;\n }\n }\n if ((s->flags & PARSER_FLAG_COMPLETE_FRAMES) &&\n unesc_index >= UNESCAPED_THRESHOLD &&\n vpc->prev_start_code == (VC1_CODE_FRAME & 0xFF))\n {\n vc1_extract_header(s, avctx, unesc_buffer, unesc_index);\n break;\n }\n if (unesc_index >= UNESCAPED_THRESHOLD && !start_code_found) {\n while (i < buf_size) {\n if (search_state == NO_MATCH) {\n i += vpc->v.vc1dsp.startcode_find_candidate(buf + i, buf_size - i);\n if (i < buf_size) {\n search_state = ONE_ZERO;\n }\n i++;\n } else {\n b = buf[i++];\n if (search_state == ONE_ZERO)\n search_state = b ? NO_MATCH : TWO_ZEROS;\n else if (search_state == TWO_ZEROS) {\n if (b >= 1)\n search_state = b == 1 ? ONE : NO_MATCH;\n }\n else {\n search_state = NO_MATCH;\n start_code_found = 1;\n break;\n }\n }\n }\n }\n if (start_code_found) {\n vc1_extract_header(s, avctx, unesc_buffer, unesc_index);\n vpc->prev_start_code = b;\n unesc_index = 0;\n if (!(s->flags & PARSER_FLAG_COMPLETE_FRAMES)) {\n if (!pic_found && (b == (VC1_CODE_FRAME & 0xFF) || b == (VC1_CODE_FIELD & 0xFF))) {\n pic_found = 1;\n }\n else if (pic_found && b != (VC1_CODE_FIELD & 0xFF) && b != (VC1_CODE_SLICE & 0xFF)) {\n next = i - 4;\n pic_found = b == (VC1_CODE_FRAME & 0xFF);\n break;\n }\n }\n }\n }\n vpc->pc.frame_start_found = pic_found;\n vpc->unesc_index = unesc_index;\n vpc->search_state = search_state;\n if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {\n next = buf_size;\n } else {\n if (ff_combine_frame(&vpc->pc, next, &buf, &buf_size) < 0) {\n vpc->bytes_to_skip = 0;\n *poutbuf = NULL;\n *poutbuf_size = 0;\n return buf_size;\n }\n }\n vpc->bytes_to_skip = 4;\n if (next < 0)\n vpc->bytes_to_skip += next;\n *poutbuf = buf;\n *poutbuf_size = buf_size;\n return next;\n}']
|
2,703
| 0
|
https://github.com/openssl/openssl/blob/a8ea8018fa187e22fb4989450b550589e20f62c2/crypto/err/err.c/#L679
|
ERR_STATE *ERR_get_state(void)
{
ERR_STATE *state = NULL;
if (!RUN_ONCE(&err_init, err_do_init))
return NULL;
state = CRYPTO_THREAD_get_local(&err_thread_local);
if (state == NULL) {
state = OPENSSL_zalloc(sizeof(*state));
if (state == NULL)
return NULL;
if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE)
|| !CRYPTO_THREAD_set_local(&err_thread_local, state)) {
ERR_STATE_free(state);
return NULL;
}
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
}
return state;
}
|
['ERR_STATE *ERR_get_state(void)\n{\n ERR_STATE *state = NULL;\n if (!RUN_ONCE(&err_init, err_do_init))\n return NULL;\n state = CRYPTO_THREAD_get_local(&err_thread_local);\n if (state == NULL) {\n state = OPENSSL_zalloc(sizeof(*state));\n if (state == NULL)\n return NULL;\n if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE)\n || !CRYPTO_THREAD_set_local(&err_thread_local, state)) {\n ERR_STATE_free(state);\n return NULL;\n }\n OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n }\n return state;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int ossl_init_thread_start(uint64_t opts)\n{\n struct thread_local_inits_st *locals;\n if (!OPENSSL_init_crypto(0, NULL))\n return 0;\n locals = ossl_init_get_thread_local(1);\n if (locals == NULL)\n return 0;\n if (opts & OPENSSL_INIT_THREAD_ASYNC) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for async\\n");\n#endif\n locals->async = 1;\n }\n if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for err_state\\n");\n#endif\n locals->err_state = 1;\n }\n return 1;\n}']
|
2,704
| 0
|
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L352
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *A, *a = NULL;
const BN_ULONG *B;
int i;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b,BN_FLG_SECURE))
a = A = OPENSSL_secure_malloc(words * sizeof(*a));
else
a = A = OPENSSL_malloc(words * sizeof(*a));
if (A == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
#ifdef PURIFY
memset(a, 0, sizeof(*a) * words);
#endif
#if 1
B = b->d;
if (B != NULL) {
for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
BN_ULONG a0, a1, a2, a3;
a0 = B[0];
a1 = B[1];
a2 = B[2];
a3 = B[3];
A[0] = a0;
A[1] = a1;
A[2] = a2;
A[3] = a3;
}
switch (b->top & 3) {
case 3:
A[2] = B[2];
case 2:
A[1] = B[1];
case 1:
A[0] = B[0];
case 0:
;
}
}
#else
memset(A, 0, sizeof(*A) * words);
memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
return (a);
}
|
['int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *a, *b, *order, *tmp_1, *tmp_2;\n const BIGNUM *p = group->field;\n BN_CTX *new_ctx = NULL;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL) {\n ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT,\n ERR_R_MALLOC_FAILURE);\n goto err;\n }\n }\n BN_CTX_start(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n tmp_1 = BN_CTX_get(ctx);\n tmp_2 = BN_CTX_get(ctx);\n order = BN_CTX_get(ctx);\n if (order == NULL)\n goto err;\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, a, group->a, ctx))\n goto err;\n if (!group->meth->field_decode(group, b, group->b, ctx))\n goto err;\n } else {\n if (!BN_copy(a, group->a))\n goto err;\n if (!BN_copy(b, group->b))\n goto err;\n }\n if (BN_is_zero(a)) {\n if (BN_is_zero(b))\n goto err;\n } else if (!BN_is_zero(b)) {\n if (!BN_mod_sqr(tmp_1, a, p, ctx))\n goto err;\n if (!BN_mod_mul(tmp_2, tmp_1, a, p, ctx))\n goto err;\n if (!BN_lshift(tmp_1, tmp_2, 2))\n goto err;\n if (!BN_mod_sqr(tmp_2, b, p, ctx))\n goto err;\n if (!BN_mul_word(tmp_2, 27))\n goto err;\n if (!BN_mod_add(a, tmp_1, tmp_2, p, ctx))\n goto err;\n if (BN_is_zero(a))\n goto err;\n }\n ret = 1;\n err:\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n int i;\n BN_ULONG *A;\n const BN_ULONG *B;\n bn_check_top(b);\n if (a == b)\n return (a);\n if (bn_wexpand(a, b->top) == NULL)\n return (NULL);\n#if 1\n A = a->d;\n B = b->d;\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:;\n }\n#else\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n#endif\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return (a);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *A, *a = NULL;\n const BN_ULONG *B;\n int i;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b,BN_FLG_SECURE))\n a = A = OPENSSL_secure_malloc(words * sizeof(*a));\n else\n a = A = OPENSSL_malloc(words * sizeof(*a));\n if (A == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n#ifdef PURIFY\n memset(a, 0, sizeof(*a) * words);\n#endif\n#if 1\n B = b->d;\n if (B != NULL) {\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:\n ;\n }\n }\n#else\n memset(A, 0, sizeof(*A) * words);\n memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n return (a);\n}']
|
2,705
| 0
|
https://github.com/libav/libav/blob/44594cc7980a4651aba8ac40c59192c283634748/libavformat/rtsp.c/#L2175
|
static int rtp_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
uint8_t recvbuf[1500];
char host[500], sdp[500];
int ret, port;
URLContext* in = NULL;
int payload_type;
AVCodecContext codec;
struct sockaddr_storage addr;
ByteIOContext pb;
socklen_t addrlen = sizeof(addr);
if (!ff_network_init())
return AVERROR(EIO);
ret = url_open(&in, s->filename, URL_RDONLY);
if (ret)
goto fail;
while (1) {
ret = url_read(in, recvbuf, sizeof(recvbuf));
if (ret == AVERROR(EAGAIN))
continue;
if (ret < 0)
goto fail;
if (ret < 12) {
av_log(s, AV_LOG_WARNING, "Received too short packet\n");
continue;
}
if ((recvbuf[0] & 0xc0) != 0x80) {
av_log(s, AV_LOG_WARNING, "Unsupported RTP version packet "
"received\n");
continue;
}
payload_type = recvbuf[1] & 0x7f;
break;
}
getsockname(url_get_file_handle(in), (struct sockaddr*) &addr, &addrlen);
url_close(in);
in = NULL;
memset(&codec, 0, sizeof(codec));
if (ff_rtp_get_codec_info(&codec, payload_type)) {
av_log(s, AV_LOG_ERROR, "Unable to receive RTP payload type %d "
"without an SDP file describing it\n",
payload_type);
goto fail;
}
if (codec.codec_type != AVMEDIA_TYPE_DATA) {
av_log(s, AV_LOG_WARNING, "Guessing on RTP content - if not received "
"properly you need an SDP file "
"describing it\n");
}
av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port,
NULL, 0, s->filename);
snprintf(sdp, sizeof(sdp),
"v=0\r\nc=IN IP%d %s\r\nm=%s %d RTP/AVP %d\r\n",
addr.ss_family == AF_INET ? 4 : 6, host,
codec.codec_type == AVMEDIA_TYPE_DATA ? "application" :
codec.codec_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio",
port, payload_type);
av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sdp);
init_put_byte(&pb, sdp, strlen(sdp), 0, NULL, NULL, NULL, NULL);
s->pb = &pb;
ff_network_close();
ret = sdp_read_header(s, ap);
s->pb = NULL;
return ret;
fail:
if (in)
url_close(in);
ff_network_close();
return ret;
}
|
['static int rtp_read_header(AVFormatContext *s,\n AVFormatParameters *ap)\n{\n uint8_t recvbuf[1500];\n char host[500], sdp[500];\n int ret, port;\n URLContext* in = NULL;\n int payload_type;\n AVCodecContext codec;\n struct sockaddr_storage addr;\n ByteIOContext pb;\n socklen_t addrlen = sizeof(addr);\n if (!ff_network_init())\n return AVERROR(EIO);\n ret = url_open(&in, s->filename, URL_RDONLY);\n if (ret)\n goto fail;\n while (1) {\n ret = url_read(in, recvbuf, sizeof(recvbuf));\n if (ret == AVERROR(EAGAIN))\n continue;\n if (ret < 0)\n goto fail;\n if (ret < 12) {\n av_log(s, AV_LOG_WARNING, "Received too short packet\\n");\n continue;\n }\n if ((recvbuf[0] & 0xc0) != 0x80) {\n av_log(s, AV_LOG_WARNING, "Unsupported RTP version packet "\n "received\\n");\n continue;\n }\n payload_type = recvbuf[1] & 0x7f;\n break;\n }\n getsockname(url_get_file_handle(in), (struct sockaddr*) &addr, &addrlen);\n url_close(in);\n in = NULL;\n memset(&codec, 0, sizeof(codec));\n if (ff_rtp_get_codec_info(&codec, payload_type)) {\n av_log(s, AV_LOG_ERROR, "Unable to receive RTP payload type %d "\n "without an SDP file describing it\\n",\n payload_type);\n goto fail;\n }\n if (codec.codec_type != AVMEDIA_TYPE_DATA) {\n av_log(s, AV_LOG_WARNING, "Guessing on RTP content - if not received "\n "properly you need an SDP file "\n "describing it\\n");\n }\n av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port,\n NULL, 0, s->filename);\n snprintf(sdp, sizeof(sdp),\n "v=0\\r\\nc=IN IP%d %s\\r\\nm=%s %d RTP/AVP %d\\r\\n",\n addr.ss_family == AF_INET ? 4 : 6, host,\n codec.codec_type == AVMEDIA_TYPE_DATA ? "application" :\n codec.codec_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio",\n port, payload_type);\n av_log(s, AV_LOG_VERBOSE, "SDP:\\n%s\\n", sdp);\n init_put_byte(&pb, sdp, strlen(sdp), 0, NULL, NULL, NULL, NULL);\n s->pb = &pb;\n ff_network_close();\n ret = sdp_read_header(s, ap);\n s->pb = NULL;\n return ret;\nfail:\n if (in)\n url_close(in);\n ff_network_close();\n return ret;\n}']
|
2,706
| 0
|
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/asn1/a_set.c/#L124
|
int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag,
int ex_class, int is_set)
{
int ret=0,r;
int i;
unsigned char *p;
unsigned char *pStart, *pTempMem;
MYBLOB *rgSetBlob;
int totSize;
if (a == NULL) return(0);
for (i=sk_num(a)-1; i>=0; i--)
ret+=func(sk_value(a,i),NULL);
r=ASN1_object_size(1,ret,ex_tag);
if (pp == NULL) return(r);
p= *pp;
ASN1_put_object(&p,1,ret,ex_tag,ex_class);
if(!is_set || (sk_num(a) < 2))
{
for (i=0; i<sk_num(a); i++)
func(sk_value(a,i),&p);
*pp=p;
return(r);
}
pStart = p;
rgSetBlob = (MYBLOB *)Malloc( sk_num(a) * sizeof(MYBLOB));
for (i=0; i<sk_num(a); i++)
{
rgSetBlob[i].pbData = p;
func(sk_value(a,i),&p);
rgSetBlob[i].cbData = p - rgSetBlob[i].pbData;
}
*pp=p;
totSize = p - pStart;
qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp);
pTempMem = Malloc(totSize);
p = pTempMem;
for(i=0; i<sk_num(a); ++i)
{
memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
p += rgSetBlob[i].cbData;
}
memcpy(pStart, pTempMem, totSize);
Free(pTempMem);
Free(rgSetBlob);
return(r);
}
|
['int MAIN(int argc, char **argv)\n{\n char *infile=NULL, *outfile=NULL, *keyname = NULL;\n char *certfile=NULL;\n BIO *in=NULL, *out = NULL, *inkey = NULL, *certsin = NULL;\n char **args;\n char *name = NULL;\n PKCS12 *p12 = NULL;\n char pass[50], macpass[50];\n int export_cert = 0;\n int options = 0;\n int chain = 0;\n int badarg = 0;\n int iter = PKCS12_DEFAULT_ITER;\n int maciter = 1;\n int twopass = 0;\n int keytype = 0;\n int cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;\n int ret = 1;\n int macver = 1;\n int noprompt = 0;\n STACK *canames = NULL;\n char *cpass = NULL, *mpass = NULL;\n apps_startup();\n enc = EVP_des_ede3_cbc();\n if (bio_err == NULL ) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);\n args = argv + 1;\n while (*args) {\n\tif (*args[0] == \'-\') {\n\t\tif (!strcmp (*args, "-nokeys")) options |= NOKEYS;\n\t\telse if (!strcmp (*args, "-keyex")) keytype = KEY_EX;\n\t\telse if (!strcmp (*args, "-keysig")) keytype = KEY_SIG;\n\t\telse if (!strcmp (*args, "-nocerts")) options |= NOCERTS;\n\t\telse if (!strcmp (*args, "-clcerts")) options |= CLCERTS;\n\t\telse if (!strcmp (*args, "-cacerts")) options |= CACERTS;\n\t\telse if (!strcmp (*args, "-noout")) options |= (NOKEYS|NOCERTS);\n\t\telse if (!strcmp (*args, "-info")) options |= INFO;\n\t\telse if (!strcmp (*args, "-chain")) chain = 1;\n\t\telse if (!strcmp (*args, "-twopass")) twopass = 1;\n\t\telse if (!strcmp (*args, "-nomacver")) macver = 0;\n\t\telse if (!strcmp (*args, "-descert"))\n \t\t\tcert_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;\n\t\telse if (!strcmp (*args, "-export")) export_cert = 1;\n\t\telse if (!strcmp (*args, "-des")) enc=EVP_des_cbc();\n#ifndef NO_IDEA\n\t\telse if (!strcmp (*args, "-idea")) enc=EVP_idea_cbc();\n#endif\n\t\telse if (!strcmp (*args, "-des3")) enc = EVP_des_ede3_cbc();\n\t\telse if (!strcmp (*args, "-noiter")) iter = 1;\n\t\telse if (!strcmp (*args, "-maciter"))\n\t\t\t\t\t maciter = PKCS12_DEFAULT_ITER;\n\t\telse if (!strcmp (*args, "-nodes")) enc=NULL;\n\t\telse if (!strcmp (*args, "-inkey")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tkeyname = *args;\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-certfile")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tcertfile = *args;\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-name")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tname = *args;\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-caname")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tif (!canames) canames = sk_new(NULL);\n\t\t\tsk_push(canames, *args);\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-in")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tinfile = *args;\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-out")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\toutfile = *args;\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-envpass")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tif(!(cpass = getenv(*args))) {\n\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t "Can\'t read environment variable %s\\n", *args);\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t\tnoprompt = 1;\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-password")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tcpass = *args;\n\t\t \tnoprompt = 1;\n\t\t } else badarg = 1;\n\t\t} else badarg = 1;\n\t} else badarg = 1;\n\targs++;\n }\n if (badarg) {\n\tBIO_printf (bio_err, "Usage: pkcs12 [options]\\n");\n\tBIO_printf (bio_err, "where options are\\n");\n\tBIO_printf (bio_err, "-export output PKCS12 file\\n");\n\tBIO_printf (bio_err, "-chain add certificate chain\\n");\n\tBIO_printf (bio_err, "-inkey file private key if not infile\\n");\n\tBIO_printf (bio_err, "-certfile f add all certs in f\\n");\n\tBIO_printf (bio_err, "-name \\"name\\" use name as friendly name\\n");\n\tBIO_printf (bio_err, "-caname \\"nm\\" use nm as CA friendly name (can be used more than once).\\n");\n\tBIO_printf (bio_err, "-in infile input filename\\n");\n\tBIO_printf (bio_err, "-out outfile output filename\\n");\n\tBIO_printf (bio_err, "-noout don\'t output anything, just verify.\\n");\n\tBIO_printf (bio_err, "-nomacver don\'t verify MAC.\\n");\n\tBIO_printf (bio_err, "-nocerts don\'t output certificates.\\n");\n\tBIO_printf (bio_err, "-clcerts only output client certificates.\\n");\n\tBIO_printf (bio_err, "-cacerts only output CA certificates.\\n");\n\tBIO_printf (bio_err, "-nokeys don\'t output private keys.\\n");\n\tBIO_printf (bio_err, "-info give info about PKCS#12 structure.\\n");\n\tBIO_printf (bio_err, "-des encrypt private keys with DES\\n");\n\tBIO_printf (bio_err, "-des3 encrypt private keys with triple DES (default)\\n");\n#ifndef NO_IDEA\n\tBIO_printf (bio_err, "-idea encrypt private keys with idea\\n");\n#endif\n\tBIO_printf (bio_err, "-nodes don\'t encrypt private keys\\n");\n\tBIO_printf (bio_err, "-noiter don\'t use encryption iteration\\n");\n\tBIO_printf (bio_err, "-maciter use MAC iteration\\n");\n\tBIO_printf (bio_err, "-twopass separate MAC, encryption passwords\\n");\n\tBIO_printf (bio_err, "-descert encrypt PKCS#12 certificates with triple DES (default RC2-40)\\n");\n\tBIO_printf (bio_err, "-keyex set MS key exchange type\\n");\n\tBIO_printf (bio_err, "-keysig set MS key signature type\\n");\n\tBIO_printf (bio_err, "-password p set import/export password (NOT RECOMMENDED)\\n");\n\tBIO_printf (bio_err, "-envpass p set import/export password from environment\\n");\n \tgoto end;\n }\n if(cpass) mpass = cpass;\n else {\n\tcpass = pass;\n\tmpass = macpass;\n }\n ERR_load_crypto_strings();\n in = BIO_new (BIO_s_file());\n out = BIO_new (BIO_s_file());\n if (!infile) BIO_set_fp (in, stdin, BIO_NOCLOSE);\n else {\n if (BIO_read_filename (in, infile) <= 0) {\n\t perror (infile);\n\t goto end;\n\t}\n }\n if (certfile) {\n \tcertsin = BIO_new (BIO_s_file());\n if (BIO_read_filename (certsin, certfile) <= 0) {\n\t perror (certfile);\n\t goto end;\n\t}\n }\n if (keyname) {\n \tinkey = BIO_new (BIO_s_file());\n if (BIO_read_filename (inkey, keyname) <= 0) {\n\t perror (keyname);\n\t goto end;\n\t}\n }\n if (!outfile) BIO_set_fp (out, stdout, BIO_NOCLOSE);\n else {\n if (BIO_write_filename (out, outfile) <= 0) {\n\t perror (outfile);\n\t goto end;\n\t}\n }\n if (twopass) {\n\tif(EVP_read_pw_string (macpass, 50, "Enter MAC Password:", export_cert)) {\n \t BIO_printf (bio_err, "Can\'t read Password\\n");\n \t goto end;\n \t}\n }\nif (export_cert) {\n\tEVP_PKEY *key;\n\tSTACK *bags, *safes;\n\tPKCS12_SAFEBAG *bag;\n\tPKCS8_PRIV_KEY_INFO *p8;\n\tPKCS7 *authsafe;\n\tX509 *cert, *ucert = NULL;\n\tSTACK *certs;\n\tchar *catmp;\n\tint i, pmatch = 0;\n\tunsigned char keyid[EVP_MAX_MD_SIZE];\n\tunsigned int keyidlen;\n\tkey = PEM_read_bio_PrivateKey(inkey ? inkey : in, NULL, NULL);\n\tif (!inkey) BIO_reset(in);\n\tif (!key) {\n\t\tBIO_printf (bio_err, "Error loading private key\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n\tcerts = sk_new(NULL);\n\tif(!cert_load(in, certs)) {\n\t\tBIO_printf(bio_err, "Error loading certificates from input\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n\tbags = sk_new (NULL);\n\tif (certsin) {\n\t\tif(!cert_load(certsin, certs)) {\n\t\t\tBIO_printf(bio_err, "Error loading certificates from certfile\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t}\n\t \tBIO_free(certsin);\n \t}\n\tfor(i = 0; i < sk_num(certs); i++) {\n\t\t\tcert = (X509 *)sk_value(certs, i);\n\t\t\tif(X509_check_private_key(cert, key)) {\n\t\t\t\tucert = cert;\n\t\t\t\tbreak;\n\t\t\t}\n\t}\n\tif(!ucert) {\n\t\tBIO_printf(bio_err, "No certificate matches private key\\n");\n\t\tgoto end;\n\t}\n\tif (chain) {\n \tint vret;\n\t\tSTACK *chain2;\n\t\tvret = get_cert_chain (ucert, &chain2);\n\t\tif (vret) {\n\t\t\tBIO_printf (bio_err, "Error %s getting chain.\\n",\n\t\t\t\t\tX509_verify_cert_error_string(vret));\n\t\t\tgoto end;\n\t\t}\n\t\tfor (i = 1; i < sk_num (chain2) ; i++)\n\t\t\t\t sk_push(certs, sk_value (chain2, i));\n\t\tsk_free(chain2);\n \t}\n\tfor(i = 0; i < sk_num(certs); i++) {\n\t\tcert = (X509 *)sk_value(certs, i);\n\t\tbag = M_PKCS12_x5092certbag(cert);\n\t\tif(cert == ucert) {\n\t\t\tif(name) PKCS12_add_friendlyname(bag, name, -1);\n\t\t\tX509_digest(cert, EVP_sha1(), keyid, &keyidlen);\n\t\t\tPKCS12_add_localkeyid(bag, keyid, keyidlen);\n\t\t\tpmatch = 1;\n\t\t} else if((catmp = sk_shift(canames)))\n\t\t\t\tPKCS12_add_friendlyname(bag, catmp, -1);\n\t\tsk_push(bags, (char *)bag);\n\t}\n\tif (canames) sk_free(canames);\n\tif(!noprompt &&\n\t\tEVP_read_pw_string(pass, 50, "Enter Export Password:", 1)) {\n\t BIO_printf (bio_err, "Can\'t read Password\\n");\n\t goto end;\n }\n\tif (!twopass) strcpy(macpass, pass);\n\tauthsafe = PKCS12_pack_p7encdata (cert_pbe, cpass, -1, NULL, 0,\n\t\t\t\t\t\t\t\t iter, bags);\n\tsk_pop_free(bags, PKCS12_SAFEBAG_free);\n\tif (!authsafe) {\n\t\tERR_print_errors (bio_err);\n\t\tgoto end;\n\t}\n\tsafes = sk_new (NULL);\n\tsk_push (safes, (char *)authsafe);\n\tp8 = EVP_PKEY2PKCS8 (key);\n\tEVP_PKEY_free(key);\n\tif(keytype) PKCS8_add_keyusage(p8, keytype);\n\tbag = PKCS12_MAKE_SHKEYBAG (NID_pbe_WithSHA1And3_Key_TripleDES_CBC,\n\t\t\tcpass, -1, NULL, 0, iter, p8);\n\tPKCS8_PRIV_KEY_INFO_free(p8);\n if (name) PKCS12_add_friendlyname (bag, name, -1);\n\tif(pmatch) PKCS12_add_localkeyid (bag, keyid, keyidlen);\n\tbags = sk_new(NULL);\n\tsk_push (bags, (char *)bag);\n\tauthsafe = PKCS12_pack_p7data (bags);\n\tsk_pop_free(bags, PKCS12_SAFEBAG_free);\n\tsk_push (safes, (char *)authsafe);\n\tp12 = PKCS12_init (NID_pkcs7_data);\n\tM_PKCS12_pack_authsafes (p12, safes);\n\tsk_pop_free(safes, PKCS7_free);\n\tPKCS12_set_mac (p12, mpass, -1, NULL, 0, maciter, NULL);\n\ti2d_PKCS12_bio (out, p12);\n\tPKCS12_free(p12);\n\tret = 0;\n\tgoto end;\n }\n if (!(p12 = d2i_PKCS12_bio (in, NULL))) {\n\tERR_print_errors(bio_err);\n\tgoto end;\n }\n if(!noprompt && EVP_read_pw_string(pass, 50, "Enter Import Password:", 0)) {\n\tBIO_printf (bio_err, "Can\'t read Password\\n");\n\tgoto end;\n }\n if (!twopass) strcpy(macpass, pass);\n if (options & INFO) BIO_printf (bio_err, "MAC Iteration %ld\\n", p12->mac->iter ? ASN1_INTEGER_get (p12->mac->iter) : 1);\n if(macver) {\n\tif (!PKCS12_verify_mac (p12, mpass, -1)) {\n\t BIO_printf (bio_err, "Mac verify errror: invalid password?\\n");\n\t ERR_print_errors (bio_err);\n\t goto end;\n\t} else BIO_printf (bio_err, "MAC verified OK\\n");\n }\n if (!dump_certs_keys_p12 (out, p12, cpass, -1, options)) {\n\tBIO_printf(bio_err, "Error outputting keys and certificates\\n");\n\tERR_print_errors (bio_err);\n\tgoto end;\n }\n PKCS12_free(p12);\n ret = 0;\n end:\n EXIT(ret);\n}', 'STACK *sk_new(int (*c)())\n\t{\n\tSTACK *ret;\n\tint i;\n\tif ((ret=(STACK *)Malloc(sizeof(STACK))) == NULL)\n\t\tgoto err0;\n\tif ((ret->data=(char **)Malloc(sizeof(char *)*MIN_NODES)) == NULL)\n\t\tgoto err1;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->data[i]=NULL;\n\tret->comp=c;\n\tret->num_alloc=MIN_NODES;\n\tret->num=0;\n\tret->sorted=0;\n\treturn(ret);\nerr1:\n\tFree((char *)ret);\nerr0:\n\treturn(NULL);\n\t}', 'int sk_push(STACK *st, char *data)\n\t{\n\treturn(sk_insert(st,data,st->num));\n\t}', 'int sk_insert(STACK *st, char *data, int loc)\n\t{\n\tchar **s;\n\tif(st == NULL) return 0;\n\tif (st->num_alloc <= st->num+1)\n\t\t{\n\t\ts=(char **)Realloc((char *)st->data,\n\t\t\t(unsigned int)sizeof(char *)*st->num_alloc*2);\n\t\tif (s == NULL)\n\t\t\treturn(0);\n\t\tst->data=s;\n\t\tst->num_alloc*=2;\n\t\t}\n\tif ((loc >= (int)st->num) || (loc < 0))\n\t\tst->data[st->num]=data;\n\telse\n\t\t{\n\t\tint i;\n\t\tchar **f,**t;\n\t\tf=(char **)st->data;\n\t\tt=(char **)&(st->data[1]);\n\t\tfor (i=st->num; i>=loc; i--)\n\t\t\tt[i]=f[i];\n#ifdef undef\n\t\tmemmove( (char *)&(st->data[loc+1]),\n\t\t\t(char *)&(st->data[loc]),\n\t\t\tsizeof(char *)*(st->num-loc));\n#endif\n\t\tst->data[loc]=data;\n\t\t}\n\tst->num++;\n\tst->sorted=0;\n\treturn(st->num);\n\t}', 'void sk_pop_free(STACK *st, void (*func)())\n\t{\n\tint i;\n\tif (st == NULL) return;\n\tfor (i=0; i<st->num; i++)\n\t\tif (st->data[i] != NULL)\n\t\t\tfunc(st->data[i]);\n\tsk_free(st);\n\t}', 'unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,\n\t int *len)\n{\n\tint safelen;\n\tunsigned char *safe, *p;\n\tif (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,\n\t\t\t\t\t V_ASN1_UNIVERSAL, IS_SEQUENCE))) {\n\t\tASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR);\n\t\treturn NULL;\n\t}\n\tif (!(safe = Malloc (safelen))) {\n\t\tASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tp = safe;\n\ti2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,\n\t\t\t\t\t\t\t\t IS_SEQUENCE);\n\tif (len) *len = safelen;\n\tif (buf) *buf = safe;\n\treturn safe;\n}', 'int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag,\n\t int ex_class, int is_set)\n\t{\n\tint ret=0,r;\n\tint i;\n\tunsigned char *p;\n unsigned char *pStart, *pTempMem;\n MYBLOB *rgSetBlob;\n int totSize;\n\tif (a == NULL) return(0);\n\tfor (i=sk_num(a)-1; i>=0; i--)\n\t\tret+=func(sk_value(a,i),NULL);\n\tr=ASN1_object_size(1,ret,ex_tag);\n\tif (pp == NULL) return(r);\n\tp= *pp;\n\tASN1_put_object(&p,1,ret,ex_tag,ex_class);\n\tif(!is_set || (sk_num(a) < 2))\n\t\t{\n\t\tfor (i=0; i<sk_num(a); i++)\n \tfunc(sk_value(a,i),&p);\n\t\t*pp=p;\n\t\treturn(r);\n\t\t}\n pStart = p;\n rgSetBlob = (MYBLOB *)Malloc( sk_num(a) * sizeof(MYBLOB));\n for (i=0; i<sk_num(a); i++)\n\t {\n rgSetBlob[i].pbData = p;\n func(sk_value(a,i),&p);\n rgSetBlob[i].cbData = p - rgSetBlob[i].pbData;\n\t\t}\n *pp=p;\n totSize = p - pStart;\n qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp);\n pTempMem = Malloc(totSize);\n p = pTempMem;\n for(i=0; i<sk_num(a); ++i)\n\t\t{\n memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);\n p += rgSetBlob[i].cbData;\n\t\t}\n memcpy(pStart, pTempMem, totSize);\n Free(pTempMem);\n Free(rgSetBlob);\n return(r);\n }', 'int sk_num(STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}']
|
2,707
| 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)];
}
|
['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("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}']
|
2,708
| 0
|
https://github.com/openssl/openssl/blob/5d99881e6a58a8775b8ca866b794f615a16bb033/crypto/bn/bn_shift.c/#L112
|
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return 0;
r->neg = a->neg;
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return 1;
}
|
['static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)\n{\n BIGNUM *kinv = NULL;\n BIGNUM *m;\n BIGNUM *xr;\n BN_CTX *ctx = NULL;\n int reason = ERR_R_BN_LIB;\n DSA_SIG *ret = NULL;\n int rv = 0;\n m = BN_new();\n xr = BN_new();\n if (m == NULL || xr == NULL)\n goto err;\n if (!dsa->p || !dsa->q || !dsa->g) {\n reason = DSA_R_MISSING_PARAMETERS;\n goto err;\n }\n ret = DSA_SIG_new();\n if (ret == NULL)\n goto err;\n ret->r = BN_new();\n ret->s = BN_new();\n if (ret->r == NULL || ret->s == NULL)\n goto err;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n redo:\n if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen))\n goto err;\n if (dlen > BN_num_bytes(dsa->q))\n dlen = BN_num_bytes(dsa->q);\n if (BN_bin2bn(dgst, dlen, m) == NULL)\n goto err;\n if (!BN_mod_mul(xr, dsa->priv_key, ret->r, dsa->q, ctx))\n goto err;\n if (!BN_add(ret->s, xr, m))\n goto err;\n if (BN_cmp(ret->s, dsa->q) > 0)\n if (!BN_sub(ret->s, ret->s, dsa->q))\n goto err;\n if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->q, ctx))\n goto err;\n if (BN_is_zero(ret->r) || BN_is_zero(ret->s))\n goto redo;\n rv = 1;\n err:\n if (rv == 0) {\n DSAerr(DSA_F_DSA_DO_SIGN, reason);\n DSA_SIG_free(ret);\n ret = NULL;\n }\n BN_CTX_free(ctx);\n BN_clear_free(m);\n BN_clear_free(xr);\n BN_clear_free(kinv);\n return ret;\n}', 'static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,\n BIGNUM **kinvp, BIGNUM **rp,\n const unsigned char *dgst, int dlen)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *k, *kinv = NULL, *r = *rp;\n BIGNUM *l, *m;\n int ret = 0;\n int q_bits;\n if (!dsa->p || !dsa->q || !dsa->g) {\n DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS);\n return 0;\n }\n k = BN_new();\n l = BN_new();\n m = BN_new();\n if (k == NULL || l == NULL || m == NULL)\n goto err;\n if (ctx_in == NULL) {\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n } else\n ctx = ctx_in;\n q_bits = BN_num_bits(dsa->q);\n if (!BN_set_bit(k, q_bits)\n || !BN_set_bit(l, q_bits)\n || !BN_set_bit(m, q_bits))\n goto err;\n do {\n if (dgst != NULL) {\n if (!BN_generate_dsa_nonce(k, dsa->q, dsa->priv_key, dgst,\n dlen, ctx))\n goto err;\n } else if (!BN_priv_rand_range(k, dsa->q))\n goto err;\n } while (BN_is_zero(k));\n BN_set_flags(k, BN_FLG_CONSTTIME);\n if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n dsa->lock, dsa->p, ctx))\n goto err;\n }\n if (!BN_add(l, k, dsa->q)\n || !BN_add(m, l, dsa->q)\n || !BN_copy(k, BN_num_bits(l) > q_bits ? l : m))\n goto err;\n if ((dsa)->meth->bn_mod_exp != NULL) {\n if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx,\n dsa->method_mont_p))\n goto err;\n } else {\n if (!BN_mod_exp_mont(r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p))\n goto err;\n }\n if (!BN_mod(r, r, dsa->q, ctx))\n goto err;\n if ((kinv = BN_mod_inverse(NULL, k, dsa->q, ctx)) == NULL)\n goto err;\n BN_clear_free(*kinvp);\n *kinvp = kinv;\n kinv = NULL;\n ret = 1;\n err:\n if (!ret)\n DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n BN_clear_free(k);\n BN_clear_free(l);\n BN_clear_free(m);\n return ret;\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (BN_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n bn_correct_top(r);\n } else\n#endif\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if (!a->neg) {\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_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}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return 0;\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
2,709
| 0
|
https://github.com/openssl/openssl/blob/ba4f1331e3e96a83144adf5f100b8b5f8f29a2c9/ssl/s3_cbc.c/#L344
|
int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx,
unsigned char *md_out,
size_t *md_out_size,
const unsigned char header[13],
const unsigned char *data,
size_t data_plus_mac_size,
size_t data_plus_mac_plus_padding_size,
const unsigned char *mac_secret,
unsigned mac_secret_length, char is_sslv3)
{
union {
double align;
unsigned char c[sizeof(LARGEST_DIGEST_CTX)];
} md_state;
void (*md_final_raw) (void *ctx, unsigned char *md_out);
void (*md_transform) (void *ctx, const unsigned char *block);
unsigned md_size, md_block_size = 64;
unsigned sslv3_pad_length = 40, header_length, variance_blocks,
len, max_mac_bytes, num_blocks,
num_starting_blocks, k, mac_end_offset, c, index_a, index_b;
unsigned int bits;
unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];
unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];
unsigned char first_block[MAX_HASH_BLOCK_SIZE];
unsigned char mac_out[EVP_MAX_MD_SIZE];
unsigned i, j, md_out_size_u;
EVP_MD_CTX md_ctx;
unsigned md_length_size = 8;
char length_is_big_endian = 1;
int ret;
OPENSSL_assert(data_plus_mac_plus_padding_size < 1024 * 1024);
switch (EVP_MD_CTX_type(ctx)) {
case NID_md5:
if (MD5_Init((MD5_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_md5_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))MD5_Transform;
md_size = 16;
sslv3_pad_length = 48;
length_is_big_endian = 0;
break;
case NID_sha1:
if (SHA1_Init((SHA_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_sha1_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))SHA1_Transform;
md_size = 20;
break;
case NID_sha224:
if (SHA224_Init((SHA256_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_sha256_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))SHA256_Transform;
md_size = 224 / 8;
break;
case NID_sha256:
if (SHA256_Init((SHA256_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_sha256_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))SHA256_Transform;
md_size = 32;
break;
case NID_sha384:
if (SHA384_Init((SHA512_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_sha512_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))SHA512_Transform;
md_size = 384 / 8;
md_block_size = 128;
md_length_size = 16;
break;
case NID_sha512:
if (SHA512_Init((SHA512_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_sha512_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))SHA512_Transform;
md_size = 64;
md_block_size = 128;
md_length_size = 16;
break;
default:
OPENSSL_assert(0);
if (md_out_size)
*md_out_size = -1;
return 0;
}
OPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES);
OPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE);
OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);
header_length = 13;
if (is_sslv3) {
header_length = mac_secret_length + sslv3_pad_length + 8 +
1 +
2 ;
}
variance_blocks = is_sslv3 ? 2 : 6;
len = data_plus_mac_plus_padding_size + header_length;
max_mac_bytes = len - md_size - 1;
num_blocks =
(max_mac_bytes + 1 + md_length_size + md_block_size -
1) / md_block_size;
num_starting_blocks = 0;
k = 0;
mac_end_offset = data_plus_mac_size + header_length - md_size;
c = mac_end_offset % md_block_size;
index_a = mac_end_offset / md_block_size;
index_b = (mac_end_offset + md_length_size) / md_block_size;
if (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0)) {
num_starting_blocks = num_blocks - variance_blocks;
k = md_block_size * num_starting_blocks;
}
bits = 8 * mac_end_offset;
if (!is_sslv3) {
bits += 8 * md_block_size;
memset(hmac_pad, 0, md_block_size);
OPENSSL_assert(mac_secret_length <= sizeof(hmac_pad));
memcpy(hmac_pad, mac_secret, mac_secret_length);
for (i = 0; i < md_block_size; i++)
hmac_pad[i] ^= 0x36;
md_transform(md_state.c, hmac_pad);
}
if (length_is_big_endian) {
memset(length_bytes, 0, md_length_size - 4);
length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24);
length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16);
length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8);
length_bytes[md_length_size - 1] = (unsigned char)bits;
} else {
memset(length_bytes, 0, md_length_size);
length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24);
length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16);
length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8);
length_bytes[md_length_size - 8] = (unsigned char)bits;
}
if (k > 0) {
if (is_sslv3) {
unsigned overhang;
if (header_length <= md_block_size) {
return 0;
}
overhang = header_length - md_block_size;
md_transform(md_state.c, header);
memcpy(first_block, header + md_block_size, overhang);
memcpy(first_block + overhang, data, md_block_size - overhang);
md_transform(md_state.c, first_block);
for (i = 1; i < k / md_block_size - 1; i++)
md_transform(md_state.c, data + md_block_size * i - overhang);
} else {
memcpy(first_block, header, 13);
memcpy(first_block + 13, data, md_block_size - 13);
md_transform(md_state.c, first_block);
for (i = 1; i < k / md_block_size; i++)
md_transform(md_state.c, data + md_block_size * i - 13);
}
}
memset(mac_out, 0, sizeof(mac_out));
for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks;
i++) {
unsigned char block[MAX_HASH_BLOCK_SIZE];
unsigned char is_block_a = constant_time_eq_8(i, index_a);
unsigned char is_block_b = constant_time_eq_8(i, index_b);
for (j = 0; j < md_block_size; j++) {
unsigned char b = 0, is_past_c, is_past_cp1;
if (k < header_length)
b = header[k];
else if (k < data_plus_mac_plus_padding_size + header_length)
b = data[k - header_length];
k++;
is_past_c = is_block_a & constant_time_ge_8(j, c);
is_past_cp1 = is_block_a & constant_time_ge_8(j, c + 1);
b = constant_time_select_8(is_past_c, 0x80, b);
b = b & ~is_past_cp1;
b &= ~is_block_b | is_block_a;
if (j >= md_block_size - md_length_size) {
b = constant_time_select_8(is_block_b,
length_bytes[j -
(md_block_size -
md_length_size)], b);
}
block[j] = b;
}
md_transform(md_state.c, block);
md_final_raw(md_state.c, block);
for (j = 0; j < md_size; j++)
mac_out[j] |= block[j] & is_block_b;
}
EVP_MD_CTX_init(&md_ctx);
if (EVP_DigestInit_ex(&md_ctx, ctx->digest, NULL ) <= 0)
goto err;
if (is_sslv3) {
memset(hmac_pad, 0x5c, sslv3_pad_length);
if (EVP_DigestUpdate(&md_ctx, mac_secret, mac_secret_length) <= 0
|| EVP_DigestUpdate(&md_ctx, hmac_pad, sslv3_pad_length) <= 0
|| EVP_DigestUpdate(&md_ctx, mac_out, md_size) <= 0)
goto err;
} else {
for (i = 0; i < md_block_size; i++)
hmac_pad[i] ^= 0x6a;
if (EVP_DigestUpdate(&md_ctx, hmac_pad, md_block_size) <= 0
|| EVP_DigestUpdate(&md_ctx, mac_out, md_size) <= 0)
goto err;
}
ret = EVP_DigestFinal(&md_ctx, md_out, &md_out_size_u);
if (ret && md_out_size)
*md_out_size = md_out_size_u;
EVP_MD_CTX_cleanup(&md_ctx);
return 1;
err:
EVP_MD_CTX_cleanup(&md_ctx);
return 0;
}
|
['int tls1_mac(SSL *ssl, unsigned char *md, int send)\n{\n SSL3_RECORD *rec;\n unsigned char *seq;\n EVP_MD_CTX *hash;\n size_t md_size;\n int i;\n EVP_MD_CTX hmac, *mac_ctx;\n unsigned char header[13];\n int stream_mac = (send ? (ssl->mac_flags & SSL_MAC_FLAG_WRITE_MAC_STREAM)\n : (ssl->mac_flags & SSL_MAC_FLAG_READ_MAC_STREAM));\n int t;\n if (send) {\n rec = RECORD_LAYER_get_wrec(&ssl->rlayer);\n seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);\n hash = ssl->write_hash;\n } else {\n rec = RECORD_LAYER_get_rrec(&ssl->rlayer);\n seq = RECORD_LAYER_get_read_sequence(&ssl->rlayer);\n hash = ssl->read_hash;\n }\n t = EVP_MD_CTX_size(hash);\n OPENSSL_assert(t >= 0);\n md_size = t;\n if (stream_mac) {\n mac_ctx = hash;\n } else {\n if (!EVP_MD_CTX_copy(&hmac, hash))\n return -1;\n mac_ctx = &hmac;\n }\n if (SSL_IS_DTLS(ssl)) {\n unsigned char dtlsseq[8], *p = dtlsseq;\n s2n(send ? DTLS_RECORD_LAYER_get_w_epoch(&ssl->rlayer) :\n DTLS_RECORD_LAYER_get_r_epoch(&ssl->rlayer), p);\n memcpy(p, &seq[2], 6);\n memcpy(header, dtlsseq, 8);\n } else\n memcpy(header, seq, 8);\n header[8] = rec->type;\n header[9] = (unsigned char)(ssl->version >> 8);\n header[10] = (unsigned char)(ssl->version);\n header[11] = (rec->length) >> 8;\n header[12] = (rec->length) & 0xff;\n if (!send && !SSL_USE_ETM(ssl) &&\n EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n ssl3_cbc_record_digest_supported(mac_ctx)) {\n if (ssl3_cbc_digest_record(mac_ctx,\n md, &md_size,\n header, rec->input,\n rec->length + md_size, rec->orig_len,\n ssl->s3->read_mac_secret,\n ssl->s3->read_mac_secret_size, 0) <= 0) {\n if (!stream_mac)\n EVP_MD_CTX_cleanup(&hmac);\n return -1;\n }\n } else {\n if (EVP_DigestSignUpdate(mac_ctx, header, sizeof(header)) <= 0\n || EVP_DigestSignUpdate(mac_ctx, rec->input, rec->length) <= 0\n || EVP_DigestSignFinal(mac_ctx, md, &md_size) <= 0) {\n if (!stream_mac)\n EVP_MD_CTX_cleanup(&hmac);\n return -1;\n }\n if (!send && !SSL_USE_ETM(ssl) && FIPS_mode())\n tls_fips_digest_extra(ssl->enc_read_ctx,\n mac_ctx, rec->input,\n rec->length, rec->orig_len);\n }\n if (!stream_mac)\n EVP_MD_CTX_cleanup(&hmac);\n#ifdef TLS_DEBUG\n fprintf(stderr, "seq=");\n {\n int z;\n for (z = 0; z < 8; z++)\n fprintf(stderr, "%02X ", seq[z]);\n fprintf(stderr, "\\n");\n }\n fprintf(stderr, "rec=");\n {\n unsigned int z;\n for (z = 0; z < rec->length; z++)\n fprintf(stderr, "%02X ", rec->data[z]);\n fprintf(stderr, "\\n");\n }\n#endif\n if (!SSL_IS_DTLS(ssl)) {\n for (i = 7; i >= 0; i--) {\n ++seq[i];\n if (seq[i] != 0)\n break;\n }\n }\n#ifdef TLS_DEBUG\n {\n unsigned int z;\n for (z = 0; z < md_size; z++)\n fprintf(stderr, "%02X ", md[z]);\n fprintf(stderr, "\\n");\n }\n#endif\n return (md_size);\n}', 'int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx,\n unsigned char *md_out,\n size_t *md_out_size,\n const unsigned char header[13],\n const unsigned char *data,\n size_t data_plus_mac_size,\n size_t data_plus_mac_plus_padding_size,\n const unsigned char *mac_secret,\n unsigned mac_secret_length, char is_sslv3)\n{\n union {\n double align;\n unsigned char c[sizeof(LARGEST_DIGEST_CTX)];\n } md_state;\n void (*md_final_raw) (void *ctx, unsigned char *md_out);\n void (*md_transform) (void *ctx, const unsigned char *block);\n unsigned md_size, md_block_size = 64;\n unsigned sslv3_pad_length = 40, header_length, variance_blocks,\n len, max_mac_bytes, num_blocks,\n num_starting_blocks, k, mac_end_offset, c, index_a, index_b;\n unsigned int bits;\n unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];\n unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];\n unsigned char first_block[MAX_HASH_BLOCK_SIZE];\n unsigned char mac_out[EVP_MAX_MD_SIZE];\n unsigned i, j, md_out_size_u;\n EVP_MD_CTX md_ctx;\n unsigned md_length_size = 8;\n char length_is_big_endian = 1;\n int ret;\n OPENSSL_assert(data_plus_mac_plus_padding_size < 1024 * 1024);\n switch (EVP_MD_CTX_type(ctx)) {\n case NID_md5:\n if (MD5_Init((MD5_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_md5_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))MD5_Transform;\n md_size = 16;\n sslv3_pad_length = 48;\n length_is_big_endian = 0;\n break;\n case NID_sha1:\n if (SHA1_Init((SHA_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha1_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA1_Transform;\n md_size = 20;\n break;\n case NID_sha224:\n if (SHA224_Init((SHA256_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha256_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;\n md_size = 224 / 8;\n break;\n case NID_sha256:\n if (SHA256_Init((SHA256_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha256_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;\n md_size = 32;\n break;\n case NID_sha384:\n if (SHA384_Init((SHA512_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha512_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;\n md_size = 384 / 8;\n md_block_size = 128;\n md_length_size = 16;\n break;\n case NID_sha512:\n if (SHA512_Init((SHA512_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha512_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;\n md_size = 64;\n md_block_size = 128;\n md_length_size = 16;\n break;\n default:\n OPENSSL_assert(0);\n if (md_out_size)\n *md_out_size = -1;\n return 0;\n }\n OPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES);\n OPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE);\n OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);\n header_length = 13;\n if (is_sslv3) {\n header_length = mac_secret_length + sslv3_pad_length + 8 +\n 1 +\n 2 ;\n }\n variance_blocks = is_sslv3 ? 2 : 6;\n len = data_plus_mac_plus_padding_size + header_length;\n max_mac_bytes = len - md_size - 1;\n num_blocks =\n (max_mac_bytes + 1 + md_length_size + md_block_size -\n 1) / md_block_size;\n num_starting_blocks = 0;\n k = 0;\n mac_end_offset = data_plus_mac_size + header_length - md_size;\n c = mac_end_offset % md_block_size;\n index_a = mac_end_offset / md_block_size;\n index_b = (mac_end_offset + md_length_size) / md_block_size;\n if (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0)) {\n num_starting_blocks = num_blocks - variance_blocks;\n k = md_block_size * num_starting_blocks;\n }\n bits = 8 * mac_end_offset;\n if (!is_sslv3) {\n bits += 8 * md_block_size;\n memset(hmac_pad, 0, md_block_size);\n OPENSSL_assert(mac_secret_length <= sizeof(hmac_pad));\n memcpy(hmac_pad, mac_secret, mac_secret_length);\n for (i = 0; i < md_block_size; i++)\n hmac_pad[i] ^= 0x36;\n md_transform(md_state.c, hmac_pad);\n }\n if (length_is_big_endian) {\n memset(length_bytes, 0, md_length_size - 4);\n length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24);\n length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16);\n length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8);\n length_bytes[md_length_size - 1] = (unsigned char)bits;\n } else {\n memset(length_bytes, 0, md_length_size);\n length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24);\n length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16);\n length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8);\n length_bytes[md_length_size - 8] = (unsigned char)bits;\n }\n if (k > 0) {\n if (is_sslv3) {\n unsigned overhang;\n if (header_length <= md_block_size) {\n return 0;\n }\n overhang = header_length - md_block_size;\n md_transform(md_state.c, header);\n memcpy(first_block, header + md_block_size, overhang);\n memcpy(first_block + overhang, data, md_block_size - overhang);\n md_transform(md_state.c, first_block);\n for (i = 1; i < k / md_block_size - 1; i++)\n md_transform(md_state.c, data + md_block_size * i - overhang);\n } else {\n memcpy(first_block, header, 13);\n memcpy(first_block + 13, data, md_block_size - 13);\n md_transform(md_state.c, first_block);\n for (i = 1; i < k / md_block_size; i++)\n md_transform(md_state.c, data + md_block_size * i - 13);\n }\n }\n memset(mac_out, 0, sizeof(mac_out));\n for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks;\n i++) {\n unsigned char block[MAX_HASH_BLOCK_SIZE];\n unsigned char is_block_a = constant_time_eq_8(i, index_a);\n unsigned char is_block_b = constant_time_eq_8(i, index_b);\n for (j = 0; j < md_block_size; j++) {\n unsigned char b = 0, is_past_c, is_past_cp1;\n if (k < header_length)\n b = header[k];\n else if (k < data_plus_mac_plus_padding_size + header_length)\n b = data[k - header_length];\n k++;\n is_past_c = is_block_a & constant_time_ge_8(j, c);\n is_past_cp1 = is_block_a & constant_time_ge_8(j, c + 1);\n b = constant_time_select_8(is_past_c, 0x80, b);\n b = b & ~is_past_cp1;\n b &= ~is_block_b | is_block_a;\n if (j >= md_block_size - md_length_size) {\n b = constant_time_select_8(is_block_b,\n length_bytes[j -\n (md_block_size -\n md_length_size)], b);\n }\n block[j] = b;\n }\n md_transform(md_state.c, block);\n md_final_raw(md_state.c, block);\n for (j = 0; j < md_size; j++)\n mac_out[j] |= block[j] & is_block_b;\n }\n EVP_MD_CTX_init(&md_ctx);\n if (EVP_DigestInit_ex(&md_ctx, ctx->digest, NULL ) <= 0)\n goto err;\n if (is_sslv3) {\n memset(hmac_pad, 0x5c, sslv3_pad_length);\n if (EVP_DigestUpdate(&md_ctx, mac_secret, mac_secret_length) <= 0\n || EVP_DigestUpdate(&md_ctx, hmac_pad, sslv3_pad_length) <= 0\n || EVP_DigestUpdate(&md_ctx, mac_out, md_size) <= 0)\n goto err;\n } else {\n for (i = 0; i < md_block_size; i++)\n hmac_pad[i] ^= 0x6a;\n if (EVP_DigestUpdate(&md_ctx, hmac_pad, md_block_size) <= 0\n || EVP_DigestUpdate(&md_ctx, mac_out, md_size) <= 0)\n goto err;\n }\n ret = EVP_DigestFinal(&md_ctx, md_out, &md_out_size_u);\n if (ret && md_out_size)\n *md_out_size = md_out_size_u;\n EVP_MD_CTX_cleanup(&md_ctx);\n return 1;\nerr:\n EVP_MD_CTX_cleanup(&md_ctx);\n return 0;\n}']
|
2,710
| 0
|
https://github.com/libav/libav/blob/63380b5e54f64abdde4a8b6bce0d60f1fa4a22a1/libavcodec/vorbis_enc.c/#L865
|
static void residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc,
PutBitContext *pb, float *coeffs, int samples,
int real_ch)
{
int pass, i, j, p, k;
int psize = rc->partition_size;
int partitions = (rc->end - rc->begin) / psize;
int channels = (rc->type == 2) ? 1 : real_ch;
int classes[channels][partitions];
int classwords = venc->codebooks[rc->classbook].ndimentions;
assert(rc->type == 2);
assert(real_ch == 2);
for (p = 0; p < partitions; p++) {
float max1 = 0., max2 = 0.;
int s = rc->begin + p * psize;
for (k = s; k < s + psize; k += 2) {
max1 = FFMAX(max1, fabs(coeffs[ k / real_ch]));
max2 = FFMAX(max2, fabs(coeffs[samples + k / real_ch]));
}
for (i = 0; i < rc->classifications - 1; i++)
if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])
break;
classes[0][p] = i;
}
for (pass = 0; pass < 8; pass++) {
p = 0;
while (p < partitions) {
if (pass == 0)
for (j = 0; j < channels; j++) {
vorbis_enc_codebook * book = &venc->codebooks[rc->classbook];
int entry = 0;
for (i = 0; i < classwords; i++) {
entry *= rc->classifications;
entry += classes[j][p + i];
}
put_codeword(pb, book, entry);
}
for (i = 0; i < classwords && p < partitions; i++, p++) {
for (j = 0; j < channels; j++) {
int nbook = rc->books[classes[j][p]][pass];
vorbis_enc_codebook * book = &venc->codebooks[nbook];
float *buf = coeffs + samples*j + rc->begin + p*psize;
if (nbook == -1)
continue;
assert(rc->type == 0 || rc->type == 2);
assert(!(psize % book->ndimentions));
if (rc->type == 0) {
for (k = 0; k < psize; k += book->ndimentions) {
float *a = put_vector(book, pb, &buf[k]);
int l;
for (l = 0; l < book->ndimentions; l++)
buf[k + l] -= a[l];
}
} else {
int s = rc->begin + p * psize, a1, b1;
a1 = (s % real_ch) * samples;
b1 = s / real_ch;
s = real_ch * samples;
for (k = 0; k < psize; k += book->ndimentions) {
int dim, a2 = a1, b2 = b1;
float vec[book->ndimentions], *pv = vec;
for (dim = book->ndimentions; dim--; ) {
*pv++ = coeffs[a2 + b2];
if ((a2 += samples) == s) {
a2 = 0;
b2++;
}
}
pv = put_vector(book, pb, vec);
for (dim = book->ndimentions; dim--; ) {
coeffs[a1 + b1] -= *pv++;
if ((a1 += samples) == s) {
a1 = 0;
b1++;
}
}
}
}
}
}
}
}
}
|
['static void residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc,\n PutBitContext *pb, float *coeffs, int samples,\n int real_ch)\n{\n int pass, i, j, p, k;\n int psize = rc->partition_size;\n int partitions = (rc->end - rc->begin) / psize;\n int channels = (rc->type == 2) ? 1 : real_ch;\n int classes[channels][partitions];\n int classwords = venc->codebooks[rc->classbook].ndimentions;\n assert(rc->type == 2);\n assert(real_ch == 2);\n for (p = 0; p < partitions; p++) {\n float max1 = 0., max2 = 0.;\n int s = rc->begin + p * psize;\n for (k = s; k < s + psize; k += 2) {\n max1 = FFMAX(max1, fabs(coeffs[ k / real_ch]));\n max2 = FFMAX(max2, fabs(coeffs[samples + k / real_ch]));\n }\n for (i = 0; i < rc->classifications - 1; i++)\n if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])\n break;\n classes[0][p] = i;\n }\n for (pass = 0; pass < 8; pass++) {\n p = 0;\n while (p < partitions) {\n if (pass == 0)\n for (j = 0; j < channels; j++) {\n vorbis_enc_codebook * book = &venc->codebooks[rc->classbook];\n int entry = 0;\n for (i = 0; i < classwords; i++) {\n entry *= rc->classifications;\n entry += classes[j][p + i];\n }\n put_codeword(pb, book, entry);\n }\n for (i = 0; i < classwords && p < partitions; i++, p++) {\n for (j = 0; j < channels; j++) {\n int nbook = rc->books[classes[j][p]][pass];\n vorbis_enc_codebook * book = &venc->codebooks[nbook];\n float *buf = coeffs + samples*j + rc->begin + p*psize;\n if (nbook == -1)\n continue;\n assert(rc->type == 0 || rc->type == 2);\n assert(!(psize % book->ndimentions));\n if (rc->type == 0) {\n for (k = 0; k < psize; k += book->ndimentions) {\n float *a = put_vector(book, pb, &buf[k]);\n int l;\n for (l = 0; l < book->ndimentions; l++)\n buf[k + l] -= a[l];\n }\n } else {\n int s = rc->begin + p * psize, a1, b1;\n a1 = (s % real_ch) * samples;\n b1 = s / real_ch;\n s = real_ch * samples;\n for (k = 0; k < psize; k += book->ndimentions) {\n int dim, a2 = a1, b2 = b1;\n float vec[book->ndimentions], *pv = vec;\n for (dim = book->ndimentions; dim--; ) {\n *pv++ = coeffs[a2 + b2];\n if ((a2 += samples) == s) {\n a2 = 0;\n b2++;\n }\n }\n pv = put_vector(book, pb, vec);\n for (dim = book->ndimentions; dim--; ) {\n coeffs[a1 + b1] -= *pv++;\n if ((a1 += samples) == s) {\n a1 = 0;\n b1++;\n }\n }\n }\n }\n }\n }\n }\n }\n}']
|
2,711
| 0
|
https://github.com/libav/libav/blob/41874d0a5df35732367f0c675eac914c23d65aee/ffmpeg.c/#L4067
|
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}']
|
2,712
| 0
|
https://github.com/openssl/openssl/blob/97d5809c2b70fdd240990b940c564bcbd77a19c6/ssl/s3_cbc.c/#L551
|
void ssl3_cbc_digest_record(
const EVP_MD_CTX *ctx,
unsigned char* md_out,
size_t* md_out_size,
const unsigned char header[13],
const unsigned char *data,
size_t data_plus_mac_size,
size_t data_plus_mac_plus_padding_size,
const unsigned char *mac_secret,
unsigned mac_secret_length,
char is_sslv3)
{
union { double align;
unsigned char c[sizeof(LARGEST_DIGEST_CTX)]; } md_state;
void (*md_final_raw)(void *ctx, unsigned char *md_out);
void (*md_transform)(void *ctx, const unsigned char *block);
unsigned md_size, md_block_size = 64;
unsigned sslv3_pad_length = 40, header_length, variance_blocks,
len, max_mac_bytes, num_blocks,
num_starting_blocks, k, mac_end_offset, c, index_a, index_b;
unsigned int bits;
unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];
unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];
unsigned char first_block[MAX_HASH_BLOCK_SIZE];
unsigned char mac_out[EVP_MAX_MD_SIZE];
unsigned i, j, md_out_size_u;
EVP_MD_CTX md_ctx;
unsigned md_length_size = 8;
char length_is_big_endian = 1;
int ret;
OPENSSL_assert(data_plus_mac_plus_padding_size < 1024*1024);
switch (EVP_MD_CTX_type(ctx))
{
case NID_md5:
MD5_Init((MD5_CTX*)md_state.c);
md_final_raw = tls1_md5_final_raw;
md_transform = (void(*)(void *ctx, const unsigned char *block)) MD5_Transform;
md_size = 16;
sslv3_pad_length = 48;
length_is_big_endian = 0;
break;
case NID_sha1:
SHA1_Init((SHA_CTX*)md_state.c);
md_final_raw = tls1_sha1_final_raw;
md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA1_Transform;
md_size = 20;
break;
#ifndef OPENSSL_NO_SHA256
case NID_sha224:
SHA224_Init((SHA256_CTX*)md_state.c);
md_final_raw = tls1_sha256_final_raw;
md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA256_Transform;
md_size = 224/8;
break;
case NID_sha256:
SHA256_Init((SHA256_CTX*)md_state.c);
md_final_raw = tls1_sha256_final_raw;
md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA256_Transform;
md_size = 32;
break;
#endif
#ifndef OPENSSL_NO_SHA512
case NID_sha384:
SHA384_Init((SHA512_CTX*)md_state.c);
md_final_raw = tls1_sha512_final_raw;
md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA512_Transform;
md_size = 384/8;
md_block_size = 128;
md_length_size = 16;
break;
case NID_sha512:
SHA512_Init((SHA512_CTX*)md_state.c);
md_final_raw = tls1_sha512_final_raw;
md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA512_Transform;
md_size = 64;
md_block_size = 128;
md_length_size = 16;
break;
#endif
default:
OPENSSL_assert(0);
if (md_out_size)
*md_out_size = -1;
return;
}
OPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES);
OPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE);
OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);
header_length = 13;
if (is_sslv3)
{
header_length =
mac_secret_length +
sslv3_pad_length +
8 +
1 +
2 ;
}
variance_blocks = is_sslv3 ? 2 : 6;
len = data_plus_mac_plus_padding_size + header_length;
max_mac_bytes = len - md_size - 1;
num_blocks = (max_mac_bytes + 1 + md_length_size + md_block_size - 1) / md_block_size;
num_starting_blocks = 0;
k = 0;
mac_end_offset = data_plus_mac_size + header_length - md_size;
c = mac_end_offset % md_block_size;
index_a = mac_end_offset / md_block_size;
index_b = (mac_end_offset + md_length_size) / md_block_size;
if (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0))
{
num_starting_blocks = num_blocks - variance_blocks;
k = md_block_size*num_starting_blocks;
}
bits = 8*mac_end_offset;
if (!is_sslv3)
{
bits += 8*md_block_size;
memset(hmac_pad, 0, md_block_size);
OPENSSL_assert(mac_secret_length <= sizeof(hmac_pad));
memcpy(hmac_pad, mac_secret, mac_secret_length);
for (i = 0; i < md_block_size; i++)
hmac_pad[i] ^= 0x36;
md_transform(md_state.c, hmac_pad);
}
if (length_is_big_endian)
{
memset(length_bytes,0,md_length_size-4);
length_bytes[md_length_size-4] = (unsigned char)(bits>>24);
length_bytes[md_length_size-3] = (unsigned char)(bits>>16);
length_bytes[md_length_size-2] = (unsigned char)(bits>>8);
length_bytes[md_length_size-1] = (unsigned char)bits;
}
else
{
memset(length_bytes,0,md_length_size);
length_bytes[md_length_size-5] = (unsigned char)(bits>>24);
length_bytes[md_length_size-6] = (unsigned char)(bits>>16);
length_bytes[md_length_size-7] = (unsigned char)(bits>>8);
length_bytes[md_length_size-8] = (unsigned char)bits;
}
if (k > 0)
{
if (is_sslv3)
{
unsigned overhang = header_length-md_block_size;
md_transform(md_state.c, header);
memcpy(first_block, header + md_block_size, overhang);
memcpy(first_block + overhang, data, md_block_size-overhang);
md_transform(md_state.c, first_block);
for (i = 1; i < k/md_block_size - 1; i++)
md_transform(md_state.c, data + md_block_size*i - overhang);
}
else
{
memcpy(first_block, header, 13);
memcpy(first_block+13, data, md_block_size-13);
md_transform(md_state.c, first_block);
for (i = 1; i < k/md_block_size; i++)
md_transform(md_state.c, data + md_block_size*i - 13);
}
}
memset(mac_out, 0, sizeof(mac_out));
for (i = num_starting_blocks; i <= num_starting_blocks+variance_blocks; i++)
{
unsigned char block[MAX_HASH_BLOCK_SIZE];
unsigned char is_block_a = constant_time_eq_8(i, index_a);
unsigned char is_block_b = constant_time_eq_8(i, index_b);
for (j = 0; j < md_block_size; j++)
{
unsigned char b = 0, is_past_c, is_past_cp1;
if (k < header_length)
b = header[k];
else if (k < data_plus_mac_plus_padding_size + header_length)
b = data[k-header_length];
k++;
is_past_c = is_block_a & constant_time_ge_8(j, c);
is_past_cp1 = is_block_a & constant_time_ge_8(j, c+1);
b = constant_time_select_8(is_past_c, 0x80, b);
b = b&~is_past_cp1;
b &= ~is_block_b | is_block_a;
if (j >= md_block_size - md_length_size)
{
b = constant_time_select_8(
is_block_b, length_bytes[j-(md_block_size-md_length_size)], b);
}
block[j] = b;
}
md_transform(md_state.c, block);
md_final_raw(md_state.c, block);
for (j = 0; j < md_size; j++)
mac_out[j] |= block[j]&is_block_b;
}
EVP_MD_CTX_init(&md_ctx);
EVP_DigestInit_ex(&md_ctx, ctx->digest, NULL );
if (is_sslv3)
{
memset(hmac_pad, 0x5c, sslv3_pad_length);
EVP_DigestUpdate(&md_ctx, mac_secret, mac_secret_length);
EVP_DigestUpdate(&md_ctx, hmac_pad, sslv3_pad_length);
EVP_DigestUpdate(&md_ctx, mac_out, md_size);
}
else
{
for (i = 0; i < md_block_size; i++)
hmac_pad[i] ^= 0x6a;
EVP_DigestUpdate(&md_ctx, hmac_pad, md_block_size);
EVP_DigestUpdate(&md_ctx, mac_out, md_size);
}
ret = EVP_DigestFinal(&md_ctx, md_out, &md_out_size_u);
if (ret && md_out_size)
*md_out_size = md_out_size_u;
EVP_MD_CTX_cleanup(&md_ctx);
}
|
['int n_ssl3_mac(SSL *ssl, unsigned char *md, int send)\n\t{\n\tSSL3_RECORD *rec;\n\tunsigned char *mac_sec,*seq;\n\tEVP_MD_CTX md_ctx;\n\tconst EVP_MD_CTX *hash;\n\tunsigned char *p,rec_char;\n\tsize_t md_size;\n\tint npad;\n\tint t;\n\tif (send)\n\t\t{\n\t\trec= &(ssl->s3->wrec);\n\t\tmac_sec= &(ssl->s3->write_mac_secret[0]);\n\t\tseq= &(ssl->s3->write_sequence[0]);\n\t\thash=ssl->write_hash;\n\t\t}\n\telse\n\t\t{\n\t\trec= &(ssl->s3->rrec);\n\t\tmac_sec= &(ssl->s3->read_mac_secret[0]);\n\t\tseq= &(ssl->s3->read_sequence[0]);\n\t\thash=ssl->read_hash;\n\t\t}\n\tt=EVP_MD_CTX_size(hash);\n\tif (t < 0)\n\t\treturn -1;\n\tmd_size=t;\n\tnpad=(48/md_size)*md_size;\n\tif (!send &&\n\t EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n\t ssl3_cbc_record_digest_supported(hash))\n\t\t{\n\t\tunsigned char header[75];\n\t\tunsigned j = 0;\n\t\tmemcpy(header+j, mac_sec, md_size);\n\t\tj += md_size;\n\t\tmemcpy(header+j, ssl3_pad_1, npad);\n\t\tj += npad;\n\t\tmemcpy(header+j, seq, 8);\n\t\tj += 8;\n\t\theader[j++] = rec->type;\n\t\theader[j++] = rec->length >> 8;\n\t\theader[j++] = rec->length & 0xff;\n\t\tssl3_cbc_digest_record(\n\t\t\thash,\n\t\t\tmd, &md_size,\n\t\t\theader, rec->input,\n\t\t\trec->length + md_size, rec->orig_len,\n\t\t\tmac_sec, md_size,\n\t\t\t1 );\n\t\t}\n\telse\n\t\t{\n\t\tunsigned int md_size_u;\n\t\tEVP_MD_CTX_init(&md_ctx);\n\t\tEVP_MD_CTX_copy_ex( &md_ctx,hash);\n\t\tEVP_DigestUpdate(&md_ctx,mac_sec,md_size);\n\t\tEVP_DigestUpdate(&md_ctx,ssl3_pad_1,npad);\n\t\tEVP_DigestUpdate(&md_ctx,seq,8);\n\t\trec_char=rec->type;\n\t\tEVP_DigestUpdate(&md_ctx,&rec_char,1);\n\t\tp=md;\n\t\ts2n(rec->length,p);\n\t\tEVP_DigestUpdate(&md_ctx,md,2);\n\t\tEVP_DigestUpdate(&md_ctx,rec->input,rec->length);\n\t\tEVP_DigestFinal_ex( &md_ctx,md,NULL);\n\t\tEVP_MD_CTX_copy_ex( &md_ctx,hash);\n\t\tEVP_DigestUpdate(&md_ctx,mac_sec,md_size);\n\t\tEVP_DigestUpdate(&md_ctx,ssl3_pad_2,npad);\n\t\tEVP_DigestUpdate(&md_ctx,md,md_size);\n\t\tEVP_DigestFinal_ex( &md_ctx,md,&md_size_u);\n\t\tmd_size = md_size_u;\n\t\tEVP_MD_CTX_cleanup(&md_ctx);\n\t}\n\tssl3_record_sequence_update(seq);\n\treturn(md_size);\n\t}', 'void ssl3_cbc_digest_record(\n\tconst EVP_MD_CTX *ctx,\n\tunsigned char* md_out,\n\tsize_t* md_out_size,\n\tconst unsigned char header[13],\n\tconst unsigned char *data,\n\tsize_t data_plus_mac_size,\n\tsize_t data_plus_mac_plus_padding_size,\n\tconst unsigned char *mac_secret,\n\tunsigned mac_secret_length,\n\tchar is_sslv3)\n\t{\n\tunion {\tdouble align;\n\t\tunsigned char c[sizeof(LARGEST_DIGEST_CTX)]; } md_state;\n\tvoid (*md_final_raw)(void *ctx, unsigned char *md_out);\n\tvoid (*md_transform)(void *ctx, const unsigned char *block);\n\tunsigned md_size, md_block_size = 64;\n\tunsigned sslv3_pad_length = 40, header_length, variance_blocks,\n\t\t len, max_mac_bytes, num_blocks,\n\t\t num_starting_blocks, k, mac_end_offset, c, index_a, index_b;\n\tunsigned int bits;\n\tunsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];\n\tunsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];\n\tunsigned char first_block[MAX_HASH_BLOCK_SIZE];\n\tunsigned char mac_out[EVP_MAX_MD_SIZE];\n\tunsigned i, j, md_out_size_u;\n\tEVP_MD_CTX md_ctx;\n\tunsigned md_length_size = 8;\n\tchar length_is_big_endian = 1;\n\tint ret;\n\tOPENSSL_assert(data_plus_mac_plus_padding_size < 1024*1024);\n\tswitch (EVP_MD_CTX_type(ctx))\n\t\t{\n\t\tcase NID_md5:\n\t\t\tMD5_Init((MD5_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_md5_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) MD5_Transform;\n\t\t\tmd_size = 16;\n\t\t\tsslv3_pad_length = 48;\n\t\t\tlength_is_big_endian = 0;\n\t\t\tbreak;\n\t\tcase NID_sha1:\n\t\t\tSHA1_Init((SHA_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_sha1_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) SHA1_Transform;\n\t\t\tmd_size = 20;\n\t\t\tbreak;\n#ifndef OPENSSL_NO_SHA256\n\t\tcase NID_sha224:\n\t\t\tSHA224_Init((SHA256_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_sha256_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) SHA256_Transform;\n\t\t\tmd_size = 224/8;\n\t\t\tbreak;\n\t\tcase NID_sha256:\n\t\t\tSHA256_Init((SHA256_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_sha256_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) SHA256_Transform;\n\t\t\tmd_size = 32;\n\t\t\tbreak;\n#endif\n#ifndef OPENSSL_NO_SHA512\n\t\tcase NID_sha384:\n\t\t\tSHA384_Init((SHA512_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_sha512_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) SHA512_Transform;\n\t\t\tmd_size = 384/8;\n\t\t\tmd_block_size = 128;\n\t\t\tmd_length_size = 16;\n\t\t\tbreak;\n\t\tcase NID_sha512:\n\t\t\tSHA512_Init((SHA512_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_sha512_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) SHA512_Transform;\n\t\t\tmd_size = 64;\n\t\t\tmd_block_size = 128;\n\t\t\tmd_length_size = 16;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tOPENSSL_assert(0);\n\t\t\tif (md_out_size)\n\t\t\t\t*md_out_size = -1;\n\t\t\treturn;\n\t\t}\n\tOPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES);\n\tOPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE);\n\tOPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);\n\theader_length = 13;\n\tif (is_sslv3)\n\t\t{\n\t\theader_length =\n\t\t\tmac_secret_length +\n\t\t\tsslv3_pad_length +\n\t\t\t8 +\n\t\t\t1 +\n\t\t\t2 ;\n\t\t}\n\tvariance_blocks = is_sslv3 ? 2 : 6;\n\tlen = data_plus_mac_plus_padding_size + header_length;\n\tmax_mac_bytes = len - md_size - 1;\n\tnum_blocks = (max_mac_bytes + 1 + md_length_size + md_block_size - 1) / md_block_size;\n\tnum_starting_blocks = 0;\n\tk = 0;\n\tmac_end_offset = data_plus_mac_size + header_length - md_size;\n\tc = mac_end_offset % md_block_size;\n\tindex_a = mac_end_offset / md_block_size;\n\tindex_b = (mac_end_offset + md_length_size) / md_block_size;\n\tif (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0))\n\t\t{\n\t\tnum_starting_blocks = num_blocks - variance_blocks;\n\t\tk = md_block_size*num_starting_blocks;\n\t\t}\n\tbits = 8*mac_end_offset;\n\tif (!is_sslv3)\n\t\t{\n\t\tbits += 8*md_block_size;\n\t\tmemset(hmac_pad, 0, md_block_size);\n\t\tOPENSSL_assert(mac_secret_length <= sizeof(hmac_pad));\n\t\tmemcpy(hmac_pad, mac_secret, mac_secret_length);\n\t\tfor (i = 0; i < md_block_size; i++)\n\t\t\thmac_pad[i] ^= 0x36;\n\t\tmd_transform(md_state.c, hmac_pad);\n\t\t}\n\tif (length_is_big_endian)\n\t\t{\n\t\tmemset(length_bytes,0,md_length_size-4);\n\t\tlength_bytes[md_length_size-4] = (unsigned char)(bits>>24);\n\t\tlength_bytes[md_length_size-3] = (unsigned char)(bits>>16);\n\t\tlength_bytes[md_length_size-2] = (unsigned char)(bits>>8);\n\t\tlength_bytes[md_length_size-1] = (unsigned char)bits;\n\t\t}\n\telse\n\t\t{\n\t\tmemset(length_bytes,0,md_length_size);\n\t\tlength_bytes[md_length_size-5] = (unsigned char)(bits>>24);\n\t\tlength_bytes[md_length_size-6] = (unsigned char)(bits>>16);\n\t\tlength_bytes[md_length_size-7] = (unsigned char)(bits>>8);\n\t\tlength_bytes[md_length_size-8] = (unsigned char)bits;\n\t\t}\n\tif (k > 0)\n\t\t{\n\t\tif (is_sslv3)\n\t\t\t{\n\t\t\tunsigned overhang = header_length-md_block_size;\n\t\t\tmd_transform(md_state.c, header);\n\t\t\tmemcpy(first_block, header + md_block_size, overhang);\n\t\t\tmemcpy(first_block + overhang, data, md_block_size-overhang);\n\t\t\tmd_transform(md_state.c, first_block);\n\t\t\tfor (i = 1; i < k/md_block_size - 1; i++)\n\t\t\t\tmd_transform(md_state.c, data + md_block_size*i - overhang);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tmemcpy(first_block, header, 13);\n\t\t\tmemcpy(first_block+13, data, md_block_size-13);\n\t\t\tmd_transform(md_state.c, first_block);\n\t\t\tfor (i = 1; i < k/md_block_size; i++)\n\t\t\t\tmd_transform(md_state.c, data + md_block_size*i - 13);\n\t\t\t}\n\t\t}\n\tmemset(mac_out, 0, sizeof(mac_out));\n\tfor (i = num_starting_blocks; i <= num_starting_blocks+variance_blocks; i++)\n\t\t{\n\t\tunsigned char block[MAX_HASH_BLOCK_SIZE];\n\t\tunsigned char is_block_a = constant_time_eq_8(i, index_a);\n\t\tunsigned char is_block_b = constant_time_eq_8(i, index_b);\n\t\tfor (j = 0; j < md_block_size; j++)\n\t\t\t{\n\t\t\tunsigned char b = 0, is_past_c, is_past_cp1;\n\t\t\tif (k < header_length)\n\t\t\t\tb = header[k];\n\t\t\telse if (k < data_plus_mac_plus_padding_size + header_length)\n\t\t\t\tb = data[k-header_length];\n\t\t\tk++;\n\t\t\tis_past_c = is_block_a & constant_time_ge_8(j, c);\n\t\t\tis_past_cp1 = is_block_a & constant_time_ge_8(j, c+1);\n b = constant_time_select_8(is_past_c, 0x80, b);\n\t\t\tb = b&~is_past_cp1;\n\t\t\tb &= ~is_block_b | is_block_a;\n\t\t\tif (j >= md_block_size - md_length_size)\n\t\t\t\t{\n\t\t\t\tb = constant_time_select_8(\n\t\t\t\t\tis_block_b, length_bytes[j-(md_block_size-md_length_size)], b);\n\t\t\t\t}\n\t\t\tblock[j] = b;\n\t\t\t}\n\t\tmd_transform(md_state.c, block);\n\t\tmd_final_raw(md_state.c, block);\n\t\tfor (j = 0; j < md_size; j++)\n\t\t\tmac_out[j] |= block[j]&is_block_b;\n\t\t}\n\tEVP_MD_CTX_init(&md_ctx);\n\tEVP_DigestInit_ex(&md_ctx, ctx->digest, NULL );\n\tif (is_sslv3)\n\t\t{\n\t\tmemset(hmac_pad, 0x5c, sslv3_pad_length);\n\t\tEVP_DigestUpdate(&md_ctx, mac_secret, mac_secret_length);\n\t\tEVP_DigestUpdate(&md_ctx, hmac_pad, sslv3_pad_length);\n\t\tEVP_DigestUpdate(&md_ctx, mac_out, md_size);\n\t\t}\n\telse\n\t\t{\n\t\tfor (i = 0; i < md_block_size; i++)\n\t\t\thmac_pad[i] ^= 0x6a;\n\t\tEVP_DigestUpdate(&md_ctx, hmac_pad, md_block_size);\n\t\tEVP_DigestUpdate(&md_ctx, mac_out, md_size);\n\t\t}\n\tret = EVP_DigestFinal(&md_ctx, md_out, &md_out_size_u);\n\tif (ret && md_out_size)\n\t\t*md_out_size = md_out_size_u;\n\tEVP_MD_CTX_cleanup(&md_ctx);\n\t}']
|
2,713
| 0
|
https://github.com/openssl/openssl/blob/80aa9cc985251463a3ad65b0a4d64bf93c70b175/ssl/ssl_lib.c/#L1375
|
STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
STACK_OF(SSL_CIPHER) **skp)
{
const SSL_CIPHER *c;
STACK_OF(SSL_CIPHER) *sk;
int i,n;
n=ssl_put_cipher_by_char(s,NULL,NULL);
if ((num%n) != 0)
{
SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
return(NULL);
}
if ((skp == NULL) || (*skp == NULL))
sk=sk_SSL_CIPHER_new_null();
else
{
sk= *skp;
sk_SSL_CIPHER_zero(sk);
}
for (i=0; i<num; i+=n)
{
c=ssl_get_cipher_by_char(s,p);
p+=n;
if (c != NULL)
{
if (!sk_SSL_CIPHER_push(sk,c))
{
SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
goto err;
}
}
}
if (skp != NULL)
*skp=sk;
return(sk);
err:
if ((skp == NULL) || (*skp == NULL))
sk_SSL_CIPHER_free(sk);
return(NULL);
}
|
['STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,\n\t\t\t\t\t STACK_OF(SSL_CIPHER) **skp)\n\t{\n\tconst SSL_CIPHER *c;\n\tSTACK_OF(SSL_CIPHER) *sk;\n\tint i,n;\n\tn=ssl_put_cipher_by_char(s,NULL,NULL);\n\tif ((num%n) != 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);\n\t\treturn(NULL);\n\t\t}\n\tif ((skp == NULL) || (*skp == NULL))\n\t\tsk=sk_SSL_CIPHER_new_null();\n\telse\n\t\t{\n\t\tsk= *skp;\n\t\tsk_SSL_CIPHER_zero(sk);\n\t\t}\n\tfor (i=0; i<num; i+=n)\n\t\t{\n\t\tc=ssl_get_cipher_by_char(s,p);\n\t\tp+=n;\n\t\tif (c != NULL)\n\t\t\t{\n\t\t\tif (!sk_SSL_CIPHER_push(sk,c))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (skp != NULL)\n\t\t*skp=sk;\n\treturn(sk);\nerr:\n\tif ((skp == NULL) || (*skp == NULL))\n\t\tsk_SSL_CIPHER_free(sk);\n\treturn(NULL);\n\t}', '_STACK *sk_new_null(void)\n\t{\n\treturn sk_new((int (*)(const void *, const void *))0);\n\t}', '_STACK *sk_new(int (*c)(const void *, const void *))\n\t{\n\t_STACK *ret;\n\tint i;\n\tif ((ret=OPENSSL_malloc(sizeof(_STACK))) == NULL)\n\t\tgoto err;\n\tif ((ret->data=OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)\n\t\tgoto err;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->data[i]=NULL;\n\tret->comp=c;\n\tret->num_alloc=MIN_NODES;\n\tret->num=0;\n\tret->sorted=0;\n\treturn(ret);\nerr:\n\tif(ret)\n\t\tOPENSSL_free(ret);\n\treturn(NULL);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}', 'int sk_push(_STACK *st, void *data)\n\t{\n\treturn(sk_insert(st,data,st->num));\n\t}']
|
2,714
| 0
|
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L352
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *A, *a = NULL;
const BN_ULONG *B;
int i;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b,BN_FLG_SECURE))
a = A = OPENSSL_secure_malloc(words * sizeof(*a));
else
a = A = OPENSSL_malloc(words * sizeof(*a));
if (A == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
#ifdef PURIFY
memset(a, 0, sizeof(*a) * words);
#endif
#if 1
B = b->d;
if (B != NULL) {
for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
BN_ULONG a0, a1, a2, a3;
a0 = B[0];
a1 = B[1];
a2 = B[2];
a3 = B[3];
A[0] = a0;
A[1] = a1;
A[2] = a2;
A[3] = a3;
}
switch (b->top & 3) {
case 3:
A[2] = B[2];
case 2:
A[1] = B[1];
case 1:
A[0] = B[0];
case 0:
;
}
}
#else
memset(A, 0, sizeof(*A) * words);
memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
return (a);
}
|
['static int dsa_builtin_keygen(DSA *dsa)\n{\n int ok = 0;\n BN_CTX *ctx = NULL;\n BIGNUM *pub_key = NULL, *priv_key = NULL;\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n if (dsa->priv_key == NULL) {\n if ((priv_key = BN_secure_new()) == NULL)\n goto err;\n } else\n priv_key = dsa->priv_key;\n do\n if (!BN_rand_range(priv_key, dsa->q))\n goto err;\n while (BN_is_zero(priv_key)) ;\n if (dsa->pub_key == NULL) {\n if ((pub_key = BN_new()) == NULL)\n goto err;\n } else\n pub_key = dsa->pub_key;\n {\n BIGNUM *local_prk = NULL;\n BIGNUM *prk;\n if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) {\n local_prk = prk = BN_new();\n if (local_prk == NULL)\n goto err;\n BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);\n } else {\n prk = priv_key;\n }\n if (!BN_mod_exp(pub_key, dsa->g, prk, dsa->p, ctx)) {\n BN_free(local_prk);\n goto err;\n }\n BN_free(local_prk);\n }\n dsa->priv_key = priv_key;\n dsa->pub_key = pub_key;\n ok = 1;\n err:\n if (pub_key != dsa->pub_key)\n BN_free(pub_key);\n if (priv_key != dsa->priv_key)\n BN_free(priv_key);\n BN_CTX_free(ctx);\n return (ok);\n}', 'int BN_rand_range(BIGNUM *r, const BIGNUM *range)\n{\n return bn_rand_range(0, r, range);\n}', 'static int bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range)\n{\n int (*bn_rand) (BIGNUM *, int, int, int) =\n pseudo ? BN_pseudo_rand : BN_rand;\n int n;\n int count = 100;\n if (range->neg || BN_is_zero(range)) {\n BNerr(BN_F_BN_RAND_RANGE, BN_R_INVALID_RANGE);\n return 0;\n }\n n = BN_num_bits(range);\n if (n == 1)\n BN_zero(r);\n else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) {\n do {\n if (!bn_rand(r, n + 1, -1, 0))\n return 0;\n if (BN_cmp(r, range) >= 0) {\n if (!BN_sub(r, r, range))\n return 0;\n if (BN_cmp(r, range) >= 0)\n if (!BN_sub(r, r, range))\n return 0;\n }\n if (!--count) {\n BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n return 0;\n }\n }\n while (BN_cmp(r, range) >= 0);\n } else {\n do {\n if (!bn_rand(r, n, -1, 0))\n return 0;\n if (!--count) {\n BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n return 0;\n }\n }\n while (BN_cmp(r, range) >= 0);\n }\n bn_check_top(r);\n return 1;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *A, *a = NULL;\n const BN_ULONG *B;\n int i;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b,BN_FLG_SECURE))\n a = A = OPENSSL_secure_malloc(words * sizeof(*a));\n else\n a = A = OPENSSL_malloc(words * sizeof(*a));\n if (A == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n#ifdef PURIFY\n memset(a, 0, sizeof(*a) * words);\n#endif\n#if 1\n B = b->d;\n if (B != NULL) {\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:\n ;\n }\n }\n#else\n memset(A, 0, sizeof(*A) * words);\n memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n return (a);\n}']
|
2,715
| 0
|
https://github.com/openssl/openssl/blob/a8ae0891d4bfd18f224777aed1fbb172504421f1/apps/ca.c/#L2812
|
int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
ASN1_GENERALIZEDTIME **pinvtm, const char *str)
{
char *tmp = NULL;
char *rtime_str, *reason_str = NULL, *arg_str = NULL, *p;
int reason_code = -1;
int ret = 0;
unsigned int i;
ASN1_OBJECT *hold = NULL;
ASN1_GENERALIZEDTIME *comp_time = NULL;
tmp = BUF_strdup(str);
p = strchr(tmp, ',');
rtime_str = tmp;
if (p) {
*p = '\0';
p++;
reason_str = p;
p = strchr(p, ',');
if (p) {
*p = '\0';
arg_str = p + 1;
}
}
if (prevtm) {
*prevtm = ASN1_UTCTIME_new();
if (!ASN1_UTCTIME_set_string(*prevtm, rtime_str)) {
BIO_printf(bio_err, "invalid revocation date %s\n", rtime_str);
goto err;
}
}
if (reason_str) {
for (i = 0; i < NUM_REASONS; i++) {
if (!strcasecmp(reason_str, crl_reasons[i])) {
reason_code = i;
break;
}
}
if (reason_code == OCSP_REVOKED_STATUS_NOSTATUS) {
BIO_printf(bio_err, "invalid reason code %s\n", reason_str);
goto err;
}
if (reason_code == 7)
reason_code = OCSP_REVOKED_STATUS_REMOVEFROMCRL;
else if (reason_code == 8) {
if (!arg_str) {
BIO_printf(bio_err, "missing hold instruction\n");
goto err;
}
reason_code = OCSP_REVOKED_STATUS_CERTIFICATEHOLD;
hold = OBJ_txt2obj(arg_str, 0);
if (!hold) {
BIO_printf(bio_err, "invalid object identifier %s\n",
arg_str);
goto err;
}
if (phold)
*phold = hold;
} else if ((reason_code == 9) || (reason_code == 10)) {
if (!arg_str) {
BIO_printf(bio_err, "missing compromised time\n");
goto err;
}
comp_time = ASN1_GENERALIZEDTIME_new();
if (!ASN1_GENERALIZEDTIME_set_string(comp_time, arg_str)) {
BIO_printf(bio_err, "invalid compromised time %s\n", arg_str);
goto err;
}
if (reason_code == 9)
reason_code = OCSP_REVOKED_STATUS_KEYCOMPROMISE;
else
reason_code = OCSP_REVOKED_STATUS_CACOMPROMISE;
}
}
if (preason)
*preason = reason_code;
if (pinvtm)
*pinvtm = comp_time;
else
ASN1_GENERALIZEDTIME_free(comp_time);
ret = 1;
err:
if (tmp)
OPENSSL_free(tmp);
if (!phold)
ASN1_OBJECT_free(hold);
if (!pinvtm)
ASN1_GENERALIZEDTIME_free(comp_time);
return ret;
}
|
['int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,\n ASN1_GENERALIZEDTIME **pinvtm, const char *str)\n{\n char *tmp = NULL;\n char *rtime_str, *reason_str = NULL, *arg_str = NULL, *p;\n int reason_code = -1;\n int ret = 0;\n unsigned int i;\n ASN1_OBJECT *hold = NULL;\n ASN1_GENERALIZEDTIME *comp_time = NULL;\n tmp = BUF_strdup(str);\n p = strchr(tmp, \',\');\n rtime_str = tmp;\n if (p) {\n *p = \'\\0\';\n p++;\n reason_str = p;\n p = strchr(p, \',\');\n if (p) {\n *p = \'\\0\';\n arg_str = p + 1;\n }\n }\n if (prevtm) {\n *prevtm = ASN1_UTCTIME_new();\n if (!ASN1_UTCTIME_set_string(*prevtm, rtime_str)) {\n BIO_printf(bio_err, "invalid revocation date %s\\n", rtime_str);\n goto err;\n }\n }\n if (reason_str) {\n for (i = 0; i < NUM_REASONS; i++) {\n if (!strcasecmp(reason_str, crl_reasons[i])) {\n reason_code = i;\n break;\n }\n }\n if (reason_code == OCSP_REVOKED_STATUS_NOSTATUS) {\n BIO_printf(bio_err, "invalid reason code %s\\n", reason_str);\n goto err;\n }\n if (reason_code == 7)\n reason_code = OCSP_REVOKED_STATUS_REMOVEFROMCRL;\n else if (reason_code == 8) {\n if (!arg_str) {\n BIO_printf(bio_err, "missing hold instruction\\n");\n goto err;\n }\n reason_code = OCSP_REVOKED_STATUS_CERTIFICATEHOLD;\n hold = OBJ_txt2obj(arg_str, 0);\n if (!hold) {\n BIO_printf(bio_err, "invalid object identifier %s\\n",\n arg_str);\n goto err;\n }\n if (phold)\n *phold = hold;\n } else if ((reason_code == 9) || (reason_code == 10)) {\n if (!arg_str) {\n BIO_printf(bio_err, "missing compromised time\\n");\n goto err;\n }\n comp_time = ASN1_GENERALIZEDTIME_new();\n if (!ASN1_GENERALIZEDTIME_set_string(comp_time, arg_str)) {\n BIO_printf(bio_err, "invalid compromised time %s\\n", arg_str);\n goto err;\n }\n if (reason_code == 9)\n reason_code = OCSP_REVOKED_STATUS_KEYCOMPROMISE;\n else\n reason_code = OCSP_REVOKED_STATUS_CACOMPROMISE;\n }\n }\n if (preason)\n *preason = reason_code;\n if (pinvtm)\n *pinvtm = comp_time;\n else\n ASN1_GENERALIZEDTIME_free(comp_time);\n ret = 1;\n err:\n if (tmp)\n OPENSSL_free(tmp);\n if (!phold)\n ASN1_OBJECT_free(hold);\n if (!pinvtm)\n ASN1_GENERALIZEDTIME_free(comp_time);\n return ret;\n}', 'char *BUF_strdup(const char *str)\n{\n if (str == NULL)\n return (NULL);\n return BUF_strndup(str, strlen(str));\n}']
|
2,716
| 0
|
https://github.com/libav/libav/blob/c15fea7933b3801962851a37c3ef00ce968431c4/libavcodec/vp3.c/#L1924
|
static int vp3_decode_frame(AVCodecContext *avctx,
void *data, int *got_frame,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
Vp3DecodeContext *s = avctx->priv_data;
GetBitContext gb;
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);
for (i = 0; i < 3; i++)
s->last_qps[i] = s->qps[i];
s->nqps=0;
do{
s->qps[s->nqps++]= get_bits(&gb, 6);
} while(s->theora >= 0x030200 && s->nqps<3 && get_bits1(&gb));
for (i = s->nqps; i < 3; i++)
s->qps[i] = -1;
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":"", avctx->frame_number+1, s->qps[0]);
s->skip_loop_filter = !s->filter_limit_values[s->qps[0]] ||
avctx->skip_loop_filter >= (s->keyframe ? AVDISCARD_ALL : AVDISCARD_NONKEY);
if (s->qps[0] != s->last_qps[0])
init_loop_filter(s);
for (i = 0; i < s->nqps; i++)
if (s->qps[i] != s->last_qps[i] || s->qps[0] != s->last_qps[0])
init_dequantizer(s, i);
if (avctx->skip_frame >= AVDISCARD_NONKEY && !s->keyframe)
return buf_size;
s->current_frame.reference = 3;
s->current_frame.pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
if (ff_thread_get_buffer(avctx, &s->current_frame) < 0) {
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
goto error;
}
if (!s->edge_emu_buffer)
s->edge_emu_buffer = av_malloc(9*FFABS(s->current_frame.linesize[0]));
if (s->keyframe) {
if (!s->theora)
{
skip_bits(&gb, 4);
skip_bits(&gb, 4);
if (s->version)
{
s->version = get_bits(&gb, 5);
if (avctx->frame_number == 0)
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);
}
} else {
if (!s->golden_frame.data[0]) {
av_log(s->avctx, AV_LOG_WARNING, "vp3: first frame not a keyframe\n");
s->golden_frame.reference = 3;
s->golden_frame.pict_type = AV_PICTURE_TYPE_I;
if (ff_thread_get_buffer(avctx, &s->golden_frame) < 0) {
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
goto error;
}
s->last_frame = s->golden_frame;
s->last_frame.type = FF_BUFFER_TYPE_COPY;
ff_thread_report_progress(&s->last_frame, INT_MAX, 0);
}
}
memset(s->all_fragments, 0, s->fragment_count * sizeof(Vp3Fragment));
ff_thread_finish_setup(avctx);
if (unpack_superblocks(s, &gb)){
av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n");
goto error;
}
if (unpack_modes(s, &gb)){
av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n");
goto error;
}
if (unpack_vectors(s, &gb)){
av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n");
goto error;
}
if (unpack_block_qpis(s, &gb)){
av_log(s->avctx, AV_LOG_ERROR, "error in unpack_block_qpis\n");
goto error;
}
if (unpack_dct_coeffs(s, &gb)){
av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n");
goto error;
}
for (i = 0; i < 3; i++) {
int height = s->height >> (i && s->chroma_y_shift);
if (s->flipped_image)
s->data_offset[i] = 0;
else
s->data_offset[i] = (height-1) * s->current_frame.linesize[i];
}
s->last_slice_end = 0;
for (i = 0; i < s->c_superblock_height; i++)
render_slice(s, i);
for (i = 0; i < 3; i++) {
int row = (s->height >> (3+(i && s->chroma_y_shift))) - 1;
apply_loop_filter(s, i, row, row+1);
}
vp3_draw_horiz_band(s, s->avctx->height);
*got_frame = 1;
*(AVFrame*)data= s->current_frame;
if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_FRAME))
update_frames(avctx);
return buf_size;
error:
ff_thread_report_progress(&s->current_frame, INT_MAX, 0);
if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_FRAME))
avctx->release_buffer(avctx, &s->current_frame);
return -1;
}
|
['static int vp3_decode_frame(AVCodecContext *avctx,\n void *data, int *got_frame,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n Vp3DecodeContext *s = avctx->priv_data;\n GetBitContext gb;\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 for (i = 0; i < 3; i++)\n s->last_qps[i] = s->qps[i];\n s->nqps=0;\n do{\n s->qps[s->nqps++]= get_bits(&gb, 6);\n } while(s->theora >= 0x030200 && s->nqps<3 && get_bits1(&gb));\n for (i = s->nqps; i < 3; i++)\n s->qps[i] = -1;\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":"", avctx->frame_number+1, s->qps[0]);\n s->skip_loop_filter = !s->filter_limit_values[s->qps[0]] ||\n avctx->skip_loop_filter >= (s->keyframe ? AVDISCARD_ALL : AVDISCARD_NONKEY);\n if (s->qps[0] != s->last_qps[0])\n init_loop_filter(s);\n for (i = 0; i < s->nqps; i++)\n if (s->qps[i] != s->last_qps[i] || s->qps[0] != s->last_qps[0])\n init_dequantizer(s, i);\n if (avctx->skip_frame >= AVDISCARD_NONKEY && !s->keyframe)\n return buf_size;\n s->current_frame.reference = 3;\n s->current_frame.pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;\n if (ff_thread_get_buffer(avctx, &s->current_frame) < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n goto error;\n }\n if (!s->edge_emu_buffer)\n s->edge_emu_buffer = av_malloc(9*FFABS(s->current_frame.linesize[0]));\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 (avctx->frame_number == 0)\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 } else {\n if (!s->golden_frame.data[0]) {\n av_log(s->avctx, AV_LOG_WARNING, "vp3: first frame not a keyframe\\n");\n s->golden_frame.reference = 3;\n s->golden_frame.pict_type = AV_PICTURE_TYPE_I;\n if (ff_thread_get_buffer(avctx, &s->golden_frame) < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n goto error;\n }\n s->last_frame = s->golden_frame;\n s->last_frame.type = FF_BUFFER_TYPE_COPY;\n ff_thread_report_progress(&s->last_frame, INT_MAX, 0);\n }\n }\n memset(s->all_fragments, 0, s->fragment_count * sizeof(Vp3Fragment));\n ff_thread_finish_setup(avctx);\n if (unpack_superblocks(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\\n");\n goto error;\n }\n if (unpack_modes(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\\n");\n goto error;\n }\n if (unpack_vectors(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\\n");\n goto error;\n }\n if (unpack_block_qpis(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_block_qpis\\n");\n goto error;\n }\n if (unpack_dct_coeffs(s, &gb)){\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\\n");\n goto error;\n }\n for (i = 0; i < 3; i++) {\n int height = s->height >> (i && s->chroma_y_shift);\n if (s->flipped_image)\n s->data_offset[i] = 0;\n else\n s->data_offset[i] = (height-1) * s->current_frame.linesize[i];\n }\n s->last_slice_end = 0;\n for (i = 0; i < s->c_superblock_height; i++)\n render_slice(s, i);\n for (i = 0; i < 3; i++) {\n int row = (s->height >> (3+(i && s->chroma_y_shift))) - 1;\n apply_loop_filter(s, i, row, row+1);\n }\n vp3_draw_horiz_band(s, s->avctx->height);\n *got_frame = 1;\n *(AVFrame*)data= s->current_frame;\n if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_FRAME))\n update_frames(avctx);\n return buf_size;\nerror:\n ff_thread_report_progress(&s->current_frame, INT_MAX, 0);\n if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_FRAME))\n avctx->release_buffer(avctx, &s->current_frame);\n return -1;\n}', 'static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer,\n 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#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}', '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}']
|
2,717
| 0
|
https://github.com/openssl/openssl/blob/5850cc75ea0c1581a9034390f1ca77cadc596238/crypto/bn/bn_ctx.c/#L328
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int dsa_do_verify(const unsigned char *dgst, int dgst_len,\n DSA_SIG *sig, DSA *dsa)\n{\n BN_CTX *ctx;\n BIGNUM *u1, *u2, *t1;\n BN_MONT_CTX *mont = NULL;\n int ret = -1, i;\n if (!dsa->p || !dsa->q || !dsa->g) {\n DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MISSING_PARAMETERS);\n return -1;\n }\n i = BN_num_bits(dsa->q);\n if (i != 160 && i != 224 && i != 256) {\n DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_BAD_Q_VALUE);\n return -1;\n }\n if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) {\n DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MODULUS_TOO_LARGE);\n return -1;\n }\n u1 = BN_new();\n u2 = BN_new();\n t1 = BN_new();\n ctx = BN_CTX_new();\n if (!u1 || !u2 || !t1 || !ctx)\n goto err;\n if (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||\n BN_ucmp(sig->r, dsa->q) >= 0) {\n ret = 0;\n goto err;\n }\n if (BN_is_zero(sig->s) || BN_is_negative(sig->s) ||\n BN_ucmp(sig->s, dsa->q) >= 0) {\n ret = 0;\n goto err;\n }\n if ((BN_mod_inverse(u2, sig->s, dsa->q, ctx)) == NULL)\n goto err;\n if (dgst_len > (i >> 3))\n dgst_len = (i >> 3);\n if (BN_bin2bn(dgst, dgst_len, u1) == NULL)\n goto err;\n if (!BN_mod_mul(u1, u1, u2, dsa->q, ctx))\n goto err;\n if (!BN_mod_mul(u2, sig->r, u2, dsa->q, ctx))\n goto err;\n if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n CRYPTO_LOCK_DSA, dsa->p, ctx);\n if (!mont)\n goto err;\n }\n DSA_MOD_EXP(goto err, dsa, t1, dsa->g, u1, dsa->pub_key, u2, dsa->p, ctx,\n mont);\n if (!BN_mod(u1, t1, dsa->q, ctx))\n goto err;\n ret = (BN_ucmp(u1, sig->r) == 0);\n err:\n if (ret < 0)\n DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB);\n BN_CTX_free(ctx);\n BN_free(u1);\n BN_free(u2);\n BN_free(t1);\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 local_B.flags = 0;\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 local_A.flags = 0;\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_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}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
2,718
| 0
|
https://github.com/openssl/openssl/blob/3ba25ee86a3758cc659c954b59718d8397030768/crypto/lhash/lhash.c/#L363
|
static void contract(LHASH *lh)
{
LHASH_NODE **n,*n1,*np;
np=lh->b[lh->p+lh->pmax-1];
lh->b[lh->p+lh->pmax-1]=NULL;
if (lh->p == 0)
{
n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
if (n == NULL)
{
lh->error++;
return;
}
lh->num_contract_reallocs++;
lh->num_alloc_nodes/=2;
lh->pmax/=2;
lh->p=lh->pmax-1;
lh->b=n;
}
else
lh->p--;
lh->num_nodes--;
lh->num_contracts++;
n1=lh->b[(int)lh->p];
if (n1 == NULL)
lh->b[(int)lh->p]=np;
else
{
while (n1->next != NULL)
n1=n1->next;
n1->next=np;
}
}
|
['int ssl3_get_finished(SSL *s, int a, int b)\n\t{\n\tint al,i,ok;\n\tlong n;\n\tunsigned char *p;\n\tn=ssl3_get_message(s,\n\t\ta,\n\t\tb,\n\t\tSSL3_MT_FINISHED,\n\t\t64,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\tif (!s->s3->change_cipher_spec)\n\t\t{\n\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\tSSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_GOT_A_FIN_BEFORE_A_CCS);\n\t\tgoto f_err;\n\t\t}\n\ts->s3->change_cipher_spec=0;\n\tp = (unsigned char *)s->init_buf->data;\n\ti = s->s3->tmp.peer_finish_md_len;\n\tif (i != n)\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_BAD_DIGEST_LENGTH);\n\t\tgoto f_err;\n\t\t}\n\tif (memcmp(p, s->s3->tmp.peer_finish_md, i) != 0)\n\t\t{\n\t\tal=SSL_AD_DECRYPT_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_FINISHED,SSL_R_DIGEST_CHECK_FAILED);\n\t\tgoto f_err;\n\t\t}\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\treturn(0);\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\tint skip_message;\n\t\tdo\n\t\t\t{\n\t\t\twhile (s->init_num < 4)\n\t\t\t\t{\n\t\t\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],\n\t\t\t\t\t4 - s->init_num, 0);\n\t\t\t\tif (i <= 0)\n\t\t\t\t\t{\n\t\t\t\t\ts->rwstate=SSL_READING;\n\t\t\t\t\t*ok = 0;\n\t\t\t\t\treturn i;\n\t\t\t\t\t}\n\t\t\t\ts->init_num+=i;\n\t\t\t\t}\n\t\t\tskip_message = 0;\n\t\t\tif (!s->server)\n\t\t\t\tif (p[0] == SSL3_MT_HELLO_REQUEST)\n\t\t\t\t\tif (p[1] == 0 && p[2] == 0 &&p[3] == 0)\n\t\t\t\t\t\tskip_message = 1;\n\t\t\t}\n\t\twhile (skip_message);\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\t}\n\t\tssl3_finish_mac(s, (unsigned char *)s->init_buf->data, 4);\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\twhile (n > 0)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n,0);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\ts->rwstate=SSL_READING;\n\t\t\t*ok = 0;\n\t\t\treturn i;\n\t\t\t}\n\t\ts->init_num += i;\n\t\tn -= i;\n\t\t}\n\tssl3_finish_mac(s, (unsigned char *)s->init_buf->data, s->init_num);\n\t*ok=1;\n\treturn s->init_num;\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, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tconst void *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn((void *)ret);\n\t}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)OPENSSL_realloc(lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}']
|
2,719
| 0
|
https://github.com/libav/libav/blob/688417399c69aadd4c287bdb0dec82ef8799011c/libavcodec/hevcdsp_template.c/#L901
|
PUT_HEVC_QPEL_HV(1, 1)
|
['QPEL(32)', 'PUT_HEVC_QPEL_HV(1, 1)']
|
2,720
| 0
|
https://github.com/openssl/openssl/blob/7747a49f2452dfab8880ff60451073ae8506c90e/apps/srp.c/#L69
|
static void print_entry(CA_DB *db, int indx, int verbose, char *s)
{
if (indx >= 0 && verbose) {
int j;
char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);
BIO_printf(bio_err, "%s \"%s\"\n", s, pp[DB_srpid]);
for (j = 0; j < DB_NUMBER; j++) {
BIO_printf(bio_err, " %d = \"%s\"\n", j, pp[j]);
}
}
}
|
['static void print_entry(CA_DB *db, int indx, int verbose, char *s)\n{\n if (indx >= 0 && verbose) {\n int j;\n char **pp = sk_OPENSSL_PSTRING_value(db->db->data, indx);\n BIO_printf(bio_err, "%s \\"%s\\"\\n", s, pp[DB_srpid]);\n for (j = 0; j < DB_NUMBER; j++) {\n BIO_printf(bio_err, " %d = \\"%s\\"\\n", j, pp[j]);\n }\n }\n}', 'DEFINE_SPECIAL_STACK_OF(OPENSSL_PSTRING, OPENSSL_STRING)', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n if (st == NULL || i < 0 || i >= st->num)\n return NULL;\n return (void *)st->data[i];\n}']
|
2,721
| 0
|
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/asn1/asn1_lib.c/#L228
|
static void asn1_put_length(unsigned char **pp, int length)
{
unsigned char *p= *pp;
int i,l;
if (length <= 127)
*(p++)=(unsigned char)length;
else
{
l=length;
for (i=0; l > 0; i++)
l>>=8;
*(p++)=i|0x80;
l=i;
while (i-- > 0)
{
p[i]=length&0xff;
length>>=8;
}
p+=l;
}
*pp=p;
}
|
['static int request_certificate(SSL *s)\n\t{\n\tunsigned char *p,*p2,*buf2;\n\tunsigned char *ccd;\n\tint i,j,ctype,ret= -1;\n\tX509 *x509=NULL;\n\tSTACK_OF(X509) *sk=NULL;\n\tccd=s->s2->tmp.ccl;\n\tif (s->state == SSL2_ST_SEND_REQUEST_CERTIFICATE_A)\n\t\t{\n\t\tp=(unsigned char *)s->init_buf->data;\n\t\t*(p++)=SSL2_MT_REQUEST_CERTIFICATE;\n\t\t*(p++)=SSL2_AT_MD5_WITH_RSA_ENCRYPTION;\n\t\tRAND_bytes(ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH);\n\t\tmemcpy(p,ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH);\n\t\ts->state=SSL2_ST_SEND_REQUEST_CERTIFICATE_B;\n\t\ts->init_num=SSL2_MIN_CERT_CHALLENGE_LENGTH+2;\n\t\ts->init_off=0;\n\t\t}\n\tif (s->state == SSL2_ST_SEND_REQUEST_CERTIFICATE_B)\n\t\t{\n\t\ti=ssl2_do_write(s);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\tret=i;\n\t\t\tgoto end;\n\t\t\t}\n\t\ts->init_num=0;\n\t\ts->state=SSL2_ST_SEND_REQUEST_CERTIFICATE_C;\n\t\t}\n\tif (s->state == SSL2_ST_SEND_REQUEST_CERTIFICATE_C)\n\t\t{\n\t\tp=(unsigned char *)s->init_buf->data;\n\t\ti=ssl2_read(s,(char *)&(p[s->init_num]),6-s->init_num);\n\t\tif (i < 3)\n\t\t\t{\n\t\t\tret=ssl2_part_read(s,SSL_F_REQUEST_CERTIFICATE,i);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif ((*p == SSL2_MT_ERROR) && (i >= 3))\n\t\t\t{\n\t\t\tn2s(p,i);\n\t\t\tif (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)\n\t\t\t\t{\n\t\t\t\tssl2_return_error(s,SSL2_PE_BAD_CERTIFICATE);\n\t\t\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tret=1;\n\t\t\tgoto end;\n\t\t\t}\n\t\tif ((*(p++) != SSL2_MT_CLIENT_CERTIFICATE) || (i < 6))\n\t\t\t{\n\t\t\tssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);\n\t\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_SHORT_READ);\n\t\t\tgoto end;\n\t\t\t}\n\t\tctype= *(p++);\n\t\tif (ctype != SSL2_AT_MD5_WITH_RSA_ENCRYPTION)\n\t\t\t{\n\t\t\tssl2_return_error(s,SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE);\n\t\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_BAD_RESPONSE_ARGUMENT);\n\t\t\tgoto end;\n\t\t\t}\n\t\tn2s(p,i); s->s2->tmp.clen=i;\n\t\tn2s(p,i); s->s2->tmp.rlen=i;\n\t\ts->state=SSL2_ST_SEND_REQUEST_CERTIFICATE_D;\n\t\ts->init_num=0;\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tj=s->s2->tmp.clen+s->s2->tmp.rlen-s->init_num;\n\ti=ssl2_read(s,(char *)&(p[s->init_num]),j);\n\tif (i < j)\n\t\t{\n\t\tret=ssl2_part_read(s,SSL_F_REQUEST_CERTIFICATE,i);\n\t\tgoto end;\n\t\t}\n\tx509=(X509 *)d2i_X509(NULL,&p,(long)s->s2->tmp.clen);\n\tif (x509 == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,ERR_R_X509_LIB);\n\t\tgoto msg_end;\n\t\t}\n\tif (((sk=sk_X509_new_null()) == NULL) || (!sk_X509_push(sk,x509)))\n\t\t{\n\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,ERR_R_MALLOC_FAILURE);\n\t\tgoto msg_end;\n\t\t}\n\ti=ssl_verify_cert_chain(s,sk);\n\tif (i)\n\t\t{\n\t\tEVP_MD_CTX ctx;\n\t\tEVP_PKEY *pkey=NULL;\n\t\tEVP_VerifyInit(&ctx,s->ctx->rsa_md5);\n\t\tEVP_VerifyUpdate(&ctx,s->s2->key_material,\n\t\t\t(unsigned int)s->s2->key_material_length);\n\t\tEVP_VerifyUpdate(&ctx,ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH);\n\t\ti=i2d_X509(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509,NULL);\n\t\tbuf2=(unsigned char *)Malloc((unsigned int)i);\n\t\tif (buf2 == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto msg_end;\n\t\t\t}\n\t\tp2=buf2;\n\t\ti=i2d_X509(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509,&p2);\n\t\tEVP_VerifyUpdate(&ctx,buf2,(unsigned int)i);\n\t\tFree(buf2);\n\t\tpkey=X509_get_pubkey(x509);\n\t\tif (pkey == NULL) goto end;\n\t\ti=EVP_VerifyFinal(&ctx,p,s->s2->tmp.rlen,pkey);\n\t\tEVP_PKEY_free(pkey);\n\t\tmemset(&ctx,0,sizeof(ctx));\n\t\tif (i)\n\t\t\t{\n\t\t\tif (s->session->peer != NULL)\n\t\t\t\tX509_free(s->session->peer);\n\t\t\ts->session->peer=x509;\n\t\t\tCRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);\n\t\t\tret=1;\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_BAD_CHECKSUM);\n\t\t\tgoto msg_end;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\nmsg_end:\n\t\tssl2_return_error(s,SSL2_PE_BAD_CERTIFICATE);\n\t\t}\nend:\n\tsk_X509_free(sk);\n\tX509_free(x509);\n\treturn(ret);\n\t}', 'int i2d_X509(X509 *a, unsigned char **pp)\n\t{\n\tM_ASN1_I2D_vars(a);\n\tM_ASN1_I2D_len(a->cert_info,\ti2d_X509_CINF);\n\tM_ASN1_I2D_len(a->sig_alg,\ti2d_X509_ALGOR);\n\tM_ASN1_I2D_len(a->signature,\ti2d_ASN1_BIT_STRING);\n\tM_ASN1_I2D_seq_total();\n\tM_ASN1_I2D_put(a->cert_info,\ti2d_X509_CINF);\n\tM_ASN1_I2D_put(a->sig_alg,\ti2d_X509_ALGOR);\n\tM_ASN1_I2D_put(a->signature,\ti2d_ASN1_BIT_STRING);\n\tM_ASN1_I2D_finish();\n\t}', 'void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,\n\t int xclass)\n\t{\n\tunsigned char *p= *pp;\n\tint i;\n\ti=(constructed)?V_ASN1_CONSTRUCTED:0;\n\ti|=(xclass&V_ASN1_PRIVATE);\n\tif (tag < 31)\n\t\t*(p++)=i|(tag&V_ASN1_PRIMATIVE_TAG);\n\telse\n\t\t{\n\t\t*(p++)=i|V_ASN1_PRIMATIVE_TAG;\n\t\twhile (tag > 0x7f)\n\t\t\t{\n\t\t\t*(p++)=(tag&0x7f)|0x80;\n\t\t\ttag>>=7;\n\t\t\t}\n\t\t*(p++)=(tag&0x7f);\n\t\t}\n\tif ((constructed == 2) && (length == 0))\n\t\t*(p++)=0x80;\n\telse\n\t\tasn1_put_length(&p,length);\n\t*pp=p;\n\t}', 'static void asn1_put_length(unsigned char **pp, int length)\n\t{\n\tunsigned char *p= *pp;\n\tint i,l;\n\tif (length <= 127)\n\t\t*(p++)=(unsigned char)length;\n\telse\n\t\t{\n\t\tl=length;\n\t\tfor (i=0; l > 0; i++)\n\t\t\tl>>=8;\n\t\t*(p++)=i|0x80;\n\t\tl=i;\n\t\twhile (i-- > 0)\n\t\t\t{\n\t\t\tp[i]=length&0xff;\n\t\t\tlength>>=8;\n\t\t\t}\n\t\tp+=l;\n\t\t}\n\t*pp=p;\n\t}']
|
2,722
| 0
|
https://github.com/openssl/openssl/blob/0f3ffbd1581fad58095fedcc32b0da42a486b8b7/test/exdatatest.c/#L135
|
static MYOBJ *MYOBJ_new()
{
static int count = 0;
MYOBJ *obj = OPENSSL_malloc(sizeof(*obj));
obj->id = ++count;
obj->st = CRYPTO_new_ex_data(CRYPTO_EX_INDEX_APP, obj, &obj->ex_data);
return obj;
}
|
['static MYOBJ *MYOBJ_new()\n{\n static int count = 0;\n MYOBJ *obj = OPENSSL_malloc(sizeof(*obj));\n obj->id = ++count;\n obj->st = CRYPTO_new_ex_data(CRYPTO_EX_INDEX_APP, obj, &obj->ex_data);\n return obj;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
2,723
| 0
|
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L246
|
static inline void bitstream_skip(BitstreamContext *bc, unsigned n)
{
if (n <= bc->bits_left)
skip_remaining(bc, n);
else {
n -= bc->bits_left;
skip_remaining(bc, bc->bits_left);
if (n >= 64) {
unsigned skip = n / 8;
n -= skip * 8;
bc->ptr += skip;
}
refill_64(bc);
if (n)
skip_remaining(bc, n);
}
}
|
['static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)\n{\n MpegEncContext *const s = &h->s;\n int code, level, i, j, run;\n RLTable *rl = &ff_h261_rl_tcoeff;\n const uint8_t *scan_table;\n scan_table = s->intra_scantable.permutated;\n if (s->mb_intra) {\n level = bitstream_read(&s->bc, 8);\n if ((level & 0x7F) == 0) {\n av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\\n",\n level, s->mb_x, s->mb_y);\n return -1;\n }\n if (level == 255)\n level = 128;\n block[0] = level;\n i = 1;\n } else if (coded) {\n int check = bitstream_peek(&s->bc, 2);\n i = 0;\n if (check & 0x2) {\n bitstream_skip(&s->bc, 2);\n block[0] = (check & 0x1) ? -1 : 1;\n i = 1;\n }\n } else {\n i = 0;\n }\n if (!coded) {\n s->block_last_index[n] = i - 1;\n return 0;\n }\n for (;;) {\n code = bitstream_read_vlc(&s->bc, rl->vlc.table, TCOEFF_VLC_BITS, 2);\n if (code < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\\n",\n s->mb_x, s->mb_y);\n return -1;\n }\n if (code == rl->n) {\n run = bitstream_read(&s->bc, 6);\n level = bitstream_read_signed(&s->bc, 8);\n } else if (code == 0) {\n break;\n } else {\n run = rl->table_run[code];\n level = rl->table_level[code];\n if (bitstream_read_bit(&s->bc))\n level = -level;\n }\n i += run;\n if (i >= 64) {\n av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\\n",\n s->mb_x, s->mb_y);\n return -1;\n }\n j = scan_table[i];\n block[j] = level;\n i++;\n }\n s->block_last_index[n] = i - 1;\n return 0;\n}', 'static inline unsigned bitstream_peek(BitstreamContext *bc, unsigned n)\n{\n if (n > bc->bits_left)\n refill_32(bc);\n return show_val(bc, n);\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n <= bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n skip_remaining(bc, bc->bits_left);\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}']
|
2,724
| 0
|
https://github.com/openssl/openssl/blob/3ad4af89cf7380aa94d1995e05e713d59e1c469a/crypto/mem.c/#L226
|
void CRYPTO_free(void *str, const char *file, int line)
{
if (free_impl != NULL && free_impl != &CRYPTO_free) {
free_impl(str, file, line);
return;
}
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (call_malloc_debug) {
CRYPTO_mem_debug_free(str, 0, file, line);
free(str);
CRYPTO_mem_debug_free(str, 1, file, line);
} else {
free(str);
}
#else
free(str);
#endif
}
|
['static int process_pci_value(CONF_VALUE *val,\n ASN1_OBJECT **language, ASN1_INTEGER **pathlen,\n ASN1_OCTET_STRING **policy)\n{\n int free_policy = 0;\n if (strcmp(val->name, "language") == 0) {\n if (*language) {\n X509V3err(X509V3_F_PROCESS_PCI_VALUE,\n X509V3_R_POLICY_LANGUAGE_ALREADY_DEFINED);\n X509V3_conf_err(val);\n return 0;\n }\n if ((*language = OBJ_txt2obj(val->value, 0)) == NULL) {\n X509V3err(X509V3_F_PROCESS_PCI_VALUE,\n X509V3_R_INVALID_OBJECT_IDENTIFIER);\n X509V3_conf_err(val);\n return 0;\n }\n } else if (strcmp(val->name, "pathlen") == 0) {\n if (*pathlen) {\n X509V3err(X509V3_F_PROCESS_PCI_VALUE,\n X509V3_R_POLICY_PATH_LENGTH_ALREADY_DEFINED);\n X509V3_conf_err(val);\n return 0;\n }\n if (!X509V3_get_value_int(val, pathlen)) {\n X509V3err(X509V3_F_PROCESS_PCI_VALUE,\n X509V3_R_POLICY_PATH_LENGTH);\n X509V3_conf_err(val);\n return 0;\n }\n } else if (strcmp(val->name, "policy") == 0) {\n unsigned char *tmp_data = NULL;\n long val_len;\n if (!*policy) {\n *policy = ASN1_OCTET_STRING_new();\n if (*policy == NULL) {\n X509V3err(X509V3_F_PROCESS_PCI_VALUE, ERR_R_MALLOC_FAILURE);\n X509V3_conf_err(val);\n return 0;\n }\n free_policy = 1;\n }\n if (strncmp(val->value, "hex:", 4) == 0) {\n unsigned char *tmp_data2 =\n OPENSSL_hexstr2buf(val->value + 4, &val_len);\n if (!tmp_data2) {\n X509V3_conf_err(val);\n goto err;\n }\n tmp_data = OPENSSL_realloc((*policy)->data,\n (*policy)->length + val_len + 1);\n if (tmp_data) {\n (*policy)->data = tmp_data;\n memcpy(&(*policy)->data[(*policy)->length],\n tmp_data2, val_len);\n (*policy)->length += val_len;\n (*policy)->data[(*policy)->length] = \'\\0\';\n } else {\n OPENSSL_free(tmp_data2);\n OPENSSL_free((*policy)->data);\n (*policy)->data = NULL;\n (*policy)->length = 0;\n X509V3err(X509V3_F_PROCESS_PCI_VALUE, ERR_R_MALLOC_FAILURE);\n X509V3_conf_err(val);\n goto err;\n }\n OPENSSL_free(tmp_data2);\n } else if (strncmp(val->value, "file:", 5) == 0) {\n unsigned char buf[2048];\n int n;\n BIO *b = BIO_new_file(val->value + 5, "r");\n if (!b) {\n X509V3err(X509V3_F_PROCESS_PCI_VALUE, ERR_R_BIO_LIB);\n X509V3_conf_err(val);\n goto err;\n }\n while ((n = BIO_read(b, buf, sizeof(buf))) > 0\n || (n == 0 && BIO_should_retry(b))) {\n if (!n)\n continue;\n tmp_data = OPENSSL_realloc((*policy)->data,\n (*policy)->length + n + 1);\n if (!tmp_data) {\n OPENSSL_free((*policy)->data);\n (*policy)->data = NULL;\n (*policy)->length = 0;\n X509V3err(X509V3_F_PROCESS_PCI_VALUE,\n ERR_R_MALLOC_FAILURE);\n X509V3_conf_err(val);\n BIO_free_all(b);\n goto err;\n }\n (*policy)->data = tmp_data;\n memcpy(&(*policy)->data[(*policy)->length], buf, n);\n (*policy)->length += n;\n (*policy)->data[(*policy)->length] = \'\\0\';\n }\n BIO_free_all(b);\n if (n < 0) {\n X509V3err(X509V3_F_PROCESS_PCI_VALUE, ERR_R_BIO_LIB);\n X509V3_conf_err(val);\n goto err;\n }\n } else if (strncmp(val->value, "text:", 5) == 0) {\n val_len = strlen(val->value + 5);\n tmp_data = OPENSSL_realloc((*policy)->data,\n (*policy)->length + val_len + 1);\n if (tmp_data) {\n (*policy)->data = tmp_data;\n memcpy(&(*policy)->data[(*policy)->length],\n val->value + 5, val_len);\n (*policy)->length += val_len;\n (*policy)->data[(*policy)->length] = \'\\0\';\n } else {\n OPENSSL_free((*policy)->data);\n (*policy)->data = NULL;\n (*policy)->length = 0;\n X509V3err(X509V3_F_PROCESS_PCI_VALUE, ERR_R_MALLOC_FAILURE);\n X509V3_conf_err(val);\n goto err;\n }\n } else {\n X509V3err(X509V3_F_PROCESS_PCI_VALUE,\n X509V3_R_INCORRECT_POLICY_SYNTAX_TAG);\n X509V3_conf_err(val);\n goto err;\n }\n if (!tmp_data) {\n X509V3err(X509V3_F_PROCESS_PCI_VALUE, ERR_R_MALLOC_FAILURE);\n X509V3_conf_err(val);\n goto err;\n }\n }\n return 1;\n err:\n if (free_policy) {\n ASN1_OCTET_STRING_free(*policy);\n *policy = NULL;\n }\n return 0;\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (realloc_impl != NULL && realloc_impl != &CRYPTO_realloc)\n return realloc_impl(str, num, file, line);\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str, file, line);\n return NULL;\n }\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n osslargused(file); osslargused(line);\n#endif\n return realloc(str, num);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
|
2,725
| 0
|
https://github.com/nginx/nginx/blob/e4ecddfdb0d2ffc872658e36028971ad9a873726/src/core/ngx_string.c/#L244
|
u_char *
ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)
{
u_char *p, zero, *last;
int d;
float f, scale;
size_t len, slen;
int64_t i64;
uint64_t ui64;
ngx_msec_t ms;
ngx_uint_t width, sign, hex, max_width, frac_width, i;
ngx_str_t *v;
ngx_variable_value_t *vv;
if (max == 0) {
return buf;
}
last = buf + max;
while (*fmt && buf < last) {
if (*fmt == '%') {
i64 = 0;
ui64 = 0;
zero = (u_char) ((*++fmt == '0') ? '0' : ' ');
width = 0;
sign = 1;
hex = 0;
max_width = 0;
frac_width = 0;
slen = (size_t) -1;
while (*fmt >= '0' && *fmt <= '9') {
width = width * 10 + *fmt++ - '0';
}
for ( ;; ) {
switch (*fmt) {
case 'u':
sign = 0;
fmt++;
continue;
case 'm':
max_width = 1;
fmt++;
continue;
case 'X':
hex = 2;
sign = 0;
fmt++;
continue;
case 'x':
hex = 1;
sign = 0;
fmt++;
continue;
case '.':
fmt++;
while (*fmt >= '0' && *fmt <= '9') {
frac_width = frac_width * 10 + *fmt++ - '0';
}
break;
case '*':
slen = va_arg(args, size_t);
fmt++;
continue;
default:
break;
}
break;
}
switch (*fmt) {
case 'V':
v = va_arg(args, ngx_str_t *);
len = v->len;
len = (buf + len < last) ? len : (size_t) (last - buf);
buf = ngx_cpymem(buf, v->data, len);
fmt++;
continue;
case 'v':
vv = va_arg(args, ngx_variable_value_t *);
len = vv->len;
len = (buf + len < last) ? len : (size_t) (last - buf);
buf = ngx_cpymem(buf, vv->data, len);
fmt++;
continue;
case 's':
p = va_arg(args, u_char *);
if (slen == (size_t) -1) {
while (*p && buf < last) {
*buf++ = *p++;
}
} else {
len = (buf + slen < last) ? slen : (size_t) (last - buf);
buf = ngx_cpymem(buf, p, len);
}
fmt++;
continue;
case 'O':
i64 = (int64_t) va_arg(args, off_t);
sign = 1;
break;
case 'P':
i64 = (int64_t) va_arg(args, ngx_pid_t);
sign = 1;
break;
case 'T':
i64 = (int64_t) va_arg(args, time_t);
sign = 1;
break;
case 'M':
ms = (ngx_msec_t) va_arg(args, ngx_msec_t);
if ((ngx_msec_int_t) ms == -1) {
sign = 1;
i64 = -1;
} else {
sign = 0;
ui64 = (uint64_t) ms;
}
break;
case 'z':
if (sign) {
i64 = (int64_t) va_arg(args, ssize_t);
} else {
ui64 = (uint64_t) va_arg(args, size_t);
}
break;
case 'i':
if (sign) {
i64 = (int64_t) va_arg(args, ngx_int_t);
} else {
ui64 = (uint64_t) va_arg(args, ngx_uint_t);
}
if (max_width) {
width = NGX_INT_T_LEN;
}
break;
case 'd':
if (sign) {
i64 = (int64_t) va_arg(args, int);
} else {
ui64 = (uint64_t) va_arg(args, u_int);
}
break;
case 'l':
if (sign) {
i64 = (int64_t) va_arg(args, long);
} else {
ui64 = (uint64_t) va_arg(args, u_long);
}
break;
case 'D':
if (sign) {
i64 = (int64_t) va_arg(args, int32_t);
} else {
ui64 = (uint64_t) va_arg(args, uint32_t);
}
break;
case 'L':
if (sign) {
i64 = va_arg(args, int64_t);
} else {
ui64 = va_arg(args, uint64_t);
}
break;
case 'A':
if (sign) {
i64 = (int64_t) va_arg(args, ngx_atomic_int_t);
} else {
ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);
}
if (max_width) {
width = NGX_ATOMIC_T_LEN;
}
break;
case 'f':
f = (float) va_arg(args, double);
if (f < 0) {
*buf++ = '-';
f = -f;
}
ui64 = (int64_t) f;
buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);
if (frac_width) {
if (buf < last) {
*buf++ = '.';
}
scale = 1.0;
for (i = 0; i < frac_width; i++) {
scale *= 10.0;
}
ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);
buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);
}
fmt++;
continue;
#if !(NGX_WIN32)
case 'r':
i64 = (int64_t) va_arg(args, rlim_t);
sign = 1;
break;
#endif
case 'p':
ui64 = (uintptr_t) va_arg(args, void *);
hex = 2;
sign = 0;
zero = '0';
width = NGX_PTR_SIZE * 2;
break;
case 'c':
d = va_arg(args, int);
*buf++ = (u_char) (d & 0xff);
fmt++;
continue;
case 'Z':
*buf++ = '\0';
fmt++;
continue;
case 'N':
#if (NGX_WIN32)
*buf++ = CR;
#endif
*buf++ = LF;
fmt++;
continue;
case '%':
*buf++ = '%';
fmt++;
continue;
default:
*buf++ = *fmt++;
continue;
}
if (sign) {
if (i64 < 0) {
*buf++ = '-';
ui64 = (uint64_t) -i64;
} else {
ui64 = (uint64_t) i64;
}
}
buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);
fmt++;
} else {
*buf++ = *fmt++;
}
}
return buf;
}
|
['static void *\nngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size)\n{\n ngx_http_gzip_ctx_t *ctx = opaque;\n void *p;\n ngx_uint_t alloc;\n alloc = items * size;\n if (alloc % 512 != 0 && alloc < 8192) {\n alloc = 8192;\n }\n if (alloc <= ctx->allocated) {\n p = ctx->free_mem;\n ctx->free_mem += alloc;\n ctx->allocated -= alloc;\n ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,\n "gzip alloc: n:%ud s:%ud a:%ud p:%p",\n items, size, alloc, p);\n return p;\n }\n ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0,\n "gzip filter failed to use preallocated memory: %ud of %ud",\n items * size, ctx->allocated);\n p = ngx_palloc(ctx->request->pool, items * size);\n return p;\n}', 'void\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, ...)\n#else\nvoid\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, va_list args)\n#endif\n{\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_list args;\n#endif\n u_char errstr[NGX_MAX_ERROR_STR], *p, *last;\n if (log->file->fd == NGX_INVALID_FILE) {\n return;\n }\n last = errstr + NGX_MAX_ERROR_STR;\n ngx_memcpy(errstr, ngx_cached_err_log_time.data,\n ngx_cached_err_log_time.len);\n p = errstr + ngx_cached_err_log_time.len;\n p = ngx_snprintf(p, last - p, " [%s] ", err_levels[level]);\n p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ",\n ngx_log_pid, ngx_log_tid);\n if (log->connection) {\n p = ngx_snprintf(p, last - p, "*%uA ", log->connection);\n }\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_start(args, fmt);\n p = ngx_vsnprintf(p, last - p, fmt, args);\n va_end(args);\n#else\n p = ngx_vsnprintf(p, last - p, fmt, args);\n#endif\n if (err) {\n if (p > last - 50) {\n p = last - 50;\n *p++ = \'.\';\n *p++ = \'.\';\n *p++ = \'.\';\n }\n#if (NGX_WIN32)\n p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)\n ? " (%d: " : " (%Xd: ", err);\n#else\n p = ngx_snprintf(p, last - p, " (%d: ", err);\n#endif\n p = ngx_strerror_r(err, p, last - p);\n if (p < last) {\n *p++ = \')\';\n }\n }\n if (level != NGX_LOG_DEBUG && log->handler) {\n p = log->handler(log, p, last - p);\n }\n if (p > last - NGX_LINEFEED_SIZE) {\n p = last - NGX_LINEFEED_SIZE;\n }\n ngx_linefeed(p);\n (void) ngx_write_fd(log->file->fd, errstr, p - errstr);\n}', 'u_char * ngx_cdecl\nngx_snprintf(u_char *buf, size_t max, const char *fmt, ...)\n{\n u_char *p;\n va_list args;\n va_start(args, fmt);\n p = ngx_vsnprintf(buf, max, fmt, args);\n va_end(args);\n return p;\n}', "u_char *\nngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)\n{\n u_char *p, zero, *last;\n int d;\n float f, scale;\n size_t len, slen;\n int64_t i64;\n uint64_t ui64;\n ngx_msec_t ms;\n ngx_uint_t width, sign, hex, max_width, frac_width, i;\n ngx_str_t *v;\n ngx_variable_value_t *vv;\n if (max == 0) {\n return buf;\n }\n last = buf + max;\n while (*fmt && buf < last) {\n if (*fmt == '%') {\n i64 = 0;\n ui64 = 0;\n zero = (u_char) ((*++fmt == '0') ? '0' : ' ');\n width = 0;\n sign = 1;\n hex = 0;\n max_width = 0;\n frac_width = 0;\n slen = (size_t) -1;\n while (*fmt >= '0' && *fmt <= '9') {\n width = width * 10 + *fmt++ - '0';\n }\n for ( ;; ) {\n switch (*fmt) {\n case 'u':\n sign = 0;\n fmt++;\n continue;\n case 'm':\n max_width = 1;\n fmt++;\n continue;\n case 'X':\n hex = 2;\n sign = 0;\n fmt++;\n continue;\n case 'x':\n hex = 1;\n sign = 0;\n fmt++;\n continue;\n case '.':\n fmt++;\n while (*fmt >= '0' && *fmt <= '9') {\n frac_width = frac_width * 10 + *fmt++ - '0';\n }\n break;\n case '*':\n slen = va_arg(args, size_t);\n fmt++;\n continue;\n default:\n break;\n }\n break;\n }\n switch (*fmt) {\n case 'V':\n v = va_arg(args, ngx_str_t *);\n len = v->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, v->data, len);\n fmt++;\n continue;\n case 'v':\n vv = va_arg(args, ngx_variable_value_t *);\n len = vv->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, vv->data, len);\n fmt++;\n continue;\n case 's':\n p = va_arg(args, u_char *);\n if (slen == (size_t) -1) {\n while (*p && buf < last) {\n *buf++ = *p++;\n }\n } else {\n len = (buf + slen < last) ? slen : (size_t) (last - buf);\n buf = ngx_cpymem(buf, p, len);\n }\n fmt++;\n continue;\n case 'O':\n i64 = (int64_t) va_arg(args, off_t);\n sign = 1;\n break;\n case 'P':\n i64 = (int64_t) va_arg(args, ngx_pid_t);\n sign = 1;\n break;\n case 'T':\n i64 = (int64_t) va_arg(args, time_t);\n sign = 1;\n break;\n case 'M':\n ms = (ngx_msec_t) va_arg(args, ngx_msec_t);\n if ((ngx_msec_int_t) ms == -1) {\n sign = 1;\n i64 = -1;\n } else {\n sign = 0;\n ui64 = (uint64_t) ms;\n }\n break;\n case 'z':\n if (sign) {\n i64 = (int64_t) va_arg(args, ssize_t);\n } else {\n ui64 = (uint64_t) va_arg(args, size_t);\n }\n break;\n case 'i':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_uint_t);\n }\n if (max_width) {\n width = NGX_INT_T_LEN;\n }\n break;\n case 'd':\n if (sign) {\n i64 = (int64_t) va_arg(args, int);\n } else {\n ui64 = (uint64_t) va_arg(args, u_int);\n }\n break;\n case 'l':\n if (sign) {\n i64 = (int64_t) va_arg(args, long);\n } else {\n ui64 = (uint64_t) va_arg(args, u_long);\n }\n break;\n case 'D':\n if (sign) {\n i64 = (int64_t) va_arg(args, int32_t);\n } else {\n ui64 = (uint64_t) va_arg(args, uint32_t);\n }\n break;\n case 'L':\n if (sign) {\n i64 = va_arg(args, int64_t);\n } else {\n ui64 = va_arg(args, uint64_t);\n }\n break;\n case 'A':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_atomic_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);\n }\n if (max_width) {\n width = NGX_ATOMIC_T_LEN;\n }\n break;\n case 'f':\n f = (float) va_arg(args, double);\n if (f < 0) {\n *buf++ = '-';\n f = -f;\n }\n ui64 = (int64_t) f;\n buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);\n if (frac_width) {\n if (buf < last) {\n *buf++ = '.';\n }\n scale = 1.0;\n for (i = 0; i < frac_width; i++) {\n scale *= 10.0;\n }\n ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);\n buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);\n }\n fmt++;\n continue;\n#if !(NGX_WIN32)\n case 'r':\n i64 = (int64_t) va_arg(args, rlim_t);\n sign = 1;\n break;\n#endif\n case 'p':\n ui64 = (uintptr_t) va_arg(args, void *);\n hex = 2;\n sign = 0;\n zero = '0';\n width = NGX_PTR_SIZE * 2;\n break;\n case 'c':\n d = va_arg(args, int);\n *buf++ = (u_char) (d & 0xff);\n fmt++;\n continue;\n case 'Z':\n *buf++ = '\\0';\n fmt++;\n continue;\n case 'N':\n#if (NGX_WIN32)\n *buf++ = CR;\n#endif\n *buf++ = LF;\n fmt++;\n continue;\n case '%':\n *buf++ = '%';\n fmt++;\n continue;\n default:\n *buf++ = *fmt++;\n continue;\n }\n if (sign) {\n if (i64 < 0) {\n *buf++ = '-';\n ui64 = (uint64_t) -i64;\n } else {\n ui64 = (uint64_t) i64;\n }\n }\n buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);\n fmt++;\n } else {\n *buf++ = *fmt++;\n }\n }\n return buf;\n}"]
|
2,726
| 0
|
https://github.com/libav/libav/blob/0dc7df28dd50167722550fb20c57327398e32e9f/ffmpeg.c/#L3862
|
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}']
|
2,727
| 0
|
https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/bn/bn_lib.c/#L404
|
int BN_set_word(BIGNUM *a, BN_ULONG w)
{
bn_check_top(a);
if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
return (0);
a->neg = 0;
a->d[0] = w;
a->top = (w ? 1 : 0);
bn_check_top(a);
return 1;
}
|
['static int ecp_nistz256_windowed_mul(const EC_GROUP *group,\n P256_POINT *r,\n const BIGNUM **scalar,\n const EC_POINT **point,\n size_t num, BN_CTX *ctx)\n{\n size_t i;\n int j, ret = 0;\n unsigned int idx;\n unsigned char (*p_str)[33] = NULL;\n const unsigned int window_size = 5;\n const unsigned int mask = (1 << (window_size + 1)) - 1;\n unsigned int wvalue;\n P256_POINT *temp;\n const BIGNUM **scalars = NULL;\n P256_POINT (*table)[16] = NULL;\n void *table_storage = NULL;\n if ((num * 16 + 6) > OPENSSL_MALLOC_MAX_NELEMS(P256_POINT)\n || (table_storage =\n OPENSSL_malloc((num * 16 + 5) * sizeof(P256_POINT) + 64)) == NULL\n || (p_str =\n OPENSSL_malloc(num * 33 * sizeof(unsigned char))) == NULL\n || (scalars = OPENSSL_malloc(num * sizeof(BIGNUM *))) == NULL) {\n ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n table = (void *)ALIGNPTR(table_storage, 64);\n temp = (P256_POINT *)(table + num);\n for (i = 0; i < num; i++) {\n P256_POINT *row = table[i];\n if ((BN_num_bits(scalar[i]) > 256) || BN_is_negative(scalar[i])) {\n BIGNUM *mod;\n if ((mod = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_nnmod(mod, scalar[i], group->order, ctx)) {\n ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, ERR_R_BN_LIB);\n goto err;\n }\n scalars[i] = mod;\n } else\n scalars[i] = scalar[i];\n for (j = 0; j < bn_get_top(scalars[i]) * BN_BYTES; j += BN_BYTES) {\n BN_ULONG d = bn_get_words(scalars[i])[j / BN_BYTES];\n p_str[i][j + 0] = (unsigned char)d;\n p_str[i][j + 1] = (unsigned char)(d >> 8);\n p_str[i][j + 2] = (unsigned char)(d >> 16);\n p_str[i][j + 3] = (unsigned char)(d >>= 24);\n if (BN_BYTES == 8) {\n d >>= 8;\n p_str[i][j + 4] = (unsigned char)d;\n p_str[i][j + 5] = (unsigned char)(d >> 8);\n p_str[i][j + 6] = (unsigned char)(d >> 16);\n p_str[i][j + 7] = (unsigned char)(d >> 24);\n }\n }\n for (; j < 33; j++)\n p_str[i][j] = 0;\n if (!ecp_nistz256_bignum_to_field_elem(temp[0].X, point[i]->X)\n || !ecp_nistz256_bignum_to_field_elem(temp[0].Y, point[i]->Y)\n || !ecp_nistz256_bignum_to_field_elem(temp[0].Z, point[i]->Z)) {\n ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL,\n EC_R_COORDINATES_OUT_OF_RANGE);\n goto err;\n }\n ecp_nistz256_scatter_w5 (row, &temp[0], 1);\n ecp_nistz256_point_double(&temp[1], &temp[0]);\n ecp_nistz256_scatter_w5 (row, &temp[1], 2);\n ecp_nistz256_point_add (&temp[2], &temp[1], &temp[0]);\n ecp_nistz256_scatter_w5 (row, &temp[2], 3);\n ecp_nistz256_point_double(&temp[1], &temp[1]);\n ecp_nistz256_scatter_w5 (row, &temp[1], 4);\n ecp_nistz256_point_double(&temp[2], &temp[2]);\n ecp_nistz256_scatter_w5 (row, &temp[2], 6);\n ecp_nistz256_point_add (&temp[3], &temp[1], &temp[0]);\n ecp_nistz256_scatter_w5 (row, &temp[3], 5);\n ecp_nistz256_point_add (&temp[4], &temp[2], &temp[0]);\n ecp_nistz256_scatter_w5 (row, &temp[4], 7);\n ecp_nistz256_point_double(&temp[1], &temp[1]);\n ecp_nistz256_scatter_w5 (row, &temp[1], 8);\n ecp_nistz256_point_double(&temp[2], &temp[2]);\n ecp_nistz256_scatter_w5 (row, &temp[2], 12);\n ecp_nistz256_point_double(&temp[3], &temp[3]);\n ecp_nistz256_scatter_w5 (row, &temp[3], 10);\n ecp_nistz256_point_double(&temp[4], &temp[4]);\n ecp_nistz256_scatter_w5 (row, &temp[4], 14);\n ecp_nistz256_point_add (&temp[2], &temp[2], &temp[0]);\n ecp_nistz256_scatter_w5 (row, &temp[2], 13);\n ecp_nistz256_point_add (&temp[3], &temp[3], &temp[0]);\n ecp_nistz256_scatter_w5 (row, &temp[3], 11);\n ecp_nistz256_point_add (&temp[4], &temp[4], &temp[0]);\n ecp_nistz256_scatter_w5 (row, &temp[4], 15);\n ecp_nistz256_point_add (&temp[2], &temp[1], &temp[0]);\n ecp_nistz256_scatter_w5 (row, &temp[2], 9);\n ecp_nistz256_point_double(&temp[1], &temp[1]);\n ecp_nistz256_scatter_w5 (row, &temp[1], 16);\n }\n idx = 255;\n wvalue = p_str[0][(idx - 1) / 8];\n wvalue = (wvalue >> ((idx - 1) % 8)) & mask;\n ecp_nistz256_gather_w5(&temp[0], table[0], _booth_recode_w5(wvalue) >> 1);\n memcpy(r, &temp[0], sizeof(temp[0]));\n while (idx >= 5) {\n for (i = (idx == 255 ? 1 : 0); i < num; i++) {\n unsigned int off = (idx - 1) / 8;\n wvalue = p_str[i][off] | p_str[i][off + 1] << 8;\n wvalue = (wvalue >> ((idx - 1) % 8)) & mask;\n wvalue = _booth_recode_w5(wvalue);\n ecp_nistz256_gather_w5(&temp[0], table[i], wvalue >> 1);\n ecp_nistz256_neg(temp[1].Y, temp[0].Y);\n copy_conditional(temp[0].Y, temp[1].Y, (wvalue & 1));\n ecp_nistz256_point_add(r, r, &temp[0]);\n }\n idx -= window_size;\n ecp_nistz256_point_double(r, r);\n ecp_nistz256_point_double(r, r);\n ecp_nistz256_point_double(r, r);\n ecp_nistz256_point_double(r, r);\n ecp_nistz256_point_double(r, r);\n }\n for (i = 0; i < num; i++) {\n wvalue = p_str[i][0];\n wvalue = (wvalue << 1) & mask;\n wvalue = _booth_recode_w5(wvalue);\n ecp_nistz256_gather_w5(&temp[0], table[i], wvalue >> 1);\n ecp_nistz256_neg(temp[1].Y, temp[0].Y);\n copy_conditional(temp[0].Y, temp[1].Y, wvalue & 1);\n ecp_nistz256_point_add(r, r, &temp[0]);\n }\n ret = 1;\n err:\n OPENSSL_free(table_storage);\n OPENSSL_free(p_str);\n OPENSSL_free(scalars);\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_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}', '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}']
|
2,728
| 0
|
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/sha/sha1dgst.c/#L157
|
void SHA1_Update(SHA_CTX *c, register unsigned char *data,
unsigned long len)
{
register SHA_LONG *p;
int ew,ec,sw,sc;
SHA_LONG l;
if (len == 0) return;
l=(c->Nl+(len<<3))&0xffffffffL;
if (l < c->Nl)
c->Nh++;
c->Nh+=(len>>29);
c->Nl=l;
if (c->num != 0)
{
p=c->data;
sw=c->num>>2;
sc=c->num&0x03;
if ((c->num+len) >= SHA_CBLOCK)
{
l= p[sw];
M_p_c2nl(data,l,sc);
p[sw++]=l;
for (; sw<SHA_LBLOCK; sw++)
{
M_c2nl(data,l);
p[sw]=l;
}
len-=(SHA_CBLOCK-c->num);
sha1_block(c,p,64);
c->num=0;
}
else
{
c->num+=(int)len;
if ((sc+len) < 4)
{
l= p[sw];
M_p_c2nl_p(data,l,sc,len);
p[sw]=l;
}
else
{
ew=(c->num>>2);
ec=(c->num&0x03);
l= p[sw];
M_p_c2nl(data,l,sc);
p[sw++]=l;
for (; sw < ew; sw++)
{ M_c2nl(data,l); p[sw]=l; }
if (ec)
{
M_c2nl_p(data,l,ec);
p[sw]=l;
}
}
return;
}
}
#if 1
#if defined(B_ENDIAN) || defined(SHA1_ASM)
if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
{
sw=len/SHA_CBLOCK;
if (sw)
{
sw*=SHA_CBLOCK;
sha1_block(c,(SHA_LONG *)data,sw);
data+=sw;
len-=sw;
}
}
#endif
#endif
p=c->data;
while (len >= SHA_CBLOCK)
{
#if defined(B_ENDIAN) || defined(L_ENDIAN)
if (p != (SHA_LONG *)data)
memcpy(p,data,SHA_CBLOCK);
data+=SHA_CBLOCK;
# ifdef L_ENDIAN
# ifndef SHA1_ASM
for (sw=(SHA_LBLOCK/4); sw; sw--)
{
Endian_Reverse32(p[0]);
Endian_Reverse32(p[1]);
Endian_Reverse32(p[2]);
Endian_Reverse32(p[3]);
p+=4;
}
p=c->data;
# endif
# endif
#else
for (sw=(SHA_BLOCK/4); sw; sw--)
{
M_c2nl(data,l); *(p++)=l;
M_c2nl(data,l); *(p++)=l;
M_c2nl(data,l); *(p++)=l;
M_c2nl(data,l); *(p++)=l;
}
p=c->data;
#endif
sha1_block(c,p,64);
len-=SHA_CBLOCK;
}
ec=(int)len;
c->num=ec;
ew=(ec>>2);
ec&=0x03;
for (sw=0; sw < ew; sw++)
{ M_c2nl(data,l); p[sw]=l; }
M_c2nl_p(data,l,ec);
p[sw]=l;
}
|
['DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,\n\t int *counter_ret, unsigned long *h_ret, void (*callback)(),\n\t char *cb_arg)\n\t{\n\tint ok=0;\n\tunsigned char seed[SHA_DIGEST_LENGTH];\n\tunsigned char md[SHA_DIGEST_LENGTH];\n\tunsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH];\n\tBIGNUM *r0,*W,*X,*c,*test;\n\tBIGNUM *g=NULL,*q=NULL,*p=NULL;\n\tBN_MONT_CTX *mont=NULL;\n\tint k,n=0,i,b,m=0;\n\tint counter=0;\n\tBN_CTX *ctx=NULL,*ctx2=NULL;\n\tunsigned int h=2;\n\tDSA *ret=NULL;\n\tif (bits < 512) bits=512;\n\tbits=(bits+63)/64*64;\n\tif ((seed_in != NULL) && (seed_len == 20))\n\t\tmemcpy(seed,seed_in,seed_len);\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tif ((ctx2=BN_CTX_new()) == NULL) goto err;\n\tif ((ret=DSA_new()) == NULL) goto err;\n\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\tr0= &(ctx2->bn[0]);\n\tg= &(ctx2->bn[1]);\n\tW= &(ctx2->bn[2]);\n\tq= &(ctx2->bn[3]);\n\tX= &(ctx2->bn[4]);\n\tc= &(ctx2->bn[5]);\n\tp= &(ctx2->bn[6]);\n\ttest= &(ctx2->bn[7]);\n\tBN_lshift(test,BN_value_one(),bits-1);\n\tfor (;;)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tif (callback != NULL) callback(0,m++,cb_arg);\n\t\t\tif (!seed_len)\n\t\t\t\tRAND_bytes(seed,SHA_DIGEST_LENGTH);\n\t\t\telse\n\t\t\t\tseed_len=0;\n\t\t\tmemcpy(buf,seed,SHA_DIGEST_LENGTH);\n\t\t\tmemcpy(buf2,seed,SHA_DIGEST_LENGTH);\n\t\t\tfor (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)\n\t\t\t\t{\n\t\t\t\tbuf[i]++;\n\t\t\t\tif (buf[i] != 0) break;\n\t\t\t\t}\n\t\t\tHASH(seed,SHA_DIGEST_LENGTH,md);\n\t\t\tHASH(buf,SHA_DIGEST_LENGTH,buf2);\n\t\t\tfor (i=0; i<SHA_DIGEST_LENGTH; i++)\n\t\t\t\tmd[i]^=buf2[i];\n\t\t\tmd[0]|=0x80;\n\t\t\tmd[SHA_DIGEST_LENGTH-1]|=0x01;\n\t\t\tif (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) abort();\n\t\t\tif (DSA_is_prime(q,callback,cb_arg) > 0) break;\n\t\t\t}\n\t\tif (callback != NULL) callback(2,0,cb_arg);\n\t\tif (callback != NULL) callback(3,0,cb_arg);\n\t\tcounter=0;\n\t\tn=(bits-1)/160;\n\t\tb=(bits-1)-n*160;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tBN_zero(W);\n\t\t\tfor (k=0; k<=n; k++)\n\t\t\t\t{\n\t\t\t\tfor (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)\n\t\t\t\t\t{\n\t\t\t\t\tbuf[i]++;\n\t\t\t\t\tif (buf[i] != 0) break;\n\t\t\t\t\t}\n\t\t\t\tHASH(buf,SHA_DIGEST_LENGTH,md);\n\t\t\t\tif (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0)) abort();\n\t\t\t\tBN_lshift(r0,r0,160*k);\n\t\t\t\tBN_add(W,W,r0);\n\t\t\t\t}\n\t\t\tBN_mask_bits(W,bits-1);\n\t\t\tBN_copy(X,W);\n\t\t\tBN_add(X,X,test);\n\t\t\tBN_lshift1(r0,q);\n\t\t\tBN_mod(c,X,r0,ctx);\n\t\t\tBN_sub(r0,c,BN_value_one());\n\t\t\tBN_sub(p,X,r0);\n\t\t\tif (BN_cmp(p,test) >= 0)\n\t\t\t\t{\n\t\t\t\tif (DSA_is_prime(p,callback,cb_arg) > 0)\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tcounter++;\n\t\t\tif (counter >= 4096) break;\n\t\t\tif (callback != NULL) callback(0,counter,cb_arg);\n\t\t\t}\n\t\t}\nend:\n\tif (callback != NULL) callback(2,1,cb_arg);\n BN_sub(test,p,BN_value_one());\n BN_div(r0,NULL,test,q,ctx);\n\tBN_set_word(test,h);\n\tBN_MONT_CTX_set(mont,p,ctx);\n\tfor (;;)\n\t\t{\n\t\tBN_mod_exp_mont(g,test,r0,p,ctx,mont);\n\t\tif (!BN_is_one(g)) break;\n\t\tBN_add(test,test,BN_value_one());\n\t\th++;\n\t\t}\n\tif (callback != NULL) callback(3,1,cb_arg);\n\tok=1;\nerr:\n\tif (!ok)\n\t\t{\n\t\tif (ret != NULL) DSA_free(ret);\n\t\t}\n\telse\n\t\t{\n\t\tret->p=BN_dup(p);\n\t\tret->q=BN_dup(q);\n\t\tret->g=BN_dup(g);\n\t\tif ((m > 1) && (seed_in != NULL)) memcpy(seed_in,seed,20);\n\t\tif (counter_ret != NULL) *counter_ret=counter;\n\t\tif (h_ret != NULL) *h_ret=h;\n\t\t}\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tif (ctx != NULL) BN_CTX_free(ctx2);\n\tif (mont != NULL) BN_MONT_CTX_free(mont);\n\treturn(ok?ret:NULL);\n\t}', 'unsigned char *SHA1(unsigned char *d, unsigned long n, unsigned char *md)\n\t{\n\tSHA_CTX c;\n\tstatic unsigned char m[SHA_DIGEST_LENGTH];\n\tif (md == NULL) md=m;\n\tSHA1_Init(&c);\n\tSHA1_Update(&c,d,n);\n\tSHA1_Final(md,&c);\n\tmemset(&c,0,sizeof(c));\n\treturn(md);\n\t}', 'void SHA1_Update(SHA_CTX *c, register unsigned char *data,\n\t unsigned long len)\n\t{\n\tregister SHA_LONG *p;\n\tint ew,ec,sw,sc;\n\tSHA_LONG l;\n\tif (len == 0) return;\n\tl=(c->Nl+(len<<3))&0xffffffffL;\n\tif (l < c->Nl)\n\t\tc->Nh++;\n\tc->Nh+=(len>>29);\n\tc->Nl=l;\n\tif (c->num != 0)\n\t\t{\n\t\tp=c->data;\n\t\tsw=c->num>>2;\n\t\tsc=c->num&0x03;\n\t\tif ((c->num+len) >= SHA_CBLOCK)\n\t\t\t{\n\t\t\tl= p[sw];\n\t\t\tM_p_c2nl(data,l,sc);\n\t\t\tp[sw++]=l;\n\t\t\tfor (; sw<SHA_LBLOCK; sw++)\n\t\t\t\t{\n\t\t\t\tM_c2nl(data,l);\n\t\t\t\tp[sw]=l;\n\t\t\t\t}\n\t\t\tlen-=(SHA_CBLOCK-c->num);\n\t\t\tsha1_block(c,p,64);\n\t\t\tc->num=0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tc->num+=(int)len;\n\t\t\tif ((sc+len) < 4)\n\t\t\t\t{\n\t\t\t\tl= p[sw];\n\t\t\t\tM_p_c2nl_p(data,l,sc,len);\n\t\t\t\tp[sw]=l;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tew=(c->num>>2);\n\t\t\t\tec=(c->num&0x03);\n\t\t\t\tl= p[sw];\n\t\t\t\tM_p_c2nl(data,l,sc);\n\t\t\t\tp[sw++]=l;\n\t\t\t\tfor (; sw < ew; sw++)\n\t\t\t\t\t{ M_c2nl(data,l); p[sw]=l; }\n\t\t\t\tif (ec)\n\t\t\t\t\t{\n\t\t\t\t\tM_c2nl_p(data,l,ec);\n\t\t\t\t\tp[sw]=l;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\treturn;\n\t\t\t}\n\t\t}\n#if 1\n#if defined(B_ENDIAN) || defined(SHA1_ASM)\n\tif ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)\n\t\t{\n\t\tsw=len/SHA_CBLOCK;\n\t\tif (sw)\n\t\t\t{\n\t\t\tsw*=SHA_CBLOCK;\n\t\t\tsha1_block(c,(SHA_LONG *)data,sw);\n\t\t\tdata+=sw;\n\t\t\tlen-=sw;\n\t\t\t}\n\t\t}\n#endif\n#endif\n\tp=c->data;\n\twhile (len >= SHA_CBLOCK)\n\t\t{\n#if defined(B_ENDIAN) || defined(L_ENDIAN)\n\t\tif (p != (SHA_LONG *)data)\n\t\t\tmemcpy(p,data,SHA_CBLOCK);\n\t\tdata+=SHA_CBLOCK;\n# ifdef L_ENDIAN\n# ifndef SHA1_ASM\n\t\tfor (sw=(SHA_LBLOCK/4); sw; sw--)\n\t\t\t{\n\t\t\tEndian_Reverse32(p[0]);\n\t\t\tEndian_Reverse32(p[1]);\n\t\t\tEndian_Reverse32(p[2]);\n\t\t\tEndian_Reverse32(p[3]);\n\t\t\tp+=4;\n\t\t\t}\n\t\tp=c->data;\n# endif\n# endif\n#else\n\t\tfor (sw=(SHA_BLOCK/4); sw; sw--)\n\t\t\t{\n\t\t\tM_c2nl(data,l); *(p++)=l;\n\t\t\tM_c2nl(data,l); *(p++)=l;\n\t\t\tM_c2nl(data,l); *(p++)=l;\n\t\t\tM_c2nl(data,l); *(p++)=l;\n\t\t\t}\n\t\tp=c->data;\n#endif\n\t\tsha1_block(c,p,64);\n\t\tlen-=SHA_CBLOCK;\n\t\t}\n\tec=(int)len;\n\tc->num=ec;\n\tew=(ec>>2);\n\tec&=0x03;\n\tfor (sw=0; sw < ew; sw++)\n\t\t{ M_c2nl(data,l); p[sw]=l; }\n\tM_c2nl_p(data,l,ec);\n\tp[sw]=l;\n\t}']
|
2,729
| 0
|
https://github.com/libav/libav/blob/47399ccdfd93d337c96c76fbf591f0e3637131ef/libavcodec/bitstream.h/#L138
|
static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
bc->bits >>= n;
#else
uint64_t ret = bc->bits >> (64 - n);
bc->bits <<= n;
#endif
bc->bits_left -= n;
return ret;
}
|
['int ff_flac_decode_frame_header(AVCodecContext *avctx, BitstreamContext *bc,\n FLACFrameInfo *fi, int log_level_offset)\n{\n int bs_code, sr_code, bps_code;\n if ((bitstream_read(bc, 15) & 0x7FFF) != 0x7FFC) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\\n");\n return AVERROR_INVALIDDATA;\n }\n fi->is_var_size = bitstream_read_bit(bc);\n bs_code = bitstream_read(bc, 4);\n sr_code = bitstream_read(bc, 4);\n fi->ch_mode = bitstream_read(bc, 4);\n if (fi->ch_mode < FLAC_MAX_CHANNELS) {\n fi->channels = fi->ch_mode + 1;\n fi->ch_mode = FLAC_CHMODE_INDEPENDENT;\n } else if (fi->ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {\n fi->channels = 2;\n fi->ch_mode -= FLAC_MAX_CHANNELS - 1;\n } else {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "invalid channel mode: %d\\n", fi->ch_mode);\n return AVERROR_INVALIDDATA;\n }\n bps_code = bitstream_read(bc, 3);\n if (bps_code == 3 || bps_code == 7) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "invalid sample size code (%d)\\n",\n bps_code);\n return AVERROR_INVALIDDATA;\n }\n fi->bps = sample_size_table[bps_code];\n if (bitstream_read_bit(bc)) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "broken stream, invalid padding\\n");\n return AVERROR_INVALIDDATA;\n }\n fi->frame_or_sample_num = get_utf8(bc);\n if (fi->frame_or_sample_num < 0) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "sample/frame number invalid; utf8 fscked\\n");\n return AVERROR_INVALIDDATA;\n }\n if (bs_code == 0) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "reserved blocksize code: 0\\n");\n return AVERROR_INVALIDDATA;\n } else if (bs_code == 6) {\n fi->blocksize = bitstream_read(bc, 8) + 1;\n } else if (bs_code == 7) {\n fi->blocksize = bitstream_read(bc, 16) + 1;\n } else {\n fi->blocksize = ff_flac_blocksize_table[bs_code];\n }\n if (sr_code < 12) {\n fi->samplerate = ff_flac_sample_rate_table[sr_code];\n } else if (sr_code == 12) {\n fi->samplerate = bitstream_read(bc, 8) * 1000;\n } else if (sr_code == 13) {\n fi->samplerate = bitstream_read(bc, 16);\n } else if (sr_code == 14) {\n fi->samplerate = bitstream_read(bc, 16) * 10;\n } else {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "illegal sample rate code %d\\n",\n sr_code);\n return AVERROR_INVALIDDATA;\n }\n bitstream_skip(bc, 8);\n if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, bc->buffer,\n bitstream_tell(bc) / 8)) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "header crc mismatch\\n");\n return AVERROR_INVALIDDATA;\n }\n return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
|
2,730
| 0
|
https://github.com/openssl/openssl/blob/a68d8c7b77a3d46d591b89cfd0ecd2a2242e4613/crypto/err/err.c/#L697
|
void ERR_set_error_data(char *data, int flags)
{
ERR_STATE *es;
int i;
es = ERR_get_state();
i = es->top;
if (i == 0)
i = ERR_NUM_ERRORS - 1;
err_clear_data(es, i);
es->err_data[i] = data;
es->err_data_flags[i] = flags;
}
|
['void ERR_set_error_data(char *data, int flags)\n{\n ERR_STATE *es;\n int i;\n es = ERR_get_state();\n i = es->top;\n if (i == 0)\n i = ERR_NUM_ERRORS - 1;\n err_clear_data(es, i);\n es->err_data[i] = data;\n es->err_data_flags[i] = flags;\n}', 'ERR_STATE *ERR_get_state(void)\n{\n ERR_STATE *state = NULL;\n if (!RUN_ONCE(&err_init, err_do_init))\n return NULL;\n state = CRYPTO_THREAD_get_local(&err_thread_local);\n if (state == NULL) {\n state = OPENSSL_zalloc(sizeof(*state));\n if (state == NULL)\n return NULL;\n if (!CRYPTO_THREAD_set_local(&err_thread_local, state)) {\n ERR_STATE_free(state);\n return NULL;\n }\n OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE);\n }\n return state;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n 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}', '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}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
|
2,731
| 0
|
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/bn/bn_mul.c/#L100
|
BN_ULONG bn_sub_part_words(BN_ULONG *r,
const BN_ULONG *a, const BN_ULONG *b,
int cl, int dl)
{
BN_ULONG c, t;
assert(cl >= 0);
c = bn_sub_words(r, a, b, cl);
if (dl == 0)
return c;
r += cl;
a += cl;
b += cl;
if (dl < 0) {
for (;;) {
t = b[0];
r[0] = (0 - t - c) & BN_MASK2;
if (t != 0)
c = 1;
if (++dl >= 0)
break;
t = b[1];
r[1] = (0 - t - c) & BN_MASK2;
if (t != 0)
c = 1;
if (++dl >= 0)
break;
t = b[2];
r[2] = (0 - t - c) & BN_MASK2;
if (t != 0)
c = 1;
if (++dl >= 0)
break;
t = b[3];
r[3] = (0 - t - c) & BN_MASK2;
if (t != 0)
c = 1;
if (++dl >= 0)
break;
b += 4;
r += 4;
}
} else {
int save_dl = dl;
while (c) {
t = a[0];
r[0] = (t - c) & BN_MASK2;
if (t != 0)
c = 0;
if (--dl <= 0)
break;
t = a[1];
r[1] = (t - c) & BN_MASK2;
if (t != 0)
c = 0;
if (--dl <= 0)
break;
t = a[2];
r[2] = (t - c) & BN_MASK2;
if (t != 0)
c = 0;
if (--dl <= 0)
break;
t = a[3];
r[3] = (t - c) & BN_MASK2;
if (t != 0)
c = 0;
if (--dl <= 0)
break;
save_dl = dl;
a += 4;
r += 4;
}
if (dl > 0) {
if (save_dl > dl) {
switch (save_dl - dl) {
case 1:
r[1] = a[1];
if (--dl <= 0)
break;
case 2:
r[2] = a[2];
if (--dl <= 0)
break;
case 3:
r[3] = a[3];
if (--dl <= 0)
break;
}
a += 4;
r += 4;
}
}
if (dl > 0) {
for (;;) {
r[0] = a[0];
if (--dl <= 0)
break;
r[1] = a[1];
if (--dl <= 0)
break;
r[2] = a[2];
if (--dl <= 0)
break;
r[3] = a[3];
if (--dl <= 0)
break;
a += 4;
r += 4;
}
}
}
return c;
}
|
['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, b, bits1, bits2, ret =\n 0, wpos1, wpos2, window1, window2, wvalue1, wvalue2;\n int r_is_one = 1;\n BIGNUM *d, *r;\n const BIGNUM *a_mod_m;\n BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n bn_check_top(a1);\n bn_check_top(p1);\n bn_check_top(a2);\n bn_check_top(p2);\n bn_check_top(m);\n if (!(m->d[0] & 1)) {\n BNerr(BN_F_BN_MOD_EXP2_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n bits1 = BN_num_bits(p1);\n bits2 = BN_num_bits(p2);\n if ((bits1 == 0) && (bits2 == 0)) {\n ret = BN_one(rr);\n return ret;\n }\n bits = (bits1 > bits2) ? bits1 : bits2;\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val1[0] = BN_CTX_get(ctx);\n val2[0] = BN_CTX_get(ctx);\n if (!d || !r || !val1[0] || !val2[0])\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n window1 = BN_window_bits_for_exponent_size(bits1);\n window2 = BN_window_bits_for_exponent_size(bits2);\n if (a1->neg || BN_ucmp(a1, m) >= 0) {\n if (!BN_mod(val1[0], a1, m, ctx))\n goto err;\n a_mod_m = val1[0];\n } else\n a_mod_m = a1;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx))\n goto err;\n if (window1 > 1) {\n if (!BN_mod_mul_montgomery(d, val1[0], val1[0], mont, ctx))\n goto err;\n j = 1 << (window1 - 1);\n for (i = 1; i < j; i++) {\n if (((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val1[i], val1[i - 1], d, mont, ctx))\n goto err;\n }\n }\n if (a2->neg || BN_ucmp(a2, m) >= 0) {\n if (!BN_mod(val2[0], a2, m, ctx))\n goto err;\n a_mod_m = val2[0];\n } else\n a_mod_m = a2;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val2[0], a_mod_m, mont, ctx))\n goto err;\n if (window2 > 1) {\n if (!BN_mod_mul_montgomery(d, val2[0], val2[0], mont, ctx))\n goto err;\n j = 1 << (window2 - 1);\n for (i = 1; i < j; i++) {\n if (((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val2[i], val2[i - 1], d, mont, ctx))\n goto err;\n }\n }\n r_is_one = 1;\n wvalue1 = 0;\n wvalue2 = 0;\n wpos1 = 0;\n wpos2 = 0;\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (b = bits - 1; b >= 0; b--) {\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!wvalue1)\n if (BN_is_bit_set(p1, b)) {\n i = b - window1 + 1;\n while (!BN_is_bit_set(p1, i))\n i++;\n wpos1 = i;\n wvalue1 = 1;\n for (i = b - 1; i >= wpos1; i--) {\n wvalue1 <<= 1;\n if (BN_is_bit_set(p1, i))\n wvalue1++;\n }\n }\n if (!wvalue2)\n if (BN_is_bit_set(p2, b)) {\n i = b - window2 + 1;\n while (!BN_is_bit_set(p2, i))\n i++;\n wpos2 = i;\n wvalue2 = 1;\n for (i = b - 1; i >= wpos2; i--) {\n wvalue2 <<= 1;\n if (BN_is_bit_set(p2, i))\n wvalue2++;\n }\n }\n if (wvalue1 && b == wpos1) {\n if (!BN_mod_mul_montgomery(r, r, val1[wvalue1 >> 1], mont, ctx))\n goto err;\n wvalue1 = 0;\n r_is_one = 0;\n }\n if (wvalue2 && b == wpos2) {\n if (!BN_mod_mul_montgomery(r, r, val2[wvalue2 >> 1], mont, ctx))\n goto err;\n wvalue2 = 0;\n r_is_one = 0;\n }\n }\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if ((in_mont == NULL) && (mont != NULL))\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'const BIGNUM *BN_value_one(void)\n{\n static const BN_ULONG data_one = 1L;\n static const BIGNUM const_one =\n { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };\n return (&const_one);\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n int num = mont->N.top;\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return (0);\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return (1);\n }\n }\n#endif\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n bn_correct_top(rr);\n if (r != rr)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&(r[n2 + tn * 2]), 0, sizeof(BN_ULONG) * (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(BN_ULONG) * (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(BN_ULONG) * (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(BN_ULONG) * 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}', '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}', 'BN_ULONG bn_sub_part_words(BN_ULONG *r,\n const BN_ULONG *a, const BN_ULONG *b,\n int cl, int dl)\n{\n BN_ULONG c, t;\n assert(cl >= 0);\n c = bn_sub_words(r, a, b, cl);\n if (dl == 0)\n return c;\n r += cl;\n a += cl;\n b += cl;\n if (dl < 0) {\n for (;;) {\n t = b[0];\n r[0] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n t = b[1];\n r[1] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n t = b[2];\n r[2] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n t = b[3];\n r[3] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n b += 4;\n r += 4;\n }\n } else {\n int save_dl = dl;\n while (c) {\n t = a[0];\n r[0] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n t = a[1];\n r[1] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n t = a[2];\n r[2] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n t = a[3];\n r[3] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n save_dl = dl;\n a += 4;\n r += 4;\n }\n if (dl > 0) {\n if (save_dl > dl) {\n switch (save_dl - dl) {\n case 1:\n r[1] = a[1];\n if (--dl <= 0)\n break;\n case 2:\n r[2] = a[2];\n if (--dl <= 0)\n break;\n case 3:\n r[3] = a[3];\n if (--dl <= 0)\n break;\n }\n a += 4;\n r += 4;\n }\n }\n if (dl > 0) {\n for (;;) {\n r[0] = a[0];\n if (--dl <= 0)\n break;\n r[1] = a[1];\n if (--dl <= 0)\n break;\n r[2] = a[2];\n if (--dl <= 0)\n break;\n r[3] = a[3];\n if (--dl <= 0)\n break;\n a += 4;\n r += 4;\n }\n }\n }\n return c;\n}']
|
2,732
| 0
|
https://github.com/nginx/nginx/blob/ce05841eefe0e6c5d18ae9b0fb8f9fbd7e99afdd/src/http/ngx_http_core_module.c/#L2567
|
ngx_int_t
ngx_http_internal_redirect(ngx_http_request_t *r,
ngx_str_t *uri, ngx_str_t *args)
{
ngx_http_core_srv_conf_t *cscf;
r->uri_changes--;
if (r->uri_changes == 0) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"rewrite or internal redirection cycle "
"while internally redirecting to \"%V\"", uri);
r->main->count++;
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return NGX_DONE;
}
r->uri = *uri;
if (args) {
r->args = *args;
} else {
ngx_str_null(&r->args);
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"internal redirect: \"%V?%V\"", uri, &r->args);
ngx_http_set_exten(r);
ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
r->loc_conf = cscf->ctx->loc_conf;
ngx_http_update_location_config(r);
#if (NGX_HTTP_CACHE)
r->cache = NULL;
#endif
r->internal = 1;
r->valid_unparsed_uri = 0;
r->add_uri_to_alias = 0;
r->main->count++;
ngx_http_handler(r);
return NGX_DONE;
}
|
['static void\nngx_http_upstream_init_request(ngx_http_request_t *r)\n{\n ngx_str_t *host;\n ngx_uint_t i;\n ngx_resolver_ctx_t *ctx, temp;\n ngx_http_cleanup_t *cln;\n ngx_http_upstream_t *u;\n ngx_http_core_loc_conf_t *clcf;\n ngx_http_upstream_srv_conf_t *uscf, **uscfp;\n ngx_http_upstream_main_conf_t *umcf;\n if (r->aio) {\n return;\n }\n u = r->upstream;\n#if (NGX_HTTP_CACHE)\n if (u->conf->cache) {\n ngx_int_t rc;\n rc = ngx_http_upstream_cache(r, u);\n if (rc == NGX_BUSY) {\n r->write_event_handler = ngx_http_upstream_init_request;\n return;\n }\n r->write_event_handler = ngx_http_request_empty_handler;\n if (rc == NGX_ERROR) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (rc == NGX_OK) {\n rc = ngx_http_upstream_cache_send(r, u);\n if (rc == NGX_DONE) {\n return;\n }\n if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {\n rc = NGX_DECLINED;\n r->cached = 0;\n }\n }\n if (rc != NGX_DECLINED) {\n ngx_http_finalize_request(r, rc);\n return;\n }\n }\n#endif\n u->store = u->conf->store;\n if (!u->store && !r->post_action && !u->conf->ignore_client_abort) {\n r->read_event_handler = ngx_http_upstream_rd_check_broken_connection;\n r->write_event_handler = ngx_http_upstream_wr_check_broken_connection;\n }\n if (r->request_body) {\n u->request_bufs = r->request_body->bufs;\n }\n if (u->create_request(r) != NGX_OK) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->peer.local = ngx_http_upstream_get_local(r, u->conf->local);\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n u->output.alignment = clcf->directio_alignment;\n u->output.pool = r->pool;\n u->output.bufs.num = 1;\n u->output.bufs.size = clcf->client_body_buffer_size;\n if (u->output.output_filter == NULL) {\n u->output.output_filter = ngx_chain_writer;\n u->output.filter_ctx = &u->writer;\n }\n u->writer.pool = r->pool;\n if (r->upstream_states == NULL) {\n r->upstream_states = ngx_array_create(r->pool, 1,\n sizeof(ngx_http_upstream_state_t));\n if (r->upstream_states == NULL) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n } else {\n u->state = ngx_array_push(r->upstream_states);\n if (u->state == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));\n }\n cln = ngx_http_cleanup_add(r, 0);\n if (cln == NULL) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n cln->handler = ngx_http_upstream_cleanup;\n cln->data = r;\n u->cleanup = &cln->handler;\n if (u->resolved == NULL) {\n uscf = u->conf->upstream;\n } else {\n#if (NGX_HTTP_SSL)\n u->ssl_name = u->resolved->host;\n#endif\n if (u->resolved->sockaddr) {\n if (ngx_http_upstream_create_round_robin_peer(r, u->resolved)\n != NGX_OK)\n {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n ngx_http_upstream_connect(r, u);\n return;\n }\n host = &u->resolved->host;\n umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);\n uscfp = umcf->upstreams.elts;\n for (i = 0; i < umcf->upstreams.nelts; i++) {\n uscf = uscfp[i];\n if (uscf->host.len == host->len\n && ((uscf->port == 0 && u->resolved->no_port)\n || uscf->port == u->resolved->port)\n && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0)\n {\n goto found;\n }\n }\n if (u->resolved->port == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "no port in upstream \\"%V\\"", host);\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n temp.name = *host;\n ctx = ngx_resolve_start(clcf->resolver, &temp);\n if (ctx == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (ctx == NGX_NO_RESOLVER) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "no resolver defined to resolve %V", host);\n ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);\n return;\n }\n ctx->name = *host;\n ctx->handler = ngx_http_upstream_resolve_handler;\n ctx->data = r;\n ctx->timeout = clcf->resolver_timeout;\n u->resolved->ctx = ctx;\n if (ngx_resolve_name(ctx) != NGX_OK) {\n u->resolved->ctx = NULL;\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n return;\n }\nfound:\n if (uscf == NULL) {\n ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,\n "no upstream configuration");\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n#if (NGX_HTTP_SSL)\n u->ssl_name = uscf->host;\n#endif\n if (uscf->peer.init(r, uscf) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->peer.start_time = ngx_current_msec;\n if (u->conf->next_upstream_tries\n && u->peer.tries > u->conf->next_upstream_tries)\n {\n u->peer.tries = u->conf->next_upstream_tries;\n }\n ngx_http_upstream_connect(r, u);\n}', 'void\nngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)\n{\n ngx_connection_t *c;\n ngx_http_request_t *pr;\n ngx_http_core_loc_conf_t *clcf;\n c = r->connection;\n ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize request: %d, \\"%V?%V\\" a:%d, c:%d",\n rc, &r->uri, &r->args, r == c->data, r->main->count);\n if (rc == NGX_DONE) {\n ngx_http_finalize_connection(r);\n return;\n }\n if (rc == NGX_OK && r->filter_finalize) {\n c->error = 1;\n }\n if (rc == NGX_DECLINED) {\n r->content_handler = NULL;\n r->write_event_handler = ngx_http_core_run_phases;\n ngx_http_core_run_phases(r);\n return;\n }\n if (r != r->main && r->post_subrequest) {\n rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);\n }\n if (rc == NGX_ERROR\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n || c->error)\n {\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (r->main->blocked) {\n r->write_event_handler = ngx_http_request_finalizer;\n }\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE\n || rc == NGX_HTTP_CREATED\n || rc == NGX_HTTP_NO_CONTENT)\n {\n if (rc == NGX_HTTP_CLOSE) {\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (r == r->main) {\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n ngx_del_timer(c->write);\n }\n }\n c->read->handler = ngx_http_request_handler;\n c->write->handler = ngx_http_request_handler;\n ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));\n return;\n }\n if (r != r->main) {\n if (r->buffered || r->postponed) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n pr = r->parent;\n if (r == c->data) {\n r->main->count--;\n if (!r->logged) {\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->log_subrequest) {\n ngx_http_log_request(r);\n }\n r->logged = 1;\n } else {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "subrequest: \\"%V?%V\\" logged again",\n &r->uri, &r->args);\n }\n r->done = 1;\n if (pr->postponed && pr->postponed->request == r) {\n pr->postponed = pr->postponed->next;\n }\n c->data = pr;\n } else {\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n r->write_event_handler = ngx_http_request_finalizer;\n if (r->waited) {\n r->done = 1;\n }\n }\n if (ngx_http_post_request(pr, NULL) != NGX_OK) {\n r->main->count++;\n ngx_http_terminate_request(r, 0);\n return;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http wake parent request: \\"%V?%V\\"",\n &pr->uri, &pr->args);\n return;\n }\n if (r->buffered || c->buffered || r->postponed || r->blocked) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n if (r != c->data) {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n return;\n }\n r->done = 1;\n r->write_event_handler = ngx_http_request_empty_handler;\n if (!r->post_action) {\n r->request_complete = 1;\n }\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n c->write->delayed = 0;\n ngx_del_timer(c->write);\n }\n if (c->read->eof) {\n ngx_http_close_request(r, 0);\n return;\n }\n ngx_http_finalize_connection(r);\n}', 'static ngx_int_t\nngx_http_post_action(ngx_http_request_t *r)\n{\n ngx_http_core_loc_conf_t *clcf;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->post_action.data == NULL) {\n return NGX_DECLINED;\n }\n if (r->post_action && r->uri_changes == 0) {\n return NGX_DECLINED;\n }\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "post action: \\"%V\\"", &clcf->post_action);\n r->main->count--;\n r->http_version = NGX_HTTP_VERSION_9;\n r->header_only = 1;\n r->post_action = 1;\n r->read_event_handler = ngx_http_block_reading;\n if (clcf->post_action.data[0] == \'/\') {\n ngx_http_internal_redirect(r, &clcf->post_action, NULL);\n } else {\n ngx_http_named_location(r, &clcf->post_action);\n }\n return NGX_OK;\n}', 'ngx_int_t\nngx_http_internal_redirect(ngx_http_request_t *r,\n ngx_str_t *uri, ngx_str_t *args)\n{\n ngx_http_core_srv_conf_t *cscf;\n r->uri_changes--;\n if (r->uri_changes == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "rewrite or internal redirection cycle "\n "while internally redirecting to \\"%V\\"", uri);\n r->main->count++;\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n r->uri = *uri;\n if (args) {\n r->args = *args;\n } else {\n ngx_str_null(&r->args);\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "internal redirect: \\"%V?%V\\"", uri, &r->args);\n ngx_http_set_exten(r);\n ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);\n cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n r->loc_conf = cscf->ctx->loc_conf;\n ngx_http_update_location_config(r);\n#if (NGX_HTTP_CACHE)\n r->cache = NULL;\n#endif\n r->internal = 1;\n r->valid_unparsed_uri = 0;\n r->add_uri_to_alias = 0;\n r->main->count++;\n ngx_http_handler(r);\n return NGX_DONE;\n}']
|
2,733
| 0
|
https://github.com/libav/libav/blob/4860abb116674c7be31e825db05cdcfd30f3aff2/libavformat/matroskaenc.c/#L630
|
static int mkv_write_header(AVFormatContext *s)
{
MatroskaMuxContext *mkv = s->priv_data;
ByteIOContext *pb = s->pb;
ebml_master ebml_header, segment_info;
int ret;
mkv->md5_ctx = av_mallocz(av_md5_size);
av_md5_init(mkv->md5_ctx);
ebml_header = start_ebml_master(pb, EBML_ID_HEADER, 0);
put_ebml_uint (pb, EBML_ID_EBMLVERSION , 1);
put_ebml_uint (pb, EBML_ID_EBMLREADVERSION , 1);
put_ebml_uint (pb, EBML_ID_EBMLMAXIDLENGTH , 4);
put_ebml_uint (pb, EBML_ID_EBMLMAXSIZELENGTH , 8);
put_ebml_string (pb, EBML_ID_DOCTYPE , "matroska");
put_ebml_uint (pb, EBML_ID_DOCTYPEVERSION , 2);
put_ebml_uint (pb, EBML_ID_DOCTYPEREADVERSION , 2);
end_ebml_master(pb, ebml_header);
mkv->segment = start_ebml_master(pb, MATROSKA_ID_SEGMENT, 0);
mkv->segment_offset = url_ftell(pb);
mkv->main_seekhead = mkv_start_seekhead(pb, mkv->segment_offset, 10);
mkv->cluster_seekhead = mkv_start_seekhead(pb, mkv->segment_offset, 0);
if (mkv->main_seekhead == NULL || mkv->cluster_seekhead == NULL)
return AVERROR(ENOMEM);
ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_INFO, url_ftell(pb));
if (ret < 0) return ret;
segment_info = start_ebml_master(pb, MATROSKA_ID_INFO, 0);
put_ebml_uint(pb, MATROSKA_ID_TIMECODESCALE, 1000000);
if (strlen(s->title))
put_ebml_string(pb, MATROSKA_ID_TITLE, s->title);
if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {
put_ebml_string(pb, MATROSKA_ID_MUXINGAPP , LIBAVFORMAT_IDENT);
put_ebml_string(pb, MATROSKA_ID_WRITINGAPP, LIBAVFORMAT_IDENT);
mkv->segment_uid = url_ftell(pb);
put_ebml_void(pb, 19);
}
mkv->duration = 0;
mkv->duration_offset = url_ftell(pb);
put_ebml_void(pb, 11);
end_ebml_master(pb, segment_info);
ret = mkv_write_tracks(s);
if (ret < 0) return ret;
ret = mkv_add_seekhead_entry(mkv->cluster_seekhead, MATROSKA_ID_CLUSTER, url_ftell(pb));
if (ret < 0) return ret;
mkv->cluster_pos = url_ftell(pb);
mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER, 0);
put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, 0);
mkv->cluster_pts = 0;
mkv->cues = mkv_start_cues(mkv->segment_offset);
if (mkv->cues == NULL)
return AVERROR(ENOMEM);
return 0;
}
|
['static int mkv_write_header(AVFormatContext *s)\n{\n MatroskaMuxContext *mkv = s->priv_data;\n ByteIOContext *pb = s->pb;\n ebml_master ebml_header, segment_info;\n int ret;\n mkv->md5_ctx = av_mallocz(av_md5_size);\n av_md5_init(mkv->md5_ctx);\n ebml_header = start_ebml_master(pb, EBML_ID_HEADER, 0);\n put_ebml_uint (pb, EBML_ID_EBMLVERSION , 1);\n put_ebml_uint (pb, EBML_ID_EBMLREADVERSION , 1);\n put_ebml_uint (pb, EBML_ID_EBMLMAXIDLENGTH , 4);\n put_ebml_uint (pb, EBML_ID_EBMLMAXSIZELENGTH , 8);\n put_ebml_string (pb, EBML_ID_DOCTYPE , "matroska");\n put_ebml_uint (pb, EBML_ID_DOCTYPEVERSION , 2);\n put_ebml_uint (pb, EBML_ID_DOCTYPEREADVERSION , 2);\n end_ebml_master(pb, ebml_header);\n mkv->segment = start_ebml_master(pb, MATROSKA_ID_SEGMENT, 0);\n mkv->segment_offset = url_ftell(pb);\n mkv->main_seekhead = mkv_start_seekhead(pb, mkv->segment_offset, 10);\n mkv->cluster_seekhead = mkv_start_seekhead(pb, mkv->segment_offset, 0);\n if (mkv->main_seekhead == NULL || mkv->cluster_seekhead == NULL)\n return AVERROR(ENOMEM);\n ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_INFO, url_ftell(pb));\n if (ret < 0) return ret;\n segment_info = start_ebml_master(pb, MATROSKA_ID_INFO, 0);\n put_ebml_uint(pb, MATROSKA_ID_TIMECODESCALE, 1000000);\n if (strlen(s->title))\n put_ebml_string(pb, MATROSKA_ID_TITLE, s->title);\n if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {\n put_ebml_string(pb, MATROSKA_ID_MUXINGAPP , LIBAVFORMAT_IDENT);\n put_ebml_string(pb, MATROSKA_ID_WRITINGAPP, LIBAVFORMAT_IDENT);\n mkv->segment_uid = url_ftell(pb);\n put_ebml_void(pb, 19);\n }\n mkv->duration = 0;\n mkv->duration_offset = url_ftell(pb);\n put_ebml_void(pb, 11);\n end_ebml_master(pb, segment_info);\n ret = mkv_write_tracks(s);\n if (ret < 0) return ret;\n ret = mkv_add_seekhead_entry(mkv->cluster_seekhead, MATROSKA_ID_CLUSTER, url_ftell(pb));\n if (ret < 0) return ret;\n mkv->cluster_pos = url_ftell(pb);\n mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER, 0);\n put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, 0);\n mkv->cluster_pts = 0;\n mkv->cues = mkv_start_cues(mkv->segment_offset);\n if (mkv->cues == NULL)\n return AVERROR(ENOMEM);\n return 0;\n}', 'void *av_mallocz(unsigned int size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr;\n#ifdef CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#ifdef CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif defined (HAVE_MEMALIGN)\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'void av_md5_init(AVMD5 *ctx){\n ctx->len = 0;\n ctx->ABCD[0] = 0x10325476;\n ctx->ABCD[1] = 0x98badcfe;\n ctx->ABCD[2] = 0xefcdab89;\n ctx->ABCD[3] = 0x67452301;\n}']
|
2,734
| 0
|
https://github.com/libav/libav/blob/1db9da523815beb8e9fdcbc63205b3473616c6f0/libavcodec/mpc8.c/#L290
|
static int mpc8_decode_frame(AVCodecContext * avctx,
void *data, int *data_size,
const uint8_t * buf, int buf_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];
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;
}
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_random(&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, data);
c->cur_frame++;
c->last_bits_used = get_bits_count(gb);
if(c->cur_frame >= c->frames)
c->cur_frame = 0;
*data_size = MPC_FRAME_SIZE * 4;
return c->cur_frame ? c->last_bits_used >> 3 : buf_size;
}
|
['static int mpc8_decode_frame(AVCodecContext * avctx,\n void *data, int *data_size,\n const uint8_t * buf, int buf_size)\n{\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 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 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_random(&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, data);\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 *data_size = MPC_FRAME_SIZE * 4;\n return c->cur_frame ? c->last_bits_used >> 3 : buf_size;\n}', 'static inline unsigned int av_random(AVRandomState *state)\n{\n unsigned int y;\n if (state->index >= AV_RANDOM_N)\n av_random_generate_untempered_numbers(state);\n y = state->mt[state->index++];\n y ^= (y >> 11);\n y ^= (y << 7) & 0x9d2c5680;\n y ^= (y << 15) & 0xefc60000;\n y ^= (y >> 18);\n return y;\n}']
|
2,735
| 0
|
https://github.com/openssl/openssl/blob/02cba628daa7fea959c561531a8a984756bdf41c/crypto/bn/bn_shift.c/#L112
|
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return (0);
r->neg = a->neg;
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return (1);
}
|
['int dhparam_main(int argc, char **argv)\n{\n BIO *in = NULL, *out = NULL;\n DH *dh = NULL;\n char *infile = NULL, *outfile = NULL, *prog, *inrand = NULL;\n ENGINE *e = NULL;\n#ifndef OPENSSL_NO_DSA\n int dsaparam = 0;\n#endif\n int i, text = 0, C = 0, ret = 1, num = 0, g = 0;\n int informat = FORMAT_PEM, outformat = FORMAT_PEM, check = 0, noout = 0;\n OPTION_CHOICE o;\n prog = opt_init(argc, argv, dhparam_options);\n while ((o = opt_next()) != OPT_EOF) {\n switch (o) {\n case OPT_EOF:\n case OPT_ERR:\n opthelp:\n BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n goto end;\n case OPT_HELP:\n opt_help(dhparam_options);\n ret = 0;\n goto end;\n case OPT_INFORM:\n if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat))\n goto opthelp;\n break;\n case OPT_OUTFORM:\n if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat))\n goto opthelp;\n break;\n case OPT_IN:\n infile = opt_arg();\n break;\n case OPT_OUT:\n outfile = opt_arg();\n break;\n case OPT_ENGINE:\n e = setup_engine(opt_arg(), 0);\n break;\n case OPT_CHECK:\n check = 1;\n break;\n case OPT_TEXT:\n text = 1;\n break;\n case OPT_DSAPARAM:\n#ifndef OPENSSL_NO_DSA\n dsaparam = 1;\n#endif\n break;\n case OPT_C:\n C = 1;\n break;\n case OPT_2:\n g = 2;\n break;\n case OPT_5:\n g = 5;\n break;\n case OPT_NOOUT:\n noout = 1;\n break;\n case OPT_RAND:\n inrand = opt_arg();\n break;\n }\n }\n argc = opt_num_rest();\n argv = opt_rest();\n if (argv[0] && (!opt_int(argv[0], &num) || num <= 0))\n goto end;\n if (g && !num)\n num = DEFBITS;\n# ifndef OPENSSL_NO_DSA\n if (dsaparam && g) {\n BIO_printf(bio_err,\n "generator may not be chosen for DSA parameters\\n");\n goto end;\n }\n# endif\n if (num && !g)\n g = 2;\n if (num) {\n BN_GENCB *cb;\n cb = BN_GENCB_new();\n if (cb == NULL) {\n ERR_print_errors(bio_err);\n goto end;\n }\n BN_GENCB_set(cb, dh_cb, bio_err);\n if (!app_RAND_load_file(NULL, 1) && inrand == NULL) {\n BIO_printf(bio_err,\n "warning, not much extra random data, consider using the -rand option\\n");\n }\n if (inrand != NULL)\n BIO_printf(bio_err, "%ld semi-random bytes loaded\\n",\n app_RAND_load_files(inrand));\n# ifndef OPENSSL_NO_DSA\n if (dsaparam) {\n DSA *dsa = DSA_new();\n BIO_printf(bio_err,\n "Generating DSA parameters, %d bit long prime\\n", num);\n if (dsa == NULL\n || !DSA_generate_parameters_ex(dsa, num, NULL, 0, NULL, NULL,\n cb)) {\n DSA_free(dsa);\n BN_GENCB_free(cb);\n ERR_print_errors(bio_err);\n goto end;\n }\n dh = DSA_dup_DH(dsa);\n DSA_free(dsa);\n if (dh == NULL) {\n BN_GENCB_free(cb);\n ERR_print_errors(bio_err);\n goto end;\n }\n } else\n# endif\n {\n dh = DH_new();\n BIO_printf(bio_err,\n "Generating DH parameters, %d bit long safe prime, generator %d\\n",\n num, g);\n BIO_printf(bio_err, "This is going to take a long time\\n");\n if (dh == NULL || !DH_generate_parameters_ex(dh, num, g, cb)) {\n BN_GENCB_free(cb);\n ERR_print_errors(bio_err);\n goto end;\n }\n }\n BN_GENCB_free(cb);\n app_RAND_write_file(NULL);\n } else {\n in = bio_open_default(infile, \'r\', informat);\n if (in == NULL)\n goto end;\n# ifndef OPENSSL_NO_DSA\n if (dsaparam) {\n DSA *dsa;\n if (informat == FORMAT_ASN1)\n dsa = d2i_DSAparams_bio(in, NULL);\n else\n dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL);\n if (dsa == NULL) {\n BIO_printf(bio_err, "unable to load DSA parameters\\n");\n ERR_print_errors(bio_err);\n goto end;\n }\n dh = DSA_dup_DH(dsa);\n DSA_free(dsa);\n if (dh == NULL) {\n ERR_print_errors(bio_err);\n goto end;\n }\n } else\n# endif\n {\n if (informat == FORMAT_ASN1)\n dh = d2i_DHparams_bio(in, NULL);\n else\n dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);\n if (dh == NULL) {\n BIO_printf(bio_err, "unable to load DH parameters\\n");\n ERR_print_errors(bio_err);\n goto end;\n }\n }\n }\n out = bio_open_default(outfile, \'w\', outformat);\n if (out == NULL)\n goto end;\n if (text) {\n DHparams_print(out, dh);\n }\n if (check) {\n if (!DH_check(dh, &i)) {\n ERR_print_errors(bio_err);\n goto end;\n }\n if (i & DH_CHECK_P_NOT_PRIME)\n BIO_printf(bio_err, "WARNING: p value is not prime\\n");\n if (i & DH_CHECK_P_NOT_SAFE_PRIME)\n BIO_printf(bio_err, "WARNING: p value is not a safe prime\\n");\n if (i & DH_CHECK_Q_NOT_PRIME)\n BIO_printf(bio_err, "WARNING: q value is not a prime\\n");\n if (i & DH_CHECK_INVALID_Q_VALUE)\n BIO_printf(bio_err, "WARNING: q value is invalid\\n");\n if (i & DH_CHECK_INVALID_J_VALUE)\n BIO_printf(bio_err, "WARNING: j value is invalid\\n");\n if (i & DH_UNABLE_TO_CHECK_GENERATOR)\n BIO_printf(bio_err,\n "WARNING: unable to check the generator value\\n");\n if (i & DH_NOT_SUITABLE_GENERATOR)\n BIO_printf(bio_err, "WARNING: the g value is not a generator\\n");\n if (i == 0)\n BIO_printf(bio_err, "DH parameters appear to be ok.\\n");\n if (num != 0 && i != 0) {\n BIO_printf(bio_err, "ERROR: Invalid parameters generated\\n");\n goto end;\n }\n }\n if (C) {\n unsigned char *data;\n int len, bits;\n const BIGNUM *pbn, *gbn;\n len = DH_size(dh);\n bits = DH_bits(dh);\n DH_get0_pqg(dh, &pbn, NULL, &gbn);\n data = app_malloc(len, "print a BN");\n BIO_printf(out, "#ifndef HEADER_DH_H\\n"\n "# include <openssl/dh.h>\\n"\n "#endif\\n"\n "\\n");\n BIO_printf(out, "DH *get_dh%d()\\n{\\n", bits);\n print_bignum_var(out, pbn, "dhp", bits, data);\n print_bignum_var(out, gbn, "dhg", bits, data);\n BIO_printf(out, " DH *dh = DH_new();\\n"\n " BIGNUM *dhp_bn, *dhg_bn;\\n"\n "\\n"\n " if (dh == NULL)\\n"\n " return NULL;\\n");\n BIO_printf(out, " dhp_bn = BN_bin2bn(dhp_%d, sizeof (dhp_%d), NULL);\\n",\n bits, bits);\n BIO_printf(out, " dhg_bn = BN_bin2bn(dhg_%d, sizeof (dhg_%d), NULL);\\n",\n bits, bits);\n BIO_printf(out, " if (dhp_bn == NULL || dhg_bn == NULL\\n"\n " || !DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn)) {\\n"\n " DH_free(dh);\\n"\n " BN_free(dhp_bn);\\n"\n " BN_free(dhg_bn);\\n"\n " return NULL;\\n"\n " }\\n");\n if (DH_get_length(dh) > 0)\n BIO_printf(out,\n " if (!DH_set_length(dh, %ld)) {\\n"\n " DH_free(dh);\\n"\n " }\\n", DH_get_length(dh));\n BIO_printf(out, " return dh;\\n}\\n");\n OPENSSL_free(data);\n }\n if (!noout) {\n const BIGNUM *q;\n DH_get0_pqg(dh, NULL, &q, NULL);\n if (outformat == FORMAT_ASN1)\n i = i2d_DHparams_bio(out, dh);\n else if (q != NULL)\n i = PEM_write_bio_DHxparams(out, dh);\n else\n i = PEM_write_bio_DHparams(out, dh);\n if (!i) {\n BIO_printf(bio_err, "unable to write DH parameters\\n");\n ERR_print_errors(bio_err);\n goto end;\n }\n }\n ret = 0;\n end:\n BIO_free(in);\n BIO_free_all(out);\n DH_free(dh);\n release_engine(e);\n return (ret);\n}', 'int DH_generate_parameters_ex(DH *ret, int prime_len, int generator,\n BN_GENCB *cb)\n{\n if (ret->meth->generate_params)\n return ret->meth->generate_params(ret, prime_len, generator, cb);\n return dh_builtin_genparams(ret, prime_len, generator, cb);\n}', 'int DH_check(const DH *dh, int *ret)\n{\n int ok = 0, r;\n BN_CTX *ctx = NULL;\n BN_ULONG l;\n BIGNUM *t1 = NULL, *t2 = NULL;\n *ret = 0;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n if (t1 == NULL)\n goto err;\n t2 = BN_CTX_get(ctx);\n if (t2 == NULL)\n goto err;\n if (dh->q) {\n if (BN_cmp(dh->g, BN_value_one()) <= 0)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n else if (BN_cmp(dh->g, dh->p) >= 0)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n else {\n if (!BN_mod_exp(t1, dh->g, dh->q, dh->p, ctx))\n goto err;\n if (!BN_is_one(t1))\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n }\n r = BN_is_prime_ex(dh->q, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_Q_NOT_PRIME;\n if (!BN_div(t1, t2, dh->p, dh->q, ctx))\n goto err;\n if (!BN_is_one(t2))\n *ret |= DH_CHECK_INVALID_Q_VALUE;\n if (dh->j && BN_cmp(dh->j, t1))\n *ret |= DH_CHECK_INVALID_J_VALUE;\n } else if (BN_is_word(dh->g, DH_GENERATOR_2)) {\n l = BN_mod_word(dh->p, 24);\n if (l == (BN_ULONG)-1)\n goto err;\n if (l != 11)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n } else if (BN_is_word(dh->g, DH_GENERATOR_5)) {\n l = BN_mod_word(dh->p, 10);\n if (l == (BN_ULONG)-1)\n goto err;\n if ((l != 3) && (l != 7))\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n } else\n *ret |= DH_UNABLE_TO_CHECK_GENERATOR;\n r = BN_is_prime_ex(dh->p, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_P_NOT_PRIME;\n else if (!dh->q) {\n if (!BN_rshift1(t1, dh->p))\n goto err;\n r = BN_is_prime_ex(t1, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_P_NOT_SAFE_PRIME;\n }\n ok = 1;\n err:\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return (ok);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
2,736
| 0
|
https://github.com/openssl/openssl/blob/38d1b3cc0271008b8bd130a2c4b442775b028a08/crypto/bn/bn_shift.c/#L110
|
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return (0);
r->neg = a->neg;
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return (1);
}
|
['static int eckey_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)\n{\n const unsigned char *p = NULL;\n const void *pval;\n int ptype, pklen;\n EC_KEY *eckey = NULL;\n X509_ALGOR *palg;\n if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey))\n return 0;\n X509_ALGOR_get0(NULL, &ptype, &pval, palg);\n eckey = eckey_type2param(ptype, pval);\n if (!eckey) {\n ECerr(EC_F_ECKEY_PUB_DECODE, ERR_R_EC_LIB);\n return 0;\n }\n if (!o2i_ECPublicKey(&eckey, &p, pklen)) {\n ECerr(EC_F_ECKEY_PUB_DECODE, EC_R_DECODE_ERROR);\n goto ecerr;\n }\n EVP_PKEY_assign_EC_KEY(pkey, eckey);\n return 1;\n ecerr:\n EC_KEY_free(eckey);\n return 0;\n}', 'static EC_KEY *eckey_type2param(int ptype, const void *pval)\n{\n EC_KEY *eckey = NULL;\n if (ptype == V_ASN1_SEQUENCE) {\n const ASN1_STRING *pstr = pval;\n const unsigned char *pm = NULL;\n int pmlen;\n pm = pstr->data;\n pmlen = pstr->length;\n if ((eckey = d2i_ECParameters(NULL, &pm, pmlen)) == NULL) {\n ECerr(EC_F_ECKEY_TYPE2PARAM, EC_R_DECODE_ERROR);\n goto ecerr;\n }\n } else if (ptype == V_ASN1_OBJECT) {\n const ASN1_OBJECT *poid = pval;\n EC_GROUP *group;\n if ((eckey = EC_KEY_new()) == NULL) {\n ECerr(EC_F_ECKEY_TYPE2PARAM, ERR_R_MALLOC_FAILURE);\n goto ecerr;\n }\n group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(poid));\n if (group == NULL)\n goto ecerr;\n EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);\n if (EC_KEY_set_group(eckey, group) == 0)\n goto ecerr;\n EC_GROUP_free(group);\n } else {\n ECerr(EC_F_ECKEY_TYPE2PARAM, EC_R_DECODE_ERROR);\n goto ecerr;\n }\n return eckey;\n ecerr:\n EC_KEY_free(eckey);\n return NULL;\n}', 'EC_GROUP *EC_GROUP_new_by_curve_name(int nid)\n{\n size_t i;\n EC_GROUP *ret = NULL;\n if (nid <= 0)\n return NULL;\n for (i = 0; i < curve_list_length; i++)\n if (curve_list[i].nid == nid) {\n ret = ec_group_new_from_data(curve_list[i]);\n break;\n }\n if (ret == NULL) {\n ECerr(EC_F_EC_GROUP_NEW_BY_CURVE_NAME, EC_R_UNKNOWN_GROUP);\n return NULL;\n }\n EC_GROUP_set_curve_name(ret, nid);\n return ret;\n}', 'static EC_GROUP *ec_group_new_from_data(const ec_list_element curve)\n{\n EC_GROUP *group = NULL;\n EC_POINT *P = NULL;\n BN_CTX *ctx = NULL;\n BIGNUM *p = NULL, *a = NULL, *b = NULL, *x = NULL, *y = NULL, *order =\n NULL;\n int ok = 0;\n int seed_len, param_len;\n const EC_METHOD *meth;\n const EC_CURVE_DATA *data;\n const unsigned char *params;\n if (curve.data == NULL)\n return EC_GROUP_new(curve.meth != NULL ? curve.meth() : NULL);\n if ((ctx = BN_CTX_new()) == NULL) {\n ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n data = curve.data;\n seed_len = data->seed_len;\n param_len = data->param_len;\n params = (const unsigned char *)(data + 1);\n params += seed_len;\n if ((p = BN_bin2bn(params + 0 * param_len, param_len, NULL)) == NULL\n || (a = BN_bin2bn(params + 1 * param_len, param_len, NULL)) == NULL\n || (b = BN_bin2bn(params + 2 * param_len, param_len, NULL)) == NULL) {\n ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);\n goto err;\n }\n if (curve.meth != 0) {\n meth = curve.meth();\n if (((group = EC_GROUP_new(meth)) == NULL) ||\n (!(group->meth->group_set_curve(group, p, a, b, ctx)))) {\n ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n goto err;\n }\n } else if (data->field_type == NID_X9_62_prime_field) {\n if ((group = EC_GROUP_new_curve_GFp(p, a, b, ctx)) == NULL) {\n ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n goto err;\n }\n }\n#ifndef OPENSSL_NO_EC2M\n else {\n if ((group = EC_GROUP_new_curve_GF2m(p, a, b, ctx)) == NULL) {\n ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n goto err;\n }\n }\n#endif\n if ((P = EC_POINT_new(group)) == NULL) {\n ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n goto err;\n }\n if ((x = BN_bin2bn(params + 3 * param_len, param_len, NULL)) == NULL\n || (y = BN_bin2bn(params + 4 * param_len, param_len, NULL)) == NULL) {\n ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);\n goto err;\n }\n if (!EC_POINT_set_affine_coordinates_GFp(group, P, x, y, ctx)) {\n ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n goto err;\n }\n if ((order = BN_bin2bn(params + 5 * param_len, param_len, NULL)) == NULL\n || !BN_set_word(x, (BN_ULONG)data->cofactor)) {\n ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);\n goto err;\n }\n if (!EC_GROUP_set_generator(group, P, order, x)) {\n ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n goto err;\n }\n if (seed_len) {\n if (!EC_GROUP_set_seed(group, params - seed_len, seed_len)) {\n ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n goto err;\n }\n }\n ok = 1;\n err:\n if (!ok) {\n EC_GROUP_free(group);\n group = NULL;\n }\n EC_POINT_free(P);\n BN_CTX_free(ctx);\n BN_free(p);\n BN_free(a);\n BN_free(b);\n BN_free(order);\n BN_free(x);\n BN_free(y);\n return group;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return (NULL);\n bn_check_top(ret);\n for ( ; len > 0 && *s == 0; s++, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return (ret);\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n l = (l << 8L) | *(s++);\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\n return (ret);\n}', 'EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len)\n{\n EC_KEY *ret = NULL;\n if (a == NULL || (*a) == NULL || (*a)->group == NULL) {\n ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n ret = *a;\n if (!EC_KEY_oct2key(ret, *in, len, NULL)) {\n ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_EC_LIB);\n return 0;\n }\n *in += len;\n return ret;\n}', 'int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len,\n BN_CTX *ctx)\n{\n if (key == NULL || key->group == NULL)\n return 0;\n if (key->pub_key == NULL)\n key->pub_key = EC_POINT_new(key->group);\n if (key->pub_key == NULL)\n return 0;\n if (EC_POINT_oct2point(key->group, key->pub_key, buf, len, ctx) == 0)\n return 0;\n if ((key->group->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0)\n key->conv_form = (point_conversion_form_t)(buf[0] & ~0x01);\n return 1;\n}', 'int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,\n const unsigned char *buf, size_t len, BN_CTX *ctx)\n{\n if (group->meth->oct2point == 0\n && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {\n ECerr(EC_F_EC_POINT_OCT2POINT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n if (group->meth != point->meth) {\n ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {\n if (group->meth->field_type == NID_X9_62_prime_field)\n return ec_GFp_simple_oct2point(group, point, buf, len, ctx);\n else\n#ifdef OPENSSL_NO_EC2M\n {\n ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_GF2M_NOT_SUPPORTED);\n return 0;\n }\n#else\n return ec_GF2m_simple_oct2point(group, point, buf, len, ctx);\n#endif\n }\n return group->meth->oct2point(group, point, buf, len, ctx);\n}', 'int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,\n const unsigned char *buf, size_t len,\n BN_CTX *ctx)\n{\n point_conversion_form_t form;\n int y_bit;\n BN_CTX *new_ctx = NULL;\n BIGNUM *x, *y, *yxi;\n size_t field_len, enc_len;\n int ret = 0;\n if (len == 0) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL);\n return 0;\n }\n form = buf[0];\n y_bit = form & 1;\n form = form & ~1U;\n if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED)\n && (form != POINT_CONVERSION_UNCOMPRESSED)\n && (form != POINT_CONVERSION_HYBRID)) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n return 0;\n }\n if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n return 0;\n }\n if (form == 0) {\n if (len != 1) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n return 0;\n }\n return EC_POINT_set_to_infinity(group, point);\n }\n field_len = (EC_GROUP_get_degree(group) + 7) / 8;\n enc_len =\n (form ==\n POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;\n if (len != enc_len) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n return 0;\n }\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n BN_CTX_start(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n yxi = BN_CTX_get(ctx);\n if (yxi == NULL)\n goto err;\n if (!BN_bin2bn(buf + 1, field_len, x))\n goto err;\n if (BN_ucmp(x, group->field) >= 0) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n goto err;\n }\n if (form == POINT_CONVERSION_COMPRESSED) {\n if (!EC_POINT_set_compressed_coordinates_GF2m\n (group, point, x, y_bit, ctx))\n goto err;\n } else {\n if (!BN_bin2bn(buf + 1 + field_len, field_len, y))\n goto err;\n if (BN_ucmp(y, group->field) >= 0) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n goto err;\n }\n if (form == POINT_CONVERSION_HYBRID) {\n if (!group->meth->field_div(group, yxi, y, x, ctx))\n goto err;\n if (y_bit != BN_is_odd(yxi)) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n goto err;\n }\n }\n if (!EC_POINT_set_affine_coordinates_GF2m(group, point, x, y, ctx))\n goto err;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group,\n EC_POINT *point, const BIGNUM *x,\n int y_bit, BN_CTX *ctx)\n{\n if (group->meth->point_set_compressed_coordinates == 0\n && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {\n ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M,\n ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n if (group->meth != point->meth) {\n ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M,\n EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {\n if (group->meth->field_type == NID_X9_62_prime_field)\n return ec_GFp_simple_set_compressed_coordinates(group, point, x,\n y_bit, ctx);\n else\n return ec_GF2m_simple_set_compressed_coordinates(group, point, x,\n y_bit, ctx);\n }\n return group->meth->point_set_compressed_coordinates(group, point, x,\n y_bit, ctx);\n}', '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}', '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 if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_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_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
2,737
| 0
|
https://gitlab.com/libtiff/libtiff/blob/db77de50bc63656963056920e137be3c6f2f2498/libtiff/tif_write.c/#L428
|
tmsize_t
TIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc)
{
static const char module[] = "TIFFWriteEncodedTile";
TIFFDirectory *td;
uint16 sample;
uint32 howmany32;
if (!WRITECHECKTILES(tif, module))
return ((tmsize_t)(-1));
td = &tif->tif_dir;
if (tile >= td->td_nstrips) {
TIFFErrorExt(tif->tif_clientdata, module, "Tile %lu out of range, max %lu",
(unsigned long) tile, (unsigned long) td->td_nstrips);
return ((tmsize_t)(-1));
}
if (!BUFFERCHECK(tif))
return ((tmsize_t)(-1));
tif->tif_flags |= TIFF_BUF4WRITE;
tif->tif_curtile = tile;
if( !_TIFFReserveLargeEnoughWriteBuffer(tif, tile) ) {
return ((tmsize_t)(-1));
}
tif->tif_rawcc = 0;
tif->tif_rawcp = tif->tif_rawdata;
howmany32=TIFFhowmany_32(td->td_imagelength, td->td_tilelength);
if (howmany32 == 0) {
TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");
return ((tmsize_t)(-1));
}
tif->tif_row = (tile % howmany32) * td->td_tilelength;
howmany32=TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth);
if (howmany32 == 0) {
TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");
return ((tmsize_t)(-1));
}
tif->tif_col = (tile % howmany32) * td->td_tilewidth;
if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
if (!(*tif->tif_setupencode)(tif))
return ((tmsize_t)(-1));
tif->tif_flags |= TIFF_CODERSETUP;
}
tif->tif_flags &= ~TIFF_POSTENCODE;
if ( cc < 1 || cc > tif->tif_tilesize)
cc = tif->tif_tilesize;
if( td->td_compression == COMPRESSION_NONE )
{
tif->tif_postdecode( tif, (uint8*) data, cc );
if (!isFillOrder(tif, td->td_fillorder) &&
(tif->tif_flags & TIFF_NOBITREV) == 0)
TIFFReverseBits((uint8*) data, cc);
if (cc > 0 &&
!TIFFAppendToStrip(tif, tile, (uint8*) data, cc))
return ((tmsize_t) -1);
return (cc);
}
sample = (uint16)(tile/td->td_stripsperimage);
if (!(*tif->tif_preencode)(tif, sample))
return ((tmsize_t)(-1));
tif->tif_postdecode( tif, (uint8*) data, cc );
if (!(*tif->tif_encodetile)(tif, (uint8*) data, cc, sample))
return ((tmsize_t) -1);
if (!(*tif->tif_postencode)(tif))
return ((tmsize_t)(-1));
if (!isFillOrder(tif, td->td_fillorder) &&
(tif->tif_flags & TIFF_NOBITREV) == 0)
TIFFReverseBits((uint8*)tif->tif_rawdata, tif->tif_rawcc);
if (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile,
tif->tif_rawdata, tif->tif_rawcc))
return ((tmsize_t)(-1));
tif->tif_rawcc = 0;
tif->tif_rawcp = tif->tif_rawdata;
return (cc);
}
|
['tmsize_t\nTIFFWriteEncodedTile(TIFF* tif, uint32 tile, void* data, tmsize_t cc)\n{\n\tstatic const char module[] = "TIFFWriteEncodedTile";\n\tTIFFDirectory *td;\n\tuint16 sample;\n uint32 howmany32;\n\tif (!WRITECHECKTILES(tif, module))\n\t\treturn ((tmsize_t)(-1));\n\ttd = &tif->tif_dir;\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module, "Tile %lu out of range, max %lu",\n\t\t (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n\tif (!BUFFERCHECK(tif))\n\t\treturn ((tmsize_t)(-1));\n tif->tif_flags |= TIFF_BUF4WRITE;\n\ttif->tif_curtile = tile;\n if( !_TIFFReserveLargeEnoughWriteBuffer(tif, tile) ) {\n return ((tmsize_t)(-1));\n }\n\ttif->tif_rawcc = 0;\n\ttif->tif_rawcp = tif->tif_rawdata;\n howmany32=TIFFhowmany_32(td->td_imagelength, td->td_tilelength);\n if (howmany32 == 0) {\n TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");\n return ((tmsize_t)(-1));\n }\n\ttif->tif_row = (tile % howmany32) * td->td_tilelength;\n howmany32=TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth);\n if (howmany32 == 0) {\n TIFFErrorExt(tif->tif_clientdata,module,"Zero tiles");\n return ((tmsize_t)(-1));\n }\n\ttif->tif_col = (tile % howmany32) * td->td_tilewidth;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupencode)(tif))\n\t\t\treturn ((tmsize_t)(-1));\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_flags &= ~TIFF_POSTENCODE;\n\tif ( cc < 1 || cc > tif->tif_tilesize)\n\t\tcc = tif->tif_tilesize;\n if( td->td_compression == COMPRESSION_NONE )\n {\n tif->tif_postdecode( tif, (uint8*) data, cc );\n if (!isFillOrder(tif, td->td_fillorder) &&\n (tif->tif_flags & TIFF_NOBITREV) == 0)\n TIFFReverseBits((uint8*) data, cc);\n if (cc > 0 &&\n !TIFFAppendToStrip(tif, tile, (uint8*) data, cc))\n return ((tmsize_t) -1);\n return (cc);\n }\n sample = (uint16)(tile/td->td_stripsperimage);\n if (!(*tif->tif_preencode)(tif, sample))\n return ((tmsize_t)(-1));\n tif->tif_postdecode( tif, (uint8*) data, cc );\n if (!(*tif->tif_encodetile)(tif, (uint8*) data, cc, sample))\n return ((tmsize_t) -1);\n if (!(*tif->tif_postencode)(tif))\n return ((tmsize_t)(-1));\n if (!isFillOrder(tif, td->td_fillorder) &&\n (tif->tif_flags & TIFF_NOBITREV) == 0)\n TIFFReverseBits((uint8*)tif->tif_rawdata, tif->tif_rawcc);\n if (tif->tif_rawcc > 0 && !TIFFAppendToStrip(tif, tile,\n tif->tif_rawdata, tif->tif_rawcc))\n return ((tmsize_t)(-1));\n tif->tif_rawcc = 0;\n tif->tif_rawcp = tif->tif_rawdata;\n return (cc);\n}']
|
2,738
| 0
|
https://github.com/openssl/openssl/blob/04dec1ab34df70c1588d42cc394e8fa8b5f3191c/crypto/evp/m_sigver.c/#L126
|
int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
size_t *siglen)
{
int sctx = 0, r = 0;
EVP_PKEY_CTX *pctx = ctx->pctx;
if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) {
if (!sigret)
return pctx->pmeth->signctx(pctx, sigret, siglen, ctx);
if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE)
r = pctx->pmeth->signctx(pctx, sigret, siglen, ctx);
else {
EVP_PKEY_CTX *dctx = EVP_PKEY_CTX_dup(ctx->pctx);
if (!dctx)
return 0;
r = dctx->pmeth->signctx(dctx, sigret, siglen, ctx);
EVP_PKEY_CTX_free(dctx);
}
return r;
}
if (pctx->pmeth->signctx)
sctx = 1;
else
sctx = 0;
if (sigret) {
unsigned char md[EVP_MAX_MD_SIZE];
unsigned int mdlen = 0;
if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) {
if (sctx)
r = ctx->pctx->pmeth->signctx(ctx->pctx, sigret, siglen, ctx);
else
r = EVP_DigestFinal_ex(ctx, md, &mdlen);
} else {
EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();
if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx))
return 0;
if (sctx)
r = tmp_ctx->pctx->pmeth->signctx(tmp_ctx->pctx,
sigret, siglen, tmp_ctx);
else
r = EVP_DigestFinal_ex(tmp_ctx, md, &mdlen);
EVP_MD_CTX_free(tmp_ctx);
}
if (sctx || !r)
return r;
if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0)
return 0;
} else {
if (sctx) {
if (pctx->pmeth->signctx(pctx, sigret, siglen, ctx) <= 0)
return 0;
} else {
int s = EVP_MD_size(ctx->digest);
if (s < 0 || EVP_PKEY_sign(pctx, sigret, siglen, NULL, s) <= 0)
return 0;
}
}
return 1;
}
|
['int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,\n size_t *siglen)\n{\n int sctx = 0, r = 0;\n EVP_PKEY_CTX *pctx = ctx->pctx;\n if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) {\n if (!sigret)\n return pctx->pmeth->signctx(pctx, sigret, siglen, ctx);\n if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE)\n r = pctx->pmeth->signctx(pctx, sigret, siglen, ctx);\n else {\n EVP_PKEY_CTX *dctx = EVP_PKEY_CTX_dup(ctx->pctx);\n if (!dctx)\n return 0;\n r = dctx->pmeth->signctx(dctx, sigret, siglen, ctx);\n EVP_PKEY_CTX_free(dctx);\n }\n return r;\n }\n if (pctx->pmeth->signctx)\n sctx = 1;\n else\n sctx = 0;\n if (sigret) {\n unsigned char md[EVP_MAX_MD_SIZE];\n unsigned int mdlen = 0;\n if (ctx->flags & EVP_MD_CTX_FLAG_FINALISE) {\n if (sctx)\n r = ctx->pctx->pmeth->signctx(ctx->pctx, sigret, siglen, ctx);\n else\n r = EVP_DigestFinal_ex(ctx, md, &mdlen);\n } else {\n EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();\n if (tmp_ctx == NULL || !EVP_MD_CTX_copy_ex(tmp_ctx, ctx))\n return 0;\n if (sctx)\n r = tmp_ctx->pctx->pmeth->signctx(tmp_ctx->pctx,\n sigret, siglen, tmp_ctx);\n else\n r = EVP_DigestFinal_ex(tmp_ctx, md, &mdlen);\n EVP_MD_CTX_free(tmp_ctx);\n }\n if (sctx || !r)\n return r;\n if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0)\n return 0;\n } else {\n if (sctx) {\n if (pctx->pmeth->signctx(pctx, sigret, siglen, ctx) <= 0)\n return 0;\n } else {\n int s = EVP_MD_size(ctx->digest);\n if (s < 0 || EVP_PKEY_sign(pctx, sigret, siglen, NULL, s) <= 0)\n return 0;\n }\n }\n return 1;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n 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}', 'int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)\n{\n unsigned char *tmp_buf;\n if ((in == NULL) || (in->digest == NULL)) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);\n return 0;\n }\n#ifndef OPENSSL_NO_ENGINE\n if (in->engine && !ENGINE_init(in->engine)) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);\n return 0;\n }\n#endif\n if (out->digest == in->digest) {\n tmp_buf = out->md_data;\n EVP_MD_CTX_set_flags(out, EVP_MD_CTX_FLAG_REUSE);\n } else\n tmp_buf = NULL;\n EVP_MD_CTX_reset(out);\n memcpy(out, in, sizeof(*out));\n out->md_data = NULL;\n out->pctx = NULL;\n if (in->md_data && out->digest->ctx_size) {\n if (tmp_buf)\n out->md_data = tmp_buf;\n else {\n out->md_data = OPENSSL_malloc(out->digest->ctx_size);\n if (out->md_data == NULL) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n }\n memcpy(out->md_data, in->md_data, out->digest->ctx_size);\n }\n out->update = in->update;\n if (in->pctx) {\n out->pctx = EVP_PKEY_CTX_dup(in->pctx);\n if (!out->pctx) {\n EVP_MD_CTX_reset(out);\n return 0;\n }\n }\n if (out->digest->copy)\n return out->digest->copy(out, in);\n return 1;\n}', 'int ENGINE_init(ENGINE *e)\n{\n int ret;\n if (e == NULL) {\n ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {\n ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n CRYPTO_THREAD_write_lock(global_engine_lock);\n ret = engine_unlocked_init(e);\n CRYPTO_THREAD_unlock(global_engine_lock);\n return ret;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}']
|
2,739
| 0
|
https://github.com/libav/libav/blob/47399ccdfd93d337c96c76fbf591f0e3637131ef/libavcodec/bitstream.h/#L236
|
static inline void skip_remaining(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
bc->bits >>= n;
#else
bc->bits <<= n;
#endif
bc->bits_left -= n;
}
|
['static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt,\n AVStream *st, AVPacket *pkt,\n uint32_t *timestamp, const uint8_t *buf,\n int len, uint16_t seq, int flags)\n{\n AVIOContext pb;\n BitstreamContext bc;\n int packing_scheme, has_payload_desc, has_packet_info, alen,\n has_marker_bit = flags & RTP_FLAG_MARKER,\n keyframe;\n if (qt->remaining) {\n int num = qt->pkt.size / qt->bytes_per_frame;\n if (av_new_packet(pkt, qt->bytes_per_frame))\n return AVERROR(ENOMEM);\n pkt->stream_index = st->index;\n pkt->flags = qt->pkt.flags;\n memcpy(pkt->data,\n &qt->pkt.data[(num - qt->remaining) * qt->bytes_per_frame],\n qt->bytes_per_frame);\n if (--qt->remaining == 0) {\n av_freep(&qt->pkt.data);\n qt->pkt.size = 0;\n }\n return qt->remaining > 0;\n }\n bitstream_init8(&bc, buf, len);\n ffio_init_context(&pb, buf, len, 0, NULL, NULL, NULL, NULL);\n if (len < 4)\n return AVERROR_INVALIDDATA;\n bitstream_skip(&bc, 4);\n if ((packing_scheme = bitstream_read(&bc, 2)) == 0)\n return AVERROR_INVALIDDATA;\n keyframe = bitstream_read_bit(&bc);\n has_payload_desc = bitstream_read_bit(&bc);\n has_packet_info = bitstream_read_bit(&bc);\n bitstream_skip(&bc, 23);\n if (has_payload_desc) {\n int data_len, pos, is_start, is_finish;\n uint32_t tag;\n pos = bitstream_tell(&bc) >> 3;\n if (pos + 12 > len)\n return AVERROR_INVALIDDATA;\n bitstream_skip(&bc, 2);\n is_start = bitstream_read_bit(&bc);\n is_finish = bitstream_read_bit(&bc);\n if (!is_start || !is_finish) {\n avpriv_request_sample(s, "RTP-X-QT with payload description "\n "split over several packets");\n return AVERROR_PATCHWELCOME;\n }\n bitstream_skip(&bc, 12);\n data_len = bitstream_read(&bc, 16);\n avio_seek(&pb, pos + 4, SEEK_SET);\n tag = avio_rl32(&pb);\n if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&\n tag != MKTAG(\'v\',\'i\',\'d\',\'e\')) ||\n (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&\n tag != MKTAG(\'s\',\'o\',\'u\',\'n\')))\n return AVERROR_INVALIDDATA;\n avpriv_set_pts_info(st, 32, 1, avio_rb32(&pb));\n if (pos + data_len > len)\n return AVERROR_INVALIDDATA;\n while (avio_tell(&pb) + 4 < pos + data_len) {\n int tlv_len = avio_rb16(&pb);\n tag = avio_rl16(&pb);\n if (avio_tell(&pb) + tlv_len > pos + data_len)\n return AVERROR_INVALIDDATA;\n#define MKTAG16(a,b) MKTAG(a,b,0,0)\n switch (tag) {\n case MKTAG16(\'s\',\'d\'): {\n MOVStreamContext *msc;\n void *priv_data = st->priv_data;\n int nb_streams = s->nb_streams;\n MOVContext *mc = av_mallocz(sizeof(*mc));\n if (!mc)\n return AVERROR(ENOMEM);\n mc->fc = s;\n st->priv_data = msc = av_mallocz(sizeof(MOVStreamContext));\n if (!msc) {\n av_free(mc);\n st->priv_data = priv_data;\n return AVERROR(ENOMEM);\n }\n s->nb_streams = st->index + 1;\n ff_mov_read_stsd_entries(mc, &pb, 1);\n qt->bytes_per_frame = msc->bytes_per_frame;\n av_free(msc);\n av_free(mc);\n st->priv_data = priv_data;\n s->nb_streams = nb_streams;\n break;\n }\n default:\n avio_skip(&pb, tlv_len);\n break;\n }\n }\n avio_skip(&pb, ((avio_tell(&pb) + 3) & ~3) - avio_tell(&pb));\n } else\n avio_seek(&pb, 4, SEEK_SET);\n if (has_packet_info) {\n avpriv_request_sample(s, "RTP-X-QT with packet-specific info");\n return AVERROR_PATCHWELCOME;\n }\n alen = len - avio_tell(&pb);\n if (alen <= 0)\n return AVERROR_INVALIDDATA;\n switch (packing_scheme) {\n case 3:\n if (qt->pkt.size > 0 && qt->timestamp == *timestamp) {\n int err;\n if ((err = av_reallocp(&qt->pkt.data, qt->pkt.size + alen +\n AV_INPUT_BUFFER_PADDING_SIZE)) < 0) {\n qt->pkt.size = 0;\n return err;\n }\n } else {\n av_freep(&qt->pkt.data);\n av_init_packet(&qt->pkt);\n qt->pkt.data = av_realloc(NULL, alen + AV_INPUT_BUFFER_PADDING_SIZE);\n if (!qt->pkt.data)\n return AVERROR(ENOMEM);\n qt->pkt.size = 0;\n qt->timestamp = *timestamp;\n }\n memcpy(qt->pkt.data + qt->pkt.size, buf + avio_tell(&pb), alen);\n qt->pkt.size += alen;\n if (has_marker_bit) {\n int ret = av_packet_from_data(pkt, qt->pkt.data, qt->pkt.size);\n if (ret < 0)\n return ret;\n qt->pkt.size = 0;\n qt->pkt.data = NULL;\n pkt->flags = keyframe ? AV_PKT_FLAG_KEY : 0;\n pkt->stream_index = st->index;\n memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);\n return 0;\n }\n return AVERROR(EAGAIN);\n case 1:\n if (qt->bytes_per_frame == 0 ||\n alen % qt->bytes_per_frame != 0)\n return AVERROR_INVALIDDATA;\n qt->remaining = (alen / qt->bytes_per_frame) - 1;\n if (av_new_packet(pkt, qt->bytes_per_frame))\n return AVERROR(ENOMEM);\n memcpy(pkt->data, buf + avio_tell(&pb), qt->bytes_per_frame);\n pkt->flags = keyframe ? AV_PKT_FLAG_KEY : 0;\n pkt->stream_index = st->index;\n if (qt->remaining > 0) {\n av_freep(&qt->pkt.data);\n qt->pkt.data = av_realloc(NULL, qt->remaining * qt->bytes_per_frame);\n if (!qt->pkt.data) {\n av_packet_unref(pkt);\n return AVERROR(ENOMEM);\n }\n qt->pkt.size = qt->remaining * qt->bytes_per_frame;\n memcpy(qt->pkt.data,\n buf + avio_tell(&pb) + qt->bytes_per_frame,\n qt->remaining * qt->bytes_per_frame);\n qt->pkt.flags = pkt->flags;\n return 1;\n }\n return 0;\n default:\n avpriv_request_sample(NULL, "RTP-X-QT with packing scheme 2");\n return AVERROR_PATCHWELCOME;\n }\n}', 'static inline int bitstream_init8(BitstreamContext *bc, const uint8_t *buffer,\n unsigned byte_size)\n{\n if (byte_size > INT_MAX / 8)\n return AVERROR_INVALIDDATA;\n return bitstream_init(bc, buffer, byte_size * 8);\n}', 'static inline 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}']
|
2,740
| 0
|
https://github.com/openssl/openssl/blob/7432d073af97539e5a2c8b0f1ff254d6b53c9682/apps/x509.c/#L1214
|
static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, const EVP_MD *digest,
CONF *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_nconf(&ctx, conf);
if (!X509V3_EXT_add_nconf(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\tCONF *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\t{\n\t\twhile (X509_get_ext_count(x) > 0) X509_delete_ext(x, 0);\n\t\t}\n\tif (conf)\n\t\t{\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_nconf(&ctx, conf);\n if (!X509V3_EXT_add_nconf(conf, &ctx, section, x)) goto err;\n\t\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}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tif (key == NULL) goto error;\n\tif (key->pkey != NULL)\n\t\t{\n\t\tCRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);\n\t\treturn key->pkey;\n\t\t}\n\tif (key->public_key == NULL) goto error;\n\tif ((ret = EVP_PKEY_new()) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);\n\t\tgoto error;\n\t\t}\n\tif (!EVP_PKEY_set_type(ret, OBJ_obj2nid(key->algor->algorithm)))\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM);\n\t\tgoto error;\n\t\t}\n\tif (ret->ameth->pub_decode)\n\t\t{\n\t\tif (!ret->ameth->pub_decode(ret, key))\n\t\t\t{\n\t\t\tX509err(X509_F_X509_PUBKEY_GET,\n\t\t\t\t\t\tX509_R_PUBLIC_KEY_DECODE_ERROR);\n\t\t\tgoto error;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET, X509_R_METHOD_NOT_SUPPORTED);\n\t\tgoto error;\n\t\t}\n\tkey->pkey = ret;\n\tCRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY);\n\treturn ret;\n\terror:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'EVP_PKEY *EVP_PKEY_new(void)\n\t{\n\tEVP_PKEY *ret;\n\tret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));\n\tif (ret == NULL)\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->type=EVP_PKEY_NONE;\n\tret->save_type=EVP_PKEY_NONE;\n\tret->references=1;\n\tret->ameth=NULL;\n\tret->engine=NULL;\n\tret->pkey.ptr=NULL;\n\tret->attributes=NULL;\n\tret->save_parameters=1;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)\n\t{\n\tif (to->type != from->type)\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);\n\t\tgoto err;\n\t\t}\n\tif (EVP_PKEY_missing_parameters(from))\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);\n\t\tgoto err;\n\t\t}\n\tif (from->ameth && from->ameth->param_copy)\n\t\treturn from->ameth->param_copy(to, from);\nerr:\n\treturn 0;\n\t}']
|
2,741
| 0
|
https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/test/evp_test.c/#L1635
|
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 = OPENSSL_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 = OPENSSL_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(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', '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}']
|
2,742
| 0
|
https://github.com/libav/libav/blob/df84d7d9bdf6b8e6896c711880f130b72738c828/libavformat/utils.c/#L2345
|
void av_close_input_stream(AVFormatContext *s)
{
int i;
AVStream *st;
if (s->iformat->read_close)
s->iformat->read_close(s);
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
if (st->parser) {
av_parser_close(st->parser);
av_free_packet(&st->cur_pkt);
}
av_metadata_free(&st->metadata);
av_free(st->index_entries);
av_free(st->codec->extradata);
av_free(st->codec);
#if LIBAVFORMAT_VERSION_INT < (53<<16)
av_free(st->filename);
#endif
av_free(st->priv_data);
av_free(st);
}
for(i=s->nb_programs-1; i>=0; i--) {
#if LIBAVFORMAT_VERSION_INT < (53<<16)
av_freep(&s->programs[i]->provider_name);
av_freep(&s->programs[i]->name);
#endif
av_metadata_free(&s->programs[i]->metadata);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
av_freep(&s->programs);
flush_packet_queue(s);
av_freep(&s->priv_data);
while(s->nb_chapters--) {
#if LIBAVFORMAT_VERSION_INT < (53<<16)
av_free(s->chapters[s->nb_chapters]->title);
#endif
av_metadata_free(&s->chapters[s->nb_chapters]->metadata);
av_free(s->chapters[s->nb_chapters]);
}
av_freep(&s->chapters);
av_metadata_free(&s->metadata);
av_free(s);
}
|
['void ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p)\n{\n if (av_strstart(p, "pgmpu:data:application/vnd.ms.wms-hdr.asfv1;base64,", &p)) {\n ByteIOContext pb;\n RTSPState *rt = s->priv_data;\n int len = strlen(p) * 6 / 8;\n char *buf = av_mallocz(len);\n av_base64_decode(buf, p, len);\n if (rtp_asf_fix_header(buf, len) < 0)\n av_log(s, AV_LOG_ERROR,\n "Failed to fix invalid RTSP-MS/ASF min_pktsize\\n");\n init_packetizer(&pb, buf, len);\n if (rt->asf_ctx) {\n av_close_input_stream(rt->asf_ctx);\n rt->asf_ctx = NULL;\n }\n av_open_input_stream(&rt->asf_ctx, &pb, "", &asf_demuxer, NULL);\n rt->asf_pb_pos = url_ftell(&pb);\n av_free(buf);\n rt->asf_ctx->pb = NULL;\n }\n}', 'static void init_packetizer(ByteIOContext *pb, uint8_t *buf, int len)\n{\n init_put_byte(pb, buf, len, 0, NULL, packetizer_read, NULL, NULL);\n pb->pos = len;\n pb->buf_end = buf + len;\n}', 'int init_put_byte(ByteIOContext *s,\n unsigned char *buffer,\n int buffer_size,\n int write_flag,\n void *opaque,\n int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),\n int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),\n int64_t (*seek)(void *opaque, int64_t offset, int whence))\n{\n s->buffer = buffer;\n s->buffer_size = buffer_size;\n s->buf_ptr = buffer;\n s->opaque = opaque;\n url_resetbuf(s, write_flag ? URL_WRONLY : URL_RDONLY);\n s->write_packet = write_packet;\n s->read_packet = read_packet;\n s->seek = seek;\n s->pos = 0;\n s->must_flush = 0;\n s->eof_reached = 0;\n s->error = 0;\n s->is_streamed = 0;\n s->max_packet_size = 0;\n s->update_checksum= NULL;\n if(!read_packet && !write_flag){\n s->pos = buffer_size;\n s->buf_end = s->buffer + buffer_size;\n }\n s->read_pause = NULL;\n s->read_seek = NULL;\n return 0;\n}', 'int url_resetbuf(ByteIOContext *s, int flags)\n#else\nstatic int url_resetbuf(ByteIOContext *s, int flags)\n#endif\n{\n#if LIBAVFORMAT_VERSION_MAJOR < 53\n URLContext *h = s->opaque;\n if ((flags & URL_RDWR) || (h && h->flags != flags && !h->flags & URL_RDWR))\n return AVERROR(EINVAL);\n#else\n assert(flags == URL_WRONLY || flags == URL_RDONLY);\n#endif\n if (flags & URL_WRONLY) {\n s->buf_end = s->buffer + s->buffer_size;\n s->write_flag = 1;\n } else {\n s->buf_end = s->buffer;\n s->write_flag = 0;\n }\n return 0;\n}', 'void av_close_input_stream(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n if (s->iformat->read_close)\n s->iformat->read_close(s);\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n av_free_packet(&st->cur_pkt);\n }\n av_metadata_free(&st->metadata);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec);\n#if LIBAVFORMAT_VERSION_INT < (53<<16)\n av_free(st->filename);\n#endif\n av_free(st->priv_data);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n#if LIBAVFORMAT_VERSION_INT < (53<<16)\n av_freep(&s->programs[i]->provider_name);\n av_freep(&s->programs[i]->name);\n#endif\n av_metadata_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n flush_packet_queue(s);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n#if LIBAVFORMAT_VERSION_INT < (53<<16)\n av_free(s->chapters[s->nb_chapters]->title);\n#endif\n av_metadata_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_metadata_free(&s->metadata);\n av_free(s);\n}']
|
2,743
| 0
|
https://github.com/openssl/openssl/blob/0f3ffbd1581fad58095fedcc32b0da42a486b8b7/crypto/x509/by_dir.c/#L200
|
static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
{
const char *s, *p;
if (dir == NULL || !*dir) {
X509err(X509_F_ADD_CERT_DIR, X509_R_INVALID_DIRECTORY);
return 0;
}
s = dir;
p = s;
do {
if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0')) {
BY_DIR_ENTRY *ent;
int j;
size_t len;
const char *ss = s;
s = p + 1;
len = p - ss;
if (len == 0)
continue;
for (j = 0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) {
ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j);
if (strlen(ent->dir) == len &&
strncmp(ent->dir, ss, len) == 0)
break;
}
if (j < sk_BY_DIR_ENTRY_num(ctx->dirs))
continue;
if (ctx->dirs == NULL) {
ctx->dirs = sk_BY_DIR_ENTRY_new_null();
if (!ctx->dirs) {
X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE);
return 0;
}
}
ent = OPENSSL_malloc(sizeof(*ent));
if (ent == NULL)
return 0;
ent->dir_type = type;
ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp);
ent->dir = OPENSSL_strndup(ss, len);
if (ent->dir == NULL || ent->hashes == NULL) {
by_dir_entry_free(ent);
return 0;
}
if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) {
by_dir_entry_free(ent);
return 0;
}
}
} while (*p++ != '\0');
return 1;
}
|
["static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)\n{\n const char *s, *p;\n if (dir == NULL || !*dir) {\n X509err(X509_F_ADD_CERT_DIR, X509_R_INVALID_DIRECTORY);\n return 0;\n }\n s = dir;\n p = s;\n do {\n if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\\0')) {\n BY_DIR_ENTRY *ent;\n int j;\n size_t len;\n const char *ss = s;\n s = p + 1;\n len = p - ss;\n if (len == 0)\n continue;\n for (j = 0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) {\n ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j);\n if (strlen(ent->dir) == len &&\n strncmp(ent->dir, ss, len) == 0)\n break;\n }\n if (j < sk_BY_DIR_ENTRY_num(ctx->dirs))\n continue;\n if (ctx->dirs == NULL) {\n ctx->dirs = sk_BY_DIR_ENTRY_new_null();\n if (!ctx->dirs) {\n X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n }\n ent = OPENSSL_malloc(sizeof(*ent));\n if (ent == NULL)\n return 0;\n ent->dir_type = type;\n ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp);\n ent->dir = OPENSSL_strndup(ss, len);\n if (ent->dir == NULL || ent->hashes == NULL) {\n by_dir_entry_free(ent);\n return 0;\n }\n if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) {\n by_dir_entry_free(ent);\n return 0;\n }\n }\n } while (*p++ != '\\0');\n return 1;\n}", 'int OPENSSL_sk_num(const OPENSSL_STACK *st)\n{\n if (st == NULL)\n return -1;\n return st->num;\n}', 'OPENSSL_STACK *OPENSSL_sk_new_null(void)\n{\n return OPENSSL_sk_new((OPENSSL_sk_compfunc)NULL);\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', "char *CRYPTO_strndup(const char *str, size_t s, const char* file, int line)\n{\n size_t maxlen;\n char *ret;\n if (str == NULL)\n return NULL;\n maxlen = OPENSSL_strnlen(str, s);\n ret = CRYPTO_malloc(maxlen + 1, file, line);\n if (ret) {\n memcpy(ret, str, maxlen);\n ret[maxlen] = '\\0';\n }\n return ret;\n}", "size_t OPENSSL_strnlen(const char *str, size_t maxlen)\n{\n const char *p;\n for (p = str; maxlen-- != 0 && *p != '\\0'; ++p) ;\n return p - str;\n}", 'int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)\n{\n return (OPENSSL_sk_insert(st, data, st->num));\n}', 'static void by_dir_entry_free(BY_DIR_ENTRY *ent)\n{\n OPENSSL_free(ent->dir);\n sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free);\n OPENSSL_free(ent);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
|
2,744
| 0
|
https://github.com/libav/libav/blob/f5a2c9816e0b58edf2a87297be8d648631fc3432/libavcodec/indeo3.c/#L250
|
static void iv_Decode_Chunk(Indeo3DecodeContext *s,
uint8_t *cur, uint8_t *ref, int width, int height,
const uint8_t *buf1, long cb_offset, const uint8_t *hdr,
const uint8_t *buf2, int min_width_160)
{
uint8_t bit_buf;
unsigned long bit_pos, lv, lv1, lv2;
long *width_tbl, width_tbl_arr[10];
const signed char *ref_vectors;
uint8_t *cur_frm_pos, *ref_frm_pos, *cp, *cp2;
uint32_t *cur_lp, *ref_lp;
const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2];
uint8_t *correction_type_sp[2];
ustr_t strip_tbl[20], *strip;
int i, j, k, lp1, lp2, flag1, cmd, blks_width, blks_height, region_160_width,
rle_v1, rle_v2, rle_v3;
unsigned short res;
bit_buf = 0;
ref_vectors = NULL;
width_tbl = width_tbl_arr + 1;
i = (width < 0 ? width + 3 : width)/4;
for(j = -1; j < 8; j++)
width_tbl[j] = i * j;
strip = strip_tbl;
for(region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160);
strip->ypos = strip->xpos = 0;
for(strip->width = min_width_160; width > strip->width; strip->width *= 2);
strip->height = height;
strip->split_direction = 0;
strip->split_flag = 0;
strip->usl7 = 0;
bit_pos = 0;
rle_v1 = rle_v2 = rle_v3 = 0;
while(strip >= strip_tbl) {
if(bit_pos <= 0) {
bit_pos = 8;
bit_buf = *buf1++;
}
bit_pos -= 2;
cmd = (bit_buf >> bit_pos) & 0x03;
if(cmd == 0) {
strip++;
memcpy(strip, strip-1, sizeof(ustr_t));
strip->split_flag = 1;
strip->split_direction = 0;
strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4);
continue;
} else if(cmd == 1) {
strip++;
memcpy(strip, strip-1, sizeof(ustr_t));
strip->split_flag = 1;
strip->split_direction = 1;
strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4);
continue;
} else if(cmd == 2) {
if(strip->usl7 == 0) {
strip->usl7 = 1;
ref_vectors = NULL;
continue;
}
} else if(cmd == 3) {
if(strip->usl7 == 0) {
strip->usl7 = 1;
ref_vectors = (const signed char*)buf2 + (*buf1 * 2);
buf1++;
continue;
}
}
cur_frm_pos = cur + width * strip->ypos + strip->xpos;
if((blks_width = strip->width) < 0)
blks_width += 3;
blks_width >>= 2;
blks_height = strip->height;
if(ref_vectors != NULL) {
ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width +
ref_vectors[1] + strip->xpos;
} else
ref_frm_pos = cur_frm_pos - width_tbl[4];
if(cmd == 2) {
if(bit_pos <= 0) {
bit_pos = 8;
bit_buf = *buf1++;
}
bit_pos -= 2;
cmd = (bit_buf >> bit_pos) & 0x03;
if(cmd == 0 || ref_vectors != NULL) {
for(lp1 = 0; lp1 < blks_width; lp1++) {
for(i = 0, j = 0; i < blks_height; i++, j += width_tbl[1])
((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
cur_frm_pos += 4;
ref_frm_pos += 4;
}
} else if(cmd != 1)
return;
} else {
k = *buf1 >> 4;
j = *buf1 & 0x0f;
buf1++;
lv = j + cb_offset;
if((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) {
cp2 = s->ModPred + ((lv - 8) << 7);
cp = ref_frm_pos;
for(i = 0; i < blks_width << 2; i++) {
int v = *cp >> 1;
*(cp++) = cp2[v];
}
}
if(k == 1 || k == 4) {
lv = (hdr[j] & 0xf) + cb_offset;
correction_type_sp[0] = s->corrector_type + (lv << 8);
correction_lp[0] = correction + (lv << 8);
lv = (hdr[j] >> 4) + cb_offset;
correction_lp[1] = correction + (lv << 8);
correction_type_sp[1] = s->corrector_type + (lv << 8);
} else {
correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8);
correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8);
correction_type_sp[0] = correction_type_sp[1] = s->corrector_type + (lv << 8);
correction_lp[0] = correction_lp[1] = correction + (lv << 8);
}
switch(k) {
case 1:
case 0:
for( ; blks_height > 0; blks_height -= 4) {
for(lp1 = 0; lp1 < blks_width; lp1++) {
for(lp2 = 0; lp2 < 4; ) {
k = *buf1++;
cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2];
ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2];
switch(correction_type_sp[0][k]) {
case 0:
*cur_lp = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
lp2++;
break;
case 1:
res = ((le2me_16(((unsigned short *)(ref_lp))[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
((unsigned short *)cur_lp)[0] = le2me_16(res);
res = ((le2me_16(((unsigned short *)(ref_lp))[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
((unsigned short *)cur_lp)[1] = le2me_16(res);
buf1++;
lp2++;
break;
case 2:
if(lp2 == 0) {
for(i = 0, j = 0; i < 2; i++, j += width_tbl[1])
cur_lp[j] = ref_lp[j];
lp2 += 2;
}
break;
case 3:
if(lp2 < 2) {
for(i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1])
cur_lp[j] = ref_lp[j];
lp2 = 3;
}
break;
case 8:
if(lp2 == 0) {
RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
if(rle_v1 == 1 || ref_vectors != NULL) {
for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
cur_lp[j] = ref_lp[j];
}
RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
break;
} else {
rle_v1 = 1;
rle_v2 = *buf1 - 1;
}
case 5:
LP2_CHECK(buf1,rle_v3,lp2)
case 4:
for(i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1])
cur_lp[j] = ref_lp[j];
lp2 = 4;
break;
case 7:
if(rle_v3 != 0)
rle_v3 = 0;
else {
buf1--;
rle_v3 = 1;
}
case 6:
if(ref_vectors != NULL) {
for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
cur_lp[j] = ref_lp[j];
}
lp2 = 4;
break;
case 9:
lv1 = *buf1++;
lv = (lv1 & 0x7F) << 1;
lv += (lv << 8);
lv += (lv << 16);
for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
cur_lp[j] = lv;
LV1_CHECK(buf1,rle_v3,lv1,lp2)
break;
default:
return;
}
}
cur_frm_pos += 4;
ref_frm_pos += 4;
}
cur_frm_pos += ((width - blks_width) * 4);
ref_frm_pos += ((width - blks_width) * 4);
}
break;
case 4:
case 3:
if(ref_vectors != NULL)
return;
flag1 = 1;
for( ; blks_height > 0; blks_height -= 8) {
for(lp1 = 0; lp1 < blks_width; lp1++) {
for(lp2 = 0; lp2 < 4; ) {
k = *buf1++;
cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
switch(correction_type_sp[lp2 & 0x01][k]) {
case 0:
cur_lp[width_tbl[1]] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
else
cur_lp[0] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
lp2++;
break;
case 1:
res = ((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res);
res = ((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res);
if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
else
cur_lp[0] = cur_lp[width_tbl[1]];
buf1++;
lp2++;
break;
case 2:
if(lp2 == 0) {
for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
cur_lp[j] = *ref_lp;
lp2 += 2;
}
break;
case 3:
if(lp2 < 2) {
for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
cur_lp[j] = *ref_lp;
lp2 = 3;
}
break;
case 6:
lp2 = 4;
break;
case 7:
if(rle_v3 != 0)
rle_v3 = 0;
else {
buf1--;
rle_v3 = 1;
}
lp2 = 4;
break;
case 8:
if(lp2 == 0) {
RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
if(rle_v1 == 1) {
for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
cur_lp[j] = ref_lp[j];
}
RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
break;
} else {
rle_v2 = (*buf1) - 1;
rle_v1 = 1;
}
case 5:
LP2_CHECK(buf1,rle_v3,lp2)
case 4:
for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
cur_lp[j] = *ref_lp;
lp2 = 4;
break;
case 9:
av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
lv1 = *buf1++;
lv = (lv1 & 0x7F) << 1;
lv += (lv << 8);
lv += (lv << 16);
for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
cur_lp[j] = lv;
LV1_CHECK(buf1,rle_v3,lv1,lp2)
break;
default:
return;
}
}
cur_frm_pos += 4;
}
cur_frm_pos += (((width * 2) - blks_width) * 4);
flag1 = 0;
}
break;
case 10:
if(ref_vectors == NULL) {
flag1 = 1;
for( ; blks_height > 0; blks_height -= 8) {
for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
for(lp2 = 0; lp2 < 4; ) {
k = *buf1++;
cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
lv1 = ref_lp[0];
lv2 = ref_lp[1];
if(lp2 == 0 && flag1 != 0) {
#ifdef WORDS_BIGENDIAN
lv1 = lv1 & 0xFF00FF00;
lv1 = (lv1 >> 8) | lv1;
lv2 = lv2 & 0xFF00FF00;
lv2 = (lv2 >> 8) | lv2;
#else
lv1 = lv1 & 0x00FF00FF;
lv1 = (lv1 << 8) | lv1;
lv2 = lv2 & 0x00FF00FF;
lv2 = (lv2 << 8) | lv2;
#endif
}
switch(correction_type_sp[lp2 & 0x01][k]) {
case 0:
cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1);
if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
} else {
cur_lp[0] = cur_lp[width_tbl[1]];
cur_lp[1] = cur_lp[width_tbl[1]+1];
}
lp2++;
break;
case 1:
cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1]) << 1);
cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
} else {
cur_lp[0] = cur_lp[width_tbl[1]];
cur_lp[1] = cur_lp[width_tbl[1]+1];
}
buf1++;
lp2++;
break;
case 2:
if(lp2 == 0) {
if(flag1 != 0) {
for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) {
cur_lp[j] = lv1;
cur_lp[j+1] = lv2;
}
cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
} else {
for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
cur_lp[j] = lv1;
cur_lp[j+1] = lv2;
}
}
lp2 += 2;
}
break;
case 3:
if(lp2 < 2) {
if(lp2 == 0 && flag1 != 0) {
for(i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) {
cur_lp[j] = lv1;
cur_lp[j+1] = lv2;
}
cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
} else {
for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
cur_lp[j] = lv1;
cur_lp[j+1] = lv2;
}
}
lp2 = 3;
}
break;
case 8:
if(lp2 == 0) {
RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
if(rle_v1 == 1) {
if(flag1 != 0) {
for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
cur_lp[j] = lv1;
cur_lp[j+1] = lv2;
}
cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
} else {
for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
cur_lp[j] = lv1;
cur_lp[j+1] = lv2;
}
}
}
RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
break;
} else {
rle_v1 = 1;
rle_v2 = (*buf1) - 1;
}
case 5:
LP2_CHECK(buf1,rle_v3,lp2)
case 4:
if(lp2 == 0 && flag1 != 0) {
for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
cur_lp[j] = lv1;
cur_lp[j+1] = lv2;
}
cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
} else {
for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
cur_lp[j] = lv1;
cur_lp[j+1] = lv2;
}
}
lp2 = 4;
break;
case 6:
lp2 = 4;
break;
case 7:
if(lp2 == 0) {
if(rle_v3 != 0)
rle_v3 = 0;
else {
buf1--;
rle_v3 = 1;
}
lp2 = 4;
}
break;
case 9:
av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
lv1 = *buf1;
lv = (lv1 & 0x7F) << 1;
lv += (lv << 8);
lv += (lv << 16);
for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
cur_lp[j] = lv;
LV1_CHECK(buf1,rle_v3,lv1,lp2)
break;
default:
return;
}
}
cur_frm_pos += 8;
}
cur_frm_pos += (((width * 2) - blks_width) * 4);
flag1 = 0;
}
} else {
for( ; blks_height > 0; blks_height -= 8) {
for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
for(lp2 = 0; lp2 < 4; ) {
k = *buf1++;
cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
switch(correction_type_sp[lp2 & 0x01][k]) {
case 0:
lv1 = correctionloworder_lp[lp2 & 0x01][k];
lv2 = correctionhighorder_lp[lp2 & 0x01][k];
cur_lp[0] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1);
cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1);
cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
lp2++;
break;
case 1:
lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++];
lv2 = correctionloworder_lp[lp2 & 0x01][k];
cur_lp[0] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1);
cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1);
cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);
lp2++;
break;
case 2:
if(lp2 == 0) {
for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
cur_lp[j] = ref_lp[j];
cur_lp[j+1] = ref_lp[j+1];
}
lp2 += 2;
}
break;
case 3:
if(lp2 < 2) {
for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
cur_lp[j] = ref_lp[j];
cur_lp[j+1] = ref_lp[j+1];
}
lp2 = 3;
}
break;
case 8:
if(lp2 == 0) {
RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
((uint32_t *)cur_frm_pos)[j+1] = ((uint32_t *)ref_frm_pos)[j+1];
}
RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
break;
} else {
rle_v1 = 1;
rle_v2 = (*buf1) - 1;
}
case 5:
case 7:
LP2_CHECK(buf1,rle_v3,lp2)
case 6:
case 4:
for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
cur_lp[j] = ref_lp[j];
cur_lp[j+1] = ref_lp[j+1];
}
lp2 = 4;
break;
case 9:
av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
lv1 = *buf1;
lv = (lv1 & 0x7F) << 1;
lv += (lv << 8);
lv += (lv << 16);
for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)cur_frm_pos)[j+1] = lv;
LV1_CHECK(buf1,rle_v3,lv1,lp2)
break;
default:
return;
}
}
cur_frm_pos += 8;
ref_frm_pos += 8;
}
cur_frm_pos += (((width * 2) - blks_width) * 4);
ref_frm_pos += (((width * 2) - blks_width) * 4);
}
}
break;
case 11:
if(ref_vectors == NULL)
return;
for( ; blks_height > 0; blks_height -= 8) {
for(lp1 = 0; lp1 < blks_width; lp1++) {
for(lp2 = 0; lp2 < 4; ) {
k = *buf1++;
cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
switch(correction_type_sp[lp2 & 0x01][k]) {
case 0:
cur_lp[0] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
lp2++;
break;
case 1:
lv1 = (unsigned short)(correction_lp[lp2 & 0x01][*buf1++]);
lv2 = (unsigned short)(correction_lp[lp2 & 0x01][k]);
res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + lv1) << 1);
((unsigned short *)cur_lp)[0] = le2me_16(res);
res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + lv2) << 1);
((unsigned short *)cur_lp)[1] = le2me_16(res);
res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]]) >> 1) + lv1) << 1);
((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res);
res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]+1]) >> 1) + lv2) << 1);
((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res);
lp2++;
break;
case 2:
if(lp2 == 0) {
for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
cur_lp[j] = ref_lp[j];
lp2 += 2;
}
break;
case 3:
if(lp2 < 2) {
for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
cur_lp[j] = ref_lp[j];
lp2 = 3;
}
break;
case 8:
if(lp2 == 0) {
RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
cur_lp[j] = ref_lp[j];
RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
break;
} else {
rle_v1 = 1;
rle_v2 = (*buf1) - 1;
}
case 5:
case 7:
LP2_CHECK(buf1,rle_v3,lp2)
case 4:
case 6:
for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
cur_lp[j] = ref_lp[j];
lp2 = 4;
break;
case 9:
av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n");
lv1 = *buf1++;
lv = (lv1 & 0x7F) << 1;
lv += (lv << 8);
lv += (lv << 16);
for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
cur_lp[j] = lv;
LV1_CHECK(buf1,rle_v3,lv1,lp2)
break;
default:
return;
}
}
cur_frm_pos += 4;
ref_frm_pos += 4;
}
cur_frm_pos += (((width * 2) - blks_width) * 4);
ref_frm_pos += (((width * 2) - blks_width) * 4);
}
break;
default:
return;
}
}
if(strip < strip_tbl)
return;
for( ; strip >= strip_tbl; strip--) {
if(strip->split_flag != 0) {
strip->split_flag = 0;
strip->usl7 = (strip-1)->usl7;
if(strip->split_direction) {
strip->xpos += strip->width;
strip->width = (strip-1)->width - strip->width;
if(region_160_width <= strip->xpos && width < strip->width + strip->xpos)
strip->width = width - strip->xpos;
} else {
strip->ypos += strip->height;
strip->height = (strip-1)->height - strip->height;
}
break;
}
}
}
}
|
['static void iv_Decode_Chunk(Indeo3DecodeContext *s,\n uint8_t *cur, uint8_t *ref, int width, int height,\n const uint8_t *buf1, long cb_offset, const uint8_t *hdr,\n const uint8_t *buf2, int min_width_160)\n{\n uint8_t bit_buf;\n unsigned long bit_pos, lv, lv1, lv2;\n long *width_tbl, width_tbl_arr[10];\n const signed char *ref_vectors;\n uint8_t *cur_frm_pos, *ref_frm_pos, *cp, *cp2;\n uint32_t *cur_lp, *ref_lp;\n const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2];\n uint8_t *correction_type_sp[2];\n ustr_t strip_tbl[20], *strip;\n int i, j, k, lp1, lp2, flag1, cmd, blks_width, blks_height, region_160_width,\n rle_v1, rle_v2, rle_v3;\n unsigned short res;\n bit_buf = 0;\n ref_vectors = NULL;\n width_tbl = width_tbl_arr + 1;\n i = (width < 0 ? width + 3 : width)/4;\n for(j = -1; j < 8; j++)\n width_tbl[j] = i * j;\n strip = strip_tbl;\n for(region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160);\n strip->ypos = strip->xpos = 0;\n for(strip->width = min_width_160; width > strip->width; strip->width *= 2);\n strip->height = height;\n strip->split_direction = 0;\n strip->split_flag = 0;\n strip->usl7 = 0;\n bit_pos = 0;\n rle_v1 = rle_v2 = rle_v3 = 0;\n while(strip >= strip_tbl) {\n if(bit_pos <= 0) {\n bit_pos = 8;\n bit_buf = *buf1++;\n }\n bit_pos -= 2;\n cmd = (bit_buf >> bit_pos) & 0x03;\n if(cmd == 0) {\n strip++;\n memcpy(strip, strip-1, sizeof(ustr_t));\n strip->split_flag = 1;\n strip->split_direction = 0;\n strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4);\n continue;\n } else if(cmd == 1) {\n strip++;\n memcpy(strip, strip-1, sizeof(ustr_t));\n strip->split_flag = 1;\n strip->split_direction = 1;\n strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4);\n continue;\n } else if(cmd == 2) {\n if(strip->usl7 == 0) {\n strip->usl7 = 1;\n ref_vectors = NULL;\n continue;\n }\n } else if(cmd == 3) {\n if(strip->usl7 == 0) {\n strip->usl7 = 1;\n ref_vectors = (const signed char*)buf2 + (*buf1 * 2);\n buf1++;\n continue;\n }\n }\n cur_frm_pos = cur + width * strip->ypos + strip->xpos;\n if((blks_width = strip->width) < 0)\n blks_width += 3;\n blks_width >>= 2;\n blks_height = strip->height;\n if(ref_vectors != NULL) {\n ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width +\n ref_vectors[1] + strip->xpos;\n } else\n ref_frm_pos = cur_frm_pos - width_tbl[4];\n if(cmd == 2) {\n if(bit_pos <= 0) {\n bit_pos = 8;\n bit_buf = *buf1++;\n }\n bit_pos -= 2;\n cmd = (bit_buf >> bit_pos) & 0x03;\n if(cmd == 0 || ref_vectors != NULL) {\n for(lp1 = 0; lp1 < blks_width; lp1++) {\n for(i = 0, j = 0; i < blks_height; i++, j += width_tbl[1])\n ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];\n cur_frm_pos += 4;\n ref_frm_pos += 4;\n }\n } else if(cmd != 1)\n return;\n } else {\n k = *buf1 >> 4;\n j = *buf1 & 0x0f;\n buf1++;\n lv = j + cb_offset;\n if((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) {\n cp2 = s->ModPred + ((lv - 8) << 7);\n cp = ref_frm_pos;\n for(i = 0; i < blks_width << 2; i++) {\n int v = *cp >> 1;\n *(cp++) = cp2[v];\n }\n }\n if(k == 1 || k == 4) {\n lv = (hdr[j] & 0xf) + cb_offset;\n correction_type_sp[0] = s->corrector_type + (lv << 8);\n correction_lp[0] = correction + (lv << 8);\n lv = (hdr[j] >> 4) + cb_offset;\n correction_lp[1] = correction + (lv << 8);\n correction_type_sp[1] = s->corrector_type + (lv << 8);\n } else {\n correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8);\n correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8);\n correction_type_sp[0] = correction_type_sp[1] = s->corrector_type + (lv << 8);\n correction_lp[0] = correction_lp[1] = correction + (lv << 8);\n }\n switch(k) {\n case 1:\n case 0:\n for( ; blks_height > 0; blks_height -= 4) {\n for(lp1 = 0; lp1 < blks_width; lp1++) {\n for(lp2 = 0; lp2 < 4; ) {\n k = *buf1++;\n cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2];\n ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2];\n switch(correction_type_sp[0][k]) {\n case 0:\n *cur_lp = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);\n lp2++;\n break;\n case 1:\n res = ((le2me_16(((unsigned short *)(ref_lp))[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;\n ((unsigned short *)cur_lp)[0] = le2me_16(res);\n res = ((le2me_16(((unsigned short *)(ref_lp))[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;\n ((unsigned short *)cur_lp)[1] = le2me_16(res);\n buf1++;\n lp2++;\n break;\n case 2:\n if(lp2 == 0) {\n for(i = 0, j = 0; i < 2; i++, j += width_tbl[1])\n cur_lp[j] = ref_lp[j];\n lp2 += 2;\n }\n break;\n case 3:\n if(lp2 < 2) {\n for(i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1])\n cur_lp[j] = ref_lp[j];\n lp2 = 3;\n }\n break;\n case 8:\n if(lp2 == 0) {\n RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)\n if(rle_v1 == 1 || ref_vectors != NULL) {\n for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])\n cur_lp[j] = ref_lp[j];\n }\n RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)\n break;\n } else {\n rle_v1 = 1;\n rle_v2 = *buf1 - 1;\n }\n case 5:\n LP2_CHECK(buf1,rle_v3,lp2)\n case 4:\n for(i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1])\n cur_lp[j] = ref_lp[j];\n lp2 = 4;\n break;\n case 7:\n if(rle_v3 != 0)\n rle_v3 = 0;\n else {\n buf1--;\n rle_v3 = 1;\n }\n case 6:\n if(ref_vectors != NULL) {\n for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])\n cur_lp[j] = ref_lp[j];\n }\n lp2 = 4;\n break;\n case 9:\n lv1 = *buf1++;\n lv = (lv1 & 0x7F) << 1;\n lv += (lv << 8);\n lv += (lv << 16);\n for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])\n cur_lp[j] = lv;\n LV1_CHECK(buf1,rle_v3,lv1,lp2)\n break;\n default:\n return;\n }\n }\n cur_frm_pos += 4;\n ref_frm_pos += 4;\n }\n cur_frm_pos += ((width - blks_width) * 4);\n ref_frm_pos += ((width - blks_width) * 4);\n }\n break;\n case 4:\n case 3:\n if(ref_vectors != NULL)\n return;\n flag1 = 1;\n for( ; blks_height > 0; blks_height -= 8) {\n for(lp1 = 0; lp1 < blks_width; lp1++) {\n for(lp2 = 0; lp2 < 4; ) {\n k = *buf1++;\n cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];\n ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];\n switch(correction_type_sp[lp2 & 0x01][k]) {\n case 0:\n cur_lp[width_tbl[1]] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);\n if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)\n cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;\n else\n cur_lp[0] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);\n lp2++;\n break;\n case 1:\n res = ((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;\n ((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res);\n res = ((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;\n ((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res);\n if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)\n cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;\n else\n cur_lp[0] = cur_lp[width_tbl[1]];\n buf1++;\n lp2++;\n break;\n case 2:\n if(lp2 == 0) {\n for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])\n cur_lp[j] = *ref_lp;\n lp2 += 2;\n }\n break;\n case 3:\n if(lp2 < 2) {\n for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])\n cur_lp[j] = *ref_lp;\n lp2 = 3;\n }\n break;\n case 6:\n lp2 = 4;\n break;\n case 7:\n if(rle_v3 != 0)\n rle_v3 = 0;\n else {\n buf1--;\n rle_v3 = 1;\n }\n lp2 = 4;\n break;\n case 8:\n if(lp2 == 0) {\n RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)\n if(rle_v1 == 1) {\n for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])\n cur_lp[j] = ref_lp[j];\n }\n RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)\n break;\n } else {\n rle_v2 = (*buf1) - 1;\n rle_v1 = 1;\n }\n case 5:\n LP2_CHECK(buf1,rle_v3,lp2)\n case 4:\n for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])\n cur_lp[j] = *ref_lp;\n lp2 = 4;\n break;\n case 9:\n av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\\n");\n lv1 = *buf1++;\n lv = (lv1 & 0x7F) << 1;\n lv += (lv << 8);\n lv += (lv << 16);\n for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])\n cur_lp[j] = lv;\n LV1_CHECK(buf1,rle_v3,lv1,lp2)\n break;\n default:\n return;\n }\n }\n cur_frm_pos += 4;\n }\n cur_frm_pos += (((width * 2) - blks_width) * 4);\n flag1 = 0;\n }\n break;\n case 10:\n if(ref_vectors == NULL) {\n flag1 = 1;\n for( ; blks_height > 0; blks_height -= 8) {\n for(lp1 = 0; lp1 < blks_width; lp1 += 2) {\n for(lp2 = 0; lp2 < 4; ) {\n k = *buf1++;\n cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];\n ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];\n lv1 = ref_lp[0];\n lv2 = ref_lp[1];\n if(lp2 == 0 && flag1 != 0) {\n#ifdef WORDS_BIGENDIAN\n lv1 = lv1 & 0xFF00FF00;\n lv1 = (lv1 >> 8) | lv1;\n lv2 = lv2 & 0xFF00FF00;\n lv2 = (lv2 >> 8) | lv2;\n#else\n lv1 = lv1 & 0x00FF00FF;\n lv1 = (lv1 << 8) | lv1;\n lv2 = lv2 & 0x00FF00FF;\n lv2 = (lv2 << 8) | lv2;\n#endif\n }\n switch(correction_type_sp[lp2 & 0x01][k]) {\n case 0:\n cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);\n cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1);\n if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {\n cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;\n cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;\n } else {\n cur_lp[0] = cur_lp[width_tbl[1]];\n cur_lp[1] = cur_lp[width_tbl[1]+1];\n }\n lp2++;\n break;\n case 1:\n cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1]) << 1);\n cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);\n if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {\n cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;\n cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;\n } else {\n cur_lp[0] = cur_lp[width_tbl[1]];\n cur_lp[1] = cur_lp[width_tbl[1]+1];\n }\n buf1++;\n lp2++;\n break;\n case 2:\n if(lp2 == 0) {\n if(flag1 != 0) {\n for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) {\n cur_lp[j] = lv1;\n cur_lp[j+1] = lv2;\n }\n cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;\n cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;\n } else {\n for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {\n cur_lp[j] = lv1;\n cur_lp[j+1] = lv2;\n }\n }\n lp2 += 2;\n }\n break;\n case 3:\n if(lp2 < 2) {\n if(lp2 == 0 && flag1 != 0) {\n for(i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) {\n cur_lp[j] = lv1;\n cur_lp[j+1] = lv2;\n }\n cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;\n cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;\n } else {\n for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {\n cur_lp[j] = lv1;\n cur_lp[j+1] = lv2;\n }\n }\n lp2 = 3;\n }\n break;\n case 8:\n if(lp2 == 0) {\n RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)\n if(rle_v1 == 1) {\n if(flag1 != 0) {\n for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {\n cur_lp[j] = lv1;\n cur_lp[j+1] = lv2;\n }\n cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;\n cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;\n } else {\n for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {\n cur_lp[j] = lv1;\n cur_lp[j+1] = lv2;\n }\n }\n }\n RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)\n break;\n } else {\n rle_v1 = 1;\n rle_v2 = (*buf1) - 1;\n }\n case 5:\n LP2_CHECK(buf1,rle_v3,lp2)\n case 4:\n if(lp2 == 0 && flag1 != 0) {\n for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {\n cur_lp[j] = lv1;\n cur_lp[j+1] = lv2;\n }\n cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;\n cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;\n } else {\n for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {\n cur_lp[j] = lv1;\n cur_lp[j+1] = lv2;\n }\n }\n lp2 = 4;\n break;\n case 6:\n lp2 = 4;\n break;\n case 7:\n if(lp2 == 0) {\n if(rle_v3 != 0)\n rle_v3 = 0;\n else {\n buf1--;\n rle_v3 = 1;\n }\n lp2 = 4;\n }\n break;\n case 9:\n av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\\n");\n lv1 = *buf1;\n lv = (lv1 & 0x7F) << 1;\n lv += (lv << 8);\n lv += (lv << 16);\n for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])\n cur_lp[j] = lv;\n LV1_CHECK(buf1,rle_v3,lv1,lp2)\n break;\n default:\n return;\n }\n }\n cur_frm_pos += 8;\n }\n cur_frm_pos += (((width * 2) - blks_width) * 4);\n flag1 = 0;\n }\n } else {\n for( ; blks_height > 0; blks_height -= 8) {\n for(lp1 = 0; lp1 < blks_width; lp1 += 2) {\n for(lp2 = 0; lp2 < 4; ) {\n k = *buf1++;\n cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];\n ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];\n switch(correction_type_sp[lp2 & 0x01][k]) {\n case 0:\n lv1 = correctionloworder_lp[lp2 & 0x01][k];\n lv2 = correctionhighorder_lp[lp2 & 0x01][k];\n cur_lp[0] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1);\n cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1);\n cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);\n cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);\n lp2++;\n break;\n case 1:\n lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++];\n lv2 = correctionloworder_lp[lp2 & 0x01][k];\n cur_lp[0] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1);\n cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1);\n cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);\n cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1);\n lp2++;\n break;\n case 2:\n if(lp2 == 0) {\n for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {\n cur_lp[j] = ref_lp[j];\n cur_lp[j+1] = ref_lp[j+1];\n }\n lp2 += 2;\n }\n break;\n case 3:\n if(lp2 < 2) {\n for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {\n cur_lp[j] = ref_lp[j];\n cur_lp[j+1] = ref_lp[j+1];\n }\n lp2 = 3;\n }\n break;\n case 8:\n if(lp2 == 0) {\n RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)\n for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {\n ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];\n ((uint32_t *)cur_frm_pos)[j+1] = ((uint32_t *)ref_frm_pos)[j+1];\n }\n RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)\n break;\n } else {\n rle_v1 = 1;\n rle_v2 = (*buf1) - 1;\n }\n case 5:\n case 7:\n LP2_CHECK(buf1,rle_v3,lp2)\n case 6:\n case 4:\n for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {\n cur_lp[j] = ref_lp[j];\n cur_lp[j+1] = ref_lp[j+1];\n }\n lp2 = 4;\n break;\n case 9:\n av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\\n");\n lv1 = *buf1;\n lv = (lv1 & 0x7F) << 1;\n lv += (lv << 8);\n lv += (lv << 16);\n for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])\n ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)cur_frm_pos)[j+1] = lv;\n LV1_CHECK(buf1,rle_v3,lv1,lp2)\n break;\n default:\n return;\n }\n }\n cur_frm_pos += 8;\n ref_frm_pos += 8;\n }\n cur_frm_pos += (((width * 2) - blks_width) * 4);\n ref_frm_pos += (((width * 2) - blks_width) * 4);\n }\n }\n break;\n case 11:\n if(ref_vectors == NULL)\n return;\n for( ; blks_height > 0; blks_height -= 8) {\n for(lp1 = 0; lp1 < blks_width; lp1++) {\n for(lp2 = 0; lp2 < 4; ) {\n k = *buf1++;\n cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];\n ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];\n switch(correction_type_sp[lp2 & 0x01][k]) {\n case 0:\n cur_lp[0] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);\n cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);\n lp2++;\n break;\n case 1:\n lv1 = (unsigned short)(correction_lp[lp2 & 0x01][*buf1++]);\n lv2 = (unsigned short)(correction_lp[lp2 & 0x01][k]);\n res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + lv1) << 1);\n ((unsigned short *)cur_lp)[0] = le2me_16(res);\n res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + lv2) << 1);\n ((unsigned short *)cur_lp)[1] = le2me_16(res);\n res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]]) >> 1) + lv1) << 1);\n ((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res);\n res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]+1]) >> 1) + lv2) << 1);\n ((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res);\n lp2++;\n break;\n case 2:\n if(lp2 == 0) {\n for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])\n cur_lp[j] = ref_lp[j];\n lp2 += 2;\n }\n break;\n case 3:\n if(lp2 < 2) {\n for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])\n cur_lp[j] = ref_lp[j];\n lp2 = 3;\n }\n break;\n case 8:\n if(lp2 == 0) {\n RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)\n for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])\n cur_lp[j] = ref_lp[j];\n RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)\n break;\n } else {\n rle_v1 = 1;\n rle_v2 = (*buf1) - 1;\n }\n case 5:\n case 7:\n LP2_CHECK(buf1,rle_v3,lp2)\n case 4:\n case 6:\n for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])\n cur_lp[j] = ref_lp[j];\n lp2 = 4;\n break;\n case 9:\n av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\\n");\n lv1 = *buf1++;\n lv = (lv1 & 0x7F) << 1;\n lv += (lv << 8);\n lv += (lv << 16);\n for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])\n cur_lp[j] = lv;\n LV1_CHECK(buf1,rle_v3,lv1,lp2)\n break;\n default:\n return;\n }\n }\n cur_frm_pos += 4;\n ref_frm_pos += 4;\n }\n cur_frm_pos += (((width * 2) - blks_width) * 4);\n ref_frm_pos += (((width * 2) - blks_width) * 4);\n }\n break;\n default:\n return;\n }\n }\n if(strip < strip_tbl)\n return;\n for( ; strip >= strip_tbl; strip--) {\n if(strip->split_flag != 0) {\n strip->split_flag = 0;\n strip->usl7 = (strip-1)->usl7;\n if(strip->split_direction) {\n strip->xpos += strip->width;\n strip->width = (strip-1)->width - strip->width;\n if(region_160_width <= strip->xpos && width < strip->width + strip->xpos)\n strip->width = width - strip->xpos;\n } else {\n strip->ypos += strip->height;\n strip->height = (strip-1)->height - strip->height;\n }\n break;\n }\n }\n }\n}']
|
2,745
| 0
|
https://github.com/openssl/openssl/blob/55442b8a5b719f54578083fae0fcc814b599cd84/crypto/bn/bn_shift.c/#L112
|
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return 0;
r->neg = a->neg;
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return 1;
}
|
['int RSA_check_key_ex(const RSA *key, BN_GENCB *cb)\n{\n BIGNUM *i, *j, *k, *l, *m;\n BN_CTX *ctx;\n int ret = 1, ex_primes = 0, idx;\n RSA_PRIME_INFO *pinfo;\n if (key->p == NULL || key->q == NULL || key->n == NULL\n || key->e == NULL || key->d == NULL) {\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_VALUE_MISSING);\n return 0;\n }\n if (key->version == RSA_ASN1_VERSION_MULTI) {\n ex_primes = sk_RSA_PRIME_INFO_num(key->prime_infos);\n if (ex_primes <= 0\n || (ex_primes + 2) > rsa_multip_cap(BN_num_bits(key->n))) {\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_INVALID_MULTI_PRIME_KEY);\n return 0;\n }\n }\n i = BN_new();\n j = BN_new();\n k = BN_new();\n l = BN_new();\n m = BN_new();\n ctx = BN_CTX_new();\n if (i == NULL || j == NULL || k == NULL || l == NULL\n || m == NULL || ctx == NULL) {\n ret = -1;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (BN_is_one(key->e)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n }\n if (!BN_is_odd(key->e)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n }\n if (BN_is_prime_ex(key->p, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_P_NOT_PRIME);\n }\n if (BN_is_prime_ex(key->q, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_Q_NOT_PRIME);\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (BN_is_prime_ex(pinfo->r, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_R_NOT_PRIME);\n }\n }\n if (!BN_mul(i, key->p, key->q, ctx)) {\n ret = -1;\n goto err;\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (!BN_mul(i, i, pinfo->r, ctx)) {\n ret = -1;\n goto err;\n }\n }\n if (BN_cmp(i, key->n) != 0) {\n ret = 0;\n if (ex_primes)\n RSAerr(RSA_F_RSA_CHECK_KEY_EX,\n RSA_R_N_DOES_NOT_EQUAL_PRODUCT_OF_PRIMES);\n else\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_N_DOES_NOT_EQUAL_P_Q);\n }\n if (!BN_sub(i, key->p, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_sub(j, key->q, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mul(l, i, j, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_gcd(m, i, j, ctx)) {\n ret = -1;\n goto err;\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (!BN_sub(k, pinfo->r, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mul(l, l, k, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_gcd(m, m, k, ctx)) {\n ret = -1;\n goto err;\n }\n }\n if (!BN_div(k, NULL, l, m, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_mod_mul(i, key->d, key->e, k, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_is_one(i)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_D_E_NOT_CONGRUENT_TO_1);\n }\n if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) {\n if (!BN_sub(i, key->p, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, key->dmp1) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMP1_NOT_CONGRUENT_TO_D);\n }\n if (!BN_sub(i, key->q, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, key->dmq1) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMQ1_NOT_CONGRUENT_TO_D);\n }\n if (!BN_mod_inverse(i, key->q, key->p, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(i, key->iqmp) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_IQMP_NOT_INVERSE_OF_Q);\n }\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (!BN_sub(i, pinfo->r, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, pinfo->d) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_EXPONENT_NOT_CONGRUENT_TO_D);\n }\n if (!BN_mod_inverse(i, pinfo->pp, pinfo->r, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(i, pinfo->t) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_COEFFICIENT_NOT_INVERSE_OF_R);\n }\n }\n err:\n BN_free(i);\n BN_free(j);\n BN_free(k);\n BN_free(l);\n BN_free(m);\n BN_CTX_free(ctx);\n return ret;\n}', 'int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n BN_GENCB *cb)\n{\n return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);\n}', 'int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n int do_trial_division, BN_GENCB *cb)\n{\n int i, j, ret = -1;\n int k;\n BN_CTX *ctx = NULL;\n BIGNUM *A1, *A1_odd, *check;\n BN_MONT_CTX *mont = NULL;\n if (BN_cmp(a, BN_value_one()) <= 0)\n return 0;\n if (checks == BN_prime_checks)\n checks = BN_prime_checks_for_size(BN_num_bits(a));\n if (!BN_is_odd(a))\n return BN_is_word(a, 2);\n if (do_trial_division) {\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG mod = BN_mod_word(a, primes[i]);\n if (mod == (BN_ULONG)-1)\n goto err;\n if (mod == 0)\n return BN_is_word(a, primes[i]);\n }\n if (!BN_GENCB_call(cb, 1, -1))\n goto err;\n }\n if (ctx_passed != NULL)\n ctx = ctx_passed;\n else if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n A1 = BN_CTX_get(ctx);\n A1_odd = BN_CTX_get(ctx);\n check = BN_CTX_get(ctx);\n if (check == NULL)\n goto err;\n if (!BN_copy(A1, a))\n goto err;\n if (!BN_sub_word(A1, 1))\n goto err;\n if (BN_is_zero(A1)) {\n ret = 0;\n goto err;\n }\n k = 1;\n while (!BN_is_bit_set(A1, k))\n k++;\n if (!BN_rshift(A1_odd, A1, k))\n goto err;\n mont = BN_MONT_CTX_new();\n if (mont == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, a, ctx))\n goto err;\n for (i = 0; i < checks; i++) {\n if (!BN_priv_rand_range(check, A1))\n goto err;\n if (!BN_add_word(check, 1))\n goto err;\n j = witness(check, a, A1, A1_odd, k, ctx, mont);\n if (j == -1)\n goto err;\n if (j) {\n ret = 0;\n goto err;\n }\n if (!BN_GENCB_call(cb, 1, i))\n goto err;\n }\n ret = 1;\n err:\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n if (ctx_passed == NULL)\n BN_CTX_free(ctx);\n }\n BN_MONT_CTX_free(mont);\n return ret;\n}', 'int BN_cmp(const BIGNUM *a, const BIGNUM *b)\n{\n int i;\n int gt, lt;\n BN_ULONG t1, t2;\n if ((a == NULL) || (b == NULL)) {\n if (a != NULL)\n return -1;\n else if (b != NULL)\n return 1;\n else\n return 0;\n }\n bn_check_top(a);\n bn_check_top(b);\n if (a->neg != b->neg) {\n if (a->neg)\n return -1;\n else\n return 1;\n }\n if (a->neg == 0) {\n gt = 1;\n lt = -1;\n } else {\n gt = -1;\n lt = 1;\n }\n if (a->top > b->top)\n return gt;\n if (a->top < b->top)\n return lt;\n for (i = a->top - 1; i >= 0; i--) {\n t1 = a->d[i];\n t2 = b->d[i];\n if (t1 > t2)\n return gt;\n if (t1 < t2)\n return lt;\n }\n return 0;\n}', 'int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int ret, r_neg, cmp_res;\n bn_check_top(a);\n bn_check_top(b);\n if (a->neg != b->neg) {\n r_neg = a->neg;\n ret = BN_uadd(r, a, b);\n } else {\n cmp_res = BN_ucmp(a, b);\n if (cmp_res > 0) {\n r_neg = a->neg;\n ret = BN_usub(r, a, b);\n } else if (cmp_res < 0) {\n r_neg = !b->neg;\n ret = BN_usub(r, b, a);\n } else {\n r_neg = 0;\n BN_zero(r);\n ret = 1;\n }\n }\n r->neg = r_neg;\n bn_check_top(r);\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) <= 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 a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\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}', '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_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return 0;\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
2,746
| 0
|
https://github.com/libav/libav/blob/6a2176aac05e1edbcdf8fb9c26d572d092a00c3c/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.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->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_slice(struct AVCodecContext *avctx, void *arg){\n H264Context *h = *(void**)arg;\n MpegEncContext * const s = &h->s;\n const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;\n int lf_x_start = s->mb_x;\n s->mb_skip_run= -1;\n h->is_complex = FRAME_MBAFF || s->picture_structure != PICT_FRAME || s->codec_id != CODEC_ID_H264 ||\n (CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY));\n if( h->pps.cabac ) {\n align_get_bits( &s->gb );\n ff_init_cabac_states( &h->cabac);\n ff_init_cabac_decoder( &h->cabac,\n s->gb.buffer + get_bits_count(&s->gb)/8,\n (get_bits_left(&s->gb) + 7)/8);\n ff_h264_init_cabac_states(h);\n for(;;){\n int ret = ff_h264_decode_mb_cabac(h);\n int eos;\n if(ret>=0) ff_h264_hl_decode_mb(h);\n if( ret >= 0 && FRAME_MBAFF ) {\n s->mb_y++;\n ret = ff_h264_decode_mb_cabac(h);\n if(ret>=0) ff_h264_hl_decode_mb(h);\n s->mb_y--;\n }\n eos = get_cabac_terminate( &h->cabac );\n if((s->workaround_bugs & FF_BUG_TRUNCATED) && h->cabac.bytestream > h->cabac.bytestream_end + 2){\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n if (s->mb_x >= lf_x_start) loop_filter(h, lf_x_start, s->mb_x + 1);\n return 0;\n }\n if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) {\n av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream);\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n return -1;\n }\n if( ++s->mb_x >= s->mb_width ) {\n loop_filter(h, lf_x_start, s->mb_x);\n s->mb_x = lf_x_start = 0;\n decode_finish_row(h);\n ++s->mb_y;\n if(FIELD_OR_MBAFF_PICTURE) {\n ++s->mb_y;\n if(FRAME_MBAFF && s->mb_y < s->mb_height)\n predict_field_decoding_flag(h);\n }\n }\n if( eos || s->mb_y >= s->mb_height ) {\n tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x);\n return 0;\n }\n }\n } else {\n for(;;){\n int ret = ff_h264_decode_mb_cavlc(h);\n if(ret>=0) ff_h264_hl_decode_mb(h);\n if(ret>=0 && FRAME_MBAFF){\n s->mb_y++;\n ret = ff_h264_decode_mb_cavlc(h);\n if(ret>=0) ff_h264_hl_decode_mb(h);\n s->mb_y--;\n }\n if(ret<0){\n av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\\n", s->mb_x, s->mb_y);\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n return -1;\n }\n if(++s->mb_x >= s->mb_width){\n loop_filter(h, lf_x_start, s->mb_x);\n s->mb_x = lf_x_start = 0;\n decode_finish_row(h);\n ++s->mb_y;\n if(FIELD_OR_MBAFF_PICTURE) {\n ++s->mb_y;\n if(FRAME_MBAFF && s->mb_y < s->mb_height)\n predict_field_decoding_flag(h);\n }\n if(s->mb_y >= s->mb_height){\n tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n return 0;\n }else{\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n return -1;\n }\n }\n }\n if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){\n tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n if(get_bits_count(&s->gb) == s->gb.size_in_bits ){\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x);\n return 0;\n }else{\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n return -1;\n }\n }\n }\n }\n#if 0\n for(;s->mb_y < s->mb_height; s->mb_y++){\n for(;s->mb_x < s->mb_width; s->mb_x++){\n int ret= decode_mb(h);\n ff_h264_hl_decode_mb(h);\n if(ret<0){\n av_log(s->avctx, AV_LOG_ERROR, "error while decoding MB %d %d\\n", s->mb_x, s->mb_y);\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n return -1;\n }\n if(++s->mb_x >= s->mb_width){\n s->mb_x=0;\n if(++s->mb_y >= s->mb_height){\n if(get_bits_count(s->gb) == s->gb.size_in_bits){\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n return 0;\n }else{\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n return -1;\n }\n }\n }\n if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){\n if(get_bits_count(s->gb) == s->gb.size_in_bits){\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n return 0;\n }else{\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n return -1;\n }\n }\n }\n s->mb_x=0;\n ff_draw_horiz_band(s, 16*s->mb_y, 16);\n }\n#endif\n}', 'int ff_h264_decode_mb_cabac(H264Context *h) {\n MpegEncContext * const s = &h->s;\n int mb_xy;\n int mb_type, partition_count, cbp = 0;\n int dct8x8_allowed= h->pps.transform_8x8_mode;\n int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2;\n const int pixel_shift = h->pixel_shift;\n mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;\n tprintf(s->avctx, "pic:%d mb:%d/%d\\n", h->frame_num, s->mb_x, s->mb_y);\n if( h->slice_type_nos != AV_PICTURE_TYPE_I ) {\n int skip;\n if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped )\n skip = h->next_mb_skipped;\n else\n skip = decode_cabac_mb_skip( h, s->mb_x, s->mb_y );\n if( skip ) {\n if( FRAME_MBAFF && (s->mb_y&1)==0 ){\n s->current_picture.mb_type[mb_xy] = MB_TYPE_SKIP;\n h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 );\n if(!h->next_mb_skipped)\n h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n }\n decode_mb_skip(h);\n h->cbp_table[mb_xy] = 0;\n h->chroma_pred_mode_table[mb_xy] = 0;\n h->last_qscale_diff = 0;\n return 0;\n }\n }\n if(FRAME_MBAFF){\n if( (s->mb_y&1) == 0 )\n h->mb_mbaff =\n h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n }\n h->prev_mb_skipped = 0;\n fill_decode_neighbors(h, -(MB_FIELD));\n if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {\n int ctx = 0;\n assert(h->slice_type_nos == AV_PICTURE_TYPE_B);\n if( !IS_DIRECT( h->left_type[LTOP]-1 ) )\n ctx++;\n if( !IS_DIRECT( h->top_type-1 ) )\n ctx++;\n if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+ctx] ) ){\n mb_type= 0;\n }else if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+3] ) ) {\n mb_type= 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n }else{\n int bits;\n bits = get_cabac_noinline( &h->cabac, &h->cabac_state[27+4] ) << 3;\n bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 2;\n bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 1;\n bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n if( bits < 8 ){\n mb_type= bits + 3;\n }else if( bits == 13 ){\n mb_type= decode_cabac_intra_mb_type(h, 32, 0);\n goto decode_intra_mb;\n }else if( bits == 14 ){\n mb_type= 11;\n }else if( bits == 15 ){\n mb_type= 22;\n }else{\n bits= ( bits<<1 ) + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n mb_type= bits - 4;\n }\n }\n partition_count= b_mb_type_info[mb_type].partition_count;\n mb_type= b_mb_type_info[mb_type].type;\n } else if( h->slice_type_nos == AV_PICTURE_TYPE_P ) {\n if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) {\n if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) {\n mb_type= 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] );\n } else {\n mb_type= 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] );\n }\n partition_count= p_mb_type_info[mb_type].partition_count;\n mb_type= p_mb_type_info[mb_type].type;\n } else {\n mb_type= decode_cabac_intra_mb_type(h, 17, 0);\n goto decode_intra_mb;\n }\n } else {\n mb_type= decode_cabac_intra_mb_type(h, 3, 1);\n if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type)\n mb_type--;\n assert(h->slice_type_nos == AV_PICTURE_TYPE_I);\ndecode_intra_mb:\n partition_count = 0;\n cbp= i_mb_type_info[mb_type].cbp;\n h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;\n mb_type= i_mb_type_info[mb_type].type;\n }\n if(MB_FIELD)\n mb_type |= MB_TYPE_INTERLACED;\n h->slice_table[ mb_xy ]= h->slice_num;\n if(IS_INTRA_PCM(mb_type)) {\n static const uint16_t mb_sizes[4] = {256,384,512,768};\n const int mb_size = mb_sizes[h->sps.chroma_format_idc]*h->sps.bit_depth_luma >> 3;\n const uint8_t *ptr;\n ptr= h->cabac.bytestream;\n if(h->cabac.low&0x1) ptr--;\n if(CABAC_BITS==16){\n if(h->cabac.low&0x1FF) ptr--;\n }\n memcpy(h->mb, ptr, mb_size); ptr+=mb_size;\n ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);\n h->cbp_table[mb_xy] = 0xf7ef;\n h->chroma_pred_mode_table[mb_xy] = 0;\n s->current_picture.qscale_table[mb_xy]= 0;\n memset(h->non_zero_count[mb_xy], 16, 48);\n s->current_picture.mb_type[mb_xy]= mb_type;\n h->last_qscale_diff = 0;\n return 0;\n }\n if(MB_MBAFF){\n h->ref_count[0] <<= 1;\n h->ref_count[1] <<= 1;\n }\n fill_decode_caches(h, mb_type);\n if( IS_INTRA( mb_type ) ) {\n int i, pred_mode;\n if( IS_INTRA4x4( mb_type ) ) {\n if( dct8x8_allowed && get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ) ) {\n mb_type |= MB_TYPE_8x8DCT;\n for( i = 0; i < 16; i+=4 ) {\n int pred = pred_intra_mode( h, i );\n int mode = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );\n }\n } else {\n for( i = 0; i < 16; i++ ) {\n int pred = pred_intra_mode( h, i );\n h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n }\n }\n write_back_intra_pred_mode(h);\n if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1;\n } else {\n h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode );\n if( h->intra16x16_pred_mode < 0 ) return -1;\n }\n if(decode_chroma){\n h->chroma_pred_mode_table[mb_xy] =\n pred_mode = decode_cabac_mb_chroma_pre_mode( h );\n pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode );\n if( pred_mode < 0 ) return -1;\n h->chroma_pred_mode= pred_mode;\n } else {\n h->chroma_pred_mode= DC_128_PRED8x8;\n }\n } else if( partition_count == 4 ) {\n int i, j, sub_partition_count[4], list, ref[2][4];\n if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {\n for( i = 0; i < 4; i++ ) {\n h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h );\n sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] |\n h->sub_mb_type[2] | h->sub_mb_type[3]) ) {\n ff_h264_pred_direct_motion(h, &mb_type);\n h->ref_cache[0][scan8[4]] =\n h->ref_cache[1][scan8[4]] =\n h->ref_cache[0][scan8[12]] =\n h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n for( i = 0; i < 4; i++ )\n fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, (h->sub_mb_type[i]>>1)&0xFF, 1 );\n }\n } else {\n for( i = 0; i < 4; i++ ) {\n h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h );\n sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n }\n for( list = 0; list < h->list_count; list++ ) {\n for( i = 0; i < 4; i++ ) {\n if(IS_DIRECT(h->sub_mb_type[i])) continue;\n if(IS_DIR(h->sub_mb_type[i], 0, list)){\n if( h->ref_count[list] > 1 ){\n ref[list][i] = decode_cabac_mb_ref( h, list, 4*i );\n if(ref[list][i] >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref[list][i], h->ref_count[list]);\n return -1;\n }\n }else\n ref[list][i] = 0;\n } else {\n ref[list][i] = -1;\n }\n h->ref_cache[list][ scan8[4*i]+1 ]=\n h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];\n }\n }\n if(dct8x8_allowed)\n dct8x8_allowed = get_dct8x8_allowed(h);\n for(list=0; list<h->list_count; list++){\n for(i=0; i<4; i++){\n h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ];\n if(IS_DIRECT(h->sub_mb_type[i])){\n fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 2);\n continue;\n }\n if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){\n const int sub_mb_type= h->sub_mb_type[i];\n const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;\n for(j=0; j<sub_partition_count[i]; j++){\n int mpx, mpy;\n int mx, my;\n const int index= 4*i + block_width*j;\n int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];\n uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];\n pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, index)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n if(IS_SUB_8X8(sub_mb_type)){\n mv_cache[ 1 ][0]=\n mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;\n mv_cache[ 1 ][1]=\n mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;\n mvd_cache[ 1 ][0]=\n mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mpx;\n mvd_cache[ 1 ][1]=\n mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mpy;\n }else if(IS_SUB_8X4(sub_mb_type)){\n mv_cache[ 1 ][0]= mx;\n mv_cache[ 1 ][1]= my;\n mvd_cache[ 1 ][0]= mpx;\n mvd_cache[ 1 ][1]= mpy;\n }else if(IS_SUB_4X8(sub_mb_type)){\n mv_cache[ 8 ][0]= mx;\n mv_cache[ 8 ][1]= my;\n mvd_cache[ 8 ][0]= mpx;\n mvd_cache[ 8 ][1]= mpy;\n }\n mv_cache[ 0 ][0]= mx;\n mv_cache[ 0 ][1]= my;\n mvd_cache[ 0 ][0]= mpx;\n mvd_cache[ 0 ][1]= mpy;\n }\n }else{\n fill_rectangle(h->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4);\n fill_rectangle(h->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2);\n }\n }\n }\n } else if( IS_DIRECT(mb_type) ) {\n ff_h264_pred_direct_motion(h, &mb_type);\n fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 2);\n fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2);\n dct8x8_allowed &= h->sps.direct_8x8_inference_flag;\n } else {\n int list, i;\n if(IS_16X16(mb_type)){\n for(list=0; list<h->list_count; list++){\n if(IS_DIR(mb_type, 0, list)){\n int ref;\n if(h->ref_count[list] > 1){\n ref= decode_cabac_mb_ref(h, list, 0);\n if(ref >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n if(IS_DIR(mb_type, 0, list)){\n int mx,my,mpx,mpy;\n pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 0)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2);\n fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);\n }\n }\n }\n else if(IS_16X8(mb_type)){\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int ref;\n if(h->ref_count[list] > 1){\n ref= decode_cabac_mb_ref( h, list, 8*i );\n if(ref >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1);\n }else\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int mx,my,mpx,mpy;\n pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 8*i)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2);\n fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);\n }else{\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 2);\n fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);\n }\n }\n }\n }else{\n assert(IS_8X16(mb_type));\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int ref;\n if(h->ref_count[list] > 1){\n ref= decode_cabac_mb_ref( h, list, 4*i );\n if(ref >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1);\n }else\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int mx,my,mpx,mpy;\n pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 4*i)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2);\n fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);\n }else{\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 2);\n fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);\n }\n }\n }\n }\n }\n if( IS_INTER( mb_type ) ) {\n h->chroma_pred_mode_table[mb_xy] = 0;\n write_back_motion( h, mb_type );\n }\n if( !IS_INTRA16x16( mb_type ) ) {\n cbp = decode_cabac_mb_cbp_luma( h );\n if(decode_chroma)\n cbp |= decode_cabac_mb_cbp_chroma( h ) << 4;\n }\n h->cbp_table[mb_xy] = h->cbp = cbp;\n if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) {\n mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] );\n }\n if (CHROMA444 && IS_8x8DCT(mb_type)){\n int i;\n uint8_t *nnz_cache = h->non_zero_count_cache;\n for (i = 0; i < 2; i++){\n if (h->left_type[LEFT(i)] && !IS_8x8DCT(h->left_type[LEFT(i)])){\n nnz_cache[3+8* 1 + 2*8*i]=\n nnz_cache[3+8* 2 + 2*8*i]=\n nnz_cache[3+8* 6 + 2*8*i]=\n nnz_cache[3+8* 7 + 2*8*i]=\n nnz_cache[3+8*11 + 2*8*i]=\n nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;\n }\n }\n if (h->top_type && !IS_8x8DCT(h->top_type)){\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 }\n s->current_picture.mb_type[mb_xy]= mb_type;\n if( cbp || IS_INTRA16x16( mb_type ) ) {\n const uint8_t *scan, *scan8x8;\n const uint32_t *qmul;\n if(IS_INTERLACED(mb_type)){\n scan8x8= s->qscale ? h->field_scan8x8 : h->field_scan8x8_q0;\n scan= s->qscale ? h->field_scan : h->field_scan_q0;\n }else{\n scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;\n scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n }\n if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){\n int val = 1;\n int ctx= 2;\n const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);\n while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {\n ctx= 3;\n val++;\n if(val > 2*max_qp){\n av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\\n", s->mb_x, s->mb_y);\n return -1;\n }\n }\n if( val&0x01 )\n val= (val + 1)>>1 ;\n else\n val= -((val + 1)>>1);\n h->last_qscale_diff = val;\n s->qscale += val;\n if(((unsigned)s->qscale) > max_qp){\n if(s->qscale<0) s->qscale+= max_qp+1;\n else s->qscale-= max_qp+1;\n }\n h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n }else\n h->last_qscale_diff=0;\n decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 0);\n if(CHROMA444){\n decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);\n decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2);\n } else {\n if( cbp&0x30 ){\n int c;\n for( c = 0; c < 2; c++ ) {\n decode_cabac_residual_dc(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4);\n }\n }\n if( cbp&0x20 ) {\n int c, i;\n for( c = 0; c < 2; c++ ) {\n qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];\n for( i = 0; i < 4; i++ ) {\n const int index = 16 + 16 * c + i;\n decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15);\n }\n }\n } else {\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n }\n }\n } else {\n fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n h->last_qscale_diff = 0;\n }\n s->current_picture.qscale_table[mb_xy]= s->qscale;\n write_back_non_zero_count(h);\n if(MB_MBAFF){\n h->ref_count[0] >>= 1;\n h->ref_count[1] >>= 1;\n }\n return 0;\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.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.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.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.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.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->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}']
|
2,747
| 0
|
https://github.com/openssl/openssl/blob/ed371b8cbac0d0349667558c061c1ae380cf75eb/crypto/bn/bn_ctx.c/#L276
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,\n const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,\n int (*bn_mod_exp) (BIGNUM *r,\n const BIGNUM *a,\n const BIGNUM *p,\n const BIGNUM *m,\n BN_CTX *ctx,\n BN_MONT_CTX *m_ctx),\n BN_MONT_CTX *m_ctx)\n{\n int retry_counter = 32;\n BN_BLINDING *ret = NULL;\n if (b == NULL)\n ret = BN_BLINDING_new(NULL, NULL, m);\n else\n ret = b;\n if (ret == NULL)\n goto err;\n if (ret->A == NULL && (ret->A = BN_new()) == NULL)\n goto err;\n if (ret->Ai == NULL && (ret->Ai = BN_new()) == NULL)\n goto err;\n if (e != NULL) {\n BN_free(ret->e);\n ret->e = BN_dup(e);\n }\n if (ret->e == NULL)\n goto err;\n if (bn_mod_exp != NULL)\n ret->bn_mod_exp = bn_mod_exp;\n if (m_ctx != NULL)\n ret->m_ctx = m_ctx;\n do {\n int rv;\n if (!BN_priv_rand_range(ret->A, ret->mod))\n goto err;\n if (int_bn_mod_inverse(ret->Ai, ret->A, ret->mod, ctx, &rv))\n break;\n if (!rv)\n goto err;\n if (retry_counter-- == 0) {\n BNerr(BN_F_BN_BLINDING_CREATE_PARAM, BN_R_TOO_MANY_ITERATIONS);\n goto err;\n }\n } while (1);\n if (ret->bn_mod_exp != NULL && ret->m_ctx != NULL) {\n if (!ret->bn_mod_exp(ret->A, ret->A, ret->e, ret->mod, ctx, ret->m_ctx))\n goto err;\n } else {\n if (!BN_mod_exp(ret->A, ret->A, ret->e, ret->mod, ctx))\n goto err;\n }\n if (ret->m_ctx != NULL) {\n if (!bn_to_mont_fixed_top(ret->Ai, ret->Ai, ret->m_ctx, ctx)\n || !bn_to_mont_fixed_top(ret->A, ret->A, ret->m_ctx, ctx))\n goto err;\n }\n return ret;\n err:\n if (b == NULL) {\n BN_BLINDING_free(ret);\n ret = NULL;\n }\n return ret;\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}', '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 ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n const BIGNUM *divisor, BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnum, *wnumtop;\n BN_ULONG d0, d1;\n int num_n, div_n;\n assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);\n bn_check_top(num);\n bn_check_top(divisor);\n bn_check_top(dv);\n bn_check_top(rm);\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n if (!BN_copy(sdiv, divisor))\n goto err;\n norm_shift = bn_left_align(sdiv);\n sdiv->neg = 0;\n if (!(bn_lshift_fixed_top(snum, num, norm_shift)))\n goto err;\n div_n = sdiv->top;\n num_n = snum->top;\n if (num_n <= div_n) {\n if (bn_wexpand(snum, div_n + 1) == NULL)\n goto err;\n memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));\n snum->top = num_n = div_n + 1;\n }\n loop = num_n - div_n;\n wnum = &(snum->d[loop]);\n wnumtop = &(snum->d[num_n - 1]);\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n if (!bn_wexpand(res, loop))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop;\n res->flags |= BN_FLG_FIXED_TOP;\n resp = &(res->d[loop]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n for (i = 0; i < loop; i++, wnumtop--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnumtop, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnumtop[0];\n n1 = wnumtop[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum--;\n l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);\n q -= l0;\n for (l0 = 0 - l0, j = 0; j < div_n; j++)\n tmp->d[j] = sdiv->d[j] & l0;\n l0 = bn_add_words(wnum, wnum, tmp->d, div_n);\n (*wnumtop) += l0;\n assert((*wnumtop) == 0);\n *--resp = q;\n }\n snum->neg = num->neg;\n snum->top = div_n;\n snum->flags |= BN_FLG_FIXED_TOP;\n if (rm != NULL)\n bn_rshift_fixed_top(rm, snum, norm_shift);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
2,748
| 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 *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x,\n BIGNUM *a, BIGNUM *u)\n{\n BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL, *k = NULL, *K = NULL;\n BN_CTX *bn_ctx;\n if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL\n || a == NULL || (bn_ctx = BN_CTX_new()) == NULL)\n return NULL;\n if ((tmp = BN_new()) == NULL ||\n (tmp2 = BN_new()) == NULL ||\n (tmp3 = BN_new()) == NULL || (K = BN_new()) == NULL)\n goto err;\n if (!BN_mod_exp(tmp, g, x, N, bn_ctx))\n goto err;\n if (!(k = srp_Calc_k(N, g)))\n goto err;\n if (!BN_mod_mul(tmp2, tmp, k, N, bn_ctx))\n goto err;\n if (!BN_mod_sub(tmp, B, tmp2, N, bn_ctx))\n goto err;\n if (!BN_mod_mul(tmp3, u, x, N, bn_ctx))\n goto err;\n if (!BN_mod_add(tmp2, a, tmp3, N, bn_ctx))\n goto err;\n if (!BN_mod_exp(K, tmp, tmp2, N, bn_ctx))\n goto err;\n err:\n BN_CTX_free(bn_ctx);\n BN_clear_free(tmp);\n BN_clear_free(tmp2);\n BN_clear_free(tmp3);\n BN_free(k);\n return K;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return -1;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n ret = BN_one(r);\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (!aa || !val[0])\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return (ret);\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_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}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
2,749
| 0
|
https://github.com/libav/libav/blob/1c3e117e0bd73ffc5a3abeb35b521fd048988f06/libavfilter/vf_gradfun.c/#L135
|
static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
{
GradFunContext *gf = ctx->priv;
float thresh = 1.2;
int radius = 16;
av_unused int cpu_flags = av_get_cpu_flags();
if (args)
sscanf(args, "%f:%d", &thresh, &radius);
thresh = av_clipf(thresh, 0.51, 255);
gf->thresh = (1 << 15) / thresh;
gf->radius = av_clip((radius + 1) & ~1, 4, 32);
gf->blur_line = ff_gradfun_blur_line_c;
gf->filter_line = ff_gradfun_filter_line_c;
if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX2)
gf->filter_line = ff_gradfun_filter_line_mmx2;
if (HAVE_SSSE3 && cpu_flags & AV_CPU_FLAG_SSSE3)
gf->filter_line = ff_gradfun_filter_line_ssse3;
if (HAVE_SSE && cpu_flags & AV_CPU_FLAG_SSE2)
gf->blur_line = ff_gradfun_blur_line_sse2;
av_log(ctx, AV_LOG_INFO, "threshold:%.2f radius:%d\n", thresh, gf->radius);
return 0;
}
|
['static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)\n{\n GradFunContext *gf = ctx->priv;\n float thresh = 1.2;\n int radius = 16;\n av_unused int cpu_flags = av_get_cpu_flags();\n if (args)\n sscanf(args, "%f:%d", &thresh, &radius);\n thresh = av_clipf(thresh, 0.51, 255);\n gf->thresh = (1 << 15) / thresh;\n gf->radius = av_clip((radius + 1) & ~1, 4, 32);\n gf->blur_line = ff_gradfun_blur_line_c;\n gf->filter_line = ff_gradfun_filter_line_c;\n if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX2)\n gf->filter_line = ff_gradfun_filter_line_mmx2;\n if (HAVE_SSSE3 && cpu_flags & AV_CPU_FLAG_SSSE3)\n gf->filter_line = ff_gradfun_filter_line_ssse3;\n if (HAVE_SSE && cpu_flags & AV_CPU_FLAG_SSE2)\n gf->blur_line = ff_gradfun_blur_line_sse2;\n av_log(ctx, AV_LOG_INFO, "threshold:%.2f radius:%d\\n", thresh, gf->radius);\n return 0;\n}']
|
2,750
| 0
|
https://github.com/openssl/openssl/blob/b6a8916102b9bf84b33ade2030079d76d9ba60f6/crypto/evp/digest.c/#L358
|
int EVP_Digest(const void *data, size_t count,
unsigned char *md, unsigned int *size, const EVP_MD *type,
ENGINE *impl)
{
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
int ret;
if (ctx == NULL)
return 0;
EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT);
ret = EVP_DigestInit_ex(ctx, type, impl)
&& EVP_DigestUpdate(ctx, data, count)
&& EVP_DigestFinal_ex(ctx, md, size);
EVP_MD_CTX_free(ctx);
return ret;
}
|
['int EVP_Digest(const void *data, size_t count,\n unsigned char *md, unsigned int *size, const EVP_MD *type,\n ENGINE *impl)\n{\n EVP_MD_CTX *ctx = EVP_MD_CTX_new();\n int ret;\n if (ctx == NULL)\n return 0;\n EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_ONESHOT);\n ret = EVP_DigestInit_ex(ctx, type, impl)\n && EVP_DigestUpdate(ctx, data, count)\n && EVP_DigestFinal_ex(ctx, md, size);\n EVP_MD_CTX_free(ctx);\n return ret;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)\n{\n ctx->flags |= flags;\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}']
|
2,751
| 0
|
https://github.com/openssl/openssl/blob/1145e03870dd82eae00bb45e0b2162494b9b2f38/ssl/ssl_rsa.c/#L197
|
static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey)
{
int i,ok=0,bad=0;
i=ssl_cert_type(NULL,pkey);
if (i < 0)
{
SSLerr(SSL_F_SSL_SET_PKEY,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
return(0);
}
if (c->pkeys[i].x509 != NULL)
{
EVP_PKEY *pktmp;
pktmp = X509_get_pubkey(c->pkeys[i].x509);
EVP_PKEY_copy_parameters(pktmp,pkey);
EVP_PKEY_free(pktmp);
ERR_clear_error();
#ifndef OPENSSL_NO_RSA
if ((pkey->type == EVP_PKEY_RSA) &&
(RSA_flags(pkey->pkey.rsa) &
RSA_METHOD_FLAG_NO_CHECK))
ok=1;
else
#endif
if (!X509_check_private_key(c->pkeys[i].x509,pkey))
{
if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA))
{
i=(i == SSL_PKEY_DH_RSA)?
SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA;
if (c->pkeys[i].x509 == NULL)
ok=1;
else
{
if (!X509_check_private_key(
c->pkeys[i].x509,pkey))
bad=1;
else
ok=1;
}
}
else
bad=1;
}
else
ok=1;
}
else
ok=1;
if (bad)
{
X509_free(c->pkeys[i].x509);
c->pkeys[i].x509=NULL;
return(0);
}
ERR_clear_error();
if (c->pkeys[i].privatekey != NULL)
EVP_PKEY_free(c->pkeys[i].privatekey);
CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
c->pkeys[i].privatekey=pkey;
c->key= &(c->pkeys[i]);
c->valid=0;
return(1);
}
|
['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 OPENSSL_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 if (!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\tERR_clear_error();\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#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)\n\tconst unsigned char *cp;\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t\t{\n\t\tCRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);\n\t\treturn(key->pkey);\n\t\t}\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tif ((ret = EVP_PKEY_new()) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tret->type = EVP_PKEY_type(type);\n#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)\n\ta=key->algor;\n#endif\n\tif (0)\n\t\t;\n#ifndef OPENSSL_NO_DSA\n\telse if (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))\n\t\t\t{\n\t\t\tif ((ret->pkey.dsa = DSA_new()) == NULL)\n\t\t\t\t{\n\t\t\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tcp=p=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa, &cp, (long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_EC\n\telse if (ret->type == EVP_PKEY_EC)\n\t\t{\n\t\tif (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))\n\t\t\t{\n\t\t\tif ((ret->pkey.eckey= EC_KEY_new()) == NULL)\n\t\t\t\t{\n\t\t\t\tX509err(X509_F_X509_PUBKEY_GET,\n\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tcp = p = a->parameter->value.sequence->data;\n\t\t\tj = a->parameter->value.sequence->length;\n\t\t\tif (!d2i_ECParameters(&ret->pkey.eckey, &cp, (long)j))\n\t\t\t\t{\n\t\t\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_EC_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse if (a->parameter && (a->parameter->type == V_ASN1_OBJECT))\n\t\t\t{\n\t\t\tEC_KEY *eckey;\n\t\t\tif (ret->pkey.eckey == NULL)\n\t\t\t\tret->pkey.eckey = EC_KEY_new();\n\t\t\teckey = ret->pkey.eckey;\n\t\t\tif (eckey->group)\n\t\t\t\tEC_GROUP_free(eckey->group);\n\t\t\tif ((eckey->group = EC_GROUP_new_by_nid(\n OBJ_obj2nid(a->parameter->value.object))) == NULL)\n\t\t\t\tgoto err;\n\t\t\tEC_GROUP_set_asn1_flag(eckey->group,\n\t\t\t\t\t\tOPENSSL_EC_NAMED_CURVE);\n\t\t\t}\n\t\tret->save_parameters = 1;\n\t\t}\n#endif\n\tp=key->public_key->data;\n j=key->public_key->length;\n if (!d2i_PublicKey(type, &ret, &p, (long)j))\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET, X509_R_ERR_ASN1_LIB);\n\t\tgoto err;\n\t\t}\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}', 'int OBJ_obj2nid(const ASN1_OBJECT *a)\n\t{\n\tASN1_OBJECT **op;\n\tADDED_OBJ ad,*adp;\n\tif (a == NULL)\n\t\treturn(NID_undef);\n\tif (a->nid != 0)\n\t\treturn(a->nid);\n\tif (added != NULL)\n\t\t{\n\t\tad.type=ADDED_DATA;\n\t\tad.obj=(ASN1_OBJECT *)a;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,&ad);\n\t\tif (adp != NULL) return (adp->obj->nid);\n\t\t}\n\top=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,\n\t\tsizeof(ASN1_OBJECT *),obj_cmp);\n\tif (op == NULL)\n\t\treturn(NID_undef);\n\treturn((*op)->nid);\n\t}', 'void *lh_retrieve(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE **rn;\n\tconst void *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_retrieve_miss++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tret= (*rn)->data;\n\t\tlh->num_retrieve++;\n\t\t}\n\treturn((void *)ret);\n\t}', 'EVP_PKEY *EVP_PKEY_new(void)\n\t{\n\tEVP_PKEY *ret;\n\tret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));\n\tif (ret == NULL)\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->type=EVP_PKEY_NONE;\n\tret->references=1;\n\tret->pkey.ptr=NULL;\n\tret->attributes=NULL;\n\tret->save_parameters=1;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)\n\t{\n\tif (to->type != from->type)\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);\n\t\tgoto err;\n\t\t}\n\tif (EVP_PKEY_missing_parameters(from))\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);\n\t\tgoto err;\n\t\t}\n#ifndef OPENSSL_NO_DSA\n\tif (to->type == EVP_PKEY_DSA)\n\t\t{\n\t\tBIGNUM *a;\n\t\tif ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err;\n\t\tif (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p);\n\t\tto->pkey.dsa->p=a;\n\t\tif ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err;\n\t\tif (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q);\n\t\tto->pkey.dsa->q=a;\n\t\tif ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err;\n\t\tif (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g);\n\t\tto->pkey.dsa->g=a;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_EC\n\tif (to->type == EVP_PKEY_EC)\n\t\t{\n\t\tif (to->pkey.eckey->group != NULL)\n\t\t\tEC_GROUP_free(to->pkey.eckey->group);\n\t\tif ((to->pkey.eckey->group = EC_GROUP_new(\n\t\t\tEC_GROUP_method_of(from->pkey.eckey->group))) == NULL)\n\t\t\tgoto err;\n\t\tif (!EC_GROUP_copy(to->pkey.eckey->group,\n\t\t\tfrom->pkey.eckey->group)) goto err;\n\t\t}\n#endif\n\treturn(1);\nerr:\n\treturn(0);\n\t}']
|
2,752
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L266
|
static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){
const int lt= src[-1-1*stride];
LOAD_TOP_EDGE
LOAD_LEFT_EDGE
src[0+0*stride]=
src[1+2*stride]=(lt + t0 + 1)>>1;
src[1+0*stride]=
src[2+2*stride]=(t0 + t1 + 1)>>1;
src[2+0*stride]=
src[3+2*stride]=(t1 + t2 + 1)>>1;
src[3+0*stride]=(t2 + t3 + 1)>>1;
src[0+1*stride]=
src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
src[1+1*stride]=
src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2;
src[2+1*stride]=
src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2;
src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2;
src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
}
|
['static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){\n const int lt= src[-1-1*stride];\n LOAD_TOP_EDGE\n LOAD_LEFT_EDGE\n src[0+0*stride]=\n src[1+2*stride]=(lt + t0 + 1)>>1;\n src[1+0*stride]=\n src[2+2*stride]=(t0 + t1 + 1)>>1;\n src[2+0*stride]=\n src[3+2*stride]=(t1 + t2 + 1)>>1;\n src[3+0*stride]=(t2 + t3 + 1)>>1;\n src[0+1*stride]=\n src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2;\n src[1+1*stride]=\n src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2;\n src[2+1*stride]=\n src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2;\n src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2;\n src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2;\n src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;\n}']
|
2,753
| 0
|
https://github.com/libav/libav/blob/fd16f567987524a769d5d4f1f69089f000386ac2/libavcodec/h264.c/#L3720
|
static int execute_decode_slices(H264Context *h, int context_count){
MpegEncContext * const s = &h->s;
AVCodecContext * const avctx= s->avctx;
H264Context *hx;
int i;
if (s->avctx->hwaccel || s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
return 0;
if(context_count == 1) {
return decode_slice(avctx, &h);
} else {
for(i = 1; i < context_count; i++) {
hx = h->thread_context[i];
hx->s.err_recognition = avctx->err_recognition;
hx->s.error_count = 0;
}
avctx->execute(avctx, decode_slice,
h->thread_context, NULL, context_count, sizeof(void*));
hx = h->thread_context[context_count - 1];
s->mb_x = hx->s.mb_x;
s->mb_y = hx->s.mb_y;
s->dropable = hx->s.dropable;
s->picture_structure = hx->s.picture_structure;
for(i = 1; i < context_count; i++)
h->s.error_count += h->thread_context[i]->s.error_count;
}
return 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 = s->slice_context_count;\n if(!(s->flags2 & CODEC_FLAG2_CHUNKS)){\n h->current_slice = 0;\n if (!s->first_field)\n s->current_picture_ptr= NULL;\n ff_h264_reset_sei(h);\n }\n for(;pass <= 1;pass++){\n buf_index = 0;\n context_count = 0;\n next_avc = h->is_avc ? 0 : buf_size;\n nal_index = 0;\n for(;;){\n int consumed;\n int dst_length;\n int bit_length;\n uint8_t *ptr;\n int i, nalsize = 0;\n int err;\n if(buf_index >= next_avc) {\n if (buf_index >= buf_size - h->nal_length_size) 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 if (bit_length & 7)\n ptr[bit_length >> 3] = ptr[bit_length >> 3] & (0xff << 8 - (bit_length & 7));\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 h->cur_chroma_format_idc != h->sps.chroma_format_idc) {\n if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10) {\n avctx->bits_per_raw_sample = h->sps.bit_depth_luma;\n h->cur_chroma_format_idc = h->sps.chroma_format_idc;\n h->pixel_shift = h->sps.bit_depth_luma > 8;\n ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma, h->sps.chroma_format_idc);\n ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma, h->sps.chroma_format_idc);\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_ERROR, "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 execute_decode_slices(H264Context *h, int context_count){\n MpegEncContext * const s = &h->s;\n AVCodecContext * const avctx= s->avctx;\n H264Context *hx;\n int i;\n if (s->avctx->hwaccel || s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)\n return 0;\n if(context_count == 1) {\n return decode_slice(avctx, &h);\n } else {\n for(i = 1; i < context_count; i++) {\n hx = h->thread_context[i];\n hx->s.err_recognition = avctx->err_recognition;\n hx->s.error_count = 0;\n }\n avctx->execute(avctx, decode_slice,\n h->thread_context, NULL, context_count, sizeof(void*));\n hx = h->thread_context[context_count - 1];\n s->mb_x = hx->s.mb_x;\n s->mb_y = hx->s.mb_y;\n s->dropable = hx->s.dropable;\n s->picture_structure = hx->s.picture_structure;\n for(i = 1; i < context_count; i++)\n h->s.error_count += h->thread_context[i]->s.error_count;\n }\n return 0;\n}']
|
2,754
| 0
|
https://gitlab.com/libtiff/libtiff/blob/d85a64b6d6379c9f9b8de6ff3a26e380b0fc3e18/tools/tiff2pdf.c/#L1836
|
void t2p_read_tiff_size(T2P* t2p, TIFF* input){
uint64* sbc=NULL;
#if defined(JPEG_SUPPORT) || defined (OJPEG_SUPPORT)
unsigned char* jpt=NULL;
tstrip_t i=0;
tstrip_t stripcount=0;
#endif
uint64 k = 0;
if(t2p->pdf_transcode == T2P_TRANSCODE_RAW){
#ifdef CCITT_SUPPORT
if(t2p->pdf_compression == T2P_COMPRESS_G4 ){
TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc);
t2p->tiff_datasize=(tmsize_t)sbc[0];
return;
}
#endif
#ifdef ZIP_SUPPORT
if(t2p->pdf_compression == T2P_COMPRESS_ZIP){
TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc);
t2p->tiff_datasize=(tmsize_t)sbc[0];
return;
}
#endif
#ifdef OJPEG_SUPPORT
if(t2p->tiff_compression == COMPRESSION_OJPEG){
if(!TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc)){
TIFFError(TIFF2PDF_MODULE,
"Input file %s missing field: TIFFTAG_STRIPBYTECOUNTS",
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return;
}
stripcount=TIFFNumberOfStrips(input);
for(i=0;i<stripcount;i++){
k = checkAdd64(k, sbc[i], t2p);
}
if(TIFFGetField(input, TIFFTAG_JPEGIFOFFSET, &(t2p->tiff_dataoffset))){
if(t2p->tiff_dataoffset != 0){
if(TIFFGetField(input, TIFFTAG_JPEGIFBYTECOUNT, &(t2p->tiff_datasize))!=0){
if((uint64)t2p->tiff_datasize < k) {
TIFFWarning(TIFF2PDF_MODULE,
"Input file %s has short JPEG interchange file byte count",
TIFFFileName(input));
t2p->pdf_ojpegiflength=t2p->tiff_datasize;
k = checkAdd64(k, t2p->tiff_datasize, t2p);
k = checkAdd64(k, 6, t2p);
k = checkAdd64(k, stripcount, t2p);
k = checkAdd64(k, stripcount, t2p);
t2p->tiff_datasize = (tsize_t) k;
if ((uint64) t2p->tiff_datasize != k) {
TIFFError(TIFF2PDF_MODULE, "Integer overflow");
t2p->t2p_error = T2P_ERR_ERROR;
}
return;
}
return;
}else {
TIFFError(TIFF2PDF_MODULE,
"Input file %s missing field: TIFFTAG_JPEGIFBYTECOUNT",
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return;
}
}
}
k = checkAdd64(k, stripcount, t2p);
k = checkAdd64(k, stripcount, t2p);
k = checkAdd64(k, 2048, t2p);
t2p->tiff_datasize = (tsize_t) k;
if ((uint64) t2p->tiff_datasize != k) {
TIFFError(TIFF2PDF_MODULE, "Integer overflow");
t2p->t2p_error = T2P_ERR_ERROR;
}
return;
}
#endif
#ifdef JPEG_SUPPORT
if(t2p->tiff_compression == COMPRESSION_JPEG) {
uint32 count = 0;
if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0 ){
if(count > 4){
k += count;
k -= 2;
}
} else {
k = 2;
}
stripcount=TIFFNumberOfStrips(input);
if(!TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc)){
TIFFError(TIFF2PDF_MODULE,
"Input file %s missing field: TIFFTAG_STRIPBYTECOUNTS",
TIFFFileName(input));
t2p->t2p_error = T2P_ERR_ERROR;
return;
}
for(i=0;i<stripcount;i++){
k = checkAdd64(k, sbc[i], t2p);
k -=4;
}
k = checkAdd64(k, 2, t2p);
t2p->tiff_datasize = (tsize_t) k;
if ((uint64) t2p->tiff_datasize != k) {
TIFFError(TIFF2PDF_MODULE, "Integer overflow");
t2p->t2p_error = T2P_ERR_ERROR;
}
return;
}
#endif
(void) 0;
}
k = checkMultiply64(TIFFScanlineSize(input), t2p->tiff_length, t2p);
if(t2p->tiff_planar==PLANARCONFIG_SEPARATE){
k = checkMultiply64(k, t2p->tiff_samplesperpixel, t2p);
}
if (k == 0) {
t2p->t2p_error = T2P_ERR_ERROR;
}
t2p->tiff_datasize = (tsize_t) k;
if ((uint64) t2p->tiff_datasize != k) {
TIFFError(TIFF2PDF_MODULE, "Integer overflow");
t2p->t2p_error = T2P_ERR_ERROR;
}
return;
}
|
['void t2p_read_tiff_size(T2P* t2p, TIFF* input){\n\tuint64* sbc=NULL;\n#if defined(JPEG_SUPPORT) || defined (OJPEG_SUPPORT)\n\tunsigned char* jpt=NULL;\n\ttstrip_t i=0;\n\ttstrip_t stripcount=0;\n#endif\n uint64 k = 0;\n\tif(t2p->pdf_transcode == T2P_TRANSCODE_RAW){\n#ifdef CCITT_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_G4 ){\n\t\t\tTIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc);\n\t\t\tt2p->tiff_datasize=(tmsize_t)sbc[0];\n\t\t\treturn;\n\t\t}\n#endif\n#ifdef ZIP_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_ZIP){\n\t\t\tTIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc);\n\t\t\tt2p->tiff_datasize=(tmsize_t)sbc[0];\n\t\t\treturn;\n\t\t}\n#endif\n#ifdef OJPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_OJPEG){\n\t\t\tif(!TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc)){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Input file %s missing field: TIFFTAG_STRIPBYTECOUNTS",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstripcount=TIFFNumberOfStrips(input);\n\t\t\tfor(i=0;i<stripcount;i++){\n\t\t\t\tk = checkAdd64(k, sbc[i], t2p);\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGIFOFFSET, &(t2p->tiff_dataoffset))){\n\t\t\t\tif(t2p->tiff_dataoffset != 0){\n\t\t\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGIFBYTECOUNT, &(t2p->tiff_datasize))!=0){\n\t\t\t\t\t\tif((uint64)t2p->tiff_datasize < k) {\n\t\t\t\t\t\t\tTIFFWarning(TIFF2PDF_MODULE,\n\t\t\t\t\t\t\t\t"Input file %s has short JPEG interchange file byte count",\n\t\t\t\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\t\t\tt2p->pdf_ojpegiflength=t2p->tiff_datasize;\n\t\t\t\t\t\t\tk = checkAdd64(k, t2p->tiff_datasize, t2p);\n\t\t\t\t\t\t\tk = checkAdd64(k, 6, t2p);\n\t\t\t\t\t\t\tk = checkAdd64(k, stripcount, t2p);\n\t\t\t\t\t\t\tk = checkAdd64(k, stripcount, t2p);\n\t\t\t\t\t\t\tt2p->tiff_datasize = (tsize_t) k;\n\t\t\t\t\t\t\tif ((uint64) t2p->tiff_datasize != k) {\n\t\t\t\t\t\t\t\tTIFFError(TIFF2PDF_MODULE, "Integer overflow");\n\t\t\t\t\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}else {\n\t\t\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t\t\t"Input file %s missing field: TIFFTAG_JPEGIFBYTECOUNT",\n\t\t\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tk = checkAdd64(k, stripcount, t2p);\n\t\t\tk = checkAdd64(k, stripcount, t2p);\n\t\t\tk = checkAdd64(k, 2048, t2p);\n\t\t\tt2p->tiff_datasize = (tsize_t) k;\n\t\t\tif ((uint64) t2p->tiff_datasize != k) {\n\t\t\t\tTIFFError(TIFF2PDF_MODULE, "Integer overflow");\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n#endif\n#ifdef JPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_JPEG) {\n\t\t\tuint32 count = 0;\n\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0 ){\n\t\t\t\tif(count > 4){\n\t\t\t\t\tk += count;\n\t\t\t\t\tk -= 2;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tk = 2;\n\t\t\t}\n\t\t\tstripcount=TIFFNumberOfStrips(input);\n\t\t\tif(!TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc)){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Input file %s missing field: TIFFTAG_STRIPBYTECOUNTS",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(i=0;i<stripcount;i++){\n\t\t\t\tk = checkAdd64(k, sbc[i], t2p);\n\t\t\t\tk -=4;\n\t\t\t}\n\t\t\tk = checkAdd64(k, 2, t2p);\n\t\t\tt2p->tiff_datasize = (tsize_t) k;\n\t\t\tif ((uint64) t2p->tiff_datasize != k) {\n\t\t\t\tTIFFError(TIFF2PDF_MODULE, "Integer overflow");\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n#endif\n\t\t(void) 0;\n\t}\n\tk = checkMultiply64(TIFFScanlineSize(input), t2p->tiff_length, t2p);\n\tif(t2p->tiff_planar==PLANARCONFIG_SEPARATE){\n\t\tk = checkMultiply64(k, t2p->tiff_samplesperpixel, t2p);\n\t}\n\tif (k == 0) {\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t}\n\tt2p->tiff_datasize = (tsize_t) k;\n\tif ((uint64) t2p->tiff_datasize != k) {\n\t\tTIFFError(TIFF2PDF_MODULE, "Integer overflow");\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t}\n\treturn;\n}', 'int\nTIFFGetField(TIFF* tif, uint32 tag, ...)\n{\n\tint status;\n\tva_list ap;\n\tva_start(ap, tag);\n\tstatus = TIFFVGetField(tif, tag, ap);\n\tva_end(ap);\n\treturn (status);\n}', 'uint32\nTIFFNumberOfStrips(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 nstrips;\n\tnstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 :\n\t TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\tnstrips = _TIFFMultiply32(tif, nstrips, (uint32)td->td_samplesperpixel,\n\t\t "TIFFNumberOfStrips");\n\treturn (nstrips);\n}', 'uint32\n_TIFFMultiply32(TIFF* tif, uint32 first, uint32 second, const char* where)\n{\n\tuint32 bytes = first * second;\n\tif (second && bytes / second != first) {\n\t\tTIFFErrorExt(tif->tif_clientdata, where, "Integer overflow in %s", where);\n\t\tbytes = 0;\n\t}\n\treturn bytes;\n}']
|
2,755
| 0
|
https://github.com/openssl/openssl/blob/64c3da230f557e85422f76c9e3c45fac9b16466c/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_SECG_PRIME_112R1:\n\tcase EC_GROUP_WTLS_6:\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_WTLS_8:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_WTLS_8);\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\tcase EC_GROUP_WTLS_7:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_160R2);\n\t\tbreak;\n\tcase EC_GROUP_WTLS_9:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_WTLS_9);\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_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_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_224R1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_NIST_PRIME_224);\n\t\tbreak;\n\tcase EC_GROUP_WTLS_12:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_WTLS_12);\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_SECG_PRIME_256K1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_SECG_PRIME_256K1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_256R1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_X9_62_PRIME_256V1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_384R1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_NIST_PRIME_384);\n\t\tbreak;\n\tcase EC_GROUP_SECG_PRIME_521R1:\n\t\tret = ec_group_new_GFp_from_hex(_EC_GROUP_NIST_PRIME_521);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_113R1:\n\tcase EC_GROUP_WTLS_4:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_113R1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_113R2:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_113R2);\n\t\tbreak;\n\tcase EC_GROUP_WTLS_1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_WTLS_1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_131R1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_131R1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_131R2:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_131R2);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_163K1:\n\tcase EC_GROUP_WTLS_3:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_163K1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_163R1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_163R1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_163R2:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_163R2);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_163V1:\n\tcase EC_GROUP_WTLS_5:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_163V1);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_163V2:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_163V2);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_163V3:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_163V3);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_176V1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_176V1);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_191V1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_191V1);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_191V2:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_191V2);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_191V3:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_191V3);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_193R1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_193R1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_193R2:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_193R2);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_208W1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_208W1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_233K1:\n\tcase EC_GROUP_WTLS_10:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_233K1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_233R1:\n\tcase EC_GROUP_WTLS_11:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_233R1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_239K1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_239K1);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_239V1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_239V1);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_239V2:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_239V2);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_239V3:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_239V3);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_272W1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_272W1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_283K1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_283K1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_283R1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_283R1);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_304W1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_304W1);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_359V1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_359V1);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_368W1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_368W1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_409K1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_409K1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_409R1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_409R1);\n\t\tbreak;\n\tcase EC_GROUP_X9_62_CHAR2_431R1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_X9_62_CHAR2_431R1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_571K1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_571K1);\n\t\tbreak;\n\tcase EC_GROUP_SECG_CHAR2_571R1:\n\t\tret = ec_group_new_GF2m_from_hex(_EC_GROUP_SECG_CHAR2_571R1);\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_GF2m_from_hex(const char *prime_in,\n\t const char *a_in, const char *b_in,\n\t const char *x_in, const char *y_in, 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,*y=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 || (y = 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_GF2m(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 (!BN_hex2bn(&y, y_in)) goto bn_err;\n\tif (!EC_POINT_set_affine_coordinates_GF2m(group, P, x, y, 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_GF2M_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\tif (y) BN_free(y);\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}"]
|
2,756
| 0
|
https://github.com/openssl/openssl/blob/b59e1bed7da7933d4c6af750fe3f0300b57874fe/test/bntest.c/#L1260
|
int test_gf2m_add(BIO *bp)
{
BIGNUM *a, *b, *c;
int i, ret = 0;
a = BN_new();
b = BN_new();
c = BN_new();
for (i = 0; i < num0; i++) {
BN_rand(a, 512, 0, 0);
BN_copy(b, BN_value_one());
a->neg = rand_neg();
b->neg = rand_neg();
BN_GF2m_add(c, a, b);
if ((BN_is_odd(a) && BN_is_odd(c))
|| (!BN_is_odd(a) && !BN_is_odd(c))) {
fprintf(stderr, "GF(2^m) addition test (a) failed!\n");
goto err;
}
BN_GF2m_add(c, c, c);
if (!BN_is_zero(c)) {
fprintf(stderr, "GF(2^m) addition test (b) failed!\n");
goto err;
}
}
ret = 1;
err:
BN_free(a);
BN_free(b);
BN_free(c);
return ret;
}
|
['int test_gf2m_add(BIO *bp)\n{\n BIGNUM *a, *b, *c;\n int i, ret = 0;\n a = BN_new();\n b = BN_new();\n c = BN_new();\n for (i = 0; i < num0; i++) {\n BN_rand(a, 512, 0, 0);\n BN_copy(b, BN_value_one());\n a->neg = rand_neg();\n b->neg = rand_neg();\n BN_GF2m_add(c, a, b);\n if ((BN_is_odd(a) && BN_is_odd(c))\n || (!BN_is_odd(a) && !BN_is_odd(c))) {\n fprintf(stderr, "GF(2^m) addition test (a) failed!\\n");\n goto err;\n }\n BN_GF2m_add(c, c, c);\n if (!BN_is_zero(c)) {\n fprintf(stderr, "GF(2^m) addition test (b) failed!\\n");\n goto err;\n }\n }\n ret = 1;\n err:\n BN_free(a);\n BN_free(b);\n BN_free(c);\n return ret;\n}', 'BIGNUM *BN_new(void)\n{\n BIGNUM *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->flags = BN_FLG_MALLOCED;\n bn_check_top(ret);\n return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'void BN_free(BIGNUM *a)\n{\n if (a == NULL)\n return;\n bn_check_top(a);\n if (!BN_get_flags(a, BN_FLG_STATIC_DATA))\n bn_free_d(a);\n if (a->flags & BN_FLG_MALLOCED)\n OPENSSL_free(a);\n else {\n#if OPENSSL_API_COMPAT < 0x00908000L\n a->flags |= BN_FLG_FREE;\n#endif\n a->d = NULL;\n }\n}', 'int BN_get_flags(const BIGNUM *b, int n)\n{\n return b->flags & n;\n}']
|
2,757
| 0
|
https://github.com/nginx/nginx/blob/79ddab189fb4bf27abd21a04bb9d1210e06384ac/src/http/ngx_http_core_module.c/#L1801
|
void
ngx_http_set_exten(ngx_http_request_t *r)
{
ngx_int_t i;
ngx_str_null(&r->exten);
for (i = r->uri.len - 1; i > 1; i--) {
if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
r->exten.len = r->uri.len - i - 1;
r->exten.data = &r->uri.data[i + 1];
return;
} else if (r->uri.data[i] == '/') {
return;
}
}
return;
}
|
['static void\nngx_http_upstream_init_request(ngx_http_request_t *r)\n{\n ngx_str_t *host;\n ngx_uint_t i;\n ngx_resolver_ctx_t *ctx, temp;\n ngx_http_cleanup_t *cln;\n ngx_http_upstream_t *u;\n ngx_http_core_loc_conf_t *clcf;\n ngx_http_upstream_srv_conf_t *uscf, **uscfp;\n ngx_http_upstream_main_conf_t *umcf;\n if (r->aio) {\n return;\n }\n u = r->upstream;\n#if (NGX_HTTP_CACHE)\n if (u->conf->cache) {\n ngx_int_t rc;\n rc = ngx_http_upstream_cache(r, u);\n if (rc == NGX_BUSY) {\n r->write_event_handler = ngx_http_upstream_init_request;\n return;\n }\n r->write_event_handler = ngx_http_request_empty_handler;\n if (rc == NGX_DONE) {\n return;\n }\n if (rc == NGX_ERROR) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (rc != NGX_DECLINED) {\n ngx_http_finalize_request(r, rc);\n return;\n }\n }\n#endif\n u->store = (u->conf->store || u->conf->store_lengths);\n if (!u->store && !r->post_action && !u->conf->ignore_client_abort) {\n r->read_event_handler = ngx_http_upstream_rd_check_broken_connection;\n r->write_event_handler = ngx_http_upstream_wr_check_broken_connection;\n }\n if (r->request_body) {\n u->request_bufs = r->request_body->bufs;\n }\n if (u->create_request(r) != NGX_OK) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->peer.local = ngx_http_upstream_get_local(r, u->conf->local);\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n u->output.alignment = clcf->directio_alignment;\n u->output.pool = r->pool;\n u->output.bufs.num = 1;\n u->output.bufs.size = clcf->client_body_buffer_size;\n u->output.output_filter = ngx_chain_writer;\n u->output.filter_ctx = &u->writer;\n u->writer.pool = r->pool;\n if (r->upstream_states == NULL) {\n r->upstream_states = ngx_array_create(r->pool, 1,\n sizeof(ngx_http_upstream_state_t));\n if (r->upstream_states == NULL) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n } else {\n u->state = ngx_array_push(r->upstream_states);\n if (u->state == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));\n }\n cln = ngx_http_cleanup_add(r, 0);\n if (cln == NULL) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n cln->handler = ngx_http_upstream_cleanup;\n cln->data = r;\n u->cleanup = &cln->handler;\n if (u->resolved == NULL) {\n uscf = u->conf->upstream;\n } else {\n#if (NGX_HTTP_SSL)\n u->ssl_name = u->resolved->host;\n#endif\n if (u->resolved->sockaddr) {\n if (ngx_http_upstream_create_round_robin_peer(r, u->resolved)\n != NGX_OK)\n {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n ngx_http_upstream_connect(r, u);\n return;\n }\n host = &u->resolved->host;\n umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);\n uscfp = umcf->upstreams.elts;\n for (i = 0; i < umcf->upstreams.nelts; i++) {\n uscf = uscfp[i];\n if (uscf->host.len == host->len\n && ((uscf->port == 0 && u->resolved->no_port)\n || uscf->port == u->resolved->port)\n && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0)\n {\n goto found;\n }\n }\n if (u->resolved->port == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "no port in upstream \\"%V\\"", host);\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n temp.name = *host;\n ctx = ngx_resolve_start(clcf->resolver, &temp);\n if (ctx == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (ctx == NGX_NO_RESOLVER) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "no resolver defined to resolve %V", host);\n ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);\n return;\n }\n ctx->name = *host;\n ctx->handler = ngx_http_upstream_resolve_handler;\n ctx->data = r;\n ctx->timeout = clcf->resolver_timeout;\n u->resolved->ctx = ctx;\n if (ngx_resolve_name(ctx) != NGX_OK) {\n u->resolved->ctx = NULL;\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n return;\n }\nfound:\n if (uscf == NULL) {\n ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,\n "no upstream configuration");\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n#if (NGX_HTTP_SSL)\n u->ssl_name = uscf->host;\n#endif\n if (uscf->peer.init(r, uscf) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->peer.start_time = ngx_current_msec;\n if (u->conf->next_upstream_tries\n && u->peer.tries > u->conf->next_upstream_tries)\n {\n u->peer.tries = u->conf->next_upstream_tries;\n }\n ngx_http_upstream_connect(r, u);\n}', 'static ngx_int_t\nngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n ngx_int_t rc;\n ngx_http_cache_t *c;\n c = r->cache;\n if (c == NULL) {\n if (!(r->method & u->conf->cache_methods)) {\n return NGX_DECLINED;\n }\n if (r->method & NGX_HTTP_HEAD) {\n u->method = ngx_http_core_get_method;\n }\n if (ngx_http_file_cache_new(r) != NGX_OK) {\n return NGX_ERROR;\n }\n if (u->create_key(r) != NGX_OK) {\n return NGX_ERROR;\n }\n ngx_http_file_cache_create_key(r);\n if (r->cache->header_start + 256 >= u->conf->buffer_size) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "%V_buffer_size %uz is not enough for cache key, "\n "it should be increased to at least %uz",\n &u->conf->module, u->conf->buffer_size,\n ngx_align(r->cache->header_start + 256, 1024));\n r->cache = NULL;\n return NGX_DECLINED;\n }\n u->cacheable = 1;\n switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) {\n case NGX_ERROR:\n return NGX_ERROR;\n case NGX_DECLINED:\n u->cache_status = NGX_HTTP_CACHE_BYPASS;\n return NGX_DECLINED;\n default:\n break;\n }\n c = r->cache;\n c->min_uses = u->conf->cache_min_uses;\n c->body_start = u->conf->buffer_size;\n c->file_cache = u->conf->cache->data;\n c->lock = u->conf->cache_lock;\n c->lock_timeout = u->conf->cache_lock_timeout;\n c->lock_age = u->conf->cache_lock_age;\n u->cache_status = NGX_HTTP_CACHE_MISS;\n }\n rc = ngx_http_file_cache_open(r);\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http upstream cache: %i", rc);\n switch (rc) {\n case NGX_HTTP_CACHE_UPDATING:\n if (u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) {\n u->cache_status = rc;\n rc = NGX_OK;\n } else {\n rc = NGX_HTTP_CACHE_STALE;\n }\n break;\n case NGX_OK:\n u->cache_status = NGX_HTTP_CACHE_HIT;\n }\n switch (rc) {\n case NGX_OK:\n rc = ngx_http_upstream_cache_send(r, u);\n if (rc != NGX_HTTP_UPSTREAM_INVALID_HEADER) {\n return rc;\n }\n break;\n case NGX_HTTP_CACHE_STALE:\n c->valid_sec = 0;\n u->buffer.start = NULL;\n u->cache_status = NGX_HTTP_CACHE_EXPIRED;\n break;\n case NGX_DECLINED:\n if ((size_t) (u->buffer.end - u->buffer.start) < u->conf->buffer_size) {\n u->buffer.start = NULL;\n } else {\n u->buffer.pos = u->buffer.start + c->header_start;\n u->buffer.last = u->buffer.pos;\n }\n break;\n case NGX_HTTP_CACHE_SCARCE:\n u->cacheable = 0;\n break;\n case NGX_AGAIN:\n return NGX_BUSY;\n case NGX_ERROR:\n return NGX_ERROR;\n default:\n u->cache_status = NGX_HTTP_CACHE_HIT;\n return rc;\n }\n r->cached = 0;\n return NGX_DECLINED;\n}', 'void\nngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)\n{\n ngx_connection_t *c;\n ngx_http_request_t *pr;\n ngx_http_core_loc_conf_t *clcf;\n c = r->connection;\n ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize request: %d, \\"%V?%V\\" a:%d, c:%d",\n rc, &r->uri, &r->args, r == c->data, r->main->count);\n if (rc == NGX_DONE) {\n ngx_http_finalize_connection(r);\n return;\n }\n if (rc == NGX_OK && r->filter_finalize) {\n c->error = 1;\n }\n if (rc == NGX_DECLINED) {\n r->content_handler = NULL;\n r->write_event_handler = ngx_http_core_run_phases;\n ngx_http_core_run_phases(r);\n return;\n }\n if (r != r->main && r->post_subrequest) {\n rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);\n }\n if (rc == NGX_ERROR\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n || c->error)\n {\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (r->main->blocked) {\n r->write_event_handler = ngx_http_request_finalizer;\n }\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE\n || rc == NGX_HTTP_CREATED\n || rc == NGX_HTTP_NO_CONTENT)\n {\n if (rc == NGX_HTTP_CLOSE) {\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (r == r->main) {\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n ngx_del_timer(c->write);\n }\n }\n c->read->handler = ngx_http_request_handler;\n c->write->handler = ngx_http_request_handler;\n ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));\n return;\n }\n if (r != r->main) {\n if (r->buffered || r->postponed) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n pr = r->parent;\n if (r == c->data) {\n r->main->count--;\n r->main->subrequests++;\n if (!r->logged) {\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->log_subrequest) {\n ngx_http_log_request(r);\n }\n r->logged = 1;\n } else {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "subrequest: \\"%V?%V\\" logged again",\n &r->uri, &r->args);\n }\n r->done = 1;\n if (pr->postponed && pr->postponed->request == r) {\n pr->postponed = pr->postponed->next;\n }\n c->data = pr;\n } else {\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n r->write_event_handler = ngx_http_request_finalizer;\n if (r->waited) {\n r->done = 1;\n }\n }\n if (ngx_http_post_request(pr, NULL) != NGX_OK) {\n r->main->count++;\n ngx_http_terminate_request(r, 0);\n return;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http wake parent request: \\"%V?%V\\"",\n &pr->uri, &pr->args);\n return;\n }\n if (r->buffered || c->buffered || r->postponed || r->blocked) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n if (r != c->data) {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n return;\n }\n r->done = 1;\n r->write_event_handler = ngx_http_request_empty_handler;\n if (!r->post_action) {\n r->request_complete = 1;\n }\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n c->write->delayed = 0;\n ngx_del_timer(c->write);\n }\n if (c->read->eof) {\n ngx_http_close_request(r, 0);\n return;\n }\n ngx_http_finalize_connection(r);\n}', 'ngx_int_t\nngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)\n{\n ngx_uint_t i, err;\n ngx_http_err_page_t *err_page;\n ngx_http_core_loc_conf_t *clcf;\n ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http special response: %i, \\"%V?%V\\"",\n error, &r->uri, &r->args);\n r->err_status = error;\n if (r->keepalive) {\n switch (error) {\n case NGX_HTTP_BAD_REQUEST:\n case NGX_HTTP_REQUEST_ENTITY_TOO_LARGE:\n case NGX_HTTP_REQUEST_URI_TOO_LARGE:\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n case NGX_HTTP_INTERNAL_SERVER_ERROR:\n case NGX_HTTP_NOT_IMPLEMENTED:\n r->keepalive = 0;\n }\n }\n if (r->lingering_close) {\n switch (error) {\n case NGX_HTTP_BAD_REQUEST:\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n r->lingering_close = 0;\n }\n }\n r->headers_out.content_type.len = 0;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (!r->error_page && clcf->error_pages && r->uri_changes != 0) {\n if (clcf->recursive_error_pages == 0) {\n r->error_page = 1;\n }\n err_page = clcf->error_pages->elts;\n for (i = 0; i < clcf->error_pages->nelts; i++) {\n if (err_page[i].status == error) {\n return ngx_http_send_error_page(r, &err_page[i]);\n }\n }\n }\n r->expect_tested = 1;\n if (ngx_http_discard_request_body(r) != NGX_OK) {\n r->keepalive = 0;\n }\n if (clcf->msie_refresh\n && r->headers_in.msie\n && (error == NGX_HTTP_MOVED_PERMANENTLY\n || error == NGX_HTTP_MOVED_TEMPORARILY))\n {\n return ngx_http_send_refresh(r);\n }\n if (error == NGX_HTTP_CREATED) {\n err = 0;\n } else if (error == NGX_HTTP_NO_CONTENT) {\n err = 0;\n } else if (error >= NGX_HTTP_MOVED_PERMANENTLY\n && error < NGX_HTTP_LAST_3XX)\n {\n err = error - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_OFF_3XX;\n } else if (error >= NGX_HTTP_BAD_REQUEST\n && error < NGX_HTTP_LAST_4XX)\n {\n err = error - NGX_HTTP_BAD_REQUEST + NGX_HTTP_OFF_4XX;\n } else if (error >= NGX_HTTP_NGINX_CODES\n && error < NGX_HTTP_LAST_5XX)\n {\n err = error - NGX_HTTP_NGINX_CODES + NGX_HTTP_OFF_5XX;\n switch (error) {\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n case NGX_HTTP_REQUEST_HEADER_TOO_LARGE:\n r->err_status = NGX_HTTP_BAD_REQUEST;\n break;\n }\n } else {\n err = 0;\n }\n return ngx_http_send_special_response(r, clcf, err);\n}', 'static ngx_int_t\nngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)\n{\n ngx_int_t overwrite;\n ngx_str_t uri, args;\n ngx_table_elt_t *location;\n ngx_http_core_loc_conf_t *clcf;\n overwrite = err_page->overwrite;\n if (overwrite && overwrite != NGX_HTTP_OK) {\n r->expect_tested = 1;\n }\n if (overwrite >= 0) {\n r->err_status = overwrite;\n }\n if (ngx_http_complex_value(r, &err_page->value, &uri) != NGX_OK) {\n return NGX_ERROR;\n }\n if (uri.data[0] == \'/\') {\n if (err_page->value.lengths) {\n ngx_http_split_args(r, &uri, &args);\n } else {\n args = err_page->args;\n }\n if (r->method != NGX_HTTP_HEAD) {\n r->method = NGX_HTTP_GET;\n r->method_name = ngx_http_get_name;\n }\n return ngx_http_internal_redirect(r, &uri, &args);\n }\n if (uri.data[0] == \'@\') {\n return ngx_http_named_location(r, &uri);\n }\n location = ngx_list_push(&r->headers_out.headers);\n if (location == NULL) {\n return NGX_ERROR;\n }\n if (overwrite != NGX_HTTP_MOVED_PERMANENTLY\n && overwrite != NGX_HTTP_MOVED_TEMPORARILY\n && overwrite != NGX_HTTP_SEE_OTHER\n && overwrite != NGX_HTTP_TEMPORARY_REDIRECT)\n {\n r->err_status = NGX_HTTP_MOVED_TEMPORARILY;\n }\n location->hash = 1;\n ngx_str_set(&location->key, "Location");\n location->value = uri;\n ngx_http_clear_location(r);\n r->headers_out.location = location;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->msie_refresh && r->headers_in.msie) {\n return ngx_http_send_refresh(r);\n }\n return ngx_http_send_special_response(r, clcf, r->err_status\n - NGX_HTTP_MOVED_PERMANENTLY\n + NGX_HTTP_OFF_3XX);\n}', 'ngx_int_t\nngx_http_internal_redirect(ngx_http_request_t *r,\n ngx_str_t *uri, ngx_str_t *args)\n{\n ngx_http_core_srv_conf_t *cscf;\n r->uri_changes--;\n if (r->uri_changes == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "rewrite or internal redirection cycle "\n "while internally redirecting to \\"%V\\"", uri);\n r->main->count++;\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n r->uri = *uri;\n if (args) {\n r->args = *args;\n } else {\n ngx_str_null(&r->args);\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "internal redirect: \\"%V?%V\\"", uri, &r->args);\n ngx_http_set_exten(r);\n ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);\n cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n r->loc_conf = cscf->ctx->loc_conf;\n ngx_http_update_location_config(r);\n#if (NGX_HTTP_CACHE)\n r->cache = NULL;\n#endif\n r->internal = 1;\n r->valid_unparsed_uri = 0;\n r->add_uri_to_alias = 0;\n r->main->count++;\n ngx_http_handler(r);\n return NGX_DONE;\n}', "void\nngx_http_set_exten(ngx_http_request_t *r)\n{\n ngx_int_t i;\n ngx_str_null(&r->exten);\n for (i = r->uri.len - 1; i > 1; i--) {\n if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {\n r->exten.len = r->uri.len - i - 1;\n r->exten.data = &r->uri.data[i + 1];\n return;\n } else if (r->uri.data[i] == '/') {\n return;\n }\n }\n return;\n}"]
|
2,758
| 0
|
https://github.com/libav/libav/blob/1e4dd198aff2f1071b88aba6ae873745e9c18a81/libavcodec/motion_est.c/#L170
|
static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
const int size, const int h, int ref_index, int src_index,
me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){
MotionEstContext * const c= &s->me;
const int stride= c->stride;
const int hx= subx + (x<<(1+qpel));
const int hy= suby + (y<<(1+qpel));
uint8_t * const * const ref= c->ref[ref_index];
uint8_t * const * const src= c->src[src_index];
int d;
assert(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));
if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){
const int time_pp= s->pp_time;
const int time_pb= s->pb_time;
const int mask= 2*qpel+1;
if(s->mv_type==MV_TYPE_8X8){
int i;
for(i=0; i<4; i++){
int fx = c->direct_basis_mv[i][0] + hx;
int fy = c->direct_basis_mv[i][1] + hy;
int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));
int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));
int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);
if(qpel){
c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);
c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);
}else{
c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);
c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);
}
}
}else{
int fx = c->direct_basis_mv[0][0] + hx;
int fy = c->direct_basis_mv[0][1] + hy;
int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);
int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);
int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
if(qpel){
c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride);
c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride);
c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride);
c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);
c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride);
c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride);
c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride);
c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);
}else{
assert((fx>>1) + 16*s->mb_x >= -16);
assert((fy>>1) + 16*s->mb_y >= -16);
assert((fx>>1) + 16*s->mb_x <= s->width);
assert((fy>>1) + 16*s->mb_y <= s->height);
assert((bx>>1) + 16*s->mb_x >= -16);
assert((by>>1) + 16*s->mb_y >= -16);
assert((bx>>1) + 16*s->mb_x <= s->width);
assert((by>>1) + 16*s->mb_y <= s->height);
c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);
c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);
}
}
d = cmp_func(s, c->temp, src[0], stride, 16);
}else
d= 256*256*256*32;
return d;
}
|
['void ff_estimate_b_frame_motion(MpegEncContext * s,\n int mb_x, int mb_y)\n{\n MotionEstContext * const c= &s->me;\n const int penalty_factor= c->mb_penalty_factor;\n int fmin, bmin, dmin, fbmin, bimin, fimin;\n int type=0;\n const int xy = mb_y*s->mb_stride + mb_x;\n init_ref(c, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2);\n get_limits(s, 16*mb_x, 16*mb_y);\n c->skip=0;\n if(s->codec_id == CODEC_ID_MPEG4 && s->next_picture.mbskip_table[xy]){\n int score= direct_search(s, mb_x, mb_y);\n score= ((unsigned)(score*score + 128*256))>>16;\n c->mc_mb_var_sum_temp += score;\n s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score;\n s->mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_DIRECT0;\n return;\n }\n if(c->avctx->me_threshold){\n int vard= check_input_motion(s, mb_x, mb_y, 0);\n if((vard+128)>>8 < c->avctx->me_threshold){\n s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8;\n c->mc_mb_var_sum_temp += (vard+128)>>8;\n return;\n }\n if((vard+128)>>8 < c->avctx->mb_threshold){\n type= s->mb_type[mb_y*s->mb_stride + mb_x];\n if(type == CANDIDATE_MB_TYPE_DIRECT){\n direct_search(s, mb_x, mb_y);\n }\n if(type == CANDIDATE_MB_TYPE_FORWARD || type == CANDIDATE_MB_TYPE_BIDIR){\n c->skip=0;\n ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code);\n }\n if(type == CANDIDATE_MB_TYPE_BACKWARD || type == CANDIDATE_MB_TYPE_BIDIR){\n c->skip=0;\n ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code);\n }\n if(type == CANDIDATE_MB_TYPE_FORWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){\n c->skip=0;\n c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;\n interlaced_search(s, 0,\n s->b_field_mv_table[0], s->b_field_select_table[0],\n s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 1);\n }\n if(type == CANDIDATE_MB_TYPE_BACKWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){\n c->skip=0;\n c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV;\n interlaced_search(s, 2,\n s->b_field_mv_table[1], s->b_field_select_table[1],\n s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 1);\n }\n return;\n }\n }\n if (s->codec_id == CODEC_ID_MPEG4)\n dmin= direct_search(s, mb_x, mb_y);\n else\n dmin= INT_MAX;\n c->skip=0;\n fmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) + 3*penalty_factor;\n c->skip=0;\n bmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) + 2*penalty_factor;\n c->skip=0;\n fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor;\n if(s->flags & CODEC_FLAG_INTERLACED_ME){\n c->skip=0;\n c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;\n fimin= interlaced_search(s, 0,\n s->b_field_mv_table[0], s->b_field_select_table[0],\n s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 0);\n c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV;\n bimin= interlaced_search(s, 2,\n s->b_field_mv_table[1], s->b_field_select_table[1],\n s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 0);\n }else\n fimin= bimin= INT_MAX;\n {\n int score= fmin;\n type = CANDIDATE_MB_TYPE_FORWARD;\n if (dmin <= score){\n score = dmin;\n type = CANDIDATE_MB_TYPE_DIRECT;\n }\n if(bmin<score){\n score=bmin;\n type= CANDIDATE_MB_TYPE_BACKWARD;\n }\n if(fbmin<score){\n score=fbmin;\n type= CANDIDATE_MB_TYPE_BIDIR;\n }\n if(fimin<score){\n score=fimin;\n type= CANDIDATE_MB_TYPE_FORWARD_I;\n }\n if(bimin<score){\n score=bimin;\n type= CANDIDATE_MB_TYPE_BACKWARD_I;\n }\n score= ((unsigned)(score*score + 128*256))>>16;\n c->mc_mb_var_sum_temp += score;\n s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score;\n }\n if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){\n type= CANDIDATE_MB_TYPE_FORWARD | CANDIDATE_MB_TYPE_BACKWARD | CANDIDATE_MB_TYPE_BIDIR | CANDIDATE_MB_TYPE_DIRECT;\n if(fimin < INT_MAX)\n type |= CANDIDATE_MB_TYPE_FORWARD_I;\n if(bimin < INT_MAX)\n type |= CANDIDATE_MB_TYPE_BACKWARD_I;\n if(fimin < INT_MAX && bimin < INT_MAX){\n type |= CANDIDATE_MB_TYPE_BIDIR_I;\n }\n if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT;\n if(s->codec_id == CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT && s->flags&CODEC_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy])\n type |= CANDIDATE_MB_TYPE_DIRECT0;\n#if 0\n if(s->out_format == FMT_MPEG1)\n type |= CANDIDATE_MB_TYPE_INTRA;\n#endif\n }\n s->mb_type[mb_y*s->mb_stride + mb_x]= type;\n}', 'static int interlaced_search(MpegEncContext *s, int ref_index,\n int16_t (*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my, int user_field_select)\n{\n MotionEstContext * const c= &s->me;\n const int size=0;\n const int h=8;\n int block;\n int P[10][2];\n uint8_t * const mv_penalty= c->current_mv_penalty;\n int same=1;\n const int stride= 2*s->linesize;\n int dmin_sum= 0;\n const int mot_stride= s->mb_stride;\n const int xy= s->mb_x + s->mb_y*mot_stride;\n c->ymin>>=1;\n c->ymax>>=1;\n c->stride<<=1;\n c->uvstride<<=1;\n init_interlaced_ref(s, ref_index);\n for(block=0; block<2; block++){\n int field_select;\n int best_dmin= INT_MAX;\n int best_field= -1;\n for(field_select=0; field_select<2; field_select++){\n int dmin, mx_i, my_i;\n int16_t (*mv_table)[2]= mv_tables[block][field_select];\n if(user_field_select){\n assert(field_select==0 || field_select==1);\n assert(field_select_tables[block][xy]==0 || field_select_tables[block][xy]==1);\n if(field_select_tables[block][xy] != field_select)\n continue;\n }\n P_LEFT[0] = mv_table[xy - 1][0];\n P_LEFT[1] = mv_table[xy - 1][1];\n if(P_LEFT[0] > (c->xmax<<1)) P_LEFT[0] = (c->xmax<<1);\n c->pred_x= P_LEFT[0];\n c->pred_y= P_LEFT[1];\n if(!s->first_slice_line){\n P_TOP[0] = mv_table[xy - mot_stride][0];\n P_TOP[1] = mv_table[xy - mot_stride][1];\n P_TOPRIGHT[0] = mv_table[xy - mot_stride + 1][0];\n P_TOPRIGHT[1] = mv_table[xy - mot_stride + 1][1];\n if(P_TOP[1] > (c->ymax<<1)) P_TOP[1] = (c->ymax<<1);\n if(P_TOPRIGHT[0] < (c->xmin<<1)) P_TOPRIGHT[0]= (c->xmin<<1);\n if(P_TOPRIGHT[0] > (c->xmax<<1)) P_TOPRIGHT[0]= (c->xmax<<1);\n if(P_TOPRIGHT[1] > (c->ymax<<1)) P_TOPRIGHT[1]= (c->ymax<<1);\n P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);\n P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);\n }\n P_MV1[0]= mx;\n P_MV1[1]= my / 2;\n dmin = epzs_motion_search2(s, &mx_i, &my_i, P, block, field_select+ref_index, mv_table, (1<<16)>>1);\n dmin= c->sub_motion_search(s, &mx_i, &my_i, dmin, block, field_select+ref_index, size, h);\n mv_table[xy][0]= mx_i;\n mv_table[xy][1]= my_i;\n if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){\n int dxy;\n uint8_t *ref= c->ref[field_select+ref_index][0] + (mx_i>>1) + (my_i>>1)*stride;\n dxy = ((my_i & 1) << 1) | (mx_i & 1);\n if(s->no_rounding){\n s->dsp.put_no_rnd_pixels_tab[size][dxy](c->scratchpad, ref , stride, h);\n }else{\n s->dsp.put_pixels_tab [size][dxy](c->scratchpad, ref , stride, h);\n }\n dmin= s->dsp.mb_cmp[size](s, c->src[block][0], c->scratchpad, stride, h);\n dmin+= (mv_penalty[mx_i-c->pred_x] + mv_penalty[my_i-c->pred_y] + 1)*c->mb_penalty_factor;\n }else\n dmin+= c->mb_penalty_factor;\n dmin += field_select != block;\n if(dmin < best_dmin){\n best_dmin= dmin;\n best_field= field_select;\n }\n }\n {\n int16_t (*mv_table)[2]= mv_tables[block][best_field];\n if(mv_table[xy][0] != mx) same=0;\n if(mv_table[xy][1]&1) same=0;\n if(mv_table[xy][1]*2 != my) same=0;\n if(best_field != block) same=0;\n }\n field_select_tables[block][xy]= best_field;\n dmin_sum += best_dmin;\n }\n c->ymin<<=1;\n c->ymax<<=1;\n c->stride>>=1;\n c->uvstride>>=1;\n if(same)\n return INT_MAX;\n switch(c->avctx->mb_cmp&0xFF){\n case FF_CMP_RD:\n return dmin_sum;\n default:\n return dmin_sum+ 11*c->mb_penalty_factor;\n }\n}', 'static int epzs_motion_search2(MpegEncContext * s,\n int *mx_ptr, int *my_ptr, int P[10][2],\n int src_index, int ref_index, int16_t (*last_mv)[2],\n int ref_mv_scale)\n{\n MotionEstContext * const c= &s->me;\n int best[2]={0, 0};\n int d, dmin;\n int map_generation;\n const int penalty_factor= c->penalty_factor;\n const int size=0;\n const int h=8;\n const int ref_mv_stride= s->mb_stride;\n const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;\n me_cmp_func cmpf, chroma_cmpf;\n LOAD_COMMON\n int flags= c->flags;\n LOAD_COMMON2\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n map_generation= update_map_generation(c);\n dmin = 1000000;\n if (s->first_slice_line) {\n CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)\n CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)\n }else{\n CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)\n CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)\n CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)\n CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)\n CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)\n }\n if(dmin>64*4){\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)\n if(s->mb_y+1<s->end_mb_y)\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)\n }\n dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n *mx_ptr= best[0];\n *my_ptr= best[1];\n return dmin;\n}', 'static av_always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,\n int src_index, int ref_index, int const penalty_factor,\n int size, int h, int flags){\n MotionEstContext * const c= &s->me;\n if(c->dia_size==-1)\n return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size<-1)\n return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size<2)\n return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size>1024)\n return full_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size>768)\n return umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size>512)\n return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, c->dia_size&0xFF);\n else if(c->dia_size>256)\n return l2s_dia_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else\n return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n}', 'static int umh_search(MpegEncContext * s, int *best, int dmin,\n int src_index, int ref_index, int const penalty_factor,\n int size, int h, int flags)\n{\n MotionEstContext * const c= &s->me;\n me_cmp_func cmpf, chroma_cmpf;\n LOAD_COMMON\n LOAD_COMMON2\n int map_generation= c->map_generation;\n int x,y,x2,y2, i, j, d;\n const int dia_size= c->dia_size&0xFE;\n static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},\n { 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2},\n {-2, 3}, { 0, 4}, { 2, 3},\n {-2,-3}, { 0,-4}, { 2,-3},};\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n x= best[0];\n y= best[1];\n for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){\n CHECK_MV(x2, y);\n }\n for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){\n CHECK_MV(x, y2);\n }\n x= best[0];\n y= best[1];\n for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){\n for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){\n CHECK_MV(x2, y2);\n }\n }\n for(j=1; j<=dia_size/4; j++){\n for(i=0; i<16; i++){\n CHECK_CLIPPED_MV(x+hex[i][0]*j, y+hex[i][1]*j);\n }\n }\n return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, 2);\n}', 'static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby,\n const int size, const int h, int ref_index, int src_index,\n me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){\n if(av_builtin_constant_p(flags) && av_builtin_constant_p(h) && av_builtin_constant_p(size)\n && av_builtin_constant_p(subx) && av_builtin_constant_p(suby)\n && flags==0 && h==16 && size==0 && subx==0 && suby==0){\n return cmp_simple(s,x,y,ref_index,src_index, cmp_func, chroma_cmp_func);\n }else if(av_builtin_constant_p(subx) && av_builtin_constant_p(suby)\n && subx==0 && suby==0){\n return cmp_fpel_internal(s,x,y,size,h,ref_index,src_index, cmp_func, chroma_cmp_func,flags);\n }else{\n return cmp_internal(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags);\n }\n}', 'static int cmp_fpel_internal(MpegEncContext *s, const int x, const int y,\n const int size, const int h, int ref_index, int src_index,\n me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){\n if(flags&FLAG_DIRECT){\n return cmp_direct_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL);\n }else{\n return cmp_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&FLAG_CHROMA);\n }\n}', 'static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby,\n const int size, const int h, int ref_index, int src_index,\n me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){\n MotionEstContext * const c= &s->me;\n const int stride= c->stride;\n const int hx= subx + (x<<(1+qpel));\n const int hy= suby + (y<<(1+qpel));\n uint8_t * const * const ref= c->ref[ref_index];\n uint8_t * const * const src= c->src[src_index];\n int d;\n assert(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));\n if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){\n const int time_pp= s->pp_time;\n const int time_pb= s->pb_time;\n const int mask= 2*qpel+1;\n if(s->mv_type==MV_TYPE_8X8){\n int i;\n for(i=0; i<4; i++){\n int fx = c->direct_basis_mv[i][0] + hx;\n int fy = c->direct_basis_mv[i][1] + hy;\n int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));\n int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));\n int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));\n int bxy= (bx&mask) + ((by&mask)<<(qpel+1));\n uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);\n if(qpel){\n c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);\n c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);\n }else{\n c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);\n c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);\n }\n }\n }else{\n int fx = c->direct_basis_mv[0][0] + hx;\n int fy = c->direct_basis_mv[0][1] + hy;\n int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);\n int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);\n int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));\n int bxy= (bx&mask) + ((by&mask)<<(qpel+1));\n if(qpel){\n c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride);\n c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride);\n c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride);\n c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);\n c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride);\n c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride);\n c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride);\n c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);\n }else{\n assert((fx>>1) + 16*s->mb_x >= -16);\n assert((fy>>1) + 16*s->mb_y >= -16);\n assert((fx>>1) + 16*s->mb_x <= s->width);\n assert((fy>>1) + 16*s->mb_y <= s->height);\n assert((bx>>1) + 16*s->mb_x >= -16);\n assert((by>>1) + 16*s->mb_y >= -16);\n assert((bx>>1) + 16*s->mb_x <= s->width);\n assert((by>>1) + 16*s->mb_y <= s->height);\n c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);\n c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);\n }\n }\n d = cmp_func(s, c->temp, src[0], stride, 16);\n }else\n d= 256*256*256*32;\n return d;\n}']
|
2,759
| 0
|
https://github.com/openssl/openssl/blob/e3713c365c2657236439fea00822a43aa396d112/crypto/objects/o_names.c/#L236
|
int OBJ_NAME_add(const char *name, int type, const char *data)
{
OBJ_NAME *onp, *ret;
int alias, ok = 0;
if (!OBJ_NAME_init())
return 0;
CRYPTO_THREAD_write_lock(obj_lock);
alias = type & OBJ_NAME_ALIAS;
type &= ~OBJ_NAME_ALIAS;
onp = OPENSSL_malloc(sizeof(*onp));
if (onp == NULL) {
goto unlock;
}
onp->name = name;
onp->alias = alias;
onp->type = type;
onp->data = data;
ret = lh_OBJ_NAME_insert(names_lh, onp);
if (ret != NULL) {
if ((name_funcs_stack != NULL)
&& (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type)) {
sk_NAME_FUNCS_value(name_funcs_stack,
ret->type)->free_func(ret->name, ret->type,
ret->data);
}
OPENSSL_free(ret);
} else {
if (lh_OBJ_NAME_error(names_lh)) {
OPENSSL_free(onp);
goto unlock;
}
}
ok = 1;
unlock:
CRYPTO_THREAD_unlock(obj_lock);
return ok;
}
|
['int OBJ_NAME_add(const char *name, int type, const char *data)\n{\n OBJ_NAME *onp, *ret;\n int alias, ok = 0;\n if (!OBJ_NAME_init())\n return 0;\n CRYPTO_THREAD_write_lock(obj_lock);\n alias = type & OBJ_NAME_ALIAS;\n type &= ~OBJ_NAME_ALIAS;\n onp = OPENSSL_malloc(sizeof(*onp));\n if (onp == NULL) {\n goto unlock;\n }\n onp->name = name;\n onp->alias = alias;\n onp->type = type;\n onp->data = data;\n ret = lh_OBJ_NAME_insert(names_lh, onp);\n if (ret != NULL) {\n if ((name_funcs_stack != NULL)\n && (sk_NAME_FUNCS_num(name_funcs_stack) > ret->type)) {\n sk_NAME_FUNCS_value(name_funcs_stack,\n ret->type)->free_func(ret->name, ret->type,\n ret->data);\n }\n OPENSSL_free(ret);\n } else {\n if (lh_OBJ_NAME_error(names_lh)) {\n OPENSSL_free(onp);\n goto unlock;\n }\n }\n ok = 1;\nunlock:\n CRYPTO_THREAD_unlock(obj_lock);\n return ok;\n}', 'int OBJ_NAME_init(void)\n{\n return RUN_ONCE(&init, o_names_init);\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n if (pthread_rwlock_wrlock(lock) != 0)\n return 0;\n# else\n if (pthread_mutex_lock(lock) != 0)\n return 0;\n# endif\n return 1;\n}', '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}', 'void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data)\n{\n unsigned long hash;\n OPENSSL_LH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n if ((lh->up_load <= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)) && !expand(lh))\n return NULL;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n if ((nn = OPENSSL_malloc(sizeof(*nn))) == NULL) {\n lh->error++;\n return NULL;\n }\n nn->data = data;\n nn->next = NULL;\n nn->hash = hash;\n *rn = nn;\n ret = NULL;\n lh->num_insert++;\n lh->num_items++;\n } else {\n ret = (*rn)->data;\n (*rn)->data = data;\n lh->num_replace++;\n }\n return ret;\n}']
|
2,760
| 0
|
https://gitlab.com/libtiff/libtiff/blob/6dac309a9701d15ac52d895d566ddae2ed49db9b/libtiff/tif_swab.c/#L130
|
void
TIFFSwabArrayOfLong8(register uint64* lp, tmsize_t n)
{
register unsigned char *cp;
register unsigned char t;
assert(sizeof(uint64)==8);
while (n-- > 0) {
cp = (unsigned char *)lp;
t = cp[7]; cp[7] = cp[0]; cp[0] = t;
t = cp[6]; cp[6] = cp[1]; cp[1] = t;
t = cp[5]; cp[5] = cp[2]; cp[2] = t;
t = cp[4]; cp[4] = cp[3]; cp[3] = t;
lp++;
}
}
|
['static void TIFFWriteOvrRow( TIFFOvrCache * psCache )\n{\n int\t\tnRet, iTileX, iTileY = psCache->nBlockOffset;\n unsigned char *pabyData;\n toff_t\tnBaseDirOffset;\n uint32 RowsInStrip;\n if( TIFFIsByteSwapped(psCache->hTIFF) )\n {\n if( psCache->nBitsPerPixel == 16 )\n TIFFSwabArrayOfShort( (uint16 *) psCache->pabyRow1Blocks,\n (psCache->nBytesPerBlock * psCache->nSamples) / 2 );\n else if( psCache->nBitsPerPixel == 32 )\n TIFFSwabArrayOfLong( (uint32 *) psCache->pabyRow1Blocks,\n (psCache->nBytesPerBlock * psCache->nSamples) / 4 );\n else if( psCache->nBitsPerPixel == 64 )\n TIFFSwabArrayOfDouble( (double *) psCache->pabyRow1Blocks,\n (psCache->nBytesPerBlock * psCache->nSamples) / 8 );\n }\n nBaseDirOffset = TIFFCurrentDirOffset( psCache->hTIFF );\n nRet = TIFFSetSubDirectory( psCache->hTIFF, psCache->nDirOffset );\n assert( nRet == 1 );\n\tfor( iTileX = 0; iTileX < psCache->nBlocksPerRow; iTileX++ )\n\t{\n\t\tint nTileID;\n\t\tif (psCache->nPlanarConfig == PLANARCONFIG_SEPARATE)\n\t\t{\n\t\t\tint iSample;\n\t\t\tfor( iSample = 0; iSample < psCache->nSamples; iSample++ )\n\t\t\t{\n\t\t\t\tpabyData = TIFFGetOvrBlock( psCache, iTileX, iTileY, iSample );\n\t\t\t\tif( psCache->bTiled )\n\t\t\t\t{\n\t\t\t\t\tnTileID = TIFFComputeTile( psCache->hTIFF,\n\t\t\t\t\t iTileX * psCache->nBlockXSize,\n\t\t\t\t\t iTileY * psCache->nBlockYSize,\n\t\t\t\t\t 0, (tsample_t) iSample );\n\t\t\t\t\tTIFFWriteEncodedTile( psCache->hTIFF, nTileID,\n\t\t\t\t\t pabyData,\n\t\t\t\t\t TIFFTileSize(psCache->hTIFF) );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tnTileID = TIFFComputeStrip( psCache->hTIFF,\n\t\t\t\t\t iTileY * psCache->nBlockYSize,\n\t\t\t\t\t (tsample_t) iSample );\n\t\t\t\t\tRowsInStrip=psCache->nBlockYSize;\n\t\t\t\t\tif ((iTileY+1)*psCache->nBlockYSize>psCache->nYSize)\n\t\t\t\t\t\tRowsInStrip=psCache->nYSize-iTileY*psCache->nBlockYSize;\n\t\t\t\t\tTIFFWriteEncodedStrip( psCache->hTIFF, nTileID,\n\t\t\t\t\t pabyData,\n\t\t\t\t\t TIFFVStripSize(psCache->hTIFF,RowsInStrip) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tpabyData = TIFFGetOvrBlock( psCache, iTileX, iTileY, 0 );\n\t\t\tif( psCache->bTiled )\n\t\t\t{\n\t\t\t\tnTileID = TIFFComputeTile( psCache->hTIFF,\n\t\t\t\t iTileX * psCache->nBlockXSize,\n\t\t\t\t iTileY * psCache->nBlockYSize,\n\t\t\t\t 0, 0 );\n\t\t\t\tTIFFWriteEncodedTile( psCache->hTIFF, nTileID,\n\t\t\t\t pabyData,\n\t\t\t\t TIFFTileSize(psCache->hTIFF) );\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tnTileID = TIFFComputeStrip( psCache->hTIFF,\n\t\t\t\t iTileY * psCache->nBlockYSize,\n\t\t\t\t 0 );\n\t\t\t\tRowsInStrip=psCache->nBlockYSize;\n\t\t\t\tif ((iTileY+1)*psCache->nBlockYSize>psCache->nYSize)\n\t\t\t\t\tRowsInStrip=psCache->nYSize-iTileY*psCache->nBlockYSize;\n\t\t\t\tTIFFWriteEncodedStrip( psCache->hTIFF, nTileID,\n\t\t\t\t pabyData,\n\t\t\t\t TIFFVStripSize(psCache->hTIFF,RowsInStrip) );\n\t\t\t}\n\t\t}\n\t}\n pabyData = psCache->pabyRow1Blocks;\n psCache->pabyRow1Blocks = psCache->pabyRow2Blocks;\n psCache->pabyRow2Blocks = pabyData;\n _TIFFmemset( pabyData, 0, psCache->nBytesPerRow );\n psCache->nBlockOffset++;\n TIFFFlush( psCache->hTIFF );\n TIFFSetSubDirectory( psCache->hTIFF, nBaseDirOffset );\n}', 'tmsize_t\nTIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)\n{\n\tstatic const char module[] = "TIFFWriteEncodedStrip";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint16 sample;\n\tif (!WRITECHECKSTRIPS(tif, module))\n\t\treturn ((tmsize_t) -1);\n\tif (strip >= td->td_nstrips) {\n\t\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Can not grow image by strips when using separate planes");\n\t\t\treturn ((tmsize_t) -1);\n\t\t}\n\t\tif (!TIFFGrowStrips(tif, 1, module))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttd->td_stripsperimage =\n\t\t TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip);\n\t}\n\tif (!BUFFERCHECK(tif))\n\t\treturn ((tmsize_t) -1);\n tif->tif_flags |= TIFF_BUF4WRITE;\n\ttif->tif_curstrip = strip;\n if (td->td_stripsperimage == 0) {\n TIFFErrorExt(tif->tif_clientdata, module, "Zero strips per image");\n return ((tmsize_t) -1);\n }\n\ttif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupencode)(tif))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\tif( td->td_stripbytecount[strip] > 0 )\n {\n if( tif->tif_rawdatasize <= (tmsize_t)td->td_stripbytecount[strip] )\n {\n if( !(TIFFWriteBufferSetup(tif, NULL,\n (tmsize_t)TIFFroundup_64((uint64)(td->td_stripbytecount[strip] + 1), 1024))) )\n return ((tmsize_t)(-1));\n }\n tif->tif_curoff = 0;\n }\n tif->tif_rawcc = 0;\n tif->tif_rawcp = tif->tif_rawdata;\n\ttif->tif_flags &= ~TIFF_POSTENCODE;\n if( td->td_compression == COMPRESSION_NONE )\n {\n tif->tif_postdecode( tif, (uint8*) data, cc );\n if (!isFillOrder(tif, td->td_fillorder) &&\n (tif->tif_flags & TIFF_NOBITREV) == 0)\n TIFFReverseBits((uint8*) data, cc);\n if (cc > 0 &&\n !TIFFAppendToStrip(tif, strip, (uint8*) data, cc))\n return ((tmsize_t) -1);\n return (cc);\n }\n\tsample = (uint16)(strip / td->td_stripsperimage);\n\tif (!(*tif->tif_preencode)(tif, sample))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_postdecode( tif, (uint8*) data, cc );\n\tif (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample))\n\t\treturn ((tmsize_t) -1);\n\tif (!(*tif->tif_postencode)(tif))\n\t\treturn ((tmsize_t) -1);\n\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\tTIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);\n\tif (tif->tif_rawcc > 0 &&\n\t !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_rawcc = 0;\n\ttif->tif_rawcp = tif->tif_rawdata;\n\treturn (cc);\n}', 'int\nTIFFFlush(TIFF* tif)\n{\n if( tif->tif_mode == O_RDONLY )\n return 1;\n if (!TIFFFlushData(tif))\n return (0);\n if( (tif->tif_flags & TIFF_DIRTYSTRIP)\n && !(tif->tif_flags & TIFF_DIRTYDIRECT)\n && tif->tif_mode == O_RDWR )\n {\n uint64 *offsets=NULL, *sizes=NULL;\n if( TIFFIsTiled(tif) )\n {\n if( TIFFGetField( tif, TIFFTAG_TILEOFFSETS, &offsets )\n && TIFFGetField( tif, TIFFTAG_TILEBYTECOUNTS, &sizes )\n && _TIFFRewriteField( tif, TIFFTAG_TILEOFFSETS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, offsets )\n && _TIFFRewriteField( tif, TIFFTAG_TILEBYTECOUNTS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, sizes ) )\n {\n tif->tif_flags &= ~TIFF_DIRTYSTRIP;\n tif->tif_flags &= ~TIFF_BEENWRITING;\n return 1;\n }\n }\n else\n {\n if( TIFFGetField( tif, TIFFTAG_STRIPOFFSETS, &offsets )\n && TIFFGetField( tif, TIFFTAG_STRIPBYTECOUNTS, &sizes )\n && _TIFFRewriteField( tif, TIFFTAG_STRIPOFFSETS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, offsets )\n && _TIFFRewriteField( tif, TIFFTAG_STRIPBYTECOUNTS, TIFF_LONG8,\n tif->tif_dir.td_nstrips, sizes ) )\n {\n tif->tif_flags &= ~TIFF_DIRTYSTRIP;\n tif->tif_flags &= ~TIFF_BEENWRITING;\n return 1;\n }\n }\n }\n if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP))\n && !TIFFRewriteDirectory(tif))\n return (0);\n return (1);\n}', 'int\nTIFFRewriteDirectory( TIFF *tif )\n{\n\tstatic const char module[] = "TIFFRewriteDirectory";\n\tif( tif->tif_diroff == 0 )\n\t\treturn TIFFWriteDirectory( tif );\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t{\n\t\tif (tif->tif_header.classic.tiff_diroff == tif->tif_diroff)\n\t\t{\n\t\t\ttif->tif_header.classic.tiff_diroff = 0;\n\t\t\ttif->tif_diroff = 0;\n\t\t\tTIFFSeekFile(tif,4,SEEK_SET);\n\t\t\tif (!WriteOK(tif, &(tif->tif_header.classic.tiff_diroff),4))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t\t "Error updating TIFF header");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tuint32 nextdir;\n\t\t\tnextdir = tif->tif_header.classic.tiff_diroff;\n\t\t\twhile(1) {\n\t\t\t\tuint16 dircount;\n\t\t\t\tuint32 nextnextdir;\n\t\t\t\tif (!SeekOK(tif, nextdir) ||\n\t\t\t\t !ReadOK(tif, &dircount, 2)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory count");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabShort(&dircount);\n\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t nextdir+2+dircount*12, SEEK_SET);\n\t\t\t\tif (!ReadOK(tif, &nextnextdir, 4)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory link");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong(&nextnextdir);\n\t\t\t\tif (nextnextdir==tif->tif_diroff)\n\t\t\t\t{\n\t\t\t\t\tuint32 m;\n\t\t\t\t\tm=0;\n\t\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t\t nextdir+2+dircount*12, SEEK_SET);\n\t\t\t\t\tif (!WriteOK(tif, &m, 4)) {\n\t\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t\t "Error writing directory link");\n\t\t\t\t\t\treturn (0);\n\t\t\t\t\t}\n\t\t\t\t\ttif->tif_diroff=0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tnextdir=nextnextdir;\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tif (tif->tif_header.big.tiff_diroff == tif->tif_diroff)\n\t\t{\n\t\t\ttif->tif_header.big.tiff_diroff = 0;\n\t\t\ttif->tif_diroff = 0;\n\t\t\tTIFFSeekFile(tif,8,SEEK_SET);\n\t\t\tif (!WriteOK(tif, &(tif->tif_header.big.tiff_diroff),8))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t\t "Error updating TIFF header");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tuint64 nextdir;\n\t\t\tnextdir = tif->tif_header.big.tiff_diroff;\n\t\t\twhile(1) {\n\t\t\t\tuint64 dircount64;\n\t\t\t\tuint16 dircount;\n\t\t\t\tuint64 nextnextdir;\n\t\t\t\tif (!SeekOK(tif, nextdir) ||\n\t\t\t\t !ReadOK(tif, &dircount64, 8)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory count");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong8(&dircount64);\n\t\t\t\tif (dircount64>0xFFFF)\n\t\t\t\t{\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Sanity check on tag count failed, likely corrupt TIFF");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tdircount=(uint16)dircount64;\n\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t nextdir+8+dircount*20, SEEK_SET);\n\t\t\t\tif (!ReadOK(tif, &nextnextdir, 8)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory link");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong8(&nextnextdir);\n\t\t\t\tif (nextnextdir==tif->tif_diroff)\n\t\t\t\t{\n\t\t\t\t\tuint64 m;\n\t\t\t\t\tm=0;\n\t\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t\t nextdir+8+dircount*20, SEEK_SET);\n\t\t\t\t\tif (!WriteOK(tif, &m, 8)) {\n\t\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t\t "Error writing directory link");\n\t\t\t\t\t\treturn (0);\n\t\t\t\t\t}\n\t\t\t\t\ttif->tif_diroff=0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tnextdir=nextnextdir;\n\t\t\t}\n\t\t}\n\t}\n\treturn TIFFWriteDirectory( tif );\n}', 'int\nTIFFWriteDirectory(TIFF* tif)\n{\n\treturn TIFFWriteDirectorySec(tif,TRUE,TRUE,NULL);\n}', 'static int\nTIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)\n{\n\tstatic const char module[] = "TIFFWriteDirectorySec";\n\tuint32 ndir;\n\tTIFFDirEntry* dir;\n\tuint32 dirsize;\n\tvoid* dirmem;\n\tuint32 m;\n\tif (tif->tif_mode == O_RDONLY)\n\t\treturn (1);\n _TIFFFillStriles( tif );\n\tif (imagedone)\n\t{\n\t\tif (tif->tif_flags & TIFF_POSTENCODE)\n\t\t{\n\t\t\ttif->tif_flags &= ~TIFF_POSTENCODE;\n\t\t\tif (!(*tif->tif_postencode)(tif))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t\t\t "Error post-encoding before directory write");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\t(*tif->tif_close)(tif);\n\t\tif (tif->tif_rawcc > 0\n\t\t && (tif->tif_flags & TIFF_BEENWRITING) != 0 )\n\t\t{\n\t\t if( !TIFFFlushData1(tif) )\n {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Error flushing data before directory write");\n\t\t\treturn (0);\n }\n\t\t}\n\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)\n\t\t{\n\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\ttif->tif_rawdata = NULL;\n\t\t\ttif->tif_rawcc = 0;\n\t\t\ttif->tif_rawdatasize = 0;\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = 0;\n\t\t}\n\t\ttif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP);\n\t}\n\tdir=NULL;\n\tdirmem=NULL;\n\tdirsize=0;\n\twhile (1)\n\t{\n\t\tndir=0;\n\t\tif (isimage)\n\t\t{\n\t\t\tif (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGEWIDTH,tif->tif_dir.td_imagewidth))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGELENGTH,tif->tif_dir.td_imagelength))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILEWIDTH,tif->tif_dir.td_tilewidth))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILELENGTH,tif->tif_dir.td_tilelength))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_RESOLUTION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XRESOLUTION,tif->tif_dir.td_xresolution))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YRESOLUTION,tif->tif_dir.td_yresolution))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_POSITION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XPOSITION,tif->tif_dir.td_xposition))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YPOSITION,tif->tif_dir.td_yposition))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SUBFILETYPE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_SUBFILETYPE,tif->tif_dir.td_subfiletype))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_BITSPERSAMPLE,tif->tif_dir.td_bitspersample))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_COMPRESSION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_COMPRESSION,tif->tif_dir.td_compression))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PHOTOMETRIC))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PHOTOMETRIC,tif->tif_dir.td_photometric))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_THRESHHOLDING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_THRESHHOLDING,tif->tif_dir.td_threshholding))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_FILLORDER))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_FILLORDER,tif->tif_dir.td_fillorder))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_ORIENTATION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_ORIENTATION,tif->tif_dir.td_orientation))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_SAMPLESPERPIXEL,tif->tif_dir.td_samplesperpixel))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_ROWSPERSTRIP,tif->tif_dir.td_rowsperstrip))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MINSAMPLEVALUE,tif->tif_dir.td_minsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MAXSAMPLEVALUE,tif->tif_dir.td_maxsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PLANARCONFIG))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PLANARCONFIG,tif->tif_dir.td_planarconfig))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_RESOLUTIONUNIT,tif->tif_dir.td_resolutionunit))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PAGENUMBER))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_PAGENUMBER,2,&tif->tif_dir.td_pagenumber[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_STRIPBYTECOUNTS))\n\t\t\t{\n\t\t\t\tif (!isTiled(tif))\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_STRIPOFFSETS))\n\t\t\t{\n\t\t\t\tif (!isTiled(tif))\n\t\t\t\t{\n if (tif->tif_dir.td_stripoffset != NULL &&\n !TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset))\n goto bad;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_COLORMAP))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagColormap(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_EXTRASAMPLES))\n\t\t\t{\n\t\t\t\tif (tif->tif_dir.td_extrasamples)\n\t\t\t\t{\n\t\t\t\t\tuint16 na;\n\t\t\t\t\tuint16* nb;\n\t\t\t\t\tTIFFGetFieldDefaulted(tif,TIFFTAG_EXTRASAMPLES,&na,&nb);\n\t\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_EXTRASAMPLES,na,nb))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_SAMPLEFORMAT,tif->tif_dir.td_sampleformat))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMINSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_sminsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMAXSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_smaxsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_IMAGEDEPTH))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_IMAGEDEPTH,tif->tif_dir.td_imagedepth))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TILEDEPTH))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_TILEDEPTH,tif->tif_dir.td_tiledepth))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_HALFTONEHINTS,2,&tif->tif_dir.td_halftonehints[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_YCBCRSUBSAMPLING,2,&tif->tif_dir.td_ycbcrsubsampling[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_YCBCRPOSITIONING,tif->tif_dir.td_ycbcrpositioning))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_REFBLACKWHITE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,TIFFTAG_REFERENCEBLACKWHITE,6,tif->tif_dir.td_refblackwhite))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagTransferfunction(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_INKNAMES))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,TIFFTAG_INKNAMES,tif->tif_dir.td_inknameslen,tif->tif_dir.td_inknames))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SUBIFD))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSubifd(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\t{\n\t\t\t\tuint32 n;\n\t\t\t\tfor (n=0; n<tif->tif_nfields; n++) {\n\t\t\t\t\tconst TIFFField* o;\n\t\t\t\t\to = tif->tif_fields[n];\n\t\t\t\t\tif ((o->field_bit>=FIELD_CODEC)&&(TIFFFieldSet(tif,o->field_bit)))\n\t\t\t\t\t{\n\t\t\t\t\t\tswitch (o->get_field_type)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcase TIFF_SETGET_ASCII:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 pa;\n\t\t\t\t\t\t\t\t\tchar* pb;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_ASCII);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==TIFF_VARIABLE);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&pb);\n\t\t\t\t\t\t\t\t\tpa=(uint32)(strlen(pb));\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,(uint16)o->field_tag,pa,pb))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_UINT16:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint16 p;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_SHORT);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==1);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&p);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,(uint16)o->field_tag,p))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_UINT32:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 p;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_LONG);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==1);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&p);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,(uint16)o->field_tag,p))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_C32_UINT8:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 pa;\n\t\t\t\t\t\t\t\t\tvoid* pb;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_UNDEFINED);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==TIFF_VARIABLE2);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==1);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&pa,&pb);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,(uint16)o->field_tag,pa,pb))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\tassert(0);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (m=0; m<(uint32)(tif->tif_dir.td_customValueCount); m++)\n\t\t{\n uint16 tag = (uint16)tif->tif_dir.td_customValues[m].info->field_tag;\n uint32 count = tif->tif_dir.td_customValues[m].count;\n\t\t\tswitch (tif->tif_dir.td_customValues[m].info->field_type)\n\t\t\t{\n\t\t\t\tcase TIFF_ASCII:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_UNDEFINED:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_BYTE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagByteArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SBYTE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSbyteArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SHORT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SSHORT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSshortArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_LONG:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SLONG:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSlongArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_LONG8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLong8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SLONG8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSlong8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_RATIONAL:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SRATIONAL:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_FLOAT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagFloatArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_DOUBLE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagDoubleArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_IFD:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagIfdArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_IFD8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagIfdIfd8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert(0);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (dir!=NULL)\n\t\t\tbreak;\n\t\tdir=_TIFFmalloc(ndir*sizeof(TIFFDirEntry));\n\t\tif (dir==NULL)\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Out of memory");\n\t\t\tgoto bad;\n\t\t}\n\t\tif (isimage)\n\t\t{\n\t\t\tif ((tif->tif_diroff==0)&&(!TIFFLinkDirectory(tif)))\n\t\t\t\tgoto bad;\n\t\t}\n\t\telse\n\t\t\ttif->tif_diroff=(TIFFSeekFile(tif,0,SEEK_END)+1)&(~((toff_t)1));\n\t\tif (pdiroff!=NULL)\n\t\t\t*pdiroff=tif->tif_diroff;\n\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\tdirsize=2+ndir*12+4;\n\t\telse\n\t\t\tdirsize=8+ndir*20+8;\n\t\ttif->tif_dataoff=tif->tif_diroff+dirsize;\n\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\ttif->tif_dataoff=(uint32)tif->tif_dataoff;\n\t\tif ((tif->tif_dataoff<tif->tif_diroff)||(tif->tif_dataoff<(uint64)dirsize))\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Maximum TIFF file size exceeded");\n\t\t\tgoto bad;\n\t\t}\n\t\tif (tif->tif_dataoff&1)\n\t\t\ttif->tif_dataoff++;\n\t\tif (isimage)\n\t\t\ttif->tif_curdir++;\n\t}\n\tif (isimage)\n\t{\n\t\tif (TIFFFieldSet(tif,FIELD_SUBIFD)&&(tif->tif_subifdoff==0))\n\t\t{\n\t\t\tuint32 na;\n\t\t\tTIFFDirEntry* nb;\n\t\t\tfor (na=0, nb=dir; ; na++, nb++)\n\t\t\t{\n\t\t\t\tif( na == ndir )\n {\n TIFFErrorExt(tif->tif_clientdata,module,\n "Cannot find SubIFD tag");\n goto bad;\n }\n\t\t\t\tif (nb->tdir_tag==TIFFTAG_SUBIFD)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\t\ttif->tif_subifdoff=tif->tif_diroff+2+na*12+8;\n\t\t\telse\n\t\t\t\ttif->tif_subifdoff=tif->tif_diroff+8+na*20+12;\n\t\t}\n\t}\n\tdirmem=_TIFFmalloc(dirsize);\n\tif (dirmem==NULL)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Out of memory");\n\t\tgoto bad;\n\t}\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t{\n\t\tuint8* n;\n\t\tuint32 nTmp;\n\t\tTIFFDirEntry* o;\n\t\tn=dirmem;\n\t\t*(uint16*)n=(uint16)ndir;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabShort((uint16*)n);\n\t\tn+=2;\n\t\to=dir;\n\t\tfor (m=0; m<ndir; m++)\n\t\t{\n\t\t\t*(uint16*)n=o->tdir_tag;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t*(uint16*)n=o->tdir_type;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\tnTmp = (uint32)o->tdir_count;\n\t\t\t_TIFFmemcpy(n,&nTmp,4);\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabLong((uint32*)n);\n\t\t\tn+=4;\n\t\t\t_TIFFmemcpy(n,&o->tdir_offset,4);\n\t\t\tn+=4;\n\t\t\to++;\n\t\t}\n\t\tnTmp = (uint32)tif->tif_nextdiroff;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong(&nTmp);\n\t\t_TIFFmemcpy(n,&nTmp,4);\n\t}\n\telse\n\t{\n\t\tuint8* n;\n\t\tTIFFDirEntry* o;\n\t\tn=dirmem;\n\t\t*(uint64*)n=ndir;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong8((uint64*)n);\n\t\tn+=8;\n\t\to=dir;\n\t\tfor (m=0; m<ndir; m++)\n\t\t{\n\t\t\t*(uint16*)n=o->tdir_tag;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t*(uint16*)n=o->tdir_type;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t_TIFFmemcpy(n,&o->tdir_count,8);\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabLong8((uint64*)n);\n\t\t\tn+=8;\n\t\t\t_TIFFmemcpy(n,&o->tdir_offset,8);\n\t\t\tn+=8;\n\t\t\to++;\n\t\t}\n\t\t_TIFFmemcpy(n,&tif->tif_nextdiroff,8);\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong8((uint64*)n);\n\t}\n\t_TIFFfree(dir);\n\tdir=NULL;\n\tif (!SeekOK(tif,tif->tif_diroff))\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory");\n\t\tgoto bad;\n\t}\n\tif (!WriteOK(tif,dirmem,(tmsize_t)dirsize))\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory");\n\t\tgoto bad;\n\t}\n\t_TIFFfree(dirmem);\n\tif (imagedone)\n\t{\n\t\tTIFFFreeDirectory(tif);\n\t\ttif->tif_flags &= ~TIFF_DIRTYDIRECT;\n\t\ttif->tif_flags &= ~TIFF_DIRTYSTRIP;\n\t\t(*tif->tif_cleanup)(tif);\n\t\tTIFFCreateDirectory(tif);\n\t}\n\treturn(1);\nbad:\n\tif (dir!=NULL)\n\t\t_TIFFfree(dir);\n\tif (dirmem!=NULL)\n\t\t_TIFFfree(dirmem);\n\treturn(0);\n}', 'static int\nTIFFWriteDirectoryTagLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value)\n{\n static const char module[] = "TIFFWriteDirectoryTagLongLong8Array";\n uint64* ma;\n uint32 mb;\n uint32* p;\n uint32* q;\n int o;\n if (dir==NULL)\n {\n (*ndir)++;\n return(1);\n }\n if( tif->tif_flags&TIFF_BIGTIFF )\n return TIFFWriteDirectoryTagCheckedLong8Array(tif,ndir,dir,\n tag,count,value);\n p = _TIFFmalloc(count*sizeof(uint32));\n if (p==NULL)\n {\n TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");\n return(0);\n }\n for (q=p, ma=value, mb=0; mb<count; ma++, mb++, q++)\n {\n if (*ma>0xFFFFFFFF)\n {\n TIFFErrorExt(tif->tif_clientdata,module,\n "Attempt to write value larger than 0xFFFFFFFF in Classic TIFF file.");\n _TIFFfree(p);\n return(0);\n }\n *q= (uint32)(*ma);\n }\n o=TIFFWriteDirectoryTagCheckedLongArray(tif,ndir,dir,tag,count,p);\n _TIFFfree(p);\n return(o);\n}', 'static int\nTIFFWriteDirectoryTagCheckedLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value)\n{\n\tassert(count<0x20000000);\n\tassert(sizeof(uint64)==8);\n\tif( !(tif->tif_flags&TIFF_BIGTIFF) ) {\n\t\tTIFFErrorExt(tif->tif_clientdata,"TIFFWriteDirectoryTagCheckedLong8Array","LONG8 not allowed for ClassicTIFF");\n\t\treturn(0);\n\t}\n\tif (tif->tif_flags&TIFF_SWAB)\n\t\tTIFFSwabArrayOfLong8(value,count);\n\treturn(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG8,count,count*8,value));\n}', 'void\nTIFFSwabArrayOfLong8(register uint64* lp, tmsize_t n)\n{\n\tregister unsigned char *cp;\n\tregister unsigned char t;\n\tassert(sizeof(uint64)==8);\n\twhile (n-- > 0) {\n\t\tcp = (unsigned char *)lp;\n\t\tt = cp[7]; cp[7] = cp[0]; cp[0] = t;\n\t\tt = cp[6]; cp[6] = cp[1]; cp[1] = t;\n\t\tt = cp[5]; cp[5] = cp[2]; cp[2] = t;\n\t\tt = cp[4]; cp[4] = cp[3]; cp[3] = t;\n\t\tlp++;\n\t}\n}']
|
2,761
| 0
|
https://github.com/nginx/nginx/blob/70f7141074896fb1ff3e5fc08407ea0f64f2076b/src/core/ngx_sha1.c/#L235
|
static const u_char *
ngx_sha1_body(ngx_sha1_t *ctx, const u_char *data, size_t size)
{
uint32_t a, b, c, d, e, temp;
uint32_t saved_a, saved_b, saved_c, saved_d, saved_e;
uint32_t words[80];
ngx_uint_t i;
const u_char *p;
p = data;
a = ctx->a;
b = ctx->b;
c = ctx->c;
d = ctx->d;
e = ctx->e;
do {
saved_a = a;
saved_b = b;
saved_c = c;
saved_d = d;
saved_e = e;
for (i = 0; i < 16; i++) {
words[i] = GET(i);
}
for (i = 16; i < 80; i++) {
words[i] = ROTATE(1, words[i - 3] ^ words[i - 8] ^ words[i - 14]
^ words[i - 16]);
}
STEP(F1, a, b, c, d, e, words[0], 0x5a827999);
STEP(F1, a, b, c, d, e, words[1], 0x5a827999);
STEP(F1, a, b, c, d, e, words[2], 0x5a827999);
STEP(F1, a, b, c, d, e, words[3], 0x5a827999);
STEP(F1, a, b, c, d, e, words[4], 0x5a827999);
STEP(F1, a, b, c, d, e, words[5], 0x5a827999);
STEP(F1, a, b, c, d, e, words[6], 0x5a827999);
STEP(F1, a, b, c, d, e, words[7], 0x5a827999);
STEP(F1, a, b, c, d, e, words[8], 0x5a827999);
STEP(F1, a, b, c, d, e, words[9], 0x5a827999);
STEP(F1, a, b, c, d, e, words[10], 0x5a827999);
STEP(F1, a, b, c, d, e, words[11], 0x5a827999);
STEP(F1, a, b, c, d, e, words[12], 0x5a827999);
STEP(F1, a, b, c, d, e, words[13], 0x5a827999);
STEP(F1, a, b, c, d, e, words[14], 0x5a827999);
STEP(F1, a, b, c, d, e, words[15], 0x5a827999);
STEP(F1, a, b, c, d, e, words[16], 0x5a827999);
STEP(F1, a, b, c, d, e, words[17], 0x5a827999);
STEP(F1, a, b, c, d, e, words[18], 0x5a827999);
STEP(F1, a, b, c, d, e, words[19], 0x5a827999);
STEP(F2, a, b, c, d, e, words[20], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[21], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[22], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[23], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[24], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[25], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[26], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[27], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[28], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[29], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[30], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[31], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[32], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[33], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[34], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[35], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[36], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[37], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[38], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[39], 0x6ed9eba1);
STEP(F3, a, b, c, d, e, words[40], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[41], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[42], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[43], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[44], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[45], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[46], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[47], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[48], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[49], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[50], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[51], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[52], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[53], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[54], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[55], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[56], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[57], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[58], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[59], 0x8f1bbcdc);
STEP(F2, a, b, c, d, e, words[60], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[61], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[62], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[63], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[64], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[65], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[66], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[67], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[68], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[69], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[70], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[71], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[72], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[73], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[74], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[75], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[76], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[77], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[78], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[79], 0xca62c1d6);
a += saved_a;
b += saved_b;
c += saved_c;
d += saved_d;
e += saved_e;
p += 64;
} while (size -= 64);
ctx->a = a;
ctx->b = b;
ctx->c = c;
ctx->d = d;
ctx->e = e;
return p;
}
|
['static const u_char *\nngx_sha1_body(ngx_sha1_t *ctx, const u_char *data, size_t size)\n{\n uint32_t a, b, c, d, e, temp;\n uint32_t saved_a, saved_b, saved_c, saved_d, saved_e;\n uint32_t words[80];\n ngx_uint_t i;\n const u_char *p;\n p = data;\n a = ctx->a;\n b = ctx->b;\n c = ctx->c;\n d = ctx->d;\n e = ctx->e;\n do {\n saved_a = a;\n saved_b = b;\n saved_c = c;\n saved_d = d;\n saved_e = e;\n for (i = 0; i < 16; i++) {\n words[i] = GET(i);\n }\n for (i = 16; i < 80; i++) {\n words[i] = ROTATE(1, words[i - 3] ^ words[i - 8] ^ words[i - 14]\n ^ words[i - 16]);\n }\n STEP(F1, a, b, c, d, e, words[0], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[1], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[2], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[3], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[4], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[5], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[6], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[7], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[8], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[9], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[10], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[11], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[12], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[13], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[14], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[15], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[16], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[17], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[18], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[19], 0x5a827999);\n STEP(F2, a, b, c, d, e, words[20], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[21], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[22], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[23], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[24], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[25], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[26], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[27], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[28], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[29], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[30], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[31], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[32], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[33], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[34], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[35], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[36], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[37], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[38], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[39], 0x6ed9eba1);\n STEP(F3, a, b, c, d, e, words[40], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[41], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[42], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[43], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[44], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[45], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[46], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[47], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[48], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[49], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[50], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[51], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[52], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[53], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[54], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[55], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[56], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[57], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[58], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[59], 0x8f1bbcdc);\n STEP(F2, a, b, c, d, e, words[60], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[61], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[62], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[63], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[64], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[65], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[66], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[67], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[68], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[69], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[70], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[71], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[72], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[73], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[74], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[75], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[76], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[77], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[78], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[79], 0xca62c1d6);\n a += saved_a;\n b += saved_b;\n c += saved_c;\n d += saved_d;\n e += saved_e;\n p += 64;\n } while (size -= 64);\n ctx->a = a;\n ctx->b = b;\n ctx->c = c;\n ctx->d = d;\n ctx->e = e;\n return p;\n}']
|
2,762
| 0
|
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/asn1/asn1_lib.c/#L204
|
void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
int xclass)
{
unsigned char *p= *pp;
int i;
i=(constructed)?V_ASN1_CONSTRUCTED:0;
i|=(xclass&V_ASN1_PRIVATE);
if (tag < 31)
*(p++)=i|(tag&V_ASN1_PRIMATIVE_TAG);
else
{
*(p++)=i|V_ASN1_PRIMATIVE_TAG;
while (tag > 0x7f)
{
*(p++)=(tag&0x7f)|0x80;
tag>>=7;
}
*(p++)=(tag&0x7f);
}
if ((constructed == 2) && (length == 0))
*(p++)=0x80;
else
asn1_put_length(&p,length);
*pp=p;
}
|
['PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)\n{\n\tPKCS8_PRIV_KEY_INFO *p8;\n\tASN1_INTEGER *dpkey;\n\tunsigned char *p, *q;\n\tint len;\n\tif (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {\n\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tASN1_INTEGER_set (p8->version, 0);\n\tif (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {\n\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);\n\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\treturn NULL;\n\t}\n\tswitch (EVP_PKEY_type(pkey->type)) {\n\t\tcase EVP_PKEY_RSA:\n\t\tp8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);\n\t\tp8->pkeyalg->parameter->type = V_ASN1_NULL;\n\t\tif (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,\n\t\t\t\t\t &p8->pkey->value.octet_string)) {\n\t\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);\n\t\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\t\treturn NULL;\n\t\t}\n\t\tbreak;\n\t\tcase EVP_PKEY_DSA:\n\t\tp8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);\n\t\tlen = i2d_DSAparams (pkey->pkey.dsa, NULL);\n\t\tif (!(p = Malloc(len))) {\n\t\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);\n\t\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\t\treturn NULL;\n\t\t}\n\t\tq = p;\n\t\ti2d_DSAparams (pkey->pkey.dsa, &q);\n\t\tp8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;\n\t\tp8->pkeyalg->parameter->value.sequence = ASN1_STRING_new();\n\t\tASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, len);\n\t\tFree(p);\n\t\tif (!(dpkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {\n\t\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);\n\t\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (!ASN1_pack_string((char *)dpkey, i2d_ASN1_INTEGER,\n\t\t\t\t\t &p8->pkey->value.octet_string)) {\n\t\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);\n\t\t\tASN1_INTEGER_free (dpkey);\n\t\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\t\treturn NULL;\n\t\t}\n\t\tASN1_INTEGER_free (dpkey);\n\t\tbreak;\n\t\tdefault:\n\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);\n\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\treturn NULL;\n\t}\n\tp8->pkey->type = V_ASN1_OCTET_STRING;\n\tRAND_seed (p8->pkey->value.octet_string->data,\n\t\t\t\t\t p8->pkey->value.octet_string->length);\n\treturn p8;\n}', 'int i2d_DSAparams(DSA *a, unsigned char **pp)\n\t{\n\tBIGNUM *num[3];\n\tASN1_INTEGER bs;\n\tunsigned int j,i,tot=0,len,max=0;\n\tint t,ret= -1;\n\tunsigned char *p;\n\tif (a == NULL) return(0);\n\tnum[0]=a->p;\n\tnum[1]=a->q;\n\tnum[2]=a->g;\n\tfor (i=0; i<3; i++)\n\t\t{\n\t\tif (num[i] == NULL) continue;\n\t\tj=BN_num_bits(num[i]);\n\t\tlen=((j == 0)?0:((j/8)+1));\n\t\tif (len > max) max=len;\n\t\tlen=ASN1_object_size(0,len,\n\t\t\t(num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER);\n\t\ttot+=len;\n\t\t}\n\tt=ASN1_object_size(1,tot,V_ASN1_SEQUENCE);\n\tif (pp == NULL) return(t);\n\tp= *pp;\n\tASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);\n\tbs.type=V_ASN1_INTEGER;\n\tbs.data=(unsigned char *)Malloc(max+4);\n\tif (bs.data == NULL)\n\t\t{\n\t\tASN1err(ASN1_F_I2D_DSAPARAMS,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tfor (i=0; i<3; i++)\n\t\t{\n\t\tif (num[i] == NULL) continue;\n\t\tbs.length=BN_bn2bin(num[i],bs.data);\n\t\ti2d_ASN1_INTEGER(&bs,&p);\n\t\t}\n\tFree((char *)bs.data);\n\tret=t;\nerr:\n\t*pp=p;\n\treturn(ret);\n\t}', 'void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,\n\t int xclass)\n\t{\n\tunsigned char *p= *pp;\n\tint i;\n\ti=(constructed)?V_ASN1_CONSTRUCTED:0;\n\ti|=(xclass&V_ASN1_PRIVATE);\n\tif (tag < 31)\n\t\t*(p++)=i|(tag&V_ASN1_PRIMATIVE_TAG);\n\telse\n\t\t{\n\t\t*(p++)=i|V_ASN1_PRIMATIVE_TAG;\n\t\twhile (tag > 0x7f)\n\t\t\t{\n\t\t\t*(p++)=(tag&0x7f)|0x80;\n\t\t\ttag>>=7;\n\t\t\t}\n\t\t*(p++)=(tag&0x7f);\n\t\t}\n\tif ((constructed == 2) && (length == 0))\n\t\t*(p++)=0x80;\n\telse\n\t\tasn1_put_length(&p,length);\n\t*pp=p;\n\t}']
|
2,763
| 0
|
https://github.com/libav/libav/blob/60728e8bab8d2a5f6bbb4baa7d53142dbc6047ed/libavcodec/g2meet.c/#L248
|
static int jpg_decode_data(JPGContext *c, int width, int height,
const uint8_t *src, int src_size,
uint8_t *dst, int dst_stride,
const uint8_t *mask, int mask_stride, int num_mbs,
int swapuv)
{
GetBitContext gb;
int mb_w, mb_h, mb_x, mb_y, i, j;
int bx, by;
int unesc_size;
int ret;
if ((ret = av_reallocp(&c->buf,
src_size + FF_INPUT_BUFFER_PADDING_SIZE)) < 0)
return ret;
jpg_unescape(src, src_size, c->buf, &unesc_size);
memset(c->buf + unesc_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
init_get_bits(&gb, c->buf, unesc_size * 8);
width = FFALIGN(width, 16);
mb_w = width >> 4;
mb_h = (height + 15) >> 4;
if (!num_mbs)
num_mbs = mb_w * mb_h * 4;
for (i = 0; i < 3; i++)
c->prev_dc[i] = 1024;
bx = by = 0;
c->dsp.clear_blocks(c->block[0]);
for (mb_y = 0; mb_y < mb_h; mb_y++) {
for (mb_x = 0; mb_x < mb_w; mb_x++) {
if (mask && !mask[mb_x * 2] && !mask[mb_x * 2 + 1] &&
!mask[mb_x * 2 + mask_stride] &&
!mask[mb_x * 2 + 1 + mask_stride]) {
bx += 16;
continue;
}
for (j = 0; j < 2; j++) {
for (i = 0; i < 2; i++) {
if (mask && !mask[mb_x * 2 + i + j * mask_stride])
continue;
num_mbs--;
if ((ret = jpg_decode_block(c, &gb, 0,
c->block[i + j * 2])) != 0)
return ret;
c->dsp.idct(c->block[i + j * 2]);
}
}
for (i = 1; i < 3; i++) {
if ((ret = jpg_decode_block(c, &gb, i, c->block[i + 3])) != 0)
return ret;
c->dsp.idct(c->block[i + 3]);
}
for (j = 0; j < 16; j++) {
uint8_t *out = dst + bx * 3 + (by + j) * dst_stride;
for (i = 0; i < 16; i++) {
int Y, U, V;
Y = c->block[(j >> 3) * 2 + (i >> 3)][(i & 7) + (j & 7) * 8];
U = c->block[4 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;
V = c->block[5 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;
yuv2rgb(out + i * 3, Y, U, V);
}
}
if (!num_mbs)
return 0;
bx += 16;
}
bx = 0;
by += 16;
if (mask)
mask += mask_stride * 2;
}
return 0;
}
|
['static int jpg_decode_data(JPGContext *c, int width, int height,\n const uint8_t *src, int src_size,\n uint8_t *dst, int dst_stride,\n const uint8_t *mask, int mask_stride, int num_mbs,\n int swapuv)\n{\n GetBitContext gb;\n int mb_w, mb_h, mb_x, mb_y, i, j;\n int bx, by;\n int unesc_size;\n int ret;\n if ((ret = av_reallocp(&c->buf,\n src_size + FF_INPUT_BUFFER_PADDING_SIZE)) < 0)\n return ret;\n jpg_unescape(src, src_size, c->buf, &unesc_size);\n memset(c->buf + unesc_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n init_get_bits(&gb, c->buf, unesc_size * 8);\n width = FFALIGN(width, 16);\n mb_w = width >> 4;\n mb_h = (height + 15) >> 4;\n if (!num_mbs)\n num_mbs = mb_w * mb_h * 4;\n for (i = 0; i < 3; i++)\n c->prev_dc[i] = 1024;\n bx = by = 0;\n c->dsp.clear_blocks(c->block[0]);\n for (mb_y = 0; mb_y < mb_h; mb_y++) {\n for (mb_x = 0; mb_x < mb_w; mb_x++) {\n if (mask && !mask[mb_x * 2] && !mask[mb_x * 2 + 1] &&\n !mask[mb_x * 2 + mask_stride] &&\n !mask[mb_x * 2 + 1 + mask_stride]) {\n bx += 16;\n continue;\n }\n for (j = 0; j < 2; j++) {\n for (i = 0; i < 2; i++) {\n if (mask && !mask[mb_x * 2 + i + j * mask_stride])\n continue;\n num_mbs--;\n if ((ret = jpg_decode_block(c, &gb, 0,\n c->block[i + j * 2])) != 0)\n return ret;\n c->dsp.idct(c->block[i + j * 2]);\n }\n }\n for (i = 1; i < 3; i++) {\n if ((ret = jpg_decode_block(c, &gb, i, c->block[i + 3])) != 0)\n return ret;\n c->dsp.idct(c->block[i + 3]);\n }\n for (j = 0; j < 16; j++) {\n uint8_t *out = dst + bx * 3 + (by + j) * dst_stride;\n for (i = 0; i < 16; i++) {\n int Y, U, V;\n Y = c->block[(j >> 3) * 2 + (i >> 3)][(i & 7) + (j & 7) * 8];\n U = c->block[4 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;\n V = c->block[5 ^ swapuv][(i >> 1) + (j >> 1) * 8] - 128;\n yuv2rgb(out + i * 3, Y, U, V);\n }\n }\n if (!num_mbs)\n return 0;\n bx += 16;\n }\n bx = 0;\n by += 16;\n if (mask)\n mask += mask_stride * 2;\n }\n return 0;\n}', 'int av_reallocp(void *ptr, size_t size)\n{\n void **ptrptr = ptr;\n void *ret;\n if (!size) {\n av_freep(ptr);\n return 0;\n }\n ret = av_realloc(*ptrptr, size);\n if (!ret) {\n av_freep(ptr);\n return AVERROR(ENOMEM);\n }\n *ptrptr = ret;\n return 0;\n}', 'void av_freep(void *arg)\n{\n void **ptr = (void **)arg;\n av_free(*ptr);\n *ptr = NULL;\n}', 'void av_free(void *ptr)\n{\n#if CONFIG_MEMALIGN_HACK\n if (ptr)\n free((char *)ptr - ((char *)ptr)[-1]);\n#elif HAVE_ALIGNED_MALLOC\n _aligned_free(ptr);\n#else\n free(ptr);\n#endif\n}', 'static void jpg_unescape(const uint8_t *src, int src_size,\n uint8_t *dst, int *dst_size)\n{\n const uint8_t *src_end = src + src_size;\n uint8_t *dst_start = dst;\n while (src < src_end) {\n uint8_t x = *src++;\n *dst++ = x;\n if (x == 0xFF && !*src)\n src++;\n }\n *dst_size = dst - dst_start;\n}']
|
2,764
| 0
|
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L139
|
static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
bc->bits >>= n;
#else
uint64_t ret = bc->bits >> (64 - n);
bc->bits <<= n;
#endif
bc->bits_left -= n;
return ret;
}
|
['static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,\n AVPacket *avpkt)\n{\n RALFContext *ctx = avctx->priv_data;\n AVFrame *frame = data;\n int16_t *samples0;\n int16_t *samples1;\n int ret;\n BitstreamContext bc;\n int table_size, table_bytes, i;\n const uint8_t *src, *block_pointer;\n int src_size;\n int bytes_left;\n if (ctx->has_pkt) {\n ctx->has_pkt = 0;\n table_bytes = (AV_RB16(avpkt->data) + 7) >> 3;\n if (table_bytes + 3 > avpkt->size || avpkt->size > RALF_MAX_PKT_SIZE) {\n av_log(avctx, AV_LOG_ERROR, "Wrong packet\'s breath smells of wrong data!\\n");\n return AVERROR_INVALIDDATA;\n }\n if (memcmp(ctx->pkt, avpkt->data, 2 + table_bytes)) {\n av_log(avctx, AV_LOG_ERROR, "Wrong packet tails are wrong!\\n");\n return AVERROR_INVALIDDATA;\n }\n src = ctx->pkt;\n src_size = RALF_MAX_PKT_SIZE + avpkt->size;\n memcpy(ctx->pkt + RALF_MAX_PKT_SIZE, avpkt->data + 2 + table_bytes,\n avpkt->size - 2 - table_bytes);\n } else {\n if (avpkt->size == RALF_MAX_PKT_SIZE) {\n memcpy(ctx->pkt, avpkt->data, avpkt->size);\n ctx->has_pkt = 1;\n *got_frame_ptr = 0;\n return avpkt->size;\n }\n src = avpkt->data;\n src_size = avpkt->size;\n }\n frame->nb_samples = ctx->max_frame_size;\n if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {\n av_log(avctx, AV_LOG_ERROR, "Me fail get_buffer()? That\'s unpossible!\\n");\n return ret;\n }\n samples0 = (int16_t *)frame->data[0];\n samples1 = (int16_t *)frame->data[1];\n if (src_size < 5) {\n av_log(avctx, AV_LOG_ERROR, "too short packets are too short!\\n");\n return AVERROR_INVALIDDATA;\n }\n table_size = AV_RB16(src);\n table_bytes = (table_size + 7) >> 3;\n if (src_size < table_bytes + 3) {\n av_log(avctx, AV_LOG_ERROR, "short packets are short!\\n");\n return AVERROR_INVALIDDATA;\n }\n bitstream_init(&bc, src + 2, table_size);\n ctx->num_blocks = 0;\n while (bitstream_bits_left(&bc) > 0) {\n ctx->block_size[ctx->num_blocks] = bitstream_read(&bc, 15);\n if (bitstream_read_bit(&bc)) {\n ctx->block_pts[ctx->num_blocks] = bitstream_read(&bc, 9);\n } else {\n ctx->block_pts[ctx->num_blocks] = 0;\n }\n ctx->num_blocks++;\n }\n block_pointer = src + table_bytes + 2;\n bytes_left = src_size - table_bytes - 2;\n ctx->sample_offset = 0;\n for (i = 0; i < ctx->num_blocks; i++) {\n if (bytes_left < ctx->block_size[i]) {\n av_log(avctx, AV_LOG_ERROR, "I\'m pedaling backwards\\n");\n break;\n }\n bitstream_init8(&bc, block_pointer, ctx->block_size[i]);\n if (decode_block(avctx, &bc, samples0 + ctx->sample_offset,\n samples1 + ctx->sample_offset) < 0) {\n av_log(avctx, AV_LOG_ERROR, "Sir, I got carsick in your office. Not decoding the rest of packet.\\n");\n break;\n }\n block_pointer += ctx->block_size[i];\n bytes_left -= ctx->block_size[i];\n }\n frame->nb_samples = ctx->sample_offset;\n *got_frame_ptr = ctx->sample_offset > 0;\n return avpkt->size;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline unsigned bitstream_read_bit(BitstreamContext *bc)\n{\n if (!bc->bits_left)\n refill_64(bc);\n return get_val(bc, 1);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
|
2,765
| 0
|
https://github.com/openssl/openssl/blob/25a5d1b8c425d9434ed8b2bec53d20ab8c14f886/crypto/x509/x509_req.c/#L126
|
int X509_REQ_check_private_key(X509_REQ *x, EVP_PKEY *k)
{
EVP_PKEY *xk = NULL;
int ok = 0;
xk = X509_REQ_get_pubkey(x);
switch (EVP_PKEY_cmp(xk, k)) {
case 1:
ok = 1;
break;
case 0:
X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,
X509_R_KEY_VALUES_MISMATCH);
break;
case -1:
X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, X509_R_KEY_TYPE_MISMATCH);
break;
case -2:
#ifndef OPENSSL_NO_EC
if (k->type == EVP_PKEY_EC) {
X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, ERR_R_EC_LIB);
break;
}
#endif
#ifndef OPENSSL_NO_DH
if (k->type == EVP_PKEY_DH) {
X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,
X509_R_CANT_CHECK_DH_KEY);
break;
}
#endif
X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, X509_R_UNKNOWN_KEY_TYPE);
}
EVP_PKEY_free(xk);
return (ok);
}
|
['int X509_REQ_check_private_key(X509_REQ *x, EVP_PKEY *k)\n{\n EVP_PKEY *xk = NULL;\n int ok = 0;\n xk = X509_REQ_get_pubkey(x);\n switch (EVP_PKEY_cmp(xk, k)) {\n case 1:\n ok = 1;\n break;\n case 0:\n X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,\n X509_R_KEY_VALUES_MISMATCH);\n break;\n case -1:\n X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, X509_R_KEY_TYPE_MISMATCH);\n break;\n case -2:\n#ifndef OPENSSL_NO_EC\n if (k->type == EVP_PKEY_EC) {\n X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, ERR_R_EC_LIB);\n break;\n }\n#endif\n#ifndef OPENSSL_NO_DH\n if (k->type == EVP_PKEY_DH) {\n X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,\n X509_R_CANT_CHECK_DH_KEY);\n break;\n }\n#endif\n X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, X509_R_UNKNOWN_KEY_TYPE);\n }\n EVP_PKEY_free(xk);\n return (ok);\n}', 'EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req)\n{\n if ((req == NULL) || (req->req_info == NULL))\n return (NULL);\n return (X509_PUBKEY_get(req->req_info->pubkey));\n}', 'int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)\n{\n if (a->type != b->type)\n return -1;\n if (a->ameth) {\n int ret;\n if (a->ameth->param_cmp) {\n ret = a->ameth->param_cmp(a, b);\n if (ret <= 0)\n return ret;\n }\n if (a->ameth->pub_cmp)\n return a->ameth->pub_cmp(a, b);\n }\n return -2;\n}']
|
2,766
| 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_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,\n const BIGNUM *Xp, const BIGNUM *Xp1,\n const BIGNUM *Xp2, const BIGNUM *e, BN_CTX *ctx,\n BN_GENCB *cb)\n{\n int ret = 0;\n BIGNUM *t, *p1p2, *pm1;\n if (!BN_is_odd(e))\n return 0;\n BN_CTX_start(ctx);\n if (p1 == NULL)\n p1 = BN_CTX_get(ctx);\n if (p2 == NULL)\n p2 = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n p1p2 = BN_CTX_get(ctx);\n pm1 = BN_CTX_get(ctx);\n if (pm1 == NULL)\n goto err;\n if (!bn_x931_derive_pi(p1, Xp1, ctx, cb))\n goto err;\n if (!bn_x931_derive_pi(p2, Xp2, ctx, cb))\n goto err;\n if (!BN_mul(p1p2, p1, p2, ctx))\n goto err;\n if (!BN_mod_inverse(p, p2, p1, ctx))\n goto err;\n if (!BN_mul(p, p, p2, ctx))\n goto err;\n if (!BN_mod_inverse(t, p1, p2, ctx))\n goto err;\n if (!BN_mul(t, t, p1, ctx))\n goto err;\n if (!BN_sub(p, p, t))\n goto err;\n if (p->neg && !BN_add(p, p, p1p2))\n goto err;\n if (!BN_mod_sub(p, p, Xp, p1p2, ctx))\n goto err;\n if (!BN_add(p, p, Xp))\n goto err;\n for (;;) {\n int i = 1;\n BN_GENCB_call(cb, 0, i++);\n if (!BN_copy(pm1, p))\n goto err;\n if (!BN_sub_word(pm1, 1))\n goto err;\n if (!BN_gcd(t, pm1, e, ctx))\n goto err;\n if (BN_is_one(t)) {\n int r = BN_is_prime_fasttest_ex(p, 50, ctx, 1, cb);\n if (r < 0)\n goto err;\n if (r)\n break;\n }\n if (!BN_add(p, p, p1p2))\n goto err;\n }\n BN_GENCB_call(cb, 3, 0);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx,\n BN_GENCB *cb)\n{\n int i = 0, is_prime;\n if (!BN_copy(pi, Xpi))\n return 0;\n if (!BN_is_odd(pi) && !BN_add_word(pi, 1))\n return 0;\n for (;;) {\n i++;\n BN_GENCB_call(cb, 0, i);\n is_prime = BN_is_prime_fasttest_ex(pi, 27, ctx, 1, cb);\n if (is_prime < 0)\n return 0;\n if (is_prime)\n break;\n if (!BN_add_word(pi, 2))\n return 0;\n }\n BN_GENCB_call(cb, 2, i);\n return 1;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->neg = b->neg;\n a->top = b->top;\n a->flags |= b->flags & BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
2,767
| 0
|
https://github.com/libav/libav/blob/9104cd5161ec7cb31361f3dabd73a8a813d4f7d0/ffmpeg.c/#L3067
|
static void new_video_stream(AVFormatContext *oc)
{
AVStream *st;
AVCodecContext *video_enc;
enum CodecID codec_id;
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
av_exit(1);
}
avcodec_get_context_defaults2(st->codec, CODEC_TYPE_VIDEO);
bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters;
video_bitstream_filters= NULL;
avcodec_thread_init(st->codec, thread_count);
video_enc = st->codec;
if(video_codec_tag)
video_enc->codec_tag= video_codec_tag;
if( (video_global_header&1)
|| (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))){
video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
avcodec_opts[CODEC_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
}
if(video_global_header&2){
video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER;
avcodec_opts[CODEC_TYPE_VIDEO]->flags2|= CODEC_FLAG2_LOCAL_HEADER;
}
if (video_stream_copy) {
st->stream_copy = 1;
video_enc->codec_type = CODEC_TYPE_VIDEO;
video_enc->sample_aspect_ratio =
st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);
} else {
const char *p;
int i;
AVCodec *codec;
AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};
if (video_codec_name) {
codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 1);
codec = avcodec_find_encoder_by_name(video_codec_name);
output_codecs[nb_ocodecs] = codec;
} else {
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
codec = avcodec_find_encoder(codec_id);
}
video_enc->codec_id = codec_id;
set_context_opts(video_enc, avcodec_opts[CODEC_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
if (codec && codec->supported_framerates && !force_fps)
fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)];
video_enc->time_base.den = fps.num;
video_enc->time_base.num = fps.den;
video_enc->width = frame_width + frame_padright + frame_padleft;
video_enc->height = frame_height + frame_padtop + frame_padbottom;
video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255);
video_enc->pix_fmt = frame_pix_fmt;
st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
if(codec && codec->pix_fmts){
const enum PixelFormat *p= codec->pix_fmts;
for(; *p!=-1; p++){
if(*p == video_enc->pix_fmt)
break;
}
if(*p == -1)
video_enc->pix_fmt = codec->pix_fmts[0];
}
if (intra_only)
video_enc->gop_size = 0;
if (video_qscale || same_quality) {
video_enc->flags |= CODEC_FLAG_QSCALE;
video_enc->global_quality=
st->quality = FF_QP2LAMBDA * video_qscale;
}
if(intra_matrix)
video_enc->intra_matrix = intra_matrix;
if(inter_matrix)
video_enc->inter_matrix = inter_matrix;
p= video_rc_override_string;
for(i=0; p; i++){
int start, end, q;
int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
if(e!=3){
fprintf(stderr, "error parsing rc_override\n");
av_exit(1);
}
video_enc->rc_override=
av_realloc(video_enc->rc_override,
sizeof(RcOverride)*(i+1));
video_enc->rc_override[i].start_frame= start;
video_enc->rc_override[i].end_frame = end;
if(q>0){
video_enc->rc_override[i].qscale= q;
video_enc->rc_override[i].quality_factor= 1.0;
}
else{
video_enc->rc_override[i].qscale= 0;
video_enc->rc_override[i].quality_factor= -q/100.0;
}
p= strchr(p, '/');
if(p) p++;
}
video_enc->rc_override_count=i;
if (!video_enc->rc_initial_buffer_occupancy)
video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;
video_enc->me_threshold= me_threshold;
video_enc->intra_dc_precision= intra_dc_precision - 8;
if (do_psnr)
video_enc->flags|= CODEC_FLAG_PSNR;
if (do_pass) {
if (do_pass == 1) {
video_enc->flags |= CODEC_FLAG_PASS1;
} else {
video_enc->flags |= CODEC_FLAG_PASS2;
}
}
}
nb_ocodecs++;
if (video_language) {
av_metadata_set(&st->metadata, "language", video_language);
av_freep(&video_language);
}
video_disable = 0;
av_freep(&video_codec_name);
video_stream_copy = 0;
}
|
['static void new_video_stream(AVFormatContext *oc)\n{\n AVStream *st;\n AVCodecContext *video_enc;\n enum CodecID codec_id;\n st = av_new_stream(oc, oc->nb_streams);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n av_exit(1);\n }\n avcodec_get_context_defaults2(st->codec, CODEC_TYPE_VIDEO);\n bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters;\n video_bitstream_filters= NULL;\n avcodec_thread_init(st->codec, thread_count);\n video_enc = st->codec;\n if(video_codec_tag)\n video_enc->codec_tag= video_codec_tag;\n if( (video_global_header&1)\n || (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))){\n video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;\n avcodec_opts[CODEC_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;\n }\n if(video_global_header&2){\n video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER;\n avcodec_opts[CODEC_TYPE_VIDEO]->flags2|= CODEC_FLAG2_LOCAL_HEADER;\n }\n if (video_stream_copy) {\n st->stream_copy = 1;\n video_enc->codec_type = CODEC_TYPE_VIDEO;\n video_enc->sample_aspect_ratio =\n st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);\n } else {\n const char *p;\n int i;\n AVCodec *codec;\n AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};\n if (video_codec_name) {\n codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 1);\n codec = avcodec_find_encoder_by_name(video_codec_name);\n output_codecs[nb_ocodecs] = codec;\n } else {\n codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);\n codec = avcodec_find_encoder(codec_id);\n }\n video_enc->codec_id = codec_id;\n set_context_opts(video_enc, avcodec_opts[CODEC_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);\n if (codec && codec->supported_framerates && !force_fps)\n fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)];\n video_enc->time_base.den = fps.num;\n video_enc->time_base.num = fps.den;\n video_enc->width = frame_width + frame_padright + frame_padleft;\n video_enc->height = frame_height + frame_padtop + frame_padbottom;\n video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255);\n video_enc->pix_fmt = frame_pix_fmt;\n st->sample_aspect_ratio = video_enc->sample_aspect_ratio;\n if(codec && codec->pix_fmts){\n const enum PixelFormat *p= codec->pix_fmts;\n for(; *p!=-1; p++){\n if(*p == video_enc->pix_fmt)\n break;\n }\n if(*p == -1)\n video_enc->pix_fmt = codec->pix_fmts[0];\n }\n if (intra_only)\n video_enc->gop_size = 0;\n if (video_qscale || same_quality) {\n video_enc->flags |= CODEC_FLAG_QSCALE;\n video_enc->global_quality=\n st->quality = FF_QP2LAMBDA * video_qscale;\n }\n if(intra_matrix)\n video_enc->intra_matrix = intra_matrix;\n if(inter_matrix)\n video_enc->inter_matrix = inter_matrix;\n p= video_rc_override_string;\n for(i=0; p; i++){\n int start, end, q;\n int e=sscanf(p, "%d,%d,%d", &start, &end, &q);\n if(e!=3){\n fprintf(stderr, "error parsing rc_override\\n");\n av_exit(1);\n }\n video_enc->rc_override=\n av_realloc(video_enc->rc_override,\n sizeof(RcOverride)*(i+1));\n video_enc->rc_override[i].start_frame= start;\n video_enc->rc_override[i].end_frame = end;\n if(q>0){\n video_enc->rc_override[i].qscale= q;\n video_enc->rc_override[i].quality_factor= 1.0;\n }\n else{\n video_enc->rc_override[i].qscale= 0;\n video_enc->rc_override[i].quality_factor= -q/100.0;\n }\n p= strchr(p, \'/\');\n if(p) p++;\n }\n video_enc->rc_override_count=i;\n if (!video_enc->rc_initial_buffer_occupancy)\n video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;\n video_enc->me_threshold= me_threshold;\n video_enc->intra_dc_precision= intra_dc_precision - 8;\n if (do_psnr)\n video_enc->flags|= CODEC_FLAG_PSNR;\n if (do_pass) {\n if (do_pass == 1) {\n video_enc->flags |= CODEC_FLAG_PASS1;\n } else {\n video_enc->flags |= CODEC_FLAG_PASS2;\n }\n }\n }\n nb_ocodecs++;\n if (video_language) {\n av_metadata_set(&st->metadata, "language", video_language);\n av_freep(&video_language);\n }\n video_disable = 0;\n av_freep(&video_codec_name);\n video_stream_copy = 0;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n if (s->nb_streams >= MAX_STREAMS)\n return NULL;\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n st->codec= avcodec_alloc_context();\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->id = id;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = 0;\n st->first_dts = AV_NOPTS_VALUE;\n st->probe_packets = MAX_PROBE_PACKETS;\n av_set_pts_info(st, 33, 1, 90000);\n st->last_IP_pts = AV_NOPTS_VALUE;\n for(i=0; i<MAX_REORDER_DELAY+1; i++)\n st->pts_buffer[i]= AV_NOPTS_VALUE;\n st->reference_dts = AV_NOPTS_VALUE;\n st->sample_aspect_ratio = (AVRational){0,1};\n s->streams[s->nb_streams++] = st;\n return st;\n}']
|
2,768
| 0
|
https://gitlab.com/libtiff/libtiff/blob/709e93ded0000128625a23838756a408ea30745d/libtiff/tif_tile.c/#L131
|
uint32
TIFFNumberOfTiles(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
uint32 dx = td->td_tilewidth;
uint32 dy = td->td_tilelength;
uint32 dz = td->td_tiledepth;
uint32 ntiles;
if (dx == (uint32) -1)
dx = td->td_imagewidth;
if (dy == (uint32) -1)
dy = td->td_imagelength;
if (dz == (uint32) -1)
dz = td->td_imagedepth;
ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :
_TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx),
TIFFhowmany_32(td->td_imagelength, dy),
"TIFFNumberOfTiles"),
TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
ntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel,
"TIFFNumberOfTiles");
return (ntiles);
}
|
['static void\nquant_fsdither(TIFF* in, TIFF* out)\n{\n\tunsigned char *outline, *inputline, *inptr;\n\tshort *thisline, *nextline;\n\tregister unsigned char\t*outptr;\n\tregister short *thisptr, *nextptr;\n\tregister uint32 i, j;\n\tuint32 imax, jmax;\n\tint lastline, lastpixel;\n\timax = imagelength - 1;\n\tjmax = imagewidth - 1;\n\tinputline = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(in));\n\tthisline = (short *)_TIFFmalloc(imagewidth * 3 * sizeof (short));\n\tnextline = (short *)_TIFFmalloc(imagewidth * 3 * sizeof (short));\n\toutline = (unsigned char *) _TIFFmalloc(TIFFScanlineSize(out));\n\tGetInputLine(in, 0, goto bad);\n\tfor (i = 1; i <= imagelength; ++i) {\n\t\tSWAP(short *, thisline, nextline);\n\t\tlastline = (i >= imax);\n\t\tif (i <= imax)\n\t\t\tGetInputLine(in, i, break);\n\t\tthisptr = thisline;\n\t\tnextptr = nextline;\n\t\toutptr = outline;\n\t\tfor (j = 0; j < imagewidth; ++j) {\n\t\t\tint red, green, blue;\n\t\t\tregister int oval, r2, g2, b2;\n\t\t\tlastpixel = (j == jmax);\n\t\t\tGetComponent(*thisptr++, r2, red);\n\t\t\tGetComponent(*thisptr++, g2, green);\n\t\t\tGetComponent(*thisptr++, b2, blue);\n\t\t\toval = histogram[r2][g2][b2];\n\t\t\tif (oval == -1) {\n\t\t\t\tint ci;\n\t\t\t\tregister int cj, tmp, d2, dist;\n\t\t\t\tregister C_cell\t*cell;\n\t\t\t\tcell = *(ColorCells +\n\t\t\t\t (((r2>>(B_DEPTH-C_DEPTH)) << C_DEPTH*2) +\n\t\t\t\t ((g2>>(B_DEPTH-C_DEPTH)) << C_DEPTH ) +\n\t\t\t\t (b2>>(B_DEPTH-C_DEPTH))));\n\t\t\t\tif (cell == NULL)\n\t\t\t\t\tcell = create_colorcell(red,\n\t\t\t\t\t green, blue);\n\t\t\t\tdist = 9999999;\n\t\t\t\tfor (ci = 0; ci < cell->num_ents && dist > cell->entries[ci][1]; ++ci) {\n\t\t\t\t\tcj = cell->entries[ci][0];\n\t\t\t\t\td2 = (rm[cj] >> COLOR_SHIFT) - r2;\n\t\t\t\t\td2 *= d2;\n\t\t\t\t\ttmp = (gm[cj] >> COLOR_SHIFT) - g2;\n\t\t\t\t\td2 += tmp*tmp;\n\t\t\t\t\ttmp = (bm[cj] >> COLOR_SHIFT) - b2;\n\t\t\t\t\td2 += tmp*tmp;\n\t\t\t\t\tif (d2 < dist) {\n\t\t\t\t\t\tdist = d2;\n\t\t\t\t\t\toval = cj;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\thistogram[r2][g2][b2] = oval;\n\t\t\t}\n\t\t\t*outptr++ = oval;\n\t\t\tred -= rm[oval];\n\t\t\tgreen -= gm[oval];\n\t\t\tblue -= bm[oval];\n\t\t\tif (!lastpixel) {\n\t\t\t\tthisptr[0] += blue * 7 / 16;\n\t\t\t\tthisptr[1] += green * 7 / 16;\n\t\t\t\tthisptr[2] += red * 7 / 16;\n\t\t\t}\n\t\t\tif (!lastline) {\n\t\t\t\tif (j != 0) {\n\t\t\t\t\tnextptr[-3] += blue * 3 / 16;\n\t\t\t\t\tnextptr[-2] += green * 3 / 16;\n\t\t\t\t\tnextptr[-1] += red * 3 / 16;\n\t\t\t\t}\n\t\t\t\tnextptr[0] += blue * 5 / 16;\n\t\t\t\tnextptr[1] += green * 5 / 16;\n\t\t\t\tnextptr[2] += red * 5 / 16;\n\t\t\t\tif (!lastpixel) {\n\t\t\t\t\tnextptr[3] += blue / 16;\n\t\t\t\t nextptr[4] += green / 16;\n\t\t\t\t nextptr[5] += red / 16;\n\t\t\t\t}\n\t\t\t\tnextptr += 3;\n\t\t\t}\n\t\t}\n\t\tif (TIFFWriteScanline(out, outline, i-1, 0) < 0)\n\t\t\tbreak;\n\t}\nbad:\n\t_TIFFfree(inputline);\n\t_TIFFfree(thisline);\n\t_TIFFfree(nextline);\n\t_TIFFfree(outline);\n}', 'int\nTIFFWriteScanline(TIFF* tif, void* buf, uint32 row, uint16 sample)\n{\n\tstatic const char module[] = "TIFFWriteScanline";\n\tregister TIFFDirectory *td;\n\tint status, imagegrew = 0;\n\tuint32 strip;\n\tif (!WRITECHECKSTRIPS(tif, module))\n\t\treturn (-1);\n\tif (!BUFFERCHECK(tif))\n\t\treturn (-1);\n tif->tif_flags |= TIFF_BUF4WRITE;\n\ttd = &tif->tif_dir;\n\tif (row >= td->td_imagelength) {\n\t\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Can not change \\"ImageLength\\" when using separate planes");\n\t\t\treturn (-1);\n\t\t}\n\t\ttd->td_imagelength = row+1;\n\t\timagegrew = 1;\n\t}\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE) {\n\t\tif (sample >= td->td_samplesperpixel) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "%lu: Sample out of range, max %lu",\n\t\t\t (unsigned long) sample, (unsigned long) td->td_samplesperpixel);\n\t\t\treturn (-1);\n\t\t}\n\t\tstrip = sample*td->td_stripsperimage + row/td->td_rowsperstrip;\n\t} else\n\t\tstrip = row / td->td_rowsperstrip;\n\tif (strip >= td->td_nstrips && !TIFFGrowStrips(tif, 1, module))\n\t\treturn (-1);\n\tif (strip != tif->tif_curstrip) {\n\t\tif (!TIFFFlushData(tif))\n\t\t\treturn (-1);\n\t\ttif->tif_curstrip = strip;\n\t\tif (strip >= td->td_stripsperimage && imagegrew)\n\t\t\ttd->td_stripsperimage =\n\t\t\t TIFFhowmany_32(td->td_imagelength,td->td_rowsperstrip);\n\t\ttif->tif_row =\n\t\t (strip % td->td_stripsperimage) * td->td_rowsperstrip;\n\t\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\t\tif (!(*tif->tif_setupencode)(tif))\n\t\t\t\treturn (-1);\n\t\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t\t}\n\t\ttif->tif_rawcc = 0;\n\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\tif( td->td_stripbytecount[strip] > 0 )\n\t\t{\n\t\t\ttd->td_stripbytecount[strip] = 0;\n\t\t\ttif->tif_curoff = 0;\n\t\t}\n\t\tif (!(*tif->tif_preencode)(tif, sample))\n\t\t\treturn (-1);\n\t\ttif->tif_flags |= TIFF_POSTENCODE;\n\t}\n\tif (row != tif->tif_row) {\n\t\tif (row < tif->tif_row) {\n\t\t\ttif->tif_row = (strip % td->td_stripsperimage) *\n\t\t\t td->td_rowsperstrip;\n\t\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\t}\n\t\tif (!(*tif->tif_seek)(tif, row - tif->tif_row))\n\t\t\treturn (-1);\n\t\ttif->tif_row = row;\n\t}\n\ttif->tif_postdecode( tif, (uint8*) buf, tif->tif_scanlinesize );\n\tstatus = (*tif->tif_encoderow)(tif, (uint8*) buf,\n\t tif->tif_scanlinesize, sample);\n\ttif->tif_row = row + 1;\n\treturn (status);\n}', 'int\nTIFFWriteCheck(TIFF* tif, int tiles, const char* module)\n{\n\tif (tif->tif_mode == O_RDONLY) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module, "File not open for writing");\n\t\treturn (0);\n\t}\n\tif (tiles ^ isTiled(tif)) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module, tiles ?\n\t\t "Can not write tiles to a stripped image" :\n\t\t "Can not write scanlines to a tiled image");\n\t\treturn (0);\n\t}\n\tif (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "Must set \\"ImageWidth\\" before writing data");\n\t\treturn (0);\n\t}\n\tif (tif->tif_dir.td_samplesperpixel == 1) {\n\t\tif (!TIFFFieldSet(tif, FIELD_PLANARCONFIG))\n tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG;\n\t} else {\n\t\tif (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Must set \\"PlanarConfiguration\\" before writing data");\n\t\t\treturn (0);\n\t\t}\n\t}\n\tif (tif->tif_dir.td_stripoffset == NULL && !TIFFSetupStrips(tif)) {\n\t\ttif->tif_dir.td_nstrips = 0;\n\t\tTIFFErrorExt(tif->tif_clientdata, module, "No space for %s arrays",\n\t\t isTiled(tif) ? "tile" : "strip");\n\t\treturn (0);\n\t}\n\tif (isTiled(tif))\n\t{\n\t\ttif->tif_tilesize = TIFFTileSize(tif);\n\t\tif (tif->tif_tilesize == 0)\n\t\t\treturn (0);\n\t}\n\telse\n\t\ttif->tif_tilesize = (tmsize_t)(-1);\n\ttif->tif_scanlinesize = TIFFScanlineSize(tif);\n\tif (tif->tif_scanlinesize == 0)\n\t\treturn (0);\n\ttif->tif_flags |= TIFF_BEENWRITING;\n\treturn (1);\n}', 'int\nTIFFSetupStrips(TIFF* tif)\n{\n\tTIFFDirectory* td = &tif->tif_dir;\n\tif (isTiled(tif))\n\t\ttd->td_stripsperimage =\n\t\t isUnspecified(tif, FIELD_TILEDIMENSIONS) ?\n\t\t\ttd->td_samplesperpixel : TIFFNumberOfTiles(tif);\n\telse\n\t\ttd->td_stripsperimage =\n\t\t isUnspecified(tif, FIELD_ROWSPERSTRIP) ?\n\t\t\ttd->td_samplesperpixel : TIFFNumberOfStrips(tif);\n\ttd->td_nstrips = td->td_stripsperimage;\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\ttd->td_stripsperimage /= td->td_samplesperpixel;\n\ttd->td_stripoffset = (uint64 *)\n\t _TIFFmalloc(td->td_nstrips * sizeof (uint64));\n\ttd->td_stripbytecount = (uint64 *)\n\t _TIFFmalloc(td->td_nstrips * sizeof (uint64));\n\tif (td->td_stripoffset == NULL || td->td_stripbytecount == NULL)\n\t\treturn (0);\n\t_TIFFmemset(td->td_stripoffset, 0, td->td_nstrips*sizeof (uint64));\n\t_TIFFmemset(td->td_stripbytecount, 0, td->td_nstrips*sizeof (uint64));\n\tTIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);\n\tTIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);\n\treturn (1);\n}', 'uint32\nTIFFNumberOfTiles(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 dx = td->td_tilewidth;\n\tuint32 dy = td->td_tilelength;\n\tuint32 dz = td->td_tiledepth;\n\tuint32 ntiles;\n\tif (dx == (uint32) -1)\n\t\tdx = td->td_imagewidth;\n\tif (dy == (uint32) -1)\n\t\tdy = td->td_imagelength;\n\tif (dz == (uint32) -1)\n\t\tdz = td->td_imagedepth;\n\tntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :\n\t _TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx),\n\t TIFFhowmany_32(td->td_imagelength, dy),\n\t "TIFFNumberOfTiles"),\n\t TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\tntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel,\n\t\t "TIFFNumberOfTiles");\n\treturn (ntiles);\n}']
|
2,769
| 0
|
https://github.com/openssl/openssl/blob/2ac68bd6f14f27504cf9ae86e714030083de732b/crypto/mem.c/#L179
|
void CRYPTO_free(void *str, const char *file, int line)
{
if (free_impl != NULL && free_impl != &CRYPTO_free) {
free_impl(str, file, line);
return;
}
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (call_malloc_debug) {
CRYPTO_mem_debug_free(str, 0, file, line);
free(str);
CRYPTO_mem_debug_free(str, 1, file, line);
} else {
free(str);
}
#else
free(str);
#endif
}
|
['static int tlsa_import_rrset(SSL *con, STACK_OF(OPENSSL_STRING) *rrset)\n{\n int num = sk_OPENSSL_STRING_num(rrset);\n int count = 0;\n int i;\n for (i = 0; i < num; ++i) {\n char *rrdata = sk_OPENSSL_STRING_value(rrset, i);\n if (tlsa_import_rr(con, rrdata) > 0)\n ++count;\n }\n return count > 0;\n}', 'static int tlsa_import_rr(SSL *con, const char *rrdata)\n{\n static uint8_t usage;\n static uint8_t selector;\n static uint8_t mtype;\n static unsigned char *data;\n static struct tlsa_field tlsa_fields[] = {\n { &usage, "usage", checked_uint8 },\n { &selector, "selector", checked_uint8 },\n { &mtype, "mtype", checked_uint8 },\n { &data, "data", hexdecode },\n { NULL, }\n };\n struct tlsa_field *f;\n int ret;\n const char *cp = rrdata;\n ossl_ssize_t len = 0;\n for (f = tlsa_fields; f->var; ++f) {\n if ((len = f->parser(&cp, f->var)) <= 0) {\n BIO_printf(bio_err, "%s: warning: bad TLSA %s field in: %s\\n",\n prog, f->name, rrdata);\n return 0;\n }\n }\n ret = SSL_dane_tlsa_add(con, usage, selector, mtype, data, len);\n OPENSSL_free(data);\n if (ret == 0) {\n ERR_print_errors(bio_err);\n BIO_printf(bio_err, "%s: warning: unusable TLSA rrdata: %s\\n",\n prog, rrdata);\n return 0;\n }\n if (ret < 0) {\n ERR_print_errors(bio_err);\n BIO_printf(bio_err, "%s: warning: error loading TLSA rrdata: %s\\n",\n prog, rrdata);\n return 0;\n }\n return ret;\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
|
2,770
| 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)];
}
|
['static int rsa_ossl_public_encrypt(int flen, const unsigned char *from,\n unsigned char *to, RSA *rsa, int padding)\n{\n BIGNUM *f, *ret;\n int i, j, k, num = 0, r = -1;\n unsigned char *buf = NULL;\n BN_CTX *ctx = NULL;\n if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);\n return -1;\n }\n if (BN_ucmp(rsa->n, rsa->e) <= 0) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);\n return -1;\n }\n if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS) {\n if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);\n return -1;\n }\n }\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n f = BN_CTX_get(ctx);\n ret = BN_CTX_get(ctx);\n num = BN_num_bytes(rsa->n);\n buf = OPENSSL_malloc(num);\n if (ret == NULL || buf == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n switch (padding) {\n case RSA_PKCS1_PADDING:\n i = RSA_padding_add_PKCS1_type_2(buf, num, from, flen);\n break;\n case RSA_PKCS1_OAEP_PADDING:\n i = RSA_padding_add_PKCS1_OAEP(buf, num, from, flen, NULL, 0);\n break;\n case RSA_SSLV23_PADDING:\n i = RSA_padding_add_SSLv23(buf, num, from, flen);\n break;\n case RSA_NO_PADDING:\n i = RSA_padding_add_none(buf, num, from, flen);\n break;\n default:\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE);\n goto err;\n }\n if (i <= 0)\n goto err;\n if (BN_bin2bn(buf, num, f) == NULL)\n goto err;\n if (BN_ucmp(f, rsa->n) >= 0) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT,\n RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n goto err;\n }\n if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n if (!BN_MONT_CTX_set_locked\n (&rsa->_method_mod_n, rsa->lock, rsa->n, ctx))\n goto err;\n if (!rsa->meth->bn_mod_exp(ret, f, rsa->e, rsa->n, ctx,\n rsa->_method_mod_n))\n goto err;\n j = BN_num_bytes(ret);\n i = BN_bn2bin(ret, &(to[num - j]));\n for (k = 0; k < (num - i); k++)\n to[k] = 0;\n r = num;\n err:\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n OPENSSL_clear_free(buf, num);\n return (r);\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock,\n const BIGNUM *mod, BN_CTX *ctx)\n{\n BN_MONT_CTX *ret;\n CRYPTO_THREAD_read_lock(lock);\n ret = *pmont;\n CRYPTO_THREAD_unlock(lock);\n if (ret)\n return ret;\n ret = BN_MONT_CTX_new();\n if (ret == NULL)\n return NULL;\n if (!BN_MONT_CTX_set(ret, mod, ctx)) {\n BN_MONT_CTX_free(ret);\n return NULL;\n }\n CRYPTO_THREAD_write_lock(lock);\n if (*pmont) {\n BN_MONT_CTX_free(ret);\n ret = *pmont;\n } else\n *pmont = ret;\n CRYPTO_THREAD_unlock(lock);\n return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', '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}']
|
2,771
| 0
|
https://github.com/openssl/openssl/blob/02cba628daa7fea959c561531a8a984756bdf41c/crypto/lhash/lhash.c/#L123
|
void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
{
unsigned long hash;
OPENSSL_LH_NODE *nn, **rn;
void *ret;
lh->error = 0;
rn = getrn(lh, data, &hash);
if (*rn == NULL) {
lh->num_no_delete++;
return (NULL);
} else {
nn = *rn;
*rn = nn->next;
ret = nn->data;
OPENSSL_free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
contract(lh);
return (ret);
}
|
['static int execute_test_session(SSL_SESSION_TEST_FIXTURE fix)\n{\n SSL_CTX *sctx = NULL, *cctx = NULL;\n SSL *serverssl1 = NULL, *clientssl1 = NULL;\n SSL *serverssl2 = NULL, *clientssl2 = NULL;\n#ifndef OPENSSL_NO_TLS1_1\n SSL *serverssl3 = NULL, *clientssl3 = NULL;\n#endif\n SSL_SESSION *sess1 = NULL, *sess2 = NULL;\n int testresult = 0;\n if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,\n &cctx, cert, privkey)) {\n printf("Unable to create SSL_CTX pair\\n");\n return 0;\n }\n#ifndef OPENSSL_NO_TLS1_2\n SSL_CTX_set_min_proto_version(cctx, TLS1_2_VERSION);\n#endif\n if (fix.use_ext_cache) {\n SSL_CTX_sess_set_new_cb(cctx, new_session_cb);\n SSL_CTX_sess_set_remove_cb(cctx, remove_session_cb);\n }\n if (fix.use_int_cache) {\n SSL_CTX_set_session_cache_mode(cctx, SSL_SESS_CACHE_CLIENT);\n } else {\n SSL_CTX_set_session_cache_mode(cctx,\n SSL_SESS_CACHE_CLIENT\n | SSL_SESS_CACHE_NO_INTERNAL_STORE);\n }\n if (!create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1, NULL,\n NULL)) {\n printf("Unable to create SSL objects\\n");\n goto end;\n }\n if (!create_ssl_connection(serverssl1, clientssl1)) {\n printf("Unable to create SSL connection\\n");\n goto end;\n }\n sess1 = SSL_get1_session(clientssl1);\n if (sess1 == NULL) {\n printf("Unexpected NULL session\\n");\n goto end;\n }\n if (fix.use_int_cache && SSL_CTX_add_session(cctx, sess1)) {\n printf("Unexpected success adding session to cache\\n");\n goto end;\n }\n if (fix.use_ext_cache && (new_called != 1 || remove_called != 0)) {\n printf("Session not added to cache\\n");\n goto end;\n }\n if (!create_ssl_objects(sctx, cctx, &serverssl2, &clientssl2, NULL, NULL)) {\n printf("Unable to create second SSL objects\\n");\n goto end;\n }\n if (!create_ssl_connection(serverssl2, clientssl2)) {\n printf("Unable to create second SSL connection\\n");\n goto end;\n }\n sess2 = SSL_get1_session(clientssl2);\n if (sess2 == NULL) {\n printf("Unexpected NULL session from clientssl2\\n");\n goto end;\n }\n if (fix.use_ext_cache && (new_called != 2 || remove_called != 0)) {\n printf("Remove session callback unexpectedly called\\n");\n goto end;\n }\n if (!SSL_set_session(clientssl2, sess1)) {\n printf("Unexpected failure setting session\\n");\n goto end;\n }\n if (fix.use_ext_cache && (new_called != 2 || remove_called != 1)) {\n printf("Failed to call callback to remove session\\n");\n goto end;\n }\n if (SSL_get_session(clientssl2) != sess1) {\n printf("Unexpected session found\\n");\n goto end;\n }\n if (fix.use_int_cache) {\n if (!SSL_CTX_add_session(cctx, sess2)) {\n printf("Unexpected failure adding session to cache\\n");\n goto end;\n }\n if (!SSL_CTX_remove_session(cctx, sess2)) {\n printf("Unexpected failure removing session from cache\\n");\n goto end;\n }\n if (fix.use_ext_cache)\n remove_called--;\n }\n if (SSL_CTX_remove_session(cctx, sess2)) {\n printf("Unexpected success removing session from cache\\n");\n goto end;\n }\n if (fix.use_ext_cache && (new_called != 2 || remove_called != 2)) {\n printf("Failed to call callback to remove session #2\\n");\n goto end;\n }\n#if !defined(OPENSSL_NO_TLS1_1) && !defined(OPENSSL_NO_TLS1_2)\n SSL_CTX_set_max_proto_version(sctx, TLS1_1_VERSION);\n if (!create_ssl_objects(sctx, cctx, &serverssl3, &clientssl3, NULL, NULL)) {\n printf("Unable to create third SSL objects\\n");\n goto end;\n }\n if (!SSL_set_session(clientssl3, sess1)) {\n printf("Unable to set session for third connection\\n");\n goto end;\n }\n if (create_ssl_connection(serverssl3, clientssl3)) {\n printf("Unable to create third SSL connection\\n");\n goto end;\n }\n if (fix.use_ext_cache && (new_called != 2 || remove_called != 3)) {\n printf("Failed to call callback to remove session #2\\n");\n goto end;\n }\n if (fix.use_int_cache && !SSL_CTX_add_session(cctx, sess2)) {\n printf("Unexpected failure adding session to cache #2\\n");\n goto end;\n }\n#endif\n testresult = 1;\n end:\n SSL_free(serverssl1);\n SSL_free(clientssl1);\n SSL_free(serverssl2);\n SSL_free(clientssl2);\n#ifndef OPENSSL_NO_TLS1_1\n SSL_free(serverssl3);\n SSL_free(clientssl3);\n#endif\n SSL_SESSION_free(sess1);\n SSL_SESSION_free(sess2);\n if (new_called >= 1)\n SSL_SESSION_free(sess1);\n if (new_called >= 2)\n SSL_SESSION_free(sess2);\n SSL_CTX_free(sctx);\n SSL_CTX_free(cctx);\n return testresult;\n}', 'int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,\n SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)\n{\n SSL *serverssl, *clientssl;\n BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;\n if (*sssl == NULL)\n serverssl = SSL_new(serverctx);\n else\n serverssl = *sssl;\n if (*cssl == NULL)\n clientssl = SSL_new(clientctx);\n else\n clientssl = *cssl;\n if (serverssl == NULL || clientssl == NULL) {\n printf("Failed to create SSL object\\n");\n goto error;\n }\n if (SSL_is_dtls(clientssl)) {\n s_to_c_bio = BIO_new(bio_s_mempacket_test());\n c_to_s_bio = BIO_new(bio_s_mempacket_test());\n } else {\n s_to_c_bio = BIO_new(BIO_s_mem());\n c_to_s_bio = BIO_new(BIO_s_mem());\n }\n if (s_to_c_bio == NULL || c_to_s_bio == NULL) {\n printf("Failed to create mem BIOs\\n");\n goto error;\n }\n if (s_to_c_fbio != NULL)\n s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio);\n if (c_to_s_fbio != NULL)\n c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio);\n if (s_to_c_bio == NULL || c_to_s_bio == NULL) {\n printf("Failed to create chained BIOs\\n");\n goto error;\n }\n BIO_set_mem_eof_return(s_to_c_bio, -1);\n BIO_set_mem_eof_return(c_to_s_bio, -1);\n BIO_up_ref(s_to_c_bio);\n BIO_up_ref(c_to_s_bio);\n SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);\n SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);\n s_to_c_bio = c_to_s_bio = NULL;\n s_to_c_fbio = c_to_s_fbio = NULL;\n *sssl = serverssl;\n *cssl = clientssl;\n return 1;\n error:\n SSL_free(serverssl);\n SSL_free(clientssl);\n BIO_free(s_to_c_bio);\n BIO_free(c_to_s_bio);\n BIO_free(s_to_c_fbio);\n BIO_free(c_to_s_fbio);\n return 0;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return (NULL);\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return (NULL);\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL) {\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(s);\n return NULL;\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->dane.flags = ctx->dane.flags;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->references = 1;\n s->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->sid_ctx_length = ctx->sid_ctx_length;\n OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->ext.debug_cb = 0;\n s->ext.debug_arg = NULL;\n s->ext.ticket_expected = 0;\n s->ext.status_type = ctx->ext.status_type;\n s->ext.status_expected = 0;\n s->ext.ocsp.ids = NULL;\n s->ext.ocsp.exts = NULL;\n s->ext.ocsp.resp = NULL;\n s->ext.ocsp.resp_len = 0;\n SSL_CTX_up_ref(ctx);\n s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n if (ctx->ext.ecpointformats) {\n s->ext.ecpointformats =\n OPENSSL_memdup(ctx->ext.ecpointformats,\n ctx->ext.ecpointformats_len);\n if (!s->ext.ecpointformats)\n goto err;\n s->ext.ecpointformats_len =\n ctx->ext.ecpointformats_len;\n }\n if (ctx->ext.supportedgroups) {\n s->ext.supportedgroups =\n OPENSSL_memdup(ctx->ext.supportedgroups,\n ctx->ext.supportedgroups_len);\n if (!s->ext.supportedgroups)\n goto err;\n s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n s->ext.npn = NULL;\n#endif\n if (s->ctx->ext.alpn) {\n s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n if (s->ext.alpn == NULL)\n goto err;\n memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n s->ext.alpn_len = s->ctx->ext.alpn_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'int SSL_set_session(SSL *s, SSL_SESSION *session)\n{\n ssl_clear_bad_session(s);\n if (s->ctx->method != s->method) {\n if (!SSL_set_ssl_method(s, s->ctx->method))\n return 0;\n }\n if (session != NULL) {\n SSL_SESSION_up_ref(session);\n s->verify_result = session->verify_result;\n }\n SSL_SESSION_free(s->session);\n s->session = session;\n return 1;\n}', 'int ssl_clear_bad_session(SSL *s)\n{\n if ((s->session != NULL) &&\n !(s->shutdown & SSL_SENT_SHUTDOWN) &&\n !(SSL_in_init(s) || SSL_in_before(s))) {\n SSL_CTX_remove_session(s->session_ctx, s->session);\n return (1);\n } else\n return (0);\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_THREAD_write_lock(ctx->lock);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, c);\n SSL_SESSION_list_remove(ctx, c);\n }\n c->not_resumable = 1;\n if (lck)\n CRYPTO_THREAD_unlock(ctx->lock);\n if (ret)\n SSL_SESSION_free(r);\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, c);\n } else\n ret = 0;\n return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n unsigned long hash;\n OPENSSL_LH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return (NULL);\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return (ret);\n}']
|
2,772
| 0
|
https://github.com/openssl/openssl/blob/388de53c274dee20c07eee7ff892108668fb3a61/test/evp_test.c/#L1591
|
static int pbe_test_init(EVP_TEST *t, const char *alg)
{
PBE_DATA *pdat;
PBE_TYPE pbe_type = PBE_TYPE_INVALID;
if (strcmp(alg, "scrypt") == 0) {
#ifndef OPENSSL_NO_SCRYPT
pbe_type = PBE_TYPE_SCRYPT;
#else
t->skip = 1;
return 1;
#endif
} else if (strcmp(alg, "pbkdf2") == 0) {
pbe_type = PBE_TYPE_PBKDF2;
} else if (strcmp(alg, "pkcs12") == 0) {
pbe_type = PBE_TYPE_PKCS12;
} else {
TEST_error("Unknown pbe algorithm %s", alg);
}
pdat = OPENSSL_zalloc(sizeof(*pdat));
pdat->pbe_type = pbe_type;
t->data = pdat;
return 1;
}
|
['static int pbe_test_init(EVP_TEST *t, const char *alg)\n{\n PBE_DATA *pdat;\n PBE_TYPE pbe_type = PBE_TYPE_INVALID;\n if (strcmp(alg, "scrypt") == 0) {\n#ifndef OPENSSL_NO_SCRYPT\n pbe_type = PBE_TYPE_SCRYPT;\n#else\n t->skip = 1;\n return 1;\n#endif\n } else if (strcmp(alg, "pbkdf2") == 0) {\n pbe_type = PBE_TYPE_PBKDF2;\n } else if (strcmp(alg, "pkcs12") == 0) {\n pbe_type = PBE_TYPE_PKCS12;\n } else {\n TEST_error("Unknown pbe algorithm %s", alg);\n }\n pdat = OPENSSL_zalloc(sizeof(*pdat));\n pdat->pbe_type = pbe_type;\n t->data = pdat;\n return 1;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
2,773
| 0
|
https://github.com/nginx/nginx/blob/e4ecddfdb0d2ffc872658e36028971ad9a873726/src/core/ngx_string.c/#L244
|
u_char *
ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)
{
u_char *p, zero, *last;
int d;
float f, scale;
size_t len, slen;
int64_t i64;
uint64_t ui64;
ngx_msec_t ms;
ngx_uint_t width, sign, hex, max_width, frac_width, i;
ngx_str_t *v;
ngx_variable_value_t *vv;
if (max == 0) {
return buf;
}
last = buf + max;
while (*fmt && buf < last) {
if (*fmt == '%') {
i64 = 0;
ui64 = 0;
zero = (u_char) ((*++fmt == '0') ? '0' : ' ');
width = 0;
sign = 1;
hex = 0;
max_width = 0;
frac_width = 0;
slen = (size_t) -1;
while (*fmt >= '0' && *fmt <= '9') {
width = width * 10 + *fmt++ - '0';
}
for ( ;; ) {
switch (*fmt) {
case 'u':
sign = 0;
fmt++;
continue;
case 'm':
max_width = 1;
fmt++;
continue;
case 'X':
hex = 2;
sign = 0;
fmt++;
continue;
case 'x':
hex = 1;
sign = 0;
fmt++;
continue;
case '.':
fmt++;
while (*fmt >= '0' && *fmt <= '9') {
frac_width = frac_width * 10 + *fmt++ - '0';
}
break;
case '*':
slen = va_arg(args, size_t);
fmt++;
continue;
default:
break;
}
break;
}
switch (*fmt) {
case 'V':
v = va_arg(args, ngx_str_t *);
len = v->len;
len = (buf + len < last) ? len : (size_t) (last - buf);
buf = ngx_cpymem(buf, v->data, len);
fmt++;
continue;
case 'v':
vv = va_arg(args, ngx_variable_value_t *);
len = vv->len;
len = (buf + len < last) ? len : (size_t) (last - buf);
buf = ngx_cpymem(buf, vv->data, len);
fmt++;
continue;
case 's':
p = va_arg(args, u_char *);
if (slen == (size_t) -1) {
while (*p && buf < last) {
*buf++ = *p++;
}
} else {
len = (buf + slen < last) ? slen : (size_t) (last - buf);
buf = ngx_cpymem(buf, p, len);
}
fmt++;
continue;
case 'O':
i64 = (int64_t) va_arg(args, off_t);
sign = 1;
break;
case 'P':
i64 = (int64_t) va_arg(args, ngx_pid_t);
sign = 1;
break;
case 'T':
i64 = (int64_t) va_arg(args, time_t);
sign = 1;
break;
case 'M':
ms = (ngx_msec_t) va_arg(args, ngx_msec_t);
if ((ngx_msec_int_t) ms == -1) {
sign = 1;
i64 = -1;
} else {
sign = 0;
ui64 = (uint64_t) ms;
}
break;
case 'z':
if (sign) {
i64 = (int64_t) va_arg(args, ssize_t);
} else {
ui64 = (uint64_t) va_arg(args, size_t);
}
break;
case 'i':
if (sign) {
i64 = (int64_t) va_arg(args, ngx_int_t);
} else {
ui64 = (uint64_t) va_arg(args, ngx_uint_t);
}
if (max_width) {
width = NGX_INT_T_LEN;
}
break;
case 'd':
if (sign) {
i64 = (int64_t) va_arg(args, int);
} else {
ui64 = (uint64_t) va_arg(args, u_int);
}
break;
case 'l':
if (sign) {
i64 = (int64_t) va_arg(args, long);
} else {
ui64 = (uint64_t) va_arg(args, u_long);
}
break;
case 'D':
if (sign) {
i64 = (int64_t) va_arg(args, int32_t);
} else {
ui64 = (uint64_t) va_arg(args, uint32_t);
}
break;
case 'L':
if (sign) {
i64 = va_arg(args, int64_t);
} else {
ui64 = va_arg(args, uint64_t);
}
break;
case 'A':
if (sign) {
i64 = (int64_t) va_arg(args, ngx_atomic_int_t);
} else {
ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);
}
if (max_width) {
width = NGX_ATOMIC_T_LEN;
}
break;
case 'f':
f = (float) va_arg(args, double);
if (f < 0) {
*buf++ = '-';
f = -f;
}
ui64 = (int64_t) f;
buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);
if (frac_width) {
if (buf < last) {
*buf++ = '.';
}
scale = 1.0;
for (i = 0; i < frac_width; i++) {
scale *= 10.0;
}
ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);
buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);
}
fmt++;
continue;
#if !(NGX_WIN32)
case 'r':
i64 = (int64_t) va_arg(args, rlim_t);
sign = 1;
break;
#endif
case 'p':
ui64 = (uintptr_t) va_arg(args, void *);
hex = 2;
sign = 0;
zero = '0';
width = NGX_PTR_SIZE * 2;
break;
case 'c':
d = va_arg(args, int);
*buf++ = (u_char) (d & 0xff);
fmt++;
continue;
case 'Z':
*buf++ = '\0';
fmt++;
continue;
case 'N':
#if (NGX_WIN32)
*buf++ = CR;
#endif
*buf++ = LF;
fmt++;
continue;
case '%':
*buf++ = '%';
fmt++;
continue;
default:
*buf++ = *fmt++;
continue;
}
if (sign) {
if (i64 < 0) {
*buf++ = '-';
ui64 = (uint64_t) -i64;
} else {
ui64 = (uint64_t) i64;
}
}
buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);
fmt++;
} else {
*buf++ = *fmt++;
}
}
return buf;
}
|
['ngx_int_t\nngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in)\n{\n off_t bsize;\n ngx_int_t rc, last;\n ngx_chain_t *cl, *out, **last_out;\n if (ctx->in == NULL && ctx->busy == NULL) {\n if (in == NULL) {\n return ctx->output_filter(ctx->filter_ctx, in);\n }\n if (in->next == NULL\n#if (NGX_SENDFILE_LIMIT)\n && !(in->buf->in_file && in->buf->file_last > NGX_SENDFILE_LIMIT)\n#endif\n && ngx_output_chain_as_is(ctx, in->buf))\n {\n return ctx->output_filter(ctx->filter_ctx, in);\n }\n }\n if (in) {\n if (ngx_output_chain_add_copy(ctx->pool, &ctx->in, in) == NGX_ERROR) {\n return NGX_ERROR;\n }\n }\n out = NULL;\n last_out = &out;\n last = NGX_NONE;\n for ( ;; ) {\n while (ctx->in) {\n bsize = ngx_buf_size(ctx->in->buf);\n if (bsize == 0 && !ngx_buf_special(ctx->in->buf)) {\n ngx_log_error(NGX_LOG_ALERT, ctx->pool->log, 0,\n "zero size buf in output "\n "t:%d r:%d f:%d %p %p-%p %p %O-%O",\n ctx->in->buf->temporary,\n ctx->in->buf->recycled,\n ctx->in->buf->in_file,\n ctx->in->buf->start,\n ctx->in->buf->pos,\n ctx->in->buf->last,\n ctx->in->buf->file,\n ctx->in->buf->file_pos,\n ctx->in->buf->file_last);\n ngx_debug_point();\n ctx->in = ctx->in->next;\n continue;\n }\n if (ngx_output_chain_as_is(ctx, ctx->in->buf)) {\n cl = ctx->in;\n ctx->in = cl->next;\n *last_out = cl;\n last_out = &cl->next;\n cl->next = NULL;\n continue;\n }\n if (ctx->buf == NULL) {\n rc = ngx_output_chain_align_file_buf(ctx, bsize);\n if (rc == NGX_ERROR) {\n return NGX_ERROR;\n }\n if (rc != NGX_OK) {\n if (ctx->free) {\n cl = ctx->free;\n ctx->buf = cl->buf;\n ctx->free = cl->next;\n ngx_free_chain(ctx->pool, cl);\n } else if (out || ctx->allocated == ctx->bufs.num) {\n break;\n } else if (ngx_output_chain_get_buf(ctx, bsize) != NGX_OK) {\n return NGX_ERROR;\n }\n }\n }\n rc = ngx_output_chain_copy_buf(ctx);\n if (rc == NGX_ERROR) {\n return rc;\n }\n if (rc == NGX_AGAIN) {\n if (out) {\n break;\n }\n return rc;\n }\n if (ngx_buf_size(ctx->in->buf) == 0) {\n ctx->in = ctx->in->next;\n }\n cl = ngx_alloc_chain_link(ctx->pool);\n if (cl == NULL) {\n return NGX_ERROR;\n }\n cl->buf = ctx->buf;\n cl->next = NULL;\n *last_out = cl;\n last_out = &cl->next;\n ctx->buf = NULL;\n }\n if (out == NULL && last != NGX_NONE) {\n if (ctx->in) {\n return NGX_AGAIN;\n }\n return last;\n }\n last = ctx->output_filter(ctx->filter_ctx, out);\n if (last == NGX_ERROR || last == NGX_DONE) {\n return last;\n }\n ngx_chain_update_chains(&ctx->free, &ctx->busy, &out, ctx->tag);\n last_out = &out;\n }\n}', 'void\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, ...)\n#else\nvoid\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, va_list args)\n#endif\n{\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_list args;\n#endif\n u_char errstr[NGX_MAX_ERROR_STR], *p, *last;\n if (log->file->fd == NGX_INVALID_FILE) {\n return;\n }\n last = errstr + NGX_MAX_ERROR_STR;\n ngx_memcpy(errstr, ngx_cached_err_log_time.data,\n ngx_cached_err_log_time.len);\n p = errstr + ngx_cached_err_log_time.len;\n p = ngx_snprintf(p, last - p, " [%s] ", err_levels[level]);\n p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ",\n ngx_log_pid, ngx_log_tid);\n if (log->connection) {\n p = ngx_snprintf(p, last - p, "*%uA ", log->connection);\n }\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_start(args, fmt);\n p = ngx_vsnprintf(p, last - p, fmt, args);\n va_end(args);\n#else\n p = ngx_vsnprintf(p, last - p, fmt, args);\n#endif\n if (err) {\n if (p > last - 50) {\n p = last - 50;\n *p++ = \'.\';\n *p++ = \'.\';\n *p++ = \'.\';\n }\n#if (NGX_WIN32)\n p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)\n ? " (%d: " : " (%Xd: ", err);\n#else\n p = ngx_snprintf(p, last - p, " (%d: ", err);\n#endif\n p = ngx_strerror_r(err, p, last - p);\n if (p < last) {\n *p++ = \')\';\n }\n }\n if (level != NGX_LOG_DEBUG && log->handler) {\n p = log->handler(log, p, last - p);\n }\n if (p > last - NGX_LINEFEED_SIZE) {\n p = last - NGX_LINEFEED_SIZE;\n }\n ngx_linefeed(p);\n (void) ngx_write_fd(log->file->fd, errstr, p - errstr);\n}', 'u_char * ngx_cdecl\nngx_snprintf(u_char *buf, size_t max, const char *fmt, ...)\n{\n u_char *p;\n va_list args;\n va_start(args, fmt);\n p = ngx_vsnprintf(buf, max, fmt, args);\n va_end(args);\n return p;\n}', "u_char *\nngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)\n{\n u_char *p, zero, *last;\n int d;\n float f, scale;\n size_t len, slen;\n int64_t i64;\n uint64_t ui64;\n ngx_msec_t ms;\n ngx_uint_t width, sign, hex, max_width, frac_width, i;\n ngx_str_t *v;\n ngx_variable_value_t *vv;\n if (max == 0) {\n return buf;\n }\n last = buf + max;\n while (*fmt && buf < last) {\n if (*fmt == '%') {\n i64 = 0;\n ui64 = 0;\n zero = (u_char) ((*++fmt == '0') ? '0' : ' ');\n width = 0;\n sign = 1;\n hex = 0;\n max_width = 0;\n frac_width = 0;\n slen = (size_t) -1;\n while (*fmt >= '0' && *fmt <= '9') {\n width = width * 10 + *fmt++ - '0';\n }\n for ( ;; ) {\n switch (*fmt) {\n case 'u':\n sign = 0;\n fmt++;\n continue;\n case 'm':\n max_width = 1;\n fmt++;\n continue;\n case 'X':\n hex = 2;\n sign = 0;\n fmt++;\n continue;\n case 'x':\n hex = 1;\n sign = 0;\n fmt++;\n continue;\n case '.':\n fmt++;\n while (*fmt >= '0' && *fmt <= '9') {\n frac_width = frac_width * 10 + *fmt++ - '0';\n }\n break;\n case '*':\n slen = va_arg(args, size_t);\n fmt++;\n continue;\n default:\n break;\n }\n break;\n }\n switch (*fmt) {\n case 'V':\n v = va_arg(args, ngx_str_t *);\n len = v->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, v->data, len);\n fmt++;\n continue;\n case 'v':\n vv = va_arg(args, ngx_variable_value_t *);\n len = vv->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, vv->data, len);\n fmt++;\n continue;\n case 's':\n p = va_arg(args, u_char *);\n if (slen == (size_t) -1) {\n while (*p && buf < last) {\n *buf++ = *p++;\n }\n } else {\n len = (buf + slen < last) ? slen : (size_t) (last - buf);\n buf = ngx_cpymem(buf, p, len);\n }\n fmt++;\n continue;\n case 'O':\n i64 = (int64_t) va_arg(args, off_t);\n sign = 1;\n break;\n case 'P':\n i64 = (int64_t) va_arg(args, ngx_pid_t);\n sign = 1;\n break;\n case 'T':\n i64 = (int64_t) va_arg(args, time_t);\n sign = 1;\n break;\n case 'M':\n ms = (ngx_msec_t) va_arg(args, ngx_msec_t);\n if ((ngx_msec_int_t) ms == -1) {\n sign = 1;\n i64 = -1;\n } else {\n sign = 0;\n ui64 = (uint64_t) ms;\n }\n break;\n case 'z':\n if (sign) {\n i64 = (int64_t) va_arg(args, ssize_t);\n } else {\n ui64 = (uint64_t) va_arg(args, size_t);\n }\n break;\n case 'i':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_uint_t);\n }\n if (max_width) {\n width = NGX_INT_T_LEN;\n }\n break;\n case 'd':\n if (sign) {\n i64 = (int64_t) va_arg(args, int);\n } else {\n ui64 = (uint64_t) va_arg(args, u_int);\n }\n break;\n case 'l':\n if (sign) {\n i64 = (int64_t) va_arg(args, long);\n } else {\n ui64 = (uint64_t) va_arg(args, u_long);\n }\n break;\n case 'D':\n if (sign) {\n i64 = (int64_t) va_arg(args, int32_t);\n } else {\n ui64 = (uint64_t) va_arg(args, uint32_t);\n }\n break;\n case 'L':\n if (sign) {\n i64 = va_arg(args, int64_t);\n } else {\n ui64 = va_arg(args, uint64_t);\n }\n break;\n case 'A':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_atomic_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);\n }\n if (max_width) {\n width = NGX_ATOMIC_T_LEN;\n }\n break;\n case 'f':\n f = (float) va_arg(args, double);\n if (f < 0) {\n *buf++ = '-';\n f = -f;\n }\n ui64 = (int64_t) f;\n buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);\n if (frac_width) {\n if (buf < last) {\n *buf++ = '.';\n }\n scale = 1.0;\n for (i = 0; i < frac_width; i++) {\n scale *= 10.0;\n }\n ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);\n buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);\n }\n fmt++;\n continue;\n#if !(NGX_WIN32)\n case 'r':\n i64 = (int64_t) va_arg(args, rlim_t);\n sign = 1;\n break;\n#endif\n case 'p':\n ui64 = (uintptr_t) va_arg(args, void *);\n hex = 2;\n sign = 0;\n zero = '0';\n width = NGX_PTR_SIZE * 2;\n break;\n case 'c':\n d = va_arg(args, int);\n *buf++ = (u_char) (d & 0xff);\n fmt++;\n continue;\n case 'Z':\n *buf++ = '\\0';\n fmt++;\n continue;\n case 'N':\n#if (NGX_WIN32)\n *buf++ = CR;\n#endif\n *buf++ = LF;\n fmt++;\n continue;\n case '%':\n *buf++ = '%';\n fmt++;\n continue;\n default:\n *buf++ = *fmt++;\n continue;\n }\n if (sign) {\n if (i64 < 0) {\n *buf++ = '-';\n ui64 = (uint64_t) -i64;\n } else {\n ui64 = (uint64_t) i64;\n }\n }\n buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);\n fmt++;\n } else {\n *buf++ = *fmt++;\n }\n }\n return buf;\n}"]
|
2,774
| 0
|
https://github.com/openssl/openssl/blob/5cc977619181d5dd68fba7ec6e185550f824a6db/ssl/packet_locl.h/#L36
|
static ossl_inline void packet_forward(PACKET *pkt, size_t len)
{
pkt->curr += len;
pkt->remaining -= len;
}
|
['static int test_client_hello(int currtest)\n{\n SSL_CTX *ctx;\n SSL *con = NULL;\n BIO *rbio;\n BIO *wbio;\n long len;\n unsigned char *data;\n PACKET pkt = {0}, pkt2 = {0}, pkt3 = {0};\n char *dummytick = "Hello World!";\n unsigned int type = 0;\n int testresult = 0;\n size_t msglen;\n BIO *sessbio = NULL;\n SSL_SESSION *sess = NULL;\n#ifdef OPENSSL_NO_TLS1_3\n if (currtest == TEST_ADD_PADDING_AND_PSK)\n return 1;\n#endif\n ctx = SSL_CTX_new(TLS_method());\n if (!TEST_ptr(ctx))\n goto end;\n switch(currtest) {\n case TEST_SET_SESSION_TICK_DATA_VER_NEG:\n if (!TEST_true(SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION)))\n goto end;\n break;\n case TEST_ADD_PADDING_AND_PSK:\n case TEST_ADD_PADDING:\n case TEST_PADDING_NOT_NEEDED:\n SSL_CTX_set_options(ctx, SSL_OP_TLSEXT_PADDING);\n if (currtest == TEST_ADD_PADDING\n && (!TEST_true(SSL_CTX_set_cipher_list(ctx, "ALL"))\n || !TEST_false(SSL_CTX_set_alpn_protos(ctx,\n (unsigned char *)alpn_prots,\n sizeof(alpn_prots) - 1))))\n goto end;\n break;\n default:\n goto end;\n }\n con = SSL_new(ctx);\n if (!TEST_ptr(con))\n goto end;\n if (currtest == TEST_ADD_PADDING_AND_PSK) {\n sessbio = BIO_new_file(sessionfile, "r");\n if (!TEST_ptr(sessbio)) {\n TEST_info("Unable to open session.pem");\n goto end;\n }\n sess = PEM_read_bio_SSL_SESSION(sessbio, NULL, NULL, NULL);\n if (!TEST_ptr(sess)) {\n TEST_info("Unable to load SSL_SESSION");\n goto end;\n }\n if (!TEST_true(SSL_SESSION_set_time(sess, time(NULL)))\n || !TEST_true(SSL_set_session(con, sess)))\n goto end;\n }\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_connect_state(con);\n if (currtest == TEST_SET_SESSION_TICK_DATA_VER_NEG) {\n if (!TEST_true(SSL_set_session_ticket_ext(con, dummytick,\n strlen(dummytick))))\n goto end;\n }\n if (!TEST_int_le(SSL_connect(con), 0)) {\n goto end;\n }\n len = BIO_get_mem_data(wbio, (char **)&data);\n if (!TEST_true(PACKET_buf_init(&pkt, data, len))\n || !PACKET_forward(&pkt, SSL3_RT_HEADER_LENGTH))\n goto end;\n msglen = PACKET_remaining(&pkt);\n if (!TEST_true(PACKET_forward(&pkt, SSL3_HM_HEADER_LENGTH))\n || !TEST_true(PACKET_forward(&pkt, CLIENT_VERSION_LEN\n + SSL3_RANDOM_SIZE))\n || !TEST_true(PACKET_get_length_prefixed_1(&pkt, &pkt2))\n || !TEST_true(PACKET_get_length_prefixed_2(&pkt, &pkt2))\n || !TEST_true(PACKET_get_length_prefixed_1(&pkt, &pkt2))\n || !TEST_true(PACKET_as_length_prefixed_2(&pkt, &pkt2)))\n goto end;\n while (PACKET_remaining(&pkt2)) {\n if (!TEST_true(PACKET_get_net_2(&pkt2, &type))\n || !TEST_true(PACKET_get_length_prefixed_2(&pkt2, &pkt3)))\n goto end;\n if (type == TLSEXT_TYPE_session_ticket) {\n if (currtest == TEST_SET_SESSION_TICK_DATA_VER_NEG) {\n if (TEST_true(PACKET_equal(&pkt3, dummytick,\n strlen(dummytick)))) {\n testresult = 1;\n }\n goto end;\n }\n }\n if (type == TLSEXT_TYPE_padding) {\n if (!TEST_false(currtest == TEST_PADDING_NOT_NEEDED))\n goto end;\n else if (TEST_true(currtest == TEST_ADD_PADDING\n || currtest == TEST_ADD_PADDING_AND_PSK))\n testresult = TEST_true(msglen == F5_WORKAROUND_MAX_MSG_LEN);\n }\n }\n if (currtest == TEST_PADDING_NOT_NEEDED)\n testresult = 1;\nend:\n SSL_free(con);\n SSL_CTX_free(ctx);\n SSL_SESSION_free(sess);\n BIO_free(sessbio);\n return testresult;\n}', 'static ossl_inline int PACKET_buf_init(PACKET *pkt,\n const unsigned char *buf,\n size_t len)\n{\n if (len > (size_t)(SIZE_MAX / 2))\n return 0;\n pkt->curr = buf;\n pkt->remaining = len;\n return 1;\n}', 'static ossl_inline int PACKET_forward(PACKET *pkt, size_t len)\n{\n if (PACKET_remaining(pkt) < len)\n return 0;\n packet_forward(pkt, len);\n return 1;\n}', 'static ossl_inline void packet_forward(PACKET *pkt, size_t len)\n{\n pkt->curr += len;\n pkt->remaining -= len;\n}']
|
2,775
| 0
|
https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/crypto/bn/bn_blind.c/#L168
|
BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod)
{
BN_BLINDING *ret = NULL;
bn_check_top(mod);
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {
BNerr(BN_F_BN_BLINDING_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
}
if (A != NULL) {
if ((ret->A = BN_dup(A)) == NULL)
goto err;
}
if (Ai != NULL) {
if ((ret->Ai = BN_dup(Ai)) == NULL)
goto err;
}
if ((ret->mod = BN_dup(mod)) == NULL)
goto err;
if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)
BN_set_flags(ret->mod, BN_FLG_CONSTTIME);
ret->counter = -1;
CRYPTO_THREADID_current(&ret->tid);
return (ret);
err:
BN_BLINDING_free(ret);
return (NULL);
}
|
['BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod)\n{\n BN_BLINDING *ret = NULL;\n bn_check_top(mod);\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n BNerr(BN_F_BN_BLINDING_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n if (A != NULL) {\n if ((ret->A = BN_dup(A)) == NULL)\n goto err;\n }\n if (Ai != NULL) {\n if ((ret->Ai = BN_dup(Ai)) == NULL)\n goto err;\n }\n if ((ret->mod = BN_dup(mod)) == NULL)\n goto err;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(ret->mod, BN_FLG_CONSTTIME);\n ret->counter = -1;\n CRYPTO_THREADID_current(&ret->tid);\n return (ret);\n err:\n BN_BLINDING_free(ret);\n return (NULL);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'BIGNUM *BN_dup(const BIGNUM *a)\n{\n BIGNUM *t;\n if (a == NULL)\n return NULL;\n bn_check_top(a);\n t = BN_get_flags(a, BN_FLG_SECURE) ? BN_secure_new() : BN_new();\n if (t == NULL)\n return NULL;\n if (!BN_copy(t, a)) {\n BN_free(t);\n return NULL;\n }\n bn_check_top(t);\n return t;\n}', 'int BN_get_flags(const BIGNUM *b, int n)\n{\n return b->flags & n;\n}', 'BIGNUM *BN_new(void)\n{\n BIGNUM *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->flags = BN_FLG_MALLOCED;\n bn_check_top(ret);\n return (ret);\n}']
|
2,776
| 0
|
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_lib.c/#L250
|
int BN_num_bits(const BIGNUM *a)
{
int i = a->top - 1;
bn_check_top(a);
if (BN_is_zero(a)) return 0;
return ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));
}
|
['int test_exp(BIO *bp, BN_CTX *ctx)\n\t{\n\tBIGNUM *a,*b,*d,*e,*one;\n\tint i;\n\ta=BN_new();\n\tb=BN_new();\n\td=BN_new();\n\te=BN_new();\n\tone=BN_new();\n\tBN_one(one);\n\tfor (i=0; i<num2; i++)\n\t\t{\n\t\tBN_bntest_rand(a,20+i*5,0,0);\n\t\tBN_bntest_rand(b,2+i,0,0);\n\t\tif (!BN_exp(d,a,b,ctx))\n\t\t\treturn(00);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,a);\n\t\t\t\tBIO_puts(bp," ^ ");\n\t\t\t\tBN_print(bp,b);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,d);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\tBN_one(e);\n\t\tfor( ; !BN_is_zero(b) ; BN_sub(b,b,one))\n\t\t BN_mul(e,e,a,ctx);\n\t\tBN_sub(e,e,d);\n\t\tif(!BN_is_zero(e))\n\t\t {\n\t\t fprintf(stderr,"Exponentiation test failed!\\n");\n\t\t return 0;\n\t\t }\n\t\t}\n\tBN_free(a);\n\tBN_free(b);\n\tBN_free(d);\n\tBN_free(e);\n\tBN_free(one);\n\treturn(1);\n\t}', 'int BN_bntest_rand(BIGNUM *rnd, size_t bits, int top, int bottom)\n\t{\n\treturn bnrand(2, rnd, bits, top, bottom);\n\t}', 'static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)\n\t{\n\tunsigned char *buf=NULL;\n\tint ret=0,bit,bytes,mask;\n\ttime_t tim;\n\tif (bits == 0)\n\t\t{\n\t\tBN_zero(rnd);\n\t\treturn 1;\n\t\t}\n\tbytes=(bits+7)/8;\n\tbit=(bits-1)%8;\n\tmask=0xff<<(bit+1);\n\tbuf=(unsigned char *)OPENSSL_malloc(bytes);\n\tif (buf == NULL)\n\t\t{\n\t\tBNerr(BN_F_BNRAND,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\ttime(&tim);\n\tRAND_add(&tim,sizeof(tim),0.0);\n\tif (pseudorand)\n\t\t{\n\t\tif (RAND_pseudo_bytes(buf, bytes) == -1)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (RAND_bytes(buf, bytes) <= 0)\n\t\t\tgoto err;\n\t\t}\n#if 1\n\tif (pseudorand == 2)\n\t\t{\n\t\tint i;\n\t\tunsigned char c;\n\t\tfor (i = 0; i < bytes; i++)\n\t\t\t{\n\t\t\tRAND_pseudo_bytes(&c, 1);\n\t\t\tif (c >= 128 && i > 0)\n\t\t\t\tbuf[i] = buf[i-1];\n\t\t\telse if (c < 42)\n\t\t\t\tbuf[i] = 0;\n\t\t\telse if (c < 84)\n\t\t\t\tbuf[i] = 255;\n\t\t\t}\n\t\t}\n#endif\n\tif (top != -1)\n\t\t{\n\t\tif (top)\n\t\t\t{\n\t\t\tif (bit == 0)\n\t\t\t\t{\n\t\t\t\tbuf[0]=1;\n\t\t\t\tbuf[1]|=0x80;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tbuf[0]|=(3<<(bit-1));\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbuf[0]|=(1<<bit);\n\t\t\t}\n\t\t}\n\tbuf[0] &= ~mask;\n\tif (bottom)\n\t\tbuf[bytes-1]|=1;\n\tif (!BN_bin2bn(buf,bytes,rnd)) goto err;\n\tret=1;\nerr:\n\tif (buf != NULL)\n\t\t{\n\t\tOPENSSL_cleanse(buf,bytes);\n\t\tOPENSSL_free(buf);\n\t\t}\n\tbn_check_top(rnd);\n\treturn(ret);\n\t}', 'int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n\t{\n\tint i,bits,ret=0;\n\tBIGNUM *v,*rr;\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\tBNerr(BN_F_BN_EXP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\treturn -1;\n\t\t}\n\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == p))\n\t\trr = BN_CTX_get(ctx);\n\telse\n\t\trr = r;\n\tif ((v = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (BN_copy(v,a) == NULL) goto err;\n\tbits=BN_num_bits(p);\n\tif (BN_is_odd(p))\n\t\t{ if (BN_copy(rr,a) == NULL) goto err; }\n\telse\t{ if (!BN_one(rr)) goto err; }\n\tfor (i=1; i<bits; i++)\n\t\t{\n\t\tif (!BN_sqr(v,v,ctx)) goto err;\n\t\tif (BN_is_bit_set(p,i))\n\t\t\t{\n\t\t\tif (!BN_mul(rr,rr,v,ctx)) goto err;\n\t\t\t}\n\t\t}\n\tret=1;\nerr:\n\tif (r != rr) BN_copy(r,rr);\n\tBN_CTX_end(ctx);\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}']
|
2,777
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavformat/rtpdec.c/#L346
|
static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf)
{
int au_headers_length, au_header_size, i;
GetBitContext getbitcontext;
rtp_payload_data_t *infos;
infos = s->rtp_payload_data;
if (infos == NULL)
return -1;
au_headers_length = AV_RB16(buf);
if (au_headers_length > RTP_MAX_PACKET_LENGTH)
return -1;
infos->au_headers_length_bytes = (au_headers_length + 7) / 8;
buf += 2;
init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8);
au_header_size = infos->sizelength + infos->indexlength;
if (au_header_size <= 0 || (au_headers_length % au_header_size != 0))
return -1;
infos->nb_au_headers = au_headers_length / au_header_size;
infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers);
infos->au_headers[0].size = 0;
infos->au_headers[0].index = 0;
for (i = 0; i < infos->nb_au_headers; ++i) {
infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength);
infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength);
}
infos->nb_au_headers = 1;
return 0;
}
|
['static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf)\n{\n int au_headers_length, au_header_size, i;\n GetBitContext getbitcontext;\n rtp_payload_data_t *infos;\n infos = s->rtp_payload_data;\n if (infos == NULL)\n return -1;\n au_headers_length = AV_RB16(buf);\n if (au_headers_length > RTP_MAX_PACKET_LENGTH)\n return -1;\n infos->au_headers_length_bytes = (au_headers_length + 7) / 8;\n buf += 2;\n init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8);\n au_header_size = infos->sizelength + infos->indexlength;\n if (au_header_size <= 0 || (au_headers_length % au_header_size != 0))\n return -1;\n infos->nb_au_headers = au_headers_length / au_header_size;\n infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers);\n infos->au_headers[0].size = 0;\n infos->au_headers[0].index = 0;\n for (i = 0; i < infos->nb_au_headers; ++i) {\n infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength);\n infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength);\n }\n infos->nb_au_headers = 1;\n return 0;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size= (bit_size+7)>>3;\n if(buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer= buffer;\n s->size_in_bits= bit_size;\n s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index=0;\n#elif defined 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}', '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}']
|
2,778
| 0
|
https://github.com/libav/libav/blob/a734fa575f94c7c28103420f756b5f64dd0c806b/ffmpeg.c/#L3648
|
static int opt_streamid(const char *opt, const char *arg)
{
int idx;
char *p;
char idx_str[16];
strncpy(idx_str, arg, sizeof(idx_str));
idx_str[sizeof(idx_str)-1] = '\0';
p = strchr(idx_str, ':');
if (!p) {
fprintf(stderr,
"Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
arg, opt);
ffmpeg_exit(1);
}
*p++ = '\0';
idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
streamid_map = grow_array(streamid_map, sizeof(*streamid_map), &nb_streamid_map, idx+1);
streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
return 0;
}
|
['static int opt_streamid(const char *opt, const char *arg)\n{\n int idx;\n char *p;\n char idx_str[16];\n strncpy(idx_str, arg, sizeof(idx_str));\n idx_str[sizeof(idx_str)-1] = \'\\0\';\n p = strchr(idx_str, \':\');\n if (!p) {\n fprintf(stderr,\n "Invalid value \'%s\' for option \'%s\', required syntax is \'index:value\'\\n",\n arg, opt);\n ffmpeg_exit(1);\n }\n *p++ = \'\\0\';\n idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);\n streamid_map = grow_array(streamid_map, sizeof(*streamid_map), &nb_streamid_map, idx+1);\n streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);\n return 0;\n}']
|
2,779
| 0
|
https://github.com/openssl/openssl/blob/9f9442918aeaed5dc2442d81ab8d29fe3e1fb906/crypto/bn/bn_lib.c/#L333
|
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
bn_check_top(b);
if (a == b)
return a;
if (bn_wexpand(a, b->top) == NULL)
return NULL;
if (b->top > 0)
memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)
BN_set_flags(a, BN_FLG_CONSTTIME);
a->top = b->top;
a->neg = b->neg;
bn_check_top(a);
return a;
}
|
['BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,\n const BIGNUM *b, const BIGNUM *N)\n{\n BIGNUM *tmp = NULL, *S = NULL;\n BN_CTX *bn_ctx;\n if (u == NULL || A == NULL || v == NULL || b == NULL || N == NULL)\n return NULL;\n if ((bn_ctx = BN_CTX_new()) == NULL || (tmp = BN_new()) == NULL)\n goto err;\n if (!BN_mod_exp(tmp, v, u, N, bn_ctx))\n goto err;\n if (!BN_mod_mul(tmp, A, tmp, N, bn_ctx))\n goto err;\n S = BN_new();\n if (S != NULL && !BN_mod_exp(S, tmp, b, N, bn_ctx)) {\n BN_free(S);\n S = NULL;\n }\n err:\n BN_CTX_free(bn_ctx);\n BN_clear_free(tmp);\n return S;\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_is_odd(const BIGNUM *a)\n{\n return (a->top > 0) && (a->d[0] & 1);\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 *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 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_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}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n 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}']
|
2,780
| 0
|
https://github.com/libav/libav/blob/bdefbf3e8857d2861d8d57c0ef583fe15a46d1a4/libavcodec/mp3_header_compress_bsf.c/#L67
|
static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size, int keyframe){
uint32_t header, extraheader;
int mode_extension, header_size;
if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
av_log(avctx, AV_LOG_ERROR, "not standards compliant\n");
return -1;
}
header = AV_RB32(buf);
mode_extension= (header>>4)&3;
if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){
output_unchanged:
*poutbuf= (uint8_t *) buf;
*poutbuf_size= buf_size;
av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header);
return 0;
}
if(avctx->extradata_size == 0){
avctx->extradata_size=15;
avctx->extradata= av_malloc(avctx->extradata_size);
strcpy(avctx->extradata, "FFCMP3 0.0");
memcpy(avctx->extradata+11, buf, 4);
}
if(avctx->extradata_size != 15){
av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n");
return -1;
}
extraheader = AV_RB32(avctx->extradata+11);
if((extraheader&MP3_MASK) != (header&MP3_MASK))
goto output_unchanged;
header_size= (header&0x10000) ? 4 : 6;
*poutbuf_size= buf_size - header_size;
*poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
if(avctx->channels==2){
if((header & (3<<19)) != 3<<19){
(*poutbuf)[1] &= 0x3F;
(*poutbuf)[1] |= mode_extension<<6;
FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]);
}else{
(*poutbuf)[1] &= 0x8F;
(*poutbuf)[1] |= mode_extension<<4;
}
}
return 1;
}
|
['static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,\n uint8_t **poutbuf, int *poutbuf_size,\n const uint8_t *buf, int buf_size, int keyframe){\n uint32_t header, extraheader;\n int mode_extension, header_size;\n if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){\n av_log(avctx, AV_LOG_ERROR, "not standards compliant\\n");\n return -1;\n }\n header = AV_RB32(buf);\n mode_extension= (header>>4)&3;\n if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){\noutput_unchanged:\n *poutbuf= (uint8_t *) buf;\n *poutbuf_size= buf_size;\n av_log(avctx, AV_LOG_INFO, "cannot compress %08X\\n", header);\n return 0;\n }\n if(avctx->extradata_size == 0){\n avctx->extradata_size=15;\n avctx->extradata= av_malloc(avctx->extradata_size);\n strcpy(avctx->extradata, "FFCMP3 0.0");\n memcpy(avctx->extradata+11, buf, 4);\n }\n if(avctx->extradata_size != 15){\n av_log(avctx, AV_LOG_ERROR, "Extradata invalid\\n");\n return -1;\n }\n extraheader = AV_RB32(avctx->extradata+11);\n if((extraheader&MP3_MASK) != (header&MP3_MASK))\n goto output_unchanged;\n header_size= (header&0x10000) ? 4 : 6;\n *poutbuf_size= buf_size - header_size;\n *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);\n memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);\n if(avctx->channels==2){\n if((header & (3<<19)) != 3<<19){\n (*poutbuf)[1] &= 0x3F;\n (*poutbuf)[1] |= mode_extension<<6;\n FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]);\n }else{\n (*poutbuf)[1] &= 0x8F;\n (*poutbuf)[1] |= mode_extension<<4;\n }\n }\n return 1;\n}', 'static av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);\n x= (x>>16) | (x<<16);\n return x;\n}', 'static inline int ff_mpa_check_header(uint32_t header){\n if ((header & 0xffe00000) != 0xffe00000)\n return -1;\n if ((header & (3<<17)) == 0)\n return -1;\n if ((header & (0xf<<12)) == 0xf<<12)\n return -1;\n if ((header & (3<<10)) == 3<<10)\n return -1;\n return 0;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-32) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
2,781
| 0
|
https://github.com/openssl/openssl/blob/2864df8f9d3264e19b49a246e272fb513f4c1be3/crypto/bn/bn_ctx.c/#L270
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['size_t ec_GF2m_simple_point2oct(const EC_GROUP *group, const EC_POINT *point,\n point_conversion_form_t form,\n unsigned char *buf, size_t len, BN_CTX *ctx)\n{\n size_t ret;\n BN_CTX *new_ctx = NULL;\n int used_ctx = 0;\n BIGNUM *x, *y, *yxi;\n size_t field_len, i, skip;\n if ((form != POINT_CONVERSION_COMPRESSED)\n && (form != POINT_CONVERSION_UNCOMPRESSED)\n && (form != POINT_CONVERSION_HYBRID)) {\n ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_INVALID_FORM);\n goto err;\n }\n if (EC_POINT_is_at_infinity(group, point)) {\n if (buf != NULL) {\n if (len < 1) {\n ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL);\n return 0;\n }\n buf[0] = 0;\n }\n return 1;\n }\n field_len = (EC_GROUP_get_degree(group) + 7) / 8;\n ret =\n (form ==\n POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;\n if (buf != NULL) {\n if (len < ret) {\n ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL);\n goto err;\n }\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n BN_CTX_start(ctx);\n used_ctx = 1;\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n yxi = BN_CTX_get(ctx);\n if (yxi == NULL)\n goto err;\n if (!EC_POINT_get_affine_coordinates(group, point, x, y, ctx))\n goto err;\n buf[0] = form;\n if ((form != POINT_CONVERSION_UNCOMPRESSED) && !BN_is_zero(x)) {\n if (!group->meth->field_div(group, yxi, y, x, ctx))\n goto err;\n if (BN_is_odd(yxi))\n buf[0]++;\n }\n i = 1;\n skip = field_len - BN_num_bytes(x);\n if (skip > field_len) {\n ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n while (skip > 0) {\n buf[i++] = 0;\n skip--;\n }\n skip = BN_bn2bin(x, buf + i);\n i += skip;\n if (i != 1 + field_len) {\n ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (form == POINT_CONVERSION_UNCOMPRESSED\n || form == POINT_CONVERSION_HYBRID) {\n skip = field_len - BN_num_bytes(y);\n if (skip > field_len) {\n ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n while (skip > 0) {\n buf[i++] = 0;\n skip--;\n }\n skip = BN_bn2bin(y, buf + i);\n i += skip;\n }\n if (i != ret) {\n ECerr(EC_F_EC_GF2M_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n }\n if (used_ctx)\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n err:\n if (used_ctx)\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return 0;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
2,782
| 0
|
https://github.com/openssl/openssl/blob/0ea155fc1c4e6ba3655f435164ea3f884883df29/ssl/statem/statem_clnt.c/#L2883
|
static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt, int *al)
{
#ifndef OPENSSL_NO_RSA
unsigned char *encdata = NULL;
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = NULL;
size_t enclen;
unsigned char *pms = NULL;
size_t pmslen = 0;
if (s->session->peer == NULL) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
return 0;
}
pkey = X509_get0_pubkey(s->session->peer);
if (EVP_PKEY_get0_RSA(pkey) == NULL) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
return 0;
}
pmslen = SSL_MAX_MASTER_KEY_LENGTH;
pms = OPENSSL_malloc(pmslen);
if (pms == NULL) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);
*al = SSL_AD_INTERNAL_ERROR;
return 0;
}
pms[0] = s->client_version >> 8;
pms[1] = s->client_version & 0xff;
if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {
goto err;
}
if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
goto err;
}
pctx = EVP_PKEY_CTX_new(pkey, NULL);
if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0
|| EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_EVP_LIB);
goto err;
}
if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)
|| EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, SSL_R_BAD_RSA_ENCRYPT);
goto err;
}
EVP_PKEY_CTX_free(pctx);
pctx = NULL;
if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
goto err;
}
if (!ssl_log_rsa_client_key_exchange(s, encdata, enclen, pms, pmslen))
goto err;
s->s3->tmp.pms = pms;
s->s3->tmp.pmslen = pmslen;
return 1;
err:
OPENSSL_clear_free(pms, pmslen);
EVP_PKEY_CTX_free(pctx);
return 0;
#else
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
*al = SSL_AD_INTERNAL_ERROR;
return 0;
#endif
}
|
['static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt, int *al)\n{\n#ifndef OPENSSL_NO_RSA\n unsigned char *encdata = NULL;\n EVP_PKEY *pkey = NULL;\n EVP_PKEY_CTX *pctx = NULL;\n size_t enclen;\n unsigned char *pms = NULL;\n size_t pmslen = 0;\n if (s->session->peer == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pkey = X509_get0_pubkey(s->session->peer);\n if (EVP_PKEY_get0_RSA(pkey) == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pmslen = SSL_MAX_MASTER_KEY_LENGTH;\n pms = OPENSSL_malloc(pmslen);\n if (pms == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);\n *al = SSL_AD_INTERNAL_ERROR;\n return 0;\n }\n pms[0] = s->client_version >> 8;\n pms[1] = s->client_version & 0xff;\n if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {\n goto err;\n }\n if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n pctx = EVP_PKEY_CTX_new(pkey, NULL);\n if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0\n || EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_EVP_LIB);\n goto err;\n }\n if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)\n || EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, SSL_R_BAD_RSA_ENCRYPT);\n goto err;\n }\n EVP_PKEY_CTX_free(pctx);\n pctx = NULL;\n if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!ssl_log_rsa_client_key_exchange(s, encdata, enclen, pms, pmslen))\n goto err;\n s->s3->tmp.pms = pms;\n s->s3->tmp.pmslen = pmslen;\n return 1;\n err:\n OPENSSL_clear_free(pms, pmslen);\n EVP_PKEY_CTX_free(pctx);\n return 0;\n#else\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n *al = SSL_AD_INTERNAL_ERROR;\n return 0;\n#endif\n}', 'EVP_PKEY *X509_get0_pubkey(const X509 *x)\n{\n if (x == NULL)\n return NULL;\n return X509_PUBKEY_get0(x->cert_info.key);\n}', 'EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)\n{\n EVP_PKEY *ret = NULL;\n if (key == NULL || key->public_key == NULL)\n return NULL;\n if (key->pkey != NULL)\n return key->pkey;\n x509_pubkey_decode(&ret, key);\n if (ret != NULL) {\n X509err(X509_F_X509_PUBKEY_GET0, ERR_R_INTERNAL_ERROR);\n EVP_PKEY_free(ret);\n }\n return NULL;\n}', 'RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)\n{\n if (pkey->type != EVP_PKEY_RSA) {\n EVPerr(EVP_F_EVP_PKEY_GET0_RSA, EVP_R_EXPECTING_AN_RSA_KEY);\n return NULL;\n }\n return pkey->pkey.rsa;\n}', '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}', 'int RAND_bytes(unsigned char *buf, int num)\n{\n const RAND_METHOD *meth = RAND_get_rand_method();\n if (meth && meth->bytes)\n return meth->bytes(buf, num);\n RANDerr(RAND_F_RAND_BYTES, RAND_R_FUNC_NOT_IMPLEMENTED);\n return (-1);\n}', 'const RAND_METHOD *RAND_get_rand_method(void)\n{\n const RAND_METHOD *tmp_meth = NULL;\n if (!RUN_ONCE(&rand_lock_init, do_rand_lock_init))\n return NULL;\n CRYPTO_THREAD_write_lock(rand_meth_lock);\n if (!default_RAND_meth) {\n#ifndef OPENSSL_NO_ENGINE\n ENGINE *e = ENGINE_get_default_RAND();\n if (e) {\n default_RAND_meth = ENGINE_get_RAND(e);\n if (default_RAND_meth == NULL) {\n ENGINE_finish(e);\n e = NULL;\n }\n }\n if (e)\n funct_ref = e;\n else\n#endif\n default_RAND_meth = RAND_OpenSSL();\n }\n tmp_meth = default_RAND_meth;\n CRYPTO_THREAD_unlock(rand_meth_lock);\n return tmp_meth;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)\n{\n if (str == NULL)\n return;\n if (num)\n OPENSSL_cleanse(str, num);\n CRYPTO_free(str, file, line);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
|
2,783
| 0
|
https://github.com/nginx/nginx/blob/a54e3193bfa0e0b912cdc394564307be5bb68c17/src/core/ngx_slab.c/#L570
|
void
ngx_slab_free_locked(ngx_slab_pool_t *pool, void *p)
{
size_t size;
uintptr_t slab, m, *bitmap;
ngx_uint_t i, n, type, slot, shift, map;
ngx_slab_page_t *slots, *page;
ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, ngx_cycle->log, 0, "slab free: %p", p);
if ((u_char *) p < pool->start || (u_char *) p > pool->end) {
ngx_slab_error(pool, NGX_LOG_ALERT, "ngx_slab_free(): outside of pool");
goto fail;
}
n = ((u_char *) p - pool->start) >> ngx_pagesize_shift;
page = &pool->pages[n];
slab = page->slab;
type = ngx_slab_page_type(page);
switch (type) {
case NGX_SLAB_SMALL:
shift = slab & NGX_SLAB_SHIFT_MASK;
size = (size_t) 1 << shift;
if ((uintptr_t) p & (size - 1)) {
goto wrong_chunk;
}
n = ((uintptr_t) p & (ngx_pagesize - 1)) >> shift;
m = (uintptr_t) 1 << (n % (8 * sizeof(uintptr_t)));
n /= 8 * sizeof(uintptr_t);
bitmap = (uintptr_t *)
((uintptr_t) p & ~((uintptr_t) ngx_pagesize - 1));
if (bitmap[n] & m) {
slot = shift - pool->min_shift;
if (page->next == NULL) {
slots = ngx_slab_slots(pool);
page->next = slots[slot].next;
slots[slot].next = page;
page->prev = (uintptr_t) &slots[slot] | NGX_SLAB_SMALL;
page->next->prev = (uintptr_t) page | NGX_SLAB_SMALL;
}
bitmap[n] &= ~m;
n = (ngx_pagesize >> shift) / ((1 << shift) * 8);
if (n == 0) {
n = 1;
}
i = n / (8 * sizeof(uintptr_t));
m = ((uintptr_t) 1 << (n % (8 * sizeof(uintptr_t)))) - 1;
if (bitmap[i] & ~m) {
goto done;
}
map = (ngx_pagesize >> shift) / (8 * sizeof(uintptr_t));
for (i = i + 1; i < map; i++) {
if (bitmap[i]) {
goto done;
}
}
ngx_slab_free_pages(pool, page, 1);
pool->stats[slot].total -= (ngx_pagesize >> shift) - n;
goto done;
}
goto chunk_already_free;
case NGX_SLAB_EXACT:
m = (uintptr_t) 1 <<
(((uintptr_t) p & (ngx_pagesize - 1)) >> ngx_slab_exact_shift);
size = ngx_slab_exact_size;
if ((uintptr_t) p & (size - 1)) {
goto wrong_chunk;
}
if (slab & m) {
slot = ngx_slab_exact_shift - pool->min_shift;
if (slab == NGX_SLAB_BUSY) {
slots = ngx_slab_slots(pool);
page->next = slots[slot].next;
slots[slot].next = page;
page->prev = (uintptr_t) &slots[slot] | NGX_SLAB_EXACT;
page->next->prev = (uintptr_t) page | NGX_SLAB_EXACT;
}
page->slab &= ~m;
if (page->slab) {
goto done;
}
ngx_slab_free_pages(pool, page, 1);
pool->stats[slot].total -= 8 * sizeof(uintptr_t);
goto done;
}
goto chunk_already_free;
case NGX_SLAB_BIG:
shift = slab & NGX_SLAB_SHIFT_MASK;
size = (size_t) 1 << shift;
if ((uintptr_t) p & (size - 1)) {
goto wrong_chunk;
}
m = (uintptr_t) 1 << ((((uintptr_t) p & (ngx_pagesize - 1)) >> shift)
+ NGX_SLAB_MAP_SHIFT);
if (slab & m) {
slot = shift - pool->min_shift;
if (page->next == NULL) {
slots = ngx_slab_slots(pool);
page->next = slots[slot].next;
slots[slot].next = page;
page->prev = (uintptr_t) &slots[slot] | NGX_SLAB_BIG;
page->next->prev = (uintptr_t) page | NGX_SLAB_BIG;
}
page->slab &= ~m;
if (page->slab & NGX_SLAB_MAP_MASK) {
goto done;
}
ngx_slab_free_pages(pool, page, 1);
pool->stats[slot].total -= ngx_pagesize >> shift;
goto done;
}
goto chunk_already_free;
case NGX_SLAB_PAGE:
if ((uintptr_t) p & (ngx_pagesize - 1)) {
goto wrong_chunk;
}
if (!(slab & NGX_SLAB_PAGE_START)) {
ngx_slab_error(pool, NGX_LOG_ALERT,
"ngx_slab_free(): page is already free");
goto fail;
}
if (slab == NGX_SLAB_PAGE_BUSY) {
ngx_slab_error(pool, NGX_LOG_ALERT,
"ngx_slab_free(): pointer to wrong page");
goto fail;
}
n = ((u_char *) p - pool->start) >> ngx_pagesize_shift;
size = slab & ~NGX_SLAB_PAGE_START;
ngx_slab_free_pages(pool, &pool->pages[n], size);
ngx_slab_junk(p, size << ngx_pagesize_shift);
return;
}
return;
done:
pool->stats[slot].used--;
ngx_slab_junk(p, size);
return;
wrong_chunk:
ngx_slab_error(pool, NGX_LOG_ALERT,
"ngx_slab_free(): pointer to wrong chunk");
goto fail;
chunk_already_free:
ngx_slab_error(pool, NGX_LOG_ALERT,
"ngx_slab_free(): chunk is already free");
fail:
return;
}
|
['static void\nngx_http_file_cache_delete(ngx_http_file_cache_t *cache, ngx_queue_t *q,\n u_char *name)\n{\n u_char *p;\n size_t len;\n ngx_path_t *path;\n ngx_http_file_cache_node_t *fcn;\n fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue);\n if (fcn->exists) {\n cache->sh->size -= fcn->fs_size;\n path = cache->path;\n p = name + path->name.len + 1 + path->len;\n p = ngx_hex_dump(p, (u_char *) &fcn->node.key,\n sizeof(ngx_rbtree_key_t));\n len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t);\n p = ngx_hex_dump(p, fcn->key, len);\n *p = \'\\0\';\n fcn->count++;\n fcn->deleting = 1;\n ngx_shmtx_unlock(&cache->shpool->mutex);\n len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN;\n ngx_create_hashed_filename(path, name, len);\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,\n "http file cache expire: \\"%s\\"", name);\n if (ngx_delete_file(name) == NGX_FILE_ERROR) {\n ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, ngx_errno,\n ngx_delete_file_n " \\"%s\\" failed", name);\n }\n ngx_shmtx_lock(&cache->shpool->mutex);\n fcn->count--;\n fcn->deleting = 0;\n }\n if (fcn->count == 0) {\n ngx_queue_remove(q);\n ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);\n ngx_slab_free_locked(cache->shpool, fcn);\n cache->sh->count--;\n }\n}', 'void\nngx_slab_free_locked(ngx_slab_pool_t *pool, void *p)\n{\n size_t size;\n uintptr_t slab, m, *bitmap;\n ngx_uint_t i, n, type, slot, shift, map;\n ngx_slab_page_t *slots, *page;\n ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, ngx_cycle->log, 0, "slab free: %p", p);\n if ((u_char *) p < pool->start || (u_char *) p > pool->end) {\n ngx_slab_error(pool, NGX_LOG_ALERT, "ngx_slab_free(): outside of pool");\n goto fail;\n }\n n = ((u_char *) p - pool->start) >> ngx_pagesize_shift;\n page = &pool->pages[n];\n slab = page->slab;\n type = ngx_slab_page_type(page);\n switch (type) {\n case NGX_SLAB_SMALL:\n shift = slab & NGX_SLAB_SHIFT_MASK;\n size = (size_t) 1 << shift;\n if ((uintptr_t) p & (size - 1)) {\n goto wrong_chunk;\n }\n n = ((uintptr_t) p & (ngx_pagesize - 1)) >> shift;\n m = (uintptr_t) 1 << (n % (8 * sizeof(uintptr_t)));\n n /= 8 * sizeof(uintptr_t);\n bitmap = (uintptr_t *)\n ((uintptr_t) p & ~((uintptr_t) ngx_pagesize - 1));\n if (bitmap[n] & m) {\n slot = shift - pool->min_shift;\n if (page->next == NULL) {\n slots = ngx_slab_slots(pool);\n page->next = slots[slot].next;\n slots[slot].next = page;\n page->prev = (uintptr_t) &slots[slot] | NGX_SLAB_SMALL;\n page->next->prev = (uintptr_t) page | NGX_SLAB_SMALL;\n }\n bitmap[n] &= ~m;\n n = (ngx_pagesize >> shift) / ((1 << shift) * 8);\n if (n == 0) {\n n = 1;\n }\n i = n / (8 * sizeof(uintptr_t));\n m = ((uintptr_t) 1 << (n % (8 * sizeof(uintptr_t)))) - 1;\n if (bitmap[i] & ~m) {\n goto done;\n }\n map = (ngx_pagesize >> shift) / (8 * sizeof(uintptr_t));\n for (i = i + 1; i < map; i++) {\n if (bitmap[i]) {\n goto done;\n }\n }\n ngx_slab_free_pages(pool, page, 1);\n pool->stats[slot].total -= (ngx_pagesize >> shift) - n;\n goto done;\n }\n goto chunk_already_free;\n case NGX_SLAB_EXACT:\n m = (uintptr_t) 1 <<\n (((uintptr_t) p & (ngx_pagesize - 1)) >> ngx_slab_exact_shift);\n size = ngx_slab_exact_size;\n if ((uintptr_t) p & (size - 1)) {\n goto wrong_chunk;\n }\n if (slab & m) {\n slot = ngx_slab_exact_shift - pool->min_shift;\n if (slab == NGX_SLAB_BUSY) {\n slots = ngx_slab_slots(pool);\n page->next = slots[slot].next;\n slots[slot].next = page;\n page->prev = (uintptr_t) &slots[slot] | NGX_SLAB_EXACT;\n page->next->prev = (uintptr_t) page | NGX_SLAB_EXACT;\n }\n page->slab &= ~m;\n if (page->slab) {\n goto done;\n }\n ngx_slab_free_pages(pool, page, 1);\n pool->stats[slot].total -= 8 * sizeof(uintptr_t);\n goto done;\n }\n goto chunk_already_free;\n case NGX_SLAB_BIG:\n shift = slab & NGX_SLAB_SHIFT_MASK;\n size = (size_t) 1 << shift;\n if ((uintptr_t) p & (size - 1)) {\n goto wrong_chunk;\n }\n m = (uintptr_t) 1 << ((((uintptr_t) p & (ngx_pagesize - 1)) >> shift)\n + NGX_SLAB_MAP_SHIFT);\n if (slab & m) {\n slot = shift - pool->min_shift;\n if (page->next == NULL) {\n slots = ngx_slab_slots(pool);\n page->next = slots[slot].next;\n slots[slot].next = page;\n page->prev = (uintptr_t) &slots[slot] | NGX_SLAB_BIG;\n page->next->prev = (uintptr_t) page | NGX_SLAB_BIG;\n }\n page->slab &= ~m;\n if (page->slab & NGX_SLAB_MAP_MASK) {\n goto done;\n }\n ngx_slab_free_pages(pool, page, 1);\n pool->stats[slot].total -= ngx_pagesize >> shift;\n goto done;\n }\n goto chunk_already_free;\n case NGX_SLAB_PAGE:\n if ((uintptr_t) p & (ngx_pagesize - 1)) {\n goto wrong_chunk;\n }\n if (!(slab & NGX_SLAB_PAGE_START)) {\n ngx_slab_error(pool, NGX_LOG_ALERT,\n "ngx_slab_free(): page is already free");\n goto fail;\n }\n if (slab == NGX_SLAB_PAGE_BUSY) {\n ngx_slab_error(pool, NGX_LOG_ALERT,\n "ngx_slab_free(): pointer to wrong page");\n goto fail;\n }\n n = ((u_char *) p - pool->start) >> ngx_pagesize_shift;\n size = slab & ~NGX_SLAB_PAGE_START;\n ngx_slab_free_pages(pool, &pool->pages[n], size);\n ngx_slab_junk(p, size << ngx_pagesize_shift);\n return;\n }\n return;\ndone:\n pool->stats[slot].used--;\n ngx_slab_junk(p, size);\n return;\nwrong_chunk:\n ngx_slab_error(pool, NGX_LOG_ALERT,\n "ngx_slab_free(): pointer to wrong chunk");\n goto fail;\nchunk_already_free:\n ngx_slab_error(pool, NGX_LOG_ALERT,\n "ngx_slab_free(): chunk is already free");\nfail:\n return;\n}']
|
2,784
| 0
|
https://github.com/openssl/openssl/blob/3ad4af89cf7380aa94d1995e05e713d59e1c469a/crypto/err/err.c/#L575
|
static unsigned long get_error_values(int inc, int top, const char **file,
int *line, const char **data,
int *flags)
{
int i = 0;
ERR_STATE *es;
unsigned long ret;
es = ERR_get_state();
if (inc && top) {
if (file)
*file = "";
if (line)
*line = 0;
if (data)
*data = "";
if (flags)
*flags = 0;
return ERR_R_INTERNAL_ERROR;
}
if (es->bottom == es->top)
return 0;
if (top)
i = es->top;
else
i = (es->bottom + 1) % ERR_NUM_ERRORS;
ret = es->err_buffer[i];
if (inc) {
es->bottom = i;
es->err_buffer[i] = 0;
}
if ((file != NULL) && (line != NULL)) {
if (es->err_file[i] == NULL) {
*file = "NA";
if (line != NULL)
*line = 0;
} else {
*file = es->err_file[i];
if (line != NULL)
*line = es->err_line[i];
}
}
if (data == NULL) {
if (inc) {
err_clear_data(es, i);
}
} else {
if (es->err_data[i] == NULL) {
*data = "";
if (flags != NULL)
*flags = 0;
} else {
*data = es->err_data[i];
if (flags != NULL)
*flags = es->err_data_flags[i];
}
}
return ret;
}
|
['static unsigned long get_error_values(int inc, int top, const char **file,\n int *line, const char **data,\n int *flags)\n{\n int i = 0;\n ERR_STATE *es;\n unsigned long ret;\n es = ERR_get_state();\n if (inc && top) {\n if (file)\n *file = "";\n if (line)\n *line = 0;\n if (data)\n *data = "";\n if (flags)\n *flags = 0;\n return ERR_R_INTERNAL_ERROR;\n }\n if (es->bottom == es->top)\n return 0;\n if (top)\n i = es->top;\n else\n i = (es->bottom + 1) % ERR_NUM_ERRORS;\n ret = es->err_buffer[i];\n if (inc) {\n es->bottom = i;\n es->err_buffer[i] = 0;\n }\n if ((file != NULL) && (line != NULL)) {\n if (es->err_file[i] == NULL) {\n *file = "NA";\n if (line != NULL)\n *line = 0;\n } else {\n *file = es->err_file[i];\n if (line != NULL)\n *line = es->err_line[i];\n }\n }\n if (data == NULL) {\n if (inc) {\n err_clear_data(es, i);\n }\n } else {\n if (es->err_data[i] == NULL) {\n *data = "";\n if (flags != NULL)\n *flags = 0;\n } else {\n *data = es->err_data[i];\n if (flags != NULL)\n *flags = es->err_data_flags[i];\n }\n }\n return ret;\n}', 'ERR_STATE *ERR_get_state(void)\n{\n ERR_STATE *state = NULL;\n CRYPTO_THREAD_run_once(&err_init, err_do_init);\n state = CRYPTO_THREAD_get_local(&err_thread_local);\n if (state == NULL) {\n state = OPENSSL_zalloc(sizeof(*state));\n if (state == NULL)\n return NULL;\n if (!CRYPTO_THREAD_set_local(&err_thread_local, state)) {\n ERR_STATE_free(state);\n return NULL;\n }\n OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE);\n }\n return state;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', '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}']
|
2,785
| 0
|
https://github.com/openssl/openssl/blob/8ccf2ffbd6a98d3750b715787c80d5d2b76d054b/apps/pkeyparam.c/#L82
|
int pkeyparam_main(int argc, char **argv)
{
ENGINE *e = NULL;
BIO *in = NULL, *out = NULL;
EVP_PKEY *pkey = NULL;
int text = 0, noout = 0, ret = 1, check = 0;
OPTION_CHOICE o;
char *infile = NULL, *outfile = NULL, *prog;
prog = opt_init(argc, argv, pkeyparam_options);
while ((o = opt_next()) != OPT_EOF) {
switch (o) {
case OPT_EOF:
case OPT_ERR:
opthelp:
BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
goto end;
case OPT_HELP:
opt_help(pkeyparam_options);
ret = 0;
goto end;
case OPT_IN:
infile = opt_arg();
break;
case OPT_OUT:
outfile = opt_arg();
break;
case OPT_ENGINE:
e = setup_engine(opt_arg(), 0);
break;
case OPT_TEXT:
text = 1;
break;
case OPT_NOOUT:
noout = 1;
break;
case OPT_CHECK:
check = 1;
break;
}
}
argc = opt_num_rest();
if (argc != 0)
goto opthelp;
in = bio_open_default(infile, 'r', FORMAT_PEM);
if (in == NULL)
goto end;
out = bio_open_default(outfile, 'w', FORMAT_PEM);
if (out == NULL)
goto end;
pkey = PEM_read_bio_Parameters(in, NULL);
if (pkey == NULL) {
BIO_printf(bio_err, "Error reading parameters\n");
ERR_print_errors(bio_err);
goto end;
}
if (check) {
int r;
EVP_PKEY_CTX *ctx;
ctx = EVP_PKEY_CTX_new(pkey, e);
if (ctx == NULL) {
ERR_print_errors(bio_err);
goto end;
}
r = EVP_PKEY_param_check(ctx);
if (r == 1) {
BIO_printf(out, "Parameters are valid\n");
} else {
unsigned long err;
BIO_printf(out, "Parameters are invalid\n");
while ((err = ERR_peek_error()) != 0) {
BIO_printf(out, "Detailed error: %s\n",
ERR_reason_error_string(err));
ERR_get_error();
}
}
EVP_PKEY_CTX_free(ctx);
}
if (!noout)
PEM_write_bio_Parameters(out, pkey);
if (text)
EVP_PKEY_print_params(out, pkey, 0, NULL);
ret = 0;
end:
EVP_PKEY_free(pkey);
release_engine(e);
BIO_free_all(out);
BIO_free(in);
return ret;
}
|
['int pkeyparam_main(int argc, char **argv)\n{\n ENGINE *e = NULL;\n BIO *in = NULL, *out = NULL;\n EVP_PKEY *pkey = NULL;\n int text = 0, noout = 0, ret = 1, check = 0;\n OPTION_CHOICE o;\n char *infile = NULL, *outfile = NULL, *prog;\n prog = opt_init(argc, argv, pkeyparam_options);\n while ((o = opt_next()) != OPT_EOF) {\n switch (o) {\n case OPT_EOF:\n case OPT_ERR:\n opthelp:\n BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n goto end;\n case OPT_HELP:\n opt_help(pkeyparam_options);\n ret = 0;\n goto end;\n case OPT_IN:\n infile = opt_arg();\n break;\n case OPT_OUT:\n outfile = opt_arg();\n break;\n case OPT_ENGINE:\n e = setup_engine(opt_arg(), 0);\n break;\n case OPT_TEXT:\n text = 1;\n break;\n case OPT_NOOUT:\n noout = 1;\n break;\n case OPT_CHECK:\n check = 1;\n break;\n }\n }\n argc = opt_num_rest();\n if (argc != 0)\n goto opthelp;\n in = bio_open_default(infile, \'r\', FORMAT_PEM);\n if (in == NULL)\n goto end;\n out = bio_open_default(outfile, \'w\', FORMAT_PEM);\n if (out == NULL)\n goto end;\n pkey = PEM_read_bio_Parameters(in, NULL);\n if (pkey == NULL) {\n BIO_printf(bio_err, "Error reading parameters\\n");\n ERR_print_errors(bio_err);\n goto end;\n }\n if (check) {\n int r;\n EVP_PKEY_CTX *ctx;\n ctx = EVP_PKEY_CTX_new(pkey, e);\n if (ctx == NULL) {\n ERR_print_errors(bio_err);\n goto end;\n }\n r = EVP_PKEY_param_check(ctx);\n if (r == 1) {\n BIO_printf(out, "Parameters are valid\\n");\n } else {\n unsigned long err;\n BIO_printf(out, "Parameters are invalid\\n");\n while ((err = ERR_peek_error()) != 0) {\n BIO_printf(out, "Detailed error: %s\\n",\n ERR_reason_error_string(err));\n ERR_get_error();\n }\n }\n EVP_PKEY_CTX_free(ctx);\n }\n if (!noout)\n PEM_write_bio_Parameters(out, pkey);\n if (text)\n EVP_PKEY_print_params(out, pkey, 0, NULL);\n ret = 0;\n end:\n EVP_PKEY_free(pkey);\n release_engine(e);\n BIO_free_all(out);\n BIO_free(in);\n return ret;\n}', 'int opt_num_rest(void)\n{\n int i = 0;\n char **pp;\n for (pp = opt_rest(); *pp; pp++, i++)\n continue;\n return i;\n}', 'char **opt_rest(void)\n{\n return &argv[opt_index];\n}', 'BIO *bio_open_default(const char *filename, char mode, int format)\n{\n return bio_open_default_(filename, mode, format, 0);\n}', 'static BIO *bio_open_default_(const char *filename, char mode, int format,\n int quiet)\n{\n BIO *ret;\n if (filename == NULL || strcmp(filename, "-") == 0) {\n ret = mode == \'r\' ? dup_bio_in(format) : dup_bio_out(format);\n if (quiet) {\n ERR_clear_error();\n return ret;\n }\n if (ret != NULL)\n return ret;\n BIO_printf(bio_err,\n "Can\'t open %s, %s\\n",\n mode == \'r\' ? "stdin" : "stdout", strerror(errno));\n } else {\n ret = BIO_new_file(filename, modestr(mode, format));\n if (quiet) {\n ERR_clear_error();\n return ret;\n }\n if (ret != NULL)\n return ret;\n BIO_printf(bio_err,\n "Can\'t open %s for %s, %s\\n",\n filename, modeverb(mode), strerror(errno));\n }\n ERR_print_errors(bio_err);\n return NULL;\n}', 'BIO *dup_bio_in(int format)\n{\n return BIO_new_fp(stdin,\n BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0));\n}', 'int FMT_istext(int format)\n{\n return (format & B_FORMAT_TEXT) == B_FORMAT_TEXT;\n}', 'BIO *BIO_new_fp(FILE *stream, int close_flag)\n{\n BIO *ret;\n if ((ret = BIO_new(BIO_s_file())) == NULL)\n return NULL;\n BIO_set_flags(ret, BIO_FLAGS_UPLINK_INTERNAL);\n BIO_set_fp(ret, stream, close_flag);\n return ret;\n}', 'const BIO_METHOD *BIO_s_file(void)\n{\n return &methods_filep;\n}', 'void ERR_print_errors(BIO *bp)\n{\n ERR_print_errors_cb(print_bio, bp);\n}', 'void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),\n void *u)\n{\n CRYPTO_THREAD_ID tid = CRYPTO_THREAD_get_current_id();\n unsigned long l;\n char buf[256];\n char buf2[4096], *hex;\n const char *file, *data;\n int line, flags;\n while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {\n ERR_error_string_n(l, buf, sizeof(buf));\n hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));\n BIO_snprintf(buf2, sizeof(buf2), "%s:%s:%s:%d:%s\\n", hex, buf, file,\n line, (flags & ERR_TXT_STRING) ? data : "");\n OPENSSL_free(hex);\n if (cb(buf2, strlen(buf2), u) <= 0)\n break;\n }\n}', 'CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void)\n{\n return pthread_self();\n}', 'unsigned long ERR_get_error_line_data(const char **file, int *line,\n const char **data, int *flags)\n{\n return get_error_values(1, 0, file, line, data, flags);\n}', 'static unsigned long get_error_values(int inc, int top, const char **file,\n int *line, const char **data,\n int *flags)\n{\n int i = 0;\n ERR_STATE *es;\n unsigned long ret;\n es = ERR_get_state();\n if (es == NULL)\n return 0;\n if (inc && top) {\n if (file)\n *file = "";\n if (line)\n *line = 0;\n if (data)\n *data = "";\n if (flags)\n *flags = 0;\n return ERR_R_INTERNAL_ERROR;\n }\n while (es->bottom != es->top) {\n if (es->err_flags[es->top] & ERR_FLAG_CLEAR) {\n err_clear(es, es->top);\n es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;\n continue;\n }\n i = (es->bottom + 1) % ERR_NUM_ERRORS;\n if (es->err_flags[i] & ERR_FLAG_CLEAR) {\n es->bottom = i;\n err_clear(es, es->bottom);\n continue;\n }\n break;\n }\n if (es->bottom == es->top)\n return 0;\n if (top)\n i = es->top;\n else\n i = (es->bottom + 1) % ERR_NUM_ERRORS;\n ret = es->err_buffer[i];\n if (inc) {\n es->bottom = i;\n es->err_buffer[i] = 0;\n }\n if (file != NULL && line != NULL) {\n if (es->err_file[i] == NULL) {\n *file = "NA";\n *line = 0;\n } else {\n *file = es->err_file[i];\n *line = es->err_line[i];\n }\n }\n if (data == NULL) {\n if (inc) {\n err_clear_data(es, i);\n }\n } else {\n if (es->err_data[i] == NULL) {\n *data = "";\n if (flags != NULL)\n *flags = 0;\n } else {\n *data = es->err_data[i];\n if (flags != NULL)\n *flags = es->err_data_flags[i];\n }\n }\n return ret;\n}', 'ERR_STATE *ERR_get_state(void)\n{\n ERR_STATE *state;\n int saveerrno = get_last_sys_error();\n if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))\n return NULL;\n if (!RUN_ONCE(&err_init, err_do_init))\n return NULL;\n state = CRYPTO_THREAD_get_local(&err_thread_local);\n if (state == (ERR_STATE*)-1)\n return NULL;\n if (state == NULL) {\n if (!CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)-1))\n return NULL;\n if ((state = OPENSSL_zalloc(sizeof(*state))) == NULL) {\n CRYPTO_THREAD_set_local(&err_thread_local, NULL);\n return NULL;\n }\n if (!ossl_init_thread_start(NULL, NULL, err_delete_thread_state)\n || !CRYPTO_THREAD_set_local(&err_thread_local, state)) {\n ERR_STATE_free(state);\n CRYPTO_THREAD_set_local(&err_thread_local, NULL);\n return NULL;\n }\n OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n }\n set_sys_error(saveerrno);\n return state;\n}']
|
2,786
| 0
|
https://github.com/openssl/openssl/blob/72257204bd2a88773461150765dfd0e0a428ee86/crypto/bn/bn_exp.c/#L542
|
static int MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, int top,
unsigned char *buf, int idx,
int window)
{
int i, j;
int width = 1 << window;
volatile BN_ULONG *table = (volatile BN_ULONG *)buf;
if (bn_wexpand(b, top) == NULL)
return 0;
if (window <= 3) {
for (i = 0; i < top; i++, table += width) {
BN_ULONG acc = 0;
for (j = 0; j < width; j++) {
acc |= table[j] &
((BN_ULONG)0 - (constant_time_eq_int(j,idx)&1));
}
b->d[i] = acc;
}
} else {
int xstride = 1 << (window - 2);
BN_ULONG y0, y1, y2, y3;
i = idx >> (window - 2);
idx &= xstride - 1;
y0 = (BN_ULONG)0 - (constant_time_eq_int(i,0)&1);
y1 = (BN_ULONG)0 - (constant_time_eq_int(i,1)&1);
y2 = (BN_ULONG)0 - (constant_time_eq_int(i,2)&1);
y3 = (BN_ULONG)0 - (constant_time_eq_int(i,3)&1);
for (i = 0; i < top; i++, table += width) {
BN_ULONG acc = 0;
for (j = 0; j < xstride; j++) {
acc |= ( (table[j + 0 * xstride] & y0) |
(table[j + 1 * xstride] & y1) |
(table[j + 2 * xstride] & y2) |
(table[j + 3 * xstride] & y3) )
& ((BN_ULONG)0 - (constant_time_eq_int(j,idx)&1));
}
b->d[i] = acc;
}
}
b->top = top;
bn_correct_top(b);
return 1;
}
|
['static int MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, int top,\n unsigned char *buf, int idx,\n int window)\n{\n int i, j;\n int width = 1 << window;\n volatile BN_ULONG *table = (volatile BN_ULONG *)buf;\n if (bn_wexpand(b, top) == NULL)\n return 0;\n if (window <= 3) {\n for (i = 0; i < top; i++, table += width) {\n BN_ULONG acc = 0;\n for (j = 0; j < width; j++) {\n acc |= table[j] &\n ((BN_ULONG)0 - (constant_time_eq_int(j,idx)&1));\n }\n b->d[i] = acc;\n }\n } else {\n int xstride = 1 << (window - 2);\n BN_ULONG y0, y1, y2, y3;\n i = idx >> (window - 2);\n idx &= xstride - 1;\n y0 = (BN_ULONG)0 - (constant_time_eq_int(i,0)&1);\n y1 = (BN_ULONG)0 - (constant_time_eq_int(i,1)&1);\n y2 = (BN_ULONG)0 - (constant_time_eq_int(i,2)&1);\n y3 = (BN_ULONG)0 - (constant_time_eq_int(i,3)&1);\n for (i = 0; i < top; i++, table += width) {\n BN_ULONG acc = 0;\n for (j = 0; j < xstride; j++) {\n acc |= ( (table[j + 0 * xstride] & y0) |\n (table[j + 1 * xstride] & y1) |\n (table[j + 2 * xstride] & y2) |\n (table[j + 3 * xstride] & y3) )\n & ((BN_ULONG)0 - (constant_time_eq_int(j,idx)&1));\n }\n b->d[i] = acc;\n }\n }\n b->top = top;\n bn_correct_top(b);\n return 1;\n}', 'static ossl_inline unsigned int constant_time_eq_int(int a, int b)\n{\n return constant_time_eq((unsigned)(a), (unsigned)(b));\n}', 'static ossl_inline unsigned int constant_time_eq(unsigned int a,\n unsigned int b)\n{\n return constant_time_is_zero(a ^ b);\n}', 'static ossl_inline unsigned int constant_time_is_zero(unsigned int a)\n{\n return constant_time_msb(~a & (a - 1));\n}', 'static ossl_inline unsigned int constant_time_msb(unsigned int a)\n{\n return 0 - (a >> (sizeof(a) * 8 - 1));\n}']
|
2,787
| 0
|
https://github.com/libav/libav/blob/7fa70598e83cca650717d02ac96bcf55e9f97c19/libavformat/oggparsevorbis.c/#L138
|
static unsigned int
fixup_vorbis_headers(AVFormatContext * as, struct oggvorbis_private *priv,
uint8_t **buf)
{
int i,offset, len;
unsigned char *ptr;
len = priv->len[0] + priv->len[1] + priv->len[2];
ptr = *buf = av_mallocz(len + len/255 + 64);
ptr[0] = 2;
offset = 1;
offset += av_xiphlacing(&ptr[offset], priv->len[0]);
offset += av_xiphlacing(&ptr[offset], priv->len[1]);
for (i = 0; i < 3; i++) {
memcpy(&ptr[offset], priv->packet[i], priv->len[i]);
offset += priv->len[i];
}
*buf = av_realloc(*buf, offset + FF_INPUT_BUFFER_PADDING_SIZE);
return offset;
}
|
['static unsigned int\nfixup_vorbis_headers(AVFormatContext * as, struct oggvorbis_private *priv,\n uint8_t **buf)\n{\n int i,offset, len;\n unsigned char *ptr;\n len = priv->len[0] + priv->len[1] + priv->len[2];\n ptr = *buf = av_mallocz(len + len/255 + 64);\n ptr[0] = 2;\n offset = 1;\n offset += av_xiphlacing(&ptr[offset], priv->len[0]);\n offset += av_xiphlacing(&ptr[offset], priv->len[1]);\n for (i = 0; i < 3; i++) {\n memcpy(&ptr[offset], priv->packet[i], priv->len[i]);\n offset += priv->len[i];\n }\n *buf = av_realloc(*buf, offset + FF_INPUT_BUFFER_PADDING_SIZE);\n return offset;\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 = 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 posix_memalign(&ptr,16,size);\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
2,788
| 0
|
https://github.com/libav/libav/blob/cf6bae6883607f83f3b042b7b9d711197f736e2a/libavcodec/mlpdec.c/#L1076
|
static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MLPDecodeContext *m = avctx->priv_data;
GetBitContext gb;
unsigned int length, substr;
unsigned int substream_start;
unsigned int header_size = 4;
unsigned int substr_header_size = 0;
uint8_t substream_parity_present[MAX_SUBSTREAMS];
uint16_t substream_data_len[MAX_SUBSTREAMS];
uint8_t parity_bits;
if (buf_size < 4)
return 0;
length = (AV_RB16(buf) & 0xfff) * 2;
if (length > buf_size)
return -1;
init_get_bits(&gb, (buf + 4), (length - 4) * 8);
m->is_major_sync_unit = 0;
if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {
if (read_major_sync(m, &gb) < 0)
goto error;
m->is_major_sync_unit = 1;
header_size += 28;
}
if (!m->params_valid) {
av_log(m->avctx, AV_LOG_WARNING,
"Stream parameters not seen; skipping frame.\n");
*data_size = 0;
return length;
}
substream_start = 0;
for (substr = 0; substr < m->num_substreams; substr++) {
int extraword_present, checkdata_present, end, nonrestart_substr;
extraword_present = get_bits1(&gb);
nonrestart_substr = get_bits1(&gb);
checkdata_present = get_bits1(&gb);
skip_bits1(&gb);
end = get_bits(&gb, 12) * 2;
substr_header_size += 2;
if (extraword_present) {
if (m->avctx->codec_id == CODEC_ID_MLP) {
av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\n");
goto error;
}
skip_bits(&gb, 16);
substr_header_size += 2;
}
if (!(nonrestart_substr ^ m->is_major_sync_unit)) {
av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\n");
goto error;
}
if (end + header_size + substr_header_size > length) {
av_log(m->avctx, AV_LOG_ERROR,
"Indicated length of substream %d data goes off end of "
"packet.\n", substr);
end = length - header_size - substr_header_size;
}
if (end < substream_start) {
av_log(avctx, AV_LOG_ERROR,
"Indicated end offset of substream %d data "
"is smaller than calculated start offset.\n",
substr);
goto error;
}
if (substr > m->max_decoded_substream)
continue;
substream_parity_present[substr] = checkdata_present;
substream_data_len[substr] = end - substream_start;
substream_start = end;
}
parity_bits = ff_mlp_calculate_parity(buf, 4);
parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size);
if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {
av_log(avctx, AV_LOG_ERROR, "Parity check failed.\n");
goto error;
}
buf += header_size + substr_header_size;
for (substr = 0; substr <= m->max_decoded_substream; substr++) {
SubStream *s = &m->substream[substr];
init_get_bits(&gb, buf, substream_data_len[substr] * 8);
m->matrix_changed = 0;
memset(m->filter_changed, 0, sizeof(m->filter_changed));
s->blockpos = 0;
do {
if (get_bits1(&gb)) {
if (get_bits1(&gb)) {
if (read_restart_header(m, &gb, buf, substr) < 0)
goto next_substr;
s->restart_seen = 1;
}
if (!s->restart_seen)
goto next_substr;
if (read_decoding_params(m, &gb, substr) < 0)
goto next_substr;
}
if (!s->restart_seen)
goto next_substr;
if (read_block_data(m, &gb, substr) < 0)
return -1;
if (get_bits_count(&gb) >= substream_data_len[substr] * 8)
goto substream_length_mismatch;
} while (!get_bits1(&gb));
skip_bits(&gb, (-get_bits_count(&gb)) & 15);
if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32) {
int shorten_by;
if (get_bits(&gb, 16) != 0xD234)
return -1;
shorten_by = get_bits(&gb, 16);
if (m->avctx->codec_id == CODEC_ID_TRUEHD && shorten_by & 0x2000)
s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);
else if (m->avctx->codec_id == CODEC_ID_MLP && shorten_by != 0xD234)
return -1;
if (substr == m->max_decoded_substream)
av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\n");
}
if (substream_parity_present[substr]) {
uint8_t parity, checksum;
if (substream_data_len[substr] * 8 - get_bits_count(&gb) != 16)
goto substream_length_mismatch;
parity = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2);
checksum = ff_mlp_checksum8 (buf, substream_data_len[substr] - 2);
if ((get_bits(&gb, 8) ^ parity) != 0xa9 )
av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\n", substr);
if ( get_bits(&gb, 8) != checksum)
av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\n" , substr);
}
if (substream_data_len[substr] * 8 != get_bits_count(&gb))
goto substream_length_mismatch;
next_substr:
if (!s->restart_seen)
av_log(m->avctx, AV_LOG_ERROR,
"No restart header present in substream %d.\n", substr);
buf += substream_data_len[substr];
}
rematrix_channels(m, m->max_decoded_substream);
if (output_data(m, m->max_decoded_substream, data, data_size) < 0)
return -1;
return length;
substream_length_mismatch:
av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\n", substr);
return -1;
error:
m->params_valid = 0;
return -1;
}
|
['static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n MLPDecodeContext *m = avctx->priv_data;\n GetBitContext gb;\n unsigned int length, substr;\n unsigned int substream_start;\n unsigned int header_size = 4;\n unsigned int substr_header_size = 0;\n uint8_t substream_parity_present[MAX_SUBSTREAMS];\n uint16_t substream_data_len[MAX_SUBSTREAMS];\n uint8_t parity_bits;\n if (buf_size < 4)\n return 0;\n length = (AV_RB16(buf) & 0xfff) * 2;\n if (length > buf_size)\n return -1;\n init_get_bits(&gb, (buf + 4), (length - 4) * 8);\n m->is_major_sync_unit = 0;\n if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {\n if (read_major_sync(m, &gb) < 0)\n goto error;\n m->is_major_sync_unit = 1;\n header_size += 28;\n }\n if (!m->params_valid) {\n av_log(m->avctx, AV_LOG_WARNING,\n "Stream parameters not seen; skipping frame.\\n");\n *data_size = 0;\n return length;\n }\n substream_start = 0;\n for (substr = 0; substr < m->num_substreams; substr++) {\n int extraword_present, checkdata_present, end, nonrestart_substr;\n extraword_present = get_bits1(&gb);\n nonrestart_substr = get_bits1(&gb);\n checkdata_present = get_bits1(&gb);\n skip_bits1(&gb);\n end = get_bits(&gb, 12) * 2;\n substr_header_size += 2;\n if (extraword_present) {\n if (m->avctx->codec_id == CODEC_ID_MLP) {\n av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\\n");\n goto error;\n }\n skip_bits(&gb, 16);\n substr_header_size += 2;\n }\n if (!(nonrestart_substr ^ m->is_major_sync_unit)) {\n av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\\n");\n goto error;\n }\n if (end + header_size + substr_header_size > length) {\n av_log(m->avctx, AV_LOG_ERROR,\n "Indicated length of substream %d data goes off end of "\n "packet.\\n", substr);\n end = length - header_size - substr_header_size;\n }\n if (end < substream_start) {\n av_log(avctx, AV_LOG_ERROR,\n "Indicated end offset of substream %d data "\n "is smaller than calculated start offset.\\n",\n substr);\n goto error;\n }\n if (substr > m->max_decoded_substream)\n continue;\n substream_parity_present[substr] = checkdata_present;\n substream_data_len[substr] = end - substream_start;\n substream_start = end;\n }\n parity_bits = ff_mlp_calculate_parity(buf, 4);\n parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size);\n if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {\n av_log(avctx, AV_LOG_ERROR, "Parity check failed.\\n");\n goto error;\n }\n buf += header_size + substr_header_size;\n for (substr = 0; substr <= m->max_decoded_substream; substr++) {\n SubStream *s = &m->substream[substr];\n init_get_bits(&gb, buf, substream_data_len[substr] * 8);\n m->matrix_changed = 0;\n memset(m->filter_changed, 0, sizeof(m->filter_changed));\n s->blockpos = 0;\n do {\n if (get_bits1(&gb)) {\n if (get_bits1(&gb)) {\n if (read_restart_header(m, &gb, buf, substr) < 0)\n goto next_substr;\n s->restart_seen = 1;\n }\n if (!s->restart_seen)\n goto next_substr;\n if (read_decoding_params(m, &gb, substr) < 0)\n goto next_substr;\n }\n if (!s->restart_seen)\n goto next_substr;\n if (read_block_data(m, &gb, substr) < 0)\n return -1;\n if (get_bits_count(&gb) >= substream_data_len[substr] * 8)\n goto substream_length_mismatch;\n } while (!get_bits1(&gb));\n skip_bits(&gb, (-get_bits_count(&gb)) & 15);\n if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32) {\n int shorten_by;\n if (get_bits(&gb, 16) != 0xD234)\n return -1;\n shorten_by = get_bits(&gb, 16);\n if (m->avctx->codec_id == CODEC_ID_TRUEHD && shorten_by & 0x2000)\n s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);\n else if (m->avctx->codec_id == CODEC_ID_MLP && shorten_by != 0xD234)\n return -1;\n if (substr == m->max_decoded_substream)\n av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\\n");\n }\n if (substream_parity_present[substr]) {\n uint8_t parity, checksum;\n if (substream_data_len[substr] * 8 - get_bits_count(&gb) != 16)\n goto substream_length_mismatch;\n parity = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2);\n checksum = ff_mlp_checksum8 (buf, substream_data_len[substr] - 2);\n if ((get_bits(&gb, 8) ^ parity) != 0xa9 )\n av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\\n", substr);\n if ( get_bits(&gb, 8) != checksum)\n av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\\n" , substr);\n }\n if (substream_data_len[substr] * 8 != get_bits_count(&gb))\n goto substream_length_mismatch;\nnext_substr:\n if (!s->restart_seen)\n av_log(m->avctx, AV_LOG_ERROR,\n "No restart header present in substream %d.\\n", substr);\n buf += substream_data_len[substr];\n }\n rematrix_channels(m, m->max_decoded_substream);\n if (output_data(m, m->max_decoded_substream, data, data_size) < 0)\n return -1;\n return length;\nsubstream_length_mismatch:\n av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\\n", substr);\n return -1;\nerror:\n m->params_valid = 0;\n return -1;\n}']
|
2,789
| 1
|
https://github.com/nginx/nginx/blob/2d9db482aa92194a2258334545908d620b6dd214/src/http/ngx_http_core_module.c/#L1557
|
void
ngx_http_set_exten(ngx_http_request_t *r)
{
ngx_int_t i;
ngx_str_null(&r->exten);
for (i = r->uri.len - 1; i > 1; i--) {
if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {
r->exten.len = r->uri.len - i - 1;
r->exten.data = &r->uri.data[i + 1];
return;
} else if (r->uri.data[i] == '/') {
return;
}
}
return;
}
|
['static void\nngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n ssize_t n;\n ngx_int_t rc;\n ngx_connection_t *c;\n c = u->peer.connection;\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http upstream process header");\n c->log->action = "reading response header from upstream";\n if (c->read->timedout) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);\n return;\n }\n if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n return;\n }\n if (u->buffer.start == NULL) {\n u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size);\n if (u->buffer.start == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->buffer.pos = u->buffer.start;\n u->buffer.last = u->buffer.start;\n u->buffer.end = u->buffer.start + u->conf->buffer_size;\n u->buffer.temporary = 1;\n u->buffer.tag = u->output.tag;\n if (ngx_list_init(&u->headers_in.headers, r->pool, 8,\n sizeof(ngx_table_elt_t))\n != NGX_OK)\n {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n#if (NGX_HTTP_CACHE)\n if (r->cache) {\n u->buffer.pos += r->cache->header_start;\n u->buffer.last = u->buffer.pos;\n }\n#endif\n }\n for ( ;; ) {\n n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);\n if (n == NGX_AGAIN) {\n#if 0\n ngx_add_timer(rev, u->read_timeout);\n#endif\n if (ngx_handle_read_event(c->read, 0) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n return;\n }\n if (n == 0) {\n ngx_log_error(NGX_LOG_ERR, c->log, 0,\n "upstream prematurely closed connection");\n }\n if (n == NGX_ERROR || n == 0) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n return;\n }\n u->state->bytes_received += n;\n u->buffer.last += n;\n#if 0\n u->valid_header_in = 0;\n u->peer.cached = 0;\n#endif\n rc = u->process_header(r);\n if (rc == NGX_AGAIN) {\n if (u->buffer.last == u->buffer.end) {\n ngx_log_error(NGX_LOG_ERR, c->log, 0,\n "upstream sent too big header");\n ngx_http_upstream_next(r, u,\n NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);\n return;\n }\n continue;\n }\n break;\n }\n if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);\n return;\n }\n if (rc == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->state->header_time = ngx_current_msec - u->state->response_time;\n if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) {\n if (ngx_http_upstream_test_next(r, u) == NGX_OK) {\n return;\n }\n if (ngx_http_upstream_intercept_errors(r, u) == NGX_OK) {\n return;\n }\n }\n if (ngx_http_upstream_process_headers(r, u) != NGX_OK) {\n return;\n }\n if (!r->subrequest_in_memory) {\n ngx_http_upstream_send_response(r, u);\n return;\n }\n if (u->input_filter == NULL) {\n u->input_filter_init = ngx_http_upstream_non_buffered_filter_init;\n u->input_filter = ngx_http_upstream_non_buffered_filter;\n u->input_filter_ctx = r;\n }\n if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n return;\n }\n n = u->buffer.last - u->buffer.pos;\n if (n) {\n u->buffer.last = u->buffer.pos;\n u->state->response_length += n;\n if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n return;\n }\n }\n if (u->length == 0) {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n u->read_event_handler = ngx_http_upstream_process_body_in_memory;\n ngx_http_upstream_process_body_in_memory(r, u);\n}', "static ngx_int_t\nngx_http_upstream_process_headers(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n ngx_str_t uri, args;\n ngx_uint_t i, flags;\n ngx_list_part_t *part;\n ngx_table_elt_t *h;\n ngx_http_upstream_header_t *hh;\n ngx_http_upstream_main_conf_t *umcf;\n umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);\n if (u->headers_in.x_accel_redirect\n && !(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT))\n {\n ngx_http_upstream_finalize_request(r, u, NGX_DECLINED);\n part = &u->headers_in.headers.part;\n h = part->elts;\n for (i = 0; ; i++) {\n if (i >= part->nelts) {\n if (part->next == NULL) {\n break;\n }\n part = part->next;\n h = part->elts;\n i = 0;\n }\n hh = ngx_hash_find(&umcf->headers_in_hash, h[i].hash,\n h[i].lowcase_key, h[i].key.len);\n if (hh && hh->redirect) {\n if (hh->copy_handler(r, &h[i], hh->conf) != NGX_OK) {\n ngx_http_finalize_request(r,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n }\n }\n uri = u->headers_in.x_accel_redirect->value;\n if (uri.data[0] == '@') {\n ngx_http_named_location(r, &uri);\n } else {\n ngx_str_null(&args);\n flags = NGX_HTTP_LOG_UNSAFE;\n if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags) != NGX_OK) {\n ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);\n return NGX_DONE;\n }\n if (r->method != NGX_HTTP_HEAD) {\n r->method = NGX_HTTP_GET;\n r->method_name = ngx_http_core_get_method;\n }\n ngx_http_internal_redirect(r, &uri, &args);\n }\n ngx_http_finalize_request(r, NGX_DONE);\n return NGX_DONE;\n }\n part = &u->headers_in.headers.part;\n h = part->elts;\n for (i = 0; ; i++) {\n if (i >= part->nelts) {\n if (part->next == NULL) {\n break;\n }\n part = part->next;\n h = part->elts;\n i = 0;\n }\n if (ngx_hash_find(&u->conf->hide_headers_hash, h[i].hash,\n h[i].lowcase_key, h[i].key.len))\n {\n continue;\n }\n hh = ngx_hash_find(&umcf->headers_in_hash, h[i].hash,\n h[i].lowcase_key, h[i].key.len);\n if (hh) {\n if (hh->copy_handler(r, &h[i], hh->conf) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n continue;\n }\n if (ngx_http_upstream_copy_header_line(r, &h[i], 0) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n }\n if (r->headers_out.server && r->headers_out.server->value.data == NULL) {\n r->headers_out.server->hash = 0;\n }\n if (r->headers_out.date && r->headers_out.date->value.data == NULL) {\n r->headers_out.date->hash = 0;\n }\n r->headers_out.status = u->headers_in.status_n;\n r->headers_out.status_line = u->headers_in.status_line;\n r->headers_out.content_length_n = u->headers_in.content_length_n;\n r->disable_not_modified = !u->cacheable;\n if (u->conf->force_ranges) {\n r->allow_ranges = 1;\n r->single_range = 1;\n#if (NGX_HTTP_CACHE)\n if (r->cached) {\n r->single_range = 0;\n }\n#endif\n }\n u->length = -1;\n return NGX_OK;\n}", 'static void\nngx_http_upstream_process_body_in_memory(ngx_http_request_t *r,\n ngx_http_upstream_t *u)\n{\n size_t size;\n ssize_t n;\n ngx_buf_t *b;\n ngx_event_t *rev;\n ngx_connection_t *c;\n c = u->peer.connection;\n rev = c->read;\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http upstream process body in memory");\n if (rev->timedout) {\n ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");\n ngx_http_upstream_finalize_request(r, u, NGX_HTTP_GATEWAY_TIME_OUT);\n return;\n }\n b = &u->buffer;\n for ( ;; ) {\n size = b->end - b->last;\n if (size == 0) {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "upstream buffer is too small to read response");\n ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n return;\n }\n n = c->recv(c, b->last, size);\n if (n == NGX_AGAIN) {\n break;\n }\n if (n == 0 || n == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u, n);\n return;\n }\n u->state->bytes_received += n;\n u->state->response_length += n;\n if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n return;\n }\n if (!rev->ready) {\n break;\n }\n }\n if (u->length == 0) {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n if (ngx_handle_read_event(rev, 0) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n return;\n }\n if (rev->active) {\n ngx_add_timer(rev, u->conf->read_timeout);\n } else if (rev->timer_set) {\n ngx_del_timer(rev);\n }\n}', 'static void\nngx_http_upstream_finalize_request(ngx_http_request_t *r,\n ngx_http_upstream_t *u, ngx_int_t rc)\n{\n ngx_uint_t flush;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "finalize http upstream request: %i", rc);\n if (u->cleanup == NULL) {\n ngx_http_finalize_request(r, NGX_DONE);\n return;\n }\n *u->cleanup = NULL;\n u->cleanup = NULL;\n if (u->resolved && u->resolved->ctx) {\n ngx_resolve_name_done(u->resolved->ctx);\n u->resolved->ctx = NULL;\n }\n if (u->state && u->state->response_time) {\n u->state->response_time = ngx_current_msec - u->state->response_time;\n if (u->pipe && u->pipe->read_length) {\n u->state->bytes_received += u->pipe->read_length\n - u->pipe->preread_size;\n u->state->response_length = u->pipe->read_length;\n }\n }\n u->finalize_request(r, rc);\n if (u->peer.free && u->peer.sockaddr) {\n u->peer.free(&u->peer, u->peer.data, 0);\n u->peer.sockaddr = NULL;\n }\n if (u->peer.connection) {\n#if (NGX_HTTP_SSL)\n if (u->peer.connection->ssl) {\n u->peer.connection->ssl->no_wait_shutdown = 1;\n (void) ngx_ssl_shutdown(u->peer.connection);\n }\n#endif\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "close http upstream connection: %d",\n u->peer.connection->fd);\n if (u->peer.connection->pool) {\n ngx_destroy_pool(u->peer.connection->pool);\n }\n ngx_close_connection(u->peer.connection);\n }\n u->peer.connection = NULL;\n if (u->pipe && u->pipe->temp_file) {\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http upstream temp fd: %d",\n u->pipe->temp_file->file.fd);\n }\n if (u->store && u->pipe && u->pipe->temp_file\n && u->pipe->temp_file->file.fd != NGX_INVALID_FILE)\n {\n if (ngx_delete_file(u->pipe->temp_file->file.name.data)\n == NGX_FILE_ERROR)\n {\n ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,\n ngx_delete_file_n " \\"%s\\" failed",\n u->pipe->temp_file->file.name.data);\n }\n }\n#if (NGX_HTTP_CACHE)\n if (r->cache) {\n if (u->cacheable) {\n if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {\n time_t valid;\n valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc);\n if (valid) {\n r->cache->valid_sec = ngx_time() + valid;\n r->cache->error = rc;\n }\n }\n }\n ngx_http_file_cache_free(r->cache, u->pipe->temp_file);\n }\n#endif\n if (r->subrequest_in_memory\n && u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE)\n {\n u->buffer.last = u->buffer.pos;\n }\n r->read_event_handler = ngx_http_block_reading;\n if (rc == NGX_DECLINED) {\n return;\n }\n r->connection->log->action = "sending to client";\n if (!u->header_sent\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST)\n {\n ngx_http_finalize_request(r, rc);\n return;\n }\n flush = 0;\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {\n rc = NGX_ERROR;\n flush = 1;\n }\n if (r->header_only\n || (u->pipe && u->pipe->downstream_error))\n {\n ngx_http_finalize_request(r, rc);\n return;\n }\n if (rc == 0) {\n rc = ngx_http_send_special(r, NGX_HTTP_LAST);\n } else if (flush) {\n r->keepalive = 0;\n rc = ngx_http_send_special(r, NGX_HTTP_FLUSH);\n }\n ngx_http_finalize_request(r, rc);\n}', 'void\nngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)\n{\n ngx_connection_t *c;\n ngx_http_request_t *pr;\n ngx_http_core_loc_conf_t *clcf;\n c = r->connection;\n ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize request: %i, \\"%V?%V\\" a:%d, c:%d",\n rc, &r->uri, &r->args, r == c->data, r->main->count);\n if (rc == NGX_DONE) {\n ngx_http_finalize_connection(r);\n return;\n }\n if (rc == NGX_OK && r->filter_finalize) {\n c->error = 1;\n }\n if (rc == NGX_DECLINED) {\n r->content_handler = NULL;\n r->write_event_handler = ngx_http_core_run_phases;\n ngx_http_core_run_phases(r);\n return;\n }\n if (r != r->main && r->post_subrequest) {\n rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);\n }\n if (rc == NGX_ERROR\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n || c->error)\n {\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE\n || rc == NGX_HTTP_CREATED\n || rc == NGX_HTTP_NO_CONTENT)\n {\n if (rc == NGX_HTTP_CLOSE) {\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (r == r->main) {\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n ngx_del_timer(c->write);\n }\n }\n c->read->handler = ngx_http_request_handler;\n c->write->handler = ngx_http_request_handler;\n ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));\n return;\n }\n if (r != r->main) {\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (r->background) {\n if (!r->logged) {\n if (clcf->log_subrequest) {\n ngx_http_log_request(r);\n }\n r->logged = 1;\n } else {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "subrequest: \\"%V?%V\\" logged again",\n &r->uri, &r->args);\n }\n r->done = 1;\n ngx_http_finalize_connection(r);\n return;\n }\n if (r->buffered || r->postponed) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n pr = r->parent;\n if (r == c->data) {\n r->main->count--;\n if (!r->logged) {\n if (clcf->log_subrequest) {\n ngx_http_log_request(r);\n }\n r->logged = 1;\n } else {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "subrequest: \\"%V?%V\\" logged again",\n &r->uri, &r->args);\n }\n r->done = 1;\n if (pr->postponed && pr->postponed->request == r) {\n pr->postponed = pr->postponed->next;\n }\n c->data = pr;\n } else {\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n r->write_event_handler = ngx_http_request_finalizer;\n if (r->waited) {\n r->done = 1;\n }\n }\n if (ngx_http_post_request(pr, NULL) != NGX_OK) {\n r->main->count++;\n ngx_http_terminate_request(r, 0);\n return;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http wake parent request: \\"%V?%V\\"",\n &pr->uri, &pr->args);\n return;\n }\n if (r->buffered || c->buffered || r->postponed) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n if (r != c->data) {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n return;\n }\n r->done = 1;\n r->read_event_handler = ngx_http_block_reading;\n r->write_event_handler = ngx_http_request_empty_handler;\n if (!r->post_action) {\n r->request_complete = 1;\n }\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n c->write->delayed = 0;\n ngx_del_timer(c->write);\n }\n if (c->read->eof) {\n ngx_http_close_request(r, 0);\n return;\n }\n ngx_http_finalize_connection(r);\n}', 'ngx_int_t\nngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)\n{\n ngx_uint_t i, err;\n ngx_http_err_page_t *err_page;\n ngx_http_core_loc_conf_t *clcf;\n ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http special response: %i, \\"%V?%V\\"",\n error, &r->uri, &r->args);\n r->err_status = error;\n if (r->keepalive) {\n switch (error) {\n case NGX_HTTP_BAD_REQUEST:\n case NGX_HTTP_REQUEST_ENTITY_TOO_LARGE:\n case NGX_HTTP_REQUEST_URI_TOO_LARGE:\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n case NGX_HTTP_INTERNAL_SERVER_ERROR:\n case NGX_HTTP_NOT_IMPLEMENTED:\n r->keepalive = 0;\n }\n }\n if (r->lingering_close) {\n switch (error) {\n case NGX_HTTP_BAD_REQUEST:\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n r->lingering_close = 0;\n }\n }\n r->headers_out.content_type.len = 0;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (!r->error_page && clcf->error_pages && r->uri_changes != 0) {\n if (clcf->recursive_error_pages == 0) {\n r->error_page = 1;\n }\n err_page = clcf->error_pages->elts;\n for (i = 0; i < clcf->error_pages->nelts; i++) {\n if (err_page[i].status == error) {\n return ngx_http_send_error_page(r, &err_page[i]);\n }\n }\n }\n r->expect_tested = 1;\n if (ngx_http_discard_request_body(r) != NGX_OK) {\n r->keepalive = 0;\n }\n if (clcf->msie_refresh\n && r->headers_in.msie\n && (error == NGX_HTTP_MOVED_PERMANENTLY\n || error == NGX_HTTP_MOVED_TEMPORARILY))\n {\n return ngx_http_send_refresh(r);\n }\n if (error == NGX_HTTP_CREATED) {\n err = 0;\n } else if (error == NGX_HTTP_NO_CONTENT) {\n err = 0;\n } else if (error >= NGX_HTTP_MOVED_PERMANENTLY\n && error < NGX_HTTP_LAST_3XX)\n {\n err = error - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_OFF_3XX;\n } else if (error >= NGX_HTTP_BAD_REQUEST\n && error < NGX_HTTP_LAST_4XX)\n {\n err = error - NGX_HTTP_BAD_REQUEST + NGX_HTTP_OFF_4XX;\n } else if (error >= NGX_HTTP_NGINX_CODES\n && error < NGX_HTTP_LAST_5XX)\n {\n err = error - NGX_HTTP_NGINX_CODES + NGX_HTTP_OFF_5XX;\n switch (error) {\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n case NGX_HTTP_REQUEST_HEADER_TOO_LARGE:\n r->err_status = NGX_HTTP_BAD_REQUEST;\n }\n } else {\n err = 0;\n }\n return ngx_http_send_special_response(r, clcf, err);\n}', 'static ngx_int_t\nngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)\n{\n ngx_int_t overwrite;\n ngx_str_t uri, args;\n ngx_table_elt_t *location;\n ngx_http_core_loc_conf_t *clcf;\n overwrite = err_page->overwrite;\n if (overwrite && overwrite != NGX_HTTP_OK) {\n r->expect_tested = 1;\n }\n if (overwrite >= 0) {\n r->err_status = overwrite;\n }\n if (ngx_http_complex_value(r, &err_page->value, &uri) != NGX_OK) {\n return NGX_ERROR;\n }\n if (uri.len && uri.data[0] == \'/\') {\n if (err_page->value.lengths) {\n ngx_http_split_args(r, &uri, &args);\n } else {\n args = err_page->args;\n }\n if (r->method != NGX_HTTP_HEAD) {\n r->method = NGX_HTTP_GET;\n r->method_name = ngx_http_core_get_method;\n }\n return ngx_http_internal_redirect(r, &uri, &args);\n }\n if (uri.len && uri.data[0] == \'@\') {\n return ngx_http_named_location(r, &uri);\n }\n location = ngx_list_push(&r->headers_out.headers);\n if (location == NULL) {\n return NGX_ERROR;\n }\n if (overwrite != NGX_HTTP_MOVED_PERMANENTLY\n && overwrite != NGX_HTTP_MOVED_TEMPORARILY\n && overwrite != NGX_HTTP_SEE_OTHER\n && overwrite != NGX_HTTP_TEMPORARY_REDIRECT\n && overwrite != NGX_HTTP_PERMANENT_REDIRECT)\n {\n r->err_status = NGX_HTTP_MOVED_TEMPORARILY;\n }\n location->hash = 1;\n ngx_str_set(&location->key, "Location");\n location->value = uri;\n ngx_http_clear_location(r);\n r->headers_out.location = location;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->msie_refresh && r->headers_in.msie) {\n return ngx_http_send_refresh(r);\n }\n return ngx_http_send_special_response(r, clcf, r->err_status\n - NGX_HTTP_MOVED_PERMANENTLY\n + NGX_HTTP_OFF_3XX);\n}', 'ngx_int_t\nngx_http_internal_redirect(ngx_http_request_t *r,\n ngx_str_t *uri, ngx_str_t *args)\n{\n ngx_http_core_srv_conf_t *cscf;\n r->uri_changes--;\n if (r->uri_changes == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "rewrite or internal redirection cycle "\n "while internally redirecting to \\"%V\\"", uri);\n r->main->count++;\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n r->uri = *uri;\n if (args) {\n r->args = *args;\n } else {\n ngx_str_null(&r->args);\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "internal redirect: \\"%V?%V\\"", uri, &r->args);\n ngx_http_set_exten(r);\n ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);\n cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n r->loc_conf = cscf->ctx->loc_conf;\n ngx_http_update_location_config(r);\n#if (NGX_HTTP_CACHE)\n r->cache = NULL;\n#endif\n r->internal = 1;\n r->valid_unparsed_uri = 0;\n r->add_uri_to_alias = 0;\n r->main->count++;\n ngx_http_handler(r);\n return NGX_DONE;\n}', "void\nngx_http_set_exten(ngx_http_request_t *r)\n{\n ngx_int_t i;\n ngx_str_null(&r->exten);\n for (i = r->uri.len - 1; i > 1; i--) {\n if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {\n r->exten.len = r->uri.len - i - 1;\n r->exten.data = &r->uri.data[i + 1];\n return;\n } else if (r->uri.data[i] == '/') {\n return;\n }\n }\n return;\n}"]
|
2,790
| 0
|
https://github.com/openssl/openssl/blob/f345b1f39d9b4e4c9ef07e7522e9b2a870c9ca09/crypto/bn/bn_lib.c/#L363
|
int BN_set_word(BIGNUM *a, BN_ULONG w)
{
bn_check_top(a);
if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
return 0;
a->neg = 0;
a->d[0] = w;
a->top = (w ? 1 : 0);
bn_check_top(a);
return 1;
}
|
['int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,\n BIGNUM **verifier, const BIGNUM *N,\n const BIGNUM *g)\n{\n int result = 0;\n BIGNUM *x = NULL;\n BN_CTX *bn_ctx = BN_CTX_new();\n unsigned char tmp2[MAX_LEN];\n BIGNUM *salttmp = NULL;\n if ((user == NULL) ||\n (pass == NULL) ||\n (salt == NULL) ||\n (verifier == NULL) || (N == NULL) || (g == NULL) || (bn_ctx == NULL))\n goto err;\n if (*salt == NULL) {\n if (RAND_bytes(tmp2, SRP_RANDOM_SALT_LEN) <= 0)\n goto err;\n salttmp = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);\n } else {\n salttmp = *salt;\n }\n x = SRP_Calc_x(salttmp, user, pass);\n *verifier = BN_new();\n if (*verifier == NULL)\n goto err;\n if (!BN_mod_exp(*verifier, g, x, N, bn_ctx)) {\n BN_clear_free(*verifier);\n goto err;\n }\n result = 1;\n *salt = salttmp;\n err:\n if (salt != NULL && *salt != salttmp)\n BN_clear_free(salttmp);\n BN_clear_free(x);\n BN_CTX_free(bn_ctx);\n return result;\n}', 'BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass)\n{\n unsigned char dig[SHA_DIGEST_LENGTH];\n EVP_MD_CTX *ctxt;\n unsigned char *cs = NULL;\n BIGNUM *res = NULL;\n if ((s == NULL) || (user == NULL) || (pass == NULL))\n return NULL;\n ctxt = EVP_MD_CTX_new();\n if (ctxt == NULL)\n return NULL;\n if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL)\n goto err;\n if (!EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)\n || !EVP_DigestUpdate(ctxt, user, strlen(user))\n || !EVP_DigestUpdate(ctxt, ":", 1)\n || !EVP_DigestUpdate(ctxt, pass, strlen(pass))\n || !EVP_DigestFinal_ex(ctxt, dig, NULL)\n || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL))\n goto err;\n BN_bn2bin(s, cs);\n if (!EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s)))\n goto err;\n if (!EVP_DigestUpdate(ctxt, dig, sizeof(dig))\n || !EVP_DigestFinal_ex(ctxt, dig, NULL))\n goto err;\n res = BN_bin2bn(dig, sizeof(dig), NULL);\n err:\n OPENSSL_free(cs);\n EVP_MD_CTX_free(ctxt);\n return res;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return NULL;\n bn_check_top(ret);\n for ( ; len > 0 && *s == 0; s++, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return ret;\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n l = (l << 8L) | *(s++);\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\n return ret;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}']
|
2,791
| 0
|
https://github.com/openssl/openssl/blob/270a4bba49849de7f928f4fab186205abd132411/crypto/objects/o_names.c/#L130
|
int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
int (*cmp_func) (const char *, const char *),
void (*free_func) (const char *, int, const char *))
{
int ret = 0, i, push;
NAME_FUNCS *name_funcs;
if (!OBJ_NAME_init())
return 0;
CRYPTO_THREAD_write_lock(obj_lock);
if (name_funcs_stack == NULL) {
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
name_funcs_stack = sk_NAME_FUNCS_new_null();
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
}
if (name_funcs_stack == NULL) {
goto out;
}
ret = names_type_num;
names_type_num++;
for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) {
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
name_funcs = OPENSSL_zalloc(sizeof(*name_funcs));
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
if (name_funcs == NULL) {
OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);
ret = 0;
goto out;
}
name_funcs->hash_func = OPENSSL_LH_strhash;
name_funcs->cmp_func = obj_strcmp;
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
push = sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
if (!push) {
OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);
OPENSSL_free(name_funcs);
ret = 0;
goto out;
}
}
name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
if (hash_func != NULL)
name_funcs->hash_func = hash_func;
if (cmp_func != NULL)
name_funcs->cmp_func = cmp_func;
if (free_func != NULL)
name_funcs->free_func = free_func;
out:
CRYPTO_THREAD_unlock(obj_lock);
return ret;
}
|
['int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),\n int (*cmp_func) (const char *, const char *),\n void (*free_func) (const char *, int, const char *))\n{\n int ret = 0, i, push;\n NAME_FUNCS *name_funcs;\n if (!OBJ_NAME_init())\n return 0;\n CRYPTO_THREAD_write_lock(obj_lock);\n if (name_funcs_stack == NULL) {\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n name_funcs_stack = sk_NAME_FUNCS_new_null();\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n }\n if (name_funcs_stack == NULL) {\n goto out;\n }\n ret = names_type_num;\n names_type_num++;\n for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) {\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n name_funcs = OPENSSL_zalloc(sizeof(*name_funcs));\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n if (name_funcs == NULL) {\n OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);\n ret = 0;\n goto out;\n }\n name_funcs->hash_func = OPENSSL_LH_strhash;\n name_funcs->cmp_func = obj_strcmp;\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n push = sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n if (!push) {\n OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(name_funcs);\n ret = 0;\n goto out;\n }\n }\n name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);\n if (hash_func != NULL)\n name_funcs->hash_func = hash_func;\n if (cmp_func != NULL)\n name_funcs->cmp_func = cmp_func;\n if (free_func != NULL)\n name_funcs->free_func = free_func;\nout:\n CRYPTO_THREAD_unlock(obj_lock);\n return ret;\n}', 'int OBJ_NAME_init(void)\n{\n return RUN_ONCE(&init, o_names_init);\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n if (pthread_rwlock_wrlock(lock) != 0)\n return 0;\n# else\n if (pthread_mutex_lock(lock) != 0)\n return 0;\n# endif\n return 1;\n}', 'int CRYPTO_mem_ctrl(int mode)\n{\n#ifdef OPENSSL_NO_CRYPTO_MDEBUG\n return mode - mode;\n#else\n int ret = mh_mode;\n if (!RUN_ONCE(&memdbg_init, do_memdbg_init))\n return -1;\n CRYPTO_THREAD_write_lock(malloc_lock);\n switch (mode) {\n default:\n break;\n case CRYPTO_MEM_CHECK_ON:\n mh_mode = CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE;\n num_disable = 0;\n break;\n case CRYPTO_MEM_CHECK_OFF:\n mh_mode = 0;\n num_disable = 0;\n break;\n case CRYPTO_MEM_CHECK_DISABLE:\n if (mh_mode & CRYPTO_MEM_CHECK_ON) {\n CRYPTO_THREAD_ID cur = CRYPTO_THREAD_get_current_id();\n if (!num_disable\n || !CRYPTO_THREAD_compare_id(disabling_threadid, cur)) {\n CRYPTO_THREAD_unlock(malloc_lock);\n CRYPTO_THREAD_write_lock(long_malloc_lock);\n CRYPTO_THREAD_write_lock(malloc_lock);\n mh_mode &= ~CRYPTO_MEM_CHECK_ENABLE;\n disabling_threadid = cur;\n }\n num_disable++;\n }\n break;\n case CRYPTO_MEM_CHECK_ENABLE:\n if (mh_mode & CRYPTO_MEM_CHECK_ON) {\n if (num_disable) {\n num_disable--;\n if (num_disable == 0) {\n mh_mode |= CRYPTO_MEM_CHECK_ENABLE;\n CRYPTO_THREAD_unlock(long_malloc_lock);\n }\n }\n }\n break;\n }\n CRYPTO_THREAD_unlock(malloc_lock);\n return ret;\n#endif\n}', 'OPENSSL_STACK *OPENSSL_sk_new_null(void)\n{\n return OPENSSL_zalloc(sizeof(OPENSSL_STACK));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int OPENSSL_sk_num(const OPENSSL_STACK *st)\n{\n if (st == NULL)\n return -1;\n return st->num;\n}', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n if (st == NULL || i < 0 || i >= st->num)\n return NULL;\n return (void *)st->data[i];\n}']
|
2,792
| 0
|
https://github.com/openssl/openssl/blob/7144c4212a18e01bf805169ad1f3fdd885975759/crypto/pkcs7/pk7_doit.c/#L577
|
BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
{
int i,j;
BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;
X509_ALGOR *xa;
ASN1_OCTET_STRING *data_body=NULL;
const EVP_MD *evp_md;
const EVP_CIPHER *evp_cipher=NULL;
EVP_CIPHER_CTX *evp_ctx=NULL;
X509_ALGOR *enc_alg=NULL;
STACK_OF(X509_ALGOR) *md_sk=NULL;
STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
X509_ALGOR *xalg=NULL;
PKCS7_RECIP_INFO *ri=NULL;
i=OBJ_obj2nid(p7->type);
p7->state=PKCS7_S_HEADER;
switch (i)
{
case NID_pkcs7_signed:
data_body=PKCS7_get_octet_string(p7->d.sign->contents);
md_sk=p7->d.sign->md_algs;
break;
case NID_pkcs7_signedAndEnveloped:
rsk=p7->d.signed_and_enveloped->recipientinfo;
md_sk=p7->d.signed_and_enveloped->md_algs;
data_body=p7->d.signed_and_enveloped->enc_data->enc_data;
enc_alg=p7->d.signed_and_enveloped->enc_data->algorithm;
evp_cipher=EVP_get_cipherbyobj(enc_alg->algorithm);
if (evp_cipher == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
goto err;
}
xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
break;
case NID_pkcs7_enveloped:
rsk=p7->d.enveloped->recipientinfo;
enc_alg=p7->d.enveloped->enc_data->algorithm;
data_body=p7->d.enveloped->enc_data->enc_data;
evp_cipher=EVP_get_cipherbyobj(enc_alg->algorithm);
if (evp_cipher == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
goto err;
}
xalg=p7->d.enveloped->enc_data->algorithm;
break;
default:
PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
goto err;
}
if (md_sk != NULL)
{
for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
{
xa=sk_X509_ALGOR_value(md_sk,i);
if ((btmp=BIO_new(BIO_f_md())) == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
goto err;
}
j=OBJ_obj2nid(xa->algorithm);
evp_md=EVP_get_digestbynid(j);
if (evp_md == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE);
goto err;
}
BIO_set_md(btmp,evp_md);
if (out == NULL)
out=btmp;
else
BIO_push(out,btmp);
btmp=NULL;
}
}
if (evp_cipher != NULL)
{
#if 0
unsigned char key[EVP_MAX_KEY_LENGTH];
unsigned char iv[EVP_MAX_IV_LENGTH];
unsigned char *p;
int keylen,ivlen;
int max;
X509_OBJECT ret;
#endif
unsigned char *ek = NULL;
int eklen;
if ((etmp=BIO_new(BIO_f_cipher())) == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
goto err;
}
if (pcert)
{
for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
{
ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
if (!pkcs7_cmp_ri(ri, pcert))
break;
ri=NULL;
}
if (ri == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,
PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
goto err;
}
}
if (pcert == NULL)
{
for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
{
ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
if (pkcs7_decrypt_rinfo(&ek, &eklen,
ri, pkey) > 0)
break;
ERR_clear_error();
ri = NULL;
}
if (ri == NULL)
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,
PKCS7_R_NO_RECIPIENT_MATCHES_KEY);
goto err;
}
}
else
{
if (pkcs7_decrypt_rinfo(&ek, &eklen, ri, pkey) <= 0)
goto err;
}
evp_ctx=NULL;
BIO_get_cipher_ctx(etmp,&evp_ctx);
if (EVP_CipherInit_ex(evp_ctx,evp_cipher,NULL,NULL,NULL,0) <= 0)
goto err;
if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)
goto err;
if (eklen != EVP_CIPHER_CTX_key_length(evp_ctx)) {
if(!EVP_CIPHER_CTX_set_key_length(evp_ctx, eklen))
{
PKCS7err(PKCS7_F_PKCS7_DATADECODE,
PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH);
goto err;
}
}
if (EVP_CipherInit_ex(evp_ctx,NULL,NULL,ek,NULL,0) <= 0)
goto err;
if (ek)
{
OPENSSL_cleanse(ek,eklen);
OPENSSL_free(ek);
}
if (out == NULL)
out=etmp;
else
BIO_push(out,etmp);
etmp=NULL;
}
#if 1
if (PKCS7_is_detached(p7) || (in_bio != NULL))
{
bio=in_bio;
}
else
{
#if 0
bio=BIO_new(BIO_s_mem());
BIO_set_mem_eof_return(bio,0);
if (data_body->length > 0)
BIO_write(bio,(char *)data_body->data,data_body->length);
#else
if (data_body->length > 0)
bio = BIO_new_mem_buf(data_body->data,data_body->length);
else {
bio=BIO_new(BIO_s_mem());
BIO_set_mem_eof_return(bio,0);
}
#endif
}
BIO_push(out,bio);
bio=NULL;
#endif
if (0)
{
err:
if (out != NULL) BIO_free_all(out);
if (btmp != NULL) BIO_free_all(btmp);
if (etmp != NULL) BIO_free_all(etmp);
if (bio != NULL) BIO_free_all(bio);
out=NULL;
}
return(out);
}
|
['BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)\n\t{\n\tint i,j;\n\tBIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;\n\tX509_ALGOR *xa;\n\tASN1_OCTET_STRING *data_body=NULL;\n\tconst EVP_MD *evp_md;\n\tconst EVP_CIPHER *evp_cipher=NULL;\n\tEVP_CIPHER_CTX *evp_ctx=NULL;\n\tX509_ALGOR *enc_alg=NULL;\n\tSTACK_OF(X509_ALGOR) *md_sk=NULL;\n\tSTACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;\n\tX509_ALGOR *xalg=NULL;\n\tPKCS7_RECIP_INFO *ri=NULL;\n\ti=OBJ_obj2nid(p7->type);\n\tp7->state=PKCS7_S_HEADER;\n\tswitch (i)\n\t\t{\n\tcase NID_pkcs7_signed:\n\t\tdata_body=PKCS7_get_octet_string(p7->d.sign->contents);\n\t\tmd_sk=p7->d.sign->md_algs;\n\t\tbreak;\n\tcase NID_pkcs7_signedAndEnveloped:\n\t\trsk=p7->d.signed_and_enveloped->recipientinfo;\n\t\tmd_sk=p7->d.signed_and_enveloped->md_algs;\n\t\tdata_body=p7->d.signed_and_enveloped->enc_data->enc_data;\n\t\tenc_alg=p7->d.signed_and_enveloped->enc_data->algorithm;\n\t\tevp_cipher=EVP_get_cipherbyobj(enc_alg->algorithm);\n\t\tif (evp_cipher == NULL)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);\n\t\t\tgoto err;\n\t\t\t}\n\t\txalg=p7->d.signed_and_enveloped->enc_data->algorithm;\n\t\tbreak;\n\tcase NID_pkcs7_enveloped:\n\t\trsk=p7->d.enveloped->recipientinfo;\n\t\tenc_alg=p7->d.enveloped->enc_data->algorithm;\n\t\tdata_body=p7->d.enveloped->enc_data->enc_data;\n\t\tevp_cipher=EVP_get_cipherbyobj(enc_alg->algorithm);\n\t\tif (evp_cipher == NULL)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);\n\t\t\tgoto err;\n\t\t\t}\n\t\txalg=p7->d.enveloped->enc_data->algorithm;\n\t\tbreak;\n\tdefault:\n\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);\n\t goto err;\n\t\t}\n\tif (md_sk != NULL)\n\t\t{\n\t\tfor (i=0; i<sk_X509_ALGOR_num(md_sk); i++)\n\t\t\t{\n\t\t\txa=sk_X509_ALGOR_value(md_sk,i);\n\t\t\tif ((btmp=BIO_new(BIO_f_md())) == NULL)\n\t\t\t\t{\n\t\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tj=OBJ_obj2nid(xa->algorithm);\n\t\t\tevp_md=EVP_get_digestbynid(j);\n\t\t\tif (evp_md == NULL)\n\t\t\t\t{\n\t\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tBIO_set_md(btmp,evp_md);\n\t\t\tif (out == NULL)\n\t\t\t\tout=btmp;\n\t\t\telse\n\t\t\t\tBIO_push(out,btmp);\n\t\t\tbtmp=NULL;\n\t\t\t}\n\t\t}\n\tif (evp_cipher != NULL)\n\t\t{\n#if 0\n\t\tunsigned char key[EVP_MAX_KEY_LENGTH];\n\t\tunsigned char iv[EVP_MAX_IV_LENGTH];\n\t\tunsigned char *p;\n\t\tint keylen,ivlen;\n\t\tint max;\n\t\tX509_OBJECT ret;\n#endif\n\t\tunsigned char *ek = NULL;\n\t\tint eklen;\n\t\tif ((etmp=BIO_new(BIO_f_cipher())) == NULL)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (pcert)\n\t\t\t{\n\t\t\tfor (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)\n\t\t\t\t{\n\t\t\t\tri=sk_PKCS7_RECIP_INFO_value(rsk,i);\n\t\t\t\tif (!pkcs7_cmp_ri(ri, pcert))\n\t\t\t\t\tbreak;\n\t\t\t\tri=NULL;\n\t\t\t\t}\n\t\t\tif (ri == NULL)\n\t\t\t\t{\n\t\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,\n\t\t\t\t PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\tif (pcert == NULL)\n\t\t\t{\n\t\t\tfor (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)\n\t\t\t\t{\n\t\t\t\tri=sk_PKCS7_RECIP_INFO_value(rsk,i);\n\t\t\t\tif (pkcs7_decrypt_rinfo(&ek, &eklen,\n\t\t\t\t\t\t\tri, pkey) > 0)\n\t\t\t\t\tbreak;\n\t\t\t\tERR_clear_error();\n\t\t\t\tri = NULL;\n\t\t\t\t}\n\t\t\tif (ri == NULL)\n\t\t\t\t{\n\t\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,\n\t\t\t\t PKCS7_R_NO_RECIPIENT_MATCHES_KEY);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (pkcs7_decrypt_rinfo(&ek, &eklen, ri, pkey) <= 0)\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tevp_ctx=NULL;\n\t\tBIO_get_cipher_ctx(etmp,&evp_ctx);\n\t\tif (EVP_CipherInit_ex(evp_ctx,evp_cipher,NULL,NULL,NULL,0) <= 0)\n\t\t\tgoto err;\n\t\tif (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)\n\t\t\tgoto err;\n\t\tif (eklen != EVP_CIPHER_CTX_key_length(evp_ctx)) {\n\t\t\tif(!EVP_CIPHER_CTX_set_key_length(evp_ctx, eklen))\n\t\t\t\t{\n\t\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,\n\t\t\t\t\tPKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t}\n\t\tif (EVP_CipherInit_ex(evp_ctx,NULL,NULL,ek,NULL,0) <= 0)\n\t\t\tgoto err;\n\t\tif (ek)\n\t\t\t{\n\t\t\tOPENSSL_cleanse(ek,eklen);\n\t\t\tOPENSSL_free(ek);\n\t\t\t}\n\t\tif (out == NULL)\n\t\t\tout=etmp;\n\t\telse\n\t\t\tBIO_push(out,etmp);\n\t\tetmp=NULL;\n\t\t}\n#if 1\n\tif (PKCS7_is_detached(p7) || (in_bio != NULL))\n\t\t{\n\t\tbio=in_bio;\n\t\t}\n\telse\n\t\t{\n#if 0\n\t\tbio=BIO_new(BIO_s_mem());\n\t\tBIO_set_mem_eof_return(bio,0);\n\t\tif (data_body->length > 0)\n\t\t\tBIO_write(bio,(char *)data_body->data,data_body->length);\n#else\n\t\tif (data_body->length > 0)\n\t\t bio = BIO_new_mem_buf(data_body->data,data_body->length);\n\t\telse {\n\t\t\tbio=BIO_new(BIO_s_mem());\n\t\t\tBIO_set_mem_eof_return(bio,0);\n\t\t}\n#endif\n\t\t}\n\tBIO_push(out,bio);\n\tbio=NULL;\n#endif\n\tif (0)\n\t\t{\nerr:\n\t\tif (out != NULL) BIO_free_all(out);\n\t\tif (btmp != NULL) BIO_free_all(btmp);\n\t\tif (etmp != NULL) BIO_free_all(etmp);\n\t\tif (bio != NULL) BIO_free_all(bio);\n\t\tout=NULL;\n\t\t}\n\treturn(out);\n\t}']
|
2,793
| 0
|
https://github.com/libav/libav/blob/8f935b9271052be8f97d655081b94b68b6c23bfb/libavformat/mpc8.c/#L148
|
static void mpc8_parse_seektable(AVFormatContext *s, int64_t off)
{
MPCContext *c = s->priv_data;
int tag;
int64_t size, pos, ppos[2];
uint8_t *buf;
int i, t, seekd;
GetBitContext gb;
url_fseek(s->pb, off, SEEK_SET);
mpc8_get_chunk_header(s->pb, &tag, &size);
if(tag != TAG_SEEKTABLE){
av_log(s, AV_LOG_ERROR, "No seek table at given position\n");
return;
}
if(!(buf = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE)))
return;
avio_read(s->pb, buf, size);
init_get_bits(&gb, buf, size * 8);
size = gb_get_v(&gb);
if(size > UINT_MAX/4 || size > c->samples/1152){
av_log(s, AV_LOG_ERROR, "Seek table is too big\n");
return;
}
seekd = get_bits(&gb, 4);
for(i = 0; i < 2; i++){
pos = gb_get_v(&gb) + c->header_pos;
ppos[1 - i] = pos;
av_add_index_entry(s->streams[0], pos, i, 0, 0, AVINDEX_KEYFRAME);
}
for(; i < size; i++){
t = get_unary(&gb, 1, 33) << 12;
t += get_bits(&gb, 12);
if(t & 1)
t = -(t & ~1);
pos = (t >> 1) + ppos[0]*2 - ppos[1];
av_add_index_entry(s->streams[0], pos, i << seekd, 0, 0, AVINDEX_KEYFRAME);
ppos[1] = ppos[0];
ppos[0] = pos;
}
av_free(buf);
}
|
['static void mpc8_parse_seektable(AVFormatContext *s, int64_t off)\n{\n MPCContext *c = s->priv_data;\n int tag;\n int64_t size, pos, ppos[2];\n uint8_t *buf;\n int i, t, seekd;\n GetBitContext gb;\n url_fseek(s->pb, off, SEEK_SET);\n mpc8_get_chunk_header(s->pb, &tag, &size);\n if(tag != TAG_SEEKTABLE){\n av_log(s, AV_LOG_ERROR, "No seek table at given position\\n");\n return;\n }\n if(!(buf = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE)))\n return;\n avio_read(s->pb, buf, size);\n init_get_bits(&gb, buf, size * 8);\n size = gb_get_v(&gb);\n if(size > UINT_MAX/4 || size > c->samples/1152){\n av_log(s, AV_LOG_ERROR, "Seek table is too big\\n");\n return;\n }\n seekd = get_bits(&gb, 4);\n for(i = 0; i < 2; i++){\n pos = gb_get_v(&gb) + c->header_pos;\n ppos[1 - i] = pos;\n av_add_index_entry(s->streams[0], pos, i, 0, 0, AVINDEX_KEYFRAME);\n }\n for(; i < size; i++){\n t = get_unary(&gb, 1, 33) << 12;\n t += get_bits(&gb, 12);\n if(t & 1)\n t = -(t & ~1);\n pos = (t >> 1) + ppos[0]*2 - ppos[1];\n av_add_index_entry(s->streams[0], pos, i << seekd, 0, 0, AVINDEX_KEYFRAME);\n ppos[1] = ppos[0];\n ppos[0] = pos;\n }\n av_free(buf);\n}', 'void *av_malloc(FF_INTERNAL_MEM_TYPE 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}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size = (bit_size+7)>>3;\n if (buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n s->buffer_end = buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index = 0;\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer & ~3);\n s->bit_count = 32 + 8*((intptr_t)buffer & 3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline int64_t gb_get_v(GetBitContext *gb)\n{\n int64_t v = 0;\n int bits = 0;\n while(get_bits1(gb) && bits < 64-7){\n v <<= 7;\n v |= get_bits(gb, 7);\n bits += 7;\n }\n v <<= 7;\n v |= get_bits(gb, 7);\n return v;\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef ALT_BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n index++;\n s->index = index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}', 'static inline unsigned int get_bits(GetBitContext *s, int n){\n register int tmp;\n OPEN_READER(re, s);\n UPDATE_CACHE(re, s);\n tmp = SHOW_UBITS(re, s, n);\n LAST_SKIP_BITS(re, s, n);\n CLOSE_READER(re, s);\n return tmp;\n}', 'static av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);\n x= (x>>16) | (x<<16);\n return x;\n}']
|
2,794
| 0
|
https://github.com/openssl/openssl/blob/507db4c5313288d55eeb8434b0111201ba363b28/test/ssltest.c/#L437
|
static int cb_server_alpn(SSL *s, const unsigned char **out,
unsigned char *outlen, const unsigned char *in,
unsigned int inlen, void *arg)
{
unsigned char *protos;
unsigned short protos_len;
protos = next_protos_parse(&protos_len, alpn_server);
if (protos == NULL) {
fprintf(stderr, "failed to parser ALPN server protocol string: %s\n",
alpn_server);
abort();
}
if (SSL_select_next_proto
((unsigned char **)out, outlen, protos, protos_len, in,
inlen) != OPENSSL_NPN_NEGOTIATED) {
OPENSSL_free(protos);
return SSL_TLSEXT_ERR_NOACK;
}
alpn_selected = OPENSSL_malloc(*outlen);
memcpy(alpn_selected, *out, *outlen);
*out = alpn_selected;
OPENSSL_free(protos);
return SSL_TLSEXT_ERR_OK;
}
|
['static int cb_server_alpn(SSL *s, const unsigned char **out,\n unsigned char *outlen, const unsigned char *in,\n unsigned int inlen, void *arg)\n{\n unsigned char *protos;\n unsigned short protos_len;\n protos = next_protos_parse(&protos_len, alpn_server);\n if (protos == NULL) {\n fprintf(stderr, "failed to parser ALPN server protocol string: %s\\n",\n alpn_server);\n abort();\n }\n if (SSL_select_next_proto\n ((unsigned char **)out, outlen, protos, protos_len, in,\n inlen) != OPENSSL_NPN_NEGOTIATED) {\n OPENSSL_free(protos);\n return SSL_TLSEXT_ERR_NOACK;\n }\n alpn_selected = OPENSSL_malloc(*outlen);\n memcpy(alpn_selected, *out, *outlen);\n *out = alpn_selected;\n OPENSSL_free(protos);\n return SSL_TLSEXT_ERR_OK;\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}']
|
2,795
| 0
|
https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/bn/bn_lib.c/#L377
|
BIGNUM *bn_expand2(BIGNUM *b, int words)
{
BN_ULONG *A,*B,*a;
int i,j;
bn_check_top(b);
if (words > b->max)
{
bn_check_top(b);
if (BN_get_flags(b,BN_FLG_STATIC_DATA))
{
BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return(NULL);
}
a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));
if (A == NULL)
{
BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);
return(NULL);
}
memset(A,0x5c,sizeof(BN_ULONG)*(words+1));
#if 1
B=b->d;
if (B != NULL)
{
for (i=b->top&(~7); i>0; i-=8)
{
A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];
A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];
A+=8;
B+=8;
}
switch (b->top&7)
{
case 7:
A[6]=B[6];
case 6:
A[5]=B[5];
case 5:
A[4]=B[4];
case 4:
A[3]=B[3];
case 3:
A[2]=B[2];
case 2:
A[1]=B[1];
case 1:
A[0]=B[0];
case 0:
;
}
Free(b->d);
}
b->d=a;
b->max=words;
B= &(b->d[b->top]);
j=(b->max - b->top) & ~7;
for (i=0; i<j; i+=8)
{
B[0]=0; B[1]=0; B[2]=0; B[3]=0;
B[4]=0; B[5]=0; B[6]=0; B[7]=0;
B+=8;
}
j=(b->max - b->top) & 7;
for (i=0; i<j; i++)
{
B[0]=0;
B++;
}
#else
memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
#endif
}
return(b);
}
|
['int test_mod_exp(BIO *bp, BN_CTX *ctx)\n\t{\n\tBIGNUM *a,*b,*c,*d,*e;\n\tint i;\n\ta=BN_new();\n\tb=BN_new();\n\tc=BN_new();\n\td=BN_new();\n\te=BN_new();\n\tBN_rand(c,30,0,1);\n\tfor (i=0; i<6; i++)\n\t\t{\n\t\tBN_rand(a,20+i*5,0,0);\n\t\tBN_rand(b,2+i,0,0);\n\t\tif (!BN_mod_exp(d,a,b,c,ctx))\n\t\t\treturn(00);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,a);\n\t\t\t\tBIO_puts(bp," ^ ");\n\t\t\t\tBN_print(bp,b);\n\t\t\t\tBIO_puts(bp," % ");\n\t\t\t\tBN_print(bp,c);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,d);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\t}\n\tBN_free(a);\n\tBN_free(b);\n\tBN_free(c);\n\tBN_free(d);\n\tBN_free(e);\n\treturn(1);\n\t}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n\t{\n\tunsigned char *buf=NULL;\n\tint ret=0,bit,bytes,mask;\n\ttime_t tim;\n\tbytes=(bits+7)/8;\n\tbit=(bits-1)%8;\n\tmask=0xff<<bit;\n\tbuf=(unsigned char *)Malloc(bytes);\n\tif (buf == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\ttime(&tim);\n\tRAND_seed(&tim,sizeof(tim));\n\tRAND_bytes(buf,(int)bytes);\n\tif (top)\n\t\t{\n\t\tif (bit == 0)\n\t\t\t{\n\t\t\tbuf[0]=1;\n\t\t\tbuf[1]|=0x80;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbuf[0]|=(3<<(bit-1));\n\t\t\tbuf[0]&= ~(mask<<1);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tbuf[0]|=(1<<bit);\n\t\tbuf[0]&= ~(mask<<1);\n\t\t}\n\tif (bottom)\n\t\tbuf[bytes-1]|=1;\n\tif (!BN_bin2bn(buf,bytes,rnd)) goto err;\n\tret=1;\nerr:\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bytes);\n\t\tFree(buf);\n\t\t}\n\treturn(ret);\n\t}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n\t{\n\tunsigned int i,m;\n\tunsigned int n;\n\tBN_ULONG l;\n\tif (ret == NULL) ret=BN_new();\n\tif (ret == NULL) return(NULL);\n\tl=0;\n\tn=len;\n\tif (n == 0)\n\t\t{\n\t\tret->top=0;\n\t\treturn(ret);\n\t\t}\n\tif (bn_expand(ret,(int)(n+2)*8) == NULL)\n\t\treturn(NULL);\n\ti=((n-1)/BN_BYTES)+1;\n\tm=((n-1)%(BN_BYTES));\n\tret->top=i;\n\twhile (n-- > 0)\n\t\t{\n\t\tl=(l<<8L)| *(s++);\n\t\tif (m-- == 0)\n\t\t\t{\n\t\t\tret->d[--i]=l;\n\t\t\tl=0;\n\t\t\tm=BN_BYTES-1;\n\t\t\t}\n\t\t}\n\tbn_fix_top(ret);\n\treturn(ret);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*B,*a;\n\tint i,j;\n\tbn_check_top(b);\n\tif (words > b->max)\n\t\t{\n\t\tbn_check_top(b);\n\t\tif (BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\ta=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));\n\t\tif (A == NULL)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(NULL);\n\t\t\t}\nmemset(A,0x5c,sizeof(BN_ULONG)*(words+1));\n#if 1\n\t\tB=b->d;\n\t\tif (B != NULL)\n\t\t\t{\n\t\t\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t\t\t{\n\t\t\t\tA[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];\n\t\t\t\tA[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];\n\t\t\t\tA+=8;\n\t\t\t\tB+=8;\n\t\t\t\t}\n\t\t\tswitch (b->top&7)\n\t\t\t\t{\n\t\t\tcase 7:\n\t\t\t\tA[6]=B[6];\n\t\t\tcase 6:\n\t\t\t\tA[5]=B[5];\n\t\t\tcase 5:\n\t\t\t\tA[4]=B[4];\n\t\t\tcase 4:\n\t\t\t\tA[3]=B[3];\n\t\t\tcase 3:\n\t\t\t\tA[2]=B[2];\n\t\t\tcase 2:\n\t\t\t\tA[1]=B[1];\n\t\t\tcase 1:\n\t\t\t\tA[0]=B[0];\n\t\t\tcase 0:\n\t\t\t\t;\n\t\t\t\t}\n\t\t\tFree(b->d);\n\t\t\t}\n\t\tb->d=a;\n\t\tb->max=words;\n\t\tB= &(b->d[b->top]);\n\t\tj=(b->max - b->top) & ~7;\n\t\tfor (i=0; i<j; i+=8)\n\t\t\t{\n\t\t\tB[0]=0; B[1]=0; B[2]=0; B[3]=0;\n\t\t\tB[4]=0; B[5]=0; B[6]=0; B[7]=0;\n\t\t\tB+=8;\n\t\t\t}\n\t\tj=(b->max - b->top) & 7;\n\t\tfor (i=0; i<j; i++)\n\t\t\t{\n\t\t\tB[0]=0;\n\t\t\tB++;\n\t\t\t}\n#else\n\t\t\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\t\t}\n\treturn(b);\n\t}']
|
2,796
| 0
|
https://github.com/openssl/openssl/blob/7fcdbd839c629f5419a49bf8da28c968c8140c3d/ssl/statem/statem_clnt.c/#L2912
|
static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt)
{
#ifndef OPENSSL_NO_RSA
unsigned char *encdata = NULL;
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = NULL;
size_t enclen;
unsigned char *pms = NULL;
size_t pmslen = 0;
if (s->session->peer == NULL) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
ERR_R_INTERNAL_ERROR);
return 0;
}
pkey = X509_get0_pubkey(s->session->peer);
if (EVP_PKEY_get0_RSA(pkey) == NULL) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
ERR_R_INTERNAL_ERROR);
return 0;
}
pmslen = SSL_MAX_MASTER_KEY_LENGTH;
pms = OPENSSL_malloc(pmslen);
if (pms == NULL) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
ERR_R_MALLOC_FAILURE);
return 0;
}
pms[0] = s->client_version >> 8;
pms[1] = s->client_version & 0xff;
if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
ERR_R_MALLOC_FAILURE);
goto err;
}
if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
ERR_R_INTERNAL_ERROR);
goto err;
}
pctx = EVP_PKEY_CTX_new(pkey, NULL);
if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0
|| EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
ERR_R_EVP_LIB);
goto err;
}
if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)
|| EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
SSL_R_BAD_RSA_ENCRYPT);
goto err;
}
EVP_PKEY_CTX_free(pctx);
pctx = NULL;
if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
ERR_R_INTERNAL_ERROR);
goto err;
}
if (!ssl_log_rsa_client_key_exchange(s, encdata, enclen, pms, pmslen)) {
goto err;
}
s->s3->tmp.pms = pms;
s->s3->tmp.pmslen = pmslen;
return 1;
err:
OPENSSL_clear_free(pms, pmslen);
EVP_PKEY_CTX_free(pctx);
return 0;
#else
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,
ERR_R_INTERNAL_ERROR);
return 0;
#endif
}
|
['static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt)\n{\n#ifndef OPENSSL_NO_RSA\n unsigned char *encdata = NULL;\n EVP_PKEY *pkey = NULL;\n EVP_PKEY_CTX *pctx = NULL;\n size_t enclen;\n unsigned char *pms = NULL;\n size_t pmslen = 0;\n if (s->session->peer == NULL) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pkey = X509_get0_pubkey(s->session->peer);\n if (EVP_PKEY_get0_RSA(pkey) == NULL) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pmslen = SSL_MAX_MASTER_KEY_LENGTH;\n pms = OPENSSL_malloc(pmslen);\n if (pms == NULL) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n ERR_R_MALLOC_FAILURE);\n return 0;\n }\n pms[0] = s->client_version >> 8;\n pms[1] = s->client_version & 0xff;\n if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n pctx = EVP_PKEY_CTX_new(pkey, NULL);\n if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0\n || EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n ERR_R_EVP_LIB);\n goto err;\n }\n if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)\n || EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n SSL_R_BAD_RSA_ENCRYPT);\n goto err;\n }\n EVP_PKEY_CTX_free(pctx);\n pctx = NULL;\n if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!ssl_log_rsa_client_key_exchange(s, encdata, enclen, pms, pmslen)) {\n goto err;\n }\n s->s3->tmp.pms = pms;\n s->s3->tmp.pmslen = pmslen;\n return 1;\n err:\n OPENSSL_clear_free(pms, pmslen);\n EVP_PKEY_CTX_free(pctx);\n return 0;\n#else\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CKE_RSA,\n ERR_R_INTERNAL_ERROR);\n return 0;\n#endif\n}', 'EVP_PKEY *X509_get0_pubkey(const X509 *x)\n{\n if (x == NULL)\n return NULL;\n return X509_PUBKEY_get0(x->cert_info.key);\n}', 'EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)\n{\n EVP_PKEY *ret = NULL;\n if (key == NULL || key->public_key == NULL)\n return NULL;\n if (key->pkey != NULL)\n return key->pkey;\n x509_pubkey_decode(&ret, key);\n if (ret != NULL) {\n X509err(X509_F_X509_PUBKEY_GET0, ERR_R_INTERNAL_ERROR);\n EVP_PKEY_free(ret);\n }\n return NULL;\n}', 'static int x509_pubkey_decode(EVP_PKEY **ppkey, X509_PUBKEY *key)\n{\n EVP_PKEY *pkey = EVP_PKEY_new();\n if (pkey == NULL) {\n X509err(X509_F_X509_PUBKEY_DECODE, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n if (!EVP_PKEY_set_type(pkey, OBJ_obj2nid(key->algor->algorithm))) {\n X509err(X509_F_X509_PUBKEY_DECODE, X509_R_UNSUPPORTED_ALGORITHM);\n goto error;\n }\n if (pkey->ameth->pub_decode) {\n if (!pkey->ameth->pub_decode(pkey, key)) {\n X509err(X509_F_X509_PUBKEY_DECODE, X509_R_PUBLIC_KEY_DECODE_ERROR);\n goto error;\n }\n } else {\n X509err(X509_F_X509_PUBKEY_DECODE, X509_R_METHOD_NOT_SUPPORTED);\n goto error;\n }\n *ppkey = pkey;\n return 1;\n error:\n EVP_PKEY_free(pkey);\n return 0;\n}', 'RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)\n{\n if (pkey->type != EVP_PKEY_RSA) {\n EVPerr(EVP_F_EVP_PKEY_GET0_RSA, EVP_R_EXPECTING_AN_RSA_KEY);\n return NULL;\n }\n return pkey->pkey.rsa;\n}']
|
2,797
| 0
|
https://gitlab.com/libtiff/libtiff/blob/709e93ded0000128625a23838756a408ea30745d/libtiff/tif_tile.c/#L130
|
uint32
TIFFNumberOfTiles(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
uint32 dx = td->td_tilewidth;
uint32 dy = td->td_tilelength;
uint32 dz = td->td_tiledepth;
uint32 ntiles;
if (dx == (uint32) -1)
dx = td->td_imagewidth;
if (dy == (uint32) -1)
dy = td->td_imagelength;
if (dz == (uint32) -1)
dz = td->td_imagedepth;
ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :
_TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx),
TIFFhowmany_32(td->td_imagelength, dy),
"TIFFNumberOfTiles"),
TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
ntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel,
"TIFFNumberOfTiles");
return (ntiles);
}
|
['DECLAREcpFunc(cpBiasedContig2Contig)\n{\n\tif (spp == 1) {\n\t\ttsize_t biasSize = TIFFScanlineSize(bias);\n\t\ttsize_t bufSize = TIFFScanlineSize(in);\n\t\ttdata_t buf, biasBuf;\n\t\tuint32 biasWidth = 0, biasLength = 0;\n\t\tTIFFGetField(bias, TIFFTAG_IMAGEWIDTH, &biasWidth);\n\t\tTIFFGetField(bias, TIFFTAG_IMAGELENGTH, &biasLength);\n\t\tif (biasSize == bufSize &&\n\t\t imagelength == biasLength && imagewidth == biasWidth) {\n\t\t\tuint16 sampleBits = 0;\n\t\t\tbiasFn *subtractLine;\n\t\t\tTIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &sampleBits);\n\t\t\tsubtractLine = lineSubtractFn (sampleBits);\n\t\t\tif (subtractLine) {\n\t\t\t\tuint32 row;\n\t\t\t\tbuf = _TIFFmalloc(bufSize);\n\t\t\t\tbiasBuf = _TIFFmalloc(bufSize);\n\t\t\t\tfor (row = 0; row < imagelength; row++) {\n\t\t\t\t\tif (TIFFReadScanline(in, buf, row, 0) < 0\n\t\t\t\t\t && !ignore) {\n\t\t\t\t\t\tTIFFError(TIFFFileName(in),\n\t\t\t\t\t\t "Error, can\'t read scanline %lu",\n\t\t\t\t\t\t (unsigned long) row);\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t}\n\t\t\t\t\tif (TIFFReadScanline(bias, biasBuf, row, 0) < 0\n\t\t\t\t\t && !ignore) {\n\t\t\t\t\t\tTIFFError(TIFFFileName(in),\n\t\t\t\t\t\t "Error, can\'t read biased scanline %lu",\n\t\t\t\t\t\t (unsigned long) row);\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t}\n\t\t\t\t\tsubtractLine (buf, biasBuf, imagewidth);\n\t\t\t\t\tif (TIFFWriteScanline(out, buf, row, 0) < 0) {\n\t\t\t\t\t\tTIFFError(TIFFFileName(out),\n\t\t\t\t\t\t "Error, can\'t write scanline %lu",\n\t\t\t\t\t\t (unsigned long) row);\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t_TIFFfree(buf);\n\t\t\t\t_TIFFfree(biasBuf);\n\t\t\t\tTIFFSetDirectory(bias,\n\t\t\t\t TIFFCurrentDirectory(bias));\n\t\t\t\treturn 1;\nbad:\n\t\t\t\t_TIFFfree(buf);\n\t\t\t\t_TIFFfree(biasBuf);\n\t\t\t\treturn 0;\n\t\t\t} else {\n\t\t\t\tTIFFError(TIFFFileName(in),\n\t\t\t\t "No support for biasing %d bit pixels\\n",\n\t\t\t\t sampleBits);\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\tTIFFError(TIFFFileName(in),\n\t\t "Bias image %s,%d\\nis not the same size as %s,%d\\n",\n\t\t TIFFFileName(bias), TIFFCurrentDirectory(bias),\n\t\t TIFFFileName(in), TIFFCurrentDirectory(in));\n\t\treturn 0;\n\t} else {\n\t\tTIFFError(TIFFFileName(in),\n\t\t "Can\'t bias %s,%d as it has >1 Sample/Pixel\\n",\n\t\t TIFFFileName(in), TIFFCurrentDirectory(in));\n\t\treturn 0;\n\t}\n}', 'tmsize_t\nTIFFScanlineSize(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFScanlineSize";\n\tuint64 m;\n\ttmsize_t n;\n\tm=TIFFScanlineSize64(tif);\n\tn=(tmsize_t)m;\n\tif ((uint64)n!=m)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer arithmetic overflow");\n\t\tn=0;\n\t}\n\treturn(n);\n}', 'uint64\nTIFFScanlineSize64(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFScanlineSize64";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint64 scanline_size;\n\tif (td->td_planarconfig==PLANARCONFIG_CONTIG)\n\t{\n\t\tif ((td->td_photometric==PHOTOMETRIC_YCBCR)&&\n\t\t (td->td_samplesperpixel==3)&&\n\t\t (!isUpSampled(tif)))\n\t\t{\n\t\t\tuint16 ycbcrsubsampling[2];\n\t\t\tuint16 samplingblock_samples;\n\t\t\tuint32 samplingblocks_hor;\n\t\t\tuint64 samplingrow_samples;\n\t\t\tuint64 samplingrow_size;\n\t\t\tif(td->td_samplesperpixel!=3)\n\t\t\t{\n TIFFErrorExt(tif->tif_clientdata,module,\n "Invalid td_samplesperpixel value");\n return 0;\n\t\t\t}\n\t\t\tTIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,\n ycbcrsubsampling+0,\n ycbcrsubsampling+1);\n\t\t\tif (((ycbcrsubsampling[0]!=1)&&(ycbcrsubsampling[0]!=2)&&(ycbcrsubsampling[0]!=4)) ||\n\t\t\t ((ycbcrsubsampling[1]!=1)&&(ycbcrsubsampling[1]!=2)&&(ycbcrsubsampling[1]!=4)))\n\t\t\t{\n TIFFErrorExt(tif->tif_clientdata,module,\n "Invalid YCbCr subsampling");\n return 0;\n\t\t\t}\n\t\t\tsamplingblock_samples = ycbcrsubsampling[0]*ycbcrsubsampling[1]+2;\n\t\t\tsamplingblocks_hor = TIFFhowmany_32(td->td_imagewidth,ycbcrsubsampling[0]);\n\t\t\tsamplingrow_samples = _TIFFMultiply64(tif,samplingblocks_hor,samplingblock_samples,module);\n\t\t\tsamplingrow_size = TIFFhowmany_64(_TIFFMultiply64(tif,samplingrow_samples,td->td_bitspersample,module),8);\n\t\t\tscanline_size = (samplingrow_size/ycbcrsubsampling[1]);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tuint64 scanline_samples;\n\t\t\tscanline_samples=_TIFFMultiply64(tif,td->td_imagewidth,td->td_samplesperpixel,module);\n\t\t\tscanline_size=TIFFhowmany_64(_TIFFMultiply64(tif,scanline_samples,td->td_bitspersample,module),8);\n\t\t}\n\t}\n\telse\n\t\tscanline_size=TIFFhowmany_64(_TIFFMultiply64(tif,td->td_imagewidth,td->td_bitspersample,module),8);\n\treturn(scanline_size);\n}', 'int\nTIFFSetDirectory(TIFF* tif, uint16 dirn)\n{\n\tuint64 nextdir;\n\tuint16 n;\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\tnextdir = tif->tif_header.classic.tiff_diroff;\n\telse\n\t\tnextdir = tif->tif_header.big.tiff_diroff;\n\tfor (n = dirn; n > 0 && nextdir != 0; n--)\n\t\tif (!TIFFAdvanceDirectory(tif, &nextdir, NULL))\n\t\t\treturn (0);\n\ttif->tif_nextdiroff = nextdir;\n\ttif->tif_curdir = (dirn - n) - 1;\n\ttif->tif_dirnumber = 0;\n\treturn (TIFFReadDirectory(tif));\n}', 'int\nTIFFReadDirectory(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFReadDirectory";\n\tTIFFDirEntry* dir;\n\tuint16 dircount;\n\tTIFFDirEntry* dp;\n\tuint16 di;\n\tconst TIFFField* fip;\n\tuint32 fii;\n toff_t nextdiroff;\n\ttif->tif_diroff=tif->tif_nextdiroff;\n\tif (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff))\n\t\treturn 0;\n\t(*tif->tif_cleanup)(tif);\n\ttif->tif_curdir++;\n nextdiroff = tif->tif_nextdiroff;\n\tdircount=TIFFFetchDirectory(tif,nextdiroff,&dir,&tif->tif_nextdiroff);\n\tif (!dircount)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t "Failed to read directory at offset " TIFF_UINT64_FORMAT,nextdiroff);\n\t\treturn 0;\n\t}\n\tTIFFReadDirectoryCheckOrder(tif,dir,dircount);\n\ttif->tif_flags &= ~TIFF_BEENWRITING;\n\ttif->tif_flags &= ~TIFF_BUF4WRITE;\n\tTIFFFreeDirectory(tif);\n\tTIFFDefaultDirectory(tif);\n\tTIFFSetField(tif,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);\n\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_SAMPLESPERPIXEL);\n\tif (dp)\n\t{\n\t\tif (!TIFFFetchNormalTag(tif,dp,0))\n\t\t\tgoto bad;\n\t\tdp->tdir_tag=IGNORE;\n\t}\n\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_COMPRESSION);\n\tif (dp)\n\t{\n\t\tuint16 value;\n\t\tenum TIFFReadDirEntryErr err;\n\t\terr=TIFFReadDirEntryShort(tif,dp,&value);\n\t\tif (err==TIFFReadDirEntryErrCount)\n\t\t\terr=TIFFReadDirEntryPersampleShort(tif,dp,&value);\n\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t{\n\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,"Compression",0);\n\t\t\tgoto bad;\n\t\t}\n\t\tif (!TIFFSetField(tif,TIFFTAG_COMPRESSION,value))\n\t\t\tgoto bad;\n\t\tdp->tdir_tag=IGNORE;\n\t}\n\telse\n\t{\n\t\tif (!TIFFSetField(tif,TIFFTAG_COMPRESSION,COMPRESSION_NONE))\n\t\t\tgoto bad;\n\t}\n\tfor (di=0, dp=dir; di<dircount; di++, dp++)\n\t{\n\t\tif (dp->tdir_tag!=IGNORE)\n\t\t{\n\t\t\tTIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii);\n\t\t\tif (fii == FAILED_FII)\n\t\t\t{\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t\t "Unknown field with tag %d (0x%x) encountered",\n\t\t\t\t dp->tdir_tag,dp->tdir_tag);\n\t\t\t\tif (!_TIFFMergeFields(tif,\n\t\t\t\t\t_TIFFCreateAnonField(tif,\n\t\t\t\t\t\tdp->tdir_tag,\n\t\t\t\t\t\t(TIFFDataType) dp->tdir_type),\n\t\t\t\t\t1)) {\n\t\t\t\t\tTIFFWarningExt(tif->tif_clientdata,\n\t\t\t\t\t module,\n\t\t\t\t\t "Registering anonymous field with tag %d (0x%x) failed",\n\t\t\t\t\t dp->tdir_tag,\n\t\t\t\t\t dp->tdir_tag);\n\t\t\t\t\tdp->tdir_tag=IGNORE;\n\t\t\t\t} else {\n\t\t\t\t\tTIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii);\n\t\t\t\t\tassert(fii != FAILED_FII);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (dp->tdir_tag!=IGNORE)\n\t\t{\n\t\t\tfip=tif->tif_fields[fii];\n\t\t\tif (fip->field_bit==FIELD_IGNORE)\n\t\t\t\tdp->tdir_tag=IGNORE;\n\t\t\telse\n\t\t\t{\n\t\t\t\tswitch (dp->tdir_tag)\n\t\t\t\t{\n\t\t\t\t\tcase TIFFTAG_STRIPOFFSETS:\n\t\t\t\t\tcase TIFFTAG_STRIPBYTECOUNTS:\n\t\t\t\t\tcase TIFFTAG_TILEOFFSETS:\n\t\t\t\t\tcase TIFFTAG_TILEBYTECOUNTS:\n\t\t\t\t\t\tTIFFSetFieldBit(tif,fip->field_bit);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase TIFFTAG_IMAGEWIDTH:\n\t\t\t\t\tcase TIFFTAG_IMAGELENGTH:\n\t\t\t\t\tcase TIFFTAG_IMAGEDEPTH:\n\t\t\t\t\tcase TIFFTAG_TILELENGTH:\n\t\t\t\t\tcase TIFFTAG_TILEWIDTH:\n\t\t\t\t\tcase TIFFTAG_TILEDEPTH:\n\t\t\t\t\tcase TIFFTAG_PLANARCONFIG:\n\t\t\t\t\tcase TIFFTAG_ROWSPERSTRIP:\n\t\t\t\t\tcase TIFFTAG_EXTRASAMPLES:\n\t\t\t\t\t\tif (!TIFFFetchNormalTag(tif,dp,0))\n\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\tdp->tdir_tag=IGNORE;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif ((tif->tif_dir.td_compression==COMPRESSION_OJPEG)&&\n\t (tif->tif_dir.td_planarconfig==PLANARCONFIG_SEPARATE))\n\t{\n\t\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,TIFFTAG_STRIPOFFSETS);\n\t\tif ((dp!=0)&&(dp->tdir_count==1))\n\t\t{\n\t\t\tdp=TIFFReadDirectoryFindEntry(tif,dir,dircount,\n\t\t\t TIFFTAG_STRIPBYTECOUNTS);\n\t\t\tif ((dp!=0)&&(dp->tdir_count==1))\n\t\t\t{\n\t\t\t\ttif->tif_dir.td_planarconfig=PLANARCONFIG_CONTIG;\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t "Planarconfig tag value assumed incorrect, "\n\t\t\t\t "assuming data is contig instead of chunky");\n\t\t\t}\n\t\t}\n\t}\n\tif (!TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS))\n\t{\n\t\tMissingRequired(tif,"ImageLength");\n\t\tgoto bad;\n\t}\n\tif (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) {\n\t\ttif->tif_dir.td_nstrips = TIFFNumberOfStrips(tif);\n\t\ttif->tif_dir.td_tilewidth = tif->tif_dir.td_imagewidth;\n\t\ttif->tif_dir.td_tilelength = tif->tif_dir.td_rowsperstrip;\n\t\ttif->tif_dir.td_tiledepth = tif->tif_dir.td_imagedepth;\n\t\ttif->tif_flags &= ~TIFF_ISTILED;\n\t} else {\n\t\ttif->tif_dir.td_nstrips = TIFFNumberOfTiles(tif);\n\t\ttif->tif_flags |= TIFF_ISTILED;\n\t}\n\tif (!tif->tif_dir.td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "Cannot handle zero number of %s",\n\t\t isTiled(tif) ? "tiles" : "strips");\n\t\tgoto bad;\n\t}\n\ttif->tif_dir.td_stripsperimage = tif->tif_dir.td_nstrips;\n\tif (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\ttif->tif_dir.td_stripsperimage /= tif->tif_dir.td_samplesperpixel;\n\tif (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) {\n\t\tif ((tif->tif_dir.td_compression==COMPRESSION_OJPEG) &&\n\t\t (isTiled(tif)==0) &&\n\t\t (tif->tif_dir.td_nstrips==1)) {\n\t\t\tTIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);\n\t\t} else {\n\t\t\tMissingRequired(tif,\n\t\t\t\tisTiled(tif) ? "TileOffsets" : "StripOffsets");\n\t\t\tgoto bad;\n\t\t}\n\t}\n\tfor (di=0, dp=dir; di<dircount; di++, dp++)\n\t{\n\t\tswitch (dp->tdir_tag)\n\t\t{\n\t\t\tcase IGNORE:\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_MINSAMPLEVALUE:\n\t\t\tcase TIFFTAG_MAXSAMPLEVALUE:\n\t\t\tcase TIFFTAG_BITSPERSAMPLE:\n\t\t\tcase TIFFTAG_DATATYPE:\n\t\t\tcase TIFFTAG_SAMPLEFORMAT:\n\t\t\t\t{\n\t\t\t\t\tuint16 value;\n\t\t\t\t\tenum TIFFReadDirEntryErr err;\n\t\t\t\t\terr=TIFFReadDirEntryShort(tif,dp,&value);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrCount)\n\t\t\t\t\t\terr=TIFFReadDirEntryPersampleShort(tif,dp,&value);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,TIFFFieldWithTag(tif,dp->tdir_tag)->field_name,0);\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t}\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_SMINSAMPLEVALUE:\n\t\t\tcase TIFFTAG_SMAXSAMPLEVALUE:\n\t\t\t\t{\n\t\t\t\t\tdouble value;\n\t\t\t\t\tenum TIFFReadDirEntryErr err;\n\t\t\t\t\terr=TIFFReadDirEntryPersampleDouble(tif,dp,&value);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,TIFFFieldWithTag(tif,dp->tdir_tag)->field_name,0);\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t}\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_STRIPOFFSETS:\n\t\t\tcase TIFFTAG_TILEOFFSETS:\n\t\t\t\tif (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripoffset))\n\t\t\t\t\tgoto bad;\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_STRIPBYTECOUNTS:\n\t\t\tcase TIFFTAG_TILEBYTECOUNTS:\n\t\t\t\tif (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripbytecount))\n\t\t\t\t\tgoto bad;\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_COLORMAP:\n\t\t\tcase TIFFTAG_TRANSFERFUNCTION:\n\t\t\t\t{\n\t\t\t\t\tenum TIFFReadDirEntryErr err;\n\t\t\t\t\tuint32 countpersample;\n\t\t\t\t\tuint32 countrequired;\n\t\t\t\t\tuint32 incrementpersample;\n\t\t\t\t\tuint16* value;\n\t\t\t\t\tcountpersample=(1L<<tif->tif_dir.td_bitspersample);\n\t\t\t\t\tif ((dp->tdir_tag==TIFFTAG_TRANSFERFUNCTION)&&(dp->tdir_count==(uint64)countpersample))\n\t\t\t\t\t{\n\t\t\t\t\t\tcountrequired=countpersample;\n\t\t\t\t\t\tincrementpersample=0;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tcountrequired=3*countpersample;\n\t\t\t\t\t\tincrementpersample=countpersample;\n\t\t\t\t\t}\n\t\t\t\t\tif (dp->tdir_count!=(uint64)countrequired)\n\t\t\t\t\t\terr=TIFFReadDirEntryErrCount;\n\t\t\t\t\telse\n\t\t\t\t\t\terr=TIFFReadDirEntryShortArray(tif,dp,&value);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t\tTIFFReadDirEntryOutputErr(tif,err,module,TIFFFieldWithTag(tif,dp->tdir_tag)->field_name,1);\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tTIFFSetField(tif,dp->tdir_tag,value,value+incrementpersample,value+2*incrementpersample);\n\t\t\t\t\t\t_TIFFfree(value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase TIFFTAG_OSUBFILETYPE:\n\t\t\t\t{\n\t\t\t\t\tuint16 valueo;\n\t\t\t\t\tuint32 value;\n\t\t\t\t\tif (TIFFReadDirEntryShort(tif,dp,&valueo)==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tswitch (valueo)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcase OFILETYPE_REDUCEDIMAGE: value=FILETYPE_REDUCEDIMAGE; break;\n\t\t\t\t\t\t\tcase OFILETYPE_PAGE: value=FILETYPE_PAGE; break;\n\t\t\t\t\t\t\tdefault: value=0; break;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (value!=0)\n\t\t\t\t\t\t\tTIFFSetField(tif,TIFFTAG_SUBFILETYPE,value);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\t(void) TIFFFetchNormalTag(tif, dp, TRUE);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tif (tif->tif_dir.td_compression==COMPRESSION_OJPEG)\n\t{\n\t\tif (!TIFFFieldSet(tif,FIELD_PHOTOMETRIC))\n\t\t{\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t "Photometric tag is missing, assuming data is YCbCr");\n\t\t\tif (!TIFFSetField(tif,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_YCBCR))\n\t\t\t\tgoto bad;\n\t\t}\n\t\telse if (tif->tif_dir.td_photometric==PHOTOMETRIC_RGB)\n\t\t{\n\t\t\ttif->tif_dir.td_photometric=PHOTOMETRIC_YCBCR;\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t "Photometric tag value assumed incorrect, "\n\t\t\t "assuming data is YCbCr instead of RGB");\n\t\t}\n\t\tif (!TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))\n\t\t{\n\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t "BitsPerSample tag is missing, assuming 8 bits per sample");\n\t\t\tif (!TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE,8))\n\t\t\t\tgoto bad;\n\t\t}\n\t\tif (!TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))\n\t\t{\n\t\t\tif ((tif->tif_dir.td_photometric==PHOTOMETRIC_RGB)\n\t\t\t || (tif->tif_dir.td_photometric==PHOTOMETRIC_YCBCR))\n\t\t\t{\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t "SamplesPerPixel tag is missing, "\n\t\t\t\t "assuming correct SamplesPerPixel value is 3");\n\t\t\t\tif (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,3))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\telse if ((tif->tif_dir.td_photometric==PHOTOMETRIC_MINISWHITE)\n\t\t\t\t || (tif->tif_dir.td_photometric==PHOTOMETRIC_MINISBLACK))\n\t\t\t{\n\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t "SamplesPerPixel tag is missing, "\n\t\t\t\t "assuming correct SamplesPerPixel value is 1");\n\t\t\t\tif (!TIFFSetField(tif,TIFFTAG_SAMPLESPERPIXEL,1))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t}\n\t}\n\tif (tif->tif_dir.td_photometric == PHOTOMETRIC_PALETTE &&\n\t !TIFFFieldSet(tif, FIELD_COLORMAP)) {\n\t\tMissingRequired(tif, "Colormap");\n\t\tgoto bad;\n\t}\n\tif (tif->tif_dir.td_compression!=COMPRESSION_OJPEG)\n\t{\n\t\tif (!TIFFFieldSet(tif, FIELD_STRIPBYTECOUNTS)) {\n\t\t\tif ((tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG &&\n\t\t\t tif->tif_dir.td_nstrips > 1) ||\n\t\t\t (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE &&\n\t\t\t tif->tif_dir.td_nstrips != (uint32)tif->tif_dir.td_samplesperpixel)) {\n\t\t\t MissingRequired(tif, "StripByteCounts");\n\t\t\t goto bad;\n\t\t\t}\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t\t"TIFF directory is missing required "\n\t\t\t\t"\\"%s\\" field, calculating from imagelength",\n\t\t\t\tTIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);\n\t\t\tif (EstimateStripByteCounts(tif, dir, dircount) < 0)\n\t\t\t goto bad;\n\t\t#define\tBYTECOUNTLOOKSBAD \\\n\t\t ( (tif->tif_dir.td_stripbytecount[0] == 0 && tif->tif_dir.td_stripoffset[0] != 0) || \\\n\t\t (tif->tif_dir.td_compression == COMPRESSION_NONE && \\\n\t\t tif->tif_dir.td_stripbytecount[0] > TIFFGetFileSize(tif) - tif->tif_dir.td_stripoffset[0]) || \\\n\t\t (tif->tif_mode == O_RDONLY && \\\n\t\t tif->tif_dir.td_compression == COMPRESSION_NONE && \\\n\t\t tif->tif_dir.td_stripbytecount[0] < TIFFScanlineSize64(tif) * tif->tif_dir.td_imagelength) )\n\t\t} else if (tif->tif_dir.td_nstrips == 1\n\t\t\t && tif->tif_dir.td_stripoffset[0] != 0\n\t\t\t && BYTECOUNTLOOKSBAD) {\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t "Bogus \\"%s\\" field, ignoring and calculating from imagelength",\n\t\t\t TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);\n\t\t\tif(EstimateStripByteCounts(tif, dir, dircount) < 0)\n\t\t\t goto bad;\n\t\t} else if (tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG\n\t\t\t && tif->tif_dir.td_nstrips > 2\n\t\t\t && tif->tif_dir.td_compression == COMPRESSION_NONE\n\t\t\t && tif->tif_dir.td_stripbytecount[0] != tif->tif_dir.td_stripbytecount[1]\n\t\t\t && tif->tif_dir.td_stripbytecount[0] != 0\n\t\t\t && tif->tif_dir.td_stripbytecount[1] != 0 ) {\n\t\t\tTIFFWarningExt(tif->tif_clientdata, module,\n\t\t\t "Wrong \\"%s\\" field, ignoring and calculating from imagelength",\n\t\t\t TIFFFieldWithTag(tif,TIFFTAG_STRIPBYTECOUNTS)->field_name);\n\t\t\tif (EstimateStripByteCounts(tif, dir, dircount) < 0)\n\t\t\t goto bad;\n\t\t}\n\t}\n\tif (dir)\n\t{\n\t\t_TIFFfree(dir);\n\t\tdir=NULL;\n\t}\n\tif (!TIFFFieldSet(tif, FIELD_MAXSAMPLEVALUE))\n\t{\n\t\tif (tif->tif_dir.td_bitspersample>=16)\n\t\t\ttif->tif_dir.td_maxsamplevalue=0xFFFF;\n\t\telse\n\t\t\ttif->tif_dir.td_maxsamplevalue = (uint16)((1L<<tif->tif_dir.td_bitspersample)-1);\n\t}\n\tif (tif->tif_dir.td_nstrips > 1) {\n\t\tuint32 strip;\n\t\ttif->tif_dir.td_stripbytecountsorted = 1;\n\t\tfor (strip = 1; strip < tif->tif_dir.td_nstrips; strip++) {\n\t\t\tif (tif->tif_dir.td_stripoffset[strip - 1] >\n\t\t\t tif->tif_dir.td_stripoffset[strip]) {\n\t\t\t\ttif->tif_dir.td_stripbytecountsorted = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\t(*tif->tif_fixuptags)(tif);\n\tif ((tif->tif_dir.td_planarconfig==PLANARCONFIG_CONTIG)&&\n\t (tif->tif_dir.td_nstrips==1)&&\n\t (tif->tif_dir.td_compression==COMPRESSION_NONE)&&\n\t ((tif->tif_flags&(TIFF_STRIPCHOP|TIFF_ISTILED))==TIFF_STRIPCHOP))\n\t\tChopUpSingleUncompressedStrip(tif);\n\ttif->tif_flags &= ~TIFF_DIRTYDIRECT;\n\ttif->tif_flags &= ~TIFF_DIRTYSTRIP;\n\ttif->tif_row = (uint32) -1;\n\ttif->tif_curstrip = (uint32) -1;\n\ttif->tif_col = (uint32) -1;\n\ttif->tif_curtile = (uint32) -1;\n\ttif->tif_tilesize = (tmsize_t) -1;\n\ttif->tif_scanlinesize = TIFFScanlineSize(tif);\n\tif (!tif->tif_scanlinesize) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "Cannot handle zero scanline size");\n\t\treturn (0);\n\t}\n\tif (isTiled(tif)) {\n\t\ttif->tif_tilesize = TIFFTileSize(tif);\n\t\tif (!tif->tif_tilesize) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Cannot handle zero tile size");\n\t\t\treturn (0);\n\t\t}\n\t} else {\n\t\tif (!TIFFStripSize(tif)) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Cannot handle zero strip size");\n\t\t\treturn (0);\n\t\t}\n\t}\n\treturn (1);\nbad:\n\tif (dir)\n\t\t_TIFFfree(dir);\n\treturn (0);\n}', 'uint32\nTIFFNumberOfTiles(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 dx = td->td_tilewidth;\n\tuint32 dy = td->td_tilelength;\n\tuint32 dz = td->td_tiledepth;\n\tuint32 ntiles;\n\tif (dx == (uint32) -1)\n\t\tdx = td->td_imagewidth;\n\tif (dy == (uint32) -1)\n\t\tdy = td->td_imagelength;\n\tif (dz == (uint32) -1)\n\t\tdz = td->td_imagedepth;\n\tntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :\n\t _TIFFMultiply32(tif, _TIFFMultiply32(tif, TIFFhowmany_32(td->td_imagewidth, dx),\n\t TIFFhowmany_32(td->td_imagelength, dy),\n\t "TIFFNumberOfTiles"),\n\t TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\tntiles = _TIFFMultiply32(tif, ntiles, td->td_samplesperpixel,\n\t\t "TIFFNumberOfTiles");\n\treturn (ntiles);\n}']
|
2,798
| 0
|
https://github.com/apache/httpd/blob/83099f13296cd19faa810ec58c6d2246f1f51fdb/modules/proxy/mod_proxy_ajp.c/#L256
|
static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
proxy_conn_rec *conn,
conn_rec *origin,
proxy_dir_conf *conf,
apr_uri_t *uri,
char *url, char *server_portstr)
{
apr_status_t status;
int result;
apr_bucket *e;
apr_bucket_brigade *input_brigade;
apr_bucket_brigade *output_brigade;
ajp_msg_t *msg;
apr_size_t bufsiz = 0;
char *buff;
char *send_body_chunk_buff;
apr_uint16_t size;
apr_byte_t conn_reuse = 0;
const char *tenc;
int havebody = 1;
int client_failed = 0;
int backend_failed = 0;
apr_off_t bb_len;
int data_sent = 0;
int request_ended = 0;
int headers_sent = 0;
int rv = OK;
apr_int32_t conn_poll_fd;
apr_pollfd_t *conn_poll;
proxy_server_conf *psf =
ap_get_module_config(r->server->module_config, &proxy_module);
apr_size_t maxsize = AJP_MSG_BUFFER_SZ;
int send_body = 0;
apr_off_t content_length = 0;
int original_status = r->status;
const char *original_status_line = r->status_line;
const char *secret = NULL;
if (psf->io_buffer_size_set)
maxsize = psf->io_buffer_size;
if (maxsize > AJP_MAX_BUFFER_SZ)
maxsize = AJP_MAX_BUFFER_SZ;
else if (maxsize < AJP_MSG_BUFFER_SZ)
maxsize = AJP_MSG_BUFFER_SZ;
maxsize = APR_ALIGN(maxsize, 1024);
if (*conn->worker->s->secret)
secret = conn->worker->s->secret;
status = ajp_send_header(conn->sock, r, maxsize, uri, secret);
if (status != APR_SUCCESS) {
conn->close = 1;
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00868)
"request failed to %pI (%s)",
conn->worker->cp->addr,
conn->worker->s->hostname);
if (status == AJP_EOVERFLOW)
return HTTP_BAD_REQUEST;
else {
if (is_idempotent(r) == METHOD_IDEMPOTENT) {
return HTTP_SERVICE_UNAVAILABLE;
}
return HTTP_INTERNAL_SERVER_ERROR;
}
}
bufsiz = maxsize;
status = ajp_alloc_data_msg(r->pool, &buff, &bufsiz, &msg);
if (status != APR_SUCCESS) {
conn->close = 1;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00869)
"ajp_alloc_data_msg failed");
return HTTP_INTERNAL_SERVER_ERROR;
}
input_brigade = apr_brigade_create(p, r->connection->bucket_alloc);
tenc = apr_table_get(r->headers_in, "Transfer-Encoding");
if (tenc && (ap_casecmpstr(tenc, "chunked") == 0)) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00870) "request is chunked");
} else {
content_length = get_content_length(r);
status = ap_get_brigade(r->input_filters, input_brigade,
AP_MODE_READBYTES, APR_BLOCK_READ,
maxsize - AJP_HEADER_SZ);
if (status != APR_SUCCESS) {
conn->close = 1;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00871)
"ap_get_brigade failed");
apr_brigade_destroy(input_brigade);
return ap_map_http_request_error(status, HTTP_BAD_REQUEST);
}
if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00872) "APR_BUCKET_IS_EOS");
}
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00873)
"data to read (max %" APR_SIZE_T_FMT
" at %" APR_SIZE_T_FMT ")", bufsiz, msg->pos);
status = apr_brigade_flatten(input_brigade, buff, &bufsiz);
if (status != APR_SUCCESS) {
conn->close = 1;
apr_brigade_destroy(input_brigade);
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00874)
"apr_brigade_flatten");
return HTTP_INTERNAL_SERVER_ERROR;
}
apr_brigade_cleanup(input_brigade);
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00875)
"got %" APR_SIZE_T_FMT " bytes of data", bufsiz);
if (bufsiz > 0) {
status = ajp_send_data_msg(conn->sock, msg, bufsiz);
ajp_msg_log(r, msg, "First ajp_send_data_msg: ajp_ilink_send packet dump");
if (status != APR_SUCCESS) {
conn->close = 1;
apr_brigade_destroy(input_brigade);
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00876)
"send failed to %pI (%s)",
conn->worker->cp->addr,
conn->worker->s->hostname);
return HTTP_INTERNAL_SERVER_ERROR;
}
conn->worker->s->transferred += bufsiz;
send_body = 1;
}
else if (content_length > 0) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00877)
"read zero bytes, expecting"
" %" APR_OFF_T_FMT " bytes",
content_length);
conn->close = 1;
return HTTP_BAD_REQUEST;
}
}
conn->data = NULL;
status = ajp_read_header(conn->sock, r, maxsize,
(ajp_msg_t **)&(conn->data));
if (status != APR_SUCCESS) {
conn->close = 1;
apr_brigade_destroy(input_brigade);
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00878)
"read response failed from %pI (%s)",
conn->worker->cp->addr,
conn->worker->s->hostname);
if (APR_STATUS_IS_TIMEUP(status) &&
conn->worker->s->ping_timeout_set) {
return HTTP_GATEWAY_TIME_OUT;
}
if (!send_body && (is_idempotent(r) == METHOD_IDEMPOTENT)) {
return HTTP_SERVICE_UNAVAILABLE;
}
return HTTP_INTERNAL_SERVER_ERROR;
}
result = ajp_parse_type(r, conn->data);
output_brigade = apr_brigade_create(p, r->connection->bucket_alloc);
conn_poll = apr_pcalloc(p, sizeof(apr_pollfd_t));
conn_poll->reqevents = APR_POLLIN;
conn_poll->desc_type = APR_POLL_SOCKET;
conn_poll->desc.s = conn->sock;
bufsiz = maxsize;
for (;;) {
switch (result) {
case CMD_AJP13_GET_BODY_CHUNK:
if (havebody) {
if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) {
bufsiz = 0;
havebody = 0;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00879)
"APR_BUCKET_IS_EOS");
} else {
status = ap_get_brigade(r->input_filters, input_brigade,
AP_MODE_READBYTES,
APR_BLOCK_READ,
maxsize - AJP_HEADER_SZ);
if (status != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00880)
"ap_get_brigade failed");
if (APR_STATUS_IS_TIMEUP(status)) {
rv = HTTP_REQUEST_TIME_OUT;
}
else if (status == AP_FILTER_ERROR) {
rv = AP_FILTER_ERROR;
}
client_failed = 1;
break;
}
bufsiz = maxsize;
status = apr_brigade_flatten(input_brigade, buff,
&bufsiz);
apr_brigade_cleanup(input_brigade);
if (status != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00881)
"apr_brigade_flatten failed");
rv = HTTP_INTERNAL_SERVER_ERROR;
client_failed = 1;
break;
}
}
ajp_msg_reset(msg);
status = ajp_send_data_msg(conn->sock, msg, bufsiz);
ajp_msg_log(r, msg, "ajp_send_data_msg after CMD_AJP13_GET_BODY_CHUNK: ajp_ilink_send packet dump");
if (status != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00882)
"ajp_send_data_msg failed");
backend_failed = 1;
break;
}
conn->worker->s->transferred += bufsiz;
} else {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00883)
"ap_proxy_ajp_request error read after end");
backend_failed = 1;
}
break;
case CMD_AJP13_SEND_HEADERS:
if (headers_sent) {
backend_failed = 1;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00884)
"Backend sent headers twice.");
break;
}
status = ajp_parse_header(r, conf, conn->data);
if (status != APR_SUCCESS) {
backend_failed = 1;
}
else if ((r->status == 401) && conf->error_override) {
const char *buf;
const char *wa = "WWW-Authenticate";
if ((buf = apr_table_get(r->headers_out, wa))) {
apr_table_set(r->err_headers_out, wa, buf);
} else {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00885)
"ap_proxy_ajp_request: origin server "
"sent 401 without WWW-Authenticate header");
}
}
headers_sent = 1;
break;
case CMD_AJP13_SEND_BODY_CHUNK:
status = ajp_parse_data(r, conn->data, &size, &send_body_chunk_buff);
if (status == APR_SUCCESS) {
if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) {
if (size == 0) {
if (headers_sent) {
e = apr_bucket_flush_create(r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
}
else {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00886)
"Ignoring flush message "
"received before headers");
}
}
else {
apr_status_t rv;
if (conf->error_override && !ap_is_HTTP_ERROR(r->status)
&& ap_is_HTTP_ERROR(original_status)) {
r->status = original_status;
r->status_line = original_status_line;
}
e = apr_bucket_transient_create(send_body_chunk_buff, size,
r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
if ((conn->worker->s->flush_packets == flush_on) ||
((conn->worker->s->flush_packets == flush_auto) &&
((rv = apr_poll(conn_poll, 1, &conn_poll_fd,
conn->worker->s->flush_wait))
!= APR_SUCCESS) &&
APR_STATUS_IS_TIMEUP(rv))) {
e = apr_bucket_flush_create(r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
}
apr_brigade_length(output_brigade, 0, &bb_len);
if (bb_len != -1)
conn->worker->s->read += bb_len;
}
if (headers_sent) {
if (ap_pass_brigade(r->output_filters,
output_brigade) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00887)
"error processing body.%s",
r->connection->aborted ?
" Client aborted connection." : "");
client_failed = 1;
}
data_sent = 1;
apr_brigade_cleanup(output_brigade);
}
}
}
else {
backend_failed = 1;
}
break;
case CMD_AJP13_END_RESPONSE:
status = ajp_parse_reuse(r, conn->data, &conn_reuse);
if (status != APR_SUCCESS) {
backend_failed = 1;
}
if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) {
e = apr_bucket_eos_create(r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
if (ap_pass_brigade(r->output_filters,
output_brigade) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00888)
"error processing end");
client_failed = 1;
}
data_sent = 1;
}
request_ended = 1;
break;
default:
backend_failed = 1;
break;
}
if (r->connection->aborted) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02821)
"client connection aborted");
if (!headers_sent) {
r->status = HTTP_BAD_REQUEST;
}
client_failed = 1;
data_sent = 1;
break;
}
if ((result == CMD_AJP13_END_RESPONSE)
|| backend_failed || client_failed)
break;
status = ajp_read_header(conn->sock, r, maxsize,
(ajp_msg_t **)&(conn->data));
if (status != APR_SUCCESS) {
backend_failed = 1;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00889)
"ajp_read_header failed");
break;
}
result = ajp_parse_type(r, conn->data);
}
apr_brigade_destroy(input_brigade);
apr_brigade_cleanup(output_brigade);
if (backend_failed || client_failed) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00890)
"Processing of request failed backend: %i, client: %i",
backend_failed, client_failed);
conn->close = 1;
if (data_sent) {
rv = DONE;
}
}
else if (!request_ended) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00891)
"Processing of request didn't terminate cleanly");
conn->close = 1;
backend_failed = 1;
if (data_sent) {
rv = DONE;
}
}
else if (!conn_reuse) {
conn->close = 1;
}
else {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00892)
"got response from %pI (%s)",
conn->worker->cp->addr,
conn->worker->s->hostname);
if (conf->error_override && ap_is_HTTP_ERROR(r->status)) {
rv = r->status;
r->status = HTTP_OK;
apr_table_setn(r->notes, "proxy-error-override", "1");
}
else {
rv = OK;
}
}
if (backend_failed) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00893)
"dialog to %pI (%s) failed",
conn->worker->cp->addr,
conn->worker->s->hostname);
if (data_sent) {
ap_proxy_backend_broke(r, output_brigade);
} else if (!send_body && (is_idempotent(r) == METHOD_IDEMPOTENT)) {
rv = HTTP_SERVICE_UNAVAILABLE;
} else {
if (APR_STATUS_IS_TIMEUP(status) &&
conn->worker->s->ping_timeout_set) {
apr_table_setn(r->notes, "proxy_timedout", "1");
rv = HTTP_GATEWAY_TIME_OUT;
}
else {
rv = HTTP_INTERNAL_SERVER_ERROR;
}
}
}
else if (client_failed) {
int level = (r->connection->aborted) ? APLOG_DEBUG : APLOG_ERR;
ap_log_rerror(APLOG_MARK, level, status, r, APLOGNO(02822)
"dialog with client %pI failed",
r->connection->client_addr);
if (rv == OK) {
rv = HTTP_BAD_REQUEST;
}
}
if (data_sent && !r->eos_sent && !r->connection->aborted
&& APR_BRIGADE_EMPTY(output_brigade)) {
e = apr_bucket_eos_create(r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
}
if (!APR_BRIGADE_EMPTY(output_brigade)
&& ap_pass_brigade(r->output_filters, output_brigade) != APR_SUCCESS) {
rv = AP_FILTER_ERROR;
}
apr_brigade_destroy(output_brigade);
if (apr_table_get(r->subprocess_env, "proxy-nokeepalive")) {
conn->close = 1;
}
return rv;
}
|
['static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,\n proxy_conn_rec *conn,\n conn_rec *origin,\n proxy_dir_conf *conf,\n apr_uri_t *uri,\n char *url, char *server_portstr)\n{\n apr_status_t status;\n int result;\n apr_bucket *e;\n apr_bucket_brigade *input_brigade;\n apr_bucket_brigade *output_brigade;\n ajp_msg_t *msg;\n apr_size_t bufsiz = 0;\n char *buff;\n char *send_body_chunk_buff;\n apr_uint16_t size;\n apr_byte_t conn_reuse = 0;\n const char *tenc;\n int havebody = 1;\n int client_failed = 0;\n int backend_failed = 0;\n apr_off_t bb_len;\n int data_sent = 0;\n int request_ended = 0;\n int headers_sent = 0;\n int rv = OK;\n apr_int32_t conn_poll_fd;\n apr_pollfd_t *conn_poll;\n proxy_server_conf *psf =\n ap_get_module_config(r->server->module_config, &proxy_module);\n apr_size_t maxsize = AJP_MSG_BUFFER_SZ;\n int send_body = 0;\n apr_off_t content_length = 0;\n int original_status = r->status;\n const char *original_status_line = r->status_line;\n const char *secret = NULL;\n if (psf->io_buffer_size_set)\n maxsize = psf->io_buffer_size;\n if (maxsize > AJP_MAX_BUFFER_SZ)\n maxsize = AJP_MAX_BUFFER_SZ;\n else if (maxsize < AJP_MSG_BUFFER_SZ)\n maxsize = AJP_MSG_BUFFER_SZ;\n maxsize = APR_ALIGN(maxsize, 1024);\n if (*conn->worker->s->secret)\n secret = conn->worker->s->secret;\n status = ajp_send_header(conn->sock, r, maxsize, uri, secret);\n if (status != APR_SUCCESS) {\n conn->close = 1;\n ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00868)\n "request failed to %pI (%s)",\n conn->worker->cp->addr,\n conn->worker->s->hostname);\n if (status == AJP_EOVERFLOW)\n return HTTP_BAD_REQUEST;\n else {\n if (is_idempotent(r) == METHOD_IDEMPOTENT) {\n return HTTP_SERVICE_UNAVAILABLE;\n }\n return HTTP_INTERNAL_SERVER_ERROR;\n }\n }\n bufsiz = maxsize;\n status = ajp_alloc_data_msg(r->pool, &buff, &bufsiz, &msg);\n if (status != APR_SUCCESS) {\n conn->close = 1;\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00869)\n "ajp_alloc_data_msg failed");\n return HTTP_INTERNAL_SERVER_ERROR;\n }\n input_brigade = apr_brigade_create(p, r->connection->bucket_alloc);\n tenc = apr_table_get(r->headers_in, "Transfer-Encoding");\n if (tenc && (ap_casecmpstr(tenc, "chunked") == 0)) {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00870) "request is chunked");\n } else {\n content_length = get_content_length(r);\n status = ap_get_brigade(r->input_filters, input_brigade,\n AP_MODE_READBYTES, APR_BLOCK_READ,\n maxsize - AJP_HEADER_SZ);\n if (status != APR_SUCCESS) {\n conn->close = 1;\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00871)\n "ap_get_brigade failed");\n apr_brigade_destroy(input_brigade);\n return ap_map_http_request_error(status, HTTP_BAD_REQUEST);\n }\n if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00872) "APR_BUCKET_IS_EOS");\n }\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00873)\n "data to read (max %" APR_SIZE_T_FMT\n " at %" APR_SIZE_T_FMT ")", bufsiz, msg->pos);\n status = apr_brigade_flatten(input_brigade, buff, &bufsiz);\n if (status != APR_SUCCESS) {\n conn->close = 1;\n apr_brigade_destroy(input_brigade);\n ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00874)\n "apr_brigade_flatten");\n return HTTP_INTERNAL_SERVER_ERROR;\n }\n apr_brigade_cleanup(input_brigade);\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00875)\n "got %" APR_SIZE_T_FMT " bytes of data", bufsiz);\n if (bufsiz > 0) {\n status = ajp_send_data_msg(conn->sock, msg, bufsiz);\n ajp_msg_log(r, msg, "First ajp_send_data_msg: ajp_ilink_send packet dump");\n if (status != APR_SUCCESS) {\n conn->close = 1;\n apr_brigade_destroy(input_brigade);\n ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00876)\n "send failed to %pI (%s)",\n conn->worker->cp->addr,\n conn->worker->s->hostname);\n return HTTP_INTERNAL_SERVER_ERROR;\n }\n conn->worker->s->transferred += bufsiz;\n send_body = 1;\n }\n else if (content_length > 0) {\n ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00877)\n "read zero bytes, expecting"\n " %" APR_OFF_T_FMT " bytes",\n content_length);\n conn->close = 1;\n return HTTP_BAD_REQUEST;\n }\n }\n conn->data = NULL;\n status = ajp_read_header(conn->sock, r, maxsize,\n (ajp_msg_t **)&(conn->data));\n if (status != APR_SUCCESS) {\n conn->close = 1;\n apr_brigade_destroy(input_brigade);\n ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00878)\n "read response failed from %pI (%s)",\n conn->worker->cp->addr,\n conn->worker->s->hostname);\n if (APR_STATUS_IS_TIMEUP(status) &&\n conn->worker->s->ping_timeout_set) {\n return HTTP_GATEWAY_TIME_OUT;\n }\n if (!send_body && (is_idempotent(r) == METHOD_IDEMPOTENT)) {\n return HTTP_SERVICE_UNAVAILABLE;\n }\n return HTTP_INTERNAL_SERVER_ERROR;\n }\n result = ajp_parse_type(r, conn->data);\n output_brigade = apr_brigade_create(p, r->connection->bucket_alloc);\n conn_poll = apr_pcalloc(p, sizeof(apr_pollfd_t));\n conn_poll->reqevents = APR_POLLIN;\n conn_poll->desc_type = APR_POLL_SOCKET;\n conn_poll->desc.s = conn->sock;\n bufsiz = maxsize;\n for (;;) {\n switch (result) {\n case CMD_AJP13_GET_BODY_CHUNK:\n if (havebody) {\n if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) {\n bufsiz = 0;\n havebody = 0;\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00879)\n "APR_BUCKET_IS_EOS");\n } else {\n status = ap_get_brigade(r->input_filters, input_brigade,\n AP_MODE_READBYTES,\n APR_BLOCK_READ,\n maxsize - AJP_HEADER_SZ);\n if (status != APR_SUCCESS) {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00880)\n "ap_get_brigade failed");\n if (APR_STATUS_IS_TIMEUP(status)) {\n rv = HTTP_REQUEST_TIME_OUT;\n }\n else if (status == AP_FILTER_ERROR) {\n rv = AP_FILTER_ERROR;\n }\n client_failed = 1;\n break;\n }\n bufsiz = maxsize;\n status = apr_brigade_flatten(input_brigade, buff,\n &bufsiz);\n apr_brigade_cleanup(input_brigade);\n if (status != APR_SUCCESS) {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00881)\n "apr_brigade_flatten failed");\n rv = HTTP_INTERNAL_SERVER_ERROR;\n client_failed = 1;\n break;\n }\n }\n ajp_msg_reset(msg);\n status = ajp_send_data_msg(conn->sock, msg, bufsiz);\n ajp_msg_log(r, msg, "ajp_send_data_msg after CMD_AJP13_GET_BODY_CHUNK: ajp_ilink_send packet dump");\n if (status != APR_SUCCESS) {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00882)\n "ajp_send_data_msg failed");\n backend_failed = 1;\n break;\n }\n conn->worker->s->transferred += bufsiz;\n } else {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00883)\n "ap_proxy_ajp_request error read after end");\n backend_failed = 1;\n }\n break;\n case CMD_AJP13_SEND_HEADERS:\n if (headers_sent) {\n backend_failed = 1;\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00884)\n "Backend sent headers twice.");\n break;\n }\n status = ajp_parse_header(r, conf, conn->data);\n if (status != APR_SUCCESS) {\n backend_failed = 1;\n }\n else if ((r->status == 401) && conf->error_override) {\n const char *buf;\n const char *wa = "WWW-Authenticate";\n if ((buf = apr_table_get(r->headers_out, wa))) {\n apr_table_set(r->err_headers_out, wa, buf);\n } else {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00885)\n "ap_proxy_ajp_request: origin server "\n "sent 401 without WWW-Authenticate header");\n }\n }\n headers_sent = 1;\n break;\n case CMD_AJP13_SEND_BODY_CHUNK:\n status = ajp_parse_data(r, conn->data, &size, &send_body_chunk_buff);\n if (status == APR_SUCCESS) {\n if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) {\n if (size == 0) {\n if (headers_sent) {\n e = apr_bucket_flush_create(r->connection->bucket_alloc);\n APR_BRIGADE_INSERT_TAIL(output_brigade, e);\n }\n else {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00886)\n "Ignoring flush message "\n "received before headers");\n }\n }\n else {\n apr_status_t rv;\n if (conf->error_override && !ap_is_HTTP_ERROR(r->status)\n && ap_is_HTTP_ERROR(original_status)) {\n r->status = original_status;\n r->status_line = original_status_line;\n }\n e = apr_bucket_transient_create(send_body_chunk_buff, size,\n r->connection->bucket_alloc);\n APR_BRIGADE_INSERT_TAIL(output_brigade, e);\n if ((conn->worker->s->flush_packets == flush_on) ||\n ((conn->worker->s->flush_packets == flush_auto) &&\n ((rv = apr_poll(conn_poll, 1, &conn_poll_fd,\n conn->worker->s->flush_wait))\n != APR_SUCCESS) &&\n APR_STATUS_IS_TIMEUP(rv))) {\n e = apr_bucket_flush_create(r->connection->bucket_alloc);\n APR_BRIGADE_INSERT_TAIL(output_brigade, e);\n }\n apr_brigade_length(output_brigade, 0, &bb_len);\n if (bb_len != -1)\n conn->worker->s->read += bb_len;\n }\n if (headers_sent) {\n if (ap_pass_brigade(r->output_filters,\n output_brigade) != APR_SUCCESS) {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00887)\n "error processing body.%s",\n r->connection->aborted ?\n " Client aborted connection." : "");\n client_failed = 1;\n }\n data_sent = 1;\n apr_brigade_cleanup(output_brigade);\n }\n }\n }\n else {\n backend_failed = 1;\n }\n break;\n case CMD_AJP13_END_RESPONSE:\n status = ajp_parse_reuse(r, conn->data, &conn_reuse);\n if (status != APR_SUCCESS) {\n backend_failed = 1;\n }\n if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) {\n e = apr_bucket_eos_create(r->connection->bucket_alloc);\n APR_BRIGADE_INSERT_TAIL(output_brigade, e);\n if (ap_pass_brigade(r->output_filters,\n output_brigade) != APR_SUCCESS) {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00888)\n "error processing end");\n client_failed = 1;\n }\n data_sent = 1;\n }\n request_ended = 1;\n break;\n default:\n backend_failed = 1;\n break;\n }\n if (r->connection->aborted) {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02821)\n "client connection aborted");\n if (!headers_sent) {\n r->status = HTTP_BAD_REQUEST;\n }\n client_failed = 1;\n data_sent = 1;\n break;\n }\n if ((result == CMD_AJP13_END_RESPONSE)\n || backend_failed || client_failed)\n break;\n status = ajp_read_header(conn->sock, r, maxsize,\n (ajp_msg_t **)&(conn->data));\n if (status != APR_SUCCESS) {\n backend_failed = 1;\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00889)\n "ajp_read_header failed");\n break;\n }\n result = ajp_parse_type(r, conn->data);\n }\n apr_brigade_destroy(input_brigade);\n apr_brigade_cleanup(output_brigade);\n if (backend_failed || client_failed) {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00890)\n "Processing of request failed backend: %i, client: %i",\n backend_failed, client_failed);\n conn->close = 1;\n if (data_sent) {\n rv = DONE;\n }\n }\n else if (!request_ended) {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00891)\n "Processing of request didn\'t terminate cleanly");\n conn->close = 1;\n backend_failed = 1;\n if (data_sent) {\n rv = DONE;\n }\n }\n else if (!conn_reuse) {\n conn->close = 1;\n }\n else {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00892)\n "got response from %pI (%s)",\n conn->worker->cp->addr,\n conn->worker->s->hostname);\n if (conf->error_override && ap_is_HTTP_ERROR(r->status)) {\n rv = r->status;\n r->status = HTTP_OK;\n apr_table_setn(r->notes, "proxy-error-override", "1");\n }\n else {\n rv = OK;\n }\n }\n if (backend_failed) {\n ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00893)\n "dialog to %pI (%s) failed",\n conn->worker->cp->addr,\n conn->worker->s->hostname);\n if (data_sent) {\n ap_proxy_backend_broke(r, output_brigade);\n } else if (!send_body && (is_idempotent(r) == METHOD_IDEMPOTENT)) {\n rv = HTTP_SERVICE_UNAVAILABLE;\n } else {\n if (APR_STATUS_IS_TIMEUP(status) &&\n conn->worker->s->ping_timeout_set) {\n apr_table_setn(r->notes, "proxy_timedout", "1");\n rv = HTTP_GATEWAY_TIME_OUT;\n }\n else {\n rv = HTTP_INTERNAL_SERVER_ERROR;\n }\n }\n }\n else if (client_failed) {\n int level = (r->connection->aborted) ? APLOG_DEBUG : APLOG_ERR;\n ap_log_rerror(APLOG_MARK, level, status, r, APLOGNO(02822)\n "dialog with client %pI failed",\n r->connection->client_addr);\n if (rv == OK) {\n rv = HTTP_BAD_REQUEST;\n }\n }\n if (data_sent && !r->eos_sent && !r->connection->aborted\n && APR_BRIGADE_EMPTY(output_brigade)) {\n e = apr_bucket_eos_create(r->connection->bucket_alloc);\n APR_BRIGADE_INSERT_TAIL(output_brigade, e);\n }\n if (!APR_BRIGADE_EMPTY(output_brigade)\n && ap_pass_brigade(r->output_filters, output_brigade) != APR_SUCCESS) {\n rv = AP_FILTER_ERROR;\n }\n apr_brigade_destroy(output_brigade);\n if (apr_table_get(r->subprocess_env, "proxy-nokeepalive")) {\n conn->close = 1;\n }\n return rv;\n}']
|
2,799
| 0
|
https://github.com/libav/libav/blob/cc20fbcd39c7b60602edae4f7deb092ecfd3c975/libavcodec/smacker.c/#L629
|
static int smka_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{
AVFrame *frame = data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
GetBitContext gb;
HuffContext h[4] = { { 0 } };
VLC vlc[4] = { { 0 } };
int16_t *samples;
uint8_t *samples8;
int val;
int i, res, ret;
int unp_size;
int bits, stereo;
int pred[2] = {0, 0};
if (buf_size <= 4) {
av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
return AVERROR(EINVAL);
}
unp_size = AV_RL32(buf);
init_get_bits(&gb, buf + 4, (buf_size - 4) * 8);
if(!get_bits1(&gb)){
av_log(avctx, AV_LOG_INFO, "Sound: no data\n");
*got_frame_ptr = 0;
return 1;
}
stereo = get_bits1(&gb);
bits = get_bits1(&gb);
if (stereo ^ (avctx->channels != 1)) {
av_log(avctx, AV_LOG_ERROR, "channels mismatch\n");
return AVERROR(EINVAL);
}
if (bits && avctx->sample_fmt == AV_SAMPLE_FMT_U8) {
av_log(avctx, AV_LOG_ERROR, "sample format mismatch\n");
return AVERROR(EINVAL);
}
frame->nb_samples = unp_size / (avctx->channels * (bits + 1));
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
samples = (int16_t *)frame->data[0];
samples8 = frame->data[0];
for(i = 0; i < (1 << (bits + stereo)); i++) {
h[i].length = 256;
h[i].maxlength = 0;
h[i].current = 0;
h[i].bits = av_mallocz(256 * 4);
h[i].lengths = av_mallocz(256 * sizeof(int));
h[i].values = av_mallocz(256 * sizeof(int));
if (!h[i].bits || !h[i].lengths || !h[i].values) {
ret = AVERROR(ENOMEM);
goto error;
}
skip_bits1(&gb);
if (smacker_decode_tree(&gb, &h[i], 0, 0) < 0) {
ret = AVERROR_INVALIDDATA;
goto error;
}
skip_bits1(&gb);
if(h[i].current > 1) {
res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
h[i].lengths, sizeof(int), sizeof(int),
h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
if(res < 0) {
av_log(avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
ret = AVERROR_INVALIDDATA;
goto error;
}
}
}
if(bits) {
for(i = stereo; i >= 0; i--)
pred[i] = sign_extend(av_bswap16(get_bits(&gb, 16)), 16);
for(i = 0; i <= stereo; i++)
*samples++ = pred[i];
for(; i < unp_size / 2; i++) {
if(i & stereo) {
if(vlc[2].table)
res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3);
else
res = 0;
val = h[2].values[res];
if(vlc[3].table)
res = get_vlc2(&gb, vlc[3].table, SMKTREE_BITS, 3);
else
res = 0;
val |= h[3].values[res] << 8;
pred[1] += sign_extend(val, 16);
*samples++ = pred[1];
} else {
if(vlc[0].table)
res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
else
res = 0;
val = h[0].values[res];
if(vlc[1].table)
res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
else
res = 0;
val |= h[1].values[res] << 8;
pred[0] += sign_extend(val, 16);
*samples++ = pred[0];
}
}
} else {
for(i = stereo; i >= 0; i--)
pred[i] = get_bits(&gb, 8);
for(i = 0; i <= stereo; i++)
*samples8++ = pred[i];
for(; i < unp_size; i++) {
if(i & stereo){
if(vlc[1].table)
res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
else
res = 0;
pred[1] += sign_extend(h[1].values[res], 8);
*samples8++ = pred[1];
} else {
if(vlc[0].table)
res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
else
res = 0;
pred[0] += sign_extend(h[0].values[res], 8);
*samples8++ = pred[0];
}
}
}
*got_frame_ptr = 1;
ret = buf_size;
error:
for(i = 0; i < 4; i++) {
if(vlc[i].table)
ff_free_vlc(&vlc[i]);
av_free(h[i].bits);
av_free(h[i].lengths);
av_free(h[i].values);
}
return ret;
}
|
['static int smka_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame_ptr, AVPacket *avpkt)\n{\n AVFrame *frame = data;\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n GetBitContext gb;\n HuffContext h[4] = { { 0 } };\n VLC vlc[4] = { { 0 } };\n int16_t *samples;\n uint8_t *samples8;\n int val;\n int i, res, ret;\n int unp_size;\n int bits, stereo;\n int pred[2] = {0, 0};\n if (buf_size <= 4) {\n av_log(avctx, AV_LOG_ERROR, "packet is too small\\n");\n return AVERROR(EINVAL);\n }\n unp_size = AV_RL32(buf);\n init_get_bits(&gb, buf + 4, (buf_size - 4) * 8);\n if(!get_bits1(&gb)){\n av_log(avctx, AV_LOG_INFO, "Sound: no data\\n");\n *got_frame_ptr = 0;\n return 1;\n }\n stereo = get_bits1(&gb);\n bits = get_bits1(&gb);\n if (stereo ^ (avctx->channels != 1)) {\n av_log(avctx, AV_LOG_ERROR, "channels mismatch\\n");\n return AVERROR(EINVAL);\n }\n if (bits && avctx->sample_fmt == AV_SAMPLE_FMT_U8) {\n av_log(avctx, AV_LOG_ERROR, "sample format mismatch\\n");\n return AVERROR(EINVAL);\n }\n frame->nb_samples = unp_size / (avctx->channels * (bits + 1));\n if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {\n av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return ret;\n }\n samples = (int16_t *)frame->data[0];\n samples8 = frame->data[0];\n for(i = 0; i < (1 << (bits + stereo)); i++) {\n h[i].length = 256;\n h[i].maxlength = 0;\n h[i].current = 0;\n h[i].bits = av_mallocz(256 * 4);\n h[i].lengths = av_mallocz(256 * sizeof(int));\n h[i].values = av_mallocz(256 * sizeof(int));\n if (!h[i].bits || !h[i].lengths || !h[i].values) {\n ret = AVERROR(ENOMEM);\n goto error;\n }\n skip_bits1(&gb);\n if (smacker_decode_tree(&gb, &h[i], 0, 0) < 0) {\n ret = AVERROR_INVALIDDATA;\n goto error;\n }\n skip_bits1(&gb);\n if(h[i].current > 1) {\n res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,\n h[i].lengths, sizeof(int), sizeof(int),\n h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);\n if(res < 0) {\n av_log(avctx, AV_LOG_ERROR, "Cannot build VLC table\\n");\n ret = AVERROR_INVALIDDATA;\n goto error;\n }\n }\n }\n if(bits) {\n for(i = stereo; i >= 0; i--)\n pred[i] = sign_extend(av_bswap16(get_bits(&gb, 16)), 16);\n for(i = 0; i <= stereo; i++)\n *samples++ = pred[i];\n for(; i < unp_size / 2; i++) {\n if(i & stereo) {\n if(vlc[2].table)\n res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3);\n else\n res = 0;\n val = h[2].values[res];\n if(vlc[3].table)\n res = get_vlc2(&gb, vlc[3].table, SMKTREE_BITS, 3);\n else\n res = 0;\n val |= h[3].values[res] << 8;\n pred[1] += sign_extend(val, 16);\n *samples++ = pred[1];\n } else {\n if(vlc[0].table)\n res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);\n else\n res = 0;\n val = h[0].values[res];\n if(vlc[1].table)\n res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);\n else\n res = 0;\n val |= h[1].values[res] << 8;\n pred[0] += sign_extend(val, 16);\n *samples++ = pred[0];\n }\n }\n } else {\n for(i = stereo; i >= 0; i--)\n pred[i] = get_bits(&gb, 8);\n for(i = 0; i <= stereo; i++)\n *samples8++ = pred[i];\n for(; i < unp_size; i++) {\n if(i & stereo){\n if(vlc[1].table)\n res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);\n else\n res = 0;\n pred[1] += sign_extend(h[1].values[res], 8);\n *samples8++ = pred[1];\n } else {\n if(vlc[0].table)\n res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);\n else\n res = 0;\n pred[0] += sign_extend(h[0].values[res], 8);\n *samples8++ = pred[0];\n }\n }\n }\n *got_frame_ptr = 1;\n ret = buf_size;\nerror:\n for(i = 0; i < 4; i++) {\n if(vlc[i].table)\n ff_free_vlc(&vlc[i]);\n av_free(h[i].bits);\n av_free(h[i].lengths);\n av_free(h[i].values);\n }\n return ret;\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 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}']
|
2,800
| 0
|
https://github.com/libav/libav/blob/edbb0c07081e78a4c7b6d999d641183bf30f1a2e/libavformat/utils.c/#L2589
|
void avformat_free_context(AVFormatContext *s)
{
int i;
AVStream *st;
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
if (st->parser) {
av_parser_close(st->parser);
av_free_packet(&st->cur_pkt);
}
av_metadata_free(&st->metadata);
av_free(st->index_entries);
av_free(st->codec->extradata);
av_free(st->codec->subtitle_header);
av_free(st->codec);
#if FF_API_OLD_METADATA
av_free(st->filename);
#endif
av_free(st->priv_data);
av_free(st->info);
av_free(st);
}
for(i=s->nb_programs-1; i>=0; i--) {
#if FF_API_OLD_METADATA
av_freep(&s->programs[i]->provider_name);
av_freep(&s->programs[i]->name);
#endif
av_metadata_free(&s->programs[i]->metadata);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
av_freep(&s->programs);
av_freep(&s->priv_data);
while(s->nb_chapters--) {
#if FF_API_OLD_METADATA
av_free(s->chapters[s->nb_chapters]->title);
#endif
av_metadata_free(&s->chapters[s->nb_chapters]->metadata);
av_free(s->chapters[s->nb_chapters]);
}
av_freep(&s->chapters);
av_metadata_free(&s->metadata);
av_freep(&s->key);
av_free(s);
}
|
['static int mov_write_trailer(AVFormatContext *s)\n{\n MOVMuxContext *mov = s->priv_data;\n ByteIOContext *pb = s->pb;\n int res = 0;\n int i;\n int64_t moov_pos = url_ftell(pb);\n if (mov->mdat_size+8 <= UINT32_MAX) {\n url_fseek(pb, mov->mdat_pos, SEEK_SET);\n put_be32(pb, mov->mdat_size+8);\n } else {\n url_fseek(pb, mov->mdat_pos - 8, SEEK_SET);\n put_be32(pb, 1);\n put_tag(pb, "mdat");\n put_be64(pb, mov->mdat_size+16);\n }\n url_fseek(pb, moov_pos, SEEK_SET);\n mov_write_moov_tag(pb, mov, s);\n if (mov->chapter_track)\n av_freep(&mov->tracks[mov->chapter_track].enc);\n for (i=0; i<mov->nb_streams; i++) {\n if (mov->tracks[i].tag == MKTAG(\'r\',\'t\',\'p\',\' \'))\n ff_mov_close_hinting(&mov->tracks[i]);\n av_freep(&mov->tracks[i].cluster);\n if(mov->tracks[i].vosLen) av_free(mov->tracks[i].vosData);\n }\n put_flush_packet(pb);\n av_freep(&mov->tracks);\n return res;\n}', 'void av_freep(void *arg)\n{\n void **ptr= (void**)arg;\n av_free(*ptr);\n *ptr = NULL;\n}', 'void ff_mov_close_hinting(MOVTrack *track) {\n AVFormatContext* rtp_ctx = track->rtp_ctx;\n uint8_t *ptr;\n av_freep(&track->enc);\n sample_queue_free(&track->sample_queue);\n if (!rtp_ctx)\n return;\n if (rtp_ctx->pb) {\n av_write_trailer(rtp_ctx);\n url_close_dyn_buf(rtp_ctx->pb, &ptr);\n av_free(ptr);\n }\n avformat_free_context(rtp_ctx);\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n av_free_packet(&st->cur_pkt);\n }\n av_metadata_free(&st->metadata);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec->subtitle_header);\n av_free(st->codec);\n#if FF_API_OLD_METADATA\n av_free(st->filename);\n#endif\n av_free(st->priv_data);\n av_free(st->info);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n#if FF_API_OLD_METADATA\n av_freep(&s->programs[i]->provider_name);\n av_freep(&s->programs[i]->name);\n#endif\n av_metadata_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n#if FF_API_OLD_METADATA\n av_free(s->chapters[s->nb_chapters]->title);\n#endif\n av_metadata_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_metadata_free(&s->metadata);\n av_freep(&s->key);\n av_free(s);\n}']
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.